commit 204f5964bcbd0cde52f91fa867cca303dab2aa4e Author: evan.liu <583229071@qq.com> Date: Tue Sep 1 06:22:11 2026 +0800 第一次�交 diff --git a/nations-tec/AN_N32WB03x_BLE_Common_Parameter_Configuration_Application_Note_V1.1.pdf b/nations-tec/AN_N32WB03x_BLE_Common_Parameter_Configuration_Application_Note_V1.1.pdf new file mode 100644 index 0000000..ec7554e Binary files /dev/null and b/nations-tec/AN_N32WB03x_BLE_Common_Parameter_Configuration_Application_Note_V1.1.pdf differ diff --git a/nations-tec/AN_N32WB03x_BLE_Service&Characteristic_Configuration_Application_Note_V1.0.pdf b/nations-tec/AN_N32WB03x_BLE_Service&Characteristic_Configuration_Application_Note_V1.0.pdf new file mode 100644 index 0000000..ec39463 Binary files /dev/null and b/nations-tec/AN_N32WB03x_BLE_Service&Characteristic_Configuration_Application_Note_V1.0.pdf differ diff --git a/nations-tec/CN_DG_N32WB03x_Series_Chips_Hardware_Design_Guide_V1.4.pdf b/nations-tec/CN_DG_N32WB03x_Series_Chips_Hardware_Design_Guide_V1.4.pdf new file mode 100644 index 0000000..e2c1bf0 Binary files /dev/null and b/nations-tec/CN_DG_N32WB03x_Series_Chips_Hardware_Design_Guide_V1.4.pdf differ diff --git a/nations-tec/CN_ES_N32WB03x_series_errata_sheet_V1.1.pdf b/nations-tec/CN_ES_N32WB03x_series_errata_sheet_V1.1.pdf new file mode 100644 index 0000000..622c192 Binary files /dev/null and b/nations-tec/CN_ES_N32WB03x_series_errata_sheet_V1.1.pdf differ diff --git a/nations-tec/CN_UG_N32WB03x_Firmware_Update_User_Guide_V1.3.pdf b/nations-tec/CN_UG_N32WB03x_Firmware_Update_User_Guide_V1.3.pdf new file mode 100644 index 0000000..7508139 Binary files /dev/null and b/nations-tec/CN_UG_N32WB03x_Firmware_Update_User_Guide_V1.3.pdf differ diff --git a/nations-tec/CN_UG_N32WB03x_SDK_User_Guide_V1.5 (1).pdf b/nations-tec/CN_UG_N32WB03x_SDK_User_Guide_V1.5 (1).pdf new file mode 100644 index 0000000..3040159 Binary files /dev/null and b/nations-tec/CN_UG_N32WB03x_SDK_User_Guide_V1.5 (1).pdf differ diff --git a/nations-tec/CN_UM_N32WB03X_Series_User_Manual_V1.5.pdf b/nations-tec/CN_UM_N32WB03X_Series_User_Manual_V1.5.pdf new file mode 100644 index 0000000..6a7c692 Binary files /dev/null and b/nations-tec/CN_UM_N32WB03X_Series_User_Manual_V1.5.pdf differ diff --git a/nations-tec/N32WB031_STB_V1.3/CN_UG_N32WB031_STB_Development_Board_User_Guide_V1.3.pdf b/nations-tec/N32WB031_STB_V1.3/CN_UG_N32WB031_STB_Development_Board_User_Guide_V1.3.pdf new file mode 100644 index 0000000..71acd6b Binary files /dev/null and b/nations-tec/N32WB031_STB_V1.3/CN_UG_N32WB031_STB_Development_Board_User_Guide_V1.3.pdf differ diff --git a/nations-tec/N32WB031_STB_V1.3/EN_UG_N32WB031_STB_Development_Board_User_Guide_V1.3.pdf b/nations-tec/N32WB031_STB_V1.3/EN_UG_N32WB031_STB_Development_Board_User_Guide_V1.3.pdf new file mode 100644 index 0000000..dd13a6f Binary files /dev/null and b/nations-tec/N32WB031_STB_V1.3/EN_UG_N32WB031_STB_Development_Board_User_Guide_V1.3.pdf differ diff --git a/nations-tec/N32WB031_STB_V1.3/N32WB031_Development_Board_Inductor_Selection_Table.xlsx b/nations-tec/N32WB031_STB_V1.3/N32WB031_Development_Board_Inductor_Selection_Table.xlsx new file mode 100644 index 0000000..4edb760 Binary files /dev/null and b/nations-tec/N32WB031_STB_V1.3/N32WB031_Development_Board_Inductor_Selection_Table.xlsx differ diff --git a/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_20220930.pcb b/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_20220930.pcb new file mode 100644 index 0000000..5fa9ca2 Binary files /dev/null and b/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_20220930.pcb differ diff --git a/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_20220930.pdf b/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_20220930.pdf new file mode 100644 index 0000000..2d2c741 Binary files /dev/null and b/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_20220930.pdf differ diff --git a/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_20220930.sch b/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_20220930.sch new file mode 100644 index 0000000..13182a8 Binary files /dev/null and b/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_20220930.sch differ diff --git a/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_BOM_20221111.xlsx b/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_BOM_20221111.xlsx new file mode 100644 index 0000000..62c123e Binary files /dev/null and b/nations-tec/N32WB031_STB_V1.3/N32WB031_STB_V1.3_BOM_20221111.xlsx differ diff --git a/nations-tec/N32WB03x_DFP.1.4.0.pack b/nations-tec/N32WB03x_DFP.1.4.0.pack new file mode 100644 index 0000000..ea4c3fa Binary files /dev/null and b/nations-tec/N32WB03x_DFP.1.4.0.pack differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/cmsis_armcc.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/cmsis_armcc.h new file mode 100644 index 0000000..74c49c6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/cmsis_armcc.h @@ -0,0 +1,734 @@ +/**************************************************************************//** + * @file cmsis_armcc.h + * @brief CMSIS Cortex-M Core Function/Instruction 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. + ---------------------------------------------------------------------------*/ + + +#ifndef __CMSIS_ARMCC_H +#define __CMSIS_ARMCC_H + + +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677) + #error "Please use ARM Compiler Toolchain V4.0.677 or later!" +#endif + +/* ########################### Core Function Access ########################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions + @{ + */ + +/* intrinsic void __enable_irq(); */ +/* intrinsic void __disable_irq(); */ + +/** + \brief Get Control Register + \details Returns the content of the Control Register. + \return Control Register value + */ +__STATIC_INLINE uint32_t __get_CONTROL(void) +{ + register uint32_t __regControl __ASM("control"); + return(__regControl); +} + + +/** + \brief Set Control Register + \details Writes the given value to the Control Register. + \param [in] control Control Register value to set + */ +__STATIC_INLINE void __set_CONTROL(uint32_t control) +{ + register uint32_t __regControl __ASM("control"); + __regControl = control; +} + + +/** + \brief Get IPSR Register + \details Returns the content of the IPSR Register. + \return IPSR Register value + */ +__STATIC_INLINE uint32_t __get_IPSR(void) +{ + register uint32_t __regIPSR __ASM("ipsr"); + return(__regIPSR); +} + + +/** + \brief Get APSR Register + \details Returns the content of the APSR Register. + \return APSR Register value + */ +__STATIC_INLINE uint32_t __get_APSR(void) +{ + register uint32_t __regAPSR __ASM("apsr"); + return(__regAPSR); +} + + +/** + \brief Get xPSR Register + \details Returns the content of the xPSR Register. + \return xPSR Register value + */ +__STATIC_INLINE uint32_t __get_xPSR(void) +{ + register uint32_t __regXPSR __ASM("xpsr"); + return(__regXPSR); +} + + +/** + \brief Get Process Stack Pointer + \details Returns the current value of the Process Stack Pointer (PSP). + \return PSP Register value + */ +__STATIC_INLINE uint32_t __get_PSP(void) +{ + register uint32_t __regProcessStackPointer __ASM("psp"); + return(__regProcessStackPointer); +} + + +/** + \brief Set Process Stack Pointer + \details Assigns the given value to the Process Stack Pointer (PSP). + \param [in] topOfProcStack Process Stack Pointer value to set + */ +__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) +{ + register uint32_t __regProcessStackPointer __ASM("psp"); + __regProcessStackPointer = topOfProcStack; +} + + +/** + \brief Get Main Stack Pointer + \details Returns the current value of the Main Stack Pointer (MSP). + \return MSP Register value + */ +__STATIC_INLINE uint32_t __get_MSP(void) +{ + register uint32_t __regMainStackPointer __ASM("msp"); + return(__regMainStackPointer); +} + + +/** + \brief Set Main Stack Pointer + \details Assigns the given value to the Main Stack Pointer (MSP). + \param [in] topOfMainStack Main Stack Pointer value to set + */ +__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) +{ + register uint32_t __regMainStackPointer __ASM("msp"); + __regMainStackPointer = topOfMainStack; +} + + +/** + \brief Get Priority Mask + \details Returns the current state of the priority mask bit from the Priority Mask Register. + \return Priority Mask value + */ +__STATIC_INLINE uint32_t __get_PRIMASK(void) +{ + register uint32_t __regPriMask __ASM("primask"); + return(__regPriMask); +} + + +/** + \brief Set Priority Mask + \details Assigns the given value to the Priority Mask Register. + \param [in] priMask Priority Mask + */ +__STATIC_INLINE void __set_PRIMASK(uint32_t priMask) +{ + register uint32_t __regPriMask __ASM("primask"); + __regPriMask = (priMask); +} + + +#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) + +/** + \brief Enable FIQ + \details Enables FIQ interrupts by clearing the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +#define __enable_fault_irq __enable_fiq + + +/** + \brief Disable FIQ + \details Disables FIQ interrupts by setting the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +#define __disable_fault_irq __disable_fiq + + +/** + \brief Get Base Priority + \details Returns the current value of the Base Priority register. + \return Base Priority register value + */ +__STATIC_INLINE uint32_t __get_BASEPRI(void) +{ + register uint32_t __regBasePri __ASM("basepri"); + return(__regBasePri); +} + + +/** + \brief Set Base Priority + \details Assigns the given value to the Base Priority register. + \param [in] basePri Base Priority value to set + */ +__STATIC_INLINE void __set_BASEPRI(uint32_t basePri) +{ + register uint32_t __regBasePri __ASM("basepri"); + __regBasePri = (basePri & 0xFFU); +} + + +/** + \brief Set Base Priority with condition + \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, + or the new value increases the BASEPRI priority level. + \param [in] basePri Base Priority value to set + */ +__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri) +{ + register uint32_t __regBasePriMax __ASM("basepri_max"); + __regBasePriMax = (basePri & 0xFFU); +} + + +/** + \brief Get Fault Mask + \details Returns the current value of the Fault Mask register. + \return Fault Mask register value + */ +__STATIC_INLINE uint32_t __get_FAULTMASK(void) +{ + register uint32_t __regFaultMask __ASM("faultmask"); + return(__regFaultMask); +} + + +/** + \brief Set Fault Mask + \details Assigns the given value to the Fault Mask register. + \param [in] faultMask Fault Mask value to set + */ +__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) +{ + register uint32_t __regFaultMask __ASM("faultmask"); + __regFaultMask = (faultMask & (uint32_t)1); +} + +#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */ + + +#if (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) + +/** + \brief Get FPSCR + \details Returns the current value of the Floating Point Status/Control register. + \return Floating Point Status/Control register value + */ +__STATIC_INLINE uint32_t __get_FPSCR(void) +{ +#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U) + register uint32_t __regfpscr __ASM("fpscr"); + return(__regfpscr); +#else + return(0U); +#endif +} + + +/** + \brief Set FPSCR + \details Assigns the given value to the Floating Point Status/Control register. + \param [in] fpscr Floating Point Status/Control value to set + */ +__STATIC_INLINE void __set_FPSCR(uint32_t fpscr) +{ +#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U) + register uint32_t __regfpscr __ASM("fpscr"); + __regfpscr = (fpscr); +#endif +} + +#endif /* (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) */ + + + +/*@} end of CMSIS_Core_RegAccFunctions */ + + +/* ########################## Core Instruction Access ######################### */ +/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface + Access to dedicated instructions + @{ +*/ + +/** + \brief No Operation + \details No Operation does nothing. This instruction can be used for code alignment purposes. + */ +#define __NOP __nop + + +/** + \brief Wait For Interrupt + \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. + */ +#define __WFI __wfi + + +/** + \brief Wait For Event + \details Wait For Event is a hint instruction that permits the processor to enter + a low-power state until one of a number of events occurs. + */ +#define __WFE __wfe + + +/** + \brief Send Event + \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. + */ +#define __SEV __sev + + +/** + \brief Instruction Synchronization Barrier + \details Instruction Synchronization Barrier flushes the pipeline in the processor, + so that all instructions following the ISB are fetched from cache or memory, + after the instruction has been completed. + */ +#define __ISB() do {\ + __schedule_barrier();\ + __isb(0xF);\ + __schedule_barrier();\ + } while (0U) + +/** + \brief Data Synchronization Barrier + \details Acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. + */ +#define __DSB() do {\ + __schedule_barrier();\ + __dsb(0xF);\ + __schedule_barrier();\ + } while (0U) + +/** + \brief Data Memory Barrier + \details Ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. + */ +#define __DMB() do {\ + __schedule_barrier();\ + __dmb(0xF);\ + __schedule_barrier();\ + } while (0U) + +/** + \brief Reverse byte order (32 bit) + \details Reverses the byte order in integer value. + \param [in] value Value to reverse + \return Reversed value + */ +#define __REV __rev + + +/** + \brief Reverse byte order (16 bit) + \details Reverses the byte order in two unsigned short values. + \param [in] value Value to reverse + \return Reversed value + */ +#ifndef __NO_EMBEDDED_ASM +__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value) +{ + rev16 r0, r0 + bx lr +} +#endif + +/** + \brief Reverse byte order in signed short value + \details Reverses the byte order in a signed short value with sign extension to integer. + \param [in] value Value to reverse + \return Reversed value + */ +#ifndef __NO_EMBEDDED_ASM +__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value) +{ + revsh r0, r0 + bx lr +} +#endif + + +/** + \brief Rotate Right in unsigned value (32 bit) + \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. + \param [in] value Value to rotate + \param [in] value Number of Bits to rotate + \return Rotated value + */ +#define __ROR __ror + + +/** + \brief Breakpoint + \details Causes the processor to enter Debug state. + Debug tools can use this to investigate system state when the instruction at a particular address is reached. + \param [in] value is ignored by the processor. + If required, a debugger can use it to store additional information about the breakpoint. + */ +#define __BKPT(value) __breakpoint(value) + + +/** + \brief Reverse bit order of value + \details Reverses the bit order of the given value. + \param [in] value Value to reverse + \return Reversed value + */ +#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) + #define __RBIT __rbit +#else +__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) +{ + uint32_t result; + int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */ + + result = value; /* r will be reversed bits of v; first get LSB of v */ + for (value >>= 1U; value; value >>= 1U) + { + result <<= 1U; + result |= value & 1U; + s--; + } + result <<= s; /* shift when v's highest bits are zero */ + return(result); +} +#endif + + +/** + \brief Count leading zeros + \details Counts the number of leading zeros of a data value. + \param [in] value Value to count the leading zeros + \return number of leading zeros in value + */ +#define __CLZ __clz + + +#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) + +/** + \brief LDR Exclusive (8 bit) + \details Executes a exclusive LDR instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) +#else + #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop") +#endif + + +/** + \brief LDR Exclusive (16 bit) + \details Executes a exclusive LDR instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) +#else + #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop") +#endif + + +/** + \brief LDR Exclusive (32 bit) + \details Executes a exclusive LDR instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) +#else + #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop") +#endif + + +/** + \brief STR Exclusive (8 bit) + \details Executes a exclusive STR instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __STREXB(value, ptr) __strex(value, ptr) +#else + #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#endif + + +/** + \brief STR Exclusive (16 bit) + \details Executes a exclusive STR instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __STREXH(value, ptr) __strex(value, ptr) +#else + #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#endif + + +/** + \brief STR Exclusive (32 bit) + \details Executes a exclusive STR instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __STREXW(value, ptr) __strex(value, ptr) +#else + #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#endif + + +/** + \brief Remove the exclusive lock + \details Removes the exclusive lock which is created by LDREX. + */ +#define __CLREX __clrex + + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +#define __SSAT __ssat + + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +#define __USAT __usat + + +/** + \brief Rotate Right with Extend (32 bit) + \details Moves each bit of a bitstring right by one bit. + The carry input is shifted in at the left end of the bitstring. + \param [in] value Value to rotate + \return Rotated value + */ +#ifndef __NO_EMBEDDED_ASM +__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value) +{ + rrx r0, r0 + bx lr +} +#endif + + +/** + \brief LDRT Unprivileged (8 bit) + \details Executes a Unprivileged LDRT instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +#define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr)) + + +/** + \brief LDRT Unprivileged (16 bit) + \details Executes a Unprivileged LDRT instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +#define __LDRHT(ptr) ((uint16_t) __ldrt(ptr)) + + +/** + \brief LDRT Unprivileged (32 bit) + \details Executes a Unprivileged LDRT instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#define __LDRT(ptr) ((uint32_t ) __ldrt(ptr)) + + +/** + \brief STRT Unprivileged (8 bit) + \details Executes a Unprivileged STRT instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +#define __STRBT(value, ptr) __strt(value, ptr) + + +/** + \brief STRT Unprivileged (16 bit) + \details Executes a Unprivileged STRT instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +#define __STRHT(value, ptr) __strt(value, ptr) + + +/** + \brief STRT Unprivileged (32 bit) + \details Executes a Unprivileged STRT instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +#define __STRT(value, ptr) __strt(value, ptr) + +#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */ + +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ + + +/* ################### Compiler specific Intrinsics ########################### */ +/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics + Access to dedicated SIMD instructions + @{ +*/ + +#if (__CORTEX_M >= 0x04U) /* only for Cortex-M4 and above */ + +#define __SADD8 __sadd8 +#define __QADD8 __qadd8 +#define __SHADD8 __shadd8 +#define __UADD8 __uadd8 +#define __UQADD8 __uqadd8 +#define __UHADD8 __uhadd8 +#define __SSUB8 __ssub8 +#define __QSUB8 __qsub8 +#define __SHSUB8 __shsub8 +#define __USUB8 __usub8 +#define __UQSUB8 __uqsub8 +#define __UHSUB8 __uhsub8 +#define __SADD16 __sadd16 +#define __QADD16 __qadd16 +#define __SHADD16 __shadd16 +#define __UADD16 __uadd16 +#define __UQADD16 __uqadd16 +#define __UHADD16 __uhadd16 +#define __SSUB16 __ssub16 +#define __QSUB16 __qsub16 +#define __SHSUB16 __shsub16 +#define __USUB16 __usub16 +#define __UQSUB16 __uqsub16 +#define __UHSUB16 __uhsub16 +#define __SASX __sasx +#define __QASX __qasx +#define __SHASX __shasx +#define __UASX __uasx +#define __UQASX __uqasx +#define __UHASX __uhasx +#define __SSAX __ssax +#define __QSAX __qsax +#define __SHSAX __shsax +#define __USAX __usax +#define __UQSAX __uqsax +#define __UHSAX __uhsax +#define __USAD8 __usad8 +#define __USADA8 __usada8 +#define __SSAT16 __ssat16 +#define __USAT16 __usat16 +#define __UXTB16 __uxtb16 +#define __UXTAB16 __uxtab16 +#define __SXTB16 __sxtb16 +#define __SXTAB16 __sxtab16 +#define __SMUAD __smuad +#define __SMUADX __smuadx +#define __SMLAD __smlad +#define __SMLADX __smladx +#define __SMLALD __smlald +#define __SMLALDX __smlaldx +#define __SMUSD __smusd +#define __SMUSDX __smusdx +#define __SMLSD __smlsd +#define __SMLSDX __smlsdx +#define __SMLSLD __smlsld +#define __SMLSLDX __smlsldx +#define __SEL __sel +#define __QADD __qadd +#define __QSUB __qsub + +#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ + ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) + +#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ + ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) + +#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \ + ((int64_t)(ARG3) << 32U) ) >> 32U)) + +#endif /* (__CORTEX_M >= 0x04) */ +/*@} end of group CMSIS_SIMD_intrinsics */ + + +#endif /* __CMSIS_ARMCC_H */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/core_cm0.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/core_cm0.h new file mode 100644 index 0000000..9d7a19f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/core_cm0.h @@ -0,0 +1,665 @@ +/**************************************************************************//** + * @file core_cm0.h + * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File + * @version V2.10 + * @date 19. July 2011 + * + * @note + * Copyright (C) 2009-2011 ARM Limited. All rights reserved. + * + * @par + * ARM Limited (ARM) is supplying this software for use with Cortex-M + * processor based microcontrollers. This file can be freely distributed + * within development tools that are supporting such ARM based processors. + * + * @par + * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. + * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR + * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. + * + ******************************************************************************/ +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#endif + +#ifdef __cplusplus + extern "C" { +#endif + +#ifndef __CORE_CM0_H_GENERIC +#define __CORE_CM0_H_GENERIC + + +/** \mainpage CMSIS Cortex-M0 + + This documentation describes the CMSIS Cortex-M Core Peripheral Access Layer. + It consists of: + + - Cortex-M Core Register Definitions + - Cortex-M functions + - Cortex-M instructions + + The CMSIS Cortex-M0 Core Peripheral Access Layer contains C and assembly functions that ease + access to the Cortex-M Core + */ + +/** \defgroup CMSIS_MISRA_Exceptions CMSIS MISRA-C:2004 Compliance Exceptions + CMSIS violates following MISRA-C2004 Rules: + + - Violates MISRA 2004 Required Rule 8.5, object/function definition in header file.
+ Function definitions in header files are used to allow 'inlining'. + + - Violates MISRA 2004 Required Rule 18.4, declaration of union type or object of union type: '{...}'.
+ Unions are used for effective representation of core registers. + + - Violates MISRA 2004 Advisory Rule 19.7, Function-like macro defined.
+ Function-like macros are used to allow more efficient code. + + */ + + +/******************************************************************************* + * CMSIS definitions + ******************************************************************************/ +/** \defgroup CMSIS_core_definitions CMSIS Core Definitions + This file defines all structures and symbols for CMSIS core: + - CMSIS version number + - Cortex-M core + - Cortex-M core Revision Number + @{ + */ + +/* CMSIS CM0 definitions */ +#define __CM0_CMSIS_VERSION_MAIN (0x02) /*!< [31:16] CMSIS HAL main version */ +#define __CM0_CMSIS_VERSION_SUB (0x10) /*!< [15:0] CMSIS HAL sub version */ +#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16) | __CM0_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */ + +#define __CORTEX_M (0x00) /*!< Cortex core */ + + +#if defined ( __CC_ARM ) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ + +#elif defined ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + +#elif defined ( __TASKING__ ) + #define __ASM __asm /*!< asm keyword for TASKING Compiler */ + #define __INLINE inline /*!< inline keyword for TASKING Compiler */ + +#endif + +/*!< __FPU_USED to be checked prior to making use of FPU specific registers and functions */ +#define __FPU_USED 0 + +#if defined ( __CC_ARM ) + #if defined __TARGET_FPU_VFP + #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif +#elif defined ( __ICCARM__ ) + #if defined __ARMVFP__ + #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined ( __GNUC__ ) + #if defined (__VFP_FP__) && !defined(__SOFTFP__) + #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined ( __TASKING__ ) + /* add preprocessor checks */ +#endif + +#include /*!< standard types definitions */ +#include "core_cmInstr.h" /*!< Core Instruction Access */ +#include "core_cmFunc.h" /*!< Core Function Access */ + +#endif /* __CORE_CM0_H_GENERIC */ + +#ifndef __CMSIS_GENERIC + +#ifndef __CORE_CM0_H_DEPENDANT +#define __CORE_CM0_H_DEPENDANT + +/* check device defines and use defaults */ +#if defined __CHECK_DEVICE_DEFINES + #ifndef __CM0_REV + #define __CM0_REV 0x0000 + #warning "__CM0_REV not defined in device header file; using default!" + #endif + + #ifndef __NVIC_PRIO_BITS + #define __NVIC_PRIO_BITS 2 + #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" + #endif + + #ifndef __Vendor_SysTickConfig + #define __Vendor_SysTickConfig 0 + #warning "__Vendor_SysTickConfig not defined in device header file; using default!" + #endif +#endif + +/* IO definitions (access restrictions to peripheral registers) */ +#ifdef __cplusplus + #define __I volatile /*!< defines 'read only' permissions */ +#else + #define __I volatile const /*!< defines 'read only' permissions */ +#endif +#define __O volatile /*!< defines 'write only' permissions */ +#define __IO volatile /*!< defines 'read / write' permissions */ + +/*@} end of group CMSIS_core_definitions */ + + + +/******************************************************************************* + * Register Abstraction + ******************************************************************************/ +/** \defgroup CMSIS_core_register CMSIS Core Register + Core Register contain: + - Core Register + - Core NVIC Register + - Core SCB Register + - Core SysTick Register +*/ + +/** \ingroup CMSIS_core_register + \defgroup CMSIS_CORE CMSIS Core + Type definitions for the Cortex-M Core Registers + @{ + */ + +/** \brief Union type to access the Application Program Status Register (APSR). + */ +typedef union +{ + struct + { +#if (__CORTEX_M != 0x04) + uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */ +#else + uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */ + uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ +#endif + uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ + uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C:1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ + uint32_t N:1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} APSR_Type; + + +/** \brief Union type to access the Interrupt Program Status Register (IPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} IPSR_Type; + + +/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ +#if (__CORTEX_M != 0x04) + uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ +#else + uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */ + uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ +#endif + uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ + uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ + uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ + uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C:1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ + uint32_t N:1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} xPSR_Type; + + +/** \brief Union type to access the Control Registers (CONTROL). + */ +typedef union +{ + struct + { + uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ + uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ + uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */ + uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} CONTROL_Type; + +/*@} end of group CMSIS_CORE */ + + +/** \ingroup CMSIS_core_register + \defgroup CMSIS_NVIC CMSIS NVIC + Type definitions for the Cortex-M NVIC Registers + @{ + */ + +/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). + */ +typedef struct +{ + __IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ + uint32_t RESERVED0[31]; + __IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ + uint32_t RSERVED1[31]; + __IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ + uint32_t RESERVED2[31]; + __IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ + uint32_t RESERVED3[31]; + uint32_t RESERVED4[64]; + __IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */ +} NVIC_Type; + +/*@} end of group CMSIS_NVIC */ + + +/** \ingroup CMSIS_core_register + \defgroup CMSIS_SCB CMSIS SCB + Type definitions for the Cortex-M System Control Block Registers + @{ + */ + +/** \brief Structure type to access the System Control Block (SCB). + */ +typedef struct +{ + __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ + __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ + uint32_t RESERVED0; + __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ + __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ + __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ + uint32_t RESERVED1; + __IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */ + __IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ +} SCB_Type; + +/* SCB CPUID Register Definitions */ +#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */ +#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ + +#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */ +#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ + +#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */ +#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ + +#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */ +#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ + +#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */ +#define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */ + +/* SCB Interrupt Control State Register Definitions */ +#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */ +#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ + +#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */ +#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ + +#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */ +#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ + +#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */ +#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ + +#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */ +#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ + +#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */ +#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ + +#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */ +#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ + +#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */ +#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ + +#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */ +#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */ + +/* SCB Application Interrupt and Reset Control Register Definitions */ +#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */ +#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ + +#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */ +#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ + +#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */ +#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ + +#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */ +#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ + +#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */ +#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ + +/* SCB System Control Register Definitions */ +#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */ +#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ + +#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */ +#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ + +#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */ +#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ + +/* SCB Configuration Control Register Definitions */ +#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */ +#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ + +#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */ +#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ + +/* SCB System Handler Control and State Register Definitions */ +#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */ +#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ + +/*@} end of group CMSIS_SCB */ + + +/** \ingroup CMSIS_core_register + \defgroup CMSIS_SysTick CMSIS SysTick + Type definitions for the Cortex-M System Timer Registers + @{ + */ + +/** \brief Structure type to access the System Timer (SysTick). + */ +typedef struct +{ + __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ + __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ + __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ + __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ +} SysTick_Type; + +/* SysTick Control / Status Register Definitions */ +#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */ +#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ + +#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */ +#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ + +#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */ +#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ + +#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */ +#define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */ + +/* SysTick Reload Register Definitions */ +#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */ +#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */ + +/* SysTick Current Register Definitions */ +#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */ +#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */ + +/* SysTick Calibration Register Definitions */ +#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */ +#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ + +#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */ +#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ + +#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */ +#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */ + +/*@} end of group CMSIS_SysTick */ + + +/** \ingroup CMSIS_core_register + \defgroup CMSIS_CoreDebug CMSIS Core Debug + Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP + and not via processor. Therefore they are not covered by the Cortex-M0 header file. + @{ + */ +/*@} end of group CMSIS_CoreDebug */ + + +/** \ingroup CMSIS_core_register + @{ + */ + +/* Memory mapping of Cortex-M0 Hardware */ +#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ +#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ +#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ +#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ +#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ + +#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ +#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ +#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ + + +/*@} */ + + + +/******************************************************************************* + * Hardware Abstraction Layer + ******************************************************************************/ +/** \defgroup CMSIS_Core_FunctionInterface CMSIS Core Function Interface + Core Function Interface contains: + - Core NVIC Functions + - Core SysTick Functions + - Core Register Access Functions +*/ + + + +/* ########################## NVIC functions #################################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_NVICFunctions CMSIS Core NVIC Functions + @{ + */ + +/* Interrupt Priorities are WORD accessible only under ARMv6M */ +/* The following MACROS handle generation of the register offset and byte masks */ +#define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 ) +#define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) ) +#define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) ) + + +/** \brief Enable External Interrupt + + This function enables a device specific interrupt in the NVIC interrupt controller. + The interrupt number cannot be a negative value. + + \param [in] IRQn Number of the external interrupt to enable + */ +static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) +{ + NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); +} + + +/** \brief Disable External Interrupt + + This function disables a device specific interrupt in the NVIC interrupt controller. + The interrupt number cannot be a negative value. + + \param [in] IRQn Number of the external interrupt to disable + */ +static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) +{ + NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); +} + + +/** \brief Get Pending Interrupt + + This function reads the pending register in the NVIC and returns the pending bit + for the specified interrupt. + + \param [in] IRQn Number of the interrupt for get pending + \return 0 Interrupt status is not pending + \return 1 Interrupt status is pending + */ +static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) +{ + return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); +} + + +/** \brief Set Pending Interrupt + + This function sets the pending bit for the specified interrupt. + The interrupt number cannot be a negative value. + + \param [in] IRQn Number of the interrupt for set pending + */ +static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) +{ + NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); +} + + +/** \brief Clear Pending Interrupt + + This function clears the pending bit for the specified interrupt. + The interrupt number cannot be a negative value. + + \param [in] IRQn Number of the interrupt for clear pending + */ +static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) +{ + NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */ +} + + +/** \brief Set Interrupt Priority + + This function sets the priority for the specified interrupt. The interrupt + number can be positive to specify an external (device specific) + interrupt, or negative to specify an internal (core) interrupt. + + Note: The priority cannot be set for every core interrupt. + + \param [in] IRQn Number of the interrupt for set priority + \param [in] priority Priority to set + */ +static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) +{ + if(IRQn < 0) { + SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) | + (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); } + else { + NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) | + (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); } +} + + +/** \brief Get Interrupt Priority + + This function reads the priority for the specified interrupt. The interrupt + number can be positive to specify an external (device specific) + interrupt, or negative to specify an internal (core) interrupt. + + The returned priority value is automatically aligned to the implemented + priority bits of the microcontroller. + + \param [in] IRQn Number of the interrupt for get priority + \return Interrupt Priority + */ +static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn) +{ + + if(IRQn < 0) { + return((uint32_t)((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */ + else { + return((uint32_t)((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */ +} + + +/** \brief System Reset + + This function initiate a system reset request to reset the MCU. + */ +static __INLINE void NVIC_SystemReset(void) +{ + __DSB(); /* Ensure all outstanding memory accesses included + buffered write are completed before reset */ + SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | + SCB_AIRCR_SYSRESETREQ_Msk); + __DSB(); /* Ensure completion of memory access */ + while(1); /* wait until reset */ +} + +/*@} end of CMSIS_Core_NVICFunctions */ + + + +/* ################################## SysTick function ############################################ */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_SysTickFunctions CMSIS Core SysTick Functions + @{ + */ + +#if (__Vendor_SysTickConfig == 0) + +/** \brief System Tick Configuration + + This function initialises the system tick timer and its interrupt and start the system tick timer. + Counter is in free running mode to generate periodical interrupts. + + \param [in] ticks Number of ticks between two interrupts + \return 0 Function succeeded + \return 1 Function failed + */ +static __INLINE uint32_t SysTick_Config(uint32_t ticks) +{ + if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */ + + SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */ + NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */ + SysTick->VAL = 0; /* Load the SysTick Counter Value */ + SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | + SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ + return (0); /* Function successful */ +} + +#endif + +/*@} end of CMSIS_Core_SysTickFunctions */ + + + + +#endif /* __CORE_CM0_H_DEPENDANT */ + +#endif /* __CMSIS_GENERIC */ + +#ifdef __cplusplus +} +#endif diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/core_cmFunc.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/core_cmFunc.h new file mode 100644 index 0000000..88819f9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/core_cmFunc.h @@ -0,0 +1,609 @@ +/**************************************************************************//** + * @file core_cmFunc.h + * @brief CMSIS Cortex-M Core Function Access Header File + * @version V2.10 + * @date 26. July 2011 + * + * @note + * Copyright (C) 2009-2011 ARM Limited. All rights reserved. + * + * @par + * ARM Limited (ARM) is supplying this software for use with Cortex-M + * processor based microcontrollers. This file can be freely distributed + * within development tools that are supporting such ARM based processors. + * + * @par + * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. + * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR + * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. + * + ******************************************************************************/ + +#ifndef __CORE_CMFUNC_H +#define __CORE_CMFUNC_H + + +/* ########################### Core Function Access ########################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions + @{ + */ + +#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ +/* ARM armcc specific functions */ + +#if (__ARMCC_VERSION < 400677) + #error "Please use ARM Compiler Toolchain V4.0.677 or later!" +#endif + +/* intrinsic void __enable_irq(); */ +/* intrinsic void __disable_irq(); */ + +/** \brief Get Control Register + + This function returns the content of the Control Register. + + \return Control Register value + */ +static __INLINE uint32_t __get_CONTROL(void) +{ + register uint32_t __regControl __ASM("control"); + return(__regControl); +} + + +/** \brief Set Control Register + + This function writes the given value to the Control Register. + + \param [in] control Control Register value to set + */ +static __INLINE void __set_CONTROL(uint32_t control) +{ + register uint32_t __regControl __ASM("control"); + __regControl = control; +} + + +/** \brief Get ISPR Register + + This function returns the content of the ISPR Register. + + \return ISPR Register value + */ +static __INLINE uint32_t __get_IPSR(void) +{ + register uint32_t __regIPSR __ASM("ipsr"); + return(__regIPSR); +} + + +/** \brief Get APSR Register + + This function returns the content of the APSR Register. + + \return APSR Register value + */ +static __INLINE uint32_t __get_APSR(void) +{ + register uint32_t __regAPSR __ASM("apsr"); + return(__regAPSR); +} + + +/** \brief Get xPSR Register + + This function returns the content of the xPSR Register. + + \return xPSR Register value + */ +static __INLINE uint32_t __get_xPSR(void) +{ + register uint32_t __regXPSR __ASM("xpsr"); + return(__regXPSR); +} + + +/** \brief Get Process Stack Pointer + + This function returns the current value of the Process Stack Pointer (PSP). + + \return PSP Register value + */ +static __INLINE uint32_t __get_PSP(void) +{ + register uint32_t __regProcessStackPointer __ASM("psp"); + return(__regProcessStackPointer); +} + + +/** \brief Set Process Stack Pointer + + This function assigns the given value to the Process Stack Pointer (PSP). + + \param [in] topOfProcStack Process Stack Pointer value to set + */ +static __INLINE void __set_PSP(uint32_t topOfProcStack) +{ + register uint32_t __regProcessStackPointer __ASM("psp"); + __regProcessStackPointer = topOfProcStack; +} + + +/** \brief Get Main Stack Pointer + + This function returns the current value of the Main Stack Pointer (MSP). + + \return MSP Register value + */ +static __INLINE uint32_t __get_MSP(void) +{ + register uint32_t __regMainStackPointer __ASM("msp"); + return(__regMainStackPointer); +} + + +/** \brief Set Main Stack Pointer + + This function assigns the given value to the Main Stack Pointer (MSP). + + \param [in] topOfMainStack Main Stack Pointer value to set + */ +static __INLINE void __set_MSP(uint32_t topOfMainStack) +{ + register uint32_t __regMainStackPointer __ASM("msp"); + __regMainStackPointer = topOfMainStack; +} + + +/** \brief Get Priority Mask + + This function returns the current state of the priority mask bit from the Priority Mask Register. + + \return Priority Mask value + */ +static __INLINE uint32_t __get_PRIMASK(void) +{ + register uint32_t __regPriMask __ASM("primask"); + return(__regPriMask); +} + + +/** \brief Set Priority Mask + + This function assigns the given value to the Priority Mask Register. + + \param [in] priMask Priority Mask + */ +static __INLINE void __set_PRIMASK(uint32_t priMask) +{ + register uint32_t __regPriMask __ASM("primask"); + __regPriMask = (priMask); +} + + +#if (__CORTEX_M >= 0x03) + +/** \brief Enable FIQ + + This function enables FIQ interrupts by clearing the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +#define __enable_fault_irq __enable_fiq + + +/** \brief Disable FIQ + + This function disables FIQ interrupts by setting the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +#define __disable_fault_irq __disable_fiq + + +/** \brief Get Base Priority + + This function returns the current value of the Base Priority register. + + \return Base Priority register value + */ +static __INLINE uint32_t __get_BASEPRI(void) +{ + register uint32_t __regBasePri __ASM("basepri"); + return(__regBasePri); +} + + +/** \brief Set Base Priority + + This function assigns the given value to the Base Priority register. + + \param [in] basePri Base Priority value to set + */ +static __INLINE void __set_BASEPRI(uint32_t basePri) +{ + register uint32_t __regBasePri __ASM("basepri"); + __regBasePri = (basePri & 0xff); +} + + +/** \brief Get Fault Mask + + This function returns the current value of the Fault Mask register. + + \return Fault Mask register value + */ +static __INLINE uint32_t __get_FAULTMASK(void) +{ + register uint32_t __regFaultMask __ASM("faultmask"); + return(__regFaultMask); +} + + +/** \brief Set Fault Mask + + This function assigns the given value to the Fault Mask register. + + \param [in] faultMask Fault Mask value to set + */ +static __INLINE void __set_FAULTMASK(uint32_t faultMask) +{ + register uint32_t __regFaultMask __ASM("faultmask"); + __regFaultMask = (faultMask & (uint32_t)1); +} + +#endif /* (__CORTEX_M >= 0x03) */ + + +#if (__CORTEX_M == 0x04) + +/** \brief Get FPSCR + + This function returns the current value of the Floating Point Status/Control register. + + \return Floating Point Status/Control register value + */ +static __INLINE uint32_t __get_FPSCR(void) +{ +#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + register uint32_t __regfpscr __ASM("fpscr"); + return(__regfpscr); +#else + return(0); +#endif +} + + +/** \brief Set FPSCR + + This function assigns the given value to the Floating Point Status/Control register. + + \param [in] fpscr Floating Point Status/Control value to set + */ +static __INLINE void __set_FPSCR(uint32_t fpscr) +{ +#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + register uint32_t __regfpscr __ASM("fpscr"); + __regfpscr = (fpscr); +#endif +} + +#endif /* (__CORTEX_M == 0x04) */ + + +#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ +/* IAR iccarm specific functions */ + +#include + +#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ +/* GNU gcc specific functions */ + +/** \brief Enable IRQ Interrupts + + This function enables IRQ interrupts by clearing the I-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__attribute__( ( always_inline ) ) static __INLINE void __enable_irq(void) +{ + __ASM volatile ("cpsie i"); +} + + +/** \brief Disable IRQ Interrupts + + This function disables IRQ interrupts by setting the I-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__attribute__( ( always_inline ) ) static __INLINE void __disable_irq(void) +{ + __ASM volatile ("cpsid i"); +} + + +/** \brief Get Control Register + + This function returns the content of the Control Register. + + \return Control Register value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __get_CONTROL(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, control" : "=r" (result) ); + return(result); +} + + +/** \brief Set Control Register + + This function writes the given value to the Control Register. + + \param [in] control Control Register value to set + */ +__attribute__( ( always_inline ) ) static __INLINE void __set_CONTROL(uint32_t control) +{ + __ASM volatile ("MSR control, %0" : : "r" (control) ); +} + + +/** \brief Get ISPR Register + + This function returns the content of the ISPR Register. + + \return ISPR Register value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __get_IPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); + return(result); +} + + +/** \brief Get APSR Register + + This function returns the content of the APSR Register. + + \return APSR Register value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __get_APSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, apsr" : "=r" (result) ); + return(result); +} + + +/** \brief Get xPSR Register + + This function returns the content of the xPSR Register. + + \return xPSR Register value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __get_xPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); + return(result); +} + + +/** \brief Get Process Stack Pointer + + This function returns the current value of the Process Stack Pointer (PSP). + + \return PSP Register value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __get_PSP(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, psp\n" : "=r" (result) ); + return(result); +} + + +/** \brief Set Process Stack Pointer + + This function assigns the given value to the Process Stack Pointer (PSP). + + \param [in] topOfProcStack Process Stack Pointer value to set + */ +__attribute__( ( always_inline ) ) static __INLINE void __set_PSP(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) ); +} + + +/** \brief Get Main Stack Pointer + + This function returns the current value of the Main Stack Pointer (MSP). + + \return MSP Register value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __get_MSP(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, msp\n" : "=r" (result) ); + return(result); +} + + +/** \brief Set Main Stack Pointer + + This function assigns the given value to the Main Stack Pointer (MSP). + + \param [in] topOfMainStack Main Stack Pointer value to set + */ +__attribute__( ( always_inline ) ) static __INLINE void __set_MSP(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) ); +} + + +/** \brief Get Priority Mask + + This function returns the current state of the priority mask bit from the Priority Mask Register. + + \return Priority Mask value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __get_PRIMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, primask" : "=r" (result) ); + return(result); +} + + +/** \brief Set Priority Mask + + This function assigns the given value to the Priority Mask Register. + + \param [in] priMask Priority Mask + */ +__attribute__( ( always_inline ) ) static __INLINE void __set_PRIMASK(uint32_t priMask) +{ + __ASM volatile ("MSR primask, %0" : : "r" (priMask) ); +} + + +#if (__CORTEX_M >= 0x03) + +/** \brief Enable FIQ + + This function enables FIQ interrupts by clearing the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__attribute__( ( always_inline ) ) static __INLINE void __enable_fault_irq(void) +{ + __ASM volatile ("cpsie f"); +} + + +/** \brief Disable FIQ + + This function disables FIQ interrupts by setting the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__attribute__( ( always_inline ) ) static __INLINE void __disable_fault_irq(void) +{ + __ASM volatile ("cpsid f"); +} + + +/** \brief Get Base Priority + + This function returns the current value of the Base Priority register. + + \return Base Priority register value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __get_BASEPRI(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, basepri_max" : "=r" (result) ); + return(result); +} + + +/** \brief Set Base Priority + + This function assigns the given value to the Base Priority register. + + \param [in] basePri Base Priority value to set + */ +__attribute__( ( always_inline ) ) static __INLINE void __set_BASEPRI(uint32_t value) +{ + __ASM volatile ("MSR basepri, %0" : : "r" (value) ); +} + + +/** \brief Get Fault Mask + + This function returns the current value of the Fault Mask register. + + \return Fault Mask register value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __get_FAULTMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); + return(result); +} + + +/** \brief Set Fault Mask + + This function assigns the given value to the Fault Mask register. + + \param [in] faultMask Fault Mask value to set + */ +__attribute__( ( always_inline ) ) static __INLINE void __set_FAULTMASK(uint32_t faultMask) +{ + __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) ); +} + +#endif /* (__CORTEX_M >= 0x03) */ + + +#if (__CORTEX_M == 0x04) + +/** \brief Get FPSCR + + This function returns the current value of the Floating Point Status/Control register. + + \return Floating Point Status/Control register value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __get_FPSCR(void) +{ +#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + uint32_t result; + + __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); + return(result); +#else + return(0); +#endif +} + + +/** \brief Set FPSCR + + This function assigns the given value to the Floating Point Status/Control register. + + \param [in] fpscr Floating Point Status/Control value to set + */ +__attribute__( ( always_inline ) ) static __INLINE void __set_FPSCR(uint32_t fpscr) +{ +#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) ); +#endif +} + +#endif /* (__CORTEX_M == 0x04) */ + + +#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ +/* TASKING carm specific functions */ + +/* + * The CMSIS functions have been implemented as intrinsics in the compiler. + * Please use "carm -?i" to get an up to date list of all instrinsics, + * Including the CMSIS ones. + */ + +#endif + +/*@} end of CMSIS_Core_RegAccFunctions */ + + +#endif /* __CORE_CMFUNC_H */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/core_cmInstr.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/core_cmInstr.h new file mode 100644 index 0000000..78d2ef8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/core/core_cmInstr.h @@ -0,0 +1,585 @@ +/**************************************************************************//** + * @file core_cmInstr.h + * @brief CMSIS Cortex-M Core Instruction Access Header File + * @version V2.10 + * @date 19. July 2011 + * + * @note + * Copyright (C) 2009-2011 ARM Limited. All rights reserved. + * + * @par + * ARM Limited (ARM) is supplying this software for use with Cortex-M + * processor based microcontrollers. This file can be freely distributed + * within development tools that are supporting such ARM based processors. + * + * @par + * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. + * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR + * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. + * + ******************************************************************************/ + +#ifndef __CORE_CMINSTR_H +#define __CORE_CMINSTR_H + + +/* ########################## Core Instruction Access ######################### */ +/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface + Access to dedicated instructions + @{ +*/ + +#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ +/* ARM armcc specific functions */ + +#if (__ARMCC_VERSION < 400677) + #error "Please use ARM Compiler Toolchain V4.0.677 or later!" +#endif + + +/** \brief No Operation + + No Operation does nothing. This instruction can be used for code alignment purposes. + */ +#define __NOP __nop + + +/** \brief Wait For Interrupt + + Wait For Interrupt is a hint instruction that suspends execution + until one of a number of events occurs. + */ +#define __WFI __wfi + + +/** \brief Wait For Event + + Wait For Event is a hint instruction that permits the processor to enter + a low-power state until one of a number of events occurs. + */ +#define __WFE __wfe + + +/** \brief Send Event + + Send Event is a hint instruction. It causes an event to be signaled to the CPU. + */ +#define __SEV __sev + + +/** \brief Instruction Synchronization Barrier + + Instruction Synchronization Barrier flushes the pipeline in the processor, + so that all instructions following the ISB are fetched from cache or + memory, after the instruction has been completed. + */ +#define __ISB() __isb(0xF) + + +/** \brief Data Synchronization Barrier + + This function acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. + */ +#define __DSB() __dsb(0xF) + + +/** \brief Data Memory Barrier + + This function ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. + */ +#define __DMB() __dmb(0xF) + + +/** \brief Reverse byte order (32 bit) + + This function reverses the byte order in integer value. + + \param [in] value Value to reverse + \return Reversed value + */ +#define __REV __rev + + +/** \brief Reverse byte order (16 bit) + + This function reverses the byte order in two unsigned short values. + + \param [in] value Value to reverse + \return Reversed value + */ +static __INLINE __ASM uint32_t __REV16(uint32_t value) +{ + rev16 r0, r0 + bx lr +} + + +/** \brief Reverse byte order in signed short value + + This function reverses the byte order in a signed short value with sign extension to integer. + + \param [in] value Value to reverse + \return Reversed value + */ +static __INLINE __ASM int32_t __REVSH(int32_t value) +{ + revsh r0, r0 + bx lr +} + + +#if (__CORTEX_M >= 0x03) + +/** \brief Reverse bit order of value + + This function reverses the bit order of the given value. + + \param [in] value Value to reverse + \return Reversed value + */ +#define __RBIT __rbit + + +/** \brief LDR Exclusive (8 bit) + + This function performs a exclusive LDR command for 8 bit value. + + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) + + +/** \brief LDR Exclusive (16 bit) + + This function performs a exclusive LDR command for 16 bit values. + + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) + + +/** \brief LDR Exclusive (32 bit) + + This function performs a exclusive LDR command for 32 bit values. + + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) + + +/** \brief STR Exclusive (8 bit) + + This function performs a exclusive STR command for 8 bit values. + + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STREXB(value, ptr) __strex(value, ptr) + + +/** \brief STR Exclusive (16 bit) + + This function performs a exclusive STR command for 16 bit values. + + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STREXH(value, ptr) __strex(value, ptr) + + +/** \brief STR Exclusive (32 bit) + + This function performs a exclusive STR command for 32 bit values. + + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STREXW(value, ptr) __strex(value, ptr) + + +/** \brief Remove the exclusive lock + + This function removes the exclusive lock which is created by LDREX. + + */ +#define __CLREX __clrex + + +/** \brief Signed Saturate + + This function saturates a signed value. + + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +#define __SSAT __ssat + + +/** \brief Unsigned Saturate + + This function saturates an unsigned value. + + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +#define __USAT __usat + + +/** \brief Count leading zeros + + This function counts the number of leading zeros of a data value. + + \param [in] value Value to count the leading zeros + \return number of leading zeros in value + */ +#define __CLZ __clz + +#endif /* (__CORTEX_M >= 0x03) */ + + + +#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ +/* IAR iccarm specific functions */ + +#include + + +#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ +/* GNU gcc specific functions */ + +/** \brief No Operation + + No Operation does nothing. This instruction can be used for code alignment purposes. + */ +__attribute__( ( always_inline ) ) static __INLINE void __NOP(void) +{ + __ASM volatile ("nop"); +} + + +/** \brief Wait For Interrupt + + Wait For Interrupt is a hint instruction that suspends execution + until one of a number of events occurs. + */ +__attribute__( ( always_inline ) ) static __INLINE void __WFI(void) +{ + __ASM volatile ("wfi"); +} + + +/** \brief Wait For Event + + Wait For Event is a hint instruction that permits the processor to enter + a low-power state until one of a number of events occurs. + */ +__attribute__( ( always_inline ) ) static __INLINE void __WFE(void) +{ + __ASM volatile ("wfe"); +} + + +/** \brief Send Event + + Send Event is a hint instruction. It causes an event to be signaled to the CPU. + */ +__attribute__( ( always_inline ) ) static __INLINE void __SEV(void) +{ + __ASM volatile ("sev"); +} + + +/** \brief Instruction Synchronization Barrier + + Instruction Synchronization Barrier flushes the pipeline in the processor, + so that all instructions following the ISB are fetched from cache or + memory, after the instruction has been completed. + */ +__attribute__( ( always_inline ) ) static __INLINE void __ISB(void) +{ + __ASM volatile ("isb"); +} + + +/** \brief Data Synchronization Barrier + + This function acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. + */ +__attribute__( ( always_inline ) ) static __INLINE void __DSB(void) +{ + __ASM volatile ("dsb"); +} + + +/** \brief Data Memory Barrier + + This function ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. + */ +__attribute__( ( always_inline ) ) static __INLINE void __DMB(void) +{ + __ASM volatile ("dmb"); +} + + +/** \brief Reverse byte order (32 bit) + + This function reverses the byte order in integer value. + + \param [in] value Value to reverse + \return Reversed value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __REV(uint32_t value) +{ + uint32_t result; + + __ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) ); + return(result); +} + + +/** \brief Reverse byte order (16 bit) + + This function reverses the byte order in two unsigned short values. + + \param [in] value Value to reverse + \return Reversed value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __REV16(uint32_t value) +{ + uint32_t result; + + __ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) ); + return(result); +} + + +/** \brief Reverse byte order in signed short value + + This function reverses the byte order in a signed short value with sign extension to integer. + + \param [in] value Value to reverse + \return Reversed value + */ +__attribute__( ( always_inline ) ) static __INLINE int32_t __REVSH(int32_t value) +{ + uint32_t result; + + __ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) ); + return(result); +} + + +#if (__CORTEX_M >= 0x03) + +/** \brief Reverse bit order of value + + This function reverses the bit order of the given value. + + \param [in] value Value to reverse + \return Reversed value + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __RBIT(uint32_t value) +{ + uint32_t result; + + __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); + return(result); +} + + +/** \brief LDR Exclusive (8 bit) + + This function performs a exclusive LDR command for 8 bit value. + + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__attribute__( ( always_inline ) ) static __INLINE uint8_t __LDREXB(volatile uint8_t *addr) +{ + uint8_t result; + + __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) ); + return(result); +} + + +/** \brief LDR Exclusive (16 bit) + + This function performs a exclusive LDR command for 16 bit values. + + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__attribute__( ( always_inline ) ) static __INLINE uint16_t __LDREXH(volatile uint16_t *addr) +{ + uint16_t result; + + __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) ); + return(result); +} + + +/** \brief LDR Exclusive (32 bit) + + This function performs a exclusive LDR command for 32 bit values. + + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __LDREXW(volatile uint32_t *addr) +{ + uint32_t result; + + __ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) ); + return(result); +} + + +/** \brief STR Exclusive (8 bit) + + This function performs a exclusive STR command for 8 bit values. + + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) +{ + uint32_t result; + + __ASM volatile ("strexb %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); + return(result); +} + + +/** \brief STR Exclusive (16 bit) + + This function performs a exclusive STR command for 16 bit values. + + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) +{ + uint32_t result; + + __ASM volatile ("strexh %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); + return(result); +} + + +/** \brief STR Exclusive (32 bit) + + This function performs a exclusive STR command for 32 bit values. + + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) +{ + uint32_t result; + + __ASM volatile ("strex %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); + return(result); +} + + +/** \brief Remove the exclusive lock + + This function removes the exclusive lock which is created by LDREX. + + */ +__attribute__( ( always_inline ) ) static __INLINE void __CLREX(void) +{ + __ASM volatile ("clrex"); +} + + +/** \brief Signed Saturate + + This function saturates a signed value. + + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +#define __SSAT(ARG1,ARG2) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1); \ + __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + + +/** \brief Unsigned Saturate + + This function saturates an unsigned value. + + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +#define __USAT(ARG1,ARG2) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1); \ + __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + + +/** \brief Count leading zeros + + This function counts the number of leading zeros of a data value. + + \param [in] value Value to count the leading zeros + \return number of leading zeros in value + */ +__attribute__( ( always_inline ) ) static __INLINE uint8_t __CLZ(uint32_t value) +{ + uint8_t result; + + __ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) ); + return(result); +} + +#endif /* (__CORTEX_M >= 0x03) */ + + + + +#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ +/* TASKING carm specific functions */ + +/* + * 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. + */ + +#endif + +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ + +#endif /* __CORE_CMINSTR_H */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/n32wb03x.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/n32wb03x.h new file mode 100644 index 0000000..7e92798 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/n32wb03x.h @@ -0,0 +1,3148 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_H__ +#define __N32WB03X_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup N32WB03X_Library_Basic + * @{ + */ + +#if !defined USE_STDPERIPH_DRIVER +/* + * Comment the line below if you will not use the peripherals drivers. + In this case, these drivers will not be included and the application code will + be based on direct access to peripherals registers + */ +#define USE_STDPERIPH_DRIVER +#endif + +/* + * In the following line adjust the value of External High Speed oscillator (HSE) + used in your application + + Tip: To avoid modifying this file each time you need to use different HSE, you + can define the HSE value in your toolchain compiler preprocessor. + */ +#if !defined HSE_VALUE +#define HSE_VALUE (32000000) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +/* + * In the following line adjust the External High Speed oscillator (HSE) Startup + Timeout value + */ +#define HSE_STARTUP_TIMEOUT ((uint16_t)0x2000) /*!< Time out for HSE start up */ +#define HSI_STARTUP_TIMEOUT ((uint16_t)0x0500) /*!< Time out for HSI start up */ +#define LSE_STARTUP_TIMEOUT ((uint16_t)0x1000) /*!< Time out for LSE start up */ +#define LSI_STARTUP_TIMEOUT ((uint16_t)0x1000) /*!< Time out for LSI start up */ + +#define HSI_VALUE (64000000) /*!< Value of the Internal oscillator in Hz*/ + +#define LSE_VALUE (32768) /*!< Value of the External Low Speed oscillator in Hz*/ +#define LSI_VALUE (32000) /*!< Value of the Internal Low Speed oscillator in Hz*/ + +#define ADC_AUDIOPLLCLK_VALUE (4096000) /*!< Value of the Internal ADC clk in Hz*/ + +#define __N32WB03X_STDPERIPH_VERSION_MAIN (0x01) /*!< [31:24] main version */ +#define __N32WB03X_STDPERIPH_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */ +#define __N32WB03X_STDPERIPH_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ +#define __N32WB03X_STDPERIPH_VERSION_RC (0x00) /*!< [7:0] release candidate */ + +/** + * @brief N32WB03X Standard Peripheral Library version number + */ +#define __N32WB03X_STDPERIPH_VERSION \ + ((__N32WB03X_STDPERIPH_VERSION_MAIN << 24) | (__N32WB03X_STDPERIPH_VERSION_SUB1 << 16) \ + | (__N32WB03X_STDPERIPH_VERSION_SUB2 << 8) | (__N32WB03X_STDPERIPH_VERSION_RC)) + +/* + * Configuration of the Cortex-M0 Processor and Core Peripherals + */ +#define __NVIC_PRIO_BITS 2 /*!< N32WB03X uses 4 Bits for the Priority Levels */ +#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */ + +/** + * @brief N32WB03X Interrupt Number Definition + */ +typedef enum IRQn +{ + /****** Cortex-M0 Processor Exceptions Numbers ***************************************************/ + NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ + HardFault_IRQn = -13, /*!< 3 Hard Fault Interrupt */ + SVCall_IRQn = -5, /*!< 11 Cortex-M0 SV Call Interrupt */ + PendSV_IRQn = -2, /*!< 14 Cortex-M0 Pend SV Interrupt */ + SysTick_IRQn = -1, /*!< 15 Cortex-M0 System Tick Interrupt */ + + /****** N32WB03X specific Interrupt Numbers ********************************************************/ + WWDG_IRQn = 0, /*!< Window WatchDog Interrupt */ + BLE_SW_IRQn = 1, /*!< BLE_SW Interrupt */ + RTC_IRQn = 2, /*!< RTC interrupt through EXTI line 17/19/20 */ + BLE_HSLOT_IRQn = 3, /*!< BLE_HSLOT Interrupt */ + FLASH_IRQn = 4, /*!< FLASH global Interrupt */ + RCC_IRQn = 5, /*!< RCC global Interrupt */ + EXTI0_1_IRQn = 6, /*!< EXTI Line0/1 Interrupt */ + EXTI2_3_IRQn = 7, /*!< EXTI Line2/3 Interrupt */ + EXTI4_12_IRQn = 8, /*!< EXTI Line4 ~ 12 Interrupt */ + BLE_FINETGT_IRQn = 9, /*!< BLE_FINETGT global Interrupt */ + BLE_FIFO_IRQn = 10, /*!< BLE_FIFO global Interrupt */ + DMA_Channel1_2_3_4_IRQn = 11, /*!< DMA Channel 1/2/3/4 global Interrupt */ + DMA_Channel5_IRQn = 12, /*!< DMA Channel 5 global Interrupt */ + TIM1_BRK_UP_TRG_COM_IRQn = 13, /*!< TIM1 Break Update Trigger and Commutation Interrupt */ + TIM1_CC_IRQn = 14, /*!< TIM1 Capture Compare Interrupt */ + RESERVED_IRQn = 15, /*!< RESERVED Interrupt */ + TIM3_IRQn = 16, /*!< TIM3 global Interrupt */ + BLE_ERROR_IRQn = 17, /*!< BLE_ERROR Interrupt */ + BLE_CRYPT_IRQn = 18, /*!< BLE_CYPT Interrupt */ + BLE_TIMESTAMP_TGT1_IRQn = 19, /*!< BLE_TIMESTAMP_TGT1 Interrupt */ + TIM6_IRQn = 20, /*!< TIM6 global Interrupts */ + ADC_IRQn = 21, /*!< ADC global Interrupts */ + SPI2_IRQn = 22, /*!< SPI2 global Interrupts */ + I2C1_IRQn = 23, /*!< I2C1 global Interrupts */ + BLE_TIMESTAMP_TGT2_IRQn = 24, /*!< BLE_TIMESTAMP_TGT12 Interrupts */ + SPI1_IRQn = 25, /*!< SPI1 global Interrupts */ + BLE_SLP_IRQn = 26, /*!< BLE_SLP global Interrupts */ + KEYSCAN_IRQn = 27, /*!< KEYSCAN Interrupt */ + USART1_IRQn = 28, /*!< USART1 global Interrupt */ + LPUART1_IRQn = 29, /*!< LPUART global Interrupt */ + USART2_IRQn = 30, /*!< USART2 global Interrupt */ + IRC_IRQn = 31, /*!< IRC global Interrupt */ +} IRQn_Type; + +#include "core_cm0.h" +#include "system_n32wb03x.h" +#include +#include + +typedef int32_t s32; +typedef int16_t s16; +typedef int8_t s8; + +typedef const int32_t sc32; /*!< Read Only */ +typedef const int16_t sc16; /*!< Read Only */ +typedef const int8_t sc8; /*!< Read Only */ + +typedef __IO int32_t vs32; +typedef __IO int16_t vs16; +typedef __IO int8_t vs8; + +typedef __I int32_t vsc32; /*!< Read Only */ +typedef __I int16_t vsc16; /*!< Read Only */ +typedef __I int8_t vsc8; /*!< Read Only */ + +typedef uint32_t u32; +typedef uint16_t u16; +typedef uint8_t u8; + +typedef const uint32_t uc32; /*!< Read Only */ +typedef const uint16_t uc16; /*!< Read Only */ +typedef const uint8_t uc8; /*!< Read Only */ + +typedef __IO uint32_t vu32; +typedef __IO uint16_t vu16; +typedef __IO uint8_t vu8; + +typedef __I uint32_t vuc32; /*!< Read Only */ +typedef __I uint16_t vuc16; /*!< Read Only */ +typedef __I uint8_t vuc8; /*!< Read Only */ +typedef enum +{ + RESET = 0, + SET = !RESET +} FlagStatus, + INTStatus; + +typedef enum +{ + DISABLE = 0, + ENABLE = !DISABLE +} FunctionalState; +#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) + +typedef enum +{ + ERROR = 0, + SUCCESS = !ERROR +} ErrorStatus; + +/* N32WB03X Standard Peripheral Library old definitions (maintained for legacy purpose) */ +#define HSEStartUp_TimeOut HSE_STARTUP_TIMEOUT +#define HSE_Value HSE_VALUE +#define HSI_Value HSI_VALUE + +/** + * @brief Analog to Digital Converter + */ +typedef struct +{ + __IO uint32_t CTRL; + __IO uint32_t SR; + __IO uint32_t OVR_SAMP_CNT; + __IO uint32_t DAT; + __IO uint32_t WDT_THRES; + __IO uint32_t FGA_CFG; + __IO uint32_t VOICE_DET_CR; + __IO uint32_t VOICE_ZCR_THRES; + __IO uint32_t VOICE_ED_THRES; + __IO uint32_t VOICE_ED_DWN_THRES; + __IO uint32_t VOICE_ED_UP_THRES; +} ADC_Module; + +/** + * @brief CRC calculation unit + */ + +typedef struct +{ + __IO uint32_t CRC32DAT; /*!< CRC data register */ + __IO uint8_t CRC32IDAT; /*!< CRC independent data register*/ + uint8_t RESERVED0; + uint16_t RESERVED1; + __IO uint32_t CRC32CTRL; /*!< CRC control register */ + __IO uint32_t CRC16CTRL; + __IO uint8_t CRC16DAT; + uint8_t RESERVED2; + uint16_t RESERVED3; + __IO uint16_t CRC16D; + uint16_t RESERVED4; + __IO uint8_t LRC; + uint8_t RESERVED5; + uint16_t RESERVED6; +} CRC_Module; + + +/** + * @brief DMA Controller + */ + +typedef struct +{ + __IO uint32_t CHCFG; + __IO uint32_t TXNUM; + __IO uint32_t PADDR; + __IO uint32_t MADDR; + __IO uint32_t CHSEL; + +} DMA_ChannelType; + +typedef struct +{ + __IO uint32_t INTSTS; + __IO uint32_t INTCLR; + __IO DMA_ChannelType DMA_Channel[5]; +} DMA_Module; + +/** + * @brief External Interrupt/Event Controller + */ + +typedef struct +{ + __IO uint32_t IMASK; /*offset 0x00*/ + __IO uint32_t EMASK; /*offset 0x04*/ + __IO uint32_t RT_CFG; /*offset 0x08*/ + __IO uint32_t FT_CFG; /*offset 0x0C*/ + __IO uint32_t SWIE; /*offset 0x10*/ + __IO uint32_t PEND; /*offset 0x14*/ +} EXTI_Module; + +/** + * @brief General Purpose I/O + */ + +typedef struct +{ + __IO uint32_t PMODE; /*offset 0x00*/ + __IO uint32_t POTYPE; /*offset 0x04*/ + __IO uint32_t SR; /*offset 0x08*/ + __IO uint32_t PUPD; /*offset 0x0C*/ + __IO uint32_t PID; /*offset 0x10*/ + __IO uint32_t POD; /*offset 0x14*/ + __IO uint32_t PBSC; /*offset 0x18*/ + __IO uint32_t PLOCK; /*offset 0x1C*/ + __IO uint32_t AFL; /*offset 0x20*/ + __IO uint32_t AFH; /*offset 0x24*/ + __IO uint32_t PBC; /*offset 0x28*/ + __IO uint32_t DS; /*offset 0x2C*/ +} GPIO_Module; + +/** + * @brief Alternate Function I/O + */ + +typedef struct +{ + __IO uint32_t CFG; + __IO uint32_t EXTI_CFG[2]; +} AFIO_Module; +/** + * @brief Inter Integrated Circuit Interface + */ + +typedef struct +{ + __IO uint16_t CTRL1; + uint16_t RESERVED0; + __IO uint16_t CTRL2; + uint16_t RESERVED1; + __IO uint16_t OADDR1; + uint16_t RESERVED2; + __IO uint16_t OADDR2; + uint16_t RESERVED3; + __IO uint16_t DAT; + uint16_t RESERVED4; + __IO uint16_t STS1; + uint16_t RESERVED5; + __IO uint16_t STS2; + uint16_t RESERVED6; + __IO uint16_t CLKCTRL; + uint16_t RESERVED7; + __IO uint16_t TMRISE; + uint16_t RESERVED8; +} I2C_Module; + +/** + * @brief Independent WATCHDOG + */ + +typedef struct +{ + __IO uint32_t KEY; + __IO uint32_t PREDIV; /*!< IWDG PREDIV */ + __IO uint32_t RELV; + __IO uint32_t STS; +} IWDG_Module; + +/** + * @brief Power Control + */ + +typedef struct +{ + __IO uint32_t CR1; + __IO uint32_t CR2; + __IO uint32_t reserved0; + __IO uint32_t reserved1; + __IO uint32_t reserved2; + __IO uint32_t reserved3; + __IO uint32_t reserved4; + __IO uint32_t reserved5; + __IO uint32_t reserved6; + __IO uint32_t reserved7; + __IO uint32_t reserved8; + __IO uint32_t reserved9; + __IO uint32_t VTOR_REG; +} PWR_Module; + +/** + * @brief Reset and Clock Control + */ + +typedef struct +{ + __IO uint32_t CTRL; + __IO uint32_t CFG; + __IO uint32_t CLKINT; + __IO uint32_t APB2PRST; + __IO uint32_t APB1PRST; + __IO uint32_t AHBPCLKEN; + __IO uint32_t APB2PCLKEN; + __IO uint32_t APB1PCLKEN; + __IO uint32_t LSCTRL; + __IO uint32_t CTRLSTS; + __IO uint32_t AHBPRST; + __IO uint32_t CFG2; + __IO uint32_t OSCFCCR; + __IO uint32_t OSCFCSR; + __IO uint32_t OSCFCLSICNT; + __IO uint32_t OSCFCHSICNT; + __IO uint32_t ROMCCR; + __IO uint32_t DBGMCU_CR; +} RCC_Module; + +/** + * @brief Real-Time Clock + */ + +typedef struct +{ + __IO uint32_t TSH; /*!< RTC time register, Address offset: 0x00 */ + __IO uint32_t DATE; /*!< RTC date register, Address offset: 0x04 */ + __IO uint32_t CTRL; /*!< RTC control register, Address offset: 0x08 */ + __IO uint32_t INITSTS; /*!< RTC initialization and status register, Address offset: 0x0C */ + __IO uint32_t PRE; /*!< RTC prescaler register, Address offset: 0x10 */ + __IO uint32_t WKUPT; /*!< RTC wakeup timer register, Address offset: 0x14 */ + uint32_t reserved0; /*!< Reserved Address offset: 0x18 */ + __IO uint32_t ALARMA; /*!< RTC alarm A register, Address offset: 0x1C */ + uint32_t reserved1; /*!< Reserved Address offset: 0x20 */ + __IO uint32_t WRP; /*!< RTC write protection register, Address offset: 0x24 */ + __IO uint32_t SUBS; /*!< RTC sub second register, Address offset: 0x28 */ + __IO uint32_t SCTRL; /*!< RTC shift control register, Address offset: 0x2C */ + uint32_t reserved2; /*!< Reserved Address offset: 0x30 */ + uint32_t reserved3; /*!< Reserved Address offset: 0x34 */ + uint32_t reserved4; /*!< Reserved Address offset: 0x38 */ + __IO uint32_t CALIB; /*!< RTC calibration register, Address offset: 0x3C */ + uint32_t reserved5; /*!< Reserved Address offset: 0x40 */ + __IO uint32_t ALRMASS; /*!< RTC alarm A sub second register, Address offset: 0x44 */ +} RTC_Module; + +/** + * @brief Serial Peripheral Interface + */ + +typedef struct +{ + __IO uint16_t CTRL1; + uint16_t RESERVED0; + __IO uint16_t CTRL2; + uint16_t RESERVED1; + __IO uint16_t STS; + uint16_t RESERVED2; + __IO uint16_t DAT; + uint16_t RESERVED3; + __IO uint16_t CRCPOLY; + uint16_t RESERVED4; + __IO uint16_t CRCRDAT; + uint16_t RESERVED5; + __IO uint16_t CRCTDAT; + uint16_t RESERVED6; + __IO uint16_t I2SCFG; + uint16_t RESERVED7; + __IO uint16_t I2SPREDIV; + uint16_t RESERVED8; +} SPI_Module; + +/** + * @brief TIM + */ + +typedef struct +{ + __IO uint32_t CTRL1; + __IO uint32_t CTRL2; + __IO uint16_t SMCTRL; + uint16_t RESERVED1; + __IO uint16_t DINTEN; + uint16_t RESERVED2; + __IO uint32_t STS; + __IO uint16_t EVTGEN; + uint16_t RESERVED3; + __IO uint16_t CCMOD1; + uint16_t RESERVED4; + __IO uint16_t CCMOD2; + uint16_t RESERVED5; + __IO uint32_t CCEN; + __IO uint16_t CNT; + uint16_t RESERVED6; + __IO uint16_t PSC; + uint16_t RESERVED7; + __IO uint16_t AR; + uint16_t RESERVED8; + __IO uint16_t REPCNT; + uint16_t RESERVED9; + __IO uint16_t CCDAT1; + uint16_t RESERVED10; + __IO uint16_t CCDAT2; + uint16_t RESERVED11; + __IO uint16_t CCDAT3; + uint16_t RESERVED12; + __IO uint16_t CCDAT4; + uint16_t RESERVED13; + __IO uint16_t BKDT; + uint16_t RESERVED14; + __IO uint16_t DCTRL; + uint16_t RESERVED15; + __IO uint16_t DADDR; + uint16_t RESERVED16; + uint32_t RESERVED17; + __IO uint16_t CCMOD3; + uint16_t RESERVED18; + __IO uint16_t CCDAT5; + uint16_t RESERVED19; + __IO uint16_t CCDAT6; + uint16_t RESERVED20; +} TIM_Module; + +/** + * @brief Universal Synchronous Asynchronous Receiver Transmitter + */ + +typedef struct +{ + __IO uint16_t STS; + uint16_t RESERVED0; + __IO uint16_t DAT; + uint16_t RESERVED1; + __IO uint16_t BRCF; + uint16_t RESERVED2; + __IO uint16_t CTRL1; + uint16_t RESERVED3; + __IO uint16_t CTRL2; + uint16_t RESERVED4; + __IO uint16_t CTRL3; + uint16_t RESERVED5; + __IO uint16_t GTP; + uint16_t RESERVED6; +} USART_Module; + +/** + * @brief Low-power Universal Asynchronous Receiver Transmitter + */ + +typedef struct +{ + __IO uint16_t STS; + uint16_t RESERVED0; + __IO uint8_t INTEN; + uint8_t RESERVED1; + uint16_t RESERVED2; + __IO uint16_t CTRL; + uint16_t RESERVED3; + __IO uint16_t BRCFG1; + uint16_t RESERVED4; + __IO uint8_t DAT; + uint8_t RESERVED5; + uint16_t RESERVED6; + __IO uint8_t BRCFG2; + uint8_t RESERVED7; + uint16_t RESERVED8; + __IO uint32_t WUDAT; +} LPUART_Module; + +/** + * @brief Window WATCHDOG + */ + +typedef struct +{ + __IO uint32_t CTRL; + __IO uint32_t CFG; + __IO uint32_t STS; +} WWDG_Module; + +/** + * @brief IRC + */ +typedef struct +{ + __IO uint32_t FREQ_CARRIER_ON; + __IO uint32_t FREQ_CARRIER_OFF; + __IO uint32_t LOGIC_ONE_TIME; + __IO uint32_t LOGIC_ZERO_TIME; + __IO uint32_t CTRL; + __IO uint32_t STATUS; + __IO uint32_t REPEAT_TIME; + __IO uint32_t CODE_FIFO; + __IO uint32_t REPEAT_FIFO; +} IRC_Module; + +/** + * @brief Keyscan Peripheral Interface + */ +typedef struct +{ + __IO uint32_t KEYCR; + __IO uint32_t KEYDATA0; + __IO uint32_t KEYDATA1; + __IO uint32_t KEYDATA2; + __IO uint32_t KEYDATA3; + __IO uint32_t KEYDATA4; +} KEYSCAN_Module; + +#define FLASH_BASE ((uint32_t)0x01000000) /*!< FLASH base address in the alias region */ +#define SRAM_BASE ((uint32_t)0x20000000) /*!< SRAM base address in the alias region */ +#define PERIPH_BASE ((uint32_t)0x40000000) /*!< Peripheral base address in the alias region */ + +/*!< Peripheral memory map */ +#define APB1PERIPH_BASE (PERIPH_BASE) +#define APB2PERIPH_BASE (PERIPH_BASE + 0x10000) +#define AHBPERIPH_BASE (PERIPH_BASE + 0x20000) + +/* APB1 */ +#define TIM3_BASE (APB1PERIPH_BASE + 0x0400) +#define TIM6_BASE (APB1PERIPH_BASE + 0x1000) +#define RTC_BASE (APB1PERIPH_BASE + 0x2800) +#define WWDG_BASE (APB1PERIPH_BASE + 0x2C00) +#define IWDG_BASE (APB1PERIPH_BASE + 0x3000) +#define USART2_BASE (APB1PERIPH_BASE + 0x4400) +#define LPUART1_BASE (APB1PERIPH_BASE + 0x4800) +#define I2C1_BASE (APB1PERIPH_BASE + 0x5400) +#define PWR_BASE (APB1PERIPH_BASE + 0x7000) + +/* APB2 */ +#define AFIO_BASE (APB2PERIPH_BASE + 0x0000) +#define EXTI_BASE (APB2PERIPH_BASE + 0x0400) +#define GPIOA_BASE (APB2PERIPH_BASE + 0x0800) +#define GPIOB_BASE (APB2PERIPH_BASE + 0x0C00) +#define AFEC_BASE (APB2PERIPH_BASE + 0x1000) +#define KEYSCAN_BASE (APB2PERIPH_BASE + 0x1400) +#define SPI1_BASE (APB2PERIPH_BASE + 0x2000) +#define TIM1_BASE (APB2PERIPH_BASE + 0x2C00) +#define USART1_BASE (APB2PERIPH_BASE + 0x3800) +#define SPI2_BASE (APB2PERIPH_BASE + 0x4400) + +/* AHB */ +#define DMA_BASE (AHBPERIPH_BASE + 0x0000) +#define DMA_CH1_BASE (AHBPERIPH_BASE + 0x0008) +#define DMA_CH2_BASE (AHBPERIPH_BASE + 0x001C) +#define DMA_CH3_BASE (AHBPERIPH_BASE + 0x0030) +#define DMA_CH4_BASE (AHBPERIPH_BASE + 0x0044) +#define DMA_CH5_BASE (AHBPERIPH_BASE + 0x0058) +#define ADC_BASE (AHBPERIPH_BASE + 0x0800) +#define RCC_BASE (AHBPERIPH_BASE + 0x1000) +#define IRC_BASE (AHBPERIPH_BASE + 0x1C00) +#define PATCH_BASE (AHBPERIPH_BASE + 0x2000) +#define MODEM_BASE (AHBPERIPH_BASE + 0x2400) +#define CRC_BASE (AHBPERIPH_BASE + 0x3000) +#define BLE_BASE (AHBPERIPH_BASE + 0x8000) +#define BLE_EM_BASE (AHBPERIPH_BASE + 0xC000) + +#define TIM3 ((TIM_Module*)TIM3_BASE) +#define TIM6 ((TIM_Module*)TIM6_BASE) +#define RTC ((RTC_Module*)RTC_BASE) +#define WWDG ((WWDG_Module*)WWDG_BASE) +#define IWDG ((IWDG_Module*)IWDG_BASE) +#define USART2 ((USART_Module*)USART2_BASE) +#define LPUART1 ((LPUART_Module*)LPUART1_BASE) +#define I2C1 ((I2C_Module*)I2C1_BASE) +#define PWR ((PWR_Module*)PWR_BASE) +#define AFIO ((AFIO_Module*)AFIO_BASE) +#define EXTI ((EXTI_Module*)EXTI_BASE) +#define GPIOA ((GPIO_Module*)GPIOA_BASE) +#define GPIOB ((GPIO_Module*)GPIOB_BASE) +#define SPI1 ((SPI_Module*)SPI1_BASE) +#define TIM1 ((TIM_Module*)TIM1_BASE) +#define USART1 ((USART_Module*)USART1_BASE) +#define SPI2 ((SPI_Module*)SPI2_BASE) +#define DMA ((DMA_Module*)DMA_BASE) +#define DMA_CH1 ((DMA_ChannelType*)DMA_CH1_BASE) +#define DMA_CH2 ((DMA_ChannelType*)DMA_CH2_BASE) +#define DMA_CH3 ((DMA_ChannelType*)DMA_CH3_BASE) +#define DMA_CH4 ((DMA_ChannelType*)DMA_CH4_BASE) +#define DMA_CH5 ((DMA_ChannelType*)DMA_CH5_BASE) +#define ADC ((ADC_Module*)ADC_BASE) +#define RCC ((RCC_Module*)RCC_BASE) +#define CRC ((CRC_Module*)CRC_BASE) +#define IRC ((IRC_Module*)IRC_BASE) +#define KEYSCAN ((KEYSCAN_Module*)KEYSCAN_BASE) + + +//#define MODEM_BASE (0x40022400) +#define EXCHANGE_MEM_BASE (0x4002C000) /// start at 0x50800 8000 offset of the memory span //TODO TRANSPLANT +#define BASEBAND_REG_BASE (0x40028000) + +/******************************************************************************/ +/* Peripheral Registers_Bits_Definition */ +/******************************************************************************/ + +/******************************************************************************/ +/* */ +/* CRC calculation unit */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for CRC_CRC32DAT register *********************/ +#define CRC32_DAT_DAT ((uint32_t)0xFFFFFFFF) /*!< Data register bits */ + +/******************* Bit definition for CRC_CRC32IDAT register ********************/ +#define CRC32_IDAT_IDAT ((uint8_t)0xFF) /*!< General-purpose 8-bit data register bits */ + +/******************** Bit definition for CRC_CRC32CTRL register ********************/ +#define CRC32_CTRL_RESET ((uint8_t)0x01) /*!< RESET bit */ + +/******************** Bit definition for CRC16_CR register ********************/ +#define CRC16_CTRL_LITTLE ((uint8_t)0x02) +#define CRC16_CTRL_BIG ((uint8_t)0xFD) + +#define CRC16_CTRL_RESET ((uint8_t)0x04) +#define CRC16_CTRL_NO_RESET ((uint8_t)0xFB) + +/******************************************************************************/ +/* */ +/* Power Control */ +/* */ +/******************************************************************************/ +/******************** Bit definition for PWR_CR1 register ********************/ +#define PWR_CR1_MODE_SEL ((uint16_t)0x0007) /*!< low power mode entered select*/ +#define PWR_CR1_MODE_ACTIVE ((uint16_t)0x0000) +#define PWR_CR1_MODE_STANDBY ((uint16_t)0x0001) +#define PWR_CR1_MODE_SLEEP ((uint16_t)0x0002) +#define PWR_CR1_MODE_PD ((uint16_t)0x0004) + +#define PWR_CR1_MODE_EN ((uint16_t)0x0008) + +#define PWR_CR1_OSC_EN ((uint16_t)0x0020) + +/******************** Bit definition for PWR_CR2 register ********************/ +#define PWR_CR2_CORE_32KMEM_LP ((uint16_t)0x0001) +#define PWR_CR2_CORE_16KMEM_LP ((uint16_t)0x0002) +#define PWR_CR2_PAD_STA ((uint16_t)0x0008) + +#define PWR_CR2_BLE_STATE ((uint16_t)0xE000) +#define PWR_CR2_BLE_STATE_POWERON ((uint16_t)0x0000) +#define PWR_CR2_BLE_STATE_ACTIVE ((uint16_t)0x2000) +#define PWR_CR2_BLE_STATE_SLEEP ((uint16_t)0x8000) + +/******************** Bit definition for PWR_VTOR register ********************/ +#define PWR_VTOR_EN ((uint32_t)0x80000000) +#define PWR_VTOR_ADDR ((uint32_t)0x7FFFFFFF) + +/******************************************************************************/ +/* */ +/* Reset and Clock Control */ +/* */ +/******************************************************************************/ + +/******************** Bit definition for RCC_CTRL register ********************/ +#define RCC_CTRL_HSIEN ((uint32_t)0x00000001) /*!< Internal High Speed clock enable */ +#define RCC_CTRL_HSIRDF ((uint32_t)0x00000002) /*!< Internal High Speed clock ready flag */ +#define RCC_CTRL_HSITRIM ((uint32_t)0x00007F00) /*!< Internal High Speed clock trimming */ +#define RCC_CTRL_HSEEN ((uint32_t)0x00010000) /*!< External High Speed clock enable */ +#define RCC_CTRL_HSERDF ((uint32_t)0x00020000) /*!< External High Speed clock ready flag */ +#define RCC_CTRL_AUDIOPLLEN ((uint32_t)0x01000000) /*!< AUDIOPLL enable */ + +/******************* Bit definition for RCC_CFG register *******************/ +/*!< SCLKSW configuration */ +#define RCC_CFG_SCLKSW ((uint32_t)0x00000001) /*!< SCLKSW[0] bits (System clock Switch) */ +#define RCC_CFG_SCLKSW_HSI ((uint32_t)0x00000000) /*!< HSI selected as system clock */ +#define RCC_CFG_SCLKSW_HSE ((uint32_t)0x00000001) /*!< HSE selected as system clock */ + +/*!< SCLKSTS configuration */ +#define RCC_CFG_SCLKSTS ((uint32_t)0x00000004) /*!< SCLKSTS[0] bits (System Clock Switch Status) */ +#define RCC_CFG_SCLKSTS_HSI ((uint32_t)0x00000000) /*!< HSI oscillator used as system clock */ +#define RCC_CFG_SCLKSTS_HSE ((uint32_t)0x00000004) /*!< HSE oscillator used as system clock */ + + +/*!< AHBPRES configuration */ +#define RCC_CFG_AHBPRES ((uint32_t)0x00000030) /*!< AHBPRES[1:0] bits (AHB prescaler) */ + +#define RCC_CFG_AHBPRES_DIV1 ((uint32_t)0x00000000) /*!< SYSCLK not divided */ +#define RCC_CFG_AHBPRES_DIV2 ((uint32_t)0x00000020) /*!< SYSCLK divided by 2 */ +#define RCC_CFG_AHBPRES_DIV4 ((uint32_t)0x00000030) /*!< SYSCLK divided by 4 */ + + +/*!< APB1PRES configuration */ +#define RCC_CFG_APB1PRES ((uint32_t)0x00000700) /*!< APB1PRES[2:0] bits (APB1 prescaler) */ + + +#define RCC_CFG_APB1PRES_DIV1 ((uint32_t)0x00000000) /*!< HCLK not divided */ +#define RCC_CFG_APB1PRES_DIV2 ((uint32_t)0x00000400) /*!< HCLK divided by 2 */ +#define RCC_CFG_APB1PRES_DIV4 ((uint32_t)0x00000500) /*!< HCLK divided by 4 */ +#define RCC_CFG_APB1PRES_DIV8 ((uint32_t)0x00000600) /*!< HCLK divided by 8 */ +#define RCC_CFG_APB1PRES_DIV16 ((uint32_t)0x00000700) /*!< HCLK divided by 16 */ + +/*!< APB2PRES configuration */ +#define RCC_CFG_APB2PRES ((uint32_t)0x00003800) /*!< APB2PRES[2:0] bits (APB2 prescaler) */ +#define RCC_CFG_APB2PRES_0 ((uint32_t)0x00000800) /*!< Bit 0 */ +#define RCC_CFG_APB2PRES_1 ((uint32_t)0x00001000) /*!< Bit 1 */ +#define RCC_CFG_APB2PRES_2 ((uint32_t)0x00002000) /*!< Bit 2 */ + +#define RCC_CFG_APB2PRES_DIV1 ((uint32_t)0x00000000) /*!< HCLK not divided */ +#define RCC_CFG_APB2PRES_DIV2 ((uint32_t)0x00002000) /*!< HCLK divided by 2 */ +#define RCC_CFG_APB2PRES_DIV4 ((uint32_t)0x00002800) /*!< HCLK divided by 4 */ +#define RCC_CFG_APB2PRES_DIV8 ((uint32_t)0x00003000) /*!< HCLK divided by 8 */ +#define RCC_CFG_APB2PRES_DIV16 ((uint32_t)0x00003800) /*!< HCLK divided by 16 */ + +/*!< HSISRC configuration */ +#define RCC_CFG_HSISRC ((uint32_t)0x00010000) /*!< HSISRC[0] bit */ +#define RCC_CFG_HSISRC_DIV1 ((uint32_t)0x00010000) /*!< HSI frequency divided by 1 */ +#define RCC_CFG_HSISRC_DIV2 ((uint32_t)0x00000000) /*!< HSI frequency divided by 2 */ + + +/*!< MCO configuration */ +#define RCC_CFG_MCO ((uint32_t)0x1E000000) /*!< MCO[3:0] bits (Microcontroller Clock Output) */ +#define RCC_CFG_MCO_0 ((uint32_t)0x02000000) /*!< Bit 0 */ +#define RCC_CFG_MCO_1 ((uint32_t)0x04000000) /*!< Bit 1 */ +#define RCC_CFG_MCO_2 ((uint32_t)0x08000000) /*!< Bit 2 */ +#define RCC_CFG_MCO_3 ((uint32_t)0x10000000) /*!< Bit 3 */ + +#define RCC_CFG_MCO_NOCLK ((uint32_t)0x00000000) /*!< No clock */ +#define RCC_CFG_MCO_LSI ((uint32_t)0x02000000) /*!< LSI clock selected as MCO source */ +#define RCC_CFG_MCO_LSE ((uint32_t)0x04000000) /*!< LSE clock selected as MCO source */ +#define RCC_CFG_MCO_SYSCLK ((uint32_t)0x06000000) /*!< System clock selected as MCO source */ +#define RCC_CFG_MCO_HSI ((uint32_t)0x08000000) /*!< HSI clock selected as MCO source */ +#define RCC_CFG_MCO_HSE ((uint32_t)0x0A000000) /*!< HSE clock selected as MCO source */ +#define RCC_CFG_MCO_HCLK ((uint32_t)0x0C000000) /*!< HCLK clock selected as MCO source */ +#define RCC_CFG_MCO_AUDIOPLL ((uint32_t)0x0E000000) /*!< AUDIOPLL clock selected as MCO source */ + +/*!<****************** Bit definition for RCC_CLKINT register ********************/ +#define RCC_CLKINT_LSIRDIF ((uint32_t)0x00000001) /*!< LSI Ready Interrupt flag */ +#define RCC_CLKINT_LSERDIF ((uint32_t)0x00000002) /*!< LSE Ready Interrupt flag */ +#define RCC_CLKINT_HSIRDIF ((uint32_t)0x00000004) /*!< HSI Ready Interrupt flag */ +#define RCC_CLKINT_HSERDIF ((uint32_t)0x00000008) /*!< HSE Ready Interrupt flag */ +#define RCC_CLKINT_LSIRDIEN ((uint32_t)0x00000100) /*!< LSI Ready Interrupt Enable */ +#define RCC_CLKINT_LSERDIEN ((uint32_t)0x00000200) /*!< LSE Ready Interrupt Enable */ +#define RCC_CLKINT_HSIRDIEN ((uint32_t)0x00000400) /*!< HSI Ready Interrupt Enable */ +#define RCC_CLKINT_HSERDIEN ((uint32_t)0x00000800) /*!< HSE Ready Interrupt Enable */ +#define RCC_CLKINT_LSIRDICLR ((uint32_t)0x00010000) /*!< LSI Ready Interrupt Clear */ +#define RCC_CLKINT_LSERDICLR ((uint32_t)0x00020000) /*!< LSE Ready Interrupt Clear */ +#define RCC_CLKINT_HSIRDICLR ((uint32_t)0x00040000) /*!< HSI Ready Interrupt Clear */ +#define RCC_CLKINT_HSERDICLR ((uint32_t)0x00080000) /*!< HSE Ready Interrupt Clear */ + +/***************** Bit definition for RCC_APB2PRST register *****************/ +#define RCC_APB2PRST_AFIORST ((uint32_t)0x00000001) /*!< Alternate Function I/O reset */ +#define RCC_APB2PRST_IOPARST ((uint32_t)0x00000004) /*!< I/O port A reset */ +#define RCC_APB2PRST_IOPBRST ((uint32_t)0x00000008) /*!< I/O port B reset */ +#define RCC_APB2PRST_SPI1RST ((uint32_t)0x00000200) /*!< SPI1 reset */ +#define RCC_APB2PRST_SPI2RST ((uint32_t)0x00000400) /*!< SPI2 reset */ +#define RCC_APB2PRST_TIM1RST ((uint32_t)0x00001000) /*!< TIM1 Timer reset */ +#define RCC_APB2PRST_USART1RST ((uint32_t)0x00004000) /*!< USART1 reset */ + +/***************** Bit definition for RCC_APB1PRST register *****************/ +#define RCC_APB1PRST_TIM3RST ((uint32_t)0x00000002) /*!< Timer 3 reset */ +#define RCC_APB1PRST_TIM6RST ((uint32_t)0x00000010) /*!< Timer 6 reset */ +#define RCC_APB1PRST_WWDGRST ((uint32_t)0x00000800) /*!< Window Watchdog reset */ +#define RCC_APB1PRST_USART2RST ((uint32_t)0x00020000) /*!< USART 2 reset */ +#define RCC_APB1PRST_I2C1RST ((uint32_t)0x00200000) /*!< I2C 1 reset */ +#define RCC_APB1PRST_PWRRST ((uint32_t)0x10000000) /*!< Power interface reset */ + +/****************** Bit definition for RCC_AHBPCLKEN register ******************/ +#define RCC_AHBPCLKEN_DMAEN ((uint32_t)0x00000001) /*!< DMA clock enable */ +#define RCC_AHBPCLKEN_SRAMEN ((uint32_t)0x00000004) /*!< SRAM interface clock enable */ +#define RCC_AHBPCLKEN_FLITFEN ((uint32_t)0x00000010) /*!< FLITF clock enable */ +#define RCC_AHBPCLKEN_PATCHEN ((uint32_t)0x00000020) /*!< PATCH clock enable */ +#define RCC_AHBPCLKEN_CRCEN ((uint32_t)0x00000040) /*!< CRC clock enable */ +#define RCC_AHBPCLKEN_ADCEN ((uint32_t)0x00001000) /*!< ADC clock enable */ +#define RCC_AHBPCLKEN_IRCEN ((uint32_t)0x00004000) /*!< IRC clock enable */ + +/****************** Bit definition for RCC_APB2PCLKEN register *****************/ +#define RCC_APB2PCLKEN_AFIOEN ((uint32_t)0x00000001) /*!< Alternate Function I/O clock enable */ +#define RCC_APB2PCLKEN_IOPAEN ((uint32_t)0x00000004) /*!< I/O port A clock enable */ +#define RCC_APB2PCLKEN_IOPBEN ((uint32_t)0x00000008) /*!< I/O port B clock enable */ +#define RCC_APB2PCLKEN_SPI1EN ((uint32_t)0x00000200) /*!< SPI1 clock enable */ +#define RCC_APB2PCLKEN_SPI2EN ((uint32_t)0x00000400) /*!< SPI2 clock enable */ +#define RCC_APB2PCLKEN_TIM1EN ((uint32_t)0x00001000) /*!< TIM1 Timer clock enable */ +#define RCC_APB2PCLKEN_USART1EN ((uint32_t)0x00004000) /*!< USART1 clock enable */ + +/***************** Bit definition for RCC_APB1PCLKEN register ******************/ +#define RCC_APB1PCLKEN_TIM3EN ((uint32_t)0x00000002) /*!< Timer 3 clock enable */ +#define RCC_APB1PCLKEN_TIM6EN ((uint32_t)0x00000010) /*!< Timer 6 clock enable */ +#define RCC_APB1PCLKEN_WWDGEN ((uint32_t)0x00000800) /*!< Window Watchdog clock enable */ +#define RCC_APB1PCLKEN_USART2EN ((uint32_t)0x00020000) /*!< USART 2 clock enable */ +#define RCC_APB1PCLKEN_I2C1EN ((uint32_t)0x00200000) /*!< I2C 1 clock enable */ +#define RCC_APB1PCLKEN_PWREN ((uint32_t)0x10000000) /*!< Power interface clock enable */ + +/******************* Bit definition for RCC_LSCTRL register *******************/ +#define RCC_LSCTRL_LSIEN ((uint32_t)0x00000001) /*!< Internal Low Speed oscillator enable */ +#define RCC_LSCTRL_LSIRD ((uint32_t)0x00000002) /*!< Internal Low Speed oscillator Ready */ +#define RCC_LSCTRL_LSEEN ((uint32_t)0x00000004) /*!< External Low Speed oscillator enable */ +#define RCC_LSCTRL_LSERD ((uint32_t)0x00000008) /*!< External Low Speed oscillator Ready */ +#define RCC_LSCTRL_LSEBP ((uint32_t)0x00000010) /*!< External Low Speed oscillator Bypass */ + +#define RCC_LSCTRL_LSXSEL ((uint32_t)0x00000020) /*!< LSC clock source selection */ +#define RCC_LSCTRL_LSXSEL_LSI ((uint32_t)0x00000000) /*!< LSI oscillator clock used as LSC clock */ +#define RCC_LSCTRL_LSXSEL_LSE ((uint32_t)0x00000020) /*!< LSE oscillator clock used as LSC clock */ + +#define RCC_LSCTRL_LSTTRIM ((uint32_t)0x0007FF00) /*!< LSI triming value */ + +#define RCC_LSCTRL_RTCEN ((uint32_t)0x01000000) /*!< RTC clock enable */ +#define RCC_LSCTRL_RTCRST ((uint32_t)0x02000000) /*!< RTC software reset */ + +#define RCC_LSCTRL_LPUARTSEL ((uint32_t)0x04000000) /*!< LPUART clock selection */ +#define RCC_LSCTRL_LPUART_APB1 ((uint32_t)0x00000000) /*!< APB1 clock selection */ + +#define RCC_LSCTRL_LPUARTSEL_LSI_LSE ((uint32_t)0x04000020) /*!< LPUART clock selection */ +#define RCC_LSCTRL_LPUART_LSI ((uint32_t)0x04000000) /*!< LSI_LSE clock selection */ +#define RCC_LSCTRL_LPUART_LSE ((uint32_t)0x04000020) /*!< LSI_LSE clock selection */ + + +#define RCC_LSCTRL_LPUARTEN ((uint32_t)0x08000000) /*!< LPUART clock enable */ +#define RCC_LSCTRL_LPUARTRST ((uint32_t)0x10000000) /*!< LPUART reset */ +#define RCC_LSCTRL_KEYSCANEN ((uint32_t)0x40000000) /*!< KEYSCAN clock enable */ + +/******************* Bit definition for RCC_CTRLSTS register ********************/ +#define RCC_CTRLSTS_RMRSTF ((uint32_t)0x00000001) /*!< Remove reset flag */ +#define RCC_CTRLSTS_PINRSTF ((uint32_t)0x00000008) /*!< PIN reset flag */ +#define RCC_CTRLSTS_PORRSTF ((uint32_t)0x00000010) /*!< POR reset flag */ +#define RCC_CTRLSTS_SFTRSTF ((uint32_t)0x00000020) /*!< Software Reset flag */ +#define RCC_CTRLSTS_IWDGRSTF ((uint32_t)0x00000040) /*!< Independent Watchdog reset flag */ +#define RCC_CTRLSTS_WWDGRSTF ((uint32_t)0x00000080) /*!< Window watchdog reset flag */ + +/******************* Bit definition for RCC_AHBPRST register ****************/ +#define RCC_AHBRST_IRCRST ((uint32_t)0x00004000) /*!< IRC reset */ +#define RCC_AHBRST_ADCRST ((uint32_t)0x00001000) /*!< ADC reset */ + +/******************* Bit definition for RCC_CFG2 register ******************/ +/*!< ADCHPRE configuration */ +#define RCC_CFG2_ADCHPRES ((uint32_t)0x00000010) /*!< ADCHPRE[3:0] bits */ +#define RCC_CFG2_ADCHPRES_DIV8 ((uint32_t)0x00000005) /*!< HCLK clock divided by 8 */ +#define RCC_CFG2_ADCHPRES_DIV10 ((uint32_t)0x00000006) /*!< HCLK clock divided by 10 */ +#define RCC_CFG2_ADCHPRES_DIV12 ((uint32_t)0x00000007) /*!< HCLK clock divided by 12 */ +#define RCC_CFG2_ADCHPRES_DIV16 ((uint32_t)0x00000008) /*!< HCLK clock divided by 16 */ +#define RCC_CFG2_ADCHPRES_DIV32 ((uint32_t)0x00000009) /*!< HCLK clock divided by 32 */ +#define RCC_CFG2_ADCHPRES_OTHERS ((uint32_t)0x00000009) /*!< HCLK clock divided by 32 */ + +/*!< ADC1MSEL configuration */ +#define RCC_CFG2_ADCSEL ((uint32_t)0x00000010) /*!< ADC clock source select */ +#define RCC_CFG2_ADCSEL_AUDIOPLL ((uint32_t)0x00000000) /*!< AUDIOPLL clock selected as ADC input clock */ +#define RCC_CFG2_ADCSEL_HSE_DIV8 ((uint32_t)0x00000010) /*!< HSE_DIV8 clock selected as ADC input clock */ + +/*!< TIMCLK_SEL configuration */ +#define RCC_CFG2_TIMCLKSEL ((uint32_t)0x80000000) /*!< Timer1 clock source select */ +#define RCC_CFG2_TIMCLKSEL_TIM1CLK ((uint32_t)0x00000000) /*!< Timer1 clock selected as tim1_clk input clock */ +#define RCC_CFG2_TIMCLKSEL_SYSCLK ((uint32_t)0x80000000) /*!< Timer1 clock selected as sysclk input clock */ + +/*!< ROMCCTRL configuration */ +#define RCC_ROMCCTRL_READCYCLESEL ((uint32_t)0x00000020) /*!< ROMCReadcycle select */ +#define RCC_ROMCCTRL_READCYCLE_ONE ((uint32_t)0x00000000) /*!< one */ +#define RCC_ROMCCTRL_READCYCLE_TWO ((uint32_t)0x00000020) /*!< two */ + +/******************** Bit definition for RCC_DBGCTRL register ********************/ +#define RCC_DBGCTRL_IWDGSTP ((uint32_t)0x00000001) /*!< when enter debug mode,IWDG work mode selection*/ +#define RCC_DBGCTRL_WWDGSTP ((uint32_t)0x00000002) /*!< when enter debug mode,WWDG work mode selection*/ +#define RCC_DBGCTRL_TIM1STP ((uint32_t)0x00000003) /*!< when enter debug mode,TIM1 work mode selection*/ +#define RCC_DBGCTRL_TIM3STP ((uint32_t)0x00000004) /*!< when enter debug mode,TIM3 work mode selection*/ +#define RCC_DBGCTRL_TIM6STP ((uint32_t)0x00000010) /*!< when enter debug mode,TIM6 work mode selection*/ +#define RCC_DBGCTRL_I2C1TIMOUT ((uint32_t)0x00000020) /*!< when enter debug mode,I2C1 timeout work mode selection*/ + +/******************************************************************************/ +/* */ +/* SystemTick */ +/* */ +/******************************************************************************/ + +/***************** Bit definition for SysTick_CTRL register *****************/ +#define SysTick_CTRL_ENABLE ((uint32_t)0x00000001) /*!< Counter enable */ +#define SysTick_CTRL_TICKINT ((uint32_t)0x00000002) /*!< Counting down to 0 pends the SysTick handler */ +#define SysTick_CTRL_CLKSOURCE ((uint32_t)0x00000004) /*!< Clock source */ +#define SysTick_CTRL_COUNTFLAG ((uint32_t)0x00010000) /*!< Count Flag */ + +/***************** Bit definition for SysTick_LOAD register *****************/ +#define SysTick_LOAD_RELOAD \ + ((uint32_t)0x00FFFFFF) /*!< Value to load into the SysTick Current Value Register when the counter reaches 0 */ + +/***************** Bit definition for SysTick_VAL register ******************/ +#define SysTick_VAL_CURRENT ((uint32_t)0x00FFFFFF) /*!< Current value at the time the register is accessed */ + +/***************** Bit definition for SysTick_CALIB register ****************/ +#define SysTick_CALIB_TENMS ((uint32_t)0x00FFFFFF) /*!< Reload value to use for 10ms timing */ +#define SysTick_CALIB_SKEW ((uint32_t)0x40000000) /*!< Calibration value is not exactly 10 ms */ +#define SysTick_CALIB_NOREF ((uint32_t)0x80000000) /*!< The reference clock is not provided */ + +/******************************************************************************/ +/* */ +/* Nested Vectored Interrupt Controller */ +/* */ +/******************************************************************************/ + +/****************** Bit definition for NVIC_ISER register *******************/ +#define NVIC_ISER_SETENA ((uint32_t)0xFFFFFFFF) /*!< Interrupt set enable bits */ +#define NVIC_ISER_SETENA_0 ((uint32_t)0x00000001) /*!< bit 0 */ +#define NVIC_ISER_SETENA_1 ((uint32_t)0x00000002) /*!< bit 1 */ +#define NVIC_ISER_SETENA_2 ((uint32_t)0x00000004) /*!< bit 2 */ +#define NVIC_ISER_SETENA_3 ((uint32_t)0x00000008) /*!< bit 3 */ +#define NVIC_ISER_SETENA_4 ((uint32_t)0x00000010) /*!< bit 4 */ +#define NVIC_ISER_SETENA_5 ((uint32_t)0x00000020) /*!< bit 5 */ +#define NVIC_ISER_SETENA_6 ((uint32_t)0x00000040) /*!< bit 6 */ +#define NVIC_ISER_SETENA_7 ((uint32_t)0x00000080) /*!< bit 7 */ +#define NVIC_ISER_SETENA_8 ((uint32_t)0x00000100) /*!< bit 8 */ +#define NVIC_ISER_SETENA_9 ((uint32_t)0x00000200) /*!< bit 9 */ +#define NVIC_ISER_SETENA_10 ((uint32_t)0x00000400) /*!< bit 10 */ +#define NVIC_ISER_SETENA_11 ((uint32_t)0x00000800) /*!< bit 11 */ +#define NVIC_ISER_SETENA_12 ((uint32_t)0x00001000) /*!< bit 12 */ +#define NVIC_ISER_SETENA_13 ((uint32_t)0x00002000) /*!< bit 13 */ +#define NVIC_ISER_SETENA_14 ((uint32_t)0x00004000) /*!< bit 14 */ +#define NVIC_ISER_SETENA_15 ((uint32_t)0x00008000) /*!< bit 15 */ +#define NVIC_ISER_SETENA_16 ((uint32_t)0x00010000) /*!< bit 16 */ +#define NVIC_ISER_SETENA_17 ((uint32_t)0x00020000) /*!< bit 17 */ +#define NVIC_ISER_SETENA_18 ((uint32_t)0x00040000) /*!< bit 18 */ +#define NVIC_ISER_SETENA_19 ((uint32_t)0x00080000) /*!< bit 19 */ +#define NVIC_ISER_SETENA_20 ((uint32_t)0x00100000) /*!< bit 20 */ +#define NVIC_ISER_SETENA_21 ((uint32_t)0x00200000) /*!< bit 21 */ +#define NVIC_ISER_SETENA_22 ((uint32_t)0x00400000) /*!< bit 22 */ +#define NVIC_ISER_SETENA_23 ((uint32_t)0x00800000) /*!< bit 23 */ +#define NVIC_ISER_SETENA_24 ((uint32_t)0x01000000) /*!< bit 24 */ +#define NVIC_ISER_SETENA_25 ((uint32_t)0x02000000) /*!< bit 25 */ +#define NVIC_ISER_SETENA_26 ((uint32_t)0x04000000) /*!< bit 26 */ +#define NVIC_ISER_SETENA_27 ((uint32_t)0x08000000) /*!< bit 27 */ +#define NVIC_ISER_SETENA_28 ((uint32_t)0x10000000) /*!< bit 28 */ +#define NVIC_ISER_SETENA_29 ((uint32_t)0x20000000) /*!< bit 29 */ +#define NVIC_ISER_SETENA_30 ((uint32_t)0x40000000) /*!< bit 30 */ +#define NVIC_ISER_SETENA_31 ((uint32_t)0x80000000) /*!< bit 31 */ + +/****************** Bit definition for NVIC_ICER register *******************/ +#define NVIC_ICER_CLRENA ((uint32_t)0xFFFFFFFF) /*!< Interrupt clear-enable bits */ +#define NVIC_ICER_CLRENA_0 ((uint32_t)0x00000001) /*!< bit 0 */ +#define NVIC_ICER_CLRENA_1 ((uint32_t)0x00000002) /*!< bit 1 */ +#define NVIC_ICER_CLRENA_2 ((uint32_t)0x00000004) /*!< bit 2 */ +#define NVIC_ICER_CLRENA_3 ((uint32_t)0x00000008) /*!< bit 3 */ +#define NVIC_ICER_CLRENA_4 ((uint32_t)0x00000010) /*!< bit 4 */ +#define NVIC_ICER_CLRENA_5 ((uint32_t)0x00000020) /*!< bit 5 */ +#define NVIC_ICER_CLRENA_6 ((uint32_t)0x00000040) /*!< bit 6 */ +#define NVIC_ICER_CLRENA_7 ((uint32_t)0x00000080) /*!< bit 7 */ +#define NVIC_ICER_CLRENA_8 ((uint32_t)0x00000100) /*!< bit 8 */ +#define NVIC_ICER_CLRENA_9 ((uint32_t)0x00000200) /*!< bit 9 */ +#define NVIC_ICER_CLRENA_10 ((uint32_t)0x00000400) /*!< bit 10 */ +#define NVIC_ICER_CLRENA_11 ((uint32_t)0x00000800) /*!< bit 11 */ +#define NVIC_ICER_CLRENA_12 ((uint32_t)0x00001000) /*!< bit 12 */ +#define NVIC_ICER_CLRENA_13 ((uint32_t)0x00002000) /*!< bit 13 */ +#define NVIC_ICER_CLRENA_14 ((uint32_t)0x00004000) /*!< bit 14 */ +#define NVIC_ICER_CLRENA_15 ((uint32_t)0x00008000) /*!< bit 15 */ +#define NVIC_ICER_CLRENA_16 ((uint32_t)0x00010000) /*!< bit 16 */ +#define NVIC_ICER_CLRENA_17 ((uint32_t)0x00020000) /*!< bit 17 */ +#define NVIC_ICER_CLRENA_18 ((uint32_t)0x00040000) /*!< bit 18 */ +#define NVIC_ICER_CLRENA_19 ((uint32_t)0x00080000) /*!< bit 19 */ +#define NVIC_ICER_CLRENA_20 ((uint32_t)0x00100000) /*!< bit 20 */ +#define NVIC_ICER_CLRENA_21 ((uint32_t)0x00200000) /*!< bit 21 */ +#define NVIC_ICER_CLRENA_22 ((uint32_t)0x00400000) /*!< bit 22 */ +#define NVIC_ICER_CLRENA_23 ((uint32_t)0x00800000) /*!< bit 23 */ +#define NVIC_ICER_CLRENA_24 ((uint32_t)0x01000000) /*!< bit 24 */ +#define NVIC_ICER_CLRENA_25 ((uint32_t)0x02000000) /*!< bit 25 */ +#define NVIC_ICER_CLRENA_26 ((uint32_t)0x04000000) /*!< bit 26 */ +#define NVIC_ICER_CLRENA_27 ((uint32_t)0x08000000) /*!< bit 27 */ +#define NVIC_ICER_CLRENA_28 ((uint32_t)0x10000000) /*!< bit 28 */ +#define NVIC_ICER_CLRENA_29 ((uint32_t)0x20000000) /*!< bit 29 */ +#define NVIC_ICER_CLRENA_30 ((uint32_t)0x40000000) /*!< bit 30 */ +#define NVIC_ICER_CLRENA_31 ((uint32_t)0x80000000) /*!< bit 31 */ + +/****************** Bit definition for NVIC_ISPR register *******************/ +#define NVIC_ISPR_SETPEND ((uint32_t)0xFFFFFFFF) /*!< Interrupt set-pending bits */ +#define NVIC_ISPR_SETPEND_0 ((uint32_t)0x00000001) /*!< bit 0 */ +#define NVIC_ISPR_SETPEND_1 ((uint32_t)0x00000002) /*!< bit 1 */ +#define NVIC_ISPR_SETPEND_2 ((uint32_t)0x00000004) /*!< bit 2 */ +#define NVIC_ISPR_SETPEND_3 ((uint32_t)0x00000008) /*!< bit 3 */ +#define NVIC_ISPR_SETPEND_4 ((uint32_t)0x00000010) /*!< bit 4 */ +#define NVIC_ISPR_SETPEND_5 ((uint32_t)0x00000020) /*!< bit 5 */ +#define NVIC_ISPR_SETPEND_6 ((uint32_t)0x00000040) /*!< bit 6 */ +#define NVIC_ISPR_SETPEND_7 ((uint32_t)0x00000080) /*!< bit 7 */ +#define NVIC_ISPR_SETPEND_8 ((uint32_t)0x00000100) /*!< bit 8 */ +#define NVIC_ISPR_SETPEND_9 ((uint32_t)0x00000200) /*!< bit 9 */ +#define NVIC_ISPR_SETPEND_10 ((uint32_t)0x00000400) /*!< bit 10 */ +#define NVIC_ISPR_SETPEND_11 ((uint32_t)0x00000800) /*!< bit 11 */ +#define NVIC_ISPR_SETPEND_12 ((uint32_t)0x00001000) /*!< bit 12 */ +#define NVIC_ISPR_SETPEND_13 ((uint32_t)0x00002000) /*!< bit 13 */ +#define NVIC_ISPR_SETPEND_14 ((uint32_t)0x00004000) /*!< bit 14 */ +#define NVIC_ISPR_SETPEND_15 ((uint32_t)0x00008000) /*!< bit 15 */ +#define NVIC_ISPR_SETPEND_16 ((uint32_t)0x00010000) /*!< bit 16 */ +#define NVIC_ISPR_SETPEND_17 ((uint32_t)0x00020000) /*!< bit 17 */ +#define NVIC_ISPR_SETPEND_18 ((uint32_t)0x00040000) /*!< bit 18 */ +#define NVIC_ISPR_SETPEND_19 ((uint32_t)0x00080000) /*!< bit 19 */ +#define NVIC_ISPR_SETPEND_20 ((uint32_t)0x00100000) /*!< bit 20 */ +#define NVIC_ISPR_SETPEND_21 ((uint32_t)0x00200000) /*!< bit 21 */ +#define NVIC_ISPR_SETPEND_22 ((uint32_t)0x00400000) /*!< bit 22 */ +#define NVIC_ISPR_SETPEND_23 ((uint32_t)0x00800000) /*!< bit 23 */ +#define NVIC_ISPR_SETPEND_24 ((uint32_t)0x01000000) /*!< bit 24 */ +#define NVIC_ISPR_SETPEND_25 ((uint32_t)0x02000000) /*!< bit 25 */ +#define NVIC_ISPR_SETPEND_26 ((uint32_t)0x04000000) /*!< bit 26 */ +#define NVIC_ISPR_SETPEND_27 ((uint32_t)0x08000000) /*!< bit 27 */ +#define NVIC_ISPR_SETPEND_28 ((uint32_t)0x10000000) /*!< bit 28 */ +#define NVIC_ISPR_SETPEND_29 ((uint32_t)0x20000000) /*!< bit 29 */ +#define NVIC_ISPR_SETPEND_30 ((uint32_t)0x40000000) /*!< bit 30 */ +#define NVIC_ISPR_SETPEND_31 ((uint32_t)0x80000000) /*!< bit 31 */ + +/****************** Bit definition for NVIC_ICPR register *******************/ +#define NVIC_ICPR_CLRPEND ((uint32_t)0xFFFFFFFF) /*!< Interrupt clear-pending bits */ +#define NVIC_ICPR_CLRPEND_0 ((uint32_t)0x00000001) /*!< bit 0 */ +#define NVIC_ICPR_CLRPEND_1 ((uint32_t)0x00000002) /*!< bit 1 */ +#define NVIC_ICPR_CLRPEND_2 ((uint32_t)0x00000004) /*!< bit 2 */ +#define NVIC_ICPR_CLRPEND_3 ((uint32_t)0x00000008) /*!< bit 3 */ +#define NVIC_ICPR_CLRPEND_4 ((uint32_t)0x00000010) /*!< bit 4 */ +#define NVIC_ICPR_CLRPEND_5 ((uint32_t)0x00000020) /*!< bit 5 */ +#define NVIC_ICPR_CLRPEND_6 ((uint32_t)0x00000040) /*!< bit 6 */ +#define NVIC_ICPR_CLRPEND_7 ((uint32_t)0x00000080) /*!< bit 7 */ +#define NVIC_ICPR_CLRPEND_8 ((uint32_t)0x00000100) /*!< bit 8 */ +#define NVIC_ICPR_CLRPEND_9 ((uint32_t)0x00000200) /*!< bit 9 */ +#define NVIC_ICPR_CLRPEND_10 ((uint32_t)0x00000400) /*!< bit 10 */ +#define NVIC_ICPR_CLRPEND_11 ((uint32_t)0x00000800) /*!< bit 11 */ +#define NVIC_ICPR_CLRPEND_12 ((uint32_t)0x00001000) /*!< bit 12 */ +#define NVIC_ICPR_CLRPEND_13 ((uint32_t)0x00002000) /*!< bit 13 */ +#define NVIC_ICPR_CLRPEND_14 ((uint32_t)0x00004000) /*!< bit 14 */ +#define NVIC_ICPR_CLRPEND_15 ((uint32_t)0x00008000) /*!< bit 15 */ +#define NVIC_ICPR_CLRPEND_16 ((uint32_t)0x00010000) /*!< bit 16 */ +#define NVIC_ICPR_CLRPEND_17 ((uint32_t)0x00020000) /*!< bit 17 */ +#define NVIC_ICPR_CLRPEND_18 ((uint32_t)0x00040000) /*!< bit 18 */ +#define NVIC_ICPR_CLRPEND_19 ((uint32_t)0x00080000) /*!< bit 19 */ +#define NVIC_ICPR_CLRPEND_20 ((uint32_t)0x00100000) /*!< bit 20 */ +#define NVIC_ICPR_CLRPEND_21 ((uint32_t)0x00200000) /*!< bit 21 */ +#define NVIC_ICPR_CLRPEND_22 ((uint32_t)0x00400000) /*!< bit 22 */ +#define NVIC_ICPR_CLRPEND_23 ((uint32_t)0x00800000) /*!< bit 23 */ +#define NVIC_ICPR_CLRPEND_24 ((uint32_t)0x01000000) /*!< bit 24 */ +#define NVIC_ICPR_CLRPEND_25 ((uint32_t)0x02000000) /*!< bit 25 */ +#define NVIC_ICPR_CLRPEND_26 ((uint32_t)0x04000000) /*!< bit 26 */ +#define NVIC_ICPR_CLRPEND_27 ((uint32_t)0x08000000) /*!< bit 27 */ +#define NVIC_ICPR_CLRPEND_28 ((uint32_t)0x10000000) /*!< bit 28 */ +#define NVIC_ICPR_CLRPEND_29 ((uint32_t)0x20000000) /*!< bit 29 */ +#define NVIC_ICPR_CLRPEND_30 ((uint32_t)0x40000000) /*!< bit 30 */ +#define NVIC_ICPR_CLRPEND_31 ((uint32_t)0x80000000) /*!< bit 31 */ + +/****************** Bit definition for NVIC_IABR register *******************/ +#define NVIC_IABR_ACTIVE ((uint32_t)0xFFFFFFFF) /*!< Interrupt active flags */ +#define NVIC_IABR_ACTIVE_0 ((uint32_t)0x00000001) /*!< bit 0 */ +#define NVIC_IABR_ACTIVE_1 ((uint32_t)0x00000002) /*!< bit 1 */ +#define NVIC_IABR_ACTIVE_2 ((uint32_t)0x00000004) /*!< bit 2 */ +#define NVIC_IABR_ACTIVE_3 ((uint32_t)0x00000008) /*!< bit 3 */ +#define NVIC_IABR_ACTIVE_4 ((uint32_t)0x00000010) /*!< bit 4 */ +#define NVIC_IABR_ACTIVE_5 ((uint32_t)0x00000020) /*!< bit 5 */ +#define NVIC_IABR_ACTIVE_6 ((uint32_t)0x00000040) /*!< bit 6 */ +#define NVIC_IABR_ACTIVE_7 ((uint32_t)0x00000080) /*!< bit 7 */ +#define NVIC_IABR_ACTIVE_8 ((uint32_t)0x00000100) /*!< bit 8 */ +#define NVIC_IABR_ACTIVE_9 ((uint32_t)0x00000200) /*!< bit 9 */ +#define NVIC_IABR_ACTIVE_10 ((uint32_t)0x00000400) /*!< bit 10 */ +#define NVIC_IABR_ACTIVE_11 ((uint32_t)0x00000800) /*!< bit 11 */ +#define NVIC_IABR_ACTIVE_12 ((uint32_t)0x00001000) /*!< bit 12 */ +#define NVIC_IABR_ACTIVE_13 ((uint32_t)0x00002000) /*!< bit 13 */ +#define NVIC_IABR_ACTIVE_14 ((uint32_t)0x00004000) /*!< bit 14 */ +#define NVIC_IABR_ACTIVE_15 ((uint32_t)0x00008000) /*!< bit 15 */ +#define NVIC_IABR_ACTIVE_16 ((uint32_t)0x00010000) /*!< bit 16 */ +#define NVIC_IABR_ACTIVE_17 ((uint32_t)0x00020000) /*!< bit 17 */ +#define NVIC_IABR_ACTIVE_18 ((uint32_t)0x00040000) /*!< bit 18 */ +#define NVIC_IABR_ACTIVE_19 ((uint32_t)0x00080000) /*!< bit 19 */ +#define NVIC_IABR_ACTIVE_20 ((uint32_t)0x00100000) /*!< bit 20 */ +#define NVIC_IABR_ACTIVE_21 ((uint32_t)0x00200000) /*!< bit 21 */ +#define NVIC_IABR_ACTIVE_22 ((uint32_t)0x00400000) /*!< bit 22 */ +#define NVIC_IABR_ACTIVE_23 ((uint32_t)0x00800000) /*!< bit 23 */ +#define NVIC_IABR_ACTIVE_24 ((uint32_t)0x01000000) /*!< bit 24 */ +#define NVIC_IABR_ACTIVE_25 ((uint32_t)0x02000000) /*!< bit 25 */ +#define NVIC_IABR_ACTIVE_26 ((uint32_t)0x04000000) /*!< bit 26 */ +#define NVIC_IABR_ACTIVE_27 ((uint32_t)0x08000000) /*!< bit 27 */ +#define NVIC_IABR_ACTIVE_28 ((uint32_t)0x10000000) /*!< bit 28 */ +#define NVIC_IABR_ACTIVE_29 ((uint32_t)0x20000000) /*!< bit 29 */ +#define NVIC_IABR_ACTIVE_30 ((uint32_t)0x40000000) /*!< bit 30 */ +#define NVIC_IABR_ACTIVE_31 ((uint32_t)0x80000000) /*!< bit 31 */ + +/****************** Bit definition for NVIC_PRI0 register *******************/ +#define NVIC_IPR0_PRI_0 ((uint32_t)0x000000FF) /*!< Priority of interrupt 0 */ +#define NVIC_IPR0_PRI_1 ((uint32_t)0x0000FF00) /*!< Priority of interrupt 1 */ +#define NVIC_IPR0_PRI_2 ((uint32_t)0x00FF0000) /*!< Priority of interrupt 2 */ +#define NVIC_IPR0_PRI_3 ((uint32_t)0xFF000000) /*!< Priority of interrupt 3 */ + +/****************** Bit definition for NVIC_PRI1 register *******************/ +#define NVIC_IPR1_PRI_4 ((uint32_t)0x000000FF) /*!< Priority of interrupt 4 */ +#define NVIC_IPR1_PRI_5 ((uint32_t)0x0000FF00) /*!< Priority of interrupt 5 */ +#define NVIC_IPR1_PRI_6 ((uint32_t)0x00FF0000) /*!< Priority of interrupt 6 */ +#define NVIC_IPR1_PRI_7 ((uint32_t)0xFF000000) /*!< Priority of interrupt 7 */ + +/****************** Bit definition for NVIC_PRI2 register *******************/ +#define NVIC_IPR2_PRI_8 ((uint32_t)0x000000FF) /*!< Priority of interrupt 8 */ +#define NVIC_IPR2_PRI_9 ((uint32_t)0x0000FF00) /*!< Priority of interrupt 9 */ +#define NVIC_IPR2_PRI_10 ((uint32_t)0x00FF0000) /*!< Priority of interrupt 10 */ +#define NVIC_IPR2_PRI_11 ((uint32_t)0xFF000000) /*!< Priority of interrupt 11 */ + +/****************** Bit definition for NVIC_PRI3 register *******************/ +#define NVIC_IPR3_PRI_12 ((uint32_t)0x000000FF) /*!< Priority of interrupt 12 */ +#define NVIC_IPR3_PRI_13 ((uint32_t)0x0000FF00) /*!< Priority of interrupt 13 */ +#define NVIC_IPR3_PRI_14 ((uint32_t)0x00FF0000) /*!< Priority of interrupt 14 */ +#define NVIC_IPR3_PRI_15 ((uint32_t)0xFF000000) /*!< Priority of interrupt 15 */ + +/****************** Bit definition for NVIC_PRI4 register *******************/ +#define NVIC_IPR4_PRI_16 ((uint32_t)0x000000FF) /*!< Priority of interrupt 16 */ +#define NVIC_IPR4_PRI_17 ((uint32_t)0x0000FF00) /*!< Priority of interrupt 17 */ +#define NVIC_IPR4_PRI_18 ((uint32_t)0x00FF0000) /*!< Priority of interrupt 18 */ +#define NVIC_IPR4_PRI_19 ((uint32_t)0xFF000000) /*!< Priority of interrupt 19 */ + +/****************** Bit definition for NVIC_PRI5 register *******************/ +#define NVIC_IPR5_PRI_20 ((uint32_t)0x000000FF) /*!< Priority of interrupt 20 */ +#define NVIC_IPR5_PRI_21 ((uint32_t)0x0000FF00) /*!< Priority of interrupt 21 */ +#define NVIC_IPR5_PRI_22 ((uint32_t)0x00FF0000) /*!< Priority of interrupt 22 */ +#define NVIC_IPR5_PRI_23 ((uint32_t)0xFF000000) /*!< Priority of interrupt 23 */ + +/****************** Bit definition for NVIC_PRI6 register *******************/ +#define NVIC_IPR6_PRI_24 ((uint32_t)0x000000FF) /*!< Priority of interrupt 24 */ +#define NVIC_IPR6_PRI_25 ((uint32_t)0x0000FF00) /*!< Priority of interrupt 25 */ +#define NVIC_IPR6_PRI_26 ((uint32_t)0x00FF0000) /*!< Priority of interrupt 26 */ +#define NVIC_IPR6_PRI_27 ((uint32_t)0xFF000000) /*!< Priority of interrupt 27 */ + +/****************** Bit definition for NVIC_PRI7 register *******************/ +#define NVIC_IPR7_PRI_28 ((uint32_t)0x000000FF) /*!< Priority of interrupt 28 */ +#define NVIC_IPR7_PRI_29 ((uint32_t)0x0000FF00) /*!< Priority of interrupt 29 */ +#define NVIC_IPR7_PRI_30 ((uint32_t)0x00FF0000) /*!< Priority of interrupt 30 */ +#define NVIC_IPR7_PRI_31 ((uint32_t)0xFF000000) /*!< Priority of interrupt 31 */ + +/****************** Bit definition for SCB_CPUID register *******************/ +#define SCB_CPUID_REVISION ((uint32_t)0x0000000F) /*!< Implementation defined revision number */ +#define SCB_CPUID_PARTNO ((uint32_t)0x0000FFF0) /*!< Number of processor within family */ +#define SCB_CPUID_Constant ((uint32_t)0x000F0000) /*!< Reads as 0x0F */ +#define SCB_CPUID_VARIANT ((uint32_t)0x00F00000) /*!< Implementation defined variant number */ +#define SCB_CPUID_IMPLEMENTER ((uint32_t)0xFF000000) /*!< Implementer code. ARM is 0x41 */ + +/******************* Bit definition for SCB_ICSR register *******************/ +#define SCB_ICSR_VECTACTIVE ((uint32_t)0x000001FF) /*!< Active INTSTS number field */ +#define SCB_ICSR_RETTOBASE \ + ((uint32_t)0x00000800) /*!< All active exceptions minus the IPSR_current_exception yields the empty set */ +#define SCB_ICSR_VECTPENDING ((uint32_t)0x003FF000) /*!< Pending INTSTS number field */ +#define SCB_ICSR_ISRPENDING ((uint32_t)0x00400000) /*!< Interrupt pending flag */ +#define SCB_ICSR_ISRPREEMPT \ + ((uint32_t)0x00800000) /*!< It indicates that a pending interrupt becomes active in the next running cycle */ +#define SCB_ICSR_PENDSTCLR ((uint32_t)0x02000000) /*!< Clear pending SysTick bit */ +#define SCB_ICSR_PENDSTSET ((uint32_t)0x04000000) /*!< Set pending SysTick bit */ +#define SCB_ICSR_PENDSVCLR ((uint32_t)0x08000000) /*!< Clear pending pendSV bit */ +#define SCB_ICSR_PENDSVSET ((uint32_t)0x10000000) /*!< Set pending pendSV bit */ +#define SCB_ICSR_NMIPENDSET ((uint32_t)0x80000000) /*!< Set pending NMI bit */ + +/*!<***************** Bit definition for SCB_AIRCR register *******************/ +#define SCB_AIRCR_VECTRESET ((uint32_t)0x00000001) /*!< System Reset bit */ +#define SCB_AIRCR_VECTCLRACTIVE ((uint32_t)0x00000002) /*!< Clear active vector bit */ +#define SCB_AIRCR_SYSRESETREQ ((uint32_t)0x00000004) /*!< Requests chip control logic to generate a reset */ + +#define SCB_AIRCR_PRIGROUP ((uint32_t)0x00000700) /*!< PRIGROUP[2:0] bits (Priority group) */ +#define SCB_AIRCR_PRIGROUP_0 ((uint32_t)0x00000100) /*!< Bit 0 */ +#define SCB_AIRCR_PRIGROUP_1 ((uint32_t)0x00000200) /*!< Bit 1 */ +#define SCB_AIRCR_PRIGROUP_2 ((uint32_t)0x00000400) /*!< Bit 2 */ + +/* prority group configuration */ +#define SCB_AIRCR_PRIGROUP0 \ + ((uint32_t)0x00000000) /*!< Priority group=0 (7 bits of pre-emption priority, 1 bit of subpriority) */ +#define SCB_AIRCR_PRIGROUP1 \ + ((uint32_t)0x00000100) /*!< Priority group=1 (6 bits of pre-emption priority, 2 bits of subpriority) */ +#define SCB_AIRCR_PRIGROUP2 \ + ((uint32_t)0x00000200) /*!< Priority group=2 (5 bits of pre-emption priority, 3 bits of subpriority) */ +#define SCB_AIRCR_PRIGROUP3 \ + ((uint32_t)0x00000300) /*!< Priority group=3 (4 bits of pre-emption priority, 4 bits of subpriority) */ +#define SCB_AIRCR_PRIGROUP4 \ + ((uint32_t)0x00000400) /*!< Priority group=4 (3 bits of pre-emption priority, 5 bits of subpriority) */ +#define SCB_AIRCR_PRIGROUP5 \ + ((uint32_t)0x00000500) /*!< Priority group=5 (2 bits of pre-emption priority, 6 bits of subpriority) */ +#define SCB_AIRCR_PRIGROUP6 \ + ((uint32_t)0x00000600) /*!< Priority group=6 (1 bit of pre-emption priority, 7 bits of subpriority) */ +#define SCB_AIRCR_PRIGROUP7 \ + ((uint32_t)0x00000700) /*!< Priority group=7 (no pre-emption priority, 8 bits of subpriority) */ + +#define SCB_AIRCR_ENDIANESS ((uint32_t)0x00008000) /*!< Data endianness bit */ +#define SCB_AIRCR_VECTKEY ((uint32_t)0xFFFF0000) /*!< Register key (VECTKEY) - Reads as 0xFA05 (VECTKEYSTAT) */ + +/******************* Bit definition for SCB_SCR register ********************/ +#define SCB_SCR_SLEEPONEXIT ((uint8_t)0x02) /*!< Sleep on exit bit */ +#define SCB_SCR_SLEEPDEEP ((uint8_t)0x04) /*!< Sleep deep bit */ +#define SCB_SCR_SEVONPEND ((uint8_t)0x10) /*!< Wake up from WFE */ + +/******************** Bit definition for SCB_CCR register *******************/ +#define SCB_CCR_NONBASETHRDENA \ + ((uint16_t)0x0001) /*!< Thread mode can be entered from any level in Handler mode by controlled return value */ +#define SCB_CCR_USERSETMPEND \ + ((uint16_t)0x0002) /*!< Enables user code to write the Software Trigger Interrupt register to trigger (pend) a \ + Main exception */ +#define SCB_CCR_UNALIGN_TRP ((uint16_t)0x0008) /*!< Trap for unaligned access */ +#define SCB_CCR_DIV_0_TRP ((uint16_t)0x0010) /*!< Trap on Divide by 0 */ +#define SCB_CCR_BFHFNMIGN ((uint16_t)0x0100) /*!< Handlers running at priority -1 and -2 */ +#define SCB_CCR_STKALIGN \ + ((uint16_t)0x0200) /*!< On exception entry, the SP used prior to the exception is adjusted to be 8-byte aligned */ + +/******************* Bit definition for SCB_SHPR register ********************/ +#define SCB_SHPR_PRI_N \ + ((uint32_t)0x000000FF) /*!< Priority of system handler 4,8, and 12. Mem Manage, reserved and Debug Monitor */ +#define SCB_SHPR_PRI_N1 \ + ((uint32_t)0x0000FF00) /*!< Priority of system handler 5,9, and 13. Bus Fault, reserved and reserved */ +#define SCB_SHPR_PRI_N2 \ + ((uint32_t)0x00FF0000) /*!< Priority of system handler 6,10, and 14. Usage Fault, reserved and PendSV */ +#define SCB_SHPR_PRI_N3 \ + ((uint32_t)0xFF000000) /*!< Priority of system handler 7,11, and 15. Reserved, SVCall and SysTick */ + +/****************** Bit definition for SCB_SHCSR register *******************/ +#define SCB_SHCSR_MEMFAULTACT ((uint32_t)0x00000001) /*!< MemManage is active */ +#define SCB_SHCSR_BUSFAULTACT ((uint32_t)0x00000002) /*!< BusFault is active */ +#define SCB_SHCSR_USGFAULTACT ((uint32_t)0x00000008) /*!< UsageFault is active */ +#define SCB_SHCSR_SVCALLACT ((uint32_t)0x00000080) /*!< SVCall is active */ +#define SCB_SHCSR_MONITORACT ((uint32_t)0x00000100) /*!< Monitor is active */ +#define SCB_SHCSR_PENDSVACT ((uint32_t)0x00000400) /*!< PendSV is active */ +#define SCB_SHCSR_SYSTICKACT ((uint32_t)0x00000800) /*!< SysTick is active */ +#define SCB_SHCSR_USGFAULTPENDED ((uint32_t)0x00001000) /*!< Usage Fault is pended */ +#define SCB_SHCSR_MEMFAULTPENDED ((uint32_t)0x00002000) /*!< MemManage is pended */ +#define SCB_SHCSR_BUSFAULTPENDED ((uint32_t)0x00004000) /*!< Bus Fault is pended */ +#define SCB_SHCSR_SVCALLPENDED ((uint32_t)0x00008000) /*!< SVCall is pended */ +#define SCB_SHCSR_MEMFAULTENA ((uint32_t)0x00010000) /*!< MemManage enable */ +#define SCB_SHCSR_BUSFAULTENA ((uint32_t)0x00020000) /*!< Bus Fault enable */ +#define SCB_SHCSR_USGFAULTENA ((uint32_t)0x00040000) /*!< UsageFault enable */ + +/******************************************************************************/ +/* */ +/* DMA Controller */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for DMA_INTSTS register ********************/ +#define DMA_INTSTS_GLBF1 ((uint32_t)0x00000001) /*!< Channel 1 Global interrupt flag */ +#define DMA_INTSTS_TXCF1 ((uint32_t)0x00000002) /*!< Channel 1 Transfer Complete flag */ +#define DMA_INTSTS_HTXF1 ((uint32_t)0x00000004) /*!< Channel 1 Half Transfer flag */ +#define DMA_INTSTS_ERRF1 ((uint32_t)0x00000008) /*!< Channel 1 Transfer Error flag */ +#define DMA_INTSTS_GLBF2 ((uint32_t)0x00000010) /*!< Channel 2 Global interrupt flag */ +#define DMA_INTSTS_TXCF2 ((uint32_t)0x00000020) /*!< Channel 2 Transfer Complete flag */ +#define DMA_INTSTS_HTXF2 ((uint32_t)0x00000040) /*!< Channel 2 Half Transfer flag */ +#define DMA_INTSTS_ERRF2 ((uint32_t)0x00000080) /*!< Channel 2 Transfer Error flag */ +#define DMA_INTSTS_GLBF3 ((uint32_t)0x00000100) /*!< Channel 3 Global interrupt flag */ +#define DMA_INTSTS_TXCF3 ((uint32_t)0x00000200) /*!< Channel 3 Transfer Complete flag */ +#define DMA_INTSTS_HTXF3 ((uint32_t)0x00000400) /*!< Channel 3 Half Transfer flag */ +#define DMA_INTSTS_ERRF3 ((uint32_t)0x00000800) /*!< Channel 3 Transfer Error flag */ +#define DMA_INTSTS_GLBF4 ((uint32_t)0x00001000) /*!< Channel 4 Global interrupt flag */ +#define DMA_INTSTS_TXCF4 ((uint32_t)0x00002000) /*!< Channel 4 Transfer Complete flag */ +#define DMA_INTSTS_HTXF4 ((uint32_t)0x00004000) /*!< Channel 4 Half Transfer flag */ +#define DMA_INTSTS_ERRF4 ((uint32_t)0x00008000) /*!< Channel 4 Transfer Error flag */ +#define DMA_INTSTS_GLBF5 ((uint32_t)0x00010000) /*!< Channel 5 Global interrupt flag */ +#define DMA_INTSTS_TXCF5 ((uint32_t)0x00020000) /*!< Channel 5 Transfer Complete flag */ +#define DMA_INTSTS_HTXF5 ((uint32_t)0x00040000) /*!< Channel 5 Half Transfer flag */ +#define DMA_INTSTS_ERRF5 ((uint32_t)0x00080000) /*!< Channel 5 Transfer Error flag */ + +/******************* Bit definition for DMA_INTCLR register *******************/ +#define DMA_INTCLR_CGLBF1 ((uint32_t)0x00000001) /*!< Channel 1 Global interrupt clear */ +#define DMA_INTCLR_CTXCF1 ((uint32_t)0x00000002) /*!< Channel 1 Transfer Complete clear */ +#define DMA_INTCLR_CHTXF1 ((uint32_t)0x00000004) /*!< Channel 1 Half Transfer clear */ +#define DMA_INTCLR_CERRF1 ((uint32_t)0x00000008) /*!< Channel 1 Transfer Error clear */ +#define DMA_INTCLR_CGLBF2 ((uint32_t)0x00000010) /*!< Channel 2 Global interrupt clear */ +#define DMA_INTCLR_CTXCF2 ((uint32_t)0x00000020) /*!< Channel 2 Transfer Complete clear */ +#define DMA_INTCLR_CHTXF2 ((uint32_t)0x00000040) /*!< Channel 2 Half Transfer clear */ +#define DMA_INTCLR_CERRF2 ((uint32_t)0x00000080) /*!< Channel 2 Transfer Error clear */ +#define DMA_INTCLR_CGLBF3 ((uint32_t)0x00000100) /*!< Channel 3 Global interrupt clear */ +#define DMA_INTCLR_CTXCF3 ((uint32_t)0x00000200) /*!< Channel 3 Transfer Complete clear */ +#define DMA_INTCLR_CHTXF3 ((uint32_t)0x00000400) /*!< Channel 3 Half Transfer clear */ +#define DMA_INTCLR_CERRF3 ((uint32_t)0x00000800) /*!< Channel 3 Transfer Error clear */ +#define DMA_INTCLR_CGLBF4 ((uint32_t)0x00001000) /*!< Channel 4 Global interrupt clear */ +#define DMA_INTCLR_CTXCF4 ((uint32_t)0x00002000) /*!< Channel 4 Transfer Complete clear */ +#define DMA_INTCLR_CHTXF4 ((uint32_t)0x00004000) /*!< Channel 4 Half Transfer clear */ +#define DMA_INTCLR_CERRF4 ((uint32_t)0x00008000) /*!< Channel 4 Transfer Error clear */ +#define DMA_INTCLR_CGLBF5 ((uint32_t)0x00010000) /*!< Channel 5 Global interrupt clear */ +#define DMA_INTCLR_CTXCF5 ((uint32_t)0x00020000) /*!< Channel 5 Transfer Complete clear */ +#define DMA_INTCLR_CHTXF5 ((uint32_t)0x00040000) /*!< Channel 5 Half Transfer clear */ +#define DMA_INTCLR_CERRF5 ((uint32_t)0x00080000) /*!< Channel 5 Transfer Error clear */ + +/******************* Bit definition for DMA_CHCFG1 register *******************/ +#define DMA_CHCFG1_CHEN ((uint16_t)0x0001) /*!< Channel enable*/ +#define DMA_CHCFG1_TXCIE ((uint16_t)0x0002) /*!< Transfer complete interrupt enable */ +#define DMA_CHCFG1_HTXIE ((uint16_t)0x0004) /*!< Half Transfer interrupt enable */ +#define DMA_CHCFG1_ERRIE ((uint16_t)0x0008) /*!< Transfer error interrupt enable */ +#define DMA_CHCFG1_DIR ((uint16_t)0x0010) /*!< Data transfer direction */ +#define DMA_CHCFG1_CIRC ((uint16_t)0x0020) /*!< Circular mode */ +#define DMA_CHCFG1_PINC ((uint16_t)0x0040) /*!< Peripheral increment mode */ +#define DMA_CHCFG1_MINC ((uint16_t)0x0080) /*!< Memory increment mode */ + +#define DMA_CHCFG1_PSIZE ((uint16_t)0x0300) /*!< PSIZE[1:0] bits (Peripheral size) */ +#define DMA_CHCFG1_PSIZE_0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define DMA_CHCFG1_PSIZE_1 ((uint16_t)0x0200) /*!< Bit 1 */ + +#define DMA_CHCFG1_MSIZE ((uint16_t)0x0C00) /*!< MSIZE[1:0] bits (Memory size) */ +#define DMA_CHCFG1_MSIZE_0 ((uint16_t)0x0400) /*!< Bit 0 */ +#define DMA_CHCFG1_MSIZE_1 ((uint16_t)0x0800) /*!< Bit 1 */ + +#define DMA_CHCFG1_PRIOLVL ((uint16_t)0x3000) /*!< PL[1:0] bits(Channel Priority level) */ +#define DMA_CHCFG1_PRIOLVL_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define DMA_CHCFG1_PRIOLVL_1 ((uint16_t)0x2000) /*!< Bit 1 */ + +#define DMA_CHCFG1_MEM2MEM ((uint16_t)0x4000) /*!< Memory to memory mode */ + +/******************* Bit definition for DMA_CHCFG2 register *******************/ +#define DMA_CHCFG2_CHEN ((uint16_t)0x0001) /*!< Channel enable */ +#define DMA_CHCFG2_TXCIE ((uint16_t)0x0002) /*!< Transfer complete interrupt enable */ +#define DMA_CHCFG2_HTXIE ((uint16_t)0x0004) /*!< Half Transfer interrupt enable */ +#define DMA_CHCFG2_ERRIE ((uint16_t)0x0008) /*!< Transfer error interrupt enable */ +#define DMA_CHCFG2_DIR ((uint16_t)0x0010) /*!< Data transfer direction */ +#define DMA_CHCFG2_CIRC ((uint16_t)0x0020) /*!< Circular mode */ +#define DMA_CHCFG2_PINC ((uint16_t)0x0040) /*!< Peripheral increment mode */ +#define DMA_CHCFG2_MINC ((uint16_t)0x0080) /*!< Memory increment mode */ + +#define DMA_CHCFG2_PSIZE ((uint16_t)0x0300) /*!< PSIZE[1:0] bits (Peripheral size) */ +#define DMA_CHCFG2_PSIZE_0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define DMA_CHCFG2_PSIZE_1 ((uint16_t)0x0200) /*!< Bit 1 */ + +#define DMA_CHCFG2_MSIZE ((uint16_t)0x0C00) /*!< MSIZE[1:0] bits (Memory size) */ +#define DMA_CHCFG2_MSIZE_0 ((uint16_t)0x0400) /*!< Bit 0 */ +#define DMA_CHCFG2_MSIZE_1 ((uint16_t)0x0800) /*!< Bit 1 */ + +#define DMA_CHCFG2_PRIOLVL ((uint16_t)0x3000) /*!< PL[1:0] bits (Channel Priority level) */ +#define DMA_CHCFG2_PRIOLVL_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define DMA_CHCFG2_PRIOLVL_1 ((uint16_t)0x2000) /*!< Bit 1 */ + +#define DMA_CHCFG2_MEM2MEM ((uint16_t)0x4000) /*!< Memory to memory mode */ + +/******************* Bit definition for DMA_CHCFG3 register *******************/ +#define DMA_CHCFG3_CHEN ((uint16_t)0x0001) /*!< Channel enable */ +#define DMA_CHCFG3_TXCIE ((uint16_t)0x0002) /*!< Transfer complete interrupt enable */ +#define DMA_CHCFG3_HTXIE ((uint16_t)0x0004) /*!< Half Transfer interrupt enable */ +#define DMA_CHCFG3_ERRIE ((uint16_t)0x0008) /*!< Transfer error interrupt enable */ +#define DMA_CHCFG3_DIR ((uint16_t)0x0010) /*!< Data transfer direction */ +#define DMA_CHCFG3_CIRC ((uint16_t)0x0020) /*!< Circular mode */ +#define DMA_CHCFG3_PINC ((uint16_t)0x0040) /*!< Peripheral increment mode */ +#define DMA_CHCFG3_MINC ((uint16_t)0x0080) /*!< Memory increment mode */ + +#define DMA_CHCFG3_PSIZE ((uint16_t)0x0300) /*!< PSIZE[1:0] bits (Peripheral size) */ +#define DMA_CHCFG3_PSIZE_0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define DMA_CHCFG3_PSIZE_1 ((uint16_t)0x0200) /*!< Bit 1 */ + +#define DMA_CHCFG3_MSIZE ((uint16_t)0x0C00) /*!< MSIZE[1:0] bits (Memory size) */ +#define DMA_CHCFG3_MSIZE_0 ((uint16_t)0x0400) /*!< Bit 0 */ +#define DMA_CHCFG3_MSIZE_1 ((uint16_t)0x0800) /*!< Bit 1 */ + +#define DMA_CHCFG3_PRIOLVL ((uint16_t)0x3000) /*!< PL[1:0] bits (Channel Priority level) */ +#define DMA_CHCFG3_PRIOLVL_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define DMA_CHCFG3_PRIOLVL_1 ((uint16_t)0x2000) /*!< Bit 1 */ + +#define DMA_CHCFG3_MEM2MEM ((uint16_t)0x4000) /*!< Memory to memory mode */ + +/*!<****************** Bit definition for DMA_CHCFG4 register *******************/ +#define DMA_CHCFG4_CHEN ((uint16_t)0x0001) /*!< Channel enable */ +#define DMA_CHCFG4_TXCIE ((uint16_t)0x0002) /*!< Transfer complete interrupt enable */ +#define DMA_CHCFG4_HTXIE ((uint16_t)0x0004) /*!< Half Transfer interrupt enable */ +#define DMA_CHCFG4_ERRIE ((uint16_t)0x0008) /*!< Transfer error interrupt enable */ +#define DMA_CHCFG4_DIR ((uint16_t)0x0010) /*!< Data transfer direction */ +#define DMA_CHCFG4_CIRC ((uint16_t)0x0020) /*!< Circular mode */ +#define DMA_CHCFG4_PINC ((uint16_t)0x0040) /*!< Peripheral increment mode */ +#define DMA_CHCFG4_MINC ((uint16_t)0x0080) /*!< Memory increment mode */ + +#define DMA_CHCFG4_PSIZE ((uint16_t)0x0300) /*!< PSIZE[1:0] bits (Peripheral size) */ +#define DMA_CHCFG4_PSIZE_0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define DMA_CHCFG4_PSIZE_1 ((uint16_t)0x0200) /*!< Bit 1 */ + +#define DMA_CHCFG4_MSIZE ((uint16_t)0x0C00) /*!< MSIZE[1:0] bits (Memory size) */ +#define DMA_CHCFG4_MSIZE_0 ((uint16_t)0x0400) /*!< Bit 0 */ +#define DMA_CHCFG4_MSIZE_1 ((uint16_t)0x0800) /*!< Bit 1 */ + +#define DMA_CHCFG4_PRIOLVL ((uint16_t)0x3000) /*!< PL[1:0] bits (Channel Priority level) */ +#define DMA_CHCFG4_PRIOLVL_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define DMA_CHCFG4_PRIOLVL_1 ((uint16_t)0x2000) /*!< Bit 1 */ + +#define DMA_CHCFG4_MEM2MEM ((uint16_t)0x4000) /*!< Memory to memory mode */ + +/****************** Bit definition for DMA_CHCFG5 register *******************/ +#define DMA_CHCFG5_CHEN ((uint16_t)0x0001) /*!< Channel enable */ +#define DMA_CHCFG5_TXCIE ((uint16_t)0x0002) /*!< Transfer complete interrupt enable */ +#define DMA_CHCFG5_HTXIE ((uint16_t)0x0004) /*!< Half Transfer interrupt enable */ +#define DMA_CHCFG5_ERRIE ((uint16_t)0x0008) /*!< Transfer error interrupt enable */ +#define DMA_CHCFG5_DIR ((uint16_t)0x0010) /*!< Data transfer direction */ +#define DMA_CHCFG5_CIRC ((uint16_t)0x0020) /*!< Circular mode */ +#define DMA_CHCFG5_PINC ((uint16_t)0x0040) /*!< Peripheral increment mode */ +#define DMA_CHCFG5_MINC ((uint16_t)0x0080) /*!< Memory increment mode */ + +#define DMA_CHCFG5_PSIZE ((uint16_t)0x0300) /*!< PSIZE[1:0] bits (Peripheral size) */ +#define DMA_CHCFG5_PSIZE_0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define DMA_CHCFG5_PSIZE_1 ((uint16_t)0x0200) /*!< Bit 1 */ + +#define DMA_CHCFG5_MSIZE ((uint16_t)0x0C00) /*!< MSIZE[1:0] bits (Memory size) */ +#define DMA_CHCFG5_MSIZE_0 ((uint16_t)0x0400) /*!< Bit 0 */ +#define DMA_CHCFG5_MSIZE_1 ((uint16_t)0x0800) /*!< Bit 1 */ + +#define DMA_CHCFG5_PRIOLVL ((uint16_t)0x3000) /*!< PL[1:0] bits (Channel Priority level) */ +#define DMA_CHCFG5_PRIOLVL_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define DMA_CHCFG5_PRIOLVL_1 ((uint16_t)0x2000) /*!< Bit 1 */ + +#define DMA_CHCFG5_MEM2MEM ((uint16_t)0x4000) /*!< Memory to memory mode enable */ + +/****************** Bit definition for DMA_TXNUM1 register ******************/ +#define DMA_TXNUM1_NDTX ((uint16_t)0xFFFF) /*!< Number of data to Transfer */ + +/****************** Bit definition for DMA_TXNUM2 register ******************/ +#define DMA_TXNUM2_NDTX ((uint16_t)0xFFFF) /*!< Number of data to Transfer */ + +/****************** Bit definition for DMA_TXNUM3 register ******************/ +#define DMA_TXNUM3_NDTX ((uint16_t)0xFFFF) /*!< Number of data to Transfer */ + +/****************** Bit definition for DMA_TXNUM4 register ******************/ +#define DMA_TXNUM4_NDTX ((uint16_t)0xFFFF) /*!< Number of data to Transfer */ + +/****************** Bit definition for DMA_TXNUM5 register ******************/ +#define DMA_TXNUM5_NDTX ((uint16_t)0xFFFF) /*!< Number of data to Transfer */ + +/****************** Bit definition for DMA_PADDR1 register *******************/ +#define DMA_PADDR1_ADDR ((uint32_t)0xFFFFFFFF) /*!< Peripheral Address */ + +/****************** Bit definition for DMA_PADDR2 register *******************/ +#define DMA_PADDR2_ADDR ((uint32_t)0xFFFFFFFF) /*!< Peripheral Address */ + +/****************** Bit definition for DMA_PADDR3 register *******************/ +#define DMA_PADDR3_ADDR ((uint32_t)0xFFFFFFFF) /*!< Peripheral Address */ + +/****************** Bit definition for DMA_PADDR4 register *******************/ +#define DMA_PADDR4_ADDR ((uint32_t)0xFFFFFFFF) /*!< Peripheral Address */ + +/****************** Bit definition for DMA_PADDR5 register *******************/ +#define DMA_PADDR5_ADDR ((uint32_t)0xFFFFFFFF) /*!< Peripheral Address */ + +/****************** Bit definition for DMA_MADDR1 register *******************/ +#define DMA_MADDR1_ADDR ((uint32_t)0xFFFFFFFF) /*!< Memory Address */ + +/****************** Bit definition for DMA_MADDR2 register *******************/ +#define DMA_MADDR2_ADDR ((uint32_t)0xFFFFFFFF) /*!< Memory Address */ + +/****************** Bit definition for DMA_MADDR3 register *******************/ +#define DMA_MADDR3_ADDR ((uint32_t)0xFFFFFFFF) /*!< Memory Address */ + +/****************** Bit definition for DMA_MADDR4 register *******************/ +#define DMA_MADDR4_ADDR ((uint32_t)0xFFFFFFFF) /*!< Memory Address */ + +/****************** Bit definition for DMA_MADDR5 register *******************/ +#define DMA_MADDR5_ADDR ((uint32_t)0xFFFFFFFF) /*!< Memory Address */ + +/******************************************************************************/ +/* */ +/* Analog to Digital Converter */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for ADC_CTRL register ********************/ +#define ADC_CTRL_EN ((uint32_t)0x00000001) /*!< Bit 0 */ +#define ADC_CTRL_TS_EN ((uint32_t)0x00000002) /*!< Bit 1 */ +#define ADC_CTRL_AWD_EN ((uint32_t)0x00000004) /*!< Bit 2 */ +#define ADC_CTRL_DMA_MODE_EN ((uint32_t)0x00000008) /*!< Bit 3 */ + +#define ADC_CTRL_CH_SEL ((uint32_t)0x00000070) /*!< ADC_CH[6:4] bits (channel select bits) */ +#define ADC_CTRL_CH_0 ((uint32_t)0x00000000) /*!< Bit 0 */ +#define ADC_CTRL_CH_1 ((uint32_t)0x00000010) /*!< Bit 1 */ +#define ADC_CTRL_CH_2 ((uint32_t)0x00000020) /*!< Bit 2 */ +#define ADC_CTRL_CH_3 ((uint32_t)0x00000030) /*!< Bit 3 */ +#define ADC_CTRL_CH_4 ((uint32_t)0x00000040) /*!< Bit 4 */ +#define ADC_CTRL_CH_5 ((uint32_t)0x00000050) /*!< Bit 5 */ +#define ADC_CTRL_CH_6 ((uint32_t)0x00000060) /*!< Bit 6 */ +#define ADC_CTRL_CH_7 ((uint32_t)0x00000070) /*!< Bit 7 */ + +#define ADC_CTRL_MODE ((uint32_t)0x00000080) +#define ADC_CTRL_DONE_IE ((uint32_t)0x00000100) /*!< interrupt enable */ +#define ADC_CTRL_AWD_IE ((uint32_t)0x00000200) +#define ADC_CTRL_PGARDY_IE ((uint32_t)0x00000400) + +/******************** Bit definition for ADC_SR register ********************/ +#define ADC_SR_DONE_F ((uint8_t)0x01) /*!< DONE flag */ +#define ADC_SR_AWD_F ((uint8_t)0x02) /*!< Analog watchdog flag */ +#define ADC_SR_PGARDY_F ((uint8_t)0x04) /*!< PGA_READY flag */ + +/******************** Bit definition for ADC_OVR_SAMP_CNT register ********************/ +#define ADC_OS_CNT_LD_CNT ((uint8_t)0x1F) + +/******************** Bit definition for ADC_DAT register ********************/ +#define ADC_DAT_DATA ((uint32_t)0x0000FFFF) /*!< Regular data */ + +/******************** Bit definition for ADC_WDT_THRES register ********************/ +#define ADC_WDT_THRES_LT ((uint32_t)0x000003FF) /*!< Regular data */ +#define ADC_WDT_THRES_HT ((uint32_t)0x0FFC0000) /*!< Regular data */ + +/******************** Bit definition for ADC_PGA_CFG register ********************/ +#define ADC_PGA_CFG_MICBIAS_EN ((uint32_t)0x00000001) /*!< Regular data */ + +#define ADC_PGA_CFG_MICBIAS ((uint32_t)0x0000000E) /*!< Regular data */ +#define ADC_PGA_CFG_MICBIAS_0 ((uint32_t)0x00000000) +#define ADC_PGA_CFG_MICBIAS_1 ((uint32_t)0x00000002) +#define ADC_PGA_CFG_MICBIAS_2 ((uint32_t)0x00000004) +#define ADC_PGA_CFG_MICBIAS_3 ((uint32_t)0x00000006) +#define ADC_PGA_CFG_MICBIAS_4 ((uint32_t)0x00000008) +#define ADC_PGA_CFG_MICBIAS_5 ((uint32_t)0x0000000A) +#define ADC_PGA_CFG_MICBIAS_6 ((uint32_t)0x0000000C) +#define ADC_PGA_CFG_MICBIAS_7 ((uint32_t)0x0000000E) + +#define ADC_PGA_CFG_INIT_ENA ((uint32_t)0x00000010) + +#define ADC_PGA_CFG_PEAK ((uint32_t)0x00000600) +#define ADC_PGA_CFG_PEAK_0 ((uint32_t)0x00000000) +#define ADC_PGA_CFG_PEAK_1 ((uint32_t)0x00000200) +#define ADC_PGA_CFG_PEAK_2 ((uint32_t)0x00000400) +#define ADC_PGA_CFG_PEAK_3 ((uint32_t)0x00000600) + +#define ADC_PGA_CFG_DRIVE ((uint32_t)0x00001800) +#define ADC_PGA_CFG_DRIVE_0 ((uint32_t)0x00000000) +#define ADC_PGA_CFG_DRIVE_1 ((uint32_t)0x00000800) +#define ADC_PGA_CFG_DRIVE_2 ((uint32_t)0x00001000) +#define ADC_PGA_CFG_DRIVE_3 ((uint32_t)0x00001800) + +#define ADC_PGA_CFG_EN ((uint32_t)0x00002000) + +#define ADC_PGA_CFG_GAIN ((uint32_t)0x0001C000) +#define ADC_PGA_CFG_GAIN_0dB ((uint32_t)0x00000000) +#define ADC_PGA_CFG_GAIN_6dB ((uint32_t)0x00004000) +#define ADC_PGA_CFG_GAIN_12dB ((uint32_t)0x00008000) +#define ADC_PGA_CFG_GAIN_18dB ((uint32_t)0x0000C000) +#define ADC_PGA_CFG_GAIN_24dB ((uint32_t)0x00010000) +#define ADC_PGA_CFG_GAIN_30dB ((uint32_t)0x00014000) +#define ADC_PGA_CFG_GAIN_36dB ((uint32_t)0x00018000) +#define ADC_PGA_CFG_GAIN_42dB ((uint32_t)0x0001C000) + +/******************* Bit definition for ADC_VOICE_DET_CR register ********************/ +#define ADC_VOICE_DET_CR_ZCRD_EN ((uint32_t)0x00000001) +#define ADC_VOICE_DET_CR_ED_EN ((uint32_t)0x00000002) +#define ADC_VOICE_DET_CR_FILTTER_BYP ((uint32_t)0x00000004) + +/******************* Bit definition for ADC_VOICE_ZCR_THRES register ********************/ +#define ADC_VAD_ZCRD_LOW_THRES ((uint32_t)0x000000FF) +#define ADC_VAD_ZCRD_HIGH_THRES ((uint32_t)0x0000FF00) + +/******************* Bit definition for ADC_VOICE_ED_THRES register ********************/ +#define ADC_VOICE_ED_THRES_MOFFSET ((uint32_t)0x007FFFFF) + +/******************* Bit definition for ADC_VOICE_ED_DWN_THRES register ********************/ +#define ADC_VOICE_ED_DWN_THRES_GATE_MIN ((uint32_t)0x007FFFFF) + +/******************* Bit definition for ADC_VOICE_ED_UP_THRES register ********************/ +#define ADC_VOICE_ED_UP_THRES_GATE_MAX ((uint32_t)0x007FFFFF) + +/******************************************************************************/ +/* */ +/* IRC */ +/* */ +/******************************************************************************/ +/******************** Bits definition for FREQ_CARRI_ON register *******************/ +#define IR_FREQ_CARR_ON_Msk ((uint16_t)0x03FF) /*!< IR_FREQ_CARR_ON (Bitfield-Mask: 0x3ff) */ + +/******************** Bits definition for FREQ_CARR_OFF register *******************/ +#define IR_FREQ_CARR_OFF_Msk ((uint16_t)0x03FF) /*!< IR_FREQ_CARR_OFF (Bitfield-Mask: 0x3ff) */ + +/******************** Bits definition for LOGIC_ONE_TIME register *******************/ +#define IR_LOGIC_ONE_TIME_LOGIC_ONE_SPACE_Pos (0) /*!< IR_LOGIC_ONE_TIME_LOGIC_ONE_SPACE (Bit 0) */ +#define IR_LOGIC_ONE_TIME_LOGIC_ONE_SPACE_Msk ((uint16_t)0x00FF) /*!< IR_LOGIC_ONE_TIME_LOGIC_ONE_SPACE (Bitfield-Mask: 0xff) */ +#define IR_LOGIC_ONE_TIME_LOGIC_ONE_MARK_Pos (8) /*!< IR_LOGIC_ONE_TIME_LOGIC_ONE_MARK (Bit 0) */ +#define IR_LOGIC_ONE_TIME_LOGIC_ONE_MARK_Msk ((uint16_t)0xFF00) /*!< IR_LOGIC_ONE_TIME_LOGIC_ONE_MARK (Bitfield-Mask: 0xff) */ + +/******************** Bits definition for LOGIC_ZERO_TIME register *******************/ +#define IR_LOGIC_ZERO_TIME_LOGIC_ZERO_SPACE_Pos (0) /*!< IR_LOGIC_ZERO_TIME_LOGIC_ZERO_SPACE (Bit 0) */ +#define IR_LOGIC_ZERO_TIME_LOGIC_ZERO_SPACE_Msk ((uint16_t)0x00FF) /*!< IR_LOGIC_ZERO_TIME_LOGIC_ZERO_SPACE (Bitfield-Mask: 0xff) */ +#define IR_LOGIC_ZERO_TIME_LOGIC_ZERO_MARK_Pos (8) /*!< IR_LOGIC_ZERO_TIME_LOGIC_ZERO_MARK (Bit 8) */ +#define IR_LOGIC_ZERO_TIME_LOGIC_ZERO_MARK_Msk ((uint16_t)0xFF00) /*!< IR_LOGIC_ZERO_TIME_LOGIC_ZERO_MARK (Bitfield-Mask: 0xff) */ + +/******************** Bits definition for IR_CTRL register *******************/ +#define IR_CTRL_CODE_FIFO_RESET_Pos (0) /*!< IR_CTRL_REG: IR_CODE_FIFO_RESET (Bit 0) */ +#define IR_CTRL_CODE_FIFO_RESET_Msk ((uint16_t)0x0001) /*!< IR_CTRL_REG: IR_CODE_FIFO_RESET (Bitfield-Mask: 0x01) */ +#define IR_CTRL_REP_FIFO_RESET_Pos (1) /*!< IR_CTRL_REG: IR_REP_FIFO_RESET (Bit 1) */ +#define IR_CTRL_REP_FIFO_RESET_Msk ((uint16_t)0x0002) /*!< IR_CTRL_REG: IR_REP_FIFO_RESET (Bitfield-Mask: 0x01) */ +#define IR_CTRL_ENABLE_Pos (2) /*!< IR_CTRL_REG: IR_ENABLE (Bit 2) */ +#define IR_CTRL_ENABLE_Msk ((uint16_t)0x0004) /*!< IR_CTRL_REG: IR_ENABLE (Bitfield-Mask: 0x01) */ +#define IR_CTRL_TX_START_Pos (3) /*!< IR_CTRL_REG: IR_TX_START (Bit 3) */ +#define IR_CTRL_TX_START_Msk ((uint16_t)0x0008) /*!< IR_CTRL_REG: IR_TX_START (Bitfield-Mask: 0x01) */ + +#define IR_CTRL_INVERT_OUTPUT_Pos (5) /*!< IR_CTRL_INVERT_OUTPUT (Bit 5) */ +#define IR_CTRL_INVERT_OUTPUT_Msk ((uint16_t)0x0020) /*!< IR_CTRL_INVERT_OUTPUT (Bitfield-Mask: 0x01) */ +#define IR_CTRL_LOGIC_ZERO_FORMAT_Pos (6) /*!< IR_CTRL_LOGIC_ZERO_FORMAT (Bit 6) */ +#define IR_CTRL_LOGIC_ZERO_FORMAT_Msk ((uint16_t)0x0040) /*!< IR_CTRL_LOGIC_ZERO_FORMAT (Bitfield-Mask: 0x01) */ +#define IR_CTRL_LOGIC_ONE_FORMAT_Pos (7) /*!< IR_CTRL_LOGIC_ONE_FORMAT (Bit 7) */ +#define IR_CTRL_LOGIC_ONE_FORMAT_Msk ((uint16_t)0x0080) /*!< IR_CTRL_LOGIC_ONE_FORMAT (Bitfield-Mask: 0x01) */ +#define IR_CTRL_IRQ_EN_Pos (8) /*!< IR_CTRL_IRQ_EN (Bit 8) */ +#define IR_CTRL_IRQ_EN_Msk ((uint16_t)0x0100) /*!< IR_CTRL_IRQ_EN (Bitfield-Mask: 0x01) */ + +/******************** Bits definition for IR_STATUS register *******************/ +#define IR_STATUS_CODE_FIFO_WORDS_Pos (0) /*!< IR IR_STATUS_REG: IR_CODE_FIFO_WRDS (Bit 0) */ +#define IR_STATUS_CODE_FIFO_WORDS_Msk ((uint16_t)0x003F) /*!< IR_STATUS_CODE_FIFO_WORDS_MASK (Bitfield-Mask: 0x3f) */ +#define IR_STATUS_REP_FIFO_WORDS_Pos (6) /*!< IR IR_STATUS_REG: IR_REP_FIFO_WRDS (Bit 6) */ +#define IR_STATUS_REP_FIFO_WORDS_Msk ((uint16_t)0x03C0) /*!< IR_STATUS_REP_FIFO_WORDS_MASK (Bitfield-Mask: 0x0f) */ +#define IR_STATUS_BUSY ((uint16_t)0x0400) /*!< IR_STATUS_BUSY (Bitfield-Mask: 0x01) */ +#define IR_IRQ_FLAG ((uint16_t)0x0800) /*!< IR_IRQ_FLAG (Bitfield-Mask: 0x01) */ + +/******************** Bits definition for IR_REPEAT_TIME register *******************/ +#define IR_REPEAT_TIME_Msk ((uint32_t)0x0000FFFF) /*!< IR_REPEAT_TIME (Bitfield-Mask: 0xffff) */ + +/******************** Bits definition for IR_CODE_FIFO register *******************/ +#define IR_CODE_FIFO_Msk ((uint32_t)0x001FFFFF) /*!< IR_CODE_FIFO (Bitfield-Mask: 0xffff) */ + +/******************** Bits definition for IR_REPEAT_FIFO register *******************/ +#define IR_REPEAT_FIFO_Msk ((uint32_t)0x001FFFFF) /*!< IR_REPEAT_FIFO (Bitfield-Mask: 0xffff) */ + +/******************************************************************************/ +/* */ +/* KEYSCAN */ +/* */ +/******************************************************************************/ +/******************** Bits definition for KEYSCAN_CTRL register *******************/ +#define KEYSCAN_CTRL_EN ((uint32_t)0x00000001) + +#define KEYSCAN_CTRL_MODE_SEL ((uint32_t)0x0000000C) +#define KEYSCAN_CTRL_MODE_AUTO ((uint32_t)0x00000000) +#define KEYSCAN_CTRL_MODE_SOFT ((uint32_t)0x00000004) +#define KEYSCAN_CTRL_MODE_LP ((uint32_t)0x00000008) + +#define KEYSCAN_CTRL_DTS ((uint32_t)0x00000070) +#define KEYSCAN_CTRL_DTS_10MS ((uint32_t)0x00000000) +#define KEYSCAN_CTRL_DTS_20MS ((uint32_t)0x00000010) +#define KEYSCAN_CTRL_DTS_40MS ((uint32_t)0x00000020) +#define KEYSCAN_CTRL_DTS_80MS ((uint32_t)0x00000030) +#define KEYSCAN_CTRL_DTS_160MS ((uint32_t)0x00000040) +#define KEYSCAN_CTRL_DTS_320MS ((uint32_t)0x00000050) +#define KEYSCAN_CTRL_DTS_640MS ((uint32_t)0x00000060) + +#define KEYSCAN_CTRL_WTS ((uint32_t)0x00000380) +#define KEYSCAN_CTRL_WTS_0MS ((uint32_t)0x00000000) +#define KEYSCAN_CTRL_WTS_32MS ((uint32_t)0x00000080) +#define KEYSCAN_CTRL_WTS_64MS ((uint32_t)0x00000100) +#define KEYSCAN_CTRL_WTS_96MS ((uint32_t)0x00000180) +#define KEYSCAN_CTRL_WTS_128MS ((uint32_t)0x00000200) +#define KEYSCAN_CTRL_WTS_160MS ((uint32_t)0x00000280) +#define KEYSCAN_CTRL_WTS_192MS ((uint32_t)0x00000300) +#define KEYSCAN_CTRL_WTS_224MS ((uint32_t)0x00000380) + +#define KEYSCAN_CTRL_MASK ((uint32_t)0x00000C00) +#define KEYSCAN_CTRL_MASK_13 ((uint32_t)0x00000000) +#define KEYSCAN_CTRL_MASK_8 ((uint32_t)0x00000400) +#define KEYSCAN_CTRL_MASK_10 ((uint32_t)0x00000800) + +#define KEYSCAN_CTRL_SOFT_START ((uint32_t)0x00001000) +#define KEYSCAN_CTRL_INFO_CLR ((uint32_t)0x00002000) +#define KEYSCAN_CTRL_INTEN ((uint32_t)0x00400000) +#define KEYSCAN_CTRL_IRP ((uint32_t)0x00800000) + +/******************************************************************************/ +/* */ +/* TIM */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for TIM_CTRL1 register ********************/ +#define TIM_CTRL1_CNTEN ((uint32_t)0x00000001) /*!< Counter enable */ +#define TIM_CTRL1_UPDIS ((uint32_t)0x00000002) /*!< Update disable */ +#define TIM_CTRL1_UPRS ((uint32_t)0x00000004) /*!< Update request source */ +#define TIM_CTRL1_ONEPM ((uint32_t)0x00000008) /*!< One pulse mode */ +#define TIM_CTRL1_DIR ((uint32_t)0x00000010) /*!< Direction */ + +#define TIM_CTRL1_CAMSEL ((uint32_t)0x00000060) /*!< CMS[1:0] bits (Center-aligned mode selection) */ +#define TIM_CTRL1_CAMSEL_0 ((uint32_t)0x00000020) /*!< Bit 0 */ +#define TIM_CTRL1_CAMSEL_1 ((uint32_t)0x00000040) /*!< Bit 1 */ + +#define TIM_CTRL1_ARPEN ((uint32_t)0x00000080) /*!< Auto-reload preload enable */ + +#define TIM_CTRL1_CLKD ((uint32_t)0x00000300) /*!< CKD[1:0] bits (clock division) */ +#define TIM_CTRL1_CLKD_0 ((uint32_t)0x00000100) /*!< Bit 0 */ +#define TIM_CTRL1_CLKD_1 ((uint32_t)0x00000200) /*!< Bit 1 */ + +#define TIM_CTRL1_IOMBKPEN ((uint32_t)0x00000400) /*!< Break_in selection from IOM/COMP */ +#define TIM_CTRL1_LBKPEN ((uint32_t)0x00010000) /*!< LOCKUP as bkp Enable*/ + +/******************* Bit definition for TIM_CTRL2 register ********************/ +#define TIM_CTRL2_CCPCTL ((uint32_t)0x00000001) /*!< Capture/Compare Preloaded Control */ +#define TIM_CTRL2_CCUSEL ((uint32_t)0x00000004) /*!< Capture/Compare Control Update Selection */ +#define TIM_CTRL2_CCDSEL ((uint32_t)0x00000008) /*!< Capture/Compare DMA Selection */ + +#define TIM_CTRL2_MMSEL ((uint32_t)0x00000070) /*!< MMS[2:0] bits (Master Mode Selection) */ +#define TIM_CTRL2_MMSEL_0 ((uint32_t)0x00000010) /*!< Bit 0 */ +#define TIM_CTRL2_MMSEL_1 ((uint32_t)0x00000020) /*!< Bit 1 */ +#define TIM_CTRL2_MMSEL_2 ((uint32_t)0x00000040) /*!< Bit 2 */ + +#define TIM_CTRL2_TI1SEL ((uint32_t)0x00000080) /*!< TI1 Selection */ +#define TIM_CTRL2_OI1 ((uint32_t)0x00000100) /*!< Output Idle state 1 (OC1 output) */ +#define TIM_CTRL2_OI1N ((uint32_t)0x00000200) /*!< Output Idle state 1 (OC1N output) */ +#define TIM_CTRL2_OI2 ((uint32_t)0x00000400) /*!< Output Idle state 2 (OC2 output) */ +#define TIM_CTRL2_OI2N ((uint32_t)0x00000800) /*!< Output Idle state 2 (OC2N output) */ +#define TIM_CTRL2_OI3 ((uint32_t)0x00001000) /*!< Output Idle state 3 (OC3 output) */ +#define TIM_CTRL2_OI3N ((uint32_t)0x00002000) /*!< Output Idle state 3 (OC3N output) */ +#define TIM_CTRL2_OI4 ((uint32_t)0x00004000) /*!< Output Idle state 4 (OC4 output) */ + +#define TIM_CTRL2_OI5 ((uint32_t)0x00010000) /*!< Output Idle state 5 (OC5 output) */ +#define TIM_CTRL2_OI6 ((uint32_t)0x00040000) /*!< Output Idle state 6 (OC6 output) */ + +/******************* Bit definition for TIM_SMCTRL register *******************/ +#define TIM_SMCTRL_SMSEL ((uint16_t)0x0007) /*!< SMS[2:0] bits (Slave mode selection) */ +#define TIM_SMCTRL_SMSEL_0 ((uint16_t)0x0001) /*!< Bit 0 */ +#define TIM_SMCTRL_SMSEL_1 ((uint16_t)0x0002) /*!< Bit 1 */ +#define TIM_SMCTRL_SMSEL_2 ((uint16_t)0x0004) /*!< Bit 2 */ + +#define TIM_SMCTRL_TSEL ((uint16_t)0x0070) /*!< TS[2:0] bits (Trigger selection) */ +#define TIM_SMCTRL_TSEL_0 ((uint16_t)0x0010) /*!< Bit 0 */ +#define TIM_SMCTRL_TSEL_1 ((uint16_t)0x0020) /*!< Bit 1 */ +#define TIM_SMCTRL_TSEL_2 ((uint16_t)0x0040) /*!< Bit 2 */ + +#define TIM_SMCTRL_MSMD ((uint16_t)0x0080) /*!< Master/slave mode */ + +#define TIM_SMCTRL_EXTF ((uint16_t)0x0F00) /*!< ETF[3:0] bits (External trigger filter) */ +#define TIM_SMCTRL_EXTF_0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define TIM_SMCTRL_EXTF_1 ((uint16_t)0x0200) /*!< Bit 1 */ +#define TIM_SMCTRL_EXTF_2 ((uint16_t)0x0400) /*!< Bit 2 */ +#define TIM_SMCTRL_EXTF_3 ((uint16_t)0x0800) /*!< Bit 3 */ + +#define TIM_SMCTRL_EXTPS ((uint16_t)0x3000) /*!< ETPS[1:0] bits (External trigger prescaler) */ +#define TIM_SMCTRL_EXTPS_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define TIM_SMCTRL_EXTPS_1 ((uint16_t)0x2000) /*!< Bit 1 */ + +#define TIM_SMCTRL_EXCEN ((uint16_t)0x4000) /*!< External clock enable */ +#define TIM_SMCTRL_EXTP ((uint16_t)0x8000) /*!< External trigger polarity */ + +/******************* Bit definition for TIM_DINTEN register *******************/ +#define TIM_DINTEN_UIEN ((uint16_t)0x0001) /*!< Update interrupt enable */ +#define TIM_DINTEN_CC1IEN ((uint16_t)0x0002) /*!< Capture/Compare 1 interrupt enable */ +#define TIM_DINTEN_CC2IEN ((uint16_t)0x0004) /*!< Capture/Compare 2 interrupt enable */ +#define TIM_DINTEN_CC3IEN ((uint16_t)0x0008) /*!< Capture/Compare 3 interrupt enable */ +#define TIM_DINTEN_CC4IEN ((uint16_t)0x0010) /*!< Capture/Compare 4 interrupt enable */ +#define TIM_DINTEN_COMIEN ((uint16_t)0x0020) /*!< COM interrupt enable */ +#define TIM_DINTEN_TIEN ((uint16_t)0x0040) /*!< Trigger interrupt enable */ +#define TIM_DINTEN_BIEN ((uint16_t)0x0080) /*!< Break interrupt enable */ +#define TIM_DINTEN_UDEN ((uint16_t)0x0100) /*!< Update DMA request enable */ +#define TIM_DINTEN_CC1DEN ((uint16_t)0x0200) /*!< Capture/Compare 1 DMA request enable */ +#define TIM_DINTEN_CC2DEN ((uint16_t)0x0400) /*!< Capture/Compare 2 DMA request enable */ +#define TIM_DINTEN_CC3DEN ((uint16_t)0x0800) /*!< Capture/Compare 3 DMA request enable */ +#define TIM_DINTEN_CC4DEN ((uint16_t)0x1000) /*!< Capture/Compare 4 DMA request enable */ +#define TIM_DINTEN_COMDEN ((uint16_t)0x2000) /*!< COM DMA request enable */ +#define TIM_DINTEN_TDEN ((uint16_t)0x4000) /*!< Trigger DMA request enable */ + +/******************** Bit definition for TIM_STS register ********************/ +#define TIM_STS_UDITF ((uint32_t)0x00000001) /*!< Update interrupt Flag */ +#define TIM_STS_CC1ITF ((uint32_t)0x00000002) /*!< Capture/Compare 1 interrupt Flag */ +#define TIM_STS_CC2ITF ((uint32_t)0x00000004) /*!< Capture/Compare 2 interrupt Flag */ +#define TIM_STS_CC3ITF ((uint32_t)0x00000008) /*!< Capture/Compare 3 interrupt Flag */ +#define TIM_STS_CC4ITF ((uint32_t)0x00000010) /*!< Capture/Compare 4 interrupt Flag */ +#define TIM_STS_COMITF ((uint32_t)0x00000020) /*!< COM interrupt Flag */ +#define TIM_STS_TITF ((uint32_t)0x00000040) /*!< Trigger interrupt Flag */ +#define TIM_STS_BITF ((uint32_t)0x00000080) /*!< Break interrupt Flag */ +#define TIM_STS_CC1OCF ((uint32_t)0x00000200) /*!< Capture/Compare 1 Overcapture Flag */ +#define TIM_STS_CC2OCF ((uint32_t)0x00000400) /*!< Capture/Compare 2 Overcapture Flag */ +#define TIM_STS_CC3OCF ((uint32_t)0x00000800) /*!< Capture/Compare 3 Overcapture Flag */ +#define TIM_STS_CC4OCF ((uint32_t)0x00001000) /*!< Capture/Compare 4 Overcapture Flag */ + +/******************* Bit definition for TIM_EVTGEN register ********************/ +#define TIM_EVTGEN_UDGN ((uint8_t)0x01) /*!< Update Generation */ +#define TIM_EVTGEN_CC1GN ((uint8_t)0x02) /*!< Capture/Compare 1 Generation */ +#define TIM_EVTGEN_CC2GN ((uint8_t)0x04) /*!< Capture/Compare 2 Generation */ +#define TIM_EVTGEN_CC3GN ((uint8_t)0x08) /*!< Capture/Compare 3 Generation */ +#define TIM_EVTGEN_CC4GN ((uint8_t)0x10) /*!< Capture/Compare 4 Generation */ +#define TIM_EVTGEN_CCUDGN ((uint8_t)0x20) /*!< Capture/Compare Control Update Generation */ +#define TIM_EVTGEN_TGN ((uint8_t)0x40) /*!< Trigger Generation */ +#define TIM_EVTGEN_BGN ((uint8_t)0x80) /*!< Break Generation */ + +/****************** Bit definition for TIM_CCMOD1 register *******************/ +#define TIM_CCMOD1_CC1SEL ((uint16_t)0x0003) /*!< CC1S[1:0] bits (Capture/Compare 1 Selection) */ +#define TIM_CCMOD1_CC1SEL_0 ((uint16_t)0x0001) /*!< Bit 0 */ +#define TIM_CCMOD1_CC1SEL_1 ((uint16_t)0x0002) /*!< Bit 1 */ + +#define TIM_CCMOD1_OC1FEN ((uint16_t)0x0004) /*!< Output Compare 1 Fast enable */ +#define TIM_CCMOD1_OC1PEN ((uint16_t)0x0008) /*!< Output Compare 1 Preload enable */ + +#define TIM_CCMOD1_OC1M ((uint16_t)0x0070) /*!< OC1M[2:0] bits (Output Compare 1 Mode) */ +#define TIM_CCMOD1_OC1M_0 ((uint16_t)0x0010) /*!< Bit 0 */ +#define TIM_CCMOD1_OC1M_1 ((uint16_t)0x0020) /*!< Bit 1 */ +#define TIM_CCMOD1_OC1M_2 ((uint16_t)0x0040) /*!< Bit 2 */ + +#define TIM_CCMOD1_OC1CEN ((uint16_t)0x0080) /*!< Output Compare 1Clear Enable */ + +#define TIM_CCMOD1_CC2SEL ((uint16_t)0x0300) /*!< CC2S[1:0] bits (Capture/Compare 2 Selection) */ +#define TIM_CCMOD1_CC2SEL_0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define TIM_CCMOD1_CC2SEL_1 ((uint16_t)0x0200) /*!< Bit 1 */ + +#define TIM_CCMOD1_OC2FEN ((uint16_t)0x0400) /*!< Output Compare 2 Fast enable */ +#define TIM_CCMOD1_OC2PEN ((uint16_t)0x0800) /*!< Output Compare 2 Preload enable */ + +#define TIM_CCMOD1_OC2M ((uint16_t)0x7000) /*!< OC2M[2:0] bits (Output Compare 2 Mode) */ +#define TIM_CCMOD1_OC2M_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define TIM_CCMOD1_OC2M_1 ((uint16_t)0x2000) /*!< Bit 1 */ +#define TIM_CCMOD1_OC2M_2 ((uint16_t)0x4000) /*!< Bit 2 */ + +#define TIM_CCMOD1_OC2CEN ((uint16_t)0x8000) /*!< Output Compare 2 Clear Enable */ + +/*----------------------------------------------------------------------------*/ + +#define TIM_CCMOD1_IC1PSC ((uint16_t)0x000C) /*!< IC1PSC[1:0] bits (Input Capture 1 Prescaler) */ +#define TIM_CCMOD1_IC1PSC_0 ((uint16_t)0x0004) /*!< Bit 0 */ +#define TIM_CCMOD1_IC1PSC_1 ((uint16_t)0x0008) /*!< Bit 1 */ + +#define TIM_CCMOD1_IC1F ((uint16_t)0x00F0) /*!< IC1F[3:0] bits (Input Capture 1 Filter) */ +#define TIM_CCMOD1_IC1F_0 ((uint16_t)0x0010) /*!< Bit 0 */ +#define TIM_CCMOD1_IC1F_1 ((uint16_t)0x0020) /*!< Bit 1 */ +#define TIM_CCMOD1_IC1F_2 ((uint16_t)0x0040) /*!< Bit 2 */ +#define TIM_CCMOD1_IC1F_3 ((uint16_t)0x0080) /*!< Bit 3 */ + +#define TIM_CCMOD1_IC2PSC ((uint16_t)0x0C00) /*!< IC2PSC[1:0] bits (Input Capture 2 Prescaler) */ +#define TIM_CCMOD1_IC2PSC_0 ((uint16_t)0x0400) /*!< Bit 0 */ +#define TIM_CCMOD1_IC2PSC_1 ((uint16_t)0x0800) /*!< Bit 1 */ + +#define TIM_CCMOD1_IC2F ((uint16_t)0xF000) /*!< IC2F[3:0] bits (Input Capture 2 Filter) */ +#define TIM_CCMOD1_IC2F_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define TIM_CCMOD1_IC2F_1 ((uint16_t)0x2000) /*!< Bit 1 */ +#define TIM_CCMOD1_IC2F_2 ((uint16_t)0x4000) /*!< Bit 2 */ +#define TIM_CCMOD1_IC2F_3 ((uint16_t)0x8000) /*!< Bit 3 */ + +/****************** Bit definition for TIM_CCMOD2 register *******************/ +#define TIM_CCMOD2_CC3SEL ((uint16_t)0x0003) /*!< CC3S[1:0] bits (Capture/Compare 3 Selection) */ +#define TIM_CCMOD2_CC3SEL_0 ((uint16_t)0x0001) /*!< Bit 0 */ +#define TIM_CCMOD2_CC3SEL_1 ((uint16_t)0x0002) /*!< Bit 1 */ + +#define TIM_CCMOD2_OC3FEN ((uint16_t)0x0004) /*!< Output Compare 3 Fast enable */ +#define TIM_CCMOD2_OC3PEN ((uint16_t)0x0008) /*!< Output Compare 3 Preload enable */ + +#define TIM_CCMOD2_OC3MD ((uint16_t)0x0070) /*!< OC3M[2:0] bits (Output Compare 3 Mode) */ +#define TIM_CCMOD2_OC3MD_0 ((uint16_t)0x0010) /*!< Bit 0 */ +#define TIM_CCMOD2_OC3MD_1 ((uint16_t)0x0020) /*!< Bit 1 */ +#define TIM_CCMOD2_OC3MD_2 ((uint16_t)0x0040) /*!< Bit 2 */ + +#define TIM_CCMOD2_OC3CEN ((uint16_t)0x0080) /*!< Output Compare 3 Clear Enable */ + +#define TIM_CCMOD2_CC4SEL ((uint16_t)0x0300) /*!< CC4S[1:0] bits (Capture/Compare 4 Selection) */ +#define TIM_CCMOD2_CC4SEL_0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define TIM_CCMOD2_CC4SEL_1 ((uint16_t)0x0200) /*!< Bit 1 */ + +#define TIM_CCMOD2_OC4FEN ((uint16_t)0x0400) /*!< Output Compare 4 Fast enable */ +#define TIM_CCMOD2_OC4PEN ((uint16_t)0x0800) /*!< Output Compare 4 Preload enable */ + +#define TIM_CCMOD2_OC4MD ((uint16_t)0x7000) /*!< OC4M[2:0] bits (Output Compare 4 Mode) */ +#define TIM_CCMOD2_OC4MD_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define TIM_CCMOD2_OC4MD_1 ((uint16_t)0x2000) /*!< Bit 1 */ +#define TIM_CCMOD2_OC4MD_2 ((uint16_t)0x4000) /*!< Bit 2 */ + +#define TIM_CCMOD2_OC4CEN ((uint16_t)0x8000) /*!< Output Compare 4 Clear Enable */ + +/*----------------------------------------------------------------------------*/ + +#define TIM_CCMOD2_IC3PSC ((uint16_t)0x000C) /*!< IC3PSC[1:0] bits (Input Capture 3 Prescaler) */ +#define TIM_CCMOD2_IC3PSC_0 ((uint16_t)0x0004) /*!< Bit 0 */ +#define TIM_CCMOD2_IC3PSC_1 ((uint16_t)0x0008) /*!< Bit 1 */ + +#define TIM_CCMOD2_IC3F ((uint16_t)0x00F0) /*!< IC3F[3:0] bits (Input Capture 3 Filter) */ +#define TIM_CCMOD2_IC3F_0 ((uint16_t)0x0010) /*!< Bit 0 */ +#define TIM_CCMOD2_IC3F_1 ((uint16_t)0x0020) /*!< Bit 1 */ +#define TIM_CCMOD2_IC3F_2 ((uint16_t)0x0040) /*!< Bit 2 */ +#define TIM_CCMOD2_IC3F_3 ((uint16_t)0x0080) /*!< Bit 3 */ + +#define TIM_CCMOD2_IC4PSC ((uint16_t)0x0C00) /*!< IC4PSC[1:0] bits (Input Capture 4 Prescaler) */ +#define TIM_CCMOD2_IC4PSC_0 ((uint16_t)0x0400) /*!< Bit 0 */ +#define TIM_CCMOD2_IC4PSC_1 ((uint16_t)0x0800) /*!< Bit 1 */ + +#define TIM_CCMOD2_IC4F ((uint16_t)0xF000) /*!< IC4F[3:0] bits (Input Capture 4 Filter) */ +#define TIM_CCMOD2_IC4F_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define TIM_CCMOD2_IC4F_1 ((uint16_t)0x2000) /*!< Bit 1 */ +#define TIM_CCMOD2_IC4F_2 ((uint16_t)0x4000) /*!< Bit 2 */ +#define TIM_CCMOD2_IC4F_3 ((uint16_t)0x8000) /*!< Bit 3 */ + +/*----------------------------------------------------------------------------*/ + +/******************* Bit definition for TIM_CCEN register *******************/ +#define TIM_CCEN_CC1EN ((uint32_t)0x00000001) /*!< Capture/Compare 1 output enable */ +#define TIM_CCEN_CC1P ((uint32_t)0x00000002) /*!< Capture/Compare 1 output Polarity */ +#define TIM_CCEN_CC1NEN ((uint32_t)0x00000004) /*!< Capture/Compare 1 Complementary output enable */ +#define TIM_CCEN_CC1NP ((uint32_t)0x00000008) /*!< Capture/Compare 1 Complementary output Polarity */ +#define TIM_CCEN_CC2EN ((uint32_t)0x00000010) /*!< Capture/Compare 2 output enable */ +#define TIM_CCEN_CC2P ((uint32_t)0x00000020) /*!< Capture/Compare 2 output Polarity */ +#define TIM_CCEN_CC2NEN ((uint32_t)0x00000040) /*!< Capture/Compare 2 Complementary output enable */ +#define TIM_CCEN_CC2NP ((uint32_t)0x00000080) /*!< Capture/Compare 2 Complementary output Polarity */ +#define TIM_CCEN_CC3EN ((uint32_t)0x00000100) /*!< Capture/Compare 3 output enable */ +#define TIM_CCEN_CC3P ((uint32_t)0x00000200) /*!< Capture/Compare 3 output Polarity */ +#define TIM_CCEN_CC3NEN ((uint32_t)0x00000400) /*!< Capture/Compare 3 Complementary output enable */ +#define TIM_CCEN_CC3NP ((uint32_t)0x00000800) /*!< Capture/Compare 3 Complementary output Polarity */ +#define TIM_CCEN_CC4EN ((uint32_t)0x00001000) /*!< Capture/Compare 4 output enable */ +#define TIM_CCEN_CC4P ((uint32_t)0x00002000) /*!< Capture/Compare 4 output Polarity */ + +/******************* Bit definition for TIM_CNT register ********************/ +#define TIM_CNT_CNT ((uint16_t)0xFFFF) /*!< Counter Value */ + +/******************* Bit definition for TIM_PSC register ********************/ +#define TIM_PSC_PSC ((uint16_t)0xFFFF) /*!< Prescaler Value */ + +/******************* Bit definition for TIM_AR register ********************/ +#define TIM_AR_AR ((uint16_t)0xFFFF) /*!< actual auto-reload Value */ + +/******************* Bit definition for TIM_REPCNT register ********************/ +#define TIM_REPCNT_REPCNT ((uint8_t)0xFF) /*!< Repetition Counter Value */ + +/******************* Bit definition for TIM_CCDAT1 register *******************/ +#define TIM_CCDAT1_CCDAT1 ((uint16_t)0xFFFF) /*!< Capture/Compare 1 Value */ + +/******************* Bit definition for TIM_CCDAT2 register *******************/ +#define TIM_CCDAT2_CCDAT2 ((uint16_t)0xFFFF) /*!< Capture/Compare 2 Value */ + +/******************* Bit definition for TIM_CCDAT3 register *******************/ +#define TIM_CCDAT3_CCDAT3 ((uint16_t)0xFFFF) /*!< Capture/Compare 3 Value */ + +/******************* Bit definition for TIM_CCDAT4 register *******************/ +#define TIM_CCDAT4_CCDAT4 ((uint16_t)0xFFFF) /*!< Capture/Compare 4 Value */ + +/******************* Bit definition for TIM_BKDT register *******************/ +#define TIM_BKDT_DTGN ((uint16_t)0x00FF) /*!< DTG[0:7] bits (Dead-Time Generator set-up) */ +#define TIM_BKDT_DTGN_0 ((uint16_t)0x0001) /*!< Bit 0 */ +#define TIM_BKDT_DTGN_1 ((uint16_t)0x0002) /*!< Bit 1 */ +#define TIM_BKDT_DTGN_2 ((uint16_t)0x0004) /*!< Bit 2 */ +#define TIM_BKDT_DTGN_3 ((uint16_t)0x0008) /*!< Bit 3 */ +#define TIM_BKDT_DTGN_4 ((uint16_t)0x0010) /*!< Bit 4 */ +#define TIM_BKDT_DTGN_5 ((uint16_t)0x0020) /*!< Bit 5 */ +#define TIM_BKDT_DTGN_6 ((uint16_t)0x0040) /*!< Bit 6 */ +#define TIM_BKDT_DTGN_7 ((uint16_t)0x0080) /*!< Bit 7 */ + +#define TIM_BKDT_LCKCFG ((uint16_t)0x0300) /*!< LOCK[1:0] bits (Lock Configuration) */ +#define TIM_BKDT_LCKCFG_0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define TIM_BKDT_LCKCFG_1 ((uint16_t)0x0200) /*!< Bit 1 */ + +#define TIM_BKDT_OSSI ((uint16_t)0x0400) /*!< Off-State Selection for Idle mode */ +#define TIM_BKDT_OSSR ((uint16_t)0x0800) /*!< Off-State Selection for Run mode */ +#define TIM_BKDT_BKEN ((uint16_t)0x1000) /*!< Break enable */ +#define TIM_BKDT_BKP ((uint16_t)0x2000) /*!< Break Polarity */ +#define TIM_BKDT_AOEN ((uint16_t)0x4000) /*!< Automatic Output enable */ +#define TIM_BKDT_MOEN ((uint16_t)0x8000) /*!< Main Output enable */ + +/******************* Bit definition for TIM_DCTRL register ********************/ +#define TIM_DCTRL_DBADDR ((uint16_t)0x001F) /*!< DBA[4:0] bits (DMA Base Address) */ +#define TIM_DCTRL_DBADDR_0 ((uint16_t)0x0001) /*!< Bit 0 */ +#define TIM_DCTRL_DBADDR_1 ((uint16_t)0x0002) /*!< Bit 1 */ +#define TIM_DCTRL_DBADDR_2 ((uint16_t)0x0004) /*!< Bit 2 */ +#define TIM_DCTRL_DBADDR_3 ((uint16_t)0x0008) /*!< Bit 3 */ +#define TIM_DCTRL_DBADDR_4 ((uint16_t)0x0010) /*!< Bit 4 */ + +#define TIM_DCTRL_DBLEN ((uint16_t)0x1F00) /*!< DBL[4:0] bits (DMA Burst Length) */ +#define TIM_DCTRL_DBLEN_0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define TIM_DCTRL_DBLEN_1 ((uint16_t)0x0200) /*!< Bit 1 */ +#define TIM_DCTRL_DBLEN_2 ((uint16_t)0x0400) /*!< Bit 2 */ +#define TIM_DCTRL_DBLEN_3 ((uint16_t)0x0800) /*!< Bit 3 */ +#define TIM_DCTRL_DBLEN_4 ((uint16_t)0x1000) /*!< Bit 4 */ + +/******************* Bit definition for TIM_DADDR register *******************/ +#define TIM_DADDR_BURST ((uint16_t)0xFFFF) /*!< DMA register for burst accesses */ + +/******************************************************************************/ +/* */ +/* Real-Time Clock (RTC) */ +/* */ +/******************************************************************************/ +/******************** Bits definition for RTC_TSH register *******************/ +#define RTC_TSH_APM ((uint32_t)0x00400000) +#define RTC_TSH_HOT ((uint32_t)0x00300000) +#define RTC_TSH_HOT_0 ((uint32_t)0x00100000) +#define RTC_TSH_HOT_1 ((uint32_t)0x00200000) +#define RTC_TSH_HOU ((uint32_t)0x000F0000) +#define RTC_TSH_HOU_0 ((uint32_t)0x00010000) +#define RTC_TSH_HOU_1 ((uint32_t)0x00020000) +#define RTC_TSH_HOU_2 ((uint32_t)0x00040000) +#define RTC_TSH_HOU_3 ((uint32_t)0x00080000) +#define RTC_TSH_MIT ((uint32_t)0x00007000) +#define RTC_TSH_MIT_0 ((uint32_t)0x00001000) +#define RTC_TSH_MIT_1 ((uint32_t)0x00002000) +#define RTC_TSH_MIT_2 ((uint32_t)0x00004000) +#define RTC_TSH_MIU ((uint32_t)0x00000F00) +#define RTC_TSH_MIU_0 ((uint32_t)0x00000100) +#define RTC_TSH_MIU_1 ((uint32_t)0x00000200) +#define RTC_TSH_MIU_2 ((uint32_t)0x00000400) +#define RTC_TSH_MIU_3 ((uint32_t)0x00000800) +#define RTC_TSH_SCT ((uint32_t)0x00000070) +#define RTC_TSH_SCT_0 ((uint32_t)0x00000010) +#define RTC_TSH_SCT_1 ((uint32_t)0x00000020) +#define RTC_TSH_SCT_2 ((uint32_t)0x00000040) +#define RTC_TSH_SCU ((uint32_t)0x0000000F) +#define RTC_TSH_SCU_0 ((uint32_t)0x00000001) +#define RTC_TSH_SCU_1 ((uint32_t)0x00000002) +#define RTC_TSH_SCU_2 ((uint32_t)0x00000004) +#define RTC_TSH_SCU_3 ((uint32_t)0x00000008) + +/******************** Bits definition for RTC_DATE register *******************/ +#define RTC_DATE_YRT ((uint32_t)0x00F00000) +#define RTC_DATE_YRT_0 ((uint32_t)0x00100000) +#define RTC_DATE_YRT_1 ((uint32_t)0x00200000) +#define RTC_DATE_YRT_2 ((uint32_t)0x00400000) +#define RTC_DATE_YRT_3 ((uint32_t)0x00800000) +#define RTC_DATE_YRU ((uint32_t)0x000F0000) +#define RTC_DATE_YRU_0 ((uint32_t)0x00010000) +#define RTC_DATE_YRU_1 ((uint32_t)0x00020000) +#define RTC_DATE_YRU_2 ((uint32_t)0x00040000) +#define RTC_DATE_YRU_3 ((uint32_t)0x00080000) +#define RTC_DATE_WDU ((uint32_t)0x0000E000) +#define RTC_DATE_WDU_0 ((uint32_t)0x00002000) +#define RTC_DATE_WDU_1 ((uint32_t)0x00004000) +#define RTC_DATE_WDU_2 ((uint32_t)0x00008000) +#define RTC_DATE_MOT ((uint32_t)0x00001000) +#define RTC_DATE_MOU ((uint32_t)0x00000F00) +#define RTC_DATE_MOU_0 ((uint32_t)0x00000100) +#define RTC_DATE_MOU_1 ((uint32_t)0x00000200) +#define RTC_DATE_MOU_2 ((uint32_t)0x00000400) +#define RTC_DATE_MOU_3 ((uint32_t)0x00000800) +#define RTC_DATE_DAT ((uint32_t)0x00000030) +#define RTC_DATE_DAT_0 ((uint32_t)0x00000010) +#define RTC_DATE_DAT_1 ((uint32_t)0x00000020) +#define RTC_DATE_DAU ((uint32_t)0x0000000F) +#define RTC_DATE_DAU_0 ((uint32_t)0x00000001) +#define RTC_DATE_DAU_1 ((uint32_t)0x00000002) +#define RTC_DATE_DAU_2 ((uint32_t)0x00000004) +#define RTC_DATE_DAU_3 ((uint32_t)0x00000008) + +/******************** Bits definition for RTC_CTRL register *******************/ +#define RTC_CTRL_BAKP ((uint32_t)0x00040000) +#define RTC_CTRL_SU1H ((uint32_t)0x00020000) +#define RTC_CTRL_AD1H ((uint32_t)0x00010000) +#define RTC_CTRL_WTIEN ((uint32_t)0x00004000) +#define RTC_CTRL_ALAIEN ((uint32_t)0x00001000) +#define RTC_CTRL_WTEN ((uint32_t)0x00000400) +#define RTC_CTRL_ALAEN ((uint32_t)0x00000100) +#define RTC_CTRL_HFMT ((uint32_t)0x00000040) +#define RTC_CTRL_BYPS ((uint32_t)0x00000020) +#define RTC_CTRL_WKUPSEL ((uint32_t)0x00000007) +#define RTC_CTRL_WKUPSEL_0 ((uint32_t)0x00000001) +#define RTC_CTRL_WKUPSEL_1 ((uint32_t)0x00000002) +#define RTC_CTRL_WKUPSEL_2 ((uint32_t)0x00000004) + +/******************** Bits definition for RTC_INITSTS register ******************/ +#define RTC_INITSTS_RECPF ((uint32_t)0x00010000) +#define RTC_INITSTS_WTF ((uint32_t)0x00000400) +#define RTC_INITSTS_ALAF ((uint32_t)0x00000100) +#define RTC_INITSTS_INITM ((uint32_t)0x00000080) +#define RTC_INITSTS_INITF ((uint32_t)0x00000040) +#define RTC_INITSTS_RSYF ((uint32_t)0x00000020) +#define RTC_INITSTS_INITSF ((uint32_t)0x00000010) +#define RTC_INITSTS_SHOPF ((uint32_t)0x00000008) +#define RTC_INITSTS_WTWF ((uint32_t)0x00000004) +#define RTC_INITSTS_ALAWF ((uint32_t)0x00000001) + +/******************** Bits definition for RTC_PRE register *****************/ +#define RTC_PRE_DIVA ((uint32_t)0x007F0000) +#define RTC_PRE_DIVS ((uint32_t)0x00007FFF) + +/******************** Bits definition for RTC_WKUPT register *****************/ +#define RTC_WKUPT_WKUPT ((uint32_t)0x0000FFFF) + +/******************** Bits definition for RTC_ALARMA register ***************/ +#define RTC_ALARMA_MASK4 ((uint32_t)0x80000000) +#define RTC_ALARMA_WKDSEL ((uint32_t)0x40000000) +#define RTC_ALARMA_DTT ((uint32_t)0x30000000) +#define RTC_ALARMA_DTT_0 ((uint32_t)0x10000000) +#define RTC_ALARMA_DTT_1 ((uint32_t)0x20000000) +#define RTC_ALARMA_DTU ((uint32_t)0x0F000000) +#define RTC_ALARMA_DTU_0 ((uint32_t)0x01000000) +#define RTC_ALARMA_DTU_1 ((uint32_t)0x02000000) +#define RTC_ALARMA_DTU_2 ((uint32_t)0x04000000) +#define RTC_ALARMA_DTU_3 ((uint32_t)0x08000000) +#define RTC_ALARMA_MASK3 ((uint32_t)0x00800000) +#define RTC_ALARMA_APM ((uint32_t)0x00400000) +#define RTC_ALARMA_HOT ((uint32_t)0x00300000) +#define RTC_ALARMA_HOT_0 ((uint32_t)0x00100000) +#define RTC_ALARMA_HOT_1 ((uint32_t)0x00200000) +#define RTC_ALARMA_HOU ((uint32_t)0x000F0000) +#define RTC_ALARMA_HOU_0 ((uint32_t)0x00010000) +#define RTC_ALARMA_HOU_1 ((uint32_t)0x00020000) +#define RTC_ALARMA_HOU_2 ((uint32_t)0x00040000) +#define RTC_ALARMA_HOU_3 ((uint32_t)0x00080000) +#define RTC_ALARMA_MASK2 ((uint32_t)0x00008000) +#define RTC_ALARMA_MIT ((uint32_t)0x00007000) +#define RTC_ALARMA_MIT_0 ((uint32_t)0x00001000) +#define RTC_ALARMA_MIT_1 ((uint32_t)0x00002000) +#define RTC_ALARMA_MIT_2 ((uint32_t)0x00004000) +#define RTC_ALARMA_MIU ((uint32_t)0x00000F00) +#define RTC_ALARMA_MIU_0 ((uint32_t)0x00000100) +#define RTC_ALARMA_MIU_1 ((uint32_t)0x00000200) +#define RTC_ALARMA_MIU_2 ((uint32_t)0x00000400) +#define RTC_ALARMA_MIU_3 ((uint32_t)0x00000800) +#define RTC_ALARMA_MASK1 ((uint32_t)0x00000080) +#define RTC_ALARMA_SET ((uint32_t)0x00000070) +#define RTC_ALARMA_SET_0 ((uint32_t)0x00000010) +#define RTC_ALARMA_SET_1 ((uint32_t)0x00000020) +#define RTC_ALARMA_SET_2 ((uint32_t)0x00000040) +#define RTC_ALARMA_SEU ((uint32_t)0x0000000F) +#define RTC_ALARMA_SEU_0 ((uint32_t)0x00000001) +#define RTC_ALARMA_SEU_1 ((uint32_t)0x00000002) +#define RTC_ALARMA_SEU_2 ((uint32_t)0x00000004) +#define RTC_ALARMA_SEU_3 ((uint32_t)0x00000008) + +/******************** Bits definition for RTC_WRP register ******************/ +#define RTC_WRP_PKEY ((uint32_t)0x000000FF) + +/******************** Bits definition for RTC_SUBS register ******************/ +#define RTC_SUBS_SS ((uint32_t)0x0000FFFF) + +/******************** Bits definition for RTC_SCTRL register ***************/ +#define RTC_SCTRL_SUBF ((uint32_t)0x00007FFF) +#define RTC_SCTRL_ADD1S ((uint32_t)0x80000000) + +/******************** Bits definition for RTC_CALIB register *****************/ +#define RTC_CALIB_CP ((uint32_t)0x00008000) +#define RTC_CALIB_CW8 ((uint32_t)0x00004000) +#define RTC_CALIB_CW16 ((uint32_t)0x00002000) +#define RTC_CALIB_CM ((uint32_t)0x000001FF) +#define RTC_CALIB_CM_0 ((uint32_t)0x00000001) +#define RTC_CALIB_CM_1 ((uint32_t)0x00000002) +#define RTC_CALIB_CM_2 ((uint32_t)0x00000004) +#define RTC_CALIB_CM_3 ((uint32_t)0x00000008) +#define RTC_CALIB_CM_4 ((uint32_t)0x00000010) +#define RTC_CALIB_CM_5 ((uint32_t)0x00000020) +#define RTC_CALIB_CM_6 ((uint32_t)0x00000040) +#define RTC_CALIB_CM_7 ((uint32_t)0x00000080) +#define RTC_CALIB_CM_8 ((uint32_t)0x00000100) + +/******************** Bits definition for RTC_ALRMASS register *************/ +#define RTC_ALRMASS_MASKSSB ((uint32_t)0x0F000000) +#define RTC_ALRMASS_MASKSSB_0 ((uint32_t)0x00000000) +#define RTC_ALRMASS_MASKSSB_1 ((uint32_t)0x01000000) +#define RTC_ALRMASS_MASKSSB_2 ((uint32_t)0x02000000) +#define RTC_ALRMASS_MASKSSB_3 ((uint32_t)0x03000000) +#define RTC_ALRMASS_MASKSSB_4 ((uint32_t)0x04000000) +#define RTC_ALRMASS_MASKSSB_5 ((uint32_t)0x05000000) +#define RTC_ALRMASS_MASKSSB_6 ((uint32_t)0x06000000) +#define RTC_ALRMASS_MASKSSB_7 ((uint32_t)0x07000000) +#define RTC_ALRMASS_MASKSSB_8 ((uint32_t)0x08000000) +#define RTC_ALRMASS_MASKSSB_9 ((uint32_t)0x09000000) +#define RTC_ALRMASS_MASKSSB_10 ((uint32_t)0x0A000000) +#define RTC_ALRMASS_MASKSSB_11 ((uint32_t)0x0B000000) +#define RTC_ALRMASS_MASKSSB_12 ((uint32_t)0x0C000000) +#define RTC_ALRMASS_MASKSSB_13 ((uint32_t)0x0D000000) +#define RTC_ALRMASS_MASKSSB_14 ((uint32_t)0x0E000000) +#define RTC_ALRMASS_MASKSSB_15 ((uint32_t)0x0F000000) +#define RTC_ALRMASS_SSV ((uint32_t)0x00007FFF) + +/******************************************************************************/ +/* */ +/* Independent WATCHDOG */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for IWDG_KEY register ********************/ +#define IWDG_KEY_KEYV ((uint16_t)0xFFFF) /*!< Key value (write only, read 0000h) */ + +/******************* Bit definition for IWDG_PREDIV register ********************/ +#define IWDG_PREDIV_PD ((uint8_t)0x07) /*!< PD[2:0] (Prescaler divider) */ +#define IWDG_PR_PR_0 ((uint8_t)0x01) /*!< Bit 0 */ +#define IWDG_PR_PR_1 ((uint8_t)0x02) /*!< Bit 1 */ +#define IWDG_PR_PR_2 ((uint8_t)0x04) /*!< Bit 2 */ + +/******************* Bit definition for IWDG_RELV register *******************/ +#define IWDG_RELV_REL ((uint16_t)0x0FFF) /*!< Watchdog counter reload value */ + +/******************* Bit definition for IWDG_STS register ********************/ +#define IWDG_STS_PVU ((uint8_t)0x01) /*!< Watchdog prescaler value update */ +#define IWDG_STS_CRVU ((uint8_t)0x02) /*!< Watchdog counter reload value update */ + +/******************************************************************************/ +/* */ +/* Window WATCHDOG */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for WWDG_CTRL register ********************/ +#define WWDG_CTRL_T ((uint8_t)0x7F) /*!< T[6:0] bits (7-Bit counter (MSB to LSB)) */ +#define WWDG_CTRL_T0 ((uint8_t)0x01) /*!< Bit 0 */ +#define WWDG_CTRL_T1 ((uint8_t)0x02) /*!< Bit 1 */ +#define WWDG_CTRL_T2 ((uint8_t)0x04) /*!< Bit 2 */ +#define WWDG_CTRL_T3 ((uint8_t)0x08) /*!< Bit 3 */ +#define WWDG_CTRL_T4 ((uint8_t)0x10) /*!< Bit 4 */ +#define WWDG_CTRL_T5 ((uint8_t)0x20) /*!< Bit 5 */ +#define WWDG_CTRL_T6 ((uint8_t)0x40) /*!< Bit 6 */ + +#define WWDG_CTRL_ACTB ((uint8_t)0x80) /*!< Activation bit */ + +/******************* Bit definition for WWDG_CFG register *******************/ +#define WWDG_CFG_W ((uint16_t)0x007F) /*!< W[6:0] bits (7-bit window value) */ +#define WWDG_CFG_W0 ((uint16_t)0x0001) /*!< Bit 0 */ +#define WWDG_CFG_W1 ((uint16_t)0x0002) /*!< Bit 1 */ +#define WWDG_CFG_W2 ((uint16_t)0x0004) /*!< Bit 2 */ +#define WWDG_CFG_W3 ((uint16_t)0x0008) /*!< Bit 3 */ +#define WWDG_CFG_W4 ((uint16_t)0x0010) /*!< Bit 4 */ +#define WWDG_CFG_W5 ((uint16_t)0x0020) /*!< Bit 5 */ +#define WWDG_CFG_W6 ((uint16_t)0x0040) /*!< Bit 6 */ + +#define WWDG_CFG_TIMERB ((uint16_t)0x0180) /*!< TIMERB[1:0] bits (Timer Base) */ +#define WWDG_CFG_TIMERB0 ((uint16_t)0x0080) /*!< Bit 0 */ +#define WWDG_CFG_TIMERB1 ((uint16_t)0x0100) /*!< Bit 1 */ + +#define WWDG_CFG_EWINT ((uint16_t)0x0200) /*!< Early Wakeup Interrupt */ + +/******************* Bit definition for WWDG_STS register ********************/ +#define WWDG_STS_EWINTF ((uint8_t)0x01) /*!< Early Wakeup Interrupt Flag */ + +/******************************************************************************/ +/* */ +/* Serial Peripheral Interface */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for SPI_CTRL1 register ********************/ +#define SPI_CTRL1_CLKPHA ((uint16_t)0x0001) /*!< Clock Phase */ +#define SPI_CTRL1_CLKPOL ((uint16_t)0x0002) /*!< Clock Polarity */ +#define SPI_CTRL1_MSEL ((uint16_t)0x0004) /*!< Master Selection */ + +#define SPI_CTRL1_BR ((uint16_t)0x0038) /*!< BR[2:0] bits (Baud Rate Control) */ +#define SPI_CTRL1_BR0 ((uint16_t)0x0008) /*!< Bit 0 */ +#define SPI_CTRL1_BR1 ((uint16_t)0x0010) /*!< Bit 1 */ +#define SPI_CTRL1_BR2 ((uint16_t)0x0020) /*!< Bit 2 */ + +#define SPI_CTRL1_SPIEN ((uint16_t)0x0040) /*!< SPI Enable */ +#define SPI_CTRL1_LSBFF ((uint16_t)0x0080) /*!< Frame Format */ +#define SPI_CTRL1_SSEL ((uint16_t)0x0100) /*!< Internal slave select */ +#define SPI_CTRL1_SSMEN ((uint16_t)0x0200) /*!< Software slave management */ +#define SPI_CTRL1_RONLY ((uint16_t)0x0400) /*!< Receive only */ +#define SPI_CTRL1_DATFF ((uint16_t)0x0800) /*!< Data Frame Format */ +#define SPI_CTRL1_CRCNEXT ((uint16_t)0x1000) /*!< Transmit CRC next */ +#define SPI_CTRL1_CRCEN ((uint16_t)0x2000) /*!< Hardware CRC calculation enable */ +#define SPI_CTRL1_BIDIROEN ((uint16_t)0x4000) /*!< Output enable in bidirectional mode */ +#define SPI_CTRL1_BIDIRMODE ((uint16_t)0x8000) /*!< Bidirectional data mode enable */ + +/******************* Bit definition for SPI_CTRL2 register ********************/ +#define SPI_CTRL2_RDMAEN ((uint8_t)0x01) /*!< Rx Buffer DMA Enable */ +#define SPI_CTRL2_TDMAEN ((uint8_t)0x02) /*!< Tx Buffer DMA Enable */ +#define SPI_CTRL2_SSOEN ((uint8_t)0x04) /*!< SS Output Enable */ +#define SPI_CTRL2_ERRINTEN ((uint8_t)0x20) /*!< Error Interrupt Enable */ +#define SPI_CTRL2_RNEINTEN ((uint8_t)0x40) /*!< RX buffer Not Empty Interrupt Enable */ +#define SPI_CTRL2_TEINTEN ((uint8_t)0x80) /*!< Tx buffer Empty Interrupt Enable */ + +/******************** Bit definition for SPI_STS register ********************/ +#define SPI_STS_RNE ((uint8_t)0x01) /*!< Receive buffer Not Empty */ +#define SPI_STS_TE ((uint8_t)0x02) /*!< Transmit buffer Empty */ +#define SPI_STS_CRCERR ((uint8_t)0x10) /*!< CRC Error flag */ +#define SPI_STS_MODERR ((uint8_t)0x20) /*!< Mode fault */ +#define SPI_STS_OVER ((uint8_t)0x40) /*!< Overrun flag */ +#define SPI_STS_BUSY ((uint8_t)0x80) /*!< Busy flag */ + +/******************** Bit definition for SPI_DAT register ********************/ +#define SPI_DAT_DAT ((uint16_t)0xFFFF) /*!< Data Register */ + + +/******************* Bit definition for SPI_CRCPOLY register ******************/ +#define SPI_CRCPOLY_CRCPOLY ((uint16_t)0xFFFF) /*!< CRC polynomial register */ + +/****************** Bit definition for SPI_CRCRDAT register ******************/ +#define SPI_CRCRDAT_CRCRDAT ((uint16_t)0xFFFF) /*!< Rx CRC Register */ + +/****************** Bit definition for SPI_CRCTDAT register ******************/ +#define SPI_CRCTDAT_CRCTDAT ((uint16_t)0xFFFF) /*!< Tx CRC Register */ + +/****************** Bit definition for SPI_I2SCFG register *****************/ +#define SPI_I2SCFG_CHBITS ((uint16_t)0x0001) /*!< Channel length (number of bits per audio channel) */ + +#define SPI_I2SCFG_TDATLEN ((uint16_t)0x0006) /*!< TDATLEN[1:0] bits (Data length to be transferred) */ +#define SPI_I2SCFG_TDATLEN0 ((uint16_t)0x0002) /*!< Bit 0 */ +#define SPI_I2SCFG_TDATLEN1 ((uint16_t)0x0004) /*!< Bit 1 */ + +#define SPI_I2SCFG_CLKPOL ((uint16_t)0x0008) /*!< steady state clock polarity */ + +#define SPI_I2SCFG_STDSEL ((uint16_t)0x0030) /*!< STDSEL[1:0] bits (I2S standard selection) */ +#define SPI_I2SCFG_STDSEL0 ((uint16_t)0x0010) /*!< Bit 0 */ +#define SPI_I2SCFG_STDSEL1 ((uint16_t)0x0020) /*!< Bit 1 */ + +#define SPI_I2SCFG_PCMFSYNC ((uint16_t)0x0080) /*!< PCM frame synchronization */ + +#define SPI_I2SCFG_MODCFG ((uint16_t)0x0300) /*!< MODCFG[1:0] bits (I2S configuration mode) */ +#define SPI_I2SCFG_MODCFG0 ((uint16_t)0x0100) /*!< Bit 0 */ +#define SPI_I2SCFG_MODCFG1 ((uint16_t)0x0200) /*!< Bit 1 */ + +#define SPI_I2SCFG_I2SEN ((uint16_t)0x0400) /*!< I2S Enable */ +#define SPI_I2SCFG_MODSEL ((uint16_t)0x0800) /*!< I2S mode selection */ + +/****************** Bit definition for SPI_I2SPREDIV register *******************/ +#define SPI_I2SPREDIV_LDIV ((uint16_t)0x00FF) /*!< I2S Linear prescaler */ +#define SPI_I2SPREDIV_ODD_EVEN ((uint16_t)0x0100) /*!< Odd factor for the prescaler */ +#define SPI_I2SPREDIV_MCLKOEN ((uint16_t)0x0200) /*!< Master Clock Output Enable */ + +/******************************************************************************/ +/* */ +/* Inter-integrated Circuit Interface */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for I2C_CTRL1 register ********************/ +#define I2C_CTRL1_EN ((uint16_t)0x0001) /*!< Peripheral Enable */ +#define I2C_CTRL1_SMBMODE ((uint16_t)0x0002) /*!< SMBus Mode */ +#define I2C_CTRL1_SMBTYPE ((uint16_t)0x0008) /*!< SMBus Type */ +#define I2C_CTRL1_ARPEN ((uint16_t)0x0010) /*!< ARP Enable */ +#define I2C_CTRL1_PECEN ((uint16_t)0x0020) /*!< PEC Enable */ +#define I2C_CTRL1_GCEN ((uint16_t)0x0040) /*!< General Call Enable */ +#define I2C_CTRL1_NOEXTEND ((uint16_t)0x0080) /*!< Clock Stretching Disable (Slave mode) */ +#define I2C_CTRL1_STARTGEN ((uint16_t)0x0100) /*!< Start Generation */ +#define I2C_CTRL1_STOPGEN ((uint16_t)0x0200) /*!< Stop Generation */ +#define I2C_CTRL1_ACKEN ((uint16_t)0x0400) /*!< Acknowledge Enable */ +#define I2C_CTRL1_ACKPOS ((uint16_t)0x0800) /*!< Acknowledge/PEC Position (for data reception) */ +#define I2C_CTRL1_PEC ((uint16_t)0x1000) /*!< Packet Error Checking */ +#define I2C_CTRL1_SMBALERT ((uint16_t)0x2000) /*!< SMBus Alert */ +#define I2C_CTRL1_SWRESET ((uint16_t)0x8000) /*!< Software Reset */ + +/******************* Bit definition for I2C_CTRL2 register ********************/ +#define I2C_CTRL2_CLKFREQ ((uint16_t)0x003F) /*!< FREQ[5:0] bits (Peripheral Clock Frequency) */ +#define I2C_CTRL2_CLKFREQ_0 ((uint16_t)0x0001) /*!< Bit 0 */ +#define I2C_CTRL2_CLKFREQ_1 ((uint16_t)0x0002) /*!< Bit 1 */ +#define I2C_CTRL2_CLKFREQ_2 ((uint16_t)0x0004) /*!< Bit 2 */ +#define I2C_CTRL2_CLKFREQ_3 ((uint16_t)0x0008) /*!< Bit 3 */ +#define I2C_CTRL2_CLKFREQ_4 ((uint16_t)0x0010) /*!< Bit 4 */ +#define I2C_CTRL2_CLKFREQ_5 ((uint16_t)0x0020) /*!< Bit 5 */ + +#define I2C_CTRL2_ERRINTEN ((uint16_t)0x0100) /*!< Error Interrupt Enable */ +#define I2C_CTRL2_EVTINTEN ((uint16_t)0x0200) /*!< Event Interrupt Enable */ +#define I2C_CTRL2_BUFINTEN ((uint16_t)0x0400) /*!< Buffer Interrupt Enable */ +#define I2C_CTRL2_DMAEN ((uint16_t)0x0800) /*!< DMA Requests Enable */ +#define I2C_CTRL2_DMALAST ((uint16_t)0x1000) /*!< DMA Last Transfer */ + +/******************* Bit definition for I2C_OADDR1 register *******************/ +#define I2C_OADDR1_ADDR1_7 ((uint16_t)0x00FE) /*!< Interface Address */ +#define I2C_OADDR1_ADDR8_9 ((uint16_t)0x0300) /*!< Interface Address */ + +#define I2C_OADDR1_ADDR0 ((uint16_t)0x0001) /*!< Bit 0 */ +#define I2C_OADDR1_ADDR1 ((uint16_t)0x0002) /*!< Bit 1 */ +#define I2C_OADDR1_ADDR2 ((uint16_t)0x0004) /*!< Bit 2 */ +#define I2C_OADDR1_ADDR3 ((uint16_t)0x0008) /*!< Bit 3 */ +#define I2C_OADDR1_ADDR4 ((uint16_t)0x0010) /*!< Bit 4 */ +#define I2C_OADDR1_ADDR5 ((uint16_t)0x0020) /*!< Bit 5 */ +#define I2C_OADDR1_ADDR6 ((uint16_t)0x0040) /*!< Bit 6 */ +#define I2C_OADDR1_ADDR7 ((uint16_t)0x0080) /*!< Bit 7 */ +#define I2C_OADDR1_ADDR8 ((uint16_t)0x0100) /*!< Bit 8 */ +#define I2C_OADDR1_ADDR9 ((uint16_t)0x0200) /*!< Bit 9 */ + +#define I2C_OADDR1_ADDRMODE ((uint16_t)0x8000) /*!< Addressing Mode (Slave mode) */ + +/******************* Bit definition for I2C_OADDR2 register *******************/ +#define I2C_OADDR2_DUALEN ((uint8_t)0x01) /*!< Dual addressing mode enable */ +#define I2C_OADDR2_ADDR2 ((uint8_t)0xFE) /*!< Interface address */ + +/******************** Bit definition for I2C_DAT register ********************/ +#define I2C_DAT_DATA ((uint8_t)0xFF) /*!< 8-bit Data Register */ + +/******************* Bit definition for I2C_STS1 register ********************/ +#define I2C_STS1_STARTBF ((uint16_t)0x0001) /*!< Start Bit (Master mode) */ +#define I2C_STS1_ADDRF ((uint16_t)0x0002) /*!< Address sent (master mode)/matched (slave mode) */ +#define I2C_STS1_BSF ((uint16_t)0x0004) /*!< Byte Transfer Finished */ +#define I2C_STS1_ADDR10F ((uint16_t)0x0008) /*!< 10-bit header sent (Master mode) */ +#define I2C_STS1_STOPF ((uint16_t)0x0010) /*!< Stop detection (Slave mode) */ +#define I2C_STS1_RXDATNE ((uint16_t)0x0040) /*!< Data Register not Empty (receivers) */ +#define I2C_STS1_TXDATE ((uint16_t)0x0080) /*!< Data Register Empty (transmitters) */ +#define I2C_STS1_BUSERR ((uint16_t)0x0100) /*!< Bus Error */ +#define I2C_STS1_ARLOST ((uint16_t)0x0200) /*!< Arbitration Lost (master mode) */ +#define I2C_STS1_ACKFAIL ((uint16_t)0x0400) /*!< Acknowledge Failure */ +#define I2C_STS1_OVERRUN ((uint16_t)0x0800) /*!< Overrun/Underrun */ +#define I2C_STS1_PECERR ((uint16_t)0x1000) /*!< PEC Error in reception */ +#define I2C_STS1_TIMOUT ((uint16_t)0x4000) /*!< Timeout or Tlow Error */ +#define I2C_STS1_SMBALERT ((uint16_t)0x8000) /*!< SMBus Alert */ + +/******************* Bit definition for I2C_STS2 register ********************/ +#define I2C_STS2_MSMODE ((uint16_t)0x0001) /*!< Master/Slave */ +#define I2C_STS2_BUSY ((uint16_t)0x0002) /*!< Bus Busy */ +#define I2C_STS2_TRF ((uint16_t)0x0004) /*!< Transmitter/Receiver */ +#define I2C_STS2_GCALLADDR ((uint16_t)0x0010) /*!< General Call Address (Slave mode) */ +#define I2C_STS2_SMBDADDR ((uint16_t)0x0020) /*!< SMBus Device Default Address (Slave mode) */ +#define I2C_STS2_SMBHADDR ((uint16_t)0x0040) /*!< SMBus Host Header (Slave mode) */ +#define I2C_STS2_DUALFLAG ((uint16_t)0x0080) /*!< Dual Flag (Slave mode) */ +#define I2C_STS2_PECVAL ((uint16_t)0xFF00) /*!< Packet Error Checking Register */ + +/******************* Bit definition for I2C_CLKCTRL register ********************/ +#define I2C_CLKCTRL_CLKCTRL ((uint16_t)0x0FFF) /*!< Clock Control Register in Fast/Standard mode (Master mode) */ +#define I2C_CLKCTRL_DUTY ((uint16_t)0x4000) /*!< Fast Mode Duty Cycle */ +#define I2C_CLKCTRL_FSMODE ((uint16_t)0x8000) /*!< I2C Master Mode Selection */ + +/****************** Bit definition for I2C_TRISE register *******************/ +#define I2C_TMRISE_TMRISE ((uint8_t)0x3F) /*!< Maximum Rise Time in Fast/Standard mode (Master mode) */ + +/******************************************************************************/ +/* */ +/* Universal Synchronous Asynchronous Receiver Transmitter */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for USART_STS register *******************/ +#define USART_STS_PEF ((uint16_t)0x0001) /*!< Parity Error */ +#define USART_STS_FEF ((uint16_t)0x0002) /*!< Framing Error */ +#define USART_STS_NEF ((uint16_t)0x0004) /*!< Noise Error Flag */ +#define USART_STS_OREF ((uint16_t)0x0008) /*!< OverRun Error */ +#define USART_STS_IDLEF ((uint16_t)0x0010) /*!< IDLE line detected */ +#define USART_STS_RXDNE ((uint16_t)0x0020) /*!< Read Data Register Not Empty */ +#define USART_STS_TXC ((uint16_t)0x0040) /*!< Transmission Complete */ +#define USART_STS_TXDE ((uint16_t)0x0080) /*!< Transmit Data Register Empty */ +#define USART_STS_LINBDF ((uint16_t)0x0100) /*!< LIN Break Detection Flag */ +#define USART_STS_CTSF ((uint16_t)0x0200) /*!< CTS Flag */ + +/******************* Bit definition for USART_DAT register *******************/ +#define USART_DAT_DATV ((uint16_t)0x01FF) /*!< Data value */ + +/****************** Bit definition for USART_BRCF register *******************/ +#define USART_BRCF_DIV_Decimal ((uint16_t)0x000F) /*!< Fraction of USARTDIV */ +#define USART_BRCF_DIV_Integer ((uint16_t)0xFFF0) /*!< Mantissa of USARTDIV */ + +/****************** Bit definition for USART_CTRL1 register *******************/ +#define USART_CTRL1_SDBRK ((uint16_t)0x0001) /*!< Send Break */ +#define USART_CTRL1_RCVWU ((uint16_t)0x0002) /*!< Receiver wakeup */ +#define USART_CTRL1_RXEN ((uint16_t)0x0004) /*!< Receiver Enable */ +#define USART_CTRL1_TXEN ((uint16_t)0x0008) /*!< Transmitter Enable */ +#define USART_CTRL1_IDLEIEN ((uint16_t)0x0010) /*!< IDLE Interrupt Enable */ +#define USART_CTRL1_RXDNEIEN ((uint16_t)0x0020) /*!< RXNE Interrupt Enable */ +#define USART_CTRL1_TXCIEN ((uint16_t)0x0040) /*!< Transmission Complete Interrupt Enable */ +#define USART_CTRL1_TXDEIEN ((uint16_t)0x0080) /*!< PE Interrupt Enable */ +#define USART_CTRL1_PEIEN ((uint16_t)0x0100) /*!< PE Interrupt Enable */ +#define USART_CTRL1_PSEL ((uint16_t)0x0200) /*!< Parity Selection */ +#define USART_CTRL1_PCEN ((uint16_t)0x0400) /*!< Parity Control Enable */ +#define USART_CTRL1_WUM ((uint16_t)0x0800) /*!< Wakeup method */ +#define USART_CTRL1_WL ((uint16_t)0x1000) /*!< Word length */ +#define USART_CTRL1_UEN ((uint16_t)0x2000) /*!< USART Enable */ + +/****************** Bit definition for USART_CTRL2 register *******************/ +#define USART_CTRL2_ADDR ((uint16_t)0x000F) /*!< Address of the USART node */ +#define USART_CTRL2_LINBDL ((uint16_t)0x0020) /*!< LIN Break Detection Length */ +#define USART_CTRL2_LINBDIEN ((uint16_t)0x0040) /*!< LIN Break Detection Interrupt Enable */ +#define USART_CTRL2_LBCLK ((uint16_t)0x0100) /*!< Last Bit Clock pulse */ +#define USART_CTRL2_CLKPHA ((uint16_t)0x0200) /*!< Clock Phase */ +#define USART_CTRL2_CLKPOL ((uint16_t)0x0400) /*!< Clock Polarity */ +#define USART_CTRL2_CLKEN ((uint16_t)0x0800) /*!< Clock Enable */ + +#define USART_CTRL2_STPB ((uint16_t)0x3000) /*!< STOP[1:0] bits (STOP bits) */ +#define USART_CTRL2_STPB_0 ((uint16_t)0x1000) /*!< Bit 0 */ +#define USART_CTRL2_STPB_1 ((uint16_t)0x2000) /*!< Bit 1 */ + +#define USART_CTRL2_LINMEN ((uint16_t)0x4000) /*!< LIN mode enable */ + +/****************** Bit definition for USART_CTRL3 register *******************/ +#define USART_CTRL3_ERRIEN ((uint16_t)0x0001) /*!< Error Interrupt Enable */ +#define USART_CTRL3_IRDAMEN ((uint16_t)0x0002) /*!< IrDA mode Enable */ +#define USART_CTRL3_IRDALP ((uint16_t)0x0004) /*!< IrDA Low-Power */ +#define USART_CTRL3_HDMEN ((uint16_t)0x0008) /*!< Half-Duplex Selection */ +#define USART_CTRL3_SCNACK ((uint16_t)0x0010) /*!< Smartcard NACK enable */ +#define USART_CTRL3_SCMEN ((uint16_t)0x0020) /*!< Smartcard mode enable */ +#define USART_CTRL3_DMARXEN ((uint16_t)0x0040) /*!< DMA Enable Receiver */ +#define USART_CTRL3_DMATXEN ((uint16_t)0x0080) /*!< DMA Enable Transmitter */ +#define USART_CTRL3_RTSEN ((uint16_t)0x0100) /*!< RTS Enable */ +#define USART_CTRL3_CTSEN ((uint16_t)0x0200) /*!< CTS Enable */ +#define USART_CTRL3_CTSIEN ((uint16_t)0x0400) /*!< CTS Interrupt Enable */ + +/****************** Bit definition for USART_GTP register ******************/ +#define USART_GTP_PSCV ((uint16_t)0x00FF) /*!< PSC[7:0] bits (Prescaler value) */ +#define USART_GTP_PSCV_0 ((uint16_t)0x0001) /*!< Bit 0 */ +#define USART_GTP_PSCV_1 ((uint16_t)0x0002) /*!< Bit 1 */ +#define USART_GTP_PSCV_2 ((uint16_t)0x0004) /*!< Bit 2 */ +#define USART_GTP_PSCV_3 ((uint16_t)0x0008) /*!< Bit 3 */ +#define USART_GTP_PSCV_4 ((uint16_t)0x0010) /*!< Bit 4 */ +#define USART_GTP_PSCV_5 ((uint16_t)0x0020) /*!< Bit 5 */ +#define USART_GTP_PSCV_6 ((uint16_t)0x0040) /*!< Bit 6 */ +#define USART_GTP_PSCV_7 ((uint16_t)0x0080) /*!< Bit 7 */ + +#define USART_GTP_GTV ((uint16_t)0xFF00) /*!< Guard time value */ + +/******************************************************************************/ +/* */ +/* Low-power Universal Asynchronous Receiver Transmitter */ +/* */ +/******************************************************************************/ + +/****************** Bit definition for LPUART_STS register ******************/ +#define LPUART_STS_PEF ((uint16_t)0x0001) /*!< Parity Check Error Flag */ +#define LPUART_STS_TXC ((uint16_t)0x0002) /*!< TX Complete Flag */ +#define LPUART_STS_FIFO_OV ((uint16_t)0x0004) /*!< FIFO Overflow Flag */ +#define LPUART_STS_FIFO_FU ((uint16_t)0x0008) /*!< FIFO Full Flag */ +#define LPUART_STS_FIFO_HF ((uint16_t)0x0010) /*!< FIFO Half Full Flag */ +#define LPUART_STS_FIFO_NE ((uint16_t)0x0020) /*!< FIFO Non-Empty Flag */ +#define LPUART_STS_CTS ((uint16_t)0x0040) /*!< Clear to Send (Hardware Flow Control) Flag */ +#define LPUART_STS_WUF ((uint16_t)0x0080) /*!< Wakeup from Stop mode Flag */ +#define LPUART_STS_NF ((uint16_t)0x0100) /*!< Noise Detected Flag */ + +/****************** Bit definition for LPUART_INTEN register ******************/ +#define LPUART_INTEN_PEIE ((uint8_t)0x01) /*!< Parity Check Error Interrupt Enable */ +#define LPUART_INTEN_TXCIE ((uint8_t)0x02) /*!< TX Complete Interrupt Enable */ +#define LPUART_INTEN_FIFO_OVIE ((uint8_t)0x04) /*!< FIFO Overflow Interrupt Enable */ +#define LPUART_INTEN_FIFO_FUIE ((uint8_t)0x08) /*!< FIFO Full Interrupt Enable*/ +#define LPUART_INTEN_FIFO_HFIE ((uint8_t)0x10) /*!< FIFO Half Full Interrupt Enable */ +#define LPUART_INTEN_FIFO_NEIE ((uint8_t)0x20) /*!< FIFO Non-Empty Interrupt Enable */ +#define LPUART_INTEN_WUFIE ((uint8_t)0x40) /*!< Wakeup Interrupt Enable */ + +/****************** Bit definition for LPUART_CTRL register ******************/ +#define LPUART_CTRL_PSEL ((uint16_t)0x0001) /*!< Odd Parity Bit Enable */ +#define LPUART_CTRL_TXEN ((uint16_t)0x0002) /*!< TX Enable */ +#define LPUART_CTRL_FLUSH ((uint16_t)0x0004) /*!< Flush Receiver FIFO Enable */ +#define LPUART_CTRL_PCDIS ((uint16_t)0x0008) /*!< Parity Control Disable */ +#define LPUART_CTRL_LOOPBACK ((uint16_t)0x0010) /*!< Loop Back Self-Test */ +#define LPUART_CTRL_DMA_TXEN ((uint16_t)0x0020) /*!< DMA TX Request Enable */ +#define LPUART_CTRL_DMA_RXEN ((uint16_t)0x0040) /*!< DMA RX Request Enable */ +#define LPUART_CTRL_WUSTP ((uint16_t)0x0080) /*!< LPUART Wakeup Enable in Stop mode */ +#define LPUART_CTRL_RTS_THSEL ((uint16_t)0x0300) /*!< RTS Threshold Selection */ +#define LPUART_CTRL_CTSEN ((uint16_t)0x0400) /*!< Hardware Flow Control TX Enable */ +#define LPUART_CTRL_RTSEN ((uint16_t)0x0800) /*!< Hardware Flow Control RX Enable */ +#define LPUART_CTRL_WUSEL ((uint16_t)0x3000) /*!< Wakeup Event Selection */ +#define LPUART_CTRL_SMPCNT ((uint16_t)0x4000) /*!< Specify the Sampling Method */ + +/****************** Bit definition for LPUART_BRCFG1 register ******************/ +#define LPUART_BRCFG1_INTEGER ((uint16_t)0xFFFF) /*!< Baud Rate Parameter Configeration Register1: Fraction */ + +/****************** Bit definition for LPUART_DAT register ******************/ +#define LPUART_DAT_DAT ((uint8_t)0xFF) /*!< Data Register */ + +/****************** Bit definition for LPUART_BRCFG2 register ******************/ +#define LPUART_BRCFG2_DECIMAL ((uint8_t)0xFF) /*!< Baud Rate Parameter Configeration Register2: Mantissa */ + +/****************** Bit definition for LPUART_WUDAT register ******************/ +#define LPUART_WUDAT_WUDAT ((uint32_t)0xFFFFFFFF) /*!< Data Register */ + +/******************************************************************************/ + +/******************************************************************************/ +/* */ +/* General Purpose and Alternate Function I/O */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for GPIO_PMODE register *******************/ +#define GPIO_PMODE0_Pos (0) +#define GPIO_PMODE0_Msk (0x3UL << GPIO_PMODE0_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE0 GPIO_PMODE0_Msk +#define GPIO_PMODE0_0 (0x0UL << GPIO_PMODE0_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE0_1 (0x1UL << GPIO_PMODE0_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE0_2 (0x2UL << GPIO_PMODE0_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE0_3 (0x3UL << GPIO_PMODE0_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE1_Pos (2) +#define GPIO_PMODE1_Msk (0x3UL << GPIO_PMODE1_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE1 GPIO_PMODE1_Msk +#define GPIO_PMODE1_0 (0x0UL << GPIO_PMODE1_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE1_1 (0x1UL << GPIO_PMODE1_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE1_2 (0x2UL << GPIO_PMODE1_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE1_3 (0x3UL << GPIO_PMODE1_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE2_Pos (4) +#define GPIO_PMODE2_Msk (0x3UL << GPIO_PMODE2_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE2 GPIO_PMODE2_Msk +#define GPIO_PMODE2_0 (0x0UL << GPIO_PMODE2_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE2_1 (0x1UL << GPIO_PMODE2_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE2_2 (0x2UL << GPIO_PMODE2_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE2_3 (0x3UL << GPIO_PMODE2_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE3_Pos (6) +#define GPIO_PMODE3_Msk (0x3UL << GPIO_PMODE3_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE3 GPIO_PMODE3_Msk +#define GPIO_PMODE3_0 (0x0UL << GPIO_PMODE3_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE3_1 (0x1UL << GPIO_PMODE3_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE3_2 (0x2UL << GPIO_PMODE3_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE3_3 (0x3UL << GPIO_PMODE3_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE4_Pos (8) +#define GPIO_PMODE4_Msk (0x3UL << GPIO_PMODE4_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE4 GPIO_PMODE4_Msk +#define GPIO_PMODE4_0 (0x0UL << GPIO_PMODE4_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE4_1 (0x1UL << GPIO_PMODE4_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE4_2 (0x2UL << GPIO_PMODE4_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE4_3 (0x3UL << GPIO_PMODE4_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE5_Pos (10) +#define GPIO_PMODE5_Msk (0x3UL << GPIO_PMODE5_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE5 GPIO_PMODE5_Msk +#define GPIO_PMODE5_0 (0x0UL << GPIO_PMODE5_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE5_1 (0x1UL << GPIO_PMODE5_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE5_2 (0x2UL << GPIO_PMODE5_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE5_3 (0x3UL << GPIO_PMODE5_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE6_Pos (12) +#define GPIO_PMODE6_Msk (0x3UL << GPIO_PMODE6_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE6 GPIO_PMODE6_Msk +#define GPIO_PMODE6_0 (0x0UL << GPIO_PMODE6_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE6_1 (0x1UL << GPIO_PMODE6_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE6_2 (0x2UL << GPIO_PMODE6_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE6_3 (0x3UL << GPIO_PMODE6_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE7_Pos (14) +#define GPIO_PMODE7_Msk (0x3UL << GPIO_PMODE7_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE7 GPIO_PMODE7_Msk +#define GPIO_PMODE7_0 (0x0UL << GPIO_PMODE7_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE7_1 (0x1UL << GPIO_PMODE7_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE7_2 (0x2UL << GPIO_PMODE7_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE7_3 (0x3UL << GPIO_PMODE7_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE8_Pos (16) +#define GPIO_PMODE8_Msk (0x3UL << GPIO_PMODE8_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE8 GPIO_PMODE8_Msk +#define GPIO_PMODE8_0 (0x0UL << GPIO_PMODE8_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE8_1 (0x1UL << GPIO_PMODE8_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE8_2 (0x2UL << GPIO_PMODE8_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE8_3 (0x3UL << GPIO_PMODE8_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE9_Pos (18) +#define GPIO_PMODE9_Msk (0x3UL << GPIO_PMODE9_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE9 GPIO_PMODE9_Msk +#define GPIO_PMODE9_0 (0x0UL << GPIO_PMODE9_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE9_1 (0x1UL << GPIO_PMODE9_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE9_2 (0x2UL << GPIO_PMODE9_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE9_3 (0x3UL << GPIO_PMODE9_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE10_Pos (20) +#define GPIO_PMODE10_Msk (0x3UL << GPIO_PMODE10_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE10 GPIO_PMODE10_Msk +#define GPIO_PMODE10_0 (0x0UL << GPIO_PMODE10_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE10_1 (0x1UL << GPIO_PMODE10_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE10_2 (0x2UL << GPIO_PMODE10_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE10_3 (0x3UL << GPIO_PMODE10_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE11_Pos (22) +#define GPIO_PMODE11_Msk (0x3UL << GPIO_PMODE11_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE11 GPIO_PMODE11_Msk +#define GPIO_PMODE11_0 (0x0UL << GPIO_PMODE11_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE11_1 (0x1UL << GPIO_PMODE11_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE11_2 (0x2UL << GPIO_PMODE11_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE11_3 (0x3UL << GPIO_PMODE11_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE12_Pos (24) +#define GPIO_PMODE12_Msk (0x3UL << GPIO_PMODE12_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE12 GPIO_PMODE12_Msk +#define GPIO_PMODE12_0 (0x0UL << GPIO_PMODE12_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE12_1 (0x1UL << GPIO_PMODE12_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE12_2 (0x2UL << GPIO_PMODE12_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE12_3 (0x3UL << GPIO_PMODE12_Pos) /*!< 0x00000003 */ + +#define GPIO_PMODE13_Pos (26) +#define GPIO_PMODE13_Msk (0x3UL << GPIO_PMODE13_Pos) /*!< 0x00000003 */ +#define GPIO_PMODE13 GPIO_PMODE13_Msk +#define GPIO_PMODE13_0 (0x0UL << GPIO_PMODE13_Pos) /*!< 0x00000000 */ +#define GPIO_PMODE13_1 (0x1UL << GPIO_PMODE13_Pos) /*!< 0x00000001 */ +#define GPIO_PMODE13_2 (0x2UL << GPIO_PMODE13_Pos) /*!< 0x00000002 */ +#define GPIO_PMODE13_3 (0x3UL << GPIO_PMODE13_Pos) /*!< 0x00000003 */ + +/****************** Bit definition for GPIO_POTYPE register *****************/ +#define GPIO_POTYPE_POT_0 (0x00000001) +#define GPIO_POTYPE_POT_1 (0x00000002) +#define GPIO_POTYPE_POT_2 (0x00000004) +#define GPIO_POTYPE_POT_3 (0x00000008) +#define GPIO_POTYPE_POT_4 (0x00000010) +#define GPIO_POTYPE_POT_5 (0x00000020) +#define GPIO_POTYPE_POT_6 (0x00000040) +#define GPIO_POTYPE_POT_7 (0x00000080) +#define GPIO_POTYPE_POT_8 (0x00000100) +#define GPIO_POTYPE_POT_9 (0x00000200) +#define GPIO_POTYPE_POT_10 (0x00000400) +#define GPIO_POTYPE_POT_11 (0x00000800) +#define GPIO_POTYPE_POT_12 (0x00001000) +#define GPIO_POTYPE_POT_13 (0x00002000) + +/******************* Bit definition for GPIO_SR register *******************/ +#define GPIO_SR_SR0 ((uint16_t)0x0001) /*!< Slew rate bit 0 */ +#define GPIO_SR_SR1 ((uint16_t)0x0002) /*!< Slew rate bit 1 */ +#define GPIO_SR_SR2 ((uint16_t)0x0004) /*!< Slew rate bit 2 */ +#define GPIO_SR_SR3 ((uint16_t)0x0008) /*!< Slew rate bit 3 */ +#define GPIO_SR_SR4 ((uint16_t)0x0010) /*!< Slew rate bit 4 */ +#define GPIO_SR_SR5 ((uint16_t)0x0020) /*!< Slew rate bit 5 */ +#define GPIO_SR_SR6 ((uint16_t)0x0040) /*!< Slew rate bit 6 */ +#define GPIO_SR_SR7 ((uint16_t)0x0080) /*!< Slew rate bit 7 */ +#define GPIO_SR_SR8 ((uint16_t)0x0100) /*!< Slew rate bit 8 */ +#define GPIO_SR_SR9 ((uint16_t)0x0200) /*!< Slew rate bit 9 */ +#define GPIO_SR_SR10 ((uint16_t)0x0400) /*!< Slew rate bit 10 */ +#define GPIO_SR_SR11 ((uint16_t)0x0800) /*!< Slew rate bit 11 */ +#define GPIO_SR_SR12 ((uint16_t)0x1000) /*!< Slew rate bit 12 */ +#define GPIO_SR_SR13 ((uint16_t)0x2000) /*!< Slew rate bit 13 */ + +/******************* Bit definition for GPIO_PUPD register ******************/ +#define GPIO_PUPD0_Pos (0) +#define GPIO_PUPD0_Msk (0x3UL << GPIO_PUPD0_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD0 GPIO_PUPD0_Msk +#define GPIO_PUPD0_0 (0x0UL << GPIO_PUPD0_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD0_1 (0x1UL << GPIO_PUPD0_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD0_2 (0x2UL << GPIO_PUPD0_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD1_Pos (2) +#define GPIO_PUPD1_Msk (0x3UL << GPIO_PUPD1_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD1 GPIO_PUPD1_Msk +#define GPIO_PUPD1_0 (0x0UL << GPIO_PUPD1_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD1_1 (0x1UL << GPIO_PUPD1_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD1_2 (0x2UL << GPIO_PUPD1_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD2_Pos (4) +#define GPIO_PUPD2_Msk (0x3UL << GPIO_PUPD2_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD2 GPIO_PUPD2_Msk +#define GPIO_PUPD2_0 (0x0UL << GPIO_PUPD2_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD2_1 (0x1UL << GPIO_PUPD2_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD2_2 (0x2UL << GPIO_PUPD2_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD3_Pos (6) +#define GPIO_PUPD3_Msk (0x3UL << GPIO_PUPD3_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD3 GPIO_PUPD3_Msk +#define GPIO_PUPD3_0 (0x0UL << GPIO_PUPD3_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD3_1 (0x1UL << GPIO_PUPD3_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD3_2 (0x2UL << GPIO_PUPD3_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD4_Pos (8) +#define GPIO_PUPD4_Msk (0x3UL << GPIO_PUPD4_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD4 GPIO_PUPD4_Msk +#define GPIO_PUPD4_0 (0x0UL << GPIO_PUPD4_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD4_1 (0x1UL << GPIO_PUPD4_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD4_2 (0x2UL << GPIO_PUPD4_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD5_Pos (10) +#define GPIO_PUPD5_Msk (0x3UL << GPIO_PUPD5_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD5 GPIO_PUPD5_Msk +#define GPIO_PUPD5_0 (0x0UL << GPIO_PUPD5_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD5_1 (0x1UL << GPIO_PUPD5_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD5_2 (0x2UL << GPIO_PUPD5_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD6_Pos (12) +#define GPIO_PUPD6_Msk (0x3UL << GPIO_PUPD6_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD6 GPIO_PUPD6_Msk +#define GPIO_PUPD6_0 (0x0UL << GPIO_PUPD6_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD6_1 (0x1UL << GPIO_PUPD6_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD6_2 (0x2UL << GPIO_PUPD6_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD7_Pos (14) +#define GPIO_PUPD7_Msk (0x3UL << GPIO_PUPD7_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD7 GPIO_PUPD7_Msk +#define GPIO_PUPD7_0 (0x0UL << GPIO_PUPD7_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD7_1 (0x1UL << GPIO_PUPD7_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD7_2 (0x2UL << GPIO_PUPD7_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD8_Pos (16) +#define GPIO_PUPD8_Msk (0x3UL << GPIO_PUPD8_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD8 GPIO_PUPD8_Msk +#define GPIO_PUPD8_0 (0x0UL << GPIO_PUPD8_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD8_1 (0x1UL << GPIO_PUPD8_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD8_2 (0x2UL << GPIO_PUPD8_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD9_Pos (18) +#define GPIO_PUPD9_Msk (0x3UL << GPIO_PUPD9_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD9 GPIO_PUPD9_Msk +#define GPIO_PUPD9_0 (0x0UL << GPIO_PUPD9_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD9_1 (0x1UL << GPIO_PUPD9_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD9_2 (0x2UL << GPIO_PUPD9_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD10_Pos (20) +#define GPIO_PUPD10_Msk (0x3UL << GPIO_PUPD10_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD10 GPIO_PUPD10_Msk +#define GPIO_PUPD10_0 (0x0UL << GPIO_PUPD10_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD10_1 (0x1UL << GPIO_PUPD10_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD10_2 (0x2UL << GPIO_PUPD10_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD11_Pos (22) +#define GPIO_PUPD11_Msk (0x3UL << GPIO_PUPD11_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD11 GPIO_PUPD11_Msk +#define GPIO_PUPD11_0 (0x0UL << GPIO_PUPD11_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD11_1 (0x1UL << GPIO_PUPD11_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD11_2 (0x2UL << GPIO_PUPD11_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD12_Pos (24) +#define GPIO_PUPD12_Msk (0x3UL << GPIO_PUPD12_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD12 GPIO_PUPD12_Msk +#define GPIO_PUPD12_0 (0x0UL << GPIO_PUPD12_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD12_1 (0x1UL << GPIO_PUPD12_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD12_2 (0x2UL << GPIO_PUPD12_Pos) /*!< 0x00000002 */ + +#define GPIO_PUPD13_Pos (26) +#define GPIO_PUPD13_Msk (0x3UL << GPIO_PUPD13_Pos) /*!< 0x00000003 */ +#define GPIO_PUPD13 GPIO_PUPD13_Msk +#define GPIO_PUPD13_0 (0x0UL << GPIO_PUPD13_Pos) /*!< 0x00000000 */ +#define GPIO_PUPD13_1 (0x1UL << GPIO_PUPD13_Pos) /*!< 0x00000001 */ +#define GPIO_PUPD13_2 (0x2UL << GPIO_PUPD13_Pos) /*!< 0x00000002 */ + +/*!<****************** Bit definition for GPIO_PID register *******************/ +#define GPIO_PID_PID0 ((uint16_t)0x0001) /*!< Port input data, bit 0 */ +#define GPIO_PID_PID1 ((uint16_t)0x0002) /*!< Port input data, bit 1 */ +#define GPIO_PID_PID2 ((uint16_t)0x0004) /*!< Port input data, bit 2 */ +#define GPIO_PID_PID3 ((uint16_t)0x0008) /*!< Port input data, bit 3 */ +#define GPIO_PID_PID4 ((uint16_t)0x0010) /*!< Port input data, bit 4 */ +#define GPIO_PID_PID5 ((uint16_t)0x0020) /*!< Port input data, bit 5 */ +#define GPIO_PID_PID6 ((uint16_t)0x0040) /*!< Port input data, bit 6 */ +#define GPIO_PID_PID7 ((uint16_t)0x0080) /*!< Port input data, bit 7 */ +#define GPIO_PID_PID8 ((uint16_t)0x0100) /*!< Port input data, bit 8 */ +#define GPIO_PID_PID9 ((uint16_t)0x0200) /*!< Port input data, bit 9 */ +#define GPIO_PID_PID10 ((uint16_t)0x0400) /*!< Port input data, bit 10 */ +#define GPIO_PID_PID11 ((uint16_t)0x0800) /*!< Port input data, bit 11 */ +#define GPIO_PID_PID12 ((uint16_t)0x1000) /*!< Port input data, bit 12 */ +#define GPIO_PID_PID13 ((uint16_t)0x2000) /*!< Port input data, bit 13 */ + +/******************* Bit definition for GPIO_POD register *******************/ +#define GPIO_POD_POD0 ((uint16_t)0x0001) /*!< Port output data, bit 0 */ +#define GPIO_POD_POD1 ((uint16_t)0x0002) /*!< Port output data, bit 1 */ +#define GPIO_POD_POD2 ((uint16_t)0x0004) /*!< Port output data, bit 2 */ +#define GPIO_POD_POD3 ((uint16_t)0x0008) /*!< Port output data, bit 3 */ +#define GPIO_POD_POD4 ((uint16_t)0x0010) /*!< Port output data, bit 4 */ +#define GPIO_POD_POD5 ((uint16_t)0x0020) /*!< Port output data, bit 5 */ +#define GPIO_POD_POD6 ((uint16_t)0x0040) /*!< Port output data, bit 6 */ +#define GPIO_POD_POD7 ((uint16_t)0x0080) /*!< Port output data, bit 7 */ +#define GPIO_POD_POD8 ((uint16_t)0x0100) /*!< Port output data, bit 8 */ +#define GPIO_POD_POD9 ((uint16_t)0x0200) /*!< Port output data, bit 9 */ +#define GPIO_POD_POD10 ((uint16_t)0x0400) /*!< Port output data, bit 10 */ +#define GPIO_POD_POD11 ((uint16_t)0x0800) /*!< Port output data, bit 11 */ +#define GPIO_POD_POD12 ((uint16_t)0x1000) /*!< Port output data, bit 12 */ +#define GPIO_POD_POD13 ((uint16_t)0x2000) /*!< Port output data, bit 13 */ + +/****************** Bit definition for GPIO_PBSC register *******************/ +#define GPIO_PBSC_PBS0 ((uint32_t)0x00000001) /*!< Port x Set bit 0 */ +#define GPIO_PBSC_PBS1 ((uint32_t)0x00000002) /*!< Port x Set bit 1 */ +#define GPIO_PBSC_PBS2 ((uint32_t)0x00000004) /*!< Port x Set bit 2 */ +#define GPIO_PBSC_PBS3 ((uint32_t)0x00000008) /*!< Port x Set bit 3 */ +#define GPIO_PBSC_PBS4 ((uint32_t)0x00000010) /*!< Port x Set bit 4 */ +#define GPIO_PBSC_PBS5 ((uint32_t)0x00000020) /*!< Port x Set bit 5 */ +#define GPIO_PBSC_PBS6 ((uint32_t)0x00000040) /*!< Port x Set bit 6 */ +#define GPIO_PBSC_PBS7 ((uint32_t)0x00000080) /*!< Port x Set bit 7 */ +#define GPIO_PBSC_PBS8 ((uint32_t)0x00000100) /*!< Port x Set bit 8 */ +#define GPIO_PBSC_PBS9 ((uint32_t)0x00000200) /*!< Port x Set bit 9 */ +#define GPIO_PBSC_PBS10 ((uint32_t)0x00000400) /*!< Port x Set bit 10 */ +#define GPIO_PBSC_PBS11 ((uint32_t)0x00000800) /*!< Port x Set bit 11 */ +#define GPIO_PBSC_PBS12 ((uint32_t)0x00001000) /*!< Port x Set bit 12 */ +#define GPIO_PBSC_PBS13 ((uint32_t)0x00002000) /*!< Port x Set bit 13 */ + +#define GPIO_PBSC_PBC0 ((uint32_t)0x00010000) /*!< Port x Reset bit 0 */ +#define GPIO_PBSC_PBC1 ((uint32_t)0x00020000) /*!< Port x Reset bit 1 */ +#define GPIO_PBSC_PBC2 ((uint32_t)0x00040000) /*!< Port x Reset bit 2 */ +#define GPIO_PBSC_PBC3 ((uint32_t)0x00080000) /*!< Port x Reset bit 3 */ +#define GPIO_PBSC_PBC4 ((uint32_t)0x00100000) /*!< Port x Reset bit 4 */ +#define GPIO_PBSC_PBC5 ((uint32_t)0x00200000) /*!< Port x Reset bit 5 */ +#define GPIO_PBSC_PBC6 ((uint32_t)0x00400000) /*!< Port x Reset bit 6 */ +#define GPIO_PBSC_PBC7 ((uint32_t)0x00800000) /*!< Port x Reset bit 7 */ +#define GPIO_PBSC_PBC8 ((uint32_t)0x01000000) /*!< Port x Reset bit 8 */ +#define GPIO_PBSC_PBC9 ((uint32_t)0x02000000) /*!< Port x Reset bit 9 */ +#define GPIO_PBSC_PBC10 ((uint32_t)0x04000000) /*!< Port x Reset bit 10 */ +#define GPIO_PBSC_PBC11 ((uint32_t)0x08000000) /*!< Port x Reset bit 11 */ +#define GPIO_PBSC_PBC12 ((uint32_t)0x10000000) /*!< Port x Reset bit 12 */ +#define GPIO_PBSC_PBC13 ((uint32_t)0x20000000) /*!< Port x Reset bit 13 */ + +/****************** Bit definition for GPIO_PLOCK register *******************/ +#define GPIO_PLOCK_PLOCK0 ((uint32_t)0x00000001) /*!< Port x Lock bit 0 */ +#define GPIO_PLOCK_PLOCK1 ((uint32_t)0x00000002) /*!< Port x Lock bit 1 */ +#define GPIO_PLOCK_PLOCK2 ((uint32_t)0x00000004) /*!< Port x Lock bit 2 */ +#define GPIO_PLOCK_PLOCK3 ((uint32_t)0x00000008) /*!< Port x Lock bit 3 */ +#define GPIO_PLOCK_PLOCK4 ((uint32_t)0x00000010) /*!< Port x Lock bit 4 */ +#define GPIO_PLOCK_PLOCK5 ((uint32_t)0x00000020) /*!< Port x Lock bit 5 */ +#define GPIO_PLOCK_PLOCK6 ((uint32_t)0x00000040) /*!< Port x Lock bit 6 */ +#define GPIO_PLOCK_PLOCK7 ((uint32_t)0x00000080) /*!< Port x Lock bit 7 */ +#define GPIO_PLOCK_PLOCK8 ((uint32_t)0x00000100) /*!< Port x Lock bit 8 */ +#define GPIO_PLOCK_PLOCK9 ((uint32_t)0x00000200) /*!< Port x Lock bit 9 */ +#define GPIO_PLOCK_PLOCK10 ((uint32_t)0x00000400) /*!< Port x Lock bit 10 */ +#define GPIO_PLOCK_PLOCK11 ((uint32_t)0x00000800) /*!< Port x Lock bit 11 */ +#define GPIO_PLOCK_PLOCK12 ((uint32_t)0x00001000) /*!< Port x Lock bit 12 */ +#define GPIO_PLOCK_PLOCK13 ((uint32_t)0x00002000) /*!< Port x Lock bit 13 */ +#define GPIO_PLOCK_PLOCKK ((uint32_t)0x00010000) /*!< Lock key */ + +/****************** Bit definition for GPIO_AFL register *******************/ +#define GPIO_AFL_AFSEL0 ((uint32_t)0x0000000F) /*!< Port x AFL bit (0..3) */ +#define GPIO_AFL_AFSEL1 ((uint32_t)0x000000F0) /*!< Port x AFL bit (4..7) */ +#define GPIO_AFL_AFSEL2 ((uint32_t)0x00000F00) /*!< Port x AFL bit (8..11) */ +#define GPIO_AFL_AFSEL3 ((uint32_t)0x0000F000) /*!< Port x AFL bit (12..15) */ +#define GPIO_AFL_AFSEL4 ((uint32_t)0x000F0000) /*!< Port x AFL bit (16..19) */ +#define GPIO_AFL_AFSEL5 ((uint32_t)0x00F00000) /*!< Port x AFL bit (20..23) */ +#define GPIO_AFL_AFSEL6 ((uint32_t)0x0F000000) /*!< Port x AFL bit (24..27) */ +#define GPIO_AFL_AFSEL7 ((uint32_t)0xF0000000) /*!< Port x AFL bit (27..31) */ + +/****************** Bit definition for GPIO_AFH register *******************/ +#define GPIO_AFH_AFSEL8 ((uint32_t)0x0000000F) /*!< Port x AFH bit (0..3) */ +#define GPIO_AFH_AFSEL9 ((uint32_t)0x000000F0) /*!< Port x AFH bit (4..7) */ +#define GPIO_AFH_AFSEL10 ((uint32_t)0x00000F00) /*!< Port x AFH bit (8..11) */ +#define GPIO_AFH_AFSEL11 ((uint32_t)0x0000F000) /*!< Port x AFH bit (12..15) */ +#define GPIO_AFH_AFSEL12 ((uint32_t)0x000F0000) /*!< Port x AFH bit (16..19) */ +#define GPIO_AFH_AFSEL13 ((uint32_t)0x00F00000) /*!< Port x AFH bit (20..23) */ + +/******************* Bit definition for GPIO_PBC register *******************/ +#define GPIO_PBC_PBC0 ((uint16_t)0x0001) /*!< Port x Reset bit 0 */ +#define GPIO_PBC_PBC1 ((uint16_t)0x0002) /*!< Port x Reset bit 1 */ +#define GPIO_PBC_PBC2 ((uint16_t)0x0004) /*!< Port x Reset bit 2 */ +#define GPIO_PBC_PBC3 ((uint16_t)0x0008) /*!< Port x Reset bit 3 */ +#define GPIO_PBC_PBC4 ((uint16_t)0x0010) /*!< Port x Reset bit 4 */ +#define GPIO_PBC_PBC5 ((uint16_t)0x0020) /*!< Port x Reset bit 5 */ +#define GPIO_PBC_PBC6 ((uint16_t)0x0040) /*!< Port x Reset bit 6 */ +#define GPIO_PBC_PBC7 ((uint16_t)0x0080) /*!< Port x Reset bit 7 */ +#define GPIO_PBC_PBC8 ((uint16_t)0x0100) /*!< Port x Reset bit 8 */ +#define GPIO_PBC_PBC9 ((uint16_t)0x0200) /*!< Port x Reset bit 9 */ +#define GPIO_PBC_PBC10 ((uint16_t)0x0400) /*!< Port x Reset bit 10 */ +#define GPIO_PBC_PBC11 ((uint16_t)0x0800) /*!< Port x Reset bit 11 */ +#define GPIO_PBC_PBC12 ((uint16_t)0x1000) /*!< Port x Reset bit 12 */ +#define GPIO_PBC_PBC13 ((uint16_t)0x2000) /*!< Port x Reset bit 13 */ + +/******************* Bit definition for GPIO_DS register ******************/ +#define GPIO_DS_DS0 ((uint16_t)0x0001) /*!< Port x driver strength bit 0 */ +#define GPIO_DS_DS1 ((uint16_t)0x0002) /*!< Port x driver strength bit 1 */ +#define GPIO_DS_DS2 ((uint16_t)0x0004) /*!< Port x driver strength bit 2 */ +#define GPIO_DS_DS3 ((uint16_t)0x0008) /*!< Port x driver strength bit 3 */ +#define GPIO_DS_DS4 ((uint16_t)0x0010) /*!< Port x driver strength bit 4 */ +#define GPIO_DS_DS5 ((uint16_t)0x0020) /*!< Port x driver strength bit 5 */ +#define GPIO_DS_DS6 ((uint16_t)0x0040) /*!< Port x driver strength bit 6 */ +#define GPIO_DS_DS7 ((uint16_t)0x0080) /*!< Port x driver strength bit 7 */ +#define GPIO_DS_DS8 ((uint16_t)0x0100) /*!< Port x driver strength bit 8 */ +#define GPIO_DS_DS9 ((uint16_t)0x0200) /*!< Port x driver strength bit 9 */ +#define GPIO_DS_DS10 ((uint16_t)0x0400) /*!< Port x driver strength bit 10 */ +#define GPIO_DS_DS11 ((uint16_t)0x0800) /*!< Port x driver strength bit 11 */ +#define GPIO_DS_DS12 ((uint16_t)0x1000) /*!< Port x driver strength bit 12 */ +#define GPIO_DS_DS13 ((uint16_t)0x2000) /*!< Port x driver strength bit 13 */ + +/*----------------------------------------------------------------------------*/ + +/***************** Bit definition for AFIO_CFG register *****************/ +#define AFIO_CFG_SPI2_NSS ((uint32_t)0x00000800) /*!< AFIO_CFG bit 11 */ +#define AFIO_CFG_SPI1_NSS ((uint32_t)0x00000400) /*!< AFIO_CFG bit 10 */ +#define AFIO_CFG_EXTI_ETRI ((uint32_t)0x00000070) /*!< AFIO_CFG bit (6-4) */ +#define AFIO_CFG_EXTI_ETRR ((uint32_t)0x00000007) /*!< AFIO_CFG bit (2-0) */ + +/***************** Bit definition for AFIO_EXTI_CFG1 register *****************/ +#define AFIO_EXTI_CFG1_EXTI0 ((uint16_t)0x0003) /*!< EXTI 0 configuration */ +#define AFIO_EXTI_CFG1_EXTI1 ((uint16_t)0x0030) /*!< EXTI 1 configuration */ +#define AFIO_EXTI_CFG1_EXTI2 ((uint16_t)0x0300) /*!< EXTI 2 configuration */ +#define AFIO_EXTI_CFG1_EXTI3 ((uint16_t)0x3000) /*!< EXTI 3 configuration */ + +/*!< EXTI0 configuration */ +#define AFIO_EXTI_CFG1_EXTI0_PA ((uint16_t)0x0000) /*!< PA[0] pin */ +#define AFIO_EXTI_CFG1_EXTI0_PB ((uint16_t)0x0001) /*!< PB[0] pin */ + +/*!< EXTI1 configuration */ +#define AFIO_EXTI_CFG1_EXTI1_PA ((uint16_t)0x0000) /*!< PA[1] pin */ +#define AFIO_EXTI_CFG1_EXTI1_PB ((uint16_t)0x0010) /*!< PB[1] pin */ + +/*!< EXTI2 configuration */ +#define AFIO_EXTI_CFG1_EXTI2_PA ((uint16_t)0x0000) /*!< PA[2] pin */ +#define AFIO_EXTI_CFG1_EXTI2_PB ((uint16_t)0x0100) /*!< PB[2] pin */ + +/*!< EXTI3 configuration */ +#define AFIO_EXTI_CFG1_EXTI3_PA ((uint16_t)0x0000) /*!< PA[3] pin */ +#define AFIO_EXTI_CFG1_EXTI3_PB ((uint16_t)0x1000) /*!< PB[3] pin */ + +/***************** Bit definition for AFIO_EXTI_CFG2 register *****************/ +#define AFIO_EXTI_CFG2_EXTI4 ((uint16_t)0x0003) /*!< EXTI 4 configuration */ +#define AFIO_EXTI_CFG2_EXTI5 ((uint16_t)0x0030) /*!< EXTI 5 configuration */ +#define AFIO_EXTI_CFG2_EXTI6 ((uint16_t)0x0300) /*!< EXTI 6 configuration */ +#define AFIO_EXTI_CFG2_EXTI7 ((uint16_t)0x3000) /*!< EXTI 7 configuration */ + +/*!< EXTI4 configuration */ +#define AFIO_EXTI_CFG2_EXTI4_PA ((uint16_t)0x0000) /*!< PA[4] pin */ +#define AFIO_EXTI_CFG2_EXTI4_PB ((uint16_t)0x0001) /*!< PB[4] pin */ + +/*!< EXTI5 configuration */ +#define AFIO_EXTI_CFG2_EXTI5_PA ((uint16_t)0x0000) /*!< PA[5] pin */ +#define AFIO_EXTI_CFG2_EXTI5_PB ((uint16_t)0x0010) /*!< PB[5] pin */ + +/*!< EXTI6 configuration */ +#define AFIO_EXTI_CFG2_EXTI6_PA ((uint16_t)0x0000) /*!< PA[6] pin */ +#define AFIO_EXTI_CFG2_EXTI6_PB ((uint16_t)0x0100) /*!< PB[6] pin */ + +/*!< EXTI7 configuration */ +#define AFIO_EXTI_CFG2_EXTI7_PA ((uint16_t)0x0000) /*!< PA[7] pin */ +#define AFIO_EXTI_CFG2_EXTI7_PB ((uint16_t)0x1000) /*!< PB[7] pin */ + +/******************************************************************************/ +/* */ +/* External Interrupt/Event Controller */ +/* */ +/******************************************************************************/ + +/******************* Bit definition for EXTI_IMR register *******************/ +#define EXTI_IMASK_IMASK0 ((uint32_t)0x00000001) /*!< Interrupt Mask on line 0 */ +#define EXTI_IMASK_IMASK1 ((uint32_t)0x00000002) /*!< Interrupt Mask on line 1 */ +#define EXTI_IMASK_IMASK2 ((uint32_t)0x00000004) /*!< Interrupt Mask on line 2 */ +#define EXTI_IMASK_IMASK3 ((uint32_t)0x00000008) /*!< Interrupt Mask on line 3 */ +#define EXTI_IMASK_IMASK4 ((uint32_t)0x00000010) /*!< Interrupt Mask on line 4 */ +#define EXTI_IMASK_IMASK5 ((uint32_t)0x00000020) /*!< Interrupt Mask on line 5 */ +#define EXTI_IMASK_IMASK6 ((uint32_t)0x00000040) /*!< Interrupt Mask on line 6 */ +#define EXTI_IMASK_IMASK7 ((uint32_t)0x00000080) /*!< Interrupt Mask on line 7 */ +#define EXTI_IMASK_IMASK8 ((uint32_t)0x00000100) /*!< Interrupt Mask on line 8 */ +#define EXTI_IMASK_IMASK9 ((uint32_t)0x00000200) /*!< Interrupt Mask on line 9 */ +#define EXTI_IMASK_IMASK10 ((uint32_t)0x00000400) /*!< Interrupt Mask on line 10 */ +#define EXTI_IMASK_IMASK11 ((uint32_t)0x00000800) /*!< Interrupt Mask on line 11 */ +#define EXTI_IMASK_IMASK12 ((uint32_t)0x00001000) /*!< Interrupt Mask on line 12 */ + +/******************* Bit definition for EXTI_EMR register *******************/ +#define EXTI_EMASK_EMASK0 ((uint32_t)0x00000001) /*!< Event Mask on line 0 */ +#define EXTI_EMASK_EMASK1 ((uint32_t)0x00000002) /*!< Event Mask on line 1 */ +#define EXTI_EMASK_EMASK2 ((uint32_t)0x00000004) /*!< Event Mask on line 2 */ +#define EXTI_EMASK_EMASK3 ((uint32_t)0x00000008) /*!< Event Mask on line 3 */ +#define EXTI_EMASK_EMASK4 ((uint32_t)0x00000010) /*!< Event Mask on line 4 */ +#define EXTI_EMASK_EMASK5 ((uint32_t)0x00000020) /*!< Event Mask on line 5 */ +#define EXTI_EMASK_EMASK6 ((uint32_t)0x00000040) /*!< Event Mask on line 6 */ +#define EXTI_EMASK_EMASK7 ((uint32_t)0x00000080) /*!< Event Mask on line 7 */ +#define EXTI_EMASK_EMASK8 ((uint32_t)0x00000100) /*!< Event Mask on line 8 */ +#define EXTI_EMASK_EMASK9 ((uint32_t)0x00000200) /*!< Event Mask on line 9 */ +#define EXTI_EMASK_EMASK10 ((uint32_t)0x00000400) /*!< Event Mask on line 10 */ +#define EXTI_EMASK_EMASK11 ((uint32_t)0x00000800) /*!< Event Mask on line 11 */ +#define EXTI_EMASK_EMASK12 ((uint32_t)0x00001000) /*!< Event Mask on line 12 */ + +/****************** Bit definition for EXTI_RT_CFG register *******************/ +#define EXTI_EMASK_RT_CFG_RT_CFG0 ((uint32_t)0x00000001) /*!< Rising trigger event configuration bit of line 0 */ +#define EXTI_EMASK_RT_CFG_RT_CFG1 ((uint32_t)0x00000002) /*!< Rising trigger event configuration bit of line 1 */ +#define EXTI_EMASK_RT_CFG_RT_CFG2 ((uint32_t)0x00000004) /*!< Rising trigger event configuration bit of line 2 */ +#define EXTI_EMASK_RT_CFG_RT_CFG3 ((uint32_t)0x00000008) /*!< Rising trigger event configuration bit of line 3 */ +#define EXTI_EMASK_RT_CFG_RT_CFG4 ((uint32_t)0x00000010) /*!< Rising trigger event configuration bit of line 4 */ +#define EXTI_EMASK_RT_CFG_RT_CFG5 ((uint32_t)0x00000020) /*!< Rising trigger event configuration bit of line 5 */ +#define EXTI_EMASK_RT_CFG_RT_CFG6 ((uint32_t)0x00000040) /*!< Rising trigger event configuration bit of line 6 */ +#define EXTI_EMASK_RT_CFG_RT_CFG7 ((uint32_t)0x00000080) /*!< Rising trigger event configuration bit of line 7 */ +#define EXTI_EMASK_RT_CFG_RT_CFG8 ((uint32_t)0x00000100) /*!< Rising trigger event configuration bit of line 8 */ +#define EXTI_EMASK_RT_CFG_RT_CFG9 ((uint32_t)0x00000200) /*!< Rising trigger event configuration bit of line 9 */ +#define EXTI_EMASK_RT_CFG_RT_CFG10 ((uint32_t)0x00000400) /*!< Rising trigger event configuration bit of line 10 */ +#define EXTI_EMASK_RT_CFG_RT_CFG11 ((uint32_t)0x00000800) /*!< Rising trigger event configuration bit of line 11 */ +#define EXTI_EMASK_RT_CFG_RT_CFG12 ((uint32_t)0x00001000) /*!< Rising trigger event configuration bit of line 12 */ + +/****************** Bit definition for EXTI_FT_CFG register *******************/ +#define EXTI_EMASK_FT_CFG_FT_CFG0 ((uint32_t)0x00000001) /*!< Falling trigger event configuration bit of line 0 */ +#define EXTI_EMASK_FT_CFG_FT_CFG1 ((uint32_t)0x00000002) /*!< Falling trigger event configuration bit of line 1 */ +#define EXTI_EMASK_FT_CFG_FT_CFG2 ((uint32_t)0x00000004) /*!< Falling trigger event configuration bit of line 2 */ +#define EXTI_EMASK_FT_CFG_FT_CFG3 ((uint32_t)0x00000008) /*!< Falling trigger event configuration bit of line 3 */ +#define EXTI_EMASK_FT_CFG_FT_CFG4 ((uint32_t)0x00000010) /*!< Falling trigger event configuration bit of line 4 */ +#define EXTI_EMASK_FT_CFG_FT_CFG5 ((uint32_t)0x00000020) /*!< Falling trigger event configuration bit of line 5 */ +#define EXTI_EMASK_FT_CFG_FT_CFG6 ((uint32_t)0x00000040) /*!< Falling trigger event configuration bit of line 6 */ +#define EXTI_EMASK_FT_CFG_FT_CFG7 ((uint32_t)0x00000080) /*!< Falling trigger event configuration bit of line 7 */ +#define EXTI_EMASK_FT_CFG_FT_CFG8 ((uint32_t)0x00000100) /*!< Falling trigger event configuration bit of line 8 */ +#define EXTI_EMASK_FT_CFG_FT_CFG9 ((uint32_t)0x00000200) /*!< Falling trigger event configuration bit of line 9 */ +#define EXTI_EMASK_FT_CFG_FT_CFG10 ((uint32_t)0x00000400) /*!< Falling trigger event configuration bit of line 10 */ +#define EXTI_EMASK_FT_CFG_FT_CFG11 ((uint32_t)0x00000800) /*!< Falling trigger event configuration bit of line 11 */ +#define EXTI_EMASK_FT_CFG_FT_CFG12 ((uint32_t)0x00001000) /*!< Falling trigger event configuration bit of line 12 */ + +/****************** Bit definition for EXTI_SWIE register ******************/ +#define EXTI_SWIE_SWIE0 ((uint32_t)0x00000001) /*!< Software Interrupt on line 0 */ +#define EXTI_SWIE_SWIE1 ((uint32_t)0x00000002) /*!< Software Interrupt on line 1 */ +#define EXTI_SWIE_SWIE2 ((uint32_t)0x00000004) /*!< Software Interrupt on line 2 */ +#define EXTI_SWIE_SWIE3 ((uint32_t)0x00000008) /*!< Software Interrupt on line 3 */ +#define EXTI_SWIE_SWIE4 ((uint32_t)0x00000010) /*!< Software Interrupt on line 4 */ +#define EXTI_SWIE_SWIE5 ((uint32_t)0x00000020) /*!< Software Interrupt on line 5 */ +#define EXTI_SWIE_SWIE6 ((uint32_t)0x00000040) /*!< Software Interrupt on line 6 */ +#define EXTI_SWIE_SWIE7 ((uint32_t)0x00000080) /*!< Software Interrupt on line 7 */ +#define EXTI_SWIE_SWIE8 ((uint32_t)0x00000100) /*!< Software Interrupt on line 8 */ +#define EXTI_SWIE_SWIE9 ((uint32_t)0x00000200) /*!< Software Interrupt on line 9 */ +#define EXTI_SWIE_SWIE10 ((uint32_t)0x00000400) /*!< Software Interrupt on line 10 */ +#define EXTI_SWIE_SWIE11 ((uint32_t)0x00000800) /*!< Software Interrupt on line 11 */ +#define EXTI_SWIE_SWIE12 ((uint32_t)0x00001000) /*!< Software Interrupt on line 12 */ + +/******************* Bit definition for EXTI_PEND register ********************/ +#define EXTI_PEND_PEND0 ((uint32_t)0x00000001) /*!< Pending bit for line 0 */ +#define EXTI_PEND_PEND1 ((uint32_t)0x00000002) /*!< Pending bit for line 1 */ +#define EXTI_PEND_PEND2 ((uint32_t)0x00000004) /*!< Pending bit for line 2 */ +#define EXTI_PEND_PEND3 ((uint32_t)0x00000008) /*!< Pending bit for line 3 */ +#define EXTI_PEND_PEND4 ((uint32_t)0x00000010) /*!< Pending bit for line 4 */ +#define EXTI_PEND_PEND5 ((uint32_t)0x00000020) /*!< Pending bit for line 5 */ +#define EXTI_PEND_PEND6 ((uint32_t)0x00000040) /*!< Pending bit for line 6 */ +#define EXTI_PEND_PEND7 ((uint32_t)0x00000080) /*!< Pending bit for line 7 */ +#define EXTI_PEND_PEND8 ((uint32_t)0x00000100) /*!< Pending bit for line 8 */ +#define EXTI_PEND_PEND9 ((uint32_t)0x00000200) /*!< Pending bit for line 9 */ +#define EXTI_PEND_PEND10 ((uint32_t)0x00000400) /*!< Pending bit for line 10 */ +#define EXTI_PEND_PEND11 ((uint32_t)0x00000800) /*!< Pending bit for line 11 */ +#define EXTI_PEND_PEND12 ((uint32_t)0x00001000) /*!< Pending bit for line 12 */ + +/*********************** Common macro fuction define *******************/ + +#define SET_BIT(REG, BIT) ((REG) |= (BIT)) + +#define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) + +#define READ_BIT(REG, BIT) ((REG) & (BIT)) + +#define CLEAR_REG(REG) ((REG) = (0x0)) + +#define WRITE_REG(REG, VAL) ((REG) = (VAL)) + +#define READ_REG(REG) ((REG)) + +#define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) + + +/*********************** Trim data struct *******************/ +typedef struct{ + uint32_t stote_bg_vtrim_value; + uint32_t stote_rc28800_trim_value; + uint32_t stote_rc32000_trim_value; + uint32_t stote_rc32768_trim_value; + uint32_t stote_rc64m_trim_value; + uint32_t stote_rc96m_trim_value; + uint32_t rc_adc_ts_25c; + uint32_t rc_gpadc_value_3400mv; + uint32_t rc_gpadc_value_600mv; + uint8_t flash_uuid[16]; +}trim_stored_t; +extern trim_stored_t* SystemTrimValueGet(void); +extern uint8_t* SystemGetUUID(void); +extern uint8_t* SystemGetMacAddr(void); +/** + * @} + */ + +#ifdef USE_STDPERIPH_DRIVER +#include "n32wb03x_conf.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/n32wb03x_conf.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/n32wb03x_conf.h new file mode 100644 index 0000000..2f4aebc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/n32wb03x_conf.h @@ -0,0 +1,100 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_conf.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_CONF_H__ +#define __N32WB03X_CONF_H__ + +/* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */ + +#include "n32wb03x_adc.h" +#include "n32wb03x_crc.h" +#include "n32wb03x_dma.h" +#include "n32wb03x_exti.h" +#include "n32wb03x_gpio.h" +#include "n32wb03x_i2c.h" +#include "n32wb03x_iwdg.h" +#include "n32wb03x_pwr.h" +#include "n32wb03x_rcc.h" +#include "n32wb03x_rtc.h" +#include "n32wb03x_spi.h" +#include "n32wb03x_tim.h" +#include "n32wb03x_usart.h" +#include "n32wb03x_lpuart.h" +#include "n32wb03x_wwdg.h" +#include "n32wb03x_irgen.h" +#include "n32wb03x_keyscan.h" +#include "n32wb03x_qflash.h" +#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ + +/* Uncomment the line below to expanse the "assert_param" macro in the + Standard Peripheral Library drivers code */ +/* #define USE_FULL_ASSERT 1 */ + +#ifdef USE_FULL_ASSERT + +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr If expr is false, it calls assert_failed function which reports + * the name of the source file and the source line number of the call + * that failed. If expr is true, it returns no value. + */ +#define assert_param(expr) ((expr) ? (void)0 : assert_failed((const uint8_t*)#expr, (const uint8_t*)__FILE__, __LINE__)) + +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line); +#else +#define assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT */ + +#endif /* __N32WB03X_CONF_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/startup/startup_n32wb03x.s b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/startup/startup_n32wb03x.s new file mode 100644 index 0000000..36e7ced --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/startup/startup_n32wb03x.s @@ -0,0 +1,251 @@ +; **************************************************************************** +; Copyright (c) 2025, NSING Technologies Inc. +; +; 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 disclaimer below. +; +; NSING' name may not be used to endorse or promote products derived from +; this software without specific prior written permission. +; +; DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NSING "AS IS" AND ANY EXPRESS OR +; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE +; DISCLAIMED. IN NO EVENT SHALL NSING 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. +; **************************************************************************** + +; Amount of memory (in bytes) allocated for Stack +; Tailor this value to your application needs +; Stack Configuration +; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + +Stack_Size EQU 0x00000800 + + AREA STACK, NOINIT, READWRITE, ALIGN=3 +Stack_Mem SPACE Stack_Size +__initial_sp + +; Heap Configuration +; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + +Heap_Size EQU 0x00000200 + + AREA HEAP, NOINIT, READWRITE, ALIGN=3 +__heap_base +Heap_Mem SPACE Heap_Size +__heap_limit + + PRESERVE8 + THUMB + + +; Vector Table Mapped to Address 0 at Reset + AREA RESET, DATA, READONLY + EXPORT __Vectors + EXPORT __Vectors_End + EXPORT __Vectors_Size + +__Vectors DCD __initial_sp ; Top of Stack + DCD Reset_Handler ; Reset Handler + DCD NMI_Handler ; NMI Handler + DCD HardFault_Handler ; Hard Fault Handler + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD SVC_Handler ; SVCall Handler + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD PendSV_Handler ; PendSV Handler + DCD SysTick_Handler ; SysTick Handler + + ; External Interrupts + DCD WWDG_IRQHandler ; Window Watchdog + DCD BLE_SW_IRQHandler ; BLE_SW interrupt + DCD RTC_IRQHandler ; RTC interrupt(through EXTI line 17/19/20 interrupt) + DCD BLE_HSLOT_IRQHandler ; BLE_HSLOT + DCD FLASH_IRQHandler ; Flash + DCD RCC_IRQHandler ; RCC + DCD EXTI0_1_IRQHandler ; EXTI Line 0.1 + DCD EXTI2_3_IRQHandler ; EXTI Line 2.3 + DCD EXTI4_12_IRQHandler ; EXTI Line 4..12 + DCD BLE_FINETGT_IRQHandler ; BLE_FINETGT + DCD BLE_FIFO_IRQHandler ; BLE_FIFO + DCD DMA_Channel1_2_3_4_IRQHandler ; DMA Channel 1,2,3,4 + DCD DMA_Channel5_IRQHandler ; DMA Channel 5,6,7,8 + DCD TIM1_BRK_UP_TRG_COM_IRQHandler ; TIM1 Break/Update/Trigger and Commutation + DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare + DCD RESERVED_IRQHandler ; + DCD TIM3_IRQHandler ; TIM3 + DCD BLE_ERROR_IRQHandler ; BLE_ERROR + DCD BLE_CRYPT_IRQHandler ; BLE_CYPT_IRQHandler + DCD BLE_TIMESTAMP_TGT1_IRQHandler ; BLE_TIMESTAMP_TGT1 + DCD TIM6_IRQHandler ; TIM6 + DCD ADC_IRQHandler ; ADC + DCD SPI2_IRQHandler ; SPI2 + DCD I2C1_IRQHandler ; I2C1 + DCD BLE_TIMESTAMP_TGT2_IRQHandler ; BLE_TIMESTAMP_TGT12 + DCD SPI1_IRQHandler ; SPI1 + DCD BLE_SLP_IRQHandler ; BLE_SLP + DCD KEYSCAN_IRQHandler ; KEYSCAN + DCD USART1_IRQHandler ; USART1 + DCD LPUART1_IRQHandler ; LPUART1 + DCD USART2_IRQHandler ; USART2 + DCD IRC_IRQHandler ; IRC +__Vectors_End + +__Vectors_Size EQU __Vectors_End - __Vectors + + AREA |.text|, CODE, READONLY + +; Reset handler +Reset_Handler PROC + EXPORT Reset_Handler [WEAK] + IMPORT __main + IMPORT SystemInit + LDR R0, =SystemInit + BLX R0 + LDR R0, =__main + BX R0 + ENDP + +; Dummy Exception Handlers (infinite loops which can be modified) + +NMI_Handler PROC + EXPORT NMI_Handler [WEAK] + B . + ENDP +HardFault_Handler\ + PROC + EXPORT HardFault_Handler [WEAK] + B . + ENDP +SVC_Handler PROC + EXPORT SVC_Handler [WEAK] + B . + ENDP +PendSV_Handler PROC + EXPORT PendSV_Handler [WEAK] + B . + ENDP +SysTick_Handler PROC + EXPORT SysTick_Handler [WEAK] + B . + ENDP + +Default_Handler PROC + + EXPORT WWDG_IRQHandler [WEAK] + EXPORT BLE_SW_IRQHandler [WEAK] + EXPORT RTC_IRQHandler [WEAK] + EXPORT BLE_HSLOT_IRQHandler [WEAK] + EXPORT FLASH_IRQHandler [WEAK] + EXPORT RCC_IRQHandler [WEAK] + EXPORT EXTI0_1_IRQHandler [WEAK] + EXPORT EXTI2_3_IRQHandler [WEAK] + EXPORT EXTI4_12_IRQHandler [WEAK] + EXPORT BLE_FINETGT_IRQHandler [WEAK] + EXPORT BLE_FIFO_IRQHandler [WEAK] + EXPORT DMA_Channel1_2_3_4_IRQHandler [WEAK] + EXPORT DMA_Channel5_IRQHandler [WEAK] + EXPORT TIM1_BRK_UP_TRG_COM_IRQHandler [WEAK] + EXPORT TIM1_CC_IRQHandler [WEAK] + EXPORT RESERVED_IRQHandler [WEAK] + EXPORT TIM3_IRQHandler [WEAK] + EXPORT BLE_ERROR_IRQHandler [WEAK] + EXPORT BLE_CRYPT_IRQHandler [WEAK] + EXPORT BLE_TIMESTAMP_TGT1_IRQHandler [WEAK] + EXPORT TIM6_IRQHandler [WEAK] + EXPORT ADC_IRQHandler [WEAK] + EXPORT SPI2_IRQHandler [WEAK] + EXPORT I2C1_IRQHandler [WEAK] + EXPORT BLE_TIMESTAMP_TGT2_IRQHandler [WEAK] + EXPORT SPI1_IRQHandler [WEAK] + EXPORT BLE_SLP_IRQHandler [WEAK] + EXPORT KEYSCAN_IRQHandler [WEAK] + EXPORT USART1_IRQHandler [WEAK] + EXPORT LPUART1_IRQHandler [WEAK] + EXPORT USART2_IRQHandler [WEAK] + EXPORT IRC_IRQHandler [WEAK] + +WWDG_IRQHandler +BLE_SW_IRQHandler +RTC_IRQHandler +BLE_HSLOT_IRQHandler +FLASH_IRQHandler +RCC_IRQHandler +EXTI0_1_IRQHandler +EXTI2_3_IRQHandler +EXTI4_12_IRQHandler +BLE_FINETGT_IRQHandler +BLE_FIFO_IRQHandler +DMA_Channel1_2_3_4_IRQHandler +DMA_Channel5_IRQHandler +TIM1_BRK_UP_TRG_COM_IRQHandler +TIM1_CC_IRQHandler +RESERVED_IRQHandler +TIM3_IRQHandler +BLE_ERROR_IRQHandler +BLE_CRYPT_IRQHandler +BLE_TIMESTAMP_TGT1_IRQHandler +TIM6_IRQHandler +ADC_IRQHandler +SPI2_IRQHandler +I2C1_IRQHandler +BLE_TIMESTAMP_TGT2_IRQHandler +SPI1_IRQHandler +BLE_SLP_IRQHandler +KEYSCAN_IRQHandler +USART1_IRQHandler +LPUART1_IRQHandler +USART2_IRQHandler +IRC_IRQHandler + B . + + ENDP + + ALIGN + +;******************************************************************************* +; User Stack and Heap initialization +;******************************************************************************* + IF :DEF:__MICROLIB + + EXPORT __initial_sp + EXPORT __heap_base + EXPORT __heap_limit + + ELSE + + IMPORT __use_two_region_memory + EXPORT __user_initial_stackheap + +__user_initial_stackheap + + LDR R0, = Heap_Mem + LDR R1, =(Stack_Mem + Stack_Size) + LDR R2, = (Heap_Mem + Heap_Size) + LDR R3, = Stack_Mem + BX LR + + ALIGN + + ENDIF + + END diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/system_n32wb03x.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/system_n32wb03x.c new file mode 100644 index 0000000..a35acdb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/system_n32wb03x.c @@ -0,0 +1,520 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file system_n32wb03x.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "string.h" +/* Uncomment the line corresponding to the desired System clock (SYSCLK) + frequency (after reset the HSI is used as SYSCLK source) + + IMPORTANT NOTE: + ============== + 1. After each device reset the HSI is used as System clock source. + + 2. Please make sure that the selected System clock doesn't exceed your + device's maximum frequency. + + 3. If none of the define below is enabled, the HSI is used as System clock + source. + + 4. The System clock configuration functions provided within this file assume + that: + - HSI is configer as 64M and used to driverd the system clock. + - External 32MHz crystal use for Bluetooth RF system only. + - If Bluetooth stack is enable, we should select the LSI or LSE when configer + the Bluetooth stack only. +*/ + +#define SYSCLK_USE_HSI 1 +#define SYSCLK_USE_HSE 0 + +#ifndef SYSCLK_FREQ +#define SYSCLK_FREQ HSI_VALUE +#endif + +/* +* SYSCLK_SRC * +** SYSCLK_USE_HSI ** +** SYSCLK_USE_HSE ** +*/ +#ifndef SYSCLK_SRC +#define SYSCLK_SRC SYSCLK_USE_HSI +#endif + +/************ start: add new otp read func ************/ +//Read function +#define TRIM_READ_CMD_CODE_LEN 0x140 +#define TRIM_READ_CMD_CODE_CRC 0x3aa0 +typedef uint32_t (*trim_read_cmd_func_t)(uint32_t,uint8_t*,uint32_t); +const unsigned char TRIM_READ_CMD_CODE[] ={ +0x40,0xba,0x70,0x47,0xc0,0xba,0x70,0x47,0x01,0x38,0xfd,0xd1,0x70,0x47,0x00,0x00, +0xf7,0xb5,0x03,0x25,0xad,0x06,0x28,0x6a,0x82,0xb0,0x16,0x46,0x0c,0x46,0x40,0x08, +0x40,0x00,0x28,0x62,0x28,0x6a,0x02,0x21,0x08,0x43,0x28,0x62,0x28,0x6a,0x80,0x07, +0xfc,0xd4,0x66,0x20,0x68,0x60,0x01,0x27,0x2f,0x61,0xa8,0x6a,0xc0,0x05,0xfc,0xd5, +0x99,0x20,0x68,0x60,0x2f,0x61,0xa8,0x6a,0xc0,0x05,0xfc,0xd5,0xff,0x20,0x91,0x30, +0xff,0xf7,0xda,0xff,0xff,0x23,0x01,0x33,0xab,0x62,0x68,0x46,0xef,0x60,0x35,0x21, +0x69,0x60,0x2f,0x61,0xa9,0x6a,0xc9,0x05,0xfc,0xd5,0xab,0x62,0xa9,0x69,0xef,0x60, +0xc9,0xb2,0x05,0x22,0x6a,0x60,0x2f,0x61,0xaa,0x6a,0xd2,0x05,0xfc,0xd5,0xab,0x62, +0xaa,0x69,0x09,0x02,0xd2,0xb2,0x11,0x43,0x01,0x80,0xc8,0x07,0x02,0xd0,0x03,0x20, +0x05,0xb0,0xf0,0xbd,0xab,0x62,0x68,0x69,0xff,0x21,0x08,0x31,0x88,0x43,0x68,0x61, +0x68,0x69,0xc9,0x1e,0x08,0x43,0x68,0x61,0x02,0x98,0x00,0x02,0x48,0x30,0x68,0x60, +0x08,0x20,0xa8,0x60,0xee,0x60,0x2f,0x61,0xa8,0x6a,0xc0,0x05,0xfc,0xd5,0xff,0x20, +0x01,0x30,0xa8,0x62,0x00,0x23,0xf6,0x1c,0xb0,0x08,0x0e,0xd0,0xb2,0x08,0x11,0x48, +0x00,0x68,0x99,0x00,0x60,0x54,0x06,0x0a,0x09,0x19,0x4e,0x70,0x06,0x0c,0x00,0x0e, +0x8e,0x70,0x5b,0x1c,0xc8,0x70,0x9a,0x42,0xf1,0xd8,0xff,0x20,0x01,0x30,0xa8,0x62, +0x68,0x69,0xff,0x21,0x08,0x31,0x88,0x43,0x68,0x61,0x68,0x69,0x38,0x43,0x68,0x61, +0x28,0x6a,0x80,0x08,0x80,0x00,0x28,0x62,0x28,0x6a,0x38,0x43,0x28,0x62,0x00,0x20, +0x05,0xb0,0xf0,0xbd,0x80,0x00,0x00,0x0c,0x03,0x20,0x80,0x06,0x41,0x69,0xff,0x22, +0x08,0x32,0x91,0x43,0x41,0x61,0x42,0x69,0x01,0x21,0x0a,0x43,0x42,0x61,0x02,0x6a, +0x92,0x08,0x92,0x00,0x02,0x62,0x02,0x6a,0x0a,0x43,0x02,0x62,0x70,0x47,0x00,0x00, +}; + +//Read ID function +typedef uint32_t (*rd_id_cmd_func_t)(void); +const unsigned char CMD_RDID[] ={ + 0x00, 0x20, 0x03, 0x21, 0x89, 0x06, 0x09, 0x6A, 0x49, 0x08, 0x49, 0x00, 0x03, 0x22, 0x92, 0x06, + 0x11, 0x62, 0x11, 0x46, 0x09, 0x6A, 0x02, 0x22, 0x11, 0x43, 0x03, 0x22, 0x92, 0x06, 0x11, 0x62, + 0x00, 0xBF, 0x03, 0x21, 0x89, 0x06, 0x09, 0x6A, 0x02, 0x22, 0x11, 0x40, 0x02, 0x29, 0xF8, 0xD0, + 0xD1, 0x01, 0x03, 0x22, 0x92, 0x06, 0x91, 0x62, 0x03, 0x21, 0xD1, 0x60, 0x9F, 0x21, 0x51, 0x60, + 0x01, 0x21, 0x11, 0x61, 0x00, 0xBF, 0x03, 0x21, 0x89, 0x06, 0x89, 0x6A, 0xFF, 0x22, 0x01, 0x32, + 0x11, 0x40, 0x91, 0x42, 0xF7, 0xD1, 0x03, 0x22, 0x92, 0x06, 0x91, 0x62, 0x11, 0x46, 0x88, 0x69, + 0x49, 0x69, 0xFF, 0x22, 0x08, 0x32, 0x91, 0x43, 0x03, 0x22, 0x92, 0x06, 0x51, 0x61, 0x11, 0x46, + 0x49, 0x69, 0x01, 0x22, 0x11, 0x43, 0x03, 0x22, 0x92, 0x06, 0x51, 0x61, 0x11, 0x46, 0x09, 0x6A, + 0x89, 0x08, 0x89, 0x00, 0x11, 0x62, 0x11, 0x46, 0x09, 0x6A, 0x01, 0x22, 0x11, 0x43, 0x03, 0x22, + 0x92, 0x06, 0x11, 0x62, 0x70, 0x47, 0x00, 0x00 +}; +static uint32_t read_flash_ID(void) +{ + uint32_t ramcode[TRIM_READ_CMD_CODE_LEN/4 +1 ]; + rd_id_cmd_func_t rd_id_cmd_func = NULL; + uint32_t id = 0; + uint32_t Status = __get_PRIMASK(); + memset(ramcode,0,sizeof(ramcode)); + rd_id_cmd_func = (rd_id_cmd_func_t)((uint8_t*)&ramcode[0]+1); + memcpy((void*)ramcode,(const void*)CMD_RDID,sizeof(CMD_RDID)); + __set_PRIMASK(1); + id = rd_id_cmd_func(); + __set_PRIMASK(Status); + return id; +} + +/** + * @brief Read mutable length OTP data to ram. + * @param[in] address OTP address. + * @param[out] p_data data to read. + * @param[in] byte_length data len. + * @return none. + */ +uint32_t OTPTrim_Read(uint32_t address, uint8_t* p_data, uint32_t byte_length) +{ + uint32_t otp_addr = 0; + uint32_t error=FlashAddressInvalid; + uint32_t ramcode[TRIM_READ_CMD_CODE_LEN/4 +1 ]; + uint32_t id = 0; + trim_read_cmd_func_t trim_read_cmd_func = NULL; + uint32_t Status = __get_PRIMASK(); + memset(ramcode,0,sizeof(ramcode)); + id = read_flash_ID(); + if(id == 0x001340c4)//N32WB031KEQ7-1 + { + if(address == 0x1000) otp_addr = 0x0; + else if(address == 0x2000) otp_addr = 0x100; + else if(address == 0x3000) otp_addr = 0x200; + else return error; //no valid otp address; + }else if(id == 0x00136085){//N32WB031KEQ6-1///N32WB031KEQ6-2 + if(address == 0x1000) otp_addr = 0x1000; + else if(address == 0x2000) otp_addr = 0x2000; + else if(address == 0x3000) otp_addr = 0x3000; + else return error; //no valid otp address; + + }else{ + return error; //no valid flash detect; + } + trim_read_cmd_func = (trim_read_cmd_func_t)((uint8_t*)&ramcode[0] + 0x11); + memcpy((void*)ramcode,(const void*)TRIM_READ_CMD_CODE,TRIM_READ_CMD_CODE_LEN); + __set_PRIMASK(1); + error = (*trim_read_cmd_func)(otp_addr, p_data, byte_length); + assert_param(error == FlashOperationSuccess); + __set_PRIMASK(Status); + return error; +} +/************ end ************/ + +#define TRIM_STORE_ADDR 0x1000 +trim_stored_t trim_stored; + +/******************************************************************************* + * Clock Definitions + *******************************************************************************/ +uint32_t SystemCoreClock = SYSCLK_FREQ; /*!< System Clock Frequency (Core Clock) */ +static void RCC_HsiCalib(uint32_t systemfreq); +bool system_authentication(const uint32_t* info, uint32_t len); +void SystemTrimValueRead(uint8_t* p_data,uint32_t byte_length) +{ + OTPTrim_Read(TRIM_STORE_ADDR, p_data, byte_length); +} + +trim_stored_t* SystemTrimValueGet(void) +{ + //read the trim value if not in RAM yet + if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) + { + SystemTrimValueRead((uint8_t*)&trim_stored,sizeof(trim_stored)); + } + //check again if read trim value sucessful + if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) + { + return NULL; + }else{ + return &trim_stored; + } +} + +uint8_t* SystemGetUUID(void) +{ + //read the trim value if not in RAM yet + if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) + { + SystemTrimValueRead((uint8_t*)&trim_stored,sizeof(trim_stored)); + } + //check again if read trim value sucessful + if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) + { + return NULL; + }else{ + return trim_stored.flash_uuid; + } + +} + +uint8_t* SystemGetMacAddr(void) +{ + //read the trim value if not in RAM yet + if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) + { + SystemTrimValueRead((uint8_t*)&trim_stored,sizeof(trim_stored)); + } + //check again if read trim value sucessful + if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) + { + return NULL; + }else{ + return &trim_stored.flash_uuid[5]; + } + +} + + +/** + * @brief Setup the microcontroller system + * Initialize the Embedded Flash Interface, the PLL and update the + * SystemCoreClock variable. + * @note This function should be used only after reset. + */ +void SystemInit(void) +{ + uint32_t tmp; + RCC->APB1PCLKEN |= RCC_APB1_PERIPH_PWR; // PWR enable + PWR->VTOR_REG = 0x81000000; //set irq vtor to flash address + + *(uint32_t*)0x40007014 = 0x0000080F; + *(uint32_t*)0x40007020 = 0x00020018; + *(uint32_t*)0x40011000 &= ~0xC000; + + SystemTrimValueRead((uint8_t*)&trim_stored,sizeof(trim_stored)); + /* check otp has been write */ + if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) + { + RCC->CFG |= RCC_CFG_HSISRC_DIV1; // USE HSI as system clock + RCC->CFG &= ~RCC_CFG_APB1PRES; + RCC->CFG |= RCC_HCLK_DIV2; //APB1 = HCLK/2, APB1 max is 32M + /* Calib from HSE */ + RCC_HsiCalib(SYSCLK_FREQ); + } + else + { + tmp = (PWR->reserved4)&(~0X1F); + tmp |= (trim_stored.stote_bg_vtrim_value)&0X1F; + PWR->reserved4 = tmp; + if(SYSCLK_FREQ == 64000000) + { + RCC->CTRL &= ~0x8000;// Set HSI as 64M + /* Configures LSI trim */ + tmp = RCC->CTRL & ~(0x7F << 8); // TRIM 8-14 bit + RCC->CTRL = tmp|(trim_stored.stote_rc64m_trim_value << 8);// clear and set TRIM value + + RCC->CFG |= RCC_CFG_HSISRC_DIV1; // USE HSI as system clock + + RCC->CFG &= ~RCC_CFG_APB1PRES; + RCC->CFG |= RCC_HCLK_DIV2; //APB1 = HCLK/2, APB1 max is 32M + } +// else if(SYSCLK_FREQ == 96000000) +// { +// RCC->CTRL |= 0x8000; // Set HSI as 96M +// /* Configures LSI trim */ +// tmp = RCC->CTRL & ~(0x7F << 8); // TRIM 8-14 bit +// RCC->CTRL = tmp|(trim_stored.stote_rc96m_trim_value << 8);// clear and set TRIM value +// +// RCC->CFG |= RCC_CFG_HSISRC_DIV1; // USE HSI as system clock +// tmp = RCC->CFG & ~RCC_CFG_APB1PRES; +// RCC->CFG |= RCC_HCLK_DIV4; //APB1 = HCLK/4, APB1 max is 32M +// +// tmp = RCC->CFG & ~RCC_CFG_APB2PRES; +// RCC->CFG |= RCC_HCLK_DIV4<<3; //APB2 = HCLK/2, APB1 max is 64M +// } + /* Configures LSI trim */ + RCC->LSCTRL &= ~RCC_LSCTRL_LSTTRIM; + RCC->LSCTRL |= trim_stored.stote_rc32768_trim_value << 8; + } + #if (ENABLE_FIRMWARE_AUTH) + /* user info just for demo, please change it in your project. */ + const uint32_t user_info[16] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, + 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}; + if(system_authentication(user_info, 16) == false) + { + //illegal firmware, stay here + while(1) + { + RCC_HsiCalib(SYSCLK_FREQ); + } + } + #endif + +} + +/** + * @brief Update SystemCoreClock variable according to Clock Register Values. + * The SystemCoreClock variable contains the core clock (HCLK), it can + * be used by the user application to setup the SysTick timer or + * configure other parameters. + * + * @note Each time the core clock (HCLK) changes, this function must be called + * to update SystemCoreClock variable value. Otherwise, any + * configuration based on this variable will be incorrect. + * + * @note - The system frequency computed by this function is not the real + * frequency in the chip. It is calculated based on the predefined + * constant and the selected clock source: + */ +void SystemCoreClockUpdate(void) +{ + SystemCoreClock = HSI_VALUE; +} + +/** + * @brief dealy cycles. + */ +__ASM void system_delay_cycles(uint32_t i) +{ + SUBS r0, #1 + BNE system_delay_cycles + BX LR +} + +/** + * @brief Dealy 10 us + */ +void system_delay_n_10us(uint32_t value) +{ + system_delay_cycles(107*value); +} + +/** + * @brief Enable the HSI and calibration it. + */ +static void RCC_HsiCalib(uint32_t systemfreq) +{ + uint32_t g_hsi_accuracy = 0; + uint32_t g_timeoutcnt = 1000; + uint32_t g_cal_hsi_cnt_value = 1024; + + uint32_t delta =0; + uint32_t min = 0; + uint32_t max = 127; //32M TRIM 8-14 bit + uint32_t mid = 64; + uint16_t count_value = 0; + uint32_t hsi_timeoutcnt = 0; + uint8_t tmp_trim; + uint8_t min_delta_trim =0; + uint16_t min_delta = 1024; + uint32_t tmp =0; + + if(systemfreq<=64000000) + { + RCC->CTRL &= ~0x8000; + } + else + { + RCC->CTRL |= 0x8000; + } + + g_cal_hsi_cnt_value = systemfreq /1000/1000*32; + + + do{ + tmp = RCC->CTRL & ~(0x7F << 8); //32M TRIM 8-14 bit + RCC->CTRL = tmp| (mid << 8); // clear and set TRIM value //and start to cnt + system_delay_cycles(5); // delay scape + while(1) + { + system_delay_cycles(1); + if((RCC->OSCFCSR & 0x02)) + { + break; + } + if(hsi_timeoutcnt++ > g_timeoutcnt) + { + break; + } + } + count_value = RCC->OSCFCHSICNT; //ready cnt value + if(count_value > g_cal_hsi_cnt_value) + { + delta = count_value - g_cal_hsi_cnt_value; + } + else + { + delta = g_cal_hsi_cnt_value - count_value; + } + + if(delta < min_delta) + { + min_delta_trim = mid; + min_delta = delta; + } + + if(count_value >= g_cal_hsi_cnt_value) + { + max = mid; + } + else + { + min = mid; + } + + tmp_trim = (min + max)/2; + if(tmp_trim == mid ) //0 and 127 if not used + { + break; + } + mid = tmp_trim; + }while(delta > g_hsi_accuracy); + + tmp = RCC->CTRL & ~(0x7F << 8); //32M TRIM 8-14 bit + RCC->CTRL = tmp| (min_delta_trim << 8); // clear and set TRIM value //and start to cnt + + RCC->CFG &= ~1; + while((RCC->CFG & (1<<2))); +} + +#if (ENABLE_FIRMWARE_AUTH) +/** + * @brief firmware authentication function. It will wite the authentication data + * in flash when first power on, and then authenticate firmware each power on. + * User can put it in other logic code to authenticate the firmware. + * @param[in] info: data pointer of manufacture string. + * @param[in] len : length of manufacture string . + * @return result of encrypt or verify, true for pass, false for fail. + */ +bool system_authentication(const uint32_t* info, uint32_t len) +{ + /* AUTH_ADDRESS just for demo, production should seltect another address and + write the Tag data on production line. */ + #ifdef BLE_OTA_ENABLE + #define AUTH_ADDRESS (0x01001FF0) + #else + const static uint32_t AUTH_ADDRESS[1] = {0xffffffff}; + #endif + uint32_t index = 0; + uint32_t crc_result = 0; + volatile uint32_t crc_read = 0; + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_CRC, ENABLE); + CRC32_ResetCrc(); + for (index = 0; index < len; index++) + { + CRC->CRC32DAT = info[index]; + } + /* get trim value */ + trim_stored_t *p_trim = SystemTrimValueGet(); + if(p_trim != 0) + { + for (index = 0; index < 16; index++) + { + CRC->CRC32DAT = p_trim->flash_uuid[index]; + } + } + + crc_result = CRC->CRC32DAT; + Qflash_Init(); + Qflash_Read((uint32_t)AUTH_ADDRESS,(uint8_t*)&crc_read,4); + if(crc_read == 0xffffffff) + { + /* We suggest write the Tag data when flashing firmware or produciton testing. */ + // Wirte the Tag when first run + Qflash_Write((uint32_t)AUTH_ADDRESS,(uint8_t*)&crc_result,4); + Qflash_Read( (uint32_t)AUTH_ADDRESS,(uint8_t*)&crc_read,4); + } + + if(crc_read != crc_result){ + return false; + } + return true; +} +#endif +/** + * @} + */ + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/system_n32wb03x.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/system_n32wb03x.h new file mode 100644 index 0000000..2816a4e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/CMSIS/device/system_n32wb03x.h @@ -0,0 +1,80 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file system_n32wb03x.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __SYSTEM_N32WB03X_H__ +#define __SYSTEM_N32WB03X_H__ + +#include +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup N32WB03X_System + * @{ + */ + +extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ + +extern void SystemInit(void); +extern void SystemCoreClockUpdate(void); +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /*__SYSTEM_N32WB03X_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/misc.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/misc.h new file mode 100644 index 0000000..3aa6720 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/misc.h @@ -0,0 +1,168 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file misc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MISC_H__ +#define __MISC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup MISC + * @{ + */ + +/** @addtogroup MISC_Exported_Types + * @{ + */ + +/** + * @brief NVIC Init Structure definition + */ + +typedef struct +{ + IRQn_Type NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled. + This parameter can be a value of @ref IRQn_Type + (For the complete N32WB03X Devices IRQ Channels list, please + refer to n32wb03x.h file) */ + + uint8_t NVIC_IRQChannelPriority; /*!< Specifies the priority for the IRQ channel + specified in NVIC_IRQChannel. This parameter can be a value + between 0 and 3 */ + + FunctionalState NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel + will be enabled or disabled. + This parameter can be set either to ENABLE or DISABLE */ +} NVIC_InitType; + +/** + * @} + */ + +/** @addtogroup MISC_Exported_Constants + * @{ + */ + +/** + * @} + */ + +/** @addtogroup Preemption_Priority_Group + * @{ + */ + +#define IS_NVIC_PRIORITY(PRIORITY) ((PRIORITY) < 0x04) + +#define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x000FFFFF) + +/** + * @} + */ + +/** @addtogroup SysTick_clock_source + * @{ + */ + +#define SysTick_CLKSource_HCLK_Div8 ((uint32_t)0xFFFFFFFB) +#define SysTick_CLKSource_HCLK ((uint32_t)0x00000004) +#define IS_SYSTICK_CLK_SOURCE(SOURCE) \ + (((SOURCE) == SysTick_CLKSource_HCLK) || ((SOURCE) == SysTick_CLKSource_HCLK_Div8)) +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup MISC_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup MISC_Exported_Functions + * @{ + */ + +void NVIC_Init(NVIC_InitType* NVIC_InitStruct); +void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource); + +#ifdef __cplusplus +} +#endif + +#endif /* __MISC_H__ */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_adc.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_adc.h new file mode 100644 index 0000000..c18bddc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_adc.h @@ -0,0 +1,318 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_adc.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_ADC_H__ +#define __N32WB03X_ADC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" +#include + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup ADC + * @{ + */ + +/** @addtogroup ADC_Exported_Types + * @{ + */ + +/** + * @brief ADC Init structure definition + */ +typedef struct +{ + + FunctionalState MicbiasEn; /*!< MIC BIAS enable control signal + This parameter can be set to ENABLE or DISABLE */ + + FunctionalState AudiopgaInitEn; /*!< Audio PGA off-chip capacitorfast charge control + This parameter can be set to ENABLE or DISABLE. */ + + FunctionalState PgaEn; /*!< Audio PGA Enable + This parameter can be set to ENABLE or DISABLE. */ + + uint32_t Micbias; /*!< MIC BIAS output voltage range setting, step=0.1V + This parameter must range from 1.6 to 2.3 */ + + uint32_t AudiopgaPeak; /*!< Audio PGA drive signal amplitude setting. */ + + uint32_t AudiopgaDrive; /*!< Audio PGA drive current setting */ + + uint32_t PgaGain; /*!< Audio PGA gain configuration (0??42dB) */ + +} ADC_PGA_InitType; +/** + * @} + */ + +/** @addtogroup ADC_Exported_Constants + * @{ + */ +#define IsAdcChannel(PERIPH) (((PERIPH) == ADC_CTRL_CH_0) || ((PERIPH) == ADC_CTRL_CH_1)|| \ + ((PERIPH) == ADC_CTRL_CH_2) || ((PERIPH) == ADC_CTRL_CH_3)|| \ + ((PERIPH) == ADC_CTRL_CH_4) || ((PERIPH) == ADC_CTRL_CH_5)|| \ + ((PERIPH) == ADC_CTRL_CH_6) || ((PERIPH) == ADC_CTRL_CH_7) ) + +#define IsAdcModule(PERIPH) (((PERIPH) == ADC)) + +#define IsAdcDmaModule(PERIPH) (((PERIPH) == ADC)) + +/** @addtogroup MIC BIAS output voltage range setting, step=0.1V + * @{ + */ + + +/** @addtogroup Audio PGA drive signal amplitude setting + * @{ + */ + +/** @addtogroup Audio PGA drive current setting + * @{ + */ + +/** @addtogroup ADC_Exported_Constants + * @{ + */ + + +/** + * @brief ADC Init structure definition + */ +typedef struct +{ + FunctionalState VadZcrdEn; /*!< Audio PGA off-chip capacitorfast charge control + This parameter can be set to ENABLE or DISABLE. */ + + FunctionalState VadEdEn; /*!< Audio PGA Enable + This parameter can be set to ENABLE or DISABLE. */ + + FunctionalState VadFilterByp; /*!< Decides between Single and Continuous Conversion modes + This parameter can be set to ENABLE or DISABLE. */ +} ADC_DET_InitType; + +/** + * @} + */ + +/** @addtogroup ADC_channels + * @{ + */ + +/** + * @} + */ + + +/** @addtogroup ADC_interrupts_definition + the hign 8 bits (02,01,04) do not correspond to CTRL1 register, + the main poupose is to match the corresponding flag bit in the sts register + * @{ + */ + +#define ADC_INT_DONE ((uint16_t)0x0100) +#define ADC_INT_AWD ((uint16_t)0x0200) +#define ADC_INT_PGARDY ((uint16_t)0x0400) + +#define IsAdcInt(IT) ((((IT) & (uint16_t)0xF8FF) == 0x00) && ((IT) != 0x00)) + +#define IsAdcGetInt(IT) (((IT) == ADC_INT_DONE) || ((IT) == ADC_INT_AWD) || ((IT) == ADC_INT_PGARDY)) +/** + * @} + */ + +/** @addtogroup ADC_flags_definition + * @{ + */ + +#define ADC_FLAG_DONE ((uint8_t)0x01) +#define ADC_FLAG_AWD ((uint8_t)0x02) +#define ADC_FLAG_PGARDY ((uint8_t)0x04) +#define IsAdcClrFlag(FLAG) ((((FLAG) & (uint8_t)0xF8) == 0x00) && ((FLAG) != 0x00)) +#define IsAdcGetFlag(FLAG) \ + (((FLAG) == ADC_FLAG_DONE) || ((FLAG) == ADC_FLAG_AWD) || ((FLAG) == ADC_FLAG_PGARDY)) +/** + * @} + */ + + + /** @addtogroup ADC_MICBIAS_definition + * @{ + */ +#define MICBIAS_1V6 ADC_PGA_CFG_MICBIAS_0 +#define MICBIAS_1V7 ADC_PGA_CFG_MICBIAS_1 +#define MICBIAS_1V8 ADC_PGA_CFG_MICBIAS_2 +#define MICBIAS_1V9 ADC_PGA_CFG_MICBIAS_3 +#define MICBIAS_2V0 ADC_PGA_CFG_MICBIAS_4 +#define MICBIAS_2V1 ADC_PGA_CFG_MICBIAS_5 +#define MICBIAS_2V2 ADC_PGA_CFG_MICBIAS_6 +#define MICBIAS_2V3 ADC_PGA_CFG_MICBIAS_7 +#define IsAdcMicbias(Micbias) (((Micbias) == MICBIAS_1V6) || ((Micbias) == MICBIAS_1V7) || \ + ((Micbias) == MICBIAS_1V8) || ((Micbias) == MICBIAS_1V9) || \ + ((Micbias) == MICBIAS_2V0) || ((Micbias) == MICBIAS_2V1) || \ + ((Micbias) == MICBIAS_2V2) || ((Micbias) == MICBIAS_2V3) ) + +/** + * @} + */ + +#define IsAdcPgaPeak(Peak) (((Peak) == ADC_PGA_CFG_PEAK_0) || ((Peak) == ADC_PGA_CFG_PEAK_1) || \ + ((Peak) == ADC_PGA_CFG_PEAK_2) || ((Peak) == ADC_PGA_CFG_PEAK_3) ) + +#define IsAdcPgaDriver(Drive) (((Drive) == ADC_PGA_CFG_DRIVE_0) || ((Drive) == ADC_PGA_CFG_DRIVE_1) || \ + ((Drive) == ADC_PGA_CFG_DRIVE_2) || ((Drive) == ADC_PGA_CFG_DRIVE_3)) + +#define IsAdcPgaGain(Gain) (((Gain) == ADC_PGA_CFG_GAIN_0dB) || ((Gain) == ADC_PGA_CFG_GAIN_6dB) || \ + ((Gain) == ADC_PGA_CFG_GAIN_12dB) || ((Gain) == ADC_PGA_CFG_GAIN_18dB) || \ + ((Gain) == ADC_PGA_CFG_GAIN_24dB) || ((Gain) == ADC_PGA_CFG_GAIN_30dB) || \ + ((Gain) == ADC_PGA_CFG_GAIN_36dB) || ((Gain) == ADC_PGA_CFG_GAIN_42dB) ) + +/** + * @} + */ + +/** @addtogroup ADC_thresholds + * @{ + */ +#define IsAdcValid(Value) ((Value) <= 0xFFF) + +#define IsAdcVoiceZcrValid(THRESHOLD) ((THRESHOLD) <= 0xFF) +#define IsAdcVoiceEDValid(THRESHOLD) ((THRESHOLD) <= 0x007FFFFF) +/** + * @} + */ + + +/** @addtogroup ADC_NoiseOffset + * @{ + */ + +#define IsAdcNoiseOffsetValid(OFFSET) ((OFFSET) <= 0x00FFFFFF) + +/** @addtogroup ADC FIR FLT COEFFICIENT + * @{ + */ + +#define IsAdcFIRFLTValid(COEFFICIENT) ((COEFFICIENT) <= 0xFFFF) +/** + * @} + */ + +/** + * @} + */ + + + +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup ADC_Exported_Functions + * @{ + */ + +void ADC_DeInit(ADC_Module* ADCx); +void ADC_Enable(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_EnableDMA(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_EnableTS(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_EnableAWD(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_ConfigInt(ADC_Module* ADCx, uint16_t ADC_IT, FunctionalState Cmd); +void ADC_ConfigChannel(ADC_Module* ADCx, uint16_t Channel); +void ADC_ConfigContinuousMode(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_ConfigAnalogWatchdogThresholds(ADC_Module* ADCx, uint32_t High_Threshold, uint32_t Low_Threshold); +void ADC_ConfigVoiceZcrThresholds(ADC_Module* ADCx, uint32_t High_Threshold, uint32_t Low_Threshold); +void ADC_ConfigEDThreshold(ADC_Module* ADCx, uint32_t High_Threshold, uint32_t Low_Threshold); +void ADC_SetNoiseOffset(ADC_Module* ADCx, uint32_t moffset); +uint16_t ADC_GetDat(ADC_Module* ADCx); +FlagStatus ADC_GetFlagStatus(ADC_Module* ADCx, uint8_t ADC_FLAG); +void ADC_ClearFlag(ADC_Module* ADCx, uint8_t ADC_FLAG); +void ADC_EnableZeroCross(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_EnableEnergy(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_EnableBypassFilter(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_EnableMICBIAS(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_SetMICOutputVoltage(ADC_Module* ADCx, uint32_t MIC_VoltageValue); +void ADC_EnableAUDIOPGA(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_SetAUDIOAmplitude(ADC_Module* ADCx, uint32_t AMP_Value); +void ADC_SetAUDIOCurrent(ADC_Module* ADCx, uint32_t Drive_Value); +void ADC_EnablePGA(ADC_Module* ADCx, FunctionalState Cmd); +void ADC_SetPGAGain(ADC_Module* ADCx, uint32_t Gain_Value); +void ADC_SetOverSampleCounter(ADC_Module* ADCx, uint32_t Cnt); +uint32_t ADC_ConverValueToVoltage(uint16_t adc_value, uint16_t channel); +uint32_t ADC16Bit_ConverValueToVoltage(int16_t value_16bit, uint16_t channel,int16_t offset); +float ADC_ConverValueToTemperature(uint16_t adc_value); + +#ifdef __cplusplus +} +#endif + +#endif /*__N32WB03X_ADC_H__ */ + +/** + * @} + */ +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_crc.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_crc.h new file mode 100644 index 0000000..7141fc2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_crc.h @@ -0,0 +1,126 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_crc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_CRC_H__ +#define __N32WB03X_CRC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup CRC + * @{ + */ + +/** @addtogroup CRC_Exported_Types + * @{ + */ + +/** + * @} + */ + +/** @addtogroup CRC_Exported_Constants + * @{ + */ + +/** + * @} + */ + +/** @addtogroup CRC_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup CRC_Exported_Functions + * @{ + */ + +void CRC32_ResetCrc(void); +uint32_t CRC32_CalcCrc(uint32_t Data); +uint32_t CRC32_CalcBufCrc(uint32_t pBuffer[], uint32_t BufferLength); +uint32_t CRC32_GetCrc(void); +void CRC32_SetIDat(uint8_t IDValue); +uint8_t CRC32_GetIDat(void); + +uint16_t CRC16_CalcBufCrc(uint8_t pBuffer[], uint32_t BufferLength); +uint16_t CRC16_CalcCRC(uint8_t Data); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_CRC_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_dma.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_dma.h new file mode 100644 index 0000000..9243054 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_dma.h @@ -0,0 +1,417 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_dma.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_DMA_H__ +#define __N32WB03X_DMA_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup DMA + * @{ + */ + +/** @addtogroup DMA_Exported_Types + * @{ + */ + +/** + * @brief DMA Init structure definition + */ + +typedef struct +{ + uint32_t PeriphAddr; /*!< Specifies the peripheral base address for DMAy Channelx. */ + + uint32_t MemAddr; /*!< Specifies the memory base address for DMAy Channelx. */ + + uint32_t Direction; /*!< Specifies if the peripheral is the source or destination. + This parameter can be a value of @ref DMA_data_transfer_direction */ + + uint32_t BufSize; /*!< Specifies the buffer size, in data unit, of the specified Channel. + The data unit is equal to the configuration set in PeriphDataSize + or MemDataSize members depending in the transfer direction. */ + + uint32_t PeriphInc; /*!< Specifies whether the Peripheral address register is incremented or not. + This parameter can be a value of @ref DMA_peripheral_incremented_mode */ + + uint32_t DMA_MemoryInc; /*!< Specifies whether the memory address register is incremented or not. + This parameter can be a value of @ref DMA_memory_incremented_mode */ + + uint32_t PeriphDataSize; /*!< Specifies the Peripheral data width. + This parameter can be a value of @ref DMA_peripheral_data_size */ + + uint32_t MemDataSize; /*!< Specifies the Memory data width. + This parameter can be a value of @ref DMA_memory_data_size */ + + uint32_t CircularMode; /*!< Specifies the operation mode of the DMAy Channelx. + This parameter can be a value of @ref DMA_circular_normal_mode. + @note: The circular buffer mode cannot be used if the memory-to-memory + data transfer is configured on the selected Channel */ + + uint32_t Priority; /*!< Specifies the software priority for the DMAy Channelx. + This parameter can be a value of @ref DMA_priority_level */ + + uint32_t Mem2Mem; /*!< Specifies if the DMAy Channelx will be used in memory-to-memory transfer. + This parameter can be a value of @ref DMA_memory_to_memory */ +} DMA_InitType; + +/** + * @} + */ + +/** @addtogroup DMA_Exported_Constants + * @{ + */ +#define IS_DMA_PERIPH(PERIPH) ((PERIPH) == DMA) + +#define IS_DMA_ALL_PERIPH(PERIPH) \ + (((PERIPH) == DMA_CH1) || ((PERIPH) == DMA_CH2) || ((PERIPH) == DMA_CH3) || ((PERIPH) == DMA_CH4) \ + || ((PERIPH) == DMA_CH5)) + +/** @addtogroup DMA_data_transfer_direction + * @{ + */ + +#define DMA_DIR_PERIPH_DST ((uint32_t)0x00000010) +#define DMA_DIR_PERIPH_SRC ((uint32_t)0x00000000) +#define IS_DMA_DIR(DIR) (((DIR) == DMA_DIR_PERIPH_DST) || ((DIR) == DMA_DIR_PERIPH_SRC)) +/** + * @} + */ + +/** @addtogroup DMA_peripheral_incremented_mode + * @{ + */ + +#define DMA_PERIPH_INC_ENABLE ((uint32_t)0x00000040) +#define DMA_PERIPH_INC_DISABLE ((uint32_t)0x00000000) +#define IS_DMA_PERIPH_INC_STATE(STATE) (((STATE) == DMA_PERIPH_INC_ENABLE) || ((STATE) == DMA_PERIPH_INC_DISABLE)) +/** + * @} + */ + +/** @addtogroup DMA_memory_incremented_mode + * @{ + */ + +#define DMA_MEM_INC_ENABLE ((uint32_t)0x00000080) +#define DMA_MEM_INC_DISABLE ((uint32_t)0x00000000) +#define IS_DMA_MEM_INC_STATE(STATE) (((STATE) == DMA_MEM_INC_ENABLE) || ((STATE) == DMA_MEM_INC_DISABLE)) +/** + * @} + */ + +/** @addtogroup DMA_peripheral_data_size + * @{ + */ + +#define DMA_PERIPH_DATA_SIZE_BYTE ((uint32_t)0x00000000) +#define DMA_PERIPH_DATA_SIZE_HALFWORD ((uint32_t)0x00000100) +#define DMA_PERIPH_DATA_SIZE_WORD ((uint32_t)0x00000200) +#define IS_DMA_PERIPH_DATA_SIZE(SIZE) \ + (((SIZE) == DMA_PERIPH_DATA_SIZE_BYTE) || ((SIZE) == DMA_PERIPH_DATA_SIZE_HALFWORD) \ + || ((SIZE) == DMA_PERIPH_DATA_SIZE_WORD)) +/** + * @} + */ + +/** @addtogroup DMA_memory_data_size + * @{ + */ + +#define DMA_MemoryDataSize_Byte ((uint32_t)0x00000000) +#define DMA_MemoryDataSize_HalfWord ((uint32_t)0x00000400) +#define DMA_MemoryDataSize_Word ((uint32_t)0x00000800) +#define IS_DMA_MEMORY_DATA_SIZE(SIZE) \ + (((SIZE) == DMA_MemoryDataSize_Byte) || ((SIZE) == DMA_MemoryDataSize_HalfWord) \ + || ((SIZE) == DMA_MemoryDataSize_Word)) +/** + * @} + */ + +/** @addtogroup DMA_circular_normal_mode + * @{ + */ + +#define DMA_MODE_CIRCULAR ((uint32_t)0x00000020) +#define DMA_MODE_NORMAL ((uint32_t)0x00000000) +#define IS_DMA_MODE(MODE) (((MODE) == DMA_MODE_CIRCULAR) || ((MODE) == DMA_MODE_NORMAL)) +/** + * @} + */ + +/** @addtogroup DMA_priority_level + * @{ + */ + +#define DMA_PRIORITY_VERY_HIGH ((uint32_t)0x00003000) +#define DMA_PRIORITY_HIGH ((uint32_t)0x00002000) +#define DMA_PRIORITY_MEDIUM ((uint32_t)0x00001000) +#define DMA_PRIORITY_LOW ((uint32_t)0x00000000) +#define IS_DMA_PRIORITY(PRIORITY) \ + (((PRIORITY) == DMA_PRIORITY_VERY_HIGH) || ((PRIORITY) == DMA_PRIORITY_HIGH) \ + || ((PRIORITY) == DMA_PRIORITY_MEDIUM) || ((PRIORITY) == DMA_PRIORITY_LOW)) +/** + * @} + */ + +/** @addtogroup DMA_memory_to_memory + * @{ + */ + +#define DMA_M2M_ENABLE ((uint32_t)0x00004000) +#define DMA_M2M_DISABLE ((uint32_t)0x00000000) +#define IS_DMA_M2M_STATE(STATE) (((STATE) == DMA_M2M_ENABLE) || ((STATE) == DMA_M2M_DISABLE)) + +/** + * @} + */ + +/** @addtogroup DMA_interrupts_definition + * @{ + */ + +#define DMA_INT_TXC ((uint32_t)0x00000002) +#define DMA_INT_HTX ((uint32_t)0x00000004) +#define DMA_INT_ERR ((uint32_t)0x00000008) +#define IS_DMA_CONFIG_INT(IT) ((((IT)&0xFFFFFFF1) == 0x00) && ((IT) != 0x00)) + +#define DMA_INT_GLB1 ((uint32_t)0x00000001) +#define DMA_INT_TXC1 ((uint32_t)0x00000002) +#define DMA_INT_HTX1 ((uint32_t)0x00000004) +#define DMA_INT_ERR1 ((uint32_t)0x00000008) +#define DMA_INT_GLB2 ((uint32_t)0x00000010) +#define DMA_INT_TXC2 ((uint32_t)0x00000020) +#define DMA_INT_HTX2 ((uint32_t)0x00000040) +#define DMA_INT_ERR2 ((uint32_t)0x00000080) +#define DMA_INT_GLB3 ((uint32_t)0x00000100) +#define DMA_INT_TXC3 ((uint32_t)0x00000200) +#define DMA_INT_HTX3 ((uint32_t)0x00000400) +#define DMA_INT_ERR3 ((uint32_t)0x00000800) +#define DMA_INT_GLB4 ((uint32_t)0x00001000) +#define DMA_INT_TXC4 ((uint32_t)0x00002000) +#define DMA_INT_HTX4 ((uint32_t)0x00004000) +#define DMA_INT_ERR4 ((uint32_t)0x00008000) +#define DMA_INT_GLB5 ((uint32_t)0x00010000) +#define DMA_INT_TXC5 ((uint32_t)0x00020000) +#define DMA_INT_HTX5 ((uint32_t)0x00040000) +#define DMA_INT_ERR5 ((uint32_t)0x00080000) + + + +#define IS_DMA_CLR_INT(IT) (((((IT)&0xF0000000) == 0x00) || (((IT)&0xEFF00000) == 0x00)) && ((IT) != 0x00)) + +#define IS_DMA_GET_IT(IT) \ + (((IT) == DMA_INT_GLB1) || ((IT) == DMA_INT_TXC1) || ((IT) == DMA_INT_HTX1) || ((IT) == DMA_INT_ERR1) \ + || ((IT) == DMA_INT_GLB2) || ((IT) == DMA_INT_TXC2) || ((IT) == DMA_INT_HTX2) || ((IT) == DMA_INT_ERR2) \ + || ((IT) == DMA_INT_GLB3) || ((IT) == DMA_INT_TXC3) || ((IT) == DMA_INT_HTX3) || ((IT) == DMA_INT_ERR3) \ + || ((IT) == DMA_INT_GLB4) || ((IT) == DMA_INT_TXC4) || ((IT) == DMA_INT_HTX4) || ((IT) == DMA_INT_ERR4) \ + || ((IT) == DMA_INT_GLB5) || ((IT) == DMA_INT_TXC5) || ((IT) == DMA_INT_HTX5) || ((IT) == DMA_INT_ERR5) \ +) + +/** + * @} + */ + +/** @addtogroup DMA_flags_definition + * @{ + */ +#define DMA_FLAG_GL1 ((uint32_t)0x00000001) +#define DMA_FLAG_TC1 ((uint32_t)0x00000002) +#define DMA_FLAG_HT1 ((uint32_t)0x00000004) +#define DMA_FLAG_TE1 ((uint32_t)0x00000008) +#define DMA_FLAG_GL2 ((uint32_t)0x00000010) +#define DMA_FLAG_TC2 ((uint32_t)0x00000020) +#define DMA_FLAG_HT2 ((uint32_t)0x00000040) +#define DMA_FLAG_TE2 ((uint32_t)0x00000080) +#define DMA_FLAG_GL3 ((uint32_t)0x00000100) +#define DMA_FLAG_TC3 ((uint32_t)0x00000200) +#define DMA_FLAG_HT3 ((uint32_t)0x00000400) +#define DMA_FLAG_TE3 ((uint32_t)0x00000800) +#define DMA_FLAG_GL4 ((uint32_t)0x00001000) +#define DMA_FLAG_TC4 ((uint32_t)0x00002000) +#define DMA_FLAG_HT4 ((uint32_t)0x00004000) +#define DMA_FLAG_TE4 ((uint32_t)0x00008000) +#define DMA_FLAG_GL5 ((uint32_t)0x00010000) +#define DMA_FLAG_TC5 ((uint32_t)0x00020000) +#define DMA_FLAG_HT5 ((uint32_t)0x00040000) +#define DMA_FLAG_TE5 ((uint32_t)0x00080000) + + +#define IS_DMA_CLEAR_FLAG(FLAG) (((((FLAG)&0xF0000000) == 0x00) || (((FLAG)&0xEFF00000) == 0x00)) && ((FLAG) != 0x00)) + +#define IS_DMA_GET_FLAG(FLAG) \ + (((FLAG) == DMA_FLAG_GL1) || ((FLAG) == DMA_FLAG_TC1) || ((FLAG) == DMA_FLAG_HT1) || ((FLAG) == DMA_FLAG_TE1) \ + || ((FLAG) == DMA_FLAG_GL2) || ((FLAG) == DMA_FLAG_TC2) || ((FLAG) == DMA_FLAG_HT2) \ + || ((FLAG) == DMA_FLAG_TE2) || ((FLAG) == DMA_FLAG_GL3) || ((FLAG) == DMA_FLAG_TC3) \ + || ((FLAG) == DMA_FLAG_HT3) || ((FLAG) == DMA_FLAG_TE3) || ((FLAG) == DMA_FLAG_GL4) \ + || ((FLAG) == DMA_FLAG_TC4) || ((FLAG) == DMA_FLAG_HT4) || ((FLAG) == DMA_FLAG_TE4) \ + || ((FLAG) == DMA_FLAG_GL5) || ((FLAG) == DMA_FLAG_TC5) || ((FLAG) == DMA_FLAG_HT5) \ + || ((FLAG) == DMA_FLAG_TE5)) +/** + * @} + */ + +/** @addtogroup DMA_Buffer_Size + * @{ + */ + +#define IS_DMA_BUF_SIZE(SIZE) (((SIZE) >= 0x1) && ((SIZE) < 0x10000)) + +/** + * @} + */ + +/** @addtogroup DMA_remap_request_definition + * @{ + */ +#define DMA_REMAP_ADC ((uint32_t)0x00000000) +#define DMA_REMAP_USART1_TX ((uint32_t)0x00000002) +#define DMA_REMAP_USART1_RX ((uint32_t)0x00000003) +#define DMA_REMAP_LPUART_TX ((uint32_t)0x00000004) +#define DMA_REMAP_LPUART_RX ((uint32_t)0x00000005) +#define DMA_REMAP_USART2_TX ((uint32_t)0x00000006) +#define DMA_REMAP_USART2_RX ((uint32_t)0x00000007) +#define DMA_REMAP_SPI1_TX ((uint32_t)0x00000008) +#define DMA_REMAP_SPI1_RX ((uint32_t)0x00000009) +#define DMA_REMAP_SPI2_TX ((uint32_t)0x0000000A) +#define DMA_REMAP_SPI2_RX ((uint32_t)0x0000000B) +#define DMA_REMAP_I2C_TX ((uint32_t)0x0000000C) +#define DMA_REMAP_I2C_RX ((uint32_t)0x0000000D) +#define DMA_REMAP_TIM1_CH1 ((uint32_t)0x0000000E) +#define DMA_REMAP_TIM1_CH2 ((uint32_t)0x0000000F) +#define DMA_REMAP_TIM1_CH3 ((uint32_t)0x00000010) +#define DMA_REMAP_TIM1_CH4 ((uint32_t)0x00000011) +#define DMA_REMAP_TIM1_COM ((uint32_t)0x00000012) +#define DMA_REMAP_TIM1_UP ((uint32_t)0x00000013) +#define DMA_REMAP_TIM1_TRIG ((uint32_t)0x00000014) +#define DMA_REMAP_TIM3_CH1 ((uint32_t)0x00000015) +#define DMA_REMAP_TIM3_CH3 ((uint32_t)0x00000016) +#define DMA_REMAP_TIM3_CH4 ((uint32_t)0x00000017) +#define DMA_REMAP_TIM3_UP ((uint32_t)0x00000018) +#define DMA_REMAP_TIM3_TRIG ((uint32_t)0x00000019) +#define DMA_REMAP_TIM6 ((uint32_t)0x0000001A) + +#define IS_DMA_REMAP(FLAG) (((FLAG) == DMA_REMAP_ADC) || \ + ((FLAG) == DMA_REMAP_USART1_TX) || ((FLAG) == DMA_REMAP_USART1_RX) || \ + ((FLAG) == DMA_REMAP_LPUART_TX) || ((FLAG) == DMA_REMAP_LPUART_RX)|| \ + ((FLAG) == DMA_REMAP_USART2_TX) || ((FLAG) == DMA_REMAP_USART2_RX)|| \ + ((FLAG) == DMA_REMAP_SPI1_TX) || ((FLAG) == DMA_REMAP_SPI1_RX) || \ + ((FLAG) == DMA_REMAP_SPI2_TX) || ((FLAG) == DMA_REMAP_SPI2_RX) || \ + ((FLAG) == DMA_REMAP_I2C_TX) || ((FLAG) == DMA_REMAP_I2C_RX) || \ + ((FLAG) == DMA_REMAP_TIM1_CH1) || ((FLAG) == DMA_REMAP_TIM1_CH2) || \ + ((FLAG) == DMA_REMAP_TIM1_CH3) || ((FLAG) == DMA_REMAP_TIM1_CH4) || \ + ((FLAG) == DMA_REMAP_TIM1_COM) || ((FLAG) == DMA_REMAP_TIM1_UP) || \ + ((FLAG) == DMA_REMAP_TIM1_TRIG) || ((FLAG) == DMA_REMAP_TIM3_CH1) || \ + ((FLAG) == DMA_REMAP_TIM3_CH3) || ((FLAG) == DMA_REMAP_TIM3_CH4) || \ + ((FLAG) == DMA_REMAP_TIM3_UP) || ((FLAG) == DMA_REMAP_TIM3_TRIG) || \ + ((FLAG) == DMA_REMAP_TIM6)) +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup DMA_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup DMA_Exported_Functions + * @{ + */ + +void DMA_DeInit(DMA_ChannelType* DMAChx); +void DMA_Init(DMA_ChannelType* DMAChx, DMA_InitType* DMA_InitParam); +void DMA_StructInit(DMA_InitType* DMA_InitParam); +void DMA_EnableChannel(DMA_ChannelType* DMAChx, FunctionalState Cmd); +void DMA_ConfigInt(DMA_ChannelType* DMAChx, uint32_t DMAInt, FunctionalState Cmd); +void DMA_SetCurrDataCounter(DMA_ChannelType* DMAChx, uint16_t DataNumber); +uint16_t DMA_GetCurrDataCounter(DMA_ChannelType* DMAChx); +FlagStatus DMA_GetFlagStatus(uint32_t DMAFlag, DMA_Module* DMAy); +void DMA_ClearFlag(uint32_t DMAFlag, DMA_Module* DMAy); +INTStatus DMA_GetIntStatus(uint32_t DMA_IT, DMA_Module* DMAy); +void DMA_ClrIntPendingBit(uint32_t DMA_IT, DMA_Module* DMAy); +void DMA_RequestRemap(uint32_t DMA_REMAP, DMA_Module* DMAy, DMA_ChannelType* DMAChx, FunctionalState Cmd); + +#ifdef __cplusplus +} +#endif + +#endif /*__N32WB03X_DMA_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_exti.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_exti.h new file mode 100644 index 0000000..a3b7c54 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_exti.h @@ -0,0 +1,232 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_exti.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_EXTI_H__ +#define __N32WB03X_EXTI_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup EXTI + * @{ + */ + +/** @addtogroup EXTI_Exported_Types + * @{ + */ + +/** + * @brief EXTI mode enumeration + */ + +typedef enum +{ + EXTI_Mode_Interrupt = 0x00, + EXTI_Mode_Event = 0x04 +} EXTI_ModeType; + +#define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event)) + +/** + * @brief EXTI Trigger enumeration + */ + +typedef enum +{ + EXTI_Trigger_Rising = 0x08, + EXTI_Trigger_Falling = 0x0C, + EXTI_Trigger_Rising_Falling = 0x10 +} EXTI_TriggerType; + +#define IS_EXTI_TRIGGER(TRIGGER) \ + (((TRIGGER) == EXTI_Trigger_Rising) || ((TRIGGER) == EXTI_Trigger_Falling) \ + || ((TRIGGER) == EXTI_Trigger_Rising_Falling)) +/** + * @brief EXTI Init Structure definition + */ + +typedef struct +{ + uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled. + This parameter can be any combination of @ref EXTI_Lines */ + + EXTI_ModeType EXTI_Mode; /*!< Specifies the mode for the EXTI lines. + This parameter can be a value of @ref EXTI_ModeType */ + + EXTI_TriggerType EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines. + This parameter can be a value of @ref EXTI_ModeType */ + + FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines. + This parameter can be set either to ENABLE or DISABLE */ +} EXTI_InitType; + +/** + * @} + */ + +/** @addtogroup EXTI_Exported_Constants + * @{ + */ + +/** @addtogroup EXTI_Lines + * @{ + */ + +#define EXTI_LINE0 ((uint32_t)0x00001) /*!< External interrupt line 0 Connected to the PA0 PA1 PB0 */ +#define EXTI_LINE1 ((uint32_t)0x00002) /*!< External interrupt line 1 Connected to the PA2 PA3 PB1 */ +#define EXTI_LINE2 ((uint32_t)0x00004) /*!< External interrupt line 2 Connected to the PA6 PB2 */ +#define EXTI_LINE3 ((uint32_t)0x00008) /*!< External interrupt line 3 Connected to the PA5 PB3 */ +#define EXTI_LINE4 ((uint32_t)0x00010) /*!< External interrupt line 4 Connected to the PB9 PB4 */ +#define EXTI_LINE5 ((uint32_t)0x00020) /*!< External interrupt line 5 Connected to the PB10 PB11 PB5 */ +#define EXTI_LINE6 ((uint32_t)0x00040) /*!< External interrupt line 6 Connected to the PB12 PB6 PA4 */ +#define EXTI_LINE7 ((uint32_t)0x00080) /*!< External interrupt line 7 Connected to the PB13 PB7 PB8 */ +#define EXTI_LINE8 ((uint32_t)0x00100) /*!< External interrupt line 8 Connected to the RTC Alarm event */ +#define EXTI_LINE9 ((uint32_t)0x00200) /*!< External interrupt line 9 Connected to the RTC Wakeup event */ +#define EXTI_LINE10 ((uint32_t)0x00400) /*!< External interrupt line 10 Connected to the LPUART Wakeup event */ +#define EXTI_LINE11 ((uint32_t)0x00800) /*!< External interrupt line 11 Connected to the LPTIM Wakeup event */ +#define EXTI_LINE12 ((uint32_t)0x01000) /*!< External interrupt line 12 Connected to the NRST Wakeup event */ +#define EXTI_LINE13 ((uint32_t)0x02000) /*!< External interrupt line 13 Connected to the KEYSCAN Wakeup event */ + +#define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFF000000) == 0x00) && ((LINE) != (uint16_t)0x00)) +#define IS_GET_EXTI_LINE(LINE) \ + (((LINE) == EXTI_LINE0) || ((LINE) == EXTI_LINE1) || ((LINE) == EXTI_LINE2) || ((LINE) == EXTI_LINE3) \ + || ((LINE) == EXTI_LINE4) || ((LINE) == EXTI_LINE5) || ((LINE) == EXTI_LINE6) || ((LINE) == EXTI_LINE7) \ + || ((LINE) == EXTI_LINE8) || ((LINE) == EXTI_LINE9) || ((LINE) == EXTI_LINE10) || ((LINE) == EXTI_LINE11) \ + || ((LINE) == EXTI_LINE12) || ((LINE) == EXTI_LINE13) ) + +/** + * @} + */ + +/** @addtogroup EXTI_TSSEL_Line + * @{ + */ +#define EXTI_TSSEL_LINE_MASK ((uint32_t)0x00000) +#define EXTI_TSSEL_LINE0 ((uint32_t)0x00000) /*!< External interrupt line 0 */ +#define EXTI_TSSEL_LINE1 ((uint32_t)0x00001) /*!< External interrupt line 1 */ +#define EXTI_TSSEL_LINE2 ((uint32_t)0x00002) /*!< External interrupt line 2 */ +#define EXTI_TSSEL_LINE3 ((uint32_t)0x00003) /*!< External interrupt line 3 */ +#define EXTI_TSSEL_LINE4 ((uint32_t)0x00004) /*!< External interrupt line 4 */ +#define EXTI_TSSEL_LINE5 ((uint32_t)0x00005) /*!< External interrupt line 5 */ +#define EXTI_TSSEL_LINE6 ((uint32_t)0x00006) /*!< External interrupt line 6 */ +#define EXTI_TSSEL_LINE7 ((uint32_t)0x00007) /*!< External interrupt line 7 */ +#define EXTI_TSSEL_LINE8 ((uint32_t)0x00008) /*!< External interrupt line 8 */ +#define EXTI_TSSEL_LINE9 ((uint32_t)0x00009) /*!< External interrupt line 9 */ +#define EXTI_TSSEL_LINE10 ((uint32_t)0x0000A) /*!< External interrupt line 10 */ +#define EXTI_TSSEL_LINE11 ((uint32_t)0x0000B) /*!< External interrupt line 11 */ +#define EXTI_TSSEL_LINE12 ((uint32_t)0x0000C) /*!< External interrupt line 12 */ +#define EXTI_TSSEL_LINE13 ((uint32_t)0x0000D) /*!< External interrupt line 13 */ +#define EXTI_TSSEL_LINE14 ((uint32_t)0x0000E) /*!< External interrupt line 14 */ +#define EXTI_TSSEL_LINE15 ((uint32_t)0x0000F) /*!< External interrupt line 15 */ + +#define IS_EXTI_TSSEL_LINE(LINE) \ + (((LINE) == EXTI_TSSEL_LINE0) || ((LINE) == EXTI_TSSEL_LINE1) || ((LINE) == EXTI_TSSEL_LINE2) \ + || ((LINE) == EXTI_TSSEL_LINE3) || ((LINE) == EXTI_TSSEL_LINE4) || ((LINE) == EXTI_TSSEL_LINE5) \ + || ((LINE) == EXTI_TSSEL_LINE6) || ((LINE) == EXTI_TSSEL_LINE7) || ((LINE) == EXTI_TSSEL_LINE8) \ + || ((LINE) == EXTI_TSSEL_LINE9) || ((LINE) == EXTI_TSSEL_LINE10) || ((LINE) == EXTI_TSSEL_LINE11) \ + || ((LINE) == EXTI_TSSEL_LINE12) || ((LINE) == EXTI_TSSEL_LINE13) || ((LINE) == EXTI_TSSEL_LINE14) \ + || ((LINE) == EXTI_TSSEL_LINE15)) +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup EXTI_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup EXTI_Exported_Functions + * @{ + */ + +void EXTI_DeInit(void); +void EXTI_InitPeripheral(EXTI_InitType* EXTI_InitStruct); +void EXTI_InitStruct(EXTI_InitType* EXTI_InitStruct); +void EXTI_TriggerSWInt(uint32_t EXTI_Line); +FlagStatus EXTI_GetStatusFlag(uint32_t EXTI_Line); +void EXTI_ClrStatusFlag(uint32_t EXTI_Line); +INTStatus EXTI_GetITStatus(uint32_t EXTI_Line); +void EXTI_ClrITPendBit(uint32_t EXTI_Line); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_EXTI_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_gpio.h new file mode 100644 index 0000000..60f6322 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_gpio.h @@ -0,0 +1,486 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_GPIO_H__ +#define __N32WB03X_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup GPIO + * @{ + */ + +/** @addtogroup GPIO_Exported_Types + * @{ + */ + +/** + * @brief GPIO Init structure definition + */ +typedef struct +{ + uint32_t Pin; /*!< Specifies the GPIO pins to be configured. + This parameter can be any value of @ref GPIO_pins_define */ + + uint32_t GPIO_Mode; /*!< Specifies the operating mode for the selected pins. + This parameter can be a value of @ref GPIO_mode_define */ + + uint32_t GPIO_Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins. + This parameter can be a value of @ref GPIO_pull_define */ + + uint32_t GPIO_Speed; /*!< Specifies the slew rate for the selected pins. + This parameter can be a value of @ref GPIO_speed_define */ + + uint32_t GPIO_Current; /*!. + This paramter can be a value of @ref GPIO_current_define */ + + uint32_t GPIO_Alternate; /*!< Specifies the alternate function for the selected pins + This parameter can be a value of @ref GPIOEx_Alternate_function_selection */ +} GPIO_InitType; + +/** + * @brief Bit_SET and Bit_RESET enumeration + */ + +typedef enum +{ + Bit_RESET = 0, + Bit_SET +} Bit_OperateType; + +#define IS_GPIO_BIT_OPERATE(OPERATE) (((OPERATE) == Bit_RESET) || ((OPERATE) == Bit_SET)) + +/** + * @} + */ + +/** @addtogroup GPIO_Exported_Constants GPIO Exported Constants + * @{ + */ + +#define IS_GPIO_ALL_PERIPH(PERIPH) \ + (((PERIPH) == GPIOA) || ((PERIPH) == GPIOB)) + +#define GPIO_GET_INDEX(PERIPH) (((PERIPH) == (GPIOA))? 0 :1) + +#define GPIO_GET_PERIPH(INDEX) (((INDEX)==((uint8_t)0x00))? GPIOA :GPIOB) + +/** @addtogroup GPIO_pins_define Pin definition + * @{ + */ +#define GPIO_PIN_0 ((uint16_t)0x0001U) /*!< Pin 0 selected */ +#define GPIO_PIN_1 ((uint16_t)0x0002U) /*!< Pin 1 selected */ +#define GPIO_PIN_2 ((uint16_t)0x0004U) /*!< Pin 2 selected */ +#define GPIO_PIN_3 ((uint16_t)0x0008U) /*!< Pin 3 selected */ +#define GPIO_PIN_4 ((uint16_t)0x0010U) /*!< Pin 4 selected */ +#define GPIO_PIN_5 ((uint16_t)0x0020U) /*!< Pin 5 selected */ +#define GPIO_PIN_6 ((uint16_t)0x0040U) /*!< Pin 6 selected */ +#define GPIO_PIN_7 ((uint16_t)0x0080U) /*!< Pin 7 selected */ +#define GPIO_PIN_8 ((uint16_t)0x0100U) /*!< Pin 8 selected */ +#define GPIO_PIN_9 ((uint16_t)0x0200U) /*!< Pin 9 selected */ +#define GPIO_PIN_10 ((uint16_t)0x0400U) /*!< Pin 10 selected */ +#define GPIO_PIN_11 ((uint16_t)0x0800U) /*!< Pin 11 selected */ +#define GPIO_PIN_12 ((uint16_t)0x1000U) /*!< Pin 12 selected */ +#define GPIO_PIN_13 ((uint16_t)0x2000U) /*!< Pin 13 selected */ +#define GPIO_PIN_ALL ((uint16_t)0x3FFFU) /*!< All pins selected */ + +#define GPIOA_PIN_AVAILABLE (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |GPIO_PIN_3 |\ + GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6) +#define GPIOB_PIN_AVAILABLE GPIO_PIN_ALL +/** + * @} + */ +#define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00)) + +#define IS_GET_GPIO_PIN(PIN) \ + (((PIN) == GPIO_PIN_0) || ((PIN) == GPIO_PIN_1) || ((PIN) == GPIO_PIN_2) || ((PIN) == GPIO_PIN_3) \ + || ((PIN) == GPIO_PIN_4) || ((PIN) == GPIO_PIN_5) || ((PIN) == GPIO_PIN_6) || ((PIN) == GPIO_PIN_7) \ + || ((PIN) == GPIO_PIN_8) || ((PIN) == GPIO_PIN_9) || ((PIN) == GPIO_PIN_10) || ((PIN) == GPIO_PIN_11) \ + || ((PIN) == GPIO_PIN_12) || ((PIN) == GPIO_PIN_13)) + + +#define IS_GPIO_PIN_AVAILABLE(__INSTANCE__,__PIN__) \ + ((((__INSTANCE__) == GPIOA) && (((__PIN__) & (GPIOA_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOA_PIN_AVAILABLE)) == (GPIOA_PIN_AVAILABLE))) || \ + (((__INSTANCE__) == GPIOB) && (((__PIN__) & (GPIOB_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOB_PIN_AVAILABLE)) == (GPIOB_PIN_AVAILABLE)))) + +/** @addtogroup GPIO_mode_define Mode definition + * Values convention: 0xW0yz00YZ + * - W : GPIO mode or EXTI Mode + * - y : External IT or Event trigger detection + * - z : IO configuration on External IT or Event + * - Y : Output type (Push Pull or Open Drain) + * - Z : IO Direction mode (Input, Output, Alternate or Analog) + * @{ + */ +#define GPIO_MODE_INPUT ((uint32_t)0x00000000U) /*!< Input Floating Mode */ +#define GPIO_MODE_OUTPUT_PP ((uint32_t)0x00000001U) /*!< Output Push Pull Mode */ +#define GPIO_MODE_OUTPUT_OD ((uint32_t)0x00000011U) /*!< Output Open Drain Mode */ +#define GPIO_MODE_AF_PP ((uint32_t)0x00000002U) /*!< Alternate Function Push Pull Mode */ +#define GPIO_MODE_AF_OD ((uint32_t)0x00000012U) /*!< Alternate Function Open Drain Mode */ + +#define GPIO_MODE_ANALOG ((uint32_t)0x00000003U) /*!< Analog Mode */ + +#define GPIO_MODE_IT_RISING ((uint32_t)0x10110000U) +#define GPIO_MODE_IT_FALLING ((uint32_t)0x10210000U) +#define GPIO_MODE_IT_RISING_FALLING ((uint32_t)0x10310000U) + +#define GPIO_MODE_EVT_RISING ((uint32_t)0x10132000U) +#define GPIO_MODE_EVT_FALLING ((uint32_t)0x10120000U) +#define GPIO_MODE_EVT_RISING_FALLING ((uint32_t)0x10320000U) +/** + * @} + */ +#define IS_GPIO_MODE(__MODE__) (((__MODE__) == GPIO_MODE_INPUT) ||\ + ((__MODE__) == GPIO_MODE_OUTPUT_PP) ||\ + ((__MODE__) == GPIO_MODE_OUTPUT_OD) ||\ + ((__MODE__) == GPIO_MODE_AF_PP) ||\ + ((__MODE__) == GPIO_MODE_AF_OD) ||\ + ((__MODE__) == GPIO_MODE_IT_RISING) ||\ + ((__MODE__) == GPIO_MODE_IT_FALLING) ||\ + ((__MODE__) == GPIO_MODE_IT_RISING_FALLING) ||\ + ((__MODE__) == GPIO_MODE_EVT_RISING) ||\ + ((__MODE__) == GPIO_MODE_EVT_FALLING) ||\ + ((__MODE__) == GPIO_MODE_EVT_RISING_FALLING) ||\ + ((__MODE__) == GPIO_MODE_ANALOG)) + +/** + * @addtogroup GPIO_pull_define Pull definition + * @brief GPIO Pull-Up or Pull-Down Activation + * @{ + */ +#define GPIO_NO_PULL ((uint32_t)0x00000000U) +#define GPIO_PULL_UP ((uint32_t)0x00000001U) +#define GPIO_PULL_DOWN ((uint32_t)0x00000002U) +/** + * @} + */ +#define IS_GPIO_PULL(__PULL__) (((__PULL__) == GPIO_NO_PULL) || ((__PULL__) == GPIO_PULL_UP) || \ + ((__PULL__) == GPIO_PULL_DOWN)) + +/** + * @addtogroup GPIO_speed_define Speed definition + * @brief GPIO Output Maximum frequency + * @{ + */ +#define GPIO_SPEED_HIGH ((uint32_t)0x00000000U) +#define GPIO_SPEED_LOW ((uint32_t)0x00000001U) +/** + * @} + */ +#define IS_GPIO_SPEED(_SPEED_) \ + (((_SPEED_) == GPIO_SPEED_HIGH) || ((_SPEED_) == GPIO_SPEED_LOW)) + +/** + * @addtogroup GPIO_current_define Current definition + * @brief GPIO Driver Strength Configuration + * @{ + */ +#define GPIO_DC_2MA ((uint32_t)0x00000000U) +#define GPIO_DC_4MA ((uint32_t)0x00000002U) +#define GPIO_DC_8MA ((uint32_t)0x00000001U) +#define GPIO_DC_12MA ((uint32_t)0x00000003U) +#define GPIO_DC_HIGH GPIO_DC_12MA +#define GPIO_DC_LOW GPIO_DC_2MA +/** + * @} + */ +#define IS_GPIO_CURRENT(CURRENT) \ + (((CURRENT) == GPIO_DC_HIGH)||((CURRENT) == GPIO_DC_LOW)) + +/** @addtogroup GPIO_Port_Sources + * @{ + */ + +#define GPIOA_PORT_SOURCE ((uint8_t)0x00) +#define GPIOB_PORT_SOURCE ((uint8_t)0x01) +/** + * @} + */ +/** + * @} + */ +#define IS_GPIO_REMAP_PORT_SOURCE(PORTSOURCE) \ + (((PORTSOURCE) == GPIOA_PORT_SOURCE) || ((PORTSOURCE) == GPIOB_PORT_SOURCE)) + + +#define IS_GPIO_EXTI_PORT_SOURCE(PORTSOURCE) \ + (((PORTSOURCE) == GPIOA_PORT_SOURCE) || ((PORTSOURCE) == GPIOB_PORT_SOURCE)) + +/** @addtogroup GPIO_Pin_sources + * @{ + */ +#define GPIO_PIN_SOURCE0 ((uint8_t)0x00) +#define GPIO_PIN_SOURCE1 ((uint8_t)0x01) +#define GPIO_PIN_SOURCE2 ((uint8_t)0x02) +#define GPIO_PIN_SOURCE3 ((uint8_t)0x03) +#define GPIO_PIN_SOURCE4 ((uint8_t)0x04) +#define GPIO_PIN_SOURCE5 ((uint8_t)0x05) +#define GPIO_PIN_SOURCE6 ((uint8_t)0x06) +#define GPIO_PIN_SOURCE7 ((uint8_t)0x07) +#define GPIO_PIN_SOURCE8 ((uint8_t)0x08) +#define GPIO_PIN_SOURCE9 ((uint8_t)0x09) +#define GPIO_PIN_SOURCE10 ((uint8_t)0x0A) +#define GPIO_PIN_SOURCE11 ((uint8_t)0x0B) +#define GPIO_PIN_SOURCE12 ((uint8_t)0x0C) +#define GPIO_PIN_SOURCE13 ((uint8_t)0x0D) +/** + * @} + */ +#define IS_GPIO_PIN_SOURCE(PINSOURCE) \ + (((PINSOURCE) == GPIO_PIN_SOURCE0) || ((PINSOURCE) == GPIO_PIN_SOURCE1) || ((PINSOURCE) == GPIO_PIN_SOURCE2) \ + || ((PINSOURCE) == GPIO_PIN_SOURCE3) || ((PINSOURCE) == GPIO_PIN_SOURCE4) || ((PINSOURCE) == GPIO_PIN_SOURCE5) \ + || ((PINSOURCE) == GPIO_PIN_SOURCE6) || ((PINSOURCE) == GPIO_PIN_SOURCE7) || ((PINSOURCE) == GPIO_PIN_SOURCE8) \ + || ((PINSOURCE) == GPIO_PIN_SOURCE9) || ((PINSOURCE) == GPIO_PIN_SOURCE10) || ((PINSOURCE) == GPIO_PIN_SOURCE11) \ + || ((PINSOURCE) == GPIO_PIN_SOURCE12) || ((PINSOURCE) == GPIO_PIN_SOURCE13)) + +/** @addtogroup GPIOx_Alternate_function_selection Alternate function selection + * @{ + */ + +/* + * Alternate function AF0 + */ +#define GPIO_AF0 ((uint8_t)0x00U) +#define GPIO_AF0_SWD (GPIO_AF0) /* SWD Alternate Function mapping */ +#define GPIO_AF0_OSC (GPIO_AF0) /* OSC Alternate Function mapping */ + +/* + * Alternate function AF1 + */ +#define GPIO_AF1 ((uint8_t)0x01U) +#define GPIO_AF1_TIM1 (GPIO_AF1) /* TIM1 Alternate Function mapping */ +#define GPIO_AF1_SPI1 (GPIO_AF1) /* SPI1 Alternate Function mapping */ +#define GPIO_AF1_SPI2 (GPIO_AF1) /* SPI2 Alternate Function mapping */ + + +/* + * Alternate function AF2 + */ +#define GPIO_AF2 ((uint8_t)0x02U) +#define GPIO_AF2_TIM3 (GPIO_AF2) /* TIM3 Alternate Function mapping */ +#define GPIO_AF2_LPUART1 (GPIO_AF2) /* LPUART1 Alternate Function mapping */ +#define GPIO_AF2_USART2 (GPIO_AF2) /* USART2 Alternate Function mapping */ +#define GPIO_AF2_SPI2 (GPIO_AF2) /* SPI2 Alternate Function mapping */ +#define GPIO_AF2_I2C (GPIO_AF2) /* I2C Alternate Function mapping */ + + +/* + * Alternate function AF3 + */ +#define GPIO_AF3 ((uint8_t)0x03U) +#define GPIO_AF3_USART1 (GPIO_AF3) /* USART1 Alternate Function mapping */ +#define GPIO_AF3_USART2 (GPIO_AF3) /* USART2 Alternate Function mapping */ +#define GPIO_AF3_I2C (GPIO_AF3) /* I2C Alternate Function mapping */ + +/* + * Alternate function AF4 + */ +#define GPIO_AF4 ((uint8_t)0x04U) +#define GPIO_AF4_USART1 (GPIO_AF4) /* USART1 Alternate Function mapping */ +#define GPIO_AF4_LPUART1 (GPIO_AF4) /* LPUART1 Alternate Function mapping */ +#define GPIO_AF4_I2C (GPIO_AF4) /* I2C Alternate Function mapping */ +#define GPIO_AF4_MCO (GPIO_AF4) /* RCC MCO Alternate Function mapping */ + +/* + * Alternate function AF5 + */ +#define GPIO_AF5 ((uint8_t)0x05U) +#define GPIO_AF5_KEYSCAN (GPIO_AF5) /* KEYSCAN Alternate Function mapping */ + +/* + * Alternate function AF6 + */ +#define GPIO_AF6 ((uint8_t)0x06U) +#define GPIO_AF6_SWD (GPIO_AF6) /* SWD Alternate Function mapping */ + + +#define GPIO_AF15 ((uint8_t)0x0FU) /* NON Alternate Function mapping */ +#define GPIO_NO_AF (GPIO_AF15) +/** + * @} + */ + + +/** + * IS_GPIO_AF macro definition + */ +#define IS_GPIO_AF(AF) ((AF) <= (uint8_t)0x0FU) +/** + * @} + */ +/** + * @} + */ + +/** @defgroup GPIO Alternate function remaping + * @{ + */ + +#define AFIO_SPI1_NSS (0x00000800UL) +#define AFIO_SPI2_NSS (0x00000400UL) +#define IS_AFIO_SPIX(_PARAMETER_) \ + (((_PARAMETER_) == AFIO_SPI1_NSS) || ((_PARAMETER_) == AFIO_SPI2_NSS) ) + +#define AFIO_SPI_NSS_High_IMPEDANCE (0x0UL) +#define AFIO_SPI_NSS_High_LEVEL (0x1UL) +#define IS_AFIO_SPI_NSS(_PARAMETER_) \ + (((_PARAMETER_) == AFIO_SPI_NSS_High_IMPEDANCE) ||((_PARAMETER_) == AFIO_SPI_NSS_High_LEVEL)) + + +typedef enum +{ + AFIO_ADC_ETRI = 0U, + AFIO_ADC_ETRR = 1U +}AFIO_ADC_ETRType; + +typedef enum +{ + AFIO_ADC_TRIG_EXTI_0 = 0U, + AFIO_ADC_TRIG_EXTI_1 = 1U, + AFIO_ADC_TRIG_EXTI_2, + AFIO_ADC_TRIG_EXTI_3, + AFIO_ADC_TRIG_EXTI_4, + AFIO_ADC_TRIG_EXTI_5, + AFIO_ADC_TRIG_EXTI_6, + AFIO_ADC_TRIG_EXTI_7, + AFIO_ADC_TRIG_EXTI_8, + AFIO_ADC_TRIG_EXTI_9, + AFIO_ADC_TRIG_EXTI_10, + AFIO_ADC_TRIG_EXTI_11, + AFIO_ADC_TRIG_EXTI_12, + AFIO_ADC_TRIG_EXTI_13, +}AFIO_ADC_Trig_RemapType; + +#define IS_AFIO_ADC_ETR(_PARAMETER_) \ + (((_PARAMETER_) == AFIO_ADC_ETRI) ||((_PARAMETER_) == AFIO_ADC_ETRR)) + +#define IS_AFIO_ADC_ETRI(_PARAMETER_) \ + (((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_0) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_1)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_2) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_3)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_4) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_5)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_6) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_7)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_8) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_9)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_10) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_11)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_12) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_13)) + +#define IS_AFIO_ADC_ETRR(_PARAMETER_) \ + (((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_0) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_1)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_2) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_3)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_4) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_5)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_6) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_7)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_8) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_9)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_10) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_11)|| \ + ((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_12) ||((_PARAMETER_) == AFIO_ADC_TRIG_EXTI_13)) + + /** + * @} + */ + +/** @addtogroup GPIO_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup GPIO_Exported_Functions + * @{ + */ + +void GPIO_DeInit(GPIO_Module* GPIOx); +void GPIO_DeInitPin(GPIO_Module* GPIOx, uint32_t GPIO_Pin); +void GPIO_AFIOInitDefault(void); +void GPIO_InitPeripheral(GPIO_Module* GPIOx, GPIO_InitType* GPIO_InitStruct); +void GPIO_InitStruct(GPIO_InitType* GPIO_InitStruct); +uint8_t GPIO_ReadInputDataBit(GPIO_Module* GPIOx, uint16_t Pin); +uint16_t GPIO_ReadInputData(GPIO_Module* GPIOx); +uint8_t GPIO_ReadOutputDataBit(GPIO_Module* GPIOx, uint16_t Pin); +uint16_t GPIO_ReadOutputData(GPIO_Module* GPIOx); +void GPIO_SetBits(GPIO_Module* GPIOx, uint16_t Pin); +void GPIO_ResetBits(GPIO_Module* GPIOx, uint16_t Pin); +void GPIO_WriteBit(GPIO_Module* GPIOx, uint16_t Pin, Bit_OperateType BitCmd); +void GPIO_Write(GPIO_Module* GPIOx, uint16_t PortVal); +void GPIO_TogglePin(GPIO_Module* GPIOx, uint16_t Pin); +void GPIO_ConfigPinLock(GPIO_Module* GPIOx, uint16_t Pin); + +void GPIO_ConfigEXTILine(uint8_t PortSource, uint8_t PinSource); +void GPIO_ConfigPinRemap(uint8_t PortSource, uint8_t PinSource, uint32_t AlternateFunction); +void AFIO_ConfigSPINSSMode(uint32_t AFIO_SPIx_NSS, uint32_t SpiNssMode); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_i2c.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_i2c.h new file mode 100644 index 0000000..ebaf9ff --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_i2c.h @@ -0,0 +1,690 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_i2c.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_I2C_H__ +#define __N32WB03X_I2C_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup I2C + * @{ + */ + +/** @addtogroup I2C_Exported_Types + * @{ + */ + +/** + * @brief I2C Init structure definition + */ + +typedef struct +{ + uint32_t ClkSpeed; /*!< Specifies the clock frequency. + This parameter must be set to a value lower than 400kHz */ + + uint16_t BusMode; /*!< Specifies the I2C mode. + This parameter can be a value of @ref I2C_BusMode */ + + uint16_t FmDutyCycle; /*!< Specifies the I2C fast mode duty cycle. + This parameter can be a value of @ref I2C_duty_cycle_in_fast_mode */ + + uint16_t OwnAddr1; /*!< Specifies the first device own address. + This parameter can be a 7-bit or 10-bit address. */ + + uint16_t AckEnable; /*!< Enables or disables the acknowledgement. + This parameter can be a value of @ref I2C_acknowledgement */ + + uint16_t AddrMode; /*!< Specifies if 7-bit or 10-bit address is acknowledged. + This parameter can be a value of @ref I2C_acknowledged_address */ +} I2C_InitType; + +/** + * @} + */ + +/** @addtogroup I2C_Exported_Constants + * @{ + */ + +#define IS_I2C_PERIPH(PERIPH) ((PERIPH) == I2C1) +/** @addtogroup I2C_BusMode + * @{ + */ + +#define I2C_BUSMODE_I2C ((uint16_t)0x0000) +#define I2C_BUSMODE_SMBDEVICE ((uint16_t)0x0002) +#define I2C_BUSMODE_SMBHOST ((uint16_t)0x000A) +#define IS_I2C_BUS_MODE(MODE) \ + (((MODE) == I2C_BUSMODE_I2C) || ((MODE) == I2C_BUSMODE_SMBDEVICE) || ((MODE) == I2C_BUSMODE_SMBHOST)) +/** + * @} + */ + +/** @addtogroup I2C_duty_cycle +* @{ +*/ + +#define I2C_FMDUTYCYCLE_16_9 ((uint16_t)0xC000) /*!< I2C duty Tlow/Thigh = 16/9 */ +#define I2C_FMDUTYCYCLE_2 ((uint16_t)0x8000) /*!< I2C duty Tlow/Thigh = 2 */ +#define I2C_FMDUTYCYCLE_1 ((uint16_t)0x0000) /*!< I2C duty Tlow/Thigh = 1 */ +#define IS_I2C_FM_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_FMDUTYCYCLE_16_9) || ((CYCLE) == I2C_FMDUTYCYCLE_2) || ((CYCLE) == I2C_FMDUTYCYCLE_1)) +/** + * @} + */ + +/** @addtogroup I2C_acknowledgement + * @{ + */ + +#define I2C_ACKEN ((uint16_t)0x0400) +#define I2C_ACKDIS ((uint16_t)0x0000) +#define IS_I2C_ACK_STATE(STATE) (((STATE) == I2C_ACKEN) || ((STATE) == I2C_ACKDIS)) +/** + * @} + */ + +/** @addtogroup I2C_transfer_direction + * @{ + */ + +#define I2C_DIRECTION_SEND ((uint8_t)0x00) +#define I2C_DIRECTION_RECV ((uint8_t)0x01) +#define IS_I2C_DIRECTION(DIRECTION) (((DIRECTION) == I2C_DIRECTION_SEND) || ((DIRECTION) == I2C_DIRECTION_RECV)) +/** + * @} + */ + +/** @addtogroup I2C_acknowledged_address + * @{ + */ + +#define I2C_ADDR_MODE_7BIT ((uint16_t)0x4000) +#define I2C_ADDR_MODE_10BIT ((uint16_t)0xC000) +#define IS_I2C_ADDR_MODE(ADDRESS) (((ADDRESS) == I2C_ADDR_MODE_7BIT) || ((ADDRESS) == I2C_ADDR_MODE_10BIT)) +/** + * @} + */ + +/** @addtogroup I2C_registers + * @{ + */ + +#define I2C_REG_CTRL1 ((uint8_t)0x00) +#define I2C_REG_CTRL2 ((uint8_t)0x04) +#define I2C_REG_OADDR1 ((uint8_t)0x08) +#define I2C_REG_OADDR2 ((uint8_t)0x0C) +#define I2C_REG_DAT ((uint8_t)0x10) +#define I2C_REG_STS1 ((uint8_t)0x14) +#define I2C_REG_STS2 ((uint8_t)0x18) +#define I2C_REG_CLKCTRL ((uint8_t)0x1C) +#define I2C_REG_TMRISE ((uint8_t)0x20) +#define IS_I2C_REG(REGISTER) \ + (((REGISTER) == I2C_REG_CTRL1) || ((REGISTER) == I2C_REG_CTRL2) || ((REGISTER) == I2C_REG_OADDR1) \ + || ((REGISTER) == I2C_REG_OADDR2) || ((REGISTER) == I2C_REG_DAT) || ((REGISTER) == I2C_REG_STS1) \ + || ((REGISTER) == I2C_REG_STS2) || ((REGISTER) == I2C_REG_CLKCTRL) || ((REGISTER) == I2C_REG_TMRISE)) +/** + * @} + */ + +/** @addtogroup I2C_SMBus_alert_pin_level + * @{ + */ + +#define I2C_SMBALERT_LOW ((uint16_t)0x2000) +#define I2C_SMBALERT_HIGH ((uint16_t)0xDFFF) +#define IS_I2C_SMB_ALERT(ALERT) (((ALERT) == I2C_SMBALERT_LOW) || ((ALERT) == I2C_SMBALERT_HIGH)) +/** + * @} + */ + +/** @addtogroup I2C_PEC_position + * @{ + */ + +#define I2C_PEC_POS_NEXT ((uint16_t)0x0800) +#define I2C_PEC_POS_CURRENT ((uint16_t)0xF7FF) +#define IS_I2C_PEC_POS(POSITION) (((POSITION) == I2C_PEC_POS_NEXT) || ((POSITION) == I2C_PEC_POS_CURRENT)) +/** + * @} + */ + +/** @addtogroup I2C_NCAK_position + * @{ + */ + +#define I2C_NACK_POS_NEXT ((uint16_t)0x0800) +#define I2C_NACK_POS_CURRENT ((uint16_t)0xF7FF) +#define IS_I2C_NACK_POS(POSITION) (((POSITION) == I2C_NACK_POS_NEXT) || ((POSITION) == I2C_NACK_POS_CURRENT)) +/** + * @} + */ + +/** @addtogroup I2C_interrupts_definition + * @{ + */ + +#define I2C_INT_BUF ((uint16_t)0x0400) +#define I2C_INT_EVENT ((uint16_t)0x0200) +#define I2C_INT_ERR ((uint16_t)0x0100) +#define IS_I2C_CFG_INT(IT) ((((IT) & (uint16_t)0xF8FF) == 0x00) && ((IT) != 0x00)) +/** + * @} + */ + +/** @addtogroup I2C_interrupts_definition + * @{ + */ + +#define I2C_INT_SMBALERT ((uint32_t)0x01008000) +#define I2C_INT_TIMOUT ((uint32_t)0x01004000) +#define I2C_INT_PECERR ((uint32_t)0x01001000) +#define I2C_INT_OVERRUN ((uint32_t)0x01000800) +#define I2C_INT_ACKFAIL ((uint32_t)0x01000400) +#define I2C_INT_ARLOST ((uint32_t)0x01000200) +#define I2C_INT_BUSERR ((uint32_t)0x01000100) +#define I2C_INT_TXDATE ((uint32_t)0x06000080) +#define I2C_INT_RXDATNE ((uint32_t)0x06000040) +#define I2C_INT_STOPF ((uint32_t)0x02000010) +#define I2C_INT_ADDR10F ((uint32_t)0x02000008) +#define I2C_INT_BYTEF ((uint32_t)0x02000004) +#define I2C_INT_ADDRF ((uint32_t)0x02000002) +#define I2C_INT_STARTBF ((uint32_t)0x02000001) + +#define IS_I2C_CLR_INT(IT) ((((IT) & (uint16_t)0x20FF) == 0x00) && ((IT) != (uint16_t)0x00)) + +#define IS_I2C_GET_INT(IT) \ + (((IT) == I2C_INT_SMBALERT) || ((IT) == I2C_INT_TIMOUT) || ((IT) == I2C_INT_PECERR) || ((IT) == I2C_INT_OVERRUN) \ + || ((IT) == I2C_INT_ACKFAIL) || ((IT) == I2C_INT_ARLOST) || ((IT) == I2C_INT_BUSERR) || ((IT) == I2C_INT_TXDATE) \ + || ((IT) == I2C_INT_RXDATNE) || ((IT) == I2C_INT_STOPF) || ((IT) == I2C_INT_ADDR10F) || ((IT) == I2C_INT_BYTEF) \ + || ((IT) == I2C_INT_ADDRF) || ((IT) == I2C_INT_STARTBF)) +/** + * @} + */ + +/** @addtogroup I2C_flags_definition + * @{ + */ + +/** + * @brief STS2 register flags + */ + +#define I2C_FLAG_DUALFLAG ((uint32_t)0x00800000) +#define I2C_FLAG_SMBHADDR ((uint32_t)0x00400000) +#define I2C_FLAG_SMBDADDR ((uint32_t)0x00200000) +#define I2C_FLAG_GCALLADDR ((uint32_t)0x00100000) +#define I2C_FLAG_TRF ((uint32_t)0x00040000) +#define I2C_FLAG_BUSY ((uint32_t)0x00020000) +#define I2C_FLAG_MSMODE ((uint32_t)0x00010000) + +/** + * @brief STS1 register flags + */ + +#define I2C_FLAG_SMBALERT ((uint32_t)0x10008000) +#define I2C_FLAG_TIMOUT ((uint32_t)0x10004000) +#define I2C_FLAG_PECERR ((uint32_t)0x10001000) +#define I2C_FLAG_OVERRUN ((uint32_t)0x10000800) +#define I2C_FLAG_ACKFAIL ((uint32_t)0x10000400) +#define I2C_FLAG_ARLOST ((uint32_t)0x10000200) +#define I2C_FLAG_BUSERR ((uint32_t)0x10000100) +#define I2C_FLAG_TXDATE ((uint32_t)0x10000080) +#define I2C_FLAG_RXDATNE ((uint32_t)0x10000040) +#define I2C_FLAG_STOPF ((uint32_t)0x10000010) +#define I2C_FLAG_ADDR10F ((uint32_t)0x10000008) +#define I2C_FLAG_BYTEF ((uint32_t)0x10000004) +#define I2C_FLAG_ADDRF ((uint32_t)0x10000002) +#define I2C_FLAG_STARTBF ((uint32_t)0x10000001) + +#define IS_I2C_CLR_FLAG(FLAG) ((((FLAG) & (uint16_t)0x20FF) == 0x00) && ((FLAG) != (uint16_t)0x00)) + +#define IS_I2C_GET_FLAG(FLAG) \ + (((FLAG) == I2C_FLAG_DUALFLAG) || ((FLAG) == I2C_FLAG_SMBHADDR) || ((FLAG) == I2C_FLAG_SMBDADDR) \ + || ((FLAG) == I2C_FLAG_GCALLADDR) || ((FLAG) == I2C_FLAG_TRF) || ((FLAG) == I2C_FLAG_BUSY) \ + || ((FLAG) == I2C_FLAG_MSMODE) || ((FLAG) == I2C_FLAG_SMBALERT) || ((FLAG) == I2C_FLAG_TIMOUT) \ + || ((FLAG) == I2C_FLAG_PECERR) || ((FLAG) == I2C_FLAG_OVERRUN) || ((FLAG) == I2C_FLAG_ACKFAIL) \ + || ((FLAG) == I2C_FLAG_ARLOST) || ((FLAG) == I2C_FLAG_BUSERR) || ((FLAG) == I2C_FLAG_TXDATE) \ + || ((FLAG) == I2C_FLAG_RXDATNE) || ((FLAG) == I2C_FLAG_STOPF) || ((FLAG) == I2C_FLAG_ADDR10F) \ + || ((FLAG) == I2C_FLAG_BYTEF) || ((FLAG) == I2C_FLAG_ADDRF) || ((FLAG) == I2C_FLAG_STARTBF)) +/** + * @} + */ + +/** @addtogroup I2C_Events + * @{ + */ + +/*======================================== + + I2C Master Events (Events grouped in order of communication) + ==========================================*/ +/** + * @brief Communication start + * + * After sending the START condition (I2C_GenerateStart() function) the master + * has to wait for this event. It means that the Start condition has been correctly + * released on the I2C bus (the bus is free, no other devices is communicating). + * + */ +/* --EV5 */ +#define I2C_EVT_MASTER_MODE_FLAG ((uint32_t)0x00030001) /* BUSY, MSL and SB flag */ + +/** + * @brief Address Acknowledge + * + * After checking on EV5 (start condition correctly released on the bus), the + * master sends the address of the slave(s) with which it will communicate + * (I2C_SendAddr7bit() function, it also determines the direction of the communication: + * Master transmitter or Receiver). Then the master has to wait that a slave acknowledges + * his address. If an acknowledge is sent on the bus, one of the following events will + * be set: + * + * 1) In case of Master Receiver (7-bit addressing): the I2C_EVT_MASTER_RXMODE_FLAG + * event is set. + * + * 2) In case of Master Transmitter (7-bit addressing): the I2C_EVT_MASTER_TXMODE_FLAG + * is set + * + * 3) In case of 10-Bit addressing mode, the master (just after generating the START + * and checking on EV5) has to send the header of 10-bit addressing mode (I2C_SendData() + * function). Then master should wait on EV9. It means that the 10-bit addressing + * header has been correctly sent on the bus. Then master should send the second part of + * the 10-bit address (LSB) using the function I2C_SendAddr7bit(). Then master + * should wait for event EV6. + * + */ + +/* --EV6 */ +#define I2C_EVT_MASTER_TXMODE_FLAG ((uint32_t)0x00070082) /* BUSY, MSL, ADDR, TXE and TRA flags */ +#define I2C_EVT_MASTER_RXMODE_FLAG ((uint32_t)0x00030002) /* BUSY, MSL and ADDR flags */ +/* --EV9 */ +#define I2C_EVT_MASTER_MODE_ADDRESS10_FLAG ((uint32_t)0x00030008) /* BUSY, MSL and ADD10 flags */ + +/** + * @brief Communication events + * + * If a communication is established (START condition generated and slave address + * acknowledged) then the master has to check on one of the following events for + * communication procedures: + * + * 1) Master Receiver mode: The master has to wait on the event EV7 then to read + * the data received from the slave (I2C_RecvData() function). + * + * 2) Master Transmitter mode: The master has to send data (I2C_SendData() + * function) then to wait on event EV8 or EV8_2. + * These two events are similar: + * - EV8 means that the data has been written in the data register and is + * being shifted out. + * - EV8_2 means that the data has been physically shifted out and output + * on the bus. + * In most cases, using EV8 is sufficient for the application. + * Using EV8_2 leads to a slower communication but ensure more reliable test. + * EV8_2 is also more suitable than EV8 for testing on the last data transmission + * (before Stop condition generation). + * + * @note In case the user software does not guarantee that this event EV7 is + * managed before the current byte end of transfer, then user may check on EV7 + * and BTF flag at the same time (ie. (I2C_EVT_MASTER_DATA_RECVD_FLAG | I2C_FLAG_BYTEF)). + * In this case the communication may be slower. + * + */ + +/* Master RECEIVER mode -----------------------------*/ +/* --EV7 */ +#define I2C_EVT_MASTER_DATA_RECVD_FLAG ((uint32_t)0x00030040) /* BUSY, MSL and RXNE flags */ +#define I2C_EVT_MASTER_DATA_RECVD_BSF_FLAG ((uint32_t)0x00030044) /* BUSY, MSL ,BSF and RXNE flags */ + +/* Master TRANSMITTER mode --------------------------*/ +/* --EV8 */ +#define I2C_EVT_MASTER_DATA_SENDING ((uint32_t)0x00070080) /* TRA, BUSY, MSL, TXE flags */ +/* --EV8_2 */ +#define I2C_EVT_MASTER_DATA_SENDED ((uint32_t)0x00070084) /* TRA, BUSY, MSL, TXE and BTF flags */ + +/*======================================== + + I2C Slave Events (Events grouped in order of communication) + ==========================================*/ + +/** + * @brief Communication start events + * + * Wait on one of these events at the start of the communication. It means that + * the I2C peripheral detected a Start condition on the bus (generated by master + * device) followed by the peripheral address. The peripheral generates an ACK + * condition on the bus (if the acknowledge feature is enabled through function + * I2C_ConfigAck()) and the events listed above are set : + * + * 1) In normal case (only one address managed by the slave), when the address + * sent by the master matches the own address of the peripheral (configured by + * OwnAddr1 field) the I2C_EVENT_SLAVE_XXX_ADDRESS_MATCHED event is set + * (where XXX could be TRANSMITTER or RECEIVER). + * + * 2) In case the address sent by the master matches the second address of the + * peripheral (configured by the function I2C_ConfigOwnAddr2() and enabled + * by the function I2C_EnableDualAddr()) the events I2C_EVENT_SLAVE_XXX_SECONDADDRESS_MATCHED + * (where XXX could be TRANSMITTER or RECEIVER) are set. + * + * 3) In case the address sent by the master is General Call (address 0x00) and + * if the General Call is enabled for the peripheral (using function I2C_EnableGeneralCall()) + * the following event is set I2C_EVT_SLAVE_GCALLADDR_MATCHED. + * + */ + +/* --EV1 (all the events below are variants of EV1) */ +/* 1) Case of One Single Address managed by the slave */ +#define I2C_EVT_SLAVE_RECV_ADDR_MATCHED ((uint32_t)0x00020002) /* BUSY and ADDR flags */ +#define I2C_EVT_SLAVE_SEND_ADDR_MATCHED ((uint32_t)0x00060082) /* TRA, BUSY, TXE and ADDR flags */ + +/* 2) Case of Dual address managed by the slave */ +#define I2C_EVT_SLAVE_RECV_ADDR2_MATCHED ((uint32_t)0x00820000) /* DUALF and BUSY flags */ +#define I2C_EVT_SLAVE_SEND_ADDR2_MATCHED ((uint32_t)0x00860080) /* DUALF, TRA, BUSY and TXE flags */ + +/* 3) Case of General Call enabled for the slave */ +#define I2C_EVT_SLAVE_GCALLADDR_MATCHED ((uint32_t)0x00120000) /* GENCALL and BUSY flags */ + +/** + * @brief Communication events + * + * Wait on one of these events when EV1 has already been checked and: + * + * - Slave RECEIVER mode: + * - EV2: When the application is expecting a data byte to be received. + * - EV4: When the application is expecting the end of the communication: master + * sends a stop condition and data transmission is stopped. + * + * - Slave Transmitter mode: + * - EV3: When a byte has been transmitted by the slave and the application is expecting + * the end of the byte transmission. The two events I2C_EVT_SLAVE_DATA_SENDED and + * I2C_EVT_SLAVE_DATA_SENDING are similar. The second one can optionally be + * used when the user software doesn't guarantee the EV3 is managed before the + * current byte end of transfer. + * - EV3_2: When the master sends a NACK in order to tell slave that data transmission + * shall end (before sending the STOP condition). In this case slave has to stop sending + * data bytes and expect a Stop condition on the bus. + * + * @note In case the user software does not guarantee that the event EV2 is + * managed before the current byte end of transfer, then user may check on EV2 + * and BTF flag at the same time (ie. (I2C_EVT_SLAVE_DATA_RECVD | I2C_FLAG_BYTEF)). + * In this case the communication may be slower. + * + */ + +/* Slave RECEIVER mode --------------------------*/ +/* --EV2 */ +#define I2C_EVT_SLAVE_DATA_RECVD ((uint32_t)0x00020040) /* BUSY and RXNE flags */ +#define I2C_EVT_SLAVE_DATA_RECVD_BSF ((uint32_t)0x00020044) /* BUSY ,BSF and RXNE flags */ +/* --EV4 */ +#define I2C_EVT_SLAVE_STOP_RECVD ((uint32_t)0x00000010) /* STOPF flag */ + +/* Slave TRANSMITTER mode -----------------------*/ +/* --EV3 */ +#define I2C_EVT_SLAVE_DATA_SENDED ((uint32_t)0x00060084) /* TRA, BUSY, TXE and BTF flags */ +#define I2C_EVT_SLAVE_DATA_SENDING ((uint32_t)0x00060080) /* TRA, BUSY and TXE flags */ +/* --EV3_2 */ +#define I2C_EVT_SLAVE_ACK_MISS ((uint32_t)0x00000400) /* AF flag */ + +/*=========================== End of Events Description ==========================================*/ + +#define IS_I2C_EVT(EVENT) \ + (((EVENT) == I2C_EVT_SLAVE_SEND_ADDR_MATCHED) || ((EVENT) == I2C_EVT_SLAVE_RECV_ADDR_MATCHED) \ + || ((EVENT) == I2C_EVT_SLAVE_SEND_ADDR2_MATCHED) || ((EVENT) == I2C_EVT_SLAVE_RECV_ADDR2_MATCHED) \ + || ((EVENT) == I2C_EVT_SLAVE_GCALLADDR_MATCHED) || ((EVENT) == I2C_EVT_SLAVE_DATA_RECVD) \ + || ((EVENT) == I2C_EVT_SLAVE_DATA_RECVD_BSF) \ + || ((EVENT) == (I2C_EVT_SLAVE_DATA_RECVD | I2C_FLAG_DUALFLAG)) \ + || ((EVENT) == (I2C_EVT_SLAVE_DATA_RECVD | I2C_FLAG_GCALLADDR)) || ((EVENT) == I2C_EVT_SLAVE_DATA_SENDED) \ + || ((EVENT) == (I2C_EVT_SLAVE_DATA_SENDED | I2C_FLAG_DUALFLAG)) \ + || ((EVENT) == (I2C_EVT_SLAVE_DATA_SENDED | I2C_FLAG_GCALLADDR)) || ((EVENT) == I2C_EVT_SLAVE_STOP_RECVD) \ + || ((EVENT) == I2C_EVT_MASTER_MODE_FLAG) || ((EVENT) == I2C_EVT_MASTER_TXMODE_FLAG) \ + || ((EVENT) == I2C_EVT_MASTER_DATA_RECVD_BSF_FLAG) \ + || ((EVENT) == I2C_EVT_MASTER_RXMODE_FLAG) || ((EVENT) == I2C_EVT_MASTER_DATA_RECVD_FLAG) \ + || ((EVENT) == I2C_EVT_MASTER_DATA_SENDED) || ((EVENT) == I2C_EVT_MASTER_DATA_SENDING) \ + || ((EVENT) == I2C_EVT_MASTER_MODE_ADDRESS10_FLAG) || ((EVENT) == I2C_EVT_SLAVE_ACK_MISS)) +/** + * @} + */ + +/** @addtogroup I2C_own_address1 + * @{ + */ + +#define IS_I2C_OWN_ADDR1(ADDRESS1) ((ADDRESS1) <= 0x3FF) +/** + * @} + */ + +/** @addtogroup I2C_clock_speed + * @{ + */ + +#define IS_I2C_CLK_SPEED(SPEED) (((SPEED) >= 0x1) && ((SPEED) <= 1000000)) + +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup I2C_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup I2C_Exported_Functions + * @{ + */ + +void I2C_DeInit(I2C_Module* I2Cx); +void I2C_Init(I2C_Module* I2Cx, I2C_InitType* I2C_InitStruct); +void I2C_InitStruct(I2C_InitType* I2C_InitStruct); +void I2C_Enable(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_EnableDMA(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_EnableDmaLastSend(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_GenerateStart(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_GenerateStop(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_ConfigAck(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_ConfigOwnAddr2(I2C_Module* I2Cx, uint8_t Address); +void I2C_EnableDualAddr(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_EnableGeneralCall(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_ConfigInt(I2C_Module* I2Cx, uint16_t I2C_IT, FunctionalState Cmd); +void I2C_SendData(I2C_Module* I2Cx, uint8_t Data); +uint8_t I2C_RecvData(I2C_Module* I2Cx); +void I2C_SendAddr7bit(I2C_Module* I2Cx, uint8_t Address, uint8_t I2C_Direction); +uint16_t I2C_GetRegister(I2C_Module* I2Cx, uint8_t I2C_Register); +void I2C_EnableSoftwareReset(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_ConfigNackLocation(I2C_Module* I2Cx, uint16_t I2C_NACKPosition); +void I2C_ConfigSmbusAlert(I2C_Module* I2Cx, uint16_t I2C_SMBusAlert); +void I2C_SendPEC(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_ConfigPecLocation(I2C_Module* I2Cx, uint16_t I2C_PECPosition); +void I2C_ComputePec(I2C_Module* I2Cx, FunctionalState Cmd); +uint8_t I2C_GetPec(I2C_Module* I2Cx); +void I2C_EnableArp(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_EnableExtendClk(I2C_Module* I2Cx, FunctionalState Cmd); +void I2C_ConfigFastModeDutyCycle(I2C_Module* I2Cx, uint16_t FmDutyCycle); + +/** + * @brief + **************************************************************************************** + * + * I2C State Monitoring Functions + * + **************************************************************************************** + * This I2C driver provides three different ways for I2C state monitoring + * depending on the application requirements and constraints: + * + * + * 1) Basic state monitoring: + * Using I2C_CheckEvent() function: + * It compares the status registers (STS1 and STS2) content to a given event + * (can be the combination of one or more flags). + * It returns SUCCESS if the current status includes the given flags + * and returns ERROR if one or more flags are missing in the current status. + * - When to use: + * - This function is suitable for most applications as well as for startup + * activity since the events are fully described in the product reference manual + * (RM0008). + * - It is also suitable for users who need to define their own events. + * - Limitations: + * - If an error occurs (ie. error flags are set besides to the monitored flags), + * the I2C_CheckEvent() function may return SUCCESS despite the communication + * hold or corrupted real state. + * In this case, it is advised to use error interrupts to monitor the error + * events and handle them in the interrupt IRQ handler. + * + * @note + * For error management, it is advised to use the following functions: + * - I2C_ConfigInt() to configure and enable the error interrupts (I2C_INT_ERR). + * - I2Cx_ER_IRQHandler() which is called when the error interrupt occurs. + * Where x is the peripheral instance (I2C1, I2C2 ...) + * - I2C_GetFlag() or I2C_GetIntStatus() to be called into I2Cx_ER_IRQHandler() + * in order to determine which error occurred. + * - I2C_ClrFlag() or I2C_ClrIntPendingBit() and/or I2C_EnableSoftwareReset() + * and/or I2C_GenerateStop() in order to clear the error flag and source, + * and return to correct communication status. + * + * + * 2) Advanced state monitoring: + * Using the function I2C_GetLastEvent() which returns the image of both status + * registers in a single word (uint32_t) (Status Register 2 value is shifted left + * by 16 bits and concatenated to Status Register 1). + * - When to use: + * - This function is suitable for the same applications above but it allows to + * overcome the limitations of I2C_GetFlag() function (see below). + * The returned value could be compared to events already defined in the + * library (n32wb03x_i2c.h) or to custom values defined by user. + * - This function is suitable when multiple flags are monitored at the same time. + * - At the opposite of I2C_CheckEvent() function, this function allows user to + * choose when an event is accepted (when all events flags are set and no + * other flags are set or just when the needed flags are set like + * I2C_CheckEvent() function). + * - Limitations: + * - User may need to define his own events. + * - Same remark concerning the error management is applicable for this + * function if user decides to check only regular communication flags (and + * ignores error flags). + * + * + * 3) Flag-based state monitoring: + * Using the function I2C_GetFlag() which simply returns the status of + * one single flag (ie. I2C_FLAG_RXDATNE ...). + * - When to use: + * - This function could be used for specific applications or in debug phase. + * - It is suitable when only one flag checking is needed (most I2C events + * are monitored through multiple flags). + * - Limitations: + * - When calling this function, the Status register is accessed. Some flags are + * cleared when the status register is accessed. So checking the status + * of one Flag, may clear other ones. + * - Function may need to be called twice or more in order to monitor one + * single event. + * + */ + +/** + * + * 1) Basic state monitoring + ******************************************************************************* + */ +ErrorStatus I2C_CheckEvent(I2C_Module* I2Cx, uint32_t I2C_EVENT); +/** + * + * 2) Advanced state monitoring + ******************************************************************************* + */ +uint32_t I2C_GetLastEvent(I2C_Module* I2Cx); +/** + * + * 3) Flag-based state monitoring + ******************************************************************************* + */ +FlagStatus I2C_GetFlag(I2C_Module* I2Cx, uint32_t I2C_FLAG); +/** + * + ******************************************************************************* + */ + +void I2C_ClrFlag(I2C_Module* I2Cx, uint32_t I2C_FLAG); +INTStatus I2C_GetIntStatus(I2C_Module* I2Cx, uint32_t I2C_IT); +void I2C_ClrIntPendingBit(I2C_Module* I2Cx, uint32_t I2C_IT); + +#ifdef __cplusplus +} +#endif + +#endif /*__N32WB03X_I2C_H */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_irgen.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_irgen.h new file mode 100644 index 0000000..969868d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_irgen.h @@ -0,0 +1,324 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_irgen.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03x_IRGEN_H__ +#define __N32WB03x_IRGEN_H__ + +#include +#include +#include + +/** + * \brief IR logic bit format + * + */ +typedef enum { + HW_IRGEN_LOGIC_FORMAT_MARK = 0, /**< logic bit starts with mark followed by space */ + HW_IRGEN_LOGIC_FORMAT_SPACE = 1 /**< logic bit starts with space followed by mark */ +} HW_IRGEN_LOGIC_FORMAT; + +/** + * \brief IR FIFO + * + */ +typedef enum { + HW_IRGEN_FIFO_CODE = 0, /**< code FIFO */ + HW_IRGEN_FIFO_REPEAT = 1 /**< repeat FIFO */ +} HW_IRGEN_FIFO; + +/** + * \brief Paint symbol + * + */ +typedef enum { + HW_IRGEN_PAINT_SPACE = 0, /**< space */ + HW_IRGEN_PAINT_MARK = 1 /**< mark */ +} HW_IRGEN_PAINT; + +/** + * \brief IR generator output mode + * + */ +typedef enum { + HW_IRGEN_OUTPUT_NORMAL = 0, /**< output is not inverted */ + HW_IRGEN_OUTPUT_INVERTED = 1 /**< output is inverted */ +} HW_IRGEN_OUTPUT; + +/** + * \brief Set carrier frequency + * + * \param [in] hi_time carrier signal high duration in IR clock cycles (must be >0) + * \param [in] lo_time carrier signal low duration in IR clock cycles (must be >0) + * + */ +static __INLINE void hw_irgen_set_carrier_freq(uint16_t hi_time, uint16_t lo_time) +{ + IRC->FREQ_CARRIER_ON = hi_time; + IRC->FREQ_CARRIER_OFF = lo_time; +} + +/** + * \brief Set "logic 0" parameters + * + * \param [in] format "logic 0" format + * \param [in] mark_time mark duration in carrier clock cycles (must be >0) + * \param [in] space_time space duration in carrier clock cycles (must be >0) + * + * \sa hw_ir_insert_digital_message + */ +static __INLINE void hw_irgen_set_logic0_param(HW_IRGEN_LOGIC_FORMAT format, uint8_t mark_time, + uint8_t space_time) +{ + IRC->LOGIC_ZERO_TIME = (uint16_t)(mark_time << IR_LOGIC_ZERO_TIME_LOGIC_ZERO_MARK_Pos | space_time); + IRC->CTRL = ((IRC->CTRL & ~(IR_CTRL_LOGIC_ZERO_FORMAT_Msk)) | \ + ((IR_CTRL_LOGIC_ZERO_FORMAT_Msk) & ((format) << (IR_CTRL_LOGIC_ZERO_FORMAT_Pos)))); +} + +/** + * \brief Set "logic 1" parameters + * + * \param [in] format "logic 1" format + * \param [in] mark_time mark duration in carrier clock cycles (must be >0) + * \param [in] space_time space duration in carrier clock cycles (must be >0) + * + * \sa hw_ir_insert_digital_message + */ +static __INLINE void hw_irgen_set_logic1_param(HW_IRGEN_LOGIC_FORMAT format, uint8_t mark_time, + uint8_t space_time) +{ + IRC->LOGIC_ONE_TIME = (uint16_t)(mark_time << IR_LOGIC_ONE_TIME_LOGIC_ONE_MARK_Pos | space_time); + IRC->CTRL = ((IRC->CTRL & ~(IR_CTRL_LOGIC_ONE_FORMAT_Msk)) | \ + ((IR_CTRL_LOGIC_ONE_FORMAT_Msk) & ((format) << (IR_CTRL_LOGIC_ONE_FORMAT_Pos)))); +} + +/** + * \brief Set command repeat time + * + * \param [in] time repeat time in carrier clock cycles + * + * \sa hw_irgen_set_repeat_type + * + */ +static __INLINE void hw_irgen_set_repeat_time(uint16_t time) +{ + IRC->REPEAT_TIME = time; +} + +/** + * \brief Insert Digital message into FIFO + * + * Digital message is represented by \p payload as sequence of "logic 0" and "logic 1". + * + * \param [in] fifo FIFO to be used + * \param [in] length number of valid bits in \p message (must be >0) + * \param [in] payload message content + * + * \sa hw_irgen_set_logic0_format + * \sa hw_irgen_set_logic1_format + * + */ +static __INLINE void hw_irgen_insert_digital_message(HW_IRGEN_FIFO fifo, uint8_t length, uint16_t payload) +{ + /* reg[20] = digital message (1), reg[19:16] = length-1, reg[15:0] = payload */ + uint32_t value = 0x100000 | (((length - 1) & 0xF) << 16) | (payload & 0xFFFF); + if (fifo == HW_IRGEN_FIFO_REPEAT) { + IRC->REPEAT_FIFO = value; + } else { + IRC->CODE_FIFO = value; + } +} + +/** + * \brief Insert Paint message into FIFO + * + * Paint message is represented by either mark or space and its duration. This allows to represent + * any custom "painted" waveform. + * + * \param [in] fifo FIFO to be used + * \param [in] symbol symbol type + * \param [in] duration symbol duration in carrier clock cycles + * + */ +static __INLINE void hw_irgen_insert_paint_message(HW_IRGEN_FIFO fifo, HW_IRGEN_PAINT symbol, uint16_t duration) +{ + /* reg[20] = paint message (0), reg[14] = symbol, reg[13:0] = duration */ + uint16_t value = (!!symbol << 14) | (duration & 0x3FFF); + if (fifo == HW_IRGEN_FIFO_REPEAT) { + IRC->REPEAT_FIFO = value; + } else { + IRC->CODE_FIFO = value; + } +} + +/** + * \brief Flush FIFO + * + * Paint message is represented by either mark or space and its duration. This allows to represent + * any custom "painted" waveform. + * + * \param [in] fifo FIFO to be flushed + * + */ +static __INLINE void hw_irgen_flush_fifo(HW_IRGEN_FIFO fifo) +{ + if (fifo == HW_IRGEN_FIFO_REPEAT) { + IRC->CTRL = ((IRC->CTRL & ~(IR_CTRL_REP_FIFO_RESET_Msk)) | \ + ((IR_CTRL_REP_FIFO_RESET_Msk) & ((1) << (IR_CTRL_REP_FIFO_RESET_Pos)))); + } else { + IRC->CTRL = ((IRC->CTRL & ~(IR_CTRL_CODE_FIFO_RESET_Msk)) | \ + ((IR_CTRL_CODE_FIFO_RESET_Msk) & ((1) << (IR_CTRL_CODE_FIFO_RESET_Pos)))); + } +} + +/** + * \brief Set output type (normal or inverted) + * + * \param [in] output output type + * + */ +static __INLINE void hw_irgen_set_output_type(HW_IRGEN_OUTPUT output) +{ + IRC->CTRL = ((IRC->CTRL & ~(IR_CTRL_INVERT_OUTPUT_Msk)) | \ + ((IR_CTRL_INVERT_OUTPUT_Msk) & ((output) << (IR_CTRL_INVERT_OUTPUT_Pos)))); +} + +/** + * \brief Start IR data transmission + * + */ +static __INLINE void hw_irgen_start(void) +{ + IRC->CTRL = ((IRC->CTRL & ~(IR_CTRL_TX_START_Msk)) | \ + ((IR_CTRL_TX_START_Msk) & ((1) << (IR_CTRL_TX_START_Pos)))); + +} + +/** + * \brief Stop IR data transmission + * + * When called after transmission is started, this will also flush code FIFO. + * + */ +static __INLINE void hw_irgen_stop(void) +{ + IRC->CTRL = ((IRC->CTRL & ~(IR_CTRL_TX_START_Msk)) | \ + ((IR_CTRL_TX_START_Msk) & ((0) << (IR_CTRL_TX_START_Pos)))); +} + +/** + * \brief Check if IR generator is busy + * + * \return true if IR generator is busy, false otherwise + * + */ +static __INLINE bool hw_irgen_is_busy(void) +{ + return ((IRC->STATUS) & (IR_STATUS_BUSY)); +} + +/** + * \brief Get number of messages in FIFO + * + * \param [in] fifo FIFO + * + * \return number of messages + * + */ +static __INLINE uint16_t hw_irgen_get_fifo_level(HW_IRGEN_FIFO fifo) +{ + if (fifo == HW_IRGEN_FIFO_REPEAT) { + return (((IRC->STATUS) & (IR_STATUS_REP_FIFO_WORDS_Msk)) >> (IR_STATUS_REP_FIFO_WORDS_Pos)); + } else { + return (((IRC->STATUS) & (IR_STATUS_CODE_FIFO_WORDS_Msk)) >> (IR_STATUS_CODE_FIFO_WORDS_Pos)); + } +} + +/** + * \brief Reverse bit order + * + * Helper function to reverse order of bits in message. + * + * \param [in] val message value + * \param [in] bits number of valid bits in \p val + * + * \return \p val with bit order reversed + * + */ +static __INLINE uint16_t hw_irgen_reverse_bit_order(uint16_t val, uint8_t bits) +{ + uint16_t ret = 0; + + while (bits--) { + ret = (ret << 1) | (val & 1); + val >>= 1; + } + + return ret; +} + + +#endif /* __N32WB03x_IRGEN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_iwdg.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_iwdg.h new file mode 100644 index 0000000..1f3d6c1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_iwdg.h @@ -0,0 +1,166 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_iwdg.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IWDG_H__ +#define __N32WB03X_IWDG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup IWDG + * @{ + */ + +/** @addtogroup IWDG_Exported_Types + * @{ + */ + +/** + * @} + */ + +/** @addtogroup IWDG_Exported_Constants + * @{ + */ + +/** @addtogroup IWDG_WriteAccess + * @{ + */ + +#define IWDG_WRITE_ENABLE ((uint16_t)0x5555) +#define IWDG_WRITE_DISABLE ((uint16_t)0x0000) +#define IS_IWDG_WRITE(ACCESS) (((ACCESS) == IWDG_WRITE_ENABLE) || ((ACCESS) == IWDG_WRITE_DISABLE)) +/** + * @} + */ + +/** @addtogroup IWDG_prescaler + * @{ + */ + +#define IWDG_PRESCALER_DIV4 ((uint8_t)0x00) +#define IWDG_PRESCALER_DIV8 ((uint8_t)0x01) +#define IWDG_PRESCALER_DIV16 ((uint8_t)0x02) +#define IWDG_PRESCALER_DIV32 ((uint8_t)0x03) +#define IWDG_PRESCALER_DIV64 ((uint8_t)0x04) +#define IWDG_PRESCALER_DIV128 ((uint8_t)0x05) +#define IWDG_PRESCALER_DIV256 ((uint8_t)0x06) +#define IS_IWDG_PRESCALER_DIV(PRESCALER) \ + (((PRESCALER) == IWDG_PRESCALER_DIV4) || ((PRESCALER) == IWDG_PRESCALER_DIV8) \ + || ((PRESCALER) == IWDG_PRESCALER_DIV16) || ((PRESCALER) == IWDG_PRESCALER_DIV32) \ + || ((PRESCALER) == IWDG_PRESCALER_DIV64) || ((PRESCALER) == IWDG_PRESCALER_DIV128) \ + || ((PRESCALER) == IWDG_PRESCALER_DIV256)) +/** + * @} + */ + +/** @addtogroup IWDG_Flag + * @{ + */ + +#define IWDG_PVU_FLAG ((uint16_t)0x0001) +#define IWDG_CRVU_FLAG ((uint16_t)0x0002) +#define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_PVU_FLAG) || ((FLAG) == IWDG_CRVU_FLAG)) +#define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup IWDG_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup IWDG_Exported_Functions + * @{ + */ + +void IWDG_WriteConfig(uint16_t IWDG_WriteAccess); +void IWDG_SetPrescalerDiv(uint8_t IWDG_Prescaler); +void IWDG_CntReload(uint16_t Reload); +void IWDG_ReloadKey(void); +void IWDG_Enable(void); +FlagStatus IWDG_GetStatus(uint16_t IWDG_FLAG); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IWDG_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_keyscan.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_keyscan.h new file mode 100644 index 0000000..cbe96bb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_keyscan.h @@ -0,0 +1,214 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_keyscan.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X__KEYSCAN_H__ +#define __N32WB03X__KEYSCAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup n32wb03x_StdPeriph_Driver + * @{ + */ + +/** @addtogroup KEYSCAN + * @{ + */ + +/** @addtogroup KEYSCAN_Exported_Types + * @{ + */ + +/** + * @brief KEYSCAN Init Structure definition + */ +typedef struct +{ + uint32_t Mask; + uint16_t Mode; + uint16_t Wts; + uint16_t Dts; + uint16_t Int_en; + +} KEYSCAN_InitType; + + +/** + * @brief KEYSCAN NUM enumeration + */ +typedef enum +{ + KEY_104, + KEY_44, + KEY_65, +}KEY_NUM; + +/** + * @brief KEYSCAN NUM enumeration + */ +typedef enum +{ + MODE_FIXED_INTV, + MODE_SW_TRIG, + MODE_PRESS_TRIG, +}KEY_MODE; + +/** + * @brief KEYSCAN debounce time enumeration + */ +typedef enum +{ + DTS_10MS, + DTS_20MS, + DTS_40MS, + DTS_80MS, + DTS_160MS, + DTS_320MS, + DTS_640MS, + DTS_640MS_2, +}KEY_DTS; + +/** + * @brief KEYSCAN scan wait time enumeration + */ +typedef enum +{ + WTS_0MS, + WTS_32MS, + WTS_64MS, + WTS_96MS, + WTS_128MS, + WTS_160MS, + WTS_192MS, + WTS_224MS, +}KEY_WTS; + +/** + * @brief KEYSCAN INT trigger enumeration + */ +typedef enum +{ + INT_DIS, + INT_EN, +}KEY_INT_EN; + +/** + * @} + */ + +/** @addtogroup KEYSCAN_Exported_Constants + * @{ + */ + +/** @addtogroup KEYSCAN_Prescaler + * @{ + */ + +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup KEYSCAN_Exported_Macros + * @{ + */ + +#define KEYSCAN_EN_POS 0 +#define KEY_MODE_POS 2 +#define KEY_DTS_POS 4 +#define KEY_WTS_POS 7 +#define KEY_MASK_POS 10 +#define KEY_SW_START_POS 12 +#define KEY_INFO_CLR_POS 13 +#define KEY_INT_EN_POS 22 +#define KEY_IRP_POS 23 + +/** + * @} + */ + +/** @addtogroup KEYSCAN_Exported_Functions + * @{ + */ +void KEYSCAN_Init(KEYSCAN_InitType* KEYSCAN_InitStruct); +void KEYSCAN_Enable(FunctionalState Cmd); +void KEYSCAN_InfoClear(void); +void KEYSCAN_SoftwareStartScan(void); +FlagStatus KEYSCAN_GetInterruptState(void); +void KEYSCAN_ClearInterrupt(void); +void KEYSCAN_ReadKeyData(uint32_t *key_data); +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X__KEYSCAN_H */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_lpuart.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_lpuart.h new file mode 100644 index 0000000..35ebfc6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_lpuart.h @@ -0,0 +1,302 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_lpuart.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_LPUART_H__ +#define __N32WB03X_LPUART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup LPUART + * @{ + */ + +/** @addtogroup LPUART_Exported_Types + * @{ + */ + +/** + * @brief LPUART Init Structure definition + */ + +typedef struct +{ + uint32_t BaudRate; /*!< This member configures the LPUART communication baud rate. + The baud rate is computed using the following formula: + - IntegerDivider = ((CLK) / (LPUART_InitStruct->BaudRate))) + - FractionalDivider */ + + uint16_t Parity; /*!< Specifies the parity mode. + This parameter can be a value of @ref Parity + @note When parity is enabled, the computed parity is inserted + at the MSB position of the transmitted data (only support + 8 data bits). */ + + uint16_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled. + This parameter can be a value of @ref Mode */ + + uint16_t RtsThreshold; /* Specifies RTS Threshold. + This parameter can be a value of @ref RtsThreshold */ + + uint16_t HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled + or disabled. + This parameter can be a value of @ref LPUART_Hardware_Flow_Control */ +} LPUART_InitType; + +/** + * @} + */ + +/** @addtogroup LPUART_Exported_Constants + * @{ + */ + +#define IS_LPUART_ALL_PERIPH(PERIPH) ((PERIPH) == LPUART1) + +/** @addtogroup Parity + * @{ + */ + +#define LPUART_PE_NO ((uint16_t)0x0008) +#define LPUART_PE_EVEN ((uint16_t)0x0000) +#define LPUART_PE_ODD ((uint16_t)0x0001) +#define IS_LPUART_PARITY(PARITY) (((PARITY) == LPUART_PE_NO) || ((PARITY) == LPUART_PE_EVEN) || ((PARITY) == LPUART_PE_ODD)) +/** + * @} + */ + +/** @addtogroup Mode + * @{ + */ + +#define LPUART_MODE_RX ((uint16_t)0x0000) +#define LPUART_MODE_TX ((uint16_t)0x0002) +#define IS_LPUART_MODE(MODE) (((MODE) == LPUART_MODE_RX) || ((MODE) == LPUART_MODE_TX)) +/** + * @} + */ + +/** @addtogroup RtsThreshold + * @{ + */ + +#define LPUART_RTSTH_FIFOHF ((uint16_t)0x0000) +#define LPUART_RTSTH_FIFO3QF ((uint16_t)0x0100) +#define LPUART_RTSTH_FIFOFU ((uint16_t)0x0200) +#define IS_LPUART_RTSTHRESHOLD(RTSTHRESHOLD) \ + (((RTSTHRESHOLD) == LPUART_RTSTH_FIFOHF) || ((RTSTHRESHOLD) == LPUART_RTSTH_FIFO3QF) || ((RTSTHRESHOLD) == LPUART_RTSTH_FIFOFU)) +/** + * @} + */ + +/** @addtogroup Hardware_Flow_Control + * @{ + */ +#define LPUART_HFCTRL_NONE ((uint16_t)0x0000) +#define LPUART_HFCTRL_CTS ((uint16_t)0x0400) +#define LPUART_HFCTRL_RTS ((uint16_t)0x0800) +#define LPUART_HFCTRL_RTS_CTS ((uint16_t)0x0C00) +#define IS_LPUART_HARDWARE_FLOW_CONTROL(CONTROL) \ + (((CONTROL) == LPUART_HFCTRL_NONE) || ((CONTROL) == LPUART_HFCTRL_RTS) || ((CONTROL) == LPUART_HFCTRL_CTS) \ + || ((CONTROL) == LPUART_HFCTRL_RTS_CTS)) +/** + * @} + */ + +/** @addtogroup LPUART_Interrupt_definition + * @{ + */ +#define LPUART_INT_PE ((uint16_t)0x0001) +#define LPUART_INT_TXC ((uint16_t)0x0102) +#define LPUART_INT_FIFO_OV ((uint16_t)0x0204) +#define LPUART_INT_FIFO_FU ((uint16_t)0x0308) +#define LPUART_INT_FIFO_HF ((uint16_t)0x0410) +#define LPUART_INT_FIFO_NE ((uint16_t)0x0520) +#define LPUART_INT_WUF ((uint16_t)0x0680) + +#define IS_LPUART_CFG_INT(IT) \ + (((IT) == LPUART_INT_PE) || ((IT) == LPUART_INT_TXC) || ((IT) == LPUART_INT_FIFO_OV) || ((IT) == LPUART_INT_FIFO_FU) \ + || ((IT) == LPUART_INT_FIFO_HF) || ((IT) == LPUART_INT_FIFO_NE) || ((IT) == LPUART_INT_WUF)) +#define IS_LPUART_GET_INT(IT) \ + (((IT) == LPUART_INT_PE) || ((IT) == LPUART_INT_TXC) || ((IT) == LPUART_INT_FIFO_OV) || ((IT) == LPUART_INT_FIFO_FU) \ + || ((IT) == LPUART_INT_FIFO_HF) || ((IT) == LPUART_INT_FIFO_NE) || ((IT) == LPUART_INT_WUF)) +#define IS_LPUART_CLR_INT(IT) \ + (((IT) == LPUART_INT_PE) || ((IT) == LPUART_INT_TXC) || ((IT) == LPUART_INT_FIFO_OV) || ((IT) == LPUART_INT_FIFO_FU) \ + || ((IT) == LPUART_INT_FIFO_HF) || ((IT) == LPUART_INT_FIFO_NE) || ((IT) == LPUART_INT_WUF)) +/** + * @} + */ + +/** @addtogroup LPUART_DMA_Requests + * @{ + */ + +#define LPUART_DMAREQ_TX ((uint16_t)0x0020) +#define LPUART_DMAREQ_RX ((uint16_t)0x0040) +#define IS_LPUART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF9F) == (uint16_t)0x00) && ((DMAREQ) != (uint16_t)0x00)) + +/** + * @} + */ + +/** @addtogroup LPUART_WakeUp_methods + * @{ + */ + +#define LPUART_WUSTP_STARTBIT ((uint16_t)0x0000) +#define LPUART_WUSTP_RXNE ((uint16_t)0x1000) +#define LPUART_WUSTP_BYTE ((uint16_t)0x2000) +#define LPUART_WUSTP_FRAME ((uint16_t)0x3000) +#define IS_LPUART_WAKEUP(WAKEUP) \ + (((WAKEUP) == LPUART_WUSTP_STARTBIT) || ((WAKEUP) == LPUART_WUSTP_RXNE) || ((WAKEUP) == LPUART_WUSTP_BYTE) || ((WAKEUP) == LPUART_WUSTP_FRAME)) +/** + * @} + */ + +/** @addtogroup LPUART_Sampling_methods + * @{ + */ + +#define LPUART_SMPCNT_3B ((uint16_t)0x0000) +#define LPUART_SMPCNT_1B ((uint16_t)0x4000) +#define IS_LPUART_SAMPLING(SAMPLING) (((SAMPLING) == LPUART_SMPCNT_1B) || ((SAMPLING) == LPUART_SMPCNT_3B)) +/** + * @} + */ + +/** @addtogroup LPUART_Flags + * @{ + */ + +#define LPUART_FLAG_PEF ((uint16_t)0x0001) +#define LPUART_FLAG_TXC ((uint16_t)0x0002) +#define LPUART_FLAG_FIFO_OV ((uint16_t)0x0004) +#define LPUART_FLAG_FIFO_FU ((uint16_t)0x0008) +#define LPUART_FLAG_FIFO_HF ((uint16_t)0x0010) +#define LPUART_FLAG_FIFO_NE ((uint16_t)0x0020) +#define LPUART_FLAG_CTS ((uint16_t)0x0040) +#define LPUART_FLAG_WUF ((uint16_t)0x0080) +#define LPUART_FLAG_NF ((uint16_t)0x0100) +#define IS_LPUART_FLAG(FLAG) \ + (((FLAG) == LPUART_FLAG_PEF) || ((FLAG) == LPUART_FLAG_TXC) || ((FLAG) == LPUART_FLAG_FIFO_OV) \ + || ((FLAG) == LPUART_FLAG_FIFO_FU) || ((FLAG) == LPUART_FLAG_FIFO_HF) || ((FLAG) == LPUART_FLAG_FIFO_NE) \ + || ((FLAG) == LPUART_FLAG_CTS) || ((FLAG) == LPUART_FLAG_WUF) || ((FLAG) == LPUART_FLAG_NF)) + +#define IS_LPUART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFE40) == 0x00) && ((FLAG) != (uint16_t)0x00)) + +#define IS_LPUART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 2000001)) +#define IS_LPUART_DATA(DATA) ((DATA < 0x0100)) + +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup LPUART_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup LPUART_Exported_Functions + * @{ + */ + +void LPUART_DeInit(LPUART_Module* LPUARTx); +void LPUART_Init(LPUART_Module* LPUARTx, LPUART_InitType* LPUART_InitStruct); +void LPUART_StructInit(LPUART_InitType* LPUART_InitStruct); +void LPUART_FlushRxFifo(LPUART_Module* LPUARTx); +void LPUART_ConfigInt(LPUART_Module* LPUARTx, uint16_t LPUART_INT, FunctionalState Cmd); +void LPUART_EnableDMA(LPUART_Module* LPUARTx, uint16_t LPUART_DMAReq, FunctionalState Cmd); +void LPUART_ConfigWakeUpMethod(LPUART_Module* LPUARTx, uint16_t LPUART_WakeUpMethod); +void LPUART_EnableWakeUpStop(LPUART_Module* LPUARTx, FunctionalState Cmd); +void LPUART_ConfigSamplingMethod(LPUART_Module* LPUARTx, uint16_t LPUART_SamplingMethod); +void LPUART_EnableLoopBack(LPUART_Module* LPUARTx, FunctionalState Cmd); +void LPUART_SendData(LPUART_Module* LPUARTx, uint8_t Data); +uint8_t LPUART_ReceiveData(LPUART_Module* LPUARTx); +void LPUART_ConfigWakeUpData(LPUART_Module* LPUARTx, uint32_t LPUART_WakeUpData); +FlagStatus LPUART_GetFlagStatus(LPUART_Module* LPUARTx, uint16_t LPUART_FLAG); +void LPUART_ClrFlag(LPUART_Module* LPUARTx, uint16_t LPUART_FLAG); +INTStatus LPUART_GetIntStatus(LPUART_Module* LPUARTx, uint16_t LPUART_INT); +void LPUART_ClrIntPendingBit(LPUART_Module* LPUARTx, uint16_t LPART_INT); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_LPUART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_pwr.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_pwr.h new file mode 100644 index 0000000..d475812 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_pwr.h @@ -0,0 +1,124 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_pwr.h + * @author NSING Firmware Team + * @version v1.1.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_PWR_H__ +#define __N32WB03X_PWR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** + * @} + */ + +/** @defgroup SLEEP_mode_entry + * @{ + */ +#define PWR_IDLEENTRY_WFI ((uint8_t)0x01) +#define PWR_IDLEENTRY_WFE ((uint8_t)0x02) + + +/** + * @} + */ + + +/** @defgroup SLEEP_mode_entry + * @{ + */ + +#define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) +#define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) + +/** @defgroup Powerdown_mode_entry + * @{ + */ + +#define PWR_PDENTRY_WFI ((uint8_t)0x01) +#define PWR_PDENTRY_WFE ((uint8_t)0x02) + + +/** @addtogroup PWR_Exported_Functions + * @{ + */ + +void PWR_DeInit(void); +void PWR_EnterIDLEMode(uint8_t IDLEONEXIT, uint8_t PWR_IdleEntry); +void PWR_EnterSLEEPMode(uint8_t PWR_SleepEntry); +void PWR_EnterPDMode(uint8_t PWR_PDEntry); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_PWR_H__ */ + /** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_qflash.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_qflash.h new file mode 100644 index 0000000..9bd0a42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_qflash.h @@ -0,0 +1,124 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_qflash.h + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_QFLASH_H__ +#define __N32WB03X_QFLASH_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup QFLASH + * @{ + */ + +/** @addtogroup QFLASH_Defines + * @{ + */ +#define Qflash_Erase_Sector_Raw Qflash_Erase_Sector +#define Qflash_Write_Raw Qflash_Write + +#define FLASH_PAGE_SIZE 0x100 +#define FLASH_SECTOR_SIZE 0x1000 + + +/** + * @} + */ + +/** @addtogroup QFLASH_ReturnMsg + * @{ + */ +typedef enum{ + FlashOperationSuccess, + FlashWriteRegFailed, + FlashTimeOut, + FlashIsBusy, + FlashQuadNotEnable, + FlashAddressInvalid, +}ReturnMsg; +/** + * @} + */ + +/** @addtogroup RCC_Exported_Functions + * @{ + */ +void Qflash_Init(void); +uint32_t Qflash_Erase_Sector(uint32_t address); +uint32_t Qflash_Write(uint32_t address, uint8_t* p_data, uint32_t len); +uint32_t Qflash_Read(uint32_t address, uint8_t* p_data, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_QFLASH_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_rcc.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_rcc.h new file mode 100644 index 0000000..a404ace --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_rcc.h @@ -0,0 +1,428 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_rcc.h + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_RCC_H__ +#define __N32WB03X_RCC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup RCC + * @{ + */ + +/** @addtogroup RCC_Exported_Types + * @{ + */ + +typedef struct +{ + uint32_t SysclkFreq; /*!< returns SYSCLK clock frequency expressed in Hz */ + uint32_t HclkFreq; /*!< returns HCLK clock frequency expressed in Hz */ + uint32_t Pclk1Freq; /*!< returns PCLK1 clock frequency expressed in Hz */ + uint32_t Pclk2Freq; /*!< returns PCLK2 clock frequency expressed in Hz */ + uint32_t AdcclkFreq; /*!< returns ADCCLK clock frequency expressed in Hz */ +} RCC_ClocksType; + +/** + * @} + */ + +/** @addtogroup RCC_Exported_Constants + * @{ + */ + +/** @addtogroup HSE_configuration + * @{ + */ + +#define RCC_HSE_DISABLE ((uint32_t)0x00000000) +#define RCC_HSE_ENABLE ((uint32_t)0x00010000) + +#define IS_RCC_HSE(HSE) (((HSE) == RCC_HSE_DISABLE) || ((HSE) == RCC_HSE_ENABLE)) + +/** + * @} + */ + +/** @addtogroup HSI_configuration + * @{ + */ + +#define RCC_HSI_DISABLE ((uint32_t)0x00000000) +#define RCC_HSI_ENABLE ((uint32_t)0x00000001) +#define IS_RCC_HSI(HSI) (((HSI) == RCC_HSI_DISABLE) || ((HSI) == RCC_HSI_ENABLE)) + +/** + * @} + */ + +/** @addtogroup System_clock_source + * @{ + */ + +#define RCC_SYSCLK_SRC_HSI ((uint32_t)0x00000000) +#define RCC_SYSCLK_SRC_HSE ((uint32_t)0x00000001) +#define IS_RCC_SYSCLK_SRC(SOURCE) (((SOURCE) == RCC_SYSCLK_SRC_HSI) || ((SOURCE) == RCC_SYSCLK_SRC_HSE)) + +/** + * @} + */ + +/** @addtogroup AHB_clock_source + * @{ + */ + +#define RCC_SYSCLK_DIV1 ((uint32_t)0x00000000) +#define RCC_SYSCLK_DIV2 ((uint32_t)0x00000020) +#define RCC_SYSCLK_DIV4 ((uint32_t)0x00000030) +#define IS_RCC_SYSCLK_DIV(HCLK) (((HCLK) == RCC_SYSCLK_DIV1) || ((HCLK) == RCC_SYSCLK_DIV2) || ((HCLK) == RCC_SYSCLK_DIV4)) + +/** + * @} + */ + +/** @addtogroup APB1_APB2_clock_source + * @{ + */ + +#define RCC_HCLK_DIV1 ((uint32_t)0x00000000) +#define RCC_HCLK_DIV2 ((uint32_t)0x00000400) +#define RCC_HCLK_DIV4 ((uint32_t)0x00000500) +#define RCC_HCLK_DIV8 ((uint32_t)0x00000600) +#define RCC_HCLK_DIV16 ((uint32_t)0x00000700) +#define IS_RCC_HCLK_DIV(PCLK) \ + (((PCLK) == RCC_HCLK_DIV1) || ((PCLK) == RCC_HCLK_DIV2) || ((PCLK) == RCC_HCLK_DIV4) || ((PCLK) == RCC_HCLK_DIV8) \ + || ((PCLK) == RCC_HCLK_DIV16)) +/** + * @} + */ + +/** @addtogroup RCC_Interrupt_source + * @{ + */ + +#define RCC_INT_LSIRDIF ((uint8_t)0x01) +#define RCC_INT_LSERDIF ((uint8_t)0x02) +#define RCC_INT_HSIRDIF ((uint8_t)0x04) +#define RCC_INT_HSERDIF ((uint8_t)0x08) + +#define IS_RCC_INT(IT) \ + (((IT) == RCC_INT_LSIRDIF) || ((IT) == RCC_INT_LSERDIF) || ((IT) == RCC_INT_HSIRDIF) || ((IT) == RCC_INT_HSERDIF)) + + +#define IS_RCC_GET_INT(IT) \ + (((IT) == RCC_INT_LSIRDIF) || ((IT) == RCC_INT_LSERDIF) || ((IT) == RCC_INT_HSIRDIF) || ((IT) == RCC_INT_HSERDIF)) + +#define RCC_CLR_LSIRDIF ((uint32_t)0x00010000) +#define RCC_CLR_LSERDIF ((uint32_t)0x00020000) +#define RCC_CLR_HSIRDIF ((uint32_t)0x00040000) +#define RCC_CLR_HSERDIF ((uint32_t)0x00080000) + +#define IS_RCC_CLR_INTF(IT) \ + (((IT) == RCC_CLR_LSIRDIF) || ((IT) == RCC_CLR_LSERDIF) || ((IT) == RCC_CLR_HSIRDIF) || ((IT) == RCC_CLR_HSERDIF)) + +/** + * @} + */ + +/** @addtogroup RCC_CFG2_Config + * @{ + */ +#define RCC_TIM1CLK_SRC_TIM1CLK ((uint32_t)0x00000000) +#define RCC_TIM1CLK_SRC_SYSCLK ((uint32_t)0x80000000) +#define IS_RCC_TIM1CLKSRC(TIM1CLK) (((TIM1CLK) == RCC_TIM1CLK_SRC_TIM1CLK) || ((TIM1CLK) == RCC_TIM1CLK_SRC_SYSCLK)) + + +#define RCC_ADCCLK_SRC_AUDIOPLL ((uint32_t)0x00000000) +#define RCC_ADCCLK_SRC_HSE_DIV8 ((uint32_t)0x00000010) +#define IS_RCC_ADCCLKSRC(ADCMCLK) (((ADCMCLK) == RCC_ADCCLK_SRC_AUDIOPLL) || ((ADCMCLK) == RCC_ADCCLK_SRC_HSE_DIV8)) + +/** + * @} + */ + +/** @addtogroup LSE_configuration + * @{ + */ + +#define RCC_LSE_DISABLE ((uint32_t)0x00000000) +#define RCC_LSE_ENABLE ((uint32_t)0x00000004) +#define RCC_LSE_BYPASS ((uint32_t)0x00000010) +#define IS_RCC_LSE(LSE) (((LSE) == RCC_LSE_DISABLE) || ((LSE) == RCC_LSE_ENABLE) || ((LSE) == RCC_LSE_BYPASS)) +/** + * @} + */ + +/** @addtogroup RTC_clock_source + * @{ + */ + +#define RCC_RTCCLK_SRC_LSE ((uint32_t)0x00000020) +#define RCC_RTCCLK_SRC_LSI ((uint32_t)0x00000000) +#define IS_RCC_RTCCLK_SRC(SOURCE) (((SOURCE) == RCC_RTCCLK_SRC_LSE) || ((SOURCE) == RCC_RTCCLK_SRC_LSI)) + +/** + * @} + */ + +/** @addtogroup AHB_peripheral + * @{ + */ + +#define RCC_AHB_PERIPH_DMA ((uint32_t)0x00000001) +#define RCC_AHB_PERIPH_SRAM ((uint32_t)0x00000004) +#define RCC_AHB_PERIPH_CRC ((uint32_t)0x00000040) +#define RCC_AHB_PERIPH_ADC ((uint32_t)0x00001000) +#define RCC_AHB_PERIPH_IRC ((uint32_t)0x00004000) + +#define IS_RCC_AHB_PERIPH(PERIPH) ((((PERIPH)&0xFFFFAF8A) == 0x00) && ((PERIPH) != 0x00)) +#define IS_RCC_AHB_PERIPH_RESET(PERIPH) ((((PERIPH)&0xFFFFAF8A) == 0x00) && ((PERIPH) != 0x00)) + +/** + * @} + */ + +/** @addtogroup APB2_peripheral + * @{ + */ + +#define RCC_APB2_PERIPH_AFIO ((uint32_t)0x00000001) +#define RCC_APB2_PERIPH_GPIOA ((uint32_t)0x00000004) +#define RCC_APB2_PERIPH_GPIOB ((uint32_t)0x00000008) +#define RCC_APB2_PERIPH_SPI1 ((uint32_t)0x00000200) +#define RCC_APB2_PERIPH_SPI2 ((uint32_t)0x00000400) +#define RCC_APB2_PERIPH_TIM1 ((uint32_t)0x00001000) +#define RCC_APB2_PERIPH_USART1 ((uint32_t)0x00004000) + +#define IS_RCC_APB2_PERIPH(PERIPH) ((((PERIPH)&0xFFFFA9F2) == 0x00) && ((PERIPH) != 0x00)) +/** + * @} + */ + +/** @addtogroup APB1_peripheral + * @{ + */ + +#define RCC_APB1_PERIPH_TIM3 ((uint32_t)0x00000002) +#define RCC_APB1_PERIPH_TIM6 ((uint32_t)0x00000010) +#define RCC_APB1_PERIPH_WWDG ((uint32_t)0x00000800) +#define RCC_APB1_PERIPH_USART2 ((uint32_t)0x00020000) +#define RCC_APB1_PERIPH_I2C1 ((uint32_t)0x00200000) +#define RCC_APB1_PERIPH_PWR ((uint32_t)0x10000000) + +#define IS_RCC_APB1_PERIPH(PERIPH) ((((PERIPH)&0xEFDDF7ED) == 0x00) && ((PERIPH) != 0x00)) +#define IS_RCC_APB1_PERIPH_RESET(PERIPH) ((((PERIPH)&0xEFDDF7ED) == 0x00) && ((PERIPH) != 0x00)) + +/** + * @} + */ + +/** @addtogroup LPUART + * @{ + */ + +#define RCC_LPUART1CLK ((uint32_t)0x00000000) +#define RCC_LPUARTCLK_SRC_APB1 ((uint32_t)0x00000000) +#define RCC_LPUARTCLK_SRC_LSI_LSE ((uint32_t)0x04000000) +#define IS_RCC_LPUART_CLK(LPUARTCLK) ((LPUARTCLK == RCC_LPUARTCLK_SRC_APB1)||(LPUARTCLK == RCC_LPUARTCLK_SRC_LSI_LSE)) +#define IS_RCC_LPUARTX(RCC_LPUARTx) (RCC_LPUARTx == RCC_LPUART1CLK) + + +/** @addtogroup Clock_source_to_output_on_MCO_pin + * @{ + */ + +#define RCC_MCO_NOCLK ((uint8_t)0x00) +#define RCC_MCO_LSI ((uint8_t)0x01) +#define RCC_MCO_LSE ((uint8_t)0x02) +#define RCC_MCO_SYSCLK ((uint8_t)0x03) +#define RCC_MCO_HSI ((uint8_t)0x04) +#define RCC_MCO_HSE ((uint8_t)0x05) +#define RCC_MCO_HCLK ((uint8_t)0x06) +#define RCC_MCO_AUDIOPLL ((uint8_t)0x06) + +#define IS_RCC_MCO(MCO) \ + (((MCO) == RCC_MCO_NOCLK) || ((MCO) == RCC_MCO_LSI) || ((MCO) == RCC_MCO_LSE) || \ + ((MCO) == RCC_MCO_SYSCLK) || ((MCO) == RCC_MCO_HSI) || ((MCO) == RCC_MCO_HSE) || \ + ((MCO) == RCC_MCO_HCLK) || ((MCO) == RCC_MCO_AUDIOPLL)) + +/** + * @} + */ + +/** @addtogroup RCC_Flag + * @{ + */ +#define RCC_CTRL_FLAG_HSIRDF ((uint8_t)0x21) +#define RCC_CTRL_FLAG_HSERDF ((uint8_t)0x31) + +#define RCC_LSCTRL_FLAG_LSIRD ((uint8_t)0x41) +#define RCC_LSCTRL_FLAG_LSERD ((uint8_t)0x43) + +#define RCC_CTRLSTS_FLAG_PINRSTF ((uint8_t)0x83) +#define RCC_CTRLSTS_FLAG_PORRSTF ((uint8_t)0x84) +#define RCC_CTRLSTS_FLAG_SFTRSTF ((uint8_t)0x85) +#define RCC_CTRLSTS_FLAG_IWDGRSTF ((uint8_t)0x86) +#define RCC_CTRLSTS_FLAG_WWDGRSTF ((uint8_t)0x87) + +#define IS_RCC_FLAG(FLAG) \ + (((FLAG) == RCC_CTRL_FLAG_HSIRDF) || ((FLAG) == RCC_CTRL_FLAG_HSERDF) || ((FLAG) == RCC_LSCTRL_FLAG_LSIRD) \ + || ((FLAG) == RCC_CTRLSTS_FLAG_PINRSTF) || ((FLAG) == RCC_CTRLSTS_FLAG_PORRSTF) || ((FLAG) == RCC_LSCTRL_FLAG_LSERD) \ + || ((FLAG) == RCC_CTRLSTS_FLAG_SFTRSTF) || ((FLAG) == RCC_CTRLSTS_FLAG_IWDGRSTF) || ((FLAG) == RCC_CTRLSTS_FLAG_WWDGRSTF)) + +#define RCC_FLAG_MASK ((uint8_t)0x1F) + + +/** @addtogroup DBGMCU_Exported_Constants + * @{ + */ +#define DBG_IWDG_STOP ((uint32_t)0x00000001) +#define DBG_WWDG_STOP ((uint32_t)0x00000002) +#define DBG_TIM1_STOP ((uint32_t)0x00000004) +#define DBG_TIM3_STOP ((uint32_t)0x00000008) +#define DBG_TIM6_STOP ((uint32_t)0x00000010) +#define DBG_I2C1SMBUS_TIMEOUT ((uint32_t)0x00000020) + + +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup RCC_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup RCC_Exported_Functions + * @{ + */ + +void RCC_DeInit(void); +void RCC_ConfigHse(uint32_t RCC_HSE); +ErrorStatus RCC_WaitHseStable(void); +void RCC_ConfigHsi(uint32_t RCC_HSI); +ErrorStatus RCC_WaitHsiStable(void); +void RCC_SetHsiCalibValue(uint8_t HSICalibrationValue); +void RCC_EnableHsi(FunctionalState Cmd); + +void RCC_ConfigSysclk(uint32_t RCC_SYSCLKSource); +uint32_t RCC_GetSysclkSrc(void); +void RCC_ConfigHclk(uint32_t RCC_SYSCLK); +void RCC_ConfigPclk1(uint32_t RCC_HCLK); +void RCC_ConfigPclk2(uint32_t RCC_HCLK); +void RCC_ConfigInt(uint8_t RccInt, FunctionalState Cmd); + +void RCC_ConfigTim1Clk(uint32_t RCC_TIM1CLKSource); +void RCC_ConfigAdcClk(uint32_t RCC_ADCCLKSource); + +void RCC_ConfigLpuartClk(uint32_t RCC_LPUARTx, uint32_t RCC_LPUARTCLKSource); +uint32_t RCC_GetLpuartClkSrc(uint32_t RCC_LPUARTx); +void RCC_EnableLpuartClk(FunctionalState Cmd); +void RCC_ConfigLse(uint8_t RCC_LSE); +void RCC_EnableLsi(FunctionalState Cmd); +void RCC_ConfigLSXSEL(uint32_t RCC_LS_Source); +void RCC_EnableRtcClk(FunctionalState Cmd); +void RCC_EnableRTCReset(FunctionalState Cmd); +uint32_t RCC_GetRTCClkSrc(void); +void RCC_GetClocksFreqValue(RCC_ClocksType* RCC_Clocks); +void RCC_EnableAHBPeriphClk(uint32_t RCC_AHBPeriph, FunctionalState Cmd); +void RCC_EnableAPB2PeriphClk(uint32_t RCC_APB2Periph, FunctionalState Cmd); +void RCC_EnableAPB1PeriphClk(uint32_t RCC_APB1Periph, FunctionalState Cmd); + +void RCC_EnableAHBPeriphReset(uint32_t RCC_AHBPeriph, FunctionalState Cmd); +void RCC_EnableAPB2PeriphReset(uint32_t RCC_APB2Periph, FunctionalState Cmd); +void RCC_EnableAPB1PeriphReset(uint32_t RCC_APB1Periph, FunctionalState Cmd); + +void RCC_EnableClockSecuritySystem(FunctionalState Cmd); +void RCC_ConfigMco(uint8_t RCC_MCO); +FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG); +void RCC_ClrFlag(void); +INTStatus RCC_GetIntStatus(uint8_t RccInt); +void RCC_ClrIntPendingBit(uint32_t RccClrInt); +void RCC_Enable_ADC_CLK_SRC_AUDIOPLL(FunctionalState Cmd); +void RCC_EnableRAMCParityErrorReset(FunctionalState Cmd); +void DBG_ConfigPeriph(uint32_t DBG_Periph, FunctionalState Cmd); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_RCC_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_rtc.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_rtc.h new file mode 100644 index 0000000..aed5034 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_rtc.h @@ -0,0 +1,783 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_rtc.h + * @author NSING Firmware Team + * @version v1.0.3 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_RTC_H__ +#define __N32WB03X_RTC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup RTC + * @{ + */ + +/** + * @brief RTC Init structures definition + */ +typedef struct +{ + uint32_t RTC_HourFormat; /*!< Specifies the RTC Hour Format. + This parameter can be a value of @ref RTC_Hour_Formats */ + + uint32_t RTC_AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value. + This parameter must be set to a value lower than 0x7F */ + + uint32_t RTC_SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value. + This parameter must be set to a value lower than 0x7FFF */ +} RTC_InitType; + +/** + * @brief RTC Time structure definition + */ +typedef struct +{ + uint8_t Hours; /*!< Specifies the RTC Time Hour. + This parameter must be set to a value in the 0-12 range + if the RTC_12HOUR_FORMAT is selected or 0-23 range if + the RTC_24HOUR_FORMAT is selected. */ + + uint8_t Minutes; /*!< Specifies the RTC Time Minutes. + This parameter must be set to a value in the 0-59 range. */ + + uint8_t Seconds; /*!< Specifies the RTC Time Seconds. + This parameter must be set to a value in the 0-59 range. */ + + uint8_t H12; /*!< Specifies the RTC AM/PM Time. + This parameter can be a value of @ref RTC_AM_PM_Definitions */ +} RTC_TimeType; + +/** + * @brief RTC Date structure definition + */ +typedef struct +{ + uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. + This parameter can be a value of @ref RTC_WeekDay_Definitions */ + + uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). + This parameter can be a value of @ref RTC_Month_Date_Definitions */ + + uint8_t Date; /*!< Specifies the RTC Date. + This parameter must be set to a value in the 1-31 range. */ + + uint8_t Year; /*!< Specifies the RTC Date Year. + This parameter must be set to a value in the 0-99 range. */ +} RTC_DateType; + +/** + * @brief RTC Alarm structure definition + */ +typedef struct +{ + RTC_TimeType AlarmTime; /*!< Specifies the RTC Alarm Time members. */ + + uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. + This parameter can be a value of @ref RTC_AlarmMask_Definitions */ + + uint32_t DateWeekMode; /*!< Specifies the RTC Alarm is on Date or WeekDay. + This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ + + uint8_t DateWeekValue; /*!< Specifies the RTC Alarm Date/WeekDay. + If the Alarm Date is selected, this parameter + must be set to a value in the 1-31 range. + If the Alarm WeekDay is selected, this + parameter can be a value of @ref RTC_WeekDay_Definitions */ +} RTC_AlarmType; + +/** @addtogroup RTC_Exported_Constants + * @{ + */ + +/** @addtogroup RTC_Hour_Formats + * @{ + */ +#define RTC_24HOUR_FORMAT ((uint32_t)0x00000000) +#define RTC_12HOUR_FORMAT ((uint32_t)0x00000040) +#define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_12HOUR_FORMAT) || ((FORMAT) == RTC_24HOUR_FORMAT)) +/** + * @} + */ + +/** @addtogroup RTC_Asynchronous_Predivider + * @{ + */ +#define IS_RTC_PREDIV_ASYNCH(PREDIV) ((PREDIV) <= 0x7F) + +/** + * @} + */ + +/** @addtogroup RTC_Synchronous_Predivider + * @{ + */ +#define IS_RTC_PREDIV_SYNCH(PREDIV) ((PREDIV) <= 0x7FFF) + +/** + * @} + */ + +/** @addtogroup RTC_Time_Definitions + * @{ + */ +#define IS_RTC_12HOUR(HOUR) (((HOUR) > 0) && ((HOUR) <= 12)) +#define IS_RTC_24HOUR(HOUR) ((HOUR) <= 23) +#define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59) +#define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59) + +/** + * @} + */ + +/** @addtogroup RTC_AM_PM_Definitions + * @{ + */ +#define RTC_AM_H12 ((uint8_t)0x00) +#define RTC_PM_H12 ((uint8_t)0x40) +#define IS_RTC_H12(PM) (((PM) == RTC_AM_H12) || ((PM) == RTC_PM_H12)) + +/** + * @} + */ + +/** @addtogroup RTC_Year_Date_Definitions + * @{ + */ +#define IS_RTC_YEAR(YEAR) ((YEAR) <= 99) + +/** + * @} + */ + +/** @addtogroup RTC_Month_Date_Definitions + * @{ + */ + +/* Coded in BCD format */ +#define RTC_MONTH_JANUARY ((uint8_t)0x01) +#define RTC_MONTH_FEBRURY ((uint8_t)0x02) +#define RTC_MONTH_MARCH ((uint8_t)0x03) +#define RTC_MONTH_APRIL ((uint8_t)0x04) +#define RTC_MONTH_MAY ((uint8_t)0x05) +#define RTC_MONTH_JUNE ((uint8_t)0x06) +#define RTC_MONTH_JULY ((uint8_t)0x07) +#define RTC_MONTH_AUGUST ((uint8_t)0x08) +#define RTC_MONTH_SEPTEMBER ((uint8_t)0x09) +#define RTC_MONTH_OCTOBER ((uint8_t)0x10) +#define RTC_MONTH_NOVEMBER ((uint8_t)0x11) +#define RTC_MONTH_DECEMBER ((uint8_t)0x12) +#define IS_RTC_MONTH(MONTH) (((MONTH) >= 1) && ((MONTH) <= 12)) +#define IS_RTC_DATE(DATE) (((DATE) >= 1) && ((DATE) <= 31)) + +/** + * @} + */ + +/** @addtogroup RTC_WeekDay_Definitions + * @{ + */ + +#define RTC_WEEKDAY_MONDAY ((uint8_t)0x01) +#define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02) +#define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03) +#define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04) +#define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05) +#define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06) +#define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07) +#define IS_RTC_WEEKDAY(WEEKDAY) \ + (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) \ + || ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) \ + || ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) +/** + * @} + */ + +/** @addtogroup RTC_Alarm_Definitions + * @{ + */ +#define IS_RTC_ALARM_WEEKDAY_DATE(DATE) (((DATE) > 0) && ((DATE) <= 31)) +#define IS_RTC_ALARM_WEEKDAY_WEEKDAY(WEEKDAY) \ + (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) \ + || ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) \ + || ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) + +/** + * @} + */ + +/** @addtogroup RTC_AlarmDateWeekDay_Definitions + * @{ + */ +#define RTC_ALARM_SEL_WEEKDAY_DATE ((uint32_t)0x00000000) +#define RTC_ALARM_SEL_WEEKDAY_WEEKDAY ((uint32_t)0x40000000) + +#define IS_RTC_ALARM_WEEKDAY_SEL(SEL) \ + (((SEL) == RTC_ALARM_SEL_WEEKDAY_DATE) || ((SEL) == RTC_ALARM_SEL_WEEKDAY_WEEKDAY)) + +/** + * @} + */ + +/** @addtogroup RTC_AlarmMask_Definitions + * @{ + */ +#define RTC_ALARMMASK_NONE ((uint32_t)0x00000000) +#define RTC_ALARMMASK_WEEKDAY ((uint32_t)0x80000000) +#define RTC_ALARMMASK_HOURS ((uint32_t)0x00800000) +#define RTC_ALARMMASK_MINUTES ((uint32_t)0x00008000) +#define RTC_ALARMMASK_SECONDS ((uint32_t)0x00000080) +#define RTC_ALARMMASK_ALL ((uint32_t)0x80808080) +#define IS_ALARM_MASK(INTEN) (((INTEN)&0x7F7F7F7F) == (uint32_t)RESET) + +/** + * @} + */ + +/** @addtogroup RTC_Alarms_Definitions + * @{ + */ +#define RTC_A_ALARM ((uint32_t)0x00000100) +#define IS_RTC_ALARM_SEL(ALARM) (((ALARM) == RTC_A_ALARM) ) +#define IS_RTC_ALARM_ENABLE(ALARM) (((ALARM) & (RTC_A_ALARM)) != (uint32_t)RESET) + +/** + * @} + */ + +/** @addtogroup RTC_Alarm_Sub_Seconds_Masks_Definitions + * @{ + */ +#define RTC_SUBS_MASK_ALL \ + ((uint32_t)0x00000000) /*!< All Alarm SS fields are masked. \ + There is no comparison on sub seconds \ + for Alarm */ +#define RTC_SUBS_MASK_SS14_1 \ + ((uint32_t)0x01000000) /*!< SS[14:1] are don't care in Alarm \ + comparison. Only SS[0] is compared. */ +#define RTC_SUBS_MASK_SS14_2 \ + ((uint32_t)0x02000000) /*!< SS[14:2] are don't care in Alarm \ + comparison. Only SS[1:0] are compared */ +#define RTC_SUBS_MASK_SS14_3 \ + ((uint32_t)0x03000000) /*!< SS[14:3] are don't care in Alarm \ + comparison. Only SS[2:0] are compared */ +#define RTC_SUBS_MASK_SS14_4 \ + ((uint32_t)0x04000000) /*!< SS[14:4] are don't care in Alarm \ + comparison. Only SS[3:0] are compared */ +#define RTC_SUBS_MASK_SS14_5 \ + ((uint32_t)0x05000000) /*!< SS[14:5] are don't care in Alarm \ + comparison. Only SS[4:0] are compared */ +#define RTC_SUBS_MASK_SS14_6 \ + ((uint32_t)0x06000000) /*!< SS[14:6] are don't care in Alarm \ + comparison. Only SS[5:0] are compared */ +#define RTC_SUBS_MASK_SS14_7 \ + ((uint32_t)0x07000000) /*!< SS[14:7] are don't care in Alarm \ + comparison. Only SS[6:0] are compared */ +#define RTC_SUBS_MASK_SS14_8 \ + ((uint32_t)0x08000000) /*!< SS[14:8] are don't care in Alarm \ + comparison. Only SS[7:0] are compared */ +#define RTC_SUBS_MASK_SS14_9 \ + ((uint32_t)0x09000000) /*!< SS[14:9] are don't care in Alarm \ + comparison. Only SS[8:0] are compared */ +#define RTC_SUBS_MASK_SS14_10 \ + ((uint32_t)0x0A000000) /*!< SS[14:10] are don't care in Alarm \ + comparison. Only SS[9:0] are compared */ +#define RTC_SUBS_MASK_SS14_11 \ + ((uint32_t)0x0B000000) /*!< SS[14:11] are don't care in Alarm \ + comparison. Only SS[10:0] are compared */ +#define RTC_SUBS_MASK_SS14_12 \ + ((uint32_t)0x0C000000) /*!< SS[14:12] are don't care in Alarm \ + comparison.Only SS[11:0] are compared */ +#define RTC_SUBS_MASK_SS14_13 \ + ((uint32_t)0x0D000000) /*!< SS[14:13] are don't care in Alarm \ + comparison. Only SS[12:0] are compared */ +#define RTC_SUBS_MASK_SS14_14 \ + ((uint32_t)0x0E000000) /*!< SS[14] is don't care in Alarm \ + comparison.Only SS[13:0] are compared */ +#define RTC_SUBS_MASK_NONE \ + ((uint32_t)0x0F000000) /*!< SS[14:0] are compared and must match \ + to activate alarm. */ +#define IS_RTC_ALARM_SUB_SECOND_MASK_MODE(INTEN) \ + (((INTEN) == RTC_SUBS_MASK_ALL) || ((INTEN) == RTC_SUBS_MASK_SS14_1) || ((INTEN) == RTC_SUBS_MASK_SS14_2) \ + || ((INTEN) == RTC_SUBS_MASK_SS14_3) || ((INTEN) == RTC_SUBS_MASK_SS14_4) || ((INTEN) == RTC_SUBS_MASK_SS14_5) \ + || ((INTEN) == RTC_SUBS_MASK_SS14_6) || ((INTEN) == RTC_SUBS_MASK_SS14_7) || ((INTEN) == RTC_SUBS_MASK_SS14_8) \ + || ((INTEN) == RTC_SUBS_MASK_SS14_9) || ((INTEN) == RTC_SUBS_MASK_SS14_10) || ((INTEN) == RTC_SUBS_MASK_SS14_11) \ + || ((INTEN) == RTC_SUBS_MASK_SS14_12) || ((INTEN) == RTC_SUBS_MASK_SS14_13) || ((INTEN) == RTC_SUBS_MASK_SS14_14) \ + || ((INTEN) == RTC_SUBS_MASK_NONE)) +/** + * @} + */ + +/** @addtogroup RTC_Alarm_Sub_Seconds_Value + * @{ + */ + +#define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFF) + +/** + * @} + */ + +/** @addtogroup RTC_Wakeup_Timer_Definitions + * @{ + */ +#define RTC_WKUPCLK_RTCCLK_DIV16 ((uint32_t)0x00000000) +#define RTC_WKUPCLK_RTCCLK_DIV8 ((uint32_t)0x00000001) +#define RTC_WKUPCLK_RTCCLK_DIV4 ((uint32_t)0x00000002) +#define RTC_WKUPCLK_RTCCLK_DIV2 ((uint32_t)0x00000003) +#define RTC_WKUPCLK_CK_SPRE_16BITS ((uint32_t)0x00000004) +#define RTC_WKUPCLK_CK_SPRE_17BITS ((uint32_t)0x00000006) +#define IS_RTC_WKUP_CLOCK(CLOCK) \ + (((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV16) || ((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV8) \ + || ((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV4) || ((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV2) \ + || ((CLOCK) == RTC_WKUPCLK_CK_SPRE_16BITS) || ((CLOCK) == RTC_WKUPCLK_CK_SPRE_17BITS)) +#define IS_RTC_WKUP_COUNTER(COUNTER) ((COUNTER) <= 0xFFFF) + +/** + * @} + */ + +/** @addtogroup RTC_Output_selection_Definitions + * @{ + */ +#define RTC_OUTPUT_DIS ((uint32_t)0x00000000) +#define RTC_OUTPUT_ALA ((uint32_t)0x00200000) +#define RTC_OUTPUT_ALB ((uint32_t)0x00400000) +#define RTC_OUTPUT_WKUP ((uint32_t)0x00600000) + +#define IS_RTC_OUTPUT_MODE(OUTPUT) \ + (((OUTPUT) == RTC_OUTPUT_DIS) || ((OUTPUT) == RTC_OUTPUT_ALA) || ((OUTPUT) == RTC_OUTPUT_ALB) \ + || ((OUTPUT) == RTC_OUTPUT_WKUP)) + +/** + * @} + */ + +/** @addtogroup RTC_Output_Polarity_Definitions + * @{ + */ +#define RTC_OUTPOL_HIGH ((uint32_t)0x00000000) +#define RTC_OUTPOL_LOW ((uint32_t)0x00100000) +#define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPOL_HIGH) || ((POL) == RTC_OUTPOL_LOW)) +/** + * @} + */ + +/** @addtogroup RTC_Coarse_Calibration_Definitions + * @{ + */ +#define RTC_CALIB_POSITIVE ((uint32_t)0x00000000) +#define RTC_CALIB_NEGATIVE ((uint32_t)0x00000080) +#define IS_RTC_CALIB_DIR(SIGN) (((SIGN) == RTC_CALIB_POSITIVE) || ((SIGN) == RTC_CALIB_NEGATIVE)) +#define IS_RTC_CALIB_VALUE(VALUE) ((VALUE) < 0x20) + +/** + * @} + */ + +/** @addtogroup RTC_Calib_Output_selection_Definitions + * @{ + */ +#define RTC_CALIB_OUTPUT_256HZ ((uint32_t)0x00000000) +#define RTC_CALIB_OUTPUT_1HZ ((uint32_t)0x00080000) +#define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CALIB_OUTPUT_256HZ) || ((OUTPUT) == RTC_CALIB_OUTPUT_1HZ)) +/** + * @} + */ + +/** @addtogroup RTC_Smooth_calib_period_Definitions + * @{ + */ +#define SMOOTH_CALIB_32SEC \ + ((uint32_t)0x00000000) /*!< if RTCCLK = 32768 Hz, Smooth calibation \ + period is 32s, else 2exp20 RTCCLK seconds */ +#define SMOOTH_CALIB_16SEC \ + ((uint32_t)0x00002000) /*!< if RTCCLK = 32768 Hz, Smooth calibation \ + period is 16s, else 2exp19 RTCCLK seconds */ +#define SMOOTH_CALIB_8SEC \ + ((uint32_t)0x00004000) /*!< if RTCCLK = 32768 Hz, Smooth calibation \ + period is 8s, else 2exp18 RTCCLK seconds */ +#define IS_RTC_SMOOTH_CALIB_PERIOD_SEL(PERIOD) \ + (((PERIOD) == SMOOTH_CALIB_32SEC) || ((PERIOD) == SMOOTH_CALIB_16SEC) || ((PERIOD) == SMOOTH_CALIB_8SEC)) + +/** + * @} + */ + +/** @addtogroup RTC_Smooth_calib_Plus_pulses_Definitions + * @{ + */ +#define RTC_SMOOTH_CALIB_PLUS_PULSES_SET \ + ((uint32_t)0x00008000) /*!< The number of RTCCLK pulses added \ + during a X -second window = Y - CALM[8:0]. \ + with Y = 512, 256, 128 when X = 32, 16, 8 */ +#define RTC_SMOOTH_CALIB_PLUS_PULSES_RESET \ + ((uint32_t)0x00000000) /*!< The number of RTCCLK pulses subbstited \ + during a 32-second window = CALM[8:0]. */ +#define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) \ + (((PLUS) == RTC_SMOOTH_CALIB_PLUS_PULSES_SET) || ((PLUS) == RTC_SMOOTH_CALIB_PLUS_PULSES_RESET)) + +/** + * @} + */ + +/** @addtogroup RTC_Smooth_calib_Minus_pulses_Definitions + * @{ + */ +#define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= 0x000001FF) + +/** + * @} + */ + +/** @addtogroup RTC_DayLightSaving_Definitions + * @{ + */ +#define RTC_DAYLIGHT_SAVING_SUB1H ((uint32_t)0x00020000) +#define RTC_DAYLIGHT_SAVING_ADD1H ((uint32_t)0x00010000) +#define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHT_SAVING_SUB1H) || ((SAVE) == RTC_DAYLIGHT_SAVING_ADD1H)) + +#define RTC_STORE_OPERATION_RESET ((uint32_t)0x00000000) +#define RTC_STORE_OPERATION_SET ((uint32_t)0x00040000) +#define IS_RTC_STORE_OPERATION(OPERATION) \ + (((OPERATION) == RTC_STORE_OPERATION_RESET) || ((OPERATION) == RTC_STORE_OPERATION_SET)) +/** + * @} + */ + +/** @addtogroup RTC_Output_Type_ALARM_OUT + * @{ + */ +#define RTC_OUTPUT_OPENDRAIN ((uint32_t)0x00000000) +#define RTC_OUTPUT_PUSHPULL ((uint32_t)0x00000001) +#define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_OPENDRAIN) || ((TYPE) == RTC_OUTPUT_PUSHPULL)) + +/** + * @} + */ + +/** @addtogroup RTC_Add_1_Second_Parameter_Definitions + * @{ + */ +#define RTC_SHIFT_ADD1S_DISABLE ((uint32_t)0x00000000) +#define RTC_SHIFT_ADD1S_ENABLE ((uint32_t)0x80000000) +#define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFT_ADD1S_DISABLE) || ((SEL) == RTC_SHIFT_ADD1S_ENABLE)) +/** + * @} + */ + +/** @addtogroup RTC_Substract_Fraction_Of_Second_Value + * @{ + */ +#define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= 0x00007FFF) + +/** + * @} + */ + +/** @addtogroup RTC_Input_parameter_format_definitions + * @{ + */ +#define RTC_FORMAT_BIN ((uint32_t)0x000000000) +#define RTC_FORMAT_BCD ((uint32_t)0x000000001) +#define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD)) + +/** + * @} + */ + +/** @addtogroup RTC_Flags_Definitions + * @{ + */ +#define RTC_FLAG_RECPF ((uint32_t)0x00010000) + +#define RTC_FLAG_TAMP2F ((uint32_t)0x00004000) +#define RTC_FLAG_TAMP1F ((uint32_t)0x00002000) +#define RTC_FLAG_TISOVF ((uint32_t)0x00001000) +#define RTC_FLAG_TISF ((uint32_t)0x00000800) +#define RTC_FLAG_WTF ((uint32_t)0x00000400) +#define RTC_FLAG_ALAF ((uint32_t)0x00000100) +#define RTC_FLAG_INITF ((uint32_t)0x00000040) +#define RTC_FLAG_RSYF ((uint32_t)0x00000020) +#define RTC_FLAG_INITSF ((uint32_t)0x00000010) +#define RTC_FLAG_SHOPF ((uint32_t)0x00000008) +#define RTC_FLAG_WTWF ((uint32_t)0x00000004) +#define RTC_FLAG_ALBWF ((uint32_t)0x00000002) +#define RTC_FLAG_ALAWF ((uint32_t)0x00000001) +#define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RECPF) || ((FLAG) == RTC_FLAG_TAMP2F) || \ + ((FLAG) == RTC_FLAG_TAMP1F) || ((FLAG) == RTC_FLAG_TISOVF) || \ + ((FLAG) == RTC_FLAG_TISF) || ((FLAG) == RTC_FLAG_WTF) || \ + ((FLAG) == RTC_FLAG_WTWF) || ((FLAG) == RTC_FLAG_ALAF) || \ + ((FLAG) == RTC_FLAG_INITF) || ((FLAG) == RTC_FLAG_RSYF) || \ + ((FLAG) == RTC_FLAG_INITSF) || ((FLAG) == RTC_FLAG_SHOPF) || \ + ((FLAG) == RTC_FLAG_ALBWF)|| ((FLAG) == RTC_FLAG_ALAWF)) +#define IS_RTC_CLEAR_FLAG(FLAG) (((FLAG) != (uint32_t)RESET) && (((FLAG) & 0xFFFF00DF) == (uint32_t)RESET)) + +/** + * @} + */ + +/** @addtogroup RTC_Interrupts_Definitions + * @{ + */ + +#define RTC_INT_TAMP2 ((uint32_t)0x00040000) +#define RTC_INT_TAMP1 ((uint32_t)0x00020000) + +#define RTC_INT_WUT ((uint32_t)0x00004000) +#define RTC_INT_ALRA ((uint32_t)0x00001000) + +#define IS_RTC_CONFIG_INT(IT) (((IT) != (uint32_t)RESET) && (((IT)&0xFFFF0FFB) == (uint32_t)RESET)) +#define IS_RTC_GET_INT(IT) (((IT) == RTC_INT_WUT) || ((IT) == RTC_INT_ALRA)) +#define IS_RTC_CLEAR_INT(IT) (((IT) != (uint32_t)RESET) && (((IT)&0xFFF10FFF) == (uint32_t)RESET)) + +/** + * @} + */ + +/** @addtogroup RTC_Legacy + * @{ + */ +#define RTC_DigitalCalibConfig RTC_CoarseCalibConfig +#define RTC_DigitalCalibCmd RTC_CoarseCalibCmd +/** @defgroup RTC_Tamper_Trigger_Definitions + * @{ + */ +#define RTC_TamperTrigger_RisingEdge ((uint32_t)0x00000000) +#define RTC_TamperTrigger_FallingEdge ((uint32_t)0x00000002) +#define RTC_TamperTrigger_LowLevel ((uint32_t)0x00000000) +#define RTC_TamperTrigger_HighLevel ((uint32_t)0x00000002) +#define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TamperTrigger_RisingEdge) || \ + ((TRIGGER) == RTC_TamperTrigger_FallingEdge) || \ + ((TRIGGER) == RTC_TamperTrigger_LowLevel) || \ + ((TRIGGER) == RTC_TamperTrigger_HighLevel)) + +/** + * @} + */ + +/** @defgroup RTC_Tamper_Filter_Definitions + * @{ + */ +#define RTC_TamperFilter_Disable ((uint32_t)0x00000000) /*!< Tamper filter is disabled */ + +#define RTC_TamperFilter_2Sample ((uint32_t)0x00000800) /*!< Tamper is activated after 2 + consecutive samples at the active level */ +#define RTC_TamperFilter_4Sample ((uint32_t)0x00001000) /*!< Tamper is activated after 4 + consecutive samples at the active level */ +#define RTC_TamperFilter_8Sample ((uint32_t)0x00001800) /*!< Tamper is activated after 8 + consecutive samples at the active leve. */ + +#define IS_RTC_TAMPER_FILTER(FILTER) (((FILTER) == RTC_TamperFilter_Disable) || \ + ((FILTER) == RTC_TamperFilter_2Sample) || \ + ((FILTER) == RTC_TamperFilter_4Sample) || \ + ((FILTER) == RTC_TamperFilter_8Sample)) +/** + * @} + */ + +/** @defgroup RTC_Tamper_Sampling_Frequencies_Definitions + * @{ + */ +#define RTC_TamperSamplingFreq_RTCCLK_Div32768 ((uint32_t)0x00000000) /*!< Each of the tamper inputs are sampled + with a frequency = RTCCLK / 32768 */ +#define RTC_TamperSamplingFreq_RTCCLK_Div16384 ((uint32_t)0x000000100) /*!< Each of the tamper inputs are sampled + with a frequency = RTCCLK / 16384 */ +#define RTC_TamperSamplingFreq_RTCCLK_Div8192 ((uint32_t)0x00000200) /*!< Each of the tamper inputs are sampled + with a frequency = RTCCLK / 8192 */ +#define RTC_TamperSamplingFreq_RTCCLK_Div4096 ((uint32_t)0x00000300) /*!< Each of the tamper inputs are sampled + with a frequency = RTCCLK / 4096 */ +#define RTC_TamperSamplingFreq_RTCCLK_Div2048 ((uint32_t)0x00000400) /*!< Each of the tamper inputs are sampled + with a frequency = RTCCLK / 2048 */ +#define RTC_TamperSamplingFreq_RTCCLK_Div1024 ((uint32_t)0x00000500) /*!< Each of the tamper inputs are sampled + with a frequency = RTCCLK / 1024 */ +#define RTC_TamperSamplingFreq_RTCCLK_Div512 ((uint32_t)0x00000600) /*!< Each of the tamper inputs are sampled + with a frequency = RTCCLK / 512 */ +#define RTC_TamperSamplingFreq_RTCCLK_Div256 ((uint32_t)0x00000700) /*!< Each of the tamper inputs are sampled + with a frequency = RTCCLK / 256 */ +#define RTC_TAMPCR_TAMPFREQ ((uint32_t)0x00000700) /* Clear TAMPFREQ[2:0] bits in the RTC_TAMPCR register */ + +#define IS_RTC_TAMPER_SAMPLING_FREQ(FREQ) (((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div32768) || \ + ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div16384) || \ + ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div8192) || \ + ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div4096) || \ + ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div2048) || \ + ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div1024) || \ + ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div512) || \ + ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div256)) + +/** + * @} + */ + + /** @defgroup RTC_Tamper_Pin_Precharge_Duration_Definitions + * @{ + */ +#define RTC_TamperPrechargeDuration_1RTCCLK ((uint32_t)0x00000000) /*!< Tamper pins are pre-charged before + sampling during 1 RTCCLK cycle */ +#define RTC_TamperPrechargeDuration_2RTCCLK ((uint32_t)0x00002000) /*!< Tamper pins are pre-charged before + sampling during 2 RTCCLK cycles */ +#define RTC_TamperPrechargeDuration_4RTCCLK ((uint32_t)0x00004000) /*!< Tamper pins are pre-charged before + sampling during 4 RTCCLK cycles */ +#define RTC_TamperPrechargeDuration_8RTCCLK ((uint32_t)0x00006000) /*!< Tamper pins are pre-charged before + sampling during 8 RTCCLK cycles */ +#define IS_RTC_TAMPER_PRECHARGE_DURATION(DURATION) (((DURATION) == RTC_TamperPrechargeDuration_1RTCCLK) || \ + ((DURATION) == RTC_TamperPrechargeDuration_2RTCCLK) || \ + ((DURATION) == RTC_TamperPrechargeDuration_4RTCCLK) || \ + ((DURATION) == RTC_TamperPrechargeDuration_8RTCCLK)) +/** + * @} + */ + +/** @defgroup RTC_Tamper_Pins_Definitions + * @{ + */ +#define RTC_TAMPER_1 RTC_TMPCFG_TP1EN /*!< Tamper detection enable for + input tamper 1 */ +#define RTC_TAMPER_2 RTC_TMPCFG_TP2EN /*!< Tamper detection enable for + input tamper 2 */ +#define RTC_TAMPER_3 RTC_TMPCFG_TP3EN /*!< Tamper detection enable for + input tamper 3 */ +#define IS_RTC_TAMPER(TAMPER) ((((TAMPER) & (uint32_t)0xFFFFFFD6) == 0x00) && ((TAMPER) != (uint32_t)RESET)) + + +#define RTC_TAMPER1_INT RTC_TMPCFG_TP1INTEN /*!< Tamper detection interruput enable */ +#define RTC_TAMPER2_INT RTC_TMPCFG_TP2INTEN /*!< Tamper detection interruput enable */ +#define RTC_TAMPER3_INT RTC_TMPCFG_TP3INTEN /*!< Tamper detection interruput enable */ +/** + * @} + */ + +/** + * @} + */ + +/* Function used to set the RTC configuration to the default reset state *****/ +ErrorStatus RTC_DeInit(void); + +/* Initialization and Configuration functions *********************************/ +ErrorStatus RTC_Init(RTC_InitType* RTC_InitStruct); +void RTC_StructInit(RTC_InitType* RTC_InitStruct); +void RTC_EnableWriteProtection(FunctionalState Cmd); +ErrorStatus RTC_EnterInitMode(void); +void RTC_ExitInitMode(void); +ErrorStatus RTC_WaitForSynchro(void); +ErrorStatus RTC_EnableRefClock(FunctionalState Cmd); +void RTC_EnableBypassShadow(FunctionalState Cmd); + +/* Time and Date configuration functions **************************************/ +ErrorStatus RTC_ConfigTime(uint32_t RTC_Format, RTC_TimeType* RTC_TimeStruct); +void RTC_TimeStructInit(RTC_TimeType* RTC_TimeStruct); +void RTC_GetTime(uint32_t RTC_Format, RTC_TimeType* RTC_TimeStruct); +uint32_t RTC_GetSubSecond(void); +ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateType* RTC_DateStruct); +void RTC_DateStructInit(RTC_DateType* RTC_DateStruct); +void RTC_GetDate(uint32_t RTC_Format, RTC_DateType* RTC_DateStruct); + +/* Alarms (Alarm A and Alarm B) configuration functions **********************/ +void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmType* RTC_AlarmStruct); +void RTC_AlarmStructInit(RTC_AlarmType* RTC_AlarmStruct); +void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmType* RTC_AlarmStruct); +ErrorStatus RTC_EnableAlarm(uint32_t RTC_Alarm, FunctionalState Cmd); +void RTC_ConfigAlarmSubSecond(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint32_t RTC_AlarmSubSecondMask); +uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm); + +/* WakeUp Timer configuration functions ***************************************/ +void RTC_ConfigWakeUpClock(uint32_t RTC_WakeUpClock); +void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter); +uint32_t RTC_GetWakeUpCounter(void); +ErrorStatus RTC_EnableWakeUp(FunctionalState Cmd); + +/* Daylight Saving configuration functions ************************************/ +void RTC_ConfigDayLightSaving(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation); +uint32_t RTC_GetStoreOperation(void); + +/* Output pin Configuration function ******************************************/ +void RTC_ConfigOutput(uint32_t RTC_Output, uint32_t RTC_OutputPolarity); + +/* Coarse and Smooth Calibration configuration functions **********************/ +ErrorStatus RTC_ConfigSmoothCalib(uint32_t RTC_SmoothCalibPeriod, + uint32_t RTC_SmoothCalibPlusPulses, + uint32_t RTC_SmouthCalibMinusPulsesValue); + + +/* RTC_Shift_control_synchonisation_functions *********************************/ +ErrorStatus RTC_ConfigSynchroShift(uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS); + +/* Interrupts and flags management functions **********************************/ +void RTC_ConfigInt(uint32_t RTC_INT, FunctionalState Cmd); +FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG); +void RTC_ClrFlag(uint32_t RTC_FLAG); +INTStatus RTC_GetITStatus(uint32_t RTC_INT); +void RTC_ClrIntPendingBit(uint32_t RTC_INT); + +#ifdef __cplusplus +} +#endif + +#endif /*__N32WB03X_RTC_H__ */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_spi.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_spi.h new file mode 100644 index 0000000..061716a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_spi.h @@ -0,0 +1,477 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_spi.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_SPI_H__ +#define __N32WB03X_SPI_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup SPI + * @{ + */ + +/** @addtogroup SPI_Exported_Types + * @{ + */ + +/** + * @brief SPI Init structure definition + */ + +typedef struct +{ + uint16_t DataDirection; /*!< Specifies the SPI unidirectional or bidirectional data mode. + This parameter can be a value of @ref SPI_data_direction */ + + uint16_t SpiMode; /*!< Specifies the SPI operating mode. + This parameter can be a value of @ref SPI_mode */ + + uint16_t DataLen; /*!< Specifies the SPI data size. + This parameter can be a value of @ref SPI_data_size */ + + uint16_t CLKPOL; /*!< Specifies the serial clock steady state. + This parameter can be a value of @ref SPI_Clock_Polarity */ + + uint16_t CLKPHA; /*!< Specifies the clock active edge for the bit capture. + This parameter can be a value of @ref SPI_Clock_Phase */ + + uint16_t NSS; /*!< Specifies whether the NSS signal is managed by + hardware (NSS pin) or by software using the SSI bit. + This parameter can be a value of @ref SPI_Slave_Select_management */ + + uint16_t BaudRatePres; /*!< Specifies the Baud Rate prescaler value which will be + used to configure the transmit and receive SCK clock. + This parameter can be a value of @ref SPI_BaudRate_Prescaler. + @note The communication clock is derived from the master + clock. The slave clock does not need to be set. */ + + uint16_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit. + This parameter can be a value of @ref SPI_MSB_LSB_transmission */ + + uint16_t CRCPoly; /*!< Specifies the polynomial used for the CRC calculation. */ +} SPI_InitType; + +/** + * @brief I2S Init structure definition + */ + +typedef struct +{ + uint16_t I2sMode; /*!< Specifies the I2S operating mode. + This parameter can be a value of @ref I2sMode */ + + uint16_t Standard; /*!< Specifies the standard used for the I2S communication. + This parameter can be a value of @ref Standard */ + + uint16_t DataFormat; /*!< Specifies the data format for the I2S communication. + This parameter can be a value of @ref I2S_Data_Format */ + + uint32_t AudioFrequency; /*!< Specifies the frequency selected for the I2S communication. + This parameter can be a value of @ref I2S_Audio_Frequency */ + + uint16_t CLKPOL; /*!< Specifies the idle state of the I2S clock. + This parameter can be a value of @ref I2S_Clock_Polarity */ +} I2S_InitType; + +/** + * @} + */ + +/** @addtogroup SPI_Exported_Constants + * @{ + */ + +#define IS_SPI_PERIPH(PERIPH) (((PERIPH) == SPI1) || ((PERIPH) == SPI2)) + +#define IS_SPI_I2S_PERIPH(PERIPH) (((PERIPH) == SPI1)) + +/** @addtogroup SPI_data_direction + * @{ + */ + +#define SPI_DIR_DOUBLELINE_FULLDUPLEX ((uint16_t)0x0000) +#define SPI_DIR_DOUBLELINE_RONLY ((uint16_t)0x0400) +#define SPI_DIR_SINGLELINE_RX ((uint16_t)0x8000) +#define SPI_DIR_SINGLELINE_TX ((uint16_t)0xC000) +#define IS_SPI_DIR_MODE(MODE) \ + (((MODE) == SPI_DIR_DOUBLELINE_FULLDUPLEX) || ((MODE) == SPI_DIR_DOUBLELINE_RONLY) \ + || ((MODE) == SPI_DIR_SINGLELINE_RX) || ((MODE) == SPI_DIR_SINGLELINE_TX)) +/** + * @} + */ + +/** @addtogroup SPI_mode + * @{ + */ + +#define SPI_MODE_MASTER ((uint16_t)0x0104) +#define SPI_MODE_SLAVE ((uint16_t)0x0000) +#define IS_SPI_MODE(MODE) (((MODE) == SPI_MODE_MASTER) || ((MODE) == SPI_MODE_SLAVE)) +/** + * @} + */ + +/** @addtogroup SPI_data_size + * @{ + */ + +#define SPI_DATA_SIZE_16BITS ((uint16_t)0x0800) +#define SPI_DATA_SIZE_8BITS ((uint16_t)0x0000) +#define IS_SPI_DATASIZE(DATASIZE) (((DATASIZE) == SPI_DATA_SIZE_16BITS) || ((DATASIZE) == SPI_DATA_SIZE_8BITS)) +/** + * @} + */ + +/** @addtogroup SPI_Clock_Polarity + * @{ + */ + +#define SPI_CLKPOL_LOW ((uint16_t)0x0000) +#define SPI_CLKPOL_HIGH ((uint16_t)0x0002) +#define IS_SPI_CLKPOL(CPOL) (((CPOL) == SPI_CLKPOL_LOW) || ((CPOL) == SPI_CLKPOL_HIGH)) +/** + * @} + */ + +/** @addtogroup SPI_Clock_Phase + * @{ + */ + +#define SPI_CLKPHA_FIRST_EDGE ((uint16_t)0x0000) +#define SPI_CLKPHA_SECOND_EDGE ((uint16_t)0x0001) +#define IS_SPI_CLKPHA(CPHA) (((CPHA) == SPI_CLKPHA_FIRST_EDGE) || ((CPHA) == SPI_CLKPHA_SECOND_EDGE)) +/** + * @} + */ + +/** @addtogroup SPI_Slave_Select_management + * @{ + */ + +#define SPI_NSS_SOFT ((uint16_t)0x0200) +#define SPI_NSS_HARD ((uint16_t)0x0000) +#define IS_SPI_NSS(NSS) (((NSS) == SPI_NSS_SOFT) || ((NSS) == SPI_NSS_HARD)) +/** + * @} + */ + +/** @addtogroup SPI_BaudRate_Prescaler + * @{ + */ + +#define SPI_BR_PRESCALER_2 ((uint16_t)0x0000) +#define SPI_BR_PRESCALER_4 ((uint16_t)0x0008) +#define SPI_BR_PRESCALER_8 ((uint16_t)0x0010) +#define SPI_BR_PRESCALER_16 ((uint16_t)0x0018) +#define SPI_BR_PRESCALER_32 ((uint16_t)0x0020) +#define SPI_BR_PRESCALER_64 ((uint16_t)0x0028) +#define SPI_BR_PRESCALER_128 ((uint16_t)0x0030) +#define SPI_BR_PRESCALER_256 ((uint16_t)0x0038) +#define IS_SPI_BR_PRESCALER(PRESCALER) \ + (((PRESCALER) == SPI_BR_PRESCALER_2) || ((PRESCALER) == SPI_BR_PRESCALER_4) || ((PRESCALER) == SPI_BR_PRESCALER_8) \ + || ((PRESCALER) == SPI_BR_PRESCALER_16) || ((PRESCALER) == SPI_BR_PRESCALER_32) \ + || ((PRESCALER) == SPI_BR_PRESCALER_64) || ((PRESCALER) == SPI_BR_PRESCALER_128) \ + || ((PRESCALER) == SPI_BR_PRESCALER_256)) +/** + * @} + */ + +/** @addtogroup SPI_MSB_LSB_transmission + * @{ + */ + +#define SPI_FB_MSB ((uint16_t)0x0000) +#define SPI_FB_LSB ((uint16_t)0x0080) +#define IS_SPI_FIRST_BIT(BIT) (((BIT) == SPI_FB_MSB) || ((BIT) == SPI_FB_LSB)) +/** + * @} + */ + +/** @addtogroup I2sMode + * @{ + */ + +#define I2S_MODE_SlAVE_TX ((uint16_t)0x0000) +#define I2S_MODE_SlAVE_RX ((uint16_t)0x0100) +#define I2S_MODE_MASTER_TX ((uint16_t)0x0200) +#define I2S_MODE_MASTER_RX ((uint16_t)0x0300) +#define IS_I2S_MODE(MODE) \ + (((MODE) == I2S_MODE_SlAVE_TX) || ((MODE) == I2S_MODE_SlAVE_RX) || ((MODE) == I2S_MODE_MASTER_TX) \ + || ((MODE) == I2S_MODE_MASTER_RX)) +/** + * @} + */ + +/** @addtogroup Standard + * @{ + */ + +#define I2S_STD_PHILLIPS ((uint16_t)0x0000) +#define I2S_STD_MSB_ALIGN ((uint16_t)0x0010) +#define I2S_STD_LSB_ALIGN ((uint16_t)0x0020) +#define I2S_STD_PCM_SHORTFRAME ((uint16_t)0x0030) +#define I2S_STD_PCM_LONGFRAME ((uint16_t)0x00B0) +#define IS_I2S_STANDARD(STANDARD) \ + (((STANDARD) == I2S_STD_PHILLIPS) || ((STANDARD) == I2S_STD_MSB_ALIGN) || ((STANDARD) == I2S_STD_LSB_ALIGN) \ + || ((STANDARD) == I2S_STD_PCM_SHORTFRAME) || ((STANDARD) == I2S_STD_PCM_LONGFRAME)) +/** + * @} + */ + +/** @addtogroup I2S_Data_Format + * @{ + */ + +#define I2S_DATA_FMT_16BITS ((uint16_t)0x0000) +#define I2S_DATA_FMT_16BITS_EXTENDED ((uint16_t)0x0001) +#define I2S_DATA_FMT_24BITS ((uint16_t)0x0003) +#define I2S_DATA_FMT_32BITS ((uint16_t)0x0005) +#define IS_I2S_DATA_FMT(FORMAT) \ + (((FORMAT) == I2S_DATA_FMT_16BITS) || ((FORMAT) == I2S_DATA_FMT_16BITS_EXTENDED) \ + || ((FORMAT) == I2S_DATA_FMT_24BITS) || ((FORMAT) == I2S_DATA_FMT_32BITS)) +/** + * @} + */ + +/** @addtogroup I2S_Audio_Frequency + * @{ + */ + +#define I2S_AUDIO_FREQ_96K ((uint32_t)96000) +#define I2S_AUDIO_FREQ_48K ((uint32_t)48000) +#define I2S_AUDIO_FREQ_44K ((uint32_t)44100) +#define I2S_AUDIO_FREQ_32K ((uint32_t)32000) +#define I2S_AUDIO_FREQ_22K ((uint32_t)22050) +#define I2S_AUDIO_FREQ_16K ((uint32_t)16000) +#define I2S_AUDIO_FREQ_11K ((uint32_t)11025) +#define I2S_AUDIO_FREQ_8K ((uint32_t)8000) +#define I2S_AUDIO_FREQ_DEFAULT ((uint32_t)2) + +#define IS_I2S_AUDIO_FREQ(FREQ) \ + ((((FREQ) >= I2S_AUDIO_FREQ_8K) && ((FREQ) <= I2S_AUDIO_FREQ_96K)) || ((FREQ) == I2S_AUDIO_FREQ_DEFAULT)) +/** + * @} + */ + +/** @addtogroup I2S_Clock_Polarity + * @{ + */ + +#define I2S_CLKPOL_LOW ((uint16_t)0x0000) +#define I2S_CLKPOL_HIGH ((uint16_t)0x0008) +#define IS_I2S_CLKPOL(CPOL) (((CPOL) == I2S_CLKPOL_LOW) || ((CPOL) == I2S_CLKPOL_HIGH)) +/** + * @} + */ + +/** @addtogroup SPI_I2S_DMA_transfer_requests + * @{ + */ + +#define SPI_I2S_DMA_TX ((uint16_t)0x0002) +#define SPI_I2S_DMA_RX ((uint16_t)0x0001) +#define IS_SPI_I2S_DMA(DMAREQ) ((((DMAREQ) & (uint16_t)0xFFFC) == 0x00) && ((DMAREQ) != 0x00)) +/** + * @} + */ + +/** @addtogroup SPI_NSS_internal_software_management + * @{ + */ + +#define SPI_NSS_HIGH ((uint16_t)0x0100) +#define SPI_NSS_LOW ((uint16_t)0xFEFF) +#define IS_SPI_NSS_LEVEL(INTERNAL) (((INTERNAL) == SPI_NSS_HIGH) || ((INTERNAL) == SPI_NSS_LOW)) +/** + * @} + */ + +/** @addtogroup SPI_CRC_Transmit_Receive + * @{ + */ + +#define SPI_CRC_TX ((uint8_t)0x00) +#define SPI_CRC_RX ((uint8_t)0x01) +#define IS_SPI_CRC(CRC) (((CRC) == SPI_CRC_TX) || ((CRC) == SPI_CRC_RX)) +/** + * @} + */ + +/** @addtogroup SPI_direction_transmit_receive + * @{ + */ + +#define SPI_BIDIRECTION_RX ((uint16_t)0xBFFF) +#define SPI_BIDIRECTION_TX ((uint16_t)0x4000) +#define IS_SPI_BIDIRECTION(DIRECTION) (((DIRECTION) == SPI_BIDIRECTION_RX) || ((DIRECTION) == SPI_BIDIRECTION_TX)) +/** + * @} + */ + +/** @addtogroup SPI_I2S_interrupts_definition + * @{ + */ + +#define SPI_I2S_INT_TE ((uint8_t)0x71) +#define SPI_I2S_INT_RNE ((uint8_t)0x60) +#define SPI_I2S_INT_ERR ((uint8_t)0x50) +#define IS_SPI_I2S_CONFIG_INT(IT) (((IT) == SPI_I2S_INT_TE) || ((IT) == SPI_I2S_INT_RNE) || ((IT) == SPI_I2S_INT_ERR)) +#define SPI_I2S_INT_OVER ((uint8_t)0x56) +#define SPI_INT_MODERR ((uint8_t)0x55) +#define SPI_INT_CRCERR ((uint8_t)0x54) +#define I2S_INT_UNDER ((uint8_t)0x53) +#define IS_SPI_I2S_CLR_INT(IT) (((IT) == SPI_INT_CRCERR)) +#define IS_SPI_I2S_GET_INT(IT) \ + (((IT) == SPI_I2S_INT_RNE) || ((IT) == SPI_I2S_INT_TE) || ((IT) == I2S_INT_UNDER) || ((IT) == SPI_INT_CRCERR) \ + || ((IT) == SPI_INT_MODERR) || ((IT) == SPI_I2S_INT_OVER)) +/** + * @} + */ + +/** @addtogroup SPI_I2S_flags_definition + * @{ + */ + +#define SPI_I2S_RNE_FLAG ((uint16_t)0x0001) +#define SPI_I2S_TE_FLAG ((uint16_t)0x0002) +#define I2S_CHSIDE_FLAG ((uint16_t)0x0004) +#define I2S_UNDER_FLAG ((uint16_t)0x0008) +#define SPI_CRCERR_FLAG ((uint16_t)0x0010) +#define SPI_MODERR_FLAG ((uint16_t)0x0020) +#define SPI_I2S_OVER_FLAG ((uint16_t)0x0040) +#define SPI_I2S_BUSY_FLAG ((uint16_t)0x0080) +#define IS_SPI_I2S_CLR_FLAG(FLAG) (((FLAG) == SPI_CRCERR_FLAG)) +#define IS_SPI_I2S_GET_FLAG(FLAG) \ + (((FLAG) == SPI_I2S_BUSY_FLAG) || ((FLAG) == SPI_I2S_OVER_FLAG) || ((FLAG) == SPI_MODERR_FLAG) \ + || ((FLAG) == SPI_CRCERR_FLAG) || ((FLAG) == I2S_UNDER_FLAG) || ((FLAG) == I2S_CHSIDE_FLAG) \ + || ((FLAG) == SPI_I2S_TE_FLAG) || ((FLAG) == SPI_I2S_RNE_FLAG)) +/** + * @} + */ + +/** @addtogroup SPI_CRC_polynomial + * @{ + */ + +#define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL) ((POLYNOMIAL) >= 0x1) +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup SPI_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup SPI_Exported_Functions + * @{ + */ + +void SPI_I2S_DeInit(SPI_Module* SPIx); +void SPI_Init(SPI_Module* SPIx, SPI_InitType* SPI_InitStruct); +void I2S_Init(SPI_Module* SPIx, I2S_InitType* I2S_InitStruct); +void SPI_InitStruct(SPI_InitType* SPI_InitStruct); +void I2S_InitStruct(I2S_InitType* I2S_InitStruct); +void SPI_Enable(SPI_Module* SPIx, FunctionalState Cmd); +void I2S_Enable(SPI_Module* SPIx, FunctionalState Cmd); +void SPI_I2S_EnableInt(SPI_Module* SPIx, uint8_t SPI_I2S_IT, FunctionalState Cmd); +void SPI_I2S_EnableDma(SPI_Module* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState Cmd); +void SPI_I2S_TransmitData(SPI_Module* SPIx, uint16_t Data); +uint16_t SPI_I2S_ReceiveData(SPI_Module* SPIx); +void SPI_SetNssLevel(SPI_Module* SPIx, uint16_t SPI_NSSInternalSoft); +void SPI_SSOutputEnable(SPI_Module* SPIx, FunctionalState Cmd); +void SPI_ConfigDataLen(SPI_Module* SPIx, uint16_t DataLen); +void SPI_TransmitCrcNext(SPI_Module* SPIx); +void SPI_EnableCalculateCrc(SPI_Module* SPIx, FunctionalState Cmd); +uint16_t SPI_GetCRCDat(SPI_Module* SPIx, uint8_t SPI_CRC); +uint16_t SPI_GetCRCPoly(SPI_Module* SPIx); +void SPI_ConfigBidirectionalMode(SPI_Module* SPIx, uint16_t DataDirection); +FlagStatus SPI_I2S_GetStatus(SPI_Module* SPIx, uint16_t SPI_I2S_FLAG); +void SPI_I2S_ClrCRCErrFlag(SPI_Module* SPIx, uint16_t SPI_I2S_FLAG); +INTStatus SPI_I2S_GetIntStatus(SPI_Module* SPIx, uint8_t SPI_I2S_IT); +void SPI_I2S_ClrITPendingBit(SPI_Module* SPIx, uint8_t SPI_I2S_IT); + +#ifdef __cplusplus +} +#endif + +#endif /*__N32WB03X_SPI_H__ */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_tim.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_tim.h new file mode 100644 index 0000000..d7a1a63 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_tim.h @@ -0,0 +1,1078 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_tim.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_TIM_H__ +#define __N32WB03X_TIM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" +#include "stdbool.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup TIM + * @{ + */ + +/** @addtogroup TIM_Exported_Types + * @{ + */ + +/** + * @brief TIM Time Base Init structure definition + * @note This structure is used with all TIMx except for TIM6. + */ + +typedef struct +{ + uint16_t Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock. + This parameter can be a number between 0x0000 and 0xFFFF */ + + uint16_t CntMode; /*!< Specifies the counter mode. + This parameter can be a value of @ref TIM_Counter_Mode */ + + uint16_t Period; /*!< Specifies the period value to be loaded into the active + Auto-Reload Register at the next update event. + This parameter must be a number between 0x0000 and 0xFFFF. */ + + uint16_t ClkDiv; /*!< Specifies the clock division. + This parameter can be a value of @ref TIM_Clock_Division_CKD */ + + uint8_t RepetCnt; /*!< Specifies the repetition counter value. Each time the REPCNT downcounter + reaches zero, an update event is generated and counting restarts + from the REPCNT value (N). + This means in PWM mode that (N+1) corresponds to: + - the number of PWM periods in edge-aligned mode + - the number of half PWM period in center-aligned mode + This parameter must be a number between 0x00 and 0xFF. + @note This parameter is valid only for TIM1. */ + + bool CapCh1FromCompEn; /*!< channel 1 select capture in from comp if 1, from IOM if + Tim1, Tim3 valid*/ + bool CapCh2FromCompEn; /*!< channel 2 select capture in from comp if 1, from IOM if + Tim1, Tim3 valid*/ + bool CapCh3FromCompEn; /*!< channel 3 select capture in from comp if 1, from IOM if + Tim1, Tim3 valid*/ + bool CapEtrClrFromCompEn; /*!< etr clearref select from comp if 1, from ETR IOM if + Tim1, Tim3 valid*/ + bool CapEtrSelFromTscEn; /*!< etr select from TSC if 1, from IOM if Tim1, Tim3 valid*/ + +} TIM_TimeBaseInitType; + +/** + * @brief TIM Output Compare Init structure definition + */ + +typedef struct +{ + uint16_t OcMode; /*!< Specifies the TIM mode. + This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */ + + uint16_t OutputState; /*!< Specifies the TIM Output Compare state. + This parameter can be a value of @ref TIM_Output_Compare_state */ + + uint16_t OutputNState; /*!< Specifies the TIM complementary Output Compare state. + This parameter can be a value of @ref TIM_Output_Compare_N_state + @note This parameter is valid only for TIM1. */ + + uint16_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. + This parameter can be a number between 0x0000 and 0xFFFF */ + + uint16_t OcPolarity; /*!< Specifies the output polarity. + This parameter can be a value of @ref TIM_Output_Compare_Polarity */ + + uint16_t OcNPolarity; /*!< Specifies the complementary output polarity. + This parameter can be a value of @ref TIM_Output_Compare_N_Polarity + @note This parameter is valid only for TIM1. */ + + uint16_t OcIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state. + This parameter can be a value of @ref TIM_Output_Compare_Idle_State + @note This parameter is valid only for TIM1. */ + + uint16_t OcNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state. + This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State + @note This parameter is valid only for TIM1. */ +} OCInitType; + +/** + * @brief TIM Input Capture Init structure definition + */ + +typedef struct +{ + uint16_t Channel; /*!< Specifies the TIM channel. + This parameter can be a value of @ref Channel */ + + uint16_t IcPolarity; /*!< Specifies the active edge of the input signal. + This parameter can be a value of @ref TIM_Input_Capture_Polarity */ + + uint16_t IcSelection; /*!< Specifies the input. + This parameter can be a value of @ref TIM_Input_Capture_Selection */ + + uint16_t IcPrescaler; /*!< Specifies the Input Capture Prescaler. + This parameter can be a value of @ref TIM_Input_Capture_Prescaler */ + + uint16_t IcFilter; /*!< Specifies the input capture filter. + This parameter can be a number between 0x0 and 0xF */ +} TIM_ICInitType; + +/** + * @brief BKDT structure definition + * @note This structure is used only with TIM1. + */ + +typedef struct +{ + uint16_t OssrState; /*!< Specifies the Off-State selection used in Run mode. + This parameter can be a value of @ref OSSR_Off_State_Selection_for_Run_mode_state */ + + uint16_t OssiState; /*!< Specifies the Off-State used in Idle state. + This parameter can be a value of @ref OSSI_Off_State_Selection_for_Idle_mode_state */ + + uint16_t LockLevel; /*!< Specifies the LOCK level parameters. + This parameter can be a value of @ref Lock_level */ + + uint16_t DeadTime; /*!< Specifies the delay time between the switching-off and the + switching-on of the outputs. + This parameter can be a number between 0x00 and 0xFF */ + + uint16_t Break; /*!< Specifies whether the TIM Break input is enabled or not. + This parameter can be a value of @ref Break_Input_enable_disable */ + + uint16_t BreakPolarity; /*!< Specifies the TIM Break Input pin polarity. + This parameter can be a value of @ref Break_Polarity */ + + uint16_t AutomaticOutput; /*!< Specifies whether the TIM Automatic Output feature is enabled or not. + This parameter can be a value of @ref TIM_AOE_Bit_Set_Reset */ + bool IomBreakEn; /*!< EXTENDMODE valid, open iom as break in*/ + bool LockUpBreakEn; /*!< EXTENDMODE valid, open lockup(haldfault) as break in*/ + bool PvdBreakEn; /*!< EXTENDMODE valid, open pvd(sys voltage too high or too low) as break in*/ +} TIM_BDTRInitType; + +/** @addtogroup TIM_Exported_constants + * @{ + */ + +#define IsTimAllModule(PERIPH) \ + (((PERIPH) == TIM1) || ((PERIPH) == TIM3) || ((PERIPH) == TIM6)) + +/* LIST1: TIM 1 */ +#define IsTimList1Module(PERIPH) ((PERIPH) == TIM1) + +/* LIST2: TIM 1 */ +#define IsTimList2Module(PERIPH) ((PERIPH) == TIM1) + +/* LIST3: TIM 1, 3 */ +#define IsTimList3Module(PERIPH) \ + (((PERIPH) == TIM1) || ((PERIPH) == TIM3)) + +/* LIST4: TIM 1, 3 */ +#define IsTimList4Module(PERIPH) \ + (((PERIPH) == TIM1) || ((PERIPH) == TIM3)) + +/* LIST5: TIM 1, 3 */ +#define IsTimList5Module(PERIPH) \ + (((PERIPH) == TIM1) || ((PERIPH) == TIM3)) + +/* LIST6: TIM 1, 3 */ +#define IsTimList6Module(PERIPH) \ + (((PERIPH) == TIM1) || ((PERIPH) == TIM3)) + +/* LIST7: TIM 1, 3, 6 */ +#define IsTimList7Module(PERIPH) \ + (((PERIPH) == TIM1) || ((PERIPH) == TIM3) || ((PERIPH) == TIM6)) + +/* LIST8: TIM 1, 3 */ +#define IsTimList8Module(PERIPH) \ + (((PERIPH) == TIM1) || ((PERIPH) == TIM3)) + +/* LIST9: TIM 1, 3, 6 */ +#define IsTimList9Module(PERIPH) \ + (((PERIPH) == TIM1) || ((PERIPH) == TIM3) || ((PERIPH) == TIM6)) + +/** + * @} + */ + +/** @addtogroup TIM_Output_Compare_and_PWM_modes + * @{ + */ + +#define TIM_OCMODE_TIMING ((uint16_t)0x0000) +#define TIM_OCMODE_ACTIVE ((uint16_t)0x0010) +#define TIM_OCMODE_INACTIVE ((uint16_t)0x0020) +#define TIM_OCMODE_TOGGLE ((uint16_t)0x0030) +#define TIM_OCMODE_PWM1 ((uint16_t)0x0060) +#define TIM_OCMODE_PWM2 ((uint16_t)0x0070) +#define IsTimOcMode(MODE) \ + (((MODE) == TIM_OCMODE_TIMING) || ((MODE) == TIM_OCMODE_ACTIVE) || ((MODE) == TIM_OCMODE_INACTIVE) \ + || ((MODE) == TIM_OCMODE_TOGGLE) || ((MODE) == TIM_OCMODE_PWM1) || ((MODE) == TIM_OCMODE_PWM2)) +#define IsTimOc(MODE) \ + (((MODE) == TIM_OCMODE_TIMING) || ((MODE) == TIM_OCMODE_ACTIVE) || ((MODE) == TIM_OCMODE_INACTIVE) \ + || ((MODE) == TIM_OCMODE_TOGGLE) || ((MODE) == TIM_OCMODE_PWM1) || ((MODE) == TIM_OCMODE_PWM2) \ + || ((MODE) == TIM_FORCED_ACTION_ACTIVE) || ((MODE) == TIM_FORCED_ACTION_INACTIVE)) +/** + * @} + */ + +/** @addtogroup TIM_One_Pulse_Mode + * @{ + */ + +#define TIM_OPMODE_SINGLE ((uint16_t)0x0008) +#define TIM_OPMODE_REPET ((uint16_t)0x0000) +#define IsTimOpMOde(MODE) (((MODE) == TIM_OPMODE_SINGLE) || ((MODE) == TIM_OPMODE_REPET)) +/** + * @} + */ + +/** @addtogroup Channel + * @{ + */ + +#define TIM_CH_1 ((uint16_t)0x0000) +#define TIM_CH_2 ((uint16_t)0x0004) +#define TIM_CH_3 ((uint16_t)0x0008) +#define TIM_CH_4 ((uint16_t)0x000C) +#define IsTimCh(CHANNEL) \ + (((CHANNEL) == TIM_CH_1) || ((CHANNEL) == TIM_CH_2) || ((CHANNEL) == TIM_CH_3) || ((CHANNEL) == TIM_CH_4)) +#define IsTimPwmInCh(CHANNEL) (((CHANNEL) == TIM_CH_1) || ((CHANNEL) == TIM_CH_2)) +#define IsTimComplementaryCh(CHANNEL) (((CHANNEL) == TIM_CH_1) || ((CHANNEL) == TIM_CH_2) || ((CHANNEL) == TIM_CH_3)) +/** + * @} + */ + +/** @addtogroup TIM_Clock_Division_CKD + * @{ + */ + +#define TIM_CLK_DIV1 ((uint16_t)0x0000) +#define TIM_CLK_DIV2 ((uint16_t)0x0100) +#define TIM_CLK_DIV4 ((uint16_t)0x0200) +#define IsTimClkDiv(DIV) (((DIV) == TIM_CLK_DIV1) || ((DIV) == TIM_CLK_DIV2) || ((DIV) == TIM_CLK_DIV4)) +/** + * @} + */ + +/** @addtogroup TIM_Counter_Mode + * @{ + */ + +#define TIM_CNT_MODE_UP ((uint16_t)0x0000) +#define TIM_CNT_MODE_DOWN ((uint16_t)0x0010) +#define TIM_CNT_MODE_CENTER_ALIGN1 ((uint16_t)0x0020) +#define TIM_CNT_MODE_CENTER_ALIGN2 ((uint16_t)0x0040) +#define TIM_CNT_MODE_CENTER_ALIGN3 ((uint16_t)0x0060) +#define IsTimCntMode(MODE) \ + (((MODE) == TIM_CNT_MODE_UP) || ((MODE) == TIM_CNT_MODE_DOWN) || ((MODE) == TIM_CNT_MODE_CENTER_ALIGN1) \ + || ((MODE) == TIM_CNT_MODE_CENTER_ALIGN2) || ((MODE) == TIM_CNT_MODE_CENTER_ALIGN3)) +/** + * @} + */ + +/** @addtogroup TIM_Output_Compare_Polarity + * @{ + */ + +#define TIM_OC_POLARITY_HIGH ((uint16_t)0x0000) +#define TIM_OC_POLARITY_LOW ((uint16_t)0x0002) +#define IsTimOcPolarity(POLARITY) (((POLARITY) == TIM_OC_POLARITY_HIGH) || ((POLARITY) == TIM_OC_POLARITY_LOW)) +/** + * @} + */ + +/** @addtogroup TIM_Output_Compare_N_Polarity + * @{ + */ + +#define TIM_OCN_POLARITY_HIGH ((uint16_t)0x0000) +#define TIM_OCN_POLARITY_LOW ((uint16_t)0x0008) +#define IsTimOcnPolarity(POLARITY) (((POLARITY) == TIM_OCN_POLARITY_HIGH) || ((POLARITY) == TIM_OCN_POLARITY_LOW)) +/** + * @} + */ + +/** @addtogroup TIM_Output_Compare_state + * @{ + */ + +#define TIM_OUTPUT_STATE_DISABLE ((uint16_t)0x0000) +#define TIM_OUTPUT_STATE_ENABLE ((uint16_t)0x0001) +#define IsTimOutputState(STATE) (((STATE) == TIM_OUTPUT_STATE_DISABLE) || ((STATE) == TIM_OUTPUT_STATE_ENABLE)) +/** + * @} + */ + +/** @addtogroup TIM_Output_Compare_N_state + * @{ + */ + +#define TIM_OUTPUT_NSTATE_DISABLE ((uint16_t)0x0000) +#define TIM_OUTPUT_NSTATE_ENABLE ((uint16_t)0x0004) +#define IsTimOutputNState(STATE) (((STATE) == TIM_OUTPUT_NSTATE_DISABLE) || ((STATE) == TIM_OUTPUT_NSTATE_ENABLE)) +/** + * @} + */ + +/** @addtogroup TIM_Capture_Compare_state + * @{ + */ + +#define TIM_CAP_CMP_ENABLE ((uint16_t)0x0001) +#define TIM_CAP_CMP_DISABLE ((uint16_t)0x0000) +#define IsTimCapCmpState(CCX) (((CCX) == TIM_CAP_CMP_ENABLE) || ((CCX) == TIM_CAP_CMP_DISABLE)) +/** + * @} + */ + +/** @addtogroup TIM_Capture_Compare_N_state + * @{ + */ + +#define TIM_CAP_CMP_N_ENABLE ((uint16_t)0x0004) +#define TIM_CAP_CMP_N_DISABLE ((uint16_t)0x0000) +#define IsTimCapCmpNState(CCXN) (((CCXN) == TIM_CAP_CMP_N_ENABLE) || ((CCXN) == TIM_CAP_CMP_N_DISABLE)) +/** + * @} + */ + +/** @addtogroup Break_Input_enable_disable + * @{ + */ + +#define TIM_BREAK_IN_ENABLE ((uint16_t)0x1000) +#define TIM_BREAK_IN_DISABLE ((uint16_t)0x0000) +#define IsTimBreakInState(STATE) (((STATE) == TIM_BREAK_IN_ENABLE) || ((STATE) == TIM_BREAK_IN_DISABLE)) +/** + * @} + */ + +/** @addtogroup Break_Polarity + * @{ + */ + +#define TIM_BREAK_POLARITY_LOW ((uint16_t)0x0000) +#define TIM_BREAK_POLARITY_HIGH ((uint16_t)0x2000) +#define IsTimBreakPalarity(POLARITY) (((POLARITY) == TIM_BREAK_POLARITY_LOW) || ((POLARITY) == TIM_BREAK_POLARITY_HIGH)) +/** + * @} + */ + +/** @addtogroup TIM_AOE_Bit_Set_Reset + * @{ + */ + +#define TIM_AUTO_OUTPUT_ENABLE ((uint16_t)0x4000) +#define TIM_AUTO_OUTPUT_DISABLE ((uint16_t)0x0000) +#define IsTimAutoOutputState(STATE) (((STATE) == TIM_AUTO_OUTPUT_ENABLE) || ((STATE) == TIM_AUTO_OUTPUT_DISABLE)) +/** + * @} + */ + +/** @addtogroup Lock_level + * @{ + */ + +#define TIM_LOCK_LEVEL_OFF ((uint16_t)0x0000) +#define TIM_LOCK_LEVEL_1 ((uint16_t)0x0100) +#define TIM_LOCK_LEVEL_2 ((uint16_t)0x0200) +#define TIM_LOCK_LEVEL_3 ((uint16_t)0x0300) +#define IsTimLockLevel(LEVEL) \ + (((LEVEL) == TIM_LOCK_LEVEL_OFF) || ((LEVEL) == TIM_LOCK_LEVEL_1) || ((LEVEL) == TIM_LOCK_LEVEL_2) \ + || ((LEVEL) == TIM_LOCK_LEVEL_3)) +/** + * @} + */ + +/** @addtogroup OSSI_Off_State_Selection_for_Idle_mode_state + * @{ + */ + +#define TIM_OSSI_STATE_ENABLE ((uint16_t)0x0400) +#define TIM_OSSI_STATE_DISABLE ((uint16_t)0x0000) +#define IsTimOssiState(STATE) (((STATE) == TIM_OSSI_STATE_ENABLE) || ((STATE) == TIM_OSSI_STATE_DISABLE)) +/** + * @} + */ + +/** @addtogroup OSSR_Off_State_Selection_for_Run_mode_state + * @{ + */ + +#define TIM_OSSR_STATE_ENABLE ((uint16_t)0x0800) +#define TIM_OSSR_STATE_DISABLE ((uint16_t)0x0000) +#define IsTimOssrState(STATE) (((STATE) == TIM_OSSR_STATE_ENABLE) || ((STATE) == TIM_OSSR_STATE_DISABLE)) +/** + * @} + */ + +/** @addtogroup TIM_Output_Compare_Idle_State + * @{ + */ + +#define TIM_OC_IDLE_STATE_SET ((uint16_t)0x0100) +#define TIM_OC_IDLE_STATE_RESET ((uint16_t)0x0000) +#define IsTimOcIdleState(STATE) (((STATE) == TIM_OC_IDLE_STATE_SET) || ((STATE) == TIM_OC_IDLE_STATE_RESET)) +/** + * @} + */ + +/** @addtogroup TIM_Output_Compare_N_Idle_State + * @{ + */ + +#define TIM_OCN_IDLE_STATE_SET ((uint16_t)0x0200) +#define TIM_OCN_IDLE_STATE_RESET ((uint16_t)0x0000) +#define IsTimOcnIdleState(STATE) (((STATE) == TIM_OCN_IDLE_STATE_SET) || ((STATE) == TIM_OCN_IDLE_STATE_RESET)) +/** + * @} + */ + +/** @addtogroup TIM_Input_Capture_Polarity + * @{ + */ + +#define TIM_IC_POLARITY_RISING ((uint16_t)0x0000) +#define TIM_IC_POLARITY_FALLING ((uint16_t)0x0002) +#define TIM_IC_POLARITY_BOTHEDGE ((uint16_t)0x000A) +#define IsTimIcPalaritySingleEdge(POLARITY) \ + (((POLARITY) == TIM_IC_POLARITY_RISING) || ((POLARITY) == TIM_IC_POLARITY_FALLING)) +#define IsTimIcPolarityAnyEdge(POLARITY) \ + (((POLARITY) == TIM_IC_POLARITY_RISING) || ((POLARITY) == TIM_IC_POLARITY_FALLING) \ + || ((POLARITY) == TIM_IC_POLARITY_BOTHEDGE)) +/** + * @} + */ + +/** @addtogroup TIM_Input_Capture_Selection + * @{ + */ + +#define TIM_IC_SELECTION_DIRECTTI \ + ((uint16_t)0x0001) /*!< TIM Input 1 or 3 is selected to be \ + connected to IC1, IC2, IC3 or IC4, respectively */ +#define TIM_IC_SELECTION_INDIRECTTI \ + ((uint16_t)0x0002) /*!< TIM Input 1 or 3 is selected to be \ + connected to IC2, IC1, IC4 or IC3, respectively. */ +#define TIM_IC_SELECTION_TRC ((uint16_t)0x0003) /*!< TIM Input 1 or 3 is selected to be connected to TRC. */ +#define IsTimIcSelection(SELECTION) \ + (((SELECTION) == TIM_IC_SELECTION_DIRECTTI) || ((SELECTION) == TIM_IC_SELECTION_INDIRECTTI) \ + || ((SELECTION) == TIM_IC_SELECTION_TRC)) +/** + * @} + */ + +/** @addtogroup TIM_Input_Capture_Prescaler + * @{ + */ + +#define TIM_IC_PSC_DIV1 ((uint16_t)0x0000) /*!< Capture performed each time an edge is detected on the capture input. \ + */ +#define TIM_IC_PSC_DIV2 ((uint16_t)0x0004) /*!< Capture performed once every 2 events. */ +#define TIM_IC_PSC_DIV4 ((uint16_t)0x0008) /*!< Capture performed once every 4 events. */ +#define TIM_IC_PSC_DIV8 ((uint16_t)0x000C) /*!< Capture performed once every 8 events. */ +#define IsTimIcPrescaler(PRESCALER) \ + (((PRESCALER) == TIM_IC_PSC_DIV1) || ((PRESCALER) == TIM_IC_PSC_DIV2) || ((PRESCALER) == TIM_IC_PSC_DIV4) \ + || ((PRESCALER) == TIM_IC_PSC_DIV8)) +/** + * @} + */ + +/** @addtogroup TIM_interrupt_sources + * @{ + */ + +#define TIM_INT_UPDATE ((uint16_t)0x0001) +#define TIM_INT_CC1 ((uint16_t)0x0002) +#define TIM_INT_CC2 ((uint16_t)0x0004) +#define TIM_INT_CC3 ((uint16_t)0x0008) +#define TIM_INT_CC4 ((uint16_t)0x0010) +#define TIM_INT_COM ((uint16_t)0x0020) +#define TIM_INT_TRIG ((uint16_t)0x0040) +#define TIM_INT_BREAK ((uint16_t)0x0080) +#define IsTimInt(IT) ((((IT) & (uint16_t)0xFF00) == 0x0000) && ((IT) != 0x0000)) + +#define IsTimGetInt(IT) \ + (((IT) == TIM_INT_UPDATE) || ((IT) == TIM_INT_CC1) || ((IT) == TIM_INT_CC2) || ((IT) == TIM_INT_CC3) \ + || ((IT) == TIM_INT_CC4) || ((IT) == TIM_INT_COM) || ((IT) == TIM_INT_TRIG) || ((IT) == TIM_INT_BREAK)) +/** + * @} + */ + +/** @addtogroup TIM_DMA_Base_address + * @{ + */ + +#define TIM_DMABASE_CTRL1 ((uint16_t)0x0000) +#define TIM_DMABASE_CTRL2 ((uint16_t)0x0001) +#define TIM_DMABASE_SMCTRL ((uint16_t)0x0002) +#define TIM_DMABASE_DMAINTEN ((uint16_t)0x0003) +#define TIM_DMABASE_STS ((uint16_t)0x0004) +#define TIM_DMABASE_EVTGEN ((uint16_t)0x0005) +#define TIM_DMABASE_CAPCMPMOD1 ((uint16_t)0x0006) +#define TIM_DMABASE_CAPCMPMOD2 ((uint16_t)0x0007) +#define TIM_DMABASE_CAPCMPEN ((uint16_t)0x0008) +#define TIM_DMABASE_CNT ((uint16_t)0x0009) +#define TIM_DMABASE_PSC ((uint16_t)0x000A) +#define TIM_DMABASE_AR ((uint16_t)0x000B) +#define TIM_DMABASE_REPCNT ((uint16_t)0x000C) +#define TIM_DMABASE_CAPCMPDAT1 ((uint16_t)0x000D) +#define TIM_DMABASE_CAPCMPDAT2 ((uint16_t)0x000E) +#define TIM_DMABASE_CAPCMPDAT3 ((uint16_t)0x000F) +#define TIM_DMABASE_CAPCMPDAT4 ((uint16_t)0x0010) +#define TIM_DMABASE_BKDT ((uint16_t)0x0011) +#define TIM_DMABASE_DMACTRL ((uint16_t)0x0012) +#define TIM_DMABASE_CAPCMPMOD3 ((uint16_t)0x0013) +#define TIM_DMABASE_CAPCMPDAT5 ((uint16_t)0x0014) +#define TIM_DMABASE_CAPCMPDAT6 ((uint16_t)0x0015) + +#define IsTimDmaBase(BASE) \ + (((BASE) == TIM_DMABASE_CTRL1) || ((BASE) == TIM_DMABASE_CTRL2) || ((BASE) == TIM_DMABASE_SMCTRL) \ + || ((BASE) == TIM_DMABASE_DMAINTEN) || ((BASE) == TIM_DMABASE_STS) || ((BASE) == TIM_DMABASE_EVTGEN) \ + || ((BASE) == TIM_DMABASE_CAPCMPMOD1) || ((BASE) == TIM_DMABASE_CAPCMPMOD2) || ((BASE) == TIM_DMABASE_CAPCMPMOD3) \ + || ((BASE) == TIM_DMABASE_CAPCMPEN) || ((BASE) == TIM_DMABASE_CNT) || ((BASE) == TIM_DMABASE_PSC) \ + || ((BASE) == TIM_DMABASE_AR) || ((BASE) == TIM_DMABASE_REPCNT) || ((BASE) == TIM_DMABASE_CAPCMPDAT1) \ + || ((BASE) == TIM_DMABASE_CAPCMPDAT2) || ((BASE) == TIM_DMABASE_CAPCMPDAT3) || ((BASE) == TIM_DMABASE_CAPCMPDAT4) \ + || ((BASE) == TIM_DMABASE_CAPCMPDAT5) || ((BASE) == TIM_DMABASE_CAPCMPDAT6) || ((BASE) == TIM_DMABASE_BKDT) \ + || ((BASE) == TIM_DMABASE_DMACTRL)) +/** + * @} + */ + +/** @addtogroup TIM_DMA_Burst_Length + * @{ + */ + +#define TIM_DMABURST_LENGTH_1TRANSFER ((uint16_t)0x0000) +#define TIM_DMABURST_LENGTH_2TRANSFERS ((uint16_t)0x0100) +#define TIM_DMABURST_LENGTH_3TRANSFERS ((uint16_t)0x0200) +#define TIM_DMABURST_LENGTH_4TRANSFERS ((uint16_t)0x0300) +#define TIM_DMABURST_LENGTH_5TRANSFERS ((uint16_t)0x0400) +#define TIM_DMABURST_LENGTH_6TRANSFERS ((uint16_t)0x0500) +#define TIM_DMABURST_LENGTH_7TRANSFERS ((uint16_t)0x0600) +#define TIM_DMABURST_LENGTH_8TRANSFERS ((uint16_t)0x0700) +#define TIM_DMABURST_LENGTH_9TRANSFERS ((uint16_t)0x0800) +#define TIM_DMABURST_LENGTH_10TRANSFERS ((uint16_t)0x0900) +#define TIM_DMABURST_LENGTH_11TRANSFERS ((uint16_t)0x0A00) +#define TIM_DMABURST_LENGTH_12TRANSFERS ((uint16_t)0x0B00) +#define TIM_DMABURST_LENGTH_13TRANSFERS ((uint16_t)0x0C00) +#define TIM_DMABURST_LENGTH_14TRANSFERS ((uint16_t)0x0D00) +#define TIM_DMABURST_LENGTH_15TRANSFERS ((uint16_t)0x0E00) +#define TIM_DMABURST_LENGTH_16TRANSFERS ((uint16_t)0x0F00) +#define TIM_DMABURST_LENGTH_17TRANSFERS ((uint16_t)0x1000) +#define TIM_DMABURST_LENGTH_18TRANSFERS ((uint16_t)0x1100) +#define TIM_DMABURST_LENGTH_19TRANSFERS ((uint16_t)0x1200) +#define TIM_DMABURST_LENGTH_20TRANSFERS ((uint16_t)0x1300) +#define TIM_DMABURST_LENGTH_21TRANSFERS ((uint16_t)0x1400) +#define IsTimDmaLength(LENGTH) \ + (((LENGTH) == TIM_DMABURST_LENGTH_1TRANSFER) || ((LENGTH) == TIM_DMABURST_LENGTH_2TRANSFERS) \ + || ((LENGTH) == TIM_DMABURST_LENGTH_3TRANSFERS) || ((LENGTH) == TIM_DMABURST_LENGTH_4TRANSFERS) \ + || ((LENGTH) == TIM_DMABURST_LENGTH_5TRANSFERS) || ((LENGTH) == TIM_DMABURST_LENGTH_6TRANSFERS) \ + || ((LENGTH) == TIM_DMABURST_LENGTH_7TRANSFERS) || ((LENGTH) == TIM_DMABURST_LENGTH_8TRANSFERS) \ + || ((LENGTH) == TIM_DMABURST_LENGTH_9TRANSFERS) || ((LENGTH) == TIM_DMABURST_LENGTH_10TRANSFERS) \ + || ((LENGTH) == TIM_DMABURST_LENGTH_11TRANSFERS) || ((LENGTH) == TIM_DMABURST_LENGTH_12TRANSFERS) \ + || ((LENGTH) == TIM_DMABURST_LENGTH_13TRANSFERS) || ((LENGTH) == TIM_DMABURST_LENGTH_14TRANSFERS) \ + || ((LENGTH) == TIM_DMABURST_LENGTH_15TRANSFERS) || ((LENGTH) == TIM_DMABURST_LENGTH_16TRANSFERS) \ + || ((LENGTH) == TIM_DMABURST_LENGTH_17TRANSFERS) || ((LENGTH) == TIM_DMABURST_LENGTH_18TRANSFERS) \ + || ((LENGTH) == TIM_DMABURST_LENGTH_19TRANSFERS) || ((LENGTH) == TIM_DMABURST_LENGTH_20TRANSFERS) \ + || ((LENGTH) == TIM_DMABURST_LENGTH_21TRANSFERS)) +/** + * @} + */ + +/** @addtogroup TIM_DMA_sources + * @{ + */ + +#define TIM_DMA_UPDATE ((uint16_t)0x0100) +#define TIM_DMA_CC1 ((uint16_t)0x0200) +#define TIM_DMA_CC2 ((uint16_t)0x0400) +#define TIM_DMA_CC3 ((uint16_t)0x0800) +#define TIM_DMA_CC4 ((uint16_t)0x1000) +#define TIM_DMA_COM ((uint16_t)0x2000) +#define TIM_DMA_TRIG ((uint16_t)0x4000) +#define IsTimDmaSrc(SOURCE) ((((SOURCE) & (uint16_t)0x80FF) == 0x0000) && ((SOURCE) != 0x0000)) + +/** + * @} + */ + +/** @addtogroup TIM_External_Trigger_Prescaler + * @{ + */ + +#define TIM_EXT_TRG_PSC_OFF ((uint16_t)0x0000) +#define TIM_EXT_TRG_PSC_DIV2 ((uint16_t)0x1000) +#define TIM_EXT_TRG_PSC_DIV4 ((uint16_t)0x2000) +#define TIM_EXT_TRG_PSC_DIV8 ((uint16_t)0x3000) +#define IsTimExtPreDiv(PRESCALER) \ + (((PRESCALER) == TIM_EXT_TRG_PSC_OFF) || ((PRESCALER) == TIM_EXT_TRG_PSC_DIV2) \ + || ((PRESCALER) == TIM_EXT_TRG_PSC_DIV4) || ((PRESCALER) == TIM_EXT_TRG_PSC_DIV8)) +/** + * @} + */ + +/** @addtogroup TIM_Internal_Trigger_Selection + * @{ + */ + +#define TIM_TRIG_SEL_IN_TR0 ((uint16_t)0x0000) +#define TIM_TRIG_SEL_IN_TR1 ((uint16_t)0x0010) +#define TIM_TRIG_SEL_IN_TR2 ((uint16_t)0x0020) +#define TIM_TRIG_SEL_IN_TR3 ((uint16_t)0x0030) +#define TIM_TRIG_SEL_TI1F_ED ((uint16_t)0x0040) +#define TIM_TRIG_SEL_TI1FP1 ((uint16_t)0x0050) +#define TIM_TRIG_SEL_TI2FP2 ((uint16_t)0x0060) +#define TIM_TRIG_SEL_ETRF ((uint16_t)0x0070) +#define IsTimTrigSel(SELECTION) \ + (((SELECTION) == TIM_TRIG_SEL_IN_TR0) || ((SELECTION) == TIM_TRIG_SEL_IN_TR1) \ + || ((SELECTION) == TIM_TRIG_SEL_IN_TR2) || ((SELECTION) == TIM_TRIG_SEL_IN_TR3) \ + || ((SELECTION) == TIM_TRIG_SEL_TI1F_ED) || ((SELECTION) == TIM_TRIG_SEL_TI1FP1) \ + || ((SELECTION) == TIM_TRIG_SEL_TI2FP2) || ((SELECTION) == TIM_TRIG_SEL_ETRF)) +#define IsTimInterTrigSel(SELECTION) \ + (((SELECTION) == TIM_TRIG_SEL_IN_TR0) || ((SELECTION) == TIM_TRIG_SEL_IN_TR1) \ + || ((SELECTION) == TIM_TRIG_SEL_IN_TR2) || ((SELECTION) == TIM_TRIG_SEL_IN_TR3)) +/** + * @} + */ + +/** @addtogroup TIM_TIx_External_Clock_Source + * @{ + */ + +#define TIM_EXT_CLK_SRC_TI1 ((uint16_t)0x0050) +#define TIM_EXT_CLK_SRC_TI2 ((uint16_t)0x0060) +#define TIM_EXT_CLK_SRC_TI1ED ((uint16_t)0x0040) +#define IsTimExtClkSrc(SOURCE) \ + (((SOURCE) == TIM_EXT_CLK_SRC_TI1) || ((SOURCE) == TIM_EXT_CLK_SRC_TI2) || ((SOURCE) == TIM_EXT_CLK_SRC_TI1ED)) +/** + * @} + */ + +/** @addtogroup TIM_External_Trigger_Polarity + * @{ + */ +#define TIM_EXT_TRIG_POLARITY_INVERTED ((uint16_t)0x8000) +#define TIM_EXT_TRIG_POLARITY_NONINVERTED ((uint16_t)0x0000) +#define IsTimExtTrigPolarity(POLARITY) \ + (((POLARITY) == TIM_EXT_TRIG_POLARITY_INVERTED) || ((POLARITY) == TIM_EXT_TRIG_POLARITY_NONINVERTED)) +/** + * @} + */ + +/** @addtogroup TIM_Prescaler_Reload_Mode + * @{ + */ + +#define TIM_PSC_RELOAD_MODE_UPDATE ((uint16_t)0x0000) +#define TIM_PSC_RELOAD_MODE_IMMEDIATE ((uint16_t)0x0001) +#define IsTimPscReloadMode(RELOAD) \ + (((RELOAD) == TIM_PSC_RELOAD_MODE_UPDATE) || ((RELOAD) == TIM_PSC_RELOAD_MODE_IMMEDIATE)) +/** + * @} + */ + +/** @addtogroup TIM_Forced_Action + * @{ + */ + +#define TIM_FORCED_ACTION_ACTIVE ((uint16_t)0x0050) +#define TIM_FORCED_ACTION_INACTIVE ((uint16_t)0x0040) +#define IsTimForceActive(OPERATE) (((OPERATE) == TIM_FORCED_ACTION_ACTIVE) || ((OPERATE) == TIM_FORCED_ACTION_INACTIVE)) +/** + * @} + */ + +/** @addtogroup TIM_Encoder_Mode + * @{ + */ + +#define TIM_ENCODE_MODE_TI1 ((uint16_t)0x0001) +#define TIM_ENCODE_MODE_TI2 ((uint16_t)0x0002) +#define TIM_ENCODE_MODE_TI12 ((uint16_t)0x0003) +#define IsTimEncodeMode(MODE) \ + (((MODE) == TIM_ENCODE_MODE_TI1) || ((MODE) == TIM_ENCODE_MODE_TI2) || ((MODE) == TIM_ENCODE_MODE_TI12)) +/** + * @} + */ + +/** @addtogroup TIM_Event_Source + * @{ + */ + +#define TIM_EVT_SRC_UPDATE ((uint16_t)0x0001) +#define TIM_EVT_SRC_CC1 ((uint16_t)0x0002) +#define TIM_EVT_SRC_CC2 ((uint16_t)0x0004) +#define TIM_EVT_SRC_CC3 ((uint16_t)0x0008) +#define TIM_EVT_SRC_CC4 ((uint16_t)0x0010) +#define TIM_EVT_SRC_COM ((uint16_t)0x0020) +#define TIM_EVT_SRC_TRIG ((uint16_t)0x0040) +#define TIM_EVT_SRC_BREAK ((uint16_t)0x0080) +#define IsTimEvtSrc(SOURCE) ((((SOURCE) & (uint16_t)0xFF00) == 0x0000) && ((SOURCE) != 0x0000)) + +/** + * @} + */ + +/** @addtogroup TIM_Update_Source + * @{ + */ + +#define TIM_UPDATE_SRC_GLOBAL \ + ((uint16_t)0x0000) /*!< Source of update is the counter overflow/underflow \ + or the setting of UG bit, or an update generation \ + through the slave mode controller. */ +#define TIM_UPDATE_SRC_REGULAr ((uint16_t)0x0001) /*!< Source of update is counter overflow/underflow. */ +#define IsTimUpdateSrc(SOURCE) (((SOURCE) == TIM_UPDATE_SRC_GLOBAL) || ((SOURCE) == TIM_UPDATE_SRC_REGULAr)) +/** + * @} + */ + +/** @addtogroup TIM_Output_Compare_Preload_State + * @{ + */ + +#define TIM_OC_PRE_LOAD_ENABLE ((uint16_t)0x0008) +#define TIM_OC_PRE_LOAD_DISABLE ((uint16_t)0x0000) +#define IsTimOcPreLoadState(STATE) (((STATE) == TIM_OC_PRE_LOAD_ENABLE) || ((STATE) == TIM_OC_PRE_LOAD_DISABLE)) +/** + * @} + */ + +/** @addtogroup TIM_Output_Compare_Fast_State + * @{ + */ + +#define TIM_OC_FAST_ENABLE ((uint16_t)0x0004) +#define TIM_OC_FAST_DISABLE ((uint16_t)0x0000) +#define IsTimOcFastState(STATE) (((STATE) == TIM_OC_FAST_ENABLE) || ((STATE) == TIM_OC_FAST_DISABLE)) + +/** + * @} + */ + +/** @addtogroup TIM_Output_Compare_Clear_State + * @{ + */ + +#define TIM_OC_CLR_ENABLE ((uint16_t)0x0080) +#define TIM_OC_CLR_DISABLE ((uint16_t)0x0000) +#define IsTimOcClrState(STATE) (((STATE) == TIM_OC_CLR_ENABLE) || ((STATE) == TIM_OC_CLR_DISABLE)) +/** + * @} + */ + +/** @addtogroup TIM_Trigger_Output_Source + * @{ + */ + +#define TIM_TRGO_SRC_RESET ((uint16_t)0x0000) +#define TIM_TRGO_SRC_ENABLE ((uint16_t)0x0010) +#define TIM_TRGO_SRC_UPDATE ((uint16_t)0x0020) +#define TIM_TRGO_SRC_OC1 ((uint16_t)0x0030) +#define TIM_TRGO_SRC_OC1REF ((uint16_t)0x0040) +#define TIM_TRGO_SRC_OC2REF ((uint16_t)0x0050) +#define TIM_TRGO_SRC_OC3REF ((uint16_t)0x0060) +#define TIM_TRGO_SRC_OC4REF ((uint16_t)0x0070) +#define IsTimTrgoSrc(SOURCE) \ + (((SOURCE) == TIM_TRGO_SRC_RESET) || ((SOURCE) == TIM_TRGO_SRC_ENABLE) || ((SOURCE) == TIM_TRGO_SRC_UPDATE) \ + || ((SOURCE) == TIM_TRGO_SRC_OC1) || ((SOURCE) == TIM_TRGO_SRC_OC1REF) || ((SOURCE) == TIM_TRGO_SRC_OC2REF) \ + || ((SOURCE) == TIM_TRGO_SRC_OC3REF) || ((SOURCE) == TIM_TRGO_SRC_OC4REF)) +/** + * @} + */ + +/** @addtogroup TIM_Slave_Mode + * @{ + */ + +#define TIM_SLAVE_MODE_RESET ((uint16_t)0x0004) +#define TIM_SLAVE_MODE_GATED ((uint16_t)0x0005) +#define TIM_SLAVE_MODE_TRIG ((uint16_t)0x0006) +#define TIM_SLAVE_MODE_EXT1 ((uint16_t)0x0007) +#define IsTimSlaveMode(MODE) \ + (((MODE) == TIM_SLAVE_MODE_RESET) || ((MODE) == TIM_SLAVE_MODE_GATED) || ((MODE) == TIM_SLAVE_MODE_TRIG) \ + || ((MODE) == TIM_SLAVE_MODE_EXT1)) +/** + * @} + */ + +/** @addtogroup TIM_Master_Slave_Mode + * @{ + */ + +#define TIM_MASTER_SLAVE_MODE_ENABLE ((uint16_t)0x0080) +#define TIM_MASTER_SLAVE_MODE_DISABLE ((uint16_t)0x0000) +#define IsTimMasterSlaveMode(STATE) \ + (((STATE) == TIM_MASTER_SLAVE_MODE_ENABLE) || ((STATE) == TIM_MASTER_SLAVE_MODE_DISABLE)) +/** + * @} + */ + +/** @addtogroup TIM_Flags + * @{ + */ + +#define TIM_FLAG_UPDATE ((uint32_t)0x0001) +#define TIM_FLAG_CC1 ((uint32_t)0x0002) +#define TIM_FLAG_CC2 ((uint32_t)0x0004) +#define TIM_FLAG_CC3 ((uint32_t)0x0008) +#define TIM_FLAG_CC4 ((uint32_t)0x0010) +#define TIM_FLAG_COM ((uint32_t)0x0020) +#define TIM_FLAG_TRIG ((uint32_t)0x0040) +#define TIM_FLAG_BREAK ((uint32_t)0x0080) +#define TIM_FLAG_CC1OF ((uint32_t)0x0200) +#define TIM_FLAG_CC2OF ((uint32_t)0x0400) +#define TIM_FLAG_CC3OF ((uint32_t)0x0800) +#define TIM_FLAG_CC4OF ((uint32_t)0x1000) +#define TIM_FLAG_CC5 ((uint32_t)0x010000) +#define TIM_FLAG_CC6 ((uint32_t)0x020000) + +#define IsTimGetFlag(FLAG) \ + (((FLAG) == TIM_FLAG_UPDATE) || ((FLAG) == TIM_FLAG_CC1) || ((FLAG) == TIM_FLAG_CC2) || ((FLAG) == TIM_FLAG_CC3) \ + || ((FLAG) == TIM_FLAG_CC4) || ((FLAG) == TIM_FLAG_COM) || ((FLAG) == TIM_FLAG_TRIG) \ + || ((FLAG) == TIM_FLAG_BREAK) || ((FLAG) == TIM_FLAG_CC1OF) || ((FLAG) == TIM_FLAG_CC2OF) \ + || ((FLAG) == TIM_FLAG_CC3OF) || ((FLAG) == TIM_FLAG_CC4OF) || ((FLAG) == TIM_FLAG_CC5) \ + || ((FLAG) == TIM_FLAG_CC6)) + +#define IsTimClrFlag(TIM_FLAG) ((((TIM_FLAG) & (uint16_t)0xE100) == 0x0000) && ((TIM_FLAG) != 0x0000)) +/** + * @} + */ + +/** @addtogroup TIM_Input_Capture_Filer_Value + * @{ + */ + +#define IsTimInCapFilter(ICFILTER) ((ICFILTER) <= 0xF) +/** + * @} + */ + +/** @addtogroup TIM_External_Trigger_Filter + * @{ + */ + +#define IsTimExtTrigFilter(EXTFILTER) ((EXTFILTER) <= 0xF) +/** + * @} + */ + +/** @addtogroup TIM_Legacy + * @{ + */ + +#define TIM_DMA_BURST_LEN_1BYTE TIM_DMABURST_LENGTH_1TRANSFER +#define TIM_DMA_BURST_LEN_2BYTES TIM_DMABURST_LENGTH_2TRANSFERS +#define TIM_DMA_BURST_LEN_3BYTES TIM_DMABURST_LENGTH_3TRANSFERS +#define TIM_DMA_BURST_LEN_4BYTES TIM_DMABURST_LENGTH_4TRANSFERS +#define TIM_DMA_BURST_LEN_5BYTES TIM_DMABURST_LENGTH_5TRANSFERS +#define TIM_DMA_BURST_LEN_6BYTES TIM_DMABURST_LENGTH_6TRANSFERS +#define TIM_DMA_BURST_LEN_7BYTES TIM_DMABURST_LENGTH_7TRANSFERS +#define TIM_DMA_BURST_LEN_8BYTES TIM_DMABURST_LENGTH_8TRANSFERS +#define TIM_DMA_BURST_LEN_9BYTES TIM_DMABURST_LENGTH_9TRANSFERS +#define TIM_DMA_BURST_LEN_10BYTES TIM_DMABURST_LENGTH_10TRANSFERS +#define TIM_DMA_BURST_LEN_11BYTES TIM_DMABURST_LENGTH_11TRANSFERS +#define TIM_DMA_BURST_LEN_12BYTES TIM_DMABURST_LENGTH_12TRANSFERS +#define TIM_DMA_BURST_LEN_13BYTES TIM_DMABURST_LENGTH_13TRANSFERS +#define TIM_DMA_BURST_LEN_14BYTES TIM_DMABURST_LENGTH_14TRANSFERS +#define TIM_DMA_BURST_LEN_15BYTES TIM_DMABURST_LENGTH_15TRANSFERS +#define TIM_DMA_BURST_LEN_16BYTES TIM_DMABURST_LENGTH_16TRANSFERS +#define TIM_DMA_BURST_LEN_17BYTES TIM_DMABURST_LENGTH_17TRANSFERS +#define TIM_DMA_BURST_LEN_18BYTES TIM_DMABURST_LENGTH_18TRANSFERS +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup TIM_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup TIM_Exported_Functions + * @{ + */ + +void TIM_DeInit(TIM_Module* TIMx); +void TIM_InitTimeBase(TIM_Module* TIMx, TIM_TimeBaseInitType* TIM_TimeBaseInitStruct); +void TIM_InitOc1(TIM_Module* TIMx, OCInitType* TIM_OCInitStruct); +void TIM_InitOc2(TIM_Module* TIMx, OCInitType* TIM_OCInitStruct); +void TIM_InitOc3(TIM_Module* TIMx, OCInitType* TIM_OCInitStruct); +void TIM_InitOc4(TIM_Module* TIMx, OCInitType* TIM_OCInitStruct); +void TIM_ICInit(TIM_Module* TIMx, TIM_ICInitType* TIM_ICInitStruct); +void TIM_ConfigPwmIc(TIM_Module* TIMx, TIM_ICInitType* TIM_ICInitStruct); +void TIM_ConfigBkdt(TIM_Module* TIMx, TIM_BDTRInitType* TIM_BDTRInitStruct); +void TIM_InitTimBaseStruct(TIM_TimeBaseInitType* TIM_TimeBaseInitStruct); +void TIM_InitOcStruct(OCInitType* TIM_OCInitStruct); +void TIM_InitIcStruct(TIM_ICInitType* TIM_ICInitStruct); +void TIM_InitBkdtStruct(TIM_BDTRInitType* TIM_BDTRInitStruct); +void TIM_Enable(TIM_Module* TIMx, FunctionalState Cmd); +void TIM_EnableCtrlPwmOutputs(TIM_Module* TIMx, FunctionalState Cmd); +void TIM_ConfigInt(TIM_Module* TIMx, uint16_t TIM_IT, FunctionalState Cmd); +void TIM_GenerateEvent(TIM_Module* TIMx, uint16_t TIM_EventSource); +void TIM_ConfigDma(TIM_Module* TIMx, uint16_t TIM_DMABase, uint16_t TIM_DMABurstLength); +void TIM_EnableDma(TIM_Module* TIMx, uint16_t TIM_DMASource, FunctionalState Cmd); +void TIM_ConfigInternalClk(TIM_Module* TIMx); +void TIM_ConfigInternalTrigToExt(TIM_Module* TIMx, uint16_t TIM_InputTriggerSource); +void TIM_ConfigExtTrigAsClk(TIM_Module* TIMx, + uint16_t TIM_TIxExternalCLKSource, + uint16_t IcPolarity, + uint16_t ICFilter); +void TIM_ConfigExtClkMode1(TIM_Module* TIMx, + uint16_t TIM_ExtTRGPrescaler, + uint16_t TIM_ExtTRGPolarity, + uint16_t ExtTRGFilter); +void TIM_ConfigExtClkMode2(TIM_Module* TIMx, + uint16_t TIM_ExtTRGPrescaler, + uint16_t TIM_ExtTRGPolarity, + uint16_t ExtTRGFilter); +void TIM_ConfigExtTrig(TIM_Module* TIMx, + uint16_t TIM_ExtTRGPrescaler, + uint16_t TIM_ExtTRGPolarity, + uint16_t ExtTRGFilter); +void TIM_ConfigPrescaler(TIM_Module* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode); +void TIM_ConfigCntMode(TIM_Module* TIMx, uint16_t CntMode); +void TIM_SelectInputTrig(TIM_Module* TIMx, uint16_t TIM_InputTriggerSource); +void TIM_ConfigEncoderInterface(TIM_Module* TIMx, + uint16_t TIM_EncoderMode, + uint16_t TIM_IC1Polarity, + uint16_t TIM_IC2Polarity); +void TIM_ConfigForcedOc1(TIM_Module* TIMx, uint16_t TIM_ForcedAction); +void TIM_ConfigForcedOc2(TIM_Module* TIMx, uint16_t TIM_ForcedAction); +void TIM_ConfigForcedOc3(TIM_Module* TIMx, uint16_t TIM_ForcedAction); +void TIM_ConfigForcedOc4(TIM_Module* TIMx, uint16_t TIM_ForcedAction); +void TIM_ConfigArPreload(TIM_Module* TIMx, FunctionalState Cmd); +void TIM_SelectComEvt(TIM_Module* TIMx, FunctionalState Cmd); +void TIM_SelectCapCmpDmaSrc(TIM_Module* TIMx, FunctionalState Cmd); +void TIM_EnableCapCmpPreloadControl(TIM_Module* TIMx, FunctionalState Cmd); +void TIM_EnableOc1Preload(TIM_Module* TIMx, uint16_t TIM_OCPreload); +void TIM_ConfigOc2Preload(TIM_Module* TIMx, uint16_t TIM_OCPreload); +void TIM_ConfigOc3Preload(TIM_Module* TIMx, uint16_t TIM_OCPreload); +void TIM_ConfigOc4Preload(TIM_Module* TIMx, uint16_t TIM_OCPreload); +void TIM_ConfigOc1Fast(TIM_Module* TIMx, uint16_t TIM_OCFast); +void TIM_ConfigOc2Fast(TIM_Module* TIMx, uint16_t TIM_OCFast); +void TIM_ConfigOc3Fast(TIM_Module* TIMx, uint16_t TIM_OCFast); +void TIM_ConfigOc4Fast(TIM_Module* TIMx, uint16_t TIM_OCFast); +void TIM_ClrOc1Ref(TIM_Module* TIMx, uint16_t TIM_OCClear); +void TIM_ClrOc2Ref(TIM_Module* TIMx, uint16_t TIM_OCClear); +void TIM_ClrOc3Ref(TIM_Module* TIMx, uint16_t TIM_OCClear); +void TIM_ClrOc4Ref(TIM_Module* TIMx, uint16_t TIM_OCClear); +void TIM_ConfigOc1Polarity(TIM_Module* TIMx, uint16_t OcPolarity); +void TIM_ConfigOc1NPolarity(TIM_Module* TIMx, uint16_t OcNPolarity); +void TIM_ConfigOc2Polarity(TIM_Module* TIMx, uint16_t OcPolarity); +void TIM_ConfigOc2NPolarity(TIM_Module* TIMx, uint16_t OcNPolarity); +void TIM_ConfigOc3Polarity(TIM_Module* TIMx, uint16_t OcPolarity); +void TIM_ConfigOc3NPolarity(TIM_Module* TIMx, uint16_t OcNPolarity); +void TIM_ConfigOc4Polarity(TIM_Module* TIMx, uint16_t OcPolarity); +void TIM_EnableCapCmpCh(TIM_Module* TIMx, uint16_t Channel, uint32_t TIM_CCx); +void TIM_EnableCapCmpChN(TIM_Module* TIMx, uint16_t Channel, uint32_t TIM_CCxN); +void TIM_SelectOcMode(TIM_Module* TIMx, uint16_t Channel, uint16_t OcMode); +void TIM_EnableUpdateEvt(TIM_Module* TIMx, FunctionalState Cmd); +void TIM_ConfigUpdateRequestIntSrc(TIM_Module* TIMx, uint16_t TIM_UpdateSource); +void TIM_SelectHallSensor(TIM_Module* TIMx, FunctionalState Cmd); +void TIM_SelectOnePulseMode(TIM_Module* TIMx, uint16_t TIM_OPMode); +void TIM_SelectOutputTrig(TIM_Module* TIMx, uint16_t TIM_TRGOSource); +void TIM_SelectSlaveMode(TIM_Module* TIMx, uint16_t TIM_SlaveMode); +void TIM_SelectMasterSlaveMode(TIM_Module* TIMx, uint16_t TIM_MasterSlaveMode); +void TIM_SetCnt(TIM_Module* TIMx, uint16_t Counter); +void TIM_SetAutoReload(TIM_Module* TIMx, uint16_t Autoreload); +void TIM_SetCmp1(TIM_Module* TIMx, uint16_t Compare1); +void TIM_SetCmp2(TIM_Module* TIMx, uint16_t Compare2); +void TIM_SetCmp3(TIM_Module* TIMx, uint16_t Compare3); +void TIM_SetCmp4(TIM_Module* TIMx, uint16_t Compare4); +void TIM_SetInCap1Prescaler(TIM_Module* TIMx, uint16_t TIM_ICPSC); +void TIM_SetInCap2Prescaler(TIM_Module* TIMx, uint16_t TIM_ICPSC); +void TIM_SetInCap3Prescaler(TIM_Module* TIMx, uint16_t TIM_ICPSC); +void TIM_SetInCap4Prescaler(TIM_Module* TIMx, uint16_t TIM_ICPSC); +void TIM_SetClkDiv(TIM_Module* TIMx, uint16_t TIM_CKD); +uint16_t TIM_GetCap1(TIM_Module* TIMx); +uint16_t TIM_GetCap2(TIM_Module* TIMx); +uint16_t TIM_GetCap3(TIM_Module* TIMx); +uint16_t TIM_GetCap4(TIM_Module* TIMx); +uint16_t TIM_GetCnt(TIM_Module* TIMx); +uint16_t TIM_GetPrescaler(TIM_Module* TIMx); +FlagStatus TIM_GetFlagStatus(TIM_Module* TIMx, uint32_t TIM_FLAG); +void TIM_ClearFlag(TIM_Module* TIMx, uint32_t TIM_FLAG); +INTStatus TIM_GetIntStatus(TIM_Module* TIMx, uint32_t TIM_IT); +void TIM_ClrIntPendingBit(TIM_Module* TIMx, uint32_t TIM_IT); + +#ifdef __cplusplus +} +#endif + +#endif /*__N32WB03X_TIM_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_usart.h new file mode 100644 index 0000000..f051896 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_usart.h @@ -0,0 +1,415 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_usart.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_USART_H__ +#define __N32WB03X_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup USART + * @{ + */ + +/** @addtogroup USART_Exported_Types + * @{ + */ + +/** + * @brief USART Init Structure definition + */ + +typedef struct +{ + uint32_t BaudRate; /*!< This member configures the USART communication baud rate. + The baud rate is computed using the following formula: + - IntegerDivider = ((PCLKx) / (16 * (USART_InitStruct->BaudRate))) + - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 16) + 0.5 */ + + uint16_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. + This parameter can be a value of @ref USART_Word_Length */ + + uint16_t StopBits; /*!< Specifies the number of stop bits transmitted. + This parameter can be a value of @ref USART_Stop_Bits */ + + uint16_t Parity; /*!< Specifies the parity mode. + This parameter can be a value of @ref Parity + @note When parity is enabled, the computed parity is inserted + at the MSB position of the transmitted data (9th bit when + the word length is set to 9 data bits; 8th bit when the + word length is set to 8 data bits). */ + + uint16_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled. + This parameter can be a value of @ref Mode */ + + uint16_t HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled + or disabled. + This parameter can be a value of @ref USART_Hardware_Flow_Control */ +} USART_InitType; + +/** + * @brief USART Clock Init Structure definition + */ + +typedef struct +{ + uint16_t Clock; /*!< Specifies whether the USART clock is enabled or disabled. + This parameter can be a value of @ref Clock */ + + uint16_t Polarity; /*!< Specifies the steady state value of the serial clock. + This parameter can be a value of @ref USART_Clock_Polarity */ + + uint16_t Phase; /*!< Specifies the clock transition on which the bit capture is made. + This parameter can be a value of @ref USART_Clock_Phase */ + + uint16_t LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted + data bit (MSB) has to be output on the SCLK pin in synchronous mode. + This parameter can be a value of @ref USART_Last_Bit */ +} USART_ClockInitType; + +/** + * @} + */ + +/** @addtogroup USART_Exported_Constants + * @{ + */ + +#define IS_USART_ALL_PERIPH(PERIPH) \ + (((PERIPH) == USART1) || ((PERIPH) == USART2)) + +#define IS_USART_12_PERIPH(PERIPH) (((PERIPH) == USART1) || ((PERIPH) == USART2)) +/** @addtogroup USART_Word_Length + * @{ + */ + +#define USART_WL_8B ((uint16_t)0x0000) +#define USART_WL_9B ((uint16_t)0x1000) + +#define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WL_8B) || ((LENGTH) == USART_WL_9B)) +/** + * @} + */ + +/** @addtogroup USART_Stop_Bits + * @{ + */ + +#define USART_STPB_1 ((uint16_t)0x0000) +#define USART_STPB_0_5 ((uint16_t)0x1000) +#define USART_STPB_2 ((uint16_t)0x2000) +#define USART_STPB_1_5 ((uint16_t)0x3000) +#define IS_USART_STOPBITS(STOPBITS) \ + (((STOPBITS) == USART_STPB_1) || ((STOPBITS) == USART_STPB_0_5) || ((STOPBITS) == USART_STPB_2) \ + || ((STOPBITS) == USART_STPB_1_5)) +/** + * @} + */ + +/** @addtogroup Parity + * @{ + */ + +#define USART_PE_NO ((uint16_t)0x0000) +#define USART_PE_EVEN ((uint16_t)0x0400) +#define USART_PE_ODD ((uint16_t)0x0600) +#define IS_USART_PARITY(PARITY) (((PARITY) == USART_PE_NO) || ((PARITY) == USART_PE_EVEN) || ((PARITY) == USART_PE_ODD)) +/** + * @} + */ + +/** @addtogroup Mode + * @{ + */ + +#define USART_MODE_RX ((uint16_t)0x0004) +#define USART_MODE_TX ((uint16_t)0x0008) +#define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00)) +/** + * @} + */ + +/** @addtogroup USART_Hardware_Flow_Control + * @{ + */ +#define USART_HFCTRL_NONE ((uint16_t)0x0000) +#define USART_HFCTRL_RTS ((uint16_t)0x0100) +#define USART_HFCTRL_CTS ((uint16_t)0x0200) +#define USART_HFCTRL_RTS_CTS ((uint16_t)0x0300) +#define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL) \ + (((CONTROL) == USART_HFCTRL_NONE) || ((CONTROL) == USART_HFCTRL_RTS) || ((CONTROL) == USART_HFCTRL_CTS) \ + || ((CONTROL) == USART_HFCTRL_RTS_CTS)) +/** + * @} + */ + +/** @addtogroup Clock + * @{ + */ +#define USART_CLK_DISABLE ((uint16_t)0x0000) +#define USART_CLK_ENABLE ((uint16_t)0x0800) +#define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_CLK_DISABLE) || ((CLOCK) == USART_CLK_ENABLE)) +/** + * @} + */ + +/** @addtogroup USART_Clock_Polarity + * @{ + */ + +#define USART_CLKPOL_LOW ((uint16_t)0x0000) +#define USART_CLKPOL_HIGH ((uint16_t)0x0400) +#define IS_USART_CPOL(CPOL) (((CPOL) == USART_CLKPOL_LOW) || ((CPOL) == USART_CLKPOL_HIGH)) + +/** + * @} + */ + +/** @addtogroup USART_Clock_Phase + * @{ + */ + +#define USART_CLKPHA_1EDGE ((uint16_t)0x0000) +#define USART_CLKPHA_2EDGE ((uint16_t)0x0200) +#define IS_USART_CPHA(CPHA) (((CPHA) == USART_CLKPHA_1EDGE) || ((CPHA) == USART_CLKPHA_2EDGE)) + +/** + * @} + */ + +/** @addtogroup USART_Last_Bit + * @{ + */ + +#define USART_CLKLB_DISABLE ((uint16_t)0x0000) +#define USART_CLKLB_ENABLE ((uint16_t)0x0100) +#define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_CLKLB_DISABLE) || ((LASTBIT) == USART_CLKLB_ENABLE)) +/** + * @} + */ + +/** @addtogroup USART_Interrupt_definition + * @{ + */ + +#define USART_INT_PEF ((uint16_t)0x0028) +#define USART_INT_TXDE ((uint16_t)0x0727) +#define USART_INT_TXC ((uint16_t)0x0626) +#define USART_INT_RXDNE ((uint16_t)0x0525) +#define USART_INT_IDLEF ((uint16_t)0x0424) +#define USART_INT_LINBD ((uint16_t)0x0846) +#define USART_INT_CTSF ((uint16_t)0x096A) +#define USART_INT_ERRF ((uint16_t)0x0060) +#define USART_INT_OREF ((uint16_t)0x0360) +#define USART_INT_NEF ((uint16_t)0x0260) +#define USART_INT_FEF ((uint16_t)0x0160) +#define IS_USART_CFG_INT(IT) \ + (((IT) == USART_INT_PEF) || ((IT) == USART_INT_TXDE) || ((IT) == USART_INT_TXC) || ((IT) == USART_INT_RXDNE) \ + || ((IT) == USART_INT_IDLEF) || ((IT) == USART_INT_LINBD) || ((IT) == USART_INT_CTSF) \ + || ((IT) == USART_INT_ERRF)) +#define IS_USART_GET_INT(IT) \ + (((IT) == USART_INT_PEF) || ((IT) == USART_INT_TXDE) || ((IT) == USART_INT_TXC) || ((IT) == USART_INT_RXDNE) \ + || ((IT) == USART_INT_IDLEF) || ((IT) == USART_INT_LINBD) || ((IT) == USART_INT_CTSF) || ((IT) == USART_INT_OREF) \ + || ((IT) == USART_INT_NEF) || ((IT) == USART_INT_FEF)) +#define IS_USART_CLR_INT(IT) \ + (((IT) == USART_INT_TXC) || ((IT) == USART_INT_RXDNE) || ((IT) == USART_INT_LINBD) || ((IT) == USART_INT_CTSF)) +/** + * @} + */ + +/** @addtogroup USART_DMA_Requests + * @{ + */ + +#define USART_DMAREQ_TX ((uint16_t)0x0080) +#define USART_DMAREQ_RX ((uint16_t)0x0040) +#define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00)) + +/** + * @} + */ + +/** @addtogroup USART_WakeUp_methods + * @{ + */ + +#define USART_WUM_IDLELINE ((uint16_t)0x0000) +#define USART_WUM_ADDRMASK ((uint16_t)0x0800) +#define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WUM_IDLELINE) || ((WAKEUP) == USART_WUM_ADDRMASK)) +/** + * @} + */ + +/** @addtogroup USART_LIN_Break_Detection_Length + * @{ + */ + +#define USART_LINBDL_10B ((uint16_t)0x0000) +#define USART_LINBDL_11B ((uint16_t)0x0020) +#define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == USART_LINBDL_10B) || ((LENGTH) == USART_LINBDL_11B)) +/** + * @} + */ + +/** @addtogroup USART_IrDA_Low_Power + * @{ + */ + +#define USART_IRDAMODE_LOWPPWER ((uint16_t)0x0004) +#define USART_IRDAMODE_NORMAL ((uint16_t)0x0000) +#define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IRDAMODE_LOWPPWER) || ((MODE) == USART_IRDAMODE_NORMAL)) +/** + * @} + */ + +/** @addtogroup USART_Flags + * @{ + */ + +#define USART_FLAG_CTSF ((uint16_t)0x0200) +#define USART_FLAG_LINBD ((uint16_t)0x0100) +#define USART_FLAG_TXDE ((uint16_t)0x0080) +#define USART_FLAG_TXC ((uint16_t)0x0040) +#define USART_FLAG_RXDNE ((uint16_t)0x0020) +#define USART_FLAG_IDLEF ((uint16_t)0x0010) +#define USART_FLAG_OREF ((uint16_t)0x0008) +#define USART_FLAG_NEF ((uint16_t)0x0004) +#define USART_FLAG_FEF ((uint16_t)0x0002) +#define USART_FLAG_PEF ((uint16_t)0x0001) +#define IS_USART_FLAG(FLAG) \ + (((FLAG) == USART_FLAG_PEF) || ((FLAG) == USART_FLAG_TXDE) || ((FLAG) == USART_FLAG_TXC) \ + || ((FLAG) == USART_FLAG_RXDNE) || ((FLAG) == USART_FLAG_IDLEF) || ((FLAG) == USART_FLAG_LINBD) \ + || ((FLAG) == USART_FLAG_CTSF) || ((FLAG) == USART_FLAG_OREF) || ((FLAG) == USART_FLAG_NEF) \ + || ((FLAG) == USART_FLAG_FEF)) + +#define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00)) +#define IS_USART_PERIPH_FLAG(PERIPH, USART_FLAG) \ + ((((*(uint32_t*)&(PERIPH)) != UART4_BASE) && ((*(uint32_t*)&(PERIPH)) != UART5_BASE)) \ + || ((USART_FLAG) != USART_FLAG_CTSF)) +#define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x3D0901)) +#define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF) +#define IS_USART_DATA(DATA) ((DATA) <= 0x1FF) + +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup USART_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup USART_Exported_Functions + * @{ + */ + +void USART_DeInit(USART_Module* USARTx); +void USART_Init(USART_Module* USARTx, USART_InitType* USART_InitStruct); +void USART_StructInit(USART_InitType* USART_InitStruct); +void USART_ClockInit(USART_Module* USARTx, USART_ClockInitType* USART_ClockInitStruct); +void USART_ClockStructInit(USART_ClockInitType* USART_ClockInitStruct); +void USART_Enable(USART_Module* USARTx, FunctionalState Cmd); +void USART_ConfigInt(USART_Module* USARTx, uint16_t USART_INT, FunctionalState Cmd); +void USART_EnableDMA(USART_Module* USARTx, uint16_t USART_DMAReq, FunctionalState Cmd); +void USART_SetAddr(USART_Module* USARTx, uint8_t USART_Addr); +void USART_ConfigWakeUpMode(USART_Module* USARTx, uint16_t USART_WakeUpMode); +void USART_EnableRcvWakeUp(USART_Module* USARTx, FunctionalState Cmd); +void USART_ConfigLINBreakDetectLength(USART_Module* USARTx, uint16_t USART_LINBreakDetectLength); +void USART_EnableLIN(USART_Module* USARTx, FunctionalState Cmd); +void USART_SendData(USART_Module* USARTx, uint16_t Data); +uint16_t USART_ReceiveData(USART_Module* USARTx); +void USART_SendBreak(USART_Module* USARTx); +void USART_SetGuardTime(USART_Module* USARTx, uint8_t USART_GuardTime); +void USART_SetPrescaler(USART_Module* USARTx, uint8_t USART_Prescaler); +void USART_EnableSmartCard(USART_Module* USARTx, FunctionalState Cmd); +void USART_SetSmartCardNACK(USART_Module* USARTx, FunctionalState Cmd); +void USART_EnableHalfDuplex(USART_Module* USARTx, FunctionalState Cmd); +void USART_ConfigIrDAMode(USART_Module* USARTx, uint16_t USART_IrDAMode); +void USART_EnableIrDA(USART_Module* USARTx, FunctionalState Cmd); +FlagStatus USART_GetFlagStatus(USART_Module* USARTx, uint16_t USART_FLAG); +void USART_ClrFlag(USART_Module* USARTx, uint16_t USART_FLAG); +INTStatus USART_GetIntStatus(USART_Module* USARTx, uint16_t USART_INT); +void USART_ClrIntPendingBit(USART_Module* USARTx, uint16_t USART_INT); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_wwdg.h b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_wwdg.h new file mode 100644 index 0000000..8fedd47 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/inc/n32wb03x_wwdg.h @@ -0,0 +1,143 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_wwdg.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_WWDG_H__ +#define __N32WB03X_WWDG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup WWDG + * @{ + */ + +/** @addtogroup WWDG_Exported_Types + * @{ + */ + +/** + * @} + */ + +/** @addtogroup WWDG_Exported_Constants + * @{ + */ + +/** @addtogroup WWDG_Prescaler + * @{ + */ + +#define WWDG_PRESCALER_DIV1 ((uint32_t)0x00000000) +#define WWDG_PRESCALER_DIV2 ((uint32_t)0x00000080) +#define WWDG_PRESCALER_DIV4 ((uint32_t)0x00000100) +#define WWDG_PRESCALER_DIV8 ((uint32_t)0x00000180) +#define IS_WWDG_PRESCALER_DIV(PRESCALER) \ + (((PRESCALER) == WWDG_PRESCALER_DIV1) || ((PRESCALER) == WWDG_PRESCALER_DIV2) \ + || ((PRESCALER) == WWDG_PRESCALER_DIV4) || ((PRESCALER) == WWDG_PRESCALER_DIV8)) +#define IS_WWDG_WVALUE(VALUE) ((VALUE) <= 0x7F) +#define IS_WWDG_CNT(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) + +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup WWDG_Exported_Macros + * @{ + */ +/** + * @} + */ + +/** @addtogroup WWDG_Exported_Functions + * @{ + */ + +void WWDG_DeInit(void); +void WWDG_SetPrescalerDiv(uint32_t WWDG_Prescaler); +void WWDG_SetWValue(uint8_t WindowValue); +void WWDG_EnableInt(void); +void WWDG_SetCnt(uint8_t Counter); +void WWDG_Enable(uint8_t Counter); +FlagStatus WWDG_GetEWINTF(void); +void WWDG_ClrEWINTF(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X__WWDG_H */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/misc.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/misc.c new file mode 100644 index 0000000..8a5fb7b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/misc.c @@ -0,0 +1,170 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file misc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "misc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup MISC + * @brief MISC driver modules + * @{ + */ + +/** @addtogroup MISC_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup MISC_Private_Defines + * @{ + */ + +#define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) +/** + * @} + */ + +/** @addtogroup MISC_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup MISC_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup MISC_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup MISC_Private_Functions + * @{ + */ + +/** + * @brief Initializes the NVIC peripheral according to the specified + * parameters in the NVIC_InitStruct. + * @param NVIC_InitStruct pointer to a NVIC_InitType structure that contains + * the configuration information for the specified NVIC peripheral. + */ +void NVIC_Init(NVIC_InitType* NVIC_InitStruct) +{ + /* Check the parameters */ + assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); + assert_param(IS_NVIC_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPriority)); + + /* Set Interrupt Priority */ + NVIC_SetPriority(NVIC_InitStruct->NVIC_IRQChannel, NVIC_InitStruct->NVIC_IRQChannelPriority); + + if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) + { + /* Enable the Selected IRQ Channels --------------------------------------*/ + NVIC_EnableIRQ(NVIC_InitStruct->NVIC_IRQChannel); + } + else + { + /* Disable the Selected IRQ Channels -------------------------------------*/ + NVIC_DisableIRQ(NVIC_InitStruct->NVIC_IRQChannel); + } +} + +/** + * @brief Configures the SysTick clock source. + * @param SysTick_CLKSource specifies the SysTick clock source. + * This parameter can be one of the following values: + * @arg SysTick_CLKSource_HCLK_Div8 AHB clock divided by 8 selected as SysTick clock source. + * @arg SysTick_CLKSource_HCLK AHB clock selected as SysTick clock source. + */ +void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) +{ + /* Check the parameters */ + assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); + if (SysTick_CLKSource == SysTick_CLKSource_HCLK) + { + SysTick->CTRL |= SysTick_CLKSource_HCLK; + } + else + { + SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; + } +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_adc.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_adc.c new file mode 100644 index 0000000..7fbf304 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_adc.c @@ -0,0 +1,959 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_adc.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_adc.h" +#include "n32wb03x_rcc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup ADC + * @brief ADC driver modules + * @{ + */ + +/** @addtogroup ADC_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup ADC_Private_Defines + * @{ + */ + + +/** + * @} + */ + +/** @addtogroup ADC_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup ADC_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup ADC_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup ADC_Private_Functions + * @{ + */ + +/** + * @brief Deinitializes the ADCx peripheral registers to their default reset values. + * @param ADCx can be ADC to select the ADC peripheral. + */ +void ADC_DeInit(ADC_Module* ADCx) +{ + /* Check the parameters */ + assert_param(IsAdcModule(ADCx)); + + if (ADCx == ADC) + { + /* Enable ADC reset state */ + RCC_EnableAHBPeriphReset(RCC_AHB_PERIPH_ADC, ENABLE); + /* Release ADC from reset state */ + RCC_EnableAHBPeriphReset(RCC_AHB_PERIPH_ADC, DISABLE); + + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC, ENABLE); + /* Reset ADC registers */ + ADC->FGA_CFG = 0x20A08; + ADC->CTRL = 0; + ADC->SR = 0; + ADC->OVR_SAMP_CNT = 0x1F; + ADC->WDT_THRES = 0x0FFC0000; + ADC->VOICE_DET_CR = 0; + ADC->VOICE_ED_DWN_THRES = 0; + ADC->VOICE_ED_THRES = 0; + ADC->VOICE_ED_UP_THRES = 0; + ADC->VOICE_ZCR_THRES = 0x00006D2E; + } +} + + +/** + * @brief Enables or disables the specified ADC peripheral. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the ADCx peripheral. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_Enable(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable GPADC */ + ADCx->CTRL |= ADC_CTRL_EN; + } + else + { + /* Disable GPADC */ + ADCx->CTRL &= ~ADC_CTRL_EN; + } +} + +/** + * @brief Enables or disables the specified ADC DMA request. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the selected ADC DMA transfer. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_EnableDMA(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected ADC DMA request */ + ADCx->CTRL |= ADC_CTRL_DMA_MODE_EN; + } + else + { + /* Disable the selected ADC DMA request */ + ADCx->CTRL &= ~ADC_CTRL_DMA_MODE_EN; + } +} + +/** + * @brief Enables or disables the specified ADC TS request. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the selected ADC DMA transfer. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_EnableTS(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected Temperature Sensor */ + ADCx->CTRL |= ADC_CTRL_TS_EN; + } + else + { + /* Disable the selected Temperature Sensor */ + ADCx->CTRL &= ~ADC_CTRL_TS_EN; + } +} + +/** + * @brief Enables or disables the specified Analog watchdog. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the selected Analog watchdog. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_EnableAWD(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected Analog watchdog */ + ADCx->CTRL |= ADC_CTRL_AWD_EN; + } + else + { + /* Disable the selected Analog watchdog */ + ADCx->CTRL &= ~ADC_CTRL_AWD_EN; + } +} + +/** + * @brief Enables or disables the specified ADC interrupts. + * @param ADCx can be ADC to select the ADC peripheral. + * @param ADC_IT specifies the ADC interrupt sources to be enabled or disabled. + * This parameter can be any combination of the following values: + * @arg ADC_INT_DONE GPADC Done Interrupt Enable + * @arg ADC_INT_AWD Analog watchdog interrupt mask + * @arg ADC_INT_PGARDY Used to enable the interrupt PGAREADY to interrupt processor when PGA fails + * @param Cmd new state of the specified ADC interrupts. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_ConfigInt(ADC_Module* ADCx, uint16_t ADC_IT, FunctionalState Cmd) +{ + uint16_t itmask = 0; + /* Check the parameters */ + assert_param(IsAdcModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + assert_param(IsAdcInt(ADC_IT)); + /* Get the ADC IT index */ + itmask = (uint16_t)ADC_IT; + if (Cmd != DISABLE) + { + /* Enable the selected ADC interrupts */ + ADCx->CTRL |= itmask; + } + else + { + /* Disable the selected ADC interrupts */ + ADCx->CTRL &= (~(uint16_t)itmask); + } +} + +/** + * @brief Configures for the selected ADC channel + * @param ADCx can be ADC to select the ADC peripheral. + * @param ADC_Channel the ADC channel to configure. + * This parameter can be any combination of the following values: + * @arg ADC_CTRL_CH_0(MIC) ADC Channel0 selected + * @arg ADC_CTRL_CH_1(PB10) ADC Channel1 selected + * @arg ADC_CTRL_CH_2(PB9) ADC Channel2 selected + * @arg ADC_CTRL_CH_3(PB8) ADC Channel3 selected + * @arg ADC_CTRL_CH_4(PB7) ADC Channel4 selected + * @arg ADC_CTRL_CH_5(PB6) ADC Channel5 selected + * @arg ADC_CTRL_CH_6(VCC) ADC Channel6 selected + * @arg ADC_CTRL_CH_7(TS) ADC Channel7 selected + */ +void ADC_ConfigChannel(ADC_Module* ADCx, uint16_t Channel) +{ + uint16_t itmask = 0; + + /* Check the parameters */ + assert_param(IsAdcModule(ADCx)); + assert_param(IsAdcChannel(Channel)); + /* Get the old register value */ + itmask = ADCx->CTRL; + /* Clear the old channel value */ + itmask &= ~ADC_CTRL_CH_SEL; + /* Set the new channel value */ + itmask |= Channel; + /* Store the new register value */ + ADCx->CTRL = itmask; +} + +/** + * @brief Configures for the selected ADC Mode. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the specified ADC Mode. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_ConfigContinuousMode(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Set ADC_MODE bit according to ContinueConvEn value */ + ADCx->CTRL |= ADC_CTRL_MODE; + } + else + { + /* Set ADC_MODE bit according to SingleEn value */ + ADCx->CTRL &= ~ADC_CTRL_MODE; + } +} + +/** + * @brief Configures the high and low thresholds of the analog watchdog. + * @param ADCx can be ADC to select the ADC peripheral. + * @param HighThreshold the ADC analog watchdog High threshold value. + * This parameter must be a 10bit value. + * @param LowThreshold the ADC analog watchdog Low threshold value. + * This parameter must be a 10bit value. + */ +void ADC_ConfigAnalogWatchdogThresholds(ADC_Module* ADCx, uint32_t High_Threshold, uint32_t Low_Threshold) +{ + uint32_t tmp1 = 0; + uint32_t tmp2 = 0; + + /* Check the parameters */ + assert_param(IsAdcModule(ADCx)); + assert_param(IsAdcValid(High_Threshold)); + assert_param(IsAdcValid(Low_Threshold)); + /* Get the old register value */ + tmp1 = ADCx->WDT_THRES ; + /* Clear the old value */ + tmp1 &= ~(ADC_WDT_THRES_HT | ADC_WDT_THRES_LT); + /* Calculate the mask to set */ + tmp2 = High_Threshold << 18; + /* Set the analog watchdog threshold */ + tmp1 |= (tmp2 | Low_Threshold); + /* Store the new register value */ + ADCx->WDT_THRES = tmp1; +} + +/** + * @brief Configures the high and low thresholds of the zero cross. + * @param ADCx can be ADC to select the ADC peripheral. + * @param HighThreshold the ADC zero cross High threshold value. + * This parameter must be a 8bit value. + * @param LowThreshold the ADC zero cross Low threshold value. + * This parameter must be a 8bit value. + */ +void ADC_ConfigVoiceZcrThresholds(ADC_Module* ADCx, uint32_t High_Threshold, uint32_t Low_Threshold) +{ + uint32_t tmp1 = 0; + uint32_t tmp2 = 0; + + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IsAdcVoiceZcrValid(High_Threshold)); + assert_param(IsAdcVoiceZcrValid(Low_Threshold)); + /* Get the old register value */ + tmp1 = ADCx->VOICE_ZCR_THRES; + /* Clear the old value */ + tmp1 &= ~(ADC_VAD_ZCRD_HIGH_THRES | ADC_VAD_ZCRD_LOW_THRES); + /* Calculate the mask to set */ + tmp2 = (High_Threshold&0xFF) << 8; + /* Set the zero cross threshold */ + tmp1 |= (tmp2 | (Low_Threshold&0xFF)); + /* Store the new register value */ + ADCx->VOICE_ZCR_THRES = tmp1; +} + +/** + * @brief Configures the high and low thresholds of the energy detection. + * @param ADCx can be ADC to select the ADC peripheral. + * @param HighThreshold the ADC energy detection High threshold value. + * This parameter must be a 23bit value. + * @param LowThreshold the ADC energy detection Low threshold value. + * This parameter must be a 23bit value. + */ +void ADC_ConfigEDThreshold(ADC_Module* ADCx, uint32_t High_Threshold, uint32_t Low_Threshold) +{ + uint32_t tmp1 = 0; + uint32_t tmp2 = 0; + + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IsAdcVoiceEDValid(High_Threshold)); + assert_param(IsAdcVoiceEDValid(Low_Threshold)); + /* Get the old register value */ + tmp1 = ADCx->VOICE_ED_UP_THRES; + /* Get the old register value */ + tmp2 = ADCx->VOICE_ED_DWN_THRES; + /* Clear the old value */ + tmp1 &= ~ADC_VOICE_ED_UP_THRES_GATE_MAX; + /* Clear the old value */ + tmp2 &= ~ADC_VOICE_ED_DWN_THRES_GATE_MIN; + /* Set the energy detection High threshold value */ + tmp1 |= High_Threshold&ADC_VOICE_ED_UP_THRES_GATE_MAX; + /* Set the energy detection Low threshold value */ + tmp2 |= Low_Threshold&ADC_VOICE_ED_DWN_THRES_GATE_MIN; + /* Store the new register value */ + ADCx->VOICE_ED_UP_THRES = tmp1; + /* Store the new register value */ + ADCx->VOICE_ED_DWN_THRES = tmp2; +} + +/** + * @brief Set the environment noise level value. + * @param ADCx can be ADC to select the ADC peripheral. + * @param moffset the offset value for the selected environment noise level value. + * This parameter must be a 23bit value. + */ +void ADC_SetNoiseOffset(ADC_Module* ADCx, uint32_t moffset) +{ + uint32_t tmp1 = 0; + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IsAdcNoiseOffsetValid(moffset)); + /* Get the old register value */ + tmp1 = ADCx->VOICE_ED_THRES; + /* Clear the old value */ + tmp1 &= ~ADC_VOICE_ED_THRES_MOFFSET; + /* Set the environment noise level value */ + tmp1 |= moffset&ADC_VOICE_ED_THRES_MOFFSET; + /* Store the new register value */ + ADCx->VOICE_ED_THRES = tmp1; +} + +/** + * @brief Returns the last ADCx conversion result data for channel. + * @param ADCx can be ADC to select the ADC peripheral. + * @return The Data conversion value. + */ +uint16_t ADC_GetDat(ADC_Module* ADCx) +{ + /* Check the parameters */ + assert_param(IsAdcModule(ADCx)); + /* Return the selected ADC conversion value */ + return (uint16_t)ADCx->DAT; +} + +/** + * @brief Checks whether the specified ADC flag is set or not. + * @param ADCx can be ADC to select the ADC peripheral. + * @param ADC_FLAG specifies the flag to check. + * This parameter can be one of the following values: + * @arg ADC_FLAG_DONE GP-ADC conversion complete status + * @arg ADC_FLAG_AWD Analog watchdog flag + * @arg ADC_FLAG_PGARDY PGA fail status + * @return The new state of ADC_FLAG (SET or RESET). + */ +FlagStatus ADC_GetFlagStatus(ADC_Module* ADCx, uint8_t ADC_FLAG) +{ + FlagStatus bitstatus = RESET; + /* Check the parameters */ + assert_param(IsAdcModule(ADCx)); + assert_param(IsAdcGetFlag(ADC_FLAG)); + /* Check the status of the specified ADC flag */ + if ((ADCx->SR & ADC_FLAG) != (uint8_t)RESET) + { + /* ADC_FLAG is set */ + bitstatus = SET; + } + else + { + /* ADC_FLAG is reset */ + bitstatus = RESET; + } + /* Return the ADC_FLAG status */ + return bitstatus; +} + +/** + * @brief Clears the ADCx's pending flags. + * @param ADCx can be ADC to select the ADC peripheral. + * @param ADC_FLAG specifies the flag to clear. + * This parameter can be any combination of the following values: + * @arg ADC_FLAG_DONE GP-ADC conversion complete status + * @arg ADC_FLAG_AWD Analog watchdog flag + * @arg ADC_FLAG_PGARDY PGA fail status + */ +void ADC_ClearFlag(ADC_Module* ADCx, uint8_t ADC_FLAG) +{ + /* Check the parameters */ + assert_param(IsAdcModule(ADCx)); + assert_param(IsAdcClrFlag(ADC_FLAG)); + /* Clear the selected ADC flags */ + ADCx->SR = ~(uint8_t)ADC_FLAG; +} + +/** + * @brief Enables or disables the selected ADC zero cross. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the selected ADC zero cross. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_EnableZeroCross(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable zero cross */ + ADCx->VOICE_DET_CR |= ADC_VOICE_DET_CR_ZCRD_EN; + } + else + { + /* Disable zero cross */ + ADCx->VOICE_DET_CR &= ~ADC_VOICE_DET_CR_ZCRD_EN; + } +} + +/** + * @brief Enables or disables the selected ADC energy . + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the selected ADC energy. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_EnableEnergy(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable energy */ + ADCx->VOICE_DET_CR |= ADC_VOICE_DET_CR_ED_EN; + } + else + { + /* Disable energy */ + ADCx->VOICE_DET_CR &= ~ADC_VOICE_DET_CR_ED_EN; + } +} + +/** + * @brief Enables or disables the selected bypass the digital filtering and ED/ZCRD features . + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the selected ADC bypass. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_EnableBypassFilter(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enbale bypass mode */ + ADCx->VOICE_DET_CR |= ADC_VOICE_DET_CR_FILTTER_BYP; + } + else + { + /* Disbale bypass mode */ + ADCx->VOICE_DET_CR &= ~ADC_VOICE_DET_CR_FILTTER_BYP; + /* config filter */ + *(uint32_t *)0x4002082C = 0x00780022; + *(uint32_t *)0x40020830 = 0x00e100e7; + *(uint32_t *)0x40020834 = 0x04bf009f; + *(uint32_t *)0x40020838 = 0x16050c19; + *(uint32_t *)0x4002083C = 0x286e2070; + *(uint32_t *)0x40020840 = 0x2b6e; + + } +} + +/** + * @brief Enables or disables the selected the ADC MIC bias . + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the selected the ADC MIC bias. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_EnableMICBIAS(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enbale MIC bias*/ + ADCx->FGA_CFG |= ADC_PGA_CFG_MICBIAS_EN; + } + else + { + /* Disbale MIC bias*/ + ADCx->FGA_CFG &= ~ADC_PGA_CFG_MICBIAS_EN; + } +} + +/** + * @brief Set the MIC bias output voltage. + * @param ADCx can be ADC to select the ADC peripheral. + * @param MIC_VoltageValue the value for the selected the MIC bias output voltage. + * This parameter can be any combination of the following values: + * @arg MICBIAS_1V6 + * @arg MICBIAS_1V7 + * @arg MICBIAS_1V8 + * @arg MICBIAS_1V9 + * @arg MICBIAS_2V0 + * @arg MICBIAS_2V1 + * @arg MICBIAS_2V2 + * @arg MICBIAS_2V3 + */ +void ADC_SetMICOutputVoltage(ADC_Module* ADCx, uint32_t MIC_VoltageValue) +{ + uint32_t tmp = 0; + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IsAdcMicbias(MIC_VoltageValue)); + + /* Get the old register value */ + tmp = ADC->FGA_CFG; + /* Clear the old value */ + tmp &= ~ADC_PGA_CFG_MICBIAS; + /* Set the MIC bias output voltage */ + tmp |= MIC_VoltageValue; + /* Store the new register value */ + ADC->FGA_CFG = tmp; +} + +/** + * @brief Enables or disables the selected the Audio PGA fast charge control. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the selected the Audio PGA fast charge control. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_EnableAUDIOPGA(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enbale fast charge */ + ADCx->FGA_CFG |= ADC_PGA_CFG_INIT_ENA; + } + else + { + /* Disbale fast charge */ + ADCx->FGA_CFG &= ~ADC_PGA_CFG_INIT_ENA; + } +} + +/** + * @brief Set the Audio PGA drive signal amplitud. + * @param ADCx can be ADC to select the ADC peripheral. + * @param AMP_Value the value for the selected the Audio PGA drive signal amplitud. + * This parameter can be any combination of the following values: + * @arg ADC_PGA_CFG_PEAK_0 + * @arg ADC_PGA_CFG_PEAK_1 + * @arg ADC_PGA_CFG_PEAK_2 + * @arg ADC_PGA_CFG_PEAK_3 + */ +void ADC_SetAUDIOAmplitude(ADC_Module* ADCx, uint32_t AMP_Value) +{ + uint32_t tmp = 0; + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IsAdcPgaPeak(AMP_Value)); + + /* Get the old register value */ + tmp = ADC->FGA_CFG; + /* Clear the old value */ + tmp &= ~ADC_PGA_CFG_PEAK; + /* Set the Audio PGA drive signal amplitud */ + tmp |= AMP_Value; + /* Store the new register value */ + ADC->FGA_CFG = tmp; +} + +/** + * @brief Set the Audio PGA drive current. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Drive_Value the value for the selected the Audio PGA drive current. + * This parameter can be any combination of the following values: + * @arg ADC_PGA_CFG_DRIVE_0 + * @arg ADC_PGA_CFG_DRIVE_1 + * @arg ADC_PGA_CFG_DRIVE_2 + * @arg ADC_PGA_CFG_DRIVE_3 + */ +void ADC_SetAUDIOCurrent(ADC_Module* ADCx, uint32_t Drive_Value) +{ + uint32_t tmp = 0; + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IsAdcPgaDriver(Drive_Value)); + + /* Get the old register value */ + tmp = ADC->FGA_CFG; + /* Clear the old value */ + tmp &= ~ADC_PGA_CFG_DRIVE; + /* Set the Audio PGA drive current */ + tmp |= Drive_Value; + /* Store the new register value */ + ADC->FGA_CFG = tmp; +} + +/** + * @brief Enables or disables the selected the Audio PGA. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cmd new state of the selected the Audio PGA. + * This parameter can be: ENABLE or DISABLE. + */ +void ADC_EnablePGA(ADC_Module* ADCx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable Audio PGA */ + ADCx->FGA_CFG |= ADC_PGA_CFG_EN; + } + else + { + /* Disable Audio PGA */ + ADCx->FGA_CFG &= ~ADC_PGA_CFG_EN; + } +} + +/** + * @brief Set the Audio PGA gain configuration. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Gain_Value the value for the selected the Audio PGA gain configuration. + * This parameter can be any combination of the following values: + * @arg ADC_PGA_CFG_GAIN_0dB + * @arg ADC_PGA_CFG_GAIN_6dB + * @arg ADC_PGA_CFG_GAIN_12dB + * @arg ADC_PGA_CFG_GAIN_18dB + * @arg ADC_PGA_CFG_GAIN_24dB + * @arg ADC_PGA_CFG_GAIN_30dB + * @arg ADC_PGA_CFG_GAIN_36dB + * @arg ADC_PGA_CFG_GAIN_42dB + */ +void ADC_SetPGAGain(ADC_Module* ADCx, uint32_t Gain_Value) +{ + uint32_t tmp = 0; + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + assert_param(IsAdcPgaGain(Gain_Value)); + + /* Get the old register value */ + tmp = ADC->FGA_CFG; + /* Clear the old value */ + tmp &= ~ADC_PGA_CFG_GAIN; + /* Set the MIC bias output voltage */ + tmp |= Gain_Value; + /* Store the new register value */ + ADC->FGA_CFG = tmp; +} + +/** + * @brief Set the Over Sampling Counter. + * @param ADCx can be ADC to select the ADC peripheral. + * @param Cnt the value for the selected the Over Sampling Counter. + * This parameter must be a 5bit value. + */ +void ADC_SetOverSampleCounter(ADC_Module* ADCx, uint32_t Cnt) +{ + uint32_t tmp = 0; + /* Check the parameters */ + assert_param(IsAdcDmaModule(ADCx)); + + /* Get the old register value */ + tmp = ADC->OVR_SAMP_CNT; + /* Clear the old value */ + tmp &= ~ADC_OS_CNT_LD_CNT; + /* Set the MIC bias output voltage */ + tmp |= Cnt&ADC_OS_CNT_LD_CNT; + /* Store the new register value */ + ADC->OVR_SAMP_CNT = tmp; +} + +/** + * @brief Conver adc value to voltage + * @param adc_value the adv value want to conver to voltage. + * @param Channel the adc value is from which ADC channel(1 to 6) + * @return The voltage in mV unit after conver. + */ +uint32_t ADC_ConverValueToVoltage(uint16_t adc_value, uint16_t channel) +{ + + uint16_t value_3400mv; + uint16_t value_600mv; + uint16_t value_850mv; + uint16_t value_150mv; + int32_t voltage_mV = 0; + /* get trim value */ + trim_stored_t *p_trim = SystemTrimValueGet(); + /* Check the parameters */ + assert_param(IsAdcValid(adc_value)); + assert_param(IsAdcChannel(channel)); + + if(p_trim == 0 || + p_trim->rc_gpadc_value_3400mv == 0 || + p_trim->rc_gpadc_value_600mv == 0) + { + return 0; + } + else + { + value_3400mv = p_trim->rc_gpadc_value_3400mv; + value_600mv = p_trim->rc_gpadc_value_600mv; + value_850mv = p_trim->rc_gpadc_value_3400mv; + value_150mv = p_trim->rc_gpadc_value_600mv; + } + + if( channel == ADC_CTRL_CH_1 || channel == ADC_CTRL_CH_2 ) + { + /* CH1 and CH2 150mV to 850mV */ + voltage_mV =(((int32_t)adc_value - value_150mv) * 700)/(value_850mv - value_150mv) + 150; + + //make sure the voltage valid(0~1000mV) + if(voltage_mV < 0) + { + voltage_mV = 0; + } + else if(voltage_mV > 1000) + { + voltage_mV = 1000; + } + } + else if(channel == ADC_CTRL_CH_3 || channel == ADC_CTRL_CH_4|| channel == ADC_CTRL_CH_5 || channel == ADC_CTRL_CH_6) + { + /* CH3, CH4 and CH5 600mV to 3400mV */ + voltage_mV =(((int32_t)adc_value - value_600mv)* 2800)/(value_3400mv - value_600mv) + 600; + + //make sure the voltage valid(0~3600mV) + if(voltage_mV < 0) + { + voltage_mV = 0; + } + else if(voltage_mV > 3600) + { + voltage_mV = 3600; + } + } + return voltage_mV; +} + + +/** + * @brief Conver 16bit adc value to voltage + * @param adc_value the adv value want to conver to voltage. + * @param Channel the adc value is from which ADC channel(1 to 6) + * @param offset the voltage offset of 16bit ADC in mV. it can get from VCC channel. + * @return The voltage in mV unit after conver. + */ +uint32_t ADC16Bit_ConverValueToVoltage(int16_t value_16bit, uint16_t channel,int16_t offset) +{ + uint16_t value_3400mv; + uint16_t value_600mv; + uint16_t value_850mv; + uint16_t value_150mv; + int32_t voltage_mV = 0; + int32_t adc_value = value_16bit+0x7fff; + /* get trim value */ + trim_stored_t *p_trim = SystemTrimValueGet(); + + if(p_trim == 0 || p_trim->rc_gpadc_value_3400mv == 0) + { + return 0; + } + else + { + value_850mv = value_3400mv = p_trim->rc_gpadc_value_3400mv<<6; + value_150mv = value_600mv = p_trim->rc_gpadc_value_600mv<<6; + } + if( channel == ADC_CTRL_CH_1 || channel == ADC_CTRL_CH_2 ) + { + /* CH1 and CH2 150mV to 850mV */ + voltage_mV =((adc_value - value_150mv) * 700)/(value_850mv - value_150mv) + 150 + (offset/4); + + //make sure the voltage valid(0~1000mV) + if(voltage_mV < 0) + { + voltage_mV = 0; + } + else if(voltage_mV > 1000) + { + voltage_mV = 1000; + } + } + else if(channel == ADC_CTRL_CH_3 || channel == ADC_CTRL_CH_4|| channel == ADC_CTRL_CH_5 || channel == ADC_CTRL_CH_6) + { + /* CH3, CH4 and CH5 600mV to 3400mV */ + voltage_mV =((adc_value - value_600mv)* 2800)/(value_3400mv - value_600mv) + 600 +offset; + + //make sure the voltage valid(0~3600mV) + if(voltage_mV < 0) + { + voltage_mV = 0; + } + else if(voltage_mV > 3600) + { + voltage_mV = 3600; + } + } + return voltage_mV; +} + +/** + * @brief Conver adc value to temperature in centigrade + * @param adc_value the adv value want to conver to voltage. + * @param Channel the adc value is from which ADC channel(1 to 7) + * @return The voltage in mA unit after conver. + */ +float ADC_ConverValueToTemperature(uint16_t adc_value) +{ + float Temperature; + float adc_ts_trim; + /* get trim value */ + trim_stored_t *p_trim = SystemTrimValueGet(); + /* Check the parameters */ + assert_param(IsAdcValid(adc_value)); + + if(p_trim == 0 || p_trim->rc_adc_ts_25c == 0) + { + /* default value if chip without trim value*/ + adc_ts_trim = 750; // 660; + } + else{ + adc_ts_trim = p_trim->rc_adc_ts_25c; + } + + Temperature = ((adc_ts_trim - adc_value)/(2.14)) + 25; + return Temperature; +} + + + +/** + * @} + */ + +/** + * @}S + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_crc.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_crc.c new file mode 100644 index 0000000..194a7c5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_crc.c @@ -0,0 +1,248 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_crc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_crc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup CRC + * @brief CRC driver modules + * @{ + */ + +/** @addtogroup CRC_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup CRC_Private_Defines + * @{ + */ + +/** + * @} + */ + +/** @addtogroup CRC_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup CRC_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup CRC_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup CRC_Private_Functions + * @{ + */ + +/** + * @brief Resets the CRC Data register (DAT). + */ +void CRC32_ResetCrc(void) +{ + /* Reset CRC generator */ + CRC->CRC32CTRL = CRC32_CTRL_RESET; +} + +/** + * @brief Computes the 32-bit CRC of a given data word(32-bit). + * @param Data data word(32-bit) to compute its CRC + * @return 32-bit CRC + */ +uint32_t CRC32_CalcCrc(uint32_t Data) +{ + CRC->CRC32DAT = Data; + + return (CRC->CRC32DAT); +} + +/** + * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). + * @param pBuffer pointer to the buffer containing the data to be computed + * @param BufferLength length of the buffer to be computed + * @return 32-bit CRC + */ +uint32_t CRC32_CalcBufCrc(uint32_t pBuffer[], uint32_t BufferLength) +{ + uint32_t index = 0; + + for (index = 0; index < BufferLength; index++) + { + CRC->CRC32DAT = pBuffer[index]; + } + return (CRC->CRC32DAT); +} + +/** + * @brief Returns the current CRC value. + * @return 32-bit CRC + */ +uint32_t CRC32_GetCrc(void) +{ + return (CRC->CRC32DAT); +} + +/** + * @brief Stores a 8-bit data in the Independent Data(ID) register. + * @param IDValue 8-bit value to be stored in the ID register + */ +void CRC32_SetIDat(uint8_t IDValue) +{ + CRC->CRC32IDAT = IDValue; +} + +/** + * @brief Returns the 8-bit data stored in the Independent Data(ID) register + * @return 8-bit value of the ID register + */ +uint8_t CRC32_GetIDat(void) +{ + return (CRC->CRC32IDAT); +} + +// CRC16 add +void __CRC16_SetLittleEndianFmt(void) +{ + CRC->CRC16CTRL = CRC16_CTRL_LITTLE | CRC->CRC16CTRL; +} +void __CRC16_SetBigEndianFmt(void) +{ + CRC->CRC16CTRL = CRC16_CTRL_BIG & CRC->CRC16CTRL; +} +void __CRC16_SetCleanEnable(void) +{ + CRC->CRC16CTRL = CRC16_CTRL_RESET | CRC->CRC16CTRL; +} +void __CRC16_SetCleanDisable(void) +{ + CRC->CRC16CTRL = CRC16_CTRL_NO_RESET & CRC->CRC16CTRL; +} + +uint16_t __CRC16_CalcCrc(uint8_t Data) +{ + CRC->CRC16DAT = Data; + return (CRC->CRC16D); +} + +void __CRC16_SetCrc(uint8_t Data) +{ + CRC->CRC16DAT = Data; +} + +uint16_t __CRC16_GetCrc(void) +{ + return (CRC->CRC16D); +} + +void __CRC16_SetLRC(uint8_t Data) +{ + CRC->LRC = Data; +} + +uint8_t __CRC16_GetLRC(void) +{ + return (CRC->LRC); +} + +uint16_t CRC16_CalcBufCrc(uint8_t pBuffer[], uint32_t BufferLength) +{ + uint32_t index = 0; + + CRC->CRC16D = 0x00; + for (index = 0; index < BufferLength; index++) + { + CRC->CRC16DAT = pBuffer[index]; + } + return (CRC->CRC16D); +} + +uint16_t CRC16_CalcCRC(uint8_t Data) +{ + CRC->CRC16DAT = Data; + + return (CRC->CRC16D); +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_dma.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_dma.c new file mode 100644 index 0000000..c991ba8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_dma.c @@ -0,0 +1,610 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_dma.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_dma.h" +#include "n32wb03x_rcc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup DMA + * @brief DMA driver modules + * @{ + */ + +/** @addtogroup DMA_Private_TypesDefinitions + * @{ + */ +/** + * @} + */ + +/** @addtogroup DMA_Private_Defines + * @{ + */ + +/* DMA Channelx interrupt pending bit masks */ +#define DMA_CH1_INT_MASK ((uint32_t)(DMA_INTSTS_GLBF1 | DMA_INTSTS_TXCF1 | DMA_INTSTS_HTXF1 | DMA_INTSTS_ERRF1)) +#define DMA_CH2_INT_MASK ((uint32_t)(DMA_INTSTS_GLBF2 | DMA_INTSTS_TXCF2 | DMA_INTSTS_HTXF2 | DMA_INTSTS_ERRF2)) +#define DMA_CH3_INT_MASK ((uint32_t)(DMA_INTSTS_GLBF3 | DMA_INTSTS_TXCF3 | DMA_INTSTS_HTXF3 | DMA_INTSTS_ERRF3)) +#define DMA_CH4_INT_MASK ((uint32_t)(DMA_INTSTS_GLBF4 | DMA_INTSTS_TXCF4 | DMA_INTSTS_HTXF4 | DMA_INTSTS_ERRF4)) +#define DMA_CH5_INT_MASK ((uint32_t)(DMA_INTSTS_GLBF5 | DMA_INTSTS_TXCF5 | DMA_INTSTS_HTXF5 | DMA_INTSTS_ERRF5)) + + +/* DMA CHCFGx registers Masks, MEM2MEM, PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */ +#define CCR_CLEAR_Mask ((uint32_t)0xFFFF800F) + +/** + * @} + */ + +/** @addtogroup DMA_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup DMA_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup DMA_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup DMA_Private_Functions + * @{ + */ + +/** + * @brief Deinitializes the DMAy Channelx registers to their default reset + * values. + * @param DMAyChx where y can be 1 to select the DMA and + * x can be 1 to 5 for DMA Channel. + */ +void DMA_DeInit(DMA_ChannelType* DMAChx) +{ + /* Check the parameters */ + assert_param(IS_DMA_ALL_PERIPH(DMAChx)); + + /* Disable the selected DMAy Channelx */ + DMAChx->CHCFG &= (uint16_t)(~DMA_CHCFG1_CHEN); + + /* Reset DMAy Channelx control register */ + DMAChx->CHCFG = 0; + + /* Reset DMAy Channelx remaining bytes register */ + DMAChx->TXNUM = 0; + + /* Reset DMAy Channelx peripheral address register */ + DMAChx->PADDR = 0; + + /* Reset DMAy Channelx memory address register */ + DMAChx->MADDR = 0; + + if (DMAChx == DMA_CH1) + { + /* Reset interrupt pending bits for DMA1 Channel1 */ + DMA->INTCLR |= DMA_CH1_INT_MASK; + } + else if (DMAChx == DMA_CH2) + { + /* Reset interrupt pending bits for DMA1 Channel2 */ + DMA->INTCLR |= DMA_CH2_INT_MASK; + } + else if (DMAChx == DMA_CH3) + { + /* Reset interrupt pending bits for DMA1 Channel3 */ + DMA->INTCLR |= DMA_CH3_INT_MASK; + } + else if (DMAChx == DMA_CH4) + { + /* Reset interrupt pending bits for DMA1 Channel4 */ + DMA->INTCLR |= DMA_CH4_INT_MASK; + } + else if (DMAChx == DMA_CH5) + { + /* Reset interrupt pending bits for DMA1 Channel5 */ + DMA->INTCLR |= DMA_CH5_INT_MASK; + } + else + { + } +} + +/** + * @brief Initializes the DMAy Channelx according to the specified + * parameters in the DMA_InitParam. + * @param DMAChx where x can be 1 to 5 for DMA to select the DMA Channel. + * @param DMA_InitParam pointer to a DMA_InitType structure that + * contains the configuration information for the specified DMA Channel. + */ +void DMA_Init(DMA_ChannelType* DMAChx, DMA_InitType* DMA_InitParam) +{ + uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_DMA_ALL_PERIPH(DMAChx)); + assert_param(IS_DMA_DIR(DMA_InitParam->Direction)); + assert_param(IS_DMA_BUF_SIZE(DMA_InitParam->BufSize)); + assert_param(IS_DMA_PERIPH_INC_STATE(DMA_InitParam->PeriphInc)); + assert_param(IS_DMA_MEM_INC_STATE(DMA_InitParam->DMA_MemoryInc)); + assert_param(IS_DMA_PERIPH_DATA_SIZE(DMA_InitParam->PeriphDataSize)); + assert_param(IS_DMA_MEMORY_DATA_SIZE(DMA_InitParam->MemDataSize)); + assert_param(IS_DMA_MODE(DMA_InitParam->CircularMode)); + assert_param(IS_DMA_PRIORITY(DMA_InitParam->Priority)); + assert_param(IS_DMA_M2M_STATE(DMA_InitParam->Mem2Mem)); + + /*--------------------------- DMAy Channelx CHCFG Configuration -----------------*/ + /* Get the DMAyChx CHCFG value */ + tmpregister = DMAChx->CHCFG; + /* Clear MEM2MEM, PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */ + tmpregister &= CCR_CLEAR_Mask; + /* Configure DMAy Channelx: data transfer, data size, priority level and mode */ + /* Set DIR bit according to Direction value */ + /* Set CIRC bit according to CircularMode value */ + /* Set PINC bit according to PeriphInc value */ + /* Set MINC bit according to DMA_MemoryInc value */ + /* Set PSIZE bits according to PeriphDataSize value */ + /* Set MSIZE bits according to MemDataSize value */ + /* Set PL bits according to Priority value */ + /* Set the MEM2MEM bit according to Mem2Mem value */ + tmpregister |= DMA_InitParam->Direction | DMA_InitParam->CircularMode | DMA_InitParam->PeriphInc + | DMA_InitParam->DMA_MemoryInc | DMA_InitParam->PeriphDataSize | DMA_InitParam->MemDataSize + | DMA_InitParam->Priority | DMA_InitParam->Mem2Mem; + + /* Write to DMAy Channelx CHCFG */ + DMAChx->CHCFG = tmpregister; + + /*--------------------------- DMAy Channelx TXNUM Configuration ---------------*/ + /* Write to DMAy Channelx TXNUM */ + DMAChx->TXNUM = DMA_InitParam->BufSize; + + /*--------------------------- DMAy Channelx PADDR Configuration ----------------*/ + /* Write to DMAy Channelx PADDR */ + DMAChx->PADDR = DMA_InitParam->PeriphAddr; + + /*--------------------------- DMAy Channelx MADDR Configuration ----------------*/ + /* Write to DMAy Channelx MADDR */ + DMAChx->MADDR = DMA_InitParam->MemAddr; +} + +/** + * @brief Fills each DMA_InitParam member with its default value. + * @param DMA_InitParam pointer to a DMA_InitType structure which will + * be initialized. + */ +void DMA_StructInit(DMA_InitType* DMA_InitParam) +{ + /*-------------- Reset DMA init structure parameters values ------------------*/ + /* Initialize the PeriphAddr member */ + DMA_InitParam->PeriphAddr = 0; + /* Initialize the MemAddr member */ + DMA_InitParam->MemAddr = 0; + /* Initialize the Direction member */ + DMA_InitParam->Direction = DMA_DIR_PERIPH_SRC; + /* Initialize the BufSize member */ + DMA_InitParam->BufSize = 0; + /* Initialize the PeriphInc member */ + DMA_InitParam->PeriphInc = DMA_PERIPH_INC_DISABLE; + /* Initialize the DMA_MemoryInc member */ + DMA_InitParam->DMA_MemoryInc = DMA_MEM_INC_DISABLE; + /* Initialize the PeriphDataSize member */ + DMA_InitParam->PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + /* Initialize the MemDataSize member */ + DMA_InitParam->MemDataSize = DMA_MemoryDataSize_Byte; + /* Initialize the CircularMode member */ + DMA_InitParam->CircularMode = DMA_MODE_NORMAL; + /* Initialize the Priority member */ + DMA_InitParam->Priority = DMA_PRIORITY_LOW; + /* Initialize the Mem2Mem member */ + DMA_InitParam->Mem2Mem = DMA_M2M_DISABLE; +} + +/** + * @brief Enables or disables the specified DMAy Channelx. + * @param DMAChx where x can be 1 to 5 for DMA to select the DMA Channel. + * @param Cmd new state of the DMA Channelx. + * This parameter can be: ENABLE or DISABLE. + */ +void DMA_EnableChannel(DMA_ChannelType* DMAChx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_DMA_ALL_PERIPH(DMAChx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the selected DMAy Channelx */ + DMAChx->CHCFG |= DMA_CHCFG1_CHEN; + } + else + { + /* Disable the selected DMAy Channelx */ + DMAChx->CHCFG &= (uint16_t)(~DMA_CHCFG1_CHEN); + } +} + +/** + * @brief Enables or disables the specified DMAy Channelx interrupts. + * @param DMAChx where x can be 1 to 5 for DMA to select the DMA Channel. + * @param DMAInt specifies the DMA interrupts sources to be enabled + * or disabled. + * This parameter can be any combination of the following values: + * @arg DMA_INT_TXC Transfer complete interrupt mask + * @arg DMA_INT_HTX Half transfer interrupt mask + * @arg DMA_INT_ERR Transfer error interrupt mask + * @param Cmd new state of the specified DMA interrupts. + * This parameter can be: ENABLE or DISABLE. + */ +void DMA_ConfigInt(DMA_ChannelType* DMAChx, uint32_t DMAInt, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_DMA_ALL_PERIPH(DMAChx)); + assert_param(IS_DMA_CONFIG_INT(DMAInt)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected DMA interrupts */ + DMAChx->CHCFG |= DMAInt; + } + else + { + /* Disable the selected DMA interrupts */ + DMAChx->CHCFG &= ~DMAInt; + } +} + +/** + * @brief Sets the number of data units in the current DMAy Channelx transfer. + * @param DMAChx where x can be 1 to 5 for DMA to select the DMA Channel. + * @param DataNumber The number of data units in the current DMAy Channelx + * transfer. + * @note This function can only be used when the DMAyChx is disabled. + */ +void DMA_SetCurrDataCounter(DMA_ChannelType* DMAChx, uint16_t DataNumber) +{ + /* Check the parameters */ + assert_param(IS_DMA_ALL_PERIPH(DMAChx)); + + /*--------------------------- DMAy Channelx TXNUM Configuration ---------------*/ + /* Write to DMA Channelx TXNUM */ + DMAChx->TXNUM = DataNumber; +} + +/** + * @brief Returns the number of remaining data units in the current + * DMA Channelx transfer. + * @param DMAChx where x can be 1 to 5 for DMA to select the DMA Channel. + * @return The number of remaining data units in the current DMA Channelx + * transfer. + */ +uint16_t DMA_GetCurrDataCounter(DMA_ChannelType* DMAChx) +{ + /* Check the parameters */ + assert_param(IS_DMA_ALL_PERIPH(DMAChx)); + /* Return the number of remaining data units for DMAy Channelx */ + return ((uint16_t)(DMAChx->TXNUM)); +} + +/** + * @brief Checks whether the specified DMA Channelx flag is set or not. + * @param DMAFlag specifies the flag to check. + * This parameter can be one of the following values: + * @arg DMA_FLAG_GL1 DMA Channel1 global flag. + * @arg DMA_FLAG_TC1 DMA Channel1 transfer complete flag. + * @arg DMA_FLAG_HT1 DMA Channel1 half transfer flag. + * @arg DMA_FLAG_TE1 DMA Channel1 transfer error flag. + * @arg DMA_FLAG_GL2 DMA Channel2 global flag. + * @arg DMA_FLAG_TC2 DMA Channel2 transfer complete flag. + * @arg DMA_FLAG_HT2 DMA Channel2 half transfer flag. + * @arg DMA_FLAG_TE2 DMA Channel2 transfer error flag. + * @arg DMA_FLAG_GL3 DMA Channel3 global flag. + * @arg DMA_FLAG_TC3 DMA Channel3 transfer complete flag. + * @arg DMA_FLAG_HT3 DMA Channel3 half transfer flag. + * @arg DMA_FLAG_TE3 DMA Channel3 transfer error flag. + * @arg DMA_FLAG_GL4 DMA Channel4 global flag. + * @arg DMA_FLAG_TC4 DMA Channel4 transfer complete flag. + * @arg DMA_FLAG_HT4 DMA Channel4 half transfer flag. + * @arg DMA_FLAG_TE4 DMA Channel4 transfer error flag. + * @arg DMA_FLAG_GL5 DMA Channel5 global flag. + * @arg DMA_FLAG_TC5 DMA Channel5 transfer complete flag. + * @arg DMA_FLAG_HT5 DMA Channel5 half transfer flag. + * @arg DMA_FLAG_TE5 DMA Channel5 transfer error flag. + * @param DMAy DMA + * This parameter can be one of the following values: + * @arg DMA . + * @return The new state of DMAFlag (SET or RESET). + */ +FlagStatus DMA_GetFlagStatus(uint32_t DMAFlag, DMA_Module* DMAy) +{ + FlagStatus bitstatus = RESET; + uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_DMA_GET_FLAG(DMAFlag)); + assert_param(IS_DMA_PERIPH(DMAy)); + /* Calculate the used DMAy */ + /* Get DMAy INTSTS register value */ + tmpregister = DMAy->INTSTS; + + /* Check the status of the specified DMAy flag */ + if ((tmpregister & DMAFlag) != (uint32_t)RESET) + { + /* DMAyFlag is set */ + bitstatus = SET; + } + else + { + /* DMAyFlag is reset */ + bitstatus = RESET; + } + + /* Return the DMAyFlag status */ + return bitstatus; +} + +/** + * @brief Clears the DMA Channelx's pending flags. + * @param DMAFlag specifies the flag to clear. + * This parameter can be any combination (for the same DMA) of the following values: + * @arg DMA_FLAG_GL1 DMA Channel1 global flag. + * @arg DMA_FLAG_TC1 DMA Channel1 transfer complete flag. + * @arg DMA_FLAG_HT1 DMA Channel1 half transfer flag. + * @arg DMA_FLAG_TE1 DMA Channel1 transfer error flag. + * @arg DMA_FLAG_GL2 DMA Channel2 global flag. + * @arg DMA_FLAG_TC2 DMA Channel2 transfer complete flag. + * @arg DMA_FLAG_HT2 DMA Channel2 half transfer flag. + * @arg DMA_FLAG_TE2 DMA Channel2 transfer error flag. + * @arg DMA_FLAG_GL3 DMA Channel3 global flag. + * @arg DMA_FLAG_TC3 DMA Channel3 transfer complete flag. + * @arg DMA_FLAG_HT3 DMA Channel3 half transfer flag. + * @arg DMA_FLAG_TE3 DMA Channel3 transfer error flag. + * @arg DMA_FLAG_GL4 DMA Channel4 global flag. + * @arg DMA_FLAG_TC4 DMA Channel4 transfer complete flag. + * @arg DMA_FLAG_HT4 DMA Channel4 half transfer flag. + * @arg DMA_FLAG_TE4 DMA Channel4 transfer error flag. + * @arg DMA_FLAG_GL5 DMA Channel5 global flag. + * @arg DMA_FLAG_TC5 DMA Channel5 transfer complete flag. + * @arg DMA_FLAG_HT5 DMA Channel5 half transfer flag. + * @arg DMA_FLAG_TE5 DMA Channel5 transfer error flag. + * @param DMA DMA + * This parameter can be one of the following values: + * @arg DMA . + */ +void DMA_ClearFlag(uint32_t DMAFlag, DMA_Module* DMAy) +{ + /* Check the parameters */ + assert_param(IS_DMA_CLEAR_FLAG(DMAFlag)); + assert_param(IS_DMA_PERIPH(DMAy)); + /* Calculate the used DMAy */ + /* Clear the selected DMAy flags */ + DMAy->INTCLR = DMAFlag; +} + +/** + * @brief Checks whether the specified DMA Channelx interrupt has occurred or not. + * @param DMA_IT specifies the DMAy interrupt source to check. + * This parameter can be one of the following values: + * @arg DMA_INT_GLB1 DMA Channel1 global interrupt. + * @arg DMA_INT_TXC1 DMA Channel1 transfer complete interrupt. + * @arg DMA_INT_HTX1 DMA Channel1 half transfer interrupt. + * @arg DMA_INT_ERR1 DMA Channel1 transfer error interrupt. + * @arg DMA_INT_GLB2 DMA Channel2 global interrupt. + * @arg DMA_INT_TXC2 DMA Channel2 transfer complete interrupt. + * @arg DMA_INT_HTX2 DMA Channel2 half transfer interrupt. + * @arg DMA_INT_ERR2 DMA Channel2 transfer error interrupt. + * @arg DMA_INT_GLB3 DMA Channel3 global interrupt. + * @arg DMA_INT_TXC3 DMA Channel3 transfer complete interrupt. + * @arg DMA_INT_HTX3 DMA Channel3 half transfer interrupt. + * @arg DMA_INT_ERR3 DMA Channel3 transfer error interrupt. + * @arg DMA_INT_GLB4 DMA Channel4 global interrupt. + * @arg DMA_INT_TXC4 DMA Channel4 transfer complete interrupt. + * @arg DMA_INT_HTX4 DMA Channel4 half transfer interrupt. + * @arg DMA_INT_ERR4 DMA Channel4 transfer error interrupt. + * @arg DMA_INT_GLB5 DMA Channel5 global interrupt. + * @arg DMA_INT_TXC5 DMA Channel5 transfer complete interrupt. + * @arg DMA_INT_HTX5 DMA Channel5 half transfer interrupt. + * @arg DMA_INT_ERR5 DMA Channel5 transfer error interrupt. + * @param DMA DMA + * This parameter can be one of the following values: + * @arg DMA . + * @return The new state of DMA_IT (SET or RESET). + */ +INTStatus DMA_GetIntStatus(uint32_t DMA_IT, DMA_Module* DMAy) +{ + INTStatus bitstatus = RESET; + uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_DMA_GET_IT(DMA_IT)); + assert_param(IS_DMA_PERIPH(DMAy)); + /* Calculate the used DMA */ + /* Get DMAy INTSTS register value */ + tmpregister = DMAy->INTSTS; + + /* Check the status of the specified DMAy interrupt */ + if ((tmpregister & DMA_IT) != (uint32_t)RESET) + { + /* DMAy_IT is set */ + bitstatus = SET; + } + else + { + /* DMAy_IT is reset */ + bitstatus = RESET; + } + /* Return the DMAInt status */ + return bitstatus; +} + +/** + * @brief Clears the DMA Channelx's interrupt pending bits. + * @param DMA_IT specifies the DMA interrupt pending bit to clear. + * This parameter can be any combination (for the same DMA) of the following values: + * @arg DMA_INT_GLB1 DMA Channel1 global interrupt. + * @arg DMA_INT_TXC1 DMA Channel1 transfer complete interrupt. + * @arg DMA_INT_HTX1 DMA Channel1 half transfer interrupt. + * @arg DMA_INT_ERR1 DMA Channel1 transfer error interrupt. + * @arg DMA_INT_GLB2 DMA Channel2 global interrupt. + * @arg DMA_INT_TXC2 DMA Channel2 transfer complete interrupt. + * @arg DMA_INT_HTX2 DMA Channel2 half transfer interrupt. + * @arg DMA_INT_ERR2 DMA Channel2 transfer error interrupt. + * @arg DMA_INT_GLB3 DMA Channel3 global interrupt. + * @arg DMA_INT_TXC3 DMA Channel3 transfer complete interrupt. + * @arg DMA_INT_HTX3 DMA Channel3 half transfer interrupt. + * @arg DMA_INT_ERR3 DMA Channel3 transfer error interrupt. + * @arg DMA_INT_GLB4 DMA Channel4 global interrupt. + * @arg DMA_INT_TXC4 DMA Channel4 transfer complete interrupt. + * @arg DMA_INT_HTX4 DMA Channel4 half transfer interrupt. + * @arg DMA_INT_ERR4 DMA Channel4 transfer error interrupt. + * @arg DMA_INT_GLB5 DMA Channel5 global interrupt. + * @arg DMA_INT_TXC5 DMA Channel5 transfer complete interrupt. + * @arg DMA_INT_HTX5 DMA Channel5 half transfer interrupt. + * @arg DMA_INT_ERR5 DMA Channel5 transfer error interrupt. + * @param DMAy DMA + * This parameter can be one of the following values: + * @arg DMA . + */ +void DMA_ClrIntPendingBit(uint32_t DMA_IT, DMA_Module* DMAy) +{ + /* Check the parameters */ + assert_param(IS_DMA_CLR_INT(DMA_IT)); + assert_param(IS_DMA_PERIPH(DMAy)); + /* Calculate the used DMA */ + /* Clear the selected DMA interrupt pending bits */ + DMAy->INTCLR = DMA_IT; +} + +/** + * @brief Set the DMA Channelx's remap request. + * @param DMA_REMAP specifies the DMA request. + * This parameter can be set by the following values: + * @arg DMA_REMAP_ADC DMA Request For ADC + * @arg DMA_REMAP_USART1_TX DMA Request For USART1_TX + * @arg DMA_REMAP_USART1_RX DMA Request For USART1_RX + * @arg DMA_REMAP_LPUART_TX DMA Request For LPUART_TX + * @arg DMA_REMAP_LPUART_RX DMA Request For LPUART_RX + * @arg DMA_REMAP_USART2_TX DMA Request For USART2_TX + * @arg DMA_REMAP_USART2_RX DMA Request For USART2_RX + * @arg DMA_REMAP_SPI1_TX DMA Request For SPI1_TX + * @arg DMA_REMAP_SPI1_RX DMA Request For SPI1_RX + * @arg DMA_REMAP_SPI2_TX DMA Request For SPI2_TX + * @arg DMA_REMAP_SPI2_RX DMA Request For SPI2_RX + * @arg DMA_REMAP_I2C_TX DMA Request For I2C_TX + * @arg DMA_REMAP_I2C_RX DMA Request For I2C_RX + * @arg DMA_REMAP_TIM1_CH1 DMA Request For TIM1_CH1 + * @arg DMA_REMAP_TIM1_CH2 DMA Request For TIM1_CH2 + * @arg DMA_REMAP_TIM1_CH3 DMA Request For TIM1_CH3 + * @arg DMA_REMAP_TIM1_CH4 DMA Request For TIM1_CH4 + * @arg DMA_REMAP_TIM1_COM DMA Request For TIM1_COM + * @arg DMA_REMAP_TIM1_UP DMA Request For TIM1_UP + * @arg DMA_REMAP_TIM1_TRIG DMA Request For TIM1_TRIG + * @arg DMA_REMAP_TIM3_CH1 DMA Request For TIM3_CH1 + * @arg DMA_REMAP_TIM3_CH3 DMA Request For TIM3_CH3 + * @arg DMA_REMAP_TIM3_CH4 DMA Request For TIM3_CH4 + * @arg DMA_REMAP_TIM3_UP DMA Request For TIM3_UP + * @arg DMA_REMAP_TIM3_TRIG DMA Request For TIM3_TRIG + * @arg DMA_REMAP_TIM6 DMA Request For TIM6 + * @param DMAy DMA + * This parameter can be one of the following values: + * @arg DMA . + * @param DMAChx where x can be 1 to 5 for DMA to select the DMA Channel. + * @param Cmd new state of the DMA Channelx. + * This parameter can be: ENABLE or DISABLE. + */ +void DMA_RequestRemap(uint32_t DMA_REMAP, DMA_Module* DMAy, DMA_ChannelType* DMAChx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_DMA_REMAP(DMA_REMAP)); + assert_param(IS_DMA_PERIPH(DMAy)); + assert_param(IS_DMA_ALL_PERIPH(DMAChx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Calculate the used DMAy */ + /* Set the selected DMAy remap request */ + DMAChx->CHSEL = DMA_REMAP; + } + else + { + /* Clear DMAy remap */ + DMAChx->CHSEL = 0; + } +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_exti.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_exti.c new file mode 100644 index 0000000..babc7ca --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_exti.c @@ -0,0 +1,293 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_exti.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_exti.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup EXTI + * @brief EXTI driver modules + * @{ + */ + +/** @addtogroup EXTI_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup EXTI_Private_Defines + * @{ + */ + +#define EXTI_LINENONE ((uint32_t)0x00000000) /* No interrupt selected */ + +/** + * @} + */ + +/** @addtogroup EXTI_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup EXTI_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup EXTI_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup EXTI_Private_Functions + * @{ + */ + +/** + * @brief Deinitializes the EXTI peripheral registers to their default reset values. + */ +void EXTI_DeInit(void) +{ + EXTI->IMASK = 0x00000000; + EXTI->EMASK = 0x00000000; + EXTI->RT_CFG = 0x00000000; + EXTI->FT_CFG = 0x00000000; + EXTI->PEND = 0x00FFFFFF; +} + +/** + * @brief Initializes the EXTI peripheral according to the specified + * parameters in the EXTI_InitStruct. + * @param EXTI_InitStruct pointer to a EXTI_InitType structure + * that contains the configuration information for the EXTI peripheral. + */ +void EXTI_InitPeripheral(EXTI_InitType* EXTI_InitStruct) +{ + uint32_t tmp = 0; + + /* Check the parameters */ + assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode)); + assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger)); + assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line)); + assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd)); + + tmp = (uint32_t)EXTI_BASE; + + if (EXTI_InitStruct->EXTI_LineCmd != DISABLE) + { + /* Clear EXTI line configuration */ + EXTI->IMASK &= ~EXTI_InitStruct->EXTI_Line; + EXTI->EMASK &= ~EXTI_InitStruct->EXTI_Line; + + tmp += EXTI_InitStruct->EXTI_Mode; + + *(__IO uint32_t*)tmp |= EXTI_InitStruct->EXTI_Line; + + /* Clear Rising Falling edge configuration */ + EXTI->RT_CFG &= ~EXTI_InitStruct->EXTI_Line; + EXTI->FT_CFG &= ~EXTI_InitStruct->EXTI_Line; + + /* Select the trigger for the selected external interrupts */ + if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling) + { + /* Rising Falling edge */ + EXTI->RT_CFG |= EXTI_InitStruct->EXTI_Line; + EXTI->FT_CFG |= EXTI_InitStruct->EXTI_Line; + } + else + { + tmp = (uint32_t)EXTI_BASE; + tmp += EXTI_InitStruct->EXTI_Trigger; + + *(__IO uint32_t*)tmp |= EXTI_InitStruct->EXTI_Line; + } + } + else + { + tmp += EXTI_InitStruct->EXTI_Mode; + + /* Disable the selected external lines */ + *(__IO uint32_t*)tmp &= ~EXTI_InitStruct->EXTI_Line; + } +} + +/** + * @brief Fills each EXTI_InitStruct member with its reset value. + * @param EXTI_InitStruct pointer to a EXTI_InitType structure which will + * be initialized. + */ +void EXTI_InitStruct(EXTI_InitType* EXTI_InitStruct) +{ + EXTI_InitStruct->EXTI_Line = EXTI_LINENONE; + EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling; + EXTI_InitStruct->EXTI_LineCmd = DISABLE; +} + +/** + * @brief Generates a Software interrupt. + * @param EXTI_Line specifies the EXTI lines to be enabled or disabled. + * This parameter can be any combination of EXTI_Linex where x can be (0..13). + */ +void EXTI_TriggerSWInt(uint32_t EXTI_Line) +{ + /* Check the parameters */ + assert_param(IS_EXTI_LINE(EXTI_Line)); + + EXTI->SWIE |= EXTI_Line; +} + +/** + * @brief Checks whether the specified EXTI line flag is set or not. + * @param EXTI_Line specifies the EXTI line flag to check. + * This parameter can be: + * @arg EXTI_Linex External interrupt line x where x(0..13) + * @return The new state of EXTI_Line (SET or RESET). + */ +FlagStatus EXTI_GetStatusFlag(uint32_t EXTI_Line) +{ + FlagStatus bitstatus = RESET; + /* Check the parameters */ + assert_param(IS_GET_EXTI_LINE(EXTI_Line)); + + if ((EXTI->PEND & EXTI_Line) != (uint32_t)RESET) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/** + * @brief Clears the EXTI's line pending flags. + * @param EXTI_Line specifies the EXTI lines flags to clear. + * This parameter can be any combination of EXTI_Linex where x can be (0..13). + */ +void EXTI_ClrStatusFlag(uint32_t EXTI_Line) +{ + /* Check the parameters */ + assert_param(IS_EXTI_LINE(EXTI_Line)); + + EXTI->PEND = EXTI_Line; +} + +/** + * @brief Checks whether the specified EXTI line is asserted or not. + * @param EXTI_Line specifies the EXTI line to check. + * This parameter can be: + * @arg EXTI_Linex External interrupt line x where x(0..13) + * @return The new state of EXTI_Line (SET or RESET). + */ +INTStatus EXTI_GetITStatus(uint32_t EXTI_Line) +{ + INTStatus bitstatus = RESET; + uint32_t enablestatus = 0; + /* Check the parameters */ + assert_param(IS_GET_EXTI_LINE(EXTI_Line)); + + enablestatus = EXTI->IMASK & EXTI_Line; + if (((EXTI->PEND & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/** + * @brief Clears the EXTI's line pending bits. + * @param EXTI_Line specifies the EXTI lines to clear. + * This parameter can be any combination of EXTI_Linex where x can be (0..13). + */ +void EXTI_ClrITPendBit(uint32_t EXTI_Line) +{ + /* Check the parameters */ + assert_param(IS_EXTI_LINE(EXTI_Line)); + + EXTI->PEND = EXTI_Line; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_gpio.c new file mode 100644 index 0000000..8e641be --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_gpio.c @@ -0,0 +1,687 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_gpio.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_gpio.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup GPIO + * @brief GPIO driver modules + * @{ + */ + +/** @addtogroup GPIO_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup GPIO_Private_Defines + * @{ + */ + +#define GPIO_MODE ((uint32_t)0x00000003) +#define EXTI_MODE ((uint32_t)0x10000000) +#define GPIO_MODE_IT ((uint32_t)0x00010000) +#define GPIO_MODE_EVT ((uint32_t)0x00020000) +#define RISING_EDGE ((uint32_t)0x00100000) +#define FALLING_EDGE ((uint32_t)0x00200000) +#define GPIO_OUTPUT_TYPE ((uint32_t)0x00000010) + +/** + * @} + */ + +/** @addtogroup GPIO_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup GPIO_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup GPIO_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup GPIO_Private_Functions + * @{ + */ + +/** + * @brief Deinitializes the GPIOx peripheral registers to their default reset values. + * @param GPIOx where x can be (A,B,C,D,F) to select the GPIO peripheral. + */ +void GPIO_DeInit(GPIO_Module* GPIOx) +{ + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_GPIOA, ENABLE); + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_GPIOA, DISABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_GPIOB, ENABLE); + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_GPIOB, DISABLE); + } + else + { + return; + } +} + +/** + * @brief Deinitializes the GPIOx peripheral registers to their default reset values. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @param GPIO_Pin specifies the port bit to be written. + * This parameter can be one of GPIO_PIN_x where x can be (0..13). + * All port bits are not necessarily available on all GPIOs. + */ +void GPIO_DeInitPin(GPIO_Module* GPIOx, uint32_t Pin) +{ + uint32_t pos = 0x00U, currentpin = 0x00U; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, Pin)); + + while((Pin >> pos) != 0) + { + /* Get the IO position */ + currentpin = (Pin) & (1U << pos); + + if(currentpin) + { + /*------------------------- GPIO Mode Configuration --------------------*/ + /* Configure IO Direction in Analog Mode */ + GPIOx->PMODE |= (GPIO_PMODE0 << (pos * 2U)); + + /* Configure the default Alternate Function in current IO */ + if(pos & 0x08) + GPIOx->AFH |= ((0x0FUL) << ((pos & 0x07U) * 4U)); + else + GPIOx->AFL |= ((0x0FUL) << ((pos & 0x07U) * 4U)); + + /* Configure the default value IO Output Type */ + GPIOx->POTYPE &= ~(GPIO_POTYPE_POT_0 << pos); + + /* Deactivate the Pull-up and Pull-down resistor for the current IO */ + GPIOx->PUPD &= ~(GPIO_PUPD0 << (pos * 2U)); + + /* Configure the default value for IO Speed */ + GPIOx->SR |= (GPIO_SR_SR0 << pos); + + /* Configure the default value for IO Speed */ + GPIOx->DS &= ~(GPIO_DS_DS0 << pos); + } + pos++; + } + +} + +/** + * @brief Deinitializes the Alternate Functions (remap, event control + * and EXTI configuration) registers to their default reset values. + */ +void GPIO_AFIOInitDefault(void) +{ + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_AFIO, ENABLE); + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_AFIO, DISABLE); +} + +/** + * @brief Initializes the GPIOx peripheral according to the specified + * parameters in the GPIO_InitStruct. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @param GPIO_InitStruct pointer to a GPIO_InitType structure that + * contains the configuration information for the specified GPIO peripheral. + */ + +void GPIO_InitPeripheral(GPIO_Module* GPIOx, GPIO_InitType * GPIO_InitStruct) +{ + uint32_t pos = 0x00U, currentpin = 0x00U; + uint32_t tmpregister = 0x00U; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, GPIO_InitStruct->Pin)); + assert_param(IS_GPIO_AF(GPIO_InitStruct->GPIO_Alternate)); + assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode)); + assert_param(IS_GPIO_PULL(GPIO_InitStruct->GPIO_Pull)); + assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed)); + assert_param(IS_GPIO_CURRENT(GPIO_InitStruct->GPIO_Current)); + + while(((GPIO_InitStruct->Pin) >> pos) != 0) + { + /* Get the IO position */ + currentpin = (GPIO_InitStruct->Pin) & (1U << pos); + + if(currentpin) + { + /*--------------------- GPIO Mode Configuration ------------------------*/ + /* In case of Alternate function mode selection */ + if((GPIO_InitStruct->GPIO_Mode == GPIO_MODE_AF_PP) || (GPIO_InitStruct->GPIO_Mode == GPIO_MODE_AF_OD)) + { + /* Check the Alternate function parameters */ + assert_param(IS_GPIO_AF(GPIO_InitStruct->GPIO_Alternate)); + + /* Configure Alternate function mapped with the current IO */ + if(pos & 0x08) + { + tmpregister = GPIOx->AFH; + tmpregister &= ~((uint32_t)0xF << ((uint32_t)(pos & (uint32_t)0x07) * 4U)); + tmpregister |= ((uint32_t)(GPIO_InitStruct->GPIO_Alternate) << ((uint32_t)(pos & (uint32_t)0x07) * 4U)) ; + GPIOx->AFH = tmpregister; + } + else + { + tmpregister = GPIOx->AFL; + tmpregister &= ~((uint32_t)0xF << ((uint32_t)(pos & (uint32_t)0x07) * 4U)) ; + tmpregister |= ((uint32_t)(GPIO_InitStruct->GPIO_Alternate) << ((uint32_t)(pos & (uint32_t)0x07) * 4U)) ; + GPIOx->AFL = tmpregister; + } + } + + /* In case of Output or Alternate function mode selection */ + if ((GPIO_InitStruct->GPIO_Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_InitStruct->GPIO_Mode == GPIO_MODE_OUTPUT_OD) + ||(GPIO_InitStruct->GPIO_Mode == GPIO_MODE_AF_PP) || (GPIO_InitStruct->GPIO_Mode == GPIO_MODE_AF_OD)) + { + /* Configure the IO Output Type */ + tmpregister = GPIOx->POTYPE; + tmpregister &= ~(GPIO_POTYPE_POT_0 << pos); + tmpregister |= (((GPIO_InitStruct->GPIO_Mode >> 4U) & 0x01U) << pos); + GPIOx->POTYPE = tmpregister; + } + + /*---------------------------- GPIO Mode Configuration -----------------------*/ + /* Configure IO Direction mode (Input, Output, Alternate or Analog) */ + tmpregister = GPIOx->PMODE; + tmpregister &= ~(GPIO_PMODE0 << (pos * 2U)); + tmpregister |= (((GPIO_InitStruct->GPIO_Mode & 0x03U) << (pos * 2U))); + GPIOx->PMODE = tmpregister; + + /* Configure pull-down mode */ + tmpregister = GPIOx->PUPD; + tmpregister &= ~(GPIO_PUPD0 << (pos * 2U)); + tmpregister |= (GPIO_InitStruct->GPIO_Pull << (pos * 2U)); + GPIOx->PUPD = tmpregister; + + /* Configure slew rate */ + tmpregister = GPIOx->SR; + tmpregister &= ~(GPIO_SR_SR0 << pos); + tmpregister |= (GPIO_InitStruct->GPIO_Speed << pos); + GPIOx->SR = tmpregister; + + /* Configure driver current */ + tmpregister = GPIOx->DS; + tmpregister &= ~(GPIO_DS_DS0 << pos* 2U); + tmpregister |= (GPIO_InitStruct->GPIO_Current << pos* 2U); + GPIOx->DS = tmpregister; + } + pos++; + } +} + +/** + * @brief Fills each GPIO_InitStruct member with its default value. + * @param GPIO_InitStruct pointer to a GPIO_InitType structure which will + * be initialized. + */ +void GPIO_InitStruct(GPIO_InitType* GPIO_InitStruct) +{ + /* Reset GPIO init structure parameters values */ + GPIO_InitStruct->Pin = GPIO_PIN_ALL; + GPIO_InitStruct->GPIO_Alternate = GPIO_NO_AF; + GPIO_InitStruct->GPIO_Mode = GPIO_MODE_INPUT; + GPIO_InitStruct->GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStruct->GPIO_Speed = GPIO_SPEED_LOW; + GPIO_InitStruct->GPIO_Current = GPIO_DC_LOW; +} + +/** + * @brief Reads the specified input port pin. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @param Pin specifies the port bit to read. + * This parameter can be GPIO_Pin_x where x can be (0..13). + * @return The input port pin value. + */ +uint8_t GPIO_ReadInputDataBit(GPIO_Module* GPIOx, uint16_t Pin) +{ + uint8_t bitstatus = 0x00; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, Pin)); + + if ((GPIOx->PID & Pin) != (uint32_t)Bit_RESET) + { + bitstatus = (uint8_t)Bit_SET; + } + else + { + bitstatus = (uint8_t)Bit_RESET; + } + return bitstatus; +} + +/** + * @brief Reads the specified GPIO input data port. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @return GPIO input data port value. + */ +uint16_t GPIO_ReadInputData(GPIO_Module* GPIOx) +{ + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + return ((uint16_t)GPIOx->PID); +} + +/** + * @brief Reads the specified output data port bit. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @param Pin specifies the port bit to read. + * This parameter can be GPIO_Pin_x where x can be (0..13). + * @return The output port pin value. + */ +uint8_t GPIO_ReadOutputDataBit(GPIO_Module* GPIOx, uint16_t Pin) +{ + uint8_t bitstatus = 0x00; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, Pin)); + + if ((GPIOx->POD & Pin) != (uint32_t)Bit_RESET) + { + bitstatus = (uint8_t)Bit_SET; + } + else + { + bitstatus = (uint8_t)Bit_RESET; + } + return bitstatus; +} + +/** + * @brief Reads the specified GPIO output data port. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @return GPIO output data port value. + */ +uint16_t GPIO_ReadOutputData(GPIO_Module* GPIOx) +{ + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + return ((uint16_t)GPIOx->POD); +} + +/** + * @brief Sets the selected data port bits. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @param Pin specifies the port bits to be written. + * This parameter can be any combination of GPIO_Pin_x where x can be (0..13). + */ +void GPIO_SetBits(GPIO_Module* GPIOx, uint16_t Pin) +{ + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, Pin)); + + GPIOx->PBSC = Pin; +} + +/** + * @brief Clears the selected data port bits. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @param Pin specifies the port bits to be written. + * This parameter can be any combination of GPIO_Pin_x where x can be (0..13). + */ +void GPIO_ResetBits(GPIO_Module* GPIOx, uint16_t Pin) +{ + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, Pin)); + + GPIOx->PBC = Pin; +} + +/** + * @brief Sets or clears the selected data port bit. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @param Pin specifies the port bit to be written. + * This parameter can be one of GPIO_Pin_x where x can be (0..13). + * @param BitCmd specifies the value to be written to the selected bit. + * This parameter can be one of the Bit_OperateType enum values: + * @arg Bit_RESET to clear the port pin + * @arg Bit_SET to set the port pin + */ +void GPIO_WriteBit(GPIO_Module* GPIOx, uint16_t Pin, Bit_OperateType BitCmd) +{ + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, Pin)); + assert_param(IS_GPIO_BIT_OPERATE(BitCmd)); + + if (BitCmd != Bit_RESET) + { + GPIOx->PBSC = Pin; + } + else + { + GPIOx->PBC = Pin; + } +} + +/** + * @brief Writes data to the specified GPIO data port. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @param PortVal specifies the value to be written to the port output data register. + */ +void GPIO_Write(GPIO_Module* GPIOx, uint16_t PortVal) +{ + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + GPIOx->POD = PortVal; +} + +/** + * @brief Toggles the specified GPIO pins. + * @param GPIOx Where x can be (A,B) to select the GPIO peripheral. + * All port bits are not necessarily available on all GPIOs. + * @param GPIO_Pin Specifies the pins to be toggled. + * @retval None + */ +void GPIO_TogglePin(GPIO_Module *GPIOx, uint16_t Pin) +{ + /* Check the parameters */ + assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, Pin)); + assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, Pin)); + GPIOx->POD ^= Pin; +} + +/** + * @brief Locks GPIO Pins configuration registers. + * @param GPIOx where x can be (A,B) to select the GPIO peripheral. + * @param Pin specifies the port bit to be written. + * This parameter can be any combination of GPIO_Pin_x where x can be (0..13). + */ +void GPIO_ConfigPinLock(GPIO_Module* GPIOx, uint16_t Pin) +{ + uint32_t tmp = 0x00010000; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + assert_param(IS_GPIO_PIN_AVAILABLE(GPIOx, Pin)); + + tmp |= Pin; + /* Set LCKK bit */ + GPIOx->PLOCK = tmp; + /* Reset LCKK bit */ + GPIOx->PLOCK = Pin; + /* Set LCKK bit */ + GPIOx->PLOCK = tmp; + /* Read LCKK bit*/ + tmp = GPIOx->PLOCK; + /* Read LCKK bit*/ + tmp = GPIOx->PLOCK; +} + +/** + * @brief Selects the GPIO pin used as EXTI Line. + * @param PortSource selects the GPIO port to be used as source for EXTI lines. + * This parameter can be GPIO_PortSourceGPIOx where x can be (A,B). + * @param PinSource specifies the EXTI line to be configured. + * This parameter can be GPIO_PinSourcex where x can be (0..13). + */ +void GPIO_ConfigEXTILine(uint8_t PortSource, uint8_t PinSource) +{ + /* Check the parameters */ + assert_param(IS_GPIO_EXTI_PORT_SOURCE(PortSource)); + assert_param(IS_GPIO_PIN_SOURCE(PinSource)); + + if(PortSource == GPIOA_PORT_SOURCE) + { + switch(PinSource) + { + case 0: + AFIO->EXTI_CFG[0] &= ~(0x03U); + break; + case 1: + AFIO->EXTI_CFG[0] &= ~(0x03U); + AFIO->EXTI_CFG[0] |= (0x01U); + break; + case 2: + AFIO->EXTI_CFG[0] &= ~(0x03U << 4U); + break; + case 3: + AFIO->EXTI_CFG[0] &= ~(0x03U << 4U); + AFIO->EXTI_CFG[0] |= (0x01U << 4U); + break; + case 4: + AFIO->EXTI_CFG[1] &= ~(0x03U << 8U); + AFIO->EXTI_CFG[1] |= (0x02U << 8U); + break; + case 5: + AFIO->EXTI_CFG[0] &= ~(0x03U << 12U); + break; + case 6: + AFIO->EXTI_CFG[0] &= ~(0x03U << 8U); + break; + default: + break; + } + } + else{ + switch(PinSource) + { + case 0: + AFIO->EXTI_CFG[0] &= ~(0x03U); + AFIO->EXTI_CFG[0] |= (0x02U); + break; + case 1: + AFIO->EXTI_CFG[0] &= ~(0x03U << 4U); + AFIO->EXTI_CFG[0] |= (0x02U << 4U); + break; + case 2: + AFIO->EXTI_CFG[0] &= ~(0x03U << 8U); + AFIO->EXTI_CFG[0] |= (0x01U << 8U); + break; + case 3: + AFIO->EXTI_CFG[0] &= ~(0x03U << 12U); + AFIO->EXTI_CFG[0] |= (0x01U << 12U); + break; + case 4: + AFIO->EXTI_CFG[1] &= ~(0x03U); + AFIO->EXTI_CFG[1] |= (0x01U); + break; + case 5: + AFIO->EXTI_CFG[1] &= ~(0x03U << 4U); + AFIO->EXTI_CFG[1] |= (0x02U << 4U); + break; + case 6: + AFIO->EXTI_CFG[1] &= ~(0x03U << 8U); + AFIO->EXTI_CFG[1] |= (0x01U << 8U); + break; + case 7: + AFIO->EXTI_CFG[1] &= ~(0x03U << 12U); + AFIO->EXTI_CFG[1] |= (0x01U << 12U); + break; + case 8: + AFIO->EXTI_CFG[1] &= ~(0x03U << 12U); + AFIO->EXTI_CFG[1] |= (0x02U << 12U); + break; + case 9: + AFIO->EXTI_CFG[1] &= ~(0x03U); + break; + case 10: + AFIO->EXTI_CFG[1] &= ~(0x03U << 4U); + break; + case 11: + AFIO->EXTI_CFG[1] &= ~(0x03U << 4U); + AFIO->EXTI_CFG[1] |= (0x01U << 4U); + break; + case 12: + AFIO->EXTI_CFG[1] &= ~(0x03U << 8U); + break; + case 13: + AFIO->EXTI_CFG[1] &= ~(0x03U << 12U); + break; + default: + break; + } + } +} + +/** + * @brief Changes the mapping of the specified pin. + * @param PortSource selects the GPIO port to be used. + * @param PinSource specifies the pin for the remaping. + * This parameter can be GPIO_PinSourcex where x can be (0..13). + * @param AlternateFunction specifies the alternate function for the remaping. + */ +void GPIO_ConfigPinRemap(uint8_t PortSource, uint8_t PinSource, uint32_t AlternateFunction) +{ + uint32_t tmp = 0x00, tmpregister = 0x00; + GPIO_Module *GPIOx; + /* Check the parameters */ + assert_param(IS_GPIO_REMAP_PORT_SOURCE(PortSource)); + assert_param(IS_GPIO_PIN_SOURCE(PinSource)); + assert_param(IS_GPIO_AF(AlternateFunction)); + /*Get Peripheral point*/ + GPIOx = GPIO_GET_PERIPH(PortSource); + /**/ + if(PinSource & (uint8_t)0x08) + { + tmp = (uint32_t)(PinSource & (uint8_t)0x07); + /*Read GPIO_AFH register*/ + tmpregister = GPIOx->AFH; + /*Reset corresponding bits*/ + tmpregister &=~((uint32_t)0x0F <<(tmp*4U)); + /*Set corresponding bits*/ + tmpregister |= (AlternateFunction <<(tmp*4U)); + /*Write to the GPIO_AFH register*/ + GPIOx->AFH = tmpregister; + } + else + { + tmp = (uint32_t)(PinSource & (uint8_t)0x07); + /*Read GPIO_AFL register*/ + tmpregister = GPIOx->AFL; + /*Reset corresponding bits*/ + tmpregister &=~((uint32_t)0x0F <<(tmp*4U)); + /*Set corresponding bits*/ + tmpregister |= (AlternateFunction <<(tmp*4U)); + /*Write to the GPIO_AFL register*/ + GPIOx->AFL = tmpregister; + } +} + + +/** + * @brief Selects the alternate function SPIx NSS mode. + * @param AFIO_SPIx_NSS choose which SPI configuration. + * This parameter can be AFIO_SPI1_NSS and AFIO_SPI2_NSS. + * @param SpiNssMode specifies the SPI_NSS mode to be configured. + * This parameter can be AFIO_SPI_NSS_High_IMPEDANCE and AFIO_SPI_NSS_High_LEVEL. + */ +void AFIO_ConfigSPINSSMode(uint32_t AFIO_SPIx_NSS, uint32_t SpiNssMode) +{ + uint32_t tmpregister = 0x00U; + + /* Check the parameters */ + assert_param(IS_AFIO_SPIX(AFIO_SPIx_NSS)); + assert_param(IS_AFIO_SPI_NSS(SpiNssMode)); + + tmpregister = AFIO->CFG; + if(SpiNssMode != AFIO_SPI_NSS_High_IMPEDANCE) + { + tmpregister |= AFIO_SPIx_NSS; + } + else + { + tmpregister &= ~AFIO_SPIx_NSS; + } + AFIO->CFG = tmpregister; +} + + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_i2c.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_i2c.c new file mode 100644 index 0000000..c63e1df --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_i2c.c @@ -0,0 +1,1321 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_i2c.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_i2c.h" +#include "n32wb03x_rcc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup I2C + * @brief I2C driver modules + * @{ + */ + +/** @addtogroup I2C_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup I2C_Private_Defines + * @{ + */ + +/* I2C SPE mask */ +#define CTRL1_PACKET_ERR_SET ((uint16_t)0x0001) +#define CTRL1_PACKET_ERR_RESET ((uint16_t)0xFFFE) + +/* I2C START mask */ +#define CTRL1_START_SET ((uint16_t)0x0100) +#define CTRL1_START_RESET ((uint16_t)0xFEFF) + +/* I2C STOP mask */ +#define CTRL1_STOP_SET ((uint16_t)0x0200) +#define CTRL1_STOP_RESET ((uint16_t)0xFDFF) + +/* I2C ACK mask */ +#define CTRL1_ACK_SET ((uint16_t)0x0400) +#define CTRL1_ACK_RESET ((uint16_t)0xFBFF) + +/* I2C ENGC mask */ +#define CTRL1_GCEN_SET ((uint16_t)0x0040) +#define CTRL1_GCEN_RESET ((uint16_t)0xFFBF) + +/* I2C SWRST mask */ +#define CTRL1_SWRESET_SET ((uint16_t)0x8000) +#define CTRL1_SWRESET_RESET ((uint16_t)0x7FFF) + +/* I2C PEC mask */ +#define CTRL1_PEC_SET ((uint16_t)0x1000) +#define CTRL1_PEC_RESET ((uint16_t)0xEFFF) + +/* I2C ENPEC mask */ +#define CTRL1_PECEN_SET ((uint16_t)0x0020) +#define CTRL1_PECEN_RESET ((uint16_t)0xFFDF) + +/* I2C ENARP mask */ +#define CTRL1_ARPEN_SET ((uint16_t)0x0010) +#define CTRL1_ARPEN_RESET ((uint16_t)0xFFEF) + +/* I2C NOSTRETCH mask */ +#define CTRL1_NOEXTEND_SET ((uint16_t)0x0080) +#define CTRL1_NOEXTEND_RESET ((uint16_t)0xFF7F) + +/* I2C registers Masks */ +#define CTRL1_CLR_MASK ((uint16_t)0xFBF5) + +/* I2C DMAEN mask */ +#define CTRL2_DMAEN_SET ((uint16_t)0x0800) +#define CTRL2_DMAEN_RESET ((uint16_t)0xF7FF) + +/* I2C LAST mask */ +#define CTRL2_DMALAST_SET ((uint16_t)0x1000) +#define CTRL2_DMALAST_RESET ((uint16_t)0xEFFF) + +/* I2C FREQ mask */ +#define CTRL2_CLKFREQ_RESET ((uint16_t)0xFFC0) + +/* I2C ADD0 mask */ +#define OADDR1_ADDR0_SET ((uint16_t)0x0001) +#define OADDR1_ADDR0_RESET ((uint16_t)0xFFFE) + +/* I2C ENDUAL mask */ +#define OADDR2_DUALEN_SET ((uint16_t)0x0001) +#define OADDR2_DUALEN_RESET ((uint16_t)0xFFFE) + +/* I2C ADD2 mask */ +#define OADDR2_ADDR2_RESET ((uint16_t)0xFF01) + +/* I2C F/S mask */ +#define CLKCTRL_FSMODE_SET ((uint16_t)0x8000) + +/* I2C CHCFG mask */ +#define CLKCTRL_CLKCTRL_SET ((uint16_t)0x0FFF) + +/* I2C FLAG mask */ +#define FLAG_MASK ((uint32_t)0x00FFFFFF) + +/* I2C Interrupt Enable mask */ +#define INTEN_MASK ((uint32_t)0x07000000) + +/** + * @} + */ + +/** @addtogroup I2C_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup I2C_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup I2C_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup I2C_Private_Functions + * @{ + */ + +/** + * @brief Deinitializes the I2Cx peripheral registers to their default reset values. + * @param I2Cx where x can be 1 to select the I2C peripheral. + */ +void I2C_DeInit(I2C_Module* I2Cx) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + + if (I2Cx == I2C1) + { + /* Enable I2C1 reset state */ + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_I2C1, ENABLE); + /* Release I2C1 from reset state */ + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_I2C1, DISABLE); + } + else + { + } +} + +/** + * @brief Initializes the I2Cx peripheral according to the specified + * parameters in the I2C_InitStruct. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_InitStruct pointer to a I2C_InitType structure that + * contains the configuration information for the specified I2C peripheral. + */ +void I2C_Init(I2C_Module* I2Cx, I2C_InitType* I2C_InitStruct) +{ + uint16_t tmpregister = 0, freqrange = 0; + uint16_t result = 0x04; + uint32_t pclk1 = 8000000; + RCC_ClocksType rcc_clocks; + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_CLK_SPEED(I2C_InitStruct->ClkSpeed)); + assert_param(IS_I2C_BUS_MODE(I2C_InitStruct->BusMode)); + assert_param(IS_I2C_FM_DUTY_CYCLE(I2C_InitStruct->FmDutyCycle)); + assert_param(IS_I2C_OWN_ADDR1(I2C_InitStruct->OwnAddr1)); + assert_param(IS_I2C_ACK_STATE(I2C_InitStruct->AckEnable)); + assert_param(IS_I2C_ADDR_MODE(I2C_InitStruct->AddrMode)); + + /*---------------------------- I2Cx CTRL2 Configuration ------------------------*/ + /* Get the I2Cx CTRL2 value */ + tmpregister = I2Cx->CTRL2; + /* Clear frequency FREQ[5:0] bits */ + tmpregister &= CTRL2_CLKFREQ_RESET; + /* Get pclk1 frequency value */ + RCC_GetClocksFreqValue(&rcc_clocks); + pclk1 = rcc_clocks.Pclk1Freq; + /* Set frequency bits depending on pclk1 value */ + freqrange = (uint16_t)(pclk1 / 1000000); + tmpregister |= freqrange; + /* Write to I2Cx CTRL2 */ + I2Cx->CTRL2 = tmpregister; + + /*---------------------------- I2Cx CLKCTRL Configuration ------------------------*/ + /* Disable the selected I2C peripheral to configure TMRISE */ + I2Cx->CTRL1 &= CTRL1_PACKET_ERR_RESET; + /* Reset tmpregister value */ + /* Clear DUTY and CLKCTRL[11:0] bits */ + tmpregister = 0; + + /* DUTY as I2C_FMDUTYCYCLE_1 */ + if(I2C_InitStruct->FmDutyCycle == I2C_FMDUTYCYCLE_1) + { + /* duty calculate: Tlow/Thigh = 1 */ + result = (uint16_t)(pclk1 / (I2C_InitStruct->ClkSpeed << 1)); + /* Set DUTY bit */ + result |= I2C_FMDUTYCYCLE_1; + /* Test if CLKCTRL value is under 0x4*/ + if (result < 0x04) + { + /* Set minimum allowed value */ + result = 0x04; + } + } + /* DUTY as I2C_FMDUTYCYCLE_2 */ + else if (I2C_InitStruct->FmDutyCycle == I2C_FMDUTYCYCLE_2) + { + /* duty calculate: Tlow/Thigh = 2 */ + result = (uint16_t)(pclk1 / (I2C_InitStruct->ClkSpeed * 3)); + /* Set DUTY bit */ + result |= I2C_FMDUTYCYCLE_2; + /* Test if CLKCTRL value is under 0x1*/ + if ((result & CLKCTRL_CLKCTRL_SET) == 0) + { + /* Set minimum allowed value */ + result |= (uint16_t)0x0001; + } + } + /* DUTY as I2C_FMDUTYCYCLE_16_9 */ + else + { + /* duty calculate: Tlow/Thigh = 16/9 */ + result = (uint16_t)(pclk1 / (I2C_InitStruct->ClkSpeed * 25)); + /* Set DUTY bit */ + result |= I2C_FMDUTYCYCLE_16_9; + /* Test if CLKCTRL value is under 0x1*/ + if ((result & CLKCTRL_CLKCTRL_SET) == 0) + { + /* Set minimum allowed value */ + result |= (uint16_t)0x0001; + } + } + /* Set speed value*/ + tmpregister |= result; + /* Set Maximum Rise Time for standard mode*/ + if (I2C_InitStruct->ClkSpeed <= 100000) + { + I2Cx->TMRISE = freqrange + 1; + } + else if((I2C_InitStruct->ClkSpeed > 100000) && (I2C_InitStruct->ClkSpeed <= 1000000)) + { + I2Cx->TMRISE = (uint16_t)(((freqrange * (uint16_t)300) / (uint16_t)1000) + (uint16_t)1); + } + /* Write to I2Cx CLKCTRL */ + I2Cx->CLKCTRL = tmpregister; + /* Enable the selected I2C peripheral */ + I2Cx->CTRL1 |= CTRL1_PACKET_ERR_SET; + + /*---------------------------- I2Cx CTRL1 Configuration ------------------------*/ + /* Get the I2Cx CTRL1 value */ + tmpregister = I2Cx->CTRL1; + /* Clear ACK, SMBTYPE and SMBUS bits */ + tmpregister &= CTRL1_CLR_MASK; + /* Configure I2Cx: mode and acknowledgement */ + /* Set SMBTYPE and SMBUS bits according to BusMode value */ + /* Set ACK bit according to AckEnable value */ + tmpregister |= (uint16_t)((uint32_t)I2C_InitStruct->BusMode | I2C_InitStruct->AckEnable); + /* Write to I2Cx CTRL1 */ + I2Cx->CTRL1 = tmpregister; + + /*---------------------------- I2Cx OADDR1 Configuration -----------------------*/ + /* Set I2Cx Own Address1 and acknowledged address */ + I2Cx->OADDR1 = (I2C_InitStruct->AddrMode | I2C_InitStruct->OwnAddr1); +} + +/** + * @brief Fills each I2C_InitStruct member with its default value. + * @param I2C_InitStruct pointer to an I2C_InitType structure which will be initialized. + */ +void I2C_InitStruct(I2C_InitType* I2C_InitStruct) +{ + /*---------------- Reset I2C init structure parameters values ----------------*/ + /* initialize the ClkSpeed member */ + I2C_InitStruct->ClkSpeed = 5000; + /* Initialize the BusMode member */ + I2C_InitStruct->BusMode = I2C_BUSMODE_I2C; + /* Initialize the FmDutyCycle member */ + I2C_InitStruct->FmDutyCycle = I2C_FMDUTYCYCLE_1; + /* Initialize the OwnAddr1 member */ + I2C_InitStruct->OwnAddr1 = 0; + /* Initialize the AckEnable member */ + I2C_InitStruct->AckEnable = I2C_ACKDIS; + /* Initialize the AddrMode member */ + I2C_InitStruct->AddrMode = I2C_ADDR_MODE_7BIT; +} + +/** + * @brief Enables or disables the specified I2C peripheral. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2Cx peripheral. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_Enable(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected I2C peripheral */ + I2Cx->CTRL1 |= CTRL1_PACKET_ERR_SET; + } + else + { + /* Disable the selected I2C peripheral */ + I2Cx->CTRL1 &= CTRL1_PACKET_ERR_RESET; + } +} + +/** + * @brief Enables or disables the specified I2C DMA requests. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2C DMA transfer. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_EnableDMA(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected I2C DMA requests */ + I2Cx->CTRL2 |= CTRL2_DMAEN_SET; + } + else + { + /* Disable the selected I2C DMA requests */ + I2Cx->CTRL2 &= CTRL2_DMAEN_RESET; + } +} + +/** + * @brief Specifies if the next DMA transfer will be the last one. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2C DMA last transfer. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_EnableDmaLastSend(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Next DMA transfer is the last transfer */ + I2Cx->CTRL2 |= CTRL2_DMALAST_SET; + } + else + { + /* Next DMA transfer is not the last transfer */ + I2Cx->CTRL2 &= CTRL2_DMALAST_RESET; + } +} + +/** + * @brief Generates I2Cx communication START condition. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2C START condition generation. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_GenerateStart(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Generate a START condition */ + I2Cx->CTRL1 |= CTRL1_START_SET; + } + else + { + /* Disable the START condition generation */ + I2Cx->CTRL1 &= CTRL1_START_RESET; + } +} + +/** + * @brief Generates I2Cx communication STOP condition. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2C STOP condition generation. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_GenerateStop(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Generate a STOP condition */ + I2Cx->CTRL1 |= CTRL1_STOP_SET; + } + else + { + /* Disable the STOP condition generation */ + I2Cx->CTRL1 &= CTRL1_STOP_RESET; + } +} + +/** + * @brief Enables or disables the specified I2C acknowledge feature. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2C Acknowledgement. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_ConfigAck(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the acknowledgement */ + I2Cx->CTRL1 |= CTRL1_ACK_SET; + } + else + { + /* Disable the acknowledgement */ + I2Cx->CTRL1 &= CTRL1_ACK_RESET; + } +} + +/** + * @brief Configures the specified I2C own address2. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Address specifies the 7bit I2C own address2. + */ +void I2C_ConfigOwnAddr2(I2C_Module* I2Cx, uint8_t Address) +{ + uint16_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + + /* Get the old register value */ + tmpregister = I2Cx->OADDR2; + + /* Reset I2Cx Own address2 bit [7:1] */ + tmpregister &= OADDR2_ADDR2_RESET; + + /* Set I2Cx Own address2 */ + tmpregister |= (uint16_t)((uint16_t)Address & (uint16_t)0x00FE); + + /* Store the new register value */ + I2Cx->OADDR2 = tmpregister; +} + +/** + * @brief Enables or disables the specified I2C dual addressing mode. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2C dual addressing mode. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_EnableDualAddr(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable dual addressing mode */ + I2Cx->OADDR2 |= OADDR2_DUALEN_SET; + } + else + { + /* Disable dual addressing mode */ + I2Cx->OADDR2 &= OADDR2_DUALEN_RESET; + } +} + +/** + * @brief Enables or disables the specified I2C general call feature. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2C General call. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_EnableGeneralCall(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable generall call */ + I2Cx->CTRL1 |= CTRL1_GCEN_SET; + } + else + { + /* Disable generall call */ + I2Cx->CTRL1 &= CTRL1_GCEN_RESET; + } +} + +/** + * @brief Enables or disables the specified I2C interrupts. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_IT specifies the I2C interrupts sources to be enabled or disabled. + * This parameter can be any combination of the following values: + * @arg I2C_INT_BUF Buffer interrupt mask + * @arg I2C_INT_EVENT Event interrupt mask + * @arg I2C_INT_ERR Error interrupt mask + * @param Cmd new state of the specified I2C interrupts. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_ConfigInt(I2C_Module* I2Cx, uint16_t I2C_IT, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + assert_param(IS_I2C_CFG_INT(I2C_IT)); + + if (Cmd != DISABLE) + { + /* Enable the selected I2C interrupts */ + I2Cx->CTRL2 |= I2C_IT; + } + else + { + /* Disable the selected I2C interrupts */ + I2Cx->CTRL2 &= (uint16_t)~I2C_IT; + } +} + +/** + * @brief Sends a data byte through the I2Cx peripheral. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Data Byte to be transmitted.. + */ +void I2C_SendData(I2C_Module* I2Cx, uint8_t Data) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + /* Write in the DAT register the data to be sent */ + I2Cx->DAT = Data; +} + +/** + * @brief Returns the most recent received data by the I2Cx peripheral. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @return The value of the received data. + */ +uint8_t I2C_RecvData(I2C_Module* I2Cx) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + /* Return the data in the DAT register */ + return (uint8_t)I2Cx->DAT; +} + +/** + * @brief Transmits the address byte to select the slave device. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Address specifies the slave address which will be transmitted + * @param I2C_Direction specifies whether the I2C device will be a + * Transmitter or a Receiver. This parameter can be one of the following values + * @arg I2C_DIRECTION_SEND Transmitter mode + * @arg I2C_DIRECTION_RECV Receiver mode + */ +void I2C_SendAddr7bit(I2C_Module* I2Cx, uint8_t Address, uint8_t I2C_Direction) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_DIRECTION(I2C_Direction)); + /* Test on the direction to set/reset the read/write bit */ + if (I2C_Direction != I2C_DIRECTION_SEND) + { + /* Set the address bit0 for read */ + Address |= OADDR1_ADDR0_SET; + } + else + { + /* Reset the address bit0 for write */ + Address &= OADDR1_ADDR0_RESET; + } + /* Send the address */ + I2Cx->DAT = Address; +} + +/** + * @brief Reads the specified I2C register and returns its value. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_Register specifies the register to read. + * This parameter can be one of the following values: + * @arg I2C_REG_CTRL1 CTRL1 register. + * @arg I2C_REG_CTRL2 CTRL2 register. + * @arg I2C_REG_OADDR1 OADDR1 register. + * @arg I2C_REG_OADDR2 OADDR2 register. + * @arg I2C_REG_DAT DAT register. + * @arg I2C_REG_STS1 STS1 register. + * @arg I2C_REG_STS2 STS2 register. + * @arg I2C_REG_CLKCTRL CHCFG register. + * @arg I2C_REG_TMRISE TMRISE register. + * @return The value of the read register. + */ +uint16_t I2C_GetRegister(I2C_Module* I2Cx, uint8_t I2C_Register) +{ + __IO uint32_t tmp = 0; + + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_REG(I2C_Register)); + + tmp = (uint32_t)I2Cx; + tmp += I2C_Register; + + /* Return the selected register value */ + return (*(__IO uint16_t*)tmp); +} + +/** + * @brief Enables or disables the specified I2C software reset. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2C software reset. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_EnableSoftwareReset(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Peripheral under reset */ + I2Cx->CTRL1 |= CTRL1_SWRESET_SET; + } + else + { + /* Peripheral not under reset */ + I2Cx->CTRL1 &= CTRL1_SWRESET_RESET; + } +} + +/** + * @brief Selects the specified I2C NACK position in master receiver mode. + * This function is useful in I2C Master Receiver mode when the number + * of data to be received is equal to 2. In this case, this function + * should be called (with parameter I2C_NACK_POS_NEXT) before data + * reception starts,as described in the 2-byte reception procedure + * recommended in Reference Manual in Section: Master receiver. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_NACKPosition specifies the NACK position. + * This parameter can be one of the following values: + * @arg I2C_NACK_POS_NEXT indicates that the next byte will be the last + * received byte. + * @arg I2C_NACK_POS_CURRENT indicates that current byte is the last + * received byte. + * + * @note This function configures the same bit (POS) as I2C_ConfigPecLocation() + * but is intended to be used in I2C mode while I2C_ConfigPecLocation() + * is intended to used in SMBUS mode. + * + */ +void I2C_ConfigNackLocation(I2C_Module* I2Cx, uint16_t I2C_NACKPosition) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_NACK_POS(I2C_NACKPosition)); + + /* Check the input parameter */ + if (I2C_NACKPosition == I2C_NACK_POS_NEXT) + { + /* Next byte in shift register is the last received byte */ + I2Cx->CTRL1 |= I2C_NACK_POS_NEXT; + } + else + { + /* Current byte in shift register is the last received byte */ + I2Cx->CTRL1 &= I2C_NACK_POS_CURRENT; + } +} + +/** + * @brief Drives the SMBusAlert pin high or low for the specified I2C. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_SMBusAlert specifies SMBAlert pin level. + * This parameter can be one of the following values: + * @arg I2C_SMBALERT_LOW SMBAlert pin driven low + * @arg I2C_SMBALERT_HIGH SMBAlert pin driven high + */ +void I2C_ConfigSmbusAlert(I2C_Module* I2Cx, uint16_t I2C_SMBusAlert) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_SMB_ALERT(I2C_SMBusAlert)); + if (I2C_SMBusAlert == I2C_SMBALERT_LOW) + { + /* Drive the SMBusAlert pin Low */ + I2Cx->CTRL1 |= I2C_SMBALERT_LOW; + } + else + { + /* Drive the SMBusAlert pin High */ + I2Cx->CTRL1 &= I2C_SMBALERT_HIGH; + } +} + +/** + * @brief Enables or disables the specified I2C PEC transfer. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2C PEC transmission. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_SendPEC(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected I2C PEC transmission */ + I2Cx->CTRL1 |= CTRL1_PEC_SET; + } + else + { + /* Disable the selected I2C PEC transmission */ + I2Cx->CTRL1 &= CTRL1_PEC_RESET; + } +} + +/** + * @brief Selects the specified I2C PEC position. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_PECPosition specifies the PEC position. + * This parameter can be one of the following values: + * @arg I2C_PEC_POS_NEXT indicates that the next byte is PEC + * @arg I2C_PEC_POS_CURRENT indicates that current byte is PEC + * + * @note This function configures the same bit (POS) as I2C_ConfigNackLocation() + * but is intended to be used in SMBUS mode while I2C_ConfigNackLocation() + * is intended to used in I2C mode. + * + */ +void I2C_ConfigPecLocation(I2C_Module* I2Cx, uint16_t I2C_PECPosition) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_PEC_POS(I2C_PECPosition)); + if (I2C_PECPosition == I2C_PEC_POS_NEXT) + { + /* Next byte in shift register is PEC */ + I2Cx->CTRL1 |= I2C_PEC_POS_NEXT; + } + else + { + /* Current byte in shift register is PEC */ + I2Cx->CTRL1 &= I2C_PEC_POS_CURRENT; + } +} + +/** + * @brief Enables or disables the PEC value calculation of the transferred bytes. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2Cx PEC value calculation. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_ComputePec(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected I2C PEC calculation */ + I2Cx->CTRL1 |= CTRL1_PECEN_SET; + } + else + { + /* Disable the selected I2C PEC calculation */ + I2Cx->CTRL1 &= CTRL1_PECEN_RESET; + } +} + +/** + * @brief Returns the PEC value for the specified I2C. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @return The PEC value. + */ +uint8_t I2C_GetPec(I2C_Module* I2Cx) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + /* Return the selected I2C PEC value */ + return ((I2Cx->STS2) >> 8); +} + +/** + * @brief Enables or disables the specified I2C ARP. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2Cx ARP. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_EnableArp(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected I2C ARP */ + I2Cx->CTRL1 |= CTRL1_ARPEN_SET; + } + else + { + /* Disable the selected I2C ARP */ + I2Cx->CTRL1 &= CTRL1_ARPEN_RESET; + } +} + +/** + * @brief Enables or disables the specified I2C Clock stretching. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param Cmd new state of the I2Cx Clock stretching. + * This parameter can be: ENABLE or DISABLE. + */ +void I2C_EnableExtendClk(I2C_Module* I2Cx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd == DISABLE) + { + /* Enable the selected I2C Clock stretching */ + I2Cx->CTRL1 |= CTRL1_NOEXTEND_SET; + } + else + { + /* Disable the selected I2C Clock stretching */ + I2Cx->CTRL1 &= CTRL1_NOEXTEND_RESET; + } +} + +/** + * @brief Selects the specified I2C fast mode duty cycle. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param FmDutyCycle specifies the fast mode duty cycle. + * This parameter can be one of the following values: + * @arg I2C_FMDUTYCYCLE_2 I2C fast mode Tlow/Thigh = 2 + * @arg I2C_FMDUTYCYCLE_16_9 I2C fast mode Tlow/Thigh = 16/9 + */ +void I2C_ConfigFastModeDutyCycle(I2C_Module* I2Cx, uint16_t FmDutyCycle) +{ + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_FM_DUTY_CYCLE(FmDutyCycle)); + if (FmDutyCycle != I2C_FMDUTYCYCLE_16_9) + { + /* I2C fast mode Tlow/Thigh=2 */ + I2Cx->CLKCTRL &= I2C_FMDUTYCYCLE_1; + } + else + { + /* I2C fast mode Tlow/Thigh=16/9 */ + I2Cx->CLKCTRL |= I2C_FMDUTYCYCLE_16_9; + } +} + +/** + * @brief + **************************************************************************************** + * + * I2C State Monitoring Functions + * + **************************************************************************************** + * This I2C driver provides three different ways for I2C state monitoring + * depending on the application requirements and constraints: + * + * + * 1) Basic state monitoring: + * Using I2C_CheckEvent() function: + * It compares the status registers (STS1 and STS2) content to a given event + * (can be the combination of one or more flags). + * It returns SUCCESS if the current status includes the given flags + * and returns ERROR if one or more flags are missing in the current status. + * - When to use: + * - This function is suitable for most applications as well as for startup + * activity since the events are fully described in the product reference manual + * (RM0008). + * - It is also suitable for users who need to define their own events. + * - Limitations: + * - If an error occurs (ie. error flags are set besides to the monitored flags), + * the I2C_CheckEvent() function may return SUCCESS despite the communication + * hold or corrupted real state. + * In this case, it is advised to use error interrupts to monitor the error + * events and handle them in the interrupt IRQ handler. + * + * @note + * For error management, it is advised to use the following functions: + * - I2C_ConfigInt() to configure and enable the error interrupts (I2C_INT_ERR). + * - I2Cx_ER_IRQHandler() which is called when the error interrupt occurs. + * Where x is the peripheral instance (I2C1, I2C2 ...) + * - I2C_GetFlag() or I2C_GetIntStatus() to be called into I2Cx_ER_IRQHandler() + * in order to determine which error occured. + * - I2C_ClrFlag() or I2C_ClrIntPendingBit() and/or I2C_EnableSoftwareReset() + * and/or I2C_GenerateStop() in order to clear the error flag and source, + * and return to correct communication status. + * + * + * 2) Advanced state monitoring: + * Using the function I2C_GetLastEvent() which returns the image of both status + * registers in a single word (uint32_t) (Status Register 2 value is shifted left + * by 16 bits and concatenated to Status Register 1). + * - When to use: + * - This function is suitable for the same applications above but it allows to + * overcome the mentioned limitation of I2C_GetFlag() function. + * The returned value could be compared to events already defined in the + * library (n32wb03x_i2c.h) or to custom values defined by user. + * - This function is suitable when multiple flags are monitored at the same time. + * - At the opposite of I2C_CheckEvent() function, this function allows user to + * choose when an event is accepted (when all events flags are set and no + * other flags are set or just when the needed flags are set like + * I2C_CheckEvent() function). + * - Limitations: + * - User may need to define his own events. + * - Same remark concerning the error management is applicable for this + * function if user decides to check only regular communication flags (and + * ignores error flags). + * + * + * 3) Flag-based state monitoring: + * Using the function I2C_GetFlag() which simply returns the status of + * one single flag (ie. I2C_FLAG_RXDATNE ...). + * - When to use: + * - This function could be used for specific applications or in debug phase. + * - It is suitable when only one flag checking is needed (most I2C events + * are monitored through multiple flags). + * - Limitations: + * - When calling this function, the Status register is accessed. Some flags are + * cleared when the status register is accessed. So checking the status + * of one Flag, may clear other ones. + * - Function may need to be called twice or more in order to monitor one + * single event. + * + * For detailed description of Events, please refer to section I2C_Events in + * n32wb03x_i2c.h file. + * + */ + +/** + * @brief Checks whether the last I2Cx Event is equal to the one passed + * as parameter. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_EVENT specifies the event to be checked. + * This parameter can be one of the following values: + * @arg I2C_EVT_SLAVE_SEND_ADDR_MATCHED EV1 + * @arg I2C_EVT_SLAVE_RECV_ADDR_MATCHED EV1 + * @arg I2C_EVT_SLAVE_SEND_ADDR2_MATCHED EV1 + * @arg I2C_EVT_SLAVE_RECV_ADDR2_MATCHED EV1 + * @arg I2C_EVT_SLAVE_GCALLADDR_MATCHED EV1 + * @arg I2C_EVT_SLAVE_DATA_RECVD EV2 + * @arg I2C_EVT_SLAVE_DATA_RECVD_BSF EV2 + * @arg (I2C_EVT_SLAVE_DATA_RECVD | I2C_FLAG_DUALFLAG) EV2 + * @arg (I2C_EVT_SLAVE_DATA_RECVD | I2C_FLAG_GCALLADDR) EV2 + * @arg I2C_EVT_SLAVE_DATA_SENDED EV3 + * @arg (I2C_EVT_SLAVE_DATA_SENDED | I2C_FLAG_DUALFLAG) EV3 + * @arg (I2C_EVT_SLAVE_DATA_SENDED | I2C_FLAG_GCALLADDR) EV3 + * @arg I2C_EVT_SLAVE_ACK_MISS EV3_2 + * @arg I2C_EVT_SLAVE_STOP_RECVD EV4 + * @arg I2C_EVT_MASTER_MODE_FLAG EV5 + * @arg I2C_EVT_MASTER_TXMODE_FLAG EV6 + * @arg I2C_EVT_MASTER_RXMODE_FLAG EV6 + * @arg I2C_EVT_MASTER_DATA_RECVD_FLAG EV7 + * @arg I2C_EVT_MASTER_DATA_RECVD_BSF_FLAG EV7 + * @arg I2C_EVT_MASTER_DATA_SENDING EV8 + * @arg I2C_EVT_MASTER_DATA_SENDED EV8_2 + * @arg I2C_EVT_MASTER_MODE_ADDRESS10_FLAG EV9 + * + * @note: For detailed description of Events, please refer to section + * I2C_Events in n32wb03x_i2c.h file. + * + * @return An ErrorStatus enumeration value: + * - SUCCESS: Last event is equal to the I2C_EVENT + * - ERROR: Last event is different from the I2C_EVENT + */ +ErrorStatus I2C_CheckEvent(I2C_Module* I2Cx, uint32_t I2C_EVENT) +{ + uint32_t lastevent = 0; + uint32_t flag1 = 0, flag2 = 0; + ErrorStatus status = ERROR; + + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_EVT(I2C_EVENT)); + + /* Read the I2Cx status register */ + flag1 = I2Cx->STS1; + flag2 = I2Cx->STS2; + flag2 = flag2 << 16; + + /* Get the last event value from I2C status register */ + lastevent = (flag1 | flag2) & FLAG_MASK; + + /* Check whether the last event contains the I2C_EVENT */ + if ((lastevent & I2C_EVENT) == I2C_EVENT) + { + /* SUCCESS: last event is equal to I2C_EVENT */ + status = SUCCESS; + } + else + { + /* ERROR: last event is different from I2C_EVENT */ + status = ERROR; + } + /* Return status */ + return status; +} + +/** + * @brief Returns the last I2Cx Event. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * + * @note: For detailed description of Events, please refer to section + * I2C_Events in n32wb03x_i2c.h file. + * + * @return The last event + */ +uint32_t I2C_GetLastEvent(I2C_Module* I2Cx) +{ + uint32_t lastevent = 0; + uint32_t flag1 = 0, flag2 = 0; + + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + + /* Read the I2Cx status register */ + flag1 = I2Cx->STS1; + flag2 = I2Cx->STS2; + flag2 = flag2 << 16; + + /* Get the last event value from I2C status register */ + lastevent = (flag1 | flag2) & FLAG_MASK; + + /* Return status */ + return lastevent; +} + +/** + * @brief Checks whether the specified I2C flag is set or not. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_FLAG specifies the flag to check. + * This parameter can be one of the following values: + * @arg I2C_FLAG_DUALFLAG Dual flag (Slave mode) + * @arg I2C_FLAG_SMBHADDR SMBus host header (Slave mode) + * @arg I2C_FLAG_SMBDADDR SMBus default header (Slave mode) + * @arg I2C_FLAG_GCALLADDR General call header flag (Slave mode) + * @arg I2C_FLAG_TRF Transmitter/Receiver flag + * @arg I2C_FLAG_BUSY Bus busy flag + * @arg I2C_FLAG_MSMODE Master/Slave flag + * @arg I2C_FLAG_SMBALERT SMBus Alert flag + * @arg I2C_FLAG_TIMOUT Timeout or Tlow error flag + * @arg I2C_FLAG_PECERR PEC error in reception flag + * @arg I2C_FLAG_OVERRUN Overrun/Underrun flag (Slave mode) + * @arg I2C_FLAG_ACKFAIL Acknowledge failure flag + * @arg I2C_FLAG_ARLOST Arbitration lost flag (Master mode) + * @arg I2C_FLAG_BUSERR Bus error flag + * @arg I2C_FLAG_TXDATE Data register empty flag (Transmitter) + * @arg I2C_FLAG_RXDATNE Data register not empty (Receiver) flag + * @arg I2C_FLAG_STOPF Stop detection flag (Slave mode) + * @arg I2C_FLAG_ADDR10F 10-bit header sent flag (Master mode) + * @arg I2C_FLAG_BYTEF Byte transfer finished flag + * @arg I2C_FLAG_ADDRF Address sent flag (Master mode) "ADSL" + * Address matched flag (Slave mode)"ENDA" + * @arg I2C_FLAG_STARTBF Start bit flag (Master mode) + * @return The new state of I2C_FLAG (SET or RESET). + */ +FlagStatus I2C_GetFlag(I2C_Module* I2Cx, uint32_t I2C_FLAG) +{ + FlagStatus bitstatus = RESET; + __IO uint32_t i2creg = 0, i2cxbase = 0; + + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_GET_FLAG(I2C_FLAG)); + + /* Get the I2Cx peripheral base address */ + i2cxbase = (uint32_t)I2Cx; + + /* Read flag register index */ + i2creg = I2C_FLAG >> 28; + + /* Get bit[23:0] of the flag */ + I2C_FLAG &= FLAG_MASK; + + if (i2creg != 0) + { + /* Get the I2Cx STS1 register address */ + i2cxbase += 0x14; + } + else + { + /* Flag in I2Cx STS2 Register */ + I2C_FLAG = (uint32_t)(I2C_FLAG >> 16); + /* Get the I2Cx STS2 register address */ + i2cxbase += 0x18; + } + + if (((*(__IO uint32_t*)i2cxbase) & I2C_FLAG) != (uint32_t)RESET) + { + /* I2C_FLAG is set */ + bitstatus = SET; + } + else + { + /* I2C_FLAG is reset */ + bitstatus = RESET; + } + + /* Return the I2C_FLAG status */ + return bitstatus; +} + +/** + * @brief Clears the I2Cx's pending flags. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_FLAG specifies the flag to clear. + * This parameter can be any combination of the following values: + * @arg I2C_FLAG_SMBALERT SMBus Alert flag + * @arg I2C_FLAG_TIMOUT Timeout or Tlow error flag + * @arg I2C_FLAG_PECERR PEC error in reception flag + * @arg I2C_FLAG_OVERRUN Overrun/Underrun flag (Slave mode) + * @arg I2C_FLAG_ACKFAIL Acknowledge failure flag + * @arg I2C_FLAG_ARLOST Arbitration lost flag (Master mode) + * @arg I2C_FLAG_BUSERR Bus error flag + * + * @note + * - STOPF (STOP detection) is cleared by software sequence: a read operation + * to I2C_STS1 register (I2C_GetFlag()) followed by a write operation + * to I2C_CTRL1 register (I2C_Enable() to re-enable the I2C peripheral). + * - ADD10 (10-bit header sent) is cleared by software sequence: a read + * operation to I2C_STS1 (I2C_GetFlag()) followed by writing the + * second byte of the address in DAT register. + * - BTF (Byte Transfer Finished) is cleared by software sequence: a read + * operation to I2C_STS1 register (I2C_GetFlag()) followed by a + * read/write to I2C_DAT register (I2C_SendData()). + * - ADDR (Address sent) is cleared by software sequence: a read operation to + * I2C_STS1 register (I2C_GetFlag()) followed by a read operation to + * I2C_STS2 register ((void)(I2Cx->STS2)). + * - SB (Start Bit) is cleared software sequence: a read operation to I2C_STS1 + * register (I2C_GetFlag()) followed by a write operation to I2C_DAT + * register (I2C_SendData()). + */ +void I2C_ClrFlag(I2C_Module* I2Cx, uint32_t I2C_FLAG) +{ + uint32_t flagpos = 0; + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_CLR_FLAG(I2C_FLAG)); + /* Get the I2C flag position */ + flagpos = I2C_FLAG & FLAG_MASK; + /* Clear the selected I2C flag */ + I2Cx->STS1 = (uint16_t)~flagpos; +} + +/** + * @brief Checks whether the specified I2C interrupt has occurred or not. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_IT specifies the interrupt source to check. + * This parameter can be one of the following values: + * @arg I2C_INT_SMBALERT SMBus Alert flag + * @arg I2C_INT_TIMOUT Timeout or Tlow error flag + * @arg I2C_INT_PECERR PEC error in reception flag + * @arg I2C_INT_OVERRUN Overrun/Underrun flag (Slave mode) + * @arg I2C_INT_ACKFAIL Acknowledge failure flag + * @arg I2C_INT_ARLOST Arbitration lost flag (Master mode) + * @arg I2C_INT_BUSERR Bus error flag + * @arg I2C_INT_TXDATE Data register empty flag (Transmitter) + * @arg I2C_INT_RXDATNE Data register not empty (Receiver) flag + * @arg I2C_INT_STOPF Stop detection flag (Slave mode) + * @arg I2C_INT_ADDR10F 10-bit header sent flag (Master mode) + * @arg I2C_INT_BYTEF Byte transfer finished flag + * @arg I2C_INT_ADDRF Address sent flag (Master mode) "ADSL" + * Address matched flag (Slave mode)"ENDAD" + * @arg I2C_INT_STARTBF Start bit flag (Master mode) + * @return The new state of I2C_IT (SET or RESET). + */ +INTStatus I2C_GetIntStatus(I2C_Module* I2Cx, uint32_t I2C_IT) +{ + INTStatus bitstatus = RESET; + uint32_t enablestatus = 0; + + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_GET_INT(I2C_IT)); + + /* Check if the interrupt source is enabled or not */ + enablestatus = (uint32_t)(((I2C_IT & INTEN_MASK) >> 16) & (I2Cx->CTRL2)); + + /* Get bit[23:0] of the flag */ + I2C_IT &= FLAG_MASK; + + /* Check the status of the specified I2C flag */ + if (((I2Cx->STS1 & I2C_IT) != (uint32_t)RESET) && enablestatus) + { + /* I2C_IT is set */ + bitstatus = SET; + } + else + { + /* I2C_IT is reset */ + bitstatus = RESET; + } + /* Return the I2C_IT status */ + return bitstatus; +} + +/** + * @brief Clears the I2Cx's interrupt pending bits. + * @param I2Cx where x can be 1 to select the I2C peripheral. + * @param I2C_IT specifies the interrupt pending bit to clear. + * This parameter can be any combination of the following values: + * @arg I2C_INT_SMBALERT SMBus Alert interrupt + * @arg I2C_INT_TIMOUT Timeout or Tlow error interrupt + * @arg I2C_INT_PECERR PEC error in reception interrupt + * @arg I2C_INT_OVERRUN Overrun/Underrun interrupt (Slave mode) + * @arg I2C_INT_ACKFAIL Acknowledge failure interrupt + * @arg I2C_INT_ARLOST Arbitration lost interrupt (Master mode) + * @arg I2C_INT_BUSERR Bus error interrupt + * + * @note + * - STOPF (STOP detection) is cleared by software sequence: a read operation + * to I2C_STS1 register (I2C_GetIntStatus()) followed by a write operation to + * I2C_CTRL1 register (I2C_Enable() to re-enable the I2C peripheral). + * - ADD10 (10-bit header sent) is cleared by software sequence: a read + * operation to I2C_STS1 (I2C_GetIntStatus()) followed by writing the second + * byte of the address in I2C_DAT register. + * - BTF (Byte Transfer Finished) is cleared by software sequence: a read + * operation to I2C_STS1 register (I2C_GetIntStatus()) followed by a + * read/write to I2C_DAT register (I2C_SendData()). + * - ADDR (Address sent) is cleared by software sequence: a read operation to + * I2C_STS1 register (I2C_GetIntStatus()) followed by a read operation to + * I2C_STS2 register ((void)(I2Cx->STS2)). + * - SB (Start Bit) is cleared by software sequence: a read operation to + * I2C_STS1 register (I2C_GetIntStatus()) followed by a write operation to + * I2C_DAT register (I2C_SendData()). + */ +void I2C_ClrIntPendingBit(I2C_Module* I2Cx, uint32_t I2C_IT) +{ + uint32_t flagpos = 0; + /* Check the parameters */ + assert_param(IS_I2C_PERIPH(I2Cx)); + assert_param(IS_I2C_CLR_INT(I2C_IT)); + /* Get the I2C flag position */ + flagpos = I2C_IT & FLAG_MASK; + /* Clear the selected I2C flag */ + I2Cx->STS1 = (uint16_t)~flagpos; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_iwdg.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_iwdg.c new file mode 100644 index 0000000..2e9edfb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_iwdg.c @@ -0,0 +1,214 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_iwdg.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_iwdg.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup IWDG + * @brief IWDG driver modules + * @{ + */ + +/** @addtogroup IWDG_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup IWDG_Private_Defines + * @{ + */ + +/* ---------------------- IWDG registers bit mask ----------------------------*/ + +/* KEY register bit mask */ +#define KEY_ReloadKey ((uint16_t)0xAAAA) +#define KEY_EnableKey ((uint16_t)0xCCCC) + +/** + * @} + */ + +/** @addtogroup IWDG_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup IWDG_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup IWDG_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup IWDG_Private_Functions + * @{ + */ + +/** + * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers. + * @param IWDG_WriteAccess new state of write access to IWDG_PR and IWDG_RLR registers. + * This parameter can be one of the following values: + * @arg IWDG_WRITE_ENABLE Enable write access to IWDG_PR and IWDG_RLR registers + * @arg IWDG_WRITE_DISABLE Disable write access to IWDG_PR and IWDG_RLR registers + */ +void IWDG_WriteConfig(uint16_t IWDG_WriteAccess) +{ + /* Check the parameters */ + assert_param(IS_IWDG_WRITE(IWDG_WriteAccess)); + IWDG->KEY = IWDG_WriteAccess; +} + +/** + * @brief Sets IWDG Prescaler value. + * @param IWDG_Prescaler specifies the IWDG Prescaler value. + * This parameter can be one of the following values: + * @arg IWDG_PRESCALER_DIV4 IWDG prescaler set to 4 + * @arg IWDG_PRESCALER_DIV8 IWDG prescaler set to 8 + * @arg IWDG_PRESCALER_DIV16 IWDG prescaler set to 16 + * @arg IWDG_PRESCALER_DIV32 IWDG prescaler set to 32 + * @arg IWDG_PRESCALER_DIV64 IWDG prescaler set to 64 + * @arg IWDG_PRESCALER_DIV128 IWDG prescaler set to 128 + * @arg IWDG_PRESCALER_DIV256 IWDG prescaler set to 256 + */ +void IWDG_SetPrescalerDiv(uint8_t IWDG_Prescaler) +{ + /* Check the parameters */ + assert_param(IS_IWDG_PRESCALER_DIV(IWDG_Prescaler)); + IWDG->PREDIV = IWDG_Prescaler; +} + +/** + * @brief Sets IWDG Reload value. + * @param Reload specifies the IWDG Reload value. + * This parameter must be a number between 0 and 0x0FFF. + */ +void IWDG_CntReload(uint16_t Reload) +{ + /* Check the parameters */ + assert_param(IS_IWDG_RELOAD(Reload)); + IWDG->RELV = Reload; +} + +/** + * @brief Reloads IWDG counter with value defined in the reload register + * (write access to IWDG_PR and IWDG_RLR registers disabled). + */ +void IWDG_ReloadKey(void) +{ + IWDG->KEY = KEY_ReloadKey; +} + +/** + * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled). + */ +void IWDG_Enable(void) +{ + IWDG->KEY = KEY_EnableKey; +} + +/** + * @brief Checks whether the specified IWDG flag is set or not. + * @param IWDG_FLAG specifies the flag to check. + * This parameter can be one of the following values: + * @arg IWDG_PVU_FLAG Prescaler Value Update on going + * @arg IWDG_CRVU_FLAG Reload Value Update on going + * @return The new state of IWDG_FLAG (SET or RESET). + */ +FlagStatus IWDG_GetStatus(uint16_t IWDG_FLAG) +{ + FlagStatus bitstatus = RESET; + /* Check the parameters */ + assert_param(IS_IWDG_FLAG(IWDG_FLAG)); + if ((IWDG->STS & IWDG_FLAG) != (uint32_t)RESET) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + /* Return the flag status */ + return bitstatus; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_keyscan.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_keyscan.c new file mode 100644 index 0000000..34bfe0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_keyscan.c @@ -0,0 +1,157 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_keyscan.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_keyscan.h" +#include "n32wb03x_rcc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** + * @brief Initializes the KEYSCAN peripheral according to the specified + * parameters in the KEYSCAN_InitType. + * @param KEYSCAN_InitStruct pointer to a KEYSCAN_InitType structure that + * contains the configuration information for the KEYSCAN peripheral. + */ + +void KEYSCAN_Init(KEYSCAN_InitType* KEYSCAN_InitStruct) +{ + KEYSCAN->KEYCR = 0; + + KEYSCAN->KEYCR = (KEYSCAN_InitStruct->Mask<Mode<Dts<Wts<Int_en<KEYCR |= (1<KEYCR &= ~(1<KEYCR |= (1<KEYCR |= (1<KEYCR & (1<KEYCR |= (1<KEYDATA0; + key_data[1] = KEYSCAN->KEYDATA1; + key_data[2] = KEYSCAN->KEYDATA2; + key_data[3] = KEYSCAN->KEYDATA3; + key_data[4] = KEYSCAN->KEYDATA4; +} + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_lpuart.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_lpuart.c new file mode 100644 index 0000000..fb79c5c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_lpuart.c @@ -0,0 +1,623 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_lpuart.c + * @author NSING Firmware Team + * @version v1.0.3 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_lpuart.h" +#include "n32wb03x_rcc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup LPUART + * @brief LPUART driver modules + * @{ + */ + +/** @addtogroup LPUART_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup LPUART_Private_Defines + * @{ + */ + +#define STS_CLR_MASK ((uint16_t)0x01BF) /*!< LPUART STS Mask */ + +#define INTEN_CLR_MASK ((uint16_t)0x0000) /*!< LPUART INTEN Mask */ +#define INT_MASK ((uint16_t)0x007F) /*!< LPUART Interrupt Mask */ + +#define CTRL_CLR_MASK ((uint16_t)0x70F4) /*!< LPUART CTRL Mask */ +#define CTRL_SMPCNT_MASK ((uint16_t)0x3FFF) /*!< LPUART Sampling Method Mask */ +#define CTRL_WUSTP_MASK ((uint16_t)0x4FFF) /*!< LPUART WakeUp Method Mask */ +#define CTRL_WUSTP_SET ((uint16_t)0x0080) /*!< LPUART stop mode Enable Mask */ +#define CTRL_WUSTP_RESET ((uint16_t)0x7F7F) /*!< LPUART stop mode Disable Mask */ +#define CTRL_LOOPBACK_SET ((uint16_t)0x0010) /*!< LPUART Loopback Test Enable Mask */ +#define CTRL_LOOPBACK_RESET ((uint16_t)0xFFEF) /*!< LPUART Loopback Test Disable Mask */ +#define CTRL_FLUSH_SET ((uint16_t)0x0004) /*!< LPUART Flush Receiver FIFO Enable Mask */ +#define CTRL_FLUSH_RESET ((uint16_t)0x7FFB) /*!< LPUART Flush Receiver FIFO Disable Mask */ + +/** + * @} + */ + +/** @addtogroup LPUART_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup LPUART_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup LPUART_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup LPUART_Private_Functions + * @{ + */ + +/** + * @brief Deinitializes the LPUART peripheral registers to their default reset values. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + */ +void LPUART_DeInit(LPUART_Module* LPUARTx) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + + if(LPUARTx == LPUART1) + { + RCC->LSCTRL |=RCC_LSCTRL_LPUARTRST; + RCC->LSCTRL &=~RCC_LSCTRL_LPUARTRST; + } + else + { + } +} + +/** + * @brief Initializes the LPUART peripheral according to the specified + * parameters in the LPUART_InitStruct. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param LPUART_InitStruct pointer to a LPUART_InitType structure + * that contains the configuration information for the specified LPUART + * peripheral. + */ +void LPUART_Init(LPUART_Module* LPUARTx, LPUART_InitType* LPUART_InitStruct) +{ + uint32_t tmpregister = 0x00, clocksrc = 0x00, apbclock = 0x00; + uint32_t integerdivider = 0x00; + uint32_t fractionaldivider = 0x00; + uint32_t tmpdivider = 0x00, lastdivider = 0x00, i = 0x00; + uint32_t lpuartxbase = 0; + RCC_ClocksType RCC_ClocksStatus; + + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_LPUART_BAUDRATE(LPUART_InitStruct->BaudRate)); + assert_param(IS_LPUART_PARITY(LPUART_InitStruct->Parity)); + assert_param(IS_LPUART_MODE(LPUART_InitStruct->Mode)); + assert_param(IS_LPUART_RTSTHRESHOLD(LPUART_InitStruct->RtsThreshold)); + assert_param(IS_LPUART_HARDWARE_FLOW_CONTROL(LPUART_InitStruct->HardwareFlowControl)); + + lpuartxbase = (uint32_t)LPUARTx; + + /*---------------------------- LPUART CTRL Configuration -----------------------*/ + tmpregister = LPUARTx->CTRL; + /* Clear FC_RXEN, FC_TXEN, RTS_THSEL[1:0], PCDIS, TRS and PSEL bits */ + tmpregister &= CTRL_CLR_MASK; + /* Configure the LPUART Parity, Mode, RtsThrehold and HardwareFlowControl ----------------------- */ + /* Set PCDIS and PSEL bits according to Parity value */ + /* Set the TRS bit according to Mode */ + /* Set RTS_THSEL[1:0] bits according to RtsThrehold */ + /* Set FC_RXEN and FC_TXEN bits according to HardwareFlowControl */ + tmpregister |= (uint32_t)LPUART_InitStruct->Parity | LPUART_InitStruct->Mode | LPUART_InitStruct->RtsThreshold | LPUART_InitStruct->HardwareFlowControl; + /* Write to LPUART CTRL */ + LPUARTx->CTRL = (uint16_t)tmpregister; + + /*---------------------------- LPUART BRCFG1 & 2 Configuration -----------------------*/ + /* Configure the LPUART Baud Rate -------------------------------------------*/ + if(lpuartxbase == LPUART1_BASE) + { + clocksrc = RCC_GetLpuartClkSrc(RCC_LPUART1CLK); + } + if (clocksrc == RCC_LSCTRL_LPUART_LSI) + { + #ifdef LSI_TRIM_32768HZ + apbclock = 0x8000; // 32.768kHz, should the same with your LSI trim + #elif defined LSI_TRIM_28800HZ + apbclock = 28800; // 28.8kHz, should the same with your LSI trim + #elif defined LSI_TRIM_32000HZ + apbclock = 0x7D00; // 32kHz, should the same with your LSI trim + #else + apbclock = 0x8000; // LSI default is 32.768kHz + #endif + } + else if (clocksrc == RCC_LSCTRL_LPUART_LSE) + { + apbclock = 0x8000; // 32.768kHz + } + else // APB1 + { + RCC_GetClocksFreqValue(&RCC_ClocksStatus); + apbclock = RCC_ClocksStatus.Pclk1Freq; + } + + /* Determine the integer part */ + integerdivider = apbclock / (LPUART_InitStruct->BaudRate); + + /* Configure sampling method */ + if(integerdivider <= 10) + { + LPUART_ConfigSamplingMethod(LPUARTx, LPUART_SMPCNT_1B); + } + else + { + LPUART_ConfigSamplingMethod(LPUARTx, LPUART_SMPCNT_3B); + } + + /* Check baudrate */ + assert_param(IS_LPUART_BAUDRATE(integerdivider)); + /* Write to LPUART BRCFG1 */ + LPUARTx->BRCFG1 = (uint16_t)integerdivider; + + /* Determine the fractional part */ + fractionaldivider = ((apbclock % (LPUART_InitStruct->BaudRate)) * 10000) / (LPUART_InitStruct->BaudRate); + + tmpregister = 0x00; + tmpdivider = fractionaldivider; + /* Implement the fractional part in the register */ + for( i = 0; i < 8; i++) + { + lastdivider = tmpdivider; + tmpdivider = lastdivider + fractionaldivider; + if((tmpdivider / 10000) ^ (lastdivider / 10000)) + { + tmpregister |= (0x01 << i); + } + } + /* Write to LPUART BRCFG2 */ + LPUARTx->BRCFG2 = (uint8_t)tmpregister; +} + +/** + * @brief Fills each LPUART_InitStruct member with its default value. + * @param LPUART_InitStruct pointer to a LPUART_InitType structure + * which will be initialized. + */ +void LPUART_StructInit(LPUART_InitType* LPUART_InitStruct) +{ + /* LPUART_InitStruct members default value */ + LPUART_InitStruct->BaudRate = 9600; + LPUART_InitStruct->Parity = LPUART_PE_NO; + LPUART_InitStruct->Mode = LPUART_MODE_RX | LPUART_MODE_TX; + LPUART_InitStruct->RtsThreshold = LPUART_RTSTH_FIFOFU; + LPUART_InitStruct->HardwareFlowControl = LPUART_HFCTRL_NONE; +} + +/** + * @brief Flushes Receiver FIFO. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + */ +void LPUART_FlushRxFifo(LPUART_Module* LPUARTx) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + + /* Clear LPUART Flush Receiver FIFO */ + LPUARTx->CTRL |= CTRL_FLUSH_SET; + while(LPUART_GetFlagStatus(LPUARTx, LPUART_FLAG_FIFO_NE) != RESET) + { + } + LPUARTx->CTRL &= CTRL_FLUSH_RESET; +} + +/** + * @brief Enables or disables the specified LPUART interrupts. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param LPUART_INT specifies the LPUART interrupt sources to be enabled or disabled. + * This parameter can be one of the following values: + * @arg LPUART_INT_WUF Wake-Up Interrupt + * @arg LPUART_INT_FIFO_NE FIFO Non-Empty Interrupt + * @arg LPUART_INT_FIFO_HF FIFO Half Full Interrupt + * @arg LPUART_INT_FIFO_FU FIFO Full Interrupt Enable + * @arg LPUART_INT_FIFO_OV FIFO Overflow Interrupt + * @arg LPUART_INT_TXC TX Complete Interrupt + * @arg LPUART_INT_PE Parity Check Error Interrupt + * @param Cmd new state of the specified LPUART interrupts. + * This parameter can be: ENABLE or DISABLE. + */ +void LPUART_ConfigInt(LPUART_Module* LPUARTx, uint16_t LPUART_INT, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_LPUART_CFG_INT(LPUART_INT)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + LPUARTx->INTEN |= (uint8_t)LPUART_INT; + } + else + { + LPUARTx->INTEN &= (uint8_t)(~LPUART_INT); + } +} + +/** + * @brief Enables or disables the LPUART's DMA interface. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param LPUART_DMAReq specifies the DMA request. + * This parameter can be any combination of the following values: + * @arg LPUART_DMAREQ_TX LPUART DMA transmit request + * @arg LPUART_DMAREQ_RX LPUART DMA receive request + * @param Cmd new state of the DMA Request sources. + * This parameter can be: ENABLE or DISABLE. + */ +void LPUART_EnableDMA(LPUART_Module* LPUARTx, uint16_t LPUART_DMAReq, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_LPUART_DMAREQ(LPUART_DMAReq)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the DMA transfer by setting the DMA_RXEN and/or DMA_TXEN bits in the LPUART_CTRL register */ + LPUARTx->CTRL |= LPUART_DMAReq; + } + else + { + /* Disable the DMA transfer by clearing the DMA_RXEN and/or DMA_TXEN bits in the LPUART_CTRL register */ + LPUARTx->CTRL &= (uint16_t)(~LPUART_DMAReq); + } +} + +/** + * @brief Selects the LPUART WakeUp method. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param LPUART_WakeUpMethod specifies the LPUART wakeup method. + * This parameter can be one of the following values: + * @arg LPUART_WUSTP_STARTBIT WakeUp by Start Bit Detection + * @arg LPUART_WUSTP_RXNE WakeUp by RXNE Detection + * @arg LPUART_WUSTP_BYTE WakeUp by A Configurable Received Byte + * @arg LPUART_WUSTP_FRAME WakeUp by A Programmed 4-Byte Frame + */ +void LPUART_ConfigWakeUpMethod(LPUART_Module* LPUARTx, uint16_t LPUART_WakeUpMethod) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_LPUART_WAKEUP(LPUART_WakeUpMethod)); + + LPUARTx->CTRL &= CTRL_WUSTP_MASK; + LPUARTx->CTRL |= LPUART_WakeUpMethod; +} + +/** + * @brief Enables or disables LPUART Wakeup in STOP mode. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param Cmd new state of the LPUART Wakeup in STOP mode. + * This parameter can be: ENABLE or DISABLE. + */ +void LPUART_EnableWakeUpStop(LPUART_Module* LPUARTx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable Wakeup in STOP mode by setting the WUSTP bit in the CTRL register */ + LPUARTx->CTRL |= CTRL_WUSTP_SET; + } + else + { + /* Disable Wakeup in STOP mode by clearing the WUSTP bit in the CTRL register */ + LPUARTx->CTRL &= CTRL_WUSTP_RESET; + } +} + +/** + * @brief Selects the LPUART Sampling method. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param LPUART_SamplingMethod specifies the LPAURT sampling method. + * This parameter can be one of the following values: + * @arg LPUART_SMPCNT_3B 3 Sample bit + * @arg LPUART_SMPCNT_1B 1 Sample bit + */ +void LPUART_ConfigSamplingMethod(LPUART_Module* LPUARTx, uint16_t LPUART_SamplingMethod) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_LPUART_SAMPLING(LPUART_SamplingMethod)); + + LPUARTx->CTRL &= CTRL_SMPCNT_MASK; + LPUARTx->CTRL |= LPUART_SamplingMethod; +} + +/** + * @brief Enables or disables LPUART Loop Back Self-Test. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param Cmd new state of the LPUART Loop Back Self-Test. + * This parameter can be: ENABLE or DISABLE. + */ +void LPUART_EnableLoopBack(LPUART_Module* LPUARTx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable LPUART Loop Back Self-Test by setting the LOOKBACK bit in the CTRL register */ + LPUARTx->CTRL |= CTRL_LOOPBACK_SET; + } + else + { + /* Disable LPUART Loop Back Self-Test by clearing the LOOKBACK bit in the CTRL register */ + LPUARTx->CTRL &= CTRL_LOOPBACK_RESET; + } +} + +/** + * @brief Transmits single data through the LPUART peripheral. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param Data the data to transmit. + */ +void LPUART_SendData(LPUART_Module* LPUARTx, uint8_t Data) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_LPUART_DATA(Data)); + + /* Transmit Data */ + LPUARTx->DAT = (Data & (uint8_t)0xFF); +} + +/** + * @brief Returns the most recent received data by the LPUART peripheral. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @return The received data. + */ +uint8_t LPUART_ReceiveData(LPUART_Module* LPUARTx) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + + /* Receive Data */ + return (uint8_t)(LPUARTx->DAT & (uint8_t)0xFF); +} + +/** + * @brief SConfigures LPUART detected byte or frame match for wakeup CPU from STOPS mode. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param LPUART_WakeUpData specifies the LPUART detected byte or frame match for wakeup CPU from STOP mode. + */ +void LPUART_ConfigWakeUpData(LPUART_Module* LPUARTx, uint32_t LPUART_WakeUpData) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + + LPUARTx->WUDAT = LPUART_WakeUpData; +} + +/** + * @brief Checks whether the specified LPUART flag is set or not. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param LPUART_FLAG specifies the flag to check. + * This parameter can be one of the following values: + * @arg LPUART_FLAG_PEF Parity Check Error Flag. + * @arg LPUART_FLAG_TXC TX Complete Flag. + * @arg LPUART_FLAG_FIFO_OV FIFO Overflow Flag. + * @arg LPUART_FLAG_FIFO_FU FIFO Full Flag. + * @arg LPUART_FLAG_FIFO_HF FIFO Half Full Flag. + * @arg LPUART_FLAG_FIFO_NE FIFO Non-Empty Flag. + * @arg LPUART_FLAG_CTS CTS Change(Hardware Flow Control) Flag. + * @arg LPUART_FLAG_WUFWakeup from STOP mode Flag. + * @arg LPUART_FLAG_NF Noise Detection Flag. + * @return The new state of LPUART_FLAG (SET or RESET). + */ +FlagStatus LPUART_GetFlagStatus(LPUART_Module* LPUARTx, uint16_t LPUART_FLAG) +{ + FlagStatus bitstatus = RESET; + + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_LPUART_FLAG(LPUART_FLAG)); + + if ((LPUARTx->STS & LPUART_FLAG) != (uint16_t)RESET) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/** + * @brief Clears the LPUART's pending flags. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param LPUART_FLAG specifies the flag to clear. + * This parameter can be any combination of the following values: + * @arg LPUART_FLAG_PEF Parity Check Error Flag. + * @arg LPUART_FLAG_TXC TX Complete Flag. + * @arg LPUART_FLAG_FIFO_OV FIFO Overflow Flag. + * @arg LPUART_FLAG_FIFO_FU FIFO Full Flag. + * @arg LPUART_FLAG_FIFO_HF FIFO Half Full Flag. + * @arg LPUART_FLAG_FIFO_NE FIFO Non-Empty Flag. + * @arg LPUART_FLAG_CTS CTS Change(Hardware Flow Control) Flag. + * @arg LPUART_FLAG_WUFWakeup from STOP mode Flag. + * @arg LPUART_FLAG_NF Noise Detection Flag. + */ +void LPUART_ClrFlag(LPUART_Module* LPUARTx, uint16_t LPUART_FLAG) +{ + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_LPUART_CLEAR_FLAG(LPUART_FLAG)); + + LPUARTx->STS = (uint16_t)LPUART_FLAG; +} + +/** + * @brief Checks whether the specified LPUART interrupt has occurred or not. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param LPUART_INT specifies the LPUART interrupt source to check. + * This parameter can be one of the following values: + * @arg LPUART_INT_WUF Wake-Up Interrupt + * @arg LPUART_INT_FIFO_NE FIFO Non-Empty Interrupt + * @arg LPUART_INT_FIFO_HF FIFO Half Full Interrupt + * @arg LPUART_INT_FIFO_FU FIFO Full Interrupt Enable + * @arg LPUART_INT_FIFO_OV FIFO Overflow Interrupt + * @arg LPUART_INT_TXC TX Complete Interrupt + * @arg LPUART_INT_PE Parity Check Error Interrupt + * @return The new state of LPUART_INT (SET or RESET). + */ +INTStatus LPUART_GetIntStatus(LPUART_Module* LPUARTx, uint16_t LPUART_INT) +{ + uint32_t bitpos = 0x00, itmask = 0x00; + INTStatus bitstatus = RESET; + + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_LPUART_GET_INT(LPUART_INT)); + + /* Get the interrupt position */ + itmask = (uint8_t)(LPUART_INT >> 0x08) & INT_MASK; + itmask = (uint32_t)0x01 << itmask; + itmask &= LPUARTx->INTEN; + + bitpos = ((uint8_t)LPUART_INT) & 0xFF; + bitpos &= LPUARTx->STS; + if ((itmask != (uint16_t)RESET) && (bitpos != (uint16_t)RESET)) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + + return bitstatus; +} + +/** + * @brief Clears the LPUART's interrupt pending bits. + * @param LPUARTx Select the LPUART peripheral. + * This parameter can be one of the following values: LPUART1. + * @param LPUART_INT specifies the interrupt pending bit to clear. + * This parameter can be one of the following values: + * @arg LPUART_INT_WUF Wake-Up Interrupt + * @arg LPUART_INT_FIFO_NE FIFO Non-Empty Interrupt + * @arg LPUART_INT_FIFO_HF FIFO Half Full Interrupt + * @arg LPUART_INT_FIFO_FU FIFO Full Interrupt Enable + * @arg LPUART_INT_FIFO_OV FIFO Overflow Interrupt + * @arg LPUART_INT_TXC TX Complete Interrupt + * @arg LPUART_INT_PE Parity Check Error Interrupt + */ +void LPUART_ClrIntPendingBit(LPUART_Module* LPUARTx, uint16_t LPUART_INT) +{ + uint16_t itmask = 0x00; + + /* Check the parameters */ + assert_param(IS_LPUART_ALL_PERIPH(LPUARTx)); + assert_param(IS_LPUART_CLR_INT(LPUART_INT)); + + itmask = ((uint8_t)LPUART_INT) & 0xFF; + LPUARTx->STS = (uint16_t)itmask; +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_pwr.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_pwr.c new file mode 100644 index 0000000..978b740 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_pwr.c @@ -0,0 +1,248 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_pwr.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_pwr.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** + * @} + */ + +/** @addtogroup PWR_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup PWR_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup PWR_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup PWR_Private_Functions + * @{ + */ + + +/** + * @brief Deinitializes the PWR peripheral registers to their default reset values. + */ +void PWR_DeInit(void) +{ + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_PWR, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_PWR, DISABLE); +} + +/** + * @brief Enters IDLE mode. + * @param SLEEPONEXIT: specifies the SLEEPONEXIT state in IDLE mode. + * This parameter can be one of the following values: + * @arg DISABLE: SLEEP mode with SLEEPONEXIT disable + * @arg ENABLE : SLEEP mode with SLEEPONEXIT enable + * @param PWR_STOPEntry: specifies if SLEEP mode in entered with WFI or WFE instruction. + * This parameter can be one of the following values: + * @arg PWR_IDLEENTRY_WFI: enter IDLE mode with WFI instruction + * @arg PWR_IDLEENTRY_WFE: enter IDLE mode with WFE instruction + * @retval None + */ +void PWR_EnterIDLEMode(uint8_t IDLEONEXIT, uint8_t PWR_IDLEEntry) +{ + + /* CLEAR SLEEPDEEP bit of Cortex System Control Register */ + SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP); + + /* Select SLEEPONEXIT mode entry --------------------------------------------------*/ + if(IDLEONEXIT == ENABLE) + { + /* the MCU enters Sleep mode as soon as it exits the lowest priority ISR */ + SCB->SCR |= SCB_SCR_SLEEPONEXIT; + } + else if(IDLEONEXIT == DISABLE) + { + /* Sleep-now */ + SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPONEXIT); + } + + /* Select SLEEP mode entry --------------------------------------------------*/ + if(PWR_IDLEEntry == PWR_IDLEENTRY_WFI) + { + /* Request Wait For Interrupt */ + __WFI(); + } + else + { + /* Request Wait For Event */ + __SEV(); + __WFE(); + __WFE(); + } +} + +/** + * @brief Enters SLEEP mode. + * @param PWR_SLEEPEntry: specifies if SLEEP mode in entered with WFI or WFE instruction. + * This parameter can be one of the following values: + * @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction + * @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction + * @retval None + */ +void PWR_EnterSLEEPMode(uint8_t PWR_SleepEntry) +{ + uint32_t tmpreg = 0; + /* Set BLE modem sleep */ + *(uint32_t*)0x40011004 |= 0x40; //for without HSE + *(uint32_t *)(BLE_BASE + 0x30) = 0x07; + while(PWR->CR1&PWR_CR1_OSC_EN); + *(uint32_t*)0x40011004 &= ~0x40;//for without HSE + + /* Select the regulator state in SLEEP mode ---------------------------------*/ + tmpreg = PWR->CR1; + /* Clear PDDS and FLPDS bits */ + tmpreg &= ~PWR_CR1_MODE_SEL; + /* Set FLPDS bit according to PWR_Regulator value */ + tmpreg |= (PWR_CR1_MODE_SLEEP |PWR_CR1_MODE_EN); + /* Store the new value */ + PWR->CR1 = tmpreg; + /* Set SLEEPDEEP bit of Cortex System Control Register */ + SCB->SCR |= SCB_SCR_SLEEPDEEP; + + /* Select SLEEP mode entry --------------------------------------------------*/ + if(PWR_SleepEntry == PWR_SLEEPENTRY_WFI) + { + /* Request Wait For Interrupt */ + __WFI(); + } + else + { + /* Request Wait For Event */ + __SEV(); + __WFE(); + __WFE(); + } + + /* Reset SLEEPDEEP bit of Cortex System Control Register */ + SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP); +} + + /** + * @brief Enters PD mode. + * @param PWR_PDEntry: specifies if PD mode in entered with WFI or WFE instruction. + * This parameter can be one of the following values: + * @arg PWR_PDENTRY_WFI: enter PD mode with WFI instruction + * @arg PWR_PDENTRY_WFE: enter PD mode with WFE instruction + * @retval None + */ +void PWR_EnterPDMode(uint8_t PWR_PDEntry) +{ + uint32_t tmpreg = 0; + /* Select the regulator state in SHUTDOWN mode ---------------------------------*/ + tmpreg = PWR->CR1; + /* Clear PDDS bits */ + tmpreg &= ~PWR_CR1_MODE_SEL; + /* Set FLPDS bit according to PWR_Regulator value */ + tmpreg |= PWR_CR1_MODE_PD|PWR_CR1_MODE_EN; + /* Store the new value */ + PWR->CR1 = tmpreg; + + /* Set SLEEPDEEP bit of Cortex System Control Register */ + SCB->SCR |= SCB_SCR_SLEEPDEEP; + /* This option is used to ensure that store operations are completed */ + #if defined ( __CC_ARM ) + __force_stores(); + #endif + /* Select SHUTDOWN mode entry --------------------------------------------------*/ + if(PWR_PDEntry == PWR_PDENTRY_WFI) + { + /* Request Wait For Interrupt */ + __WFI(); + } + else + { + /* Request Wait For Event */ + __SEV(); + __WFE(); + __WFE(); + } + +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_qflash.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_qflash.c new file mode 100644 index 0000000..2c31d8a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_qflash.c @@ -0,0 +1,266 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_qflash.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_qflash.h" +#include +/** @addtogroup n32wb03x_StdPeriph_Driver + * @{ + */ + +/** @addtogroup QFLASH + * @brief QFLASH driver modules + * @{ + */ + + +/** @addtogroup QFLASH_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup QFLASH_Private_Defines + * @{ + */ + +#define GLOBAL_INT_DISABLE() \ +uint32_t ui32IntStatus = 0; \ +do{ \ + ui32IntStatus = __get_PRIMASK();\ + __set_PRIMASK(1); \ +}while(0) + +#define GLOBAL_INT_RESTORE() \ +do{ \ + __set_PRIMASK(ui32IntStatus);\ +}while(0) + +/** + * @} + */ + +/** @addtogroup QFLASH_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup QFLASH_Private_Variables + * @{ + */ +static uint32_t ram_qflash_cmd[0x324/4+1]; +const uint8_t const_qflash_cmd[0x324] = { +0x01,0x38,0xfd,0xd1,0x70,0x47,0x00,0x00,0xf0,0xb4,0x03,0x24,0xa4,0x06,0x23,0x6a, +0x5b,0x08,0x5b,0x00,0x23,0x62,0x23,0x6a,0x02,0x25,0x2b,0x43,0x23,0x62,0x23,0x6a, +0x9b,0x07,0xfc,0xd4,0xff,0x23,0x01,0x33,0xa3,0x62,0x65,0x69,0xde,0x1d,0xb5,0x43, +0x65,0x61,0x65,0x69,0x1e,0x1d,0x35,0x43,0x65,0x61,0x00,0x02,0x6b,0x30,0x60,0x60, +0x08,0x20,0xa0,0x60,0xe2,0x60,0x01,0x26,0x26,0x61,0xa0,0x6a,0xc0,0x05,0xfc,0xd5, +0xa3,0x62,0x00,0x23,0xd2,0x1c,0x90,0x08,0x0e,0xd0,0x95,0x08,0x0f,0x48,0x00,0x68, +0x9a,0x00,0x88,0x54,0x07,0x0a,0x52,0x18,0x57,0x70,0x07,0x0c,0x00,0x0e,0x97,0x70, +0x5b,0x1c,0xd0,0x70,0x9d,0x42,0xf1,0xd8,0x60,0x69,0xff,0x21,0x08,0x31,0x88,0x43, +0x60,0x61,0x60,0x69,0x30,0x43,0x60,0x61,0x20,0x6a,0x80,0x08,0x80,0x00,0x20,0x62, +0x20,0x6a,0x30,0x43,0x20,0x62,0xf0,0xbc,0x00,0x20,0x70,0x47,0x80,0x00,0x00,0x0c, +0xf8,0xb5,0x06,0x46,0x01,0x20,0x00,0x25,0xc0,0x04,0x86,0x42,0x01,0xd9,0x05,0x20, +0xf8,0xbd,0x03,0x24,0xa4,0x06,0x20,0x6a,0x40,0x08,0x40,0x00,0x20,0x62,0x20,0x6a, +0x02,0x21,0x08,0x43,0x20,0x62,0x20,0x6a,0x80,0x07,0xfc,0xd4,0xff,0x27,0x01,0x37, +0xa7,0x62,0x00,0xf0,0xbb,0xf8,0x00,0x28,0x01,0xd0,0x03,0x25,0x15,0xe0,0x06,0x20, +0x60,0x60,0x01,0x21,0x21,0x61,0xa0,0x6a,0xc0,0x05,0xfc,0xd5,0xa7,0x62,0x30,0x02, +0x20,0x30,0x60,0x60,0x21,0x61,0xa0,0x6a,0xc0,0x05,0xfc,0xd5,0xa7,0x62,0x0c,0x48, +0x00,0xf0,0xc8,0xf8,0x00,0x28,0x00,0xd1,0x02,0x25,0x60,0x69,0xff,0x21,0x08,0x31, +0x88,0x43,0x60,0x61,0x60,0x69,0x01,0x21,0x08,0x43,0x60,0x61,0x20,0x6a,0x80,0x08, +0x80,0x00,0x20,0x62,0x20,0x6a,0x08,0x43,0x20,0x62,0x28,0x46,0xf8,0xbd,0x00,0x00, +0xe6,0x96,0x01,0x00,0xf7,0xb5,0x06,0x46,0x01,0x20,0xc0,0x04,0x82,0xb0,0x15,0x46, +0x86,0x42,0x02,0xd9,0x05,0x20,0x05,0xb0,0xf0,0xbd,0x03,0x20,0x80,0x06,0x01,0x6a, +0x49,0x08,0x49,0x00,0x01,0x62,0x01,0x6a,0x02,0x22,0x11,0x43,0x01,0x62,0x01,0x6a, +0x89,0x07,0xfc,0xd4,0xff,0x21,0x01,0x31,0x81,0x62,0xf2,0xb2,0x8c,0x1a,0xa5,0x42, +0x00,0xd8,0xac,0xb2,0x03,0x98,0x00,0x90,0x00,0xf0,0x68,0xf8,0x00,0x28,0x40,0xd1, +0x06,0x21,0x48,0x06,0x41,0x60,0x01,0x21,0x01,0x61,0x81,0x6a,0xc9,0x05,0xfc,0xd5, +0xff,0x21,0x01,0x31,0x03,0x20,0x80,0x06,0x81,0x62,0x41,0x69,0xff,0x22,0x08,0x32, +0x91,0x43,0x41,0x61,0x41,0x69,0x04,0x22,0x11,0x43,0x41,0x61,0x31,0x02,0x32,0x31, +0x41,0x60,0xc4,0x60,0x00,0x22,0x00,0x2c,0x16,0xd9,0x00,0x98,0x87,0x18,0x3b,0x78, +0xf8,0x78,0x19,0x46,0x7b,0x78,0x00,0x06,0x1b,0x02,0x19,0x43,0xbb,0x78,0x1b,0x04, +0x19,0x43,0x01,0x43,0x08,0x02,0xf9,0x78,0x00,0x0a,0x09,0x06,0x08,0x43,0x19,0x49, +0x08,0x60,0x12,0x1d,0xa2,0x42,0xe8,0xd3,0x01,0x21,0x03,0x20,0x80,0x06,0x01,0x61, +0x81,0x6a,0xc9,0x05,0xfc,0xd5,0xff,0x21,0x01,0x31,0x81,0x62,0x12,0x48,0x00,0xf0, +0x49,0xf8,0xa5,0x42,0x09,0xd0,0x03,0x98,0x36,0x19,0x00,0x19,0x2d,0x1b,0xff,0x24, +0x01,0x34,0x03,0x90,0xa5,0x42,0xad,0xd8,0xab,0xe7,0x03,0x20,0x80,0x06,0x41,0x69, +0xff,0x22,0x08,0x32,0x91,0x43,0x41,0x61,0x41,0x69,0x01,0x22,0x11,0x43,0x41,0x61, +0x01,0x6a,0x89,0x08,0x89,0x00,0x01,0x62,0x01,0x6a,0x11,0x43,0x01,0x62,0x00,0x20, +0x05,0xb0,0xf0,0xbd,0x80,0x00,0x00,0x0c,0x1a,0x06,0x00,0x00,0x38,0xb4,0x01,0x25, +0x03,0x20,0x80,0x06,0x6a,0x46,0xc5,0x60,0x35,0x21,0x41,0x60,0x05,0x61,0x81,0x6a, +0xc9,0x05,0xfc,0xd5,0xff,0x24,0x01,0x34,0x84,0x62,0x81,0x69,0xc5,0x60,0xcb,0xb2, +0x05,0x21,0x41,0x60,0x05,0x61,0x81,0x6a,0xc9,0x05,0xfc,0xd5,0x84,0x62,0x80,0x69, +0x19,0x02,0xc0,0xb2,0x01,0x43,0x88,0xb2,0x11,0x80,0xc0,0x07,0x00,0xd0,0x01,0x20, +0x38,0xbc,0x70,0x47,0xf8,0xb4,0x00,0x21,0x01,0x25,0x03,0x22,0x92,0x06,0x6b,0x46, +0xd5,0x60,0x35,0x24,0x54,0x60,0x15,0x61,0x94,0x6a,0xe4,0x05,0xfc,0xd5,0xff,0x27, +0x01,0x37,0x97,0x62,0x94,0x69,0xd5,0x60,0xe4,0xb2,0x05,0x26,0x56,0x60,0x15,0x61, +0x96,0x6a,0xf6,0x05,0xfc,0xd5,0x97,0x62,0x96,0x69,0x24,0x02,0xf6,0xb2,0x34,0x43, +0x1c,0x80,0xe3,0x07,0x22,0xd0,0x81,0x42,0x02,0xd9,0xf8,0xbc,0x00,0x20,0x70,0x47, +0x03,0x22,0x92,0x06,0x6b,0x46,0xd5,0x60,0x35,0x24,0x54,0x60,0x15,0x61,0x49,0x1c, +0x94,0x6a,0xe4,0x05,0xfc,0xd5,0x97,0x62,0x94,0x69,0xd5,0x60,0xe4,0xb2,0x05,0x26, +0x56,0x60,0x15,0x61,0x96,0x6a,0xf6,0x05,0xfc,0xd5,0x97,0x62,0x92,0x69,0x24,0x02, +0xd2,0xb2,0x14,0x43,0xa2,0xb2,0x1c,0x80,0xd2,0x07,0xdc,0xd1,0xf8,0xbc,0x01,0x20, +0x70,0x47,0x00,0x00}; + +/** + * @} + */ + +/** @addtogroup QFLASH_Private_FunctionPrototypes + * @{ + */ +typedef ReturnMsg CMD_FLASH_SE_t( uint32_t flash_address) ; +typedef ReturnMsg CMD_FLASH_WRITE_t(uint32_t flash_address, uint8_t* p_data, uint32_t len); +typedef ReturnMsg CMD_FLASH_READ_t(uint32_t flash_address, uint8_t* p_data, uint32_t len); + +ReturnMsg (*CMD_FLASH_SE)( uint32_t flash_address); +ReturnMsg (*CMD_FLASH_WRITE)(uint32_t addr, uint8_t* p_data, uint32_t len); +ReturnMsg (*CMD_FLASH_READ)(uint32_t addr, uint8_t* p_data, uint32_t len); + +/** + * @} + */ + +/** @addtogroup QFLASH_Private_Functions + * @{ + */ + +/** + * @brief Initialize Qflash. + */ +void Qflash_Init(void) +{ + //Init Qflash algorithm + CMD_FLASH_SE = (CMD_FLASH_SE_t *)((uint8_t*)ram_qflash_cmd + 0xA1); + CMD_FLASH_WRITE = (CMD_FLASH_WRITE_t *)((uint8_t*)ram_qflash_cmd + 0x135); + CMD_FLASH_READ = (CMD_FLASH_READ_t *)((uint8_t*)ram_qflash_cmd + 0x09); + memcpy(ram_qflash_cmd,const_qflash_cmd,0x324); +} + +/** + * @brief Erase one sector in flash with ble schedule on. + * @param[in] flash_address erase address. + * @return none. + */ +uint32_t Qflash_Erase_Sector(uint32_t address) +{ + ReturnMsg error; + GLOBAL_INT_DISABLE(); + address -= 0x01000000; + assert_param(CMD_FLASH_SE != NULL); + error = CMD_FLASH_SE(address); + assert_param(error == FlashOperationSuccess); + GLOBAL_INT_RESTORE(); + return error; +} + +/** + * @brief Write mutable length data to flash with ble schedule on. + * @param[in] addr flash address. + * @param[in] p_data data to write. + * @param[in] len data len. (4-byte alignment) + * @return none. + */ +uint32_t Qflash_Write(uint32_t address, uint8_t* p_data, uint32_t len) +{ + ReturnMsg error; + GLOBAL_INT_DISABLE(); + address -= 0x01000000; + assert_param(CMD_FLASH_WRITE != NULL); + error = CMD_FLASH_WRITE(address, p_data, len); + assert_param(error == FlashOperationSuccess); + GLOBAL_INT_RESTORE(); + return error; +} + + +/** + * @brief Read mutable length data to ram. + * @param[in] addr flash address. + * @param[out] p_data data to read. + * @param[in] len data len. (4-byte alignment) + * @return none. + */ +uint32_t Qflash_Read(uint32_t address, uint8_t* p_data, uint32_t len) +{ + + ReturnMsg error; + GLOBAL_INT_DISABLE(); + address -= 0x01000000; + assert_param(CMD_FLASH_READ != NULL); + error = CMD_FLASH_READ(address, p_data, len); + assert_param(error == FlashOperationSuccess); + GLOBAL_INT_RESTORE(); + return error; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_rcc.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_rcc.c new file mode 100644 index 0000000..d4a006b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_rcc.c @@ -0,0 +1,1086 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_rcc.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_rcc.h" + +/** @addtogroup n32wb03x_StdPeriph_Driver + * @{ + */ + +/** @addtogroup RCC + * @brief RCC driver modules + * @{ + */ + +/** @addtogroup RCC_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup RCC_Private_Defines + * @{ + */ + + +/** + * @} + */ + +/** @addtogroup RCC_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup RCC_Private_Variables + * @{ + */ +static const uint8_t s_ApbPresTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; +static const uint8_t s_AhbPresTable[4] = {0, 0, 1, 2}; +/** + * @} + */ + +/** @addtogroup RCC_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup RCC_Private_Functions + * @{ + */ + +/** + * @brief Resets the RCC clock configuration to the default reset state. + */ +void RCC_DeInit(void) +{ + /* Set HSIEN bit */ + RCC->CTRL |= (uint32_t)0x00000001; + + /* Reset SCLKSW, AHBPRE, APB1PRES, APB2PRES, MCO and MCOPRES bits */ + RCC->CFG &= (uint32_t)0x21FF0000; + + /* Reset HSEEN, CLKSSEN and PLLEN bits */ + RCC->CTRL &= (uint32_t)0xFEF6FFFF; + + /* Reset PLLBP, PLLOUTEN bit */ + RCC->CTRL &= (uint32_t)0xFFFBFFFF; + + /* Reset PLLMULFCT, PLLPRE, PLLOUTDIV and PLLSRC bits */ + RCC->CFG &= (uint32_t)0xFE00FFFF; + + /* Reset CFG2 register */ + RCC->CFG2 = 0x00003800; + + /* Disable all interrupts and clear pending bits */ + RCC->CLKINT = 0x00BF0000; +} + +/** + * @brief Configures the External High Speed oscillator (HSE). + * @note HSE can not be stopped if it is used directly or through the PLL as system clock. + * @param RCC_HSE specifies the new state of the HSE. + * This parameter can be one of the following values: + * @arg RCC_HSE_DISABLE HSE oscillator OFF + * @arg RCC_HSE_ENABLE HSE oscillator ON + */ +void RCC_ConfigHse(uint32_t RCC_HSE) +{ + /* Check the parameters */ + assert_param(IS_RCC_HSE(RCC_HSE)); + /* Reset HSEON and HSEIOSEL bits before configuring the HSE ------------------*/ + /* Reset HSEON bit */ + RCC->CTRL &= ~RCC_CTRL_HSEEN; + /* Configure HSE (RCC_HSE_DISABLE is already covered by the code section above) */ + switch (RCC_HSE) + { + case RCC_HSE_ENABLE: + /* Set HSEEN bit */ + RCC->CTRL |= RCC_CTRL_HSEEN; + break; + default: + break; + } +} + +/** + * @brief Waits for HSE start-up. + * @return An ErrorStatus enumuration value: + * - SUCCESS: HSE oscillator is stable and ready to use + * - ERROR: HSE oscillator not yet ready + */ +ErrorStatus RCC_WaitHseStable(void) +{ + __IO uint32_t StartUpCounter = 0; + ErrorStatus status = ERROR; + FlagStatus HSEStatus = RESET; + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC_GetFlagStatus(RCC_CTRL_FLAG_HSERDF); + StartUpCounter++; + } while ((StartUpCounter != HSE_STARTUP_TIMEOUT) && (HSEStatus == RESET)); + + if (RCC_GetFlagStatus(RCC_CTRL_FLAG_HSERDF) != RESET) + { + status = SUCCESS; + } + else + { + status = ERROR; + } + return (status); +} + +/** + * @brief Configures the Internal High Speed oscillator (HSI). + * @note HSI can not be stopped if it is used directly or through the PLL as system clock. + * @param RCC_HSI specifies the new state of the HSI. + * This parameter can be one of the following values: + * @arg RCC_HSI_DISABLE HSI oscillator OFF + * @arg RCC_HSI_ENABLE HSI oscillator ON + */ +void RCC_ConfigHsi(uint32_t RCC_HSI) +{ + /* Check the parameters */ + assert_param(IS_RCC_HSI(RCC_HSI)); + /* Reset HSIEN bit */ + RCC->CTRL &= ~RCC_CTRL_HSIEN; + /* Configure HSI */ + switch (RCC_HSI) + { + case RCC_HSI_ENABLE: + /* Set HSIEN bit */ + RCC->CTRL |= RCC_CTRL_HSIEN; + break; + + default: + break; + } +} + +/** + * @brief Waits for HSI start-up. + * @return An ErrorStatus enumuration value: + * - SUCCESS: HSI oscillator is stable and ready to use + * - ERROR: HSI oscillator not yet ready + */ +ErrorStatus RCC_WaitHsiStable(void) +{ + __IO uint32_t StartUpCounter = 0; + ErrorStatus status = ERROR; + FlagStatus HSIStatus = RESET; + + /* Wait till HSI is ready and if Time out is reached exit */ + do + { + HSIStatus = RCC_GetFlagStatus(RCC_CTRL_FLAG_HSIRDF); + StartUpCounter++; + } while ((StartUpCounter != HSI_STARTUP_TIMEOUT) && (HSIStatus == RESET)); + + if (RCC_GetFlagStatus(RCC_CTRL_FLAG_HSIRDF) != RESET) + { + status = SUCCESS; + } + else + { + status = ERROR; + } + return (status); +} + + +/** + * @brief Enables or disables the Internal High Speed oscillator (HSI). + * @note HSI can not be stopped if it is used directly or through the PLL as system clock. + * @param Cmd new state of the HSI. This parameter can be: ENABLE or DISABLE. + */ +void RCC_EnableHsi(FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if(Cmd == ENABLE) + { + /* Set HSIEN bit */ + RCC->CTRL |= RCC_CTRL_HSIEN; + } + else + { + /* Reset HSIEN bit */ + RCC->CTRL &= ~RCC_CTRL_HSIEN; + } +} + + +/** + * @brief Configures the system clock (SYSCLK). + * @param RCC_SYSCLKSource specifies the clock source used as system clock. + * This parameter can be one of the following values: + * @arg RCC_SYSCLK_SRC_HSI HSI selected as system clock + * @arg RCC_SYSCLK_SRC_HSE HSE selected as system clock + */ +void RCC_ConfigSysclk(uint32_t RCC_SYSCLKSource) +{ + uint32_t tmpregister = 0; + /* Check the parameters */ + assert_param(IS_RCC_SYSCLK_SRC(RCC_SYSCLKSource)); + tmpregister = RCC->CFG; + /* Clear SW[2:0] bits */ + tmpregister &= ~RCC_CFG_SCLKSW; + /* Set SW[2:0] bits according to RCC_SYSCLKSource value */ + tmpregister |= RCC_SYSCLKSource; + /* Store the new value */ + RCC->CFG = tmpregister; +} + +/** + * @brief Returns the clock source used as system clock. + * @return The clock source used as system clock. The returned value can + * be one of the following: + * - RCC_CFG_SCLKSTS_HSI: HSI used as system clock + * - RCC_CFG_SCLKSTS_HSE: HSE used as system clock + */ +uint32_t RCC_GetSysclkSrc(void) +{ + return ((uint32_t)(RCC->CFG & RCC_CFG_SCLKSTS)); +} + +/** + * @brief Configures the AHB clock (HCLK). + * @param RCC_SYSCLK defines the AHB clock divider. This clock is derived from + * the system clock (SYSCLK). + * This parameter can be one of the following values: + * @arg RCC_SYSCLK_DIV1 AHB clock = SYSCLK + * @arg RCC_SYSCLK_DIV2 AHB clock = SYSCLK/2 + * @arg RCC_SYSCLK_DIV4 AHB clock = SYSCLK/4 + */ +void RCC_ConfigHclk(uint32_t RCC_SYSCLK) +{ + uint32_t tmpregister = 0; + /* Check the parameters */ + assert_param(IS_RCC_SYSCLK_DIV(RCC_SYSCLK)); + tmpregister = RCC->CFG; + /* Clear HPRE[3:0] bits */ + tmpregister &= ~RCC_CFG_AHBPRES; + /* Set HPRE[3:0] bits according to RCC_SYSCLK value */ + tmpregister |= RCC_SYSCLK; + /* Store the new value */ + RCC->CFG = tmpregister; +} + +/** + * @brief Configures the Low Speed APB clock (PCLK1). + * @param RCC_HCLK defines the APB1 clock divider. This clock is derived from + * the AHB clock (HCLK). + * This parameter can be one of the following values: + * @arg RCC_HCLK_DIV1 APB1 clock = HCLK + * @arg RCC_HCLK_DIV2 APB1 clock = HCLK/2 + * @arg RCC_HCLK_DIV4 APB1 clock = HCLK/4 + * @arg RCC_HCLK_DIV8 APB1 clock = HCLK/8 + * @arg RCC_HCLK_DIV16 APB1 clock = HCLK/16 + */ +void RCC_ConfigPclk1(uint32_t RCC_HCLK) +{ + uint32_t tmpregister = 0; + /* Check the parameters */ + assert_param(IS_RCC_HCLK_DIV(RCC_HCLK)); + tmpregister = RCC->CFG; + /* Clear PPRE1[2:0] bits */ + tmpregister &= ~RCC_CFG_APB1PRES; + /* Set PPRE1[2:0] bits according to RCC_HCLK value */ + tmpregister |= RCC_HCLK; + /* Store the new value */ + RCC->CFG = tmpregister; +} + +/** + * @brief Configures the High Speed APB clock (PCLK2). + * @param RCC_HCLK defines the APB2 clock divider. This clock is derived from + * the AHB clock (HCLK). + * This parameter can be one of the following values: + * @arg RCC_HCLK_DIV1 APB2 clock = HCLK + * @arg RCC_HCLK_DIV2 APB2 clock = HCLK/2 + * @arg RCC_HCLK_DIV4 APB2 clock = HCLK/4 + * @arg RCC_HCLK_DIV8 APB2 clock = HCLK/8 + * @arg RCC_HCLK_DIV16 APB2 clock = HCLK/16 + */ +void RCC_ConfigPclk2(uint32_t RCC_HCLK) +{ + uint32_t tmpregister = 0; + /* Check the parameters */ + assert_param(IS_RCC_HCLK_DIV(RCC_HCLK)); + tmpregister = RCC->CFG; + /* Clear PPRE2[2:0] bits */ + tmpregister &= ~RCC_CFG_APB2PRES; + /* Set PPRE2[2:0] bits according to RCC_HCLK value */ + tmpregister |= RCC_HCLK << 3; + /* Store the new value */ + RCC->CFG = tmpregister; +} + +/** + * @brief Enables or disables the specified RCC interrupts. + * @param RccInt specifies the RCC interrupt sources to be enabled or disabled. + * + * this parameter can be any combination of the following values + * @arg RCC_INT_LSIRDIF LSI ready interrupt + * @arg RCC_INT_LSERDIF LSE ready interrupt + * @arg RCC_INT_HSIRDIF HSI ready interrupt + * @arg RCC_INT_HSERDIF HSE ready interrupt + * @arg RCC_INT_PLLRDIF PLL ready interrupt + * @arg RCC_INT_RAMCPIF RAMC parity interrupt + * + * @param Cmd new state of the specified RCC interrupts. + * This parameter can be: ENABLE or DISABLE. + */ +void RCC_ConfigInt(uint8_t RccInt, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_RCC_INT(RccInt)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Perform Byte access to RCC_CLKINT bits to enable the selected interrupts */ + RCC->LSCTRL |= (((uint32_t)RccInt) << 8); + } + else + { + /* Perform Byte access to RCC_CLKINT bits to disable the selected interrupts */ + RCC->LSCTRL &= (~(((uint32_t)RccInt) << 8)); + } +} + +/** + * @brief Configures the TIM1 clock (TIM1CLK). + * @param RCC_TIM1CLKSource specifies the TIM1 clock source. + * This parameter can be one of the following values: + * @arg RCC_TIM1CLK_SRC_TIM1CLK + * @arg RCC_TIM1CLK_SRC_SYSCLK + */ +void RCC_ConfigTim1Clk(uint32_t RCC_TIM1CLKSource) +{ + uint32_t tmpregister = 0; + /* Check the parameters */ + assert_param(IS_RCC_TIM1CLKSRC(RCC_TIM1CLKSource)); + + tmpregister = RCC->CFG2; + /* Clear TIMCLK_SEL bits */ + tmpregister &= ~RCC_CFG2_TIMCLKSEL; + /* Set TIMCLK_SEL bits according to RCC_TIM18CLKSource value */ + tmpregister |= RCC_TIM1CLKSource; + + /* Store the new value */ + RCC->CFG2 = tmpregister; +} + + +/** + * @brief Configures the ADC clock. + * @param RCC_ADCCLKSource specifies the ADC clock source. + * This parameter can be on of the following values: + * @arg RCC_ADCCLK_SRC_AUDIOPLL + * @arg RCC_ADCCLK_SRC_HSE_DIV8 + */ +void RCC_ConfigAdcClk(uint32_t RCC_ADCCLKSource) +{ + uint32_t tmpregister = 0; + /* Check the parameters */ + assert_param(IS_RCC_ADCCLKSRC(RCC_ADCCLKSource)); + + tmpregister = RCC->CFG2; + + tmpregister &= ~RCC_CFG2_ADCSEL; + /* Set ADCSEL bits according to RCC_ADCCLKSource value */ + tmpregister |= RCC_ADCCLKSource; + + /* Store the new value */ + RCC->CFG2 = tmpregister; +} + + +/** + * @brief Configures the LPUART clock (LPUARTCLK). + * @param RCC_LPUARTx x = 1. + * This parameter can be one of the following values: + * @arg RCC_LPUART1CLK LPUART1 + * @param RCC_LPUARTCLKSource specifies the LPUART clock source. + * This parameter can be one of the following values: + * @arg RCC_LPUARTCLK_SRC_APB1 APB1 clock selected as LPUART clock + * @arg RCC_LPUARTCLK_SRC_LSI_LSE LSI_LSE selected as LPUART clock + */ +void RCC_ConfigLpuartClk(uint32_t RCC_LPUARTx, uint32_t RCC_LPUARTCLKSource) +{ + /* Check the parameters */ + assert_param(IS_RCC_LPUARTX(RCC_LPUARTx)); + assert_param(IS_RCC_LPUART_CLK(RCC_LPUARTCLKSource)); + + /* LPUART1 */ + if(RCC_LPUARTx == RCC_LPUART1CLK) + { + /* Clear the LPUART1 clock source */ + RCC->LSCTRL &= ~RCC_LSCTRL_LPUARTSEL; + + /* Select the LPTIM clock source */ + RCC->LSCTRL |= RCC_LPUARTCLKSource; + } +} + +/** + * @brief Returns the clock source used as LPUART clock. + * @param RCC_LPUARTx x = 1. + * This parameter can be one of the following values: + * @arg RCC_LPUART1CLK LPUART1 + * @return The clock source used as system clock. The returned value can + * be one of the following: + * - RCC_LPUARTCLK_SRC_APB1: APB1 used as LPUART clock + * - RCC_LPUARTCLK_SRC_LSI_LSE: LSI_LSE used as LPUART clock + */ + +uint32_t RCC_GetLpuartClkSrc(uint32_t RCC_LPUARTx) +{ + return ((uint32_t)(RCC->LSCTRL & (RCC_LSCTRL_LPUARTSEL_LSI_LSE))); +} + +/** + * @brief Enables or disables the LPUART clock. + * @note This function must be used only after the LPUART clock was selected using the RCC_ConfigLpuartClk function. + * @param Cmd new state of the LPUART clock. This parameter can be: ENABLE or DISABLE. + */ +void RCC_EnableLpuartClk(FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if(Cmd == ENABLE) + { + /* Set RTCEN bit */ + RCC->LSCTRL |= RCC_LSCTRL_LPUARTEN; + } + else + { + /* Reset RTCEN bit */ + RCC->LSCTRL &= ~RCC_LSCTRL_LPUARTEN; + } +} + +/** + * @brief Configures the External Low Speed oscillator (LSE). + * @param RCC_LSE specifies the new state of the LSE. + * This parameter can be one of the following values: + * @arg RCC_LSE_DISABLE LSE oscillator OFF + * @arg RCC_LSE_ENABLE LSE oscillator ON + * @arg RCC_LSE_BYPASS LSE oscillator bypassed with external clock + */ +void RCC_ConfigLse(uint8_t RCC_LSE) +{ + /* Check the parameters */ + assert_param(IS_RCC_LSE(RCC_LSE)); + /* Reset LSEEN and LSEBYP bits before configuring the LSE ------------------*/ + RCC->LSCTRL &= (~(RCC_LSCTRL_LSEEN | RCC_LSCTRL_LSEBP)); + /* Configure LSE (RCC_LSE_DISABLE is already covered by the code section above) */ + switch (RCC_LSE) + { + case RCC_LSE_ENABLE: + /* Set LSEON bit */ + RCC->LSCTRL |= RCC_LSE_ENABLE; + break; + + case RCC_LSE_BYPASS: + /* Set LSEBYP and LSEON bits */ + RCC->LSCTRL |= (RCC_LSE_BYPASS | RCC_LSE_ENABLE); + break; + + default: + break; + } +} + +/** + * @brief Enables or disables the Internal Low Speed oscillator (LSI). + * @note LSI can not be disabled if the IWDG is running. + * @param Cmd new state of the LSI. This parameter can be: ENABLE or DISABLE. + */ +void RCC_EnableLsi(FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if(Cmd == ENABLE) + { + /* Set LSIEN bit */ + RCC->LSCTRL |= RCC_LSCTRL_LSIEN; + } + else + { + /* Reset PLLEN bit */ + RCC->LSCTRL &= ~RCC_LSCTRL_LSIEN; + } +} + +/** + * @brief Configures the Low Speed Clock Source as LSE or LSI. + * @note Once the Low Speed Clock Source is selected it can't be changed unless the LowPower domain is reset. + * @param RCC_LSCTRLCLKSource specifies the LSCTRL clock source. + * This parameter can be one of the following values: + * @arg RCC_LSCTRL_LSXSEL_LSE: LSE selected as Low Speed Clock Source + * @arg RCC_LSCTRL_LSXSEL_LSI: LSI selected as Low Speed Clock Source + */ +void RCC_ConfigLSXSEL(uint32_t RCC_LS_Source) +{ + /* Check the parameters */ + assert_param(IS_RCC_RTCCLK_SRC(RCC_LS_Source)); + + /* Clear the RTC clock source */ + RCC->LSCTRL &= (~RCC_LSCTRL_LSXSEL); + + /* Select the RTC clock source */ + RCC->LSCTRL |= RCC_LS_Source; +} + +/** + * @brief Returns the clock source used as RTC clock (RTCCLK). + * @return The clock source used as system clock. The returned value can + * be one of the following: + * - RCC_RTCCLK_SRC_LSE: LSE used as RTC clock (RTCCLK) + * - RCC_RTCCLK_SRC_LSI: LSI used as RTC clock (RTCCLK) + */ +uint32_t RCC_GetRTCClkSrc(void) +{ + return ((uint32_t)(RCC->LSCTRL & RCC_LSCTRL_LSXSEL)); +} + +/** + * @brief Enables or disables the RTC clock. + * @note This function must be used only after the RTC clock was selected using the RCC_ConfigRtcClk function. + * @param Cmd new state of the RTC clock. This parameter can be: ENABLE or DISABLE. + */ +void RCC_EnableRtcClk(FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if(Cmd == ENABLE) + { + /* Set RTCEN bit */ + RCC->LSCTRL |= RCC_LSCTRL_RTCEN; + } + else + { + /* Reset RTCEN bit */ + RCC->LSCTRL &= ~RCC_LSCTRL_RTCEN; + } +} + + + +/** + * @brief Forces or releases RTC reset. + * @param Cmd new state of the specified peripheral reset. This parameter can be ENABLE or DISABLE. + */ +void RCC_EnableRTCReset(FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + RCC->LSCTRL |= RCC_LSCTRL_RTCRST; + } + else + { + RCC->LSCTRL &= ~RCC_LSCTRL_RTCRST; + } +} + + +/** + * @brief Returns the frequencies of different on chip clocks. + * @param RCC_Clocks pointer to a RCC_ClocksType structure which will hold + * the clocks frequencies. + * @note The result of this function could be not correct when using + * fractional value for HSE crystal. + */ +void RCC_GetClocksFreqValue(RCC_ClocksType* RCC_Clocks) +{ + uint32_t tmp = 0, presc = 0; + + /* Get SYSCLK source -------------------------------------------------------*/ + tmp = RCC->CFG & RCC_CFG_SCLKSTS; + + switch (tmp) + { + case RCC_CFG_SCLKSTS_HSI: /* HSI used as system clock */ + RCC_Clocks->SysclkFreq = HSI_VALUE; + break; + case RCC_CFG_SCLKSTS_HSE: /* HSE used as system clock */ + RCC_Clocks->SysclkFreq = HSE_VALUE; + break; + default: + RCC_Clocks->SysclkFreq = HSI_VALUE; + break; + } + + /* Compute HCLK, PCLK1, PCLK2 and ADCCLK clocks frequencies ----------------*/ + /* Get HCLK prescaler */ + tmp = RCC->CFG & RCC_CFG_AHBPRES; + tmp = tmp >> 4; + + presc = s_AhbPresTable[tmp]; + /* HCLK clock frequency */ + RCC_Clocks->HclkFreq = RCC_Clocks->SysclkFreq >> presc; + /* Get PCLK1 prescaler */ + tmp = RCC->CFG & RCC_CFG_APB1PRES; + tmp = tmp >> 8; + presc = s_ApbPresTable[tmp]; + /* PCLK1 clock frequency */ + RCC_Clocks->Pclk1Freq = RCC_Clocks->HclkFreq >> presc; + + /* Get PCLK2 prescaler */ + tmp = RCC->CFG & RCC_CFG_APB2PRES; + tmp = tmp >> 11; + presc = s_ApbPresTable[tmp]; + /* PCLK2 clock frequency */ + RCC_Clocks->Pclk2Freq = RCC_Clocks->HclkFreq >> presc; + + /* HSE_DIV8 is the ADC clock source */ + if(RCC->CFG2 & RCC_ADCCLK_SRC_HSE_DIV8 ) + { + RCC_Clocks->AdcclkFreq = HSE_VALUE/8; + } + /* AUDIOPLL is the ADC clock source */ + else + { + RCC_Clocks->AdcclkFreq = ADC_AUDIOPLLCLK_VALUE; + } +} + +/** + * @brief Enables or disables the AHB peripheral clock. + * @param RCC_AHBPeriph specifies the AHB peripheral to gates its clock. + * + * this parameter can be any combination of the following values: + * @arg RCC_AHB_PERIPH_DMA + * @arg RCC_AHB_PERIPH_SRAM + * @arg RCC_AHB_PERIPH_CRC + * @arg RCC_AHB_PERIPH_ADC + * + * @param Cmd new state of the specified peripheral clock. + * This parameter can be: ENABLE or DISABLE. + */ +void RCC_EnableAHBPeriphClk(uint32_t RCC_AHBPeriph, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + RCC->AHBPCLKEN |= RCC_AHBPeriph; + } + else + { + RCC->AHBPCLKEN &= ~RCC_AHBPeriph; + } +} + +/** + * @brief Enables or disables the High Speed APB (APB2) peripheral clock. + * @param RCC_APB2Periph specifies the APB2 peripheral to gates its clock. + * This parameter can be any combination of the following values: + * @arg RCC_APB2_PERIPH_AFIO, RCC_APB2_PERIPH_GPIOA, RCC_APB2_PERIPH_GPIOB, + * RCC_APB2_PERIPH_SPI1, RCC_APB2_PERIPH_SPI2, + * RCC_APB2_PERIPH_TIM1, + * RCC_APB2_PERIPH_USART1 + * @param Cmd new state of the specified peripheral clock. + * This parameter can be: ENABLE or DISABLE. + */ +void RCC_EnableAPB2PeriphClk(uint32_t RCC_APB2Periph, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + RCC->APB2PCLKEN |= RCC_APB2Periph; + } + else + { + RCC->APB2PCLKEN &= ~RCC_APB2Periph; + } +} + +/** + * @brief Enables or disables the Low Speed APB (APB1) peripheral clock. + * @param RCC_APB1Periph specifies the APB1 peripheral to gates its clock. + * This parameter can be any combination of the following values: + * @arg RCC_APB1_PERIPH_TIM3, + * RCC_APB1_PERIPH_TIM6, + * RCC_APB1_PERIPH_WWDG, + * RCC_APB1_PERIPH_USART2, + * RCC_APB1_PERIPH_I2C1, + * RCC_APB1_PERIPH_PWR + * @param Cmd new state of the specified peripheral clock. + * This parameter can be: ENABLE or DISABLE. + */ +void RCC_EnableAPB1PeriphClk(uint32_t RCC_APB1Periph, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + RCC->APB1PCLKEN |= RCC_APB1Periph; + } + else + { + RCC->APB1PCLKEN &= ~RCC_APB1Periph; + } +} + +/** + * @brief Forces or releases AHB peripheral reset. + * @param RCC_AHBPeriph specifies the AHB peripheral to reset. + * This parameter can be any combination of the following values: + * @arg RCC_AHB_PERIPH_ADC + * RCC_AHB_PERIPH_IRC + * @param Cmd new state of the specified peripheral reset. This parameter can be ENABLE or DISABLE. + */ +void RCC_EnableAHBPeriphReset(uint32_t RCC_AHBPeriph, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_RCC_AHB_PERIPH_RESET(RCC_AHBPeriph)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + RCC->AHBPRST |= RCC_AHBPeriph; + } + else + { + RCC->AHBPRST &= ~RCC_AHBPeriph; + } +} + +/** + * @brief Forces or releases High Speed APB (APB2) peripheral reset. + * @param RCC_APB2Periph specifies the APB2 peripheral to reset. + * This parameter can be any combination of the following values: + * @arg RCC_APB2_PERIPH_AFIO, RCC_APB2_PERIPH_GPIOA, RCC_APB2_PERIPH_GPIOB, + * RCC_APB2_PERIPH_SPI1, RCC_APB2_PERIPH_SPI2, + * RCC_APB2_PERIPH_TIM1, + * RCC_APB2_PERIPH_USART1 + * @param Cmd new state of the specified peripheral reset. + * This parameter can be: ENABLE or DISABLE. + */ +void RCC_EnableAPB2PeriphReset(uint32_t RCC_APB2Periph, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + RCC->APB2PRST |= RCC_APB2Periph; + } + else + { + RCC->APB2PRST &= ~RCC_APB2Periph; + } +} + +/** + * @brief Forces or releases Low Speed APB (APB1) peripheral reset. + * @param RCC_APB1Periph specifies the APB1 peripheral to reset. + * This parameter can be any combination of the following values: + * @arg RCC_APB1_PERIPH_TIM3, + * RCC_APB1_PERIPH_TIM6, + * RCC_APB1_PERIPH_USART2, + * RCC_APB1_PERIPH_I2C1, + * RCC_APB1_PERIPH_PWR + * @param Cmd new state of the specified peripheral clock. + * This parameter can be: ENABLE or DISABLE. + */ +void RCC_EnableAPB1PeriphReset(uint32_t RCC_APB1Periph, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_RCC_APB1_PERIPH_RESET(RCC_APB1Periph)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + RCC->APB1PRST |= RCC_APB1Periph; + } + else + { + RCC->APB1PRST &= ~RCC_APB1Periph; + } + +} + +/** + * @brief Selects the clock source to output on MCO pin. + * @param RCC_MCO specifies the clock source to output. + * + * this parameter can be one of the following values: + * @arg RCC_MCO_NOCLK No clock selected + * @arg RCC_MCO_SYSCLK System clock selected + * @arg RCC_MCO_HSI HSI oscillator clock selected + * @arg RCC_MCO_HSE HSE oscillator clock selected + * @arg RCC_MCO_PLLCLK_PRES PLL clock prescaler + * + */ +void RCC_ConfigMco(uint8_t RCC_MCO) +{ + uint32_t tmpregister = 0; + /* Check the parameters */ + assert_param(IS_RCC_MCO(RCC_MCO)); + + tmpregister = RCC->CFG; + /* Clear MCO[2:0] bits */ + tmpregister &= (~RCC_CFG_MCO); + /* Set MCO[2:0] bits according to RCC_MCO value */ + tmpregister |= ((uint32_t)(RCC_MCO << 25)); + + /* Store the new value */ + RCC->CFG = tmpregister; +} + +/** + * @brief Checks whether the specified RCC flag is set or not. + * @param RCC_FLAG specifies the flag to check. + * + * this parameter can be one of the following values: + * @arg RCC_CTRL_FLAG_HSIRDF HSI oscillator clock ready + * @arg RCC_CTRL_FLAG_HSERDF HSE oscillator clock ready + * @arg RCC_LSCTRL_FLAG_LSIRD LSI oscillator clock ready + * @arg RCC_LSCTRL_FLAG_LSERD LSE oscillator clock ready + * @arg RCC_CTRLSTS_FLAG_PINRSTF Pin reset + * @arg RCC_CTRLSTS_FLAG_PORRSTF POR reset + * @arg RCC_CTRLSTS_FLAG_SFTRSTF Software reset + * @arg RCC_CTRLSTS_FLAG_IWDGRSTF Independent Watchdog reset + * @arg RCC_CTRLSTS_FLAG_WWDGRSTF Window Watchdog reset + * + * @return The new state of RCC_FLAG (SET or RESET). + */ +FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG) +{ + uint32_t tmp = 0; + uint32_t statusreg = 0; + FlagStatus bitstatus = RESET; + /* Check the parameters */ + assert_param(IS_RCC_FLAG(RCC_FLAG)); + + /* Get the RCC register index */ + tmp = RCC_FLAG >> 5; + if (tmp == 1) /* The flag to check is in CTRL register */ + { + statusreg = RCC->CTRL; + } + else if (tmp == 2) /* The flag to check is in BDCTRL register */ + { + statusreg = RCC->LSCTRL; + } + else /* The flag to check is in CTRLSTS register */ + { + statusreg = RCC->CTRLSTS; + } + + /* Get the flag position */ + tmp = RCC_FLAG & RCC_FLAG_MASK; + if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + + /* Return the flag status */ + return bitstatus; +} + +/** + * @brief Clears the RCC reset flags. + * @note The reset flags are: RCC_CTRLSTS_FLAG_PINRSTF, RCC_CTRLSTS_FLAG_PORRSTF, + * RCC_CTRLSTS_FLAG_SFTRSTF, RCC_CTRLSTS_FLAG_IWDGRSTF, + * RCC_CTRLSTS_FLAG_WWDGRSTF + */ +void RCC_ClrFlag(void) +{ + /* Set RMVF bit to clear the reset flags */ + RCC->CTRLSTS |= RCC_CTRLSTS_RMRSTF; + /* RMVF bit should be reset */ + RCC->CTRLSTS &= ~RCC_CTRLSTS_RMRSTF; +} + +/** + * @brief Checks whether the specified RCC interrupt has occurred or not. + * @param RccInt specifies the RCC interrupt source to check. + * + * this parameter can be one of the following values: + * @arg RCC_INT_LSIRDIF LSI ready interrupt + * @arg RCC_INT_LSERDIF LSE ready interrupt + * @arg RCC_INT_HSIRDIF HSI ready interrupt + * @arg RCC_INT_HSERDIF HSE ready interrupt + * + * @return The new state of RccInt (SET or RESET). + */ +INTStatus RCC_GetIntStatus(uint8_t RccInt) +{ + INTStatus bitstatus = RESET; + /* Check the parameters */ + assert_param(IS_RCC_GET_INT(RccInt)); + + /* Check the status of the specified RCC interrupt */ + if ((RCC->CLKINT & RccInt) != (uint32_t)RESET) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + + /* Return the RccInt status */ + return bitstatus; +} + +/** + * @brief Clears the RCC's interrupt pending bits. + * @param RccInt specifies the interrupt pending bit to clear. + * + * this parameter can be any combination of the + * following values: + * @arg RCC_CLR_LSIRDIF Clear LSI ready interrupt flag + * @arg RCC_CLR_LSERDIF Clear LSE ready interrupt flag + * @arg RCC_CLR_HSIRDIF Clear HSI ready interrupt flag + * @arg RCC_CLR_HSERDIF Clear HSE ready interrupt flag + */ +void RCC_ClrIntPendingBit(uint32_t RccClrInt) +{ + /* Check the parameters */ + assert_param(IS_RCC_CLR_INTF(RccClrInt)); + /* Software set this bit to clear INT flag. */ + RCC->CLKINT |= RccClrInt; +} + +/** + * @brief Enables or disables the ADC clock source AUDIOPLL. + * @param This parameter can be: ENABLE or DISABLE. + */ +void RCC_Enable_ADC_CLK_SRC_AUDIOPLL(FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if(Cmd == ENABLE) + { + /* Set RAMCERRRST bit */ + RCC->CTRL |= RCC_CTRL_AUDIOPLLEN; + } + else + { + /* Reset RAMCERRRST bit */ + RCC->CTRL &= ~RCC_CTRL_AUDIOPLLEN; + } +} + +/** + * @brief Configures the specified peripheral and low power mode behavior + * when the MCU under Debug mode. + * @param DBG_Periph specifies the peripheral and low power mode. + * This parameter can be any combination of the following values: + * @arg DBG_IWDG_STOP Debug IWDG stopped when Core is halted + * @arg DBG_WWDG_STOP Debug WWDG stopped when Core is halted + * @arg DBG_TIM1_STOP TIM1 counter stopped when Core is halted + * @arg DBG_TIM3_STOP TIM3 counter stopped when Core is halted + * @arg DBG_I2C1SMBUS_TIMEOUT I2C1 SMBUS timeout mode stopped when Core is halted + * @arg DBG_TIM6_STOP TIM6 counter stopped when Core is halted + * @param Cmd new state of the specified peripheral in Debug mode. + * This parameter can be: ENABLE or DISABLE. + */ +void DBG_ConfigPeriph(uint32_t DBG_Periph, FunctionalState Cmd) +{ + + if (Cmd != DISABLE) + { + RCC->DBGMCU_CR |= DBG_Periph; + } + else + { + RCC->DBGMCU_CR &= ~DBG_Periph; + } +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_rtc.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_rtc.c new file mode 100644 index 0000000..ce3eb2c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_rtc.c @@ -0,0 +1,1691 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_rtc.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_rtc.h" +#include "n32wb03x_rcc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup RTC + * @brief RTC driver modules + * @{ + */ + +/* Masks Definition */ +#define RTC_TR_RESERVED_MASK ((uint32_t)0x007F7F7F) +#define RTC_DATE_RESERVED_MASK ((uint32_t)0x00FFFF3F) +#define RTC_INITM_MASK ((uint32_t)0xFFFFFF7F) +#define RTC_RSF_MASK ((uint32_t)0xFFFFFFDF) +#define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_WTF | RTC_FLAG_ALAF | RTC_FLAG_INITF | RTC_FLAG_RSYF \ +| RTC_FLAG_INITSF | RTC_FLAG_WTWF | RTC_FLAG_ALAWF | RTC_FLAG_RECPF | RTC_FLAG_SHOPF)) + +#define INITMODE_TIMEOUT ((uint32_t)0x00002000) +#define SYNCHRO_TIMEOUT ((uint32_t)0x00008000) +#define RECALPF_TIMEOUT ((uint32_t)0x00001000) +#define SHPF_TIMEOUT ((uint32_t)0x00002000) + +static uint8_t RTC_ByteToBcd2(uint8_t Value); +static uint8_t RTC_Bcd2ToByte(uint8_t Value); + +/** @addtogroup RTC_Private_Functions + * @{ + */ + +/** @addtogroup RTC_Group1 Initialization and Configuration functions + * @brief Initialization and Configuration functions + * +@verbatim + =============================================================================== + ##### Initialization and Configuration functions ##### + =============================================================================== + [..] This section provide functions allowing to initialize and configure the + RTC Prescaler (Synchronous and Asynchronous), RTC Hour format, disable + RTC registers Write protection, enter and exit the RTC initialization mode, + RTC registers synchronization check and reference clock detection enable. + (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base. + It is split into 2 programmable prescalers to minimize power consumption. + (++) A 7-bit asynchronous prescaler and A 13-bit synchronous prescaler. + (++) When both prescalers are used, it is recommended to configure the + asynchronous prescaler to a high value to minimize consumption. + (#) All RTC registers are Write protected. Writing to the RTC registers + is enabled by writing a key into the Write Protection register, RTC_WRP. + (#) To Configure the RTC Calendar, user application should enter + initialization mode. In this mode, the calendar counter is stopped + and its value can be updated. When the initialization sequence is + complete, the calendar restarts counting after 4 RTCCLK cycles. + (#) To read the calendar through the shadow registers after Calendar + initialization, calendar update or after wakeup from low power modes + the software must first clear the RSYF flag. The software must then + wait until it is set again before reading the calendar, which means + that the calendar registers have been correctly copied into the + RTC_TSH and RTC_DATE shadow registers.The RTC_WaitForSynchro() function + implements the above software sequence (RSYF clear and RSYF check). + +@endverbatim + * @{ + */ + +/** + * @brief Deinitializes the RTC registers to their default reset values. + * @note This function doesn't reset the RTC Clock source and RTC Backup Data + * registers. + * @return An ErrorStatus enumeration value: + * - SUCCESS: RTC registers are deinitialized + * - ERROR: RTC registers are not deinitialized + */ +ErrorStatus RTC_DeInit(void) +{ + __IO uint32_t wutcounter = 0x00; + uint32_t wutwfstatus = 0x00; + ErrorStatus status = ERROR; + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Set Initialization mode */ + if (RTC_EnterInitMode() == ERROR) + { + status = ERROR; + } + else + { + /* Reset TSH, DAT and CTRL registers */ + RTC->TSH = (uint32_t)0x00000000; + RTC->DATE = (uint32_t)0x00002101; + + /* Reset All CTRL bits except CTRL[2:0] and CTRL[7] lock bit*/ + RTC->CTRL &= (uint32_t)0x00000087; + + /* Wait till RTC WTWF flag is set and if Time out is reached exit */ + do + { + wutwfstatus = RTC->INITSTS & RTC_INITSTS_WTWF; + wutcounter++; + } while ((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00)); + + if ((RTC->INITSTS & RTC_INITSTS_WTWF) == RESET) + { + status = ERROR; + } + else + { + /* Reset all RTC CTRL register bits */ + RTC->CTRL &= (uint32_t)0x00000080; /* Bit CTRL[7] is a exception*/ + RTC->WKUPT = (uint32_t)0x0000FFFF; + RTC->PRE = (uint32_t)0x007F00FF; + RTC->ALARMA = (uint32_t)0x00000000; + RTC->SCTRL = (uint32_t)0x00000000; + RTC->CALIB = (uint32_t)0x00000000; + RTC->ALRMASS = (uint32_t)0x00000000; + + /* Reset INITSTS register and exit initialization mode */ + RTC->INITSTS &= (uint32_t)0x000000FF; + /* Exit Initialization mode */ + RTC_ExitInitMode(); + + /* Wait till the RTC RSYF flag is set */ + if (RTC_WaitForSynchro() == ERROR) + { + status = ERROR; + } + else + { + status = SUCCESS; + } + } + } + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); + + return status; +} + +/** + * @brief Initializes the RTC registers according to the specified parameters + * in RTC_InitStruct. + * @param RTC_InitStruct pointer to a RTC_InitType structure that contains + * the configuration information for the RTC peripheral. + * @note The RTC Prescaler register is write protected and can be written in + * initialization mode only. + * @return An ErrorStatus enumeration value: + * - SUCCESS: RTC registers are initialized + * - ERROR: RTC registers are not initialized + */ +ErrorStatus RTC_Init(RTC_InitType* RTC_InitStruct) +{ + ErrorStatus status = ERROR; + + /* Check the parameters */ + assert_param(IS_RTC_HOUR_FORMAT(RTC_InitStruct->RTC_HourFormat)); + assert_param(IS_RTC_PREDIV_ASYNCH(RTC_InitStruct->RTC_AsynchPrediv)); + assert_param(IS_RTC_PREDIV_SYNCH(RTC_InitStruct->RTC_SynchPrediv)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Set Initialization mode */ + if (RTC_EnterInitMode() == ERROR) + { + status = ERROR; + } + else + { + /* Clear RTC CTRL HFMT Bit */ + RTC->CTRL &= ((uint32_t) ~(RTC_CTRL_HFMT)); + /* Set RTC_CTRL register */ + RTC->CTRL |= ((uint32_t)(RTC_InitStruct->RTC_HourFormat)); + + /* Configure the RTC PRE */ + RTC->PRE = (uint32_t)(RTC_InitStruct->RTC_SynchPrediv); + RTC->PRE |= (uint32_t)(RTC_InitStruct->RTC_AsynchPrediv << 16); + + /* Exit Initialization mode */ + RTC_ExitInitMode(); + + status = SUCCESS; + } + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); + + return status; +} + +/** + * @brief Fills each RTC_InitStruct member with its default value. + * @param RTC_InitStruct pointer to a RTC_InitType structure which will be + * initialized. + */ +void RTC_StructInit(RTC_InitType* RTC_InitStruct) +{ + /* Initialize the RTC_HourFormat member */ + RTC_InitStruct->RTC_HourFormat = RTC_24HOUR_FORMAT; + + /* Initialize the RTC_AsynchPrediv member */ + RTC_InitStruct->RTC_AsynchPrediv = (uint32_t)0x7F; + + /* Initialize the RTC_SynchPrediv member */ + RTC_InitStruct->RTC_SynchPrediv = (uint32_t)0xFF; +} + +/** + * @brief Enables or disables the RTC registers write protection. + * @note All the RTC registers are write protected except for RTC_INITSTS[13:8]. + * @note Writing a wrong key reactivates the write protection. + * @note The protection mechanism is not affected by system reset. + * @param Cmd new state of the write protection. + * This parameter can be: ENABLE or DISABLE. + */ +void RTC_EnableWriteProtection(FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the write protection for RTC registers */ + RTC->CTRL&= 0xFFFFFF7F; + } + else + { + /* Disable the write protection for RTC registers */ + RTC->WRP = 0xCA; + RTC->WRP = 0x53; + RTC->CTRL|= 0x00000080; + } +} + +/** + * @brief Enters the RTC Initialization mode. + * @note The RTC Initialization mode is write protected, use the + * RTC_EnableWriteProtection(DISABLE) before calling this function. + * @return An ErrorStatus enumeration value: + * - SUCCESS: RTC is in Init mode + * - ERROR: RTC is not in Init mode + */ +ErrorStatus RTC_EnterInitMode(void) +{ + __IO uint32_t initcounter = 0x00; + ErrorStatus status = ERROR; + uint32_t initstatus = 0x00; + + /* Check if the Initialization mode is set */ + if ((RTC->INITSTS & RTC_INITSTS_INITF) == (uint32_t)RESET) + { + /* Set the Initialization mode */ + RTC->INITSTS |= (uint32_t)(~RTC_INITM_MASK) ; + + /* Wait till RTC is in INIT state and if Time out is reached exit */ + do + { + initstatus = RTC->INITSTS & RTC_INITSTS_INITF; + initcounter++; + } while ((initcounter != INITMODE_TIMEOUT) && (initstatus == 0x00)); + + if ((RTC->INITSTS & RTC_INITSTS_INITF) != RESET) + { + status = SUCCESS; + } + else + { + status = ERROR; + } + } + else + { + status = SUCCESS; + } + + return (status); +} + +/** + * @brief Exits the RTC Initialization mode. + * @note When the initialization sequence is complete, the calendar restarts + * counting after 4 RTCCLK cycles. + * @note The RTC Initialization mode is write protected, use the + * RTC_EnableWriteProtection(DISABLE) before calling this function. + */ +void RTC_ExitInitMode(void) +{ + /* Exit Initialization mode */ + RTC->INITSTS &= (uint32_t)~RTC_INITSTS_INITM; +} + +/** + * @brief Waits until the RTC Time and Date registers (RTC_TSH and RTC_DATE) are + * synchronized with RTC APB clock. + * @note The RTC Resynchronization mode is write protected, use the + * RTC_EnableWriteProtection(DISABLE) before calling this function. + * @note To read the calendar through the shadow registers after Calendar + * initialization, calendar update or after wakeup from low power modes + * the software must first clear the RSYF flag. + * The software must then wait until it is set again before reading + * the calendar, which means that the calendar registers have been + * correctly copied into the RTC_TSH and RTC_DATE shadow registers. + * @return An ErrorStatus enumeration value: + * - SUCCESS: RTC registers are synchronised + * - ERROR: RTC registers are not synchronised + */ +ErrorStatus RTC_WaitForSynchro(void) +{ + __IO uint32_t synchrocounter = 0; + ErrorStatus status = ERROR; + uint32_t synchrostatus = 0x00; + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Clear RSYF flag */ + RTC->INITSTS &= (uint32_t)RTC_RSF_MASK; + + /* Wait the registers to be synchronised */ + do + { + synchrostatus = RTC->INITSTS & RTC_INITSTS_RSYF; + synchrocounter++; + } while ((synchrocounter != SYNCHRO_TIMEOUT) && (synchrostatus == 0x00)); + + if ((RTC->INITSTS & RTC_INITSTS_RSYF) != RESET) + { + status = SUCCESS; + } + else + { + status = ERROR; + } + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); + + return (status); +} + +/** + * @brief Enables or Disables the Bypass Shadow feature. + * @note When the Bypass Shadow is enabled the calendar value are taken + * directly from the Calendar counter. + * @param Cmd new state of the Bypass Shadow feature. + * This parameter can be: ENABLE or DISABLE. + */ +void RTC_EnableBypassShadow(FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + if (Cmd != DISABLE) + { + /* Set the BYPS bit */ + RTC->CTRL |= (uint8_t)RTC_CTRL_BYPS; + } + else + { + /* Reset the BYPS bit */ + RTC->CTRL &= (uint8_t)~RTC_CTRL_BYPS; + } + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); +} + +/** + * @} + */ + +/** @addtogroup RTC_Group2 Time and Date configuration functions + * @brief Time and Date configuration functions + * +@verbatim + =============================================================================== + ##### Time and Date configuration functions ##### + =============================================================================== + [..] This section provide functions allowing to program and read the RTC + Calendar (Time and Date). + +@endverbatim + * @{ + */ + +/** + * @brief Set the RTC current time. + * @param RTC_Format specifies the format of the entered parameters. + * This parameter can be one of the following values: + * @arg RTC_FORMAT_BIN Binary data format. + * @arg RTC_FORMAT_BCD BCD data format. + * @param RTC_TimeStruct pointer to a RTC_TimeType structure that contains + * the time configuration information for the RTC. + * @return An ErrorStatus enumeration value: + * - SUCCESS: RTC Time register is configured + * - ERROR: RTC Time register is not configured + */ +ErrorStatus RTC_ConfigTime(uint32_t RTC_Format, RTC_TimeType* RTC_TimeStruct) +{ + uint32_t tmpregister = 0; + ErrorStatus status = ERROR; + + /* Check the parameters */ + assert_param(IS_RTC_FORMAT(RTC_Format)); + + if (RTC_Format == RTC_FORMAT_BIN) + { + if ((RTC->CTRL & RTC_CTRL_HFMT) != (uint32_t)RESET) + { + assert_param(IS_RTC_12HOUR(RTC_TimeStruct->Hours)); + assert_param(IS_RTC_H12(RTC_TimeStruct->H12)); + } + else + { + RTC_TimeStruct->H12 = 0x00; + assert_param(IS_RTC_24HOUR(RTC_TimeStruct->Hours)); + } + assert_param(IS_RTC_MINUTES(RTC_TimeStruct->Minutes)); + assert_param(IS_RTC_SECONDS(RTC_TimeStruct->Seconds)); + } + else + { + if ((RTC->CTRL & RTC_CTRL_HFMT) != (uint32_t)RESET) + { + tmpregister = RTC_Bcd2ToByte(RTC_TimeStruct->Hours); + assert_param(IS_RTC_12HOUR(tmpregister)); + assert_param(IS_RTC_H12(RTC_TimeStruct->H12)); + } + else + { + RTC_TimeStruct->H12 = 0x00; + assert_param(IS_RTC_24HOUR(RTC_Bcd2ToByte(RTC_TimeStruct->Hours))); + } + assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_TimeStruct->Minutes))); + assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_TimeStruct->Seconds))); + } + + /* Check the input parameters format */ + if (RTC_Format != RTC_FORMAT_BIN) + { + tmpregister = (((uint32_t)(RTC_TimeStruct->Hours) << 16) | ((uint32_t)(RTC_TimeStruct->Minutes) << 8) + | ((uint32_t)RTC_TimeStruct->Seconds) | ((uint32_t)(RTC_TimeStruct->H12) << 16)); + } + else + { + tmpregister = + (uint32_t)(((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->Hours) << 16) + | ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->Minutes) << 8) + | ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->Seconds)) | (((uint32_t)RTC_TimeStruct->H12) << 16)); + } + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Set Initialization mode */ + if (RTC_EnterInitMode() == ERROR) + { + status = ERROR; + } + else + { + /* Set the RTC_TSH register */ + RTC->TSH = (uint32_t)(tmpregister & RTC_TR_RESERVED_MASK); + + /* Exit Initialization mode */ + RTC_ExitInitMode(); + + /* If RTC_CTRL_BYPS bit = 0, wait for synchro else this check is not needed */ + if ((RTC->CTRL & RTC_CTRL_BYPS) == RESET) + { + if (RTC_WaitForSynchro() == ERROR) + { + status = ERROR; + } + else + { + status = SUCCESS; + } + } + else + { + status = SUCCESS; + } + } + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); + + return status; +} + +/** + * @brief Fills each RTC_TimeStruct member with its default value + * (Time = 00h:00min:00sec). + * @param RTC_TimeStruct pointer to a RTC_TimeType structure which will be + * initialized. + */ +void RTC_TimeStructInit(RTC_TimeType* RTC_TimeStruct) +{ + /* Time = 00h:00min:00sec */ + RTC_TimeStruct->H12 = RTC_AM_H12; + RTC_TimeStruct->Hours = 0; + RTC_TimeStruct->Minutes = 0; + RTC_TimeStruct->Seconds = 0; +} + +/** + * @brief Get the RTC current Time. + * @param RTC_Format specifies the format of the returned parameters. + * This parameter can be one of the following values: + * @arg RTC_FORMAT_BIN Binary data format. + * @arg RTC_FORMAT_BCD BCD data format. + * @param RTC_TimeStruct pointer to a RTC_TimeType structure that will + * contain the returned current time configuration. + */ +void RTC_GetTime(uint32_t RTC_Format, RTC_TimeType* RTC_TimeStruct) +{ + uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_RTC_FORMAT(RTC_Format)); + + /* Get the RTC_TSH register */ + tmpregister = (uint32_t)(RTC->TSH & RTC_TR_RESERVED_MASK); + + /* Fill the structure fields with the read parameters */ + RTC_TimeStruct->Hours = (uint8_t)((tmpregister & (RTC_TSH_HOT | RTC_TSH_HOU)) >> 16); + RTC_TimeStruct->Minutes = (uint8_t)((tmpregister & (RTC_TSH_MIT | RTC_TSH_MIU)) >> 8); + RTC_TimeStruct->Seconds = (uint8_t)(tmpregister & (RTC_TSH_SCT | RTC_TSH_SCU)); + RTC_TimeStruct->H12 = (uint8_t)((tmpregister & (RTC_TSH_APM)) >> 16); + + /* Check the input parameters format */ + if (RTC_Format == RTC_FORMAT_BIN) + { + /* Convert the structure parameters to Binary format */ + RTC_TimeStruct->Hours = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->Hours); + RTC_TimeStruct->Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->Minutes); + RTC_TimeStruct->Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->Seconds); + } +} + +/** + * @brief Gets the RTC current Calendar Subseconds value. + * @return RTC current Calendar Subseconds value. + */ +uint32_t RTC_GetSubSecond(void) +{ + uint32_t tmpregister = 0; + + /* Get subseconds values from the correspondent registers*/ + tmpregister = (uint32_t)(RTC->SUBS); + + /* Read DAT register to unfroze calendar registers */ + (void)(RTC->DATE); + + return (tmpregister); +} + +/** + * @brief Set the RTC current date. + * @param RTC_Format specifies the format of the entered parameters. + * This parameter can be one of the following values: + * @arg RTC_FORMAT_BIN Binary data format. + * @arg RTC_FORMAT_BCD BCD data format. + * @param RTC_DateStruct pointer to a RTC_DateType structure that contains + * the date configuration information for the RTC. + * @return An ErrorStatus enumeration value: + * - SUCCESS: RTC Date register is configured + * - ERROR: RTC Date register is not configured + */ +ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateType* RTC_DateStruct) +{ + uint32_t tmpregister = 0; + ErrorStatus status = ERROR; + + /* Check the parameters */ + assert_param(IS_RTC_FORMAT(RTC_Format)); + + if ((RTC_Format == RTC_FORMAT_BIN) && ((RTC_DateStruct->Month & 0x10) == 0x10)) + { + RTC_DateStruct->Month = (RTC_DateStruct->Month & (uint32_t) ~(0x10)) + 0x0A; + } + if (RTC_Format == RTC_FORMAT_BIN) + { + assert_param(IS_RTC_YEAR(RTC_DateStruct->Year)); + assert_param(IS_RTC_MONTH(RTC_DateStruct->Month)); + assert_param(IS_RTC_DATE(RTC_DateStruct->Date)); + } + else + { + assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(RTC_DateStruct->Year))); + tmpregister = RTC_Bcd2ToByte(RTC_DateStruct->Month); + assert_param(IS_RTC_MONTH(tmpregister)); + tmpregister = RTC_Bcd2ToByte(RTC_DateStruct->Date); + assert_param(IS_RTC_DATE(tmpregister)); + } + assert_param(IS_RTC_WEEKDAY(RTC_DateStruct->WeekDay)); + + /* Check the input parameters format */ + if (RTC_Format != RTC_FORMAT_BIN) + { + tmpregister = ((((uint32_t)RTC_DateStruct->Year) << 16) | (((uint32_t)RTC_DateStruct->Month) << 8) + | ((uint32_t)RTC_DateStruct->Date) | (((uint32_t)RTC_DateStruct->WeekDay) << 13)); + } + else + { + tmpregister = (((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->Year) << 16) + | ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->Month) << 8) + | ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->Date)) | ((uint32_t)RTC_DateStruct->WeekDay << 13)); + } + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Set Initialization mode */ + if (RTC_EnterInitMode() == ERROR) + { + status = ERROR; + } + else + { + /* Set the RTC_DATE register */ + RTC->DATE = (uint32_t)(tmpregister & RTC_DATE_RESERVED_MASK); + + /* Exit Initialization mode */ + RTC_ExitInitMode(); + + /* If RTC_CTRL_BYPS bit = 0, wait for synchro else this check is not needed */ + if ((RTC->CTRL & RTC_CTRL_BYPS) == RESET) + { + if (RTC_WaitForSynchro() == ERROR) + { + status = ERROR; + } + else + { + status = SUCCESS; + } + } + else + { + status = SUCCESS; + } + } + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); + + return status; +} + +/** + * @brief Fills each RTC_DateStruct member with its default value + * (Monday, January 01 xx00). + * @param RTC_DateStruct pointer to a RTC_DateType structure which will be + * initialized. + */ +void RTC_DateStructInit(RTC_DateType* RTC_DateStruct) +{ + /* Monday, January 01 xx00 */ + RTC_DateStruct->WeekDay = RTC_WEEKDAY_MONDAY; + RTC_DateStruct->Date = 1; + RTC_DateStruct->Month = RTC_MONTH_JANUARY; + RTC_DateStruct->Year = 0; +} + +/** + * @brief Get the RTC current date. + * @param RTC_Format specifies the format of the returned parameters. + * This parameter can be one of the following values: + * @arg RTC_FORMAT_BIN Binary data format. + * @arg RTC_FORMAT_BCD BCD data format. + * @param RTC_DateStruct pointer to a RTC_DateType structure that will + * contain the returned current date configuration. + */ +void RTC_GetDate(uint32_t RTC_Format, RTC_DateType* RTC_DateStruct) +{ + uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_RTC_FORMAT(RTC_Format)); + + /* Get the RTC_TSH register */ + tmpregister = (uint32_t)(RTC->DATE & RTC_DATE_RESERVED_MASK); + + /* Fill the structure fields with the read parameters */ + RTC_DateStruct->Year = (uint8_t)((tmpregister & (RTC_DATE_YRT | RTC_DATE_YRU)) >> 16); + RTC_DateStruct->Month = (uint8_t)((tmpregister & (RTC_DATE_MOT | RTC_DATE_MOU)) >> 8); + RTC_DateStruct->Date = (uint8_t)(tmpregister & (RTC_DATE_DAT | RTC_DATE_DAU)); + RTC_DateStruct->WeekDay = (uint8_t)((tmpregister & (RTC_DATE_WDU)) >> 13); + + /* Check the input parameters format */ + if (RTC_Format == RTC_FORMAT_BIN) + { + /* Convert the structure parameters to Binary format */ + RTC_DateStruct->Year = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->Year); + RTC_DateStruct->Month = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->Month); + RTC_DateStruct->Date = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->Date); + } +} + +/** + * @} + */ + +/** @addtogroup RTC_Group3 Alarms configuration functions + * @brief Alarms (Alarm A and Alarm B) configuration functions + * +@verbatim + =============================================================================== + ##### Alarms (Alarm A and Alarm B) configuration functions ##### + =============================================================================== + [..] This section provide functions allowing to program and read the RTC + Alarms. + +@endverbatim + * @{ + */ + +/** + * @brief Set the specified RTC Alarm. + * @note The Alarm register can only be written when the corresponding Alarm + * is disabled (Use the RTC_EnableAlarm(DISABLE)). + * @param RTC_Format specifies the format of the returned parameters. + * This parameter can be one of the following values: + * @arg RTC_FORMAT_BIN Binary data format. + * @arg RTC_FORMAT_BCD BCD data format. + * @param RTC_Alarm specifies the alarm to be configured. + * This parameter can only be the following values: + * @arg RTC_A_ALARM to select Alarm A. + * @param RTC_AlarmStruct pointer to a RTC_AlarmType structure that + * contains the alarm configuration parameters. + */ +void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmType* RTC_AlarmStruct) +{ + uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_RTC_FORMAT(RTC_Format)); + assert_param(IS_RTC_ALARM_SEL(RTC_Alarm)); + assert_param(IS_ALARM_MASK(RTC_AlarmStruct->AlarmMask)); + assert_param(IS_RTC_ALARM_WEEKDAY_SEL(RTC_AlarmStruct->DateWeekMode)); + + if (RTC_Format == RTC_FORMAT_BIN) + { + if ((RTC->CTRL & RTC_CTRL_HFMT) != (uint32_t)RESET) + { + assert_param(IS_RTC_12HOUR(RTC_AlarmStruct->AlarmTime.Hours)); + assert_param(IS_RTC_H12(RTC_AlarmStruct->AlarmTime.H12)); + } + else + { + RTC_AlarmStruct->AlarmTime.H12 = 0x00; + assert_param(IS_RTC_24HOUR(RTC_AlarmStruct->AlarmTime.Hours)); + } + assert_param(IS_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes)); + assert_param(IS_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds)); + + if (RTC_AlarmStruct->DateWeekMode == RTC_ALARM_SEL_WEEKDAY_DATE) + { + assert_param(IS_RTC_ALARM_WEEKDAY_DATE(RTC_AlarmStruct->DateWeekValue)); + } + else + { + assert_param(IS_RTC_ALARM_WEEKDAY_WEEKDAY(RTC_AlarmStruct->DateWeekValue)); + } + } + else + { + if ((RTC->CTRL & RTC_CTRL_HFMT) != (uint32_t)RESET) + { + tmpregister = RTC_Bcd2ToByte(RTC_AlarmStruct->AlarmTime.Hours); + assert_param(IS_RTC_12HOUR(tmpregister)); + assert_param(IS_RTC_H12(RTC_AlarmStruct->AlarmTime.H12)); + } + else + { + RTC_AlarmStruct->AlarmTime.H12 = 0x00; + assert_param(IS_RTC_24HOUR(RTC_Bcd2ToByte(RTC_AlarmStruct->AlarmTime.Hours))); + } + + assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_AlarmStruct->AlarmTime.Minutes))); + assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_AlarmStruct->AlarmTime.Seconds))); + + if (RTC_AlarmStruct->DateWeekMode == RTC_ALARM_SEL_WEEKDAY_DATE) + { + tmpregister = RTC_Bcd2ToByte(RTC_AlarmStruct->DateWeekValue); + assert_param(IS_RTC_ALARM_WEEKDAY_DATE(tmpregister)); + } + else + { + tmpregister = RTC_Bcd2ToByte(RTC_AlarmStruct->DateWeekValue); + assert_param(IS_RTC_ALARM_WEEKDAY_WEEKDAY(tmpregister)); + } + } + + /* Check the input parameters format */ + if (RTC_Format != RTC_FORMAT_BIN) + { + tmpregister = + (((uint32_t)(RTC_AlarmStruct->AlarmTime.Hours) << 16) + | ((uint32_t)(RTC_AlarmStruct->AlarmTime.Minutes) << 8) | ((uint32_t)RTC_AlarmStruct->AlarmTime.Seconds) + | ((uint32_t)(RTC_AlarmStruct->AlarmTime.H12) << 16) | ((uint32_t)(RTC_AlarmStruct->DateWeekValue) << 24) + | ((uint32_t)RTC_AlarmStruct->DateWeekMode) | ((uint32_t)RTC_AlarmStruct->AlarmMask)); + } + else + { + tmpregister = (((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->AlarmTime.Hours) << 16) + | ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->AlarmTime.Minutes) << 8) + | ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->AlarmTime.Seconds)) + | ((uint32_t)(RTC_AlarmStruct->AlarmTime.H12) << 16) + | ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->DateWeekValue) << 24) + | ((uint32_t)RTC_AlarmStruct->DateWeekMode) | ((uint32_t)RTC_AlarmStruct->AlarmMask)); + } + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Configure the Alarm register */ + if (RTC_Alarm == RTC_A_ALARM) + { + RTC->ALARMA = (uint32_t)tmpregister; + } + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); +} + +/** + * @brief Fills each RTC_AlarmStruct member with its default value + * (Time = 00h:00mn:00sec / Date = 1st day of the month/Mask = + * all fields are masked). + * @param RTC_AlarmStruct pointer to a @ref RTC_AlarmType structure which + * will be initialized. + */ +void RTC_AlarmStructInit(RTC_AlarmType* RTC_AlarmStruct) +{ + /* Alarm Time Settings : Time = 00h:00mn:00sec */ + RTC_AlarmStruct->AlarmTime.H12 = RTC_AM_H12; + RTC_AlarmStruct->AlarmTime.Hours = 0; + RTC_AlarmStruct->AlarmTime.Minutes = 0; + RTC_AlarmStruct->AlarmTime.Seconds = 0; + + /* Alarm Date Settings : Date = 1st day of the month */ + RTC_AlarmStruct->DateWeekMode = RTC_ALARM_SEL_WEEKDAY_DATE; + RTC_AlarmStruct->DateWeekValue = 1; + + /* Alarm Masks Settings : Mask = all fields are not masked */ + RTC_AlarmStruct->AlarmMask = RTC_ALARMMASK_NONE; +} + +/** + * @brief Get the RTC Alarm value and masks. + * @param RTC_Format specifies the format of the output parameters. + * This parameter can be one of the following values: + * @arg RTC_FORMAT_BIN Binary data format. + * @arg RTC_FORMAT_BCD BCD data format. + * @param RTC_Alarm specifies the alarm to be read. + * This parameter can be one of the following values: + * @arg RTC_A_ALARM to select Alarm A. + * @param RTC_AlarmStruct pointer to a RTC_AlarmType structure that will + * contains the output alarm configuration values. + */ +void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmType* RTC_AlarmStruct) +{ + uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_RTC_FORMAT(RTC_Format)); + assert_param(IS_RTC_ALARM_SEL(RTC_Alarm)); + + /* Get the RTC_ALARMx register */ + if (RTC_Alarm == RTC_A_ALARM) + { + tmpregister = (uint32_t)(RTC->ALARMA); + } + + /* Fill the structure with the read parameters */ + RTC_AlarmStruct->AlarmTime.Hours = (uint32_t)((tmpregister & (RTC_ALARMA_HOT | RTC_ALARMA_HOU)) >> 16); + RTC_AlarmStruct->AlarmTime.Minutes = (uint32_t)((tmpregister & (RTC_ALARMA_MIT | RTC_ALARMA_MIU)) >> 8); + RTC_AlarmStruct->AlarmTime.Seconds = (uint32_t)(tmpregister & (RTC_ALARMA_SET | RTC_ALARMA_SEU)); + RTC_AlarmStruct->AlarmTime.H12 = (uint32_t)((tmpregister & RTC_ALARMA_APM) >> 16); + RTC_AlarmStruct->DateWeekValue = (uint32_t)((tmpregister & (RTC_ALARMA_DTT | RTC_ALARMA_DTU)) >> 24); + RTC_AlarmStruct->DateWeekMode = (uint32_t)(tmpregister & RTC_ALARMA_WKDSEL); + RTC_AlarmStruct->AlarmMask = (uint32_t)(tmpregister & RTC_ALARMMASK_ALL); + + if (RTC_Format == RTC_FORMAT_BIN) + { + RTC_AlarmStruct->AlarmTime.Hours = RTC_Bcd2ToByte(RTC_AlarmStruct->AlarmTime.Hours); + RTC_AlarmStruct->AlarmTime.Minutes = RTC_Bcd2ToByte(RTC_AlarmStruct->AlarmTime.Minutes); + RTC_AlarmStruct->AlarmTime.Seconds = RTC_Bcd2ToByte(RTC_AlarmStruct->AlarmTime.Seconds); + RTC_AlarmStruct->DateWeekValue = RTC_Bcd2ToByte(RTC_AlarmStruct->DateWeekValue); + } +} + +/** + * @brief Enables or disables the specified RTC Alarm. + * @param RTC_Alarm specifies the alarm to be configured. + * This parameter can be any combination of the following values: + * @arg RTC_A_ALARM to select Alarm A. + * @param Cmd new state of the specified alarm. + * This parameter can be: ENABLE or DISABLE. + * @return An ErrorStatus enumeration value: + * - SUCCESS: RTC Alarm is enabled/disabled + * - ERROR: RTC Alarm is not enabled/disabled + */ +ErrorStatus RTC_EnableAlarm(uint32_t RTC_Alarm, FunctionalState Cmd) +{ + __IO uint32_t alarmcounter = 0x00; + uint32_t alarmstatus = 0x00; + ErrorStatus status = ERROR; + + /* Check the parameters */ + assert_param(IS_RTC_ALARM_ENABLE(RTC_Alarm)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Configure the Alarm state */ + if (Cmd != DISABLE) + { + RTC->CTRL |= (uint32_t)RTC_Alarm; + + status = SUCCESS; + } + else + { + /* Disable the Alarm in RTC_CTRL register */ + RTC->CTRL &= (uint32_t)~RTC_Alarm; + + /* Wait till RTC ALxWF flag is set and if Time out is reached exit */ + do + { + alarmstatus = RTC->INITSTS & (RTC_Alarm >> 8); + alarmcounter++; + } while ((alarmcounter != INITMODE_TIMEOUT) && (alarmstatus == 0x00)); + + if ((RTC->INITSTS & (RTC_Alarm >> 8)) == RESET) + { + status = ERROR; + } + else + { + status = SUCCESS; + } + } + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); + + return status; +} + +/** + * @brief Configure the RTC AlarmA Subseconds value and mask.* + * @note This function is performed only when the Alarm is disabled. + * @param RTC_Alarm specifies the alarm to be configured. + * This parameter can be one of the following values: + * @arg RTC_A_ALARM to select Alarm A. + + * @param RTC_AlarmSubSecondValue specifies the Subseconds value. + * This parameter can be a value from 0 to 0x00007FFF. + * @param RTC_AlarmSubSecondMask specifies the Subseconds Mask. + * This parameter can be any combination of the following values: + * @arg RTC_SUBS_MASK_ALL All Alarm SS fields are masked. + * There is no comparison on sub seconds for Alarm. + * @arg RTC_SUBS_MASK_SS14_1 SS[14:1] are don't care in Alarm comparison. + * Only SS[0] is compared + * @arg RTC_SUBS_MASK_SS14_2 SS[14:2] are don't care in Alarm comparison. + * Only SS[1:0] are compared + * @arg RTC_SUBS_MASK_SS14_3 SS[14:3] are don't care in Alarm comparison. + * Only SS[2:0] are compared + * @arg RTC_SUBS_MASK_SS14_4 SS[14:4] are don't care in Alarm comparison. + * Only SS[3:0] are compared + * @arg RTC_SUBS_MASK_SS14_5 SS[14:5] are don't care in Alarm comparison. + * Only SS[4:0] are compared. + * @arg RTC_SUBS_MASK_SS14_6 SS[14:6] are don't care in Alarm comparison. + * Only SS[5:0] are compared. + * @arg RTC_SUBS_MASK_SS14_7 SS[14:7] are don't care in Alarm comparison. + * Only SS[6:0] are compared. + * @arg RTC_SUBS_MASK_SS14_8 SS[14:8] are don't care in Alarm comparison. + * Only SS[7:0] are compared. + * @arg RTC_SUBS_MASK_SS14_9 SS[14:9] are don't care in Alarm comparison. + * Only SS[8:0] are compared. + * @arg RTC_SUBS_MASK_SS14_10 SS[14:10] are don't care in Alarm comparison. + * Only SS[9:0] are compared. + * @arg RTC_SUBS_MASK_SS14_11 SS[14:11] are don't care in Alarm comparison. + * Only SS[10:0] are compared. + * @arg RTC_SUBS_MASK_SS14_12 SS[14:12] are don't care in Alarm comparison. + * Only SS[11:0] are compared. + * @arg RTC_SUBS_MASK_SS14_13 SS[14:13] are don't care in Alarm comparison. + * Only SS[12:0] are compared. + * @arg RTC_SUBS_MASK_SS14_14 SS[14] is don't care in Alarm comparison. + * Only SS[13:0] are compared. + * @arg RTC_SUBS_MASK_NONE SS[14:0] are compared and must match + * to activate alarm. + */ +void RTC_ConfigAlarmSubSecond(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint32_t RTC_AlarmSubSecondMask) +{ + uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_RTC_ALARM_SEL(RTC_Alarm)); + assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(RTC_AlarmSubSecondValue)); + assert_param(IS_RTC_ALARM_SUB_SECOND_MASK_MODE(RTC_AlarmSubSecondMask)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Configure the Alarm A or Alarm B SubSecond registers */ + tmpregister = (uint32_t)(uint32_t)(RTC_AlarmSubSecondValue) | (uint32_t)(RTC_AlarmSubSecondMask); + + if (RTC_Alarm == RTC_A_ALARM) + { + /* Configure the AlarmA SubSecond register */ + RTC->ALRMASS = tmpregister; + } + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); +} + +/** + * @brief Gets the RTC Alarm Subseconds value. + * @param RTC_Alarm specifies the alarm to be read. + * This parameter can be one of the following values: + * @arg RTC_A_ALARM to select Alarm A. + * @return RTC Alarm Subseconds value. + */ +uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm) +{ + uint32_t tmpregister = 0; + + /* Get the RTC_ALARMx register */ + if (RTC_Alarm == RTC_A_ALARM) + { + tmpregister = (uint32_t)((RTC->ALRMASS) & RTC_ALRMASS_SSV); + } + + return (tmpregister); +} + +/** + * @} + */ + +/** @addtogroup RTC_Group4 WakeUp Timer configuration functions + * @brief WakeUp Timer configuration functions + * +@verbatim + =============================================================================== + ##### WakeUp Timer configuration functions ##### + =============================================================================== + [..] This section provide functions allowing to program and read the RTC WakeUp. + +@endverbatim + * @{ + */ + +/** + * @brief Configures the RTC Wakeup clock source. + * @note The WakeUp Clock source can only be changed when the RTC WakeUp + * is disabled (Use the RTC_EnableWakeUp(DISABLE)). + * @param RTC_WakeUpClock Wakeup Clock source. + * This parameter can be one of the following values: + * @arg RTC_WKUPCLK_RTCCLK_DIV16 RTC Wakeup Counter Clock = RTCCLK/16. + * @arg RTC_WKUPCLK_RTCCLK_DIV8 RTC Wakeup Counter Clock = RTCCLK/8. + * @arg RTC_WKUPCLK_RTCCLK_DIV4 RTC Wakeup Counter Clock = RTCCLK/4. + * @arg RTC_WKUPCLK_RTCCLK_DIV2 RTC Wakeup Counter Clock = RTCCLK/2. + * @arg RTC_WKUPCLK_CK_SPRE_16BITS RTC Wakeup Counter Clock = CK_SPRE. + * @arg RTC_WKUPCLK_CK_SPRE_17BITS RTC Wakeup Counter Clock = CK_SPRE. + */ +void RTC_ConfigWakeUpClock(uint32_t RTC_WakeUpClock) +{ + /* Check the parameters */ + assert_param(IS_RTC_WKUP_CLOCK(RTC_WakeUpClock)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Clear the Wakeup Timer clock source bits in CTRL register */ + RTC->CTRL &= (uint32_t)~RTC_CTRL_WKUPSEL; + + /* Configure the clock source */ + RTC->CTRL |= (uint32_t)RTC_WakeUpClock; + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); +} + +/** + * @brief Configures the RTC Wakeup counter. + * @note The RTC WakeUp counter can only be written when the RTC WakeUp. + * is disabled (Use the RTC_EnableWakeUp(DISABLE)). + * @param RTC_WakeUpCounter specifies the WakeUp counter. + * This parameter can be a value from 0x0000 to 0xFFFF. + */ +void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter) +{ + /* Check the parameters */ + assert_param(IS_RTC_WKUP_COUNTER(RTC_WakeUpCounter)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Configure the Wakeup Timer counter */ + RTC->WKUPT = (uint32_t)RTC_WakeUpCounter; + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); +} + +/** + * @brief Returns the RTC WakeUp timer counter value. + * @return The RTC WakeUp Counter value. + */ +uint32_t RTC_GetWakeUpCounter(void) +{ + /* Get the counter value */ + return ((uint32_t)(RTC->WKUPT & RTC_WKUPT_WKUPT)); +} + +/** + * @brief Enables or Disables the RTC WakeUp timer. + * @param Cmd new state of the WakeUp timer. + * This parameter can be: ENABLE or DISABLE. + */ +ErrorStatus RTC_EnableWakeUp(FunctionalState Cmd) +{ + __IO uint32_t wutcounter = 0x00; + uint32_t wutwfstatus = 0x00; + ErrorStatus status = ERROR; + + /* Check the parameters */ + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + if (Cmd != DISABLE) + { + /* Enable the Wakeup Timer */ + RTC->CTRL |= (uint32_t)RTC_CTRL_WTEN; + status = SUCCESS; + } + else + { + /* Disable the Wakeup Timer */ + RTC->CTRL &= (uint32_t)~RTC_CTRL_WTEN; + /* Wait till RTC WTWF flag is set and if Time out is reached exit */ + do + { + wutwfstatus = RTC->INITSTS & RTC_INITSTS_WTWF; + wutcounter++; + } while ((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00)); + + if ((RTC->INITSTS & RTC_INITSTS_WTWF) == RESET) + { + status = ERROR; + } + else + { + status = SUCCESS; + } + } + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); + + return status; +} + +/** + * @} + */ + +/** @addtogroup RTC_Group5 Daylight Saving configuration functions + * @brief Daylight Saving configuration functions + * +@verbatim + =============================================================================== + ##### Daylight Saving configuration functions ##### + =============================================================================== + [..] This section provide functions allowing to configure the RTC DayLight Saving. + +@endverbatim + * @{ + */ + +/** + * @brief Adds or substract one hour from the current time. + * @param RTC_DayLightSaving the value of hour adjustment. + * This parameter can be one of the following values: + * @arg RTC_DAYLIGHT_SAVING_SUB1H Substract one hour (winter time). + * @arg RTC_DAYLIGHT_SAVING_ADD1H Add one hour (summer time). + * @param RTC_StoreOperation Specifies the value to be written in the BCK bit + * in CTRL register to store the operation. + * This parameter can be one of the following values: + * @arg RTC_STORE_OPERATION_RESET BCK Bit Reset. + * @arg RTC_STORE_OPERATION_SET BCK Bit Set. + */ +void RTC_ConfigDayLightSaving(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation) +{ + /* Check the parameters */ + assert_param(IS_RTC_DAYLIGHT_SAVING(RTC_DayLightSaving)); + assert_param(IS_RTC_STORE_OPERATION(RTC_StoreOperation)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Clear the bits to be configured */ + RTC->CTRL &= (uint32_t) ~(RTC_CTRL_BAKP); + + /* Configure the RTC_CTRL register */ + RTC->CTRL |= (uint32_t)(RTC_DayLightSaving | RTC_StoreOperation); + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); +} + +/** + * @brief Returns the RTC Day Light Saving stored operation. + * @return RTC Day Light Saving stored operation. + * - RTC_STORE_OPERATION_RESET + * - RTC_STORE_OPERATION_SET + */ +uint32_t RTC_GetStoreOperation(void) +{ + return (RTC->CTRL & RTC_CTRL_BAKP); +} + +/** + * @} + */ + +/** @addtogroup RTC_Group6 Output pin Configuration function + * @brief Output pin Configuration function + * +@verbatim + =============================================================================== + ##### Output pin Configuration function ##### + =============================================================================== + [..] This section provide functions allowing to configure the RTC Output source. + +@endverbatim + * @{ + */ + +/** + * @} + */ + +/** @addtogroup RTC_Group7 Coarse and Smooth Calibrations configuration functions + * @brief Coarse and Smooth Calibrations configuration functions + * +@verbatim + =============================================================================== + ##### Coarse and Smooth Calibrations configuration functions ##### + =============================================================================== + +@endverbatim + * @{ + */ + +/** + * @brief Configures the Smooth Calibration Settings. + * @param RTC_SmoothCalibPeriod Select the Smooth Calibration Period. + * This parameter can be can be one of the following values: + * @arg SMOOTH_CALIB_32SEC The smooth calibration periode is 32s. + * @arg SMOOTH_CALIB_16SEC The smooth calibration periode is 16s. + * @arg SMOOTH_CALIB_8SEC The smooth calibartion periode is 8s. + * @param RTC_SmoothCalibPlusPulses Select to Set or reset the CALP bit. + * This parameter can be one of the following values: + * @arg RTC_SMOOTH_CALIB_PLUS_PULSES_SET Add one RTCCLK puls every 2**11 pulses. + * @arg RTC_SMOOTH_CALIB_PLUS_PULSES__RESET No RTCCLK pulses are added. + * @param RTC_SmouthCalibMinusPulsesValue Select the value of CALM[8:0] bits. + * This parameter can be any value from 0 to 0x000001FF. + * @return An ErrorStatus enumeration value: + * - SUCCESS: RTC Calib registers are configured + * - ERROR: RTC Calib registers are not configured + */ +ErrorStatus RTC_ConfigSmoothCalib(uint32_t RTC_SmoothCalibPeriod, + uint32_t RTC_SmoothCalibPlusPulses, + uint32_t RTC_SmouthCalibMinusPulsesValue) +{ + ErrorStatus status = ERROR; + uint32_t recalpfcount = 0; + + /* Check the parameters */ + assert_param(IS_RTC_SMOOTH_CALIB_PERIOD_SEL(RTC_SmoothCalibPeriod)); + assert_param(IS_RTC_SMOOTH_CALIB_PLUS(RTC_SmoothCalibPlusPulses)); + assert_param(IS_RTC_SMOOTH_CALIB_MINUS(RTC_SmouthCalibMinusPulsesValue)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* check if a calibration is pending*/ + if ((RTC->INITSTS & RTC_INITSTS_RECPF) != RESET) + { + /* wait until the Calibration is completed*/ + while (((RTC->INITSTS & RTC_INITSTS_RECPF) != RESET) && (recalpfcount != RECALPF_TIMEOUT)) + { + recalpfcount++; + } + } + + /* check if the calibration pending is completed or if there is no calibration operation at all*/ + if ((RTC->INITSTS & RTC_INITSTS_RECPF) == RESET) + { + /* Configure the Smooth calibration settings */ + RTC->CALIB = (uint32_t)((uint32_t)RTC_SmoothCalibPeriod | (uint32_t)RTC_SmoothCalibPlusPulses + | (uint32_t)RTC_SmouthCalibMinusPulsesValue); + + status = SUCCESS; + } + else + { + status = ERROR; + } + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); + + return (ErrorStatus)(status); +} + +/** + * @} + */ + + +/** + * @} + */ + +/** @addtogroup RTC_Group12 Shift control synchronisation functions + * @brief Shift control synchronisation functions + * +@verbatim + =============================================================================== + ##### Shift control synchronisation functions ##### + =============================================================================== + +@endverbatim + * @{ + */ + +/** + * @brief Configures the Synchronization Shift Control Settings. + * @note When REFCKON is set, firmware must not write to Shift control register + * @param RTC_ShiftAdd1S Select to add or not 1 second to the time Calendar. + * This parameter can be one of the following values : + * @arg RTC_SHIFT_ADD1S_ENABLE Add one second to the clock calendar. + * @arg RTC_SHIFT_ADD1S_DISABLE No effect. + * @param RTC_ShiftSubFS Select the number of Second Fractions to Substitute. + * This parameter can be one any value from 0 to 0x7FFF. + * @return An ErrorStatus enumeration value: + * - SUCCESS: RTC Shift registers are configured + * - ERROR: RTC Shift registers are not configured + */ +ErrorStatus RTC_ConfigSynchroShift(uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS) +{ + ErrorStatus status = ERROR; + uint32_t shpfcount = 0; + + /* Check the parameters */ + assert_param(IS_RTC_SHIFT_ADD1S(RTC_ShiftAdd1S)); + assert_param(IS_RTC_SHIFT_SUBFS(RTC_ShiftSubFS)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + /* Check if a Shift is pending*/ + if ((RTC->INITSTS & RTC_INITSTS_SHOPF) != RESET) + { + /* Wait until the shift is completed*/ + while (((RTC->INITSTS & RTC_INITSTS_SHOPF) != RESET) && (shpfcount != SHPF_TIMEOUT)) + { + shpfcount++; + } + } + + /* Check if the Shift pending is completed or if there is no Shift operation at all*/ + if ((RTC->INITSTS & RTC_INITSTS_SHOPF) == RESET) + { + /* Configure the Shift settings */ + RTC->SCTRL = (uint32_t)(uint32_t)(RTC_ShiftSubFS) | (uint32_t)(RTC_ShiftAdd1S); + + if (RTC_WaitForSynchro() == ERROR) + { + status = ERROR; + } + else + { + status = SUCCESS; + } + } + else + { + status = ERROR; + } + + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); + + return (ErrorStatus)(status); +} + +/** + * @} + */ + +/** @addtogroup RTC_Group13 Interrupts and flags management functions + * @brief Interrupts and flags management functions + * +@verbatim + =============================================================================== + ##### Interrupts and flags management functions ##### + =============================================================================== + [..] All RTC interrupts are connected to the EXTI controller. + (+) To enable the RTC Alarm interrupt, the following sequence is required: + (+) Configure and enable the EXTI Line 17 in interrupt mode and select + the rising edge sensitivity using the EXTI_InitPeripheral() function. + (+) Configure and enable the RTC_Alarm IRQ channel in the NVIC using + the NVIC_Init() function. + (+) Configure the RTC to generate RTC alarms (Alarm A and/or Alarm B) + using the RTC_SetAlarm() and RTC_EnableAlarm() functions. + + (+) To enable the RTC Wakeup interrupt, the following sequence is required: + (+) Configure and enable the EXTI Line 20 in interrupt mode and select + the rising edge sensitivity using the EXTI_InitPeripheral() function. + (+) Configure and enable the RTC_WKUP IRQ channel in the NVIC using the + NVIC_Init() function. + (+) Configure the RTC to generate the RTC wakeup timer event using the + RTC_ConfigWakeUpClock(), RTC_SetWakeUpCounter() and RTC_EnableWakeUp() + functions. + +@endverbatim + * @{ + */ + +/** + * @brief Enables or disables the specified RTC interrupts. + * @param RTC_INT specifies the RTC interrupt sources to be enabled or disabled. + * This parameter can be any combination of the following values: + * @arg RTC_INT_WUT WakeUp Timer interrupt mask. + * @arg RTC_INT_ALRA Alarm A interrupt mask. + * @param Cmd new state of the specified RTC interrupts. + * This parameter can be: ENABLE or DISABLE. + */ +void RTC_ConfigInt(uint32_t RTC_INT, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_RTC_CONFIG_INT(RTC_INT)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + /* Disable the write protection for RTC registers */ + RTC_EnableWriteProtection(DISABLE); + + if (Cmd != DISABLE) + { + /* Configure the Interrupts in the RTC_CTRL register */ + RTC->CTRL |= (uint32_t)RTC_INT; + } + else + { + /* Configure the Interrupts in the RTC_CTRL register */ + RTC->CTRL &= (uint32_t) ~(RTC_INT); + } + /* Enable the write protection for RTC registers */ + RTC_EnableWriteProtection(ENABLE); +} + +/** + * @brief Checks whether the specified RTC flag is set or not. + * @param RTC_FLAG specifies the flag to check. + * This parameter can be one of the following values: + * @arg RTC_FLAG_RECPF RECALPF event flag. + * @arg RTC_FLAG_WTF WakeUp Timer flag. + * @arg RTC_FLAG_ALAF Alarm A flag. + * @arg RTC_FLAG_INITF Initialization mode flag. + * @arg RTC_FLAG_RSYF Registers Synchronized flag. + * @arg RTC_FLAG_INITSF Registers Configured flag. + * @arg RTC_FLAG_SHOPF Shift operation pending flag. + * @arg RTC_FLAG_WTWF WakeUp Timer Write flag. + * @arg RTC_FLAG_ALAWF Alarm A write flag. + * @return The new state of RTC_FLAG (SET or RESET). + */ +FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG) +{ + FlagStatus bitstatus = RESET; + uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_RTC_GET_FLAG(RTC_FLAG)); + + /* Get all the flags */ + tmpregister = (uint32_t)(RTC->INITSTS & RTC_FLAGS_MASK); + + /* Return the status of the flag */ + if ((tmpregister & RTC_FLAG) != (uint32_t)RESET) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/** + * @brief Clears the RTC's pending flags. + * @param RTC_FLAG specifies the RTC flag to clear. + * This parameter can be any combination of the following values:. + * @arg RTC_FLAG_WTF WakeUp Timer flag. + * @arg RTC_FLAG_ALAF Alarm A flag. + * @arg RTC_FLAG_RSYF Registers Synchronized flag. + */ +void RTC_ClrFlag(uint32_t RTC_FLAG) +{ + /* Check the parameters */ + assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG)); + + /* Clear the Flags in the RTC_INITSTS register */ + RTC->INITSTS = (uint32_t)( + (uint32_t)(~((RTC_FLAG | RTC_INITSTS_INITM) & 0x0001FFFF) | (uint32_t)(RTC->INITSTS & RTC_INITSTS_INITM))); +} + +/** + * @brief Checks whether the specified RTC interrupt has occurred or not. + * @param RTC_INT specifies the RTC interrupt source to check. + * This parameter can be one of the following values: + * @arg RTC_INT_WUT WakeUp Timer interrupt. + * @arg RTC_INT_ALRA Alarm A interrupt. + * @return The new state of RTC_INT (SET or RESET). + */ +INTStatus RTC_GetITStatus(uint32_t RTC_INT) +{ + INTStatus bitstatus = RESET; + uint32_t tmpregister = 0, enablestatus = 0; + + /* Check the parameters */ + assert_param(IS_RTC_GET_INT(RTC_INT)); + + enablestatus = (uint32_t)((RTC->CTRL & RTC_INT)); + + /* Get the Interrupt pending bit */ + tmpregister = (uint32_t)((RTC->INITSTS & (uint32_t)(RTC_INT >> 4))); + + /* Get the status of the Interrupt */ + if ((enablestatus != (uint32_t)RESET) && ((tmpregister & 0x0000FFFF) != (uint32_t)RESET)) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/** + * @brief Clears the RTC's interrupt pending bits. + * @param RTC_INT specifies the RTC interrupt pending bit to clear. + * This parameter can be any combination of the following values: + * @arg RTC_INT_WUT WakeUp Timer interrupt + * @arg RTC_INT_ALRA Alarm A interrupt + */ +void RTC_ClrIntPendingBit(uint32_t RTC_INT) +{ + uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_RTC_CLEAR_INT(RTC_INT)); + + /* Get the RTC_INITSTS Interrupt pending bits mask */ + tmpregister = (uint32_t)(RTC_INT >> 4); + + /* Clear the interrupt pending bits in the RTC_INITSTS register */ + RTC->INITSTS = (uint32_t)( + (uint32_t)(~((tmpregister | RTC_INITSTS_INITM) & 0x0000FFFF) | (uint32_t)(RTC->INITSTS & RTC_INITSTS_INITM))); +} + +/** + * @} + */ + +/** + * @brief Converts a 2 digit decimal to BCD format. + * @param Value Byte to be converted. + * @return Converted byte + */ +static uint8_t RTC_ByteToBcd2(uint8_t Value) +{ + uint8_t bcdhigh = 0; + + while (Value >= 10) + { + bcdhigh++; + Value -= 10; + } + + return ((uint8_t)(bcdhigh << 4) | Value); +} + +/** + * @brief Convert from 2 digit BCD to Binary. + * @param Value BCD value to be converted. + * @return Converted word + */ +static uint8_t RTC_Bcd2ToByte(uint8_t Value) +{ + uint8_t tmp = 0; + tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10; + return (tmp + (Value & (uint8_t)0x0F)); +} + + + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_spi.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_spi.c new file mode 100644 index 0000000..fbf6861 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_spi.c @@ -0,0 +1,846 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_spi.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_spi.h" +#include "n32wb03x_rcc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup SPI + * @brief SPI driver modules + * @{ + */ + +/** @addtogroup SPI_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup SPI_Private_Defines + * @{ + */ + +/* SPI SPEN mask */ +#define CTRL1_SPIEN_ENABLE ((uint16_t)0x0040) +#define CTRL1_SPIEN_DISABLE ((uint16_t)0xFFBF) +/* I2S I2SEN mask */ +#define I2SCFG_I2SEN_ENABLE ((uint16_t)0x0400) +#define I2SCFG_I2SEN_DISABLE ((uint16_t)0xFBFF) + +/* SPI CRCNEXT mask */ +#define CTRL1_CRCNEXT_ENABLE ((uint16_t)0x1000) + +/* SPI CRCEN mask */ +#define CTRL1_CRCEN_ENABLE ((uint16_t)0x2000) +#define CTRL1_CRCEN_DISABLE ((uint16_t)0xDFFF) + +/* SPI SSOEN mask */ +#define CTRL2_SSOEN_ENABLE ((uint16_t)0x0004) +#define CTRL2_SSOEN_DISABLE ((uint16_t)0xFFFB) + +/* SPI registers Masks */ +#define CTRL1_CLR_MASK ((uint16_t)0x3040) +#define I2SCFG_CLR_MASK ((uint16_t)0xF040) + +/* SPI or I2S mode selection masks */ +#define SPI_MODE_ENABLE ((uint16_t)0xF7FF) +#define I2S_MODE_ENABLE ((uint16_t)0x0800) + +/* I2S clock source selection masks */ +#define I2S_MUL_MASK ((uint32_t)(0x0000F000)) +#define I2S_DIV_MASK ((uint32_t)(0x000000F0)) + +/** + * @} + */ + +/** @addtogroup SPI_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup SPI_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup SPI_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup SPI_Private_Functions + * @{ + */ + +/** + * @brief Deinitializes the SPIx peripheral registers to their default + * reset values. + * @param SPIx where x can be 1, 2 to select the SPI peripheral. + */ +void SPI_I2S_DeInit(SPI_Module* SPIx) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + + if (SPIx == SPI1) + { + /* Enable SPI1 reset state */ + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_SPI1, ENABLE); + /* Release SPI1 from reset state */ + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_SPI1, DISABLE); + } + else + { + /* Enable SPI2 reset state */ + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_SPI2, ENABLE); + /* Release SPI2 from reset state */ + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_SPI2, DISABLE); + } + +} + +/** + * @brief Initializes the SPIx peripheral according to the specified + * parameters in the SPI_InitStruct. + * @param SPIx where x can be 1, 2 to select the SPI peripheral. + * @param SPI_InitStruct pointer to a SPI_InitType structure that + * contains the configuration information for the specified SPI peripheral. + */ +void SPI_Init(SPI_Module* SPIx, SPI_InitType* SPI_InitStruct) +{ + uint16_t tmpregister = 0; + + /* check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + + /* Check the SPI parameters */ + assert_param(IS_SPI_DIR_MODE(SPI_InitStruct->DataDirection)); + assert_param(IS_SPI_MODE(SPI_InitStruct->SpiMode)); + assert_param(IS_SPI_DATASIZE(SPI_InitStruct->DataLen)); + assert_param(IS_SPI_CLKPOL(SPI_InitStruct->CLKPOL)); + assert_param(IS_SPI_CLKPHA(SPI_InitStruct->CLKPHA)); + assert_param(IS_SPI_NSS(SPI_InitStruct->NSS)); + assert_param(IS_SPI_BR_PRESCALER(SPI_InitStruct->BaudRatePres)); + assert_param(IS_SPI_FIRST_BIT(SPI_InitStruct->FirstBit)); + assert_param(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->CRCPoly)); + + /*---------------------------- SPIx CTRL1 Configuration ------------------------*/ + /* Get the SPIx CTRL1 value */ + tmpregister = SPIx->CTRL1; + /* Clear BIDIMode, BIDIOE, RxONLY, SSM, SSI, LSBFirst, BR, MSTR, CPOL and CPHA bits */ + tmpregister &= CTRL1_CLR_MASK; + /* Configure SPIx: direction, NSS management, first transmitted bit, BaudRate prescaler + master/salve mode, CPOL and CPHA */ + /* Set BIDImode, BIDIOE and RxONLY bits according to DataDirection value */ + /* Set SSM, SSI and MSTR bits according to SpiMode and NSS values */ + /* Set LSBFirst bit according to FirstBit value */ + /* Set BR bits according to BaudRatePres value */ + /* Set CPOL bit according to CLKPOL value */ + /* Set CPHA bit according to CLKPHA value */ + tmpregister |= (uint16_t)((uint32_t)SPI_InitStruct->DataDirection | SPI_InitStruct->SpiMode + | SPI_InitStruct->DataLen | SPI_InitStruct->CLKPOL | SPI_InitStruct->CLKPHA + | SPI_InitStruct->NSS | SPI_InitStruct->BaudRatePres | SPI_InitStruct->FirstBit); + /* Write to SPIx CTRL1 */ + SPIx->CTRL1 = tmpregister; + + /* Activate the SPI mode (Reset I2SMOD bit in I2SCFG register) */ + SPIx->I2SCFG &= SPI_MODE_ENABLE; + + /*---------------------------- SPIx CRCPOLY Configuration --------------------*/ + /* Write to SPIx CRCPOLY */ + SPIx->CRCPOLY = SPI_InitStruct->CRCPoly; +} + +/** + * @brief Initializes the SPIx peripheral according to the specified + * parameters in the I2S_InitStruct. + * @param SPIx where x can be 1 or 2 select the SPI peripheral + * (configured in I2S mode). + * @param I2S_InitStruct pointer to an I2S_InitType structure that + * contains the configuration information for the specified SPI peripheral + * configured in I2S mode. + * @note + * The function calculates the optimal prescaler needed to obtain the most + * accurate audio frequency (depending on the I2S clock source, the PLL values + * and the product configuration). But in case the prescaler value is greater + * than 511, the default value (0x02) will be configured instead. * + */ +void I2S_Init(SPI_Module* SPIx, I2S_InitType* I2S_InitStruct) +{ + uint16_t tmpregister = 0, i2sdiv = 2, i2sodd = 0, packetlength = 1; + uint32_t tmp = 0; + RCC_ClocksType RCC_Clocks; + uint32_t sourceclock = 0; + + /* Check the I2S parameters */ + assert_param(IS_SPI_I2S_PERIPH(SPIx)); + assert_param(IS_I2S_MODE(I2S_InitStruct->I2sMode)); + assert_param(IS_I2S_STANDARD(I2S_InitStruct->Standard)); + assert_param(IS_I2S_DATA_FMT(I2S_InitStruct->DataFormat)); + assert_param(IS_I2S_AUDIO_FREQ(I2S_InitStruct->AudioFrequency)); + assert_param(IS_I2S_CLKPOL(I2S_InitStruct->CLKPOL)); + + /*----------------------- SPIx I2SCFG & I2SPREDIV Configuration -----------------*/ + /* Clear MODSEL, I2SEN, MODCFG, PCMFSYNC, STDSEL, CKPOL, TDATLEN and CHBITS bits */ + SPIx->I2SCFG &= I2SCFG_CLR_MASK; + SPIx->I2SPREDIV = 0x0002; + + /* Get the I2SCFG register value */ + tmpregister = SPIx->I2SCFG; + + /* If the default value has to be written, reinitialize i2sdiv and i2sodd*/ + if (I2S_InitStruct->AudioFrequency == I2S_AUDIO_FREQ_DEFAULT) + { + i2sodd = (uint16_t)0; + i2sdiv = (uint16_t)2; + } + /* If the requested audio frequency is not the default, compute the prescaler */ + else + { + /* Check the frame length (For the Prescaler computing) */ + if (I2S_InitStruct->DataFormat == I2S_DATA_FMT_16BITS) + { + /* Packet length is 16 bits */ + packetlength = 1; + } + else + { + /* Packet length is 32 bits */ + packetlength = 2; + } + + /* I2S Clock source is System clock: Get System Clock frequency */ + RCC_GetClocksFreqValue(&RCC_Clocks); + + /* Get the source clock value: based on System Clock value */ + sourceclock = RCC_Clocks.SysclkFreq; + + /* Compute the Real divider with a floating point */ + tmp = (uint16_t)(((((sourceclock / (32 * packetlength)) * 10) / I2S_InitStruct->AudioFrequency)) + 5); + + /* Remove the floating point */ + tmp = tmp / 10; + + /* Check the parity of the divider */ + i2sodd = (uint16_t)(tmp & (uint16_t)0x0001); + + /* Compute the i2sdiv prescaler */ + i2sdiv = (uint16_t)((tmp - i2sodd) / 2); + + /* Get the Mask for the Odd bit (SPI_I2SPREDIV[8]) register */ + i2sodd = (uint16_t)(i2sodd << 8); + } + + /* Test if the divider is 1 or 0 or greater than 0xFF */ + if ((i2sdiv < 2) || (i2sdiv > 0xFF)) + { + /* Set the default values */ + i2sdiv = 2; + i2sodd = 0; + } + + /* Write to SPIx I2SPREDIV register the computed value */ + SPIx->I2SPREDIV = (uint16_t)(i2sdiv | (uint16_t)(i2sodd)); + + /* Configure the I2S with the SPI_InitStruct values */ + tmpregister |= (uint16_t)( + I2S_MODE_ENABLE + | (uint16_t)(I2S_InitStruct->I2sMode + | (uint16_t)(I2S_InitStruct->Standard + | (uint16_t)(I2S_InitStruct->DataFormat | (uint16_t)I2S_InitStruct->CLKPOL)))); + + /* Write to SPIx I2SCFG */ + SPIx->I2SCFG = tmpregister; +} + +/** + * @brief Fills each SPI_InitStruct member with its default value. + * @param SPI_InitStruct pointer to a SPI_InitType structure which will be initialized. + */ +void SPI_InitStruct(SPI_InitType* SPI_InitStruct) +{ + /*--------------- Reset SPI init structure parameters values -----------------*/ + /* Initialize the DataDirection member */ + SPI_InitStruct->DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX; + /* initialize the SpiMode member */ + SPI_InitStruct->SpiMode = SPI_MODE_SLAVE; + /* initialize the DataLen member */ + SPI_InitStruct->DataLen = SPI_DATA_SIZE_8BITS; + /* Initialize the CLKPOL member */ + SPI_InitStruct->CLKPOL = SPI_CLKPOL_LOW; + /* Initialize the CLKPHA member */ + SPI_InitStruct->CLKPHA = SPI_CLKPHA_FIRST_EDGE; + /* Initialize the NSS member */ + SPI_InitStruct->NSS = SPI_NSS_HARD; + /* Initialize the BaudRatePres member */ + SPI_InitStruct->BaudRatePres = SPI_BR_PRESCALER_2; + /* Initialize the FirstBit member */ + SPI_InitStruct->FirstBit = SPI_FB_MSB; + /* Initialize the CRCPoly member */ + SPI_InitStruct->CRCPoly = 7; +} + +/** + * @brief Fills each I2S_InitStruct member with its default value. + * @param I2S_InitStruct pointer to a I2S_InitType structure which will be initialized. + */ +void I2S_InitStruct(I2S_InitType* I2S_InitStruct) +{ + /*--------------- Reset I2S init structure parameters values -----------------*/ + /* Initialize the I2sMode member */ + I2S_InitStruct->I2sMode = I2S_MODE_SlAVE_TX; + + /* Initialize the Standard member */ + I2S_InitStruct->Standard = I2S_STD_PHILLIPS; + + /* Initialize the DataFormat member */ + I2S_InitStruct->DataFormat = I2S_DATA_FMT_16BITS; + + /* Initialize the AudioFrequency member */ + I2S_InitStruct->AudioFrequency = I2S_AUDIO_FREQ_DEFAULT; + + /* Initialize the CLKPOL member */ + I2S_InitStruct->CLKPOL = I2S_CLKPOL_LOW; +} + +/** + * @brief Enables or disables the specified SPI peripheral. + * @param SPIx where x can be 1 or 2 to select the SPI peripheral. + * @param Cmd new state of the SPIx peripheral. + * This parameter can be: ENABLE or DISABLE. + */ +void SPI_Enable(SPI_Module* SPIx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected SPI peripheral */ + SPIx->CTRL1 |= CTRL1_SPIEN_ENABLE; + } + else + { + /* Disable the selected SPI peripheral */ + SPIx->CTRL1 &= CTRL1_SPIEN_DISABLE; + } +} + +/** + * @brief Enables or disables the specified SPI peripheral (in I2S mode). + * @param SPIx where x can be 1 or 2 to select the SPI peripheral. + * @param Cmd new state of the SPIx peripheral. + * This parameter can be: ENABLE or DISABLE. + */ +void I2S_Enable(SPI_Module* SPIx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_SPI_I2S_PERIPH(SPIx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected SPI peripheral (in I2S mode) */ + SPIx->I2SCFG |= I2SCFG_I2SEN_ENABLE; + } + else + { + /* Disable the selected SPI peripheral (in I2S mode) */ + SPIx->I2SCFG &= I2SCFG_I2SEN_DISABLE; + } +} + +/** + * @brief Enables or disables the specified SPI/I2S interrupts. + * @param SPIx where x can be + * - 1, 2 in SPI mode + * - 1, 2 in I2S mode + * @param SPI_I2S_IT specifies the SPI/I2S interrupt source to be enabled or disabled. + * This parameter can be one of the following values: + * @arg SPI_I2S_INT_TE Tx buffer empty interrupt mask + * @arg SPI_I2S_INT_RNE Rx buffer not empty interrupt mask + * @arg SPI_I2S_INT_ERR Error interrupt mask + * @param Cmd new state of the specified SPI/I2S interrupt. + * This parameter can be: ENABLE or DISABLE. + */ +void SPI_I2S_EnableInt(SPI_Module* SPIx, uint8_t SPI_I2S_IT, FunctionalState Cmd) +{ + uint16_t itpos = 0, itmask = 0; + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + assert_param(IS_SPI_I2S_CONFIG_INT(SPI_I2S_IT)); + + /* Get the SPI/I2S IT index */ + itpos = SPI_I2S_IT >> 4; + + /* Set the IT mask */ + itmask = (uint16_t)1 << (uint16_t)itpos; + + if (Cmd != DISABLE) + { + /* Enable the selected SPI/I2S interrupt */ + SPIx->CTRL2 |= itmask; + } + else + { + /* Disable the selected SPI/I2S interrupt */ + SPIx->CTRL2 &= (uint16_t)~itmask; + } +} + +/** + * @brief Enables or disables the SPIx/I2Sx DMA interface. + * @param SPIx where x can be + * - 1, 2 in SPI mode + * - 1, 2 in I2S mode + * @param SPI_I2S_DMAReq specifies the SPI/I2S DMA transfer request to be enabled or disabled. + * This parameter can be any combination of the following values: + * @arg SPI_I2S_DMA_TX Tx buffer DMA transfer request + * @arg SPI_I2S_DMA_RX Rx buffer DMA transfer request + * @param Cmd new state of the selected SPI/I2S DMA transfer request. + * This parameter can be: ENABLE or DISABLE. + */ +void SPI_I2S_EnableDma(SPI_Module* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + assert_param(IS_SPI_I2S_DMA(SPI_I2S_DMAReq)); + if (Cmd != DISABLE) + { + /* Enable the selected SPI/I2S DMA requests */ + SPIx->CTRL2 |= SPI_I2S_DMAReq; + } + else + { + /* Disable the selected SPI/I2S DMA requests */ + SPIx->CTRL2 &= (uint16_t)~SPI_I2S_DMAReq; + } +} + +/** + * @brief Transmits a Data through the SPIx/I2Sx peripheral. + * @param SPIx where x can be + * - 1, 2 in SPI mode + * - 1, 2 in I2S mode + * @param Data Data to be transmitted. + */ +void SPI_I2S_TransmitData(SPI_Module* SPIx, uint16_t Data) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + + /* Write in the DAT register the data to be sent */ + SPIx->DAT = Data; +} + +/** + * @brief Returns the most recent received data by the SPIx/I2Sx peripheral. + * @param SPIx where x can be + * - 1, 2 in SPI mode + * - 1, 2 in I2S mode + * @return The value of the received data. + */ +uint16_t SPI_I2S_ReceiveData(SPI_Module* SPIx) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + + /* Return the data in the DAT register */ + return SPIx->DAT; +} + +/** + * @brief Configures internally by software the NSS pin for the selected SPI. + * @param SPIx where x can be 1, 2 to select the SPI peripheral. + * @param SPI_NSSInternalSoft specifies the SPI NSS internal state. + * This parameter can be one of the following values: + * @arg SPI_NSS_HIGH Set NSS pin internally + * @arg SPI_NSS_LOW Reset NSS pin internally + */ +void SPI_SetNssLevel(SPI_Module* SPIx, uint16_t SPI_NSSInternalSoft) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_SPI_NSS_LEVEL(SPI_NSSInternalSoft)); + if (SPI_NSSInternalSoft != SPI_NSS_LOW) + { + /* Set NSS pin internally by software */ + SPIx->CTRL1 |= SPI_NSS_HIGH; + } + else + { + /* Reset NSS pin internally by software */ + SPIx->CTRL1 &= SPI_NSS_LOW; + } +} + +/** + * @brief Enables or disables the SS output for the selected SPI. + * @param SPIx where x can be 1, 2 to select the SPI peripheral. + * @param Cmd new state of the SPIx SS output. + * This parameter can be: ENABLE or DISABLE. + */ +void SPI_SSOutputEnable(SPI_Module* SPIx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected SPI SS output */ + SPIx->CTRL2 |= CTRL2_SSOEN_ENABLE; + } + else + { + /* Disable the selected SPI SS output */ + SPIx->CTRL2 &= CTRL2_SSOEN_DISABLE; + } +} + +/** + * @brief Configures the data size for the selected SPI. + * @param SPIx where x can be 1, 2 to select the SPI peripheral. + * @param DataLen specifies the SPI data size. + * This parameter can be one of the following values: + * @arg SPI_DATA_SIZE_16BITS Set data frame format to 16bit + * @arg SPI_DATA_SIZE_8BITS Set data frame format to 8bit + */ +void SPI_ConfigDataLen(SPI_Module* SPIx, uint16_t DataLen) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_SPI_DATASIZE(DataLen)); + /* Clear DFF bit */ + SPIx->CTRL1 &= (uint16_t)~SPI_DATA_SIZE_16BITS; + /* Set new DFF bit value */ + SPIx->CTRL1 |= DataLen; +} + +/** + * @brief Transmit the SPIx CRC value. + * @param SPIx where x can be 1, 2 to select the SPI peripheral. + */ +void SPI_TransmitCrcNext(SPI_Module* SPIx) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + + /* Enable the selected SPI CRC transmission */ + SPIx->CTRL1 |= CTRL1_CRCNEXT_ENABLE; +} + +/** + * @brief Enables or disables the CRC value calculation of the transferred bytes. + * @param SPIx where x can be 1, 2 to select the SPI peripheral. + * @param Cmd new state of the SPIx CRC value calculation. + * This parameter can be: ENABLE or DISABLE. + */ +void SPI_EnableCalculateCrc(SPI_Module* SPIx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the selected SPI CRC calculation */ + SPIx->CTRL1 |= CTRL1_CRCEN_ENABLE; + } + else + { + /* Disable the selected SPI CRC calculation */ + SPIx->CTRL1 &= CTRL1_CRCEN_DISABLE; + } +} + +/** + * @brief Returns the transmit or the receive CRC register value for the specified SPI. + * @param SPIx where x can be 1, 2 to select the SPI peripheral. + * @param SPI_CRC specifies the CRC register to be read. + * This parameter can be one of the following values: + * @arg SPI_CRC_TX Selects Tx CRC register + * @arg SPI_CRC_RX Selects Rx CRC register + * @return The selected CRC register value.. + */ +uint16_t SPI_GetCRCDat(SPI_Module* SPIx, uint8_t SPI_CRC) +{ + uint16_t crcreg = 0; + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_SPI_CRC(SPI_CRC)); + if (SPI_CRC != SPI_CRC_RX) + { + /* Get the Tx CRC register */ + crcreg = SPIx->CRCTDAT; + } + else + { + /* Get the Rx CRC register */ + crcreg = SPIx->CRCRDAT; + } + /* Return the selected CRC register */ + return crcreg; +} + +/** + * @brief Returns the CRC Polynomial register value for the specified SPI. + * @param SPIx where x can be 1, 2 to select the SPI peripheral. + * @return The CRC Polynomial register value. + */ +uint16_t SPI_GetCRCPoly(SPI_Module* SPIx) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + + /* Return the CRC polynomial register */ + return SPIx->CRCPOLY; +} + +/** + * @brief Selects the data transfer direction in bi-directional mode for the specified SPI. + * @param SPIx where x can be 1, 2 to select the SPI peripheral. + * @param DataDirection specifies the data transfer direction in bi-directional mode. + * This parameter can be one of the following values: + * @arg SPI_BIDIRECTION_TX Selects Tx transmission direction + * @arg SPI_BIDIRECTION_RX Selects Rx receive direction + */ +void SPI_ConfigBidirectionalMode(SPI_Module* SPIx, uint16_t DataDirection) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_SPI_BIDIRECTION(DataDirection)); + if (DataDirection == SPI_BIDIRECTION_TX) + { + /* Set the Tx only mode */ + SPIx->CTRL1 |= SPI_BIDIRECTION_TX; + } + else + { + /* Set the Rx only mode */ + SPIx->CTRL1 &= SPI_BIDIRECTION_RX; + } +} + +/** + * @brief Checks whether the specified SPI/I2S flag is set or not. + * @param SPIx where x can be + * - 1 or 2 in SPI mode + * - 1 or 2 in I2S mode + * @param SPI_I2S_FLAG specifies the SPI/I2S flag to check. + * This parameter can be one of the following values: + * @arg SPI_I2S_TE_FLAG Transmit buffer empty flag. + * @arg SPI_I2S_RNE_FLAG Receive buffer not empty flag. + * @arg SPI_I2S_BUSY_FLAG Busy flag. + * @arg SPI_I2S_OVER_FLAG Overrun flag. + * @arg SPI_MODERR_FLAG Mode Fault flag. + * @arg SPI_CRCERR_FLAG CRC Error flag. + * @arg I2S_UNDER_FLAG Underrun Error flag. + * @arg I2S_CHSIDE_FLAG Channel Side flag. + * @return The new state of SPI_I2S_FLAG (SET or RESET). + */ +FlagStatus SPI_I2S_GetStatus(SPI_Module* SPIx, uint16_t SPI_I2S_FLAG) +{ + FlagStatus bitstatus = RESET; + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_SPI_I2S_GET_FLAG(SPI_I2S_FLAG)); + /* Check the status of the specified SPI/I2S flag */ + if ((SPIx->STS & SPI_I2S_FLAG) != (uint16_t)RESET) + { + /* SPI_I2S_FLAG is set */ + bitstatus = SET; + } + else + { + /* SPI_I2S_FLAG is reset */ + bitstatus = RESET; + } + /* Return the SPI_I2S_FLAG status */ + return bitstatus; +} + +/** + * @brief Clears the SPIx CRC Error (CRCERR) flag. + * @param SPIx where x can be + * - 1, 2 in SPI mode + * @param SPI_I2S_FLAG specifies the SPI flag to clear. + * This function clears only CRCERR flag. + * @note + * - OVER (OverRun error) flag is cleared by software sequence: a read + * operation to SPI_DAT register (SPI_I2S_ReceiveData()) followed by a read + * operation to SPI_STS register (SPI_I2S_GetStatus()). + * - UNDER (UnderRun error) flag is cleared by a read operation to + * SPI_STS register (SPI_I2S_GetStatus()). + * - MODERR (Mode Fault) flag is cleared by software sequence: a read/write + * operation to SPI_STS register (SPI_I2S_GetStatus()) followed by a + * write operation to SPI_CTRL1 register (SPI_Enable() to enable the SPI). + */ +void SPI_I2S_ClrCRCErrFlag(SPI_Module* SPIx, uint16_t SPI_I2S_FLAG) +{ + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_SPI_I2S_CLR_FLAG(SPI_I2S_FLAG)); + + /* Clear the selected SPI CRC Error (CRCERR) flag */ + SPIx->STS = (uint16_t)~SPI_I2S_FLAG; +} + +/** + * @brief Checks whether the specified SPI/I2S interrupt has occurred or not. + * @param SPIx where x can be + * - 1, 2 in SPI mode + * - 1, 2 in I2S mode + * @param SPI_I2S_IT specifies the SPI/I2S interrupt source to check. + * This parameter can be one of the following values: + * @arg SPI_I2S_INT_TE Transmit buffer empty interrupt. + * @arg SPI_I2S_INT_RNE Receive buffer not empty interrupt. + * @arg SPI_I2S_INT_OVER Overrun interrupt. + * @arg SPI_INT_MODERR Mode Fault interrupt. + * @arg SPI_INT_CRCERR CRC Error interrupt. + * @arg I2S_INT_UNDER Underrun Error interrupt. + * @return The new state of SPI_I2S_IT (SET or RESET). + */ +INTStatus SPI_I2S_GetIntStatus(SPI_Module* SPIx, uint8_t SPI_I2S_IT) +{ + INTStatus bitstatus = RESET; + uint16_t itpos = 0, itmask = 0, enablestatus = 0; + + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_SPI_I2S_GET_INT(SPI_I2S_IT)); + + /* Get the SPI/I2S IT index */ + itpos = 0x01 << (SPI_I2S_IT & 0x0F); + + /* Get the SPI/I2S IT mask */ + itmask = SPI_I2S_IT >> 4; + + /* Set the IT mask */ + itmask = 0x01 << itmask; + + /* Get the SPI_I2S_IT enable bit status */ + enablestatus = (SPIx->CTRL2 & itmask); + + /* Check the status of the specified SPI/I2S interrupt */ + if (((SPIx->STS & itpos) != (uint16_t)RESET) && enablestatus) + { + /* SPI_I2S_IT is set */ + bitstatus = SET; + } + else + { + /* SPI_I2S_IT is reset */ + bitstatus = RESET; + } + /* Return the SPI_I2S_IT status */ + return bitstatus; +} + +/** + * @brief Clears the SPIx CRC Error (CRCERR) interrupt pending bit. + * @param SPIx where x can be + * - 1, 2 in SPI mode + * @param SPI_I2S_IT specifies the SPI interrupt pending bit to clear. + * This function clears only CRCERR interrupt pending bit. + * @note + * - OVER (OverRun Error) interrupt pending bit is cleared by software + * sequence: a read operation to SPI_DAT register (SPI_I2S_ReceiveData()) + * followed by a read operation to SPI_STS register (SPI_I2S_GetIntStatus()). + * - UNDER (UnderRun Error) interrupt pending bit is cleared by a read + * operation to SPI_STS register (SPI_I2S_GetIntStatus()). + * - MODERR (Mode Fault) interrupt pending bit is cleared by software sequence: + * a read/write operation to SPI_STS register (SPI_I2S_GetIntStatus()) + * followed by a write operation to SPI_CTRL1 register (SPI_Enable() to enable + * the SPI). + */ +void SPI_I2S_ClrITPendingBit(SPI_Module* SPIx, uint8_t SPI_I2S_IT) +{ + uint16_t itpos = 0; + /* Check the parameters */ + assert_param(IS_SPI_PERIPH(SPIx)); + assert_param(IS_SPI_I2S_CLR_INT(SPI_I2S_IT)); + + /* Get the SPI IT index */ + itpos = 0x01 << (SPI_I2S_IT & 0x0F); + + /* Clear the selected SPI CRC Error (CRCERR) interrupt pending bit */ + SPIx->STS = (uint16_t)~itpos; +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_tim.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_tim.c new file mode 100644 index 0000000..61a3714 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_tim.c @@ -0,0 +1,2818 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_tim.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_tim.h" +#include "n32wb03x_rcc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup TIM + * @brief TIM driver modules + * @{ + */ + +/** @addtogroup TIM_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup TIM_Private_Defines + * @{ + */ + +/* ---------------------- TIM registers bit mask ------------------------ */ +#define SMCTRL_ETR_MASK ((uint16_t)0x00FF) +#define CAPCMPMOD_OFFSET ((uint16_t)0x0018) +#define CAPCMPEN_CCE_SET ((uint16_t)0x0001) +#define CAPCMPEN_CCNE_SET ((uint16_t)0x0004) + +/** + * @} + */ + +/** @addtogroup TIM_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup TIM_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup TIM_Private_FunctionPrototypes + * @{ + */ + +static void ConfigTI1(TIM_Module* TIMx, uint16_t IcPolarity, uint16_t IcSelection, uint16_t IcFilter); +static void ConfigTI2(TIM_Module* TIMx, uint16_t IcPolarity, uint16_t IcSelection, uint16_t IcFilter); +static void ConfigTI3(TIM_Module* TIMx, uint16_t IcPolarity, uint16_t IcSelection, uint16_t IcFilter); +static void ConfigTI4(TIM_Module* TIMx, uint16_t IcPolarity, uint16_t IcSelection, uint16_t IcFilter); +/** + * @} + */ + +/** @addtogroup TIM_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup TIM_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup TIM_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup TIM_Private_Functions + * @{ + */ + +/** + * @brief Deinitializes the TIMx peripheral registers to their default reset values. + * @param TIMx where x can be 1 3 6 to select the TIM peripheral. + */ +void TIM_DeInit(TIM_Module* TIMx) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + + if (TIMx == TIM1) + { + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_TIM1, ENABLE); + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_TIM1, DISABLE); + } + else if (TIMx == TIM3) + { + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_TIM3, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_TIM3, DISABLE); + } + else if (TIMx == TIM6) + { + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_TIM6, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_TIM6, DISABLE); + } +} + +/** + * @brief Initializes the TIMx Time Base Unit peripheral according to + * the specified parameters in the TIM_TimeBaseInitStruct. + * @param TIMx where x can be 1 3 6 to select the TIM peripheral. + * @param TIM_TimeBaseInitStruct pointer to a TIM_TimeBaseInitType + * structure that contains the configuration information for the + * specified TIM peripheral. + */ +void TIM_InitTimeBase(TIM_Module* TIMx, TIM_TimeBaseInitType* TIM_TimeBaseInitStruct) +{ + uint32_t tmpcr1 = 0; + + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IsTimCntMode(TIM_TimeBaseInitStruct->CntMode)); + assert_param(IsTimClkDiv(TIM_TimeBaseInitStruct->ClkDiv)); + + tmpcr1 = TIMx->CTRL1; + + if ((TIMx == TIM1) || (TIMx == TIM3)) + { + /* Select the Counter Mode */ + tmpcr1 &= (uint32_t)(~((uint32_t)(TIM_CTRL1_DIR | TIM_CTRL1_CAMSEL))); + tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->CntMode; + } + + if (TIMx != TIM6) + { + /* Set the clock division */ + tmpcr1 &= (uint32_t)(~((uint32_t)TIM_CTRL1_CLKD)); + tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->ClkDiv; + } + + TIMx->CTRL1 = tmpcr1; + + /* Set the Autoreload value */ + TIMx->AR = TIM_TimeBaseInitStruct->Period; + + /* Set the Prescaler value */ + TIMx->PSC = TIM_TimeBaseInitStruct->Prescaler; + + if (TIMx == TIM1) + { + /* Set the Repetition Counter value */ + TIMx->REPCNT = TIM_TimeBaseInitStruct->RepetCnt; + } + + /* Generate an update event to reload the Prescaler and the Repetition counter + values immediately */ + TIMx->EVTGEN = TIM_PSC_RELOAD_MODE_IMMEDIATE; + + /*channel input from comp or iom*/ + tmpcr1 = TIMx->CTRL1; + if ((TIMx == TIM1)|| (TIMx == TIM3)) + { + if (TIM_TimeBaseInitStruct->CapCh1FromCompEn) + tmpcr1 |= (0x01L << 11); + else + tmpcr1 &= ~(0x01L << 11); + } + if (TIMx == TIM3) + { + if (TIM_TimeBaseInitStruct->CapCh2FromCompEn) + tmpcr1 |= (0x01L << 12); + else + tmpcr1 &= ~(0x01L << 12); + if (TIM_TimeBaseInitStruct->CapCh3FromCompEn) + tmpcr1 |= (0x01L << 13); + else + tmpcr1 &= ~(0x01L << 13); + } + /*etr input from comp or iom*/ + if ((TIMx == TIM1) || (TIMx == TIM3)) + { + if (TIM_TimeBaseInitStruct->CapEtrClrFromCompEn) + tmpcr1 |= (0x01L << 15); + else + tmpcr1 &= ~(0x01L << 15); + } + TIMx->CTRL1 = tmpcr1; + /*sel etr from iom or tsc*/ + tmpcr1 = TIMx->CTRL2; + + TIMx->CTRL2 = tmpcr1; +} + +/** + * @brief Initializes the TIMx Channel1 according to the specified + * parameters in the TIM_OCInitStruct. + * @param TIMx where x can be 1 3 to select the TIM peripheral. + * @param TIM_OCInitStruct pointer to a OCInitType structure + * that contains the configuration information for the specified TIM peripheral. + */ +void TIM_InitOc1(TIM_Module* TIMx, OCInitType* TIM_OCInitStruct) +{ + uint16_t tmpccmrx = 0; + uint32_t tmpccer = 0, tmpcr2 = 0; + + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + assert_param(IsTimOcMode(TIM_OCInitStruct->OcMode)); + assert_param(IsTimOutputState(TIM_OCInitStruct->OutputState)); + assert_param(IsTimOcPolarity(TIM_OCInitStruct->OcPolarity)); + /* Disable the Channel 1: Reset the CC1E Bit */ + TIMx->CCEN &= (uint32_t)(~(uint32_t)TIM_CCEN_CC1EN); + /* Get the TIMx CCEN register value */ + tmpccer = TIMx->CCEN; + /* Get the TIMx CTRL2 register value */ + tmpcr2 = TIMx->CTRL2; + + /* Get the TIMx CCMOD1 register value */ + tmpccmrx = TIMx->CCMOD1; + + /* Reset the Output Compare Mode Bits */ + tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMOD1_OC1M)); + tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMOD1_CC1SEL)); + + /* Select the Output Compare Mode */ + tmpccmrx |= TIM_OCInitStruct->OcMode; + + /* Reset the Output Polarity level */ + tmpccer &= (uint32_t)(~((uint32_t)TIM_CCEN_CC1P)); + /* Set the Output Compare Polarity */ + tmpccer |= TIM_OCInitStruct->OcPolarity; + + /* Set the Output State */ + tmpccer |= TIM_OCInitStruct->OutputState; + + if (TIMx == TIM1) + { + assert_param(IsTimOutputNState(TIM_OCInitStruct->OutputNState)); + assert_param(IsTimOcnPolarity(TIM_OCInitStruct->OcNPolarity)); + assert_param(IsTimOcnIdleState(TIM_OCInitStruct->OcNIdleState)); + assert_param(IsTimOcIdleState(TIM_OCInitStruct->OcIdleState)); + + /* Reset the Output N Polarity level */ + tmpccer &= (uint32_t)(~((uint32_t)TIM_CCEN_CC1NP)); + /* Set the Output N Polarity */ + tmpccer |= TIM_OCInitStruct->OcNPolarity; + + /* Reset the Output N State */ + tmpccer &= (uint32_t)(~((uint32_t)TIM_CCEN_CC1NEN)); + /* Set the Output N State */ + tmpccer |= TIM_OCInitStruct->OutputNState; + + /* Reset the Output Compare and Output Compare N IDLE State */ + tmpcr2 &= (uint32_t)(~((uint32_t)TIM_CTRL2_OI1)); + tmpcr2 &= (uint32_t)(~((uint32_t)TIM_CTRL2_OI1N)); + + /* Set the Output Idle state */ + tmpcr2 |= TIM_OCInitStruct->OcIdleState; + /* Set the Output N Idle state */ + tmpcr2 |= TIM_OCInitStruct->OcNIdleState; + } + /* Write to TIMx CTRL2 */ + TIMx->CTRL2 = tmpcr2; + + /* Write to TIMx CCMOD1 */ + TIMx->CCMOD1 = tmpccmrx; + + /* Set the Capture Compare Register value */ + TIMx->CCDAT1 = TIM_OCInitStruct->Pulse; + + /* Write to TIMx CCEN */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Initializes the TIMx Channel2 according to the specified + * parameters in the TIM_OCInitStruct. + * @param TIMx where x can be 1 3 to select + * the TIM peripheral. + * @param TIM_OCInitStruct pointer to a OCInitType structure + * that contains the configuration information for the specified TIM peripheral. + */ +void TIM_InitOc2(TIM_Module* TIMx, OCInitType* TIM_OCInitStruct) +{ + uint16_t tmpccmrx = 0; + uint32_t tmpccer = 0, tmpcr2 = 0; + + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimOcMode(TIM_OCInitStruct->OcMode)); + assert_param(IsTimOutputState(TIM_OCInitStruct->OutputState)); + assert_param(IsTimOcPolarity(TIM_OCInitStruct->OcPolarity)); + /* Disable the Channel 2: Reset the CC2E Bit */ + TIMx->CCEN &= (uint32_t)(~((uint32_t)TIM_CCEN_CC2EN)); + + /* Get the TIMx CCEN register value */ + tmpccer = TIMx->CCEN; + /* Get the TIMx CTRL2 register value */ + tmpcr2 = TIMx->CTRL2; + + /* Get the TIMx CCMOD1 register value */ + tmpccmrx = TIMx->CCMOD1; + + /* Reset the Output Compare mode and Capture/Compare selection Bits */ + tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMOD1_OC2M)); + tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMOD1_CC2SEL)); + + /* Select the Output Compare Mode */ + tmpccmrx |= (uint16_t)(TIM_OCInitStruct->OcMode << 8); + + /* Reset the Output Polarity level */ + tmpccer &= (uint32_t)(~((uint32_t)TIM_CCEN_CC2P)); + /* Set the Output Compare Polarity */ + tmpccer |= (uint32_t)(TIM_OCInitStruct->OcPolarity << 4); + + /* Set the Output State */ + tmpccer |= (uint32_t)(TIM_OCInitStruct->OutputState << 4); + + if (TIMx == TIM1) + { + assert_param(IsTimOutputNState(TIM_OCInitStruct->OutputNState)); + assert_param(IsTimOcnPolarity(TIM_OCInitStruct->OcNPolarity)); + assert_param(IsTimOcnIdleState(TIM_OCInitStruct->OcNIdleState)); + assert_param(IsTimOcIdleState(TIM_OCInitStruct->OcIdleState)); + + /* Reset the Output N Polarity level */ + tmpccer &= (uint32_t)(~((uint32_t)TIM_CCEN_CC2NP)); + /* Set the Output N Polarity */ + tmpccer |= (uint32_t)(TIM_OCInitStruct->OcNPolarity << 4); + + /* Reset the Output N State */ + tmpccer &= (uint32_t)(~((uint16_t)TIM_CCEN_CC2NEN)); + /* Set the Output N State */ + tmpccer |= (uint32_t)(TIM_OCInitStruct->OutputNState << 4); + + /* Reset the Output Compare and Output Compare N IDLE State */ + tmpcr2 &= (uint32_t)(~((uint32_t)TIM_CTRL2_OI2)); + tmpcr2 &= (uint32_t)(~((uint32_t)TIM_CTRL2_OI2N)); + + /* Set the Output Idle state */ + tmpcr2 |= (uint32_t)(TIM_OCInitStruct->OcIdleState << 2); + /* Set the Output N Idle state */ + tmpcr2 |= (uint32_t)(TIM_OCInitStruct->OcNIdleState << 2); + } + /* Write to TIMx CTRL2 */ + TIMx->CTRL2 = tmpcr2; + + /* Write to TIMx CCMOD1 */ + TIMx->CCMOD1 = tmpccmrx; + + /* Set the Capture Compare Register value */ + TIMx->CCDAT2 = TIM_OCInitStruct->Pulse; + + /* Write to TIMx CCEN */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Initializes the TIMx Channel3 according to the specified + * parameters in the TIM_OCInitStruct. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCInitStruct pointer to a OCInitType structure + * that contains the configuration information for the specified TIM peripheral. + */ +void TIM_InitOc3(TIM_Module* TIMx, OCInitType* TIM_OCInitStruct) +{ + uint16_t tmpccmrx = 0; + uint32_t tmpccer = 0, tmpcr2 = 0; + + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcMode(TIM_OCInitStruct->OcMode)); + assert_param(IsTimOutputState(TIM_OCInitStruct->OutputState)); + assert_param(IsTimOcPolarity(TIM_OCInitStruct->OcPolarity)); + /* Disable the Channel 2: Reset the CC2E Bit */ + TIMx->CCEN &= (uint32_t)(~((uint32_t)TIM_CCEN_CC3EN)); + + /* Get the TIMx CCEN register value */ + tmpccer = TIMx->CCEN; + /* Get the TIMx CTRL2 register value */ + tmpcr2 = TIMx->CTRL2; + + /* Get the TIMx CCMOD2 register value */ + tmpccmrx = TIMx->CCMOD2; + + /* Reset the Output Compare mode and Capture/Compare selection Bits */ + tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMOD2_OC3MD)); + tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMOD2_CC3SEL)); + /* Select the Output Compare Mode */ + tmpccmrx |= TIM_OCInitStruct->OcMode; + + /* Reset the Output Polarity level */ + tmpccer &= (uint32_t)(~((uint16_t)TIM_CCEN_CC3P)); + /* Set the Output Compare Polarity */ + tmpccer |= (uint32_t)(TIM_OCInitStruct->OcPolarity << 8); + + /* Set the Output State */ + tmpccer |= (uint32_t)(TIM_OCInitStruct->OutputState << 8); + + if (TIMx == TIM1) + { + assert_param(IsTimOutputNState(TIM_OCInitStruct->OutputNState)); + assert_param(IsTimOcnPolarity(TIM_OCInitStruct->OcNPolarity)); + assert_param(IsTimOcnIdleState(TIM_OCInitStruct->OcNIdleState)); + assert_param(IsTimOcIdleState(TIM_OCInitStruct->OcIdleState)); + + /* Reset the Output N Polarity level */ + tmpccer &= (uint32_t)(~((uint32_t)TIM_CCEN_CC3NP)); + /* Set the Output N Polarity */ + tmpccer |= (uint32_t)(TIM_OCInitStruct->OcNPolarity << 8); + /* Reset the Output N State */ + tmpccer &= (uint32_t)(~((uint32_t)TIM_CCEN_CC3NEN)); + + /* Set the Output N State */ + tmpccer |= (uint32_t)(TIM_OCInitStruct->OutputNState << 8); + /* Reset the Output Compare and Output Compare N IDLE State */ + tmpcr2 &= (uint32_t)(~((uint32_t)TIM_CTRL2_OI3)); + tmpcr2 &= (uint32_t)(~((uint32_t)TIM_CTRL2_OI3N)); + /* Set the Output Idle state */ + tmpcr2 |= (uint32_t)(TIM_OCInitStruct->OcIdleState << 4); + /* Set the Output N Idle state */ + tmpcr2 |= (uint32_t)(TIM_OCInitStruct->OcNIdleState << 4); + } + /* Write to TIMx CTRL2 */ + TIMx->CTRL2 = tmpcr2; + + /* Write to TIMx CCMOD2 */ + TIMx->CCMOD2 = tmpccmrx; + + /* Set the Capture Compare Register value */ + TIMx->CCDAT3 = TIM_OCInitStruct->Pulse; + + /* Write to TIMx CCEN */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Initializes the TIMx Channel4 according to the specified + * parameters in the TIM_OCInitStruct. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCInitStruct pointer to a OCInitType structure + * that contains the configuration information for the specified TIM peripheral. + */ +void TIM_InitOc4(TIM_Module* TIMx, OCInitType* TIM_OCInitStruct) +{ + uint16_t tmpccmrx = 0; + uint32_t tmpccer = 0, tmpcr2 = 0; + + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcMode(TIM_OCInitStruct->OcMode)); + assert_param(IsTimOutputState(TIM_OCInitStruct->OutputState)); + assert_param(IsTimOcPolarity(TIM_OCInitStruct->OcPolarity)); + /* Disable the Channel 2: Reset the CC4E Bit */ + TIMx->CCEN &= (uint32_t)(~((uint32_t)TIM_CCEN_CC4EN)); + + /* Get the TIMx CCEN register value */ + tmpccer = TIMx->CCEN; + /* Get the TIMx CTRL2 register value */ + tmpcr2 = TIMx->CTRL2; + + /* Get the TIMx CCMOD2 register value */ + tmpccmrx = TIMx->CCMOD2; + + /* Reset the Output Compare mode and Capture/Compare selection Bits */ + tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMOD2_OC4MD)); + tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMOD2_CC4SEL)); + + /* Select the Output Compare Mode */ + tmpccmrx |= (uint16_t)(TIM_OCInitStruct->OcMode << 8); + + /* Reset the Output Polarity level */ + tmpccer &= (uint32_t)(~((uint32_t)TIM_CCEN_CC4P)); + /* Set the Output Compare Polarity */ + tmpccer |= (uint32_t)(TIM_OCInitStruct->OcPolarity << 12); + + /* Set the Output State */ + tmpccer |= (uint32_t)(TIM_OCInitStruct->OutputState << 12); + + if (TIMx == TIM1) + { + assert_param(IsTimOcIdleState(TIM_OCInitStruct->OcIdleState)); + /* Reset the Output Compare IDLE State */ + tmpcr2 &= (uint32_t)(~((uint32_t)TIM_CTRL2_OI4)); + /* Set the Output Idle state */ + tmpcr2 |= (uint32_t)(TIM_OCInitStruct->OcIdleState << 6); + } + /* Write to TIMx CTRL2 */ + TIMx->CTRL2 = tmpcr2; + + /* Write to TIMx CCMOD2 */ + TIMx->CCMOD2 = tmpccmrx; + + /* Set the Capture Compare Register value */ + TIMx->CCDAT4 = TIM_OCInitStruct->Pulse; + + /* Write to TIMx CCEN */ + TIMx->CCEN = tmpccer; +} + + +/** + * @brief Initializes the TIM peripheral according to the specified + * parameters in the TIM_ICInitStruct. + * @param TIMx where x can be 1 3 to select the TIM peripheral. + * @param TIM_ICInitStruct pointer to a TIM_ICInitType structure + * that contains the configuration information for the specified TIM peripheral. + */ +void TIM_ICInit(TIM_Module* TIMx, TIM_ICInitType* TIM_ICInitStruct) +{ + /* Check the parameters */ + assert_param(IsTimCh(TIM_ICInitStruct->Channel)); + assert_param(IsTimIcSelection(TIM_ICInitStruct->IcSelection)); + assert_param(IsTimIcPrescaler(TIM_ICInitStruct->IcPrescaler)); + assert_param(IsTimInCapFilter(TIM_ICInitStruct->IcFilter)); + + if ((TIMx == TIM1) || (TIMx == TIM3)) + { + assert_param(IsTimIcPalaritySingleEdge(TIM_ICInitStruct->IcPolarity)); + } + else + { + assert_param(IsTimIcPolarityAnyEdge(TIM_ICInitStruct->IcPolarity)); + } + if (TIM_ICInitStruct->Channel == TIM_CH_1) + { + assert_param(IsTimList8Module(TIMx)); + /* TI1 Configuration */ + ConfigTI1(TIMx, TIM_ICInitStruct->IcPolarity, TIM_ICInitStruct->IcSelection, TIM_ICInitStruct->IcFilter); + /* Set the Input Capture Prescaler value */ + TIM_SetInCap1Prescaler(TIMx, TIM_ICInitStruct->IcPrescaler); + } + else if (TIM_ICInitStruct->Channel == TIM_CH_2) + { + assert_param(IsTimList6Module(TIMx)); + /* TI2 Configuration */ + ConfigTI2(TIMx, TIM_ICInitStruct->IcPolarity, TIM_ICInitStruct->IcSelection, TIM_ICInitStruct->IcFilter); + /* Set the Input Capture Prescaler value */ + TIM_SetInCap2Prescaler(TIMx, TIM_ICInitStruct->IcPrescaler); + } + else if (TIM_ICInitStruct->Channel == TIM_CH_3) + { + assert_param(IsTimList3Module(TIMx)); + /* TI3 Configuration */ + ConfigTI3(TIMx, TIM_ICInitStruct->IcPolarity, TIM_ICInitStruct->IcSelection, TIM_ICInitStruct->IcFilter); + /* Set the Input Capture Prescaler value */ + TIM_SetInCap3Prescaler(TIMx, TIM_ICInitStruct->IcPrescaler); + } + else + { + assert_param(IsTimList3Module(TIMx)); + /* TI4 Configuration */ + ConfigTI4(TIMx, TIM_ICInitStruct->IcPolarity, TIM_ICInitStruct->IcSelection, TIM_ICInitStruct->IcFilter); + /* Set the Input Capture Prescaler value */ + TIM_SetInCap4Prescaler(TIMx, TIM_ICInitStruct->IcPrescaler); + } +} + +/** + * @brief Configures the TIM peripheral according to the specified + * parameters in the TIM_ICInitStruct to measure an external PWM signal. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ICInitStruct pointer to a TIM_ICInitType structure + * that contains the configuration information for the specified TIM peripheral. + */ +void TIM_ConfigPwmIc(TIM_Module* TIMx, TIM_ICInitType* TIM_ICInitStruct) +{ + uint16_t icoppositepolarity = TIM_IC_POLARITY_RISING; + uint16_t icoppositeselection = TIM_IC_SELECTION_DIRECTTI; + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + /* Select the Opposite Input Polarity */ + if (TIM_ICInitStruct->IcPolarity == TIM_IC_POLARITY_RISING) + { + icoppositepolarity = TIM_IC_POLARITY_FALLING; + } + else + { + icoppositepolarity = TIM_IC_POLARITY_RISING; + } + /* Select the Opposite Input */ + if (TIM_ICInitStruct->IcSelection == TIM_IC_SELECTION_DIRECTTI) + { + icoppositeselection = TIM_IC_SELECTION_INDIRECTTI; + } + else + { + icoppositeselection = TIM_IC_SELECTION_DIRECTTI; + } + if (TIM_ICInitStruct->Channel == TIM_CH_1) + { + /* TI1 Configuration */ + ConfigTI1(TIMx, TIM_ICInitStruct->IcPolarity, TIM_ICInitStruct->IcSelection, TIM_ICInitStruct->IcFilter); + /* Set the Input Capture Prescaler value */ + TIM_SetInCap1Prescaler(TIMx, TIM_ICInitStruct->IcPrescaler); + /* TI2 Configuration */ + ConfigTI2(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->IcFilter); + /* Set the Input Capture Prescaler value */ + TIM_SetInCap2Prescaler(TIMx, TIM_ICInitStruct->IcPrescaler); + } + else + { + /* TI2 Configuration */ + ConfigTI2(TIMx, TIM_ICInitStruct->IcPolarity, TIM_ICInitStruct->IcSelection, TIM_ICInitStruct->IcFilter); + /* Set the Input Capture Prescaler value */ + TIM_SetInCap2Prescaler(TIMx, TIM_ICInitStruct->IcPrescaler); + /* TI1 Configuration */ + ConfigTI1(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->IcFilter); + /* Set the Input Capture Prescaler value */ + TIM_SetInCap1Prescaler(TIMx, TIM_ICInitStruct->IcPrescaler); + } +} + +/** + * @brief Configures the: Break feature, dead time, Lock level, the OSSI, + * the OSSR State and the AOE(automatic output enable). + * @param TIMx where x can be 1 or 8 to select the TIM + * @param TIM_BDTRInitStruct pointer to a TIM_BDTRInitType structure that + * contains the BKDT Register configuration information for the TIM peripheral. + */ +void TIM_ConfigBkdt(TIM_Module* TIMx, TIM_BDTRInitType* TIM_BDTRInitStruct) +{ + uint32_t tmp; + /* Check the parameters */ + assert_param(IsTimList2Module(TIMx)); + assert_param(IsTimOssrState(TIM_BDTRInitStruct->OssrState)); + assert_param(IsTimOssiState(TIM_BDTRInitStruct->OssiState)); + assert_param(IsTimLockLevel(TIM_BDTRInitStruct->LockLevel)); + assert_param(IsTimBreakInState(TIM_BDTRInitStruct->Break)); + assert_param(IsTimBreakPalarity(TIM_BDTRInitStruct->BreakPolarity)); + assert_param(IsTimAutoOutputState(TIM_BDTRInitStruct->AutomaticOutput)); + /* Set the Lock level, the Break enable Bit and the Ploarity, the OSSR State, + the OSSI State, the dead time value and the Automatic Output Enable Bit */ + TIMx->BKDT = (uint32_t)TIM_BDTRInitStruct->OssrState | TIM_BDTRInitStruct->OssiState | TIM_BDTRInitStruct->LockLevel + | TIM_BDTRInitStruct->DeadTime | TIM_BDTRInitStruct->Break | TIM_BDTRInitStruct->BreakPolarity + | TIM_BDTRInitStruct->AutomaticOutput; + + /*cofigure other break in*/ + tmp = TIMx->CTRL1; + /*IOMBKPEN 0 meaning iom as break enable*/ + if (TIM_BDTRInitStruct->IomBreakEn) + tmp &= ~(0x01L << 10); + else + tmp |= (0x01L << 10); + if (TIM_BDTRInitStruct->LockUpBreakEn) + tmp |= (0x01L << 16); + else + tmp &= ~(0x01L << 16); + if (TIM_BDTRInitStruct->PvdBreakEn) + tmp |= (0x01L << 17); + else + tmp &= ~(0x01L << 17); + TIMx->CTRL1 = tmp; +} + +/** + * @brief Fills each TIM_TimeBaseInitStruct member with its default value. + * @param TIM_TimeBaseInitStruct pointer to a TIM_TimeBaseInitType + * structure which will be initialized. + */ +void TIM_InitTimBaseStruct(TIM_TimeBaseInitType* TIM_TimeBaseInitStruct) +{ + /* Set the default configuration */ + TIM_TimeBaseInitStruct->Period = 0xFFFF; + TIM_TimeBaseInitStruct->Prescaler = 0x0000; + TIM_TimeBaseInitStruct->ClkDiv = TIM_CLK_DIV1; + TIM_TimeBaseInitStruct->CntMode = TIM_CNT_MODE_UP; + TIM_TimeBaseInitStruct->RepetCnt = 0x0000; + + TIM_TimeBaseInitStruct->CapCh1FromCompEn = false; + TIM_TimeBaseInitStruct->CapCh2FromCompEn = false; + TIM_TimeBaseInitStruct->CapCh3FromCompEn = false; + TIM_TimeBaseInitStruct->CapEtrClrFromCompEn = false; + TIM_TimeBaseInitStruct->CapEtrSelFromTscEn = false; +} + +/** + * @brief Fills each TIM_OCInitStruct member with its default value. + * @param TIM_OCInitStruct pointer to a OCInitType structure which will + * be initialized. + */ +void TIM_InitOcStruct(OCInitType* TIM_OCInitStruct) +{ + /* Set the default configuration */ + TIM_OCInitStruct->OcMode = TIM_OCMODE_TIMING; + TIM_OCInitStruct->OutputState = TIM_OUTPUT_STATE_DISABLE; + TIM_OCInitStruct->OutputNState = TIM_OUTPUT_NSTATE_DISABLE; + TIM_OCInitStruct->Pulse = 0x0000; + TIM_OCInitStruct->OcPolarity = TIM_OC_POLARITY_HIGH; + TIM_OCInitStruct->OcNPolarity = TIM_OC_POLARITY_HIGH; + TIM_OCInitStruct->OcIdleState = TIM_OC_IDLE_STATE_RESET; + TIM_OCInitStruct->OcNIdleState = TIM_OCN_IDLE_STATE_RESET; +} + +/** + * @brief Fills each TIM_ICInitStruct member with its default value. + * @param TIM_ICInitStruct pointer to a TIM_ICInitType structure which will + * be initialized. + */ +void TIM_InitIcStruct(TIM_ICInitType* TIM_ICInitStruct) +{ + /* Set the default configuration */ + TIM_ICInitStruct->Channel = TIM_CH_1; + TIM_ICInitStruct->IcPolarity = TIM_IC_POLARITY_RISING; + TIM_ICInitStruct->IcSelection = TIM_IC_SELECTION_DIRECTTI; + TIM_ICInitStruct->IcPrescaler = TIM_IC_PSC_DIV1; + TIM_ICInitStruct->IcFilter = 0x00; +} + +/** + * @brief Fills each TIM_BDTRInitStruct member with its default value. + * @param TIM_BDTRInitStruct pointer to a TIM_BDTRInitType structure which + * will be initialized. + */ +void TIM_InitBkdtStruct(TIM_BDTRInitType* TIM_BDTRInitStruct) +{ + /* Set the default configuration */ + TIM_BDTRInitStruct->OssrState = TIM_OSSR_STATE_DISABLE; + TIM_BDTRInitStruct->OssiState = TIM_OSSI_STATE_DISABLE; + TIM_BDTRInitStruct->LockLevel = TIM_LOCK_LEVEL_OFF; + TIM_BDTRInitStruct->DeadTime = 0x00; + TIM_BDTRInitStruct->Break = TIM_BREAK_IN_DISABLE; + TIM_BDTRInitStruct->BreakPolarity = TIM_BREAK_POLARITY_LOW; + TIM_BDTRInitStruct->AutomaticOutput = TIM_AUTO_OUTPUT_DISABLE; +} + +/** + * @brief Enables or disables the specified TIM peripheral. + * @param TIMx where x can be 1 3 6 to select the TIMx peripheral. + * @param Cmd new state of the TIMx peripheral. + * This parameter can be: ENABLE or DISABLE. + */ +void TIM_Enable(TIM_Module* TIMx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the TIM Counter */ + TIMx->CTRL1 |= TIM_CTRL1_CNTEN; + } + else + { + /* Disable the TIM Counter */ + TIMx->CTRL1 &= (uint32_t)(~((uint32_t)TIM_CTRL1_CNTEN)); + } +} + +/** + * @brief Enables or disables the TIM peripheral Main Outputs. + * @param TIMx where x can be 1 to select the TIMx peripheral. + * @param Cmd new state of the TIM peripheral Main Outputs. + * This parameter can be: ENABLE or DISABLE. + */ +void TIM_EnableCtrlPwmOutputs(TIM_Module* TIMx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsTimList2Module(TIMx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the TIM Main Output */ + TIMx->BKDT |= TIM_BKDT_MOEN; + } + else + { + /* Disable the TIM Main Output */ + TIMx->BKDT &= (uint16_t)(~((uint16_t)TIM_BKDT_MOEN)); + } +} + +/** + * @brief Enables or disables the specified TIM interrupts. + * @param TIMx where x can be 1 3 6 to select the TIMx peripheral. + * @param TIM_IT specifies the TIM interrupts sources to be enabled or disabled. + * This parameter can be any combination of the following values: + * @arg TIM_INT_UPDATE TIM update Interrupt source + * @arg TIM_INT_CC1 TIM Capture Compare 1 Interrupt source + * @arg TIM_INT_CC2 TIM Capture Compare 2 Interrupt source + * @arg TIM_INT_CC3 TIM Capture Compare 3 Interrupt source + * @arg TIM_INT_CC4 TIM Capture Compare 4 Interrupt source + * @arg TIM_INT_COM TIM Commutation Interrupt source + * @arg TIM_INT_TRIG TIM Trigger Interrupt source + * @arg TIM_INT_BREAK TIM Break Interrupt source + * @note + * - TIM6 can only generate an update interrupt. + * - TIM_INT_BREAK is used only with TIM1. + * - TIM_INT_COM is used only with TIM1. + * @param Cmd new state of the TIM interrupts. + * This parameter can be: ENABLE or DISABLE. + */ +void TIM_ConfigInt(TIM_Module* TIMx, uint16_t TIM_IT, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IsTimInt(TIM_IT)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the Interrupt sources */ + TIMx->DINTEN |= TIM_IT; + } + else + { + /* Disable the Interrupt sources */ + TIMx->DINTEN &= (uint16_t)~TIM_IT; + } +} + +/** + * @brief Configures the TIMx event to be generate by software. + * @param TIMx where x can be 1 3 6 to select the TIM peripheral. + * @param TIM_EventSource specifies the event source. + * This parameter can be one or more of the following values: + * @arg TIM_EVT_SRC_UPDATE Timer update Event source + * @arg TIM_EVT_SRC_CC1 Timer Capture Compare 1 Event source + * @arg TIM_EVT_SRC_CC2 Timer Capture Compare 2 Event source + * @arg TIM_EVT_SRC_CC3 Timer Capture Compare 3 Event source + * @arg TIM_EVT_SRC_CC4 Timer Capture Compare 4 Event source + * @arg TIM_EVT_SRC_COM Timer COM event source + * @arg TIM_EVT_SRC_TRIG Timer Trigger Event source + * @arg TIM_EVT_SRC_BREAK Timer Break event source + * @note + * - TIM6 can only generate an update event. + * - TIM_EVT_SRC_COM and TIM_EVT_SRC_BREAK are used only with TIM1. + */ +void TIM_GenerateEvent(TIM_Module* TIMx, uint16_t TIM_EventSource) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IsTimEvtSrc(TIM_EventSource)); + + /* Set the event sources */ + TIMx->EVTGEN = TIM_EventSource; +} + +/** + * @brief Configures the TIMx's DMA interface. + * @param TIMx where x can be 1 or 3 to select + * the TIM peripheral. + * @param TIM_DMABase DMA Base address. + * This parameter can be one of the following values: + * @arg TIM_DMABASE_CTRL1 + * @arg TIM_DMABASE_CTRL2 + * @arg TIM_DMABASE_SMCTRL + * @arg TIM_DMABASE_DMAINTEN + * @arg TIM_DMABASE_STS + * @arg TIM_DMABASE_EVTGEN + * @arg TIM_DMABASE_CAPCMPMOD1 + * @arg TIM_DMABASE_CAPCMPMOD2 + * @arg TIM_DMABASE_CAPCMPEN + * @arg TIM_DMABASE_CNT + * @arg TIM_DMABASE_PSC + * @arg TIM_DMABASE_AR + * @arg TIM_DMABASE_REPCNT + * @arg TIM_DMABASE_CAPCMPDAT1 + * @arg TIM_DMABASE_CAPCMPDAT2 + * @arg TIM_DMABASE_CAPCMPDAT3 + * @arg TIM_DMABASE_CAPCMPDAT4 + * @arg TIM_DMABASE_BKDT + * @arg TIM_DMABASE_DMACTRL + * @arg TIM_DMABASE_CAPCMPMOD3 + * @arg TIM_DMABASE_CAPCMPDAT5 + * @arg TIM_DMABASE_CAPCMPDAT6 + * @param TIM_DMABurstLength DMA Burst length. + * This parameter can be one value between: + * TIM_DMABURST_LENGTH_1TRANSFER and TIM_DMABURST_LENGTH_18TRANSFERS. + */ +void TIM_ConfigDma(TIM_Module* TIMx, uint16_t TIM_DMABase, uint16_t TIM_DMABurstLength) +{ + /* Check the parameters */ + assert_param(IsTimList4Module(TIMx)); + assert_param(IsTimDmaBase(TIM_DMABase)); + assert_param(IsTimDmaLength(TIM_DMABurstLength)); + /* Set the DMA Base and the DMA Burst Length */ + TIMx->DCTRL = TIM_DMABase | TIM_DMABurstLength; +} + +/** + * @brief Enables or disables the TIMx's DMA Requests. + * @param TIMx where x can be 1, 3, 6 + * to select the TIM peripheral. + * @param TIM_DMASource specifies the DMA Request sources. + * This parameter can be any combination of the following values: + * @arg TIM_DMA_UPDATE TIM update Interrupt source + * @arg TIM_DMA_CC1 TIM Capture Compare 1 DMA source + * @arg TIM_DMA_CC2 TIM Capture Compare 2 DMA source + * @arg TIM_DMA_CC3 TIM Capture Compare 3 DMA source + * @arg TIM_DMA_CC4 TIM Capture Compare 4 DMA source + * @arg TIM_DMA_COM TIM Commutation DMA source + * @arg TIM_DMA_TRIG TIM Trigger DMA source + * @param Cmd new state of the DMA Request sources. + * This parameter can be: ENABLE or DISABLE. + */ +void TIM_EnableDma(TIM_Module* TIMx, uint16_t TIM_DMASource, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsTimList9Module(TIMx)); + assert_param(IsTimDmaSrc(TIM_DMASource)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the DMA sources */ + TIMx->DINTEN |= TIM_DMASource; + } + else + { + /* Disable the DMA sources */ + TIMx->DINTEN &= (uint16_t)~TIM_DMASource; + } +} + +/** + * @brief Configures the TIMx internal Clock + * @param TIMx where x can be 1 or 3 + * to select the TIM peripheral. + */ +void TIM_ConfigInternalClk(TIM_Module* TIMx) +{ + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + /* Disable slave mode to clock the prescaler directly with the internal clock */ + TIMx->SMCTRL &= (uint16_t)(~((uint16_t)TIM_SMCTRL_SMSEL)); +} + +/** + * @brief Configures the TIMx Internal Trigger as External Clock + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_InputTriggerSource Trigger source. + * This parameter can be one of the following values: + * @arg TIM_TRIG_SEL_IN_TR0 Internal Trigger 0 + * @arg TIM_TRIG_SEL_IN_TR1 Internal Trigger 1 + * @arg TIM_TRIG_SEL_IN_TR2 Internal Trigger 2 + * @arg TIM_TRIG_SEL_IN_TR3 Internal Trigger 3 + */ +void TIM_ConfigInternalTrigToExt(TIM_Module* TIMx, uint16_t TIM_InputTriggerSource) +{ + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimInterTrigSel(TIM_InputTriggerSource)); + /* Select the Internal Trigger */ + TIM_SelectInputTrig(TIMx, TIM_InputTriggerSource); + /* Select the External clock mode1 */ + TIMx->SMCTRL |= TIM_SLAVE_MODE_EXT1; +} + +/** + * @brief Configures the TIMx Trigger as External Clock + * @param TIMx where x can be 1, 3 to select the TIM peripheral. + * @param TIM_TIxExternalCLKSource Trigger source. + * This parameter can be one of the following values: + * @arg TIM_EXT_CLK_SRC_TI1ED TI1 Edge Detector + * @arg TIM_EXT_CLK_SRC_TI1 Filtered Timer Input 1 + * @arg TIM_EXT_CLK_SRC_TI2 Filtered Timer Input 2 + * @param IcPolarity specifies the TIx Polarity. + * This parameter can be one of the following values: + * @arg TIM_IC_POLARITY_RISING + * @arg TIM_IC_POLARITY_FALLING + * @param ICFilter specifies the filter value. + * This parameter must be a value between 0x0 and 0xF. + */ +void TIM_ConfigExtTrigAsClk(TIM_Module* TIMx, uint16_t TIM_TIxExternalCLKSource, uint16_t IcPolarity, uint16_t ICFilter) +{ + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimExtClkSrc(TIM_TIxExternalCLKSource)); + assert_param(IsTimIcPalaritySingleEdge(IcPolarity)); + assert_param(IsTimInCapFilter(ICFilter)); + /* Configure the Timer Input Clock Source */ + if (TIM_TIxExternalCLKSource == TIM_EXT_CLK_SRC_TI2) + { + ConfigTI2(TIMx, IcPolarity, TIM_IC_SELECTION_DIRECTTI, ICFilter); + } + else + { + ConfigTI1(TIMx, IcPolarity, TIM_IC_SELECTION_DIRECTTI, ICFilter); + } + /* Select the Trigger source */ + TIM_SelectInputTrig(TIMx, TIM_TIxExternalCLKSource); + /* Select the External clock mode1 */ + TIMx->SMCTRL |= TIM_SLAVE_MODE_EXT1; +} + +/** + * @brief Configures the External clock Mode1 + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ExtTRGPrescaler The external Trigger Prescaler. + * This parameter can be one of the following values: + * @arg TIM_EXT_TRG_PSC_OFF ETRP Prescaler OFF. + * @arg TIM_EXT_TRG_PSC_DIV2 ETRP frequency divided by 2. + * @arg TIM_EXT_TRG_PSC_DIV4 ETRP frequency divided by 4. + * @arg TIM_EXT_TRG_PSC_DIV8 ETRP frequency divided by 8. + * @param TIM_ExtTRGPolarity The external Trigger Polarity. + * This parameter can be one of the following values: + * @arg TIM_EXT_TRIG_POLARITY_INVERTED active low or falling edge active. + * @arg TIM_EXT_TRIG_POLARITY_NONINVERTED active high or rising edge active. + * @param ExtTRGFilter External Trigger Filter. + * This parameter must be a value between 0x00 and 0x0F + */ +void TIM_ConfigExtClkMode1(TIM_Module* TIMx, + uint16_t TIM_ExtTRGPrescaler, + uint16_t TIM_ExtTRGPolarity, + uint16_t ExtTRGFilter) +{ + uint16_t tmpsmcr = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimExtPreDiv(TIM_ExtTRGPrescaler)); + assert_param(IsTimExtTrigPolarity(TIM_ExtTRGPolarity)); + assert_param(IsTimExtTrigFilter(ExtTRGFilter)); + /* Configure the ETR Clock source */ + TIM_ConfigExtTrig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter); + + /* Get the TIMx SMCTRL register value */ + tmpsmcr = TIMx->SMCTRL; + /* Reset the SMS Bits */ + tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCTRL_SMSEL)); + /* Select the External clock mode1 */ + tmpsmcr |= TIM_SLAVE_MODE_EXT1; + /* Select the Trigger selection : ETRF */ + tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCTRL_TSEL)); + tmpsmcr |= TIM_TRIG_SEL_ETRF; + /* Write to TIMx SMCTRL */ + TIMx->SMCTRL = tmpsmcr; +} + +/** + * @brief Configures the External clock Mode2 + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ExtTRGPrescaler The external Trigger Prescaler. + * This parameter can be one of the following values: + * @arg TIM_EXT_TRG_PSC_OFF ETRP Prescaler OFF. + * @arg TIM_EXT_TRG_PSC_DIV2 ETRP frequency divided by 2. + * @arg TIM_EXT_TRG_PSC_DIV4 ETRP frequency divided by 4. + * @arg TIM_EXT_TRG_PSC_DIV8 ETRP frequency divided by 8. + * @param TIM_ExtTRGPolarity The external Trigger Polarity. + * This parameter can be one of the following values: + * @arg TIM_EXT_TRIG_POLARITY_INVERTED active low or falling edge active. + * @arg TIM_EXT_TRIG_POLARITY_NONINVERTED active high or rising edge active. + * @param ExtTRGFilter External Trigger Filter. + * This parameter must be a value between 0x00 and 0x0F + */ +void TIM_ConfigExtClkMode2(TIM_Module* TIMx, + uint16_t TIM_ExtTRGPrescaler, + uint16_t TIM_ExtTRGPolarity, + uint16_t ExtTRGFilter) +{ + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimExtPreDiv(TIM_ExtTRGPrescaler)); + assert_param(IsTimExtTrigPolarity(TIM_ExtTRGPolarity)); + assert_param(IsTimExtTrigFilter(ExtTRGFilter)); + /* Configure the ETR Clock source */ + TIM_ConfigExtTrig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter); + /* Enable the External clock mode2 */ + TIMx->SMCTRL |= TIM_SMCTRL_EXCEN; +} + +/** + * @brief Configures the TIMx External Trigger (ETR). + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ExtTRGPrescaler The external Trigger Prescaler. + * This parameter can be one of the following values: + * @arg TIM_EXT_TRG_PSC_OFF ETRP Prescaler OFF. + * @arg TIM_EXT_TRG_PSC_DIV2 ETRP frequency divided by 2. + * @arg TIM_EXT_TRG_PSC_DIV4 ETRP frequency divided by 4. + * @arg TIM_EXT_TRG_PSC_DIV8 ETRP frequency divided by 8. + * @param TIM_ExtTRGPolarity The external Trigger Polarity. + * This parameter can be one of the following values: + * @arg TIM_EXT_TRIG_POLARITY_INVERTED active low or falling edge active. + * @arg TIM_EXT_TRIG_POLARITY_NONINVERTED active high or rising edge active. + * @param ExtTRGFilter External Trigger Filter. + * This parameter must be a value between 0x00 and 0x0F + */ +void TIM_ConfigExtTrig(TIM_Module* TIMx, + uint16_t TIM_ExtTRGPrescaler, + uint16_t TIM_ExtTRGPolarity, + uint16_t ExtTRGFilter) +{ + uint16_t tmpsmcr = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimExtPreDiv(TIM_ExtTRGPrescaler)); + assert_param(IsTimExtTrigPolarity(TIM_ExtTRGPolarity)); + assert_param(IsTimExtTrigFilter(ExtTRGFilter)); + tmpsmcr = TIMx->SMCTRL; + /* Reset the ETR Bits */ + tmpsmcr &= SMCTRL_ETR_MASK; + /* Set the Prescaler, the Filter value and the Polarity */ + tmpsmcr |= + (uint16_t)(TIM_ExtTRGPrescaler | (uint16_t)(TIM_ExtTRGPolarity | (uint16_t)(ExtTRGFilter << (uint16_t)8))); + /* Write to TIMx SMCTRL */ + TIMx->SMCTRL = tmpsmcr; +} + +/** + * @brief Configures the TIMx Prescaler. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param Prescaler specifies the Prescaler Register value + * @param TIM_PSCReloadMode specifies the TIM Prescaler Reload mode + * This parameter can be one of the following values: + * @arg TIM_PSC_RELOAD_MODE_UPDATE The Prescaler is loaded at the update event. + * @arg TIM_PSC_RELOAD_MODE_IMMEDIATE The Prescaler is loaded immediately. + */ +void TIM_ConfigPrescaler(TIM_Module* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IsTimPscReloadMode(TIM_PSCReloadMode)); + /* Set the Prescaler value */ + TIMx->PSC = Prescaler; + /* Set or reset the UG Bit */ + TIMx->EVTGEN = TIM_PSCReloadMode; +} + +/** + * @brief Specifies the TIMx Counter Mode to be used. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param CntMode specifies the Counter Mode to be used + * This parameter can be one of the following values: + * @arg TIM_CNT_MODE_UP TIM Up Counting Mode + * @arg TIM_CNT_MODE_DOWN TIM Down Counting Mode + * @arg TIM_CNT_MODE_CENTER_ALIGN1 TIM Center Aligned Mode1 + * @arg TIM_CNT_MODE_CENTER_ALIGN2 TIM Center Aligned Mode2 + * @arg TIM_CNT_MODE_CENTER_ALIGN3 TIM Center Aligned Mode3 + */ +void TIM_ConfigCntMode(TIM_Module* TIMx, uint16_t CntMode) +{ + uint32_t tmpcr1 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimCntMode(CntMode)); + tmpcr1 = TIMx->CTRL1; + /* Reset the CMS and DIR Bits */ + tmpcr1 &= (uint32_t)(~((uint32_t)(TIM_CTRL1_DIR | TIM_CTRL1_CAMSEL))); + /* Set the Counter Mode */ + tmpcr1 |= CntMode; + /* Write to TIMx CTRL1 register */ + TIMx->CTRL1 = tmpcr1; +} + +/** + * @brief Selects the Input Trigger source + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_InputTriggerSource The Input Trigger source. + * This parameter can be one of the following values: + * @arg TIM_TRIG_SEL_IN_TR0 Internal Trigger 0 + * @arg TIM_TRIG_SEL_IN_TR1 Internal Trigger 1 + * @arg TIM_TRIG_SEL_IN_TR2 Internal Trigger 2 + * @arg TIM_TRIG_SEL_IN_TR3 Internal Trigger 3 + * @arg TIM_TRIG_SEL_TI1F_ED TI1 Edge Detector + * @arg TIM_TRIG_SEL_TI1FP1 Filtered Timer Input 1 + * @arg TIM_TRIG_SEL_TI2FP2 Filtered Timer Input 2 + * @arg TIM_TRIG_SEL_ETRF External Trigger input + */ +void TIM_SelectInputTrig(TIM_Module* TIMx, uint16_t TIM_InputTriggerSource) +{ + uint16_t tmpsmcr = 0; + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimTrigSel(TIM_InputTriggerSource)); + /* Get the TIMx SMCTRL register value */ + tmpsmcr = TIMx->SMCTRL; + /* Reset the TS Bits */ + tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCTRL_TSEL)); + /* Set the Input Trigger source */ + tmpsmcr |= TIM_InputTriggerSource; + /* Write to TIMx SMCTRL */ + TIMx->SMCTRL = tmpsmcr; +} + +/** + * @brief Configures the TIMx Encoder Interface. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_EncoderMode specifies the TIMx Encoder Mode. + * This parameter can be one of the following values: + * @arg TIM_ENCODE_MODE_TI1 Counter counts on TI1FP1 edge depending on TI2FP2 level. + * @arg TIM_ENCODE_MODE_TI2 Counter counts on TI2FP2 edge depending on TI1FP1 level. + * @arg TIM_ENCODE_MODE_TI12 Counter counts on both TI1FP1 and TI2FP2 edges depending + * on the level of the other input. + * @param TIM_IC1Polarity specifies the IC1 Polarity + * This parameter can be one of the following values: + * @arg TIM_IC_POLARITY_FALLING IC Falling edge. + * @arg TIM_IC_POLARITY_RISING IC Rising edge. + * @param TIM_IC2Polarity specifies the IC2 Polarity + * This parameter can be one of the following values: + * @arg TIM_IC_POLARITY_FALLING IC Falling edge. + * @arg TIM_IC_POLARITY_RISING IC Rising edge. + */ +void TIM_ConfigEncoderInterface(TIM_Module* TIMx, + uint16_t TIM_EncoderMode, + uint16_t TIM_IC1Polarity, + uint16_t TIM_IC2Polarity) +{ + uint16_t tmpsmcr = 0; + uint16_t tmpccmr1 = 0; + uint32_t tmpccer = 0; + + /* Check the parameters */ + assert_param(IsTimList5Module(TIMx)); + assert_param(IsTimEncodeMode(TIM_EncoderMode)); + assert_param(IsTimIcPalaritySingleEdge(TIM_IC1Polarity)); + assert_param(IsTimIcPalaritySingleEdge(TIM_IC2Polarity)); + + /* Get the TIMx SMCTRL register value */ + tmpsmcr = TIMx->SMCTRL; + + /* Get the TIMx CCMOD1 register value */ + tmpccmr1 = TIMx->CCMOD1; + + /* Get the TIMx CCEN register value */ + tmpccer = TIMx->CCEN; + + /* Set the encoder Mode */ + tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCTRL_SMSEL)); + tmpsmcr |= TIM_EncoderMode; + + /* Select the Capture Compare 1 and the Capture Compare 2 as input */ + tmpccmr1 &= (uint16_t)(((uint16_t) ~((uint16_t)TIM_CCMOD1_CC1SEL)) & (uint16_t)(~((uint16_t)TIM_CCMOD1_CC2SEL))); + tmpccmr1 |= TIM_CCMOD1_CC1SEL_0 | TIM_CCMOD1_CC2SEL_0; + + /* Set the TI1 and the TI2 Polarities */ + tmpccer &= (uint32_t)(((uint32_t) ~((uint32_t)TIM_CCEN_CC1P)) & ((uint32_t) ~((uint32_t)TIM_CCEN_CC2P))); + tmpccer |= (uint32_t)(TIM_IC1Polarity | (uint16_t)(TIM_IC2Polarity << (uint16_t)4)); + + /* Write to TIMx SMCTRL */ + TIMx->SMCTRL = tmpsmcr; + /* Write to TIMx CCMOD1 */ + TIMx->CCMOD1 = tmpccmr1; + /* Write to TIMx CCEN */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Forces the TIMx output 1 waveform to active or inactive level. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ForcedAction specifies the forced Action to be set to the output waveform. + * This parameter can be one of the following values: + * @arg TIM_FORCED_ACTION_ACTIVE Force active level on OC1REF + * @arg TIM_FORCED_ACTION_INACTIVE Force inactive level on OC1REF. + */ +void TIM_ConfigForcedOc1(TIM_Module* TIMx, uint16_t TIM_ForcedAction) +{ + uint16_t tmpccmr1 = 0; + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + assert_param(IsTimForceActive(TIM_ForcedAction)); + tmpccmr1 = TIMx->CCMOD1; + /* Reset the OC1M Bits */ + tmpccmr1 &= (uint16_t) ~((uint16_t)TIM_CCMOD1_OC1M); + /* Configure The Forced output Mode */ + tmpccmr1 |= TIM_ForcedAction; + /* Write to TIMx CCMOD1 register */ + TIMx->CCMOD1 = tmpccmr1; +} + +/** + * @brief Forces the TIMx output 2 waveform to active or inactive level. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ForcedAction specifies the forced Action to be set to the output waveform. + * This parameter can be one of the following values: + * @arg TIM_FORCED_ACTION_ACTIVE Force active level on OC2REF + * @arg TIM_FORCED_ACTION_INACTIVE Force inactive level on OC2REF. + */ +void TIM_ConfigForcedOc2(TIM_Module* TIMx, uint16_t TIM_ForcedAction) +{ + uint16_t tmpccmr1 = 0; + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimForceActive(TIM_ForcedAction)); + tmpccmr1 = TIMx->CCMOD1; + /* Reset the OC2M Bits */ + tmpccmr1 &= (uint16_t) ~((uint16_t)TIM_CCMOD1_OC2M); + /* Configure The Forced output Mode */ + tmpccmr1 |= (uint16_t)(TIM_ForcedAction << 8); + /* Write to TIMx CCMOD1 register */ + TIMx->CCMOD1 = tmpccmr1; +} + +/** + * @brief Forces the TIMx output 3 waveform to active or inactive level. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ForcedAction specifies the forced Action to be set to the output waveform. + * This parameter can be one of the following values: + * @arg TIM_FORCED_ACTION_ACTIVE Force active level on OC3REF + * @arg TIM_FORCED_ACTION_INACTIVE Force inactive level on OC3REF. + */ +void TIM_ConfigForcedOc3(TIM_Module* TIMx, uint16_t TIM_ForcedAction) +{ + uint16_t tmpccmr2 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimForceActive(TIM_ForcedAction)); + tmpccmr2 = TIMx->CCMOD2; + /* Reset the OC1M Bits */ + tmpccmr2 &= (uint16_t) ~((uint16_t)TIM_CCMOD2_OC3MD); + /* Configure The Forced output Mode */ + tmpccmr2 |= TIM_ForcedAction; + /* Write to TIMx CCMOD2 register */ + TIMx->CCMOD2 = tmpccmr2; +} + +/** + * @brief Forces the TIMx output 4 waveform to active or inactive level. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ForcedAction specifies the forced Action to be set to the output waveform. + * This parameter can be one of the following values: + * @arg TIM_FORCED_ACTION_ACTIVE Force active level on OC4REF + * @arg TIM_FORCED_ACTION_INACTIVE Force inactive level on OC4REF. + */ +void TIM_ConfigForcedOc4(TIM_Module* TIMx, uint16_t TIM_ForcedAction) +{ + uint16_t tmpccmr2 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimForceActive(TIM_ForcedAction)); + tmpccmr2 = TIMx->CCMOD2; + /* Reset the OC2M Bits */ + tmpccmr2 &= (uint16_t) ~((uint16_t)TIM_CCMOD2_OC4MD); + /* Configure The Forced output Mode */ + tmpccmr2 |= (uint16_t)(TIM_ForcedAction << 8); + /* Write to TIMx CCMOD2 register */ + TIMx->CCMOD2 = tmpccmr2; +} + +/** + * @brief Enables or disables TIMx peripheral Preload register on AR. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param Cmd new state of the TIMx peripheral Preload register + * This parameter can be: ENABLE or DISABLE. + */ +void TIM_ConfigArPreload(TIM_Module* TIMx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Set the AR Preload Bit */ + TIMx->CTRL1 |= TIM_CTRL1_ARPEN; + } + else + { + /* Reset the AR Preload Bit */ + TIMx->CTRL1 &= (uint32_t) ~((uint32_t)TIM_CTRL1_ARPEN); + } +} + +/** + * @brief Selects the TIM peripheral Commutation event. + * @param TIMx where x can be 1 to select the TIMx peripheral + * @param Cmd new state of the Commutation event. + * This parameter can be: ENABLE or DISABLE. + */ +void TIM_SelectComEvt(TIM_Module* TIMx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsTimList2Module(TIMx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Set the COM Bit */ + TIMx->CTRL2 |= TIM_CTRL2_CCUSEL; + } + else + { + /* Reset the COM Bit */ + TIMx->CTRL2 &= (uint32_t) ~((uint32_t)TIM_CTRL2_CCUSEL); + } +} + +/** + * @brief Selects the TIMx peripheral Capture Compare DMA source. + * @param TIMx where x can be 1 or 3 to select + * the TIM peripheral. + * @param Cmd new state of the Capture Compare DMA source + * This parameter can be: ENABLE or DISABLE. + */ +void TIM_SelectCapCmpDmaSrc(TIM_Module* TIMx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsTimList4Module(TIMx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Set the CCDS Bit */ + TIMx->CTRL2 |= TIM_CTRL2_CCDSEL; + } + else + { + /* Reset the CCDS Bit */ + TIMx->CTRL2 &= (uint32_t) ~((uint32_t)TIM_CTRL2_CCDSEL); + } +} + +/** + * @brief Sets or Resets the TIM peripheral Capture Compare Preload Control bit. + * @param TIMx where x can be 1 or 3 + * to select the TIMx peripheral + * @param Cmd new state of the Capture Compare Preload Control bit + * This parameter can be: ENABLE or DISABLE. + */ +void TIM_EnableCapCmpPreloadControl(TIM_Module* TIMx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsTimList5Module(TIMx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Set the CCPC Bit */ + TIMx->CTRL2 |= TIM_CTRL2_CCPCTL; + } + else + { + /* Reset the CCPC Bit */ + TIMx->CTRL2 &= (uint32_t) ~((uint32_t)TIM_CTRL2_CCPCTL); + } +} + +/** + * @brief Enables or disables the TIMx peripheral Preload register on CCDAT1. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCPreload new state of the TIMx peripheral Preload register + * This parameter can be one of the following values: + * @arg TIM_OC_PRE_LOAD_ENABLE + * @arg TIM_OC_PRE_LOAD_DISABLE + */ +void TIM_EnableOc1Preload(TIM_Module* TIMx, uint16_t TIM_OCPreload) +{ + uint16_t tmpccmr1 = 0; + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + assert_param(IsTimOcPreLoadState(TIM_OCPreload)); + tmpccmr1 = TIMx->CCMOD1; + /* Reset the OC1PE Bit */ + tmpccmr1 &= (uint16_t) ~((uint16_t)TIM_CCMOD1_OC1PEN); + /* Enable or Disable the Output Compare Preload feature */ + tmpccmr1 |= TIM_OCPreload; + /* Write to TIMx CCMOD1 register */ + TIMx->CCMOD1 = tmpccmr1; +} + +/** + * @brief Enables or disables the TIMx peripheral Preload register on CCDAT2. + * @param TIMx where x can be 1 or 3 to select + * the TIM peripheral. + * @param TIM_OCPreload new state of the TIMx peripheral Preload register + * This parameter can be one of the following values: + * @arg TIM_OC_PRE_LOAD_ENABLE + * @arg TIM_OC_PRE_LOAD_DISABLE + */ +void TIM_ConfigOc2Preload(TIM_Module* TIMx, uint16_t TIM_OCPreload) +{ + uint16_t tmpccmr1 = 0; + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimOcPreLoadState(TIM_OCPreload)); + tmpccmr1 = TIMx->CCMOD1; + /* Reset the OC2PE Bit */ + tmpccmr1 &= (uint16_t) ~((uint16_t)TIM_CCMOD1_OC2PEN); + /* Enable or Disable the Output Compare Preload feature */ + tmpccmr1 |= (uint16_t)(TIM_OCPreload << 8); + /* Write to TIMx CCMOD1 register */ + TIMx->CCMOD1 = tmpccmr1; +} + +/** + * @brief Enables or disables the TIMx peripheral Preload register on CCDAT3. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCPreload new state of the TIMx peripheral Preload register + * This parameter can be one of the following values: + * @arg TIM_OC_PRE_LOAD_ENABLE + * @arg TIM_OC_PRE_LOAD_DISABLE + */ +void TIM_ConfigOc3Preload(TIM_Module* TIMx, uint16_t TIM_OCPreload) +{ + uint16_t tmpccmr2 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcPreLoadState(TIM_OCPreload)); + tmpccmr2 = TIMx->CCMOD2; + /* Reset the OC3PE Bit */ + tmpccmr2 &= (uint16_t) ~((uint16_t)TIM_CCMOD2_OC3PEN); + /* Enable or Disable the Output Compare Preload feature */ + tmpccmr2 |= TIM_OCPreload; + /* Write to TIMx CCMOD2 register */ + TIMx->CCMOD2 = tmpccmr2; +} + +/** + * @brief Enables or disables the TIMx peripheral Preload register on CCDAT4. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCPreload new state of the TIMx peripheral Preload register + * This parameter can be one of the following values: + * @arg TIM_OC_PRE_LOAD_ENABLE + * @arg TIM_OC_PRE_LOAD_DISABLE + */ +void TIM_ConfigOc4Preload(TIM_Module* TIMx, uint16_t TIM_OCPreload) +{ + uint16_t tmpccmr2 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcPreLoadState(TIM_OCPreload)); + tmpccmr2 = TIMx->CCMOD2; + /* Reset the OC4PE Bit */ + tmpccmr2 &= (uint16_t) ~((uint16_t)TIM_CCMOD2_OC4PEN); + /* Enable or Disable the Output Compare Preload feature */ + tmpccmr2 |= (uint16_t)(TIM_OCPreload << 8); + /* Write to TIMx CCMOD2 register */ + TIMx->CCMOD2 = tmpccmr2; +} + + +/** + * @brief Configures the TIMx Output Compare 1 Fast feature. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCFast new state of the Output Compare Fast Enable Bit. + * This parameter can be one of the following values: + * @arg TIM_OC_FAST_ENABLE TIM output compare fast enable + * @arg TIM_OC_FAST_DISABLE TIM output compare fast disable + */ +void TIM_ConfigOc1Fast(TIM_Module* TIMx, uint16_t TIM_OCFast) +{ + uint16_t tmpccmr1 = 0; + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + assert_param(IsTimOcFastState(TIM_OCFast)); + /* Get the TIMx CCMOD1 register value */ + tmpccmr1 = TIMx->CCMOD1; + /* Reset the OC1FE Bit */ + tmpccmr1 &= (uint16_t) ~((uint16_t)TIM_CCMOD1_OC1FEN); + /* Enable or Disable the Output Compare Fast Bit */ + tmpccmr1 |= TIM_OCFast; + /* Write to TIMx CCMOD1 */ + TIMx->CCMOD1 = tmpccmr1; +} + +/** + * @brief Configures the TIMx Output Compare 2 Fast feature. + * @param TIMx where x can be 1 or 3 to select + * the TIM peripheral. + * @param TIM_OCFast new state of the Output Compare Fast Enable Bit. + * This parameter can be one of the following values: + * @arg TIM_OC_FAST_ENABLE TIM output compare fast enable + * @arg TIM_OC_FAST_DISABLE TIM output compare fast disable + */ +void TIM_ConfigOc2Fast(TIM_Module* TIMx, uint16_t TIM_OCFast) +{ + uint16_t tmpccmr1 = 0; + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimOcFastState(TIM_OCFast)); + /* Get the TIMx CCMOD1 register value */ + tmpccmr1 = TIMx->CCMOD1; + /* Reset the OC2FE Bit */ + tmpccmr1 &= (uint16_t) ~((uint16_t)TIM_CCMOD1_OC2FEN); + /* Enable or Disable the Output Compare Fast Bit */ + tmpccmr1 |= (uint16_t)(TIM_OCFast << 8); + /* Write to TIMx CCMOD1 */ + TIMx->CCMOD1 = tmpccmr1; +} + +/** + * @brief Configures the TIMx Output Compare 3 Fast feature. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCFast new state of the Output Compare Fast Enable Bit. + * This parameter can be one of the following values: + * @arg TIM_OC_FAST_ENABLE TIM output compare fast enable + * @arg TIM_OC_FAST_DISABLE TIM output compare fast disable + */ +void TIM_ConfigOc3Fast(TIM_Module* TIMx, uint16_t TIM_OCFast) +{ + uint16_t tmpccmr2 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcFastState(TIM_OCFast)); + /* Get the TIMx CCMOD2 register value */ + tmpccmr2 = TIMx->CCMOD2; + /* Reset the OC3FE Bit */ + tmpccmr2 &= (uint16_t) ~((uint16_t)TIM_CCMOD2_OC3FEN); + /* Enable or Disable the Output Compare Fast Bit */ + tmpccmr2 |= TIM_OCFast; + /* Write to TIMx CCMOD2 */ + TIMx->CCMOD2 = tmpccmr2; +} + +/** + * @brief Configures the TIMx Output Compare 4 Fast feature. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCFast new state of the Output Compare Fast Enable Bit. + * This parameter can be one of the following values: + * @arg TIM_OC_FAST_ENABLE TIM output compare fast enable + * @arg TIM_OC_FAST_DISABLE TIM output compare fast disable + */ +void TIM_ConfigOc4Fast(TIM_Module* TIMx, uint16_t TIM_OCFast) +{ + uint16_t tmpccmr2 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcFastState(TIM_OCFast)); + /* Get the TIMx CCMOD2 register value */ + tmpccmr2 = TIMx->CCMOD2; + /* Reset the OC4FE Bit */ + tmpccmr2 &= (uint16_t) ~((uint16_t)TIM_CCMOD2_OC4FEN); + /* Enable or Disable the Output Compare Fast Bit */ + tmpccmr2 |= (uint16_t)(TIM_OCFast << 8); + /* Write to TIMx CCMOD2 */ + TIMx->CCMOD2 = tmpccmr2; +} + +/** + * @brief Clears or safeguards the OCREF1 signal on an external event + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCClear new state of the Output Compare Clear Enable Bit. + * This parameter can be one of the following values: + * @arg TIM_OC_CLR_ENABLE TIM Output clear enable + * @arg TIM_OC_CLR_DISABLE TIM Output clear disable + */ +void TIM_ClrOc1Ref(TIM_Module* TIMx, uint16_t TIM_OCClear) +{ + uint16_t tmpccmr1 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcClrState(TIM_OCClear)); + + tmpccmr1 = TIMx->CCMOD1; + + /* Reset the OC1CE Bit */ + tmpccmr1 &= (uint16_t) ~((uint16_t)TIM_CCMOD1_OC1CEN); + /* Enable or Disable the Output Compare Clear Bit */ + tmpccmr1 |= TIM_OCClear; + /* Write to TIMx CCMOD1 register */ + TIMx->CCMOD1 = tmpccmr1; +} + +/** + * @brief Clears or safeguards the OCREF2 signal on an external event + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCClear new state of the Output Compare Clear Enable Bit. + * This parameter can be one of the following values: + * @arg TIM_OC_CLR_ENABLE TIM Output clear enable + * @arg TIM_OC_CLR_DISABLE TIM Output clear disable + */ +void TIM_ClrOc2Ref(TIM_Module* TIMx, uint16_t TIM_OCClear) +{ + uint16_t tmpccmr1 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcClrState(TIM_OCClear)); + tmpccmr1 = TIMx->CCMOD1; + /* Reset the OC2CE Bit */ + tmpccmr1 &= (uint16_t) ~((uint16_t)TIM_CCMOD1_OC2CEN); + /* Enable or Disable the Output Compare Clear Bit */ + tmpccmr1 |= (uint16_t)(TIM_OCClear << 8); + /* Write to TIMx CCMOD1 register */ + TIMx->CCMOD1 = tmpccmr1; +} + +/** + * @brief Clears or safeguards the OCREF3 signal on an external event + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCClear new state of the Output Compare Clear Enable Bit. + * This parameter can be one of the following values: + * @arg TIM_OC_CLR_ENABLE TIM Output clear enable + * @arg TIM_OC_CLR_DISABLE TIM Output clear disable + */ +void TIM_ClrOc3Ref(TIM_Module* TIMx, uint16_t TIM_OCClear) +{ + uint16_t tmpccmr2 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcClrState(TIM_OCClear)); + tmpccmr2 = TIMx->CCMOD2; + /* Reset the OC3CE Bit */ + tmpccmr2 &= (uint16_t) ~((uint16_t)TIM_CCMOD2_OC3CEN); + /* Enable or Disable the Output Compare Clear Bit */ + tmpccmr2 |= TIM_OCClear; + /* Write to TIMx CCMOD2 register */ + TIMx->CCMOD2 = tmpccmr2; +} + +/** + * @brief Clears or safeguards the OCREF4 signal on an external event + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_OCClear new state of the Output Compare Clear Enable Bit. + * This parameter can be one of the following values: + * @arg TIM_OC_CLR_ENABLE TIM Output clear enable + * @arg TIM_OC_CLR_DISABLE TIM Output clear disable + */ +void TIM_ClrOc4Ref(TIM_Module* TIMx, uint16_t TIM_OCClear) +{ + uint16_t tmpccmr2 = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcClrState(TIM_OCClear)); + tmpccmr2 = TIMx->CCMOD2; + /* Reset the OC4CE Bit */ + tmpccmr2 &= (uint16_t) ~((uint16_t)TIM_CCMOD2_OC4CEN); + /* Enable or Disable the Output Compare Clear Bit */ + tmpccmr2 |= (uint16_t)(TIM_OCClear << 8); + /* Write to TIMx CCMOD2 register */ + TIMx->CCMOD2 = tmpccmr2; +} + +/** + * @brief Configures the TIMx channel 1 polarity. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param OcPolarity specifies the OC1 Polarity + * This parameter can be one of the following values: + * @arg TIM_OC_POLARITY_HIGH Output Compare active high + * @arg TIM_OC_POLARITY_LOW Output Compare active low + */ +void TIM_ConfigOc1Polarity(TIM_Module* TIMx, uint16_t OcPolarity) +{ + uint32_t tmpccer = 0; + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + assert_param(IsTimOcPolarity(OcPolarity)); + tmpccer = TIMx->CCEN; + /* Set or Reset the CC1P Bit */ + tmpccer &= (uint32_t) ~((uint32_t)TIM_CCEN_CC1P); + tmpccer |= OcPolarity; + /* Write to TIMx CCEN register */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Configures the TIMx Channel 1N polarity. + * @param TIMx where x can be 1, 8 to select the TIM peripheral. + * @param OcNPolarity specifies the OC1N Polarity + * This parameter can be one of the following values: + * @arg TIM_OCN_POLARITY_HIGH Output Compare active high + * @arg TIM_OCN_POLARITY_LOW Output Compare active low + */ +void TIM_ConfigOc1NPolarity(TIM_Module* TIMx, uint16_t OcNPolarity) +{ + uint32_t tmpccer = 0; + /* Check the parameters */ + assert_param(IsTimList2Module(TIMx)); + assert_param(IsTimOcnPolarity(OcNPolarity)); + + tmpccer = TIMx->CCEN; + /* Set or Reset the CC1NP Bit */ + tmpccer &= (uint32_t) ~((uint32_t)TIM_CCEN_CC1NP); + tmpccer |= OcNPolarity; + /* Write to TIMx CCEN register */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Configures the TIMx channel 2 polarity. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param OcPolarity specifies the OC2 Polarity + * This parameter can be one of the following values: + * @arg TIM_OC_POLARITY_HIGH Output Compare active high + * @arg TIM_OC_POLARITY_LOW Output Compare active low + */ +void TIM_ConfigOc2Polarity(TIM_Module* TIMx, uint16_t OcPolarity) +{ + uint32_t tmpccer = 0; + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimOcPolarity(OcPolarity)); + tmpccer = TIMx->CCEN; + /* Set or Reset the CC2P Bit */ + tmpccer &= (uint32_t) ~((uint32_t)TIM_CCEN_CC2P); + tmpccer |= (uint32_t)(OcPolarity << 4); + /* Write to TIMx CCEN register */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Configures the TIMx Channel 2N polarity. + * @param TIMx where x can be 1 or 8 to select the TIM peripheral. + * @param OcNPolarity specifies the OC2N Polarity + * This parameter can be one of the following values: + * @arg TIM_OCN_POLARITY_HIGH Output Compare active high + * @arg TIM_OCN_POLARITY_LOW Output Compare active low + */ +void TIM_ConfigOc2NPolarity(TIM_Module* TIMx, uint16_t OcNPolarity) +{ + uint32_t tmpccer = 0; + /* Check the parameters */ + assert_param(IsTimList1Module(TIMx)); + assert_param(IsTimOcnPolarity(OcNPolarity)); + + tmpccer = TIMx->CCEN; + /* Set or Reset the CC2NP Bit */ + tmpccer &= (uint32_t) ~((uint32_t)TIM_CCEN_CC2NP); + tmpccer |= (uint32_t)(OcNPolarity << 4); + /* Write to TIMx CCEN register */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Configures the TIMx channel 3 polarity. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param OcPolarity specifies the OC3 Polarity + * This parameter can be one of the following values: + * @arg TIM_OC_POLARITY_HIGH Output Compare active high + * @arg TIM_OC_POLARITY_LOW Output Compare active low + */ +void TIM_ConfigOc3Polarity(TIM_Module* TIMx, uint16_t OcPolarity) +{ + uint32_t tmpccer = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcPolarity(OcPolarity)); + tmpccer = TIMx->CCEN; + /* Set or Reset the CC3P Bit */ + tmpccer &= (uint32_t) ~((uint32_t)TIM_CCEN_CC3P); + tmpccer |= (uint32_t)(OcPolarity << 8); + /* Write to TIMx CCEN register */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Configures the TIMx Channel 3N polarity. + * @param TIMx where x can be 1 or 8 to select the TIM peripheral. + * @param OcNPolarity specifies the OC3N Polarity + * This parameter can be one of the following values: + * @arg TIM_OCN_POLARITY_HIGH Output Compare active high + * @arg TIM_OCN_POLARITY_LOW Output Compare active low + */ +void TIM_ConfigOc3NPolarity(TIM_Module* TIMx, uint16_t OcNPolarity) +{ + uint32_t tmpccer = 0; + + /* Check the parameters */ + assert_param(IsTimList1Module(TIMx)); + assert_param(IsTimOcnPolarity(OcNPolarity)); + + tmpccer = TIMx->CCEN; + /* Set or Reset the CC3NP Bit */ + tmpccer &= (uint32_t) ~((uint32_t)TIM_CCEN_CC3NP); + tmpccer |= (uint32_t)(OcNPolarity << 8); + /* Write to TIMx CCEN register */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Configures the TIMx channel 4 polarity. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param OcPolarity specifies the OC4 Polarity + * This parameter can be one of the following values: + * @arg TIM_OC_POLARITY_HIGH Output Compare active high + * @arg TIM_OC_POLARITY_LOW Output Compare active low + */ +void TIM_ConfigOc4Polarity(TIM_Module* TIMx, uint16_t OcPolarity) +{ + uint32_t tmpccer = 0; + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimOcPolarity(OcPolarity)); + tmpccer = TIMx->CCEN; + /* Set or Reset the CC4P Bit */ + tmpccer &= (uint32_t) ~((uint32_t)TIM_CCEN_CC4P); + tmpccer |= (uint32_t)(OcPolarity << 12); + /* Write to TIMx CCEN register */ + TIMx->CCEN = tmpccer; +} + +/** + * @brief Enables or disables the TIM Capture Compare Channel x. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param Channel specifies the TIM Channel + * This parameter can be one of the following values: + * @arg TIM_CH_1 TIM Channel 1 + * @arg TIM_CH_2 TIM Channel 2 + * @arg TIM_CH_3 TIM Channel 3 + * @arg TIM_CH_4 TIM Channel 4 + * @param TIM_CCx specifies the TIM Channel CCxE bit new state. + * This parameter can be: TIM_CAP_CMP_ENABLE or TIM_CAP_CMP_DISABLE. + */ +void TIM_EnableCapCmpCh(TIM_Module* TIMx, uint16_t Channel, uint32_t TIM_CCx) +{ + uint16_t tmp = 0; + + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + assert_param(IsTimCh(Channel)); + assert_param(IsTimCapCmpState(TIM_CCx)); + + tmp = CAPCMPEN_CCE_SET << Channel; + + /* Reset the CCxE Bit */ + TIMx->CCEN &= (uint32_t)~tmp; + + /* Set or reset the CCxE Bit */ + TIMx->CCEN |= (uint32_t)(TIM_CCx << Channel); +} + +/** + * @brief Enables or disables the TIM Capture Compare Channel xN. + * @param TIMx where x can be 1, 8 to select the TIM peripheral. + * @param Channel specifies the TIM Channel + * This parameter can be one of the following values: + * @arg TIM_CH_1 TIM Channel 1 + * @arg TIM_CH_2 TIM Channel 2 + * @arg TIM_CH_3 TIM Channel 3 + * @param TIM_CCxN specifies the TIM Channel CCxNE bit new state. + * This parameter can be: TIM_CAP_CMP_N_ENABLE or TIM_CAP_CMP_N_DISABLE. + */ +void TIM_EnableCapCmpChN(TIM_Module* TIMx, uint16_t Channel, uint32_t TIM_CCxN) +{ + uint16_t tmp = 0; + + /* Check the parameters */ + assert_param(IsTimList2Module(TIMx)); + assert_param(IsTimComplementaryCh(Channel)); + assert_param(IsTimCapCmpNState(TIM_CCxN)); + + tmp = CAPCMPEN_CCNE_SET << Channel; + + /* Reset the CCxNE Bit */ + TIMx->CCEN &= (uint32_t)~tmp; + + /* Set or reset the CCxNE Bit */ + TIMx->CCEN |= (uint32_t)(TIM_CCxN << Channel); +} + +/** + * @brief Selects the TIM Output Compare Mode. + * @note This function disables the selected channel before changing the Output + * Compare Mode. + * User has to enable this channel using TIM_EnableCapCmpCh and TIM_EnableCapCmpChN functions. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param Channel specifies the TIM Channel + * This parameter can be one of the following values: + * @arg TIM_CH_1 TIM Channel 1 + * @arg TIM_CH_2 TIM Channel 2 + * @arg TIM_CH_3 TIM Channel 3 + * @arg TIM_CH_4 TIM Channel 4 + * @param OcMode specifies the TIM Output Compare Mode. + * This parameter can be one of the following values: + * @arg TIM_OCMODE_TIMING + * @arg TIM_OCMODE_ACTIVE + * @arg TIM_OCMODE_TOGGLE + * @arg TIM_OCMODE_PWM1 + * @arg TIM_OCMODE_PWM2 + * @arg TIM_FORCED_ACTION_ACTIVE + * @arg TIM_FORCED_ACTION_INACTIVE + */ +void TIM_SelectOcMode(TIM_Module* TIMx, uint16_t Channel, uint16_t OcMode) +{ + uint32_t tmp = 0; + uint16_t tmp1 = 0; + + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + assert_param(IsTimCh(Channel)); + assert_param(IsTimOc(OcMode)); + + tmp = (uint32_t)TIMx; + tmp += CAPCMPMOD_OFFSET; + + tmp1 = CAPCMPEN_CCE_SET << (uint16_t)Channel; + + /* Disable the Channel: Reset the CCxE Bit */ + TIMx->CCEN &= (uint16_t)~tmp1; + + if ((Channel == TIM_CH_1) || (Channel == TIM_CH_3)) + { + tmp += (Channel >> 1); + + /* Reset the OCxM bits in the CCMRx register */ + *(__IO uint32_t*)tmp &= (uint32_t) ~((uint32_t)TIM_CCMOD1_OC1M); + + /* Configure the OCxM bits in the CCMRx register */ + *(__IO uint32_t*)tmp |= OcMode; + } + else + { + tmp += (uint16_t)(Channel - (uint16_t)4) >> (uint16_t)1; + + /* Reset the OCxM bits in the CCMRx register */ + *(__IO uint32_t*)tmp &= (uint32_t) ~((uint32_t)TIM_CCMOD1_OC2M); + + /* Configure the OCxM bits in the CCMRx register */ + *(__IO uint32_t*)tmp |= (uint16_t)(OcMode << 8); + } +} + +/** + * @brief Enables or Disables the TIMx Update event. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param Cmd new state of the TIMx UDIS bit + * This parameter can be: ENABLE or DISABLE. + */ +void TIM_EnableUpdateEvt(TIM_Module* TIMx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Set the Update Disable Bit */ + TIMx->CTRL1 |= TIM_CTRL1_UPDIS; + } + else + { + /* Reset the Update Disable Bit */ + TIMx->CTRL1 &= (uint32_t) ~((uint32_t)TIM_CTRL1_UPDIS); + } +} + +/** + * @brief Configures the TIMx Update Request Interrupt source. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param TIM_UpdateSource specifies the Update source. + * This parameter can be one of the following values: + * @arg TIM_UPDATE_SRC_REGULAr Source of update is the counter overflow/underflow + or the setting of UG bit, or an update generation + through the slave mode controller. + * @arg TIM_UPDATE_SRC_GLOBAL Source of update is counter overflow/underflow. + */ +void TIM_ConfigUpdateRequestIntSrc(TIM_Module* TIMx, uint16_t TIM_UpdateSource) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IsTimUpdateSrc(TIM_UpdateSource)); + if (TIM_UpdateSource != TIM_UPDATE_SRC_GLOBAL) + { + /* Set the URS Bit */ + TIMx->CTRL1 |= TIM_CTRL1_UPRS; + } + else + { + /* Reset the URS Bit */ + TIMx->CTRL1 &= (uint32_t) ~((uint32_t)TIM_CTRL1_UPRS); + } +} + +/** + * @brief Enables or disables the TIMx's Hall sensor interface. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param Cmd new state of the TIMx Hall sensor interface. + * This parameter can be: ENABLE or DISABLE. + */ +void TIM_SelectHallSensor(TIM_Module* TIMx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Set the TI1S Bit */ + TIMx->CTRL2 |= TIM_CTRL2_TI1SEL; + } + else + { + /* Reset the TI1S Bit */ + TIMx->CTRL2 &= (uint32_t) ~((uint32_t)TIM_CTRL2_TI1SEL); + } +} + +/** + * @brief Selects the TIMx's One Pulse Mode. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param TIM_OPMode specifies the OPM Mode to be used. + * This parameter can be one of the following values: + * @arg TIM_OPMODE_SINGLE + * @arg TIM_OPMODE_REPET + */ +void TIM_SelectOnePulseMode(TIM_Module* TIMx, uint16_t TIM_OPMode) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IsTimOpMOde(TIM_OPMode)); + /* Reset the OPM Bit */ + TIMx->CTRL1 &= (uint32_t) ~((uint32_t)TIM_CTRL1_ONEPM); + /* Configure the OPM Mode */ + TIMx->CTRL1 |= TIM_OPMode; +} + +/** + * @brief Selects the TIMx Trigger Output Mode. + * @param TIMx where x can be 1, 3, 6 to select the TIM peripheral. + * @param TIM_TRGOSource specifies the Trigger Output source. + * This paramter can be one of the following values: + * + * - For all TIMx + * @arg TIM_TRGO_SRC_RESET The UG bit in the TIM_EVTGEN register is used as the trigger output (TRGO). + * @arg TIM_TRGO_SRC_ENABLE The Counter Enable CEN is used as the trigger output (TRGO). + * @arg TIM_TRGO_SRC_UPDATE The update event is selected as the trigger output (TRGO). + * + * - For all TIMx except TIM6 + * @arg TIM_TRGO_SRC_OC1 The trigger output sends a positive pulse when the CC1IF flag + * is to be set, as soon as a capture or compare match occurs (TRGO). + * @arg TIM_TRGO_SRC_OC1REF OC1REF signal is used as the trigger output (TRGO). + * @arg TIM_TRGO_SRC_OC2REF OC2REF signal is used as the trigger output (TRGO). + * @arg TIM_TRGO_SRC_OC3REF OC3REF signal is used as the trigger output (TRGO). + * @arg TIM_TRGO_SRC_OC4REF OC4REF signal is used as the trigger output (TRGO). + * + */ +void TIM_SelectOutputTrig(TIM_Module* TIMx, uint16_t TIM_TRGOSource) +{ + /* Check the parameters */ + assert_param(IsTimList7Module(TIMx)); + assert_param(IsTimTrgoSrc(TIM_TRGOSource)); + /* Reset the MMS Bits */ + TIMx->CTRL2 &= (uint32_t) ~((uint32_t)TIM_CTRL2_MMSEL); + /* Select the TRGO source */ + TIMx->CTRL2 |= TIM_TRGOSource; +} + +/** + * @brief Selects the TIMx Slave Mode. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_SlaveMode specifies the Timer Slave Mode. + * This parameter can be one of the following values: + * @arg TIM_SLAVE_MODE_RESET Rising edge of the selected trigger signal (TRGI) re-initializes + * the counter and triggers an update of the registers. + * @arg TIM_SLAVE_MODE_GATED The counter clock is enabled when the trigger signal (TRGI) is high. + * @arg TIM_SLAVE_MODE_TRIG The counter starts at a rising edge of the trigger TRGI. + * @arg TIM_SLAVE_MODE_EXT1 Rising edges of the selected trigger (TRGI) clock the counter. + */ +void TIM_SelectSlaveMode(TIM_Module* TIMx, uint16_t TIM_SlaveMode) +{ + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimSlaveMode(TIM_SlaveMode)); + /* Reset the SMS Bits */ + TIMx->SMCTRL &= (uint16_t) ~((uint16_t)TIM_SMCTRL_SMSEL); + /* Select the Slave Mode */ + TIMx->SMCTRL |= TIM_SlaveMode; +} + +/** + * @brief Sets or Resets the TIMx Master/Slave Mode. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_MasterSlaveMode specifies the Timer Master Slave Mode. + * This parameter can be one of the following values: + * @arg TIM_MASTER_SLAVE_MODE_ENABLE synchronization between the current timer + * and its slaves (through TRGO). + * @arg TIM_MASTER_SLAVE_MODE_DISABLE No action + */ +void TIM_SelectMasterSlaveMode(TIM_Module* TIMx, uint16_t TIM_MasterSlaveMode) +{ + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimMasterSlaveMode(TIM_MasterSlaveMode)); + /* Reset the MSM Bit */ + TIMx->SMCTRL &= (uint16_t) ~((uint16_t)TIM_SMCTRL_MSMD); + + /* Set or Reset the MSM Bit */ + TIMx->SMCTRL |= TIM_MasterSlaveMode; +} + +/** + * @brief Sets the TIMx Counter Register value + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param Counter specifies the Counter register new value. + */ +void TIM_SetCnt(TIM_Module* TIMx, uint16_t Counter) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + /* Set the Counter Register value */ + TIMx->CNT = Counter; +} + +/** + * @brief Sets the TIMx Autoreload Register value + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param Autoreload specifies the Autoreload register new value. + */ +void TIM_SetAutoReload(TIM_Module* TIMx, uint16_t Autoreload) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + /* Set the Autoreload Register value */ + TIMx->AR = Autoreload; +} + +/** + * @brief Sets the TIMx Capture Compare1 Register value + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param Compare1 specifies the Capture Compare1 register new value. + */ +void TIM_SetCmp1(TIM_Module* TIMx, uint16_t Compare1) +{ + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + /* Set the Capture Compare1 Register value */ + TIMx->CCDAT1 = Compare1; +} + +/** + * @brief Sets the TIMx Capture Compare2 Register value + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param Compare2 specifies the Capture Compare2 register new value. + */ +void TIM_SetCmp2(TIM_Module* TIMx, uint16_t Compare2) +{ + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + /* Set the Capture Compare2 Register value */ + TIMx->CCDAT2 = Compare2; +} + +/** + * @brief Sets the TIMx Capture Compare3 Register value + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param Compare3 specifies the Capture Compare3 register new value. + */ +void TIM_SetCmp3(TIM_Module* TIMx, uint16_t Compare3) +{ + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + /* Set the Capture Compare3 Register value */ + TIMx->CCDAT3 = Compare3; +} + +/** + * @brief Sets the TIMx Capture Compare4 Register value + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param Compare4 specifies the Capture Compare4 register new value. + */ +void TIM_SetCmp4(TIM_Module* TIMx, uint16_t Compare4) +{ + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + /* Set the Capture Compare4 Register value */ + TIMx->CCDAT4 = Compare4; +} + + +/** + * @brief Sets the TIMx Input Capture 1 prescaler. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ICPSC specifies the Input Capture1 prescaler new value. + * This parameter can be one of the following values: + * @arg TIM_IC_PSC_DIV1 no prescaler + * @arg TIM_IC_PSC_DIV2 capture is done once every 2 events + * @arg TIM_IC_PSC_DIV4 capture is done once every 4 events + * @arg TIM_IC_PSC_DIV8 capture is done once every 8 events + */ +void TIM_SetInCap1Prescaler(TIM_Module* TIMx, uint16_t TIM_ICPSC) +{ + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + assert_param(IsTimIcPrescaler(TIM_ICPSC)); + /* Reset the IC1PSC Bits */ + TIMx->CCMOD1 &= (uint16_t) ~((uint16_t)TIM_CCMOD1_IC1PSC); + /* Set the IC1PSC value */ + TIMx->CCMOD1 |= TIM_ICPSC; +} + +/** + * @brief Sets the TIMx Input Capture 2 prescaler. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ICPSC specifies the Input Capture2 prescaler new value. + * This parameter can be one of the following values: + * @arg TIM_IC_PSC_DIV1 no prescaler + * @arg TIM_IC_PSC_DIV2 capture is done once every 2 events + * @arg TIM_IC_PSC_DIV4 capture is done once every 4 events + * @arg TIM_IC_PSC_DIV8 capture is done once every 8 events + */ +void TIM_SetInCap2Prescaler(TIM_Module* TIMx, uint16_t TIM_ICPSC) +{ + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + assert_param(IsTimIcPrescaler(TIM_ICPSC)); + /* Reset the IC2PSC Bits */ + TIMx->CCMOD1 &= (uint16_t) ~((uint16_t)TIM_CCMOD1_IC2PSC); + /* Set the IC2PSC value */ + TIMx->CCMOD1 |= (uint16_t)(TIM_ICPSC << 8); +} + +/** + * @brief Sets the TIMx Input Capture 3 prescaler. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ICPSC specifies the Input Capture3 prescaler new value. + * This parameter can be one of the following values: + * @arg TIM_IC_PSC_DIV1 no prescaler + * @arg TIM_IC_PSC_DIV2 capture is done once every 2 events + * @arg TIM_IC_PSC_DIV4 capture is done once every 4 events + * @arg TIM_IC_PSC_DIV8 capture is done once every 8 events + */ +void TIM_SetInCap3Prescaler(TIM_Module* TIMx, uint16_t TIM_ICPSC) +{ + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimIcPrescaler(TIM_ICPSC)); + /* Reset the IC3PSC Bits */ + TIMx->CCMOD2 &= (uint16_t) ~((uint16_t)TIM_CCMOD2_IC3PSC); + /* Set the IC3PSC value */ + TIMx->CCMOD2 |= TIM_ICPSC; +} + +/** + * @brief Sets the TIMx Input Capture 4 prescaler. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param TIM_ICPSC specifies the Input Capture4 prescaler new value. + * This parameter can be one of the following values: + * @arg TIM_IC_PSC_DIV1 no prescaler + * @arg TIM_IC_PSC_DIV2 capture is done once every 2 events + * @arg TIM_IC_PSC_DIV4 capture is done once every 4 events + * @arg TIM_IC_PSC_DIV8 capture is done once every 8 events + */ +void TIM_SetInCap4Prescaler(TIM_Module* TIMx, uint16_t TIM_ICPSC) +{ + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + assert_param(IsTimIcPrescaler(TIM_ICPSC)); + /* Reset the IC4PSC Bits */ + TIMx->CCMOD2 &= (uint16_t) ~((uint16_t)TIM_CCMOD2_IC4PSC); + /* Set the IC4PSC value */ + TIMx->CCMOD2 |= (uint16_t)(TIM_ICPSC << 8); +} + +/** + * @brief Sets the TIMx Clock Division value. + * @param TIMx where x can be 1 or 3 to select + * the TIM peripheral. + * @param TIM_CKD specifies the clock division value. + * This parameter can be one of the following value: + * @arg TIM_CLK_DIV1 TDTS = Tck_tim + * @arg TIM_CLK_DIV2 TDTS = 2*Tck_tim + * @arg TIM_CLK_DIV4 TDTS = 4*Tck_tim + */ +void TIM_SetClkDiv(TIM_Module* TIMx, uint16_t TIM_CKD) +{ + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + assert_param(IsTimClkDiv(TIM_CKD)); + /* Reset the CKD Bits */ + TIMx->CTRL1 &= (uint32_t) ~((uint32_t)TIM_CTRL1_CLKD); + /* Set the CKD value */ + TIMx->CTRL1 |= TIM_CKD; +} + +/** + * @brief Gets the TIMx Input Capture 1 value. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @return Capture Compare 1 Register value. + */ +uint16_t TIM_GetCap1(TIM_Module* TIMx) +{ + /* Check the parameters */ + assert_param(IsTimList8Module(TIMx)); + /* Get the Capture 1 Register value */ + return TIMx->CCDAT1; +} + +/** + * @brief Gets the TIMx Input Capture 2 value. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @return Capture Compare 2 Register value. + */ +uint16_t TIM_GetCap2(TIM_Module* TIMx) +{ + /* Check the parameters */ + assert_param(IsTimList6Module(TIMx)); + /* Get the Capture 2 Register value */ + return TIMx->CCDAT2; +} + +/** + * @brief Gets the TIMx Input Capture 3 value. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @return Capture Compare 3 Register value. + */ +uint16_t TIM_GetCap3(TIM_Module* TIMx) +{ + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + /* Get the Capture 3 Register value */ + return TIMx->CCDAT3; +} + +/** + * @brief Gets the TIMx Input Capture 4 value. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @return Capture Compare 4 Register value. + */ +uint16_t TIM_GetCap4(TIM_Module* TIMx) +{ + /* Check the parameters */ + assert_param(IsTimList3Module(TIMx)); + /* Get the Capture 4 Register value */ + return TIMx->CCDAT4; +} + +/** + * @brief Gets the TIMx Counter value. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @return Counter Register value. + */ +uint16_t TIM_GetCnt(TIM_Module* TIMx) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + /* Get the Counter Register value */ + return TIMx->CNT; +} + +/** + * @brief Gets the TIMx Prescaler value. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @return Prescaler Register value. + */ +uint16_t TIM_GetPrescaler(TIM_Module* TIMx) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + /* Get the Prescaler Register value */ + return TIMx->PSC; +} + +/** + * @brief Checks whether the specified TIM flag is set or not. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param TIM_FLAG specifies the flag to check. + * This parameter can be one of the following values: + * @arg TIM_FLAG_UPDATE TIM update Flag + * @arg TIM_FLAG_CC1 TIM Capture Compare 1 Flag + * @arg TIM_FLAG_CC2 TIM Capture Compare 2 Flag + * @arg TIM_FLAG_CC3 TIM Capture Compare 3 Flag + * @arg TIM_FLAG_CC4 TIM Capture Compare 4 Flag + * @arg TIM_FLAG_COM TIM Commutation Flag + * @arg TIM_FLAG_TRIG TIM Trigger Flag + * @arg TIM_FLAG_BREAK TIM Break Flag + * @arg TIM_FLAG_CC1OF TIM Capture Compare 1 overcapture Flag + * @arg TIM_FLAG_CC2OF TIM Capture Compare 2 overcapture Flag + * @arg TIM_FLAG_CC3OF TIM Capture Compare 3 overcapture Flag + * @arg TIM_FLAG_CC4OF TIM Capture Compare 4 overcapture Flag + * @arg TIM_FLAG_CC5 TIM Capture Compare 5 Flag + * @arg TIM_FLAG_CC6 TIM Capture Compare 6 Flag + * @note + * - TIM6 can have only one update flag. + * - TIM_FLAG_BREAK is used only with TIM1. + * - TIM_FLAG_COM is used only with TIM1. + * @return The new state of TIM_FLAG (SET or RESET). + */ +FlagStatus TIM_GetFlagStatus(TIM_Module* TIMx, uint32_t TIM_FLAG) +{ + INTStatus bitstatus = RESET; + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IsTimGetFlag(TIM_FLAG)); + + if ((TIMx->STS & TIM_FLAG) != (uint32_t)RESET) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/** + * @brief Clears the TIMx's pending flags. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param TIM_FLAG specifies the flag bit to clear. + * This parameter can be any combination of the following values: + * @arg TIM_FLAG_UPDATE TIM update Flag + * @arg TIM_FLAG_CC1 TIM Capture Compare 1 Flag + * @arg TIM_FLAG_CC2 TIM Capture Compare 2 Flag + * @arg TIM_FLAG_CC3 TIM Capture Compare 3 Flag + * @arg TIM_FLAG_CC4 TIM Capture Compare 4 Flag + * @arg TIM_FLAG_COM TIM Commutation Flag + * @arg TIM_FLAG_TRIG TIM Trigger Flag + * @arg TIM_FLAG_BREAK TIM Break Flag + * @arg TIM_FLAG_CC1OF TIM Capture Compare 1 overcapture Flag + * @arg TIM_FLAG_CC2OF TIM Capture Compare 2 overcapture Flag + * @arg TIM_FLAG_CC3OF TIM Capture Compare 3 overcapture Flag + * @arg TIM_FLAG_CC4OF TIM Capture Compare 4 overcapture Flag + * @note + * - TIM6 can have only one update flag. + * - TIM_FLAG_BREAK is used only with TIM1. + * - TIM_FLAG_COM is used only with TIM1. + */ +void TIM_ClearFlag(TIM_Module* TIMx, uint32_t TIM_FLAG) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IsTimClrFlag(TIM_FLAG)); + + /* Clear the flags */ + TIMx->STS &= (uint32_t)~TIM_FLAG; +} + +/** + * @brief Checks whether the TIM interrupt has occurred or not. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param TIM_IT specifies the TIM interrupt source to check. + * This parameter can be one of the following values: + * @arg TIM_INT_UPDATE TIM update Interrupt source + * @arg TIM_INT_CC1 TIM Capture Compare 1 Interrupt source + * @arg TIM_INT_CC2 TIM Capture Compare 2 Interrupt source + * @arg TIM_INT_CC3 TIM Capture Compare 3 Interrupt source + * @arg TIM_INT_CC4 TIM Capture Compare 4 Interrupt source + * @arg TIM_INT_COM TIM Commutation Interrupt source + * @arg TIM_INT_TRIG TIM Trigger Interrupt source + * @arg TIM_INT_BREAK TIM Break Interrupt source + * @note + * - TIM6 can generate only an update interrupt. + * - TIM_INT_BREAK is used only with TIM1. + * - TIM_INT_COM is used only with TIM1. + * @return The new state of the TIM_IT(SET or RESET). + */ +INTStatus TIM_GetIntStatus(TIM_Module* TIMx, uint32_t TIM_IT) +{ + INTStatus bitstatus = RESET; + uint32_t itstatus = 0x0, itenable = 0x0; + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IsTimGetInt(TIM_IT)); + + itstatus = TIMx->STS & TIM_IT; + + itenable = TIMx->DINTEN & TIM_IT; + if ((itstatus != (uint32_t)RESET) && (itenable != (uint32_t)RESET)) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/** + * @brief Clears the TIMx's interrupt pending bits. + * @param TIMx where x can be 1, 3 or 6 to select the TIM peripheral. + * @param TIM_IT specifies the pending bit to clear. + * This parameter can be any combination of the following values: + * @arg TIM_INT_UPDATE TIM1 update Interrupt source + * @arg TIM_INT_CC1 TIM Capture Compare 1 Interrupt source + * @arg TIM_INT_CC2 TIM Capture Compare 2 Interrupt source + * @arg TIM_INT_CC3 TIM Capture Compare 3 Interrupt source + * @arg TIM_INT_CC4 TIM Capture Compare 4 Interrupt source + * @arg TIM_INT_COM TIM Commutation Interrupt source + * @arg TIM_INT_TRIG TIM Trigger Interrupt source + * @arg TIM_INT_BREAK TIM Break Interrupt source + * @note + * - TIM6 can generate only an update interrupt. + * - TIM_INT_BREAK is used only with TIM1. + * - TIM_INT_COM is used only with TIM1. + */ +void TIM_ClrIntPendingBit(TIM_Module* TIMx, uint32_t TIM_IT) +{ + /* Check the parameters */ + assert_param(IsTimAllModule(TIMx)); + assert_param(IsTimInt(TIM_IT)); + /* Clear the IT pending Bit */ + TIMx->STS &= (uint32_t)~TIM_IT; +} + +/** + * @brief Configure the TI1 as Input. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param IcPolarity The Input Polarity. + * This parameter can be one of the following values: + * @arg TIM_IC_POLARITY_RISING + * @arg TIM_IC_POLARITY_FALLING + * @param IcSelection specifies the input to be used. + * This parameter can be one of the following values: + * @arg TIM_IC_SELECTION_DIRECTTI TIM Input 1 is selected to be connected to IC1. + * @arg TIM_IC_SELECTION_INDIRECTTI TIM Input 1 is selected to be connected to IC2. + * @arg TIM_IC_SELECTION_TRC TIM Input 1 is selected to be connected to TRC. + * @param IcFilter Specifies the Input Capture Filter. + * This parameter must be a value between 0x00 and 0x0F. + */ +static void ConfigTI1(TIM_Module* TIMx, uint16_t IcPolarity, uint16_t IcSelection, uint16_t IcFilter) +{ + uint16_t tmpccmr1 = 0; + uint32_t tmpccer = 0; + /* Disable the Channel 1: Reset the CC1E Bit */ + TIMx->CCEN &= (uint32_t) ~((uint32_t)TIM_CCEN_CC1EN); + tmpccmr1 = TIMx->CCMOD1; + tmpccer = TIMx->CCEN; + /* Select the Input and set the filter */ + tmpccmr1 &= (uint16_t)(((uint16_t) ~((uint16_t)TIM_CCMOD1_CC1SEL)) & ((uint16_t) ~((uint16_t)TIM_CCMOD1_IC1F))); + tmpccmr1 |= (uint16_t)(IcSelection | (uint16_t)(IcFilter << (uint16_t)4)); + + if ((TIMx == TIM1) || (TIMx == TIM3)) + { + /* Select the Polarity and set the CC1E Bit */ + tmpccer &= (uint32_t) ~((uint32_t)(TIM_CCEN_CC1P)); + tmpccer |= (uint32_t)(IcPolarity | (uint32_t)TIM_CCEN_CC1EN); + } + else + { + /* Select the Polarity and set the CC1E Bit */ + tmpccer &= (uint32_t) ~((uint32_t)(TIM_CCEN_CC1P | TIM_CCEN_CC1NP)); + tmpccer |= (uint32_t)(IcPolarity | (uint32_t)TIM_CCEN_CC1EN); + } + + /* Write to TIMx CCMOD1 and CCEN registers */ + TIMx->CCMOD1 = tmpccmr1; + TIMx->CCEN = tmpccer; +} + +/** + * @brief Configure the TI2 as Input. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param IcPolarity The Input Polarity. + * This parameter can be one of the following values: + * @arg TIM_IC_POLARITY_RISING + * @arg TIM_IC_POLARITY_FALLING + * @param IcSelection specifies the input to be used. + * This parameter can be one of the following values: + * @arg TIM_IC_SELECTION_DIRECTTI TIM Input 2 is selected to be connected to IC2. + * @arg TIM_IC_SELECTION_INDIRECTTI TIM Input 2 is selected to be connected to IC1. + * @arg TIM_IC_SELECTION_TRC TIM Input 2 is selected to be connected to TRC. + * @param IcFilter Specifies the Input Capture Filter. + * This parameter must be a value between 0x00 and 0x0F. + */ +static void ConfigTI2(TIM_Module* TIMx, uint16_t IcPolarity, uint16_t IcSelection, uint16_t IcFilter) +{ + uint16_t tmpccmr1 = 0; + uint32_t tmpccer = 0, tmp = 0; + /* Disable the Channel 2: Reset the CC2E Bit */ + TIMx->CCEN &= (uint32_t) ~((uint32_t)TIM_CCEN_CC2EN); + tmpccmr1 = TIMx->CCMOD1; + tmpccer = TIMx->CCEN; + tmp = (uint32_t)(IcPolarity << 4); + /* Select the Input and set the filter */ + tmpccmr1 &= (uint16_t)(((uint16_t) ~((uint16_t)TIM_CCMOD1_CC2SEL)) & ((uint16_t) ~((uint16_t)TIM_CCMOD1_IC2F))); + tmpccmr1 |= (uint16_t)(IcFilter << 12); + tmpccmr1 |= (uint16_t)(IcSelection << 8); + + if ((TIMx == TIM1) || (TIMx == TIM3)) + { + /* Select the Polarity and set the CC2E Bit */ + tmpccer &= (uint32_t) ~((uint32_t)(TIM_CCEN_CC2P)); + tmpccer |= (uint32_t)(tmp | (uint32_t)TIM_CCEN_CC2EN); + } + else + { + /* Select the Polarity and set the CC2E Bit */ + tmpccer &= (uint32_t) ~((uint32_t)(TIM_CCEN_CC2P | TIM_CCEN_CC2NP)); + tmpccer |= (uint32_t)(IcPolarity | (uint32_t)TIM_CCEN_CC2EN); + } + + /* Write to TIMx CCMOD1 and CCEN registers */ + TIMx->CCMOD1 = tmpccmr1; + TIMx->CCEN = tmpccer; +} + +/** + * @brief Configure the TI3 as Input. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param IcPolarity The Input Polarity. + * This parameter can be one of the following values: + * @arg TIM_IC_POLARITY_RISING + * @arg TIM_IC_POLARITY_FALLING + * @param IcSelection specifies the input to be used. + * This parameter can be one of the following values: + * @arg TIM_IC_SELECTION_DIRECTTI TIM Input 3 is selected to be connected to IC3. + * @arg TIM_IC_SELECTION_INDIRECTTI TIM Input 3 is selected to be connected to IC4. + * @arg TIM_IC_SELECTION_TRC TIM Input 3 is selected to be connected to TRC. + * @param IcFilter Specifies the Input Capture Filter. + * This parameter must be a value between 0x00 and 0x0F. + */ +static void ConfigTI3(TIM_Module* TIMx, uint16_t IcPolarity, uint16_t IcSelection, uint16_t IcFilter) +{ + uint16_t tmpccmr2 = 0; + uint32_t tmpccer = 0, tmp = 0; + /* Disable the Channel 3: Reset the CC3E Bit */ + TIMx->CCEN &= (uint32_t) ~((uint32_t)TIM_CCEN_CC3EN); + tmpccmr2 = TIMx->CCMOD2; + tmpccer = TIMx->CCEN; + tmp = (uint32_t)(IcPolarity << 8); + /* Select the Input and set the filter */ + tmpccmr2 &= (uint16_t)(((uint16_t) ~((uint16_t)TIM_CCMOD2_CC3SEL)) & ((uint16_t) ~((uint16_t)TIM_CCMOD2_IC3F))); + tmpccmr2 |= (uint16_t)(IcSelection | (uint16_t)(IcFilter << (uint16_t)4)); + + if ((TIMx == TIM1) || (TIMx == TIM3)) + { + /* Select the Polarity and set the CC3E Bit */ + tmpccer &= (uint32_t) ~((uint32_t)(TIM_CCEN_CC3P)); + tmpccer |= (uint32_t)(tmp | (uint32_t)TIM_CCEN_CC3EN); + } + else + { + /* Select the Polarity and set the CC3E Bit */ + tmpccer &= (uint32_t) ~((uint32_t)(TIM_CCEN_CC3P | TIM_CCEN_CC3NP)); + tmpccer |= (uint32_t)(IcPolarity | (uint32_t)TIM_CCEN_CC3EN); + } + + /* Write to TIMx CCMOD2 and CCEN registers */ + TIMx->CCMOD2 = tmpccmr2; + TIMx->CCEN = tmpccer; +} + +/** + * @brief Configure the TI4 as Input. + * @param TIMx where x can be 1 or 3 to select the TIM peripheral. + * @param IcPolarity The Input Polarity. + * This parameter can be one of the following values: + * @arg TIM_IC_POLARITY_RISING + * @arg TIM_IC_POLARITY_FALLING + * @param IcSelection specifies the input to be used. + * This parameter can be one of the following values: + * @arg TIM_IC_SELECTION_DIRECTTI TIM Input 4 is selected to be connected to IC4. + * @arg TIM_IC_SELECTION_INDIRECTTI TIM Input 4 is selected to be connected to IC3. + * @arg TIM_IC_SELECTION_TRC TIM Input 4 is selected to be connected to TRC. + * @param IcFilter Specifies the Input Capture Filter. + * This parameter must be a value between 0x00 and 0x0F. + */ +static void ConfigTI4(TIM_Module* TIMx, uint16_t IcPolarity, uint16_t IcSelection, uint16_t IcFilter) +{ + uint16_t tmpccmr2 = 0; + uint32_t tmpccer = 0, tmp = 0; + + /* Disable the Channel 4: Reset the CC4E Bit */ + TIMx->CCEN &= (uint32_t) ~((uint32_t)TIM_CCEN_CC4EN); + tmpccmr2 = TIMx->CCMOD2; + tmpccer = TIMx->CCEN; + tmp = (uint32_t)(IcPolarity << 12); + /* Select the Input and set the filter */ + tmpccmr2 &= (uint16_t)((uint16_t)(~(uint16_t)TIM_CCMOD2_CC4SEL) & ((uint16_t) ~((uint16_t)TIM_CCMOD2_IC4F))); + tmpccmr2 |= (uint16_t)(IcSelection << 8); + tmpccmr2 |= (uint16_t)(IcFilter << 12); + + if ((TIMx == TIM1) || (TIMx == TIM3)) + { + /* Select the Polarity and set the CC4E Bit */ + tmpccer &= (uint32_t) ~((uint32_t)(TIM_CCEN_CC4P)); + tmpccer |= (uint32_t)(tmp | (uint32_t)TIM_CCEN_CC4EN); + } + else + { + /* Select the Polarity and set the CC4E Bit */ + tmpccer &= (uint32_t) ~((uint32_t)(TIM_CCEN_CC4P)); + tmpccer |= (uint32_t)(IcPolarity | (uint32_t)TIM_CCEN_CC4EN); + } + /* Write to TIMx CCMOD2 and CCEN registers */ + TIMx->CCMOD2 = tmpccmr2; + TIMx->CCEN = tmpccer; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_usart.c new file mode 100644 index 0000000..4499d19 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_usart.c @@ -0,0 +1,963 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_usart.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_usart.h" +#include "n32wb03x_rcc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup USART + * @brief USART driver modules + * @{ + */ + +/** @addtogroup USART_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup USART_Private_Defines + * @{ + */ + +#define CTRL1_UEN_SET ((uint16_t)0x2000) /*!< USART Enable Mask */ +#define CTRL1_UEN_RESET ((uint16_t)0xDFFF) /*!< USART Disable Mask */ + +#define CTRL1_WUM_MASK ((uint16_t)0xF7FF) /*!< USART WakeUp Method Mask */ + +#define CTRL1_RCVWU_SET ((uint16_t)0x0002) /*!< USART mute mode Enable Mask */ +#define CTRL1_RCVWU_RESET ((uint16_t)0xFFFD) /*!< USART mute mode Enable Mask */ +#define CTRL1_SDBRK_SET ((uint16_t)0x0001) /*!< USART Break Character send Mask */ +#define CTRL1_CLR_MASK ((uint16_t)0xE9F3) /*!< USART CTRL1 Mask */ +#define CTRL2_ADDR_MASK ((uint16_t)0xFFF0) /*!< USART address Mask */ + +#define CTRL2_LINMEN_SET ((uint16_t)0x4000) /*!< USART LIN Enable Mask */ +#define CTRL2_LINMEN_RESET ((uint16_t)0xBFFF) /*!< USART LIN Disable Mask */ + +#define CTRL2_LINBDL_MASK ((uint16_t)0xFFDF) /*!< USART LIN Break detection Mask */ +#define CTRL2_STPB_CLR_MASK ((uint16_t)0xCFFF) /*!< USART CTRL2 STOP Bits Mask */ +#define CTRL2_CLOCK_CLR_MASK ((uint16_t)0xF0FF) /*!< USART CTRL2 Clock Mask */ + +#define CTRL3_SCMEN_SET ((uint16_t)0x0020) /*!< USART SC Enable Mask */ +#define CTRL3_SCMEN_RESET ((uint16_t)0xFFDF) /*!< USART SC Disable Mask */ + +#define CTRL3_SCNACK_SET ((uint16_t)0x0010) /*!< USART SC NACK Enable Mask */ +#define CTRL3_SCNACK_RESET ((uint16_t)0xFFEF) /*!< USART SC NACK Disable Mask */ + +#define CTRL3_HDMEN_SET ((uint16_t)0x0008) /*!< USART Half-Duplex Enable Mask */ +#define CTRL3_HDMEN_RESET ((uint16_t)0xFFF7) /*!< USART Half-Duplex Disable Mask */ + +#define CTRL3_IRDALP_MASK ((uint16_t)0xFFFB) /*!< USART IrDA LowPower mode Mask */ +#define CTRL3_CLR_MASK ((uint16_t)0xFCFF) /*!< USART CTRL3 Mask */ + +#define CTRL3_IRDAMEN_SET ((uint16_t)0x0002) /*!< USART IrDA Enable Mask */ +#define CTRL3_IRDAMEN_RESET ((uint16_t)0xFFFD) /*!< USART IrDA Disable Mask */ +#define GTP_LSB_MASK ((uint16_t)0x00FF) /*!< Guard Time Register LSB Mask */ +#define GTP_MSB_MASK ((uint16_t)0xFF00) /*!< Guard Time Register MSB Mask */ +#define INT_MASK ((uint16_t)0x001F) /*!< USART Interrupt Mask */ + +/** + * @} + */ + +/** @addtogroup USART_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup USART_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup USART_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup USART_Private_Functions + * @{ + */ + +/** + * @brief Deinitializes the USARTx peripheral registers to their default reset values. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + */ +void USART_DeInit(USART_Module* USARTx) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + + if (USARTx == USART1) + { + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_USART1, ENABLE); + RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_USART1, DISABLE); + } + else + { + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_USART2, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_USART2, DISABLE); + } + +} + +/** + * @brief Initializes the USARTx peripheral according to the specified + * parameters in the USART_InitStruct . + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1, USART2 + * @param USART_InitStruct pointer to a USART_InitType structure + * that contains the configuration information for the specified USART + * peripheral. + */ +void USART_Init(USART_Module* USARTx, USART_InitType* USART_InitStruct) +{ + uint32_t tmpregister = 0x00, apbclock = 0x00; + uint32_t integerdivider = 0x00; + uint32_t fractionaldivider = 0x00; + uint32_t usartxbase = 0; + RCC_ClocksType RCC_ClocksStatus; + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_BAUDRATE(USART_InitStruct->BaudRate)); + assert_param(IS_USART_WORD_LENGTH(USART_InitStruct->WordLength)); + assert_param(IS_USART_STOPBITS(USART_InitStruct->StopBits)); + assert_param(IS_USART_PARITY(USART_InitStruct->Parity)); + assert_param(IS_USART_MODE(USART_InitStruct->Mode)); + assert_param(IS_USART_HARDWARE_FLOW_CONTROL(USART_InitStruct->HardwareFlowControl)); + /* The hardware flow control is available only for USART1, USART2 and USART3 */ + if (USART_InitStruct->HardwareFlowControl != USART_HFCTRL_NONE) + { + assert_param(IS_USART_12_PERIPH(USARTx)); + } + + usartxbase = (uint32_t)USARTx; + + /*---------------------------- USART CTRL2 Configuration -----------------------*/ + tmpregister = USARTx->CTRL2; + /* Clear STOP[13:12] bits */ + tmpregister &= CTRL2_STPB_CLR_MASK; + /* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit ------------*/ + /* Set STOP[13:12] bits according to StopBits value */ + tmpregister |= (uint32_t)USART_InitStruct->StopBits; + + /* Write to USART CTRL2 */ + USARTx->CTRL2 = (uint16_t)tmpregister; + + /*---------------------------- USART CTRL1 Configuration -----------------------*/ + tmpregister = USARTx->CTRL1; + /* Clear M, PCE, PS, TE and RE bits */ + tmpregister &= CTRL1_CLR_MASK; + /* Configure the USART Word Length, Parity and mode ----------------------- */ + /* Set the M bits according to WordLength value */ + /* Set PCE and PS bits according to Parity value */ + /* Set TE and RE bits according to Mode value */ + tmpregister |= (uint32_t)USART_InitStruct->WordLength | USART_InitStruct->Parity | USART_InitStruct->Mode; + /* Write to USART CTRL1 */ + USARTx->CTRL1 = (uint16_t)tmpregister; + + /*---------------------------- USART CTRL3 Configuration -----------------------*/ + tmpregister = USARTx->CTRL3; + /* Clear CTSE and RTSE bits */ + tmpregister &= CTRL3_CLR_MASK; + /* Configure the USART HFC -------------------------------------------------*/ + /* Set CTSE and RTSE bits according to HardwareFlowControl value */ + tmpregister |= USART_InitStruct->HardwareFlowControl; + /* Write to USART CTRL3 */ + USARTx->CTRL3 = (uint16_t)tmpregister; + + /*---------------------------- USART PBC Configuration -----------------------*/ + /* Configure the USART Baud Rate -------------------------------------------*/ + RCC_GetClocksFreqValue(&RCC_ClocksStatus); + if (usartxbase == USART1_BASE) + { + apbclock = RCC_ClocksStatus.Pclk2Freq; + } + else + { + apbclock = RCC_ClocksStatus.Pclk1Freq; + } + + /* Determine the integer part */ + integerdivider = ((25 * apbclock) / (4 * (USART_InitStruct->BaudRate))); + tmpregister = (integerdivider / 100) << 4; + + /* Determine the fractional part */ + fractionaldivider = integerdivider - (100 * (tmpregister >> 4)); + + /* Implement the fractional part in the register */ + tmpregister |= ((((fractionaldivider * 16) + 50) / 100)) & ((uint8_t)0x0F); + + /* Write to USART PBC */ + USARTx->BRCF = (uint16_t)tmpregister; +} + +/** + * @brief Fills each USART_InitStruct member with its default value. + * @param USART_InitStruct pointer to a USART_InitType structure + * which will be initialized. + */ +void USART_StructInit(USART_InitType* USART_InitStruct) +{ + /* USART_InitStruct members default value */ + USART_InitStruct->BaudRate = 9600; + USART_InitStruct->WordLength = USART_WL_8B; + USART_InitStruct->StopBits = USART_STPB_1; + USART_InitStruct->Parity = USART_PE_NO; + USART_InitStruct->Mode = USART_MODE_RX | USART_MODE_TX; + USART_InitStruct->HardwareFlowControl = USART_HFCTRL_NONE; +} + +/** + * @brief Initializes the USARTx peripheral Clock according to the + * specified parameters in the USART_ClockInitStruct . + * @param USARTx where x can be 1 or 2 to select the USART peripheral. + * @param USART_ClockInitStruct pointer to a USART_ClockInitType + * structure that contains the configuration information for the specified + * USART peripheral. + * @note + */ +void USART_ClockInit(USART_Module* USARTx, USART_ClockInitType* USART_ClockInitStruct) +{ + uint32_t tmpregister = 0x00; + /* Check the parameters */ + assert_param(IS_USART_12_PERIPH(USARTx)); + assert_param(IS_USART_CLOCK(USART_ClockInitStruct->Clock)); + assert_param(IS_USART_CPOL(USART_ClockInitStruct->Polarity)); + assert_param(IS_USART_CPHA(USART_ClockInitStruct->Phase)); + assert_param(IS_USART_LASTBIT(USART_ClockInitStruct->LastBit)); + + /*---------------------------- USART CTRL2 Configuration -----------------------*/ + tmpregister = USARTx->CTRL2; + /* Clear CLKEN, CPOL, CPHA and LBCL bits */ + tmpregister &= CTRL2_CLOCK_CLR_MASK; + /* Configure the USART Clock, CPOL, CPHA and LastBit ------------*/ + /* Set CLKEN bit according to Clock value */ + /* Set CPOL bit according to Polarity value */ + /* Set CPHA bit according to Phase value */ + /* Set LBCL bit according to LastBit value */ + tmpregister |= (uint32_t)USART_ClockInitStruct->Clock | USART_ClockInitStruct->Polarity + | USART_ClockInitStruct->Phase | USART_ClockInitStruct->LastBit; + /* Write to USART CTRL2 */ + USARTx->CTRL2 = (uint16_t)tmpregister; +} + +/** + * @brief Fills each USART_ClockInitStruct member with its default value. + * @param USART_ClockInitStruct pointer to a USART_ClockInitType + * structure which will be initialized. + */ +void USART_ClockStructInit(USART_ClockInitType* USART_ClockInitStruct) +{ + /* USART_ClockInitStruct members default value */ + USART_ClockInitStruct->Clock = USART_CLK_DISABLE; + USART_ClockInitStruct->Polarity = USART_CLKPOL_LOW; + USART_ClockInitStruct->Phase = USART_CLKPHA_1EDGE; + USART_ClockInitStruct->LastBit = USART_CLKLB_DISABLE; +} + +/** + * @brief Enables or disables the specified USART peripheral. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param Cmd new state of the USARTx peripheral. + * This parameter can be: ENABLE or DISABLE. + */ +void USART_Enable(USART_Module* USARTx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the selected USART by setting the UE bit in the CTRL1 register */ + USARTx->CTRL1 |= CTRL1_UEN_SET; + } + else + { + /* Disable the selected USART by clearing the UE bit in the CTRL1 register */ + USARTx->CTRL1 &= CTRL1_UEN_RESET; + } +} + +/** + * @brief Enables or disables the specified USART interrupts. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param USART_INT specifies the USART interrupt sources to be enabled or disabled. + * This parameter can be one of the following values: + * @arg USART_INT_CTSF CTS change interrupt + * @arg USART_INT_LINBD LIN Break detection interrupt + * @arg USART_INT_TXDE Transmit Data Register empty interrupt + * @arg USART_INT_TXC Transmission complete interrupt + * @arg USART_INT_RXDNE Receive Data register not empty interrupt + * @arg USART_INT_IDLEF Idle line detection interrupt + * @arg USART_INT_PEF Parity Error interrupt + * @arg USART_INT_ERRF Error interrupt(Frame error, noise error, overrun error) + * @param Cmd new state of the specified USARTx interrupts. + * This parameter can be: ENABLE or DISABLE. + */ +void USART_ConfigInt(USART_Module* USARTx, uint16_t USART_INT, FunctionalState Cmd) +{ + uint32_t usartreg = 0x00, itpos = 0x00, itmask = 0x00; + uint32_t usartxbase = 0x00; + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_CFG_INT(USART_INT)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (USART_INT == USART_INT_CTSF) + { + assert_param(IS_USART_12_PERIPH(USARTx)); + } + + usartxbase = (uint32_t)USARTx; + + /* Get the USART register index */ + usartreg = (((uint8_t)USART_INT) >> 0x05); + + /* Get the interrupt position */ + itpos = USART_INT & INT_MASK; + itmask = (((uint32_t)0x01) << itpos); + + if (usartreg == 0x01) /* The IT is in CTRL1 register */ + { + usartxbase += 0x0C; + } + else if (usartreg == 0x02) /* The IT is in CTRL2 register */ + { + usartxbase += 0x10; + } + else /* The IT is in CTRL3 register */ + { + usartxbase += 0x14; + } + if (Cmd != DISABLE) + { + *(__IO uint32_t*)usartxbase |= itmask; + } + else + { + *(__IO uint32_t*)usartxbase &= ~itmask; + } +} + +/** + * @brief Enables or disables the USART's DMA interface. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param USART_DMAReq specifies the DMA request. + * This parameter can be any combination of the following values: + * @arg USART_DMAREQ_TX USART DMA transmit request + * @arg USART_DMAREQ_RX USART DMA receive request + * @param Cmd new state of the DMA Request sources. + * This parameter can be: ENABLE or DISABLE. + */ +void USART_EnableDMA(USART_Module* USARTx, uint16_t USART_DMAReq, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_DMAREQ(USART_DMAReq)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the DMA transfer for selected requests by setting the DMAT and/or + DADDR bits in the USART CTRL3 register */ + USARTx->CTRL3 |= USART_DMAReq; + } + else + { + /* Disable the DMA transfer for selected requests by clearing the DMAT and/or + DADDR bits in the USART CTRL3 register */ + USARTx->CTRL3 &= (uint16_t)~USART_DMAReq; + } +} + +/** + * @brief Sets the address of the USART node. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param USART_Addr Indicates the address of the USART node. + */ +void USART_SetAddr(USART_Module* USARTx, uint8_t USART_Addr) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_ADDRESS(USART_Addr)); + + /* Clear the USART address */ + USARTx->CTRL2 &= CTRL2_ADDR_MASK; + /* Set the USART address node */ + USARTx->CTRL2 |= USART_Addr; +} + +/** + * @brief Selects the USART WakeUp method. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param USART_WakeUpMode specifies the USART wakeup method. + * This parameter can be one of the following values: + * @arg USART_WUM_IDLELINE WakeUp by an idle line detection + * @arg USART_WUM_ADDRMASK WakeUp by an address mark + */ +void USART_ConfigWakeUpMode(USART_Module* USARTx, uint16_t USART_WakeUpMode) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_WAKEUP(USART_WakeUpMode)); + + USARTx->CTRL1 &= CTRL1_WUM_MASK; + USARTx->CTRL1 |= USART_WakeUpMode; +} + +/** + * @brief Determines if the USART is in mute mode or not. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param Cmd new state of the USART mute mode. + * This parameter can be: ENABLE or DISABLE. + */ +void USART_EnableRcvWakeUp(USART_Module* USARTx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the USART mute mode by setting the RWU bit in the CTRL1 register */ + USARTx->CTRL1 |= CTRL1_RCVWU_SET; + } + else + { + /* Disable the USART mute mode by clearing the RWU bit in the CTRL1 register */ + USARTx->CTRL1 &= CTRL1_RCVWU_RESET; + } +} + +/** + * @brief Sets the USART LIN Break detection length. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param USART_LINBreakDetectLength specifies the LIN break detection length. + * This parameter can be one of the following values: + * @arg USART_LINBDL_10B 10-bit break detection + * @arg USART_LINBDL_11B 11-bit break detection + */ +void USART_ConfigLINBreakDetectLength(USART_Module* USARTx, uint16_t USART_LINBreakDetectLength) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength)); + + USARTx->CTRL2 &= CTRL2_LINBDL_MASK; + USARTx->CTRL2 |= USART_LINBreakDetectLength; +} + +/** + * @brief Enables or disables the USART's LIN mode. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param Cmd new state of the USART LIN mode. + * This parameter can be: ENABLE or DISABLE. + */ +void USART_EnableLIN(USART_Module* USARTx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the LIN mode by setting the LINEN bit in the CTRL2 register */ + USARTx->CTRL2 |= CTRL2_LINMEN_SET; + } + else + { + /* Disable the LIN mode by clearing the LINEN bit in the CTRL2 register */ + USARTx->CTRL2 &= CTRL2_LINMEN_RESET; + } +} + +/** + * @brief Transmits single data through the USARTx peripheral. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param Data the data to transmit. + */ +void USART_SendData(USART_Module* USARTx, uint16_t Data) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_DATA(Data)); + + /* Transmit Data */ + USARTx->DAT = (Data & (uint16_t)0x01FF); +} + +/** + * @brief Returns the most recent received data by the USARTx peripheral. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @return The received data. + */ +uint16_t USART_ReceiveData(USART_Module* USARTx) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + + /* Receive Data */ + return (uint16_t)(USARTx->DAT & (uint16_t)0x01FF); +} + +/** + * @brief Transmits break characters. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + */ +void USART_SendBreak(USART_Module* USARTx) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + + /* Send break characters */ + USARTx->CTRL1 |= CTRL1_SDBRK_SET; +} + +/** + * @brief Sets the specified USART guard time. + * @param USARTx where x can be 1 or 2 to select the USART peripheral. + * @param USART_GuardTime specifies the guard time. + * @note + */ +void USART_SetGuardTime(USART_Module* USARTx, uint8_t USART_GuardTime) +{ + /* Check the parameters */ + assert_param(IS_USART_12_PERIPH(USARTx)); + + /* Clear the USART Guard time */ + USARTx->GTP &= GTP_LSB_MASK; + /* Set the USART guard time */ + USARTx->GTP |= (uint16_t)((uint16_t)USART_GuardTime << 0x08); +} + +/** + * @brief Sets the system clock prescaler. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param USART_Prescaler specifies the prescaler clock. + * @note + */ +void USART_SetPrescaler(USART_Module* USARTx, uint8_t USART_Prescaler) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + + /* Clear the USART prescaler */ + USARTx->GTP &= GTP_MSB_MASK; + /* Set the USART prescaler */ + USARTx->GTP |= USART_Prescaler; +} + +/** + * @brief Enables or disables the USART's Smart Card mode. + * @param USARTx where x can be 1 or 2 to select the USART peripheral. + * @param Cmd new state of the Smart Card mode. + * This parameter can be: ENABLE or DISABLE. + * @note + */ +void USART_EnableSmartCard(USART_Module* USARTx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_USART_12_PERIPH(USARTx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the SC mode by setting the SCEN bit in the CTRL3 register */ + USARTx->CTRL3 |= CTRL3_SCMEN_SET; + } + else + { + /* Disable the SC mode by clearing the SCEN bit in the CTRL3 register */ + USARTx->CTRL3 &= CTRL3_SCMEN_RESET; + } +} + +/** + * @brief Enables or disables NACK transmission. + * @param USARTx where x can be 1 or 2 to select the USART peripheral. + * @param Cmd new state of the NACK transmission. + * This parameter can be: ENABLE or DISABLE. + * @note + */ +void USART_SetSmartCardNACK(USART_Module* USARTx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_USART_12_PERIPH(USARTx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + if (Cmd != DISABLE) + { + /* Enable the NACK transmission by setting the NACK bit in the CTRL3 register */ + USARTx->CTRL3 |= CTRL3_SCNACK_SET; + } + else + { + /* Disable the NACK transmission by clearing the NACK bit in the CTRL3 register */ + USARTx->CTRL3 &= CTRL3_SCNACK_RESET; + } +} + +/** + * @brief Enables or disables the USART's Half Duplex communication. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param Cmd new state of the USART Communication. + * This parameter can be: ENABLE or DISABLE. + */ +void USART_EnableHalfDuplex(USART_Module* USARTx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the Half-Duplex mode by setting the HDSEL bit in the CTRL3 register */ + USARTx->CTRL3 |= CTRL3_HDMEN_SET; + } + else + { + /* Disable the Half-Duplex mode by clearing the HDSEL bit in the CTRL3 register */ + USARTx->CTRL3 &= CTRL3_HDMEN_RESET; + } +} + +/** + * @brief Configures the USART's IrDA interface. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param USART_IrDAMode specifies the IrDA mode. + * This parameter can be one of the following values: + * @arg USART_IRDAMODE_LOWPOWER + * @arg USART_IRDAMODE_NORMAL + */ +void USART_ConfigIrDAMode(USART_Module* USARTx, uint16_t USART_IrDAMode) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_IRDA_MODE(USART_IrDAMode)); + + USARTx->CTRL3 &= CTRL3_IRDALP_MASK; + USARTx->CTRL3 |= USART_IrDAMode; +} + +/** + * @brief Enables or disables the USART's IrDA interface. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param Cmd new state of the IrDA mode. + * This parameter can be: ENABLE or DISABLE. + */ +void USART_EnableIrDA(USART_Module* USARTx, FunctionalState Cmd) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_FUNCTIONAL_STATE(Cmd)); + + if (Cmd != DISABLE) + { + /* Enable the IrDA mode by setting the IREN bit in the CTRL3 register */ + USARTx->CTRL3 |= CTRL3_IRDAMEN_SET; + } + else + { + /* Disable the IrDA mode by clearing the IREN bit in the CTRL3 register */ + USARTx->CTRL3 &= CTRL3_IRDAMEN_RESET; + } +} + +/** + * @brief Checks whether the specified USART flag is set or not. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param USART_FLAG specifies the flag to check. + * This parameter can be one of the following values: + * @arg USART_FLAG_CTSF CTS Change flag + * @arg USART_FLAG_LINBD LIN Break detection flag + * @arg USART_FLAG_TXDE Transmit data register empty flag + * @arg USART_FLAG_TXC Transmission Complete flag + * @arg USART_FLAG_RXDNE Receive data register not empty flag + * @arg USART_FLAG_IDLEF Idle Line detection flag + * @arg USART_FLAG_OREF OverRun Error flag + * @arg USART_FLAG_NEF Noise Error flag + * @arg USART_FLAG_FEF Framing Error flag + * @arg USART_FLAG_PEF Parity Error flag + * @return The new state of USART_FLAG (SET or RESET). + */ +FlagStatus USART_GetFlagStatus(USART_Module* USARTx, uint16_t USART_FLAG) +{ + FlagStatus bitstatus = RESET; + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_FLAG(USART_FLAG)); + + if (USART_FLAG == USART_FLAG_CTSF) + { + assert_param(IS_USART_12_PERIPH(USARTx)); + } + + if ((USARTx->STS & USART_FLAG) != (uint16_t)RESET) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/** + * @brief Clears the USARTx's pending flags. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2 + * @param USART_FLAG specifies the flag to clear. + * This parameter can be any combination of the following values: + * @arg USART_FLAG_CTSF CTS Change flag + * @arg USART_FLAG_LINBD LIN Break detection flag. + * @arg USART_FLAG_TXC Transmission Complete flag. + * @arg USART_FLAG_RXDNE Receive data register not empty flag. + * + * @note + * - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun + * error) and IDLE (Idle line detected) flags are cleared by software + * sequence: a read operation to USART_SR register (USART_GetFlagStatus()) + * followed by a read operation to USART_DR register (USART_ReceiveData()). + * - RXNE flag can be also cleared by a read to the USART_DR register + * (USART_ReceiveData()). + * - TC flag can be also cleared by software sequence: a read operation to + * USART_SR register (USART_GetFlagStatus()) followed by a write operation + * to USART_DR register (USART_SendData()). + * - TXE flag is cleared only by a write to the USART_DR register + * (USART_SendData()). + */ +void USART_ClrFlag(USART_Module* USARTx, uint16_t USART_FLAG) +{ + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_CLEAR_FLAG(USART_FLAG)); + + if ((USART_FLAG & USART_FLAG_CTSF) == USART_FLAG_CTSF) + { + assert_param(IS_USART_12_PERIPH(USARTx)); + } + + USARTx->STS = (uint16_t)~USART_FLAG; +} + +/** + * @brief Checks whether the specified USART interrupt has occurred or not. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2. + * @param USART_INT specifies the USART interrupt source to check. + * This parameter can be one of the following values: + * @arg USART_INT_CTSF CTS change interrupt + * @arg USART_INT_LINBD LIN Break detection interrupt + * @arg USART_INT_TXDE Tansmit Data Register empty interrupt + * @arg USART_INT_TXC Transmission complete interrupt + * @arg USART_INT_RXDNE Receive Data register not empty interrupt + * @arg USART_INT_IDLEF Idle line detection interrupt + * @arg USART_INT_OREF OverRun Error interrupt + * @arg USART_INT_NEF Noise Error interrupt + * @arg USART_INT_FEF Framing Error interrupt + * @arg USART_INT_PEF Parity Error interrupt + * @return The new state of USART_INT (SET or RESET). + */ +INTStatus USART_GetIntStatus(USART_Module* USARTx, uint16_t USART_INT) +{ + uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00; + INTStatus bitstatus = RESET; + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_GET_INT(USART_INT)); + + if (USART_INT == USART_INT_CTSF) + { + assert_param(IS_USART_12_PERIPH(USARTx)); + } + + /* Get the USART register index */ + usartreg = (((uint8_t)USART_INT) >> 0x05); + /* Get the interrupt position */ + itmask = USART_INT & INT_MASK; + itmask = (uint32_t)0x01 << itmask; + + if (usartreg == 0x01) /* The IT is in CTRL1 register */ + { + itmask &= USARTx->CTRL1; + } + else if (usartreg == 0x02) /* The IT is in CTRL2 register */ + { + itmask &= USARTx->CTRL2; + } + else /* The IT is in CTRL3 register */ + { + itmask &= USARTx->CTRL3; + } + + bitpos = USART_INT >> 0x08; + bitpos = (uint32_t)0x01 << bitpos; + bitpos &= USARTx->STS; + if ((itmask != (uint16_t)RESET) && (bitpos != (uint16_t)RESET)) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + + return bitstatus; +} + +/** + * @brief Clears the USARTx's interrupt pending bits. + * @param USARTx Select the USART or the UART peripheral. + * This parameter can be one of the following values: + * USART1 or USART2. + * @param USART_INT specifies the interrupt pending bit to clear. + * This parameter can be one of the following values: + * @arg USART_INT_CTSF CTS change interrupt + * @arg USART_INT_LINBD LIN Break detection interrupt + * @arg USART_INT_TXC Transmission complete interrupt. + * @arg USART_INT_RXDNE Receive Data register not empty interrupt. + * + * @note + * - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun + * error) and IDLE (Idle line detected) pending bits are cleared by + * software sequence: a read operation to USART_SR register + * (USART_GetIntStatus()) followed by a read operation to USART_DR register + * (USART_ReceiveData()). + * - RXNE pending bit can be also cleared by a read to the USART_DR register + * (USART_ReceiveData()). + * - TC pending bit can be also cleared by software sequence: a read + * operation to USART_SR register (USART_GetIntStatus()) followed by a write + * operation to USART_DR register (USART_SendData()). + * - TXE pending bit is cleared only by a write to the USART_DR register + * (USART_SendData()). + */ +void USART_ClrIntPendingBit(USART_Module* USARTx, uint16_t USART_INT) +{ + uint16_t bitpos = 0x00, itmask = 0x00; + /* Check the parameters */ + assert_param(IS_USART_ALL_PERIPH(USARTx)); + assert_param(IS_USART_CLR_INT(USART_INT)); + + if (USART_INT == USART_INT_CTSF) + { + assert_param(IS_USART_12_PERIPH(USARTx)); + } + + bitpos = USART_INT >> 0x08; + itmask = ((uint16_t)0x01 << (uint16_t)bitpos); + USARTx->STS = (uint16_t)~itmask; +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_wwdg.c b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_wwdg.c new file mode 100644 index 0000000..b31f5e1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/firmware/n32wb03x_std_periph_driver/src/n32wb03x_wwdg.c @@ -0,0 +1,239 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_wwdg.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_wwdg.h" +#include "n32wb03x_rcc.h" + +/** @addtogroup N32WB03X_StdPeriph_Driver + * @{ + */ + +/** @addtogroup WWDG + * @brief WWDG driver modules + * @{ + */ + +/** @addtogroup WWDG_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup WWDG_Private_Defines + * @{ + */ + + + +/* --------------------- WWDG registers bit mask ------------------------ */ + +/* CTRL register bit mask */ +#define CTRL_ACTB_SET ((uint32_t)0x00000080) + +/* CFG register bit mask */ +#define CFG_TIMERB_MASK ((uint32_t)0xFFFFFE7F) +#define CFG_W_MASK ((uint32_t)0xFFFFFF80) +#define BIT_MASK ((uint8_t)0x7F) + +/** + * @} + */ + +/** @addtogroup WWDG_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup WWDG_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @addtogroup WWDG_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup WWDG_Private_Functions + * @{ + */ + +/** + * @brief Deinitializes the WWDG peripheral registers to their default reset values. + */ +void WWDG_DeInit(void) +{ + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_WWDG, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_WWDG, DISABLE); +} + +/** + * @brief Sets the WWDG Prescaler. + * @param WWDG_Prescaler specifies the WWDG Prescaler. + * This parameter can be one of the following values: + * @arg WWDG_PRESCALER_DIV1 WWDG counter clock = (PCLK1/4096)/1 + * @arg WWDG_PRESCALER_DIV2 WWDG counter clock = (PCLK1/4096)/2 + * @arg WWDG_PRESCALER_DIV4 WWDG counter clock = (PCLK1/4096)/4 + * @arg WWDG_PRESCALER_DIV8 WWDG counter clock = (PCLK1/4096)/8 + */ +void WWDG_SetPrescalerDiv(uint32_t WWDG_Prescaler) +{ + uint32_t tmpregister = 0; + /* Check the parameters */ + assert_param(IS_WWDG_PRESCALER_DIV(WWDG_Prescaler)); + /* Clear WDGTB[1:0] bits */ + tmpregister = WWDG->CFG & CFG_TIMERB_MASK; + /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */ + tmpregister |= WWDG_Prescaler; + /* Store the new value */ + WWDG->CFG = tmpregister; +} + +/** + * @brief Sets the WWDG window value. + * @param WindowValue specifies the window value to be compared to the downcounter. + * This parameter value must be lower than 0x80. + */ +void WWDG_SetWValue(uint8_t WindowValue) +{ + __IO uint32_t tmpregister = 0; + + /* Check the parameters */ + assert_param(IS_WWDG_WVALUE(WindowValue)); + /* Clear W[6:0] bits */ + + tmpregister = WWDG->CFG & CFG_W_MASK; + + /* Set W[6:0] bits according to WindowValue value */ + tmpregister |= WindowValue & (uint32_t)BIT_MASK; + + /* Store the new value */ + WWDG->CFG = tmpregister; +} + +/** + * @brief Enables the WWDG Early Wakeup interrupt(EWI). + */ +void WWDG_EnableInt(void) +{ + + WWDG->CFG |= (uint32_t)( ENABLE << 9); +} + +/** + * @brief Sets the WWDG counter value. + * @param Counter specifies the watchdog counter value. + * This parameter must be a number between 0x40 and 0x7F. + */ +void WWDG_SetCnt(uint8_t Counter) +{ + /* Check the parameters */ + assert_param(IS_WWDG_CNT(Counter)); + /* Write to T[6:0] bits to configure the counter value, no need to do + a read-modify-write; writing a 0 to WDGA bit does nothing */ + WWDG->CTRL = Counter & BIT_MASK; +} + +/** + * @brief Enables WWDG and load the counter value. + * @param Counter specifies the watchdog counter value. + * This parameter must be a number between 0x40 and 0x7F. + */ +void WWDG_Enable(uint8_t Counter) +{ + /* Check the parameters */ + assert_param(IS_WWDG_CNT(Counter)); + WWDG->CTRL = CTRL_ACTB_SET | Counter; +} + +/** + * @brief Checks whether the Early Wakeup interrupt flag is set or not. + * @return The new state of the Early Wakeup interrupt flag (SET or RESET) + */ +FlagStatus WWDG_GetEWINTF(void) +{ + return (FlagStatus)(WWDG->STS); +} + +/** + * @brief Clears Early Wakeup interrupt flag. + */ +void WWDG_ClrEWINTF(void) +{ + WWDG->STS = (uint32_t)RESET; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/anc_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/anc_common.h new file mode 100644 index 0000000..9d08ccb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/anc_common.h @@ -0,0 +1,286 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + +/** + * @file ancc_common.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef ANC_COMMON_H_ +#define ANC_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup ANC Apple Notification Center Service + * @ingroup ANC + * @brief Apple Notification Center Service Client + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#if (BLE_ANC_SERVER || BLE_ANC_CLIENT) + +#include "prf_types.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Error Codes +// Command not recognized by the NP - Protocol +#define ANC_CMD_UNKNOWN (0xA0) +// Command improperly formatted - Proprietary +#define ANC_CMD_INVALID (0xA1) +// One of the parameters does not refer to an existing object on the NP - Proprietary +#define ANC_PARAM_INVALID (0xA2) +// The action was not performed +#define ANC_ACTION_FAILED (0xA3) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Category ID Values +enum +{ + /// Other + CAT_ID_OTHER = 0, + /// Incoming Call + CAT_ID_CALL = 1, + /// Missed Call + CAT_ID_MISSED_CALL = 2, + /// Voice Mail + CAT_ID_VOICE_MAIL = 3, + /// Social network + CAT_ID_SOCIAL = 4, + /// Schedule + CAT_ID_SCHEDULE = 5, + /// Email + CAT_ID_EMAIL = 6, + /// News Feed + CAT_ID_NEWS = 7, + /// Health and Fitness + CAT_ID_HEALTH_FITNESS = 8, + /// Business and Finance + CAT_ID_BUSINESS_FINANCE = 9, + /// Location + CAT_ID_LOCATION = 10, + /// Entertainment + CAT_ID_ENTERTAINMENT = 11, + + CAT_ID_NB, + + /// All supported categories + CAT_ID_ALL_SUPPORTED_CAT = 255, +}; + +/// Event ID Values +enum +{ + /// Notification Added + EVT_ID_NTF_ADDED = 0, + /// Notification Modified + EVT_ID_NTF_MODIFIED = 1, + /// Notification Removed + EVT_ID_NTF_REMOVED = 2, + + EVT_ID_NB, + + EVT_ID_ALL_SUPPORTED_EVT = 255, +}; + +/// Event Flags +enum +{ + /// Silent + ANC_EVT_FLAG_SILENT = (1 << 0), + /// Important + ANC_EVT_FLAG_IMPORTANT = (1 << 1), + /// PreExisting + ANC_EVT_FLAG_PRE_EXISTING = (1 << 2), + /// Positive Action + ANC_EVT_FLAG_POS_ACT = (1 << 3), + /// Negative Action + ANC_EVT_FLAG_NEG_ACT = (1 << 4), + + ANC_EVT_FLAG_NB, + + ANC_EVT_FLAG_ALL_SUPPORTED_EVT_FLAG = (1 << 7), +}; + +/// Command ID Values +enum +{ + /// Get Notification Attributes + CMD_ID_GET_NTF_ATTS = 0, + /// Get App Attributes + CMD_ID_GET_APP_ATTS = 1, + /// Perform Notification Action + CMD_ID_PERF_NTF_ACT = 2, + + CMD_ID_NB, + + /// All supported commands + CMD_ID_ALL_SUPPORTED_CMD = 255, +}; + +/// Notification Attribute ID Values +enum +{ + /// App Identifier + NTF_ATT_ID_APP_ID = 0, + /// Title (Needs to be followed by a 2-bytes max length parameter) + NTF_ATT_ID_TITLE = 1, + /// Subtitle (Needs to be followed by a 2-bytes max length parameter) + NTF_ATT_ID_SUBTITLE = 2, + /// Message (Needs to be followed by a 2-bytes max length parameter) + NTF_ATT_ID_MSG = 3, + /// Message Size + NTF_ATT_ID_MSG_SIZE = 4, + /// Date + NTF_ATT_ID_DATE = 5, + /// Positive Action Label + NTF_ATT_ID_POS_ACT_LBL = 6, + /// Negative Action Label + NTF_ATT_ID_NEG_ACT_LBL = 7, + + NTF_ATT_ID_NB, + + /// All supported Notification Attributes + NTF_ATT_ID_ALL_SUPPORTED_NTF_ATT = 255, +}; + +/// ActionID Values +enum +{ + /// ActionID Postive + ACT_ID_POS = 0, + /// Action ID Negative + ACT_ID_NEG = 1, + + ACT_ID_NB, + + ACT_ID_ALL_SUPPORTED_ID = 255, +}; + +/// Notification Attribute Bit Mask Flags +enum ancc_ntf_attr_present +{ + /// App Identifier present + NTF_ATT_ID_APP_ID_PRESENT = 0x01, + /// Title present + NTF_ATT_ID_TITLE_PRESENT = 0x02, + /// Subtitle present + NTF_ATT_ID_SUBTITLE_PRESENT = 0x04, + /// Message present + NTF_ATT_ID_MSG_PRESENT = 0x08, + /// Message Size present + NTF_ATT_ID_MSG_SIZE_PRESENT = 0x10, + /// Date present + NTF_ATT_ID_DATE_PRESENT = 0x20, +}; + +/// App Attribute ID Values +enum +{ + /// Display Name present + APP_ATT_ID_DISPLAY_NAME = 0, + + APP_ADD_ID_NB, + + /// All supported App Attributes + APP_ATT_ID_ALL_SUPPORTED_APP_ATT = 255, +}; + +// App Attribute Bit Mask Flags +enum +{ + /// App Identifier + APP_ATT_ID_DISPLAY_NAME_PRESENT = 0x01, + +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Notification Source Characteristic Value Structure +struct anc_ntf_src +{ + /// Event ID + uint8_t event_id; + + /// Event Flags + uint8_t event_flags; + + /// Category ID + uint8_t cat_id; + + /// Category Count: Number of active notifications in the given category + uint8_t cat_cnt; + + /// Notification UID + uint32_t ntf_uid; +}; + +#endif // (BLE_ANC_SERVER || BLE_ANC_CLIENT) + +/// @} anc_common + +#endif // (ANC_COMMON_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/api/ancc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/api/ancc.h new file mode 100644 index 0000000..2748459 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/api/ancc.h @@ -0,0 +1,270 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ancc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef ANCC_H_ +#define ANCC_H_ + +/** + **************************************************************************************** + * @addtogroup ANCC Apple Notification Center Client + * @ingroup ANCC + * @brief Apple Notification Center Client + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_ANC_CLIENT) + +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of ANCC task instances +#define ANCC_IDX_MAX (BLE_CONNECTION_MAX) +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// ANCS Characteristics +enum ancc_anc_chars +{ + /// Notification Source + ANCC_CHAR_NTF_SRC, + /// Control Point + ANCC_CHAR_CTRL_PT, + /// Data Source + ANCC_CHAR_DATA_SRC, + + ANCC_CHAR_MAX +}; + +/// ANCS Characteristic Descriptors +enum ancc_anc_descs +{ + /// Notification Source - Client Characteristic Configuration + ANCC_DESC_NTF_SRC_CL_CFG, + /// Data Source - Client Characteristic Configuration + ANCC_DESC_DATA_SRC_CL_CFG, + + ANCC_DESC_MAX, + + ANCC_DESC_MASK = 0x10 +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ +///Structure containing the characteristics handles, value handles and descriptors + +struct ancc_content +{ + /// Service info + struct prf_svc svc; + /// Characteristics + struct prf_char_inf chars[ANCC_CHAR_MAX]; + /// Descriptors + struct prf_char_desc_inf descs[ANCC_DESC_MAX]; +}; + +/// Structure for ANCS Notification reception variables +struct ancc_data_src_ntf_tag +{ + /// Notification Reception state + uint8_t state; + /// Number of requested attributes + uint8_t nb_req_atts; + /// Current attribute id + uint8_t curr_att_id; + /// Current attribute id + uint8_t curr_app_id_length; + /// Current attribute id + uint8_t curr_att_length; + /// Remaining bytes for current value + uint16_t curr_value_idx; + /// Last allocated notification + void *alloc_rsp_ind; +}; + +struct ancc_cnx_env +{ + /// Last requested operation code + uint8_t last_op_code; + /// Provide an indication about the last operation + uint16_t last_req; + /// Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Last characteristic code used in a read or a write request + uint16_t last_char_code; + /// Counter used to check service uniqueness + uint8_t nb_svc; + /// Data Source Notification reception variables structure + struct ancc_data_src_ntf_tag data_src; + /// ANC characteristics + struct ancc_content anc; + /// Current operation code + void *operation; +}; + +/// ANCC environment variable +struct ancc_env_tag +{ + /// Profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct ancc_cnx_env* env[ANCC_IDX_MAX]; + /// State of different task instances + ke_state_t state[ANCC_IDX_MAX]; +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve ANC client profile interface + * @return ANC client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *ancc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send ANC ATT DB discovery results to ANCC host. + **************************************************************************************** + */ +void ancc_enable_rsp_send(struct ancc_env_tag *ancc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send Notification Configuration Response + **************************************************************************************** + */ +void ancc_wr_cfg_ntf_rsp_send(struct ancc_env_tag *ancc_env, uint8_t conidx, + uint8_t op_code, uint8_t status); + +/** + **************************************************************************************** + * @brief Send Read Notification Configuration Response + **************************************************************************************** + */ +void ancc_rd_cfg_ntf_rsp_send(struct ancc_env_tag *ancc_env, uint8_t conidx, + uint8_t op_code, uint16_t value, uint8_t status); + +/** + **************************************************************************************** + * @brief Send Operation Completion Event + **************************************************************************************** + */ +void ancc_cmp_evt_send(struct ancc_env_tag *ancc_env, uint8_t conidx, uint8_t op_code, + uint8_t status); + +/** + **************************************************************************************** + * @brief Handles reception of response to a Get Notification Attributes command. + * @param[in] ancc_env Pointer to the profile environment. + * @param[in] conidx Connection index + * @param[in] value Pointer to the response value. + * @param[in] length Length of the response value. + **************************************************************************************** + */ +void ancc_get_ntf_atts_rsp(struct ancc_env_tag *ancc_env, uint8_t conidx, + const uint8_t *value, uint16_t length); + +/** + **************************************************************************************** + * @brief Handles reception of response to a Get App Attributes command. + * @param[in] ancc_env Pointer to the profile environment. + * @param[in] value Pointer to the response value. + * @param[in] length Length of the response value. + **************************************************************************************** + */ +void ancc_get_app_atts_rsp(struct ancc_env_tag *ancc_env, uint8_t conidx, + const uint8_t *value, uint16_t length); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * Initialize task handler + * + * @param task_desc Task descriptor to fill + **************************************************************************************** + */ +void ancc_task_init(struct ke_task_desc *p_task_desc); + +#endif // (BLE_ANC_CLIENT) + +/// @} ANCC + +#endif // ANCC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/api/ancc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/api/ancc_task.h new file mode 100644 index 0000000..4d40378 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/api/ancc_task.h @@ -0,0 +1,328 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ancc_task.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef ANCC_TASK_H_ +#define ANCC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup ANCCTASK Apple Notification Center Service Client Task + * @ingroup ANCC + * @brief Apple Notification Center Service Client Task + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#if (BLE_ANC_CLIENT) + +#include "ke_task.h" +#include "gattc_task.h" +#include "co_error.h" +#include "ancc.h" +#include "anc_common.h" +#include "prf_types.h" + +#define ANCC_GET_ATT_CMD_MAX_LEN (19) +#define ANCC_PERF_NTF_ACT_CMD_MAX_LEN (6) + +/// Possible states of the ANCC task +enum ancc_state +{ + /// Free state + ANCC_FREE, + /// IDLE state + ANCC_IDLE, + /// Discovering Apple Notification Service + ANCC_DISCOVERING, + /// Busy state + ANCC_BUSY, + + /// Number of defined states + ANCC_STATE_MAX +}; + +/// Message IDs +enum +{ + /// Enable the ANCS Client task - at connection + ANCC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_ANCC), + /// Disable Indication + ANCC_ENABLE_RSP, + /// Write Notification Configuration Request + ANCC_WR_CFG_NTF_REQ, + /// Write Notification Configuration Response + ANCC_WR_CFG_NTF_RSP, + /// Read Notification Configuration Request + ANCC_RD_CFG_NTF_REQ, + /// Read Notification Configuration Response + ANCC_RD_CFG_NTF_RSP, + /// Indicate that a notification of the Notification Source characteristic has been received + ANCC_NTF_SRC_IND, + /// Write a "Get Notification Attributes" command in Control Point + ANCC_GET_NTF_ATTS_CMD_REQ, + /// Indicate that the value of a notification attribute is available + ANCC_NTF_ATT_IND, + /// Write a "Get App Attributes" command in Control Point + ANCC_GET_APP_ATTS_CMD_REQ, + /// Indicate that the value of an application attribute is available + ANCC_APP_ATT_IND, + /// Write a "Perform Notification Action" command in Control Point + ANCC_PERF_NTF_ACT_CMD_REQ, + /// Procedure complete information + ANCC_CMP_EVT, +}; + +enum +{ + ANCC_INVALID_OP_CODE = 0x00, + + /// Write notification configuration for Notification Source characteristic + ANCC_WR_NTF_NTF_SRC_OP_CODE, + /// Write notification configuration for Data Source characteristic + ANCC_WR_NTF_DATA_SRC_OP_CODE, + /// Read notification configuration for Notification Source characteristic + ANCC_RD_NTF_NTF_SRC_OP_CODE, + /// Read notification configuration for Data Source characteristic + ANCC_RD_NTF_DATA_SRC_OP_CODE, + + // Get notification attributes command + ANCC_GET_NTF_ATTS_CMD_OP_CODE, + // Get application attributes command + ANCC_GET_APP_ATTS_CMD_OP_CODE, + // Perform notification action command + ANCC_PERF_NTF_ACT_CMD_OP_CODE, +}; + +/// Data Source notification reception states +enum +{ + /** + * DATA SOURCE NOTIFICATION STATES + */ + /// Waiting for next notification + ANCC_DATA_SRC_NTF_IDLE, + /// Waiting for next APP_ID + ANCC_DATA_SRC_APP_ID_IDLE, + /// Waiting for App Identifier + ANCC_DATA_SRC_NTF_APP_ID, + /// Waiting for next attribute + ANCC_DATA_SRC_NTF_NEXT_ATT, + /// Waiting for attribute msb + ANCC_DATA_SRC_NTF_ATT_MSB, + /// Waiting for attribute length + ANCC_DATA_SRC_NTF_ATT_LENGTH, + /// Waiting for attribute value + ANCC_DATA_SRC_NTF_ATT_VALUE, + /// Enter this state when in idle state and reveive an invalid cmd or uid + ANCC_DATA_SRC_NTF_CMD_UID_ERROR, + /// Enter this state when in idle state and reveive an invalid cmd + ANCC_DATA_SRC_APP_CMD_ERROR, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Parameters of the @ref ANCC_ENABLE_REQ message +struct ancc_enable_req +{ + /// Connection type + uint8_t con_type; + /// ANC handle values and characteristic properties + struct ancc_content anc; +}; + +/// Parameters of the @ref ANCC_ENABLE_RSP message +struct ancc_enable_rsp +{ + /// Status + uint8_t status; + /// ANC handle values and characteristic properties + struct ancc_content anc; +}; + +/// Parameters of the @ref ANCC_WR_CFG_NTF_REQ message +struct ancc_wr_cfg_ntf_req +{ + /// Operation code + uint8_t op_code; + /// Notification value + uint16_t cfg_val; +}; + +/// Parameters of the @ref ANCC_WR_CFG_NTF_RSP message +struct ancc_wr_cfg_ntf_rsp +{ + /// Operation code + uint8_t op_code; + /// Operation status + uint8_t status; +}; + +/// Parameters of the @ref ANCC_RD_CFG_NTF_REQ message +struct ancc_rd_cfg_ntf_req +{ + /// Operation code + uint8_t op_code; +}; + +/// Parameters of the @ref ANCC_RD_CFG_NTF_RSP message +struct ancc_rd_cfg_ntf_rsp +{ + /// Operation code + uint8_t op_code; + /// Operation status + uint8_t status; + /// Notification value + uint16_t cfg_val; +}; + +/// Parameters of the @ref ANCC_NTF_SRC_IND message +struct ancc_ntf_src_ind +{ + /// Value + struct anc_ntf_src value; +}; + +/// Parameters of the @ref ANCC_GET_NTF_ATTS_CMD_REQ message +struct ancc_get_ntf_atts_cmd_req +{ + /// Notification UID + uint32_t ntf_uid; + /// Attribute bit mask + uint8_t atts; + /// Title attribute maximum length + uint16_t title_len; + /// Subtitle attribute maximum length + uint16_t subtitle_len; + /// Message attribute maximum length + uint16_t message_len; +}; + +/// Parameters of the @ref ANCC_NTF_ATT_IND message +struct ancc_ntf_att_ind +{ + /// Attribute Code + uint32_t ntf_uid; + /// Attribute ID + uint8_t att_id; + /// Attribute length + uint16_t length; + /// Value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref ANCC_GET_APP_ATTS_CMD_REQ message +struct ancc_get_app_atts_cmd_req +{ + /// Requested attributes bit mask + uint8_t atts; + /// App Identifier length (not including NULL termination) + uint8_t app_id_length; + /// App Identifier + uint8_t app_id[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref ANCC_APP_ATT_IND message +struct ancc_app_att_ind +{ + /// app id + uint8_t app_id_length; + /// app AttributeID + uint8_t att_id; + /// Attribute length + uint16_t att_length; + /// Value + uint8_t values[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref ANCC_PERF_NTF_ACT_CMD_REQ message +struct ancc_perf_ntf_act_cmd_req +{ + /// Notification UID + uint32_t ntf_uid; + /// Requested Action + uint8_t action; +}; + +/// Parameters of the @ref ANCC_CMP_EVT message +struct ancc_cmp_evt +{ + /// Operation code + uint8_t operation; + /// Status + uint8_t status; +}; + +/* + * GLOBAL VARIABLES DECLARATIONS + **************************************************************************************** + */ +extern const struct ke_state_handler ancc_default_handler; + +#endif // (BLE_ANC_CLIENT) + +/// @} ANCCTASK + +#endif // ANCC_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/src/ancc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/src/ancc.c new file mode 100644 index 0000000..9f7a9dd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/src/ancc.c @@ -0,0 +1,674 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ancc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#include "rwip_config.h" +#include "anc_common.h" + +#if (BLE_ANC_CLIENT) + +#include + +#include "ancc.h" +#include "ancc_task.h" +#include "ke_mem.h" +#include "co_utils.h" +#include "prf_utils.h" +#include "prf.h" +#include "prf_utils_128.h" + +/** + **************************************************************************************** + * @brief Initialization of the ANCC module. + * This function performs the initialization of the Profile module: + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application: + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] env Client or Service allocated environment data. + * @param[in,out] start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @enum attm_svc_perm_mask) + * @param[in] param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeeds + **************************************************************************************** + */ +static uint8_t ancc_init(struct prf_task_env *env, uint16_t *start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *params) +{ + uint8_t idx; + NS_LOG_DEBUG("%s\r\n", __func__); + + struct ancc_env_tag *ancc_env = + (struct ancc_env_tag *) ke_malloc(sizeof(struct ancc_env_tag), KE_MEM_ATT_DB); + memset(ancc_env, 0, sizeof(struct ancc_env_tag)); + + // Allocate ANCC required environment variable + env->env = (prf_env_t*) ancc_env; + + ancc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + ancc_env->prf_env.prf_task = env->task | PERM(PRF_MI, ENABLE); + + // Initialize environment variable + env->id = TASK_ID_ANCC; + ancc_task_init(&(env->desc)); + + for (idx = 0; idx < ANCC_IDX_MAX ; idx++) + { + ancc_env->env[idx] = NULL; + // Service is ready, go into the Free state + ke_state_set(KE_BUILD_ID(env->task, idx), ANCC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + + +/** + **************************************************************************************** + * @brief Clean up of connection dedicated environment parameters + * This function performs clean up of ongoing operations + * @param[in,out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void ancc_cleanup(struct prf_task_env *env, uint8_t conidx, uint8_t reason) +{ + struct ancc_env_tag *ancc_env = (struct ancc_env_tag *) env->env; + + // Clean up environment variable allocated for task instance + if (ancc_env->env[conidx] != NULL) + { + prf_unregister_atthdl2gatt(&ancc_env->prf_env, conidx, &ancc_env->env[conidx]->anc.svc); + + if (ancc_env->env[conidx]->data_src.alloc_rsp_ind != NULL) + { + ke_free(ke_param2msg(ancc_env->env[conidx]->data_src.alloc_rsp_ind)); + } + + if (ancc_env->env[conidx]->operation != NULL) + { + ke_free(ke_param2msg(ancc_env->env[conidx]->operation)); + } + + ke_free(ancc_env->env[conidx]); + ancc_env->env[conidx] = NULL; + } + + // Put ANCS Client in Free state + ke_state_set(KE_BUILD_ID(env->task, conidx), ANCC_FREE); +} + + +/** + **************************************************************************************** + * @brief Destruction of the ANCC module - due to a reset for instance. + * This function cleans up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in,out] env Client or Service allocated environment data. + **************************************************************************************** + */ +static void ancc_destroy(struct prf_task_env *env) +{ + uint8_t idx; + struct ancc_env_tag *ancc_env = (struct ancc_env_tag *) env->env; + + // Cleanup environment variable for each task instances + for (idx = 0; idx < ANCC_IDX_MAX ; idx++) + { + if (ancc_env->env[idx] != NULL) + { + ancc_cleanup(env, idx, 0); + } + } + + // Free profile environment variables + env->env = NULL; + ke_free(ancc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in,out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void ancc_create(struct prf_task_env *env, uint8_t conidx) +{ + // Put ANP Client in Idle state + ke_state_set(KE_BUILD_ID(env->task, conidx), ANCC_IDLE); +} + +/** + **************************************************************************************** + * @brief Set IDLE state if prevoius state was BUSY + * + * @param[in,out] env Collector allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void ancc_idle_state_set(struct ancc_env_tag *ancc_env, uint8_t conidx) +{ + if (ke_state_get(prf_src_task_get(&(ancc_env->prf_env), conidx)) == ANCC_BUSY) + { + ke_state_set(prf_src_task_get(&(ancc_env->prf_env), conidx), ANCC_IDLE); + } +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// ANCC Task interface required by profile manager +const struct prf_task_cbs ancc_itf = +{ + (prf_init_fnct)ancc_init, + ancc_destroy, + ancc_create, + ancc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *ancc_prf_itf_get(void) +{ + return &ancc_itf; +} + +void ancc_enable_rsp_send(struct ancc_env_tag *ancc_env, uint8_t conidx, uint8_t status) +{ + // Send APP the details of the discovered attributes on ANCC + NS_LOG_DEBUG("%s\r\n", __func__); + struct ancc_enable_rsp *rsp = KE_MSG_ALLOC(ANCC_ENABLE_RSP, + prf_dst_task_get(&(ancc_env->prf_env), conidx), + prf_src_task_get(&(ancc_env->prf_env), conidx), + ancc_enable_rsp); + + rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + rsp->anc = ancc_env->env[conidx]->anc; + // Register ANCC task in gatt for indication/notifications + prf_register_atthdl2gatt(&ancc_env->prf_env, conidx, &ancc_env->env[conidx]->anc.svc); + // Go to connected state + ke_state_set(prf_src_task_get(&(ancc_env->prf_env), conidx), ANCC_IDLE); + } + ke_msg_send(rsp); +} + +void ancc_wr_cfg_ntf_rsp_send(struct ancc_env_tag *ancc_env, uint8_t conidx, uint8_t op_code, + uint8_t status) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + + // Go back to IDLE state + ancc_idle_state_set(ancc_env, conidx); + + struct ancc_wr_cfg_ntf_rsp *rsp = KE_MSG_ALLOC(ANCC_WR_CFG_NTF_RSP, + prf_dst_task_get(&(ancc_env->prf_env), conidx), + prf_src_task_get(&(ancc_env->prf_env), conidx), + ancc_wr_cfg_ntf_rsp); + + rsp->op_code = op_code; + rsp->status = status; + + ke_msg_send(rsp); +} + +void ancc_rd_cfg_ntf_rsp_send(struct ancc_env_tag *ancc_env, uint8_t conidx, uint8_t op_code, + uint16_t value, uint8_t status) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + + // Go back to IDLE state + ancc_idle_state_set(ancc_env, conidx); + + struct ancc_rd_cfg_ntf_rsp *rsp = KE_MSG_ALLOC(ANCC_RD_CFG_NTF_RSP, + prf_dst_task_get(&(ancc_env->prf_env), conidx), + prf_src_task_get(&(ancc_env->prf_env), conidx), + ancc_rd_cfg_ntf_rsp); + + rsp->op_code = op_code; + rsp->cfg_val = value; + rsp->status = status; + + ke_msg_send(rsp); +} + +void ancc_cmp_evt_send(struct ancc_env_tag *ancc_env, uint8_t conidx, uint8_t op_code, + uint8_t status) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + + // Free stored request message + if (ancc_env->env[conidx]->operation != NULL) + { + ke_msg_free(ke_param2msg(ancc_env->env[conidx]->operation)); + ancc_env->env[conidx]->operation = NULL; + } + // Go back to IDLE state + ancc_idle_state_set(ancc_env, conidx); + + struct ancc_cmp_evt *evt = KE_MSG_ALLOC(ANCC_CMP_EVT, + prf_dst_task_get(&(ancc_env->prf_env), conidx), + prf_src_task_get(&(ancc_env->prf_env), conidx), + ancc_cmp_evt); + + evt->operation = op_code; + evt->status = status; + + ke_msg_send(evt); +} + +void ancc_get_ntf_atts_rsp(struct ancc_env_tag *env_tag, uint8_t conidx, const uint8_t *value, + uint16_t length) +{ + uint16_t idx = 0; + struct ancc_cnx_env *ancc_env = env_tag->env[conidx]; + NS_LOG_DEBUG("%s\r\n", __func__); + + while (idx < length) + { + switch (ancc_env->data_src.state) + { + case ANCC_DATA_SRC_NTF_IDLE: + { + if (value[0] == CMD_ID_GET_NTF_ATTS && + ancc_env->operation != NULL && + ((struct ancc_get_ntf_atts_cmd_req *)ancc_env->operation)->ntf_uid == co_read32p(&value[1])) + { + uint8_t mask = ((struct ancc_get_ntf_atts_cmd_req *)ancc_env->operation)->atts; + uint8_t i = 0; + idx += 5; // skip cmd id and uid + + ancc_env->data_src.nb_req_atts = 0; + for (i = 0; i < 8; ++i) + { + if (mask & 1) + ancc_env->data_src.nb_req_atts += 1; + mask >>= 1; + } + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_NEXT_ATT; + } + else + { + idx = length; + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_CMD_UID_ERROR; + // Since only one NTF_ATTS_CMD is sent at a time and then wait for the completion event + // to send the next, send the completion event now so the next command can be sent + ancc_cmp_evt_send(env_tag, conidx, ANCC_GET_NTF_ATTS_CMD_OP_CODE, GAP_ERR_NO_ERROR); + } + }break; + + case ANCC_DATA_SRC_NTF_NEXT_ATT: + { + ancc_env->data_src.curr_att_id = value[idx++]; + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_ATT_LENGTH; + }break; + + case ANCC_DATA_SRC_NTF_ATT_LENGTH: + { + ancc_env->data_src.curr_att_length = value[idx++]; + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_ATT_MSB; + }break; + + case ANCC_DATA_SRC_NTF_ATT_MSB: + { + ancc_env->data_src.curr_att_length |= (value[idx++] << 8); + ancc_env->data_src.curr_value_idx = 0; + + // Allocate the indication + struct ancc_ntf_att_ind *ind = KE_MSG_ALLOC_DYN(ANCC_NTF_ATT_IND, + prf_dst_task_get(&(env_tag->prf_env), conidx), + prf_src_task_get(&(env_tag->prf_env), conidx), + ancc_ntf_att_ind, + ancc_env->data_src.curr_att_length); + + ind->ntf_uid = ((struct ancc_get_ntf_atts_cmd_req *)ancc_env->operation)->ntf_uid; + ind->att_id = ancc_env->data_src.curr_att_id; + ind->length = ancc_env->data_src.curr_att_length; + + ancc_env->data_src.alloc_rsp_ind = ind; + + if (ancc_env->data_src.curr_att_length == 0) + { + ancc_env->data_src.nb_req_atts -= 1; + // Send indication to app + ke_msg_send(ancc_env->data_src.alloc_rsp_ind); + ancc_env->data_src.alloc_rsp_ind = NULL; + + // Check if all requested attributes have been received + if (ancc_env->data_src.nb_req_atts > 0) + { + // Advance to the next attribute + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_NEXT_ATT; // set next state + } + else + { + // Command complete + ancc_cmp_evt_send(env_tag, conidx, ANCC_GET_NTF_ATTS_CMD_OP_CODE, GAP_ERR_NO_ERROR); + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_IDLE; + } + } + else + { + // Wait for att value + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_ATT_VALUE; + } + }break; + + case ANCC_DATA_SRC_NTF_ATT_VALUE: + { + ((struct ancc_ntf_att_ind *) ancc_env->data_src.alloc_rsp_ind)->value[ancc_env->data_src.curr_value_idx] = value[idx++]; + ancc_env->data_src.curr_value_idx += 1; + + // Check if attribute value has been read + if (ancc_env->data_src.curr_value_idx == ancc_env->data_src.curr_att_length) + { + ancc_env->data_src.nb_req_atts -= 1; + // Send indication to app + ke_msg_send(ancc_env->data_src.alloc_rsp_ind); + ancc_env->data_src.alloc_rsp_ind = NULL; + + // Check if all requested attributes have been received + if (ancc_env->data_src.nb_req_atts > 0) + { + // Advance to the next attribute + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_NEXT_ATT; // set next state + } + else + { + // Command complete + ancc_cmp_evt_send(env_tag, conidx, ANCC_GET_NTF_ATTS_CMD_OP_CODE, + GAP_ERR_NO_ERROR); + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_IDLE; + } + } + }break; + + case ANCC_DATA_SRC_NTF_CMD_UID_ERROR: + { + if (value[0] == CMD_ID_GET_NTF_ATTS && + ancc_env->operation != NULL && + ((struct ancc_get_ntf_atts_cmd_req *)ancc_env->operation)->ntf_uid == co_read32p(&value[1])) + { + idx += 5; // skip cmd id and uid + + uint8_t mask = ((struct ancc_get_ntf_atts_cmd_req *)ancc_env->operation)->atts; + + ancc_env->data_src.nb_req_atts = 0; + for(int kk=0; kk < 8; ++kk) + { + if (mask & 1) + ancc_env->data_src.nb_req_atts += 1; + mask >>= 1; + } + + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_NEXT_ATT; + } + else + { + idx = length; + // Do nothing, just ignore the packet until we get the write cmd and uid + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_CMD_UID_ERROR; + } + }break; + } + } +} + +void ancc_get_app_atts_rsp(struct ancc_env_tag *env_tag, uint8_t conidx, + const uint8_t *value, uint16_t length) +{ + uint16_t idx = 0; + struct ancc_cnx_env *ancc_env = env_tag->env[conidx]; + NS_LOG_DEBUG("%s\r\n", __func__); + while (idx < length) + { + switch (ancc_env->data_src.state) + { + case ANCC_DATA_SRC_APP_ID_IDLE: + { + if ((value[0] == CMD_ID_GET_APP_ATTS) && ancc_env->operation != NULL) + { + uint8_t mask = ((struct ancc_get_app_atts_cmd_req *)ancc_env->operation)->atts; + uint8_t i = 0; + idx += 1; // Skip Command ID + + ancc_env->data_src.nb_req_atts = 0; + for(i = 0; i < 8; ++i) + { + if (mask & 1) + ancc_env->data_src.nb_req_atts += 1; + mask >>= 1; + } + // Initialize index for the buffer that will hold the value + ancc_env->data_src.curr_value_idx = 0; + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_APP_ID; + } + else + { + idx = length; + ancc_env->data_src.state = ANCC_DATA_SRC_APP_CMD_ERROR; + // Since only one APP_ATTS_CMD is sent at a time and then wait for the completion event + // to send the next, send the completion event now so the next command can be sent + ancc_cmp_evt_send(env_tag, conidx, ANCC_GET_APP_ATTS_CMD_OP_CODE, GAP_ERR_NO_ERROR); + } + }break; + + case ANCC_DATA_SRC_NTF_APP_ID: + { + if (((struct ancc_get_app_atts_cmd_req *) ancc_env->operation)->app_id[ancc_env->data_src.curr_value_idx++] + != value[idx++]) + { + ASSERT_ERR(0); + }; + + // Check if app id has been read + if (ancc_env->data_src.curr_value_idx == ((struct ancc_get_app_atts_cmd_req *) ancc_env->operation)->app_id_length) + { + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_NEXT_ATT; + // Save current App ID length + ancc_env->data_src.curr_app_id_length = ancc_env->data_src.curr_value_idx; + + } + }break; + + case ANCC_DATA_SRC_NTF_NEXT_ATT: + { + ancc_env->data_src.curr_att_id = value[idx++]; + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_ATT_LENGTH; + }break; + + case ANCC_DATA_SRC_NTF_ATT_LENGTH: + { + ancc_env->data_src.curr_att_length = value[idx++]; + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_ATT_MSB; + } + + case ANCC_DATA_SRC_NTF_ATT_MSB: + { + ancc_env->data_src.curr_att_length |= (value[idx++] << 8); + + // Allocate the indication + struct ancc_app_att_ind *ind = KE_MSG_ALLOC_DYN(ANCC_APP_ATT_IND, + prf_dst_task_get(&(env_tag->prf_env), conidx), + prf_src_task_get(&(env_tag->prf_env), conidx), + ancc_app_att_ind, + ancc_env->data_src.curr_app_id_length + ancc_env->data_src.curr_att_length); + + ind->app_id_length = ancc_env->data_src.curr_app_id_length; + ind->att_id = ancc_env->data_src.curr_att_id; + ind->att_length = ancc_env->data_src.curr_att_length; + + memcpy(&ind->values, + &(((struct ancc_get_app_atts_cmd_req *)ancc_env->operation)->app_id), + ((struct ancc_get_app_atts_cmd_req *)ancc_env->operation)->app_id_length); + + ancc_env->data_src.alloc_rsp_ind = ind; + if (ancc_env->data_src.curr_att_length == 0) + { + ancc_env->data_src.nb_req_atts -= 1; + + // Send indication to app + ke_msg_send(ancc_env->data_src.alloc_rsp_ind); + ancc_env->data_src.alloc_rsp_ind = NULL; + + // Check if all requested attributes have been received + if (ancc_env->data_src.nb_req_atts > 0) + { + // Advance to the next attr + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_NEXT_ATT; + } + else + { + // Command complete + ancc_cmp_evt_send(env_tag, conidx, ANCC_GET_APP_ATTS_CMD_OP_CODE, + GAP_ERR_NO_ERROR); + ancc_env->data_src.state = ANCC_DATA_SRC_APP_ID_IDLE; + + } + } + else + { + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_ATT_VALUE; + } + + }break; + + case ANCC_DATA_SRC_NTF_ATT_VALUE: + { + ((struct ancc_app_att_ind *) ancc_env->data_src.alloc_rsp_ind)->values[ancc_env->data_src.curr_value_idx] = value[idx++]; + ancc_env->data_src.curr_value_idx += 1; + + // Check if the attribute value has been read + if (ancc_env->data_src.curr_value_idx == ancc_env->data_src.curr_att_length + + ancc_env->data_src.curr_app_id_length) + { + ancc_env->data_src.nb_req_atts -= 1; + + // Send indication to app + ke_msg_send(ancc_env->data_src.alloc_rsp_ind); + ancc_env->data_src.alloc_rsp_ind = NULL; + + // Check if all requested attributes have been received + if (ancc_env->data_src.nb_req_atts > 0) + { + // Advance to the next attr + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_NEXT_ATT; + } + else + { + // Command complete + ancc_cmp_evt_send(env_tag, conidx, ANCC_GET_APP_ATTS_CMD_OP_CODE, GAP_ERR_NO_ERROR); + ancc_env->data_src.state = ANCC_DATA_SRC_APP_ID_IDLE; + + } + } + }break; + + case ANCC_DATA_SRC_APP_CMD_ERROR: + { + if ((value[0] == CMD_ID_GET_APP_ATTS) && ancc_env->operation != NULL) + { + + // Skip Command ID + idx += 1; + + // Compute the amount of requested attributes + uint8_t mask = ((struct ancc_get_app_atts_cmd_req *)ancc_env->operation)->atts; + + ancc_env->data_src.nb_req_atts = 0; + for(int kk=0; kk < 8; ++kk) + { + if (mask & 1) + ancc_env->data_src.nb_req_atts += 1; + mask >>= 1; + } + + // Initialize index for the buffer that will hold the value + ancc_env->data_src.curr_value_idx = 0; + + // Set next state + ancc_env->data_src.state = ANCC_DATA_SRC_NTF_APP_ID; + } + else + { + idx = length; + // Do nothing, just ignore the packet until we get the write cmd + ancc_env->data_src.state = ANCC_DATA_SRC_APP_CMD_ERROR; + } + }break; + } + } +} + +#endif // (BLE_ANC_CLIENT) + +/// @} ANCC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/src/ancc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/src/ancc_task.c new file mode 100644 index 0000000..f8f19ab --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anc/ancc/src/ancc_task.c @@ -0,0 +1,823 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + +/** + * @file ancc_task.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +/** + **************************************************************************************** + * @addtogroup ANCCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_ANC_CLIENT) + +#include "gap.h" +#include "co_utils.h" +#include "ancc.h" +#include "ancc_task.h" +#include "gattc_task.h" +#include "prf_utils.h" +#include "prf.h" +#include "prf_utils_128.h" +#include "ke_mem.h" + +/// ANCS UUID +const struct att_uuid_128 ancc_anc_svc = {{0xD0, 0x00, 0x2D, 0x12, 0x1E, 0x4B, 0x0F, 0xA4, 0x99, 0x4E, 0xCE, 0xB5, 0x31, 0xF4, 0x05, 0x79}}; + +/// State machine used to retrieve ANCS characteristics information +const struct prf_char_def_128 ancc_anc_char[ANCC_CHAR_MAX] = +{ + /// Notification Source + [ANCC_CHAR_NTF_SRC] = {{0xBD, 0x1D, 0xA2, 0x99, 0xE6, 0x25, 0x58, 0x8C, 0xD9, 0x42, 0x01, 0x63, 0x0D, 0x12, 0xBF, 0x9F}, + ATT_MANDATORY, + ATT_CHAR_PROP_NTF}, + + /// Control Point + [ANCC_CHAR_CTRL_PT] = {{0xD9, 0xD9, 0xAA, 0xFD, 0xBD, 0x9B, 0x21, 0x98, 0xA8, 0x49, 0xE1, 0x45, 0xF3, 0xD8, 0xD1, 0x69}, + ATT_OPTIONAL, + ATT_CHAR_PROP_WR}, + + /// Data Source + [ANCC_CHAR_DATA_SRC] = {{0xFB, 0x7B, 0x7C, 0xCE, 0x6A, 0xB3, 0x44, 0xBE, 0xB5, 0x4B, 0xD6, 0x24, 0xE9, 0xC6, 0xEA, 0x22}, + ATT_OPTIONAL, + ATT_CHAR_PROP_NTF}, +}; + +/// State machine used to retrieve ANCS characteristic descriptor information +const struct prf_char_desc_def ancc_anc_char_desc[ANCC_DESC_MAX] = +{ + /// Notification Source Char. - Client Characteristic Configuration + [ANCC_DESC_NTF_SRC_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + ANCC_CHAR_NTF_SRC}, + /// Data Source Char. - Client Characteristic Configuration + [ANCC_DESC_DATA_SRC_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_OPTIONAL, + ANCC_CHAR_DATA_SRC}, +}; + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANCC_ENABLE_REQ message. + * The handler enables the ANCS Client Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int ancc_enable_req_handler(ke_msg_id_t const msgid, + struct ancc_enable_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct ancc_env_tag *ancc_env = PRF_ENV_GET(ANCC, ancc); + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + ASSERT_ERR(ancc_env != NULL); + NS_LOG_DEBUG("%s\r\n", __func__); + + ancc_env->env[conidx] = (struct ancc_cnx_env*) ke_malloc(sizeof(struct ancc_cnx_env), KE_MEM_ENV); + memset(ancc_env->env[conidx], 0, sizeof(struct ancc_cnx_env)); + + // Start discovering + if (param->con_type == PRF_CON_DISCOVERY) + { + prf_disc_svc_sdp_send_128(&(ancc_env->prf_env), conidx, ancc_anc_svc.uuid); + ancc_env->env[conidx]->last_uuid_req = ATT_DECL_PRIMARY_SERVICE; + ke_state_set(dest_id, ANCC_DISCOVERING); + } + else + { + ancc_env->env[conidx]->anc = param->anc; + ancc_enable_rsp_send(ancc_env, conidx, GAP_ERR_NO_ERROR); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct ancc_env_tag *ancc_env = PRF_ENV_GET(ANCC, ancc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_ERR(ancc_env != NULL); + ASSERT_ERR(ancc_env->env[conidx] != NULL); + NS_LOG_DEBUG("%s\r\n", __func__); + + if (ancc_env->env[conidx]->nb_svc == 0) + { + // Retrieve ANCS characteristics and descriptors + prf_extract_svc_sdp_info_128(ind, + ANCC_CHAR_MAX, ancc_anc_char, ancc_env->env[conidx]->anc.chars, + ANCC_DESC_MAX, ancc_anc_char_desc, ancc_env->env[conidx]->anc.descs); + + // Even if we get multiple responses we only store first range + ancc_env->env[conidx]->anc.svc.shdl = ind->start_hdl; + ancc_env->env[conidx]->anc.svc.ehdl = ind->end_hdl; + } + + ancc_env->env[conidx]->nb_svc++; + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct ancc_env_tag *ancc_env = PRF_ENV_GET(ANCC, ancc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_ERR(ancc_env != NULL); + ASSERT_ERR(ancc_env->env[conidx] != NULL); + NS_LOG_DEBUG("%s,status= %x\r\n", __func__,param->status); + if (ancc_env->state[conidx] == ANCC_DISCOVERING) + { + uint8_t status = param->status; + + if ((param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)|| + (param->status == ATT_ERR_NO_ERROR)) + { + if (ancc_env->env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity_128(ANCC_CHAR_MAX, + ancc_env->env[conidx]->anc.chars, + ancc_anc_char); + } + else if (ancc_env->env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(ANCC_DESC_MAX, + ancc_env->env[conidx]->anc.descs, + ancc_anc_char_desc, + ancc_env->env[conidx]->anc.chars); + } + } + // Send response and go to IDLE state + ancc_enable_rsp_send(ancc_env, conidx, status); + ke_state_set(dest_id, ANCC_IDLE); + } + else if (ancc_env->state[conidx] == ANCC_BUSY) + { + uint8_t op_code = ancc_env->env[conidx]->last_op_code; + + switch (param->operation) + { + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + switch (op_code) + { + case (ANCC_WR_NTF_NTF_SRC_OP_CODE): + case (ANCC_WR_NTF_DATA_SRC_OP_CODE): + { + ancc_wr_cfg_ntf_rsp_send(ancc_env, conidx, op_code, param->status); + } break; + + case (ANCC_GET_NTF_ATTS_CMD_OP_CODE): + case (ANCC_GET_APP_ATTS_CMD_OP_CODE): + { + // If there was an error then command is considered completed. + if (param->status != GAP_ERR_NO_ERROR) + { + ancc_cmp_evt_send(ancc_env, conidx, op_code, param->status); + } + } break; + + case (ANCC_PERF_NTF_ACT_CMD_OP_CODE): + { + // No notifications after this command + ancc_cmp_evt_send(ancc_env, conidx, op_code, param->status); + } break; + + default: + ASSERT_ERR(0); + break; + } + } break; + + case GATTC_READ: + { + if (param->status != GAP_ERR_NO_ERROR) + { + if ((op_code == ANCC_RD_NTF_NTF_SRC_OP_CODE) || (op_code == ANCC_RD_NTF_DATA_SRC_OP_CODE)) + { + ancc_rd_cfg_ntf_rsp_send(ancc_env, conidx, op_code, 0, param->status); + } + } + }break; + + default: + break; + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANCC_WR_CFG_NTF_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int ancc_wr_cfg_ntf_req_handler(ke_msg_id_t const msgid, + struct ancc_wr_cfg_ntf_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint16_t cfg_hdl = ATT_INVALID_SEARCH_HANDLE; + struct ancc_env_tag *ancc_env = PRF_ENV_GET(ANCC, ancc); + uint8_t conidx = KE_IDX_GET(dest_id); + NS_LOG_DEBUG("%s\r\n", __func__); + if (ancc_env->state[conidx] == ANCC_IDLE) + { + uint8_t status = PRF_ERR_REQ_DISALLOWED; + if ((param->cfg_val == PRF_CLI_STOP_NTFIND) || + (param->cfg_val == PRF_CLI_START_NTF)) + { + if (param->op_code == ANCC_WR_NTF_NTF_SRC_OP_CODE) + { + cfg_hdl = ancc_env->env[conidx]->anc.descs[ANCC_DESC_NTF_SRC_CL_CFG].desc_hdl; + } + else if (param->op_code == ANCC_WR_NTF_DATA_SRC_OP_CODE) + { + cfg_hdl = ancc_env->env[conidx]->anc.descs[ANCC_DESC_DATA_SRC_CL_CFG].desc_hdl; + } + + if (cfg_hdl != ATT_INVALID_SEARCH_HANDLE) + { + prf_gatt_write_ntf_ind(&ancc_env->prf_env, conidx, cfg_hdl, param->cfg_val); + ancc_env->env[conidx]->last_op_code = param->op_code; + ke_state_set(dest_id, ANCC_BUSY); + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + ancc_wr_cfg_ntf_rsp_send(ancc_env, conidx, param->op_code, status); + } + } + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANCC_RD_CFG_NTF_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int ancc_rd_cfg_ntf_req_handler(ke_msg_id_t const msgid, + struct ancc_rd_cfg_ntf_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint16_t cfg_hdl = ATT_INVALID_SEARCH_HANDLE; + struct ancc_env_tag *ancc_env = PRF_ENV_GET(ANCC, ancc); + uint8_t conidx = KE_IDX_GET(dest_id); + NS_LOG_DEBUG("%s\r\n", __func__); + + if (ancc_env->state[conidx] == ANCC_IDLE) + { + uint8_t status = PRF_ERR_REQ_DISALLOWED; + if (param->op_code == ANCC_RD_NTF_NTF_SRC_OP_CODE) + { + cfg_hdl = ancc_env->env[conidx]->anc.descs[ANCC_DESC_NTF_SRC_CL_CFG].desc_hdl; + } + else if (param->op_code == ANCC_RD_NTF_DATA_SRC_OP_CODE) + { + cfg_hdl = ancc_env->env[conidx]->anc.descs[ANCC_DESC_DATA_SRC_CL_CFG].desc_hdl; + } + + if (cfg_hdl != ATT_INVALID_SEARCH_HANDLE) + { + prf_read_char_send(&ancc_env->prf_env, conidx, + ancc_env->env[conidx]->anc.svc.shdl, + ancc_env->env[conidx]->anc.svc.ehdl, + cfg_hdl); + + ancc_env->env[conidx]->last_op_code = param->op_code; + ke_state_set(dest_id, ANCC_BUSY); + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + + if (status != GAP_ERR_NO_ERROR) + { + ancc_rd_cfg_ntf_rsp_send(ancc_env, conidx, param->op_code, 0, status); + } + } + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANCC_GET_NTF_ATTS_CMD_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int ancc_get_ntf_atts_cmd_req_handler(ke_msg_id_t const msgid, + struct ancc_get_ntf_atts_cmd_req *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct ancc_env_tag *ancc_env = PRF_ENV_GET(ANCC, ancc); + uint8_t msg_status = KE_MSG_CONSUMED; + uint8_t conidx = KE_IDX_GET(dest_id); + NS_LOG_DEBUG("%s\r\n", __func__); + if (ancc_env->state[conidx] == ANCC_IDLE) + { + uint8_t status = PRF_ERR_REQ_DISALLOWED; + uint8_t buffer[ANCC_GET_ATT_CMD_MAX_LEN]; + uint8_t length = 0; + uint16_t handle = ancc_env->env[conidx]->anc.chars[ANCC_CHAR_CTRL_PT].val_hdl; + + if (handle != ATT_INVALID_HANDLE) + { + buffer[length] = CMD_ID_GET_NTF_ATTS; + length += 1; + co_write32p(&buffer[length], param->ntf_uid); + length += 4; + + if (param->atts & NTF_ATT_ID_APP_ID_PRESENT) + { + // App Identifier + buffer[length] = NTF_ATT_ID_APP_ID; + length += 1; + } + if (param->atts & NTF_ATT_ID_TITLE_PRESENT) + { + // Title (Needs to be followed by a 2-byte max length parameter) + buffer[length] = NTF_ATT_ID_TITLE; + length += 1; + co_write16p(&buffer[length], param->title_len); + length += 2; + } + if (param->atts & NTF_ATT_ID_SUBTITLE_PRESENT) + { + // Subtitle (Needs to be followed by a 2-byte max length parameter) + buffer[length] = NTF_ATT_ID_SUBTITLE; + length += 1; + co_write16p(&buffer[length], param->subtitle_len); + length += 2; + } + if (param->atts & NTF_ATT_ID_MSG_PRESENT) + { + // Message (Needs to be followed by a 2-byte max length parameter) + buffer[length] = NTF_ATT_ID_MSG; + length += 1; + co_write16p(&buffer[length], param->message_len); + length += 2; + } + if (param->atts & NTF_ATT_ID_MSG_SIZE_PRESENT) + { + // Message Size + buffer[length] = NTF_ATT_ID_MSG_SIZE; + length += 1; + } + if (param->atts & NTF_ATT_ID_DATE_PRESENT) + { + // Date + buffer[length] = NTF_ATT_ID_DATE; + length += 1; + } + + if(length < 6) + { + // Check if no attributes have been requested. + status = PRF_ERR_INVALID_PARAM; + } + else + { + status = GAP_ERR_NO_ERROR; + } + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send completion event with error status + ancc_cmp_evt_send(ancc_env, conidx, ANCC_GET_NTF_ATTS_CMD_OP_CODE, status); + } + else + { + // Write command + prf_gatt_write(&ancc_env->prf_env, conidx, handle, buffer, length, GATTC_WRITE); + ancc_env->env[conidx]->operation = param; + ancc_env->env[conidx]->last_op_code = ANCC_GET_NTF_ATTS_CMD_OP_CODE; + if (ancc_env->env[conidx]->data_src.state != ANCC_DATA_SRC_NTF_CMD_UID_ERROR) + { + // Initialize the Data Source Notification reception state machine + // If in error state, do not change the state until all the erroneous packets have been received + ancc_env->env[conidx]->data_src.state = ANCC_DATA_SRC_NTF_IDLE; + } + + ke_state_set(dest_id, ANCC_BUSY); + msg_status = KE_MSG_NO_FREE; + } + } + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANCC_GET_APP_ATTS_CMD_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int ancc_get_app_atts_cmd_req_handler(ke_msg_id_t const msgid, + struct ancc_get_app_atts_cmd_req *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct ancc_env_tag *ancc_env = PRF_ENV_GET(ANCC, ancc); + uint8_t msg_status = KE_MSG_CONSUMED; + uint8_t conidx = KE_IDX_GET(dest_id); + NS_LOG_DEBUG("%s\r\n", __func__); + if (ancc_env->state[conidx] == ANCC_IDLE) + { + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t length = 0; + // Temporary buffer to store the Get App Attributes command + uint8_t *buffer = (uint8_t*)ke_malloc(param->app_id_length + 2, KE_MEM_NON_RETENTION); + + uint16_t handle = ancc_env->env[conidx]->anc.chars[ANCC_CHAR_CTRL_PT].val_hdl; + + if (handle != ATT_INVALID_HANDLE) + { + // Pack command + buffer[length] = CMD_ID_GET_APP_ATTS; + length += 1; + memcpy( &buffer[length], param->app_id, param->app_id_length); + length += param->app_id_length; + + if (param->atts & APP_ATT_ID_DISPLAY_NAME_PRESENT) // App Identifier + { + buffer[length] = NTF_ATT_ID_APP_ID; + length += 1; + } + else + { + // No attributes have been requested. + status = PRF_ERR_INVALID_PARAM; + } + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send completion event with error status + ancc_cmp_evt_send(ancc_env, conidx, ANCC_GET_APP_ATTS_CMD_OP_CODE, status); + } + else + { + // Write command + prf_gatt_write(&ancc_env->prf_env, conidx, handle, buffer, length, GATTC_WRITE); + ancc_env->env[conidx]->operation = param; + ancc_env->env[conidx]->last_op_code = ANCC_GET_APP_ATTS_CMD_OP_CODE; + if (ancc_env->env[conidx]->data_src.state != ANCC_DATA_SRC_APP_CMD_ERROR) + { + // Initialize the APP ID reception state machine + // If in error state, do not change the state until all the erroneous packets have been received + ancc_env->env[conidx]->data_src.state = ANCC_DATA_SRC_APP_ID_IDLE; + } + + ke_state_set(dest_id, ANCC_BUSY); + msg_status = KE_MSG_NO_FREE; + } + + ke_free(buffer); + } + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANCC_PERF_NTF_ACT_CMD_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int ancc_perf_ntf_act_cmd_req_handler(ke_msg_id_t const msgid, + struct ancc_perf_ntf_act_cmd_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct ancc_env_tag *ancc_env = PRF_ENV_GET(ANCC, ancc); + uint8_t conidx = KE_IDX_GET(dest_id); + NS_LOG_DEBUG("%s\r\n", __func__); + if (ancc_env->state[conidx] == ANCC_IDLE) + { + uint8_t status = PRF_ERR_REQ_DISALLOWED; + uint8_t length = 0; + uint8_t buffer[ANCC_PERF_NTF_ACT_CMD_MAX_LEN]; + uint16_t handle = ancc_env->env[conidx]->anc.chars[ANCC_CHAR_CTRL_PT].val_hdl; + + if (handle != ATT_INVALID_HANDLE) + { + if (param->action > ACT_ID_NB) + { + status = PRF_ERR_INVALID_PARAM; + } + else + { + // Pack command + buffer[length++] = CMD_ID_PERF_NTF_ACT; + co_write32p(&buffer[length], param->ntf_uid); + length += 4; + buffer[length++] = param->action; + status = GAP_ERR_NO_ERROR; + } + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send completion event with error status + ancc_cmp_evt_send(ancc_env, conidx, ANCC_PERF_NTF_ACT_CMD_OP_CODE, status); + } + else + { + // Write command + prf_gatt_write(&ancc_env->prf_env, conidx, handle, buffer, length, GATTC_WRITE); + ancc_env->env[conidx]->last_op_code= ANCC_PERF_NTF_ACT_CMD_OP_CODE; + ke_state_set(dest_id, ANCC_BUSY); + } + } + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct ancc_env_tag *ancc_env = PRF_ENV_GET(ANCC, ancc); + uint8_t conidx = KE_IDX_GET(dest_id); + uint16_t cfg_val; + + ASSERT_ERR(ancc_env != NULL); + ASSERT_ERR(ancc_env->env[conidx] != NULL); + NS_LOG_DEBUG("%s\r\n", __func__); + + uint8_t op_code = ancc_env->env[conidx]->last_op_code; + + if ((op_code == ANCC_RD_NTF_NTF_SRC_OP_CODE) || (op_code == ANCC_RD_NTF_DATA_SRC_OP_CODE)) + { + cfg_val = co_read16p(param->value); + ancc_rd_cfg_ntf_rsp_send(ancc_env, conidx, op_code, cfg_val, GAP_ERR_NO_ERROR); + } + else + { + ASSERT_ERR(0); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct ancc_env_tag *ancc_env = PRF_ENV_GET(ANCC, ancc); + uint8_t conidx = KE_IDX_GET(dest_id); + NS_LOG_DEBUG("%s\r\n", __func__); + + if (param->type == GATTC_NOTIFY) + { + if (param->handle == ancc_env->env[conidx]->anc.chars[ANCC_CHAR_NTF_SRC].val_hdl) + { + if (param->value[2] < CAT_ID_NB) + { + #if ANC_CFG_DROP_PREEXISTING_NTF + if (param->value[1] & ANC_EVT_FLAG_PRE_EXISTING) + { + // Drop pre-existing notifications, as we might run out of + // memory otherwise. + return KE_MSG_CONSUMED; + } + #endif + + struct ancc_ntf_src_ind *ind = KE_MSG_ALLOC(ANCC_NTF_SRC_IND, + prf_dst_task_get(&(ancc_env->prf_env), conidx), + prf_src_task_get(&(ancc_env->prf_env), conidx), + ancc_ntf_src_ind); + + ind->value.event_id = param->value[0]; + ind->value.event_flags = param->value[1]; + ind->value.cat_id = param->value[2]; + ind->value.cat_cnt = param->value[3]; + ind->value.ntf_uid = co_read32p(¶m->value[4]); + + ke_msg_send(ind); + } + } + else if (param->handle == ancc_env->env[conidx]->anc.chars[ANCC_CHAR_DATA_SRC].val_hdl) + { + switch (ancc_env->env[conidx]->last_op_code) + { + case ANCC_GET_NTF_ATTS_CMD_OP_CODE: + { + ancc_get_ntf_atts_rsp(ancc_env, conidx, param->value, param->length); + }break; + + case ANCC_GET_APP_ATTS_CMD_OP_CODE: + { + ancc_get_app_atts_rsp(ancc_env, conidx, param->value, param->length); + }break; + } + } + } + + return (KE_MSG_CONSUMED); +} + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the ancc default message handlers +KE_MSG_HANDLER_TAB(ancc) +{ + {ANCC_ENABLE_REQ, (ke_msg_func_t)ancc_enable_req_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {ANCC_WR_CFG_NTF_REQ, (ke_msg_func_t)ancc_wr_cfg_ntf_req_handler}, + {ANCC_RD_CFG_NTF_REQ, (ke_msg_func_t)ancc_rd_cfg_ntf_req_handler}, + {ANCC_GET_NTF_ATTS_CMD_REQ, (ke_msg_func_t)ancc_get_ntf_atts_cmd_req_handler}, + {ANCC_GET_APP_ATTS_CMD_REQ, (ke_msg_func_t)ancc_get_app_atts_cmd_req_handler}, + {ANCC_PERF_NTF_ACT_CMD_REQ, (ke_msg_func_t)ancc_perf_ntf_act_cmd_req_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, +}; + +void ancc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct ancc_env_tag *p_ancc_env = PRF_ENV_GET(ANCC, ancc); + + p_task_desc->msg_handler_tab = ancc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(ancc_msg_handler_tab); + p_task_desc->state = p_ancc_env->state; + p_task_desc->idx_max = ANCC_IDX_MAX; +} + +/// @} ANCCTASK + +#endif // BLE_ANC_CLIENT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anp_common.h new file mode 100644 index 0000000..29cf9a6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anp_common.h @@ -0,0 +1,228 @@ +/** + **************************************************************************************** + * + * @file anp_common.h + * + * @brief Header File - Alert Notification Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +#ifndef _ANP_COMMON_H_ +#define _ANP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup ANP Alert Notification Profile + * @ingroup ANP + * @brief Alert Notification Profile + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Command Not Supported - Protocol +#define ANP_CMD_NOT_SUPPORTED (0xA0) +/// Category Not Supported - Proprietary +#define ANP_CAT_NOT_SUPPORTED (0xA1) + +/// New Alert Characteristic Value - Text String Information Max Length +#define ANS_NEW_ALERT_STRING_INFO_MAX_LEN (18) +/// New Alert Characteristic Value Max Length +#define ANS_NEW_ALERT_MAX_LEN (ANS_NEW_ALERT_STRING_INFO_MAX_LEN + 2) +/// Bonded data configured +#define ANPS_FLAG_CFG_PERFORMED_OK (0x10) +/// Alert Category ID 1 Mask +#define ANP_CAT_ID_1_MASK (ANP_CAT_ID_HIGH_PRTY_ALERT_BIT | ANP_CAT_ID_INST_MSG_BIT) +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Category ID Field Keys +enum anp_category_id +{ + /// Simple Alert + CAT_ID_SPL_ALERT = 0, + /// Email + CAT_ID_EMAIL, + /// News Feed + CAT_ID_NEWS, + /// Incoming Call + CAT_ID_CALL, + /// Missed Call + CAT_ID_MISSED_CALL, + /// SMS/MMS + CAT_ID_SMS_MMS, + /// Voice Mail + CAT_ID_VOICE_MAIL, + /// Schedule + CAT_ID_SCHEDULE, + /// High Priority Alert + CAT_ID_HIGH_PRTY_ALERT, + /// Instant Message + CAT_ID_INST_MSG, + + CAT_ID_NB, + + /// All supported category + CAT_ID_ALL_SUPPORTED_CAT = 255, +}; + +/// Command ID Field Keys +enum anp_cmd_id +{ + /// Enable New Incoming Alert Notification + CMD_ID_EN_NEW_IN_ALERT_NTF = 0, + /// Enable Unread Category Status Notification + CMD_ID_EN_UNREAD_CAT_STATUS_NTF, + /// Disable New Incoming Alert Notification + CMD_ID_DIS_NEW_IN_ALERT_NTF, + /// Disable Unread Category Status Notification + CMD_ID_DIS_UNREAD_CAT_STATUS_NTF, + /// Notify New Incoming Alert immediately + CMD_ID_NTF_NEW_IN_ALERT_IMM, + /// Notify Unread Category Status immediately + CMD_ID_NTF_UNREAD_CAT_STATUS_IMM, + + CMD_ID_NB, +}; + +/// Characteristic Codes +enum +{ + /// Supported New Alert Category Characteristic + ANS_SUPP_NEW_ALERT_CAT_CHAR, + /// New Alert Characteristic + ANS_NEW_ALERT_CHAR, + /// Supported Unread Alert Category Characteristic + ANS_SUPP_UNREAD_ALERT_CAT_CHAR, + /// Unread Alert Status Characteristic + ANS_UNREAD_ALERT_STATUS_CHAR, + /// Alert Notification Control Point Characteristic + ANS_ALERT_NTF_CTNL_PT_CHAR, + + ANS_CHAR_MAX, +}; + +/// Alert codes +enum anp_alert_codes +{ + /// New Alert + ANP_NEW_ALERT = 0, + /// Unread Alert + ANP_UNREAD_ALERT, +}; + +/// Alert category bit field (@see struct anp_cat_id_bit_mask) +enum anp_alert_category_id_bf +{ + // Alert Category ID Bit Mask 0 Masks + /// Simple Alert - The title of the alert + ANP_CAT_ID_SPL_ALERT_SUP_POS = 0, + ANP_CAT_ID_SPL_ALERT_SUP_BIT = CO_BIT(ANP_CAT_ID_SPL_ALERT_SUP_POS), + + /// Email - Sender name + ANP_CAT_ID_EMAIL_SUP_POS = 1, + ANP_CAT_ID_EMAIL_SUP_BIT = CO_BIT(ANP_CAT_ID_EMAIL_SUP_POS), + + /// News - Title of the news feed + ANP_CAT_ID_NEWS_SUP_POS = 2, + ANP_CAT_ID_NEWS_SUP_BIT = CO_BIT(ANP_CAT_ID_NEWS_SUP_POS), + + /// Call - Caller name or caller ID + ANP_CAT_ID_CALL_SUP_POS = 3, + ANP_CAT_ID_CALL_SUP_BIT = CO_BIT(ANP_CAT_ID_CALL_SUP_POS), + + /// Missed call - Caller name or caller ID + ANP_CAT_ID_MISSED_CALL_SUP_POS = 4, + ANP_CAT_ID_MISSED_CALL_SUP_BIT = CO_BIT(ANP_CAT_ID_MISSED_CALL_SUP_POS), + + /// SMS - Sender name or caller ID + ANP_CAT_ID_SMS_MMS_SUP_POS = 5, + ANP_CAT_ID_SMS_MMS_SUP_BIT = CO_BIT(ANP_CAT_ID_SMS_MMS_SUP_POS), + + /// Voice mail - Sender name or caller ID + ANP_CAT_ID_VOICE_MAIL_SUP_POS = 6, + ANP_CAT_ID_VOICE_MAIL_SUP_BIT = CO_BIT(ANP_CAT_ID_VOICE_MAIL_SUP_POS), + + /// Schedule - Title of the schedule + ANP_CAT_ID_SCHEDULE_SUP_POS = 7, + ANP_CAT_ID_SCHEDULE_SUP_BIT = CO_BIT(ANP_CAT_ID_SCHEDULE_SUP_POS), + + // Alert Category ID Bit Mask 1 Masks + /// High Prioritized Alert = Title of the alert + ANP_CAT_ID_HIGH_PRTY_ALERT_POS = 0, + ANP_CAT_ID_HIGH_PRTY_ALERT_BIT = CO_BIT(ANP_CAT_ID_HIGH_PRTY_ALERT_POS), + + /// Instant Messaging - Sender name + ANP_CAT_ID_INST_MSG_POS = 1, + ANP_CAT_ID_INST_MSG_BIT = CO_BIT(ANP_CAT_ID_INST_MSG_POS), +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Alert Category ID Bit Mask Structure +struct anp_cat_id_bit_mask +{ + /// Category ID Bit Mask 0 + uint8_t cat_id_mask_0; + /// Category ID Bit Mask 1 + uint8_t cat_id_mask_1; +}; + +/// New Alert Characteristic Value Structure +struct anp_new_alert +{ + /// Information String Length + uint8_t info_str_len; + + /// Category ID + uint8_t cat_id; + /// Number of alerts + uint8_t nb_new_alert; + /// Text String Information + uint8_t str_info[1]; +}; + +/// Unread Alert Characteristic Value Structure +struct anp_unread_alert +{ + /// Category ID + uint8_t cat_id; + /// Number of alert + uint8_t nb_unread_alert; +}; + +/// Alert Notification Control Point Characteristic Value Structure +struct anp_ctnl_pt +{ + /// Command ID + uint8_t cmd_id; + /// Category ID + uint8_t cat_id; +}; + +/// @} anp_common + +#endif //(_ANP_COMMON_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/api/anpc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/api/anpc_task.h new file mode 100644 index 0000000..6e35d86 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/api/anpc_task.h @@ -0,0 +1,238 @@ +/** + **************************************************************************************** + * + * @file anpc_task.h + * + * @brief Header file - Alert Notification Profile Client Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _ANPC_TASK_H_ +#define _ANPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup ANPCTASK Alert Notification Profile Client Task + * @ingroup ANPC + * @brief Alert Notification Profile Client Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + +#include "anp_common.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Message IDs +/*@TRACE*/ +enum anpc_msg_ids +{ + /// Enable the Alert Notification Profile Client task - at connection + ANPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_ANPC), + /// Enable the Alert Notification Profile Client task - at connection + ANPC_ENABLE_RSP, + + /// Read the value of an attribute in the peer device database + ANPC_READ_CMD, + /// Write the value of an attribute in the peer device database + ANPC_WRITE_CMD, + + /// Indicate that an attribute value has been received either upon notification or read response + ANPC_VALUE_IND, + + /// Complete Event Information + ANPC_CMP_EVT, +}; + +/// Operation Codes +enum anpc_op_codes +{ + /// Reserved operation code + ANPC_RESERVED_OP_CODE = 0x00, + + /** + * EXTERNAL OPERATION CODES + */ + + /// Discovery Procedure + ANPC_ENABLE_OP_CODE, + /// Read attribute value Procedure + ANPC_READ_OP_CODE, + /// Write attribute value Procedure + ANPC_WRITE_OP_CODE, + + /** + * INTERNAL OPERATION CODES + */ + + /// Discovery Procedure - Read Supported New Alert Category + ANPC_ENABLE_RD_NEW_ALERT_OP_CODE, + /// Discovery Procedure - Read Supported Unread Alert Category + ANPC_ENABLE_RD_UNREAD_ALERT_OP_CODE, + /// Discovery Procedure - Enable New Alert Categories for Notifications + ANPC_ENABLE_WR_NEW_ALERT_OP_CODE, + /// Discovery Procedure - Ask to be notified immediately for New Alert Values + ANPC_ENABLE_WR_NTF_NEW_ALERT_OP_CODE, + /// Discovery Procedure - Enable Unread Alert Categories for Notifications + ANPC_ENABLE_WR_UNREAD_ALERT_OP_CODE, + /// Discovery Procedure - Ask to be notified immediately for Unread Alert Values + ANPC_ENABLE_WR_NTF_UNREAD_ALERT_OP_CODE, +}; + +/// Alert Notification Service Characteristics +enum anpc_ans_chars +{ + /// Supported New Alert Category + ANPC_CHAR_SUP_NEW_ALERT_CAT, + /// New Alert + ANPC_CHAR_NEW_ALERT, + /// Supported Unread Alert Category + ANPC_CHAR_SUP_UNREAD_ALERT_CAT, + /// Unread Alert Status + ANPC_CHAR_UNREAD_ALERT_STATUS, + /// Alert Notification Control Point + ANPC_CHAR_ALERT_NTF_CTNL_PT, + + ANPC_CHAR_MAX, +}; + +/// Alert Notification Service Characteristic Descriptors +enum anpc_ans_descs +{ + /// New Alert Char. - Client Characteristic Configuration + ANPC_DESC_NEW_ALERT_CL_CFG, + /// Unread Alert Status Char. - Client Characteristic Configuration + ANPC_DESC_UNREAD_ALERT_STATUS_CL_CFG, + + ANPC_DESC_MAX, + + ANPC_DESC_MASK = 0x10, +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Alert Notification Service + */ +struct anpc_ans_content +{ + /// Service info + struct prf_svc svc; + + /// Characteristic info: + /// - Supported New Alert Category + /// - New Alert + /// - Supported Unread Alert Category + /// - Unread Alert Status + /// - Alert Notification Control Point + struct prf_char_inf chars[ANPC_CHAR_MAX]; + + /// Descriptor handles: + /// - New Alert Client Cfg + /// - Unread Alert Status Client Cfg + struct prf_char_desc_inf descs[ANPC_DESC_MAX]; +}; + +/// Parameters of the @ref ANPC_ENABLE_REQ message +struct anpc_enable_req +{ + /// Connection type + uint8_t con_type; + + /// New Alert Category to Enable for Notifications + struct anp_cat_id_bit_mask new_alert_enable; + /// Unread Alert Category to Enable for Notifications + struct anp_cat_id_bit_mask unread_alert_enable; + + /// Existing handle values ANS + struct anpc_ans_content ans; +}; + +/// Parameters of the @ref ANPC_ENABLE_RSP message +struct anpc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values ANS + struct anpc_ans_content ans; +}; + +/// Parameters of the @ref ANPC_READ_CMD message +struct anpc_read_cmd +{ + /// Operation Code + uint8_t operation; + /// Read code + uint8_t read_code; +}; + +/// Parameters of the @ref ANPC_WRITE_CMD message +struct anpc_write_cmd +{ + /// Operation Code + uint8_t operation; + /// Write code + uint8_t write_code; + /// Value + union anpc_write_value_tag + { + /// Alert Notification Control Point + struct anp_ctnl_pt ctnl_pt; + /// New Alert Notification Configuration + uint16_t new_alert_ntf_cfg; + /// Unread Alert Status Notification Configuration + uint16_t unread_alert_status_ntf_cfg; + } value; +}; + +/// Parameters of the @ref ANPC_VALUE_IND message +struct anpc_value_ind +{ + /// Attribute Code + uint8_t att_code; + /// Value + union anpc_value_tag + { + /// List of supported categories + struct anp_cat_id_bit_mask supp_cat; + /// New Alert + struct anp_new_alert new_alert; + /// Unread Alert + struct anp_unread_alert unread_alert; + /// Client Characteristic Configuration Descriptor Value + uint16_t ntf_cfg; + } value; +}; + +/// Parameters of the @ref ANPC_CMP_EVT message +struct anpc_cmp_evt +{ + /// Operation code + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} ANPCTASK + +#endif //(_ANPC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/sourcelist.txt new file mode 100644 index 0000000..fd8df75 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + anpc.c + anpc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/src/anpc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/src/anpc.c new file mode 100644 index 0000000..7af5715 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/src/anpc.c @@ -0,0 +1,278 @@ +/** + **************************************************************************************** + * + * @file anpc.c + * + * @brief Alert Notification Profile Client implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup ANPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_AN_CLIENT) + +#include "anp_common.h" +#include "anpc.h" +#include "anpc_task.h" + +#include "ke_mem.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the ANPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t anpc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void* p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct anpc_env_tag* p_anpc_env = + (struct anpc_env_tag* ) ke_malloc(sizeof(struct anpc_env_tag), KE_MEM_ATT_DB); + + // allocate ANPC required environment variable + p_env->env = (prf_env_t*) p_anpc_env; + + p_anpc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_anpc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_ANPC; + anpc_task_init(&(p_env->desc)); + + for (idx = 0; idx < ANPC_IDX_MAX ; idx++) + { + p_anpc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), ANPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void anpc_cleanup(struct prf_task_env* p_env, uint8_t conidx, uint8_t reason) +{ + struct anpc_env_tag* p_anpc_env = (struct anpc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_anpc_env->p_env[conidx] != NULL) + { + ke_free(p_anpc_env->p_env[conidx]); + p_anpc_env->p_env[conidx] = NULL; + } + + // Put ANP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), ANPC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the ANPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void anpc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct anpc_env_tag* p_anpc_env = (struct anpc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < ANPC_IDX_MAX; idx++) + { + anpc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_anpc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void anpc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put ANP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), ANPC_IDLE); +} + +/// ANPC Task interface required by profile manager +const struct prf_task_cbs anpc_itf = +{ + anpc_init, + anpc_destroy, + anpc_create, + anpc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* anpc_prf_itf_get(void) +{ + return &anpc_itf; +} + +void anpc_enable_rsp_send(struct anpc_env_tag *p_anpc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on ANPS + struct anpc_enable_rsp *p_rsp = KE_MSG_ALLOC( + ANPC_ENABLE_RSP, + prf_dst_task_get(&(p_anpc_env->prf_env), conidx), + prf_src_task_get(&(p_anpc_env->prf_env), conidx), + anpc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->ans = p_anpc_env->p_env[conidx]->ans; + // Register ANPC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_anpc_env->prf_env), conidx, &(p_anpc_env->p_env[conidx]->ans.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_anpc_env->prf_env), conidx), ANPC_IDLE); + } + + ke_msg_send(p_rsp); +} + +bool anpc_found_next_alert_cat(struct anpc_env_tag *p_anpc_env, uint8_t conidx, struct anp_cat_id_bit_mask cat_id) +{ + // Next Category Found ? + bool found = false; + + if (p_anpc_env->p_env[conidx]->last_uuid_req < CAT_ID_HIGH_PRTY_ALERT) + { + // Look in the first part of the categories + while ((p_anpc_env->p_env[conidx]->last_uuid_req < CAT_ID_HIGH_PRTY_ALERT) && (!found)) + { + if (((cat_id.cat_id_mask_0 >> p_anpc_env->p_env[conidx]->last_uuid_req) & 1) == 1) + { + found = true; + } + + p_anpc_env->p_env[conidx]->last_uuid_req++; + } + } + + if (p_anpc_env->p_env[conidx]->last_uuid_req >= CAT_ID_HIGH_PRTY_ALERT) + { + // Look in the first part of the categories + while ((p_anpc_env->p_env[conidx]->last_uuid_req < CAT_ID_NB) && (!found)) + { + if (((cat_id.cat_id_mask_1 >> + (p_anpc_env->p_env[conidx]->last_uuid_req - CAT_ID_HIGH_PRTY_ALERT)) & 1) == 1) + { + found = true; + } + + p_anpc_env->p_env[conidx]->last_uuid_req++; + } + } + + return found; +} + +void anpc_write_alert_ntf_ctnl_pt(struct anpc_env_tag *p_anpc_env, uint8_t conidx, uint8_t cmd_id, uint8_t cat_id) +{ + struct anp_ctnl_pt ctnl_pt = {cmd_id, cat_id}; + + // Send the write request + prf_gatt_write(&(p_anpc_env->prf_env), conidx, + p_anpc_env->p_env[conidx]->ans.chars[ANPC_CHAR_ALERT_NTF_CTNL_PT].val_hdl, + (uint8_t *)&ctnl_pt, sizeof(struct anp_ctnl_pt), GATTC_WRITE); +} + +void anpc_send_cmp_evt(struct anpc_env_tag *p_anpc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct anpc_cmp_evt *p_evt; + + if (p_anpc_env->p_env[conidx] != NULL) + { + // Free the stored operation if needed + if (p_anpc_env->p_env[conidx]->p_operation != NULL) + { + ke_msg_free(ke_param2msg(p_anpc_env->p_env[conidx]->p_operation)); + p_anpc_env->p_env[conidx]->p_operation = NULL; + } + } + + // Go back to the CONNECTED state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_anpc_env->prf_env), conidx)) == ANPC_BUSY) + { + ke_state_set(prf_src_task_get(&p_anpc_env->prf_env, conidx), ANPC_IDLE); + } + + // Send the message + p_evt = KE_MSG_ALLOC(ANPC_CMP_EVT, + prf_dst_task_get(&(p_anpc_env->prf_env), conidx), + prf_src_task_get(&(p_anpc_env->prf_env), conidx), + anpc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //(BLE_AN_CLIENT) + +/// @} ANPC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/src/anpc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/src/anpc.h new file mode 100644 index 0000000..542747c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/src/anpc.h @@ -0,0 +1,206 @@ +/** + **************************************************************************************** + * + * @file anpc.h + * + * @brief Header file - Alert Notification Status Profile - Client Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _ANPC_H_ +#define _ANPC_H_ + +/** + **************************************************************************************** + * @addtogroup ANPC Alert Notification Profile Client + * @ingroup ANP + * @brief Phone Alert Notification Profile Client + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_AN_CLIENT) +#include "anp_common.h" +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" +#include "anpc_task.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Alert Notification Client task instances +#define ANPC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the ANPC task +enum anpc_states +{ + /// Free state + ANPC_FREE, + /// Idle state + ANPC_IDLE, + /// Connected state + ANPC_DISCOVERING, + /// Busy state + ANPC_BUSY, + + /// Number of defined states. + ANPC_STATE_MAX +}; + +/// Codes for reading/writing a ANS characteristic with one single request +enum anpc_rd_wr_ntf_codes +{ + /// Read ANS Supported New Alert Category + ANPC_RD_SUP_NEW_ALERT_CAT = ANPC_CHAR_SUP_NEW_ALERT_CAT, + /// NTF New Alert + ANPC_NTF_NEW_ALERT = ANPC_CHAR_NEW_ALERT, + /// Read ANS Supported Unread Alert Category + ANPC_RD_SUP_UNREAD_ALERT_CAT = ANPC_CHAR_SUP_UNREAD_ALERT_CAT, + /// NTF Unread Alert Categories + ANPC_NTF_UNREAD_ALERT = ANPC_CHAR_UNREAD_ALERT_STATUS, + /// Write ANS Alert Notification Control Point + ANPC_WR_ALERT_NTF_CTNL_PT = ANPC_CHAR_ALERT_NTF_CTNL_PT, + + /// Read/Write ANS New Alert Client Characteristic Configuration Descriptor + ANPC_RD_WR_NEW_ALERT_CFG = (ANPC_DESC_NEW_ALERT_CL_CFG | ANPC_DESC_MASK), + /// Read ANS Unread Alert Status Client Characteristic Configuration Descriptor + ANPC_RD_WR_UNREAD_ALERT_STATUS_CFG = (ANPC_DESC_UNREAD_ALERT_STATUS_CL_CFG | ANPC_DESC_MASK), +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + + +/// Command Message Basic Structure +struct anpc_cmd +{ + /// Operation Code + uint8_t operation; + + /// MORE DATA +}; + +struct anpc_cnx_env +{ + /// Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Last characteristic code used in a read or a write request + uint16_t last_char_code; + /// Counter used to check service uniqueness + uint8_t nb_svc; + /// Current operation code + void *p_operation; + /// Phone Alert Status Service Characteristics + struct anpc_ans_content ans; +}; + +/// Alert Notification Profile Client environment variable +struct anpc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct anpc_cnx_env *p_env[ANPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[ANPC_IDX_MAX]; +}; + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Send Alert Notification ATT DB discovery results to ANPC host. + * @param[in] p_anpc_env Environment variable + * @param[in] conidx Connection index + * @param[in] status Status code + **************************************************************************************** + */ +void anpc_enable_rsp_send(struct anpc_env_tag *p_anpc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Try to find the next Alert Category + * @param[in] p_anpc_env Environment variable + * @param[in] conidx Connection index + * @param[in] cat_id Alert category bit mask + * @return If next alert category was found or not. + ***************************************************************************************** + */ +bool anpc_found_next_alert_cat(struct anpc_env_tag *p_anpc_env, uint8_t conidx, + struct anp_cat_id_bit_mask cat_id); + +/** + **************************************************************************************** + * @brief Write over GATT to enable sending of notifications for the found category ID + * @param[in] p_anpc_env Environment variable + * @param[in] conidx Connection index + * @param[in] cmd_id Command ID @see enum anp_cmd_id + * @param[in] cat_id Alert category bit mask + ***************************************************************************************** + */ +void anpc_write_alert_ntf_ctnl_pt(struct anpc_env_tag *p_anpc_env, uint8_t conidx, + uint8_t cmd_id, uint8_t cat_id); + +/** + **************************************************************************************** + * @brief Send a ANPC_CMP_EVT message to the task which enabled the profile + * @param[in] p_anpc_env environment variable + * @param[in] conidx Connection index + * @param[in] operation Operation + * @param[in] status Status + **************************************************************************************** + */ +void anpc_send_cmp_evt(struct anpc_env_tag *p_anpc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/** + **************************************************************************************** + * @brief Retrieve ANP client profile interface + * @return ANP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* anpc_prf_itf_get(void); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void anpc_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_AN_CLIENT) + +/// @} ANPC + +#endif //(_ANPC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/src/anpc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/src/anpc_task.c new file mode 100644 index 0000000..f4131d1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anpc/src/anpc_task.c @@ -0,0 +1,903 @@ +/** + **************************************************************************************** + * + * @file anpc_task.c + * + * @brief Alert Notification Profile Profile Client Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup ANPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_AN_CLIENT) +#include "anp_common.h" + +#include "gap.h" +#include "anpc.h" +#include "anpc_task.h" +#include "gattm_task.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve Alert Notification service characteristics information +const struct prf_char_def anpc_ans_char[ANPC_CHAR_MAX] = +{ + // Supported New Alert Category + [ANPC_CHAR_SUP_NEW_ALERT_CAT] = {ATT_CHAR_SUP_NEW_ALERT_CAT, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, + // New Alert + [ANPC_CHAR_NEW_ALERT] = {ATT_CHAR_NEW_ALERT, + ATT_MANDATORY, + ATT_CHAR_PROP_NTF}, + // Supported Unread Alert Category + [ANPC_CHAR_SUP_UNREAD_ALERT_CAT] = {ATT_CHAR_SUP_UNREAD_ALERT_CAT, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, + // Unread Alert Status + [ANPC_CHAR_UNREAD_ALERT_STATUS] = {ATT_CHAR_UNREAD_ALERT_STATUS, + ATT_MANDATORY, + ATT_CHAR_PROP_NTF}, + // Alert Notification Control Point + [ANPC_CHAR_ALERT_NTF_CTNL_PT] = {ATT_CHAR_ALERT_NTF_CTNL_PT, + ATT_MANDATORY, + ATT_CHAR_PROP_WR}, +}; + +/// State machine used to retrieve Phone Alert Status service characteristic descriptor information +const struct prf_char_desc_def anpc_ans_char_desc[ANPC_DESC_MAX] = +{ + // New Alert Char. - Client Characteristic Configuration + [ANPC_DESC_NEW_ALERT_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + ANPC_CHAR_NEW_ALERT}, + // Unread Alert Status Char. - Client Characteristic Configuration + [ANPC_DESC_UNREAD_ALERT_STATUS_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + ANPC_CHAR_UNREAD_ALERT_STATUS}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANPC_ENABLE_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int anpc_enable_req_handler(ke_msg_id_t const msgid, + struct anpc_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Phone Alert Status Profile Client Role Task Environment + struct anpc_env_tag *p_anpc_env = PRF_ENV_GET(ANPC, anpc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if ((state == ANPC_IDLE) && (p_anpc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_anpc_env->p_env[conidx] = (struct anpc_cnx_env *) ke_malloc(sizeof(struct anpc_cnx_env), KE_MEM_ATT_DB); + memset(p_anpc_env->p_env[conidx], 0, sizeof(struct anpc_cnx_env)); + + p_anpc_env->p_env[conidx]->last_char_code = ANPC_ENABLE_OP_CODE; + + // Start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + prf_disc_svc_send(&(p_anpc_env->prf_env), conidx, ATT_SVC_ALERT_NTF); + + // Go to DISCOVERING state + ke_state_set(dest_id, ANPC_DISCOVERING); + + // Configure the environment for a discovery procedure + p_anpc_env->p_env[conidx]->last_uuid_req = ATT_SVC_ALERT_NTF; + } + // Bond information is provided + else + { + // Keep the provided database content + memcpy(&p_anpc_env->p_env[conidx]->ans, &p_param->ans, sizeof(struct anpc_ans_content)); + + //send APP confirmation that can start normal connection to TH + anpc_enable_rsp_send(p_anpc_env, conidx, GAP_ERR_NO_ERROR); + } + } + + else if (state != ANPC_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + anpc_enable_rsp_send(p_anpc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANPC_READ_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int anpc_read_cmd_handler(ke_msg_id_t const msgid, + struct anpc_read_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct anpc_env_tag *p_anpc_env = PRF_ENV_GET(ANPC, anpc); + + if (p_anpc_env->p_env[conidx] != NULL) + { + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + // Check the provided connection handle + do + { + // Check the current state + if (ke_state_get(dest_id) == ANPC_BUSY) + { + // Keep the request for later, status is GAP_ERR_NO_ERROR + msg_status = KE_MSG_SAVED; + break; + } + + switch (p_param->read_code) + { + // Read Supported New Alert + case (ANPC_RD_SUP_NEW_ALERT_CAT): + { + handle = p_anpc_env->p_env[conidx]->ans.chars[ANPC_CHAR_SUP_NEW_ALERT_CAT].val_hdl; + } break; + + // Read Supported Unread Alert + case (ANPC_RD_SUP_UNREAD_ALERT_CAT): + { + handle = p_anpc_env->p_env[conidx]->ans.chars[ANPC_CHAR_SUP_UNREAD_ALERT_CAT].val_hdl; + } break; + + // Read New Alert Characteristic Client Char. Cfg. Descriptor Value + case (ANPC_RD_WR_NEW_ALERT_CFG): + { + handle = p_anpc_env->p_env[conidx]->ans.descs[ANPC_DESC_NEW_ALERT_CL_CFG].desc_hdl; + } break; + + // Read Unread Alert Characteristic Client Char. Cfg. Descriptor Value + case (ANPC_RD_WR_UNREAD_ALERT_STATUS_CFG): + { + handle = p_anpc_env->p_env[conidx]->ans.descs[ANPC_DESC_UNREAD_ALERT_STATUS_CL_CFG].desc_hdl; + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + // Check if handle is viable + if ((handle != ATT_INVALID_SEARCH_HANDLE) && + (status == GAP_ERR_NO_ERROR)) + { + // Force the operation value + p_param->operation = ANPC_READ_OP_CODE; + + // Store the command structure + p_anpc_env->p_env[conidx]->p_operation = p_param; + msg_status = KE_MSG_NO_FREE; + + // Send the read request + prf_read_char_send(&(p_anpc_env->prf_env), conidx, + p_anpc_env->p_env[conidx]->ans.svc.shdl, + p_anpc_env->p_env[conidx]->ans.svc.ehdl, + handle); + + // Go to the Busy state + ke_state_set(dest_id, ANPC_BUSY); + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + }while(0); + + if (status != GAP_ERR_NO_ERROR) + { + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_READ_OP_CODE, status); + } + } + else + { + // No connection exists + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_READ_OP_CODE, PRF_ERR_REQ_DISALLOWED); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANPC_WRITE_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int anpc_write_cmd_handler(ke_msg_id_t const msgid, + struct anpc_write_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Get the address of the environment + struct anpc_env_tag *p_anpc_env = PRF_ENV_GET(ANPC, anpc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_anpc_env->p_env[conidx] != NULL) + { + do + { + // Attribute handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Length + uint8_t length; + + // Check the current state + if (ke_state_get(dest_id) != ANPC_IDLE) + { + msg_status = KE_MSG_SAVED; + break; + } + + switch (p_param->write_code) + { + // Write Alert Notification Control Point Characteristic Value + case (ANPC_WR_ALERT_NTF_CTNL_PT): + { + // Check the Category ID and the Command ID + if ((p_param->value.ctnl_pt.cmd_id < CMD_ID_NB) && + ((p_param->value.ctnl_pt.cat_id < CAT_ID_NB) || + (p_param->value.ctnl_pt.cat_id == CAT_ID_ALL_SUPPORTED_CAT))) + { + handle = p_anpc_env->p_env[conidx]->ans.chars[ANPC_CHAR_ALERT_NTF_CTNL_PT].val_hdl; + length = sizeof(struct anp_ctnl_pt); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write New Alert Characteristic Client Char. Cfg. Descriptor Value + case (ANPC_RD_WR_NEW_ALERT_CFG): + { + if (p_param->value.new_alert_ntf_cfg <= PRF_CLI_START_NTF) + { + handle = p_anpc_env->p_env[conidx]->ans.descs[ANPC_DESC_NEW_ALERT_CL_CFG].desc_hdl; + length = sizeof(uint16_t); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write Unread Alert Status Characteristic Client Char. Cfg. Descriptor Value + case (ANPC_RD_WR_UNREAD_ALERT_STATUS_CFG): + { + if (p_param->value.unread_alert_status_ntf_cfg <= PRF_CLI_START_NTF) + { + handle = p_anpc_env->p_env[conidx]->ans.descs[ANPC_DESC_UNREAD_ALERT_STATUS_CL_CFG].desc_hdl; + length = sizeof(uint16_t); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + if (status == GAP_ERR_NO_ERROR) + { + // Check if handle is viable + if (handle != ATT_INVALID_SEARCH_HANDLE) + { + // Send the write request + prf_gatt_write(&(p_anpc_env->prf_env), conidx, handle, + (uint8_t *)&p_param->value, length, GATTC_WRITE); + + // Force the operation value + p_param->operation = ANPC_WRITE_OP_CODE; + // Store the command structure + p_anpc_env->p_env[conidx]->p_operation = p_param; + + msg_status = KE_MSG_NO_FREE; + + // Go to the Busy state + ke_state_set(dest_id, ANPC_BUSY); + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + }while(0); + } + else + { + status = PRF_ERR_REQ_DISALLOWED; + } + + if (status != GAP_ERR_NO_ERROR) + { + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_WRITE_OP_CODE, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + do + { + // Get the address of the environment + struct anpc_env_tag *p_anpc_env = PRF_ENV_GET(ANPC, anpc); + uint8_t conidx = KE_IDX_GET(dest_id); + // Status + uint8_t status; + uint8_t state = ke_state_get(dest_id); + + if (p_anpc_env->p_env[conidx] == NULL) + { + break; + } + + if (state == ANPC_DISCOVERING) + { + status = p_param->status; + + if ((status == ATT_ERR_ATTRIBUTE_NOT_FOUND) || + (status == ATT_ERR_NO_ERROR)) + { + // Discovery + // check characteristic validity + if(p_anpc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(ANPC_CHAR_MAX, + p_anpc_env->p_env[conidx]->ans.chars, + anpc_ans_char); + } + // too much services + else if (p_anpc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(ANPC_DESC_MAX, + p_anpc_env->p_env[conidx]->ans.descs, + anpc_ans_char_desc, + p_anpc_env->p_env[conidx]->ans.chars); + } + } + + anpc_enable_rsp_send(p_anpc_env, conidx, status); + } + + else if (state == ANPC_BUSY) + { + switch (p_param->operation) + { + case GATTC_READ: + { + switch (((struct anpc_cmd *)p_anpc_env->p_env[conidx]->p_operation)->operation) + { + // Read Supported New Alert Category Characteristic value + case (ANPC_ENABLE_RD_NEW_ALERT_OP_CODE): + { + if (p_param->status == GAP_ERR_NO_ERROR) + { + // Force the operation value + ((struct anpc_cmd *)p_anpc_env->p_env[conidx]->p_operation)->operation = + ANPC_ENABLE_RD_UNREAD_ALERT_OP_CODE; + + // Check Supported Unread Alert Category + prf_read_char_send(&(p_anpc_env->prf_env), conidx, + p_anpc_env->p_env[conidx]->ans.svc.shdl, p_anpc_env->p_env[conidx]->ans.svc.ehdl, + p_anpc_env->p_env[conidx]->ans.chars[ANPC_CHAR_SUP_UNREAD_ALERT_CAT].val_hdl); + } + else + { + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_ENABLE_OP_CODE, p_param->status); + } + } break; + + case (ANPC_ENABLE_RD_UNREAD_ALERT_OP_CODE): + { + if (p_param->status == GAP_ERR_NO_ERROR) + { + // If peer device was unknown, stop the procedure + if (((struct anpc_enable_req *)p_anpc_env->p_env[conidx]->p_operation)->con_type == + PRF_CON_DISCOVERY) + { + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_ENABLE_OP_CODE, GAP_ERR_NO_ERROR); + } + // If peer device was already known (bonded), + // start Recovery from Connection Loss procedure + else + { + // Reset the environment + p_anpc_env->p_env[conidx]->last_uuid_req = CAT_ID_SPL_ALERT; + + if (anpc_found_next_alert_cat(p_anpc_env, conidx, + ((struct anpc_enable_req *)p_anpc_env->p_env[conidx]->p_operation)->new_alert_enable)) + { + // Force the operation value + ((struct anpc_cmd *)p_anpc_env->p_env[conidx]->p_operation)->operation = + ANPC_ENABLE_WR_NEW_ALERT_OP_CODE; + // Enable sending of notifications for the found category ID + anpc_write_alert_ntf_ctnl_pt(p_anpc_env, conidx, CMD_ID_EN_NEW_IN_ALERT_NTF, + p_anpc_env->p_env[conidx]->last_uuid_req - 1); + } + else + { + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_ENABLE_OP_CODE, GAP_ERR_NO_ERROR); + } + } + } + else + { + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_ENABLE_OP_CODE, p_param->status); + } + } break; + + case (ANPC_READ_OP_CODE): + { + // Inform the requester that the read procedure is over + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_READ_OP_CODE, p_param->status); + } break; + + default: + { + ASSERT_ERR(0); + } + } + } break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + // Retrieve the operation currently performed + uint8_t operation = ((struct anpc_cmd *)p_anpc_env->p_env[conidx]->p_operation)->operation; + + switch (operation) + { + case (ANPC_WRITE_OP_CODE): + { + uint8_t wr_code = ((struct anpc_write_cmd *) + p_anpc_env->p_env[conidx]->p_operation)->write_code; + + if ((wr_code == ANPC_RD_WR_NEW_ALERT_CFG) || + (wr_code == ANPC_RD_WR_UNREAD_ALERT_STATUS_CFG) || + (wr_code == ANPC_WR_ALERT_NTF_CTNL_PT)) + { + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_WRITE_OP_CODE, p_param->status); + } + else + { + ASSERT_ERR(0); + } + } break; + + case (ANPC_ENABLE_WR_NEW_ALERT_OP_CODE): + { + // Look for the next category to enable + if (anpc_found_next_alert_cat(p_anpc_env, conidx, + ((struct anpc_enable_req *)p_anpc_env->p_env[conidx]->p_operation)->new_alert_enable)) + { + // Enable sending of notifications for the found category ID + anpc_write_alert_ntf_ctnl_pt(p_anpc_env, conidx, CMD_ID_EN_NEW_IN_ALERT_NTF, + p_anpc_env->p_env[conidx]->last_uuid_req - 1); + } + else + { + // Force the operation value + ((struct anpc_cmd *)p_anpc_env->p_env[conidx]->p_operation)->operation = + ANPC_ENABLE_WR_NTF_NEW_ALERT_OP_CODE; + // Send a "Notify New Alert Immediately" command with the Category ID field set to 0xFF + anpc_write_alert_ntf_ctnl_pt(p_anpc_env, conidx, + CMD_ID_NTF_NEW_IN_ALERT_IMM, CAT_ID_ALL_SUPPORTED_CAT); + } + } break; + + case (ANPC_ENABLE_WR_NTF_NEW_ALERT_OP_CODE): + { + // Reset the environment + p_anpc_env->p_env[conidx]->last_uuid_req = CAT_ID_SPL_ALERT; + + if (anpc_found_next_alert_cat(p_anpc_env, conidx, + ((struct anpc_enable_req *)p_anpc_env->p_env[conidx]->p_operation)->unread_alert_enable)) + { + // Force the operation value + ((struct anpc_cmd *)p_anpc_env->p_env[conidx]->p_operation)->operation = + ANPC_ENABLE_WR_UNREAD_ALERT_OP_CODE; + // Enable sending of notifications for the found category ID + anpc_write_alert_ntf_ctnl_pt(p_anpc_env, conidx, CMD_ID_EN_UNREAD_CAT_STATUS_NTF, + p_anpc_env->p_env[conidx]->last_uuid_req - 1); + } + else + { + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_ENABLE_OP_CODE, GAP_ERR_NO_ERROR); + } + } break; + + case (ANPC_ENABLE_WR_UNREAD_ALERT_OP_CODE): + { + // Look for the next category to enable + if (anpc_found_next_alert_cat(p_anpc_env, conidx, + ((struct anpc_enable_req *)p_anpc_env->p_env[conidx]->p_operation)->unread_alert_enable)) + { + // Enable sending of notifications for the found category ID + anpc_write_alert_ntf_ctnl_pt(p_anpc_env, conidx, + CMD_ID_EN_UNREAD_CAT_STATUS_NTF, p_anpc_env->p_env[conidx]->last_uuid_req - 1); + } + else + { + // Force the operation value + ((struct anpc_cmd *)p_anpc_env->p_env[conidx]->p_operation)->operation = + ANPC_ENABLE_WR_NTF_UNREAD_ALERT_OP_CODE; + // Send a "Notify New Alert Immediately" command with the Category ID field set to 0xFF + anpc_write_alert_ntf_ctnl_pt(p_anpc_env, conidx, + CMD_ID_NTF_UNREAD_CAT_STATUS_IMM, CAT_ID_ALL_SUPPORTED_CAT); + } + } break; + + case (ANPC_ENABLE_WR_NTF_UNREAD_ALERT_OP_CODE): + { + // The discovery procedure is over + anpc_send_cmp_evt(p_anpc_env, conidx, ANPC_ENABLE_OP_CODE, p_param->status); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } break; + + case GATTC_REGISTER: + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + } while (0); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id)== ANPC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct anpc_env_tag *p_anpc_env = PRF_ENV_GET(ANPC, anpc); + + ASSERT_INFO(p_anpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_anpc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_anpc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve ANS characteristics and descriptors + prf_extract_svc_info(p_ind, ANPC_CHAR_MAX, &anpc_ans_char[0], &p_anpc_env->p_env[conidx]->ans.chars[0], + ANPC_DESC_MAX, &anpc_ans_char_desc[0], &p_anpc_env->p_env[conidx]->ans.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_anpc_env->p_env[conidx]->ans.svc.shdl = p_ind->start_hdl; + p_anpc_env->p_env[conidx]->ans.svc.ehdl = p_ind->end_hdl; + } + + p_anpc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct anpc_env_tag *p_anpc_env = PRF_ENV_GET(ANPC, anpc); + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_anpc_env->p_env[conidx] != NULL) + { + ASSERT_ERR(ke_state_get(dest_id) == ANPC_BUSY); + + // Prepare the indication to send to the application + struct anpc_value_ind *p_ind = KE_MSG_ALLOC(ANPC_VALUE_IND, + prf_dst_task_get(&(p_anpc_env->prf_env), conidx), + dest_id, + anpc_value_ind); + + switch (((struct anpc_cmd *)p_anpc_env->p_env[conidx]->p_operation)->operation) + { + // Read Supported New Alert Category Characteristic value + case (ANPC_ENABLE_RD_NEW_ALERT_OP_CODE): + { + p_ind->att_code = ANPC_RD_SUP_NEW_ALERT_CAT; + p_ind->value.supp_cat.cat_id_mask_0 = p_param->value[0]; + // If cat_id_mask_1 not present, shall be considered as 0 + p_ind->value.supp_cat.cat_id_mask_1 = (p_param->length > 1) + ? p_param->value[1] : 0x00; + } break; + + case (ANPC_ENABLE_RD_UNREAD_ALERT_OP_CODE): + { + p_ind->att_code = ANPC_RD_SUP_UNREAD_ALERT_CAT; + p_ind->value.supp_cat.cat_id_mask_0 = p_param->value[0]; + // If cat_id_mask_1 not present, shall be considered as 0 + p_ind->value.supp_cat.cat_id_mask_1 = (p_param->length > 1) + ? p_param->value[1] : 0; + } break; + + case (ANPC_READ_OP_CODE): + { + p_ind->att_code = ((struct anpc_read_cmd *)p_anpc_env->p_env[conidx]->p_operation)->read_code; + p_ind->value.ntf_cfg = co_read16p(&p_param->value[0]); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + // Send the indication + ke_msg_send(p_ind); + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + do + { + // Get the address of the environment + struct anpc_env_tag *p_anpc_env = PRF_ENV_GET(ANPC, anpc); + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_anpc_env->p_env[conidx] == NULL) + { + break; + } + + // Check the category ID + if (p_param->value[0] >= CAT_ID_NB) + { + break; + } + + // New Alert Characteristic Value + if (p_param->handle == p_anpc_env->p_env[conidx]->ans.chars[ANPC_CHAR_NEW_ALERT].val_hdl) + { + // Text String information Length + uint8_t length = p_param->length - 2; + + if (length > ANS_NEW_ALERT_STRING_INFO_MAX_LEN) + { + length = ANS_NEW_ALERT_STRING_INFO_MAX_LEN; + } + + // Send an indication to the application + struct anpc_value_ind *p_new_alert_ind = KE_MSG_ALLOC_DYN(ANPC_VALUE_IND, + prf_dst_task_get(&p_anpc_env->prf_env, conidx), + prf_src_task_get(&p_anpc_env->prf_env, conidx), + anpc_value_ind, + length); + + p_new_alert_ind->att_code = ANPC_NTF_NEW_ALERT; + + // Fulfill the characteristic value + p_new_alert_ind->value.new_alert.cat_id = p_param->value[0]; + p_new_alert_ind->value.new_alert.nb_new_alert = p_param->value[1]; + p_new_alert_ind->value.new_alert.info_str_len = length; + memcpy(&p_new_alert_ind->value.new_alert.str_info[0], &p_param->value[2], length); + + // Send the message + ke_msg_send(p_new_alert_ind); + } + // Unread Alert Status Characteristic Value + else if (p_param->handle == p_anpc_env->p_env[conidx]->ans.chars[ANPC_CHAR_UNREAD_ALERT_STATUS].val_hdl) + { + // Send an indication to the application + struct anpc_value_ind *p_unrd_alert_ind = KE_MSG_ALLOC(ANPC_VALUE_IND, + prf_dst_task_get(&p_anpc_env->prf_env, conidx), + prf_src_task_get(&p_anpc_env->prf_env, conidx), + anpc_value_ind); + + p_unrd_alert_ind->att_code = ANPC_NTF_UNREAD_ALERT; + + // Fulfill the characteristic value + p_unrd_alert_ind->value.unread_alert.cat_id = p_param->value[0]; + p_unrd_alert_ind->value.unread_alert.nb_unread_alert = p_param->value[1]; + + // Send the message + ke_msg_send(p_unrd_alert_ind); + } + else + { + ASSERT_ERR(0); + } + + } while (0); + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(anpc) +{ + {ANPC_ENABLE_REQ, (ke_msg_func_t)anpc_enable_req_handler}, + {ANPC_READ_CMD, (ke_msg_func_t)anpc_read_cmd_handler}, + {ANPC_WRITE_CMD, (ke_msg_func_t)anpc_write_cmd_handler}, + + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void anpc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct anpc_env_tag *p_anpc_env = PRF_ENV_GET(ANPC, anpc); + + p_task_desc->msg_handler_tab = anpc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(anpc_msg_handler_tab); + p_task_desc->state = p_anpc_env->state; + p_task_desc->idx_max = ANPC_IDX_MAX; +} + + +#endif //(BLE_AN_CLIENT) + +/// @} ANPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/api/anps_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/api/anps_task.h new file mode 100644 index 0000000..7604fa7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/api/anps_task.h @@ -0,0 +1,149 @@ +/** + **************************************************************************************** + * + * @file anps_task.h + * + * @brief Header file - ANPSTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev: $ + * + **************************************************************************************** + */ + +#ifndef ANPS_TASK_H_ +#define ANPS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup ANPSTASK Task + * @ingroup ANPS + * @brief Alert Notification Profile Server Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include "rwip_task.h" // Task definitions +#include "anp_common.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Messages for Alert Notification Profile Server +/*@TRACE*/ +enum anps_msg_ids +{ + /// Start the Alert Notification Profile Server Role + ANPS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_ANPS), + /// Start the Alert Notification Profile Server Role + ANPS_ENABLE_RSP, + + /// Update the value of a characteristic + ANPS_NTF_ALERT_CMD, + /// The peer device requests to be notified about new alert values + ANPS_NTF_IMMEDIATE_REQ_IND, + /// Indicate that the notification configuration has been modified by the peer device + ANPS_NTF_STATUS_UPDATE_IND, + + /// Complete Event Information + ANPS_CMP_EVT, +}; + +/// Operation Codes +enum anps_op_codes +{ + ANPS_RESERVED_OP_CODE = 0x00, + + /// Update New Alert Char. value + ANPS_UPD_NEW_ALERT_OP_CODE, + /// Update Unread Alert Status Char. value + ANPS_UPD_UNREAD_ALERT_STATUS_OP_CODE, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the @ref ANPS_CREATE_DB_REQ message +struct anps_db_cfg +{ + /// Supported New Alert Category Characteristic Value - Shall not be 0 + struct anp_cat_id_bit_mask supp_new_alert_cat; + /// Supported Unread Alert Category Characteristic Value - Can be 0 + struct anp_cat_id_bit_mask supp_unread_alert_cat; +}; + +/// Parameters of the @ref ANPS_ENABLE_REQ message +struct anps_enable_req +{ + /// New Alert Characteristic - Saved Client Characteristic Configuration Descriptor Value + uint16_t new_alert_ntf_cfg; + /// Unread Alert Status Characteristic - Saved Client Characteristic Configuration Descriptor Value + uint16_t unread_alert_status_ntf_cfg; +}; + +/// Parameters of the @ref ANPS_ENABLE_RSP message +struct anps_enable_rsp +{ + /// status + uint8_t status; +}; + +///Parameters of the @ref ANPS_NTF_ALERT_CMD message +struct anps_ntf_alert_cmd +{ + /// Operation Code (ANPS_UPD_NEW_ALERT_OP_CODE or ANPS_UPD_UNREAD_ALERT_STATUS_OP_CODE) + uint8_t operation; + /// New Alert Characteristic Value or Unread Alert Status Characteristic Value + union anps_value_tag + { + /// New Alert + struct anp_new_alert new_alert; + /// Unread Alert Status + struct anp_unread_alert unread_alert_status; + } value; +}; + +///Parameters of the @ref ANPS_NTF_IMMEDIATE_REQ_IND message +struct anps_ntf_immediate_req_ind +{ + /// Alert type (New Alert or Unread Alert Status) + uint8_t alert_type; + /// Status for each category + struct anp_cat_id_bit_mask cat_ntf_cfg; +}; + +///Parameters of the @ref ANPS_NTF_STATUS_UPDATE_IND message +struct anps_ntf_status_update_ind +{ + /// Alert type (New Alert or Unread Alert Status) + uint8_t alert_type; + /// Client Characteristic Configuration Descriptor Status + uint16_t ntf_ccc_cfg; + /// Status for each category + struct anp_cat_id_bit_mask cat_ntf_cfg; +}; + +///Parameters of the @ref ANPS_CMP_EVT message +struct anps_cmp_evt +{ + /// Operation + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} ANPSTASK + +#endif //(ANPS_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/sourcelist.txt new file mode 100644 index 0000000..2bc43a9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + anps.c + anps_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/src/anps.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/src/anps.c new file mode 100644 index 0000000..22f05dd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/src/anps.c @@ -0,0 +1,354 @@ +/** + **************************************************************************************** + * + * @file anps.c + * + * @brief Alert Notification Profile Server implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev: $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup ANPS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_AN_SERVER) + +#include "anps.h" +#include "anps_task.h" +#include "anp_common.h" +#include "prf_utils.h" +#include "prf_types.h" + +#include "ke_mem.h" + +/* + * ANS DATABASE + **************************************************************************************** + */ + +/// Full ANS Database Description - Used to add attributes into the database +const struct attm_desc anps_att_db[ANS_IDX_NB] = +{ + // Alert Notification Service Declaration + [ANS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Supported New Alert Category Characteristic Declaration + [ANS_IDX_SUPP_NEW_ALERT_CAT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Supported New Alert Category Characteristic Value + [ANS_IDX_SUPP_NEW_ALERT_CAT_VAL] = + {ATT_CHAR_SUP_NEW_ALERT_CAT, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(struct anp_cat_id_bit_mask)}, + + // New Alert Characteristic Declaration + [ANS_IDX_NEW_ALERT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // New Alert Characteristic Value + [ANS_IDX_NEW_ALERT_VAL] = {ATT_CHAR_NEW_ALERT, PERM(NTF, ENABLE), PERM(RI, ENABLE), ANS_NEW_ALERT_MAX_LEN}, + // New Alert Characteristic - Client Char. Configuration Descriptor + [ANS_IDX_NEW_ALERT_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Supported Unread Alert Category Characteristic Declaration + [ANS_IDX_SUPP_UNREAD_ALERT_CAT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Supported New Alert Category Characteristic Value + [ANS_IDX_SUPP_UNREAD_ALERT_CAT_VAL] = + {ATT_CHAR_SUP_UNREAD_ALERT_CAT, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(struct anp_cat_id_bit_mask)}, + + // Unread Alert Status Characteristic Declaration + [ANS_IDX_UNREAD_ALERT_STATUS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Unread Alert Status Characteristic Value + [ANS_IDX_UNREAD_ALERT_STATUS_VAL] = + {ATT_CHAR_UNREAD_ALERT_STATUS, PERM(NTF, ENABLE), PERM(RI, ENABLE), sizeof(struct anp_unread_alert)}, + // Unread Alert Status Characteristic - Client Char. Configuration Descriptor + [ANS_IDX_UNREAD_ALERT_STATUS_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Alert Notification Control Point Characteristic Declaration + [ANS_IDX_ALERT_NTF_CTNL_PT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Alert Notification Control Point Characteristic Value + [ANS_IDX_ALERT_NTF_CTNL_PT_VAL] = + {ATT_CHAR_ALERT_NTF_CTNL_PT, PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 2*sizeof(uint8_t)}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the ANPS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t anps_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct anps_db_cfg *p_params) +{ + //------------------ create the attribute database for the profile ------------------- + // Service content flag + uint32_t cfg_flag = ANPS_DB_CONFIG_MASK; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + // Add service in the database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_ALERT_NTF, (uint8_t *)&cfg_flag, + ANS_IDX_NB, NULL, p_env->task, &anps_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, ENABLE)); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + // Allocate ANPS required environment variable + struct anps_env_tag *p_anps_env = + (struct anps_env_tag* ) ke_malloc(sizeof(struct anps_env_tag), KE_MEM_ATT_DB); + + // Initialize ANPS environment + p_env->env = (prf_env_t*) p_anps_env; + p_anps_env->shdl = *p_start_hdl; + + memcpy(&p_anps_env->supp_new_alert_cat, &p_params->supp_new_alert_cat, sizeof(struct anp_cat_id_bit_mask)); + memcpy(&p_anps_env->supp_unread_alert_cat, &p_params->supp_unread_alert_cat, sizeof(struct anp_cat_id_bit_mask)); + + p_anps_env->operation = ANPS_RESERVED_OP_CODE; + + p_anps_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Multi Instantiated task + p_anps_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_ANPS; + anps_task_init(&(p_env->desc)); + + for (uint8_t idx = 0; idx < BLE_CONNECTION_MAX ; idx++) + { + p_anps_env->p_env[idx] = NULL; + // Put ANS in disabled state + ke_state_set(KE_BUILD_ID(p_env->task, idx), ANPS_FREE); + } + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the ANPS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void anps_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct anps_env_tag *p_anps_env = (struct anps_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < BLE_CONNECTION_MAX ; idx++) + { + if (p_anps_env->p_env[idx] != NULL) + { + ke_free(p_anps_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_anps_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void anps_create(struct prf_task_env* p_env, uint8_t conidx) +{ + struct anps_env_tag *p_anps_env = (struct anps_env_tag *) p_env->env; + + p_anps_env->p_env[conidx] = (struct anps_cnx_env *) + ke_malloc(sizeof(struct anps_cnx_env), KE_MEM_ATT_DB); + + memset(p_anps_env->p_env[conidx], 0, sizeof(struct anps_cnx_env)); + // Put ANS in idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), ANPS_IDLE); + +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void anps_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct anps_env_tag *p_anps_env = (struct anps_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_anps_env->p_env[conidx] != NULL) + { + ke_free(p_anps_env->p_env[conidx]); + p_anps_env->p_env[conidx] = NULL; + } + + // Put ANS in disabled state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), ANPS_FREE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// ANPS Task interface required by profile manager +const struct prf_task_cbs anps_itf = +{ + (prf_init_fnct) anps_init, + anps_destroy, + anps_create, + anps_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* anps_prf_itf_get(void) +{ + return &anps_itf; +} + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +void anps_send_cmp_evt(ke_task_id_t src_id, ke_task_id_t dest_id, + uint8_t operation, uint8_t status) +{ + struct anps_cmp_evt *p_evt; + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == ANPS_BUSY) + { + ke_state_set(src_id, ANPS_IDLE); + } + + // Send the message to the application + p_evt = KE_MSG_ALLOC(ANPS_CMP_EVT, dest_id, src_id, anps_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +void anps_send_ntf_status_update_ind(uint8_t conidx, struct anps_env_tag *p_anps_env, uint8_t alert_type) +{ + // Send the message to the application + struct anps_ntf_status_update_ind *p_ind = KE_MSG_ALLOC(ANPS_NTF_STATUS_UPDATE_IND, + prf_dst_task_get(&p_anps_env->prf_env, conidx), + prf_src_task_get(&p_anps_env->prf_env, conidx), + anps_ntf_status_update_ind); + + p_ind->alert_type = alert_type; + p_ind->ntf_ccc_cfg = ANPS_IS_ALERT_ENABLED(conidx, p_anps_env, alert_type) ? + PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND; + + if (alert_type == ANP_NEW_ALERT) + { + p_ind->cat_ntf_cfg.cat_id_mask_0 = (uint8_t)(p_anps_env->p_env[conidx]->ntf_new_alert_cfg & 0x00FF); + p_ind->cat_ntf_cfg.cat_id_mask_1 = (uint8_t)((p_anps_env->p_env[conidx]->ntf_new_alert_cfg & 0xFF00) >> 8); + } + else + { + p_ind->cat_ntf_cfg.cat_id_mask_0 = (uint8_t)(p_anps_env->p_env[conidx]->ntf_unread_alert_cfg & 0x00FF); + p_ind->cat_ntf_cfg.cat_id_mask_1 = (uint8_t)(p_anps_env->p_env[conidx]->ntf_unread_alert_cfg >> 8); + } + + ke_msg_send(p_ind); +} + +void anps_send_ntf_immediate_req_ind(uint8_t conidx, struct anps_env_tag *p_anps_env, uint8_t alert_type, + uint8_t category_id) +{ + uint16_t req_cat; + + // Send the message to the application + struct anps_ntf_immediate_req_ind *p_ind = KE_MSG_ALLOC(ANPS_NTF_IMMEDIATE_REQ_IND, + prf_dst_task_get(&p_anps_env->prf_env, conidx), + prf_src_task_get(&p_anps_env->prf_env, conidx), + anps_ntf_immediate_req_ind); + + p_ind->alert_type = alert_type; + + if (alert_type == ANP_NEW_ALERT) + { + if (category_id == CAT_ID_ALL_SUPPORTED_CAT) + { + // All category that are supported and enabled shall be notified + req_cat = p_anps_env->p_env[conidx]->ntf_new_alert_cfg; + } + else + { + req_cat = (1 << category_id); + } + } + // Unread alert + else + { + if (category_id == CAT_ID_ALL_SUPPORTED_CAT) + { + // All category that are supported and enabled shall be notified + req_cat = p_anps_env->p_env[conidx]->ntf_unread_alert_cfg; + } + else + { + req_cat = (1 << category_id); + } + } + + p_ind->cat_ntf_cfg.cat_id_mask_0 = (uint8_t)(req_cat & 0x00FF); + p_ind->cat_ntf_cfg.cat_id_mask_1 = (uint8_t)((req_cat & 0xFF00) >> 8); + + ke_msg_send(p_ind); +} + +#endif //(BLE_AN_SERVER) + +/// @} ANPS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/src/anps.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/src/anps.h new file mode 100644 index 0000000..5ebb3fa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/src/anps.h @@ -0,0 +1,254 @@ +/** + **************************************************************************************** + * + * @file anps.h + * + * @brief Header file - Alert Notification Profile Server. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $Rev: $ + * + **************************************************************************************** + */ + +#ifndef ANPS_H_ +#define ANPS_H_ + +/** + **************************************************************************************** + * @addtogroup ANPS Alert Notification Profile Server + * @ingroup ANP + * @brief Alert Notification Profile Server + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "anp_common.h" + +#if (BLE_AN_SERVER) + +#include "prf_types.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximal number of Alert Notification Server task instances +#define ANPS_IDX_MAX (BLE_CONNECTION_MAX) +/// Database Configuration Flag +#define ANPS_DB_CONFIG_MASK (0x1FFF) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the ANPS task +enum anps_states +{ + /// Not connected state + ANPS_FREE, + /// Idle state + ANPS_IDLE, + /// Busy state + ANPS_BUSY, + + /// Number of defined states. + ANPS_STATE_MAX +}; +/// Alert Notification Service Attributes +enum anps_ans_att_list +{ + ANS_IDX_SVC, + + ANS_IDX_SUPP_NEW_ALERT_CAT_CHAR, + ANS_IDX_SUPP_NEW_ALERT_CAT_VAL, + + ANS_IDX_NEW_ALERT_CHAR, + ANS_IDX_NEW_ALERT_VAL, + ANS_IDX_NEW_ALERT_CFG, + + ANS_IDX_SUPP_UNREAD_ALERT_CAT_CHAR, + ANS_IDX_SUPP_UNREAD_ALERT_CAT_VAL, + + ANS_IDX_UNREAD_ALERT_STATUS_CHAR, + ANS_IDX_UNREAD_ALERT_STATUS_VAL, + ANS_IDX_UNREAD_ALERT_STATUS_CFG, + + ANS_IDX_ALERT_NTF_CTNL_PT_CHAR, + ANS_IDX_ALERT_NTF_CTNL_PT_VAL, + + ANS_IDX_NB, +}; + + +/* + * MACROS + * ************************************************************************************** + */ + +#define ANPS_IS_NEW_ALERT_CATEGORY_SUPPORTED(category_id) \ + (((p_anps_env->supp_new_alert_cat >> category_id) & 1) == 1) + +#define ANPS_IS_UNREAD_ALERT_CATEGORY_SUPPORTED(category_id) \ + (((p_anps_env->supp_unread_alert_cat >> category_id) & 1) == 1) + +#define ANPS_IS_ALERT_ENABLED(conidx, idx_env, alert_type) \ + (((idx_env->p_env[conidx]->ntf_cfg >> alert_type) & 1) == 1) + +#define ANPS_IS_NEW_ALERT_CATEGORY_ENABLED(conidx, category_id, idx_env) \ + (((idx_env->p_env[conidx]->ntf_new_alert_cfg >> category_id) & 1) == 1) + +#define ANPS_IS_UNREAD_ALERT_CATEGORY_ENABLED(conidx, category_id, idx_env) \ + (((idx_env->p_env[conidx]->ntf_unread_alert_cfg >> category_id) & 1) == 1) + +#define ANPS_ENABLE_ALERT(conidx, idx_env, alert_type) \ + (idx_env->p_env[conidx]->ntf_cfg |= (1 << alert_type)) + +#define ANPS_DISABLE_ALERT(conidx, idx_env, alert_type) \ + (idx_env->p_env[conidx]->ntf_cfg &= ~(1 << alert_type)) + +#define ANPS_ENABLE_NEW_ALERT_CATEGORY(conidx, category_id, idx_env) \ + (idx_env->p_env[conidx]->ntf_new_alert_cfg |= (1 << category_id)) + +#define ANPS_ENABLE_UNREAD_ALERT_CATEGORY(conidx, category_id, idx_env) \ + (idx_env->p_env[conidx]->ntf_unread_alert_cfg |= (1 << category_id)) + +#define ANPS_DISABLE_NEW_ALERT_CATEGORY(conidx, category_id, idx_env) \ + (idx_env->p_env[conidx]->ntf_new_alert_cfg &= ~(1 << category_id)) + +#define ANPS_DISABLE_UNREAD_ALERT_CATEGORY(conidx, category_id, idx_env) \ + (idx_env->p_env[conidx]->ntf_unread_alert_cfg &= ~(1 << category_id)) + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Alert Notification Profile Server Connection Dependent Environment Variable +struct anps_cnx_env +{ + /** + * Client Characteristic Configuration Status + * Bit 0 : New Alert Characteristic + * Bit 1 : Unread Alert Status Characteristic + */ + uint8_t ntf_cfg; + + /** + * Category Notification Configuration + * Bit 0 : Simple Alert + * Bit 1 : Email + * Bit 2 : News + * Bit 3 : Call + * Bit 4 : Missed Call + * Bit 5 : SMS/MMS + * Bit 6 : Voice Mail + * Bit 7 : Schedule + * Bit 8 : High Prioritized Alert + * Bit 9 : Instance Message + */ + uint16_t ntf_new_alert_cfg; + uint16_t ntf_unread_alert_cfg; +}; + +/// Alert Notification Profile Server. Environment variable +struct anps_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// ANS Start Handle + uint16_t shdl; + /// Environment variable pointer for each connection + struct anps_cnx_env *p_env[BLE_CONNECTION_MAX]; + + /// Current Operation Code + uint8_t operation; + /// Supported New Alert Category Characteristic Value + uint16_t supp_new_alert_cat; + /// Supported Unread Alert Category Characteristic Value + uint16_t supp_unread_alert_cat; + + /// State of different task instances + ke_state_t state[ANPS_IDX_MAX]; + +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve ANP service profile interface + * + * @return ANP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *anps_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send an ANPS_NTF_STATUS_UPDATE_IND message to a requester. + * + * @param[in] conidx Connection index + * @param[in] p_anps_env Environment variable + * @param[in] alert_type Alert type @see enum anp_alert_codes + **************************************************************************************** + */ +void anps_send_ntf_status_update_ind(uint8_t conidx, struct anps_env_tag *p_anps_env, uint8_t alert_type); + +/** + **************************************************************************************** + * @brief Send an ANPS_NTF_IMMEDIATE_REQ_IND message to a requester. + * + * @param[in] conidx Connection index + * @param[in] p_anps_env Environment variable + * @param[in] alert_type Alert type @see enum anp_alert_codes + * @param[in] category_id Category Index @see enum anp_category_id + **************************************************************************************** + */ +void anps_send_ntf_immediate_req_ind(uint8_t conidx, struct anps_env_tag *p_anps_env, uint8_t alert_type, + uint8_t category_id); + +/** + **************************************************************************************** + * @brief Send an ANPS_CMP_EVT message to a requester. + * + * @param[in] src_id Source ID of the message (instance of TASK_ANPS) + * @param[in] dest_id Destination ID of the message + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void anps_send_cmp_evt(ke_task_id_t src_id, ke_task_id_t dest_id, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void anps_task_init(struct ke_task_desc *p_task_desc); + + +#endif //(BLE_AN_SERVER) + +/// @} ANPS + +#endif //(ANPS_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/src/anps_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/src/anps_task.c new file mode 100644 index 0000000..2ca5bee --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/anp/anps/src/anps_task.c @@ -0,0 +1,676 @@ +/** + **************************************************************************************** + * + * @file anps_task.c + * + * @brief Alert Notification Profile Server Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev: $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup ANPSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_AN_SERVER) + +#include "gapm.h" +#include "gattc_task.h" +#include "anps.h" +#include "anps_task.h" + +#include "prf_utils.h" +#include "prf_types.h" + +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANPS_ENABLE_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int anps_enable_req_handler(ke_msg_id_t const msgid, + struct anps_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct anps_enable_rsp *p_cmp_evt; + + do + { + // Alert Notification Profile Server Role Task Index Environment + struct anps_env_tag *p_anps_env = PRF_ENV_GET(ANPS, anps); + uint8_t conidx = KE_IDX_GET(src_id); + + if (ke_state_get(dest_id) != ANPS_IDLE) + { + break; + } + + if (p_anps_env->p_env[conidx] == NULL) + { + break; + } + + // Bonded data was not used before + if (!ANPS_IS_ALERT_ENABLED(conidx, p_anps_env, ANPS_FLAG_CFG_PERFORMED_OK)) + { + status = GAP_ERR_NO_ERROR; + // Update the state in the environment + if (p_param->new_alert_ntf_cfg != PRF_CLI_STOP_NTFIND) + { + // Force to PRF_CLI_START_NTF + p_param->new_alert_ntf_cfg = PRF_CLI_START_NTF; + + ANPS_ENABLE_ALERT(conidx, p_anps_env, ANP_NEW_ALERT); + } + + if (p_param->unread_alert_status_ntf_cfg != PRF_CLI_STOP_NTFIND) + { + // Force to PRF_CLI_START_NTF + p_param->unread_alert_status_ntf_cfg = PRF_CLI_START_NTF; + + ANPS_ENABLE_ALERT(conidx, p_anps_env, ANP_UNREAD_ALERT); + } + } + // Enable Bonded Data + ANPS_ENABLE_ALERT(conidx, p_anps_env, ANPS_FLAG_CFG_PERFORMED_OK); + } while (0); + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(ANPS_ENABLE_RSP, src_id, dest_id, anps_enable_rsp); + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref ANPS_NTF_ALERT_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int anps_ntf_alert_cmd_handler(ke_msg_id_t const msgid, + struct anps_ntf_alert_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = PRF_ERR_INVALID_PARAM; + // Message Status + int msg_status = KE_MSG_CONSUMED; + // Task environment + struct anps_env_tag *p_anps_env = PRF_ENV_GET(ANPS, anps); + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == ANPS_IDLE) + { + // Category ID + uint8_t cat_id; + // Is the category supported ? + bool cat_supported; + // Handle + uint16_t handle = ATT_ERR_INVALID_HANDLE; + + ASSERT_ERR(p_anps_env != NULL); + ASSERT_ERR(p_anps_env->p_env[conidx] != NULL); + + do + { + // Check the operation code, get the category ID. + if (p_param->operation == ANPS_UPD_NEW_ALERT_OP_CODE) + { + // Check the length of the string info value + if (p_param->value.new_alert.info_str_len > ANS_NEW_ALERT_STRING_INFO_MAX_LEN) + { + status = PRF_ERR_INVALID_PARAM; + break; + } + + // Get the category ID + cat_id = p_param->value.new_alert.cat_id; + // Check if the category is supported + cat_supported = ANPS_IS_NEW_ALERT_CATEGORY_SUPPORTED(cat_id); + } + else if (p_param->operation == ANPS_UPD_UNREAD_ALERT_STATUS_OP_CODE) + { + // Get the category ID + cat_id = p_param->value.unread_alert_status.cat_id; + // Check if the category is supported + cat_supported = ANPS_IS_UNREAD_ALERT_CATEGORY_SUPPORTED(cat_id); + } + else + { + status = PRF_ERR_INVALID_PARAM; + break; + } + + // Check the category ID + if ((cat_id >= CAT_ID_NB) || (!cat_supported)) + { + status = PRF_ERR_INVALID_PARAM; + break; + } + + if (p_param->operation == ANPS_UPD_NEW_ALERT_OP_CODE) + { + // Check if sending of notification is enabled for the provided category + if (ANPS_IS_NEW_ALERT_CATEGORY_ENABLED(conidx, cat_id, p_anps_env) && + ANPS_IS_ALERT_ENABLED(conidx, p_anps_env, ANP_NEW_ALERT)) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ntf = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), dest_id, + gattc_send_evt_cmd, 2 + p_param->value.new_alert.info_str_len); + + handle = p_anps_env->shdl + ANS_IDX_NEW_ALERT_VAL; + // Fill in the p_parameter structure + p_ntf->operation = GATTC_NOTIFY; + p_ntf->handle = handle; + // pack measured value in database + p_ntf->length = 2 + p_param->value.new_alert.info_str_len; + // Fill data + memcpy(&p_ntf->value, &p_param->value.new_alert.cat_id, p_ntf->length); + + // The notification can be sent, send the notification + status = GAP_ERR_NO_ERROR; + ke_msg_send(p_ntf); + } + else + { + status = PRF_ERR_NTF_DISABLED; + break; + } + } + else + { + if (ANPS_IS_UNREAD_ALERT_CATEGORY_ENABLED(conidx, cat_id, p_anps_env) && + ANPS_IS_ALERT_ENABLED(conidx, p_anps_env, ANP_UNREAD_ALERT)) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ntf = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), dest_id, + gattc_send_evt_cmd, sizeof(struct anp_unread_alert)); + + handle = p_anps_env->shdl + ANS_IDX_UNREAD_ALERT_STATUS_VAL; + // Fill in the p_parameter structure + p_ntf->operation = GATTC_NOTIFY; + p_ntf->handle = handle; + // pack measured value in database + p_ntf->length = sizeof(struct anp_unread_alert); + // Fill data + memcpy(&p_ntf->value, &p_param->value.unread_alert_status, p_ntf->length); + + // The notification can be sent, send the notification + status = GAP_ERR_NO_ERROR; + ke_msg_send(p_ntf); + } + else + { + status = PRF_ERR_NTF_DISABLED; + break; + } + } + + // Configure the environment + p_anps_env->operation = p_param->operation; + // Go to Busy state + ke_state_set(dest_id, ANPS_BUSY); + } while(0); + } + else if (state == ANPS_BUSY) + { + // Save it for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + // no connection + else + { + status = GAP_ERR_DISCONNECTED; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send the message to the application + anps_send_cmp_evt(dest_id, src_id, p_param->operation, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT message meaning that a notification or an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct anps_env_tag *p_anps_env = PRF_ENV_GET(ANPS, anps); + + if (p_anps_env != NULL) + { + uint8_t conidx = KE_IDX_GET(src_id); + + // Send a complete event status to the application + anps_send_cmp_evt(prf_src_task_get(&p_anps_env->prf_env, conidx), + prf_dst_task_get(&p_anps_env->prf_env, conidx), + p_anps_env->operation, p_param->status); + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == ANPS_IDLE) + { + // Get the address of the environment + struct anps_env_tag *p_anps_env = PRF_ENV_GET(ANPS, anps); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t value[2]; + uint8_t value_size = 0; + uint8_t status = ATT_ERR_NO_ERROR; + struct gattc_read_cfm *p_cfm; + + switch(p_param->handle - p_anps_env->shdl) + { + case ANS_IDX_SUPP_NEW_ALERT_CAT_VAL: + { + // Fill data + value_size = sizeof(uint16_t); + co_write16p(value, p_anps_env->supp_new_alert_cat); + } break; + + case ANS_IDX_NEW_ALERT_CFG: + { + // Fill data + value_size = sizeof(uint16_t); + co_write16p(value, ANPS_IS_ALERT_ENABLED(conidx, p_anps_env, ANP_NEW_ALERT)); + } break; + + case ANS_IDX_SUPP_UNREAD_ALERT_CAT_VAL: + { + // Fill data + value_size = sizeof(uint16_t); + co_write16p(value, p_anps_env->supp_unread_alert_cat); + } break; + + case ANS_IDX_UNREAD_ALERT_STATUS_CFG: + { + // Fill data + value_size = sizeof(uint16_t); + co_write16p(value, ANPS_IS_ALERT_ENABLED(conidx, p_anps_env, ANP_UNREAD_ALERT)); + } break; + + default: + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + // Send data to peer device + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, value_size); + p_cfm->length = value_size; + memcpy(p_cfm->value, value, value_size); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct anps_env_tag *p_anps_env = PRF_ENV_GET(ANPS, anps); + + // Check if the connection exists + if (p_anps_env != NULL) + { + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get the conidx + uint8_t conidx = KE_IDX_GET(src_id); + struct gattc_write_cfm *p_cfm; + + /* + * --------------------------------------------------------------------------------------------- + * New Alert Client Characteristic Configuration Descriptor Value - Write + * --------------------------------------------------------------------------------------------- + * Unread Status Alert Client Characteristic Configuration Descriptor Value - Write + * --------------------------------------------------------------------------------------------- + */ + if ((p_param->handle == (p_anps_env->shdl + ANS_IDX_NEW_ALERT_CFG)) || + (p_param->handle == (p_anps_env->shdl + ANS_IDX_UNREAD_ALERT_STATUS_CFG))) + { + // Received configuration value + uint16_t ntf_cfg = co_read16p(&p_param->value[0]); + + if (ntf_cfg <= PRF_CLI_START_NTF) + { + // Alert type + uint8_t alert_type = (p_param->handle == (p_anps_env->shdl + ANS_IDX_NEW_ALERT_CFG)) + ? ANP_NEW_ALERT : ANP_UNREAD_ALERT; + + // Update the status in the environment + if (ntf_cfg == PRF_CLI_START_NTF) + { + ANPS_ENABLE_ALERT(conidx, p_anps_env, alert_type); + } + else + { + ANPS_DISABLE_ALERT(conidx, p_anps_env, alert_type); + } + + // Inform the HL that the notification configuration status has been written + anps_send_ntf_status_update_ind(conidx, p_anps_env, alert_type); + // Enable bond Data + ANPS_ENABLE_ALERT(conidx, p_anps_env, ANPS_FLAG_CFG_PERFORMED_OK); + } + else + { + status = PRF_APP_ERROR; + } + } + /* + * --------------------------------------------------------------------------------------------- + * Alert Notification Control Point Characteristic Value - Write + * --------------------------------------------------------------------------------------------- + */ + else if (p_param->handle == (p_anps_env->shdl + ANS_IDX_ALERT_NTF_CTNL_PT_VAL)) + { + do + { + // Check the command ID value + if (p_param->value[0] >= CMD_ID_NB) + { + status = ANP_CMD_NOT_SUPPORTED; + break; + } + + // Check the category ID value + if ((p_param->value[1] >= CAT_ID_NB) && + (p_param->value[1] != CAT_ID_ALL_SUPPORTED_CAT)) + { + status = ANP_CAT_NOT_SUPPORTED; + break; + } + + if (p_param->value[1] < CAT_ID_NB) + { + // New Alert + if ((p_param->value[0] % 2) == 0) + { + // Check if the category is supported + if (!ANPS_IS_NEW_ALERT_CATEGORY_SUPPORTED(p_param->value[1])) + { + status = ANP_CAT_NOT_SUPPORTED; + break; + } + } + // Unread Alert Status + else + { + // Check if the category is supported + if (!ANPS_IS_UNREAD_ALERT_CATEGORY_SUPPORTED(p_param->value[1])) + { + status = ANP_CAT_NOT_SUPPORTED; + break; + } + } + } + + // React according to the received command id value + switch (p_param->value[0]) + { + // Enable New Alert Notification + case (CMD_ID_EN_NEW_IN_ALERT_NTF): + { + if (p_param->value[1] != CAT_ID_ALL_SUPPORTED_CAT) + { + // Enable sending of new alert notification for the specified category + ANPS_ENABLE_NEW_ALERT_CATEGORY(conidx, p_param->value[1], p_anps_env); + } + else + { + // Enable sending of new alert notification for all supported category + p_anps_env->p_env[conidx]->ntf_new_alert_cfg |= p_anps_env->supp_new_alert_cat; + } + + anps_send_ntf_status_update_ind(conidx, p_anps_env, ANP_NEW_ALERT); + } break; + + // Enable Unread Alert Status Notification + case (CMD_ID_EN_UNREAD_CAT_STATUS_NTF): + { + if (p_param->value[1] != CAT_ID_ALL_SUPPORTED_CAT) + { + // Enable sending of unread alert notification for the specified category + ANPS_ENABLE_UNREAD_ALERT_CATEGORY(conidx, p_param->value[1], p_anps_env); + } + else + { + // Enable sending of unread alert notification for all supported category + p_anps_env->p_env[conidx]->ntf_unread_alert_cfg |= p_anps_env->supp_unread_alert_cat; + } + + anps_send_ntf_status_update_ind(conidx, p_anps_env, ANP_UNREAD_ALERT); + } break; + + // Disable New Alert Notification + case (CMD_ID_DIS_NEW_IN_ALERT_NTF): + { + if (p_param->value[1] != CAT_ID_ALL_SUPPORTED_CAT) + { + // Disable sending of new alert notification for the specified category + ANPS_DISABLE_NEW_ALERT_CATEGORY(conidx, p_param->value[1], p_anps_env); + } + else + { + // Disable sending of new alert notification for all supported category + p_anps_env->p_env[conidx]->ntf_new_alert_cfg &= ~p_anps_env->supp_new_alert_cat; + } + + anps_send_ntf_status_update_ind(conidx, p_anps_env, ANP_NEW_ALERT); + } break; + + // Disable Unread Alert Status Notification + case (CMD_ID_DIS_UNREAD_CAT_STATUS_NTF): + { + if (p_param->value[1] != CAT_ID_ALL_SUPPORTED_CAT) + { + // Disable sending of unread alert notification for the specified category + ANPS_DISABLE_UNREAD_ALERT_CATEGORY(conidx, p_param->value[1], p_anps_env); + } + else + { + // Enable sending of unread alert notification for all supported category + p_anps_env->p_env[conidx]->ntf_unread_alert_cfg &= ~p_anps_env->supp_unread_alert_cat; + } + + anps_send_ntf_status_update_ind(conidx, p_anps_env, ANP_UNREAD_ALERT); + } break; + + // Notify New Alert immediately + case (CMD_ID_NTF_NEW_IN_ALERT_IMM): + { + // Check if sending of notification is enabled + if (ANPS_IS_ALERT_ENABLED(conidx, p_anps_env, ANP_NEW_ALERT)) + { + if (p_param->value[1] == CAT_ID_ALL_SUPPORTED_CAT) + { + // Check if at least one category can be notified + if (p_anps_env->p_env[conidx]->ntf_new_alert_cfg != 0) + { + anps_send_ntf_immediate_req_ind(conidx, p_anps_env, ANP_NEW_ALERT, + CAT_ID_ALL_SUPPORTED_CAT); + } + } + else + { + // Check if sending of notifications has been enabled for the specified category. + if (ANPS_IS_NEW_ALERT_CATEGORY_ENABLED(conidx, p_param->value[1], p_anps_env)) + { + anps_send_ntf_immediate_req_ind(conidx, p_anps_env, ANP_NEW_ALERT, + p_param->value[1]); + } + } + } + } break; + + // Notify Unread Alert Status immediately + case (CMD_ID_NTF_UNREAD_CAT_STATUS_IMM): + { + // Check if sending of notification is enabled + if (ANPS_IS_ALERT_ENABLED(conidx, p_anps_env, ANP_UNREAD_ALERT)) + { + if (p_param->value[1] == CAT_ID_ALL_SUPPORTED_CAT) + { + // Check if at least one category can be notified + if (p_anps_env->p_env[conidx]->ntf_unread_alert_cfg != 0) + { + anps_send_ntf_immediate_req_ind(conidx, p_anps_env, ANP_UNREAD_ALERT, + CAT_ID_ALL_SUPPORTED_CAT); + } + } + else + { + // Check if sending of notifications has been enabled for the specified category. + if (ANPS_IS_UNREAD_ALERT_CATEGORY_ENABLED(conidx, p_param->value[1], p_anps_env)) + { + anps_send_ntf_immediate_req_ind(conidx, p_anps_env, ANP_UNREAD_ALERT, + p_param->value[1]); + } + } + } + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } while (0); + } + else + { + ASSERT_ERR(0); + } + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC( + GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(anps) +{ + {ANPS_ENABLE_REQ, (ke_msg_func_t)anps_enable_req_handler}, + {ANPS_NTF_ALERT_CMD, (ke_msg_func_t)anps_ntf_alert_cmd_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t)gattc_read_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t)gattc_write_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void anps_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct anps_env_tag *p_anps_env = PRF_ENV_GET(ANPS, anps); + + p_task_desc->msg_handler_tab = anps_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(anps_msg_handler_tab); + p_task_desc->state = p_anps_env->state; + p_task_desc->idx_max = ANPS_IDX_MAX; +} + +#endif //(BLE_AN_SERVER) + +/// @} ANPSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/api/basc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/api/basc_task.h new file mode 100644 index 0000000..620e64b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/api/basc_task.h @@ -0,0 +1,212 @@ +/** + **************************************************************************************** + * + * @file basc_task.h + * + * @brief Header file - Battery Service Client Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _BASC_TASK_H_ +#define _BASC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup BASCTASK Battery Service Client Task + * @ingroup BASC + * @brief Battery Service Client Task + * + * The BASCTASK is responsible for handling the messages coming in and out of the + * @ref BASC block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +///Maximum number of Battery Service instances we can handle +#define BASC_NB_BAS_INSTANCES_MAX (2) + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/*@TRACE*/ +enum basc_msg_id +{ + /// Start the Battery Service Client Role - at connection + BASC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_BASC), + ///Confirm that cfg connection has finished with discovery results, or that normal cnx started + BASC_ENABLE_RSP, + + /// Read Characteristic Value Request + BASC_READ_INFO_REQ, + /// Read Characteristic Value Request + BASC_READ_INFO_RSP, + + /// Write Battery Level Notification Configuration Value request + BASC_BATT_LEVEL_NTF_CFG_REQ, + /// Write Battery Level Notification Configuration Value response + BASC_BATT_LEVEL_NTF_CFG_RSP, + + /// Indicate to APP that the Battery Level value has been received + BASC_BATT_LEVEL_IND, +}; + +/// Peer battery info that can be read +enum basc_info +{ + /// Battery Level value + BASC_BATT_LVL_VAL, + /// Battery Level Client Characteristic Configuration + BASC_NTF_CFG, + /// Battery Level Characteristic Presentation Format + BASC_BATT_LVL_PRES_FORMAT, + + BASC_INFO_MAX, +}; + +/// Battery Service Characteristics +enum bass_char_type +{ + /// Battery Level + BAS_CHAR_BATT_LEVEL, + + BAS_CHAR_MAX, +}; + +/// Battery Service Descriptors +enum bass_desc_type +{ + /// Battery Level Characteristic Presentation Format + BAS_DESC_BATT_LEVEL_PRES_FORMAT, + /// Battery Level Client Characteristic Configuration + BAS_DESC_BATT_LEVEL_CFG, + + BAS_DESC_MAX, +}; + +/* + * APIs Structure + **************************************************************************************** + */ + +///Structure containing the characteristics handles, value handles and descriptors +struct bas_content +{ + /// service info + struct prf_svc svc; + + /// Characteristic Info: + /// - Battery Level + struct prf_char_inf chars[BAS_CHAR_MAX]; + + /// Descriptor handles: + /// - Battery Level Client Characteristic Configuration + /// - Battery Level Characteristic Presentation Format + struct prf_char_desc_inf descs[BAS_DESC_MAX]; +}; + +/// Parameters of the @ref BASC_ENABLE_REQ message +struct basc_enable_req +{ + ///Connection type + uint8_t con_type; + /// Number of BAS instances that have previously been found + uint8_t bas_nb; + /// Existing handle values bas + struct bas_content bas[BASC_NB_BAS_INSTANCES_MAX]; +}; + +/// Parameters of the @ref BASC_ENABLE_RSP message +struct basc_enable_rsp +{ + /// Status + uint8_t status; + /// Number of BAS that have been found + uint8_t bas_nb; + ///Existing handle values bas + struct bas_content bas[BASC_NB_BAS_INSTANCES_MAX]; +}; + +///Parameters of the @ref BASC_READ_INFO_REQ message +struct basc_read_info_req +{ + ///Characteristic info @see enum basc_info + uint8_t info; + ///Battery Service Instance - From 0 to BASC_NB_BAS_INSTANCES_MAX-1 + uint8_t bas_nb; +}; + +///Parameters of the @ref BASC_READ_INFO_RSP message +struct basc_read_info_rsp +{ + /// status of the request + uint8_t status; + ///Characteristic info @see enum basc_info + uint8_t info; + ///Battery Service Instance - From 0 to BASC_NB_BAS_INSTANCES_MAX-1 + uint8_t bas_nb; + + /// Information data + union basc_data + { + /// Battery Level - if info = BASC_BATT_LVL_VAL + uint8_t batt_level; + ///Notification Configuration Value - if info = BASC_NTF_CFG + uint16_t ntf_cfg; + ///Characteristic Presentation Format - if info = BASC_BATT_LVL_PRES_FORMAT + struct prf_char_pres_fmt char_pres_format; + } data; +}; + +///Parameters of the @ref BASC_BATT_LEVEL_NTF_CFG_REQ message +struct basc_batt_level_ntf_cfg_req +{ + ///Notification Configuration + uint16_t ntf_cfg; + ///Battery Service Instance - From 0 to BASC_NB_BAS_INSTANCES_MAX-1 + uint8_t bas_nb; +}; + +///Parameters of the @ref BASC_BATT_LEVEL_NTF_CFG_RSP message +struct basc_batt_level_ntf_cfg_rsp +{ + ///Status + uint8_t status; + ///Battery Service Instance - From 0 to BASC_NB_BAS_INSTANCES_MAX-1 + uint8_t bas_nb; +}; + +///Parameters of the @ref BASC_BATT_LEVEL_IND message +struct basc_batt_level_ind +{ + ///Battery Level + uint8_t batt_level; + ///Battery Service Instance - From 0 to BASC_NB_BAS_INSTANCES_MAX-1 + uint8_t bas_nb; +}; + + +/// @} BASCTASK + +#endif /* _BASC_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/sourcelist.txt new file mode 100644 index 0000000..7a4f277 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + basc.c + basc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/src/basc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/src/basc.c new file mode 100644 index 0000000..fd66630 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/src/basc.c @@ -0,0 +1,224 @@ +/** + **************************************************************************************** + * + * @file basc.c + * + * @brief Battery Service Client implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup BASC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_BATT_CLIENT) + +#include "gap.h" +#include "basc.h" +#include "basc_task.h" +#include "co_math.h" + +#include "ke_mem.h" + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Initialization of the BASC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t basc_init (struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_param) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct basc_env_tag *p_basc_env = + (struct basc_env_tag *) ke_malloc(sizeof(struct basc_env_tag), KE_MEM_ATT_DB); + + // allocate BASC required environment variable + p_env->env = (prf_env_t *) p_basc_env; + + p_basc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_basc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_BASC; + basc_task_init(&(p_env->desc)); + + for (idx = 0; idx < BASC_IDX_MAX; idx++) + { + p_basc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), BASC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Destruction of the BASC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void basc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct basc_env_tag *p_basc_env = (struct basc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < BASC_IDX_MAX; idx++) + { + if (p_basc_env->p_env[idx] != NULL) + { + if (p_basc_env->p_env[idx]->p_operation != NULL) + { + ke_free(p_basc_env->p_env[idx]->p_operation); + } + + ke_free(p_basc_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_basc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void basc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put BAS Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), BASC_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void basc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct basc_env_tag *p_basc_env = (struct basc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_basc_env->p_env[conidx] != NULL) + { + if (p_basc_env->p_env[conidx]->p_operation != NULL) + { + ke_free(p_basc_env->p_env[conidx]->p_operation); + } + ke_free(p_basc_env->p_env[conidx]); + + p_basc_env->p_env[conidx] = NULL; + } + + /* Put BAS Client in Free state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), BASC_FREE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// BASC Task interface required by profile manager +const struct prf_task_cbs basc_itf = +{ + basc_init, + basc_destroy, + basc_create, + basc_cleanup, +}; + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *basc_prf_itf_get(void) +{ + return &basc_itf; +} + + +void basc_enable_rsp_send(struct basc_env_tag *p_basc_env, uint8_t conidx, uint8_t status) +{ + // Send APP the details of the discovered attributes on BASC + struct basc_enable_rsp *p_rsp = KE_MSG_ALLOC(BASC_ENABLE_RSP, + prf_dst_task_get(&(p_basc_env->prf_env) ,conidx), + prf_src_task_get(&(p_basc_env->prf_env) ,conidx), + basc_enable_rsp); + + p_rsp->status = status; + p_rsp->bas_nb = 0; + + if (status == GAP_ERR_NO_ERROR) + { + // Counter + uint8_t svc_inst; + + p_rsp->bas_nb = p_basc_env->p_env[conidx]->bas_nb; + + for (svc_inst = 0; svc_inst < co_min(p_basc_env->p_env[conidx]->bas_nb, BASC_NB_BAS_INSTANCES_MAX); svc_inst++) + { + p_rsp->bas[svc_inst] = p_basc_env->p_env[conidx]->bas[svc_inst]; + + // Register BASC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_basc_env->prf_env), conidx, &p_basc_env->p_env[conidx]->bas[svc_inst].svc); + } + } + + ke_msg_send(p_rsp); +} + +#endif /* (BLE_BATT_CLIENT) */ + +/// @} BASC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/src/basc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/src/basc.h new file mode 100644 index 0000000..b6efe65 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/src/basc.h @@ -0,0 +1,147 @@ +/** + **************************************************************************************** + * + * @file basc.h + * + * @brief Header file - Battery Service - Client Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _BASC_H_ +#define _BASC_H_ + +/** + **************************************************************************************** + * @addtogroup BASC Battery Service Client + * @ingroup BAS + * @brief Battery Service Client + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_BATT_CLIENT) + +#include +#include +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" +#include "basc_task.h" + +/* + * DEFINES + **************************************************************************************** + */ + +///Maximum number of Battery Client task instances +#define BASC_IDX_MAX (BLE_CONNECTION_MAX) + +/// Possible states of the BAPC task +enum basc_state +{ + /// Disconnected state + BASC_FREE, + /// IDLE state + BASC_IDLE, + /// Busy State + BASC_BUSY, + + /// Number of defined states. + BASC_STATE_MAX +}; + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/// Environment variable for each Connections +struct basc_cnx_env +{ + /// on-going operation + struct ke_msg *p_operation; + ///BAS characteristics + struct bas_content bas[BASC_NB_BAS_INSTANCES_MAX]; + + ///Number of BAS instances found + uint8_t bas_nb; +}; + +/// Battery 'Profile' Client environment variable +struct basc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct basc_cnx_env *p_env[BASC_IDX_MAX]; + /// State of different task instances + ke_state_t state[BASC_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Retrieve BAS client profile interface + * + * @return BAS client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *basc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send BAS ATT DB discovery results to BASC host. + * + * @param p_basc_env Battery Service Client Role task environment + * @param conidx Connection index + * @param status Response status code + **************************************************************************************** + */ +void basc_enable_rsp_send(struct basc_env_tag *p_basc_env, uint8_t conidx, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void basc_task_init(struct ke_task_desc *p_task_desc); + +#endif /* (BLE_BATT_CLIENT) */ + +/// @} BASC + +#endif /* _BASC_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/src/basc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/src/basc_task.c new file mode 100644 index 0000000..f21f604 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/basc/src/basc_task.c @@ -0,0 +1,647 @@ +/** + **************************************************************************************** + * + * @file basc_task.c + * + * @brief Battery Service Client Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup BASCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_BATT_CLIENT) + +#include "gap.h" +#include "basc.h" +#include "basc_task.h" +#include "gattc_task.h" +#include "co_math.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// State machine used to retrieve Battery Service characteristics information +const struct prf_char_def basc_bas_char[BAS_CHAR_MAX] = +{ + /// Battery Level + [BAS_CHAR_BATT_LEVEL] = {ATT_CHAR_BATTERY_LEVEL, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, +}; + +/// State machine used to retrieve Battery Service characteristic description information +const struct prf_char_desc_def basc_bas_char_desc[BAS_DESC_MAX] = +{ + /// Battery Level Characteristic Presentation Format + [BAS_DESC_BATT_LEVEL_PRES_FORMAT] = {ATT_DESC_CHAR_PRES_FORMAT, ATT_OPTIONAL, BAS_CHAR_BATT_LEVEL}, + /// Battery Level Client Config + [BAS_DESC_BATT_LEVEL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_OPTIONAL, BAS_CHAR_BATT_LEVEL}, + +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BASC_ENABLE_REQ message. + * The handler enables the Battery Service Client Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int basc_enable_req_handler(ke_msg_id_t const msgid, + struct basc_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + int msg_status = KE_MSG_CONSUMED; + + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Battery service Client Role Task Environment + struct basc_env_tag *p_basc_env = PRF_ENV_GET(BASC, basc); + + ASSERT_INFO(p_basc_env != NULL, dest_id, src_id); + if ((state == BASC_IDLE) && (p_basc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_basc_env->p_env[conidx] = (struct basc_cnx_env *) ke_malloc(sizeof(struct basc_cnx_env),KE_MEM_ATT_DB); + memset(p_basc_env->p_env[conidx], 0, sizeof(struct basc_cnx_env)); + + //Config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + //start discovering BAS on peer + prf_disc_svc_send(&(p_basc_env->prf_env), conidx, ATT_SVC_BATTERY_SERVICE); + + // Go to DISCOVERING state + ke_state_set(dest_id, BASC_BUSY); + p_basc_env->p_env[conidx]->p_operation = ke_param2msg(p_param); + msg_status = KE_MSG_NO_FREE; + } + //normal connection, get saved att details + else + { + p_basc_env->p_env[conidx]->bas_nb = p_param->bas_nb; + memcpy(&(p_basc_env->p_env[conidx]->bas[0]), &(p_param->bas[0]), + sizeof(struct bas_content) * BASC_NB_BAS_INSTANCES_MAX); + + //send APP confirmation that can start normal connection to TH + basc_enable_rsp_send(p_basc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != BASC_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + basc_enable_rsp_send(p_basc_env, conidx, status); + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == BASC_BUSY) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct basc_env_tag *p_basc_env = PRF_ENV_GET(BASC, basc); + + ASSERT_INFO(p_basc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_basc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_basc_env->p_env[conidx]->bas_nb < BASC_NB_BAS_INSTANCES_MAX) + { + // Retrieve DIS characteristics + prf_extract_svc_info(p_ind, BAS_CHAR_MAX, &basc_bas_char[0], + &(p_basc_env->p_env[conidx]->bas[p_basc_env->p_env[conidx]->bas_nb].chars[0]), + BAS_DESC_MAX, &basc_bas_char_desc[0], + &(p_basc_env->p_env[conidx]->bas[p_basc_env->p_env[conidx]->bas_nb].descs[0])); + + //Even if we get multiple responses we only store 1 range + p_basc_env->p_env[conidx]->bas[p_basc_env->p_env[conidx]->bas_nb].svc.shdl = p_ind->start_hdl; + p_basc_env->p_env[conidx]->bas[p_basc_env->p_env[conidx]->bas_nb].svc.ehdl = p_ind->end_hdl; + } + + p_basc_env->p_env[conidx]->bas_nb++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BASC_READ_INFO_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int basc_read_info_req_handler(ke_msg_id_t const msgid, struct basc_read_info_req const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (state == BASC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct basc_env_tag *p_basc_env = PRF_ENV_GET(BASC, basc); + + ASSERT_INFO(p_basc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_basc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + // check p_parameter range + else if (p_param->bas_nb > p_basc_env->p_env[conidx]->bas_nb) + { + status = PRF_ERR_INVALID_PARAM; + } + else + { + uint16_t handle = ATT_INVALID_HANDLE; + + status = PRF_ERR_INEXISTENT_HDL; + + // check requested info + switch (p_param->info) + { + // Battery Level value + case BASC_BATT_LVL_VAL: + { + handle = p_basc_env->p_env[conidx]->bas[p_param->bas_nb]. + chars[BAS_CHAR_BATT_LEVEL].val_hdl; + } break; + // Battery Level Client Characteristic Configuration + case BASC_NTF_CFG: + { + handle = p_basc_env->p_env[conidx]->bas[p_param->bas_nb]. + descs[BAS_DESC_BATT_LEVEL_CFG].desc_hdl; + } break; + // Battery Level Characteristic Presentation Format + case BASC_BATT_LVL_PRES_FORMAT: + { + handle = p_basc_env->p_env[conidx]->bas[p_param->bas_nb]. + descs[BAS_DESC_BATT_LEVEL_PRES_FORMAT].desc_hdl; + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + if (handle != ATT_INVALID_HANDLE) + { + status = GAP_ERR_NO_ERROR; + // read information + prf_read_char_send(&(p_basc_env->prf_env), conidx, + p_basc_env->p_env[conidx]->bas[p_param->bas_nb].svc.shdl, + p_basc_env->p_env[conidx]->bas[p_param->bas_nb].svc.ehdl, handle); + + // store context of request and go into busy state + p_basc_env->p_env[conidx]->p_operation = ke_param2msg(p_param); + ke_state_set(dest_id, BASC_BUSY); + msg_status = KE_MSG_NO_FREE; + } + } + } + // process message later + else if (state == BASC_BUSY) + { + status = GAP_ERR_NO_ERROR; + msg_status = KE_MSG_SAVED; + } + + // request cannot be performed + if (status != GAP_ERR_NO_ERROR) + { + struct basc_read_info_rsp *p_rsp = KE_MSG_ALLOC(BASC_READ_INFO_RSP, + src_id, dest_id, basc_read_info_rsp); + + // set error status + p_rsp->status = status; + p_rsp->info = p_param->info; + p_rsp->bas_nb = p_param->bas_nb; + + ke_msg_send(p_rsp); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BASC_BATT_LEVEL_NTF_CFG_REQ message. + * It allows configuration of the peer ntf/stop characteristic for Battery Level Characteristic. + * Will return an error code if that cfg char does not exist. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int basc_batt_level_ntf_cfg_req_handler(ke_msg_id_t const msgid, + struct basc_batt_level_ntf_cfg_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (state == BASC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct basc_env_tag *p_basc_env = PRF_ENV_GET(BASC, basc); + + ASSERT_INFO(p_basc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_basc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + // check p_parameter range + else if ((p_param->bas_nb > p_basc_env->p_env[conidx]->bas_nb) + || (p_param->ntf_cfg > PRF_CLI_START_NTF)) + { + status = PRF_ERR_INVALID_PARAM; + } + else + { + uint16_t handle = p_basc_env->p_env[conidx]->bas[p_param->bas_nb]. + descs[BAS_DESC_BATT_LEVEL_CFG].desc_hdl; + + status = PRF_ERR_INEXISTENT_HDL; + + if (handle == ATT_INVALID_HDL) + { + status = PRF_ERR_INEXISTENT_HDL; + } + else + { + status = GAP_ERR_NO_ERROR; + // Send GATT Write Request + prf_gatt_write_ntf_ind(&p_basc_env->prf_env, conidx, handle, p_param->ntf_cfg); + // store context of request and go into busy state + p_basc_env->p_env[conidx]->p_operation = ke_param2msg(p_param); + ke_state_set(dest_id, BASC_BUSY); + msg_status = KE_MSG_NO_FREE; + } + } + } + // process message later + else if (state == BASC_BUSY) + { + status = GAP_ERR_NO_ERROR; + msg_status = KE_MSG_SAVED; + } + + // request cannot be performed + if (status != GAP_ERR_NO_ERROR) + { + struct basc_batt_level_ntf_cfg_rsp *p_rsp = KE_MSG_ALLOC(BASC_BATT_LEVEL_NTF_CFG_RSP, + src_id, dest_id, basc_batt_level_ntf_cfg_rsp); + + // set error status + p_rsp->status = status; + p_rsp->bas_nb = p_param->bas_nb; + + ke_msg_send(p_rsp); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct basc_env_tag *p_basc_env = PRF_ENV_GET(BASC, basc); + + // sanity check + if ((ke_state_get(dest_id) == BASC_BUSY) && (p_basc_env->p_env[conidx] != NULL) + && (p_basc_env->p_env[conidx]->p_operation != NULL)) + { + switch (p_basc_env->p_env[conidx]->p_operation->id) + { + case BASC_ENABLE_REQ: + { + uint8_t status = p_param->status; + + if (p_param->status == ATT_ERR_NO_ERROR) + { + // check characteristic validity + if (p_basc_env->p_env[conidx]->bas_nb > 0) + { + uint8_t i; + + for (i = 0; (i < co_min(p_basc_env->p_env[conidx]->bas_nb, BASC_NB_BAS_INSTANCES_MAX)) + && (status == GAP_ERR_NO_ERROR); i++) + { + status = prf_check_svc_char_validity(BAS_CHAR_MAX, p_basc_env->p_env[conidx]->bas[i].chars, + basc_bas_char); + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + struct prf_char_desc_def bas_desc[BAS_DESC_MAX]; + + memcpy(bas_desc, basc_bas_char_desc, sizeof(basc_bas_char_desc)); + + if (p_basc_env->p_env[conidx]->bas_nb > 1) + { + bas_desc[BAS_DESC_BATT_LEVEL_PRES_FORMAT].req_flag = ATT_MANDATORY; + } + if ((p_basc_env->p_env[conidx]->bas[i].chars[BAS_CHAR_BATT_LEVEL]. + prop & ATT_CHAR_PROP_NTF) == ATT_CHAR_PROP_NTF) + { + bas_desc[BAS_DESC_BATT_LEVEL_CFG].req_flag = ATT_MANDATORY; + } + + status = prf_check_svc_char_desc_validity(BAS_DESC_MAX, + p_basc_env->p_env[conidx]->bas[i].descs, bas_desc, + p_basc_env->p_env[conidx]->bas[i].chars); + } + } + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + } + + basc_enable_rsp_send(p_basc_env, conidx, status); + } break; + + case BASC_READ_INFO_REQ: + { + struct basc_read_info_req *p_req = (struct basc_read_info_req *) + ke_msg2param(p_basc_env->p_env[conidx]->p_operation); + + struct basc_read_info_rsp *p_rsp = KE_MSG_ALLOC(BASC_READ_INFO_RSP, + prf_dst_task_get(&(p_basc_env->prf_env), conidx), dest_id, basc_read_info_rsp); + + // set error status + p_rsp->status = p_param->status; + p_rsp->bas_nb = p_req->bas_nb; + p_rsp->info = p_req->info; + + ke_msg_send(p_rsp); + } break; + + case BASC_BATT_LEVEL_NTF_CFG_REQ: + { + struct basc_batt_level_ntf_cfg_req *p_req = (struct basc_batt_level_ntf_cfg_req *) + ke_msg2param(p_basc_env->p_env[conidx]->p_operation); + + struct basc_batt_level_ntf_cfg_rsp *p_rsp = KE_MSG_ALLOC(BASC_BATT_LEVEL_NTF_CFG_RSP, + prf_dst_task_get(&(p_basc_env->prf_env), conidx), dest_id, basc_batt_level_ntf_cfg_rsp); + + // set error status + p_rsp->status = p_param->status; + p_rsp->bas_nb = p_req->bas_nb; + + ke_msg_send(p_rsp); + } break; + + default: + { + // Not Expected at all + ASSERT_ERR(0); + }break; + } + + // operation is over - go back to idle state + ke_free(p_basc_env->p_env[conidx]->p_operation); + p_basc_env->p_env[conidx]->p_operation = NULL; + ke_state_set(dest_id, BASC_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == BASC_BUSY) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct basc_env_tag *p_basc_env = PRF_ENV_GET(BASC, basc); + struct basc_read_info_req *p_req = (struct basc_read_info_req *) + ke_msg2param(p_basc_env->p_env[conidx]->p_operation); + + ASSERT_INFO(p_basc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_basc_env->p_env[conidx] != NULL, dest_id, src_id); + + + struct basc_read_info_rsp *p_rsp = KE_MSG_ALLOC(BASC_READ_INFO_RSP, + prf_dst_task_get(&(p_basc_env->prf_env),conidx), dest_id, basc_read_info_rsp); + + // set error status + p_rsp->status = GAP_ERR_NO_ERROR; + p_rsp->bas_nb = p_req->bas_nb; + p_rsp->info = p_req->info; + + switch (p_req->info) + { + // Battery Level value + case BASC_BATT_LVL_VAL: + { + p_rsp->data.batt_level = p_param->value[0]; + } break; + + // Battery Level Client Characteristic Configuration + case BASC_NTF_CFG: + { + p_rsp->data.ntf_cfg = co_read16p(&p_param->value[0]); + } break; + + // Battery Level Characteristic Presentation Format + case BASC_BATT_LVL_PRES_FORMAT: + { + prf_unpack_char_pres_fmt(&p_param->value[0], &p_rsp->data.char_pres_format); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + // send response + ke_msg_send(p_rsp); + + // operation is over - go back to idle state + ke_free(p_basc_env->p_env[conidx]->p_operation); + p_basc_env->p_env[conidx]->p_operation = NULL; + ke_state_set(dest_id, BASC_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) != BASC_FREE) + { + // BAS Instance + uint8_t bas_nb; + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct basc_env_tag *p_basc_env = PRF_ENV_GET(BASC, basc); + + //Battery Level - BAS instance is unknown. + for (bas_nb = 0; (bas_nb < p_basc_env->p_env[conidx]->bas_nb); bas_nb++) + { + if (p_param->handle == p_basc_env->p_env[conidx]->bas[bas_nb].chars[BAS_CHAR_BATT_LEVEL].val_hdl) + { + struct basc_batt_level_ind *p_ind = KE_MSG_ALLOC(BASC_BATT_LEVEL_IND, + prf_dst_task_get(&(p_basc_env->prf_env), conidx), dest_id, + basc_batt_level_ind); + + p_ind->batt_level = p_param->value[0]; + p_ind->bas_nb = bas_nb; + + //Send Battery Level value to APP + ke_msg_send(p_ind); + + break; + } + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(basc) +{ + {BASC_ENABLE_REQ, (ke_msg_func_t)basc_enable_req_handler}, + {BASC_READ_INFO_REQ, (ke_msg_func_t)basc_read_info_req_handler}, + {BASC_BATT_LEVEL_NTF_CFG_REQ, (ke_msg_func_t)basc_batt_level_ntf_cfg_req_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void basc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct basc_env_tag *p_basc_env = PRF_ENV_GET(BASC, basc); + + p_task_desc->msg_handler_tab = basc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(basc_msg_handler_tab); + p_task_desc->state = p_basc_env->state; + p_task_desc->idx_max = BASC_IDX_MAX; +} + +#endif /* (BLE_BATT_CLIENT) */ + +/// @} BASCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/api/bass_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/api/bass_task.h new file mode 100644 index 0000000..a61b5eb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/api/bass_task.h @@ -0,0 +1,144 @@ +/** + **************************************************************************************** + * + * @file bass_task.h + * + * @brief Header file - Battery Service Server Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _BASS_TASK_H_ +#define _BASS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup BAPSTASK Task + * @ingroup BAPS + * @brief Battery 'Profile' Task. + * + * The BAPS_TASK is responsible for handling the messages coming in and out of the + * @ref BAPS block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "prf_types.h" +#include "rwip_task.h" // Task definitions + +/* + * DEFINES + **************************************************************************************** + */ + +#define BAS_BATTERY_LVL_MAX (100) + + +///Maximal number of BAS that can be added in the DB +#define BASS_NB_BAS_INSTANCES_MAX (2) + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/// Messages for Battery Server +/*@TRACE*/ +enum bass_msg_id +{ + /// Start the Battery Server - at connection used to restore bond data + BASS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_BASS), + /// Confirmation of the Battery Server start + BASS_ENABLE_RSP, + /// Battery Level Value Update Request + BASS_BATT_LEVEL_UPD_REQ, + /// Inform APP if Battery Level value has been notified or not + BASS_BATT_LEVEL_UPD_RSP, + /// Inform APP that Battery Level Notification Configuration has been changed - use to update bond data + BASS_BATT_LEVEL_NTF_CFG_IND, +}; + +/// Features Flag Masks +enum bass_features +{ + /// Battery Level Characteristic doesn't support notifications + BAS_BATT_LVL_NTF_NOT_SUP, + /// Battery Level Characteristic support notifications + BAS_BATT_LVL_NTF_SUP, +}; + +/* + * APIs Structures + **************************************************************************************** + */ + +/// Parameters for the database creation +struct bass_db_cfg +{ + /// Number of BAS to add + uint8_t bas_nb; + /// Features of each BAS instance + uint8_t features[BASS_NB_BAS_INSTANCES_MAX]; + /// Battery Level Characteristic Presentation Format - Should not change during connection + struct prf_char_pres_fmt batt_level_pres_format[BASS_NB_BAS_INSTANCES_MAX]; +}; + +/// Parameters of the @ref BASS_ENABLE_REQ message +struct bass_enable_req +{ + /// connection index + uint8_t conidx; + /// Notification Configuration + uint8_t ntf_cfg; + /// Old Battery Level used to decide if notification should be triggered + uint8_t old_batt_lvl[BASS_NB_BAS_INSTANCES_MAX]; +}; + +/// Parameters of the @ref BASS_ENABLE_RSP message +struct bass_enable_rsp +{ + /// connection index + uint8_t conidx; + ///status + uint8_t status; +}; + +///Parameters of the @ref BASS_BATT_LEVEL_UPD_REQ message +struct bass_batt_level_upd_req +{ + /// BAS instance + uint8_t bas_instance; + /// Battery Level + uint8_t batt_level; +}; + +///Parameters of the @ref BAPS_BATT_LEVEL_UPD_RSP message +struct bass_batt_level_upd_rsp +{ + ///status + uint8_t status; +}; + +///Parameters of the @ref BASS_BATT_LEVEL_NTF_CFG_IND message +struct bass_batt_level_ntf_cfg_ind +{ + /// connection index + uint8_t conidx; + ///Notification Configuration + uint8_t ntf_cfg; +}; + +/// @} BASSTASK + +#endif /* _BASS_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/sourcelist.txt new file mode 100644 index 0000000..525002e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + bass.c + bass_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass.c new file mode 100644 index 0000000..c9625af --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass.c @@ -0,0 +1,486 @@ +/** + **************************************************************************************** + * + * @file bass.c + * + * @brief Battery Server Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup BASS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_BATT_SERVER) +#include "bass.h" +#include "bass_task.h" +#include "prf_utils.h" +#include "prf.h" + +#include "ke_mem.h" + +/* + * BAS ATTRIBUTES DEFINITION + **************************************************************************************** + */ + +/// Full BAS Database Description - Used to add attributes into the database +const struct attm_desc bas_att_db[BAS_IDX_NB] = +{ + // Battery Service Declaration + [BAS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Battery Level Characteristic Declaration + [BAS_IDX_BATT_LVL_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Battery Level Characteristic Value + [BAS_IDX_BATT_LVL_VAL] = {ATT_CHAR_BATTERY_LEVEL, PERM(RD, ENABLE), PERM(RI, ENABLE), 0}, + // Battery Level Characteristic - Client Characteristic Configuration Descriptor + [BAS_IDX_BATT_LVL_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WRITE_REQ, ENABLE), 0, 0}, + // Battery Level Characteristic - Characteristic Presentation Format Descriptor + [BAS_IDX_BATT_LVL_PRES_FMT] = {ATT_DESC_CHAR_PRES_FORMAT, PERM(RD, ENABLE), PERM(RI, ENABLE), 0}, +}; + + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the BASS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t bass_init (struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct bass_db_cfg *p_params) +{ +// NS_LOG_DEBUG("%s\r\n",__func__); + uint16_t shdl[BASS_NB_BAS_INSTANCES_MAX]; + struct bass_env_tag *p_bass_env = NULL; + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Counter + uint8_t i; + + // Check number of BAS instances + if ((p_params->bas_nb > 0) && (p_params->bas_nb <= BASS_NB_BAS_INSTANCES_MAX)) + { + //-------------------- allocate memory required for the profile --------------------- + p_bass_env = (struct bass_env_tag *) ke_malloc(sizeof(struct bass_env_tag), KE_MEM_ATT_DB); + memset(p_bass_env, 0 , sizeof(struct bass_env_tag)); + + // Save number of BAS + p_bass_env->svc_nb = p_params->bas_nb; + + for (i = 0; ((i < p_params->bas_nb) && (status == GAP_ERR_NO_ERROR)); i++) + { + // Service content flag + uint8_t cfg_flag = BAS_CFG_FLAG_MANDATORY_MASK; + + // Save database configuration + p_bass_env->features |= (p_params->features[i]) << i; + p_bass_env->batt_level_pres_format[i] = p_params->batt_level_pres_format[i]; + + // Check if notifications are supported + if (p_params->features[i] == BAS_BATT_LVL_NTF_SUP) + { + cfg_flag |= BAS_CFG_FLAG_NTF_SUP_MASK; + } + + // Check if multiple instances + if (p_bass_env->svc_nb > 1) + { + cfg_flag |= BAS_CFG_FLAG_MTP_BAS_MASK; + } + + shdl[i] = *p_start_hdl; + + //Create BAS in the DB + //------------------ create the attribute database for the profile ------------------- + status = attm_svc_create_db(&(shdl[i]), ATT_SVC_BATTERY_SERVICE, (uint8_t *)&cfg_flag, + BAS_IDX_NB, NULL, p_env->task, bas_att_db, + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS))); + + //Set optional permissions + if (status == GAP_ERR_NO_ERROR) + { + // update start handle for next service - only useful if multiple service, else not used. + // 4 characteristics + optional notification characteristic. + *p_start_hdl = shdl[i] + BAS_IDX_NB - ((p_params->features[i] == BAS_BATT_LVL_NTF_SUP) ? 0 : 1); + + //Set optional permissions + if (p_params->features[i] == BAS_BATT_LVL_NTF_SUP) + { + // Battery Level characteristic value permissions + uint16_t perm = PERM(RD, ENABLE) | PERM(NTF, ENABLE); + + attm_att_set_permission(shdl[i] + BAS_IDX_BATT_LVL_VAL, perm, 0); + } + } + + // Reset configuration flag + cfg_flag = BAS_CFG_FLAG_MANDATORY_MASK; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + + //-------------------- Update profile task information --------------------- + if (status == ATT_ERR_NO_ERROR) + { + // allocate BASS required environment variable + p_env->env = (prf_env_t *) p_bass_env; + *p_start_hdl = shdl[0]; + p_bass_env->start_hdl = *p_start_hdl; + p_bass_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_bass_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_BASS; + bass_task_init(&(p_env->desc)); + + // service is ready, go into an Idle state + ke_state_set(p_env->task, BASS_IDLE); + } + else if(p_bass_env != NULL) + { + ke_free(p_bass_env); + } + + return (status); +} +/** + **************************************************************************************** + * @brief Destruction of the BASS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void bass_destroy(struct prf_task_env *p_env) +{ + struct bass_env_tag *p_bass_env = (struct bass_env_tag *) p_env->env; + + // clear on-going operation + if (p_bass_env->p_operation != NULL) + { + ke_free(p_bass_env->p_operation); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_bass_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void bass_create(struct prf_task_env* p_env, uint8_t conidx) +{ + struct bass_env_tag *p_bass_env = (struct bass_env_tag *) p_env->env; + + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + // force notification config to zero when peer device is connected + p_bass_env->ntf_cfg[conidx] = 0; +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void bass_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct bass_env_tag *p_bass_env = (struct bass_env_tag *) p_env->env; + + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + // force notification config to zero when peer device is disconnected + p_bass_env->ntf_cfg[conidx] = 0; +} + + +/** + **************************************************************************************** + * @brief Trigger battery level notification + * + * @param p_bass_env profile environment + * @param conidx peer destination connection index + * @param svc_idx Service index + **************************************************************************************** + */ +static void bass_notify_batt_lvl(struct bass_env_tag *p_bass_env, uint8_t conidx, uint8_t svc_idx) +{ + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_batt_lvl = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), prf_src_task_get(&(p_bass_env->prf_env),0), + gattc_send_evt_cmd, sizeof(uint8_t)); + + // Fill in the parameter structure + p_batt_lvl->operation = GATTC_NOTIFY; + p_batt_lvl->handle = bass_get_att_handle(svc_idx, BAS_IDX_BATT_LVL_VAL); + // pack measured value in database + p_batt_lvl->length = sizeof(uint8_t); + p_batt_lvl->value[0] = p_bass_env->batt_lvl[svc_idx]; + + // send notification to peer device + ke_msg_send(p_batt_lvl); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// BASS Task interface required by profile manager +const struct prf_task_cbs bass_itf = +{ + (prf_init_fnct) bass_init, + bass_destroy, + bass_create, + bass_cleanup, +}; + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *bass_prf_itf_get(void) +{ + return &bass_itf; +} + +uint16_t bass_get_att_handle(uint8_t svc_idx, uint8_t att_idx) +{ + struct bass_env_tag *p_bass_env = PRF_ENV_GET(BASS, bass); + uint16_t handle = ATT_INVALID_HDL; + uint8_t i = 0; + + if (svc_idx < p_bass_env ->svc_nb) + { + handle = p_bass_env->start_hdl; + + for (i = 0; i < svc_idx; i++) + { + // update start handle for next service - only useful if multiple service, else not used. + // 4 characteristics + optional notification characteristic. + handle += BAS_IDX_NB - ((((p_bass_env->features >> i) & 0x01) == BAS_BATT_LVL_NTF_SUP) ? 0 : 1); + } + + // increment index according to expected index + if (att_idx < BAS_IDX_BATT_LVL_NTF_CFG) + { + handle += att_idx; + } + // Battery notification + else if ((att_idx == BAS_IDX_BATT_LVL_NTF_CFG) && + (((p_bass_env->features >> i) & 0x01) == BAS_BATT_LVL_NTF_SUP)) + { + handle += BAS_IDX_BATT_LVL_NTF_CFG; + } + // Battery Level format + else if ((att_idx == BAS_IDX_BATT_LVL_PRES_FMT) && (p_bass_env->svc_nb > 1)) + { + handle += BAS_IDX_BATT_LVL_PRES_FMT - + ((((p_bass_env->features >> i) & 0x01) == BAS_BATT_LVL_NTF_SUP) ? 0 : 1); + } + else + { + handle = ATT_INVALID_HDL; + } + } + + return handle; +} + +uint8_t bass_get_att_idx(uint16_t handle, uint8_t *p_svc_idx, uint8_t *p_att_idx) +{ + struct bass_env_tag *p_bass_env = PRF_ENV_GET(BASS, bass); + uint16_t hdl_cursor = p_bass_env->start_hdl; + uint8_t status = PRF_APP_ERROR; + + // Browse list of services + // handle must be greater than current index + for (*p_svc_idx = 0; (*p_svc_idx < p_bass_env->svc_nb) && (handle >= hdl_cursor); (*p_svc_idx)++) + { + // check if it's a mandatory index + if (handle <= (hdl_cursor + BAS_IDX_BATT_LVL_VAL)) + { + *p_att_idx = handle - hdl_cursor; + status = GAP_ERR_NO_ERROR; + + break; + } + + hdl_cursor += BAS_IDX_BATT_LVL_VAL; + + // check if it's a notify index + if (((p_bass_env->features >> *p_svc_idx) & 0x01) == BAS_BATT_LVL_NTF_SUP) + { + hdl_cursor++; + + if (handle == hdl_cursor) + { + *p_att_idx = BAS_IDX_BATT_LVL_NTF_CFG; + status = GAP_ERR_NO_ERROR; + + break; + } + } + + // check if it's battery level format + if (p_bass_env->svc_nb > 1) + { + hdl_cursor++; + + if (handle == hdl_cursor) + { + *p_att_idx = BAS_IDX_BATT_LVL_PRES_FMT; + status = GAP_ERR_NO_ERROR; + break; + } + } + + hdl_cursor++; + } + + return (status); +} + +void bass_exe_operation(void) +{ + struct bass_env_tag *p_bass_env = PRF_ENV_GET(BASS, bass); + ASSERT_ERR(p_bass_env->p_operation != NULL); + bool finished = true; + uint8_t conidx = GAP_INVALID_CONIDX; + + // Restoring connection information requested + if (p_bass_env->p_operation->id == BASS_ENABLE_REQ) + { + struct bass_enable_req *p_enable = (struct bass_enable_req *) ke_msg2param(p_bass_env->p_operation); + + conidx = p_enable->conidx; + // loop on all services to check if notification should be triggered + while (p_bass_env->cursor < BASS_NB_BAS_INSTANCES_MAX) + { + if (((p_bass_env->ntf_cfg[p_enable->conidx] & (1 << p_bass_env->cursor)) != 0) + && (p_enable->old_batt_lvl[p_bass_env->cursor] != p_bass_env->batt_lvl[p_bass_env->cursor])) + { + // trigger notification + bass_notify_batt_lvl(p_bass_env, p_enable->conidx, p_bass_env->cursor); + + finished = false; + p_bass_env->cursor++; + break; + } + + p_bass_env->cursor++; + } + } + // Battery level updated + else if (p_bass_env->p_operation->id == BASS_BATT_LEVEL_UPD_REQ) + { + struct bass_batt_level_upd_req *p_update = + (struct bass_batt_level_upd_req *) ke_msg2param(p_bass_env->p_operation); + + // loop on all connection + while (p_bass_env->cursor < BLE_CONNECTION_MAX) + { + if ((p_bass_env->ntf_cfg[p_bass_env->cursor] & (1 << p_update->bas_instance)) != 0) + { + // trigger notification + bass_notify_batt_lvl(p_bass_env, p_bass_env->cursor, p_update->bas_instance); + finished = false; + p_bass_env->cursor++; + + break; + } + + p_bass_env->cursor++; + } + } + // default, should not happen + else + { + ASSERT_ERR(0); + } + + // check if operation is finished + if (finished) + { + // trigger response message + if (p_bass_env->p_operation->id == BASS_ENABLE_REQ) + { + struct bass_enable_rsp *p_rsp = KE_MSG_ALLOC(BASS_ENABLE_RSP, p_bass_env->p_operation->src_id, + p_bass_env->p_operation->dest_id, bass_enable_rsp); + + p_rsp->conidx = conidx; + p_rsp->status = GAP_ERR_NO_ERROR; + ke_msg_send(p_rsp); + } + else if (p_bass_env->p_operation->id == BASS_BATT_LEVEL_UPD_REQ) + { + struct bass_batt_level_upd_rsp *p_rsp = KE_MSG_ALLOC(BASS_BATT_LEVEL_UPD_RSP, + p_bass_env->p_operation->src_id, + p_bass_env->p_operation->dest_id, bass_batt_level_upd_rsp); + + p_rsp->status = GAP_ERR_NO_ERROR; + ke_msg_send(p_rsp); + } + + // free operation + ke_free(p_bass_env->p_operation); + p_bass_env->p_operation = NULL; + // go back to idle state + ke_state_set(prf_src_task_get(&(p_bass_env->prf_env), 0), BASS_IDLE); + } +} + + +#endif // (BLE_BATT_SERVER) + +/// @} BASS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass.h new file mode 100644 index 0000000..5ea0030 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass.h @@ -0,0 +1,185 @@ +/** + **************************************************************************************** + * + * @file bass.h + * + * @brief Header file - Battery Service Server Role + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _BASS_H_ +#define _BASS_H_ + +/** + **************************************************************************************** + * @addtogroup BAPS Battery 'Profile' Server + * @ingroup BAP + * @brief Battery 'Profile' Server + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_BATT_SERVER) + +#include "bass_task.h" +#include "prf_types.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + +///Maximum number of Battery Server task instances +#define BASS_IDX_MAX 0x01 + +#define BAS_CFG_FLAG_MANDATORY_MASK (0x07) +#define BAS_CFG_FLAG_NTF_SUP_MASK (0x08) +#define BAS_CFG_FLAG_MTP_BAS_MASK (0x10) + +#define BASS_FLAG_NTF_CFG_BIT (0x02) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the BASS task +enum bass_state +{ + /// Idle state + BASS_IDLE, + /// busy state + BASS_BUSY, + /// Number of defined states. + BASS_STATE_MAX +}; + +/// Battery Service Attributes Indexes +enum +{ + BAS_IDX_SVC, + + BAS_IDX_BATT_LVL_CHAR, + BAS_IDX_BATT_LVL_VAL, + BAS_IDX_BATT_LVL_NTF_CFG, + BAS_IDX_BATT_LVL_PRES_FMT, + + BAS_IDX_NB, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Battery 'Profile' Server environment variable +struct bass_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Battery Level Characteristic Presentation Format - Should not change during connection + struct prf_char_pres_fmt batt_level_pres_format[BASS_NB_BAS_INSTANCES_MAX]; + /// On-going operation + struct ke_msg *p_operation; + /// BAS Services Start Handle + uint16_t start_hdl; + /// Level of the battery + uint8_t batt_lvl[BASS_NB_BAS_INSTANCES_MAX]; + /// BASS task state + ke_state_t state[BASS_IDX_MAX]; + /// Notification configuration of peer devices. + uint8_t ntf_cfg[BLE_CONNECTION_MAX]; + /// Database features + uint8_t features; + /// Number of BAS + uint8_t svc_nb; + /// Cursor on connection used to notify peer devices when battery level changes + uint8_t cursor; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve BAS service profile interface + * + * @return BAS service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *bass_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Retrieve Attribute handle from service and attribute index + * + * @param[in] svc_idx BAS Service index + * @param[in] att_idx Attribute index + * + * @return BAS attribute handle or INVALID HANDLE if nothing found + **************************************************************************************** + */ +uint16_t bass_get_att_handle(uint8_t svc_idx, uint8_t att_idx); + +/** + **************************************************************************************** + * @brief Retrieve Service and attribute index form attribute handle + * + * @param[out] handle Attribute handle + * @param[out] p_svc_idx BAS Service index + * @param[out] p_att_idx Attribute index + * + * @return Success if attribute and service index found, else Application error + **************************************************************************************** + */ +uint8_t bass_get_att_idx(uint16_t handle, uint8_t *p_svc_idx, uint8_t *p_att_idx); + +/** + **************************************************************************************** + * @brief This function fully manage notification of battery level to peer(s) device(s) + * according to on-going operation requested by application: + * - Modification of Battery Level + * - Indicate to a known device that battery level has change + **************************************************************************************** + */ +void bass_exe_operation(void); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void bass_task_init(struct ke_task_desc *p_task_desc); + + +#endif /* #if (BLE_BATT_SERVER) */ + +/// @} BASS + +#endif /* _BASS_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass_task.c new file mode 100644 index 0000000..7ffd511 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/src/bass_task.c @@ -0,0 +1,403 @@ +/** + **************************************************************************************** + * + * @file bass_task.c + * + * @brief Battery Service Server Role Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup BASSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_BATT_SERVER) + +#include "gap.h" +#include "gattc_task.h" + +#include "bass.h" +#include "bass_task.h" + +#include "prf_utils.h" + +#include "co_utils.h" + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BAPS_ENABLE_REQ message. + * The handler enables the Battery 'Profile' Server Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int bass_enable_req_handler(ke_msg_id_t const msgid, + struct bass_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_SAVED; + + // check state of the task + if (ke_state_get(dest_id) == BASS_IDLE) + { + struct bass_env_tag *p_bass_env = PRF_ENV_GET(BASS, bass); + + // Check provided values + if ((p_param->conidx > BLE_CONNECTION_MAX) + || (gapc_get_conhdl(p_param->conidx) == GAP_INVALID_CONHDL)) + { + // an error occurs, trigger it. + struct bass_enable_rsp *p_rsp = KE_MSG_ALLOC(BASS_ENABLE_RSP, src_id, + dest_id, bass_enable_rsp); + + p_rsp->conidx = p_param->conidx; + p_rsp->status = (p_param->conidx > BLE_CONNECTION_MAX) ? GAP_ERR_INVALID_PARAM : PRF_ERR_REQ_DISALLOWED; + ke_msg_send(p_rsp); + + msg_status = KE_MSG_CONSUMED; + } + else + { + // put task in a busy state + msg_status = KE_MSG_NO_FREE; + ke_state_set(dest_id, BASS_BUSY); + p_bass_env->ntf_cfg[p_param->conidx] = p_param->ntf_cfg; + p_bass_env->p_operation = ke_param2msg(p_param); + p_bass_env->cursor = 0; + + // trigger notification + bass_exe_operation(); + } + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BAPS_BATT_LEVEL_SEND_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int bass_batt_level_upd_req_handler(ke_msg_id_t const msgid, + struct bass_batt_level_upd_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_SAVED; + + // check state of the task + if (ke_state_get(dest_id) == BASS_IDLE) + { + struct bass_env_tag *p_bass_env = PRF_ENV_GET(BASS, bass); + + // Check provided values + if ((p_param->bas_instance < p_bass_env->svc_nb) && (p_param->batt_level <= BAS_BATTERY_LVL_MAX)) + { + // update the battery level value + p_bass_env->batt_lvl[p_param->bas_instance] = p_param->batt_level; + + // put task in a busy state + msg_status = KE_MSG_NO_FREE; + ke_state_set(dest_id, BASS_BUSY); + p_bass_env->p_operation = ke_param2msg(p_param); + p_bass_env->cursor = 0; + + // trigger notification + bass_exe_operation(); + } + else + { + // an error occurs, trigger it. + struct bass_batt_level_upd_rsp *p_rsp = KE_MSG_ALLOC(BASS_BATT_LEVEL_UPD_RSP, src_id, + dest_id, bass_batt_level_upd_rsp); + + p_rsp->status = PRF_ERR_INVALID_PARAM; + ke_msg_send(p_rsp); + msg_status = KE_MSG_CONSUMED; + } + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct gattc_att_info_cfm *p_cfm; + uint8_t svc_idx = 0, att_idx = 0; + // retrieve handle information + uint8_t status = bass_get_att_idx(p_param->handle, &svc_idx, &att_idx); + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + if (status == GAP_ERR_NO_ERROR) + { + // check if it's a client configuration char + if (att_idx == BAS_IDX_BATT_LVL_NTF_CFG) + { + // CCC attribute length = 2 + p_cfm->length = 2; + } + // not expected request + else + { + p_cfm->length = 0; + status = ATT_ERR_WRITE_NOT_PERMITTED; + } + } + + p_cfm->status = status; + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + struct gattc_write_cfm *p_cfm; + uint8_t svc_idx = 0, att_idx = 0; + uint8_t conidx = KE_IDX_GET(src_id); + // retrieve handle information + uint8_t status = bass_get_att_idx(p_param->handle, &svc_idx, &att_idx); + + // If the attribute has been found, status is GAP_ERR_NO_ERROR + if (status == GAP_ERR_NO_ERROR) + { + struct bass_env_tag *p_bass_env = PRF_ENV_GET(BASS, bass); + // Extract value before check + uint16_t ntf_cfg = co_read16p(&p_param->value[0]); + + // Only update configuration if value for stop or notification enable + if ((att_idx == BAS_IDX_BATT_LVL_NTF_CFG) + && ((ntf_cfg == PRF_CLI_STOP_NTFIND) || (ntf_cfg == PRF_CLI_START_NTF))) + { + // Inform APP of configuration change + struct bass_batt_level_ntf_cfg_ind *p_ind; + + // Conserve information in environment + if (ntf_cfg == PRF_CLI_START_NTF) + { + // Ntf cfg bit set to 1 + p_bass_env->ntf_cfg[conidx] |= (BAS_BATT_LVL_NTF_SUP << svc_idx); + } + else + { + // Ntf cfg bit set to 0 + p_bass_env->ntf_cfg[conidx] &= ~(BAS_BATT_LVL_NTF_SUP << svc_idx); + } + + p_ind = KE_MSG_ALLOC(BASS_BATT_LEVEL_NTF_CFG_IND, + prf_dst_task_get(&(p_bass_env->prf_env), conidx), dest_id, + bass_batt_level_ntf_cfg_ind); + + p_ind->conidx = conidx; + p_ind->ntf_cfg = p_bass_env->ntf_cfg[conidx]; + + ke_msg_send(p_ind); + } + else + { + status = PRF_APP_ERROR; + } + + } + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + struct gattc_read_cfm *p_cfm; + uint8_t svc_idx = 0, att_idx = 0; + uint8_t conidx = KE_IDX_GET(src_id); + // retrieve handle information + uint8_t status = bass_get_att_idx(p_param->handle, &svc_idx, &att_idx); + uint16_t length = 0; + struct bass_env_tag *p_bass_env = PRF_ENV_GET(BASS, bass); + + // If the attribute has been found, status is GAP_ERR_NO_ERROR + if (status == GAP_ERR_NO_ERROR) + { + // read notification information + if (att_idx == BAS_IDX_BATT_LVL_VAL) + { + length = sizeof(uint8_t); + } + // read notification information + else if (att_idx == BAS_IDX_BATT_LVL_NTF_CFG) + { + length = sizeof(uint16_t); + } + else if (att_idx == BAS_IDX_BATT_LVL_PRES_FMT) + { + length = PRF_CHAR_PRES_FMT_SIZE; + } + else + { + status = PRF_APP_ERROR; + } + } + + //Send write response + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, length); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + p_cfm->length = length; + + if (status == GAP_ERR_NO_ERROR) + { + // read notification information + if (att_idx == BAS_IDX_BATT_LVL_VAL) + { + p_cfm->value[0] = p_bass_env->batt_lvl[svc_idx]; + } + // retrieve notification config + else if (att_idx == BAS_IDX_BATT_LVL_NTF_CFG) + { + uint16_t ntf_cfg = (p_bass_env->ntf_cfg[conidx] >> svc_idx & BAS_BATT_LVL_NTF_SUP) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND; + + co_write16p(p_cfm->value, ntf_cfg); + } + // retrieve battery level format + else if (att_idx == BAS_IDX_BATT_LVL_PRES_FMT) + { + prf_pack_char_pres_fmt(p_cfm->value, &(p_bass_env->batt_level_pres_format[svc_idx])); + } + else + { + // Not Possible + } + } + + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT for GATTC_NOTIFY message meaning that Measurement + * notification has been correctly sent to peer device (but not confirmed by peer device). + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + if(p_param->operation == GATTC_NOTIFY) + { + // continue operation execution + bass_exe_operation(); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(bass) +{ + {BASS_ENABLE_REQ, (ke_msg_func_t) bass_enable_req_handler}, + {BASS_BATT_LEVEL_UPD_REQ, (ke_msg_func_t) bass_batt_level_upd_req_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +void bass_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct bass_env_tag *p_bass_env = PRF_ENV_GET(BASS, bass); + + p_task_desc->msg_handler_tab = bass_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(bass_msg_handler_tab); + p_task_desc->state = p_bass_env->state; + p_task_desc->idx_max = BASS_IDX_MAX; +} + +#endif /* #if (BLE_BATT_SERVER) */ + +/// @} BASSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcs_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcs_common.h new file mode 100644 index 0000000..4b3926c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcs_common.h @@ -0,0 +1,242 @@ +/** + **************************************************************************************** + * + * @file bcs_common.h + * + * @brief Header File - Body Composition Service common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + + +#ifndef _BCS_COMMON_H_ +#define _BCS_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup BCS Body Composition Service + * @ingroup PROFILE + * @brief Body Composition Service + * + * The Body Composition Service enables the user to expose data related to body composition + * from a body composition analyzer (Server) intended for consumer healthcare + * as well as sports/fitness applications. + * + * This file contains all definitions that are common for the server and the client parts + * of the profile. + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "prf_types.h" +#include +#include "co_math.h" + + +/* + * DEFINES + **************************************************************************************** + */ + +/// Indicate Measurement Unsuccessful to the Client +#define BCS_MEAS_UNSUCCESSFUL (0xFFFF) +/// Indicate Unknown User +#define BCS_MEAS_USER_ID_UNKNOWN_USER (0xFF) +/// All features Supported +#define BCS_FEAT_ALL_SUPP (0x000007FF) +/// All valid bits of Flags field (bit [0:12]) +#define BCS_MEAS_FLAGS_VALID (0x1FFF) +/// Feature value length +#define BCS_FEAT_VAL_LEN (4) +/// Measurement CCC length +#define BCS_MEAS_CCC_LEN (2) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// BCS Feature Support bit field +enum bcs_feat_bf +{ + /// Time Stamp Supported + BCS_FEAT_TIME_STAMP_SUPP_POS = 0, + BCS_FEAT_TIME_STAMP_SUPP_BIT = CO_BIT(BCS_FEAT_TIME_STAMP_SUPP_POS), + + /// Multiple Users Supported + BCS_FEAT_MULTIPLE_USERS_SUPP_POS = 1, + BCS_FEAT_MULTIPLE_USERS_SUPP_BIT = CO_BIT(BCS_FEAT_MULTIPLE_USERS_SUPP_POS), + + /// Basal Metabolism Supported + BCS_FEAT_BASAL_METAB_SUPP_POS = 2, + BCS_FEAT_BASAL_METAB_SUPP_BIT = CO_BIT(BCS_FEAT_BASAL_METAB_SUPP_POS), + + /// Muscle percentate supported + BCS_FEAT_MUSCLE_PERCENTAGE_SUPP_POS = 3, + BCS_FEAT_MUSCLE_PERCENTAGE_SUPP_BIT = CO_BIT(BCS_FEAT_MUSCLE_PERCENTAGE_SUPP_POS), + + /// Muscle mass supported + BCS_FEAT_MUSCLE_MASS_SUPP_POS = 4, + BCS_FEAT_MUSCLE_MASS_SUPP_BIT = CO_BIT(BCS_FEAT_MUSCLE_MASS_SUPP_POS), + + /// Fat Free mass Supported + BCS_FEAT_FAT_FREE_MASS_SUPP_POS = 5, + BCS_FEAT_FAT_FREE_MASS_SUPP_BIT = CO_BIT(BCS_FEAT_FAT_FREE_MASS_SUPP_POS), + + /// Soft lean mass Supported + BCS_FEAT_SOFT_LEAN_MASS_SUPP_POS = 6, + BCS_FEAT_SOFT_LEAN_MASS_SUPP_BIT = CO_BIT(BCS_FEAT_SOFT_LEAN_MASS_SUPP_POS), + + /// Body Water Mass Supported + BCS_FEAT_BODY_WATER_MASS_SUPP_POS = 7, + BCS_FEAT_BODY_WATER_MASS_SUPP_BIT = CO_BIT(BCS_FEAT_BODY_WATER_MASS_SUPP_POS), + + /// Impedance Supported + BCS_FEAT_IMPEDANCE_SUPP_POS = 8, + BCS_FEAT_IMPEDANCE_SUPP_BIT = CO_BIT(BCS_FEAT_IMPEDANCE_SUPP_POS), + + /// Weight Supported + BCS_FEAT_WEIGHT_SUPP_POS = 9, + BCS_FEAT_WEIGHT_SUPP_BIT = CO_BIT(BCS_FEAT_WEIGHT_SUPP_POS), + + /// Height Supported + BCS_FEAT_HEIGHT_SUPP_POS = 10, + BCS_FEAT_HEIGHT_SUPP_BIT = CO_BIT(BCS_FEAT_HEIGHT_SUPP_POS), + + /// Mass Measurement Resolution bit field (bits[11:14]) + BCS_FEAT_MASS_RESOL_LSB = 11, + BCS_FEAT_MASS_RESOL_MASK = 0x00007800, + + /// Height Measurement Resolution bit field (bits[15:17]) + BCS_FEAT_HGHT_RESOL_LSB = 15, + BCS_FEAT_HGHT_RESOL_MASK = 0x00038000, +}; + +/// BCS Feature Measurement Mass Resolution values +enum bcs_feat_mass_resol_value +{ + /// Mass Measurement Resolution not specified + BCS_MASS_RESOL_NOT_SPECIFIED = 0, + /// Resolution of 0.5 kg or 1 lb + BCS_MASS_RESOL_05kg_1lb = 1, + /// Resolution of 0.2 kg or 0.5 lb + BCS_MASS_RESOL_02kg_05lb = 2, + /// Resolution of 0.1 kg or 0.2 lb + BCS_MASS_RESOL_01kg_02lb = 3, + /// Resolution of 0.05 kg or 0.1 lb + BCS_MASS_RESOL_005kg_01lb = 4, + /// Resolution of 0.02 kg or 0.05 lb + BCS_MASS_RESOL_002kg_005lb = 5, + /// Resolution of 0.01 kg or 0.02 lb + BCS_MASS_RESOL_001kg_002lb = 6, + /// Resolution of 0.005 kg or 0.01 lb + BCS_MASS_RESOL_0005kg_001lb = 7, + /// Reserved for future use bit 8 - 15 +}; + +/// BCS Feature Measurement Height Resolution values +enum bcs_feat_hght_resol_value +{ + /// Height Measurement Resolution not specified + BCS_HGHT_RESOL_NOT_SPECIFIED = 0, + /// Resolution of 0.01 meter or 1 inch + BCS_HGHT_RESOL_001mtr_1inch = 1, + /// Resolution of 0.005 meter or 0.5 inch + BCS_HGHT_RESOL_0005mtr_05inch = 2, + /// Resolution of 0.001 meter or 0.1 inch + BCS_HGHT_RESOL_0001mtr_01inch = 3, + /// Reserved for future use bit 8 - 15 +}; + +/// BCS Measurement Flags bit field +enum bcs_meas_flags_bf +{ + /// Measurement Units (bit 0) + /// 0 for SI (Weight and Mass in units of kilogram (kg) and Height in units of meter) + /// 1 for Imperial (Weight and Mass in units of pound (lb) and Height in units of inch (in)) + BCS_MEAS_FLAGS_UNITS_IMPERIAL_POS = 0, + BCS_MEAS_FLAGS_UNITS_IMPERIAL_BIT = CO_BIT(BCS_MEAS_FLAGS_UNITS_IMPERIAL_POS), + + /// Time stamp present (bit 1) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_TIMESTAMP_PRESENT_POS = 1, + BCS_MEAS_FLAGS_TIMESTAMP_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_TIMESTAMP_PRESENT_POS), + + /// User ID present (bit 2) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_USER_ID_PRESENT_POS = 2, + BCS_MEAS_FLAGS_USER_ID_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_USER_ID_PRESENT_POS), + + /// Basal Metabolism present (bit 3) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_BASAL_METAB_PRESENT_POS = 3, + BCS_MEAS_FLAGS_BASAL_METAB_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_BASAL_METAB_PRESENT_POS), + + /// Muscle Percentage present (bit 4) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_MUSCLE_PERCENT_PRESENT_POS = 4, + BCS_MEAS_FLAGS_MUSCLE_PERCENT_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_MUSCLE_PERCENT_PRESENT_POS), + + /// Muscle Mass present (bit 5) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_MUSCLE_MASS_PRESENT_POS = 5, + BCS_MEAS_FLAGS_MUSCLE_MASS_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_MUSCLE_MASS_PRESENT_POS), + + /// Fat Free Mass present (bit 6) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_FAT_FREE_MASS_PRESENT_POS = 6, + BCS_MEAS_FLAGS_FAT_FREE_MASS_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_FAT_FREE_MASS_PRESENT_POS), + + /// Soft Lean Mass present (bit 7) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_SOFT_LEAN_MASS_PRESENT_POS = 7, + BCS_MEAS_FLAGS_SOFT_LEAN_MASS_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_SOFT_LEAN_MASS_PRESENT_POS), + + /// Body Water Mass present (bit 8) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_BODY_WATER_MASS_PRESENT_POS = 8, + BCS_MEAS_FLAGS_BODY_WATER_MASS_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_BODY_WATER_MASS_PRESENT_POS), + + /// Impedance present (bit 9) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_IMPEDANCE_PRESENT_POS = 9, + BCS_MEAS_FLAGS_IMPEDANCE_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_IMPEDANCE_PRESENT_POS), + + /// Weight present (bit 10) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_WEIGHT_PRESENT_POS = 10, + BCS_MEAS_FLAGS_WEIGHT_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_WEIGHT_PRESENT_POS), + + /// Height present (bit 11) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_HEIGHT_PRESENT_POS = 11, + BCS_MEAS_FLAGS_HEIGHT_PRESENT_BIT = CO_BIT(BCS_MEAS_FLAGS_HEIGHT_PRESENT_POS), + + /// Multiple packet Measurement (bit 12) + /// 0 for not present + /// 1 for present + BCS_MEAS_FLAGS_MULTIPACKET_MEAS_POS = 12, + BCS_MEAS_FLAGS_MULTIPACKET_MEAS_BIT = CO_BIT(BCS_MEAS_FLAGS_MULTIPACKET_MEAS_POS), +}; + +/// @} bcs_common + +#endif // (_BCS_COMMON_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/api/bcsc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/api/bcsc_task.h new file mode 100644 index 0000000..0fd7125 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/api/bcsc_task.h @@ -0,0 +1,222 @@ +/** + **************************************************************************************** + * + * @file bcsc_task.h + * + * @brief Header file - Body Composition Service Collector/Client Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _BCSC_TASK_H_ +#define _BCSC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup BCSC Body Composition Service Collector Task + * @ingroup BCSC + * @brief Body Composition Service Collector + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" +#include "bcs_common.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Message IDs +/*@TRACE*/ +enum bcsc_msg_ids +{ + /// Enable the Profile Collector task - at connection + BCSC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_BCSC), + /// Response to Enable the Profile Collector task - at connection + BCSC_ENABLE_RSP, + /// Read the Body Composition Feature + BCSC_RD_FEAT_CMD, + /// Read the CCC of a measurement sensor characteristic + BCSC_RD_MEAS_CCC_CMD, + /// Write the CCC of a measurement sensor characteristic + BCSC_WR_MEAS_CCC_CMD, + /// Read the Body Composition Feature + BCSC_FEAT_IND, + /// Read the CCC of a measurement sensor characteristic + BCSC_MEAS_CCC_IND, + /// Characteristic Measurement Indication from peer + BCSC_MEAS_IND, + /// Complete Event Information + BCSC_CMP_EVT, +}; + +/// Body Composition Service Characteristics +enum bcsc_chars +{ + /// Body Composition Feature + BCSC_CHAR_BCS_FEATURE, + /// Body Composition Measurement + BCSC_CHAR_BCS_MEAS, + + BCSC_CHAR_BCS_MAX, +}; + +/// Body Composition Service Characteristic Descriptors +enum bcsc_descs +{ + /// Client config + BCSC_DESC_BCS_MEAS_CCC, + + BCSC_DESC_BCS_MAX, +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Body Composition Service + */ +struct bcsc_bcs_content +{ + /// service info + struct prf_svc svc; + + /// Characteristic info: + /// - Feature + /// - Measurement + struct prf_char_inf chars[BCSC_CHAR_BCS_MAX]; + + /// Descriptor handles: + /// - Client cfg + struct prf_char_desc_inf descs[BCSC_DESC_BCS_MAX]; +}; + +/// Parameters of the @ref BCSC_ENABLE_REQ message +struct bcsc_enable_req +{ + /// Connection type + uint8_t con_type; + + /// Primary or Secondary Service + uint8_t svc_type; + + /// If Secondary Service - the Start and End Handle for the service are contained + /// in the bcs. + + /// Existing handle values of BCS + struct bcsc_bcs_content bcs; + +}; + +/// Parameters of the @ref BCSC_ENABLE_RSP message +struct bcsc_enable_rsp +{ + /// status + uint8_t status; + /// handle values of BCS + struct bcsc_bcs_content bcs; +}; + +/// Parameters of the @ref BCSC_RD_FEAT_CMD message +/// Read the Body Composition Feature +struct bcsc_rd_feat_cmd +{ + /// NULL +}; + +/// Parameters of the @ref BCSC_RD_MEAS_CCC_CMD message +/// Read the CCC of a measurement sensor characteristic +struct bcsc_rd_meas_ccc_cmd +{ + /// NULL +}; + +/// Parameters of the @ref BCSC_WR_MEAS_CCC_CMD message +/// Write the CCC of a measurement sensor characteristic +struct bcsc_wr_meas_ccc_cmd +{ + /// Client Characteristic Configuration written value + uint16_t ccc; +}; + +/// Parameters of the @ref BCSC_FEAT_IND message +/// Read the Body Composition Feature +struct bcsc_feat_ind +{ + /// Body Composition Feature read value + uint32_t feature; +}; + +/// Parameters of the @ref BCSC_MEAS_CCC_IND message +/// Read the CCC of a measurement sensor characteristic +struct bcsc_meas_ccc_ind +{ + /// Client Characteristic Configuration read value + uint16_t ccc; +}; + +/// Parameters of the @ref BCSC_MEAS_IND message +/// Characteristic Measurement Indication from peer +struct bcsc_meas_ind +{ + /// Presence of optional fields and measurement units + uint16_t flags; + /// Body fat percentage value + uint16_t body_fat_percent; + /// Measurement Units + uint8_t meas_u; + /// Time stamp value + struct prf_date_time time_stamp; + /// User ID value + uint8_t user_id; + /// Basal Metabolism value + uint16_t basal_metab; + /// Muscle Percentage value + uint16_t muscle_percent; + /// Muscle Mass value + uint16_t muscle_mass; + /// Fat Free Mass value + uint16_t fat_free_mass; + /// Soft Lean Mass value + uint16_t soft_lean_mass; + /// Body Water Mass value + uint16_t body_water_mass; + /// Impedance Value + uint16_t impedance; + /// Weight value + uint16_t weight; + /// Mass Resolution + uint8_t mass_resol; + /// Height value + uint16_t height; + /// Height Resolution + uint8_t hght_resol; +}; + +/// Parameters of the @ref BCSC_CMP_EVT message +struct bcsc_cmp_evt +{ + /// Operation code + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} BCSC TASK + +#endif //(_BCSC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/sourcelist.txt new file mode 100644 index 0000000..9a8de3c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2016 +# +#*************************************************************************************** + + bcsc.c + bcsc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/src/bcsc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/src/bcsc.c new file mode 100644 index 0000000..7be0667 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/src/bcsc.c @@ -0,0 +1,243 @@ +/** + **************************************************************************************** + * + * @file bcsc.c + * + * @brief Body Composition Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup BCSC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_BCS_CLIENT) +#include "prf.h" +#include "bcs_common.h" + +#include "bcsc_task.h" +#include "bcsc.h" +#include "gap.h" + +#include "ke_mem.h" + +/* + * GLOBAL VARIABLES DECLARATION + **************************************************************************************** + */ + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the BCSC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t bcsc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct bcsc_env_tag *p_bcsc_env = + (struct bcsc_env_tag *) ke_malloc(sizeof(struct bcsc_env_tag), KE_MEM_ATT_DB); + + // allocate BCSC required environment variable + p_env->env = (prf_env_t *) p_bcsc_env; + + p_bcsc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_bcsc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_BCSC; + bcsc_task_init(&(p_env->desc)); + + for(idx = 0; idx < BCSC_IDX_MAX; idx++) + { + p_bcsc_env->env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), BCSC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void bcsc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct bcsc_env_tag *p_bcsc_env = (struct bcsc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if(p_bcsc_env->env[conidx] != NULL) + { + if (p_bcsc_env->env[conidx]->meas_evt_msg != 0) + { + ke_msg_free(p_bcsc_env->env[conidx]->meas_evt_msg); + } + + ke_free(p_bcsc_env->env[conidx]); + p_bcsc_env->env[conidx] = NULL; + } + + /* Put BSC Client in Free state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), BCSC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the BCSC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void bcsc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct bcsc_env_tag *p_bcsc_env = (struct bcsc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for(idx = 0; idx < BCSC_IDX_MAX ; idx++) + { + bcsc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_bcsc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void bcsc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + /* Put BCS Client in Idle state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), BCSC_IDLE); +} + +/// BCSC Task interface required by profile manager +const struct prf_task_cbs bcsc_itf = +{ + bcsc_init, + bcsc_destroy, + bcsc_create, + bcsc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* bcsc_prf_itf_get(void) +{ + return &bcsc_itf; +} + +void bcsc_enable_rsp_send(struct bcsc_env_tag *p_bcsc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on BCSC + struct bcsc_enable_rsp *p_rsp = KE_MSG_ALLOC( + BCSC_ENABLE_RSP, + prf_dst_task_get(&(p_bcsc_env->prf_env), conidx), + prf_src_task_get(&(p_bcsc_env->prf_env), conidx), + bcsc_enable_rsp); + + p_rsp->status = status; + p_bcsc_env->env[conidx]->meas_evt_msg = 0; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->bcs = p_bcsc_env->env[conidx]->bcs; + + // Register BCSC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_bcsc_env->prf_env), conidx, &(p_bcsc_env->env[conidx]->bcs.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_bcsc_env->prf_env), conidx), BCSC_BUSY); + } + else + { + memset(&p_rsp->bcs, 0 , sizeof(p_rsp->bcs)); + // Enabled failed - so go back to the FREE state + ke_state_set(prf_src_task_get(&(p_bcsc_env->prf_env), conidx), BCSC_FREE); + } + + ke_msg_send(p_rsp); +} + +void bcsc_send_cmp_evt(struct bcsc_env_tag *p_bcsc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct bcsc_cmp_evt *p_evt = NULL; + + // Go back to the CONNECTED state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_bcsc_env->prf_env), conidx)) == BCSC_BUSY) + { + ke_state_set(prf_src_task_get(&(p_bcsc_env->prf_env), conidx), BCSC_IDLE); + } + + p_bcsc_env->env[conidx]->op_pending = 0; + // Send the message + p_evt = KE_MSG_ALLOC(BCSC_CMP_EVT,prf_dst_task_get(&(p_bcsc_env->prf_env), conidx), + prf_src_task_get(&(p_bcsc_env->prf_env), conidx), + bcsc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //(BLE_BCS_CLIENT) + +/// @} BCSC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/src/bcsc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/src/bcsc.h new file mode 100644 index 0000000..2d5421d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/src/bcsc.h @@ -0,0 +1,181 @@ +/** + **************************************************************************************** + * + * @file bcsc.h + * + * @brief Header file - Body composition service - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _BCSC_H_ +#define _BCSC_H_ + +/** + **************************************************************************************** + * @addtogroup BCSC Body Composition Service Collector + * @ingroup BCSC + * @brief Body Composition Service Collector + * @{ + **************************************************************************************** + */ + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Body Composition instances +#define BCSC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "bcs_common.h" + +#if (BLE_BCS_CLIENT) + +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the BCSC task +enum bcsc_states +{ + /// Idle state + BCSC_FREE, + /// Connected state + BCSC_IDLE, + /// Discovering Services + BCSC_DISCOVERING_SVC, + /// Discovering Characteristics + BCSC_DISCOVERING_CHARS, + /// Discovering Characteristic Descriptors + BCSC_DISCOVERING_CHAR_DESC, + /// Busy state + BCSC_BUSY, + /// Number of defined states. + BCSC_STATE_MAX +}; + +/// Operation Codes for pending operations in the client. +enum bcsc_op_codes +{ + /// Read feature operation code + BCSC_READ_FEAT_OP_CODE = 0, + /// Read CCC operation code + BCSC_READ_CCC_OP_CODE = 1, + /// Write CCC operation codes + BCSC_WRITE_CCC_OP_CODE = 2, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Stored Environment content/context information for a connection +struct bcsc_cnx_env +{ + /// Current Operation + uint8_t op_pending; + + /// Counter used to check service uniqueness + uint8_t nb_svc; + + /// Store the @ref bcsc_meas_ind param when Multipacket presents + struct ke_msg* meas_evt_msg; + + /// Current Operation + void *operation; + + /// Weight Scale Service Characteristics + struct bcsc_bcs_content bcs; +}; + +/// BCSC environment variable +struct bcsc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct bcsc_cnx_env* env[BCSC_IDX_MAX]; + /// State of different task instances + ke_state_t state[BCSC_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Pool of Environmental Profile Collector task environments. +extern struct bcsc_env_tag **bcsc_envs; + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve Body Compistion serice client interface + * + * @return Body Composition client interface + **************************************************************************************** + */ +const struct prf_task_cbs* bcsc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Body Composition ATT DB discovery results to BCSC host. + * + * @param[in] p_bcsc_env The profile environment for the connection + * @param[in] conidx Connection Identifier + * @param[in] status Indicates the outcome of the operation + **************************************************************************************** + */ +void bcsc_enable_rsp_send(struct bcsc_env_tag *p_bcsc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send a BCSC_CMP_EVT message to the task which enabled the profile + * + * @param[in] p_bcsc_env The profile environment + * @param[in] conidx Connection Identifier + * @param[in] operation Indicates the operation for which the cmp_evt is being sent. + * @param[in] status Indicates the outcome of the operation + **************************************************************************************** + */ +void bcsc_send_cmp_evt(struct bcsc_env_tag *p_bcsc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void bcsc_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_BCS_CLIENT) + +/// @} BCSC + +#endif //(_BCSC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/src/bcsc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/src/bcsc_task.c new file mode 100644 index 0000000..8e33b30 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcsc/src/bcsc_task.c @@ -0,0 +1,1052 @@ +/** + **************************************************************************************** + * + * @file bcsc_task.c + * + * @brief Body Composition Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup BCSCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_BCS_CLIENT) +#include "bcs_common.h" +#include "bcsc_task.h" +#include "bcsc.h" + +#include "gap.h" +#include "attm.h" +#include "gattc_task.h" +#include "ke_mem.h" +#include "co_utils.h" + + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve Body Composition Service characteristics information +const struct prf_char_def bcsc_bcs_char[BCSC_CHAR_BCS_MAX] = +{ + [BCSC_CHAR_BCS_FEATURE] = {ATT_CHAR_BODY_COMPOSITION_FEATURE, + ATT_MANDATORY, + (ATT_CHAR_PROP_RD ) }, + + [BCSC_CHAR_BCS_MEAS] = {ATT_CHAR_BODY_COMPOSITION_MEASUREMENT, + ATT_MANDATORY, + (ATT_CHAR_PROP_IND) }, +}; + +/// State machine used to retrieve Body Composition Service characteristic description information +const struct prf_char_desc_def bcsc_bcs_char_desc[BCSC_DESC_BCS_MAX] = +{ + /// Client config + [BCSC_DESC_BCS_MEAS_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + BCSC_CHAR_BCS_MEAS}, +}; + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == BCSC_DISCOVERING_SVC) + { + // Body Composition Client Role Task Environment + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_bcsc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_bcsc_env->env[conidx] != NULL, dest_id, src_id); + + if(attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_BODY_COMPOSITION)) + { + // Retrieve BCS characteristics and descriptors + prf_extract_svc_info(p_ind, BCSC_CHAR_BCS_MAX, &bcsc_bcs_char[0], &p_bcsc_env->env[conidx]->bcs.chars[0], + BCSC_DESC_BCS_MAX, &bcsc_bcs_char_desc[0], &p_bcsc_env->env[conidx]->bcs.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_bcsc_env->env[conidx]->bcs.svc.shdl = p_ind->start_hdl; + p_bcsc_env->env[conidx]->bcs.svc.ehdl = p_ind->end_hdl; + + p_bcsc_env->env[conidx]->nb_svc++; + } + + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_DISC_CHAR_IND message. + * The handler stores the found characteristic details. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int gattc_disc_char_ind_handler(ke_msg_id_t const msgid, + struct gattc_disc_char_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == BCSC_DISCOVERING_CHARS) + { + uint8_t i; + uint8_t conidx = KE_IDX_GET(dest_id); + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + + ASSERT_INFO(p_bcsc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_bcsc_env->env[conidx] != NULL, dest_id, src_id); + + for(i = 0; i < BCSC_CHAR_BCS_MAX; i++) + { + uint16_t uuid = co_read16p(&p_ind->uuid[0]); + + if ((bcsc_bcs_char[i].uuid == uuid) && (p_ind->prop == bcsc_bcs_char[i].prop_mand)) + { + p_bcsc_env->env[conidx]->bcs.chars[i].char_hdl = p_ind->attr_hdl; + p_bcsc_env->env[conidx]->bcs.chars[i].val_hdl = p_ind->pointer_hdl; + p_bcsc_env->env[conidx]->bcs.chars[i].prop = p_ind->prop; + + // If Body Composition Feature - then End Handle == val_hdl. + // The end handle for the Body Composition Measurement is written after the discovery of the CCC. + if (uuid == ATT_CHAR_BODY_COMPOSITION_FEATURE) + { + p_bcsc_env->env[conidx]->bcs.chars[BCSC_CHAR_BCS_FEATURE].char_ehdl_off = + p_ind->pointer_hdl - p_ind->attr_hdl; + } + } + } + } + + return (KE_MSG_CONSUMED); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_DISC_CHAR_DESC_IND message. + * The handler stores the found descriptor details for a given characteristic. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int gattc_disc_char_desc_ind_handler(ke_msg_id_t const msgid, + struct gattc_disc_char_desc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == BCSC_DISCOVERING_CHAR_DESC) + { + uint8_t i; + uint8_t conidx = KE_IDX_GET(dest_id); + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + + ASSERT_INFO(p_bcsc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_bcsc_env->env[conidx] != NULL, dest_id, src_id); + + for (i = 0; i < BCSC_DESC_BCS_MAX; i++) + { + uint16_t uuid = co_read16p(&p_ind->uuid[0]); + + if (bcsc_bcs_char_desc[i].uuid == uuid) + { + p_bcsc_env->env[conidx]->bcs.descs[i].desc_hdl = p_ind->attr_hdl; + + if (uuid == ATT_DESC_CLIENT_CHAR_CFG) + { + // This is the end handle of the Body Measurement Characteristic + if (p_ind->attr_hdl) + { + p_bcsc_env->env[conidx]->bcs.chars[BCSC_CHAR_BCS_MEAS].char_ehdl_off = + p_ind->attr_hdl - p_bcsc_env->env[conidx]->bcs.chars[BCSC_CHAR_BCS_MEAS].char_hdl; + } + } + } + } + } + + return (KE_MSG_CONSUMED); +} +/** + **************************************************************************************** + * @brief Handles reception of the @ref BCSC_ENABLE_REQ message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int bcsc_enable_req_handler(ke_msg_id_t const msgid, + struct bcsc_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + // Body Composition Collector Role Task Environment + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + + ASSERT_INFO(p_bcsc_env != NULL, dest_id, src_id); + if ((state == BCSC_IDLE) && (p_bcsc_env->env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_bcsc_env->env[conidx] = (struct bcsc_cnx_env *) ke_malloc(sizeof(struct bcsc_cnx_env), KE_MEM_ATT_DB); + memset(p_bcsc_env->env[conidx], 0, sizeof(struct bcsc_cnx_env)); + + // Start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + if (p_param->svc_type != PRF_SECONDARY_SERVICE) + { + // Start discovery with Body Composition + prf_disc_svc_send(&(p_bcsc_env->prf_env), conidx, ATT_SVC_BODY_COMPOSITION); + + // Go to DISCOVERING SERVICE state + ke_state_set(dest_id, BCSC_DISCOVERING_SVC); + } + else + { + // The Start and End Handle of the service are provided as Params. + if ((p_param->bcs.svc.shdl) && (p_param->bcs.svc.ehdl)) + { + struct gattc_disc_cmd * p_char_disc = NULL; + + p_bcsc_env->env[conidx]->bcs.svc.shdl = p_param->bcs.svc.shdl; + p_bcsc_env->env[conidx]->bcs.svc.ehdl = p_param->bcs.svc.ehdl; + + // Need to Kick Start off the - Discovery of the Chars and Descriptors. + // Send a Characteristic Discovery + p_char_disc = KE_MSG_ALLOC_DYN(GATTC_DISC_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + prf_src_task_get(&(p_bcsc_env->prf_env), conidx), + gattc_disc_cmd, ATT_UUID_16_LEN); + + p_char_disc->operation = GATTC_DISC_ALL_CHAR; + p_char_disc->start_hdl = p_bcsc_env->env[conidx]->bcs.svc.shdl; + p_char_disc->end_hdl = p_bcsc_env->env[conidx]->bcs.svc.ehdl; + p_char_disc->uuid_len = ATT_UUID_16_LEN; + memset(p_char_disc->uuid, 0, ATT_UUID_16_LEN); + + ke_msg_send(p_char_disc); + // Go to DISCOVERING state + ke_state_set(dest_id, BCSC_DISCOVERING_CHARS); + } + else + { + bcsc_enable_rsp_send(p_bcsc_env, conidx, PRF_ERR_INEXISTENT_HDL); + } + } + } + // normal connection, get saved att details + else + { + p_bcsc_env->env[conidx]->bcs = p_param->bcs; + p_bcsc_env->env[conidx]->meas_evt_msg = 0; + bcsc_enable_rsp_send(p_bcsc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != BCSC_FREE) + { + // The message will be forwarded towards the good task instance + status = PRF_ERR_REQ_DISALLOWED; + } + + if (status != GAP_ERR_NO_ERROR) + { + // The request is disallowed (profile already enabled for this connection, or not enough memory, ...) + bcsc_enable_rsp_send(p_bcsc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BCSC_RD_FEAT_CMD message from the application. + * @brief To read the Feature Characteristic in the peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int bcsc_rd_feat_cmd_handler(ke_msg_id_t const msgid, + struct bcsc_rd_feat_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == BCSC_IDLE) + { + ASSERT_INFO(p_bcsc_env != NULL, dest_id, src_id); + // environment variable not ready + if(p_bcsc_env->env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = p_bcsc_env->env[conidx]->bcs.chars[BCSC_CHAR_BCS_FEATURE].val_hdl; + // Service + struct prf_svc *p_svc = &p_bcsc_env->env[conidx]->bcs.svc; + + // Check if handle is viable + if ((search_hdl != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_bcsc_env->env[conidx]->op_pending = BCSC_READ_FEAT_OP_CODE; + // Send read request + prf_read_char_send(&(p_bcsc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, BCSC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == BCSC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + bcsc_send_cmp_evt(p_bcsc_env, conidx, BCSC_READ_FEAT_OP_CODE, status); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BCSC_RD_MEAS_CCC_CMD message from the application. + * @brief To read the CCC value of the Measurement characteristic in the peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int bcsc_rd_meas_ccc_cmd_handler(ke_msg_id_t const msgid, + struct bcsc_rd_meas_ccc_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == BCSC_IDLE) + { + ASSERT_INFO(p_bcsc_env != NULL, dest_id, src_id); + // environment variable not ready + if(p_bcsc_env->env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = p_bcsc_env->env[conidx]->bcs.descs[BCSC_DESC_BCS_MEAS_CCC].desc_hdl; + // Service + struct prf_svc *p_svc = &p_bcsc_env->env[conidx]->bcs.svc; + + // Check if handle is viable + if ((search_hdl != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_bcsc_env->env[conidx]->op_pending = BCSC_READ_CCC_OP_CODE; + // Send read request + prf_read_char_send(&(p_bcsc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, BCSC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + bcsc_send_cmp_evt(p_bcsc_env, conidx, BCSC_READ_CCC_OP_CODE, status); + } + } + else if (state == BCSC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + bcsc_send_cmp_evt(p_bcsc_env, conidx, BCSC_READ_CCC_OP_CODE, status); + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BCSC_WR_MEAS_CCC_CMD message. + * Allows the application to write new CCC values to a Characteristic in the peer server + * + * @param[in] msgid Id of the message received. + * @param[in] p_cmd Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int bcsc_wr_meas_ccc_cmd_handler(ke_msg_id_t const msgid, + struct bcsc_wr_meas_ccc_cmd *p_cmd, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Get the address of the environment + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + // Get connection index + + if (state == BCSC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_bcsc_env != NULL, dest_id, src_id); + // environment variable not ready + if(p_bcsc_env->env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t handle = p_bcsc_env->env[conidx]->bcs.descs[BCSC_DESC_BCS_MEAS_CCC].desc_hdl; + // Service + struct prf_svc *p_svc = &p_bcsc_env->env[conidx]->bcs.svc; + + // Check if handle is viable + if ((handle != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_bcsc_env->env[conidx]->op_pending = BCSC_WRITE_CCC_OP_CODE; + + // Send the write request + prf_gatt_write_ntf_ind(&(p_bcsc_env->prf_env), conidx, handle, p_cmd->ccc); + + // Go to the Busy state + ke_state_set(dest_id, BCSC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + bcsc_send_cmp_evt(p_bcsc_env, conidx, BCSC_WRITE_CCC_OP_CODE, status); + } + } + else if (state == BCSC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + + if (p_bcsc_env != NULL) + { + // Status + uint8_t status; + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == BCSC_DISCOVERING_SVC) + { + if ((p_param->status == GAP_ERR_NO_ERROR) || (p_param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)) + { + // Check service (if found) + if(p_bcsc_env->env[conidx]->nb_svc) + { + // Check service (mandatory) + status = prf_check_svc_char_validity(BCSC_CHAR_BCS_MAX, + p_bcsc_env->env[conidx]->bcs.chars, + bcsc_bcs_char); + + // Check Descriptors (mandatory) + if(status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(BCSC_DESC_BCS_MAX, + p_bcsc_env->env[conidx]->bcs.descs, + bcsc_bcs_char_desc, + p_bcsc_env->env[conidx]->bcs.chars); + } + } + } + + // Raise an ESP_ENABLE_REQ complete event. + ke_state_set(dest_id, BCSC_IDLE); + + bcsc_enable_rsp_send(p_bcsc_env, conidx, p_param->status); + } + else if (state == BCSC_DISCOVERING_CHARS) + { + // Finished Characteristic Discovery - move onto Descriptor Discovery + if ((p_param->status == GAP_ERR_NO_ERROR) || (p_param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)) + { + // Send a Descriptor Discovery + struct gattc_disc_cmd *p_desc_disc = + KE_MSG_ALLOC_DYN(GATTC_DISC_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + prf_src_task_get(&(p_bcsc_env->prf_env), conidx), + gattc_disc_cmd, ATT_UUID_16_LEN); + + p_desc_disc->operation = GATTC_DISC_DESC_CHAR; + p_desc_disc->start_hdl = p_bcsc_env->env[conidx]->bcs.svc.shdl+1; + p_desc_disc->end_hdl = p_bcsc_env->env[conidx]->bcs.svc.ehdl; + p_desc_disc->uuid_len = ATT_UUID_16_LEN; + + memset(p_desc_disc->uuid, 0, ATT_UUID_16_LEN); + + // Reset the Char_Idx back to zero. So Descriptor discovery begins at the first char. + //envc_env->env[conidx]->char_idx = 0; + ke_msg_send(p_desc_disc); + + ke_state_set(dest_id, BCSC_DISCOVERING_CHAR_DESC); + } + else + { + // Send an BCSC_ENABLE_RSP . + ke_state_set(dest_id, BCSC_IDLE); + bcsc_enable_rsp_send(p_bcsc_env, conidx, p_param->status); + } + } + else if (state == BCSC_DISCOVERING_CHAR_DESC) + { + // Raise an ESP_ENABLE_REQ complete event. + ke_state_set(dest_id, BCSC_IDLE); + + if (p_param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND) + { + bcsc_enable_rsp_send(p_bcsc_env, conidx, GAP_ERR_NO_ERROR); + } + else + { + bcsc_enable_rsp_send(p_bcsc_env, conidx, p_param->status); + } + } + else if (state == BCSC_BUSY) + { + uint8_t op_pending = p_bcsc_env->env[conidx]->op_pending; + + status = p_param->status; + switch (p_param->operation) + { + case GATTC_READ: + { + switch(op_pending) + { + case BCSC_READ_FEAT_OP_CODE: + case BCSC_READ_CCC_OP_CODE: + { + bcsc_send_cmp_evt(p_bcsc_env, conidx, op_pending, status); + } + break; + + default: + { + break; + } + } + ke_state_set(dest_id, BCSC_IDLE); + } break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + // Send the complete event status + bcsc_send_cmp_evt(p_bcsc_env, conidx, op_pending, status); + ke_state_set(dest_id, BCSC_IDLE); + + } break; + + case GATTC_REGISTER: + { + if (status != GAP_ERR_NO_ERROR) + { + // Send the complete event error status + bcsc_send_cmp_evt(p_bcsc_env, conidx, GATTC_REGISTER, status); + } + // Go to connected state + ke_state_set(dest_id, BCSC_IDLE); + } break; + + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == BCSC_BUSY) + { + // Get the address of the environment + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t op_pending; + + ASSERT_INFO(p_bcsc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_bcsc_env->env[conidx] != NULL, dest_id, src_id); + + // Find the op_pending - and check it is a valid read code. + op_pending = p_bcsc_env->env[conidx]->op_pending; + if ((op_pending == BCSC_READ_FEAT_OP_CODE) || (op_pending == BCSC_READ_CCC_OP_CODE)) + { + switch (op_pending) + { + case BCSC_READ_FEAT_OP_CODE: + { + struct bcsc_feat_ind *p_ind = KE_MSG_ALLOC(BCSC_FEAT_IND, + prf_dst_task_get(&(p_bcsc_env->prf_env), conidx), + dest_id, + bcsc_feat_ind); + + p_ind->feature = co_read32p(&p_param->value[0]); + + ke_msg_send(p_ind); + } + break; + + case BCSC_READ_CCC_OP_CODE : + { + struct bcsc_meas_ccc_ind *p_ind = KE_MSG_ALLOC(BCSC_MEAS_CCC_IND, + prf_dst_task_get(&(p_bcsc_env->prf_env), conidx), + dest_id, + bcsc_meas_ccc_ind); + + p_ind->ccc = co_read16p(&p_param->value[0]); + + ke_msg_send(p_ind); + } + break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + + if (p_bcsc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + switch (p_param->type) + { + case (GATTC_INDICATE): + { + // confirm that indication has been correctly received + struct gattc_event_cfm *p_cfm = NULL; + + if (p_param->handle == p_bcsc_env->env[conidx]->bcs.chars[BCSC_CHAR_BCS_MEAS].val_hdl) + { + //indication Build a BCSC_MEAS_IND message + uint8_t *p_val; + struct bcsc_meas_ind *p_ind = NULL; + uint16_t flags; + uint8_t second_segment_of_multipacket = 0; + + p_val = (uint8_t *)&p_param->value[0]; + flags = co_read16p(p_val) & BCS_MEAS_FLAGS_VALID; + + if (GETB(flags, BCS_MEAS_FLAGS_MULTIPACKET_MEAS) && (p_bcsc_env->env[conidx]->meas_evt_msg != 0)) + { + p_ind = ke_msg2param(p_bcsc_env->env[conidx]->meas_evt_msg); + second_segment_of_multipacket = 0x1; + } + else if (p_bcsc_env->env[conidx]->meas_evt_msg == 0) + { + p_ind = KE_MSG_ALLOC(BCSC_MEAS_IND, + prf_dst_task_get(&p_bcsc_env->prf_env, conidx), + prf_src_task_get(&p_bcsc_env->prf_env, conidx), + bcsc_meas_ind); + + if (GETB(flags, BCS_MEAS_FLAGS_MULTIPACKET_MEAS)) + { + p_bcsc_env->env[conidx]->meas_evt_msg = ke_param2msg(p_ind); + } + } + + if (p_ind != NULL) + { + // decode message + // Flags is 16 bit + p_val += sizeof(uint16_t); + + // Body Fat Percentage is mandatory + p_ind->body_fat_percent = co_read16p(p_val); + p_val += sizeof(uint16_t); + + // shall not be considered if it's in the second segement of multipacket + if (!second_segment_of_multipacket) + { + // Measurement Units + p_ind->meas_u = *p_val++; + } + + // Time Stamp if present + if (GETB(flags, BCS_MEAS_FLAGS_TIMESTAMP_PRESENT)) + { + p_val += prf_unpack_date_time(p_val, &p_ind->time_stamp); + } + // User Id if present + if (GETB(flags, BCS_MEAS_FLAGS_USER_ID_PRESENT)) + { + p_ind->user_id = *p_val++; + } + + // Basal Metabolism if present + if (GETB(flags, BCS_MEAS_FLAGS_BASAL_METAB_PRESENT)) + { + p_ind->basal_metab = co_read16p(p_val); + p_val += sizeof(uint16_t); + } + + // Muscle Percentage if present + if (GETB(flags, BCS_MEAS_FLAGS_MUSCLE_PERCENT_PRESENT)) + { + p_ind->muscle_percent = co_read16p(p_val); + p_val += sizeof(uint16_t); + } + + // Muscle Mass if present + if (GETB(flags, BCS_MEAS_FLAGS_MUSCLE_MASS_PRESENT)) + { + p_ind->muscle_mass = co_read16p(p_val); + p_val += sizeof(uint16_t); + } + + // Fat Free Mass if present + if (GETB(flags, BCS_MEAS_FLAGS_FAT_FREE_MASS_PRESENT)) + { + p_ind->fat_free_mass = co_read16p(p_val); + p_val += sizeof(uint16_t); + } + + // Soft Lean Mass if present + if (GETB(flags, BCS_MEAS_FLAGS_SOFT_LEAN_MASS_PRESENT)) + { + p_ind->soft_lean_mass = co_read16p(p_val); + p_val += sizeof(uint16_t); + } + + // Body Water Mass if present + if (GETB(flags, BCS_MEAS_FLAGS_BODY_WATER_MASS_PRESENT)) + { + p_ind->body_water_mass = co_read16p(p_val); + p_val += sizeof(uint16_t); + } + + // Impedance if present + if (GETB(flags, BCS_MEAS_FLAGS_IMPEDANCE_PRESENT)) + { + p_ind->impedance = co_read16p(p_val); + p_val += sizeof(uint16_t); + } + + // Weight if present + if (GETB(flags, BCS_MEAS_FLAGS_WEIGHT_PRESENT)) + { + p_ind->weight = co_read16p(p_val); + p_val += sizeof(uint16_t); + + // Mass resolution + p_ind->mass_resol = *p_val++; + } + + // Height if present + if (GETB(flags, BCS_MEAS_FLAGS_HEIGHT_PRESENT)) + { + p_ind->height = co_read16p(p_val); + p_val += sizeof(uint16_t); + + // Height resolution + p_ind->hght_resol = *p_val++; + } + + // if Multipacket Measurement present + if (GETB(flags, BCS_MEAS_FLAGS_MULTIPACKET_MEAS)) + { + if (second_segment_of_multipacket) + { + SETB(flags, BCS_MEAS_FLAGS_MULTIPACKET_MEAS, 0); + p_ind->flags |= flags; + + p_bcsc_env->env[conidx]->meas_evt_msg = 0; + ke_msg_send(p_ind); + } + else + { + SETB(flags, BCS_MEAS_FLAGS_MULTIPACKET_MEAS, 0); + p_ind->flags = flags; + } + } + else + { + p_ind->flags = flags; + p_bcsc_env->env[conidx]->meas_evt_msg = 0; + ke_msg_send(p_ind); + } + } + } + + p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + + // else drop the message + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(bcsc) +{ + {BCSC_ENABLE_REQ, (ke_msg_func_t)bcsc_enable_req_handler}, + + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {GATTC_DISC_CHAR_IND, (ke_msg_func_t)gattc_disc_char_ind_handler}, + {GATTC_DISC_CHAR_DESC_IND, (ke_msg_func_t)gattc_disc_char_desc_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {BCSC_RD_FEAT_CMD, (ke_msg_func_t)bcsc_rd_feat_cmd_handler}, + {BCSC_RD_MEAS_CCC_CMD, (ke_msg_func_t)bcsc_rd_meas_ccc_cmd_handler}, + {BCSC_WR_MEAS_CCC_CMD, (ke_msg_func_t)bcsc_wr_meas_ccc_cmd_handler}, + +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +void bcsc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct bcsc_env_tag *p_bcsc_env = PRF_ENV_GET(BCSC, bcsc); + + p_task_desc->msg_handler_tab = bcsc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(bcsc_msg_handler_tab); + p_task_desc->state = p_bcsc_env->state; + p_task_desc->idx_max = BCSC_IDX_MAX; +} + +#endif //(BLE_BCS_CLIENT) + +/// @} BCSCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/api/bcss_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/api/bcss_task.h new file mode 100644 index 0000000..52b41d5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/api/bcss_task.h @@ -0,0 +1,143 @@ +/** + **************************************************************************************** + * + * @file bcss_task.h + * + * @brief Header file - Body Composition Service Sensor/Server Role Task. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _BCSS_TASK_H_ +#define _BCSS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup BCSSTASK Task + * @ingroup BCSS + * @brief Body Composition Service Task. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "bcs_common.h" +#include +#include "rwip_task.h" // Task definitions + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Messages for Body Composition Service Sensor +/*@TRACE*/ +enum bcss_msg_id +{ + /// Enable the BCS Sensor task for a connection + BCSS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_BCSS), + /// Enable the BCS Sensor task for a connection + BCSS_ENABLE_RSP, + /// Indicate a new IND configuration to the application + /// Send CCC descriptor write update to the APP + BCSS_MEAS_CCC_IND, + + /// Make BCS Sensor indicate it's peer device with the measurement + BCSS_MEAS_INDICATE_CMD, + + /// Send a complete event status to the application + BCSS_CMP_EVT, +}; + +/// Operation codes +enum bcss_op_codes +{ + /// Indicate Measurement Operation Code + BCSS_MEAS_INDICATE_CMD_OP_CODE = 1, +}; +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the initialization function +struct bcss_db_cfg +{ + /// Body Composition service Feature Value + uint32_t feature; + /// Secondary service value + uint8_t secondary_service; +}; + +/// Parameters of the @ref BCSS_ENABLE_REQ message +struct bcss_enable_req +{ + /// CCC for the current connection + uint16_t ind_cfg; +}; + +/// Parameters of the @ref BCSS_ENABLE_RSP message +struct bcss_enable_rsp +{ + /// Status + uint8_t status; +}; + +/// Parameters of the @ref BCSS_MEAS_INDICATE_CMD message +struct bcss_meas_indicate_cmd +{ + /// Presence of optional fields and measurement units + uint16_t flags; + /// Body fat percentage value + uint16_t body_fat_percent; + /// Time stamp value + struct prf_date_time time_stamp; + /// User ID value + uint8_t user_id; + /// Basal Metabolism value + uint16_t basal_metab; + /// Muscle Percentage value + uint16_t muscle_percent; + /// Muscle Mass value + uint16_t muscle_mass; + /// Fat Free Mass value + uint16_t fat_free_mass; + /// Soft Lean Mass value + uint16_t soft_lean_mass; + /// Body Water Mass value + uint16_t body_water_mass; + /// Impedance Value + uint16_t impedance; + /// Weight value + uint16_t weight; + /// Height value + uint16_t height; +}; + +/// Parameters of the @ref BCSS_MEAS_CCC_IND message +struct bcss_meas_ccc_ind +{ + /// Char. Client Characteristic Configuration + uint16_t ind_cfg; +}; + +/// Parameters of the @ref BCSS_CMP_EVT message +struct bcss_cmp_evt +{ + /// operation + uint8_t operation; + /// Operation Status + uint8_t status; +}; + +/// @} BCSSTASK + +#endif //(_BCSS_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/sourcelist.txt new file mode 100644 index 0000000..1678350 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2016 +# +#*************************************************************************************** + + bcss.c + bcss_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/src/bcss.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/src/bcss.c new file mode 100644 index 0000000..794b53b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/src/bcss.c @@ -0,0 +1,338 @@ +/** + **************************************************************************************** + * + * @file bcss.c + * + * @brief Body Composition Service implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup BCSS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#include "prf.h" +#if (BLE_BCS_SERVER) +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" + +#include "bcss.h" +#include "bcss_task.h" +#include "bcs_common.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ +/// default read perm +#define RD_P (PERM(RD, ENABLE) | PERM(RP, NO_AUTH)) +/// default write perm +#define WR_P (PERM(WRITE_REQ, ENABLE) | PERM(WP, NO_AUTH)) +/// ind perm +#define IND_P (PERM(IND, ENABLE) | PERM(IP, NO_AUTH)) +/// enable Read Indication (1 = Value not present in Database) +#define EXT_P (PERM(RI, ENABLE)) + + +/// Full BCSS Database Description - Used to add attributes into the database +static const struct attm_desc bcss_att_db[BCSS_IDX_NB] = +{ + /// ATT Index | ATT UUID | Permission | EXT PERM | MAX ATT SIZE + // Weight SCale Service Declaration + [BCSS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, RD_P, 0, 0}, + + // Weight SCale Feature + [BCSS_IDX_FEAT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // Descriptor Value Changed Characteristic Value + [BCSS_IDX_FEAT_VAL] = {ATT_CHAR_BODY_COMPOSITION_FEATURE, RD_P, EXT_P, BCSS_FEAT_VAL_SIZE}, + + // Weight SCale Measurement + [BCSS_IDX_MEAS_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // Weight SCale Measurement Characteristic Value + [BCSS_IDX_MEAS_IND] = {ATT_CHAR_BODY_COMPOSITION_MEASUREMENT, IND_P, 0, BCSS_MEAS_IND_SIZE}, + // Weight SCale Measurement Characteristic - Client Characteristic Configuration Descriptor + [BCSS_IDX_MEAS_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, RD_P | WR_P, EXT_P, sizeof(uint16_t)}, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the BCSS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t bcss_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct bcss_db_cfg *p_param) +{ + //------------------ create the attribute database for the profile ------------------- + // Service content flag + uint8_t cfg_flag = (1 << BCSS_IDX_NB) - 1; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + uint8_t svc_perm; + + // Add service in the database + if (p_param->secondary_service) + { + svc_perm = PERM(SVC_SECONDARY,ENABLE); + } + else + { + svc_perm = PERM(SVC_SECONDARY,DISABLE); + } + + status = attm_svc_create_db(p_start_hdl, ATT_SVC_BODY_COMPOSITION, (uint8_t *)&cfg_flag, + BCSS_IDX_NB, NULL, p_env->task, &bcss_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, ENABLE) | svc_perm); + + // Check if an error has occured + if (status == ATT_ERR_NO_ERROR) + { + // Allocate BCSS required environment variable + struct bcss_env_tag *p_bcss_env = + (struct bcss_env_tag *) ke_malloc(sizeof(struct bcss_env_tag), KE_MEM_ATT_DB); + + // Initialize BCSS environment + + p_env->env = (prf_env_t *) p_bcss_env; + p_bcss_env->shdl = *p_start_hdl; + p_bcss_env->feature = p_param->feature; + + // Mono Instantiated APP task + p_bcss_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Multi Instantiated task depending on Multiple user support Feature + p_bcss_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_BCSS; + bcss_task_init(&(p_env->desc)); + + // Initialize CCC per connection + memset(p_bcss_env->prfl_ind_cfg, 0, BLE_CONNECTION_MAX); + // If we are here, database has been fulfilled with success, go to idle state + for(uint8_t idx = 0; idx < BLE_CONNECTION_MAX ; idx++) + { + // Put WSCS in disabled state + ke_state_set(KE_BUILD_ID(p_env->task, idx), BCSS_FREE); + } + } + + return status; +} +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void bcss_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct bcss_env_tag *p_bcss_env = (struct bcss_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + p_bcss_env->prfl_ind_cfg[conidx] = 0; + + /* Put BCSS in disabled state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), BCSS_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the BCSS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void bcss_destroy(struct prf_task_env *p_env) +{ + struct bcss_env_tag *p_bcss_env = (struct bcss_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + + // free profile environment variables + p_env->env = NULL; + ke_free(p_bcss_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void bcss_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct bcss_env_tag *p_bcss_env = (struct bcss_env_tag *) p_env->env; + + p_bcss_env->prfl_ind_cfg[conidx] = 0; + // Change state to IDLE + ke_state_set(KE_BUILD_ID(p_env->task, conidx), BCSS_IDLE); +} + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// BCSS Task interface required by profile manager +const struct prf_task_cbs bcss_itf = +{ + (prf_init_fnct) bcss_init, + bcss_destroy, + bcss_create, + bcss_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *bcss_prf_itf_get(void) +{ + return &bcss_itf; +} + + +void bcss_send_cmp_evt(struct bcss_env_tag *p_bcss_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct bcss_cmp_evt *p_evt = KE_MSG_ALLOC(BCSS_CMP_EVT, + prf_dst_task_get(&(p_bcss_env->prf_env), conidx), + prf_src_task_get(&(p_bcss_env->prf_env), conidx), + bcss_cmp_evt); + + p_evt->status = status; + p_evt->operation = operation; + ke_msg_send(p_evt); +} + +uint8_t bcss_get_mass_resol(uint32_t feature) +{ + uint8_t mass_resol; + + // Imperial - Weight and Mass in units of pound (lb) and Height in units of inch (in) + switch(GETF(feature, BCS_FEAT_MASS_RESOL)) + { + case BCS_MASS_RESOL_05kg_1lb: + { + mass_resol = BCS_MASS_RESOL_05kg_1lb; + } break; + + case BCS_MASS_RESOL_02kg_05lb: + { + mass_resol = BCS_MASS_RESOL_02kg_05lb; + } break; + + case BCS_MASS_RESOL_01kg_02lb: + { + mass_resol = BCS_MASS_RESOL_01kg_02lb; + } break; + + case BCS_MASS_RESOL_005kg_01lb: + { + mass_resol = BCS_MASS_RESOL_005kg_01lb; + } break; + + case BCS_MASS_RESOL_002kg_005lb: + { + mass_resol = BCS_MASS_RESOL_002kg_005lb; + } break; + + case BCS_MASS_RESOL_001kg_002lb: + { + mass_resol = BCS_MASS_RESOL_001kg_002lb; + } break; + + case BCS_MASS_RESOL_0005kg_001lb: + { + mass_resol = BCS_MASS_RESOL_0005kg_001lb; + } break; + + case BCS_MASS_RESOL_NOT_SPECIFIED: + default: + { + mass_resol = BCS_MASS_RESOL_NOT_SPECIFIED; + } break; + } + + return mass_resol; +} + +uint8_t bcss_get_hght_resol(uint32_t feature) +{ + uint8_t hght_resol; + + // Imperial - Weight and Mass in units of pound (lb) and Height in units of inch (in) + switch(GETF(feature, BCS_FEAT_HGHT_RESOL)) + { + case BCS_HGHT_RESOL_001mtr_1inch: + { + hght_resol = BCS_HGHT_RESOL_001mtr_1inch; + } break; + + case BCS_HGHT_RESOL_0005mtr_05inch: + { + hght_resol = BCS_HGHT_RESOL_0005mtr_05inch; + } break; + + case BCS_HGHT_RESOL_0001mtr_01inch: + { + hght_resol = BCS_HGHT_RESOL_0001mtr_01inch; + } break; + + case BCS_HGHT_RESOL_NOT_SPECIFIED: + default: + { + hght_resol = BCS_HGHT_RESOL_NOT_SPECIFIED; + } break; + } + + return hght_resol; +} +#endif //(BLE_BCS_SERVER) + +/// @} BCSS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/src/bcss.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/src/bcss.h new file mode 100644 index 0000000..c7027c5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/src/bcss.h @@ -0,0 +1,184 @@ +/** + **************************************************************************************** + * + * @file wscs.h + * + * @brief Header file - Body Composition Service Sensor. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _BCSS_H_ +#define _BCSS_H_ + +/** + **************************************************************************************** + * @addtogroup BCSS Body Composition Service Sensor + * @ingroup CSCP + * @brief Body Composition Service Sensor + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_BCS_SERVER) +#include "bcs_common.h" +#include "bcss_task.h" + +#include "prf_types.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Body Composition Sensor role task instances +#define BCSS_IDX_MAX (BLE_CONNECTION_MAX) +/// Feature value size 32 bits +#define BCSS_FEAT_VAL_SIZE (4) +/// Measurement Indication size (plus 3 bytes for meas_u, mass_resol and hght_resol) +#define BCSS_MEAS_IND_SIZE (sizeof(struct bcss_meas_indicate_cmd) + 3) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the Body Composition Service task +enum bcss_states +{ + /// not connected state + BCSS_FREE, + /// idle state + BCSS_IDLE, + + /// indicate + BCSS_OP_INDICATE, + + /// Number of defined states. + BCSS_STATE_MAX +}; + +/// Body Composition Service - Attribute List +enum bcss_bcs_att_list +{ + /// Body Composition Service + BCSS_IDX_SVC, + /// Body Composition Feature Characteristic + BCSS_IDX_FEAT_CHAR, + BCSS_IDX_FEAT_VAL, + /// Body Composition Measurement Characteristic + BCSS_IDX_MEAS_CHAR, + BCSS_IDX_MEAS_IND, + /// CCC Descriptor + BCSS_IDX_MEAS_CCC, + + /// Number of attributes + BCSS_IDX_NB, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Body Composition Service Sensor environment variable +struct bcss_env_tag +{ + /// profile environment + prf_env_t prf_env; + + /// Body Composition Service Start Handle + uint16_t shdl; + /// Feature configuration + uint32_t feature; + + /// CCC for each connections + uint8_t prfl_ind_cfg[BLE_CONNECTION_MAX]; + + /// State of different task instances + ke_state_t state[BCSS_IDX_MAX]; + + /// Store the @ref bcss_meas_indicate_cmd param when Multipacket presents + struct ke_msg* meas_cmd_msg[BLE_CONNECTION_MAX]; + +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Inform the APP that a procedure has been completed + * + * @param[in] p_bcss_env BCS Sensor environment variable + * @param[in] conidx Connection index + * @param[in] operation Operation code + * @param[in] status Operation status + **************************************************************************************** + */ +void bcss_send_cmp_evt(struct bcss_env_tag *p_bcss_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/** + **************************************************************************************** + * @brief Retrieve BSCS service profile interface + * + * @return Body composition service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* bcss_prf_itf_get(void); + + +/** + **************************************************************************************** + * @brief Get Mass Resolution from feature value + * + * @param[in] feature Body Composition Feature value + * + * @return Mass Resolution + **************************************************************************************** + */ +uint8_t bcss_get_mass_resol(uint32_t feature); + +/** + **************************************************************************************** + * @brief Get Height Resolution from feature value + * + * @param[in] feature Body Composition Feature value + * + * @return Height Resolution + **************************************************************************************** + */ +uint8_t bcss_get_hght_resol(uint32_t feature); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void bcss_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_BSC_SERVER) + +/// @} BCSS + +#endif //(_BSCS_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/src/bcss_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/src/bcss_task.c new file mode 100644 index 0000000..131c576 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/bcs/bcss/src/bcss_task.c @@ -0,0 +1,795 @@ +/** + **************************************************************************************** + * + * @file bcss_task.c + * + * @brief Body Composition Service Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup BCSSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_BCS_SERVER) +#include "rwble_hl_error.h" +#include "gapc.h" +#include "gattc.h" +#include "gattc_task.h" +#include "attm.h" +#include "bcss.h" +#include "bcss_task.h" +#include "bcs_common.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BCSS_ENABLE_REQ message. + * + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int bcss_enable_req_handler(ke_msg_id_t const msgid, + struct bcss_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct bcss_enable_rsp *p_cmp_evt = NULL; + + if (ke_state_get(dest_id) == BCSS_IDLE) + { + // Get the address of the environment + struct bcss_env_tag *p_bcss_env = PRF_ENV_GET(BCSS, bcss); + + // Save indication config + p_bcss_env->prfl_ind_cfg[KE_IDX_GET(src_id)] = p_param->ind_cfg; + status = GAP_ERR_NO_ERROR; + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(BCSS_ENABLE_RSP, src_id, dest_id, bcss_enable_rsp); + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + + // check that task is in idle state + if(ke_state_get(dest_id) == BCSS_IDLE) + { + // Get the address of the environment + struct bcss_env_tag *p_bcss_env = PRF_ENV_GET(BCSS, bcss); + uint8_t att_idx = p_param->handle - p_bcss_env->shdl; + uint8_t value[BCS_FEAT_VAL_LEN]; + uint8_t value_size = 0; + uint8_t status = ATT_ERR_NO_ERROR; + struct gattc_read_cfm* p_cfm = NULL; + + switch(att_idx) + { + case BCSS_IDX_FEAT_VAL: + { + value_size = BCS_FEAT_VAL_LEN; + co_write32p(&(value[0]), p_bcss_env->feature); + } break; + + case BCSS_IDX_MEAS_CCC: + { + value_size = BCS_MEAS_CCC_LEN; + co_write16p(&(value[0]), p_bcss_env->prfl_ind_cfg[KE_IDX_GET(src_id)]); + } break; + + default: + { + if (p_cfm == NULL) + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } + } break; + } + + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, value_size); + p_cfm->length = value_size; + memcpy(p_cfm->value, value, value_size); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct bcss_env_tag *p_bcss_env = PRF_ENV_GET(BCSS, bcss); + uint8_t att_idx = p_param->handle - p_bcss_env->shdl; + struct gattc_att_info_cfm *p_cfm; + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + // check if it's a client configuration char + if (att_idx == BCSS_IDX_MEAS_CCC) + { + // CCC attribute length = 2 + p_cfm->length = BCS_MEAS_CCC_LEN; + p_cfm->status = GAP_ERR_NO_ERROR; + } + else // not expected request + { + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } + + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BCSS_MEAS_INDICATE_CMD message. + * Send MEASUREMENT INDICATION to the connected peer case of CCC enabled + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int bcss_meas_indicate_cmd_handler(ke_msg_id_t const msgid, + struct bcss_meas_indicate_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct bcss_env_tag *p_bcss_env = PRF_ENV_GET(BCSS, bcss); + + // check that task is in idle state + if (ke_state_get(dest_id) == BCSS_IDLE) + { + // Connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_bcss_env->prfl_ind_cfg[conidx] & PRF_CLI_START_IND) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ind; + uint16_t max_payload = gattc_get_mtu(conidx) - 3; + uint16_t next_segment_flags = 0; + uint16_t length = 0; + // allocate the maxim block for indication + uint8_t value[BCSS_MEAS_IND_SIZE]; + + // Mask off any illegal bits in the flags field + p_param->flags &= BCS_MEAS_FLAGS_VALID; + + if (p_param->body_fat_percent == BCS_MEAS_UNSUCCESSFUL) + { + // Disable all other optional fields other than Timestamp and User ID + SETB(p_param->flags, BCS_MEAS_FLAGS_BASAL_METAB_PRESENT, 0); + SETB(p_param->flags, BCS_MEAS_FLAGS_MUSCLE_PERCENT_PRESENT, 0); + SETB(p_param->flags, BCS_MEAS_FLAGS_MUSCLE_MASS_PRESENT, 0); + SETB(p_param->flags, BCS_MEAS_FLAGS_FAT_FREE_MASS_PRESENT, 0); + SETB(p_param->flags, BCS_MEAS_FLAGS_SOFT_LEAN_MASS_PRESENT, 0); + SETB(p_param->flags, BCS_MEAS_FLAGS_BODY_WATER_MASS_PRESENT, 0); + SETB(p_param->flags, BCS_MEAS_FLAGS_IMPEDANCE_PRESENT, 0); + SETB(p_param->flags, BCS_MEAS_FLAGS_WEIGHT_PRESENT, 0); + SETB(p_param->flags, BCS_MEAS_FLAGS_HEIGHT_PRESENT, 0); + } + + //************************************************************** + // Encode the Fields of the Measurement + // if the Application provide flags and fields which do not correspond + // to the features declared by the server, we adjust the flags field to + // ensure we only Indicate with fields compatible with our features. + // Thus the flags fields is encoded last as it will be modified by checks on + // features. + // + // If the Fields provided require 2 ATT_HANDLE_VALUE_INDs. The following will + // always be contained in the first message (if selected in flags field). + // 1/ Flags + // 2/ Body Fat (mandatory) + // 3/ Measurement Units (retrieve from flags) + // 4/ Time Stamp + // 5/ User Id + // 6/ Basal Metabolism + // 7/ Muscle Percentage + // 8/ Muscle Mass + //******************************************************************** + length += sizeof(uint16_t); // Flags is 16bit + + // Mandatory Body Fat Percentage + co_write16p(&value[length], p_param->body_fat_percent); + length += sizeof(uint16_t); + + // Measurement Units + // 0 for SI and 1 for Imperial + value[length++] = GETB(p_param->flags, BCS_MEAS_FLAGS_UNITS_IMPERIAL); + + // We always include the Time-Stamp and User Id in the first message - if segmenting. + // Time stamp shall be included in flags field if the Server supports Time Stamp feature + if (GETB(p_bcss_env->feature, BCS_FEAT_TIME_STAMP_SUPP)) + { + SETB(p_param->flags, BCS_MEAS_FLAGS_TIMESTAMP_PRESENT, 1); + length += prf_pack_date_time(&value[length], &p_param->time_stamp); + } + else + { + // Shall not be included if the Time Stamp feature is not supported + SETB(p_param->flags, BCS_MEAS_FLAGS_TIMESTAMP_PRESENT, 0); + } + + // User ID shall be included in flags field if the Server supports Multiple Users feature + if (GETB(p_bcss_env->feature, BCS_FEAT_MULTIPLE_USERS_SUPP)) + { + SETB(p_param->flags, BCS_MEAS_FLAGS_USER_ID_PRESENT, 1); + value[length++] = p_param->user_id; + } + else + { + // Shall not be included if the Multiple Users feature is not supported + SETB(p_param->flags, BCS_MEAS_FLAGS_USER_ID_PRESENT, 0); + } + + // Basal Metabolism if present and enabled in the features. + if (GETB(p_param->flags, BCS_MEAS_FLAGS_BASAL_METAB_PRESENT)) + { + if (GETB(p_bcss_env->feature, BCS_FEAT_BASAL_METAB_SUPP)) + { + co_write16p(&value[length], p_param->basal_metab); + length += sizeof(uint16_t); + } + else + { + SETB(p_param->flags, BCS_MEAS_FLAGS_BASAL_METAB_PRESENT, 0); + } + } + + // Muscle Percentage if present and enabled in the features. + if (GETB(p_param->flags, BCS_MEAS_FLAGS_MUSCLE_PERCENT_PRESENT)) + { + if (GETB(p_bcss_env->feature, BCS_FEAT_MUSCLE_PERCENTAGE_SUPP)) + { + co_write16p(&value[length], p_param->muscle_percent); + length += sizeof(uint16_t); + } + else + { + SETB(p_param->flags, BCS_MEAS_FLAGS_MUSCLE_PERCENT_PRESENT, 0); + } + } + + // Muscle Mass if present and enabled in the features. + if (GETB(p_param->flags, BCS_MEAS_FLAGS_MUSCLE_MASS_PRESENT)) + { + if (GETB(p_bcss_env->feature, BCS_FEAT_MUSCLE_MASS_SUPP)) + { + co_write16p(&value[length], p_param->muscle_mass); + length += sizeof(uint16_t); + } + else + { + SETB(p_param->flags, BCS_MEAS_FLAGS_MUSCLE_MASS_PRESENT, 0); + } + } + + // Fat Free Mass if present and enabled in the features. + if (GETB(p_param->flags, BCS_MEAS_FLAGS_FAT_FREE_MASS_PRESENT)) + { + if (GETB(p_bcss_env->feature, BCS_FEAT_FAT_FREE_MASS_SUPP)) + { + if ((length + sizeof(uint16_t)) <= max_payload) + { + co_write16p(&value[length], p_param->fat_free_mass); + length += sizeof(uint16_t); + } + else + { + SETB(next_segment_flags, BCS_MEAS_FLAGS_FAT_FREE_MASS_PRESENT, 1); + } + } + else + { + SETB(p_param->flags, BCS_MEAS_FLAGS_FAT_FREE_MASS_PRESENT, 0); + } + } + + // Soft Lean Mass if present and enabled in the features. + if (GETB(p_param->flags, BCS_MEAS_FLAGS_SOFT_LEAN_MASS_PRESENT)) + { + if (GETB(p_bcss_env->feature, BCS_FEAT_SOFT_LEAN_MASS_SUPP)) + { + if ((length + sizeof(uint16_t)) <= max_payload) + { + co_write16p(&value[length], p_param->soft_lean_mass); + length += sizeof(uint16_t); + } + else + { + SETB(next_segment_flags, BCS_MEAS_FLAGS_SOFT_LEAN_MASS_PRESENT, 1); + } + } + else + { + SETB(p_param->flags, BCS_MEAS_FLAGS_SOFT_LEAN_MASS_PRESENT, 0); + } + } + + // Body Water Mass if present and enabled in the features. + if (GETB(p_param->flags, BCS_MEAS_FLAGS_BODY_WATER_MASS_PRESENT)) + { + if (GETB(p_bcss_env->feature, BCS_FEAT_BODY_WATER_MASS_SUPP)) + { + if ((length + sizeof(uint16_t)) <= max_payload) + { + co_write16p(&value[length], p_param->body_water_mass); + length += sizeof(uint16_t); + } + else + { + SETB(next_segment_flags, BCS_MEAS_FLAGS_BODY_WATER_MASS_PRESENT, 1); + } + } + else + { + SETB(p_param->flags, BCS_MEAS_FLAGS_BODY_WATER_MASS_PRESENT, 0); + } + } + + // Impedance if present and enabled in the features. + if (GETB(p_param->flags, BCS_MEAS_FLAGS_IMPEDANCE_PRESENT)) + { + if (GETB(p_bcss_env->feature, BCS_FEAT_IMPEDANCE_SUPP)) + { + if ((length + sizeof(uint16_t)) <= max_payload) + { + co_write16p(&value[length], p_param->impedance); + length += sizeof(uint16_t); + } + else + { + SETB(next_segment_flags, BCS_MEAS_FLAGS_IMPEDANCE_PRESENT, 1); + } + } + else + { + SETB(p_param->flags, BCS_MEAS_FLAGS_IMPEDANCE_PRESENT, 0); + } + } + + // Weight if present and enabled in the features. + if (GETB(p_param->flags, BCS_MEAS_FLAGS_WEIGHT_PRESENT)) + { + if (GETB(p_bcss_env->feature, BCS_FEAT_WEIGHT_SUPP)) + { + if ((length + sizeof(uint16_t) + sizeof(uint8_t)) <= max_payload) + { + co_write16p(&value[length], p_param->weight); + length += sizeof(uint16_t); + + // Get Mass Resolution + value[length++] = bcss_get_mass_resol(p_bcss_env->feature); + } + else + { + SETB(next_segment_flags, BCS_MEAS_FLAGS_WEIGHT_PRESENT, 1); + } + } + else + { + SETB(p_param->flags, BCS_MEAS_FLAGS_WEIGHT_PRESENT, 0); + } + } + + // Height if present and enabled in the features. + if (GETB(p_param->flags, BCS_MEAS_FLAGS_HEIGHT_PRESENT)) + { + if (GETB(p_bcss_env->feature, BCS_FEAT_HEIGHT_SUPP)) + { + if ((length + sizeof(uint16_t) + sizeof(uint8_t)) <= max_payload) + { + co_write16p(&value[length], p_param->height); + length += sizeof(uint16_t); + + // Get Height Resolution + value[length++] = bcss_get_hght_resol(p_bcss_env->feature); + } + else + { + SETB(next_segment_flags, BCS_MEAS_FLAGS_HEIGHT_PRESENT, 1); + } + } + else + { + SETB(p_param->flags, BCS_MEAS_FLAGS_HEIGHT_PRESENT, 0); + } + } + + // Finally store the flags in Byte 0 - the flags may have been changed in pre-ceeding steps. + if (next_segment_flags) + { + // Indicate this is a multipacket measurement. + // remove flags for fields which will not be transmitted in first segment + SETB(p_param->flags, BCS_MEAS_FLAGS_MULTIPACKET_MEAS, 1); + + co_write16p(&value[0], (p_param->flags &= ~next_segment_flags)); + SETB(next_segment_flags, BCS_MEAS_FLAGS_MULTIPACKET_MEAS, 1); + p_param->flags = next_segment_flags; + // Store the param in order to send the second segment + p_bcss_env->meas_cmd_msg[conidx] = ke_param2msg(p_param); + + msg_status = KE_MSG_NO_FREE; + } + else + { + co_write16p(&value[0], p_param->flags); + p_bcss_env->meas_cmd_msg[conidx] = 0; + } + + // Allocate the GATT notification message + p_ind = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + gattc_send_evt_cmd, length); + + // Fill in the p_parameter structure + p_ind->operation = GATTC_INDICATE; + p_ind->handle = p_bcss_env->shdl + BCSS_IDX_MEAS_IND; + // Pack Measurement record + p_ind->length = length; + // data + memcpy (p_ind->value, &value[0], length); + + // Send the event + ke_msg_send(p_ind); + + // go to busy state + ke_state_set(dest_id, BCSS_OP_INDICATE); + } + else + { + // Send a command complete to the App indicate msg could not be sent. + bcss_send_cmp_evt(p_bcss_env, conidx, BCSS_MEAS_INDICATE_CMD_OP_CODE, PRF_ERR_IND_DISABLED); + } + + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return msg_status; +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct bcss_env_tag *p_bcss_env = PRF_ENV_GET(BCSS, bcss); + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Check the connection handle + if (p_bcss_env != NULL) + { + // check that task is in idle state + if (ke_state_get(dest_id) == BCSS_IDLE) + { + // Status + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t att_idx = p_param->handle - p_bcss_env->shdl; + struct gattc_write_cfm *p_cfm = NULL; + + // CSC Measurement Characteristic, Client Characteristic Configuration Descriptor + if (att_idx == BCSS_IDX_MEAS_CCC) + { + uint16_t ntf_cfg; + uint8_t conidx = KE_IDX_GET(src_id); + struct bcss_meas_ccc_ind *p_ind = NULL; + + // Get the value + co_write16p(&ntf_cfg, p_param->value[0]); + p_bcss_env->prfl_ind_cfg[conidx] = ntf_cfg; + + // Inform the HL about the new configuration + p_ind = KE_MSG_ALLOC(BCSS_MEAS_CCC_IND, + prf_dst_task_get(&p_bcss_env->prf_env, conidx), + prf_src_task_get(&p_bcss_env->prf_env, conidx), + bcss_meas_ccc_ind); + + p_ind->ind_cfg = ntf_cfg; + + ke_msg_send(p_ind); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + else + { + msg_status = KE_MSG_SAVED; + } + } + // else drop the message + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT message meaning that an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + do + { + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct bcss_env_tag *p_bcss_env = PRF_ENV_GET(BCSS, bcss); + + // Check if a connection exists + if ((p_bcss_env == NULL) || (p_param->operation != GATTC_INDICATE) || + (ke_state_get(dest_id) != BCSS_OP_INDICATE)) + { + break; + } + + if (p_bcss_env->meas_cmd_msg[conidx]) + { + // If this is the CFM to the first part of a segmented message we must Tx the second part. + if (p_bcss_env->prfl_ind_cfg[conidx] & PRF_CLI_START_IND) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ind; + struct bcss_meas_indicate_cmd *p_cmd = ke_msg2param(p_bcss_env->meas_cmd_msg[conidx]); + // allocate the maxim block for indication + uint8_t value[BCSS_MEAS_IND_SIZE]; + uint8_t length = 0; + + //************************************************************** + // + // Following fields will not be present - allways in first segment + // 3/ Time Stamp + // 4/ User Id + // 5/ Basal Metabolism + // 6/ Muscle Percentage + // 7/ Muscle Mass + //******************************************************************** + co_write16p(&value[length], p_cmd->flags); + // Flags is 16bit + length += sizeof(uint16_t); + + // Mandatory Body Fat Percentage + co_write16p(&value[length], p_cmd->body_fat_percent); + length += sizeof(uint16_t); + + if (GETB(p_cmd->flags, BCS_MEAS_FLAGS_FAT_FREE_MASS_PRESENT)) + { + co_write16p(&value[length], p_cmd->fat_free_mass); + length += sizeof(uint16_t); + } + + if (GETB(p_cmd->flags, BCS_MEAS_FLAGS_SOFT_LEAN_MASS_PRESENT)) + { + co_write16p(&value[length], p_cmd->soft_lean_mass); + length += sizeof(uint16_t); + } + + if (GETB(p_cmd->flags, BCS_MEAS_FLAGS_BODY_WATER_MASS_PRESENT)) + { + co_write16p(&value[length], p_cmd->body_water_mass); + length += sizeof(uint16_t); + } + + if (GETB(p_cmd->flags, BCS_MEAS_FLAGS_IMPEDANCE_PRESENT)) + { + co_write16p(&value[length], p_cmd->impedance); + length += sizeof(uint16_t); + } + + if (GETB(p_cmd->flags, BCS_MEAS_FLAGS_WEIGHT_PRESENT)) + { + co_write16p(&value[length], p_cmd->weight); + length += sizeof(uint16_t); + + // Get Mass Resolution + value[length++] = bcss_get_mass_resol(p_bcss_env->feature); + } + + if (GETB(p_cmd->flags, BCS_MEAS_FLAGS_HEIGHT_PRESENT)) + { + co_write16p(&value[length], p_cmd->height); + length += sizeof(uint16_t); + + // Get Height Resolution + value[length++] = bcss_get_hght_resol(p_bcss_env->feature); + } + + // Finally store the flags in Byte 0 - the flags may have been changed in pre-ceeding steps. + co_write16p(&value[0], p_cmd->flags); + // Allocate the GATT notification message + p_ind = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + gattc_send_evt_cmd, length); + + // Fill in the p_parameter structure + p_ind->operation = GATTC_INDICATE; + p_ind->handle = p_bcss_env->shdl + BCSS_IDX_MEAS_IND; + p_ind->length = length; + // data + memcpy (p_ind->value, &value[0], length); + + // Send the event + ke_msg_send(p_ind); + + } + + ke_msg_free(p_bcss_env->meas_cmd_msg[conidx]); + p_bcss_env->meas_cmd_msg[conidx] = 0; + } + else + { + // Inform the application that a procedure has been completed + bcss_send_cmp_evt(p_bcss_env, + conidx, + BCSS_MEAS_INDICATE_CMD_OP_CODE, + p_param->status); + + ke_state_set(dest_id, BCSS_IDLE); + } + + } while (0); + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(bcss) +{ + {BCSS_ENABLE_REQ, (ke_msg_func_t) bcss_enable_req_handler}, + /// Send a BCS Measurement to the peer device (Indication) + {BCSS_MEAS_INDICATE_CMD, (ke_msg_func_t) bcss_meas_indicate_cmd_handler}, + + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +void bcss_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct bcss_env_tag *p_bcss_env = PRF_ENV_GET(BCSS, bcss); + + p_task_desc->msg_handler_tab = bcss_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(bcss_msg_handler_tab); + p_task_desc->state = p_bcss_env->state; + p_task_desc->idx_max = BCSS_IDX_MAX; +} + +#endif //(BLE_BCS_SERVER) + +/// @} BCSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blp_common.h new file mode 100644 index 0000000..b0fd694 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blp_common.h @@ -0,0 +1,260 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file blps_common.h + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +#ifndef _BLP_COMMON_H_ +#define _BLP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup BLP Blood Pressure Profile + * @ingroup PROFILE + * @brief Blood Pressure Profile + * + * The BLP module is the responsible block for implementing the Blood Pressure Profile + * functionalities in the BLE Host. + * + * The Blood Pressure Profile defines the functionality required in a device that allows + * the user (Collector device) to configure and recover blood pressure measurements from + * a blood pressure device. + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "prf_types.h" +#include +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// BLPC codes for the 2 possible client configuration characteristic descriptors determination in BPS +enum blp_ccc_code +{ + ///Blood Pressure Measurement + BPS_BP_MEAS_CODE = 0x01, + ///Intermediate Cuff Pressure Measurement + BPS_INTERM_CP_CODE, + ///Record Access Control Point + BPS_RACP_CODE, +}; + +/// Blood Pressure Measurement Flags bit field values +enum blp_meas_bf +{ + /// Blood Pressure Units Flag + /// 0 : Blood pressure for Systolic, Diastolic and MAP in units of mmHg + /// 1 : Blood pressure for Systolic, Diastolic and MAP in units of kPa + BPS_MEAS_FLAG_BP_UNITS_POS = 0, + BPS_MEAS_FLAG_BP_UNITS_BIT = CO_BIT(BPS_MEAS_FLAG_BP_UNITS_POS), + + /// Time Stamp Flag + /// 0 : not present + /// 1 : present + BPS_MEAS_FLAG_TIME_STAMP_POS = 1, + BPS_MEAS_FLAG_TIME_STAMP_BIT = CO_BIT(BPS_MEAS_FLAG_TIME_STAMP_POS), + + /// Pulse Rate Flag + /// 0 : not present + /// 1 : present + BPS_MEAS_PULSE_RATE_POS = 2, + BPS_MEAS_PULSE_RATE_BIT = CO_BIT(BPS_MEAS_PULSE_RATE_POS), + + /// User ID Flag + /// 0 : not present + /// 1 : present + BPS_MEAS_USER_ID_POS = 3, + BPS_MEAS_USER_ID_BIT = CO_BIT(BPS_MEAS_USER_ID_POS), + + /// Measurement Status Flag + /// 0 : not present + /// 1 : present + BPS_MEAS_MEAS_STATUS_POS = 4, + BPS_MEAS_MEAS_STATUS_BIT = CO_BIT(BPS_MEAS_MEAS_STATUS_POS), + + // Bit 5 - 7 RFU +}; + +/// Blood Pressure Measurement Status Flags field bit values +enum blp_meas_status_bf +{ + /// Body Movement Detection Flag + /// 0 : No body movement + /// 1 : Body movement during measurement + BPS_STATUS_MVMT_DETECT_POS = 0, + BPS_STATUS_MVMT_DETECT_BIT = CO_BIT(BPS_STATUS_MVMT_DETECT_POS), + + /// Cuff Fit Detection Flag + /// 0 : Cuff fits properly + /// 1 : Cuff too loose + BPS_STATUS_CUFF_FIT_DETECT_POS = 1, + BPS_STATUS_CUFF_FIT_DETECT_BIT = CO_BIT(BPS_STATUS_CUFF_FIT_DETECT_POS), + + /// Irregular Pulse Detection Flag + /// 0 : No irregular pulse detected + /// 1 : Irregular pulse detected + BPS_STATUS_IRREGULAR_PULSE_DETECT_POS = 2, + BPS_STATUS_IRREGULAR_PULSE_DETECT_BIT = CO_BIT(BPS_STATUS_IRREGULAR_PULSE_DETECT_POS), + + /// Pulse Rate Range Detection Flags + /// value 0 : Pulse rate is within the range + /// value 1 : Pulse rate exceeds upper limit + /// value 2 : Pulse rate is less than lower limit + BPS_STATUS_PR_RANGE_DETECT_LSB_POS = 3, + BPS_STATUS_PR_RANGE_DETECT_LSB_BIT = CO_BIT(BPS_STATUS_PR_RANGE_DETECT_LSB_POS), + + BPS_STATUS_PR_RANGE_DETECT_MSB_POS = 4, + BPS_STATUS_PR_RANGE_DETECT_MSB_BIT = CO_BIT(BPS_STATUS_PR_RANGE_DETECT_MSB_POS), + + /// Measurement Position Detection Flag + /// 0 : Proper measurement position + /// 1 : Improper measurement position + BPS_STATUS_MEAS_POS_DETECT_POS = 5, + BPS_STATUS_MEAS_POS_DETECT_BIT = CO_BIT(BPS_STATUS_MEAS_POS_DETECT_POS), + + // Bit 6 - 15 RFU +}; + +/// Blood Pressure Feature Flags field bit values +enum blp_feat_flags_bf +{ + ///Body Movement Detection Support bit + BPS_F_BODY_MVMT_DETECT_SUP_POS = 0, + BPS_F_BODY_MVMT_DETECT_SUP_BIT = CO_BIT(BPS_F_BODY_MVMT_DETECT_SUP_POS), + + /// Cuff Fit Detection Support bit + BPS_F_CUFF_FIT_DETECT_SUP_POS = 1, + BPS_F_CUFF_FIT_DETECT_SUP_BIT = CO_BIT(BPS_F_CUFF_FIT_DETECT_SUP_POS), + + /// Irregular Pulse Detection Support bit + BPS_F_IRREGULAR_PULSE_DETECT_SUP_POS = 2, + BPS_F_IRREGULAR_PULSE_DETECT_SUP_BIT = CO_BIT(BPS_F_IRREGULAR_PULSE_DETECT_SUP_POS), + + /// Pulse Rate Range Detection Support bit + BPS_F_PULSE_RATE_RANGE_DETECT_SUP_POS = 3, + BPS_F_PULSE_RATE_RANGE_DETECT_SUP_BIT = CO_BIT(BPS_F_PULSE_RATE_RANGE_DETECT_SUP_POS), + + /// Measurement Position Detection Support bit + BPS_F_MEAS_POS_DETECT_SUP_POS = 4, + BPS_F_MEAS_POS_DETECT_SUP_BIT = CO_BIT(BPS_F_MEAS_POS_DETECT_SUP_POS), + + /// Multiple Bond Support bit + BPS_F_MULTIPLE_BONDS_SUP_POS = 5, + BPS_F_MULTIPLE_BONDS_SUP_BIT = CO_BIT(BPS_F_MULTIPLE_BONDS_SUP_POS), + + // Bit 6 - 15 RFU +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Blood Pressure measurement structure +struct bps_bp_meas +{ + /// Flag + uint8_t flags; + /// User ID + uint8_t user_id; + /// Systolic (mmHg/kPa) + prf_sfloat systolic; + /// Diastolic (mmHg/kPa) + prf_sfloat diastolic; + /// Mean Arterial Pressure (mmHg/kPa) + prf_sfloat mean_arterial_pressure; + /// Pulse Rate + prf_sfloat pulse_rate; + /// Measurement Status + uint16_t meas_status; + /// Time stamp + struct prf_date_time time_stamp; +}; + +/// Record Access Control Point structure +struct bps_racp +{ + /// Opcode + uint8_t opcode; + /// Operator + uint8_t op_operator; + /// Operand + uint8_t operand; + /// Data + uint8_t data[17]; //BLPS_RACP_MAX_LEN-3 +}; + +/// Record Access Control Point structure +struct bps_racp_rsp +{ + /// Opcode + uint8_t opcode; + /// Operator + uint8_t op_operator; + /// Operand + uint8_t operand[18]; //BLPS_RACP_MAX_LEN-2 +}; + +/// @} blp_common + +#endif /* _BLP_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/api/blpc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/api/blpc_task.h new file mode 100644 index 0000000..d1587e3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/api/blpc_task.h @@ -0,0 +1,185 @@ +/** + **************************************************************************************** + * + * @file blpc_task.h + * + * @brief Header file - Blood Pressure Profile Collector Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _BLPC_TASK_H_ +#define _BLPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup BLPCTASK Blood Pressure Profile Collector Task + * @ingroup BLPC + * @brief Blood Pressure Profile Collector Task + * + * The BLPCTASK is responsible for handling the messages coming in and out of the + * @ref BLPC monitor block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" +#include "blp_common.h" + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/*@TRACE*/ +enum blpc_msg_id +{ + /// Start the blood pressure profile - at connection + BLPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_BLPC), + /// Confirm that cfg connection has finished with discovery results, or that normal cnx started + BLPC_ENABLE_RSP, + + /// Generic message to read a BPS or DIS characteristic value + BLPC_RD_CHAR_CMD, + ///Generic message for read responses for APP + BLPC_RD_CHAR_IND, + + /// Generic message for configuring the 2 characteristics that can be handled + BLPC_CFG_INDNTF_CMD, + + /// Blood pressure value send to APP + BLPC_BP_MEAS_IND, + + /// Complete Event Information + BLPC_CMP_EVT, +}; + +/// Characteristics +enum +{ + /// Blood Pressure Measurement + BLPC_CHAR_BP_MEAS, + /// Intermediate Cuff pressure + BLPC_CHAR_CP_MEAS, + /// Blood Pressure Feature + BLPC_CHAR_BP_FEATURE, + + BLPC_CHAR_MAX, +}; + +/// Characteristic descriptors +enum +{ + /// Blood Pressure Measurement client config + BLPC_DESC_BP_MEAS_CLI_CFG, + /// Intermediate Cuff pressure client config + BLPC_DESC_IC_MEAS_CLI_CFG, + BLPC_DESC_MAX, + BLPC_DESC_MASK = 0x10, +}; + +/// Operation codes +enum blpc_op_codes +{ + /// Database Creation Procedure + BLPC_RESERVED_OP_CODE = 0, + + /// Configure CCC Operation Code + BLPC_CFG_INDNTF_CMD_OP_CODE = 1, + + /// Read char. Operation Code + BLPC_RD_CHAR_CMD_OP_CODE = 2, +}; + +///Structure containing the characteristics handles, value handles and descriptors +struct bps_content +{ + /// service info + struct prf_svc svc; + + /// characteristic info: + /// - Blood Pressure Measurement + /// - Intermediate Cuff pressure + /// - Blood Pressure Feature + struct prf_char_inf chars[BLPC_CHAR_MAX]; + + /// Descriptor handles: + /// - Blood Pressure Measurement client cfg + /// - Intermediate Cuff pressure client cfg + struct prf_char_desc_inf descs[BLPC_DESC_MAX]; +}; + +/// Parameters of the @ref BLPC_ENABLE_REQ message +struct blpc_enable_req +{ + ///Connection type + uint8_t con_type; + ///Existing handle values bps + struct bps_content bps; +}; + +/// Parameters of the @ref BLPC_ENABLE_RSP message +struct blpc_enable_rsp +{ + ///status + uint8_t status; + ///Existing handle values bps + struct bps_content bps; +}; + +/// Parameters of the @ref BLPC_RD_CHAR_CMD message +struct blpc_rd_char_cmd +{ + ///Characteristic value code + uint8_t char_code; +}; + +/// Parameters of the @ref BLPC_RD_CHAR_IND message +struct blpc_rd_char_ind +{ + /// Attribute data information + struct prf_att_info info; +}; + +/// Parameters of the @ref BLPC_CFG_INDNTF_CMD message +struct blpc_cfg_indntf_cmd +{ + ///Own code for differentiating between blood pressure and + ///intermediate cuff pressure measurements + uint8_t char_code; + ///Stop/notify/indicate value to configure into the peer characteristic + uint16_t cfg_val; +}; + +/// Parameters of the @ref BLPC_BP_MEAS_IND message +struct blpc_bp_meas_ind +{ + /// Flag indicating if it is a intermediary cuff pressure measurement (0) or + /// stable blood pressure measurement (1). + uint16_t flag_interm_cp; + ///Blood Pressure measurement + struct bps_bp_meas meas_val; +}; + +///Parameters of the @ref BLPC_CMP_EVT message +struct blpc_cmp_evt +{ + /// Operation + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} BLPCTASK + +#endif /* _BLPC_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/sourcelist.txt new file mode 100644 index 0000000..74d62a0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + blpc.c + blpc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/src/blpc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/src/blpc.c new file mode 100644 index 0000000..17a4a2c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/src/blpc.c @@ -0,0 +1,270 @@ +/** + **************************************************************************************** + * + * @file blpc.c + * + * @brief Blood Pressure Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup BLPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_BP_COLLECTOR) +#include "blpc.h" +#include "blpc_task.h" +#include "gap.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the BLPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t blpc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct blpc_env_tag *p_blpc_env = + (struct blpc_env_tag *) ke_malloc(sizeof(struct blpc_env_tag), KE_MEM_ATT_DB); + + // allocate BLPC required environment variable + p_env->env = (prf_env_t *) p_blpc_env; + + p_blpc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_blpc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_BLPC; + blpc_task_init(&(p_env->desc)); + + for (idx = 0; idx < BLPC_IDX_MAX; idx++) + { + p_blpc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), BLPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void blpc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct blpc_env_tag *p_blpc_env = (struct blpc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_blpc_env->p_env[conidx] != NULL) + { + ke_free(p_blpc_env->p_env[conidx]); + p_blpc_env->p_env[conidx] = NULL; + } + + // Put BLP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), BLPC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the BLPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void blpc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct blpc_env_tag *p_blpc_env = (struct blpc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < BLPC_IDX_MAX; idx++) + { + blpc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_blpc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void blpc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put BLP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), BLPC_IDLE); +} + +/// BLPC Task interface required by profile manager +const struct prf_task_cbs blpc_itf = +{ + blpc_init, + blpc_destroy, + blpc_create, + blpc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *blpc_prf_itf_get(void) +{ + return &blpc_itf; +} + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +void blpc_enable_rsp_send(struct blpc_env_tag *p_blpc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on BLPS + struct blpc_enable_rsp *p_rsp = KE_MSG_ALLOC( + BLPC_ENABLE_RSP, + prf_dst_task_get(&(p_blpc_env->prf_env), conidx), + prf_src_task_get(&(p_blpc_env->prf_env), conidx), + blpc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->bps = p_blpc_env->p_env[conidx]->bps; + + prf_register_atthdl2gatt(&(p_blpc_env->prf_env), conidx, &(p_blpc_env->p_env[conidx]->bps.svc)); + + // Go to connected state + ke_state_set(prf_src_task_get(&(p_blpc_env->prf_env), conidx), BLPC_IDLE); + } + + ke_msg_send(p_rsp); +} + +void blpc_unpack_meas_value(struct bps_bp_meas *p_meas_val, uint8_t *p_packed_bp) +{ + uint8_t cursor; + + // blood pressure measurement flags + p_meas_val->flags = p_packed_bp[0]; + + // Blood Pressure Measurement Compound Value - Systolic + p_meas_val->systolic = co_read16p(&(p_packed_bp[1])); + + // Blood Pressure Measurement Compound Value - Diastolic (mmHg) + p_meas_val->diastolic = co_read16p(&(p_packed_bp[3])); + + // Blood Pressure Measurement Compound Value - Mean Arterial Pressure (mmHg) + p_meas_val->mean_arterial_pressure = co_read16p(&(p_packed_bp[5])); + + cursor = 7; + + // time flag set + if (GETB(p_meas_val->flags, BPS_MEAS_FLAG_TIME_STAMP)) + { + cursor += prf_unpack_date_time(p_packed_bp + cursor, &(p_meas_val->time_stamp)); + } + + // pulse rate flag set + if (GETB(p_meas_val->flags, BPS_MEAS_PULSE_RATE)) + { + p_meas_val->pulse_rate = co_read16p(&(p_packed_bp[cursor + 0])); + cursor += 2; + } + + // User ID flag set + if (GETB(p_meas_val->flags, BPS_MEAS_USER_ID)) + { + p_meas_val->user_id = p_packed_bp[cursor + 0]; + cursor += 1; + } + + // measurement status flag set + if (GETB(p_meas_val->flags, BPS_MEAS_MEAS_STATUS)) + { + p_meas_val->meas_status = co_read16p(&(p_packed_bp[cursor + 0])); + cursor += 2; + } +} + +void blpc_send_cmp_evt(struct blpc_env_tag *p_blpc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct blpc_cmp_evt *p_evt; + ke_task_id_t src_id = prf_src_task_get(&(p_blpc_env->prf_env), conidx); + ke_task_id_t dest_id = prf_dst_task_get(&(p_blpc_env->prf_env), conidx); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == BLPC_BUSY) + { + ke_state_set(src_id, BLPC_IDLE); + } + + // Send the message to the application + p_evt = KE_MSG_ALLOC(BLPC_CMP_EVT, dest_id, src_id, blpc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif /* (BLE_BP_COLLECTOR) */ + +/// @} BLPC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/src/blpc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/src/blpc.h new file mode 100644 index 0000000..c3c98f7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/src/blpc.h @@ -0,0 +1,185 @@ +/** + **************************************************************************************** + * + * @file blpc.h + * + * @brief Header file - Blood Pressure Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _BLPC_H_ +#define _BLPC_H_ + + +/** + **************************************************************************************** + * @addtogroup BLPC Blood Pressure Profile Collector + * @ingroup BLP + * @brief Blood Pressure Profile Collector + * + * The BLPC is responsible for providing Blood Pressure Profile Collector functionalities + * to upper layer module or application. The device using this profile takes the role + * of Blood Pressure Profile Collector. + * + * Blood Pressure Profile Collector. (BLPC): A BLPC (e.g. PC, phone, etc) + * is the term used by this profile to describe a device that can interpret blood pressure + * measurement in a way suitable to the user application. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_BP_COLLECTOR) + +#include "blpc_task.h" +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +///Maximum number of Blood Pressure Collector task instances +#define BLPC_IDX_MAX (BLE_CONNECTION_MAX) + +/// Possible states of the BLPC task +enum +{ + /// Free state + BLPC_FREE, + /// IDLE state + BLPC_IDLE, + /// Discovering Blood Pressure SVC and CHars + BLPC_DISCOVERING, + /// Busy state + BLPC_BUSY, + + /// Number of defined states. + BLPC_STATE_MAX +}; + +/// Internal codes for reading a BPS or DIS characteristic with one single request +enum +{ + ///Read BPS Blood pressure Measurement + BLPC_RD_BPS_BP_MEAS = BLPC_CHAR_BP_MEAS, + ///Read BPS Intermdiate Cuff Pressure + BLPC_RD_BPS_CP_MEAS = BLPC_CHAR_CP_MEAS, + ///Read BPS Blood pressure Features + BLPC_RD_BPS_FEATURE = BLPC_CHAR_BP_FEATURE, + + ///Read BPS Blood pressure Measurement Client Cfg. Desc + BLPC_RD_BPS_BP_MEAS_CFG = (BLPC_DESC_MASK | BLPC_DESC_BP_MEAS_CLI_CFG), + ///Read BPS Intermdiate Cuff Pressure Client Cfg. Desc + BLPC_RD_BPS_CP_MEAS_CFG = (BLPC_DESC_MASK | BLPC_DESC_IC_MEAS_CLI_CFG), +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ +struct blpc_cnx_env +{ + /// Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Last characteristic code used in a read or a write request + uint16_t last_char_code; + /// Counter used to check service uniqueness + uint8_t nb_svc; + /// Current operation code + uint8_t operation; + ///HTS characteristics + struct bps_content bps; +}; + +/// Blood Pressure Profile Collector environment variable +struct blpc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct blpc_cnx_env *p_env[BLPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[BLPC_IDX_MAX]; +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve BLP client profile interface + * @return BLP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* blpc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Blood Pressure ATT DB discovery results to BLPC host. + * + * @param p_blpc_env Blood Pressure Profile Client Role task environment + * @param conidx Connection index + * @param status Response status code + **************************************************************************************** + */ +void blpc_enable_rsp_send(struct blpc_env_tag *p_blpc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Unpack Blood pressure measurement data into a comprehensive structure. + * + * @param[out] p_meas_val Pointer to Blood pressure measurement structure destination + * @param[in] p_packed_bp Pointer of the packed data of Blood Pressure Measurement information + **************************************************************************************** + */ +void blpc_unpack_meas_value(struct bps_bp_meas *p_meas_val, uint8_t *p_packed_bp); + +/** + **************************************************************************************** + * @brief Send an BLPC_CMP_EVT message to a requester. + * + * @param[in] p_blpc_env BLP Client environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void blpc_send_cmp_evt(struct blpc_env_tag *p_blpc_env, uint8_t conidx, uint8_t operation, uint8_t status); + + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void blpc_task_init(struct ke_task_desc *p_task_desc); + + +#endif /* (BLE_BP_COLLECTOR) */ + +/// @} BLPC + +#endif /* _BLPC_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/src/blpc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/src/blpc_task.c new file mode 100644 index 0000000..e14abe8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blpc/src/blpc_task.c @@ -0,0 +1,544 @@ +/** + **************************************************************************************** + * + * @file blpc_task.c + * + * @brief Blood Pressure Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup BLPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_BP_COLLECTOR) +#include "co_utils.h" +#include "blpc_task.h" +#include "blpc.h" +#include "gap.h" +#include "att.h" +#include "gattc_task.h" +#include "gapc_task.h" +#include "ke_mem.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// State machine used to retrieve blood pressure service characteristics information +const struct prf_char_def blpc_bps_char[BLPC_CHAR_MAX] = +{ + // Blood Pressure Measurement + [BLPC_CHAR_BP_MEAS] = {ATT_CHAR_BLOOD_PRESSURE_MEAS, + ATT_MANDATORY, + ATT_CHAR_PROP_IND}, + // Intermediate Cuff pressure + [BLPC_CHAR_CP_MEAS] = {ATT_CHAR_INTERMEDIATE_CUFF_PRESSURE, + ATT_OPTIONAL, + ATT_CHAR_PROP_NTF}, + // Blood Pressure Feature + [BLPC_CHAR_BP_FEATURE] = {ATT_CHAR_BLOOD_PRESSURE_FEATURE, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, +}; + +/// State machine used to retrieve blood pressure service characteristic description information +const struct prf_char_desc_def blpc_bps_char_desc[BLPC_DESC_MAX] = +{ + // Blood Pressure Measurement client config + [BLPC_DESC_BP_MEAS_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, BLPC_CHAR_BP_MEAS}, + // Intermediate Cuff pressure client config + [BLPC_DESC_IC_MEAS_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, BLPC_CHAR_CP_MEAS}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == BLPC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct blpc_env_tag *p_blpc_env = PRF_ENV_GET(BLPC, blpc); + + ASSERT_INFO(p_blpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_blpc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_blpc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve BLS characteristics and descriptors + prf_extract_svc_info(p_ind, BLPC_CHAR_MAX, &blpc_bps_char[0], &p_blpc_env->p_env[conidx]->bps.chars[0], + BLPC_DESC_MAX, &blpc_bps_char_desc[0], &p_blpc_env->p_env[conidx]->bps.descs[0]); + + // Even if we get multiple responses we only store 1 range + p_blpc_env->p_env[conidx]->bps.svc.shdl = p_ind->start_hdl; + p_blpc_env->p_env[conidx]->bps.svc.ehdl = p_ind->end_hdl; + } + + p_blpc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BLPC_ENABLE_REQ message. + * The handler enables the Blood Pressure Profile Collector Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int blpc_enable_req_handler(ke_msg_id_t const msgid, + struct blpc_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Get state + uint8_t state = ke_state_get(dest_id); + + // Blood pressure Client Role Task Environment + struct blpc_env_tag *p_blpc_env = PRF_ENV_GET(BLPC, blpc); + + ASSERT_INFO(p_blpc_env != NULL, dest_id, src_id); + if ((state == BLPC_IDLE) && (p_blpc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_blpc_env->p_env[conidx] = (struct blpc_cnx_env *) ke_malloc(sizeof(struct blpc_cnx_env), KE_MEM_ATT_DB); + memset(p_blpc_env->p_env[conidx], 0, sizeof(struct blpc_cnx_env)); + + // Config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + //start discovering BPS on peer + prf_disc_svc_send(&(p_blpc_env->prf_env), conidx, ATT_SVC_BLOOD_PRESSURE); + + p_blpc_env->p_env[conidx]->last_uuid_req = ATT_SVC_BLOOD_PRESSURE; + + // Go to DISCOVERING state + ke_state_set(dest_id, BLPC_DISCOVERING); + } + // normal connection, get saved att details + else + { + p_blpc_env->p_env[conidx]->bps = p_param->bps; + + // send APP confirmation that can start normal connection to TH + blpc_enable_rsp_send(p_blpc_env, conidx, GAP_ERR_NO_ERROR); + } + } + + else if (state != BLPC_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + blpc_enable_rsp_send(p_blpc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct blpc_env_tag *p_blpc_env = PRF_ENV_GET(BLPC, blpc); + + if (p_blpc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == BLPC_DISCOVERING) + { + // Status + uint8_t status = p_param->status; + + if ((status == ATT_ERR_ATTRIBUTE_NOT_FOUND)|| + (status == ATT_ERR_NO_ERROR)) + { + // Discovery + // check characteristic validity + if (p_blpc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(BLPC_CHAR_MAX, + p_blpc_env->p_env[conidx]->bps.chars, + blpc_bps_char); + } + // too much services + else if (p_blpc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(BLPC_DESC_MAX, + p_blpc_env->p_env[conidx]->bps.descs, + blpc_bps_char_desc, + p_blpc_env->p_env[conidx]->bps.chars); + } + } + + blpc_enable_rsp_send(p_blpc_env, conidx, status); + } + + else if (state == BLPC_BUSY) + { + switch (p_param->operation) + { + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + blpc_send_cmp_evt(p_blpc_env, conidx, BLPC_CFG_INDNTF_CMD_OP_CODE, p_param->status); + } break; + + case GATTC_READ: + { + blpc_send_cmp_evt(p_blpc_env, conidx, BLPC_RD_CHAR_CMD_OP_CODE, p_param->status); + } break; + + default: + { + + } break; + } + + ke_state_set(prf_src_task_get(&p_blpc_env->prf_env, conidx), BLPC_IDLE); + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BLPC_RD_CHAR_CMD message. + * Check if the handle exists in profile(already discovered) and send request, otherwise + * error to APP. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int blpc_rd_char_cmd_handler(ke_msg_id_t const msgid, + struct blpc_rd_char_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Get the address of the environment + struct blpc_env_tag *p_blpc_env = PRF_ENV_GET(BLPC, blpc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if ((ke_state_get(dest_id) == BLPC_IDLE) && (p_blpc_env->p_env[conidx] != NULL)) + { + uint16_t search_hdl = ATT_INVALID_SEARCH_HANDLE; + + if ((p_param->char_code & BLPC_DESC_MASK) == BLPC_DESC_MASK) + { + search_hdl = p_blpc_env->p_env[conidx]->bps.descs[p_param->char_code & ~BLPC_DESC_MASK].desc_hdl; + } + else + { + search_hdl = p_blpc_env->p_env[conidx]->bps.chars[p_param->char_code].val_hdl; + } + + // check if handle is viable + if (search_hdl != ATT_INVALID_SEARCH_HANDLE) + { + prf_read_char_send( + &(p_blpc_env->prf_env), conidx, + p_blpc_env->p_env[conidx]->bps.svc.shdl, + p_blpc_env->p_env[conidx]->bps.svc.ehdl, + search_hdl); + + status = GAP_ERR_NO_ERROR; + ke_state_set(dest_id, BLPC_BUSY); + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + blpc_send_cmp_evt(p_blpc_env, conidx, BLPC_RD_CHAR_CMD_OP_CODE, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct blpc_env_tag *p_blpc_env = PRF_ENV_GET(BLPC, blpc); + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_blpc_env ->p_env[conidx] != NULL) + { + ASSERT_ERR(ke_state_get(dest_id) == BLPC_BUSY); + + prf_client_att_info_rsp(&p_blpc_env->prf_env, KE_IDX_GET(dest_id), BLPC_RD_CHAR_IND, + GAP_ERR_NO_ERROR, p_param); + + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BLPC_CFG_INDNTF_CMD message. + * It allows configuration of the peer ind/ntf/stop characteristic for a specified characteristic. + * Will return an error code if that cfg char does not exist. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int blpc_cfg_indntf_cmd_handler(ke_msg_id_t const msgid, + struct blpc_cfg_indntf_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct blpc_env_tag *p_blpc_env = PRF_ENV_GET(BLPC, blpc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if ((p_blpc_env->p_env[conidx] != NULL) && (ke_state_get(dest_id) == BLPC_IDLE)) + { + uint16_t cfg_hdl = ATT_INVALID_SEARCH_HANDLE; + + status = PRF_ERR_INVALID_PARAM; + + // get handle of the configuration characteristic to set and check if value matches property + switch (p_param->char_code) + { + case BLPC_CHAR_BP_MEAS://can only IND + { + if ((p_param->cfg_val == PRF_CLI_STOP_NTFIND)|| + (p_param->cfg_val == PRF_CLI_START_IND)) + { + cfg_hdl = p_blpc_env->p_env[conidx]->bps.descs[BLPC_DESC_BP_MEAS_CLI_CFG].desc_hdl; + } + } break; + + case BLPC_CHAR_CP_MEAS://can only NTF + { + if ((p_param->cfg_val == PRF_CLI_STOP_NTFIND)|| + (p_param->cfg_val == PRF_CLI_START_NTF)) + { + cfg_hdl = p_blpc_env->p_env[conidx]->bps.descs[BLPC_DESC_IC_MEAS_CLI_CFG].desc_hdl; + } + + } break; + + default: + { + status = PRF_ERR_INEXISTENT_HDL; + } break; + } + + //check if the handle value exists + if (cfg_hdl != ATT_INVALID_SEARCH_HANDLE) + { + // Send GATT Write Request + prf_gatt_write_ntf_ind(&p_blpc_env->prf_env, conidx, cfg_hdl, p_param->cfg_val); + // Set status + status = GAP_ERR_NO_ERROR; + ke_state_set(dest_id, BLPC_BUSY); + } + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send error message to application + blpc_send_cmp_evt(p_blpc_env, conidx, BLPC_CFG_INDNTF_CMD_OP_CODE, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct blpc_env_tag *p_blpc_env = PRF_ENV_GET(BLPC, blpc); + + if (p_blpc_env->p_env[conidx] != NULL) + { + switch (p_param->type) + { + case GATTC_INDICATE: + { + // confirm that indication has been correctly received + struct gattc_event_cfm *p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + } + // no break + + case GATTC_NOTIFY: + { + if((p_param->handle == p_blpc_env->p_env[conidx]->bps.chars[BLPC_CHAR_CP_MEAS].val_hdl) + || ((p_param->handle == p_blpc_env->p_env[conidx]->bps.chars[BLPC_CHAR_BP_MEAS].val_hdl))) + { + // build a BLPC_BP_MEAD_IND message with stable blood pressure value code. + struct blpc_bp_meas_ind * p_ind = KE_MSG_ALLOC( + BLPC_BP_MEAS_IND, + prf_dst_task_get(&(p_blpc_env->prf_env), conidx), + prf_src_task_get(&(p_blpc_env->prf_env), conidx), + blpc_bp_meas_ind); + + // Intermediate cuff pressure value + p_ind->flag_interm_cp = ((p_param->type == GATTC_NOTIFY) ? 0x01 : 0x00); + + // unpack blood pressure measurement. + blpc_unpack_meas_value(&(p_ind->meas_val), (uint8_t*) p_param->value); + + ke_msg_send(p_ind); + } + } break; + + default: + { + + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(blpc) +{ + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {BLPC_ENABLE_REQ, (ke_msg_func_t)blpc_enable_req_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + {BLPC_RD_CHAR_CMD, (ke_msg_func_t)blpc_rd_char_cmd_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {BLPC_CFG_INDNTF_CMD, (ke_msg_func_t)blpc_cfg_indntf_cmd_handler}, +}; + +void blpc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct blpc_env_tag *p_blpc_env = PRF_ENV_GET(BLPC, blpc); + + p_task_desc->msg_handler_tab = blpc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(blpc_msg_handler_tab); + p_task_desc->state = p_blpc_env->state; + p_task_desc->idx_max = BLPC_IDX_MAX; +} + +#endif /* (BLE_BP_COLLECTOR) */ +/// @} BLPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/api/blps_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/api/blps_task.h new file mode 100644 index 0000000..e2cea9c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/api/blps_task.h @@ -0,0 +1,232 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file blps_task.h + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +#ifndef _BLPS_TASK_H_ +#define _BLPS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup BLPSTASK Task + * @ingroup BLPS + * @brief Blood Pressure Profile Task. + * + * The BLPSTASK is responsible for handling the messages coming in and out of the + * @ref BLPS collector block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include +#include "rwip_task.h" // Task definitions +#include "blp_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +enum +{ + /// measurement sent by profile + BLPS_BP_MEAS_SEND, + /// peer device confirm reception + BLPS_CENTRAL_IND_CFM, +}; + +/// Messages for Blood Pressure Profile Sensor +/*@TRACE*/ +enum blps_msg_id +{ + /// Start the Blood Pressure Profile Sensor - at connection + BLPS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_BLPS), + /// Start the Blood Pressure Profile Sensor - at connection + BLPS_ENABLE_RSP, + + /// Send blood pressure measurement value from APP + BLPS_MEAS_SEND_CMD, + + /// Inform APP of new configuration value + BLPS_CFG_INDNTF_IND, + + /// Inform APP of new RACP value + BLPS_RACP_WRITE_IND, + + /// Send record access control point response value from APP + BLPS_RACP_RESP_SEND_CMD, + + /// Complete Event Information + BLPS_CMP_EVT, +}; + +/// Operation codes +enum blps_op_codes +{ + /// Database Creation Procedure + BLPS_RESERVED_OP_CODE = 0, + + /// Indicate Measurement Operation Code + BLPS_MEAS_SEND_CMD_OP_CODE = 1, + + /// Indicate Record Access Control Point Code + BLPS_RACP_RSP_SEND_CMD_OP_CODE = 2, +}; + +/// Parameters of the @ref BLPS_ENABLE_REQ message +struct blps_enable_req +{ + ///Connection index + uint8_t conidx; + + /// Blood Pressure indication configuration + uint16_t bp_meas_ind_en; + /// Intermediate Cuff Pressure Notification configuration + uint16_t interm_cp_ntf_en; + /// Record Access Control Point configuration + uint16_t racp_ind_en; +}; + +/// Parameters of the @ref BLPS_ENABLE_RSP message +struct blps_enable_rsp +{ + ///Connection index + uint8_t conidx; + ///Status + uint8_t status; +}; + +///Parameters of the @ref BLPS_CFG_INDNTF_IND message +struct blps_cfg_indntf_ind +{ + ///Connection index + uint8_t conidx; + ///Own code for differentiating between Blood Pressure Measurement, and Intermediate + /// Cuff Pressure Measurement characteristics + uint8_t char_code; + ///Stop/notify/indicate value to configure into the peer characteristic + uint16_t cfg_val; +}; + +/////Parameters of the @ref BLPS_MEAS_SEND_CMD message +struct blps_meas_send_cmd +{ + ///Connection index + uint8_t conidx; + /// Flag indicating if it is a intermediary cuff pressure measurement (0) or + /// stable blood pressure measurement (1). + uint8_t flag_interm_cp; + ///Blood Pressure measurement + struct bps_bp_meas meas_val; +}; + +/////Parameters of the @ref BLPS_RACP_WRITE_IND message +struct blps_racp_write_ind +{ + ///Connection index + uint8_t conidx; + /// RACP write value + struct bps_racp write_val; + /// RACP write value length + uint16_t write_val_len; +}; + +/////Parameters of the @ref BLPS_RACP_RESP_SEND_CMD message +struct blps_racp_resp_send_cmd +{ + ///Connection index + uint8_t conidx; + /// RACP response value + struct bps_racp_rsp write_val; + /// RACP response value length + uint16_t write_val_len; +}; + +///Parameters of the @ref BLPS_CMP_EVT message +struct blps_cmp_evt +{ + /// Operation + uint8_t operation; + /// Operation code see enum blps_op_codes + uint8_t operation_code; + /// Status + uint8_t status; +}; + +///Parameters of the @ref BLPS_CREATE_DB_REQ message +struct blps_db_cfg +{ + /// Supported features + uint16_t features; + /// Profile Configuration + uint8_t prfl_cfg; +}; + +/// @} BLPSTASK + +#endif /* _BLPS_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/sourcelist.txt new file mode 100644 index 0000000..e92049c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + blps.c + blps_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/src/blps.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/src/blps.c new file mode 100644 index 0000000..c482ca6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/src/blps.c @@ -0,0 +1,388 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file blps.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +/** + **************************************************************************************** + * @addtogroup BLPS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_BP_SENSOR) +#include "gap.h" +#include "gattc_task.h" +#include "blps.h" +#include "blps_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * BLPS PROFILE ATTRIBUTES + **************************************************************************************** + */ + +/// Full BLPS Database Description - Used to add attributes into the database +const struct attm_desc blps_att_db[BPS_IDX_NB] = +{ + // Blood Pressure Service Declaration + [BPS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Blood Pressure Measurement Characteristic Declaration + [BPS_IDX_BP_MEAS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Blood Pressure Measurement Characteristic Value + [BPS_IDX_BP_MEAS_VAL] = {ATT_CHAR_BLOOD_PRESSURE_MEAS, PERM(IND, ENABLE), PERM(RI, ENABLE), BLPS_BP_MEAS_MAX_LEN}, + // Blood Pressure Measurement Characteristic - Client Characteristic Configuration Descriptor + [BPS_IDX_BP_MEAS_IND_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Blood Pressure Feature Characteristic Declaration + [BPS_IDX_BP_FEATURE_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Blood Pressure Feature Characteristic Value + [BPS_IDX_BP_FEATURE_VAL] = {ATT_CHAR_BLOOD_PRESSURE_FEATURE, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint16_t)}, + + // Intermediate Cuff Pressure Characteristic Declaration + [BPS_IDX_INTM_CUFF_PRESS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Intermediate Cuff Pressure Characteristic Value + [BPS_IDX_INTM_CUFF_PRESS_VAL] = + {ATT_CHAR_INTERMEDIATE_CUFF_PRESSURE, PERM(NTF, ENABLE), PERM(RI, ENABLE), BLPS_BP_MEAS_MAX_LEN}, + // Intermediate Cuff Pressure Characteristic - Client Characteristic Configuration Descriptor + [BPS_IDX_INTM_CUFF_PRESS_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Record Access Control Point Characteristic Declaration + [BPS_IDX_RACP_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Record Access Control Point Characteristic Value + [BPS_IDX_RACP_VAL] = + {ATT_CHAR_REC_ACCESS_CTRL_PT, PERM(IND, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, BLPS_RACP_MAX_LEN}, + // Record Access Control Point Characteristic - Client Characteristic Configuration Descriptor + [BPS_IDX_RACP_IND_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the BLPS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t blps_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct blps_db_cfg *p_params) +{ + //------------------ create the attribute database for the profile ------------------- + // Service content flag + uint32_t cfg_flag= BLPS_MANDATORY_MASK; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + + //Set Configuration Flag Value + if (GETB(p_params->prfl_cfg, BLPS_INTM_CUFF_PRESS_SUP)) + { + cfg_flag |= BLPS_INTM_CUFF_PRESS_MASK; + } + + //Set Configuration Flag Value + if (GETB(p_params->prfl_cfg, BLPS_RACP_SUP)) + { + cfg_flag |= BLPS_RACP_MASK; + } + + // Add service in the database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_BLOOD_PRESSURE, (uint8_t *)&cfg_flag, + BPS_IDX_NB, NULL, p_env->task, &blps_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, DISABLE)); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + // Allocate BLPS required environment variable + struct blps_env_tag *p_blps_env = + (struct blps_env_tag *) ke_malloc(sizeof(struct blps_env_tag), KE_MEM_ATT_DB); + + // Initialize BLPS environment + p_env->env = (prf_env_t *) p_blps_env; + p_blps_env->shdl = *p_start_hdl; + p_blps_env->features = p_params->features; + p_blps_env->prfl_cfg = p_params->prfl_cfg; + + p_blps_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Multi Instantiated task + p_blps_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_BLPS; + blps_task_init(&(p_env->desc)); + + memset(p_blps_env->prfl_ntf_ind_cfg, 0, BLE_CONNECTION_MAX); + + // Put BLS in disabled state + ke_state_set(p_env->task, BLPS_IDLE); + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the BLPS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void blps_destroy(struct prf_task_env *p_env) +{ + struct blps_env_tag *p_blps_env = (struct blps_env_tag *) p_env->env; + + // free profile environment variables + p_env->env = NULL; + ke_free(p_blps_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void blps_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct blps_env_tag *p_blps_env = (struct blps_env_tag *) p_env->env; + p_blps_env->prfl_ntf_ind_cfg[conidx] = 0; +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void blps_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct blps_env_tag *p_blps_env = (struct blps_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + p_blps_env->prfl_ntf_ind_cfg[conidx] = 0; +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// BLPS Task interface required by profile manager +const struct prf_task_cbs blps_itf = +{ + (prf_init_fnct) blps_init, + blps_destroy, + blps_create, + blps_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* blps_prf_itf_get(void) +{ + return &blps_itf; +} + +uint8_t blps_pack_meas_value(uint8_t *p_packed_bp, const struct bps_bp_meas *p_meas_val) +{ + // Get the address of the environment + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + + uint8_t cursor; + + *(p_packed_bp) = p_meas_val->flags; + + // Blood Pressure Measurement Compound Value - Systolic + co_write16p(p_packed_bp + 1, p_meas_val->systolic); + + // Blood Pressure Measurement Compound Value - Diastolic (mmHg) + co_write16p(p_packed_bp + 3, p_meas_val->diastolic); + + // Blood Pressure Measurement Compound Value - Mean Arterial Pressure (mmHg) + co_write16p(p_packed_bp + 5, p_meas_val->mean_arterial_pressure); + + cursor = 7; + + // time flag set + if (GETB(p_meas_val->flags, BPS_MEAS_FLAG_TIME_STAMP)) + { + cursor += prf_pack_date_time(p_packed_bp + cursor, &(p_meas_val->time_stamp)); + } + + // Pulse rate flag set + if (GETB(p_meas_val->flags, BPS_MEAS_PULSE_RATE)) + { + co_write16p(p_packed_bp + cursor, p_meas_val->pulse_rate); + cursor += 2; + } + + // User ID flag set + if (GETB(p_meas_val->flags, BPS_MEAS_USER_ID)) + { + *(p_packed_bp + cursor) = p_meas_val->user_id; + cursor += 1; + } + + // Measurement status flag set + if (GETB(p_meas_val->flags, BPS_MEAS_MEAS_STATUS)) + { + // To avoid modify the value pointed by p_meas_val + uint16_t meas_status_temp = p_meas_val->meas_status; + + // If feature is not supported, the corresponding Measurement status bit(s) shall be set to 0 + if (!GETB(p_blps_env->features, BPS_F_BODY_MVMT_DETECT_SUP)) + { + SETB(meas_status_temp, BPS_STATUS_MVMT_DETECT, 0); + } + + if (!GETB(p_blps_env->features, BPS_F_CUFF_FIT_DETECT_SUP)) + { + SETB(meas_status_temp, BPS_STATUS_CUFF_FIT_DETECT, 0); + } + + if (!GETB(p_blps_env->features, BPS_F_IRREGULAR_PULSE_DETECT_SUP)) + { + SETB(meas_status_temp, BPS_STATUS_IRREGULAR_PULSE_DETECT, 0); + } + + if (!GETB(p_blps_env->features, BPS_F_PULSE_RATE_RANGE_DETECT_SUP)) + { + SETB(meas_status_temp, BPS_STATUS_PR_RANGE_DETECT_LSB, 0); + SETB(meas_status_temp, BPS_STATUS_PR_RANGE_DETECT_MSB, 0); + } + + if (!GETB(p_blps_env->features, BPS_F_MEAS_POS_DETECT_SUP)) + { + SETB(meas_status_temp, BPS_STATUS_MEAS_POS_DETECT, 0); + } + + co_write16p(p_packed_bp + cursor, meas_status_temp); + cursor += 2; + } + + // clear unused packet data + if (cursor < BLPS_BP_MEAS_MAX_LEN) + { + memset(p_packed_bp + cursor, 0, BLPS_BP_MEAS_MAX_LEN - cursor); + } + + return cursor; +} + +void blps_send_cmp_evt(struct blps_env_tag *p_blps_env, uint8_t conidx, uint8_t operation, uint8_t operation_code, uint8_t status) +{ + struct blps_cmp_evt *p_evt; + ke_task_id_t src_id = prf_src_task_get(&(p_blps_env->prf_env), conidx); + ke_task_id_t dest_id = prf_dst_task_get(&(p_blps_env->prf_env), conidx); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == BLPS_BUSY) + { + ke_state_set(src_id, BLPS_IDLE); + } + + // Send the message to the application + p_evt = KE_MSG_ALLOC(BLPS_CMP_EVT, dest_id, src_id, blps_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + p_evt->operation_code = operation_code; + + ke_msg_send(p_evt); +} + +#endif /* BLE_BP_SENSOR */ + +/// @} BLPS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/src/blps.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/src/blps.h new file mode 100644 index 0000000..8660eef --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/src/blps.h @@ -0,0 +1,289 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file blps.h + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _BLPS_H_ +#define _BLPS_H_ + +/** + **************************************************************************************** + * @addtogroup BLPS Blood Pressure Profile Sensor + * @ingroup BLP + * @brief Blood Pressure Profile Sensor + * + * Blood pressure sensor (BPS) profile provides functionalities to upper layer module + * application. The device using this profile takes the role of Blood pressure sensor. + * + * The interface of this role to the Application is: + * - Enable the profile role (from APP) + * - Disable the profile role (from APP) + * - Notify peer device during Blood Pressure measurement (from APP) + * - Indicate measurements performed to peer device (from APP) + * + * Profile didn't manages multiple users configuration and storage of offline measurements. + * This must be handled by application. + * + * Blood Pressure Profile Sensor. (BLPS): A BLPS (e.g. PC, phone, etc) + * is the term used by this profile to describe a device that can perform blood pressure + * measurement and notify about on-going measurement and indicate final result to a peer + * BLE device. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "blp_common.h" + +#if (BLE_BP_SENSOR) + +#include "prf_types.h" +#include "prf.h" +#include "blps_task.h" +#include "attm.h" + +/* + * DEFINES + **************************************************************************************** + */ +///Maximum number of Blood Pressure task instances +#define BLPS_IDX_MAX 0x01 + +/// Maximum notification length +#define BLPS_BP_MEAS_MAX_LEN (19) +#define BLPS_RACP_MAX_LEN (20) + +///BPS Configuration Flag Masks +#define BLPS_MANDATORY_MASK (0x003F) +#define BLPS_INTM_CUFF_PRESS_MASK (0x01C0) +#define BLPS_RACP_MASK (0X0E00) + +/// indication/notification config mask +#define BLPS_NTFIND_MASK (0x0E) + +/* + * MACROS + **************************************************************************************** + */ + +/// Possible states of the BLPS task +enum +{ + /// Idle state + BLPS_IDLE, + /// Busy state + BLPS_BUSY, + + /// Number of defined states. + BLPS_STATE_MAX +}; + +///Attributes State Machine +enum +{ + BPS_IDX_SVC, + + BPS_IDX_BP_MEAS_CHAR, + BPS_IDX_BP_MEAS_VAL, + BPS_IDX_BP_MEAS_IND_CFG, + + BPS_IDX_BP_FEATURE_CHAR, + BPS_IDX_BP_FEATURE_VAL, + + BPS_IDX_INTM_CUFF_PRESS_CHAR, + BPS_IDX_INTM_CUFF_PRESS_VAL, + BPS_IDX_INTM_CUFF_PRESS_NTF_CFG, + + BPS_IDX_RACP_CHAR, + BPS_IDX_RACP_VAL, + BPS_IDX_RACP_IND_CFG, + + BPS_IDX_NB, +}; + +///Characteristic Codes +enum +{ + BPS_BP_MEAS_CHAR, + BPS_INTM_CUFF_MEAS_CHAR, + BPS_BP_FEATURE_CHAR, + BPS_RACP_CHAR, +}; + +/// Database Configuration Bit Field Flags +enum blps_db_config_bf +{ + /// support of Intermediate Cuff Pressure + BLPS_INTM_CUFF_PRESS_SUP_POS = 0, + BLPS_INTM_CUFF_PRESS_SUP_BIT = CO_BIT(BLPS_INTM_CUFF_PRESS_SUP_POS), + + /// support of Record Access Control Point + BLPS_RACP_SUP_POS = 1, + BLPS_RACP_SUP_BIT = CO_BIT(BLPS_RACP_SUP_POS), +}; + +/// Indication/notification configuration (put in feature flag to optimize memory usage) +enum blps_indntf_config_bf +{ + /// Bit used to know if blood pressure measurement indication is enabled + BLPS_BP_MEAS_IND_CFG_POS = 1, + BLPS_BP_MEAS_IND_CFG_BIT = CO_BIT(BLPS_BP_MEAS_IND_CFG_POS), + + /// Bit used to know if cuff pressure measurement notification is enabled + BLPS_INTM_CUFF_PRESS_NTF_CFG_POS = 2, + BLPS_INTM_CUFF_PRESS_NTF_CFG_BIT = CO_BIT(BLPS_INTM_CUFF_PRESS_NTF_CFG_POS), + + /// Bit used to know if record access cotrol point notification is enabled + BLPS_RACP_IND_CFG_POS = 3, + BLPS_RACP_IND_CFG_BIT = CO_BIT(BLPS_RACP_IND_CFG_POS), +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Blood Pressure Profile Sensor environment variable per connection +struct blps_cnx_env +{ + /// Profile Notify/Indication Flags + uint8_t prfl_ntf_ind_cfg; +}; + +/// Blood Pressure Profile Sensor environment variable +struct blps_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Blood Pressure Service Start Handle + uint16_t shdl; + /// Feature Configuration Flags + uint16_t features; + /// Profile configuration flags + uint8_t prfl_cfg; + /// Event (notification/indication) config + uint8_t evt_cfg; + /// Environment variable pointer for each connections + uint8_t prfl_ntf_ind_cfg[BLE_CONNECTION_MAX]; + /// State of different task instances + ke_state_t state[BLPS_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve BLP service profile interface + * + * @return BLP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* blps_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Pack Blood Pressure measurement value + * + * @param[out] p_packed_bp Pointer of the packed data of Blood Pressure Measurement information + * @param[in] p_meas_val Blood Pressure measurement value + * @return size of packed value + **************************************************************************************** + */ +uint8_t blps_pack_meas_value(uint8_t *p_packed_bp, const struct bps_bp_meas* p_meas_val); + +/** + **************************************************************************************** + * @brief Send an BLPS_CMP_EVT message to a requester. + * + * @param[in] p_blps_env BLP Sensor environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] operation_code Code of the operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void blps_send_cmp_evt(struct blps_env_tag *p_blps_env, uint8_t conidx, uint8_t operation, uint8_t operation_code, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void blps_task_init(struct ke_task_desc *p_task_desc); + + +#endif /* #if (BLE_BP_SENSOR) */ + +/// @} BLPS + +#endif /* _BLPS_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/src/blps_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/src/blps_task.c new file mode 100644 index 0000000..f7514dd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/blp/blps/src/blps_task.c @@ -0,0 +1,616 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file blps_task.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +/** + **************************************************************************************** + * @addtogroup BLPSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_BP_SENSOR) +#include "co_utils.h" + +#include "gap.h" +#include "gattc_task.h" +#include "blps.h" +#include "blps_task.h" +#include "prf_utils.h" + + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BLPS_ENABLE_REQ message. + * The handler enables the Blood Pressure Sensor Profile and initialize readable values. + * @param[in] msgid Id of the message received (probably unused).off + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int blps_enable_req_handler(ke_msg_id_t const msgid, + struct blps_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + struct blps_enable_rsp *p_cmp_evt; + + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (gapc_get_conhdl(p_param->conidx) == GAP_INVALID_CONHDL) + { + status = PRF_ERR_DISCONNECTED; + } + else if (ke_state_get(dest_id) == BLPS_IDLE) + { + if (p_param->interm_cp_ntf_en == PRF_CLI_START_NTF) + { + // Enable Bonded Data + SETB(p_blps_env->prfl_ntf_ind_cfg[p_param->conidx], BLPS_INTM_CUFF_PRESS_NTF_CFG, 1); + } + + if (p_param->bp_meas_ind_en == PRF_CLI_START_IND) + { + // Enable Bonded Data + SETB(p_blps_env->prfl_ntf_ind_cfg[p_param->conidx], BLPS_BP_MEAS_IND_CFG, 1); + } + + if (p_param->racp_ind_en == PRF_CLI_START_IND) + { + // Enable Bonded Data + SETB(p_blps_env->prfl_ntf_ind_cfg[p_param->conidx], BLPS_RACP_IND_CFG, 1); + } + + status = GAP_ERR_NO_ERROR; + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(BLPS_ENABLE_RSP, src_id, dest_id, blps_enable_rsp); + p_cmp_evt->status = status; + p_cmp_evt->conidx = p_param->conidx; + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == BLPS_IDLE) + { + // Get the address of the environment + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + uint8_t conidx = KE_IDX_GET(src_id); + + uint16_t value = 0; + uint8_t status = ATT_ERR_NO_ERROR; + struct gattc_read_cfm *p_cfm; + + switch (p_param->handle - p_blps_env->shdl) + { + case BPS_IDX_BP_FEATURE_VAL: + { + value = p_blps_env->features; + } break; + + case BPS_IDX_BP_MEAS_IND_CFG: + { + value = GETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_BP_MEAS_IND_CFG) + ? PRF_CLI_START_IND : PRF_CLI_STOP_NTFIND; + } break; + + case BPS_IDX_INTM_CUFF_PRESS_NTF_CFG: + { + // Characteristic is profile specific + if (GETB(p_blps_env->prfl_cfg, BLPS_INTM_CUFF_PRESS_SUP)) + { + // Fill data + value = GETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_INTM_CUFF_PRESS_NTF_CFG) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND; + } + else + { + status = ATT_ERR_ATTRIBUTE_NOT_FOUND; + } + } break; + + default: + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + // Send data to peer device + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + memcpy(p_cfm->value, &value, sizeof(uint16_t)); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BLPS_MEAS_SEND_CMD message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int blps_meas_send_cmd_handler(ke_msg_id_t const msgid, + struct blps_meas_send_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get the address of the environment + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + + if (gapc_get_conhdl(p_param->conidx) == GAP_INVALID_CONHDL) + { + status = PRF_ERR_DISCONNECTED; + } + else if (ke_state_get(dest_id) == BLPS_IDLE) + { + + // Intermediary blood pressure, must be notified if enabled + if (p_param->flag_interm_cp) + { + // Check if supported + if (GETB(p_blps_env->prfl_cfg, BLPS_INTM_CUFF_PRESS_SUP)) + { + if (!GETB(p_blps_env->prfl_ntf_ind_cfg[p_param->conidx], BLPS_INTM_CUFF_PRESS_NTF_CFG)) + { + status = PRF_ERR_NTF_DISABLED; + } + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } + + // Stable Blood Pressure Measurement, must be indicated if enabled + else if (!GETB(p_blps_env->prfl_ntf_ind_cfg[p_param->conidx], BLPS_BP_MEAS_IND_CFG)) + { + status = PRF_ERR_IND_DISABLED; + } + + // Check if message can be sent + if (status == GAP_ERR_NO_ERROR) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_meas_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, p_param->conidx), dest_id, + gattc_send_evt_cmd, BLPS_BP_MEAS_MAX_LEN); + + // Fill event type and handle which trigger event + if (p_param->flag_interm_cp) + { + p_meas_val->operation = GATTC_NOTIFY; + p_meas_val->handle = p_blps_env->shdl + BPS_IDX_INTM_CUFF_PRESS_VAL; + } + else + { + // Fill in the p_parameter structure + p_meas_val->operation = GATTC_INDICATE; + p_meas_val->handle = p_blps_env->shdl + BPS_IDX_BP_MEAS_VAL; + } + + p_meas_val->seq_num = BLPS_MEAS_SEND_CMD_OP_CODE; + #if 1 + // Pack the BP Measurement value + p_meas_val->length = blps_pack_meas_value(p_meas_val->value, &p_param->meas_val); + #else + //copy raw data if already pack + p_meas_val->length = BLPS_BP_MEAS_MAX_LEN; + memcpy(p_meas_val->value,(const uint8_t*)&p_param->meas_val,p_meas_val->length); + #endif + // Send the event + ke_msg_send(p_meas_val); + // Go to busy state + ke_state_set(dest_id, BLPS_BUSY); + } + } + else + { + // Save it for later + msg_status = KE_MSG_SAVED; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send error message to application + blps_send_cmp_evt(p_blps_env, p_param->conidx, GATTC_INDICATE, BLPS_MEAS_SEND_CMD_OP_CODE, status); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref BLPS_RACP_RESP_SEND_CMD message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int blps_racp_resp_send_cmd_handler(ke_msg_id_t const msgid, + struct blps_racp_resp_send_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get the address of the environment + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + + if (gapc_get_conhdl(p_param->conidx) == GAP_INVALID_CONHDL) + { + status = PRF_ERR_DISCONNECTED; + } + else if (ke_state_get(dest_id) == BLPS_IDLE) + { + // Send Record Access Control Point Value, must be indicated if enabled + if (!GETB(p_blps_env->prfl_ntf_ind_cfg[p_param->conidx], BLPS_RACP_IND_CFG)) + { + status = PRF_ERR_IND_DISABLED; + } + + // Check if message can be sent + if (status == GAP_ERR_NO_ERROR) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_racp_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, p_param->conidx), dest_id, + gattc_send_evt_cmd, BLPS_RACP_MAX_LEN); + + // Fill in the p_parameter structure + p_racp_val->operation = GATTC_INDICATE; + p_racp_val->handle = p_blps_env->shdl + BPS_IDX_RACP_VAL; + + p_racp_val->seq_num = BLPS_RACP_RSP_SEND_CMD_OP_CODE; + + if(p_param->write_val_len <= BLPS_RACP_MAX_LEN) + { + p_racp_val->length = p_param->write_val_len; + } + else + { + p_racp_val->length = BLPS_RACP_MAX_LEN; + } + + memcpy(p_racp_val->value, &(p_param->write_val), p_racp_val->length); + + // Send the event + ke_msg_send(p_racp_val); + // Go to busy state + ke_state_set(dest_id, BLPS_BUSY); + } + } + else + { + // Save it for later + msg_status = KE_MSG_SAVED; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send error message to application + blps_send_cmp_evt(p_blps_env, p_param->conidx, GATTC_INDICATE, BLPS_RACP_RSP_SEND_CMD_OP_CODE, status); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GL2C_CODE_ATT_WR_CMD_IND message. + * The handler compares the new values with current ones and notifies them if they changed. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + struct gattc_write_cfm *p_cfm; + uint8_t conidx = KE_IDX_GET(src_id); + + uint16_t value = 0x0000; + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t char_code = 0; + + //Extract value before check, for CCC attribute + memcpy(&value, &(p_param->value), sizeof(uint16_t)); + + //BP Measurement Char. - Client Char. Configuration + if (p_param->handle == (p_blps_env->shdl + BPS_IDX_BP_MEAS_IND_CFG)) + { + if ((value == PRF_CLI_STOP_NTFIND) || (value == PRF_CLI_START_IND)) + { + char_code = BPS_BP_MEAS_CHAR; + + if (value == PRF_CLI_STOP_NTFIND) + { + SETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_BP_MEAS_IND_CFG, 0); + } + else //PRF_CLI_START_IND + { + SETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_BP_MEAS_IND_CFG, 1); + } + } + else + { + status = PRF_APP_ERROR; + } + } + else if (p_param->handle == (p_blps_env->shdl + BPS_IDX_INTM_CUFF_PRESS_NTF_CFG)) + { + if ((value == PRF_CLI_STOP_NTFIND) || (value == PRF_CLI_START_NTF)) + { + char_code = BPS_INTM_CUFF_MEAS_CHAR; + + if (value == PRF_CLI_STOP_NTFIND) + { + SETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_INTM_CUFF_PRESS_NTF_CFG, 0); + } + else //PRF_CLI_START_NTF + { + SETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_INTM_CUFF_PRESS_NTF_CFG, 1); + } + } + else + { + status = PRF_APP_ERROR; + } + } + else if (p_param->handle == (p_blps_env->shdl + BPS_IDX_RACP_IND_CFG)) + { + if ((value == PRF_CLI_STOP_NTFIND) || (value == PRF_CLI_START_IND)) + { + char_code = BPS_RACP_CHAR; + + if (value == PRF_CLI_STOP_NTFIND) + { + SETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_RACP_IND_CFG, 0); + } + else //PRF_CLI_START_IND + { + SETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_RACP_IND_CFG, 1); + } + } + else + { + status = PRF_APP_ERROR; + } + } + + if (status == GAP_ERR_NO_ERROR) + { + if( (p_param->handle == (p_blps_env->shdl + BPS_IDX_BP_MEAS_IND_CFG)) + || (p_param->handle == (p_blps_env->shdl + BPS_IDX_INTM_CUFF_PRESS_NTF_CFG)) + || (p_param->handle == (p_blps_env->shdl + BPS_IDX_RACP_IND_CFG)) + ) + { + // Inform APP of configuration change + struct blps_cfg_indntf_ind *p_ind = KE_MSG_ALLOC( + BLPS_CFG_INDNTF_IND, + prf_dst_task_get(&p_blps_env->prf_env, conidx), + prf_src_task_get(&p_blps_env->prf_env, conidx), + blps_cfg_indntf_ind); + + p_ind->conidx = conidx; + p_ind->char_code = char_code; + memcpy(&p_ind->cfg_val, &value, sizeof(uint16_t)); + + ke_msg_send(p_ind); + } + else if(p_param->handle == (p_blps_env->shdl + BPS_IDX_RACP_VAL)) + { + // Inform APP of RACP write REQ + struct blps_racp_write_ind *p_ind = KE_MSG_ALLOC( + BLPS_RACP_WRITE_IND, + prf_dst_task_get(&p_blps_env->prf_env, conidx), + prf_src_task_get(&p_blps_env->prf_env, conidx), + blps_racp_write_ind); + + p_ind->conidx = conidx; + + if(p_param->length <= BLPS_RACP_MAX_LEN) + { + memcpy(&p_ind->write_val, &(p_param->value), p_param->length); + } + else + { + memcpy(&p_ind->write_val, &(p_param->value), BLPS_RACP_MAX_LEN); + } + + p_ind->write_val_len = p_param->length; + + ke_msg_send(p_ind); + } + } + + // Send write response + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT for GATTC_NOTIFY and GATT_INDICATE message meaning + * that Measurement notification/indication has been correctly sent to peer device + * + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + // Get the address of the environment + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + uint8_t conidx = KE_IDX_GET(src_id); + + switch (p_param->operation) + { + case GATTC_NOTIFY: + case GATTC_INDICATE: + { + // Send a complete event status to the application + blps_send_cmp_evt(p_blps_env, conidx, p_param->operation, p_param->seq_num, p_param->status); + } break; + + default: + { + + } break; + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(blps) +{ + {BLPS_ENABLE_REQ, (ke_msg_func_t) blps_enable_req_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {BLPS_MEAS_SEND_CMD, (ke_msg_func_t) blps_meas_send_cmd_handler}, + {BLPS_RACP_RESP_SEND_CMD, (ke_msg_func_t) blps_racp_resp_send_cmd_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, +}; + +void blps_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + + p_task_desc->msg_handler_tab = blps_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(blps_msg_handler_tab); + p_task_desc->state = p_blps_env->state; + p_task_desc->idx_max = BLPS_IDX_MAX; +} + +#endif /* #if (BLE_BP_SENSOR) */ + +/// @} BLPSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/api/cgmc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/api/cgmc_task.h new file mode 100644 index 0000000..350c593 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/api/cgmc_task.h @@ -0,0 +1,460 @@ +/** + **************************************************************************************** + * + * @file cgmc_task.h + * + * @brief Header file - Continuous Glucose Monitoring Profile Collector/Client Role Task. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CGMC_TASK_H_ +#define _CGMC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup CGMCTASK Continuous Glucose Monitoring Collector Task + * @ingroup CGMC + * @brief Continuous Glucose Monitoring ProfileProfile Collector Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" +#include "prf_types.h" + +#include "cgmp_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// 30 seconds control point timeout timer +#define CGMC_CP_TIMEOUT (0x0BB8) +/// Maximum RACP size +#define CGMC_WR_RACP_CMD_SIZE_MAX (7) +/// CGM Feature data size +#define CGMC_FEAT_DATA_SIZE (4) +/// CGM Status data size (without E2E-CRC) +#define CGMC_STATUS_DATA_SIZE (5) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Message IDs +enum cgmc_msg_ids +{ + /// Enable the Profile Collector task - at connection + CGMC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_CGMC), + /// Response to Enable the Profile Collector task - at connection + CGMC_ENABLE_RSP, + ///*** CGMC CHARACTERISTIC REQUESTS + /// Read Characteristic + CGMC_READ_CMD, + /// Read Characteristic's CCC descriptor + CGMC_READ_CCC_CMD, + + /// Write Session Start Time Characteristic + CGMC_WRITE_SESS_START_TIME_CMD, + /// Configure Characteristic's CCC descriptor + CGMC_CFG_CCC_CMD, + /// Write Command to the Control Point + CGMC_WRITE_RACP_CMD, + /// Write Command to the Specific OPS Control Point + CGMC_WRITE_OPS_CTRL_PT_CMD, + /// Receive + /// * Continuous Measurement Notification + /// * Control Point Response Indication RACP_RESP + /// * Specific OPS Control Point Response Indication + /// Measurement + /// Record Access Control Point response + /// CGM Feature + /// CGM Status + /// CGM Session Start Time + /// CGM Session Run Time + /// CGM Specific OPS Control Point + CGMC_VALUE_IND, + /// Read CCC value of specific characteristic + CGMC_RD_CHAR_CCC_IND, + + /// Complete event for the Application commands + CGMC_CMP_EVT, + + /// Control Point Request Timeout + CGMC_CP_REQ_TIMEOUT, + +}; + +/// Continuous Glucose Monitoring Service Characteristics +enum cgmc_char_ids +{ + /// CGM Measurement Characteristic + CGMC_CHAR_MEAS = 0, + /// CGM Feature Characteristic + CGMC_CHAR_FEAT, + /// CGM Status Characteristic + CGMC_CHAR_STATUS, + /// CGM Session Start Time Characteristic + CGMC_CHAR_SESS_ST_TIME, + /// CGM Session Run Time Characteristic + CGMC_CHAR_SESS_RUN_TIME, + /// CGM Record Access Control Point Characteristic + CGMC_CHAR_RACP, + /// CGM Specific Ops Control Point Characteristic + CGMC_CHAR_SPEC_OPS_CTRL_PT, + + CGMC_CHAR_MAX, +}; + +/// Continuous Glucose Monitoring Service Characteristic Descriptors +enum cgmc_desc_ids +{ + /// CGM Measurement Characteristic Client Configuration + CGMC_DESC_MEAS_CCC = 0, + /// CGM Record Access Control Point Characteristic Client Configuration + CGMC_DESC_RACP_CCC, + /// CGM Specific Ops Control Point Characteristic Client Configuration + CGMC_DESC_SPEC_OPS_CTRL_PT_CCC, + + CGMC_DESC_MAX, +}; + + +/// Define command operation +enum cgmc_op_codes +{ + /// No Operations + CGMC_NO_OP = 0, + + /// Read CGM Feature Characteristic + CGMC_OP_CODE_READ_FEATURES = 1, + /// Read CGM Status Characteristic + CGMC_OP_CODE_READ_STATUS = 2, + /// Read Session Start Time Characteristic + CGMC_OP_CODE_READ_SESSION_START_TIME = 3, + /// Read Session Run Time Characteristic + CGMC_OP_CODE_READ_SESSION_RUN_TIME = 4, + /// Read CCC + CGMC_OP_CODE_READ_CCC = 5, + + /// Write Session Start Time Characteristic + CGMC_OP_CODE_WRITE_SESSION_START_TIME = 6, + /// Write CCC descriptor + CGMC_OP_CODE_WRITE_CCC = 7, + /// Write Record Access Control Point value + CGMC_OP_CODE_WRITE_CTRL_PT = 8, + /// Write Specific Ops Control Point value + CGMC_OP_CODE_WRITE_OPS_CTRL_PT = 9, + /// GATTC Register + CGMC_OP_CODE_GATTC_REGISTER = 10, + + /// Indications + /// Measurement Characteristic + CGMC_OP_CODE_MEASUREMENT = 11, + /// RACP Characteristic + CGMC_OP_CODE_RACP = 12, + /// Specific Ops Control Point Characteristic + CGMC_OP_CODE_SPECIFIC_OPS_CTRL_PT = 13, +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Continuous Glucose Monitoring Service + */ +struct cgmc_cgms_content +{ + /// service info + struct prf_svc svc; + + /// Characteristic info: + /// - Feature + /// - Measurement + struct prf_char_inf chars[CGMC_CHAR_MAX]; + + /// Descriptor handles: + /// - Client cfg + struct prf_char_desc_inf descs[CGMC_DESC_MAX]; +}; + +/// Parameters of the @see CGMC_ENABLE_REQ message +struct cgmc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values CGMC + struct cgmc_cgms_content cgmc; +}; + +/// Parameters of the @see CGMC_ENABLE_RSP message +struct cgmc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values CGMC + struct cgmc_cgms_content cgmc; +}; + +/// CGM Feature +struct cgmc_rd_feat_value +{ + /// If enabled in CGM Features @see common cgm_feat_bf + uint32_t cgm_feat; + /// Define the Type of Sample @see common enum cgmp_type_sample_id + uint8_t type_samp; + /// Define the Location of Sample @see common enum cgmp_sample_location_id + uint8_t samp_loc; +}; + +/// CGM Status +struct cgmc_rd_status +{ + /// The following values are defined for the Time Offset Field, specifying + /// the relative time difference of the single CGM values to the session + /// start time. Value: (0x0000 - 0xFFFF), + /// Description: (Time offset in minutes as offset to the Session Start Time). + uint16_t time_offset; + /// The Sensor Status Annunciation Field shall be attached to every CGM Measurement Record + /// to which the status applies. + uint8_t warning; + /// The Sensor Status Annunciation Field. - bitfield @see common enum cgm_meas_sensor_status_annuc_bf + uint8_t cal_temp; + /// The Sensor Status Annunciation Field. - bitfield @see common enum cgm_meas_sensor_status_annuc_bf + uint8_t annunc_status; +}; + +/// CGM Session Start Time +struct cgmc_rd_sess_start_time +{ + /// time of Session Start Time + struct prf_date_time sess_start_time; + /// (-48..+56) Offset from UTC in number of 15 minutes increments. + /// A value of -128 means that the time zone offset is not known. + /// The offset defined in this characteristic is constant, regardless whether daylight savings is in effect. + int8_t time_zone; + /// DSTOOffset @see common enum cgmp_dst_offset_id + uint8_t dst_offset; +}; + +/// CGM Session Run Time +struct cgmc_rd_sess_run_time +{ + /// Run time in minutes + uint16_t run_time; +}; + +///*** CGMC CHARACTERISTIC READ REQUESTS +/// Parameters of the @see CGMC_READ_CMD message +/// operations: CGMC_OP_CODE_READ_FEATURES = 1, +/// CGMC_OP_CODE_READ_STATUS = 2, +/// CGMC_OP_CODE_READ_SESSION_START_TIME = 3, +/// CGMC_OP_CODE_READ_SESSION_RUN_TIME = 4, + +struct cgmc_read_cmd +{ + /// Operation - select characteristic @see enum cgmc_op_codes + uint8_t operation; +}; + +/// Parameters of the @see CGMC_READ_CCC_CMD message +/// Read CCC values of a CGM characteristic +/// operations: CGMC_OP_CODE_MEASUREMENT = 11 +/// CGMC_OP_CODE_RACP = 12 +/// CGMC_OP_CODE_SPECIFIC_OPS_CTRL_PT = 13 +struct cgmc_read_ccc_cmd +{ + /// operation = char_opcode - select characteristic @see enum cgmc_op_codes + uint8_t operation; +}; + + +/// Parameters of the @see CGMC_WRITE_SESS_START_TIME_CMD message +struct cgmc_write_sess_start_time_cmd +{ + /// time of Session Start Time + struct prf_date_time sess_start_time; + /// (-48..+56) Offset from UTC in number of 15 minutes increments. + /// A value of -128 means that the time zone offset is not known. + /// The offset defined in this characteristic is constant, regardless whether daylight savings is in effect. + int8_t time_zone; + /// DSTOOffset @see common enum cgmp_dst_offset_id + uint8_t dst_offset; +}; + +///*** CGMC CHARACTERISTIC/CCC DESCRIPTOR WRITE REQUESTS +/// Parameters of the @see CGMC_CFG_CCC_CMD message +/// operation +struct cgmc_cfg_ccc_cmd +{ + /// operation = char_opcode - select characteristic @see enum cgmc_op_codes + uint8_t operation; + /// The Client Characteristic Configuration Value + uint16_t ccc; +}; + +/// Write Operation Command to the Control Point +/// Parameters of the @see CGMC_WRITE_RACP_CMD, +struct cgmc_write_racp_cmd +{ + /// Operation = CGMC_OP_CODE_RACP_CMD @see enum cgmc_op_codes + uint8_t operation; + /// Control Point OpCode @see enum cgmp_cp_opcodes_id + uint8_t cp_opcode; + /// Operator @see enum cgmp_cp_operator_id + uint8_t cp_operator; + /// Filter type + uint8_t filter_type; + /// Filter parameter + uint16_t min_time_offset; + /// Filter parameter + uint16_t max_time_offset; +}; + +/// Receive Features +/// * Receive Measurement Notification +/// * Receive Control Point Response Indication RACP_RESP +/// CGMC_VALUE_IND, + +/// Indication Record Access Control Point Response +struct cgmc_racp_rsp +{ + /// Control Point OpCode @see enum cgmp_cp_opcodes_id + uint8_t cp_opcode; + /// Request Control Point OpCode @see enum cgmp_cp_opcodes_id + uint8_t req_cp_opcode; + /// Control Point Operator @see enum cgmp_cp_operator_id + uint8_t cp_operator; + /// Response Code @see enum cgmp_racp_rsp_id + uint8_t rsp_code; + /// Number of Records + uint16_t records_num; +}; + +/// CGM Measurement Value +struct cgmc_meas_value +{ + /// The Size Field represents the size of the CGM Measurement record. + uint8_t size; + /// Presence of optional field - bit field @see common cgm_meas_flags_bf + uint8_t flags; + /// The CGM Glucose Concentration Field contains the CGM glucose concentration in mg/dL as a SFLOAT data type. + prf_sfloat gluc_concent; + /// The following values are defined for the Time Offset Field, specifying + /// the relative time difference of the single CGM values to the session + /// start time. Value: (0x0000 - 0xFFFF), + /// Description: (Time offset in minutes as offset to the Session Start Time). + uint16_t time_offset; + /// The Sensor Status Annunciation Field shall be attached to + /// every CGM Measurement Record to which the status applies. + /// bit field @see common cgm_meas_sensor_status_annuc_bf + uint8_t warn; + /// The Sensor Status Annunciation Field. - bit field @see common cgm_meas_sensor_status_annuc_bf + uint8_t cal_temp; + /// The Sensor Status Annunciation Field. - bit field @see common cgm_meas_sensor_status_annuc_bf + uint8_t status; + /// The CGM Trend Information Field contains the CGM Trend information in (mg/dL)/min as an SFLOAT data type. + /// This field is optional if the device supports CGM Trend information (Bit 15 in CGM Feature is set to 1) + /// otherwise excluded. + prf_sfloat trend_info; + /// This field contains the CGM Quality information in % as an SFLOAT data type. + /// The SFLOAT-Type is a 16-bit word comprising a signed 4-bit integer exponent + /// followed by a signed 12-bit Mantissa, each in twos-complement form. + /// This field is optional if the device supports CGM Quality (Bit 16 in CGM Feature is set to 1) + /// otherwise excluded. + prf_sfloat quality; +}; + +/// Specific OPS Control Point Response +struct cgmc_ops_ctrl_pt_rsp +{ + /// Control Point OpCode @see enum cgmp_spec_ops_opcodes_id + uint8_t opcode; + /// Op-code Response @see enum cgmp_spec_ops_cp_rsp_id + uint8_t response; + /// operand specific to opcode + union cgmp_ops_operand operand; +}; + +/// Indication the Record Access Control Point response +/// Indication CGM Measurement +/// Parameters of the @see CGMC_VALUE_IND, +struct cgmc_value_ind +{ + /// Operation @see enum cgmc_op_codes + uint8_t operation; + /// Value to indicate + union cgmc_meas_value_tag + { + /// Measurement + struct cgmc_meas_value meas; + /// Record Access Control Point response + struct cgmc_racp_rsp racp_rsp; + /// Specific Ops Control Point response + struct cgmc_ops_ctrl_pt_rsp ops_cp_rsp; + /// CGM Feature + struct cgmc_rd_feat_value feat; + /// CGM Status + struct cgmc_rd_status rd_status; + /// CGM Session Start Time + struct cgmc_rd_sess_start_time start_time; + /// CGM Session Run Time + struct cgmc_rd_sess_run_time run_time; + } value; +}; + +/// Inform Application about the Characteristic's CCC descriptor +/// Parameters of the @see CGMC_RD_CHAR_CCC_IND, +struct cgmc_rd_char_ccc_ind +{ + /// Char. Client Characteristic Configuration + uint16_t ind_cfg; +}; + +/// Write Operation Command to the Specific Ops Control Point +/// Parameters of the @see CGMC_WRITE_OPS_CTRL_PT_CMD, +struct cgmc_write_ops_ctrl_pt_cmd +{ + /// Operation = CGMC_OP_CODE_SPECIFIC_OPS_CTRL_PT @see enum cgmc_op_codes + uint8_t operation; + /// Control Point OpCode @see enum cgmp_spec_ops_opcodes_id + uint8_t opcode; + /// Op-code Response @see enum cgmp_spec_ops_cp_rsp_id + uint8_t response; + /// operand specific to opcode + union cgmp_ops_operand operand; +}; + +/// Complete event for the Application commands +/// Parameters of the @see CGMC_CMP_EVT message +struct cgmc_cmp_evt +{ + /// Operation @see enum cgmc_op_codes + uint8_t operation; + /// Status + uint8_t status; +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/// @} CGMCTASK + +#endif //(_CGMC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/sourcelist.txt new file mode 100644 index 0000000..5a06cc5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2017 +# +#*************************************************************************************** + + cgmc.c + cgmc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/src/cgmc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/src/cgmc.c new file mode 100644 index 0000000..6f49bff --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/src/cgmc.c @@ -0,0 +1,241 @@ +/** + **************************************************************************************** + * + * @file cgmc.c + * + * @brief Continuous Glucose Monitoring Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup CGMC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_CGM_CLIENT) +#include "prf.h" +#include "cgmp_common.h" + +#include "cgmc_task.h" +#include "cgmc.h" +#include "gap.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLES DECLARATION + **************************************************************************************** + */ + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the CGMC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t cgmc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct cgmc_env_tag *p_cgmc_env = + (struct cgmc_env_tag *) ke_malloc(sizeof(struct cgmc_env_tag), KE_MEM_ATT_DB); + + // allocate CGMC required environment variable + p_env->env = (prf_env_t *) p_cgmc_env; + + p_cgmc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_cgmc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_CGMC; + cgmc_task_init(&(p_env->desc)); + + for(idx = 0; idx < CGMC_IDX_MAX ; idx++) + { + p_cgmc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), CGMC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void cgmc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct cgmc_env_tag *p_cgmc_env = (struct cgmc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if(p_cgmc_env->p_env[conidx] != NULL) + { + ke_free(p_cgmc_env->p_env[conidx]); + p_cgmc_env->p_env[conidx] = NULL; + } + + /* Put WSCP Client in Free state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), CGMC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the CGMC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void cgmc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct cgmc_env_tag* p_cgmc_env = (struct cgmc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for(idx = 0; idx < CGMC_IDX_MAX ; idx++) + { + cgmc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_cgmc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void cgmc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + /* Put WSC Client in Idle state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), CGMC_IDLE); +} + +/// CGMC Task interface required by profile manager +const struct prf_task_cbs cgmc_itf = +{ + cgmc_init, + cgmc_destroy, + cgmc_create, + cgmc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* cgmc_prf_itf_get(void) +{ + return &cgmc_itf; +} + +void cgmc_enable_rsp_send(struct cgmc_env_tag *p_cgmc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on WSCP + struct cgmc_enable_rsp * p_rsp = KE_MSG_ALLOC( + CGMC_ENABLE_RSP, + prf_dst_task_get(&(p_cgmc_env->prf_env), conidx), + prf_src_task_get(&(p_cgmc_env->prf_env), conidx), + cgmc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + // Provide all Discovered Characteristics and Descriptors + p_rsp->cgmc = p_cgmc_env->p_env[conidx]->cgmc; + + // Register CGMC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_cgmc_env->prf_env), conidx, &(p_cgmc_env->p_env[conidx]->cgmc.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_cgmc_env->prf_env), conidx), CGMC_IDLE); + } + else + { + // Clean-up environment variable allocated for task instance + if(p_cgmc_env->p_env[conidx] != NULL) + { + ke_free(p_cgmc_env->p_env[conidx]); + p_cgmc_env->p_env[conidx] = NULL; + } + } + + ke_msg_send(p_rsp); +} + +void cgmc_send_cmp_evt(struct cgmc_env_tag *p_cgmc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct cgmc_cmp_evt *p_evt = NULL; + + // Go back to the CONNECTED state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_cgmc_env->prf_env), conidx)) == CGMC_BUSY) + { + ke_state_set(prf_src_task_get(&(p_cgmc_env->prf_env), conidx), CGMC_IDLE); + } + + // Send the message + p_evt = KE_MSG_ALLOC(CGMC_CMP_EVT,prf_dst_task_get(&(p_cgmc_env->prf_env), conidx), + prf_src_task_get(&(p_cgmc_env->prf_env), conidx), + cgmc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //(BLE_CGM_CLIENT) + +/// @} CGMC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/src/cgmc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/src/cgmc.h new file mode 100644 index 0000000..dbf07b9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/src/cgmc.h @@ -0,0 +1,203 @@ +/** + **************************************************************************************** + * + * @file cgmc.h + * + * @brief Header file - Continuous Glucose Monitoring Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CGMC_H_ +#define _CGMC_H_ + +/** + **************************************************************************************** + * @addtogroup CGMC Continuous Glucose Monitoring Profile Collector + * @ingroup CGMC + * @brief Continuous Glucose Monitoring Profile Collector + * @{ + **************************************************************************************** + */ + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Continuous Glucose Monitoring Task instances +#define CGMC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "cgmp_common.h" + +#if (BLE_CGM_CLIENT) + +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the CGMC task +enum cgmc_states +{ + /// Idle state + CGMC_FREE, + /// Connected state + CGMC_IDLE, + /// Discovering Services + CGMC_DISCOVERING_SVC, + /// Busy state + CGMC_BUSY, + /// Number of defined states. + CGMC_STATE_MAX +}; + +/// Operation Codes for pending operations in the client. +enum cgmc_op_pending +{ + /// Reserved operation code + CGMC_OP_PENDING_NO_OP = 0x00, + + /// Read op-codes + /// internal state when reading features after discovery + CGMC_OP_PENDING_READ_FEATURES_AT_INIT, + /// Read FEATURES as the result of the command request + CGMC_OP_PENDING_READ_FEATURES, + /// Read STATUS as the result of the command request + CGMC_OP_PENDING_READ_STATUS, + /// Read Session Start Time as the result of the command request + CGMC_OP_PENDING_READ_SESSION_START_TIME, + /// Read Session Run Time as the result of the command request + CGMC_OP_PENDING_READ_SESSION_RUN_TIME, + /// Read CCC + CGMC_OP_PENDING_READ_CCC, + + /// Write op-codes. + /// Write RACP characteristic + CGMC_OP_PENDING_WRITE_RACP, + /// Write Specific Ops Control Point characteristic + CGMC_OP_PENDING_WRITE_SPECIFIC_OPS_CTRL_PT, + /// Write CCC values + CGMC_OP_PENDING_WRITE_CCC, + +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Stored Environment content/context information for a connection +struct cgmc_cnx_env +{ + /// Current Operation + uint8_t op_pending; + /// If enabled in CGM Features @see enum cgm_feat_bf + uint32_t cgm_feature; + /// Define the Type of Sample @see enum cgmp_type_sample_id + uint8_t type_sample; + /// Define the Location of Sample @see common enum cgmp_sample_location_id + uint8_t sample_location; + + /// Counter used to check service uniqueness + uint8_t nb_svc; + + /// Continuous Glucose Monitoring Service Characteristics + struct cgmc_cgms_content cgmc; +}; + + +/// Continuous Glucose Monitoring environment variable +struct cgmc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct cgmc_cnx_env* p_env[CGMC_IDX_MAX]; + /// State of different task instances + ke_state_t state[CGMC_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Pool of Continuous Glucose Monitoring Collector task environments. +extern struct cgmc_env_tag **cgmc_envs; + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve Continuous Glucose Monitoring client profile interface + * + * @return CGM client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* cgmc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Continuous Glucose Monitoring ATT DB discovery results to CGMC host. + * + * @param[in] p_cgmc_env The profile environment for the connection + * @param[in] conidx Connection Identifier + * @param[in] status Indicates the outcome of the operation + * + * @return none. + **************************************************************************************** + */ +void cgmc_enable_rsp_send(struct cgmc_env_tag *p_cgmc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send a CGMC_CMP_EVT message to the task which enabled the profile + * + * @param[in] p_cgmc_env The profile environment + * @param[in] conidx Connection Identifier + * @param[in] operation Indicates the operation for which the cmp_evt is being sent. + * @param[in] status Indicates the outcome of the operation + * + * @return Error_Code. + **************************************************************************************** + */ +void cgmc_send_cmp_evt(struct cgmc_env_tag *p_cgmc_env, uint8_t conidx, uint8_t operation, uint8_t status); + + + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param task_desc Task descriptor to fill + **************************************************************************************** + */ +void cgmc_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_CGMP_CLIENT) + +/// @} CGMC + +#endif //(_CGMC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/src/cgmc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/src/cgmc_task.c new file mode 100644 index 0000000..d47d86f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmc/src/cgmc_task.c @@ -0,0 +1,1924 @@ +/** + **************************************************************************************** + * + * @file cgmc_task.c + * + * @brief Continuous Glucose Monitoring Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup CGMCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_CGM_CLIENT) +#include "cgmp_common.h" +#include "cgmc_task.h" +#include "cgmc.h" + +#include "gap.h" +#include "attm.h" +#include "gattc_task.h" +#include "ke_mem.h" +#include "ke_timer.h" +#include "co_utils.h" + + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve Continuous Glucose Monitoring Service characteristics information +const struct prf_char_def cgmc_cgm_char[CGMC_CHAR_MAX] = +{ + [CGMC_CHAR_MEAS] = {ATT_CHAR_CGM_MEASUREMENT, + ATT_MANDATORY, + (ATT_CHAR_PROP_NTF) }, + + [CGMC_CHAR_FEAT] = {ATT_CHAR_CGM_FEATURES, + ATT_MANDATORY, + (ATT_CHAR_PROP_RD) }, + + [CGMC_CHAR_STATUS] = {ATT_CHAR_CGM_STATUS, + ATT_MANDATORY, + (ATT_CHAR_PROP_RD) }, + + [CGMC_CHAR_SESS_ST_TIME] = {ATT_CHAR_CGM_SESSION_START, + ATT_MANDATORY, + (ATT_CHAR_PROP_WR | ATT_CHAR_PROP_RD) }, + + [CGMC_CHAR_SESS_RUN_TIME] = {ATT_CHAR_CGM_SESSION_RUN, + ATT_MANDATORY, + (ATT_CHAR_PROP_RD) }, + + [CGMC_CHAR_RACP] = {ATT_CHAR_REC_ACCESS_CTRL_PT, + ATT_MANDATORY, + (ATT_CHAR_PROP_WR | ATT_CHAR_PROP_IND) }, + + [CGMC_CHAR_SPEC_OPS_CTRL_PT] = {ATT_CHAR_CGM_SPECIFIC_OPS_CTRL_PT, + ATT_MANDATORY, + (ATT_CHAR_PROP_WR | ATT_CHAR_PROP_IND) }, +}; + +/// State machine used to retrieve Continuous Glucose Monitoring Service characteristic Description information +const struct prf_char_desc_def cgmc_cgm_char_desc[CGMC_DESC_MAX] = +{ + /// Client config + [CGMC_DESC_MEAS_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + CGMC_CHAR_MEAS}, + /// Client config + [CGMC_DESC_RACP_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + CGMC_CHAR_RACP}, + /// Client config + [CGMC_DESC_SPEC_OPS_CTRL_PT_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + CGMC_CHAR_SPEC_OPS_CTRL_PT}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @see GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CGMC_DISCOVERING_SVC) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Continuous Glucose Monitoring Collector Role Task Environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + + ASSERT_INFO(p_cgmc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_cgmc_env->p_env[conidx] != NULL, dest_id, src_id); + + if(attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_CONTINUOUS_GLUCOSE_MONITORING)) + { + // Retrieve CGMS characteristics and descriptors + prf_extract_svc_info(p_ind, CGMC_CHAR_MAX, &cgmc_cgm_char[0], &p_cgmc_env->p_env[conidx]->cgmc.chars[0], + CGMC_DESC_MAX, &cgmc_cgm_char_desc[0], &p_cgmc_env->p_env[conidx]->cgmc.descs[0]); + + // Even if we get multiple responses we only store 1 range + p_cgmc_env->p_env[conidx]->cgmc.svc.shdl = p_ind->start_hdl; + p_cgmc_env->p_env[conidx]->cgmc.svc.ehdl = p_ind->end_hdl; + + p_cgmc_env->p_env[conidx]->nb_svc++; + } + } + + return (KE_MSG_CONSUMED); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMC_ENABLE_REQ message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int cgmc_enable_req_handler(ke_msg_id_t const msgid, + struct cgmc_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + // Continuous Glucose Monitoring Collector Role Task Environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + + ASSERT_INFO(p_cgmc_env != NULL, dest_id, src_id); + if ((state == CGMC_IDLE) && (p_cgmc_env->p_env[conidx] == NULL)) + { + // Allocate environment variable for task instance + p_cgmc_env->p_env[conidx] = (struct cgmc_cnx_env*) ke_malloc(sizeof(struct cgmc_cnx_env), KE_MEM_ATT_DB); + memset(p_cgmc_env->p_env[conidx], 0, sizeof(struct cgmc_cnx_env)); + + // Start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + // Start discovery with Continuous Glucose Monitoring + prf_disc_svc_send(&(p_cgmc_env->prf_env), conidx, ATT_SVC_CONTINUOUS_GLUCOSE_MONITORING); + + // Go to DISCOVERING SERVICE state + ke_state_set(dest_id, CGMC_DISCOVERING_SVC); + } + // Normal connection, get saved att details + else + { + uint16_t search_hdl; + struct prf_svc *p_svc; + + p_cgmc_env->p_env[conidx]->cgmc = p_param->cgmc; + + // Get Features handle + search_hdl = p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_FEAT].val_hdl; + // Service + p_svc = &p_cgmc_env->p_env[conidx]->cgmc.svc; + + // Check if handle is viable + if ((p_svc != NULL) && (search_hdl != ATT_INVALID_SEARCH_HANDLE)) + { + // Force the operation value + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_READ_FEATURES_AT_INIT; + + // Send the write request + prf_read_char_send(&(p_cgmc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, CGMC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + } + } + else if (state != CGMC_FREE) + { + // The message will be forwarded towards the good task instance + status = PRF_ERR_REQ_DISALLOWED; + } + + if(status != GAP_ERR_NO_ERROR) + { + // The request is disallowed (profile already enabled for this connection, or not enough memory, ...) + cgmc_enable_rsp_send(p_cgmc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMC_READ_CMD message from the application. + * To read the Feature Characteristic in the peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int cgmc_read_cmd_handler(ke_msg_id_t const msgid, + struct cgmc_read_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == CGMC_IDLE) + { + ASSERT_INFO(p_cgmc_env != NULL, dest_id, src_id); + // Environment variable not ready + if(p_cgmc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Service + struct prf_svc *p_svc = &p_cgmc_env->p_env[conidx]->cgmc.svc; + + if ((p_svc != NULL) && (p_svc->shdl != ATT_INVALID_SEARCH_HANDLE)) + { + if (p_param->operation == CGMC_OP_CODE_READ_FEATURES) + { + // Immediate results as features kept in the profile + // Send value ind and next complete event. + // Build a CGMC_VALUE_IND message + struct cgmc_value_ind *p_ind = KE_MSG_ALLOC(CGMC_VALUE_IND, + prf_dst_task_get(&p_cgmc_env->prf_env, conidx), + prf_src_task_get(&p_cgmc_env->prf_env, conidx), + cgmc_value_ind); + + p_ind->operation = CGMC_OP_CODE_READ_FEATURES; + p_ind->value.feat.cgm_feat = p_cgmc_env->p_env[conidx]->cgm_feature; + p_ind->value.feat.type_samp = p_cgmc_env->p_env[conidx]->type_sample; + p_ind->value.feat.samp_loc = p_cgmc_env->p_env[conidx]->sample_location; + + // Send indication to the application + ke_msg_send(p_ind); + + status = GAP_ERR_NO_ERROR; + cgmc_send_cmp_evt(p_cgmc_env, conidx, CGMC_OP_CODE_READ_FEATURES, status); + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_NO_OP; + + return msg_status; + } + else if (p_param->operation == CGMC_OP_CODE_READ_STATUS) + { + handle = p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_STATUS].val_hdl; + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_READ_STATUS; + } + else if (p_param->operation == CGMC_OP_CODE_READ_SESSION_START_TIME) + { + handle = p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_SESS_ST_TIME].val_hdl; + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_READ_SESSION_START_TIME; + } + else if (p_param->operation == CGMC_OP_CODE_READ_SESSION_RUN_TIME) + { + handle = p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_SESS_RUN_TIME].val_hdl; + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_READ_SESSION_RUN_TIME; + } + } + + // Check if handle is viable + if (handle != ATT_INVALID_SEARCH_HANDLE) + { + // Send the read request + prf_read_char_send(&(p_cgmc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, handle); + // Go to the Busy state + ke_state_set(dest_id, CGMC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == CGMC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + cgmc_send_cmp_evt(p_cgmc_env, conidx, p_param->operation, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMC_READ_CCC_CMD message. + * Allows the application to read CCC values in the peer server + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cgmc_read_ccc_cmd_handler(ke_msg_id_t const msgid, + struct cgmc_read_ccc_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Get the address of the environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + + if (state == CGMC_IDLE) + { + ASSERT_INFO(p_cgmc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_cgmc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = ATT_INVALID_SEARCH_HANDLE; + // Service + struct prf_svc *p_svc = &p_cgmc_env->p_env[conidx]->cgmc.svc; + + if (p_param->operation == CGMC_OP_CODE_MEASUREMENT) + { + search_hdl = p_cgmc_env->p_env[conidx]->cgmc.descs[CGMC_DESC_MEAS_CCC].desc_hdl; + } + else if (p_param->operation == CGMC_OP_CODE_RACP) + { + search_hdl = p_cgmc_env->p_env[conidx]->cgmc.descs[CGMC_DESC_RACP_CCC].desc_hdl; + } + else if (p_param->operation == CGMC_OP_CODE_SPECIFIC_OPS_CTRL_PT) + { + search_hdl = p_cgmc_env->p_env[conidx]->cgmc.descs[CGMC_DESC_SPEC_OPS_CTRL_PT_CCC].desc_hdl; + } + + // Check if handle is viable + if ((p_svc != NULL) && (search_hdl != ATT_INVALID_SEARCH_HANDLE)) + { + // Force the operation value + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_READ_CCC; + + // Send read request + prf_read_char_send(&(p_cgmc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + + // Go to the Busy state + ke_state_set(dest_id, CGMC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == CGMC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + } + + if (status != GAP_ERR_NO_ERROR) + { + cgmc_send_cmp_evt(p_cgmc_env, conidx, CGMC_OP_CODE_READ_CCC, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMC_WRITE_SESS_START_TIME_CMD message from the application. + * To write command to the Records Access Control Point in the peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int cgmc_write_sess_start_time_cmd_handler(ke_msg_id_t const msgid, + struct cgmc_write_sess_start_time_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == CGMC_IDLE) + { + ASSERT_INFO(p_cgmc_env != NULL, dest_id, src_id); + // Environment variable not ready + if(p_cgmc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_SESS_ST_TIME].val_hdl; + // Service + struct prf_svc *p_svc = &p_cgmc_env->p_env[conidx]->cgmc.svc; + + // Check if handle is viable + if ((p_svc != NULL) && (search_hdl != ATT_INVALID_SEARCH_HANDLE)) + { + // Length (7 -packed data 1 - zone 1- offset, 2-CRC) + uint8_t length = CGMP_SESS_ST_TIME_SIZE_MAX; + uint8_t data[CGMP_SESS_ST_TIME_SIZE_MAX]; + + // Fill parameters + prf_pack_date_time(&data[0], &p_param->sess_start_time); + data[PRF_CHAR_PRES_FMT_SIZE] = p_param->time_zone; + data[PRF_CHAR_PRES_FMT_SIZE + 1] = p_param->dst_offset; + + // Add E2E-CRC + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + uint16_t crc = prf_e2e_crc(&data[0],length - CGMP_CRC_LEN); + + co_write16p(&data[length-CGMP_CRC_LEN], crc); + } + else + { + // Minus E2E-CRC length + length -= sizeof(uint16_t); + } + + // Force the operation value + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_CODE_WRITE_SESSION_START_TIME; + + // Send the write request + prf_gatt_write(&(p_cgmc_env->prf_env), conidx, search_hdl, &data[0], length, GATTC_WRITE); + // Go to the Busy state + ke_state_set(dest_id, CGMC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == CGMC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + cgmc_send_cmp_evt(p_cgmc_env, conidx, CGMC_OP_CODE_WRITE_CTRL_PT, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMC_WRITE_RACP_CMD message from the application. + * To write command to the Records Access Control Point in the peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int cgmc_write_racp_cmd_handler(ke_msg_id_t const msgid, + struct cgmc_write_racp_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == CGMC_IDLE) + { + ASSERT_INFO(p_cgmc_env != NULL, dest_id, src_id); + // environment variable not ready + if(p_cgmc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Service + struct prf_svc *p_svc = &p_cgmc_env->p_env[conidx]->cgmc.svc; + // Attribute Handle + uint16_t search_hdl = p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_RACP].val_hdl; + + if ((p_svc != NULL) && (search_hdl != ATT_INVALID_SEARCH_HANDLE)) + { + // Length: op_code+operand + filter +2x2byte time offset + uint8_t length = CGMC_WR_RACP_CMD_SIZE_MAX; + uint8_t data[CGMC_WR_RACP_CMD_SIZE_MAX]; + + // fill parameters + data[0] = p_param->cp_opcode; + data[1] = p_param->cp_operator; + + switch (p_param->cp_opcode) + { + case CGMP_OPCODE_REP_STRD_RECS: + case CGMP_OPCODE_REP_NUM_OF_STRD_RECS: + case CGMP_OPCODE_DEL_STRD_RECS: + { + switch (p_param->cp_operator) + { + case CGMP_OP_LT_OR_EQ: + { + // filter type is normally: CGMP_FILTER_TIME_OFFSET + data[2] = p_param->filter_type; + co_write16p(&data[3], p_param->max_time_offset); + length = CGMC_WR_RACP_CMD_SIZE_MAX - 2; + } break; + + case CGMP_OP_GT_OR_EQ: + { + // filter type is normally: CGMP_FILTER_TIME_OFFSET + data[2] = p_param->filter_type; + co_write16p(&data[3], p_param->min_time_offset); + length = CGMC_WR_RACP_CMD_SIZE_MAX - 2; + } break; + + case CGMP_OP_WITHIN_RANGE_OF: + { + // filter type is normally: CGMP_FILTER_TIME_OFFSET + data[2] = p_param->filter_type; + co_write16p(&data[3], p_param->min_time_offset); + co_write16p(&data[5], p_param->max_time_offset); + length = CGMC_WR_RACP_CMD_SIZE_MAX; + } break; + + case CGMP_OP_ALL_RECS: + case CGMP_OP_FIRST_REC: + case CGMP_OP_LAST_REC: + default: + { + // send across anyway + length = 2; + } break; + } + } break; + + case CGMP_OPCODE_ABORT_OP: + { + // fill parameters + data[1] = CGMP_OP_NULL; // only + length = 2; + } break; + + default: + { + // send across anyway + length = 2; + } break; + } + + // Force the operation value + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_WRITE_RACP; + + // Send the write request + prf_gatt_write(&(p_cgmc_env->prf_env), conidx, search_hdl, &data[0], length, GATTC_WRITE); + // Go to the Busy state + ke_state_set(dest_id, CGMC_BUSY); + // start the timer; will destroy the link if it expires + ke_timer_set(CGMC_CP_REQ_TIMEOUT, dest_id, 10*CGMC_CP_TIMEOUT); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == CGMC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + cgmc_send_cmp_evt(p_cgmc_env, conidx, CGMC_OP_CODE_WRITE_CTRL_PT, status); + } + + return msg_status; +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMC_WRITE_OPS_CTRL_PT_CMD message from the application. + * To write command to the Specific Ops Control Point in the peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int cgmc_write_ops_ctrl_pt_cmd_handler(ke_msg_id_t const msgid, + struct cgmc_write_ops_ctrl_pt_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // data pointer + uint8_t *p_data; + + if (state == CGMC_IDLE) + { + ASSERT_INFO(p_cgmc_env != NULL, dest_id, src_id); + // environment variable not ready + if(p_cgmc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_SPEC_OPS_CTRL_PT].val_hdl; + // Service + struct prf_svc *p_svc = &p_cgmc_env->p_env[conidx]->cgmc.svc; + + // Length + uint8_t length= 2 * sizeof(uint8_t); //min size response consist of opcode & response + uint8_t data[(2 + CGMP_CALIBR_SIZE + CGMP_CRC_LEN)]; + + // Check if handle is viable + if ((p_svc != NULL) && (search_hdl != ATT_INVALID_SEARCH_HANDLE)) + { + // treat request as correct + status = GAP_ERR_NO_ERROR; + // fill parameters + data[0] = p_param->opcode; + data[1] = p_param->response; + + p_data = &(data[2]); + + switch(p_param->opcode) + { + case CGMP_OPS_CODE_SET_CGM_COM_INTVL: // 1, + { + co_write16p(p_data, p_param->operand.intvl); + p_data += 2; + length += 2; + } break; + case CGMP_OPS_CODE_SET_GLUC_CALIB_VALUE: // 4, + { + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_CALIB_SUP)) + { + // Glucose Concentration at Calibration + co_write16p(p_data, p_param->operand.calib.cal_gluc_concent); + p_data += 2; + length += 2; + // Calibration Time in minutes + co_write16p(p_data, p_param->operand.calib.cal_time); + p_data += 2; + length += 2; + // Calibration Type of Sample @see common enum cgmp_type_sample_id + *p_data++ = p_param->operand.calib.cal_type_spl; + length++; + // Calibration Location of Sample @see common enum cgmp_sample_location_id + *p_data++ = p_param->operand.calib.cal_spl_loc; + length++; + // Next Calibration Time in minutes + co_write16p(p_data, p_param->operand.calib.next_cal_time); + p_data += 2; + length += 2; + // Calibration Record Number + co_write16p(p_data, p_param->operand.calib.cal_record_num); + p_data += 2; + length += 2; + // Calibration Status - bitfield @see common enum cgmp_calib_status_bf + *p_data++ = p_param->operand.calib.cal_status; + length++; + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_GET_GLUC_CALIB_VALUE: // 5, + { + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_CALIB_SUP)) + { + // Calibration Record Number + co_write16p(p_data, p_param->operand.cal_data_record_num); + p_data += 2; + length += 2; + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_SET_PAT_HIGH_ALERT_LEVEL: // 7, + { + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_PAT_HIGH_LOW_ALERT_SUP)) + { + co_write16p(p_data, p_param->operand.pat_high_bg); + p_data += 2; + length += 2; + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_SET_PAT_LOW_ALERT_LEVEL: // 10, + { + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_PAT_HIGH_LOW_ALERT_SUP)) + { + co_write16p(p_data, p_param->operand.pat_low_bg); + p_data += 2; + length += 2; + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_SET_HYPO_ALERT_LEVEL: // 13, + { + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_HYPO_ALERT_SUP)) + { + co_write16p(p_data, p_param->operand.hypo_alert_level); + p_data += 2; + length += 2; + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_SET_HYPER_ALERT_LEVEL: // 16, + { + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_HYPER_ALERT_SUP)) + { + co_write16p(p_data, p_param->operand.hyper_alert_level); + p_data += 2; + length += 2; + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_SET_RATE_OF_DECR_ALERT_LEVEL: // 19, + { + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_RATE_OF_INCR_DECR_ALERT_SUP)) + { + co_write16p(p_data, p_param->operand.rate_decr_alert_level); + p_data += 2; + length += 2; + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_SET_RATE_OF_INCR_ALERT_LEVEL: // 22, + { + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_RATE_OF_INCR_DECR_ALERT_SUP)) + { + co_write16p(p_data, p_param->operand.rate_incr_alert_level); + p_data += 2; + length += 2; + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + // valid codes with no parameters + case CGMP_OPS_CODE_GET_CGM_COM_INTVL: // 2, + case CGMP_OPS_CODE_START_SESS: // 26, + case CGMP_OPS_CODE_STOP_SESS: // 27, + { + + } break; + + case CGMP_OPS_CODE_GET_PAT_HIGH_ALERT_LEVEL: // 8, + case CGMP_OPS_CODE_GET_PAT_LOW_ALERT_LEVEL: // 11, + { + if (!GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_PAT_HIGH_LOW_ALERT_SUP)) + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_GET_HYPO_ALERT_LEVEL: // 14, + { + if (!GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_HYPO_ALERT_SUP)) + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_GET_HYPER_ALERT_LEVEL: // 17, + { + if (!GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_HYPER_ALERT_SUP)) + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_GET_RATE_OF_DECR_ALERT_LEVEL: // 20, + case CGMP_OPS_CODE_GET_RATE_OF_INCR_ALERT_LEVEL: // 23, + { + if (!GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_RATE_OF_INCR_DECR_ALERT_SUP)) + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case CGMP_OPS_CODE_RESET_DEV_SPEC_ALERT: // 25, + { + if (!GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_DEV_SPEC_ALERT_SUP)) + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + // invalid codes for request + case CGMP_OPS_CODE_CGM_COM_INTVL_RSP: // 3, + case CGMP_OPS_CODE_GLUC_CALIB_VALUE_RSP: // 6, + case CGMP_OPS_CODE_PAT_HIGH_ALERT_LEVEL_RSP: // 9, + case CGMP_OPS_CODE_PAT_LOW_ALERT_LEVEL_RSP: // 12, + case CGMP_OPS_CODE_HYPO_ALERT_LEVEL_RSP: // 15, + case CGMP_OPS_CODE_HYPER_ALERT_LEVEL_RSP: // 18, + case CGMP_OPS_CODE_RATE_OF_DECR_ALERT_LEVEL_RSP: // 21, + case CGMP_OPS_CODE_RATE_OF_INCR_ALERT_LEVEL_RSP: // 24, + case CGMP_OPS_CODE_RSP_CODE: // 28, + default : + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + if (status == GAP_ERR_NO_ERROR) + { + // add E2E-CRC if applicable + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + uint16_t crc = prf_e2e_crc(&data[0],length); + + co_write16p(p_data, crc); + p_data +=CGMP_CRC_LEN; + length += CGMP_CRC_LEN; + } + + // Force the operation value + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_WRITE_SPECIFIC_OPS_CTRL_PT; + + // Send the write request + prf_gatt_write(&(p_cgmc_env->prf_env), conidx, search_hdl, &data[0], length, GATTC_WRITE); + // Go to the Busy state + ke_state_set(dest_id, CGMC_BUSY); + // start the timer; will destroy the link if it expires + ke_timer_set(CGMC_CP_REQ_TIMEOUT, dest_id, 10*CGMC_CP_TIMEOUT); + } + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == CGMC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + if (p_cgmc_env->p_env[conidx]->op_pending == CGMC_OP_PENDING_WRITE_SPECIFIC_OPS_CTRL_PT) + { + // Another Control Point request is pending + status = PRF_PROC_IN_PROGRESS; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + cgmc_send_cmp_evt(p_cgmc_env, conidx, CGMC_OP_CODE_WRITE_CTRL_PT, status); + } + + return msg_status; +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMC_CFG_CCC_CMD message. + * Allows the application to write new CCC values to a Alert Characteristic in the peer server + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cgmc_cfg_ccc_cmd_handler(ke_msg_id_t const msgid, + struct cgmc_cfg_ccc_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Get the address of the environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + + if (state == CGMC_IDLE) + { + ASSERT_INFO(p_cgmc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_cgmc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Service + struct prf_svc *p_svc = &p_cgmc_env->p_env[conidx]->cgmc.svc; + + if (p_param->operation == CGMC_OP_CODE_MEASUREMENT) + { + handle = p_cgmc_env->p_env[conidx]->cgmc.descs[CGMC_DESC_MEAS_CCC].desc_hdl; + } + else if (p_param->operation == CGMC_OP_CODE_RACP) + { + handle = p_cgmc_env->p_env[conidx]->cgmc.descs[CGMC_DESC_RACP_CCC].desc_hdl; + } + else if (p_param->operation == CGMC_OP_CODE_SPECIFIC_OPS_CTRL_PT) + { + handle = p_cgmc_env->p_env[conidx]->cgmc.descs[CGMC_DESC_SPEC_OPS_CTRL_PT_CCC].desc_hdl; + } + + // Check if handle is viable + if ((p_svc != NULL) && (handle != ATT_INVALID_SEARCH_HANDLE)) + { + // Force the operation value + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_WRITE_CCC; + + // Send the write request + prf_gatt_write_ntf_ind(&(p_cgmc_env->prf_env), conidx, handle, p_param->ccc); + + // Go to the Busy state + ke_state_set(dest_id, CGMC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == CGMC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + } + + if (status != GAP_ERR_NO_ERROR) + { + cgmc_send_cmp_evt(p_cgmc_env, conidx, CGMC_OP_CODE_WRITE_CCC, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see GATTC_CMP_EVT message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + + if (p_cgmc_env != NULL) + { + // Status + uint8_t status = PRF_APP_ERROR; + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == CGMC_DISCOVERING_SVC) + { + // clean state for the new discovering + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_NO_OP; + + if ((p_param->status == GAP_ERR_NO_ERROR) || (p_param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)) + { + // Check service (if found) + if (p_cgmc_env->p_env[conidx]->nb_svc) + { + // Check service (mandatory) + status = prf_check_svc_char_validity(CGMC_CHAR_MAX, + p_cgmc_env->p_env[conidx]->cgmc.chars, + cgmc_cgm_char); + + // Check Descriptors (mandatory) + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(CGMC_DESC_MAX, + p_cgmc_env->p_env[conidx]->cgmc.descs, + cgmc_cgm_char_desc, + p_cgmc_env->p_env[conidx]->cgmc.chars); + } + } + } + + // request read FEATURES + if (status == GAP_ERR_NO_ERROR) + { + // Attribute Handle + uint16_t search_hdl = p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_FEAT].val_hdl; + // Service + struct prf_svc *p_svc = &p_cgmc_env->p_env[conidx]->cgmc.svc; + + // Check if handle is viable + if ((p_svc != NULL) && (search_hdl != ATT_INVALID_SEARCH_HANDLE)) + { + // Force the operation value + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_READ_FEATURES_AT_INIT; + + // Send the read request + prf_read_char_send(&(p_cgmc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, CGMC_BUSY); + } + else + { + // Raise an CGMC_ENABLE_REQ complete event. + // Was an issue reading features + status = ATT_ERR_INVALID_HANDLE; + } + } + + // at this stage we send response only if it fail in some case + if (status != GAP_ERR_NO_ERROR) + { + // Raise an CGMC_ENABLE_REQ complete event. + ke_state_set(dest_id, CGMC_IDLE); + + cgmc_enable_rsp_send(p_cgmc_env, conidx, p_param->status); + } + } + else if (state == CGMC_BUSY) + { + uint8_t op_pending = p_cgmc_env->p_env[conidx]->op_pending; + + status = p_param->status; + switch (p_param->operation) + { + case GATTC_READ: + { + // Send the complete event status + switch(op_pending) + { + case CGMC_OP_PENDING_READ_FEATURES_AT_INIT: + { + // Raise an CGMC_ENABLE_REQ complete event. + // Was an issue reading features + cgmc_enable_rsp_send(p_cgmc_env, conidx, status); + } break; + + case CGMC_OP_PENDING_READ_FEATURES: + { + // Send read complete event. + cgmc_send_cmp_evt(p_cgmc_env, conidx, CGMC_OP_CODE_READ_FEATURES, status); + } break; + + case CGMC_OP_PENDING_READ_CCC: + { + // Send read complete event. + cgmc_send_cmp_evt(p_cgmc_env, conidx, CGMC_OP_CODE_READ_CCC, status); + } break; + + default: + { + // Do nothing + } break; + } + + ke_state_set(dest_id, CGMC_IDLE); + } + break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + uint8_t operation = CGMC_OP_PENDING_NO_OP; + + switch(op_pending) + { + case CGMC_OP_PENDING_WRITE_RACP: + { + operation = CGMC_OP_CODE_WRITE_CTRL_PT; + } break; + + case CGMC_OP_CODE_WRITE_SESSION_START_TIME: + { + operation = CGMC_OP_CODE_WRITE_SESSION_START_TIME; + } break; + + case CGMC_OP_PENDING_WRITE_CCC: + { + operation = CGMC_OP_CODE_WRITE_CCC; + } break; + + case CGMC_OP_PENDING_WRITE_SPECIFIC_OPS_CTRL_PT: + { + operation = CGMC_OP_CODE_WRITE_OPS_CTRL_PT; + } break; + + default: + { + // Do nothing + } break; + } + + // Send the complete event status + cgmc_send_cmp_evt(p_cgmc_env, conidx, operation, p_param->status); + ke_state_set(dest_id, CGMC_IDLE); + + } break; + + case GATTC_REGISTER: + { + if (status != GAP_ERR_NO_ERROR) + { + // Send the complete event error status + cgmc_send_cmp_evt(p_cgmc_env, conidx, CGMC_OP_CODE_GATTC_REGISTER, p_param->status); + } + + // Go to connected state + ke_state_set(dest_id, CGMC_IDLE); + } break; + + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_NO_OP; + } + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CGMC_BUSY) + { + // Get the address of the environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + uint8_t conidx = KE_IDX_GET(dest_id); + // Service + uint8_t op_pending; + uint8_t status = GAP_ERR_NO_ERROR; + + // E2E crc field + uint16_t feature_crc; + // Calculated crc + // e2e crc to protect the fields + // predefined value when crc is not supported + // this field exist in all the cases + uint16_t crc = 0xFFFF; + + // Send value ind and next complete event. + // indication in a CGMC_VALUE_IND message + struct cgmc_value_ind *p_ind; + + // Flag to check if we need to return IDLE state + uint8_t to_idle = 0; + + ASSERT_INFO(p_cgmc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_cgmc_env->p_env[conidx] != NULL, dest_id, src_id); + + // Find the op_pending - and check it is a valid read code. + op_pending = p_cgmc_env->p_env[conidx]->op_pending; + + switch (op_pending) + { + case CGMC_OP_PENDING_READ_FEATURES_AT_INIT: + case CGMC_OP_PENDING_READ_FEATURES: + { + // If enabled in CGM Features @see common cgm_features + uint32_t cgm_feature; + + cgm_feature = co_read24p(&p_param->value[0]); + + // check if E2E-CRC is supported + if (GETB(cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + crc = prf_e2e_crc(&p_param->value[0], CGMC_FEAT_DATA_SIZE); // 24bits 4bit 4bits + feature_crc = co_read16p(&p_param->value[CGMC_FEAT_DATA_SIZE]); + + // only take reading if crc match + if (feature_crc != crc) + { + status = CGM_ERROR_INVALID_CRC; + } + } + + p_cgmc_env->p_env[conidx]->cgm_feature = cgm_feature; + // Get 4 bits LSB for type sample + p_cgmc_env->p_env[conidx]->type_sample = (p_param->value[CGMC_FEAT_DATA_SIZE - 1]) & 0x0F; + // Get 4 bits MSB for type sample + p_cgmc_env->p_env[conidx]->sample_location = (p_param->value[CGMC_FEAT_DATA_SIZE - 1] >> 4) & 0x0F; + + if (op_pending == CGMC_OP_PENDING_READ_FEATURES_AT_INIT) + { + // Raise an CGMC_ENABLE_RSP complete event. + cgmc_enable_rsp_send(p_cgmc_env, conidx, status); + // no need for complete event at the end + status = GAP_ERR_NO_ERROR; + } + + to_idle = 1; + } break; + + case CGMC_OP_PENDING_READ_STATUS: + case CGMC_OP_PENDING_READ_SESSION_START_TIME: + case CGMC_OP_PENDING_READ_SESSION_RUN_TIME: + { + // Offset + uint8_t offs = 0; + // Operation code for CMP EVT + uint8_t op_code = CGMC_NO_OP; + + // Send value ind and next complete event. + p_ind = KE_MSG_ALLOC(CGMC_VALUE_IND, + prf_dst_task_get(&p_cgmc_env->prf_env, conidx), + prf_src_task_get(&p_cgmc_env->prf_env, conidx), + cgmc_value_ind); + + if (op_pending == CGMC_OP_PENDING_READ_STATUS) + { + p_ind->operation = CGMC_OP_CODE_READ_STATUS; + p_ind->value.rd_status.time_offset = co_read16p(&p_param->value[0]); + p_ind->value.rd_status.warning = p_param->value[2]; + p_ind->value.rd_status.cal_temp = p_param->value[3]; + p_ind->value.rd_status.annunc_status = p_param->value[4]; + offs = CGMC_STATUS_DATA_SIZE; + + op_code = CGMC_OP_CODE_READ_STATUS; + } + else if (op_pending == CGMC_OP_PENDING_READ_SESSION_START_TIME) + { + p_ind->operation = CGMC_OP_CODE_READ_SESSION_START_TIME; + offs = prf_unpack_date_time((uint8_t *) &(p_param->value[0]), + &(p_ind->value.start_time.sess_start_time)); + p_ind->value.start_time.time_zone = p_param->value[offs]; + p_ind->value.start_time.dst_offset = p_param->value[offs+1]; + offs += 2; + + op_code = CGMC_OP_CODE_READ_SESSION_START_TIME; + } + else if (op_pending == CGMC_OP_PENDING_READ_SESSION_RUN_TIME) + { + p_ind->operation = CGMC_OP_CODE_READ_SESSION_RUN_TIME; + p_ind->value.run_time.run_time = co_read16p(&p_param->value[0]); + offs = 2; + + op_code = CGMC_OP_CODE_READ_SESSION_RUN_TIME; + } + + // check E2E-CRC + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + if (p_param->length < (offs+2)) // 16bit 24bits +16bit CRC + { + status = CGM_ERROR_MISSING_CRC; + } + else + { + feature_crc = co_read16p(&p_param->value[offs]); + crc = prf_e2e_crc(&p_param->value[0], offs); // 16bit 24bits + // only take reading if crc match + if (feature_crc != crc) + { + status = CGM_ERROR_INVALID_CRC; + } + } + } + + if (status == GAP_ERR_NO_ERROR) + { + // send indication to the application + ke_msg_send(p_ind); + } + else + { + // No need to send prepared message + KE_MSG_FREE(p_ind); + } + + to_idle = 1; + + // event complete sent as a result of operation command request + cgmc_send_cmp_evt(p_cgmc_env, conidx, op_code, status); + + } break; + + case CGMC_OP_PENDING_READ_CCC: + { + struct cgmc_rd_char_ccc_ind *p_ind = KE_MSG_ALLOC(CGMC_RD_CHAR_CCC_IND, + prf_dst_task_get(&(p_cgmc_env->prf_env), conidx), + dest_id, + cgmc_rd_char_ccc_ind); + + p_ind->ind_cfg = co_read16p(&p_param->value[0]); + + ke_msg_send(p_ind); + + // Keep the Busy state to be treated in gattc_cmp_evt_handler + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + // return to IDLE state + if (to_idle) + { + // translation from op_pending to NO_OP opcode + p_cgmc_env->p_env[conidx]->op_pending = CGMC_OP_PENDING_NO_OP; + + ke_state_set(dest_id, CGMC_IDLE); + } + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see GATTC_EVENT_IND message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + + do + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Data pointer + const uint8_t *p_data; + // Length of data block + uint16_t length = p_param->length; + // E2E crc field + uint16_t feature_crc; + // Calculated crc + // e2e crc to protect the fields + uint16_t crc; + // Build a CGMC_VALUE_IND message + struct cgmc_value_ind *p_ind = NULL; + + if (p_cgmc_env == NULL) + { + break; + } + + if ((p_param->type != GATTC_INDICATE) && (p_param->type != GATTC_NOTIFY)) + { + break; + } + + if (p_param->handle == p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_RACP].val_hdl) + { + // No crc for legacy reasons + p_ind = KE_MSG_ALLOC(CGMC_VALUE_IND, + prf_dst_task_get(&p_cgmc_env->prf_env, conidx), + prf_src_task_get(&p_cgmc_env->prf_env, conidx), + cgmc_value_ind); + memset(p_ind, 0, sizeof(struct cgmc_value_ind)); + + p_ind->operation = CGMC_OP_CODE_RACP; + // RACP response carry number of records or Requested OpCode+ Response code + p_ind->value.racp_rsp.cp_opcode = p_param->value[0]; + // RACP operator should be indicated (normally an Operator of NULL 0x00) + p_ind->value.racp_rsp.cp_operator = p_param->value[1]; + + if (p_param->value[0] == CGMP_OPCODE_NUM_OF_STRD_RECS_RSP) + { + p_ind->value.racp_rsp.records_num = co_read16p(&p_param->value[2]); + } + else + { + // Request Control Point OpCode @see enum cgmp_cp_opcodes_id + p_ind->value.racp_rsp.req_cp_opcode = p_param->value[2]; + // Response Code @see enum cgmp_cp_resp_code_id + p_ind->value.racp_rsp.rsp_code = p_param->value[3]; + } + + // Stop timer + ke_timer_clear(CGMC_CP_REQ_TIMEOUT, dest_id); + } + else + { + // Check E2E crc + if (GETB(p_cgmc_env->p_env[conidx]->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + feature_crc = co_read16p(&p_param->value[length-CGMP_CRC_LEN]); + + // Calculate E2E-CRC + crc = prf_e2e_crc(&p_param->value[0], length-CGMP_CRC_LEN); + + // Only take reading if crc match + if (feature_crc != crc) + { + uint8_t operation = CGMC_OP_CODE_SPECIFIC_OPS_CTRL_PT; + + if (p_param->handle == p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_MEAS].val_hdl) + { + operation = CGMC_OP_CODE_MEASUREMENT; + } + + // Send the complete event status + cgmc_send_cmp_evt(p_cgmc_env, conidx, operation, CGM_ERROR_INVALID_CRC); + } + } + + p_ind = KE_MSG_ALLOC(CGMC_VALUE_IND, + prf_dst_task_get(&p_cgmc_env->prf_env, conidx), + prf_src_task_get(&p_cgmc_env->prf_env, conidx), + cgmc_value_ind); + + memset(p_ind, 0, sizeof(struct cgmc_value_ind)); + + if (p_param->handle == p_cgmc_env->p_env[conidx]->cgmc.chars[CGMC_CHAR_MEAS].val_hdl) + { + uint8_t flags = p_param->value[1]; + + p_ind->operation = CGMC_OP_CODE_MEASUREMENT; + p_ind->value.meas.size = p_param->value[0]; + p_ind->value.meas.flags = flags; + // CGM Glucose Concentration (SFLOAT/16bit) + p_data = &(p_param->value[2]); + p_ind->value.meas.gluc_concent = co_read16p(p_data); + p_data += 2; + // Time Offset + p_ind->value.meas.time_offset = co_read16p(p_data); + p_data += 2; + + // Verify flags vs supported_features + // annunciation data + if (GETB(flags, CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_WARN)) + { + p_ind->value.meas.warn = *(p_data++); + } + if (GETB(flags, CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_CAL_TEMP)) + { + p_ind->value.meas.cal_temp = *(p_data++); + } + if (GETB(flags, CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_STATUS)) + { + p_ind->value.meas.status = *(p_data++); + } + + // Trend data + if (GETB(flags, CGM_MEAS_FLAGS_CGM_TREND_INFO)) + { + p_ind->value.meas.trend_info = co_read16p(p_data); + p_data += 2; + } + + // Quality data + if (GETB(flags, CGM_MEAS_FLAGS_CGM_QUALITY)) + { + p_ind->value.meas.quality = co_read16p(p_data); + p_data += 2; + } + + // Start the timer; will destroy the link if it expires + ke_timer_set(CGMC_CP_REQ_TIMEOUT, dest_id, 10*CGMC_CP_TIMEOUT); + } + else if(p_param->handle == p_cgmc_env->p_env[conidx]-> + cgmc.chars[CGMC_CHAR_SPEC_OPS_CTRL_PT].val_hdl) + { + // Control Point OpCode @see enum cgmp_cp_opcodes_id + uint8_t cp_opcode = p_param->value[0]; + union cgmp_ops_operand *p_operand = &p_ind->value.ops_cp_rsp.operand; + + p_ind->operation = CGMC_OP_CODE_SPECIFIC_OPS_CTRL_PT; + + // Op Code + p_ind->value.ops_cp_rsp.opcode = cp_opcode; + // Response + p_ind->value.ops_cp_rsp.response = p_param->value[1]; + // Point to Operand + p_data = &(p_param->value[2]); + + // operand based on op code + switch (cp_opcode) + { + // Communication interval in minutes + case CGMP_OPS_CODE_SET_CGM_COM_INTVL: + case CGMP_OPS_CODE_CGM_COM_INTVL_RSP: + { + p_operand->intvl = co_read16p(&(p_param->value[2])); + p_data += 2; + } break; + + // Calibration Data Record Number + case CGMP_OPS_CODE_GET_GLUC_CALIB_VALUE: + { + p_operand->cal_data_record_num = co_read16p(&(p_param->value[2])); + p_data += 2; + } break; + + // Patient High bG value in mg/dL + case CGMP_OPS_CODE_SET_PAT_HIGH_ALERT_LEVEL: + case CGMP_OPS_CODE_PAT_HIGH_ALERT_LEVEL_RSP: + { + p_operand->pat_high_bg = co_read16p(&(p_param->value[2])); + p_data += 2; + } break; + + // Patient Low bG value in mg/dL + case CGMP_OPS_CODE_SET_PAT_LOW_ALERT_LEVEL: + case CGMP_OPS_CODE_PAT_LOW_ALERT_LEVEL_RSP: + { + p_operand->pat_low_bg = co_read16p(&(p_param->value[2])); + p_data += 2; + } break; + + // Hypo Alert Level value in mg/dL + case CGMP_OPS_CODE_SET_HYPO_ALERT_LEVEL: + case CGMP_OPS_CODE_HYPO_ALERT_LEVEL_RSP: + { + p_operand->hypo_alert_level = co_read16p(&(p_param->value[2])); + p_data += 2; + } break; + + // Hyper Alert Level value in mg/dL + case CGMP_OPS_CODE_SET_HYPER_ALERT_LEVEL: + case CGMP_OPS_CODE_HYPER_ALERT_LEVEL_RSP: + { + p_operand->hyper_alert_level = co_read16p(&(p_param->value[2])); + p_data += 2; + } break; + + // Rate of Decrease Alert Level value in mg/dL/min + case CGMP_OPS_CODE_SET_RATE_OF_DECR_ALERT_LEVEL: + case CGMP_OPS_CODE_RATE_OF_DECR_ALERT_LEVEL_RSP: + { + p_operand->rate_decr_alert_level = co_read16p(&(p_param->value[2])); + p_data += 2; + } break; + + // Rate of Increase Alert Level value in mg/dL/min + case CGMP_OPS_CODE_SET_RATE_OF_INCR_ALERT_LEVEL: + case CGMP_OPS_CODE_RATE_OF_INCR_ALERT_LEVEL_RSP: + { + p_operand->rate_incr_alert_level = co_read16p(&(p_param->value[2])); + p_data += 2; + } break; + + // Request Op Code, Response Code Value + case CGMP_OPS_CODE_RSP_CODE: + { + p_operand->req_rsp_value.req_op_code = p_param->value[2]; + p_operand->req_rsp_value.rsp_code = p_param->value[3]; + p_data += 2; + } break; + + // Operand value as defined in the Calibration Value Fields + case CGMP_OPS_CODE_SET_GLUC_CALIB_VALUE: + // Calibration Data + case CGMP_OPS_CODE_GLUC_CALIB_VALUE_RSP: + { + struct cgm_calib_operand *p_calibr = + &p_ind->value.ops_cp_rsp.operand.calib; + + *p_calibr = (struct cgm_calib_operand){ + .cal_gluc_concent = co_read16p(&(p_param->value[2])), + .cal_time = co_read16p(&(p_param->value[4])), + .cal_type_spl = p_param->value[6], + .cal_spl_loc = p_param->value[7], + .next_cal_time = co_read16p(&(p_param->value[8])), + .cal_record_num = co_read16p(&(p_param->value[10])), + .cal_status = p_param->value[12] + }; + p_data += CGMP_CALIBR_SIZE; + } break; + + default: + { + // Do nothing here + } break; //NA + } + + // stop timer. + ke_timer_clear(CGMC_CP_REQ_TIMEOUT, dest_id); + } + } + + if (p_ind != NULL) + { + // confirm that indication has been correctly received + struct gattc_event_cfm *p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + + // send indication to the application + ke_msg_send(p_ind); + + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + } + + } while (0); + + return (KE_MSG_CONSUMED); +} + + +/** + **************************************************************************************** + * @brief Control Point request not executed by peer device or is freezed. + * It can be a connection problem, disconnect the link. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GATTC). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + * + **************************************************************************************** + */ +__STATIC int cgmc_cp_req_timeout_handler(ke_msg_id_t const msgid, void const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) != CGMC_BUSY) + { + uint8_t op_pending; + uint8_t operation; + uint8_t conidx = KE_IDX_GET(dest_id); + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + + ASSERT_INFO(p_cgmc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_cgmc_env->p_env[conidx] != NULL, dest_id, src_id); + + // inform that racp execution is into a timeout state + op_pending = p_cgmc_env->p_env[conidx]->op_pending; + operation = CGMC_OP_PENDING_NO_OP; + + switch(op_pending) + { + case CGMC_OP_PENDING_WRITE_RACP: + { + operation = CGMC_OP_CODE_WRITE_CTRL_PT; + } break; + + case CGMC_OP_PENDING_WRITE_SPECIFIC_OPS_CTRL_PT: + { + operation = CGMC_OP_CODE_WRITE_OPS_CTRL_PT; + } break; + + default: + { + // Do nothing + } break; + } + + // Send the complete event status + cgmc_send_cmp_evt(p_cgmc_env, conidx, operation, PRF_ERR_PROC_TIMEOUT); + ke_state_set(dest_id, CGMC_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(cgmc) +{ + {CGMC_ENABLE_REQ, (ke_msg_func_t)cgmc_enable_req_handler}, + + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + + {CGMC_READ_CMD, (ke_msg_func_t)cgmc_read_cmd_handler}, + {CGMC_READ_CCC_CMD, (ke_msg_func_t)cgmc_read_ccc_cmd_handler}, + + {CGMC_WRITE_SESS_START_TIME_CMD, (ke_msg_func_t)cgmc_write_sess_start_time_cmd_handler}, + + {CGMC_WRITE_RACP_CMD, (ke_msg_func_t)cgmc_write_racp_cmd_handler}, + + {CGMC_WRITE_OPS_CTRL_PT_CMD, (ke_msg_func_t)cgmc_write_ops_ctrl_pt_cmd_handler}, + + {CGMC_CFG_CCC_CMD, (ke_msg_func_t)cgmc_cfg_ccc_cmd_handler}, + {CGMC_CP_REQ_TIMEOUT, (ke_msg_func_t)cgmc_cp_req_timeout_handler}, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ +void cgmc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct cgmc_env_tag *p_cgmc_env = PRF_ENV_GET(CGMC, cgmc); + + p_task_desc->msg_handler_tab = cgmc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(cgmc_msg_handler_tab); + p_task_desc->state = p_cgmc_env->state; + p_task_desc->idx_max = CGMC_IDX_MAX; +} + + +#endif //(BLE_CGM_CLIENT) + +/// @} CGMCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmp_common.h new file mode 100644 index 0000000..cfbaffa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgmp_common.h @@ -0,0 +1,673 @@ +/** + **************************************************************************************** + * + * @file cgmp_common.h + * + * @brief Header File - Continuous Glucose Monitoring Profile common types. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * + **************************************************************************************** + */ + + +#ifndef _CGMP_COMMON_H_ +#define _CGMP_COMMON_H_ + +#include "rwip_config.h" + +#if (BLE_CGM_CLIENT || BLE_CGM_SERVER) +#include "co_math.h" +#include "prf_types.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// All valid bits of Flags field +#define CGMS_MEAS_FLAGS_VALID (0xE3) +/// Special value for measurements +/// NaN (not a number) +#define CGMP_NAN (0x07FF) +/// NRes (not at this resolution) +#define CGMP_NRES (0x0800) +/// + INFINITY +#define CGMP_INFINITY_PLUS (0x07FE) +/// - INFINITY +#define CGMP_INFINITY_MINUS (0x0802) +/// Size of the E2E CRC +#define CGMP_CRC_LEN (2) +/// Minimum Size of the Control Point Request +#define CGMP_CP_MIN_LEN (2) +/// Maximum Session Start Time size +#define CGMP_SESS_ST_TIME_SIZE_MAX (PRF_CHAR_PRES_FMT_SIZE + 1 + 1 + 2) +/// CGM RACP response +#define CGMP_RACP_RSP_SIZE (4) + +/// Size of the calibration block in the Sp Ops requests +#define CGMP_OPS_CALIBRATION_SIZE (11) + +/// ERROR CODES +#define CGM_ERROR_MISSING_CRC (0x80) +#define CGM_ERROR_INVALID_CRC (0x81) + +/// Time zone defines +#define CGM_TIME_ZONE_MIN (-48) +#define CGM_TIME_ZONE_MAX (56) +#define CGM_TIME_ZONE_UNKNOWN (-128) + +/// Compacted size pf the struct cgm_calibration_operand +#define CGMP_CALIBR_SIZE (11) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// CGM Feature Support bit field +enum cgm_feat_bf +{ + /// Calibration supported + CGM_FEAT_CALIB_SUP_POS = 0, + CGM_FEAT_CALIB_SUP_BIT = CO_BIT(CGM_FEAT_CALIB_SUP_POS), + + /// Patient High/Low Alerts supported + CGM_FEAT_PAT_HIGH_LOW_ALERT_SUP_POS = 1, + CGM_FEAT_PAT_HIGH_LOW_ALERT_SUP_BIT = CO_BIT(CGM_FEAT_PAT_HIGH_LOW_ALERT_SUP_POS), + + /// Hypo Alert supported + CGM_FEAT_HYPO_ALERT_SUP_POS = 2, + CGM_FEAT_HYPO_ALERT_SUP_BIT = CO_BIT(CGM_FEAT_HYPO_ALERT_SUP_POS), + + /// Hyper Alert supported + CGM_FEAT_HYPER_ALERT_SUP_POS = 3, + CGM_FEAT_HYPER_ALERT_SUP_BIT = CO_BIT(CGM_FEAT_HYPER_ALERT_SUP_POS), + + /// Rate of Increase/Decrease Alert supported + CGM_FEAT_RATE_OF_INCR_DECR_ALERT_SUP_POS = 4, + CGM_FEAT_RATE_OF_INCR_DECR_ALERT_SUP_BIT = CO_BIT(CGM_FEAT_RATE_OF_INCR_DECR_ALERT_SUP_POS), + + /// Device Specific Alert supported + CGM_FEAT_DEV_SPEC_ALERT_SUP_POS = 5, + CGM_FEAT_DEV_SPEC_ALERT_SUP_BIT = CO_BIT(CGM_FEAT_DEV_SPEC_ALERT_SUP_POS), + + /// Sensor Malfunction Detection supported + CGM_FEAT_SENSOR_MALFUNC_DETEC_SUP_POS = 6, + CGM_FEAT_SENSOR_MALFUNC_DETEC_SUP_BIT = CO_BIT(CGM_FEAT_SENSOR_MALFUNC_DETEC_SUP_POS), + + /// Sensor Temperature High-Low Detection supported + CGM_FEAT_SENSOR_TEMP_HIGH_LOW_DETECT_SUP_POS = 7, + CGM_FEAT_SENSOR_TEMP_HIGH_LOW_DETECT_SUP_BIT = CO_BIT(CGM_FEAT_SENSOR_TEMP_HIGH_LOW_DETECT_SUP_POS), + + /// Sensor Result High-Low Detection supported + CGM_FEAT_SENSOR_RESULT_HIGH_LOW_DETECT_SUP_POS = 8, + CGM_FEAT_SENSOR_RESULT_HIGH_LOW_DETECT_SUP_BIT = CO_BIT(CGM_FEAT_SENSOR_RESULT_HIGH_LOW_DETECT_SUP_POS), + + /// Low Battery Detection supported + CGM_FEAT_LOW_BATT_DETECT_SUP_POS = 9, + CGM_FEAT_LOW_BATT_DETECT_SUP_BIT = CO_BIT(CGM_FEAT_LOW_BATT_DETECT_SUP_POS), + + /// Sensor Type Error Detection supported + CGM_FEAT_SENSOR_TYPE_ERR_DETECT_SUP_POS = 10, + CGM_FEAT_SENSOR_TYPE_ERR_DETECT_SUP_BIT = CO_BIT(CGM_FEAT_SENSOR_TYPE_ERR_DETECT_SUP_POS), + + /// General Device Fault supported + CGM_FEAT_GENERAL_DEV_FAULT_SUP_POS = 11, + CGM_FEAT_GENERAL_DEV_FAULT_SUP_BIT = CO_BIT(CGM_FEAT_GENERAL_DEV_FAULT_SUP_POS), + + /// E2E-CRC supported + CGM_FEAT_E2E_CRC_SUP_POS = 12, + CGM_FEAT_E2E_CRC_SUP_BIT = CO_BIT(CGM_FEAT_E2E_CRC_SUP_POS), + + /// Multiple Bond supported + CGM_FEAT_MULTI_BOND_SUP_POS = 13, + CGM_FEAT_MULTI_BOND_SUP_BIT = CO_BIT(CGM_FEAT_MULTI_BOND_SUP_POS), + + /// Multiple Session supported + CGM_FEAT_MULTI_SESS_SUP_POS = 14, + CGM_FEAT_MULTI_SESS_SUP_BIT = CO_BIT(CGM_FEAT_MULTI_SESS_SUP_POS), + + /// CGM Trend Information supported + CGM_FEAT_CGM_TREND_INFO_SUP_POS = 15, + CGM_FEAT_CGM_TREND_INFO_SUP_BIT = CO_BIT(CGM_FEAT_CGM_TREND_INFO_SUP_POS), + + /// CGM Quality supported + CGM_FEAT_CGM_QUALITY_SUP_POS = 16, + CGM_FEAT_CGM_QUALITY_SUP_BIT = CO_BIT(CGM_FEAT_CGM_QUALITY_SUP_POS), +}; + +/// Calibration sample type ID +enum cgmp_type_sample_id +{ + /// Capillary whole blood + CGM_TYPE_SMP_CAPILLARY_WHOLE_BLOOD = 1, + /// Capillary Plasma + CGM_TYPE_SMP_CAPILLARY_PLASMA = 2, + /// Capillary whole blood 2 + CGM_TYPE_SMP_CAPILLARY_WHOLE_BLOOD_2 = 3, + /// Venous plasma + CGM_TYPE_SMP_VENOUS_PLASMA = 4, + /// Arterial whole blood + CGM_TYPE_SMP_ARTERIAL_WHOLE_BLOOD = 5, + /// Arterial plasma + CGM_TYPE_SMP_ARTERIAL_PLASMA = 6, + /// Undetermined whole blood + CGM_TYPE_SMP_UNDETERMINED_WHOLE_BLOOD = 7, + /// Undetermined plasma + CGM_TYPE_SMP_UNDETERMINED_PLASMA = 8, + /// Interstitial fluid + CGM_TYPE_SMP_INTERSTITIAL_FLUID = 9, + /// Control solution + CGM_TYPE_SMP_CONTROL_SOLUTION = 10, +}; + +/// Calibration location of sample +enum cgmp_sample_location_id +{ + /// Finger + CGM_SMP_LOC_FINGER = 1, + /// Alternate site test + CGM_SMP_LOC_ALTERNATE_SITE_TEST = 2, + /// Earlobe + CGM_SMP_LOC_EARLOBE = 3, + /// Control solution + CGM_SMP_LOC_CONTROL_SOLUTION = 4, + /// Subcutaneous tissue + CGM_SMP_LOC_SUBCUTANEOUS_TISSUE = 5, + /// Location not available + CGM_SMP_LOC_LOCATION_NOT_AVAILABLE = 15, +}; + +/// Calibration status +enum cgmp_calib_status_bf +{ + /// Calibration Data rejected (Calibration failed) + /// 0 for false + /// 1 for true + CGMP_CAL_STATUS_DATA_REJECTED_POS = 0, + CGMP_CAL_STATUS_DATA_REJECTED_BIT = CO_BIT(CGMP_CAL_STATUS_DATA_REJECTED_POS), + + /// Calibration Data out of range + /// 0 for false + /// 1 for true + CGMP_CAL_STATUS_DATA_OUT_RANGE_POS = 1, + CGMP_CAL_STATUS_DATA_OUT_RANGE_BIT = CO_BIT(CGMP_CAL_STATUS_DATA_OUT_RANGE_POS), + + /// Calibration Process Pending + /// 0 for false + /// 1 for true + CGMP_CAL_STATUS_PROCESS_PENDING_POS = 2, + CGMP_CAL_STATUS_PROCESS_PENDING_BIT = CO_BIT(CGMP_CAL_STATUS_PROCESS_PENDING_POS), +}; + + +/// CGM Measurement Flags bit field +enum cgm_meas_flags_bf +{ + /// CGM Trend Information Field (bit 0) + /// 0 for not present + /// 1 for present + CGM_MEAS_FLAGS_CGM_TREND_INFO_POS = 0, + CGM_MEAS_FLAGS_CGM_TREND_INFO_BIT = CO_BIT(CGM_MEAS_FLAGS_CGM_TREND_INFO_POS), + + /// CGM Quality Field (bit 1) + /// 0 for not present + /// 1 for present + CGM_MEAS_FLAGS_CGM_QUALITY_POS = 1, + CGM_MEAS_FLAGS_CGM_QUALITY_BIT = CO_BIT(CGM_MEAS_FLAGS_CGM_QUALITY_POS), + + /// Sensor Status Annunciation Field - Warning (bit 5) + /// 0 for not present + /// 1 for present + CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_WARN_POS = 5, + CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_WARN_BIT = CO_BIT(CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_WARN_POS), + + /// Sensor Status Annunciation Field - Cal/Temp (bit 6) + /// 0 for not present + /// 1 for present + CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_CAL_TEMP_POS = 6, + CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_CAL_TEMP_BIT = CO_BIT(CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_CAL_TEMP_POS), + + /// Sensor Status Annunciation Field - Status (bit 7) + /// 0 for not present + /// 1 for present + CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_STATUS_POS = 7, + CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_STATUS_BIT = CO_BIT(CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_STATUS_POS), +}; + +/// CGM Measurement Sensor Status Annunciation bit field[0:7] - Status-Octet present +enum cgm_meas_sensor_status_annuc_status_bf +{ + /// Session Stopped Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_STATUS_SESS_STOPPED_POS = 0, + CGM_MEAS_ANNUNC_STATUS_SESS_STOPPED_BIT = CO_BIT(CGM_MEAS_ANNUNC_STATUS_SESS_STOPPED_POS), + + /// Device Battery Low Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_STATUS_DEV_BATT_LOW_POS = 1, + CGM_MEAS_ANNUNC_STATUS_DEV_BATT_LOW_BIT = CO_BIT(CGM_MEAS_ANNUNC_STATUS_DEV_BATT_LOW_POS), + + /// Sensor type incorrect for device Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_STATUS_SENSOR_TYPE_INCOR_POS = 2, + CGM_MEAS_ANNUNC_STATUS_SENSOR_TYPE_INCOR_BIT = CO_BIT(CGM_MEAS_ANNUNC_STATUS_SENSOR_TYPE_INCOR_POS), + + /// Sensor malfunction Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_STATUS_SENSOR_MALFUNC_POS = 3, + CGM_MEAS_ANNUNC_STATUS_SENSOR_MALFUNC_BIT = CO_BIT(CGM_MEAS_ANNUNC_STATUS_SENSOR_MALFUNC_POS), + + /// Device Specific Alert Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_STATUS_DEV_SPEC_ALERT_POS = 4, + CGM_MEAS_ANNUNC_STATUS_DEV_SPEC_ALERT_BIT = CO_BIT(CGM_MEAS_ANNUNC_STATUS_DEV_SPEC_ALERT_POS), + + /// General device fault has occurred in the sensor Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_STATUS_GEN_DEV_FAULT_POS = 5, + CGM_MEAS_ANNUNC_STATUS_GEN_DEV_FAULT_BIT = CO_BIT(CGM_MEAS_ANNUNC_STATUS_GEN_DEV_FAULT_POS), +}; + +/// CGM Measurement Sensor Status Annunciation Field[8:15] - Cal/Temp-Octet present +enum cgm_meas_sensor_status_annuc_cal_temp_bf +{ + /// Time synchronization between sensor and collector required Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_CAL_TEMP_TIME_SYNC_REQ_POS = 0, + CGM_MEAS_ANNUNC_CAL_TEMP_TIME_SYNC_REQ_BIT = CO_BIT(CGM_MEAS_ANNUNC_CAL_TEMP_TIME_SYNC_REQ_POS), + + /// Calibration not allowed Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_NOT_ALLOWED_POS = 1, + CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_NOT_ALLOWED_BIT = CO_BIT(CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_NOT_ALLOWED_POS), + + /// Calibration recommended Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_RECMD_POS = 2, + CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_RECMD_BIT = CO_BIT(CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_RECMD_POS), + + /// Calibration required Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_REQ_POS = 3, + CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_REQ_BIT = CO_BIT(CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_REQ_POS), + + /// Sensor Temperature too high for valid test/result at time of measurement Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_CAL_TEMP_SENSOR_TEMP_HIGH_POS = 4, + CGM_MEAS_ANNUNC_CAL_TEMP_SENSOR_TEMP_HIGH_BIT = CO_BIT(CGM_MEAS_ANNUNC_CAL_TEMP_SENSOR_TEMP_HIGH_POS), + + /// Sensor Temperature too low for valid test/result at time of measurement Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_CAL_TEMP_SENSOR_TEMP_LOW_POS = 5, + CGM_MEAS_ANNUNC_CAL_TEMP_SENSOR_TEMP_LOW_BIT = CO_BIT(CGM_MEAS_ANNUNC_CAL_TEMP_SENSOR_TEMP_LOW_POS), +}; + +/// CGM Measurement Sensor Status Annunciation bit field[16:23] - Warning-Octet present +enum cgm_meas_sensor_status_annuc_warn_bf +{ + + /// Sensor result lower than the Patient Low level Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_PAT_POS = 0, + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_PAT_BIT = CO_BIT(CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_PAT_POS), + + /// Sensor result higher than the Patient High level Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_PAT_POS = 1, + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_PAT_BIT = CO_BIT(CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_PAT_POS), + + /// Sensor result lower than the Hypo level Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_HYPO_POS = 2, + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_HYPO_BIT = CO_BIT(CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_HYPO_POS), + + /// Sensor result higher than the Hyper level Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_HYPER_POS = 3, + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_HYPER_BIT = CO_BIT(CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_HYPER_POS), + + /// Sensor Rate of Decrease exceeded Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_WARN_SENSOR_RATE_DECR_POS = 4, + CGM_MEAS_ANNUNC_WARN_SENSOR_RATE_DECR_BIT = CO_BIT(CGM_MEAS_ANNUNC_WARN_SENSOR_RATE_DECR_POS), + + /// Sensor Rate of Increase exceeded Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_WARN_SENSOR_RATE_INCR_POS = 5, + CGM_MEAS_ANNUNC_WARN_SENSOR_RATE_INCR_BIT = CO_BIT(CGM_MEAS_ANNUNC_WARN_SENSOR_RATE_INCR_POS), + + /// Sensor result lower than the device can process Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_DEV_POS = 6, + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_DEV_BIT = CO_BIT(CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_DEV_POS), + + /// Sensor result higher than the device can process Field + /// 0 for false + /// 1 for true + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_DEV_POS = 7, + CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_DEV_BIT = CO_BIT(CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_DEV_POS), +}; + + +/// Daylight Saving Time Offset +enum cgmp_dst_offset_id +{ + /// Daylight Saving Time Offset +0h + CGM_DST_OFFSET_STANDARD_TIME = 0, + /// Daylight Saving Time Offset +0.5h + CGM_DST_OFFSET_HALF_AN_HOUR_DAYLIGHT_TIME = 2, + /// Daylight Saving Time Offset +1h + CGM_DST_OFFSET_DAYLIGHT_TIME = 4, + /// Daylight Saving Time Offset +2h + CGM_DST_OFFSET_DOUBLE_DAYLIGHT_TIME = 8, + /// Unknown value + CGM_DST_OFFSET_UNKNOWN_DAYLIGHT_TIME = 255, +}; + +/// Control Point OpCodes +enum cgmp_cp_opcodes_id +{ + /// Report stored records + CGMP_OPCODE_REP_STRD_RECS = 1, + /// Delete stored records + CGMP_OPCODE_DEL_STRD_RECS = 2, + /// Abort operation + CGMP_OPCODE_ABORT_OP = 3, + /// Report number of stored records + CGMP_OPCODE_REP_NUM_OF_STRD_RECS = 4, + /// Number of stored records response + CGMP_OPCODE_NUM_OF_STRD_RECS_RSP = 5, + /// Response code + CGMP_OPCODE_RSP_CODE = 6, +}; + +/// Control Point Operators +enum cgmp_cp_operator_id +{ + /// NULL operation + CGMP_OP_NULL = 0, + /// All records + CGMP_OP_ALL_RECS = 1, + /// Less than or equal to + CGMP_OP_LT_OR_EQ = 2, + /// Greater than or equal to + CGMP_OP_GT_OR_EQ = 3, + /// Within range of (inclusive) + CGMP_OP_WITHIN_RANGE_OF = 4, + /// First record(i.e. oldest record) + CGMP_OP_FIRST_REC = 5, + /// Last record (i.e. most recent record) + CGMP_OP_LAST_REC = 6, +}; + + +/// record access control filter type +enum cgmp_racp_filter +{ + /// Filter using Time Offset + CGMP_FILTER_TIME_OFFSET = (1), +}; + + +/// Record Access Control Point Response Code Values +enum cgmp_racp_rsp_id +{ + /// Success + CGMP_RSP_SUCCESS = 1, + /// Not supported + CGMP_RSP_OP_CODE_NOT_SUP = 2, + /// Invalid Operator + CGMP_RSP_INV_OPERATOR = 3, + /// Operator not supported + CGMP_RSP_OPERATOR_NOT_SUP = 4, + /// Invalid Operand + CGMP_RSP_INV_OPERAND = 5, + /// No records found + CGMP_RSP_NO_RECORDS_FOUND = 6, + /// Abort unsuccessful + CGMP_RSP_ABORT_UNSUCCESSFUL = 7, + /// Procedure not completed + CGMP_RSP_PROC_NOT_CMP = 8, + /// Operand not supported + CGMP_RSP_OPERAND_NOT_SUP = 9, +}; + +/// Specific Ops Control Point Response Codes +enum cgmp_spec_ops_cp_rsp_id +{ + /// Success - Normal response for successful operation + CGMP_OPS_RSP_SUCCESS = 1, + /// Op Code not supported - Normal response if unsupported Op Code is received + CGMP_OPS_RSP_OP_CODE_NOT_SUP = 2, + /// Invalid Operand - Normal response if Operand received does not meet the requirements of the service + CGMP_OPS_RSP_INV_OPERAND = 3, + /// Procedure not completed - Normal response if unable to complete a procedure for any reason + CGMP_OPS_RSP_PROC_NOT_CMP = 4, + /// Parameters out of range - Normal response if Operand received does not meet the range requirements + CGMP_OPS_RSP_PARAM_OUT_OF_RANGE = 5, + +}; + +/// CGM OPS CONTROL POINT Op code +enum cgmp_spec_ops_opcodes_id +{ + /// Set CGM communication interval + /// The response to this control point is Response Code (Op Code 0x0F) + CGMP_OPS_CODE_SET_CGM_COM_INTVL = 1, + /// Get CGM communication interval + /// The normal response to this control point is Op Code 0x03. + /// For error conditions, the response is defined in the Op Code - Response Codes field + CGMP_OPS_CODE_GET_CGM_COM_INTVL = 2, + /// Communication interval response + /// This is the normal response to Op Code 0x02 + CGMP_OPS_CODE_CGM_COM_INTVL_RSP = 3, + /// Set Glucose Calibration value + /// The response to this control point is defined in Op Code - Response Codes field + CGMP_OPS_CODE_SET_GLUC_CALIB_VALUE = 4, + /// Get Glucose Calibration value + /// The normal response to this control point is Op Code 0x06. for error conditions, + /// the response is defined in the Op Code - Response Codes field + CGMP_OPS_CODE_GET_GLUC_CALIB_VALUE = 5, + /// Glucose Calibration value + /// Glucose Calibration Value response + CGMP_OPS_CODE_GLUC_CALIB_VALUE_RSP = 6, + /// Set Patient High Alert Level + /// The response to this control point is defined in Op Code - Response Codes field + CGMP_OPS_CODE_SET_PAT_HIGH_ALERT_LEVEL = 7, + /// Get Patient High Alert Level + /// The normal response to this control point is Op Code 0x09. + /// For error conditions, the response is defined in the Op Code - Response Codes field + CGMP_OPS_CODE_GET_PAT_HIGH_ALERT_LEVEL = 8, + /// Patient High Alert Level response + /// This is the normal response to Op Code 0x08 + CGMP_OPS_CODE_PAT_HIGH_ALERT_LEVEL_RSP = 9, + /// Set Patient Low Alert Level + /// The response to this control point is defined in Op Code - Response Codes field + CGMP_OPS_CODE_SET_PAT_LOW_ALERT_LEVEL = 10, + /// Get Patient Low Alert Level + /// The normal response to this control point is Op Code 0x0C. + /// the response is defined in the Op Code - Response Codes field + CGMP_OPS_CODE_GET_PAT_LOW_ALERT_LEVEL = 11, + /// Patient Low Alert Level response + /// This is the normal response to Op Code 0x0B + CGMP_OPS_CODE_PAT_LOW_ALERT_LEVEL_RSP = 12, + /// Set Hypo Alert Level + /// The response to this control point is defined in Op Code - Response Codes field + CGMP_OPS_CODE_SET_HYPO_ALERT_LEVEL = 13, + /// Get Hypo Alert Level + /// The normal response to this control point is Op Code 0x0F. + /// the response is defined in the Op Code - Response Codes field + CGMP_OPS_CODE_GET_HYPO_ALERT_LEVEL = 14, + /// Hypo Alert Level response + /// This is the normal response to Op Code 0x0E + CGMP_OPS_CODE_HYPO_ALERT_LEVEL_RSP = 15, + /// Set Hyper Alert Level + /// The response to this control point is defined in Op Code - Response Codes field + CGMP_OPS_CODE_SET_HYPER_ALERT_LEVEL = 16, + /// Get Hyper Alert Level + /// The normal response to this control point is Op Code 0x12. + /// The response is defined in the Op Code - Response Codes field + CGMP_OPS_CODE_GET_HYPER_ALERT_LEVEL = 17, + /// Hyper Alert Level response + /// This is the normal response to Op Code 0x11 + CGMP_OPS_CODE_HYPER_ALERT_LEVEL_RSP = 18, + /// Set Rate of Decrease Alert Level + /// The response to this control point is defined in Op Code - Response Codes field + CGMP_OPS_CODE_SET_RATE_OF_DECR_ALERT_LEVEL = 19, + /// Get Rate of Decrease Alert Level + /// The normal response to this control point is Op Code 0x15. + /// For error conditions, the response is Response Code + CGMP_OPS_CODE_GET_RATE_OF_DECR_ALERT_LEVEL = 20, + /// Rate of Decrease Alert Level Response + /// This is the normal response to Op Code 0x14 + CGMP_OPS_CODE_RATE_OF_DECR_ALERT_LEVEL_RSP = 21, + /// Set Rate of Increase Alert Level + /// The response to this control point is defined in Op Code - Response Codes field + CGMP_OPS_CODE_SET_RATE_OF_INCR_ALERT_LEVEL = 22, + /// Get Rate of Increase Alert Level + /// The normal response to this control point is Op Code 0x18. + /// For error conditions, the response is Response Code + CGMP_OPS_CODE_GET_RATE_OF_INCR_ALERT_LEVEL = 23, + /// Rate of Increase Alert Level Response + /// This is the normal response to Op Code 0x17 + CGMP_OPS_CODE_RATE_OF_INCR_ALERT_LEVEL_RSP = 24, + /// Reset Device Specific Alert + /// The response to this control point is defined in Op Code - Response Codes field + CGMP_OPS_CODE_RESET_DEV_SPEC_ALERT = 25, + /// Start Session + /// The response to this control point is defined in Op Code - Response Codes field + CGMP_OPS_CODE_START_SESS = 26, + /// Stop Session + /// The response to this control point is defined in Op Code - Response Codes field + CGMP_OPS_CODE_STOP_SESS = 27, + /// Response + /// see Op Code - Response Codes field + CGMP_OPS_CODE_RSP_CODE = 28, + +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// CGM Calibration Operand value +struct cgm_calib_operand +{ + /// Glucose Concentration at Calibration + prf_sfloat cal_gluc_concent; + /// Calibration Time in minutes + uint16_t cal_time; + /// Calibration Type of Sample @see common enum cgmp_type_sample_id + uint8_t cal_type_spl; + /// Calibration Location of Sample @see common enum cgmp_sample_location_id + uint8_t cal_spl_loc; + /// Next Calibration Time in minutes + uint16_t next_cal_time; + /// Calibration Record Number + uint16_t cal_record_num; + /// Calibration Status - bitfield @see common enum cgmp_calib_status_bf + uint8_t cal_status; +}; + +/// CGM Ops Operand value +union cgmp_ops_operand +{ + /// Communication interval in minutes + /// @see CGMP_OPS_CODE_SET_CGM_COM_INTVL - 1 + /// @see CGMP_OPS_CODE_CGM_COM_INTVL_RSP - 3 + uint16_t intvl; + /// Operand value as defined in the Calibration Value Fields. + /// @see CGMP_OPS_CODE_SET_GLUC_CALIB_VALUE - 4 + struct cgm_calib_operand calib; + /// Calibration Data Record Number + /// @see CGMP_OPS_CODE_GET_GLUC_CALIB_VALUE - 5 + /// @see CGMP_OPS_CODE_GLUC_CALIB_VALUE_RSP - 6 + uint16_t cal_data_record_num; + /// Patient High bG value in mg/dL + /// @see CGMP_OPS_CODE_SET_PAT_HIGH_ALERT_LEVEL - 7 + /// @see CGMP_OPS_CODE_PAT_HIGH_ALERT_LEVEL_RSP - 9 + prf_sfloat pat_high_bg; + /// Patient Low bG value in mg/dL + /// @see CGMP_OPS_CODE_SET_PAT_LOW_ALERT_LEVEL - 10 + /// @see CGMP_OPS_CODE_PAT_LOW_ALERT_LEVEL_RSP - 12 + prf_sfloat pat_low_bg; + /// Hypo Alert Level value in mg/dL + /// @see CGMP_OPS_CODE_SET_HYPO_ALERT_LEVEL - 13 + /// @see CGMP_OPS_CODE_HYPO_ALERT_LEVEL_RSP - 15 + prf_sfloat hypo_alert_level; + /// Hyper Alert Level value in mg/dL + /// @see CGMP_OPS_CODE_SET_HYPER_ALERT_LEVEL - 16 + /// @see CGMP_OPS_CODE_HYPER_ALERT_LEVEL_RSP - 18 + prf_sfloat hyper_alert_level; + /// Rate of Decrease Alert Level value in mg/dL/min + /// @see CGMP_OPS_CODE_SET_RATE_OF_DECR_ALERT_LEVEL - 19 + /// @see CGMP_OPS_CODE_RATE_OF_DECR_ALERT_LEVEL_RSP - 21 + prf_sfloat rate_decr_alert_level; + /// Rate of Increase Alert Level value in mg/dL/min + /// @see CGMP_OPS_CODE_SET_RATE_OF_INCR_ALERT_LEVEL - 22 + /// @see CGMP_OPS_CODE_RATE_OF_INCR_ALERT_LEVEL_RSP - 24 + prf_sfloat rate_incr_alert_level; + /// Request Op Code, Response Code Value + /// @see CGMP_OPS_CODE_RSP_CODE - 28 + struct req_rsp_code + { + /// request op code value + uint8_t req_op_code; + /// response code value + uint8_t rsp_code; + } req_rsp_value; +}; + +/// Record access control point response +struct cgmp_racp_rsp +{ + /// operation code + uint8_t op_code; + + /// operator (ignored, always set to null) + uint8_t operator; + + /// response operand + union + { + /// Number of record (if op_code = CGMP_REQ_NUM_OF_STRD_RECS_RSP) + uint16_t num_of_record; + + /// Command Status (if op_code = CGMP_REQ_RSP_CODE) + struct + { + /// Request Op Code + uint8_t op_code_req; + /// Response Code status + uint8_t status; + } rsp; + } operand; +}; + + +#endif /* (BLE_CGMP_CLIENT || BLE_CGMP_SERVER) */ + +#endif /* _CGMP_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/api/cgms_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/api/cgms_task.h new file mode 100644 index 0000000..8185492 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/api/cgms_task.h @@ -0,0 +1,350 @@ +/** + **************************************************************************************** + * + * @file cgms_task.h + * + * @brief Header file - Continuous Glucose Monitoring Profile Service Task. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CGMS_TASK_H_ +#define _CGMS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup CGMSTASK Task + * @ingroup CGMS + * @brief Continuous Glucose Monitoring Profile Task. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" +#include "prf_types.h" + +#include "cgmp_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +/// Minimum configuration: +/// 1oct(Size)+ 1oct(flags) + 2oct(Glucose Concentration) +2oct(Time Offset) +#define CGMS_MEAS_CMD_MIN_LENGTH (1 +1 +2 +2) + +/// Size of read Session Start Time request without e2e-crc +#define CGMS_RD_SESS_START_TIME_CFM_SIZE (9) +/// Size of read Session Start Time request with e2e-crc +#define CGMS_SESS_START_TIME_CFM_SIZE_MAX (9+2) +/// Size of read status request without e2e-crc +#define CGMS_RD_STATUS_CFM_SIZE (5) +/// Size of read Session Run Time request without e2e-crc +#define CGMS_RD_SESS_RUN_TIME_CFM_SIZE (2) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Messages for Continuous Glucose Monitoring Profile Service +enum cgms_msg_id +{ + /// Enable the CGMP Sensor task at connection + CGMS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_CGMS), + /// Enable the CGMP Sensor task at connection + CGMS_ENABLE_RSP, + /// Send the Measurement or Measurement Record + CGMS_MEAS_VALUE_CMD, + + /// Write to the Session Start Time Indication + CGMS_WR_SESS_START_TIME_IND, + + /// Read Request for the CGM Status, CGM Session Start Time, CGM Session Run Time + CGMS_RD_CHAR_REQ_IND, + /// Read confirmation from the app with data + CGMS_RD_CHAR_CFM, + + /// Inform Application on the Characteristics CCC descriptor changes + CGMS_WR_CHAR_CCC_IND, + /// Write to the Control Point forward to Application + CGMS_WR_RACP_IND, + /// Send Control Point Response + CGMS_RACP_RESP_CMD, + /// Request for the OPS Control Point + CGMS_WR_OPS_CTRL_PT_REQ_IND, + /// Confirmation from OPS Control Point + CGMS_WR_OPS_CTRL_PT_CFM, + /// Complete event for the Application commands + CGMS_CMP_EVT, +}; + +/// Define Complete Event command (CGMS_CMP_EVT) operation op codes +enum cgms_op_codes +{ + /// CGMS Measurement operation + CGMS_MEAS_CMD_OP_CODE = 1, + /// Special OPS Control Point operation + CGMS_OPS_CTRL_PT_OP_CODE = 2, + /// RACP operation + CGMS_RACP_CMD_OP_CODE = 3, + /// Read Characteristic operation + CGMS_RD_CHAR_OP_CODE = 4, +}; + +/// Define characteristic type +enum cgms_char_type +{ + /// CGM Measurement CCC + CGMS_CHAR_ID_MEAS_CCC = 1, + /// CGM Specific Ops Control Point CCC + CGMS_CHAR_ID_OPS_CTRL_PT_CCC = 2, + /// Record Access Control Point CCC + CGMS_CHAR_ID_RACP_CCC = 3, + /// CGM Status value + CGMS_CHAR_ID_STATUS_VAL = 4, + /// CGM Session Start Time value + CGMS_CHAR_ID_SESSION_START_TIME_VAL = 5, + /// CGM Session Run Time value + CGMS_CHAR_ID_SESSION_RUN_TIME_VAL = 6, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the initialization function +struct cgms_db_cfg +{ + /// If enabled in CGM Features @see enum cgm_feat_bf + uint32_t cgm_feature; + /// Define the Type of Sample @see enum cgmp_type_sample_id + uint8_t type_sample; + /// Define the Location of Sample @see enum cgmp_sample_location_id + uint8_t sample_location; +}; + +/// Parameters of the @see CGMS_ENABLE_REQ message +struct cgms_enable_req +{ + /** + * Profile characteristic configuration: + * CGM Measurement Characteristic notification config Bit 0 + * Record Access Control Point indication config Bit 1 + * CGM Specific Ops Control Point indication config Bit 2 + */ + uint16_t prfl_ntf_ind_cfg; +}; + +/// Parameters of the @see CGMS_ENABLE_RSP message +struct cgms_enable_rsp +{ + /// Status + uint8_t status; +}; + +/// CGM Measurement Value +/// Parameters of the @see CGMS_MEAS_VALUE_CMD, +struct cgms_meas_value_cmd +{ + /// CGMS_MEAS_CMD_OP_CODE for this command @see enum cgms_op_codes + uint8_t operation; + /// CGM Measurement Characteristic Flags field @see enum cgm_meas_flags_bf + uint8_t flags; + /// The CGM Glucose Concentration Field contains the CGM glucose concentration in mg/dL as a SFLOAT data type + prf_sfloat gluc_concent; + /// The following values are defined for the Time Offset Field, specifying + /// the relative time difference of the single CGM values to the session + /// start time. Value: (0x0000 - 0xFFFF) + /// Description: (Time offset in minutes as offset to the Session Start Time) + uint16_t time_offset; + /// The Sensor Status Annunciation Field shall be attached to every CGM Measurement Record + /// to which the status applies. Bits[16:23] of @see enum cgm_meas_sensor_status_annuc_bf + uint8_t warn; + /// The Sensor Status Annunciation Field, bits[8:13] of @see enum cgm_meas_sensor_status_annuc_bf + uint8_t cal_temp; + /// The Sensor Status Annunciation Field, bits[0:5] of @see enum cgm_meas_sensor_status_annuc_bf + uint8_t status; + /// The CGM Trend Information Field contains the CGM Trend information in (mg/dL)/min as an SFLOAT data type + /// This field is optional if the device supports CGM Trend information + /// (Bit 15 in CGM Feature is set to 1) otherwise excluded + prf_sfloat trend_info; + /// This field contains the CGM Quality information in % as an SFLOAT data type + /// The SFLOAT-Type is a 16-bit word comprising a signed 4-bit integer exponent + /// followed by a signed 12-bit Mantissa, each in twos-complement form + /// This field is optional if the device supports CGM Quality + /// (Bit 16 in CGM Feature is set to 1) otherwise excluded + prf_sfloat quality; +}; + +/// CGM Status +/// Parameters of the @see CGMS_RD_CHAR_REQ_IND +struct cgms_rd_char_req_ind +{ + /// characteristic id @see cgms_char_type + uint8_t char_type; +}; + +/// CGM Status +struct cgms_rd_status +{ + /// The following values are defined for the Time Offset Field, specifying + /// the relative time difference of the single CGM values to the session + /// start time. Value: (0x0000 - 0xFFFF), + /// Description: (Time offset in minutes as offset to the Session Start Time). + uint16_t time_offset; + /// The Sensor Status Annunciation Field shall be attached to + /// every CGM Measurement Record to which the status applies. + uint8_t warning; + /// The Sensor Status Annunciation Field. + /// - bitfield @see common Sensor Status Annunciation Field CAL_TEMP + uint8_t cal_temp; + /// The Sensor Status Annunciation Field. + /// - bitfield @see common Sensor Status Annunciation Field STATUS + uint8_t annunc_status; +}; + +/// CGM Session Start Time +struct cgms_rd_sess_start_time +{ + /// time of Session Start Time + struct prf_date_time sess_start_time; + /// (-48..+56) Offset from UTC in number of 15 minutes increments. + /// A value of -128 means that the time zone offset is not known. + /// The offset defined in this characteristic is constant, regardless whether daylight savings is in effect. + int8_t time_zone; + /// DSTOOffset @see common enum cgmp_dst_offset_id + uint8_t dst_offset; +}; + +/// Parameters of the @see CGMS_WR_SESS_START_TIME_IND message +struct cgms_wr_sess_start_time_ind +{ + /// time of Session Start Time + struct prf_date_time sess_start_time; + /// (-48..+56) Offset from UTC in number of 15 minutes increments. + /// A value of -128 means that the time zone offset is not known. + /// The offset defined in this characteristic is constant, regardless whether daylight savings is in effect. + int8_t time_zone; + /// DSTOOffset @see common enum cgmp_dst_offset_id + uint8_t dst_offset; +}; + +/// CGM Session Run Time +struct cgms_rd_sess_run_time +{ + /// Run time in minutes + uint16_t run_time; +}; + +/// Parameters of the @see CGMS_RD_CHAR_CFM message +struct cgms_rd_char_cfm +{ + /// characteristic id @see cgms_char_type + uint8_t char_type; + /// Operation Status + uint8_t status; + /// data for the characteristic + union + { + /// CGM Status + struct cgms_rd_status status; + /// CGM Session Start Time + struct cgms_rd_sess_start_time sess_start_time; + /// CGN Session Run Time + struct cgms_rd_sess_run_time sess_run_time; + } value; +}; + +/// Send Control Point Response +/// Parameters of the @see CGMS_RACP_RESP_CMD, +struct cgms_racp_resp_cmd +{ + /// Operation = CGMS_RACP_CMD_OP_CODE @see enum cgms_op_codes + uint8_t operation; + /// Control Point OpCode @see enum cgmp_cp_opcodes_id + uint8_t cp_opcode; + /// Request Control Point OpCode @see enum cgmp_cp_opcodes_id + uint8_t req_cp_opcode; + /// Response Code @see enum cgmp_racp_rsp_id + uint8_t rsp_code; + /// Number of Records + uint16_t records_num; +}; + +/// Write to the Control Point forward to Application +/// Parameters of the @see CGMS_WR_RACP_IND, +struct cgms_wr_racp_ind +{ + /// Control Point OpCode @see enum cgmp_cp_opcodes_id + uint8_t cp_opcode; + /// Operator @see enum cgmp_cp_operator_id + uint8_t cp_operator; + /// Filter Type + uint8_t filter_type; + /// Filter parameter + uint16_t min_time_offset; + /// Filter parameter + uint16_t max_time_offset; +}; + +/// Inform Application on the Characteristic's CCC descriptor changes +/// Parameters of the @see CGMS_WR_CHAR_CCC_IND, +struct cgms_wr_char_ccc_ind +{ + /// Characteristic type @see enum cgms_char_type + uint8_t char_type; + /// Char. Client Characteristic Configuration + uint16_t ind_cfg; +}; + + +/// Write to the Control Point forward to Application +/// Parameters of the @see CGMS_WR_OPS_CTRL_PT_REQ_IND, +struct cgms_wr_ops_ctrl_pt_req_ind +{ + /// Control Point OpCode @see enum cgmp_spec_ops_opcodes_id + uint8_t opcode; + /// Op-code Response @see enum cgmp_spec_ops_cp_rsp_id + uint8_t rsp; + /// operand specific to opcode + union cgmp_ops_operand operand; +}; + +/// OPS Control Point Response +/// Parameters of the @see CGMS_WR_OPS_CTRL_PT_CFM, +struct cgms_wr_ops_ctrl_pt_cfm +{ + /// Control Point OpCode @see enum cgmp_spec_ops_opcodes_id + uint8_t opcode; + /// Op-code Response @see enum cgmp_spec_ops_cp_rsp_id + uint8_t rsp; + /// operand specific to opcode + union cgmp_ops_operand operand; +}; + +/// Send App command complete event +/// Parameters of the @see CGMS_CMP_EVT message +struct cgms_cmp_evt +{ + /// Operation @see enum cgms_op_codes + uint8_t operation; + /// Operation Status + uint8_t status; +}; + +/// @} CGMSTASK + +#endif //(_CGMS_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/sourcelist.txt new file mode 100644 index 0000000..abfb4a1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2017 +# +#*************************************************************************************** + + cgms.c + cgms_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/src/cgms.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/src/cgms.c new file mode 100644 index 0000000..678ce6e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/src/cgms.c @@ -0,0 +1,281 @@ +/** + **************************************************************************************** + * + * @file cgms.c + * + * @brief Continuous Glucose Monitoring Profile Service implementation. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup CGMS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_CGM_SERVER) +#include "cgmp_common.h" + +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "cgms.h" +#include "cgms_task.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +// Default read perm +#define RD_P (PERM(RD, ENABLE) | PERM(RP, UNAUTH)) +// Default write perm +#define WR_P (PERM(WRITE_REQ, ENABLE) | PERM(WP, UNAUTH)) +// Default notify perm +#define NTF_P (PERM(NTF, ENABLE) | PERM(NP, UNAUTH)) +// Ind perm +#define IND_P (PERM(IND, ENABLE) | PERM(IP, NO_AUTH)) +// Enable Read Indication (1 = Value not present in Database) +#define RI_P PERM(RI, ENABLE) + +/// Full CGMS Database Description - Used to add attributes into the database +static const struct attm_desc cgms_att_db[CGMS_IDX_NB] = +{ + // ATT Index | ATT UUID | Permission | EXT PERM | MAX ATT SIZE + // Service attribute + [CGMS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + // CGM Measurement Characteristic + [CGMS_IDX_MEAS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [CGMS_IDX_MEAS_VAL] = {ATT_CHAR_CGM_MEASUREMENT, NTF_P, 0, 0}, + [CGMS_IDX_MEAS_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, RD_P | WR_P, RI_P, 0}, + // CGM Features Characteristic + [CGMS_IDX_FEAT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [CGMS_IDX_FEAT_VAL] = {ATT_CHAR_CGM_FEATURES, RD_P, 0, CGMS_FEAT_SIZE_MAX}, + // CGM Status Characteristic + [CGMS_IDX_STATUS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [CGMS_IDX_STATUS_VAL] = {ATT_CHAR_CGM_STATUS, RD_P, RI_P, 0}, + // CGM Session Start Time Characteristic + [CGMS_IDX_SESS_ST_TIME_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [CGMS_IDX_SESS_ST_TIME_VAL] = {ATT_CHAR_CGM_SESSION_START, RD_P | WR_P, RI_P, CGMP_SESS_ST_TIME_SIZE_MAX}, + // CGM Session Run Time Characteristic + [CGMS_IDX_SESS_RUN_TIME_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [CGMS_IDX_SESS_RUN_TIME_VAL] = {ATT_CHAR_CGM_SESSION_RUN, RD_P, RI_P, 0}, + // CGM Record Access Control Point Characteristic + [CGMS_IDX_RACP_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [CGMS_IDX_RACP_VAL] = {ATT_CHAR_REC_ACCESS_CTRL_PT, WR_P | IND_P, 0, CGMS_RACP_SIZE_MAX}, + [CGMS_IDX_RACP_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, RD_P | WR_P, RI_P, 0}, + // CGM Specific Ops Control Point Characteristic + [CGMS_IDX_SPEC_OPS_CTRL_PT_CHAR]= {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [CGMS_IDX_SPEC_OPS_CTRL_PT_VAL] = {ATT_CHAR_CGM_SPECIFIC_OPS_CTRL_PT, WR_P | IND_P, 0, CGMS_OPS_CTRL_PT_SIZE_MAX}, + [CGMS_IDX_SPEC_OPS_CTRL_PT_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, RD_P | WR_P, RI_P, 0}, +}; + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the CGMS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t cgms_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, + uint16_t app_task, uint8_t sec_lvl, struct cgms_db_cfg *p_param) +{ + //------------------ create the attribute database for the profile ------------------- + // Service content flag + uint8_t cfg_flag[] = {0xFF,0xFF,0x03}; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + // Add service in the database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_CONTINUOUS_GLUCOSE_MONITORING, (uint8_t *)&cfg_flag[0], + CGMS_IDX_NB, NULL, p_env->task, &cgms_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS )) | PERM(SVC_MI, ENABLE)); + + // Check if an error has occured + if (status == ATT_ERR_NO_ERROR) + { + // Allocate CGMS required environment variable + struct cgms_env_tag *p_cgms_env = + (struct cgms_env_tag* ) ke_malloc(sizeof(struct cgms_env_tag), KE_MEM_ATT_DB); + + // Initialize CGMS environment + + p_env->env = (prf_env_t*) p_cgms_env; + p_cgms_env->shdl = *p_start_hdl; + + // Keep CGM Features @see enum cgm_feat_bf + p_cgms_env->cgm_feature = p_param->cgm_feature; + + // Multi Instantiated APP task + p_cgms_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Multi Instantiated app task + p_cgms_env->prf_env.prf_task = p_env->task + | PERM(PRF_MI, ENABLE); + + // Initialize environment variable + p_env->id = TASK_ID_CGMS; + cgms_task_init(&(p_env->desc)); + + // Store the Features into AT database + uint8_t value[CGMS_FEAT_SIZE_MAX]; + uint8_t *p_val = &value[0]; + uint16_t handle = cgms_att2handle(CGMS_IDX_FEAT_VAL); + // E22 CRC to protect the fields + // Predefined value when crc is not supported + // This field exists in all the cases + uint16_t crc = 0xFFFF;; + + co_write24p(p_val, p_param->cgm_feature); + p_val += 3; + *p_val++ = ((p_param->sample_location) << 4) | p_param->type_sample; + + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + crc = prf_e2e_crc(&value[0], CGMS_FEAT_SIZE_MAX - 2); + } + + co_write16p(p_val, crc); + + attm_att_set_value(handle, CGMS_FEAT_SIZE_MAX, 0, &value[0]); + + // If we are here, database has been fulfilled with success, go to idle state + for(uint8_t idx = 0; idx < BLE_CONNECTION_MAX ; idx++) + { + /* Put CGMS in disabled state */ + ke_state_set(KE_BUILD_ID(p_env->task, idx), CGMS_FREE); + } + } + + return (status); +} +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void cgms_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + /* Put CGMS in disabled state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), CGMS_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the CGMS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void cgms_destroy(struct prf_task_env *p_env) +{ + struct cgms_env_tag *p_cgms_env = (struct cgms_env_tag *) p_env->env; + + // Cleanup environment variable for each task instances + + // Free profile environment variables + p_env->env = NULL; + ke_free(p_cgms_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void cgms_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct cgms_env_tag *p_cgms_env = (struct cgms_env_tag*) p_env->env; + p_cgms_env->prfl_state[conidx] = CGMS_PRFL_STATE_CLEAR; + + /* Put CGMS in IDLE state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), CGMS_IDLE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// CGMS Task interface required by profile manager +const struct prf_task_cbs cgms_itf = +{ + (prf_init_fnct) cgms_init, + cgms_destroy, + cgms_create, + cgms_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *cgms_prf_itf_get(void) +{ + return &cgms_itf; +} + +uint16_t cgms_att2handle(uint8_t att_idx) +{ + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + uint16_t handle = p_cgms_env->shdl + att_idx; + + return handle; +} + +uint8_t cgms_handle2att(uint16_t handle) +{ + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + uint8_t att_idx = handle - p_cgms_env->shdl; + + return att_idx; +} + +#endif //(BLE_CGM_SERVER) + +/// @} CGMS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/src/cgms.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/src/cgms.h new file mode 100644 index 0000000..3273ae6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/src/cgms.h @@ -0,0 +1,222 @@ +/** + **************************************************************************************** + * + * @file cgms.h + * + * @brief Header file - Continuous Glucose Monitoring Profile Service. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CGMS_H_ +#define _CGMS_H_ + +/** + **************************************************************************************** + * @addtogroup CGMS Continuous Glucose Monitoring Profile Service + * @ingroup CGMS + * @brief Continuous Glucose Monitoring Profile Service + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_CGM_SERVER) +#include "cgmp_common.h" +#include "cgms_task.h" + +#include "prf_types.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Continuous Glucose Monitoring Profile Service role task instances +#define CGMS_IDX_MAX (BLE_CONNECTION_MAX) +/// Internal state of CCC enabled set to 0 +#define CGMS_PRFL_STATE_CLEAR (0) +/// Maximum Features size (uint24 + 2x 4bit + crc) +#define CGMS_FEAT_SIZE_MAX (3 + 1 + 2) +///Maximum Status size +#define CGMS_IDX_STATUS_SIZE_MAX (2 + 3 + 2) +/// Maximum Session Run Time size +#define CGMS_IDX_SESS_RUN_TIME_SIZE_MAX (2 + 2) +/// Maximum Control Point size (OpCode + Operator+ Filter + FilterParameter) +#define CGMS_RACP_SIZE_MAX (2 + 5 + 2) +/// Maximum Specific OPs Control Point size (OpCode + Operator+ Operand) +#define CGMS_OPS_CTRL_PT_SIZE_MAX (2 + sizeof(struct cgm_calib_operand) + 2) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + /// Possible states of the CGMS task +enum cgms_state_id +{ + /// Not connected state + CGMS_FREE, + /// Idle state + CGMS_IDLE, + /// Read request + CGMS_OP_READ, + /// Notify + CGMS_OP_NOTIFY, + /// Indicate Spot_Measurement + CGMS_OP_INDICATE_MEAS, + /// Indicate RACP + CGMS_OP_INDICATE_RACP, + CGMS_OP_INDICATE_RACP_NO_CMP, + /// Application request + CGMS_OP_WRITE_OPS_CTRL_PT, + CGMS_OP_INDICATE_OPS_CTRL_PT, + + /// Number of defined states. + CGMS_STATE_MAX +}; + +/// CGM Service - Attribute List +enum cgms_att_list +{ + /// CGM Service + CGMS_IDX_SVC, + /// CGM Measurement Characteristic + CGMS_IDX_MEAS_CHAR, + CGMS_IDX_MEAS_VAL, + /// CCC Descriptor + CGMS_IDX_MEAS_CCC, + /// CGM Features Characteristic + CGMS_IDX_FEAT_CHAR, + CGMS_IDX_FEAT_VAL, + /// CGM Status Characteristic + CGMS_IDX_STATUS_CHAR, + CGMS_IDX_STATUS_VAL, + /// CGM Session Start Time Characteristic + CGMS_IDX_SESS_ST_TIME_CHAR, + CGMS_IDX_SESS_ST_TIME_VAL, + /// CGM Session Run Time Characteristic + CGMS_IDX_SESS_RUN_TIME_CHAR, + CGMS_IDX_SESS_RUN_TIME_VAL, + /// CGM Record Access Control Point Characteristic + CGMS_IDX_RACP_CHAR, + CGMS_IDX_RACP_VAL, + /// CCC Descriptor + CGMS_IDX_RACP_CCC, + /// CGM Specific Ops Control Point Characteristic + CGMS_IDX_SPEC_OPS_CTRL_PT_CHAR, + CGMS_IDX_SPEC_OPS_CTRL_PT_VAL, + /// CCC Descriptor + CGMS_IDX_SPEC_OPS_CTRL_PT_CCC, + + /// Number of attributes + CGMS_IDX_NB, +}; + +/// Internal state of CCC enabled per Characteristic and RACP process @see struct cgms_env_tag +enum cgms_prfl_state_bf +{ + /// CCC for Measurement + CGMS_NTF_MEAS_ENABLED_POS = 0, + CGMS_NTF_MEAS_ENABLED_BIT = CO_BIT(CGMS_NTF_MEAS_ENABLED_POS), + + /// CCC for RACP + CGMS_IND_RACP_ENABLED_POS = 1, + CGMS_IND_RACP_ENABLED_BIT = CO_BIT(CGMS_IND_RACP_ENABLED_POS), + + /// CCC for Specific OPS Control Point + CGMS_IND_SOPS_ENABLED_POS = 2, + CGMS_IND_SOPS_ENABLED_BIT = CO_BIT(CGMS_IND_SOPS_ENABLED_POS), + + /// RACP keep state of the procedure + CGMS_RACP_IN_PROG_POS = 3, + CGMS_RACP_IN_PROG_BIT = CO_BIT(CGMS_RACP_IN_PROG_POS), +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Continuous Glucose Monitoring Profile Service environment variable +struct cgms_env_tag +{ + /// profile environment + prf_env_t prf_env; + + /// CGM Service Start Handle + uint16_t shdl; + /// CGM Features @see enum cgm_feat_bf + uint32_t cgm_feature; + /// Internal state of CCC enabled @see enum cgms_prfl_state_bf: + uint8_t prfl_state[CGMS_IDX_MAX]; + /// State of different task instances + ke_state_t state[CGMS_IDX_MAX]; + +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Convert raw handle to the attribute index @see enum cgms_att_list + * + * @param[in] handle Raw handle + * + * @return Attribute index + **************************************************************************************** + */ +uint8_t cgms_handle2att(uint16_t handle); + +/** + **************************************************************************************** + * @brief Convert attribute to the raw handle index @see enum cgms_att_list + * + * @param[in] att_idx Attribute index + * + * @return Handle of the attribute + **************************************************************************************** + */ +uint16_t cgms_att2handle(uint8_t att_idx); + +/** + **************************************************************************************** + * @brief Retrieve CGMP service profile interface + * + * @return CGMP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *cgms_prf_itf_get(void); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param task_desc Task descriptor to fill + **************************************************************************************** + */ +void cgms_task_init(struct ke_task_desc *task_desc); + +#endif //(BLE_CGM_SERVER) + +/// @} CGMS + +#endif //(_CGMS_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/src/cgms_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/src/cgms_task.c new file mode 100644 index 0000000..dd7a795 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cgmp/cgms/src/cgms_task.c @@ -0,0 +1,1716 @@ +/** + **************************************************************************************** + * + * @file cgms_task.c + * + * @brief Continuous Glucose Monitoring Profile Service Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup CGMSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_CGM_SERVER) +#include "cgmp_common.h" + +#include "gapc.h" +#include "gattc_task.h" +#include "attm.h" +#include "cgms.h" +#include "cgms_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief SEND RACP response indication. + * If cp_opcode == CGMP_OPCODE_NUMBER_OF_STORED_RECORDS_RESP + * then sends the number of stored records response using number_of_records + * + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @param[in] cp_opcode Sent in the header of response- Mandatory + * @param[in] req_cp_opcode Copy the requested op_code + * @param[in] rsp_code Result code + * @param[in] num_records Used if cp_opcode == CGMP_OPCODE_NUMBER_OF_STORED_RECORDS_RESP + **************************************************************************************** + */ +__STATIC void cgms_racp_resp_send(ke_task_id_t const dest_id, ke_task_id_t const src_id, uint8_t cp_opcode, + uint8_t req_cp_opcode, uint8_t rsp_code, uint16_t num_records) +{ + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ind; + // Length of the data block + uint16_t length; + // Handle to send the indication + uint16_t handle; + + handle = cgms_att2handle(CGMS_IDX_RACP_VAL); + // OpCode -1oct,Operator=Null-1oct,Operand -2oct + length = CGMP_RACP_RSP_SIZE; + // Allocate the GATT notification message + p_ind = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + dest_id, + src_id, + gattc_send_evt_cmd, length); + + // Fill in the parameter structure + p_ind->operation = GATTC_INDICATE; + p_ind->handle = handle; + p_ind->length = length; + // Fill data + // Procedure Op Code + p_ind->value[0] = cp_opcode; + // Operator - Null + p_ind->value[1] = CGMP_OP_NULL; + if (cp_opcode == CGMP_OPCODE_NUM_OF_STRD_RECS_RSP) + { + co_write16p(&(p_ind->value[2]), num_records); + } + else + { + p_ind->value[2] = req_cp_opcode; + p_ind->value[3] = rsp_code; + } + + // Send notification to peer device + ke_msg_send(p_ind); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMS_ENABLE_REQ message. + * + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cgms_enable_req_handler(ke_msg_id_t const msgid, + struct cgms_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Allocate Response message + struct cgms_enable_rsp *p_cmp_evt = KE_MSG_ALLOC(CGMS_ENABLE_RSP, src_id, dest_id, cgms_enable_rsp); + + if (ke_state_get(dest_id) == CGMS_IDLE) + { + // CCCs for the current connection + p_cgms_env->prfl_state[KE_IDX_GET(src_id)] = p_param->prfl_ntf_ind_cfg; + + status = GAP_ERR_NO_ERROR; + } + + // Send completed information to APP task that contains error status + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMS_RD_CHAR_CFM message. + * Read confirmation from the app with CGM Status, CGM Session Start Time, CGM Session Run Time + * + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cgms_rd_char_cfm_handler(ke_msg_id_t const msgid, + struct cgms_rd_char_cfm *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CGMS_OP_READ) + { + struct gattc_read_cfm *p_cfm; + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + // Determine handle + uint16_t handle = 0; + // Message size + uint16_t length = 0; + + // Add E2E-CRC + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + length += CGMP_CRC_LEN; // E2E-CRC size + } + + switch (p_param->char_type) + { + case CGMS_CHAR_ID_STATUS_VAL: + { + handle = p_cgms_env->shdl + CGMS_IDX_STATUS_VAL; + length += CGMS_RD_STATUS_CFM_SIZE; + } break; + + case CGMS_CHAR_ID_SESSION_START_TIME_VAL: + { + handle = p_cgms_env->shdl + CGMS_IDX_SESS_ST_TIME_VAL; + length += CGMS_RD_SESS_START_TIME_CFM_SIZE; + } break; + + case CGMS_CHAR_ID_SESSION_RUN_TIME_VAL: + { + handle = p_cgms_env->shdl + CGMS_IDX_SESS_RUN_TIME_VAL; + length += CGMS_RD_SESS_RUN_TIME_CFM_SIZE; + } break; + + default: + { + // Do nothing + } break; + } + + // Send data to peer device + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, KE_IDX_GET(dest_id)), dest_id, + gattc_read_cfm, length); + + p_cfm->handle = handle; + p_cfm->length = length; + p_cfm->status = p_param->status; + + // Fill data per characteristic type + switch (p_param->char_type) + { + case CGMS_CHAR_ID_STATUS_VAL: + { + co_write16p(&p_cfm->value[0], p_param->value.status.time_offset); + p_cfm->value[2] = p_param->value.status.warning; + p_cfm->value[3] = p_param->value.status.cal_temp; + p_cfm->value[4] = p_param->value.status.annunc_status; + } break; + + case CGMS_CHAR_ID_SESSION_START_TIME_VAL: + { + prf_pack_date_time(&p_cfm->value[0], &(p_param->value.sess_start_time.sess_start_time)); + p_cfm->value[7] = p_param->value.sess_start_time.time_zone; + p_cfm->value[8] = p_param->value.sess_start_time.dst_offset; + } break; + + case CGMS_CHAR_ID_SESSION_RUN_TIME_VAL: + { + co_write16p(&p_cfm->value[0], p_param->value.sess_run_time.run_time); + } break; + + default: + { + // Do nothing + } break; + } + + // Add E2E-CRC + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + uint16_t crc = prf_e2e_crc(&p_cfm->value[0],length-CGMP_CRC_LEN); + + co_write16p(&p_cfm->value[length-CGMP_CRC_LEN], crc); + } + + ke_state_set(dest_id, CGMS_IDLE); + // Send message + ke_msg_send(p_cfm); + } + // Error condition + else + { + // Send a command complete to the App with error reason + struct cgms_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(CGMS_CMP_EVT, + src_id, + dest_id, cgms_cmp_evt); + + // Read characteristic confirmation is not allowed + p_cmp_evt->operation = CGMS_RD_CHAR_OP_CODE; + p_cmp_evt->status = PRF_ERR_REQ_DISALLOWED; + + ke_msg_send(p_cmp_evt); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMS_WR_OPS_CTRL_PT_CFM message. + * Confirmation from OPS Control Point + * + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cgms_wr_ops_ctrl_pt_cfm_handler(ke_msg_id_t const msgid, + struct cgms_wr_ops_ctrl_pt_cfm *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t status = ATT_ERR_NO_ERROR; + + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + uint8_t conidx = KE_IDX_GET(dest_id); + + if (ke_state_get(dest_id) != CGMS_OP_WRITE_OPS_CTRL_PT) + { + // Error condition + status = PRF_ERR_REQ_DISALLOWED; + } + + // Only send if CCC is properly configured + if ((status == ATT_ERR_NO_ERROR) && GETB(p_cgms_env->prfl_state[conidx], CGMS_IND_SOPS_ENABLED)) + { + // Handle to send the indication + uint16_t handle = p_cgms_env->shdl + CGMS_IDX_SPEC_OPS_CTRL_PT_VAL; + // Length of the data block + uint16_t length = 2 * sizeof(uint8_t); // Minimum Op-Code & Response codes present + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ind; + + switch (p_param->opcode) + { + // Communication interval in minutes 3 + case CGMP_OPS_CODE_CGM_COM_INTVL_RSP: + // Request Op Code, Response Code Value 28 + case CGMP_OPS_CODE_RSP_CODE: + { + length += sizeof(uint16_t); + } break; + + // Calibration Data 6 + case CGMP_OPS_CODE_GLUC_CALIB_VALUE_RSP: + { + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_CALIB_SUP)) + { + length += CGMP_OPS_CALIBRATION_SIZE; + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + // Patient High bG value in mg/dL 9 + case CGMP_OPS_CODE_PAT_HIGH_ALERT_LEVEL_RSP: + // Patient Low bG value in mg/dL 12 + case CGMP_OPS_CODE_PAT_LOW_ALERT_LEVEL_RSP: + { + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_PAT_HIGH_LOW_ALERT_SUP)) + { + length += sizeof(uint16_t); + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + // Hypo Alert Level value in mg/dL 15 + case CGMP_OPS_CODE_HYPO_ALERT_LEVEL_RSP: + { + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_HYPO_ALERT_SUP)) + { + length += sizeof(uint16_t); + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + // Hyper Alert Level value in mg/dL 18 + case CGMP_OPS_CODE_HYPER_ALERT_LEVEL_RSP: + { + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_HYPER_ALERT_SUP)) + { + length += sizeof(uint16_t); + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + // Rate of Decrease Alert Level value in mg/dL/min 21 + case CGMP_OPS_CODE_RATE_OF_DECR_ALERT_LEVEL_RSP: + // Rate of Increase Alert Level value in mg/dL/min 24 + case CGMP_OPS_CODE_RATE_OF_INCR_ALERT_LEVEL_RSP: + { + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_RATE_OF_INCR_DECR_ALERT_SUP)) + { + length += sizeof(uint16_t); + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + default: + { + // Do nothing + } break; + } + + // Add E2E-CRC + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + length += CGMP_CRC_LEN; // E2E-CRC size + } + + // Allocate the GATT notification message + p_ind = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + gattc_send_evt_cmd, length); + + // Fill in the parameter structure + p_ind->operation = GATTC_INDICATE; + p_ind->handle = handle; + p_ind->length = length; + // Fill data + // Op Code + p_ind->value[0] = p_param->opcode; + // Response + p_ind->value[1] = p_param->rsp; + + // Operand based on op code + switch (p_param->opcode) + { + // Communication interval in minutes 3 + case CGMP_OPS_CODE_CGM_COM_INTVL_RSP: + { + co_write16p(&(p_ind->value[2]), p_param->operand.intvl); + } break; + + // Calibration Data Record Number 5 + case CGMP_OPS_CODE_GET_GLUC_CALIB_VALUE: + { + co_write16p(&(p_ind->value[2]), p_param->operand.cal_data_record_num); + } break; + + // Patient High bG value in mg/dL 9 + case CGMP_OPS_CODE_PAT_HIGH_ALERT_LEVEL_RSP: + { + co_write16p(&(p_ind->value[2]), p_param->operand.pat_high_bg); + } break; + + // Patient Low bG value in mg/dL 12 + case CGMP_OPS_CODE_PAT_LOW_ALERT_LEVEL_RSP: + { + co_write16p(&(p_ind->value[2]), p_param->operand.pat_low_bg); + } break; + + // Hypo Alert Level value in mg/dL 15 + case CGMP_OPS_CODE_HYPO_ALERT_LEVEL_RSP: + { + co_write16p(&(p_ind->value[2]), p_param->operand.hypo_alert_level); + } break; + + // Hyper Alert Level value in mg/dL 18 + case CGMP_OPS_CODE_HYPER_ALERT_LEVEL_RSP: + { + co_write16p(&(p_ind->value[2]), p_param->operand.hyper_alert_level); + } break; + + // Rate of Decrease Alert Level value in mg/dL/min 21 + case CGMP_OPS_CODE_RATE_OF_DECR_ALERT_LEVEL_RSP: + { + co_write16p(&(p_ind->value[2]), p_param->operand.rate_decr_alert_level); + } break; + + // Rate of Increase Alert Level value in mg/dL/min 24 + case CGMP_OPS_CODE_RATE_OF_INCR_ALERT_LEVEL_RSP: + { + co_write16p(&(p_ind->value[2]), p_param->operand.rate_incr_alert_level); + } break; + + // Request Op Code, Response Code Value 28 + case CGMP_OPS_CODE_RSP_CODE: + { + p_ind->value[2] = p_param->operand.req_rsp_value.req_op_code; + p_ind->value[3] = p_param->operand.req_rsp_value.rsp_code; + } break; + + // Calibration Data. 6 + case CGMP_OPS_CODE_GLUC_CALIB_VALUE_RSP: + { + co_write16p(&(p_ind->value[2]), p_param->operand.calib.cal_gluc_concent); + co_write16p(&(p_ind->value[4]), p_param->operand.calib.cal_time); + p_ind->value[6] = p_param->operand.calib.cal_type_spl; + p_ind->value[7] = p_param->operand.calib.cal_spl_loc; + co_write16p(&(p_ind->value[8]), p_param->operand.calib.next_cal_time); + co_write16p(&(p_ind->value[10]), p_param->operand.calib.cal_record_num); + p_ind->value[12] = p_param->operand.calib.cal_status; + } break; + + default: + { + // Do nothing + } break; + } + + // Add E2E-CRC + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + uint16_t crc = prf_e2e_crc(&p_ind->value[0], length-CGMP_CRC_LEN); + co_write16p(&p_ind->value[length-CGMP_CRC_LEN], crc); + } + + ke_state_set(dest_id, CGMS_OP_INDICATE_OPS_CTRL_PT); + // Send notification to peer device + ke_msg_send(p_ind); + } + else + { + status = PRF_ERR_IND_DISABLED; + } + + // In error case immediately send response to HL + if (status != ATT_ERR_NO_ERROR) + { + // Send a command complete to the App with error reason why Indicate msg could not be sent. + struct cgms_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(CGMS_CMP_EVT, + src_id, + dest_id, cgms_cmp_evt); + + // Indication is Special OPS Control Point + p_cmp_evt->operation = CGMS_OPS_CTRL_PT_OP_CODE; + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + + // Check that task is in idle state + if(ke_state_get(dest_id) == CGMS_IDLE) + { + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t att_idx = cgms_handle2att(p_param->handle); + + // Send data to peer device + struct gattc_read_cfm *p_cfm = NULL; + + uint8_t status = ATT_ERR_NO_ERROR; + + switch(att_idx) + { + case CGMS_IDX_MEAS_CCC: + case CGMS_IDX_SPEC_OPS_CTRL_PT_CCC: + case CGMS_IDX_RACP_CCC: + { + // Fill data + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + + switch(att_idx) + { + uint16_t ccc; + + case CGMS_IDX_MEAS_CCC: + { + // CCC for Measurement + ccc = (GETB(p_cgms_env->prfl_state[conidx], CGMS_NTF_MEAS_ENABLED) ? PRF_CLI_START_NTF : 0); + co_write16p(p_cfm->value, ccc); + } break; + + case CGMS_IDX_SPEC_OPS_CTRL_PT_CCC: + { + // CCC for Specific OPS Ctrl Pt + ccc = (GETB(p_cgms_env->prfl_state[conidx], CGMS_IND_SOPS_ENABLED) ? PRF_CLI_START_IND : 0); + co_write16p(p_cfm->value, ccc); + } break; + + case CGMS_IDX_RACP_CCC: + { + // CCC for RACP + ccc = (GETB(p_cgms_env->prfl_state[conidx], CGMS_IND_RACP_ENABLED) ? PRF_CLI_START_IND : 0); + co_write16p(p_cfm->value, ccc); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } break; + + case CGMS_IDX_STATUS_VAL: + case CGMS_IDX_SESS_ST_TIME_VAL: + case CGMS_IDX_SESS_RUN_TIME_VAL: + { + // Need request APP + struct cgms_rd_char_req_ind *p_ind = KE_MSG_ALLOC(CGMS_RD_CHAR_REQ_IND, + prf_dst_task_get(&(p_cgms_env->prf_env), conidx), + dest_id, + cgms_rd_char_req_ind); + + switch(att_idx) + { + case CGMS_IDX_STATUS_VAL: + { + // Characteristic id @ref cgms_char_type + p_ind->char_type = CGMS_CHAR_ID_STATUS_VAL; + } break; + + case CGMS_IDX_SESS_ST_TIME_VAL: + { + // Characteristic id @ref cgms_char_type + p_ind->char_type = CGMS_CHAR_ID_SESSION_START_TIME_VAL; + } break; + + case CGMS_IDX_SESS_RUN_TIME_VAL: + { + // Characteristic id @ref cgms_char_type + p_ind->char_type = CGMS_CHAR_ID_SESSION_RUN_TIME_VAL; + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + // Send the request indication to the application + ke_msg_send(p_ind); + + // Go to busy state + ke_state_set(dest_id, CGMS_OP_READ); + } break; + + default: + { + p_cfm = KE_MSG_ALLOC(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm); + p_cfm->length = 0; + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + if (p_cfm != NULL) + { + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + } + // Else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + uint8_t att_idx = cgms_handle2att(p_param->handle); + struct gattc_att_info_cfm *p_cfm; + + // Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = GAP_ERR_NO_ERROR; + + switch(att_idx) + { + case CGMS_IDX_MEAS_CCC: + case CGMS_IDX_SPEC_OPS_CTRL_PT_CCC: + case CGMS_IDX_RACP_CCC: + { + // Check if it's a client configuration char + // CCC attribute length = 2 + p_cfm->length = sizeof(uint16_t); + } break; + + case CGMS_IDX_RACP_VAL: + { + // RACP value + p_cfm->length = CGMS_RACP_SIZE_MAX; + } break; + + case CGMS_IDX_SESS_ST_TIME_VAL: + { + // Session Start Time value + p_cfm->length = CGMP_SESS_ST_TIME_SIZE_MAX; + } break; + + case CGMS_IDX_SPEC_OPS_CTRL_PT_VAL: + { + // Specific Ops Control Point value + p_cfm->length = CGMS_OPS_CTRL_PT_SIZE_MAX; + } break; + + default: + { + // Not expected request + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } break; + } + + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see GATTC_WRITE_REQ_IND message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + // Message status + int msg_status = KE_MSG_CONSUMED; + + do + { + // Check the connection handle + if (p_cgms_env == NULL) + { + break; + } + + // Check that task is in idle state + if(ke_state_get(dest_id) == CGMS_IDLE) + { + uint8_t conidx = KE_IDX_GET(src_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t att_idx = cgms_handle2att(p_param->handle); + + switch(att_idx) + { + case CGMS_IDX_MEAS_CCC: + case CGMS_IDX_SPEC_OPS_CTRL_PT_CCC: + case CGMS_IDX_RACP_CCC: + { + uint16_t ntf_cfg; + // Inform the HL about the new configuration + struct cgms_wr_char_ccc_ind *p_ind = KE_MSG_ALLOC(CGMS_WR_CHAR_CCC_IND, + prf_dst_task_get(&(p_cgms_env->prf_env), conidx), + dest_id, + cgms_wr_char_ccc_ind); + + // Get the value + co_write16p(&ntf_cfg, p_param->value[0]); + + switch(att_idx) + { + case CGMS_IDX_MEAS_CCC: + { + // CCC for Measurement + p_ind->char_type = CGMS_CHAR_ID_MEAS_CCC; + + if (ntf_cfg & PRF_CLI_START_NTF) + { + SETB(p_cgms_env->prfl_state[conidx], CGMS_NTF_MEAS_ENABLED, 1); + } + } break; + + case CGMS_IDX_SPEC_OPS_CTRL_PT_CCC: + { + // CCC for Specific OPS Ctrl Pt + p_ind->char_type = CGMS_CHAR_ID_OPS_CTRL_PT_CCC; + + if (ntf_cfg & PRF_CLI_START_IND) + { + SETB(p_cgms_env->prfl_state[conidx], CGMS_IND_SOPS_ENABLED, 1); + } + } break; + + case CGMS_IDX_RACP_CCC: + { + // CCC for RACP + p_ind->char_type = CGMS_CHAR_ID_RACP_CCC; + + if (ntf_cfg & PRF_CLI_START_IND) + { + SETB(p_cgms_env->prfl_state[conidx], CGMS_IND_RACP_ENABLED, 1); + } + } break; + + default: + { + // Do nothing + } break; + } + + p_ind->ind_cfg = ntf_cfg; + + ke_msg_send(p_ind); + + } break; + + case CGMS_IDX_SESS_ST_TIME_VAL: + { + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + if (p_param->length < CGMP_SESS_ST_TIME_SIZE_MAX) + { + status = CGM_ERROR_MISSING_CRC; + } + else + { + uint16_t crc = prf_e2e_crc(&p_param->value[0], + CGMP_SESS_ST_TIME_SIZE_MAX - CGMP_CRC_LEN); + + // Check crc + if (crc != co_read16p(&(p_param->value[CGMP_SESS_ST_TIME_SIZE_MAX - CGMP_CRC_LEN]))) + { + status = CGM_ERROR_INVALID_CRC; + } + } + } + + if (status == GAP_ERR_NO_ERROR) + { + int8_t time_zone = p_param->value[7]; + uint8_t dst_offset = p_param->value[8]; + + if (!( (time_zone == CGM_TIME_ZONE_UNKNOWN) + || ((time_zone >= CGM_TIME_ZONE_MIN) && (time_zone <= CGM_TIME_ZONE_MAX)))) + { + // Incorrect request + status = PRF_OUT_OF_RANGE; + } + + if (!( (dst_offset == CGM_DST_OFFSET_STANDARD_TIME) + ||(dst_offset == CGM_DST_OFFSET_HALF_AN_HOUR_DAYLIGHT_TIME) + ||(dst_offset == CGM_DST_OFFSET_DAYLIGHT_TIME) + ||(dst_offset == CGM_DST_OFFSET_DOUBLE_DAYLIGHT_TIME) + ||(dst_offset == CGM_DST_OFFSET_UNKNOWN_DAYLIGHT_TIME))) + { + // Incorrect request + status = PRF_OUT_OF_RANGE; + } + + if (status == GAP_ERR_NO_ERROR) + { + // Inform the HL about the new Time + struct cgms_wr_sess_start_time_ind *p_ind = KE_MSG_ALLOC(CGMS_WR_SESS_START_TIME_IND, + prf_dst_task_get(&p_cgms_env->prf_env, conidx), + prf_src_task_get(&p_cgms_env->prf_env, conidx), + cgms_wr_sess_start_time_ind); + + prf_unpack_date_time((uint8_t *) &p_param->value[0], &p_ind->sess_start_time); + p_ind->time_zone = time_zone; + p_ind->dst_offset = dst_offset; + + ke_msg_send(p_ind); + } + } + } break; + + case CGMS_IDX_SPEC_OPS_CTRL_PT_VAL: + { + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + uint16_t length = CGMP_CP_MIN_LEN; + + // Length of the message base on the OpCode + switch (p_param->value[0]) + { + // Communication interval in minutes 1 + case CGMP_OPS_CODE_SET_CGM_COM_INTVL: + // Communication interval in minutes 3 + case CGMP_OPS_CODE_CGM_COM_INTVL_RSP: + // Calibration Data Record Number 5 + case CGMP_OPS_CODE_GET_GLUC_CALIB_VALUE: + // Patient High bG value in mg/dL 7 + case CGMP_OPS_CODE_SET_PAT_HIGH_ALERT_LEVEL: + // Patient High bG value in mg/dL 9 + case CGMP_OPS_CODE_PAT_HIGH_ALERT_LEVEL_RSP: + // Patient Low bG value in mg/dL 10 + case CGMP_OPS_CODE_SET_PAT_LOW_ALERT_LEVEL: + // Patient Low bG value in mg/dL 12 + case CGMP_OPS_CODE_PAT_LOW_ALERT_LEVEL_RSP: + // Hypo Alert Level value in mg/dL 13 + case CGMP_OPS_CODE_SET_HYPO_ALERT_LEVEL: + // Hypo Alert Level value in mg/dL 15 + case CGMP_OPS_CODE_HYPO_ALERT_LEVEL_RSP: + // Hyper Alert Level value in mg/dL 16 + case CGMP_OPS_CODE_SET_HYPER_ALERT_LEVEL: + // Hyper Alert Level value in mg/dL 18 + case CGMP_OPS_CODE_HYPER_ALERT_LEVEL_RSP: + // Value in mg/dL/min 19 + case CGMP_OPS_CODE_SET_RATE_OF_DECR_ALERT_LEVEL: + // Value in mg/dL/min 21 + case CGMP_OPS_CODE_RATE_OF_DECR_ALERT_LEVEL_RSP: + // Value in mg/dL/min 22 + case CGMP_OPS_CODE_SET_RATE_OF_INCR_ALERT_LEVEL: + // Value in mg/dL/min 24 + case CGMP_OPS_CODE_RATE_OF_INCR_ALERT_LEVEL_RSP: + // Request Op Code, Response Code Value + case CGMP_OPS_CODE_RSP_CODE: + { + length += sizeof(uint16_t); + } break; + + // Defined in the Cal Value Fields 4 + case CGMP_OPS_CODE_SET_GLUC_CALIB_VALUE: + // Calibration Data 6 + case CGMP_OPS_CODE_GLUC_CALIB_VALUE_RSP: + { + length += CGMP_OPS_CALIBRATION_SIZE; + } break; + + default: + { + // Do nothing + } break; + } + + if (p_param->length < length) + { + status = CGM_ERROR_MISSING_CRC; + } + else + { + uint16_t crc = prf_e2e_crc(&p_param->value[0], p_param->length - CGMP_CRC_LEN); + + // Check crc + if (crc != co_read16p(&(p_param->value[length]))) + { + status = CGM_ERROR_INVALID_CRC; + } + } + } + + if (status == GAP_ERR_NO_ERROR) + { + // Inform the HL about the new Time + struct cgms_wr_ops_ctrl_pt_req_ind *p_ind = KE_MSG_ALLOC(CGMS_WR_OPS_CTRL_PT_REQ_IND, + prf_dst_task_get(&p_cgms_env->prf_env, conidx), + prf_src_task_get(&p_cgms_env->prf_env, conidx), + cgms_wr_ops_ctrl_pt_req_ind); + + // Fill data + memset(p_ind, 0, sizeof(struct cgms_wr_ops_ctrl_pt_req_ind)); + // Op Code + p_ind->opcode = p_param->value[0]; + // Response + p_ind->rsp = p_param->value[1]; + // Operand based on op code + switch (p_ind->opcode) + { + // Communication interval in minutes 1 + case CGMP_OPS_CODE_SET_CGM_COM_INTVL: + // Communication interval in minutes 3 + case CGMP_OPS_CODE_CGM_COM_INTVL_RSP: + { + p_ind->operand.intvl = co_read16p(&(p_param->value[2])); + } break; + + // Calibration Data Record Number 5 + case CGMP_OPS_CODE_GET_GLUC_CALIB_VALUE: + { + p_ind->operand.cal_data_record_num = co_read16p(&(p_param->value[2])); + } break; + + // Patient High bG value in mg/dL 7 + case CGMP_OPS_CODE_SET_PAT_HIGH_ALERT_LEVEL: + // Patient High bG value in mg/dL 9 + case CGMP_OPS_CODE_PAT_HIGH_ALERT_LEVEL_RSP: + { + p_ind->operand.pat_high_bg = co_read16p(&(p_param->value[2])); + } break; + + // Patient Low bG value in mg/dL 10 + case CGMP_OPS_CODE_SET_PAT_LOW_ALERT_LEVEL: + // Patient Low bG value in mg/dL 12 + case CGMP_OPS_CODE_PAT_LOW_ALERT_LEVEL_RSP: + { + p_ind->operand.pat_low_bg = co_read16p(&(p_param->value[2])); + } break; + + // Hypo Alert Level value in mg/dL 13 + case CGMP_OPS_CODE_SET_HYPO_ALERT_LEVEL: + // Hypo Alert Level value in mg/dL 15 + case CGMP_OPS_CODE_HYPO_ALERT_LEVEL_RSP: + { + p_ind->operand.hypo_alert_level = co_read16p(&(p_param->value[2])); + } break; + + // Hyper Alert Level value in mg/dL 16 + case CGMP_OPS_CODE_SET_HYPER_ALERT_LEVEL: + // Hyper Alert Level value in mg/dL 18 + case CGMP_OPS_CODE_HYPER_ALERT_LEVEL_RSP: + { + p_ind->operand.hyper_alert_level = co_read16p(&(p_param->value[2])); + } break; + + // Value in mg/dL/min 19 + case CGMP_OPS_CODE_SET_RATE_OF_DECR_ALERT_LEVEL: + // value in mg/dL/min 21 + case CGMP_OPS_CODE_RATE_OF_DECR_ALERT_LEVEL_RSP: + { + p_ind->operand.rate_decr_alert_level = co_read16p(&(p_param->value[2])); + } break; + + // Value in mg/dL/min 22 + case CGMP_OPS_CODE_SET_RATE_OF_INCR_ALERT_LEVEL: + // Value in mg/dL/min 24 + case CGMP_OPS_CODE_RATE_OF_INCR_ALERT_LEVEL_RSP: + { + p_ind->operand.rate_incr_alert_level = co_read16p(&(p_param->value[2])); + } break; + + // Request Op Code, Response Code Value 28 + case CGMP_OPS_CODE_RSP_CODE: + { + p_ind->operand.req_rsp_value.req_op_code = p_param->value[2]; + p_ind->operand.req_rsp_value.rsp_code = p_param->value[3]; + } break; + + // Defined in Cal Value Fields 4 + case CGMP_OPS_CODE_SET_GLUC_CALIB_VALUE: + // Calibration Data 6 + case CGMP_OPS_CODE_GLUC_CALIB_VALUE_RSP: + { + p_ind->operand.calib.cal_gluc_concent = co_read16p(&(p_param->value[2])); + p_ind->operand.calib.cal_time = co_read16p(&(p_param->value[4])); + p_ind->operand.calib.cal_type_spl = p_param->value[6]; + p_ind->operand.calib.cal_spl_loc = p_param->value[7]; + p_ind->operand.calib.next_cal_time = co_read16p(&(p_param->value[8])); + p_ind->operand.calib.cal_record_num = co_read16p(&(p_param->value[10])); + p_ind->operand.calib.cal_status = p_param->value[12]; + } break; + + default: + { + // Do nothing + } break; + } + + ke_msg_send(p_ind); + // Go to busy state + ke_state_set(dest_id, CGMS_OP_WRITE_OPS_CTRL_PT); + } + } break; + + case CGMS_IDX_RACP_VAL: + { + // Op Code + uint8_t opcode = p_param->value[0]; + // Operator + uint8_t operator = p_param->value[1]; + + // If command to RACP and RACP is not configured for indication + // or Command to report Records and SPOT_MEAS CCC is not configured for indication + if (!GETB(p_cgms_env->prfl_state[conidx], CGMS_IND_RACP_ENABLED) + || (( opcode == CGMP_OPCODE_REP_STRD_RECS) + && (!GETB(p_cgms_env->prfl_state[conidx], CGMS_NTF_MEAS_ENABLED)) + ) + ) + { + // CPP improperly configured + status = PRF_CCCD_IMPR_CONFIGURED; + } + else if (GETB(p_cgms_env->prfl_state[conidx], CGMS_RACP_IN_PROG) + && (opcode != CGMP_OPCODE_ABORT_OP)) + { + // Procedure already in progress + status = PRF_PROC_IN_PROGRESS; + } + // Check it is the valid request + else if ((( opcode >= CGMP_OPCODE_REP_STRD_RECS) + && (opcode <= CGMP_OPCODE_REP_NUM_OF_STRD_RECS)) + && ( + ((opcode != CGMP_OPCODE_ABORT_OP) + && ((operator >= CGMP_OP_ALL_RECS) + && (operator <= CGMP_OP_LAST_REC))) + || + ((opcode == CGMP_OPCODE_ABORT_OP) && (operator == CGMP_OP_NULL)) + ) + ) + { + // Inform the HL about the new Control Point Command + struct cgms_wr_racp_ind *p_ind = KE_MSG_ALLOC(CGMS_WR_RACP_IND, + prf_dst_task_get(&p_cgms_env->prf_env, conidx), + prf_src_task_get(&p_cgms_env->prf_env, conidx), + cgms_wr_racp_ind); + + // Get the value + p_ind->cp_opcode = opcode; + p_ind->cp_operator = operator; + + // Get all Filter Parameter values no matter operator is + switch (operator) + { + case CGMP_OP_LT_OR_EQ: + { + p_ind->filter_type = p_param->value[2]; + p_ind->max_time_offset = co_read16p(&(p_param->value[3])); + } break; + + case CGMP_OP_GT_OR_EQ: + { + p_ind->filter_type = p_param->value[2]; + p_ind->min_time_offset = co_read16p(&(p_param->value[3])); + } break; + + case CGMP_OP_WITHIN_RANGE_OF: + { + p_ind->filter_type = p_param->value[2]; + p_ind->min_time_offset = co_read16p(&(p_param->value[3])); + p_ind->max_time_offset = co_read16p(&(p_param->value[5])); + } break; + + default: + { + // Do nothing + } break; + } + + ke_msg_send(p_ind); + + // Set flag that procedure is started + SETB(p_cgms_env->prfl_state[conidx], CGMS_RACP_IN_PROG, 1); + } + else + { + // Error condition + uint8_t rsp_code = CGMP_RSP_INV_OPERATOR; + + if ( (opcode < CGMP_OPCODE_REP_STRD_RECS) + ||(opcode > CGMP_OPCODE_REP_NUM_OF_STRD_RECS)) + { // Incorrect opcode + rsp_code = CGMP_RSP_OP_CODE_NOT_SUP; + } + else if ((opcode != CGMP_OPCODE_ABORT_OP) && (operator > CGMP_OP_LAST_REC)) + { + rsp_code = CGMP_RSP_OPERATOR_NOT_SUP; + } + else //if ((opcode != CGMP_OPCODE_ABORT_OPERATION) && (operator == CGMP_OPERATOR_NULL)) + { + rsp_code = CGMP_RSP_INV_OPERATOR; + } + + // Procedure complete + SETB(p_cgms_env->prfl_state[conidx], CGMS_RACP_IN_PROG, 0); + cgms_racp_resp_send(src_id, dest_id, CGMP_OPCODE_RSP_CODE, opcode, rsp_code, 0); + + // Special state as we don't need response to the server + ke_state_set(dest_id, CGMS_OP_INDICATE_RACP_NO_CMP); + } + } break; + + default: + { + // Not expected request + status = ATT_ERR_WRITE_NOT_PERMITTED; + } break; + } + + // Send the write response to the peer device + struct gattc_write_cfm *p_cfm = KE_MSG_ALLOC( + GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + else + { + msg_status = KE_MSG_SAVED; + } + + } while(0); + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles @see GATT_NOTIFY_CMP_EVT message meaning that an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + + uint8_t state = ke_state_get(dest_id); + + do + { + if (p_cgms_env == NULL) + { + break; + } + + if ( !((p_param->operation == GATTC_NOTIFY) || (p_param->operation == GATTC_INDICATE)) ) + { + break; + } + + // Measurement sent or RACP sent + // Inform the application that a procedure has been completed + if ((state == CGMS_OP_INDICATE_RACP ) + || (state == CGMS_OP_NOTIFY ) + || (state == CGMS_OP_INDICATE_OPS_CTRL_PT )) + { + // Send a command complete to the App + struct cgms_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(CGMS_CMP_EVT, + prf_dst_task_get(&p_cgms_env->prf_env, conidx), + prf_src_task_get(&p_cgms_env->prf_env, conidx), + cgms_cmp_evt); + + if (state == CGMS_OP_NOTIFY) + { + // Continuous Measurement sent + p_cmp_evt->operation = CGMS_MEAS_CMD_OP_CODE; + } + else if (state == CGMS_OP_INDICATE_RACP) + { + // Indication is RACP + p_cmp_evt->operation = CGMS_RACP_CMD_OP_CODE; + } + else if (state == CGMS_OP_INDICATE_OPS_CTRL_PT) + { + // Indication is Special OPS Control Point + p_cmp_evt->operation = CGMS_OPS_CTRL_PT_OP_CODE; + } + + p_cmp_evt->status = p_param->status; + + ke_msg_send(p_cmp_evt); + } + else if (state != CGMS_OP_INDICATE_RACP_NO_CMP) + { + ASSERT_ERR(0); + } + + // Go to idle state + ke_state_set(dest_id, CGMS_IDLE); + + } while (0); + + return (KE_MSG_CONSUMED); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMS_MEAS_VALUE_CMD message. + * Send MEASUREMENT INDICATION/NOTIFICATION to the connected peer case if CCC enabled + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cgms_meas_value_cmd_handler(ke_msg_id_t const msgid, + struct cgms_meas_value_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Check that task is in idle state + if(ke_state_get(dest_id) == CGMS_IDLE) + { + // Connection index + uint8_t conidx = KE_IDX_GET(dest_id); + uint16_t length; + uint8_t status = ATT_ERR_NO_ERROR; + + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + uint16_t handle; // = p_cgms_env->shdl + CGMS_IDX_PRU_ALERT_VAL; + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ind; + // Data pointer + uint8_t *p_data; + + switch (p_param->operation) + { + case CGMS_MEAS_CMD_OP_CODE: + { + // Check the CCC is enabled + if (GETB(p_cgms_env->prfl_state[conidx], CGMS_NTF_MEAS_ENABLED)) + { + length = CGMS_MEAS_CMD_MIN_LENGTH; + + // E2E-CRC + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + length += CGMP_CRC_LEN; // E2E-CRC size + } + + // Annunciation data + if (GETB(p_param->flags, CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_WARN)) + { + length += sizeof(uint8_t); + } + if (GETB(p_param->flags, CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_CAL_TEMP)) + { + length += sizeof(uint8_t); + } + if (GETB(p_param->flags, CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_STATUS)) + { + length += sizeof(uint8_t); + } + + if ((GETB(p_cgms_env->cgm_feature, CGM_FEAT_CGM_TREND_INFO_SUP)) + && (GETB(p_param->flags, CGM_MEAS_FLAGS_CGM_TREND_INFO))) + { + length += 2 * sizeof(uint8_t); + } + else + { + SETB(p_param->flags, CGM_MEAS_FLAGS_CGM_TREND_INFO, 0); + } + + if ((GETB(p_cgms_env->cgm_feature, CGM_FEAT_CGM_QUALITY_SUP)) + && (GETB(p_param->flags, CGM_MEAS_FLAGS_CGM_QUALITY))) + { + length += 2 * sizeof(uint8_t); + } + else + { + SETB(p_param->flags, CGM_MEAS_FLAGS_CGM_QUALITY, 0); + } + + p_param->flags &= CGMS_MEAS_FLAGS_VALID; + + handle = cgms_att2handle(CGMS_IDX_MEAS_VAL); + // Allocate the GATT notification message + p_ind = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + gattc_send_evt_cmd, length); + + // Fill in the parameter structure + p_ind->operation = GATTC_NOTIFY; + p_ind->handle = handle; + p_ind->length = length; + + // Fill data + // SIZE field + p_ind->value[0] = length; + // FLAGS field + p_ind->value[1] = p_param->flags; + // CGM Glucose Concentration (SFLOAT/16bit) + p_data = &(p_ind->value[2]); + co_write16p(p_data, p_param->gluc_concent); + p_data +=2; + + // Time Offset + co_write16p(p_data, p_param->time_offset); + p_data +=2; + + // Annunciation data + if (GETB(p_param->flags, CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_WARN)) + { + // If Patient High/Low Alert is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_PAT_HIGH_LOW_ALERT_SUP)) + { + SETB(p_param->warn, CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_PAT, 0); + SETB(p_param->warn, CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_PAT, 0); + } + + // If Hypo Alert is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_HYPO_ALERT_SUP)) + { + SETB(p_param->warn, CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_HYPO, 0); + } + + // If Hyper Alert is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_HYPER_ALERT_SUP)) + { + SETB(p_param->warn, CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_HYPER, 0); + } + + // If Rate of Increase/Decrease Alert is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_RATE_OF_INCR_DECR_ALERT_SUP)) + { + SETB(p_param->warn, CGM_MEAS_ANNUNC_WARN_SENSOR_RATE_INCR, 0); + SETB(p_param->warn, CGM_MEAS_ANNUNC_WARN_SENSOR_RATE_DECR, 0); + } + + // If Sensor Result High-Low Detection is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_SENSOR_RESULT_HIGH_LOW_DETECT_SUP)) + { + SETB(p_param->warn, CGM_MEAS_ANNUNC_WARN_SENSOR_RES_LOWER_DEV, 0); + SETB(p_param->warn, CGM_MEAS_ANNUNC_WARN_SENSOR_RES_HIGHER_DEV, 0); + } + + *p_data = p_param->warn; + p_data += 1; + } + + if (GETB(p_param->flags, CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_CAL_TEMP)) + { + // If Calibration is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_CALIB_SUP)) + { + SETB(p_param->cal_temp, CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_NOT_ALLOWED, 0); + SETB(p_param->cal_temp, CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_RECMD, 0); + SETB(p_param->cal_temp, CGM_MEAS_ANNUNC_CAL_TEMP_CALIB_REQ, 0); + } + + // If Sensor Temperature High-Low Detection is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_SENSOR_TEMP_HIGH_LOW_DETECT_SUP)) + { + SETB(p_param->cal_temp, CGM_MEAS_ANNUNC_CAL_TEMP_SENSOR_TEMP_HIGH, 0); + SETB(p_param->cal_temp, CGM_MEAS_ANNUNC_CAL_TEMP_SENSOR_TEMP_LOW, 0); + } + + *p_data = p_param->cal_temp; + p_data += 1; + } + + if (GETB(p_param->flags, CGM_MEAS_FLAGS_SENSOR_STATUS_ANNUNC_STATUS)) + { + // If Device Specific Alert is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_DEV_SPEC_ALERT_SUP)) + { + SETB(p_param->status, CGM_MEAS_ANNUNC_STATUS_DEV_SPEC_ALERT, 0); + } + + // If Sensor Malfunction Detection is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_SENSOR_MALFUNC_DETEC_SUP)) + { + SETB(p_param->status, CGM_MEAS_ANNUNC_STATUS_SENSOR_MALFUNC, 0); + } + + // If Low Battery Detection is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_LOW_BATT_DETECT_SUP)) + { + SETB(p_param->status, CGM_MEAS_ANNUNC_STATUS_DEV_BATT_LOW, 0); + } + + // If Sensor Type Error Detection is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_SENSOR_TYPE_ERR_DETECT_SUP)) + { + SETB(p_param->status, CGM_MEAS_ANNUNC_STATUS_SENSOR_TYPE_INCOR, 0); + } + + // If General Device Fault is not supported, + // corresponding bit in Sensor Status Annunciation shall be set to 0 + if (!GETB(p_cgms_env->cgm_feature, CGM_FEAT_GENERAL_DEV_FAULT_SUP)) + { + SETB(p_param->status, CGM_MEAS_ANNUNC_STATUS_GEN_DEV_FAULT, 0); + } + + *p_data = p_param->status; + p_data += 1; + } + + // Trend data + if (GETB(p_param->flags, CGM_MEAS_FLAGS_CGM_TREND_INFO)) + { + co_write16p(p_data, p_param->trend_info); + p_data += 2; + } + + // Quality data + if (GETB(p_param->flags, CGM_MEAS_FLAGS_CGM_QUALITY)) + { + co_write16p(p_data, p_param->quality); + p_data += 2; + } + + // E2E-CRC + if (GETB(p_cgms_env->cgm_feature, CGM_FEAT_E2E_CRC_SUP)) + { + uint16_t crc = prf_e2e_crc(&p_ind->value[0], length-CGMP_CRC_LEN); + + co_write16p(p_data, crc); + } + + // Send notification to peer device + ke_msg_send(p_ind); + + // Go to busy state + ke_state_set(dest_id, CGMS_OP_NOTIFY); + } + else + { + status = PRF_ERR_NTF_DISABLED; + } + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + // In error case immediately send response to HL + if (status != ATT_ERR_NO_ERROR) + { + // Send a command complete to the App with error status indicate msg could not be sent. + struct cgms_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(CGMS_CMP_EVT, + src_id, + dest_id, cgms_cmp_evt); + + p_cmp_evt->operation = p_param->operation; + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + } + } + // Else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see CGMS_RACP_RESP_CMD message. + * Send MEASUREMENT INDICATION to the connected peer case if CCC enabled + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cgms_racp_resp_cmd_handler(ke_msg_id_t const msgid, + struct cgms_racp_resp_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + + if(ke_state_get(dest_id) == CGMS_IDLE) + { + // Connection index + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t status = ATT_ERR_NO_ERROR; + + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + + // Do we have active procedure + // Check the RACP procedure is ongoing + if (GETB(p_cgms_env->prfl_state[conidx], CGMS_RACP_IN_PROG)) + { + switch (p_param->operation) + { + case CGMS_RACP_CMD_OP_CODE: + { + // Check the CCC is enabled + if (GETB(p_cgms_env->prfl_state[conidx], CGMS_IND_RACP_ENABLED)) + { + // Procedure complete + SETB(p_cgms_env->prfl_state[conidx], CGMS_RACP_IN_PROG, 0); + cgms_racp_resp_send( + KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + p_param->cp_opcode, + p_param->req_cp_opcode, + p_param->rsp_code, + p_param->records_num); + + // Go to busy state + ke_state_set(dest_id, CGMS_OP_INDICATE_RACP); + } + else + { + status = PRF_ERR_IND_DISABLED; + } + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + } + else + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // In error case immediately send response to HL + if (status != ATT_ERR_NO_ERROR) + { + // Send a command complete to the App with error indicating why msg could not be sent. + struct cgms_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(CGMS_CMP_EVT, + src_id, + dest_id, cgms_cmp_evt); + + p_cmp_evt->operation = p_param->operation; + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + } + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(cgms) +{ + {CGMS_ENABLE_REQ, (ke_msg_func_t) cgms_enable_req_handler}, + {CGMS_MEAS_VALUE_CMD, (ke_msg_func_t) cgms_meas_value_cmd_handler}, + {CGMS_RACP_RESP_CMD, (ke_msg_func_t) cgms_racp_resp_cmd_handler}, + {CGMS_RD_CHAR_CFM, (ke_msg_func_t) cgms_rd_char_cfm_handler}, + {CGMS_WR_OPS_CTRL_PT_CFM, (ke_msg_func_t) cgms_wr_ops_ctrl_pt_cfm_handler}, + + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ +void cgms_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct cgms_env_tag *p_cgms_env = PRF_ENV_GET(CGMS, cgms); + + p_task_desc->msg_handler_tab = cgms_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(cgms_msg_handler_tab); + p_task_desc->state = p_cgms_env->state; + p_task_desc->idx_max = CGMS_IDX_MAX; +} + +#endif //(BLE_CGM_SERVER) + +/// @} CGMSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpp_common.h new file mode 100644 index 0000000..53fc9d7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpp_common.h @@ -0,0 +1,587 @@ +/** + **************************************************************************************** + * + * @file cpp_common.h + * + * @brief Header File - Cycling Power Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +#ifndef _CPP_COMMON_H_ +#define _CPP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup CPP Cycling Power Profile + * @ingroup PROFILE + * @brief Cycling Power Profile + * + * The Cycling Power Profile is used to enable a collector device in order to obtain + * data from a Cycling Power Sensor (CP Sensor) that exposes the Cycling Power Service + * in sports and fitness applications. + * + * This file contains all definitions that are common for the server and the client parts + * of the profile. + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include "prf_types.h" +#include +#include "co_math.h" + +/* + * DEFINES + **************************************************************************************** + */ +/// Procedure Already in Progress Error Code +#define CPP_ERROR_PROC_IN_PROGRESS (0xFE) + +/// CP Measurement Notification Value Max Length +#define CPP_CP_MEAS_NTF_MAX_LEN (35) +/// CP Measurement Value Min Length +#define CPP_CP_MEAS_NTF_MIN_LEN (4) + +/// ADV Header size +#define CPP_CP_ADV_HEADER_LEN (3) +/// ADV Length size +#define CPP_CP_ADV_LENGTH_LEN (1) + +/// CP Measurement Advertisement Value Max Length +#define CPP_CP_MEAS_ADV_MAX_LEN (CPP_CP_MEAS_NTF_MAX_LEN + CPP_CP_ADV_HEADER_LEN) +/// CP Measurement Value Min Length +#define CPP_CP_MEAS_ADV_MIN_LEN (CPP_CP_MEAS_NTF_MIN_LEN + CPP_CP_ADV_HEADER_LEN) + +/// CP Vector Value Max Length +#define CPP_CP_VECTOR_MAX_LEN (19) +/// CP Vector Value Min Length +#define CPP_CP_VECTOR_MIN_LEN (1) + +/// CP Control Point Value Max Length +#define CPP_CP_CNTL_PT_REQ_MAX_LEN (9) +/// CP Control Point Value Min Length +#define CPP_CP_CNTL_PT_REQ_MIN_LEN (1) + +/// CP Control Point Value Max Length +#define CPP_CP_CNTL_PT_RSP_MAX_LEN (20) +/// CP Control Point Value Min Length +#define CPP_CP_CNTL_PT_RSP_MIN_LEN (3) + +/// CPP Measurement all supported +#define CPP_MEAS_ALL_SUPP (0x1FFF) + +/// CPP Feature all supported +#define CPP_FEAT_ALL_SUPP (0x0007FFFF) + +/// CPP Vector all supported +#define CPP_VECTOR_ALL_SUPP (0x3F) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// CPP Service Characteristics +enum cpp_cpps_char +{ + /// CPP Measurement + CPP_CPS_MEAS_CHAR, + /// CPP Feature + CPP_CPS_FEAT_CHAR, + /// Sensor Location + CPP_CPS_SENSOR_LOC_CHAR, + ///Cycling Power Vector + CPP_CPS_VECTOR_CHAR, + /// CP Control Point + CPP_CPS_CTNL_PT_CHAR, + + CPP_CPS_CHAR_MAX, +}; + +/// CPP Measurement Flags bit field +enum cpp_meas_flags_bf +{ + /// Pedal Power Balance Present + CPP_MEAS_PEDAL_POWER_BALANCE_PRESENT_POS = 0, + CPP_MEAS_PEDAL_POWER_BALANCE_PRESENT_BIT = CO_BIT(CPP_MEAS_PEDAL_POWER_BALANCE_PRESENT_POS), + + /// Pedal Power Balance Reference + CPP_MEAS_PEDAL_POWER_BALANCE_REFERENCE_POS = 1, + CPP_MEAS_PEDAL_POWER_BALANCE_REFERENCE_BIT = CO_BIT(CPP_MEAS_PEDAL_POWER_BALANCE_REFERENCE_POS), + + /// Accumulated Torque Present + CPP_MEAS_ACCUM_TORQUE_PRESENT_POS = 2, + CPP_MEAS_ACCUM_TORQUE_PRESENT_BIT = CO_BIT(CPP_MEAS_ACCUM_TORQUE_PRESENT_POS), + + /// Accumulated Torque Source + CPP_MEAS_ACCUM_TORQUE_SOURCE_POS = 3, + CPP_MEAS_ACCUM_TORQUE_SOURCE_BIT = CO_BIT(CPP_MEAS_ACCUM_TORQUE_SOURCE_POS), + + /// Wheel Revolution Data Present + CPP_MEAS_WHEEL_REV_DATA_PRESENT_POS = 4, + CPP_MEAS_WHEEL_REV_DATA_PRESENT_BIT = CO_BIT(CPP_MEAS_WHEEL_REV_DATA_PRESENT_POS), + + /// Crank Revolution Data Present + CPP_MEAS_CRANK_REV_DATA_PRESENT_POS = 5, + CPP_MEAS_CRANK_REV_DATA_PRESENT_BIT = CO_BIT(CPP_MEAS_CRANK_REV_DATA_PRESENT_POS), + + /// Extreme Force Magnitudes Present + CPP_MEAS_EXTREME_FORCE_MAGNITUDES_PRESENT_POS = 6, + CPP_MEAS_EXTREME_FORCE_MAGNITUDES_PRESENT_BIT = CO_BIT(CPP_MEAS_EXTREME_FORCE_MAGNITUDES_PRESENT_POS), + + /// Extreme Torque Magnitudes Present + CPP_MEAS_EXTREME_TORQUE_MAGNITUDES_PRESENT_POS = 7, + CPP_MEAS_EXTREME_TORQUE_MAGNITUDES_PRESENT_BIT = CO_BIT(CPP_MEAS_EXTREME_TORQUE_MAGNITUDES_PRESENT_POS), + + /// Extreme Angles Present + CPP_MEAS_EXTREME_ANGLES_PRESENT_POS = 8, + CPP_MEAS_EXTREME_ANGLES_PRESENT_BIT = CO_BIT(CPP_MEAS_EXTREME_ANGLES_PRESENT_POS), + + /// Top Dead Spot Angle Present + CPP_MEAS_TOP_DEAD_SPOT_ANGLE_PRESENT_POS = 9, + CPP_MEAS_TOP_DEAD_SPOT_ANGLE_PRESENT_BIT = CO_BIT(CPP_MEAS_TOP_DEAD_SPOT_ANGLE_PRESENT_POS), + + /// Bottom Dead Spot Angle Present + CPP_MEAS_BOTTOM_DEAD_SPOT_ANGLE_PRESENT_POS = 10, + CPP_MEAS_BOTTOM_DEAD_SPOT_ANGLE_PRESENT_BIT = CO_BIT(CPP_MEAS_BOTTOM_DEAD_SPOT_ANGLE_PRESENT_POS), + + /// Accumulated Energy Present + CPP_MEAS_ACCUM_ENERGY_PRESENT_POS = 11, + CPP_MEAS_ACCUM_ENERGY_PRESENT_BIT = CO_BIT(CPP_MEAS_ACCUM_ENERGY_PRESENT_POS), + + /// Offset Compensation Indicator + CPP_MEAS_OFFSET_COMPENSATION_INDICATOR_POS = 12, + CPP_MEAS_OFFSET_COMPENSATION_INDICATOR_BIT = CO_BIT(CPP_MEAS_OFFSET_COMPENSATION_INDICATOR_POS), + + // bit 13 - 15 RFU +}; + +/// CPP Feature Flags bit field +enum cpp_feat_flags_bf +{ + /// Pedal Power Balance Supported + CPP_FEAT_PEDAL_POWER_BALANCE_SUP_POS = 0, + CPP_FEAT_PEDAL_POWER_BALANCE_SUP_BIT = CO_BIT(CPP_FEAT_PEDAL_POWER_BALANCE_SUP_POS), + + /// Accumulated Torque Supported + CPP_FEAT_ACCUM_TORQUE_SUP_POS = 1, + CPP_FEAT_ACCUM_TORQUE_SUP_BIT = CO_BIT(CPP_FEAT_ACCUM_TORQUE_SUP_POS), + + /// Wheel Revolution Data Supported + CPP_FEAT_WHEEL_REV_DATA_SUP_POS = 2, + CPP_FEAT_WHEEL_REV_DATA_SUP_BIT = CO_BIT(CPP_FEAT_WHEEL_REV_DATA_SUP_POS), + + /// Crank Revolution Data Supported + CPP_FEAT_CRANK_REV_DATA_SUP_POS = 3, + CPP_FEAT_CRANK_REV_DATA_SUP_BIT = CO_BIT(CPP_FEAT_CRANK_REV_DATA_SUP_POS), + + /// Extreme Magnitudes Supported + CPP_FEAT_EXTREME_MAGNITUDES_SUP_POS = 4, + CPP_FEAT_EXTREME_MAGNITUDES_SUP_BIT = CO_BIT(CPP_FEAT_EXTREME_MAGNITUDES_SUP_POS), + + /// Extreme Angles Supported + CPP_FEAT_EXTREME_ANGLES_SUP_POS = 5, + CPP_FEAT_EXTREME_ANGLES_SUP_BIT = CO_BIT(CPP_FEAT_EXTREME_ANGLES_SUP_POS), + + /// Top and Bottom Dead Spot Angles Supported + CPP_FEAT_TOPBOT_DEAD_SPOT_ANGLES_SUP_POS = 6, + CPP_FEAT_TOPBOT_DEAD_SPOT_ANGLES_SUP_BIT = CO_BIT(CPP_FEAT_TOPBOT_DEAD_SPOT_ANGLES_SUP_POS), + + /// Accumulated Energy Supported + CPP_FEAT_ACCUM_ENERGY_SUP_POS = 7, + CPP_FEAT_ACCUM_ENERGY_SUP_BIT = CO_BIT(CPP_FEAT_ACCUM_ENERGY_SUP_POS), + + /// Offset Compensation Indicator Supported + CPP_FEAT_OFFSET_COMP_IND_SUP_POS = 8, + CPP_FEAT_OFFSET_COMP_IND_SUP_BIT = CO_BIT(CPP_FEAT_OFFSET_COMP_IND_SUP_POS), + + /// Offset Compensation Supported + CPP_FEAT_OFFSET_COMP_SUP_POS = 9, + CPP_FEAT_OFFSET_COMP_SUP_BIT = CO_BIT(CPP_FEAT_OFFSET_COMP_SUP_POS), + + /// CP Measurement CH Content Masking Supported + CPP_FEAT_CP_MEAS_CH_CONTENT_MASKING_SUP_POS = 10, + CPP_FEAT_CP_MEAS_CH_CONTENT_MASKING_SUP_BIT = CO_BIT(CPP_FEAT_CP_MEAS_CH_CONTENT_MASKING_SUP_POS), + + /// Multiple Sensor Locations Supported + CPP_FEAT_MULT_SENSOR_LOC_SUP_POS = 11, + CPP_FEAT_MULT_SENSOR_LOC_SUP_BIT = CO_BIT(CPP_FEAT_MULT_SENSOR_LOC_SUP_POS), + + /// Crank Length Adjustment Supported + CPP_FEAT_CRANK_LENGTH_ADJ_SUP_POS = 12, + CPP_FEAT_CRANK_LENGTH_ADJ_SUP_BIT = CO_BIT(CPP_FEAT_CRANK_LENGTH_ADJ_SUP_POS), + + /// Chain Length Adjustment Supported + CPP_FEAT_CHAIN_LENGTH_ADJ_SUP_POS = 13, + CPP_FEAT_CHAIN_LENGTH_ADJ_SUP_BIT = CO_BIT(CPP_FEAT_CHAIN_LENGTH_ADJ_SUP_POS), + + /// Chain Weight Adjustment Supported + CPP_FEAT_CHAIN_WEIGHT_ADJ_SUP_POS = 14, + CPP_FEAT_CHAIN_WEIGHT_ADJ_SUP_BIT = CO_BIT(CPP_FEAT_CHAIN_WEIGHT_ADJ_SUP_POS), + + /// Span Length Adjustment Supported + CPP_FEAT_SPAN_LENGTH_ADJ_SUP_POS = 15, + CPP_FEAT_SPAN_LENGTH_ADJ_SUP_BIT = CO_BIT(CPP_FEAT_SPAN_LENGTH_ADJ_SUP_POS), + + /// Sensor Measurement Context + CPP_FEAT_SENSOR_MEAS_CONTEXT_POS = 16, + CPP_FEAT_SENSOR_MEAS_CONTEXT_BIT = CO_BIT(CPP_FEAT_SENSOR_MEAS_CONTEXT_POS), + + /// Instantaneous Measurement Direction Supported + CPP_FEAT_INSTANT_MEAS_DIRECTION_SUP_POS = 17, + CPP_FEAT_INSTANT_MEAS_DIRECTION_SUP_BIT = CO_BIT(CPP_FEAT_INSTANT_MEAS_DIRECTION_SUP_POS), + + /// Factory Calibration Date Supported + CPP_FEAT_FACTORY_CALIBRATION_DATE_SUP_POS = 18, + CPP_FEAT_FACTORY_CALIBRATION_DATE_SUP_BIT = CO_BIT(CPP_FEAT_FACTORY_CALIBRATION_DATE_SUP_POS), + + /// Enhanced Offset Compensation Supported + CPP_FEAT_ENHANCED_OFFSET_COMPENS_SUP_POS = 19, + CPP_FEAT_ENHANCED_OFFSET_COMPENS_SUP_BIT = CO_BIT(CPP_FEAT_ENHANCED_OFFSET_COMPENS_SUP_POS), + + /// Distribute System Supported LSB + CPP_FEAT_FACTORY_CALIBRATION_DATE_SUP_LSB_POS = 20, + CPP_FEAT_FACTORY_CALIBRATION_DATE_SUP_LSB_BIT = CO_BIT(CPP_FEAT_FACTORY_CALIBRATION_DATE_SUP_LSB_POS), + + /// Distribute System Supported MSB + CPP_FEAT_FACTORY_CALIBRATION_DATE_SUP_MSB_POS = 21, + CPP_FEAT_FACTORY_CALIBRATION_DATE_SUP_MSB_BIT = CO_BIT(CPP_FEAT_FACTORY_CALIBRATION_DATE_SUP_MSB_POS), + + // bit 22 - 31 RFU +}; + +/// CPP Sensor Locations Keys +enum cpp_sensor_loc +{ + /// Other (0) + CPP_LOC_OTHER = 0, + /// Top of shoe (1) + CPP_LOC_TOP_SHOE, + /// In shoe (2) + CPP_LOC_IN_SHOE, + /// Hip (3) + CPP_LOC_HIP, + /// Front Wheel (4) + CPP_LOC_FRONT_WHEEL, + /// Left Crank (5) + CPP_LOC_LEFT_CRANK, + /// Right Crank (6) + CPP_LOC_RIGHT_CRANK, + /// Left Pedal (7) + CPP_LOC_LEFT_PEDAL, + /// Right Pedal (8) + CPP_LOC_RIGHT_PEDAL, + /// Front Hub (9) + CPP_LOC_FRONT_HUB, + /// Rear Dropout (10) + CPP_LOC_REAR_DROPOUT, + /// Chainstay (11) + CPP_LOC_CHAINSTAY, + /// Rear Wheel (12) + CPP_LOC_REAR_WHEEL, + /// Rear Hub (13) + CPP_LOC_REAR_HUB, + /// Chest (14) + CPP_LOC_CHEST, + + CPP_LOC_MAX, +}; + +/// CPP Vector Flags bit field +enum cpp_vector_flags_bf +{ + /// Crank Revolution Data Present + CPP_VECTOR_CRANK_REV_DATA_PRESENT_POS = 0, + CPP_VECTOR_CRANK_REV_DATA_PRESENT_BIT = CO_BIT(CPP_VECTOR_CRANK_REV_DATA_PRESENT_POS), + + /// First Crank Measurement Angle Present + CPP_VECTOR_FIRST_CRANK_MEAS_ANGLE_PRESENT_POS = 1, + CPP_VECTOR_FIRST_CRANK_MEAS_ANGLE_PRESENT_BIT = CO_BIT(CPP_VECTOR_FIRST_CRANK_MEAS_ANGLE_PRESENT_POS), + + /// Instantaneous Force Magnitude Array Present + CPP_VECTOR_INST_FORCE_MAGNITUDE_ARRAY_PRESENT_POS = 2, + CPP_VECTOR_INST_FORCE_MAGNITUDE_ARRAY_PRESENT_BIT = CO_BIT(CPP_VECTOR_INST_FORCE_MAGNITUDE_ARRAY_PRESENT_POS), + + /// Instantaneous Torque Magnitude Array Present + CPP_VECTOR_INST_TORQUE_MAGNITUDE_ARRAY_PRESENT_POS = 3, + CPP_VECTOR_INST_TORQUE_MAGNITUDE_ARRAY_PRESENT_BIT = CO_BIT(CPP_VECTOR_INST_TORQUE_MAGNITUDE_ARRAY_PRESENT_POS), + + /// Instantaneous Measurement Direction LSB + CPP_VECTOR_INST_MEAS_DIRECTION_LSB_POS = 4, + CPP_VECTOR_INST_MEAS_DIRECTION_LSB_BIT = CO_BIT(CPP_VECTOR_INST_MEAS_DIRECTION_LSB_POS), + + /// Instantaneous Measurement Direction MSB + CPP_VECTOR_INST_MEAS_DIRECTION_MSB_POS = 5, + CPP_VECTOR_INST_MEAS_DIRECTION_MSB_BIT = CO_BIT(CPP_VECTOR_INST_MEAS_DIRECTION_MSB_POS), + + // bit 6 - 7 RFU +}; + +/// CPP Control Point Code Keys +enum cpp_ctnl_pt_code +{ + /// Reserved value + CPP_CTNL_PT_RESERVED = 0, + + /// Set Cumulative Value + CPP_CTNL_PT_SET_CUMUL_VAL = 1, + /// Update Sensor Location + CPP_CTNL_PT_UPD_SENSOR_LOC = 2, + /// Request Supported Sensor Locations + CPP_CTNL_PT_REQ_SUPP_SENSOR_LOC = 3, + /// Set Crank Length + CPP_CTNL_PT_SET_CRANK_LENGTH = 4, + /// Request Crank Length + CPP_CTNL_PT_REQ_CRANK_LENGTH = 5, + /// Set Chain Length + CPP_CTNL_PT_SET_CHAIN_LENGTH = 6, + /// Request Chain Length + CPP_CTNL_PT_REQ_CHAIN_LENGTH = 7, + /// Set Chain Weight + CPP_CTNL_PT_SET_CHAIN_WEIGHT = 8, + /// Request Chain Weight + CPP_CTNL_PT_REQ_CHAIN_WEIGHT = 9, + /// Set Span Length + CPP_CTNL_PT_SET_SPAN_LENGTH = 10, + /// Request Span Length + CPP_CTNL_PT_REQ_SPAN_LENGTH = 11, + /// Start Offset Compensation + CPP_CTNL_PT_START_OFFSET_COMP = 12, + /// Mask CP Measurement Characteristic Content + CPP_CTNL_MASK_CP_MEAS_CH_CONTENT = 13, + /// Request Sampling Rate + CPP_CTNL_REQ_SAMPLING_RATE = 14, + /// Request Factory Calibration Date + CPP_CTNL_REQ_FACTORY_CALIBRATION_DATE = 15, + /// Start Enhanced Offset Compensation + CPP_CTNL_START_ENHANCED_OFFSET_COMP = 16, + + // Value 17 - 31 RFU + + /// Response Code + CPP_CTNL_PT_RSP_CODE = 32, + + // Value 33 - 255 RFU +}; + +/// CPP Control Point Response Value +enum cpp_ctnl_pt_resp_val +{ + /// Reserved value + CPP_CTNL_PT_RESP_RESERVED = 0, + + /// Success + CPP_CTNL_PT_RESP_SUCCESS, + /// Operation Code Not Supported + CPP_CTNL_PT_RESP_NOT_SUPP, + /// Invalid Parameter + CPP_CTNL_PT_RESP_INV_PARAM, + /// Operation Failed + CPP_CTNL_PT_RESP_FAILED, +}; + +/// CPP Control Point Error Response Parameter +enum cpp_ctnl_pt_err_resp_param +{ + /// Reserved value + CPP_CTNL_PT_ERR_RSP_PARAM_RESERVED = 0x00, + + /// Incorrect calibration position + CPP_CTNL_PT_ERR_RSP_PARAM_INCORRECT_CALIB_POS = 0x01, + + // Value 0x02 - 0xFE RFU + + /// Manufacturer specific error follows + CPP_CTNL_PT_ERR_RSP_PARAM_MANUF_SPEC_ERR_FOLLOWS = 0xFF, + +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// CP Measurement +struct cpp_cp_meas +{ + /// Flags + uint16_t flags; + /// Instantaneous Power + int16_t inst_power; + /// Pedal Power Balance + uint8_t pedal_power_balance; + /// Accumulated torque + uint16_t accum_torque; + /// Cumulative Wheel Revolutions + int16_t cumul_wheel_rev; + /// Last Wheel Event Time + uint16_t last_wheel_evt_time; + /// Cumulative Crank Revolution + uint16_t cumul_crank_rev; + /// Last Crank Event Time + uint16_t last_crank_evt_time; + /// Maximum Force Magnitude + int16_t max_force_magnitude; + /// Minimum Force Magnitude + int16_t min_force_magnitude; + /// Maximum Torque Magnitude + int16_t max_torque_magnitude; + /// Minimum Torque Magnitude + int16_t min_torque_magnitude; + /// Maximum Angle (12 bits) + uint16_t max_angle; + /// Minimum Angle (12bits) + uint16_t min_angle; + /// Top Dead Spot Angle + uint16_t top_dead_spot_angle; + /// Bottom Dead Spot Angle + uint16_t bot_dead_spot_angle; + ///Accumulated energy + uint16_t accum_energy; +}; + +/// CP Measurement +struct cpp_cp_meas_ind +{ + /// Flags + uint16_t flags; + /// Instantaneous Power + int16_t inst_power; + /// Pedal Power Balance + uint8_t pedal_power_balance; + /// Accumulated torque + uint16_t accum_torque; + /// Cumulative Wheel Revolutions + uint32_t cumul_wheel_rev; + /// Last Wheel Event Time + uint16_t last_wheel_evt_time; + /// Cumulative Crank Revolution + uint16_t cumul_crank_rev; + /// Last Crank Event Time + uint16_t last_crank_evt_time; + /// Maximum Force Magnitude + int16_t max_force_magnitude; + /// Minimum Force Magnitude + int16_t min_force_magnitude; + /// Maximum Torque Magnitude + int16_t max_torque_magnitude; + /// Minimum Torque Magnitude + int16_t min_torque_magnitude; + /// Maximum Angle (12 bits) + uint16_t max_angle; + /// Minimum Angle (12bits) + uint16_t min_angle; + /// Top Dead Spot Angle + uint16_t top_dead_spot_angle; + /// Bottom Dead Spot Angle + uint16_t bot_dead_spot_angle; + /// Accumulated energy + uint16_t accum_energy; + +}; + +/// Enhanced Offset Compensation +struct cpp_enhanced_offset_comp +{ + /// Offset + int16_t comp_offset; + /// Manufacturer Company ID + uint16_t manu_comp_id; + /// Response Parameter (error condition) + uint8_t rsp_param; + /// Manufacturer specific data length + uint8_t length; + /// Manufacturer specific data + uint8_t data[__ARRAY_EMPTY]; +}; + +/// CP Vector +struct cpp_cp_vector +{ + /// Flags + uint8_t flags; + /// Force-Torque Magnitude Array Length + uint8_t nb; + /// Cumulative Crank Revolutions + uint16_t cumul_crank_rev; + /// Last Crank Event Time + uint16_t last_crank_evt_time; + /// First Crank Measurement Angle + uint16_t first_crank_meas_angle; + /// Mutually excluded Force and Torque Magnitude Arrays + int16_t force_torque_magnitude[__ARRAY_EMPTY]; +}; + +/// CP Control Point Request +struct cpp_ctnl_pt_req +{ + /// Operation Code + uint8_t op_code; + /// Value + union cpp_ctnl_pt_req_val + { + /// Cumulative Value + uint32_t cumul_val; + /// Sensor Location + uint8_t sensor_loc; + /// Crank Length + uint16_t crank_length; + /// Chain Length + uint16_t chain_length; + /// Chain Weight + uint16_t chain_weight; + /// Span Length + uint16_t span_length; + /// Mask Content + uint16_t mask_content; + } value; +}; + +/// CP Control Point Response +struct cpp_ctnl_pt_rsp +{ + /// Operation code - Response Code (0x20) + uint8_t op_code; + /// Requested Operation Code + uint8_t req_op_code; + /// Response Value + uint8_t resp_value; + + ///Value + union cpp_ctnl_pt_rsp_val + { + /// List of supported locations + uint32_t supp_loc; + /// Crank Length + uint16_t crank_length; + /// Chain Length + uint16_t chain_length; + /// Chain Weight + uint16_t chain_weight; + /// Span Length + uint16_t span_length; + /// Start Offset Compensation + int16_t offset_comp; + /// Sampling Rate Procedure + uint8_t sampling_rate; + /// Enhanced Offset Compensation + struct cpp_enhanced_offset_comp enhanced_offset_comp; + /// Calibration date + struct prf_date_time factory_calibration; + } value; +}; + +/// @} cpp_common + +#endif //(_CPP_COMMON_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/api/cppc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/api/cppc_task.h new file mode 100644 index 0000000..5b43896 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/api/cppc_task.h @@ -0,0 +1,247 @@ +/** + **************************************************************************************** + * + * @file cppc_task.h + * + * @brief Header file - Cycling Power Profile Collector Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CPPC_TASK_H_ +#define _CPPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup CPPCTASK Cycling Power Profile Collector Task + * @ingroup CPPC + * @brief Cycling Power Profile Collector Task + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "cpp_common.h" + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Cycling Power Service Characteristic Descriptors +enum cppc_cps_descs +{ + /// CP Measurement Char. - Client Characteristic Configuration + CPPC_DESC_CP_MEAS_CL_CFG, + /// CP Measurement Char. - Server Characteristic Configuration + CPPC_DESC_CP_MEAS_SV_CFG, + /// CP Vector Char. - Client Characteristic Configuration + CPPC_DESC_VECTOR_CL_CFG, + /// Control Point Char. - Client Characteristic Configuration + CPPC_DESC_CTNL_PT_CL_CFG, + + CPPC_DESC_MAX, + + CPPC_DESC_MASK = 0x10, +}; + +/// Message IDs +/*@TRACE*/ +enum cppc_msg_ids +{ + /// Enable the Cycling Power Profile Collector task - at connection + CPPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_CPPC), + /// Confirm that cfg connection has finished with discovery results, or that normal cnx started + CPPC_ENABLE_RSP, + + /// Read the value of an attribute in the peer device database + CPPC_READ_CMD, + /// Configure sending of notification or indication + CPPC_CFG_NTFIND_CMD, + + /// Configure the Cycling Power Control Point value + CPPC_CTNL_PT_CFG_CMD, + /// Indicate that an control point response has been triggered by peer device + CPPC_CTNL_PT_IND, + + /// Indicate that an attribute value has been received either upon notification or read response + CPPC_VALUE_IND, + + /// Complete Event Information + CPPC_CMP_EVT, + + /// Procedure Timeout Timer + CPPC_TIMEOUT_TIMER_IND, +}; + +/// Operation Codes +enum cppc_op_code +{ + /// Reserved operation code + CPPC_RESERVED_OP_CODE = 0x00, + + /// Discovery Procedure + CPPC_ENABLE_OP_CODE, + /// Read attribute value Procedure + CPPC_READ_OP_CODE, + + /// Wait for the Write Response after having written a Client Char. Cfg. Descriptor. + CPPC_CFG_NTF_IND_OP_CODE, + + /// Wait for the Write Response after having written the Control Point Char. + CPPC_CTNL_PT_CFG_WR_OP_CODE, + /// Wait for the Indication Response after having written the Control Point Char. + CPPC_CTNL_PT_CFG_IND_OP_CODE, +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Cycling Power Service + */ +struct cppc_cps_content +{ + /// Service info + struct prf_svc svc; + + /// Characteristic info: + /// - CP Measurement + /// - CP Feature + /// - Sensor Location + /// - Vector + /// - SC Control Point + struct prf_char_inf chars[CPP_CPS_CHAR_MAX]; + + /// Descriptor handles: + /// - CP Measurement Client Cfg + /// - Vector Client Cfg + /// - Control Point Client Cfg + struct prf_char_desc_inf descs[CPPC_DESC_MAX]; +}; + +/// Parameters of the @ref CPPC_ENABLE_REQ message +struct cppc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values CPS + struct cppc_cps_content cps; +}; + +/// Parameters of the @ref CPPC_ENABLE_RSP message +struct cppc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values CPS + struct cppc_cps_content cps; +}; + +/// Parameters of the @ref CPPC_READ_CMD message +struct cpps_read_cmd +{ + /// Operation Code + uint8_t operation; + /// Read code + uint8_t read_code; +}; + +/// Parameters of the @ref CPPC_CFG_NTFIND_CMD message +struct cppc_cfg_ntfind_cmd +{ + /// Operation Code + uint8_t operation; + /// Descriptor code + uint8_t desc_code; + /// Ntf/Ind Configuration + uint16_t ntfind_cfg; +}; + +/// Parameters of the @ref CPPC_CTNL_PT_CFG_CMD message +struct cppc_ctnl_pt_cfg_cmd +{ + /// Operation Code + uint8_t operation; + /// CP Control Point Request + struct cpp_ctnl_pt_req ctnl_pt; +}; + +/// Parameters of the @ref CPPC_VALUE_IND message +struct cppc_value_ind +{ + /// Attribute Code + uint8_t att_code; + /// Value + union cppc_value_tag + { + /// CP Feature + uint32_t sensor_feat; + /// CP Measurement + struct cpp_cp_meas cp_meas; + /// Sensor Vector + struct cpp_cp_vector cp_vector; + /// Client Characteristic Configuration Descriptor Value + uint16_t ntf_cfg; + /// Sensor Location + uint8_t sensor_loc; + } value; +}; + +/// Parameters of the @ref CPPC_VALUE_IND message +struct cppc_value_meas_ind +{ + /// Attribute Code + uint8_t att_code; + /// Value + union cppc_value_tag2 + { + /// CP Feature + uint32_t sensor_feat; + /// CP Measurement + struct cpp_cp_meas_ind cp_meas; + /// Sensor Vector + struct cpp_cp_vector cp_vector; + /// Client Characteristic Configuration Descriptor Value + uint16_t ntf_cfg; + /// Sensor Location + uint8_t sensor_loc; + } value; +}; + +/// Parameters of the @ref CPPC_CTNL_PT_IND message +struct cppc_ctnl_pt_ind +{ + /// SC Control Point Response + struct cpp_ctnl_pt_rsp rsp; +}; + +/// Parameters of the @ref CPPC_CMP_EVT message +struct cppc_cmp_evt +{ + /// Operation code + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} CPPCTASK + +#endif //(_CPPC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/sourcelist.txt new file mode 100644 index 0000000..ff232aa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + cppc.c + cppc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/src/cppc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/src/cppc.c new file mode 100644 index 0000000..63b3d2a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/src/cppc.c @@ -0,0 +1,828 @@ +/** + **************************************************************************************** + * + * @file cppc.c + * + * @brief Cycling Power Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup CPPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_CP_COLLECTOR) + +#include "cpp_common.h" +#include "cppc.h" +#include "cppc_task.h" +#include "ke_timer.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLES DECLARATION + **************************************************************************************** + */ + + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the CPPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t cppc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct cppc_env_tag *p_cppc_env = + (struct cppc_env_tag *) ke_malloc(sizeof(struct cppc_env_tag), KE_MEM_ATT_DB); + + // allocate CPPC required environment variable + p_env->env = (prf_env_t *) p_cppc_env; + + p_cppc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_cppc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_CPPC; + cppc_task_init(&(p_env->desc)); + + for(idx = 0; idx < CPPC_IDX_MAX ; idx++) + { + p_cppc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), CPPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void cppc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct cppc_env_tag *p_cppc_env = (struct cppc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_cppc_env->p_env[conidx] != NULL) + { + if (p_cppc_env->p_env[conidx]->p_operation != NULL) + { + ke_free(ke_param2msg(p_cppc_env->p_env[conidx]->p_operation)); + } + + ke_timer_clear(CPPC_TIMEOUT_TIMER_IND, prf_src_task_get(&p_cppc_env->prf_env, conidx)); + ke_free(p_cppc_env->p_env[conidx]); + p_cppc_env->p_env[conidx] = NULL; + } + + // Put CPP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), CPPC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the CPPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void cppc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct cppc_env_tag *p_cppc_env = (struct cppc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < CPPC_IDX_MAX ; idx++) + { + cppc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_cppc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void cppc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put CPP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), CPPC_IDLE); +} + +/// CPPC Task interface required by profile manager +const struct prf_task_cbs cppc_itf = +{ + cppc_init, + cppc_destroy, + cppc_create, + cppc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *cppc_prf_itf_get(void) +{ + return &cppc_itf; +} + +void cppc_enable_rsp_send(struct cppc_env_tag *p_cppc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on CPPS + struct cppc_enable_rsp *p_rsp = KE_MSG_ALLOC( + CPPC_ENABLE_RSP, + prf_dst_task_get(&(p_cppc_env->prf_env), conidx), + prf_src_task_get(&(p_cppc_env->prf_env), conidx), + cppc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->cps = p_cppc_env->p_env[conidx]->cps; + // Register CPPC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_cppc_env->prf_env), conidx, &(p_cppc_env->p_env[conidx]->cps.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_cppc_env->prf_env), conidx), CPPC_IDLE); + } + + ke_msg_send(p_rsp); +} + + +void cppc_send_no_conn_cmp_evt(uint8_t src_id, uint8_t dest_id, uint8_t operation) +{ + // Send the message + struct cppc_cmp_evt *p_evt = KE_MSG_ALLOC(CPPC_CMP_EVT, + dest_id, src_id, + cppc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = PRF_ERR_REQ_DISALLOWED; + + ke_msg_send(p_evt); +} + +void cppc_send_cmp_evt(struct cppc_env_tag *p_cppc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct cppc_cmp_evt *p_evt; + + // Free the stored operation if needed + if (p_cppc_env->p_env[conidx]->p_operation != NULL) + { + ke_msg_free(ke_param2msg(p_cppc_env->p_env[conidx]->p_operation)); + p_cppc_env->p_env[conidx]->p_operation = NULL; + } + + // Go back to the IDLE state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_cppc_env->prf_env), conidx)) == CPPC_BUSY) + { + ke_state_set(prf_src_task_get(&p_cppc_env->prf_env, conidx), CPPC_IDLE); + } + + // Send the message + p_evt = KE_MSG_ALLOC(CPPC_CMP_EVT, + prf_dst_task_get(&(p_cppc_env->prf_env), conidx), + prf_src_task_get(&(p_cppc_env->prf_env), conidx), + cppc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +uint16_t cppc_get_read_handle_req (struct cppc_env_tag *p_cppc_env, uint8_t conidx, struct cpps_read_cmd *p_param) +{ + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + + switch (p_param->read_code) + { + // Read CP Feature + case (CPPC_RD_CP_FEAT): + { + handle = p_cppc_env->p_env[conidx]->cps.chars[CPP_CPS_FEAT_CHAR].val_hdl; + } break; + + // Read Sensor Location + case (CPPC_RD_SENSOR_LOC): + { + handle = p_cppc_env->p_env[conidx]->cps.chars[CPP_CPS_SENSOR_LOC_CHAR].val_hdl; + } break; + + // Read CP Measurement Characteristic Client Char. Cfg. Descriptor Value + case (CPPC_RD_WR_CP_MEAS_CL_CFG): + { + handle = p_cppc_env->p_env[conidx]->cps.descs[CPPC_DESC_CP_MEAS_CL_CFG].desc_hdl; + } break; + + // Read CP Measurement Characteristic Server Char. Cfg. Descriptor Value + case (CPPC_RD_WR_CP_MEAS_SV_CFG): + { + handle = p_cppc_env->p_env[conidx]->cps.descs[CPPC_DESC_CP_MEAS_SV_CFG].desc_hdl; + } break; + + // Read CP Vector Characteristic Server Char. Cfg. Descriptor Value + case (CPPC_RD_WR_VECTOR_CFG): + { + handle = p_cppc_env->p_env[conidx]->cps.descs[CPPC_DESC_VECTOR_CL_CFG].desc_hdl; + } break; + + // Read Unread Alert Characteristic Client Char. Cfg. Descriptor Value + case (CPPC_RD_WR_CTNL_PT_CFG): + { + handle = p_cppc_env->p_env[conidx]->cps.descs[CPPC_DESC_CTNL_PT_CL_CFG].desc_hdl; + } break; + + default: + { + handle = ATT_INVALID_SEARCH_HANDLE; + } break; + } + + return handle; +} + +uint8_t cppc_get_write_desc_handle_req (uint8_t conidx, struct cppc_cfg_ntfind_cmd *p_param, + struct cppc_env_tag *p_cppc_env, uint16_t *p_handle) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + switch (p_param->desc_code) + { + // Write CP Measurement Characteristic Client Char. Cfg. Descriptor Value + case (CPPC_RD_WR_CP_MEAS_CL_CFG): + { + if (p_param->ntfind_cfg <= PRF_CLI_START_NTF) + { + *p_handle = p_cppc_env->p_env[conidx]->cps.descs[CPPC_DESC_CP_MEAS_CL_CFG].desc_hdl; + + // The descriptor is mandatory + ASSERT_ERR(*p_handle != ATT_INVALID_SEARCH_HANDLE); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write CP Measurement Characteristic Server Char. Cfg. Descriptor Value + case (CPPC_RD_WR_CP_MEAS_SV_CFG): + { + if (p_param->ntfind_cfg <= PRF_SRV_START_BCST) + { + *p_handle = p_cppc_env->p_env[conidx]->cps.descs[CPPC_DESC_CP_MEAS_SV_CFG].desc_hdl; + + if (*p_handle == ATT_INVALID_SEARCH_HANDLE) + { + // The descriptor has not been found. + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write CP Vector Characteristic Client Char. Cfg. Descriptor Value + case (CPPC_RD_WR_VECTOR_CFG): + { + if (p_param->ntfind_cfg <= PRF_CLI_START_NTF) + { + *p_handle = p_cppc_env->p_env[conidx]->cps.descs[CPPC_DESC_VECTOR_CL_CFG].desc_hdl; + + if (*p_handle == ATT_INVALID_SEARCH_HANDLE) + { + // The descriptor has not been found. + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write CP Control Point Characteristic Client Char. Cfg. Descriptor Value + case (CPPC_RD_WR_CTNL_PT_CFG): + { + if ((p_param->ntfind_cfg == PRF_CLI_STOP_NTFIND) || + (p_param->ntfind_cfg == PRF_CLI_START_IND)) + { + *p_handle = p_cppc_env->p_env[conidx]->cps.descs[CPPC_DESC_CTNL_PT_CL_CFG].desc_hdl; + + if (*p_handle == ATT_INVALID_SEARCH_HANDLE) + { + // The descriptor has not been found. + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + return (status); +} + +uint8_t cppc_unpack_meas_ind (uint8_t conidx, struct gattc_event_ind const *p_param, struct cppc_env_tag *p_cppc_env) +{ + // CP Measurement value has been received + struct cppc_value_meas_ind *p_ind = KE_MSG_ALLOC( + CPPC_VALUE_IND, + prf_dst_task_get(&(p_cppc_env->prf_env), conidx), + prf_src_task_get(&(p_cppc_env->prf_env), conidx), + cppc_value_meas_ind); + + // Offset + uint8_t offset = CPP_CP_MEAS_NTF_MIN_LEN; + + // Attribute code + p_ind->att_code = CPPC_NTF_CP_MEAS; + + // Flags + p_ind->value.cp_meas.flags = co_read16p(&p_param->value[0]); + // Instant power + p_ind->value.cp_meas.inst_power = co_read16p(&p_param->value[2]); + + if (GETB(p_ind->value.cp_meas.flags, CPP_MEAS_PEDAL_POWER_BALANCE_PRESENT)) + { + // Unpack Pedal Power Balance info + p_ind->value.cp_meas.pedal_power_balance = p_param->value[offset]; + offset++; + } + + if (GETB(p_ind->value.cp_meas.flags, CPP_MEAS_ACCUM_TORQUE_PRESENT)) + { + // Unpack Accumulated Torque info + p_ind->value.cp_meas.accum_torque = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (GETB(p_ind->value.cp_meas.flags, CPP_MEAS_WHEEL_REV_DATA_PRESENT)) + { + // Unpack Wheel Revolution Data (Cumulative Wheel & Last Wheel Event Time) + p_ind->value.cp_meas.cumul_wheel_rev = co_read32p(&p_param->value[offset]); + offset += 4; + p_ind->value.cp_meas.last_wheel_evt_time = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (GETB(p_ind->value.cp_meas.flags, CPP_MEAS_CRANK_REV_DATA_PRESENT)) + { + // Unpack Crank Revolution Data (Cumulative Crank & Last Crank Event Time) + p_ind->value.cp_meas.cumul_crank_rev = co_read16p(&p_param->value[offset]); + offset += 2; + p_ind->value.cp_meas.last_crank_evt_time = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (GETB(p_ind->value.cp_meas.flags, CPP_MEAS_EXTREME_FORCE_MAGNITUDES_PRESENT)) + { + // Unpack Extreme Force Magnitudes (Maximum Force Magnitude & Minimum Force Magnitude) + p_ind->value.cp_meas.max_force_magnitude = co_read16p(&p_param->value[offset]); + offset += 2; + p_ind->value.cp_meas.min_force_magnitude = co_read16p(&p_param->value[offset]); + offset += 2; + } + + else if (GETB(p_ind->value.cp_meas.flags, CPP_MEAS_EXTREME_TORQUE_MAGNITUDES_PRESENT)) + { + // Unpack Extreme Force Magnitudes (Maximum Force Magnitude & Minimum Force Magnitude) + p_ind->value.cp_meas.max_torque_magnitude = co_read16p(&p_param->value[offset]); + offset += 2; + p_ind->value.cp_meas.min_torque_magnitude = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (GETB(p_ind->value.cp_meas.flags, CPP_MEAS_EXTREME_ANGLES_PRESENT)) + { + // Unpack Extreme Angles (Maximum Angle & Minimum Angle) + uint32_t angle = co_read24p(&p_param->value[offset]); + offset += 3; + + //Force to 12 bits + p_ind->value.cp_meas.max_angle = (angle & (0x0FFF)); + p_ind->value.cp_meas.min_angle = ((angle>>12) & 0x0FFF); + } + + if (GETB(p_ind->value.cp_meas.flags, CPP_MEAS_TOP_DEAD_SPOT_ANGLE_PRESENT)) + { + // Unpack Top Dead Spot Angle + p_ind->value.cp_meas.top_dead_spot_angle = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (GETB(p_ind->value.cp_meas.flags, CPP_MEAS_BOTTOM_DEAD_SPOT_ANGLE_PRESENT)) + { + // Unpack Bottom Dead Spot Angle + p_ind->value.cp_meas.bot_dead_spot_angle = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (GETB(p_ind->value.cp_meas.flags, CPP_MEAS_ACCUM_ENERGY_PRESENT)) + { + // Unpack Accumulated Energy + p_ind->value.cp_meas.accum_energy = co_read16p(&p_param->value[offset]); + offset += 2; + } + + // Send the message + ke_msg_send(p_ind); + + return offset; +} + +uint8_t cppc_unpack_vector_ind (uint8_t conidx, struct gattc_event_ind const *p_param, struct cppc_env_tag *p_cppc_env) +{ + // CP Measurement value has been received + struct cppc_value_ind *p_ind = KE_MSG_ALLOC_DYN( + CPPC_VALUE_IND, + prf_dst_task_get(&p_cppc_env->prf_env, conidx), + prf_src_task_get(&p_cppc_env->prf_env, conidx), + cppc_value_ind, + p_param->length); + + // Offset + uint8_t offset = CPP_CP_VECTOR_MIN_LEN; + + // Attribute code + p_ind->att_code = CPPC_NTF_CP_VECTOR; + + // Flags + p_ind->value.cp_vector.flags = p_param->value[0]; + + if (GETB(p_ind->value.cp_vector.flags, CPP_VECTOR_CRANK_REV_DATA_PRESENT)) + { + // Unpack Crank Revolution Data + p_ind->value.cp_vector.cumul_crank_rev = co_read16p(&p_param->value[offset]); + offset += 2; + // Unpack Last Crank Evt time + p_ind->value.cp_vector.last_crank_evt_time = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (GETB(p_ind->value.cp_vector.flags, CPP_VECTOR_FIRST_CRANK_MEAS_ANGLE_PRESENT)) + { + // Unpack First Crank Measurement Angle + p_ind->value.cp_vector.first_crank_meas_angle = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (!GETB(p_ind->value.cp_vector.flags, CPP_VECTOR_INST_FORCE_MAGNITUDE_ARRAY_PRESENT) != + !GETB(p_ind->value.cp_vector.flags, CPP_VECTOR_INST_TORQUE_MAGNITUDE_ARRAY_PRESENT)) + { + // Unpack Force or Torque magnitude (mutually excluded) + p_ind->value.cp_vector.nb = (p_param->length - offset)/2; + if (p_ind->value.cp_vector.nb) + { + for (int i = 0; i < p_ind->value.cp_vector.nb; i++) + { + // Handle the array buffer to extract parameters + p_ind->value.cp_vector.force_torque_magnitude[i] = co_read16p(&p_param->value[offset]); + offset += 2; + } + } + } + + // Send the message + ke_msg_send(p_ind); + + return offset; +} + +uint8_t cppc_pack_ctnl_pt_req (struct cppc_ctnl_pt_cfg_cmd *p_param, uint8_t *p_req, uint8_t *p_status) +{ + // Request Length + uint8_t req_len = CPP_CP_CNTL_PT_REQ_MIN_LEN; + + // Set the operation code + p_req[0] = p_param->ctnl_pt.op_code; + + // Fulfill the message according to the operation code + switch (p_param->ctnl_pt.op_code) + { + case (CPP_CTNL_PT_SET_CUMUL_VAL): + { + // Set the cumulative value + co_write32p(&p_req[req_len], p_param->ctnl_pt.value.cumul_val); + // Update length + req_len += 4; + } break; + + case (CPP_CTNL_PT_UPD_SENSOR_LOC): + { + // Set the sensor location + p_req[req_len] = p_param->ctnl_pt.value.sensor_loc; + // Update length + req_len++; + } break; + + case (CPP_CTNL_PT_SET_CRANK_LENGTH): + { + // Set the crank length + co_write16p(&p_req[req_len], p_param->ctnl_pt.value.crank_length); + // Update length + req_len += 2; + } break; + + case (CPP_CTNL_PT_SET_CHAIN_LENGTH): + { + // Set the chain length + co_write16p(&p_req[req_len], p_param->ctnl_pt.value.chain_length); + // Update length + req_len += 2; + } break; + + case (CPP_CTNL_PT_SET_CHAIN_WEIGHT): + { + // Set the chain weight + co_write16p(&p_req[req_len], p_param->ctnl_pt.value.chain_weight); + // Update length + req_len += 2; + } break; + + case (CPP_CTNL_PT_SET_SPAN_LENGTH): + { + // Set the span length + co_write16p(&p_req[req_len], p_param->ctnl_pt.value.span_length); + // Update length + req_len += 2; + } break; + + case (CPP_CTNL_MASK_CP_MEAS_CH_CONTENT): + { + // Set the Content Mask + co_write16p(&p_req[req_len], p_param->ctnl_pt.value.mask_content); + // Update length + req_len += 2; + } break; + + case (CPP_CTNL_PT_REQ_SUPP_SENSOR_LOC): + case (CPP_CTNL_PT_REQ_CRANK_LENGTH): + case (CPP_CTNL_PT_REQ_CHAIN_LENGTH): + case (CPP_CTNL_PT_REQ_CHAIN_WEIGHT): + case (CPP_CTNL_PT_REQ_SPAN_LENGTH): + case (CPP_CTNL_PT_START_OFFSET_COMP): + case (CPP_CTNL_REQ_SAMPLING_RATE): + case (CPP_CTNL_REQ_FACTORY_CALIBRATION_DATE): + case (CPP_CTNL_START_ENHANCED_OFFSET_COMP): + { + // Nothing more to do + } break; + + default: + { + *p_status = PRF_ERR_INVALID_PARAM; + } break; + } + + return req_len; +} + +uint8_t cppc_unpack_ctln_pt_ind (uint8_t conidx, struct gattc_event_ind const *p_param, + struct cppc_env_tag *p_cppc_env) +{ + // Offset + uint8_t offset = CPP_CP_CNTL_PT_RSP_MIN_LEN; + + // Control Point value has been received + struct cppc_ctnl_pt_ind *p_ind = KE_MSG_ALLOC( + CPPC_CTNL_PT_IND, + prf_dst_task_get(&p_cppc_env->prf_env, conidx), + prf_src_task_get(&p_cppc_env->prf_env, conidx), + cppc_ctnl_pt_ind); + + // Response Op code + p_ind->rsp.op_code = p_param->value[0]; + // Requested operation code + p_ind->rsp.req_op_code = p_param->value[1]; + // Response value + p_ind->rsp.resp_value = p_param->value[2]; + + if ((p_ind->rsp.resp_value == CPP_CTNL_PT_RESP_SUCCESS) && (p_param->length >= 3)) + { + switch (p_ind->rsp.req_op_code) + { + case (CPP_CTNL_PT_REQ_SUPP_SENSOR_LOC): + { + // Get the number of supported locations that have been received + uint8_t nb_supp_loc = (p_param->length - 3); + // Location + uint8_t loc; + + for (uint8_t counter = 0; counter < nb_supp_loc; counter++) + { + loc = p_param->value[counter + CPP_CP_CNTL_PT_RSP_MIN_LEN]; + // Check if valid + if (loc < CPP_LOC_MAX) + { + p_ind->rsp.value.supp_loc |= (1 << loc); + } + offset++; + } + } break; + + case (CPP_CTNL_PT_REQ_CRANK_LENGTH): + { + p_ind->rsp.value.crank_length = co_read16p(&p_param->value[offset]); + offset += 2; + } break; + + case (CPP_CTNL_PT_REQ_CHAIN_LENGTH): + { + p_ind->rsp.value.chain_length = co_read16p(&p_param->value[offset]); + offset += 2; + } break; + + case (CPP_CTNL_PT_REQ_CHAIN_WEIGHT): + { + p_ind->rsp.value.chain_weight = co_read16p(&p_param->value[offset]); + offset += 2; + } break; + + case (CPP_CTNL_PT_REQ_SPAN_LENGTH): + { + p_ind->rsp.value.span_length = co_read16p(&p_param->value[offset]); + offset += 2; + } break; + + case (CPP_CTNL_PT_START_OFFSET_COMP): + { + p_ind->rsp.value.offset_comp = co_read16p(&p_param->value[offset]); + offset += 2; + } break; + + case (CPP_CTNL_REQ_SAMPLING_RATE): + { + p_ind->rsp.value.sampling_rate = p_param->value[offset]; + offset++; + } break; + + case (CPP_CTNL_REQ_FACTORY_CALIBRATION_DATE): + { + offset += prf_unpack_date_time( + (uint8_t *) &(p_param->value[offset]), &(p_ind->rsp.value.factory_calibration)); + } break; + + case (CPP_CTNL_START_ENHANCED_OFFSET_COMP): + { + p_ind->rsp.value.enhanced_offset_comp.comp_offset = co_read16p(&p_param->value[offset]); + offset += 2; + + p_ind->rsp.value.enhanced_offset_comp.manu_comp_id = co_read16p(&p_param->value[offset]); + offset += 2; + + p_ind->rsp.value.enhanced_offset_comp.length = p_param->value[offset]; + offset++; + + if (p_ind->rsp.value.enhanced_offset_comp.length) + { + for (int i = 0; i < p_ind->rsp.value.enhanced_offset_comp.length; i++) + { + p_ind->rsp.value.enhanced_offset_comp.data[i] = p_param->value[offset]; + offset++; + } + } + + } break; + + case (CPP_CTNL_PT_SET_CUMUL_VAL): + case (CPP_CTNL_PT_UPD_SENSOR_LOC): + case (CPP_CTNL_PT_SET_CRANK_LENGTH): + case (CPP_CTNL_PT_SET_CHAIN_LENGTH): + case (CPP_CTNL_PT_SET_CHAIN_WEIGHT): + case (CPP_CTNL_PT_SET_SPAN_LENGTH): + case (CPP_CTNL_MASK_CP_MEAS_CH_CONTENT): + { + // No parameters + } break; + + default: + { + + } break; + } + } + // Response value is not success + else + { + // Start Enhanced Offset Compensation Op code + if (p_ind->rsp.req_op_code == CPP_CTNL_START_ENHANCED_OFFSET_COMP) + { + if (p_param->value[offset] == CPP_CTNL_PT_ERR_RSP_PARAM_INCORRECT_CALIB_POS) + { + // obtain response parameter + p_ind->rsp.value.enhanced_offset_comp.rsp_param = p_param->value[offset]; + offset++; + } + else if (p_param->value[offset] == CPP_CTNL_PT_ERR_RSP_PARAM_MANUF_SPEC_ERR_FOLLOWS) + { + // obtain response parameter + p_ind->rsp.value.enhanced_offset_comp.rsp_param = p_param->value[offset]; + offset++; + + // obtain manufacturer compensation id + p_ind->rsp.value.enhanced_offset_comp.manu_comp_id = co_read16p(&p_param->value[offset]); + offset += 2; + + // obtain data length + p_ind->rsp.value.enhanced_offset_comp.length = p_param->value[offset]; + offset++; + + // obtain data + if (p_ind->rsp.value.enhanced_offset_comp.length) + { + for (int i = 0; i < p_ind->rsp.value.enhanced_offset_comp.length; i++) + { + p_ind->rsp.value.enhanced_offset_comp.data[i] = p_param->value[offset]; + offset++; + } + } + } + // else response value is CPP_CTNL_PT_RESP_INV_PARAM + } + } + + // Send the message + ke_msg_send(p_ind); + + return offset; +} + +#endif //(BLE_CP_COLLECTOR) + +/// @} CPP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/src/cppc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/src/cppc.h new file mode 100644 index 0000000..88d4d4f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/src/cppc.h @@ -0,0 +1,270 @@ +/** + **************************************************************************************** + * + * @file cppc.h + * + * @brief Header file - Cycling Power Status Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CPPC_H_ +#define _CPPC_H_ + +/** + **************************************************************************************** + * @addtogroup CPPC Cycling Power Profile Collector + * @ingroup CPP + * @brief Cycling Power Profile Collector + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "cpp_common.h" + +#if (BLE_CP_COLLECTOR) + +#include "cppc_task.h" +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + + + +/* + * DEFINES + **************************************************************************************** + */ +/// Maximum number of Cycling Power Collector task instances +#define CPPC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the CPPC task +enum cppc_states +{ + /// Idle state + CPPC_FREE, + /// Connected state + CPPC_IDLE, + /// Busy state + CPPC_DISCOVERING, + /// Busy state + CPPC_BUSY, + + /// Number of defined states. + CPPC_STATE_MAX +}; + +/// Internal codes for reading/writing a CPS characteristic with one single request +enum cppc_code +{ + /// Notified CP Measurement + CPPC_NTF_CP_MEAS = CPP_CPS_MEAS_CHAR, + /// Read CP Feature + CPPC_RD_CP_FEAT = CPP_CPS_FEAT_CHAR, + /// Read Sensor Location + CPPC_RD_SENSOR_LOC = CPP_CPS_SENSOR_LOC_CHAR, + /// Notified Vector + CPPC_NTF_CP_VECTOR = CPP_CPS_VECTOR_CHAR, + /// Indicated SC Control Point + CPPC_IND_CTNL_PT = CPP_CPS_CTNL_PT_CHAR, + + /// Read/Write CP Measurement Client Char. Configuration Descriptor + CPPC_RD_WR_CP_MEAS_CL_CFG = (CPPC_DESC_CP_MEAS_CL_CFG | CPPC_DESC_MASK), + /// Read/Write CP Measurement Server Char. Configuration Descriptor + CPPC_RD_WR_CP_MEAS_SV_CFG = (CPPC_DESC_CP_MEAS_SV_CFG | CPPC_DESC_MASK), + + /// Read/Write Vector Client Char. Configuration Descriptor + CPPC_RD_WR_VECTOR_CFG = (CPPC_DESC_VECTOR_CL_CFG | CPPC_DESC_MASK), + /// Read CP Control Point Client Char. Configuration Descriptor + CPPC_RD_WR_CTNL_PT_CFG = (CPPC_DESC_CTNL_PT_CL_CFG | CPPC_DESC_MASK), +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +struct cppc_cnx_env +{ + /// Current Operation + void *p_operation; + ///Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Counter used to check service uniqueness + uint8_t nb_svc; + /// Cycling Power Service Characteristics + struct cppc_cps_content cps; +}; + +/// Cycling Power Profile Collector environment variable +struct cppc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct cppc_cnx_env *p_env[CPPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[CPPC_IDX_MAX]; +}; + +/// Command Message Basic Structure +struct cppc_cmd +{ + /// Operation Code + uint8_t operation; + + /// MORE DATA +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve CPP client profile interface + * @return CPP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* cppc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Cycling Power ATT DB discovery results to CPPC host. + * @param[in] p_cppc_env environment variable + * @param[in] conidx Connection index + * @param[in] status Satus + **************************************************************************************** + */ +void cppc_enable_rsp_send(struct cppc_env_tag *p_cppc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send a CPPC_CMP_EVT message when no connection exists (no environment) + * @param[in] src_id Source task + * @param[in] dest_id Destination task + * @param[in] operation Operation + **************************************************************************************** + */ +void cppc_send_no_conn_cmp_evt(uint8_t src_id, uint8_t dest_id, uint8_t operation); + +/** + **************************************************************************************** + * @brief Send a CPPC_CMP_EVT message to the task which enabled the profile + * @param[in] p_cppc_env environment variable + * @param[in] conidx Connection index + * @param[in] operation Operation + * @param[in] status Satus + **************************************************************************************** + */ +void cppc_send_cmp_evt(struct cppc_env_tag *p_cppc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/** + **************************************************************************************** + * @brief Gets correct read handle according to the request + * @param[in] p_cppc_env environment variable + * @param[in] conidx Connection index + * @param[in] param Pointer to the parameters of the message. + * @return handle + **************************************************************************************** + */ +uint16_t cppc_get_read_handle_req (struct cppc_env_tag *p_cppc_env, uint8_t conidx, struct cpps_read_cmd *p_param); + +/** + **************************************************************************************** + * @brief Gets correct write handle according to the request + * @param[in] conidx Connection index + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] p_cppc_env environment variable + * @param[out] p_handle handle + * @return status of the operation + **************************************************************************************** + */ +uint8_t cppc_get_write_desc_handle_req (uint8_t conidx, struct cppc_cfg_ntfind_cmd *p_param, + struct cppc_env_tag *p_cppc_env, uint16_t *p_handle); + +/** + **************************************************************************************** + * @brief Unpacks measurement data and sends the indication + * @param[in] conidx Connection index + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] p_cppc_env environment variable + * @return length + **************************************************************************************** + */ +uint8_t cppc_unpack_meas_ind (uint8_t conidx, struct gattc_event_ind const *p_param, struct cppc_env_tag *p_cppc_env); + +/** + **************************************************************************************** + * @brief Unpacks Vector data and sends the indication + * @param[in] conidx Connection index + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] p_cppc_env environment variable + * @return length + **************************************************************************************** + */ +uint8_t cppc_unpack_vector_ind (uint8_t conidx, struct gattc_event_ind const *p_param, struct cppc_env_tag *p_cppc_env); + +/** + **************************************************************************************** + * @brief Packs Control Point data + * @param[in] p_param Pointer to the parameters of the message. + * @param[out] p_req packed message + * @param[out] p_status status of the operation + * @return length + **************************************************************************************** + */ +uint8_t cppc_pack_ctnl_pt_req (struct cppc_ctnl_pt_cfg_cmd *p_param, uint8_t *p_req, uint8_t *p_status); + +/** + **************************************************************************************** + * @brief Unpacks Control Point data and sends the indication + * @param[in] conidx Connection index + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] p_cppc_env environment variable + * @return length + **************************************************************************************** + */ +uint8_t cppc_unpack_ctln_pt_ind (uint8_t conidx, struct gattc_event_ind const *p_param,struct cppc_env_tag *p_cppc_env); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void cppc_task_init(struct ke_task_desc *p_task_desc); + + +#endif //(BLE_CP_COLLECTOR) + +/// @} CPPC + +#endif //(_CPPC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/src/cppc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/src/cppc_task.c new file mode 100644 index 0000000..e77f763 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cppc/src/cppc_task.c @@ -0,0 +1,796 @@ +/** + **************************************************************************************** + * + * @file cppc_task.c + * + * @brief Cycling Power Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup CPPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_CP_COLLECTOR) +#include "cpp_common.h" +#include "cppc_task.h" +#include "cppc.h" + +#include "gap.h" +#include "gattc_task.h" + +#include "ke_timer.h" +#include "ke_mem.h" + +#include "co_utils.h" + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve Cycling Power service characteristics information +const struct prf_char_def cppc_cps_char[CPP_CPS_CHAR_MAX] = +{ + /// CP Measurement + [CPP_CPS_MEAS_CHAR] = {ATT_CHAR_CP_MEAS, + ATT_MANDATORY, + ATT_CHAR_PROP_NTF}, + /// CP Feature + [CPP_CPS_FEAT_CHAR] = {ATT_CHAR_CP_FEAT, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, + /// Sensor Location + [CPP_CPS_SENSOR_LOC_CHAR] = {ATT_CHAR_SENSOR_LOC, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, + /// Vector + [CPP_CPS_VECTOR_CHAR] = {ATT_CHAR_CP_VECTOR, + ATT_OPTIONAL, + ATT_CHAR_PROP_NTF}, + /// CP Control Point + [CPP_CPS_CTNL_PT_CHAR] = {ATT_CHAR_CP_CNTL_PT, + ATT_OPTIONAL, + ATT_CHAR_PROP_WR | ATT_CHAR_PROP_IND}, +}; + +/// State machine used to retrieve Cycling Power service characteristic descriptor information +const struct prf_char_desc_def cppc_cps_char_desc[CPPC_DESC_MAX] = +{ + /// CP Measurement Char. - Client Characteristic Configuration + [CPPC_DESC_CP_MEAS_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + CPP_CPS_MEAS_CHAR}, + + /// CP Measurement Char. - Server Characteristic Configuration + [CPPC_DESC_CP_MEAS_SV_CFG] = {ATT_DESC_SERVER_CHAR_CFG, + ATT_OPTIONAL, + CPP_CPS_MEAS_CHAR}, + + /// CP Vector Char. - Client Characteristic Configuration + [CPPC_DESC_VECTOR_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_OPTIONAL, + CPP_CPS_VECTOR_CHAR}, + + /// Control Point Char. - Client Characteristic Configuration + [CPPC_DESC_CTNL_PT_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_OPTIONAL, + CPP_CPS_CTNL_PT_CHAR}, +}; + +/* + * HANDLER FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPC_ENABLE_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cppc_enable_req_handler(ke_msg_id_t const msgid, + struct cppc_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + uint8_t state = ke_state_get(dest_id); + // Cycling Power Profile Collector Role Task Environment + struct cppc_env_tag *p_cppc_env = PRF_ENV_GET(CPPC, cppc); + + ASSERT_INFO(p_cppc_env != NULL, dest_id, src_id); + if ((state == CPPC_IDLE) && (p_cppc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_cppc_env->p_env[conidx] = (struct cppc_cnx_env *) ke_malloc(sizeof(struct cppc_cnx_env), KE_MEM_ATT_DB); + memset(p_cppc_env->p_env[conidx], 0, sizeof(struct cppc_cnx_env)); + + // Config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + //start discovering CPS on peer + prf_disc_svc_send(&(p_cppc_env->prf_env), conidx, ATT_SVC_CYCLING_POWER); + + // Go to DISCOVERING state + ke_state_set(dest_id, CPPC_DISCOVERING); + } + // normal connection, get saved att details + else + { + p_cppc_env->p_env[conidx]->cps = p_param->cps; + + //send APP confirmation that can start normal connection to TH + cppc_enable_rsp_send(p_cppc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != CPPC_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + cppc_enable_rsp_send(p_cppc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPC_READ_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cppc_read_req_handler(ke_msg_id_t const msgid, + struct cpps_read_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct cppc_env_tag *p_cppc_env = PRF_ENV_GET(CPPC, cppc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == CPPC_IDLE) + { + ASSERT_INFO(p_cppc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_cppc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Get the handler + uint16_t hdl = cppc_get_read_handle_req (p_cppc_env, conidx, p_param); + + // Check if handle is viable + if (hdl != ATT_INVALID_SEARCH_HANDLE) + { + // Force the operation value + p_param->operation = CPPC_READ_OP_CODE; + + // Store the command structure + p_cppc_env->p_env[conidx]->p_operation = p_param; + msg_status = KE_MSG_NO_FREE; + + // Send the read request + prf_read_char_send( &(p_cppc_env->prf_env), conidx, + p_cppc_env->p_env[conidx]->cps.svc.shdl, + p_cppc_env->p_env[conidx]->cps.svc.ehdl, + hdl); + + // Go to the Busy state + ke_state_set(dest_id, CPPC_BUSY); + + status = ATT_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == CPPC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send the complete event message to the task id stored in the environment + cppc_send_cmp_evt(p_cppc_env, conidx, CPPC_READ_OP_CODE, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPC_CFG_NTFIND_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cppc_cfg_ntfind_cmd_handler(ke_msg_id_t const msgid, + struct cppc_cfg_ntfind_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cppc_env_tag *p_cppc_env = PRF_ENV_GET(CPPC, cppc); + + // Message status + int msg_status = KE_MSG_CONSUMED; + + if (p_cppc_env != NULL) + { + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + do + { + if (ke_state_get(dest_id) != CPPC_IDLE) + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + break; + } + + ASSERT_ERR(p_cppc_env->p_env[conidx] != NULL); + + // Get handle + status = cppc_get_write_desc_handle_req (conidx, p_param, p_cppc_env, &handle); + } while (0); + + if ((status == GAP_ERR_NO_ERROR) && (handle != ATT_INVALID_SEARCH_HANDLE)) + { + // Set the operation code + p_param->operation = CPPC_CFG_NTF_IND_OP_CODE; + + // Store the command structure + p_cppc_env->p_env[conidx]->p_operation = p_param; + msg_status = KE_MSG_NO_FREE; + + // Go to the Busy state + ke_state_set(dest_id, CPPC_BUSY); + + // Send GATT Write Request + prf_gatt_write_ntf_ind(&p_cppc_env->prf_env, conidx, handle, p_param->ntfind_cfg); + } + } + else + { + cppc_send_no_conn_cmp_evt(dest_id, src_id, CPPC_CFG_NTF_IND_OP_CODE); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPC_CTNL_PT_CFG_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cppc_ctnl_pt_cfg_cmd_handler(ke_msg_id_t const msgid, + struct cppc_ctnl_pt_cfg_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct cppc_env_tag *p_cppc_env = PRF_ENV_GET(CPPC, cppc); + + if (p_cppc_env != NULL) + { + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + do + { + // State is Connected or Busy + ASSERT_ERR(ke_state_get(dest_id) > CPPC_FREE); + // Check the provided connection handle + if (p_cppc_env->p_env[conidx] == NULL) + { + status = PRF_ERR_INVALID_PARAM; + break; + } + + if (ke_state_get(dest_id) != CPPC_IDLE) + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + // Status is GAP_ERR_NO_ERROR, no message will be sent to the application + break; + } + + // Check if the characteristic has been found + if (p_cppc_env->p_env[conidx]->cps.descs[CPPC_DESC_CTNL_PT_CL_CFG].desc_hdl != ATT_INVALID_SEARCH_HANDLE) + { + // Request array declaration + uint8_t req[CPP_CP_CNTL_PT_REQ_MAX_LEN]; + // Pack request + uint8_t nb = cppc_pack_ctnl_pt_req(p_param, req, &status); + + if (status == GAP_ERR_NO_ERROR) + { + // Set the operation code + p_param->operation = CPPC_CTNL_PT_CFG_WR_OP_CODE; + + // Store the command structure + p_cppc_env->p_env[conidx]->p_operation = p_param; + // Store the command information + msg_status = KE_MSG_NO_FREE; + + // Go to the Busy state + ke_state_set(dest_id, CPPC_BUSY); + + // Send the write request + prf_gatt_write(&(p_cppc_env->prf_env), conidx, + p_cppc_env->p_env[conidx]->cps.chars[CPP_CPS_CTNL_PT_CHAR].val_hdl, + (uint8_t *)&req[0], nb, GATTC_WRITE); + } + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } while (0); + + if (status != GAP_ERR_NO_ERROR) + { + // Send a complete event status to the application + cppc_send_cmp_evt(p_cppc_env, conidx, CPPC_CTNL_PT_CFG_WR_OP_CODE, status); + } + } + else + { + // No connection + cppc_send_no_conn_cmp_evt(dest_id, src_id, CPPC_CTNL_PT_CFG_WR_OP_CODE); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPC_TIMEOUT_TIMER_IND message. This message is + * received when the peer device doesn't send a SC Control Point indication within 30s + * after reception of the write response. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cppc_timeout_timer_ind_handler(ke_msg_id_t const msgid, + void const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cppc_env_tag *p_cppc_env = PRF_ENV_GET(CPPC, cppc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_cppc_env != NULL) + { + ASSERT_ERR(p_cppc_env->p_env[conidx]->p_operation != NULL); + ASSERT_ERR(((struct cppc_cmd *)p_cppc_env->p_env[conidx]->p_operation)->operation + == CPPC_CTNL_PT_CFG_IND_OP_CODE); + + // Send the complete event message + cppc_send_cmp_evt(p_cppc_env, conidx, CPPC_CTNL_PT_CFG_WR_OP_CODE, PRF_ERR_PROC_TIMEOUT); + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CPPC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct cppc_env_tag *p_cppc_env = PRF_ENV_GET(CPPC, cppc); + + ASSERT_INFO(p_cppc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_cppc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_cppc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve CPS characteristics and descriptors + prf_extract_svc_info(p_ind, CPP_CPS_CHAR_MAX, &cppc_cps_char[0], &p_cppc_env->p_env[conidx]->cps.chars[0], + CPPC_DESC_MAX, &cppc_cps_char_desc[0], &p_cppc_env->p_env[conidx]->cps.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_cppc_env->p_env[conidx]->cps.svc.shdl = p_ind->start_hdl; + p_cppc_env->p_env[conidx]->cps.svc.ehdl = p_ind->end_hdl; + } + + p_cppc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cppc_env_tag *p_cppc_env = PRF_ENV_GET(CPPC, cppc); + + if (p_cppc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == CPPC_DISCOVERING) + { + // Status + uint8_t status = p_param->status; + + if ((status == ATT_ERR_ATTRIBUTE_NOT_FOUND) || + (status == ATT_ERR_NO_ERROR)) + { + // Discovery + // check characteristic validity + if (p_cppc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(CPP_CPS_CHAR_MAX, + p_cppc_env->p_env[conidx]->cps.chars, + cppc_cps_char); + } + // too much services + else if (p_cppc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(CPPC_DESC_MAX, + p_cppc_env->p_env[conidx]->cps.descs, + cppc_cps_char_desc, + p_cppc_env->p_env[conidx]->cps.chars); + } + } + + cppc_enable_rsp_send(p_cppc_env, conidx, status); + } + else if (state == CPPC_BUSY) + { + switch (p_param->operation) + { + case GATTC_READ: + { + // Send the complete event status + cppc_send_cmp_evt(p_cppc_env, conidx, CPPC_READ_OP_CODE, p_param->status); + } break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + uint8_t operation = ((struct cppc_cmd *)p_cppc_env->p_env[conidx]->p_operation)->operation; + + if (operation == CPPC_CFG_NTF_IND_OP_CODE) + { + // Send the complete event status + cppc_send_cmp_evt(p_cppc_env, conidx, operation, p_param->status); + } + + else if (operation == CPPC_CTNL_PT_CFG_WR_OP_CODE) + { + if (p_param->status == GAP_ERR_NO_ERROR) + { + // Start Timeout Procedure + ke_timer_set(CPPC_TIMEOUT_TIMER_IND, dest_id, 10*ATT_TRANS_RTX); + + // Wait for the response indication + ((struct cppc_cmd *)p_cppc_env->p_env[conidx]->p_operation)->operation + = CPPC_CTNL_PT_CFG_IND_OP_CODE; + } + else + { + // Send the complete event status + cppc_send_cmp_evt(p_cppc_env, conidx, operation, p_param->status); + } + } + } break; + + case GATTC_REGISTER: + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CPPC_BUSY) + { + // Get the address of the environment + struct cppc_env_tag *p_cppc_env = PRF_ENV_GET(CPPC, cppc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_cppc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_cppc_env->p_env[conidx] != NULL, dest_id, src_id); + + // Send the read value to the HL + struct cppc_value_ind *p_ind = KE_MSG_ALLOC( + CPPC_VALUE_IND, + prf_dst_task_get(&(p_cppc_env->prf_env), conidx), + dest_id, + cppc_value_ind); + + switch (((struct cpps_read_cmd *)p_cppc_env->p_env[conidx]->p_operation)->read_code) + { + // Read CP Feature Characteristic value + case (CPPC_RD_CP_FEAT): + { + p_ind->value.sensor_feat = co_read32p(&p_param->value[0]); + } break; + + // Read Sensor Location Characteristic value + case (CPPC_RD_SENSOR_LOC): + { + p_ind->value.sensor_loc = p_param->value[0]; + } break; + + // Read Client Characteristic Configuration Descriptor value + case (CPPC_RD_WR_CP_MEAS_CL_CFG): + case (CPPC_RD_WR_CP_MEAS_SV_CFG): + case (CPPC_RD_WR_VECTOR_CFG): + case (CPPC_RD_WR_CTNL_PT_CFG): + { + co_write16p(&p_ind->value.ntf_cfg, p_param->value[0]); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + p_ind->att_code = ((struct cpps_read_cmd *)p_cppc_env->p_env[conidx]->p_operation)->read_code; + + // Send the message to the application + ke_msg_send(p_ind); + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cppc_env_tag *p_cppc_env = PRF_ENV_GET(CPPC, cppc); + + if (p_cppc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + switch (p_param->type) + { + case (GATTC_NOTIFY): + { + if (p_param->handle == p_cppc_env->p_env[conidx]->cps.chars[CPP_CPS_MEAS_CHAR].val_hdl) + { + //Unpack measurement + cppc_unpack_meas_ind (conidx, p_param, p_cppc_env); + } + else if (p_param->handle == p_cppc_env->p_env[conidx]->cps.chars[CPP_CPS_VECTOR_CHAR].val_hdl) + { + //Unpack vector + cppc_unpack_vector_ind (conidx, p_param, p_cppc_env); + } + else + { + ASSERT_ERR(0); + } + } break; + + case (GATTC_INDICATE): + { + // confirm that indication has been correctly received + struct gattc_event_cfm *p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + + // Check if we were waiting for the indication + if (p_cppc_env->p_env[conidx]->p_operation != NULL) + { + if (((struct cppc_cmd *)p_cppc_env->p_env[conidx]->p_operation)->operation + == CPPC_CTNL_PT_CFG_IND_OP_CODE) + { + // Stop the procedure timeout timer + ke_timer_clear(CPPC_TIMEOUT_TIMER_IND, dest_id); + + // Unpack control point + cppc_unpack_ctln_pt_ind(conidx, p_param, p_cppc_env); + + // Send the complete event message + cppc_send_cmp_evt(p_cppc_env, conidx, CPPC_CTNL_PT_CFG_WR_OP_CODE, GAP_ERR_NO_ERROR); + } + // else drop the message + } + // else drop the message + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(cppc) +{ + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {CPPC_READ_CMD, (ke_msg_func_t)cppc_read_req_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {CPPC_CFG_NTFIND_CMD, (ke_msg_func_t)cppc_cfg_ntfind_cmd_handler}, + {CPPC_CTNL_PT_CFG_CMD, (ke_msg_func_t)cppc_ctnl_pt_cfg_cmd_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {CPPC_TIMEOUT_TIMER_IND, (ke_msg_func_t)cppc_timeout_timer_ind_handler}, + {CPPC_ENABLE_REQ, (ke_msg_func_t)cppc_enable_req_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void cppc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct cppc_env_tag *p_cppc_env = PRF_ENV_GET(CPPC, cppc); + + p_task_desc->msg_handler_tab = cppc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(cppc_msg_handler_tab); + p_task_desc->state = p_cppc_env->state; + p_task_desc->idx_max = CPPC_IDX_MAX; +} + +#endif //(BLE_CP_COLLECTOR) + +/// @} CPPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/api/cpps_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/api/cpps_task.h new file mode 100644 index 0000000..cf57a56 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/api/cpps_task.h @@ -0,0 +1,345 @@ +/** + **************************************************************************************** + * + * @file cpps_task.h + * + * @brief Header file - Cycling Power Profile Sensor Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CPPS_TASK_H_ +#define _CPPS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup CPPSTASK Task + * @ingroup CPPS + * @brief Cycling Power Profile Task. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "cpp_common.h" + + +#include +#include "rwip_task.h" // Task definitions + +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Messages for Cycling Power Profile Sensor +/*@TRACE*/ +enum cpps_msg_id +{ + /// Start the Cycling Power Profile Server profile + CPPS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_CPPS), + /// Confirm profile + CPPS_ENABLE_RSP, + + /// Gets packed data for advertising + CPPS_GET_ADV_DATA_REQ, + /// Response with packed data for advertising + CPPS_GET_ADV_DATA_RSP, + + /// Send a CP Measurement to the peer device (Notification) + CPPS_NTF_CP_MEAS_CMD, + + /// Send a CP Vector to the peer device (Notification) + CPPS_NTF_CP_VECTOR_CMD, + + /// Send a complete event status to the application + CPPS_CMP_EVT, + + /// Indicate that an attribute value has been written + CPPS_CFG_NTFIND_IND, + + /// Request to change vector client configuration + CPPS_VECTOR_CFG_REQ_IND, + /// Confirmation to change vector client configuration + CPPS_VECTOR_CFG_CFM, + + /// Indicate that Control Point characteristic value has been written + CPPS_CTNL_PT_REQ_IND, + /// Application response after receiving a CPPS_CTNL_PT_REQ_IND message + CPPS_CTNL_PT_CFM, +}; + +/// Operation Code used in the profile state machine +enum cpps_op_code +{ + /// Reserved Operation Code + CPPS_RESERVED_OP_CODE = 0x00, + + /// Enable Profile Operation Code + CPPS_ENABLE_REQ_OP_CODE, + + /// Send CP Measurement Operation Code + CPPS_NTF_MEAS_OP_CODE, + + /// Send Vector Operation Code + CPPS_NTF_VECTOR_OP_CODE, + + /** + * Control Point Operation + */ + /// Set Cumulative Value + CPPS_CTNL_PT_SET_CUMUL_VAL_OP_CODE, + /// Update Sensor Location + CPPS_CTNL_PT_UPD_SENSOR_LOC_OP_CODE, + /// Request Supported Sensor Locations + CPPS_CTNL_PT_REQ_SUPP_SENSOR_LOC_OP_CODE, + /// Set Crank Length + CPPS_CTNL_PT_SET_CRANK_LENGTH_OP_CODE, + /// Request Crank Length + CPPS_CTNL_PT_REQ_CRANK_LENGTH_OP_CODE, + /// Set Chain Length + CPPS_CTNL_PT_SET_CHAIN_LENGTH_OP_CODE, + /// Request Chain Length + CPPS_CTNL_PT_REQ_CHAIN_LENGTH_OP_CODE, + /// Set Chain Weight + CPPS_CTNL_PT_SET_CHAIN_WEIGHT_OP_CODE, + /// Request Chain Weight + CPPS_CTNL_PT_REQ_CHAIN_WEIGHT_OP_CODE, + /// Set Span Length + CPPS_CTNL_PT_SET_SPAN_LENGTH_OP_CODE, + /// Request Span Length + CPPS_CTNL_PT_REQ_SPAN_LENGTH_OP_CODE, + /// Start Offset Compensation + CPPS_CTNL_PT_START_OFFSET_COMP_OP_CODE, + /// Mask CP Measurement Characteristic Content + CPPS_CTNL_MASK_CP_MEAS_CH_CONTENT_OP_CODE, + /// Request Sampling Rate + CPPS_CTNL_REQ_SAMPLING_RATE_OP_CODE, + /// Request Factory Calibration Date + CPPS_CTNL_REQ_FACTORY_CALIBRATION_DATE_OP_CODE, + /// Start Enhanced Offset Compensation + CPPS_CTNL_START_ENHANCED_OFFSET_COMP_OP_CODE, + + /// Error Indication Sent Operation Code + CPPS_CTNL_ERR_IND_OP_CODE, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the @ref CPPS_CREATE_DB_REQ message +struct cpps_db_cfg +{ + /** + * CP Feature Value - Not supposed to be modified during the lifetime of the device + * This bit field is set in order to decide which features are supported: + * Supported features (specification) ---------------- Bits 0 to 18 + */ + uint32_t cp_feature; + /// Initial count for wheel revolutions + uint32_t wheel_rev; + /** + * Profile characteristic configuration: + * Enable broadcaster mode in Measurement Characteristic --- Bit 0 + * Enable Control Point Characteristic (*) ----------------- Bit 1 + * + * (*) Note this characteristic is mandatory if server supports: + * - Wheel Revolution Data + * - Multiple Sensor Locations + * - Configurable Settings + * - Offset Compensation + * - Server allows to be requested for parameters (CPP_CTNL_PT_REQ... codes) + */ + uint8_t prfl_config; + /** + * Indicate the sensor location. + */ + uint8_t sensor_loc; +}; + +/// Parameters of the @ref CPPS_ENABLE_REQ message +struct cpps_enable_req +{ + /// Connection index + uint8_t conidx; + /** + * Profile characteristic configuration: + * Measurement Characteristic notification config --- Bit 0 + * Measurement Characteristic broadcast config ------ Bit 1 + * Vector Characteristic notification config -------- Bit 2 + * Control Point Characteristic indication config --- Bit 3 + */ + uint16_t prfl_ntf_ind_cfg; +}; + +/// Parameters of the @ref CPPS_ENABLE_RSP message +struct cpps_enable_rsp +{ + /// Connection index + uint8_t conidx; + /// status + uint8_t status; +}; + +/// Parameters of the @ref CPPS_GET_ADV_DATA_REQ message +struct cpps_get_adv_data_req +{ + /// Measurement parameters + struct cpp_cp_meas parameters; +}; + +/// Parameters of the @ref CPPS_GET_ADV_DATA_RSP message +struct cpps_get_adv_data_rsp +{ + uint8_t status; + /// Data length + uint8_t data_len; + /// Data to advertise + uint8_t adv_data[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref CPPS_NTF_CP_MEAS_CMD message +struct cpps_ntf_cp_meas_cmd +{ + /// Measurement parameters + struct cpp_cp_meas parameters; +}; + +/// Parameters of the @ref CPPS_NTF_CP_VECTOR_CMD message +struct cpps_ntf_cp_vector_cmd +{ + /// Vector parameters + struct cpp_cp_vector parameters; +}; + +/// Parameters of the @ref CPPS_CTNL_PT_REQ_IND message +struct cpps_ctnl_pt_req_ind +{ + /// Connection index + uint8_t conidx; + /// Operation Code + uint8_t op_code; + /// Value + union cpps_ctnl_pt_req_ind_value + { + /// Cumulative Value + uint32_t cumul_val; + /// Sensor Location + uint8_t sensor_loc; + /// Crank Length + uint16_t crank_length; + /// Chain Length + uint16_t chain_length; + /// Chain Weight + uint16_t chain_weight; + /// Span Length + uint16_t span_length; + /// Mask Content + uint16_t mask_content; + } value; +}; + +/// Parameters of the @ref CPPS_CTNL_PT_CFM message +struct cpps_ctnl_pt_cfm +{ + /// Connection index + uint8_t conidx; + /// Operation Code + uint8_t op_code; + /// Status + uint8_t status; + /// Value + union cpps_sc_ctnl_pt_cfm_value + { + /// Supported sensor locations (up to 17) + uint32_t supp_sensor_loc; + /// New Cumulative Wheel revolution Value + uint32_t cumul_wheel_rev; + /// Crank Length + uint16_t crank_length; + /// Chain Length + uint16_t chain_length; + /// Chain Weight + uint16_t chain_weight; + /// Span Length + uint16_t span_length; + /// Offset compensation + int16_t offset_comp; + /// Mask Measurement content + uint16_t mask_meas_content; + ///Sampling rate + uint8_t sampling_rate; + /// New Sensor Location + uint8_t sensor_loc; + /// Enhanced Offset Compensation + struct cpp_enhanced_offset_comp enhanced_offset_comp; + /// Calibration date + struct prf_date_time factory_calibration; + + } value; +}; + +/// Parameters of the @ref CPPS_CFG_NTFIND_IND message +struct cpps_cfg_ntfind_ind +{ + /// Connection index + uint8_t conidx; + /// Characteristic Code (CP Measurement or Control Point) + uint8_t char_code; + /// Char. Client Characteristic Configuration + uint16_t ntf_cfg; +}; + +/// Parameters of the @ref CPPS_VECTOR_CFG_REQ_IND message +struct cpps_vector_cfg_req_ind +{ + /// Connection index + uint8_t conidx; + /// Characteristic Code + uint8_t char_code; + /// Char. Client Characteristic Configuration + uint16_t ntf_cfg; +}; + +/// Parameters of the @ref CPPS_VECTOR_CFG_CFM message +struct cpps_vector_cfg_cfm +{ + /// Connection index + uint8_t conidx; + /// Status + uint8_t status; + /// Char. Client Characteristic Configuration + uint16_t ntf_cfg; +}; + +/// Parameters of the @ref CPPS_CMP_EVT message +struct cpps_cmp_evt +{ + /// Connection index + uint8_t conidx; + /// Operation Code + uint8_t operation; + /// Operation Status + uint8_t status; +}; + +/// @} CPPSTASK + +#endif //(_CPPS_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/sourcelist.txt new file mode 100644 index 0000000..4cc14ea --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + cpps.c + cpps_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/src/cpps.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/src/cpps.c new file mode 100644 index 0000000..5d3d058 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/src/cpps.c @@ -0,0 +1,1545 @@ +/** + **************************************************************************************** + * + * @file cpps.c + * + * @brief Cycling Power Profile Sensor implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup CPPS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include "rwip_config.h" +#if (BLE_CP_SENSOR) +#include "cpp_common.h" +#include "gap.h" +#include "gattc_task.h" +#include "gattc.h" +#include "cpps.h" +#include "cpps_task.h" +#include "prf_utils.h" +#include "co_math.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Full CPPS Database Description - Used to add attributes into the database +static const struct attm_desc cpps_att_db[CPS_IDX_NB] = +{ + // Cycling Power Service Declaration + [CPS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // CP Measurement Characteristic Declaration + [CPS_IDX_CP_MEAS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // CP Measurement Characteristic Value + [CPS_IDX_CP_MEAS_VAL] = {ATT_CHAR_CP_MEAS, PERM(NTF, ENABLE), PERM(RI, ENABLE), CPP_CP_MEAS_NTF_MAX_LEN}, + // CP Measurement Characteristic - Client Characteristic Configuration Descriptor + [CPS_IDX_CP_MEAS_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + // CP Measurement Characteristic - Server Characteristic Configuration Descriptor + [CPS_IDX_CP_MEAS_BCST_CFG] = {ATT_DESC_SERVER_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // CP Feature Characteristic Declaration + [CPS_IDX_CP_FEAT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // CP Feature Characteristic Value + [CPS_IDX_CP_FEAT_VAL] = {ATT_CHAR_CP_FEAT, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint32_t)}, + + // Sensor Location Characteristic Declaration + [CPS_IDX_SENSOR_LOC_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Sensor Location Characteristic Value + [CPS_IDX_SENSOR_LOC_VAL] = {ATT_CHAR_SENSOR_LOC, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, + + // CP Vector Characteristic Declaration + [CPS_IDX_VECTOR_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // CP Vector Characteristic Value + [CPS_IDX_VECTOR_VAL] = {ATT_CHAR_CP_VECTOR, PERM(NTF, ENABLE), PERM(RI, ENABLE), CPP_CP_VECTOR_MAX_LEN}, + // CP Vector Characteristic - Client Characteristic Configuration Descriptor + [CPS_IDX_VECTOR_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // CP Control Point Characteristic Declaration + [CPS_IDX_CTNL_PT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // CP Control Point Characteristic Value - The response has the maximal length + [CPS_IDX_CTNL_PT_VAL] = {ATT_CHAR_CP_CNTL_PT, PERM(IND, ENABLE) | PERM(WRITE_REQ, ENABLE), + PERM(RI, ENABLE), CPP_CP_CNTL_PT_RSP_MAX_LEN}, + // CP Control Point Characteristic - Client Characteristic Configuration Descriptor + [CPS_IDX_CTNL_PT_IND_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the CPPS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t cpps_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct cpps_db_cfg *p_params) +{ + //------------------ create the attribute database for the profile ------------------- + // Service content flag + uint32_t cfg_flag= CPPS_MANDATORY_MASK; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + /* + * Check if Broadcaster role shall be added. + */ + if (CPPS_IS_FEATURE_SUPPORTED(p_params->prfl_config, CPPS_BROADCASTER_SUPP_FLAG)) + { + //Add configuration to the database + cfg_flag |= CPPS_MEAS_BCST_MASK; + } + /* + * Check if the CP Vector characteristic shall be added. + * Mandatory if at least one Vector procedure is supported, otherwise excluded. + */ + if ((GETB(p_params->cp_feature, CPP_FEAT_CRANK_REV_DATA_SUP)) || + (GETB(p_params->cp_feature, CPP_FEAT_EXTREME_ANGLES_SUP)) || + (GETB(p_params->cp_feature, CPP_FEAT_INSTANT_MEAS_DIRECTION_SUP))) + { + cfg_flag |= CPPS_VECTOR_MASK; + } + /* + * Check if the Control Point characteristic shall be added + * Mandatory if server supports: + * - Wheel Revolution Data + * - Multiple Sensor Locations + * - Configurable Settings (CPP_CTNL_PT_SET codes) + * - Offset Compensation + * - Server allows to be requested for parameters (CPP_CTNL_PT_REQ codes) + */ + if ((CPPS_IS_FEATURE_SUPPORTED(p_params->prfl_config, CPPS_CTNL_PT_CHAR_SUPP_FLAG)) || + (GETB(p_params->cp_feature, CPP_FEAT_WHEEL_REV_DATA_SUP)) || + (GETB(p_params->cp_feature, CPP_FEAT_MULT_SENSOR_LOC_SUP)) || + (GETB(p_params->cp_feature, CPP_FEAT_CRANK_LENGTH_ADJ_SUP)) || + (GETB(p_params->cp_feature, CPP_FEAT_CHAIN_LENGTH_ADJ_SUP)) || + (GETB(p_params->cp_feature, CPP_FEAT_CHAIN_WEIGHT_ADJ_SUP)) || + (GETB(p_params->cp_feature, CPP_FEAT_SPAN_LENGTH_ADJ_SUP)) || + (GETB(p_params->cp_feature, CPP_FEAT_OFFSET_COMP_SUP))) + { + cfg_flag |= CPPS_CTNL_PT_MASK; + } + + // Add service in the database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_CYCLING_POWER, (uint8_t *)&cfg_flag, + CPS_IDX_NB, NULL, p_env->task, &cpps_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, DISABLE)); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + // Allocate CPPS required environment variable + struct cpps_env_tag *p_cpps_env = + (struct cpps_env_tag *) ke_malloc(sizeof(struct cpps_env_tag), KE_MEM_ATT_DB); + + // Initialize CPPS environment + p_env->env = (prf_env_t *) p_cpps_env; + p_cpps_env->shdl = *p_start_hdl; + p_cpps_env->prfl_cfg = cfg_flag; + p_cpps_env->features = p_params->cp_feature; + p_cpps_env->sensor_loc = p_params->sensor_loc; + p_cpps_env->cumul_wheel_rev = p_params->wheel_rev; + p_cpps_env->operation = CPPS_RESERVED_OP_CODE; + + p_cpps_env->p_op_data = NULL; + memset(p_cpps_env->env, 0, sizeof(p_cpps_env->env)); + + p_cpps_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Mono Instantiated task + p_cpps_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_CPPS; + cpps_task_init(&(p_env->desc)); + + /* + * Check if the Broadcaster role shall be added. + */ + if (CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_MEAS_BCST_MASK)) + { + // Optional Permissions + uint16_t perm = PERM(NTF, ENABLE) | PERM(BROADCAST,ENABLE); + //Add configuration to the database + attm_att_set_permission(CPPS_HANDLE(CPS_IDX_CP_MEAS_VAL), perm, 0); + } + + // Put CPS in Idle state + ke_state_set(p_env->task, CPPS_IDLE); + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the CPPS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void cpps_destroy(struct prf_task_env *p_env) +{ + struct cpps_env_tag *p_cpps_env = (struct cpps_env_tag *) p_env->env; + + if (p_cpps_env->p_op_data != NULL) + { + ke_free(p_cpps_env->p_op_data->p_cmd); + if(p_cpps_env->p_op_data->p_ntf_pending) + { + ke_free(p_cpps_env->p_op_data->p_ntf_pending); + } + ke_free(p_cpps_env->p_op_data); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_cpps_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void cpps_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct cpps_env_tag *p_cpps_env = (struct cpps_env_tag *) p_env->env; + + memset(&(p_cpps_env->env[conidx]), 0, sizeof(struct cpps_cnx_env)); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void cpps_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct cpps_env_tag *p_cpps_env = (struct cpps_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + memset(&(p_cpps_env->env[conidx]), 0, sizeof(struct cpps_cnx_env)); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// CPPS Task interface required by profile manager +const struct prf_task_cbs cpps_itf = +{ + (prf_init_fnct) cpps_init, + cpps_destroy, + cpps_create, + cpps_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *cpps_prf_itf_get(void) +{ + return &cpps_itf; +} + +uint8_t cpps_pack_meas_ntf(struct cpp_cp_meas *p_param, uint8_t *p_pckd_meas) +{ + // Packed Measurement length + uint8_t pckd_meas_len = CPP_CP_MEAS_NTF_MIN_LEN; + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + + // Check provided flags + if (GETB(p_param->flags, CPP_MEAS_PEDAL_POWER_BALANCE_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_PEDAL_POWER_BALANCE_SUP)) + { + // Pack Pedal Power Balance info + p_pckd_meas[pckd_meas_len] = p_param->pedal_power_balance; + pckd_meas_len++; + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_MEAS_PEDAL_POWER_BALANCE_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_MEAS_ACCUM_TORQUE_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_ACCUM_TORQUE_SUP)) + { + // Pack Accumulated Torque info + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->accum_torque); + pckd_meas_len += 2; + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_MEAS_ACCUM_TORQUE_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_MEAS_WHEEL_REV_DATA_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_WHEEL_REV_DATA_SUP)) + { + // Pack Wheel Revolution Data (Cumulative Wheel & Last Wheel Event Time) + co_write32p(&p_pckd_meas[pckd_meas_len], p_cpps_env->cumul_wheel_rev); + pckd_meas_len += 4; + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->last_wheel_evt_time); + pckd_meas_len += 2; + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_MEAS_WHEEL_REV_DATA_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_MEAS_CRANK_REV_DATA_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_CRANK_REV_DATA_SUP)) + { + // Pack Crank Revolution Data (Cumulative Crank & Last Crank Event Time) + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->cumul_crank_rev); + pckd_meas_len += 2; + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->last_crank_evt_time); + pckd_meas_len += 2; + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_MEAS_CRANK_REV_DATA_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_MEAS_EXTREME_FORCE_MAGNITUDES_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_EXTREME_MAGNITUDES_SUP) + && (!GETB(p_cpps_env->features, CPP_FEAT_SENSOR_MEAS_CONTEXT))) + { + // Pack Extreme Force Magnitudes (Maximum Force Magnitude & Minimum Force Magnitude) + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->max_force_magnitude); + pckd_meas_len += 2; + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->min_force_magnitude); + pckd_meas_len += 2; + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_MEAS_EXTREME_FORCE_MAGNITUDES_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_MEAS_EXTREME_TORQUE_MAGNITUDES_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_EXTREME_MAGNITUDES_SUP) + && GETB(p_cpps_env->features, CPP_FEAT_SENSOR_MEAS_CONTEXT)) + { + // Pack Extreme Force Magnitudes (Maximum Force Magnitude & Minimum Force Magnitude) + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->max_torque_magnitude); + pckd_meas_len += 2; + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->min_torque_magnitude); + pckd_meas_len += 2; + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_MEAS_EXTREME_TORQUE_MAGNITUDES_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_MEAS_EXTREME_ANGLES_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_EXTREME_ANGLES_SUP)) + { + uint32_t angle; + + // Pack Extreme Angles (Maximum Angle & Minimum Angle) + // Force to 12 bits + p_param->max_angle &= 0x0FFF; + p_param->min_angle &= 0x0FFF; + angle = (uint32_t) (p_param->max_angle | (p_param->min_angle << 12)); + co_write24p(&p_pckd_meas[pckd_meas_len], angle); + pckd_meas_len += 3; + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_MEAS_EXTREME_ANGLES_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_MEAS_TOP_DEAD_SPOT_ANGLE_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_TOPBOT_DEAD_SPOT_ANGLES_SUP)) + { + // Pack Top Dead Spot Angle + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->top_dead_spot_angle); + pckd_meas_len += 2; + } + else + { + // Force to not supported + SETB(p_param->flags, CPP_MEAS_TOP_DEAD_SPOT_ANGLE_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_MEAS_BOTTOM_DEAD_SPOT_ANGLE_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_TOPBOT_DEAD_SPOT_ANGLES_SUP)) + { + // Pack Bottom Dead Spot Angle + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->bot_dead_spot_angle); + pckd_meas_len += 2; + } + else + { + // Force to not supported + SETB(p_param->flags, CPP_MEAS_BOTTOM_DEAD_SPOT_ANGLE_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_MEAS_ACCUM_ENERGY_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_ACCUM_ENERGY_SUP)) + { + // Pack Accumulated Energy + co_write16p(&p_pckd_meas[pckd_meas_len], p_param->accum_energy); + pckd_meas_len += 2; + } + else + { + // Force to not supported + SETB(p_param->flags, CPP_MEAS_ACCUM_ENERGY_PRESENT, 0); + } + } + + // Flags value + co_write16p(&p_pckd_meas[0], p_param->flags); + // Instant Power (Mandatory) + co_write16p(&p_pckd_meas[2], p_param->inst_power); + + return pckd_meas_len; +} + +uint8_t cpps_split_meas_ntf(uint8_t conidx, struct gattc_send_evt_cmd *p_meas_ntf1) +{ + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + // Extract flags info + uint16_t flags = co_read16p(&p_meas_ntf1->value[0]); + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_meas_ntf2 = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), prf_src_task_get(&p_cpps_env->prf_env, conidx), + gattc_send_evt_cmd, CPP_CP_MEAS_NTF_MAX_LEN); + // Current position + uint8_t len = 0; + + // Fill in the parameter structure + p_meas_ntf2->operation = GATTC_NOTIFY; + p_meas_ntf2->handle = CPPS_HANDLE(CPS_IDX_CP_MEAS_VAL); + p_meas_ntf2->length = CPP_CP_MEAS_NTF_MIN_LEN; + + // Copy status flags + co_write16p(&p_meas_ntf2->value[0], (flags & (CPP_MEAS_PEDAL_POWER_BALANCE_REFERENCE_BIT | + CPP_MEAS_ACCUM_TORQUE_SOURCE_BIT | + CPP_MEAS_OFFSET_COMPENSATION_INDICATOR_BIT))); + // Copy Instantaneous power + memcpy(&p_meas_ntf2->value[2], &p_meas_ntf1->value[2], 2); + + for (uint16_t feat = CPP_MEAS_PEDAL_POWER_BALANCE_PRESENT_BIT; + feat <= CPP_MEAS_OFFSET_COMPENSATION_INDICATOR_BIT; + feat <<= 1) + { + // First message fits within the MTU + if (p_meas_ntf1->length <= gattc_get_mtu(conidx) - 3) + { + // Stop splitting + break; + } + + // Check if specific bit presented in Measurement flags + if ((flags & feat) == feat) + { + switch (feat) + { + case CPP_MEAS_PEDAL_POWER_BALANCE_PRESENT_BIT: + { + // Copy uint8 + p_meas_ntf2->value[p_meas_ntf2->length] = p_meas_ntf1->value[CPP_CP_MEAS_NTF_MIN_LEN]; + len = 1; + } break; + + case CPP_MEAS_ACCUM_TORQUE_PRESENT_BIT: + case CPP_MEAS_TOP_DEAD_SPOT_ANGLE_PRESENT_BIT: + case CPP_MEAS_ACCUM_ENERGY_PRESENT_BIT: + case CPP_MEAS_BOTTOM_DEAD_SPOT_ANGLE_PRESENT_BIT: + { + // Copy uint16 + memcpy(&p_meas_ntf2->value[p_meas_ntf2->length], &p_meas_ntf1->value[CPP_CP_MEAS_NTF_MIN_LEN], 2); + len = 2; + } break; + + case CPP_MEAS_EXTREME_ANGLES_PRESENT_BIT: + { + // Copy uint24 + memcpy(&p_meas_ntf2->value[p_meas_ntf2->length], &p_meas_ntf1->value[CPP_CP_MEAS_NTF_MIN_LEN], 3); + len = 3; + } break; + + case CPP_MEAS_CRANK_REV_DATA_PRESENT_BIT: + case CPP_MEAS_EXTREME_FORCE_MAGNITUDES_PRESENT_BIT: + case CPP_MEAS_EXTREME_TORQUE_MAGNITUDES_PRESENT_BIT: + { + // Copy uint16 + uint16 + memcpy(&p_meas_ntf2->value[p_meas_ntf2->length], &p_meas_ntf1->value[CPP_CP_MEAS_NTF_MIN_LEN], 4); + len = 4; + } break; + + case CPP_MEAS_WHEEL_REV_DATA_PRESENT_BIT: + { + // Copy uint32 + uint16 + memcpy(&p_meas_ntf2->value[p_meas_ntf2->length], &p_meas_ntf1->value[CPP_CP_MEAS_NTF_MIN_LEN], 6); + len = 6; + } break; + + default: + { + len = 0; + } break; + } + + if (len) + { + // Update values + p_meas_ntf2->length += len; + // Remove field and flags from the first ntf + p_meas_ntf1->length -= len; + memcpy(&p_meas_ntf1->value[CPP_CP_MEAS_NTF_MIN_LEN], + &p_meas_ntf1->value[CPP_CP_MEAS_NTF_MIN_LEN + len], + p_meas_ntf1->length); + // Update flags + p_meas_ntf1->value[0] &= ~feat; + p_meas_ntf2->value[0] |= feat; + } + } + } + + // store the pending notification to send + p_cpps_env->p_op_data->p_ntf_pending = p_meas_ntf2; + + return p_meas_ntf2->length; +} + +uint8_t cpps_update_characteristic_config(uint8_t conidx, uint8_t prfl_config, + struct gattc_write_req_ind const *p_param) +{ + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get the value + uint16_t ntf_cfg = co_read16p(&p_param->value[0]); + + switch (prfl_config) + { + case CPP_PRF_CFG_FLAG_CTNL_PT_IND_BIT: + { + // Check CCC configuration + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + // Save the new configuration in the environment + SETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_CTNL_PT_IND, 0); + } + else if (ntf_cfg == PRF_CLI_START_IND) + { + // Save the new configuration in the environment + SETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_CTNL_PT_IND, 1); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + + } break; + + case CPP_PRF_CFG_FLAG_VECTOR_NTF_BIT: + { + // Do not save until confirmation + } break; + + case CPP_PRF_CFG_FLAG_SP_MEAS_NTF_BIT: + { + // Check CCC configuration + if ((ntf_cfg == PRF_SRV_STOP_BCST) || (ntf_cfg == PRF_SRV_START_BCST)) + { + // Save the new configuration in the environment + p_cpps_env->broadcast_enabled = (ntf_cfg == PRF_SRV_STOP_BCST) ? + false : true; + + // Update value for every connection (useful for bond data) + for (uint8_t i = 0; i < BLE_CONNECTION_MAX; i++) + { + if (ntf_cfg == PRF_SRV_STOP_BCST) + { + SETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_SP_MEAS_NTF, 0); + } + else + { + SETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_SP_MEAS_NTF, 1); + } + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + case CPP_PRF_CFG_FLAG_CP_MEAS_NTF_BIT: + { + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + SETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_CP_MEAS_NTF, 0); + } + else if (ntf_cfg == PRF_CLI_START_NTF) + { + SETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_CP_MEAS_NTF, 1); + } + else + { + status = PRF_APP_ERROR; + } + } break; + + default: + { + status = ATT_ERR_INVALID_HANDLE; + } break; + } + + if (status == GAP_ERR_NO_ERROR) + { + if (prfl_config == CPP_PRF_CFG_FLAG_VECTOR_NTF_BIT) + { + // Allocate message to inform application + struct cpps_vector_cfg_req_ind *p_ind = KE_MSG_ALLOC(CPPS_VECTOR_CFG_REQ_IND, + prf_dst_task_get(&p_cpps_env->prf_env, conidx), + prf_src_task_get(&p_cpps_env->prf_env, conidx), + cpps_vector_cfg_req_ind); + + // Inform APP of configuration change + p_ind->char_code = prfl_config; + p_ind->ntf_cfg = ntf_cfg; + p_ind->conidx = conidx; + ke_msg_send(p_ind); + } + else + { + // Allocate message to inform application + struct cpps_cfg_ntfind_ind *p_ind = KE_MSG_ALLOC(CPPS_CFG_NTFIND_IND, + prf_dst_task_get(&p_cpps_env->prf_env, conidx), + prf_src_task_get(&p_cpps_env->prf_env, conidx), + cpps_cfg_ntfind_ind); + + // Inform APP of configuration change + p_ind->char_code = prfl_config; + p_ind->ntf_cfg = ntf_cfg; + p_ind->conidx = conidx; + ke_msg_send(p_ind); + } + + // Enable Bonded Data + SETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_PERFORMED_OK, 1); + } + return (status); +} + +uint8_t cpps_pack_vector_ntf(struct cpp_cp_vector *p_param, uint8_t *p_pckd_vector) +{ + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + // Packed Measurement length + uint8_t pckd_vector_len = CPP_CP_VECTOR_MIN_LEN; + + // Check provided flags + if (GETB(p_param->flags, CPP_VECTOR_CRANK_REV_DATA_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_CRANK_REV_DATA_SUP)) + { + // Pack Crank Revolution Data (Cumulative Crank & Last Crank Event Time) + co_write16p(&p_pckd_vector[pckd_vector_len], p_param->cumul_crank_rev); + pckd_vector_len += 2; + co_write16p(&p_pckd_vector[pckd_vector_len], p_param->last_crank_evt_time); + pckd_vector_len += 2; + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_VECTOR_CRANK_REV_DATA_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_VECTOR_FIRST_CRANK_MEAS_ANGLE_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_EXTREME_ANGLES_SUP)) + { + // Pack First Crank Measurement Angle + co_write16p(&p_pckd_vector[pckd_vector_len], p_param->first_crank_meas_angle); + pckd_vector_len += 2; + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_VECTOR_FIRST_CRANK_MEAS_ANGLE_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_VECTOR_INST_FORCE_MAGNITUDE_ARRAY_PRESENT)) + { + if (!GETB(p_cpps_env->features, CPP_FEAT_SENSOR_MEAS_CONTEXT)) + { + // Pack Instantaneous Force Magnitude Array + if ((p_param->nb > CPP_CP_VECTOR_MIN_LEN) && + (p_param->nb <= CPP_CP_VECTOR_MAX_LEN - pckd_vector_len)) + { + for(int j = 0; j < p_param->nb; j++) + { + co_write16p(&p_pckd_vector[pckd_vector_len], p_param->force_torque_magnitude[j]); + pckd_vector_len += 2; + } + } + else + { + return 0; + } + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_VECTOR_INST_FORCE_MAGNITUDE_ARRAY_PRESENT, 0); + } + } + + if (GETB(p_param->flags, CPP_VECTOR_INST_TORQUE_MAGNITUDE_ARRAY_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_SENSOR_MEAS_CONTEXT)) + { + // Pack Instantaneous Torque Magnitude Array + if ((p_param->nb > CPP_CP_VECTOR_MIN_LEN) && + (p_param->nb <= CPP_CP_VECTOR_MAX_LEN - pckd_vector_len)) + { + for(int j = 0; j < p_param->nb; j++) + { + co_write16p(&p_pckd_vector[pckd_vector_len], p_param->force_torque_magnitude[j]); + pckd_vector_len += 2; + } + } + else + { + return 0; + } + } + else // Not supported by the profile + { + // Force to not supported + SETB(p_param->flags, CPP_VECTOR_INST_TORQUE_MAGNITUDE_ARRAY_PRESENT, 0); + } + } + + // Flags value + p_pckd_vector[0] = p_param->flags; + + return pckd_vector_len; +} + +void cpps_send_rsp_ind(uint8_t conidx, uint8_t req_op_code, uint8_t status) +{ + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ctl_pt_rsp = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + prf_src_task_get(&p_cpps_env->prf_env, conidx), + gattc_send_evt_cmd, CPP_CP_CNTL_PT_RSP_MIN_LEN); + + // Fill in the parameter structure + p_ctl_pt_rsp->operation = GATTC_INDICATE; + p_ctl_pt_rsp->handle = CPPS_HANDLE(CPS_IDX_CTNL_PT_VAL); + // Pack Control Point confirmation + p_ctl_pt_rsp->length = CPP_CP_CNTL_PT_RSP_MIN_LEN; + // Response Code + p_ctl_pt_rsp->value[0] = CPP_CTNL_PT_RSP_CODE; + // Request Operation Code + p_ctl_pt_rsp->value[1] = req_op_code; + // Response value + p_ctl_pt_rsp->value[2] = status; + + // Send the event + ke_msg_send(p_ctl_pt_rsp); +} + +uint8_t cpps_unpack_ctnl_point_ind (uint8_t conidx, struct gattc_write_req_ind const *p_param) +{ + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + + // Indication Status + uint8_t ind_status = CPP_CTNL_PT_RESP_NOT_SUPP; + + // Allocate a request indication message for the application + struct cpps_ctnl_pt_req_ind *p_req_ind = KE_MSG_ALLOC(CPPS_CTNL_PT_REQ_IND, + prf_dst_task_get(&p_cpps_env->prf_env, conidx), + prf_src_task_get(&p_cpps_env->prf_env, conidx), cpps_ctnl_pt_req_ind); + + // Operation Code + p_req_ind->op_code = p_param->value[0]; + p_req_ind->conidx = conidx; + + // Operation Code + switch (p_req_ind->op_code) + { + case (CPP_CTNL_PT_SET_CUMUL_VAL): + { + // Check if the Wheel Revolution Data feature is supported + if (GETB(p_cpps_env->features, CPP_FEAT_WHEEL_REV_DATA_SUP)) + { + // Provided parameter in not within the defined range + ind_status = CPP_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 5) + { + // The request can be handled + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_SET_CUMUL_VAL_OP_CODE; + // Cumulative value + p_req_ind->value.cumul_val = co_read32p(&p_param->value[1]); + } + } + } break; + + case (CPP_CTNL_PT_UPD_SENSOR_LOC): + { + // Check if the Multiple Sensor Location feature is supported + if (GETB(p_cpps_env->features, CPP_FEAT_MULT_SENSOR_LOC_SUP)) + { + // Provided parameter in not within the defined range + ind_status = CPP_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 2) + { + // Check the sensor location value + if (p_param->value[1] < CPP_LOC_MAX) + { + // The request can be handled + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_UPD_SENSOR_LOC_OP_CODE; + // Sensor Location + p_req_ind->value.sensor_loc = p_param->value[1]; + } + } + } + } break; + + case (CPP_CTNL_PT_REQ_SUPP_SENSOR_LOC): + { + // Check if the Multiple Sensor Location feature is supported + if (GETB(p_cpps_env->features, CPP_FEAT_MULT_SENSOR_LOC_SUP)) + { + // The request can be handled + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_REQ_SUPP_SENSOR_LOC_OP_CODE; + } + } break; + + case (CPP_CTNL_PT_SET_CRANK_LENGTH): + { + // Check if the Crank Length Adjustment feature is supported + if (GETB(p_cpps_env->features, CPP_FEAT_CRANK_LENGTH_ADJ_SUP)) + { + // Provided parameter in not within the defined range + ind_status = CPP_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 3) + { + // The request can be handled + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_SET_CRANK_LENGTH_OP_CODE; + // Crank Length + p_req_ind->value.crank_length = co_read16p(&p_param->value[1]); + } + } + } break; + + case (CPP_CTNL_PT_REQ_CRANK_LENGTH): + { + // Optional even if feature not supported + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_REQ_CRANK_LENGTH_OP_CODE; + } break; + + case (CPP_CTNL_PT_SET_CHAIN_LENGTH): + { + // Check if the Chain Length Adjustment feature is supported + if (GETB(p_cpps_env->features, CPP_FEAT_CHAIN_LENGTH_ADJ_SUP)) + { + // Provided parameter in not within the defined range + ind_status = CPP_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 3) + { + // The request can be handled + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_SET_CHAIN_LENGTH_OP_CODE; + // Chain Length + p_req_ind->value.crank_length = co_read16p(&p_param->value[1]); + } + } + } break; + + case (CPP_CTNL_PT_REQ_CHAIN_LENGTH): + { + // Optional even if feature not supported + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_REQ_CHAIN_LENGTH_OP_CODE; + } break; + + case (CPP_CTNL_PT_SET_CHAIN_WEIGHT): + { + // Check if the Chain Weight Adjustment feature is supported + if (GETB(p_cpps_env->features, CPP_FEAT_CHAIN_WEIGHT_ADJ_SUP)) + { + // Provided parameter in not within the defined range + ind_status = CPP_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 3) + { + // The request can be handled + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_SET_CHAIN_WEIGHT_OP_CODE; + // Chain Weight + p_req_ind->value.chain_weight = co_read16p(&p_param->value[1]); + } + } + } break; + + case (CPP_CTNL_PT_REQ_CHAIN_WEIGHT): + { + // Optional even if feature not supported + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_REQ_CHAIN_WEIGHT_OP_CODE; + } break; + + case (CPP_CTNL_PT_SET_SPAN_LENGTH): + { + // Check if the Span Length Adjustment feature is supported + if (GETB(p_cpps_env->features, CPP_FEAT_SPAN_LENGTH_ADJ_SUP)) + { + // Provided parameter in not within the defined range + ind_status = CPP_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 3) + { + // The request can be handled + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_SET_SPAN_LENGTH_OP_CODE; + // Span Length + p_req_ind->value.span_length = co_read16p(&p_param->value[1]); + } + } + + } break; + + case (CPP_CTNL_PT_REQ_SPAN_LENGTH): + { + // Optional even if feature not supported + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_REQ_SPAN_LENGTH_OP_CODE; + } break; + + case (CPP_CTNL_PT_START_OFFSET_COMP): + { + // Check if the Offset Compensation feature is supported + if (GETB(p_cpps_env->features, CPP_FEAT_OFFSET_COMP_SUP)) + { + // The request can be handled + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_PT_START_OFFSET_COMP_OP_CODE; + } + } break; + + case (CPP_CTNL_MASK_CP_MEAS_CH_CONTENT): + { + // Check if the CP Masking feature is supported + if (GETB(p_cpps_env->features, CPP_FEAT_CP_MEAS_CH_CONTENT_MASKING_SUP)) + { + // Provided parameter in not within the defined range + ind_status = CPP_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 3) + { + // The request can be handled + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_MASK_CP_MEAS_CH_CONTENT_OP_CODE; + // Mask content + p_req_ind->value.mask_content = co_read16p(&p_param->value[1]); + } + } + } break; + + case (CPP_CTNL_REQ_SAMPLING_RATE): + { + // Optional even if feature not supported + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_REQ_SAMPLING_RATE_OP_CODE; + } break; + + case (CPP_CTNL_REQ_FACTORY_CALIBRATION_DATE): + { + // Optional even if feature not supported + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_REQ_FACTORY_CALIBRATION_DATE_OP_CODE; + } break; + + case (CPP_CTNL_START_ENHANCED_OFFSET_COMP): + { + // Check if the Enhanced Offset Compensation feature is supported + if (GETB(p_cpps_env->features, CPP_FEAT_ENHANCED_OFFSET_COMPENS_SUP)) + { + // The request can be handled + ind_status = CPP_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_cpps_env->operation = CPPS_CTNL_START_ENHANCED_OFFSET_COMP_OP_CODE; + } + } break; + + default: + { + // Operation Code is invalid, status is already CPP_CTNL_PT_RESP_NOT_SUPP + } break; + } + + // If no error raised, inform the application about the request + if (ind_status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Send the request indication to the application + ke_msg_send(p_req_ind); + // Go to the Busy status + ke_state_set(prf_src_task_get(&p_cpps_env->prf_env, conidx), CPPS_BUSY); + } + else + { + // Free the allocated message + ke_msg_free(ke_param2msg(p_req_ind)); + } + + return ind_status; +} + +uint8_t cpps_pack_ctnl_point_cfm (uint8_t conidx, struct cpps_ctnl_pt_cfm *p_param, uint8_t *p_rsp) +{ + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + // Response Length (At least 3) + uint8_t rsp_len = CPP_CP_CNTL_PT_RSP_MIN_LEN; + + // Set the Response Code + p_rsp[0] = CPP_CTNL_PT_RSP_CODE; + // Set the Response Value + p_rsp[2] = (p_param->status > CPP_CTNL_PT_RESP_FAILED) ? CPP_CTNL_PT_RESP_FAILED : p_param->status; + + switch (p_cpps_env->operation) + { + case (CPPS_CTNL_PT_SET_CUMUL_VAL_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_SET_CUMUL_VAL; + + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Save in the environment + p_cpps_env->cumul_wheel_rev = p_param->value.cumul_wheel_rev; + } + } break; + + case (CPPS_CTNL_PT_UPD_SENSOR_LOC_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_UPD_SENSOR_LOC; + + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Store the new value in the environment + p_cpps_env->sensor_loc = p_param->value.sensor_loc; + } + } break; + + case (CPPS_CTNL_PT_REQ_SUPP_SENSOR_LOC_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_REQ_SUPP_SENSOR_LOC; + + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Set the list of supported location + for (uint8_t counter = 0; counter < CPP_LOC_MAX; counter++) + { + if ((p_param->value.supp_sensor_loc >> counter) & 0x0001) + { + p_rsp[rsp_len] = counter; + rsp_len++; + } + } + } + } break; + + case (CPPS_CTNL_PT_SET_CRANK_LENGTH_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_SET_CRANK_LENGTH; + } break; + + case (CPPS_CTNL_PT_REQ_CRANK_LENGTH_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_REQ_CRANK_LENGTH; + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Set the response parameter + co_write16p(&p_rsp[rsp_len], p_param->value.crank_length); + rsp_len += 2; + } + } break; + + case (CPPS_CTNL_PT_SET_CHAIN_LENGTH_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_SET_CHAIN_LENGTH; + } break; + + case (CPPS_CTNL_PT_REQ_CHAIN_LENGTH_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_REQ_CHAIN_LENGTH; + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Set the response parameter + co_write16p(&p_rsp[rsp_len], p_param->value.chain_length); + rsp_len += 2; + } + } break; + + case (CPPS_CTNL_PT_SET_CHAIN_WEIGHT_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_SET_CHAIN_WEIGHT; + } break; + + + case (CPPS_CTNL_PT_REQ_CHAIN_WEIGHT_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_REQ_CHAIN_WEIGHT; + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Set the response parameter + co_write16p(&p_rsp[rsp_len], p_param->value.chain_weight); + rsp_len += 2; + } + } break; + + case (CPPS_CTNL_PT_SET_SPAN_LENGTH_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_SET_SPAN_LENGTH; + } break; + + case (CPPS_CTNL_PT_REQ_SPAN_LENGTH_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_REQ_SPAN_LENGTH; + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Set the response parameter + co_write16p(&p_rsp[rsp_len], p_param->value.span_length); + rsp_len += 2; + } + } break; + + case (CPPS_CTNL_PT_START_OFFSET_COMP_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_PT_START_OFFSET_COMP; + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Set the response parameter + co_write16p(&p_rsp[rsp_len], p_param->value.offset_comp); + rsp_len += 2; + } + } break; + + case (CPPS_CTNL_MASK_CP_MEAS_CH_CONTENT_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_MASK_CP_MEAS_CH_CONTENT; + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + uint16_t cpp_mask_cp_meas_flags [] = + { + CPP_MEAS_PEDAL_POWER_BALANCE_PRESENT_BIT, + CPP_MEAS_ACCUM_TORQUE_PRESENT_BIT, + CPP_MEAS_WHEEL_REV_DATA_PRESENT_BIT, + CPP_MEAS_CRANK_REV_DATA_PRESENT_BIT, + CPP_MEAS_EXTREME_FORCE_MAGNITUDES_PRESENT_BIT | + CPP_MEAS_EXTREME_TORQUE_MAGNITUDES_PRESENT_BIT, + CPP_MEAS_EXTREME_ANGLES_PRESENT_BIT, + CPP_MEAS_TOP_DEAD_SPOT_ANGLE_PRESENT_BIT, + CPP_MEAS_BOTTOM_DEAD_SPOT_ANGLE_PRESENT_BIT, + CPP_MEAS_ACCUM_ENERGY_PRESENT_BIT, + }; + uint16_t mask = 0; + + for (uint8_t count = 0; count < 9; count++) + { + if ((p_param->value.mask_meas_content >> count) & 0x0001) + { + mask |= cpp_mask_cp_meas_flags[count]; + } + } + p_cpps_env->env[conidx].mask_meas_content = mask; + } + } break; + + case (CPPS_CTNL_REQ_SAMPLING_RATE_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_REQ_SAMPLING_RATE; + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Set the response parameter + p_rsp[rsp_len] = p_param->value.sampling_rate; + rsp_len ++; + } + } break; + + case (CPPS_CTNL_REQ_FACTORY_CALIBRATION_DATE_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_REQ_FACTORY_CALIBRATION_DATE; + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Set the response parameter + rsp_len += prf_pack_date_time(&p_rsp[rsp_len], &(p_param->value.factory_calibration)); + } + } break; + + case (CPPS_CTNL_START_ENHANCED_OFFSET_COMP_OP_CODE): + { + // Set the request operation code + p_rsp[1] = CPP_CTNL_START_ENHANCED_OFFSET_COMP; + if (p_param->status == CPP_CTNL_PT_RESP_SUCCESS) + { + // Set the response parameter + // Offset + co_write16p(&p_rsp[rsp_len], p_param->value.enhanced_offset_comp.comp_offset); + rsp_len += 2; + // manufacturer company ID + co_write16p(&p_rsp[rsp_len], p_param->value.enhanced_offset_comp.manu_comp_id); + rsp_len += 2; + // length + p_rsp[rsp_len] = p_param->value.enhanced_offset_comp.length; + rsp_len++; + + // data + if ((p_param->value.enhanced_offset_comp.length > 0) && + (p_param->value.enhanced_offset_comp.length <= CPP_CP_CNTL_PT_RSP_MAX_LEN - rsp_len)) + { + for (int j = 0; j < p_param->value.enhanced_offset_comp.length; j++) + { + p_rsp[rsp_len++] = p_param->value.enhanced_offset_comp.data[j]; + } + } + else + { + return 0; + } + } + // Operation results in an error condition + else + { + if (p_param->value.enhanced_offset_comp.rsp_param == CPP_CTNL_PT_ERR_RSP_PARAM_INCORRECT_CALIB_POS) + { + // Response parameter + p_rsp[rsp_len] = p_param->value.enhanced_offset_comp.rsp_param; + rsp_len++; + } + else if (p_param->value.enhanced_offset_comp.rsp_param == + CPP_CTNL_PT_ERR_RSP_PARAM_MANUF_SPEC_ERR_FOLLOWS) + { + // Response parameter + p_rsp[rsp_len] = p_param->value.enhanced_offset_comp.rsp_param; + rsp_len++; + + // manufacturer company ID + co_write16p(&p_rsp[rsp_len], p_param->value.enhanced_offset_comp.manu_comp_id); + rsp_len += 2; + + // length + p_rsp[rsp_len] = p_param->value.enhanced_offset_comp.length; + rsp_len++; + + // data + if ((p_param->value.enhanced_offset_comp.length > 0) && + (p_param->value.enhanced_offset_comp.length <= CPP_CP_CNTL_PT_RSP_MAX_LEN - rsp_len)) + { + for (int j = 0; j < p_param->value.enhanced_offset_comp.length; j++) + { + p_rsp[rsp_len++] = p_param->value.enhanced_offset_comp.data[j]; + } + } + else + { + return 0; + } + } + else + { + p_rsp[2] = CPP_CTNL_PT_RESP_INV_PARAM; + } + } + } break; + + default: + { + p_rsp[2] = CPP_CTNL_PT_RESP_NOT_SUPP; + } break; + } + + return rsp_len; +} + +void cpps_send_cmp_evt(uint8_t conidx, uint8_t src_id, uint8_t dest_id, uint8_t operation, uint8_t status) +{ + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + struct cpps_cmp_evt *p_evt; + + // Go back to the IDLE if the state is busy + if (ke_state_get(src_id) == CPPS_BUSY) + { + ke_state_set(src_id, CPPS_IDLE); + } + + // Set the operation code + p_cpps_env->operation = CPPS_RESERVED_OP_CODE; + + // Send the message + p_evt = KE_MSG_ALLOC(CPPS_CMP_EVT,dest_id, src_id, cpps_cmp_evt); + + p_evt->conidx = conidx; + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +void cpps_exe_operation(uint8_t conidx) +{ + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + + ASSERT_ERR(p_cpps_env->p_op_data != NULL); + + bool finished = true; + + while ((p_cpps_env->p_op_data->cursor < BLE_CONNECTION_MAX) && finished) + { + uint8_t cursor = p_cpps_env->p_op_data->cursor; + + switch (p_cpps_env->operation) + { + case CPPS_NTF_MEAS_OP_CODE: + { + // notification is pending, send it first + if (p_cpps_env->p_op_data->p_ntf_pending != NULL) + { + ke_msg_send(p_cpps_env->p_op_data->p_ntf_pending); + p_cpps_env->p_op_data->p_ntf_pending = NULL; + finished = false; + } + // Check if sending of notifications has been enabled + else if (GETB(p_cpps_env->env[cursor].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_CP_MEAS_NTF)) + { + struct cpps_ntf_cp_meas_cmd *p_meas_cmd = + (struct cpps_ntf_cp_meas_cmd *) ke_msg2param(p_cpps_env->p_op_data->p_cmd); + + struct gattc_send_evt_cmd *p_meas_val; + + // Save flags value + uint16_t flags = p_meas_cmd->parameters.flags; + + // Mask unwanted fields if supported + if (GETB(p_cpps_env->features, CPP_FEAT_CP_MEAS_CH_CONTENT_MASKING_SUP)) + { + p_meas_cmd->parameters.flags &= ~p_cpps_env->env[cursor].mask_meas_content; + } + + // Allocate the GATT notification message + p_meas_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, cursor), prf_src_task_get(&(p_cpps_env->prf_env),cursor), + gattc_send_evt_cmd, CPP_CP_MEAS_NTF_MAX_LEN); + + // Fill in the parameter structure + p_meas_val->operation = GATTC_NOTIFY; + p_meas_val->handle = CPPS_HANDLE(CPS_IDX_CP_MEAS_VAL); + // pack measured value in database + p_meas_val->length = cpps_pack_meas_ntf(&p_meas_cmd->parameters, p_meas_val->value); + + if (p_meas_val->length > gattc_get_mtu(cursor) - 3) + { + // Split (if necessary) + cpps_split_meas_ntf(cursor, p_meas_val); + } + + // Restore flags value + p_meas_cmd->parameters.flags = flags; + + // Send the event + ke_msg_send(p_meas_val); + + finished = false; + } + // update cursor only if all notification has been sent + if (p_cpps_env->p_op_data->p_ntf_pending == NULL) + { + p_cpps_env->p_op_data->cursor++; + } + } break; + + case CPPS_NTF_VECTOR_OP_CODE: + { + struct cpps_ntf_cp_vector_cmd *p_vector_cmd = + (struct cpps_ntf_cp_vector_cmd *) ke_msg2param(p_cpps_env->p_op_data->p_cmd); + + // Check if sending of notifications has been enabled + if (GETB(p_cpps_env->env[cursor].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_VECTOR_NTF)) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_vector_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, cursor), prf_src_task_get(&(p_cpps_env->prf_env),cursor), + gattc_send_evt_cmd, CPP_CP_VECTOR_MAX_LEN); + + // Fill in the parameter structure + p_vector_val->operation = GATTC_NOTIFY; + p_vector_val->handle = CPPS_HANDLE(CPS_IDX_VECTOR_VAL); + // pack measured value in database + p_vector_val->length = cpps_pack_vector_ntf(&p_vector_cmd->parameters, p_vector_val->value); + + // Send the event + ke_msg_send(p_vector_val); + + finished = false; + } + + p_cpps_env->p_op_data->cursor++; + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + // check if operation is finished + if (finished) + { + // Inform the application that a procedure has been completed + cpps_send_cmp_evt(conidx, + prf_src_task_get(&p_cpps_env->prf_env, conidx), + prf_dst_task_get(&p_cpps_env->prf_env, conidx), + p_cpps_env->operation, GAP_ERR_NO_ERROR); + + // free operation data + ke_msg_free(p_cpps_env->p_op_data->p_cmd); + ke_free(p_cpps_env->p_op_data); + p_cpps_env->p_op_data = NULL; + // Set the operation code + p_cpps_env->operation = CPPS_RESERVED_OP_CODE; + // go back to idle state + ke_state_set(prf_src_task_get(&(p_cpps_env->prf_env), 0), CPPS_IDLE); + } +} + +#endif //(BLE_CP_SENSOR) + +/// @} CPPS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/src/cpps.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/src/cpps.h new file mode 100644 index 0000000..698f236 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/src/cpps.h @@ -0,0 +1,372 @@ +/** + **************************************************************************************** + * + * @file cpps.h + * + * @brief Header file - Cycling Power Profile Sensor. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CPPS_H_ +#define _CPPS_H_ + +/** + **************************************************************************************** + * @addtogroup CPPS Cycling Power Profile Sensor + * @ingroup CPP + * @brief Cycling Power Profile Sensor + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "cpp_common.h" + +#if (BLE_CP_SENSOR) + +#include "prf_types.h" +#include "prf.h" +#include "cpps_task.h" +#include "attm.h" +#include "co_math.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/* + * DEFINES + **************************************************************************************** + */ +/// Maximum number of Cycling Power Profile Sensor role task instances +#define CPPS_IDX_MAX 1 + +/******************************************** + ******* CPPS Configuration Flag Masks ****** + ********************************************/ + +/// Mandatory Attributes (CP Measurement + CP Feature + CP Sensor Location) +#define CPPS_MANDATORY_MASK (0x01EF) +/// Broadcast Attribute +#define CPPS_MEAS_BCST_MASK (0x0010) +/// Vector Attributes +#define CPPS_VECTOR_MASK (0x0E00) +/// Control Point Attributes +#define CPPS_CTNL_PT_MASK (0x7000) + +/// Broadcast supported flag +#define CPPS_BROADCASTER_SUPP_FLAG (0x01) +/// Control Point supported flag +#define CPPS_CTNL_PT_CHAR_SUPP_FLAG (0x02) + + +/* + * MACROS + **************************************************************************************** + */ + +/// Check if a specific characteristic has been added in the database (according to mask) +#define CPPS_IS_FEATURE_SUPPORTED(features, flag) ((features & flag) == flag) + +/// MACRO TO CALCULATE HANDLE shdl + idx - BCST - VECTOR +/// BCST is 1 if the broadcast mode is supported otherwise 0 +/// VECTOR is 3 if the Vector characteristic is supported otherwise 0 +#define CPPS_HANDLE(idx) \ + (p_cpps_env->shdl + (idx) - \ + ((!(CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_MEAS_BCST_MASK)) && \ + ((idx) > CPS_IDX_CP_MEAS_BCST_CFG))? (1) : (0)) - \ + ((!(CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_VECTOR_MASK)) && \ + ((idx) > CPS_IDX_VECTOR_CHAR))? (3) : (0))) + +/// Get database attribute index +#define CPPS_IDX(hdl) \ + ((hdl - p_cpps_env->shdl) + \ + ((!(CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_MEAS_BCST_MASK)) && \ + ((hdl - p_cpps_env->shdl) > CPS_IDX_CP_MEAS_BCST_CFG)) ? (1) : (0)) + \ + ((!(CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_VECTOR_MASK)) && \ + ((hdl - p_cpps_env->shdl) > CPS_IDX_VECTOR_CHAR)) ? (3) : (0))) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the CPPS task +enum cpps_state +{ + /// Idle state + CPPS_IDLE, + /// Busy state + CPPS_BUSY, + + /// Number of defined states. + CPPS_STATE_MAX +}; +/// Cycling Power Service - Attribute List +enum cpps_cps_att_list +{ + /// Cycling Power Service + CPS_IDX_SVC, + /// CP Measurement + CPS_IDX_CP_MEAS_CHAR, + CPS_IDX_CP_MEAS_VAL, + CPS_IDX_CP_MEAS_NTF_CFG, + CPS_IDX_CP_MEAS_BCST_CFG, + /// CP Feature + CPS_IDX_CP_FEAT_CHAR, + CPS_IDX_CP_FEAT_VAL, + /// Sensor Location + CPS_IDX_SENSOR_LOC_CHAR, + CPS_IDX_SENSOR_LOC_VAL, + /// CP Vector + CPS_IDX_VECTOR_CHAR, + CPS_IDX_VECTOR_VAL, + CPS_IDX_VECTOR_NTF_CFG, + /// CP Control Point + CPS_IDX_CTNL_PT_CHAR, + CPS_IDX_CTNL_PT_VAL, + CPS_IDX_CTNL_PT_IND_CFG, + + /// Number of attributes + CPS_IDX_NB, +}; + +/// Profile Configuration Additional Flags () +enum cpps_prf_cfg_flag_bf +{ + /// CP Measurement - Client Char. Cfg + CPP_PRF_CFG_FLAG_CP_MEAS_NTF_POS = 0, + CPP_PRF_CFG_FLAG_CP_MEAS_NTF_BIT = CO_BIT(CPP_PRF_CFG_FLAG_CP_MEAS_NTF_POS), + + /// CP Measurement - Server Char. Cfg + CPP_PRF_CFG_FLAG_SP_MEAS_NTF_POS = 1, + CPP_PRF_CFG_FLAG_SP_MEAS_NTF_BIT = CO_BIT(CPP_PRF_CFG_FLAG_SP_MEAS_NTF_POS), + + /// CP Vector - Client Characteristic configuration + CPP_PRF_CFG_FLAG_VECTOR_NTF_POS = 2, + CPP_PRF_CFG_FLAG_VECTOR_NTF_BIT = CO_BIT(CPP_PRF_CFG_FLAG_VECTOR_NTF_POS), + + /// Control Point - Client Characteristic configuration + CPP_PRF_CFG_FLAG_CTNL_PT_IND_POS = 3, + CPP_PRF_CFG_FLAG_CTNL_PT_IND_BIT = CO_BIT(CPP_PRF_CFG_FLAG_CTNL_PT_IND_POS), + + /// Bonded data used + CPP_PRF_CFG_PERFORMED_OK_POS = 4, + CPP_PRF_CFG_PERFORMED_OK_BIT = CO_BIT(CPP_PRF_CFG_PERFORMED_OK_POS), +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// ongoing operation information +struct cpps_op +{ + /// On-going operation command + struct ke_msg *p_cmd; + /// notification pending + struct gattc_send_evt_cmd *p_ntf_pending; + + /// Cursor on connection + uint8_t cursor; +}; + +/// Cycling Power Profile Sensor environment variable per connection +struct cpps_cnx_env +{ + /// Measurement content mask + uint16_t mask_meas_content; + /// Profile Notify/Indication Flags + uint8_t prfl_ntf_ind_cfg; +}; + +/// Cycling Power Profile Sensor environment variable +struct cpps_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct cpps_cnx_env env[BLE_CONNECTION_MAX]; + /// On-going operation + struct cpps_op *p_op_data; + + /// Feature Configuration Flags + uint32_t features; + + /// Instantaneous Power + uint32_t inst_power; + /// Cumulative Value + uint32_t cumul_wheel_rev; + + /// Cycling Speed and Cadence Service Start Handle + uint16_t shdl; + /// Profile Configuration Flags + uint16_t prfl_cfg; + /// Operation + uint8_t operation; + + /// Sensor Location + uint8_t sensor_loc; + + /// State of different task instances + ke_state_t state[CPPS_IDX_MAX]; + + /// Broadcast advertisements are active + bool broadcast_enabled; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Retrieve CPP service profile interface + * + * @return CPP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *cpps_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Packs measurement notifications + * @param[in] p_param Pointer to the parameters of the message. + * @param[out] p_pckd_meas pointer to packed message + * @return status of the operation + **************************************************************************************** + */ +uint8_t cpps_pack_meas_ntf(struct cpp_cp_meas *p_param, uint8_t *p_pckd_meas); + +/** + **************************************************************************************** + * @brief Splits notifications in order to be sent with default MTU + * @param[in] conidx connection index + * @param[out] p_meas_val message to split + * @return length of the second notification + **************************************************************************************** + */ +uint8_t cpps_split_meas_ntf(uint8_t conidx, struct gattc_send_evt_cmd *p_meas_val); + +/** + **************************************************************************************** + * @brief updates the environment with the descriptor configuration and sends indication + * @param[in] conidx connection index + * @param[in] prfl_config profile descriptor code + * @param[in] p_param pointer to the message parameters + * @return status of the operation + **************************************************************************************** + */ +uint8_t cpps_update_characteristic_config(uint8_t conidx, uint8_t prfl_config, + struct gattc_write_req_ind const *p_param); + +/** + **************************************************************************************** + * @brief Packs vector notifications + * @param[in] p_param Pointer to the parameters of the message. + * @param[out] p_pckd_vector pointer to packed message + * @return length + **************************************************************************************** + */ +uint8_t cpps_pack_vector_ntf(struct cpp_cp_vector *p_param, uint8_t *p_pckd_vector); + +/** + **************************************************************************************** + * @brief Unpack control point and sends indication + * @param[in] conidx connection index + * @param[in] p_param pointer to message + * @return status of the operation + **************************************************************************************** + */ +uint8_t cpps_unpack_ctnl_point_ind (uint8_t conidx, struct gattc_write_req_ind const *p_param); + +/** + **************************************************************************************** + * @brief Packs control point + * @param[in] conidx connection index + * @param[in] p_param Pointer to the parameters of the message. + * @param[out] p_rsp pointer to message + * @return status of the operation + **************************************************************************************** + */ +uint8_t cpps_pack_ctnl_point_cfm (uint8_t conidx, struct cpps_ctnl_pt_cfm *p_param, uint8_t *p_rsp); + +/** + **************************************************************************************** + * @brief Update database in non discovery modes + * @param[in] conidx connection index + * @param[in] con_type Connection type + * @param[in] handle handle + * @param[in] ntf_cfg provided flag + * @param[in] cfg_flag requested flag + * @return status of the operation + **************************************************************************************** + */ +int cpps_update_cfg_char_value (uint8_t conidx, uint8_t con_type, uint8_t handle, uint16_t ntf_cfg, uint16_t cfg_flag); + +/** + **************************************************************************************** + * @brief Send a CPPS_CMP_EVT message to the application. + * @param[in] conidx connection index + * @param[in] src_id Source task + * @param[in] dest_id Destination task + * @param[in] operation Operation completed + * @param[in] status status of the operation + **************************************************************************************** + */ +void cpps_send_cmp_evt(uint8_t conidx, uint8_t src_id, uint8_t dest_id, uint8_t operation, uint8_t status); + +/** + **************************************************************************************** + * @brief Send a control point response to the peer + * @param[in] conidx connection index + * @param[in] req_op_code operation code + * @param[in] status status of the operation + **************************************************************************************** + */ +void cpps_send_rsp_ind(uint8_t conidx, uint8_t req_op_code, uint8_t status); + +/** + **************************************************************************************** + * @brief This function fully manages notification of measurement and vector + * @param[in] conidx connection index + **************************************************************************************** + */ +void cpps_exe_operation(uint8_t conidx); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void cpps_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_CP_SENSOR) + +/// @} CPPS + +#endif //(_CPPS_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/src/cpps_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/src/cpps_task.c new file mode 100644 index 0000000..dd6f132 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cpp/cpps/src/cpps_task.c @@ -0,0 +1,799 @@ +/** + **************************************************************************************** + * + * @file cpps_task.c + * + * @brief Cycling Power Profile Sensor Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup CPPSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include "rwip_config.h" +#if (BLE_CP_SENSOR) +#include "cpp_common.h" + +#include "gapc.h" +#include "gattc.h" +#include "gattc_task.h" +#include "cpps.h" +#include "cpps_task.h" +#include "prf_utils.h" +#include "co_math.h" + +#include "ke_mem.h" +#include "co_utils.h" + + +/* + * CYCLING POWER SERVICE ATTRIBUTES + **************************************************************************************** + */ + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPS_ENABLE_REQ message. + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int cpps_enable_req_handler(ke_msg_id_t const msgid, + struct cpps_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + struct cpps_enable_rsp *p_cmp_evt; + + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (ke_state_get(dest_id) == CPPS_IDLE) + { + // Bonded data was not used before + if (!GETB(p_cpps_env->env[p_param->conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_PERFORMED_OK)) + { + status = GAP_ERR_NO_ERROR; + // Save configuration and set flag + p_cpps_env->env[p_param->conidx].prfl_ntf_ind_cfg = p_param->prfl_ntf_ind_cfg; + // Enable Bonded Data + SETB(p_cpps_env->env[p_param->conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_PERFORMED_OK, 1); + } + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(CPPS_ENABLE_RSP, src_id, dest_id, cpps_enable_rsp); + + p_cmp_evt->status = status; + p_cmp_evt->conidx = p_param->conidx; + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPS_GET_ADV_DATA_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int cpps_get_adv_data_req_handler(ke_msg_id_t const msgid, + struct cpps_get_adv_data_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + + // State shall not be Connected or Busy + if (ke_state_get(dest_id) == CPPS_IDLE) + { + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + // Allocate the message + struct cpps_get_adv_data_rsp *p_rsp = KE_MSG_ALLOC_DYN(CPPS_GET_ADV_DATA_RSP, + src_id, dest_id, + cpps_get_adv_data_rsp, CPP_CP_MEAS_ADV_MAX_LEN); + + // Set status + p_rsp->status = GAP_ERR_COMMAND_DISALLOWED; + // Set length + p_rsp->data_len = 0; + + // Check Broadcast is supported + if (CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_MEAS_BCST_MASK)) + { + // Check if broadcast has been enabled + if (p_cpps_env->broadcast_enabled) + { + // Pack Cp Measurement + p_rsp->adv_data[0] = cpps_pack_meas_ntf(&p_param->parameters, + &p_rsp->adv_data[4]) + CPP_CP_ADV_HEADER_LEN; + // Pack Service Data AD type + p_rsp->adv_data[1] = GAP_AD_TYPE_SERVICE_16_BIT_DATA; + // Pack UUID of CPS + co_write16p(&p_rsp->adv_data[2], ATT_SVC_CYCLING_POWER); + + // Set data length + p_rsp->data_len = p_rsp->adv_data[0] + CPP_CP_ADV_LENGTH_LEN; + // Set status + p_rsp->status = GAP_ERR_NO_ERROR; + } + } + + // Send message + ke_msg_send(p_rsp); + } + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPS_NTF_CP_MEAS_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int cpps_ntf_cp_meas_cmd_handler(ke_msg_id_t const msgid, + struct cpps_ntf_cp_meas_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_NO_FREE; + + // State shall not be Connected or Busy + if (ke_state_get(dest_id) == CPPS_IDLE) + { + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + + // Configure the environment + p_cpps_env->operation = CPPS_NTF_MEAS_OP_CODE; + // allocate operation data + p_cpps_env->p_op_data = (struct cpps_op *) ke_malloc(sizeof(struct cpps_op), KE_MEM_KE_MSG); + p_cpps_env->p_op_data->p_cmd = ke_param2msg(p_param); + p_cpps_env->p_op_data->cursor = 0; + p_cpps_env->p_op_data->p_ntf_pending = NULL; + + // Go to busy state + ke_state_set(dest_id, CPPS_BUSY); + + // Should be updated just once + if (GETB(p_param->parameters.flags, CPP_MEAS_WHEEL_REV_DATA_PRESENT)) + { + if (GETB(p_cpps_env->features, CPP_FEAT_WHEEL_REV_DATA_SUP)) + { + // Update the cumulative wheel revolutions value stored in the environment + // The value shall not decrement below zero + if (p_param->parameters.cumul_wheel_rev < 0) + { + p_cpps_env->cumul_wheel_rev = + (co_abs(p_param->parameters.cumul_wheel_rev) > p_cpps_env->cumul_wheel_rev) ? + 0 : (p_cpps_env->cumul_wheel_rev + p_param->parameters.cumul_wheel_rev); + } + else + { + p_cpps_env->cumul_wheel_rev += p_param->parameters.cumul_wheel_rev; + } + } + } + + // start operation execution + cpps_exe_operation(KE_IDX_GET(src_id)); + } + else + { + // Save it for later + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPS_NTF_CP_VECTOR_CMDREQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int cpps_ntf_cp_vector_cmd_handler(ke_msg_id_t const msgid, + struct cpps_ntf_cp_vector_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + + // State shall be Connected or Busy + if (ke_state_get(dest_id) == CPPS_IDLE) + { + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + + // Check Vector characteristic is supported + if (CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_VECTOR_MASK)) + { + // Configure the environment + p_cpps_env->operation = CPPS_NTF_VECTOR_OP_CODE; + // allocate operation data + p_cpps_env->p_op_data = (struct cpps_op *) ke_malloc(sizeof(struct cpps_op), KE_MEM_KE_MSG); + p_cpps_env->p_op_data->p_cmd = ke_param2msg(p_param); + p_cpps_env->p_op_data->cursor = 0; + p_cpps_env->p_op_data->p_ntf_pending = NULL; + + // Go to busy state + ke_state_set(dest_id, CPPS_BUSY); + // start operation execution + cpps_exe_operation(conidx); + + msg_status = KE_MSG_NO_FREE; + } + else + { + // send response to requester + cpps_send_cmp_evt(conidx, + prf_src_task_get(&p_cpps_env->prf_env, conidx), + prf_dst_task_get(&p_cpps_env->prf_env, conidx), + p_cpps_env->operation, PRF_ERR_FEATURE_NOT_SUPPORTED); + } + } + else + { + // Keep the message for later + msg_status = KE_MSG_SAVED; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + uint8_t conidx = KE_IDX_GET(src_id); + // Message status + int msg_status = KE_MSG_CONSUMED; + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Control Point Status + uint8_t ctl_pt_status = CPP_CTNL_PT_RESP_SUCCESS; + + if (p_cpps_env != NULL) + { + // CP Measurement Characteristic, Client Characteristic Configuration Descriptor + if (p_param->handle == (CPPS_HANDLE(CPS_IDX_CP_MEAS_NTF_CFG))) + { + // Update value + status = cpps_update_characteristic_config(conidx, CPP_PRF_CFG_FLAG_CP_MEAS_NTF_BIT, p_param); + } + // CP Measurement Characteristic, Server Characteristic Configuration Descriptor + else if (p_param->handle == (CPPS_HANDLE(CPS_IDX_CP_MEAS_BCST_CFG))) + { + if (CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_MEAS_BCST_MASK)) + { + // Save value + status = cpps_update_characteristic_config(conidx, CPP_PRF_CFG_FLAG_SP_MEAS_NTF_BIT, p_param); + } + else + { + status = ATT_ERR_ATTRIBUTE_NOT_FOUND; + } + } + // CP Vector Characteristic, Client Characteristic Configuration Descriptor + else if (p_param->handle == (CPPS_HANDLE(CPS_IDX_VECTOR_NTF_CFG))) + { + if (CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_VECTOR_MASK)) + { + // Update value + status = cpps_update_characteristic_config(conidx, CPP_PRF_CFG_FLAG_VECTOR_NTF_BIT, p_param); + } + else + { + status = ATT_ERR_ATTRIBUTE_NOT_FOUND; + } + } + // CP Control Point Characteristic + else + { + if (CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_CTNL_PT_MASK)) + { + // CP Control Point, Client Characteristic Configuration Descriptor + if (p_param->handle == (CPPS_HANDLE(CPS_IDX_CTNL_PT_IND_CFG))) + { + // Update value + status = cpps_update_characteristic_config(conidx, CPP_PRF_CFG_FLAG_CTNL_PT_IND_BIT, p_param); + } + // CP Control Point Characteristic + else if (p_param->handle == (CPPS_HANDLE(CPS_IDX_CTNL_PT_VAL))) + { + do + { + // Check if sending of indications has been enabled + if (!GETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_CTNL_PT_IND)) + { + // CPP improperly configured + status = PRF_CCCD_IMPR_CONFIGURED; + break; + } + + if (p_cpps_env->operation >= CPPS_CTNL_PT_SET_CUMUL_VAL_OP_CODE) + { + // A procedure is already in progress + status = CPP_ERROR_PROC_IN_PROGRESS; + break; + } + + if (p_cpps_env->operation == CPPS_NTF_MEAS_OP_CODE) + { + // Keep the message until the end of the current procedure + msg_status = KE_MSG_NO_FREE; + break; + } + // Unpack Control Point parameters + ctl_pt_status = cpps_unpack_ctnl_point_ind (conidx, p_param); + + } while (0); + } + else + { + ASSERT_ERR(0); + } + } + else + { + status = ATT_ERR_ATTRIBUTE_NOT_FOUND; + } + } + + // Vector confirmation is sent by calling cpps_vector_cfg_cfm_handler + if (p_param->handle != (CPPS_HANDLE(CPS_IDX_VECTOR_NTF_CFG))) + { + //Send write response + struct gattc_write_cfm *p_cfm = KE_MSG_ALLOC( + GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + + // Check if control point failed + if ((p_param->handle == (CPPS_HANDLE(CPS_IDX_CTNL_PT_VAL))) && + (ctl_pt_status != CPP_CTNL_PT_RESP_SUCCESS)) + { + // Send response to peer + cpps_send_rsp_ind(conidx, p_param->value[0], ctl_pt_status); + } + } + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CPPS_IDLE) + { + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + uint8_t att_idx = CPPS_IDX(p_param->handle); + struct gattc_att_info_cfm *p_cfm; + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + // check if it's a client configuration char + if ((att_idx == CPS_IDX_CP_MEAS_NTF_CFG) + || (att_idx == CPS_IDX_CP_MEAS_BCST_CFG) + || (att_idx == CPS_IDX_VECTOR_NTF_CFG) + || (att_idx == CPS_IDX_CTNL_PT_IND_CFG)) + { + // CCC attribute length = 2 + p_cfm->length = 2; + p_cfm->status = GAP_ERR_NO_ERROR; + } + + else if (att_idx == CPS_IDX_CTNL_PT_VAL) + { + // force length to zero to reject any write starting from something != 0 + p_cfm->length = 0; + p_cfm->status = GAP_ERR_NO_ERROR; + } + // not expected request + else + { + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } + + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CPPS_IDLE) + { + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t att_idx = CPPS_IDX(p_param->handle); + + uint8_t value[4]; + uint8_t value_size = 0; + uint8_t status = ATT_ERR_NO_ERROR; + struct gattc_read_cfm *p_cfm; + + switch (att_idx) + { + case CPS_IDX_CP_MEAS_NTF_CFG: + { + value_size = sizeof(uint16_t); + co_write16p(value, GETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_CP_MEAS_NTF) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } break; + + case CPS_IDX_CP_MEAS_BCST_CFG: + { + // Broadcast feature is profile specific + if (CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_MEAS_BCST_MASK)) + { + // Fill data + value_size = sizeof(uint16_t); + // Broadcast status is also masked per connection (useful for bonding data) + co_write16p(value, GETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_SP_MEAS_NTF) + ? PRF_SRV_START_BCST : PRF_SRV_STOP_BCST); + } + else + { + status = ATT_ERR_ATTRIBUTE_NOT_FOUND; + } + } break; + + case CPS_IDX_VECTOR_NTF_CFG: + { + // Fill data + value_size = sizeof(uint16_t); + co_write16p(value, GETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_VECTOR_NTF) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } break; + + case CPS_IDX_CTNL_PT_IND_CFG: + { + // Fill data + value_size = sizeof(uint16_t); + co_write16p(value, GETB(p_cpps_env->env[conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_CTNL_PT_IND) + ? PRF_CLI_START_IND : PRF_CLI_STOP_NTFIND); + } break; + + case CPS_IDX_CP_FEAT_VAL: + { + // Fill data + value_size = sizeof(uint32_t); + co_write32p(value, p_cpps_env->features); + } break; + + case CPS_IDX_SENSOR_LOC_VAL: + { + // Fill data + value_size = sizeof(uint8_t); + value[0] = p_cpps_env->sensor_loc; + } break; + + default: + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + // Send data to peer device + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, value_size); + + p_cfm->length = value_size; + memcpy(p_cfm->value, value, value_size); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPS_VECTOR_CFG_CFM message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int cpps_vector_cfg_cfm_handler(ke_msg_id_t const msgid, + struct cpps_vector_cfg_cfm *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CPPS_IDLE) + { + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + // Status + uint8_t status = PRF_APP_ERROR; + struct gattc_write_cfm *p_cfm; + + if (p_param->status == GAP_ERR_NO_ERROR) + { + if (p_param->ntf_cfg == PRF_CLI_STOP_NTFIND) + { + SETB(p_cpps_env->env[p_param->conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_VECTOR_NTF, 0); + status = GAP_ERR_NO_ERROR; + } + else if (p_param->ntf_cfg == PRF_CLI_START_NTF) + { + SETB(p_cpps_env->env[p_param->conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_VECTOR_NTF, 1); + status = GAP_ERR_NO_ERROR; + } + } + + // Send write response + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, KE_BUILD_ID(TASK_GATTC, p_param->conidx), dest_id, gattc_write_cfm); + p_cfm->handle = CPPS_HANDLE(CPS_IDX_VECTOR_NTF_CFG); + p_cfm->status = status; + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CPPS_CTNL_PT_CFM message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int cpps_ctnl_pt_cfm_handler(ke_msg_id_t const msgid, + struct cpps_ctnl_pt_cfm *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CPPS_BUSY) + { + uint8_t status = GAP_ERR_NO_ERROR; + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + + do + { + struct gattc_send_evt_cmd *p_ctl_pt_rsp; + + // Check the current operation + if (p_cpps_env->operation < CPPS_CTNL_PT_SET_CUMUL_VAL_OP_CODE) + { + // The confirmation has been sent without request indication, ignore + break; + } + + // The CP Control Point Characteristic must be supported if we are here + if (!CPPS_IS_FEATURE_SUPPORTED(p_cpps_env->prfl_cfg, CPPS_CTNL_PT_MASK)) + { + status = PRF_ERR_REQ_DISALLOWED; + break; + } + + // Check if sending of indications has been enabled + if (!GETB(p_cpps_env->env[p_param->conidx].prfl_ntf_ind_cfg, CPP_PRF_CFG_FLAG_CTNL_PT_IND)) + { + // CPP improperly configured + status = PRF_CCCD_IMPR_CONFIGURED; + break; + } + + // Allocate the GATT notification message + p_ctl_pt_rsp = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, p_param->conidx), dest_id, + gattc_send_evt_cmd, CPP_CP_CNTL_PT_RSP_MAX_LEN); + + // Fill in the p_parameter structure + p_ctl_pt_rsp->operation = GATTC_INDICATE; + p_ctl_pt_rsp->handle = CPPS_HANDLE(CPS_IDX_CTNL_PT_VAL); + // Pack Control Point confirmation + p_ctl_pt_rsp->length = cpps_pack_ctnl_point_cfm(p_param->conidx, p_param, p_ctl_pt_rsp->value); + + // Send the event + ke_msg_send(p_ctl_pt_rsp); + + } while (0); + + if (status != GAP_ERR_NO_ERROR) + { + // Inform the application that a procedure has been completed + cpps_send_cmp_evt(p_param->conidx, + prf_src_task_get(&p_cpps_env->prf_env, p_param->conidx), + prf_dst_task_get(&p_cpps_env->prf_env, p_param->conidx), + p_cpps_env->operation, status); + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATT_NOTIFY_CMP_EVT message meaning that a notification or an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + + // Check if a connection exists + if (ke_state_get(dest_id) == CPPS_BUSY) + { + switch (p_param->operation) + { + case (GATTC_NOTIFY): + { + // On-going operation execution + cpps_exe_operation(conidx); + } break; + + case (GATTC_INDICATE): + { + ASSERT_INFO(p_cpps_env->operation >= CPPS_CTNL_PT_SET_CUMUL_VAL_OP_CODE, 0, 0); + + // Inform the application that a procedure has been completed + cpps_send_cmp_evt(conidx, + prf_src_task_get(&p_cpps_env->prf_env, conidx), + prf_dst_task_get(&p_cpps_env->prf_env, conidx), + p_cpps_env->operation, p_param->status); + // else ignore the message + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(cpps) +{ + {CPPS_ENABLE_REQ, (ke_msg_func_t) cpps_enable_req_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {CPPS_GET_ADV_DATA_REQ, (ke_msg_func_t) cpps_get_adv_data_req_handler}, + {CPPS_NTF_CP_MEAS_CMD, (ke_msg_func_t) cpps_ntf_cp_meas_cmd_handler}, + {CPPS_NTF_CP_VECTOR_CMD, (ke_msg_func_t) cpps_ntf_cp_vector_cmd_handler}, + {CPPS_CTNL_PT_CFM, (ke_msg_func_t) cpps_ctnl_pt_cfm_handler}, + {CPPS_VECTOR_CFG_CFM, (ke_msg_func_t) cpps_vector_cfg_cfm_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +void cpps_task_init(struct ke_task_desc *task_desc) +{ + // Get the address of the environment + struct cpps_env_tag *p_cpps_env = PRF_ENV_GET(CPPS, cpps); + + task_desc->msg_handler_tab = cpps_msg_handler_tab; + task_desc->msg_cnt = ARRAY_LEN(cpps_msg_handler_tab); + task_desc->state = p_cpps_env->state; + task_desc->idx_max = CPPS_IDX_MAX; +} + +#endif //(BLE_CSC_SENSOR) + +/// @} CPPSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscp_common.h new file mode 100644 index 0000000..d6d057a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscp_common.h @@ -0,0 +1,233 @@ +/** + **************************************************************************************** + * + * @file cscp_common.h + * + * @brief Header File - Cycling Speed and Cadence Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +#ifndef _CSCP_COMMON_H_ +#define _CSCP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup CSCP Cycling Speed and Cadence Profile + * @ingroup PROFILE + * @brief Cycling Speed and Cadence Profile + * + * The Cycling Speed and Cadence profile enables a Collector device to connect and + * interact with a Cycling Speed and Cadence Sensor for use in sports and fitness + * applications. + * + * This file contains all definitions that are common for the server and the client parts + * of the profile. + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ +/// Procedure Already in Progress Error Code +#define CSCP_ERROR_PROC_IN_PROGRESS (0x80) +/// Client Characteristic Configuration descriptor improperly configured Error Code +#define CSCP_ERROR_CCC_INVALID_PARAM (0x81) + +/// CSC Measurement Value Min Length +#define CSCP_CSC_MEAS_MIN_LEN (1) +/// CSC Measurement Value Max Length +#define CSCP_CSC_MEAS_MAX_LEN (11) +/// SC Control Point Request Value Min Length +#define CSCP_SC_CNTL_PT_REQ_MIN_LEN (1) +/// SC Control Point Request Value Max Length +#define CSCP_SC_CNTL_PT_REQ_MAX_LEN (5) +/// SC Control Point Response Value Min Length +#define CSCP_SC_CNTL_PT_RSP_MIN_LEN (3) +/// SC Control Point Response Value Max Length +#define CSCP_SC_CNTL_PT_RSP_MAX_LEN (CSCP_SC_CNTL_PT_RSP_MIN_LEN + CSCP_LOC_MAX) + +/// CSC Measurement Flags All present +#define CSCP_MEAS_ALL_PRESENT (0x03) + +/// CSC Feature Flags All supported +#define CSCP_FEAT_ALL_SUPP (0x0007) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Cycling Speed and Cadence Service Characteristics +enum cscp_cscs_char +{ + /// CSC Measurement + CSCP_CSCS_CSC_MEAS_CHAR, + /// CSC Feature + CSCP_CSCS_CSC_FEAT_CHAR, + /// Sensor Location + CSCP_CSCS_SENSOR_LOC_CHAR, + /// SC Control Point + CSCP_CSCS_SC_CTNL_PT_CHAR, + + CSCP_CSCS_CHAR_MAX, +}; + +/// CSC Measurement Flags bit field +enum cscp_meas_flags_bf +{ + /// Wheel Revolution Data Present + CSCP_MEAS_WHEEL_REV_DATA_PRESENT_POS = 0, + CSCP_MEAS_WHEEL_REV_DATA_PRESENT_BIT = CO_BIT(CSCP_MEAS_WHEEL_REV_DATA_PRESENT_POS), + + /// Crank Revolution Data Present + CSCP_MEAS_CRANK_REV_DATA_PRESENT_POS = 1, + CSCP_MEAS_CRANK_REV_DATA_PRESENT_BIT = CO_BIT(CSCP_MEAS_CRANK_REV_DATA_PRESENT_POS), +}; + +/// CSC Feature Flags bit field +enum cscp_feat_flags_bf +{ + /// Wheel Revolution Data Supported + CSCP_FEAT_WHEEL_REV_DATA_SUPP_POS = 0, + CSCP_FEAT_WHEEL_REV_DATA_SUPP_BIT = CO_BIT(CSCP_FEAT_WHEEL_REV_DATA_SUPP_POS), + + /// Crank Revolution Data Supported + CSCP_FEAT_CRANK_REV_DATA_SUPP_POS = 1, + CSCP_FEAT_CRANK_REV_DATA_SUPP_BIT = CO_BIT(CSCP_FEAT_CRANK_REV_DATA_SUPP_POS), + + /// Multiple Sensor Location Supported + CSCP_FEAT_MULT_SENSOR_LOC_SUPP_POS = 2, + CSCP_FEAT_MULT_SENSOR_LOC_SUPP_BIT = CO_BIT(CSCP_FEAT_MULT_SENSOR_LOC_SUPP_POS), +}; + +/// Sensor Locations Keys +enum cscp_sensor_loc +{ + /// Other (0) + CSCP_LOC_OTHER = 0, + /// Front Wheel (4) + CSCP_LOC_FRONT_WHEEL = 4, + /// Left Crank (5) + CSCP_LOC_LEFT_CRANK, + /// Right Crank (6) + CSCP_LOC_RIGHT_CRANK, + /// Left Pedal (7) + CSCP_LOC_LEFT_PEDAL, + /// Right Pedal (8) + CSCP_LOC_RIGHT_PEDAL, + /// Rear Dropout (9) + CSCP_LOC_REAR_DROPOUT, + /// Chainstay (10) + CSCP_LOC_CHAINSTAY, + /// Front Hub (11) + CSCP_LOC_FRONT_HUB, + /// Rear Wheel (12) + CSCP_LOC_REAR_WHEEL, + /// Rear Hub (13) + CSCP_LOC_REAR_HUB, + + CSCP_LOC_MAX, +}; + +/// Control Point Operation Code Keys +enum cscp_sc_ctnl_pt_op_code +{ + /// Reserved value + CSCP_CTNL_PT_OP_RESERVED = 0, + + /// Set Cumulative Value + CSCP_CTNL_PT_OP_SET_CUMUL_VAL, + /// Start Sensor Calibration + CSCP_CTNL_PT_OP_START_CALIB, + /// Update Sensor Location + CSCP_CTNL_PT_OP_UPD_LOC, + /// Request Supported Sensor Locations + CSCP_CTNL_PT_OP_REQ_SUPP_LOC, + + /// Response Code + CSCP_CTNL_PT_RSP_CODE = 16, +}; + +/// Control Point Response Value +enum cscp_ctnl_pt_resp_val +{ + /// Reserved value + CSCP_CTNL_PT_RESP_RESERVED = 0, + + /// Success + CSCP_CTNL_PT_RESP_SUCCESS, + /// Operation Code Not Supported + CSCP_CTNL_PT_RESP_NOT_SUPP, + /// Invalid Parameter + CSCP_CTNL_PT_RESP_INV_PARAM, + /// Operation Failed + CSCP_CTNL_PT_RESP_FAILED, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// CSC Measurement +struct cscp_csc_meas +{ + /// Flags + uint8_t flags; + /// Cumulative Crank Revolution + uint16_t cumul_crank_rev; + /// Last Crank Event Time + uint16_t last_crank_evt_time; + /// Last Wheel Event Time + uint16_t last_wheel_evt_time; + /// Cumulative Wheel Revolution + uint32_t cumul_wheel_rev; +}; + +/// SC Control Point Request +struct cscp_sc_ctnl_pt_req +{ + /// Operation Code + uint8_t op_code; + /// Value + union cscp_sc_ctnl_pt_req_val + { + /// Sensor Location + uint8_t sensor_loc; + /// Cumulative value + uint32_t cumul_val; + } value; +}; + +/// SC Control Point Response +struct cscp_sc_ctnl_pt_rsp +{ + /// Control Point Op code + uint8_t cp_opcode; + /// Requested Operation Code + uint8_t req_op_code; + /// Response Value + uint8_t resp_value; + /// List of supported locations + uint16_t supp_loc; +}; + +/// @} cscp_common + +#endif //(_CSCP_COMMON_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/api/cscpc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/api/cscpc_task.h new file mode 100644 index 0000000..bb3dc64 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/api/cscpc_task.h @@ -0,0 +1,214 @@ +/** + **************************************************************************************** + * + * @file cscpc_task.h + * + * @brief Header file - Cycling Speed and Cadence Profile Collector Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CSCPC_TASK_H_ +#define _CSCPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup CSCPCTASK Cycling Speed and Cadence Profile Collector Task + * @ingroup CSCPC + * @brief Cycling Speed and Cadence Profile Collector Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "cscp_common.h" + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Message IDs +/*@TRACE*/ +enum cscpc_msg_ids +{ + /// Enable the Cycling Speed and Cadence Profile Collector task - at connection + CSCPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_CSCPC), + /// Enable the Cycling Speed and Cadence Profile Collector task - at connection + CSCPC_ENABLE_RSP, + + /// Read the value of an attribute in the peer device database + CSCPC_READ_CMD, + + /// Configure sending of notification or indication + CSCPC_CFG_NTFIND_CMD, + + /// Configure the SC Control Point value + CSCPC_CTNL_PT_CFG_CMD, + /// SC Control Point value response + CSCPC_CTNL_PT_IND, + + /// Indicate that an attribute value has been received either upon notification or read response + CSCPC_VALUE_IND, + + /// Complete Event Information + CSCPC_CMP_EVT, + + /// Procedure Timeout Timer + CSCPC_TIMEOUT_TIMER_IND, +}; + +/// Operation Codes +enum cscpc_op_codes +{ + /// Reserved operation code + CSCPC_RESERVED_OP_CODE = 0x00, + + /// Read attribute value Procedure + CSCPC_READ_OP_CODE, + + /// Wait for the Write Response after having written a Client Char. Cfg. Descriptor. + CSCPC_CFG_NTF_IND_OP_CODE, + /// Wait for the Write Response after having written the SC Control Point Char. + CSCPC_CTNL_PT_CFG_WR_OP_CODE, + /// Wait for the Indication Response after having written the SC Control Point Char. + CSCPC_CTNL_PT_CFG_IND_OP_CODE, +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ + +/// Cycling Speed and Cadence Service Characteristic Descriptors +enum cscpc_cscs_descs +{ + /// CSC Measurement Char. - Client Characteristic Configuration + CSCPC_DESC_CSC_MEAS_CL_CFG, + /// SC Control Point Char. - Client Characteristic Configuration + CSCPC_DESC_SC_CTNL_PT_CL_CFG, + + CSCPC_DESC_MAX, + + CSCPC_DESC_MASK = 0x10, +}; + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Cycling Speed and Cadence Service + */ +struct cscpc_cscs_content +{ + /// Service info + struct prf_svc svc; + + /// Characteristic info: + /// - CSC Measurement + /// - CSC Feature + /// - Sensor Location + /// - SC Control Point + struct prf_char_inf chars[CSCP_CSCS_CHAR_MAX]; + + /// Descriptor handles: + /// - CSC Measurement Client Cfg + /// - SC Control Point Client Cfg + struct prf_char_desc_inf descs[CSCPC_DESC_MAX]; +}; + +/// Parameters of the @ref CSCPC_ENABLE_REQ message +struct cscpc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values CSCS + struct cscpc_cscs_content cscs; +}; + +/// Parameters of the @ref CSCPC_ENABLE_RSP message +struct cscpc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values CPS + struct cscpc_cscs_content cscs; +}; + +/// Parameters of the @ref CSCPC_READ_CMD message +struct cscpc_read_cmd +{ + /// Operation Code + uint8_t operation; + /// Read code + uint8_t read_code; +}; + +/// Parameters of the @ref CSCPC_CFG_NTFIND_CMD message +struct cscpc_cfg_ntfind_cmd +{ + /// Operation Code + uint8_t operation; + /// Descriptor code + uint8_t desc_code; + /// Ntf/Ind Configuration + uint16_t ntfind_cfg; +}; + +/// Parameters of the @ref CSCPC_CTNL_PT_CFG_CMD message +struct cscpc_ctnl_pt_cfg_cmd +{ + /// Operation Code + uint8_t operation; + /// SC Control Point Request + struct cscp_sc_ctnl_pt_req sc_ctnl_pt; +}; + +/// Parameters of the @ref CSCPC_CTNL_PT_IND message +struct cscpc_ctnl_pt_ind +{ + /// SC Control Point Response + struct cscp_sc_ctnl_pt_rsp ctnl_pt_rsp; +}; + + +/// Parameters of the @ref CSCPC_VALUE_IND message +struct cscpc_value_ind +{ + /// Attribute Code + uint8_t att_code; + /// Value + union cscpc_value_tag + { + /// CSC Measurement + struct cscp_csc_meas csc_meas; + /// CSC Feature + uint16_t sensor_feat; + /// Sensor Location + uint8_t sensor_loc; + /// Client Characteristic Configuration Descriptor Value + uint16_t ntf_cfg; + } value; +}; + +/// Parameters of the @ref CSCPC_CMP_EVT message +struct cscpc_cmp_evt +{ + /// Operation code + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} CSCPCTASK + +#endif //(_CSCPC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/sourcelist.txt new file mode 100644 index 0000000..9de5186 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + cscpc.c + cscpc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/src/cscpc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/src/cscpc.c new file mode 100644 index 0000000..fde686c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/src/cscpc.c @@ -0,0 +1,257 @@ +/** + **************************************************************************************** + * + * @file cscpc.c + * + * @brief Cycling Speed and Cadence Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup CSCPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_CSC_COLLECTOR) +#include "cscp_common.h" + +#include "cscpc.h" +#include "cscpc_task.h" +#include "ke_timer.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLES DECLARATION + **************************************************************************************** + */ + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the CSCPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t cscpc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct cscpc_env_tag* p_cscpc_env = + (struct cscpc_env_tag* ) ke_malloc(sizeof(struct cscpc_env_tag), KE_MEM_ATT_DB); + + // allocate CSCPC required environment variable + p_env->env = (prf_env_t*) p_cscpc_env; + + p_cscpc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_cscpc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_CSCPC; + cscpc_task_init(&(p_env->desc)); + + for (idx = 0; idx < CSCPC_IDX_MAX ; idx++) + { + p_cscpc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), CSCPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void cscpc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct cscpc_env_tag *p_cscpc_env = (struct cscpc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_cscpc_env->p_env[conidx] != NULL) + { + if (p_cscpc_env->p_env[conidx]->p_operation != NULL) + { + ke_free(ke_param2msg(p_cscpc_env->p_env[conidx]->p_operation)); + } + + ke_timer_clear(CSCPC_TIMEOUT_TIMER_IND, prf_src_task_get(&p_cscpc_env->prf_env, conidx)); + + ke_free(p_cscpc_env->p_env[conidx]); + p_cscpc_env->p_env[conidx] = NULL; + } + + // Put CSCP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), CSCPC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the CSCPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void cscpc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct cscpc_env_tag *p_cscpc_env = (struct cscpc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < CSCPC_IDX_MAX; idx++) + { + cscpc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_cscpc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void cscpc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put CSCP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), CSCPC_IDLE); +} + +/// CSCPC Task interface required by profile manager +const struct prf_task_cbs cscpc_itf = +{ + cscpc_init, + cscpc_destroy, + cscpc_create, + cscpc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* cscpc_prf_itf_get(void) +{ + return &cscpc_itf; +} + + +void cscpc_enable_rsp_send(struct cscpc_env_tag *p_cscpc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on CSCPS + struct cscpc_enable_rsp *p_rsp = KE_MSG_ALLOC( + CSCPC_ENABLE_RSP, + prf_dst_task_get(&(p_cscpc_env->prf_env), conidx), + prf_src_task_get(&(p_cscpc_env->prf_env), conidx), + cscpc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->cscs = p_cscpc_env->p_env[conidx]->cscs; + // Register CSCPC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_cscpc_env->prf_env), conidx, &(p_cscpc_env->p_env[conidx]->cscs.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_cscpc_env->prf_env), conidx), CSCPC_IDLE); + } + + ke_msg_send(p_rsp); +} + +void cscpc_send_no_conn_cmp_evt(uint8_t src_id, uint8_t dest_id, uint8_t operation) +{ + // Send the message + struct cscpc_cmp_evt *p_evt = KE_MSG_ALLOC(CSCPC_CMP_EVT, + dest_id, src_id, + cscpc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = PRF_ERR_REQ_DISALLOWED; + + ke_msg_send(p_evt); +} + +void cscpc_send_cmp_evt(struct cscpc_env_tag *p_cscpc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct cscpc_cmp_evt *p_evt; + + // Free the stored operation if needed + if (p_cscpc_env->p_env[conidx]->p_operation != NULL) + { + ke_msg_free(ke_param2msg(p_cscpc_env->p_env[conidx]->p_operation)); + p_cscpc_env->p_env[conidx]->p_operation = NULL; + } + + // Go back to the CONNECTED state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_cscpc_env->prf_env), conidx)) == CSCPC_BUSY) + { + ke_state_set(prf_src_task_get(&(p_cscpc_env->prf_env), conidx), CSCPC_IDLE); + } + + // Send the message + p_evt = KE_MSG_ALLOC(CSCPC_CMP_EVT, + prf_dst_task_get(&(p_cscpc_env->prf_env), conidx), + prf_src_task_get(&(p_cscpc_env->prf_env), conidx), + cscpc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //(BLE_CSC_COLLECTOR) + +/// @} CSCP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/src/cscpc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/src/cscpc.h new file mode 100644 index 0000000..55a22e9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/src/cscpc.h @@ -0,0 +1,199 @@ +/** + **************************************************************************************** + * + * @file cscpc.h + * + * @brief Header file - Cycling Speed and Cadence Status Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CSCPC_H_ +#define _CSCPC_H_ + +/** + **************************************************************************************** + * @addtogroup CSCPC Cycling Speed and Cadence Profile Collector + * @ingroup CSCP + * @brief Cycling Speed and Cadence Profile Collector + * @{ + **************************************************************************************** + */ + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Cycling Speed and Cadence Collector task instances +#define CSCPC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_CSC_COLLECTOR) + +#include "cscpc_task.h" +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the CSCPC task +enum cscpc_states +{ + /// Idle state + CSCPC_FREE, + /// Connected state + CSCPC_IDLE, + /// Discovery + CSCPC_DISCOVERING, + /// Busy state + CSCPC_BUSY, + + /// Number of defined states. + CSCPC_STATE_MAX +}; + + +/// Internal codes for reading/writing a CSCS characteristic with one single request +enum cscpc_codes +{ + /// Notified CSC Measurement + CSCPC_NTF_CSC_MEAS = CSCP_CSCS_CSC_MEAS_CHAR, + /// Read CSC Feature + CSCPC_RD_CSC_FEAT = CSCP_CSCS_CSC_FEAT_CHAR, + /// Read Sensor Location + CSCPC_RD_SENSOR_LOC = CSCP_CSCS_SENSOR_LOC_CHAR, + /// Indicated SC Control Point + CSCPC_IND_SC_CTNL_PT = CSCP_CSCS_SC_CTNL_PT_CHAR, + + /// Read/Write CSC Measurement Client Char. Configuration Descriptor + CSCPC_RD_WR_CSC_MEAS_CFG = (CSCPC_DESC_CSC_MEAS_CL_CFG | CSCPC_DESC_MASK), + /// Read SC Control Point Client Char. Configuration Descriptor + CSCPC_RD_WR_SC_CTNL_PT_CFG = (CSCPC_DESC_SC_CTNL_PT_CL_CFG | CSCPC_DESC_MASK), +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +struct cscpc_cnx_env +{ + /// Current Operation + void *p_operation; + ///Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Counter used to check service uniqueness + uint8_t nb_svc; + /// Cycling Speed and Cadence Service Characteristics + struct cscpc_cscs_content cscs; +}; + + +/// Cycling Speed and Cadence Profile Collector environment variable +struct cscpc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct cscpc_cnx_env *p_env[CSCPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[CSCPC_IDX_MAX]; +}; + +/// Command Message Basic Structure +struct cscpc_cmd +{ + /// Operation Code + uint8_t operation; + + /// MORE DATA +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve CSCP client profile interface + * + * @return CSCP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* cscpc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send CSCP ATT DB discovery results to CSCPC host. + * + * @param p_cscpc_env CSC Profile Client Role task environment + * @param conidx Connection index + * @param status Response status code + **************************************************************************************** + */ +void cscpc_enable_rsp_send(struct cscpc_env_tag *p_cscpc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send a CSCPC_CMP_EVT message when no connection exists (no environment) + * + * @param src_id Source ID + * @param dst_id Destination ID + * @param operation Operation code + ***************************************************************************************** + */ +void cscpc_send_no_conn_cmp_evt(uint8_t src_id, uint8_t dest_id, uint8_t operation); + +/** + **************************************************************************************** + * @brief Send a CSCPC_CMP_EVT message to the task which enabled the profile + * + * @param[in] p_cscpc_env CSCP Client environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void cscpc_send_cmp_evt(struct cscpc_env_tag *p_cscpc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void cscpc_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_CSC_COLLECTOR) + +/// @} CSCPC + +#endif //(_CSCPC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/src/cscpc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/src/cscpc_task.c new file mode 100644 index 0000000..c61714f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscpc/src/cscpc_task.c @@ -0,0 +1,969 @@ +/** + **************************************************************************************** + * + * @file cscpc_task.c + * + * @brief Cycling Speed and Cadence Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup CSCPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_CSC_COLLECTOR) +#include "cscp_common.h" +#include "cscpc_task.h" +#include "cscpc.h" + +#include "gap.h" +#include "gattc_task.h" + +#include "ke_timer.h" +#include "ke_mem.h" +#include "co_utils.h" + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve Cycling Speed and Cadence service characteristics information +const struct prf_char_def cscpc_cscs_char[CSCP_CSCS_CHAR_MAX] = +{ + // CSC Measurement + [CSCP_CSCS_CSC_MEAS_CHAR] = {ATT_CHAR_CSC_MEAS, + ATT_MANDATORY, + ATT_CHAR_PROP_NTF}, + // CSC Feature + [CSCP_CSCS_CSC_FEAT_CHAR] = {ATT_CHAR_CSC_FEAT, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, + // Sensor Location + [CSCP_CSCS_SENSOR_LOC_CHAR] = {ATT_CHAR_SENSOR_LOC, + ATT_OPTIONAL, + ATT_CHAR_PROP_RD}, + // SC Control Point + [CSCP_CSCS_SC_CTNL_PT_CHAR] = {ATT_CHAR_SC_CNTL_PT, + ATT_OPTIONAL, + ATT_CHAR_PROP_WR | ATT_CHAR_PROP_IND}, +}; + +/// State machine used to retrieve Cycling Speed and Cadence service characteristic descriptor information +const struct prf_char_desc_def cscpc_cscs_char_desc[CSCPC_DESC_MAX] = +{ + // CSC Measurement Char. - Client Characteristic Configuration + [CSCPC_DESC_CSC_MEAS_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + CSCP_CSCS_CSC_MEAS_CHAR}, + + // SC Control Point Char. - Client Characteristic Configuration + [CSCPC_DESC_SC_CTNL_PT_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_OPTIONAL, + CSCP_CSCS_SC_CTNL_PT_CHAR}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CSCPC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct cscpc_env_tag *p_cscpc_env = PRF_ENV_GET(CSCPC, cscpc); + + ASSERT_INFO(p_cscpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_cscpc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_cscpc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve CSCS characteristics and descriptors + prf_extract_svc_info(p_ind, CSCP_CSCS_CHAR_MAX, &cscpc_cscs_char[0], + &p_cscpc_env->p_env[conidx]->cscs.chars[0], + CSCPC_DESC_MAX, &cscpc_cscs_char_desc[0], + &p_cscpc_env->p_env[conidx]->cscs.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_cscpc_env->p_env[conidx]->cscs.svc.shdl = p_ind->start_hdl; + p_cscpc_env->p_env[conidx]->cscs.svc.ehdl = p_ind->end_hdl; + } + + p_cscpc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CSCPC_ENABLE_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cscpc_enable_req_handler(ke_msg_id_t const msgid, + struct cscpc_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + uint8_t state = ke_state_get(dest_id); + // Cycling Speed and Cadence Profile Collector Role Task Environment + struct cscpc_env_tag *p_cscpc_env = PRF_ENV_GET(CSCPC, cscpc); + + ASSERT_INFO(p_cscpc_env != NULL, dest_id, src_id); + if ((state == CSCPC_IDLE) && (p_cscpc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_cscpc_env->p_env[conidx] = (struct cscpc_cnx_env *) ke_malloc(sizeof(struct cscpc_cnx_env), KE_MEM_ATT_DB); + memset(p_cscpc_env->p_env[conidx], 0, sizeof(struct cscpc_cnx_env)); + + // Start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + prf_disc_svc_send(&(p_cscpc_env->prf_env), conidx, ATT_SVC_CYCLING_SPEED_CADENCE); + + // Go to DISCOVERING state + ke_state_set(dest_id, CSCPC_DISCOVERING); + } + // Bond information are provided + else + { + p_cscpc_env->p_env[conidx]->cscs = p_param->cscs; + + //send APP confirmation that can start normal connection to TH + cscpc_enable_rsp_send(p_cscpc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != CSCPC_FREE) + { + // The message will be forwarded towards the good task instance + status = PRF_ERR_REQ_DISALLOWED; + } + + if (status != GAP_ERR_NO_ERROR) + { + // The request is disallowed (profile already enabled for this connection, or not enough memory, ...) + cscpc_enable_rsp_send(p_cscpc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CSCPC_READ_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cscpc_read_cmd_handler(ke_msg_id_t const msgid, + struct cscpc_read_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct cscpc_env_tag *p_cscpc_env = PRF_ENV_GET(CSCPC, cscpc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == CSCPC_IDLE) + { + ASSERT_INFO(p_cscpc_env != NULL, dest_id, src_id); + // environment variable not ready + if(p_cscpc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + + switch (p_param->read_code) + { + // Read CSC Feature + case (CSCPC_RD_CSC_FEAT): + { + handle = p_cscpc_env->p_env[conidx]->cscs.chars[CSCP_CSCS_CSC_FEAT_CHAR].val_hdl; + } break; + + // Read Sensor Location + case (CSCPC_RD_SENSOR_LOC): + { + handle = p_cscpc_env->p_env[conidx]->cscs.chars[CSCP_CSCS_SENSOR_LOC_CHAR].val_hdl; + } break; + + // Read CSC Measurement Characteristic Client Char. Cfg. Descriptor Value + case (CSCPC_RD_WR_CSC_MEAS_CFG): + { + handle = p_cscpc_env->p_env[conidx]->cscs.descs[CSCPC_DESC_CSC_MEAS_CL_CFG].desc_hdl; + } break; + + // Read Unread Alert Characteristic Client Char. Cfg. Descriptor Value + case (CSCPC_RD_WR_SC_CTNL_PT_CFG): + { + handle = p_cscpc_env->p_env[conidx]->cscs.descs[CSCPC_DESC_SC_CTNL_PT_CL_CFG].desc_hdl; + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + // Check if handle is viable + if (handle != ATT_INVALID_SEARCH_HANDLE) + { + // Force the operation value + p_param->operation = CSCPC_READ_OP_CODE; + + // Store the command structure + p_cscpc_env->p_env[conidx]->p_operation = p_param; + msg_status = KE_MSG_NO_FREE; + + // Send the read request + prf_read_char_send(&(p_cscpc_env->prf_env), conidx, + p_cscpc_env->p_env[conidx]->cscs.svc.shdl, + p_cscpc_env->p_env[conidx]->cscs.svc.ehdl, + handle); + + // Go to the Busy state + ke_state_set(dest_id, CSCPC_BUSY); + + status = ATT_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + + else if (state == CSCPC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send the complete event message to the task id stored in the environment + cscpc_send_cmp_evt(p_cscpc_env, conidx, CSCPC_READ_OP_CODE, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CSCPC_CFG_NTFIND_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cscpc_cfg_ntfind_cmd_handler(ke_msg_id_t const msgid, + struct cscpc_cfg_ntfind_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cscpc_env_tag *p_cscpc_env = PRF_ENV_GET(CSCPC, cscpc); + + // Message status + int msg_status = KE_MSG_CONSUMED; + + if (p_cscpc_env != NULL) + { + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + do + { + if (ke_state_get(dest_id) != CSCPC_IDLE) + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + // Status is GAP_ERR_NO_ERROR, no message will be sent to the application + break; + } + + // state = CSCPC_CONNECTED + ASSERT_ERR(p_cscpc_env->p_env[conidx] != NULL); + + switch(p_param->desc_code) + { + // Write CSC Measurement Characteristic Client Char. Cfg. Descriptor Value + case (CSCPC_RD_WR_CSC_MEAS_CFG): + { + if (p_param->ntfind_cfg <= PRF_CLI_START_NTF) + { + handle = p_cscpc_env->p_env[conidx]->cscs.descs[CSCPC_DESC_CSC_MEAS_CL_CFG].desc_hdl; + // The descriptor is mandatory + ASSERT_ERR(handle != ATT_INVALID_SEARCH_HANDLE); + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write SC Control Point Characteristic Client Char. Cfg. Descriptor Value + case (CSCPC_RD_WR_SC_CTNL_PT_CFG): + { + if ((p_param->ntfind_cfg == PRF_CLI_STOP_NTFIND) || + (p_param->ntfind_cfg == PRF_CLI_START_IND)) + { + handle = p_cscpc_env->p_env[conidx]->cscs.descs[CSCPC_DESC_SC_CTNL_PT_CL_CFG].desc_hdl; + + status = GAP_ERR_NO_ERROR; + if (handle == ATT_INVALID_SEARCH_HANDLE) + { + // The descriptor has not been found. + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + } while (0); + + if ((status == GAP_ERR_NO_ERROR) && (handle != ATT_INVALID_SEARCH_HANDLE)) + { + // Set the operation code + p_param->operation = CSCPC_CFG_NTF_IND_OP_CODE; + + // Store the command structure + p_cscpc_env->p_env[conidx]->p_operation = p_param; + msg_status = KE_MSG_NO_FREE; + + // Go to the Busy state + ke_state_set(dest_id, CSCPC_BUSY); + + // Send GATT Write Request + prf_gatt_write_ntf_ind(&p_cscpc_env->prf_env, conidx, handle, p_param->ntfind_cfg); + } + } + else + { + cscpc_send_no_conn_cmp_evt(dest_id, src_id, CSCPC_CFG_NTF_IND_OP_CODE); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CSCPC_CFG_NTFIND_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cscpc_ctnl_pt_cfg_cmd_handler(ke_msg_id_t const msgid, + struct cscpc_ctnl_pt_cfg_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct cscpc_env_tag *p_cscpc_env = PRF_ENV_GET(CSCPC, cscpc); + + if (p_cscpc_env != NULL) + { + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + do + { + // State is Connected or Busy + ASSERT_ERR(ke_state_get(dest_id) > CSCPC_FREE); + + // Check the provided connection handle + if (p_cscpc_env->p_env[conidx] == NULL) + { + status = PRF_ERR_INVALID_PARAM; + break; + } + + if (ke_state_get(dest_id) != CSCPC_IDLE) + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_NO_FREE; + // Status is GAP_ERR_NO_ERROR, no message will be sent to the application + break; + } + + // Check if the characteristic has been found + if (p_cscpc_env->p_env[conidx]->cscs.descs[CSCPC_DESC_SC_CTNL_PT_CL_CFG].desc_hdl + != ATT_INVALID_SEARCH_HANDLE) + { + // Packed request + uint8_t req[CSCP_SC_CNTL_PT_REQ_MAX_LEN]; + // Request Length + uint8_t req_len = CSCP_SC_CNTL_PT_REQ_MIN_LEN; + + // Set the operation code + req[0] = p_param->sc_ctnl_pt.op_code; + + // Fulfill the message according to the operation code + switch (p_param->sc_ctnl_pt.op_code) + { + case (CSCP_CTNL_PT_OP_SET_CUMUL_VAL): + { + // Set the cumulative value + co_write32p(&req[req_len], p_param->sc_ctnl_pt.value.cumul_val); + // Update length + req_len += 4; + } break; + + case (CSCP_CTNL_PT_OP_UPD_LOC): + { + // Set the sensor location + req[req_len] = p_param->sc_ctnl_pt.value.sensor_loc; + // Update length + req_len++; + } break; + + case (CSCP_CTNL_PT_OP_RESERVED): + case (CSCP_CTNL_PT_OP_START_CALIB): + case (CSCP_CTNL_PT_OP_REQ_SUPP_LOC): + { + // Nothing more to do + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + if (status == GAP_ERR_NO_ERROR) + { + // Set the operation code + p_param->operation = CSCPC_CTNL_PT_CFG_WR_OP_CODE; + + // Store the command structure + p_cscpc_env->p_env[conidx]->p_operation = p_param; + // Store the command information + msg_status = KE_MSG_NO_FREE; + + // Go to the Busy state + ke_state_set(dest_id, CSCPC_BUSY); + + // Send the write request + prf_gatt_write(&(p_cscpc_env->prf_env), conidx, + p_cscpc_env->p_env[conidx]->cscs.chars[CSCP_CSCS_SC_CTNL_PT_CHAR].val_hdl, + (uint8_t *)&req[0], req_len, GATTC_WRITE); + } + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } while (0); + + if (status != GAP_ERR_NO_ERROR) + { + // Send a complete event status to the application + cscpc_send_cmp_evt(p_cscpc_env, conidx, CSCPC_CTNL_PT_CFG_WR_OP_CODE, status); + } + } + else + { + // No connection + cscpc_send_no_conn_cmp_evt(dest_id, src_id, CSCPC_CTNL_PT_CFG_WR_OP_CODE); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CSCPC_TIMEOUT_TIMER_IND message. This message is + * received when the peer device doesn't send a SC Control Point indication within 30s + * after reception of the write response. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cscpc_timeout_timer_ind_handler(ke_msg_id_t const msgid, + void const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cscpc_env_tag *p_cscpc_env = PRF_ENV_GET(CSCPC, cscpc); + + if (p_cscpc_env != NULL) + { + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_ERR(p_cscpc_env->p_env[conidx]->p_operation != NULL); + ASSERT_ERR(((struct cscpc_cmd *)p_cscpc_env->p_env[conidx]->p_operation)->operation == + CSCPC_CTNL_PT_CFG_IND_OP_CODE); + + // Send the complete event message + cscpc_send_cmp_evt(p_cscpc_env, conidx, CSCPC_CTNL_PT_CFG_WR_OP_CODE, PRF_ERR_PROC_TIMEOUT); + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cscpc_env_tag *p_cscpc_env = PRF_ENV_GET(CSCPC, cscpc); + + + if (p_cscpc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == CSCPC_DISCOVERING) + { + // Status + uint8_t status = p_param->status; + + if ((status == ATT_ERR_ATTRIBUTE_NOT_FOUND) || + (status == ATT_ERR_NO_ERROR)) + { + // Discovery + // check characteristic validity + if(p_cscpc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(CSCP_CSCS_CHAR_MAX, + p_cscpc_env->p_env[conidx]->cscs.chars, + cscpc_cscs_char); + } + // too much services + else if (p_cscpc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(CSCPC_DESC_MAX, + p_cscpc_env->p_env[conidx]->cscs.descs, + cscpc_cscs_char_desc, + p_cscpc_env->p_env[conidx]->cscs.chars); + } + } + + cscpc_enable_rsp_send(p_cscpc_env, conidx, status); + } + + else if (state == CSCPC_BUSY) + { + switch (p_param->operation) + { + case GATTC_READ: + { + // Send the complete event status + cscpc_send_cmp_evt(p_cscpc_env, conidx, CSCPC_READ_OP_CODE, p_param->status); + } break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + uint8_t operation = ((struct cscpc_cmd *)p_cscpc_env->p_env[conidx]->p_operation)->operation; + + if (operation == CSCPC_CFG_NTF_IND_OP_CODE) + { + // Send the complete event status + cscpc_send_cmp_evt(p_cscpc_env, conidx, operation, p_param->status); + } + + else if (operation == CSCPC_CTNL_PT_CFG_WR_OP_CODE) + { + if (p_param->status == GAP_ERR_NO_ERROR) + { + // Start Timeout Procedure + ke_timer_set(CSCPC_TIMEOUT_TIMER_IND, dest_id, 10*ATT_TRANS_RTX); + + // Wait for the response indication + ((struct cscpc_cmd *)p_cscpc_env->p_env[conidx]->p_operation)->operation = + CSCPC_CTNL_PT_CFG_IND_OP_CODE; + } + else + { + // Send the complete event status + cscpc_send_cmp_evt(p_cscpc_env, conidx, operation, p_param->status); + } + } + } break; + + case GATTC_REGISTER: + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CSCPC_BUSY) + { + // Get the address of the environment + struct cscpc_env_tag *p_cscpc_env = PRF_ENV_GET(CSCPC, cscpc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_cscpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_cscpc_env->p_env[conidx] != NULL, dest_id, src_id); + + // Send the read value to the HL + struct cscpc_value_ind *p_ind = KE_MSG_ALLOC(CSCPC_VALUE_IND, + prf_dst_task_get(&(p_cscpc_env->prf_env), conidx), + dest_id, + cscpc_value_ind); + + switch (((struct cscpc_read_cmd *)p_cscpc_env->p_env[conidx]->p_operation)->read_code) + { + // Read CSC Feature Characteristic value + case (CSCPC_RD_CSC_FEAT): + { + // Mask the reserved bits + p_ind->value.sensor_feat = co_read16p(p_param->value); + } break; + + // Read Sensor Location Characteristic value + case (CSCPC_RD_SENSOR_LOC): + { + p_ind->value.sensor_loc = p_param->value[0]; + } break; + + // Read Client Characteristic Configuration Descriptor value + case (CSCPC_RD_WR_CSC_MEAS_CFG): + case (CSCPC_RD_WR_SC_CTNL_PT_CFG): + { + co_write16p(&p_ind->value.ntf_cfg, p_param->value[0]); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + p_ind->att_code = ((struct cscpc_read_cmd *)p_cscpc_env->p_env[conidx]->p_operation)->read_code; + + // Send the message to the application + ke_msg_send(p_ind); + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct cscpc_env_tag *p_cscpc_env = PRF_ENV_GET(CSCPC, cscpc); + + if (p_cscpc_env != NULL) + { + switch (p_param->type) + { + case (GATTC_NOTIFY): + { + // Offset + uint8_t offset = CSCP_CSC_MEAS_MIN_LEN; + + // CSC Measurement value has been received + struct cscpc_value_ind *p_ind = KE_MSG_ALLOC(CSCPC_VALUE_IND, + prf_dst_task_get(&(p_cscpc_env->prf_env), conidx), + prf_src_task_get(&(p_cscpc_env->prf_env), conidx), + cscpc_value_ind); + // Attribute code + p_ind->att_code = CSCPC_NTF_CSC_MEAS; + + /*---------------------------------------------------- + * Unpack Measurement -------------------------------- + *----------------------------------------------------*/ + + // Flags + p_ind->value.csc_meas.flags = p_param->value[0]; + + // Cumulative Wheel Revolutions + // Last Wheel Event Time + if (GETB(p_param->value[0], CSCP_MEAS_WHEEL_REV_DATA_PRESENT)) + { + // Cumulative Wheel Revolutions + p_ind->value.csc_meas.cumul_wheel_rev = co_read32p(&p_param->value[offset]); + offset += 4; + + // Last Wheel Event Time + p_ind->value.csc_meas.last_wheel_evt_time = co_read16p(&p_param->value[offset]); + offset += 2; + } + + // Cumulative Crank Revolutions + // Last Crank Event Time + if (GETB(p_param->value[0], CSCP_MEAS_CRANK_REV_DATA_PRESENT)) + { + // Cumulative Crank Revolutions + p_ind->value.csc_meas.cumul_crank_rev = co_read16p(&p_param->value[offset]); + offset += 2; + + // Last Crank Event Time + p_ind->value.csc_meas.last_crank_evt_time = co_read16p(&p_param->value[offset]); + } + + ke_msg_send(p_ind); + } break; + + case (GATTC_INDICATE): + { + // confirm that indication has been correctly received + struct gattc_event_cfm *p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + + do + { + struct cscpc_ctnl_pt_ind *p_ind; + + // Check if we were waiting for the indication + if (p_cscpc_env->p_env[conidx]->p_operation == NULL) + { + break; + } + + if (((struct cscpc_cmd *)p_cscpc_env->p_env[conidx]->p_operation)->operation + != CSCPC_CTNL_PT_CFG_IND_OP_CODE) + { + break; + } + + // Stop the procedure timeout timer + ke_timer_clear(CSCPC_TIMEOUT_TIMER_IND, dest_id); + + // CSC Measurement value has been received + p_ind = KE_MSG_ALLOC(CSCPC_CTNL_PT_IND, + prf_dst_task_get(&(p_cscpc_env->prf_env), conidx), + prf_src_task_get(&(p_cscpc_env->prf_env), conidx), + cscpc_ctnl_pt_ind); + + p_ind->ctnl_pt_rsp.cp_opcode = p_param->value[0]; + // Requested operation code + p_ind->ctnl_pt_rsp.req_op_code = p_param->value[1]; + // Response value + p_ind->ctnl_pt_rsp.resp_value = p_param->value[2]; + + // Get the list of supported sensor locations if needed + if ((p_ind->ctnl_pt_rsp.req_op_code == CSCP_CTNL_PT_OP_REQ_SUPP_LOC) && + (p_ind->ctnl_pt_rsp.resp_value == CSCP_CTNL_PT_RESP_SUCCESS) && + (p_param->length > 3)) + { + // Get the number of supported locations that have been received + uint8_t nb_supp_loc = (p_param->length - 3); + // Counter + uint8_t counter; + // Location + uint8_t loc; + + for (counter = 0; counter < nb_supp_loc; counter++) + { + loc = p_param->value[counter + 3]; + + // Check if valid + if (loc < CSCP_LOC_MAX) + { + p_ind->ctnl_pt_rsp.supp_loc |= (1 << loc); + } + } + } + + // Send the message + ke_msg_send(p_ind); + + // Send the complete event message + cscpc_send_cmp_evt(p_cscpc_env, conidx, CSCPC_CTNL_PT_CFG_WR_OP_CODE, GAP_ERR_NO_ERROR); + + } while (0); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(cscpc) +{ + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {CSCPC_ENABLE_REQ, (ke_msg_func_t)cscpc_enable_req_handler}, + {CSCPC_READ_CMD, (ke_msg_func_t)cscpc_read_cmd_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {CSCPC_CFG_NTFIND_CMD, (ke_msg_func_t)cscpc_cfg_ntfind_cmd_handler}, + {CSCPC_CTNL_PT_CFG_CMD, (ke_msg_func_t)cscpc_ctnl_pt_cfg_cmd_handler}, + {CSCPC_TIMEOUT_TIMER_IND, (ke_msg_func_t)cscpc_timeout_timer_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void cscpc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct cscpc_env_tag *p_cscpc_env = PRF_ENV_GET(CSCPC, cscpc); + + p_task_desc->msg_handler_tab = cscpc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(cscpc_msg_handler_tab); + p_task_desc->state = p_cscpc_env->state; + p_task_desc->idx_max = CSCPC_IDX_MAX; +} + +#endif //(BLE_CSC_COLLECTOR) + +/// @} CSCPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/api/cscps_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/api/cscps_task.h new file mode 100644 index 0000000..04cbc83 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/api/cscps_task.h @@ -0,0 +1,212 @@ +/** + **************************************************************************************** + * + * @file cscps_task.h + * + * @brief Header file - Cycling Speed and Cadence Profile Sensor Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CSCPS_TASK_H_ +#define _CSCPS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup CSCPSTASK Task + * @ingroup CSCPS + * @brief Cycling Speed and Cadence Profile Task. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "cscp_common.h" +#include +#include "rwip_task.h" // Task definitions + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Messages for Cycling Speed and Cadence Profile Sensor +/*@TRACE*/ +enum cscps_msg_id +{ + /// Enable the CSCP Sensor task for a connection + CSCPS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_CSCPS), + /// Enable the CSCP Sensor task for a connection + CSCPS_ENABLE_RSP, + + /// Send a CSC Measurement to the peer device (Notification) + CSCPS_NTF_CSC_MEAS_CMD, + + /// Indicate that the SC Control Point characteristic value has been written + CSCPS_SC_CTNL_PT_REQ_IND, + /// Application response after receiving a CSCPS_SC_CTNL_PT_REQ_IND message + CSCPS_SC_CTNL_PT_CFM, + + /// Indicate a new NTF/IND configuration to the application + CSCPS_CFG_NTFIND_IND, + + /// Send a complete event status to the application + CSCPS_CMP_EVT, +}; + +/// Operation Code used in the profile state machine +enum cscps_op_code +{ + /// Reserved Operation Code + CSCPS_RESERVED_OP_CODE = 0x00, + + /// Send CSC Measurement Operation Code + CSCPS_SEND_CSC_MEAS_OP_CODE, + + /** + * SC Control Point Operation + */ + + /// Set Cumulative Value Operation Code + CSCPS_CTNL_PT_CUMUL_VAL_OP_CODE, + /// Update Sensor Location Operation Code + CSCPS_CTNL_PT_UPD_LOC_OP_CODE, + /// Request Supported Sensor Locations Operation Code + CSCPS_CTNL_PT_SUPP_LOC_OP_CODE, + /// Error Indication Sent Operation Code + CSCPS_CTNL_ERR_IND_OP_CODE, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the initialization function +struct cscps_db_cfg +{ + /** + * CSC Feature Value - Not supposed to be modified during the lifetime of the device + * This value is used to decide if the SC Control Point Characteristic is part of the + * Cycling Speed and Cadence service. + */ + uint16_t csc_feature; + /** + * Indicate if the Sensor Location characteristic is supported. Note that if the Multiple + * Sensor Location feature is set has supported in the csc_feature parameter, the + * characteristic will be added (mandatory). + */ + uint8_t sensor_loc_supp; + /// Sensor location + uint8_t sensor_loc; + /// Wheel revolution + uint32_t wheel_rev; +}; + +/// Parameters of the @ref CSCPS_ENABLE_REQ message +struct cscps_enable_req +{ + /// Connection index + uint8_t conidx; + /// Stored CSC Measurement Char. Client Characteristic Configuration + uint16_t csc_meas_ntf_cfg; + /// Stored SC Control Point Char. Client Characteristic Configuration + uint16_t sc_ctnl_pt_ntf_cfg; +}; + +/// Parameters of the @ref CSCPS_ENABLE_RSP message +struct cscps_enable_rsp +{ + /// Connection index + uint8_t conidx; + /// Status + uint8_t status; +}; + +/// Parameters of the @ref cscps_ntf_csc_meas_cmd message +struct cscps_ntf_csc_meas_cmd +{ + /// Flags + uint8_t flags; + /// Cumulative Crank Revolution + uint16_t cumul_crank_rev; + /// Last Crank Event Time + uint16_t last_crank_evt_time; + /// Last Wheel Event Time + uint16_t last_wheel_evt_time; + /// Wheel Revolution since the last wheel event time + int16_t wheel_rev; +}; + + +/// Parameters of the @ref CSCPS_SC_CTNL_PT_REQ_IND message +struct cscps_sc_ctnl_pt_req_ind +{ + /// Connection index + uint8_t conidx; + /// Operation Code + uint8_t op_code; + /// Value + union cscps_sc_ctnl_pt_req_ind_value + { + /// Cumulative value + uint32_t cumul_value; + /// Sensor Location + uint8_t sensor_loc; + } value; +}; + +/// Parameters of the @ref CSCPS_SC_CTNL_PT_CFM message +struct cscps_sc_ctnl_pt_cfm +{ + /// Connection index + uint8_t conidx; + /// Operation Code + uint8_t op_code; + /// Status + uint8_t status; + /// Value + union cscps_sc_ctnl_pt_cfm_value + { + /// Sensor Location + uint8_t sensor_loc; + /// Supported sensor locations + uint16_t supp_sensor_loc; + /// New Cumulative Wheel revolution Value + uint32_t cumul_wheel_rev; + } value; +}; + +/// Parameters of the @ref CSCPS_CFG_NTFIND_IND message +struct cscps_cfg_ntfind_ind +{ + /// Connection handle + uint8_t conidx; + /// Characteristic Code (CSC Measurement or SC Control Point) + uint8_t char_code; + /// Char. Client Characteristic Configuration + uint16_t ntf_cfg; +}; + +/// Parameters of the @ref CSCPS_CMP_EVT message +struct cscps_cmp_evt +{ + /// Connection index + uint8_t conidx; + /// Operation Code + uint8_t operation; + /// Operation Status + uint8_t status; +}; + +/// @} CSCPSTASK + +#endif //(_CSCPS_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/sourcelist.txt new file mode 100644 index 0000000..e1aef89 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + cscps.c + cscps_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/src/cscps.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/src/cscps.c new file mode 100644 index 0000000..a56edb1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/src/cscps.c @@ -0,0 +1,369 @@ +/** + **************************************************************************************** + * + * @file cscps.c + * + * @brief Cycling Speed and Cadence Profile Sensor implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup CSCPS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_CSC_SENSOR) +#include "cscp_common.h" +#include "prf_utils.h" + +#include "gap.h" +#include "gattc_task.h" +#include "cscps.h" +#include "cscps_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Full CSCPS Database Description - Used to add attributes into the database +static const struct attm_desc cscps_att_db[CSCS_IDX_NB] = +{ + // Cycling Speed and Cadence Service Declaration + [CSCS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // CSC Measurement Characteristic Declaration + [CSCS_IDX_CSC_MEAS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // CSC Measurement Characteristic Value + [CSCS_IDX_CSC_MEAS_VAL] = {ATT_CHAR_CSC_MEAS, PERM(NTF, ENABLE), PERM(RI, ENABLE), CSCP_CSC_MEAS_MAX_LEN}, + // CSC Measurement Characteristic - Client Characteristic Configuration Descriptor + [CSCS_IDX_CSC_MEAS_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // CSC Feature Characteristic Declaration + [CSCS_IDX_CSC_FEAT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // CSC Feature Characteristic Value + [CSCS_IDX_CSC_FEAT_VAL] = {ATT_CHAR_CSC_FEAT, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint16_t)}, + + // Sensor Location Characteristic Declaration + [CSCS_IDX_SENSOR_LOC_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Sensor Location Characteristic Value + [CSCS_IDX_SENSOR_LOC_VAL] = {ATT_CHAR_SENSOR_LOC, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, + + // SC Control Point Characteristic Declaration + [CSCS_IDX_SC_CTNL_PT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), CSCS_IDX_SC_CTNL_PT_VAL, 0}, + // SC Control Point Characteristic Value - The response has the maximal length + [CSCS_IDX_SC_CTNL_PT_VAL] = {ATT_CHAR_SC_CNTL_PT, PERM(IND, ENABLE) | PERM(WRITE_REQ, ENABLE), + PERM(RI, ENABLE), CSCP_SC_CNTL_PT_RSP_MAX_LEN}, + // SC Control Point Characteristic - Client Characteristic Configuration Descriptor + [CSCS_IDX_SC_CTNL_PT_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the CSCPS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t cscps_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct cscps_db_cfg *p_param) +{ + //------------------ create the attribute database for the profile ------------------- + // Service content flag + uint32_t cfg_flag = CSCPS_MANDATORY_MASK; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + /* + * Check if the Sensor Location characteristic shall be added. + * Mandatory if the Multiple Sensor Location feature is supported, otherwise optional. + */ + if ((p_param->sensor_loc_supp == CSCPS_SENSOR_LOC_SUPP) || + (GETB(p_param->csc_feature, CSCP_FEAT_MULT_SENSOR_LOC_SUPP))) + { + cfg_flag |= CSCPS_SENSOR_LOC_MASK; + } + + /* + * Check if the SC Control Point characteristic shall be added + * Mandatory if at least one SC Control Point procedure is supported, otherwise excluded. + */ + if (GETB(p_param->csc_feature, CSCP_FEAT_WHEEL_REV_DATA_SUPP) || + GETB(p_param->csc_feature, CSCP_FEAT_MULT_SENSOR_LOC_SUPP)) + { + cfg_flag |= CSCPS_SC_CTNL_PT_MASK; + } + + // Add service in the database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_CYCLING_SPEED_CADENCE, (uint8_t *)&cfg_flag, + CSCS_IDX_NB, NULL, p_env->task, &cscps_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, DISABLE)); + + // Check if an error has occured + if (status == ATT_ERR_NO_ERROR) + { + // Allocate CSCPS required environment variable + struct cscps_env_tag* p_cscps_env = + (struct cscps_env_tag* ) ke_malloc(sizeof(struct cscps_env_tag), KE_MEM_ATT_DB); + + // Initialize CSCPS environment + + p_env->env = (prf_env_t*) p_cscps_env; + p_cscps_env->shdl = *p_start_hdl; + p_cscps_env->prfl_cfg = cfg_flag; + p_cscps_env->features = p_param->csc_feature; + p_cscps_env->operation = CSCPS_RESERVED_OP_CODE; + + if (CSCPS_IS_FEATURE_SUPPORTED(p_cscps_env->prfl_cfg, CSCPS_SENSOR_LOC_MASK)) + { + p_cscps_env->sensor_loc = (p_param->sensor_loc >= CSCP_LOC_MAX) ? + CSCP_LOC_OTHER : p_param->sensor_loc; + } + + p_cscps_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Mono Instantiated task + p_cscps_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_CSCPS; + cscps_task_init(&(p_env->desc)); + + // Store the provided cumulative wheel revolution value + p_cscps_env->tot_wheel_rev = p_param->wheel_rev; + p_cscps_env->p_ntf = NULL; + + memset(p_cscps_env->prfl_ntf_ind_cfg, 0, BLE_CONNECTION_MAX); + + // If we are here, database has been fulfilled with success, go to idle state + ke_state_set(p_env->task, CSCPS_IDLE); + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the CSCPS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void cscps_destroy(struct prf_task_env *p_env) +{ + struct cscps_env_tag *p_cscps_env = (struct cscps_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + if (p_cscps_env->p_ntf != NULL) + { + ke_free(p_cscps_env->p_ntf); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_cscps_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void cscps_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct cscps_env_tag *p_cscps_env = (struct cscps_env_tag *) p_env->env; + + p_cscps_env->prfl_ntf_ind_cfg[conidx] = 0; +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void cscps_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct cscps_env_tag *p_cscps_env = (struct cscps_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + p_cscps_env->prfl_ntf_ind_cfg[conidx] = 0; +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// CSCPS Task interface required by profile manager +const struct prf_task_cbs cscps_itf = +{ + (prf_init_fnct) cscps_init, + cscps_destroy, + cscps_create, + cscps_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *cscps_prf_itf_get(void) +{ + return &cscps_itf; +} + +void cscps_send_cmp_evt(uint8_t conidx, uint8_t src_id, uint8_t dest_id, uint8_t operation, uint8_t status) +{ + // Get the address of the environment + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + struct cscps_cmp_evt *p_evt; + + // Go back to the Connected state if the state is busy + if (ke_state_get(src_id) == CSCPS_BUSY) + { + ke_state_set(src_id, CSCPS_IDLE); + } + + // Set the operation code + p_cscps_env->operation = CSCPS_RESERVED_OP_CODE; + + // Send the message + p_evt = KE_MSG_ALLOC(CSCPS_CMP_EVT, dest_id, src_id, cscps_cmp_evt); + + p_evt->conidx = conidx; + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + + +void cscps_exe_operation(uint8_t conidx) +{ + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + + ASSERT_ERR(p_cscps_env->p_ntf != NULL); + + bool finished = true; + + while(p_cscps_env->p_ntf->cursor < BLE_CONNECTION_MAX) + { + // Check if notifications are enabled + if (GETB(p_cscps_env->prfl_ntf_ind_cfg[p_cscps_env->p_ntf->cursor], CSCP_PRF_CFG_FLAG_CSC_MEAS_NTF)) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_meas_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, p_cscps_env->p_ntf->cursor), + prf_src_task_get(&(p_cscps_env->prf_env), 0), + gattc_send_evt_cmd, p_cscps_env->p_ntf->length); + + // Fill in the parameter structure + p_meas_val->operation = GATTC_NOTIFY; + p_meas_val->handle = CSCPS_HANDLE(CSCS_IDX_CSC_MEAS_VAL); + p_meas_val->length = p_cscps_env->p_ntf->length; + memcpy(p_meas_val->value, p_cscps_env->p_ntf->value, p_cscps_env->p_ntf->length); + + // Send the event + ke_msg_send(p_meas_val); + + finished = false; + p_cscps_env->p_ntf->cursor++; + break; + } + + p_cscps_env->p_ntf->cursor++; + } + + // check if operation is finished + if (finished) + { + // Inform the application that a procedure has been completed + cscps_send_cmp_evt(conidx, + prf_src_task_get(&p_cscps_env->prf_env, conidx), + prf_dst_task_get(&p_cscps_env->prf_env, conidx), + p_cscps_env->operation, GAP_ERR_NO_ERROR); + + // free operation + ke_free(p_cscps_env->p_ntf); + p_cscps_env->p_ntf = NULL; + p_cscps_env->operation = CSCPS_RESERVED_OP_CODE; + + ke_state_set(prf_src_task_get(&(p_cscps_env->prf_env), 0), CSCPS_IDLE); + } +} + +void cscps_send_rsp_ind(uint8_t conidx, uint8_t req_op_code, uint8_t status) +{ + // Get the address of the environment + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ctl_pt_rsp = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + prf_src_task_get(&p_cscps_env->prf_env, conidx), + gattc_send_evt_cmd, CSCP_SC_CNTL_PT_RSP_MIN_LEN); + + // Fill in the parameter structure + p_ctl_pt_rsp->operation = GATTC_INDICATE; + p_ctl_pt_rsp->handle = CSCPS_HANDLE(CSCS_IDX_SC_CTNL_PT_VAL); + // Pack Control Point confirmation + p_ctl_pt_rsp->length = CSCP_SC_CNTL_PT_RSP_MIN_LEN; + // Response Code + p_ctl_pt_rsp->value[0] = CSCP_CTNL_PT_RSP_CODE; + // Request Operation Code + p_ctl_pt_rsp->value[1] = req_op_code; + // Response value + p_ctl_pt_rsp->value[2] = status; + + // Send the event + ke_msg_send(p_ctl_pt_rsp); +} + +#endif //(BLE_CSC_SENSOR) + +/// @} CSCPS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/src/cscps.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/src/cscps.h new file mode 100644 index 0000000..be62524 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/src/cscps.h @@ -0,0 +1,256 @@ +/** + **************************************************************************************** + * + * @file cscps.h + * + * @brief Header file - Cycling Speed and Cadence Profile Sensor. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _CSCPS_H_ +#define _CSCPS_H_ + +/** + **************************************************************************************** + * @addtogroup CSCPS Cycling Speed and Cadence Profile Sensor + * @ingroup CSCP + * @brief Cycling Speed and Cadence Profile Sensor + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_CSC_SENSOR) +#include "cscp_common.h" +#include "co_utils.h" +#include "prf_types.h" +#include "prf.h" +#include "cscps_task.h" +#include "attm.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Cycling Speed and Cadence Profile Sensor role task instances +#define CSCPS_IDX_MAX (1) + +/******************************************** + ******* CSCPS Configuration Flag Masks ****** + ********************************************/ + +/// Mandatory Attributes (CSC Measurement + CSC Feature) +#define CSCPS_MANDATORY_MASK (0x003F) +/// Sensor Location Attributes +#define CSCPS_SENSOR_LOC_MASK (0x00C0) +/// SC Control Point Attributes +#define CSCPS_SC_CTNL_PT_MASK (0x0700) + +/* + * MACROS + **************************************************************************************** + */ + +#define CSCPS_IS_FEATURE_SUPPORTED(features, flag) ((features & flag) == flag) + +#define CSCPS_HANDLE(idx) \ + (p_cscps_env->shdl + (idx) - \ + ((!(CSCPS_IS_FEATURE_SUPPORTED(p_cscps_env->prfl_cfg, CSCPS_SENSOR_LOC_MASK)) && \ + ((idx) > CSCS_IDX_SENSOR_LOC_CHAR))? (1) : (0))) + +// Get database attribute index + #define CSCPS_IDX(hdl) \ + ((hdl - p_cscps_env->shdl) + \ + ((!(CSCPS_IS_FEATURE_SUPPORTED(p_cscps_env->prfl_cfg, CSCPS_SENSOR_LOC_MASK)) && \ + ((hdl - p_cscps_env->shdl) > CSCS_IDX_SENSOR_LOC_CHAR)) ? (1) : (0))) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the CSCPS task +enum cscps_state +{ + /// Idle state + CSCPS_IDLE, + /// Busy state + CSCPS_BUSY, + + /// Number of defined states. + CSCPS_STATE_MAX +}; + +/// Cycling Speed and Cadence Service - Attribute List +enum cscps_cscs_att_list +{ + /// Cycling Speed and Cadence Service + CSCS_IDX_SVC, + /// CSC Measurement + CSCS_IDX_CSC_MEAS_CHAR, + CSCS_IDX_CSC_MEAS_VAL, + CSCS_IDX_CSC_MEAS_NTF_CFG, + /// CSC Feature + CSCS_IDX_CSC_FEAT_CHAR, + CSCS_IDX_CSC_FEAT_VAL, + /// Sensor Location + CSCS_IDX_SENSOR_LOC_CHAR, + CSCS_IDX_SENSOR_LOC_VAL, + /// SC Control Point + CSCS_IDX_SC_CTNL_PT_CHAR, + CSCS_IDX_SC_CTNL_PT_VAL, + CSCS_IDX_SC_CTNL_PT_NTF_CFG, + + /// Number of attributes + CSCS_IDX_NB, +}; + +/// Profile Configuration Additional Flags bit field +enum cscps_prf_cfg_flag_bf +{ + /// CSC Measurement - Client Char. Cfg + CSCP_PRF_CFG_FLAG_CSC_MEAS_NTF_POS = 3, + CSCP_PRF_CFG_FLAG_CSC_MEAS_NTF_BIT = CO_BIT(CSCP_PRF_CFG_FLAG_CSC_MEAS_NTF_POS), + + /// SC Control Point - Client Char. Cfg + CSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND_POS = 4, + CSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND_BIT = CO_BIT(CSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND_POS), + + /// Bonded data used + CSCP_PRF_CFG_PERFORMED_OK_POS = 7, + CSCP_PRF_CFG_PERFORMED_OK_BIT = CO_BIT(CSCP_PRF_CFG_PERFORMED_OK_POS), +}; + +/// Sensor Location Supported Flag +enum cscps_sensor_loc_supp +{ + /// Sensor Location Char. is not supported + CSCPS_SENSOR_LOC_NOT_SUPP, + /// Sensor Location Char. is supported + CSCPS_SENSOR_LOC_SUPP, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// ongoing notification information +struct cscps_ntf +{ + /// Cursor on connection + uint8_t cursor; + /// Packed notification/indication data size + uint8_t length; + /// Packed notification/indication data + uint8_t value[CSCP_CSC_MEAS_MAX_LEN]; +}; + +/// Cycling Speed and Cadence Profile Sensor environment variable +struct cscps_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Notification data + struct cscps_ntf *p_ntf; + /// Wheel revolution + uint32_t tot_wheel_rev; + + /// Cycling Speed and Cadence Service Start Handle + uint16_t shdl; + /// Features configuration + uint16_t features; + /// profile configuration + uint16_t prfl_cfg; + + /// Operation + uint8_t operation; + /// Sensor location + uint8_t sensor_loc; + + /// Environment variable pointer for each connections + uint8_t prfl_ntf_ind_cfg[BLE_CONNECTION_MAX]; + + /// State of different task instances + ke_state_t state[CSCPS_IDX_MAX]; +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve CSCP service profile interface + * + * @return CSCP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* cscps_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send a CSCPS_CMP_EVT message to the application. + * + * @param[in] conidx Connection index + * @param[in] src_id Source ID + * @param[in] dest_id Destination ID + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void cscps_send_cmp_evt(uint8_t conidx, uint8_t src_id, uint8_t dest_id, + uint8_t operation, uint8_t status); + +/** + **************************************************************************************** + * @brief This function fully manage event to trigg to peer(s) device(s) according + * to on-going operation requested by application + * @param[in] conidx Connection index + **************************************************************************************** + */ +void cscps_exe_operation(uint8_t conidx); + +/** + **************************************************************************************** + * @brief This function sends control point indication error + * + * @param conidx Connection index + * @param req_op_code Request operation code + * @param status Response status code + **************************************************************************************** + */ +void cscps_send_rsp_ind(uint8_t conidx, uint8_t req_op_code, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void cscps_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_CSC_SENSOR) + +/// @} CSCPS + +#endif //(_CSCPS_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/src/cscps_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/src/cscps_task.c new file mode 100644 index 0000000..bd724b7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/cscp/cscps/src/cscps_task.c @@ -0,0 +1,857 @@ +/** + **************************************************************************************** + * + * @file cscps_task.c + * + * @brief Cycling Speed and Cadence Profile Sensor Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup CSCPSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_CSC_SENSOR) + +#include "gapc.h" +#include "gattc_task.h" +#include "cscps.h" +#include "cscps_task.h" +#include "prf_utils.h" +#include "co_math.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CSCPS_ENABLE_REQ message. + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cscps_enable_req_handler(ke_msg_id_t const msgid, + struct cscps_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct cscps_enable_rsp *p_cmp_evt; + + if (ke_state_get(dest_id) == CSCPS_IDLE) + { + status = GAP_ERR_NO_ERROR; + + if (!GETB(p_cscps_env->prfl_ntf_ind_cfg[p_param->conidx], CSCP_PRF_CFG_PERFORMED_OK)) + { + // Check the provided value + if (p_param->csc_meas_ntf_cfg == PRF_CLI_START_NTF) + { + // Store the status + SETB(p_cscps_env->prfl_ntf_ind_cfg[p_param->conidx], CSCP_PRF_CFG_FLAG_CSC_MEAS_NTF, 1); + } + + if (CSCPS_IS_FEATURE_SUPPORTED(p_cscps_env->prfl_cfg, CSCPS_SC_CTNL_PT_MASK)) + { + // Check the provided value + if (p_param->sc_ctnl_pt_ntf_cfg == PRF_CLI_START_IND) + { + // Store the status + SETB(p_cscps_env->prfl_ntf_ind_cfg[p_param->conidx], CSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND, 1); + } + } + + // Enable Bonded Data + SETB(p_cscps_env->prfl_ntf_ind_cfg[p_param->conidx], CSCP_PRF_CFG_PERFORMED_OK, 1); + } + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(CSCPS_ENABLE_RSP, src_id, dest_id, cscps_enable_rsp); + p_cmp_evt->status = status; + p_cmp_evt->conidx = p_param->conidx; + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CSCPS_IDLE) + { + // Get the address of the environment + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t att_idx = CSCPS_IDX(p_param->handle); + + // Send data to peer device + struct gattc_read_cfm *p_cfm = NULL; + + uint8_t status = ATT_ERR_NO_ERROR; + + switch (att_idx) + { + case CSCS_IDX_CSC_MEAS_NTF_CFG: + { + // Fill data + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + co_write16p(p_cfm->value, GETB(p_cscps_env->prfl_ntf_ind_cfg[conidx], CSCP_PRF_CFG_FLAG_CSC_MEAS_NTF) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } break; + + case CSCS_IDX_CSC_FEAT_VAL: + { + // Fill data + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + co_write16p(p_cfm->value, p_cscps_env->features); + } break; + + case CSCS_IDX_SENSOR_LOC_VAL: + { + // Fill data + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint8_t)); + p_cfm->length = sizeof(uint8_t); + p_cfm->value[0] = p_cscps_env->sensor_loc; + } break; + + case CSCS_IDX_SC_CTNL_PT_NTF_CFG: + { + // Fill data + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + co_write16p(p_cfm->value, GETB(p_cscps_env->prfl_ntf_ind_cfg[conidx], CSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND) + ? PRF_CLI_START_IND : PRF_CLI_STOP_NTFIND); + } break; + + default: + { + p_cfm = KE_MSG_ALLOC(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm); + p_cfm->length = 0; + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == CSCPS_IDLE) + { + // Get the address of the environment + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + uint8_t att_idx = CSCPS_IDX(p_param->handle); + struct gattc_att_info_cfm *p_cfm; + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + // check if it's a client configuration char + if ((att_idx == CSCS_IDX_CSC_MEAS_NTF_CFG) + || (att_idx == CSCS_IDX_SC_CTNL_PT_NTF_CFG)) + { + // CCC attribute length = 2 + p_cfm->length = 2; + p_cfm->status = GAP_ERR_NO_ERROR; + } + else if (att_idx == CSCS_IDX_SC_CTNL_PT_VAL) + { + // force length to zero to reject any write starting from something != 0 + p_cfm->length = 0; + p_cfm->status = GAP_ERR_NO_ERROR; + } + // not expected request + else + { + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } + + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CSCPS_NTF_CSC_MEAS_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cscps_ntf_csc_meas_cmd_handler(ke_msg_id_t const msgid, + struct cscps_ntf_csc_meas_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + + // State shall be Connected or Busy + if (ke_state_get(dest_id) == CSCPS_IDLE) + { + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + + // allocate and prepare data to notify + p_cscps_env->p_ntf = (struct cscps_ntf *) ke_malloc(sizeof(struct cscps_ntf), KE_MEM_KE_MSG); + + // pack measured value in database + p_cscps_env->p_ntf->length = CSCP_CSC_MEAS_MIN_LEN; + + // Check the provided flags value + if (!GETB(p_cscps_env->prfl_cfg, CSCP_FEAT_WHEEL_REV_DATA_SUPP) && + GETB(p_param->flags, CSCP_MEAS_WHEEL_REV_DATA_PRESENT)) + { + // Force Wheel Revolution Data to No (Not supported) + SETB(p_param->flags, CSCP_MEAS_WHEEL_REV_DATA_PRESENT, 0); + } + + if (!GETB(p_cscps_env->prfl_cfg, CSCP_FEAT_CRANK_REV_DATA_SUPP) && + GETB(p_param->flags, CSCP_MEAS_CRANK_REV_DATA_PRESENT)) + { + // Force Crank Revolution Data Present to No (Not supported) + SETB(p_param->flags, CSCP_MEAS_CRANK_REV_DATA_PRESENT, 0); + } + + // Force the unused bits of the flag value to 0 + p_cscps_env->p_ntf->value[0] = p_param->flags & CSCP_MEAS_ALL_PRESENT; + + // Cumulative Wheel Resolutions + // Last Wheel Event Time + if (GETB(p_param->flags, CSCP_MEAS_WHEEL_REV_DATA_PRESENT)) + { + // Update the cumulative wheel revolutions value stored in the environment + if (p_param->wheel_rev < 0) + { + // The value shall not decrement below zero + if (co_abs(p_param->wheel_rev) > p_cscps_env->tot_wheel_rev) + { + p_cscps_env->tot_wheel_rev = 0; + } + else + { + p_cscps_env->tot_wheel_rev += p_param->wheel_rev; + } + } + else + { + p_cscps_env->tot_wheel_rev += p_param->wheel_rev; + } + + // Cumulative Wheel Resolutions + co_write32p(&p_cscps_env->p_ntf->value[p_cscps_env->p_ntf->length], p_cscps_env->tot_wheel_rev); + p_cscps_env->p_ntf->length += 4; + + // Last Wheel Event Time + co_write16p(&p_cscps_env->p_ntf->value[p_cscps_env->p_ntf->length], p_param->last_wheel_evt_time); + p_cscps_env->p_ntf->length += 2; + } + + // Cumulative Crank Revolutions + // Last Crank Event Time + if (GETB(p_param->flags, CSCP_MEAS_CRANK_REV_DATA_PRESENT)) + { + // Cumulative Crank Revolutions + co_write32p(&p_cscps_env->p_ntf->value[p_cscps_env->p_ntf->length], p_param->cumul_crank_rev); + p_cscps_env->p_ntf->length += 2; + + // Last Crank Event Time + co_write16p(&p_cscps_env->p_ntf->value[p_cscps_env->p_ntf->length], p_param->last_crank_evt_time); + p_cscps_env->p_ntf->length += 2; + } + + // Configure the environment + p_cscps_env->operation = CSCPS_SEND_CSC_MEAS_OP_CODE; + p_cscps_env->p_ntf->cursor = 0; + + // Go to busy state + ke_state_set(dest_id, CSCPS_BUSY); + + // start operation execution + cscps_exe_operation(conidx); + } + else + { + // Save it for later + msg_status = KE_MSG_SAVED; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref CSCPS_SC_CTNL_PT_CFM message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int cscps_sc_ctnl_pt_cfm_handler(ke_msg_id_t const msgid, + struct cscps_sc_ctnl_pt_cfm *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + uint8_t conidx = KE_IDX_GET(src_id); + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (ke_state_get(dest_id) == CSCPS_BUSY) + { + do + { // check if op code valid + if ((p_param->op_code < CSCPS_CTNL_PT_CUMUL_VAL_OP_CODE) + || (p_param->op_code > CSCPS_CTNL_ERR_IND_OP_CODE)) + { + //Wrong op code + status = PRF_ERR_INVALID_PARAM; + break; + } + + // Check the current operation + if ((p_cscps_env->operation < CSCPS_CTNL_PT_CUMUL_VAL_OP_CODE) || + (p_param->op_code != p_cscps_env->operation)) + { + // The confirmation has been sent without request indication, ignore + status = PRF_ERR_REQ_DISALLOWED; + break; + } + + // The CP Control Point Characteristic must be supported if we are here + if (CSCPS_IS_FEATURE_SUPPORTED(p_cscps_env->prfl_cfg, CSCPS_SC_CTNL_PT_MASK)) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ctl_pt_rsp = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, p_param->conidx), dest_id, + gattc_send_evt_cmd, CSCP_SC_CNTL_PT_RSP_MAX_LEN); + + // Fill in the p_parameter structure + p_ctl_pt_rsp->operation = GATTC_INDICATE; + p_ctl_pt_rsp->handle = CSCPS_HANDLE(CSCS_IDX_SC_CTNL_PT_VAL); + // Pack Control Point confirmation + p_ctl_pt_rsp->length = CSCP_SC_CNTL_PT_RSP_MIN_LEN; + + // Set the operation code (Response Code) + p_ctl_pt_rsp->value[0] = CSCP_CTNL_PT_RSP_CODE; + // Set the response value + p_ctl_pt_rsp->value[2] = (p_param->status > CSCP_CTNL_PT_RESP_FAILED) + ? CSCP_CTNL_PT_RESP_FAILED : p_param->status; + + switch (p_cscps_env->operation) + { + // Set cumulative value + case (CSCPS_CTNL_PT_CUMUL_VAL_OP_CODE): + { + // Set the request operation code + p_ctl_pt_rsp->value[1] = CSCP_CTNL_PT_OP_SET_CUMUL_VAL; + + // Store the new value in the environment + p_cscps_env->tot_wheel_rev = p_param->value.cumul_wheel_rev; + status = GAP_ERR_NO_ERROR; + } break; + + // Update Sensor Location + case (CSCPS_CTNL_PT_UPD_LOC_OP_CODE): + { + // Set the request operation code + p_ctl_pt_rsp->value[1] = CSCP_CTNL_PT_OP_UPD_LOC; + + if (p_param->status == CSCP_CTNL_PT_RESP_SUCCESS) + { + // The CP Control Point Characteristic must be supported if we are here + if (CSCPS_IS_FEATURE_SUPPORTED(p_cscps_env->prfl_cfg, CSCPS_SENSOR_LOC_MASK)) + { + p_cscps_env->sensor_loc = p_param->value.sensor_loc; + status = GAP_ERR_NO_ERROR; + } + } + } break; + + case (CSCPS_CTNL_PT_SUPP_LOC_OP_CODE): + { + // Set the request operation code + p_ctl_pt_rsp->value[1] = CSCP_CTNL_PT_OP_REQ_SUPP_LOC; + + if (p_param->status == CSCP_CTNL_PT_RESP_SUCCESS) + { + // Counter + uint8_t counter; + + // Set the list of supported location + for (counter = 0; counter < CSCP_LOC_MAX; counter++) + { + if (((p_param->value.supp_sensor_loc >> counter) & 0x0001) == 0x0001) + { + p_ctl_pt_rsp->value[p_ctl_pt_rsp->length] = counter; + p_ctl_pt_rsp->length++; + } + } + status = GAP_ERR_NO_ERROR; + } + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + // Send the event + ke_msg_send(p_ctl_pt_rsp); + } + } while (0); + + if (status != GAP_ERR_NO_ERROR) + { + // Inform the application that a procedure has been completed + cscps_send_cmp_evt(conidx, + prf_src_task_get(&p_cscps_env->prf_env, conidx), + prf_dst_task_get(&p_cscps_env->prf_env, conidx), + p_cscps_env->operation, p_param->status); + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + uint8_t conidx = KE_IDX_GET(src_id); + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Check the connection handle + if (p_cscps_env != NULL) + { + // CSC Measurement Characteristic, Client Characteristic Configuration Descriptor + if (p_param->handle == (CSCPS_HANDLE(CSCS_IDX_CSC_MEAS_NTF_CFG))) + { + uint16_t ntf_cfg; + // Status + uint8_t status = PRF_ERR_INVALID_PARAM; + struct gattc_write_cfm *p_cfm; + + // Get the value + co_write16p(&ntf_cfg, p_param->value[0]); + + // Check if the value is correct + if (ntf_cfg <= PRF_CLI_START_NTF) + { + struct cscps_cfg_ntfind_ind *p_ind; + + status = GAP_ERR_NO_ERROR; + + // Save the new configuration in the environment + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + SETB(p_cscps_env->prfl_ntf_ind_cfg[conidx], CSCP_PRF_CFG_FLAG_CSC_MEAS_NTF, 0); + } + else // ntf_cfg == PRF_CLI_START_NTF + { + SETB(p_cscps_env->prfl_ntf_ind_cfg[conidx], CSCP_PRF_CFG_FLAG_CSC_MEAS_NTF, 1); + } + + // Inform the HL about the new configuration + p_ind = KE_MSG_ALLOC(CSCPS_CFG_NTFIND_IND, + prf_dst_task_get(&p_cscps_env->prf_env, conidx), + prf_src_task_get(&p_cscps_env->prf_env, conidx), + cscps_cfg_ntfind_ind); + + p_ind->conidx = conidx; + p_ind->char_code = CSCP_CSCS_CSC_MEAS_CHAR; + p_ind->ntf_cfg = ntf_cfg; + + ke_msg_send(p_ind); + + // Enable Bonded Data + SETB(p_cscps_env->prfl_ntf_ind_cfg[conidx], CSCP_PRF_CFG_PERFORMED_OK, 1); + } + // else status is PRF_ERR_INVALID_PARAM + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + else // Should be the SC Control Point Characteristic + { + if (CSCPS_IS_FEATURE_SUPPORTED(p_cscps_env->prfl_cfg, CSCPS_SC_CTNL_PT_MASK)) + { + // SC Control Point, Client Characteristic Configuration Descriptor + if (p_param->handle == (CSCPS_HANDLE(CSCS_IDX_SC_CTNL_PT_NTF_CFG))) + { + uint16_t ntf_cfg; + // Status + uint8_t status = PRF_ERR_INVALID_PARAM; + struct gattc_write_cfm *p_cfm; + + // Get the value + co_write16p(&ntf_cfg, p_param->value[0]); + + // Check if the value is correct + if ((ntf_cfg == PRF_CLI_STOP_NTFIND) || (ntf_cfg == PRF_CLI_START_IND)) + { + struct cscps_cfg_ntfind_ind *p_ind; + + status = GAP_ERR_NO_ERROR; + + // Save the new configuration in the environment + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + SETB(p_cscps_env->prfl_ntf_ind_cfg[conidx], CSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND, 0); + } + else // ntf_cfg == PRF_CLI_START_IND + { + SETB(p_cscps_env->prfl_ntf_ind_cfg[conidx], CSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND, 1); + } + + // Inform the HL about the new configuration + p_ind = KE_MSG_ALLOC(CSCPS_CFG_NTFIND_IND, + prf_dst_task_get(&p_cscps_env->prf_env, conidx), + prf_src_task_get(&p_cscps_env->prf_env, conidx), + cscps_cfg_ntfind_ind); + + p_ind->conidx = conidx; + p_ind->char_code = CSCP_CSCS_SC_CTNL_PT_CHAR; + p_ind->ntf_cfg = ntf_cfg; + + ke_msg_send(p_ind); + + // Enable Bonded Data + SETB(p_cscps_env->prfl_ntf_ind_cfg[conidx], CSCP_PRF_CFG_PERFORMED_OK, 1); + } + // else status is PRF_ERR_INVALID_PARAM + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + // SC Control Point Characteristic + else if (p_param->handle == (CSCPS_HANDLE(CSCS_IDX_SC_CTNL_PT_VAL))) + { + // Write Response Status + uint8_t wr_status = ATT_ERR_NO_ERROR; + // Indication Status + uint8_t ind_status = CSCP_CTNL_PT_RESP_NOT_SUPP; + struct gattc_write_cfm *p_cfm; + + do + { + struct cscps_sc_ctnl_pt_req_ind *p_req_ind; + + // Check if sending of indications has been enabled + if (!GETB(p_cscps_env->prfl_ntf_ind_cfg[conidx], CSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND)) + { + // CCC improperly configured + wr_status = CSCP_ERROR_CCC_INVALID_PARAM; + ind_status = CSCP_CTNL_PT_RESP_FAILED; + break; + } + + if (p_cscps_env->operation >= CSCPS_CTNL_PT_CUMUL_VAL_OP_CODE) + { + // A procedure is already in progress + wr_status = CSCP_ERROR_PROC_IN_PROGRESS; + ind_status = CSCP_CTNL_PT_RESP_FAILED; + break; + } + + if (p_cscps_env->operation == CSCPS_SEND_CSC_MEAS_OP_CODE) + { + // Keep the message until the end of the current procedure + msg_status = KE_MSG_NO_FREE; + break; + } + + // Allocate a request indication message for the application + p_req_ind = KE_MSG_ALLOC(CSCPS_SC_CTNL_PT_REQ_IND, + prf_dst_task_get(&p_cscps_env->prf_env, conidx), + prf_src_task_get(&p_cscps_env->prf_env, conidx), + cscps_sc_ctnl_pt_req_ind); + + // Operation Code + p_req_ind->op_code = p_param->value[0]; + // Connection index + p_req_ind->conidx = conidx; + + // Operation Code + switch (p_param->value[0]) + { + // Set Cumulative value + case (CSCP_CTNL_PT_OP_SET_CUMUL_VAL): + { + // Check if the Wheel Revolution Data feature is supported + if (GETB(p_cscps_env->features, CSCP_FEAT_WHEEL_REV_DATA_SUPP)) + { + // The request can be handled + ind_status = CSCP_CTNL_PT_RESP_SUCCESS; + p_cscps_env->operation = CSCPS_CTNL_PT_CUMUL_VAL_OP_CODE; + + // Cumulative value + p_req_ind->value.cumul_value = co_read32p(&p_param->value[1]); + } + } break; + + // Update sensor location + case (CSCP_CTNL_PT_OP_UPD_LOC): + { + // Check if the Multiple Sensor Location feature is supported + if (GETB(p_cscps_env->features, CSCP_FEAT_MULT_SENSOR_LOC_SUPP)) + { + // Check the sensor location value + if (p_param->value[1] < CSCP_LOC_MAX) + { + // The request can be handled + ind_status = CSCP_CTNL_PT_RESP_SUCCESS; + + p_cscps_env->operation = CSCPS_CTNL_PT_UPD_LOC_OP_CODE; + + // Sensor Location + p_req_ind->value.sensor_loc = p_param->value[1]; + } + else + { + // The request can be handled + ind_status = CSCP_CTNL_PT_RESP_INV_PARAM; + } + } + } break; + + // Request supported sensor locations + case (CSCP_CTNL_PT_OP_REQ_SUPP_LOC): + { + // Check if the Multiple Sensor Location feature is supported + if (GETB(p_cscps_env->features, CSCP_FEAT_MULT_SENSOR_LOC_SUPP)) + { + // The request can be handled + ind_status = CSCP_CTNL_PT_RESP_SUCCESS; + + p_cscps_env->operation = CSCPS_CTNL_PT_SUPP_LOC_OP_CODE; + } + + } break; + + default: + { + // Operation Code is invalid, status is already CSCP_CTNL_PT_RESP_NOT_SUPP + } break; + } + + // If no error raised, inform the application about the request + if (ind_status == CSCP_CTNL_PT_RESP_SUCCESS) + { + // Send the request indication to the application + ke_msg_send(p_req_ind); + // Go to the Busy status + ke_state_set(dest_id, CSCPS_BUSY); + // Align error code + wr_status = GAP_ERR_NO_ERROR; + } + else + { + // Free the allocated message + ke_msg_free(ke_param2msg(p_req_ind)); + } + } while (0); + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = wr_status; + ke_msg_send(p_cfm); + + // If error raised in control point, inform the peer + if ((ind_status != CSCP_CTNL_PT_RESP_SUCCESS) && + (p_param->handle == (CSCPS_HANDLE(CSCS_IDX_SC_CTNL_PT_VAL)))) + { + cscps_send_rsp_ind(conidx, p_param->value[0], ind_status); + } + } + } + else + { + ASSERT_ERR(0); + } + } + } + // else drop the message + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles @ref GATT_NOTIFY_CMP_EVT message meaning that a notification or an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + + // Check if a connection exists + if (ke_state_get(dest_id) == CSCPS_BUSY) + { + switch (p_param->operation) + { + case (GATTC_NOTIFY): + { + ASSERT_ERR(p_cscps_env->operation == CSCPS_SEND_CSC_MEAS_OP_CODE); + // continuer operation execution + cscps_exe_operation(conidx); + } break; + + case (GATTC_INDICATE): + { + ASSERT_ERR(p_cscps_env->operation >= CSCPS_CTNL_PT_CUMUL_VAL_OP_CODE); + + // Inform the application that a procedure has been completed + cscps_send_cmp_evt(conidx, + prf_src_task_get(&p_cscps_env->prf_env, conidx), + prf_dst_task_get(&p_cscps_env->prf_env, conidx), + p_cscps_env->operation, p_param->status); + // else ignore the message + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(cscps) +{ + {CSCPS_ENABLE_REQ, (ke_msg_func_t) cscps_enable_req_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {CSCPS_NTF_CSC_MEAS_CMD, (ke_msg_func_t) cscps_ntf_csc_meas_cmd_handler}, + {CSCPS_SC_CTNL_PT_CFM, (ke_msg_func_t) cscps_sc_ctnl_pt_cfm_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +void cscps_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct cscps_env_tag *p_cscps_env = PRF_ENV_GET(CSCPS, cscps); + + p_task_desc->msg_handler_tab = cscps_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(cscps_msg_handler_tab); + p_task_desc->state = p_cscps_env->state; + p_task_desc->idx_max = CSCPS_IDX_MAX; +} + +#endif //(BLE_CSC_SENSOR) + +/// @} CSCPSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/api/disc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/api/disc_task.h new file mode 100644 index 0000000..ff0a138 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/api/disc_task.h @@ -0,0 +1,158 @@ +/** + **************************************************************************************** + * + * @file disc_task.h + * + * @brief Header file - DISCTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef DISC_TASK_H_ +#define DISC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup DISCTASK Device Information Service Client Task + * @ingroup DISC + * @brief Device Information Service Client Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/*@TRACE*/ +enum disc_msg_id +{ + /// Start the find me locator profile - at connection + DISC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_DISC), + /// Confirm that cfg connection has finished with discovery results, or that normal cnx started + DISC_ENABLE_RSP, + + /// Generic message to read a DIS characteristic value + DISC_RD_CHAR_CMD, + /// Generic message for read responses for APP + DISC_RD_CHAR_IND, + /// Complete Event Information + DISC_CMP_EVT, +}; + +/// Characteristics +enum +{ + /// Manufacturer Name String + DISC_MANUFACTURER_NAME_CHAR, + /// Model Number String + DISC_MODEL_NB_STR_CHAR, + /// Serial Number String + DISC_SERIAL_NB_STR_CHAR, + /// Hardware Revision String + DISC_HARD_REV_STR_CHAR, + /// Firmware Revision String + DISC_FIRM_REV_STR_CHAR, + /// Software Revision String + DISC_SW_REV_STR_CHAR, + /// System ID + DISC_SYSTEM_ID_CHAR, + /// IEEE 11073-20601 Regulatory Certification Data List + DISC_IEEE_CHAR, + /// PnP ID + DISC_PNP_ID_CHAR, + + DISC_CHAR_MAX, +}; + +/// Operation codes +enum disc_op_codes +{ + /// Database Creation Procedure + DISC_RESERVED_OP_CODE = 0, + + /// Read char. Operation Code + DISC_RD_CHAR_CMD_OP_CODE = 1, +}; + +/* + * API MESSAGES STRUCTURES + **************************************************************************************** + */ + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Device Information Service + */ +struct disc_dis_content +{ + /// service info + struct prf_svc svc; + + /// Characteristic info: + struct prf_char_inf chars[DISC_CHAR_MAX]; +}; + +/// Parameters of the @ref DISC_ENABLE_REQ message +struct disc_enable_req +{ + ///Connection type + uint8_t con_type; + + /// Existing handle values dis + struct disc_dis_content dis; +}; + +/// Parameters of the @ref DISC_ENABLE_RSP message +struct disc_enable_rsp +{ + ///status + uint8_t status; + + /// DIS handle values and characteristic properties + struct disc_dis_content dis; +}; + +///Parameters of the @ref DISC_RD_CHAR_CMD message +struct disc_rd_char_cmd +{ + ///Characteristic value code + uint8_t char_code; +}; + +///Parameters of the @ref DISC_RD_CHAR_IND message +struct disc_rd_char_ind +{ + /// Attribute data information + struct prf_att_info info; +}; + +///Parameters of the @ref DISC_CMP_EVT message +struct disc_cmp_evt +{ + /// Operation + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} DISCTASK + +#endif // DISC_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/sourcelist.txt new file mode 100644 index 0000000..2334f58 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + disc.c + disc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/src/disc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/src/disc.c new file mode 100644 index 0000000..ca21106 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/src/disc.c @@ -0,0 +1,232 @@ +/** + **************************************************************************************** + * + * @file disc.c + * + * @brief Device Information Service Client Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup DISC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_DIS_CLIENT) +#include "disc.h" +#include "disc_task.h" +#include "gap.h" + +#include "ke_mem.h" + + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Initialization of the DISC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t disc_init (struct prf_task_env *p_env, uint16_t *p_start_hdl, + uint16_t app_task, uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct disc_env_tag *p_disc_env = + (struct disc_env_tag *) ke_malloc(sizeof(struct disc_env_tag), KE_MEM_ATT_DB); + + // allocate DISC required environment variable + p_env->env = (prf_env_t *) p_disc_env; + + p_disc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_disc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_DISC; + disc_task_init(&(p_env->desc)); + + for (idx = 0; idx < DISC_IDX_MAX; idx++) + { + p_disc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), DISC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Destruction of the DISC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void disc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct disc_env_tag *p_disc_env = (struct disc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < DISC_IDX_MAX; idx++) + { + if (p_disc_env->p_env[idx] != NULL) + { + ke_free(p_disc_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_disc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void disc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put DIS Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), DISC_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void disc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct disc_env_tag *p_disc_env = (struct disc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_disc_env->p_env[conidx] != NULL) + { + ke_free(p_disc_env->p_env[conidx]); + p_disc_env->p_env[conidx] = NULL; + } + + // Put DIS Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), DISC_FREE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// DISC Task interface required by profile manager +const struct prf_task_cbs disc_itf = +{ + disc_init, + disc_destroy, + disc_create, + disc_cleanup, +}; + + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* disc_prf_itf_get(void) +{ + return &disc_itf; +} + + +void disc_enable_rsp_send(struct disc_env_tag *p_disc_env, uint8_t conidx, uint8_t status) +{ + // Send APP the details of the discovered attributes on DISC + struct disc_enable_rsp *p_rsp = KE_MSG_ALLOC(DISC_ENABLE_RSP, + prf_dst_task_get(&(p_disc_env->prf_env), conidx), + prf_src_task_get(&(p_disc_env->prf_env), conidx), + disc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->dis = p_disc_env->p_env[conidx]->dis; + + // Go to connected state + ke_state_set(prf_src_task_get(&(p_disc_env->prf_env), conidx), DISC_IDLE); + } + else + { + // clean-up environment variable allocated for task instance + ke_free(p_disc_env->p_env[conidx]); + p_disc_env->p_env[conidx] = NULL; + } + + ke_msg_send(p_rsp); +} + +void disc_send_cmp_evt(struct disc_env_tag *p_disc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct disc_cmp_evt *p_evt; + ke_task_id_t src_id = prf_src_task_get(&(p_disc_env->prf_env), conidx); + ke_task_id_t dest_id = prf_dst_task_get(&(p_disc_env->prf_env), conidx); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == DISC_BUSY) + { + ke_state_set(src_id, DISC_IDLE); + } + + // Send the message to the application + p_evt = KE_MSG_ALLOC(DISC_CMP_EVT, dest_id, src_id, disc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //BLE_DIS_CLIENT + +/// @} DISC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/src/disc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/src/disc.h new file mode 100644 index 0000000..bda98c6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/src/disc.h @@ -0,0 +1,165 @@ +/** + **************************************************************************************** + * + * @file disc.h + * + * @brief Header file - Device Information Service - Client Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef DISC_H_ +#define DISC_H_ + +/** + **************************************************************************************** + * @addtogroup DIS Device Information Service + * @ingroup PROFILE + * @brief Device Information Service + ***************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup DISC Device Information Service Client + * @ingroup DIS + * @brief Device Information Service Client + * @{ + **************************************************************************************** + */ +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#if (BLE_DIS_CLIENT) +#include +#include +#include "ke_task.h" +#include "prf_utils.h" +#include "disc_task.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Device Information Service Client task instances +#define DISC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the DISC task +enum +{ + /// Not Connected State + DISC_FREE, + /// Idle state + DISC_IDLE, + /// Discovering State + DISC_DISCOVERING, + /// Busy State + DISC_BUSY, + + ///Number of defined states. + DISC_STATE_MAX +}; + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/// Environment variable for each Connections +struct disc_cnx_env +{ + ///Current Time Service Characteristics + struct disc_dis_content dis; + /// Last char. code requested to read. + uint8_t last_char_code; + /// counter used to check service uniqueness + uint8_t nb_svc; +}; + +/// Device Information Service Client environment variable +struct disc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct disc_cnx_env *p_env[DISC_IDX_MAX]; + /// State of different task instances + ke_state_t state[DISC_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Retrieve DIS client profile interface + * + * @return DIS client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* disc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Thermometer ATT DB discovery results to DIS host. + * + * @param p_disc_env DIS Client Role task environment + * @param conidx Connection index + * @param status Response status code + ***************************************************************************************** + */ +void disc_enable_rsp_send(struct disc_env_tag *p_disc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send an DISC_CMP_EVT message to a requester. + * + * @param[in] p_disc_env DIS Client environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void disc_send_cmp_evt(struct disc_env_tag *p_disc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void disc_task_init(struct ke_task_desc *p_task_desc); + +#endif //BLE_DIS_CLIENT + +/// @} DISC + +#endif // DISC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/src/disc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/src/disc_task.c new file mode 100644 index 0000000..537a165 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/disc/src/disc_task.c @@ -0,0 +1,350 @@ +/** + **************************************************************************************** + * + * @file disc_task.c + * + * @brief Device Information Service Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup DISCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_DIS_CLIENT) +#include "co_utils.h" +#include "gap.h" +#include "disc_task.h" +#include "disc.h" +#include "gattc_task.h" + +#include "ke_mem.h" + + +/// State machine used to retrieve Device Information Service characteristics information +const struct prf_char_def disc_dis_char[DISC_CHAR_MAX] = +{ + // Manufacturer Name + [DISC_MANUFACTURER_NAME_CHAR] = {ATT_CHAR_MANUF_NAME, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, + // Model Number String + [DISC_MODEL_NB_STR_CHAR] = {ATT_CHAR_MODEL_NB, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, + // Serial Number String + [DISC_SERIAL_NB_STR_CHAR] = {ATT_CHAR_SERIAL_NB, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, + // Hardware Revision String + [DISC_HARD_REV_STR_CHAR] = {ATT_CHAR_HW_REV, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, + // Firmware Revision String + [DISC_FIRM_REV_STR_CHAR] = {ATT_CHAR_FW_REV, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, + // TSoftware Revision String + [DISC_SW_REV_STR_CHAR] = {ATT_CHAR_SW_REV, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, + // System ID + [DISC_SYSTEM_ID_CHAR] = {ATT_CHAR_SYS_ID, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, + // IEEE + [DISC_IEEE_CHAR] = {ATT_CHAR_IEEE_CERTIF, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, + // PnP ID + [DISC_PNP_ID_CHAR] = {ATT_CHAR_PNP_ID, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref DISC_ENABLE_REQ message. + * The handler enables the Device Information Service Client Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int disc_enable_req_handler(ke_msg_id_t const msgid, + struct disc_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Device Information Service Client Role Task Environment + struct disc_env_tag *p_disc_env = PRF_ENV_GET(DISC, disc); + + ASSERT_INFO(p_disc_env != NULL, dest_id, src_id); + if ((state == DISC_IDLE) && (p_disc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_disc_env->p_env[conidx] = (struct disc_cnx_env *) ke_malloc(sizeof(struct disc_cnx_env), KE_MEM_ATT_DB); + memset(p_disc_env->p_env[conidx], 0, sizeof(struct disc_cnx_env)); + + // Config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + // start discovering HTS on peer + prf_disc_svc_send(&(p_disc_env->prf_env), conidx, ATT_SVC_DEVICE_INFO); + + // Go to DISCOVERING state + ke_state_set(dest_id, DISC_DISCOVERING); + } + // normal connection, get saved att details + else + { + p_disc_env->p_env[conidx]->dis = p_param->dis; + + // send APP confirmation that can start normal connection to TH + disc_enable_rsp_send(p_disc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != DISC_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + disc_enable_rsp_send(p_disc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == DISC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct disc_env_tag *p_disc_env = PRF_ENV_GET(DISC, disc); + + ASSERT_INFO(p_disc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_disc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_disc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve DIS characteristics + prf_extract_svc_info(p_ind, DISC_CHAR_MAX, &disc_dis_char[0], &(p_disc_env->p_env[conidx]->dis.chars[0]), + 0, NULL, NULL); + + //Even if we get multiple responses we only store 1 range + p_disc_env->p_env[conidx]->dis.svc.shdl = p_ind->start_hdl; + p_disc_env->p_env[conidx]->dis.svc.ehdl = p_ind->end_hdl; + } + + p_disc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Get the address of the environment + struct disc_env_tag *p_disc_env = PRF_ENV_GET(DISC, disc); + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == DISC_DISCOVERING) + { + uint8_t status = p_param->status; + + if (p_param->status == ATT_ERR_NO_ERROR) + { + if (p_disc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(DISC_CHAR_MAX, p_disc_env->p_env[conidx]->dis.chars, + disc_dis_char); + } + // too much services + else if (p_disc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + } + + disc_enable_rsp_send(p_disc_env, conidx, status); + } + else if (state == DISC_BUSY) + { + if (p_param->operation == GATTC_READ) + { + disc_send_cmp_evt(p_disc_env, conidx, DISC_RD_CHAR_CMD_OP_CODE, p_param->status); + } + + ke_state_set(dest_id, DISC_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref DISC_RD_CHAR_CMD message. + * Check if the handle exists in profile(already discovered) and send request, otherwise + * error to APP. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int disc_rd_char_cmd_handler(ke_msg_id_t const msgid, + struct disc_rd_char_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Device Information Service Client Role Task Environment + struct disc_env_tag *p_disc_env = PRF_ENV_GET(DISC, disc); + + ASSERT_INFO(p_disc_env != NULL, dest_id, src_id); + if ((state == DISC_IDLE) && (p_disc_env->p_env[conidx] != NULL)) + { + uint16_t search_hdl = ATT_INVALID_HDL; + + // retrieve search handle + if (p_param->char_code < DISC_CHAR_MAX) + { + search_hdl = p_disc_env->p_env[conidx]->dis.chars[p_param->char_code].val_hdl; + } + + //Check if handle is viable + if (search_hdl != ATT_INVALID_HDL) + { + // perform read request + p_disc_env->p_env[conidx]->last_char_code = p_param->char_code; + prf_read_char_send(&(p_disc_env->prf_env), conidx, p_disc_env->p_env[conidx]->dis.svc.shdl, + p_disc_env->p_env[conidx]->dis.svc.ehdl, search_hdl); + + // enter in a busy state + ke_state_set(dest_id, DISC_BUSY); + } + else + { + // invalid handle requested + status = PRF_ERR_INEXISTENT_HDL; + } + } + else if (state != DISC_FREE) + { + // request cannot be performed + status = PRF_ERR_REQ_DISALLOWED; + } + + // send error response if request fails + if (status != GAP_ERR_NO_ERROR) + { + disc_send_cmp_evt(p_disc_env, conidx, DISC_RD_CHAR_CMD_OP_CODE, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == DISC_BUSY) + { + // Get the address of the environment + struct disc_env_tag *p_disc_env = PRF_ENV_GET(DISC, disc); + + ASSERT_INFO(p_disc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_disc_env->p_env[KE_IDX_GET(dest_id)] != NULL, dest_id, src_id); + + prf_client_att_info_rsp(&(p_disc_env->prf_env), KE_IDX_GET(dest_id), DISC_RD_CHAR_IND, + GAP_ERR_NO_ERROR, p_param); + } + + return (KE_MSG_CONSUMED); +} + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(disc) +{ + {DISC_RD_CHAR_CMD, (ke_msg_func_t)disc_rd_char_cmd_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {DISC_ENABLE_REQ, (ke_msg_func_t)disc_enable_req_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void disc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct disc_env_tag *p_disc_env = PRF_ENV_GET(DISC, disc); + + p_task_desc->msg_handler_tab = disc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(disc_msg_handler_tab); + p_task_desc->state = p_disc_env->state; + p_task_desc->idx_max = DISC_IDX_MAX; +} + +#endif //BLE_DIS_CLIENT + +/// @} DISCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/api/diss.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/api/diss.h new file mode 100644 index 0000000..ad578fa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/api/diss.h @@ -0,0 +1,211 @@ +/** + **************************************************************************************** + * + * @file diss.h + * + * @brief Header file - Device Information Service Server. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef DISS_H_ +#define DISS_H_ + +/** + **************************************************************************************** + * @addtogroup DISS Device Information Service Server + * @ingroup DIS + * @brief Device Information Service Server + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_DIS_SERVER) +#include "prf_types.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +#define DISS_IDX_MAX (1) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the DISS task +enum +{ + /// Idle state + DISS_IDLE, + /// Busy state + DISS_BUSY, + /// Number of defined states. + DISS_STATE_MAX +}; + +/// DISS Attributes database handle list +enum diss_att_db_handles +{ + DIS_IDX_SVC, + + DIS_IDX_MANUFACTURER_NAME_CHAR, + DIS_IDX_MANUFACTURER_NAME_VAL, + + DIS_IDX_MODEL_NB_STR_CHAR, + DIS_IDX_MODEL_NB_STR_VAL, + + DIS_IDX_SERIAL_NB_STR_CHAR, + DIS_IDX_SERIAL_NB_STR_VAL, + + DIS_IDX_HARD_REV_STR_CHAR, + DIS_IDX_HARD_REV_STR_VAL, + + DIS_IDX_FIRM_REV_STR_CHAR, + DIS_IDX_FIRM_REV_STR_VAL, + + DIS_IDX_SW_REV_STR_CHAR, + DIS_IDX_SW_REV_STR_VAL, + + DIS_IDX_SYSTEM_ID_CHAR, + DIS_IDX_SYSTEM_ID_VAL, + + DIS_IDX_IEEE_CHAR, + DIS_IDX_IEEE_VAL, + + DIS_IDX_PNP_ID_CHAR, + DIS_IDX_PNP_ID_VAL, + + DIS_IDX_NB, +}; + +/// Value element +struct diss_val_elmt +{ + /// list element header + struct co_list_hdr hdr; + /// value identifier + uint8_t value; + /// value length + uint8_t length; + /// value data + uint8_t data[__ARRAY_EMPTY]; +}; + +///Device Information Service Server Environment Variable +struct diss_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// List of values set by application + struct co_list values; + /// Service Attribute Start Handle + uint16_t start_hdl; + /// Services features + uint16_t features; + /// Last requested value + uint8_t req_val; + /// Last connection index which request value + uint8_t req_conidx; + + /// DISS task state + ke_state_t state[DISS_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve DIS service profile interface + * + * @return DIS service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* diss_prf_itf_get(void); + + +/** + **************************************************************************************** + * @brief Check if an attribute shall be added or not in the database + * + * @param features DIS features + * + * @return Feature config flag + **************************************************************************************** + */ +uint32_t diss_compute_cfg_flag(uint16_t features); + +/** + **************************************************************************************** + * @brief Check if the provided value length matches characteristic requirements + * + * @param char_code Characteristic Code + * @param val_len Length of the Characteristic value + * + * @return status if value length is ok or not + **************************************************************************************** + */ +uint8_t diss_check_val_len(uint8_t char_code, uint8_t val_len); + +/** + **************************************************************************************** + * @brief Retrieve handle attribute from value + * + * @param[in] p_env Service environment variable + * @param[in] value Value to search + * + * @return Handle attribute from value + **************************************************************************************** + */ +uint16_t diss_value_to_handle(struct diss_env_tag *p_env, uint8_t value); + +/** + **************************************************************************************** + * @brief Retrieve value from attribute handle + * + * @param[in] p_env Service environment variable + * @param[in] handle Attribute handle to search + * + * @return Value from attribute handle + **************************************************************************************** + */ +uint8_t diss_handle_to_value(struct diss_env_tag *p_env, uint16_t handle); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void diss_task_init(struct ke_task_desc *p_task_desc); + +#endif //BLE_DIS_SERVER + +/// @} DISS + +#endif // DISS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/api/diss_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/api/diss_task.h new file mode 100644 index 0000000..07c5a43 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/api/diss_task.h @@ -0,0 +1,179 @@ +/** + **************************************************************************************** + * + * @file diss_task.h + * + * @brief Header file - DISSTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef DISS_TASK_H_ +#define DISS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup DISSTASK Task + * @ingroup DISS + * @brief Device Information Service Server Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include +#include "rwip_task.h" // Task definitions +#include "prf_types.h" +#include "co_math.h" + +/* + * DEFINES + **************************************************************************************** + */ + +///All features are supported +#define DIS_ALL_FEAT_SUP (0x01FF) + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Messages for Device Information Service Server +/*@TRACE*/ +enum diss_msg_id +{ + ///Set the value of an attribute - Request + DISS_SET_VALUE_REQ = TASK_FIRST_MSG(TASK_ID_DISS), + ///Set the value of an attribute - Response + DISS_SET_VALUE_RSP, + /// Peer device request to get profile attribute value + DISS_VALUE_REQ_IND, + /// Peer device confirm value of requested attribute + DISS_VALUE_CFM, +}; + +/// Attribute Table Indexes +enum diss_info +{ + /// Manufacturer Name + DIS_MANUFACTURER_NAME_CHAR, + /// Model Number + DIS_MODEL_NB_STR_CHAR, + /// Serial Number + DIS_SERIAL_NB_STR_CHAR, + /// HW Revision Number + DIS_HARD_REV_STR_CHAR, + /// FW Revision Number + DIS_FIRM_REV_STR_CHAR, + /// SW Revision Number + DIS_SW_REV_STR_CHAR, + /// System Identifier Name + DIS_SYSTEM_ID_CHAR, + /// IEEE Certificate + DIS_IEEE_CHAR, + /// Plug and Play Identifier + DIS_PNP_ID_CHAR, + + DIS_CHAR_MAX, +}; + +/// Database Configuration Flags (not used) +enum diss_features_bf +{ + ///Indicate if Manufacturer Name String Char. is supported + DIS_MANUFACTURER_NAME_CHAR_SUP_POS = 0, + DIS_MANUFACTURER_NAME_CHAR_SUP_BIT = CO_BIT(DIS_MANUFACTURER_NAME_CHAR_SUP_POS), + + ///Indicate if Model Number String Char. is supported + DIS_MODEL_NB_STR_CHAR_SUP_POS = 1, + DIS_MODEL_NB_STR_CHAR_SUP_BIT = CO_BIT(DIS_MODEL_NB_STR_CHAR_SUP_POS), + + ///Indicate if Serial Number String Char. is supported + DIS_SERIAL_NB_STR_CHAR_SUP_POS = 2, + DIS_SERIAL_NB_STR_CHAR_SUP_BIT = CO_BIT(DIS_SERIAL_NB_STR_CHAR_SUP_POS), + + ///Indicate if Hardware Revision String Char. supports indications + DIS_HARD_REV_STR_CHAR_SUP_POS = 3, + DIS_HARD_REV_STR_CHAR_SUP_BIT = CO_BIT(DIS_HARD_REV_STR_CHAR_SUP_POS), + + ///Indicate if Firmware Revision String Char. is writable + DIS_FIRM_REV_STR_CHAR_SUP_POS = 4, + DIS_FIRM_REV_STR_CHAR_SUP_BIT = CO_BIT(DIS_FIRM_REV_STR_CHAR_SUP_POS), + + ///Indicate if Software Revision String Char. is writable + DIS_SW_REV_STR_CHAR_SUP_POS = 5, + DIS_SW_REV_STR_CHAR_SUP_BIT = CO_BIT(DIS_SW_REV_STR_CHAR_SUP_POS), + + ///Indicate if System ID Char. is writable + DIS_SYSTEM_ID_CHAR_SUP_POS = 6, + DIS_SYSTEM_ID_CHAR_SUP_BIT = CO_BIT(DIS_SYSTEM_ID_CHAR_SUP_POS), + + ///Indicate if IEEE Char. is writable + DIS_IEEE_CHAR_SUP_POS = 7, + DIS_IEEE_CHAR_SUP_BIT = CO_BIT(DIS_IEEE_CHAR_SUP_POS), + + ///Indicate if PnP ID Char. is writable + DIS_PNP_ID_CHAR_SUP_POS = 8, + DIS_PNP_ID_CHAR_SUP_BIT = CO_BIT(DIS_PNP_ID_CHAR_SUP_POS), +}; + +/* + * API MESSAGES STRUCTURES + **************************************************************************************** + */ + +/// Parameters for the database creation +struct diss_db_cfg +{ + /// Database configuration @see enum diss_features_bf + uint16_t features; +}; + +/// Set the value of an attribute - Request +struct diss_set_value_req +{ + /// Value to Set + uint8_t value; + /// Value length + uint8_t length; + /// Value data + uint8_t data[__ARRAY_EMPTY]; +}; + +/// Set the value of an attribute - Response +struct diss_set_value_rsp +{ + /// Value Set + uint8_t value; + /// status of the request + uint8_t status; +}; + +/// Peer device request to get profile attribute value +struct diss_value_req_ind +{ + /// Requested value + uint8_t value; +}; + +/// Peer device value of requested attribute +struct diss_value_cfm +{ + /// Requested value + uint8_t value; + /// Value length + uint8_t length; + /// Value data + uint8_t data[__ARRAY_EMPTY]; +}; + +/// @} DISSTASK +#endif // DISS_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/src/diss.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/src/diss.c new file mode 100644 index 0000000..df58166 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/src/diss.c @@ -0,0 +1,368 @@ +/** + **************************************************************************************** + * + * @file diss.c + * + * @brief Device Information Service Server Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup DISS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_DIS_SERVER) +#include "attm.h" +#include "diss.h" +#include "diss_task.h" +#include "prf_utils.h" +#include "prf.h" + +#include "ke_mem.h" + +/* + * MACROS + **************************************************************************************** + */ + +/// Maximal length for Characteristic values - 128 bytes +#define DIS_VAL_MAX_LEN (128) +///System ID string length +#define DIS_SYS_ID_LEN (0x08) +///IEEE Certif length (min 6 bytes) +#define DIS_IEEE_CERTIF_MIN_LEN (0x06) +///PnP ID length +#define DIS_PNP_ID_LEN (0x07) + + +/* + * DIS ATTRIBUTES + **************************************************************************************** + */ + +/// Full DIS Database Description - Used to add attributes into the database +const struct attm_desc diss_att_db[DIS_IDX_NB] = +{ + // Device Information Service Declaration + [DIS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Manufacturer Name Characteristic Declaration + [DIS_IDX_MANUFACTURER_NAME_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Manufacturer Name Characteristic Value + [DIS_IDX_MANUFACTURER_NAME_VAL] = {ATT_CHAR_MANUF_NAME, PERM(RD, ENABLE), PERM(RI, ENABLE), DIS_VAL_MAX_LEN}, + + // Model Number String Characteristic Declaration + [DIS_IDX_MODEL_NB_STR_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Model Number String Characteristic Value + [DIS_IDX_MODEL_NB_STR_VAL] = {ATT_CHAR_MODEL_NB, PERM(RD, ENABLE), PERM(RI, ENABLE), DIS_VAL_MAX_LEN}, + + // Serial Number String Characteristic Declaration + [DIS_IDX_SERIAL_NB_STR_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Serial Number String Characteristic Value + [DIS_IDX_SERIAL_NB_STR_VAL] = {ATT_CHAR_SERIAL_NB, PERM(RD, ENABLE), PERM(RI, ENABLE), DIS_VAL_MAX_LEN}, + + // Hardware Revision String Characteristic Declaration + [DIS_IDX_HARD_REV_STR_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Hardware Revision String Characteristic Value + [DIS_IDX_HARD_REV_STR_VAL] = {ATT_CHAR_HW_REV, PERM(RD, ENABLE), PERM(RI, ENABLE), DIS_VAL_MAX_LEN}, + + // Firmware Revision String Characteristic Declaration + [DIS_IDX_FIRM_REV_STR_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Firmware Revision String Characteristic Value + [DIS_IDX_FIRM_REV_STR_VAL] = {ATT_CHAR_FW_REV, PERM(RD, ENABLE), PERM(RI, ENABLE), DIS_VAL_MAX_LEN}, + + // Software Revision String Characteristic Declaration + [DIS_IDX_SW_REV_STR_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Software Revision String Characteristic Value + [DIS_IDX_SW_REV_STR_VAL] = {ATT_CHAR_SW_REV, PERM(RD, ENABLE), PERM(RI, ENABLE), DIS_VAL_MAX_LEN}, + + // System ID Characteristic Declaration + [DIS_IDX_SYSTEM_ID_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // System ID Characteristic Value + [DIS_IDX_SYSTEM_ID_VAL] = {ATT_CHAR_SYS_ID, PERM(RD, ENABLE), PERM(RI, ENABLE), DIS_SYS_ID_LEN}, + + // IEEE 11073-20601 Regulatory Certification Data List Characteristic Declaration + [DIS_IDX_IEEE_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // IEEE 11073-20601 Regulatory Certification Data List Characteristic Value + [DIS_IDX_IEEE_VAL] = {ATT_CHAR_IEEE_CERTIF, PERM(RD, ENABLE), PERM(RI, ENABLE), DIS_SYS_ID_LEN}, + + // PnP ID Characteristic Declaration + [DIS_IDX_PNP_ID_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // PnP ID Characteristic Value + [DIS_IDX_PNP_ID_VAL] = {ATT_CHAR_PNP_ID, PERM(RD, ENABLE), PERM(RI, ENABLE), DIS_PNP_ID_LEN}, +}; + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the DISS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t diss_init (struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct diss_db_cfg *p_params) +{ + //------------------ create the attribute database for the profile ------------------- + + // Service content flag + uint32_t cfg_flag; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + // Compute Attribute Table and save it in environment + cfg_flag = diss_compute_cfg_flag(p_params->features); + + status = attm_svc_create_db(p_start_hdl, ATT_SVC_DEVICE_INFO, (uint8_t *)&cfg_flag, + DIS_IDX_NB, NULL, p_env->task, &diss_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS))); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + struct diss_env_tag *p_diss_env = + (struct diss_env_tag *) ke_malloc(sizeof(struct diss_env_tag), KE_MEM_ATT_DB); + + // allocate DISS required environment variable + p_env->env = (prf_env_t *) p_diss_env; + p_diss_env->start_hdl = *p_start_hdl; + p_diss_env->features = p_params->features; + p_diss_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_diss_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_DISS; + diss_task_init(&(p_env->desc)); + co_list_init(&(p_diss_env->values)); + + // service is ready, go into an Idle state + ke_state_set(p_env->task, DISS_IDLE); + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the DISS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void diss_destroy(struct prf_task_env *p_env) +{ + struct diss_env_tag *p_diss_env = (struct diss_env_tag *) p_env->env; + + // remove all values present in list + while (!co_list_is_empty(&(p_diss_env->values))) + { + struct co_list_hdr *p_hdr = co_list_pop_front(&(p_diss_env->values)); + + ke_free(p_hdr); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_diss_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void diss_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Nothing to do +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void diss_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + // Nothing to do +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// DISS Task interface required by profile manager +const struct prf_task_cbs diss_itf = +{ + (prf_init_fnct) diss_init, + diss_destroy, + diss_create, + diss_cleanup, +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *diss_prf_itf_get(void) +{ + return &diss_itf; +} + +uint32_t diss_compute_cfg_flag(uint16_t features) +{ + //Service Declaration + uint32_t cfg_flag = 1; + + for (uint8_t i = 0; i> i) & 1) == 1) + { + cfg_flag |= (3 << (i*2 + 1)); + } + } + + return cfg_flag; +} + +uint8_t diss_handle_to_value(struct diss_env_tag *p_env, uint16_t handle) +{ + uint8_t value = DIS_CHAR_MAX; + + // handle cursor, start from first characteristic of service handle + uint16_t cur_hdl = p_env->start_hdl + 1; + + for (uint8_t i = 0; i < DIS_CHAR_MAX; i++) + { + if (((p_env->features >> i) & 1) == 1) + { + // check if value handle correspond to requested handle + if ((cur_hdl + 1) == handle) + { + value = i; + break; + } + + cur_hdl += 2; + } + } + + return value; +} + +uint16_t diss_value_to_handle(struct diss_env_tag *p_env, uint8_t value) +{ + uint16_t handle = p_env->start_hdl + 1; + int8_t i; + + for (i = 0; i < DIS_CHAR_MAX; i++) + { + if (((p_env->features >> i) & 1) == 1) + { + // requested value + if (value == i) + { + handle += 1; + break; + } + + handle += 2; + } + } + + // check if handle found + return ((i == DIS_CHAR_MAX) ? ATT_INVALID_HDL : handle); +} + +uint8_t diss_check_val_len(uint8_t char_code, uint8_t val_len) +{ + uint8_t status = GAP_ERR_NO_ERROR; + + // Check if length is upper than the general maximal length + if (val_len > DIS_VAL_MAX_LEN) + { + status = PRF_ERR_UNEXPECTED_LEN; + } + else + { + // Check if length matches particular requirements + switch (char_code) + { + case DIS_SYSTEM_ID_CHAR: + { + if (val_len != DIS_SYS_ID_LEN) + { + status = PRF_ERR_UNEXPECTED_LEN; + } + } break; + + case DIS_IEEE_CHAR: + { + if (val_len < DIS_IEEE_CERTIF_MIN_LEN) + { + status = PRF_ERR_UNEXPECTED_LEN; + } + } break; + + case DIS_PNP_ID_CHAR: + { + if (val_len != DIS_PNP_ID_LEN) + { + status = PRF_ERR_UNEXPECTED_LEN; + } + } break; + + default: + { + + } break; + } + } + + return (status); +} + +#endif //BLE_DIS_SERVER + +/// @} DISS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/src/diss_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/src/diss_task.c new file mode 100644 index 0000000..b9efeac --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/src/diss_task.c @@ -0,0 +1,304 @@ +/** + **************************************************************************************** + * + * @file diss_task.c + * + * @brief Device Information Service Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup DISSTASK + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_DIS_SERVER) +#include "co_utils.h" +#include "gap.h" +#include "gattc_task.h" +#include "diss.h" +#include "diss_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" + +#include "stdio.h" +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref DISS_SET_VALUE_REQ message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int diss_set_value_req_handler(ke_msg_id_t const msgid, + struct diss_set_value_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Request status + uint8_t status; + struct diss_set_value_rsp *p_rsp; + + // Check Characteristic Code + if (p_param->value < DIS_CHAR_MAX) + { + struct diss_env_tag *p_diss_env = PRF_ENV_GET(DISS, diss); + + // Characteristic Declaration attribute handle + uint16_t handle = diss_value_to_handle(p_diss_env, p_param->value); + + // Check if the Characteristic exists in the database + if (handle != ATT_INVALID_HDL) + { + // Check the value length + status = diss_check_val_len(p_param->value, p_param->length); + + if (status == GAP_ERR_NO_ERROR) + { + // Check value in already present in service + struct diss_val_elmt *p_val = (struct diss_val_elmt *) co_list_pick(&(p_diss_env->values)); + + // loop until value found + while (p_val != NULL) + { + // if value already present, remove old one + if (p_val->value == p_param->value) + { + co_list_extract(&(p_diss_env->values), &(p_val->hdr)); + ke_free(p_val); + break; + } + + p_val = (struct diss_val_elmt *)p_val->hdr.next; + } + + // allocate value data + p_val = (struct diss_val_elmt *) ke_malloc(sizeof(struct diss_val_elmt) + + p_param->length, KE_MEM_ATT_DB); + + p_val->value = p_param->value; + p_val->length = p_param->length; + memcpy(p_val->data, p_param->data, p_param->length); + // insert value into the list + co_list_push_back(&(p_diss_env->values), &(p_val->hdr)); + } + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + + // send response to application + p_rsp = KE_MSG_ALLOC(DISS_SET_VALUE_RSP, src_id, dest_id, diss_set_value_rsp); + p_rsp->value = p_param->value; + p_rsp->status = status; + + ke_msg_send(p_rsp); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + int msg_status = KE_MSG_CONSUMED; + ke_state_t state = ke_state_get(dest_id); + + if (state == DISS_IDLE) + { + struct diss_env_tag *p_diss_env = PRF_ENV_GET(DISS, diss); + // retrieve value attribute + uint8_t value = diss_handle_to_value(p_diss_env, p_param->handle); + + // Check Characteristic Code + if (value < DIS_CHAR_MAX) + { + // Check value in already present in service + struct diss_val_elmt *p_val = (struct diss_val_elmt *) co_list_pick(&(p_diss_env->values)); + + // loop until value found + while (p_val != NULL) + { + // value is present in service + if (p_val->value == value) + { + break; + } + + p_val = (struct diss_val_elmt *)p_val->hdr.next; + } + + if (p_val != NULL) + { + // Send value to peer device. + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, + dest_id, gattc_read_cfm, p_val->length); + + p_cfm->handle = p_param->handle; + p_cfm->status = ATT_ERR_NO_ERROR; + p_cfm->length = p_val->length; + memcpy(p_cfm->value, p_val->data, p_val->length); + ke_msg_send(p_cfm); + } + else + { + struct diss_value_req_ind *p_req_ind; + + // request value to application + p_diss_env->req_val = value; + p_diss_env->req_conidx = KE_IDX_GET(src_id); + + p_req_ind = KE_MSG_ALLOC(DISS_VALUE_REQ_IND, + prf_dst_task_get(&(p_diss_env->prf_env), KE_IDX_GET(src_id)), + dest_id, diss_value_req_ind); + + p_req_ind->value = value; + ke_msg_send(p_req_ind); + + // Put Service in a busy state + ke_state_set(dest_id, DISS_BUSY); + } + } + else + { + // application error, value cannot be retrieved + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm); + + p_cfm->handle = p_param->handle; + p_cfm->status = ATT_ERR_APP_ERROR; + ke_msg_send(p_cfm); + } + } + // postpone request if profile is in a busy state - required for multipoint + else if (state == DISS_BUSY) + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the value confirmation from application + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int diss_value_cfm_handler(ke_msg_id_t const msgid, + struct diss_value_cfm const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + if (ke_state_get(dest_id) == DISS_BUSY) + { + struct diss_env_tag *p_diss_env = PRF_ENV_GET(DISS, diss); + // retrieve value attribute + uint16_t handle = diss_value_to_handle(p_diss_env, p_diss_env->req_val); + + // check if application provide correct value + if (p_diss_env->req_val == p_param->value) + { + // Send value to peer device. + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, p_diss_env->req_conidx), dest_id, gattc_read_cfm, p_param->length); + + p_cfm->handle = handle; + p_cfm->status = ATT_ERR_NO_ERROR; + p_cfm->length = p_param->length; + memcpy(p_cfm->value, p_param->data, p_param->length); + ke_msg_send(p_cfm); + } + else + { + // application error, value provided by application is not the expected one + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, p_diss_env->req_conidx), dest_id, gattc_read_cfm); + + p_cfm->handle = handle; + p_cfm->status = ATT_ERR_APP_ERROR; + ke_msg_send(p_cfm); + } + + // return to idle state + ke_state_set(dest_id, DISS_IDLE); + } + // else ignore request if not in busy state + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(diss) +{ + {DISS_SET_VALUE_REQ, (ke_msg_func_t)diss_set_value_req_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t)gattc_read_req_ind_handler}, + {DISS_VALUE_CFM, (ke_msg_func_t)diss_value_cfm_handler}, +}; + +void diss_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct diss_env_tag *p_diss_env = PRF_ENV_GET(DISS, diss); + + p_task_desc->msg_handler_tab = diss_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(diss_msg_handler_tab); + p_task_desc->state = p_diss_env->state; + p_task_desc->idx_max = DISS_IDX_MAX; +} + +#endif //BLE_DIS_SERVER + +/// @} DISSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/find_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/find_common.h new file mode 100644 index 0000000..b4710d7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/find_common.h @@ -0,0 +1,116 @@ +/** + **************************************************************************************** + * + * @file find_common.h + * + * @brief Header File - Find Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _FIND_COMMON_H_ +#define _FIND_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup FIND Find Profile + * @ingroup PROFILE + * @brief Find Profile + * + * The FIND module is the responsible block for implementing the Find Profile + * functionalities in the BLE Host. + * + * The Find Profile defines the functionality required in a device that allows + * the user (Collector device) to configure and recover Find measurements from + * a Find device. + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include "prf_types.h" +#include + +/* + * DEFINES + **************************************************************************************** + */ + +/// Find measurement packet max length +#define FIND_MEAS_MAX_LEN (17) +/// Find measurement context packet max length +#define FIND_MEAS_CTX_MAX_LEN (17) +/// Record Access Control Point packet max length +#define FIND_REC_ACCESS_CTRL_MAX_LEN (21) + + +/// Find Service Error Code +enum find_error_code +{ + /// RACP Procedure already in progress + FIND_ERR_PROC_ALREADY_IN_PROGRESS = (0x80), + /// Client Characteristic Configuration Descriptor Improperly Configured + FIND_ERR_IMPROPER_CLI_CHAR_CFG = (0x81), +}; + +/// Record access control point operation filter +struct find_filter +{ + /// function operator + uint8_t operator; + + /// filter type + uint8_t filter_type; + + /// filter union + union + { + /// Sequence number filtering (filter_type = FIND_FILTER_SEQ_NUMBER) + struct + { + /// Min sequence number + uint16_t min; + /// Max sequence number + uint16_t max; + }seq_num; + + /// User facing time filtering (filter_type = FIND_FILTER_USER_FACING_TIME) + struct + { + /// Min base time + struct prf_date_time facetime_min; + + /// Max base time + struct prf_date_time facetime_max; + } time; + } val; +}; + +/// Record access control point request +struct find_racp_req +{ + /// operation code + uint8_t op_code; + + /// operation filter + struct find_filter filter; +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + + +/// @} find_common + +#endif /* _FIND_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/api/findl_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/api/findl_task.h new file mode 100644 index 0000000..180222d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/api/findl_task.h @@ -0,0 +1,128 @@ +/** + **************************************************************************************** + * + * @file findl_task.h + * + * @brief Header file - FINDLTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef FINDL_TASK_H_ +#define FINDL_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup FINDLTASK Find Me Locator Task + * @ingroup FINDL + * @brief Find Me Locator Task + * + * The FINDLTASK is responsible for handling the API messages coming from the application + * or internal tasks. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" +#include "find_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +///Find Me Locator API messages +/*@TRACE*/ +enum findl_msg_id +{ + /// Start the find me locator profile - at connection + FINDL_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_FINDL), + /// Enable confirm message, containing IAS attribute details if discovery connection type + FINDL_ENABLE_RSP, + + /// Alert level set request + FINDL_SET_ALERT_CMD, + /// Complete Event Information + FINDL_CMP_EVT, +}; + +/// Alert levels +enum +{ + /// No alert + FINDL_ALERT_NONE = 0x00, + /// Mild alert + FINDL_ALERT_MILD, + /// High alert + FINDL_ALERT_HIGH +}; + +/// Operation codes +enum findl_op_codes +{ + /// Database Creation Procedure + FINDL_RESERVED_OP_CODE = 0, + + /// Set Alert level Operation Code + FINDL_SET_ALERT_CMD_OP_CODE = 1, +}; + +/// Immediate Alert service details container +struct ias_content +{ + /// Service info + struct prf_svc svc; + + /// Characteristic info: + /// - Alert Level + struct prf_char_inf alert_lvl_char; +}; + +/// Parameters of the @ref FINDL_ENABLE_REQ message +struct findl_enable_req +{ + ///Connection type + uint8_t con_type; + ///Discovered IAS details if any + struct ias_content ias; +}; + +/// Parameters of the @ref FINDL_ENABLE_RSP message +struct findl_enable_rsp +{ + ///Status + uint8_t status; + ///Discovered IAS details if any + struct ias_content ias; +}; + +/// Parameters of the @ref FINDL_SET_ALERT_CMD message +struct findl_set_alert_cmd +{ + /// Alert level + uint8_t alert_lvl; +}; + +///Parameters of the @ref FINDL_CMP_EVT message +struct findl_cmp_evt +{ + /// Operation + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} FINDLTASK + +#endif // FINDL_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/sourcelist.txt new file mode 100644 index 0000000..4b18177 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + findl.c + findl_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/src/findl.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/src/findl.c new file mode 100644 index 0000000..1dc692c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/src/findl.c @@ -0,0 +1,209 @@ +/** + **************************************************************************************** + * + * @file findl.c + * + * @brief Find Me Locator implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup FINDL + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_FINDME_LOCATOR) +#include "findl.h" +#include "findl_task.h" +#include "prf_utils.h" +#include "gap.h" + +#include "ke_mem.h" + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Initialization of the FINDL module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t findl_init (struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct findl_env_tag *p_findl_env = + (struct findl_env_tag *) ke_malloc(sizeof(struct findl_env_tag), KE_MEM_ATT_DB); + + // allocate FINDL required environment variable + p_env->env = (prf_env_t *) p_findl_env; + + p_findl_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_findl_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_FINDL; + findl_task_init(&(p_env->desc)); + + for (idx = 0; idx < FINDL_IDX_MAX; idx++) + { + p_findl_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), FINDL_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Destruction of the FINDL module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void findl_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct findl_env_tag *p_findl_env = (struct findl_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < FINDL_IDX_MAX; idx++) + { + if (p_findl_env->p_env[idx] != NULL) + { + ke_free(p_findl_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_findl_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void findl_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put FINDL in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), FINDL_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void findl_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct findl_env_tag *p_findl_env = (struct findl_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_findl_env->p_env[conidx] != NULL) + { + ke_free(p_findl_env->p_env[conidx]); + p_findl_env->p_env[conidx] = NULL; + } + + // Put FINDL in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), FINDL_FREE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/// FINDL Task interface required by profile manager +const struct prf_task_cbs findl_itf = +{ + (prf_init_fnct) findl_init, + findl_destroy, + findl_create, + findl_cleanup, +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *findl_prf_itf_get(void) +{ + return &findl_itf; +} + +void findl_enable_rsp_send(struct findl_env_tag *p_findl_env, uint8_t conidx, uint8_t status) +{ + // send response to app + struct findl_enable_rsp *p_cfm = KE_MSG_ALLOC(FINDL_ENABLE_RSP, + prf_dst_task_get(&(p_findl_env->prf_env), conidx), + prf_src_task_get(&(p_findl_env->prf_env), conidx), + findl_enable_rsp); + + p_cfm->ias = p_findl_env->p_env[conidx]->ias; + p_cfm->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + // Go to idle state + ke_state_set(prf_src_task_get(&(p_findl_env->prf_env), conidx), FINDL_IDLE); + } + else + { + // clean-up environment variable allocated for task instance + ke_free(p_findl_env->p_env[conidx]); + p_findl_env->p_env[conidx] = NULL; + } + + ke_msg_send(p_cfm); +} + +#endif //BLE_FINDME_LOCATOR + +/// @} FINDL diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/src/findl.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/src/findl.h new file mode 100644 index 0000000..eba9f97 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/src/findl.h @@ -0,0 +1,187 @@ +/** + **************************************************************************************** + * + * @file findl.h + * + * @brief Header file - FINDL. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef FINDL_H_ +#define FINDL_H_ + +/** + **************************************************************************************** + * @addtogroup FIND Find Me Profile + * @ingroup PROFILE + * @brief Find Me Profile + * + * The FIND module is the responsible block for implementing the Find Me profile + * functionalities in the BLE Host. + * + * The Find Me Profile defines the functionality required in a device that allows the user + * to find a peer device by setting its alarm level. + ***************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup FINDL Find Me Locator + * @ingroup FIND + * @brief Find Me Profile Locator + * + * The FINDL is responsible for providing Find Me profile Locator functionalities to + * upper layer module or application. The device using this profile takes the role + * of find me locator. + * + * Find Me Locator (LOC): A LOC (e.g. PC, phone, etc) + * is the term used by this profile to describe a device that can set an alarm level value + * in the peer Find Me target Device (TG), causing the TG to start a sound or flashing light + * or other type of signal allowing it to be located. + * + * The interface of this role to the Application is: + * - Enable the profile role (from APP) + * - Disable the profile role (from APP) + * - Discover Immediate Alert Service range(from APP) and Send result (to APP) + * - Discover Alert Level Characteristic in the IAS range(from APP) and Send Result (to APP) + * - Set alert level in Target (from APP) + * - Error indications (to APP) + * + * The application should remember the discovered IAS range and Alert Level Char. handles + * for the next connection to a known peer (that may also advertise it supports Find Me Profile.) + * This allows the setting of the alert level to be faster. + * + * The enable/disable of the profile and devices disconnection is handled in the application, + * depending on its User Input. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_FINDME_LOCATOR) +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" +#include "findl_task.h" + +/* + * DEFINES + **************************************************************************************** + */ + +///Maximum number of Find me Locator task instances +#define FINDL_IDX_MAX (BLE_CONNECTION_MAX) + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Possible states of the FINDL task +enum findl_state +{ + /// Not Connected State + FINDL_FREE, + /// Idle state + FINDL_IDLE, + /// Discovering state + FINDL_DISCOVERING, + /// Busy State + FINDL_BUSY, + + /// Number of defined states. + FINDL_STATE_MAX +}; +enum +{ + FINDL_ALERT_LVL_CHAR, + + FINDL_IAS_CHAR_MAX, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Environment variable for each Connections +struct findl_cnx_env +{ + /// Found IAS details + struct ias_content ias; + /// Last char. code requested to read. + uint8_t last_char_code; + /// counter used to check service uniqueness + uint8_t nb_svc; +}; + +/// Find me Locator environment variable +struct findl_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct findl_cnx_env *p_env[FINDL_IDX_MAX]; + /// State of different task instances + ke_state_t state[FINDL_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve IAS service profile interface + * + * @return IAS service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *findl_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Enable Confirm message to the application. + * + * @param p_findl_env FMP locator Role task environment + * @param conidx Connection index + * @param status Response status code + **************************************************************************************** + */ +void findl_enable_rsp_send(struct findl_env_tag *p_findl_env, uint8_t conidx, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void findl_task_init(struct ke_task_desc *p_task_desc); + + +#endif //BLE_FINDME_LOCATOR + +/// @} FINDL +#endif // FINDL_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/src/findl_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/src/findl_task.c new file mode 100644 index 0000000..5b341ca --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findl/src/findl_task.c @@ -0,0 +1,318 @@ +/** + **************************************************************************************** + * + * @file findl_task.c + * + * @brief Find Me Locator Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup FINDLTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_FINDME_LOCATOR) +#include "co_utils.h" +#include "findl_task.h" +#include "findl.h" +#include "gattc_task.h" +#include "prf_utils.h" +#include "gap.h" +#include "gapc.h" +#include "gapc_task.h" +#include + +#include "ke_mem.h" + +/// table used to retrieve immediate alert service characteristics information +const struct prf_char_def findl_ias_char[FINDL_IAS_CHAR_MAX] = +{ + [FINDL_ALERT_LVL_CHAR] = {ATT_CHAR_ALERT_LEVEL, + ATT_MANDATORY, + ATT_CHAR_PROP_WR_NO_RESP}, +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref FINDL_ENABLE_REQ message. + * The handler enables the Find Me profile - Locator Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int findl_enable_req_handler(ke_msg_id_t const msgid, + struct findl_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Find me Locator Role Task Environment + struct findl_env_tag *p_findl_env = PRF_ENV_GET(FINDL, findl); + + ASSERT_INFO(p_findl_env != NULL, dest_id, src_id); + + if ((state == FINDL_IDLE) && (p_findl_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_findl_env->p_env[conidx] = (struct findl_cnx_env *) ke_malloc(sizeof(struct findl_cnx_env), KE_MEM_ATT_DB); + memset(p_findl_env->p_env[conidx], 0, sizeof(struct findl_cnx_env)); + + // Config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + // start discovering IAS on peer + prf_disc_svc_send(&(p_findl_env->prf_env), conidx, ATT_SVC_IMMEDIATE_ALERT); + + // Go to DISCOVERING state + ke_state_set(dest_id, FINDL_DISCOVERING); + } + // normal connection, get saved att details + else + { + p_findl_env->p_env[conidx]->ias = p_param->ias; + + // send APP confirmation that can start normal connection to TH + findl_enable_rsp_send(p_findl_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != FINDL_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + findl_enable_rsp_send(p_findl_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == FINDL_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct findl_env_tag *p_findl_env = PRF_ENV_GET(FINDL, findl); + + ASSERT_INFO(p_findl_env != NULL, dest_id, src_id); + ASSERT_INFO(p_findl_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_findl_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve IAS characteristic + prf_extract_svc_info(p_ind, FINDL_IAS_CHAR_MAX, &findl_ias_char[0], + &(p_findl_env->p_env[conidx]->ias.alert_lvl_char), 0, NULL, NULL); + + //Even if we get multiple responses we only store 1 range + p_findl_env->p_env[conidx]->ias.svc.shdl = p_ind->start_hdl; + p_findl_env->p_env[conidx]->ias.svc.ehdl = p_ind->end_hdl; + } + + p_findl_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref FINDL_SET_ALERT_CMD message. + * The handler disables the Find Me profile - Target Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int findl_set_alert_cmd_handler(ke_msg_id_t const msgid, + struct findl_set_alert_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + int msg_status = KE_MSG_CONSUMED; + + if (state == FINDL_IDLE) + { + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get the address of the environment + struct findl_env_tag *p_findl_env = PRF_ENV_GET(FINDL, findl); + uint8_t conidx = KE_IDX_GET(dest_id); + struct findl_cmp_evt *p_evt; + + // check if discovery performed + if (p_findl_env->p_env[conidx] == NULL) + { + status = PRF_ERR_REQ_DISALLOWED; + } + // Check we're sending a correct value + else if ((p_param->alert_lvl == FINDL_ALERT_NONE) || + (p_param->alert_lvl == FINDL_ALERT_MILD) || + (p_param->alert_lvl == FINDL_ALERT_HIGH)) + { + if (p_findl_env->p_env[conidx]->ias.alert_lvl_char.char_hdl != 0x0000) + { + // Send GATT Write Request + prf_gatt_write(&p_findl_env->prf_env, conidx, + p_findl_env->p_env[conidx]->ias.alert_lvl_char.val_hdl, + (uint8_t *)&p_param->alert_lvl, sizeof(uint8_t), GATTC_WRITE_NO_RESPONSE); + + // wait for end of write request + ke_state_set(dest_id, FINDL_BUSY); + } + else + { + // cannot set alert level because have no char handle for it + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + // wrong level - not one of the possible 3 + status = PRF_ERR_INVALID_PARAM; + } + + p_evt = KE_MSG_ALLOC(FINDL_CMP_EVT, src_id, dest_id, findl_cmp_evt); + // set status + p_evt->status = status; + p_evt->operation = FINDL_SET_ALERT_CMD_OP_CODE; + + ke_msg_send(p_evt); + } + else if (state != FINDL_FREE) + { + msg_status = KE_MSG_SAVED;; + } + // else nothing to do - ignore message + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Get the address of the environment + struct findl_env_tag *p_findl_env = PRF_ENV_GET(FINDL, findl); + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == FINDL_DISCOVERING) + { + uint8_t status = p_param->status; + + if (p_param->status == ATT_ERR_NO_ERROR) + { + if (p_findl_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(FINDL_IAS_CHAR_MAX, + &(p_findl_env->p_env[conidx]->ias.alert_lvl_char), findl_ias_char); + } + // too much services + else if (p_findl_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + + findl_enable_rsp_send(p_findl_env, conidx, status); + } + else if (state == FINDL_BUSY) + { + ke_state_set(dest_id, FINDL_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(findl) +{ + {FINDL_ENABLE_REQ, (ke_msg_func_t)findl_enable_req_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {FINDL_SET_ALERT_CMD, (ke_msg_func_t)findl_set_alert_cmd_handler}, +}; + +void findl_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct findl_env_tag *p_findl_env = PRF_ENV_GET(FINDL, findl); + + p_task_desc->msg_handler_tab = findl_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(findl_msg_handler_tab); + p_task_desc->state = p_findl_env->state; + p_task_desc->idx_max = FINDL_IDX_MAX; +} + +#endif //BLE_FINDME_LOCATOR + +/// @} FINDLTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/api/findt_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/api/findt_task.h new file mode 100644 index 0000000..d708ad4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/api/findt_task.h @@ -0,0 +1,72 @@ +/** + **************************************************************************************** + * + * @file findt_task.h + * + * @brief Header file - FINDTTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef FINDT_TASK_H_ +#define FINDT_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup FINDTTASK Find Me Target Task + * @ingroup FINDT + * @brief Find Me Target Task + * + * The FINDTTASK is responsible for handling the APi messages from the application or + * internal tasks. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include +#include "rwip_task.h" // Task definitions +#include "find_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Messages for Find Me Target +/*@TRACE*/ +enum findt_msg_id +{ + /// Alert indication + FINDT_ALERT_IND = TASK_FIRST_MSG(TASK_ID_FINDT), +}; + +/// Parameters of the @ref FINDT_ALERT_IND message +struct findt_alert_ind +{ + /// Alert level + uint8_t alert_lvl; + /// Connection index + uint8_t conidx; +}; + +/* + * API MESSAGES STRUCTURES + **************************************************************************************** + */ +/// Parameters for the database creation +struct findt_db_cfg +{ + /// Database configuration + uint8_t dummy; +}; + +/// @} FINDTTASK +#endif // FINDT_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/sourcelist.txt new file mode 100644 index 0000000..5263c27 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + findt.c + findt_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/src/findt.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/src/findt.c new file mode 100644 index 0000000..0a4ed51 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/src/findt.c @@ -0,0 +1,186 @@ +/** + **************************************************************************************** + * + * @file findt.c + * + * @brief Find Me Target implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup FINDT + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_FINDME_TARGET) +#include "findt.h" +#include "findt_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" + +/* + * FINDT PROFILE ATTRIBUTES + **************************************************************************************** + */ +/// Full IAS Database Description - Used to add attributes into the database +const struct attm_desc findt_att_db[FINDT_IAS_IDX_NB] = +{ + // Immediate Alert Service Declaration + [FINDT_IAS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + // Alert Level Characteristic Declaration + [FINDT_IAS_IDX_ALERT_LVL_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Alert Level Characteristic Value + [FINDT_IAS_IDX_ALERT_LVL_VAL] = {ATT_CHAR_ALERT_LEVEL, PERM(WRITE_COMMAND, ENABLE), + PERM(RI, ENABLE), sizeof(uint8_t)}, +}; + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the FINDT module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t findt_init (struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct findt_db_cfg *p_params) +{ + //------------------ create the attribute database for the profile ------------------- + + // Service content flag + uint32_t cfg_flag = FINDT_MANDATORY_MASK; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + status = attm_svc_create_db(p_start_hdl, ATT_SVC_IMMEDIATE_ALERT, (uint8_t *)&cfg_flag, + FINDT_IAS_IDX_NB, NULL, p_env->task, &findt_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, DISABLE) ); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + struct findt_env_tag *p_findt_env = + (struct findt_env_tag *) ke_malloc(sizeof(struct findt_env_tag), KE_MEM_ATT_DB); + + // allocate FINDT required environment variable + p_env->env = (prf_env_t *) p_findt_env; + p_findt_env->shdl = *p_start_hdl; + p_findt_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_findt_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + + // initialize environment variable + p_env->id = TASK_ID_FINDT; + findt_task_init(&(p_env->desc)); + + // service is ready, go into an Idle state + ke_state_set(p_env->task, FINDT_IDLE); + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the FINDT module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void findt_destroy(struct prf_task_env *p_env) +{ + struct findt_env_tag *p_findt_env = (struct findt_env_tag *) p_env->env; + + // free profile environment variables + p_env->env = NULL; + ke_free(p_findt_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void findt_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // nothing to do +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void findt_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + // nothing to do +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// FINDT Task interface required by profile manager +const struct prf_task_cbs findt_itf = +{ + (prf_init_fnct) findt_init, + findt_destroy, + findt_create, + findt_cleanup, +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *findt_prf_itf_get(void) +{ + return &findt_itf; +} + + +#endif //BLE_FINDME_TARGET + +/// @} FINDT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/src/findt.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/src/findt.h new file mode 100644 index 0000000..e43ae52 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/src/findt.h @@ -0,0 +1,167 @@ +/** + **************************************************************************************** + * + * @file findt.h + * + * @brief Header file - FINDT. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef FINDT_H_ +#define FINDT_H_ + +/** + **************************************************************************************** + * @addtogroup FINDT Find Me Target + * @ingroup FIND + * @brief Find Me Profile Target. + * + * In the Find Me BLE Profile, the device that is in Target role will act as GATT server. + * + * The Target will react to alert levels written by the Locator in the Alert Level + * Characteristic of the Immediate Alert Service(IAS) present in the ATT DB of the device. + * + * The interface of this role to the Application is: + * - Enable the profile role (from APP) + * - Disable the profile role (from APP) + * - Indicate that the alert level has been written by the Locator. (to APP) + * + * There shall be only one IAS instance on the device. There shall be only one + * Alert Level Characteristic in the IAS. The characteristic properties shall be + * Write No Response only. + * + * The enable/disable of the profile and devices disconnection is handled in the application, + * depending on its User Input. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#include "find_common.h" +#if (BLE_FINDME_TARGET) +#include +#include +#include "gap.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of instances of the Find Me Target task +#define FINDT_IDX_MAX 0x01 + +#define FINDT_MANDATORY_MASK (0x07) + +/// Possible states of the FINDT task +enum findt_state +{ + /// Idle state + FINDT_IDLE, + + /// Number of defined states. + FINDT_STATE_MAX +}; + +/// Find Me Target environment variable +struct findt_env_tag +{ + /// profile environment + prf_env_t prf_env; + ///IAS Start Handle + uint16_t shdl; + /// State of different task instances + ke_state_t state[FINDT_IDX_MAX]; +}; + +/* + * MACROS + **************************************************************************************** + */ + +/// Get database attribute handle +#define FINDT_HANDLE(idx) \ + (p_findt_env->start_hdl + (idx) ) + +/// Get database attribute index +#define FINDT_IDX(hdl) \ + ( (hdl) - p_findt_env->shdl ) + +/* + * ENUMS + **************************************************************************************** + */ + +///FINDT Attributes database handle list +enum findt_att_db_handles +{ + FINDT_IAS_IDX_SVC, + + FINDT_IAS_IDX_ALERT_LVL_CHAR, + FINDT_IAS_IDX_ALERT_LVL_VAL, + + FINDT_IAS_IDX_NB, +}; + +/// Alert levels +enum +{ + /// No alert + FINDT_ALERT_NONE = 0x00, + /// Mild alert + FINDT_ALERT_MILD, + /// High alert + FINDT_ALERT_HIGH +}; + + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve IAS service profile interface + * + * @return IAS service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *findt_prf_itf_get(void); + + +/* + * GLOBAL VARIABLES DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void findt_task_init(struct ke_task_desc *p_task_desc); + +#endif //BLE_FINDME_TARGET + +/// @} FINDT + +#endif // FINDT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/src/findt_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/src/findt_task.c new file mode 100644 index 0000000..0e31d68 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/find/findt/src/findt_task.c @@ -0,0 +1,124 @@ +/** + **************************************************************************************** + * + * @file findt_task.c + * + * @brief Find Me Target Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup FINDTTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_FINDME_TARGET) +#include "co_utils.h" +#include "gattc_task.h" +#include "findt_task.h" +#include "findt.h" +#include "attm.h" +#include "prf_utils.h" + + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * The message is redirected from TASK_SVC because at profile enable, the ATT handle is + * register for TASK_FINDT. In the handler, an ATT Write Response/Error Response should + * be sent for ATT protocol, but Alert Level Characteristic only supports WNR so no + * response PDU is needed. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Allocate write confirmation message. + struct gattc_write_cfm *cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, + src_id, dest_id, gattc_write_cfm); + + // Get the address of the environment + struct findt_env_tag *p_findt_env = PRF_ENV_GET(FINDT, findt); + uint8_t att_idx = FINDT_IDX(p_param->handle); + + // Fill in the parameter structure + cfm->handle = p_param->handle; + cfm->status = PRF_APP_ERROR; + + // Check if Alert Level is valid + if ((att_idx == FINDT_IAS_IDX_ALERT_LVL_VAL) && (p_param->value[0] <= FINDT_ALERT_HIGH)) + { + struct findt_alert_ind *p_ind; + uint8_t alert_lvl = 0x0000; + uint8_t conidx = KE_IDX_GET(src_id); + + alert_lvl = p_param->value[0]; + cfm->status = GAP_ERR_NO_ERROR; + + // Allocate the alert value change indication + p_ind = KE_MSG_ALLOC(FINDT_ALERT_IND, + prf_dst_task_get(&(p_findt_env->prf_env), conidx), + dest_id, findt_alert_ind); + // Fill in the parameter structure + p_ind->alert_lvl = alert_lvl; + p_ind->conidx = conidx; + + // Send the message + ke_msg_send(p_ind); + } + + // Send the message + ke_msg_send(cfm); + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(findt) +{ + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, +}; + +void findt_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct findt_env_tag *p_findt_env = PRF_ENV_GET(FINDT, findt); + + p_task_desc->msg_handler_tab = findt_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(findt_msg_handler_tab); + p_task_desc->state = p_findt_env->state; + p_task_desc->idx_max = FINDT_IDX_MAX; +} + +#endif //BLE_FINDME_TARGET + +/// @} FINDTTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glp_common.h new file mode 100644 index 0000000..25d874f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glp_common.h @@ -0,0 +1,631 @@ +/** + **************************************************************************************** + * + * @file glp_common.h + * + * @brief Header File - Glucose Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _GLP_COMMON_H_ +#define _GLP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup GLP Glucose Profile + * @ingroup PROFILE + * @brief Glucose Profile + * + * The GLP module is the responsible block for implementing the Glucose Profile + * functionalities in the BLE Host. + * + * The Glucose Profile defines the functionality required in a device that allows + * the user (Collector device) to configure and recover Glucose measurements from + * a Glucose device. + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include "prf_types.h" +#include +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Glucose measurement packet max length +#define GLP_MEAS_MAX_LEN (17) +/// Glucose measurement context packet max length +#define GLP_MEAS_CTX_MAX_LEN (17) +/// Record Access Control Point packet max length +#define GLP_REC_ACCESS_CTRL_MAX_LEN (21) + + +/// Glucose Service Error Code +enum glp_error_code +{ + /// RACP Procedure already in progress + GLP_ERR_PROC_ALREADY_IN_PROGRESS = (0x80), + /// Client Characteristic Configuration Descriptor Improperly Configured + GLP_ERR_IMPROPER_CLI_CHAR_CFG = (0x81), +}; + +/// Glucose Measurement Flags field bit values +enum glp_meas_flag_bf +{ + /// Time Offset Present Bit + /// Time Offset Present + GLP_MEAS_TIME_OFF_PRES_POS = 0, + GLP_MEAS_TIME_OFF_PRES_BIT = CO_BIT(GLP_MEAS_TIME_OFF_PRES_POS), + + /// Glucose Concentration, Type and Sample Location Present Bit + /// Glucose Concentration, Type and Sample Location Present + GLP_MEAS_GL_CTR_TYPE_AND_SPL_LOC_PRES_POS = 1, + GLP_MEAS_GL_CTR_TYPE_AND_SPL_LOC_PRES_BIT = CO_BIT(GLP_MEAS_GL_CTR_TYPE_AND_SPL_LOC_PRES_POS), + + /// Glucose Concentration Units + /// 0 for kg/L; 1 for mol/L + GLP_MEAS_GL_CTR_UNITS_POS = 2, + GLP_MEAS_GL_CTR_UNITS_BIT = CO_BIT(GLP_MEAS_GL_CTR_UNITS_POS), + + /// Sensor Status Annunciation Present Bit + /// Sensor Status Annunciation Present + GLP_MEAS_SENS_STAT_ANNUN_PRES_POS = 3, + GLP_MEAS_SENS_STAT_ANNUN_PRES_BIT = CO_BIT(GLP_MEAS_SENS_STAT_ANNUN_PRES_POS), + + /// Context Information Follow Bit + /// Context Information Follows + GLP_MEAS_CTX_INF_FOLW_POS = 4, + GLP_MEAS_CTX_INF_FOLW_BIT = CO_BIT(GLP_MEAS_CTX_INF_FOLW_POS), + + // Bit 5 - 7 RFU +}; + +/// Glucose Measurement Context Flags field bit values +enum glp_meas_ctx_flag_bf +{ + /// Carbohydrate ID And Carbohydrate Present Bit + /// Carbohydrate ID And Carbohydrate Present + GLP_CTX_CRBH_ID_AND_CRBH_PRES_POS = 0, + GLP_CTX_CRBH_ID_AND_CRBH_PRES_BIT = CO_BIT(GLP_CTX_CRBH_ID_AND_CRBH_PRES_POS), + + /// Meal Present Bit + /// Meal Present + GLP_CTX_MEAL_PRES_POS = 1, + GLP_CTX_MEAL_PRES_BIT = CO_BIT(GLP_CTX_MEAL_PRES_POS), + + /// Tester-Health Present Bit + /// Tester-Health Present + GLP_CTX_TESTER_HEALTH_PRES_POS = 2, + GLP_CTX_TESTER_HEALTH_PRES_BIT = CO_BIT(GLP_CTX_TESTER_HEALTH_PRES_POS), + + /// Exercise Duration And Exercise Intensity Present Bit + /// Exercise Duration And Exercise Intensity Present + GLP_CTX_EXE_DUR_AND_EXE_INTENS_PRES_POS = 3, + GLP_CTX_EXE_DUR_AND_EXE_INTENS_PRES_BIT = CO_BIT(GLP_CTX_EXE_DUR_AND_EXE_INTENS_PRES_POS), + + /// Medication ID And Medication Present Bit + /// Medication ID And Medication Present + GLP_CTX_MEDIC_ID_AND_MEDIC_PRES_POS = 4, + GLP_CTX_MEDIC_ID_AND_MEDIC_PRES_BIT = CO_BIT(GLP_CTX_MEDIC_ID_AND_MEDIC_PRES_POS), + + /// Medication Value Units + /// 0 for kilograms; 1 for liters + GLP_CTX_MEDIC_VAL_UNITS_POS = 5, + GLP_CTX_MEDIC_VAL_UNITS_BIT = CO_BIT(GLP_CTX_MEDIC_VAL_UNITS_POS), + + /// HbA1c Present Bit + /// HbA1c Present + GLP_CTX_HBA1C_PRES_POS = 6, + GLP_CTX_HBA1C_PRES_BIT = CO_BIT(GLP_CTX_HBA1C_PRES_POS), + + /// Extended Flags Present Bit + /// Extended Flags Present + GLP_CTX_EXTD_F_PRES_POS = 7, + GLP_CTX_EXTD_F_PRES_BIT = CO_BIT(GLP_CTX_EXTD_F_PRES_POS), +}; + +/// Glucose Service Feature Flags field bit values +enum glp_srv_feature_flag +{ + /// Low Battery Detection During Measurement Support Bit + /// Low Battery Detection During Measurement Supported + GLP_FET_LOW_BAT_DET_DUR_MEAS_SUPP_POS = 0, + GLP_FET_LOW_BAT_DET_DUR_MEAS_SUPP_BIT = CO_BIT(GLP_FET_LOW_BAT_DET_DUR_MEAS_SUPP_POS), + + /// Sensor Malfunction Detection Support Bit + /// Sensor Malfunction Detection Supported + GLP_FET_SENS_MFNC_DET_SUPP_POS = 1, + GLP_FET_SENS_MFNC_DET_SUPP_BIT = CO_BIT(GLP_FET_SENS_MFNC_DET_SUPP_POS), + + /// Sensor Sample Size Support Bit + /// Sensor Sample Size Supported + GLP_FET_SENS_SPL_SIZE_SUPP_POS = 2, + GLP_FET_SENS_SPL_SIZE_SUPP_BIT = CO_BIT(GLP_FET_SENS_SPL_SIZE_SUPP_POS), + + /// Sensor Strip Insertion Error Detection Support Bit + /// Sensor Strip Insertion Error Detection Supported + GLP_FET_SENS_STRIP_INSERT_ERR_DET_SUPP_POS = 3, + GLP_FET_SENS_STRIP_INSERT_ERR_DET_SUPP_BIT = CO_BIT(GLP_FET_SENS_STRIP_INSERT_ERR_DET_SUPP_POS), + + /// Sensor Strip Type Error Detection Support Bit + /// Sensor Strip Type Error Detection Supported + GLP_FET_SENS_STRIP_TYPE_ERR_DET_SUPP_POS = 4, + GLP_FET_SENS_STRIP_TYPE_ERR_DET_SUPP_BIT = CO_BIT(GLP_FET_SENS_STRIP_TYPE_ERR_DET_SUPP_POS), + + /// Sensor Result High-Low Detection Support Bit + /// Sensor Result High-Low Detection Supported + GLP_FET_SENS_RES_HIGH_LOW_DET_SUPP_POS = 5, + GLP_FET_SENS_RES_HIGH_LOW_DET_SUPP_BIT = CO_BIT(GLP_FET_SENS_RES_HIGH_LOW_DET_SUPP_POS), + + /// Sensor Temperature High-Low Detection Support Bit + /// Sensor Temperature High-Low Detection Supported + GLP_FET_SENS_TEMP_HIGH_LOW_DET_SUPP_POS = 6, + GLP_FET_SENS_TEMP_HIGH_LOW_DET_SUPP_BIT = CO_BIT(GLP_FET_SENS_TEMP_HIGH_LOW_DET_SUPP_POS), + + /// Sensor Read Interrupt Detection Support Bit + /// Sensor Read Interrupt Detection Supported + GLP_FET_SENS_RD_INT_DET_SUPP_POS = 7, + GLP_FET_SENS_RD_INT_DET_SUPP_BIT = CO_BIT(GLP_FET_SENS_RD_INT_DET_SUPP_POS), + + /// General Device Fault Support Bit + /// General Device Fault Supported + GLP_FET_GEN_DEV_FLT_SUPP_POS = 8, + GLP_FET_GEN_DEV_FLT_SUPP_BIT = CO_BIT(GLP_FET_GEN_DEV_FLT_SUPP_POS), + + /// Time Fault Support Bit + /// Time Fault Supported + GLP_FET_TIME_FLT_SUPP_POS = 9, + GLP_FET_TIME_FLT_SUPP_BIT = CO_BIT(GLP_FET_TIME_FLT_SUPP_POS), + + /// Multiple Bond Support Bit + /// Multiple Bond Supported + GLP_FET_MUL_BOND_SUPP_POS = 10, + GLP_FET_MUL_BOND_SUPP_BIT = CO_BIT(GLP_FET_MUL_BOND_SUPP_POS), + + // BIT 11 - 15 RFU +}; + +/// Glucose measurement Sensor Status Annunciation +enum glp_meas_state_bf +{ + /// Device battery low at time of measurement + GLP_MEAS_STATE_DEV_BAT_LOW_POS = 0, + GLP_MEAS_STATE_DEV_BAT_LOW_BIT = CO_BIT(GLP_MEAS_STATE_DEV_BAT_LOW_POS), + + /// Sensor malfunction or faulting at time of measurement + GLP_MEAS_STATE_SENS_MFNC_OR_FLTING_POS = 1, + GLP_MEAS_STATE_SENS_MFNC_OR_FLTING_BIT = CO_BIT(GLP_MEAS_STATE_SENS_MFNC_OR_FLTING_POS), + + /// Sample size for blood or control solution insufficient at time of measurement + GLP_MEAS_STATE_SPL_SIZE_INSUFF_POS = 2, + GLP_MEAS_STATE_SPL_SIZE_INSUFF_BIT = CO_BIT(GLP_MEAS_STATE_SPL_SIZE_INSUFF_POS), + + /// Strip insertion error + GLP_MEAS_STATE_STRIP_INSERT_ERR_POS = 3, + GLP_MEAS_STATE_STRIP_INSERT_ERR_BIT = CO_BIT(GLP_MEAS_STATE_STRIP_INSERT_ERR_POS), + + /// Strip type incorrect for device + GLP_MEAS_STATE_STRIP_TYPE_INCOR_FOR_DEV_POS = 4, + GLP_MEAS_STATE_STRIP_TYPE_INCOR_FOR_DEV_BIT = CO_BIT(GLP_MEAS_STATE_STRIP_TYPE_INCOR_FOR_DEV_POS), + + /// Sensor result higher than the device can process + GLP_MEAS_STATE_SENS_RES_HIGHER_POS = 5, + GLP_MEAS_STATE_SENS_RES_HIGHER_BIT = CO_BIT(GLP_MEAS_STATE_SENS_RES_HIGHER_POS), + + /// Sensor result lower than the device can process + GLP_MEAS_STATE_SENS_RES_LOWER_POS = 6, + GLP_MEAS_STATE_SENS_RES_LOWER_BIT = CO_BIT(GLP_MEAS_STATE_SENS_RES_LOWER_POS), + + /// Sensor temperature too high for valid test/result at time of measurement + GLP_MEAS_STATE_SENS_TEMP_TOO_HIGH_POS = 7, + GLP_MEAS_STATE_SENS_TEMP_TOO_HIGH_BIT = CO_BIT(GLP_MEAS_STATE_SENS_TEMP_TOO_HIGH_POS), + + /// Sensor temperature too low for valid test/result at time of measurement + GLP_MEAS_STATE_SENS_TEMP_TOO_LOW_POS = 8, + GLP_MEAS_STATE_SENS_TEMP_TOO_LOW_BIT = CO_BIT(GLP_MEAS_STATE_SENS_TEMP_TOO_LOW_POS), + + /// Sensor read interrupted because strip was pulled too soon at time of measurement + GLP_MEAS_STATE_SENS_RD_INTED_POS = 9, + GLP_MEAS_STATE_SENS_RD_INTED_BIT = CO_BIT(GLP_MEAS_STATE_SENS_RD_INTED_POS), + + /// General device fault has occurred in the sensor + GLP_MEAS_STATE_GEN_DEV_FLT_POS = 10, + GLP_MEAS_STATE_GEN_DEV_FLT_BIT = CO_BIT(GLP_MEAS_STATE_GEN_DEV_FLT_POS), + + /// Time fault has occurred in the sensor and time may be inaccurate + GLP_MEAS_STATE_TIME_FLT_POS = 11, + GLP_MEAS_STATE_TIME_FLT_BIT = CO_BIT(GLP_MEAS_STATE_TIME_FLT_POS), + + // Bit 12 - 15 RFU +}; + + +/// Glucose measurement type +enum glp_meas_type +{ + /// Capillary Whole blood + GLP_TYPE_CAPILLARY_WHOLE_BLOOD = (1), + + /// Capillary Plasma + GLP_TYPE_CAPILLARY_PLASMA = (2), + + /// Venous Whole blood + GLP_TYPE_VENOUS_WHOLE_BLOOD = (3), + + /// Venous Plasma + GLP_TYPE_VENOUS_PLASMA = (4), + + /// Arterial Whole blood + GLP_TYPE_ARTERIAL_WHOLE_BLOOD = (5), + + /// Arterial Plasma + GLP_TYPE_ARTERIAL_PLASMA = (6), + + /// Undetermined Whole blood + GLP_TYPE_UNDETERMINED_WHOLE_BLOOD = (7), + + /// Undetermined Plasma + GLP_TYPE_UNDETERMINED_PLASMA = (8), + + /// Interstitial Fluid (ISF) + GLP_TYPE_INTERSTITIAL_FLUID = (9), + + /// Control Solution + GLP_TYPE_CTRL_SOLUTION = (10), +}; + + +/// Glucose measurement Sample Location +enum glp_meas_loc +{ + /// Finger + GLP_LOC_FINGER = (1), + + /// Alternate Site Test (AST) + GLP_LOC_ALT_SITE_TEST = (2), + + /// Earlobe + GLP_LOC_EARLOBE = (3), + + /// Control solution + GLP_LOC_CTRL_SOLUTION = (4), + + /// Sample Location value not available + GLP_LOC_SPL_LOC_VAL_NOT_AVA = (15), +}; + +/// Glucose measurement context Carbohydrate ID +enum glp_meas_ctx_carbo +{ + /// Breakfast + GLP_CID_BREAKFAST = (1), + + /// Lunch + GLP_CID_LUNCH = (2), + + /// Dinner + GLP_CID_DINNER = (3), + + /// Snack + GLP_CID_SNACK = (4), + + /// Drink + GLP_CID_DRINK = (5), + + /// Supper + GLP_CID_SUPPER = (6), + + /// Brunch + GLP_CID_BRUNCH = (7), +}; + +/// Glucose measurement context Meal +enum glp_meas_ctx_meal +{ + /// Preprandial (before meal) + GLP_MEAL_PREPRANDIAL = (1), + + /// Postprandial (after meal) + GLP_MEAL_POSTPRANDIAL = (2), + + /// Fasting + GLP_MEAL_FASTING = (3), + + /// Casual (snacks, drinks, etc.) + GLP_MEAL_CASUAL = (4), + + /// Bedtime + GLP_MEAL_BEDTIME = (5), +}; + +/// Glucose measurement context tester type +enum glp_meas_ctx_tester_type +{ + /// Self + GLP_TESTER_SELF = (1), + + /// Health Care Professional + GLP_TESTER_HEALTH_CARE_PROFESSIONAL = (2), + + /// Lab test + GLP_TESTER_LAB_TEST = (3), + + /// Tester value not available + GLP_TESTER_TESTER_VAL_NOT_AVA = (15), +}; + +/// Glucose measurement context personal health feeling +enum glp_meas_ctx_feeling +{ + /// Minor health issues + GLP_HEALTH_MINOR_HEALTH_ISSUES = (1), + + /// Major health issues + GLP_HEALTH_MAJOR_HEALTH_ISSUES = (2), + + /// During menses + GLP_HEALTH_DUR_MENSES = (3), + + /// Under stress + GLP_HEALTH_UNDER_STRESS = (4), + + /// No health issues + GLP_HEALTH_NO_HEALTH_ISSUES = (5), + + /// Health value not available + GLP_HEALTH_HEALTH_VAL_NOT_AVA = (15), +}; + +/// Glucose measurement context medication identification +enum glp_meas_ctx_med_id +{ + /// Rapid acting insulin + GLP_MEDID_RAPID_ACTING_INSULIN = (1), + + /// Short acting insulin + GLP_MEDID_SHORT_ACTING_INSULIN = (2), + + /// Intermediate acting insulin + GLP_MEDID_INTER_ACTING_INSULIN = (3), + + /// Long acting insulin + GLP_MEDID_LONG_ACTING_INSULIN = (4), + + /// Pre-mixed insulin + GLP_MEDID_PRE_MIXED_INSULIN = (5), +}; + + +/// Glucose access control OP Code +enum glp_racp_op_code +{ + /// Report stored records (Operator: Value from Operator Table) + GLP_REQ_REP_STRD_RECS = (1), + + /// Delete stored records (Operator: Value from Operator Table) + GLP_REQ_DEL_STRD_RECS = (2), + + /// Abort operation (Operator: Null 'value of 0x00 from Operator Table') + GLP_REQ_ABORT_OP = (3), + + /// Report number of stored records (Operator: Value from Operator Table) + GLP_REQ_REP_NUM_OF_STRD_RECS = (4), + + /// Number of stored records response (Operator: Null 'value of 0x00 from Operator Table') + GLP_REQ_NUM_OF_STRD_RECS_RSP = (5), + + /// Response Code (Operator: Null 'value of 0x00 from Operator Table') + GLP_REQ_RSP_CODE = (6), +}; + +/// Glucose access control Operator +enum glp_racp_operator +{ + /// All records + GLP_OP_ALL_RECS = (1), + + /// Less than or equal to + GLP_OP_LT_OR_EQ = (2), + + /// Greater than or equal to + GLP_OP_GT_OR_EQ = (3), + + /// Within range of (inclusive) + GLP_OP_WITHIN_RANGE_OF = (4), + + /// First record(i.e. oldest record) + GLP_OP_FIRST_REC = (5), + + /// Last record (i.e. most recent record) + GLP_OP_LAST_REC = (6), +}; + +/// Glucose access control response code +enum glp_racp_status +{ + /// Success + GLP_RSP_SUCCESS = (1), + + /// Op Code not supported + GLP_RSP_OP_CODE_NOT_SUP = (2), + + /// Invalid Operator + GLP_RSP_INVALID_OPERATOR = (3), + + /// Operator not supported + GLP_RSP_OPERATOR_NOT_SUP = (4), + + /// Invalid Operand + GLP_RSP_INVALID_OPERAND = (5), + + /// No records found + GLP_RSP_NO_RECS_FOUND = (6), + + /// Abort unsuccessful + GLP_RSP_ABORT_UNSUCCESSFUL = (7), + + /// Procedure not completed + GLP_RSP_PROCEDURE_NOT_COMPLETED = (8), + + /// Operand not supported + GLP_RSP_OPERAND_NOT_SUP = (9), +}; + + +/// record access control filter type +enum glp_racp_filter +{ + /// Filter using Sequence number + GLP_FILTER_SEQ_NUMBER = (1), + /// Filter using Facing time + GLP_FILTER_USER_FACING_TIME = (2), +}; + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Glucose measurement +struct glp_meas +{ + /// Base Time + struct prf_date_time base_time; + /// Time Offset + int16_t time_offset; + /// Glucose Concentration - units of kg/L or mol/L + prf_sfloat concentration; + /// Sensor Status Annunciation @see enum glp_meas_state_bf + uint16_t status; + /// Type + uint8_t type; + /// Sample Location + uint8_t location; + /// Flags + uint8_t flags; +}; + +/// Glucose measurement context +struct glp_meas_ctx +{ + /// Carbohydrate - units of kilograms + prf_sfloat carbo_val; + /// Exercise Duration + uint16_t exercise_dur; + /// Medication value (units of kilograms or liters) + prf_sfloat med_val; + /// HbA1c value + prf_sfloat hba1c_val; + + /// Carbohydrate ID + uint8_t carbo_id; + /// Meal + uint8_t meal; + /// Tester + uint8_t tester; + /// Health + uint8_t health; + /// Exercise Intensity + uint8_t exercise_intens; + /// Medication ID + uint8_t med_id; + + /// Flag + uint8_t flags; + /// Extended Flags + uint8_t ext_flags; +}; + + +/// Record access control point operation filter +struct glp_filter +{ + /// function operator + uint8_t operator; + + /// filter type + uint8_t filter_type; + + /// filter union + union + { + /// Sequence number filtering (filter_type = GLP_FILTER_SEQ_NUMBER) + struct + { + /// Min sequence number + uint16_t min; + /// Max sequence number + uint16_t max; + }seq_num; + + /// User facing time filtering (filter_type = GLP_FILTER_USER_FACING_TIME) + struct + { + /// Min base time + struct prf_date_time facetime_min; + + /// Max base time + struct prf_date_time facetime_max; + } time; + } val; +}; + + + +/// Record access control point request +struct glp_racp_req +{ + /// operation code + uint8_t op_code; + + /// operation filter + struct glp_filter filter; +}; + + + +/// Record access control point response +struct glp_racp_rsp +{ + /// operation code + uint8_t op_code; + + /// operator (ignored, always set to null) + uint8_t operator; + + /// response operand + union + { + /// Number of record (if op_code = GLP_REQ_NUM_OF_STRD_RECS_RSP) + uint16_t num_of_record; + + /// Command Status (if op_code = GLP_REQ_RSP_CODE) + struct + { + /// Request Op Code + uint8_t op_code_req; + /// Response Code status + uint8_t status; + } rsp; + } operand; +}; + + + +/// @} glp_common + +#endif /* _GLP_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/api/glpc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/api/glpc_task.h new file mode 100644 index 0000000..2a1e4ea --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/api/glpc_task.h @@ -0,0 +1,238 @@ +/** + **************************************************************************************** + * + * @file glpc_task.h + * + * @brief Header file - Glucose Profile Collector Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _GLPC_TASK_H_ +#define _GLPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup GLPCTASK Glucose Profile Collector Task + * @ingroup GLPC + * @brief Glucose Profile Collector Task + * + * The GLPCTASK is responsible for handling the messages coming in and out of the + * @ref GLPC monitor block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" +#include "glp_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/*@TRACE*/ +enum glpc_msg_id +{ + /// Start the Glucose Profile - at connection + GLPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_GLPC), + /// Confirm that cfg connection has finished with discovery results, or that normal cnx started + GLPC_ENABLE_RSP, + + /// Register to Glucose sensor notifications - request + GLPC_REGISTER_CMD, + + /// Read Glucose sensor characteristic + GLPC_READ_CMD, + /// Read Glucose sensor characteristic indication + GLPC_READ_IND, + + /// Record Access Control Point Command + GLPC_RACP_CMD, + /// Record Access Control Point - Resp + GLPC_RACP_IND, + + /// Glucose measurement value received + GLPC_MEAS_IND, + + /// Glucose measurement context received + GLPC_MEAS_CTX_IND, + + /// Complete Event Information + GLPC_CMP_EVT, + + /// Glucose Record Access Control Point Request Timeout + GLPC_RACP_CMD_TIMEOUT, +}; + +/// Characteristics +enum glpc_char_code +{ + /// Glucose Measurement + GLPC_CHAR_MEAS, + /// Glucose Measurement Context + GLPC_CHAR_MEAS_CTX, + /// Glucose Sensor Feature + GLPC_CHAR_FEATURE, + /// Record Access control point + GLPC_CHAR_RACP, + + GLPC_CHAR_MAX, +}; + + +/// Characteristic descriptors +enum glpc_desc_code +{ + /// Glucose Measurement client config + GLPC_DESC_MEAS_CLI_CFG, + /// Glucose Measurement context client config + GLPC_DESC_MEAS_CTX_CLI_CFG, + /// Record Access control point client config + GLPC_DESC_RACP_CLI_CFG, + + GLPC_DESC_MAX, +}; + +/// Operation codes +enum glpc_op_codes +{ + /// Database Creation Procedure + GLPC_RESERVED_OP_CODE = 0, + + /// Configure CCC Operation Code + GLPC_REGISTER_CMD_OP_CODE = 1, + + /// Read Operation Code + GLPC_READ_CMD_OP_CODE = 2, + + /// RACP Operation Code + GLPC_RACP_CMD_OP_CODE = 3, +}; + +///Structure containing the characteristics handles, value handles and descriptors +struct gls_content +{ + /// service info + struct prf_svc svc; + + /// characteristic info: + /// - Glucose Measurement + /// - Glucose Measurement Context + /// - Glucose Feature + /// - Record Access Control Point + struct prf_char_inf chars[GLPC_CHAR_MAX]; + + /// Descriptor handles:info: + /// - Glucose Measurement client cfg + /// - Glucose Measurement Context client cfg + /// - Record Access Control Point client cfg + struct prf_char_desc_inf descs[GLPC_DESC_MAX]; +}; + +/// Parameters of the @ref GLPC_ENABLE_REQ message +struct glpc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values gls + struct gls_content gls; +}; + +/// Parameters of the @ref GLPC_ENABLE_RSP message +struct glpc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values gls + struct gls_content gls; +}; + +/// Parameters of the @ref GLPC_REGISTER_CMD message +struct glpc_register_cmd +{ + /// Register or not Glucose measurement context notifications + bool meas_ctx_en; +}; + +/// Parameters of the @ref GLPC_READ_CMD message +struct glpc_read_cmd +{ + /// Glucose sensor read characteristic code @see enum glpc_read_code + uint8_t read_code; +}; + +/// Parameters of the @ref GLPC_READ_IND message +struct glpc_read_ind +{ + /// Read value + union + { + /// Glucose sensor features + uint16_t features; + + /// Client Characteristic Configuration Descriptor value + uint16_t ind_cfg; + } value; +}; + +/// Parameters of the @ref GLPC_RACP_CMD message +struct glpc_racp_cmd +{ + /// Record Access Control Point Request + struct glp_racp_req racp_req; +}; + +/// Parameters of the @ref GLPC_RACP_IND message +struct glpc_racp_ind +{ + ///record access control response + struct glp_racp_rsp racp_rsp; +}; + +/// Parameters of the @ref GLPC_MEAS_IND message +struct glpc_meas_ind +{ + /// Sequence Number + uint16_t seq_num; + /// Glucose measurement + struct glp_meas meas_val; +}; + +/// Parameters of the @ref GLPC_MEAS_CTX_IND message +struct glpc_meas_ctx_ind +{ + /// Sequence Number + uint16_t seq_num; + /// Glucose measurement + struct glp_meas_ctx ctx; +}; + +/// Parameters of the @ref GLPC_CMP_EVT message +struct glpc_cmp_evt +{ + /// Operation + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} GLPCTASK + +#endif /* _GLPC_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/sourcelist.txt new file mode 100644 index 0000000..c996368 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + glpc.c + glpc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/src/glpc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/src/glpc.c new file mode 100644 index 0000000..9aea341 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/src/glpc.c @@ -0,0 +1,497 @@ +/** + **************************************************************************************** + * + * @file glpc.c + * + * @brief Glucose Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup GLPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_GL_COLLECTOR) +#include "glpc.h" +#include "glpc_task.h" +#include "gap.h" + +#include "ke_mem.h" +#include "co_utils.h" + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Initialization of the GLPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t glpc_init (struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct glpc_env_tag *p_glpc_env = + (struct glpc_env_tag *) ke_malloc(sizeof(struct glpc_env_tag), KE_MEM_ATT_DB); + + // allocate GLPC required environment variable + p_env->env = (prf_env_t *) p_glpc_env; + + p_glpc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_glpc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_GLPC; + glpc_task_init(&(p_env->desc)); + + for (idx = 0; idx < GLPC_IDX_MAX; idx++) + { + p_glpc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), GLPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Destruction of the GLPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void glpc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct glpc_env_tag *p_glpc_env = (struct glpc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < GLPC_IDX_MAX; idx++) + { + if (p_glpc_env->p_env[idx] != NULL) + { + ke_free(p_glpc_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_glpc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void glpc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put GLP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), GLPC_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void glpc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct glpc_env_tag *p_glpc_env = (struct glpc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_glpc_env->p_env[conidx] != NULL) + { + ke_free(p_glpc_env->p_env[conidx]); + p_glpc_env->p_env[conidx] = NULL; + } + + // Put GLP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), GLPC_FREE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// GLPC Task interface required by profile manager +const struct prf_task_cbs glpc_itf = +{ + glpc_init, + glpc_destroy, + glpc_create, + glpc_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *glpc_prf_itf_get(void) +{ + return &glpc_itf; +} + + +void glpc_enable_rsp_send(struct glpc_env_tag *p_glpc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on GLPS + struct glpc_enable_rsp *p_rsp = KE_MSG_ALLOC(GLPC_ENABLE_RSP, + prf_dst_task_get(&(p_glpc_env->prf_env), conidx), + prf_src_task_get(&(p_glpc_env->prf_env), conidx), + glpc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->gls = p_glpc_env->p_env[conidx]->gls; + // Register GLPC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_glpc_env->prf_env), conidx, &(p_glpc_env->p_env[conidx]->gls.svc)); + // Go to IDLE state + ke_state_set(prf_src_task_get(&(p_glpc_env->prf_env), conidx), GLPC_IDLE); + } + + ke_msg_send(p_rsp); +} + +uint8_t glpc_unpack_meas_value(uint8_t *p_packed_meas, struct glp_meas *p_meas_val, + uint16_t *p_seq_num) +{ + uint8_t cursor = 0; + + // Flags + p_meas_val->flags = p_packed_meas[cursor]; + cursor += 1; + + // Sequence Number + *p_seq_num = co_read16p(p_packed_meas + cursor); + cursor += 2; + + // Base Time + cursor += prf_unpack_date_time(p_packed_meas + cursor, &(p_meas_val->base_time)); + + // Time Offset + if (GETB(p_meas_val->flags, GLP_MEAS_TIME_OFF_PRES) != 0) + { + p_meas_val->time_offset = co_read16p(p_packed_meas + cursor); + cursor += 2; + } + + // Glucose Concentration, type and location + if (GETB(p_meas_val->flags, GLP_MEAS_GL_CTR_TYPE_AND_SPL_LOC_PRES) != 0) + { + p_meas_val->concentration = co_read16p(p_packed_meas + cursor); + cursor += 2; + + // type and location are 2 nibble values + p_meas_val->location = p_packed_meas[cursor] >> 4; + p_meas_val->type = p_packed_meas[cursor] & 0xF; + + cursor += 1; + } + + // Sensor Status Annunciation + if (GETB(p_meas_val->flags, GLP_MEAS_SENS_STAT_ANNUN_PRES) != 0) + { + p_meas_val->status = co_read16p(p_packed_meas + cursor); + cursor += 2; + } + + return cursor; +} + +uint8_t glpc_unpack_meas_ctx_value(uint8_t *p_packed_meas_ctx, + struct glp_meas_ctx *p_meas_ctx_val, + uint16_t *p_seq_num) +{ + uint8_t cursor = 0; + + // Flags + p_meas_ctx_val->flags = p_packed_meas_ctx[cursor]; + cursor += 1; + + // Sequence Number + *p_seq_num = co_read16p(p_packed_meas_ctx + cursor); + cursor += 2; + + // Extended Flags + if (GETB(p_meas_ctx_val->flags, GLP_CTX_EXTD_F_PRES) != 0) + { + p_meas_ctx_val->ext_flags = p_packed_meas_ctx[cursor]; + cursor += 1; + } + + // Carbohydrate ID And Carbohydrate Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_CRBH_ID_AND_CRBH_PRES) != 0) + { + // Carbohydrate ID + p_meas_ctx_val->carbo_id = p_packed_meas_ctx[cursor]; + cursor += 1; + // Carbohydrate Present + p_meas_ctx_val->carbo_val = co_read16p(p_packed_meas_ctx + cursor); + cursor += 2; + } + + // Meal Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_MEAL_PRES) != 0) + { + p_meas_ctx_val->meal = p_packed_meas_ctx[cursor]; + cursor += 1; + } + + // Tester-Health Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_TESTER_HEALTH_PRES) != 0) + { + // Tester and Health are 2 nibble values + p_meas_ctx_val->health = p_packed_meas_ctx[cursor] >> 4; + p_meas_ctx_val->tester = p_packed_meas_ctx[cursor] & 0xF; + cursor += 1; + } + + // Exercise Duration & Exercise Intensity Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_EXE_DUR_AND_EXE_INTENS_PRES) != 0) + { + // Exercise Duration + p_meas_ctx_val->exercise_dur = co_read16p(p_packed_meas_ctx + cursor); + cursor += 2; + + // Exercise Intensity + p_meas_ctx_val->exercise_intens = p_packed_meas_ctx[cursor]; + cursor += 1; + } + + // Medication ID And Medication Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_MEDIC_ID_AND_MEDIC_PRES) != 0) + { + // Medication ID + p_meas_ctx_val->med_id = p_packed_meas_ctx[cursor]; + cursor += 1; + + // Medication Present + p_meas_ctx_val->med_val = co_read16p(p_packed_meas_ctx + cursor); + cursor += 2; + } + + // HbA1c Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_HBA1C_PRES) != 0) + { + // HbA1c + p_meas_ctx_val->hba1c_val = co_read16p(p_packed_meas_ctx + cursor); + cursor += 2; + } + + return cursor; +} + +uint8_t glpc_pack_racp_req(uint8_t *p_packed_val, const struct glp_racp_req *p_racp_req) +{ + uint8_t cursor = 0; + + // command op code + p_packed_val[cursor] = p_racp_req->op_code; + cursor++; + + // operator of the function + p_packed_val[cursor] = p_racp_req->filter.operator; + cursor++; + + // Abort operation don't require any other parameter + if (p_racp_req->op_code == GLP_REQ_ABORT_OP) + { + return cursor; + } + + // check if request requires operand (filter) + if ((p_racp_req->filter.operator >= GLP_OP_LT_OR_EQ) + && (p_racp_req->filter.operator <= GLP_OP_WITHIN_RANGE_OF)) + { + // command filter type + p_packed_val[cursor] = p_racp_req->filter.filter_type; + cursor++; + + // filter uses sequence number + if (p_racp_req->filter.filter_type == GLP_FILTER_SEQ_NUMBER) + { + // minimum value + if ((p_racp_req->filter.operator == GLP_OP_GT_OR_EQ) + || (p_racp_req->filter.operator == GLP_OP_WITHIN_RANGE_OF)) + { + // minimum value + co_write16p(p_packed_val + cursor,p_racp_req->filter.val.seq_num.min); + cursor +=2; + } + + // maximum value + if ((p_racp_req->filter.operator == GLP_OP_LT_OR_EQ) + || (p_racp_req->filter.operator == GLP_OP_WITHIN_RANGE_OF)) + { + // maximum value + co_write16p(p_packed_val + cursor,p_racp_req->filter.val.seq_num.max); + cursor +=2; + } + } + // filter uses user facing time + else + { + // retrieve minimum value + if ((p_racp_req->filter.operator == GLP_OP_GT_OR_EQ) + || (p_racp_req->filter.operator == GLP_OP_WITHIN_RANGE_OF)) + { + // retrieve minimum facing time + cursor += prf_pack_date_time((p_packed_val + cursor), + &(p_racp_req->filter.val.time.facetime_min)); + } + + // retrieve maximum value + if ((p_racp_req->filter.operator == GLP_OP_LT_OR_EQ) + || (p_racp_req->filter.operator == GLP_OP_WITHIN_RANGE_OF)) + { + // retrieve maximum facing time + cursor += prf_pack_date_time((p_packed_val + cursor), + &(p_racp_req->filter.val.time.facetime_max)); + } + } + } + + return cursor; +} + +uint8_t glpc_unpack_racp_rsp(uint8_t *p_packed_val, struct glp_racp_rsp *p_racp_rsp) +{ + uint8_t cursor = 0; + + // response op code + p_racp_rsp->op_code = p_packed_val[cursor]; + cursor++; + + // operator (null) + cursor++; + + // number of records + if (p_racp_rsp->op_code == GLP_REQ_NUM_OF_STRD_RECS_RSP) + { + p_racp_rsp->operand.num_of_record = co_read16p(p_packed_val + cursor); + cursor += 2; + } + else + { + // requested opcode + p_racp_rsp->operand.rsp.op_code_req = p_packed_val[cursor]; + cursor++; + // command status + p_racp_rsp->operand.rsp.status = p_packed_val[cursor]; + cursor++; + } + + return cursor; +} + +uint8_t glpc_validate_request(struct glpc_env_tag *p_glpc_env, uint8_t conidx, uint8_t char_code) +{ + uint8_t status = GAP_ERR_NO_ERROR; + + // check if feature val characteristic exists + if (p_glpc_env->p_env[conidx]->gls.chars[char_code].val_hdl == ATT_INVALID_HANDLE) + { + status = PRF_ERR_INEXISTENT_HDL; + } + + return (status); +} + +uint16_t glpc_get_read_handle_req(struct glpc_env_tag *p_glpc_env, uint8_t conidx, struct glpc_read_cmd const *p_param) +{ + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + + switch (p_param->read_code) + { + // Read GLP Feature + case (GLPC_RD_FEAT): + { + handle = p_glpc_env->p_env[conidx]->gls.chars[GLPC_CHAR_FEATURE].val_hdl; + } break; + + // Read Glucose Measurement Client Char. Cfg. Descriptor Value + case (GLPC_RD_DESC_MEAS_CLI_CFG): + { + handle = p_glpc_env->p_env[conidx]->gls.descs[GLPC_DESC_MEAS_CLI_CFG].desc_hdl; + } break; + + // Read Glucose Measurement context Client Char. Configuration Descriptor Value + case (GLPC_RD_DESC_MEAS_CTX_CLI_CFG): + { + handle = p_glpc_env->p_env[conidx]->gls.descs[GLPC_DESC_MEAS_CTX_CLI_CFG].desc_hdl; + } break; + + // Read Record Access control point Client Char. Configuration Descriptor Value + case (GLPC_RD_DESC_RACP_CLI): + { + handle = p_glpc_env->p_env[conidx]->gls.descs[GLPC_DESC_RACP_CLI_CFG].desc_hdl; + } break; + + default: + { + handle = ATT_INVALID_SEARCH_HANDLE; + } break; + } + + return handle; +} + +#endif /* (BLE_GL_COLLECTOR) */ + +/// @} GLPC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/src/glpc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/src/glpc.h new file mode 100644 index 0000000..6870a9d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/src/glpc.h @@ -0,0 +1,249 @@ +/** + **************************************************************************************** + * + * @file glpc.h + * + * @brief Header file - Glucose Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _GLPC_H_ +#define _GLPC_H_ + +/** + **************************************************************************************** + * @addtogroup GLPC Glucose Profile Collector + * @ingroup GLP + * @brief Glucose Profile Collector + * + * The GLPC is responsible for providing Glucose Profile Collector functionalities + * to upper layer module or application. The device using this profile takes the role + * of Glucose Profile Collector. + * + * Glucose Profile Collector. (GLPC): A GLPC (e.g. PC, phone, etc) + * is the term used by this profile to describe a device that can interpret Glucose + * measurement in a way suitable to the user application. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_GL_COLLECTOR) +#include "glp_common.h" +#include "ke_task.h" +#include "prf.h" +#include "prf_types.h" +#include "prf_utils.h" +#include "glpc_task.h" +/* + * DEFINES + **************************************************************************************** + */ +/// Maximum number of Glucose Collector task instances +#define GLPC_IDX_MAX (BLE_CONNECTION_MAX) + + +/// 30 seconds record access control point timer +#define GLPC_RACP_TIMEOUT 0x0BB8 + +/// Possible states of the GLPC task +enum glpc_state +{ + /// Not Connected state + GLPC_FREE, + /// IDLE state + GLPC_IDLE, + /// Discovering Glucose SVC and Chars + GLPC_DISCOVERING, + /// Busy state + GLPC_BUSY, + + /// Number of defined states. + GLPC_STATE_MAX +}; + +/// Internal codes for reading/writing a GLS characteristic with one single request +enum glpc_read_code +{ + /// Read GLP Feature + GLPC_RD_FEAT = 0, + + /// Read Glucose Measurement Client Char. Configuration Descriptor + GLPC_RD_DESC_MEAS_CLI_CFG = 1, + + /// Read Glucose Measurement context Client Char. Configuration Descriptor + GLPC_RD_DESC_MEAS_CTX_CLI_CFG = 2, + + /// Read Record Access control point Client Char. Configuration Descriptor + GLPC_RD_DESC_RACP_CLI = 3, + +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Glucose Profile Collector environment variable per connection +struct glpc_cnx_env +{ + /// Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// counter used to check service uniqueness + uint8_t nb_svc; + /// used to store if measurement context + uint8_t meas_ctx_en; + ///HTS characteristics + struct gls_content gls; + /// Current read Op code @see enum glpc_read_code + uint8_t read_code; +}; + +/// Glucose Profile Collector environment variable +struct glpc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct glpc_cnx_env *p_env[GLPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[GLPC_IDX_MAX]; +}; + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve GLP client profile interface + * + * @return GLP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *glpc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Glucose ATT DB discovery results to GLPC host. + * + * @param p_glpc_env Glucose Profile Client Role task environment + * @param conidx Connection index + * @param status Response status code + **************************************************************************************** + */ +void glpc_enable_rsp_send(struct glpc_env_tag *p_glpc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Unpack Glucose measurement value + * + * @param[in] p_packed_meas Glucose measurement value packed + * @param[out] p_meas_val Glucose measurement value + * @param[out] p_seq_num Glucose measurement sequence number + * + * @return size of packed value + **************************************************************************************** + */ +uint8_t glpc_unpack_meas_value(uint8_t *p_packed_meas, struct glp_meas *p_meas_val, + uint16_t *p_seq_num); + +/** + **************************************************************************************** + * @brief Unpack Glucose measurement context value + * + * @param[in] p_packed_meas_ctx Glucose measurement context value packed + * @param[out] p_meas_val Glucose measurement context value + * @param[out] p_seq_num Glucose measurement sequence number + * + * @return size of packed value + **************************************************************************************** + */ +uint8_t glpc_unpack_meas_ctx_value(uint8_t *p_packed_meas_ctx, + struct glp_meas_ctx *p_meas_ctx_val, + uint16_t *p_seq_num); + +/** + **************************************************************************************** + * @brief Pack Record Access Control request + * + * @param[out] p_packed_val Record Access Control Point value packed + * @param[in] p_racp_req Record Access Control Request value + * + * @return size of packed data + **************************************************************************************** + */ +uint8_t glpc_pack_racp_req(uint8_t *p_packed_val, const struct glp_racp_req *p_racp_req); + +/** + **************************************************************************************** + * @brief Unpack Record Access Control response + * + * @param[in] p_packed_val Record Access Control Point value packed + * @param[out] p_racp_rsp Record Access Control Response value + * + * @return size of packed data + **************************************************************************************** + */ +uint8_t glpc_unpack_racp_rsp(uint8_t *p_packed_val, struct glp_racp_rsp *p_racp_rsp); + +/** + **************************************************************************************** + * @brief Check if collector request is possible or not + * + * @param p_glpc_env Glucose Profile Client Role task environment + * @param conidx Connection index + * @param char_code Characteristic code @see enum glpc_char_code + * + * @return GAP_ERR_NO_ERROR if request can be performed, error code else. + **************************************************************************************** + */ +uint8_t glpc_validate_request(struct glpc_env_tag *p_glpc_env, uint8_t conidx, uint8_t char_code); + +/** + **************************************************************************************** + * @brief Gets correct read handle according to the request + * @param[in] p_glpc_env environment variable + * @param[in] conidx Connection index + * @param[in] p_param Pointer to the parameters of the message. + * @return handle + **************************************************************************************** + */ +uint16_t glpc_get_read_handle_req(struct glpc_env_tag *p_glpc_env, uint8_t conidx, struct glpc_read_cmd const *p_param); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void glpc_task_init(struct ke_task_desc *p_task_desc); + +#endif /* (BLE_GL_COLLECTOR) */ + +/// @} GLPC + +#endif /* _GLPC_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/src/glpc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/src/glpc_task.c new file mode 100644 index 0000000..e45b444 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glpc/src/glpc_task.c @@ -0,0 +1,825 @@ +/** + **************************************************************************************** + * + * @file glpc_task.c + * + * @brief Glucose Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup GLPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_GL_COLLECTOR) +#include "gap.h" +#include "attm.h" +#include "glpc_task.h" +#include "glpc.h" +#include "gattc_task.h" +#include "gapc_task.h" +#include "ke_timer.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/* + * DEFINES + **************************************************************************************** + */ + +/// State machine used to retrieve Glucose service characteristics information +const struct prf_char_def glpc_gls_char[GLPC_CHAR_MAX] = +{ + + // Glucose Measurement + [GLPC_CHAR_MEAS] = {ATT_CHAR_GLUCOSE_MEAS, + ATT_MANDATORY, + ATT_CHAR_PROP_NTF}, + // Glucose Measurement Context + [GLPC_CHAR_MEAS_CTX] = {ATT_CHAR_GLUCOSE_MEAS_CTX, + ATT_OPTIONAL, + ATT_CHAR_PROP_NTF}, + // Glucose Feature + [GLPC_CHAR_FEATURE] = {ATT_CHAR_GLUCOSE_FEATURE, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, + // Record Access control point + [GLPC_CHAR_RACP] = {ATT_CHAR_REC_ACCESS_CTRL_PT, + ATT_MANDATORY, + ATT_CHAR_PROP_WR|ATT_CHAR_PROP_IND}, +}; + +/// State machine used to retrieve Glucose service characteristic description information +const struct prf_char_desc_def glpc_gls_char_desc[GLPC_DESC_MAX] = +{ + // Glucose Measurement client config + [GLPC_DESC_MEAS_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, GLPC_CHAR_MEAS}, + + // Glucose Measurement context client config + [GLPC_DESC_MEAS_CTX_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, GLPC_CHAR_MEAS_CTX}, + + // Record Access control point client config + [GLPC_DESC_RACP_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, GLPC_CHAR_RACP}, +}; + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GLPC_ENABLE_REQ message. + * The handler enables the Glucose Profile Collector Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int glpc_enable_req_handler(ke_msg_id_t const msgid, + struct glpc_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Glucose Profile Client Role Task Environment + struct glpc_env_tag *p_glpc_env = PRF_ENV_GET(GLPC, glpc); + + ASSERT_INFO(p_glpc_env != NULL, dest_id, src_id); + if ((state == GLPC_IDLE) && (p_glpc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_glpc_env->p_env[conidx] = (struct glpc_cnx_env *) ke_malloc(sizeof(struct glpc_cnx_env), KE_MEM_ATT_DB); + memset(p_glpc_env->p_env[conidx], 0, sizeof(struct glpc_cnx_env)); + + // Config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + // start discovering GLS on peer + prf_disc_svc_send(&(p_glpc_env->prf_env), conidx, ATT_SVC_GLUCOSE); + + // Go to DISCOVERING state + ke_state_set(dest_id, GLPC_DISCOVERING); + } + //normal connection, get saved att details + else + { + p_glpc_env->p_env[conidx]->gls = p_param->gls; + + //send APP confirmation that can start normal connection to TH + glpc_enable_rsp_send(p_glpc_env, conidx, GAP_ERR_NO_ERROR); + } + } + + else if (state != GLPC_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + glpc_enable_rsp_send(p_glpc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == GLPC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + struct glpc_env_tag *p_glpc_env = PRF_ENV_GET(GLPC, glpc); + + ASSERT_INFO(p_glpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_glpc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_glpc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve GLS characteristics and descriptors + prf_extract_svc_info(p_ind, GLPC_CHAR_MAX, &glpc_gls_char[0], &p_glpc_env->p_env[conidx]->gls.chars[0], + GLPC_DESC_MAX, &glpc_gls_char_desc[0], &p_glpc_env->p_env[conidx]->gls.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_glpc_env->p_env[conidx]->gls.svc.shdl = p_ind->start_hdl; + p_glpc_env->p_env[conidx]->gls.svc.ehdl = p_ind->end_hdl; + } + + p_glpc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Get the address of the environment + struct glpc_env_tag *p_glpc_env = PRF_ENV_GET(GLPC, glpc); + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == GLPC_DISCOVERING) + { + uint8_t status = p_param->status; + + if (p_param->status == ATT_ERR_NO_ERROR) + { + // check characteristic validity + if (p_glpc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(GLPC_CHAR_MAX, p_glpc_env->p_env[conidx]->gls.chars, + glpc_gls_char); + } + // too much services + else if (p_glpc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(GLPC_DESC_MAX, + p_glpc_env->p_env[conidx]->gls.descs, + glpc_gls_char_desc, + p_glpc_env->p_env[conidx]->gls.chars); + } + } + + glpc_enable_rsp_send(p_glpc_env, conidx, status); + } + else if (state == GLPC_BUSY) + { + switch (p_param->operation) + { + case GATTC_READ: + { + struct glpc_cmp_evt *p_evt = KE_MSG_ALLOC(GLPC_CMP_EVT, + prf_dst_task_get(&(p_glpc_env->prf_env), conidx), dest_id, + glpc_cmp_evt); + + // set operation + p_evt->operation = GLPC_READ_CMD_OP_CODE; + // set status + p_evt->status = p_param->status; + + ke_msg_send(p_evt); + + ke_state_set(prf_src_task_get(&(p_glpc_env->prf_env), conidx), GLPC_IDLE); + + } break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + // RACP write done. + if (p_glpc_env->p_env[conidx]->last_uuid_req == ATT_CHAR_REC_ACCESS_CTRL_PT) + { + struct glpc_cmp_evt *p_evt = KE_MSG_ALLOC(GLPC_CMP_EVT, + prf_dst_task_get(&(p_glpc_env->prf_env), conidx), dest_id, + glpc_cmp_evt); + + // set status + p_evt->status = p_param->status; + // set operation + p_evt->operation = GLPC_RACP_CMD_OP_CODE; + + ke_msg_send(p_evt); + p_glpc_env->p_env[conidx]->last_uuid_req = 0; + + ke_state_set(prf_src_task_get(&(p_glpc_env->prf_env), conidx), GLPC_IDLE); + } + else + { + bool finished = false; + + // Restore if measurement context notification should be register in from + // unused variable + bool meas_ctx_en = p_glpc_env->p_env[conidx]->meas_ctx_en; + + // Registration succeed + if (p_param->status == GAP_ERR_NO_ERROR) + { + // Glucose measurement notification registration done + if (p_glpc_env->p_env[conidx]->last_uuid_req == GLPC_DESC_MEAS_CLI_CFG) + { + // register to RACP indications + prf_gatt_write_ntf_ind(&(p_glpc_env->prf_env), conidx, + p_glpc_env->p_env[conidx]->gls.descs[GLPC_DESC_RACP_CLI_CFG].desc_hdl, + PRF_CLI_START_IND); + p_glpc_env->p_env[conidx]->last_uuid_req = GLPC_DESC_RACP_CLI_CFG; + } + // Record access control point indication registration done + // Register to Glucose Measurement Context notifications if requested. + else if ((p_glpc_env->p_env[conidx]->last_uuid_req == GLPC_DESC_RACP_CLI_CFG) + && meas_ctx_en) + { + // register to Glucose Measurement Context notifications + prf_gatt_write_ntf_ind(&(p_glpc_env->prf_env), conidx, + p_glpc_env->p_env[conidx]->gls.descs[GLPC_DESC_MEAS_CTX_CLI_CFG].desc_hdl, + PRF_CLI_START_NTF); + p_glpc_env->p_env[conidx]->last_uuid_req = GLPC_DESC_MEAS_CTX_CLI_CFG; + } + // All registration done + else + { + // indication/notification registration finished + finished = true; + } + } + + // send status if registration done or if an error occurs. + if ((p_param->status != GAP_ERR_NO_ERROR) || (finished)) + { + struct glpc_cmp_evt *p_cfm = KE_MSG_ALLOC(GLPC_CMP_EVT, + prf_dst_task_get(&(p_glpc_env->prf_env), conidx), dest_id, + glpc_cmp_evt); + + // set operation code + p_cfm->operation = GLPC_REGISTER_CMD_OP_CODE; + // set error status + p_cfm->status = p_param->status; + + ke_state_set(prf_src_task_get(&(p_glpc_env->prf_env), conidx), GLPC_IDLE); + + ke_msg_send(p_cfm); + } + } + } break; + + default: + { + + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GLPC_READ_CMD message. + * Send by application task, it's used to retrieve Glucose Sensor features. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int glpc_read_cmd_handler(ke_msg_id_t const msgid, + struct glpc_read_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (ke_state_get(dest_id) == GLPC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct glpc_env_tag *p_glpc_env = PRF_ENV_GET(GLPC, glpc); + + ASSERT_INFO(p_glpc_env != NULL, dest_id, src_id); + + // environment variable not ready + if (p_glpc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Get the handler + uint16_t hdl = glpc_get_read_handle_req(p_glpc_env, conidx, p_param); + + // request can be performed + if (hdl != ATT_INVALID_SEARCH_HANDLE) + { + // Store the current read code + p_glpc_env->p_env[conidx]->read_code = p_param->read_code; + + // read glucose sensor feature + prf_read_char_send(&(p_glpc_env->prf_env), conidx, + p_glpc_env->p_env[conidx]->gls.svc.shdl, + p_glpc_env->p_env[conidx]->gls.svc.ehdl, + hdl); + + ke_state_set(dest_id, GLPC_BUSY); + + status = ATT_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + + // request cannot be performed + if (status != GAP_ERR_NO_ERROR) + { + struct glpc_cmp_evt *p_rsp = KE_MSG_ALLOC(GLPC_CMP_EVT, src_id, dest_id, glpc_cmp_evt); + + // set operation code + p_rsp->operation = GLPC_READ_CMD_OP_CODE; + // set error status + p_rsp->status = status; + + ke_msg_send(p_rsp); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == GLPC_BUSY) + { + struct glpc_env_tag *p_glpc_env = PRF_ENV_GET(GLPC, glpc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_glpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_glpc_env->p_env[conidx] != NULL, dest_id, src_id); + + struct glpc_read_ind *p_ind = KE_MSG_ALLOC(GLPC_READ_IND, + prf_dst_task_get(&(p_glpc_env->prf_env), conidx), dest_id, + glpc_read_ind); + + switch (p_glpc_env->p_env[conidx]->read_code) + { + // Read GLP Feature + case (GLPC_RD_FEAT): + { + p_ind->value.features = co_read16p(&p_param->value[0]); + } break; + + // Read Client Char. Configuration Descriptor values + case (GLPC_RD_DESC_MEAS_CLI_CFG): + case (GLPC_RD_DESC_MEAS_CTX_CLI_CFG): + case (GLPC_RD_DESC_RACP_CLI): + { + p_ind->value.ind_cfg = co_read16p(&p_param->value[0]); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + ke_msg_send(p_ind); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GLPC_REGISTER_CMD message. + * When receiving this request, Glucose collector register to measurement notifications + * and RACP indications. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int glpc_register_cmd_handler(ke_msg_id_t const msgid, + struct glpc_register_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (ke_state_get(dest_id) == GLPC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct glpc_env_tag *p_glpc_env = PRF_ENV_GET(GLPC, glpc); + + ASSERT_INFO(p_glpc_env != NULL, dest_id, src_id); + + // environment variable not ready + if (p_glpc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + // check if client characteristics are present + else if ((p_glpc_env->p_env[conidx]->gls.descs[GLPC_DESC_MEAS_CLI_CFG].desc_hdl == ATT_INVALID_HANDLE) + || (p_glpc_env->p_env[conidx]->gls.descs[GLPC_DESC_RACP_CLI_CFG].desc_hdl == ATT_INVALID_HANDLE) + || ((p_param->meas_ctx_en) + && (p_glpc_env->p_env[conidx]->gls.descs[GLPC_DESC_MEAS_CTX_CLI_CFG].desc_hdl == ATT_INVALID_HANDLE))) + { + status = PRF_ERR_INEXISTENT_HDL; + } + // request can be performed + else + { + // register to notification + prf_gatt_write_ntf_ind(&(p_glpc_env->prf_env), conidx, + p_glpc_env->p_env[conidx]->gls.descs[GLPC_DESC_MEAS_CLI_CFG].desc_hdl, + PRF_CLI_START_NTF); + p_glpc_env->p_env[conidx]->last_uuid_req = GLPC_DESC_MEAS_CLI_CFG; + + // save if measurement context notification should be register in an unused variable + p_glpc_env->p_env[conidx]->meas_ctx_en = p_param->meas_ctx_en; + + // Go to the Busy state + ke_state_set(dest_id, GLPC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + } + + // request cannot be performed + if (status != GAP_ERR_NO_ERROR) + { + struct glpc_cmp_evt *p_cfm = KE_MSG_ALLOC(GLPC_CMP_EVT, src_id, dest_id, glpc_cmp_evt); + + // set operation code + p_cfm->operation = GLPC_REGISTER_CMD_OP_CODE; + // set error status + p_cfm->status = status; + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GLPC_RACP_CMD message. + * When receiving this request, Glucose collector send a RACP command to Glucose sensor. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int glpc_racp_cmd_handler(ke_msg_id_t const msgid, + struct glpc_racp_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (ke_state_get(dest_id) == GLPC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct glpc_env_tag *p_glpc_env = PRF_ENV_GET(GLPC, glpc); + + ASSERT_INFO(p_glpc_env != NULL, dest_id, src_id); + + // environment variable not ready + if (p_glpc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + status = glpc_validate_request(p_glpc_env, conidx, GLPC_CHAR_RACP); + + // request can be performed + if (status == GAP_ERR_NO_ERROR) + { + // send command request + uint8_t value[GLP_REC_ACCESS_CTRL_MAX_LEN]; + uint16_t length; + + // pack Record Access Control Point request + length = glpc_pack_racp_req((uint8_t*)&(value[0]), &(p_param->racp_req)); + + // write Record Access Control Point request + prf_gatt_write(&(p_glpc_env->prf_env), conidx, + p_glpc_env->p_env[conidx]->gls.chars[GLPC_CHAR_RACP].val_hdl, + &(value[0]),length, GATTC_WRITE); + + p_glpc_env->p_env[conidx]->last_uuid_req = ATT_CHAR_REC_ACCESS_CTRL_PT; + + // start the timer; will destroy the link if it expires + ke_timer_set(GLPC_RACP_CMD_TIMEOUT, dest_id, 10*GLPC_RACP_TIMEOUT); + + // Go to the Busy state + ke_state_set(dest_id, GLPC_BUSY); + } + } + } + + // request cannot be performed + if (status != GAP_ERR_NO_ERROR) + { + struct glpc_cmp_evt *p_evt = KE_MSG_ALLOC(GLPC_CMP_EVT, src_id, dest_id, glpc_cmp_evt); + + // set status + p_evt->status = status; + // set operation code + p_evt->operation = GLPC_RACP_CMD_OP_CODE; + + ke_msg_send(p_evt); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) != GLPC_FREE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct glpc_env_tag *p_glpc_env = PRF_ENV_GET(GLPC, glpc); + + ASSERT_INFO(p_glpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_glpc_env->p_env[conidx] != NULL, dest_id, src_id); + + switch (p_param->type) + { + case GATTC_INDICATE: + { + // confirm that indication has been correctly received + struct gattc_event_cfm *p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + + // check if it's a RACP indication + if (p_glpc_env->p_env[conidx]->gls.chars[GLPC_CHAR_RACP].val_hdl == p_param->handle) + { + struct glpc_racp_ind *p_ind = KE_MSG_ALLOC(GLPC_RACP_IND, + prf_dst_task_get(&(p_glpc_env->prf_env), conidx), dest_id, + glpc_racp_ind); + + // stop timer. + ke_timer_clear(GLPC_RACP_CMD_TIMEOUT, dest_id); + + // unpack RACP response indication. + glpc_unpack_racp_rsp((uint8_t*)p_param->value, &(p_ind->racp_rsp)); + ke_msg_send(p_ind); + } + } break; + + case GATTC_NOTIFY: + { + // check if it's a Glucose measurement notification + if (p_glpc_env->p_env[conidx]->gls.chars[GLPC_CHAR_MEAS].val_hdl == p_param->handle) + { + // build a GLPC_MEAS_IND message with glucose measurement value + struct glpc_meas_ind *p_ind = KE_MSG_ALLOC(GLPC_MEAS_IND, + prf_dst_task_get(&(p_glpc_env->prf_env), conidx), dest_id, + glpc_meas_ind); + + // unpack Glucose measurement. + glpc_unpack_meas_value((uint8_t *) p_param->value, &(p_ind->meas_val), &(p_ind->seq_num)); + + if (p_glpc_env->p_env[conidx]->last_uuid_req == ATT_CHAR_REC_ACCESS_CTRL_PT) + { + // restart the timer; will destroy the link if it expires + ke_timer_set(GLPC_RACP_CMD_TIMEOUT, dest_id, 10*GLPC_RACP_TIMEOUT); + } + + ke_msg_send(p_ind); + } + // check if it's a Glucose measurement context notification + else if(p_glpc_env->p_env[conidx]->gls.chars[GLPC_CHAR_MEAS_CTX].val_hdl == p_param->handle) + { + // build a GLPC_MEAS_CTX_IND message with glucose measurement context value + struct glpc_meas_ctx_ind *p_ind = KE_MSG_ALLOC(GLPC_MEAS_CTX_IND, + prf_dst_task_get(&(p_glpc_env->prf_env), conidx), dest_id, + glpc_meas_ctx_ind); + + // unpack Glucose measurement context. + glpc_unpack_meas_ctx_value((uint8_t*) p_param->value, &(p_ind->ctx), &(p_ind->seq_num)); + + if (p_glpc_env->p_env[conidx]->last_uuid_req == ATT_CHAR_REC_ACCESS_CTRL_PT) + { + // restart the timer; will destroy the link if it expires + ke_timer_set(GLPC_RACP_CMD_TIMEOUT, dest_id, 10*GLPC_RACP_TIMEOUT); + } + + ke_msg_send(p_ind); + } + } break; + + default: + { + + } break; + } + } + + return (KE_MSG_CONSUMED); +} + + +/** + **************************************************************************************** + * @brief RACP request not executed by peer device or is frozen. + * It can be a connection problem, disconnect the link. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GATTC). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + * + **************************************************************************************** + */ +__STATIC int glpc_racp_cmd_timeout_handler(ke_msg_id_t const msgid, void const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) != GLPC_FREE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + struct glpc_env_tag *p_glpc_env = PRF_ENV_GET(GLPC, glpc); + struct glpc_cmp_evt *p_evt; + + ASSERT_INFO(p_glpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_glpc_env->p_env[conidx] != NULL, dest_id, src_id); + + // inform that racp execution is into a timeout state + p_evt = KE_MSG_ALLOC(GLPC_CMP_EVT, + prf_dst_task_get(&(p_glpc_env->prf_env), conidx), dest_id, glpc_cmp_evt); + // set error status + p_evt->status = PRF_ERR_PROC_TIMEOUT; + // set operation + p_evt->operation = GLPC_RACP_CMD_OP_CODE; + // set IDLE state + ke_state_set(prf_src_task_get(&(p_glpc_env->prf_env), conidx), GLPC_IDLE); + + ke_msg_send(p_evt); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(glpc) +{ + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {GLPC_READ_CMD, (ke_msg_func_t)glpc_read_cmd_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GLPC_REGISTER_CMD, (ke_msg_func_t)glpc_register_cmd_handler}, + {GLPC_RACP_CMD, (ke_msg_func_t)glpc_racp_cmd_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GLPC_RACP_CMD_TIMEOUT, (ke_msg_func_t)glpc_racp_cmd_timeout_handler}, + {GLPC_ENABLE_REQ, (ke_msg_func_t)glpc_enable_req_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void glpc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct glpc_env_tag *p_glpc_env = PRF_ENV_GET(GLPC, glpc); + + p_task_desc->msg_handler_tab = glpc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(glpc_msg_handler_tab); + p_task_desc->state = p_glpc_env->state; + p_task_desc->idx_max = GLPC_IDX_MAX; +} + +#endif /* (BLE_GL_COLLECTOR) */ +/// @} GLPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/api/glps.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/api/glps.h new file mode 100644 index 0000000..31c4069 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/api/glps.h @@ -0,0 +1,318 @@ +/** + **************************************************************************************** + * + * @file glps.h + * + * @brief Header file - Glucose Profile Sensor. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _GLPS_H_ +#define _GLPS_H_ + +/** + **************************************************************************************** + * @addtogroup GLPS Glucose Profile Sensor + * @ingroup GLP + * @brief Glucose Profile Sensor + * + * Glucose sensor (GLS) profile provides functionalities to upper layer module + * application. The device using this profile takes the role of Glucose sensor. + * + * The interface of this role to the Application is: + * - Enable the profile role (from APP) + * - Disable the profile role (from APP) + * - Notify peer device during Glucose measurement (from APP) + * - Indicate measurements performed to peer device (from APP) + * + * Profile didn't manages multiple users configuration and storage of offline measurements. + * This must be handled by application. + * + * Glucose Profile Sensor. (GLPS): A GLPS (e.g. PC, phone, etc) + * is the term used by this profile to describe a device that can perform Glucose + * measurement and notify about on-going measurement and indicate final result to a peer + * BLE device. + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_GL_SENSOR) + +#include "glp_common.h" +#include "prf_types.h" +#include "prf.h" +#include "attm.h" + +/* + * DEFINES + **************************************************************************************** + */ +/// Maximum number of Glucose task instances +#define GLPS_IDX_MAX BLE_CONNECTION_MAX + +/// GLS Configuration Flag Masks +#define GLPS_MANDATORY_MASK (0x1F8F) +#define GLPS_MEAS_CTX_PRES_MASK (0x0070) + +/* + * MACROS + **************************************************************************************** + */ + +/// check if flag enable +#define GLPS_IS(IDX, FLAG) ((p_glps_env->p_env[IDX]->flags & (1<< (GLPS_##FLAG))) == (1<< (GLPS_##FLAG))) + +/// Set flag enable +#define GLPS_SET(IDX, FLAG) (p_glps_env->p_env[IDX]->flags |= (1<< (GLPS_##FLAG))) + +/// Set flag disable +#define GLPS_CLEAR(IDX, FLAG) (p_glps_env->p_env[IDX]->flags &= ~(1<< (GLPS_##FLAG))) + + +/// Get database attribute handle +#define GLPS_HANDLE(idx) \ + (p_glps_env->start_hdl + (idx) - \ + ((!(p_glps_env->meas_ctx_supported) && ((idx) > GLS_IDX_MEAS_CTX_NTF_CFG))? (3) : (0))) + +/// Get database attribute index +#define GLPS_IDX(hdl) \ + (((((hdl) - p_glps_env->start_hdl) > GLS_IDX_MEAS_CTX_NTF_CFG) && !(p_glps_env->meas_ctx_supported)) ?\ + ((hdl) - p_glps_env->start_hdl + 3) : ((hdl) - p_glps_env->start_hdl)) + +/// Get event Indication/notification configuration bit +#define GLPS_IND_NTF_EVT(idx) (1 << ((idx - 1) / 3)) + +/* + * ENUMS + **************************************************************************************** + */ + +/// Possible states of the GLPS task +enum glps_state +{ + /// Not Connected state + GLPS_FREE, + /// Idle state + GLPS_IDLE, + + /// Number of defined states. + GLPS_STATE_MAX +}; + +/// Attributes State Machine +enum +{ + /// Glucose Service + GLS_IDX_SVC, + /// Glucose Measurement + GLS_IDX_MEAS_CHAR, + GLS_IDX_MEAS_VAL, + GLS_IDX_MEAS_NTF_CFG, + /// Glucose Measurement Context + GLS_IDX_MEAS_CTX_CHAR, + GLS_IDX_MEAS_CTX_VAL, + GLS_IDX_MEAS_CTX_NTF_CFG, + /// Glucose Feature + GLS_IDX_FEATURE_CHAR, + GLS_IDX_FEATURE_VAL, + /// Record Access Control Point + GLS_IDX_REC_ACCESS_CTRL_CHAR, + GLS_IDX_REC_ACCESS_CTRL_VAL, + GLS_IDX_REC_ACCESS_CTRL_IND_CFG, + + GLS_IDX_NB, +}; + +/// Characteristic Codes +enum +{ + /// Glucose Measurement + GLS_MEAS_CHAR, + /// Glucose Measurement Context + GLS_MEAS_CTX_CHAR, + /// Glucose Feature + GLS_FEATURE_CHAR, + /// Record Access Control Point + GLS_REC_ACCESS_CTRL_CHAR, +}; + +/// Database Configuration Bit Field Flags +enum +{ + /// support of Glucose Measurement Context + GLPS_MEAS_CTX_SUP = 0x01, +}; + +/// Indication/notification configuration (put in feature flag to optimize memory usage) +enum +{ + /// Bit used to know if Glucose measurement notification is enabled + GLPS_MEAS_NTF_CFG = GLPS_IND_NTF_EVT(GLS_IDX_MEAS_NTF_CFG), + /// Bit used to know if Glucose measurement context notification is enabled + GLPS_MEAS_CTX_NTF_CFG = GLPS_IND_NTF_EVT(GLS_IDX_MEAS_CTX_NTF_CFG), + /// Bit used to know if Glucose measurement context indication is enabled + GLPS_RACP_IND_CFG = GLPS_IND_NTF_EVT(GLS_IDX_REC_ACCESS_CTRL_IND_CFG), +}; + +/// Type of request completed +enum +{ + /// Glucose measurement notification sent completed + GLPS_SEND_MEAS_REQ_NTF_CMP, + /// Record Access Control Point Response Indication + GLPS_SEND_RACP_RSP_IND_CMP +}; + +/// Glucose service processing flags +enum +{ + /// Use To know if bond data are present + GLPS_BOND_DATA_PRESENT, + /// Flag used to know if there is an on-going record access control point request + GLPS_RACP_ON_GOING, + /// Service id sending a measurement + GLPS_SENDING_MEAS, + /// Measurement sent + GLPS_MEAS_SENT, + /// Measurement context sent + GLPS_MEAS_CTX_SENT, + /// RACP Response sent by application + GLPS_RACP_RSP_SENT_BY_APP, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Glucose Profile Sensor environment variable per connection +struct glps_cnx_env +{ + /// Glucose service processing flags + uint8_t flags; + /// Event (notification/indication) configuration + uint8_t evt_cfg; +}; + +/// Glucose Profile Sensor environment variable +struct glps_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct glps_cnx_env *p_env[GLPS_IDX_MAX]; + /// Glucose Service Start Handle + uint16_t start_hdl; + /// Glucose Feature + uint16_t features; + /// Measurement context supported + uint8_t meas_ctx_supported; + /// State of different task instances + ke_state_t state[GLPS_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve GLP service profile interface + * + * @return GLP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *glps_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Pack Glucose measurement value + * + * @param[out] p_packed_meas Glucose measurement value packed + * @param[in] p_meas_val Glucose measurement value + * @param[in] seq_num Glucose measurement sequence number + * @param[in] p_glps_env Glucose Profile service environment variable + * + * @return size of packed value + **************************************************************************************** + */ +uint8_t glps_pack_meas_value(uint8_t *p_packed_meas, const struct glp_meas *p_meas_val, + uint16_t seq_num, struct glps_env_tag *p_glps_env); + +/** + **************************************************************************************** + * @brief Pack Glucose measurement context value + * + * @param[out] p_packed_meas_ctx Glucose measurement context value packed + * @param[in] p_meas_ctx_val Glucose measurement context value + * @param[in] seq_num Glucose measurement sequence number + * + * @return size of packed value + **************************************************************************************** + */ +uint8_t glps_pack_meas_ctx_value(uint8_t *p_packed_meas_ctx, + const struct glp_meas_ctx *p_meas_ctx_val, + uint16_t seq_num); + +/** + **************************************************************************************** + * @brief Unpack Record Access Control request + * + * @param[in] p_packed_val Record Access Control Point value packed + * @param[in] length packed value length + * @param[out] p_racp_req Record Access Control Request value + * + * @return status of unpacking + **************************************************************************************** + */ +uint8_t glps_unpack_racp_req(uint8_t *p_packed_val, uint16_t length, + struct glp_racp_req *p_racp_req); + +/** + **************************************************************************************** + * @brief Pack Record Access Control response + * + * @param[out] p_packed_val Record Access Control Point value packed + * @param[in] p_racp_rsp Record Access Control Response value + * + * @return size of packed data + **************************************************************************************** + */ +uint8_t glps_pack_racp_rsp(uint8_t *p_packed_val, struct glp_racp_rsp *p_racp_rsp); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void glps_task_init(struct ke_task_desc *p_task_desc); + +#endif /* #if (BLE_GL_SENSOR) */ + +/// @} GLPS + +#endif /* _GLPS_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/api/glps_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/api/glps_task.h new file mode 100644 index 0000000..8c23b65 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/api/glps_task.h @@ -0,0 +1,162 @@ +/** + **************************************************************************************** + * + * @file glps_task.h + * + * @brief Header file - Glucose Profile Sensor Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _GLPS_TASK_H_ +#define _GLPS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup GLPSTASK Task + * @ingroup GLPS + * @brief Glucose Profile Task. + * + * The GLPSTASK is responsible for handling the messages coming in and out of the + * @ref GLPS collector block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include +#include "rwip_task.h" // Task definitions +#include "glp_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/// Messages for Glucose Profile Sensor +/*@TRACE*/ +enum glps_msg_id +{ + /// Start the Glucose Profile Sensor - at connection + GLPS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_GLPS), + /// Confirm that Glucose Profile Sensor is started. + GLPS_ENABLE_RSP, + + ///Inform APP of new configuration value + GLPS_CFG_INDNTF_IND, + + /// Record Access Control Point Request + GLPS_RACP_REQ_RCV_IND, + + /// Record Access Control Point Resp + GLPS_SEND_RACP_RSP_CMD, + + /// Send Glucose measurement with context information + GLPS_SEND_MEAS_WITH_CTX_CMD, + /// Send Glucose measurement without context information + GLPS_SEND_MEAS_WITHOUT_CTX_CMD, + + /// Inform that requested action has been performed + GLPS_CMP_EVT, +}; + +/// Parameters of the Glucose service database +struct glps_db_cfg +{ + /// Glucose Feature + uint16_t features; + /// Measurement context supported + uint8_t meas_ctx_supported; +}; + + +/// Parameters of the @ref GLPS_ENABLE_REQ message +struct glps_enable_req +{ + /// Glucose indication/notification configuration + uint16_t evt_cfg; +}; + +/// Parameters of the @ref GLPS_ENABLE_RSP message +struct glps_enable_rsp +{ + /// Status + uint8_t status; +}; + +/// Parameters of the @ref GLPS_CFG_INDNTF_IND message +struct glps_cfg_indntf_ind +{ + /// Glucose indication/notification configuration + uint8_t evt_cfg; +}; + +/// Parameters of the @ref GLPS_SEND_MEAS_WITH_CTX_CMD message +struct glps_send_meas_with_ctx_cmd +{ + /// Sequence Number + uint16_t seq_num; + /// Glucose measurement + struct glp_meas meas; + /// Glucose measurement context + struct glp_meas_ctx ctx; +}; + + +/// Parameters of the @ref GLPS_SEND_MEAS_WITHOUT_CTX_CMD message +struct glps_send_meas_without_ctx_cmd +{ + /// Sequence Number + uint16_t seq_num; + /// Glucose measurement + struct glp_meas meas; +}; + + +/// Parameters of the @ref GLPS_RACP_REQ_RCV_IND message +struct glps_racp_req_rcv_ind +{ + /// RACP Request + struct glp_racp_req racp_req; +}; + +/// Parameters of the @ref GLPS_SEND_RACP_RSP_CMD message +struct glps_send_racp_rsp_cmd +{ + /// Number of records. + uint16_t num_of_record; + /// operation code + uint8_t op_code; + /// Command status + uint8_t status; +}; + +/// Parameters of the @ref GLPS_CMP_EVT message +struct glps_cmp_evt +{ + /// completed request + uint8_t request; + /// Command status + uint8_t status; +}; + + +/// @} GLPSTASK + +#endif /* _GLPS_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/sourcelist.txt new file mode 100644 index 0000000..6e9729e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + glps.c + glps_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/src/glps.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/src/glps.c new file mode 100644 index 0000000..a4db3d7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/src/glps.c @@ -0,0 +1,635 @@ +/** + **************************************************************************************** + * + * @file glps.c + * + * @brief Glucose Profile Sensor implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup GLPS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_GL_SENSOR) +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "glps.h" +#include "glps_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Full GLPS Database Description - Used to add attributes into the database +static const struct attm_desc glps_att_db[GLS_IDX_NB] = +{ + // Glucose Service Declaration + [GLS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Glucose Measurement Characteristic Declaration + [GLS_IDX_MEAS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Glucose Measurement Characteristic Value + [GLS_IDX_MEAS_VAL] = {ATT_CHAR_GLUCOSE_MEAS, PERM(NTF, ENABLE), PERM(RI, ENABLE), 0}, + // Glucose Measurement Characteristic - Client Characteristic Configuration Descriptor + [GLS_IDX_MEAS_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Glucose Measurement Context Characteristic Declaration + [GLS_IDX_MEAS_CTX_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Glucose Measurement Context Characteristic Value + [GLS_IDX_MEAS_CTX_VAL] = {ATT_CHAR_GLUCOSE_MEAS_CTX, PERM(NTF, ENABLE), PERM(RI, ENABLE), 0}, + // Glucose Measurement Context Characteristic - Client Characteristic Configuration Descriptor + [GLS_IDX_MEAS_CTX_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Glucose Features Characteristic Declaration + [GLS_IDX_FEATURE_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Glucose Features Characteristic Value + [GLS_IDX_FEATURE_VAL] = {ATT_CHAR_GLUCOSE_FEATURE, PERM(RD, ENABLE), PERM(RI, ENABLE) | sizeof(uint16_t), 0}, + + // Record Access Control Point characteristic Declaration + [GLS_IDX_REC_ACCESS_CTRL_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Record Access Control Point characteristic Value + [GLS_IDX_REC_ACCESS_CTRL_VAL] = {ATT_CHAR_REC_ACCESS_CTRL_PT, PERM(IND, ENABLE)|PERM(WP, UNAUTH)|PERM(WRITE_REQ, ENABLE), + PERM(RI, ENABLE), GLP_REC_ACCESS_CTRL_MAX_LEN}, + // Record Access Control Point characteristic - Client Characteristic Configuration Descriptor + [GLS_IDX_REC_ACCESS_CTRL_IND_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + +/* + * DEFINES + **************************************************************************************** + */ + +#define GLPS_FILTER_USER_FACING_TIME_SIZE (7) + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Initialization of the GLPS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t glps_init (struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct glps_db_cfg *p_params) +{ + //------------------ create the attribute database for the profile ------------------- + uint8_t idx; + // Service content flag + uint32_t cfg_flag = GLPS_MANDATORY_MASK; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + // Set Configuration Flag Value + if (p_params->meas_ctx_supported) + { + cfg_flag |= GLPS_MEAS_CTX_PRES_MASK; + } + + // Create Glucose Database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_GLUCOSE, (uint8_t *)&cfg_flag, + GLS_IDX_NB, NULL, p_env->task, &glps_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, ENABLE)); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + // Allocate GLPS required environment variable + struct glps_env_tag *p_glps_env = + (struct glps_env_tag *) ke_malloc(sizeof(struct glps_env_tag), KE_MEM_ATT_DB); + + // Initialize GLPS environment + p_env->env = (prf_env_t *) p_glps_env; + p_glps_env->start_hdl = *p_start_hdl; + p_glps_env->meas_ctx_supported = p_params->meas_ctx_supported; + p_glps_env->features = p_params->features; + p_glps_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_glps_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_GLPS; + glps_task_init(&(p_env->desc)); + + for (idx = 0; idx < GLPS_IDX_MAX; idx++) + { + p_glps_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), GLPS_FREE); + } + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the GLPS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void glps_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct glps_env_tag *p_glps_env = (struct glps_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < GLPS_IDX_MAX; idx++) + { + if (p_glps_env->p_env[idx] != NULL) + { + ke_free(p_glps_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_glps_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void glps_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct glps_env_tag *p_glps_env = (struct glps_env_tag *) p_env->env; + + p_glps_env->p_env[conidx] = (struct glps_cnx_env *) + ke_malloc(sizeof(struct glps_cnx_env), KE_MEM_ATT_DB); + + memset(p_glps_env->p_env[conidx], 0, sizeof(struct glps_cnx_env)); + + // Put GLS in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), GLPS_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void glps_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct glps_env_tag *p_glps_env = (struct glps_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_glps_env->p_env[conidx] != NULL) + { + ke_free(p_glps_env->p_env[conidx]); + p_glps_env->p_env[conidx] = NULL; + } + + // Put GLS in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), GLPS_FREE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// GLPS Task interface required by profile manager +const struct prf_task_cbs glps_itf = +{ + (prf_init_fnct) glps_init, + glps_destroy, + glps_create, + glps_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *glps_prf_itf_get(void) +{ + return &glps_itf; +} + +uint8_t glps_pack_meas_value(uint8_t *p_packed_meas, const struct glp_meas* p_meas_val, + uint16_t seq_num, struct glps_env_tag *p_glps_env) +{ + uint8_t cursor = 0; + + // Flags + p_packed_meas[cursor] = p_meas_val->flags; + cursor += 1; + + // Sequence Number + co_write16p(p_packed_meas + cursor, seq_num); + cursor += 2; + + // Base Time + cursor += prf_pack_date_time(p_packed_meas + cursor, &(p_meas_val->base_time)); + + // Time Offset + if (GETB(p_meas_val->flags, GLP_MEAS_TIME_OFF_PRES) != 0) + { + co_write16p(p_packed_meas + cursor, p_meas_val->time_offset); + cursor += 2; + } + + // Glucose Concentration, type and location + if (GETB(p_meas_val->flags, GLP_MEAS_GL_CTR_TYPE_AND_SPL_LOC_PRES) != 0) + { + co_write16p(p_packed_meas + cursor, p_meas_val->concentration); + cursor += 2; + + // type and location are 2 nibble values + p_packed_meas[cursor] = (p_meas_val->location << 4) | (p_meas_val->type); + cursor += 1; + } + + // Sensor Status Annunciation + if (GETB(p_meas_val->flags, GLP_MEAS_SENS_STAT_ANNUN_PRES) != 0) + { + // Use a non-const value + uint16_t status = p_meas_val->status; + + // If feature not supported, corresponding Flag in the Sensor Status Annunciation Field + // shall be set to default of 0 + + // Low Battery Detection During Measurement Support Bit + if (!GETB(p_glps_env->features, GLP_FET_LOW_BAT_DET_DUR_MEAS_SUPP)) + { + SETB(status, GLP_MEAS_STATE_DEV_BAT_LOW, 0); + } + + // Sensor Malfunction Detection Support Bit + if (!GETB(p_glps_env->features, GLP_FET_SENS_MFNC_DET_SUPP)) + { + SETB(status, GLP_MEAS_STATE_SENS_MFNC_OR_FLTING, 0); + } + + // Sensor Sample Size Support Bit + if (!GETB(p_glps_env->features, GLP_FET_SENS_SPL_SIZE_SUPP)) + { + SETB(status, GLP_MEAS_STATE_SPL_SIZE_INSUFF, 0); + } + + // Sensor Strip Insertion Error Detection Support Bit + if (!GETB(p_glps_env->features, GLP_FET_SENS_STRIP_INSERT_ERR_DET_SUPP)) + { + SETB(status, GLP_MEAS_STATE_STRIP_INSERT_ERR, 0); + } + + // Sensor Result High-Low Detection Support Bit + if (!GETB(p_glps_env->features, GLP_FET_SENS_RES_HIGH_LOW_DET_SUPP)) + { + SETB(status, GLP_MEAS_STATE_SENS_RES_HIGHER, 0); + SETB(status, GLP_MEAS_STATE_SENS_RES_LOWER, 0); + } + + // Sensor Temperature High-Low Detection Support Bit + if (!GETB(p_glps_env->features, GLP_FET_SENS_TEMP_HIGH_LOW_DET_SUPP)) + { + SETB(status, GLP_MEAS_STATE_SENS_TEMP_TOO_HIGH, 0); + + SETB(status, GLP_MEAS_STATE_SENS_TEMP_TOO_LOW, 0); + } + + // Sensor Read Interrupt Detection Support Bit + if (!GETB(p_glps_env->features, GLP_FET_SENS_RD_INT_DET_SUPP)) + { + SETB(status, GLP_MEAS_STATE_SENS_RD_INTED, 0); + } + + // General Device Fault Support Bit + if (!GETB(p_glps_env->features, GLP_FET_GEN_DEV_FLT_SUPP)) + { + SETB(status, GLP_MEAS_STATE_GEN_DEV_FLT, 0); + } + + // Time Fault Support Bit + if (!GETB(p_glps_env->features, GLP_FET_TIME_FLT_SUPP)) + { + SETB(status, GLP_MEAS_STATE_TIME_FLT, 0); + } + + // Multiple Bond Support Bit + if (!GETB(p_glps_env->features, GLP_FET_MUL_BOND_SUPP)) + { + // can determine that the Glucose Sensor supports only a single bond + } + else + { + // Collector can determine that the Glucose supports multiple bonds + } + + co_write16p(p_packed_meas + cursor, status); + cursor += 2; + } + + return cursor; +} + +uint8_t glps_pack_meas_ctx_value(uint8_t *p_packed_meas_ctx, + const struct glp_meas_ctx* p_meas_ctx_val, + uint16_t seq_num) +{ + uint8_t cursor = 0; + // Flags + p_packed_meas_ctx[cursor] = p_meas_ctx_val->flags; + cursor += 1; + + // Sequence Number + co_write16p(p_packed_meas_ctx + cursor, seq_num); + cursor += 2; + + // Extended Flags + if (GETB(p_meas_ctx_val->flags, GLP_CTX_EXTD_F_PRES) != 0) + { + p_packed_meas_ctx[cursor] = p_meas_ctx_val->ext_flags; + cursor += 1; + } + + // Carbohydrate ID And Carbohydrate Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_CRBH_ID_AND_CRBH_PRES) != 0) + { + // Carbohydrate ID + p_packed_meas_ctx[cursor] = p_meas_ctx_val->carbo_id; + cursor += 1; + // Carbohydrate Present + co_write16p(p_packed_meas_ctx + cursor, p_meas_ctx_val->carbo_val); + cursor += 2; + } + + // Meal Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_MEAL_PRES) != 0) + { + p_packed_meas_ctx[cursor] = p_meas_ctx_val->meal; + cursor += 1; + } + + // Tester-Health Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_TESTER_HEALTH_PRES) != 0) + { + // Tester and Health are 2 nibble values + p_packed_meas_ctx[cursor] = (p_meas_ctx_val->health << 4) | (p_meas_ctx_val->tester); + cursor += 1; + } + + // Exercise Duration & Exercise Intensity Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_EXE_DUR_AND_EXE_INTENS_PRES) != 0) + { + // Exercise Duration + co_write16p(p_packed_meas_ctx + cursor, p_meas_ctx_val->exercise_dur); + cursor += 2; + + // Exercise Intensity + p_packed_meas_ctx[cursor] = p_meas_ctx_val->exercise_intens; + cursor += 1; + } + + // Medication ID And Medication Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_MEDIC_ID_AND_MEDIC_PRES) != 0) + { + // Medication ID + p_packed_meas_ctx[cursor] = p_meas_ctx_val->med_id; + cursor += 1; + + // Medication Present + co_write16p(p_packed_meas_ctx + cursor, p_meas_ctx_val->med_val); + cursor += 2; + } + + // HbA1c Present + if (GETB(p_meas_ctx_val->flags, GLP_CTX_HBA1C_PRES) != 0) + { + // HbA1c + co_write16p(p_packed_meas_ctx + cursor, p_meas_ctx_val->hba1c_val); + cursor += 2; + } + + return cursor; +} + +uint8_t glps_unpack_racp_req(uint8_t *p_packed_val, uint16_t length, + struct glp_racp_req* p_racp_req) +{ + uint8_t cursor = 0; + + // verify that enough data present to load operation filter + if (length < 2) + { + return PRF_APP_ERROR; + } + + // retrieve command op code + p_racp_req->op_code = p_packed_val[cursor]; + cursor++; + + // clear filter structure + memset(&(p_racp_req->filter), 0, sizeof(struct glp_filter)); + + // retrieve operator of the function + p_racp_req->filter.operator = p_packed_val[cursor]; + cursor++; + + // check if opcode is supported + if ((p_racp_req->op_code < GLP_REQ_REP_STRD_RECS) + || (p_racp_req->op_code > GLP_REQ_REP_NUM_OF_STRD_RECS)) + { + return GLP_RSP_OP_CODE_NOT_SUP; + } + + // Abort operation don't require any other parameter + if (p_racp_req->op_code == GLP_REQ_ABORT_OP) + { + return GAP_ERR_NO_ERROR; + } + + // check if operator is valid + if (p_racp_req->filter.operator < GLP_OP_ALL_RECS) + { + return GLP_RSP_INVALID_OPERATOR; + } + // check if operator is supported + else if (p_racp_req->filter.operator > GLP_OP_LAST_REC) + { + return GLP_RSP_OPERATOR_NOT_SUP; + } + + // check if request requires operand (filter) + if ((p_racp_req->filter.operator >= GLP_OP_LT_OR_EQ) + && (p_racp_req->filter.operator <= GLP_OP_WITHIN_RANGE_OF)) + { + // verify that enough data present to load operand filter + if (length < cursor) + { + return GLP_RSP_INVALID_OPERAND; + } + + // retrieve command filter type + p_racp_req->filter.filter_type = p_packed_val[cursor]; + cursor++; + + // filter uses sequence number + if (p_racp_req->filter.filter_type == GLP_FILTER_SEQ_NUMBER) + { + // retrieve minimum value + if ((p_racp_req->filter.operator == GLP_OP_GT_OR_EQ) + || (p_racp_req->filter.operator == GLP_OP_WITHIN_RANGE_OF)) + { + // check sufficient data available + if ((length - cursor) < 2) + { + return GLP_RSP_INVALID_OPERAND; + } + + // retrieve minimum value + p_racp_req->filter.val.seq_num.min = co_read16p(p_packed_val + cursor); + cursor +=2; + } + + // retrieve maximum value + if ((p_racp_req->filter.operator == GLP_OP_LT_OR_EQ) + || (p_racp_req->filter.operator == GLP_OP_WITHIN_RANGE_OF)) + { + if ((length - cursor) < 2) + { + return GLP_RSP_INVALID_OPERAND; + } + + // retrieve maximum value + p_racp_req->filter.val.seq_num.max = co_read16p(p_packed_val + cursor); + cursor +=2; + } + + + // check that range value is valid + if ((p_racp_req->filter.operator == GLP_OP_WITHIN_RANGE_OF) + && (p_racp_req->filter.val.seq_num.min > p_racp_req->filter.val.seq_num.max)) + { + return GLP_RSP_INVALID_OPERAND; + } + } + // filter uses user facing time + else if (p_racp_req->filter.filter_type == GLP_FILTER_USER_FACING_TIME) + { + // retrieve minimum value + if ((p_racp_req->filter.operator == GLP_OP_GT_OR_EQ) + || (p_racp_req->filter.operator == GLP_OP_WITHIN_RANGE_OF)) + { + // check sufficient data available + if ((length - cursor) < GLPS_FILTER_USER_FACING_TIME_SIZE) + { + return GLP_RSP_INVALID_OPERAND; + } + + // retrieve minimum facing time + cursor += prf_unpack_date_time((p_packed_val + cursor), + &(p_racp_req->filter.val.time.facetime_min)); + cursor +=2; + } + + // retrieve maximum value + if ((p_racp_req->filter.operator == GLP_OP_LT_OR_EQ) + || (p_racp_req->filter.operator == GLP_OP_WITHIN_RANGE_OF)) + { + if ((length - cursor) < GLPS_FILTER_USER_FACING_TIME_SIZE) + { + return GLP_RSP_INVALID_OPERAND; + } + + // retrieve maximum facing time + cursor += prf_unpack_date_time((p_packed_val + cursor), + &(p_racp_req->filter.val.time.facetime_max)); + } + } + else + { + return GLP_RSP_OPERAND_NOT_SUP; + } + } + else if ((length - cursor) != 0) + { + return GLP_RSP_INVALID_OPERAND; + } + + // Check that operand is valid + return GAP_ERR_NO_ERROR; +} + +uint8_t glps_pack_racp_rsp(uint8_t *p_packed_val, struct glp_racp_rsp *p_racp_rsp) +{ + uint8_t cursor = 0; + + // set response op code + p_packed_val[cursor] = p_racp_rsp->op_code; + cursor++; + + // set operator (null) + p_packed_val[cursor] = 0; + cursor++; + + // number of record + if (p_racp_rsp->op_code == GLP_REQ_NUM_OF_STRD_RECS_RSP) + { + co_write16(p_packed_val+cursor, p_racp_rsp->operand.num_of_record); + cursor += 2; + } + else + { + // requested opcode + p_packed_val[cursor] = p_racp_rsp->operand.rsp.op_code_req;; + cursor++; + // command status + p_packed_val[cursor] = p_racp_rsp->operand.rsp.status; + cursor++; + } + + return cursor; +} + +#endif /* BLE_GL_SENSOR */ + +/// @} GLPS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/src/glps_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/src/glps_task.c new file mode 100644 index 0000000..f684580 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/glp/glps/src/glps_task.c @@ -0,0 +1,736 @@ +/** + **************************************************************************************** + * + * @file glps_task.c + * + * @brief Glucose Profile Sensor Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup GLPSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_GL_SENSOR) + +#include "gap.h" +#include "gattc_task.h" +#include "glps.h" +#include "glps_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLUCOSE PROFILE ATTRIBUTES + **************************************************************************************** + */ + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GLPS_ENABLE_REQ message. + * The handler enables the Glucose Sensor Profile and initialize readable values. + * @param[in] msgid Id of the message received (probably unused).off + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int glps_enable_req_handler(ke_msg_id_t const msgid, + struct glps_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct glps_enable_rsp *p_cmp_evt; + + if (ke_state_get(dest_id) == GLPS_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct glps_env_tag *p_glps_env = PRF_ENV_GET(GLPS, glps); + + if(!GLPS_IS(conidx, BOND_DATA_PRESENT)) + { + GLPS_SET(conidx, BOND_DATA_PRESENT); + status = GAP_ERR_NO_ERROR; + p_glps_env->p_env[conidx]->evt_cfg = p_param->evt_cfg; + } + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(GLPS_ENABLE_RSP, src_id, dest_id, glps_enable_rsp); + p_cmp_evt->status = status; + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GLPS_MEAS_SEND_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int glps_meas_send_req_handler(ke_msg_id_t const msgid, + struct glps_send_meas_with_ctx_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (ke_state_get(dest_id) == GLPS_IDLE) + { + // Get the address of the environment + struct glps_env_tag *p_glps_env = PRF_ENV_GET(GLPS, glps); + uint8_t conidx = KE_IDX_GET(dest_id); + + // Cannot send another measurement in parallel + if (!GLPS_IS(conidx, SENDING_MEAS)) + { + // inform that device is sending a measurement + GLPS_SET(conidx, SENDING_MEAS); + + // check if context is supported + if ((msgid == GLPS_SEND_MEAS_WITH_CTX_CMD) && !(p_glps_env->meas_ctx_supported)) + { + // Context not supported + status = (PRF_ERR_FEATURE_NOT_SUPPORTED); + } + // check if notifications enabled + else if (((p_glps_env->p_env[conidx]->evt_cfg & GLPS_MEAS_NTF_CFG) == 0) + || (((p_glps_env->p_env[conidx]->evt_cfg & GLPS_MEAS_CTX_NTF_CFG) == 0) + && (msgid == GLPS_SEND_MEAS_WITH_CTX_CMD))) + { + // Not allowed to send measurement if Notifications not enabled. + status = (PRF_ERR_NTF_DISABLED); + } + else + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_meas_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), dest_id, + gattc_send_evt_cmd, GLP_MEAS_MAX_LEN); + + // Fill in the parameter structure + p_meas_val->operation = GATTC_NOTIFY; + p_meas_val->handle = GLPS_HANDLE(GLS_IDX_MEAS_VAL); + // pack measured value in database + p_meas_val->length = glps_pack_meas_value(p_meas_val->value, &(p_param->meas), + p_param->seq_num, p_glps_env); + + // Measurement value notification not yet sent + GLPS_CLEAR(conidx, MEAS_SENT); + + // Send the event + ke_msg_send(p_meas_val); + + if (msgid == GLPS_SEND_MEAS_WITH_CTX_CMD) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_meas_ctx_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), dest_id, + gattc_send_evt_cmd, GLP_MEAS_CTX_MAX_LEN); + + // Fill in the parameter structure + p_meas_ctx_val->operation = GATTC_NOTIFY; + p_meas_ctx_val->handle = GLPS_HANDLE(GLS_IDX_MEAS_CTX_VAL); + // pack measured value in database + p_meas_ctx_val->length = glps_pack_meas_ctx_value(p_meas_ctx_val->value, + &(p_param->ctx), p_param->seq_num); + + // 2 notification complete messages expected + GLPS_SET(conidx, MEAS_CTX_SENT); + + // Send the event + ke_msg_send(p_meas_ctx_val); + } + else + { + // 1 notification complete messages expected + GLPS_CLEAR(conidx, MEAS_CTX_SENT); + } + + status = (GAP_ERR_NO_ERROR); + } + } + } + + // send command complete if an error occurs + if (status != GAP_ERR_NO_ERROR) + { + // send completed information to APP task that contains error status + struct glps_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(GLPS_CMP_EVT, src_id, + dest_id, glps_cmp_evt); + + p_cmp_evt->request = GLPS_SEND_MEAS_REQ_NTF_CMP; + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GLPS_SEND_RACP_RSP_CMD message. + * Send when a RACP requests is finished + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int glps_send_racp_rsp_cmd_handler(ke_msg_id_t const msgid, + struct glps_send_racp_rsp_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (ke_state_get(dest_id) == GLPS_IDLE) + { + // Get the address of the environment + struct glps_env_tag *p_glps_env = PRF_ENV_GET(GLPS, glps); + uint8_t conidx = KE_IDX_GET(dest_id); + + // check if op code valid + if ((p_param->op_code < GLP_REQ_REP_STRD_RECS) + || (p_param->op_code > GLP_REQ_REP_NUM_OF_STRD_RECS)) + { + // Wrong op code + status = PRF_ERR_INVALID_PARAM; + } + // check if RACP on going + else if ((p_param->op_code != GLP_REQ_ABORT_OP) && !(GLPS_IS(conidx, RACP_ON_GOING))) + { + // Cannot send response since no RACP on going + status = PRF_ERR_REQ_DISALLOWED; + } + // Indication not enabled on peer device + else if ((p_glps_env->p_env[conidx]->evt_cfg & GLPS_RACP_IND_CFG) == 0) + { + status = PRF_ERR_IND_DISABLED; + // There is no more RACP on going + GLPS_CLEAR(conidx, RACP_ON_GOING); + } + else + { + struct glp_racp_rsp racp_rsp; + // Allocate the GATT indication message + struct gattc_send_evt_cmd *p_racp_rsp_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), dest_id, + gattc_send_evt_cmd, GLP_REC_ACCESS_CTRL_MAX_LEN); + + // Fill in the parameter structure + p_racp_rsp_val->operation = GATTC_INDICATE; + p_racp_rsp_val->handle = GLPS_HANDLE(GLS_IDX_REC_ACCESS_CTRL_VAL); + + // Number of stored record calculation succeed. + if ((p_param->op_code == GLP_REQ_REP_NUM_OF_STRD_RECS) + && (p_param->status == GLP_RSP_SUCCESS)) + { + racp_rsp.op_code = GLP_REQ_NUM_OF_STRD_RECS_RSP; + racp_rsp.operand.num_of_record = p_param->num_of_record; + } + // Send back status information + else + { + racp_rsp.op_code = GLP_REQ_RSP_CODE; + racp_rsp.operand.rsp.op_code_req = p_param->op_code; + racp_rsp.operand.rsp.status = p_param->status; + } + + // pack measured value in database + p_racp_rsp_val->length = glps_pack_racp_rsp(p_racp_rsp_val->value, &racp_rsp); + + // There is no more RACP on going + GLPS_CLEAR(conidx, RACP_ON_GOING); + status = GAP_ERR_NO_ERROR; + + // Store that response sent by application + GLPS_SET(conidx, RACP_RSP_SENT_BY_APP); + + // send RACP Response indication + ke_msg_send(p_racp_rsp_val); + } + } + + if (status != GAP_ERR_NO_ERROR) + { + // send completed information about request failed + struct glps_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(GLPS_CMP_EVT, src_id, dest_id, glps_cmp_evt); + + p_cmp_evt->request = GLPS_SEND_RACP_RSP_IND_CMP; + p_cmp_evt->status = status; + ke_msg_send(p_cmp_evt); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == GLPS_IDLE) + { + struct glps_env_tag *p_glps_env = PRF_ENV_GET(GLPS, glps); + uint8_t att_idx = GLPS_IDX(p_param->handle); + struct gattc_att_info_cfm *p_cfm; + + // Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + // check if it's a client configuration char + if ((att_idx == GLS_IDX_MEAS_NTF_CFG) + || (att_idx == GLS_IDX_MEAS_CTX_NTF_CFG) + || (att_idx == GLS_IDX_REC_ACCESS_CTRL_IND_CFG)) + { + // CCC attribute length = 2 + p_cfm->length = 2; + p_cfm->status = GAP_ERR_NO_ERROR; + } + else if (att_idx == GLS_IDX_REC_ACCESS_CTRL_VAL) + { + // force length to zero to reject any write starting from something != 0 + p_cfm->length = 0; + p_cfm->status = GAP_ERR_NO_ERROR; + } + // not expected request + else + { + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } + + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATT_CODE_ATT_WR_CMD_IND message. + * The handler compares the new values with current ones and notifies them if they changed. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct glp_racp_rsp racp_rsp; + + racp_rsp.op_code = 0; + + if (ke_state_get(dest_id) == GLPS_IDLE) + { + uint8_t status = GAP_ERR_NO_ERROR; + struct gattc_write_cfm *p_cfm; + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct glps_env_tag *p_glps_env = PRF_ENV_GET(GLPS, glps); + uint8_t att_idx = GLPS_IDX(p_param->handle); + + if (p_param->offset != 0) + { + status = ATT_ERR_UNLIKELY_ERR; + } + // check if it's a client configuration char + else if ((att_idx == GLS_IDX_MEAS_NTF_CFG) + || (att_idx == GLS_IDX_MEAS_CTX_NTF_CFG) + || (att_idx == GLS_IDX_REC_ACCESS_CTRL_IND_CFG)) + { + uint16_t cli_cfg; + uint8_t evt_mask = GLPS_IND_NTF_EVT(att_idx); + + // get client configuration + cli_cfg = co_read16p(&(p_param->value)); + + // stop indication/notification + if (cli_cfg == PRF_CLI_STOP_NTFIND) + { + p_glps_env->p_env[conidx]->evt_cfg &= ~evt_mask; + } + // start indication/notification (check that char value accept it) + else if (((att_idx == GLS_IDX_REC_ACCESS_CTRL_IND_CFG) && (cli_cfg == PRF_CLI_START_IND)) + ||((att_idx != GLS_IDX_REC_ACCESS_CTRL_IND_CFG) && (cli_cfg == PRF_CLI_START_NTF))) + { + p_glps_env->p_env[conidx]->evt_cfg |= evt_mask; + } + // improper value + else + { + status = GLP_ERR_IMPROPER_CLI_CHAR_CFG; + } + + if (status == GAP_ERR_NO_ERROR) + { + // Inform APP of configuration change + struct glps_cfg_indntf_ind *p_ind = KE_MSG_ALLOC(GLPS_CFG_INDNTF_IND, + prf_dst_task_get(&(p_glps_env->prf_env), conidx), dest_id, glps_cfg_indntf_ind); + + p_ind->evt_cfg = p_glps_env->p_env[conidx]->evt_cfg; + ke_msg_send(p_ind); + } + } + + else if (att_idx == GLS_IDX_REC_ACCESS_CTRL_VAL) + { + if ((p_glps_env->p_env[conidx]->evt_cfg & GLPS_RACP_IND_CFG) == 0) + { + // do nothing since indication not enabled for this characteristic + status = GLP_ERR_IMPROPER_CLI_CHAR_CFG; + } + // If a request is on going + else if (GLPS_IS(conidx, RACP_ON_GOING)) + { + // if it's an abort command, execute it. + if ((p_param->offset == 0) && (p_param->value[0] == GLP_REQ_ABORT_OP)) + { + //forward abort operation to application + struct glps_racp_req_rcv_ind *p_req = KE_MSG_ALLOC(GLPS_RACP_REQ_RCV_IND, + prf_dst_task_get(&(p_glps_env->prf_env), conidx), dest_id, glps_racp_req_rcv_ind); + + p_req->racp_req.op_code = GLP_REQ_ABORT_OP; + p_req->racp_req.filter.operator = 0; + ke_msg_send(p_req); + } + else + { + // do nothing since a procedure already in progress + status = GLP_ERR_PROC_ALREADY_IN_PROGRESS; + } + } + else + { + struct glp_racp_req racp_req; + // unpack record access control point value + uint8_t reqstatus = glps_unpack_racp_req(p_param->value, p_param->length, &racp_req); + + // check unpacked status + switch (reqstatus) + { + case PRF_APP_ERROR: + { + // Request failed + status = ATT_ERR_UNLIKELY_ERR; + } break; + + case GAP_ERR_NO_ERROR: + { + // check which request shall be send to api task + switch (racp_req.op_code) + { + case GLP_REQ_REP_STRD_RECS: + case GLP_REQ_DEL_STRD_RECS: + case GLP_REQ_REP_NUM_OF_STRD_RECS: + { + // forward request operation to application + struct glps_racp_req_rcv_ind *p_req = KE_MSG_ALLOC(GLPS_RACP_REQ_RCV_IND, + prf_dst_task_get(&(p_glps_env->prf_env), conidx), dest_id, + glps_racp_req_rcv_ind); + + p_req->racp_req = racp_req; + // RACP on going. + GLPS_SET(conidx, RACP_ON_GOING); + ke_msg_send(p_req); + } break; + + case GLP_REQ_ABORT_OP: + { + // nothing to abort, send an error message. + racp_rsp.op_code = GLP_REQ_RSP_CODE; + racp_rsp.operand.rsp.op_code_req = + racp_req.op_code; + racp_rsp.operand.rsp.status = GLP_RSP_ABORT_UNSUCCESSFUL; + } break; + + default: + { + // nothing to do since it's handled during unpack + } break; + } + } break; + + default: + { + // There is an error in record access control request, inform peer + // device that request is incorrect. + racp_rsp.op_code = GLP_REQ_RSP_CODE; + racp_rsp.operand.rsp.op_code_req = racp_req.op_code; + racp_rsp.operand.rsp.status = reqstatus; + } break; + } + } + } + // not expected request + else + { + status = ATT_ERR_WRITE_NOT_PERMITTED; + } + + // Send write response + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + + // The racp response has to be sent - after write confirm + if (racp_rsp.op_code != 0) + { + // Allocate the GATT indication message + struct gattc_send_evt_cmd *p_racp_rsp_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), dest_id, + gattc_send_evt_cmd, GLP_REC_ACCESS_CTRL_MAX_LEN); + + p_racp_rsp_val->operation = GATTC_INDICATE; + p_racp_rsp_val->handle = p_param->handle; + // pack measured value in database + p_racp_rsp_val->length = glps_pack_racp_rsp(p_racp_rsp_val->value, &racp_rsp); + + // Store that response internally sent by profile + GLPS_CLEAR(conidx, RACP_RSP_SENT_BY_APP); + + // send RACP Response indication + ke_msg_send(p_racp_rsp_val); + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == GLPS_IDLE) + { + // Send value to peer device. + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, + gattc_read_cfm, sizeof(uint16_t)); + // Get the address of the environment + struct glps_env_tag *p_glps_env = PRF_ENV_GET(GLPS, glps); + uint8_t att_idx = GLPS_IDX(p_param->handle); + uint8_t conidx = KE_IDX_GET(dest_id); + + p_cfm->handle = p_param->handle; + p_cfm->status = ATT_ERR_NO_ERROR; + p_cfm->length = sizeof(uint16_t); + + switch (att_idx) + { + case GLS_IDX_MEAS_NTF_CFG: + { + co_write16p(p_cfm->value, (p_glps_env->p_env[conidx]->evt_cfg & GLPS_MEAS_NTF_CFG) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } break; + + case GLS_IDX_MEAS_CTX_NTF_CFG: + { + co_write16p(p_cfm->value, (p_glps_env->p_env[conidx]->evt_cfg & GLPS_MEAS_CTX_NTF_CFG) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } break; + + case GLS_IDX_REC_ACCESS_CTRL_IND_CFG: + { + co_write16p(p_cfm->value, (p_glps_env->p_env[conidx]->evt_cfg & GLPS_RACP_IND_CFG) + ? PRF_CLI_START_IND : PRF_CLI_STOP_NTFIND); + } break; + + case GLS_IDX_FEATURE_VAL: + { + co_write16p(p_cfm->value, p_glps_env->features); + } break; + + default: + { + p_cfm->status = ATT_ERR_INSUFF_AUTHOR; + } break; + } + + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT for GATTC_NOTIFY and GATT_INDICATE message meaning + * that Measurement notification/indication has been correctly sent to peer device + * + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == GLPS_IDLE) + { + // Get the address of the environment + struct glps_env_tag *p_glps_env = PRF_ENV_GET(GLPS, glps); + uint8_t conidx = KE_IDX_GET(dest_id); + + switch(p_param->operation) + { + case GATTC_NOTIFY: + { + /* send message indication if an error occurs, + * or if all notification complete event has been received + */ + if ((p_param->status != GAP_ERR_NO_ERROR) + || (!(GLPS_IS(conidx, MEAS_CTX_SENT))) + || (GLPS_IS(conidx, MEAS_CTX_SENT) && (GLPS_IS(conidx, MEAS_SENT)))) + { + struct glps_cmp_evt *p_cmp_evt; + + GLPS_CLEAR(conidx, SENDING_MEAS); + + // send completed information to APP task + p_cmp_evt = KE_MSG_ALLOC(GLPS_CMP_EVT, + prf_dst_task_get(&(p_glps_env->prf_env), conidx), + dest_id, + glps_cmp_evt); + + p_cmp_evt->request = GLPS_SEND_MEAS_REQ_NTF_CMP; + p_cmp_evt->status = p_param->status; + + ke_msg_send(p_cmp_evt); + } + else + { + // Measurement value notification sent + GLPS_SET(conidx, MEAS_SENT); + } + } break; + + case GATTC_INDICATE: + { + // verify if indication should be conveyed to application task + if (GLPS_IS(conidx, RACP_RSP_SENT_BY_APP)) + { + // send completed information to APP task + struct glps_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(GLPS_CMP_EVT, + prf_dst_task_get(&(p_glps_env->prf_env), conidx), + dest_id, + glps_cmp_evt); + + p_cmp_evt->request = GLPS_SEND_RACP_RSP_IND_CMP; + p_cmp_evt->status = p_param->status; + + ke_msg_send(p_cmp_evt); + } + + GLPS_CLEAR(conidx, RACP_RSP_SENT_BY_APP); + } break; + + default: + { + + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(glps) +{ + {GLPS_ENABLE_REQ, (ke_msg_func_t) glps_enable_req_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GLPS_SEND_MEAS_WITH_CTX_CMD, (ke_msg_func_t) glps_meas_send_req_handler}, + {GLPS_SEND_MEAS_WITHOUT_CTX_CMD, (ke_msg_func_t) glps_meas_send_req_handler}, + {GLPS_SEND_RACP_RSP_CMD, (ke_msg_func_t) glps_send_racp_rsp_cmd_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +void glps_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct glps_env_tag *p_glps_env = PRF_ENV_GET(GLPS, glps); + + p_task_desc->msg_handler_tab = glps_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(glps_msg_handler_tab); + p_task_desc->state = p_glps_env->state; + p_task_desc->idx_max = GLPS_IDX_MAX; +} + +#endif /* #if (BLE_GL_SENSOR) */ + +/// @} GLPSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogp_common.h new file mode 100644 index 0000000..2613ed1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogp_common.h @@ -0,0 +1,106 @@ +/** + **************************************************************************************** + * + * @file hogp_common.h + * + * @brief Header File - HID Over GATT Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _HOGP_COMMON_H_ +#define _HOGP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup HOGP HID Over GATT Profile + * @ingroup PROFILE + * @brief HID Over GATT Profile + * + * The HOGP module is the responsible block for implementing the HID Over GATT Profile + * functionalities in the BLE Host. + * + * The HID Over GATT Profile defines the functionality required to allow HID reports and + * HID data to be exchanged between a HID Device and a HID Host + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "prf_types.h" +#include + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// HID Information bit values +enum hogp_info_bit +{ + /// Device capable of providing wake-up signal to a HID host + HIDS_REMOTE_WAKE_CAPABLE = 0x01, + /// Normally connectable support bit + HIDS_NORM_CONNECTABLE = 0x02, +}; + +/// HID Control Point Characteristic value keys +enum hogp_ctnl_pt +{ + /// Suspend + HOGP_CTNL_PT_SUSPEND = 0x00, + /// Exit suspend + HOGP_CTNL_PT_EXIT_SUSPEND, +}; + +/// Protocol Mode Char. value Keys +enum hogp_boot_prot_mode +{ + /// Boot Protocol Mode + HOGP_BOOT_PROTOCOL_MODE = 0x00, + /// Report Protocol Mode + HOGP_REPORT_PROTOCOL_MODE, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Report Reference structure +struct hids_report_ref +{ + ///Report ID + uint8_t report_id; + ///Report Type + uint8_t report_type; +}; + +/// HID Information structure +struct hids_hid_info +{ + /// bcdHID + uint16_t bcdHID; + /// bCountryCode + uint8_t bCountryCode; + /// Flags + uint8_t flags; +}; + + + +/// @} hogp_common + +#endif /* _HOGP_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/api/hogpbh_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/api/hogpbh_task.h new file mode 100644 index 0000000..3f46800 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/api/hogpbh_task.h @@ -0,0 +1,266 @@ +/** + **************************************************************************************** + * + * @file hogpbh_task.h + * + * @brief Header file - HID Over GATT Profile Boot Host Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _HOGPBH_TASK_H_ +#define _HOGPBH_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup HOGPBHTASK HID Over GATT Profile Boot Host Task + * @ingroup HOGPBH + * @brief HID Over GATT Profile Boot Host Task + * + * The HOGPBHTASK is responsible for handling the messages coming in and out of the + * @ref HOGPBH monitor block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" +#include "hogp_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximal number of hids instances that can be handled +#define HOGPBH_NB_HIDS_INST_MAX (2) + +/// Maximal Length of Boot Report Char. Value +#define HOGPBH_BOOT_REPORT_MAX_LEN (8) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +enum hogpbh_msg_id +{ + /// Start the HID Over GATT profile - at connection + HOGPBH_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_HOGPBH), + ///Confirm that cfg connection has finished with discovery results, or that normal cnx started + HOGPBH_ENABLE_RSP, + + /// Read Characteristic Value Request + HOGPBH_READ_INFO_REQ, + /// Read Characteristic Value Request + HOGPBH_READ_INFO_RSP, + + /// Write/Configure peer device attribute Request + HOGPBH_WRITE_REQ, + /// Write/Configure peer device attribute Response + HOGPBH_WRITE_RSP, + + /// Boot Report value send to APP (after Read Request or Notification) + HOGPBH_BOOT_REPORT_IND, +}; + + +/// Characteristics +enum hogpbh_chars +{ + /// Protocol Mode + HOGPBH_CHAR_PROTO_MODE, + /// Boot Keyboard Input Report + HOGPBH_CHAR_BOOT_KB_IN_REPORT, + /// Boot Keyboard Output Report + HOGPBH_CHAR_BOOT_KB_OUT_REPORT, + /// Boot Mouse Input Report + HOGPBH_CHAR_BOOT_MOUSE_IN_REPORT, + + HOGPBH_CHAR_MAX, +}; + + +/// Characteristic descriptors +enum hogpbh_descs +{ + /// Boot Keyboard Input Report Client Config + HOGPBH_DESC_BOOT_KB_IN_REPORT_CFG, + /// Boot Mouse Input Report Client Config + HOGPBH_DESC_BOOT_MOUSE_IN_REPORT_CFG, + + HOGPBH_DESC_MAX, +}; + + +/// Peer HID service info that can be read/write +enum hogpbh_info +{ + /// Protocol Mode + HOGPBH_PROTO_MODE, + /// Boot Keyboard Input Report + HOGPBH_BOOT_KB_IN_REPORT, + /// Boot Keyboard Output Report + HOGPBH_BOOT_KB_OUT_REPORT, + /// Boot Mouse Input Report + HOGPBH_BOOT_MOUSE_IN_REPORT, + + /// Boot Keyboard Input Report Client Config + HOGPBH_BOOT_KB_IN_NTF_CFG, + /// Boot Mouse Input Report Client Config + HOGPBH_BOOT_MOUSE_IN_NTF_CFG, + + HOGPBH_INFO_MAX, +}; + +/* + * APIs Structure + **************************************************************************************** + */ + +///Structure containing the characteristics handles, value handles and descriptors +struct hogpbh_content +{ + /// service info + struct prf_svc svc; + + /// characteristic info: + /// - Protocol Mode + /// - Boot Keyboard Input Report + /// - Boot Keyboard Output Report + /// - Boot Mouse Input Report + struct prf_char_inf chars[HOGPBH_CHAR_MAX]; + + /// Descriptor handles: + /// - Boot Keyboard Input Client Cfg + /// - Boot Mouse Input Client Cfg + struct prf_char_desc_inf descs[HOGPBH_DESC_MAX]; +}; + +/// Parameters of the @ref HOGPBH_ENABLE_REQ message +struct hogpbh_enable_req +{ + /// Connection type + uint8_t con_type; + /// Number of HIDS instances + uint8_t hids_nb; + /// Existing handle values hids + struct hogpbh_content hids[HOGPBH_NB_HIDS_INST_MAX]; +}; + +/// Parameters of the @ref HOGPBH_ENABLE_RSP message +struct hogpbh_enable_rsp +{ + ///status + uint8_t status; + /// Number of HIDS instances + uint8_t hids_nb; + /// Existing handle values hids + struct hogpbh_content hids[HOGPBH_NB_HIDS_INST_MAX]; +}; + +/// HID boot report info +struct hogpbh_boot_report +{ + /// Report Length + uint8_t length; + /// Boot Report value + uint8_t value[__ARRAY_EMPTY]; +}; + + +/// Information data +union hogpbh_data +{ + /// Protocol Mode + /// - info = HOGPBH_PROTO_MODE + uint8_t proto_mode; + ///Notification Configuration Value + /// - info = HOGPBH_BOOT_KB_IN_NTF_CFG + /// - info = HOGPBH_BOOT_MOUSE_IN_NTF_CFG + uint16_t ntf_cfg; + + /// Boot report information + /// - info = HOGPBH_BOOT_KB_IN_REPORT + /// - info = HOGPBH_BOOT_KB_OUT_REPORT + /// - info = HOGPBH_BOOT_MOUSE_IN_REPORT + struct hogpbh_boot_report report; +}; + + + +///Parameters of the @ref HOGPBH_READ_INFO_REQ message +struct hogpbh_read_info_req +{ + ///Characteristic info @see enum hogpbh_info + uint8_t info; + /// HID Service Instance - From 0 to HOGPBH_NB_HIDS_INST_MAX-1 + uint8_t hid_idx; +}; + +///Parameters of the @ref HOGPBH_READ_INFO_RSP message +struct hogpbh_read_info_rsp +{ + /// status of the request + uint8_t status; + ///Characteristic info @see enum hogpbh_info + uint8_t info; + /// HID Service Instance - From 0 to HOGPBH_NB_HIDS_INST_MAX-1 + uint8_t hid_idx; + /// Information data + union hogpbh_data data; +}; + + +///Parameters of the @ref HOGPBH_WRITE_REQ message +struct hogpbh_write_req +{ + ///Characteristic info @see enum hogpbh_info + uint8_t info; + /// HID Service Instance - From 0 to HOGPBH_NB_HIDS_INST_MAX-1 + uint8_t hid_idx; + /// Write type ( Write without Response True or Write Request) + /// - only valid for HOGPBH_BOOT_KB_OUT_REPORT + bool wr_cmd; + /// Information data + union hogpbh_data data; +}; + + +///Parameters of the @ref HOGPBH_WRITE_RSP message +struct hogpbh_write_rsp +{ + /// status of the request + uint8_t status; + ///Characteristic info @see enum hogpbh_info + uint8_t info; + /// HID Service Instance - From 0 to HOGPBH_NB_HIDS_INST_MAX-1 + uint8_t hid_idx; +}; + + +///Parameters of the @ref HOGPBH_BOOT_REPORT_IND message +struct hogpbh_boot_report_ind +{ + ///Characteristic info @see enum hogpbh_info + uint8_t info; + /// HIDS Instance + uint8_t hid_idx; + /// Report data + struct hogpbh_boot_report report; +}; + +/// @} HOGPBHTASK + +#endif /* _HOGPBH_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/sourcelist.txt new file mode 100644 index 0000000..140c299 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + hogpbh.c + hogpbh_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/src/hogpbh.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/src/hogpbh.c new file mode 100644 index 0000000..bc9f2f4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/src/hogpbh.c @@ -0,0 +1,222 @@ +/** + **************************************************************************************** + * + * @file hogpbh.c + * + * @brief HID Over GATT Profile - Boot Host Role Implementation + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HOGPBH + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#if (BLE_HID_BOOT_HOST) + +#include "hogpbh.h" +#include "hogpbh_task.h" +#include "co_math.h" +#include "gap.h" + +#include "ke_mem.h" + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the HOGPBH module. + * This function performs all the initializations of the Profile module. + * - Creation of datahide (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] env Collector or Service allocated environment data. + * @param[in|out] start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t hogpbh_init(struct prf_task_env* env, uint16_t* start_hdl, uint16_t app_task, uint8_t sec_lvl, void* params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct hogpbh_env_tag* hogpbh_env = + (struct hogpbh_env_tag* ) ke_malloc(sizeof(struct hogpbh_env_tag), KE_MEM_ATT_DB); + + // allocate HOGPBH required environment variable + env->env = (prf_env_t*) hogpbh_env; + + hogpbh_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + hogpbh_env->prf_env.prf_task = env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + env->id = TASK_ID_HOGPBH; + env->desc.idx_max = HOGPBH_IDX_MAX; + env->desc.state = hogpbh_env->state; + env->desc.default_handler = &hogpbh_default_handler; + + for(idx = 0; idx < HOGPBH_IDX_MAX ; idx++) + { + hogpbh_env->env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(env->task, idx), HOGPBH_FREE); + } + + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Destruction of the HOGPBH module - due to a reset for instance. + * This function clean-up allocated memory (attribute datahide is destroyed by another + * procedure) + * + * @param[in|out] env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void hogpbh_destroy(struct prf_task_env* env) +{ + uint8_t idx; + struct hogpbh_env_tag* hogpbh_env = (struct hogpbh_env_tag*) env->env; + + // cleanup environment variable for each task instances + for(idx = 0; idx < HOGPBH_IDX_MAX ; idx++) + { + if(hogpbh_env->env[idx] != NULL) + { + if(hogpbh_env->env[idx]->operation != NULL) + { + ke_free(hogpbh_env->env[idx]->operation); + } + ke_free(hogpbh_env->env[idx]); + } + } + + // free profile environment variables + env->env = NULL; + ke_free(hogpbh_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void hogpbh_create(struct prf_task_env* env, uint8_t conidx) +{ + /* Put HID Client in Idle state */ + ke_state_set(KE_BUILD_ID(env->task, conidx), HOGPBH_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void hogpbh_cleanup(struct prf_task_env* env, uint8_t conidx, uint8_t reason) +{ + struct hogpbh_env_tag* hogpbh_env = (struct hogpbh_env_tag*) env->env; + + // clean-up environment variable allocated for task instance + if(hogpbh_env->env[conidx] != NULL) + { + if(hogpbh_env->env[conidx]->operation != NULL) + { + ke_free(hogpbh_env->env[conidx]->operation); + } + ke_free(hogpbh_env->env[conidx]); + hogpbh_env->env[conidx] = NULL; + } + + /* Put HID Client in Free state */ + ke_state_set(KE_BUILD_ID(env->task, conidx), HOGPBH_FREE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// HOGPBH Task interface required by profile manager +const struct prf_task_cbs hogpbh_itf = +{ + hogpbh_init, + hogpbh_destroy, + hogpbh_create, + hogpbh_cleanup, +}; + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* hogpbh_prf_itf_get(void) +{ + return &hogpbh_itf; +} + +void hogpbh_enable_rsp_send(struct hogpbh_env_tag *hogpbh_env, uint8_t conidx, uint8_t status) +{ + // Counter + uint8_t svc_inst; + + // Send APP the details of the discovered attributes on HOGPBH + struct hogpbh_enable_rsp * rsp = KE_MSG_ALLOC(HOGPBH_ENABLE_RSP, + prf_dst_task_get(&(hogpbh_env->prf_env) ,conidx), + prf_src_task_get(&(hogpbh_env->prf_env) ,conidx), + hogpbh_enable_rsp); + rsp->status = status; + rsp->hids_nb = 0; + if (status == GAP_ERR_NO_ERROR) + { + rsp->hids_nb = hogpbh_env->env[conidx]->hids_nb; + + for (svc_inst = 0; svc_inst < co_min(hogpbh_env->env[conidx]->hids_nb, HOGPBH_NB_HIDS_INST_MAX) ; svc_inst++) + { + rsp->hids[svc_inst] = hogpbh_env->env[conidx]->hids[svc_inst]; + + // Register HOGPBH task in gatt for indication/notifications + prf_register_atthdl2gatt(&(hogpbh_env->prf_env), conidx, &hogpbh_env->env[conidx]->hids[svc_inst].svc); + } + } + + ke_msg_send(rsp); +} + +#endif /* (BLE_HID_BOOT_HOST) */ + +/// @} HOGPBH diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/src/hogpbh.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/src/hogpbh.h new file mode 100644 index 0000000..27b172d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/src/hogpbh.h @@ -0,0 +1,143 @@ +/** + **************************************************************************************** + * + * @file hogpbh.h + * + * @brief Header file - HID Over GATT Profile - Boot Host Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _HOGPBH_H_ +#define _HOGPBH_H_ + + +/** + **************************************************************************************** + * @addtogroup HOGPBH HID Over GATT Profile Client + * @ingroup HOGP + * @brief HID Over GATT Profile Client + * @{ + **************************************************************************************** + */ +#include "rwip_config.h" +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#if (BLE_HID_BOOT_HOST) + +#include "hogp_common.h" +#include "ke_task.h" +#include "hogpbh_task.h" +#include "prf_types.h" +#include "prf_utils.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +///Maximum number of HID Over GATT Boot Device task instances +#define HOGPBH_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * MACROS + **************************************************************************************** +*/ + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Possible states of the HOGPBH task +enum hogpbh_state +{ + /// Disconnected state + HOGPBH_FREE, + /// IDLE state + HOGPBH_IDLE, + /// Busy State + HOGPBH_BUSY, + /// Number of defined states. + HOGPBH_STATE_MAX +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/// Environment variable for each Connections +struct hogpbh_cnx_env +{ + /// on-going operation + struct ke_msg * operation; + ///HIDS characteristics + struct hogpbh_content hids[HOGPBH_NB_HIDS_INST_MAX]; + ///Number of HIDS instances found + uint8_t hids_nb; +}; + +/// HID Over Gatt Profile Boot Host environment variable +struct hogpbh_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct hogpbh_cnx_env* env[HOGPBH_IDX_MAX]; + /// State of different task instances + ke_state_t state[HOGPBH_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * GLOBAL FUNCTIONS DECLARATIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Retrieve HID boot host profile interface + * + * @return HID boot host profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* hogpbh_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send HID ATT DB discovery results to HOGPBH host. + **************************************************************************************** + */ +void hogpbh_enable_rsp_send(struct hogpbh_env_tag *hogpbh_env, uint8_t conidx, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +extern const struct ke_state_handler hogpbh_default_handler; + + + +#endif /* (BLE_HID_BOOT_HOST) */ + +/// @} HOGPBH + +#endif /* _HOGPBH_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/src/hogpbh_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/src/hogpbh_task.c new file mode 100644 index 0000000..b8aeec8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpbh/src/hogpbh_task.c @@ -0,0 +1,706 @@ +/** + **************************************************************************************** + * + * @file hogpbh_task.c + * + * @brief HID Over GATT Profile Boot Host Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HOGPBHTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_HID_BOOT_HOST) + +#include "gap.h" +#include "attm.h" +#include "hogpbh_task.h" +#include "hogpbh.h" +#include "gattc_task.h" +#include "hogp_common.h" + +#include "ke_mem.h" +#include "co_utils.h" +#include "co_math.h" + +/* + * LOCAL VARIABLES DEFINITION + **************************************************************************************** + */ + +/// State machine used to retrieve HID Service characteristics information +const struct prf_char_def hogpbh_hids_char[HOGPBH_CHAR_MAX] = +{ + /// Protocol Mode + [HOGPBH_CHAR_PROTO_MODE] = {ATT_CHAR_PROTOCOL_MODE, + ATT_MANDATORY, + ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR_NO_RESP}, + /// Boot Keyboard Input Report + [HOGPBH_CHAR_BOOT_KB_IN_REPORT] = {ATT_CHAR_BOOT_KB_IN_REPORT, + ATT_OPTIONAL, + ATT_CHAR_PROP_RD | ATT_CHAR_PROP_NTF}, + /// Boot Keyboard Output Report + [HOGPBH_CHAR_BOOT_KB_OUT_REPORT] = {ATT_CHAR_BOOT_KB_OUT_REPORT, + ATT_OPTIONAL, + ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR}, + /// Boot Keyboard Output Report + [HOGPBH_CHAR_BOOT_MOUSE_IN_REPORT] = {ATT_CHAR_BOOT_MOUSE_IN_REPORT, + ATT_OPTIONAL, + ATT_CHAR_PROP_RD | ATT_CHAR_PROP_NTF}, +}; + +/// State machine used to retrieve HID Service characteristic description information +const struct prf_char_desc_def hogpbh_hids_char_desc[HOGPBH_DESC_MAX] = +{ + /// Boot Keyboard Input Report Client Config + [HOGPBH_DESC_BOOT_KB_IN_REPORT_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_OPTIONAL, HOGPBH_CHAR_BOOT_KB_IN_REPORT}, + /// Boot Mouse Input Report Client Config + [HOGPBH_DESC_BOOT_MOUSE_IN_REPORT_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_OPTIONAL, HOGPBH_CHAR_BOOT_MOUSE_IN_REPORT}, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HOGPBH_ENABLE_REQ message. + * The handler enables the HID Over GATT Profile Boot Host Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int hogpbh_enable_req_handler(ke_msg_id_t const msgid, + struct hogpbh_enable_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + int msg_status = KE_MSG_CONSUMED; + + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Battery service Client Role Task Environment + struct hogpbh_env_tag *hogpbh_env = PRF_ENV_GET(HOGPBH, hogpbh); + + ASSERT_INFO(hogpbh_env != NULL, dest_id, src_id); + if((state == HOGPBH_IDLE) && (hogpbh_env->env[conidx] == NULL)) + { + // allocate environment variable for task instance + hogpbh_env->env[conidx] = (struct hogpbh_cnx_env*) ke_malloc(sizeof(struct hogpbh_cnx_env),KE_MEM_ATT_DB); + memset(hogpbh_env->env[conidx], 0, sizeof(struct hogpbh_cnx_env)); + + //Config connection, start discovering + if(param->con_type == PRF_CON_DISCOVERY) + { + //start discovering HID on peer + prf_disc_svc_send(&(hogpbh_env->prf_env), conidx, ATT_SVC_HID); + + // Go to DISCOVERING state + ke_state_set(dest_id, HOGPBH_BUSY); + hogpbh_env->env[conidx]->operation = ke_param2msg(param); + msg_status = KE_MSG_NO_FREE; + } + //normal connection, get saved att details + else + { + hogpbh_env->env[conidx]->hids_nb = param->hids_nb; + memcpy(&(hogpbh_env->env[conidx]->hids[0]), &(param->hids[0]), sizeof(struct hogpbh_content) * HOGPBH_NB_HIDS_INST_MAX); + + //send APP confirmation that can start normal connection to TH + hogpbh_enable_rsp_send(hogpbh_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if(state != HOGPBH_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if(status != GAP_ERR_NO_ERROR) + { + hogpbh_enable_rsp_send(hogpbh_env, conidx, status); + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + + if(state == HOGPBH_BUSY) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct hogpbh_env_tag *hogpbh_env = PRF_ENV_GET(HOGPBH, hogpbh); + + ASSERT_INFO(hogpbh_env != NULL, dest_id, src_id); + ASSERT_INFO(hogpbh_env->env[conidx] != NULL, dest_id, src_id); + + if(hogpbh_env->env[conidx]->hids_nb < HOGPBH_NB_HIDS_INST_MAX) + { + // Retrieve HID characteristics + prf_extract_svc_info(ind, HOGPBH_CHAR_MAX, &hogpbh_hids_char[0], + &(hogpbh_env->env[conidx]->hids[hogpbh_env->env[conidx]->hids_nb].chars[0]), + HOGPBH_DESC_MAX, &hogpbh_hids_char_desc[0], + &(hogpbh_env->env[conidx]->hids[hogpbh_env->env[conidx]->hids_nb].descs[0])); + + // Store service range + hogpbh_env->env[conidx]->hids[hogpbh_env->env[conidx]->hids_nb].svc.shdl = ind->start_hdl; + hogpbh_env->env[conidx]->hids[hogpbh_env->env[conidx]->hids_nb].svc.ehdl = ind->end_hdl; + } + + hogpbh_env->env[conidx]->hids_nb++; + } + + return (KE_MSG_CONSUMED); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HOGPBH_READ_INFO_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int hogpbh_read_info_req_handler(ke_msg_id_t const msgid, struct hogpbh_read_info_req const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if(state == HOGPBH_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct hogpbh_env_tag *hogpbh_env = PRF_ENV_GET(HOGPBH, hogpbh); + ASSERT_INFO(hogpbh_env != NULL, dest_id, src_id); + // environment variable not ready + if(hogpbh_env->env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + // check parameter range + else if(param->hid_idx > hogpbh_env->env[conidx]->hids_nb) + { + status = PRF_ERR_INVALID_PARAM; + } + else + { + uint16_t handle = ATT_INVALID_HANDLE; + status = PRF_ERR_INEXISTENT_HDL; + + // check requested info + switch(param->info) + { + /// Protocol Mode + case HOGPBH_PROTO_MODE: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].chars[HOGPBH_CHAR_PROTO_MODE].val_hdl; + }break; + /// Boot Keyboard Input Report + case HOGPBH_BOOT_KB_IN_REPORT: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].chars[HOGPBH_CHAR_BOOT_KB_IN_REPORT].val_hdl; + }break; + /// Boot Keyboard Output Report + case HOGPBH_BOOT_KB_OUT_REPORT: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].chars[HOGPBH_CHAR_BOOT_KB_OUT_REPORT].val_hdl; + }break; + /// Boot Mouse Input Report + case HOGPBH_BOOT_MOUSE_IN_REPORT: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].chars[HOGPBH_CHAR_BOOT_MOUSE_IN_REPORT].val_hdl; + }break; + /// Boot Keyboard Input Report Client Config + case HOGPBH_BOOT_KB_IN_NTF_CFG: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].descs[HOGPBH_DESC_BOOT_KB_IN_REPORT_CFG].desc_hdl; + }break; + /// Boot Mouse Input Report Client Config + case HOGPBH_BOOT_MOUSE_IN_NTF_CFG: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].descs[HOGPBH_DESC_BOOT_MOUSE_IN_REPORT_CFG].desc_hdl; + }break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + }break; + } + + if(handle != ATT_INVALID_HANDLE) + { + status = GAP_ERR_NO_ERROR; + // read information + prf_read_char_send(&(hogpbh_env->prf_env), conidx, + hogpbh_env->env[conidx]->hids[param->hid_idx].svc.shdl, + hogpbh_env->env[conidx]->hids[param->hid_idx].svc.ehdl, handle); + + // store context of request and go into busy state + hogpbh_env->env[conidx]->operation = ke_param2msg(param); + ke_state_set(dest_id, HOGPBH_BUSY); + msg_status = KE_MSG_NO_FREE; + } + } + } + // process message later + else if (state == HOGPBH_BUSY) + { + status = GAP_ERR_NO_ERROR; + msg_status = KE_MSG_SAVED; + } + + + // request cannot be performed + if(status != GAP_ERR_NO_ERROR) + { + struct hogpbh_read_info_rsp * rsp = KE_MSG_ALLOC(HOGPBH_READ_INFO_RSP, + src_id, dest_id, hogpbh_read_info_rsp); + // set error status + rsp->status = status; + rsp->info = param->info; + rsp->hid_idx = param->hid_idx; + + ke_msg_send(rsp); + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HOGPBH_WRITE_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int hogpbh_write_req_handler(ke_msg_id_t const msgid, struct hogpbh_write_req const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if(state == HOGPBH_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct hogpbh_env_tag *hogpbh_env = PRF_ENV_GET(HOGPBH, hogpbh); + ASSERT_INFO(hogpbh_env != NULL, dest_id, src_id); + // environment variable not ready + if(hogpbh_env->env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + // check parameter range + else if((param->hid_idx > hogpbh_env->env[conidx]->hids_nb) + || (param->info > HOGPBH_INFO_MAX) + || ((param->info >= HOGPBH_BOOT_KB_IN_NTF_CFG) && (param->data.ntf_cfg > PRF_CLI_START_NTF))) + { + status = PRF_ERR_INVALID_PARAM; + } + else + { + uint16_t handle = ATT_INVALID_HANDLE; + status = PRF_ERR_INEXISTENT_HDL; + + // check requested info + switch(param->info) + { + // Protocol Mode + case HOGPBH_PROTO_MODE: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].chars[HOGPBH_CHAR_PROTO_MODE].val_hdl; + prf_gatt_write(&hogpbh_env->prf_env, conidx, handle, (uint8_t*)¶m->data.proto_mode, 1, GATTC_WRITE_NO_RESPONSE); + }break; + // Boot Keyboard Input Report + case HOGPBH_BOOT_KB_IN_REPORT: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].chars[HOGPBH_CHAR_BOOT_KB_IN_REPORT].val_hdl; + prf_gatt_write(&hogpbh_env->prf_env, conidx, handle, (uint8_t*)param->data.report.value, param->data.report.length, GATTC_WRITE); + }break; + // Boot Keyboard Output Report + case HOGPBH_BOOT_KB_OUT_REPORT: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].chars[HOGPBH_CHAR_BOOT_KB_OUT_REPORT].val_hdl; + prf_gatt_write(&hogpbh_env->prf_env, conidx, handle, (uint8_t*)param->data.report.value, param->data.report.length, param->wr_cmd ? GATTC_WRITE_NO_RESPONSE : GATTC_WRITE); + }break; + // Boot Mouse Input Report + case HOGPBH_BOOT_MOUSE_IN_REPORT: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].chars[HOGPBH_CHAR_BOOT_MOUSE_IN_REPORT].val_hdl; + prf_gatt_write(&hogpbh_env->prf_env, conidx, handle, (uint8_t*)param->data.report.value, param->data.report.length, GATTC_WRITE); + }break; + // Boot Keyboard Input Report Client Config + case HOGPBH_BOOT_KB_IN_NTF_CFG: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].descs[HOGPBH_DESC_BOOT_KB_IN_REPORT_CFG].desc_hdl; + prf_gatt_write_ntf_ind(&hogpbh_env->prf_env, conidx, handle, param->data.ntf_cfg); + }break; + // Boot Mouse Input Report Client Config + case HOGPBH_BOOT_MOUSE_IN_NTF_CFG: + { + handle = hogpbh_env->env[conidx]->hids[param->hid_idx].descs[HOGPBH_DESC_BOOT_MOUSE_IN_REPORT_CFG].desc_hdl; + prf_gatt_write_ntf_ind(&hogpbh_env->prf_env, conidx, handle, param->data.ntf_cfg); + }break; + default: + { + status = PRF_ERR_INVALID_PARAM; + }break; + } + + if(handle != ATT_INVALID_HANDLE) + { + status = GAP_ERR_NO_ERROR; + + // store context of request and go into busy state + hogpbh_env->env[conidx]->operation = ke_param2msg(param); + ke_state_set(dest_id, HOGPBH_BUSY); + msg_status = KE_MSG_NO_FREE; + } + } + } + // process message later + else if (state == HOGPBH_BUSY) + { + status = GAP_ERR_NO_ERROR; + msg_status = KE_MSG_SAVED; + } + + + // request cannot be performed + if(status != GAP_ERR_NO_ERROR) + { + struct hogpbh_write_rsp * rsp = KE_MSG_ALLOC(HOGPBH_WRITE_RSP, + src_id, dest_id, hogpbh_write_rsp); + // set error status + rsp->status = status; + rsp->info = param->info; + rsp->hid_idx = param->hid_idx; + + ke_msg_send(rsp); + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct hogpbh_env_tag *hogpbh_env = PRF_ENV_GET(HOGPBH, hogpbh); + + // sanity check + if((state == HOGPBH_BUSY) && (hogpbh_env->env[conidx] != NULL) + && (hogpbh_env->env[conidx]->operation != NULL)) + { + switch(hogpbh_env->env[conidx]->operation->id) + { + case HOGPBH_ENABLE_REQ: + { + uint8_t status = param->status; + + if (param->status == ATT_ERR_NO_ERROR) + { + // check characteristic validity + if(hogpbh_env->env[conidx]->hids_nb > 0) + { + uint8_t i; + for (i = 0 ; (i < co_min(hogpbh_env->env[conidx]->hids_nb, HOGPBH_NB_HIDS_INST_MAX)) + && (status == GAP_ERR_NO_ERROR) ; i++) + { + status = prf_check_svc_char_validity(HOGPBH_CHAR_MAX, hogpbh_env->env[conidx]->hids[i].chars, + hogpbh_hids_char); + + // check descriptor validity + if(status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(HOGPBH_DESC_MAX, + hogpbh_env->env[conidx]->hids[i].descs, hogpbh_hids_char_desc, + hogpbh_env->env[conidx]->hids[i].chars); + } + } + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + } + hogpbh_enable_rsp_send(hogpbh_env, conidx, status); + }break; + case HOGPBH_READ_INFO_REQ: + { + struct hogpbh_read_info_req* req = (struct hogpbh_read_info_req*) ke_msg2param(hogpbh_env->env[conidx]->operation); + + struct hogpbh_read_info_rsp * rsp = KE_MSG_ALLOC(HOGPBH_READ_INFO_RSP, + prf_dst_task_get(&(hogpbh_env->prf_env), conidx), dest_id, hogpbh_read_info_rsp); + // set error status + rsp->status = param->status; + rsp->hid_idx = req->hid_idx; + rsp->info = req->info; + + ke_msg_send(rsp); + + }break; + case HOGPBH_WRITE_REQ: + { + struct hogpbh_write_req* req = (struct hogpbh_write_req*) ke_msg2param(hogpbh_env->env[conidx]->operation); + + struct hogpbh_write_rsp * rsp = KE_MSG_ALLOC(HOGPBH_WRITE_RSP, + prf_dst_task_get(&(hogpbh_env->prf_env), conidx), dest_id, hogpbh_write_rsp); + // set error status + rsp->status =param->status; + rsp->hid_idx = req->hid_idx; + rsp->info = req->info; + + ke_msg_send(rsp); + }break; + default: + { + // Not Expected at all + ASSERT_ERR(0); + }break; + } + + // operation is over - go back to idle state + ke_free(hogpbh_env->env[conidx]->operation); + hogpbh_env->env[conidx]->operation = NULL; + ke_state_set(dest_id, HOGPBH_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + + if(state == HOGPBH_BUSY) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct hogpbh_env_tag *hogpbh_env = PRF_ENV_GET(HOGPBH, hogpbh); + struct hogpbh_read_info_req* req = (struct hogpbh_read_info_req*) ke_msg2param(hogpbh_env->env[conidx]->operation); + + ASSERT_INFO(hogpbh_env != NULL, dest_id, src_id); + ASSERT_INFO(hogpbh_env->env[conidx] != NULL, dest_id, src_id); + + + struct hogpbh_read_info_rsp * rsp = KE_MSG_ALLOC_DYN(HOGPBH_READ_INFO_RSP, + prf_dst_task_get(&(hogpbh_env->prf_env),conidx), dest_id, hogpbh_read_info_rsp, param->length); + + // set error status + rsp->status = GAP_ERR_NO_ERROR; + rsp->hid_idx = req->hid_idx; + rsp->info = req->info; + + switch(req->info) + { + /// Protocol Mode + case HOGPBH_PROTO_MODE: + { + rsp->data.proto_mode = param->value[0]; + }break; + /// Boot Keyboard Input Report + case HOGPBH_BOOT_KB_IN_REPORT: + /// Boot Keyboard Output Report + case HOGPBH_BOOT_KB_OUT_REPORT: + /// Boot Mouse Input Report + case HOGPBH_BOOT_MOUSE_IN_REPORT: + { + rsp->data.report.length = param->length; + memcpy(rsp->data.report.value, param->value, param->length); + }break; + /// Boot Keyboard Input Report Client Config + case HOGPBH_BOOT_KB_IN_NTF_CFG: + /// Boot Mouse Input Report Client Config + case HOGPBH_BOOT_MOUSE_IN_NTF_CFG: + { + rsp->data.ntf_cfg = co_read16p(param->value); + }break; + default: + { + ASSERT_ERR(0); + }break; + } + + // send response + ke_msg_send(rsp); + + // operation is over - go back to idle state + ke_free(hogpbh_env->env[conidx]->operation); + hogpbh_env->env[conidx]->operation = NULL; + ke_state_set(dest_id, HOGPBH_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + + if(state != HOGPBH_FREE) + { + // HID Instance + uint8_t hid_nb; + uint8_t att_info = HOGPBH_INFO_MAX; + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct hogpbh_env_tag *hogpbh_env = PRF_ENV_GET(HOGPBH, hogpbh); + + // BOOT Report - HID instance is unknown. + for (hid_nb = 0; (hid_nb < hogpbh_env->env[conidx]->hids_nb); hid_nb++) + { + if (param->handle == hogpbh_env->env[conidx]->hids[hid_nb].chars[HOGPBH_CHAR_BOOT_KB_IN_REPORT].val_hdl) + { + att_info = HOGPBH_BOOT_KB_IN_REPORT; + break; + } + else if (param->handle == hogpbh_env->env[conidx]->hids[hid_nb].chars[HOGPBH_CHAR_BOOT_MOUSE_IN_REPORT].val_hdl) + { + att_info = HOGPBH_BOOT_MOUSE_IN_REPORT; + break; + } + } + + // check if indication can be handled + if(att_info != HOGPBH_INFO_MAX) + { + // send boot report indication + struct hogpbh_boot_report_ind* ind = KE_MSG_ALLOC_DYN(HOGPBH_BOOT_REPORT_IND, + prf_dst_task_get(&(hogpbh_env->prf_env), conidx), dest_id, + hogpbh_boot_report_ind, param->length); + + ind->hid_idx = hid_nb; + ind->info = att_info; + ind->report.length = param->length; + memcpy(ind->report.value, param->value, param->length); + + ke_msg_send(ind); + } + } + + return (KE_MSG_CONSUMED); +} + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +const struct ke_msg_handler hogpbh_default_state[] = +{ + {HOGPBH_ENABLE_REQ, (ke_msg_func_t)hogpbh_enable_req_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + + {HOGPBH_READ_INFO_REQ, (ke_msg_func_t)hogpbh_read_info_req_handler}, + {HOGPBH_WRITE_REQ, (ke_msg_func_t)hogpbh_write_req_handler}, + + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + + +// Specifies the message handlers that are common to all states. +const struct ke_state_handler hogpbh_default_handler = KE_STATE_HANDLER(hogpbh_default_state); + + +#endif /* (BLE_HOG_BOOT_HOST) */ +/// @} HOGPBHTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/api/hogpd_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/api/hogpd_task.h new file mode 100644 index 0000000..9cae3b2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/api/hogpd_task.h @@ -0,0 +1,319 @@ +/** + **************************************************************************************** + * + * @file hogpd_task.h + * + * @brief Header file - HID Over GATT Profile Device Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _HOGPD_TASK_H_ +#define _HOGPD_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup HOGPDTASK Task + * @ingroup HOGPD + * @brief HID Over GATT Profile Task. + * + * The HOGPD_TASK is responsible for handling the messages coming in and out of the + * @ref HOGPD block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include +#include "rwip_task.h" // Task definitions +#include "hogp_common.h" +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximal number of HIDS that can be added in the DB +#define HOGPD_NB_HIDS_INST_MAX (2) +/// Maximal number of Report Char. that can be added in the DB for one HIDS - Up to 11 +#define HOGPD_NB_REPORT_INST_MAX (5) + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/// Messages for HID Over GATT Profile Device Role +enum hogpd_msg_id +{ + /// Restore bond data the HID Over GATT Profile Device Role Task + HOGPD_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_HOGPD), + /// Response of enabled request + HOGPD_ENABLE_RSP, + + /// Request sending of a report to the host - notification + HOGPD_REPORT_UPD_REQ, + /// Response sending of a report to the host + HOGPD_REPORT_UPD_RSP, + + + /// Request from peer device to Read or update a report value + HOGPD_REPORT_REQ_IND, + /// Confirmation for peer device for Reading or Updating a report value + HOGPD_REPORT_CFM, + + /// Inform Device APP that Protocol Mode Characteristic Value has been written on Device + HOGPD_PROTO_MODE_REQ_IND, + /// Confirm if the new protocol mode value + HOGPD_PROTO_MODE_CFM, + + /// Inform Device APP that a Client Characteristic Configuration has been modified + HOGPD_NTF_CFG_IND, + /// Inform APP that HID Control Point Characteristic Value has been written on Device + HOGPD_CTNL_PT_IND, +}; + +/// Report Char. Configuration Flag Values +enum hogpd_report_cfg +{ + /// Input Report + HOGPD_CFG_REPORT_IN = 0x01, + /// Output Report + HOGPD_CFG_REPORT_OUT = 0x02, + //HOGPD_CFG_REPORT_FEAT can be used as a mask to check Report type + /// Feature Report + HOGPD_CFG_REPORT_FEAT = 0x03, + /// Input report with Write capabilities + HOGPD_CFG_REPORT_WR = 0x10, +}; + +/// Features Flag Values +enum hogpd_cfg +{ + /// Keyboard Device + HOGPD_CFG_KEYBOARD = 0x01, + /// Mouse Device + HOGPD_CFG_MOUSE = 0x02, + /// Protocol Mode present + HOGPD_CFG_PROTO_MODE = 0x04, + /// Extended Reference Present + HOGPD_CFG_MAP_EXT_REF = 0x08, + /// Boot Keyboard Report write capability + HOGPD_CFG_BOOT_KB_WR = 0x10, + /// Boot Mouse Report write capability + HOGPD_CFG_BOOT_MOUSE_WR = 0x20, + + /// Valid Feature mask + HOGPD_CFG_MASK = 0x3F, + + /// Report Notification Enabled (to be shift for each report index) + HOGPD_CFG_REPORT_NTF_EN = 0x40, +}; + +/// Type of reports +enum hogpd_report_type +{ + /// The Report characteristic is used to exchange data between a HID Device and a HID Host. + HOGPD_REPORT, + /// The Report Map characteristic + HOGPD_REPORT_MAP, + /// Boot Keyboard Input Report + HOGPD_BOOT_KEYBOARD_INPUT_REPORT, + /// Boot Keyboard Output Report + HOGPD_BOOT_KEYBOARD_OUTPUT_REPORT, + /// Boot Mouse Input Report + HOGPD_BOOT_MOUSE_INPUT_REPORT, +}; + +/// type of operation requested by peer device +enum hogpd_op +{ + /// No operation + HOGPD_OP_NO, + /// Read report value + HOGPD_OP_REPORT_READ, + /// Modify/Set report value + HOGPD_OP_REPORT_WRITE, + /// Modify Protocol mode + HOGPD_OP_PROT_UPDATE, +}; + +/* + * APIs Structures + **************************************************************************************** + */ +/// External Report Reference +struct hogpd_ext_ref +{ + /// External Report Reference - Included Service + uint16_t inc_svc_hdl; + /// External Report Reference - Characteristic UUID + uint16_t rep_ref_uuid; +}; + +/// Database Creation Service Instance Configuration structure +struct hogpd_hids_cfg +{ + /// Service Features (@see enum hogpd_cfg) + uint8_t svc_features; + /// Number of Report Char. instances to add in the database + uint8_t report_nb; + /// Report Char. Configuration (@see enum hogpd_report_cfg) + uint8_t report_char_cfg[HOGPD_NB_REPORT_INST_MAX]; + /// Report id number + uint8_t report_id[HOGPD_NB_REPORT_INST_MAX]; + /// HID Information Char. Values + struct hids_hid_info hid_info; + /// External Report Reference + struct hogpd_ext_ref ext_ref; + +}; + +/// Parameters of the @ref HOGPD_CREATE_DB_REQ message +struct hogpd_db_cfg +{ + /// Number of HIDS to add + uint8_t hids_nb; + /// Initial configuration for each HIDS instance + struct hogpd_hids_cfg cfg[HOGPD_NB_HIDS_INST_MAX]; +}; + +/// Parameters of the @ref HOGPD_ENABLE_REQ message +struct hogpd_enable_req +{ + ///Connection index + uint8_t conidx; + /// Notification Configurations + uint16_t ntf_cfg[HOGPD_NB_HIDS_INST_MAX]; +}; + +/// Parameters of the @ref HOGPD_ENABLE_RSP message +struct hogpd_enable_rsp +{ + ///Connection index + uint8_t conidx; + /// status of the request + uint8_t status; +}; + +///Parameters of the @ref HOGPD_NTF_CFG_IND message +struct hogpd_ntf_cfg_ind +{ + /// Connection Index + uint8_t conidx; + /// Notification Configurations + uint16_t ntf_cfg[HOGPD_NB_HIDS_INST_MAX]; +}; + + +/// Inform Device APP that Protocol Mode Characteristic Value has been written on Device +struct hogpd_proto_mode_req_ind +{ + /// Connection Index + uint8_t conidx; + /// Operation requested (update protocol mode @see hogpd_op) + uint8_t operation; + /// HIDS Instance + uint8_t hid_idx; + /// New Protocol Mode Characteristic Value + uint8_t proto_mode; +}; + +/// Confirm if the new protocol mode value +struct hogpd_proto_mode_cfm +{ + /// Connection Index + uint8_t conidx; + /// Status of the request + uint8_t status; + /// HIDS Instance + uint8_t hid_idx; + /// New Protocol Mode Characteristic Value + uint8_t proto_mode; +}; + +/// HID Report Info +struct hogpd_report_info +{ + /// HIDS Instance + uint8_t hid_idx; + /// type of report (@see enum hogpd_report_type) + uint8_t type; + /// Report Length (uint8_t) + uint16_t length; + /// Report Instance - 0 for boot reports and report map + uint8_t idx; + /// Report data + uint8_t value[__ARRAY_EMPTY]; +}; + + +/// Request sending of a report to the host - notification +struct hogpd_report_upd_req +{ + /// Connection Index + uint8_t conidx; + /// Report Info + struct hogpd_report_info report; +}; + +/// Response sending of a report to the host +struct hogpd_report_upd_rsp +{ + /// Connection Index + uint8_t conidx; + /// Status of the request + uint8_t status; +}; + +/// Request from peer device to Read or update a report value +struct hogpd_report_req_ind +{ + /// Connection Index + uint8_t conidx; + /// Operation requested (read/write @see hogpd_op) + uint8_t operation; + /// Report Info + struct hogpd_report_info report; +}; + +/// Confirmation for peer device for Reading or Updating a report value +struct hogpd_report_cfm +{ + /// Connection Index + uint8_t conidx; + /// Operation requested (read/write @see enum hogpd_op) + uint8_t operation; + /// Status of the request + uint8_t status; + /// Report Info + struct hogpd_report_info report; +}; + + +///Parameters of the @ref HOGPD_CTNL_PT_IND message +struct hogpd_ctnl_pt_ind +{ + /// Connection Index + uint8_t conidx; + /// HIDS Instance + uint8_t hid_idx; + /// New HID Control Point Characteristic Value + uint8_t hid_ctnl_pt; +}; + + + +/// @} HOGPDTASK + +#endif /* _HOGPD_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/sourcelist.txt new file mode 100644 index 0000000..ce7fdb6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + hogpd.c + hogpd_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/src/hogpd.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/src/hogpd.c new file mode 100644 index 0000000..1009760 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/src/hogpd.c @@ -0,0 +1,921 @@ +/** + **************************************************************************************** + * + * @file hogpd.c + * + * @brief HID Over GATT Profile HID Device Role Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HOGPD + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_HID_DEVICE) + +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "hogpd.h" +#include "hogpd_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" + +/* + * DEFINES + **************************************************************************************** + */ +#define HIDS_CFG_FLAG_MANDATORY_MASK ((uint32_t)0x000FD) +#define HIDS_MANDATORY_ATT_NB (7) +#define HIDS_CFG_FLAG_MAP_EXT_MASK ((uint32_t)0x00102) +#define HIDS_MAP_EXT_ATT_NB (2) +#define HIDS_CFG_FLAG_PROTO_MODE_MASK ((uint32_t)0x00600) +#define HIDS_PROTO_MODE_ATT_NB (2) +#define HIDS_CFG_FLAG_KEYBOARD_MASK ((uint32_t)0x0F800) +#define HIDS_KEYBOARD_ATT_NB (5) +#define HIDS_CFG_FLAG_MOUSE_MASK ((uint32_t)0x70000) +#define HIDS_MOUSE_ATT_NB (3) + +#define HIDS_CFG_REPORT_MANDATORY_MASK ((uint32_t)0x7) +#define HIDS_REPORT_MANDATORY_ATT_NB (3) +#define HIDS_CFG_REPORT_IN_MASK ((uint32_t)0x8) +#define HIDS_REPORT_IN_ATT_NB (1) +// number of attribute index for a report +#define HIDS_REPORT_NB_IDX (4) + +/* + * HIDS ATTRIBUTES DEFINITION + **************************************************************************************** + */ + +/// Full HIDS Database Description - Used to add attributes into the database +const struct attm_desc hids_att_db[HOGPD_IDX_NB] = +{ + // HID Service Declaration + [HOGPD_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // HID Service Declaration + [HOGPD_IDX_INCL_SVC] = {ATT_DECL_INCLUDE, PERM(RD, ENABLE), 0, 0}, + + // HID Information Characteristic Declaration + [HOGPD_IDX_HID_INFO_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE),0, 0}, + // HID Information Characteristic Value + [HOGPD_IDX_HID_INFO_VAL] = {ATT_CHAR_HID_INFO, PERM(RD, ENABLE), 0, sizeof(struct hids_hid_info)}, + + // HID Control Point Characteristic Declaration + [HOGPD_IDX_HID_CTNL_PT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // HID Control Point Characteristic Value + [HOGPD_IDX_HID_CTNL_PT_VAL] = {ATT_CHAR_HID_CTNL_PT, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, + + // Report Map Characteristic Declaration + [HOGPD_IDX_REPORT_MAP_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Report Map Characteristic Value + [HOGPD_IDX_REPORT_MAP_VAL] = {ATT_CHAR_REPORT_MAP, PERM(RD, ENABLE), PERM(RI, ENABLE), HOGPD_REPORT_MAP_MAX_LEN}, + // Report Map Characteristic - External Report Reference Descriptor + [HOGPD_IDX_REPORT_MAP_EXT_REP_REF] = {ATT_DESC_EXT_REPORT_REF, PERM(RD, ENABLE), 0, sizeof(uint16_t)}, + + // Protocol Mode Characteristic Declaration + [HOGPD_IDX_PROTO_MODE_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Protocol Mode Characteristic Value + [HOGPD_IDX_PROTO_MODE_VAL] = {ATT_CHAR_PROTOCOL_MODE, (PERM(RD, ENABLE) | PERM(WRITE_COMMAND, ENABLE)), PERM(RI, ENABLE), sizeof(uint8_t)}, + + // Boot Keyboard Input Report Characteristic Declaration + [HOGPD_IDX_BOOT_KB_IN_REPORT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Boot Keyboard Input Report Characteristic Value + [HOGPD_IDX_BOOT_KB_IN_REPORT_VAL] = {ATT_CHAR_BOOT_KB_IN_REPORT, (PERM(RD, ENABLE) | PERM(NTF, ENABLE)), PERM(RI, ENABLE), HOGPD_BOOT_REPORT_MAX_LEN}, + // Boot Keyboard Input Report Characteristic - Client Characteristic Configuration Descriptor + [HOGPD_IDX_BOOT_KB_IN_REPORT_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Boot Keyboard Output Report Characteristic Declaration + [HOGPD_IDX_BOOT_KB_OUT_REPORT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Boot Keyboard Output Report Characteristic Value + [HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL] = {ATT_CHAR_BOOT_KB_OUT_REPORT, (PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE) | PERM(WRITE_COMMAND, ENABLE)), PERM(RI, ENABLE), HOGPD_BOOT_REPORT_MAX_LEN}, + + // Boot Mouse Input Report Characteristic Declaration + [HOGPD_IDX_BOOT_MOUSE_IN_REPORT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Boot Mouse Input Report Characteristic Value + [HOGPD_IDX_BOOT_MOUSE_IN_REPORT_VAL] = {ATT_CHAR_BOOT_MOUSE_IN_REPORT, (PERM(RD, ENABLE) | PERM(NTF, ENABLE)), PERM(RI, ENABLE), HOGPD_BOOT_REPORT_MAX_LEN,}, + // Boot Mouse Input Report Characteristic - Client Characteristic Configuration Descriptor + [HOGPD_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WRITE_REQ, ENABLE) | PERM(WRITE_COMMAND, ENABLE), 0, 0}, + + // Report Characteristic Declaration + [HOGPD_IDX_REPORT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Report Characteristic Value + [HOGPD_IDX_REPORT_VAL] = {ATT_CHAR_REPORT, PERM(RD, ENABLE), PERM(RI, ENABLE), HOGPD_REPORT_MAX_LEN}, + // Report Characteristic - Report Reference Descriptor + [HOGPD_IDX_REPORT_REP_REF] = {ATT_DESC_REPORT_REF, PERM(RD, ENABLE), 0, sizeof(struct hids_report_ref)}, + // Report Characteristic - Client Characteristic Configuration Descriptor + [HOGPD_IDX_REPORT_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WRITE_REQ, ENABLE) | PERM(WRITE_COMMAND, ENABLE), 0, 0}, +}; + + +/** + **************************************************************************************** + * @brief Initialization of the HOGPD module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] env Collector or Service allocated environment data. + * @param[in|out] start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t hogpd_init (struct prf_task_env* env, uint16_t* start_hdl, uint16_t app_task, uint8_t sec_lvl, struct hogpd_db_cfg* params) +{ + struct hogpd_env_tag* hogpd_env = NULL; + // Service content flag - Without Report Characteristics + uint32_t cfg_flag[HOGPD_NB_HIDS_INST_MAX][(HOGPD_ATT_MAX/32) +1]; + // Start handle used to allocate service. + uint16_t shdl; + + // Total number of attributes + uint8_t tot_nb_att = 0; + + // array of service description used to allocate the service + struct attm_desc * hids_db[HOGPD_NB_HIDS_INST_MAX]; + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Service Instance Counter, Counter + uint8_t svc_idx, report_idx; + // Report Char. Report Ref value + struct hids_report_ref report_ref; + + //-------------------- allocate memory required for the profile --------------------- + hogpd_env = (struct hogpd_env_tag* ) ke_malloc(sizeof(struct hogpd_env_tag), KE_MEM_ATT_DB); + + // ensure that everything is initialized + memset(hids_db, 0, sizeof(hids_db)); + memset(cfg_flag, 0, sizeof(cfg_flag)); + memset(hogpd_env, 0, sizeof(struct hogpd_env_tag)); + + + // Check number of HID instances + if ((params->hids_nb == 0) || (params->hids_nb > HOGPD_NB_HIDS_INST_MAX)) + { + // Invalid number of service instances + status = PRF_ERR_INVALID_PARAM; + } + + // For each required HIDS instance + for (svc_idx = 0; ((svc_idx < params->hids_nb) && (status == GAP_ERR_NO_ERROR)); svc_idx++) + { + // Check number of Report Char. instances + if (params->cfg[svc_idx].report_nb > HOGPD_NB_REPORT_INST_MAX) + { + // Too many Report Char. Instances + status = PRF_ERR_INVALID_PARAM; + break; + } + + // retrieve features + hogpd_env->svcs[svc_idx].features = params->cfg[svc_idx].svc_features & HOGPD_CFG_MASK; + hogpd_env->svcs[svc_idx].nb_report = params->cfg[svc_idx].report_nb; + + hids_db[svc_idx] = (struct attm_desc *) ke_malloc(HOGPD_ATT_MAX * sizeof(struct attm_desc), KE_MEM_NON_RETENTION); + + cfg_flag[svc_idx][0] = HIDS_CFG_FLAG_MANDATORY_MASK; + hogpd_env->svcs[svc_idx].nb_att += HIDS_MANDATORY_ATT_NB; + + // copy default definition of the HID attribute database + memcpy(hids_db[svc_idx], hids_att_db, sizeof(struct attm_desc) * HOGPD_ATT_UNIQ_NB); + + //-------------------------------------------------------------------- + // Compute cfg_flag[i] without Report Characteristics + //-------------------------------------------------------------------- + if ((params->cfg[svc_idx].svc_features & HOGPD_CFG_MAP_EXT_REF) == HOGPD_CFG_MAP_EXT_REF) + { + cfg_flag[svc_idx][0] |= HIDS_CFG_FLAG_MAP_EXT_MASK; + hogpd_env->svcs[svc_idx].nb_att += HIDS_MAP_EXT_ATT_NB; + // store reference handle in database + hids_db[svc_idx][HOGPD_IDX_INCL_SVC].max_size = params->cfg[svc_idx].ext_ref.inc_svc_hdl; + } + + if ((params->cfg[svc_idx].svc_features & HOGPD_CFG_PROTO_MODE) == HOGPD_CFG_PROTO_MODE) + { + cfg_flag[svc_idx][0] |= HIDS_CFG_FLAG_PROTO_MODE_MASK; + hogpd_env->svcs[svc_idx].nb_att += HIDS_PROTO_MODE_ATT_NB; + } + + if ((params->cfg[svc_idx].svc_features & HOGPD_CFG_KEYBOARD) == HOGPD_CFG_KEYBOARD) + { + cfg_flag[svc_idx][0] |= HIDS_CFG_FLAG_KEYBOARD_MASK; + hogpd_env->svcs[svc_idx].nb_att += HIDS_KEYBOARD_ATT_NB; + + if ((params->cfg[svc_idx].svc_features & HOGPD_CFG_BOOT_KB_WR) == HOGPD_CFG_BOOT_KB_WR) + { + // Adds write permissions on report + hids_db[svc_idx][HOGPD_IDX_BOOT_KB_IN_REPORT_VAL].perm |= (PERM(WRITE_REQ, ENABLE)); + } + } + + if ((params->cfg[svc_idx].svc_features & HOGPD_CFG_MOUSE) == HOGPD_CFG_MOUSE) + { + cfg_flag[svc_idx][0] |= HIDS_CFG_FLAG_MOUSE_MASK; + hogpd_env->svcs[svc_idx].nb_att += HIDS_MOUSE_ATT_NB; + + if ((params->cfg[svc_idx].svc_features & HOGPD_CFG_BOOT_MOUSE_WR) == HOGPD_CFG_BOOT_MOUSE_WR) + { + // Adds write permissions on report + hids_db[svc_idx][HOGPD_IDX_BOOT_MOUSE_IN_REPORT_VAL].perm |= (PERM(WRITE_REQ, ENABLE)); + } + } + + // set report handle offset + hogpd_env->svcs[svc_idx].report_hdl_offset = hogpd_env->svcs[svc_idx].nb_att; + + //-------------------------------------------------------------------- + // Update cfg_flag_rep[i] with Report Characteristics + //-------------------------------------------------------------------- + for (report_idx = 0; report_idx < params->cfg[svc_idx].report_nb; report_idx++) + { + uint16_t perm = 0; + uint16_t report_offset = HIDS_REPORT_NB_IDX*report_idx; + + // update config for current report + cfg_flag[svc_idx][(HOGPD_IDX_REPORT_CHAR + report_offset) / 32] |= (1 << ((HOGPD_IDX_REPORT_CHAR + report_offset) % 32)); + cfg_flag[svc_idx][(HOGPD_IDX_REPORT_VAL + report_offset) / 32] |= (1 << ((HOGPD_IDX_REPORT_VAL + report_offset) % 32)); + cfg_flag[svc_idx][(HOGPD_IDX_REPORT_REP_REF + report_offset) / 32] |= (1 << ((HOGPD_IDX_REPORT_REP_REF + report_offset) % 32)); + hogpd_env->svcs[svc_idx].nb_att += HIDS_REPORT_MANDATORY_ATT_NB; + + // copy default definition of the HID report database + memcpy(&(hids_db[svc_idx][HOGPD_IDX_REPORT_CHAR + report_offset]), &(hids_att_db[HOGPD_IDX_REPORT_CHAR]), sizeof(struct attm_desc) * HIDS_REPORT_NB_IDX); + + // according to the report type, update value property + switch (params->cfg[svc_idx].report_char_cfg[report_idx] & HOGPD_CFG_REPORT_FEAT) + { + // Input Report + case HOGPD_CFG_REPORT_IN: + { + // add notification permission on report + perm = PERM(RD, ENABLE) | PERM(NTF, ENABLE); + // Report Char. supports NTF => Client Characteristic Configuration Descriptor + cfg_flag[svc_idx][(HOGPD_IDX_REPORT_NTF_CFG + report_offset) / 32] |= (1 << ((HOGPD_IDX_REPORT_NTF_CFG + report_offset) % 32)); + hogpd_env->svcs[svc_idx].nb_att += HIDS_REPORT_IN_ATT_NB; + + // update feature flag + hogpd_env->svcs[svc_idx].features |= (HOGPD_CFG_REPORT_NTF_EN << report_idx); + + // check if attribute value could be written + if ((params->cfg[svc_idx].report_char_cfg[report_idx] & HOGPD_CFG_REPORT_WR) == HOGPD_CFG_REPORT_WR) + { + perm |= PERM(WRITE_REQ, ENABLE); + } + } break; + + // Output Report + case HOGPD_CFG_REPORT_OUT: + { + perm = PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE) | PERM(WRITE_COMMAND, ENABLE); + } break; + + // Feature Report + case HOGPD_CFG_REPORT_FEAT: + { + perm = PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE); + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + hids_db[svc_idx][HOGPD_IDX_REPORT_VAL + (HIDS_REPORT_NB_IDX*report_idx)].perm = perm; + } + + // increment total number of attributes to allocate. + tot_nb_att += hogpd_env->svcs[svc_idx].nb_att; + } + + // Check that attribute list can be allocated. + if(status == ATT_ERR_NO_ERROR) + { + status = attm_reserve_handle_range(start_hdl, tot_nb_att); + } + + // used start handle calculated when handle range reservation has been performed + shdl = *start_hdl; + hogpd_env->start_hdl = *start_hdl; + hogpd_env->hids_nb = params->hids_nb; + // Initialize the Report ID + report_ref.report_id = 0; + + // allocate services + for (svc_idx = 0; ((svc_idx < params->hids_nb) && (status == GAP_ERR_NO_ERROR)); svc_idx++) + { + uint16_t handle; + status = attm_svc_create_db(&shdl, ATT_SVC_HID, (uint8_t *)&(cfg_flag[svc_idx][0]), + HOGPD_ATT_MAX, NULL, env->task, hids_db[svc_idx], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS))); + // update start handle for next service + shdl += hogpd_env->svcs[svc_idx].nb_att; + + // Set HID Information Char. Value + if(status == GAP_ERR_NO_ERROR) + { + handle = hogpd_get_att_handle(hogpd_env, svc_idx, HOGPD_IDX_HID_INFO_VAL, 0); + ASSERT_ERR(handle != ATT_INVALID_HDL); + status = attm_att_set_value(handle, sizeof(struct hids_hid_info), 0, (uint8_t *)¶ms->cfg[svc_idx].hid_info); + } + + // Set Report Map Char. External Report Ref value + if((status == GAP_ERR_NO_ERROR) + && ((params->cfg[svc_idx].svc_features & HOGPD_CFG_MAP_EXT_REF) == HOGPD_CFG_MAP_EXT_REF)) + { + handle = hogpd_get_att_handle(hogpd_env, svc_idx, HOGPD_IDX_REPORT_MAP_EXT_REP_REF, 0); + ASSERT_ERR(handle != ATT_INVALID_HDL); + status = attm_att_set_value(handle, sizeof(uint16_t), 0, (uint8_t *)¶ms->cfg[svc_idx].ext_ref.rep_ref_uuid); + } + + // Set Report External Ref value + for(report_idx = 0 ; (status == GAP_ERR_NO_ERROR) + && (report_idx < params->cfg[svc_idx].report_nb) ; report_idx++) + { + // Save the Report ID + report_ref.report_id = params->cfg[svc_idx].report_id[report_idx]; + // Set Report Type + report_ref.report_type = (params->cfg[svc_idx].report_char_cfg[report_idx] & HOGPD_CFG_REPORT_FEAT); + + handle = hogpd_get_att_handle(hogpd_env, svc_idx, HOGPD_IDX_REPORT_REP_REF, report_idx); + ASSERT_ERR(handle != ATT_INVALID_HDL); + // Set value in the database + status = attm_att_set_value(handle, sizeof(struct hids_report_ref), 0, (uint8_t *)&report_ref); + } + + + // by default in Report protocol mode. + hogpd_env->svcs[svc_idx].proto_mode = HOGP_REPORT_PROTOCOL_MODE; + + } + + //-------------------- Update profile task information --------------------- + if (status == ATT_ERR_NO_ERROR) + { + // allocate HOGPD required environment variable + env->env = (prf_env_t*) hogpd_env; + hogpd_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + hogpd_env->prf_env.prf_task = env->task | PERM(PRF_MI, DISABLE); + // initialize environment variable + env->id = TASK_ID_HOGPD; + +// env->desc.idx_max = HOGPD_IDX_MAX; +// env->desc.state = hogpd_env->state; +// env->desc.default_handler = &hogpd_default_handler; + + hogpd_task_init(&(env->desc)); + + // service is ready, go into an Idle state + ke_state_set(env->task, HOGPD_IDLE); + } + else if(hogpd_env != NULL) + { + ke_free(hogpd_env); + } + + // ensure that temporary allocated databases description is correctly free + for (svc_idx = 0; svc_idx < HOGPD_NB_HIDS_INST_MAX; svc_idx++) + { + if(hids_db[svc_idx] != NULL) + { + ke_free(hids_db[svc_idx]); + } + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the HOGPD module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void hogpd_destroy(struct prf_task_env* env) +{ + struct hogpd_env_tag* hogpd_env = (struct hogpd_env_tag*) env->env; + + // free profile environment variables + env->env = NULL; + ke_free(hogpd_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void hogpd_create(struct prf_task_env* env, uint8_t conidx) +{ + /* Nothing to do */ +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void hogpd_cleanup(struct prf_task_env* env, uint8_t conidx, uint8_t reason) +{ + struct hogpd_env_tag* hogpd_env = (struct hogpd_env_tag*) env->env; + uint8_t svc_idx; + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + // Reset the notification configuration to ensure that no notification will be sent on + // a disconnected link + for (svc_idx = 0; svc_idx < hogpd_env->hids_nb; svc_idx++) + { + hogpd_env->svcs[svc_idx].ntf_cfg[conidx] = 0; + } +} + + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// HOGPD Task interface required by profile manager +const struct prf_task_cbs hogpd_itf = +{ + (prf_init_fnct) hogpd_init, + hogpd_destroy, + hogpd_create, + hogpd_cleanup, +}; + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* hogpd_prf_itf_get(void) +{ + return &hogpd_itf; +} + + +uint16_t hogpd_get_att_handle(struct hogpd_env_tag* hogpd_env, uint8_t svc_idx, uint8_t att_idx, uint8_t report_idx) +{ + uint16_t handle = ATT_INVALID_HDL; + uint8_t i = 0; + + // Sanity check + if((svc_idx < hogpd_env ->hids_nb) && (att_idx < HOGPD_IDX_NB) + && ((att_idx < HOGPD_ATT_UNIQ_NB) || (report_idx < hogpd_env->svcs[svc_idx].nb_report))) + { + handle = hogpd_env->start_hdl; + + for(i = 0 ; i < svc_idx ; i++) + { + // update start handle for next service - only useful if multiple service, else not used. + handle += hogpd_env->svcs[i].nb_att; + } + + // increment index according to expected index + if(att_idx < HOGPD_ATT_UNIQ_NB) + { + handle += att_idx; + + // check if Keyboard feature active + if((hogpd_env->svcs[svc_idx].features & HOGPD_CFG_KEYBOARD) == 0) + { + if(att_idx > HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL) + { + handle -= HIDS_KEYBOARD_ATT_NB; + } + // Error Case + else if ((att_idx >= HOGPD_IDX_BOOT_KB_IN_REPORT_CHAR) + && (att_idx <= HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL)) + { + handle = ATT_INVALID_HANDLE; + } + } + + // check if Mouse feature active + if((hogpd_env->svcs[svc_idx].features & HOGPD_CFG_MOUSE) == 0) + { + if(att_idx > HOGPD_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG) + { + handle -= HIDS_MOUSE_ATT_NB; + } + // Error Case + else if ((att_idx >= HOGPD_IDX_BOOT_MOUSE_IN_REPORT_CHAR) + && (att_idx <= HOGPD_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG)) + { + handle = ATT_INVALID_HANDLE; + } + } + + // check if Protocol Mode feature active + if((hogpd_env->svcs[svc_idx].features & HOGPD_CFG_PROTO_MODE) == 0) + { + if(att_idx > HOGPD_IDX_PROTO_MODE_VAL) + { + handle -= HIDS_PROTO_MODE_ATT_NB; + } + // Error Case + else if ((att_idx >= HOGPD_IDX_PROTO_MODE_CHAR) + && (att_idx <= HOGPD_IDX_PROTO_MODE_VAL)) + { + handle = ATT_INVALID_HANDLE; + } + } + + // check if Ext Ref feature active + if((hogpd_env->svcs[svc_idx].features & HOGPD_CFG_MAP_EXT_REF) == 0) + { + if(att_idx > HOGPD_IDX_REPORT_MAP_EXT_REP_REF) + { + handle -= HIDS_MAP_EXT_ATT_NB; + } + else if(att_idx > HOGPD_IDX_INCL_SVC) + { + handle -= 1; + } + // Error Case + else if ((att_idx == HOGPD_IDX_INCL_SVC) + || (att_idx == HOGPD_IDX_REPORT_MAP_EXT_REP_REF)) + { + handle = ATT_INVALID_HANDLE; + } + } + } + else + { + handle += hogpd_env->svcs[svc_idx].report_hdl_offset; + + // increment attribute handle with other reports + for(i = 0 ; i < report_idx; i++) + { + handle += HIDS_REPORT_MANDATORY_ATT_NB; + // check if it's a Report input + if((hogpd_env->svcs[svc_idx].features & (HOGPD_CFG_REPORT_NTF_EN << i)) != 0) + { + handle += HIDS_REPORT_IN_ATT_NB; + } + } + + // Error check + if((att_idx == HOGPD_IDX_REPORT_NTF_CFG) + && ((hogpd_env->svcs[svc_idx].features & (HOGPD_CFG_REPORT_NTF_EN << report_idx)) != 0)) + { + handle = ATT_INVALID_HANDLE; + } + else + { + // update handle cursor + handle += att_idx - HOGPD_ATT_UNIQ_NB; + } + } + } + + return handle; +} + +uint8_t hogpd_get_att_idx(struct hogpd_env_tag* hogpd_env, uint16_t handle, uint8_t *svc_idx, uint8_t *att_idx, uint8_t *report_idx) +{ + uint16_t hdl_cursor = hogpd_env->start_hdl; + uint8_t status = PRF_APP_ERROR; + + // invalid index + *att_idx = HOGPD_IDX_NB; + + // Browse list of services + // handle must be greater than current index + for(*svc_idx = 0 ; (*svc_idx < hogpd_env->hids_nb) && (handle >= hdl_cursor) ; (*svc_idx)++) + { + // check if handle is on current service + if(handle >= (hdl_cursor + hogpd_env->svcs[*svc_idx].nb_att)) + { + hdl_cursor += hogpd_env->svcs[*svc_idx].nb_att; + continue; + } + + // if we are here, we are sure that handle is valid + status = GAP_ERR_NO_ERROR; + *report_idx = 0; + + // check if handle is in reports or not + if(handle < (hdl_cursor + hogpd_env->svcs[*svc_idx].report_hdl_offset)) + { + if(handle == hdl_cursor) + { + *att_idx = HOGPD_IDX_SVC; + break; + } + + // check if Ext Ref feature active + if((hogpd_env->svcs[*svc_idx].features & HOGPD_CFG_MAP_EXT_REF) != 0) + { + hdl_cursor += 1; + if(handle == hdl_cursor) + { + *att_idx = HOGPD_IDX_INCL_SVC; + break; + } + } + + // check if handle is in mandatory range + hdl_cursor += HIDS_MANDATORY_ATT_NB; + if(handle <= hdl_cursor) + { + *att_idx = HOGPD_IDX_REPORT_MAP_VAL - (hdl_cursor - handle - 1); + break; + } + + // check if Ext Ref feature active + if((hogpd_env->svcs[*svc_idx].features & HOGPD_CFG_MAP_EXT_REF) != 0) + { + hdl_cursor += 1; + if(handle == hdl_cursor) + { + *att_idx = HOGPD_IDX_REPORT_MAP_EXT_REP_REF; + break; + } + } + + // check if Protocol Mode feature active + if((hogpd_env->svcs[*svc_idx].features & HOGPD_CFG_PROTO_MODE) != 0) + { + hdl_cursor += HIDS_PROTO_MODE_ATT_NB; + if(handle <= hdl_cursor) + { + *att_idx = HOGPD_IDX_PROTO_MODE_VAL - (hdl_cursor - handle - 1); + break; + } + } + + // check if Keyboard feature active + if((hogpd_env->svcs[*svc_idx].features & HOGPD_CFG_KEYBOARD) != 0) + { + hdl_cursor += HIDS_KEYBOARD_ATT_NB; + if(handle <= hdl_cursor) + { + *att_idx = HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL - (hdl_cursor - handle - 1); + break; + } + } + + // check if Mouse feature active + if((hogpd_env->svcs[*svc_idx].features & HOGPD_CFG_MOUSE) != 0) + { + hdl_cursor += HIDS_MOUSE_ATT_NB; + if(handle <= hdl_cursor) + { + *att_idx = HOGPD_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG - (hdl_cursor - handle - 1); + break; + } + } + + // not expected + ASSERT_ERR(0); + } + else + { + // add handle offset + hdl_cursor += hogpd_env->svcs[*svc_idx].report_hdl_offset; + + for(*report_idx = 0 ; (*report_idx < hogpd_env->svcs[*svc_idx].nb_report) ; (*report_idx)++) + { + hdl_cursor += HIDS_REPORT_MANDATORY_ATT_NB; + if(handle <= hdl_cursor) + { + *att_idx = HOGPD_IDX_REPORT_REP_REF - (hdl_cursor - handle - 1); + break; + } + + if((hogpd_env->svcs[*svc_idx].features & (HOGPD_CFG_REPORT_NTF_EN << *report_idx)) != 0) + { + hdl_cursor += HIDS_REPORT_IN_ATT_NB; + if(handle == hdl_cursor) + { + *att_idx = HOGPD_IDX_REPORT_NTF_CFG; + break; + } + } + } + + // not expected + ASSERT_ERR(*att_idx != HOGPD_IDX_NB); + } + // loop not expected here + break; + } + + return (status); +} + + +uint8_t hogpd_ntf_send(uint8_t conidx, const struct hogpd_report_info* report) +{ + struct hogpd_env_tag* hogpd_env = PRF_ENV_GET(HOGPD, hogpd); + uint8_t status = GAP_ERR_NO_ERROR; + uint16_t handle = ATT_INVALID_HANDLE; + uint8_t att_idx = HOGPD_IDX_NB; + uint16_t max_report_len= 0; + uint16_t feature_mask = 0; + uint8_t exp_prot_mode = 0; + + // According to the report type retrieve: + // - Attribute index + // - Attribute max length + // - Feature to use + // - Expected protocol mode + switch(report->type) + { + // An Input Report + case HOGPD_REPORT: + { + att_idx = HOGPD_IDX_REPORT_VAL; + max_report_len = HOGPD_REPORT_MAX_LEN; + feature_mask = HOGPD_CFG_REPORT_NTF_EN << report->idx; + exp_prot_mode = HOGP_REPORT_PROTOCOL_MODE; + }break; + // Boot Keyboard input report + case HOGPD_BOOT_KEYBOARD_INPUT_REPORT: + { + att_idx = HOGPD_IDX_BOOT_KB_IN_REPORT_VAL; + max_report_len = HOGPD_BOOT_REPORT_MAX_LEN; + feature_mask = HOGPD_CFG_KEYBOARD; + exp_prot_mode = HOGP_BOOT_PROTOCOL_MODE; + }break; + // Boot Mouse input report + case HOGPD_BOOT_MOUSE_INPUT_REPORT: + { + att_idx = HOGPD_IDX_BOOT_MOUSE_IN_REPORT_VAL; + max_report_len = HOGPD_BOOT_REPORT_MAX_LEN; + feature_mask = HOGPD_CFG_MOUSE; + exp_prot_mode = HOGP_BOOT_PROTOCOL_MODE; + }break; + + default: /* Nothing to do */ break; + } + + handle = hogpd_get_att_handle(hogpd_env, report->hid_idx, att_idx, report->idx); + + // check if attribute is found + if(handle == ATT_INVALID_HANDLE) + { + // check if it's an unsupported feature + if((feature_mask != 0) && (report->hid_idx < hogpd_env->hids_nb) + && (report->idx < hogpd_env->svcs[report->hid_idx].nb_report) + && ((hogpd_env->svcs[report->hid_idx].features & feature_mask) == 0)) + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + // or an invalid param + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + // check if length is valid + else if(report->length > max_report_len) + { + status = PRF_ERR_UNEXPECTED_LEN; + } + // check if notification is enabled + else if ((hogpd_env->svcs[report->hid_idx].ntf_cfg[conidx] & feature_mask) == 0) + { + status = PRF_ERR_NTF_DISABLED; + } + // check if protocol mode is valid + else if((hogpd_env->svcs[report->hid_idx].proto_mode != exp_prot_mode) + && ((hogpd_env->svcs[report->hid_idx].features & HOGPD_CFG_PROTO_MODE) != 0)) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + if(status == GAP_ERR_NO_ERROR) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *report_ntf = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), prf_src_task_get(&(hogpd_env->prf_env), conidx), + gattc_send_evt_cmd, report->length); + + // Fill in the parameter structure + report_ntf->operation = GATTC_NOTIFY; + report_ntf->handle = handle; + // pack measured value in database + report_ntf->length = report->length; + memcpy(report_ntf->value, report->value, report->length); + // send notification to peer device + ke_msg_send(report_ntf); + } + + return (status); +} + +uint8_t hogpd_ntf_cfg_ind_send(uint8_t conidx, uint8_t svc_idx, uint8_t att_idx, uint8_t report_idx, uint16_t ntf_cfg) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + uint16_t mask = 0; + + struct hogpd_env_tag* hogpd_env = PRF_ENV_GET(HOGPD, hogpd); + + // set notification config update mask + switch(att_idx) + { + // An Input Report + case HOGPD_IDX_REPORT_NTF_CFG: + { + mask = HOGPD_CFG_REPORT_NTF_EN << report_idx; + }break; + // Boot Keyboard input report + case HOGPD_IDX_BOOT_KB_IN_REPORT_NTF_CFG: + { + mask = HOGPD_CFG_KEYBOARD; + }break; + // Boot Mouse input report + case HOGPD_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG: + { + mask = HOGPD_CFG_MOUSE; + }break; + + default: + { + ASSERT_ERR(0); + }break; + } + + // Stop notification + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + hogpd_env->svcs[svc_idx].ntf_cfg[conidx] &= ~mask; + } + // Start notification + else if(ntf_cfg == PRF_CLI_START_NTF) + { + hogpd_env->svcs[svc_idx].ntf_cfg[conidx] |= mask; + } + // Provided value is incorrect + else + { + status = PRF_APP_ERROR; + } + + + // inform application about updated notification configuration + if(status == GAP_ERR_NO_ERROR) + { + // Allocate the GATT notification message + struct hogpd_ntf_cfg_ind *ntf_cfg_ind = KE_MSG_ALLOC(HOGPD_NTF_CFG_IND, + prf_dst_task_get(&(hogpd_env->prf_env), conidx), + prf_src_task_get(&(hogpd_env->prf_env), conidx), + hogpd_ntf_cfg_ind); + + // Fill in the parameter structure + ntf_cfg_ind->conidx = conidx; + + for(svc_idx = 0 ; svc_idx < HOGPD_NB_HIDS_INST_MAX; svc_idx++) + { + ntf_cfg_ind->ntf_cfg[svc_idx] = hogpd_env->svcs[svc_idx].ntf_cfg[conidx]; + } + + // send indication to application + ke_msg_send(ntf_cfg_ind); + } + + return (status); +} + +#endif /* BLE_HID_DEVICE */ + +/// @} HOGPD diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/src/hogpd.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/src/hogpd.h new file mode 100644 index 0000000..1327096 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/src/hogpd.h @@ -0,0 +1,286 @@ +/** + **************************************************************************************** + * + * @file hogpd.h + * + * @brief Header file - HID Over GATT Profile Device Role + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _HOGPD_H_ +#define _HOGPD_H_ + +/** + **************************************************************************************** + * @addtogroup HOGPD HID Over GATT Profile Device Role + * @ingroup HOGP + * @brief HID Over GATT Profile Device Role + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_HID_DEVICE) +#include "hogp_common.h" +#include "hogpd_task.h" + +#include "prf.h" +#include "prf_types.h" + + +/* + * DEFINES + **************************************************************************************** + */ + + +///Maximum number of HID Over GATT Device task instances +#define HOGPD_IDX_MAX (0x01) + +/// Maximal length of Report Char. Value +#define HOGPD_REPORT_MAX_LEN (45) +/// Maximal length of Report Map Char. Value +#define HOGPD_REPORT_MAP_MAX_LEN (512) + +/// Length of Boot Report Char. Value Maximal Length +#define HOGPD_BOOT_REPORT_MAX_LEN (8) + +/// Boot KB Input Report Notification Configuration Bit Mask +#define HOGPD_BOOT_KB_IN_NTF_CFG_MASK (0x40) +/// Boot KB Input Report Notification Configuration Bit Mask +#define HOGPD_BOOT_MOUSE_IN_NTF_CFG_MASK (0x80) +/// Boot Report Notification Configuration Bit Mask +#define HOGPD_REPORT_NTF_CFG_MASK (0x20) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the HOGPD task +enum hogpd_state +{ + /// Idle state + HOGPD_IDLE, + /// Request from application on-going + HOGPD_REQ_BUSY = (1 << 0), + /// OPeration requested by peer device on-going + HOGPD_OP_BUSY = (1 << 1), + /// Number of defined states. + HOGPD_STATE_MAX +}; + +/// HID Service Attributes Indexes +enum +{ + HOGPD_IDX_SVC, + + // Included Service + HOGPD_IDX_INCL_SVC, + + // HID Information + HOGPD_IDX_HID_INFO_CHAR, + HOGPD_IDX_HID_INFO_VAL, + + // HID Control Point + HOGPD_IDX_HID_CTNL_PT_CHAR, + HOGPD_IDX_HID_CTNL_PT_VAL, + + // Report Map + HOGPD_IDX_REPORT_MAP_CHAR, + HOGPD_IDX_REPORT_MAP_VAL, + HOGPD_IDX_REPORT_MAP_EXT_REP_REF, + + // Protocol Mode + HOGPD_IDX_PROTO_MODE_CHAR, + HOGPD_IDX_PROTO_MODE_VAL, + + // Boot Keyboard Input Report + HOGPD_IDX_BOOT_KB_IN_REPORT_CHAR, + HOGPD_IDX_BOOT_KB_IN_REPORT_VAL, + HOGPD_IDX_BOOT_KB_IN_REPORT_NTF_CFG, + + // Boot Keyboard Output Report + HOGPD_IDX_BOOT_KB_OUT_REPORT_CHAR, + HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL, + + // Boot Mouse Input Report + HOGPD_IDX_BOOT_MOUSE_IN_REPORT_CHAR, + HOGPD_IDX_BOOT_MOUSE_IN_REPORT_VAL, + HOGPD_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG, + + /// number of attributes that are uniq in the service + HOGPD_ATT_UNIQ_NB, + + // Report + HOGPD_IDX_REPORT_CHAR = HOGPD_ATT_UNIQ_NB, + HOGPD_IDX_REPORT_VAL, + HOGPD_IDX_REPORT_REP_REF, + HOGPD_IDX_REPORT_NTF_CFG, + + HOGPD_IDX_NB, + + // maximum number of attribute that can be present in the HID service + HOGPD_ATT_MAX = HOGPD_ATT_UNIQ_NB + (4* (HOGPD_NB_REPORT_INST_MAX)), +}; + + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// HIDS service cfg +struct hogpd_svc_cfg +{ + /// Service Features (@see enum hogpd_cfg) + uint16_t features; + /// Notification configuration + uint16_t ntf_cfg[BLE_CONNECTION_MAX]; + /// Number of attribute present in service + uint8_t nb_att; + /// Number of Report Char. instances to add in the database + uint8_t nb_report; + /// Handle offset where report are available - to enhance handle search + uint8_t report_hdl_offset; + /// Current Protocol Mode + uint8_t proto_mode; +}; + +/// HIDS on-going operation +struct hogpd_operation +{ + /// Connection index impacted + uint8_t conidx; + /// Operation type (@see enum hogpd_op) + uint8_t operation; + /// Handle impacted by operation + uint16_t handle; +}; + +/// HID Over GATT Profile HID Device Role Environment variable +struct hogpd_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Supported Features + struct hogpd_svc_cfg svcs[HOGPD_NB_HIDS_INST_MAX]; + /// HIDS Start Handles + uint16_t start_hdl; + /// On-going operation (requested by peer device) + struct hogpd_operation op; + /// HID Over GATT task state + ke_state_t state[HOGPD_IDX_MAX]; + /// Number of HIDS added in the database + uint8_t hids_nb; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve HID service profile interface + * + * @return HID service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* hogpd_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Retrieve Attribute handle from service and attribute index + * + * @param[in] hogpd_env HID Service environment + * @param[in] svc_idx HID Service index + * @param[in] att_idx Attribute index + * @param[in] report_idx Report index + * + * @return HID attribute handle or INVALID HANDLE if nothing found + **************************************************************************************** + */ +uint16_t hogpd_get_att_handle(struct hogpd_env_tag* hogpd_env, uint8_t svc_idx, uint8_t att_idx, uint8_t report_idx); + + +/** + **************************************************************************************** + * @brief Retrieve Service and attribute index form attribute handle + * + * @param[out] handle Attribute handle + * @param[out] svc_idx HID Service index + * @param[out] att_idx Attribute index + * @param[out] report_idx Report Index + * + * @return Success if attribute and service index found, else Application error + **************************************************************************************** + */ +uint8_t hogpd_get_att_idx(struct hogpd_env_tag* hogpd_env, uint16_t handle, uint8_t *svc_idx, uint8_t *att_idx, uint8_t *report_idx); + + +/** + **************************************************************************************** + * @brief Check if a report value can be notified to the peer central. + * + * @param[in] conidx Connection Index + * @param[in] report Report information to notify + * + * @return Status Code to know if request succeed or not. + **************************************************************************************** + */ +uint8_t hogpd_ntf_send(uint8_t conidx, const struct hogpd_report_info* report); + +/** + **************************************************************************************** + * @brief Send a HOGPD_NTF_CFG_IND message to the application + * + * @param[in] conidx Connection Index + * @param[in] svc_idx HID Service index + * @param[in] att_idx Attribute index + * @param[in] report_idx Report Index + * @param[in] ntf_cfg Client Characteristic Configuration Descriptor value + * + * @return Status Code to know if notification update succeed or not + **************************************************************************************** + */ +uint8_t hogpd_ntf_cfg_ind_send(uint8_t conidx, uint8_t svc_idx, uint8_t att_idx, uint8_t report_idx, uint16_t ntf_cfg); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void hogpd_task_init(struct ke_task_desc *p_task_desc); + +//extern const struct ke_state_handler hogpd_default_handler; + + +#endif /* #if (BLE_HID_DEVICE) */ + +/// @} HOGPD + +#endif /* _HOGPD_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/src/hogpd_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/src/hogpd_task.c new file mode 100644 index 0000000..c1bb349 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/src/hogpd_task.c @@ -0,0 +1,796 @@ +/** + **************************************************************************************** + * + * @file hogpd_task.c + * + * @brief HID Over GATT Profile Device Role Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HOGPDTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_HID_DEVICE) +#include "gap.h" +#include "gattc_task.h" + +//HID Over GATT Profile Device Role Functions +#include "hogpd.h" +#include "hogpd_task.h" + +#include "prf_utils.h" + +#include "co_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HOGPD_ENABLE_REQ message. + * The handler enables the HID Over GATT Profile Device Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int hogpd_enable_req_handler(ke_msg_id_t const msgid, + struct hogpd_enable_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Counter for HIDS instance + uint8_t svc_idx; + uint8_t status = GAP_ERR_NO_ERROR; + + struct hogpd_env_tag* hogpd_env = PRF_ENV_GET(HOGPD, hogpd); + + ASSERT_ERR(hogpd_env!=NULL); + + // Check provided values and check if connection exists + if((param->conidx > BLE_CONNECTION_MAX) + || (gapc_get_conhdl(param->conidx) == GAP_INVALID_CONHDL)) + { + // an error occurs, trigg it. + status = (param->conidx > BLE_CONNECTION_MAX) ? GAP_ERR_INVALID_PARAM : PRF_ERR_REQ_DISALLOWED; + } + else + { + for (svc_idx = 0; svc_idx < hogpd_env->hids_nb; svc_idx++) + { + // Retrieve notification configuration + hogpd_env->svcs[svc_idx].ntf_cfg[param->conidx] = param->ntf_cfg[svc_idx]; + } + } + + // Send back response + struct hogpd_enable_rsp* rsp = KE_MSG_ALLOC(HOGPD_ENABLE_RSP, src_id, dest_id, hogpd_enable_rsp); + rsp->conidx = param->conidx; + rsp->status = status; + ke_msg_send(rsp); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HOGPD_REPORT_UPD_REQ message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int hogpd_report_upd_req_handler(ke_msg_id_t const msgid, + struct hogpd_report_upd_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + + // check that task is in idle state + if((state & HOGPD_REQ_BUSY) == HOGPD_IDLE) + { + // Status + uint8_t status = PRF_ERR_INVALID_PARAM; + // Check provided values and check if connection exists + if((param->conidx > BLE_CONNECTION_MAX) + || (gapc_get_conhdl(param->conidx) == GAP_INVALID_CONHDL)) + { + status = (param->conidx > BLE_CONNECTION_MAX) ? GAP_ERR_INVALID_PARAM : PRF_ERR_REQ_DISALLOWED; + } + else + { + status = hogpd_ntf_send(param->conidx, &(param->report)); + } + + // an error occurs inform application + if (status != GAP_ERR_NO_ERROR) + { + // send report update response + struct hogpd_report_upd_rsp *rsp = KE_MSG_ALLOC(HOGPD_REPORT_UPD_RSP, + src_id, dest_id, hogpd_report_upd_rsp); + rsp->conidx = param->conidx; + rsp->status = status; + ke_msg_send(rsp); + } + // go in a busy state + else + { + ke_state_set(dest_id, state | HOGPD_REQ_BUSY); + } + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HOGPD_REPORT_CFM message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int hogpd_report_cfm_handler(ke_msg_id_t const msgid, + struct hogpd_report_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + uint8_t state = ke_state_get(dest_id); + + // check that an operation is ongoing + if((state & HOGPD_OP_BUSY) == HOGPD_OP_BUSY) + { + uint16_t handle = ATT_INVALID_HANDLE; + uint8_t status = PRF_APP_ERROR; + struct hogpd_env_tag* hogpd_env = PRF_ENV_GET(HOGPD, hogpd); + + // check received status + if(param->status != GAP_ERR_NO_ERROR) + { + status = param->status; + } + // perform operation sanity check + else if((param->operation == hogpd_env->op.operation) && (param->conidx == hogpd_env->op.conidx)) + { + // retrieve attribute index. + uint8_t att_idx = 0; + switch(param->report.type) + { + case HOGPD_REPORT: + { + att_idx = HOGPD_IDX_REPORT_VAL; + }break; + case HOGPD_REPORT_MAP: + { + att_idx = HOGPD_IDX_REPORT_MAP_VAL; + }break; + case HOGPD_BOOT_KEYBOARD_INPUT_REPORT: + { + att_idx = HOGPD_IDX_BOOT_KB_IN_REPORT_VAL; + }break; + case HOGPD_BOOT_KEYBOARD_OUTPUT_REPORT: + { + att_idx = HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL; + }break; + case HOGPD_BOOT_MOUSE_INPUT_REPORT: + { + att_idx = HOGPD_IDX_BOOT_MOUSE_IN_REPORT_VAL; + }break; + default: /* Nothing to do */ break; + } + + // retrieve handle + handle = hogpd_get_att_handle(hogpd_env, param->report.hid_idx, att_idx, param->report.idx); + + // check if answer correspond to expected one + if(handle == hogpd_env->op.handle) + { + status = GAP_ERR_NO_ERROR; + } + } + + // read operation + if(hogpd_env->op.operation == HOGPD_OP_REPORT_READ) + { + uint16_t length = (status == GAP_ERR_NO_ERROR) ? param->report.length : 0; + //Send read response + struct gattc_read_cfm * rd_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, hogpd_env->op.conidx), dest_id, gattc_read_cfm, length); + rd_cfm->handle = hogpd_env->op.handle; + rd_cfm->status = status; + rd_cfm->length = length; + + if(status == GAP_ERR_NO_ERROR) + { + memcpy(rd_cfm->value, param->report.value, length); + } + + ke_msg_send(rd_cfm); + } + // write operation + else + { + //Send write response + struct gattc_write_cfm * wr_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, + KE_BUILD_ID(TASK_GATTC, hogpd_env->op.conidx), dest_id, gattc_write_cfm); + wr_cfm->handle = hogpd_env->op.handle; + wr_cfm->status = status; + ke_msg_send(wr_cfm); + } + + // cleanup environment + hogpd_env->op.operation = HOGPD_OP_NO; + hogpd_env->op.handle = ATT_INVALID_HDL; + hogpd_env->op.conidx = 0xFF; + + // go back in idle state + ke_state_set(dest_id, state & ~HOGPD_OP_BUSY); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HOGPD_PROTO_MODE_CFM message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int hogpd_proto_mode_cfm_handler(ke_msg_id_t const msgid, + struct hogpd_proto_mode_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + uint8_t state = ke_state_get(dest_id); + + // check that an operation is ongoing + if((state & HOGPD_OP_BUSY) == HOGPD_OP_BUSY) + { + uint16_t handle = ATT_INVALID_HANDLE; + uint8_t status = PRF_APP_ERROR; + struct hogpd_env_tag* hogpd_env = PRF_ENV_GET(HOGPD, hogpd); + + // check received status + if(param->status != GAP_ERR_NO_ERROR) + { + status = param->status; + } + // perform operation sanity check + else if((hogpd_env->op.operation == HOGPD_OP_PROT_UPDATE) && (param->conidx == hogpd_env->op.conidx)) + { + // retrieve handle + handle = hogpd_get_att_handle(hogpd_env, param->hid_idx, HOGPD_IDX_PROTO_MODE_VAL, 0); + + // check if answer correspond to expected one + if(handle == hogpd_env->op.handle) + { + status = GAP_ERR_NO_ERROR; + hogpd_env->svcs[param->hid_idx].proto_mode = param->proto_mode; + } + } + + // read operation/something failed + if(hogpd_env->op.operation == HOGPD_OP_REPORT_READ) + { + //Send read response + struct gattc_read_cfm * rd_cfm = KE_MSG_ALLOC(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, hogpd_env->op.conidx), dest_id, gattc_read_cfm); + rd_cfm->handle = hogpd_env->op.handle; + rd_cfm->status = status; + ke_msg_send(rd_cfm); + } + // write operation + else + { + //Send write response + struct gattc_write_cfm * wr_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, + KE_BUILD_ID(TASK_GATTC, hogpd_env->op.conidx), dest_id, gattc_write_cfm); + wr_cfm->handle = hogpd_env->op.handle; + wr_cfm->status = status; + ke_msg_send(wr_cfm); + } + + // cleanup environment + hogpd_env->op.operation = HOGPD_OP_NO; + hogpd_env->op.handle = ATT_INVALID_HDL; + hogpd_env->op.conidx = 0xFF; + + // go back in idle state + ke_state_set(dest_id, state & ~HOGPD_OP_BUSY); + } + + return (KE_MSG_CONSUMED); +} + + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_ATT_INFO_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t hid_idx, att_idx, report_idx; + struct gattc_att_info_cfm * cfm; + struct hogpd_env_tag* hogpd_env = PRF_ENV_GET(HOGPD, hogpd); + // retrieve attribute requested + uint8_t status = hogpd_get_att_idx(hogpd_env, param->handle, &hid_idx, &att_idx, &report_idx); + + //Send write response + cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + cfm->handle = param->handle; + + if(status == GAP_ERR_NO_ERROR) + { + // check which attribute is requested by peer device + switch(att_idx) + { + case HOGPD_IDX_BOOT_KB_IN_REPORT_VAL: + case HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL: + case HOGPD_IDX_BOOT_MOUSE_IN_REPORT_VAL: + case HOGPD_IDX_REPORT_VAL: + { + cfm->length = 0; + }break; + + // Notification configuration + case HOGPD_IDX_BOOT_KB_IN_REPORT_NTF_CFG: + case HOGPD_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG: + case HOGPD_IDX_REPORT_NTF_CFG: + { + cfm->length = 2; + }break; + + default: + { + cfm->length = 0; + status = ATT_ERR_WRITE_NOT_PERMITTED; + } break; + } + } + + cfm->status = status; + + ke_msg_send(cfm); + + return (KE_MSG_CONSUMED); +} + + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + NS_LOG_DEBUG("%s \r\n",__func__); + // check that task is in idle state + if((state & HOGPD_OP_BUSY) == HOGPD_IDLE) + { + uint8_t hid_idx, att_idx, report_idx; + + // used to know if gatt_write confirmation should be sent immediately + uint8_t conidx = KE_IDX_GET(src_id); + + struct hogpd_env_tag* hogpd_env = PRF_ENV_GET(HOGPD, hogpd); + // retrieve attribute requested + uint8_t status = hogpd_get_att_idx(hogpd_env, param->handle, &hid_idx, &att_idx, &report_idx); + + + // prepare operation info + hogpd_env->op.conidx = conidx; + hogpd_env->op.operation = HOGPD_OP_NO; + hogpd_env->op.handle = param->handle; + + if(status == GAP_ERR_NO_ERROR) + { + + // check which attribute is requested by peer device + switch(att_idx) + { + // Control point value updated + case HOGPD_IDX_HID_CTNL_PT_VAL: + { + // send control point indication + struct hogpd_ctnl_pt_ind *cp_ind = KE_MSG_ALLOC(HOGPD_CTNL_PT_IND, + prf_dst_task_get(&(hogpd_env->prf_env), conidx), dest_id, + hogpd_ctnl_pt_ind); + cp_ind->conidx = conidx; + cp_ind->hid_idx = hid_idx; + cp_ind->hid_ctnl_pt = param->value[0]; + ke_msg_send(cp_ind); + }break; + + // Modification of protocol mode requested + case HOGPD_IDX_PROTO_MODE_VAL: + { + // send control point indication + struct hogpd_proto_mode_req_ind *prot_ind = KE_MSG_ALLOC(HOGPD_PROTO_MODE_REQ_IND, + prf_dst_task_get(&(hogpd_env->prf_env), conidx), dest_id, + hogpd_proto_mode_req_ind); + prot_ind->conidx = conidx; + prot_ind->operation = HOGPD_OP_PROT_UPDATE; + prot_ind->hid_idx = hid_idx; + prot_ind->proto_mode = param->value[0]; + ke_msg_send(prot_ind); + + hogpd_env->op.operation = HOGPD_OP_PROT_UPDATE; + }break; + + // Modification of report value requested + case HOGPD_IDX_BOOT_KB_IN_REPORT_VAL: + case HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL: + case HOGPD_IDX_BOOT_MOUSE_IN_REPORT_VAL: + case HOGPD_IDX_REPORT_VAL: + { + // send report indication + struct hogpd_report_req_ind *report_ind = KE_MSG_ALLOC_DYN(HOGPD_REPORT_REQ_IND, + prf_dst_task_get(&(hogpd_env->prf_env), conidx), dest_id, + hogpd_report_req_ind, param->length); + + report_ind->conidx = conidx; + report_ind->operation = HOGPD_OP_REPORT_WRITE; + report_ind->report.length = param->length; + report_ind->report.hid_idx = hid_idx; + report_ind->report.idx = report_idx; + + memcpy(report_ind->report.value, param->value, param->length); + + // retrieve report type + switch(att_idx) + { + // An Input Report + case HOGPD_IDX_BOOT_KB_IN_REPORT_VAL: + { + report_ind->report.type = HOGPD_BOOT_KEYBOARD_INPUT_REPORT; + }break; + // Boot Keyboard input report + case HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL: + { + report_ind->report.type = HOGPD_BOOT_KEYBOARD_OUTPUT_REPORT; + }break; + // Boot Mouse input report + case HOGPD_IDX_BOOT_MOUSE_IN_REPORT_VAL: + { + report_ind->report.type = HOGPD_BOOT_MOUSE_INPUT_REPORT; + }break; + // Normal report + case HOGPD_IDX_REPORT_VAL: + { + report_ind->report.type = HOGPD_REPORT; + }break; + + default: + { + ASSERT_ERR(0); + }break; + } + + ke_msg_send(report_ind); + + hogpd_env->op.operation = HOGPD_OP_REPORT_WRITE; + }break; + + // Notification configuration update + case HOGPD_IDX_BOOT_KB_IN_REPORT_NTF_CFG: + case HOGPD_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG: + case HOGPD_IDX_REPORT_NTF_CFG: + { + uint16_t ntf_cfg = co_read16p(param->value); + status = hogpd_ntf_cfg_ind_send(conidx, hid_idx, att_idx, report_idx, ntf_cfg); + }break; + + default: + { + status = PRF_APP_ERROR; + } break; + } + } + + // check if peer operation is over + if(hogpd_env->op.operation == HOGPD_OP_NO) + { + //Send write response + struct gattc_write_cfm * cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + cfm->handle = param->handle; + cfm->status = status; + ke_msg_send(cfm); + } + else + { + // go into operation busy state + ke_state_set(dest_id, state | HOGPD_OP_BUSY); + } + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + NS_LOG_DEBUG("%s \r\n",__func__); + // check that task is in idle state + if((state & HOGPD_OP_BUSY) == HOGPD_IDLE) + { + uint8_t hid_idx, att_idx, report_idx; + bool finished = true; + uint8_t report_type = 0; + uint16_t value = 0; + uint16_t length = 0; + + struct hogpd_env_tag* hogpd_env = PRF_ENV_GET(HOGPD, hogpd); + + // used to know if gatt_write confirmation should be sent immediately + uint8_t conidx = KE_IDX_GET(src_id); + + // retrieve attribute requested + uint8_t status = hogpd_get_att_idx(hogpd_env, param->handle, &hid_idx, &att_idx, &report_idx); + + if(status == GAP_ERR_NO_ERROR) + { + // check which attribute is requested by peer device + switch(att_idx) + { + // ------------ READ report value requested + case HOGPD_IDX_BOOT_KB_IN_REPORT_VAL: + { + report_type = HOGPD_BOOT_KEYBOARD_INPUT_REPORT; + finished = false; + }break; + case HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL: + { + report_type = HOGPD_BOOT_KEYBOARD_OUTPUT_REPORT; + finished = false; + }break; + case HOGPD_IDX_BOOT_MOUSE_IN_REPORT_VAL: + { + report_type = HOGPD_BOOT_MOUSE_INPUT_REPORT; + finished = false; + }break; + case HOGPD_IDX_REPORT_VAL: + { + report_type = HOGPD_REPORT; + finished = false; + }break; + case HOGPD_IDX_REPORT_MAP_VAL: + { + report_type = HOGPD_REPORT_MAP; + finished = false; + }break; + + // ------------ READ active protocol mode + case HOGPD_IDX_PROTO_MODE_VAL: + { + value = hogpd_env->svcs[hid_idx].proto_mode; + length = sizeof(uint8_t); + }break; + + // ------------ READ Notification configuration + case HOGPD_IDX_BOOT_KB_IN_REPORT_NTF_CFG: + { + value = ((hogpd_env->svcs[hid_idx].ntf_cfg[conidx] & HOGPD_CFG_KEYBOARD) != 0) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND; + + length = sizeof(uint16_t); + }break; + case HOGPD_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG: + { + value = ((hogpd_env->svcs[hid_idx].ntf_cfg[conidx] & HOGPD_CFG_MOUSE) != 0) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND; + length = sizeof(uint16_t); + }break; + case HOGPD_IDX_REPORT_NTF_CFG: + { + value = ((hogpd_env->svcs[hid_idx].ntf_cfg[conidx] & (HOGPD_CFG_REPORT_NTF_EN << report_idx)) != 0) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND; + length = sizeof(uint16_t); + }break; + + default: + { + status = PRF_APP_ERROR; + } break; + } + } + + // check if peer operation is over + if(finished) + { + //Send write response + struct gattc_read_cfm * cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, length); + cfm->handle = param->handle; + cfm->status = status; + cfm->length = length; + memcpy(cfm->value, &value, length); + ke_msg_send(cfm); + } + else + { + // send report indication + struct hogpd_report_req_ind *report_ind = KE_MSG_ALLOC(HOGPD_REPORT_REQ_IND, + prf_dst_task_get(&(hogpd_env->prf_env), conidx), dest_id, + hogpd_report_req_ind); + + report_ind->conidx = conidx; + report_ind->operation = HOGPD_OP_REPORT_READ; + report_ind->report.length = 0; + report_ind->report.hid_idx = hid_idx; + report_ind->report.type = report_type; + report_ind->report.idx = report_idx; + + ke_msg_send(report_ind); + + hogpd_env->op.conidx = conidx; + hogpd_env->op.operation = HOGPD_OP_REPORT_READ; + hogpd_env->op.handle = param->handle; + + // go into operation busy state + ke_state_set(dest_id, state | HOGPD_OP_BUSY); + } + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles @ref GATT_NOTIFY_CMP_EVT message meaning that Report notification + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + if(param->operation == GATTC_NOTIFY) + { + uint8_t conidx = KE_IDX_GET(src_id); + struct hogpd_env_tag* hogpd_env = PRF_ENV_GET(HOGPD, hogpd); + + // send report update response + struct hogpd_report_upd_rsp *rsp = KE_MSG_ALLOC(HOGPD_REPORT_UPD_RSP, + prf_dst_task_get(&(hogpd_env->prf_env), conidx), + dest_id, hogpd_report_upd_rsp); + rsp->conidx = conidx; + rsp->status = param->status; + ke_msg_send(rsp); + + // go back in to idle mode + ke_state_set(dest_id, ke_state_get(dest_id) & ~HOGPD_REQ_BUSY); + } // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(hogpd) +{ + { HOGPD_ENABLE_REQ, (ke_msg_func_t) hogpd_enable_req_handler }, + { HOGPD_REPORT_UPD_REQ, (ke_msg_func_t) hogpd_report_upd_req_handler }, + { HOGPD_REPORT_CFM, (ke_msg_func_t) hogpd_report_cfm_handler }, + { HOGPD_PROTO_MODE_CFM, (ke_msg_func_t) hogpd_proto_mode_cfm_handler }, + + { GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler }, + { GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler }, + { GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler }, + { GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler }, +}; + +void hogpd_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct hogpd_env_tag *p_hogpd_env = PRF_ENV_GET(HOGPD, hogpd); + + p_task_desc->msg_handler_tab = hogpd_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(hogpd_msg_handler_tab); + p_task_desc->state = p_hogpd_env->state; + p_task_desc->idx_max = HOGPD_IDX_MAX; +} + +#endif /* #if (BLE_HID_DEVICE) */ + +/// @} HOGPDTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/api/hogprh_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/api/hogprh_task.h new file mode 100644 index 0000000..c8cfb32 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/api/hogprh_task.h @@ -0,0 +1,345 @@ +/** + **************************************************************************************** + * + * @file hogprh_task.h + * + * @brief Header file - HID Over GATT Profile Report Host Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _HOGPRH_TASK_H_ +#define _HOGPRH_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup HOGPRHTASK HID Over GATT Profile Report Host Task + * @ingroup HOGPRH + * @brief HID Over GATT Profile Report Host Task + * + * The HOGPRHTASK is responsible for handling the messages coming in and out of the + * @ref HOGPRH monitor block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" +#include "hogp_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +/// Maximal number of hids instances that can be handled +#define HOGPRH_NB_HIDS_INST_MAX (2) +/// Maximal number of Report Char. that can be added in the DB for one HIDS - Up to 11 +#define HOGPRH_NB_REPORT_INST_MAX (5) + +/// Maximal length of Report Map Char. Value +#define HOGPRH_REPORT_MAP_MAX_LEN (512) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +enum hogprh_msg_id +{ + /// Start the HID Over GATT profile - at connection + HOGPRH_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_HOGPRH), + ///Confirm that cfg connection has finished with discovery results, or that normal cnx started + HOGPRH_ENABLE_RSP, + + /// Read Characteristic Value Request + HOGPRH_READ_INFO_REQ, + /// Read Characteristic Value Request + HOGPRH_READ_INFO_RSP, + + /// Write/Configure peer device attribute Request + HOGPRH_WRITE_REQ, + /// Write/Configure peer device attribute Response + HOGPRH_WRITE_RSP, + + /// Report value send to APP (after Notification) + HOGPRH_REPORT_IND, +}; + + +/// Characteristics +enum hogprh_chars +{ + /// Report Map + HOGPRH_CHAR_REPORT_MAP, + /// HID Information + HOGPRH_CHAR_HID_INFO, + /// HID Control Point + HOGPRH_CHAR_HID_CTNL_PT, + /// Protocol Mode + HOGPRH_CHAR_PROTOCOL_MODE, + /// Report + HOGPRH_CHAR_REPORT, + + HOGPRH_CHAR_MAX = HOGPRH_CHAR_REPORT + HOGPRH_NB_REPORT_INST_MAX, +}; + + +/// Characteristic descriptors +enum hogprh_descs +{ + /// Report Map Char. External Report Reference Descriptor + HOGPRH_DESC_REPORT_MAP_EXT_REP_REF, + /// Report Char. Report Reference + HOGPRH_DESC_REPORT_REF, + /// Report Client Config + HOGPRH_DESC_REPORT_CFG = HOGPRH_DESC_REPORT_REF + HOGPRH_NB_REPORT_INST_MAX, + + HOGPRH_DESC_MAX = HOGPRH_DESC_REPORT_CFG + HOGPRH_NB_REPORT_INST_MAX, +}; + +/// Peer HID service info that can be read/write +enum hogprh_info +{ + /// Protocol Mode + HOGPRH_PROTO_MODE, + /// Report Map + HOGPRH_REPORT_MAP, + /// Report Map Char. External Report Reference Descriptor + HOGPRH_REPORT_MAP_EXT_REP_REF, + + /// HID Information + HOGPRH_HID_INFO, + /// HID Control Point + HOGPRH_HID_CTNL_PT, + /// Report + HOGPRH_REPORT, + /// Report Char. Report Reference + HOGPRH_REPORT_REF, + /// Report Notification config + HOGPRH_REPORT_NTF_CFG, + + HOGPRH_INFO_MAX, +}; + +/* + * APIs Structure + **************************************************************************************** + */ + + +///Structure containing the characteristics handles, value handles and descriptors +struct hogprh_content +{ + /// Service info + struct prf_svc svc; + + /// Included service info + struct prf_incl_svc incl_svc; + + /// Characteristic info: + struct prf_char_inf chars[HOGPRH_CHAR_MAX]; + + /// Descriptor handles: + struct prf_char_desc_inf descs[HOGPRH_DESC_MAX]; + + /// Number of Report Char. that have been found + uint8_t report_nb; +}; + + +/// Parameters of the @ref HOGPRH_ENABLE_REQ message +struct hogprh_enable_req +{ + /// Connection type + uint8_t con_type; + + /// Number of HIDS instances + uint8_t hids_nb; + /// Existing handle values hids + struct hogprh_content hids[HOGPRH_NB_HIDS_INST_MAX]; +}; + +/// Parameters of the @ref HOGPRH_ENABLE_RSP message +struct hogprh_enable_rsp +{ + ///status + uint8_t status; + + /// Number of HIDS instances + uint8_t hids_nb; + /// Existing handle values hids + struct hogprh_content hids[HOGPRH_NB_HIDS_INST_MAX]; +}; + + +/// HID report info +struct hogprh_report +{ + /// Report Length + uint8_t length; + /// Report value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// HID report Reference +struct hogprh_report_ref +{ + /// Report ID + uint8_t id; + /// Report Type + uint8_t type; +}; + +/// HID report MAP info +struct hogprh_report_map +{ + /// Report MAP Length + uint16_t length; + /// Report MAP value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// HID report MAP reference +struct hogprh_report_map_ref +{ + /// Reference UUID length + uint8_t uuid_len; + /// Reference UUID Value + uint8_t uuid[__ARRAY_EMPTY]; +}; + +/// Information data +union hogprh_data +{ + /// Protocol Mode + /// - info = HOGPRH_PROTO_MODE + uint8_t proto_mode; + + /// HID Information value + /// - info = HOGPRH_HID_INFO + struct hids_hid_info hid_info; + + /// HID Control Point value to write + /// - info = HOGPRH_HID_CTNL_PT + uint8_t hid_ctnl_pt; + + /// Report information + /// - info = HOGPRH_REPORT + struct hogprh_report report; + + ///Notification Configuration Value + /// - info = HOGPRH_REPORT_NTF_CFG + uint16_t report_cfg; + + /// HID report Reference + /// - info = HOGPRH_REPORT_REF + struct hogprh_report_ref report_ref; + + /// HID report MAP info + /// - info = HOGPRH_REPORT_MAP + struct hogprh_report_map report_map; + + /// HID report MAP reference + /// - info = HOGPRH_REPORT_MAP_EXT_REP_REF + struct hogprh_report_map_ref report_map_ref; +}; + + + +///Parameters of the @ref HOGPRH_READ_INFO_REQ message +struct hogprh_read_info_req +{ + ///Characteristic info @see enum hogprh_info + uint8_t info; + /// HID Service Instance - From 0 to HOGPRH_NB_HIDS_INST_MAX-1 + uint8_t hid_idx; + /// HID Report Index: only relevant for: + /// - info = HOGPRH_REPORT + /// - info = HOGPRH_REPORT_REF + /// - info = HOGPRH_REPORT_NTF_CFG + uint8_t report_idx; +}; + +///Parameters of the @ref HOGPRH_READ_INFO_RSP message +struct hogprh_read_info_rsp +{ + /// status of the request + uint8_t status; + ///Characteristic info @see enum hogprh_info + uint8_t info; + /// HID Service Instance - From 0 to HOGPRH_NB_HIDS_INST_MAX-1 + uint8_t hid_idx; + /// HID Report Index: only relevant for: + /// - info = HOGPRH_REPORT + /// - info = HOGPRH_REPORT_REF + /// - info = HOGPRH_REPORT_NTF_CFG + uint8_t report_idx; + /// Information data + union hogprh_data data; +}; + + +///Parameters of the @ref HOGPRH_WRITE_REQ message +struct hogprh_write_req +{ + ///Characteristic info @see enum hogprh_info + uint8_t info; + /// HID Service Instance - From 0 to HOGPRH_NB_HIDS_INST_MAX-1 + uint8_t hid_idx; + /// HID Report Index: only relevant for: + /// - info = HOGPRH_REPORT + /// - info = HOGPRH_REPORT_NTF_CFG + uint8_t report_idx; + /// Write type ( Write without Response True or Write Request) + /// - only valid for HOGPRH_REPORT + bool wr_cmd; + /// Information data + union hogprh_data data; +}; + + +///Parameters of the @ref HOGPRH_WRITE_RSP message +struct hogprh_write_rsp +{ + /// status of the request + uint8_t status; + ///Characteristic info @see enum hogprh_info + uint8_t info; + /// HID Service Instance - From 0 to HOGPRH_NB_HIDS_INST_MAX-1 + uint8_t hid_idx; + /// HID Report Index: only relevant for: + /// - info = HOGPRH_REPORT + /// - info = HOGPRH_REPORT_REF + /// - info = HOGPRH_REPORT_NTF_CFG + uint8_t report_idx; +}; + + +///Parameters of the @ref HOGPRH_BOOT_REPORT_IND message +struct hogprh_report_ind +{ + /// HIDS Instance + uint8_t hid_idx; + /// HID Report Index + uint8_t report_idx; + /// Report data + struct hogprh_report report; +}; + +/// @} HOGPRHTASK + +#endif /* _HOGPRH_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/sourcelist.txt new file mode 100644 index 0000000..4cc84e2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + hogprh.c + hogprh_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/src/hogprh.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/src/hogprh.c new file mode 100644 index 0000000..8500776 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/src/hogprh.c @@ -0,0 +1,220 @@ +/** + **************************************************************************************** + * + * @file hogprh.c + * + * @brief HID Over GATT Profile - Report Host Role Implementation + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup HOGPRH + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_HID_REPORT_HOST) + +#include "hogprh.h" +#include "hogprh_task.h" +#include "co_math.h" +#include "gap.h" + +#include "ke_mem.h" + +/** + **************************************************************************************** + * @brief Initialization of the HOGPRH module. + * This function performs all the initializations of the Profile module. + * - Creation of datahide (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] env Collector or Service allocated environment data. + * @param[in|out] start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t hogprh_init(struct prf_task_env* env, uint16_t* start_hdl, uint16_t app_task, uint8_t sec_lvl, void* params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct hogprh_env_tag* hogprh_env = + (struct hogprh_env_tag* ) ke_malloc(sizeof(struct hogprh_env_tag), KE_MEM_ATT_DB); + + // allocate HOGPRH required environment variable + env->env = (prf_env_t*) hogprh_env; + + hogprh_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + hogprh_env->prf_env.prf_task = env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + env->id = TASK_ID_HOGPRH; + env->desc.idx_max = HOGPRH_IDX_MAX; + env->desc.state = hogprh_env->state; +// env->desc.default_handler = &hogprh_default_handler; + hogprh_task_init(&(env->desc)); + + for(idx = 0; idx < HOGPRH_IDX_MAX ; idx++) + { + hogprh_env->env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(env->task, idx), HOGPRH_FREE); + } + + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Destruction of the HOGPRH module - due to a reset for instance. + * This function clean-up allocated memory (attribute datahide is destroyed by another + * procedure) + * + * @param[in|out] env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void hogprh_destroy(struct prf_task_env* env) +{ + uint8_t idx; + struct hogprh_env_tag* hogprh_env = (struct hogprh_env_tag*) env->env; + + // cleanup environment variable for each task instances + for(idx = 0; idx < HOGPRH_IDX_MAX ; idx++) + { + if(hogprh_env->env[idx] != NULL) + { + if(hogprh_env->env[idx]->operation != NULL) + { + ke_free(hogprh_env->env[idx]->operation); + } + ke_free(hogprh_env->env[idx]); + } + } + + // free profile environment variables + env->env = NULL; + ke_free(hogprh_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void hogprh_create(struct prf_task_env* env, uint8_t conidx) +{ + /* Put HID Client in Idle state */ + ke_state_set(KE_BUILD_ID(env->task, conidx), HOGPRH_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void hogprh_cleanup(struct prf_task_env* env, uint8_t conidx, uint8_t reason) +{ + struct hogprh_env_tag* hogprh_env = (struct hogprh_env_tag*) env->env; + + // clean-up environment variable allocated for task instance + if(hogprh_env->env[conidx] != NULL) + { + if(hogprh_env->env[conidx]->operation != NULL) + { + ke_free(hogprh_env->env[conidx]->operation); + } + ke_free(hogprh_env->env[conidx]); + hogprh_env->env[conidx] = NULL; + } + + /* Put HID Client in Free state */ + ke_state_set(KE_BUILD_ID(env->task, conidx), HOGPRH_FREE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// HOGPRH Task interface required by profile manager +const struct prf_task_cbs hogprh_itf = +{ + hogprh_init, + hogprh_destroy, + hogprh_create, + hogprh_cleanup, +}; + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* hogprh_prf_itf_get(void) +{ + return &hogprh_itf; +} + +void hogprh_enable_rsp_send(struct hogprh_env_tag *hogprh_env, uint8_t conidx, uint8_t status) +{ + // Counter + uint8_t svc_inst; + + // Send APP the details of the discovered attributes on HOGPRH + struct hogprh_enable_rsp * rsp = KE_MSG_ALLOC(HOGPRH_ENABLE_RSP, + prf_dst_task_get(&(hogprh_env->prf_env) ,conidx), + prf_src_task_get(&(hogprh_env->prf_env) ,conidx), + hogprh_enable_rsp); + rsp->status = status; + rsp->hids_nb = 0; + if (status == GAP_ERR_NO_ERROR) + { + rsp->hids_nb = hogprh_env->env[conidx]->hids_nb; + + for (svc_inst = 0; svc_inst < co_min(hogprh_env->env[conidx]->hids_nb, HOGPRH_NB_HIDS_INST_MAX) ; svc_inst++) + { + rsp->hids[svc_inst] = hogprh_env->env[conidx]->hids[svc_inst]; + + // Register HOGPRH task in gatt for indication/notifications + prf_register_atthdl2gatt(&(hogprh_env->prf_env), conidx, &hogprh_env->env[conidx]->hids[svc_inst].svc); + } + } + + ke_msg_send(rsp); +} + +#endif /* (BLE_HID_REPORT_HOST) */ + +/// @} HOGPRH diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/src/hogprh.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/src/hogprh.h new file mode 100644 index 0000000..9e0d291 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/src/hogprh.h @@ -0,0 +1,138 @@ +/** + **************************************************************************************** + * + * @file hogprh.h + * + * @brief Header file - HID Over GATT Profile - Report Host Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _HOGPRH_H_ +#define _HOGPRH_H_ + + +/** + **************************************************************************************** + * @addtogroup HOGPRH HID Over GATT Profile Report Host + * @ingroup HOGP + * @brief HID Over GATT Profile Report Host + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_HID_REPORT_HOST) + +#include "hogp_common.h" +#include "ke_task.h" +#include "hogprh_task.h" +#include "prf_types.h" +#include "prf_utils.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + +///Maximum number of HID Over GATT Report Host task instances +#define HOGPRH_IDX_MAX 1//(BLE_CONNECTION_MAX) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the HOGPRH task +enum hogprh_state +{ + /// Disconnected state + HOGPRH_FREE, + /// IDLE state + HOGPRH_IDLE, + /// Busy State + HOGPRH_BUSY, + /// Number of defined states. + HOGPRH_STATE_MAX +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/// Environment variable for each Connections +struct hogprh_cnx_env +{ + /// on-going operation + struct ke_msg * operation; + ///HIDS characteristics + struct hogprh_content hids[HOGPRH_NB_HIDS_INST_MAX]; + ///Number of HIDS instances found + uint8_t hids_nb; +}; + +/// HID Over Gatt Profile Boot Host environment variable +struct hogprh_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct hogprh_cnx_env* env[HOGPRH_IDX_MAX]; + /// State of different task instances + ke_state_t state[HOGPRH_IDX_MAX]; +}; + + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * GLOBAL FUNCTIONS DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve HID report host profile interface + * + * @return HID report host profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* hogprh_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send HID ATT DB discovery results to HOGPRH host. + **************************************************************************************** + */ +void hogprh_enable_rsp_send(struct hogprh_env_tag *hogprh_env, uint8_t conidx, uint8_t status); + + +void hogprh_task_init(struct ke_task_desc *p_task_desc); +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +//extern const struct ke_state_handler hogprh_default_handler; + + + +#endif /* (BLE_HID_REPORT_HOST) */ + +/// @} HOGPRH + +#endif /* _HOGPRH_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/src/hogprh_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/src/hogprh_task.c new file mode 100644 index 0000000..02c1434 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogprh/src/hogprh_task.c @@ -0,0 +1,841 @@ +/** + **************************************************************************************** + * + * @file hogprh_task.c + * + * @brief HID Over GATT Profile Report Host Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HOGPRHTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_HID_REPORT_HOST) + +#include "gap.h" +#include "attm.h" +#include "hogprh_task.h" +#include "hogprh.h" +#include "gattc_task.h" +#include "gattc.h" +#include "hogp_common.h" + +#include "ke_mem.h" +#include "co_utils.h" +#include "co_math.h" + +/* + * LOCAL VARIABLES DEFINITION + **************************************************************************************** + */ + +/// State machine used to retrieve HID Service characteristics information +const struct prf_char_def hogprh_hids_char[HOGPRH_CHAR_REPORT + 1] = +{ + /// Report Map + [HOGPRH_CHAR_REPORT_MAP] = {ATT_CHAR_REPORT_MAP, ATT_MANDATORY, ATT_CHAR_PROP_RD}, + /// HID Information + [HOGPRH_CHAR_HID_INFO] = {ATT_CHAR_HID_INFO, ATT_MANDATORY, ATT_CHAR_PROP_RD}, + /// HID Control Point + [HOGPRH_CHAR_HID_CTNL_PT] = {ATT_CHAR_HID_CTNL_PT, ATT_MANDATORY, ATT_CHAR_PROP_WR_NO_RESP}, + /// Protocol Mode + [HOGPRH_CHAR_PROTOCOL_MODE] = {ATT_CHAR_PROTOCOL_MODE, ATT_OPTIONAL, (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR_NO_RESP)}, + /// Report + [HOGPRH_CHAR_REPORT] = {ATT_CHAR_REPORT, ATT_MANDATORY, ATT_CHAR_PROP_RD}, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HOGPRH_ENABLE_REQ message. + * The handler enables the HID Over GATT Profile Boot Host Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int hogprh_enable_req_handler(ke_msg_id_t const msgid, + struct hogprh_enable_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + int msg_status = KE_MSG_CONSUMED; + + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Battery service Client Role Task Environment + struct hogprh_env_tag *hogprh_env = PRF_ENV_GET(HOGPRH, hogprh); + + ASSERT_INFO(hogprh_env != NULL, dest_id, src_id); + if((state == HOGPRH_IDLE) && (hogprh_env->env[conidx] == NULL)) + { + // allocate environment variable for task instance + hogprh_env->env[conidx] = (struct hogprh_cnx_env*) ke_malloc(sizeof(struct hogprh_cnx_env),KE_MEM_ATT_DB); + memset(hogprh_env->env[conidx], 0, sizeof(struct hogprh_cnx_env)); + + //Config connection, start discovering + if(param->con_type == PRF_CON_DISCOVERY) + { + //start discovering HID on peer + prf_disc_svc_send(&(hogprh_env->prf_env), conidx, ATT_SVC_HID); + + // Go to DISCOVERING state + ke_state_set(dest_id, HOGPRH_BUSY); + hogprh_env->env[conidx]->operation = ke_param2msg(param); + msg_status = KE_MSG_NO_FREE; + } + //normal connection, get saved att details + else + { + hogprh_env->env[conidx]->hids_nb = param->hids_nb; + memcpy(&(hogprh_env->env[conidx]->hids[0]), &(param->hids[0]), sizeof(struct hogprh_content) * HOGPRH_NB_HIDS_INST_MAX); + + //send APP confirmation that can start normal connection to TH + hogprh_enable_rsp_send(hogprh_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if(state != HOGPRH_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if(status != GAP_ERR_NO_ERROR) + { + hogprh_enable_rsp_send(hogprh_env, conidx, status); + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + + if(state == HOGPRH_BUSY) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct hogprh_env_tag *hogprh_env = PRF_ENV_GET(HOGPRH, hogprh); + + ASSERT_INFO(hogprh_env != NULL, dest_id, src_id); + ASSERT_INFO(hogprh_env->env[conidx] != NULL, dest_id, src_id); + + if(hogprh_env->env[conidx]->hids_nb < HOGPRH_NB_HIDS_INST_MAX) + { + uint8_t i; + struct prf_char_def hids_char[HOGPRH_CHAR_MAX]; + struct prf_char_desc_def hids_char_desc[HOGPRH_DESC_MAX]; + uint8_t hid_idx = hogprh_env->env[conidx]->hids_nb; + uint8_t fnd_att; + + + + // 1. Create characteristic reference + memcpy(hids_char, hogprh_hids_char, sizeof(struct prf_char_def) * HOGPRH_CHAR_REPORT); + for(i = HOGPRH_CHAR_REPORT ; i < HOGPRH_CHAR_MAX ; i++) + { + hids_char[i] = hogprh_hids_char[HOGPRH_CHAR_REPORT]; + } + + // 2. create descriptor reference + // Report Map Char. External Report Reference Descriptor + hids_char_desc[HOGPRH_DESC_REPORT_MAP_EXT_REP_REF].char_code = HOGPRH_CHAR_REPORT_MAP; + hids_char_desc[HOGPRH_DESC_REPORT_MAP_EXT_REP_REF].req_flag = ATT_OPTIONAL; + hids_char_desc[HOGPRH_DESC_REPORT_MAP_EXT_REP_REF].uuid = ATT_DESC_EXT_REPORT_REF; + + for(i = 0 ; i < HOGPRH_NB_REPORT_INST_MAX ; i++) + { + // Report Char. Report Reference + hids_char_desc[HOGPRH_DESC_REPORT_REF + i].char_code = HOGPRH_CHAR_REPORT + i; + hids_char_desc[HOGPRH_DESC_REPORT_REF + i].req_flag = ATT_OPTIONAL; + hids_char_desc[HOGPRH_DESC_REPORT_REF + i].uuid = ATT_DESC_REPORT_REF; + // Report Client Config + hids_char_desc[HOGPRH_DESC_REPORT_CFG + i].char_code = HOGPRH_CHAR_REPORT + i; + hids_char_desc[HOGPRH_DESC_REPORT_CFG + i].req_flag = ATT_OPTIONAL; + hids_char_desc[HOGPRH_DESC_REPORT_CFG + i].uuid = ATT_DESC_CLIENT_CHAR_CFG; + } + + // 3. Retrieve HID characteristics + prf_extract_svc_info(ind, HOGPRH_CHAR_MAX, &hids_char[0], + &(hogprh_env->env[conidx]->hids[hid_idx].chars[0]), + HOGPRH_DESC_MAX, &hids_char_desc[0], + &(hogprh_env->env[conidx]->hids[hid_idx].descs[0])); + + // 4. Store service range + hogprh_env->env[conidx]->hids[hid_idx].svc.shdl = ind->start_hdl; + hogprh_env->env[conidx]->hids[hid_idx].svc.ehdl = ind->end_hdl; + + // 5. Search for an included service + for (fnd_att=0; fnd_att< (ind->end_hdl - ind->start_hdl); fnd_att++) + { + if(ind->info[fnd_att].att_type == GATTC_SDP_INC_SVC) + { + hogprh_env->env[conidx]->hids[hid_idx].incl_svc.handle = ind->start_hdl + fnd_att + 1; + hogprh_env->env[conidx]->hids[hid_idx].incl_svc.start_hdl = ind->info[fnd_att].inc_svc.start_hdl; + hogprh_env->env[conidx]->hids[hid_idx].incl_svc.end_hdl = ind->info[fnd_att].inc_svc.end_hdl; + hogprh_env->env[conidx]->hids[hid_idx].incl_svc.uuid_len = ind->info[fnd_att].inc_svc.uuid_len; + memcpy(hogprh_env->env[conidx]->hids[hid_idx].incl_svc.uuid, ind->info[fnd_att].inc_svc.uuid, + ind->info[fnd_att].inc_svc.uuid_len); + } + if((ind->info[fnd_att].att_type == GATTC_SDP_ATT_VAL) + && (attm_uuid16_comp((uint8_t*)ind->info[fnd_att].att.uuid, ind->info[fnd_att].att.uuid_len, ATT_CHAR_REPORT))) + { + hogprh_env->env[conidx]->hids[hid_idx].report_nb++; + } + } + + hogprh_env->env[conidx]->hids_nb++; + } + } + + return (KE_MSG_CONSUMED); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HOGPRH_READ_INFO_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int hogprh_read_info_req_handler(ke_msg_id_t const msgid, struct hogprh_read_info_req const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if(state == HOGPRH_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct hogprh_env_tag *hogprh_env = PRF_ENV_GET(HOGPRH, hogprh); + ASSERT_INFO(hogprh_env != NULL, dest_id, src_id); + // environment variable not ready + if(hogprh_env->env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + // check parameter range + else if((param->hid_idx > hogprh_env->env[conidx]->hids_nb) || (param->report_idx >= HOGPRH_NB_REPORT_INST_MAX)) + { + status = PRF_ERR_INVALID_PARAM; + } + else + { + uint16_t handle = ATT_INVALID_HANDLE; + status = PRF_ERR_INEXISTENT_HDL; + + // check requested info + switch(param->info) + { + /// Protocol Mode + case HOGPRH_PROTO_MODE: + { + handle = hogprh_env->env[conidx]->hids[param->hid_idx].chars[HOGPRH_CHAR_PROTOCOL_MODE].val_hdl; + }break; + /// Report Map + case HOGPRH_REPORT_MAP: + { + handle = hogprh_env->env[conidx]->hids[param->hid_idx].chars[HOGPRH_CHAR_REPORT_MAP].val_hdl; + }break; + /// Report Map Char. External Report Reference Descriptor + case HOGPRH_REPORT_MAP_EXT_REP_REF: + { + handle = hogprh_env->env[conidx]->hids[param->hid_idx].descs[HOGPRH_DESC_REPORT_MAP_EXT_REP_REF].desc_hdl; + }break; + /// HID Information + case HOGPRH_HID_INFO: + { + handle = hogprh_env->env[conidx]->hids[param->hid_idx].chars[HOGPRH_CHAR_HID_INFO].val_hdl; + }break; + /// Report + case HOGPRH_REPORT: + { + handle = hogprh_env->env[conidx]->hids[param->hid_idx].chars[HOGPRH_CHAR_REPORT + param->report_idx].val_hdl; + }break; + /// Report Char. Report Reference + case HOGPRH_REPORT_REF: + { + handle = hogprh_env->env[conidx]->hids[param->hid_idx].descs[HOGPRH_DESC_REPORT_REF + param->report_idx].desc_hdl; + }break; + /// Report Notification config + case HOGPRH_REPORT_NTF_CFG: + { + handle = hogprh_env->env[conidx]->hids[param->hid_idx].descs[HOGPRH_DESC_REPORT_CFG + param->report_idx].desc_hdl; + }break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + }break; + } + + if(handle != ATT_INVALID_HANDLE) + { + status = GAP_ERR_NO_ERROR; + // read information + prf_read_char_send(&(hogprh_env->prf_env), conidx, + hogprh_env->env[conidx]->hids[param->hid_idx].svc.shdl, + hogprh_env->env[conidx]->hids[param->hid_idx].svc.ehdl, handle); + + // store context of request and go into busy state + hogprh_env->env[conidx]->operation = ke_param2msg(param); + ke_state_set(dest_id, HOGPRH_BUSY); + msg_status = KE_MSG_NO_FREE; + } + } + } + // process message later + else if (state == HOGPRH_BUSY) + { + status = GAP_ERR_NO_ERROR; + msg_status = KE_MSG_SAVED; + } + + + // request cannot be performed + if(status != GAP_ERR_NO_ERROR) + { + struct hogprh_read_info_rsp * rsp = KE_MSG_ALLOC(HOGPRH_READ_INFO_RSP, + src_id, dest_id, hogprh_read_info_rsp); + // set error status + rsp->status = status; + rsp->info = param->info; + rsp->hid_idx = param->hid_idx; + + ke_msg_send(rsp); + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HOGPRH_WRITE_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int hogprh_write_req_handler(ke_msg_id_t const msgid, struct hogprh_write_req *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if(state == HOGPRH_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct hogprh_env_tag *hogprh_env = PRF_ENV_GET(HOGPRH, hogprh); + ASSERT_INFO(hogprh_env != NULL, dest_id, src_id); + // environment variable not ready + if(hogprh_env->env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + // check parameter range + else if((param->hid_idx > hogprh_env->env[conidx]->hids_nb) || (param->report_idx >= HOGPRH_NB_REPORT_INST_MAX) + || (param->info > HOGPRH_INFO_MAX) + || ((param->info == HOGPRH_REPORT_NTF_CFG) && (param->data.report_cfg > PRF_CLI_START_NTF))) + { + status = PRF_ERR_INVALID_PARAM; + } + else + { + uint16_t handle = ATT_INVALID_HANDLE; + status = PRF_ERR_INEXISTENT_HDL; + + // check requested info + switch(param->info) + { + // Protocol Mode + case HOGPRH_PROTO_MODE: + { + handle = hogprh_env->env[conidx]->hids[param->hid_idx].chars[HOGPRH_CHAR_PROTOCOL_MODE].val_hdl; + prf_gatt_write(&hogprh_env->prf_env, conidx, handle, (uint8_t*)¶m->data.proto_mode, 1, GATTC_WRITE_NO_RESPONSE); + }break; + // HID Control Point + case HOGPRH_HID_CTNL_PT: + { + handle = hogprh_env->env[conidx]->hids[param->hid_idx].chars[HOGPRH_CHAR_HID_CTNL_PT].val_hdl; + prf_gatt_write(&hogprh_env->prf_env, conidx, handle, (uint8_t*)¶m->data.hid_ctnl_pt, 1, GATTC_WRITE_NO_RESPONSE); + }break; + // Report Char. Report Reference + case HOGPRH_REPORT: + { + // Get MTU to select between GATT_WRITE_LONG_CHAR and GATT_WRITE_CHAR + if (param->data.report.length > (gattc_get_mtu(conidx) - 3)) + { + param->wr_cmd = false; + } + + handle = hogprh_env->env[conidx]->hids[param->hid_idx].chars[HOGPRH_CHAR_REPORT + param->report_idx].val_hdl; + prf_gatt_write(&hogprh_env->prf_env, conidx, handle, (uint8_t*)param->data.report.value , + param->data.report.length, (param->wr_cmd ? GATTC_WRITE_NO_RESPONSE : GATTC_WRITE)); + }break; + // Report Notification config + case HOGPRH_REPORT_NTF_CFG: + { + handle = hogprh_env->env[conidx]->hids[param->hid_idx].descs[HOGPRH_DESC_REPORT_CFG + param->report_idx].desc_hdl; + prf_gatt_write_ntf_ind(&hogprh_env->prf_env, conidx, handle, param->data.report_cfg); + }break; + default: + { + status = PRF_ERR_INVALID_PARAM; + }break; + } + + if(handle != ATT_INVALID_HANDLE) + { + status = GAP_ERR_NO_ERROR; + + // store context of request and go into busy state + hogprh_env->env[conidx]->operation = ke_param2msg(param); + ke_state_set(dest_id, HOGPRH_BUSY); + msg_status = KE_MSG_NO_FREE; + } + } + } + // process message later + else if (state == HOGPRH_BUSY) + { + status = GAP_ERR_NO_ERROR; + msg_status = KE_MSG_SAVED; + } + + + // request cannot be performed + if(status != GAP_ERR_NO_ERROR) + { + struct hogprh_write_rsp * rsp = KE_MSG_ALLOC(HOGPRH_WRITE_RSP, + src_id, dest_id, hogprh_write_rsp); + // set error status + rsp->status = status; + rsp->info = param->info; + rsp->hid_idx = param->hid_idx; + + ke_msg_send(rsp); + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct hogprh_env_tag *hogprh_env = PRF_ENV_GET(HOGPRH, hogprh); + + // sanity check + if((state == HOGPRH_BUSY) && (hogprh_env->env[conidx] != NULL) + && (hogprh_env->env[conidx]->operation != NULL)) + { + switch(hogprh_env->env[conidx]->operation->id) + { + case HOGPRH_ENABLE_REQ: + { + uint8_t status = param->status; + + if (param->status == ATT_ERR_NO_ERROR) + { + // check characteristic validity + if(hogprh_env->env[conidx]->hids_nb > 0) + { + uint8_t report_idx; + uint8_t hid_idx; + for (hid_idx = 0 ; (hid_idx < co_min(hogprh_env->env[conidx]->hids_nb, HOGPRH_NB_HIDS_INST_MAX)) + && (status == GAP_ERR_NO_ERROR) ; hid_idx++) + { + + struct prf_char_def hids_char[HOGPRH_CHAR_MAX]; + struct prf_char_desc_def hids_char_desc[HOGPRH_DESC_MAX]; + + // 1. Create characteristic reference + memcpy(hids_char, hogprh_hids_char, sizeof(struct prf_char_def) * HOGPRH_CHAR_REPORT); + for(report_idx = HOGPRH_CHAR_REPORT ; report_idx < HOGPRH_CHAR_MAX ; report_idx++) + { + hids_char[report_idx] = hogprh_hids_char[HOGPRH_CHAR_REPORT]; + hids_char[report_idx].req_flag = ATT_OPTIONAL; + } + + // 2. create descriptor reference + // Report Map Char. External Report Reference Descriptor + hids_char_desc[HOGPRH_DESC_REPORT_MAP_EXT_REP_REF].char_code = HOGPRH_CHAR_REPORT_MAP; + hids_char_desc[HOGPRH_DESC_REPORT_MAP_EXT_REP_REF].req_flag = ATT_OPTIONAL; + hids_char_desc[HOGPRH_DESC_REPORT_MAP_EXT_REP_REF].uuid = ATT_DESC_EXT_REPORT_REF; + + for(report_idx = 0 ; report_idx < HOGPRH_NB_REPORT_INST_MAX ; report_idx++) + { + // Report Char. Report Reference + hids_char_desc[HOGPRH_DESC_REPORT_REF + report_idx].char_code = HOGPRH_CHAR_REPORT + report_idx; + hids_char_desc[HOGPRH_DESC_REPORT_REF + report_idx].req_flag = ATT_OPTIONAL; + hids_char_desc[HOGPRH_DESC_REPORT_REF + report_idx].uuid = ATT_DESC_REPORT_REF; + // Report Client Config + hids_char_desc[HOGPRH_DESC_REPORT_CFG + report_idx].char_code = HOGPRH_CHAR_REPORT + report_idx; + hids_char_desc[HOGPRH_DESC_REPORT_CFG + report_idx].req_flag = ATT_OPTIONAL; + hids_char_desc[HOGPRH_DESC_REPORT_CFG + report_idx].uuid = ATT_DESC_CLIENT_CHAR_CFG; + } + + // 3. Check Characteristic validity + status = prf_check_svc_char_validity(HOGPRH_CHAR_MAX, hogprh_env->env[conidx]->hids[hid_idx].chars, + hids_char); + + // 4. check descriptor validity + if(status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(HOGPRH_DESC_MAX, + hogprh_env->env[conidx]->hids[hid_idx].descs, hids_char_desc, + hogprh_env->env[conidx]->hids[hid_idx].chars); + } + } + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + } + hogprh_enable_rsp_send(hogprh_env, conidx, status); + }break; + case HOGPRH_READ_INFO_REQ: + { + // do not send anything if it's a local request + if(hogprh_env->env[conidx]->operation->src_id != dest_id) + { + struct hogprh_read_info_req* req = (struct hogprh_read_info_req*) ke_msg2param(hogprh_env->env[conidx]->operation); + struct hogprh_read_info_rsp * rsp = KE_MSG_ALLOC(HOGPRH_READ_INFO_RSP, + prf_dst_task_get(&(hogprh_env->prf_env), conidx), dest_id, hogprh_read_info_rsp); + // set error status + rsp->status = param->status; + rsp->hid_idx = req->hid_idx; + rsp->info = req->info; + rsp->report_idx = req->report_idx; + + ke_msg_send(rsp); + } + + }break; + case HOGPRH_WRITE_REQ: + { + struct hogprh_write_req* req = (struct hogprh_write_req*) ke_msg2param(hogprh_env->env[conidx]->operation); + + struct hogprh_write_rsp * rsp = KE_MSG_ALLOC(HOGPRH_WRITE_RSP, + prf_dst_task_get(&(hogprh_env->prf_env), conidx), dest_id, hogprh_write_rsp); + // set error status + rsp->status = param->status; + rsp->hid_idx = req->hid_idx; + rsp->info = req->info; + rsp->report_idx = req->report_idx; + + ke_msg_send(rsp); + }break; + default: + { + // Not Expected at all + ASSERT_ERR(0); + }break; + } + + // operation is over - go back to idle state + ke_free(hogprh_env->env[conidx]->operation); + hogprh_env->env[conidx]->operation = NULL; + ke_state_set(dest_id, HOGPRH_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + + if(state == HOGPRH_BUSY) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct hogprh_env_tag *hogprh_env = PRF_ENV_GET(HOGPRH, hogprh); + struct hogprh_read_info_req* req = (struct hogprh_read_info_req*) ke_msg2param(hogprh_env->env[conidx]->operation); + + ASSERT_INFO(hogprh_env != NULL, dest_id, src_id); + ASSERT_INFO(hogprh_env->env[conidx] != NULL, dest_id, src_id); + + // check if read is requested locally due to a received notification or b + if(hogprh_env->env[conidx]->operation->src_id == dest_id) + { + // send report indication + struct hogprh_report_ind* ind = KE_MSG_ALLOC_DYN(HOGPRH_REPORT_IND, + prf_dst_task_get(&(hogprh_env->prf_env), conidx), dest_id, + hogprh_report_ind, param->length); + + ind->hid_idx = req->hid_idx; + ind->report_idx = req->report_idx; + ind->report.length = param->length; + memcpy(ind->report.value, param->value, param->length); + + ke_msg_send(ind); + } + // or by the HID Client application + else + { + struct hogprh_read_info_rsp * rsp = KE_MSG_ALLOC_DYN(HOGPRH_READ_INFO_RSP, + prf_dst_task_get(&(hogprh_env->prf_env),conidx), dest_id, hogprh_read_info_rsp, param->length); + + // set error status + rsp->status = GAP_ERR_NO_ERROR; + rsp->hid_idx = req->hid_idx; + rsp->info = req->info; + rsp->report_idx = req->report_idx; + + switch(req->info) + { + /// Protocol Mode + case HOGPRH_PROTO_MODE: + { + rsp->data.proto_mode = param->value[0]; + }break; + /// Report Map + case HOGPRH_REPORT_MAP: + { + rsp->data.report_map.length = param->length; + memcpy(rsp->data.report_map.value, param->value, param->length); + }break; + /// Report Map Char. External Report Reference Descriptor + case HOGPRH_REPORT_MAP_EXT_REP_REF: + { + rsp->data.report_map_ref.uuid_len = param->length; + memcpy(rsp->data.report_map_ref.uuid, param->value, co_min(param->length, ATT_UUID_128_LEN)); + }break; + /// HID Information + case HOGPRH_HID_INFO: + { + rsp->data.hid_info.bcdHID = co_read16p(param->value); + rsp->data.hid_info.bCountryCode = param->value[2]; + rsp->data.hid_info.flags = param->value[3]; + }break; + /// Report + case HOGPRH_REPORT: + { + rsp->data.report.length = param->length; + memcpy(rsp->data.report.value, param->value, param->length); + }break; + /// Report Char. Report Reference + case HOGPRH_REPORT_REF: + { + rsp->data.report_ref.id = param->value[0]; + rsp->data.report_ref.type = param->value[1]; + }break; + /// Report Notification config + case HOGPRH_REPORT_NTF_CFG: + { + rsp->data.report_cfg = co_read16p(param->value); + }break; + default: + { + ASSERT_ERR(0); + }break; + } + + // send response + ke_msg_send(rsp); + } + + // operation is over - go back to idle state + ke_free(hogprh_env->env[conidx]->operation); + hogprh_env->env[conidx]->operation = NULL; + ke_state_set(dest_id, HOGPRH_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + + if(state != HOGPRH_FREE) + { + // HID Instance + uint8_t hid_nb; + uint8_t report_idx; + uint8_t conidx = KE_IDX_GET(src_id); + bool finished = false; + // Get the address of the environment + struct hogprh_env_tag *hogprh_env = PRF_ENV_GET(HOGPRH, hogprh); + + // BOOT Report - HID instance is unknown. + for (hid_nb = 0; (hid_nb < hogprh_env->env[conidx]->hids_nb) && !finished; hid_nb++) + { + for (report_idx = 0; (report_idx < HOGPRH_NB_REPORT_INST_MAX) && !finished; report_idx++) + { + if (param->handle == hogprh_env->env[conidx]->hids[hid_nb].chars[HOGPRH_CHAR_REPORT + report_idx].val_hdl) + { + + // Check if size of the data is lower than [ATT_MTU-3] + if (param->length < (gattc_get_mtu(conidx) - 3)) + { + // send report indication + struct hogprh_report_ind* ind = KE_MSG_ALLOC_DYN(HOGPRH_REPORT_IND, + prf_dst_task_get(&(hogprh_env->prf_env), conidx), dest_id, + hogprh_report_ind, param->length); + + ind->hid_idx = hid_nb; + ind->report_idx = report_idx; + ind->report.length = param->length; + memcpy(ind->report.value, param->value, param->length); + + ke_msg_send(ind); + } + else + { + // data is maybe incomplete so perform an attribute read + struct hogprh_read_info_req* req = KE_MSG_ALLOC(HOGPRH_READ_INFO_REQ, + dest_id, dest_id, hogprh_read_info_req); + + req->info = HOGPRH_REPORT; + req->hid_idx = hid_nb; + req->report_idx = report_idx; + + ke_msg_send(req); + } + + finished = true; + } + } + } + } + + return (KE_MSG_CONSUMED); +} + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +//const struct ke_msg_handler hogprh_default_state[] = +KE_MSG_HANDLER_TAB(hogprh) +{ + {HOGPRH_ENABLE_REQ, (ke_msg_func_t)hogprh_enable_req_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + + {HOGPRH_READ_INFO_REQ, (ke_msg_func_t)hogprh_read_info_req_handler}, + {HOGPRH_WRITE_REQ, (ke_msg_func_t)hogprh_write_req_handler}, + + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void hogprh_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct hogprh_env_tag *p_hogprh_env = PRF_ENV_GET(HOGPRH, hogprh); + + p_task_desc->msg_handler_tab = hogprh_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(hogprh_msg_handler_tab); + p_task_desc->state = p_hogprh_env->state; + p_task_desc->idx_max = HOGPRH_IDX_MAX; +} +// Specifies the message handlers that are common to all states. +//const struct ke_state_handler hogprh_default_handler = KE_STATE_HANDLER(hogprh_default_state); + +#endif /* (BLE_HID_REPORT_HOST) */ + +/// @} HOGPRHTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrp_common.h new file mode 100644 index 0000000..c3a24ba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrp_common.h @@ -0,0 +1,132 @@ +/** + **************************************************************************************** + * + * @file hrp_common.h + * + * @brief Header File - Heart Rate Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _HRP_COMMON_H_ +#define _HRP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup HRP Heart Rate Profile + * @ingroup PROFILE + * @brief Heart Rate Profile + * + * The HRP module is the responsible block for implementing the Heart Rate Profile + * functionalities in the BLE Host. + * + * The Heart Rate Profile defines the functionality required in a device that allows + * the user (Collector device) to configure and recover Heart Rate measurements from + * a Heart Rate device. + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "prf_types.h" +#include +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// maximum number of RR-Interval supported +#define HRS_MAX_RR_INTERVAL (4) + +/// Heart Rate Control Point Not Supported error code +#define HRS_ERR_HR_CNTL_POINT_NOT_SUPPORTED (0x80) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// HRS codes for the 2 possible client configuration characteristic descriptors determination +enum +{ + /// Heart Rate Measurement + HRS_HR_MEAS_CODE = 0x01, + /// Energy Expended - Heart Rate Control Point + HRS_HR_CNTL_POINT_CODE, +}; + + +/// Heart Rate Measurement Flags field bit values +enum hrp_meas_flags_bf +{ + /// Heart Rate Value Format bit + /// 0 for UINT8 and 1 for UINT16. Units: beats per minute (bpm) + HRS_FLAG_HR_VALUE_FORMAT_POS = 0, + HRS_FLAG_HR_VALUE_FORMAT_BIT = CO_BIT(HRS_FLAG_HR_VALUE_FORMAT_POS), + + /// Sensor Contact Status bits + /// Sensor Contact feature supported in the current connection + /// Contact is detected + HRS_FLAG_SENSOR_CCT_DETECTED_POS = 1, + HRS_FLAG_SENSOR_CCT_DETECTED_BIT = CO_BIT(HRS_FLAG_SENSOR_CCT_DETECTED_POS), + + HRS_FLAG_SENSOR_CCT_FET_SUPPORTED_POS = 2, + HRS_FLAG_SENSOR_CCT_FET_SUPPORTED_BIT = CO_BIT(HRS_FLAG_SENSOR_CCT_FET_SUPPORTED_POS), + + /// Energy Expended Status bit + /// Energy Expended field is present. Units: kilo Joules + HRS_FLAG_ENERGY_EXPENDED_PRESENT_POS = 3, + HRS_FLAG_ENERGY_EXPENDED_PRESENT_BIT = CO_BIT(HRS_FLAG_ENERGY_EXPENDED_PRESENT_POS), + + /// RR-Interval bit + /// One or more RR-Interval values are present. Units: 1/1024 seconds + HRS_FLAG_RR_INTERVAL_PRESENT_POS = 4, + HRS_FLAG_RR_INTERVAL_PRESENT_BIT = CO_BIT(HRS_FLAG_RR_INTERVAL_PRESENT_POS), +}; + +/// Body Sensor Location +enum +{ + HRS_LOC_OTHER = 0, + HRS_LOC_CHEST = 1, + HRS_LOC_WRIST = 2, + HRS_LOC_FINGER = 3, + HRS_LOC_HAND = 4, + HRS_LOC_EAR_LOBE = 5, + HRS_LOC_FOOT = 6, + HRS_LOC_MAX, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Heart Rate measurement structure +struct hrs_hr_meas +{ + /// Flag + uint8_t flags; + /// Heart Rate Measurement Value + uint16_t heart_rate; + /// Energy Expended + uint16_t energy_expended; + /// RR-Interval numbers (max 4) + uint8_t nb_rr_interval; + /// RR-Intervals + uint16_t rr_intervals[HRS_MAX_RR_INTERVAL]; +}; + + +/// @} hrp_common + +#endif /* _HRP_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/api/hrpc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/api/hrpc_task.h new file mode 100644 index 0000000..35d1684 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/api/hrpc_task.h @@ -0,0 +1,185 @@ +/** + **************************************************************************************** + * + * @file hrpc_task.h + * + * @brief Header file - Heart Rate Profile Collector Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _HRPC_TASK_H_ +#define _HRPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup HRPCTASK Heart Rate Profile Collector Task + * @ingroup HRPC + * @brief Heart Rate Profile Collector Task + * + * The HRPCTASK is responsible for handling the messages coming in and out of the + * @ref HRPC monitor block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "hrp_common.h" +#include "rwip_task.h" // Task definitions + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Characteristics +enum +{ + /// Heart Rate Measurement + HRPC_CHAR_HR_MEAS, + /// Body Sensor Location + HRPC_CHAR_BODY_SENSOR_LOCATION, + /// Heart Rate Control Point + HRPC_CHAR_HR_CNTL_POINT, + + HRPC_CHAR_MAX, +}; + +/// Characteristic descriptors +enum +{ + /// Heart Rate Measurement client config + HRPC_DESC_HR_MEAS_CLI_CFG, + HRPC_DESC_MAX, + HRPC_DESC_MASK = 0x10, +}; + +/*@TRACE*/ +enum hrpc_msg_id +{ + /// Start the Heart Rate profile - at connection + HRPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_HRPC), + /// Confirm that cfg connection has finished with discovery results, or that normal cnx started + HRPC_ENABLE_RSP, + /// Generic message to read a HRS or DIS characteristic value + HRPC_RD_CHAR_CMD, + /// Generic message for read responses for APP + HRPC_RD_CHAR_IND, + /// Generic message for configuring the 2 characteristics that can be handled + HRPC_CFG_INDNTF_CMD, + /// APP request for control point write (to reset Energy Expanded) + HRPC_WR_CNTL_POINT_CMD, + /// Heart Rate value send to APP + HRPC_HR_MEAS_IND, + /// Complete Event Information + HRPC_CMP_EVT, +}; + +/// Operation codes +enum hrpc_op_codes +{ + /// Database Creation Procedure + HRPC_RESERVED_OP_CODE = 0, + /// Read char. Operation Code + HRPC_RD_CHAR_CMD_OP_CODE = 1, + /// CCC Configuration Operation Code + HRPC_CFG_INDNTF_CMD_OP_CODE = 2, + /// Write Control Point Operation Code + HRPC_WR_CNTL_POINT_CMD_OP_CODE = 3, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +///Structure containing the characteristics handles, value handles and descriptors +struct hrs_content +{ + /// service info + struct prf_svc svc; + + /// characteristic info: + /// - Heart Rate Measurement + /// - Body Sensor Location + /// - Heart Rate Control Point + struct prf_char_inf chars[HRPC_CHAR_MAX]; + + /// Descriptor handles: + /// - Heart Rate Measurement client cfg + struct prf_char_desc_inf descs[HRPC_DESC_MAX]; +}; + +/// Parameters of the @ref HRPC_ENABLE_REQ message +struct hrpc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values hrs + struct hrs_content hrs; +}; + +/// Parameters of the @ref HRPC_ENABLE_RSP message +struct hrpc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values hrs + struct hrs_content hrs; +}; + +/// Parameters of the @ref HRPC_CFG_INDNTF_CMD message +struct hrpc_cfg_indntf_cmd +{ + /// Stop/notify/indicate value to configure into the peer characteristic + uint16_t cfg_val; +}; + +/// Parameters of the @ref HRPC_RD_CHAR_CMD message +struct hrpc_rd_char_cmd +{ + /// Characteristic value code + uint8_t char_code; +}; + +/// Parameters of the @ref HRPC_RD_CHAR_IND message +struct hrpc_rd_char_ind +{ + /// Attribute data information + struct prf_att_info info; +}; + +/// Parameters of the @ref HRPC_WR_CNTL_POINT_CMD message +struct hrpc_wr_cntl_point_cmd +{ + /// value + uint8_t val; +}; + +/// Parameters of the @ref HRPC_HR_MEAS_IND message +struct hrpc_hr_meas_ind +{ + /// Heart Rate measurement + struct hrs_hr_meas meas_val; +}; + +/// Parameters of the @ref HRPC_CMP_EVT message +struct hrpc_cmp_evt +{ + /// Operation + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} HRPCTASK + +#endif /* _HRPC_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/sourcelist.txt new file mode 100644 index 0000000..1d3f048 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + hrpc.c + hrpc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/src/hrpc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/src/hrpc.c new file mode 100644 index 0000000..0e1743b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/src/hrpc.c @@ -0,0 +1,267 @@ +/** + **************************************************************************************** + * + * @file hrpc.c + * + * @brief Heart Rate Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HRPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_HR_COLLECTOR) + +#include "hrp_common.h" +#include "hrpc.h" +#include "hrpc_task.h" + +#include "ke_mem.h" +#include "co_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the HRPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t hrpc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, + uint16_t app_task, uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct hrpc_env_tag *p_hrpc_env = + (struct hrpc_env_tag *) ke_malloc(sizeof(struct hrpc_env_tag), KE_MEM_ATT_DB); + + // allocate HRPC required environment variable + p_env->env = (prf_env_t *) p_hrpc_env; + + p_hrpc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_hrpc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_HRPC; + hrpc_task_init(&(p_env->desc)); + + for (idx = 0; idx < HRPC_IDX_MAX; idx++) + { + p_hrpc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), HRPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void hrpc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct hrpc_env_tag *p_hrpc_env = (struct hrpc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_hrpc_env->p_env[conidx] != NULL) + { + ke_free(p_hrpc_env->p_env[conidx]); + p_hrpc_env->p_env[conidx] = NULL; + } + + // Put HRP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), HRPC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the HRPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void hrpc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct hrpc_env_tag *p_hrpc_env = (struct hrpc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < HRPC_IDX_MAX; idx++) + { + hrpc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_hrpc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void hrpc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put HRP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), HRPC_IDLE); +} + +/// HRPC Task interface required by profile manager +const struct prf_task_cbs hrpc_itf = +{ + hrpc_init, + hrpc_destroy, + hrpc_create, + hrpc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *hrpc_prf_itf_get(void) +{ + return &hrpc_itf; +} + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +void hrpc_enable_rsp_send(struct hrpc_env_tag *p_hrpc_env, uint8_t conidx, uint8_t status) +{ + //send APP the details of the discovered attributes on HTPT + struct hrpc_enable_rsp *p_rsp = KE_MSG_ALLOC( + HRPC_ENABLE_RSP, + prf_dst_task_get(&(p_hrpc_env->prf_env), conidx), + prf_src_task_get(&(p_hrpc_env->prf_env), conidx), + hrpc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->hrs = p_hrpc_env->p_env[conidx]->hrs; + //register HRPC task in gatt for indication/notifications + prf_register_atthdl2gatt(&p_hrpc_env->prf_env, conidx, &p_hrpc_env->p_env[conidx]->hrs.svc); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_hrpc_env->prf_env), conidx), HRPC_IDLE); + } + + ke_msg_send(p_rsp); +} + +void hrpc_unpack_meas_value(struct hrs_hr_meas *p_meas_val, uint8_t *p_packed_hr, uint8_t size) +{ + int8_t cursor = 0; + int8_t i = 0; + + // Heart Rate measurement flags + p_meas_val->flags = p_packed_hr[0]; + cursor += 1; + + if (GETB(p_meas_val->flags, HRS_FLAG_HR_VALUE_FORMAT)) + { + // Heart Rate Measurement Value 16 bits + p_meas_val->heart_rate = co_read16p(&p_packed_hr[cursor]); + cursor += 2; + } + else + { + // Heart Rate Measurement Value 8 bits + p_meas_val->heart_rate = (uint16_t) p_packed_hr[cursor]; + cursor += 1; + } + + if (GETB(p_meas_val->flags, HRS_FLAG_ENERGY_EXPENDED_PRESENT)) + { + // Energy Expended present + p_meas_val->energy_expended = co_read16p(&p_packed_hr[cursor]); + cursor += 2; + } + + // retrieve number of rr intervals + p_meas_val->nb_rr_interval = ((size - cursor) > 0 ? ((size - cursor)/ 2) : (0)); + + for (i = 0; (i < (p_meas_val->nb_rr_interval)) && (i < (HRS_MAX_RR_INTERVAL)); i++) + { + // RR-Intervals + p_meas_val->rr_intervals[i] = co_read16p(&p_packed_hr[cursor]); + cursor += 2; + } +} + +void hrpc_send_cmp_evt(struct hrpc_env_tag *p_hrpc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct hrpc_cmp_evt *p_evt; + ke_task_id_t src_id = prf_src_task_get(&(p_hrpc_env->prf_env), conidx); + ke_task_id_t dest_id = prf_dst_task_get(&(p_hrpc_env->prf_env), conidx); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == HRPC_BUSY) + { + ke_state_set(src_id, HRPC_IDLE); + } + + // Send the message to the application + p_evt = KE_MSG_ALLOC(HRPC_CMP_EVT, dest_id, src_id, hrpc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif /* (BLE_HR_COLLECTOR) */ + +/// @} HRPC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/src/hrpc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/src/hrpc.h new file mode 100644 index 0000000..3101baf --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/src/hrpc.h @@ -0,0 +1,193 @@ +/** + **************************************************************************************** + * + * @file hrpc.h + * + * @brief Header file - Heart Rate Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _HRPC_H_ +#define _HRPC_H_ + +/** + **************************************************************************************** + * @addtogroup HRPC Heart Rate Profile Collector + * @ingroup HRP + * @brief Heart Rate Profile Collector + * + * The HRPC is responsible for providing Heart Rate Profile Collector functionalities + * to upper layer module or application. The device using this profile takes the role + * of Heart Rate Profile Collector. + * + * Heart Rate Profile Collector. (HRPC): A HRPC (e.g. PC, phone, etc) + * is the term used by this profile to describe a device that can interpret Heart Rate + * measurement in a way suitable to the user application. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#if (BLE_HR_COLLECTOR) + +#include "hrp_common.h" +#include "hrpc_task.h" +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +///Maximum number of Heart Rate Collector task instances +#define HRPC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * ENUMERATIONS + **************************************************************************************** + */ +/// Possible states of the HRPC task +enum +{ + /// Free state + HRPC_FREE, + /// Idle state + HRPC_IDLE, + /// Discovering Heart Rate SVC and Chars + HRPC_DISCOVERING, + /// Busy state + HRPC_BUSY, + + /// Number of defined states. + HRPC_STATE_MAX +}; + +/// Internal codes for reading a HRS or DIS characteristic with one single request +enum +{ + /// Read HRS Heart Rate Measurement + HRPC_RD_HRS_HR_MEAS = HRPC_CHAR_HR_MEAS, + /// Body Sensor Location + HRPC_RD_HRS_BODY_SENSOR_LOC = HRPC_CHAR_BODY_SENSOR_LOCATION, + /// Heart Rate Control Point + HRPC_RD_HRS_CNTL_POINT = HRPC_CHAR_HR_CNTL_POINT, + + /// Read HRS Heart Rate Measurement Client Cfg. Desc + HRPC_RD_HRS_HR_MEAS_CFG = (HRPC_DESC_MASK | HRPC_DESC_HR_MEAS_CLI_CFG), +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +struct hrpc_cnx_env +{ + /// Current operation code + void *p_operation; + /// Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Last characteristic code used in a read or a write request + uint16_t last_char_code; + /// Counter used to check service uniqueness + uint8_t nb_svc; + ///HTS characteristics + struct hrs_content hrs; +}; + +/// Heart Rate Profile Collector environment variable +struct hrpc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connection + struct hrpc_cnx_env *p_env[HRPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[HRPC_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve HRP client profile interface + * @return HRP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *hrpc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Heart Rate ATT DB discovery results to HRPC host. + * + * @param p_hrpc_env Heart Rate Profile Client Role task environment + * @param conidx Connection index + * @param status Response status code + **************************************************************************************** + */ +void hrpc_enable_rsp_send(struct hrpc_env_tag *p_hrpc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Unpack Heart Rate measurement data into a comprehensive structure. + * + * @param[out] p_meas_val Pointer to Heart Rate measurement structure destination + * @param[in] p_packed_hr Pointer of the packed data of Heart Rate Measurement + * information + * @param[in] size Packet data size + **************************************************************************************** + */ +void hrpc_unpack_meas_value(struct hrs_hr_meas *p_meas_val, uint8_t *p_packed_hr, uint8_t size); + +/** + **************************************************************************************** + * @brief Send an HRPC_CMP_EVT message to a requester. + * + * @param[in] p_hrpc_env HRP Client environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void hrpc_send_cmp_evt(struct hrpc_env_tag *p_hrpc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void hrpc_task_init(struct ke_task_desc *p_task_desc); + + +#endif /* (BLE_HR_COLLECTOR) */ + +/// @} HRPC + +#endif /* _HRPC_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/src/hrpc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/src/hrpc_task.c new file mode 100644 index 0000000..6110e05 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrpc/src/hrpc_task.c @@ -0,0 +1,638 @@ +/** + **************************************************************************************** + * + * @file hrpc_task.c + * + * @brief Heart Rate Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HRPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#include "hrp_common.h" + +#if (BLE_HR_COLLECTOR) +#include "co_utils.h" +#include "gap.h" +#include "attm.h" +#include "hrpc_task.h" +#include "hrpc.h" +#include "gattc_task.h" + +#include "ke_mem.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// State machine used to retrieve heart rate service characteristics information +const struct prf_char_def hrpc_hrs_char[HRPC_CHAR_MAX] = +{ + // Heart Rate Measurement + [HRPC_CHAR_HR_MEAS] = {ATT_CHAR_HEART_RATE_MEAS, + ATT_MANDATORY, + ATT_CHAR_PROP_NTF}, + // Body Sensor Location + [HRPC_CHAR_BODY_SENSOR_LOCATION] = {ATT_CHAR_BODY_SENSOR_LOCATION, + ATT_OPTIONAL, + ATT_CHAR_PROP_RD}, + // Heart Rate Control Point + [HRPC_CHAR_HR_CNTL_POINT] = {ATT_CHAR_HEART_RATE_CNTL_POINT, + ATT_OPTIONAL, + ATT_CHAR_PROP_WR}, +}; + +/// State machine used to retrieve heart rate service characteristic description information +const struct prf_char_desc_def hrpc_hrs_char_desc[HRPC_DESC_MAX] = +{ + // Heart Rate Measurement client config + [HRPC_DESC_HR_MEAS_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, HRPC_CHAR_HR_MEAS}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == HRPC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct hrpc_env_tag *p_hrpc_env = PRF_ENV_GET(HRPC, hrpc); + + ASSERT_INFO(p_hrpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_hrpc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_hrpc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve HRS characteristics and descriptors + prf_extract_svc_info(p_ind, HRPC_CHAR_MAX, &hrpc_hrs_char[0], &p_hrpc_env->p_env[conidx]->hrs.chars[0], + HRPC_DESC_MAX, &hrpc_hrs_char_desc[0], &p_hrpc_env->p_env[conidx]->hrs.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_hrpc_env->p_env[conidx]->hrs.svc.shdl = p_ind->start_hdl; + p_hrpc_env->p_env[conidx]->hrs.svc.ehdl = p_ind->end_hdl; + } + + p_hrpc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HRPC_ENABLE_REQ message. + * The handler enables the Heart Rate Profile Collector Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int hrpc_enable_req_handler(ke_msg_id_t const msgid, + struct hrpc_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Heart Rate Profile Client Role Task Environment + struct hrpc_env_tag *p_hrpc_env = PRF_ENV_GET(HRPC, hrpc);; + + ASSERT_INFO(p_hrpc_env != NULL, dest_id, src_id); + // Config connection, start discovering + if ((ke_state_get(dest_id) == HRPC_IDLE) && (p_hrpc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_hrpc_env->p_env[conidx] = (struct hrpc_cnx_env *) ke_malloc(sizeof(struct hrpc_cnx_env), KE_MEM_ATT_DB); + memset(p_hrpc_env->p_env[conidx], 0, sizeof(struct hrpc_cnx_env)); + + // Config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + // start discovering HRS on peer + prf_disc_svc_send(&(p_hrpc_env->prf_env), conidx, ATT_SVC_HEART_RATE); + + p_hrpc_env->p_env[conidx]->last_uuid_req = ATT_SVC_HEART_RATE; + + // Go to DISCOVERING state + ke_state_set(dest_id, HRPC_DISCOVERING); + } + //normal connection, get saved att details + else + { + p_hrpc_env->p_env[conidx]->hrs = p_param->hrs; + //send APP confirmation that can start normal connection to TH + hrpc_enable_rsp_send(p_hrpc_env, conidx, GAP_ERR_NO_ERROR); + } + + status = GAP_ERR_NO_ERROR; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + hrpc_enable_rsp_send(p_hrpc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct hrpc_env_tag *p_hrpc_env = PRF_ENV_GET(HRPC, hrpc); + + if (p_hrpc_env != NULL) + { + // Status + uint8_t status = p_param->status; + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == HRPC_DISCOVERING) + { + if ((status == ATT_ERR_ATTRIBUTE_NOT_FOUND)|| + (status == ATT_ERR_NO_ERROR)) + { + // Discovery + // check characteristic validity + if (p_hrpc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(HRPC_CHAR_MAX, + p_hrpc_env->p_env[conidx]->hrs.chars, + hrpc_hrs_char); + } + // too much services + else if (p_hrpc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(HRPC_DESC_MAX, + p_hrpc_env->p_env[conidx]->hrs.descs, + hrpc_hrs_char_desc, + p_hrpc_env->p_env[conidx]->hrs.chars); + } + } + + hrpc_enable_rsp_send(p_hrpc_env, conidx, status); + } + + else if (state == HRPC_BUSY) + { + switch (p_param->operation) + { + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + uint8_t operation; + + if (p_hrpc_env->p_env[conidx]->last_char_code == HRPC_DESC_HR_MEAS_CLI_CFG) + { + operation = HRPC_CFG_INDNTF_CMD_OP_CODE; + } + else + { + operation = HRPC_WR_CNTL_POINT_CMD_OP_CODE; + } + + hrpc_send_cmp_evt(p_hrpc_env, conidx, operation, status); + } break; + + case GATTC_READ: + { + hrpc_send_cmp_evt(p_hrpc_env, conidx, HRPC_RD_CHAR_CMD_OP_CODE, status); + } break; + + default: + { + + } break; + } + + ke_state_set(prf_src_task_get(&p_hrpc_env->prf_env, conidx), HRPC_IDLE); + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HRPC_RD_CHAR_CMD message. + * Check if the handle exists in profile(already discovered) and send request, otherwise + * error to APP. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int hrpc_rd_char_cmd_handler(ke_msg_id_t const msgid, + struct hrpc_rd_char_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + uint8_t msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct hrpc_env_tag *p_hrpc_env = PRF_ENV_GET(HRPC, hrpc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == HRPC_IDLE) + { + ASSERT_INFO(p_hrpc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_hrpc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + uint16_t search_hdl = ATT_INVALID_SEARCH_HANDLE; + + if (((p_param->char_code & HRPC_DESC_MASK) == HRPC_DESC_MASK) && + ((p_param->char_code & ~HRPC_DESC_MASK) < HRPC_DESC_MAX)) + { + search_hdl = p_hrpc_env->p_env[conidx]->hrs.descs[p_param->char_code & ~HRPC_DESC_MASK].desc_hdl; + } + else if (p_param->char_code < HRPC_CHAR_MAX) + { + search_hdl = p_hrpc_env->p_env[conidx]->hrs.chars[p_param->char_code].val_hdl; + } + + // check if handle is viable + if (search_hdl != ATT_INVALID_SEARCH_HANDLE) + { + // Store the command + p_hrpc_env->p_env[conidx]->last_char_code = p_param->char_code; + // Send the read request + prf_read_char_send(&(p_hrpc_env->prf_env), conidx, + p_hrpc_env->p_env[conidx]->hrs.svc.shdl, + p_hrpc_env->p_env[conidx]->hrs.svc.ehdl, + search_hdl); + + // Go to the Busy state + ke_state_set(dest_id, HRPC_BUSY); + + status = ATT_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == HRPC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + hrpc_send_cmp_evt(p_hrpc_env, conidx, HRPC_RD_CHAR_CMD_OP_CODE, status); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct hrpc_env_tag *p_hrpc_env = PRF_ENV_GET(HRPC, hrpc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_hrpc_env->p_env[conidx] != NULL) + { + ASSERT_ERR(ke_state_get(dest_id) == HRPC_BUSY); + + prf_client_att_info_rsp(&p_hrpc_env->prf_env, conidx, HRPC_RD_CHAR_IND, + GAP_ERR_NO_ERROR, p_param); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HRPC_CFG_INDNTF_CMD message. + * It allows configuration of the peer ind/ntf/stop characteristic for a specified characteristic. + * Will return an error code if that cfg char does not exist. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int hrpc_cfg_indntf_cmd_handler(ke_msg_id_t const msgid, + struct hrpc_cfg_indntf_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct hrpc_env_tag *p_hrpc_env = PRF_ENV_GET(HRPC, hrpc); + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + uint8_t msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == HRPC_IDLE) + { + if (p_hrpc_env->p_env[conidx] != NULL) + { + // Status + status = PRF_ERR_INVALID_PARAM; + // Check if p_parameter is OK + if ((p_param->cfg_val == PRF_CLI_STOP_NTFIND) || + (p_param->cfg_val == PRF_CLI_START_NTF)) + { + // Get handle of the client configuration + uint16_t cfg_hdl = + p_hrpc_env->p_env[conidx]->hrs.descs[HRPC_DESC_HR_MEAS_CLI_CFG].desc_hdl; + + // Status + status = PRF_ERR_INEXISTENT_HDL; + //check if the handle value exists + if (cfg_hdl != ATT_INVALID_SEARCH_HANDLE) + { + p_hrpc_env->p_env[conidx]->last_char_code = HRPC_DESC_HR_MEAS_CLI_CFG; + + status = GAP_ERR_NO_ERROR; + // Go to the Busy state + ke_state_set(dest_id, HRPC_BUSY); + // Send GATT Write Request + prf_gatt_write_ntf_ind(&p_hrpc_env->prf_env, conidx, cfg_hdl, p_param->cfg_val); + } + } + } + else + { + status = PRF_APP_ERROR; + } + } + else if (state == HRPC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + hrpc_send_cmp_evt(p_hrpc_env, conidx, HRPC_CFG_INDNTF_CMD_OP_CODE, status); + } + + return (msg_status); +} + +/** +**************************************************************************************** +* @brief Handles reception of the @ref HRPC_WR_CNTL_POINT_CMD message. +* Check if the handle exists in profile(already discovered) and send request, otherwise +* error to APP. +* @param[in] msgid Id of the message received (probably unused). +* @param[in] p_param Pointer to the parameters of the message. +* @param[in] dest_id ID of the receiving task instance (probably unused). +* @param[in] src_id ID of the sending task instance. +* @return If the message was consumed or not. +**************************************************************************************** +*/ +__STATIC int hrpc_wr_cntl_point_cmd_handler(ke_msg_id_t const msgid, + struct hrpc_wr_cntl_point_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct hrpc_env_tag *p_hrpc_env = PRF_ENV_GET(HRPC, hrpc); + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + uint8_t msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == HRPC_IDLE) + { + do + { + // this is mandatory readable if it is included in the peer's DB + if (p_hrpc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + + break; + } + + // this is mandatory readable if it is included in the peer's DB + if (p_hrpc_env->p_env[conidx]->hrs.chars[HRPC_CHAR_HR_CNTL_POINT].char_hdl == ATT_INVALID_SEARCH_HANDLE) + { + // send app error indication for inexistent handle for this characteristic + status = PRF_ERR_INEXISTENT_HDL; + + break; + } + + if ((p_hrpc_env->p_env[conidx]->hrs.chars[HRPC_CHAR_HR_CNTL_POINT].prop & ATT_CHAR_PROP_WR) + != ATT_CHAR_PROP_WR) + { + //write not allowed, so no point in continuing + status = PRF_ERR_NOT_WRITABLE; + + break; + } + + p_hrpc_env->p_env[conidx]->last_char_code = HRPC_CHAR_HR_CNTL_POINT; + + // Send GATT Write Request + prf_gatt_write(&p_hrpc_env->prf_env, + conidx, p_hrpc_env->p_env[conidx]->hrs.chars[HRPC_CHAR_HR_CNTL_POINT].val_hdl, + (uint8_t *)&p_param->val, sizeof(uint8_t), GATTC_WRITE); + + // Go to the Busy state + ke_state_set(dest_id, HRPC_BUSY); + + } while (0); + } + else if (state == HRPC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + hrpc_send_cmp_evt(p_hrpc_env, conidx, HRPC_WR_CNTL_POINT_CMD_OP_CODE, status); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct hrpc_env_tag *p_hrpc_env = PRF_ENV_GET(HRPC, hrpc); + + if (p_hrpc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + if ((p_param->handle == p_hrpc_env->p_env[conidx]->hrs.chars[HRPC_CHAR_HR_MEAS].val_hdl) && + (p_param->type == GATTC_NOTIFY)) + { + // build a HRPC_HR_MEAS_IND message with stable heart rate value code. + struct hrpc_hr_meas_ind *p_ind = KE_MSG_ALLOC( + HRPC_HR_MEAS_IND, + prf_dst_task_get(&(p_hrpc_env->prf_env), conidx), + prf_src_task_get(&(p_hrpc_env->prf_env), conidx), + hrpc_hr_meas_ind); + + // unpack heart rate measurement. + hrpc_unpack_meas_value(&(p_ind->meas_val), (uint8_t *) p_param->value, p_param->length); + + ke_msg_send(p_ind); + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(hrpc) +{ + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {HRPC_ENABLE_REQ, (ke_msg_func_t)hrpc_enable_req_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + {HRPC_CFG_INDNTF_CMD, (ke_msg_func_t)hrpc_cfg_indntf_cmd_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {HRPC_RD_CHAR_CMD, (ke_msg_func_t)hrpc_rd_char_cmd_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {HRPC_WR_CNTL_POINT_CMD, (ke_msg_func_t)hrpc_wr_cntl_point_cmd_handler}, +}; + +void hrpc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct hrpc_env_tag *p_hrpc_env = PRF_ENV_GET(HRPC, hrpc); + + p_task_desc->msg_handler_tab = hrpc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(hrpc_msg_handler_tab); + p_task_desc->state = p_hrpc_env->state; + p_task_desc->idx_max = HRPC_IDX_MAX; +} + +#endif /* (BLE_HR_COLLECTOR) */ +/// @} HRPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/api/hrps_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/api/hrps_task.h new file mode 100644 index 0000000..db3a46d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/api/hrps_task.h @@ -0,0 +1,136 @@ +/** + **************************************************************************************** + * + * @file hrps_task.h + * + * @brief Header file - Heart Rate Profile Sensor Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _HRPS_TASK_H_ +#define _HRPS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup HRPSTASK Task + * @ingroup HRPS + * @brief Heart Rate Profile Task. + * + * The HRPSTASK is responsible for handling the messages coming in and out of the + * @ref HRPS collector block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include +#include "rwip_task.h" // Task definitions +#include "hrp_common.h" +/* + * ENUMERATIONS + **************************************************************************************** + */ +/// Messages for Heart Rate Profile Sensor +/*@TRACE*/ +enum hrps_msg_id +{ + /// Start the Heart Rate Profile Sensor - at connection + HRPS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_HRPS), + /// Disable confirmation with configuration to save after profile disabled + HRPS_ENABLE_RSP, + /// Send Heart Rate measurement value from APP + HRPS_MEAS_SEND_CMD, + /// Inform APP of new configuration value + HRPS_CFG_INDNTF_IND, + /// Inform APP that Energy Expanded must be reset value + HRPS_ENERGY_EXP_RESET_IND, + /// Complete Event Information + HRPS_CMP_EVT, +}; + +/// Operation codes +enum hrps_op_codes +{ + /// Database Creation Procedure + HRPS_RESERVED_OP_CODE = 0, + + /// Send Measurement value Operation Code + HRPS_MEAS_SEND_CMD_OP_CODE = 1, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ +/// Parameters of the @ref HRPS_CREATE_DB_REQ message +struct hrps_db_cfg +{ + /// Database configuration + uint8_t features; + /// Body Sensor Location + uint8_t body_sensor_loc; +}; + +/// Parameters of the @ref HRPS_ENABLE_REQ message +struct hrps_enable_req +{ + /// Connection index + uint8_t conidx; + /// Heart Rate Notification configuration + uint16_t hr_meas_ntf; +}; + +/// Parameters of the @ref HRPS_ENABLE_RSP message +struct hrps_enable_rsp +{ + /// Connection index + uint8_t conidx; + /// status + uint8_t status; +}; + +/// Parameters of the @ref HRPS_CFG_INDNTF_IND message +struct hrps_cfg_indntf_ind +{ + /// Connection idx + uint8_t conidx; + /// Stop/notify/indicate value to configure into the peer characteristic + uint16_t cfg_val; +}; + +/// Parameters of the @ref HRPS_MEAS_SEND_CMD message +struct hrps_meas_send_cmd +{ + /// Heart Rate measurement + struct hrs_hr_meas meas_val; +}; + +/// Parameters of the @ref HRPS_CMP_EVT message +struct hrps_cmp_evt +{ + /// Operation code + uint8_t operation; + /// Status + uint8_t status; +}; + +/// Parameters of the @ref HRPS_ENERGY_EXP_RESET_IND message +struct hrps_energy_exp_reset_ind +{ + /// Connection handle + uint8_t conidx; +}; + +/// @} HRPSTASK + +#endif /* _HRPS_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/sourcelist.txt new file mode 100644 index 0000000..ca30190 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + hrps.c + hrps_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps.c new file mode 100644 index 0000000..d42419d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps.c @@ -0,0 +1,341 @@ +/** + **************************************************************************************** + * + * @file hrps.c + * + * @brief Heart Rate Profile Sensor implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HRPS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_HR_SENSOR) +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "gapc_task.h" +#include "hrps.h" +#include "hrps_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * HTPT PROFILE ATTRIBUTES + **************************************************************************************** + */ + +/// Full HRS Database Description - Used to add attributes into the database +const struct attm_desc hrps_att_db[HRS_IDX_NB] = +{ + // Heart Rate Service Declaration + [HRS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Heart Rate Measurement Characteristic Declaration + [HRS_IDX_HR_MEAS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Heart Rate Measurement Characteristic Value + [HRS_IDX_HR_MEAS_VAL] = {ATT_CHAR_HEART_RATE_MEAS, PERM(NTF, ENABLE), PERM(RI, ENABLE), HRPS_HT_MEAS_MAX_LEN}, + // Heart Rate Measurement Characteristic - Client Characteristic Configuration Descriptor + [HRS_IDX_HR_MEAS_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Body Sensor Location Characteristic Declaration + [HRS_IDX_BODY_SENSOR_LOC_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Body Sensor Location Characteristic Value + [HRS_IDX_BODY_SENSOR_LOC_VAL] = {ATT_CHAR_BODY_SENSOR_LOCATION, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, + + // Heart Rate Control Point Characteristic Declaration + [HRS_IDX_HR_CTNL_PT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Heart Rate Control Point Characteristic Value + [HRS_IDX_HR_CTNL_PT_VAL] = {ATT_CHAR_HEART_RATE_CNTL_POINT, PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, +}; + +/** + **************************************************************************************** + * @brief Initialization of the HRPS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t hrps_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct hrps_db_cfg *p_params) +{ + //------------------ create the attribute database for the profile ------------------- + // Service Configuration Flag + uint8_t cfg_flag = HRPS_MANDATORY_MASK; + // Database Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + // Set Configuration Flag Value + if (GETB(p_params->features, HRPS_BODY_SENSOR_LOC_CHAR_SUP)) + { + cfg_flag |= HRPS_BODY_SENSOR_LOC_MASK; + } + if (GETB(p_params->features, HRPS_ENGY_EXP_FEAT_SUP)) + { + cfg_flag |= HRPS_HR_CTNL_PT_MASK; + } + + // Add Service Into Database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_HEART_RATE, (uint8_t *)&cfg_flag, + HRS_IDX_NB, NULL, p_env->task, &hrps_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS))| PERM(SVC_MI, DISABLE)); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + // Allocate HRPS required environment variable + struct hrps_env_tag *p_hrps_env = + (struct hrps_env_tag *) ke_malloc(sizeof(struct hrps_env_tag), KE_MEM_ATT_DB); + + // Initialize HRPS environment + p_env->env = (prf_env_t*) p_hrps_env; + p_hrps_env->shdl = *p_start_hdl; + p_hrps_env->features = p_params->features; + p_hrps_env->sensor_location = p_params->body_sensor_loc; + p_hrps_env->p_operation = NULL; + + p_hrps_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Mono Instantiated task + p_hrps_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_HRPS; + hrps_task_init(&(p_env->desc)); + + // Put HRS in Idle state + ke_state_set(p_env->task, HRPS_IDLE); + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the HRPS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void hrps_destroy(struct prf_task_env *p_env) +{ + struct hrps_env_tag *p_hrps_env = (struct hrps_env_tag *) p_env->env; + + // free profile environment variables + if (p_hrps_env->p_operation != NULL) + { + ke_free(p_hrps_env->p_operation); + } + + p_env->env = NULL; + ke_free(p_hrps_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void hrps_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Nothing to do +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void hrps_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + // Nothing to do +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// HRPS Task interface required by profile manager +const struct prf_task_cbs hrps_itf = +{ + (prf_init_fnct) hrps_init, + hrps_destroy, + hrps_create, + hrps_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *hrps_prf_itf_get(void) +{ + return &hrps_itf; +} + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +void hrps_send_cmp_evt(struct hrps_env_tag *p_hrps_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct hrps_cmp_evt *p_cfm; + + ke_task_id_t src_id = prf_src_task_get(&p_hrps_env->prf_env, conidx); + ke_task_id_t dest_id = prf_dst_task_get(&p_hrps_env->prf_env, conidx); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == HRPS_BUSY) + { + ke_state_set(src_id, HRPS_IDLE); + } + + // Send CFM to APP that value has been sent or not + p_cfm = KE_MSG_ALLOC(HRPS_CMP_EVT, dest_id, src_id, hrps_cmp_evt); + p_cfm->operation = operation; + p_cfm->status = status; + + ke_msg_send(p_cfm); +} + +uint8_t hrps_pack_meas_value(uint8_t *p_packed_hr, const struct hrs_hr_meas *p_meas_val) +{ + uint8_t cursor = 0; + uint8_t i = 0; + + // Heart Rate measurement flags + *(p_packed_hr) = p_meas_val->flags; + + if (GETB(p_meas_val->flags, HRS_FLAG_HR_VALUE_FORMAT)) + { + // Heart Rate Measurement Value 16 bits + co_write16p(p_packed_hr + 1, p_meas_val->heart_rate); + cursor += 3; + } + else + { + // Heart Rate Measurement Value 8 bits + *(p_packed_hr + 1) = p_meas_val->heart_rate; + cursor += 2; + } + + if (GETB(p_meas_val->flags, HRS_FLAG_ENERGY_EXPENDED_PRESENT)) + { + // Energy Expended present + co_write16p(p_packed_hr + cursor, p_meas_val->energy_expended); + cursor += 2; + } + + if (GETB(p_meas_val->flags, HRS_FLAG_RR_INTERVAL_PRESENT)) + { + for (i = 0; (i < (p_meas_val->nb_rr_interval)) && (i < (HRS_MAX_RR_INTERVAL)); i++) + { + // RR-Intervals + co_write16p(p_packed_hr + cursor, p_meas_val->rr_intervals[i]); + cursor += 2; + } + } + + // Clear unused packet data + if (cursor < HRPS_HT_MEAS_MAX_LEN) + { + memset(p_packed_hr + cursor, 0, HRPS_HT_MEAS_MAX_LEN - cursor); + } + + return cursor; +} + +void hrps_exe_operation(uint8_t conidx) +{ + struct hrps_env_tag *p_hrps_env = PRF_ENV_GET(HRPS, hrps); + + ASSERT_ERR(p_hrps_env->p_operation != NULL); + + bool finished = true; + + while (p_hrps_env->p_operation->cursor < BLE_CONNECTION_MAX) + { + // Check if notifications are enabled + if ((p_hrps_env->hr_meas_ntf[p_hrps_env->p_operation->cursor] & ~HRP_PRF_CFG_PERFORMED_OK) == PRF_CLI_START_NTF) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_meas_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, p_hrps_env->p_operation->cursor), + prf_src_task_get(&(p_hrps_env->prf_env), 0), + gattc_send_evt_cmd, p_hrps_env->p_operation->length); + + // Fill in the parameter structure + p_meas_val->operation = GATTC_NOTIFY; + p_meas_val->handle = p_hrps_env->shdl + HRS_IDX_HR_MEAS_VAL; + p_meas_val->length = p_hrps_env->p_operation->length; + memcpy(p_meas_val->value, p_hrps_env->p_operation->data, p_hrps_env->p_operation->length); + + // Send the event + ke_msg_send(p_meas_val); + + finished = false; + p_hrps_env->p_operation->cursor++; + break; + } + + p_hrps_env->p_operation->cursor++; + } + + // check if operation is finished + if (finished) + { + // Send confirmation + hrps_send_cmp_evt(p_hrps_env, conidx, HRPS_MEAS_SEND_CMD_OP_CODE, GAP_ERR_NO_ERROR); + + // free operation + ke_free(p_hrps_env->p_operation); + p_hrps_env->p_operation = NULL; + // go back to idle state + ke_state_set(prf_src_task_get(&(p_hrps_env->prf_env), 0), HRPS_IDLE); + } +} + +#endif /* BLE_HR_SENSOR */ + +/// @} HRPS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps.h new file mode 100644 index 0000000..dec764b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps.h @@ -0,0 +1,248 @@ +/** + **************************************************************************************** + * + * @file hrps.h + * + * @brief Header file - Heart Rate Profile Sensor. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _HRPS_H_ +#define _HRPS_H_ + +/** + **************************************************************************************** + * @addtogroup HRPS Heart Rate Profile Sensor + * @ingroup HRP + * @brief Heart Rate Profile Sensor + * + * Heart Rate sensor (HRS) profile provides functionalities to upper layer module + * application. The device using this profile takes the role of Heart Rate sensor. + * + * The interface of this role to the Application is: + * - Enable the profile role (from APP) + * - Disable the profile role (from APP) + * - Notify peer device during Heart Rate measurement (from APP) + * - Indicate measurements performed to peer device (from APP) + * + * Profile didn't manages multiple users configuration and storage of offline measurements. + * This must be handled by application. + * + * Heart Rate Profile Sensor. (HRPS): A HRPS (e.g. PC, phone, etc) + * is the term used by this profile to describe a device that can perform Heart Rate + * measurement and notify about on-going measurement and indicate final result to a peer + * BLE device. + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_HR_SENSOR) +#include "hrp_common.h" +#include "prf_types.h" +#include "prf.h" +#include "hrps_task.h" +#include "attm.h" + +/* + * DEFINES + **************************************************************************************** + */ +///Maximum number of Heart Rate task instances +#define HRPS_IDX_MAX 0x01 + +#define HRPS_HT_MEAS_MAX_LEN (5 + (2 * HRS_MAX_RR_INTERVAL)) + +#define HRPS_MANDATORY_MASK (0x0F) +#define HRPS_BODY_SENSOR_LOC_MASK (0x30) +#define HRPS_HR_CTNL_PT_MASK (0xC0) + +#define HRP_PRF_CFG_PERFORMED_OK (0x80) + +/* + * MACROS + **************************************************************************************** + */ + +#define HRPS_IS_SUPPORTED(features, mask) ((features & mask) == mask) + +/* + * ENUMERATIONS + **************************************************************************************** + */ +/// Possible states of the HRPS task +enum +{ + /// Idle state + HRPS_IDLE, + /// Connected state + HRPS_BUSY, + + /// Number of defined states. + HRPS_STATE_MAX, +}; + +/// Attributes State Machine +enum +{ + HRS_IDX_SVC, + + HRS_IDX_HR_MEAS_CHAR, + HRS_IDX_HR_MEAS_VAL, + HRS_IDX_HR_MEAS_NTF_CFG, + + HRS_IDX_BODY_SENSOR_LOC_CHAR, + HRS_IDX_BODY_SENSOR_LOC_VAL, + + HRS_IDX_HR_CTNL_PT_CHAR, + HRS_IDX_HR_CTNL_PT_VAL, + + HRS_IDX_NB, +}; + +enum +{ + HRPS_HR_MEAS_CHAR, + HRPS_BODY_SENSOR_LOC_CHAR, + HRPS_HR_CTNL_PT_CHAR, + + HRPS_CHAR_MAX, +}; + +/// Feature bit field +enum hrps_feat_bf +{ + /// Body Sensor Location Feature Supported + HRPS_BODY_SENSOR_LOC_CHAR_SUP_POS = 0, + HRPS_BODY_SENSOR_LOC_CHAR_SUP_BIT = CO_BIT(HRPS_BODY_SENSOR_LOC_CHAR_SUP_POS), + + /// Energy Expanded Feature Supported + HRPS_ENGY_EXP_FEAT_SUP_POS = 1, + HRPS_ENGY_EXP_FEAT_SUP_BIT = CO_BIT(HRPS_ENGY_EXP_FEAT_SUP_POS), + + /// Heart Rate Measurement Notification Supported + HRPS_HR_MEAS_NTF_CFG_POS = 2, + HRPS_HR_MEAS_NTF_CFG_BIT = CO_BIT(HRPS_HR_MEAS_NTF_CFG_POS), +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// ongoing operation information +struct hrps_op +{ + /// Cursor on connection + uint8_t cursor; + /// Packed notification/indication data size + uint8_t length; + /// Packed notification/indication data + uint8_t data[HRPS_HT_MEAS_MAX_LEN]; +}; + +/// Heart Rate Profile Sensor environment variable +struct hrps_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Operation pointer used to generate notifications + struct hrps_op *p_operation; + ///Service Start Handle + uint16_t shdl; + ///Database configuration + uint8_t features; + /// Sensor location + uint8_t sensor_location; + /// Measurement notification config + uint16_t hr_meas_ntf[BLE_CONNECTION_MAX]; + + /// State of different task instances + ke_state_t state[HRPS_IDX_MAX]; +}; + + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve HRP service profile interface + * + * @return HRP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* hrps_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send a HRPS_CMP_EVT message to the application. + * + * @param[in] p_hrps_env HRP Sensor environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + ***************************************************************************************** + */ +void hrps_send_cmp_evt(struct hrps_env_tag *p_hrps_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/** + **************************************************************************************** + * @brief Pack Heart Rate measurement value + * + * @param[out] p_packed_hr Pointer to Heart Rate measurement structure destinationHeart Rate measurement value + * @param[in] p_meas_val Heart Rate measurement. Pointer of the packed data of Heart + * Rate Measurement + * information + **************************************************************************************** + */ +uint8_t hrps_pack_meas_value(uint8_t *p_packed_hr, const struct hrs_hr_meas *p_meas_val); + +/** + **************************************************************************************** + * @brief This function fully manage notification of Heart Rate Measurement + * to peer(s) device(s) according to on-going operation requested by application + * + * @param[in] conidx Connection index + **************************************************************************************** + */ +void hrps_exe_operation(uint8_t conidx); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * Initialize task handler + * + * @param task_desc Task descriptor to fill + **************************************************************************************** + */ +void hrps_task_init(struct ke_task_desc *p_task_desc); + +#endif /* #if (BLE_HR_SENSOR) */ + +/// @} HRPS + +#endif /* _HRPS_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps_task.c new file mode 100644 index 0000000..d54f29d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps_task.c @@ -0,0 +1,368 @@ +/** + **************************************************************************************** + * + * @file hrps_task.c + * + * @brief Heart Rate Profile Sensor Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup HRPSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_HR_SENSOR) +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "hrps.h" +#include "hrps_task.h" + +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HRPS_ENABLE_REQ message. + * The handler enables the Heart Rate Sensor Profile. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int hrps_enable_req_handler(ke_msg_id_t const msgid, + struct hrps_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct hrps_enable_rsp *p_cmp_evt; + + if (ke_state_get(dest_id) == HRPS_IDLE) + { + if ((p_param->conidx < BLE_CONNECTION_MAX) && + (p_param->hr_meas_ntf <= PRF_CLI_START_NTF)) + { + // Get the address of the environment + struct hrps_env_tag *p_hrps_env = PRF_ENV_GET(HRPS, hrps); + + // Bonded data was not used before + if (!HRPS_IS_SUPPORTED(p_hrps_env->hr_meas_ntf[p_param->conidx], HRP_PRF_CFG_PERFORMED_OK)) + { + // Save notification config + p_hrps_env->hr_meas_ntf[p_param->conidx] = p_param->hr_meas_ntf; + // Enable Bonded Data + p_hrps_env->hr_meas_ntf[p_param->conidx] |= HRP_PRF_CFG_PERFORMED_OK; + status = GAP_ERR_NO_ERROR; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(HRPS_ENABLE_RSP, src_id, dest_id, hrps_enable_rsp); + p_cmp_evt->status = status; + p_cmp_evt->conidx = p_param->conidx; + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HRPS_MEAS_SEND_CMD message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int hrps_meas_send_cmd_handler(ke_msg_id_t const msgid, + struct hrps_meas_send_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + uint8_t msg_status = KE_MSG_CONSUMED; + + // State shall not be Connected or Busy + if (ke_state_get(dest_id) == HRPS_IDLE) + { + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct hrps_env_tag *p_hrps_env = PRF_ENV_GET(HRPS, hrps); + + if (p_param->meas_val.nb_rr_interval <= HRS_MAX_RR_INTERVAL) + { + // allocate and prepare data to notify + p_hrps_env->p_operation = (struct hrps_op *) ke_malloc(sizeof(struct hrps_op), KE_MEM_KE_MSG); + p_hrps_env->p_operation->length = hrps_pack_meas_value(p_hrps_env->p_operation->data, &p_param->meas_val); + p_hrps_env->p_operation->cursor = 0; + + // start operation execution + hrps_exe_operation(conidx); + + // Go to busy state + ke_state_set(dest_id, HRPS_BUSY); + } + else + { + // Send confirmation + hrps_send_cmp_evt(p_hrps_env, conidx, HRPS_MEAS_SEND_CMD_OP_CODE, PRF_ERR_INVALID_PARAM); + } + } + else + { + // Save it for later + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GL2C_CODE_ATT_WR_CMD_IND message. + * The handler compares the new values with current ones and notifies them if they changed. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct hrps_env_tag *p_hrps_env = PRF_ENV_GET(HRPS, hrps); + struct gattc_write_cfm *p_cfm; + uint8_t status = GAP_ERR_NO_ERROR; + + if (p_hrps_env != NULL) + { + uint8_t conidx = KE_IDX_GET(src_id); + uint16_t value = 0x0000; + + // BP Measurement Char. - Client Char. Configuration + if (p_param->handle == (p_hrps_env->shdl + HRS_IDX_HR_MEAS_NTF_CFG)) + { + // Extract value before check + memcpy(&value, &(p_param->value), sizeof(uint16_t)); + + if ((value == PRF_CLI_STOP_NTFIND) || (value == PRF_CLI_START_NTF)) + { + p_hrps_env->hr_meas_ntf[conidx] = value | HRP_PRF_CFG_PERFORMED_OK; + } + else + { + status = PRF_APP_ERROR; + } + + if (status == GAP_ERR_NO_ERROR) + { + // Inform APP of configuration change + struct hrps_cfg_indntf_ind *p_ind = KE_MSG_ALLOC(HRPS_CFG_INDNTF_IND, + prf_dst_task_get(&p_hrps_env->prf_env, conidx), + prf_src_task_get(&p_hrps_env->prf_env, conidx), + hrps_cfg_indntf_ind); + + p_ind->conidx = conidx; + p_ind->cfg_val = value; + + ke_msg_send(p_ind); + } + } + // HR Control Point Char. Value + else + { + if (GETB(p_hrps_env->features, HRPS_ENGY_EXP_FEAT_SUP)) + { + // Extract value + memcpy(&value, &(p_param->value), sizeof(uint8_t)); + + if (value == 0x1) + { + // inform APP of configuration change + struct hrps_energy_exp_reset_ind *p_ind = KE_MSG_ALLOC(HRPS_ENERGY_EXP_RESET_IND, + prf_dst_task_get(&p_hrps_env->prf_env, conidx), + prf_src_task_get(&p_hrps_env->prf_env, conidx), + hrps_energy_exp_reset_ind); + + p_ind->conidx = conidx; + ke_msg_send(p_ind); + } + else + { + status = HRS_ERR_HR_CNTL_POINT_NOT_SUPPORTED; + } + } + else + { + // Allowed to send Application Error if value inconvenient + status = HRS_ERR_HR_CNTL_POINT_NOT_SUPPORTED; + } + } + } + + // Send write response + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT for GATTC_NOTIFY message meaning that Measurement + * notification has been correctly sent to peer device (but not confirmed by peer device). + * * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + if ((ke_state_get(dest_id) == HRPS_BUSY) && (p_param->operation == GATTC_NOTIFY)) + { + // continue operation execution + hrps_exe_operation(KE_IDX_GET(src_id)); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == HRPS_IDLE) + { + // Get the address of the environment + struct hrps_env_tag *p_hrps_env = PRF_ENV_GET(HRPS, hrps); + + uint8_t value[4]; + uint8_t value_size = 0; + uint8_t status = ATT_ERR_NO_ERROR; + struct gattc_read_cfm *p_cfm; + + switch (p_param->handle - p_hrps_env->shdl) + { + case HRS_IDX_HR_MEAS_NTF_CFG: + { + value_size = sizeof(uint16_t); + co_write16p(value, p_hrps_env->hr_meas_ntf[KE_IDX_GET(src_id)] & ~HRP_PRF_CFG_PERFORMED_OK); + } break; + + case HRS_IDX_BODY_SENSOR_LOC_VAL: + { + // Broadcast feature is profile specific + if (GETB(p_hrps_env->features, HRPS_BODY_SENSOR_LOC_CHAR_SUP)) + { + // Fill data + value_size = sizeof(uint8_t); + value[0] = p_hrps_env->sensor_location; + } + else + { + status = ATT_ERR_ATTRIBUTE_NOT_FOUND; + } + } break; + + default: + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + // Send data to peer device + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, value_size); + p_cfm->length = value_size; + memcpy(p_cfm->value, value, value_size); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* Default State handlers definition. */ +KE_MSG_HANDLER_TAB(hrps) +{ + {HRPS_ENABLE_REQ, (ke_msg_func_t) hrps_enable_req_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {HRPS_MEAS_SEND_CMD, (ke_msg_func_t) hrps_meas_send_cmd_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, +}; + +void hrps_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct hrps_env_tag *p_hrps_env = PRF_ENV_GET(HRPS, hrps); + + p_task_desc->msg_handler_tab = hrps_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(hrps_msg_handler_tab); + p_task_desc->state = p_hrps_env->state; + p_task_desc->idx_max = HRPS_IDX_MAX; +} + +#endif /* #if (BLE_HR_SENSOR) */ + +/// @} HRPSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htp_common.h new file mode 100644 index 0000000..efa73a3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htp_common.h @@ -0,0 +1,116 @@ +/** + **************************************************************************************** + * + * @file htp_common.h + * + * @brief Header File - Health Thermometer Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _HTP_COMMON_H_ +#define _HTP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup HTP Health Thermometer Profile + * @ingroup PROFILE + * @brief Health Thermometer Profile + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "prf_types.h" +#include "co_math.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Out of range error code. +#define HTP_OUT_OF_RANGE_ERR_CODE (0x80) + +/// Temperature Measurement Flags field bit values +enum htp_temp_flag_bf +{ + /// Temperature Units Flag (bit 0) + /// 0 for Celsius + /// 1 for Fahrenheit + HTP_FLAG_UNIT_POS = 0, + HTP_FLAG_UNIT_BIT = CO_BIT(HTP_FLAG_UNIT_POS), + + /// Time Stamp Flag + /// 0 for not present + /// 1 for present + HTP_FLAG_TIME_POS = 1, + HTP_FLAG_TIME_BIT = CO_BIT(HTP_FLAG_TIME_POS), + + /// Temperature Type Flag + /// 0 for not present + /// 1 for present + HTP_FLAG_TYPE_POS = 2, + HTP_FLAG_TYPE_BIT = CO_BIT(HTP_FLAG_TYPE_POS), +}; + +/// Temperature Type Description +enum htp_temp_type +{ + /// Armpit + HTP_TYPE_ARMPIT = 0x01, + /// Body (general) + HTP_TYPE_BODY = 0x02, + /// Ear (usually ear lobe) + HTP_TYPE_EAR = 0x03, + /// Finger + HTP_TYPE_FINGER = 0x04, + /// Gastro-intestinal Tract + HTP_TYPE_GASTRO_INTESTINAL_TRACT = 0x05, + /// Mouth + HTP_TYPE_MOUTH = 0x06, + /// Rectum + HTP_TYPE_RECTUM = 0x07, + /// Toe + HTP_TYPE_TOE = 0x08, + /// Tympanum (ear drum) + HTP_TYPE_TYMPANUM = 0x09, +}; + +/// Temperature type: intermediary/stable +enum htp_temp_info +{ + /// intermediate temperature measurement + HTP_TEMP_INTERM = (0x00), + /// stable temperature measurement + HTP_TEMP_STABLE = (0x01), +}; + /* + * STRUCTURES + **************************************************************************************** + */ + +///Temperature Measurement Value Structure +struct htp_temp_meas +{ + /// Temperature value + uint32_t temp; + /// Time stamp + struct prf_date_time time_stamp; + /// Flag (@see enum htp_temp_flag) + uint8_t flags; + /// Type (@see enum htp_temp_type) + uint8_t type; +}; + + +/// @} htp_common + +#endif /* _HTP_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/api/htpc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/api/htpc_task.h new file mode 100644 index 0000000..9eec080 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/api/htpc_task.h @@ -0,0 +1,223 @@ +/** + **************************************************************************************** + * + * @file htpc_task.h + * + * @brief Header file - HTPCTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef HTPC_TASK_H_ +#define HTPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup HTPCTASK Health Thermometer Profile Collector Task + * @ingroup HTPC + * @brief Health Thermometer Profile Collector Task + * + * The HTPCTASK is responsible for handling the messages coming in and out of the + * @ref HTPC monitor block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "htp_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Message id +/*@TRACE*/ +enum htpc_msg_id +{ + /// Start the Health Thermometer Collector profile - at connection + HTPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_HTPC), + /// Confirm that cfg connection has finished with discovery results, or that normal cnx started + HTPC_ENABLE_RSP, + + /// Write Health Thermometer Notification Configuration Value request + HTPC_HEALTH_TEMP_NTF_CFG_REQ, + /// Write Health Thermometer Notification Configuration Value response + HTPC_HEALTH_TEMP_NTF_CFG_RSP, + + /// APP request for measurement interval write + HTPC_WR_MEAS_INTV_REQ, + /// APP request for measurement interval write + HTPC_WR_MEAS_INTV_RSP, + + /// Temperature value received from peer sensor + HTPC_TEMP_IND, + /// Measurement interval update indication received from peer sensor + HTPC_MEAS_INTV_IND, + + /// Generic message to read a HTP characteristic value + HTPC_RD_CHAR_REQ, + /// Read HTP characteristic value response + HTPC_RD_CHAR_RSP, +}; + +/// Health Thermometer Service Characteristics - Char. Code +enum htpc_chars +{ + /// Temperature Measurement + HTPC_CHAR_HTS_TEMP_MEAS = 0x0, + /// Temperature Type + HTPC_CHAR_HTS_TEMP_TYPE, + /// Intermediate Temperature + HTPC_CHAR_HTS_INTM_TEMP, + /// Measurement Interval + HTPC_CHAR_HTS_MEAS_INTV, + + HTPC_CHAR_HTS_MAX, +}; + +/// Health Thermometer Service Characteristic Descriptors +enum htpc_descs +{ + /// Temp. Meas. Client Config + HTPC_DESC_HTS_TEMP_MEAS_CLI_CFG, + /// Intm. Meas. Client Config + HTPC_DESC_HTS_INTM_MEAS_CLI_CFG, + /// Meas. Intv. Client Config + HTPC_DESC_HTS_MEAS_INTV_CLI_CFG, + /// Meas. Intv. Valid Range, + HTPC_DESC_HTS_MEAS_INTV_VAL_RGE, + + HTPC_DESC_HTS_MAX, +}; + +/// Internal codes for reading a HTS characteristic with one single request +enum htpc_rd_char +{ + /// Read HTS Temp. Type + HTPC_RD_TEMP_TYPE = 0, + /// Read HTS Measurement Interval + HTPC_RD_MEAS_INTV, + + /// Read HTS Temperature Measurement Client Cfg. Desc + HTPC_RD_TEMP_MEAS_CLI_CFG, + /// Read HTS Intermediate Temperature Client Cfg. Desc + HTPC_RD_INTM_TEMP_CLI_CFG, + /// Read HTS Measurement Interval Client Cfg. Desc + HTPC_RD_MEAS_INTV_CLI_CFG, + /// Read HTS Measurement Interval Client Cfg. Desc + HTPC_RD_MEAS_INTV_VAL_RGE, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Health Thermometer Service + */ +struct htpc_hts_content +{ + /// service info + struct prf_svc svc; + + /// Characteristic info: + struct prf_char_inf chars[HTPC_CHAR_HTS_MAX]; + + /// Descriptor handles: + struct prf_char_desc_inf descs[HTPC_DESC_HTS_MAX]; +}; + +/// Parameters of the @ref HTPC_ENABLE_REQ message +struct htpc_enable_req +{ + /// Connection type + uint8_t con_type; + + /// HTS existing handle values + struct htpc_hts_content hts; +}; + +/// Parameters of the @ref HTPC_ENABLE_RSP message +struct htpc_enable_rsp +{ + /// Status + uint8_t status; + /// HTS handle values and characteristic properties + struct htpc_hts_content hts; +}; + +/// Parameters of the @ref HTPC_HEALTH_TEMP_NTF_CFG_REQ message +struct htpc_health_temp_ntf_cfg_req +{ + /// Stop/notify/indicate value to configure into the peer characteristic + uint16_t cfg_val; + /// Own code for differentiating between Temperature Measurement, + /// Intermediate Temperature and Measurement Interval chars + uint8_t char_code; +}; + +/// Parameters of the @ref HTPC_HEALTH_TEMP_NTF_CFG_RSP message +struct htpc_health_temp_ntf_cfg_rsp +{ + /// Status + uint8_t status; +}; + +/// Parameters of the @ref HTPC_WR_MEAS_INTV_REQ message +struct htpc_wr_meas_intv_req +{ + /// Interval value + uint16_t intv; +}; + +/// Parameters of the @ref HTPC_WR_MEAS_INTV_RSP message +struct htpc_wr_meas_intv_rsp +{ + /// Status + uint8_t status; +}; + +/// Parameters of the @ref HTPC_TEMP_IND message +struct htpc_temp_ind +{ + /// Temperature Measurement Structure + struct htp_temp_meas temp_meas; + /// Stable or intermediary type of temperature + bool stable_meas; +}; + +/// Parameters of @ref HTPC_MEAS_INTV_IND message +struct htpc_meas_intv_ind +{ + /// Interval + uint16_t intv; +}; + +/// Parameters of the @ref HTPC_RD_CHAR_REQ message +struct htpc_rd_char_req +{ + /// Characteristic value code (@see enum htpc_rd_char) + uint8_t char_code; +}; + +/// Parameters of the @ref HTPC_RD_CHAR_RSP message +struct htpc_rd_char_rsp +{ + /// Attribute data information + struct prf_att_info info; +}; +/// @} HTPCTASK + +#endif // HTPC_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/sourcelist.txt new file mode 100644 index 0000000..ea00edc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + htpc.c + htpc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/src/htpc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/src/htpc.c new file mode 100644 index 0000000..fd20611 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/src/htpc.c @@ -0,0 +1,271 @@ +/** + **************************************************************************************** + * + * @file htpc.c + * + * @brief Health Thermometer Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HTPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_HT_COLLECTOR) +#include "htpc.h" +#include "htpc_task.h" +#include "gap.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the HTPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t htpc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct htpc_env_tag *p_htpc_env = + (struct htpc_env_tag *) ke_malloc(sizeof(struct htpc_env_tag), KE_MEM_ATT_DB); + + // allocate HTPC required environment variable + p_env->env = (prf_env_t *) p_htpc_env; + + p_htpc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_htpc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_HTPC; + htpc_task_init(&(p_env->desc)); + + for (idx = 0; idx < HTPC_IDX_MAX; idx++) + { + p_htpc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), HTPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Destruction of the HTPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void htpc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct htpc_env_tag *p_htpc_env = (struct htpc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < HTPC_IDX_MAX; idx++) + { + if (p_htpc_env->p_env[idx] != NULL) + { + if (p_htpc_env->p_env[idx]->p_operation != NULL) + { + ke_msg_free(p_htpc_env->p_env[idx]->p_operation); + } + + ke_free(p_htpc_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_htpc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void htpc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put HTP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), HTPC_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void htpc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct htpc_env_tag *p_htpc_env = (struct htpc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_htpc_env->p_env[conidx] != NULL) + { + if (p_htpc_env->p_env[conidx]->p_operation != NULL) + { + ke_msg_free(p_htpc_env->p_env[conidx]->p_operation); + } + + ke_free(p_htpc_env->p_env[conidx]); + p_htpc_env->p_env[conidx] = NULL; + } + + // Put HTP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), HTPC_FREE); +} + +void htpc_unpack_temp(struct htpc_env_tag *p_htpc_env, uint8_t *p_packed_temp, + uint8_t length, uint8_t flag_stable_meas, uint8_t conidx) +{ + // Cursor used to read parameter in the packed temperature value + uint8_t cursor = 0; + + // Checked the length of the received value + if (length >= HTPC_PACKED_TEMP_MIN_LEN) + { + // Prepare the message to send to the application + struct htpc_temp_ind *p_ind = KE_MSG_ALLOC(HTPC_TEMP_IND, + prf_dst_task_get(&p_htpc_env->prf_env, conidx), + prf_src_task_get(&p_htpc_env->prf_env, conidx), + htpc_temp_ind); + + // Unpack Temp Measurement + p_ind->temp_meas.flags = *(p_packed_temp + cursor); + cursor += 1; + + p_ind->temp_meas.temp = co_read32p(p_packed_temp + cursor); + cursor += 4; + + // Time Flag Set + if (GETB(p_ind->temp_meas.flags, HTP_FLAG_TIME)) + { + cursor += prf_unpack_date_time(p_packed_temp + cursor, &(p_ind->temp_meas.time_stamp)); + } + + // Type Flag set + if (GETB(p_ind->temp_meas.flags, HTP_FLAG_TYPE)) + { + p_ind->temp_meas.type = *(p_packed_temp + cursor); + } + + // Stable or intermediary type of temperature + p_ind->stable_meas = flag_stable_meas; + + //Send request to ATT + ke_msg_send(p_ind); + } +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// HTPC Task interface required by profile manager +const struct prf_task_cbs htpc_itf = +{ + (prf_init_fnct) htpc_init, + htpc_destroy, + htpc_create, + htpc_cleanup, +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *htpc_prf_itf_get(void) +{ + return &htpc_itf; +} + +void htpc_enable_rsp_send(struct htpc_env_tag *p_htpc_env, uint8_t conidx, uint8_t status) +{ + // Inform the APP about the status of the enabling of the Health Thermometer Profile Collector role + struct htpc_enable_rsp *p_cfm = KE_MSG_ALLOC(HTPC_ENABLE_RSP, + prf_dst_task_get(&(p_htpc_env->prf_env), conidx), + prf_src_task_get(&(p_htpc_env->prf_env), conidx), + htpc_enable_rsp); + + // Status + p_cfm->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_cfm->hts = p_htpc_env->p_env[conidx]->hts; + // Go to IDLE state + ke_state_set(prf_src_task_get(&(p_htpc_env->prf_env), conidx), HTPC_IDLE); + + // Register profile handle to catch gatt indications + prf_register_atthdl2gatt(&(p_htpc_env->prf_env), conidx, &p_htpc_env->p_env[conidx]->hts.svc); + } + else + { + if (p_htpc_env->p_env[conidx] != NULL) + { + // clean-up environment variable allocated for task instance + if (p_htpc_env->p_env[conidx]->p_operation != NULL) + { + ke_free(p_htpc_env->p_env[conidx]->p_operation); + } + ke_free(p_htpc_env->p_env[conidx]); + p_htpc_env->p_env[conidx] = NULL; + } + } + + // Send the confirmation to the application + ke_msg_send(p_cfm); +} + +#endif //BLE_HT_COLLECTOR +/// @} HTPC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/src/htpc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/src/htpc.h new file mode 100644 index 0000000..9bec1f3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/src/htpc.h @@ -0,0 +1,191 @@ +/** + **************************************************************************************** + * + * @file htpc.h + * + * @brief Header file - Health Thermometer Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef HTPC_H_ +#define HTPC_H_ + +/** + **************************************************************************************** + * @addtogroup HTP Health Thermometer Profile + * @ingroup PROFILE + * @brief Health Thermometer Profile + * + * The HTP module is the responsible block for implementing the Health Thermometer Profile + * functionalities in the BLE Host. + * + * The Health Thermometer Profile defines the functionality required in a device that allows + * the user (Collector device) to configure and recover temperature measurements from a Thermometer device. + ***************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HTPC Health Thermometer Profile Collector + * @ingroup HTP + * @brief Health Thermometer Profile Collector + * + * The HTPC is responsible for providing Health Thermometer Profile Collector functionalities to + * upper layer module or application. The device using this profile takes the role + * of Health Thermometer Profile Collector. + * + * Health Thermometer Profile Collector (HTPC): A HTPC (e.g. PC, phone, etc) + * is the term used by this profile to describe a device that can set temperature + * indication/notification intervals in a HTP Thermometer, interpreting them in a way + * suitable to the user application. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_HT_COLLECTOR || BLE_HT_THERMOM) +#include "ke_task.h" +#include "prf_utils.h" +#include "htpc_task.h" +#include "htp_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + +#define HTPC_PACKED_TEMP_MIN_LEN (5) +#define HTPC_PACKED_TEMP_MAX_LEN (13) + +/// Maximum number of task instances +#define HTPC_IDX_MAX (BLE_CONNECTION_MAX) + +/// Possible states of the HTPC task +enum htpc_state +{ + ///Free state + HTPC_FREE, + ///Idle state + HTPC_IDLE, + ///Busy state + HTPC_BUSY, + + ///Number of defined states. + HTPC_STATE_MAX +}; + +/* + * MACROS + **************************************************************************************** + */ + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Health Temperature Collector environment variable per connection +struct htpc_cnx_env +{ + /// Last service for which something was discovered + uint8_t last_svc_req; + /// counter used to check service uniqueness + uint8_t nb_svc; + /// used to store if measurement context + uint8_t meas_ctx_en; + /// context of request + struct ke_msg *p_operation; + /// HTS handle values + struct htpc_hts_content hts; +}; + +/// Health Thermometer Profile Client environment variable +struct htpc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct htpc_cnx_env *p_env[HTPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[HTPC_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve HTS service profile interface + * + * @return HTS service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *htpc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Thermometer ATT DB discovery results to HTPC host. + * + * @param p_htpc_env Health Thermometer Profile Client Role task environment + * @param conidx Connection index + * @param status Response status code + **************************************************************************************** + */ +void htpc_enable_rsp_send(struct htpc_env_tag *p_htpc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Unpack the received temperature measurement value + * + * @param p_htpc_env Health Thermometer Profile Client Role task environment + * @param p_packed_temp Packed temperature value + * @param length Length of received value + * @param flag_stable_meas Stable or intermediary type of temperature + * @param conidx Connection index + **************************************************************************************** + */ +void htpc_unpack_temp(struct htpc_env_tag *p_htpc_env, uint8_t *p_packed_temp, + uint8_t length, uint8_t flag_stable_meas, uint8_t conidx); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void htpc_task_init(struct ke_task_desc *p_task_desc); + + +#endif //BLE_HT_COLLECTOR +/// @} HTPC +#endif // HTPC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/src/htpc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/src/htpc_task.c new file mode 100644 index 0000000..dd3a519 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpc/src/htpc_task.c @@ -0,0 +1,657 @@ +/** + **************************************************************************************** + * + * @file htpc_task.c + * + * @brief Health Thermometer Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HTPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_HT_COLLECTOR) +#include "co_utils.h" +#include "gap.h" +#include "attm.h" +#include "htpc_task.h" +#include "htpc.h" +#include "gapc.h" +#include "gapc_task.h" + +#include "ke_mem.h" + +/// State machine used to retrieve Health Thermometer service characteristics information +const struct prf_char_def htpc_hts_char[HTPC_CHAR_HTS_MAX] = +{ + /// Temperature Measurement + [HTPC_CHAR_HTS_TEMP_MEAS] = {ATT_CHAR_TEMPERATURE_MEAS, ATT_MANDATORY, ATT_CHAR_PROP_IND}, + /// Temperature Type + [HTPC_CHAR_HTS_TEMP_TYPE] = {ATT_CHAR_TEMPERATURE_TYPE, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, + /// Intermediate Temperature + [HTPC_CHAR_HTS_INTM_TEMP] = {ATT_CHAR_INTERMED_TEMPERATURE, ATT_OPTIONAL, ATT_CHAR_PROP_NTF}, + /// Measurement Interval + [HTPC_CHAR_HTS_MEAS_INTV] = {ATT_CHAR_MEAS_INTERVAL, ATT_OPTIONAL, ATT_CHAR_PROP_RD}, +}; + +/// State machine used to retrieve Health Thermometer service characteristics description information +const struct prf_char_desc_def htpc_hts_char_desc[HTPC_DESC_HTS_MAX] = +{ + /// Temperature Measurement Client Config + [HTPC_DESC_HTS_TEMP_MEAS_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, HTPC_CHAR_HTS_TEMP_MEAS}, + /// Intermediate Temperature Client Config + [HTPC_DESC_HTS_INTM_MEAS_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_OPTIONAL, HTPC_CHAR_HTS_INTM_TEMP}, + /// Measurement Interval Client Config + [HTPC_DESC_HTS_MEAS_INTV_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_OPTIONAL, HTPC_CHAR_HTS_MEAS_INTV}, + /// Measurement Interval valid range + [HTPC_DESC_HTS_MEAS_INTV_VAL_RGE] = {ATT_DESC_VALID_RANGE, ATT_OPTIONAL, HTPC_CHAR_HTS_MEAS_INTV}, +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HTPC_ENABLE_REQ message. + * The handler enables the Health Thermometer Profile Collector Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int htpc_enable_req_handler(ke_msg_id_t const msgid, + struct htpc_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t conidx = KE_IDX_GET(dest_id); + // Health Thermometer Profile Collector Role Task Environment + struct htpc_env_tag *p_htpc_env = PRF_ENV_GET(HTPC, htpc); + + if ((ke_state_get(dest_id) == HTPC_IDLE) && (p_htpc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_htpc_env->p_env[conidx] = (struct htpc_cnx_env *) ke_malloc(sizeof(struct htpc_cnx_env), KE_MEM_ATT_DB); + memset(p_htpc_env->p_env[conidx], 0, sizeof(struct htpc_cnx_env)); + + // Config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + //start discovering HTS on peer + prf_disc_svc_send(&(p_htpc_env->prf_env), conidx, ATT_SVC_HEALTH_THERMOM); + + // store context of request and go into busy state + p_htpc_env->p_env[conidx]->p_operation = ke_param2msg(p_param); + msg_status = KE_MSG_NO_FREE; + ke_state_set(dest_id, HTPC_BUSY); + } + // normal connection, get saved att details + else + { + p_htpc_env->p_env[conidx]->hts = p_param->hts; + + //send APP confirmation that can start normal connection to TH + htpc_enable_rsp_send(p_htpc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + htpc_enable_rsp_send(p_htpc_env, conidx, status); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == HTPC_BUSY) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct htpc_env_tag *p_htpc_env = PRF_ENV_GET(HTPC, htpc); + + ASSERT_INFO(p_htpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_htpc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_htpc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve IAS characteristic + prf_extract_svc_info(p_ind, HTPC_CHAR_HTS_MAX, &htpc_hts_char[0], + p_htpc_env->p_env[conidx]->hts.chars, + HTPC_DESC_HTS_MAX, + &htpc_hts_char_desc[0], + &(p_htpc_env->p_env[conidx]->hts.descs[0]) ); + + // Even if we get multiple responses we only store 1 range + p_htpc_env->p_env[conidx]->hts.svc.shdl = p_ind->start_hdl; + p_htpc_env->p_env[conidx]->hts.svc.ehdl = p_ind->end_hdl; + } + + p_htpc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HTPC_WR_MEAS_INTV_REQ message. + * Check if the handle exists in profile(already discovered) and send request, otherwise + * error to APP. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int htpc_wr_meas_intv_req_handler(ke_msg_id_t const msgid, + struct htpc_wr_meas_intv_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Device Information Service Client Role Task Environment + struct htpc_env_tag *p_htpc_env = PRF_ENV_GET(HTPC, htpc); + + ASSERT_INFO(p_htpc_env != NULL, dest_id, src_id); + + if ((state == HTPC_IDLE) && (p_htpc_env->p_env[conidx] != NULL)) + { + uint16_t val_hdl = ATT_INVALID_HANDLE; + + if ((p_htpc_env->p_env[conidx]->hts.chars[HTPC_CHAR_HTS_MEAS_INTV].prop & ATT_CHAR_PROP_WR) + != ATT_CHAR_PROP_WR) + { + status = PRF_ERR_NOT_WRITABLE; + } + else + { + val_hdl = p_htpc_env->p_env[conidx]->hts.chars[HTPC_CHAR_HTS_MEAS_INTV].val_hdl; + + if (val_hdl != ATT_INVALID_HANDLE) + { + // Send GATT Write Request + prf_gatt_write(&(p_htpc_env->prf_env), conidx, val_hdl, + (uint8_t *)&p_param->intv, sizeof(uint16_t), GATTC_WRITE); + + // store context of request and go into busy state + p_htpc_env->p_env[conidx]->p_operation = ke_param2msg(p_param); + msg_status = KE_MSG_NO_FREE; + ke_state_set(dest_id, HTPC_BUSY); + } + else + { + // invalid handle requested + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state != HTPC_FREE) + { + // request cannot be performed + status = PRF_ERR_REQ_DISALLOWED; + } + + // send error response if request fails + if (status != GAP_ERR_NO_ERROR) + { + struct htpc_wr_meas_intv_rsp *p_rsp = KE_MSG_ALLOC(HTPC_WR_MEAS_INTV_RSP, src_id, + dest_id, htpc_wr_meas_intv_rsp); + + p_rsp->status = status; + ke_msg_send(p_rsp); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HTPC_HEALTH_TEMP_NTF_CFG_REQ message. + * It allows configuration of the peer ind/ntf/stop characteristic for a specified characteristic. + * Will return an error code if that cfg char does not exist. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int htpc_health_temp_ntf_cfg_req_handler(ke_msg_id_t const msgid, + struct htpc_health_temp_ntf_cfg_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Client Characteristic Configuration Descriptor Handle + uint16_t cfg_hdl = 0x0000; + uint8_t status = GAP_ERR_NO_ERROR; + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct htpc_env_tag *p_htpc_env = PRF_ENV_GET(HTPC, htpc); + uint8_t conidx = KE_IDX_GET(dest_id); + + switch(p_param->char_code) + { + case HTPC_CHAR_HTS_TEMP_MEAS: //can only IND + { + cfg_hdl = p_htpc_env->p_env[conidx]->hts.descs[HTPC_DESC_HTS_TEMP_MEAS_CLI_CFG].desc_hdl; + if (!((p_param->cfg_val == PRF_CLI_STOP_NTFIND)|| + (p_param->cfg_val == PRF_CLI_START_IND))) + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + case HTPC_CHAR_HTS_MEAS_INTV: //can only IND + { + cfg_hdl = p_htpc_env->p_env[conidx]->hts.descs[HTPC_DESC_HTS_MEAS_INTV_CLI_CFG].desc_hdl; + if (!((p_param->cfg_val == PRF_CLI_STOP_NTFIND)|| + (p_param->cfg_val == PRF_CLI_START_IND))) + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + case HTPC_CHAR_HTS_INTM_TEMP: //can only NTF + { + cfg_hdl = p_htpc_env->p_env[conidx]->hts.descs[HTPC_DESC_HTS_INTM_MEAS_CLI_CFG].desc_hdl; + if (!((p_param->cfg_val == PRF_CLI_STOP_NTFIND)|| + (p_param->cfg_val == PRF_CLI_START_NTF))) + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + default: + { + //Let app know that one of the request p_params is incorrect + status = PRF_ERR_INVALID_PARAM; + } break; + } + + //Check if the handle value exists + if ((cfg_hdl == ATT_INVALID_HANDLE)) + { + status = PRF_ERR_INEXISTENT_HDL; + } + + // no error detected + if (status == GAP_ERR_NO_ERROR) + { + // Send GATT Write Request + prf_gatt_write_ntf_ind(&p_htpc_env->prf_env, conidx, cfg_hdl, p_param->cfg_val); + // store context of request and go into busy state + p_htpc_env->p_env[conidx]->p_operation = ke_param2msg(p_param); + ke_state_set(dest_id, HTPC_BUSY); + msg_status = KE_MSG_NO_FREE; + } + // an error occurs send back response message + else + { + struct htpc_health_temp_ntf_cfg_rsp *p_rsp = KE_MSG_ALLOC(HTPC_HEALTH_TEMP_NTF_CFG_RSP, + src_id, dest_id, + htpc_health_temp_ntf_cfg_rsp); + + p_rsp->status = status; + ke_msg_send(p_rsp); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HTPC_RD_REQ message. + * Check if the handle exists in profile(already discovered) and send request, otherwise + * error to APP. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int htpc_rd_char_req_handler(ke_msg_id_t const msgid, + struct htpc_rd_char_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Device Information Service Client Role Task Environment + struct htpc_env_tag *p_htpc_env = PRF_ENV_GET(HTPC, htpc); + + ASSERT_INFO(p_htpc_env != NULL, dest_id, src_id); + if ((state == HTPC_IDLE) && (p_htpc_env->p_env[conidx] != NULL)) + { + uint16_t search_hdl = ATT_INVALID_HDL; + + switch (p_param->char_code) + { + // Read HTS Temp. Type + case HTPC_RD_TEMP_TYPE: + { + search_hdl = p_htpc_env->p_env[conidx]->hts.chars[HTPC_CHAR_HTS_TEMP_TYPE].val_hdl; + } break; + // Read HTS Measurement Interval + case HTPC_RD_MEAS_INTV: + { + search_hdl = p_htpc_env->p_env[conidx]->hts.chars[HTPC_CHAR_HTS_MEAS_INTV].val_hdl; + } break; + // Read HTS Temperature Measurement Client Cfg. Desc + case HTPC_RD_TEMP_MEAS_CLI_CFG: + { + search_hdl = p_htpc_env->p_env[conidx]->hts.descs[HTPC_DESC_HTS_TEMP_MEAS_CLI_CFG].desc_hdl; + } break; + // Read HTS Intermediate Temperature Client Cfg. Desc + case HTPC_RD_INTM_TEMP_CLI_CFG: + { + search_hdl = p_htpc_env->p_env[conidx]->hts.descs[HTPC_DESC_HTS_INTM_MEAS_CLI_CFG].desc_hdl; + } break; + // Read HTS Measurement Interval Client Cfg. Desc + case HTPC_RD_MEAS_INTV_CLI_CFG: + { + search_hdl = p_htpc_env->p_env[conidx]->hts.descs[HTPC_DESC_HTS_MEAS_INTV_CLI_CFG].desc_hdl; + } break; + // Read HTS Measurement Interval Client Cfg. Desc + case HTPC_RD_MEAS_INTV_VAL_RGE: + { + search_hdl = p_htpc_env->p_env[conidx]->hts.descs[HTPC_DESC_HTS_MEAS_INTV_VAL_RGE].desc_hdl; + } break; + default: + { + status = GAP_ERR_INVALID_PARAM; + } break; + } + + //Check if handle is viable + if (search_hdl != ATT_INVALID_HDL) + { + // perform read request + prf_read_char_send(&(p_htpc_env->prf_env), conidx, p_htpc_env->p_env[conidx]->hts.svc.shdl, + p_htpc_env->p_env[conidx]->hts.svc.ehdl, search_hdl); + + // store context of request and go into busy state + p_htpc_env->p_env[conidx]->p_operation = ke_param2msg(p_param); + msg_status = KE_MSG_NO_FREE; + ke_state_set(dest_id, HTPC_BUSY); + } + else if (status == GAP_ERR_NO_ERROR) + { + // invalid handle requested + status = PRF_ERR_INEXISTENT_HDL; + } + } + else if (state != HTPC_FREE) + { + // request cannot be performed + status = PRF_ERR_REQ_DISALLOWED; + } + + // send error response if request fails + if (status != GAP_ERR_NO_ERROR) + { + prf_client_att_info_rsp(&(p_htpc_env->prf_env), conidx, HTPC_RD_CHAR_RSP, + status, NULL); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct htpc_env_tag *p_htpc_env = PRF_ENV_GET(HTPC, htpc); + uint8_t conidx = KE_IDX_GET(dest_id); + + // send attribute information + prf_client_att_info_rsp(&(p_htpc_env->prf_env), conidx, HTPC_RD_CHAR_RSP, GAP_ERR_NO_ERROR, p_param); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct htpc_env_tag *p_htpc_env = PRF_ENV_GET(HTPC, htpc); + + if (ke_state_get(dest_id) == HTPC_BUSY) + { + switch(p_htpc_env->p_env[conidx]->p_operation->id) + { + case HTPC_ENABLE_REQ: + { + uint8_t status; + + if (p_htpc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(HTPC_CHAR_HTS_MAX, + p_htpc_env->p_env[conidx]->hts.chars, htpc_hts_char); + + p_htpc_env->p_env[conidx]->nb_svc = 0; + } + // Too many services found only one such service should exist + else if (p_htpc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + htpc_enable_rsp_send(p_htpc_env, conidx, status); + } break; + + case HTPC_HEALTH_TEMP_NTF_CFG_REQ: + { + // send response of the notification configuration request + struct htpc_health_temp_ntf_cfg_rsp *p_rsp = KE_MSG_ALLOC(HTPC_HEALTH_TEMP_NTF_CFG_RSP, + prf_dst_task_get(&(p_htpc_env->prf_env), conidx), dest_id, htpc_health_temp_ntf_cfg_rsp); + + // set error status + p_rsp->status =p_param->status; + ke_msg_send(p_rsp); + } break; + + case HTPC_RD_CHAR_REQ: + { + if(p_param->status != GAP_ERR_NO_ERROR) + { + // send attribute information + prf_client_att_info_rsp(&(p_htpc_env->prf_env), conidx, HTPC_RD_CHAR_RSP, p_param->status, NULL); + } + } break; + + case HTPC_WR_MEAS_INTV_REQ: + { + struct htpc_wr_meas_intv_rsp *p_rsp = KE_MSG_ALLOC(HTPC_WR_MEAS_INTV_RSP, + prf_dst_task_get(&(p_htpc_env->prf_env), conidx), dest_id, htpc_wr_meas_intv_rsp); + + p_rsp->status = p_param->status; + ke_msg_send(p_rsp); + } break; + + default: break; + } + + //free operation + if ((p_htpc_env->p_env[conidx] != NULL) && (p_htpc_env->p_env[conidx]->p_operation != NULL)) + { + ke_free(p_htpc_env->p_env[conidx]->p_operation); + p_htpc_env->p_env[conidx]->p_operation = NULL; + } + // set state to IDLE + ke_state_set(dest_id, HTPC_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct htpc_env_tag *p_htpc_env = PRF_ENV_GET(HTPC, htpc); + uint8_t conidx = KE_IDX_GET(dest_id); + + // Temperature Measurement Char. + if (p_param->handle == p_htpc_env->p_env[conidx]->hts.chars[HTPC_CHAR_HTS_TEMP_MEAS].val_hdl) + { + // confirm that indication has been correctly received + struct gattc_event_cfm *p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + + htpc_unpack_temp(p_htpc_env, (uint8_t *)&(p_param->value), p_param->length, + ((p_param->type == GATTC_NOTIFY) ? HTP_TEMP_INTERM : HTP_TEMP_STABLE), conidx); + } + // Intermediate Temperature Measurement Char. + else if(p_param->handle == p_htpc_env->p_env[conidx]->hts.chars[HTPC_CHAR_HTS_INTM_TEMP].val_hdl) + { + htpc_unpack_temp(p_htpc_env, (uint8_t *)&(p_param->value), p_param->length, + ((p_param->type == GATTC_NOTIFY) ? HTP_TEMP_INTERM : HTP_TEMP_STABLE), conidx); + } + // Measurement Interval Char. + else if (p_param->handle == p_htpc_env->p_env[conidx]->hts.chars[HTPC_CHAR_HTS_MEAS_INTV].val_hdl) + { + // confirm that indication has been correctly received + struct gattc_event_cfm *p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + + struct htpc_meas_intv_ind *p_ind = KE_MSG_ALLOC(HTPC_MEAS_INTV_IND, + prf_dst_task_get(&p_htpc_env->prf_env, conidx), + prf_src_task_get(&p_htpc_env->prf_env, conidx), + htpc_meas_intv_ind); + + memcpy(&p_ind->intv, &p_param->value[0], sizeof(uint16_t)); + + ke_msg_send(p_ind); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* Default State handlers definition. */ +KE_MSG_HANDLER_TAB(htpc) +{ + {HTPC_ENABLE_REQ, (ke_msg_func_t) htpc_enable_req_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t) gattc_sdp_svc_ind_handler}, + {HTPC_HEALTH_TEMP_NTF_CFG_REQ, (ke_msg_func_t) htpc_health_temp_ntf_cfg_req_handler}, + {HTPC_WR_MEAS_INTV_REQ, (ke_msg_func_t) htpc_wr_meas_intv_req_handler}, + {HTPC_RD_CHAR_REQ, (ke_msg_func_t) htpc_rd_char_req_handler}, + {GATTC_READ_IND, (ke_msg_func_t) gattc_read_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t) gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t) gattc_event_ind_handler}, +}; + +void htpc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct htpc_env_tag *p_htpc_env = PRF_ENV_GET(HTPC, htpc); + + p_task_desc->msg_handler_tab = htpc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(htpc_msg_handler_tab); + p_task_desc->state = p_htpc_env->state; + p_task_desc->idx_max = HTPC_IDX_MAX; +} + +#endif //BLE_HT_COLLECTOR + +/// @} HTPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/api/htpt_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/api/htpt_task.h new file mode 100644 index 0000000..7d5e032 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/api/htpt_task.h @@ -0,0 +1,211 @@ +/** + **************************************************************************************** + * + * @file htpt_task.h + * + * @brief Header file - HTPTTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef HTPT_TASK_H_ +#define HTPT_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup HTPTTASK Task + * @ingroup HTPT + * @brief Health Thermometer Profile Thermometer Task + * + * The HTPTTASK is responsible for handling the messages coming in and out of the + * @ref HTPT reporter block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "htp_common.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// All Features supported +#define HTPT_ALL_FEAT_SUP 0x1F + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Messages for Health Thermometer Profile Thermometer +/*@TRACE*/ +enum htpt_msg_id +{ + /// Start the Health Thermometer Profile Thermometer profile - at connection + HTPT_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_HTPT), + /// Enable confirmation + HTPT_ENABLE_RSP, + + /// Send temperature value from APP + HTPT_TEMP_SEND_REQ, + /// Send temperature response + HTPT_TEMP_SEND_RSP, + + /// Indicate Measurement Interval + HTPT_MEAS_INTV_UPD_REQ, + /// Send Measurement Interval response + HTPT_MEAS_INTV_UPD_RSP, + + /// Inform APP of new measurement interval value requested by a peer device + HTPT_MEAS_INTV_CHG_REQ_IND, + /// APP Confirm message of new measurement interval value requested by a peer device + /// If accepted, it triggers indication on measurement interval attribute + HTPT_MEAS_INTV_CHG_CFM, + + /// Inform APP that Indication Configuration has been changed - use to update bond data + HTPT_CFG_INDNTF_IND, +}; + +/// Database Feature Configuration Flags +enum htpt_features_bf +{ + /// Indicate if Temperature Type Char. is supported + HTPT_TEMP_TYPE_CHAR_SUP_POS = 0, + HTPT_TEMP_TYPE_CHAR_SUP_BIT = CO_BIT(HTPT_TEMP_TYPE_CHAR_SUP_POS), + + /// Indicate if Intermediate Temperature Char. is supported + HTPT_INTERM_TEMP_CHAR_SUP_POS = 1, + HTPT_INTERM_TEMP_CHAR_SUP_BIT = CO_BIT(HTPT_INTERM_TEMP_CHAR_SUP_POS), + + /// Indicate if Measurement Interval Char. is supported + HTPT_MEAS_INTV_CHAR_SUP_POS = 2, + HTPT_MEAS_INTV_CHAR_SUP_BIT = CO_BIT(HTPT_MEAS_INTV_CHAR_SUP_POS), + + /// Indicate if Measurement Interval Char. supports indications + HTPT_MEAS_INTV_IND_SUP_POS = 3, + HTPT_MEAS_INTV_IND_SUP_BIT = CO_BIT(HTPT_MEAS_INTV_IND_SUP_POS), + + /// Indicate if Measurement Interval Char. is writable + HTPT_MEAS_INTV_WR_SUP_POS = 4, + HTPT_MEAS_INTV_WR_SUP_BIT = CO_BIT(HTPT_MEAS_INTV_WR_SUP_POS), +}; + +/// Notification and indication configuration +enum htpt_ntf_ind_cfg +{ + /// Stable measurement interval indication enabled + HTPT_CFG_STABLE_MEAS_IND = (1 << 0), + /// Intermediate measurement notification enabled + HTPT_CFG_INTERM_MEAS_NTF = (1 << 1), + /// Measurement interval indication + HTPT_CFG_MEAS_INTV_IND = (1 << 2), +}; + +/* + * API MESSAGES STRUCTURES + **************************************************************************************** + */ +/// Parameters of the Health thermometer service database +struct htpt_db_cfg +{ + /// Health thermometer Feature (@see enum htpt_features) + uint8_t features; + /// Temperature Type Value + uint8_t temp_type; + + /// Measurement Interval Valid Range - Minimal Value + uint16_t valid_range_min; + /// Measurement Interval Valid Range - Maximal Value + uint16_t valid_range_max; + /// Measurement interval (latest known interval range) + uint16_t meas_intv; +}; + +/// Parameters of the @ref HTPT_ENABLE_REQ message +struct htpt_enable_req +{ + /// Connection index + uint8_t conidx; + /// Notification configuration (Bond Data to restore: @see enum htpt_ntf_ind_cfg) + uint8_t ntf_ind_cfg; +}; + +/// Parameters of the @ref HTPT_ENABLE_RSP message +struct htpt_enable_rsp +{ + /// Connection index + uint8_t conidx; + /// Status of enable request + uint8_t status; +}; + +/// Parameters of the @ref HTPT_TEMP_SEND_REQ message +struct htpt_temp_send_req +{ + /// Temperature Measurement + struct htp_temp_meas temp_meas; + /// Stable or intermediary type of temperature (True stable meas, else false) + bool stable_meas; +}; + +/// Parameters of the @ref HTPT_TEMP_SEND_RSP message +struct htpt_temp_send_rsp +{ + /// Status + uint8_t status; +}; + +/// Parameters of the @ref HTPT_MEAS_INTV_UPD_REQ message +struct htpt_meas_intv_upd_req +{ + /// Measurement Interval value + uint16_t meas_intv; +}; + +/// Parameters of the @ref HTPT_MEAS_INTV_UPD_RSP message +struct htpt_meas_intv_upd_rsp +{ + /// status + uint8_t status; +}; + +/// Parameters of the @ref HTPT_MEAS_INTV_CHG_REQ_IND message +struct htpt_meas_intv_chg_req_ind +{ + /// Connection index + uint8_t conidx; + /// new measurement interval + uint16_t intv; +}; + +/// Parameters of the @ref HTPT_MEAS_INTV_CHG_CFM message +struct htpt_meas_intv_chg_cfm +{ + /// Connection index + uint8_t conidx; + /// status of the request + uint8_t status; +}; + +/// Parameters of the @ref HTPT_CFG_INDNTF_IND message +struct htpt_cfg_indntf_ind +{ + /// connection index + uint8_t conidx; + /// Notification Configuration (@see enum htpt_ntf_ind_cfg) + uint8_t ntf_ind_cfg; +}; + +/// @} HTPTTASK +#endif // HTPT_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/sourcelist.txt new file mode 100644 index 0000000..664b805 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + htpt.c + htpt_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/src/htpt.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/src/htpt.c new file mode 100644 index 0000000..8900bc7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/src/htpt.c @@ -0,0 +1,619 @@ +/** + **************************************************************************************** + * + * @file htpt.c + * + * @brief Health Thermometer Profile Thermometer implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HTPT + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_HT_THERMOM) +#include "attm.h" +#include "htpt.h" +#include "htpt_task.h" +#include "co_utils.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * HTPT PROFILE ATTRIBUTES + **************************************************************************************** + */ +/// Full HTS Database Description - Used to add attributes into the database +const struct attm_desc htpt_att_db[HTS_IDX_NB] = +{ + // Health Thermometer Service Declaration + [HTS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Temperature Measurement Characteristic Declaration + [HTS_IDX_TEMP_MEAS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Temperature Measurement Characteristic Value + [HTS_IDX_TEMP_MEAS_VAL] = {ATT_CHAR_TEMPERATURE_MEAS, PERM(IND, ENABLE), PERM(RI, ENABLE), 0}, + // Temperature Measurement Characteristic - Client Characteristic Configuration Descriptor + [HTS_IDX_TEMP_MEAS_IND_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Temperature Type Characteristic Declaration + [HTS_IDX_TEMP_TYPE_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Temperature Type Characteristic Value + [HTS_IDX_TEMP_TYPE_VAL] = {ATT_CHAR_TEMPERATURE_TYPE, PERM(RD, ENABLE), PERM(RI, ENABLE), 0}, + + // Intermediate Measurement Characteristic Declaration + [HTS_IDX_INTERM_TEMP_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Intermediate Measurement Characteristic Value + [HTS_IDX_INTERM_TEMP_VAL] = {ATT_CHAR_INTERMED_TEMPERATURE, PERM(NTF, ENABLE), PERM(RI, ENABLE), 0}, + // Intermediate Measurement Characteristic - Client Characteristic Configuration Descriptor + [HTS_IDX_INTERM_TEMP_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Measurement Interval Characteristic Declaration + [HTS_IDX_MEAS_INTV_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Measurement Interval Characteristic Value + [HTS_IDX_MEAS_INTV_VAL] = {ATT_CHAR_MEAS_INTERVAL, PERM(RD, ENABLE), PERM(RI, ENABLE), HTPT_MEAS_INTV_MAX_LEN}, + // Measurement Interval Characteristic - Client Characteristic Configuration Descriptor + [HTS_IDX_MEAS_INTV_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WRITE_REQ, ENABLE), 0, 0}, + // Measurement Interval Characteristic - Valid Range Descriptor + [HTS_IDX_MEAS_INTV_VAL_RANGE] = {ATT_DESC_VALID_RANGE, PERM(RD, ENABLE), PERM(RI, ENABLE), 0}, +}; + +static uint16_t htpt_compute_att_table(uint16_t features); + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the HTPT module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t htpt_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct htpt_db_cfg *p_params) +{ + // Service content flag + uint16_t cfg_flag; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + cfg_flag = htpt_compute_att_table(p_params->features); + + status = attm_svc_create_db(p_start_hdl, ATT_SVC_HEALTH_THERMOM, (uint8_t *)&cfg_flag, + HTS_IDX_NB, NULL, p_env->task, &htpt_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, DISABLE) ); + + if (status == ATT_ERR_NO_ERROR) + { + //-------------------- allocate memory required for the profile --------------------- + struct htpt_env_tag *p_htpt_env = + (struct htpt_env_tag *) ke_malloc(sizeof(struct htpt_env_tag), KE_MEM_ATT_DB); + + // allocate PROXR required environment variable + p_env->env = (prf_env_t *) p_htpt_env; + + p_htpt_env->shdl = *p_start_hdl; + p_htpt_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_htpt_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_HTPT; + htpt_task_init(&(p_env->desc)); + + //Save features on the environment + p_htpt_env->features = p_params->features; + p_htpt_env->meas_intv = p_params->meas_intv; + p_htpt_env->meas_intv_min = p_params->valid_range_min; + p_htpt_env->meas_intv_max = p_params->valid_range_max; + p_htpt_env->temp_type = p_params->temp_type; + p_htpt_env->p_operation = NULL; + memset(p_htpt_env->ntf_ind_cfg, 0 , sizeof(p_htpt_env->ntf_ind_cfg)); + + // Update measurement interval permissions + if (GETB(p_params->features, HTPT_MEAS_INTV_CHAR_SUP)) + { + uint16_t perm = PERM(RD, ENABLE); + + // Check if Measurement Interval Char. supports indications + if (GETB(p_params->features, HTPT_MEAS_INTV_IND_SUP)) + { + perm |= PERM(IND, ENABLE); + } + + // Check if Measurement Interval Char. is writable + if (GETB(p_params->features, HTPT_MEAS_INTV_WR_SUP)) + { + perm |= PERM(WP, UNAUTH)|PERM(WRITE_REQ, ENABLE); + } + + attm_att_set_permission(HTPT_HANDLE(HTS_IDX_MEAS_INTV_VAL), perm, 0); + } + + // service is ready, go into an Idle state + ke_state_set(p_env->task, HTPT_IDLE); + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the HTPT module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void htpt_destroy(struct prf_task_env *p_env) +{ + struct htpt_env_tag *p_htpt_env = (struct htpt_env_tag *) p_env->env; + + // free profile environment variables + if (p_htpt_env->p_operation != NULL) + { + ke_free(p_htpt_env->p_operation); + } + + p_env->env = NULL; + ke_free(p_htpt_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void htpt_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Clear configuration for this connection + struct htpt_env_tag *p_htpt_env = (struct htpt_env_tag *) p_env->env; + + p_htpt_env->ntf_ind_cfg[conidx] = 0; +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void htpt_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + // Clear configuration for this connection + struct htpt_env_tag *p_htpt_env = (struct htpt_env_tag *) p_env->env; + + p_htpt_env->ntf_ind_cfg[conidx] = 0; +} + +/** + **************************************************************************************** + * @brief Compute a flag allowing to know attributes to add into the database + * @param features Health thermometer Feature (@see enum htpt_features) + * @return a 16-bit flag whose each bit matches an attribute. If the bit is set to 1, the + * attribute will be added into the database. + **************************************************************************************** + */ +static uint16_t htpt_compute_att_table(uint16_t features) +{ + //Temperature Measurement Characteristic is mandatory + uint16_t att_table = HTPT_TEMP_MEAS_MASK; + + //Check if Temperature Type Char. is supported + if (GETB(features, HTPT_TEMP_TYPE_CHAR_SUP)) + { + att_table |= HTPT_TEMP_TYPE_MASK; + } + + //Check if Intermediate Temperature Char. is supported + if (GETB(features, HTPT_INTERM_TEMP_CHAR_SUP)) + { + att_table |= HTPT_INTM_TEMP_MASK; + } + + //Check if Measurement Interval Char. is supported + if (GETB(features, HTPT_MEAS_INTV_CHAR_SUP)) + { + att_table |= HTPT_MEAS_INTV_MASK; + + //Check if Measurement Interval Char. supports indications + if (GETB(features, HTPT_MEAS_INTV_IND_SUP)) + { + att_table |= HTPT_MEAS_INTV_CCC_MASK; + } + + //Check if Measurement Interval Char. is writable + if (GETB(features, HTPT_MEAS_INTV_WR_SUP)) + { + att_table |= HTPT_MEAS_INTV_VALID_RGE_MASK; + } + } + + return att_table; +} + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// HTPT Task interface required by profile manager +const struct prf_task_cbs htpt_itf = +{ + (prf_init_fnct) htpt_init, + htpt_destroy, + htpt_create, + htpt_cleanup, +}; + + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +uint8_t htpt_get_valid_rge_offset(uint16_t features) +{ + uint8_t offset = 0; + + if (GETB(features, HTPT_MEAS_INTV_WR_SUP)) + { + offset += 1; + + if (GETB(features, HTPT_MEAS_INTV_IND_SUP)) + { + offset += 1; + } + } + + return offset; +} + +uint8_t htpt_pack_temp_value(uint8_t *p_packed_temp, struct htp_temp_meas temp_meas) +{ + uint8_t cursor = 0; + + *(p_packed_temp + cursor) = temp_meas.flags; + cursor += 1; + + co_write32p(p_packed_temp + cursor, temp_meas.temp); + cursor += 4; + + // Time Flag Set + if (GETB(temp_meas.flags, HTP_FLAG_TIME)) + { + cursor += prf_pack_date_time(p_packed_temp + cursor, &(temp_meas.time_stamp)); + } + + // Type flag set + if (GETB(temp_meas.flags, HTP_FLAG_TYPE)) + { + *(p_packed_temp + cursor) = temp_meas.type; + cursor += 1; + } + + // Clear unused packet data + if (cursor < HTPT_TEMP_MEAS_MAX_LEN) + { + memset(p_packed_temp + cursor, 0, (HTPT_TEMP_MEAS_MAX_LEN - cursor)); + } + + return cursor; +} + +void htpt_exe_operation(void) +{ + struct htpt_env_tag *p_htpt_env = PRF_ENV_GET(HTPT, htpt); + + ASSERT_ERR(p_htpt_env->p_operation != NULL); + + bool finished = true; + + while(p_htpt_env->p_operation->cursor < BLE_CONNECTION_MAX) + { + // check if this type of event is enabled + if (((p_htpt_env->ntf_ind_cfg[p_htpt_env->p_operation->cursor] & p_htpt_env->p_operation->op) != 0) + // and event not filtered on current connection + && (p_htpt_env->p_operation->conidx != p_htpt_env->p_operation->cursor)) + { + // trigger the event + struct gattc_send_evt_cmd *p_evt = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC , p_htpt_env->p_operation->cursor), prf_src_task_get(&p_htpt_env->prf_env, 0), + gattc_send_evt_cmd, p_htpt_env->p_operation->length); + + p_evt->operation = (p_htpt_env->p_operation->op != + HTPT_CFG_INTERM_MEAS_NTF) ? GATTC_INDICATE : GATTC_NOTIFY; + p_evt->length = p_htpt_env->p_operation->length; + p_evt->handle = p_htpt_env->p_operation->handle; + memcpy(p_evt->value, p_htpt_env->p_operation->data, p_evt->length); + + ke_msg_send(p_evt); + + finished = false; + p_htpt_env->p_operation->cursor++; + break; + } + + p_htpt_env->p_operation->cursor++; + } + + // check if operation is finished + if (finished) + { + // do not send response if operation has been locally requested + if (p_htpt_env->p_operation->dest_id != prf_src_task_get(&p_htpt_env->prf_env, 0)) + { + // send response to requester + struct htpt_meas_intv_upd_rsp *p_rsp = + KE_MSG_ALLOC(((p_htpt_env->p_operation->op == + HTPT_CFG_MEAS_INTV_IND) ? HTPT_MEAS_INTV_UPD_RSP : HTPT_TEMP_SEND_RSP), + p_htpt_env->p_operation->dest_id, prf_src_task_get(&p_htpt_env->prf_env, 0), + htpt_meas_intv_upd_rsp); + + p_rsp->status = GAP_ERR_NO_ERROR; + ke_msg_send(p_rsp); + } + + // free operation + ke_free(p_htpt_env->p_operation); + p_htpt_env->p_operation = NULL; + + // go back to idle state + ke_state_set(prf_src_task_get(&(p_htpt_env->prf_env), 0), HTPT_IDLE); + } +} + +uint8_t htpt_update_ntf_ind_cfg(uint8_t conidx, uint8_t cfg, uint16_t valid_val, uint16_t value) +{ + struct htpt_env_tag *p_htpt_env = PRF_ENV_GET(HTPT, htpt); + uint8_t status = GAP_ERR_NO_ERROR; + + if ((value != valid_val) && (value != PRF_CLI_STOP_NTFIND)) + { + status = PRF_APP_ERROR; + + } + else if (value == valid_val) + { + p_htpt_env->ntf_ind_cfg[conidx] |= cfg; + } + else + { + p_htpt_env->ntf_ind_cfg[conidx] &= ~cfg; + } + + if (status == GAP_ERR_NO_ERROR) + { + // inform application that notification/indication configuration has changed + struct htpt_cfg_indntf_ind *p_ind = KE_MSG_ALLOC(HTPT_CFG_INDNTF_IND, + prf_dst_task_get(&p_htpt_env->prf_env, conidx), prf_src_task_get(&p_htpt_env->prf_env, conidx), + htpt_cfg_indntf_ind); + + p_ind->conidx = conidx; + p_ind->ntf_ind_cfg = p_htpt_env->ntf_ind_cfg[conidx]; + ke_msg_send(p_ind); + } + + return (status); +} + +const struct prf_task_cbs* htpt_prf_itf_get(void) +{ + return &htpt_itf; +} + +uint16_t htpt_att_hdl_get(struct htpt_env_tag *p_htpt_env, uint8_t att_idx) +{ + uint16_t handle = p_htpt_env->shdl; + + do + { + // Mandatory attribute handle + if (att_idx > HTS_IDX_TEMP_MEAS_IND_CFG) + { + handle += HTPT_TEMP_MEAS_ATT_NB; + } + else + { + handle += att_idx; + break; + } + + // Temperature Type + if ((GETB(p_htpt_env->features, HTPT_TEMP_TYPE_CHAR_SUP)) && (att_idx > HTS_IDX_TEMP_TYPE_VAL)) + { + handle += HTPT_TEMP_TYPE_ATT_NB; + } + else if (!GETB(p_htpt_env->features, HTPT_TEMP_TYPE_CHAR_SUP)) + { + handle = ATT_INVALID_HANDLE; + break; + } + else + { + handle += att_idx - HTS_IDX_TEMP_TYPE_CHAR; + break; + } + + // Intermediate Temperature Measurement + if ((GETB(p_htpt_env->features, HTPT_INTERM_TEMP_CHAR_SUP)) && (att_idx > HTS_IDX_INTERM_TEMP_CFG)) + { + handle += HTPT_INTERM_MEAS_ATT_NB; + } + else if (!GETB(p_htpt_env->features, HTPT_INTERM_TEMP_CHAR_SUP)) + { + handle = ATT_INVALID_HANDLE; + break; + } + else + { + handle += att_idx - HTS_IDX_INTERM_TEMP_CHAR; + break; + } + + // Measurement Interval + if (!GETB(p_htpt_env->features, HTPT_MEAS_INTV_CHAR_SUP) || (att_idx >= HTS_IDX_NB)) + { + handle = ATT_INVALID_HANDLE; + break; + } + + if (att_idx <= HTS_IDX_MEAS_INTV_VAL) + { + handle += att_idx - HTS_IDX_MEAS_INTV_CHAR; + break; + } + else + { + handle += HTPT_MEAS_INTV_ATT_NB; + } + + // Measurement Interval Indication + if (att_idx == HTS_IDX_MEAS_INTV_CFG) + { + if (!GETB(p_htpt_env->features, HTPT_MEAS_INTV_IND_SUP)) + { + handle = ATT_INVALID_HANDLE; + break; + } + } + // Measurement Interval Write permission + else if (GETB(p_htpt_env->features, HTPT_MEAS_INTV_WR_SUP)) + { + handle += HTPT_MEAS_INTV_CCC_ATT_NB; + + if (!GETB(p_htpt_env->features, HTPT_MEAS_INTV_WR_SUP)) + { + handle = ATT_INVALID_HANDLE; + break; + } + } + } while (0); + + return handle; +} + +uint8_t htpt_att_idx_get(struct htpt_env_tag *p_htpt_env, uint16_t handle) +{ + uint16_t handle_ref = p_htpt_env->shdl; + uint8_t att_idx = ATT_INVALID_IDX; + + do + { + // not valid hande + if (handle < handle_ref) + { + break; + } + + // Mandatory attribute handle + handle_ref += HTPT_TEMP_MEAS_ATT_NB; + + if (handle < handle_ref) + { + att_idx = HTS_IDX_TEMP_TYPE_CHAR - (handle_ref - handle); + break; + } + + // Temperature Type + if (GETB(p_htpt_env->features, HTPT_TEMP_TYPE_CHAR_SUP)) + { + handle_ref += HTPT_TEMP_TYPE_ATT_NB; + + if (handle < handle_ref) + { + att_idx = HTS_IDX_INTERM_TEMP_CHAR - (handle_ref - handle); + break; + } + } + + // Intermediate Temperature Measurement + if (GETB(p_htpt_env->features, HTPT_INTERM_TEMP_CHAR_SUP)) + { + handle_ref += HTPT_INTERM_MEAS_ATT_NB; + + if (handle < handle_ref) + { + att_idx = HTS_IDX_MEAS_INTV_CHAR - (handle_ref - handle); + break; + } + } + + // Measurement Interval + if (GETB(p_htpt_env->features, HTPT_MEAS_INTV_CHAR_SUP)) + { + handle_ref += HTPT_MEAS_INTV_ATT_NB; + + if (handle < handle_ref) + { + att_idx = HTS_IDX_MEAS_INTV_CFG - (handle_ref - handle); + break; + } + + if (GETB(p_htpt_env->features, HTPT_MEAS_INTV_IND_SUP)) + { + if (handle == handle_ref) + { + att_idx = HTS_IDX_MEAS_INTV_CFG; + break; + } + + handle_ref += HTPT_MEAS_INTV_CCC_ATT_NB; + } + + if (GETB(p_htpt_env->features, HTPT_MEAS_INTV_WR_SUP)) + { + if (handle == handle_ref) + { + att_idx = HTS_IDX_MEAS_INTV_VAL_RANGE; + break; + } + } + } + } while (0); + + return att_idx; +} + +#endif //BLE_HT_THERMOM + +/// @} HTPT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/src/htpt.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/src/htpt.h new file mode 100644 index 0000000..4a00fe7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/src/htpt.h @@ -0,0 +1,303 @@ +/** + **************************************************************************************** + * + * @file htpt.h + * + * @brief Header file - Health Thermometer Profile Thermometer. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef HTPT_H_ +#define HTPT_H_ + +/** + **************************************************************************************** + * @addtogroup HTPT Health Thermometer Profile Thermometer + * @ingroup HTP + * @brief Health Thermometer Profile Thermometer + * + * An actual thermometer device does not exist on current platform, so measurement values + * that would come from a driver are replaced by simple counters sent at certain intervals + * following by the profile attributes configuration. + * When a measurement interval + * has been set to a non-zero value in a configuration connection, once reconnected, + * TH will send regular measurement INDs if Temp Meas Char Cfg is set to indicate and + * using the Meas Intv Value. The INDs will continue until meas interval is set to 0 + * or connection gets disconnected by C. Measurements should be stored even so, until + * profile is disabled.(?) + * + * If the measurement interval has been set to 0, then if Intermediate Temp is set to be + * notified and Temp Meas to be indicated, then a timer of fixed length simulates + * sending several NTF before and indication of a "stable" value. This fake behavior + * should be replaced once a real driver exists. If Intermediary Temp cannot be notified, + * just send the indication, if neither can be sent (the configuration connection should + * never leave this like this) then disconnect. + * + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_HT_THERMOM) +#include +#include +#include "htp_common.h" +#include "prf_types.h" +#include "prf_utils.h" + +#include "gap.h" + +/* + * MACROS + **************************************************************************************** + */ +#define HTPT_HANDLE(idx) (htpt_att_hdl_get(p_htpt_env, (idx))) + +#define HTPT_IDX(hdl) (htpt_att_idx_get(p_htpt_env, (hdl))) + + +/* + * DEFINES + **************************************************************************************** + */ +///Maximum number of Health thermometer task instances +#define HTPT_IDX_MAX (1) + + +///Valid range for measurement interval values (s) +#define HTPT_MEAS_INTV_DFLT_MIN (0x0001) +#define HTPT_MEAS_INTV_DFLT_MAX (0x000A) + +#define HTPT_TEMP_MEAS_MAX_LEN (13) +#define HTPT_TEMP_TYPE_MAX_LEN (1) +#define HTPT_MEAS_INTV_MAX_LEN (2) +#define HTPT_MEAS_INTV_RANGE_MAX_LEN (4) +#define HTPT_IND_NTF_CFG_MAX_LEN (2) + +#define HTPT_TEMP_MEAS_MASK (0x000F) +#define HTPT_TEMP_TYPE_MASK (0x0030) +#define HTPT_INTM_TEMP_MASK (0x01C0) +#define HTPT_MEAS_INTV_MASK (0x0600) +#define HTPT_MEAS_INTV_CCC_MASK (0x0800) +#define HTPT_MEAS_INTV_VALID_RGE_MASK (0x1000) + +#define HTPT_TEMP_MEAS_ATT_NB (4) +#define HTPT_TEMP_TYPE_ATT_NB (2) +#define HTPT_INTERM_MEAS_ATT_NB (3) +#define HTPT_MEAS_INTV_ATT_NB (2) +#define HTPT_MEAS_INTV_CCC_ATT_NB (1) +#define HTPT_MEAS_INTV_RNG_ATT_NB (1) + + +/// Possible states of the HTPT task +enum htpt_state +{ + /// Idle state + HTPT_IDLE, + /// Busy state + HTPT_BUSY, + + /// Number of defined states. + HTPT_STATE_MAX +}; + +///Attributes database elements +enum hts_att_db_list +{ + HTS_IDX_SVC, + + HTS_IDX_TEMP_MEAS_CHAR, + HTS_IDX_TEMP_MEAS_VAL, + HTS_IDX_TEMP_MEAS_IND_CFG, + + HTS_IDX_TEMP_TYPE_CHAR, + HTS_IDX_TEMP_TYPE_VAL, + + HTS_IDX_INTERM_TEMP_CHAR, + HTS_IDX_INTERM_TEMP_VAL, + HTS_IDX_INTERM_TEMP_CFG, + + HTS_IDX_MEAS_INTV_CHAR, + HTS_IDX_MEAS_INTV_VAL, + HTS_IDX_MEAS_INTV_CFG, + HTS_IDX_MEAS_INTV_VAL_RANGE, + + HTS_IDX_NB, +}; + + +/// ongoing operation information +struct htpt_op +{ + /// Operation + uint8_t op; + /// Cursor on connection + uint8_t cursor; + /// Handle of the attribute to indicate/notify + uint16_t handle; + /// Task that request the operation that should receive completed message response + uint16_t dest_id; + /// Packed notification/indication data size + uint8_t length; + /// used to know on which device interval update has been requested, and to prevent + /// indication to be triggered on this connection index + uint8_t conidx; + /// Packed notification/indication data + uint8_t data[__ARRAY_EMPTY]; +}; + + +///Health Thermometer Profile Thermometer Environment Variable +struct htpt_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// On-going operation + struct htpt_op *p_operation; + /// Service Start Handle + uint16_t shdl; + /// Database configuration + uint16_t features; + + /// Current Measure interval + uint16_t meas_intv; + /// measurement interval range min + uint16_t meas_intv_min; + /// measurement interval range max + uint16_t meas_intv_max; + /// Temperature Type Value + uint8_t temp_type; + + /// Notification and indication configuration of peer devices. + uint8_t ntf_ind_cfg[BLE_CONNECTION_MAX]; + /// State of different task instances + ke_state_t state[HTPT_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Compute the offset of the valid range descriptor. + * The Measurement Interval characteristic has two optional descriptors. In the database, + * the Client Characteristic Configuration descriptor will always be placed just after the + * characteristic value. Thus, this function checks if the CCC descriptor has been added. + * @param features Health thermometer Feature (@see enum htpt_features) + * @return 0 if Measurement Interval Char. is not writable (no Valid Range descriptor) + * 1 if Measurement Interval Char. doesn't support indications (no CCC descriptor) + * 2 otherwise + **************************************************************************************** + */ +uint8_t htpt_get_valid_rge_offset(uint16_t features); + +/** + **************************************************************************************** + * @brief Retrieve HTS service profile interface + * + * @return HTS service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* htpt_prf_itf_get(void); + + +/** + **************************************************************************************** + * @brief Pack temperature value from several components + * @param p_packed_temp Packed temperature value + * @param temp_meas Temperature measurement value to pack + * @return size of packed value + **************************************************************************************** + */ +uint8_t htpt_pack_temp_value(uint8_t *p_packed_temp, struct htp_temp_meas temp_meas); + + +/** + **************************************************************************************** + * @brief This function fully manage notification and indication of health thermometer + * to peer(s) device(s) according to on-going operation requested by application: + * - Modification of Intermediate Temperature + * - Indicate to a known device that Temperature Measured has change + * - Indicate to a known device that Measure Interval has change + **************************************************************************************** + */ +void htpt_exe_operation(void); + + + +/** + **************************************************************************************** + * @brief Update Notification, Indication configuration + * + * @param[in] conidx Connection index + * @param[in] cfg Indication configuration flag + * @param[in] valid_val Valid value if NTF/IND enable + * @param[in] value Value set by peer device. + * + * @return status of configuration update + **************************************************************************************** + */ +uint8_t htpt_update_ntf_ind_cfg(uint8_t conidx, uint8_t cfg, uint16_t valid_val, uint16_t value); + + +/** + **************************************************************************************** + * @brief Retrieve attribute handle from attribute index + * + * @param[in] p_htpt_env Environment variable + * @param[in] att_idx Attribute Index + * + * @return attribute Handle + **************************************************************************************** + */ +uint16_t htpt_att_hdl_get(struct htpt_env_tag *p_htpt_env, uint8_t att_idx); + +/** + **************************************************************************************** + * @brief Retrieve attribute index from attribute handle + * + * @param[in] p_htpt_env Environment variable + * @param[in] handle Attribute Handle + * + * @return attribute Index + **************************************************************************************** + */ +uint8_t htpt_att_idx_get(struct htpt_env_tag *p_htpt_env, uint16_t handle); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void htpt_task_init(struct ke_task_desc *p_task_desc); + + + +#endif //BLE_HT_THERMOM + +/// @} HTPT + +#endif // HTPT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/src/htpt_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/src/htpt_task.c new file mode 100644 index 0000000..e54acd6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/htp/htpt/src/htpt_task.c @@ -0,0 +1,598 @@ +/** + **************************************************************************************** + * + * @file htpt_task.c + * + * @brief Health Thermometer Profile Thermometer Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup HTPTTASK + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_HT_THERMOM) + +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "htpt.h" +#include "htpt_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HTPT_ENABLE_REQ message. + * The handler enables the Health Thermometer Profile Thermometer Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int htpt_enable_req_handler(ke_msg_id_t const msgid, + struct htpt_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct htpt_enable_rsp *p_rsp; + + // check state of the task + if (gapc_get_conhdl(p_param->conidx) != GAP_INVALID_CONHDL) + { + // restore Bond Data + struct htpt_env_tag* p_htpt_env = PRF_ENV_GET(HTPT, htpt); + p_htpt_env->ntf_ind_cfg[p_param->conidx] = p_param->ntf_ind_cfg; + status = GAP_ERR_NO_ERROR; + } + + // send response + p_rsp = KE_MSG_ALLOC(HTPT_ENABLE_RSP, src_id, dest_id, htpt_enable_rsp); + p_rsp->conidx = p_param->conidx; + p_rsp->status = status; + ke_msg_send(p_rsp); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HTPT_TEMP_SEND_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int htpt_temp_send_req_handler(ke_msg_id_t const msgid, + struct htpt_temp_send_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + int msg_status = KE_MSG_SAVED; + + // check state of the task + if (ke_state_get(dest_id) == HTPT_IDLE) + { + // Get the address of the environment + struct htpt_env_tag *p_htpt_env = PRF_ENV_GET(HTPT, htpt); + + // for intermediate measurement, feature must be enabled + if (!(p_param->stable_meas) && (!GETB(p_htpt_env->features, HTPT_INTERM_TEMP_CHAR_SUP))) + { + struct htpt_temp_send_rsp *p_rsp = KE_MSG_ALLOC(HTPT_TEMP_SEND_RSP, src_id, dest_id, htpt_temp_send_rsp); + + p_rsp->status = PRF_ERR_FEATURE_NOT_SUPPORTED; + ke_msg_send(p_rsp); + } + else + { + // allocate operation to execute + p_htpt_env->p_operation = (struct htpt_op *) ke_malloc(sizeof(struct htpt_op) + + HTPT_TEMP_MEAS_MAX_LEN, KE_MEM_ATT_DB); + + // Initialize operation parameters + p_htpt_env->p_operation->cursor = 0; + p_htpt_env->p_operation->dest_id = src_id; + p_htpt_env->p_operation->conidx = GAP_INVALID_CONIDX; + + // Stable measurement indication or intermediate measurement notification + if (p_param->stable_meas) + { + p_htpt_env->p_operation->op = HTPT_CFG_STABLE_MEAS_IND; + p_htpt_env->p_operation->handle = HTPT_HANDLE(HTS_IDX_TEMP_MEAS_VAL); + } + else + { + p_htpt_env->p_operation->op = HTPT_CFG_INTERM_MEAS_NTF; + p_htpt_env->p_operation->handle = HTPT_HANDLE(HTS_IDX_INTERM_TEMP_VAL); + } + + // Pack the temperature measurement value + p_htpt_env->p_operation->length = + htpt_pack_temp_value(&(p_htpt_env->p_operation->data[0]), p_param->temp_meas); + + // put task in a busy state + ke_state_set(dest_id, HTPT_BUSY); + + // execute operation + htpt_exe_operation(); + } + + msg_status = KE_MSG_CONSUMED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Request to update Measurement Interval Value + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int htpt_meas_intv_upd_req_handler(ke_msg_id_t const msgid, + struct htpt_meas_intv_upd_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_SAVED; + + // check state of the task + if (ke_state_get(dest_id) == HTPT_IDLE) + { + // Get the address of the environment + struct htpt_env_tag *p_htpt_env = PRF_ENV_GET(HTPT, htpt); + + // update measurement interval + p_htpt_env->meas_intv = p_param->meas_intv; + + // Check if Measurement Interval indication is supported + if (!GETB(p_htpt_env->features, HTPT_MEAS_INTV_CHAR_SUP)) + { + struct htpt_meas_intv_upd_rsp *p_rsp = KE_MSG_ALLOC(HTPT_MEAS_INTV_UPD_RSP, + src_id, dest_id, htpt_meas_intv_upd_rsp); + + p_rsp->status = PRF_ERR_FEATURE_NOT_SUPPORTED; + ke_msg_send(p_rsp); + } + else + { + // update internal measurement interval value + p_htpt_env->meas_intv = p_param->meas_intv; + + // no indication to trigger + if (!GETB(p_htpt_env->features, HTPT_MEAS_INTV_IND_SUP)) + { + struct htpt_meas_intv_upd_rsp *p_rsp = KE_MSG_ALLOC(HTPT_MEAS_INTV_UPD_RSP, + src_id, dest_id, htpt_meas_intv_upd_rsp); + + p_rsp->status = GAP_ERR_NO_ERROR; + ke_msg_send(p_rsp); + } + // trigger measurement update indication + else + { + // allocate operation to execute + p_htpt_env->p_operation = (struct htpt_op *) ke_malloc(sizeof(struct htpt_op) + + HTPT_MEAS_INTV_MAX_LEN, KE_MEM_ATT_DB); + + // Initialize operation parameters + p_htpt_env->p_operation->op = HTPT_CFG_MEAS_INTV_IND; + p_htpt_env->p_operation->handle = HTPT_HANDLE(HTS_IDX_MEAS_INTV_VAL); + p_htpt_env->p_operation->dest_id = src_id; + p_htpt_env->p_operation->cursor = 0; + p_htpt_env->p_operation->conidx = GAP_INVALID_CONIDX; + + // Pack the interval value + p_htpt_env->p_operation->length = HTPT_MEAS_INTV_MAX_LEN; + co_write16p(p_htpt_env->p_operation->data, p_param->meas_intv); + + // put task in a busy state + ke_state_set(dest_id, HTPT_BUSY); + + // execute operation + htpt_exe_operation(); + } + } + + msg_status = KE_MSG_CONSUMED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct htpt_env_tag *p_htpt_env = PRF_ENV_GET(HTPT, htpt); + uint8_t att_idx = HTPT_IDX(p_param->handle); + struct gattc_att_info_cfm *p_cfm; + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + switch(att_idx) + { + case HTS_IDX_MEAS_INTV_VAL: + { + // force length to zero to reject any write starting from something != 0 + p_cfm->length = 0; + p_cfm->status = GAP_ERR_NO_ERROR; + } break; + + case HTS_IDX_TEMP_MEAS_IND_CFG: + case HTS_IDX_INTERM_TEMP_CFG: + case HTS_IDX_MEAS_INTV_CFG: + { + p_cfm->length = HTPT_IND_NTF_CFG_MAX_LEN; + p_cfm->status = GAP_ERR_NO_ERROR; + } break; + + default: + { + p_cfm->status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GL2C_CODE_ATT_WR_CMD_IND message. + * The handler compares the new values with current ones and notifies them if they changed. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct htpt_env_tag *p_htpt_env = PRF_ENV_GET(HTPT, htpt); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t status = ATT_ERR_NO_ERROR; + int msg_status = KE_MSG_CONSUMED; + + // to check if confirmation message should be send + bool send_cfm = true; + + if (p_param->length != HTPT_MEAS_INTV_MAX_LEN) + { + status = PRF_ERR_UNEXPECTED_LEN; + } + else + { + // retrieve handle information + switch(HTPT_IDX(p_param->handle)) + { + case HTS_IDX_MEAS_INTV_VAL: + { + uint16_t meas_intv = co_read16p(p_param->value); + + // check measurement length validity + if (((meas_intv >= p_htpt_env->meas_intv_min) && (meas_intv <= p_htpt_env->meas_intv_max)) + // notification can be disabled anyway + || (meas_intv == 0)) + { + uint8_t state = ke_state_get(dest_id); + + send_cfm = false; + + // check state of the task to know if it can be proceed immediately + if (state == HTPT_IDLE) + { + // inform application that update of measurement interval is requested by peer device. + struct htpt_meas_intv_chg_req_ind *p_req_ind = KE_MSG_ALLOC(HTPT_MEAS_INTV_CHG_REQ_IND, + prf_dst_task_get(&p_htpt_env->prf_env, conidx), dest_id, htpt_meas_intv_chg_req_ind); + + p_req_ind->conidx = conidx; + p_req_ind->intv = meas_intv; + ke_msg_send(p_req_ind); + + // allocate operation to execute + p_htpt_env->p_operation = (struct htpt_op *) ke_malloc(sizeof(struct htpt_op) + + HTPT_MEAS_INTV_MAX_LEN, KE_MEM_ATT_DB); + + // Initialize operation parameters + p_htpt_env->p_operation->op = HTPT_CFG_MEAS_INTV_IND; + p_htpt_env->p_operation->handle = HTPT_HANDLE(HTS_IDX_MEAS_INTV_VAL); + p_htpt_env->p_operation->dest_id = dest_id; + p_htpt_env->p_operation->conidx = conidx; + // to be sure that no notification will be triggered + p_htpt_env->p_operation->cursor = 0xFF; + + // Pack the interval value + p_htpt_env->p_operation->length = HTPT_MEAS_INTV_MAX_LEN; + co_write16p(p_htpt_env->p_operation->data, meas_intv); + + // put task in a busy state + ke_state_set(dest_id, HTPT_BUSY); + } + else + { + msg_status = KE_MSG_SAVED; + } + } + else + { + // value not in expected range + status = HTP_OUT_OF_RANGE_ERR_CODE; + } + } break; + + case HTS_IDX_TEMP_MEAS_IND_CFG: + { + status = htpt_update_ntf_ind_cfg(conidx, HTPT_CFG_STABLE_MEAS_IND, + PRF_CLI_START_IND, co_read16p(p_param->value)); + } break; + + case HTS_IDX_INTERM_TEMP_CFG: + { + status = htpt_update_ntf_ind_cfg(conidx, HTPT_CFG_INTERM_MEAS_NTF, + PRF_CLI_START_NTF, co_read16p(p_param->value)); + } break; + + case HTS_IDX_MEAS_INTV_CFG: + { + status = htpt_update_ntf_ind_cfg(conidx, HTPT_CFG_MEAS_INTV_IND, + PRF_CLI_START_IND, co_read16p(p_param->value)); + } break; + + default: + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + } + + if (send_cfm) + { + //Send write response + struct gattc_write_cfm *p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + struct htpt_env_tag *p_htpt_env = PRF_ENV_GET(HTPT, htpt); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t value[HTPT_MEAS_INTV_RANGE_MAX_LEN]; + uint8_t value_size = 0; + uint8_t status = ATT_ERR_NO_ERROR; + struct gattc_read_cfm *p_cfm; + + // retrieve handle information + switch(HTPT_IDX(p_param->handle)) + { + case HTS_IDX_MEAS_INTV_VAL: + { + value_size = HTPT_MEAS_INTV_MAX_LEN; + co_write16p(&(value[0]), p_htpt_env->meas_intv); + } break; + + case HTS_IDX_MEAS_INTV_VAL_RANGE: + { + value_size = HTPT_MEAS_INTV_RANGE_MAX_LEN; + co_write16p(&(value[0]), p_htpt_env->meas_intv_min); + co_write16p(&(value[2]), p_htpt_env->meas_intv_max); + } break; + + case HTS_IDX_TEMP_MEAS_IND_CFG: + { + value_size = HTPT_IND_NTF_CFG_MAX_LEN; + co_write16p(value, ((p_htpt_env->ntf_ind_cfg[conidx] & HTPT_CFG_STABLE_MEAS_IND) != 0) ? + PRF_CLI_START_IND : PRF_CLI_STOP_NTFIND); + } break; + + case HTS_IDX_INTERM_TEMP_CFG: + { + value_size = HTPT_IND_NTF_CFG_MAX_LEN; + co_write16p(value, ((p_htpt_env->ntf_ind_cfg[conidx] & HTPT_CFG_INTERM_MEAS_NTF) != 0) ? + PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } break; + + case HTS_IDX_MEAS_INTV_CFG: + { + value_size = HTPT_IND_NTF_CFG_MAX_LEN; + co_write16p(value, ((p_htpt_env->ntf_ind_cfg[conidx] & HTPT_CFG_MEAS_INTV_IND) != 0) ? + PRF_CLI_START_IND : PRF_CLI_STOP_NTFIND); + } break; + + case HTS_IDX_TEMP_TYPE_VAL: + { + value_size = HTPT_TEMP_TYPE_MAX_LEN; + value[0] = p_htpt_env->temp_type; + } break; + + default: + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + // Send data to peer device + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, value_size); + p_cfm->length = value_size; + memcpy(p_cfm->value, value, value_size); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref HTPT_MEAS_INTV_UPD_CFM message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int htpt_meas_intv_chg_cfm_handler(ke_msg_id_t const msgid, struct htpt_meas_intv_chg_cfm const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + struct htpt_env_tag *p_htpt_env = PRF_ENV_GET(HTPT, htpt); + + // check state of the task + if (ke_state_get(dest_id) == HTPT_BUSY) + { + // retrieve connection index from operation + uint8_t conidx = p_htpt_env->p_operation->conidx; + //Send write response + struct gattc_write_cfm *p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, + KE_BUILD_ID(TASK_GATTC, conidx), dest_id, gattc_write_cfm); + + p_cfm->handle = HTPT_HANDLE(HTS_IDX_MEAS_INTV_VAL); + p_cfm->status = (p_param->conidx == conidx) ? p_param->status : PRF_APP_ERROR; + ke_msg_send(p_cfm); + + // check if no error occurs + if (p_cfm->status == GAP_ERR_NO_ERROR) + { + // update the current measurement interval + p_htpt_env->meas_intv = co_read16p(p_htpt_env->p_operation->data); + + // check if an indication of new measurement interval should be triggered + if (GETB(p_htpt_env->features, HTPT_MEAS_INTV_IND_SUP)) + { + // set back cursor to zero in order to send indication + p_htpt_env->p_operation->cursor = 0; + } + } + + // send indication or terminate operation + htpt_exe_operation(); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT for GATTC_NOTIFY and GATT_INDICATE message meaning + * that Measurement notification/indication has been correctly sent to peer device + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + // continue operation execution + htpt_exe_operation(); + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(htpt) +{ + {HTPT_ENABLE_REQ, (ke_msg_func_t) htpt_enable_req_handler}, + + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, + + {HTPT_TEMP_SEND_REQ, (ke_msg_func_t) htpt_temp_send_req_handler}, + {HTPT_MEAS_INTV_UPD_REQ, (ke_msg_func_t) htpt_meas_intv_upd_req_handler}, + {HTPT_MEAS_INTV_CHG_CFM, (ke_msg_func_t) htpt_meas_intv_chg_cfm_handler}, +}; + +void htpt_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct htpt_env_tag *p_htpt_env = PRF_ENV_GET(HTPT, htpt); + + p_task_desc->msg_handler_tab = htpt_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(htpt_msg_handler_tab); + p_task_desc->state = p_htpt_env->state; + p_task_desc->idx_max = HTPT_IDX_MAX; +} + +#endif //BLE_HT_THERMOM + +/// @} HTPTTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lan_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lan_common.h new file mode 100644 index 0000000..72b7900 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lan_common.h @@ -0,0 +1,525 @@ +/** + **************************************************************************************** + * + * @file lanp_common.h + * + * @brief Header File - Location and Navigation Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +#ifndef _LANP_COMMON_H_ +#define _LANP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup LANP Location and Navigation Profile + * @ingroup PROFILE + * @brief Location and Navigation Profile + * + * The Location and Navigation Profile is used to enable a collector device in order to obtain + * data from a Location and Navigation Sensor (LAN Sensor) that exposes the Location and Navigation Service. + * + * This file contains all definitions that are common for the server and the client parts + * of the profile. + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "co_math.h" +#include "prf_types.h" +#include + +/* + * DEFINES + **************************************************************************************** + */ +/// Inappropriate Connection Parameters Error Code +#define LAN_ERROR_INAPP_CONNECT_PARAMS (0x80) +/// Procedure Already in Progress Error Code +#define LAN_ERROR_PROC_IN_PROGRESS (0xFE) + +#define LANP_LAN_LSPEED_MAX_PAIR_SIZE (8) + +/// LAN Location and Speed Value Max Length +#define LANP_LAN_LOC_SPEED_MAX_LEN (28) +/// LAN Location and Speed Value Min Length +#define LANP_LAN_LOC_SPEED_MIN_LEN (2) + +/// LAN Position Quality Value Max Length +#define LANP_LAN_POSQ_MAX_LEN (16) +/// LAN Position Quality Value Min Length +#define LANP_LAN_POSQ_MIN_LEN (2) + +/// LAN Control Point Value Request Max Length +#define LANP_LAN_LN_CNTL_PT_REQ_MAX_LEN (5) +/// LAN Control Point Value Request Min Length +#define LANP_LAN_LN_CNTL_PT_REQ_MIN_LEN (1) + +/// LAN Control Point data Max Length (from 2 to max route name) +#define LANP_LAN_LN_CNTL_DATA_MAX_LEN (128) +/// LAN Control Point Value Response Max Length +#define LANP_LAN_LN_CNTL_PT_RSP_MAX_LEN (3 + LANP_LAN_LN_CNTL_DATA_MAX_LEN) +/// LAN Control Point Value Response Min Length +#define LANP_LAN_LN_CNTL_PT_RSP_MIN_LEN (3) + +/// LAN Navigation Value Max Length +#define LANP_LAN_NAVIGATION_MAX_LEN (21) +/// LAN Navigation Value Min Length +#define LANP_LAN_NAVIGATION_MIN_LEN (6) + +/// All Supported +#define LANP_FEAT_ALL_SUPP (0x001FFFFF) + +/// All Present +#define LANP_LSPEED_ALL_PRESENT (0x1FFF) + +/// All Present +#define LANP_POSQ_ALL_PRESENT (0x01FF) + +/// ALl present +#define LANP_NAVI_ALL_PRESENT (0x01FF) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// LANP Service Characteristics +enum lanp_lans_char +{ + /// LN Feature + LANP_LANS_LN_FEAT_CHAR, + /// Location and speed + LANP_LANS_LOC_SPEED_CHAR, + /// Position quality + LANP_LANS_POS_Q_CHAR, + /// LN Control Point + LANP_LANS_LN_CTNL_PT_CHAR, + /// Navigation + LANP_LANS_NAVIG_CHAR, + + LANP_LANS_CHAR_MAX +}; + +/// LANP Feature Flags +enum lanp_feat_flags +{ + /// Instantaneous Speed Supported + LANP_FEAT_INSTANTANEOUS_SPEED_SUP_POS = 0, + LANP_FEAT_INSTANTANEOUS_SPEED_SUP_BIT = CO_BIT(LANP_FEAT_INSTANTANEOUS_SPEED_SUP_POS), + + /// Total Distance Supported + LANP_FEAT_TOTAL_DISTANCE_SUP_POS = 1, + LANP_FEAT_TOTAL_DISTANCE_SUP_BIT = CO_BIT(LANP_FEAT_TOTAL_DISTANCE_SUP_POS), + + /// Location Supported + LANP_FEAT_LOCATION_SUP_POS = 2, + LANP_FEAT_LOCATION_SUP_BIT = CO_BIT(LANP_FEAT_LOCATION_SUP_POS), + + /// Elevation Supported + LANP_FEAT_ELEVATION_SUP_POS = 3, + LANP_FEAT_ELEVATION_SUP_BIT = CO_BIT(LANP_FEAT_ELEVATION_SUP_POS), + + /// Heading Supported + LANP_FEAT_HEADING_SUP_POS = 4, + LANP_FEAT_HEADING_SUP_BIT = CO_BIT(LANP_FEAT_HEADING_SUP_POS), + + /// Rolling Time Supported + LANP_FEAT_ROLLING_TIME_SUP_POS = 5, + LANP_FEAT_ROLLING_TIME_SUP_BIT = CO_BIT(LANP_FEAT_ROLLING_TIME_SUP_POS), + + /// UTC Time Supported + LANP_FEAT_UTC_TIME_SUP_POS = 6, + LANP_FEAT_UTC_TIME_SUP_BIT = CO_BIT(LANP_FEAT_UTC_TIME_SUP_POS), + + /// Remaining Distance Supported + LANP_FEAT_REMAINING_DISTANCE_SUP_POS = 7, + LANP_FEAT_REMAINING_DISTANCE_SUP_BIT = CO_BIT(LANP_FEAT_REMAINING_DISTANCE_SUP_POS), + + /// Remaining Vertical Distance Supported + LANP_FEAT_REMAINING_VERTICAL_DISTANCE_SUP_POS = 8, + LANP_FEAT_REMAINING_VERTICAL_DISTANCE_SUP_BIT = CO_BIT(LANP_FEAT_REMAINING_VERTICAL_DISTANCE_SUP_POS), + + /// Estimated Time of Arrival Supported + LANP_FEAT_ESTIMATED_TIME_OF_ARRIVAL_SUP_POS = 9, + LANP_FEAT_ESTIMATED_TIME_OF_ARRIVAL_SUP_BIT = CO_BIT(LANP_FEAT_ESTIMATED_TIME_OF_ARRIVAL_SUP_POS), + + /// Number of Beacons in Solution Supported + LANP_FEAT_NUMBER_OF_BEACONS_IN_SOLUTION_SUP_POS = 10, + LANP_FEAT_NUMBER_OF_BEACONS_IN_SOLUTION_SUP_BIT = CO_BIT(LANP_FEAT_NUMBER_OF_BEACONS_IN_SOLUTION_SUP_POS), + + /// Number of Beacons in View Supported + LANP_FEAT_NUMBER_OF_BEACONS_IN_VIEW_SUP_POS = 11, + LANP_FEAT_NUMBER_OF_BEACONS_IN_VIEW_SUP_BIT = CO_BIT(LANP_FEAT_NUMBER_OF_BEACONS_IN_VIEW_SUP_POS), + + /// Time to First Fix Supported + LANP_FEAT_TIME_TO_FIRST_FIX_SUP_POS = 12, + LANP_FEAT_TIME_TO_FIRST_FIX_SUP_BIT = CO_BIT(LANP_FEAT_TIME_TO_FIRST_FIX_SUP_POS), + + /// Estimated Horizontal Position Error Supported + LANP_FEAT_ESTIMATED_HOR_POSITION_ERROR_SUP_POS = 13, + LANP_FEAT_ESTIMATED_HOR_POSITION_ERROR_SUP_BIT = CO_BIT(LANP_FEAT_ESTIMATED_HOR_POSITION_ERROR_SUP_POS), + + /// Estimated Vertical Position Error Supported + LANP_FEAT_ESTIMATED_VER_POSITION_ERROR_SUP_POS = 14, + LANP_FEAT_ESTIMATED_VER_POSITION_ERROR_SUP_BIT = CO_BIT(LANP_FEAT_ESTIMATED_VER_POSITION_ERROR_SUP_POS), + + /// Horizontal Dilution of Precision Supported + LANP_FEAT_HOR_DILUTION_OF_PRECISION_SUP_POS = 15, + LANP_FEAT_HOR_DILUTION_OF_PRECISION_SUP_BIT = CO_BIT(LANP_FEAT_HOR_DILUTION_OF_PRECISION_SUP_POS), + + /// Vertical Dilution of Precision Supported + LANP_FEAT_VER_DILUTION_OF_PRECISION_SUP_POS = 16, + LANP_FEAT_VER_DILUTION_OF_PRECISION_SUP_BIT = CO_BIT(LANP_FEAT_VER_DILUTION_OF_PRECISION_SUP_POS), + + /// Location and Speed Characteristic Content Masking Supported + LANP_FEAT_LSPEED_CHAR_CT_MASKING_SUP_POS = 17, + LANP_FEAT_LSPEED_CHAR_CT_MASKING_SUP_BIT = CO_BIT(LANP_FEAT_LSPEED_CHAR_CT_MASKING_SUP_POS), + + /// Fix Rate Setting Supported + LANP_FEAT_FIX_RATE_SETTING_SUP_POS = 18, + LANP_FEAT_FIX_RATE_SETTING_SUP_BIT = CO_BIT(LANP_FEAT_FIX_RATE_SETTING_SUP_POS), + + /// Elevation Setting Supported + LANP_FEAT_ELEVATION_SETTING_SUP_POS = 19, + LANP_FEAT_ELEVATION_SETTING_SUP_BIT = CO_BIT(LANP_FEAT_ELEVATION_SETTING_SUP_POS), + + /// Position Status Supported + LANP_FEAT_POSITION_STATUS_SUP_POS = 20, + LANP_FEAT_POSITION_STATUS_SUP_BIT = CO_BIT(LANP_FEAT_POSITION_STATUS_SUP_POS), + + // Bit 21 - 31 RFU +}; + +/// LANP Location and speed Flags +enum lanp_lspeed_flags +{ + /// Instantaneous Speed Present + LANP_LSPEED_INST_SPEED_PRESENT_POS = 0, + LANP_LSPEED_INST_SPEED_PRESENT_BIT = CO_BIT(LANP_LSPEED_INST_SPEED_PRESENT_POS), + + /// Total Distance Present + LANP_LSPEED_TOTAL_DISTANCE_PRESENT_POS = 1, + LANP_LSPEED_TOTAL_DISTANCE_PRESENT_BIT = CO_BIT(LANP_LSPEED_TOTAL_DISTANCE_PRESENT_POS), + + /// Location Present + LANP_LSPEED_LOCATION_PRESENT_POS = 2, + LANP_LSPEED_LOCATION_PRESENT_BIT = CO_BIT(LANP_LSPEED_LOCATION_PRESENT_POS), + + /// Elevation Present + LANP_LSPEED_ELEVATION_PRESENT_POS = 3, + LANP_LSPEED_ELEVATION_PRESENT_BIT = CO_BIT(LANP_LSPEED_ELEVATION_PRESENT_POS), + + /// Heading Present + LANP_LSPEED_HEADING_PRESENT_POS = 4, + LANP_LSPEED_HEADING_PRESENT_BIT = CO_BIT(LANP_LSPEED_HEADING_PRESENT_POS), + + /// Rolling Time Present + LANP_LSPEED_ROLLING_TIME_PRESENT_POS = 5, + LANP_LSPEED_ROLLING_TIME_PRESENT_BIT = CO_BIT(LANP_LSPEED_ROLLING_TIME_PRESENT_POS), + + /// UTC Time Present + LANP_LSPEED_UTC_TIME_PRESENT_POS = 6, + LANP_LSPEED_UTC_TIME_PRESENT_BIT = CO_BIT(LANP_LSPEED_UTC_TIME_PRESENT_POS), + + /// Position Status LSB + LANP_LSPEED_POSITION_STATUS_LSB_POS = 7, + LANP_LSPEED_POSITION_STATUS_LSB_BIT = CO_BIT(LANP_LSPEED_POSITION_STATUS_LSB_POS), + + /// Position Status MSB + LANP_LSPEED_POSITION_STATUS_MSB_POS = 8, + LANP_LSPEED_POSITION_STATUS_MSB_BIT = CO_BIT(LANP_LSPEED_POSITION_STATUS_MSB_POS), + + /// Speed and Distance format + LANP_LSPEED_SPEED_AND_DISTANCE_FORMAT_POS = 9, + LANP_LSPEED_SPEED_AND_DISTANCE_FORMAT_BIT = CO_BIT(LANP_LSPEED_SPEED_AND_DISTANCE_FORMAT_POS), + + /// Elevation Source LSB + LANP_LSPEED_ELEVATION_SOURCE_LSB_POS = 10, + LANP_LSPEED_ELEVATION_SOURCE_LSB_BIT = CO_BIT(LANP_LSPEED_ELEVATION_SOURCE_LSB_POS), + + /// Elevation Source MSB + LANP_LSPEED_ELEVATION_SOURCE_MSB_POS = 11, + LANP_LSPEED_ELEVATION_SOURCE_MSB_BIT = CO_BIT(LANP_LSPEED_ELEVATION_SOURCE_MSB_POS), + + /// Heading Source + LANP_LSPEED_HEADING_SOURCE_POS = 12, + LANP_LSPEED_HEADING_SOURCE_BIT = CO_BIT(LANP_LSPEED_HEADING_SOURCE_POS), + + // Bit 13 - 15 RFU +}; + +/// LANP Position quality Flags +enum lanp_posq_flags +{ + /// Number of Beacons in Solution Present + LANP_POSQ_NUMBER_OF_BEACONS_IN_SOLUTION_PRESENT_POS = 0, + LANP_POSQ_NUMBER_OF_BEACONS_IN_SOLUTION_PRESENT_BIT = CO_BIT(LANP_POSQ_NUMBER_OF_BEACONS_IN_SOLUTION_PRESENT_POS), + + /// Number of Beacons in View Present + LANP_POSQ_NUMBER_OF_BEACONS_IN_VIEW_PRESENT_POS = 1, + LANP_POSQ_NUMBER_OF_BEACONS_IN_VIEW_PRESENT_BIT = CO_BIT(LANP_POSQ_NUMBER_OF_BEACONS_IN_VIEW_PRESENT_POS), + + /// Time to First Fix Present + LANP_POSQ_TIME_TO_FIRST_FIX_PRESENT_POS = 2, + LANP_POSQ_TIME_TO_FIRST_FIX_PRESENT_BIT = CO_BIT(LANP_POSQ_TIME_TO_FIRST_FIX_PRESENT_POS), + + /// EHPE Present + LANP_POSQ_EHPE_PRESENT_POS = 3, + LANP_POSQ_EHPE_PRESENT_BIT = CO_BIT(LANP_POSQ_EHPE_PRESENT_POS), + + /// EVPE Present + LANP_POSQ_EVPE_PRESENT_POS = 4, + LANP_POSQ_EVPE_PRESENT_BIT = CO_BIT(LANP_POSQ_EVPE_PRESENT_POS), + + /// HDOP Present + LANP_POSQ_HDOP_PRESENT_POS = 5, + LANP_POSQ_HDOP_PRESENT_BIT = CO_BIT(LANP_POSQ_HDOP_PRESENT_POS), + + /// VDOP Present + LANP_POSQ_VDOP_PRESENT_POS = 6, + LANP_POSQ_VDOP_PRESENT_BIT = CO_BIT(LANP_POSQ_VDOP_PRESENT_POS), + + /// Position Status LSB + LANP_POSQ_POSITION_STATUS_LSB_POS = 7, + LANP_POSQ_POSITION_STATUS_LSB_BIT = CO_BIT(LANP_POSQ_POSITION_STATUS_LSB_POS), + + /// Position Status MSB + LANP_POSQ_POSITION_STATUS_MSB_POS = 8, + LANP_POSQ_POSITION_STATUS_MSB_BIT = CO_BIT(LANP_POSQ_POSITION_STATUS_MSB_POS), + + // Bit 9 - 15 RFU +}; + +/// LANP Control Point Keys +enum lanp_ln_ctnl_pt_code +{ + /// Reserved value + LANP_LN_CTNL_PT_RESERVED = 0, + + /// Set Cumulative Value + LANP_LN_CTNL_PT_SET_CUMUL_VALUE = 1, + /// Mask Location and Speed Characteristic Content + LANP_LN_CTNL_PT_MASK_LSPEED_CHAR_CT = 2, + /// Navigation Control + LANP_LN_CTNL_PT_NAVIGATION_CONTROL = 3, + /// Request Number of Routes + LANP_LN_CTNL_PT_REQ_NUMBER_OF_ROUTES = 4, + /// Request Name of Route + LANP_LN_CTNL_PT_REQ_NAME_OF_ROUTE = 5, + /// Select Route + LANP_LN_CTNL_PT_SELECT_ROUTE = 6, + /// Set Fix Rate + LANP_LN_CTNL_PT_SET_FIX_RATE = 7, + /// Set Elevation + LANP_LN_CTNL_PT_SET_ELEVATION = 8, + /// Response Code + LANP_LN_CTNL_PT_RESPONSE_CODE = 32 +}; + +/// LANP Control Point Response Value +enum lanp_ctnl_pt_resp_val +{ + /// Reserved value + LANP_LN_CTNL_PT_RESP_RESERVED = 0, + + /// Success + LANP_LN_CTNL_PT_RESP_SUCCESS = 1, + /// Operation Code Not Supported + LANP_LN_CTNL_PT_RESP_NOT_SUPP = 2, + /// Invalid Parameter + LANP_LN_CTNL_PT_RESP_INV_PARAM = 3, + /// Operation Failed + LANP_LN_CTNL_PT_RESP_FAILED = 4, +}; + +/// LANP Navigation Control parameter +enum lanp_navi_ctrl_val +{ + /// Stop Navigation + LANP_LN_CTNL_STOP_NAVI = 0x00, + /// Start Navigation + LANP_LN_CTNL_START_NAVI = 0x01, + /// Pause Navigation + LANP_LN_CTNL_PAUSE_NAVI = 0x02, + /// Resume Navigation + LANP_LN_CTNL_RESUME_NAVI = 0x03, + /// Skip waypoint on route + LANP_LN_CTNL_SKIP_WPT = 0x04, + /// Start Navigation from the nearest waypoint + LANP_LN_CTNL_START_NST_WPT = 0x05, + + // 0x06 - 0xFF RFU +}; + +/// LANP Navigation flags +enum lanp_navi_flags +{ + /// Remaining Distance Present + LANP_NAVI_REMAINING_DIS_PRESENT_POS = 0, + LANP_NAVI_REMAINING_DIS_PRESENT_BIT = CO_BIT(LANP_NAVI_REMAINING_DIS_PRESENT_POS), + + /// Remaining Vertical Distance Present + LANP_NAVI_REMAINING_VER_DIS_PRESENT_POS = 1, + LANP_NAVI_REMAINING_VER_DIS_PRESENT_BIT = CO_BIT(LANP_NAVI_REMAINING_VER_DIS_PRESENT_POS), + + /// Estimated Time of Arrival Present + LANP_NAVI_ESTIMATED_TIME_OF_ARRIVAL_PRESENT_POS = 2, + LANP_NAVI_ESTIMATED_TIME_OF_ARRIVAL_PRESENT_BIT = CO_BIT(LANP_NAVI_ESTIMATED_TIME_OF_ARRIVAL_PRESENT_POS), + + /// Position Status lsb + LANP_NAVI_POSITION_STATUS_LSB_POS = 3, + LANP_NAVI_POSITION_STATUS_LSB_BIT = CO_BIT(LANP_NAVI_POSITION_STATUS_LSB_POS), + + /// Position Status msb + LANP_NAVI_POSITION_STATUS_MSB_POS = 4, + LANP_NAVI_POSITION_STATUS_MSB_BIT = CO_BIT(LANP_NAVI_POSITION_STATUS_MSB_POS), + + /// Heading Source + LANP_NAVI_HEADING_SOURCE_POS = 5, + LANP_NAVI_HEADING_SOURCE_BIT = CO_BIT(LANP_NAVI_HEADING_SOURCE_POS), + + /// Navigation Indicator Type + LANP_NAVI_NAVIGATION_INDICATOR_TYPE_POS = 6, + LANP_NAVI_NAVIGATION_INDICATOR_TYPE_BIT = CO_BIT(LANP_NAVI_NAVIGATION_INDICATOR_TYPE_POS), + + /// Waypoint Reached + LANP_NAVI_WAYPOINT_REACHED_POS = 7, + LANP_NAVI_WAYPOINT_REACHED_BIT = CO_BIT(LANP_NAVI_WAYPOINT_REACHED_POS), + + /// Destination Reached + LANP_NAVI_DESTINATION_REACHED_POS = 8, + LANP_NAVI_DESTINATION_REACHED_BIT = CO_BIT(LANP_NAVI_DESTINATION_REACHED_POS), + + // Bit 9 - 15 RFU +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Location and Speed +struct lanp_loc_speed +{ + /// Flags + uint16_t flags; + /// Instantaneous Speed + uint16_t inst_speed; + /// Total distance + uint32_t total_dist; + /// Location - Latitude + int32_t latitude; + /// Location - Longitude + int32_t longitude; + /// Elevation + int32_t elevation; + /// Heading + uint16_t heading; + /// Rolling time + uint8_t rolling_time; + /// UTC Time + struct prf_date_time date_time; +}; + +/// LAN Position quality +struct lanp_posq +{ + /// Flags + uint16_t flags; + /// Time to First Fix + uint16_t time_first_fix; + /// EHPE + uint32_t ehpe; + /// EVPE + uint32_t evpe; + /// Number of Beacons in Solution + uint8_t n_beacons_solution; + /// Number of Beacons in view + uint8_t n_beacons_view; + /// HDOP + uint8_t hdop; + /// VDOP + uint8_t vdop; +}; + +/// LN Control Point Request +struct lan_ln_ctnl_pt_req +{ + /// Operation code @see enum lanp_ln_ctnl_pt_code + uint8_t op_code; + + /// Value + union lanp_ln_ctnl_pt_req_val + { + /// Cumulative Value (24 bits) + uint32_t cumul_val; + /// Mask Content + uint16_t mask_content; + /// Navigation Control @see enum lanp_navi_ctrl_val + uint8_t control_value; + /// Route number + uint16_t route_number; + /// Fix rate + uint8_t fix_rate; + /// Elevation + int32_t elevation; + } value; +}; + +/// LAN Control Point Response +struct lanp_ln_ctnl_pt_rsp +{ + /// Operation code - Response Code (0x20) + uint8_t op_code; + /// Operation code + uint8_t req_op_code; + /// Response Value + uint8_t resp_value; + + /// Value + union lanp_ctnl_pt_rsp_val + { + /// Number of routes + uint16_t number_of_routes; + + struct lanp_route_name + { + uint8_t length; + /// Name of Route UTF-8 + uint8_t name[__ARRAY_EMPTY]; + } route; + } value; +}; + +/// LAN Navigation +struct lanp_navigation +{ + /// Flags + uint16_t flags; + /// Bearing + uint16_t bearing; + /// Heading + uint16_t heading; + /// Remaining Distance (24 bits) + uint32_t remaining_distance; + /// Remaining Vertical Distance (24 bits) + uint32_t remaining_ver_distance; + /// Estimated Time of Arrival + struct prf_date_time estimated_arrival_time; +}; + + +/// @} lanp_common + +#endif //(_LANP_COMMON_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/api/lanc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/api/lanc_task.h new file mode 100644 index 0000000..4b0b58e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/api/lanc_task.h @@ -0,0 +1,226 @@ +/** + **************************************************************************************** + * + * @file lanc_task.h + * + * @brief Header file - Location and Navigation Profile Collector Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _LANC_TASK_H_ +#define _LANC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup LANCTASK Location and Navigation Profile Collector Task + * @ingroup LANC + * @brief Location and Navigation Profile Collector Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "lan_common.h" +#include "rwip_task.h" // Task definitions + + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Location and Navigation Service Characteristic Descriptors +enum lanc_lns_descs +{ + /// Location and Speed Char. - Client Characteristic Configuration + LANC_DESC_LOC_SPEED_CL_CFG, + /// LN Control Point Char. - Client Characteristic Configuration + LANC_DESC_LN_CTNL_PT_CL_CFG, + /// Navigation Char. - Client Characteristic Configuration + LANC_DESC_NAVIGATION_CL_CFG, + + LANC_DESC_MAX, + + LANC_DESC_MASK = 0x10, +}; + +/// Message IDs +/*@TRACE*/ +enum lanc_msg_ids +{ + /// Enable the Location and Navigation Profile Collector task - at connection + LANC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_LANC), + /// Confirm that cfg connection has finished with discovery results, or that normal cnx started + LANC_ENABLE_RSP, + + /// Read the value of an attribute in the peer device database + LANC_READ_CMD, + /// Configure sending of notification or indication + LANC_CFG_NTFIND_CMD, + + /// Configure the SC Control Point value + LANC_LN_CTNL_PT_CFG_CMD, + /// Indicate that an control point response has been triggered by peer device + LANC_LN_CTNL_PT_IND, + + /// Indicate that an attribute value has been received either upon notification or read response + LANC_VALUE_IND, + + /// Complete Event Information + LANC_CMP_EVT, + + /// Procedure Timeout Timer + LANC_TIMEOUT_TIMER_IND, +}; + +/// Operation Codes +enum lanc_op_code +{ + /// Reserved operation code + LANC_RESERVED_OP_CODE = 0x00, + + /// Discovery Procedure + LANC_ENABLE_OP_CODE, + /// Read attribute value Procedure + LANC_READ_OP_CODE, + + /// Wait for the Write Response after having written a Client Char. Cfg. Descriptor. + LANC_CFG_NTF_IND_OP_CODE, + + /// Wait for the Write Response after having written the Control Point Char. + LANC_LN_CTNL_PT_CFG_WR_OP_CODE, + /// Wait for the Indication Response after having written the Control Point Char. + LANC_LN_CTNL_PT_CFG_IND_OP_CODE, +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Location and Navigation Service + */ +struct lanc_lns_content +{ + /// Service info + struct prf_svc svc; + + /// Characteristic info: + /// - LN Feature + /// - Location and Speed + /// - Position quality + /// - LN Control Point + /// - Navigation + struct prf_char_inf chars[LANP_LANS_CHAR_MAX]; + + /// Descriptor handles: + /// - Location and Speed Client Cfg + /// - Control Point Client Cfg + /// - Navigation Client Cfg + struct prf_char_desc_inf descs[LANC_DESC_MAX]; +}; + +/// Parameters of the @ref LANC_ENABLE_REQ message +struct lanc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values LNS + struct lanc_lns_content lans; +}; + +/// Parameters of the @ref LANC_ENABLE_RSP message +struct lanc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values LNS + struct lanc_lns_content lns; +}; + +/// Parameters of the @ref LANC_READ_CMD message +struct lanc_read_cmd +{ + /// Operation Code + uint8_t operation; + /// Read code + uint8_t read_code; +}; + +/// Parameters of the @ref LANC_VALUE_IND message +struct lanc_value_ind +{ + /// Attribute Code + uint8_t att_code; + /// Value + union lanc_value_tag + { + /// LN Feature + uint32_t LN_feat; + /// Location and Speed + struct lanp_loc_speed loc_speed; + /// LAN Position quality + struct lanp_posq pos_q; + /// Navigation + struct lanp_navigation navigation; + /// Client Characteristic Configuration Descriptor Value + uint16_t ntf_cfg; + } value; +}; + +/// Parameters of the @ref LANC_CFG_NTFIND_CMD message +struct lanc_cfg_ntfind_cmd +{ + /// Operation Code + uint8_t operation; + /// Descriptor code + uint8_t desc_code; + /// Ntf/Ind Configuration + uint16_t ntfind_cfg; +}; + +/// Parameters of the @ref LANC_LN_CTNL_PT_CFG_CMD message +struct lanc_ln_ctnl_pt_cfg_cmd +{ + /// Operation Code + uint8_t operation; + /// SC Control Point Request + struct lan_ln_ctnl_pt_req ln_ctnl_pt; +}; + +/// Parameters of the @ref LANC_LN_CTNL_PT_IND message +struct lanc_ln_ctnl_pt_ind +{ + /// SC Control Point Response + struct lanp_ln_ctnl_pt_rsp rsp; +}; + +/// Parameters of the @ref LANC_CMP_EVT message +struct lanc_cmp_evt +{ + /// Operation code + uint8_t operation; + /// Status + uint8_t status; +}; + + + +/// @} LANCTASK + +#endif //(_LANC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/sourcelist.txt new file mode 100644 index 0000000..88803f7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + lanc.c + lanc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/src/lanc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/src/lanc.c new file mode 100644 index 0000000..1f6de54 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/src/lanc.c @@ -0,0 +1,710 @@ +/** + **************************************************************************************** + * + * @file lanc.c + * + * @brief Location and Navigation Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup LANC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_LN_COLLECTOR) +#include "lan_common.h" + +#include "lanc.h" +#include "lanc_task.h" + +#include "ke_timer.h" +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLES DECLARATION + **************************************************************************************** + */ + + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the LANC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ + +static uint8_t lanc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct lanc_env_tag *p_lanc_env = + (struct lanc_env_tag *) ke_malloc(sizeof(struct lanc_env_tag), KE_MEM_ATT_DB); + + // allocate LANC required environment variable + p_env->env = (prf_env_t *) p_lanc_env; + + p_lanc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_lanc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_LANC; + lanc_task_init(&(p_env->desc)); + + for (idx = 0; idx < LANC_IDX_MAX ; idx++) + { + p_lanc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), LANC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void lanc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct lanc_env_tag *p_lanc_env = (struct lanc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_lanc_env->p_env[conidx] != NULL) + { + if (p_lanc_env->p_env[conidx]->p_operation != NULL) + { + ke_free(ke_param2msg(p_lanc_env->p_env[conidx]->p_operation)); + } + ke_timer_clear(LANC_TIMEOUT_TIMER_IND, prf_src_task_get(&p_lanc_env->prf_env, conidx)); + + ke_free(p_lanc_env->p_env[conidx]); + p_lanc_env->p_env[conidx] = NULL; + } + + // Put LAN Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), LANC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the LANC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void lanc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct lanc_env_tag *p_lanc_env = (struct lanc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < LANC_IDX_MAX ; idx++) + { + lanc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_lanc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void lanc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put LAN Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), LANC_IDLE); +} + + +/// LANC Task interface required by profile manager +const struct prf_task_cbs lanc_itf = +{ + lanc_init, + lanc_destroy, + lanc_create, + lanc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *lanc_prf_itf_get(void) +{ + return &lanc_itf; +} + +void lanc_enable_rsp_send(struct lanc_env_tag *p_lanc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on LANS + struct lanc_enable_rsp *p_rsp = KE_MSG_ALLOC( + LANC_ENABLE_RSP, + prf_dst_task_get(&(p_lanc_env->prf_env), conidx), + prf_src_task_get(&(p_lanc_env->prf_env), conidx), + lanc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->lns = p_lanc_env->p_env[conidx]->lans; + // Register LANC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_lanc_env->prf_env), conidx, &(p_lanc_env->p_env[conidx]->lans.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_lanc_env->prf_env), conidx), LANC_IDLE); + } + + ke_msg_send(p_rsp); +} + +void lanc_send_no_conn_cmp_evt(uint8_t src_id, uint8_t dest_id, uint8_t operation) +{ + // Send the message + struct lanc_cmp_evt *p_evt = KE_MSG_ALLOC(LANC_CMP_EVT, + dest_id, src_id, + lanc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = PRF_ERR_REQ_DISALLOWED; + + ke_msg_send(p_evt); +} + +void lanc_send_cmp_evt(struct lanc_env_tag *p_lanc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct lanc_cmp_evt *p_evt; + + // Free the stored operation if needed + if (p_lanc_env->p_env[conidx]->p_operation != NULL) + { + ke_msg_free(ke_param2msg(p_lanc_env->p_env[conidx]->p_operation)); + p_lanc_env->p_env[conidx]->p_operation = NULL; + } + + // Go back to the CONNECTED state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_lanc_env->prf_env), conidx)) == LANC_BUSY) + { + ke_state_set(prf_src_task_get(&(p_lanc_env->prf_env), conidx), LANC_IDLE); + } + + // Send the message + p_evt = KE_MSG_ALLOC(LANC_CMP_EVT, + prf_dst_task_get(&(p_lanc_env->prf_env), conidx), + prf_src_task_get(&(p_lanc_env->prf_env), conidx), + lanc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +uint16_t lanc_get_read_handle_req (struct lanc_env_tag *p_lanc_env, uint8_t conidx, struct lanc_read_cmd *p_param) +{ + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + + switch (p_param->read_code) + { + // Read LN Feature + case (LANC_RD_LN_FEAT): + { + handle = p_lanc_env->p_env[conidx]->lans.chars[LANP_LANS_LN_FEAT_CHAR].val_hdl; + } break; + + // Read Position Quality + case (LANC_RD_POS_Q): + { + handle = p_lanc_env->p_env[conidx]->lans.chars[LANP_LANS_POS_Q_CHAR].val_hdl; + } break; + + // Read Location and Speed Characteristic Client Char. Cfg. Descriptor Value + case (LANC_RD_WR_LOC_SPEED_CL_CFG): + { + handle = p_lanc_env->p_env[conidx]->lans.descs[LANC_DESC_LOC_SPEED_CL_CFG].desc_hdl; + } break; + + // Read Unread Alert Characteristic Client Char. Cfg. Descriptor Value + case (LANC_RD_WR_LN_CTNL_PT_CFG): + { + handle = p_lanc_env->p_env[conidx]->lans.descs[LANC_DESC_LN_CTNL_PT_CL_CFG].desc_hdl; + } break; + + // Read Navigation Characteristic Server Char. Cfg. Descriptor Value + case (LANC_RD_WR_NAVIGATION_CFG): + { + handle = p_lanc_env->p_env[conidx]->lans.descs[LANC_DESC_NAVIGATION_CL_CFG].desc_hdl; + } break; + + default: + { + handle = ATT_INVALID_SEARCH_HANDLE; + } break; + } + + return handle; +} + +uint8_t lanc_get_write_desc_handle_req (uint8_t conidx, struct lanc_cfg_ntfind_cmd *p_param, + struct lanc_env_tag *p_lanc_env, uint16_t *p_handle) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + switch(p_param->desc_code) + { + // Write Location and speed Characteristic Client Char. Cfg. Descriptor Value + case (LANC_RD_WR_LOC_SPEED_CL_CFG): + { + if (p_param->ntfind_cfg <= PRF_CLI_START_NTF) + { + *p_handle = p_lanc_env->p_env[conidx]->lans.descs[LANC_DESC_LOC_SPEED_CL_CFG].desc_hdl; + + // The descriptor is mandatory + ASSERT_ERR(*p_handle != ATT_INVALID_SEARCH_HANDLE); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write LN Control Point Characteristic Client Char. Cfg. Descriptor Value + case (LANC_RD_WR_LN_CTNL_PT_CFG): + { + if ((p_param->ntfind_cfg == PRF_CLI_STOP_NTFIND) || + (p_param->ntfind_cfg == PRF_CLI_START_IND)) + { + *p_handle = p_lanc_env->p_env[conidx]->lans.descs[LANC_DESC_LN_CTNL_PT_CL_CFG].desc_hdl; + + if (*p_handle == ATT_INVALID_SEARCH_HANDLE) + { + // The descriptor has not been found. + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write Navigation Characteristic Client Char. Cfg. Descriptor Value + case (LANC_RD_WR_NAVIGATION_CFG): + { + if (p_param->ntfind_cfg <= PRF_CLI_START_NTF) + { + *p_handle = p_lanc_env->p_env[conidx]->lans.descs[LANC_DESC_NAVIGATION_CL_CFG].desc_hdl; + + if (*p_handle == ATT_INVALID_SEARCH_HANDLE) + { + // The descriptor has not been found. + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + return (status); +} + +uint8_t lanc_unpack_loc_speed_ind (uint8_t conidx, struct gattc_event_ind const *p_param, + struct lanc_env_tag *p_lanc_env) +{ + // Offset + uint8_t offset = LANP_LAN_LOC_SPEED_MIN_LEN; + + // LN Measurement value has been received + struct lanc_value_ind *p_ind = KE_MSG_ALLOC(LANC_VALUE_IND, + prf_dst_task_get(&(p_lanc_env->prf_env), conidx), + prf_src_task_get(&(p_lanc_env->prf_env), conidx), + lanc_value_ind); + + // Attribute code + p_ind->att_code = LANC_NTF_LOC_SPEED; + + if ((p_param->length >= LANP_LAN_LOC_SPEED_MIN_LEN) && + (p_param->length <= LANP_LAN_LOC_SPEED_MAX_LEN)) + { + // Flags + p_ind->value.loc_speed.flags = co_read16p(&p_param->value[0]); + + if (GETB(p_ind->value.loc_speed.flags, LANP_LSPEED_INST_SPEED_PRESENT)) + { + // Unpack instantaneous speed + p_ind->value.loc_speed.inst_speed = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (GETB(p_ind->value.loc_speed.flags, LANP_LSPEED_TOTAL_DISTANCE_PRESENT)) + { + // Unpack Total distance (24 bits) + p_ind->value.loc_speed.total_dist = co_read24p(&p_param->value[offset]); + offset += 3; + } + + if (GETB(p_ind->value.loc_speed.flags, LANP_LSPEED_LOCATION_PRESENT)) + { + // Unpack Location + p_ind->value.loc_speed.latitude = co_read32p(&p_param->value[offset]); + offset += 4; + p_ind->value.loc_speed.longitude = co_read32p(&p_param->value[offset]); + offset += 4; + } + + if (GETB(p_ind->value.loc_speed.flags, LANP_LSPEED_ELEVATION_PRESENT)) + { + // Unpack Elevation (24 bits) + p_ind->value.loc_speed.elevation = co_read24p(&p_param->value[offset]); + offset += 3; + } + + if (GETB(p_ind->value.loc_speed.flags, LANP_LSPEED_HEADING_PRESENT)) + { + // Unpack heading + p_ind->value.loc_speed.heading = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (GETB(p_ind->value.loc_speed.flags, LANP_LSPEED_ROLLING_TIME_PRESENT)) + { + // Unpack rolling time + p_ind->value.loc_speed.rolling_time = p_param->value[offset]; + offset++; + } + + if (GETB(p_ind->value.loc_speed.flags, LANP_LSPEED_UTC_TIME_PRESENT)) + { + //Unpack UTC time + offset += prf_unpack_date_time( + (uint8_t *) &(p_param->value[offset]), &(p_ind->value.loc_speed.date_time)); + } + } + + // Send the message + ke_msg_send(p_ind); + + return offset; +} + +uint8_t lanc_unpack_navigation_ind (uint8_t conidx, struct gattc_event_ind const *p_param, + struct lanc_env_tag *p_lanc_env) +{ + // Offset + uint8_t offset = LANP_LAN_NAVIGATION_MIN_LEN; + + // LN Measurement value has been received + struct lanc_value_ind *p_ind = KE_MSG_ALLOC(LANC_VALUE_IND, + prf_dst_task_get(&(p_lanc_env->prf_env), conidx), + prf_src_task_get(&(p_lanc_env->prf_env), conidx), + lanc_value_ind); + + // Attribute code + p_ind->att_code = LANC_NTF_NAVIGATION; + + if ((p_param->length >= LANP_LAN_NAVIGATION_MIN_LEN) && + (p_param->length <= LANP_LAN_NAVIGATION_MAX_LEN)) + { + // Flags + p_ind->value.navigation.flags = co_read16p(&p_param->value[0]); + // Bearing + p_ind->value.navigation.bearing = co_read16p(&p_param->value[2]); + // Heading + p_ind->value.navigation.heading = co_read16p(&p_param->value[4]); + + if (GETB(p_ind->value.navigation.flags, LANP_NAVI_REMAINING_DIS_PRESENT)) + { + //Unpack remaining distance (24 bits) + p_ind->value.navigation.remaining_distance = co_read24p(&p_param->value[offset]); + offset += 3; + } + + if (GETB(p_ind->value.navigation.flags, LANP_NAVI_REMAINING_VER_DIS_PRESENT)) + { + // Unpack remaining vertical distance (24 bits) + p_ind->value.navigation.remaining_ver_distance = co_read24p(&p_param->value[offset]); + offset += 3; + } + + if (GETB(p_ind->value.navigation.flags, LANP_NAVI_ESTIMATED_TIME_OF_ARRIVAL_PRESENT)) + { + //Unpack time + offset += prf_unpack_date_time( + (uint8_t *) &(p_param->value[offset]), &(p_ind->value.navigation.estimated_arrival_time)); + } + } + + // Send the message + ke_msg_send(p_ind); + + return offset; +} + + +uint8_t lanc_unpack_pos_q_ind (struct gattc_read_ind const *p_param, struct lanc_value_ind *p_ind) +{ + /*---------------------------------------------------- + * Unpack Position Quality --------------------------- + *----------------------------------------------------*/ + // Offset + uint8_t offset = LANP_LAN_POSQ_MIN_LEN; + + // Flags + p_ind->value.pos_q.flags = co_read16p(&p_param->value[0]); + + if (GETB(p_ind->value.pos_q.flags, LANP_POSQ_NUMBER_OF_BEACONS_IN_SOLUTION_PRESENT)) + { + //Unpack beacons in solution + p_ind->value.pos_q.n_beacons_solution = p_param->value[offset]; + offset++; + } + + if (GETB(p_ind->value.pos_q.flags, LANP_POSQ_NUMBER_OF_BEACONS_IN_VIEW_PRESENT)) + { + //Unpack beacons in view + p_ind->value.pos_q.n_beacons_view = p_param->value[offset]; + offset++; + } + + if (GETB(p_ind->value.pos_q.flags, LANP_POSQ_TIME_TO_FIRST_FIX_PRESENT)) + { + //Unpack time first fix + p_ind->value.pos_q.time_first_fix = co_read16p(&p_param->value[offset]); + offset += 2; + } + + if (GETB(p_ind->value.pos_q.flags, LANP_POSQ_EHPE_PRESENT)) + { + //Unpack ehpe + p_ind->value.pos_q.ehpe = co_read32p(&p_param->value[offset]); + offset += 4; + } + + if (GETB(p_ind->value.pos_q.flags, LANP_POSQ_EVPE_PRESENT)) + { + //Unpack evpe + p_ind->value.pos_q.evpe = co_read32p(&p_param->value[offset]); + offset += 4; + } + + if (GETB(p_ind->value.pos_q.flags, LANP_POSQ_HDOP_PRESENT)) + { + //Unpack hdop + p_ind->value.pos_q.hdop = p_param->value[offset]; + offset++; + } + + if (GETB(p_ind->value.pos_q.flags, LANP_POSQ_VDOP_PRESENT)) + { + //Unpack vdop + p_ind->value.pos_q.vdop = p_param->value[offset]; + offset++; + } + + return offset; +} + +uint8_t lanc_pack_ln_ctnl_pt_req (struct lanc_ln_ctnl_pt_cfg_cmd *p_param, uint8_t *p_req, uint8_t *p_status) +{ + // Request Length + uint8_t req_len = LANP_LAN_LN_CNTL_PT_REQ_MIN_LEN; + + // Set the operation code + p_req[0] = p_param->ln_ctnl_pt.op_code; + + // Fulfill the message according to the operation code + switch (p_param->ln_ctnl_pt.op_code) + { + case (LANP_LN_CTNL_PT_SET_CUMUL_VALUE): + { + // Set the cumulative value (24 bits) + co_write24p(&p_req[req_len], p_param->ln_ctnl_pt.value.cumul_val); + // Update length + req_len += 3; + } break; + + case (LANP_LN_CTNL_PT_MASK_LSPEED_CHAR_CT): + { + // Set mask content + co_write16p(&p_req[req_len], p_param->ln_ctnl_pt.value.mask_content); + // Update length + req_len += 2; + } break; + + case (LANP_LN_CTNL_PT_NAVIGATION_CONTROL): + { + // Set control value + p_req[req_len] = p_param->ln_ctnl_pt.value.control_value; + // Update length + req_len++; + } break; + + case (LANP_LN_CTNL_PT_REQ_NAME_OF_ROUTE): + case (LANP_LN_CTNL_PT_SELECT_ROUTE): + { + // Set route number + co_write16p(&p_req[req_len], p_param->ln_ctnl_pt.value.route_number); + // Update length + req_len += 2; + } break; + + case (LANP_LN_CTNL_PT_SET_FIX_RATE): + { + // Set the fix rate + p_req[req_len] = p_param->ln_ctnl_pt.value.fix_rate; + // Update length + req_len++; + } break; + + case (LANP_LN_CTNL_PT_SET_ELEVATION): + { + // Set elevation (24 bits) + co_write24p(&p_req[req_len], p_param->ln_ctnl_pt.value.elevation); + // Update length + req_len += 3; + } break; + + case (LANP_LN_CTNL_PT_REQ_NUMBER_OF_ROUTES): + { + // Nothing more to do + } break; + + default: + { + *p_status = PRF_ERR_INVALID_PARAM; + } break; + } + + return req_len; +} + +uint8_t lanc_unpack_ln_ctln_pt_ind (struct gattc_event_ind const *p_param, ke_task_id_t src, ke_task_id_t dest) +{ + // Offset + uint8_t offset = LANP_LAN_LN_CNTL_PT_RSP_MIN_LEN; + + // Control Point value has been received + struct lanc_ln_ctnl_pt_ind *p_ind = KE_MSG_ALLOC_DYN(LANC_LN_CTNL_PT_IND, + dest, + src, + lanc_ln_ctnl_pt_ind, + p_param->length); + // Response Op code + p_ind->rsp.op_code = p_param->value[0]; + // Requested operation code + p_ind->rsp.req_op_code = p_param->value[1]; + // Response value + p_ind->rsp.resp_value = p_param->value[2]; + + + if ((p_ind->rsp.resp_value == LANP_LN_CTNL_PT_RESP_SUCCESS) && (p_param->length >= 3)) + { + switch (p_ind->rsp.req_op_code) + { + case (LANP_LN_CTNL_PT_REQ_NUMBER_OF_ROUTES): + { + p_ind->rsp.value.number_of_routes = co_read16p(&p_param->value[offset]); + offset += 2; + + } break; + + case (LANP_LN_CTNL_PT_REQ_NAME_OF_ROUTE): + { + // Get the length of the route + p_ind->rsp.value.route.length = (p_param->length - 3); + + for (int i = 0; i < p_ind->rsp.value.route.length; i++) + { + p_ind->rsp.value.route.name[i] = p_param->value[i + 3]; + offset++; + } + } break; + + case (LANP_LN_CTNL_PT_SET_CUMUL_VALUE): + case (LANP_LN_CTNL_PT_MASK_LSPEED_CHAR_CT): + case (LANP_LN_CTNL_PT_NAVIGATION_CONTROL): + case (LANP_LN_CTNL_PT_SELECT_ROUTE): + case (LANP_LN_CTNL_PT_SET_FIX_RATE): + case (LANP_LN_CTNL_PT_SET_ELEVATION): + { + // No parameters + } break; + + default: + { + + } break; + } + } + + // Send the message + ke_msg_send(p_ind); + + return offset; +} +#endif //(BLE_LN_COLLECTOR) + +/// @} LAN diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/src/lanc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/src/lanc.h new file mode 100644 index 0000000..9cb81c3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/src/lanc.h @@ -0,0 +1,285 @@ +/** + **************************************************************************************** + * + * @file lanc.h + * + * @brief Header file - Location and Navigation Status Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _LANC_H_ +#define _LANC_H_ + +/** + **************************************************************************************** + * @addtogroup LANC Location and Navigation Profile Collector + * @ingroup LAN + * @brief Location and Navigation Profile Collector + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#if (BLE_LN_COLLECTOR) + +#include "lan_common.h" +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" +#include "lanc_task.h" + + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Location and Navigation Collector task instances +#define LANC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * ENUMERATIONS + **************************************************************************************** + */ +/// Possible states of the LANC task +enum lanc_states +{ + /// Idle state + LANC_FREE, + /// Connected state + LANC_IDLE, + /// SDP state + LANC_DISCOVERING, + /// Busy state + LANC_BUSY, + + /// Number of defined states. + LANC_STATE_MAX +}; + + +/// Internal codes for reading/writing a LNS characteristic with one single request +enum lanc_code +{ + /// Read LN Feature + LANC_RD_LN_FEAT = LANP_LANS_LN_FEAT_CHAR, + /// Notified Location and Speed + LANC_NTF_LOC_SPEED = LANP_LANS_LOC_SPEED_CHAR, + /// Read Position quality + LANC_RD_POS_Q = LANP_LANS_POS_Q_CHAR, + /// Indicated LN Control Point + LANC_IND_LN_CTNL_PT = LANP_LANS_LN_CTNL_PT_CHAR, + /// Notified Navigation + LANC_NTF_NAVIGATION = LANP_LANS_NAVIG_CHAR, + + /// Read/Write Location and Speed Client Char. Configuration Descriptor + LANC_RD_WR_LOC_SPEED_CL_CFG = (LANC_DESC_LOC_SPEED_CL_CFG | LANC_DESC_MASK), + + /// Read LN Control Point Client Char. Configuration Descriptor + LANC_RD_WR_LN_CTNL_PT_CFG = (LANC_DESC_LN_CTNL_PT_CL_CFG | LANC_DESC_MASK), + + /// Read/Write Vector Client Char. Configuration Descriptor + LANC_RD_WR_NAVIGATION_CFG = (LANC_DESC_NAVIGATION_CL_CFG | LANC_DESC_MASK), + +}; + + +/* + * STRUCTURES + **************************************************************************************** + */ + +struct lanc_cnx_env +{ + ///Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Counter used to check service uniqueness + uint8_t nb_svc; + /// Location and Navigation Service Characteristics + struct lanc_lns_content lans; + /// Current Operation + void *p_operation; +}; + +/// Location and Navigation Profile Collector environment variable +struct lanc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct lanc_cnx_env *p_env[LANC_IDX_MAX]; + /// State of different task instances + ke_state_t state[LANC_IDX_MAX]; +}; + +/// Command Message Basic Structure +struct lanc_cmd +{ + /// Operation Code + uint8_t operation; + + // MORE DATA +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve LAN client profile interface + * + * @return LAN client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *lanc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Location and Navigation ATT DB discovery results to LANC host. + * @param[in] p_lanc_env environment variable + * @param[in] conidx Connection index + * @param[in] status Status + * @return handle + **************************************************************************************** + */ +void lanc_enable_rsp_send(struct lanc_env_tag *p_lanc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send a LANC_CMP_EVT message when no connection exists (no environment) + * @param[in] src_id Source task + * @param[in] dest_id Destination task + * @param[in] operation Operation + **************************************************************************************** + */ +void lanc_send_no_conn_cmp_evt(uint8_t src_id, uint8_t dest_id, uint8_t operation); + +/** + **************************************************************************************** + * @brief Send a LANC_CMP_EVT message to the task which enabled the profile + * @param[in] p_lanc_env environment variable + * @param[in] conidx Connection index + * @param[in] operation Operation + * @param[in] status Status + * @return handle + **************************************************************************************** + */ +void lanc_send_cmp_evt(struct lanc_env_tag *p_lanc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/** + **************************************************************************************** + * @brief Gets correct read handle according to the request + * @param[in] p_lanc_env environment variable + * @param[in] conidx Connection index + * @param[in] p_param Pointer to the parameters of the message. + * @return handle + **************************************************************************************** + */ +uint16_t lanc_get_read_handle_req (struct lanc_env_tag *p_lanc_env, uint8_t conidx, struct lanc_read_cmd *p_param); + +/** + **************************************************************************************** + * @brief Gets correct write handle according to the request + * @param[in] conidx Connection index + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] p_lanc_env environment variable + * @param[out] p_handle handle + * @return handle + **************************************************************************************** + */ +uint8_t lanc_get_write_desc_handle_req (uint8_t conidx, struct lanc_cfg_ntfind_cmd *p_param, + struct lanc_env_tag *p_lanc_env, uint16_t *p_handle); + +/** + **************************************************************************************** + * @brief Unpacks location and speed data and sends the indication + * @param[in] conidx Connection index + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] p_lanc_env environment variable + * @return length + **************************************************************************************** + */ +uint8_t lanc_unpack_loc_speed_ind (uint8_t conidx, struct gattc_event_ind const *p_param, + struct lanc_env_tag *p_lanc_env); + +/** + **************************************************************************************** + * @brief Unpacks Navigation and sends the indication + * @param[in] conidx Connection index + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] p_lanc_env environment variable + * @return length + **************************************************************************************** + */ +uint8_t lanc_unpack_navigation_ind (uint8_t conidx, struct gattc_event_ind const *p_param, + struct lanc_env_tag *p_lanc_env); + +/** + **************************************************************************************** + * @brief Unpacks position quality + * @param[in] p_param Pointer to the parameters of the message + * @param[out] p_ind Pointer to the value indication + * @return length + **************************************************************************************** + */ +uint8_t lanc_unpack_pos_q_ind (struct gattc_read_ind const *p_param, struct lanc_value_ind *p_ind); + +/** + **************************************************************************************** + * @brief Packs Control Point data + * @param[in] p_param Pointer to the parameters of the message. + * @param[out] p_req packed message + * @param[out] p_status status of the operation + * @return length + **************************************************************************************** + */ +uint8_t lanc_pack_ln_ctnl_pt_req (struct lanc_ln_ctnl_pt_cfg_cmd *p_param, uint8_t *p_req, uint8_t *p_status); + +/** + **************************************************************************************** + * @brief Unpacks Control Point data and sends the indication + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] src Source task + * @param[in] dest Destination task + * @return length + **************************************************************************************** + */ +uint8_t lanc_unpack_ln_ctln_pt_ind (struct gattc_event_ind const *p_param, ke_task_id_t src, ke_task_id_t dest); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void lanc_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_LN_COLLECTOR) + +/// @} LANC + +#endif //(_LANC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/src/lanc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/src/lanc_task.c new file mode 100644 index 0000000..58d4460 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lanc/src/lanc_task.c @@ -0,0 +1,796 @@ +/** + **************************************************************************************** + * + * @file lanc_task.c + * + * @brief Location and Navigation Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup LANCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_LN_COLLECTOR) +#include "lan_common.h" + +#include "gap.h" +#include "attm.h" +#include "lanc_task.h" +#include "lanc.h" +#include "gattc_task.h" +#include "ke_timer.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve Location and Navigation service characteristics information +const struct prf_char_def lanc_lns_char[LANP_LANS_CHAR_MAX] = +{ + /// LN Feature + [LANP_LANS_LN_FEAT_CHAR] = {ATT_CHAR_LN_FEAT, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, + /// LN Measurement + [LANP_LANS_LOC_SPEED_CHAR] = {ATT_CHAR_LOC_SPEED, + ATT_MANDATORY, + ATT_CHAR_PROP_NTF}, + /// Position Quality + [LANP_LANS_POS_Q_CHAR] = {ATT_CHAR_POS_QUALITY, + ATT_OPTIONAL, + ATT_CHAR_PROP_RD}, + /// SC Control Point + [LANP_LANS_LN_CTNL_PT_CHAR] = {ATT_CHAR_LN_CNTL_PT, + ATT_OPTIONAL, + ATT_CHAR_PROP_WR | ATT_CHAR_PROP_IND}, + /// Navigation + [LANP_LANS_NAVIG_CHAR] = {ATT_CHAR_NAVIGATION, + ATT_OPTIONAL, + ATT_CHAR_PROP_NTF}, +}; + +/// State machine used to retrieve Location and Navigation service characteristic descriptor information +const struct prf_char_desc_def lanc_lns_char_desc[LANC_DESC_MAX] = +{ + /// Location and Speed Char. - Client Characteristic Configuration + [LANC_DESC_LOC_SPEED_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + LANP_LANS_LOC_SPEED_CHAR}, + + /// Control Point Char. - Client Characteristic Configuration + [LANC_DESC_LN_CTNL_PT_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_OPTIONAL, + LANP_LANS_LN_CTNL_PT_CHAR}, + + /// Navigation Char. - Client Characteristic Configuration + [LANC_DESC_NAVIGATION_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_OPTIONAL, + LANP_LANS_NAVIG_CHAR}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == LANC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + struct lanc_env_tag *p_lanc_env = PRF_ENV_GET(LANC, lanc); + + ASSERT_INFO(p_lanc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_lanc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_lanc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve CPS characteristics and descriptors + prf_extract_svc_info(p_ind, LANP_LANS_CHAR_MAX, &lanc_lns_char[0], + &p_lanc_env->p_env[conidx]->lans.chars[0], + LANC_DESC_MAX, &lanc_lns_char_desc[0], + &p_lanc_env->p_env[conidx]->lans.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_lanc_env->p_env[conidx]->lans.svc.shdl = p_ind->start_hdl; + p_lanc_env->p_env[conidx]->lans.svc.ehdl = p_ind->end_hdl; + } + + p_lanc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref LANC_ENABLE_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int lanc_enable_req_handler(ke_msg_id_t const msgid, + struct lanc_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + // Location and Navigation Profile Collector Role Task Environment + struct lanc_env_tag *p_lanc_env = PRF_ENV_GET(LANC, lanc); + + ASSERT_INFO(p_lanc_env != NULL, dest_id, src_id); + if ((state == LANC_IDLE) && (p_lanc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_lanc_env->p_env[conidx] = (struct lanc_cnx_env*) ke_malloc(sizeof(struct lanc_cnx_env), KE_MEM_ATT_DB); + memset(p_lanc_env->p_env[conidx], 0, sizeof(struct lanc_cnx_env)); + + // Config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + // start discovering CPS on peer + prf_disc_svc_send(&(p_lanc_env->prf_env), conidx, ATT_SVC_LOCATION_AND_NAVIGATION); + + // Go to DISCOVERING state + ke_state_set(dest_id, LANC_DISCOVERING); + } + // normal connection, get saved att details + else + { + p_lanc_env->p_env[conidx]->lans = p_param->lans; + + // send APP confirmation that can start normal connection to TH + lanc_enable_rsp_send(p_lanc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != LANC_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + lanc_enable_rsp_send(p_lanc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref LANC_READ_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int lanc_read_cmd_handler(ke_msg_id_t const msgid, + struct lanc_read_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct lanc_env_tag *p_lanc_env = PRF_ENV_GET(LANC, lanc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == LANC_IDLE) + { + ASSERT_INFO(p_lanc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_lanc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Get the handler + uint16_t hdl = lanc_get_read_handle_req (p_lanc_env, conidx, p_param); + + // Check if handle is viable + if (hdl != ATT_INVALID_SEARCH_HANDLE) + { + // Force the operation value + p_param->operation = LANC_READ_OP_CODE; + + // Store the command structure + p_lanc_env->p_env[conidx]->p_operation = p_param; + msg_status = KE_MSG_NO_FREE; + + // Send the read request + prf_read_char_send(&(p_lanc_env->prf_env), conidx, + p_lanc_env->p_env[conidx]->lans.svc.shdl, + p_lanc_env->p_env[conidx]->lans.svc.ehdl, + hdl); + + // Go to the Busy state + ke_state_set(dest_id, LANC_BUSY); + + status = ATT_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == LANC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send the complete event message to the task id stored in the environment + lanc_send_cmp_evt(p_lanc_env, conidx, LANC_READ_OP_CODE, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref LANC_CFG_NTFIND_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int lanc_cfg_ntfind_cmd_handler(ke_msg_id_t const msgid, + struct lanc_cfg_ntfind_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct lanc_env_tag *p_lanc_env = PRF_ENV_GET(LANC, lanc); + // Message status + int msg_status = KE_MSG_CONSUMED; + + if (p_lanc_env != NULL) + { + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + do + { + if (ke_state_get(dest_id) != LANC_IDLE) + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + break; + } + + ASSERT_ERR(p_lanc_env->p_env[conidx] != NULL); + + // Get handle + status = lanc_get_write_desc_handle_req (conidx, p_param, p_lanc_env, &handle); + } while (0); + + if ((status == GAP_ERR_NO_ERROR) && (handle != ATT_INVALID_SEARCH_HANDLE)) + { + // Set the operation code + p_param->operation = LANC_CFG_NTF_IND_OP_CODE; + + // Store the command structure + p_lanc_env->p_env[conidx]->p_operation = p_param; + msg_status = KE_MSG_NO_FREE; + + // Go to the Busy state + ke_state_set(dest_id, LANC_BUSY); + + // Send GATT Write Request + prf_gatt_write_ntf_ind(&p_lanc_env->prf_env, conidx, handle, p_param->ntfind_cfg); + } + } + else + { + lanc_send_no_conn_cmp_evt(dest_id, src_id, LANC_CFG_NTF_IND_OP_CODE); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref LANC_LN_CTNL_PT_CFG_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int lanc_ln_ctnl_pt_cfg_cmd_handler(ke_msg_id_t const msgid, + struct lanc_ln_ctnl_pt_cfg_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct lanc_env_tag *p_lanc_env = PRF_ENV_GET(LANC, lanc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_lanc_env != NULL) + { + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + do + { + // State is Connected or Busy + ASSERT_ERR(ke_state_get(dest_id) > LANC_FREE); + + // Check the provided connection handle + if (p_lanc_env->p_env[conidx] == NULL) + { + status = PRF_ERR_INVALID_PARAM; + break; + } + + if (ke_state_get(dest_id) != LANC_IDLE) + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + // Status is PRF_ERR_OK, no message will be sent to the application + break; + } + + // Check if the characteristic has been found + if (p_lanc_env->p_env[conidx]->lans.descs[LANC_DESC_LN_CTNL_PT_CL_CFG].desc_hdl + != ATT_INVALID_SEARCH_HANDLE) + { + // Request array declaration + uint8_t req[LANP_LAN_LN_CNTL_PT_REQ_MAX_LEN]; + // Pack request + uint8_t nb = lanc_pack_ln_ctnl_pt_req(p_param, req, &status); + + if (status == GAP_ERR_NO_ERROR) + { + // Set the operation code + p_param->operation = LANC_LN_CTNL_PT_CFG_WR_OP_CODE; + + // Store the command structure + p_lanc_env->p_env[conidx]->p_operation = p_param; + // Store the command information + msg_status = KE_MSG_NO_FREE; + + // Go to the Busy state + ke_state_set(dest_id, LANC_BUSY); + + // Send the write request + prf_gatt_write(&(p_lanc_env->prf_env), conidx, + p_lanc_env->p_env[conidx]->lans.chars[LANP_LANS_LN_CTNL_PT_CHAR].val_hdl, + (uint8_t *)&req[0], nb, GATTC_WRITE); + } + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } while (0); + + if (status != GAP_ERR_NO_ERROR) + { + // Send a complete event status to the application + lanc_send_cmp_evt(p_lanc_env, conidx, LANC_LN_CTNL_PT_CFG_WR_OP_CODE, status); + } + } + else + { + // No connection + lanc_send_no_conn_cmp_evt(dest_id, src_id, LANC_LN_CTNL_PT_CFG_WR_OP_CODE); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref LANC_TIMEOUT_TIMER_IND message. This message is + * received when the peer device doesn't send a SC Control Point indication within 30s + * after reception of the write response. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int lanc_timeout_timer_ind_handler(ke_msg_id_t const msgid, + void const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct lanc_env_tag *p_lanc_env = PRF_ENV_GET(LANC, lanc); + + if (p_lanc_env != NULL) + { + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_ERR(p_lanc_env->p_env[conidx]->p_operation != NULL); + ASSERT_ERR(((struct lanc_cmd *)p_lanc_env->p_env[conidx]->p_operation)->operation + == LANC_LN_CTNL_PT_CFG_IND_OP_CODE); + + // Send the complete event message + lanc_send_cmp_evt(p_lanc_env, conidx, LANC_LN_CTNL_PT_CFG_WR_OP_CODE, PRF_ERR_PROC_TIMEOUT); + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct lanc_env_tag *p_lanc_env = PRF_ENV_GET(LANC, lanc); + + if (p_lanc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == LANC_DISCOVERING) + { + uint8_t status = p_param->status; + + if ((status == ATT_ERR_ATTRIBUTE_NOT_FOUND) || + (status == ATT_ERR_NO_ERROR)) + { + // Discovery + // check characteristic validity + if(p_lanc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(LANP_LANS_CHAR_MAX, + p_lanc_env->p_env[conidx]->lans.chars, + lanc_lns_char); + } + // too much services + else if (p_lanc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(LANC_DESC_MAX, + p_lanc_env->p_env[conidx]->lans.descs, + lanc_lns_char_desc, + p_lanc_env->p_env[conidx]->lans.chars); + } + } + + lanc_enable_rsp_send(p_lanc_env, conidx, status); + } + else if (state == LANC_BUSY) + { + switch (p_param->operation) + { + case GATTC_READ: + { + // Send the complete event status + lanc_send_cmp_evt(p_lanc_env, conidx, LANC_READ_OP_CODE, p_param->status); + } break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + uint8_t operation = ((struct lanc_cmd *)p_lanc_env->p_env[conidx]->p_operation)->operation; + + if (operation == LANC_CFG_NTF_IND_OP_CODE) + { + // Send the complete event status + lanc_send_cmp_evt(p_lanc_env, conidx, operation, p_param->status); + } + + else if (operation == LANC_LN_CTNL_PT_CFG_WR_OP_CODE) + { + if (p_param->status == GAP_ERR_NO_ERROR) + { + // Start Timeout Procedure + ke_timer_set(LANC_TIMEOUT_TIMER_IND, dest_id, 10*ATT_TRANS_RTX); + + // Wait for the response indication + ((struct lanc_cmd *)p_lanc_env->p_env[conidx]->p_operation)->operation + = LANC_LN_CTNL_PT_CFG_IND_OP_CODE; + } + else + { + // Send the complete event status + lanc_send_cmp_evt(p_lanc_env, conidx, operation, p_param->status); + } + } + } break; + + case GATTC_REGISTER: + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == LANC_BUSY) + { + // Get the address of the environment + struct lanc_env_tag *p_lanc_env = PRF_ENV_GET(LANC, lanc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_lanc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_lanc_env->p_env[conidx] != NULL, dest_id, src_id); + + // Send the read value to the HL + struct lanc_value_ind *p_ind = KE_MSG_ALLOC(LANC_VALUE_IND, + prf_dst_task_get(&(p_lanc_env->prf_env), conidx), + dest_id, + lanc_value_ind); + + switch (((struct lanc_read_cmd *)p_lanc_env->p_env[conidx]->p_operation)->read_code) + { + // Read LN Feature Characteristic value + case (LANC_RD_LN_FEAT): + { + p_ind->value.LN_feat = co_read32p(&p_param->value[0]); + } break; + + // Read Position Quality + case (LANC_RD_POS_Q): + { + // Read position quality + lanc_unpack_pos_q_ind (p_param, p_ind); + } break; + + // Read Client Characteristic Configuration Descriptor value + case (LANC_RD_WR_LOC_SPEED_CL_CFG): + case (LANC_RD_WR_LN_CTNL_PT_CFG): + case (LANC_RD_WR_NAVIGATION_CFG): + { + p_ind->value.ntf_cfg = co_read16p(&p_param->value[0]); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + p_ind->att_code = ((struct lanc_read_cmd *)p_lanc_env->p_env[conidx]->p_operation)->read_code; + + // Send the message to the application + ke_msg_send(p_ind); + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct lanc_env_tag *p_lanc_env = PRF_ENV_GET(LANC, lanc); + + if (p_lanc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + switch (p_param->type) + { + case (GATTC_NOTIFY): + { + if (p_param->handle == p_lanc_env->p_env[conidx]->lans.chars[LANP_LANS_LOC_SPEED_CHAR].val_hdl) + { + //Unpack location and speed + lanc_unpack_loc_speed_ind(conidx, p_param, p_lanc_env); + } + else if (p_param->handle == p_lanc_env->p_env[conidx]->lans.chars[LANP_LANS_NAVIG_CHAR].val_hdl) + { + // Unpack navigation + lanc_unpack_navigation_ind(conidx, p_param, p_lanc_env); + } + else + { + ASSERT_ERR(0); + } + } break; + + case (GATTC_INDICATE): + { + // confirm that indication has been correctly received + struct gattc_event_cfm *p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + + do + { + // Check if we were waiting for the indication + if (p_lanc_env->p_env[conidx]->p_operation == NULL) + { + break; + } + + if (((struct lanc_cmd *)p_lanc_env->p_env[conidx]->p_operation)->operation + != LANC_LN_CTNL_PT_CFG_IND_OP_CODE) + { + break; + } + + // Stop the procedure timeout timer + ke_timer_clear(LANC_TIMEOUT_TIMER_IND, dest_id); + + //Unpack control point + lanc_unpack_ln_ctln_pt_ind(p_param, prf_src_task_get(&(p_lanc_env->prf_env), conidx), + prf_dst_task_get(&(p_lanc_env->prf_env), conidx)); + + // Send the complete event message + lanc_send_cmp_evt(p_lanc_env, conidx, LANC_LN_CTNL_PT_CFG_WR_OP_CODE, GAP_ERR_NO_ERROR); + } while (0); + + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(lanc) +{ + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {LANC_ENABLE_REQ, (ke_msg_func_t)lanc_enable_req_handler}, + {LANC_READ_CMD, (ke_msg_func_t)lanc_read_cmd_handler}, + {LANC_CFG_NTFIND_CMD, (ke_msg_func_t)lanc_cfg_ntfind_cmd_handler}, + {LANC_LN_CTNL_PT_CFG_CMD, (ke_msg_func_t)lanc_ln_ctnl_pt_cfg_cmd_handler}, + {LANC_TIMEOUT_TIMER_IND, (ke_msg_func_t)lanc_timeout_timer_ind_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void lanc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct lanc_env_tag *p_lanc_env = PRF_ENV_GET(LANC, lanc); + + p_task_desc->msg_handler_tab = lanc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(lanc_msg_handler_tab); + p_task_desc->state = p_lanc_env->state; + p_task_desc->idx_max = LANC_IDX_MAX; +} + +#endif //(BLE_LN_COLLECTOR) + +/// @} LANCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/api/lans_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/api/lans_task.h new file mode 100644 index 0000000..3366490 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/api/lans_task.h @@ -0,0 +1,267 @@ +/** + **************************************************************************************** + * + * @file lans_task.h + * + * @brief Header file - Location and Navigation Profile Sensor Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _LANS_TASK_H_ +#define _LANS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup LANSTASK Task + * @ingroup LANS + * @brief Location and Navigation Profile Task. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "lan_common.h" +#include "rwip_task.h" // Task definitions + +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Messages for Location and Navigation Profile Sensor +/*@TRACE*/ +enum lans_msg_id +{ + /// Start the Location and Navigation Profile Server profile + LANS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_LANS), + /// Confirm profile + LANS_ENABLE_RSP, + + /// Update Position Quality + LANS_UPD_POS_Q_REQ, + /// Update Position Quality + LANS_UPD_POS_Q_RSP, + + /// Send a Location and Speed to the peer device (Notification) + LANS_NTF_LOC_SPEED_CMD, + + /// Send a LN Vector to the peer device (Notification) + LANS_NTF_NAVIGATION_CMD, + + /// Send a complete event status to the application + LANS_CMP_EVT, + + /// Indicate that an attribute value has been written + LANS_CFG_NTFIND_IND, + + /// Indicate that Control Point characteristic value has been written + LANS_LN_CTNL_PT_REQ_IND, + /// Application response after receiving a LANS_CTNL_PT_REQ_IND message + LANS_LN_CTNL_PT_CFM, +}; + +/// Operation Code used in the profile state machine +enum lans_op_code +{ + /// Reserved Operation Code + LANS_RESERVED_OP_CODE = 0x00, + + /// Enable Profile Operation Code + LANS_ENABLE_REQ_OP_CODE, + + /// Send Location and Speed Operation Code + LANS_NTF_LOC_SPEED_OP_CODE, + + /// Update Position quality + LANS_UPD_POS_Q_OP_CODE, + + /// Send Navigation Operation Code + LANS_NTF_NAVIGATION_OP_CODE, + + /** + * Control Point Operation + */ + /// Set Cumulative Value + LANS_SET_CUMUL_VALUE_OP_CODE, + /// Mask Location and Speed Characteristic Content + LANS_MASK_LSPEED_CHAR_CT_OP_CODE, + /// Navigation Control + LANS_NAVIGATION_CONTROL_OP_CODE, + /// Request Number of Routes + LANS_REQ_NUMBER_OF_ROUTES_OP_CODE, + /// Request Name of Route + LANS_REQ_NAME_OF_ROUTE_OP_CODE, + /// Select Route + LANS_SELECT_ROUTE_OP_CODE, + /// Set Fix Rate + LANS_SET_FIX_RATE_OP_CODE, + /// Set Elevation + LANS_SET_ELEVATION_OP_CODE, + + /// Error Indication Sent Operation Code + LANS_LN_CTNL_ERR_IND_OP_CODE, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the @ref LANS_CREATE_DB_REQ message +struct lans_db_cfg +{ + /** + * LN Feature Value - Not supposed to be modified during the lifetime of the device + * This bit field is set in order to decide which features are supported: + */ + uint32_t ln_feature; + + /** + * Bit 0 - Enable LN Control Point + * Bit 1 - Enable Navigation Feature + */ + uint8_t prfl_config; +}; + +/// Parameters of the @ref LANS_ENABLE_REQ message +struct lans_enable_req +{ + /// Connection index + uint8_t conidx; + /** + * Profile characteristic configuration: + * Location and speed Characteristic NTF config -- Bit 0 + * LN Control Point Characteristic IND config ---- Bit 1 + * Navigation Characteristic NTF config ---------- Bit 2 + */ + uint16_t prfl_ntf_ind_cfg; +}; + +/// Parameters of the @ref LANS_ENABLE_RSP message +struct lans_enable_rsp +{ + /// Connection index + uint8_t conidx; + /// status + uint8_t status; +}; + +/// Parameters of the @ref LANS_CMP_EVT message +struct lans_cmp_evt +{ + /// Connection index + uint8_t conidx; + /// Operation Code + uint8_t operation; + /// Operation Status + uint8_t status; +}; + +/// Parameters of the @ref LANS_CFG_NTFIND_IND message +struct lans_cfg_ntfind_ind +{ + /// Connection index + uint8_t conidx; + /// Characteristic Code (Location and speed, Control Point or navigation) + uint8_t char_code; + /// Char. Client Characteristic Configuration + uint16_t ntf_cfg; +}; + +/// Parameters of the @ref LANS_NTF_LOC_SPEED_CMD message +struct lans_ntf_loc_speed_cmd +{ + ///Parameters + struct lanp_loc_speed parameters; +}; + +/// Parameters of the @ref LANS_NTF_NAVIGATION_CMD message +struct lans_ntf_navigation_cmd +{ + ///Parameters + struct lanp_navigation parameters; +}; + +/// Parameters of the @ref LANS_UPD_POS_Q_REQ message +struct lans_upd_pos_q_req +{ + ///Parameters + struct lanp_posq parameters; +}; + +/// Parameters of the @ref LANS_UPD_POS_Q_RSP message +struct lans_upd_pos_q_rsp +{ + /// Operation Status + uint8_t status; +}; + +/// Parameters of the @ref LANS_LN_CTNL_PT_REQ_IND message +struct lans_ln_ctnl_pt_req_ind +{ + /// Connection index + uint8_t conidx; + /// Operation Code @see enum lanp_ln_ctnl_pt_code + uint8_t op_code; + /// Value + union lans_ln_ctnl_pt_req_ind_value + { + /// Cumulative Value (24 bits) + uint32_t cumul_val; + /// Mask Content + uint16_t mask_content; + /// Navigation Control @see enum lanp_navi_ctrl_val + uint8_t control_value; + /// Route number + uint16_t route_number; + /// Fix rate + uint8_t fix_rate; + /// Elevation + int32_t elevation; + } value; +}; + +/// Parameters of the @ref LANS_CTNL_PT_CFM message +struct lans_ln_ctnl_pt_cfm +{ + /// Connection index + uint8_t conidx; + /// Operation Code + uint8_t op_code; + /// Status + uint8_t status; + /// Value + union lans_ln_ctnl_pt_cfm_value + { + /// Number of routes + uint16_t number_of_routes; + /// Mask content + uint16_t mask_lspeed_content; + struct lan_route_name + { + uint8_t length; + /// Name of Route UTF-8 + uint8_t name[__ARRAY_EMPTY]; + } route; + } value; +}; + +/// @} LANSTASK + +#endif //(_LANS_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/sourcelist.txt new file mode 100644 index 0000000..3289885 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + lans.c + lans_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/src/lans.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/src/lans.c new file mode 100644 index 0000000..93966ba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/src/lans.c @@ -0,0 +1,1406 @@ +/** + **************************************************************************************** + * + * @file lans.c + * + * @brief Location and Navigation Profile Sensor implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup LANS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_LN_SENSOR) +#include "lan_common.h" + +#include "gap.h" +#include "gattc_task.h" +#include "gattc.h" +#include "attm.h" +#include "lans.h" +#include "lans_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * CYCLING POWER SERVICE ATTRIBUTES + **************************************************************************************** + */ + +/// Full LANS Database Description - Used to add attributes into the database +static const struct attm_desc lans_att_db[LNS_IDX_NB] = +{ + // Location and Navigation Service Declaration + [LNS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // LN Feature Characteristic Declaration + [LNS_IDX_LN_FEAT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // LN Feature Characteristic Value + [LNS_IDX_LN_FEAT_VAL] = {ATT_CHAR_LN_FEAT, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint32_t)}, + + // Location and Speed Characteristic Declaration + [LNS_IDX_LOC_SPEED_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Location and Speed Characteristic Value + [LNS_IDX_LOC_SPEED_VAL] = {ATT_CHAR_LOC_SPEED, PERM(NTF, ENABLE), PERM(RI, ENABLE), LANP_LAN_LOC_SPEED_MAX_LEN}, + // Location and Speed Characteristic - Client Characteristic Configuration Descriptor + [LNS_IDX_LOC_SPEED_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Position Quality Characteristic Declaration + [LNS_IDX_POS_Q_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Position Quality Characteristic Value + [LNS_IDX_POS_Q_VAL] = {ATT_CHAR_POS_QUALITY, PERM(RD, ENABLE), PERM(RI, ENABLE), LANP_LAN_POSQ_MAX_LEN}, + + // LN Control Point Characteristic Declaration + [LNS_IDX_LN_CTNL_PT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // LN Control Point Characteristic Value - The response has the maximal length + [LNS_IDX_LN_CTNL_PT_VAL] = {ATT_CHAR_LN_CNTL_PT, PERM(IND, ENABLE) | PERM(WRITE_REQ, ENABLE), + PERM(RI, ENABLE), LANP_LAN_LN_CNTL_PT_RSP_MAX_LEN}, + // LN Control Point Characteristic - Client Characteristic Configuration Descriptor + [LNS_IDX_LN_CTNL_PT_IND_CFG]= {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Navigation Characteristic Declaration + [LNS_IDX_NAVIGATION_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Navigation Characteristic Value + [LNS_IDX_NAVIGATION_VAL] = {ATT_CHAR_NAVIGATION, PERM(NTF, ENABLE), PERM(RI, ENABLE), LANP_LAN_NAVIGATION_MAX_LEN}, + // Navigation Characteristic - Client Characteristic Configuration Descriptor + [LNS_IDX_NAVIGATION_NTF_CFG]= {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the LANS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t lans_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct lans_db_cfg *p_params) +{ + //------------------ create the attribute database for the profile ------------------- + // Service Configuration Flag + uint16_t cfg_flag = LANS_MANDATORY_MASK; + // Database Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + /* + * Check if Position Quality shall be added. + */ + if((GETB(p_params->ln_feature, LANP_FEAT_NUMBER_OF_BEACONS_IN_SOLUTION_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_NUMBER_OF_BEACONS_IN_VIEW_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_TIME_TO_FIRST_FIX_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_ESTIMATED_HOR_POSITION_ERROR_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_ESTIMATED_VER_POSITION_ERROR_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_HOR_DILUTION_OF_PRECISION_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_VER_DILUTION_OF_PRECISION_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_POSITION_STATUS_SUP))) + { + //Add configuration to the database + cfg_flag |= LANS_POS_Q_MASK; + } + + /* + * Check if the Navigation characteristic shall be added. + */ + if ((GETB(p_params->prfl_config, LANS_NAVIGATION_SUPP_FLAG)) || + (GETB(p_params->ln_feature, LANP_FEAT_NUMBER_OF_BEACONS_IN_SOLUTION_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_REMAINING_DISTANCE_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_REMAINING_VERTICAL_DISTANCE_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_ESTIMATED_TIME_OF_ARRIVAL_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_POSITION_STATUS_SUP))) + { + cfg_flag |= LANS_NAVI_MASK; + } + /* + * Check if the LN Control Point characteristic shall be added + */ + if ((LANS_IS_FEATURE_SUPPORTED(cfg_flag, LANS_NAVI_MASK)) || + (GETB(p_params->prfl_config, LANS_CTNL_PT_CHAR_SUPP_FLAG)) || + (GETB(p_params->ln_feature, LANP_FEAT_TOTAL_DISTANCE_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_LSPEED_CHAR_CT_MASKING_SUP)) || + (GETB(p_params->ln_feature, LANP_FEAT_FIX_RATE_SETTING_SUP)) || + ((GETB(p_params->ln_feature, LANP_FEAT_ELEVATION_SUP)) && + (GETB(p_params->ln_feature, LANP_FEAT_ELEVATION_SETTING_SUP)))) + { + cfg_flag |= LANS_LN_CTNL_PT_MASK; + } + + // Add service in the database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_LOCATION_AND_NAVIGATION, (uint8_t *)&cfg_flag, + LNS_IDX_NB, NULL, p_env->task, &lans_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, DISABLE)); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + // Allocate LANS required environment variable + struct lans_env_tag* p_lans_env = + (struct lans_env_tag* ) ke_malloc(sizeof(struct lans_env_tag), KE_MEM_ATT_DB); + + // Initialize LANS environment + p_env->env = (prf_env_t*) p_lans_env; + p_lans_env->shdl = *p_start_hdl; + p_lans_env->prfl_cfg = cfg_flag; + p_lans_env->features = p_params->ln_feature; + p_lans_env->operation = LANS_RESERVED_OP_CODE; + p_lans_env->p_posq = (LANS_IS_FEATURE_SUPPORTED(cfg_flag, LANS_POS_Q_MASK)) ? + (struct lanp_posq *) ke_malloc(sizeof(struct lanp_posq), KE_MEM_ATT_DB) : NULL; + + p_lans_env->p_op_data = NULL; + memset(p_lans_env->env, 0, sizeof(p_lans_env->env)); + + p_lans_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Mono Instantiated task + p_lans_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_LANS; + lans_task_init(&(p_env->desc)); + + // Put CPS in Idle state + ke_state_set(p_env->task, LANS_IDLE); + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the LANS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void lans_destroy(struct prf_task_env *p_env) +{ + struct lans_env_tag *p_lans_env = (struct lans_env_tag *) p_env->env; + + // free profile environment variables + p_env->env = NULL; + + if (p_lans_env->p_posq != NULL) + { + ke_free(p_lans_env->p_posq); + } + + if (p_lans_env->p_op_data != NULL) + { + ke_free(p_lans_env->p_op_data->p_cmd); + + if(p_lans_env->p_op_data->p_ntf_pending) + { + ke_free(p_lans_env->p_op_data->p_ntf_pending); + } + + ke_free(p_lans_env->p_op_data); + } + + ke_free(p_lans_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void lans_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct lans_env_tag *p_lans_env = (struct lans_env_tag *) p_env->env; + + memset(&(p_lans_env->env[conidx]), 0, sizeof(struct lans_cnx_env)); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void lans_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct lans_env_tag *p_lans_env = (struct lans_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + memset(&(p_lans_env->env[conidx]), 0, sizeof(struct lans_cnx_env)); +} + +/// LANS Task interface required by profile manager +const struct prf_task_cbs lans_itf = +{ + (prf_init_fnct) lans_init, + lans_destroy, + lans_create, + lans_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* lans_prf_itf_get(void) +{ + return &lans_itf; +} + +void lans_send_cmp_evt(uint8_t conidx, uint8_t src_id, uint8_t dest_id, uint8_t operation, uint8_t status) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + struct lans_cmp_evt *p_evt; + + // Go back to the Connected state if the state is busy + if (ke_state_get(src_id) == LANS_BUSY) + { + ke_state_set(src_id, LANS_IDLE); + } + + // Set the operation code + p_lans_env->operation = LANS_RESERVED_OP_CODE; + + // Send the message + p_evt = KE_MSG_ALLOC(LANS_CMP_EVT, + dest_id, src_id, + lans_cmp_evt); + + p_evt->conidx = conidx; + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +uint8_t lans_pack_loc_speed_ntf(struct lanp_loc_speed *p_param, uint8_t *p_pckd_loc_speed) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + // Packed Measurement length + uint8_t pckd_loc_speed_len = LANP_LAN_LOC_SPEED_MIN_LEN; + + // Check provided flags + if (GETB(p_param->flags, LANP_LSPEED_INST_SPEED_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_INSTANTANEOUS_SPEED_SUP)) + { + //Pack instantaneous speed + co_write16p(&p_pckd_loc_speed[pckd_loc_speed_len], p_param->inst_speed); + pckd_loc_speed_len += 2; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_param->flags, LANP_LSPEED_INST_SPEED_PRESENT, 0); + } + } + + if (GETB(p_param->flags, LANP_LSPEED_TOTAL_DISTANCE_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_TOTAL_DISTANCE_SUP)) + { + //Pack total distance (24bits) + co_write24p(&p_pckd_loc_speed[pckd_loc_speed_len], p_param->total_dist); + pckd_loc_speed_len += 3; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_param->flags, LANP_LSPEED_TOTAL_DISTANCE_PRESENT, 0); + } + } + + if (GETB(p_param->flags, LANP_LSPEED_LOCATION_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_LOCATION_SUP)) + { + //Pack Location + co_write32p(&p_pckd_loc_speed[pckd_loc_speed_len], p_param->latitude); + pckd_loc_speed_len += 4; + co_write32p(&p_pckd_loc_speed[pckd_loc_speed_len], p_param->longitude); + pckd_loc_speed_len += 4; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_param->flags, LANP_LSPEED_LOCATION_PRESENT, 0); + } + } + + if (GETB(p_param->flags, LANP_LSPEED_ELEVATION_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_ELEVATION_SUP)) + { + //Pack elevation (24 bits) + co_write24p(&p_pckd_loc_speed[pckd_loc_speed_len], p_param->elevation); + pckd_loc_speed_len += 3; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_param->flags, LANP_LSPEED_ELEVATION_PRESENT, 0); + } + } + + if (GETB(p_param->flags, LANP_LSPEED_HEADING_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_HEADING_SUP)) + { + //Pack Extreme Force Magnitudes (Maximum Force Magnitude & Minimum Force Magnitude) + co_write16p(&p_pckd_loc_speed[pckd_loc_speed_len], p_param->heading); + pckd_loc_speed_len += 2; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_param->flags, LANP_LSPEED_HEADING_PRESENT, 0); + } + } + + if (GETB(p_param->flags, LANP_LSPEED_ROLLING_TIME_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_ROLLING_TIME_SUP)) + { + //Pack rolling time + p_pckd_loc_speed[pckd_loc_speed_len] = p_param->rolling_time; + pckd_loc_speed_len++; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_param->flags, LANP_LSPEED_ROLLING_TIME_PRESENT, 0); + } + } + + if (GETB(p_param->flags, LANP_LSPEED_UTC_TIME_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_UTC_TIME_SUP)) + { + // Pack UTC time + pckd_loc_speed_len += prf_pack_date_time(&p_pckd_loc_speed[pckd_loc_speed_len], &(p_param->date_time)); + + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_param->flags, LANP_LSPEED_UTC_TIME_PRESENT, 0); + } + } + + // Flags value + co_write16p(&p_pckd_loc_speed[0], p_param->flags); + + return pckd_loc_speed_len; +} + +uint8_t lans_split_loc_speed_ntf(uint8_t conidx, struct gattc_send_evt_cmd *p_loc_speed_ntf1) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + // Extract flags info + uint16_t flags = co_read16p(&p_loc_speed_ntf1->value[0]); + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_loc_speed_ntf2 = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), prf_src_task_get(&(p_lans_env->prf_env), conidx), + gattc_send_evt_cmd, LANP_LAN_LOC_SPEED_MAX_LEN); + // Current position + uint8_t len = 0; + + // Fill in the parameter structure + p_loc_speed_ntf2->operation = GATTC_NOTIFY; + p_loc_speed_ntf2->handle = LANS_HANDLE(LNS_IDX_LOC_SPEED_VAL); + p_loc_speed_ntf2->length = LANP_LAN_LOC_SPEED_MIN_LEN; + + // Copy status flags + co_write16p(&p_loc_speed_ntf2->value[0], (flags & (LANP_LSPEED_POSITION_STATUS_LSB_BIT | + LANP_LSPEED_POSITION_STATUS_MSB_BIT | + LANP_LSPEED_SPEED_AND_DISTANCE_FORMAT_BIT | + LANP_LSPEED_ELEVATION_SOURCE_LSB_BIT | + LANP_LSPEED_ELEVATION_SOURCE_MSB_BIT | + LANP_LSPEED_HEADING_SOURCE_BIT))); + + for (uint16_t feat = LANP_LSPEED_INST_SPEED_PRESENT_BIT; + feat <= LANP_LSPEED_POSITION_STATUS_LSB_BIT; + feat <<= 1) + { + // First message fits within the MTU + if (p_loc_speed_ntf1->length <= gattc_get_mtu(conidx) - 3) + { + // Stop splitting + break; + } + + if ((flags & feat) != feat) + { + continue; + } + + switch (feat) + { + case LANP_LSPEED_ROLLING_TIME_PRESENT_BIT: + { + // Copy uint8 + p_loc_speed_ntf2->value[p_loc_speed_ntf2->length] = + p_loc_speed_ntf1->value[LANP_LAN_LOC_SPEED_MIN_LEN]; + len = 1; + } break; + + case LANP_LSPEED_INST_SPEED_PRESENT_BIT: + case LANP_LSPEED_HEADING_PRESENT_BIT: + { + // Copy uint16 + memcpy(&p_loc_speed_ntf2->value[p_loc_speed_ntf2->length], + &p_loc_speed_ntf1->value[LANP_LAN_LOC_SPEED_MIN_LEN], + 2); + len = 2; + } break; + + case LANP_LSPEED_TOTAL_DISTANCE_PRESENT_BIT: + case LANP_LSPEED_ELEVATION_PRESENT_BIT: + { + // Copy uint24 + memcpy(&p_loc_speed_ntf2->value[p_loc_speed_ntf2->length], + &p_loc_speed_ntf1->value[LANP_LAN_LOC_SPEED_MIN_LEN], + 3); + len = 3; + } break; + + case LANP_LSPEED_LOCATION_PRESENT_BIT: + { + // Copy latitude and longitude + memcpy(&p_loc_speed_ntf2->value[p_loc_speed_ntf2->length], + &p_loc_speed_ntf1->value[LANP_LAN_LOC_SPEED_MIN_LEN], + 8); + len = 8; + } break; + + case LANP_LSPEED_UTC_TIME_PRESENT_BIT: + { + // Copy time + memcpy(&p_loc_speed_ntf2->value[p_loc_speed_ntf2->length], + &p_loc_speed_ntf1->value[LANP_LAN_LOC_SPEED_MIN_LEN], + 7); + len = 7; + } break; + + default: + { + len = 0; + } break; + } + + if (len) + { + // Update values + p_loc_speed_ntf2->length += len; + // Remove field and flags from the first ntf + p_loc_speed_ntf1->length -= len; + memcpy(&p_loc_speed_ntf1->value[LANP_LAN_LOC_SPEED_MIN_LEN], + &p_loc_speed_ntf1->value[LANP_LAN_LOC_SPEED_MIN_LEN + len], + p_loc_speed_ntf1->length); + // Update flags + p_loc_speed_ntf1->value[0] &= ~feat; + p_loc_speed_ntf2->value[0] |= feat; + } + } + + // store the pending notification to send + p_lans_env->p_op_data->p_ntf_pending = p_loc_speed_ntf2; + + return p_loc_speed_ntf2->length; +} + +uint8_t lans_update_characteristic_config(uint8_t conidx, uint8_t prfl_config, + struct gattc_write_req_ind const *p_param) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get the value + uint16_t ntf_cfg = co_read16p(&p_param->value[0]); + + // Check if the value is correct + if (GETB(prfl_config, LANS_PRF_CFG_FLAG_LN_CTNL_PT_IND)) + { + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + // Save the new configuration in the environment + SETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_LN_CTNL_PT_IND, 0); + } + else if (ntf_cfg == PRF_CLI_START_IND) + { + SETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_LN_CTNL_PT_IND, 1); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + else if (GETB(prfl_config, LANS_PRF_CFG_FLAG_LOC_SPEED_NTF)) + { + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + // Save the new configuration in the environment + SETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_LOC_SPEED_NTF, 0); + } + else if (ntf_cfg == PRF_CLI_START_NTF) + { + SETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_LOC_SPEED_NTF, 1); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + else if (GETB(prfl_config, LANS_PRF_CFG_FLAG_NAVIGATION_NTF)) + { + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + // Save the new configuration in the environment + SETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_NAVIGATION_NTF, 0); + } + else if (ntf_cfg == PRF_CLI_START_NTF) + { + SETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_NAVIGATION_NTF, 1); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + + if (status == GAP_ERR_NO_ERROR) + { + // Allocate message to inform application + struct lans_cfg_ntfind_ind *p_ind = KE_MSG_ALLOC(LANS_CFG_NTFIND_IND, + prf_dst_task_get(&(p_lans_env->prf_env), conidx), + prf_src_task_get(&(p_lans_env->prf_env), conidx), + lans_cfg_ntfind_ind); + + // Inform APP of configuration change + p_ind->char_code = prfl_config; + p_ind->ntf_cfg = ntf_cfg; + p_ind->conidx = conidx; + ke_msg_send(p_ind); + + // Enable Bonded Data + SETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_PERFORMED_OK, 1); + } + + return (status); +} + +uint8_t lans_pack_navigation_ntf(struct lanp_navigation *p_param, uint8_t *p_pckd_navigation) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + // Packed Measurement length + uint8_t pckd_navigation_len = LANP_LAN_NAVIGATION_MIN_LEN; + + // Check provided flags + if (GETB(p_param->flags, LANP_NAVI_REMAINING_DIS_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_REMAINING_DISTANCE_SUP)) + { + //Pack distance (24bits) + co_write24p(&p_pckd_navigation[pckd_navigation_len], p_param->remaining_distance); + pckd_navigation_len += 3; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_param->flags, LANP_NAVI_REMAINING_DIS_PRESENT, 0); + } + } + + if (GETB(p_param->flags, LANP_NAVI_REMAINING_VER_DIS_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_REMAINING_VERTICAL_DISTANCE_SUP)) + { + //Pack vertical distance (24bits) + co_write24p(&p_pckd_navigation[pckd_navigation_len], p_param->remaining_ver_distance); + pckd_navigation_len += 3; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_param->flags, LANP_NAVI_REMAINING_VER_DIS_PRESENT, 0); + } + } + + if (GETB(p_param->flags, LANP_NAVI_ESTIMATED_TIME_OF_ARRIVAL_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_ESTIMATED_TIME_OF_ARRIVAL_SUP)) + { + //Pack time + pckd_navigation_len += prf_pack_date_time( + &p_pckd_navigation[pckd_navigation_len], &(p_param->estimated_arrival_time)); + + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_param->flags, LANP_NAVI_ESTIMATED_TIME_OF_ARRIVAL_PRESENT, 0); + } + } + + // Flags value + co_write16p(&p_pckd_navigation[0], p_param->flags); + // Bearing value + co_write16p(&p_pckd_navigation[2], p_param->bearing); + // heading value + co_write16p(&p_pckd_navigation[4], p_param->heading); + + return pckd_navigation_len; +} + +void lans_upd_posq(struct lanp_posq param) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + + // Check provided flags + if (GETB(param.flags, LANP_POSQ_NUMBER_OF_BEACONS_IN_SOLUTION_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_NUMBER_OF_BEACONS_IN_SOLUTION_SUP)) + { + //Pack beacons in solution + p_lans_env->p_posq->n_beacons_solution = param.n_beacons_solution; + } + else //Not supported by the profile + { + //Force to not supported + SETB(param.flags, LANP_POSQ_NUMBER_OF_BEACONS_IN_SOLUTION_PRESENT, 0); + } + } + + if (GETB(param.flags, LANP_POSQ_NUMBER_OF_BEACONS_IN_VIEW_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_NUMBER_OF_BEACONS_IN_VIEW_SUP)) + { + //Pack beacons in view + p_lans_env->p_posq->n_beacons_view = param.n_beacons_view; + } + else //Not supported by the profile + { + //Force to not supported + SETB(param.flags, LANP_POSQ_NUMBER_OF_BEACONS_IN_VIEW_PRESENT, 0); + } + } + + if (GETB(param.flags, LANP_POSQ_TIME_TO_FIRST_FIX_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_TIME_TO_FIRST_FIX_SUP)) + { + //Pack time to fix + p_lans_env->p_posq->time_first_fix = param.time_first_fix; + } + else //Not supported by the profile + { + //Force to not supported + SETB(param.flags, LANP_POSQ_TIME_TO_FIRST_FIX_PRESENT, 0); + } + } + + if (GETB(param.flags, LANP_POSQ_EHPE_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_ESTIMATED_HOR_POSITION_ERROR_SUP)) + { + //Pack ehpe + p_lans_env->p_posq->ehpe = param.ehpe; + } + else //Not supported by the profile + { + //Force to not supported + SETB(param.flags, LANP_POSQ_EHPE_PRESENT, 0); + } + } + + if (GETB(param.flags, LANP_POSQ_EVPE_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_ESTIMATED_VER_POSITION_ERROR_SUP)) + { + //Pack evpe + p_lans_env->p_posq->evpe = param.evpe; + } + else //Not supported by the profile + { + //Force to not supported + SETB(param.flags, LANP_POSQ_EVPE_PRESENT, 0); + } + } + + if (GETB(param.flags, LANP_POSQ_HDOP_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_HOR_DILUTION_OF_PRECISION_SUP)) + { + //Pack hdop + p_lans_env->p_posq->hdop = param.hdop; + } + else //Not supported by the profile + { + //Force to not supported + SETB(param.flags, LANP_POSQ_HDOP_PRESENT, 0); + } + } + + if (GETB(param.flags, LANP_POSQ_VDOP_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_VER_DILUTION_OF_PRECISION_SUP)) + { + //Pack vdop + p_lans_env->p_posq->vdop = param.vdop; + } + else //Not supported by the profile + { + //Force to not supported + SETB(param.flags, LANP_POSQ_VDOP_PRESENT, 0); + } + } + + // Flags value + p_lans_env->p_posq->flags = param.flags; +} + +uint8_t lans_pack_posq(uint8_t *p_pckd_posq) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + + // Packed length + uint8_t pckd_posq_len = LANP_LAN_POSQ_MIN_LEN; + + // Check provided flags + if (GETB(p_lans_env->p_posq->flags, LANP_POSQ_NUMBER_OF_BEACONS_IN_SOLUTION_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_NUMBER_OF_BEACONS_IN_SOLUTION_SUP)) + { + //Pack beacons in solution + p_pckd_posq[pckd_posq_len] = p_lans_env->p_posq->n_beacons_solution; + pckd_posq_len++; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_lans_env->p_posq->flags, LANP_POSQ_NUMBER_OF_BEACONS_IN_SOLUTION_PRESENT, 0); + } + } + + if (GETB(p_lans_env->p_posq->flags, LANP_POSQ_NUMBER_OF_BEACONS_IN_VIEW_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_NUMBER_OF_BEACONS_IN_VIEW_SUP)) + { + //Pack beacons in view + p_pckd_posq[pckd_posq_len] = p_lans_env->p_posq->n_beacons_view; + pckd_posq_len++; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_lans_env->p_posq->flags, LANP_POSQ_NUMBER_OF_BEACONS_IN_VIEW_PRESENT, 0); + } + } + + if (GETB(p_lans_env->p_posq->flags, LANP_POSQ_TIME_TO_FIRST_FIX_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_TIME_TO_FIRST_FIX_SUP)) + { + //Pack time to fix + co_write16p(&p_pckd_posq[pckd_posq_len], p_lans_env->p_posq->time_first_fix); + pckd_posq_len += 2; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_lans_env->p_posq->flags, LANP_POSQ_TIME_TO_FIRST_FIX_PRESENT, 0); + } + } + + if (GETB(p_lans_env->p_posq->flags, LANP_POSQ_EHPE_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_ESTIMATED_HOR_POSITION_ERROR_SUP)) + { + //Pack ehpe + co_write32p(&p_pckd_posq[pckd_posq_len], p_lans_env->p_posq->ehpe); + pckd_posq_len += 4; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_lans_env->p_posq->flags, LANP_POSQ_EHPE_PRESENT, 0); + } + } + + if (GETB(p_lans_env->p_posq->flags, LANP_POSQ_EVPE_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_ESTIMATED_VER_POSITION_ERROR_SUP)) + { + //Pack ehpe + co_write32p(&p_pckd_posq[pckd_posq_len], p_lans_env->p_posq->evpe); + pckd_posq_len += 4; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_lans_env->p_posq->flags, LANP_POSQ_EVPE_PRESENT, 0); + } + } + + if (GETB(p_lans_env->p_posq->flags, LANP_POSQ_HDOP_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_HOR_DILUTION_OF_PRECISION_SUP)) + { + //Pack ehpe + p_pckd_posq[pckd_posq_len] = p_lans_env->p_posq->hdop; + pckd_posq_len++; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_lans_env->p_posq->flags, LANP_POSQ_HDOP_PRESENT, 0); + } + } + + if (GETB(p_lans_env->p_posq->flags, LANP_POSQ_VDOP_PRESENT)) + { + if (GETB(p_lans_env->features, LANP_FEAT_VER_DILUTION_OF_PRECISION_SUP)) + { + //Pack ehpe + p_pckd_posq[pckd_posq_len] = p_lans_env->p_posq->vdop; + pckd_posq_len++; + } + else //Not supported by the profile + { + //Force to not supported + SETB(p_lans_env->p_posq->flags, LANP_POSQ_VDOP_PRESENT, 0); + } + } + + // Flags value + co_write16p(&p_pckd_posq[0], p_lans_env->p_posq->flags); + + return pckd_posq_len; +} + +uint8_t lans_pack_ln_ctnl_point_cfm (uint8_t conidx, struct lans_ln_ctnl_pt_cfm *p_param, uint8_t *p_rsp) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + // Response Length (At least 3) + uint8_t rsp_len = LANP_LAN_LN_CNTL_PT_RSP_MIN_LEN; + + // Set the Response Code + p_rsp[0] = LANP_LN_CTNL_PT_RESPONSE_CODE; + // Set the Response Value + p_rsp[2] = (p_param->status > LANP_LN_CTNL_PT_RESP_FAILED) ? LANP_LN_CTNL_PT_RESP_FAILED : p_param->status; + + switch (p_lans_env->operation) + { + case (LANS_SET_CUMUL_VALUE_OP_CODE): + { + // Set the request operation code + p_rsp[1] = LANP_LN_CTNL_PT_SET_CUMUL_VALUE; + } break; + + case (LANS_MASK_LSPEED_CHAR_CT_OP_CODE): + { + // Set the request operation code + p_rsp[1] = LANP_LN_CTNL_PT_MASK_LSPEED_CHAR_CT; + if (p_param->status == LANP_LN_CTNL_PT_RESP_SUCCESS) + { + // Ignore bits other than 0 - 6 + p_lans_env->env[conidx].mask_lspeed_content = + p_param->value.mask_lspeed_content & LANS_LSPEED_DISABLED_MASK; + } + } break; + + case (LANS_NAVIGATION_CONTROL_OP_CODE): + { + // Set the request operation code + p_rsp[1] = LANP_LN_CTNL_PT_NAVIGATION_CONTROL; + if (p_param->status == LANP_LN_CTNL_PT_RESP_SUCCESS) + { + switch((p_lans_env->env[conidx].nav_ctrl & LANS_NAV_CTRL_PT_VAL_MASK)) + { + // Disable notifications + case LANP_LN_CTNL_STOP_NAVI: + case LANP_LN_CTNL_PAUSE_NAVI: + { + SETB(p_lans_env->env[conidx].nav_ctrl, LANS_NAV_CTRL_PT_EN, 0); + } break; + + // Enable notifications + case LANP_LN_CTNL_START_NAVI: + case LANP_LN_CTNL_RESUME_NAVI: + case LANP_LN_CTNL_START_NST_WPT: + { + SETB(p_lans_env->env[conidx].nav_ctrl, LANS_NAV_CTRL_PT_EN, 1); + } break; + + // Do nothing + case LANP_LN_CTNL_SKIP_WPT: + default: + { + + } break; + } + } + } break; + + case (LANS_REQ_NUMBER_OF_ROUTES_OP_CODE): + { + // Set the request operation code + p_rsp[1] = LANP_LN_CTNL_PT_REQ_NUMBER_OF_ROUTES; + if (p_param->status == LANP_LN_CTNL_PT_RESP_SUCCESS) + { + co_write16p(&p_rsp[rsp_len], p_param->value.number_of_routes); + rsp_len += 2; + } + } break; + + case (LANS_REQ_NAME_OF_ROUTE_OP_CODE): + { + // Set the request operation code + p_rsp[1] = LANP_LN_CTNL_PT_REQ_NAME_OF_ROUTE; + if (p_param->status == LANP_LN_CTNL_PT_RESP_SUCCESS) + { + // pack name of route + for (int i = 0; i < p_param->value.route.length; i++) + { + p_rsp[i + 3] = p_param->value.route.name[i]; + rsp_len++; + } + } + } break; + + case (LANS_SELECT_ROUTE_OP_CODE): + { + // Set the request operation code + p_rsp[1] = LANP_LN_CTNL_PT_SELECT_ROUTE; + } break; + + case (LANS_SET_FIX_RATE_OP_CODE): + { + // Set the request operation code + p_rsp[1] = LANP_LN_CTNL_PT_SET_FIX_RATE; + } break; + + case (LANS_SET_ELEVATION_OP_CODE): + { + // Set the request operation code + p_rsp[1] = LANP_LN_CTNL_PT_SET_ELEVATION; + } break; + + default: + { + p_param->status = LANP_LN_CTNL_PT_RESP_NOT_SUPP; + } break; + } + + return rsp_len; +} + +uint8_t lans_unpack_ln_ctnl_point_ind (uint8_t conidx, struct gattc_write_req_ind const *p_param) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + + // Indication Status + uint8_t ind_status = LANP_LN_CTNL_PT_RESP_NOT_SUPP; + + // Allocate a request indication message for the application + struct lans_ln_ctnl_pt_req_ind *p_req_ind = KE_MSG_ALLOC(LANS_LN_CTNL_PT_REQ_IND, + prf_dst_task_get(&(p_lans_env->prf_env), conidx), + prf_src_task_get(&(p_lans_env->prf_env), conidx), + lans_ln_ctnl_pt_req_ind); + // Operation Code + p_req_ind->op_code = p_param->value[0]; + p_req_ind->conidx = conidx; + + // Operation Code + switch(p_req_ind->op_code) + { + case (LANP_LN_CTNL_PT_SET_CUMUL_VALUE): + { + // Check if total distance feature is supported + if (GETB(p_lans_env->features, LANP_FEAT_TOTAL_DISTANCE_SUP)) + { + // Provided parameter in not within the defined range + ind_status = LANP_LN_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 4) + { + // The request can be handled + ind_status = LANP_LN_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_lans_env->operation = LANS_SET_CUMUL_VALUE_OP_CODE; + // Cumulative value + p_req_ind->value.cumul_val = co_read24p(&p_param->value[1]); + } + } + } break; + + case (LANP_LN_CTNL_PT_MASK_LSPEED_CHAR_CT): + { + // Check if the LN Masking feature is supported + if (GETB(p_lans_env->features, LANP_FEAT_LSPEED_CHAR_CT_MASKING_SUP)) + { + // Provided parameter in not within the defined range + ind_status = LANP_LN_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 3) + { + // The request can be handled + ind_status = LANP_LN_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_lans_env->operation = LANS_MASK_LSPEED_CHAR_CT_OP_CODE; + // Mask content + p_req_ind->value.mask_content = co_read16p(&p_param->value[1]); + } + } + } break; + + case (LANP_LN_CTNL_PT_NAVIGATION_CONTROL): + { + // Check if navigation feature is supported + if ((LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_NAVI_MASK)) && + (GETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_NAVIGATION_NTF))) + { + // Provided parameter in not within the defined range + ind_status = LANP_LN_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 2) + { + if (p_param->value[1] <= 0x05) + { + // The request can be handled + ind_status = LANP_LN_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_lans_env->operation = LANS_NAVIGATION_CONTROL_OP_CODE; + // Control value + p_req_ind->value.control_value = p_param->value[1]; + // Store value in the environment + p_lans_env->env[conidx].nav_ctrl = (p_lans_env->env[conidx].nav_ctrl & LANS_NAV_CTRL_PT_EN_BIT) + | (p_req_ind->value.control_value & LANS_NAV_CTRL_PT_VAL_MASK); + } + } + } + } break; + + case (LANP_LN_CTNL_PT_REQ_NUMBER_OF_ROUTES): + { + // Check if navigation feature is supported + if (LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_NAVI_MASK)) + { + // The request can be handled + ind_status = LANP_LN_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_lans_env->operation = LANS_REQ_NUMBER_OF_ROUTES_OP_CODE; + } + } break; + + case (LANP_LN_CTNL_PT_REQ_NAME_OF_ROUTE): + { + // Check if navigation feature is supported + if (LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_NAVI_MASK)) + { + // Provided parameter in not within the defined range + ind_status = LANP_LN_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 3) + { + // The request can be handled + ind_status = LANP_LN_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_lans_env->operation = LANS_REQ_NAME_OF_ROUTE_OP_CODE; + // Route number + p_req_ind->value.route_number = co_read16p(&p_param->value[1]); + } + } + } break; + + case (LANP_LN_CTNL_PT_SELECT_ROUTE): + { + // Check if navigation feature is supported + if (LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_NAVI_MASK)) + { + // Provided parameter in not within the defined range + ind_status = LANP_LN_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 3) + { + // The request can be handled + ind_status = LANP_LN_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_lans_env->operation = LANS_SELECT_ROUTE_OP_CODE; + // route number + p_req_ind->value.route_number = co_read16p(&p_param->value[1]); + } + } + } break; + + case (LANP_LN_CTNL_PT_SET_FIX_RATE): + { + // Check if the LN Masking feature is supported + if (GETB(p_lans_env->features, LANP_FEAT_FIX_RATE_SETTING_SUP)) + { + // Provided parameter in not within the defined range + ind_status = LANP_LN_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 2) + { + // The request can be handled + ind_status = LANP_LN_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_lans_env->operation = LANS_SET_FIX_RATE_OP_CODE; + // fix rate + p_req_ind->value.fix_rate = p_param->value[1]; + } + } + } break; + + case (LANP_LN_CTNL_PT_SET_ELEVATION): + { + // Check if the Chain Weight Adjustment feature is supported + if (GETB(p_lans_env->features, LANP_FEAT_ELEVATION_SETTING_SUP)) + { + // Provided parameter in not within the defined range + ind_status = LANP_LN_CTNL_PT_RESP_INV_PARAM; + + if (p_param->length == 4) + { + // The request can be handled + ind_status = LANP_LN_CTNL_PT_RESP_SUCCESS; + // Update the environment + p_lans_env->operation = LANS_SET_ELEVATION_OP_CODE; + // elevation + p_req_ind->value.elevation = co_read24p(&p_param->value[1]); + } + } + } break; + + default: + { + // Operation Code is invalid, status is already LAN_CTNL_PT_RESP_NOT_SUPP + } break; + } + + // If no error raised, inform the application about the request + if (ind_status == LANP_LN_CTNL_PT_RESP_SUCCESS) + { + // Send the request indication to the application + ke_msg_send(p_req_ind); + // Go to the Busy status + ke_state_set(prf_src_task_get(&(p_lans_env->prf_env), conidx), LANS_BUSY); + } + else + { + // Free the allocated message + ke_msg_free(ke_param2msg(p_req_ind)); + } + + return ind_status; +} + +void lans_exe_operation(uint8_t conidx) +{ + struct lans_env_tag* p_lans_env = PRF_ENV_GET(LANS, lans); + + ASSERT_ERR(p_lans_env->p_op_data != NULL); + + bool finished = true; + + while ((p_lans_env->p_op_data->cursor < BLE_CONNECTION_MAX) && finished) + { + uint8_t cursor = p_lans_env->p_op_data->cursor; + + switch (p_lans_env->operation) + { + case LANS_NTF_LOC_SPEED_OP_CODE: + { + // notification is pending, send it first + if (p_lans_env->p_op_data->p_ntf_pending != NULL) + { + ke_msg_send(p_lans_env->p_op_data->p_ntf_pending); + p_lans_env->p_op_data->p_ntf_pending = NULL; + finished = false; + } + // Check if sending of notifications has been enabled + else if (GETB(p_lans_env->env[cursor].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_LOC_SPEED_NTF)) + { + struct gattc_send_evt_cmd *p_meas_val; + + struct lans_ntf_loc_speed_cmd *p_speed_cmd = + (struct lans_ntf_loc_speed_cmd *) ke_msg2param(p_lans_env->p_op_data->p_cmd); + + // Save flags value + uint16_t flags = p_speed_cmd->parameters.flags; + + // Mask unwanted fields if supported + if (GETB(p_lans_env->features, LANP_FEAT_LSPEED_CHAR_CT_MASKING_SUP)) + { + p_speed_cmd->parameters.flags &= ~p_lans_env->env[cursor].mask_lspeed_content; + } + + // Allocate the GATT notification message + p_meas_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, cursor), prf_src_task_get(&(p_lans_env->prf_env),cursor), + gattc_send_evt_cmd, LANP_LAN_LOC_SPEED_MAX_LEN); + + // Fill in the parameter structure + p_meas_val->operation = GATTC_NOTIFY; + p_meas_val->handle = LANS_HANDLE(LNS_IDX_LOC_SPEED_VAL); + // pack measured value in database + p_meas_val->length = lans_pack_loc_speed_ntf(&p_speed_cmd->parameters, p_meas_val->value); + + if (p_meas_val->length > gattc_get_mtu(cursor) - 3) + { + // Split (if necessary) + lans_split_loc_speed_ntf(cursor, p_meas_val); + } + + // Restore flags value + p_speed_cmd->parameters.flags = flags; + + // Send the event + ke_msg_send(p_meas_val); + + finished = false; + } + + // update cursor only if all notification has been sent + if (p_lans_env->p_op_data->p_ntf_pending == NULL) + { + p_lans_env->p_op_data->cursor++; + } + } break; + + case LANS_NTF_NAVIGATION_OP_CODE: + { + struct lans_ntf_navigation_cmd *p_nav_cmd = + (struct lans_ntf_navigation_cmd *) ke_msg2param(p_lans_env->p_op_data->p_cmd); + + // Check if sending of notifications has been enabled + if (GETB(p_lans_env->env[cursor].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_NAVIGATION_NTF) + // and if navigation is enabled + && GETB(p_lans_env->env[cursor].nav_ctrl, LANS_NAV_CTRL_PT_EN)) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_meas_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, cursor), prf_src_task_get(&(p_lans_env->prf_env),cursor), + gattc_send_evt_cmd, LANP_LAN_NAVIGATION_MAX_LEN); + + // Fill in the parameter structure + p_meas_val->operation = GATTC_NOTIFY; + p_meas_val->handle = LANS_HANDLE(LNS_IDX_NAVIGATION_VAL); + // pack measured value in database + p_meas_val->length = lans_pack_navigation_ntf(&p_nav_cmd->parameters, p_meas_val->value); + + // Send the event + ke_msg_send(p_meas_val); + + finished = false; + } + + p_lans_env->p_op_data->cursor++; + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + // check if operation is finished + if (finished) + { + // send response to requester + lans_send_cmp_evt(conidx, prf_src_task_get(&(p_lans_env->prf_env), conidx), + prf_dst_task_get(&(p_lans_env->prf_env), conidx), + p_lans_env->operation, GAP_ERR_NO_ERROR); + + // free operation data + ke_msg_free(p_lans_env->p_op_data->p_cmd); + ke_free(p_lans_env->p_op_data); + p_lans_env->p_op_data = NULL; + // Set the operation code + p_lans_env->operation = LANS_RESERVED_OP_CODE; + // go back to idle state + ke_state_set(prf_src_task_get(&(p_lans_env->prf_env), 0), LANS_IDLE); + } +} + +void lans_send_rsp_ind(uint8_t conidx, uint8_t req_op_code, uint8_t status) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ctl_pt_rsp = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + prf_src_task_get(&p_lans_env->prf_env, conidx), + gattc_send_evt_cmd, LANP_LAN_LN_CNTL_PT_RSP_MIN_LEN); + + // Fill in the parameter structure + p_ctl_pt_rsp->operation = GATTC_INDICATE; + p_ctl_pt_rsp->handle = LANS_HANDLE(LNS_IDX_LN_CTNL_PT_VAL); + // Pack Control Point confirmation + p_ctl_pt_rsp->length = LANP_LAN_LN_CNTL_PT_RSP_MIN_LEN; + // Response Code + p_ctl_pt_rsp->value[0] = LANP_LN_CTNL_PT_RESPONSE_CODE; + // Request Operation Code + p_ctl_pt_rsp->value[1] = req_op_code; + // Response value + p_ctl_pt_rsp->value[2] = status; + + // Send the event + ke_msg_send(p_ctl_pt_rsp); +} + +#endif //(BLE_LN_SENSOR) + +/// @} LANS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/src/lans.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/src/lans.h new file mode 100644 index 0000000..dfd3f3c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/src/lans.h @@ -0,0 +1,391 @@ +/** + **************************************************************************************** + * + * @file lans.h + * + * @brief Header file - Location and Navigation Profile Sensor. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _LANS_H_ +#define _LANS_H_ + +/** + **************************************************************************************** + * @addtogroup LANS Location and Navigation Profile Sensor + * @ingroup LAN + * @brief Location and Navigation Profile Sensor + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_LN_SENSOR) +#include "lan_common.h" +#include "lans_task.h" +#include "prf_types.h" +#include "prf.h" +#include "attm.h" +#include "co_math.h" + +/* + * DEFINES + **************************************************************************************** + */ +/// Maximum number of Location and Navigation Profile Sensor role task instances +#define LANS_IDX_MAX (1) + +/// Disabled fields of Mask Location and Speed Characteristic Content +/// Save Bit 0 - 6 to mask Location and Speed Characteristic Flags +#define LANS_LSPEED_DISABLED_MASK (0x7F) + +/// Navigation Control parameter value mask (value 0 - 5 corresponds bit 0 - 3 in this parameter) +#define LANS_NAV_CTRL_PT_VAL_MASK (0x07) + +/* + * MACROS + **************************************************************************************** + */ + +/// Check if a specific characteristic has been added in the database (according to mask) +#define LANS_IS_FEATURE_SUPPORTED(prfl_cfg, mask) ((prfl_cfg & mask) == mask) + +/// MACRO TO CALCULATE HANDLE shdl + idx - POSQ - CNTL PT +/// POSQ is 2 if the Position quality is supported otherwise 0 +/// CNTL PT is 3 if the CP characteristic is supported otherwise 0 +#define LANS_HANDLE(idx) \ + (p_lans_env->shdl + (idx) - \ + ((!(LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_POS_Q_MASK)) && \ + ((idx) > LNS_IDX_POS_Q_CHAR))? (2) : (0)) - \ + ((!(LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_LN_CTNL_PT_MASK)) && \ + ((idx) > LNS_IDX_LN_CTNL_PT_CHAR))? (3) : (0))) + +/// Get database attribute index +#define LANS_IDX(hdl) \ + ((hdl - p_lans_env->shdl) + \ + ((!(LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_POS_Q_MASK)) && \ + ((hdl - p_lans_env->shdl) > LNS_IDX_POS_Q_CHAR)) ? (2) : (0)) + \ + ((!(LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_LN_CTNL_PT_MASK)) && \ + ((hdl - p_lans_env->shdl) > LNS_IDX_LN_CTNL_PT_CHAR)) ? (3) : (0))) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the LANS task +enum lans_state +{ + /// Idle state + LANS_IDLE, + /// Busy state + LANS_BUSY, + + /// Number of defined states. + LANS_STATE_MAX +}; + +/// Location and Navigation Service - Attribute List +enum lans_cps_att_list +{ + /// Location and Navigation Service + LNS_IDX_SVC, + /// LN Feature + LNS_IDX_LN_FEAT_CHAR, + LNS_IDX_LN_FEAT_VAL, + /// Location and Speed + LNS_IDX_LOC_SPEED_CHAR, + LNS_IDX_LOC_SPEED_VAL, + LNS_IDX_LOC_SPEED_NTF_CFG, + /// Position Quality + LNS_IDX_POS_Q_CHAR, + LNS_IDX_POS_Q_VAL, + /// LN Control Point + LNS_IDX_LN_CTNL_PT_CHAR, + LNS_IDX_LN_CTNL_PT_VAL, + LNS_IDX_LN_CTNL_PT_IND_CFG, + /// Navigation + LNS_IDX_NAVIGATION_CHAR, + LNS_IDX_NAVIGATION_VAL, + LNS_IDX_NAVIGATION_NTF_CFG, + + /// Number of attributes + LNS_IDX_NB, +}; + +/// Profile Configuration +enum lans_prf_cfg_flag_bf +{ + /// Control Point supported flag + LANS_CTNL_PT_CHAR_SUPP_FLAG_POS = 0, + LANS_CTNL_PT_CHAR_SUPP_FLAG_BIT = CO_BIT(LANS_CTNL_PT_CHAR_SUPP_FLAG_POS), + + /// Broadcast supported flag + LANS_NAVIGATION_SUPP_FLAG_POS = 1, + LANS_NAVIGATION_SUPP_FLAG_BIT = CO_BIT(LANS_NAVIGATION_SUPP_FLAG_POS), +}; + +/// Profile Configuration NTF/IND Flags bit field +enum lans_prf_cfg_ntfind_flag_bf +{ + /// Location and Speed - Client Char. Cfg + LANS_PRF_CFG_FLAG_LOC_SPEED_NTF_POS = 0, + LANS_PRF_CFG_FLAG_LOC_SPEED_NTF_BIT = CO_BIT(LANS_PRF_CFG_FLAG_LOC_SPEED_NTF_POS), + + /// Control Point - Client Characteristic configuration + LANS_PRF_CFG_FLAG_LN_CTNL_PT_IND_POS = 1, + LANS_PRF_CFG_FLAG_LN_CTNL_PT_IND_BIT = CO_BIT(LANS_PRF_CFG_FLAG_LN_CTNL_PT_IND_POS), + + + /// Navigation - Client Characteristic configuration + LANS_PRF_CFG_FLAG_NAVIGATION_NTF_POS = 2, + LANS_PRF_CFG_FLAG_NAVIGATION_NTF_BIT = CO_BIT(LANS_PRF_CFG_FLAG_NAVIGATION_NTF_POS), + + /// Bonded Data configured + LANS_PRF_CFG_PERFORMED_OK_POS = 3, + LANS_PRF_CFG_PERFORMED_OK_BIT = CO_BIT(LANS_PRF_CFG_PERFORMED_OK_POS), +}; + +/// LANS Configuration Flag Masks +enum lans_config_flag_mask +{ + /// Mandatory Attributes (LN Feature + Location and Speed) + LANS_MANDATORY_LSB = 0, + LANS_MANDATORY_MASK = (0x003F), + + /// Position quality Attribute + LANS_POS_Q_LSB = 6, + LANS_POS_Q_MASK = (0x00C0), + + /// Control Point Attributes + LANS_LN_CTNL_PT_LSB = 8, + LANS_LN_CTNL_PT_MASK = (0x0700), + + /// Navigation Attributes + LANS_NAVI_LSB = 11, + LANS_NAVI_MASK = (0x3800), +}; + +/// Navigation control enable bit field +enum lans_navi_ctrl_en_bf +{ + /// Enable bit (RFU bit 7) + LANS_NAV_CTRL_PT_EN_POS = 7, + LANS_NAV_CTRL_PT_EN_BIT = CO_BIT(LANS_NAV_CTRL_PT_EN_POS), +}; + +/* + * STRUCTURES + **************************************************************************************** + */ +/// ongoing operation information +struct lans_op +{ + /// On-going operation command + struct ke_msg *p_cmd; + /// notification pending + struct gattc_send_evt_cmd *p_ntf_pending; + + /// Cursor on connection + uint8_t cursor; +}; + +/// Location and Navigation environment variable per connection +struct lans_cnx_env +{ + /// Location and speed content mask (bit 0 - 6) + /// 0 : leave as default, 1 : turn off + uint16_t mask_lspeed_content; + /// Profile Notify/Indication Flags + uint8_t prfl_ntf_ind_cfg; + /// LN Navigation Control parameter (value 0 - 5) + uint8_t nav_ctrl; +}; + + +/// Location and Navigation Profile Sensor environment variable +struct lans_env_tag +{ + /// profile environment + prf_env_t prf_env; + + /// Environment variable pointer for each connections + struct lans_cnx_env env[BLE_CONNECTION_MAX]; + /// Position quality + struct lanp_posq *p_posq; + /// On-going operation + struct lans_op *p_op_data; + + /// Feature Configuration Flags + uint32_t features; + + /// Location and Navigation Service Start Handle + uint16_t shdl; + /// Profile Configuration Flags + /// Every bit corresponds an attribute + uint16_t prfl_cfg; + /// Operation + uint8_t operation; + + /// State of different task instances + ke_state_t state[LANS_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Retrieve LAN service profile interface + * + * @return LAN service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* lans_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send a LANS_CMP_EVT message to the application. + * @param[in] conidx connection index + * @param[in] src_id Source task + * @param[in] dest_id Destination task + * @param[in] operation Operation completed + * @param[in] status status of the operation + **************************************************************************************** + */ +void lans_send_cmp_evt(uint8_t conidx, uint8_t src_id, uint8_t dest_id, uint8_t operation, uint8_t status); + +/** + **************************************************************************************** + * @brief Packs location and speed notifications + * @param[in] p_param Pointer to the parameters of the message. + * @param[out] p_pckd_loc_speed pointer to packed message + * @return status of the operation + **************************************************************************************** + */ +uint8_t lans_pack_loc_speed_ntf(struct lanp_loc_speed *p_param, uint8_t *p_pckd_loc_speed); + +/** + **************************************************************************************** + * @brief Packs navigation notifications + * @param[in] p_param Pointer to the parameters of the message. + * @param[out] p_pckd_navigation pointer to packed message + * @return length + **************************************************************************************** + */ +uint8_t lans_pack_navigation_ntf(struct lanp_navigation *p_param, uint8_t *p_pckd_navigation); + +/** + **************************************************************************************** + * @brief Splits notifications in order to be sent with default MTU + * @param[in] conidx connection index + * @param[in/out] p_loc_speed_ntf1 first notification + * @return length + **************************************************************************************** + */ +uint8_t lans_split_loc_speed_ntf(uint8_t conidx, struct gattc_send_evt_cmd *p_loc_speed_ntf1); + +/** + **************************************************************************************** + * @brief updates the environment with the descriptor configuration and sends indication + * @param[in] conidx connection index + * @param[in] prfl_config requested value + * @param[in] p_param pointer to the message parameters + * @return status of the operation + **************************************************************************************** + */ +uint8_t lans_update_characteristic_config(uint8_t conidx, uint8_t prfl_config, + struct gattc_write_req_ind const *p_param); + +/** + **************************************************************************************** + * @brief Packs position quality + * @param[in] param Pointer to the parameters of the message. + **************************************************************************************** + */ +void lans_upd_posq(struct lanp_posq param); + +/** + **************************************************************************************** + * @brief Packs position quality + * @param[out] p_pckd_posq pointer to packed message + * @return length + **************************************************************************************** + */ +uint8_t lans_pack_posq(uint8_t *p_pckd_posq); + +/** + **************************************************************************************** + * @brief Packs control point + * @param[in] conidx connection index + * @param[in] p_param Pointer to the parameters of the message. + * @param[out] p_rsp pointer to message + * @return status of the operation + **************************************************************************************** + */ +uint8_t lans_pack_ln_ctnl_point_cfm (uint8_t conidx, struct lans_ln_ctnl_pt_cfm *p_param, uint8_t *p_rsp); + +/** + **************************************************************************************** + * @brief Unpack control point and sends indication + * @param[in] conidx connection index + * @param[in] p_param pointer to message + * @return status of the operation + **************************************************************************************** + */ +uint8_t lans_unpack_ln_ctnl_point_ind (uint8_t conidx, struct gattc_write_req_ind const *p_param); + +/** + **************************************************************************************** + * @brief This function fully manage notification of navigation and speed information + * @param[in] conidx connection index + **************************************************************************************** + */ +void lans_exe_operation(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Send a control point response to the peer + * @param[in] conidx connection index + * @param[in] req_op_code operation code + * @param[in] status status of the operation + **************************************************************************************** + */ +void lans_send_rsp_ind(uint8_t conidx, uint8_t req_op_code, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void lans_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_LN_SENSOR) + +/// @} LANS + +#endif //(_LANS_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/src/lans_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/src/lans_task.c new file mode 100644 index 0000000..61040f4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/lan/lans/src/lans_task.c @@ -0,0 +1,693 @@ +/** + **************************************************************************************** + * + * @file lans_task.c + * + * @brief Location and Navigation Profile Sensor Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup LANSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_LN_SENSOR) +#include "lan_common.h" + +#include "gapc.h" +#include "gattc.h" +#include "gattc_task.h" +#include "attm.h" +#include "lans.h" +#include "lans_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" +#include "co_math.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref LANS_ENABLE_REQ message. + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int lans_enable_req_handler(ke_msg_id_t const msgid, + struct lans_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct lans_enable_rsp *p_cmp_evt; + + if (ke_state_get(dest_id) == LANS_IDLE) + { + // Bonded data was not used before + if (!GETB(p_lans_env->env[p_param->conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_PERFORMED_OK)) + { + status = GAP_ERR_NO_ERROR; + p_lans_env->env[p_param->conidx].prfl_ntf_ind_cfg = p_param->prfl_ntf_ind_cfg; + } + // Enable Bonded Data + SETB(p_param->conidx, LANS_PRF_CFG_PERFORMED_OK, 1); + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(LANS_ENABLE_RSP, src_id, dest_id, lans_enable_rsp); + p_cmp_evt->status = status; + p_cmp_evt->conidx = p_param->conidx; + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == LANS_IDLE) + { + // Pointer to the response message + struct gattc_read_cfm *p_cfm = NULL; + + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t att_idx = LANS_IDX(p_param->handle); + + uint8_t status = ATT_ERR_NO_ERROR; + + switch (att_idx) + { + case LNS_IDX_LN_FEAT_VAL: + { + // Allocate structure + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint32_t)); + p_cfm->length = sizeof(uint32_t); + // Fill data + co_write32p(p_cfm->value, p_lans_env->features); + } break; + + case LNS_IDX_POS_Q_VAL: + { + // Check if Position Quality Char. has been added in the database + if (LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_POS_Q_MASK)) + { + // Allocate structure + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(struct lanp_posq)); + // Fill data + p_cfm->length = lans_pack_posq(p_cfm->value); + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + + } break; + + case LNS_IDX_LOC_SPEED_NTF_CFG: + { + // allocate structure + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + // Fill data + co_write16p(p_cfm->value, + GETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_LOC_SPEED_NTF) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } break; + + case LNS_IDX_NAVIGATION_NTF_CFG: + { + // Check if Navigation Char. has been added in the database + if (LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_NAVI_MASK)) + { + // allocate structure + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + co_write16p(p_cfm->value, + GETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_NAVIGATION_NTF) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + case LNS_IDX_LN_CTNL_PT_IND_CFG: + { + // Check if LN control point has been added in the database + if (LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_LN_CTNL_PT_MASK)) + { + // allocate structure + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + // Fill data + co_write16p(p_cfm->value, + GETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_LN_CTNL_PT_IND) + ? PRF_CLI_START_IND : PRF_CLI_STOP_NTFIND); + } + else + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + } break; + + default: + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + if (status != ATT_ERR_NO_ERROR) + { + p_cfm = KE_MSG_ALLOC(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm); + p_cfm->length = 0; + } + + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == LANS_IDLE) + { + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + uint8_t att_idx = LANS_IDX(p_param->handle); + struct gattc_att_info_cfm *p_cfm; + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + // check if it's a client configuration char + if ((att_idx == LNS_IDX_LOC_SPEED_NTF_CFG) + || (att_idx == LNS_IDX_NAVIGATION_NTF_CFG) + || (att_idx == LNS_IDX_LN_CTNL_PT_IND_CFG)) + { + // CCC attribute length = 2 + p_cfm->length = 2; + p_cfm->status = GAP_ERR_NO_ERROR; + } + else if (att_idx == LNS_IDX_LN_CTNL_PT_VAL) + { + // force length to zero to reject any write starting from something != 0 + p_cfm->length = 0; + p_cfm->status = GAP_ERR_NO_ERROR; + } + // not expected request + else + { + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } + + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref LANS_NTF_LN_MEAS_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int lans_ntf_loc_speed_cmd_handler(ke_msg_id_t const msgid, + struct lans_ntf_loc_speed_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_NO_FREE; + + // State shall be Connected or Busy + if (ke_state_get(dest_id) == LANS_IDLE) + { + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + + // Configure the environment + p_lans_env->operation = LANS_NTF_LOC_SPEED_OP_CODE; + // allocate operation data + p_lans_env->p_op_data = (struct lans_op *) ke_malloc(sizeof(struct lans_op), KE_MEM_KE_MSG); + p_lans_env->p_op_data->p_cmd = ke_param2msg(p_param); + p_lans_env->p_op_data->cursor = 0; + p_lans_env->p_op_data->p_ntf_pending = NULL; + + // Go to busy state + ke_state_set(dest_id, LANS_BUSY); + + // start operation execution + lans_exe_operation(KE_IDX_GET(src_id)); + } + else + { + // Save it for later + msg_status = KE_MSG_SAVED; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref LANS_UPD_POS_Q_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int lans_upd_pos_q_req_handler(ke_msg_id_t const msgid, + struct lans_upd_pos_q_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + // Allocate response message + struct lans_upd_pos_q_rsp *p_rsp = KE_MSG_ALLOC(LANS_UPD_POS_Q_RSP, + src_id, dest_id, lans_upd_pos_q_rsp); + + p_rsp->status = PRF_ERR_FEATURE_NOT_SUPPORTED; + + // Check if Position Quality Char. has been added in the database + if (LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_POS_Q_MASK)) + { + if (p_lans_env->p_posq != NULL) + { + // Update position quality + lans_upd_posq(p_param->parameters); + // Set status value + p_rsp->status = GAP_ERR_NO_ERROR; + } + else + { + // Set status value + p_rsp->status = PRF_APP_ERROR; + } + } + + // Send response to the application + ke_msg_send(p_rsp); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref LANS_NTF_NAVIGATION_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int lans_ntf_navigation_cmd_handler(ke_msg_id_t const msgid, + struct lans_ntf_navigation_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_NO_FREE; + + // State shall be Connected or Busy + if (ke_state_get(dest_id) == LANS_IDLE) + { + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + + // Configure the environment + p_lans_env->operation = LANS_NTF_NAVIGATION_OP_CODE; + // allocate operation data + p_lans_env->p_op_data = (struct lans_op*) ke_malloc(sizeof(struct lans_op), KE_MEM_KE_MSG); + p_lans_env->p_op_data->p_cmd = ke_param2msg(p_param); + p_lans_env->p_op_data->cursor = 0; + p_lans_env->p_op_data->p_ntf_pending = NULL; + + // Go to busy state + ke_state_set(dest_id, LANS_BUSY); + + // start operation execution + lans_exe_operation(KE_IDX_GET(src_id)); + } + else + { + // Save it for later + msg_status = KE_MSG_SAVED; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref LANS_LN_CTNL_PT_CFM message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int lans_ln_ctnl_pt_cfm_handler(ke_msg_id_t const msgid, + struct lans_ln_ctnl_pt_cfm *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + uint8_t status = GAP_ERR_NO_ERROR; + + if (ke_state_get(dest_id) == LANS_BUSY) + { + do + { + struct gattc_send_evt_cmd *p_ctl_pt_rsp; + + // Check the current operation + if (p_lans_env->operation < LANS_SET_CUMUL_VALUE_OP_CODE) + { + // The confirmation has been sent without request indication, ignore + break; + } + + // The LN Control Point Characteristic must be supported if we are here + if (!LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_LN_CTNL_PT_MASK)) + { + status = PRF_ERR_REQ_DISALLOWED; + break; + } + + // Check if sending of indications has been enabled + if (!GETB(p_lans_env->env[p_param->conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_LN_CTNL_PT_IND)) + { + // CCC improperly configured + status = PRF_CCCD_IMPR_CONFIGURED; + break; + } + + // Allocate the GATT notification message + p_ctl_pt_rsp = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, p_param->conidx), dest_id, + gattc_send_evt_cmd, LANP_LAN_LN_CNTL_PT_RSP_MAX_LEN); + + // Fill in the p_parameter structure + p_ctl_pt_rsp->operation = GATTC_INDICATE; + p_ctl_pt_rsp->handle = LANS_HANDLE(LNS_IDX_LN_CTNL_PT_VAL); + // Pack Control Point confirmation + p_ctl_pt_rsp->length = lans_pack_ln_ctnl_point_cfm (p_param->conidx, p_param, p_ctl_pt_rsp->value); + + // Send the event + ke_msg_send(p_ctl_pt_rsp); + + } while (0); + + if (status != GAP_ERR_NO_ERROR) + { + // Inform the application that a procedure has been completed + lans_send_cmp_evt(p_param->conidx, + prf_src_task_get(&p_lans_env->prf_env, p_param->conidx), + prf_dst_task_get(&p_lans_env->prf_env, p_param->conidx), + p_lans_env->operation, status); + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + uint8_t conidx = KE_IDX_GET(src_id); + // Message status + int msg_status = KE_MSG_CONSUMED; + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Control Point Status + uint8_t ctl_pt_status = LANP_LN_CTNL_PT_RESP_SUCCESS; + struct gattc_write_cfm *p_cfm; + + if (p_lans_env != NULL) + { + // Location and speed Characteristic, Client Characteristic Configuration Descriptor + if (p_param->handle == (LANS_HANDLE(LNS_IDX_LOC_SPEED_NTF_CFG))) + { + // Update value + status = lans_update_characteristic_config(conidx, LANS_PRF_CFG_FLAG_LOC_SPEED_NTF_BIT, p_param); + } + // Navigation Characteristic, Client Characteristic Configuration Descriptor + else if (p_param->handle == (LANS_HANDLE(LNS_IDX_NAVIGATION_NTF_CFG))) + { + if (LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_NAVI_MASK)) + { + // Update value + status = lans_update_characteristic_config(conidx, LANS_PRF_CFG_FLAG_NAVIGATION_NTF_BIT, p_param); + } + else + { + status = ATT_ERR_ATTRIBUTE_NOT_FOUND; + } + } + // LN Control Point Characteristic + else + { + if (LANS_IS_FEATURE_SUPPORTED(p_lans_env->prfl_cfg, LANS_LN_CTNL_PT_MASK)) + { + // LN Control Point, Client Characteristic Configuration Descriptor + if (p_param->handle == (LANS_HANDLE(LNS_IDX_LN_CTNL_PT_IND_CFG))) + { + // Update value + status = lans_update_characteristic_config(conidx, LANS_PRF_CFG_FLAG_LN_CTNL_PT_IND_BIT, p_param); + } + // LN Control Point Characteristic + else if (p_param->handle == (LANS_HANDLE(LNS_IDX_LN_CTNL_PT_VAL))) + { + do + { + // Check if sending of indications has been enabled + if (!GETB(p_lans_env->env[conidx].prfl_ntf_ind_cfg, LANS_PRF_CFG_FLAG_LN_CTNL_PT_IND)) + { + // CCC improperly configured + status = PRF_CCCD_IMPR_CONFIGURED; + break; + } + + if (p_lans_env->operation >= LANS_SET_CUMUL_VALUE_OP_CODE) + { + // A procedure is already in progress + status = LAN_ERROR_PROC_IN_PROGRESS; + break; + } + + if (p_lans_env->operation == LANS_NTF_LOC_SPEED_OP_CODE) + { + // Keep the message until the end of the current procedure + msg_status = KE_MSG_SAVED; + break; + } + + // Unpack Control Point parameters + ctl_pt_status = lans_unpack_ln_ctnl_point_ind (conidx, p_param); + + } while (0); + } + else + { + ASSERT_ERR(0); + } + } + else + { + status = ATT_ERR_ATTRIBUTE_NOT_FOUND; + } + } + } + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + + // Check if control point failed + if ((p_param->handle == (LANS_HANDLE(LNS_IDX_LN_CTNL_PT_VAL))) && + (ctl_pt_status != LANP_LN_CTNL_PT_RESP_SUCCESS)) + { + // Send response to peer + lans_send_rsp_ind(conidx, p_param->value[0], ctl_pt_status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles @ref GATT_NOTIFY_CMP_EVT message meaning that a notification or an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + + uint8_t conidx = KE_IDX_GET(src_id); + + // Check if a connection exists + if (ke_state_get(dest_id) == LANS_BUSY) + { + switch (p_param->operation) + { + case (GATTC_NOTIFY): + { + lans_exe_operation(conidx); + // else ignore the message + } break; + + case (GATTC_INDICATE): + { + + ASSERT_ERR(p_lans_env->operation >= LANS_SET_CUMUL_VALUE_OP_CODE); + + // Inform the application that a procedure has been completed + lans_send_cmp_evt(conidx, prf_src_task_get(&(p_lans_env->prf_env), conidx), + prf_dst_task_get(&(p_lans_env->prf_env), conidx), + p_lans_env->operation, p_param->status); + } break; + // else ignore the message + + default: + { + ASSERT_ERR(0); + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(lans) +{ + {LANS_ENABLE_REQ, (ke_msg_func_t)lans_enable_req_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t)gattc_read_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t)gattc_att_info_req_ind_handler}, + {LANS_NTF_LOC_SPEED_CMD, (ke_msg_func_t)lans_ntf_loc_speed_cmd_handler}, + {LANS_UPD_POS_Q_REQ, (ke_msg_func_t)lans_upd_pos_q_req_handler}, + {LANS_NTF_NAVIGATION_CMD, (ke_msg_func_t)lans_ntf_navigation_cmd_handler}, + {LANS_LN_CTNL_PT_CFM, (ke_msg_func_t)lans_ln_ctnl_pt_cfm_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t)gattc_write_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void lans_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct lans_env_tag *p_lans_env = PRF_ENV_GET(LANS, lans); + + p_task_desc->msg_handler_tab = lans_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(lans_msg_handler_tab); + p_task_desc->state = p_lans_env->state; + p_task_desc->idx_max = LANS_IDX_MAX; +} + +#endif //(BLE_LN_SENSOR) + +/// @} LANSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/api/ns_iuss.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/api/ns_iuss.h new file mode 100644 index 0000000..e5c558d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/api/ns_iuss.h @@ -0,0 +1,89 @@ +#ifndef __NS_IUSS_H__ +#define __NS_IUSS_H__ + + + +#include "rwip_config.h" // SW configuration + + +#if (BLE_APP_NS_IUS) + + +#include +#include "prf_types.h" +#include "prf.h" +#include "attm.h" + + +#define NS_IUS_IDX_MAX (1) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +/* Public constants ---------------------------------------------------------*/ + +/// Value element +struct ns_ius_val_elmt +{ + struct co_list_hdr hdr; + uint8_t att_idx; + uint8_t length; + uint8_t data[__ARRAY_EMPTY]; +}; + +struct ns_ius_env_tag +{ + prf_env_t prf_env; + uint16_t shdl; + uint8_t max_nb_att; + struct ke_msg *operation; + uint8_t cursor; + uint8_t ccc_idx; + struct co_list values; + ke_state_t state[NS_IUS_IDX_MAX]; +}; + + +const struct prf_task_cbs* ns_ius_prf_itf_get(void); + + + + +/* Public function prototypes -----------------------------------------------*/ + + +/** + * @brief Initialization of the NS IUS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + */ +void ns_ius_task_init(struct ke_task_desc *p_task_desc); + + + +#endif + + + + + +#endif //__NS_IUSS_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/api/ns_iuss_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/api/ns_iuss_task.h new file mode 100644 index 0000000..677a496 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/api/ns_iuss_task.h @@ -0,0 +1,121 @@ +/** + **************************************************************************************** + * + * @file ns_ius_task.h + * + * @brief NS IUS profile task header file + * + * Copyright (C) Nation 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef __NS_IUSS_TASK_H__ +#define __NS_IUSS_TASK_H__ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_NS_IUS) + + +#include "prf_types.h" +#include "prf.h" +#include "attm.h" + + + + + + + + + + + +struct ns_ius_db_cfg +{ + uint8_t max_nb_att; + uint8_t *att_tbl; + uint8_t *cfg_flag; + uint16_t features; +}; + + +enum +{ + NS_IUS_CREATE_DB_REQ = TASK_FIRST_MSG(TASK_ID_NS_IUS), + NS_IUS_VALUE_REQ_IND, + NS_IUS_VAL_WRITE_IND, + NS_IUS_ATT_INFO_REQ, + NS_IUS_DISCONNECT, +}; + +enum ns_ius_state +{ + NS_IUS_IDLE, + NS_IUS_BUSY, + NS_IUS_STATE_MAX, +}; + +struct ns_ius_val_write_ind +{ + uint8_t conidx; + uint16_t handle; + uint16_t length; + uint8_t value[__ARRAY_EMPTY]; +}; +struct ns_ius_value_req_ind +{ + uint8_t conidx; + uint16_t att_idx; +}; + +struct ns_ius_att_info_req +{ + uint8_t conidx; + uint16_t att_idx; +}; + + +struct ns_ius_disconnect +{ + uint8_t conidx; +}; + + +extern ke_task_id_t ns_ble_ius_task; + + +/** + * @brief Set value of CCC for given attribute and connection index. + * @param[in] conidx Connection index. + * @param[in] att_idx CCC attribute index. + * @param[in] cc Value to store. + */ +void ns_ius_set_ccc_value(uint8_t conidx, uint8_t att_idx, uint16_t ccc); +/** + * @brief Initialize Client Characteristic Configuration fields. + * @details Function initializes all CCC fields to default value. + * @param[in] att_db Id of the message received. + * @param[in] max_nb_att Pointer to the parameters of the message. + */ +void ns_ius_init_ccc_values(const struct attm_desc_128 *att_db, int max_nb_att); + + + +#endif //BLE_APP_NS_IUS + + + + + + + +#endif //__NS_IUSS_TASK_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/src/ns_iuss.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/src/ns_iuss.c new file mode 100644 index 0000000..a702e54 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/src/ns_iuss.c @@ -0,0 +1,178 @@ +/** + **************************************************************************************** + * + * @file ns_iuss.c + * + * @brief Custom Service profile source file. + * + * + * + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" // SW configuration + + +#if (BLE_APP_NS_IUS) +#include "ns_iuss.h" +#include "ns_iuss_task.h" +#include "app_ns_ius.h" + + +#include "prf_utils.h" +#include "prf.h" +#include "attm_db.h" +#include "ke_mem.h" +#include "att.h" +#include "co_utils.h" +#include "attm.h" +#include "ke_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "gattc_task.h" +#include "attm_db.h" +#include "ns_log.h" + + + +/** + * @brief Initialization of the NS IUS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + */ +static uint8_t ns_ius_init(struct prf_task_env *env, uint16_t *start_hdl, uint16_t app_task, uint8_t sec_lvl, struct ns_ius_db_cfg *params) +{ + uint8_t status = ATT_ERR_NO_ERROR; + uint8_t uuid_128[16] = SERVICE_NS_IUS; + uint32_t cfg_flag = ((1<task, ns_ius_att_db, + (sec_lvl & PERM_MASK_SVC_AUTH) | (sec_lvl & PERM_MASK_SVC_EKS) | PERM(SVC_SECONDARY, DISABLE) | PERM_VAL(SVC_UUID_LEN,0x2)); + + + if (status == ATT_ERR_NO_ERROR) + { + struct ns_ius_env_tag *ns_ius_env = (struct ns_ius_env_tag *) ke_malloc(sizeof(struct ns_ius_env_tag), KE_MEM_ATT_DB); + env->env = (prf_env_t *)ns_ius_env; + ns_ius_env->shdl = *start_hdl; + ns_ius_env->max_nb_att = NS_IUS_IDX_NB; + ns_ius_env->prf_env.app_task = app_task | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + ns_ius_env->prf_env.prf_task = env->task | PERM(PRF_MI, DISABLE); + env->id = TASK_ID_NS_IUS; + ns_ius_task_init(&(env->desc)); + co_list_init(&(ns_ius_env->values)); + ns_ius_init_ccc_values(ns_ius_att_db, NS_IUS_IDX_NB); + ns_ble_ius_task = env->task; + ke_state_set(ns_ble_ius_task, NS_IUS_IDLE); + } + return status; +} + +/** + * @brief Destruction of the NS IUS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + */ +static void ns_ius_destroy(struct prf_task_env *env) +{ + struct ns_ius_env_tag *ns_ius_env = (struct ns_ius_env_tag *)env->env; + while (!co_list_is_empty(&(ns_ius_env->values))) + { + struct co_list_hdr *hdr = co_list_pop_front(&(ns_ius_env->values)); + ke_free(hdr); + } + env->env = NULL; + ke_free(ns_ius_env); +} +/** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + */ +static void ns_ius_create(struct prf_task_env *env, uint8_t conidx) +{ + int att_idx; + for (att_idx = 1; att_idx < NS_IUS_IDX_NB; att_idx++) + { + if( PERM_GET(ns_ius_att_db[att_idx].perm, UUID_LEN) == 0 && (ns_ius_att_db[att_idx].uuid[0] + (ns_ius_att_db[att_idx].uuid[1]<<8) ) == ATT_DESC_CLIENT_CHAR_CFG) + { + ns_ius_set_ccc_value(conidx, att_idx, 0); + } + } +} +/** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + */ +static void ns_ius_cleanup(struct prf_task_env *env, uint8_t conidx, uint8_t reason) +{ + int att_idx; + struct ns_ius_env_tag *ns_ius_env = (struct ns_ius_env_tag *)env->env; + for (att_idx = 1; att_idx < NS_IUS_IDX_NB; att_idx++) + { + if( PERM_GET(ns_ius_att_db[att_idx].perm, UUID_LEN) == 0 && (ns_ius_att_db[att_idx].uuid[0] + (ns_ius_att_db[att_idx].uuid[1]<<8) ) == ATT_DESC_CLIENT_CHAR_CFG + ) + ns_ius_set_ccc_value(conidx, att_idx, 0); + } + ke_state_set(prf_src_task_get(&(ns_ius_env->prf_env), conidx), NS_IUS_IDLE); +} + +/// NS IUS Task interface required by profile manager +const struct prf_task_cbs ns_ius_itf = +{ + (prf_init_fnct) ns_ius_init, + ns_ius_destroy, + ns_ius_create, + ns_ius_cleanup, +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ +const struct prf_task_cbs* ns_ius_prf_itf_get(void) +{ + return &ns_ius_itf; +} + + + + + + + + + + + + +#endif //BLE_APP_NS_IUS + + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/src/ns_iuss_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/src/ns_iuss_task.c new file mode 100644 index 0000000..b901947 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/ns_ius/ns_iuss/src/ns_iuss_task.c @@ -0,0 +1,448 @@ +/** + **************************************************************************************** + * + * @file ns_iuss_task.c + * + * @brief Custom Service profile source file. + * + * + * + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_NS_IUS) +#include "ns_iuss_task.h" +#include "ns_iuss.h" +#include "app_ns_ius.h" + + +#include "prf_utils.h" +#include "prf.h" +#include "attm_db.h" +#include "ke_mem.h" +#include "att.h" +#include "co_utils.h" +#include "attm.h" +#include "ke_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "gattc_task.h" +#include "attm_db.h" +#include "ns_log.h" + + +ke_task_id_t ns_ble_ius_task; + + + +/* Private functions ---------------------------------------------------------*/ + + + + +/** + * @brief Stores characteristic value. + * @param[in] att_idx Custom attribut index. + * @param[in] length Value length. + * @param[in] data Pointer to value data. + * @return 0 on success. + */ +static int ns_ius_att_set_value(uint8_t att_idx, uint16_t length, const uint8_t *data) +{ + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + struct ns_ius_val_elmt *val = (struct ns_ius_val_elmt *) co_list_pick(&(ns_ius_env->values)); + while (val != NULL) + { + if (val->att_idx == att_idx) + { + if (length != val->length) + { + co_list_extract(&ns_ius_env->values, &val->hdr); + ke_free(val); + val = NULL; + } + break; + } + val = (struct ns_ius_val_elmt *)val->hdr.next; + } + + if (val == NULL) + { + val = (struct ns_ius_val_elmt *) ke_malloc(sizeof(struct ns_ius_val_elmt) + length, KE_MEM_ATT_DB); + co_list_push_back(&ns_ius_env->values, &val->hdr); + } + val->att_idx = att_idx; + val->length = length; + memcpy(val->data, data, length); + + return 0; +} +/** + * @brief Read characteristic value from. + * Function checks if attribute exists, and if so return its length and pointer to data. + * @param[in] att_idx Custom attribute index. + * @param[out] length Pointer to variable that receive length of the attribute. + * @param[out] data Pointer to variable that receive pointer characteristic value. + * @return 0 on success, ATT_ERR_ATTRIBUTE_NOT_FOUND if there is no value for such attribyte. + */ +static int ns_ius_att_get_value(uint8_t att_idx, uint16_t *length, const uint8_t **data) +{ + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + struct ns_ius_val_elmt *val = (struct ns_ius_val_elmt *) co_list_pick(&ns_ius_env->values); + + while (val != NULL) + { + if (val->att_idx == att_idx) + { + *length = val->length; + *data = val->data; + break; + } + + val = (struct ns_ius_val_elmt *)val->hdr.next; + } + + if (val == NULL) + { + *length = 0; + *data = NULL; + } + return val ? 0 : ATT_ERR_ATTRIBUTE_NOT_FOUND; +} +/** + * @brief Sets initial values for all Clinet Characteristic Configurations. + * @param[in] att_db Custom service attribute definition table. + * @param[in] max_nb_att Number of elements in att_db. + */ +void ns_ius_init_ccc_values(const struct attm_desc_128 *att_db, int max_nb_att) +{ + uint8_t ccc_values[BLE_CONNECTION_MAX] = {0}; + for (int i = 1; i < max_nb_att; i++) + { + if( PERM_GET(att_db[i].perm, UUID_LEN) == PERM_UUID_16 && (att_db[i].uuid[0] + (att_db[i].uuid[1]<<8) ) == ATT_DESC_CLIENT_CHAR_CFG) + { + ns_ius_att_set_value(i, sizeof(ccc_values), ccc_values); + } + } +} +/** + * @brief Set value of CCC for given attribute and connection index. + * @param[in] conidx Connection index. + * @param[in] att_idx CCC attribute index. + * @param[in] cc Value to store. + */ +void ns_ius_set_ccc_value(uint8_t conidx, uint8_t att_idx, uint16_t ccc) +{ + uint16_t length; + const uint8_t *value; + uint8_t new_value[BLE_CONNECTION_MAX]; + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + ns_ius_att_get_value(att_idx, &length, &value); + ASSERT_ERR(length); + ASSERT_ERR(value); + memcpy(new_value, value, length); + new_value[conidx] = (uint8_t)ccc; + ns_ius_att_set_value(att_idx, length, new_value); +} +/** + * @brief Read value of CCC for given attribute and connection index. + * @param[in] conidx Connection index. + * @param[in] att_idx Custom attribute index. + * @return Value of CCC. + */ +static uint16_t ns_ius_get_ccc_value(uint8_t conidx, uint8_t att_idx) +{ + uint16_t length; + const uint8_t *value; + uint16_t ccc_value; + ns_ius_att_get_value(att_idx, &length, &value); + ccc_value = value[conidx]; + return ccc_value; +} + +static uint8_t ns_ius_get_att_idx(uint16_t handle, uint8_t *att_idx) +{ + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + uint8_t status = PRF_APP_ERROR; + + if ((handle >= ns_ius_env->shdl) && (handle < ns_ius_env->shdl + ns_ius_env->max_nb_att)) + { + *att_idx = handle - ns_ius_env->shdl; + status = ATT_ERR_NO_ERROR; + } + + return status; +} +static uint16_t get_value_handle(uint16_t cfg_handle) +{ + uint8_t uuid[ATT_UUID_128_LEN]; + uint8_t uuid_len; + uint16_t handle = cfg_handle; + struct attm_svc *srv; + + srv = attmdb_get_service(handle); + + while ((handle >= srv->svc.start_hdl) && (handle <= srv->svc.end_hdl)) + { + struct attm_elmt elmt; + attmdb_get_attribute(handle, &elmt); + attmdb_get_uuid(&elmt, &uuid_len, uuid, false, false); + if (*(uint16_t *)&uuid[0] == ATT_DECL_CHARACTERISTIC) + return handle + 1; + + handle--; + } + + return 0; +} +static int check_client_char_cfg(bool is_notification, const struct gattc_write_req_ind *param) +{ + uint8_t status = GAP_ERR_NO_ERROR; + uint16_t ntf_cfg = 0; + + if (param->length != sizeof(uint16_t)) + { + status = ATT_ERR_INVALID_ATTRIBUTE_VAL_LEN; + } + else + { + ntf_cfg = *((uint16_t*)param->value); + + if (is_notification) + { + if ( (ntf_cfg != PRF_CLI_STOP_NTFIND) && (ntf_cfg != PRF_CLI_START_NTF) ) + { + status = PRF_ERR_INVALID_PARAM; + } + } + else + { + if ( (ntf_cfg != PRF_CLI_STOP_NTFIND) && (ntf_cfg != PRF_CLI_START_IND) ) + { + status = PRF_ERR_INVALID_PARAM; + } + } + } + + return status; +} + +/** + * @brief Handles reception of the @ref GATTC_READ_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int gattc_read_req_ind_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + const struct gattc_read_req_ind *p_param = (const struct gattc_read_req_ind *)param; + + ke_state_t state = ke_state_get(dest_id); + + if(state == NS_IUS_IDLE) + { + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + struct gattc_read_cfm * cfm; + uint8_t att_idx = 0; + uint8_t conidx = KE_IDX_GET(src_id); + + uint8_t status = ns_ius_get_att_idx(p_param->handle, &att_idx); + uint16_t length = 0; + uint16_t ccc_val = 0; + + if (status == GAP_ERR_NO_ERROR) + { + if( PERM_GET(ns_ius_att_db[att_idx].perm, UUID_LEN) == PERM_UUID_16 && (ns_ius_att_db[att_idx].uuid[0] + (ns_ius_att_db[att_idx].uuid[1]<<8) ) == ATT_DESC_CLIENT_CHAR_CFG) + { + ccc_val = ns_ius_get_ccc_value(conidx, att_idx); + length = 2; + } + else + { + struct ns_ius_value_req_ind* req_ind = KE_MSG_ALLOC(NS_IUS_VALUE_REQ_IND, + prf_dst_task_get(&(ns_ius_env->prf_env), KE_IDX_GET(src_id)), + dest_id, + ns_ius_value_req_ind); + + req_ind->conidx = KE_IDX_GET(src_id); + req_ind->att_idx = att_idx; + ke_msg_send(req_ind); + ke_state_set(dest_id, NS_IUS_BUSY); + + return KE_MSG_CONSUMED; + } + } + cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + src_id, + dest_id, + gattc_read_cfm, + length); + + cfm->handle = p_param->handle; + cfm->status = status; + cfm->length = length; + + if (status == GAP_ERR_NO_ERROR) + { + memcpy(cfm->value, &ccc_val, length); + } + ke_msg_send(cfm); + + return KE_MSG_CONSUMED; + } + else + { + return KE_MSG_SAVED; + } +} +/** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int gattc_write_req_ind_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + const struct gattc_write_req_ind *p_param = (const struct gattc_write_req_ind *)param; + + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + uint8_t att_idx = 0; + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t status = ns_ius_get_att_idx(p_param->handle, &att_idx); + + uint16_t perm; + if (status == ATT_ERR_NO_ERROR) + { + if( PERM_GET(ns_ius_att_db[att_idx].perm, UUID_LEN) == PERM_UUID_16 && + (ns_ius_att_db[att_idx].uuid[0] + (ns_ius_att_db[att_idx].uuid[1]<<8) ) == ATT_DESC_CLIENT_CHAR_CFG) + { + struct attm_elmt elem = {0}; + uint16_t value_hdl = get_value_handle(p_param->handle); + attmdb_att_get_permission(value_hdl, &perm, PERM_MASK_ALL, 0, &elem); + status = check_client_char_cfg(PERM_IS_SET(perm, NTF, ENABLE), p_param); + + if (status == ATT_ERR_NO_ERROR) + { + ns_ius_set_ccc_value(conidx, att_idx, *(uint16_t *)p_param->value); + } + } + else + { + } + + if (status == ATT_ERR_NO_ERROR) + { + + struct ns_ius_val_write_ind *req_id = KE_MSG_ALLOC_DYN(NS_IUS_VAL_WRITE_IND, + prf_dst_task_get(&(ns_ius_env->prf_env), KE_IDX_GET(src_id)), + dest_id, ns_ius_val_write_ind, + p_param->length); + memcpy(req_id->value, p_param->value, p_param->length); + req_id->conidx = conidx; + req_id->handle = att_idx; + req_id->length = p_param->length; + ke_msg_send(req_id); + } + } + + struct gattc_write_cfm * cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + cfm->handle = p_param->handle; + cfm->status = status; + ke_msg_send(cfm); + + return KE_MSG_CONSUMED; +} +/** + * @brief Handles reception of the @ref RDTS_ATT_INFO_RSP message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance (probably unused). + * @return If the message shall be consumed or not. + */ +static int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + const struct gattc_att_info_req_ind *p_param = (const struct gattc_att_info_req_ind *)param; + uint8_t state = ke_state_get(dest_id); + if (state == NS_IUS_IDLE) + { + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + struct ns_ius_att_info_req *req = KE_MSG_ALLOC(NS_IUS_ATT_INFO_REQ, + TASK_APP, + dest_id, + ns_ius_att_info_req); + req->conidx = KE_IDX_GET(src_id); + req->att_idx = p_param->handle - ns_ius_env->shdl; + ke_msg_send(req); + } + return KE_MSG_CONSUMED; +} +/** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * @details The GATTC_CMP_EVT message that signals the completion of a GATTC_NOTIFY + * operation is sent back as soon as the notification PDU has been sent over + * the air. + * The GATTC_CMP_EVT message that signals the completion of a GATTC_INDICATE + * operation is sent back as soon as the ATT_HANDLE_VALUE_CONFIRMATION PDU is + * received confirming that the indication has been correctly received by the + * peer device. + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + struct gattc_cmp_evt const *p_param = (struct gattc_cmp_evt const *)param; + + + if (p_param->operation == GATTC_NOTIFY) + { + ke_state_set(ns_ble_ius_task, NS_IUS_IDLE); + } + return KE_MSG_CONSUMED; +} +/* + * GLOBAL VARIABLE DEFINITIONS + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(ns_ius) +{ + {GATTC_READ_REQ_IND, gattc_read_req_ind_handler}, + {GATTC_WRITE_REQ_IND, gattc_write_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, gattc_att_info_req_ind_handler}, + {GATTC_CMP_EVT, gattc_cmp_evt_handler}, +}; + + +void ns_ius_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct ns_ius_env_tag *p_ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + + p_task_desc->msg_handler_tab = ns_ius_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(ns_ius_msg_handler_tab); + p_task_desc->state = p_ns_ius_env->state; + p_task_desc->idx_max = NS_IUS_IDX_MAX; +} + + + + +#endif //BLE_APP_NS_IUS + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasp_common.h new file mode 100644 index 0000000..845b7db --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasp_common.h @@ -0,0 +1,90 @@ +/** + **************************************************************************************** + * + * @file pasp_common.h + * + * @brief Header File - Phone Alert Status Profile Common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +#ifndef _PASP_COMMON_H_ +#define _PASP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup PASP Phone Alert Status Profile + * @ingroup PROFILE + * @brief Phone Alert Status Profile + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Alert Status all bit enabled +#define PASP_ALERT_STATUS_VAL_MAX (0x07) + + +/* + * ENUMERATIONS + **************************************************************************************** + */ +/// Phone Alert Status Alert Status bit field +enum pasp_alert_status_bf +{ + /// Ringer State + /// 0 not active and 1 active + PASP_RINGER_STATE_POS = 0, + PASP_RINGER_STATE_BIT = CO_BIT(PASP_RINGER_STATE_POS), + + /// Vibrate State + /// 0 not active and 1 active + PASP_VIBRATE_STATE_POS = 1, + PASP_VIBRATE_STATE_BIT = CO_BIT(PASP_VIBRATE_STATE_POS), + + /// Display Alert State + /// 0 not active and 1 active + PASP_DISP_ALERT_STATE_POS = 2, + PASP_DISP_ALERT_STATE_BIT = CO_BIT(PASP_DISP_ALERT_STATE_POS), +}; + +/// Phone Alert Status Ringer Setting value +enum pasp_ringer_setting_value +{ + /// Ringer Silent + PASP_RINGER_SILENT = (0), + + /// Ringer Normal + PASP_RINGER_NORMAL = (1), +}; + +/// Phone Alert Status Ringer Control Point value +enum pasp_ringer_ctnl_pt_value +{ + /// Set Silent Mode + PASP_SILENT_MODE = (1), + + /// Mute Once + PASP_MUTE_ONCE = (2), + + /// Cancel Silent Mode + PASP_CANCEL_SILENT_MODE = (3), +}; + +/// @} pasp_common + +#endif //(_HTP_COMMON_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/api/paspc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/api/paspc_task.h new file mode 100644 index 0000000..120a73f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/api/paspc_task.h @@ -0,0 +1,203 @@ +/** + **************************************************************************************** + * + * @file paspc_task.h + * + * @brief Header file - Phone Alert Status Profile Client Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _PASPC_TASK_H_ +#define _PASPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup PASPCTASK Phone Alert Status Profile Client Task + * @ingroup PASPC + * @brief Phone Alert Status Profile Client Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "pasp_common.h" +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Message IDs +/*@TRACE*/ +enum paspc_msg_ids +{ + /// Enable the Phone Alert Status Profile Client task - at connection + PASPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_PASPC), + /// Enable the Phone Alert Status Profile Client task - at connection + PASPC_ENABLE_RSP, + + /// Read the value of an attribute in the peer device database + PASPC_READ_CMD, + /// Write the value of an attribute in the peer device database + PASPC_WRITE_CMD, + + /// Indicate that an attribute value has been received either upon notification or read response + PASPC_VALUE_IND, + + /// Complete Event Information + PASPC_CMP_EVT, +}; + +/// Operation Codes +enum paspc_op_codes +{ + /// Reserved operation code + PASPC_RESERVED_OP_CODE = 0x00, + + /// Discovery Procedure + PASPC_ENABLE_OP_CODE, + /// Read attribute value Procedure + PASPC_READ_OP_CODE, + /// Write attribute value Procedure + PASPC_WRITE_OP_CODE, +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ + +/// Phone Alert Status Service Characteristics +enum +{ + /// Alert Status + PASPC_CHAR_ALERT_STATUS, + /// Ringer Setting + PASPC_CHAR_RINGER_SETTING, + /// Ringer Control Point + PASPC_CHAR_RINGER_CTNL_PT, + + PASPC_CHAR_MAX, +}; + +/// Phone Alert Status Service Characteristic Descriptors +enum +{ + /// Alert Status Char. - Client Characteristic Configuration + PASPC_DESC_ALERT_STATUS_CL_CFG, + /// Ringer Setting Char. - Client Characteristic Configuration + PASPC_DESC_RINGER_SETTING_CL_CFG, + + PASPC_DESC_MAX, + + PASPC_DESC_MASK = 0x10, +}; + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Phone Alert Status Service + */ +struct paspc_pass_content +{ + /// Service info + struct prf_svc svc; + + /// Characteristic info: + /// - Alert Status + /// - Ringer Setting + /// - Ringer Control Point + struct prf_char_inf chars[PASPC_CHAR_MAX]; + + /// Descriptor handles: + /// - Alert Status Client Cfg + /// - Ringer Setting Client Cfg + struct prf_char_desc_inf descs[PASPC_DESC_MAX]; +}; + + +/// Parameters of the @ref PASPC_ENABLE_REQ message +struct paspc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values PASS + struct paspc_pass_content pass; +}; + +/// Parameters of the @ref PASPC_ENABLE_RSP message +struct paspc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values PASS + struct paspc_pass_content pass; +}; + +/// Parameters of the @ref PASPC_READ_CMD message +struct paspc_read_cmd +{ + /// Read code + uint8_t read_code; +}; + +/// Parameters of the @ref PASPC_WRITE_CMD message +struct paspc_write_cmd +{ + /// Write code @see enum paspc_rd_wr_codes + uint8_t write_code; + /// Value + union write_value_tag + { + /// Ringer Control Point characteristic value + uint8_t ringer_ctnl_pt; + /// Alert Status characteristic client characteristic configuration value + uint16_t alert_status_ntf_cfg; + /// Ringer Setting characteristic client characteristic configuration value + uint16_t ringer_setting_ntf_cfg; + } value; +}; + +/// Parameters of the @ref PASPC_VALUE_IND message +struct paspc_value_ind +{ + /// Attribute Code @see enum paspc_rd_wr_codes + uint8_t att_code; + /// Value + union value_tag + { + /// Alert Status characteristic value + uint8_t alert_status; + /// Ringer Setting characteristic value + uint8_t ringer_setting; + /// Alert Status characteristic client characteristic configuration value + uint16_t alert_status_ntf_cfg; + /// Ringer Setting characteristic client characteristic configuration value + uint16_t ringer_setting_ntf_cfg; + } value; +}; + +/// Parameters of the @ref PASPC_CMP_EVT message +struct paspc_cmp_evt +{ + /// Operation code @see enum paspc_op_codes + uint8_t operation; + /// Status + uint8_t status; +}; + + +/// @} PASPCTASK + +#endif //(_PASPC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/sourcelist.txt new file mode 100644 index 0000000..e0ed033 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + paspc.c + paspc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/src/paspc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/src/paspc.c new file mode 100644 index 0000000..7eeffb9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/src/paspc.c @@ -0,0 +1,223 @@ +/** + **************************************************************************************** + * + * @file paspc.c + * + * @brief Phone Alert Status Profile Client implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup PASPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_PAS_CLIENT) +#include "pasp_common.h" + +#include "paspc.h" +#include "paspc_task.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the PASPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t paspc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct paspc_env_tag *p_paspc_env = + (struct paspc_env_tag *) ke_malloc(sizeof(struct paspc_env_tag), KE_MEM_ATT_DB); + + // allocate PASPC required environment variable + p_env->env = (prf_env_t *) p_paspc_env; + + p_paspc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_paspc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_PASPC; + paspc_task_init(&(p_env->desc)); + + for (idx = 0; idx < PASPC_IDX_MAX; idx++) + { + p_paspc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), PASPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void paspc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct paspc_env_tag* p_paspc_env = (struct paspc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_paspc_env->p_env[conidx] != NULL) + { + ke_free(p_paspc_env->p_env[conidx]); + p_paspc_env->p_env[conidx] = NULL; + } + + // Put PASP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), PASPC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the PASPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void paspc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct paspc_env_tag* p_paspc_env = (struct paspc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < PASPC_IDX_MAX; idx++) + { + paspc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_paspc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void paspc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put PASP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), PASPC_IDLE); +} + +/// PASPC Task interface required by profile manager +const struct prf_task_cbs paspc_itf = +{ + paspc_init, + paspc_destroy, + paspc_create, + paspc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *paspc_prf_itf_get(void) +{ + return &paspc_itf; +} + +void paspc_enable_rsp_send(struct paspc_env_tag *p_paspc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on PASPS + struct paspc_enable_rsp *p_rsp = KE_MSG_ALLOC( + PASPC_ENABLE_RSP, + prf_dst_task_get(&(p_paspc_env->prf_env), conidx), + prf_src_task_get(&(p_paspc_env->prf_env), conidx), + paspc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->pass = p_paspc_env->p_env[conidx]->pass; + // Register PASPC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_paspc_env->prf_env), conidx, &(p_paspc_env->p_env[conidx]->pass.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_paspc_env->prf_env), conidx), PASPC_IDLE); + } + + ke_msg_send(p_rsp); +} + +void paspc_send_cmp_evt(struct paspc_env_tag *p_paspc_env, uint8_t conidx, + uint8_t operation, uint8_t status) +{ + struct paspc_cmp_evt *p_evt; + + // Go back to the CONNECTED state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_paspc_env->prf_env), conidx)) == PASPC_BUSY) + { + ke_state_set(prf_src_task_get(&p_paspc_env->prf_env, conidx), PASPC_IDLE); + } + + // Send the message + p_evt = KE_MSG_ALLOC(PASPC_CMP_EVT, + prf_dst_task_get(&(p_paspc_env->prf_env), conidx), + prf_src_task_get(&(p_paspc_env->prf_env), conidx), + paspc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //(BLE_PAS_CLIENT) + +/// @} PASPC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/src/paspc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/src/paspc.h new file mode 100644 index 0000000..e6523e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/src/paspc.h @@ -0,0 +1,169 @@ +/** + **************************************************************************************** + * + * @file paspc.h + * + * @brief Header file - Phone Alert Status Profile - Client Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _PASPC_H_ +#define _PASPC_H_ + +/** + **************************************************************************************** + * @addtogroup PASPC Phone Alert Status Profile Client + * @ingroup PASP + * @brief Phone Alert Status Profile Client + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_PAS_CLIENT) +#include "pasp_common.h" +#include "paspc_task.h" +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Phone Alert Status Client task instances +#define PASPC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the PASPC task +enum paspc_states +{ + /// Idle state + PASPC_FREE, + /// Connected state + PASPC_IDLE, + /// Busy state + PASPC_DISCOVERING, + /// Busy state + PASPC_BUSY, + + /// Number of defined states. + PASPC_STATE_MAX +}; + +/// Internal codes for reading/writing a PAS characteristic with one single request +enum paspc_rd_wr_codes +{ + /// Read PAS Alert Status + PASPC_RD_ALERT_STATUS = PASPC_CHAR_ALERT_STATUS, + /// Read PAS Ringer Setting + PASPC_RD_RINGER_SETTING = PASPC_CHAR_RINGER_SETTING, + /// Write PAS Ringer Control Point + PASPC_WR_RINGER_CTNL_PT = PASPC_CHAR_RINGER_CTNL_PT, + + /// Read/Write PAS Alert Status Client Characteristic Configuration Descriptor + PASPC_RD_WR_ALERT_STATUS_CFG = (PASPC_DESC_ALERT_STATUS_CL_CFG | PASPC_DESC_MASK), + /// Read PAS Ringer Setting Client Characteristic Configuration Descriptor + PASPC_RD_WR_RINGER_SETTING_CFG = (PASPC_DESC_RINGER_SETTING_CL_CFG | PASPC_DESC_MASK), +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +struct paspc_cnx_env +{ + /// Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Last characteristic code used in a read or a write request + uint16_t last_char_code; + /// Counter used to check service uniqueness + uint8_t nb_svc; + /// Current operation code + uint8_t operation; + /// Phone Alert Status Service Characteristics + struct paspc_pass_content pass; +}; + +/// Phone Alert Status Profile Client environment variable +struct paspc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct paspc_cnx_env *p_env[PASPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[PASPC_IDX_MAX]; +}; + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve PASP client profile interface + * @return PASP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *paspc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Phone Alert Status ATT DB discovery results to PASPC host. + * @param[in] p_paspc_env environment variable + * @param[in] conidx Connection index + * @param[in] status Status + **************************************************************************************** + */ +void paspc_enable_rsp_send(struct paspc_env_tag *p_paspc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send a PASPC_CMP_EVT message to the task which enabled the profile + * @param[in] p_paspc_env environment variable + * @param[in] conidx Connection index + * @param[in] operation Operation code + * @param[in] status Status + **************************************************************************************** + */ +void paspc_send_cmp_evt(struct paspc_env_tag *p_paspc_env, uint8_t conidx, + uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void paspc_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_PAS_CLIENT) + +/// @} PASPC + +#endif //(_PASPC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/src/paspc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/src/paspc_task.c new file mode 100644 index 0000000..871a6e1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/paspc/src/paspc_task.c @@ -0,0 +1,710 @@ +/** + **************************************************************************************** + * + * @file paspc_task.c + * + * @brief Phone Alert Status Profile Client Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup PASPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_PAS_CLIENT) +#include "pasp_common.h" +#include "paspc_task.h" +#include "paspc.h" + +#include "gap.h" +#include "attm.h" +#include "gattc_task.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve Phone Alert Status service characteristics information +const struct prf_char_def paspc_pass_char[PASPC_CHAR_MAX] = +{ + // Alert Status + [PASPC_CHAR_ALERT_STATUS] = {ATT_CHAR_ALERT_STATUS, + ATT_MANDATORY, + ATT_CHAR_PROP_RD | ATT_CHAR_PROP_NTF}, + // Ringer Setting + [PASPC_CHAR_RINGER_SETTING] = {ATT_CHAR_RINGER_SETTING, + ATT_MANDATORY, + ATT_CHAR_PROP_RD | ATT_CHAR_PROP_NTF}, + // Ringer Control Point + [PASPC_CHAR_RINGER_CTNL_PT] = {ATT_CHAR_RINGER_CNTL_POINT, + ATT_MANDATORY, + ATT_CHAR_PROP_WR_NO_RESP}, +}; + +/// State machine used to retrieve Phone Alert Status service characteristic descriptor information +const struct prf_char_desc_def paspc_pass_char_desc[PASPC_DESC_MAX] = +{ + // Alert Status Client Characteristic Configuration + [PASPC_DESC_ALERT_STATUS_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + PASPC_CHAR_ALERT_STATUS}, + // Ringer Setting Client Characteristic Configuration + [PASPC_DESC_RINGER_SETTING_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + PASPC_CHAR_RINGER_SETTING}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref PASPC_ENABLE_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int paspc_enable_req_handler(ke_msg_id_t const msgid, + struct paspc_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Phone Alert Status Profile Client Role Task Environment + struct paspc_env_tag *p_paspc_env = PRF_ENV_GET(PASPC, paspc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if ((state == PASPC_IDLE) && (p_paspc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_paspc_env->p_env[conidx] = (struct paspc_cnx_env *) ke_malloc(sizeof(struct paspc_cnx_env), KE_MEM_ATT_DB); + memset(p_paspc_env->p_env[conidx], 0, sizeof(struct paspc_cnx_env)); + + p_paspc_env->p_env[conidx]->operation = PASPC_ENABLE_OP_CODE; + + // Start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + prf_disc_svc_send(&(p_paspc_env->prf_env), conidx, ATT_SVC_PHONE_ALERT_STATUS); + + // Go to DISCOVERING state + ke_state_set(dest_id, PASPC_DISCOVERING); + + // Configure the environment for a discovery procedure + p_paspc_env->p_env[conidx]->last_uuid_req = ATT_SVC_PHONE_ALERT_STATUS; + } + // Bond information is provided + else + { + // Keep the provided database content + memcpy(&p_paspc_env->p_env[conidx]->pass, &p_param->pass, sizeof(struct paspc_pass_content)); + + //send APP confirmation that can start normal connection to TH + paspc_enable_rsp_send(p_paspc_env, conidx, GAP_ERR_NO_ERROR); + + /* -------------------------------------------------------------------------------- + * After connection establishment, once the discovery procedure is successful, + * the client shall read the Alert Status + * -------------------------------------------------------------------------------- */ + // Configure the environment for a read procedure + p_paspc_env->p_env[conidx]->last_char_code = PASPC_RD_ALERT_STATUS; + + // Send the read request + prf_read_char_send(&(p_paspc_env->prf_env), + conidx, p_paspc_env->p_env[conidx]->pass.svc.shdl, + p_paspc_env->p_env[conidx]->pass.svc.ehdl, + p_paspc_env->p_env[conidx]->pass.chars[PASPC_CHAR_ALERT_STATUS].val_hdl); + + // Go to BUSY state + ke_state_set(dest_id, PASPC_BUSY); + } + } + else if (state != PASPC_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + paspc_enable_rsp_send(p_paspc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref PASPC_READ_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int paspc_read_cmd_handler(ke_msg_id_t const msgid, + struct paspc_read_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct paspc_env_tag *p_paspc_env = PRF_ENV_GET(PASPC, paspc); + + if (p_paspc_env != NULL) + { + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + // Check the provided connection handle + do + { + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + + // Check the current state + if (ke_state_get(dest_id) == PASPC_BUSY) + { + // Keep the request for later, state is GAP_ERR_NO_ERROR + msg_status = KE_MSG_SAVED; + break; + } + + switch (p_param->read_code) + { + // Read Alert Status Characteristic Value + case (PASPC_RD_ALERT_STATUS): + { + handle = p_paspc_env->p_env[conidx]->pass.chars[PASPC_CHAR_ALERT_STATUS].val_hdl; + } break; + + // Read Ringer Setting Characteristic Value + case (PASPC_RD_RINGER_SETTING): + { + handle = p_paspc_env->p_env[conidx]->pass.chars[PASPC_CHAR_RINGER_SETTING].val_hdl; + } break; + + // Read Alert Status Characteristic Client Char. Cfg. Descriptor Value + case (PASPC_RD_WR_ALERT_STATUS_CFG): + { + handle = p_paspc_env->p_env[conidx]->pass.descs[PASPC_DESC_ALERT_STATUS_CL_CFG].desc_hdl; + } break; + + // Read Ringer Setting Characteristic Client Char. Cfg. Descriptor Value + case (PASPC_RD_WR_RINGER_SETTING_CFG): + { + handle = p_paspc_env->p_env[conidx]->pass.descs[PASPC_DESC_RINGER_SETTING_CL_CFG].desc_hdl; + } break; + + default: + { + // Handle is ATT_INVALID_SEARCH_HANDLE + status = PRF_ERR_INVALID_PARAM; + } break; + } + + if (status == GAP_ERR_NO_ERROR) + { + // Check if handle is viable + if (handle != ATT_INVALID_SEARCH_HANDLE) + { + // Configure the environment for a read operation + p_paspc_env->p_env[conidx]->operation = PASPC_READ_OP_CODE; + p_paspc_env->p_env[conidx]->last_char_code = p_param->read_code; + + // Send the read request + prf_read_char_send(&(p_paspc_env->prf_env), conidx, + p_paspc_env->p_env[conidx]->pass.svc.shdl, + p_paspc_env->p_env[conidx]->pass.svc.ehdl, + handle); + + // Go to the Busy state + ke_state_set(dest_id, PASPC_BUSY); + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } while(0); + + if (status != GAP_ERR_NO_ERROR) + { + paspc_send_cmp_evt(p_paspc_env, conidx, PASPC_READ_OP_CODE, status); + } + } + else + { + // No connection exists + paspc_send_cmp_evt(p_paspc_env, conidx, PASPC_READ_OP_CODE, PRF_ERR_REQ_DISALLOWED); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref PASPC_WRITE_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int paspc_write_cmd_handler(ke_msg_id_t const msgid, + struct paspc_write_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Get the address of the environment + struct paspc_env_tag *p_paspc_env = PRF_ENV_GET(PASPC, paspc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_paspc_env != NULL) + { + do + { + // Attribute handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Write type + uint8_t wr_type; + // Length + uint8_t length; + + // Check the current state + if (ke_state_get(dest_id) != PASPC_IDLE) + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + break; + } + + switch (p_param->write_code) + { + // Write Ringer Control Point Characteristic Value + case (PASPC_WR_RINGER_CTNL_PT): + { + if ((p_param->value.ringer_ctnl_pt >= PASP_SILENT_MODE) && + (p_param->value.ringer_ctnl_pt <= PASP_CANCEL_SILENT_MODE)) + { + handle = p_paspc_env->p_env[conidx]->pass.chars[PASPC_CHAR_RINGER_CTNL_PT].val_hdl; + length = sizeof(uint8_t); + wr_type = GATTC_WRITE_NO_RESPONSE; + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write Alert Status Characteristic Client Char. Cfg. Descriptor Value + case (PASPC_RD_WR_ALERT_STATUS_CFG): + { + if (p_param->value.alert_status_ntf_cfg <= PRF_CLI_START_NTF) + { + handle = p_paspc_env->p_env[conidx]->pass.descs[PASPC_DESC_ALERT_STATUS_CL_CFG].desc_hdl; + length = sizeof(uint16_t); + wr_type = GATTC_WRITE; + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write Ringer Setting Characteristic Client Char. Cfg. Descriptor Value + case (PASPC_RD_WR_RINGER_SETTING_CFG): + { + if (p_param->value.ringer_setting_ntf_cfg <= PRF_CLI_START_NTF) + { + handle = p_paspc_env->p_env[conidx]->pass.descs[PASPC_DESC_RINGER_SETTING_CL_CFG].desc_hdl; + length = sizeof(uint16_t); + wr_type = GATTC_WRITE; + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + if (status == GAP_ERR_NO_ERROR) + { + // Check if handle is viable + if (handle != ATT_INVALID_SEARCH_HANDLE) + { + // Send the write request + prf_gatt_write(&(p_paspc_env->prf_env), conidx, handle, (uint8_t *)&p_param->value, length, wr_type); + + // Configure the environment for a write operation + p_paspc_env->p_env[conidx]->operation = PASPC_WRITE_OP_CODE; + p_paspc_env->p_env[conidx]->last_char_code = p_param->write_code; + + // Go to the Busy state + ke_state_set(dest_id, PASPC_BUSY); + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } while (0); + } + else + { + status = PRF_ERR_REQ_DISALLOWED; + } + + if (status != GAP_ERR_NO_ERROR) + { + paspc_send_cmp_evt(p_paspc_env, conidx, PASPC_WRITE_OP_CODE, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == PASPC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct paspc_env_tag *p_paspc_env = PRF_ENV_GET(PASPC, paspc); + + ASSERT_INFO(p_paspc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_paspc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_paspc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve PASS characteristics and descriptors + prf_extract_svc_info(p_ind, PASPC_CHAR_MAX, &paspc_pass_char[0], &p_paspc_env->p_env[conidx]->pass.chars[0], + PASPC_DESC_MAX, &paspc_pass_char_desc[0], &p_paspc_env->p_env[conidx]->pass.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_paspc_env->p_env[conidx]->pass.svc.shdl = p_ind->start_hdl; + p_paspc_env->p_env[conidx]->pass.svc.ehdl = p_ind->end_hdl; + } + + p_paspc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct paspc_env_tag *p_paspc_env = PRF_ENV_GET(PASPC, paspc); + + if (p_paspc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == PASPC_DISCOVERING) + { + // Status + uint8_t status = p_param->status; + + if ((status == ATT_ERR_ATTRIBUTE_NOT_FOUND) || + (status == ATT_ERR_NO_ERROR)) + { + // Discovery + // check characteristic validity + if (p_paspc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(PASPC_CHAR_MAX, + p_paspc_env->p_env[conidx]->pass.chars, + paspc_pass_char); + } + // too much services + else if (p_paspc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(PASPC_DESC_MAX, + p_paspc_env->p_env[conidx]->pass.descs, + paspc_pass_char_desc, + p_paspc_env->p_env[conidx]->pass.chars); + } + } + + paspc_enable_rsp_send(p_paspc_env, conidx, status); + } + + else if (state == PASPC_BUSY) + { + switch (p_param->operation) + { + case GATTC_READ: + { + // Send the complete event status + paspc_send_cmp_evt(p_paspc_env, conidx, PASPC_READ_OP_CODE, p_param->status); + } break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + if (p_paspc_env->p_env[conidx]->operation == PASPC_WRITE_OP_CODE) + { + // Send the complete event status + paspc_send_cmp_evt(p_paspc_env, conidx, PASPC_WRITE_OP_CODE, p_param->status); + } + } break; + + case GATTC_REGISTER: + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct paspc_env_tag *p_paspc_env = PRF_ENV_GET(PASPC, paspc); + + if (p_paspc_env != NULL) + { + struct paspc_value_ind *p_ind; + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_ERR(ke_state_get(dest_id) == PASPC_BUSY); + + // Prepare the indication message for the HL + p_ind = KE_MSG_ALLOC(PASPC_VALUE_IND, + prf_dst_task_get(&(p_paspc_env->prf_env), conidx), + dest_id, + paspc_value_ind); + + switch (p_paspc_env->p_env[conidx]->last_char_code) + { + // Read Alert Status Characteristic Value + case (PASPC_RD_ALERT_STATUS): + { + p_ind->value.alert_status = p_param->value[0]; + } break; + + // Read Ringer Setting Characteristic Value + case (PASPC_RD_RINGER_SETTING): + { + p_ind->value.ringer_setting = p_param->value[0]; + } break; + + // Read Alert Status Characteristic Client Char. Cfg. Descriptor Value + case (PASPC_RD_WR_ALERT_STATUS_CFG): + { + p_ind->value.alert_status_ntf_cfg = co_read16p(&p_param->value[0]); + } break; + + // Read Ringer Setting Characteristic Client Char. Cfg. Descriptor Value + case (PASPC_RD_WR_RINGER_SETTING_CFG): + { + p_ind->value.ringer_setting_ntf_cfg = co_read16p(&p_param->value[0]); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + p_ind->att_code = p_paspc_env->p_env[conidx]->last_char_code; + + // Send the message + ke_msg_send(p_ind); + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct paspc_env_tag *p_paspc_env = PRF_ENV_GET(PASPC, paspc); + + if (p_paspc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + struct paspc_value_ind *p_ind; + + ASSERT_ERR((p_param->handle == p_paspc_env->p_env[conidx]->pass.chars[PASPC_CHAR_ALERT_STATUS].val_hdl) || + (p_param->handle == p_paspc_env->p_env[conidx]->pass.chars[PASPC_CHAR_RINGER_SETTING].val_hdl)); + + // Prepare the indication message for the HL + p_ind = KE_MSG_ALLOC(PASPC_VALUE_IND, + prf_dst_task_get(&p_paspc_env->prf_env, conidx), + prf_src_task_get(&p_paspc_env->prf_env, conidx), + paspc_value_ind); + + // Alert Status Characteristic Value + if (p_param->handle == p_paspc_env->p_env[conidx]->pass.chars[PASPC_CHAR_ALERT_STATUS].val_hdl) + { + p_ind->value.alert_status = p_param->value[0]; + p_ind->att_code = PASPC_RD_ALERT_STATUS; + } + // Ringer Setting Characteristic Value + else + { + p_ind->value.ringer_setting = p_param->value[0]; + p_ind->att_code = PASPC_RD_RINGER_SETTING; + } + + // Send the message + ke_msg_send(p_ind); + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(paspc) +{ + {PASPC_ENABLE_REQ, (ke_msg_func_t)paspc_enable_req_handler}, + {PASPC_READ_CMD, (ke_msg_func_t)paspc_read_cmd_handler}, + {PASPC_WRITE_CMD, (ke_msg_func_t)paspc_write_cmd_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void paspc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct paspc_env_tag *p_paspc_env = PRF_ENV_GET(PASPC, paspc); + + p_task_desc->msg_handler_tab = paspc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(paspc_msg_handler_tab); + p_task_desc->state = p_paspc_env->state; + p_task_desc->idx_max = PASPC_IDX_MAX; +} + +#endif //(BLE_PAS_CLIENT) + +/// @} PASPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/api/pasps_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/api/pasps_task.h new file mode 100644 index 0000000..0ee312c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/api/pasps_task.h @@ -0,0 +1,139 @@ +/** + **************************************************************************************** + * + * @file pasps_task.h + * + * @brief Header file - PASPSTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $Rev: $ + * + **************************************************************************************** + */ + +#ifndef PASPS_TASK_H_ +#define PASPS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup PASPSTASK Task + * @ingroup PASPS + * @brief Phone Alert Status Profile Server Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "pasp_common.h" +#include "rwip_task.h" // Task definitions + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Messages for Phone Alert Status Profile Server +/*@TRACE*/ +enum pasps_msg_ids +{ + /// Set Bonded Data + PASPS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_PASPS), + /// Bonded data confirmation + PASPS_ENABLE_RSP, + + /// Update the value of a characteristic + PASPS_UPDATE_CHAR_VAL_CMD, + /// Indicate that an attribute value has been written + PASPS_WRITTEN_CHAR_VAL_IND, + + /// Complete Event Information + PASPS_CMP_EVT, +}; + +/// Operation Codes +enum pasps_op_codes +{ + PASPS_RESERVED_OP_CODE = 0x00, + + /// Enable Procedure + PASPS_ENABLE_OP_CODE, + /// Update Alert Status Char. value + PASPS_UPD_ALERT_STATUS_OP_CODE, + /// Update Ringer Setting Char. value + PASPS_UPD_RINGER_SETTING_OP_CODE, +}; + +/* + * API MESSAGES STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the @ref PASPS_CREATE_DB_REQ message +struct pasps_db_cfg +{ + /// Alert Status Char. Value + uint8_t alert_status; + /// Ringer Settings Char. Value + uint8_t ringer_setting; +}; + +/// Parameters of the @ref PASPS_ENABLE_REQ message +struct pasps_enable_req +{ + /// Alert Status Characteristic Notification Configuration + uint16_t alert_status_ntf_cfg; + /// Ringer Setting Characteristic Notification Configuration + uint16_t ringer_setting_ntf_cfg; +}; + +/// Parameters of the @ref PASPS_ENABLE_RSP message +struct pasps_enable_rsp +{ + /// status + uint8_t status; +}; + +///Parameters of the @ref PASPS_UPDATE_CHAR_VAL_CMD message +struct pasps_update_char_val_cmd +{ + /// Operation Code (PASPS_UPD_ALERT_STATUS_OP_CODE or PASPS_UPD_RINGER_SETTING_OP_CODE) + uint8_t operation; + /// Alert Status Characteristic Value or Ringer Setting Characteristic Value + uint8_t value; +}; + +///Parameters of the @ref PASPS_WRITTEN_CHAR_VAL_IND message +struct pasps_written_char_val_ind +{ + /// Attribute Code @see enum pasps_att_code + uint8_t att_code; + /// Written value + union written_value_tag + { + /// Ringer Control Point Char. Value + uint8_t ringer_ctnl_pt; + /// Alert Status Notification Configuration + uint16_t alert_status_ntf_cfg; + /// Ringer Setting Notification Configuration + uint16_t ringer_setting_ntf_cfg; + } value; +}; + +///Parameters of the @ref PASPS_CMP_EVT message +struct pasps_cmp_evt +{ + /// Operation @see enum pasps_op_codes + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} PASPSTASK + +#endif // PASPS_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/sourcelist.txt new file mode 100644 index 0000000..25b51c6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + pasps.c + pasps_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/src/pasps.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/src/pasps.c new file mode 100644 index 0000000..66f6120 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/src/pasps.c @@ -0,0 +1,267 @@ +/** + **************************************************************************************** + * + * @file pasps.c + * + * @brief Phone Alert Status Profile Server implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $Rev: $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup PASPS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#if (BLE_PAS_SERVER) +#include "pasp_common.h" + +#include "pasps_task.h" +#include "pasps.h" +#include "prf_utils.h" + +#include "ke_mem.h" + +/* + * PHONE ALERT STATUS SERVICE ATTRIBUTES + **************************************************************************************** + */ + +/// Full PAS Database Description - Used to add attributes into the database +const struct attm_desc pasps_att_db[PASS_IDX_NB] = +{ + // Phone Alert Status Service Declaration + [PASS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Alert Status Characteristic Declaration + [PASS_IDX_ALERT_STATUS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Alert Status Characteristic Value + [PASS_IDX_ALERT_STATUS_VAL] = {ATT_CHAR_ALERT_STATUS, PERM(RD, ENABLE) | PERM(NTF, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, + // Alert Status Characteristic - Client Characteristic Configuration Descriptor + [PASS_IDX_ALERT_STATUS_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Ringer Setting Characteristic Declaration + [PASS_IDX_RINGER_SETTING_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Ringer Settings Characteristic Value + [PASS_IDX_RINGER_SETTING_VAL] = {ATT_CHAR_RINGER_SETTING, PERM(RD, ENABLE) | PERM(NTF, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, + // Ringer Settings Characteristic - Client Characteristic Configuration Descriptor + [PASS_IDX_RINGER_SETTING_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Ringer Control Point Characteristic Declaration + [PASS_IDX_RINGER_CTNL_PT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Ringer Control Point Characteristic Value + [PASS_IDX_RINGER_CTNL_PT_VAL] = {ATT_CHAR_RINGER_CNTL_POINT, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the PASPS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t pasps_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct pasps_db_cfg *p_params) +{ + //------------------ create the attribute database for the profile ------------------- + // Service content flag + uint32_t cfg_flag= PASPS_DB_CFG_FLAG; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + // Add service in the database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_PHONE_ALERT_STATUS, (uint8_t *)&cfg_flag, + PASS_IDX_NB, NULL, p_env->task, &pasps_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, ENABLE)); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + // Allocate PASPS required environment variable + struct pasps_env_tag *p_pasps_env = + (struct pasps_env_tag* ) ke_malloc(sizeof(struct pasps_env_tag), KE_MEM_ATT_DB); + + // Initialize PASPS environment + p_env->env = (prf_env_t *) p_pasps_env; + p_pasps_env->shdl = *p_start_hdl; + + p_pasps_env->alert_status = p_params->alert_status; + p_pasps_env->ringer_setting = p_params->ringer_setting; + + p_pasps_env->operation = PASPS_RESERVED_OP_CODE; + + p_pasps_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Multi Instantiated task + p_pasps_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_PASPS; + pasps_task_init(&(p_env->desc)); + + for (uint8_t idx = 0; idx < BLE_CONNECTION_MAX; idx++) + { + p_pasps_env->p_env[idx] = NULL; + // Put PASS in disabled state + ke_state_set(KE_BUILD_ID(p_env->task, idx), PASPS_FREE); + } + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the PASPS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void pasps_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct pasps_env_tag *p_pasps_env = (struct pasps_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < BLE_CONNECTION_MAX; idx++) + { + if (p_pasps_env->p_env[idx] != NULL) + { + ke_free(p_pasps_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_pasps_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void pasps_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct pasps_env_tag *p_pasps_env = (struct pasps_env_tag *) p_env->env; + + p_pasps_env->p_env[conidx] = (struct pasps_cnx_env *) + ke_malloc(sizeof(struct pasps_cnx_env), KE_MEM_ATT_DB); + + memset(p_pasps_env->p_env[conidx], 0, sizeof(struct pasps_cnx_env)); + + p_pasps_env->p_env[conidx]->ringer_state = p_pasps_env->ringer_setting; + // Put PASS in idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), PASPS_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void pasps_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct pasps_env_tag *p_pasps_env = (struct pasps_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_pasps_env->p_env[conidx] != NULL) + { + ke_free(p_pasps_env->p_env[conidx]); + p_pasps_env->p_env[conidx] = NULL; + } + + // Put PASS in disabled state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), PASPS_FREE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// PASPS Task interface required by profile manager +const struct prf_task_cbs pasps_itf = +{ + (prf_init_fnct) pasps_init, + pasps_destroy, + pasps_create, + pasps_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *pasps_prf_itf_get(void) +{ + return &pasps_itf; +} + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ +void pasps_send_cmp_evt(ke_task_id_t src_id, ke_task_id_t dest_id, + uint8_t operation, uint8_t status) +{ + // Send the message to the application + struct pasps_cmp_evt *p_evt = KE_MSG_ALLOC(PASPS_CMP_EVT, + dest_id, src_id, + pasps_cmp_evt); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == PASPS_BUSY) + { + ke_state_set(src_id, PASPS_IDLE); + } + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //(BLE_PASP_SERVER) + +/// @} PASPS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/src/pasps.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/src/pasps.h new file mode 100644 index 0000000..165237d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/src/pasps.h @@ -0,0 +1,213 @@ +/** + **************************************************************************************** + * + * @file pasps.h + * + * @brief Header file - Phone Alert Status Profile Server. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $Rev: $ + * + **************************************************************************************** + */ + +#ifndef PASPS_H_ +#define PASPS_H_ + +/** + **************************************************************************************** + * @addtogroup PASPS Phone Alert Status Profile Server + * @ingroup PASP + * @brief Phone Alert Status Profile Server + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#if (BLE_PAS_SERVER) +#include "pasp_common.h" + +#include +#include +#include "prf_types.h" +#include "prf.h" +#include "attm.h" + + +/* + * DEFINES + **************************************************************************************** + */ + +/// Number of parallel instances of the task +#define PASPS_IDX_MAX (BLE_CONNECTION_MAX) +/// Database Configuration Flag +#define PASPS_DB_CFG_FLAG (0x01FF) + +/// Notification States Flags +#define PASPS_FLAG_ALERT_STATUS_CFG (0x01) +#define PASPS_FLAG_RINGER_SETTING_CFG (0x02) +/// CP Discovery or Bonded data used +#define PASPS_FLAG_CFG_PERFORMED_OK (0x80) + + +/* + * MACROS + **************************************************************************************** + */ + +#define PASPS_IS_NTF_ENABLED(conidx, idx_env, flag) ((idx_env->p_env[conidx]->ntf_state & flag) == flag) + +#define PASPS_ENABLE_NTF(conidx, idx_env, flag) (idx_env->p_env[conidx]->ntf_state |= flag) + +#define PASPS_DISABLE_NTF(conidx, idx_env, flag) (idx_env->p_env[conidx]->ntf_state &= ~flag) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the PASPS task +enum pasps_states +{ + /// Not connected state + PASPS_FREE, + /// Idle state + PASPS_IDLE, + /// Busy state + PASPS_BUSY, + + /// Number of defined states. + PASPS_STATE_MAX +}; + +/// Attributes State Machine +enum pasps_pass_att_list +{ + PASS_IDX_SVC, + + PASS_IDX_ALERT_STATUS_CHAR, + PASS_IDX_ALERT_STATUS_VAL, + PASS_IDX_ALERT_STATUS_CFG, + + PASS_IDX_RINGER_SETTING_CHAR, + PASS_IDX_RINGER_SETTING_VAL, + PASS_IDX_RINGER_SETTING_CFG, + + PASS_IDX_RINGER_CTNL_PT_CHAR, + PASS_IDX_RINGER_CTNL_PT_VAL, + + PASS_IDX_NB, +}; + +/// Attribute Codes +enum pasps_att_code +{ + /// Alert Status Characteristic + PASPS_ALERT_STATUS_CHAR_VAL, + /// Ringer Setting Characteristic + PASPS_RINGER_SETTING_CHAR_VAL, + /// Ringer Control Point Characteristic + PASPS_RINGER_CTNL_PT_CHAR_VAL, + + /// Alert Status Characteristic - Notification Configuration + PASPS_ALERT_STATUS_NTF_CFG, + /// Ringer Setting Characteristic - Notification Configuration + PASPS_RINGER_SETTING_NTF_CFG, +}; + + + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Phone Alert Status Profile Server Connection Dependent Environment Variable +struct pasps_cnx_env +{ + /// Ringer State + uint8_t ringer_state; + + /** + * Ringer State + Notification State + * Bit 0: Alert Status notification configuration + * Bit 1: Ringer setting notification configuration + */ + uint8_t ntf_state; +}; + +/// Phone Alert Status Profile Server Environment Variable +struct pasps_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Phone Alert Status Service Start Handle + uint16_t shdl; + /// Environment variable pointer for each connections + struct pasps_cnx_env *p_env[BLE_CONNECTION_MAX]; + + /// Current Operation Code + uint8_t operation; + /// Alert Status Char. Value + uint8_t alert_status; + /// Ringer Settings Char. Value + uint8_t ringer_setting; + + /// State of different task instances + ke_state_t state[PASPS_IDX_MAX]; +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve PASP service profile interface + * + * @return PASP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *pasps_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send a PASPS_CMP_EVT message to a requester. + * + * @param[in] src_id Source ID of the message (instance of TASK_PASPS) + * @param[in] dest_id Destination ID of the message + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void pasps_send_cmp_evt(ke_task_id_t src_id, ke_task_id_t dest_id, + uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void pasps_task_init(struct ke_task_desc *p_task_desc); + + +#endif //(BLE_PAS_SERVER) + +/// @} PASPS + +#endif // PASPS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/src/pasps_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/src/pasps_task.c new file mode 100644 index 0000000..05780fa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/pasp/pasps/src/pasps_task.c @@ -0,0 +1,593 @@ +/** + **************************************************************************************** + * + * @file pasps_task.c + * + * @brief Phone Alert Status Profile Server Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $Rev: $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup PASPSTASK + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_PAS_SERVER) +#include "pasp_common.h" + +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "pasps.h" +#include "pasps_task.h" +#include "prf_utils.h" + +#include "co_utils.h" + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref PASPS_ENABLE_REQ message. + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int pasps_enable_req_handler(ke_msg_id_t const msgid, + struct pasps_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct pasps_enable_rsp *p_cmp_evt; + + if (ke_state_get(dest_id) == PASPS_IDLE) + { + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct pasps_env_tag *p_pasps_env = PRF_ENV_GET(PASPS, pasps); + + // Bonded data was not used before + if (!(p_pasps_env->p_env[conidx]->ntf_state & PASPS_FLAG_CFG_PERFORMED_OK)) + { + status = GAP_ERR_NO_ERROR; + if (p_param->alert_status_ntf_cfg != PRF_CLI_STOP_NTFIND) + { + // Force to PRF_CLI_START_NTF + p_param->alert_status_ntf_cfg = PRF_CLI_START_NTF; + + PASPS_ENABLE_NTF(conidx, p_pasps_env, PASPS_FLAG_ALERT_STATUS_CFG); + } + + if (p_param->ringer_setting_ntf_cfg != PRF_CLI_STOP_NTFIND) + { + // Force to PRF_CLI_START_NTF + p_param->ringer_setting_ntf_cfg = PRF_CLI_START_NTF; + + PASPS_ENABLE_NTF(conidx, p_pasps_env, PASPS_FLAG_RINGER_SETTING_CFG); + } + } + // Enable Bonded Data + PASPS_ENABLE_NTF(conidx, p_pasps_env, PASPS_FLAG_CFG_PERFORMED_OK); + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(PASPS_ENABLE_RSP, src_id, dest_id, pasps_enable_rsp); + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref PASPS_UPDATE_CHAR_VAL_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int pasps_update_char_val_cmd_handler(ke_msg_id_t const msgid, + struct pasps_update_char_val_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = PRF_ERR_INVALID_PARAM; + // Message status + int msg_status = KE_MSG_CONSUMED; + + uint8_t state = ke_state_get(dest_id); + + if (state == PASPS_IDLE) + { + // Get the address of the environment + struct pasps_env_tag *p_pasps_env = PRF_ENV_GET(PASPS, pasps); + uint8_t conidx = KE_IDX_GET(dest_id); + // Handle + uint16_t handle = ATT_ERR_INVALID_HANDLE; + // Notification status flag + uint8_t flag = 0; + + ASSERT_ERR(p_pasps_env != NULL); + ASSERT_ERR(p_pasps_env->p_env[conidx] != NULL); + + // Check the connection handle + switch (p_param->operation) + { + // Alert Status Characteristic + case (PASPS_UPD_ALERT_STATUS_OP_CODE): + { + // Check the provided value + if (p_param->value <= PASP_ALERT_STATUS_VAL_MAX) + { + // Set the handle value + handle = p_pasps_env->shdl + PASS_IDX_ALERT_STATUS_VAL; + // Set the flag + flag = PASPS_FLAG_ALERT_STATUS_CFG; + // Update the ringer state value + p_pasps_env->alert_status = p_param->value; + + status = GAP_ERR_NO_ERROR; + } + // else status is PRF_ERR_INVALID_PARAM + } break; + + // Ringer Setting Characteristic + case (PASPS_UPD_RINGER_SETTING_OP_CODE): + { + // Check the provided value + if (p_param->value <= PASP_RINGER_NORMAL) + { + // Set the handle value + handle = p_pasps_env->shdl + PASS_IDX_RINGER_SETTING_VAL; + // Set the flag + flag = PASPS_FLAG_RINGER_SETTING_CFG; + // Update the ringer state value + p_pasps_env->ringer_setting = p_param->value; + + status = GAP_ERR_NO_ERROR; + } + // else status is PRF_ERR_INVALID_PARAM + } break; + + default: + { + // Nothing more to do, status is PRF_ERR_INVALID_PARAM + } break; + } + + if (status == GAP_ERR_NO_ERROR) + { + // Check if sending of notifications is enabled for this connection + if (PASPS_IS_NTF_ENABLED(conidx, p_pasps_env, flag)) + { + struct gattc_send_evt_cmd *p_ntf; + + // Configure the environment for the operation + p_pasps_env->operation = p_param->operation; + // Go to the Busy state + ke_state_set(dest_id, PASPS_BUSY); + + // Allocate the GATT notification message + p_ntf = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), dest_id, + gattc_send_evt_cmd, sizeof(uint8_t)); + + // Fill in the p_parameter structure + p_ntf->operation = GATTC_NOTIFY; + p_ntf->handle = handle; + // pack measured value in database + p_ntf->length = sizeof(uint8_t); + // Fill data + p_ntf->value[0] = p_param->value; + + // The notification can be sent, send the notification + ke_msg_send(p_ntf); + } + else + { + status = PRF_ERR_NTF_DISABLED; + } + } + } + else if (state == PASPS_BUSY) + { + // Save it for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + // no connection + else + { + status = GAP_ERR_DISCONNECTED; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send the message to the application + struct pasps_cmp_evt *p_evt = KE_MSG_ALLOC(PASPS_CMP_EVT, src_id, dest_id, pasps_cmp_evt); + + p_evt->operation = p_param->operation; + p_evt->status = status; + + ke_msg_send(p_evt); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == PASPS_IDLE) + { + // Get the address of the environment + struct pasps_env_tag *p_pasps_env = PRF_ENV_GET(PASPS, pasps); + uint8_t att_idx = p_param->handle - p_pasps_env->shdl; + struct gattc_att_info_cfm *p_cfm; + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + // check if it's a client configuration char + if ((att_idx == PASS_IDX_ALERT_STATUS_CFG) + || (att_idx == PASS_IDX_RINGER_SETTING_CFG)) + { + // CCC attribute length = 2 + p_cfm->length = 2; + p_cfm->status = GAP_ERR_NO_ERROR; + } + else if (att_idx == PASS_IDX_RINGER_CTNL_PT_VAL) + { + // attribute length = 1 + p_cfm->length = 1; + p_cfm->status = GAP_ERR_NO_ERROR; + } + // not expected request + else + { + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } + + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == PASPS_IDLE) + { + // Get the address of the environment + struct pasps_env_tag *p_pasps_env = PRF_ENV_GET(PASPS, pasps); + struct gattc_read_cfm *p_cfm; + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t att_idx = p_param->handle - p_pasps_env->shdl; + + uint8_t value[2]; + uint8_t value_size = 0; + uint8_t status = ATT_ERR_NO_ERROR; + + switch(att_idx) + { + case PASS_IDX_ALERT_STATUS_VAL: + { + // Fill data + value_size = sizeof(uint8_t); + value[0] = p_pasps_env->alert_status; + } break; + + case PASS_IDX_RINGER_SETTING_VAL: + { + // Fill data + value_size = sizeof(uint8_t); + value[0] = p_pasps_env->ringer_setting; + } break; + + case PASS_IDX_ALERT_STATUS_CFG: + { + // Fill data + value_size = sizeof(uint16_t); + co_write16p(value, (p_pasps_env->p_env[conidx]->ntf_state & PASPS_FLAG_ALERT_STATUS_CFG) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } break; + + case PASS_IDX_RINGER_SETTING_CFG: + { + // Fill data + value_size = sizeof(uint16_t); + co_write16p(value, (p_pasps_env->p_env[conidx]->ntf_state & PASPS_FLAG_RINGER_SETTING_CFG) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } break; + + default: + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + // Send data to peer device + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, value_size); + p_cfm->length = value_size; + memcpy(p_cfm->value, value, value_size); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the conidx + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct pasps_env_tag *p_pasps_env = PRF_ENV_GET(PASPS, pasps); + + // Check if the connection exists + if (p_pasps_env->p_env[conidx] != NULL) + { + // Status + uint8_t status = GAP_ERR_NO_ERROR; + struct gattc_write_cfm *p_cfm; + /* + * --------------------------------------------------------------------------------------------- + * Alert Status Client Characteristic Configuration Descriptor Value - Write + * --------------------------------------------------------------------------------------------- + * Ringer Setting Client Characteristic Configuration Descriptor Value - Write + * --------------------------------------------------------------------------------------------- + */ + if ((p_param->handle == (p_pasps_env->shdl + PASS_IDX_ALERT_STATUS_CFG)) || + (p_param->handle == (p_pasps_env->shdl + PASS_IDX_RINGER_SETTING_CFG))) + { + // Received configuration value + uint16_t ntf_cfg = co_read16p(&p_param->value[0]); + + if ((ntf_cfg == PRF_CLI_STOP_NTFIND) || (ntf_cfg == PRF_CLI_START_NTF)) + { + struct pasps_written_char_val_ind *p_ind = KE_MSG_ALLOC(PASPS_WRITTEN_CHAR_VAL_IND, + prf_dst_task_get(&p_pasps_env->prf_env, conidx), + prf_src_task_get(&p_pasps_env->prf_env, conidx), + pasps_written_char_val_ind); + + if (p_param->handle == p_pasps_env->shdl + PASS_IDX_ALERT_STATUS_CFG) + { + p_ind->value.alert_status_ntf_cfg = ntf_cfg; + p_ind->att_code = PASPS_ALERT_STATUS_NTF_CFG; + + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + PASPS_DISABLE_NTF(conidx, p_pasps_env, PASPS_FLAG_ALERT_STATUS_CFG); + } + else + { + PASPS_ENABLE_NTF(conidx, p_pasps_env, PASPS_FLAG_ALERT_STATUS_CFG); + } + } + else + { + p_ind->value.ringer_setting_ntf_cfg = ntf_cfg; + p_ind->att_code = PASPS_RINGER_SETTING_NTF_CFG; + + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + PASPS_DISABLE_NTF(conidx, p_pasps_env, PASPS_FLAG_RINGER_SETTING_CFG); + } + else + { + PASPS_ENABLE_NTF(conidx, p_pasps_env, PASPS_FLAG_RINGER_SETTING_CFG); + } + } + + ke_msg_send(p_ind); + + // Enable Bonded Data + PASPS_ENABLE_NTF(conidx, p_pasps_env, PASPS_FLAG_CFG_PERFORMED_OK); + } + else + { + status = PRF_APP_ERROR; + } + } + /* + * --------------------------------------------------------------------------------------------- + * Ringer Control Point Characteristic Value - Write Without Response + * --------------------------------------------------------------------------------------------- + */ + else if (p_param->handle == (p_pasps_env->shdl + PASS_IDX_RINGER_CTNL_PT_VAL)) + { + // Inform the HL ? + bool inform_hl = false; + + // Check the received value + switch (p_param->value[0]) + { + case (PASP_SILENT_MODE): + { + // Ignore if ringer is already silent + if (p_pasps_env->p_env[conidx]->ringer_state == PASP_RINGER_NORMAL) + { + inform_hl = true; + // Set to Ringer Silent Mode + p_pasps_env->p_env[conidx]->ringer_state = PASP_RINGER_SILENT; + } + } break; + + case (PASP_CANCEL_SILENT_MODE): + { + // Ignore if ringer is not silent + if (p_pasps_env->p_env[conidx]->ringer_state == PASP_RINGER_SILENT) + { + inform_hl = true; + // Set to Ringer Normal Mode + p_pasps_env->p_env[conidx]->ringer_state = PASP_RINGER_NORMAL; + + } + } break; + + case (PASP_MUTE_ONCE): + { + inform_hl = true; + } break; + + // No need to respond with an error (Write Without Response) + default: break; + } + + if (inform_hl) + { + struct pasps_written_char_val_ind *p_ind = KE_MSG_ALLOC(PASPS_WRITTEN_CHAR_VAL_IND, + prf_dst_task_get(&p_pasps_env->prf_env, conidx), + prf_src_task_get(&p_pasps_env->prf_env, conidx), + pasps_written_char_val_ind); + + p_ind->att_code = PASPS_RINGER_CTNL_PT_CHAR_VAL; + p_ind->value.ringer_ctnl_pt = p_param->value[0]; + + ke_msg_send(p_ind); + } + } + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT message meaning that a notification or an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + // Get the address of the environment + struct pasps_env_tag *p_pasps_env = PRF_ENV_GET(PASPS, pasps); + + if (p_pasps_env != NULL) + { + uint8_t conidx = KE_IDX_GET(src_id); + + // Send a complete event status to the application + pasps_send_cmp_evt(prf_src_task_get(&p_pasps_env->prf_env, conidx), + prf_dst_task_get(&p_pasps_env->prf_env, conidx), + p_pasps_env->operation, p_param->status); + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(pasps) +{ + {PASPS_ENABLE_REQ, (ke_msg_func_t) pasps_enable_req_handler}, + {PASPS_UPDATE_CHAR_VAL_CMD, (ke_msg_func_t) pasps_update_char_val_cmd_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +void pasps_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct pasps_env_tag *p_pasps_env = PRF_ENV_GET(PASPS, pasps); + + p_task_desc->msg_handler_tab = pasps_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(pasps_msg_handler_tab); + p_task_desc->state = p_pasps_env->state; + p_task_desc->idx_max = PASPS_IDX_MAX; +} + +#endif //(BLE_PASS_SERVER) + +/// @} PASPSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/api/plxc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/api/plxc_task.h new file mode 100644 index 0000000..c0bf042 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/api/plxc_task.h @@ -0,0 +1,311 @@ +/** + **************************************************************************************** + * + * @file plxc_task.h + * + * @brief Header file - Pulse Oximeter Profile Collector/Client Role Task. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _PLXC_TASK_H_ +#define _PLXC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup PLXCTASK Pulse Oximeter Collector Task + * @ingroup PLXC + * @brief Pulse Oximeter ProfileProfile Collector Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + +#include "plxp_common.h" +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Message IDs +enum plxc_msg_ids +{ + /// Enable the Profile Collector task - at connection + PLXC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_PLXC), + /// Response to Enable the Profile Collector task - at connection + PLXC_ENABLE_RSP, + /// Read Characteristic + PLXC_READ_CMD, + /// Configure Characteristic's CCC descriptor + PLXC_CFG_CCC_CMD, + /// Write Command to the Control Point + PLXC_WRITE_RACP_CMD, + /// Receive the Spot-check Measurement or Measurement Record Indication SPOT_MEAS + /// * Receive Continuous Measurement Notification CONT_MEAS + /// * Receive Control Point Response Indication RACP_RESP + PLXC_VALUE_IND, + /// Read CCC value of specific characteristic + PLXC_RD_CHAR_CCC_IND, + + /// Complete event for the Application commands + PLXC_CMP_EVT, +}; + + +/// Pulse Oximeter Service Characteristics +enum plxc_char_ids +{ + /// PLXP SPOT-Measurement Characteristic + PLXC_CHAR_SPOT_MEASUREMENT = 0, + /// PLXP Continuous Measurement Characteristic + PLXC_CHAR_CONT_MEASUREMENT, + /// PLXP Features Characteristic + PLXC_CHAR_FEATURES, + /// PLXP Record Access Control Point Characteristic + PLXC_CHAR_RACP, + + PLXC_CHAR_MAX, +}; + +/// Pulse Oximeter Service Characteristic Descriptors +enum plxc_desc_ids +{ + /// PLXP SPOT-Measurement Characteristic Client Configuration + PLXC_DESC_SPOT_MEASUREMENT_CCC = 0, + /// PLXP Continuous Measurement Characteristic Client Configuration + PLXC_DESC_CONT_MEASUREMENT_CCC, + /// PLXP Record Access Control Point Characteristic Client Configuration + PLXC_DESC_RACP_CCC, + + PLXC_DESC_MAX, +}; + +/// Define command operation +enum plxc_op_codes +{ + PLXC_NO_OP = 0, + PLXC_SPOT_CHECK_MEAS_CMD_OP_CODE = 1, + PLXC_CONTINUOUS_MEAS_CMD_OP_CODE = 2, + PLXC_RACP_CMD_OP_CODE = 3, + + PLXC_OP_CODE_READ_FEATURES = 4, + PLXC_OP_CODE_READ_CCC = 5, + + PLXC_OP_CODE_WRITE_CCC = 6, + PLXC_OP_CODE_WRITE_RACP = 7, + PLXC_OP_CODE_GATTC_REGISTER = 8, +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Pulse Oximeter Service + */ +struct plxc_plxp_content +{ + /// service info + struct prf_svc svc; + + /// Characteristic info: + /// - Feature + /// - Measurement + struct prf_char_inf chars[PLXC_CHAR_MAX]; + + /// Descriptor handles: + /// - Client cfg + struct prf_char_desc_inf descs[PLXC_DESC_MAX]; +}; + +/// Parameters of the @see PLXC_ENABLE_REQ message +struct plxc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values PLXC + struct plxc_plxp_content plxc; +}; + +/// Parameters of the @see PLXC_ENABLE_RSP message +struct plxc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values PLXC + struct plxc_plxp_content plxc; + /// Supported Features @see common supported_features + uint16_t sup_feat; + /// If enabled in Supported Features @see common measurement_status_supported + uint16_t meas_stat_sup; + /// If enabled in Supported Features @see common device_status_supported + uint32_t dev_stat_sup; +}; + +///*** PLXC CHARACTERISTIC READ REQUESTS +/// Parameters of the @see PLXC_READ_CMD message +/// operation +struct plxc_read_cmd +{ + /// Operation - select characteristic @see enum plxc_op_codes + uint8_t operation; +}; + +struct plxc_read_cmd_value +{ + /// Supported Features @see common supported_features + uint16_t sup_feat; + /// If enabled in Supported Features @see common measurement_status_supported + uint16_t meas_stat_sup; + /// If enabled in Supported Features @see common device_status_supported + uint32_t dev_stat_sup; +}; + +///*** PLXC CHARACTERISTIC/CCC DESCRIPTOR WRITE REQUESTS +/// Parameters of the @see PLXC_CFG_CCC_CMD message +/// operation +struct plxc_cfg_ccc_cmd +{ + /// operation = char_opcode - select characteristic @see enum plxc_op_codes + uint8_t operation; + /// The Client Characteristic Configuration Value + uint16_t ccc; +}; + +/// Write Operation Command to the Control Point forward to Application +/// Parameters of the @see PLXC_WRITE_RACP_CMD, +struct plxc_write_racp_cmd +{ + /// Operation = PLXC_RASP_CMD_OP_CODE @see enum plxc_op_codes + uint8_t operation; + /// Control Point OpCode @see enum plxp_cp_opcodes_id + uint8_t cp_opcode; + /// Operator @see enum plxp_cp_operator_id + uint8_t cp_operator; +}; + +/// Receive the Spot-check Measurement or Measurement Record Indication SPOT_MEAS +/// * Receive Continuous Measurement Notification CONT_MEAS +/// * Receive Control Point Response Indication RACP_RESP +/// PLXC_VALUE_IND, +/// Indication Record Access Control Point Response +struct plxc_racp_resp +{ + /// Control Point OpCode @see enum plxp_cp_opcodes_id + uint8_t cp_opcode; + /// Request Control Point OpCode @see enum plxp_cp_opcodes_id + uint8_t req_cp_opcode; + /// Control Point Operator @see enum plxp_cp_operator_id + uint8_t cp_operator; + /// Response Code @see enum plxp_cp_resp_code_id + uint8_t rsp_code; + /// Number of Records + uint16_t rec_num; +}; + +/// PLX Spot-Check Measurement Value +struct plxc_spot_meas_value +{ + /// bitfield of supplied data @see common plxp_spot_meas_flag + uint8_t spot_flags; + /// Percentage with a resolution of 1 + uint16_t sp_o2; + /// Period (beats per minute) with a resolution of 1 + uint16_t pr; + /// Timestamp (if present) + struct prf_date_time timestamp; + /// Measurement Status (bitfield) @see common measurement_status_supported + uint16_t meas_stat; + /// Device and Sensor Status (bitfield) @see common device_status_supported + uint32_t dev_sensor_stat; + /// Pulse Amplitude Index - Unit is percentage with a resolution of 1 + uint16_t pulse_ampl; +}; + +/// SpO2 - PR measurements +struct plxc_spo2pr_value +{ + /// Percentage with a resolution of 1 + uint16_t sp_o2; + /// Period (beats per minute) with a resolution of 1 + uint16_t pr; +}; + +/// PLX Continuous Measurement Value +struct plxc_cont_meas_value +{ + /// bitfield of supplied data @see common plxp_cont_meas_flag + uint8_t cont_flags; + /// SpO2 - PR measurements - Normal + struct plxc_spo2pr_value normal; + /// SpO2 - PR measurements - Fast + struct plxc_spo2pr_value fast; + /// SpO2 - PR measurements - Slow + struct plxc_spo2pr_value slow; + /// Measurement Status (bitfield) @see common measurement_status_supported + uint16_t meas_stat; + /// Device and Sensor Status (bitfield) @see common device_status_supported + uint32_t dev_sensor_stat; + /// Pulse Amplitude Index - Unit is percentage with a resolution of 1 + uint16_t pulse_ampl; +}; + +/// Indication the Record Access Control Point response +/// Indication the Spot-check Measurement or Measurement Record +/// Indication Continuous Measurement +/// Parameters of the @see PLXC_VALUE_IND, +struct plxc_value_ind +{ + /// Operation @see enum plxc_op_codes + uint8_t operation; + union plxc_meas_value_tag + { + /// Spot-Check Measurement + struct plxc_spot_meas_value spot_meas; + /// Continuous Measurement + struct plxc_cont_meas_value cont_meas; + /// Record Access Control Point response + struct plxc_racp_resp racp_resp; + /// Read Features request command value + struct plxc_read_cmd_value features; + } value; +}; + +/// Inform Application about the Characteristic's CCC descriptor +/// Parameters of the @see PLXC_RD_CHAR_CCC_IND, +struct plxc_rd_char_ccc_ind +{ + /// Char. Client Characteristic Configuration + uint16_t ind_cfg; +}; + +/// Complete event for the Application commands +/// PLXC_CMP_EVT, +/// Parameters of the @see PLXC_CMP_EVT message +/// Complete Event Information +struct plxc_cmp_evt +{ + /// Operation @see enum plxc_op_codes + uint8_t operation; + /// Status + uint8_t status; +}; + + +/// @} PLXCTASK + +#endif //(_PLXC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/sourcelist.txt new file mode 100644 index 0000000..ed486f3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2017 +# +#*************************************************************************************** + + plxc.c + plxc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/src/plxc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/src/plxc.c new file mode 100644 index 0000000..88b6e49 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/src/plxc.c @@ -0,0 +1,248 @@ +/** + **************************************************************************************** + * + * @file plxc.c + * + * @brief Pulse Oximeter Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup PLXC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_PLX_CLIENT) +#include "prf.h" +#include "plxp_common.h" + +#include "plxc_task.h" +#include "plxc.h" +#include "gap.h" + +#include "ke_mem.h" + +/* + * GLOBAL VARIABLES DECLARATION + **************************************************************************************** + */ + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the PLXC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t plxc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, + uint16_t app_task, uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct plxc_env_tag *p_plxc_env = + (struct plxc_env_tag *) ke_malloc(sizeof(struct plxc_env_tag), KE_MEM_ATT_DB); + + // allocate PLXC required environment variable + p_env->env = (prf_env_t *) p_plxc_env; + + p_plxc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_plxc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_PLXC; + + plxc_task_init(&(p_env->desc)); + + for (idx = 0; idx < PLXC_IDX_MAX ; idx++) + { + p_plxc_env->p_env[idx] = NULL; + + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), PLXC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void plxc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct plxc_env_tag *p_plxc_env = (struct plxc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_plxc_env->p_env[conidx] != NULL) + { + ke_free(p_plxc_env->p_env[conidx]); + p_plxc_env->p_env[conidx] = NULL; + } + + // Put PLXP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), PLXC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the PLXC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void plxc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct plxc_env_tag* p_plxc_env = (struct plxc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < PLXC_IDX_MAX ; idx++) + { + plxc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_plxc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void plxc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put WSC Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), PLXC_IDLE); +} + +/// PLXC Task interface required by profile manager +const struct prf_task_cbs plxc_itf = +{ + plxc_init, + plxc_destroy, + plxc_create, + plxc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *plxc_prf_itf_get(void) +{ + return &plxc_itf; +} + +void plxc_enable_rsp_send(struct plxc_env_tag *p_plxc_env, uint8_t conidx, uint8_t status, + uint16_t sup_feat, uint16_t meas_stat_sup, uint32_t dev_stat_sup) +{ + // Send to APP the details of the discovered attributes on WSCP + struct plxc_enable_rsp *p_rsp = KE_MSG_ALLOC( + PLXC_ENABLE_RSP, + prf_dst_task_get(&(p_plxc_env->prf_env), conidx), + prf_src_task_get(&(p_plxc_env->prf_env), conidx), + plxc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + // Provide all Discovered Characteristics and Descriptors + p_rsp->plxc = p_plxc_env->p_env[conidx]->plxc; + // Supported Features + p_rsp->sup_feat = sup_feat; + // If enabled in Supported Features + p_rsp->meas_stat_sup = meas_stat_sup; + // If enabled in Supported Features + p_rsp->dev_stat_sup = dev_stat_sup; + + // Register PLXC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_plxc_env->prf_env), conidx, &(p_plxc_env->p_env[conidx]->plxc.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_plxc_env->prf_env), conidx), PLXC_IDLE); + } + else + { + memset(&p_rsp->plxc, 0 , sizeof(p_rsp->plxc)); + // Provide all Discovered Characteristics and Descriptors + p_rsp->plxc = p_plxc_env->p_env[conidx]->plxc; + // Enabled failed - so go back to the FREE state + ke_state_set(prf_src_task_get(&(p_plxc_env->prf_env), conidx), PLXC_FREE); + } + + ke_msg_send(p_rsp); +} + +void plxc_send_cmp_evt(struct plxc_env_tag *p_plxc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct plxc_cmp_evt *p_evt; + + // Go back to the CONNECTED state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_plxc_env->prf_env), conidx)) == PLXC_BUSY) + { + ke_state_set(prf_src_task_get(&(p_plxc_env->prf_env), conidx), PLXC_IDLE); + } + + // Send the message + p_evt = KE_MSG_ALLOC(PLXC_CMP_EVT, + prf_dst_task_get(&(p_plxc_env->prf_env), conidx), + prf_src_task_get(&(p_plxc_env->prf_env), conidx), + plxc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //(BLE_PLX_CLIENT) + +/// @} PLXC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/src/plxc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/src/plxc.h new file mode 100644 index 0000000..c54d7f1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/src/plxc.h @@ -0,0 +1,189 @@ +/** + **************************************************************************************** + * + * @file plxc.h + * + * @brief Header file - Pulse Oximeter Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _PLXC_H_ +#define _PLXC_H_ + +/** + **************************************************************************************** + * @addtogroup PLXC Pulse Oximeter Profile Collector + * @ingroup WSCP + * @brief Pulse Oximeter Profile Collector + * @{ + **************************************************************************************** + */ + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Pulse Oximeter Task instances +#define PLXC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "plxp_common.h" + +#if (BLE_PLX_CLIENT) + +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +//#define CCC_READY + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Possible states of the PLXC task +enum plxc_states +{ + /// Idle state + PLXC_FREE, + /// Connected state + PLXC_IDLE, + /// Discovering Services + PLXC_DISCOVERING_SVC, + /// Busy state + PLXC_BUSY, + /// Number of defined states. + PLXC_STATE_MAX +}; + +/// Operation Codes for pending operations in the client. +enum plxc_op_pending +{ + /// Reserved operation code + PLXC_OP_PENDING_NO_OP = 0x00, + + // Read op-codes + /// internal state when reading features after discovery + PLXC_OP_PENDING_READ_FEATURES_AT_INIT, + /// read FEATURES as the result of the command request + PLXC_OP_PENDING_READ_FEATURES, + /// Read CCC + PLXC_OP_PENDING_READ_CCC, + + // Write op-codes + /// Write Record Access Control Point + PLXC_OP_PENDING_WRITE_RACP, + /// Write Client Characteristic Configuration + PLXC_OP_PENDING_WRITE_CCC, + +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Stored Environment content/context information for a connection +struct plxc_cnx_env +{ + /// Current Operation + uint8_t op_pending; + + /// Counter used to check service uniqueness + uint8_t nb_svc; + + /// Pulse Oximeter Service Characteristics + struct plxc_plxp_content plxc; +}; + +/// Pulse Oximeter environment variable +struct plxc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct plxc_cnx_env *p_env[PLXC_IDX_MAX]; + /// State of different task instances + ke_state_t state[PLXC_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Pool of Pulse Oximeter Collector task environments. +extern struct plxc_env_tag **plxc_envs; + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve PLXP client profile interface + * + * @return PLXP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* plxc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Sends a PLXC_ENABLE_RSP message. + * + * @param[in] p_plxc_env The profile environment for the connection + * @param[in] conidx Connection Identifier + * @param[in] status Indicates the outcome of the operation + * @param[in] sup_feat Supported Feature @see supported_features + * @param[in] meas_stat_sup Measurement Status Supported @see measurement_status_supported + * @param[in] dev_stat_sup Device Status Supported @see device_status_supported + **************************************************************************************** + */ +void plxc_enable_rsp_send(struct plxc_env_tag *p_plxc_env, uint8_t conidx, uint8_t status, + uint16_t sup_feat, uint16_t meas_stat_sup, uint32_t dev_stat_sup); + +/** + **************************************************************************************** + * @brief Sends a Complete_Event to the App + * + * @param[in] p_plxc_env The profile environment + * @param[in] conidx Connection Identifier + * @param[in] operation Indicates the operation for which the cmp_evt is being sent. + * @param[in] status Indicates the outcome of the operation + **************************************************************************************** + */ +void plxc_send_cmp_evt(struct plxc_env_tag *p_plxc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void plxc_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_PLXP_CLIENT) + +/// @} PLXC + +#endif //(_PLXC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/src/plxc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/src/plxc_task.c new file mode 100644 index 0000000..f848d01 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxc/src/plxc_task.c @@ -0,0 +1,1075 @@ +/** + **************************************************************************************** + * + * @file plxc_task.c + * + * @brief Pulse Oximeter Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup PLXCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_PLX_CLIENT) +#include "plxp_common.h" +#include "plxc_task.h" +#include "plxc.h" + +#include "gap.h" +#include "attm.h" +#include "gattc_task.h" +#include "ke_mem.h" +#include "co_utils.h" + + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve Pulse Oximeter Service characteristics information +const struct prf_char_def plxc_plx_char[PLXC_CHAR_MAX] = +{ + [PLXC_CHAR_SPOT_MEASUREMENT] = {ATT_CHAR_PLX_SPOT_CHECK_MEASUREMENT_LOC, + ATT_OPTIONAL, + (ATT_CHAR_PROP_IND) }, + + [PLXC_CHAR_CONT_MEASUREMENT] = {ATT_CHAR_PLX_CONTINUOUS_MEASUREMENT_LOC, + ATT_OPTIONAL, + (ATT_CHAR_PROP_NTF) }, + + [PLXC_CHAR_FEATURES] = {ATT_CHAR_PLX_FEATURES_LOC, + ATT_MANDATORY, + (ATT_CHAR_PROP_RD) }, + + [PLXC_CHAR_RACP] = {ATT_CHAR_REC_ACCESS_CTRL_PT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_WR | ATT_CHAR_PROP_IND) }, +}; + + +/// State machine used to retrieve Pulse Oximeter Service characteristic Description information +const struct prf_char_desc_def plxc_plx_char_desc[PLXC_DESC_MAX] = +{ + /// Client config + [PLXC_DESC_SPOT_MEASUREMENT_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_OPTIONAL, + PLXC_CHAR_SPOT_MEASUREMENT}, + /// Client config + [PLXC_DESC_CONT_MEASUREMENT_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_OPTIONAL, + PLXC_CHAR_CONT_MEASUREMENT}, + /// Client config + [PLXC_DESC_RACP_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_OPTIONAL, + PLXC_CHAR_RACP}, +}; + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @see GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == PLXC_DISCOVERING_SVC) + { + // Pulse Oximeter Collector Role Task Environment + struct plxc_env_tag *p_plxc_env = PRF_ENV_GET(PLXC, plxc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_plxc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_plxc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_PULSE_OXIMETER)) + { + // Retrieve PLX characteristics and descriptors + prf_extract_svc_info(p_ind, PLXC_CHAR_MAX, &plxc_plx_char[0], &p_plxc_env->p_env[conidx]->plxc.chars[0], + PLXC_DESC_MAX, &plxc_plx_char_desc[0], &p_plxc_env->p_env[conidx]->plxc.descs[0]); + + // Even if we get multiple responses we only store 1 range + p_plxc_env->p_env[conidx]->plxc.svc.shdl = p_ind->start_hdl; + p_plxc_env->p_env[conidx]->plxc.svc.ehdl = p_ind->end_hdl; + + p_plxc_env->p_env[conidx]->nb_svc++; + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see PLXC_ENABLE_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +static int plxc_enable_req_handler(ke_msg_id_t const msgid, + struct plxc_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + // Pulse Oximeter Collector Role Task Environment + struct plxc_env_tag *p_plxc_env = PRF_ENV_GET(PLXC, plxc); + + ASSERT_INFO(p_plxc_env != NULL, dest_id, src_id); + + if ((state == PLXC_IDLE) && (p_plxc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_plxc_env->p_env[conidx] = (struct plxc_cnx_env*) ke_malloc(sizeof(struct plxc_cnx_env),KE_MEM_ATT_DB); + memset(p_plxc_env->p_env[conidx], 0, sizeof(struct plxc_cnx_env)); + + // Start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + // Start discovery with Pulse Oximeter + prf_disc_svc_send(&(p_plxc_env->prf_env), conidx, ATT_SVC_PULSE_OXIMETER); + + // Go to DISCOVERING SERVICE state + ke_state_set(dest_id, PLXC_DISCOVERING_SVC); + } + // normal connection, get saved att details + else + { + uint16_t search_hdl; + struct prf_svc *p_svc; + + p_plxc_env->p_env[conidx]->plxc = p_param->plxc; + // Attribute Handle + search_hdl = p_plxc_env->p_env[conidx]->plxc.chars[PLXC_CHAR_FEATURES].val_hdl; + // Service + p_svc = &p_plxc_env->p_env[conidx]->plxc.svc; + + // Check if handle is viable + if ((search_hdl != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_plxc_env->p_env[conidx]->op_pending = PLXC_OP_PENDING_READ_FEATURES_AT_INIT; + + // Send the write request + prf_read_char_send(&(p_plxc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, PLXC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + } + } + else if (state != PLXC_FREE) + { + // The message will be forwarded towards the good task instance + status = PRF_ERR_REQ_DISALLOWED; + } + + if (status != GAP_ERR_NO_ERROR) + { + // The request is disallowed (profile already enabled for this connection, or not enough memory, ...) + plxc_enable_rsp_send(p_plxc_env, conidx, status, 0, 0, 0); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see PLXC_READ_CMD message from the application. + * @brief To read the Feature Characteristic in the peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +static int plxc_read_cmd_handler(ke_msg_id_t const msgid, + struct plxc_read_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct plxc_env_tag *p_plxc_env = PRF_ENV_GET(PLXC, plxc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == PLXC_IDLE) + { + ASSERT_INFO(p_plxc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_plxc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = ATT_INVALID_SEARCH_HANDLE; + // Service + struct prf_svc *p_svc = &p_plxc_env->p_env[conidx]->plxc.svc; + + if (p_param->operation == PLXC_OP_CODE_READ_FEATURES) + { + search_hdl = p_plxc_env->p_env[conidx]->plxc.chars[PLXC_CHAR_FEATURES].val_hdl; + // Force the operation value + p_plxc_env->p_env[conidx]->op_pending = PLXC_OP_PENDING_READ_FEATURES; + } + else + { + if (p_param->operation == PLXC_SPOT_CHECK_MEAS_CMD_OP_CODE) + { + search_hdl = p_plxc_env->p_env[conidx]->plxc.descs[PLXC_DESC_SPOT_MEASUREMENT_CCC].desc_hdl; + } + else if (p_param->operation == PLXC_CONTINUOUS_MEAS_CMD_OP_CODE) + { + search_hdl = p_plxc_env->p_env[conidx]->plxc.descs[PLXC_DESC_CONT_MEASUREMENT_CCC].desc_hdl; + } + else if (p_param->operation == PLXC_RACP_CMD_OP_CODE) + { + search_hdl = p_plxc_env->p_env[conidx]->plxc.descs[PLXC_DESC_RACP_CCC].desc_hdl; + } + + // Force the operation value + p_plxc_env->p_env[conidx]->op_pending = PLXC_OP_PENDING_READ_CCC; + } + + // Check if handle is viable + if ((p_svc != NULL) && (search_hdl != ATT_INVALID_SEARCH_HANDLE)) + { + // Send the read request + prf_read_char_send(&(p_plxc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, PLXC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == PLXC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + plxc_send_cmp_evt(p_plxc_env, conidx, p_param->operation, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see PLXC_WRITE_RACP_CMD message from the application. + * @brief To write command to the Records Access Control Point in the peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +static int plxc_write_racp_cmd_handler(ke_msg_id_t const msgid, + struct plxc_write_racp_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct plxc_env_tag *p_plxc_env = PRF_ENV_GET(PLXC, plxc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == PLXC_IDLE) + { + ASSERT_INFO(p_plxc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_plxc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = p_plxc_env->p_env[conidx]->plxc.chars[PLXC_CHAR_RACP].val_hdl; + // Service + struct prf_svc *p_svc = &p_plxc_env->p_env[conidx]->plxc.svc; + // Length + uint8_t data[2]; + + // fill parameters + data[0] = p_param->cp_opcode; + data[1] = p_param->cp_operator; + + // Check if handle is viable + if ((search_hdl != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_plxc_env->p_env[conidx]->op_pending = PLXC_OP_PENDING_WRITE_RACP; + + // Send the write request + prf_gatt_write(&(p_plxc_env->prf_env), conidx, search_hdl, &data[0], 2, GATTC_WRITE); + // Go to the Busy state + ke_state_set(dest_id, PLXC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == PLXC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + plxc_send_cmp_evt(p_plxc_env, conidx, PLXC_OP_CODE_WRITE_RACP, status); + } + + return msg_status; +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @see PLXC_CFG_CCC_CMD message. + * Allows the application to write new CCC values to a Alert Characteristic in the peer server + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int plxc_cfg_ccc_cmd_handler(ke_msg_id_t const msgid, + struct plxc_cfg_ccc_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct plxc_env_tag *p_plxc_env = PRF_ENV_GET(PLXC, plxc); + + if (state == PLXC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_plxc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_plxc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t handle = 0; + + if (p_param->operation == PLXC_SPOT_CHECK_MEAS_CMD_OP_CODE) + { + handle = p_plxc_env->p_env[conidx]->plxc.descs[PLXC_DESC_SPOT_MEASUREMENT_CCC].desc_hdl; + } + else if (p_param->operation == PLXC_CONTINUOUS_MEAS_CMD_OP_CODE) + { + handle = p_plxc_env->p_env[conidx]->plxc.descs[PLXC_DESC_CONT_MEASUREMENT_CCC].desc_hdl; + } + else if (p_param->operation == PLXC_RACP_CMD_OP_CODE) + { + handle = p_plxc_env->p_env[conidx]->plxc.descs[PLXC_DESC_RACP_CCC].desc_hdl; + } + + // Check if handle is viable and service not NULL + if ((handle != ATT_INVALID_SEARCH_HANDLE) && (&p_plxc_env->p_env[conidx]->plxc.svc != NULL)) + { + // Force the operation value + p_plxc_env->p_env[conidx]->op_pending = PLXC_OP_PENDING_WRITE_CCC; + + // Send the write request + prf_gatt_write_ntf_ind(&(p_plxc_env->prf_env), conidx, handle, p_param->ccc); + + // Go to the Busy state + ke_state_set(dest_id, PLXC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + plxc_send_cmp_evt(p_plxc_env, conidx, PLXC_OP_CODE_WRITE_CCC, status); + } + } + else if (state == PLXC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see GATTC_CMP_EVT message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct plxc_env_tag *p_plxc_env = PRF_ENV_GET(PLXC, plxc); + // Status + uint8_t status = PRF_APP_ERROR; + + do + { + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (p_plxc_env == NULL) + { + break; + } + + if (state == PLXC_DISCOVERING_SVC) + { + // clean state for the new discovering + p_plxc_env->p_env[conidx]->op_pending = PLXC_OP_PENDING_NO_OP; + + if ((p_param->status == GAP_ERR_NO_ERROR) || (p_param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)) + { + // Check service (if found) + if (p_plxc_env->p_env[conidx]->nb_svc) + { + // Check service (mandatory) + status = prf_check_svc_char_validity(PLXC_CHAR_MAX, + p_plxc_env->p_env[conidx]->plxc.chars, + plxc_plx_char); + + // Check Descriptors (mandatory) + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(PLXC_DESC_MAX, + p_plxc_env->p_env[conidx]->plxc.descs, + plxc_plx_char_desc, + p_plxc_env->p_env[conidx]->plxc.chars); + } + } + } + + // request read FEATURES + if (status == GAP_ERR_NO_ERROR) + { + // Attribute Handle + uint16_t search_hdl = p_plxc_env->p_env[conidx]->plxc.chars[PLXC_CHAR_FEATURES].val_hdl; + // Service + struct prf_svc *p_svc = &p_plxc_env->p_env[conidx]->plxc.svc; + + // Check if handle is viable + if ((search_hdl != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_plxc_env->p_env[conidx]->op_pending = PLXC_OP_PENDING_READ_FEATURES_AT_INIT; + + // Send the read request + prf_read_char_send(&(p_plxc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, PLXC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + } + + // at this stage we send response only if it fail in some case + if (status != GAP_ERR_NO_ERROR) + { + // Raise an PLXC_ENABLE_REQ complete event. + ke_state_set(dest_id, PLXC_IDLE); + + plxc_enable_rsp_send(p_plxc_env, conidx, p_param->status, 0 ,0 ,0); + } + } + else if (state == PLXC_BUSY) + { + uint8_t op_pending = p_plxc_env->p_env[conidx]->op_pending; + + status = p_param->status; + switch (p_param->operation) + { + case GATTC_READ: + { + // Send the complete event status + switch (op_pending) + { + case PLXC_OP_PENDING_READ_FEATURES_AT_INIT: + { + // Raise an PLXC_ENABLE_REQ complete event. + plxc_enable_rsp_send(p_plxc_env, conidx, status, 0 ,0 ,0); + } break; + + case PLXC_OP_PENDING_READ_FEATURES: + { + // Send read complete event. + plxc_send_cmp_evt(p_plxc_env, conidx, PLXC_OP_CODE_READ_FEATURES, status); + } break; + + case PLXC_OP_PENDING_READ_CCC: + { + // Send read complete event. + plxc_send_cmp_evt(p_plxc_env, conidx, PLXC_OP_CODE_READ_CCC, status); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + ke_state_set(dest_id, PLXC_IDLE); + } break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + // Send the complete event status + plxc_send_cmp_evt(p_plxc_env, conidx, + (op_pending == PLXC_OP_PENDING_WRITE_RACP ? + PLXC_OP_CODE_WRITE_RACP : PLXC_OP_CODE_WRITE_CCC), + p_param->status); + + ke_state_set(dest_id, PLXC_IDLE); + + } break; + + case GATTC_REGISTER: + { + if (status != GAP_ERR_NO_ERROR) + { + // Send the complete event error status + plxc_send_cmp_evt(p_plxc_env, conidx, PLXC_OP_CODE_GATTC_REGISTER, p_param->status); + } + // Go to connected state + ke_state_set(dest_id, PLXC_IDLE); + } break; + + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + p_plxc_env->p_env[conidx]->op_pending = PLXC_OP_PENDING_NO_OP; + } + + } while (0); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + do + { + // Get the address of the environment + struct plxc_env_tag *p_plxc_env = PRF_ENV_GET(PLXC, plxc); + uint8_t conidx = KE_IDX_GET(dest_id); + + uint8_t op_pending; + uint8_t status = GAP_ERR_NO_ERROR; + // length of data block + uint16_t length; + + // Supported Features @see common supported_features + uint16_t sup_feat = 0; + // If enabled in Supported Features @see common measurement_status_supported + uint16_t meas_stat_sup = 0; + // If enabled in Supported Features @see common device_status_supported + uint32_t dev_stat_sup = 0; + // data pointer + uint8_t const *p_data; + + // Flag to check if we need to return IDLE state + uint8_t to_idle = 0; + + ASSERT_INFO(p_plxc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_plxc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (ke_state_get(dest_id) != PLXC_BUSY) + { + break; + } + + // Find the op_pending - and check it is a valid read code. + op_pending = p_plxc_env->p_env[conidx]->op_pending; + + length = p_param->length; + + // At least Supported Features is present + ASSERT_INFO(length >= 2, dest_id, src_id); + + if ((op_pending == PLXC_OP_PENDING_READ_FEATURES_AT_INIT) || + (op_pending == PLXC_OP_PENDING_READ_FEATURES)) + { + sup_feat = co_read16p(&p_param->value[0]); + p_data = &p_param->value[2]; + + length -= 2; // uint16 supported_features; + if (GETB(sup_feat, PLXP_FEAT_MEAS_STATUS_SUP) && (length >= 2)) + { + meas_stat_sup = co_read16p(p_data); + p_data += 2; // uint16 measurement_status_supported; + length -= 2; + } + + if (GETB(sup_feat, PLXP_FEAT_DEV_SENSOR_STATUS_SUP) && (length >= 3)) + { + dev_stat_sup = co_read24p(p_data); + } + } + + switch (op_pending) + { + case PLXC_OP_PENDING_READ_FEATURES_AT_INIT: + { + // Raise an PLXC_ENABLE_REQ complete event. + plxc_enable_rsp_send(p_plxc_env, conidx, status, + sup_feat, + meas_stat_sup, + dev_stat_sup); + + to_idle = 1; + } break; + + case PLXC_OP_PENDING_READ_FEATURES: + { + // Send value ind and next complete event. + // indication Build a PLXC_VALUE_IND message + struct plxc_value_ind *p_ind = KE_MSG_ALLOC(PLXC_VALUE_IND, + prf_dst_task_get(&p_plxc_env->prf_env, conidx), + prf_src_task_get(&p_plxc_env->prf_env, conidx), + plxc_value_ind); + + p_ind->operation = PLXC_OP_CODE_READ_FEATURES; + p_ind->value.features.sup_feat = sup_feat; + p_ind->value.features.meas_stat_sup = meas_stat_sup; + p_ind->value.features.dev_stat_sup = dev_stat_sup; + + // send indication to the application + ke_msg_send(p_ind); + + to_idle = 1; + + plxc_send_cmp_evt(p_plxc_env, conidx, PLXC_OP_CODE_READ_FEATURES, status); + } break; + + case PLXC_OP_PENDING_READ_CCC: + { + struct plxc_rd_char_ccc_ind *p_ind = KE_MSG_ALLOC(PLXC_RD_CHAR_CCC_IND, + prf_dst_task_get(&(p_plxc_env->prf_env), conidx), + dest_id, + plxc_rd_char_ccc_ind); + + p_ind->ind_cfg = co_read16p(&p_param->value[0]); + + ke_msg_send(p_ind); + + // Keep the Busy state to be treated in gattc_cmp_evt_handler + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + // return to IDLE state + if (to_idle) + { + p_plxc_env->p_env[conidx]->op_pending = PLXC_OP_PENDING_NO_OP; + ke_state_set(dest_id, PLXC_IDLE); + } + + } while (0); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + do + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct plxc_env_tag *p_plxc_env = PRF_ENV_GET(PLXC, plxc); + // data pointer + const uint8_t *p_data; + // length of data block + uint16_t length; + //indication Build a PLXC_VALUE_IND message + struct plxc_value_ind *p_ind; + struct gattc_event_cfm *p_cfm; + + if (p_plxc_env == NULL) + { + break; + } + + if ((p_param->type != GATTC_INDICATE) && (p_param->type != GATTC_NOTIFY)) + { + break; + } + + p_ind = KE_MSG_ALLOC(PLXC_VALUE_IND, + prf_dst_task_get(&p_plxc_env->prf_env, conidx), + prf_src_task_get(&p_plxc_env->prf_env, conidx), + plxc_value_ind); + + memset(p_ind, 0, sizeof(struct plxc_value_ind)); + + if (p_param->handle == p_plxc_env->p_env[conidx]->plxc.chars[PLXC_CHAR_SPOT_MEASUREMENT].val_hdl) + { + uint8_t spot_flags = p_param->value[0]; + + length = p_param->length; + p_data = &p_param->value[5]; + + p_ind->operation = PLXC_SPOT_CHECK_MEAS_CMD_OP_CODE; + // decode message + if (length >= 5) + { + // uint8_t bitfield of supplied data @see common plxp_spot_meas_flag + p_ind->value.spot_meas.spot_flags = spot_flags; + // uint16_t Percentage with a resolution of 1 + p_ind->value.spot_meas.sp_o2 = co_read16p(&p_param->value[1]); + // uint16_t Period (beats per minute) with a resolution of 1 + p_ind->value.spot_meas.pr = co_read16p(&p_param->value[3]); + + length -= 5; + } + else + { + //no further parameters possible + length = 0; + } + + // Timestamp (if present) + if (GETB(spot_flags, PLXP_SPOT_MEAS_FLAGS_TIMESTAMP)) + { + if (length >= 7) + { + p_data += prf_unpack_date_time((uint8_t *)p_data, + (struct prf_date_time *)&p_ind->value.spot_meas.timestamp); + + length -= 7; + } + else + { + //no further parameters possible + length = 0; + } + } + + // Measurement Status (bitfield) @see common measurement_status_supported + if (GETB(spot_flags, PLXP_SPOT_MEAS_FLAGS_MEAS_STATUS) && (length >= 2)) + { + p_ind->value.spot_meas.meas_stat = co_read16p(p_data); + p_data += 2; + length -= 2; + } + + // Device and Sensor Status (bitfield) @see common device_status_supported + if (GETB(spot_flags, PLXP_SPOT_MEAS_FLAGS_DEV_SENSOR_STATUS) && (length >= 2)) + { + p_ind->value.spot_meas.dev_sensor_stat = co_read24p(p_data); + p_data += 3; + length -= 3; + } + + // Pulse Amplitude Index - Unit is percentage with a resolution of 1 + if (GETB(spot_flags, PLXP_SPOT_MEAS_FLAGS_PULSE_AMPLITUDE) && (length >= 2)) + { + p_ind->value.spot_meas.pulse_ampl = co_read16p(p_data); + p_data += 2; + length -= 2; + } + } + else if (p_param->handle == p_plxc_env->p_env[conidx]->plxc.chars[PLXC_CHAR_CONT_MEASUREMENT].val_hdl) + { + uint8_t cont_flags = p_param->value[0]; + + length = p_param->length; + p_data = &p_param->value[5]; + + p_ind->operation = PLXC_CONTINUOUS_MEAS_CMD_OP_CODE; + + // decode message + if (length >= 5) + { + // bitfield of supplied data @see common plxp_cont_meas_flag + p_ind->value.cont_meas.cont_flags = cont_flags; + // SpO2 - PR measurements - Normal + p_ind->value.cont_meas.normal.sp_o2 = co_read16p(&p_param->value[1]); + p_ind->value.cont_meas.normal.pr = co_read16p(&p_param->value[3]); + length -= 5; + } + else + { + //no further parameters possible + length = 0; + } + + // SpO2 - PR measurements - Fast + if (GETB(cont_flags, PLXP_CONT_MEAS_FLAGS_SPO2PR_FAST)) + { + if (length >=4) + { + p_ind->value.cont_meas.fast.sp_o2 = co_read16p(p_data); + p_data += 2; + p_ind->value.cont_meas.fast.pr = co_read16p(p_data); + p_data += 2; + length -= 4; + } + else + { + //no further parameters possible + length = 0; + } + } + // SpO2 - PR measurements - Slow + if (GETB(cont_flags, PLXP_CONT_MEAS_FLAGS_SPO2PR_SLOW)) + { + if (length >= 4) + { + p_ind->value.cont_meas.slow.sp_o2 = co_read16p(p_data); + p_data += 2; + p_ind->value.cont_meas.slow.pr = co_read16p(p_data); + p_data += 2; + length -= 4; + } + else + { + //no further parameters possible + length = 0; + } + } + // Measurement Status (bitfield) @see common measurement_status_supported + if (GETB(cont_flags, PLXP_CONT_MEAS_FLAGS_MEAS_STATUS) && (length >= 2)) + { + p_ind->value.cont_meas.meas_stat = co_read16p(p_data); + p_data += 2; + length -= 2; + } + // Device and Sensor Status (bitfield) @see common device_status_supported + if (GETB(cont_flags, PLXP_CONT_MEAS_FLAGS_DEV_SENSOR_STATUS) && (length >= 2)) + { + p_ind->value.cont_meas.dev_sensor_stat = co_read24p(p_data); + p_data += 3; + length -= 3; + } + // Pulse Amplitude Index - Unit is percentage with a resolution of 1 + if (GETB(cont_flags, PLXP_CONT_MEAS_FLAGS_PULSE_AMPL) && (length >= 2)) + { + p_ind->value.cont_meas.pulse_ampl = co_read16p(p_data); + } + } + else if (p_param->handle == p_plxc_env->p_env[conidx]->plxc.chars[PLXC_CHAR_RACP].val_hdl) + { + // Control Point OpCode @see enum plxp_cp_opcodes_id + uint8_t cp_opcode = p_param->value[0]; + + p_ind->operation = PLXC_RACP_CMD_OP_CODE; + p_ind->value.racp_resp.cp_opcode = cp_opcode; + // RACP operator should be indicated (normally an Operator of NULL 0x00) + p_ind->value.racp_resp.cp_operator = p_param->value[1]; + if (cp_opcode == PLXP_OPCODE_NUMBER_OF_STORED_RECORDS_RESP) + { + p_ind->value.racp_resp.rec_num = co_read16p(&p_param->value[2]); + } + else + { + // Request Control Point OpCode @see enum plxp_cp_opcodes_id + p_ind->value.racp_resp.req_cp_opcode = p_param->value[2]; + // Response Code @see enum plxp_cp_resp_code_id + p_ind->value.racp_resp.rsp_code = p_param->value[3]; + } + } + else + { + // error case + ASSERT_ERR(0); + } + + // send indication to the application + ke_msg_send(p_ind); + + // confirm that indication has been correctly received + p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + + } while (0); + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(plxc) +{ + {PLXC_ENABLE_REQ, (ke_msg_func_t)plxc_enable_req_handler}, + + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + + {PLXC_READ_CMD, (ke_msg_func_t)plxc_read_cmd_handler}, + + {PLXC_WRITE_RACP_CMD, (ke_msg_func_t)plxc_write_racp_cmd_handler}, + + {PLXC_CFG_CCC_CMD, (ke_msg_func_t)plxc_cfg_ccc_cmd_handler}, +}; + +void plxc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct plxc_env_tag *p_plxc_env = PRF_ENV_GET(PLXC, plxc); + + p_task_desc->msg_handler_tab = plxc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(plxc_msg_handler_tab); + p_task_desc->state = p_plxc_env->state; + p_task_desc->idx_max = PLXC_IDX_MAX; +} + +#endif //(BLE_PLX_CLIENT) + +/// @} PLXCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxp_common.h new file mode 100644 index 0000000..7d0d3b8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxp_common.h @@ -0,0 +1,300 @@ +/** + **************************************************************************************** + * + * @file plxp_common.h + * + * @brief Header File - Pulse Oximeter Profile common types. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * + **************************************************************************************** + */ + + +#ifndef _PLXP_COMMON_H_ +#define _PLXP_COMMON_H_ + +#include "rwip_config.h" + +#if (BLE_PLX_CLIENT || BLE_PLX_SERVER) +#include "co_math.h" +#include "prf_types.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Measurement Status characteristic all valid field mask +#define PLXP_MEAS_STATUS_VALID_MASK (0xFFE0) + +/// Device and Sensor Status all valid field mask +#define PLXP_DEVICE_STATUS_VALID_MASK (0xFFFF) + +/// All Valid bits of spot check flags field +#define PLXP_SPOT_MEAS_FLAGS_VALID_MASK (0x1F) + +/// All Valid bits of continuous measurement flags field +#define PLXP_CONT_MEAS_FLAGS_VALID_MASK (0x1F) + + /* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Control Point OpCodes +enum plxp_cp_opcodes_id +{ + PLXP_OPCODE_REPORT_STORED_RECORDS = 1, + PLXP_OPCODE_DELETE_STORED_RECORDS = 2, + PLXP_OPCODE_ABORT_OPERATION = 3, + PLXP_OPCODE_REPORT_NUMBER_OF_STORED_RECORDS = 4, + PLXP_OPCODE_NUMBER_OF_STORED_RECORDS_RESP = 5, + PLXP_OPCODE_RESPONSE_CODE = 6, +}; + +/// Control Point Operators +enum plxp_cp_operator_id +{ + PLXP_OPERATOR_NULL = 0, + PLXP_OPERATOR_ALL_RECORDS = 1, +}; + +/// Control Point Response Code Values +enum plxp_cp_resp_code_id +{ + PLXP_RESP_SUCCESS = 1, + PLXP_RESP_OP_CODE_NOT_SUPPORTED = 2, + PLXP_RESP_INVALID_OPERATOR = 3, + PLXP_RESP_OPERATOR_NOT_SUPPORTED = 4, + PLXP_RESP_INVALID_OPERAND = 5, + PLXP_RESP_NO_RECORDS_FOUND = 6, + PLXP_RESP_ABORT_UNSUCCESSFUL = 7, + PLXP_RESP_PROCEDURE_NOT_COMPLETED = 8, + PLXP_RESP_OPERAND_NOT_SUPPORTED = 9, +}; + +/// Supported Features bit field +enum plxp_sup_feat_bf +{ + /// Measurement Status support is present + PLXP_FEAT_MEAS_STATUS_SUP_POS = 0, + PLXP_FEAT_MEAS_STATUS_SUP_BIT = CO_BIT(PLXP_FEAT_MEAS_STATUS_SUP_POS), + + /// Device and Sensor Status support is present + PLXP_FEAT_DEV_SENSOR_STATUS_SUP_POS = 1, + PLXP_FEAT_DEV_SENSOR_STATUS_SUP_BIT = CO_BIT(PLXP_FEAT_DEV_SENSOR_STATUS_SUP_POS), + + /// Measurement Storage for Spot-check measurements is supported + PLXP_FEAT_MEAS_STORAGE_SUP_POS = 2, + PLXP_FEAT_MEAS_STORAGE_SUP_BIT = CO_BIT(PLXP_FEAT_MEAS_STORAGE_SUP_POS), + + /// Timestamp for Spot-check measurements is supported + PLXP_FEAT_TIMESTAMP_SUP_POS = 3, + PLXP_FEAT_TIMESTAMP_SUP_BIT = CO_BIT(PLXP_FEAT_TIMESTAMP_SUP_POS), + + /// SpO2PR-Fast metric is supported + PLXP_FEAT_SPO2PR_FAST_SUP_POS = 4, + PLXP_FEAT_SPO2PR_FAST_SUP_BIT = CO_BIT(PLXP_FEAT_SPO2PR_FAST_SUP_POS), + + /// SpO2PR-Slow metric is supported + PLXP_FEAT_SPO2PR_SLOW_SUP_POS = 5, + PLXP_FEAT_SPO2PR_SLOW_SUP_BIT = CO_BIT(PLXP_FEAT_SPO2PR_SLOW_SUP_POS), + + /// Pulse Amplitude Index field is supported + PLXP_FEAT_PULSE_AMPL_SUP_POS = 6, + PLXP_FEAT_PULSE_AMPL_SUP_BIT = CO_BIT(PLXP_FEAT_PULSE_AMPL_SUP_POS), + + /// Multiple Bonds Supported + PLXP_FEAT_MULT_BONDS_SUP_POS = 7, + PLXP_FEAT_MULT_BONDS_SUP_BIT = CO_BIT(PLXP_FEAT_MULT_BONDS_SUP_POS), + + // Bit 8-15 RFU +}; + +/// Spot check measurement characteristic flags bit field +enum plxp_spot_check_flags_bf +{ + /// Timestamp field (bit 0) + /// 0 for not present + /// 1 for present + PLXP_SPOT_MEAS_FLAGS_TIMESTAMP_POS = 0, + PLXP_SPOT_MEAS_FLAGS_TIMESTAMP_BIT = CO_BIT(PLXP_SPOT_MEAS_FLAGS_TIMESTAMP_POS), + + /// Measurement Status field (bit 1) + /// 0 for not present + /// 1 for present + PLXP_SPOT_MEAS_FLAGS_MEAS_STATUS_POS = 1, + PLXP_SPOT_MEAS_FLAGS_MEAS_STATUS_BIT = CO_BIT(PLXP_SPOT_MEAS_FLAGS_MEAS_STATUS_POS), + + /// Device and Sensor Status field (bit 2) + /// 0 for not present + /// 1 for present + PLXP_SPOT_MEAS_FLAGS_DEV_SENSOR_STATUS_POS = 2, + PLXP_SPOT_MEAS_FLAGS_DEV_SENSOR_STATUS_BIT = CO_BIT(PLXP_SPOT_MEAS_FLAGS_DEV_SENSOR_STATUS_POS), + + /// Pulse Amplitude Index field (bit 3) + /// 0 for not present + /// 1 for present + PLXP_SPOT_MEAS_FLAGS_PULSE_AMPLITUDE_POS = 3, + PLXP_SPOT_MEAS_FLAGS_PULSE_AMPLITUDE_BIT = CO_BIT(PLXP_SPOT_MEAS_FLAGS_PULSE_AMPLITUDE_POS), + + /// Device Clock is Not Set (bit 4) + /// 0 for not present + /// 1 for present + PLXP_SPOT_MEAS_FLAGS_CLOCK_NOT_SET_POS = 4, + PLXP_SPOT_MEAS_FLAGS_CLOCK_NOT_SET_BIG = CO_BIT(PLXP_SPOT_MEAS_FLAGS_CLOCK_NOT_SET_POS), + + // Bit 5-7 RFU +}; + +/// Continuous measurement characteristic flags bit field +enum plxp_cont_meas_flags_bf +{ + /// SpO2PR-Fast field is present + PLXP_CONT_MEAS_FLAGS_SPO2PR_FAST_POS = 0, + PLXP_CONT_MEAS_FLAGS_SPO2PR_FAST_BIT = CO_BIT(PLXP_CONT_MEAS_FLAGS_SPO2PR_FAST_POS), + + //// SpO2PR-Slow field is present + PLXP_CONT_MEAS_FLAGS_SPO2PR_SLOW_POS = 1, + PLXP_CONT_MEAS_FLAGS_SPO2PR_SLOW_BIT = CO_BIT(PLXP_CONT_MEAS_FLAGS_SPO2PR_SLOW_POS), + + /// Measurement Status field is present + PLXP_CONT_MEAS_FLAGS_MEAS_STATUS_POS = 2, + PLXP_CONT_MEAS_FLAGS_MEAS_STATUS_BIT = CO_BIT(PLXP_CONT_MEAS_FLAGS_MEAS_STATUS_POS), + + /// Device and Sensor Status field is present + PLXP_CONT_MEAS_FLAGS_DEV_SENSOR_STATUS_POS = 3, + PLXP_CONT_MEAS_FLAGS_DEV_SENSOR_STATUS_BIT = CO_BIT(PLXP_CONT_MEAS_FLAGS_DEV_SENSOR_STATUS_POS), + + /// Pulse Amplitude Index field is present + PLXP_CONT_MEAS_FLAGS_PULSE_AMPL_POS = 4, + PLXP_CONT_MEAS_FLAGS_PULSE_AMPL_BIT = CO_BIT(PLXP_CONT_MEAS_FLAGS_PULSE_AMPL_POS), + + // Bit 5-7 RFU +}; + +/// Measurement Status field (not used) +enum plxp_meas_status_sup_bf +{ + // Bit 0-4 RFU + /// Measurement Ongoing bit supported + PLXP_MEAS_STATUS_MEAS_ONGOING_SUP_POS = 5, + PLXP_MEAS_STATUS_MEAS_ONGOING_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_MEAS_ONGOING_SUP_POS), + + /// Early Estimated Data bit supported + PLXP_MEAS_STATUS_EARLY_ESTIM_DATA_SUP_POS = 6, + PLXP_MEAS_STATUS_EARLY_ESTIM_DATA_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_EARLY_ESTIM_DATA_SUP_POS), + + /// Validated Data bit supported + PLXP_MEAS_STATUS_VALIDATED_DATA_SUP_POS = 7, + PLXP_MEAS_STATUS_VALIDATED_DATA_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_VALIDATED_DATA_SUP_POS), + + /// Fully Qualified Data bit supported + PLXP_MEAS_STATUS_FULLY_QUALIF_DATA_SUP_POS = 8, + PLXP_MEAS_STATUS_FULLY_QUALIF_DATA_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_FULLY_QUALIF_DATA_SUP_POS), + + /// Data from Measurement Storage bit supported + PLXP_MEAS_STATUS_DATA_FROM_MEAS_STRG_SUP_POS = 9, + PLXP_MEAS_STATUS_DATA_FROM_MEAS_STRG_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_DATA_FROM_MEAS_STRG_SUP_POS), + + /// Data for Demonstration bit supported + PLXP_MEAS_STATUS_DATA_FOR_DEMO_SUP_POS = 10, + PLXP_MEAS_STATUS_DATA_FOR_DEMO_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_DATA_FOR_DEMO_SUP_POS), + + /// Data for Testing bit supported + PLXP_MEAS_STATUS_DATA_FOR_TEST_SUP_POS = 11, + PLXP_MEAS_STATUS_DATA_FOR_TEST_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_DATA_FOR_TEST_SUP_POS), + + /// Calibration Ongoing bit supported + PLXP_MEAS_STATUS_CALIB_ONGOING_SUP_POS = 12, + PLXP_MEAS_STATUS_CALIB_ONGOING_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_CALIB_ONGOING_SUP_POS), + + /// Measurement Unavailable bit supported + PLXP_MEAS_STATUS_MEAS_UNAVAILB_SUP_POS = 13, + PLXP_MEAS_STATUS_MEAS_UNAVAILB_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_MEAS_UNAVAILB_SUP_POS), + + /// Questionable Measurement Detected bit supported + PLXP_MEAS_STATUS_QUEST_MEAS_DET_SUP_POS = 14, + PLXP_MEAS_STATUS_QUEST_MEAS_DET_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_QUEST_MEAS_DET_SUP_POS), + + /// Invalid Measurement Detected bit supported + PLXP_MEAS_STATUS_INV_MEAS_DET_SUP_POS = 15, + PLXP_MEAS_STATUS_INV_MEAS_DET_SUP_BIT = CO_BIT(PLXP_MEAS_STATUS_INV_MEAS_DET_SUP_POS), +}; + + +/// Device and Sensor Status field (not used) +enum plxp_dev_sensor_status_bf +{ + /// Extended Display Update Ongoing + PLXP_DEV_STATUS_EXT_DISP_UPDATE_ONGOING_POS = 0, + PLXP_DEV_STATUS_EXT_DISP_UPDATE_ONGOING_BIT = CO_BIT(PLXP_DEV_STATUS_EXT_DISP_UPDATE_ONGOING_POS), + + /// Signal Processing Irregularity Detected bit supported + PLXP_DEV_STATUS_EQUIP_MALFUNC_DET_SUP_POS = 1, + PLXP_DEV_STATUS_EQUIP_MALFUNC_DET_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_EQUIP_MALFUNC_DET_SUP_POS), + + /// Signal Processing Irregularity Detected bit supported + PLXP_DEV_STATUS_SIGNAL_PROC_IRREGUL_DET_SUP_POS = 2, + PLXP_DEV_STATUS_SIGNAL_PROC_IRREGUL_DET_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_SIGNAL_PROC_IRREGUL_DET_SUP_POS), + + /// Inadequate Signal Detected bit supported + PLXP_DEV_STATUS_INADEQ_SIGNAL_DET_SUP_POS = 3, + PLXP_DEV_STATUS_INADEQ_SIGNAL_DET_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_INADEQ_SIGNAL_DET_SUP_POS), + + /// Poor Signal Detected bit supported + PLXP_DEV_STATUS_POOR_SIGNAL_DET_SUP_POS = 4, + PLXP_DEV_STATUS_POOR_SIGNAL_DET_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_POOR_SIGNAL_DET_SUP_POS), + + /// Low Perfusion Detected bit supported + PLXP_DEV_STATUS_LOW_PERF_DET_SUP_POS = 5, + PLXP_DEV_STATUS_LOW_PERF_DET_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_LOW_PERF_DET_SUP_POS), + + /// Erratic Signal Detected bit supported + PLXP_DEV_STATUS_ERRATIC_SIGNAL_DET_SUP_POS = 6, + PLXP_DEV_STATUS_ERRATIC_SIGNAL_DET_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_ERRATIC_SIGNAL_DET_SUP_POS), + + /// Nonpulsatile Signal Detected bit supported + PLXP_DEV_STATUS_NONPULS_SIGNAL_DET_SUP_POS = 7, + PLXP_DEV_STATUS_NONPULS_SIGNAL_DET_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_NONPULS_SIGNAL_DET_SUP_POS), + + /// Questionable Pulse Detected bit supported + PLXP_DEV_STATUS_QUEST_PULSE_DET_SUP_POS = 8, + PLXP_DEV_STATUS_QUEST_PULSE_DET_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_QUEST_PULSE_DET_SUP_POS), + + /// Signal Analysis Ongoing bit supported + PLXP_DEV_STATUS_SIGNAL_ANAL_ONGOING_SUP = 9, + PLXP_DEV_STATUS_SIGNAL_ANAL_ONGOING_BIT = CO_BIT(PLXP_DEV_STATUS_SIGNAL_ANAL_ONGOING_SUP), + + /// Sensor Interference Detected bit supported + PLXP_DEV_STATUS_SENSOR_INTERF_DET_SUP_POS = 10, + PLXP_DEV_STATUS_SENSOR_INTERF_DET_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_SENSOR_INTERF_DET_SUP_POS), + + /// Sensor Unconnected to User bit supported + PLXP_DEV_STATUS_SENSOR_UNCONNCTD_TO_USER_SUP_POS = 11, + PLXP_DEV_STATUS_SENSOR_UNCONNCTD_TO_USER_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_SENSOR_UNCONNCTD_TO_USER_SUP_POS), + + /// Unknown Sensor Connected bit supported + PLXP_DEV_STATUS_UNKNOWN_SENSOR_CONNCTD_SUP_POS = 12, + PLXP_DEV_STATUS_UNKNOWN_SENSOR_CONNCTD_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_UNKNOWN_SENSOR_CONNCTD_SUP_POS), + + /// Sensor Displaced bit supported + PLXP_DEV_STATUS_SENSOR_DISPL_SUP_POS = 13, + PLXP_DEV_STATUS_SENSOR_DISPL_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_SENSOR_DISPL_SUP_POS), + + /// Sensor Malfunctioning bit supported + PLXP_DEV_STATUS_SENSOR_MALFUNC_SUP_POS = 14, + PLXP_DEV_STATUS_SENSOR_MALFUNC_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_SENSOR_MALFUNC_SUP_POS), + + /// Sensor Disconnected bit supported + PLXP_DEV_STATUS_SENSOR_DISCONNCTD_SUP_POS = 15, + PLXP_DEV_STATUS_SENSOR_DISCONNCTD_SUP_BIT = CO_BIT(PLXP_DEV_STATUS_SENSOR_DISCONNCTD_SUP_POS), + + // Bit 16-23 RFU +}; + +#endif /* (BLE_PLXP_CLIENT || BLE_PLXP_SERVER) */ + +#endif /* _PLXP_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/api/plxs_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/api/plxs_task.h new file mode 100644 index 0000000..9fb10d5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/api/plxs_task.h @@ -0,0 +1,232 @@ +/** + **************************************************************************************** + * + * @file plxs_task.h + * + * @brief Header file - Pulse Oximeter Profile Service Task. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _PLXS_TASK_H_ +#define _PLXS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup PLXSTASK Task + * @ingroup PLXS + * @brief Pulse Oximeter Profile Task. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + +#include "plxp_common.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Messages for Pulse Oximeter Profile Service +enum plxs_msg_id +{ + /// Enable the PLXP Sensor task for a connection + PLXS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_PLXS), + /// Enable the PLXP Sensor task for a connection + PLXS_ENABLE_RSP, + /// Send the Spot-check Measurement or Measurement Record + /// Send Continuous Measurement + PLXS_MEAS_VALUE_CMD, + /// Send Control Point Response + PLXS_RACP_RESP_CMD, + /// Inform Application on the Characteristics CCC descriptor changes + PLXS_WR_CHAR_CCC_IND, + /// Write to the Control Point forward to Application + PLXS_WR_RACP_IND, + /// Complete event for the Application commands + PLXS_CMP_EVT, +}; + +/// type_of_operation - Additional to Specification to select the type of operation +enum plxs_optype_id +{ + PLXS_OPTYPE_SPOT_CHECK_AND_CONTINUOUS = 0, + PLXS_OPTYPE_SPOT_CHECK_ONLY = 1, + PLXS_OPTYPE_CONTINUOUS_ONLY = 2 +}; + +/// Define command operation +enum plxs_op_codes +{ + PLXS_SPOT_CHECK_MEAS_CMD_OP_CODE = 1, + PLXS_CONTINUOUS_MEAS_CMD_OP_CODE = 2, + PLXS_RACP_CMD_OP_CODE = 3, +}; + +/// Define characteristic type +enum plxs_char_types +{ + PLXS_SPOT_CHECK_MEAS_CODE = 1, + PLXS_CONTINUOUS_MEAS_CODE = 2, + PLXS_RACP_CODE = 3, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the initialization function +struct plxs_db_cfg +{ + /// Define the Type of Operation @see enum plxs_optype_id + uint8_t optype; + /// Supported Features @see common enum plxp_sup_feat_bf + uint16_t sup_feat; + /// If enabled in Supported Features @see enum plxp_meas_status_sup_bf + uint16_t meas_stat_sup; + /// If enabled in Supported Features @see enum plxp_dev_sensor_status_bf + uint32_t dev_stat_sup; +}; + +/// Parameters of the @see PLXS_ENABLE_REQ message +struct plxs_enable_req +{ + /// CCC for the current connection + uint16_t ind_cfg_spot_meas; + /// CCC for the current connection + uint16_t ind_cfg_cont_meas; + /// CCC for the current connection + uint16_t ind_cfg_racp_meas; +}; + +/// Parameters of the @see PLXS_ENABLE_RSP message +struct plxs_enable_rsp +{ + /// Status + uint8_t status; +}; + +/// PLX Spot-Check Measurement Value +struct plxs_spot_meas_value +{ + /// bitfield of supplied data @see common plxp_spot_check_flags_bf + uint8_t spot_flags; + /// Percentage with a resolution of 1 + uint16_t sp_o2; + /// Period (beats per minute) with a resolution of 1 + uint16_t pr; + /// Timestamp (if present) + struct prf_date_time timestamp; + /// Measurement Status (bitfield) @see common measurement_status_supported + uint16_t meas_stat; + /// Device and Sensor Status (bitfield) @see common device_status_supported + uint32_t dev_sensor_stat; + /// Pulse Amplitude Index - Unit is percentage with a resolution of 1 + uint16_t pulse_ampl; +}; + +/// SpO2 - PR measurements +struct plxs_spo2pr_value +{ + /// Percentage with a resolution of 1 + uint16_t sp_o2; + /// Period (beats per minute) with a resolution of 1 + uint16_t pr; +}; + +/// PLX Continuous Measurement Value +struct plxs_cont_meas_value +{ + /// bitfield of supplied data @see common plxp_cont_meas_flag + uint8_t cont_flags; + /// SpO2 - PR measurements - Normal + struct plxs_spo2pr_value normal; + /// SpO2 - PR measurements - Fast + struct plxs_spo2pr_value fast; + /// SpO2 - PR measurements - Slow + struct plxs_spo2pr_value slow; + /// Measurement Status (bitfield) @see common measurement_status_supported + uint16_t meas_stat; + /// Device and Sensor Status (bitfield) @see common device_status_supported + uint32_t dev_sensor_stat; + /// Pulse Amplitude Index - Unit is percentage with a resolution of 1 + uint16_t pulse_ampl; +}; + +/// Send the Spot-check Measurement or Measurement Record +/// Send Continuous Measurement +/// Parameters of the @see PLXS_MEAS_VALUE_CMD, +struct plxs_meas_value_cmd +{ + /// Operation @see enum plxs_op_codes + uint8_t operation; + union plxs_meas_value_tag + { + /// Spot-Check Measurement + struct plxs_spot_meas_value spot_meas; + /// Continuous Measurement + struct plxs_cont_meas_value cont_meas; + } value; +}; + +/// Send Control Point Response +/// Parameters of the @see PLXS_RACP_RESP_CMD, +struct plxs_racp_resp_cmd +{ + /// Operation = PLXS_RASP_CMD_OP_CODE @see enum plxs_op_codes + uint8_t operation; + /// Control Point OpCode @see enum plxp_cp_opcodes_id + uint8_t cp_opcode; + /// Request Control Point OpCode @see enum plxp_cp_opcodes_id + uint8_t req_cp_opcode; + /// Response Code @see enum plxp_cp_resp_code_id + uint8_t rsp_code; + /// Number of Records + uint16_t rec_num; +}; + +/// Write to the Control Point forward to Application +/// Parameters of the @see PLXS_WR_RACP_IND, +struct plxs_wr_racp_ind +{ + /// Control Point OpCode @see enum plxp_cp_opcodes_id + uint8_t cp_opcode; + /// Operator @see enum plxp_cp_operator_id + uint8_t cp_operator; +}; + +/// Inform Application on the Characteristic's CCC descriptor changes +/// Parameters of the @see PLXS_WR_CHAR_CCC_IND, +struct plxs_wr_char_ccc_ind +{ + /// CHaracteristic type @see enum plxs_char_types + uint8_t char_type; + /// Char. Client Characteristic Configuration + uint16_t ind_cfg; +}; + +/// Parameters of the @see PLXS_CMP_EVT message +struct plxs_cmp_evt +{ + /// Operation @see enum plxs_op_codes + uint8_t operation; + /// Operation Status + uint8_t status; +}; + +/// @} PLXSTASK + +#endif //(_PLXS_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/sourcelist.txt new file mode 100644 index 0000000..3fbc9b9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2017 +# +#*************************************************************************************** + + plxs.c + plxs_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/src/plxs.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/src/plxs.c new file mode 100644 index 0000000..ad39a4d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/src/plxs.c @@ -0,0 +1,346 @@ +/** + **************************************************************************************** + * + * @file plxs.c + * + * @brief Pulse Oximeter Profile Service implementation. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup PLXS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_PLX_SERVER) +#include "plxp_common.h" + +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "plxs.h" +#include "plxs_task.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default read perm +#define RD_P (PERM(RD, ENABLE) | PERM(RP, UNAUTH)) +/// Default write perm +#define WR_P (PERM(WRITE_REQ, ENABLE) | PERM(WP, UNAUTH)) +/// Default notify perm +#define NTF_P (PERM(NTF, ENABLE) | PERM(NP, UNAUTH)) +/// Ind perm +#define IND_P (PERM(IND, ENABLE) | PERM(IP, NO_AUTH)) +/// Enable Read Indication (1 = Value not present in Database) +#define RI_P PERM(RI, ENABLE) + +/// Full PLXS Database Description - Used to add attributes into the database +static const struct attm_desc plxs_att_db[PLXS_IDX_NB] = +{ + // ATT Index | ATT UUID | Permission | EXT PERM | MAX ATT SIZE + // service attribute + [PLXS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + // PLXP SPOT-Measurement Characteristic + [PLXS_IDX_SPOT_MEASUREMENT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [PLXS_IDX_SPOT_MEASUREMENT_VAL] = {ATT_CHAR_PLX_SPOT_CHECK_MEASUREMENT_LOC, IND_P, 0, 0}, + [PLXS_IDX_SPOT_MEASUREMENT_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, RD_P | WR_P, RI_P, 0}, + // PLXP Continuous Measurement Characteristic + [PLXS_IDX_CONT_MEASUREMENT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [PLXS_IDX_CONT_MEASUREMENT_VAL] = {ATT_CHAR_PLX_CONTINUOUS_MEASUREMENT_LOC, NTF_P, 0, 0}, + [PLXS_IDX_CONT_MEASUREMENT_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, RD_P | WR_P, RI_P, 0}, + // PLXP Features Characteristic + [PLXS_IDX_FEATURES_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [PLXS_IDX_FEATURES_VAL] = {ATT_CHAR_PLX_FEATURES_LOC, RD_P, 0, PLXS_IDX_FEAT_SIZE_MAX}, + // PLXP Record Access Control Point Characteristic + [PLXS_IDX_RACP_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [PLXS_IDX_RACP_VAL] = {ATT_CHAR_REC_ACCESS_CTRL_PT, WR_P | IND_P, 0, PLXS_IDX_RACP_SIZE_MAX}, + [PLXS_IDX_RACP_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, RD_P | WR_P, RI_P, 0}, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ +uint16_t plxs_att2handle(uint8_t attribute) +{ + // Get the address of the environment + struct plxs_env_tag *p_plxs_env = PRF_ENV_GET(PLXS, plxs); + uint16_t handle = p_plxs_env->shdl + attribute; + + if (PLXS_OPTYPE_SPOT_CHECK_ONLY == p_plxs_env->optype) + { + // adjust by not existent CONT_MEAS attributes + if (attribute >= PLXS_IDX_FEATURES_CHAR) + { + handle -= PLXS_IDX_FEATURES_CHAR - PLXS_IDX_CONT_MEASUREMENT_CHAR; + } + } + else if (PLXS_OPTYPE_CONTINUOUS_ONLY == p_plxs_env->optype) + { + // adjust by not existent SPOT_MEASUREMENT attributes + if (attribute >= PLXS_IDX_CONT_MEASUREMENT_CHAR) + { + attribute += PLXS_IDX_CONT_MEASUREMENT_CHAR - PLXS_IDX_SPOT_MEASUREMENT_CHAR; + } + } + + return handle; +} + +uint8_t plxs_handle2att(uint16_t handle) +{ + // Get the address of the environment + struct plxs_env_tag *p_plxs_env = PRF_ENV_GET(PLXS, plxs); + uint8_t att_idx = handle - p_plxs_env->shdl; + + if (PLXS_OPTYPE_SPOT_CHECK_ONLY == p_plxs_env->optype) + { + // if >4 then +3 (4-->7) + if (att_idx > 4) + { + att_idx += PLXS_IDX_FEATURES_CHAR -PLXS_IDX_CONT_MEASUREMENT_CHAR; + } + } + else if (PLXS_OPTYPE_CONTINUOUS_ONLY == p_plxs_env->optype) + { + // if >0 then +3 (1-->4) + if (att_idx > 0) + { + att_idx += PLXS_IDX_CONT_MEASUREMENT_CHAR -PLXS_IDX_SPOT_MEASUREMENT_CHAR; + } + } + + return att_idx; +} +/** + **************************************************************************************** + * @brief Initialization of the PLXS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t plxs_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct plxs_db_cfg *p_params) +{ + //------------------ create the attribute database for the profile ------------------- + // Service content flag + uint8_t cfg_flag[] = {0xFF,0x0F}; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + if (PLXS_OPTYPE_SPOT_CHECK_ONLY == p_params->optype) + { + // mask off Continuous Measurement Characteristic + // mask off Records Access Control Point Characteristic + cfg_flag[0] = 0x8F; + cfg_flag[1] = 0x01; + } + else if (PLXS_OPTYPE_CONTINUOUS_ONLY == p_params->optype) + { + // mask off SPOT-Measurement Characteristic + cfg_flag[0] = 0xF1; + } + else + { + p_params->optype = 0; + } + // Add service in the database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_PULSE_OXIMETER, (uint8_t *)&cfg_flag[0], + PLXS_IDX_NB, NULL, p_env->task, &plxs_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS )) | PERM(SVC_MI, ENABLE)); + + // Check if an error has occured + if (status == ATT_ERR_NO_ERROR) + { + // Allocate PLXS required environment variable + struct plxs_env_tag *p_plxs_env = + (struct plxs_env_tag *) ke_malloc(sizeof(struct plxs_env_tag), KE_MEM_ATT_DB); + + // Initialize PLXS environment + p_env->env = (prf_env_t *) p_plxs_env; + p_plxs_env->shdl = *p_start_hdl; + // Keep the Type of Operation @see enum plxs_optype_id + p_plxs_env->optype = p_params->optype; + // Keep Supported Features @see common sup_feat + p_plxs_env->sup_feat = p_params->sup_feat; + // Keep meas_stat_sup @see common meas_stat_sup + p_plxs_env->meas_stat_sup = p_params->meas_stat_sup; + // Keep dev_stat_sup @see common dev_stat_sup + p_plxs_env->dev_stat_sup = p_params->dev_stat_sup; + + // Multi Instantiated APP task + p_plxs_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Multi Instantiated task ???depend on Multiple user support Feature + p_plxs_env->prf_env.prf_task = p_env->task + | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_PLXS; + plxs_task_init(&(p_env->desc)); + + // Initialize CCC per connection + memset(p_plxs_env->prfl_ind_cfg_spot, 0, sizeof(p_plxs_env->prfl_ind_cfg_spot)); + memset(p_plxs_env->prfl_ind_cfg_cont, 0, sizeof(p_plxs_env->prfl_ind_cfg_cont)); + memset(p_plxs_env->prfl_ind_cfg_racp, 0, sizeof(p_plxs_env->prfl_ind_cfg_racp)); + memset(p_plxs_env->racp_in_progress, 0, sizeof(p_plxs_env->racp_in_progress)); + + // Store the Features into at database + { + uint8_t value[PLXS_IDX_FEAT_SIZE_MAX]; + uint16_t length; + uint8_t *p_data = &value[0]; + uint16_t handle = plxs_att2handle(PLXS_IDX_FEATURES_VAL); + + co_write16p(p_data, p_plxs_env->sup_feat); + p_data += 2; + length = 2; + + if (GETB(p_plxs_env->sup_feat, PLXP_FEAT_MEAS_STATUS_SUP)) + { + co_write16p(p_data, p_plxs_env->meas_stat_sup); + length += 2; // sizeof(uint16_t) + p_data += 2; + } + if (GETB(p_plxs_env->sup_feat, PLXP_FEAT_DEV_SENSOR_STATUS_SUP)) + { + co_write24p(p_data, p_plxs_env->dev_stat_sup); + length += 3; // sizeof(uint24_t) + } + attm_att_set_value(handle, length, 0, &value[0]); + } + + // If we are here, database has been fulfilled with success, go to idle state + for (uint8_t idx = 0; idx < BLE_CONNECTION_MAX ; idx++) + { + // Put PLXS in disabled state + ke_state_set(KE_BUILD_ID(p_env->task, idx), PLXS_FREE); + } + } + + return (status); +} +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void plxs_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct plxs_env_tag *p_plxs_env = (struct plxs_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + p_plxs_env->prfl_ind_cfg_spot[conidx] = 0; + p_plxs_env->prfl_ind_cfg_cont[conidx] = 0; + p_plxs_env->prfl_ind_cfg_racp[conidx] = 0; + p_plxs_env->racp_in_progress[conidx] = 0; + + // Put PLXS in disabled state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), PLXS_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the PLXS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void plxs_destroy(struct prf_task_env *p_env) +{ + struct plxs_env_tag *p_plxs_env = (struct plxs_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + + // free profile environment variables + p_env->env = NULL; + + ke_free(p_plxs_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void plxs_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct plxs_env_tag *p_plxs_env = (struct plxs_env_tag *) p_env->env; + p_plxs_env->prfl_ind_cfg_spot[conidx] = 0; + p_plxs_env->prfl_ind_cfg_cont[conidx] = 0; + p_plxs_env->prfl_ind_cfg_racp[conidx] = 0; + p_plxs_env->racp_in_progress[conidx] = 0; + + // Put PLXS in IDLE state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), PLXS_IDLE);} + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// PLXS Task interface required by profile manager +const struct prf_task_cbs plxs_itf = +{ + (prf_init_fnct) plxs_init, + plxs_destroy, + plxs_create, + plxs_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *plxs_prf_itf_get(void) +{ + return &plxs_itf; +} + + +#endif //(BLE_PLX_SERVER) + +/// @} PLXS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/src/plxs.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/src/plxs.h new file mode 100644 index 0000000..e888666 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/src/plxs.h @@ -0,0 +1,192 @@ +/** + **************************************************************************************** + * + * @file plxs.h + * + * @brief Header file - Pulse Oximeter Profile Service. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _PLXS_H_ +#define _PLXS_H_ + +/** + **************************************************************************************** + * @addtogroup PLXS Pulse Oximeter Profile Service + * @ingroup PLXS + * @brief Pulse Oximeter Profile Service + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_PLX_SERVER) +#include "plxp_common.h" +#include "plxs_task.h" + +#include "prf_types.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Pulse Oximeter Profile Service role task instances +#define PLXS_IDX_MAX (BLE_CONNECTION_MAX) + +/// Maximum Features size (supported features + measurement status + device sensor status) +#define PLXS_IDX_FEAT_SIZE_MAX (2+2+3) + +/// Maximum Control Point size OpCode + Operator +#define PLXS_IDX_RACP_SIZE_MAX (2) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + /// Possible states of the PLXS task +enum plxs_state_id +{ + /// not connected state + PLXS_FREE, + /// idle state + PLXS_IDLE, + /// read request + PLXS_OP_READ, + /// notify + PLXS_OP_NOTIFY, + /// indicate Spot_Measurement + PLXS_OP_INDICATE_MEAS, + /// indicate RACP + PLXS_OP_INDICATE_RACP, + PLXS_OP_INDICATE_RACP_NO_CMP, + + /// Number of defined states. + ENVS_STATE_MAX +}; + +/// Pulse Oximeter Service - Attribute List +enum plxs_att_list +{ + /// Pulse Oximeter Service + PLXS_IDX_SVC, + /// PLXP SPOT-Measurement Characteristic + PLXS_IDX_SPOT_MEASUREMENT_CHAR, + PLXS_IDX_SPOT_MEASUREMENT_VAL, + /// CCC Descriptor + PLXS_IDX_SPOT_MEASUREMENT_CCC, + /// PLXP Continuous Measurement Characteristic + PLXS_IDX_CONT_MEASUREMENT_CHAR, + PLXS_IDX_CONT_MEASUREMENT_VAL, + /// CCC Descriptor + PLXS_IDX_CONT_MEASUREMENT_CCC, + /// PLXP Features Characteristic + PLXS_IDX_FEATURES_CHAR, + PLXS_IDX_FEATURES_VAL, + /// PLXP Record Access Control Point Characteristic + PLXS_IDX_RACP_CHAR, + PLXS_IDX_RACP_VAL, + /// CCC Descriptor + PLXS_IDX_RACP_CCC, + + /// Number of attributes + PLXS_IDX_NB, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Pulse Oximeter Profile Service environment variable +struct plxs_env_tag +{ + /// profile environment + prf_env_t prf_env; + + /// Pulse Oximeter Service Start Handle + uint16_t shdl; + /// Define the Type of Operation @see enum plxs_optype_id + uint8_t optype; + /// Supported Features @see common supported_features + uint16_t sup_feat; + /// If enabled in Supported Features @see common measurement_status_supported + uint16_t meas_stat_sup; + /// If enabled in Supported Features @see common device_status_supported + uint32_t dev_stat_sup; + /// CCC for Spot-Measurement + uint16_t prfl_ind_cfg_spot[BLE_CONNECTION_MAX]; + /// CCC for Cont-Measurement + uint16_t prfl_ind_cfg_cont[BLE_CONNECTION_MAX]; + /// CCC for RACP + uint16_t prfl_ind_cfg_racp[BLE_CONNECTION_MAX]; + /// RACP keep state of the procedure + uint8_t racp_in_progress[BLE_CONNECTION_MAX]; + + /// State of different task instances + ke_state_t state[PLXS_IDX_MAX]; + +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Convert raw handle to the attribute index from @see enum plxs_att_list + * @param[in] handle PLXS raw handle + * @return PLXS Attribute + **************************************************************************************** + */ +uint8_t plxs_handle2att(uint16_t handle); + +/** + **************************************************************************************** + * @brief Convert attribute to the raw handle index from @see enum plxs_att_list + * @param[in] attribute PLXS Attribute + * @return PLXS Handle index + **************************************************************************************** + */ +uint16_t plxs_att2handle(uint8_t attribute); + +/** + **************************************************************************************** + * @brief Retrieve PLXP service profile interface + * + * @return PLXP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *plxs_prf_itf_get(void); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void plxs_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_PLX_SERVER) + +/// @} PLXS + +#endif //(_PLXS_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/src/plxs_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/src/plxs_task.c new file mode 100644 index 0000000..f2653c0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/plxp/plxs/src/plxs_task.c @@ -0,0 +1,952 @@ +/** + **************************************************************************************** + * + * @file plxs_task.c + * + * @brief Pulse Oximeter Profile Service Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2017 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup PLXSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_PLX_SERVER) +#include "plxp_common.h" + +#include "gapc.h" +#include "gattc_task.h" +#include "attm.h" +#include "plxs.h" +#include "plxs_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Send RACP response indication. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @param[in] cp_opcode Control Point Opcode @see enum plxp_cp_opcodes_id + * @param[in] req_cp_opcode Request Control Point OpCode @see enum plxp_cp_opcodes_id + * @param[in] rsp_code Response Code @see enum plxp_cp_resp_code_id + * @param[in] rec_num Number of Records + **************************************************************************************** + */ +static void plxs_racp_resp_send(ke_task_id_t const dest_id, ke_task_id_t const src_id, + uint8_t cp_opcode, uint8_t req_cp_opcode, uint8_t rsp_code, uint16_t rec_num) +{ + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ind; + // length of the data block + uint16_t length; + // handle to send the indication + uint16_t handle; + + handle = plxs_att2handle(PLXS_IDX_RACP_VAL); + // OpCode -1oct,Operator=Null-1oct,Operand -2oct + length = 4; + // Allocate the GATT notification message + p_ind = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + dest_id, + src_id, + gattc_send_evt_cmd, length); + + // Fill in the p_parameter structure + p_ind->operation = GATTC_INDICATE; + p_ind->handle = handle; + p_ind->length = length; + // Fill data + // Procedure Op Code + p_ind->value[0] = cp_opcode; + // Operator - Null + p_ind->value[1] = PLXP_OPERATOR_NULL; + + if (cp_opcode == PLXP_OPCODE_NUMBER_OF_STORED_RECORDS_RESP) + { + co_write16p(&(p_ind->value[2]), rec_num); + } + else + { + p_ind->value[2] = req_cp_opcode; + p_ind->value[3] = rsp_code; + } + + // send notification to peer device + ke_msg_send(p_ind); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see PLXS_ENABLE_REQ message. + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int plxs_enable_req_handler(ke_msg_id_t const msgid, + struct plxs_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct plxs_enable_rsp *cmp_evt; + + if (ke_state_get(dest_id) == PLXS_IDLE) + { + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct plxs_env_tag *p_plxs_env = PRF_ENV_GET(PLXS, plxs); + + // CCCs for the current connection + p_plxs_env->prfl_ind_cfg_spot[conidx] = p_param->ind_cfg_spot_meas; + p_plxs_env->prfl_ind_cfg_cont[conidx] = p_param->ind_cfg_cont_meas; + p_plxs_env->prfl_ind_cfg_racp[conidx] = p_param->ind_cfg_racp_meas; + status = GAP_ERR_NO_ERROR; + } + + // send completed information to APP task that contains error status + cmp_evt = KE_MSG_ALLOC(PLXS_ENABLE_RSP, src_id, dest_id, plxs_enable_rsp); + cmp_evt->status = status; + + ke_msg_send(cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + + // check that task is in idle state + if (ke_state_get(dest_id) == PLXS_IDLE) + { + // Get the address of the environment + struct plxs_env_tag *p_plxs_env = PRF_ENV_GET(PLXS, plxs); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t att_idx = plxs_handle2att(p_param->handle); + uint8_t status = ATT_ERR_NO_ERROR; + + // Send data to peer device + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, + dest_id, gattc_read_cfm, sizeof(uint16_t)); + + switch(att_idx) + { + case PLXS_IDX_SPOT_MEASUREMENT_CCC: + { + // CCC for Spot-Measurement + co_write16p(p_cfm->value, p_plxs_env->prfl_ind_cfg_spot[conidx]); + } break; + + case PLXS_IDX_CONT_MEASUREMENT_CCC: + { + // CCC for Cont-Measurement + co_write16p(p_cfm->value, p_plxs_env->prfl_ind_cfg_cont[conidx]); + } break; + + case PLXS_IDX_RACP_CCC: + { + // CCC for RACP + co_write16p(p_cfm->value, p_plxs_env->prfl_ind_cfg_racp[conidx]); + } break; + + default: + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + // Fill data + p_cfm->length = sizeof(uint16_t); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t att_idx = plxs_handle2att(p_param->handle); + struct gattc_att_info_cfm *p_cfm; + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + switch(att_idx) + { + case PLXS_IDX_SPOT_MEASUREMENT_CCC: + case PLXS_IDX_CONT_MEASUREMENT_CCC: + case PLXS_IDX_RACP_CCC: + { + // check if it's a client configuration char + // CCC attribute length = 2 + p_cfm->length = sizeof(uint16_t); + p_cfm->status = GAP_ERR_NO_ERROR; + } break; + + case PLXS_IDX_RACP_VAL: + { + // control point + p_cfm->length = 4; + p_cfm->status = GAP_ERR_NO_ERROR; + } break; + + default: + { + // not expected request + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } break; + } + + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + // Message status + int msg_status = KE_MSG_CONSUMED; + + do + { + // Get the address of the environment + struct plxs_env_tag *p_plxs_env = PRF_ENV_GET(PLXS, plxs); + + // Check the connection handle + if (p_plxs_env == NULL) + { + break; + } + + // check that task is in idle state + if (ke_state_get(dest_id) == PLXS_IDLE) + { + // Status + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t att_idx = plxs_handle2att(p_param->handle); + uint8_t conidx = KE_IDX_GET(src_id); + struct gattc_write_cfm *p_cfm; + + switch(att_idx) + { + case PLXS_IDX_SPOT_MEASUREMENT_CCC: + case PLXS_IDX_CONT_MEASUREMENT_CCC: + case PLXS_IDX_RACP_CCC: + { + uint16_t ntf_cfg; + // Inform the HL about the new configuration + struct plxs_wr_char_ccc_ind *p_ind = KE_MSG_ALLOC(PLXS_WR_CHAR_CCC_IND, + prf_dst_task_get(&p_plxs_env->prf_env, conidx), + prf_src_task_get(&p_plxs_env->prf_env, conidx), + plxs_wr_char_ccc_ind); + + // Get the value + co_write16p(&ntf_cfg, p_param->value[0]); + + switch(att_idx) + { + case PLXS_IDX_SPOT_MEASUREMENT_CCC: + { + // CCC for Spot-Measurement + p_ind->char_type = PLXS_SPOT_CHECK_MEAS_CODE; + p_plxs_env->prfl_ind_cfg_spot[conidx] = ntf_cfg; + } break; + + case PLXS_IDX_CONT_MEASUREMENT_CCC: + { + // CCC for Cont-Measurement + p_ind->char_type = PLXS_CONTINUOUS_MEAS_CODE; + p_plxs_env->prfl_ind_cfg_cont[conidx] = ntf_cfg; + } break; + + case PLXS_IDX_RACP_CCC: + { + // CCC for RACP + p_ind->char_type = PLXS_RACP_CODE; + p_plxs_env->prfl_ind_cfg_racp[conidx] = ntf_cfg; + } break; + + default: + { + + } break; + } + + p_ind->ind_cfg = ntf_cfg; + + ke_msg_send(p_ind); + } break; + + case PLXS_IDX_RACP_VAL: + { + // if command to RACP and RACP is not configured for indication + // or Command to report Records and SPOT_MEAS CCC is not configured for indication + if (((p_plxs_env->prfl_ind_cfg_racp[conidx] & PRF_CLI_START_IND) != PRF_CLI_START_IND) || + (( p_param->value[0] == PLXP_OPCODE_REPORT_STORED_RECORDS) && + ((p_plxs_env->prfl_ind_cfg_spot[conidx] & PRF_CLI_START_IND) != PRF_CLI_START_IND))) + { + // CPP improperly configured + status = PRF_CCCD_IMPR_CONFIGURED; + } + else if ((p_plxs_env->racp_in_progress[conidx]) && (p_param->value[0] != PLXP_OPCODE_ABORT_OPERATION)) + { + // procedure already in progress + status = PRF_PROC_IN_PROGRESS; + } + // Check it is the valid request + else if ((( p_param->value[0] >= PLXP_OPCODE_REPORT_STORED_RECORDS) && + (p_param->value[0] <= PLXP_OPCODE_REPORT_NUMBER_OF_STORED_RECORDS)) && + (((p_param->value[0] != PLXP_OPCODE_ABORT_OPERATION) && + (p_param->value[1] == PLXP_OPERATOR_ALL_RECORDS)) || + ((p_param->value[0] == PLXP_OPCODE_ABORT_OPERATION) && + (p_param->value[1] == PLXP_OPERATOR_NULL))) + ) + { + // Inform the HL about the new Control Point Command + struct plxs_wr_racp_ind *p_ind = KE_MSG_ALLOC(PLXS_WR_RACP_IND, + prf_dst_task_get(&p_plxs_env->prf_env, conidx), + prf_src_task_get(&p_plxs_env->prf_env, conidx), + plxs_wr_racp_ind); + + // Get the value + p_ind->cp_opcode = p_param->value[0]; + p_ind->cp_operator = p_param->value[1]; + + ke_msg_send(p_ind); + // set flag that procedure is started + p_plxs_env->racp_in_progress[conidx] = true; + } + else + { + //error condition + uint8_t response_code = PLXP_RESP_INVALID_OPERATOR; + + if ((p_param->value[0]==0) || + (p_param->value[0]>PLXP_OPCODE_REPORT_NUMBER_OF_STORED_RECORDS)) + { + // incorrect opcode + response_code = PLXP_RESP_OP_CODE_NOT_SUPPORTED; + } + else if ((p_param->value[0] != PLXP_OPCODE_ABORT_OPERATION) && + (p_param->value[1] > PLXP_OPERATOR_ALL_RECORDS)) + { + response_code = PLXP_RESP_OPERATOR_NOT_SUPPORTED; + } + else // if ((p_param->value[0] != PLXP_OPCODE_ABORT_OPERATION) && + // (p_param->value[1] == PLXP_OPERATOR_NULL)) + { + response_code = PLXP_RESP_INVALID_OPERATOR; + } + + // procedure complete + p_plxs_env->racp_in_progress[conidx] = 0; + plxs_racp_resp_send(src_id, dest_id, PLXP_OPCODE_RESPONSE_CODE, + p_param->value[0], response_code, 0); + + // special state as we don't need response to the server + ke_state_set(dest_id, PLXS_OP_INDICATE_RACP_NO_CMP); + } + } break; + + default: + { + // not expected request + status = ATT_ERR_WRITE_NOT_PERMITTED; + } break; + } + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + else + { + msg_status = KE_MSG_SAVED; + } + + } while (0); + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles @see GATT_NOTIFY_CMP_EVT message meaning that an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + do + { + // Get the address of the environment + struct plxs_env_tag *p_plxs_env = PRF_ENV_GET(PLXS, plxs); + + if (p_plxs_env == NULL) + { + break; + } + + // Check if a connection exists + switch (p_param->operation) + { + case (GATTC_NOTIFY): + case (GATTC_INDICATE): + { + uint8_t state = ke_state_get(dest_id); + + // Spot-Measurement sent or RACP sent + // Inform the application that a procedure has been completed + if ((state == PLXS_OP_INDICATE_MEAS) || + (state == PLXS_OP_INDICATE_RACP) || (state == PLXS_OP_NOTIFY)) + { + uint8_t conidx = KE_IDX_GET(src_id); + // Send a command complete to the App indicate msg could not be sent. + struct plxs_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(PLXS_CMP_EVT, + prf_dst_task_get(&p_plxs_env->prf_env, conidx), + prf_src_task_get(&p_plxs_env->prf_env, conidx), + plxs_cmp_evt); + + if (state == PLXS_OP_NOTIFY) + { + // Continuous Measurement sent + p_cmp_evt->operation = PLXS_CONTINUOUS_MEAS_CMD_OP_CODE; + } + else + { + // Indication is Spot-Meas Record or RACP + p_cmp_evt->operation = (state == PLXS_OP_INDICATE_MEAS ? + PLXS_SPOT_CHECK_MEAS_CMD_OP_CODE : PLXS_RACP_CMD_OP_CODE); + } + p_cmp_evt->status = p_param->status; + + ke_msg_send(p_cmp_evt); + + // go to idle state + ke_state_set(dest_id, PLXS_IDLE); + } + else if (state == PLXS_OP_INDICATE_RACP_NO_CMP ) + { + // go to idle state + ke_state_set(dest_id, PLXS_IDLE); + } + } break; + // else ignore the message + default: + { + ASSERT_ERR(0); + } break; + } + + } while (0); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see PLXS_MEAS_VALUE_CMD message. + * @brief Send MEASUREMENT INDICATION/NOTIFICATION to the connected peer case if CCC enabled + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int plxs_meas_value_cmd_handler(ke_msg_id_t const msgid, + struct plxs_meas_value_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + + // check that task is in idle state + if (ke_state_get(dest_id) == PLXS_IDLE) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ind; + // = p_plxs_env->shdl + PLXS_IDX_PRU_ALERT_VAL; + uint16_t handle; + // data pointer + uint8_t *p_data; + uint8_t status = ATT_ERR_NO_ERROR; + uint16_t length; + // Connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct plxs_env_tag *p_plxs_env = PRF_ENV_GET(PLXS, plxs); + + switch (p_param->operation) + { + case PLXS_CONTINUOUS_MEAS_CMD_OP_CODE: + { + if ((p_plxs_env->prfl_ind_cfg_cont[conidx] & PRF_CLI_START_NTF) + && (p_plxs_env->optype != PLXS_OPTYPE_SPOT_CHECK_ONLY)) + { + handle = plxs_att2handle(PLXS_IDX_CONT_MEASUREMENT_VAL); + // Flags-1oct SpO2PR-Normal-4oct + length = 5; + + // check the sup_feat vs Flags settings + // mask off unsupported features + if (!GETB(p_plxs_env->sup_feat, PLXP_FEAT_SPO2PR_FAST_SUP)) + { + SETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_SPO2PR_FAST, 0); + } + if (!GETB(p_plxs_env->sup_feat, PLXP_FEAT_SPO2PR_SLOW_SUP)) + { + SETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_SPO2PR_SLOW, 0); + } + if (!GETB(p_plxs_env->sup_feat, PLXP_FEAT_MEAS_STATUS_SUP)) + { + SETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_MEAS_STATUS, 0); + } + if (!GETB(p_plxs_env->sup_feat, PLXP_FEAT_DEV_SENSOR_STATUS_SUP)) + { + SETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_DEV_SENSOR_STATUS, 0); + } + if (!GETB(p_plxs_env->sup_feat, PLXP_FEAT_PULSE_AMPL_SUP)) + { + SETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_PULSE_AMPL, 0); + } + // allow only valid flags + p_param->value.cont_meas.cont_flags &= PLXP_CONT_MEAS_FLAGS_VALID_MASK; + + // calculate size of data record + if (GETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_SPO2PR_FAST)) + { + length += 4; // SpO2PR-Fast-4oct + } + if (GETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_SPO2PR_SLOW)) + { + length += 4; // SpO2PR-Slow-4oct + } + if (GETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_MEAS_STATUS)) + { + length += 2; // Measurement Status + } + if (GETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_DEV_SENSOR_STATUS)) + { + length += 3; // Device & Sensor Status + } + if (GETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_PULSE_AMPL)) + { + length += 2; // Pulse Amplitude Index + } + + // Allocate the GATT notification message + p_ind = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + gattc_send_evt_cmd, length); + + // Fill in the p_parameter structure + p_ind->operation = GATTC_NOTIFY; + p_ind->handle = handle; + p_ind->length = length; + // fill data + p_ind->value[0] = p_param->value.cont_meas.cont_flags; + p_data = &(p_ind->value[1]); + co_write16p(p_data,p_param->value.cont_meas.normal.sp_o2); + p_data +=2; + co_write16p(p_data,p_param->value.cont_meas.normal.pr); + p_data +=2; + + if (GETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_SPO2PR_FAST)) + { + // SpO2PR-Fast-4oct + co_write16p(p_data,p_param->value.cont_meas.fast.sp_o2); + p_data +=2; + co_write16p(p_data,p_param->value.cont_meas.fast.pr); + p_data +=2; + } + if (GETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_SPO2PR_SLOW)) + { + // SpO2PR-Slow-4oct + co_write16p(p_data,p_param->value.cont_meas.slow.sp_o2); + p_data +=2; + co_write16p(p_data,p_param->value.cont_meas.slow.pr); + p_data +=2; + } + if (GETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_MEAS_STATUS)) + { + // If bit of the Measurement Status field is not supported in the Feature, + // it shall always be set to 0 in its characteristic field + p_param->value.cont_meas.meas_stat &= p_plxs_env->meas_stat_sup; + + // Measurement Status + co_write16p(p_data,p_param->value.cont_meas.meas_stat); + p_data +=2; + } + if (GETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_DEV_SENSOR_STATUS)) + { + // If bit of the Device and Sensor Status field is not supported in the Feature, + // it shall always be set to 0 in its characteristic field + p_param->value.cont_meas.dev_sensor_stat &= p_plxs_env->dev_stat_sup; + + // Device & Sensor Status + co_write24p(p_data,p_param->value.cont_meas.dev_sensor_stat); + p_data +=3; + } + if (GETB(p_param->value.cont_meas.cont_flags, PLXP_CONT_MEAS_FLAGS_PULSE_AMPL)) + { + // Pulse Amplitude Index + co_write16p(p_data,p_param->value.cont_meas.pulse_ampl); + p_data +=2; + } + + // send notification to peer device + ke_msg_send(p_ind); + + // go to busy state + ke_state_set(dest_id, PLXS_OP_NOTIFY); + } + else + { + status = PRF_ERR_IND_DISABLED; + } + } break; + + case PLXS_SPOT_CHECK_MEAS_CMD_OP_CODE: + { + if ((p_plxs_env->prfl_ind_cfg_spot[conidx] & PRF_CLI_START_IND) && + (p_plxs_env->optype != PLXS_OPTYPE_CONTINUOUS_ONLY)) + { + handle = plxs_att2handle(PLXS_IDX_SPOT_MEASUREMENT_VAL); + length = 5; // Flags-1oct SpO2PR-Spot-Check-4oct + // check the sup_feat vs Flags settings + // mask off unsupported features + if (!GETB(p_plxs_env->sup_feat, PLXP_FEAT_TIMESTAMP_SUP)) + { + SETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_TIMESTAMP, 0); + } + if (!GETB(p_plxs_env->sup_feat, PLXP_FEAT_MEAS_STATUS_SUP)) + { + SETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_MEAS_STATUS, 0); + } + if (!GETB(p_plxs_env->sup_feat, PLXP_FEAT_DEV_SENSOR_STATUS_SUP)) + { + SETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_DEV_SENSOR_STATUS, 0); + } + if (!GETB(p_plxs_env->sup_feat, PLXP_FEAT_PULSE_AMPL_SUP)) + { + SETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_PULSE_AMPLITUDE, 0); + } + + // allow only valid flags + p_param->value.spot_meas.spot_flags &= PLXP_SPOT_MEAS_FLAGS_VALID_MASK; + + // calculate size of data record + if (GETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_TIMESTAMP)) + { + length += 7; // Timestamp + } + if (GETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_MEAS_STATUS)) + { + length += 2; // Measurement Status + } + if (GETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_DEV_SENSOR_STATUS)) + { + length += 3; // Device & Sensor Status + } + if (GETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_PULSE_AMPLITUDE)) + { + length += 2; // Pulse Amplitude Index + } + + // Allocate the GATT notification message + p_ind = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + gattc_send_evt_cmd, length); + + // Fill in the p_parameter structure + p_ind->operation = GATTC_INDICATE; + p_ind->handle = handle; + p_ind->length = length; + // fill data + p_ind->value[0] = p_param->value.spot_meas.spot_flags; + p_data = &(p_ind->value[1]); + co_write16p(p_data,p_param->value.spot_meas.sp_o2); + p_data +=2; + co_write16p(p_data,p_param->value.spot_meas.pr); + p_data +=2; + + if (GETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_TIMESTAMP)) + { + // Timestamp-7oct + p_data +=prf_pack_date_time(p_data, &p_param->value.spot_meas.timestamp); + } + if (GETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_MEAS_STATUS)) + { + // If bit of the Measurement Status field is not supported in the Feature, + // it shall always be set to 0 in its characteristic field + p_param->value.spot_meas.meas_stat &= p_plxs_env->meas_stat_sup; + + // Measurement Status + co_write16p(p_data, p_param->value.spot_meas.meas_stat); + p_data +=2; + } + if (GETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_DEV_SENSOR_STATUS)) + { + // If bit of the Device and Sensor Status field is not supported in the Feature, + // it shall always be set to 0 in its characteristic field + p_param->value.spot_meas.dev_sensor_stat &= p_plxs_env->dev_stat_sup; + + // Device & Sensor Status + co_write24p(p_data,p_param->value.spot_meas.dev_sensor_stat); + p_data +=3; + } + if (GETB(p_param->value.spot_meas.spot_flags, PLXP_SPOT_MEAS_FLAGS_PULSE_AMPLITUDE)) + { + // Pulse Amplitude Index + co_write16p(p_data,p_param->value.spot_meas.pulse_ampl); + p_data +=2; + } + + // send notification to peer device + ke_msg_send(p_ind); + + // go to busy state + ke_state_set(dest_id, PLXS_OP_INDICATE_MEAS); + } + else + { + status = PRF_ERR_IND_DISABLED; + } + } break; + + default: + { + status = PRF_ERR_IND_DISABLED; + } break; + } + + // in error case immediately send response to HL + if (status != ATT_ERR_NO_ERROR) + { + // Send a command complete to the App indicate msg could not be sent. + struct plxs_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(PLXS_CMP_EVT, + src_id, + dest_id, plxs_cmp_evt); + + p_cmp_evt->operation = p_param->operation; + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + } + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @see PLXS_RACP_RESP_CMD message. + * @brief Send MEASUREMENT INDICATION to the connected peer case if CCC enabled + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int plxs_racp_resp_cmd_handler(ke_msg_id_t const msgid, + struct plxs_racp_resp_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + + // check that task is in idle state + if (ke_state_get(dest_id) == PLXS_IDLE) + { + uint8_t status = ATT_ERR_NO_ERROR; + + switch (p_param->operation) + { + case PLXS_RACP_CMD_OP_CODE: + { + // Connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct plxs_env_tag *p_plxs_env = PRF_ENV_GET(PLXS, plxs); + + if ((p_plxs_env->prfl_ind_cfg_racp[conidx] & PRF_CLI_START_IND) && + (p_plxs_env->optype != PLXS_OPTYPE_CONTINUOUS_ONLY)) + { + // procedure complete + p_plxs_env->racp_in_progress[conidx] = 0; + plxs_racp_resp_send(KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + p_param->cp_opcode, + p_param->req_cp_opcode, + p_param->rsp_code, + p_param->rec_num); + + // go to busy state + ke_state_set(dest_id, PLXS_OP_INDICATE_RACP); + } + else + { + status = PRF_ERR_IND_DISABLED; + } + } break; + + default: + { + status = PRF_ERR_IND_DISABLED; + } break; + } + + // in error case immediately send response to HL + if (status != ATT_ERR_NO_ERROR) + { + // Send a command complete to the App indicate msg could not be sent. + struct plxs_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(PLXS_CMP_EVT, + src_id, + dest_id, plxs_cmp_evt); + + p_cmp_evt->operation = p_param->operation; + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + } + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(plxs) +{ + {PLXS_ENABLE_REQ, (ke_msg_func_t) plxs_enable_req_handler}, + {PLXS_MEAS_VALUE_CMD, (ke_msg_func_t) plxs_meas_value_cmd_handler}, + {PLXS_RACP_RESP_CMD, (ke_msg_func_t) plxs_racp_resp_cmd_handler}, + + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +void plxs_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct plxs_env_tag *p_plxs_env = PRF_ENV_GET(PLXS, plxs); + + p_task_desc->msg_handler_tab = plxs_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(plxs_msg_handler_tab); + p_task_desc->state = p_plxs_env->state; + p_task_desc->idx_max = PLXS_IDX_MAX; +} + +#endif //(BLE_PLX_SERVER) + +/// @} PLXSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prf.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prf.c new file mode 100644 index 0000000..639b6da --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prf.c @@ -0,0 +1,395 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file prf.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +/** + **************************************************************************************** + * @addtogroup PRF + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include +#include "rwip_config.h" + +#if (BLE_PROFILES) +#include "rwip.h" +#include "prf.h" +#include "att.h" + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * MACROS + **************************************************************************************** + */ + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ +struct prf_env_tag prf_env; +struct prf_get_itf_tag get_itf; +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve profile interface + **************************************************************************************** + */ +static const struct prf_task_cbs * prf_itf_get(uint16_t task_id) +{ + const struct prf_task_cbs* prf_cbs = NULL; + + uint16_t task_type = KE_TYPE_GET(task_id); + for(uint8_t id = 0; id < get_itf.prf_num;id++) + { + //find the prf task id + if(task_type == get_itf.get_func_list[id].task_id ) + { + //found prf + prf_cbs = get_itf.get_func_list[id].prf_itf_get_func(); + } + } + + return prf_cbs; +} + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ +void prf_init(uint8_t init_type) +{ + uint8_t i; + + if(init_type == RWIP_INIT) + { + get_itf.prf_num = 0; + } + + for(i = 0; i < BLE_NB_PROFILES ; i++) + { + switch (init_type) + { + case RWIP_INIT: + { + // FW boot profile initialization + prf_env.prf[i].task = TASK_GAPC + i +1; + ke_task_delete(prf_env.prf[i].task); //TODO CHECK + ke_task_create(prf_env.prf[i].task, &(prf_env.prf[i].desc)); + } + break; + + case RWIP_RST: + { + // FW boot profile destruction + // Get Profile API + const struct prf_task_cbs * cbs = prf_itf_get(prf_env.prf[i].id); + + if(cbs != NULL) + { + // request to destroy profile + cbs->destroy(&(prf_env.prf[i])); + } + // Request kernel to flush task messages + ke_task_msg_flush(KE_TYPE_GET(prf_env.prf[i].task)); + } + // No break + + case RWIP_1ST_RST: + { + // FW boot profile destruction + prf_env.prf[i].env = NULL; + // unregister profile + prf_env.prf[i].id = TASK_ID_INVALID; + prf_env.prf[i].desc.msg_handler_tab = NULL; + prf_env.prf[i].desc.state = NULL; + prf_env.prf[i].desc.idx_max = 0; + prf_env.prf[i].desc.msg_cnt = 0; + } + break; + + default: + { + // Do nothing + } + break; + } + } +} + + +uint8_t prf_add_profile(struct gapm_profile_task_add_cmd * params, ke_task_id_t* prf_task) +{ + uint8_t i; + uint8_t status = GAP_ERR_NO_ERROR; + + // retrieve profile callback + const struct prf_task_cbs * cbs = prf_itf_get(params->prf_task_id); + if(cbs == NULL) + { + // profile API not available + status = GAP_ERR_INVALID_PARAM; + } + + // check if profile not already present in task list + if(status == GAP_ERR_NO_ERROR) + { + for(i = 0; i < BLE_NB_PROFILES ; i++) + { + if(prf_env.prf[i].id == params->prf_task_id) + { + status = GAP_ERR_NOT_SUPPORTED; + break; + } + } + } + + if(status == GAP_ERR_NO_ERROR) + { + // find first available task + for(i = 0; i < BLE_NB_PROFILES ; i++) + { + // available task found + if(prf_env.prf[i].id == TASK_ID_INVALID) + { + // initialize profile + status = cbs->init(&(prf_env.prf[i]), &(params->start_hdl), params->app_task, params->sec_lvl, params->param); + + // initialization succeed + if(status == GAP_ERR_NO_ERROR) + { + // register profile + prf_env.prf[i].id = params->prf_task_id; + *prf_task = prf_env.prf[i].task; + } + break; + } + } + + if(i == BLE_NB_PROFILES) + { + status = GAP_ERR_INSUFF_RESOURCES; + } + } + + return (status); +} + + + +void prf_create(uint8_t conidx) +{ + uint8_t i; + /* simple connection creation handler, nothing to do. */ + + // execute create function of each profiles + for(i = 0; i < BLE_NB_PROFILES ; i++) + { + // Get Profile API + const struct prf_task_cbs * cbs = prf_itf_get(prf_env.prf[i].id); + if(cbs != NULL) + { + // call create callback + cbs->create(&(prf_env.prf[i]), conidx); + } + } +} + + +void prf_cleanup(uint8_t conidx, uint8_t reason) +{ + uint8_t i; + /* simple connection creation handler, nothing to do. */ + + // execute create function of each profiles + for(i = 0; i < BLE_NB_PROFILES ; i++) + { + // Get Profile API + const struct prf_task_cbs * cbs = prf_itf_get(prf_env.prf[i].id); + if(cbs != NULL) + { + // call cleanup callback + cbs->cleanup(&(prf_env.prf[i]), conidx, reason); + } + } +} + + +prf_env_t* prf_env_get(uint16_t prf_id) +{ + prf_env_t* env = NULL; + uint8_t i; + // find if profile present in profile tasks + for(i = 0; i < BLE_NB_PROFILES ; i++) + { + // check if profile identifier is known + if(prf_env.prf[i].id == prf_id) + { + env = prf_env.prf[i].env; + break; + } + } + + return env; +} + +ke_task_id_t prf_src_task_get(prf_env_t* env, uint8_t conidx) +{ + ke_task_id_t task = PERM_GET(env->prf_task, PRF_TASK); + + if(PERM_GET(env->prf_task, PRF_MI)) + { + task = KE_BUILD_ID(task, conidx); + } + + return task; +} + +ke_task_id_t prf_dst_task_get(prf_env_t* env, uint8_t conidx) +{ + ke_task_id_t task = PERM_GET(env->app_task, PRF_TASK); + + if(PERM_GET(env->app_task, PRF_MI)) + { + task = KE_BUILD_ID(task, conidx); + } + + return task; +} + + +ke_task_id_t prf_get_id_from_task(ke_msg_id_t task) +{ + ke_task_id_t id = TASK_ID_INVALID; + uint8_t idx = KE_IDX_GET(task); + uint8_t i; + task = KE_TYPE_GET(task); + + // find if profile present in profile tasks + for(i = 0; i < BLE_NB_PROFILES ; i++) + { + // check if profile identifier is known + if(prf_env.prf[i].task == task) + { + id = prf_env.prf[i].id; + break; + } + } + + return KE_BUILD_ID(id, idx); +} + +ke_task_id_t prf_get_task_from_id(ke_msg_id_t id) +{ + ke_task_id_t task = TASK_NONE; + uint8_t idx = KE_IDX_GET(id); + uint8_t i; + id = KE_TYPE_GET(id); + + // find if profile present in profile tasks + for(i = 0; i < BLE_NB_PROFILES ; i++) + { + // check if profile identifier is known + if(prf_env.prf[i].id == id) + { + task = prf_env.prf[i].task; + break; + } + } + + return KE_BUILD_ID(task, idx); +} + + +bool prf_get_itf_func_register(struct prf_get_func_t *prf) +{ + if(get_itf.prf_num < BLE_NB_PROFILES) + { + //add profile to list + memcpy(&get_itf.get_func_list[get_itf.prf_num], + prf,sizeof(struct prf_get_func_t)); + get_itf.prf_num++; + return true; + } + + return false; +} + + +#endif // (BLE_PROFILES) + +/// @} PRF diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prf_utils.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prf_utils.c new file mode 100644 index 0000000..bb5f56f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prf_utils.c @@ -0,0 +1,556 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file prf_utils.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +/** + **************************************************************************************** + * @addtogroup PRF_UTILS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_PROFILES) +#if (BLE_SERVER_PRF || BLE_CLIENT_PRF) + +#include +#include +#include "ke_task.h" +#include "attm.h" +#include "gattc_task.h" +#include "prf_utils.h" +#include "gap.h" +#include "gapc.h" + +#include "ke_mem.h" +#include "co_utils.h" +#include "co_error.h" + +#endif /* (BLE_SERVER_PRF || BLE_CLIENT_PRF) */ + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +#if (BLE_BATT_SERVER) +void prf_pack_char_pres_fmt(uint8_t *packed_val, const struct prf_char_pres_fmt* char_pres_fmt) +{ + *packed_val = char_pres_fmt->format; + *(packed_val + 1) = char_pres_fmt->exponent; + co_write16p(packed_val + 2, char_pres_fmt->unit); + *(packed_val + 4) = char_pres_fmt->name_space; + co_write16p(packed_val + 5, char_pres_fmt->description); +} +#endif // (BLE_BATT_SERVER) + +#if (BLE_BATT_CLIENT) +void prf_unpack_char_pres_fmt(const uint8_t *packed_val, struct prf_char_pres_fmt* char_pres_fmt) +{ + + char_pres_fmt->format = *packed_val; + char_pres_fmt->exponent = *(packed_val + 1); + char_pres_fmt->unit = co_read16p(packed_val + 2); + char_pres_fmt->name_space = *(packed_val + 4); + char_pres_fmt->description = co_read16p(packed_val + 5); +} +#endif // (BLE_BATT_CLIENT) + + +#if (BLE_CLIENT_PRF) +void prf_read_char_send(prf_env_t *prf_env, uint8_t conidx, + uint16_t shdl, uint16_t ehdl, uint16_t valhdl) +{ + struct gattc_read_cmd * req = KE_MSG_ALLOC(GATTC_READ_CMD, KE_BUILD_ID(TASK_GATTC, conidx), + prf_src_task_get(prf_env, conidx), gattc_read_cmd); + //request type + req->operation = GATTC_READ; + req->nb = 1; + req->req.simple.offset = 0; + req->req.simple.length = 0; + req->req.simple.handle = valhdl; + + //send request to GATT + ke_msg_send(req); +} + +void prf_register_atthdl2gatt(prf_env_t *prf_env, uint8_t conidx, struct prf_svc *svc) +{ + if(svc->shdl != ATT_INVALID_HANDLE) + { + //register profile task in gatt for indication/notifications + struct gattc_reg_to_peer_evt_cmd * reg = KE_MSG_ALLOC(GATTC_REG_TO_PEER_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), prf_src_task_get(prf_env, conidx), + gattc_reg_to_peer_evt_cmd); + + reg->operation = GATTC_REGISTER; + reg->start_hdl = svc->shdl; + reg->end_hdl = svc->ehdl; + + ke_msg_send(reg); + } +} + +void prf_unregister_atthdl2gatt(prf_env_t *prf_env, uint8_t conidx, struct prf_svc *svc) +{ + if(svc->shdl != ATT_INVALID_HANDLE) + { + //un register profile task in gatt for indication/notifications + struct gattc_reg_to_peer_evt_cmd * reg = KE_MSG_ALLOC(GATTC_REG_TO_PEER_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), prf_src_task_get(prf_env, conidx), + gattc_reg_to_peer_evt_cmd); + + reg->operation = GATTC_UNREGISTER; + reg->start_hdl = svc->shdl; + reg->end_hdl = svc->ehdl; + + ke_msg_send(reg); + } +} + +void prf_search_descs(uint8_t nb_descs, + struct prf_char_desc_inf* descs, const struct prf_char_desc_def* descs_req, + const struct gattc_disc_char_desc_ind* param, + uint8_t last_char_code) +{ + //Counters + uint8_t cursor; + + //Retrieve characteristic descriptor handle using UUID + for(cursor = 0; cursoruuid, param->uuid_len, descs_req[cursor].uuid)) + &&attm_uuid_comp((uint8_t*)param->uuid, param->uuid_len, (uint8_t*)&descs_req[cursor].uuid, param->uuid_len) + && (descs[cursor].desc_hdl == ATT_INVALID_HANDLE)) + { + descs[cursor].desc_hdl = param->attr_hdl; + } + } +} + +void prf_disc_svc_send(prf_env_t *prf_env, uint8_t conidx, uint16_t uuid) +{ + //send GATT discover primary services by UUID request + struct gattc_sdp_svc_disc_cmd * svc_req = KE_MSG_ALLOC_DYN(GATTC_SDP_SVC_DISC_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), prf_src_task_get(prf_env, conidx), + gattc_sdp_svc_disc_cmd, ATT_UUID_16_LEN); + + //gatt request type: by UUID + svc_req->operation = GATTC_SDP_DISC_SVC; + //start handle; + svc_req->start_hdl = ATT_1ST_REQ_START_HDL; + //end handle + svc_req->end_hdl = ATT_1ST_REQ_END_HDL; + + // UUID search + svc_req->uuid_len = ATT_UUID_16_LEN; + + //set the first two bytes to the value array, LSB to MSB:Health Thermometer Service UUID first + co_write16p(&(svc_req->uuid[0]), uuid); + + //send the message to GATT, which will send back the response when it gets it + ke_msg_send(svc_req); +} + + + +void prf_gatt_write(prf_env_t *prf_env, uint8_t conidx, + uint16_t handle, uint8_t* value, uint16_t length, uint8_t operation) +{ + if(handle != ATT_INVALID_HANDLE) + { + struct gattc_write_cmd *wr_char = KE_MSG_ALLOC_DYN(GATTC_WRITE_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), prf_src_task_get(prf_env, conidx), + gattc_write_cmd, length); + + // Offset + wr_char->offset = 0x0000; + // cursor always 0 + wr_char->cursor = 0x0000; + // Write Type + wr_char->operation = operation; + // Characteristic Value attribute handle + wr_char->handle = handle; + // Value Length + wr_char->length = length; + // Auto Execute + wr_char->auto_execute = true; + // Value + memcpy(&wr_char->value[0], value, length); + + // Send the message + ke_msg_send(wr_char); + } +} + +void prf_gatt_write_ntf_ind(prf_env_t *prf_env, uint8_t conidx, uint16_t handle, uint16_t ntf_ind_cfg) +{ + uint8_t value[2]; + + // put value in air format + co_write16p((&value[0]), ntf_ind_cfg); + // write value over GATT + prf_gatt_write(prf_env, conidx, handle, value, 2, GATTC_WRITE); +} + +uint8_t prf_check_svc_char_validity(uint8_t nb_chars, + const struct prf_char_inf* chars, + const struct prf_char_def* chars_req) +{ + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t i; + + for(i = 0; ((i < nb_chars) && (status == GAP_ERR_NO_ERROR)); i++) + { + if (chars[i].char_hdl == ATT_INVALID_HANDLE) + { + //If Characteristic is not present, check requirements + if (chars_req[i].req_flag == ATT_MANDATORY) + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + } + else + { + //If Characteristic is present, check properties + if((chars[i].prop & chars_req[i].prop_mand) != chars_req[i].prop_mand) + { + status = PRF_ERR_STOP_DISC_WRONG_CHAR_PROP; + } + } + } + + return (status); +} + +void prf_disc_char_all_send( prf_env_t *env, struct prf_svc *svc, uint8_t conidx) +{ + struct gattc_disc_cmd * char_req = KE_MSG_ALLOC_DYN(GATTC_DISC_CMD, + KE_BUILD_ID(TASK_GATTC, conidx),prf_src_task_get( env ,conidx), + gattc_disc_cmd, ATT_UUID_16_LEN); + + char_req->operation = GATTC_DISC_ALL_CHAR; + char_req->start_hdl = svc->shdl; + char_req->end_hdl = svc->ehdl; + + // UUID info - Don't care + char_req->uuid_len = ATT_UUID_16_LEN; + //set the first two bytes to the value array, LSB to MSB:Health Thermometer Service UUID first + co_write16p(&(char_req->uuid[0]), ATT_INVALID_UUID); + + //send the message to GATT, which will send back the response when it gets it + ke_msg_send(char_req); +} + + +void prf_disc_char_desc_send(prf_env_t *env, struct prf_char_inf * charact, uint8_t conidx) +{ + // Check if there is at least one descriptor to find + if ((charact->val_hdl + 1) <= (charact->char_hdl + charact->char_ehdl_off - 1)) + { + + // Ask for handles of a certain uuid + struct gattc_disc_cmd * dsc_req = KE_MSG_ALLOC_DYN(GATTC_DISC_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), prf_src_task_get( env ,conidx), + gattc_disc_cmd, ATT_UUID_16_LEN); + + dsc_req->operation = GATTC_DISC_DESC_CHAR; + dsc_req->start_hdl = charact->val_hdl + 1; + dsc_req->end_hdl = charact->char_hdl + charact->char_ehdl_off - 1; + + // UUID info - Don't care + dsc_req->uuid_len = ATT_UUID_16_LEN; + //set the first two bytes to the value array, LSB to MSB:Health Thermometer Service UUID first + co_write16p(&(dsc_req->uuid[0]), ATT_INVALID_UUID); + + //send the message to GATT;there should be only one handle response every time + ke_msg_send(dsc_req); + } + else + { + + // Send a GATT complete event message + struct gattc_cmp_evt *evt = KE_MSG_ALLOC(GATTC_CMP_EVT, prf_src_task_get( env ,conidx), + KE_BUILD_ID(TASK_GATTC , conidx), + gattc_cmp_evt); + + evt->status = ATT_ERR_NO_ERROR; + + // Send the message + ke_msg_send(evt); + } +} + +uint8_t prf_check_svc_char_desc_validity(uint8_t descs_size, + const struct prf_char_desc_inf* descs, + const struct prf_char_desc_def* descs_req, + const struct prf_char_inf* chars) +{ + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t i; + + for(i = 0; ((i < descs_size) && (status == GAP_ERR_NO_ERROR)) ; i++) + { + if (descs[i].desc_hdl == ATT_INVALID_HANDLE) + { + //If Descriptor is missing, check if it is mandatory + if (descs_req[i].req_flag == ATT_MANDATORY) + { + //Check if Char is present + if (chars[descs_req[i].char_code].char_hdl != ATT_INVALID_HANDLE) + { + //Char. is present and descriptor not, error + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + } + } + } + + return (status); +} + +void prf_extract_svc_info(const struct gattc_sdp_svc_ind* param, + uint8_t nb_chars, const struct prf_char_def* chars_req, struct prf_char_inf* chars, + uint8_t nb_descs, const struct prf_char_desc_def* descs_req, struct prf_char_desc_inf* descs) +{ + //Counters + uint8_t svc_char; + uint8_t svc_desc; + uint8_t fnd_att; + + for (fnd_att=0; fnd_att< (param->end_hdl - param->start_hdl); fnd_att++) + { + if(param->info[fnd_att].att_type == GATTC_SDP_ATT_CHAR) + { + uint16_t char_hdl = param->start_hdl+ 1 + fnd_att; + uint16_t val_hdl = param->info[fnd_att].att_char.handle; + uint8_t val_prop = param->info[fnd_att].att_char.prop; + uint8_t char_idx = fnd_att; + + // check that value handle is in a valid range + if((val_hdl <= param->end_hdl) && (val_hdl > (param->start_hdl + fnd_att))) + { + // retrieve value index + uint8_t val_idx = (val_hdl - param->start_hdl - 1); + + //Look over requested characteristics + for (svc_char=0; svc_charinfo[val_idx].att.uuid, + param->info[val_idx].att.uuid_len, chars_req[svc_char].uuid)) + { + //Save properties and handles + chars[svc_char].char_hdl = char_hdl; + chars[svc_char].val_hdl = val_hdl; + chars[svc_char].prop = val_prop; + + // find end of characteristic handle and discover descriptors + do + { + fnd_att++; + + // found a descriptor + if(param->info[fnd_att].att_type == GATTC_SDP_ATT_DESC) + { + //Retrieve characteristic descriptor handle using UUID + for(svc_desc = 0; svc_descinfo[fnd_att].att.uuid, + param->info[fnd_att].att.uuid_len, descs_req[svc_desc].uuid))) + { + descs[svc_desc].desc_hdl = param->start_hdl + 1 + fnd_att; + // search for next descriptor + break; + } + } + } + } while(((param->start_hdl+ 1 + fnd_att) <= param->end_hdl) + && (param->info[fnd_att].att_type != GATTC_SDP_ATT_CHAR) + && (param->info[fnd_att].att_type != GATTC_SDP_INC_SVC)); + + // return to previous valid value + fnd_att--; + // previous handle was end of the characteristic + chars[svc_char].char_ehdl_off = fnd_att - char_idx; + + // search next characteristic + break; + } + } + } + } + } +} + + +#endif //(BLE_CLIENT_PRF) + +#if (BLE_CLIENT_PRF || BLE_TIP_SERVER || BLE_AN_SERVER || BLE_PAS_SERVER) + +void prf_client_att_info_rsp(prf_env_t *prf_env, uint8_t conidx, uint16_t msg_id, + uint8_t status, struct gattc_read_ind const* read_ind) +{ + // retrieve value length + uint16_t length = 0; + if(status == GAP_ERR_NO_ERROR) + { + length = read_ind->length; + } + + // prepare response + struct prf_att_info *rsp = KE_MSG_ALLOC_DYN(msg_id, + prf_dst_task_get(prf_env, conidx), prf_src_task_get(prf_env, conidx), + prf_att_info, length); + + rsp->status = status; + rsp->handle = ATT_INVALID_HDL; + rsp->length = length; + + // set value array + if (read_ind != NULL) + { + rsp->handle = read_ind->handle; + memcpy(&(rsp->value[0]), &(read_ind->value[0]), length); + } + + ke_msg_send(rsp); +} +#endif //(BLE_CLIENT_PRF || BLE_TIP_SERVER || BLE_AN_SERVER || BLE_PAS_SERVER) + + +#if ((BLE_SERVER_PRF || BLE_CLIENT_PRF)) + +uint8_t prf_pack_date_time(uint8_t *packed_date, const struct prf_date_time* date_time) +{ + co_write16p(packed_date, date_time->year); + *(packed_date + 2) = date_time->month; + *(packed_date + 3) = date_time->day; + *(packed_date + 4) = date_time->hour; + *(packed_date + 5) = date_time->min; + *(packed_date + 6) = date_time->sec; + + return 7; +} +uint8_t prf_unpack_date_time(uint8_t *packed_date, struct prf_date_time* date_time) +{ + date_time->year = co_read16p(&(packed_date[0])); + date_time->month = packed_date[2]; + date_time->day = packed_date[3]; + date_time->hour = packed_date[4]; + date_time->min = packed_date[5]; + date_time->sec = packed_date[6]; + + return 7; +} + +#if ((BLE_CGM_SERVER || BLE_CGM_CLIENT)) +uint16_t prf_e2e_crc(const uint8_t * buf, uint16_t length) +{ + uint16_t crc_reg = 0xffff; // initial seed + uint8_t reg; + uint16_t crc; + int i, j; + + for(i=0; i < length; i++) + { + reg = *buf++; + for(j=0; j<8; j++) + { + if ((reg & 1) != ((crc_reg>>15)& 1)) + { + crc_reg <<= 1; + crc_reg ^= (uint16_t)(1<<12) | (1<<5) | (1<<0); + } + else + { + crc_reg <<= 1; + } + reg >>= 1; + } + } + + crc = 0; + // result is in the order bits:->8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 + for(j=0; j<8; j++) + { + crc >>= 1; + crc |= crc_reg & ((1<<15) | (1<<7)); + crc_reg <<= 1; + } + return crc; +} +#endif /* ((BLE_CGM_SERVER || BLE_CGM_CLIENT)) */ + +#endif /* ((BLE_SERVER_PRF || BLE_CLIENT_PRF)) */ +#endif // (BLE_PROFILES) +/// @} PRF_UTILS + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prf_utils_128.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prf_utils_128.c new file mode 100644 index 0000000..b5c1ed6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prf_utils_128.c @@ -0,0 +1,309 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file prf_utils_128.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + **************************************************************************************** + * @addtogroup PRF_UTILS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_CLIENT_PRF) +#include +#include +#include "ke_task.h" +#include "co_error.h" +#include "gattc_task.h" +#include "prf_utils_128.h" +#include "ke_mem.h" +#include "gap.h" +#include "gapc.h" +#include "prf.h" +#endif //(BLE_CLIENT_PRF) + +#if (BLE_CLIENT_PRF) + +void prf_search_chars_128(uint16_t svc_ehdl, uint8_t nb_chars, + struct prf_char_inf* chars, const struct prf_char_def_128* chars_req, + const struct gattc_disc_char_ind* param, + uint8_t* last_found_char) +{ + //Counters + uint8_t cursor; + + //Look over requested characteristics + for (cursor=0; cursoruuid, param->uuid_len, (uint8_t*)chars_req[cursor].uuid, ATT_UUID_128_LEN)) + { + //Save properties and handles + chars[cursor].char_hdl = param->attr_hdl; + chars[cursor].val_hdl = param->pointer_hdl; + chars[cursor].prop = param->prop; + + //Compute number of attribute in Char. using SVC edhl - Limited to 255 + chars[cursor].char_ehdl_off = (uint8_t)(svc_ehdl - chars[cursor].char_hdl + 1); + + if (cursor != *last_found_char) + { + //Update number of attributes for the last found char. + chars[*last_found_char].char_ehdl_off = + (uint8_t)(chars[cursor].char_hdl - chars[*last_found_char].char_hdl); + } + + //Save code of the Char. which has been found. + *last_found_char = cursor; + } + + } +} + +void prf_disc_svc_send_128(prf_env_t *env, uint8_t *uuid_128, uint8_t conidx) +{ + //send GATT discover primary services by UUID request: find by type request + struct gattc_disc_cmd * svc_req = KE_MSG_ALLOC_DYN(GATTC_DISC_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + KE_BUILD_ID(env->prf_task, 0), + gattc_disc_cmd, + ATT_UUID_128_LEN); + + //gatt request type: by UUID + svc_req->operation = GATTC_DISC_BY_UUID_SVC; + //start handle; + svc_req->start_hdl = ATT_1ST_REQ_START_HDL; + //end handle + svc_req->end_hdl = ATT_1ST_REQ_END_HDL; + + // UUID search + svc_req->uuid_len = ATT_UUID_128_LEN; + + svc_req->seq_num = 0; + + // set 128 bit UUID for searching + memcpy(&svc_req->uuid[0], uuid_128, (sizeof(uint8_t) * ATT_UUID_128_LEN)); + + //send the message to GATT, which will send back the response when it gets it + ke_msg_send(svc_req); +} + +uint8_t prf_check_svc_char_validity_128(uint8_t nb_chars, + const struct prf_char_inf* chars, + const struct prf_char_def_128* chars_req) +{ + uint8_t status = ATT_ERR_NO_ERROR; + uint8_t i; + + for(i = 0; ((i < nb_chars) && (status == ATT_ERR_NO_ERROR)); i++) + { + if (chars[i].char_hdl == ATT_INVALID_HANDLE) + { + //If Characteristic is not present, check requirements + if (chars_req[i].req_flag == ATT_MANDATORY) + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + } + else + { + //If Characteristic is present, check properties + if((chars[i].prop & chars_req[i].prop_mand) != chars_req[i].prop_mand) + { + status = PRF_ERR_STOP_DISC_WRONG_CHAR_PROP; + } + } + } + + return status; +} + +void prf_disc_svc_sdp_send_128(prf_env_t *prf_env, uint8_t conidx,const uint8_t* uuid_128) +{ + //send GATT discover primary services by UUID request + struct gattc_sdp_svc_disc_cmd * svc_req = KE_MSG_ALLOC(GATTC_SDP_SVC_DISC_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + prf_src_task_get(prf_env, conidx), + gattc_sdp_svc_disc_cmd); + + //gatt request type: by UUID + svc_req->operation = GATTC_SDP_DISC_SVC; + //start handle; + svc_req->start_hdl = ATT_1ST_REQ_START_HDL; + //end handle + svc_req->end_hdl = ATT_1ST_REQ_END_HDL; + + // UUID search + svc_req->uuid_len = ATT_UUID_128_LEN; + + //set the first two bytes to the value array, LSB to MSB + memcpy(svc_req->uuid, uuid_128, sizeof(uint8_t) * ATT_UUID_128_LEN); + + //send the message to GATT, which will send back the response when it gets it + ke_msg_send(svc_req); +} + +void prf_disc_char_by_uuid_128_send(prf_env_t *prf_env, uint8_t conidx, const uint8_t *uuid_128) +{ + //send GATT discover primary services by UUID request: find by type request + struct gattc_disc_cmd * svc_req = KE_MSG_ALLOC_DYN(GATTC_DISC_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + prf_src_task_get(prf_env, conidx), + gattc_disc_cmd, + ATT_UUID_128_LEN); + + //gatt request type: by UUID + svc_req->operation = GATTC_DISC_BY_UUID_CHAR; + //start handle; + svc_req->start_hdl = ATT_1ST_REQ_START_HDL; + //end handle + svc_req->end_hdl = ATT_1ST_REQ_END_HDL; + + // UUID search + svc_req->uuid_len = ATT_UUID_128_LEN; + + // set 128 bit UUID for searching + memcpy(&svc_req->uuid[0], uuid_128, (sizeof(uint8_t) * ATT_UUID_128_LEN)); + + //send the message to GATT, which will send back the response when it gets it + ke_msg_send(svc_req); +} + +void prf_extract_svc_sdp_info_128(const struct gattc_sdp_svc_ind *param, + uint8_t nb_chars, + const struct prf_char_def_128* chars_req, + struct prf_char_inf* chars, + uint8_t nb_descs, + const struct prf_char_desc_def* descs_req, + struct prf_char_desc_inf* descs) +{ + //Counters + uint8_t svc_char; + uint8_t svc_desc; + uint8_t fnd_att; + + for (fnd_att=0; fnd_att< (param->end_hdl - param->start_hdl); fnd_att++) + { + if(param->info[fnd_att].att_type == GATTC_SDP_ATT_CHAR) + { + uint16_t char_hdl = param->start_hdl+ 1 + fnd_att; + uint16_t val_hdl = param->info[fnd_att].att_char.handle; + uint8_t char_idx = fnd_att; + + // check that value handle is in a valid range + if((val_hdl <= param->end_hdl) && (val_hdl > (param->start_hdl + fnd_att))) + { + // retrieve value index + uint8_t val_idx = (val_hdl - param->start_hdl - 1); + //Look over requested characteristics + for (svc_char=0; svc_char < nb_chars ; svc_char++) + { + // check if attribute is valid + if((chars[svc_char].char_hdl == ATT_INVALID_HDL) && + attm_uuid_comp((uint8_t*)param->info[val_idx].att.uuid, param->info[val_idx].att.uuid_len, + (uint8_t*)chars_req[svc_char].uuid, ATT_UUID_128_LEN)) + { + //Save properties and handles + chars[svc_char].char_hdl = char_hdl; + chars[svc_char].val_hdl = val_hdl; + chars[svc_char].prop = param->info[fnd_att].att_char.prop;; + + // find end of characteristic handle and discover descriptors + do + { + fnd_att++; + // found a descriptor + if(param->info[fnd_att].att_type == GATTC_SDP_ATT_DESC) + { + //Retrieve characteristic descriptor handle using UUID + for(svc_desc = 0; svc_desc < nb_descs; svc_desc++) + { + // check if it's expected descriptor + if ((descs[svc_desc].desc_hdl == ATT_INVALID_HANDLE) + && (descs_req[svc_desc].char_code == svc_char) + && (attm_uuid16_comp((uint8_t*)param->info[fnd_att].att.uuid, + param->info[fnd_att].att.uuid_len, descs_req[svc_desc].uuid))) + { + descs[svc_desc].desc_hdl = param->start_hdl + 1 + fnd_att; + // search for next descriptor + break; + } + } + } + }while(((param->start_hdl+ 1 + fnd_att) <= param->end_hdl) + && (param->info[fnd_att].att_type != GATTC_SDP_ATT_CHAR) + && (param->info[fnd_att].att_type != GATTC_SDP_INC_SVC)); + // return to previous valid value + fnd_att--; + // previous handle was end of the characteristic + chars[svc_char].char_ehdl_off = fnd_att - char_idx; + + // search next characteristic + break; + } + } + } + } + } +} + +#endif /*BLE_CLIENT_PRF */ + +/// @} PRF_UTILS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/api/proxm_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/api/proxm_task.h new file mode 100644 index 0000000..410b22b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/api/proxm_task.h @@ -0,0 +1,176 @@ +/** + **************************************************************************************** + * + * @file proxm_task.h + * + * @brief Header file - PROXMTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef PROXM_TASK_H_ +#define PROXM_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup PROXMTASK Proximity Monitor Task + * @ingroup PROXM + * @brief Proximity Monitor Task + * + * The Proximity Monitor Task is responsible for handling the API messages received from + * either the Application or internal tasks. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Max number of characteristics for all services +#define PROXM_CHAR_NB_MAX 1 + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Proximity Monitor API messages +/*@TRACE*/ +enum proxm_msg_id +{ + /// Proximity Monitor role enable request from application. + PROXM_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_PROXM), + /// Proximity Monitor role enable confirmation to application. + PROXM_ENABLE_RSP, + + /// Read LLS Alert or TX Power Level - request + PROXM_RD_CMD, + /// Read LLS Alert or TX Power Level - response + PROXM_RD_IND, + + /// Set Alert level + PROXM_WR_ALERT_LVL_CMD, + + /// Complete Event Information + PROXM_CMP_EVT, +}; + +enum +{ + PROXM_LK_LOSS_SVC, + PROXM_IAS_SVC, + PROXM_TX_POWER_SVC, + + PROXM_SVC_NB +}; + +/// Operation codes +enum proxm_op_codes +{ + /// Database Creation Procedure + PROXM_RESERVED_OP_CODE = 0, + /// Read Operation Code + PROXM_RD_OP_CODE = 1, + /// Set Alert Level Operation Code + PROXM_WR_ALERT_LVL_OP_CODE = 2, +}; + +// + +/* + * API Messages Structures + **************************************************************************************** + */ + +/// Service information +struct svc_content +{ + /// Service info + struct prf_svc svc; + + /// Characteristic info: + /// - Alert Level for IAS and LLS + /// - TX Power Level for TXPS + struct prf_char_inf characts[PROXM_CHAR_NB_MAX]; +}; + +/// Proximity monitor enable command structure +struct proxm_enable_req +{ + /// Connection type + uint8_t con_type; + + /// Reporter LLS details kept in APP + struct svc_content lls; + /// Reporter IAS details kept in APP + struct svc_content ias; + /// Reporter TPS details kept in APP + struct svc_content txps; +}; + +/// Proximity monitor enable confirm structure +struct proxm_enable_rsp +{ + /// Status + uint8_t status; + + /// Reporter LLS details to keep in APP + struct svc_content lls; + /// Reporter IAS details to keep in APP + struct svc_content ias; + /// Reporter TPS details to keep in APP + struct svc_content txps; +}; + +/// Parameters of the @ref PROXM_WR_ALERT_LVL_CMD message +struct proxm_wr_alert_lvl_cmd +{ + /// 0=LLS or 1=IAS, code for the service in which the alert level should be written + uint8_t svc_code; + /// Alert level + uint8_t lvl; +}; + +/// Parameters of the @ref PROXM_RD_CMD message +struct proxm_rd_cmd +{ + /// 0=LLS or 1=TXPS, code for the service in which the alert level should be read @see enum proxm_rd_char_code + uint8_t svc_code; +}; + +/// Parameters of the @ref PROXM_RD_IND message +struct proxm_rd_ind +{ + /// 0=LLS or 1=TXPS, code for the service in which the alert level should be read + uint8_t svc_code; + /// Value + uint8_t value; +}; + +/// Parameters of the @ref PROXM_CMP_EVT message +struct proxm_cmp_evt +{ + /// Operation + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} PROXMTASK + +#endif // PROXM_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/sourcelist.txt new file mode 100644 index 0000000..ad78cf5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + proxm.c + proxm_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/src/proxm.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/src/proxm.c new file mode 100644 index 0000000..db103f0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/src/proxm.c @@ -0,0 +1,252 @@ +/** + **************************************************************************************** + * + * @file proxm.c + * + * @brief Proximity monitor implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup PROXM + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_PROX_MONITOR) + +#include "proxm.h" +#include "proxm_task.h" +#include "prf_utils.h" +#include "gap.h" + +#include "ke_mem.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Initialization of the PROXM module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t proxm_init (struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct proxm_env_tag *p_proxm_env = + (struct proxm_env_tag *) ke_malloc(sizeof(struct proxm_env_tag), KE_MEM_ATT_DB); + + // allocate PROXM required environment variable + p_env->env = (prf_env_t *) p_proxm_env; + + p_proxm_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_proxm_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_PROXM; + proxm_task_init(&(p_env->desc)); + + for (idx = 0; idx < PROXM_IDX_MAX; idx++) + { + p_proxm_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), PROXM_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Destruction of the PROXM module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void proxm_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct proxm_env_tag *p_proxm_env = (struct proxm_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < PROXM_IDX_MAX; idx++) + { + if (p_proxm_env->p_env[idx] != NULL) + { + ke_free(p_proxm_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_proxm_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void proxm_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put PROX Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), PROXM_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void proxm_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct proxm_env_tag *p_proxm_env = (struct proxm_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_proxm_env->p_env[conidx] != NULL) + { + ke_free(p_proxm_env->p_env[conidx]); + p_proxm_env->p_env[conidx] = NULL; + } + + // Put PROX Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), PROXM_FREE); +} +/* +* GLOBAL VARIABLE DEFINITIONS +**************************************************************************************** +*/ + +/// PROXM Task interface required by profile manager +const struct prf_task_cbs proxm_itf = +{ + (prf_init_fnct) proxm_init, + proxm_destroy, + proxm_create, + proxm_cleanup, +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *proxm_prf_itf_get(void) +{ + return &proxm_itf; +} + +void proxm_enable_rsp_send(struct proxm_env_tag *p_proxm_env, uint8_t conidx, uint8_t status) +{ + // format response to app + struct proxm_enable_rsp *p_cfm = KE_MSG_ALLOC(PROXM_ENABLE_RSP, + prf_dst_task_get(&(p_proxm_env->prf_env), conidx), + prf_src_task_get(&(p_proxm_env->prf_env), conidx), + proxm_enable_rsp); + + p_cfm->lls = p_proxm_env->p_env[conidx]->prox[PROXM_LK_LOSS_SVC]; + p_cfm->ias = p_proxm_env->p_env[conidx]->prox[PROXM_IAS_SVC]; + p_cfm->txps = p_proxm_env->p_env[conidx]->prox[PROXM_TX_POWER_SVC]; + p_cfm->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + // Go to IDLE state + ke_state_set(prf_src_task_get(&(p_proxm_env->prf_env), conidx), PROXM_IDLE); + } + else + { + // clean-up environment variable allocated for task instance + ke_free(p_proxm_env->p_env[conidx]); + p_proxm_env->p_env[conidx] = NULL; + } + + ke_msg_send(p_cfm); +} + +uint8_t proxm_validate_request(struct proxm_env_tag *p_proxm_env, uint8_t conidx, uint8_t char_code) +{ + uint8_t status = GAP_ERR_NO_ERROR; + + // check if feature val characteristic exists + if (p_proxm_env->p_env[conidx]->prox[char_code].characts[0].val_hdl == ATT_INVALID_HANDLE) + { + status = PRF_ERR_INEXISTENT_HDL; + } + + return (status); +} + +void proxm_send_cmp_evt(struct proxm_env_tag *p_proxm_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct proxm_cmp_evt *p_evt; + ke_task_id_t src_id = prf_src_task_get(&(p_proxm_env->prf_env), conidx); + ke_task_id_t dest_id = prf_dst_task_get(&(p_proxm_env->prf_env), conidx); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == PROXM_BUSY) + { + ke_state_set(src_id, PROXM_IDLE); + } + + // Send the message to the application + p_evt = KE_MSG_ALLOC(PROXM_CMP_EVT, dest_id, src_id, proxm_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + + +#endif //BLE_PROX_MONITOR + +/// @} PROXM diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/src/proxm.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/src/proxm.h new file mode 100644 index 0000000..01e2b22 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/src/proxm.h @@ -0,0 +1,256 @@ +/** + **************************************************************************************** + * + * @file proxm.h + * + * @brief Header file - PROXM. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef PROXM_H_ +#define PROXM_H_ + +/** + **************************************************************************************** + * @addtogroup PROX Proximity Profile + * @ingroup PROFILE + * @brief Proximity Profile + * + * The PROX module is the responsible block for implementing the proximity profile + * functionalities in the BLE Host. + * + * The Proximity Profile defines the functionality required in a device that can + * alert the user when the user's personal device moves further away or closer together + * to another communicating device. + ***************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup PROXM Proximity Monitor + * @ingroup PROX + * @brief Proximity Profile Monitor + * + * The PROXM is responsible for providing proximity profile monitor functionalities to + * upper layer module or application. The device using this profile takes the role + * of a proximity monitor role. + * + * Proximity Monitor (PM): A PM (e.g. PC, phone, electronic door entry system, etc) + * is the term used by this profile to describe a device that monitors the distance + * between itself and the connected PR device. The profile on the PM device constantly + * monitors the path loss between itself and the communicating Proximity Reporter + * device. The profile provides indications to an application which can cause an alert + * to the user. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_PROX_MONITOR) + +#include "proxm_task.h" +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Proximity Monitor task instances +#define PROXM_IDX_MAX (BLE_CONNECTION_MAX) + + +/* + * ENUMERATIONS + **************************************************************************************** + */ +/// Possible states of the PROXM task +enum proxm_state +{ + /// FREE state + PROXM_FREE, + /// IDLE state + PROXM_IDLE, + /// Busy state + PROXM_BUSY, + /// Discovering + PROXM_DISCOVERING, + + /// Number of defined states. + PROXM_STATE_MAX +}; + + +/// Characteristics Link loss +enum +{ + PROXM_LK_LOSS_CHAR, + + PROXM_LK_LOSS_CHAR_MAX, +}; + +/// Characteristics IAS +enum +{ + PROXM_IAS_CHAR, + + PROXM_IAS_CHAR_MAX, +}; + +/// Characteristics Tx power +enum +{ + PROXM_TX_POWER_CHAR, + + PROXM_TX_POWER_CHAR_MAX, +}; + +/// Max characteristic number on services +enum +{ + PROXM_SVCS_CHAR_NB = 1 +}; + +/// Link Loss or Immediate Alert code for setting alert through one message +enum +{ + /// Code for LLS Alert Level Char. + PROXM_SET_LK_LOSS_ALERT = 0x00, + /// Code for IAS Alert Level Char. + PROXM_SET_IMMDT_ALERT, +}; + +/// Read Characteristic Code +enum proxm_rd_char_code +{ + /// Read Link Loss Service Alert Level Characteristic Value + PROXM_RD_LL_ALERT_LVL = 0x00, + /// Read TX Power Service TX Power Level Characteristic Value + PROXM_RD_TX_POWER_LVL, +}; + +///Alert Level Values +enum +{ + PROXM_ALERT_NONE = 0x00, + PROXM_ALERT_MILD, + PROXM_ALERT_HIGH, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + + +/// Proximity Monitor environment variable per connection +struct proxm_cnx_env +{ + /// Last service for which something was discovered + uint8_t last_svc_req; + /// counter used to check service uniqueness + uint8_t nb_svc; + /// used to store if measurement context + uint8_t meas_ctx_en; + + struct svc_content prox[PROXM_SVC_NB]; +}; + +/// Proximity monitor environment variable +struct proxm_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct proxm_cnx_env *p_env[PROXM_IDX_MAX]; + /// State of different task instances + ke_state_t state[PROXM_IDX_MAX]; +}; + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve Proximity service profile interface + * + * @return Proximity service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *proxm_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send enable confirmation to application. + * + * @param p_proxm_env Proximity Monitor Role task environment + * @param conidx Connection index + * @param status Status of the enable: either OK or error encountered while discovery. + **************************************************************************************** + */ +void proxm_enable_rsp_send(struct proxm_env_tag *p_proxm_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Check if collector request is possible or not + * + * @param[in] p_proxm_env Client environment. + * @param[in] conidx Connection Index. + * @param[in] char_code Characteristic number. + * + * @return GAP_ERR_NO_ERROR if request can be performed, error code else. + **************************************************************************************** + */ +uint8_t proxm_validate_request(struct proxm_env_tag *p_proxm_env, uint8_t conidx, uint8_t char_code); + +/** + **************************************************************************************** + * @brief Send an PROXM_CMP_EVT message to a requester. + * + * @param[in] p_proxm_env Proximity Monitor environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void proxm_send_cmp_evt(struct proxm_env_tag *p_proxm_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void proxm_task_init(struct ke_task_desc *p_task_desc); + +#endif //BLE_PROX_MONITOR + +/// @} PROXM + +#endif // PROXM_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/src/proxm_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/src/proxm_task.c new file mode 100644 index 0000000..2e89e8a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxm/src/proxm_task.c @@ -0,0 +1,519 @@ +/** + **************************************************************************************** + * + * @file proxm_task.c + * + * @brief Proximity Monitor Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup PROXMTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_PROX_MONITOR) +#include "co_utils.h" + +#include "gap.h" +#include "gapc.h" +#include "proxm_task.h" +#include "proxm.h" +#include "gattc_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +#include "ke_mem.h" + +/// State machine used to retrieve services characteristics information +const struct prf_char_def proxm_svc_char[PROXM_SVC_NB][PROXM_SVCS_CHAR_NB] = +{ + [PROXM_LK_LOSS_SVC] = {{ATT_CHAR_ALERT_LEVEL, + ATT_MANDATORY, + ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR}}, + + [PROXM_IAS_SVC] = {{ATT_CHAR_ALERT_LEVEL, + ATT_MANDATORY, + ATT_CHAR_PROP_WR_NO_RESP}}, + + [PROXM_TX_POWER_SVC] = {{ATT_CHAR_TX_POWER_LEVEL, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}} +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Enable the Proximity Monitor role, used after connection. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int proxm_enable_req_handler(ke_msg_id_t const msgid, + struct proxm_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Proximity Monitor Environment + struct proxm_env_tag *p_proxm_env = PRF_ENV_GET(PROXM, proxm); + + ASSERT_INFO(p_proxm_env != NULL, dest_id, src_id); + if ((state == PROXM_IDLE) && (p_proxm_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_proxm_env->p_env[conidx] = (struct proxm_cnx_env *) ke_malloc(sizeof(struct proxm_cnx_env), KE_MEM_ATT_DB); + memset(p_proxm_env->p_env[conidx], 0, sizeof(struct proxm_cnx_env)); + + if (p_param->con_type == PRF_CON_DISCOVERY) + { + p_proxm_env->p_env[conidx]->last_svc_req = PROXM_LK_LOSS_SVC; + prf_disc_svc_send(&(p_proxm_env->prf_env), conidx, ATT_SVC_LINK_LOSS); + + // Go to DISCOVERING state + ke_state_set(dest_id, PROXM_DISCOVERING); + } + else + { + p_proxm_env->p_env[conidx]->prox[PROXM_LK_LOSS_SVC] = p_param->lls; + p_proxm_env->p_env[conidx]->prox[PROXM_IAS_SVC] = p_param->ias; + p_proxm_env->p_env[conidx]->prox[PROXM_TX_POWER_SVC] = p_param->txps; + + // send APP confirmation that can start normal connection to TH + proxm_enable_rsp_send(p_proxm_env, conidx, GAP_ERR_NO_ERROR); + } + + } + else if (state != PROXM_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + proxm_enable_rsp_send(p_proxm_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref PROXM_RD_CMD message. + * Request to read the LLS alert level. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int proxm_rd_cmd_handler(ke_msg_id_t const msgid, + struct proxm_rd_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == PROXM_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t status = GAP_ERR_NO_ERROR; + struct proxm_env_tag *p_proxm_env = PRF_ENV_GET(PROXM, proxm); + + ASSERT_INFO(p_proxm_env != NULL, dest_id, src_id); + + // environment variable not ready + if (p_proxm_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + uint8_t current_svc = PROXM_SVC_NB; + + // Get the request type and handle value for this type of write + switch (p_param->svc_code) + { + case PROXM_RD_LL_ALERT_LVL: + { + current_svc = PROXM_LK_LOSS_SVC; + status = proxm_validate_request(p_proxm_env, conidx, PROXM_LK_LOSS_SVC); + } break; + + case PROXM_RD_TX_POWER_LVL: + { + current_svc = PROXM_TX_POWER_SVC; + status = proxm_validate_request(p_proxm_env, conidx, PROXM_TX_POWER_SVC); + } break; + + default: + { + current_svc = PROXM_SVC_NB; + status = PRF_ERR_INVALID_PARAM; + } break; + } + + if (status == GAP_ERR_NO_ERROR) + { + prf_read_char_send(&(p_proxm_env->prf_env), conidx, + p_proxm_env->p_env[conidx]->prox[current_svc].characts[0].char_hdl, + p_proxm_env->p_env[conidx]->prox[current_svc].characts[0].char_ehdl_off, + p_proxm_env->p_env[conidx]->prox[current_svc].characts[0].val_hdl); + + // wait for end of read request + p_proxm_env->p_env[conidx]->last_svc_req = p_param->svc_code; + + ke_state_set(dest_id, PROXM_BUSY); + } + } + + // request cannot be performed + if (status != GAP_ERR_NO_ERROR) + { + proxm_send_cmp_evt(p_proxm_env, conidx, PROXM_RD_OP_CODE, status); + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref PROXM_WR_ALERT_LVL_CMD message. + * Request to write either the LLS or IAS alert levels. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int proxm_wr_alert_lvl_cmd_handler(ke_msg_id_t const msgid, + struct proxm_wr_alert_lvl_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == PROXM_IDLE) + { + struct proxm_env_tag *p_proxm_env = PRF_ENV_GET(PROXM, proxm); + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_proxm_env != NULL, dest_id, src_id); + + // environment variable not ready + if (p_proxm_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Alert level only has 3 values, other not useful + if (p_param->lvl <= PROXM_ALERT_HIGH) + { + uint16_t val_hdl = 0x0000; + uint8_t operation = 0x00; + + // Get the request type and handle value for this type of write + switch (p_param->svc_code) + { + case PROXM_SET_LK_LOSS_ALERT: + { + operation = GATTC_WRITE; + val_hdl = p_proxm_env->p_env[conidx]->prox[PROXM_LK_LOSS_SVC].characts[0].val_hdl; + } break; + + case PROXM_SET_IMMDT_ALERT: + { + operation = GATTC_WRITE_NO_RESPONSE; + val_hdl = p_proxm_env->p_env[conidx]->prox[PROXM_IAS_SVC].characts[0].val_hdl; + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + if (status == GAP_ERR_NO_ERROR) + { + // Send GATT Write Request + prf_gatt_write(&(p_proxm_env->prf_env), conidx, val_hdl, (uint8_t *)&p_param->lvl, + sizeof(uint8_t), operation); + + // wait for end of write request + ke_state_set(dest_id, PROXM_BUSY); + } + } + else + { + //wrong level - not one of the possible 3 + status = PRF_ERR_INVALID_PARAM; + } + } + // An error occurs, send the response with error status + if (status != GAP_ERR_NO_ERROR) + { + proxm_send_cmp_evt(p_proxm_env, conidx, PROXM_WR_ALERT_LVL_OP_CODE, status); + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == PROXM_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + uint16_t current_svc = PROXM_SVC_NB; + const struct prf_char_def *p_current_char_def; + + struct proxm_env_tag *p_proxm_env = PRF_ENV_GET(PROXM, proxm); + + ASSERT_INFO(p_proxm_env != NULL, dest_id, src_id); + ASSERT_INFO(p_proxm_env->p_env[conidx] != NULL, dest_id, src_id); + + // check if a valid service is found + if (attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_LINK_LOSS)) + { + current_svc = PROXM_LK_LOSS_SVC; + p_current_char_def = &proxm_svc_char[PROXM_LK_LOSS_SVC][PROXM_LK_LOSS_CHAR]; + } + else if (attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_IMMEDIATE_ALERT)) + { + current_svc = PROXM_IAS_SVC; + p_current_char_def = &proxm_svc_char[PROXM_IAS_SVC][PROXM_IAS_CHAR]; + } + else if (attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_TX_POWER)) + { + current_svc = PROXM_TX_POWER_SVC; + p_current_char_def = &proxm_svc_char[PROXM_TX_POWER_SVC][PROXM_TX_POWER_CHAR]; + } + + // if a valid service found, put it into environment variable + if (current_svc != PROXM_SVC_NB) + { + prf_extract_svc_info(p_ind, PROXM_CHAR_NB_MAX, p_current_char_def, + p_proxm_env->p_env[conidx]->prox[current_svc].characts, 0, NULL, NULL); + + p_proxm_env->p_env[conidx]->prox[current_svc].svc.shdl = p_ind->start_hdl; + p_proxm_env->p_env[conidx]->prox[current_svc].svc.ehdl = p_ind->end_hdl; + + p_proxm_env->p_env[conidx]->nb_svc++; + } + } + + return (KE_MSG_CONSUMED); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Get the address of the environment + struct proxm_env_tag *p_proxm_env = PRF_ENV_GET(PROXM, proxm); + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == PROXM_DISCOVERING) + { + uint8_t status = prf_check_svc_char_validity(PROXM_SVCS_CHAR_NB, + p_proxm_env->p_env[conidx]->prox[p_proxm_env->p_env[conidx]->last_svc_req].characts, + proxm_svc_char[p_proxm_env->p_env[conidx]->last_svc_req]); + + // Too many services found only one such service should exist + if (p_proxm_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // if an error append, send confirmation with error status and stop discovering + if (status != GAP_ERR_NO_ERROR) + { + proxm_enable_rsp_send(p_proxm_env, conidx, status); + } + // if a valid service found, discover and then send confirmation message + else + { + uint16_t current_att_svc = ATT_INVALID_UUID; + + p_proxm_env->p_env[conidx]->nb_svc = 0; + p_proxm_env->p_env[conidx]->last_svc_req += 1; + + if ((p_proxm_env->p_env[conidx]->last_svc_req) < PROXM_SVC_NB) + { + switch (p_proxm_env->p_env[conidx]->last_svc_req) + { + case PROXM_LK_LOSS_SVC: + { + current_att_svc = ATT_SVC_LINK_LOSS; + } break; + + case PROXM_IAS_SVC: + { + current_att_svc = ATT_SVC_IMMEDIATE_ALERT; + } break; + + case PROXM_TX_POWER_SVC: + { + current_att_svc = ATT_SVC_TX_POWER; + } break; + + default: + { + + } break; + } + + prf_disc_svc_send(&(p_proxm_env->prf_env), conidx, current_att_svc); + } + else + { + proxm_enable_rsp_send(p_proxm_env, conidx, GAP_ERR_NO_ERROR); + } + } + } + else if (state == PROXM_BUSY) + { + switch (p_param->operation) + { + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + proxm_send_cmp_evt(p_proxm_env, conidx, PROXM_WR_ALERT_LVL_OP_CODE, p_param->status); + } break; + + case GATTC_READ: + { + proxm_send_cmp_evt(p_proxm_env, conidx, PROXM_RD_OP_CODE, p_param->status); + } break; + + default: + { + + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == PROXM_BUSY) + { + struct proxm_env_tag *p_proxm_env = PRF_ENV_GET(PROXM, proxm); + uint8_t conidx = KE_IDX_GET(dest_id); + struct proxm_rd_ind *p_ind; + + ASSERT_INFO(p_proxm_env != NULL, dest_id, src_id); + ASSERT_INFO(p_proxm_env->p_env[conidx] != NULL, dest_id, src_id); + + p_ind = KE_MSG_ALLOC(PROXM_RD_IND, + prf_dst_task_get(&(p_proxm_env->prf_env), conidx), + dest_id, + proxm_rd_ind); + + p_ind->svc_code = p_proxm_env->p_env[conidx]->last_svc_req; + p_ind->value = p_param->value[0]; + ke_msg_send(p_ind); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(proxm) +{ + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {PROXM_ENABLE_REQ, (ke_msg_func_t)proxm_enable_req_handler}, + {PROXM_WR_ALERT_LVL_CMD, (ke_msg_func_t)proxm_wr_alert_lvl_cmd_handler}, + {PROXM_RD_CMD, (ke_msg_func_t)proxm_rd_cmd_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void proxm_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct proxm_env_tag *p_proxm_env = PRF_ENV_GET(PROXM, proxm); + + p_task_desc->msg_handler_tab = proxm_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(proxm_msg_handler_tab); + p_task_desc->state = p_proxm_env->state; + p_task_desc->idx_max = PROXM_IDX_MAX; +} + +#endif //BLE_PROX_MONITOR + +/// @} PROXMTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/api/proxr_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/api/proxr_task.h new file mode 100644 index 0000000..2242084 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/api/proxr_task.h @@ -0,0 +1,100 @@ +/** + **************************************************************************************** + * + * @file proxr_task.h + * + * @brief Header file - PROXRTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef PROXR_TASK_H_ +#define PROXR_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup PROXRTASK Proximity Reporter Task + * @ingroup PROXR + * @brief Proximity Reporter Task + * + * The PROXRTASK is responsible for handling the APi messages from the Application or internal + * tasks. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Proximity reporter feature bit field +enum proxr_feature +{ + /// immediate alert and TX Power services are not present + PROXR_IAS_TXPS_NOT_SUP = 0, + /// immediate alert and TX Power services are present + PROXR_IAS_TXPS_SUP, +}; + +/// Messages for Proximity Reporter +/*@TRACE*/ +enum proxr_msg_id +{ + /// LLS/IAS Alert Level Indication + PROXR_ALERT_IND = TASK_FIRST_MSG(TASK_ID_PROXR), +}; + +/// Characteristics Code for Write Indications +enum +{ + PROXR_ERR_CHAR, + PROXR_LLS_CHAR, + PROXR_IAS_CHAR, +}; + + +/* + * API MESSAGES STRUCTURES + **************************************************************************************** + */ +/// Parameters of the Proximity service database +struct proxr_db_cfg +{ + /// Proximity Feature (@see enum proxr_feature) + uint16_t features; +}; + + +/// Parameters of the @ref PROXR_ALERT_IND message +struct proxr_alert_ind +{ + /// Connection index + uint8_t conidx; + /// Alert level + uint8_t alert_lvl; + /// Char Code - Indicate if LLS or IAS + uint8_t char_code; +}; + + +/// @} PROXRTASK + +#endif // PROXR_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/sourcelist.txt new file mode 100644 index 0000000..ac99f8b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + proxr.c + proxr_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/src/proxr.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/src/proxr.c new file mode 100644 index 0000000..30222c8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/src/proxr.c @@ -0,0 +1,232 @@ +/** + **************************************************************************************** + * + * @file proxr.c + * + * @brief Proximity Reporter Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup PROXR + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_PROX_REPORTER) + +#include "proxr.h" +#include "proxr_task.h" +#include "attm.h" +#include "gap.h" + +#include "ke_mem.h" + +/* + * PROXIMITY PROFILE ATTRIBUTES DEFINITION + **************************************************************************************** + */ + +/// Full LLS Database Description - Used to add attributes into the database +const struct attm_desc proxr_lls_att_db[LLS_IDX_NB] = +{ + // Link Loss Service Declaration + [LLS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + // Alert Level Characteristic Declaration + [LLS_IDX_ALERT_LVL_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Alert Level Characteristic Value + [LLS_IDX_ALERT_LVL_VAL] = {ATT_CHAR_ALERT_LEVEL, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, +}; + +/// Full IAS Database Description - Used to add attributes into the database +const struct attm_desc proxr_ias_att_db[IAS_IDX_NB] = +{ + // Immediate Alert Service Declaration + [IAS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE),0, 0}, + // Alert Level Characteristic Declaration + [IAS_IDX_ALERT_LVL_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Alert Level Characteristic Value + [IAS_IDX_ALERT_LVL_VAL] = {ATT_CHAR_ALERT_LEVEL, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, +}; + +/// Full TXPS Database Description - Used to add attributes into the database +const struct attm_desc proxr_txps_att_db[TXPS_IDX_NB] = +{ + // TX Power Service Declaration + [TXPS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + // TX Power Level Characteristic Declaration + [TXPS_IDX_TX_POWER_LVL_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // TX Power Level Characteristic Value + [TXPS_IDX_TX_POWER_LVL_VAL] = {ATT_CHAR_TX_POWER_LEVEL, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, +}; +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +static uint8_t proxr_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct proxr_db_cfg *p_params) +{ + // Service content flag + uint32_t cfg_flag = PROXR_LLS_MANDATORY_MASK; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + //-------------------- allocate memory required for the profile --------------------- + struct proxr_env_tag *p_proxr_env = + (struct proxr_env_tag *) ke_malloc(sizeof(struct proxr_env_tag), KE_MEM_ATT_DB); + + // allocate PROXR required environment variable + p_env->env = (prf_env_t *) p_proxr_env; + + status = attm_svc_create_db(p_start_hdl, ATT_SVC_LINK_LOSS, (uint8_t *)&cfg_flag, + LLS_IDX_NB, NULL, p_env->task, &proxr_lls_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) + | PERM(SVC_MI, DISABLE)); + + p_proxr_env->lls_start_hdl = *p_start_hdl; + *p_start_hdl += LLS_IDX_NB; + + if ((status == ATT_ERR_NO_ERROR) && (p_params->features == PROXR_IAS_TXPS_SUP) ) + { + cfg_flag = PROXR_IAS_MANDATORY_MASK; + status = attm_svc_create_db(p_start_hdl, ATT_SVC_IMMEDIATE_ALERT, (uint8_t *)&cfg_flag, + IAS_IDX_NB, NULL, p_env->task, &proxr_ias_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) + | PERM(SVC_MI, DISABLE)); + + p_proxr_env->ias_start_hdl = *p_start_hdl; + *p_start_hdl += IAS_IDX_NB; + + if (status == ATT_ERR_NO_ERROR) + { + cfg_flag = PROXR_TXP_MANDATORY_MASK; + status = attm_svc_create_db(p_start_hdl, ATT_SVC_TX_POWER, (uint8_t *)&cfg_flag, + TXPS_IDX_NB, NULL, p_env->task, &proxr_txps_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) + | PERM(SVC_MI, DISABLE)); + + p_proxr_env->txp_start_hdl = *p_start_hdl; + + if (status == ATT_ERR_NO_ERROR) + { + // set start handle to first allocated service value + *p_start_hdl = p_proxr_env->ias_start_hdl; + + p_proxr_env->features = p_params->features; + p_proxr_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_proxr_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_PROXR; + proxr_task_init(&(p_env->desc)); + + // service is ready, go into an Idle state + ke_state_set(p_env->task, PROXR_IDLE); + } + } + } + + return (status); +} + +static void proxr_destroy(struct prf_task_env *p_env) +{ + struct proxr_env_tag *p_proxr_env = (struct proxr_env_tag *) p_env->env; + + // free profile environment variables + p_env->env = NULL; + ke_free(p_proxr_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void proxr_create(struct prf_task_env* p_env, uint8_t conidx) +{ + struct proxr_env_tag *p_proxr_env = (struct proxr_env_tag *) p_env->env; + + p_proxr_env->lls_alert_lvl[conidx] = PROXR_ALERT_NONE; +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void proxr_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct proxr_env_tag *p_proxr_env = (struct proxr_env_tag *) p_env->env; + + if ((p_proxr_env->features == PROXR_IAS_TXPS_SUP) && (reason != LL_ERR_REMOTE_USER_TERM_CON)) + { + if (p_proxr_env->lls_alert_lvl[conidx] > PROXR_ALERT_NONE) + { + // Allocate the alert value change indication + struct proxr_alert_ind *p_ind = KE_MSG_ALLOC(PROXR_ALERT_IND, + prf_dst_task_get(&(p_proxr_env->prf_env), conidx), + prf_src_task_get(&(p_proxr_env->prf_env), conidx), proxr_alert_ind); + + // Fill in the parameter structure + p_ind->alert_lvl = p_proxr_env->lls_alert_lvl[conidx]; + p_ind->char_code = PROXR_LLS_CHAR; + p_ind->conidx = conidx; + + // Send the message + ke_msg_send(p_ind); + } + } + +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/// PROXR Task interface required by profile manager +const struct prf_task_cbs proxr_itf = +{ + (prf_init_fnct) proxr_init, + proxr_destroy, + proxr_create, + proxr_cleanup, +}; + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *proxr_prf_itf_get(void) +{ + return &proxr_itf; +} + + +#endif //BLE_PROX_REPORTER + +/// @} PROXR diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/src/proxr.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/src/proxr.h new file mode 100644 index 0000000..31c0266 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/src/proxr.h @@ -0,0 +1,216 @@ +/** + **************************************************************************************** + * + * @file proxr.h + * + * @brief Header file - PROXR. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef PROXR_H_ +#define PROXR_H_ + +/** + **************************************************************************************** + * @addtogroup PROXR Proximity Reporter + * @ingroup PROX + * @brief Proximity Profile Reporter. + * + * The PROXR is responsible for providing proximity reporter functionalities to + * upper layer module or application. The device using this profile takes the role + * of a proximity reporter role. + * + * Proximity Reporter (PR): A PR (e.g. a watch, key fob, etc) is the term used by + * this profile to describe a personal device that a user carries with them and that + * has low power requirement (i.e. it is operating with a button cell), allowing another + * device to monitor their connection. The device may have a simple user alert + * functionality, for example a blinking LED or audible output. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_PROX_REPORTER) + +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +///Maximum number of Proximity task instances +#define PROXR_IDX_MAX (1) + +#define PROXR_IAS_MANDATORY_MASK (0x07) +#define PROXR_LLS_MANDATORY_MASK (0x07) +#define PROXR_TXP_MANDATORY_MASK (0x07) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the PROXR task +enum +{ + /// Idle state + PROXR_IDLE, + /// Proximity reporter in a busy state + PROXR_BUSY, + + /// Number of defined states. + PROXR_STATE_MAX +}; + +/// LLS Handles offsets +enum +{ + LLS_IDX_SVC, + + LLS_IDX_ALERT_LVL_CHAR, + LLS_IDX_ALERT_LVL_VAL, + + LLS_IDX_NB, +}; + +/// IAS Handles offsets +enum +{ + IAS_IDX_SVC, + + IAS_IDX_ALERT_LVL_CHAR, + IAS_IDX_ALERT_LVL_VAL, + + IAS_IDX_NB, +}; + +/// TXPS Handles offsets +enum +{ + TXPS_IDX_SVC, + + TXPS_IDX_TX_POWER_LVL_CHAR, + TXPS_IDX_TX_POWER_LVL_VAL, + + TXPS_IDX_NB, +}; + + +///Alert Level Values +enum +{ + PROXR_ALERT_NONE, + PROXR_ALERT_MILD, + PROXR_ALERT_HIGH, +}; + + +/// Proximity service processing flags +enum +{ + /// Use To know if bond data are present + PROXR_BOND_DATA_PRESENT, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Proximity reporter environment variable +struct proxr_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// IAS Start Handle + uint16_t ias_start_hdl; + /// LLS Start Handle + uint16_t lls_start_hdl; + /// TXP Start Handle + uint16_t txp_start_hdl; + /// Proximity Feature + uint16_t features; + /// Connection index backup, needed due to GAP request for TX power read + uint8_t conidx_saved; + /// State of different task instances + ke_state_t state[PROXR_IDX_MAX]; + /// LLS alert level + uint8_t lls_alert_lvl[PROXR_IDX_MAX]; +}; + +/* + * PROXIMITY PROFILE ATTRIBUTES DECLARATION + **************************************************************************************** + */ + +/* + * PROXIMITY PROFILE ATTRIBUTES VALUES DECLARATION + **************************************************************************************** + */ + +/// Link Loss Service +extern const att_svc_desc_t proxr_lls_svc; +/// Link Loss Service - Alert Level Characteristic +extern const struct att_char_desc proxr_lls_alert_lvl_char; + +/// Immediate Alert Service +extern const att_svc_desc_t proxr_ias_svc; +/// Immediate Alert Service - Alert Level Characteristic +extern const struct att_char_desc proxr_ias_alert_lvl_char; + +/// TX Power Service +extern const att_svc_desc_t proxr_txps_svc; +/// TX Power Service -TX Power Level Characteristic +extern const struct att_char_desc proxr_txps_tx_power_lvl_char; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve Proximity service profile interface + * + * @return Proximity service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *proxr_prf_itf_get(void); + +/* + * GLOBAL VARIABLES DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void proxr_task_init(struct ke_task_desc *p_task_desc); + + +#endif //BLE_PROX_REPORTER + +/// @} PROXR + +#endif // PROXR_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/src/proxr_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/src/proxr_task.c new file mode 100644 index 0000000..f9db48b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/prox/proxr/src/proxr_task.c @@ -0,0 +1,310 @@ +/** + **************************************************************************************** + * + * @file proxr_task.c + * + * @brief Proximity Reporter Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup PROXRTASK + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_PROX_REPORTER) +#include "co_utils.h" + +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "proxr_task.h" +#include "proxr.h" +#include "prf_utils.h" + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of write request message. + * The handler will analyze what has been set and decide alert level + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + + if (state == PROXR_IDLE) + { + // Allocate write confirmation message. + struct gattc_write_cfm *p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, + src_id, dest_id, gattc_write_cfm); + + // Fill in the p_parameter structure + p_cfm->handle = p_param->handle; + p_cfm->status = PRF_APP_ERROR; + + if (p_param->value[0] <= PROXR_ALERT_HIGH) + { + // Get the address of the environment + struct proxr_env_tag *p_proxr_env = PRF_ENV_GET(PROXR, proxr); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t alert_lvl = p_param->value[0]; + + // Store alert level on the environment + if (p_param->handle == (p_proxr_env->lls_start_hdl + LLS_IDX_ALERT_LVL_VAL)) + { + p_proxr_env->lls_alert_lvl[conidx] = alert_lvl; + p_cfm->status = GAP_ERR_NO_ERROR; + } + else if (p_param->handle == (p_proxr_env->ias_start_hdl + IAS_IDX_ALERT_LVL_VAL)) + { + // Allocate the alert value change indication + struct proxr_alert_ind *p_ind = KE_MSG_ALLOC(PROXR_ALERT_IND, + prf_dst_task_get(&(p_proxr_env->prf_env), conidx), + dest_id, proxr_alert_ind); + + // Fill in the p_parameter structure + p_ind->alert_lvl = alert_lvl; + p_ind->char_code = PROXR_IAS_CHAR; + p_ind->conidx = conidx; + + // Send the message + ke_msg_send(p_ind); + + p_cfm->status = GAP_ERR_NO_ERROR; + } + else + { + p_cfm->status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } + } + + // Send the message + ke_msg_send(p_cfm); + } + else if (state == PROXR_BUSY) + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + + if (state == PROXR_IDLE) + { + // Get the address of the environment + struct proxr_env_tag *p_proxr_env = PRF_ENV_GET(PROXR, proxr); + uint8_t conidx = KE_IDX_GET(src_id); + + uint8_t value = PROXR_ALERT_NONE; + uint8_t status = ATT_ERR_NO_ERROR; + + if (p_param->handle == (p_proxr_env->lls_start_hdl + LLS_IDX_ALERT_LVL_VAL)) + { + value = p_proxr_env->lls_alert_lvl[conidx]; + } + else if (p_param->handle == (p_proxr_env->txp_start_hdl + TXPS_IDX_TX_POWER_LVL_VAL)) + { + // send a request to read TX power level on GAPM + struct gapm_get_dev_info_cmd *p_cmd = KE_MSG_ALLOC(GAPM_GET_DEV_INFO_CMD, + TASK_GAPM, + dest_id, + gapm_get_dev_info_cmd); + + p_cmd->operation = GAPM_GET_DEV_ADV_TX_POWER; + ke_msg_send(p_cmd); + + // save the connection index + p_proxr_env->conidx_saved = conidx; + + // need to wait for GAPM response, go into busy state + ke_state_set(dest_id, PROXR_BUSY); + + status = PRF_APP_ERROR; + } + else + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } + + // Don't send the confirmation if gap read request has been initiated. + if (status != PRF_APP_ERROR) + { + // Send data to peer device + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, + gattc_read_cfm, sizeof(uint8_t)); + + p_cfm->length = sizeof(uint8_t); + p_cfm->value[0] = value; + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + } + else if (state == PROXR_BUSY) + { + msg_status = KE_MSG_SAVED; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GAPM_DEV_ADV_TX_POWER_IND message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gapm_dev_adv_tx_power_ind_handler(ke_msg_id_t const msgid, + struct gapm_dev_adv_tx_power_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct proxr_env_tag *p_proxr_env = PRF_ENV_GET(PROXR, proxr); + + if (ke_state_get(dest_id) == PROXR_BUSY) + { + // Send data to peer device + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, p_proxr_env->conidx_saved), + dest_id, + gattc_read_cfm, + sizeof(uint8_t)); + + p_cfm->length = sizeof(uint8_t); + p_cfm->value[0] = p_param->power_lvl; + p_cfm->handle = p_proxr_env->txp_start_hdl + TXPS_IDX_TX_POWER_LVL_VAL; + p_cfm->status = GAP_ERR_NO_ERROR; + + // Send value to peer device. + ke_msg_send(p_cfm); + + ke_state_set(dest_id, PROXR_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GAPM_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gapm_cmp_evt_handler(ke_msg_id_t const msgid, + struct gapm_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct proxr_env_tag *p_proxr_env = PRF_ENV_GET(PROXR, proxr); + + if ((ke_state_get(dest_id) == PROXR_BUSY) && (p_param->status != GAP_ERR_NO_ERROR)) + { + // Send data to peer device + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, + p_proxr_env->conidx_saved), + dest_id, + gattc_read_cfm); + + p_cfm->length = sizeof(uint8_t); + p_cfm->handle = p_proxr_env->txp_start_hdl + TXPS_IDX_TX_POWER_LVL_VAL; + p_cfm->status = PRF_APP_ERROR; + + // Send value to peer device. + ke_msg_send(p_cfm); + + ke_state_set(dest_id, PROXR_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(proxr) +{ + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GAPM_DEV_ADV_TX_POWER_IND, (ke_msg_func_t) gapm_dev_adv_tx_power_ind_handler}, + {GAPM_CMP_EVT, (ke_msg_func_t) gapm_cmp_evt_handler}, +}; + +void proxr_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct proxr_env_tag *p_proxr_env = PRF_ENV_GET(PROXR, proxr); + + p_task_desc->msg_handler_tab = proxr_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(proxr_msg_handler_tab); + p_task_desc->state = p_proxr_env->state; + p_task_desc->idx_max = PROXR_IDX_MAX; +} + +#endif //BLE_PROX_REPORTER + +/// @} PROXRTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdts_common.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdts_common.c new file mode 100644 index 0000000..c34bdd9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdts_common.c @@ -0,0 +1,229 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdts_common.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_ENABLE) +#include "rdts_common.h" +#if (BLE_RDTSS_SERVER) +#include "rdtss.h" +#endif // (BLE_RDTSS_SERVER) + +#if (BLE_RDTSS_16BIT_SERVER) +#include "rdtss_16bit.h" +#endif // (BLE_RDTSS_16BIT_SERVER) + +#include "gattc_task.h" +#include "att.h" +#include "attm_db.h" +#include "prf_types.h" +#include "prf_utils.h" +/* Private define ------------------------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ + +int check_client_char_cfg(bool is_notification, const struct gattc_write_req_ind *param) +{ + uint8_t status = GAP_ERR_NO_ERROR; + uint16_t ntf_cfg = 0; + + if (param->length != sizeof(uint16_t)) + { + status = ATT_ERR_INVALID_ATTRIBUTE_VAL_LEN; + } + else + { + ntf_cfg = *((uint16_t*)param->value); + + if (is_notification) + { + if ( (ntf_cfg != PRF_CLI_STOP_NTFIND) && (ntf_cfg != PRF_CLI_START_NTF) ) + { + status = PRF_ERR_INVALID_PARAM; + } + } + else + { + if ( (ntf_cfg != PRF_CLI_STOP_NTFIND) && (ntf_cfg != PRF_CLI_START_IND) ) + { + status = PRF_ERR_INVALID_PARAM; + } + } + } + + return status; +} + +uint16_t get_value_handle(uint16_t cfg_handle) +{ + uint8_t uuid[ATT_UUID_128_LEN]; + uint8_t uuid_len; + uint16_t handle = cfg_handle; + struct attm_svc *srv; + + srv = attmdb_get_service(handle); + + while ((handle >= srv->svc.start_hdl) && (handle <= srv->svc.end_hdl)) + { + struct attm_elmt elmt; + + // Retrieve UUID + attmdb_get_attribute(handle, &elmt); + attmdb_get_uuid(&elmt, &uuid_len, uuid, false, false); + + // check for Characteristic declaration + if (*(uint16_t *)&uuid[0] == ATT_DECL_CHARACTERISTIC) + return handle + 1; + + handle--; + } + + return 0; //Should not reach this point. something is wrong with the database +} + +uint16_t get_cfg_handle(uint16_t value_handle) +{ + uint8_t uuid[ATT_UUID_128_LEN]; + uint8_t uuid_len; + uint16_t handle = value_handle; + struct attm_svc *srv; + + srv = attmdb_get_service(handle); + + /* Iterate the database to find the client characteristic configuration. + */ + while ((handle >= srv->svc.start_hdl) && (handle <= srv->svc.end_hdl)) + { + struct attm_elmt elmt; + + // Retrieve UUID + attmdb_get_attribute(handle, &elmt); + attmdb_get_uuid(&elmt, &uuid_len, uuid, false, false); + + // check for Client Characteristic Configuration + if (*(uint16_t *)&uuid[0] == ATT_DESC_CLIENT_CHAR_CFG && uuid_len == sizeof(uint16_t)) + return handle; + else if (*(uint16_t *)&uuid[0] == ATT_DECL_CHARACTERISTIC && uuid_len == sizeof(uint16_t)) + break; // found the next Characteristic declaration without findig a CC CFG, + + handle++; + } + + return 0; //Should not reach this point. something is wrong with the database +} + +#if (BLE_RDTSS_SERVER) +uint16_t rdtss_get_att_handle(uint8_t att_idx) +{ + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + uint16_t handle = ATT_INVALID_HDL; + + if (att_idx < rdtss_env->max_nb_att) + { + handle = rdtss_env->shdl + att_idx; + } + + return handle; +} + +uint8_t rdtss_get_att_idx(uint16_t handle, uint8_t *att_idx) +{ + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + uint8_t status = PRF_APP_ERROR; + + if ((handle >= rdtss_env->shdl) && (handle < rdtss_env->shdl + rdtss_env->max_nb_att)) + { + *att_idx = handle - rdtss_env->shdl; + status = ATT_ERR_NO_ERROR; + } + + return status; +} +#endif // (BLE_RDTSS_SERVER) + + +#if (BLE_RDTSS_16BIT_SERVER) +uint16_t rdtss_16bit_get_att_handle(uint8_t att_idx) +{ + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + uint16_t handle = ATT_INVALID_HDL; + + if (att_idx < rdtss_16bit_env->max_nb_att) + { + handle = rdtss_16bit_env->shdl + att_idx; + } + + return handle; +} + +uint8_t rdtss_16bit_get_att_idx(uint16_t handle, uint8_t *att_idx) +{ + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + uint8_t status = PRF_APP_ERROR; + + if ((handle >= rdtss_16bit_env->shdl) && (handle < rdtss_16bit_env->shdl + rdtss_16bit_env->max_nb_att)) + { + *att_idx = handle - rdtss_16bit_env->shdl; + status = ATT_ERR_NO_ERROR; + } + + return status; +} +#endif // (BLE_RDTSS_16BIT_SERVER) + + +#endif // (BLE_RDTS_ENABLE) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdts_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdts_common.h new file mode 100644 index 0000000..08f7ece --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdts_common.h @@ -0,0 +1,124 @@ + /** + * Copyright (c) 2025, NSING Technologies Inc. + * + * All rights reserved. + * + * This software is the exclusive property of NSING Technologies Inc. (Hereinafter + * referred to as NSING). This software, and the product of NSING described herein + * (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties + * of the People's Republic of China and other applicable jurisdictions worldwide. + * + * NSING does not grant any license under its patents, copyrights, trademarks, or other + * intellectual property rights. Names and brands of third party may be mentioned or referred + * thereto (if any) for identification purposes only. + * + * NSING reserves the right to make changes, corrections, enhancements, modifications, and + * improvements to this software at any time without notice. Please contact NSING and obtain + * the latest version of this software before placing orders. + + * Although NSING has attempted to provide accurate and reliable information, NSING assumes + * no responsibility for the accuracy and reliability of this software. + * + * It is the responsibility of the user of this software to properly design, program, and test + * the functionality and safety of any application made of this information and any resulting product. + * In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or + * consequential damages arising in any way out of the use of this software or the Product. + * + * NSING Products are neither intended nor warranted for usage in systems or equipment, any + * malfunction or failure of which may cause loss of human life, bodily injury or severe property + * damage. Such applications are deemed, "Insecure Usage". + * + * All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING + * harmless from and against all claims, costs, damages, and other liabilities, arising from or related + * to any customer's Insecure Usage. + + * Any express or implied warranty with regard to this software or the Product, including,but not + * limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement + * are disclaimed to the fullest extent permitted by law. + + * Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe + * or otherwise distribute this software for any purposes, in whole or in part. + * + * NSING products and technologies shall not be used for or incorporated into any products or systems + * whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. + * User shall comply with any applicable export control laws and regulations promulgated and administered by + * the governments of any countries asserting jurisdiction over the parties or transactions. + **/ + + +/** + * @file rdts_common.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef __RDTS_COMMON_H__ +#define __RDTS_COMMON_H__ + +#include "gattc_task.h" + +/** + * @brief Validate the value of the Client Characteristic CFG. + * @param[in] is_notification indicates whether the CFG is Notification (true) or Indication (false) + * @param[in] param Pointer to the parameters of the message. + * @return status. + */ +int check_client_char_cfg(bool is_notification, const struct gattc_write_req_ind *param); + +/** + * @brief Find the handle of the Characteristic Value having as input the Client Characteristic CFG handle + * @param[in] cfg_handle the Client Characteristic CFG handle + * @return the corresponding value handle + */ +uint16_t get_value_handle(uint16_t cfg_handle); + +/** + * @brief Find the handle of Client Characteristic CFG having as input the Characteristic value handle + * @param[in] value_handle the Characteristic value handle + * @return the corresponding Client Characteristic CFG handle + */ +uint16_t get_cfg_handle(uint16_t value_handle); + +#if (BLE_RDTSS_SERVER) +/** + * @brief Compute the handle of a given attribute based on its index + * @details Specific to raw data transfer server in 128bit uuid + * @param[in] att_idx attribute index + * @return the corresponding handle + */ +uint16_t rdtss_get_att_handle(uint8_t att_idx); + +/** + * @brief Compute the handle of a given attribute based on its index + * @details Specific to raw data transfer server in 128bit uuid + * @param[in] handle attribute handle + * @param[out] att_idx attribute index + * @return high layer error code + */ +uint8_t rdtss_get_att_idx(uint16_t handle, uint8_t *att_idx); +#endif // (BLE_RDTSS_SERVER) + + +#if (BLE_RDTSS_16BIT_SERVER) +/** + * @brief Compute the handle of a given attribute based on its index + * @details Specific to raw data transfer server in 16bit uuid + * @param[in] att_idx attribute index + * @return the corresponding handle + */ +uint16_t rdtss_16bit_get_att_handle(uint8_t att_idx); + +/** + * @brief Compute the handle of a given attribute based on its index + * @details Specific to raw data transfer server in 16bit uuid + * @param[in] handle attribute handle + * @param[out] att_idx attribute index + * @return high layer error code + */ +uint8_t rdtss_16bit_get_att_idx(uint16_t handle, uint8_t *att_idx); +#endif // (BLE_RDTSS_16BIT_SERVER) + + +#endif // __RDTS_COMMON_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client.h new file mode 100644 index 0000000..0735815 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client.h @@ -0,0 +1,326 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdts_client.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef RDTS_CLIENT_H_ +#define RDTS_CLIENT_H_ + +/** + **************************************************************************************** + * @addtogroup RDTS Raw Data Transfer Service + * @ingroup PROFILE + * @brief Raw Data Transfer Service + ***************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup RDTS Raw Data Transfer Service Client + * @ingroup RDTSC + * @brief RDTS Profile role: Client + * @{ + **************************************************************************************** + */ + +#include "rwprf_config.h" + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#if (BLE_RDTS_CLIENT) + +#include "ke_task.h" +#include "prf.h" +#include "prf_types.h" + +/* + * Defines + **************************************************************************************** + */ +#define RDTSC_IDX_MAX 1 + + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +#define RDTSC_CLEANUP_FNCT (NULL) + +/// RDTS Service Characteristics +enum +{ + RDTSC_SRV_TX_DATA_CHAR = 0, + RDTSC_SRV_RX_DATA_CHAR, + + RDTSC_CHAR_MAX +}; + +/// RDTS Service Characteristic Descriptors +enum +{ + /// RDTS client config + RDTSC_SRV_TX_DATA_CLI_CFG, + + RDTSC_DESC_MAX, +}; + +typedef enum flow_ctrl_states +{ + FLOW_ON = (uint8_t)0x01, + FLOW_OFF = (uint8_t)0x02, +}flow_ctrl_state_t; + +/* + * STRUCTURES + **************************************************************************************** + */ + +struct rdtsc_db_cfg +{ + const struct prf_char_def_128* p_char; + const struct prf_char_desc_def* p_desc; + const uint8_t* p_uuid128; + +}; + +/// Service information +struct rdtsc_rdts_content +{ + /// Service info + struct prf_svc svc; + + /// Characteristic info: + struct prf_char_inf chars[RDTSC_CHAR_MAX]; + + /// Characteristic cfg + struct prf_char_desc_inf descs[RDTSC_DESC_MAX]; +}; + +/// RDTS Host environment variable +struct rdtsc_env_tag +{ + + /// profile environment + prf_env_t prf_env; + /// Service Start Handle + uint16_t shdl; + /// To store the DB max number of attributes + uint8_t max_nb_att; + /// On-going operation + struct ke_msg *operation; + + /// Cursor on connection used to notify peer devices + uint8_t cursor; + /// CCC handle index, used during notification/indication busy state + uint8_t ccc_idx; + + /// List of values set by application + struct co_list values; + /// RDTSC task state + ke_state_t state[RDTSC_IDX_MAX]; + + /// Profile Connection Info + + /// Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Last service for which something was discovered + uint8_t last_svc_req[ATT_UUID_128_LEN]; + + /// Last char. code requested to read. + uint8_t last_char_code; + + /// counter used to check service uniqueness + uint8_t nb_svc; + + /// RDTS Device Service information recovered from discovery + struct rdtsc_rdts_content rdts; + + /// Flow control states + bool tx_flow_en; + bool rx_flow_en; + bool tx_busy_flag; + + /// Updated mtu + uint16_t mtu; + uint16_t tx_size; + uint16_t tx_wait_level; + + /// Pending TX + struct ke_msg *pending_tx_msg; + /// Write no rsp completion remaining + uint8_t pending_wr_no_rsp_cmp; + /// Pending notification of data tx + bool pending_tx_ntf_cmp; + + uint8_t conidx; + + struct rdtsc_db_cfg rdtsc_cfg; +}; + + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Profile Initialization + * @param[in] env enviroment + * @param[in] start_hdl start handle + * @param[in] app_task application task + * @param[in] sec_lvl security level + * @param[in] params configuration parameters + * @return void + **************************************************************************************** + */ +uint8_t rdtsc_init(struct prf_task_env *env, uint16_t *start_hdl, uint16_t app_task, uint8_t sec_lvl, struct rdtsc_db_cfg *params); +/** + **************************************************************************************** + * @brief Profile enable confirmation + * @param[in] env_tag enviroment + * @param[in] conidx Connection index + * @param[in] status + * @return void + **************************************************************************************** + */ +void rdtsc_enable_cfm_send(struct rdtsc_env_tag *rdtsc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Confirm that data has been sent + * @param[in] rdtsc_env enviroment + * @param[in] status + * @return void + **************************************************************************************** + */ +void rdtsc_confirm_data_tx(struct rdtsc_env_tag *rdtsc_env, uint8_t status); + +/** + **************************************************************************************** + * @brief Find next empty characteristic description + * @param[in] rdtsc_env enviroment + * @param[in] desc_def service characteristic description information table + * @return position of next characteristic description + **************************************************************************************** + */ +uint8_t rdtsc_get_next_desc_char_code(struct rdtsc_env_tag *rdtsc_env, + const struct prf_char_desc_def *desc_def); + +/** + **************************************************************************************** + * @brief Retrieve RDTS profile interface + * + * @return RDTS service profile interface + **************************************************************************************** + */ + +const struct prf_task_cbs* rdtsc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Receives data and forwards it to application + * @param[in] rdtsc_env enviroment + * @param[in] message received + * @param[in] length + * @return void + **************************************************************************************** + */ +void rdtsc_data_receive(struct rdtsc_env_tag *rdtsc_env, void *msg ); + + +/** + **************************************************************************************** + * @brief Receives data and forwards it to application + * @param[in] msg voi pointer to RDTS_CLIENT_DATA_TX_REQ message + * @param[in] prf_env rdtsc profile enviroment + * @param[in] conidx connection index + * @param[in] handle RDTSC_SRV_RX_DATA_CHAR handle + * @param[in] value data pointer to be written + * @param[in] operation GATTC_WRITE_NO_RESPONSE + * @return void + **************************************************************************************** + */ + +void rdtsc_write_data_tx(void *msg, prf_env_t *prf_env, uint8_t conidx, + uint16_t handle, uint8_t* value, uint16_t length, uint8_t operation); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * Initialize task handler + * + * @param task_desc Task descriptor to fill + **************************************************************************************** + */ +void rdtsc_task_init(struct ke_task_desc *p_task_desc); + +#endif //BLE_RDTS_CLIENT + +/// @} RDTSC + +#endif // RDTS_CLIENT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client_16bit.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client_16bit.h new file mode 100644 index 0000000..6dd852a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client_16bit.h @@ -0,0 +1,326 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdts_client_16bit.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef RDTS_CLIENT_H_ +#define RDTS_CLIENT_H_ + +/** + **************************************************************************************** + * @addtogroup RDTS Raw Data Transfer Service in 16bit uuid + * @ingroup PROFILE + * @brief Raw Data Transfer Service in 16bit uuid + ***************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup RDTS Raw Data Transfer Service Client in 16bit uuid + * @ingroup RDTSC + * @brief RDTS Profile role: Client + * @{ + **************************************************************************************** + */ + +#include "rwprf_config.h" + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#if (BLE_RDTS_16BIT_CLIENT) + +#include "ke_task.h" +#include "prf.h" +#include "prf_types.h" + +/* + * Defines + **************************************************************************************** + */ +#define RDTSC_IDX_MAX 1 + + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +#define RDTSC_CLEANUP_FNCT (NULL) + +/// RDTS Service Characteristics +enum +{ + RDTSC_SRV_TX_DATA_CHAR = 0, + RDTSC_SRV_RX_DATA_CHAR, + + RDTSC_CHAR_MAX +}; + +/// RDTS Service Characteristic Descriptors +enum +{ + /// RDTS client config + RDTSC_SRV_TX_DATA_CLI_CFG, + + RDTSC_DESC_MAX, +}; + +typedef enum flow_ctrl_states +{ + FLOW_ON = (uint8_t)0x01, + FLOW_OFF = (uint8_t)0x02, +}flow_ctrl_state_t; + +/* + * STRUCTURES + **************************************************************************************** + */ + +struct rdtsc_db_cfg +{ + struct prf_char_def* p_char; + struct prf_char_desc_def* p_desc; + uint16_t uuid16; + +}; + +/// Service information +struct rdtsc_rdts_content +{ + /// Service info + struct prf_svc svc; + + /// Characteristic info: + struct prf_char_inf chars[RDTSC_CHAR_MAX]; + + /// Characteristic cfg + struct prf_char_desc_inf descs[RDTSC_DESC_MAX]; +}; + +/// RDTS Host environment variable +struct rdtsc_env_tag +{ + + /// profile environment + prf_env_t prf_env; + /// Service Start Handle + uint16_t shdl; + /// To store the DB max number of attributes + uint8_t max_nb_att; + /// On-going operation + struct ke_msg *operation; + + /// Cursor on connection used to notify peer devices + uint8_t cursor; + /// CCC handle index, used during notification/indication busy state + uint8_t ccc_idx; + + /// List of values set by application + struct co_list values; + /// RDTSC task state + ke_state_t state[RDTSC_IDX_MAX]; + + /// Profile Connection Info + + /// Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Last service for which something was discovered + uint16_t last_svc_req; + + /// Last char. code requested to read. + uint8_t last_char_code; + + /// counter used to check service uniqueness + uint8_t nb_svc; + + /// RDTS Device Service information recovered from discovery + struct rdtsc_rdts_content rdts; + + /// Flow control states + bool tx_flow_en; + bool rx_flow_en; + bool tx_busy_flag; + + /// Updated mtu + uint16_t mtu; + uint16_t tx_size; + uint16_t tx_wait_level; + + /// Pending TX + struct ke_msg *pending_tx_msg; + /// Write no rsp completion remaining + uint8_t pending_wr_no_rsp_cmp; + /// Pending notification of data tx + bool pending_tx_ntf_cmp; + + uint8_t conidx; + + struct rdtsc_db_cfg rdtsc_cfg; +}; + + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Profile Initialization + * @param[in] env enviroment + * @param[in] start_hdl start handle + * @param[in] app_task application task + * @param[in] sec_lvl security level + * @param[in] params configuration parameters + * @return void + **************************************************************************************** + */ +uint8_t rdtsc_16bit_init(struct prf_task_env *env, uint16_t *start_hdl, uint16_t app_task, uint8_t sec_lvl, struct rdtsc_db_cfg *params); +/** + **************************************************************************************** + * @brief Profile enable confirmation + * @param[in] env_tag enviroment + * @param[in] conidx Connection index + * @param[in] status + * @return void + **************************************************************************************** + */ +void rdtsc_16bit_enable_cfm_send(struct rdtsc_env_tag *rdtsc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Confirm that data has been sent + * @param[in] rdtsc_env enviroment + * @param[in] status + * @return void + **************************************************************************************** + */ +void rdtsc_16bit_confirm_data_tx(struct rdtsc_env_tag *rdtsc_env, uint8_t status); + +/** + **************************************************************************************** + * @brief Find next empty characteristic description + * @param[in] rdtsc_env enviroment + * @param[in] desc_def service characteristic description information table + * @return position of next characteristic description + **************************************************************************************** + */ +uint8_t rdtsc_16bit_get_next_desc_char_code(struct rdtsc_env_tag *rdtsc_env, + const struct prf_char_desc_def *desc_def); + +/** + **************************************************************************************** + * @brief Retrieve RDTS profile interface + * + * @return RDTS service profile interface + **************************************************************************************** + */ + +const struct prf_task_cbs* rdtsc_16bit_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Receives data and forwards it to application + * @param[in] rdtsc_env enviroment + * @param[in] message received + * @param[in] length + * @return void + **************************************************************************************** + */ +void rdtsc_16bit_data_receive(struct rdtsc_env_tag *rdtsc_env, void *msg ); + + +/** + **************************************************************************************** + * @brief Receives data and forwards it to application + * @param[in] msg voi pointer to RDTS_CLIENT_DATA_TX_REQ message + * @param[in] prf_env rdtsc profile enviroment + * @param[in] conidx connection index + * @param[in] handle RDTSC_SRV_RX_DATA_CHAR handle + * @param[in] value data pointer to be written + * @param[in] operation GATTC_WRITE_NO_RESPONSE + * @return void + **************************************************************************************** + */ + +void rdtsc_16bit_write_data_tx(void *msg, prf_env_t *prf_env, uint8_t conidx, + uint16_t handle, uint8_t* value, uint16_t length, uint8_t operation); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * Initialize task handler + * + * @param task_desc Task descriptor to fill + **************************************************************************************** + */ +void rdtsc_16bit_task_init(struct ke_task_desc *p_task_desc); + +#endif //BLE_RDTS_16BIT_CLIENT + +/// @} RDTSC + +#endif // RDTS_CLIENT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client_16bit_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client_16bit_task.h new file mode 100644 index 0000000..d672173 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client_16bit_task.h @@ -0,0 +1,226 @@ + /** + * Copyright (c) 2025, NSING Technologies Inc. + * + * All rights reserved. + * + * This software is the exclusive property of NSING Technologies Inc. (Hereinafter + * referred to as NSING). This software, and the product of NSING described herein + * (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties + * of the People's Republic of China and other applicable jurisdictions worldwide. + * + * NSING does not grant any license under its patents, copyrights, trademarks, or other + * intellectual property rights. Names and brands of third party may be mentioned or referred + * thereto (if any) for identification purposes only. + * + * NSING reserves the right to make changes, corrections, enhancements, modifications, and + * improvements to this software at any time without notice. Please contact NSING and obtain + * the latest version of this software before placing orders. + + * Although NSING has attempted to provide accurate and reliable information, NSING assumes + * no responsibility for the accuracy and reliability of this software. + * + * It is the responsibility of the user of this software to properly design, program, and test + * the functionality and safety of any application made of this information and any resulting product. + * In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or + * consequential damages arising in any way out of the use of this software or the Product. + * + * NSING Products are neither intended nor warranted for usage in systems or equipment, any + * malfunction or failure of which may cause loss of human life, bodily injury or severe property + * damage. Such applications are deemed, "Insecure Usage". + * + * All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING + * harmless from and against all claims, costs, damages, and other liabilities, arising from or related + * to any customer's Insecure Usage. + + * Any express or implied warranty with regard to this software or the Product, including,but not + * limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement + * are disclaimed to the fullest extent permitted by law. + + * Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe + * or otherwise distribute this software for any purposes, in whole or in part. + * + * NSING products and technologies shall not be used for or incorporated into any products or systems + * whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. + * User shall comply with any applicable export control laws and regulations promulgated and administered by + * the governments of any countries asserting jurisdiction over the parties or transactions. + **/ + + +/** + * @file rdts_client_16bit_task.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef RDTS_CLIENT_TASK_H_ +#define RDTS_CLIENT_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup RDTSCTASK 16bit Raw Data Transfer Service client Task + * @ingroup RDTSCTASK + * @brief 16bit Raw Data Transfer Service client Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#include "ke_task.h" +#include "rdts_client_16bit.h" + +#if (BLE_RDTS_16BIT_CLIENT) +/* + * DEFINES + **************************************************************************************** + */ + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the RTDS_CLIENT task +enum +{ + /// IDLE state + RDTSC_IDLE, + + /// Connected state + RDTSC_CONNECTED, + + /// Discovering + RDTSC_DISCOVERING, + + /// Number of defined states. + RDTSC_STATE_MAX +}; + +///RDTSC Host API messages +enum +{ + /// RDTSC client role enable request from application. + RDTSC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_RDTSC_16BIT), + + /// RDTSC Host role enable confirmation to application. + RDTSC_ENABLE_CFM, + + /// Request to transmit data + RDTSC_DATA_TX_REQ, + + /// Confirm that data has been sent + RDTSC_DATA_TX_CFM, + + /// Send data to app + RDTSC_DATA_RX_IND, + + /// Indicate flow control state + RDTSC_TX_FLOW_CTRL_IND, +}; + +/* + * API Messages Structures + **************************************************************************************** + */ + +///Parameters of the @ref RDTSC_ENABLE_REQ message +struct rdtsc_enable_req +{ + /// Connection handle + uint8_t conidx; + + /// Connection type + uint8_t con_type; + +}; + +///Parameters of the @ref RDTSC_ENABLE_CFM message +struct rdtsc_enable_cfm +{ + + /// Status + uint8_t status; + + /// RDTS Device details to keep in APP + struct rdtsc_rdts_content rdts; +}; + +///Parameters of the @ref RDTSC_DATA_TX_REQ message +///WARNING, DO NOT ALTER THIS STRUCT, IT SHOULD BE COMPATIBLE WITH gattc_write_cmd struct +struct rdtsc_data_tx_req +{ + uint8_t operation; + /// Perform automatic execution + /// (if false, an ATT Prepare Write will be used this shall be use for reliable write) + bool auto_execute; + /// operation sequence number + uint16_t seq_num; + /// Attribute handle + uint16_t handle; + /// Write offset + uint16_t offset; + /// Write length + uint16_t length; + /// Internal write cursor shall be initialized to 0 + uint16_t cursor; + /// Value to write + uint8_t data[__ARRAY_EMPTY]; +}; +///Parameters of the @ref RDTSC_DATA_TX_CFM message +struct rdtsc_data_tx_cfm +{ + ///Status + uint8_t status; +}; + +///Parameters of the @ref RDTSC_DATA_RX_IND message +///WARNING, DO NOT ALTER THIS STRUCT, IT SHOULD BE COMPATIBLE WITH gattc_event_ind struct +struct rdtsc_data_rx_ind +{ + /// Event Type + uint8_t type; + /// Data length + uint16_t length; + /// Attribute handle + uint16_t handle; + /// Event Value + uint8_t data[__ARRAY_EMPTY]; +}; + +///Parameters of the @ref RDTSC_RX_FLOW_CTRL_REQ message +struct rdtsc_rx_flow_ctrl_req +{ + // flow control state + uint8_t flow_control_state; +}; + +///Parameters of the @ref RDTSC_TX_FLOW_CTRL_IND message +struct rdtsc_tx_flow_ctrl_ind +{ + // flow control state + uint8_t flow_control_state; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +extern const struct ke_state_handler rdtsc_16bit_default_handler; + +/* + * Functions + **************************************************************************************** + */ + +#endif //BLE_RDTS_16BIT_CLIENT + +/// @} RDTSCTASK + +#endif // RDTS_CLIENT_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client_task.h new file mode 100644 index 0000000..f6f27e3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/api/rdts_client_task.h @@ -0,0 +1,226 @@ + /** + * Copyright (c) 2025, NSING Technologies Inc. + * + * All rights reserved. + * + * This software is the exclusive property of NSING Technologies Inc. (Hereinafter + * referred to as NSING). This software, and the product of NSING described herein + * (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties + * of the People's Republic of China and other applicable jurisdictions worldwide. + * + * NSING does not grant any license under its patents, copyrights, trademarks, or other + * intellectual property rights. Names and brands of third party may be mentioned or referred + * thereto (if any) for identification purposes only. + * + * NSING reserves the right to make changes, corrections, enhancements, modifications, and + * improvements to this software at any time without notice. Please contact NSING and obtain + * the latest version of this software before placing orders. + + * Although NSING has attempted to provide accurate and reliable information, NSING assumes + * no responsibility for the accuracy and reliability of this software. + * + * It is the responsibility of the user of this software to properly design, program, and test + * the functionality and safety of any application made of this information and any resulting product. + * In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or + * consequential damages arising in any way out of the use of this software or the Product. + * + * NSING Products are neither intended nor warranted for usage in systems or equipment, any + * malfunction or failure of which may cause loss of human life, bodily injury or severe property + * damage. Such applications are deemed, "Insecure Usage". + * + * All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING + * harmless from and against all claims, costs, damages, and other liabilities, arising from or related + * to any customer's Insecure Usage. + + * Any express or implied warranty with regard to this software or the Product, including,but not + * limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement + * are disclaimed to the fullest extent permitted by law. + + * Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe + * or otherwise distribute this software for any purposes, in whole or in part. + * + * NSING products and technologies shall not be used for or incorporated into any products or systems + * whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. + * User shall comply with any applicable export control laws and regulations promulgated and administered by + * the governments of any countries asserting jurisdiction over the parties or transactions. + **/ + + +/** + * @file rdts_client_task.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef RDTS_CLIENT_TASK_H_ +#define RDTS_CLIENT_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup RDTSCTASK Raw Data Transfer Service client Task + * @ingroup RDTSCTASK + * @brief Raw Data Transfer Service client Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#include "ke_task.h" +#include "rdts_client.h" + +#if (BLE_RDTS_CLIENT) +/* + * DEFINES + **************************************************************************************** + */ + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the RTDS_CLIENT task +enum +{ + /// IDLE state + RDTSC_IDLE, + + /// Connected state + RDTSC_CONNECTED, + + /// Discovering + RDTSC_DISCOVERING, + + /// Number of defined states. + RDTSC_STATE_MAX +}; + +///RDTSC Host API messages +enum +{ + /// RDTSC client role enable request from application. + RDTSC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_RDTSC), + + /// RDTSC Host role enable confirmation to application. + RDTSC_ENABLE_CFM, + + /// Request to transmit data + RDTSC_DATA_TX_REQ, + + /// Confirm that data has been sent + RDTSC_DATA_TX_CFM, + + /// Send data to app + RDTSC_DATA_RX_IND, + + /// Indicate flow control state + RDTSC_TX_FLOW_CTRL_IND, +}; + +/* + * API Messages Structures + **************************************************************************************** + */ + +///Parameters of the @ref RDTSC_ENABLE_REQ message +struct rdtsc_enable_req +{ + /// Connection handle + uint8_t conidx; + + /// Connection type + uint8_t con_type; + +}; + +///Parameters of the @ref RDTSC_ENABLE_CFM message +struct rdtsc_enable_cfm +{ + + /// Status + uint8_t status; + + /// RDTS Device details to keep in APP + struct rdtsc_rdts_content rdts; +}; + +///Parameters of the @ref RDTSC_DATA_TX_REQ message +///WARNING, DO NOT ALTER THIS STRUCT, IT SHOULD BE COMPATIBLE WITH gattc_write_cmd struct +struct rdtsc_data_tx_req +{ + uint8_t operation; + /// Perform automatic execution + /// (if false, an ATT Prepare Write will be used this shall be use for reliable write) + bool auto_execute; + /// operation sequence number + uint16_t seq_num; + /// Attribute handle + uint16_t handle; + /// Write offset + uint16_t offset; + /// Write length + uint16_t length; + /// Internal write cursor shall be initialized to 0 + uint16_t cursor; + /// Value to write + uint8_t data[__ARRAY_EMPTY]; +}; +///Parameters of the @ref RDTSC_DATA_TX_CFM message +struct rdtsc_data_tx_cfm +{ + ///Status + uint8_t status; +}; + +///Parameters of the @ref RDTSC_DATA_RX_IND message +///WARNING, DO NOT ALTER THIS STRUCT, IT SHOULD BE COMPATIBLE WITH gattc_event_ind struct +struct rdtsc_data_rx_ind +{ + /// Event Type + uint8_t type; + /// Data length + uint16_t length; + /// Attribute handle + uint16_t handle; + /// Event Value + uint8_t data[__ARRAY_EMPTY]; +}; + +///Parameters of the @ref RDTSC_RX_FLOW_CTRL_REQ message +struct rdtsc_rx_flow_ctrl_req +{ + // flow control state + uint8_t flow_control_state; +}; + +///Parameters of the @ref RDTSC_TX_FLOW_CTRL_IND message +struct rdtsc_tx_flow_ctrl_ind +{ + // flow control state + uint8_t flow_control_state; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +extern const struct ke_state_handler rdtsc_default_handler; + +/* + * Functions + **************************************************************************************** + */ + +#endif //BLE_RDTS_CLIENT + +/// @} RDTSCTASK + +#endif // RDTS_CLIENT_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client.c new file mode 100644 index 0000000..4dd64a5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client.c @@ -0,0 +1,364 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdts_client.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + **************************************************************************************** + * @addtogroup RDTS_CLIENT + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_RDTS_CLIENT) +#include "prf.h" +#include "rdts_client.h" +#include "rdts_client_task.h" +#include "prf_utils.h" +#include "prf_utils_128.h" +#include "ke_mem.h" +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Profile Initialization + * @param[in] env enviroment + * @param[in] start_hdl start handle + * @param[in] app_task application task + * @param[in] sec_lvl security level + * @param[in] params configuration parameters + * @return void + **************************************************************************************** + */ +uint8_t rdtsc_init(struct prf_task_env *env, uint16_t *start_hdl, uint16_t app_task, uint8_t sec_lvl, struct rdtsc_db_cfg *params) +{ + //-------------------- allocate memory required for the profile --------------------- + + struct rdtsc_env_tag* rdtsc_env = + (struct rdtsc_env_tag* ) ke_malloc(sizeof(struct rdtsc_env_tag), KE_MEM_ATT_DB); + + // allocate RDTSC required environment variable + env->env = (prf_env_t*) rdtsc_env; + + rdtsc_env->prf_env.app_task = app_task | PERM(PRF_MI, DISABLE); + rdtsc_env->prf_env.prf_task = env->task | PERM(PRF_MI, DISABLE); + rdtsc_env->nb_svc = 0; + + // initialize environment variable + env->id = TASK_ID_RDTSC; + rdtsc_task_init(&(env->desc)); + + ke_state_set(rdtsc_env->prf_env.prf_task, RDTSC_IDLE); + + // save db cfg + memcpy(&(rdtsc_env->rdtsc_cfg),params,sizeof(struct rdtsc_db_cfg)); + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Profile enable confirmation + * @param[in] env_tag enviroment + * @param[in] conidx Connection index + * @param[in] status + * @return void + **************************************************************************************** + */ +void rdtsc_enable_cfm_send(struct rdtsc_env_tag *rdtsc_env, uint8_t conidx, uint8_t status) +{ + + struct rdtsc_enable_cfm * cfm = KE_MSG_ALLOC(RDTSC_ENABLE_CFM, + TASK_APP, + prf_src_task_get(&(rdtsc_env->prf_env), conidx), + rdtsc_enable_cfm); + + cfm->status = status; + + if (status == ATT_ERR_NO_ERROR) + { + cfm->rdts = rdtsc_env->rdts; + + prf_register_atthdl2gatt(&(rdtsc_env->prf_env), conidx, &rdtsc_env->rdts.svc); + + // Set value 0x0001 to CFG + prf_gatt_write_ntf_ind(&rdtsc_env->prf_env, conidx, rdtsc_env->rdts.descs[RDTSC_SRV_TX_DATA_CLI_CFG].desc_hdl, PRF_CLI_START_NTF); + + // Reset counter + rdtsc_env->pending_wr_no_rsp_cmp = 0; + rdtsc_env->pending_tx_ntf_cmp = false; + + //Place in connected state after discover state + ke_state_set(rdtsc_env->prf_env.prf_task, RDTSC_CONNECTED); + } + else + { + + } + + ke_msg_send(cfm); +} + +/** + **************************************************************************************** + * @brief Confirm that data has been sent + * @param[in] rdtsc_env enviroment + * @param[in] status + * @return void + **************************************************************************************** + */ +void rdtsc_confirm_data_tx(struct rdtsc_env_tag *rdtsc_env, uint8_t status) +{ + struct rdtsc_data_tx_cfm * cfm = KE_MSG_ALLOC(RDTSC_DATA_TX_CFM, + TASK_APP, + prf_src_task_get(&(rdtsc_env->prf_env), rdtsc_env->conidx), + rdtsc_data_tx_cfm); + + cfm->status = status; + + ke_msg_send(cfm); +} + +/** + **************************************************************************************** + * @brief Receives data and forwards it to application + * @param[in] rdtsc_env enviroment + * @param[in] message received + * @param[in] length + * @return void + **************************************************************************************** + */ + +void rdtsc_data_receive(struct rdtsc_env_tag *rdtsc_env, void *msg ) +{ + // Forward the message + struct ke_msg * kmsg = ke_param2msg(msg); + kmsg->dest_id = TASK_APP; + kmsg->src_id = prf_src_task_get(&(rdtsc_env->prf_env), rdtsc_env->conidx); + kmsg->id = RDTSC_DATA_RX_IND; + + struct rdtsc_data_rx_ind *req = ( struct rdtsc_data_rx_ind *) msg; + + ke_msg_send(req); +} + +/** + **************************************************************************************** + * @brief Find next empty characteristic description + * @param[in] rdtsc_env enviroment + * @param[in] desc_def service characteristic description information table + * @return position of next characteristic description + **************************************************************************************** + */ +uint8_t rdtsc_get_next_desc_char_code(struct rdtsc_env_tag *rdtsc_env, + const struct prf_char_desc_def *desc_def) +{ + uint8_t i; + uint8_t next_char_code; + + for (i=0; i rdtsc_env->last_char_code) + { + //If Char. has been found and number of attributes is upper than 2 + if ((rdtsc_env->rdts.chars[next_char_code].char_hdl != 0) + & (rdtsc_env->rdts.chars[next_char_code].char_ehdl_off > 2)) + { + return next_char_code; + } + } + } + + return RDTSC_CHAR_MAX; +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] env environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void rdtsc_create(struct prf_task_env *env, uint8_t conidx) +{ + struct rdtsc_env_tag *rdts_env = PRF_ENV_GET(RDTSC, rdtsc); + + ke_state_set(env->task, RDTSC_CONNECTED); +} +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void rdtsc_cleanup(struct prf_task_env *env, uint8_t conidx, uint8_t reason) +{ + struct rdtsc_env_tag *rdts_env = PRF_ENV_GET(RDTSC, rdtsc); + rdts_env->nb_svc = 0; +} +/** + **************************************************************************************** + * @brief Destruction of the rdts module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void rdtsc_destroy(struct prf_task_env *env) +{ + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC, rdtsc); + + // free profile environment variables + env->env = NULL; + ke_free(rdtsc_env); +} +/** + **************************************************************************************** + * @brief Receives data and forwards it to application + * @param[in] msg voi pointer to RDTSC_DATA_TX_REQ message + * @param[in] prf_env rdtsc profile enviroment + * @param[in] conidx connection index + * @param[in] handle RDTSC_SRV_RX_DATA_CHAR handle + * @param[in] value data pointer to be written + * @param[in] operation GATTC_WRITE_NO_RESPONSE + * @return void + **************************************************************************************** + */ +void rdtsc_write_data_tx(void *msg, prf_env_t *prf_env, uint8_t conidx, uint16_t handle, uint8_t* value, uint16_t length, uint8_t operation) +{ + if(handle != ATT_INVALID_HANDLE) + { + struct ke_msg * kmsg = ke_param2msg(msg); + + kmsg->dest_id = KE_BUILD_ID(TASK_GATTC, conidx); + kmsg->src_id = prf_src_task_get(prf_env, conidx); + kmsg->id = GATTC_WRITE_CMD; + + struct gattc_write_cmd *wr_char = ( struct gattc_write_cmd *) msg; + + // Offset + wr_char->offset = 0x0000; + // cursor always 0 + wr_char->cursor = 0x0000; + // Write Type + wr_char->operation = operation; + // Characteristic Value attribute handle + wr_char->handle = handle; + // Value Length + wr_char->length = length; + // Auto Execute + wr_char->auto_execute = true; + // Value + + // Send the message + ke_msg_send(wr_char); + } +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// RDTS Task interface required by profile manager +const struct prf_task_cbs spc_itf = +{ + (prf_init_fnct) rdtsc_init, + rdtsc_destroy, + rdtsc_create, + rdtsc_cleanup, +}; + + /* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Retrieve RDTS profile interface + * + * @return RDTS service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* rdtsc_prf_itf_get(void) +{ + return &spc_itf; +} + +#endif //BLE_RDTS_CLIENT + +/// @} RDTS_CLIENT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client_16bit.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client_16bit.c new file mode 100644 index 0000000..7544043 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client_16bit.c @@ -0,0 +1,360 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdts_client_16bit.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + **************************************************************************************** + * @addtogroup RDTS_CLIENT + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_RDTS_16BIT_CLIENT) +#include "prf.h" +#include "rdts_client_16bit.h" +#include "rdts_client_16bit_task.h" +#include "prf_utils.h" +#include "ke_mem.h" +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Profile Initialization + * @param[in] env enviroment + * @param[in] start_hdl start handle + * @param[in] app_task application task + * @param[in] sec_lvl security level + * @param[in] params configuration parameters + * @return void + **************************************************************************************** + */ +uint8_t rdtsc_16bit_init(struct prf_task_env *env, uint16_t *start_hdl, uint16_t app_task, uint8_t sec_lvl, struct rdtsc_db_cfg *params) +{ + //-------------------- allocate memory required for the profile --------------------- + + struct rdtsc_env_tag* rdtsc_env = + (struct rdtsc_env_tag* ) ke_malloc(sizeof(struct rdtsc_env_tag), KE_MEM_ATT_DB); + + // allocate RDTSC required environment variable + env->env = (prf_env_t*) rdtsc_env; + rdtsc_env->prf_env.app_task = app_task | PERM(PRF_MI, DISABLE); + rdtsc_env->prf_env.prf_task = env->task | PERM(PRF_MI, DISABLE); + rdtsc_env->nb_svc = 0; + + // initialize environment variable + env->id = TASK_ID_RDTSC_16BIT; + rdtsc_16bit_task_init(&(env->desc)); + + ke_state_set(rdtsc_env->prf_env.prf_task, RDTSC_IDLE); + + // save db cfg + memcpy(&(rdtsc_env->rdtsc_cfg),params,sizeof(struct rdtsc_db_cfg)); + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Profile enable confirmation + * @param[in] env_tag enviroment + * @param[in] conidx Connection index + * @param[in] status + * @return void + **************************************************************************************** + */ +void rdtsc_16bit_enable_cfm_send(struct rdtsc_env_tag *rdtsc_env, uint8_t conidx, uint8_t status) +{ + + struct rdtsc_enable_cfm * cfm = KE_MSG_ALLOC(RDTSC_ENABLE_CFM, + TASK_APP, + prf_src_task_get(&(rdtsc_env->prf_env), conidx), + rdtsc_enable_cfm); + + cfm->status = status; + if (status == ATT_ERR_NO_ERROR) + { + cfm->rdts = rdtsc_env->rdts; + + prf_register_atthdl2gatt(&(rdtsc_env->prf_env), conidx, &rdtsc_env->rdts.svc); + + // Set value 0x0001 to CFG + prf_gatt_write_ntf_ind(&rdtsc_env->prf_env, conidx, rdtsc_env->rdts.descs[RDTSC_SRV_TX_DATA_CLI_CFG].desc_hdl, PRF_CLI_START_NTF); + + // Reset counter + rdtsc_env->pending_wr_no_rsp_cmp = 0; + rdtsc_env->pending_tx_ntf_cmp = false; + + //Place in connected state after discover state + ke_state_set(rdtsc_env->prf_env.prf_task, RDTSC_CONNECTED); + } + else + { + + } + + ke_msg_send(cfm); +} + +/** + **************************************************************************************** + * @brief Confirm that data has been sent + * @param[in] rdtsc_env enviroment + * @param[in] status + * @return void + **************************************************************************************** + */ +void rdtsc_16bit_confirm_data_tx(struct rdtsc_env_tag *rdtsc_env, uint8_t status) +{ + struct rdtsc_data_tx_cfm * cfm = KE_MSG_ALLOC(RDTSC_DATA_TX_CFM, + TASK_APP, + prf_src_task_get(&(rdtsc_env->prf_env), rdtsc_env->conidx), + rdtsc_data_tx_cfm); + cfm->status = status; + + ke_msg_send(cfm); +} + +/** + **************************************************************************************** + * @brief Receives data and forwards it to application + * @param[in] rdtsc_env enviroment + * @param[in] message received + * @param[in] length + * @return void + **************************************************************************************** + */ + +void rdtsc_16bit_data_receive(struct rdtsc_env_tag *rdtsc_env, void *msg ) +{ + // Forward the message + struct ke_msg * kmsg = ke_param2msg(msg); + kmsg->dest_id = TASK_APP; + kmsg->src_id = prf_src_task_get(&(rdtsc_env->prf_env), rdtsc_env->conidx); + kmsg->id = RDTSC_DATA_RX_IND; + + struct rdtsc_data_rx_ind *req = ( struct rdtsc_data_rx_ind *) msg; + + ke_msg_send(req); +} + +/** + **************************************************************************************** + * @brief Find next empty characteristic description + * @param[in] rdtsc_env enviroment + * @param[in] desc_def service characteristic description information table + * @return position of next characteristic description + **************************************************************************************** + */ +uint8_t rdtsc_16bit_get_next_desc_char_code(struct rdtsc_env_tag *rdtsc_env, + const struct prf_char_desc_def *desc_def) +{ + uint8_t i; + uint8_t next_char_code; + + for (i=0; i rdtsc_env->last_char_code) + { + //If Char. has been found and number of attributes is upper than 2 + if ((rdtsc_env->rdts.chars[next_char_code].char_hdl != 0) + & (rdtsc_env->rdts.chars[next_char_code].char_ehdl_off > 2)) + { + return next_char_code; + } + } + } + + return RDTSC_CHAR_MAX; +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] env environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void rdtsc_16bit_create(struct prf_task_env *env, uint8_t conidx) +{ + struct rdtsc_env_tag *rdts_env = PRF_ENV_GET(RDTSC, rdtsc); + + ke_state_set(env->task, RDTSC_CONNECTED); +} +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void rdtsc_16bit_cleanup(struct prf_task_env *env, uint8_t conidx, uint8_t reason) +{ + struct rdtsc_env_tag *rdts_env = PRF_ENV_GET(RDTSC, rdtsc); + rdts_env->nb_svc = 0; +} +/** + **************************************************************************************** + * @brief Destruction of the rdts module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void rdtsc_16bit_destroy(struct prf_task_env *env) +{ + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC, rdtsc); + + // free profile environment variables + env->env = NULL; + ke_free(rdtsc_env); +} +/** + **************************************************************************************** + * @brief Receives data and forwards it to application + * @param[in] msg voi pointer to RDTSC_DATA_TX_REQ message + * @param[in] prf_env rdtsc profile enviroment + * @param[in] conidx connection index + * @param[in] handle RDTSC_SRV_RX_DATA_CHAR handle + * @param[in] value data pointer to be written + * @param[in] operation GATTC_WRITE_NO_RESPONSE + * @return void + **************************************************************************************** + */ +void rdtsc_16bit_write_data_tx(void *msg, prf_env_t *prf_env, uint8_t conidx, uint16_t handle, uint8_t* value, uint16_t length, uint8_t operation) +{ + if(handle != ATT_INVALID_HANDLE) + { + struct ke_msg * kmsg = ke_param2msg(msg); + + kmsg->dest_id = KE_BUILD_ID(TASK_GATTC, conidx); + kmsg->src_id = prf_src_task_get(prf_env, conidx); + kmsg->id = GATTC_WRITE_CMD; + + struct gattc_write_cmd *wr_char = ( struct gattc_write_cmd *) msg; + + // Offset + wr_char->offset = 0x0000; + // cursor always 0 + wr_char->cursor = 0x0000; + // Write Type + wr_char->operation = operation; + // Characteristic Value attribute handle + wr_char->handle = handle; + // Value Length + wr_char->length = length; + // Auto Execute + wr_char->auto_execute = true; + // Value + + // Send the message + ke_msg_send(wr_char); + } +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// RDTS Task interface required by profile manager +const struct prf_task_cbs spc_itf = +{ + (prf_init_fnct) rdtsc_16bit_init, + rdtsc_16bit_destroy, + rdtsc_16bit_create, + rdtsc_16bit_cleanup, +}; + + /* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Retrieve RDTS profile interface + * + * @return RDTS service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* rdtsc_16bit_prf_itf_get(void) +{ + return &spc_itf; +} + +#endif //BLE_RDTS_16BIT_CLIENT + +/// @} RDTS_CLIENT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client_16bit_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client_16bit_task.c new file mode 100644 index 0000000..a0e36a0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client_16bit_task.c @@ -0,0 +1,327 @@ + /** + * Copyright (c) 2025, NSING Technologies Inc. + * + * All rights reserved. + * + * This software is the exclusive property of NSING Technologies Inc. (Hereinafter + * referred to as NSING). This software, and the product of NSING described herein + * (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties + * of the People's Republic of China and other applicable jurisdictions worldwide. + * + * NSING does not grant any license under its patents, copyrights, trademarks, or other + * intellectual property rights. Names and brands of third party may be mentioned or referred + * thereto (if any) for identification purposes only. + * + * NSING reserves the right to make changes, corrections, enhancements, modifications, and + * improvements to this software at any time without notice. Please contact NSING and obtain + * the latest version of this software before placing orders. + + * Although NSING has attempted to provide accurate and reliable information, NSING assumes + * no responsibility for the accuracy and reliability of this software. + * + * It is the responsibility of the user of this software to properly design, program, and test + * the functionality and safety of any application made of this information and any resulting product. + * In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or + * consequential damages arising in any way out of the use of this software or the Product. + * + * NSING Products are neither intended nor warranted for usage in systems or equipment, any + * malfunction or failure of which may cause loss of human life, bodily injury or severe property + * damage. Such applications are deemed, "Insecure Usage". + * + * All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING + * harmless from and against all claims, costs, damages, and other liabilities, arising from or related + * to any customer's Insecure Usage. + + * Any express or implied warranty with regard to this software or the Product, including,but not + * limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement + * are disclaimed to the fullest extent permitted by law. + + * Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe + * or otherwise distribute this software for any purposes, in whole or in part. + * + * NSING products and technologies shall not be used for or incorporated into any products or systems + * whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. + * User shall comply with any applicable export control laws and regulations promulgated and administered by + * the governments of any countries asserting jurisdiction over the parties or transactions. + **/ + + +/** + * @file rdts_client_16bit_task.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +/** + **************************************************************************************** + * @addtogroup RDTSC_TASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_RDTS_16BIT_CLIENT) +#include "gap.h" +#include "gattc_task.h" +#include "prf.h" +#include "rdts_client_16bit.h" +#include "rdts_client_16bit_task.h" +#include "prf_utils.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * EXTERNAL DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Enable the RDTS client role, used after connection. + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int rdtsc_16bit_enable_req_handler(ke_msg_id_t const msgid, + struct rdtsc_enable_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + // RDTS Client Role Task Environment + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC_16BIT, rdtsc); + + if (param->con_type == PRF_CON_DISCOVERY) + { + // Start discovering RDTS on peer + prf_disc_svc_send(&rdtsc_env->prf_env, param->conidx, rdtsc_env->rdtsc_cfg.uuid16); + // Set state to discovering + ke_state_set(dest_id, RDTSC_DISCOVERING ); + rdtsc_env->nb_svc = 0; + + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_DISC_SVC_IND message. + * Get the start and ending handle of rdts in the enviroment. + * @param[in] msgid Id of the message received . + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + if (ke_state_get(dest_id) == RDTSC_DISCOVERING) + { + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC_16BIT, rdtsc); + + if (rdtsc_env->nb_svc == 0) + { + // Retrieve DIS characteristics + prf_extract_svc_info(param, RDTSC_CHAR_MAX, rdtsc_env->rdtsc_cfg.p_char, &(rdtsc_env->rdts.chars[0]), + RDTSC_DESC_MAX, rdtsc_env->rdtsc_cfg.p_desc, &(rdtsc_env->rdts.descs[0])); + + //Even if we get multiple responses we only store 1 range + rdtsc_env->rdts.svc.shdl = param->start_hdl; + rdtsc_env->rdts.svc.ehdl = param->end_hdl; + } + rdtsc_env->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT for GATTC_NOTIFY message meaning that + * notification has been correctly sent to peer device (but not confirmed by peer device). + * * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(src_id); + + // Get the address of the environment + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC_16BIT, rdtsc); + uint8_t status = param->status;; + if(state == RDTSC_DISCOVERING) + { + if (status == ATT_ERR_NO_ERROR) + { + if (rdtsc_env->nb_svc == 1) + { + status = prf_check_svc_char_validity(RDTSC_CHAR_MAX, rdtsc_env->rdts.chars, + rdtsc_env->rdtsc_cfg.p_char); + } + // too much services + else if (rdtsc_env->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(RDTSC_DESC_MAX, + rdtsc_env->rdts.descs, + rdtsc_env->rdtsc_cfg.p_desc, + rdtsc_env->rdts.chars); + } + } + + rdtsc_16bit_enable_cfm_send(rdtsc_env, conidx, status); + } + else if (state == RDTSC_CONNECTED) + { + if(param->operation == GATTC_WRITE_NO_RESPONSE) + { + rdtsc_env->pending_wr_no_rsp_cmp--; + if (!rdtsc_env->pending_wr_no_rsp_cmp && rdtsc_env->pending_tx_ntf_cmp) + { + rdtsc_env->pending_tx_ntf_cmp = false; + rdtsc_16bit_confirm_data_tx(rdtsc_env, param->status); + } + } + else if(param->operation == GATTC_WRITE) + { + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +static int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC_16BIT, rdtsc); + + if (rdtsc_env->rdts.chars[RDTSC_SRV_RX_DATA_CHAR].val_hdl == param->handle) + { + + rdtsc_16bit_data_receive( rdtsc_env, (void *)param); + return (KE_MSG_NO_FREE); + } + + return (KE_MSG_CONSUMED); + +} + +/** + **************************************************************************************** + * @brief Data transmitt request handler + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +static int rdtsc_16bit_data_tx_req_handler(ke_msg_id_t const msgid, + struct rdtsc_data_tx_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC_16BIT, rdtsc); + uint8_t conidx = rdtsc_env->conidx; + + if (ke_state_get(rdtsc_env->prf_env.prf_task)==RDTSC_CONNECTED) + { + rdtsc_16bit_write_data_tx((void *)param, &rdtsc_env->prf_env, conidx, rdtsc_env->rdts.chars[RDTSC_SRV_TX_DATA_CHAR].val_hdl, (uint8_t *)param->data, sizeof(uint8_t) * param->length, GATTC_WRITE_NO_RESPONSE); + rdtsc_env->pending_tx_ntf_cmp = true; + rdtsc_env->pending_wr_no_rsp_cmp++; + return (KE_MSG_NO_FREE); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +//const struct ke_msg_handler rdtsc_default_state[] = +KE_MSG_HANDLER_TAB(rdtsc_16bit) +{ + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {RDTSC_DATA_TX_REQ, (ke_msg_func_t)rdtsc_16bit_data_tx_req_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {RDTSC_ENABLE_REQ, (ke_msg_func_t)rdtsc_16bit_enable_req_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void rdtsc_16bit_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct rdtsc_env_tag *p_rdtsc_env = PRF_ENV_GET(RDTSC_16BIT, rdtsc); + + p_task_desc->msg_handler_tab = rdtsc_16bit_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(rdtsc_16bit_msg_handler_tab); + p_task_desc->state = p_rdtsc_env->state; + p_task_desc->idx_max = RDTSC_IDX_MAX; +} + +#endif //BLE_RDTS_16BIT_CLIENT + +/// @} RDTSC_TASK + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client_task.c new file mode 100644 index 0000000..b5474cd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtsc/src/rdts_client_task.c @@ -0,0 +1,420 @@ + /** + * Copyright (c) 2025, NSING Technologies Inc. + * + * All rights reserved. + * + * This software is the exclusive property of NSING Technologies Inc. (Hereinafter + * referred to as NSING). This software, and the product of NSING described herein + * (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties + * of the People's Republic of China and other applicable jurisdictions worldwide. + * + * NSING does not grant any license under its patents, copyrights, trademarks, or other + * intellectual property rights. Names and brands of third party may be mentioned or referred + * thereto (if any) for identification purposes only. + * + * NSING reserves the right to make changes, corrections, enhancements, modifications, and + * improvements to this software at any time without notice. Please contact NSING and obtain + * the latest version of this software before placing orders. + + * Although NSING has attempted to provide accurate and reliable information, NSING assumes + * no responsibility for the accuracy and reliability of this software. + * + * It is the responsibility of the user of this software to properly design, program, and test + * the functionality and safety of any application made of this information and any resulting product. + * In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or + * consequential damages arising in any way out of the use of this software or the Product. + * + * NSING Products are neither intended nor warranted for usage in systems or equipment, any + * malfunction or failure of which may cause loss of human life, bodily injury or severe property + * damage. Such applications are deemed, "Insecure Usage". + * + * All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING + * harmless from and against all claims, costs, damages, and other liabilities, arising from or related + * to any customer's Insecure Usage. + + * Any express or implied warranty with regard to this software or the Product, including,but not + * limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement + * are disclaimed to the fullest extent permitted by law. + + * Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe + * or otherwise distribute this software for any purposes, in whole or in part. + * + * NSING products and technologies shall not be used for or incorporated into any products or systems + * whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. + * User shall comply with any applicable export control laws and regulations promulgated and administered by + * the governments of any countries asserting jurisdiction over the parties or transactions. + **/ + + +/** + * @file rdts_client_task.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +/** + **************************************************************************************** + * @addtogroup RDTSC_TASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_RDTS_CLIENT) +#include "gap.h" +#include "gattc_task.h" +#include "prf.h" +#include "rdts_client.h" +#include "rdts_client_task.h" +#include "prf_utils.h" +#include "prf_utils_128.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * EXTERNAL DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Enable the RDTS client role, used after connection. + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int rdtsc_enable_req_handler(ke_msg_id_t const msgid, + struct rdtsc_enable_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + // RDTS Client Role Task Environment + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC, rdtsc); + + if (param->con_type == PRF_CON_DISCOVERY) + { + // Start discovering RDTS on peer + rdtsc_env->last_uuid_req = ATT_DECL_PRIMARY_SERVICE; + memcpy(rdtsc_env->last_svc_req, rdtsc_env->rdtsc_cfg.p_uuid128, ATT_UUID_128_LEN); + prf_disc_svc_send_128(&rdtsc_env->prf_env, rdtsc_env->last_svc_req, param->conidx); + // Set state to discovering + ke_state_set(dest_id, RDTSC_DISCOVERING ); + rdtsc_env->nb_svc = 0; + + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_DISC_SVC_IND message. + * Get the start and ending handle of rdts in the enviroment. + * @param[in] msgid Id of the message received . + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_disc_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_disc_svc_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC, rdtsc); + + // Even if we get multiple responses we only store 1 range + rdtsc_env->rdts.svc.shdl = param->start_hdl; + rdtsc_env->rdts.svc.ehdl = param->end_hdl; + rdtsc_env->nb_svc++; + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_DISC_CHAR_IND message. + * Characteristics for the currently desired service handle range are obtained and kept. + * @param[in] msgid Id of the message received . + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_disc_char_ind_handler(ke_msg_id_t const msgid, + struct gattc_disc_char_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC, rdtsc); + + prf_search_chars_128(rdtsc_env->rdts.svc.ehdl, RDTSC_CHAR_MAX, &rdtsc_env->rdts.chars[0], &rdtsc_env->rdtsc_cfg.p_char[0], param, &rdtsc_env->last_char_code); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_DISC_CHAR_DESC_IND message. + * This event can be received 2-4 times, depending if measurement interval has seevral properties. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +static int gattc_disc_char_desc_ind_handler(ke_msg_id_t const msgid, + struct gattc_disc_char_desc_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC, rdtsc); + + // Retrieve RDTS descriptors + prf_search_descs(RDTSC_DESC_MAX, &rdtsc_env->rdts.descs[0], &rdtsc_env->rdtsc_cfg.p_desc[0], param, rdtsc_env->last_char_code); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT for GATTC_NOTIFY message meaning that + * notification has been correctly sent to peer device (but not confirmed by peer device). + * * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(src_id); + + // Get the address of the environment + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC, rdtsc); + uint8_t status; + + if(state == RDTSC_DISCOVERING) + { + if ((param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)||(param->status == ATT_ERR_NO_ERROR)) + { + //Currently discovering rdts_server Service + if (!memcmp(rdtsc_env->last_svc_req, rdtsc_env->rdtsc_cfg.p_uuid128, ATT_UUID_128_LEN)) + { + if (rdtsc_env->last_uuid_req == ATT_DECL_PRIMARY_SERVICE) + { + if (rdtsc_env->rdts.svc.shdl == ATT_INVALID_HANDLE) + { + // stop discovery procedure. + rdtsc_enable_cfm_send(rdtsc_env, conidx, PRF_ERR_STOP_DISC_CHAR_MISSING); + } + // Too many services found only one such service should exist + else if(rdtsc_env->nb_svc > 1) + { + // stop discovery procedure. + rdtsc_enable_cfm_send(rdtsc_env, conidx, PRF_ERR_MULTIPLE_SVC); + } + else + { + // Discover RDTS Device characteristics + prf_disc_char_all_send(&(rdtsc_env->prf_env), &(rdtsc_env->rdts.svc), conidx); + + // Keep last UUID requested and for which service in env + rdtsc_env->last_uuid_req = ATT_DECL_CHARACTERISTIC; + } + } + else if (rdtsc_env->last_uuid_req == ATT_DECL_CHARACTERISTIC) + { + status = prf_check_svc_char_validity_128(RDTSC_CHAR_MAX, rdtsc_env->rdts.chars, rdtsc_env->rdtsc_cfg.p_char); + + // Check for characteristic properties. + if (status == ATT_ERR_NO_ERROR) + { + rdtsc_env->last_uuid_req = ATT_INVALID_HANDLE; + rdtsc_env->last_char_code = rdtsc_env->rdtsc_cfg.p_desc[RDTSC_SRV_TX_DATA_CLI_CFG].char_code; + + rdtsc_env->conidx = conidx; + + //Discover characteristic descriptor + prf_disc_char_desc_send(&(rdtsc_env->prf_env), &(rdtsc_env->rdts.chars[rdtsc_env->last_char_code]), conidx); + } + else + { + // Stop discovery procedure. + rdtsc_enable_cfm_send(rdtsc_env, conidx, status); + } + } + else //Descriptors + { + //Get code of next char. having descriptors + rdtsc_env->last_char_code = rdtsc_get_next_desc_char_code(rdtsc_env, &rdtsc_env->rdtsc_cfg.p_desc[0]); + if (rdtsc_env->last_char_code != RDTSC_CHAR_MAX) + { + prf_disc_char_desc_send(&(rdtsc_env->prf_env), &(rdtsc_env->rdts.chars[rdtsc_env->last_char_code]), conidx); + } + else + { + status = prf_check_svc_char_desc_validity(RDTSC_DESC_MAX, + rdtsc_env->rdts.descs, + rdtsc_env->rdtsc_cfg.p_desc, + rdtsc_env->rdts.chars); + + rdtsc_env->nb_svc = 0; + rdtsc_enable_cfm_send(rdtsc_env,conidx, status); + } + } + } + } + else + { + rdtsc_enable_cfm_send(rdtsc_env, conidx, param->status); + } + } + else if (state == RDTSC_CONNECTED) + { + if(param->operation == GATTC_WRITE_NO_RESPONSE) + { + rdtsc_env->pending_wr_no_rsp_cmp--; + if (!rdtsc_env->pending_wr_no_rsp_cmp && rdtsc_env->pending_tx_ntf_cmp) + { + rdtsc_env->pending_tx_ntf_cmp = false; + rdtsc_confirm_data_tx(rdtsc_env, param->status); + } + } + else if(param->operation == GATTC_WRITE) + { + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +static int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC, rdtsc); + + if (rdtsc_env->rdts.chars[RDTSC_SRV_TX_DATA_CHAR].val_hdl == param->handle) + { + + rdtsc_data_receive( rdtsc_env, (void *)param); + return (KE_MSG_NO_FREE); + } + + return (KE_MSG_CONSUMED); + +} + +/** + **************************************************************************************** + * @brief Data transmitt request handler + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +static int rdtsc_data_tx_req_handler(ke_msg_id_t const msgid, + struct rdtsc_data_tx_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct rdtsc_env_tag *rdtsc_env = PRF_ENV_GET(RDTSC, rdtsc); + + uint8_t conidx = param->cursor; + + if (ke_state_get(rdtsc_env->prf_env.prf_task)==RDTSC_CONNECTED) + { + rdtsc_write_data_tx((void *)param, &rdtsc_env->prf_env, conidx, rdtsc_env->rdts.chars[RDTSC_SRV_RX_DATA_CHAR].val_hdl, + (uint8_t *)param->data, sizeof(uint8_t) * param->length, GATTC_WRITE_NO_RESPONSE); + rdtsc_env->pending_tx_ntf_cmp = true; + rdtsc_env->pending_wr_no_rsp_cmp++; + + return (KE_MSG_NO_FREE); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +//const struct ke_msg_handler rdtsc_default_state[] = +KE_MSG_HANDLER_TAB(rdtsc) +{ + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {RDTSC_DATA_TX_REQ, (ke_msg_func_t)rdtsc_data_tx_req_handler}, + {GATTC_DISC_CHAR_IND, (ke_msg_func_t)gattc_disc_char_ind_handler}, + {GATTC_DISC_SVC_IND, (ke_msg_func_t)gattc_disc_svc_ind_handler}, + {GATTC_DISC_CHAR_DESC_IND, (ke_msg_func_t)gattc_disc_char_desc_ind_handler}, + {RDTSC_ENABLE_REQ, (ke_msg_func_t)rdtsc_enable_req_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void rdtsc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct rdtsc_env_tag *p_rdtsc_env = PRF_ENV_GET(RDTSC, rdtsc); + + p_task_desc->msg_handler_tab = rdtsc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(rdtsc_msg_handler_tab); + p_task_desc->state = p_rdtsc_env->state; + p_task_desc->idx_max = RDTSC_IDX_MAX; +} + +#endif //BLE_RDTS_CLIENT + +/// @} RDTSC_TASK + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss.h new file mode 100644 index 0000000..863f07c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss.h @@ -0,0 +1,143 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdtss.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef _RDTSS_H_ +#define _RDTSS_H_ + + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + + /* Includes ------------------------------------------------------------------*/ +#include +#include "prf_types.h" +#include "prf.h" +#include "attm.h" + +#include "rdts_common.h" + +#define RDTSS_IDX_MAX (1) + +/* Public typedef -----------------------------------------------------------*/ +/// Parameters for the database creation +struct rdtss_db_cfg +{ + ///max number of casts1 service characteristics + uint8_t max_nb_att; + const struct attm_desc_128 *att_tbl; + const uint8_t *svc_uuid; + +}; + +/// Value element +struct rdtss_val_elmt +{ + /// list element header + struct co_list_hdr hdr; + /// value identifier + uint8_t att_idx; + /// value length + uint8_t length; + /// value data + uint8_t data[__ARRAY_EMPTY]; +}; + +/// rdtss environment variable +struct rdtss_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Service Start Handle + uint16_t shdl; + /// To store the DB max number of attributes + uint8_t max_nb_att; + /// On-going operation + struct ke_msg *operation; + + /// Cursor on connection used to notify peer devices + uint8_t cursor; + /// CCC handle index, used during notification/indication busy state + uint8_t ccc_idx; + + /// List of values set by application + struct co_list values; + /// RDTSS task state + ke_state_t state[RDTSS_IDX_MAX]; + /// RDTSS data base configer + struct rdtss_db_cfg db_cfg; +}; + +//extern struct rdtss_db_cfg db_cfg; +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Disable actions grouped in getting back to IDLE and sending configuration to requester task + * @param[in] conhdl Connection Handle + */ +void rdtss_disable(uint16_t conhdl); + +const struct prf_task_cbs *rdtss_prf_itf_get(void); + +/** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + */ +void rdtss_task_init(struct ke_task_desc *p_task_desc); + +#endif // (BLE_RDTSS_SERVER) + +#endif // _RDTSS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss_16bit.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss_16bit.h new file mode 100644 index 0000000..2c66580 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss_16bit.h @@ -0,0 +1,143 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdtss_16bit.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _RDTSS_16BIT_H_ +#define _RDTSS_16BIT_H_ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_16BIT_SERVER) + + /* Includes ------------------------------------------------------------------*/ +#include +#include "prf_types.h" +#include "prf.h" +#include "attm.h" + +#include "rdts_common.h" + +#define RDTSS_16BIT_IDX_MAX (1) + +/* Public typedef -----------------------------------------------------------*/ + +/// Parameters for the database creation +struct rdtss_16bit_db_cfg +{ + ///max number of service characteristics + uint8_t max_nb_att; + const struct attm_desc* att_tbl; + const uint16_t *svc_uuid; + +}; + +/// Value element +struct rdtss_16bit_val_elmt +{ + /// list element header + struct co_list_hdr hdr; + /// value identifier + uint8_t att_idx; + /// value length + uint8_t length; + /// value data + uint8_t data[__ARRAY_EMPTY]; +}; + +/// rdtss environment variable +struct rdtss_16bit_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Service Start Handle + uint16_t shdl; + /// To store the DB max number of attributes + uint8_t max_nb_att; + /// On-going operation + struct ke_msg *operation; + + /// Cursor on connection used to notify peer devices + uint8_t cursor; + /// CCC handle index, used during notification/indication busy state + uint8_t ccc_idx; + + /// List of values set by application + struct co_list values; + /// rdtss_16bit task state + ke_state_t state[RDTSS_16BIT_IDX_MAX]; + /// rdtss_16bit db configer + struct rdtss_16bit_db_cfg db_cfg; +}; + +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Disable actions grouped in getting back to IDLE and sending configuration to requester task + * @param[in] conhdl Connection Handle + */ +void rdtss_16bit_disable(uint16_t conhdl); + +const struct prf_task_cbs *rdtss_16bit_prf_itf_get(void); + +/** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + */ +void rdtss_16bit_task_init(struct ke_task_desc *p_task_desc); + +#endif // (BLE_RDTSS_16BIT_SERVER) + +#endif // _RDTSS_16BIT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss_16bit_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss_16bit_task.h new file mode 100644 index 0000000..26485a7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss_16bit_task.h @@ -0,0 +1,288 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdtss_16bit_task.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef __RDTSS_16BIT_TASK_PRF_H +#define __RDTSS_16BIT_TASK_PRF_H + + /* Includes ------------------------------------------------------------------*/ +#if (BLE_RDTSS_16BIT_SERVER) + +#include +#include "ke_task.h" +#include "prf_types.h" +#include "compiler.h" // compiler definition +#include "att.h" +#include "attm.h" + +#include "rwip_task.h" +/* Public typedef -----------------------------------------------------------*/ + +/// Possible states of the rdtss_16bit task +enum rdtss_16bit_state +{ + /// Idle state + RDTSS_16BIT_IDLE, + /// Busy state + RDTSS_16BIT_BUSY, + /// Number of defined states. + RDTSS_16BIT_STATE_MAX, +}; + +/// Messages for RDTSS_16BIT +enum +{ + /// Add a rdtss_16bit instance into the database + RDTSS_16BIT_CREATE_DB_REQ = TASK_FIRST_MSG(TASK_ID_RDTSS_16BIT), + /// Inform APP of database creation status + RDTSS_16BIT_CREATE_DB_CFM, + + /// Start the Custom Service Task - at connection + RDTSS_16BIT_ENABLE_REQ, + /// Set/update characteristic value + RDTSS_16BIT_VAL_SET_REQ, + /// Peer device request to get a non-database value (RI enabled) + RDTSS_16BIT_VALUE_REQ_IND, + /// Response to non-database value request + RDTSS_16BIT_VALUE_REQ_RSP, + /// Set/update characteristic value and trigger a notification + RDTSS_16BIT_VAL_NTF_REQ, + /// Response after receiving a RDTSS_16BIT_VAL_NTF_REQ message and a notification is triggered + RDTSS_16BIT_VAL_NTF_CFM, + /// Set/update characteristic value and trigger an indication + RDTSS_16BIT_VAL_IND_REQ, + ///Response after receiving a RDTSS_16BIT_VAL_IND_REQ message and an indication is triggered + RDTSS_16BIT_VAL_IND_CFM, + /// Indicate that the characteristic value has been written + RDTSS_16BIT_VAL_WRITE_IND, + /// Inform the application that the profile service role task has been disabled after a disconnection + RDTSS_16BIT_DISABLE_IND, + /// Profile error report + RDTSS_16BIT_ERROR_IND, + /// Inform the application that there is an attribute info request that shall be processed + RDTSS_16BIT_ATT_INFO_REQ, + /// Inform back that the attribute info request has been processed + RDTSS_16BIT_ATT_INFO_RSP, +}; + + + +/// Parameters of the @ref RDTSS_16BIT_CREATE_DB_CFM message +struct rdtss_16bit_create_db_cfm +{ + ///Status + uint8_t status; +}; + +/// Parameters of the @ref RDTSS_16BIT_ENABLE_REQ message +struct rdtss_16bit_enable_req +{ + /// Connection index + uint8_t conidx; + /// security level: b0= nothing, b1=unauthenticated, b2=authenticated, b3=authorized; b1 or b2 and b3 can go together + uint8_t sec_lvl; + /// Type of connection + uint8_t con_type; +}; + +/// Parameters of the @ref RDTSS_16BIT_DISABLE_IND message +struct rdtss_16bit_disable_ind +{ + /// Connection index + uint8_t conidx; +}; + +/// Parameters of the @ref RDTSS_16BIT_VAL_WRITE_IND massage +struct rdtss_16bit_val_write_ind +{ + /// Connection index + uint8_t conidx; + /// Handle of the attribute that has to be written + uint16_t handle; + /// Data length to be written + uint16_t length; + /// Data to be written in attribute database + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref RDTSS_16BIT_VAL_NTF_CFM massage +struct rdtss_16bit_val_ntf_cfm +{ + /// Connection index +// uint8_t conidx; + /// Handle of the attribute that has been updated + uint16_t handle; + /// Confirmation status + uint8_t status; +}; + +/// Parameters of the @ref RDTSS_16BIT_VAL_IND_CFM massage +struct rdtss_16bit_val_ind_cfm +{ + /// Connection index + uint8_t conidx; + /// Handle of the attribute that has been updated + uint16_t handle; + /// Confirmation status + uint8_t status; +}; + +/// Parameters of the @ref RDTSS_16BIT_VAL_SET_REQ massage +struct rdtss_16bit_val_set_req +{ + /// Connection index + uint8_t conidx; + /// Handle of the attribute that has to be written + uint16_t handle; + /// Data length to be written + uint16_t length; + /// Data to be written in attribute database + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref RDTSS_16BIT_VAL_REQ_IND message +struct rdtss_16bit_value_req_ind +{ + /// Connection index + uint8_t conidx; + /// Index of the attribute for which value has been requested + uint16_t att_idx; +}; + +/// Parameters of the @ref RDTSS_16BIT_VAL_REQ_RSP message +struct rdtss_16bit_value_req_rsp +{ + /// Connection index + uint8_t conidx; + /// Index of the attribute for which value has been requested + uint16_t att_idx; + /// Current length of that attribute + uint16_t length; + /// ATT error code + uint8_t status; + /// Data value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref RDTSS_16BIT_VAL_NTF_REQ massage +struct rdtss_16bit_val_ntf_ind_req +{ + /// Connection index + uint8_t conidx; + /// Notificatin/indication + bool notification; + /// Handle of the attribute that has to be written + uint16_t handle; + /// Data length to be written + uint16_t length; + /// Data to be written in attribute database + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref RDTSS_16BIT_VAL_IND_REQ massage +struct rdtss_16bit_val_ind_req +{ + /// Connection index + uint8_t conidx; + /// Handle of the attribute that has to be written + uint16_t handle; + /// Data length to be written + uint16_t length; + /// Data to be written in attribute database + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref RDTSS_16BIT_ATT_INFO_REQ message +struct rdtss_16bit_att_info_req +{ + /// Connection index + uint8_t conidx; + /// Index of the attribute for which info has been requested + uint16_t att_idx; +}; + +/// Parameters of the @ref RDTSS_16BIT_ATT_INFO_RSP message +struct rdtss_16bit_att_info_rsp +{ + /// Connection index + uint8_t conidx; + /// Index of the attribute for which info has been requested + uint16_t att_idx; + /// Current length of that attribute + uint16_t length; + /// ATT error code + uint8_t status; +}; + +/** + * @brief Initialize Client Characteristic Configuration fields. + * @details Function initializes all CCC fields to default value. + * @param[in] att_db Id of the message received. + * @param[in] max_nb_att Pointer to the parameters of the message. + */ +void rdtss_16bit_init_ccc_values(const struct attm_desc *att_db, int max_nb_att); + +/** + * @brief Set per connection CCC value for attribute + * @details Function sets CCC for specified connection. + * @param[in] conidx Connection index. + * @param[in] att_idx Attribute index. + * @param[in] ccc Value of ccc. + */ +void rdtss_16bit_set_ccc_value(uint8_t conidx, uint8_t att_idx, uint16_t ccc); + + +#endif // BLE_RDTSS_16BIT_SERVER +#endif // __RDTSS_16BIT_TASK_PRF_H diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss_task.h new file mode 100644 index 0000000..1c7f81a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/api/rdtss_task.h @@ -0,0 +1,291 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdtss_task.h + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __RDTSS_TASK_PRF_H +#define __RDTSS_TASK_PRF_H + + /* Includes ------------------------------------------------------------------*/ +#if (BLE_RDTSS_SERVER) + +#include +#include "ke_task.h" +#include "prf_types.h" +#include "compiler.h" // compiler definition +#include "att.h" +#include "attm.h" + +#include "rwip_task.h" +/* Public typedef -----------------------------------------------------------*/ + +#define RDTSS_NOTIFY_ALL_CONN BLE_CONNECTION_MAX + +/// Possible states of the rdtss task +enum rdtss_state +{ + /// Idle state + RDTSS_IDLE, + /// Busy state + RDTSS_BUSY, + /// Number of defined states. + RDTSS_STATE_MAX, +}; + +/// Messages for RDTS +enum +{ + /// Add a rdtss instance into the database + RDTSS_CREATE_DB_REQ = TASK_FIRST_MSG(TASK_ID_RDTSS), + /// Inform APP of database creation status + RDTSS_CREATE_DB_CFM, + + /// Start the Custom Service Task - at connection + RDTSS_ENABLE_REQ, + /// Set/update characteristic value + RDTSS_VAL_SET_REQ, + /// Peer device request to get a non-database value (RI enabled) + RDTSS_VALUE_REQ_IND, + /// Response to non-database value request + RDTSS_VALUE_REQ_RSP, + /// Set/update characteristic value and trigger a notification + RDTSS_VAL_NTF_REQ, + /// Response after receiving a RDTSS_VAL_NTF_REQ message and a notification is triggered + RDTSS_VAL_NTF_CFM, + /// Set/update characteristic value and trigger an indication + RDTSS_VAL_IND_REQ, + ///Response after receiving a RDTSS_VAL_IND_REQ message and an indication is triggered + RDTSS_VAL_IND_CFM, + /// Indicate that the characteristic value has been written + RDTSS_VAL_WRITE_IND, + /// Inform the application that the profile service role task has been disabled after a disconnection + RDTSS_DISABLE_IND, + /// Profile error report + RDTSS_ERROR_IND, + /// Inform the application that there is an attribute info request that shall be processed + RDTSS_ATT_INFO_REQ, + /// Inform back that the attribute info request has been processed + RDTSS_ATT_INFO_RSP, +}; + + + + + +/// Parameters of the @ref RDTSS_CREATE_DB_CFM message +struct rdtss_create_db_cfm +{ + ///Status + uint8_t status; +}; + +/// Parameters of the @ref RDTSS_ENABLE_REQ message +struct rdtss_enable_req +{ + /// Connection index + uint8_t conidx; + /// security level: b0= nothing, b1=unauthenticated, b2=authenticated, b3=authorized; b1 or b2 and b3 can go together + uint8_t sec_lvl; + /// Type of connection + uint8_t con_type; +}; + +/// Parameters of the @ref RDTSS_DISABLE_IND message +struct rdtss_disable_ind +{ + /// Connection index + uint8_t conidx; +}; + +/// Parameters of the @ref RDTSS_VAL_WRITE_IND message +struct rdtss_val_write_ind +{ + /// Connection index + uint8_t conidx; + /// Handle of the attribute that has to be written + uint16_t handle; + /// Data length to be written + uint16_t length; + /// Data to be written in attribute database + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref RDTSS_VAL_NTF_CFM message +struct rdtss_val_ntf_cfm +{ + /// Connection index +// uint8_t conidx; + /// Handle of the attribute that has been updated + uint16_t handle; + /// Confirmation status + uint8_t status; +}; + +/// Parameters of the @ref RDTSS_VAL_IND_CFM message +struct rdtss_val_ind_cfm +{ + /// Connection index + uint8_t conidx; + /// Handle of the attribute that has been updated + uint16_t handle; + /// Confirmation status + uint8_t status; +}; + +/// Parameters of the @ref RDTSS_VAL_SET_REQ message +struct rdtss_val_set_req +{ + /// Connection index + uint8_t conidx; + /// Handle of the attribute that has to be written + uint16_t handle; + /// Data length to be written + uint16_t length; + /// Data to be written in attribute database + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref RDTSS_VAL_REQ_IND message +struct rdtss_value_req_ind +{ + /// Connection index + uint8_t conidx; + /// Index of the attribute for which value has been requested + uint16_t att_idx; +}; + +/// Parameters of the @ref RDTSS_VAL_REQ_RSP message +struct rdtss_value_req_rsp +{ + /// Connection index + uint8_t conidx; + /// Index of the attribute for which value has been requested + uint16_t att_idx; + /// Current length of that attribute + uint16_t length; + /// ATT error code + uint8_t status; + /// Data value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref RDTSS_VAL_NTF_REQ message +struct rdtss_val_ntf_ind_req +{ + /// Connection index + uint8_t conidx; + /// Notificatin/indication + bool notification; + /// Handle of the attribute that has to be written + uint16_t handle; + /// Data length to be written + uint16_t length; + /// Data to be written in attribute database + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref RDTSS_VAL_IND_REQ message +struct rdtss_val_ind_req +{ + /// Connection index + uint8_t conidx; + /// Handle of the attribute that has to be written + uint16_t handle; + /// Data length to be written + uint16_t length; + /// Data to be written in attribute database + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref RDTSS_ATT_INFO_REQ message +struct rdtss_att_info_req +{ + /// Connection index + uint8_t conidx; + /// Index of the attribute for which info has been requested + uint16_t att_idx; +}; + +/// Parameters of the @ref RDTSS_ATT_INFO_RSP message +struct rdtss_att_info_rsp +{ + /// Connection index + uint8_t conidx; + /// Index of the attribute for which info has been requested + uint16_t att_idx; + /// Current length of that attribute + uint16_t length; + /// ATT error code + uint8_t status; +}; + +/** + * @brief Initialize Client Characteristic Configuration fields. + * @details Function initializes all CCC fields to default value. + * @param[in] att_db Id of the message received. + * @param[in] max_nb_att Pointer to the parameters of the message. + */ +void rdtss_init_ccc_values(const struct attm_desc_128 *att_db, int max_nb_att); + +/** + * @brief Set per connection CCC value for attribute + * @details Function sets CCC for specified connection. + * @param[in] conidx Connection index. + * @param[in] att_idx Attribute index. + * @param[in] ccc Value of ccc. + */ +void rdtss_set_ccc_value(uint8_t conidx, uint8_t att_idx, uint16_t ccc); + + +#endif // BLE_RDTSS_SERVER +#endif // __RDTSS_TASK_PRF_H diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss.c new file mode 100644 index 0000000..99316a9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss.c @@ -0,0 +1,232 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdtss.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + /* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) +#include "rdtss.h" +#include "rdtss_task.h" +#include "attm_db.h" +#include "gapc.h" +#include "prf.h" +#include "ke_mem.h" + + +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Initialization of the RDTSS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] env Collector or Service allocated environment data. + * @param[in|out] start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + */ +static uint8_t rdtss_init(struct prf_task_env *env, uint16_t *start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct rdtss_db_cfg *params) +{ + //------------------ create the attribute database for the profile ------------------- + + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + uint32_t cfg_flag = ((1<max_nb_att)-1); + + status = attm_svc_create_db_128(start_hdl, params->svc_uuid , (uint8_t*)&cfg_flag, + params->max_nb_att, NULL, env->task, params->att_tbl, + (sec_lvl & PERM_MASK_SVC_AUTH) | (sec_lvl & PERM_MASK_SVC_EKS) | + PERM(SVC_SECONDARY, DISABLE) | PERM_VAL(SVC_UUID_LEN,2)); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + struct rdtss_env_tag *rdtss_env = + (struct rdtss_env_tag *) ke_malloc(sizeof(struct rdtss_env_tag), KE_MEM_ATT_DB); + + //load config from init + memcpy(&rdtss_env->db_cfg,params,sizeof(struct rdtss_db_cfg)); + + // allocate RDTSS required environment variable + env->env = (prf_env_t *)rdtss_env; + rdtss_env->shdl = *start_hdl; + rdtss_env->max_nb_att = rdtss_env->db_cfg.max_nb_att; + rdtss_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + rdtss_env->prf_env.prf_task = env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + env->id = TASK_ID_RDTSS; + + rdtss_task_init(&(env->desc)); + + co_list_init(&(rdtss_env->values)); + rdtss_init_ccc_values(rdtss_env->db_cfg.att_tbl, rdtss_env->db_cfg.max_nb_att); + + // service is ready, go into an Idle state + ke_state_set(env->task, RDTSS_IDLE); + } + + return status; +} +/** + * @brief Destruction of the RDTSS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] env Collector or Service allocated environment data. + */ +static void rdtss_destroy(struct prf_task_env *env) +{ + struct rdtss_env_tag *rdtss_env = (struct rdtss_env_tag *)env->env; + + // remove all values present in list + while (!co_list_is_empty(&(rdtss_env->values))) + { + struct co_list_hdr *hdr = co_list_pop_front(&(rdtss_env->values)); + ke_free(hdr); + } + + // free profile environment variables + env->env = NULL; + ke_free(rdtss_env); +} + +/** + * @brief Handles Connection creation + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + */ +static void rdtss_create(struct prf_task_env *env, uint8_t conidx) +{ + int att_idx; + struct rdtss_env_tag *rdtss_env = (struct rdtss_env_tag *)env->env; + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + // Find all ccc fields and clean them + for (att_idx = 1; att_idx < rdtss_env->db_cfg.max_nb_att; att_idx++) + { + // Find only CCC characteristics + if( PERM_GET(rdtss_env->db_cfg.att_tbl[att_idx].perm, UUID_LEN) == 0 && + (rdtss_env->db_cfg.att_tbl[att_idx].uuid[0] + + (rdtss_env->db_cfg.att_tbl[att_idx].uuid[1]<<8) ) == ATT_DESC_CLIENT_CHAR_CFG) + { + // Clear CCC value + rdtss_set_ccc_value(conidx, att_idx, 0); + } + } +} + +/** + * @brief Handles Disconnection + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + */ +static void rdtss_cleanup(struct prf_task_env *env, uint8_t conidx, uint8_t reason) +{ + int att_idx; + + struct rdtss_env_tag *rdtss_env = (struct rdtss_env_tag *)env->env; + + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + // Find all ccc fields and clean them + for (att_idx = 1; att_idx < rdtss_env->db_cfg.max_nb_att; att_idx++) + { + // Find only CCC characteristics + if( PERM_GET(rdtss_env->db_cfg.att_tbl[att_idx].perm, UUID_LEN) == 0 && + (rdtss_env->db_cfg.att_tbl[att_idx].uuid[0] + + (rdtss_env->db_cfg.att_tbl[att_idx].uuid[1]<<8) ) == ATT_DESC_CLIENT_CHAR_CFG) + { + // Clear CCC value + rdtss_set_ccc_value(conidx, att_idx, 0); + } + } +} + +/* Public variables ---------------------------------------------------------*/ + +/// RDTSS Task interface required by profile manager +const struct prf_task_cbs rdtss_itf = +{ + (prf_init_fnct) rdtss_init, + rdtss_destroy, + rdtss_create, + rdtss_cleanup, +}; + +/* Private functions ---------------------------------------------------------*/ + +const struct prf_task_cbs* rdtss_prf_itf_get(void) +{ + return &rdtss_itf; +} + +#endif // (BLE_RDTSS_SERVER) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss_16bit.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss_16bit.c new file mode 100644 index 0000000..1ff8291 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss_16bit.c @@ -0,0 +1,229 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdtss_16bit.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_16BIT_SERVER) +#include "rdtss_16bit.h" +#include "rdtss_16bit_task.h" +#include "attm_db.h" +#include "gapc.h" +#include "prf.h" +#include "ke_mem.h" + + +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Initialization of the RDTSS 16bit uuid module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] env Collector or Service allocated environment data. + * @param[in|out] start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + */ +static uint8_t rdtss_16bit_init(struct prf_task_env *env, uint16_t *start_hdl, uint16_t app_task, uint8_t sec_lvl, struct rdtss_16bit_db_cfg *params) +{ + //------------------ create the attribute database for the profile ------------------- + + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + uint32_t cfg_flag = ((1<max_nb_att)-1); + + status = attm_svc_create_db(start_hdl, *(params->svc_uuid), (uint8_t*)&cfg_flag, + params->max_nb_att, NULL, env->task, params->att_tbl, + (sec_lvl & PERM_MASK_SVC_AUTH) | (sec_lvl & PERM_MASK_SVC_EKS) | PERM(SVC_SECONDARY, DISABLE) ); + + //-------------------- allocate memory required for the profile --------------------- + if (status == ATT_ERR_NO_ERROR) + { + struct rdtss_16bit_env_tag *rdtss_16bit_env = + (struct rdtss_16bit_env_tag *) ke_malloc(sizeof(struct rdtss_16bit_env_tag), KE_MEM_ATT_DB); + + //load config from init + memcpy(&(rdtss_16bit_env->db_cfg),params,sizeof(struct rdtss_16bit_db_cfg)); + // allocate RDTSS_16BITrequired environment variable + env->env = (prf_env_t *)rdtss_16bit_env; + rdtss_16bit_env->shdl = *start_hdl; + rdtss_16bit_env->max_nb_att = params->max_nb_att; + rdtss_16bit_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + rdtss_16bit_env->prf_env.prf_task = env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + env->id = TASK_ID_RDTSS_16BIT; + + rdtss_16bit_task_init(&(env->desc)); + + co_list_init(&(rdtss_16bit_env->values)); + rdtss_16bit_init_ccc_values(params->att_tbl, params->max_nb_att); + + // service is ready, go into an Idle state + ke_state_set(env->task, RDTSS_16BIT_IDLE); + } + + return status; +} +/** + * @brief Destruction of the RDTSS_16BITmodule - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] env Collector or Service allocated environment data. + */ +static void rdtss_16bit_destroy(struct prf_task_env *env) +{ + struct rdtss_16bit_env_tag *rdtss_16bit_env = (struct rdtss_16bit_env_tag *)env->env; + + // remove all values present in list + while (!co_list_is_empty(&(rdtss_16bit_env->values))) + { + struct co_list_hdr *hdr = co_list_pop_front(&(rdtss_16bit_env->values)); + ke_free(hdr); + } + + // free profile environment variables + env->env = NULL; + ke_free(rdtss_16bit_env); +} + +/** + * @brief Handles Connection creation + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + */ +static void rdtss_16bit_create(struct prf_task_env *env, uint8_t conidx) +{ + int att_idx; + struct rdtss_16bit_env_tag *rdtss_16bit_env = (struct rdtss_16bit_env_tag *)env->env; + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + // Find all ccc fields and clean them + for (att_idx = 1; att_idx < rdtss_16bit_env->max_nb_att; att_idx++) + { + // Find only CCC characteristics + if( PERM_GET(rdtss_16bit_env->db_cfg.att_tbl[att_idx].perm, UUID_LEN) == 0 && + (rdtss_16bit_env->db_cfg.att_tbl[att_idx].uuid) == ATT_DESC_CLIENT_CHAR_CFG + ) + { + // Clear CCC value + rdtss_16bit_set_ccc_value(conidx, att_idx, 0); + } + } +} + +/** + * @brief Handles Disconnection + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + */ +static void rdtss_16bit_cleanup(struct prf_task_env *env, uint8_t conidx, uint8_t reason) +{ + int att_idx; + + struct rdtss_16bit_env_tag *rdtss_16bit_env = (struct rdtss_16bit_env_tag *)env->env; + + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + // Find all ccc fields and clean them + for (att_idx = 1; att_idx < rdtss_16bit_env->max_nb_att; att_idx++) + { + // Find only CCC characteristics + if( PERM_GET(rdtss_16bit_env->db_cfg.att_tbl[att_idx].perm, UUID_LEN) == 0 && + (rdtss_16bit_env->db_cfg.att_tbl[att_idx].uuid) == ATT_DESC_CLIENT_CHAR_CFG + ) + { + // Clear CCC value + rdtss_16bit_set_ccc_value(conidx, att_idx, 0); + } + } + +} + +/* Public variables ---------------------------------------------------------*/ + +/// RDTSS_16BITTask interface required by profile manager +const struct prf_task_cbs rdtss_16bit_itf = +{ + (prf_init_fnct) rdtss_16bit_init, + rdtss_16bit_destroy, + rdtss_16bit_create, + rdtss_16bit_cleanup, +}; + +/* Private functions ---------------------------------------------------------*/ + +const struct prf_task_cbs* rdtss_16bit_prf_itf_get(void) +{ + return &rdtss_16bit_itf; +} + +#endif // (BLE_RDTSS_16BIT_SERVER) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss_16bit_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss_16bit_task.c new file mode 100644 index 0000000..54c7c9b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss_16bit_task.c @@ -0,0 +1,771 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdtss_16bit_task.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_16BIT_SERVER) +#include "rdtss_16bit_task.h" +#include "rdtss_16bit.h" +#include "rdts_common.h" +#include "attm.h" +#include "ke_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "gattc_task.h" +#include "attm_db.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Stores characteristic value. + * @param[in] att_idx Custom attribut index. + * @param[in] length Value length. + * @param[in] data Pointer to value data. + * @return 0 on success. + */ +static int rdtss_16bit_att_set_value(uint8_t att_idx, uint16_t length, const uint8_t *data) +{ + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + // Check value in already present in service + struct rdtss_16bit_val_elmt *val = (struct rdtss_16bit_val_elmt *) co_list_pick(&(rdtss_16bit_env->values)); + // loop until value found + while (val != NULL) + { + // value is present in service + if (val->att_idx == att_idx) + { + // Value present but size changed, free old value + if (length != val->length) + { + //co_list_extract(&rdtss_16bit_env->values, &val->hdr, 0); + co_list_extract(&rdtss_16bit_env->values, &val->hdr); //lxm + + ke_free(val); + val = NULL; + } + break; + } + + val = (struct rdtss_16bit_val_elmt *)val->hdr.next; + } + + if (val == NULL) + { + // allocate value data + val = (struct rdtss_16bit_val_elmt *) ke_malloc(sizeof(struct rdtss_16bit_val_elmt) + length, KE_MEM_ATT_DB); + // insert value into the list + co_list_push_back(&rdtss_16bit_env->values, &val->hdr); + } + val->att_idx = att_idx; + val->length = length; + memcpy(val->data, data, length); + + return 0; +} + +/** + * @brief Read characteristic value from. + * Function checks if attribute exists, and if so return its length and pointer to data. + * @param[in] att_idx Custom attribute index. + * @param[out] length Pointer to variable that receive length of the attribute. + * @param[out] data Pointer to variable that receive pointer characteristic value. + * @return 0 on success, ATT_ERR_ATTRIBUTE_NOT_FOUND if there is no value for such attribyte. + */ +static int rdtss_16bit_att_get_value(uint8_t att_idx, uint16_t *length, const uint8_t **data) +{ + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + // Check value in already present in service + struct rdtss_16bit_val_elmt *val = (struct rdtss_16bit_val_elmt *) co_list_pick(&rdtss_16bit_env->values); + ASSERT_ERR(data); + ASSERT_ERR(length); + + // loop until value found + while (val != NULL) + { + // value is present in service + if (val->att_idx == att_idx) + { + *length = val->length; + *data = val->data; + break; + } + + val = (struct rdtss_16bit_val_elmt *)val->hdr.next; + } + + if (val == NULL) + { + *length = 0; + *data = NULL; + } + return val ? 0 : ATT_ERR_ATTRIBUTE_NOT_FOUND; +} + +/** + * @brief Sets initial values for all Clinet Characteristic Configurations. + * @param[in] att_db Custom service attribute definition table. + * @param[in] max_nb_att Number of elements in att_db. + */ +void rdtss_16bit_init_ccc_values(const struct attm_desc *att_db, int max_nb_att) +{ + // Default values 0 means no notification + uint8_t ccc_values[BLE_CONNECTION_MAX] = {0}; + int i; + + // Start form 1, skip service description + for (i = 1; i < max_nb_att; i++) + { + if( PERM_GET(att_db[i].perm, UUID_LEN) == PERM_UUID_16 && + (att_db[i].uuid) == ATT_DESC_CLIENT_CHAR_CFG + ) + { + // Set default values for all possible connections + rdtss_16bit_att_set_value(i, sizeof(ccc_values), ccc_values); + } + } +} + +/** + * @brief Set value of CCC for given attribute and connection index. + * @param[in] conidx Connection index. + * @param[in] att_idx CCC attribute index. + * @param[in] cc Value to store. + */ +void rdtss_16bit_set_ccc_value(uint8_t conidx, uint8_t att_idx, uint16_t ccc) +{ + uint16_t length; + const uint8_t *value; + uint8_t new_value[BLE_CONNECTION_MAX]; + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + rdtss_16bit_att_get_value(att_idx, &length, &value); + ASSERT_ERR(length); + ASSERT_ERR(value); + memcpy(new_value, value, length); + // For now there are only two valid values for ccc, store just one byte other is 0 anyway + new_value[conidx] = (uint8_t)ccc; + rdtss_16bit_att_set_value(att_idx, length, new_value); +} + +/** + * @brief Read value of CCC for given attribute and connection index. + * @param[in] conidx Connection index. + * @param[in] att_idx Custom attribute index. + * @return Value of CCC. + */ +static uint16_t rdtss_16bit_get_ccc_value(uint8_t conidx, uint8_t att_idx) +{ + uint16_t length; + const uint8_t *value; + uint16_t ccc_value; + + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + rdtss_16bit_att_get_value(att_idx, &length, &value); + ASSERT_ERR(length); + ASSERT_ERR(value); + + ccc_value = value[conidx]; + + return ccc_value; +} + +/** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * @details The GATTC_CMP_EVT message that signals the completion of a GATTC_NOTIFY + * operation is sent back as soon as the notification PDU has been sent over + * the air. + * The GATTC_CMP_EVT message that signals the completion of a GATTC_INDICATE + * operation is sent back as soon as the ATT_HANDLE_VALUE_CONFIRMATION PDU is + * received confirming that the indication has been correctly received by the + * peer device. + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + + if (param->operation == GATTC_NOTIFY || param->operation == GATTC_INDICATE) + { + //TODO + struct rdtss_16bit_val_ntf_ind_req *app_req = (struct rdtss_16bit_val_ntf_ind_req *)ke_msg2param(rdtss_16bit_env->operation); + + if (param->operation == GATTC_NOTIFY) + { + // Inform the application that the notification PDU has been sent over the air. + struct rdtss_16bit_val_ntf_cfm *cfm = KE_MSG_ALLOC(RDTSS_16BIT_VAL_NTF_CFM, + rdtss_16bit_env->operation->src_id, rdtss_16bit_env->operation->dest_id, + rdtss_16bit_val_ntf_cfm); + cfm->handle = app_req->handle; + cfm->status = GAP_ERR_NO_ERROR; + ke_msg_send(cfm); + } + else + { + // Inform the application that the indication has been confirmed by the peer device. + struct rdtss_16bit_val_ind_cfm *cfm = KE_MSG_ALLOC(RDTSS_16BIT_VAL_IND_CFM, + rdtss_16bit_env->operation->src_id, rdtss_16bit_env->operation->dest_id, + rdtss_16bit_val_ind_cfm); + cfm->handle = app_req->handle; + cfm->status = GAP_ERR_NO_ERROR; + ke_msg_send(cfm); + } + + if(rdtss_16bit_env->operation) + { + ke_free(rdtss_16bit_env->operation); + rdtss_16bit_env->operation = NULL; + } + + ke_state_set(dest_id, RDTSS_16BIT_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles reception of the @ref RDTSS_16BIT_VAL_SET_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int rdtss_16bit_val_set_req_handler(ke_msg_id_t const msgid, + struct rdtss_16bit_val_set_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + // Update value in DB + attm_att_set_value(rdtss_16bit_env->shdl + param->handle, param->length, 0, (uint8_t *)¶m->value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles reception of the @ref RDTSS_16BIT_VAL_NTF_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int rdtss_16bit_val_ntf_req_handler(ke_msg_id_t const msgid, + struct rdtss_16bit_val_ntf_ind_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + uint16_t ccc_hdl; + uint16_t handle = rdtss_16bit_env->shdl + param->handle; + uint8_t conidx = param->conidx; + uint8_t ccc_idx; + uint8_t status; + uint8_t state = ke_state_get(dest_id); + + if (state == RDTSS_16BIT_BUSY) + { + return KE_MSG_SAVED; + } + + // Find the handle of the Characteristic Client Configuration + ccc_hdl = get_cfg_handle(handle); + ASSERT_ERR(ccc_hdl); + + // Convert handle to index + status = rdtss_16bit_get_att_idx(ccc_hdl, &ccc_idx); + ASSERT_ERR(status == ATT_ERR_NO_ERROR); + if (status != ATT_ERR_NO_ERROR) + { + NS_LOG_ERROR("status err:%d\r\n", status); + return KE_MSG_SAVED; + } + rdtss_16bit_env->operation = ke_param2msg(param); + rdtss_16bit_env->cursor = conidx; + rdtss_16bit_env->ccc_idx = ccc_idx; + + //TODO + uint16_t length; + const uint8_t *ccc_values; + rdtss_16bit_att_get_value(rdtss_16bit_env->ccc_idx, &length, &ccc_values); + struct rdtss_16bit_val_ntf_ind_req *app_req = (struct rdtss_16bit_val_ntf_ind_req *)ke_msg2param(rdtss_16bit_env->operation); + + if ( (ccc_values[conidx] & PRF_CLI_START_NTF) || (ccc_values[conidx] & PRF_CLI_START_IND) ) + { + struct gattc_send_evt_cmd *req; + // Allocate the GATT notification message + req = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), rdtss_16bit_env->operation->dest_id, gattc_send_evt_cmd, app_req->length); + + // Fill in the parameter structure + req->operation = GATTC_NOTIFY; + req->handle = rdtss_16bit_env->shdl + app_req->handle; + req->length = app_req->length; + memcpy(req->value, app_req->value, app_req->length); + + // Send the event + ke_msg_send(req); + + ke_state_set(dest_id, RDTSS_16BIT_BUSY); + } + else + { + //TODO FREE + ke_free(rdtss_16bit_env->operation); + } + + return KE_MSG_NO_FREE; +} + +/** + * @brief Handles reception of the @ref RDTSS_16BIT_VAL_IND_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int rdtss_16bit_val_ind_req_handler(ke_msg_id_t const msgid, + struct rdtss_16bit_val_ind_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + uint16_t ccc_hdl; + uint16_t handle = rdtss_16bit_env->shdl + param->handle; + uint8_t ccc_idx; + uint8_t status; + uint8_t conidx = param->conidx; + + uint8_t state = ke_state_get(dest_id); + if (state == RDTSS_16BIT_BUSY) + { + return KE_MSG_SAVED; + } + + // Find the handle of the Characteristic Client Configuration + ccc_hdl = get_cfg_handle(handle); + ASSERT_ERR(ccc_hdl); + + // Convert handle to index + status = rdtss_16bit_get_att_idx(ccc_hdl, &ccc_idx); + ASSERT_ERR(status == ATT_ERR_NO_ERROR); + if (status != ATT_ERR_NO_ERROR) + { + return KE_MSG_SAVED; + } + + ke_state_set(dest_id, RDTSS_16BIT_BUSY); + rdtss_16bit_env->operation = ke_param2msg(param); + rdtss_16bit_env->cursor = 0; + rdtss_16bit_env->ccc_idx = ccc_idx; + + // Trigger indication + uint16_t length; + const uint8_t *ccc_values; + rdtss_16bit_att_get_value(rdtss_16bit_env->ccc_idx, &length, &ccc_values); + struct rdtss_16bit_val_ntf_ind_req *app_req = (struct rdtss_16bit_val_ntf_ind_req *)ke_msg2param(rdtss_16bit_env->operation); + + if (ccc_values[conidx] & PRF_CLI_START_IND) + { + struct gattc_send_evt_cmd *req; + // Allocate the GATT notification message + req = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), rdtss_16bit_env->operation->dest_id, gattc_send_evt_cmd, app_req->length); + + // Fill in the parameter structure + req->operation = GATTC_INDICATE; + req->handle = rdtss_16bit_env->shdl + app_req->handle; + req->length = app_req->length; + memcpy(req->value, app_req->value, app_req->length); + + // Send the event + ke_msg_send(req); + + ke_state_set(dest_id, RDTSS_16BIT_BUSY); + } + else + { + //TODO FREE + ke_free(rdtss_16bit_env->operation); + } + + return KE_MSG_NO_FREE; +} + +/** + * @brief Handles reception of the @ref RDTSS_16BIT_ATT_INFO_RSP message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance (probably unused). + * @return If the message shall be consumed or not. + */ +static int rdtss_16bit_att_info_rsp_handler(ke_msg_id_t const msgid, + struct rdtss_16bit_att_info_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + + if (state == RDTSS_16BIT_IDLE) + { + // Extract the service start handle. + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + // Allocate the attribute information confirmation message. + struct gattc_att_info_cfm *cfm; + cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, TASK_GATTC, dest_id, gattc_att_info_cfm); + // Fill the message. + cfm->handle = rdtss_16bit_env->shdl + param->att_idx; + cfm->length = param->length; + cfm->status = param->status; + // Send the confirmation message to GATTC. + ke_msg_send(cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles reception of the @ref GATTC_READ_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int gattc_read_req_ind_handler(ke_msg_id_t const msgid, struct gattc_read_req_ind const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + ke_state_t state = ke_state_get(dest_id); + + if(state == RDTSS_16BIT_IDLE) + { + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + struct gattc_read_cfm * cfm; + uint8_t att_idx = 0; + uint8_t conidx = KE_IDX_GET(src_id); + // retrieve handle information + + uint8_t status = rdtss_16bit_get_att_idx(param->handle, &att_idx); + + uint16_t length = 0; + uint16_t ccc_val = 0; + + // If the attribute has been found, status is GAP_ERR_NO_ERROR + if (status == GAP_ERR_NO_ERROR) + { + if( PERM_GET(rdtss_16bit_env->db_cfg.att_tbl[att_idx].perm, UUID_LEN) == PERM_UUID_16 && + (rdtss_16bit_env->db_cfg.att_tbl[att_idx].uuid) == ATT_DESC_CLIENT_CHAR_CFG + ) + { + ccc_val = rdtss_16bit_get_ccc_value(conidx, att_idx); + length = 2; + } + else + { + // Request value from application + struct rdtss_16bit_value_req_ind* req_ind = KE_MSG_ALLOC(RDTSS_16BIT_VALUE_REQ_IND, + prf_dst_task_get(&(rdtss_16bit_env->prf_env), KE_IDX_GET(src_id)), + dest_id, + rdtss_16bit_value_req_ind); + + req_ind->conidx = KE_IDX_GET(src_id); + req_ind->att_idx = att_idx; + + // Send message to application + ke_msg_send(req_ind); + + // Put Service in a busy state + ke_state_set(dest_id, RDTSS_16BIT_BUSY); + + return (KE_MSG_CONSUMED); + } + } + + // Send read response + cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + src_id, + dest_id, + gattc_read_cfm, + length); + + cfm->handle = param->handle; + cfm->status = status; + cfm->length = length; + + if (status == GAP_ERR_NO_ERROR) + { + memcpy(cfm->value, &ccc_val, length); + } + + ke_msg_send(cfm); + + return (KE_MSG_CONSUMED); + } + // Postpone request if profile is in a busy state + else + { + return (KE_MSG_SAVED); + } +} + +/** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int gattc_write_req_ind_handler(ke_msg_id_t const msgid, const struct gattc_write_req_ind *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + struct gattc_write_cfm * cfm; + uint8_t att_idx = 0; + uint8_t conidx = KE_IDX_GET(src_id); + // retrieve handle information + uint8_t status = rdtss_16bit_get_att_idx(param->handle, &att_idx); + + uint16_t perm; + + ASSERT_ERR(param->offset == 0); + + // If the attribute has been found, status is ATT_ERR_NO_ERROR + if (status == ATT_ERR_NO_ERROR) + { + if( PERM_GET(rdtss_16bit_env->db_cfg.att_tbl[att_idx].perm, UUID_LEN) == PERM_UUID_16 && + (rdtss_16bit_env->db_cfg.att_tbl[att_idx].uuid) == ATT_DESC_CLIENT_CHAR_CFG + ) + { + struct attm_elmt elem = {0}; + + // Find the handle of the Characteristic Value + uint16_t value_hdl = get_value_handle(param->handle); + ASSERT_ERR(value_hdl); + + // Get permissions to identify if it is NTF or IND. + attmdb_att_get_permission(value_hdl, &perm, PERM_MASK_ALL, 0, &elem); + + status = check_client_char_cfg(PERM_IS_SET(perm, NTF, ENABLE), param); + + if (status == ATT_ERR_NO_ERROR) + { + rdtss_16bit_set_ccc_value(conidx, att_idx, *(uint16_t *)param->value); + } + } + + + if (status == ATT_ERR_NO_ERROR) + { + // Inform APP + struct rdtss_16bit_val_write_ind *req_id = KE_MSG_ALLOC_DYN(RDTSS_16BIT_VAL_WRITE_IND, + prf_dst_task_get(&(rdtss_16bit_env->prf_env), KE_IDX_GET(src_id)), + dest_id, rdtss_16bit_val_write_ind, + param->length); + memcpy(req_id->value, param->value, param->length); + req_id->conidx = conidx; + req_id->handle = att_idx; + req_id->length = param->length; + + ke_msg_send(req_id); + } + } + + //Send write response + cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + cfm->handle = param->handle; + cfm->status = status; + ke_msg_send(cfm); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles reception of the attribute info request message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance (probably unused). + * @return If the message shall be consumed or not. + */ +static int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + + if (state == RDTSS_16BIT_IDLE) + { + // Extract the service start handle. + struct rdtss_16bit_env_tag *rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + // Allocate the attribute information request message to be processed by + // the application. + struct rdtss_16bit_att_info_req *req = KE_MSG_ALLOC(RDTSS_16BIT_ATT_INFO_REQ, + TASK_APP, + dest_id, + rdtss_16bit_att_info_req); + // Fill the message. + req->conidx = KE_IDX_GET(src_id); + ASSERT_ERR((req->conidx) < BLE_CONNECTION_MAX); + req->att_idx = param->handle - rdtss_16bit_env->shdl; + // Send the message to the application. + ke_msg_send(req); + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles reception of the @ref RDTSS_16BIT_VALUE_REQ_RSP message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance (probably unused). + * @return If the message shall be consumed or not. + */ +static int rdtss_16bit_value_req_rsp_handler(ke_msg_id_t const msgid, + struct rdtss_16bit_value_req_rsp *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + ke_state_t state = ke_state_get(dest_id); + + if(state == RDTSS_16BIT_BUSY) + { + if (param->status == ATT_ERR_NO_ERROR) + { + // Send value to peer device. + struct gattc_read_cfm* cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, param->conidx), + dest_id, + gattc_read_cfm, + param->length); + + // Fill parameters + cfm->handle = rdtss_16bit_get_att_handle(param->att_idx); + + cfm->status = ATT_ERR_NO_ERROR; + cfm->length = param->length; + memcpy(cfm->value, param->value, param->length); + + // Send message to GATTC + ke_msg_send(cfm); + } + else + { + // Application error, value provided by application is not the expected one + struct gattc_read_cfm* cfm = KE_MSG_ALLOC(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, param->conidx), + dest_id, + gattc_read_cfm); + + // Fill parameters + cfm->handle = rdtss_16bit_get_att_handle(param->att_idx); + cfm->status = ATT_ERR_APP_ERROR; + + // Send message to GATTC + ke_msg_send(cfm); + } + + // Return to idle state + ke_state_set(dest_id, RDTSS_16BIT_IDLE); + } + return (KE_MSG_CONSUMED); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(rdtss_16bit) +{ + {GATTC_READ_REQ_IND, (ke_msg_func_t)gattc_read_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t)gattc_write_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t)gattc_att_info_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + {RDTSS_16BIT_VAL_NTF_REQ, (ke_msg_func_t)rdtss_16bit_val_ntf_req_handler}, + {RDTSS_16BIT_VAL_SET_REQ, (ke_msg_func_t)rdtss_16bit_val_set_req_handler}, + {RDTSS_16BIT_VAL_IND_REQ, (ke_msg_func_t)rdtss_16bit_val_ind_req_handler}, + {RDTSS_16BIT_ATT_INFO_RSP, (ke_msg_func_t)rdtss_16bit_att_info_rsp_handler}, + {RDTSS_16BIT_VALUE_REQ_RSP, (ke_msg_func_t)rdtss_16bit_value_req_rsp_handler}, +}; + +void rdtss_16bit_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct rdtss_16bit_env_tag *p_rdtss_16bit_env = PRF_ENV_GET(RDTSS_16BIT, rdtss_16bit); + + p_task_desc->msg_handler_tab = rdtss_16bit_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(rdtss_16bit_msg_handler_tab); + p_task_desc->state = p_rdtss_16bit_env->state; + p_task_desc->idx_max = RDTSS_16BIT_IDX_MAX; +} + +#endif // BLE_RDTSS_16BIT_SERVER diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss_task.c new file mode 100644 index 0000000..0d307a3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rdts/rdtss/src/rdtss_task.c @@ -0,0 +1,769 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rdtss_task.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) +#include "rdtss_task.h" +#include "rdtss.h" +#include "rdts_common.h" +#include "attm.h" +#include "ke_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "gattc_task.h" +#include "attm_db.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Stores characteristic value. + * @param[in] att_idx Custom attribut index. + * @param[in] length Value length. + * @param[in] data Pointer to value data. + * @return 0 on success. + */ +static int rdtss_att_set_value(uint8_t att_idx, uint16_t length, const uint8_t *data) +{ + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + // Check value in already present in service + struct rdtss_val_elmt *val = (struct rdtss_val_elmt *) co_list_pick(&(rdtss_env->values)); + // loop until value found + while (val != NULL) + { + // value is present in service + if (val->att_idx == att_idx) + { + // Value present but size changed, free old value + if (length != val->length) + { + //co_list_extract(&rdtss_env->values, &val->hdr, 0); + co_list_extract(&rdtss_env->values, &val->hdr); //lxm + + ke_free(val); + val = NULL; + } + break; + } + + val = (struct rdtss_val_elmt *)val->hdr.next; + } + + if (val == NULL) + { + // allocate value data + val = (struct rdtss_val_elmt *) ke_malloc(sizeof(struct rdtss_val_elmt) + length, KE_MEM_ATT_DB); + // insert value into the list + co_list_push_back(&rdtss_env->values, &val->hdr); + } + val->att_idx = att_idx; + val->length = length; + memcpy(val->data, data, length); + + return 0; +} + +/** + * @brief Read characteristic value from. + * Function checks if attribute exists, and if so return its length and pointer to data. + * @param[in] att_idx Custom attribute index. + * @param[out] length Pointer to variable that receive length of the attribute. + * @param[out] data Pointer to variable that receive pointer characteristic value. + * @return 0 on success, ATT_ERR_ATTRIBUTE_NOT_FOUND if there is no value for such attribyte. + */ +static int rdtss_att_get_value(uint8_t att_idx, uint16_t *length, const uint8_t **data) +{ + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + // Check value in already present in service + struct rdtss_val_elmt *val = (struct rdtss_val_elmt *) co_list_pick(&rdtss_env->values); + ASSERT_ERR(data); + ASSERT_ERR(length); + + // loop until value found + while (val != NULL) + { + // value is present in service + if (val->att_idx == att_idx) + { + *length = val->length; + *data = val->data; + break; + } + + val = (struct rdtss_val_elmt *)val->hdr.next; + } + + if (val == NULL) + { + *length = 0; + *data = NULL; + } + return val ? 0 : ATT_ERR_ATTRIBUTE_NOT_FOUND; +} + +/** + * @brief Sets initial values for all Clinet Characteristic Configurations. + * @param[in] att_db Custom service attribute definition table. + * @param[in] max_nb_att Number of elements in att_db. + */ +void rdtss_init_ccc_values(const struct attm_desc_128 *att_db, int max_nb_att) +{ + // Default values 0 means no notification + uint8_t ccc_values[BLE_CONNECTION_MAX] = {0}; + int i; + // Start form 1, skip service description + for (i = 1; i < max_nb_att; i++) + { + if( PERM_GET(att_db[i].perm, UUID_LEN) == PERM_UUID_16 && + (att_db[i].uuid[0] + (att_db[i].uuid[1]<<8) ) == ATT_DESC_CLIENT_CHAR_CFG + ) + { + // Set default values for all possible connections + rdtss_att_set_value(i, sizeof(ccc_values), ccc_values); + } + } +} + +/** + * @brief Set value of CCC for given attribute and connection index. + * @param[in] conidx Connection index. + * @param[in] att_idx CCC attribute index. + * @param[in] cc Value to store. + */ +void rdtss_set_ccc_value(uint8_t conidx, uint8_t att_idx, uint16_t ccc) +{ + uint16_t length; + const uint8_t *value; + uint8_t new_value[BLE_CONNECTION_MAX]; + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + rdtss_att_get_value(att_idx, &length, &value); + ASSERT_ERR(length); + ASSERT_ERR(value); + memcpy(new_value, value, length); + // For now there are only two valid values for ccc, store just one byte other is 0 anyway + new_value[conidx] = (uint8_t)ccc; + rdtss_att_set_value(att_idx, length, new_value); +} + +/** + * @brief Read value of CCC for given attribute and connection index. + * @param[in] conidx Connection index. + * @param[in] att_idx Custom attribute index. + * @return Value of CCC. + */ +static uint16_t rdtss_get_ccc_value(uint8_t conidx, uint8_t att_idx) +{ + uint16_t length; + const uint8_t *value; + uint16_t ccc_value; + + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + + rdtss_att_get_value(att_idx, &length, &value); + ASSERT_ERR(length); + ASSERT_ERR(value); + + ccc_value = value[conidx]; + + return ccc_value; +} + +/** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * @details The GATTC_CMP_EVT message that signals the completion of a GATTC_NOTIFY + * operation is sent back as soon as the notification PDU has been sent over + * the air. + * The GATTC_CMP_EVT message that signals the completion of a GATTC_INDICATE + * operation is sent back as soon as the ATT_HANDLE_VALUE_CONFIRMATION PDU is + * received confirming that the indication has been correctly received by the + * peer device. + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + + if (param->operation == GATTC_NOTIFY || param->operation == GATTC_INDICATE) + { + //TODO + struct rdtss_val_ntf_ind_req *app_req = (struct rdtss_val_ntf_ind_req *)ke_msg2param(rdtss_env->operation); + + if (param->operation == GATTC_NOTIFY) + { + // Inform the application that the notification PDU has been sent over the air. + struct rdtss_val_ntf_cfm *cfm = KE_MSG_ALLOC(RDTSS_VAL_NTF_CFM, + rdtss_env->operation->src_id, rdtss_env->operation->dest_id, + rdtss_val_ntf_cfm); + cfm->handle = app_req->handle; + cfm->status = param->status;//GAP_ERR_NO_ERROR; + ke_msg_send(cfm); + } + else + { + // Inform the application that the indication has been confirmed by the peer device. + struct rdtss_val_ind_cfm *cfm = KE_MSG_ALLOC(RDTSS_VAL_IND_CFM, + rdtss_env->operation->src_id, rdtss_env->operation->dest_id, + rdtss_val_ind_cfm); + cfm->handle = app_req->handle; + cfm->status = param->status;//GAP_ERR_NO_ERROR; + ke_msg_send(cfm); + } + + if(rdtss_env->operation) + { + ke_free(rdtss_env->operation); + rdtss_env->operation = NULL; + } + + ke_state_set(dest_id, RDTSS_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles reception of the @ref RDTSS_VAL_SET_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int rdtss_val_set_req_handler(ke_msg_id_t const msgid, + struct rdtss_val_set_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + // Update value in DB + attm_att_set_value(rdtss_env->shdl + param->handle, param->length, 0, (uint8_t *)¶m->value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles reception of the @ref RDTSS_VAL_NTF_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int rdtss_val_ntf_req_handler(ke_msg_id_t const msgid, + struct rdtss_val_ntf_ind_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + uint16_t ccc_hdl; + uint16_t handle = rdtss_env->shdl + param->handle; + uint8_t conidx = param->conidx; + uint8_t ccc_idx; + uint8_t status; + uint8_t state = ke_state_get(dest_id); + + if (state == RDTSS_BUSY) + { + return KE_MSG_SAVED; + } + + // Find the handle of the Characteristic Client Configuration + ccc_hdl = get_cfg_handle(handle); + ASSERT_ERR(ccc_hdl); + + // Convert handle to index + status = rdtss_get_att_idx(ccc_hdl, &ccc_idx); + ASSERT_ERR(status == ATT_ERR_NO_ERROR); + if (status != ATT_ERR_NO_ERROR) + { + NS_LOG_ERROR("status err:%d\r\n", status); + return KE_MSG_SAVED; + } + rdtss_env->operation = ke_param2msg(param); + rdtss_env->cursor = conidx; + rdtss_env->ccc_idx = ccc_idx; + + //TODO + uint16_t length; + const uint8_t *ccc_values; + rdtss_att_get_value(rdtss_env->ccc_idx, &length, &ccc_values); + struct rdtss_val_ntf_ind_req *app_req = (struct rdtss_val_ntf_ind_req *)ke_msg2param(rdtss_env->operation); + + if ( (ccc_values[conidx] & PRF_CLI_START_NTF) || (ccc_values[conidx] & PRF_CLI_START_IND) ) + { + struct gattc_send_evt_cmd *req; + // Allocate the GATT notification message + req = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), rdtss_env->operation->dest_id, gattc_send_evt_cmd, app_req->length); + + // Fill in the parameter structure + req->operation = GATTC_NOTIFY; + req->handle = rdtss_env->shdl + app_req->handle; + req->length = app_req->length; + memcpy(req->value, app_req->value, app_req->length); + + // Send the event + ke_msg_send(req); + + ke_state_set(dest_id, RDTSS_BUSY); + } + else + { + //TODO FREE + ke_free(rdtss_env->operation); + } + return KE_MSG_NO_FREE; +} + +/** + * @brief Handles reception of the @ref RDTSS_VAL_IND_REQ message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int rdtss_val_ind_req_handler(ke_msg_id_t const msgid, + struct rdtss_val_ind_req const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + uint16_t ccc_hdl; + uint16_t handle = rdtss_env->shdl + param->handle; + uint8_t ccc_idx; + uint8_t status; + uint8_t conidx = param->conidx; + + uint8_t state = ke_state_get(dest_id); + if (state == RDTSS_BUSY) + { + return KE_MSG_SAVED; + } + + // Find the handle of the Characteristic Client Configuration + ccc_hdl = get_cfg_handle(handle); + ASSERT_ERR(ccc_hdl); + + // Convert handle to index + status = rdtss_get_att_idx(ccc_hdl, &ccc_idx); + ASSERT_ERR(status == ATT_ERR_NO_ERROR); + if (status != ATT_ERR_NO_ERROR) + { + return KE_MSG_SAVED; + } + + ke_state_set(dest_id, RDTSS_BUSY); + rdtss_env->operation = ke_param2msg(param); + rdtss_env->cursor = 0; + rdtss_env->ccc_idx = ccc_idx; + + // Trigger indication + uint16_t length; + const uint8_t *ccc_values; + rdtss_att_get_value(rdtss_env->ccc_idx, &length, &ccc_values); + struct rdtss_val_ntf_ind_req *app_req = (struct rdtss_val_ntf_ind_req *)ke_msg2param(rdtss_env->operation); + + if (ccc_values[conidx] & PRF_CLI_START_IND) + { + struct gattc_send_evt_cmd *req; + // Allocate the GATT notification message + req = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), rdtss_env->operation->dest_id, gattc_send_evt_cmd, app_req->length); + + // Fill in the parameter structure + req->operation = GATTC_INDICATE; + req->handle = rdtss_env->shdl + app_req->handle; + req->length = app_req->length; + memcpy(req->value, app_req->value, app_req->length); + + // Send the event + ke_msg_send(req); + + ke_state_set(dest_id, RDTSS_BUSY); + } + else + { + //TODO FREE + ke_free(rdtss_env->operation); + } + + return KE_MSG_NO_FREE; +} + +/** + * @brief Handles reception of the @ref RDTSS_ATT_INFO_RSP message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance (probably unused). + * @return If the message shall be consumed or not. + */ +static int rdtss_att_info_rsp_handler(ke_msg_id_t const msgid, + struct rdtss_att_info_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + + if (state == RDTSS_IDLE) + { + // Extract the service start handle. + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + // Allocate the attribute information confirmation message. + struct gattc_att_info_cfm *cfm; + cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, TASK_GATTC, dest_id, gattc_att_info_cfm); + // Fill the message. + cfm->handle = rdtss_env->shdl + param->att_idx; + cfm->length = param->length; + cfm->status = param->status; + // Send the confirmation message to GATTC. + ke_msg_send(cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles reception of the @ref GATTC_READ_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int gattc_read_req_ind_handler(ke_msg_id_t const msgid, struct gattc_read_req_ind const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + ke_state_t state = ke_state_get(dest_id); + + if(state == RDTSS_IDLE) + { + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + struct gattc_read_cfm * cfm; + uint8_t att_idx = 0; + uint8_t conidx = KE_IDX_GET(src_id); + // retrieve handle information + + uint8_t status = rdtss_get_att_idx(param->handle, &att_idx); + + uint16_t length = 0; + uint16_t ccc_val = 0; + + // If the attribute has been found, status is GAP_ERR_NO_ERROR + if (status == GAP_ERR_NO_ERROR) + { + if( PERM_GET(rdtss_env->db_cfg.att_tbl[att_idx].perm, UUID_LEN) == PERM_UUID_16 && + (rdtss_env->db_cfg.att_tbl[att_idx].uuid[0] + (rdtss_env->db_cfg.att_tbl[att_idx].uuid[1]<<8) ) == ATT_DESC_CLIENT_CHAR_CFG + ) + { + ccc_val = rdtss_get_ccc_value(conidx, att_idx); + length = 2; + } + else + { + // Request value from application + struct rdtss_value_req_ind* req_ind = KE_MSG_ALLOC(RDTSS_VALUE_REQ_IND, + prf_dst_task_get(&(rdtss_env->prf_env), KE_IDX_GET(src_id)), + dest_id, + rdtss_value_req_ind); + + req_ind->conidx = KE_IDX_GET(src_id); + req_ind->att_idx = att_idx; + + // Send message to application + ke_msg_send(req_ind); + + // Put Service in a busy state + ke_state_set(dest_id, RDTSS_BUSY); + + return (KE_MSG_CONSUMED); + } + } + + // Send read response + cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + src_id, + dest_id, + gattc_read_cfm, + length); + + cfm->handle = param->handle; + cfm->status = status; + cfm->length = length; + + if (status == GAP_ERR_NO_ERROR) + { + memcpy(cfm->value, &ccc_val, length); + } + + ke_msg_send(cfm); + + return (KE_MSG_CONSUMED); + } + // Postpone request if profile is in a busy state + else + { + return (KE_MSG_SAVED); + } +} + +/** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + */ +static int gattc_write_req_ind_handler(ke_msg_id_t const msgid, const struct gattc_write_req_ind *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + struct gattc_write_cfm * cfm; + uint8_t att_idx = 0; + uint8_t conidx = KE_IDX_GET(src_id); + // retrieve handle information + uint8_t status = rdtss_get_att_idx(param->handle, &att_idx); + + uint16_t perm; + + ASSERT_ERR(param->offset == 0); + + // If the attribute has been found, status is ATT_ERR_NO_ERROR + if (status == ATT_ERR_NO_ERROR) + { + if( PERM_GET(rdtss_env->db_cfg.att_tbl[att_idx].perm, UUID_LEN) == PERM_UUID_16 && + (rdtss_env->db_cfg.att_tbl[att_idx].uuid[0] + (rdtss_env->db_cfg.att_tbl[att_idx].uuid[1]<<8) ) == ATT_DESC_CLIENT_CHAR_CFG + ) + { + struct attm_elmt elem = {0}; + + // Find the handle of the Characteristic Value + uint16_t value_hdl = get_value_handle(param->handle); + ASSERT_ERR(value_hdl); + + // Get permissions to identify if it is NTF or IND. + attmdb_att_get_permission(value_hdl, &perm, PERM_MASK_ALL, 0, &elem); + + status = check_client_char_cfg(PERM_IS_SET(perm, NTF, ENABLE), param); + + if (status == ATT_ERR_NO_ERROR) + { + rdtss_set_ccc_value(conidx, att_idx, *(uint16_t *)param->value); + } + } + + + if (status == ATT_ERR_NO_ERROR) + { + // Inform APP + struct rdtss_val_write_ind *req_id = KE_MSG_ALLOC_DYN(RDTSS_VAL_WRITE_IND, + prf_dst_task_get(&(rdtss_env->prf_env), KE_IDX_GET(src_id)), + dest_id, rdtss_val_write_ind, + param->length); + memcpy(req_id->value, param->value, param->length); + req_id->conidx = conidx; + req_id->handle = att_idx; + req_id->length = param->length; + + ke_msg_send(req_id); + } + } + + //Send write response + cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + cfm->handle = param->handle; + cfm->status = status; + ke_msg_send(cfm); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles reception of the attribute info request message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance (probably unused). + * @return If the message shall be consumed or not. + */ +static int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + + if (state == RDTSS_IDLE) + { + // Extract the service start handle. + struct rdtss_env_tag *rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + // Allocate the attribute information request message to be processed by + // the application. + struct rdtss_att_info_req *req = KE_MSG_ALLOC(RDTSS_ATT_INFO_REQ, + TASK_APP, + dest_id, + rdtss_att_info_req); + // Fill the message. + req->conidx = KE_IDX_GET(src_id); + ASSERT_ERR((req->conidx) < BLE_CONNECTION_MAX); + req->att_idx = param->handle - rdtss_env->shdl; + // Send the message to the application. + ke_msg_send(req); + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles reception of the @ref RDTSS_VALUE_REQ_RSP message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance (probably unused). + * @return If the message shall be consumed or not. + */ +static int rdtss_value_req_rsp_handler(ke_msg_id_t const msgid, + struct rdtss_value_req_rsp *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + ke_state_t state = ke_state_get(dest_id); + + if(state == RDTSS_BUSY) + { + if (param->status == ATT_ERR_NO_ERROR) + { + // Send value to peer device. + struct gattc_read_cfm* cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, param->conidx), + dest_id, + gattc_read_cfm, + param->length); + + // Fill parameters + cfm->handle = rdtss_get_att_handle(param->att_idx); + + cfm->status = ATT_ERR_NO_ERROR; + cfm->length = param->length; + memcpy(cfm->value, param->value, param->length); + + // Send message to GATTC + ke_msg_send(cfm); + } + else + { + // Application error, value provided by application is not the expected one + struct gattc_read_cfm* cfm = KE_MSG_ALLOC(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, param->conidx), + dest_id, + gattc_read_cfm); + + // Fill parameters + cfm->handle = rdtss_get_att_handle(param->att_idx); + cfm->status = ATT_ERR_APP_ERROR; + + // Send message to GATTC + ke_msg_send(cfm); + } + + // Return to idle state + ke_state_set(dest_id, RDTSS_IDLE); + } + return (KE_MSG_CONSUMED); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(rdtss) +{ + {GATTC_READ_REQ_IND, (ke_msg_func_t)gattc_read_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t)gattc_write_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t)gattc_att_info_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + {RDTSS_VAL_NTF_REQ, (ke_msg_func_t)rdtss_val_ntf_req_handler}, + {RDTSS_VAL_SET_REQ, (ke_msg_func_t)rdtss_val_set_req_handler}, + {RDTSS_VAL_IND_REQ, (ke_msg_func_t)rdtss_val_ind_req_handler}, + {RDTSS_ATT_INFO_RSP, (ke_msg_func_t)rdtss_att_info_rsp_handler}, + {RDTSS_VALUE_REQ_RSP, (ke_msg_func_t)rdtss_value_req_rsp_handler}, +}; + +void rdtss_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct rdtss_env_tag *p_rdtss_env = PRF_ENV_GET(RDTSS, rdtss); + + p_task_desc->msg_handler_tab = rdtss_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(rdtss_msg_handler_tab); + p_task_desc->state = p_rdtss_env->state; + p_task_desc->idx_max = RDTSS_IDX_MAX; +} + +#endif // BLE_RDTSS_SERVER diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscp_common.h new file mode 100644 index 0000000..650bddb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscp_common.h @@ -0,0 +1,236 @@ +/** + **************************************************************************************** + * + * @file rscp_common.h + * + * @brief Header File - Running Speed and Cadence Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +#ifndef _RSCP_COMMON_H_ +#define _RSCP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup RSCP Running Speed and Cadence Profile + * @ingroup PROFILE + * @brief Running Speed and Cadence Profile + * + * The Running Speed and Cadence profile enables a Collector device to connect and + * interact with a Running Speed and Cadence Sensor for use in sports and fitness + * applications. + * + * This file contains all definitions that are common for the server and the client parts + * of the profile. + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "prf_types.h" +#include +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ +/// Procedure Already in Progress Error Code +#define RSCP_ERROR_PROC_IN_PROGRESS (0x80) +/// Client Characteristic Configuration descriptor improperly configured Error Code +#define RSCP_ERROR_CCC_INVALID_PARAM (0x81) + +/// RSC Measurement Value Min Length +#define RSCP_RSC_MEAS_MIN_LEN (4) +/// RSC Measurement Value Max Length +#define RSCP_RSC_MEAS_MAX_LEN (10) +/// SC Control Point Request Value Min Length +#define RSCP_SC_CNTL_PT_REQ_MIN_LEN (1) +/// SC Control Point Request Value Max Length +#define RSCP_SC_CNTL_PT_REQ_MAX_LEN (5) +/// SC Control Point Response Value Min Length +#define RSCP_SC_CNTL_PT_RSP_MIN_LEN (3) +/// SC Control Point Response Value Max Length +#define RSCP_SC_CNTL_PT_RSP_MAX_LEN (RSCP_SC_CNTL_PT_RSP_MIN_LEN + RSCP_LOC_MAX) + +/// RSC Measurement all present +#define RSCP_MEAS_ALL_PRESENT (0x07) +/// RSC Feature all supported +#define RSCP_FEAT_ALL_SUPP (0x001F) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Running Speed and Cadence Service Characteristics +enum rscp_rscs_char +{ + /// RSC Measurement + RSCP_RSCS_RSC_MEAS_CHAR, + /// RSC Feature + RSCP_RSCS_RSC_FEAT_CHAR, + /// Sensor Location + RSCP_RSCS_SENSOR_LOC_CHAR, + /// SC Control Point + RSCP_RSCS_SC_CTNL_PT_CHAR, + + /// Maximum Characteristic + RSCP_RSCS_CHAR_MAX, +}; + +/// RSC Measurement Flags bit field +enum rscp_meas_flags_bf +{ + /// Instantaneous Stride Length Present + /// 0 False and 1 True + RSCP_MEAS_INST_STRIDE_LEN_PRESENT_POS = 0, + RSCP_MEAS_INST_STRIDE_LEN_PRESENT_BIT = CO_BIT(RSCP_MEAS_INST_STRIDE_LEN_PRESENT_POS), + /// Total Distance Present + /// 0 False and 1 True + RSCP_MEAS_TOTAL_DST_MEAS_PRESENT_POS = 1, + RSCP_MEAS_TOTAL_DST_MEAS_PRESENT_BIT = CO_BIT(RSCP_MEAS_TOTAL_DST_MEAS_PRESENT_POS), + /// Walking or Running + /// 0 Walking and 1 Running + RSCP_MEAS_WALK_RUN_STATUS_POS = 2, + RSCP_MEAS_WALK_RUN_STATUS_BIT = CO_BIT(RSCP_MEAS_WALK_RUN_STATUS_POS), +}; + +/// RSC Feature Flags bit field +enum rscp_feat_flags_bf +{ + /// Instantaneous Stride Length Measurement Supported + RSCP_FEAT_INST_STRIDE_LEN_SUPP_POS = 0, + RSCP_FEAT_INST_STRIDE_LEN_SUPP_BIT = CO_BIT(RSCP_FEAT_INST_STRIDE_LEN_SUPP_POS), + + /// Total Distance Measurement Supported + RSCP_FEAT_TOTAL_DST_MEAS_SUPP_POS = 1, + RSCP_FEAT_TOTAL_DST_MEAS_SUPP_BIT = CO_BIT(RSCP_FEAT_TOTAL_DST_MEAS_SUPP_POS), + + /// Walking or Running Status Supported + RSCP_FEAT_WALK_RUN_STATUS_SUPP_POS = 2, + RSCP_FEAT_WALK_RUN_STATUS_SUPP_BIT = CO_BIT(RSCP_FEAT_WALK_RUN_STATUS_SUPP_POS), + + /// Calibration Procedure Supported + RSCP_FEAT_CALIB_PROC_SUPP_POS = 3, + RSCP_FEAT_CALIB_PROC_SUPP_BIT = CO_BIT(RSCP_FEAT_CALIB_PROC_SUPP_POS), + + /// Multiple Sensor Locations Supported + RSCP_FEAT_MULT_SENSOR_LOC_SUPP_POS = 4, + RSCP_FEAT_MULT_SENSOR_LOC_SUPP_BIT = CO_BIT(RSCP_FEAT_MULT_SENSOR_LOC_SUPP_POS), +}; + +/// Sensor Locations Keys +enum rscp_sensor_loc +{ + /// Other (0) + RSCP_LOC_OTHER = 0, + /// Top of shoe (1) + RSCP_LOC_TOP_SHOE, + /// In shoe (2) + RSCP_LOC_IN_SHOE, + /// Hip (3) + RSCP_LOC_HIP, + /// Chest (14) + RSCP_LOC_CHEST = 14, + + /// Maximum Sensor Location + RSCP_LOC_MAX, +}; + +/// Control Point Operation Code Keys +enum rscp_sc_ctnl_pt_op_code +{ + /// Reserved value + RSCP_CTNL_PT_OP_RESERVED = 0, + + /// Set Cumulative Value + RSCP_CTNL_PT_OP_SET_CUMUL_VAL, + /// Start Sensor Calibration + RSCP_CTNL_PT_OP_START_CALIB, + /// Update Sensor Location + RSCP_CTNL_PT_OP_UPD_LOC, + /// Request Supported Sensor Locations + RSCP_CTNL_PT_OP_REQ_SUPP_LOC, + + /// Response Code + RSCP_CTNL_PT_RSP_CODE = 16, +}; + +/// Control Point Response Value +enum rscp_sc_ctnl_pt_resp_val +{ + /// Reserved value + RSCP_CTNL_PT_RESP_RESERVED = 0, + + /// Success + RSCP_CTNL_PT_RESP_SUCCESS, + /// Operation Code Not Supported + RSCP_CTNL_PT_RESP_NOT_SUPP, + /// Invalid Parameter + RSCP_CTNL_PT_RESP_INV_PARAM, + /// Operation Failed + RSCP_CTNL_PT_RESP_FAILED, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// RSC Measurement +struct rscp_rsc_meas +{ + /// Flags + uint8_t flags; + /// Instantaneous Cadence + uint8_t inst_cad; + /// Instantaneous Speed + uint16_t inst_speed; + /// Instantaneous Stride Length + uint16_t inst_stride_len; + /// Total Distance + uint32_t total_dist; +}; + +/// SC Control Point Request +struct rscp_sc_ctnl_pt_req +{ + /// Operation Code + uint8_t op_code; + /// Value + union rscp_sc_ctnl_pt_req_val + { + /// Sensor Location + uint8_t sensor_loc; + /// Cumulative value + uint32_t cumul_val; + } value; +}; + +/// SC Control Point Response +struct rscp_sc_ctnl_pt_rsp +{ + /// Control Point Op code + uint8_t cp_opcode; + /// Requested Operation Code + uint8_t req_op_code; + /// Response Value + uint8_t resp_value; + /// List of supported locations + uint16_t supp_loc; +}; + + +/// @} rscp_common + +#endif //(_RSCP_COMMON_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/api/rscpc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/api/rscpc_task.h new file mode 100644 index 0000000..eca6559 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/api/rscpc_task.h @@ -0,0 +1,210 @@ +/** + **************************************************************************************** + * + * @file rscpc_task.h + * + * @brief Header file - Running Speed and Cadence Profile Collector Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _RSCPC_TASK_H_ +#define _RSCPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup RSCPCTASK Running Speed and Cadence Profile Collector Task + * @ingroup RSCPC + * @brief Running Speed and Cadence Profile Collector Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rscp_common.h" +#include "rwip_task.h" // Task definitions + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Message IDs +/*@TRACE*/ +enum rscpc_msg_ids +{ + /// Enable the Running Speed and Cadence Profile Collector task - at connection + RSCPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_RSCPC), + /// Enable the Running Speed and Cadence Profile Collector task - at connection + RSCPC_ENABLE_RSP, + /// Read the value of an attribute in the peer device database + RSCPC_READ_CMD, + /// Configure sending of notification or indication + RSCPC_CFG_NTFIND_CMD, + /// Configure the SC Control Point value + RSCPC_CTNL_PT_CFG_CMD, + /// SC Control Point value response + RSCPC_CTNL_PT_IND, + /// Indicate that an attribute value has been received either upon notification or read response + RSCPC_VALUE_IND, + /// Complete Event Information + RSCPC_CMP_EVT, + + /// Procedure Timeout Timer + RSCPC_TIMEOUT_TIMER_IND, +}; + +/// Operation Codes +enum rscpc_op_codes +{ + /// Reserved operation code + RSCPC_RESERVED_OP_CODE = 0x00, + + /// Discovery Procedure + RSCPC_ENABLE_OP_CODE, + /// Read attribute value Procedure + RSCPC_READ_OP_CODE, + + /// Wait for the Write Response after having written a Client Char. Cfg. Descriptor. + RSCPC_CFG_NTF_IND_OP_CODE, + /// Wait for the Write Response after having written the SC Control Point Char. + RSCPC_CTNL_PT_CFG_WR_OP_CODE, + /// Wait for the Indication Response after having written the SC Control Point Char. + RSCPC_CTNL_PT_CFG_IND_OP_CODE, +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ + +/// Running Speed and Cadence Service Characteristic Descriptors +enum rscpc_rscs_descs +{ + /// RSC Measurement Char. - Client Characteristic Configuration + RSCPC_DESC_RSC_MEAS_CL_CFG, + /// SC Control Point Char. - Client Characteristic Configuration + RSCPC_DESC_SC_CTNL_PT_CL_CFG, + + RSCPC_DESC_MAX, + + RSCPC_DESC_MASK = 0x10, +}; + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Running Speed and Cadence Service + */ +struct rscpc_rscs_content +{ + /// Service info + struct prf_svc svc; + + /// Characteristic info: + /// - RSC Measurement + /// - RSC Feature + /// - Sensor Location + /// - SC Control Point + struct prf_char_inf chars[RSCP_RSCS_CHAR_MAX]; + + /// Descriptor handles: + /// - RSC Measurement Client Cfg + /// - SC Control Point Client Cfg + struct prf_char_desc_inf descs[RSCPC_DESC_MAX]; +}; + +/// Parameters of the @ref RSCPC_ENABLE_REQ message +struct rscpc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values RSCS + struct rscpc_rscs_content rscs; +}; + +/// Parameters of the @ref RSCPC_ENABLE_RSP message +struct rscpc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values RSCS + struct rscpc_rscs_content rscs; +}; + +/// Parameters of the @ref RSCPC_READ_CMD message +struct rscpc_read_cmd +{ + /// Operation Code + uint8_t operation; + /// Read code + uint8_t read_code; +}; + + +/// Parameters of the @ref RSCPC_CFG_NTFIND_CMD message +struct rscpc_cfg_ntfind_cmd +{ + /// Operation Code + uint8_t operation; + /// Descriptor code + uint8_t desc_code; + /// Ntf/Ind Configuration + uint16_t ntfind_cfg; +}; + +/// Parameters of the @ref RSCPC_CTNL_PT_CFG_CMD message +struct rscpc_ctnl_pt_cfg_cmd +{ + /// Operation Code + uint8_t operation; + /// SC Control Point Request + struct rscp_sc_ctnl_pt_req sc_ctnl_pt; +}; + +/// Parameters of the @ref RSCPC_CTNL_PT_IND message +struct rscpc_ctnl_pt_ind +{ + /// SC Control Point Response + struct rscp_sc_ctnl_pt_rsp ctnl_pt_rsp; +}; + +/// Parameters of the @ref RSCPC_VALUE_IND message +struct rscpc_value_ind +{ + /// Attribute Code + uint8_t att_code; + /// Value + union rscpc_value_tag + { + /// RSC Measurement + struct rscp_rsc_meas rsc_meas; + /// RSC Feature + uint16_t sensor_feat; + /// Sensor Location + uint8_t sensor_loc; + /// Client Characteristic Configuration Descriptor Value + uint16_t ntf_cfg; + } value; +}; + +/// Parameters of the @ref RSCPC_CMP_EVT message +struct rscpc_cmp_evt +{ + /// Operation code + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} RSCPCTASK + +#endif //(_RSCPC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/sourcelist.txt new file mode 100644 index 0000000..b60fccc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + rscpc.c + rscpc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/src/rscpc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/src/rscpc.c new file mode 100644 index 0000000..9c031f5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/src/rscpc.c @@ -0,0 +1,253 @@ +/** + **************************************************************************************** + * + * @file rscpc.c + * + * @brief Running Speed and Cadence Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup RSCPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_RSC_COLLECTOR) +#include "rscp_common.h" + + +#include "rscpc.h" +#include "rscpc_task.h" +#include "ke_timer.h" +#include "ke_mem.h" + +/* + * GLOBAL VARIABLES DECLARATION + **************************************************************************************** + */ + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the RSCPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t rscpc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct rscpc_env_tag* p_rscpc_env = + (struct rscpc_env_tag* ) ke_malloc(sizeof(struct rscpc_env_tag), KE_MEM_ATT_DB); + + // allocate RSCPC required environment variable + p_env->env = (prf_env_t*) p_rscpc_env; + + p_rscpc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_rscpc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_RSCPC; + rscpc_task_init(&(p_env->desc)); + + for (idx = 0; idx < RSCPC_IDX_MAX ; idx++) + { + p_rscpc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), RSCPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void rscpc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct rscpc_env_tag *p_rscpc_env = (struct rscpc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_rscpc_env->p_env[conidx] != NULL) + { + if (p_rscpc_env->p_env[conidx]->p_operation != NULL) + { + ke_free(ke_param2msg(p_rscpc_env->p_env[conidx]->p_operation)); + } + ke_timer_clear(RSCPC_TIMEOUT_TIMER_IND, prf_src_task_get(&p_rscpc_env->prf_env, conidx)); + ke_free(p_rscpc_env->p_env[conidx]); + p_rscpc_env->p_env[conidx] = NULL; + } + + // Put RSCP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), RSCPC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the RSCPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void rscpc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct rscpc_env_tag *p_rscpc_env = (struct rscpc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < RSCPC_IDX_MAX; idx++) + { + rscpc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_rscpc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void rscpc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put RSCP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), RSCPC_IDLE); +} + +/// RSCPC Task interface required by profile manager +const struct prf_task_cbs rscpc_itf = +{ + rscpc_init, + rscpc_destroy, + rscpc_create, + rscpc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *rscpc_prf_itf_get(void) +{ + return &rscpc_itf; +} + +void rscpc_enable_rsp_send(struct rscpc_env_tag *p_rscpc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on RSCPS + struct rscpc_enable_rsp *p_rsp = KE_MSG_ALLOC( + RSCPC_ENABLE_RSP, + prf_dst_task_get(&(p_rscpc_env->prf_env), conidx), + prf_src_task_get(&(p_rscpc_env->prf_env), conidx), + rscpc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->rscs = p_rscpc_env->p_env[conidx]->rscs; + // Register RSCPC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_rscpc_env->prf_env), conidx, &(p_rscpc_env->p_env[conidx]->rscs.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_rscpc_env->prf_env), conidx), RSCPC_IDLE); + } + + ke_msg_send(p_rsp); +} + +void rscps_send_no_conn_cmp_evt(uint8_t src_id, uint8_t dest_id, uint8_t operation) +{ + // Send the message + struct rscpc_cmp_evt *p_evt = KE_MSG_ALLOC(RSCPC_CMP_EVT, + dest_id, src_id, + rscpc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = PRF_ERR_REQ_DISALLOWED; + + ke_msg_send(p_evt); +} + +void rscpc_send_cmp_evt(struct rscpc_env_tag *p_rscpc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct rscpc_cmp_evt *p_evt; + + // Free the stored operation if needed + if (p_rscpc_env->p_env[conidx]->p_operation != NULL) + { + ke_msg_free(ke_param2msg(p_rscpc_env->p_env[conidx]->p_operation)); + p_rscpc_env->p_env[conidx]->p_operation = NULL; + } + + // Go back to the CONNECTED state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_rscpc_env->prf_env), conidx)) == RSCPC_BUSY) + { + ke_state_set(prf_src_task_get(&(p_rscpc_env->prf_env), conidx), RSCPC_IDLE); + } + + // Send the message + p_evt = KE_MSG_ALLOC(RSCPC_CMP_EVT, + prf_dst_task_get(&(p_rscpc_env->prf_env), conidx), + prf_src_task_get(&(p_rscpc_env->prf_env), conidx), + rscpc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //(BLE_RSC_COLLECTOR) + +/// @} RSCP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/src/rscpc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/src/rscpc.h new file mode 100644 index 0000000..d5040bd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/src/rscpc.h @@ -0,0 +1,199 @@ +/** + **************************************************************************************** + * + * @file rscpc.h + * + * @brief Header file - Running Speed and Cadence Status Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _RSCPC_H_ +#define _RSCPC_H_ + +/** + **************************************************************************************** + * @addtogroup RSCPC Running Speed and Cadence Profile Collector + * @ingroup RSCP + * @brief Running Speed and Cadence Profile Collector + * @{ + **************************************************************************************** + */ + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Running Speed and Cadence Collector task instances +#define RSCPC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_RSC_COLLECTOR) +#include "rscpc_task.h" + +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the RSCPC task +enum rscpc_states +{ + /// Idle state + RSCPC_FREE, + /// Connected state + RSCPC_IDLE, + /// Discovery + RSCPC_DISCOVERING, + /// Busy state + RSCPC_BUSY, + + /// Number of defined states. + RSCPC_STATE_MAX +}; + + +/// Internal codes for reading/writing a RSCS characteristic with one single request +enum rscpc_codes +{ + /// Notified RSC Measurement + RSCPC_NTF_RSC_MEAS = RSCP_RSCS_RSC_MEAS_CHAR, + /// Read RSC Feature + RSCPC_RD_RSC_FEAT = RSCP_RSCS_RSC_FEAT_CHAR, + /// Read Sensor Location + RSCPC_RD_SENSOR_LOC = RSCP_RSCS_SENSOR_LOC_CHAR, + /// Indicated SC Control Point + RSCPC_IND_SC_CTNL_PT = RSCP_RSCS_SC_CTNL_PT_CHAR, + + /// Read/Write RSC Measurement Client Char. Configuration Descriptor + RSCPC_RD_WR_RSC_MEAS_CFG = (RSCPC_DESC_RSC_MEAS_CL_CFG | RSCPC_DESC_MASK), + /// Read SC Control Point Client Char. Configuration Descriptor + RSCPC_RD_WR_SC_CTNL_PT_CFG = (RSCPC_DESC_SC_CTNL_PT_CL_CFG | RSCPC_DESC_MASK), +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +struct rscpc_cnx_env +{ + /// Current Operation + void *p_operation; + ///Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Counter used to check service uniqueness + uint8_t nb_svc; + /// Running Speed and Cadence Service Characteristics + struct rscpc_rscs_content rscs; +}; + +/// Running Speed and Cadence Profile Collector environment variable +struct rscpc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct rscpc_cnx_env *p_env[RSCPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[RSCPC_IDX_MAX]; +}; + +/// Command Message Basic Structure +struct rscpc_cmd +{ + /// Operation Code + uint8_t operation; + + /// MORE DATA +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve RSCP client profile interface + * + * @return RSCP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* rscpc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Running Speed and Cadence ATT DB discovery results to RSCPC host. + * + * @param p_rscpc_env RSCP Client Role task environment + * @param conidx Connection index + * @param status Response status code + **************************************************************************************** + */ +void rscpc_enable_rsp_send(struct rscpc_env_tag *p_rscpc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send a RSCPC_CMP_EVT message when no connection exists (no environment) + * + * @param src_id Source ID + * @param dst_id Destination ID + * @param operation Operation code + **************************************************************************************** + */ +void rscps_send_no_conn_cmp_evt(uint8_t src_id, uint8_t dest_id, uint8_t operation); + +/** + **************************************************************************************** + * @brief Send a RSCPC_CMP_EVT message to the task which enabled the profile + * + * @param[in] p_rscpc_env RSCP Client environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void rscpc_send_cmp_evt(struct rscpc_env_tag *p_rscpc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void rscpc_task_init(struct ke_task_desc *p_task_desc); + + +#endif //(BLE_RSC_COLLECTOR) + +/// @} RSCPC + +#endif //(_RSCPC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/src/rscpc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/src/rscpc_task.c new file mode 100644 index 0000000..5d50711 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscpc/src/rscpc_task.c @@ -0,0 +1,960 @@ +/** + **************************************************************************************** + * + * @file rscpc_task.c + * + * @brief Running Speed and Cadence Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup RSCPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_RSC_COLLECTOR) +#include "rscp_common.h" +#include "rscpc_task.h" +#include "rscpc.h" + +#include "gap.h" +#include "attm.h" +#include "gattc_task.h" +#include "prf_utils.h" +#include "compiler.h" +#include "ke_timer.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve Running Speed and Cadence service characteristics information +const struct prf_char_def rscpc_rscs_char[RSCP_RSCS_CHAR_MAX] = +{ + // RSC Measurement + [RSCP_RSCS_RSC_MEAS_CHAR] = {ATT_CHAR_RSC_MEAS, + ATT_MANDATORY, + ATT_CHAR_PROP_NTF}, + // RSC Feature + [RSCP_RSCS_RSC_FEAT_CHAR] = {ATT_CHAR_RSC_FEAT, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, + // Sensor Location + [RSCP_RSCS_SENSOR_LOC_CHAR] = {ATT_CHAR_SENSOR_LOC, + ATT_OPTIONAL, + ATT_CHAR_PROP_RD}, + // SC Control Point + [RSCP_RSCS_SC_CTNL_PT_CHAR] = {ATT_CHAR_SC_CNTL_PT, + ATT_OPTIONAL, + ATT_CHAR_PROP_WR | ATT_CHAR_PROP_IND}, +}; + +/// State machine used to retrieve Running Speed and Cadence service characteristic descriptor information +const struct prf_char_desc_def rscpc_rscs_char_desc[RSCPC_DESC_MAX] = +{ + // RSC Measurement Char. - Client Characteristic Configuration + [RSCPC_DESC_RSC_MEAS_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + RSCP_RSCS_RSC_MEAS_CHAR}, + // SC Control Point Char. - Client Characteristic Configuration + [RSCPC_DESC_SC_CTNL_PT_CL_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_OPTIONAL, + RSCP_RSCS_SC_CTNL_PT_CHAR}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == RSCPC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + struct rscpc_env_tag *p_rscpc_env = PRF_ENV_GET(RSCPC, rscpc); + + ASSERT_INFO(p_rscpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_rscpc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_rscpc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve RSCS characteristics and descriptors + prf_extract_svc_info(p_ind, + RSCP_RSCS_CHAR_MAX, &rscpc_rscs_char[0], &p_rscpc_env->p_env[conidx]->rscs.chars[0], + RSCPC_DESC_MAX, &rscpc_rscs_char_desc[0], &p_rscpc_env->p_env[conidx]->rscs.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_rscpc_env->p_env[conidx]->rscs.svc.shdl = p_ind->start_hdl; + p_rscpc_env->p_env[conidx]->rscs.svc.ehdl = p_ind->end_hdl; + } + + p_rscpc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref RSCPC_ENABLE_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int rscpc_enable_req_handler(ke_msg_id_t const msgid, + struct rscpc_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + uint8_t state = ke_state_get(dest_id); + // Running Speed and Cadence Profile Collector Role Task Environment + struct rscpc_env_tag *p_rscpc_env = PRF_ENV_GET(RSCPC, rscpc); + + ASSERT_INFO(p_rscpc_env != NULL, dest_id, src_id); + if ((state == RSCPC_IDLE) && (p_rscpc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_rscpc_env->p_env[conidx] = (struct rscpc_cnx_env *) ke_malloc(sizeof(struct rscpc_cnx_env), KE_MEM_ATT_DB); + memset(p_rscpc_env->p_env[conidx], 0, sizeof(struct rscpc_cnx_env)); + + // Start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + prf_disc_svc_send(&(p_rscpc_env->prf_env), conidx, ATT_SVC_RUNNING_SPEED_CADENCE); + + // Go to DISCOVERING state + ke_state_set(dest_id, RSCPC_DISCOVERING); + } + // Bond information is provided + else + { + p_rscpc_env->p_env[conidx]->rscs = p_param->rscs; + + //send APP confirmation that can start normal connection to TH + rscpc_enable_rsp_send(p_rscpc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != RSCPC_FREE) + { + // The message will be forwarded towards the good task instance + status = PRF_ERR_REQ_DISALLOWED; + } + + if (status != GAP_ERR_NO_ERROR) + { + // The request is disallowed (profile already enabled for this connection, or not enough memory, ...) + rscpc_enable_rsp_send(p_rscpc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref RSCPC_READ_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int rscpc_read_cmd_handler(ke_msg_id_t const msgid, + struct rscpc_read_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct rscpc_env_tag *p_rscpc_env = PRF_ENV_GET(RSCPC, rscpc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == RSCPC_IDLE) + { + // State is Connected or Busy + ASSERT_INFO(p_rscpc_env != NULL, dest_id, src_id); + + // Check the current state + if (p_rscpc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + // State is RSCPC_CONNECTED + else + { + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + + switch (p_param->read_code) + { + // Read RSC Feature + case (RSCPC_RD_RSC_FEAT): + { + handle = p_rscpc_env->p_env[conidx]->rscs.chars[RSCP_RSCS_RSC_FEAT_CHAR].val_hdl; + } break; + + // Read Sensor Location + case (RSCPC_RD_SENSOR_LOC): + { + handle = p_rscpc_env->p_env[conidx]->rscs.chars[RSCP_RSCS_SENSOR_LOC_CHAR].val_hdl; + } break; + + // Read RSC Measurement Characteristic Client Char. Cfg. Descriptor Value + case (RSCPC_RD_WR_RSC_MEAS_CFG): + { + handle = p_rscpc_env->p_env[conidx]->rscs.descs[RSCPC_DESC_RSC_MEAS_CL_CFG].desc_hdl; + } break; + + // Read Unread Alert Characteristic Client Char. Cfg. Descriptor Value + case (RSCPC_RD_WR_SC_CTNL_PT_CFG): + { + handle = p_rscpc_env->p_env[conidx]->rscs.descs[RSCPC_DESC_SC_CTNL_PT_CL_CFG].desc_hdl; + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + // Check if handle is viable + if (handle != ATT_INVALID_SEARCH_HANDLE) + { + // Force the operation value + p_param->operation = RSCPC_READ_OP_CODE; + + // Store the command structure + p_rscpc_env->p_env[conidx]->p_operation = (void *)p_param; + msg_status = KE_MSG_NO_FREE; + + // Send the read request + prf_read_char_send(&(p_rscpc_env->prf_env), conidx, + p_rscpc_env->p_env[conidx]->rscs.svc.shdl, + p_rscpc_env->p_env[conidx]->rscs.svc.ehdl, + handle); + + // Go to the Busy state + ke_state_set(dest_id, RSCPC_BUSY); + + status = ATT_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == RSCPC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + // Send the complete event message to the task id stored in the environment + rscpc_send_cmp_evt(p_rscpc_env, conidx, RSCPC_READ_OP_CODE, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref RSCPC_CFG_NTFIND_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int rscpc_cfg_ntfind_cmd_handler(ke_msg_id_t const msgid, + struct rscpc_cfg_ntfind_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct rscpc_env_tag *p_rscpc_env = PRF_ENV_GET(RSCPC, rscpc); + // Message status + int msg_status = KE_MSG_CONSUMED; + + if (p_rscpc_env != NULL) + { + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + do + { + if (ke_state_get(dest_id) != RSCPC_IDLE) + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + // Status is GAP_ERR_NO_ERROR, no message will be sent to the application + break; + } + + ASSERT_ERR(p_rscpc_env->p_env[conidx] != NULL); + + switch (p_param->desc_code) + { + // Write RSC Measurement Characteristic Client Char. Cfg. Descriptor Value + case (RSCPC_RD_WR_RSC_MEAS_CFG): + { + if (p_param->ntfind_cfg <= PRF_CLI_START_NTF) + { + handle = p_rscpc_env->p_env[conidx]->rscs.descs[RSCPC_DESC_RSC_MEAS_CL_CFG].desc_hdl; + + status = GAP_ERR_NO_ERROR; + // The characteristic is mandatory and the descriptor is mandatory + ASSERT_ERR(handle != ATT_INVALID_SEARCH_HANDLE); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + // Write SC Control Point Characteristic Client Char. Cfg. Descriptor Value + case (RSCPC_RD_WR_SC_CTNL_PT_CFG): + { + if ((p_param->ntfind_cfg == PRF_CLI_STOP_NTFIND) || + (p_param->ntfind_cfg == PRF_CLI_START_IND)) + { + handle = p_rscpc_env->p_env[conidx]->rscs.descs[RSCPC_DESC_SC_CTNL_PT_CL_CFG].desc_hdl; + + status = GAP_ERR_NO_ERROR; + if (handle == ATT_INVALID_SEARCH_HANDLE) + { + // The descriptor has not been found. + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + } while (0); + + if ((status == GAP_ERR_NO_ERROR) && (handle != ATT_INVALID_SEARCH_HANDLE)) + { + // Set the operation code + p_param->operation = RSCPC_CFG_NTF_IND_OP_CODE; + + // Store the command structure + p_rscpc_env->p_env[conidx]->p_operation = p_param; + msg_status = KE_MSG_NO_FREE; + + // Go to the Busy state + ke_state_set(dest_id, RSCPC_BUSY); + + // Send GATT Write Request + prf_gatt_write_ntf_ind(&p_rscpc_env->prf_env, conidx, handle, p_param->ntfind_cfg); + } + } + else + { + // No connection + rscps_send_no_conn_cmp_evt(dest_id, src_id, RSCPC_CFG_NTF_IND_OP_CODE); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref RSCPC_CFG_NTFIND_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int rscpc_ctnl_pt_cfg_cmd_handler(ke_msg_id_t const msgid, + struct rscpc_ctnl_pt_cfg_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct rscpc_env_tag *p_rscpc_env = PRF_ENV_GET(RSCPC, rscpc); + + if (p_rscpc_env != NULL) + { + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + do + { + // State is Connected or Busy + ASSERT_ERR(ke_state_get(dest_id) > RSCPC_FREE); + + // Check the provided connection handle + if (p_rscpc_env->p_env[conidx] == NULL) + { + status = PRF_ERR_INVALID_PARAM; + break; + } + + if (ke_state_get(dest_id) != RSCPC_IDLE) + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + // Status is GAP_ERR_NO_ERROR, no message will be sent to the application + break; + } + + // Check if the characteristic has been found + if (p_rscpc_env->p_env[conidx]->rscs.descs[RSCPC_DESC_SC_CTNL_PT_CL_CFG].desc_hdl != ATT_INVALID_SEARCH_HANDLE) + { + // Packed request + uint8_t req[RSCP_SC_CNTL_PT_REQ_MAX_LEN]; + // Request Length + uint8_t req_len = RSCP_SC_CNTL_PT_REQ_MIN_LEN; + + // Set the operation code + req[0] = p_param->sc_ctnl_pt.op_code; + + // Fulfill the message according to the operation code + switch (p_param->sc_ctnl_pt.op_code) + { + case (RSCP_CTNL_PT_OP_RESERVED): + { + // Do nothing, used to generate an "Operation Code not supported" error. + } break; + + case (RSCP_CTNL_PT_OP_SET_CUMUL_VAL): + { + // Set the cumulative value + co_write32p(&req[req_len], p_param->sc_ctnl_pt.value.cumul_val); + // Update length + req_len += 4; + } break; + + case (RSCP_CTNL_PT_OP_UPD_LOC): + { + // Set the sensor location + req[req_len] = p_param->sc_ctnl_pt.value.sensor_loc; + // Update length + req_len++; + } break; + + case (RSCP_CTNL_PT_OP_START_CALIB): + case (RSCP_CTNL_PT_OP_REQ_SUPP_LOC): + { + // Nothing more to do + } break; + + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + if (status == GAP_ERR_NO_ERROR) + { + // Set the operation code + p_param->operation = RSCPC_CTNL_PT_CFG_WR_OP_CODE; + + // Store the command structure + p_rscpc_env->p_env[conidx]->p_operation = p_param; + // Store the command information + msg_status = KE_MSG_NO_FREE; + + // Go to the Busy state + ke_state_set(dest_id, RSCPC_BUSY); + + // Send the write request + prf_gatt_write(&(p_rscpc_env->prf_env), conidx, + p_rscpc_env->p_env[conidx]->rscs.chars[RSCP_RSCS_SC_CTNL_PT_CHAR].val_hdl, + (uint8_t *)&req[0], req_len, GATTC_WRITE); + } + } + else + { + // The SC Control Point Characteristic has not been found + status = PRF_ERR_INEXISTENT_HDL; + } + } while (0); + + if (status != GAP_ERR_NO_ERROR) + { + // Send a complete event status to the application + rscpc_send_cmp_evt(p_rscpc_env, conidx, RSCPC_CTNL_PT_CFG_WR_OP_CODE, status); + } + } + else + { + // No connection + rscps_send_no_conn_cmp_evt(dest_id, src_id, RSCPC_CTNL_PT_CFG_WR_OP_CODE); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref RSCPC_TIMEOUT_TIMER_IND message. This message is + * received when the peer device doesn't send a SC Control Point indication within 30s + * after reception of the write response. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int rscpc_timeout_timer_ind_handler(ke_msg_id_t const msgid, + void const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct rscpc_env_tag *p_rscpc_env = PRF_ENV_GET(RSCPC, rscpc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if ((p_rscpc_env != NULL) && (p_rscpc_env->p_env[conidx] != NULL)) + { + ASSERT_ERR(p_rscpc_env->p_env[conidx]->p_operation != NULL); + ASSERT_ERR(((struct rscpc_cmd *)p_rscpc_env->p_env[conidx]->p_operation)->operation + == RSCPC_CTNL_PT_CFG_IND_OP_CODE); + + // Send the complete event message + rscpc_send_cmp_evt(p_rscpc_env, conidx, RSCPC_CTNL_PT_CFG_WR_OP_CODE, PRF_ERR_PROC_TIMEOUT); + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct rscpc_env_tag *p_rscpc_env = PRF_ENV_GET(RSCPC, rscpc); + // Status + uint8_t status; + + if (p_rscpc_env != NULL) + { + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == RSCPC_DISCOVERING) + { + status = p_param->status; + + if ((status == ATT_ERR_ATTRIBUTE_NOT_FOUND) || + (status == ATT_ERR_NO_ERROR)) + { + // Discovery + // check characteristic validity + if (p_rscpc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(RSCP_RSCS_CHAR_MAX, + p_rscpc_env->p_env[conidx]->rscs.chars, + rscpc_rscs_char); + } + // too much services + else if (p_rscpc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(RSCPC_DESC_MAX, + p_rscpc_env->p_env[conidx]->rscs.descs, + rscpc_rscs_char_desc, + p_rscpc_env->p_env[conidx]->rscs.chars); + } + } + + rscpc_enable_rsp_send(p_rscpc_env, conidx, status); + } + + else if (state == RSCPC_BUSY) + { + switch (p_param->operation) + { + case GATTC_READ: + { + // Send the complete event status + rscpc_send_cmp_evt(p_rscpc_env, conidx, RSCPC_READ_OP_CODE, p_param->status); + } break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + uint8_t operation = ((struct rscpc_cmd *)p_rscpc_env->p_env[conidx]->p_operation)->operation; + + if (operation == RSCPC_CFG_NTF_IND_OP_CODE) + { + // Send the complete event status + rscpc_send_cmp_evt(p_rscpc_env, conidx, operation, p_param->status); + } + + else if (operation == RSCPC_CTNL_PT_CFG_WR_OP_CODE) + { + if (p_param->status == GAP_ERR_NO_ERROR) + { + // Start Timeout Procedure + ke_timer_set(RSCPC_TIMEOUT_TIMER_IND, dest_id, 10*ATT_TRANS_RTX); + + // Wait for the response indication + ((struct rscpc_cmd *)p_rscpc_env->p_env[conidx]->p_operation)->operation = + RSCPC_CTNL_PT_CFG_IND_OP_CODE; + } + else + { + // Send the complete event status + rscpc_send_cmp_evt(p_rscpc_env, conidx, operation, p_param->status); + } + } + } break; + + case GATTC_REGISTER: + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == RSCPC_BUSY) + { + // Get the address of the environment + struct rscpc_env_tag *p_rscpc_env = PRF_ENV_GET(RSCPC, rscpc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_rscpc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_rscpc_env->p_env[conidx] != NULL, dest_id, src_id); + + // Send the read value to the HL + struct rscpc_value_ind *p_ind = KE_MSG_ALLOC(RSCPC_VALUE_IND, + prf_dst_task_get(&(p_rscpc_env->prf_env), conidx), + dest_id, + rscpc_value_ind); + + switch (((struct rscpc_read_cmd *)p_rscpc_env->p_env[conidx]->p_operation)->read_code) + { + // Read RSC Feature Characteristic value + case (RSCPC_RD_RSC_FEAT): + { + p_ind->value.sensor_feat = co_read16p(p_param->value); + } break; + + // Read Sensor Location Characteristic value + case (RSCPC_RD_SENSOR_LOC): + { + p_ind->value.sensor_loc = p_param->value[0]; + } break; + + // Read Client Characteristic Configuration Descriptor value + case (RSCPC_RD_WR_RSC_MEAS_CFG): + case (RSCPC_RD_WR_SC_CTNL_PT_CFG): + { + co_write16p(&p_ind->value.ntf_cfg, p_param->value[0]); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + p_ind->att_code = ((struct rscpc_read_cmd *)p_rscpc_env->p_env[conidx]->p_operation)->read_code; + + // Send the message to the application + ke_msg_send(p_ind); + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct rscpc_env_tag *p_rscpc_env = PRF_ENV_GET(RSCPC, rscpc); + + if (p_rscpc_env != NULL) + { + switch (p_param->type) + { + case (GATTC_NOTIFY): + { + // Offset + uint8_t offset = RSCP_RSC_MEAS_MIN_LEN; + + // RSC Measurement value has been received + struct rscpc_value_ind *p_ind = KE_MSG_ALLOC(RSCPC_VALUE_IND, + prf_dst_task_get(&(p_rscpc_env->prf_env), conidx), + prf_src_task_get(&(p_rscpc_env->prf_env), conidx), + rscpc_value_ind); + + // Attribute code + p_ind->att_code = RSCPC_NTF_RSC_MEAS; + + /*---------------------------------------------------- + * Unpack Measurement -------------------------------- + *----------------------------------------------------*/ + + // Flags + p_ind->value.rsc_meas.flags = p_param->value[0]; + // Instantaneous Speed + p_ind->value.rsc_meas.inst_speed = co_read16p((uint16_t *)&p_param->value[1]); + // Instantaneous Cadence + p_ind->value.rsc_meas.inst_cad = p_param->value[3]; + + // Instantaneous Stride Length + if (GETB(p_param->value[0], RSCP_MEAS_INST_STRIDE_LEN_PRESENT)) + { + p_ind->value.rsc_meas.inst_stride_len = co_read16p(&p_param->value[offset]); + offset += 2; + } + + // Total Distance + if (GETB(p_param->value[0], RSCP_MEAS_TOTAL_DST_MEAS_PRESENT)) + { + p_ind->value.rsc_meas.total_dist = co_read32p(&p_param->value[offset]); + } + + ke_msg_send(p_ind); + } break; + + case (GATTC_INDICATE): + { + // confirm that indication has been correctly received + struct gattc_event_cfm *p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + + // Check if we were waiting for the indication + if (p_rscpc_env->p_env[conidx]->p_operation != NULL) + { + if (((struct rscpc_cmd *)p_rscpc_env->p_env[conidx]->p_operation)->operation == + RSCPC_CTNL_PT_CFG_IND_OP_CODE) + { + struct rscpc_ctnl_pt_ind *p_ind; + + // Stop the procedure timeout timer + ke_timer_clear(RSCPC_TIMEOUT_TIMER_IND, dest_id); + + // RSC Measurement value has been received + p_ind = KE_MSG_ALLOC(RSCPC_CTNL_PT_IND, + prf_dst_task_get(&(p_rscpc_env->prf_env), conidx), + prf_src_task_get(&(p_rscpc_env->prf_env), conidx), + rscpc_ctnl_pt_ind); + + // Response code + p_ind->ctnl_pt_rsp.cp_opcode = p_param->value[0]; + // Requested operation code + p_ind->ctnl_pt_rsp.req_op_code = p_param->value[1]; + // Response value + p_ind->ctnl_pt_rsp.resp_value = p_param->value[2]; + + // Get the list of supported sensor locations if needed + if ((p_ind->ctnl_pt_rsp.req_op_code == RSCP_CTNL_PT_OP_REQ_SUPP_LOC) && + (p_ind->ctnl_pt_rsp.resp_value == RSCP_CTNL_PT_RESP_SUCCESS) && + (p_param->length > 3)) + { + // Get the number of supported locations that have been received + uint8_t nb_supp_loc = (p_param->length - 3); + // Counter + uint8_t counter; + // Location + uint8_t loc; + + for (counter = 0; counter < nb_supp_loc; counter++) + { + loc = p_param->value[counter + 3]; + + // Check if valid + if (loc < RSCP_LOC_MAX) + { + p_ind->ctnl_pt_rsp.supp_loc |= (1 << loc); + } + } + } + + // Send the message + ke_msg_send(p_ind); + + // Send the complete event message + rscpc_send_cmp_evt(p_rscpc_env, conidx, RSCPC_CTNL_PT_CFG_WR_OP_CODE, GAP_ERR_NO_ERROR); + } + // else drop the message + } + // else drop the message + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(rscpc) +{ + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {RSCPC_ENABLE_REQ, (ke_msg_func_t)rscpc_enable_req_handler}, + {RSCPC_READ_CMD, (ke_msg_func_t)rscpc_read_cmd_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {RSCPC_CFG_NTFIND_CMD, (ke_msg_func_t)rscpc_cfg_ntfind_cmd_handler}, + {RSCPC_CTNL_PT_CFG_CMD, (ke_msg_func_t)rscpc_ctnl_pt_cfg_cmd_handler}, + {RSCPC_TIMEOUT_TIMER_IND, (ke_msg_func_t)rscpc_timeout_timer_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void rscpc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct rscpc_env_tag *p_rscpc_env = PRF_ENV_GET(RSCPC, rscpc); + + p_task_desc->msg_handler_tab = rscpc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(rscpc_msg_handler_tab); + p_task_desc->state = p_rscpc_env->state; + p_task_desc->idx_max = RSCPC_IDX_MAX; +} + +#endif //(BLE_RSC_COLLECTOR) + +/// @} RSCPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/api/rscps_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/api/rscps_task.h new file mode 100644 index 0000000..447d64c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/api/rscps_task.h @@ -0,0 +1,211 @@ +/** + **************************************************************************************** + * + * @file rscps_task.h + * + * @brief Header file - Running Speed and Cadence Profile Sensor Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _RSCPS_TASK_H_ +#define _RSCPS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup RSCPSTASK Task + * @ingroup RSCPS + * @brief Running Speed and Cadence Profile Task. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rscp_common.h" +#include "rwip_task.h" // Task definitions + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Messages for Running Speed and Cadence Profile Sensor +/*@TRACE*/ +enum rscps_msg_id +{ + /// Enable the RSCP Sensor task for a connection + RSCPS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_RSCPS), + /// Enable the RSCP Sensor task for a connection + RSCPS_ENABLE_RSP, + + /// Send a RSC Measurement to the peer device (Notification) + RSCPS_NTF_RSC_MEAS_CMD, + + /// Indicate that the SC Control Point characteristic value has been written + RSCPS_SC_CTNL_PT_REQ_IND, + /// Application response after receiving a RSCPS_SC_CTNL_PT_REQ_IND message + RSCPS_SC_CTNL_PT_CFM, + + /// Indicate a new NTF/IND configuration to the application + RSCPS_CFG_NTFIND_IND, + + /// Send a complete event status to the application + RSCPS_CMP_EVT, +}; + +/// Operation Code used in the profile state machine +enum rscps_op_code +{ + /// Reserved Operation Code + RSCPS_RESERVED_OP_CODE = 0x00, + + /// Enable Profile Operation Code + RSCPS_ENABLE_OP_CODE, + /// Send RSC Measurement Operation Code + RSCPS_SEND_RSC_MEAS_OP_CODE, + + /** + * SC Control Point Operation + */ + + /// Set Cumulative Value Operation Code + RSCPS_CTNL_PT_CUMUL_VAL_OP_CODE, + /// Start Sensor Calibration Operation Code + RSCPS_CTNL_PT_START_CAL_OP_CODE, + /// Update Sensor Location Operation Code + RSCPS_CTNL_PT_UPD_LOC_OP_CODE, + /// Request Supported Sensor Locations Operation Code + RSCPS_CTNL_PT_SUPP_LOC_OP_CODE, + /// Error Indication Sent Operation Code + RSCPS_CTNL_ERR_IND_OP_CODE, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the initialization function +struct rscps_db_cfg +{ + /** + * RSC Feature Value - Not supposed to be modified during the lifetime of the device + * This value is used to decide if the SC Control Point Characteristic is part of the + * Running Speed and Cadence service. + */ + uint16_t rsc_feature; + /** + * Indicate if the Sensor Location characteristic is supported. Note that if the Multiple + * Sensor Location feature is set has supported in the rsc_feature parameter, the + * characteristic will be added (mandatory). + */ + uint8_t sensor_loc_supp; + /// Sensor location + uint8_t sensor_loc; +}; + +/// Parameters of the @ref RSCPS_ENABLE_REQ message +struct rscps_enable_req +{ + /// Connection handle + uint16_t conidx; + /// Stored RSC Measurement Char. Client Characteristic Configuration + uint16_t rsc_meas_ntf_cfg; + /// Stored SC Control Point Char. Client Characteristic Configuration + uint16_t sc_ctnl_pt_ntf_cfg; +}; + +/// Parameters of the @ref RSCPS_ENABLE_RSP message +struct rscps_enable_rsp +{ + /// Connection index + uint8_t conidx; + /// Status + uint8_t status; +}; + +/// Parameters of the @ref RSCPS_NTF_RSC_MEAS_CMD message +struct rscps_ntf_rsc_meas_cmd +{ + /// Flags + uint8_t flags; + /// Instantaneous Cadence + uint8_t inst_cad; + /// Instantaneous Speed + uint16_t inst_speed; + /// Instantaneous Stride Length + uint16_t inst_stride_len; + /// Total Distance + uint32_t total_dist; +}; + +/// Parameters of the @ref RSCPS_SC_CTNL_PT_REQ_IND message +struct rscps_sc_ctnl_pt_req_ind +{ + /// Connection index + uint8_t conidx; + /// Operation Code + uint8_t op_code; + /// Value + union rscps_sc_ctnl_pt_req_ind_value + { + /// Cumulative value + uint32_t cumul_value; + /// Sensor Location + uint8_t sensor_loc; + } value; +}; + +/// Parameters of the @ref RSCPS_SC_CTNL_PT_CFM message +struct rscps_sc_ctnl_pt_cfm +{ + /// Connection handle + uint8_t conidx; + /// Operation Code + uint8_t op_code; + /// Status + uint8_t status; + /// Value + union rscps_sc_ctnl_pt_cfm_value + { + /// Sensor Location + uint8_t sensor_loc; + /// Supported sensor locations + uint16_t supp_sensor_loc; + } value; +}; + +/// Parameters of the @ref RSCPS_CFG_NTFIND_IND message +struct rscps_cfg_ntfind_ind +{ + /// Connection index + uint8_t conidx; + /// Characteristic Code (RSC Measurement or SC Control Point) + uint8_t char_code; + /// Char. Client Characteristic Configuration + uint16_t ntf_cfg; +}; + +/// Parameters of the @ref RSCPS_CMP_EVT message +struct rscps_cmp_evt +{ + /// Connection index + uint8_t conidx; + /// Operation Code + uint8_t operation; + /// Operation Status + uint8_t status; +}; + +/// @} RSCPSTASK + +#endif //(_RSCPS_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/sourcelist.txt new file mode 100644 index 0000000..7e860fd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + rscps.c + rscps_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/src/rscps.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/src/rscps.c new file mode 100644 index 0000000..2f5c81b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/src/rscps.c @@ -0,0 +1,369 @@ +/** + **************************************************************************************** + * + * @file rscps.c + * + * @brief Running Speed and Cadence Profile Sensor implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup RSCPS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_RSC_SENSOR) +#include "rscp_common.h" + +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "rscps.h" +#include "rscps_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Full RSCPS Database Description - Used to add attributes into the database +static const struct attm_desc rscps_att_db[RSCS_IDX_NB] = +{ + // Running Speed and Cadence Service Declaration + [RSCS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // RSC Measurement Characteristic Declaration + [RSCS_IDX_RSC_MEAS_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // RSC Measurement Characteristic Value + [RSCS_IDX_RSC_MEAS_VAL] = {ATT_CHAR_RSC_MEAS, PERM(NTF, ENABLE), PERM(RI, ENABLE), RSCP_RSC_MEAS_MAX_LEN}, + // RSC Measurement Characteristic - Client Characteristic Configuration Descriptor + [RSCS_IDX_RSC_MEAS_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // RSC Feature Characteristic Declaration + [RSCS_IDX_RSC_FEAT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // RSC Feature Characteristic Value + [RSCS_IDX_RSC_FEAT_VAL] = {ATT_CHAR_RSC_FEAT, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint16_t)}, + + // Sensor Location Characteristic Declaration + [RSCS_IDX_SENSOR_LOC_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Sensor Location Characteristic Value + [RSCS_IDX_SENSOR_LOC_VAL] = {ATT_CHAR_SENSOR_LOC, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, + + // SC Control Point Characteristic Declaration + [RSCS_IDX_SC_CTNL_PT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // SC Control Point Characteristic Value - The response has the maximal length + [RSCS_IDX_SC_CTNL_PT_VAL] = {ATT_CHAR_SC_CNTL_PT, PERM(IND, ENABLE) | PERM(WRITE_REQ, ENABLE), + PERM(RI, ENABLE), RSCP_SC_CNTL_PT_RSP_MAX_LEN}, + // SC Control Point Characteristic - Client Characteristic Configuration Descriptor + [RSCS_IDX_SC_CTNL_PT_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the RSCPS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t rscps_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, uint8_t sec_lvl, + struct rscps_db_cfg *p_param) +{ + //------------------ create the attribute database for the profile ------------------- + // Service content flag + uint32_t cfg_flag= RSCPS_MANDATORY_MASK; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + /* + * Check if the Sensor Location characteristic shall be added. + * Mandatory if the Multiple Sensor Location feature is supported, otherwise optional. + */ + if ((p_param->sensor_loc_supp == RSCPS_SENSOR_LOC_SUPP) || + (GETB(p_param->rsc_feature, RSCP_FEAT_MULT_SENSOR_LOC_SUPP))) + { + cfg_flag |= RSCPS_SENSOR_LOC_MASK; + } + + /* + * Check if the SC Control Point characteristic shall be added + * Mandatory if at least one SC Control Point procedure is supported, otherwise excluded. + */ + if (GETB(p_param->rsc_feature, RSCP_FEAT_CALIB_PROC_SUPP) || + GETB(p_param->rsc_feature, RSCP_FEAT_MULT_SENSOR_LOC_SUPP) || + GETB(p_param->rsc_feature, RSCP_FEAT_TOTAL_DST_MEAS_SUPP)) + { + cfg_flag |= RSCPS_SC_CTNL_PT_MASK; + } + + // Add service in the database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_RUNNING_SPEED_CADENCE, (uint8_t *)&cfg_flag, + RSCS_IDX_NB, NULL, p_env->task, &rscps_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, DISABLE)); + + // Check if an error has occured + if (status == ATT_ERR_NO_ERROR) + { + // Allocate RSCPS required environment variable + struct rscps_env_tag *p_rscps_env = + (struct rscps_env_tag *) ke_malloc(sizeof(struct rscps_env_tag), KE_MEM_ATT_DB); + + // Initialize RSCPS environment + + p_env->env = (prf_env_t *) p_rscps_env; + p_rscps_env->shdl = *p_start_hdl; + p_rscps_env->prf_cfg = cfg_flag; + p_rscps_env->features = p_param->rsc_feature; + p_rscps_env->operation = RSCPS_RESERVED_OP_CODE; + + if (RSCPS_IS_FEATURE_SUPPORTED(p_rscps_env->prf_cfg, RSCPS_SENSOR_LOC_MASK)) + { + p_rscps_env->sensor_loc = (p_param->sensor_loc >= RSCP_LOC_MAX) ? + RSCP_LOC_OTHER : p_param->sensor_loc; + } + + p_rscps_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Mono Instantiated task + p_rscps_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_RSCPS; + rscps_task_init(&(p_env->desc)); + + p_rscps_env->p_ntf = NULL; + memset(p_rscps_env->prfl_ntf_ind_cfg, 0, BLE_CONNECTION_MAX); + + // If we are here, database has been fulfilled with success, go to idle state + ke_state_set(p_env->task, RSCPS_IDLE); + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the RSCPS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void rscps_destroy(struct prf_task_env *p_env) +{ + struct rscps_env_tag *p_rscps_env = (struct rscps_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + if (p_rscps_env->p_ntf != NULL) + { + ke_free(p_rscps_env->p_ntf); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_rscps_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void rscps_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct rscps_env_tag *p_rscps_env = (struct rscps_env_tag *) p_env->env; + + p_rscps_env->prfl_ntf_ind_cfg[conidx] = 0; + +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void rscps_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct rscps_env_tag *p_rscps_env = (struct rscps_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + p_rscps_env->prfl_ntf_ind_cfg[conidx] = 0; +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// RSCPS Task interface required by profile manager +const struct prf_task_cbs rscps_itf = +{ + (prf_init_fnct) rscps_init, + rscps_destroy, + rscps_create, + rscps_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *rscps_prf_itf_get(void) +{ + return &rscps_itf; +} + +void rscps_send_cmp_evt(uint8_t conidx, uint8_t src_id, uint8_t dest_id, uint8_t operation, uint8_t status) +{ + // Get the address of the environment + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + struct rscps_cmp_evt *p_evt; + + // Go back to the Connected state if the state is busy + if (ke_state_get(src_id) == RSCPS_BUSY) + { + ke_state_set(src_id, RSCPS_IDLE); + } + + // Set the operation code + p_rscps_env->operation = RSCPS_RESERVED_OP_CODE; + + // Send the message + p_evt = KE_MSG_ALLOC(RSCPS_CMP_EVT, dest_id, src_id, rscps_cmp_evt); + + p_evt->conidx = conidx; + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + + +void rscps_exe_operation(uint8_t conidx) +{ + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + + ASSERT_ERR(p_rscps_env->p_ntf != NULL); + + bool finished = true; + + while (p_rscps_env->p_ntf->cursor < BLE_CONNECTION_MAX) + { + // Check if notifications are enabled + if (GETB(p_rscps_env->prfl_ntf_ind_cfg[p_rscps_env->p_ntf->cursor], RSCP_PRF_CFG_FLAG_RSC_MEAS_NTF)) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_meas_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, p_rscps_env->p_ntf->cursor), + prf_src_task_get(&(p_rscps_env->prf_env), 0), + gattc_send_evt_cmd, p_rscps_env->p_ntf->length); + + // Fill in the parameter structure + p_meas_val->operation = GATTC_NOTIFY; + p_meas_val->handle = RSCPS_HANDLE(RSCS_IDX_RSC_MEAS_VAL); + p_meas_val->length = p_rscps_env->p_ntf->length; + memcpy(p_meas_val->value, p_rscps_env->p_ntf->value, p_rscps_env->p_ntf->length); + + // Send the event + ke_msg_send(p_meas_val); + + finished = false; + p_rscps_env->p_ntf->cursor++; + break; + } + + p_rscps_env->p_ntf->cursor++; + } + + // check if operation is finished + if (finished) + { + // Inform the application that a procedure has been completed + rscps_send_cmp_evt(conidx, + prf_src_task_get(&p_rscps_env->prf_env, conidx), + prf_dst_task_get(&p_rscps_env->prf_env, conidx), + p_rscps_env->operation, GAP_ERR_NO_ERROR); + + // free operation + ke_free(p_rscps_env->p_ntf); + p_rscps_env->p_ntf = NULL; + p_rscps_env->operation = RSCPS_RESERVED_OP_CODE; + + ke_state_set(prf_src_task_get(&(p_rscps_env->prf_env), conidx), RSCPS_IDLE); + } +} + +void rscps_send_rsp_ind(uint8_t conidx, uint8_t req_op_code, uint8_t status) +{ + // Get the address of the environment + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ctl_pt_rsp = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + prf_src_task_get(&p_rscps_env->prf_env, conidx), + gattc_send_evt_cmd, RSCP_SC_CNTL_PT_RSP_MIN_LEN); + + // Fill in the parameter structure + p_ctl_pt_rsp->operation = GATTC_INDICATE; + p_ctl_pt_rsp->handle = RSCPS_HANDLE(RSCS_IDX_SC_CTNL_PT_VAL); + // Pack Control Point confirmation + p_ctl_pt_rsp->length = RSCP_SC_CNTL_PT_RSP_MIN_LEN; + // Response Code + p_ctl_pt_rsp->value[0] = RSCP_CTNL_PT_RSP_CODE; + // Request Operation Code + p_ctl_pt_rsp->value[1] = req_op_code; + // Response value + p_ctl_pt_rsp->value[2] = status; + + // Send the event + ke_msg_send(p_ctl_pt_rsp); +} + +#endif //(BLE_RSC_SENSOR) + +/// @} RSCPS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/src/rscps.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/src/rscps.h new file mode 100644 index 0000000..db1b10a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/src/rscps.h @@ -0,0 +1,267 @@ +/** + **************************************************************************************** + * + * @file rscps + * + * @brief Header file - Running Speed and Cadence Profile Sensor. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _RSCPS_H_ +#define _RSCPS_H_ + +/** + **************************************************************************************** + * @addtogroup RSCPS Running Speed and Cadence Profile Sensor + * @ingroup RSCP + * @brief Running Speed and Cadence Profile Sensor + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_RSC_SENSOR) +#include "rscp_common.h" + +#include "prf_types.h" +#include "prf.h" +#include "rscps_task.h" +#include "attm.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Running Speed and Cadence Profile Sensor role task instances +#define RSCPS_IDX_MAX (1) + +/******************************************** + ******* RSCS Configuration Flag Masks ****** + ********************************************/ + +/// Mandatory Attributes (RSC Measurement + RSC Feature) +#define RSCPS_MANDATORY_MASK (0x003F) +/// Sensor Location Attributes +#define RSCPS_SENSOR_LOC_MASK (0x00C0) +/// SC Control Point Attributes +#define RSCPS_SC_CTNL_PT_MASK (0x0700) + +/* + * MACROS + **************************************************************************************** + */ + +#define RSCPS_IS_FEATURE_SUPPORTED(features, flag) ((features & flag) == flag) + +#define RSCPS_HANDLE(idx) \ + (p_rscps_env->shdl + (idx) - \ + ((!(RSCPS_IS_FEATURE_SUPPORTED(p_rscps_env->prf_cfg, RSCPS_SENSOR_LOC_MASK)) && \ + ((idx) > RSCS_IDX_SENSOR_LOC_CHAR))? (1) : (0))) + +// Get database attribute index + #define RSCPS_IDX(hdl) \ + ((hdl - p_rscps_env->shdl) + \ + ((!(RSCPS_IS_FEATURE_SUPPORTED(p_rscps_env->prf_cfg, RSCPS_SENSOR_LOC_MASK)) && \ + ((hdl - p_rscps_env->shdl) > RSCS_IDX_SENSOR_LOC_CHAR)) ? (1) : (0))) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the RSCPS task +enum rscps_state +{ + /// Idle state + RSCPS_IDLE, + /// Busy state + RSCPS_BUSY, + + /// Number of defined states. + RSCPS_STATE_MAX +}; + +/// Running Speed and Cadence Service - Attribute List +enum rscps_rscs_att_list +{ + /// Running Speed and Cadence Service + RSCS_IDX_SVC, + /// RSC Measurement + RSCS_IDX_RSC_MEAS_CHAR, + RSCS_IDX_RSC_MEAS_VAL, + RSCS_IDX_RSC_MEAS_NTF_CFG, + /// RSC Feature + RSCS_IDX_RSC_FEAT_CHAR, + RSCS_IDX_RSC_FEAT_VAL, + /// Sensor Location + RSCS_IDX_SENSOR_LOC_CHAR, + RSCS_IDX_SENSOR_LOC_VAL, + /// SC Control Point + RSCS_IDX_SC_CTNL_PT_CHAR, + RSCS_IDX_SC_CTNL_PT_VAL, + RSCS_IDX_SC_CTNL_PT_NTF_CFG, + + /// Number of attributes + RSCS_IDX_NB, +}; + +/// Profile Configuration Additional Flags bit field +enum rscps_prf_cfg_flag_bf +{ + /// RSC Measurement - Client Char. Cfg + RSCP_PRF_CFG_FLAG_RSC_MEAS_NTF_POS = 5, + RSCP_PRF_CFG_FLAG_RSC_MEAS_NTF_BIT = CO_BIT(RSCP_PRF_CFG_FLAG_RSC_MEAS_NTF_POS), + + /// SC Control Point - Client Char. Cfg + RSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND_POS = 6, + RSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND_BIT = CO_BIT(RSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND_POS), + + /// Bonded data configured + RSCP_PRF_CFG_PERFORMED_OK_POS = 7, + RSCP_PRF_CFG_PERFORMED_OK_BIT = CO_BIT(RSCP_PRF_CFG_PERFORMED_OK_POS), +}; + +/// Sensor Location Supported Flag +enum rscps_sensor_loc_supp +{ + /// Sensor Location Char. is not supported + RSCPS_SENSOR_LOC_NOT_SUPP, + /// Sensor Location Char. is supported + RSCPS_SENSOR_LOC_SUPP, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// ongoing notification information +struct rscps_ntf +{ + /// Cursor on connection + uint8_t cursor; + /// Packed notification/indication data size + uint8_t length; + /// Packed notification/indication data + uint8_t value[RSCP_RSC_MEAS_MAX_LEN]; +}; + +/// Running Power Profile Sensor environment variable per connection +struct rscps_cnx_env +{ + /// Profile Notify/Indication Flags + uint8_t prfl_ntf_ind_cfg; +}; + +/// Running Speed and Cadence Profile Sensor environment variable +struct rscps_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Notification data + struct rscps_ntf *p_ntf; + + /// Cycling Speed and Cadence Service Start Handle + uint16_t shdl; + + /// Features configuration + uint16_t features; + /// profile configuration + uint16_t prf_cfg; + + /// Operation + uint8_t operation; + /// Sensor location + uint8_t sensor_loc; + + /// State of different task instances + ke_state_t state[RSCPS_IDX_MAX]; + /// Profile Notify/Indication Flags + uint8_t prfl_ntf_ind_cfg[BLE_CONNECTION_MAX]; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve RSCP service profile interface + * + * @return RSCP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* rscps_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send a RSCPS_CMP_EVT message to the application. + * + * @param[in] conidx Connection index + * @param[in] src_id Source ID + * @param[in] dest_id Destination ID + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void rscps_send_cmp_evt(uint8_t conidx, uint8_t src_id, uint8_t dest_id, uint8_t operation, uint8_t status); + +/** + **************************************************************************************** + * @brief This function fully manage event to trigg to peer(s) device(s) according + * to on-going operation requested by application + * @param[in] conidx Connection index + **************************************************************************************** + */ +void rscps_exe_operation(uint8_t conidx); + +/** + **************************************************************************************** + * @brief This function sends control point indication error + * + * @param conidx Connection index + * @param req_op_code Request operation code + * @param status Response status code + **************************************************************************************** + */ +void rscps_send_rsp_ind(uint8_t conidx, uint8_t req_op_code, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void rscps_task_init(struct ke_task_desc *p_task_desc); + + +#endif //(BLE_RSC_SENSOR) + +/// @} RSCPS + +#endif //(_RSCPS_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/src/rscps_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/src/rscps_task.c new file mode 100644 index 0000000..72a0e1c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/rscp/rscps/src/rscps_task.c @@ -0,0 +1,859 @@ +/** + **************************************************************************************** + * + * @file rscps_task.c + * + * @brief Running Speed and Cadence Profile Sensor Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup RSCPSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_RSC_SENSOR) +#include "rscp_common.h" + +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "rscps.h" +#include "rscps_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref RSCPS_ENABLE_REQ message. + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int rscps_enable_req_handler(ke_msg_id_t const msgid, + struct rscps_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct rscps_enable_rsp *p_cmp_evt; + + if (ke_state_get(dest_id) == RSCPS_IDLE) + { + status = GAP_ERR_NO_ERROR; + + if (!GETB(p_rscps_env->prfl_ntf_ind_cfg[p_param->conidx], RSCP_PRF_CFG_PERFORMED_OK)) + { + // Check the provided value + if (p_param->rsc_meas_ntf_cfg == PRF_CLI_START_NTF) + { + // Store the status + SETB(p_param->conidx, RSCP_PRF_CFG_FLAG_RSC_MEAS_NTF, 1); + } + + if (RSCPS_IS_FEATURE_SUPPORTED(p_rscps_env->prf_cfg, RSCPS_SC_CTNL_PT_MASK)) + { + // Check the provided value + if (p_param->sc_ctnl_pt_ntf_cfg == PRF_CLI_START_IND) + { + // Store the status + SETB(p_param->conidx, RSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND, 1); + } + } + // Enable Bonded Data + SETB(p_param->conidx, RSCP_PRF_CFG_PERFORMED_OK, 1); + } + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(RSCPS_ENABLE_RSP, src_id, dest_id, rscps_enable_rsp); + p_cmp_evt->status = status; + p_cmp_evt->conidx = p_param->conidx; + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == RSCPS_IDLE) + { + // Get the address of the environment + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t att_idx = RSCPS_IDX(p_param->handle); + + // Send data to peer device + struct gattc_read_cfm *p_cfm = NULL; + + uint8_t status = ATT_ERR_NO_ERROR; + + switch (att_idx) + { + case RSCS_IDX_RSC_MEAS_NTF_CFG: + { + // Fill data + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + co_write16p(p_cfm->value, GETB(p_rscps_env->prfl_ntf_ind_cfg[conidx], RSCP_PRF_CFG_FLAG_RSC_MEAS_NTF) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND); + } break; + + case RSCS_IDX_RSC_FEAT_VAL: + { + // Fill data + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + co_write16p(p_cfm->value, p_rscps_env->features); + } break; + + case RSCS_IDX_SENSOR_LOC_VAL: + { + // Fill data + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint8_t)); + p_cfm->length = sizeof(uint8_t); + p_cfm->value[0] = p_rscps_env->sensor_loc; + } break; + + case RSCS_IDX_SC_CTNL_PT_NTF_CFG: + { + // Fill data + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + p_cfm->length = sizeof(uint16_t); + co_write16p(p_cfm->value, GETB(p_rscps_env->prfl_ntf_ind_cfg[conidx], RSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND) + ? PRF_CLI_START_IND : PRF_CLI_STOP_NTFIND); + } break; + + default: + { + p_cfm = KE_MSG_ALLOC(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm); + p_cfm->length = 0; + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } break; + } + + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == RSCPS_IDLE) + { + // Get the address of the environment + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + uint8_t att_idx = RSCPS_IDX(p_param->handle); + struct gattc_att_info_cfm *p_cfm; + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + // check if it's a client configuration char + if ((att_idx == RSCS_IDX_RSC_MEAS_NTF_CFG) + || (att_idx == RSCS_IDX_SC_CTNL_PT_NTF_CFG)) + { + // CCC attribute length = 2 + p_cfm->length = 2; + p_cfm->status = GAP_ERR_NO_ERROR; + } + else if (att_idx == RSCS_IDX_SC_CTNL_PT_VAL) + { + // force length to zero to reject any write starting from something != 0 + p_cfm->length = 0; + p_cfm->status = GAP_ERR_NO_ERROR; + } + // not expected request + else + { + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } + + ke_msg_send(p_cfm); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref RSCPS_NTF_RSC_MEAS_CMD message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int rscps_ntf_rsc_meas_cmd_handler(ke_msg_id_t const msgid, + struct rscps_ntf_rsc_meas_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + + // State shall be Connected or Busy + if (ke_state_get(dest_id) == RSCPS_IDLE) + { + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + // allocate and prepare data to notify + p_rscps_env->p_ntf = (struct rscps_ntf *) ke_malloc(sizeof(struct rscps_ntf), KE_MEM_KE_MSG); + + // Fill in the p_parameter structure + p_rscps_env->p_ntf->length = RSCP_RSC_MEAS_MIN_LEN; + + // Check the provided flags value + if (!GETB(p_rscps_env->prf_cfg, RSCP_FEAT_INST_STRIDE_LEN_SUPP) && + GETB(p_param->flags, RSCP_MEAS_INST_STRIDE_LEN_PRESENT)) + { + // Force Measurement Instantaneous Stride Length Present to No (Not supported) + SETB(p_param->flags, RSCP_MEAS_INST_STRIDE_LEN_PRESENT, 0); + } + + if (!GETB(p_rscps_env->prf_cfg, RSCP_FEAT_TOTAL_DST_MEAS_SUPP) && + GETB(p_param->flags, RSCP_MEAS_TOTAL_DST_MEAS_PRESENT)) + { + // Force Total Distance Measurement Present to No (Not supported) + SETB(p_param->flags, RSCP_MEAS_TOTAL_DST_MEAS_PRESENT, 0); + } + + if (!GETB(p_rscps_env->prf_cfg, RSCP_FEAT_WALK_RUN_STATUS_SUPP) && + GETB(p_param->flags, RSCP_MEAS_WALK_RUN_STATUS)) + { + // Force Walking or Running Status Measurement Present to No (Not supported) + SETB(p_param->flags, RSCP_MEAS_WALK_RUN_STATUS, 0); + } + + + // Force the unused bits of the flag value to 0 + p_rscps_env->p_ntf->value[0] = p_param->flags & RSCP_MEAS_ALL_PRESENT; + + // Instantaneous Speed + co_write16p(&p_rscps_env->p_ntf->value[1], p_param->inst_speed); + // Instantaneous Cadence + p_rscps_env->p_ntf->value[3] = p_param->inst_cad; + + // Instantaneous Stride Length + if (GETB(p_param->flags, RSCP_MEAS_INST_STRIDE_LEN_PRESENT)) + { + co_write16p(&p_rscps_env->p_ntf->value[p_rscps_env->p_ntf->length], p_param->inst_stride_len); + p_rscps_env->p_ntf->length += 2; + } + + // Total Distance + if (GETB(p_param->flags, RSCP_MEAS_TOTAL_DST_MEAS_PRESENT)) + { + co_write32p(&p_rscps_env->p_ntf->value[p_rscps_env->p_ntf->length], p_param->total_dist); + p_rscps_env->p_ntf->length += 4; + } + + // Configure the environment + p_rscps_env->operation = RSCPS_SEND_RSC_MEAS_OP_CODE; + p_rscps_env->p_ntf->cursor = 0; + + // Go to busy state + ke_state_set(dest_id, RSCPS_BUSY); + + // start operation execution + rscps_exe_operation(conidx); + } + else + { + // Save it for later + msg_status = KE_MSG_SAVED; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref RSCPS_SC_CTNL_PT_CFM message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int rscps_sc_ctnl_pt_cfm_handler(ke_msg_id_t const msgid, + struct rscps_sc_ctnl_pt_cfm *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + uint8_t conidx = KE_IDX_GET(src_id); + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (ke_state_get(dest_id) == RSCPS_BUSY) + { + do + { + // check if op code valid + if ((p_param->op_code < RSCPS_CTNL_PT_CUMUL_VAL_OP_CODE) + || (p_param->op_code > RSCPS_CTNL_ERR_IND_OP_CODE)) + { + //Wrong op code + status = PRF_ERR_INVALID_PARAM; + break; + } + + // Check the current operation + if ((p_rscps_env->operation < RSCPS_CTNL_PT_CUMUL_VAL_OP_CODE) || + (p_param->op_code != p_rscps_env->operation)) + { + // The confirmation has been sent without request indication, ignore + status = PRF_ERR_REQ_DISALLOWED; + break; + } + + // The SC Control Point Characteristic must be supported if we are here + if (RSCPS_IS_FEATURE_SUPPORTED(p_rscps_env->prf_cfg, RSCPS_SC_CTNL_PT_MASK)) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ctl_pt_rsp = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, p_param->conidx), dest_id, + gattc_send_evt_cmd, RSCP_SC_CNTL_PT_RSP_MAX_LEN); + + // Fill in the p_parameter structure + p_ctl_pt_rsp->operation = GATTC_INDICATE; + p_ctl_pt_rsp->handle = RSCPS_HANDLE(RSCS_IDX_SC_CTNL_PT_VAL); + // Pack Control Point confirmation + p_ctl_pt_rsp->length = RSCP_SC_CNTL_PT_RSP_MIN_LEN; + + // Set the operation code (Response Code) + p_ctl_pt_rsp->value[0] = RSCP_CTNL_PT_RSP_CODE; + // Set the response value + p_ctl_pt_rsp->value[2] = (p_param->status > RSCP_CTNL_PT_RESP_FAILED) ? + RSCP_CTNL_PT_RESP_FAILED : p_param->status; + + switch (p_rscps_env->operation) + { + // Set cumulative value + case (RSCPS_CTNL_PT_CUMUL_VAL_OP_CODE): + { + // Set the request operation code + p_ctl_pt_rsp->value[1] = RSCP_CTNL_PT_OP_SET_CUMUL_VAL; + status = GAP_ERR_NO_ERROR; + } break; + + // Start Sensor Calibration + case (RSCPS_CTNL_PT_START_CAL_OP_CODE): + { + // Set the request operation code + p_ctl_pt_rsp->value[1] = RSCP_CTNL_PT_OP_START_CALIB; + status = GAP_ERR_NO_ERROR; + } break; + + // Update Sensor Location + case (RSCPS_CTNL_PT_UPD_LOC_OP_CODE): + { + // Set the request operation code + p_ctl_pt_rsp->value[1] = RSCP_CTNL_PT_OP_UPD_LOC; + + if (p_param->status == RSCP_CTNL_PT_RESP_SUCCESS) + { + // The Sensor Location Characteristic is supported if we are here + if (RSCPS_IS_FEATURE_SUPPORTED(p_rscps_env->prf_cfg, RSCPS_SENSOR_LOC_MASK)) + { + // If operation is successful, update the value in the database + p_rscps_env->sensor_loc = p_param->value.sensor_loc; + status = GAP_ERR_NO_ERROR; + } + } + } break; + + case (RSCPS_CTNL_PT_SUPP_LOC_OP_CODE): + { + // Set the request operation code + p_ctl_pt_rsp->value[1] = RSCP_CTNL_PT_OP_REQ_SUPP_LOC; + + if (p_param->status == RSCP_CTNL_PT_RESP_SUCCESS) + { + // Counter + uint8_t counter; + + // Set the list of supported location + for (counter = 0; counter < RSCP_LOC_MAX; counter++) + { + if (((p_param->value.supp_sensor_loc >> counter) & 0x0001) == 0x0001) + { + p_ctl_pt_rsp->value[p_ctl_pt_rsp->length] = counter; + p_ctl_pt_rsp->length++; + } + } + status = GAP_ERR_NO_ERROR; + } + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + // Send the event + ke_msg_send(p_ctl_pt_rsp); + } + } while (0); + + if (status != GAP_ERR_NO_ERROR) + { + // Inform the application that a procedure has been completed + rscps_send_cmp_evt(conidx, + prf_src_task_get(&p_rscps_env->prf_env, conidx), + prf_dst_task_get(&p_rscps_env->prf_env, conidx), + p_rscps_env->operation, p_param->status); + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + uint8_t conidx = KE_IDX_GET(src_id); + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Check if a connection exists + if (p_rscps_env != NULL) + { + // RSC Measurement Characteristic, Client Characteristic Configuration Descriptor + if (p_param->handle == (RSCPS_HANDLE(RSCS_IDX_RSC_MEAS_NTF_CFG))) + { + uint16_t ntf_cfg; + // Status + uint8_t status = PRF_ERR_INVALID_PARAM; + struct gattc_write_cfm *p_cfm; + + // Get the value + co_write16p(&ntf_cfg, p_param->value[0]); + + // Check if the value is correct + if (ntf_cfg <= PRF_CLI_START_NTF) + { + struct rscps_cfg_ntfind_ind *p_ind; + + status = GAP_ERR_NO_ERROR; + + // Save the new configuration in the environment + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + SETB(p_rscps_env->prfl_ntf_ind_cfg[conidx], RSCP_PRF_CFG_FLAG_RSC_MEAS_NTF, 0); + } + else // ntf_cfg == PRF_CLI_START_NTF + { + SETB(p_rscps_env->prfl_ntf_ind_cfg[conidx], RSCP_PRF_CFG_FLAG_RSC_MEAS_NTF, 1); + } + + // Inform the HL about the new configuration + p_ind = KE_MSG_ALLOC(RSCPS_CFG_NTFIND_IND, + prf_dst_task_get(&p_rscps_env->prf_env, conidx), + prf_src_task_get(&p_rscps_env->prf_env, conidx), + rscps_cfg_ntfind_ind); + + p_ind->conidx = conidx; + p_ind->char_code = RSCP_RSCS_RSC_MEAS_CHAR; + p_ind->ntf_cfg = ntf_cfg; + + ke_msg_send(p_ind); + + // Enable Bonded Data + SETB(p_rscps_env->prfl_ntf_ind_cfg[conidx], RSCP_PRF_CFG_PERFORMED_OK, 1); + } + // else status is RSCP_ERROR_CCC_INVALID_PARAM + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + else // Should be the SC Control Point Characteristic + { + if (RSCPS_IS_FEATURE_SUPPORTED(p_rscps_env->prf_cfg, RSCPS_SC_CTNL_PT_MASK)) + { + // SC Control Point, Client Characteristic Configuration Descriptor + if (p_param->handle == (RSCPS_HANDLE(RSCS_IDX_SC_CTNL_PT_NTF_CFG))) + { + uint16_t ntf_cfg; + // Status + uint8_t status = PRF_ERR_INVALID_PARAM; + struct gattc_write_cfm *p_cfm; + + // Get the value + co_write16p(&ntf_cfg, p_param->value[0]); + + // Check if the value is correct + if ((ntf_cfg == PRF_CLI_STOP_NTFIND) || (ntf_cfg == PRF_CLI_START_IND)) + { + struct rscps_cfg_ntfind_ind *p_ind; + + status = GAP_ERR_NO_ERROR; + + // Save the new configuration in the environment + if (ntf_cfg == PRF_CLI_STOP_NTFIND) + { + SETB(p_rscps_env->prfl_ntf_ind_cfg[conidx], RSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND, 0); + } + else // ntf_cfg == PRF_CLI_START_IND + { + SETB(p_rscps_env->prfl_ntf_ind_cfg[conidx], RSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND, 1); + } + + // Inform the HL about the new configuration + p_ind = KE_MSG_ALLOC(RSCPS_CFG_NTFIND_IND, + prf_dst_task_get(&p_rscps_env->prf_env, conidx), + prf_src_task_get(&p_rscps_env->prf_env, conidx), + rscps_cfg_ntfind_ind); + + p_ind->conidx = conidx; + p_ind->char_code = RSCP_RSCS_SC_CTNL_PT_CHAR; + p_ind->ntf_cfg = ntf_cfg; + + ke_msg_send(p_ind); + + // Enable Bonded Data + SETB(p_rscps_env->prfl_ntf_ind_cfg[conidx], RSCP_PRF_CFG_PERFORMED_OK, 1); + } + // else status is RSCP_ERROR_CCC_INVALID_PARAM + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + // SC Control Point Characteristic + else if (p_param->handle == (RSCPS_HANDLE(RSCS_IDX_SC_CTNL_PT_VAL))) + { + // Write Response Status + uint8_t wr_status = ATT_ERR_NO_ERROR; + // Indication Status + uint8_t ind_status = RSCP_CTNL_PT_RESP_NOT_SUPP; + struct gattc_write_cfm *p_cfm; + + do + { + struct rscps_sc_ctnl_pt_req_ind *p_req_ind; + + // Check if sending of indications has been enabled + if (!GETB(p_rscps_env->prfl_ntf_ind_cfg[conidx], RSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND)) + { + // CCC improperly configured + wr_status = RSCP_ERROR_CCC_INVALID_PARAM; + ind_status = RSCP_CTNL_PT_RESP_FAILED; + break; + } + + if ((p_rscps_env->operation >= RSCPS_CTNL_PT_CUMUL_VAL_OP_CODE) && + (p_rscps_env->operation <= RSCPS_CTNL_ERR_IND_OP_CODE)) + { + // A procedure is already in progress + wr_status = RSCP_ERROR_PROC_IN_PROGRESS; + ind_status = RSCP_CTNL_PT_RESP_FAILED; + break; + } + + if (p_rscps_env->operation == RSCPS_SEND_RSC_MEAS_OP_CODE) + { + // Keep the message until the end of the current procedure + msg_status = KE_MSG_SAVED; + break; + } + + // Allocate a request indication message for the application + p_req_ind = KE_MSG_ALLOC(RSCPS_SC_CTNL_PT_REQ_IND, + prf_dst_task_get(&p_rscps_env->prf_env, conidx), + prf_src_task_get(&p_rscps_env->prf_env, conidx), + rscps_sc_ctnl_pt_req_ind); + + // Operation Code + p_req_ind->op_code = p_param->value[0]; + // Connection index + p_req_ind->conidx = conidx; + + // Operation Code + switch (p_param->value[0]) + { + // Set Cumulative value + case (RSCP_CTNL_PT_OP_SET_CUMUL_VAL): + { + // Check if the Total Distance Measurement feature is supported + if (GETB(p_rscps_env->features, RSCP_FEAT_TOTAL_DST_MEAS_SUPP)) + { + // The request can be handled + ind_status = RSCP_CTNL_PT_RESP_SUCCESS; + p_rscps_env->operation = RSCPS_CTNL_PT_CUMUL_VAL_OP_CODE; + + // Cumulative value + p_req_ind->value.cumul_value = co_read32p(&p_param->value[1]); + } + } break; + + // Start Sensor calibration + case (RSCP_CTNL_PT_OP_START_CALIB): + { + // Check if the Calibration Procedure feature is supported + if (GETB(p_rscps_env->features, RSCP_FEAT_CALIB_PROC_SUPP)) + { + // The request can be handled + ind_status = RSCP_CTNL_PT_RESP_SUCCESS; + + p_rscps_env->operation = RSCPS_CTNL_PT_START_CAL_OP_CODE; + } + } break; + + // Update sensor location + case (RSCP_CTNL_PT_OP_UPD_LOC): + { + // Check if the Multiple Sensor Location feature is supported + if (GETB(p_rscps_env->features, RSCP_FEAT_MULT_SENSOR_LOC_SUPP)) + { + // Check the sensor location value + if (p_param->value[1] < RSCP_LOC_MAX) + { + // The request can be handled + ind_status = RSCP_CTNL_PT_RESP_SUCCESS; + + p_rscps_env->operation = RSCPS_CTNL_PT_UPD_LOC_OP_CODE; + + // Sensor Location + p_req_ind->value.sensor_loc = p_param->value[1]; + } + else + { + // Provided p_parameter in not within the defined range + ind_status = RSCP_CTNL_PT_RESP_INV_PARAM; + } + } + } break; + + // Request supported sensor locations + case (RSCP_CTNL_PT_OP_REQ_SUPP_LOC): + { + // Check if the Multiple Sensor Location feature is supported + if (GETB(p_rscps_env->features, RSCP_FEAT_MULT_SENSOR_LOC_SUPP)) + { + // The request can be handled + ind_status = RSCP_CTNL_PT_RESP_SUCCESS; + + p_rscps_env->operation = RSCPS_CTNL_PT_SUPP_LOC_OP_CODE; + } + } break; + + default: + { + // Operation Code is invalid, status is already RSCP_CTNL_PT_RESP_NOT_SUPP + } break; + } + + // If no error raised, inform the application about the request + if (ind_status == RSCP_CTNL_PT_RESP_SUCCESS) + { + // Send the request indication to the application + ke_msg_send(p_req_ind); + // Go to the Busy status + ke_state_set(dest_id, RSCPS_BUSY); + // Align error code + wr_status = GAP_ERR_NO_ERROR; + } + else + { + // Free the allocated message + ke_msg_free(ke_param2msg(p_req_ind)); + } + } while (0); + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = wr_status; + ke_msg_send(p_cfm); + + // If error raised in control point, inform the peer + if ((ind_status != RSCP_CTNL_PT_RESP_SUCCESS) && + (p_param->handle == (RSCPS_HANDLE(RSCS_IDX_SC_CTNL_PT_VAL)))) + { + rscps_send_rsp_ind(conidx, p_param->value[0], ind_status); + } + } + else + { + ASSERT_ERR(0); + } + } + } + } + // else drop the message + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles @ref GATT_NOTIFY_CMP_EVT message meaning that a notification or an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + + // Check if a connection exists + if (ke_state_get(dest_id) == RSCPS_BUSY) + { + switch (p_param->operation) + { + case (GATTC_NOTIFY): + { + ASSERT_ERR(p_rscps_env->operation == RSCPS_SEND_RSC_MEAS_OP_CODE); + // continuer operation execution + rscps_exe_operation(conidx); + } break; + + case (GATTC_INDICATE): + { + ASSERT_ERR((p_rscps_env->operation >= RSCPS_CTNL_PT_CUMUL_VAL_OP_CODE) || + (p_rscps_env->operation != RSCPS_CTNL_ERR_IND_OP_CODE)); + + // Inform the application that a procedure has been completed + rscps_send_cmp_evt(conidx, + prf_src_task_get(&p_rscps_env->prf_env, conidx), + prf_dst_task_get(&p_rscps_env->prf_env, conidx), + p_rscps_env->operation, p_param->status); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(rscps) +{ + {RSCPS_ENABLE_REQ, (ke_msg_func_t) rscps_enable_req_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {RSCPS_NTF_RSC_MEAS_CMD, (ke_msg_func_t) rscps_ntf_rsc_meas_cmd_handler}, + {RSCPS_SC_CTNL_PT_CFM, (ke_msg_func_t) rscps_sc_ctnl_pt_cfm_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +void rscps_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct rscps_env_tag *p_rscps_env = PRF_ENV_GET(RSCPS, rscps); + + p_task_desc->msg_handler_tab = rscps_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(rscps_msg_handler_tab); + p_task_desc->state = p_rscps_env->state; + p_task_desc->idx_max = RSCPS_IDX_MAX; +} + +#endif //(BLE_RSC_SENSOR) + +/// @} RSCPSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpp_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpp_common.h new file mode 100644 index 0000000..c1253d0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpp_common.h @@ -0,0 +1,59 @@ +/** + **************************************************************************************** + * + * @file scpp_common.h + * + * @brief Header File - Scan Parameters Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _SCPP_COMMON_H_ +#define _SCPP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup SCPP Scan Parameters Profile + * @ingroup PROFILE + * @brief Scan Parameters Profile + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Scan Interval Window Characteristic Value Structure +struct scpp_scan_intv_wd +{ + /// Scan interval configuration + uint16_t le_scan_intv; + /// Scan window configuration + uint16_t le_scan_window; +}; + +/// @} scpp_common + +#endif /* _SCPP_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/api/scppc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/api/scppc_task.h new file mode 100644 index 0000000..1b37f27 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/api/scppc_task.h @@ -0,0 +1,179 @@ +/** + **************************************************************************************** + * + * @file scppc_task.h + * + * @brief Header file - Scan Parameters Profile Client Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _SCPPC_TASK_H_ +#define _SCPPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup SCPPCTASK Scan Parameters Profile Client Task + * @ingroup SCPPC + * @brief Scan Parameters Profile Client Task + * + * The SCPPCTASK is responsible for handling the messages coming in and out of the + * @ref SCPPC monitor block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "scpp_common.h" +#include "prf_types.h" +#include "rwip_task.h" // Task definitions +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/*@TRACE*/ +enum scppc_msg_id +{ + /// Start the Scan Parameters profile Client Role - at connection + SCPPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_SCPPC), + ///Confirm that cfg connection has finished with discovery results, or that normal cnx started + SCPPC_ENABLE_RSP, + + /// Write Scan Interval Window Characteristic Value Request - Write Without Response + SCPPC_SCAN_INTV_WD_WR_CMD, + /// Read Scan Refresh Notification Configuration Value request + SCPPC_SCAN_REFRESH_NTF_CFG_RD_CMD, + /// Inform APP that Scan Refresh Notification Configuration has been read + SCPPC_SCAN_REFRESH_NTF_CFG_RD_IND, + /// Write Scan Refresh Notification Configuration Value request + SCPPC_SCAN_REFRESH_NTF_CFG_CMD, + /// Inform APP that peer service request a refresh of Scan Parameters values + SCPPC_SCAN_REFRESH_IND, + /// Complete Event Information + SCPPC_CMP_EVT, +}; + +/// Characteristics +enum scppc_char +{ + /// Scan Interval Window + SCPPC_CHAR_SCAN_INTV_WD, + /// Scan Refresh + SCPPC_CHAR_SCAN_REFRESH, + + SCPPC_CHAR_MAX, +}; + + +/// Characteristic descriptors +enum scppc_desc +{ + /// Scan Refresh Client Config + SCPPC_DESC_SCAN_REFRESH_CFG, + + SCPPC_DESC_MAX, +}; + +/// Operation codes +enum scppc_op_codes +{ + /// Database Creation Procedure + SCPPC_RESERVED_OP_CODE = 0, + + /// Configure CCC Operation Code + SCPPC_SCAN_INTV_WD_WR_CMD_OP_CODE = 1, + + /// Read Scan Refresh CCC Operation Code + SCPPC_SCAN_REFRESH_NTF_CFG_RD_CMD_OP_CODE = 2, + + /// Configure Scan Refresh CCC Operation Code + SCPPC_SCAN_REFRESH_NTF_CFG_CMD_OP_CODE = 3, +}; +/* + * APIs Structure + **************************************************************************************** + */ + +///Structure containing the characteristics handles, value handles and descriptors +struct scps_content +{ + /// service info + struct prf_svc svc; + + /// characteristic info: + /// - Scan Interval Window + /// - Scan Refresh + struct prf_char_inf chars[SCPPC_CHAR_MAX]; + + /// Descriptor handles: + /// - Scan Refresh Client Cfg + struct prf_char_desc_inf descs[SCPPC_DESC_MAX]; +}; + +/// Parameters of the @ref SCPPC_ENABLE_REQ message +struct scppc_enable_req +{ + ///Connection type + uint8_t con_type; + ///Existing handle values scps + struct scps_content scps; +}; + +/// Parameters of the @ref SCPPC_ENABLE_RSP message +struct scppc_enable_rsp +{ + ///status + uint8_t status; + ///Existing handle values scps + struct scps_content scps; +}; + +///Parameters of the @ref SCPPC_SCAN_INTV_WD_WR_CMD message +struct scppc_scan_intv_wd_wr_cmd +{ + ///Scan Interval Window + struct scpp_scan_intv_wd scan_intv_wd; +}; + +///Parameters of the @ref SCPPC_SCAN_REFRESH_NTF_CFG_RD_IND message +struct scppc_scan_refresh_ntf_cfg_rd_ind +{ + ///Notification Configuration Value + uint16_t ntf_cfg; +}; + +///Parameters of the @ref SCPPC_SCAN_REFRESH_NTF_CFG_CMD message +struct scppc_scan_refresh_ntf_cfg_cmd +{ + ///Notification Configuration + uint16_t ntf_cfg; +}; + +///Parameters of the @ref SCPPC_CMP_EVT message +struct scppc_cmp_evt +{ + /// Operation + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} SCPPCTASK + +#endif /* _SCPPC_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/sourcelist.txt new file mode 100644 index 0000000..5b54f66 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + scppc.c + scppc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/src/scppc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/src/scppc.c new file mode 100644 index 0000000..c8c36a5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/src/scppc.c @@ -0,0 +1,241 @@ +/** + **************************************************************************************** + * + * @file scppc.c + * + * @brief Scan Parameters Profile Client implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup SCPPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_SP_CLIENT) + +#include "scppc.h" +#include "scppc_task.h" +#include "gap.h" + +#include "ke_mem.h" + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Initialization of the SCPPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t scppc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct scppc_env_tag *p_scppc_env = + (struct scppc_env_tag *) ke_malloc(sizeof(struct scppc_env_tag), KE_MEM_ATT_DB); + + // allocate SCPPC required environment variable + p_env->env = (prf_env_t *) p_scppc_env; + + p_scppc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_scppc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_SCPPC; + scppc_task_init(&(p_env->desc)); + + for (idx = 0; idx < SCPPC_IDX_MAX ; idx++) + { + p_scppc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), SCPPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Destruction of the SCPPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void scppc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct scppc_env_tag *p_scppc_env = (struct scppc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < SCPPC_IDX_MAX; idx++) + { + if (p_scppc_env->p_env[idx] != NULL) + { + ke_free(p_scppc_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_scppc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void scppc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put SCPP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), SCPPC_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void scppc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct scppc_env_tag *p_scppc_env = (struct scppc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_scppc_env->p_env[conidx] != NULL) + { + ke_free(p_scppc_env->p_env[conidx]); + p_scppc_env->p_env[conidx] = NULL; + } + + // Put SCPP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), SCPPC_FREE); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// SCPPC Task interface required by profile manager +const struct prf_task_cbs scppc_itf = +{ + scppc_init, + scppc_destroy, + scppc_create, + scppc_cleanup, +}; + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *scppc_prf_itf_get(void) +{ + return &scppc_itf; +} + +void scppc_enable_rsp_send(struct scppc_env_tag *p_scppc_env, uint8_t conidx, uint8_t status) +{ + //send APP the details of the discovered attributes on SCPPC + struct scppc_enable_rsp *p_rsp = KE_MSG_ALLOC(SCPPC_ENABLE_RSP, + prf_dst_task_get(&(p_scppc_env->prf_env) ,conidx), + prf_src_task_get(&(p_scppc_env->prf_env) ,conidx), + scppc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->scps = p_scppc_env->p_env[conidx]->scps; + + // If Scan Refresh Char. has been discovered + if (p_scppc_env->p_env[conidx]->scps.chars[SCPPC_CHAR_SCAN_REFRESH].char_hdl != ATT_INVALID_HANDLE) + { + // Register SCPPC task in gatt for notifications + prf_register_atthdl2gatt(&(p_scppc_env->prf_env), conidx, &p_scppc_env->p_env[conidx]->scps.svc); + } + } + else + { + memset(&p_rsp->scps, 0 , sizeof(p_rsp->scps)); + } + + ke_msg_send(p_rsp); +} + +void scppc_send_cmp_evt(struct scppc_env_tag *p_scppc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct scppc_cmp_evt *p_evt; + ke_task_id_t src_id = prf_src_task_get(&(p_scppc_env->prf_env), conidx); + ke_task_id_t dest_id = prf_dst_task_get(&(p_scppc_env->prf_env), conidx); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == SCPPC_BUSY) + { + ke_state_set(src_id, SCPPC_IDLE); + } + + // Send the message to the application + p_evt = KE_MSG_ALLOC(SCPPC_CMP_EVT, dest_id, src_id, scppc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif /* (BLE_SP_CLIENT) */ + +/// @} SCPPC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/src/scppc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/src/scppc.h new file mode 100644 index 0000000..41a9918 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/src/scppc.h @@ -0,0 +1,172 @@ +/** + **************************************************************************************** + * + * @file scppc.h + * + * @brief Header file - Scan Parameters Profile -Client Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _SCPPC_H_ +#define _SCPPC_H_ + + +/** + **************************************************************************************** + * @addtogroup SCPPC Scan Parameters Profile Client + * @ingroup SCPP + * @brief Scan Parameters Profile Client + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#if (BLE_SP_CLIENT) + +#include "scpp_common.h" +#include "scppc_task.h" +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" +#include "prf.h" + + +/* + * Defines + **************************************************************************************** + */ + +///Maximum number of Scan Parameters Client task instances +#define SCPPC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the SCPPC task +enum scppc_state +{ + /// Disconnected state + SCPPC_FREE, + /// IDLE state + SCPPC_IDLE, + /// busy state + SCPPC_BUSY, + /// Number of defined states. + SCPPC_STATE_MAX +}; + +enum scppc_operation +{ + /// No operation + SCPPC_OP_NONE = 0, + /// Discover peer service + SCPPC_OP_DISCOVER, + /// Write Notification configuration + SCPPC_OP_WR_NTF_CFG, + /// Read Notification configuration + SCPPC_OP_RD_NTF_CFG, + /// Write Scan intervals + SCPPC_OP_WR_SCAN_INTV, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Environment variable for each Connections +struct scppc_cnx_env +{ + ///SCPS characteristics + struct scps_content scps; + /// on-going operation + uint8_t operation; + /// counter used to check service uniqueness + uint8_t nb_svc; +}; + +/// Scan Parameters Profile Client environment variable +struct scppc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct scppc_cnx_env *p_env[SCPPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[SCPPC_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve SCPP client profile interface + * + * @return SCPP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *scppc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send SCP ATT DB discovery results to SCPPC host. + * + * @param p_scppc_env Scan Parameters Profile Client Role task environment + * @param conidx Connection index + * @param status Response status code + **************************************************************************************** + */ +void scppc_enable_rsp_send(struct scppc_env_tag *p_scppc_env, uint8_t conidx, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void scppc_task_init(struct ke_task_desc *p_task_desc); + +/** + **************************************************************************************** + * @brief Send an SCPPC_CMP_EVT message to a requester. + * + * @param[in] p_scppc_env Scan Parameters Client environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void scppc_send_cmp_evt(struct scppc_env_tag *p_scppc_env, uint8_t conidx, uint8_t operation, uint8_t status); + + +#endif /* (BLE_SP_CLIENT) */ + +/// @} SCPPC + +#endif /* _SCPPC_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/src/scppc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/src/scppc_task.c new file mode 100644 index 0000000..acf9747 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scppc/src/scppc_task.c @@ -0,0 +1,595 @@ +/** + **************************************************************************************** + * + * @file scppc_task.c + * + * @brief Scan Parameters Profile Client Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup SCPPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_SP_CLIENT) + +#include "scpp_common.h" +#include "scppc_task.h" +#include "scppc.h" + +#include "gap.h" +#include "attm.h" +#include "gattc_task.h" +#include "prf_types.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLES DEFINITIONS + **************************************************************************************** + */ + +/// State machine used to retrieve Scan Parameters Service characteristics information +const struct prf_char_def scppc_scps_char[SCPPC_CHAR_MAX] = +{ + // Scan Interval Window + [SCPPC_CHAR_SCAN_INTV_WD] = {ATT_CHAR_SCAN_INTV_WD, + ATT_MANDATORY, + ATT_CHAR_PROP_WR_NO_RESP}, + // Scan Refresh + [SCPPC_CHAR_SCAN_REFRESH] = {ATT_CHAR_SCAN_REFRESH, + ATT_OPTIONAL, + ATT_CHAR_PROP_NTF}, +}; + +/// State machine used to retrieve Scan Parameters Service characteristic description information +const struct prf_char_desc_def scppc_scps_char_desc[SCPPC_DESC_MAX] = +{ + // Boot Keyboard Input Report Client Config + [SCPPC_DESC_SCAN_REFRESH_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, SCPPC_CHAR_SCAN_REFRESH}, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref SCPPC_ENABLE_REQ message. + * The handler enables the Scan Parameters Profile Client Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int scppc_enable_req_handler(ke_msg_id_t const msgid, + struct scppc_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Battery service Client Role Task Environment + struct scppc_env_tag *p_scppc_env = PRF_ENV_GET(SCPPC, scppc); + + ASSERT_INFO(p_scppc_env != NULL, dest_id, src_id); + if ((state == SCPPC_IDLE) && (p_scppc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_scppc_env->p_env[conidx] = (struct scppc_cnx_env *) ke_malloc(sizeof(struct scppc_cnx_env), KE_MEM_ATT_DB); + memset(p_scppc_env->p_env[conidx], 0, sizeof(struct scppc_cnx_env)); + + // Config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + //start discovering SCPP on peer + prf_disc_svc_send(&(p_scppc_env->prf_env), conidx, ATT_SVC_SCAN_PARAMETERS); + + // Go to DISCOVERING state + ke_state_set(dest_id, SCPPC_BUSY); + p_scppc_env->p_env[conidx]->operation = SCPPC_OP_DISCOVER; + } + // normal connection, get saved att details + else + { + p_scppc_env->p_env[conidx]->nb_svc = 1; + memcpy(&(p_scppc_env->p_env[conidx]->scps), &(p_param->scps), sizeof(struct scps_content)); + + // send APP confirmation that can start normal connection to TH + scppc_enable_rsp_send(p_scppc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != SCPPC_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + scppc_enable_rsp_send(p_scppc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == SCPPC_BUSY) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct scppc_env_tag *p_scppc_env = PRF_ENV_GET(SCPPC, scppc); + + ASSERT_INFO(p_scppc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_scppc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (p_scppc_env->p_env[conidx]->nb_svc == 0) + { + // Retrieve DIS characteristics + prf_extract_svc_info(p_ind, SCPPC_CHAR_MAX, &scppc_scps_char[0], + &(p_scppc_env->p_env[conidx]->scps.chars[0]), + SCPPC_DESC_MAX, &scppc_scps_char_desc[0], + &(p_scppc_env->p_env[conidx]->scps.descs[0])); + + //Even if we get multiple responses we only store 1 range + p_scppc_env->p_env[conidx]->scps.svc.shdl = p_ind->start_hdl; + p_scppc_env->p_env[conidx]->scps.svc.ehdl = p_ind->end_hdl; + } + + p_scppc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref SCPPC_SCAN_INTV_WD_WR_CMD message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int scppc_scan_intv_wd_wr_cmd_handler(ke_msg_id_t const msgid, + struct scppc_scan_intv_wd_wr_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (state == SCPPC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct scppc_env_tag *p_scppc_env = PRF_ENV_GET(SCPPC, scppc); + + ASSERT_INFO(p_scppc_env != NULL, dest_id, src_id); + + // environment variable not ready + if (p_scppc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + uint16_t handle = p_scppc_env->p_env[conidx]->scps.chars[SCPPC_CHAR_SCAN_INTV_WD].val_hdl; + status = PRF_ERR_INEXISTENT_HDL; + + if (handle != ATT_INVALID_HANDLE) + { + uint8_t data[2*sizeof(uint16_t)]; + + status = GAP_ERR_NO_ERROR; + co_write16p(&(data[0]), p_param->scan_intv_wd.le_scan_intv); + co_write16p(&(data[sizeof(uint16_t)]) , p_param->scan_intv_wd.le_scan_window); + + // Send GATT Write Request + prf_gatt_write(&p_scppc_env->prf_env, conidx, handle, data, 2*sizeof(uint16_t), GATTC_WRITE_NO_RESPONSE); + // store context of request and go into busy state + p_scppc_env->p_env[conidx]->operation = SCPPC_OP_WR_SCAN_INTV; + ke_state_set(dest_id, SCPPC_BUSY); + } + } + } + // process message later + else if (state == SCPPC_BUSY) + { + status = GAP_ERR_NO_ERROR; + msg_status = KE_MSG_SAVED; + } + + // request cannot be performed + if (status != GAP_ERR_NO_ERROR) + { + struct scppc_cmp_evt *p_evt = KE_MSG_ALLOC(SCPPC_CMP_EVT, + src_id, dest_id, scppc_cmp_evt); + + // set error status + p_evt->status = status; + p_evt->operation = SCPPC_SCAN_INTV_WD_WR_CMD_OP_CODE; + + ke_msg_send(p_evt); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref SCPPC_SCAN_REFRESH_NTF_CFG_RD_CMD message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int scppc_scan_refresh_ntf_cfg_rd_cmd_handler(ke_msg_id_t const msgid, + void const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (state == SCPPC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct scppc_env_tag *p_scppc_env = PRF_ENV_GET(SCPPC, scppc); + + ASSERT_INFO(p_scppc_env != NULL, dest_id, src_id); + + // environment variable not ready + if (p_scppc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + uint16_t handle = p_scppc_env->p_env[conidx]->scps.descs[SCPPC_DESC_SCAN_REFRESH_CFG].desc_hdl; + + status = PRF_ERR_INEXISTENT_HDL; + + if (handle != ATT_INVALID_HANDLE) + { + status = GAP_ERR_NO_ERROR; + // read information + prf_read_char_send(&(p_scppc_env->prf_env), conidx, + p_scppc_env->p_env[conidx]->scps.svc.shdl, + p_scppc_env->p_env[conidx]->scps.svc.ehdl, handle); + + // store context of request and go into busy state + p_scppc_env->p_env[conidx]->operation = SCPPC_OP_RD_NTF_CFG; + ke_state_set(dest_id, SCPPC_BUSY); + } + } + } + // process message later + else if (state == SCPPC_BUSY) + { + status = GAP_ERR_NO_ERROR; + msg_status = KE_MSG_SAVED; + } + + // request cannot be performed + if (status != GAP_ERR_NO_ERROR) + { + struct scppc_cmp_evt *p_evt = KE_MSG_ALLOC(SCPPC_CMP_EVT, + src_id, dest_id, scppc_cmp_evt); + + // set error status + p_evt->status = status; + p_evt->operation = SCPPC_SCAN_REFRESH_NTF_CFG_RD_CMD_OP_CODE; + + ke_msg_send(p_evt); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref SCPPC_SCAN_REFRESH_NTF_CFG_CMD message. + * It allows configuration of the peer ntf/stop characteristic for a specified characteristic. + * Will return an error code if that cfg char does not exist. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int scppc_scan_refresh_ntf_cfg_cmd_handler(ke_msg_id_t const msgid, + struct scppc_scan_refresh_ntf_cfg_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (state == SCPPC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct scppc_env_tag *p_scppc_env = PRF_ENV_GET(SCPPC, scppc); + + ASSERT_INFO(p_scppc_env != NULL, dest_id, src_id); + + // environment variable not ready + if (p_scppc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + uint16_t handle = p_scppc_env->p_env[conidx]->scps.descs[SCPPC_DESC_SCAN_REFRESH_CFG].desc_hdl; + + status = PRF_ERR_INEXISTENT_HDL; + + if (handle != ATT_INVALID_HANDLE) + { + status = GAP_ERR_NO_ERROR; + // Send GATT Write Request + prf_gatt_write_ntf_ind(&p_scppc_env->prf_env, conidx, handle, p_param->ntf_cfg); + // store context of request and go into busy state + p_scppc_env->p_env[conidx]->operation = SCPPC_OP_WR_NTF_CFG; + ke_state_set(dest_id, SCPPC_BUSY); + } + } + } + // process message later + else if (state == SCPPC_BUSY) + { + status = GAP_ERR_NO_ERROR; + msg_status = KE_MSG_SAVED; + } + + // request cannot be performed + if (status != GAP_ERR_NO_ERROR) + { + struct scppc_cmp_evt *p_evt = KE_MSG_ALLOC(SCPPC_CMP_EVT, + src_id, dest_id, scppc_cmp_evt); + + // set error status + p_evt->status = status; + p_evt->operation = SCPPC_SCAN_REFRESH_NTF_CFG_CMD_OP_CODE; + + ke_msg_send(p_evt); + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct scppc_env_tag *p_scppc_env = PRF_ENV_GET(SCPPC, scppc); + + // sanity check + if ((ke_state_get(dest_id) == SCPPC_BUSY) && (p_scppc_env->p_env[conidx] != NULL) + && (p_scppc_env->p_env[conidx]->operation != SCPPC_OP_NONE)) + { + switch (p_scppc_env->p_env[conidx]->operation) + { + case SCPPC_OP_DISCOVER: + { + uint8_t status = p_param->status; + + if (p_param->status == ATT_ERR_NO_ERROR) + { + // check characteristic validity + if (p_scppc_env->p_env[conidx]->nb_svc == 1) + { + status = prf_check_svc_char_validity(SCPPC_CHAR_MAX, + p_scppc_env->p_env[conidx]->scps.chars, + scppc_scps_char); + + // check descriptor validity + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(SCPPC_DESC_MAX, + p_scppc_env->p_env[conidx]->scps.descs, scppc_scps_char_desc, + p_scppc_env->p_env[conidx]->scps.chars); + } + } + // invalid number of services + else if (p_scppc_env->p_env[conidx]->nb_svc > 1) + { + status = PRF_ERR_MULTIPLE_SVC; + } + // no services found + else + { + status = PRF_ERR_STOP_DISC_CHAR_MISSING; + } + } + + scppc_enable_rsp_send(p_scppc_env, conidx, status); + } break; + + case SCPPC_OP_RD_NTF_CFG: + { + scppc_send_cmp_evt(p_scppc_env, conidx, SCPPC_SCAN_REFRESH_NTF_CFG_RD_CMD_OP_CODE, p_param->status); + } break; + + case SCPPC_OP_WR_NTF_CFG: + { + scppc_send_cmp_evt(p_scppc_env, conidx, SCPPC_SCAN_REFRESH_NTF_CFG_CMD_OP_CODE, p_param->status); + } break; + + case SCPPC_OP_WR_SCAN_INTV: + { + scppc_send_cmp_evt(p_scppc_env, conidx, SCPPC_SCAN_INTV_WD_WR_CMD_OP_CODE, p_param->status); + } break; + + default: + { + // Not Expected at all + ASSERT_ERR(0); + } break; + } + + // operation is over - go back to idle state + p_scppc_env->p_env[conidx]->operation = SCPPC_OP_NONE; + ke_state_set(dest_id, SCPPC_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == SCPPC_BUSY) + { + uint8_t conidx = KE_IDX_GET(dest_id); + struct scppc_env_tag *p_scppc_env = PRF_ENV_GET(SCPPC, scppc); + + ASSERT_INFO(p_scppc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_scppc_env->p_env[conidx] != NULL, dest_id, src_id); + + struct scppc_scan_refresh_ntf_cfg_rd_ind *p_rsp = KE_MSG_ALLOC(SCPPC_SCAN_REFRESH_NTF_CFG_RD_IND, + prf_dst_task_get(&(p_scppc_env->prf_env), conidx), dest_id, scppc_scan_refresh_ntf_cfg_rd_ind); + + p_rsp->ntf_cfg = co_read16p(&(p_param->value[0])); + + ke_msg_send(p_rsp); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) != SCPPC_FREE) + { + // Retrieve environment data + struct scppc_env_tag *p_scppc_env = PRF_ENV_GET(SCPPC, scppc); + + // inform application that service requests to refresh + ke_msg_send_basic(SCPPC_SCAN_REFRESH_IND, + prf_dst_task_get(&(p_scppc_env->prf_env), + KE_IDX_GET(src_id)), + dest_id); + } + + return (KE_MSG_CONSUMED); +} + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(scppc) +{ + {SCPPC_ENABLE_REQ, (ke_msg_func_t)scppc_enable_req_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + + {SCPPC_SCAN_INTV_WD_WR_CMD, (ke_msg_func_t)scppc_scan_intv_wd_wr_cmd_handler}, + {SCPPC_SCAN_REFRESH_NTF_CFG_RD_CMD, (ke_msg_func_t)scppc_scan_refresh_ntf_cfg_rd_cmd_handler}, + {SCPPC_SCAN_REFRESH_NTF_CFG_CMD, (ke_msg_func_t)scppc_scan_refresh_ntf_cfg_cmd_handler}, + + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void scppc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct scppc_env_tag *p_scppc_env = PRF_ENV_GET(SCPPC, scppc); + + p_task_desc->msg_handler_tab = scppc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(scppc_msg_handler_tab); + p_task_desc->state = p_scppc_env->state; + p_task_desc->idx_max = SCPPC_IDX_MAX; +} + +#endif /* (BLE_SP_CLIENT) */ +/// @} SCPPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/api/scpps_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/api/scpps_task.h new file mode 100644 index 0000000..3c4b1e8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/api/scpps_task.h @@ -0,0 +1,157 @@ +/** + **************************************************************************************** + * + * @file scpps_task.h + * + * @brief Header file - Scan Parameters Profile Server Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _SCPPS_TASK_H_ +#define _SCPPS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup SCPPSTASK Task + * @ingroup SCPPS + * @brief Scan Parameters Profile Task. + * + * The SCPPS_TASK is responsible for handling the messages coming in and out of the + * @ref SCPPS block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "scpp_common.h" +#include "prf_types.h" +#include "rwip_task.h" // Task definitions + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/// Messages for Scan Parameters Profile Server +/*@TRACE*/ +enum scpps_msg_id +{ + /// Update bond data of the Scan Parameters Profile Server for a specific connection - Request + SCPPS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_SCPPS), + /// Update bond data of the Scan Parameters Profile Server for a specific connection - Response + SCPPS_ENABLE_RSP, + + /// Indicate to APP that the Scan Interval Window value has been written by Client + SCPPS_SCAN_INTV_WD_IND, + /// Indicate to APP that the Scan Refresh Notification Configuration has been changed + SCPPS_SCAN_REFRESH_NTF_CFG_IND, + + /// Notify client about new Scan Refresh Value + SCPPS_SCAN_REFRESH_SEND_CMD, + /// Complete Event Information + SCPPS_CMP_EVT, +}; + +/// Features Flag Masks +enum scpps_features +{ + /// Scan Refresh Characteristic is not supported + SCPPS_SCAN_REFRESH_NOT_SUP = 0, + /// Scan Refresh Characteristic is supported + SCPPS_SCAN_REFRESH_SUP, +}; + +/// Operation codes +enum scpps_op_codes +{ + /// Database Creation Procedure + SCPPS_RESERVED_OP_CODE = 0, + + /// Notify Scan Refresh Operation Code + SCPPS_SCAN_REFRESH_SEND_CMD_OP_CODE = 1, +}; + +/* + * APIs Structures + **************************************************************************************** + */ + +/// Parameters for the database creation +struct scpps_db_cfg +{ + /// Optional features to add - @see enum scpps_features + uint8_t features; +}; + +/// Parameters of the @ref SCPPS_ENABLE_REQ message +struct scpps_enable_req +{ + /// Connection index + uint8_t conidx; + /// Scan Refresh Notification Configurations + uint8_t ntf_cfg; +}; + +/// Parameters of the @ref SCPPS_ENABLE_RSP message +struct scpps_enable_rsp +{ + /// Connection index + uint8_t conidx; + /// Status + uint8_t status; +}; + +/// Parameters of the @ref SCPPS_SCAN_INTV_WD_IND message +struct scpps_scan_intv_wd_ind +{ + /// Connection index + uint8_t conidx; + /// Scan Interval Window + struct scpp_scan_intv_wd scan_intv_wd; +}; + +/// Parameters of the @ref SCPPS_SCAN_REFRESH_NTF_CFG_IND message +struct scpps_scan_refresh_ntf_cfg_ind +{ + /// Connection index + uint8_t conidx; + /// Scan Refresh Notification Configuration + uint8_t ntf_cfg; +}; + +/// Parameters of the @ref SCPPS_SCAN_REFRESH_SEND_CMD message +struct scpps_scan_refresh_send_cmd +{ + /// Connection index + uint8_t conidx; +}; + +/// Parameters of the @ref SCPPS_CMP_EVT message +struct scpps_cmp_evt +{ + /// Connection index + uint8_t conidx; + /// Connection index + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} SCPPSTASK + +#endif /* _SCPPS_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/sourcelist.txt new file mode 100644 index 0000000..3c3749e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + scpps.c + scpps_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/src/scpps.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/src/scpps.c new file mode 100644 index 0000000..9e7a87d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/src/scpps.c @@ -0,0 +1,238 @@ +/** + **************************************************************************************** + * + * @file scpps.c + * + * @brief Scan Parameters Profile Server implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup SCPPS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_SP_SERVER) + +#include "gap.h" +#include "attm.h" +#include "scpps.h" +#include "scpps_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" + +/* + * SCPP ATTRIBUTES DEFINITION + **************************************************************************************** + */ + +/// Full SCPS Database Description - Used to add attributes into the database +const struct attm_desc scpps_att_db[SCPS_IDX_NB] = +{ + // Scan Parameters Service Declaration + [SCPS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Scan Interval Window Characteristic Declaration + [SCPS_IDX_SCAN_INTV_WD_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Scan Interval Window Characteristic Value + [SCPS_IDX_SCAN_INTV_WD_VAL] = {ATT_CHAR_SCAN_INTV_WD, PERM(WRITE_COMMAND, ENABLE), + PERM(RI,ENABLE), sizeof(struct scpp_scan_intv_wd)}, + + // Scan Refresh Characteristic Declaration + [SCPS_IDX_SCAN_REFRESH_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Scan Refresh Characteristic Value + [SCPS_IDX_SCAN_REFRESH_VAL] = {ATT_CHAR_SCAN_REFRESH, PERM(NTF, ENABLE), PERM(RI,ENABLE), 0}, + // Scan Refresh Characteristic - Client Characteristic Configuration Descriptor + [SCPS_IDX_SCAN_REFRESH_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) |PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the SCPPS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t scpps_init (struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct scpps_db_cfg *p_params) +{ + struct scpps_env_tag *p_scpps_env = NULL; + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Service content flag + uint8_t cfg_flag = SCPPS_CFG_FLAG_MANDATORY_MASK; + + // Check if multiple instances + if ((p_params->features & SCPPS_SCAN_REFRESH_SUP) != 0) + { + cfg_flag |= SCPPS_CFG_FLAG_SCAN_REFRESH_MASK; + } + + //Create SCPS in the DB + //------------------ create the attribute database for the profile ------------------- + status = attm_svc_create_db(p_start_hdl, ATT_SVC_SCAN_PARAMETERS, (uint8_t *)&cfg_flag, + SCPS_IDX_NB, NULL, p_env->task, scpps_att_db, + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS))); + + //-------------------- Update profile task information --------------------- + if (status == ATT_ERR_NO_ERROR) + { + //-------------------- allocate memory required for the profile --------------------- + + // allocate SCPPS required environment variable + p_scpps_env = (struct scpps_env_tag *) ke_malloc(sizeof(struct scpps_env_tag), KE_MEM_ATT_DB); + memset(p_scpps_env, 0 , sizeof(struct scpps_env_tag)); + + p_env->env = (prf_env_t *) p_scpps_env; + p_scpps_env->start_hdl = *p_start_hdl; + p_scpps_env->features = p_params->features; + p_scpps_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_scpps_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, DISABLE); + + // initialize environment variable + p_env->id = TASK_ID_SCPPS; + scpps_task_init(&(p_env->desc)); + + // service is ready, go into an Idle state + ke_state_set(p_env->task, SCPPS_IDLE); + } + else if (p_scpps_env != NULL) + { + ke_free(p_scpps_env); + } + + return (status); +} +/** + **************************************************************************************** + * @brief Destruction of the SCPPS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void scpps_destroy(struct prf_task_env *p_env) +{ + struct scpps_env_tag *p_scpps_env = (struct scpps_env_tag *) p_env->env; + + // free profile environment variables + p_env->env = NULL; + ke_free(p_scpps_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void scpps_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Nothing to do +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void scpps_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct scpps_env_tag *p_scpps_env = (struct scpps_env_tag *) p_env->env; + + ASSERT_ERR(conidx < BLE_CONNECTION_MAX); + // force notification config to zero when peer device is disconnected + p_scpps_env->ntf_cfg[conidx] = 0; +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// SCPPS Task interface required by profile manager +const struct prf_task_cbs scpps_itf = +{ + (prf_init_fnct) scpps_init, + scpps_destroy, + scpps_create, + scpps_cleanup, +}; + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *scpps_prf_itf_get(void) +{ + return &scpps_itf; +} + +void scpps_send_cmp_evt(struct scpps_env_tag *p_scpps_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct scpps_cmp_evt *p_evt; + ke_task_id_t src_id = prf_src_task_get(&(p_scpps_env->prf_env), conidx); + ke_task_id_t dest_id = prf_dst_task_get(&(p_scpps_env->prf_env), conidx); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == SCPPS_BUSY) + { + ke_state_set(src_id, SCPPS_IDLE); + } + + // Send the message to the application + p_evt = KE_MSG_ALLOC(SCPPS_CMP_EVT, dest_id, src_id, scpps_cmp_evt); + + p_evt->conidx = conidx; + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + + +#endif // (BLE_SP_SERVER) + +/// @} SCPPS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/src/scpps.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/src/scpps.h new file mode 100644 index 0000000..3d767ee --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/src/scpps.h @@ -0,0 +1,170 @@ +/** + **************************************************************************************** + * + * @file scpps.h + * + * @brief Header file - Scan Parameters Profile Server. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _SCPPS_H_ +#define _SCPPS_H_ + +/** + **************************************************************************************** + * @addtogroup SCPPS Scan Parameters Profile Server + * @ingroup SCPP + * @brief Scan Parameters Profile Server + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_SP_SERVER) + +#include "scpp_common.h" +#include "scpps_task.h" +#include "prf_types.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + +///Maximum number of Scan Parameters Device task instances +#define SCPPS_IDX_MAX 0x01 + +#define SCPPS_CFG_FLAG_MANDATORY_MASK (0x07) +#define SCPPS_CFG_FLAG_SCAN_REFRESH_MASK (0x38) + +/// Scanning set parameters range min (0x4) +#define SCPPS_SCAN_INTERVAL_MIN 4 +/// Scanning set parameters range max (0x4000) +#define SCPPS_SCAN_INTERVAL_MAX 16384 + +/// Scanning set parameters range min (0x4) +#define SCPPS_SCAN_WINDOW_MIN 4 +/// Scanning set parameters range max (0x4000) +#define SCPPS_SCAN_WINDOW_MAX 16384 + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the SCPPS task +enum scpps_state +{ + /// Idle state + SCPPS_IDLE, + /// Busy state + SCPPS_BUSY, + + /// Number of defined states. + SCPPS_STATE_MAX +}; + +/// Scan Parameters Service Attributes Indexes +enum +{ + SCPS_IDX_SVC, + + SCPS_IDX_SCAN_INTV_WD_CHAR, + SCPS_IDX_SCAN_INTV_WD_VAL, + + SCPS_IDX_SCAN_REFRESH_CHAR, + SCPS_IDX_SCAN_REFRESH_VAL, + SCPS_IDX_SCAN_REFRESH_NTF_CFG, + + SCPS_IDX_NB, +}; + +enum +{ + SCPP_SERVER_REQUIRES_REFRESH = 0x00, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Scan Parameters Profile Server environment variable +struct scpps_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// SCPS Start Handle + uint16_t start_hdl; + /// Database configuration + uint8_t features; + /// Notification configuration of peer devices. + uint8_t ntf_cfg[BLE_CONNECTION_MAX]; + /// BASS task state + ke_state_t state[SCPPS_IDX_MAX]; + +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve SCPPS service profile interface + * + * @return SCPPS service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *scpps_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send an SCPPS_CMP_EVT message to a requester. + * + * @param[in] p_scpps_env Scan Parameters Server environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void scpps_send_cmp_evt(struct scpps_env_tag *p_scpps_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void scpps_task_init(struct ke_task_desc *p_task_desc); + + +#endif /* #if (BLE_SP_SERVER) */ + +/// @} SCPPS + +#endif /* _SCPPS_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/src/scpps_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/src/scpps_task.c new file mode 100644 index 0000000..b88fbd9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/scpp/scpps/src/scpps_task.c @@ -0,0 +1,401 @@ +/** + **************************************************************************************** + * + * @file scpps_task.c + * + * @brief Scan Parameters Profile Server Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup SCPPSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_SP_SERVER) +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" + +#include "scpps.h" +#include "scpps_task.h" +#include "scpp_common.h" + +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref SCPPS_ENABLE_REQ message. + * The handler enables the Scan Parameters Profile Server Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int scpps_enable_req_handler(ke_msg_id_t const msgid, + struct scpps_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_SAVED; + + // check state of the task + if (ke_state_get(dest_id) == SCPPS_IDLE) + { + struct scpps_env_tag *p_scpps_env = PRF_ENV_GET(SCPPS, scpps); + + // an error occurs, trigg it. + struct scpps_enable_rsp *p_rsp = KE_MSG_ALLOC(SCPPS_ENABLE_RSP, src_id, + dest_id, scpps_enable_rsp); + + msg_status = KE_MSG_CONSUMED; + p_rsp->conidx = p_param->conidx; + + if ((p_param->conidx > BLE_CONNECTION_MAX) + || (gapc_get_conhdl(p_param->conidx) == GAP_INVALID_CONHDL)) + { + p_rsp->status = (p_param->conidx > BLE_CONNECTION_MAX) ? GAP_ERR_INVALID_PARAM : PRF_ERR_REQ_DISALLOWED; + } + else + { + // restore Bond Data + p_scpps_env->ntf_cfg[p_param->conidx] = p_param->ntf_cfg; + p_rsp->status = GAP_ERR_NO_ERROR; + } + + ke_msg_send(p_rsp); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref SCPPS_SCAN_REFRESH_SEND_CMD message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int scpps_scan_refresh_send_cmd_handler(ke_msg_id_t const msgid, + struct scpps_scan_refresh_send_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_SAVED; + + // check state of the task + if (ke_state_get(dest_id) == SCPPS_IDLE) + { + uint8_t status = GAP_ERR_NO_ERROR; + struct scpps_env_tag *p_scpps_env = PRF_ENV_GET(SCPPS, scpps); + + msg_status = KE_MSG_CONSUMED; + + // Check provided values + if ((p_param->conidx < BLE_CONNECTION_MAX) + && ((p_scpps_env->features & SCPPS_SCAN_REFRESH_SUP) != 0) + && ((p_scpps_env->ntf_cfg[p_param->conidx] & PRF_CLI_START_NTF) != 0)) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_refresh_ntf = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, p_param->conidx), dest_id, + gattc_send_evt_cmd, sizeof(uint8_t)); + + // Fill in the p_parameter structure + p_refresh_ntf->operation = GATTC_NOTIFY; + p_refresh_ntf->handle = p_scpps_env->start_hdl + SCPS_IDX_SCAN_REFRESH_VAL; + // pack measured value in database + p_refresh_ntf->length = sizeof(uint8_t); + p_refresh_ntf->value[0] = SCPP_SERVER_REQUIRES_REFRESH; + + // send notification to peer device + ke_msg_send(p_refresh_ntf); + // wait for event to be taken in account in Lower layers. + ke_state_set(dest_id, SCPPS_BUSY); + } + // invalid connection index + else if (p_param->conidx >= BLE_CONNECTION_MAX) + { + status = GAP_ERR_INVALID_PARAM; + } + // feature not supported + else if ((p_scpps_env->features & SCPPS_SCAN_REFRESH_SUP) == 0) + { + status = PRF_ERR_FEATURE_NOT_SUPPORTED; + } + // notification not configured + else // ((p_scpps_env->ntf_cfg[p_param->conidx] & PRF_CLI_START_NTF) == 0) + { + status = PRF_ERR_NTF_DISABLED; + } + + if (status != GAP_ERR_NO_ERROR) + { + scpps_send_cmp_evt(p_scpps_env, + p_param->conidx, + SCPPS_SCAN_REFRESH_SEND_CMD_OP_CODE, + status); + } + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct gattc_att_info_cfm *p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + struct scpps_env_tag* p_scpps_env = PRF_ENV_GET(SCPPS, scpps); + + //Send att_info response + p_cfm->handle = p_param->handle; + + // Scan Refresh Notification Configuration + if (p_param->handle == p_scpps_env->start_hdl + SCPS_IDX_SCAN_REFRESH_NTF_CFG) + { + p_cfm->length = 1; + p_cfm->status = GAP_ERR_NO_ERROR; + } + else + { + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } + + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GL2C_CODE_ATT_WR_CMD_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status for write response + uint8_t status = PRF_APP_ERROR; + struct scpps_env_tag *p_scpps_env = PRF_ENV_GET(SCPPS, scpps); + uint8_t conidx = KE_IDX_GET(src_id); + struct gattc_write_cfm *p_cfm; + + // Scan Interval Window Value + if (p_param->handle == p_scpps_env->start_hdl + SCPS_IDX_SCAN_INTV_WD_VAL) + { + uint16_t le_scan_intv; + uint16_t le_scan_window; + + // Extract value + le_scan_intv = co_read16p(&p_param->value[0]); + le_scan_window = co_read16p(&p_param->value[sizeof(uint16_t)]); + + // Check interval and window validity + if ((le_scan_window <= le_scan_intv) + &&(le_scan_window <= SCPPS_SCAN_WINDOW_MAX) + &&(le_scan_window >= SCPPS_SCAN_WINDOW_MIN) + &&(le_scan_intv <= SCPPS_SCAN_INTERVAL_MAX) + &&(le_scan_intv >= SCPPS_SCAN_INTERVAL_MIN)) + + { + // Inform APP of Scan Interval Window change + struct scpps_scan_intv_wd_ind *p_ind = KE_MSG_ALLOC(SCPPS_SCAN_INTV_WD_IND, + prf_dst_task_get(&(p_scpps_env->prf_env), conidx), + dest_id, scpps_scan_intv_wd_ind); + + p_ind->conidx = conidx; + p_ind->scan_intv_wd.le_scan_intv = le_scan_intv; + p_ind->scan_intv_wd.le_scan_window = le_scan_window; + + ke_msg_send(p_ind); + status = GAP_ERR_NO_ERROR; + } + } + // Scan Refresh Notification Configuration + else if (p_param->handle == p_scpps_env->start_hdl + SCPS_IDX_SCAN_REFRESH_NTF_CFG) + { + // Check if Scan Refresh Characteristic is supported + if ((p_scpps_env->features & SCPPS_SCAN_REFRESH_SUP) != 0) + { + // Extract value before check + uint16_t ntf_cfg = co_read16p(&p_param->value[0]); + + // Only update configuration if value for stop or notification enable + if ((ntf_cfg == PRF_CLI_STOP_NTFIND) || (ntf_cfg == PRF_CLI_START_NTF)) + { + // Inform APP of configuration change + struct scpps_scan_refresh_ntf_cfg_ind *p_ind = KE_MSG_ALLOC(SCPPS_SCAN_REFRESH_NTF_CFG_IND, + prf_dst_task_get(&(p_scpps_env->prf_env), conidx), + dest_id, scpps_scan_refresh_ntf_cfg_ind); + + // Update state value in environment + p_scpps_env->ntf_cfg[conidx]= (uint8_t)ntf_cfg; + + p_ind->conidx = conidx; + p_ind->ntf_cfg = p_scpps_env->ntf_cfg[conidx]; + ke_msg_send(p_ind); + status = GAP_ERR_NO_ERROR; + } + } + } + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_REQ_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(src_id); + struct scpps_env_tag *p_scpps_env = PRF_ENV_GET(SCPPS, scpps); + + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, sizeof(uint16_t)); + + p_cfm->handle = p_param->handle; + + // Scan Refresh Notification Configuration + if ((p_param->handle == p_scpps_env->start_hdl + SCPS_IDX_SCAN_REFRESH_NTF_CFG) + && ((p_scpps_env->features & SCPPS_SCAN_REFRESH_SUP) != 0)) + { + // Extract value before check + uint16_t ntf_cfg = (p_scpps_env->ntf_cfg[conidx] == PRF_CLI_START_NTF) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND; + + co_write16p(&p_cfm->value[0], ntf_cfg); + p_cfm->length = sizeof(uint16_t); + p_cfm->status = GAP_ERR_NO_ERROR; + } + else + { + p_cfm->length = 0; + p_cfm->status = PRF_APP_ERROR; + } + + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT for GATTC_NOTIFY message meaning that Measurement + * notification has been correctly sent to peer device (but not confirmed by peer device). + * * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + // check state of the task + if ((ke_state_get(dest_id) == SCPPS_BUSY) && (p_param->operation == GATTC_NOTIFY)) + { + // send refresh response and go back to idle state + scpps_send_cmp_evt(PRF_ENV_GET(SCPPS, scpps), + KE_IDX_GET(src_id), + SCPPS_SCAN_REFRESH_SEND_CMD_OP_CODE, + p_param->status); + + ke_state_set(dest_id, SCPPS_IDLE); + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(scpps) +{ + {SCPPS_ENABLE_REQ, (ke_msg_func_t) scpps_enable_req_handler}, + {SCPPS_SCAN_REFRESH_SEND_CMD, (ke_msg_func_t) scpps_scan_refresh_send_cmd_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +void scpps_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct scpps_env_tag *p_scpps_env = PRF_ENV_GET(SCPPS, scpps); + + p_task_desc->msg_handler_tab = scpps_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(scpps_msg_handler_tab); + p_task_desc->state = p_scpps_env->state; + p_task_desc->idx_max = SCPPS_IDX_MAX; +} + +#endif /* #if (BLE_SP_SERVER) */ + +/// @} SCPPSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tip_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tip_common.h new file mode 100644 index 0000000..92eb3ba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tip_common.h @@ -0,0 +1,253 @@ +/** + **************************************************************************************** + * + * @file tip_common.h + * + * @brief Header File - Time Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _TIP_COMMON_H_ +#define _TIP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup TIP Time Profile + * @ingroup PROFILE + * @brief Time Profile + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +#include "prf_types.h" +#include +#include "prf_utils.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Adjust Reason Flags field bit values +enum tips_adj_reason_flags_bf +{ + TIPS_FLAG_MAN_TIME_UPDATE_POS = 0, + TIPS_FLAG_MAN_TIME_UPDATE_BIT = CO_BIT(TIPS_FLAG_MAN_TIME_UPDATE_POS), + + TIPS_FLAG_EXT_TIME_UPDATE_POS = 1, + TIPS_FLAG_EXT_TIME_UPDATE_BIT = CO_BIT(TIPS_FLAG_EXT_TIME_UPDATE_POS), + + TIPS_FLAG_CHG_TIME_ZONE_POS = 2, + TIPS_FLAG_CHG_TIME_ZONE_BIT = CO_BIT(TIPS_FLAG_CHG_TIME_ZONE_POS), + + TIPS_FLAG_DST_CHANGE_POS = 3, + TIPS_FLAG_DST_CHANGE_BIT = CO_BIT(TIPS_FLAG_DST_CHANGE_POS), +}; + +/// Time Update Control Point Key values +enum +{ + TIPS_TIME_UPD_CTNL_PT_GET = 0x01, + TIPS_TIME_UPD_CTNL_PT_CANCEL, +}; + +/// Time Update State Current State Key Values +enum +{ + TIPS_TIME_UPD_STATE_IDLE = 0x00, + TIPS_TIME_UPD_STATE_PENDING, +}; + +/// Time Update State Result Key Values +enum +{ + TIPS_TIME_UPD_RESULT_SUCCESS = 0x00, + TIPS_TIME_UPD_RESULT_CANCELED, + TIPS_TIME_UPD_RESULT_NO_CONN, + TIPS_TIME_UPD_RESULT_ERROR_RSP, + TIPS_TIME_UPD_RESULT_TIMEOUT, + TIPS_TIME_UPD_NOT_ATTEMPTED, +}; + +/// Time Profile Supported Features bit flags +enum +{ + /// NDCS bit + /// NDCS supported + TIPS_NDCS_SUPPORTED = 0x01, + + /// RTUS bit + /// RTUS supported + TIPS_RTUS_SUPPORTED = 0x02, +}; + +enum +{ + TIP_RD_RSP = 0x00, + TIP_NTF = 0x01, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/* + * STRUCTURES + **************************************************************************************** + */ + +/** + * Each of the following structure is related to a characteristic. + */ + +/* + * Current Time Service + */ + +///Current Time Characteristic Structure +struct tip_curr_time +{ + /// Date time + struct prf_date_time date_time; + /// Day of the week + uint8_t day_of_week; + /// 1/256th of a second + uint8_t fraction_256; + /// Adjust reason + uint8_t adjust_reason; +}; + +/** + * + * Time Zone Characteristic - UUID:0x2A0E + * Min value : -48 (UTC-12:00), Max value : 56 (UTC+14:00) + * -128 : Time zone offset is not known + */ +typedef int8_t tip_time_zone; + +/** + * DST Offset Characteristic - UUID:0x2A2D + * Min value : 0, Max value : 8 + * 255 = DST is not known + */ +typedef uint8_t tip_dst_offset; + +///Local Time Info Characteristic Structure - UUID:0x2A0F +struct tip_loc_time_info +{ + tip_time_zone time_zone; + tip_dst_offset dst_offset; +}; + +/** + * Time Source Characteristic - UUID:0x2A13 + * Min value : 0, Max value : 6 + * 0 = Unknown + * 1 = Network Time Protocol + * 2 = GPS + * 3 = Radio Time Signal + * 4 = Manual + * 5 = Atomic Clock + * 6 = Cellular Network + */ +typedef uint8_t tip_time_source; + +/** + * Time Accuracy Characteristic - UUID:0x2A12 + * Accuracy (drift) of time information in steps of 1/8 of a second (125ms) compared + * to a reference time source. Valid range from 0 to 253 (0s to 31.5s). A value of + * 254 means Accuracy is out of range (> 31.5s). A value of 255 means Accuracy is + * unknown. + */ +typedef uint8_t tip_time_accuracy; + +///Reference Time Info Characteristic Structure - UUID:0x2A14 +struct tip_ref_time_info +{ + tip_time_source time_source; + tip_time_accuracy time_accuracy; + /** + * Days since last update about Reference Source + * Min value : 0, Max value : 254 + * 255 = 255 or more days + */ + uint8_t days_update; + /** + * Hours since update about Reference Source + * Min value : 0, Mac value : 23 + * 255 = 255 or more days (If Days Since Update = 255, then Hours Since Update shall + * also be set to 255) + */ + uint8_t hours_update; +}; + +/* + * Next DST Change Service + */ +///Time With DST Characteristic Structure - UUID:0x2A11 +struct tip_time_with_dst +{ + ///Date and Time of the Next DST Change + struct prf_date_time date_time; + ///DST Offset that will be in effect after this change + tip_dst_offset dst_offset; +}; + +/* + * Reference Time Update Service + */ +/** + * Time Update Control Point Characteristic - UUID:0x2A16 + * The Time Update Control Point Characteristic enables a client to issue a command + * request to update the time in the time server. + * 0x01 = Get Reference Update = Forces the state machine to Update Pending and + * starts the time update procedure + * 0x02 = Cancel Reference Update = Forces the state machine to idle and stops the + * attempt to receive a time update. + */ +typedef uint8_t tip_time_upd_contr_pt; + +///Time Update State Characteristic Structure - UUID:0x2A17 +struct tip_time_upd_state +{ + /** + * The Time Update Status Characteristic exposes the status of the time update + * process and the result of the last update in the server. + */ + + /** + * Current State + * Min value : 0, Max value = 1 + * 0 = Idle + * 1 = Update Pending + */ + uint8_t current_state; + /** + * Result + * Min value : 0, Max Value : 5 + * 0 = Successful + * 1 = Canceled + * 2 = No Connection To Reference + * 3 = Reference responded with an error + * 4 = Timeout + * 5 = Update not attempted after reset + */ + uint8_t result; +}; + + +/// @} tip_common + +#endif /* _TIP_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/api/tipc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/api/tipc_task.h new file mode 100644 index 0000000..73cc144 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/api/tipc_task.h @@ -0,0 +1,273 @@ +/** + **************************************************************************************** + * + * @file tipc_task.h + * + * @brief Header file - Time Profile Client Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _TIPC_TASK_H_ +#define _TIPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup TIPCTASK Time Profile Client Task + * @ingroup TIPC + * @brief Time Profile Client Task + * + * The TIPCTASK is responsible for handling the messages coming in and out of the + * @ref TIPC monitor block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "tip_common.h" +#include "rwip_task.h" // Task definitions + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/*@TRACE*/ +enum tipc_msg_id +{ + /// Start the time profile - at connection + TIPC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_TIPC), + /// Confirm that cfg connection has finished with discovery results, or that normal cnx started + TIPC_ENABLE_RSP, + + /// Generic message to read a CTS, NDCS or RTUS characteristic value + TIPC_RD_CHAR_CMD, + /// Received read value + TIPC_RD_CHAR_IND, + + /// Generic message for configuring the Current Time Characteristic on the Server + TIPC_CT_NTF_CFG_CMD, + + /// Generic message for writing the Time Update Control Point Characteristic Value on a peer device + TIPC_WR_TIME_UPD_CTNL_PT_CMD, + + /// Received Current Time value (Notification) + TIPC_CT_IND, + + /// Complete Event Information + TIPC_CMP_EVT, +}; + +/// Current Time Service Characteristics +enum +{ + /// Current Time + TIPC_CHAR_CTS_CURR_TIME, + /// Local Time Info + TIPC_CHAR_CTS_LOCAL_TIME_INFO, + /// Reference Time Info + TIPC_CHAR_CTS_REF_TIME_INFO, + + TIPC_CHAR_CTS_MAX, +}; + +/// Next DST Change Service Characteristics +enum +{ + /// Time With DST + TIPC_CHAR_NDCS_TIME_WITH_DST, + + TIPC_CHAR_NDCS_MAX, + TIPC_CHAR_NDCS_MASK = 0x10, +}; + +/// Reference Time Update Service Characteristics +enum +{ + /// Time Update Control Point + TIPC_CHAR_RTUS_TIME_UPD_CTNL_PT, + /// Time Update State + TIPC_CHAR_RTUS_TIME_UPD_STATE, + + TIPC_CHAR_RTUS_MAX, + TIPC_CHAR_RTUS_MASK = 0x20, +}; + +/// Current Time Service Characteristic Descriptors +enum +{ + /// Current Time client config + TIPC_DESC_CTS_CURR_TIME_CLI_CFG, + + TIPC_DESC_CTS_MAX, + TIPC_DESC_CTS_MASK = 0x30, +}; + +/// Operation codes +enum tipc_op_codes +{ + /// Database Creation Procedure + TIPC_RESERVED_OP_CODE = 0, + /// Read char. Operation Code + TIPC_RD_CHAR_CMD_OP_CODE = 1, + /// Configure CCC of Current Time Characteristic Operation Code + TIPC_CT_NTF_CFG_CMD_OP_CODE = 2, + /// Write the Time Update Control Point Characteristic Value Operation Code + TIPC_WR_TIME_UPD_CTNL_PT_CMD_OP_CODE = 3, +}; + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Current Time Service + */ +struct tipc_cts_content +{ + /// service info + struct prf_svc svc; + + /// Characteristic info: + /// - Current Time + /// - Local Time Info + /// - Reference Time Info + struct prf_char_inf chars[TIPC_CHAR_CTS_MAX]; + + /// Descriptor handles: + /// - Current Time client cfg + struct prf_char_desc_inf descs[TIPC_DESC_CTS_MAX]; +}; + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Next DST Change Service + */ +struct tipc_ndcs_content +{ + /// service info + struct prf_svc svc; + + /// characteristic info: + /// - Time With DST + struct prf_char_inf chars[TIPC_CHAR_NDCS_MAX]; +}; + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Reference Time Update Service + */ +struct tipc_rtus_content +{ + /// service info + struct prf_svc svc; + + /// characteristic info: + /// - Time Update Control Point + /// - Time Update State + struct prf_char_inf chars[TIPC_CHAR_RTUS_MAX]; +}; + + +/// Parameters of the @ref TIPC_ENABLE_REQ message +struct tipc_enable_req +{ + /// Connection type + uint8_t con_type; + + /// Existing handle values cts + struct tipc_cts_content cts; + /// Existing handle values ndcs + struct tipc_ndcs_content ndcs; + /// Existing handle values rtus + struct tipc_rtus_content rtus; +}; + +/// Parameters of the @ref TIPC_ENABLE_RSP message +struct tipc_enable_rsp +{ + /// status + uint8_t status; + + /// Existing handle values cts + struct tipc_cts_content cts; + /// Existing handle values ndcs + struct tipc_ndcs_content ndcs; + /// Existing handle values rtus + struct tipc_rtus_content rtus; +}; + +/// Parameters of the @ref TIPC_CT_NTF_CFG_CMD message +struct tipc_ct_ntf_cfg_cmd +{ + /// Stop/notify/indicate value to configure into the peer characteristic + uint16_t cfg_val; +}; + +/// Parameters of the @ref TIPC_RD_CHAR_CMD message +struct tipc_rd_char_cmd +{ + /// Characteristic value code + uint8_t char_code; +}; + +/// Parameters of the @ref TIPC_RD_CHAR_IND message +struct tipc_rd_char_ind +{ + /// Operation code + uint8_t op_code; + + union tipc_rd_value_tag + { + /// Notification Configuration + uint16_t ntf_cfg; + /// Current Time + struct tip_curr_time curr_time; + /// Local Time Information + struct tip_loc_time_info loc_time_info; + /// Reference Time Information + struct tip_ref_time_info ref_time_info; + /// Time With DST + struct tip_time_with_dst time_with_dst; + /// Time Update State + struct tip_time_upd_state time_upd_state; + } value; +}; + +/// Parameters of the @ref TIPC_WR_TIME_UPD_CTNL_PT_CMD message +struct tipc_wr_time_upd_ctnl_pt_cmd +{ + /// Value + uint8_t value; +}; + +/// Parameters of the @ref TIPC_CT_IND message +struct tipc_ct_ind +{ + /// Current Time Value + struct tip_curr_time ct_val; +}; + +///Parameters of the @ref TIPC_CMP_EVT message +struct tipc_cmp_evt +{ + /// Operation + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} TIPCTASK + +#endif /* _TIPC_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/sourcelist.txt new file mode 100644 index 0000000..0c29b64 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + tipc.c + tipc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/src/tipc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/src/tipc.c new file mode 100644 index 0000000..431cc38 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/src/tipc.c @@ -0,0 +1,247 @@ +/** + **************************************************************************************** + * + * @file tipc.c + * + * @brief Time Profile Client implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup TIPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_TIP_CLIENT) +#include "prf.h" +#include "tipc.h" +#include "tipc_task.h" +#include "gap.h" + +#include "ke_mem.h" + +/** + **************************************************************************************** + * @brief Initialization of the TIPC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t tipc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct tipc_env_tag *p_tipc_env = + (struct tipc_env_tag *) ke_malloc(sizeof(struct tipc_env_tag), KE_MEM_ATT_DB); + + // allocate TIPC required environment variable + p_env->env = (prf_env_t *) p_tipc_env; + + p_tipc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_tipc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_TIPC; + tipc_task_init(&(p_env->desc)); + + for (idx = 0; idx < TIPC_IDX_MAX; idx++) + { + p_tipc_env->p_env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), TIPC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void tipc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct tipc_env_tag *p_tipc_env = (struct tipc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_tipc_env->p_env[conidx] != NULL) + { + ke_free(p_tipc_env->p_env[conidx]); + p_tipc_env->p_env[conidx] = NULL; + } + + // Put TIP Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), TIPC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the TIPC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void tipc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct tipc_env_tag *p_tipc_env = (struct tipc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < TIPC_IDX_MAX; idx++) + { + tipc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_tipc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void tipc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put TIP Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), TIPC_IDLE); +} + +/// TIPC Task interface required by profile manager +const struct prf_task_cbs tipc_itf = +{ + tipc_init, + tipc_destroy, + tipc_create, + tipc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* tipc_prf_itf_get(void) +{ + return &tipc_itf; +} + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +void tipc_enable_rsp_send(struct tipc_env_tag *p_tipc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on TIPS + struct tipc_enable_rsp *p_rsp = KE_MSG_ALLOC(TIPC_ENABLE_RSP, + prf_dst_task_get(&(p_tipc_env->prf_env), conidx), + prf_src_task_get(&(p_tipc_env->prf_env), conidx), + tipc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->cts = p_tipc_env->p_env[conidx]->cts; + p_rsp->ndcs = p_tipc_env->p_env[conidx]->ndcs; + p_rsp->rtus = p_tipc_env->p_env[conidx]->rtus; + + // register TIPC task in gatt for indication/notifications + prf_register_atthdl2gatt(&p_tipc_env->prf_env, conidx, &p_tipc_env->p_env[conidx]->cts.svc); + + // Go to connected state + ke_state_set(prf_src_task_get(&p_tipc_env->prf_env, conidx), TIPC_IDLE); + } + + ke_msg_send(p_rsp); +} + +void tipc_unpack_curr_time_value(struct tip_curr_time *p_curr_time_val, uint8_t *p_packed_ct) +{ + // Date-Time + prf_unpack_date_time(p_packed_ct, &(p_curr_time_val->date_time)); + + // Day of Week + p_curr_time_val->day_of_week = p_packed_ct[7]; + + // Fraction 256 + p_curr_time_val->fraction_256 = p_packed_ct[8]; + + // Adjust Reason + p_curr_time_val->adjust_reason = p_packed_ct[9]; +} + +void tipc_unpack_time_dst_value(struct tip_time_with_dst *p_time_dst_val, uint8_t *p_packed_tdst) +{ + // Date-Time + prf_unpack_date_time(p_packed_tdst, &(p_time_dst_val->date_time)); + + // DST Offset + p_time_dst_val->dst_offset = p_packed_tdst[7]; +} + +void tipc_send_cmp_evt(struct tipc_env_tag *p_tipc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct tipc_cmp_evt *p_evt; + ke_task_id_t src_id = prf_src_task_get(&(p_tipc_env->prf_env), conidx); + ke_task_id_t dest_id = prf_dst_task_get(&(p_tipc_env->prf_env), conidx); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == TIPC_BUSY) + { + ke_state_set(src_id, TIPC_IDLE); + } + + // Send the message to the application + p_evt = KE_MSG_ALLOC(TIPC_CMP_EVT, dest_id, src_id, tipc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + + +#endif /* (BLE_TIP_CLIENT) */ + +/// @} TIPC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/src/tipc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/src/tipc.h new file mode 100644 index 0000000..7119cc4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/src/tipc.h @@ -0,0 +1,195 @@ +/** + **************************************************************************************** + * + * @file tipc.h + * + * @brief Header file - Time Profile - Client Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef _TIPC_H_ +#define _TIPC_H_ + +/** + **************************************************************************************** + * @addtogroup TIPC Time Profile Client + * @ingroup TIP + * @brief Time Profile Client + * + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_TIP_CLIENT) +#include "tipc_task.h" +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Time Client task instances +#define TIPC_IDX_MAX (BLE_CONNECTION_MAX) + +/// Possible states of the TIPC task +enum +{ + /// Free state + TIPC_FREE, + /// IDLE state + TIPC_IDLE, + /// Discovering Blood Pressure SVC and CHars + TIPC_DISCOVERING, + /// Busy state + TIPC_BUSY, + + /// Number of defined states. + TIPC_STATE_MAX +}; + +/// Internal codes for reading a CTS or NDCS or RTUS characteristic with one single request +enum +{ + /// Read CTS Current Time + TIPC_RD_CTS_CURR_TIME = TIPC_CHAR_CTS_CURR_TIME, + /// Read CTS Local Time Info + TIPC_RD_CTS_LOCAL_TIME_INFO = TIPC_CHAR_CTS_LOCAL_TIME_INFO, + /// Read CTS Reference Time Info + TIPC_RD_CTS_REF_TIME_INFO = TIPC_CHAR_CTS_REF_TIME_INFO, + + /// Read CTS Current Time Client Cfg. Desc + TIPC_RD_CTS_CURR_TIME_CLI_CFG = (TIPC_DESC_CTS_MASK | TIPC_DESC_CTS_CURR_TIME_CLI_CFG), + + /// Read NDCS Time With DST + TIPC_RD_NDCS_TIME_WITH_DST = (TIPC_CHAR_NDCS_MASK | TIPC_CHAR_NDCS_TIME_WITH_DST), + + /// Read RTUS Time Update State + TIPC_RD_RTUS_TIME_UPD_STATE = (TIPC_CHAR_RTUS_MASK | TIPC_CHAR_RTUS_TIME_UPD_STATE), +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +struct tipc_cnx_env +{ + /// Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + /// Last service for which something was discovered + uint16_t last_svc_req; + /// Last characteristic code used in a read or a write request + uint16_t last_char_code; + /// Counter used to check service uniqueness + uint8_t nb_svc; + + /// Current Time Service Characteristics + struct tipc_cts_content cts; + /// Next DST Change Characteristics + struct tipc_ndcs_content ndcs; + /// Reference Time Update Characteristics + struct tipc_rtus_content rtus; +}; + + +/// Time Profile Client environment variable +struct tipc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct tipc_cnx_env *p_env[TIPC_IDX_MAX]; + /// State of different task instances + ke_state_t state[TIPC_IDX_MAX]; +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve TIP client profile interface + * @return TIP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* tipc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Time ATT DB discovery results to TIPC host. + * + * @param p_tipc_env TIP Client Role task environment + * @param conidx Connection index + * @param status Response status code + **************************************************************************************** + */ +void tipc_enable_rsp_send(struct tipc_env_tag *p_tipc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Unpack Current Time value + * + * @param[out] p_curr_time_val Pointer to unpacked Current Time value + * @param[in] p_packed_ct Pointer to the parameters of the message + **************************************************************************************** + */ +void tipc_unpack_curr_time_value(struct tip_curr_time *p_curr_time_val, uint8_t *p_packed_ct); + +/** + **************************************************************************************** + * @brief Unpack Time with DST value + * + * @param[out] p_time_dst_val Pointer to unpacked Time with DST value + * @param[in] p_packed_tdst Pointer to the parameters of the message + **************************************************************************************** + */ +void tipc_unpack_time_dst_value(struct tip_time_with_dst *p_time_dst_val, uint8_t *p_packed_tdst); + +/** + **************************************************************************************** + * @brief Send an TLPC_CMP_EVT message to a requester. + * + * @param[in] p_tipc_env TIP Client environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void tipc_send_cmp_evt(struct tipc_env_tag *p_tipc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void tipc_task_init(struct ke_task_desc *p_task_desc); + +#endif /* (BLE_TIP_CLIENT) */ + +/// @} TIPC + +#endif /* _TIPC_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/src/tipc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/src/tipc_task.c new file mode 100644 index 0000000..d0dec54 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tipc/src/tipc_task.c @@ -0,0 +1,751 @@ +/** + **************************************************************************************** + * + * @file tipc_task.c + * + * @brief Time Profile Client Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup TIPCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_TIP_CLIENT) +#include "co_utils.h" +#include "tipc_task.h" +#include "tipc.h" +#include "gap.h" +#include "attm.h" +#include "gattc_task.h" + +#include "ke_mem.h" +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/* + * DEFINES + **************************************************************************************** + */ + +/// State machine used to retrieve Current Time service characteristics information +const struct prf_char_def tipc_cts_char[TIPC_CHAR_CTS_MAX] = +{ + // Current Time + [TIPC_CHAR_CTS_CURR_TIME] = {ATT_CHAR_CT_TIME, + ATT_MANDATORY, + ATT_CHAR_PROP_RD|ATT_CHAR_PROP_NTF}, + // Local Time Info + [TIPC_CHAR_CTS_LOCAL_TIME_INFO] = {ATT_CHAR_LOCAL_TIME_INFO, + ATT_OPTIONAL, + ATT_CHAR_PROP_RD}, + // Reference Time Info + [TIPC_CHAR_CTS_REF_TIME_INFO] = {ATT_CHAR_REFERENCE_TIME_INFO, + ATT_OPTIONAL, + ATT_CHAR_PROP_RD}, +}; + +/// State machine used to retrieve Current Time service characteristic description information +const struct prf_char_desc_def tipc_cts_char_desc[TIPC_DESC_CTS_MAX] = +{ + // Current Time client config + [TIPC_DESC_CTS_CURR_TIME_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + TIPC_CHAR_CTS_CURR_TIME}, +}; + +/// State machine used to retrieve Next DST Change service characteristics information +const struct prf_char_def tipc_ndcs_char[TIPC_CHAR_NDCS_MAX] = +{ + // Current Time + [TIPC_CHAR_NDCS_TIME_WITH_DST] = {ATT_CHAR_TIME_WITH_DST, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, +}; + +/// State machine used to retrieve Reference Time Update service characteristics information +const struct prf_char_def tipc_rtus_char[TIPC_CHAR_RTUS_MAX] = +{ + // Time Update Control Point + [TIPC_CHAR_RTUS_TIME_UPD_CTNL_PT] = {ATT_CHAR_TIME_UPDATE_CNTL_POINT, + ATT_MANDATORY, + ATT_CHAR_PROP_WR_NO_RESP}, + // Time Update State + [TIPC_CHAR_RTUS_TIME_UPD_STATE] = {ATT_CHAR_TIME_UPDATE_STATE, + ATT_MANDATORY, + ATT_CHAR_PROP_RD}, +}; + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == TIPC_DISCOVERING) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + struct tipc_env_tag *p_tipc_env = PRF_ENV_GET(TIPC, tipc); + + ASSERT_INFO(p_tipc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_tipc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_CURRENT_TIME)) + { + // Retrieve TIS characteristics and descriptors + prf_extract_svc_info(p_ind, TIPC_CHAR_CTS_MAX, &tipc_cts_char[0], &p_tipc_env->p_env[conidx]->cts.chars[0], + TIPC_DESC_CTS_MAX, &tipc_cts_char_desc[0], &p_tipc_env->p_env[conidx]->cts.descs[0]); + + // Even if we get multiple responses we only store 1 range + p_tipc_env->p_env[conidx]->cts.svc.shdl = p_ind->start_hdl; + p_tipc_env->p_env[conidx]->cts.svc.ehdl = p_ind->end_hdl; + } + + if (attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_NEXT_DST_CHANGE)) + { + // Retrieve NDCS characteristics and descriptors + prf_extract_svc_info(p_ind, TIPC_CHAR_NDCS_MAX, &tipc_ndcs_char[0], &p_tipc_env->p_env[conidx]->ndcs.chars[0], + 0, NULL, NULL); + + //Even if we get multiple responses we only store 1 range + p_tipc_env->p_env[conidx]->ndcs.svc.shdl = p_ind->start_hdl; + p_tipc_env->p_env[conidx]->ndcs.svc.ehdl = p_ind->end_hdl; + } + + if (attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_REF_TIME_UPDATE)) + { + // Retrieve RTUS characteristics and descriptors + prf_extract_svc_info(p_ind, TIPC_CHAR_RTUS_MAX, &tipc_rtus_char[0], &p_tipc_env->p_env[conidx]->rtus.chars[0], + 0, NULL, NULL); + + //Even if we get multiple responses we only store 1 range + p_tipc_env->p_env[conidx]->rtus.svc.shdl = p_ind->start_hdl; + p_tipc_env->p_env[conidx]->rtus.svc.ehdl = p_ind->end_hdl; + } + + // Increment number of services + p_tipc_env->p_env[conidx]->nb_svc++; + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref TIPC_ENABLE_REQ message. + * The handler enables the Time Profile Client Role. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int tipc_enable_req_handler(ke_msg_id_t const msgid, + struct tipc_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Get state + uint8_t state = ke_state_get(dest_id); + + // Time Service Client Role Task Environment + struct tipc_env_tag *p_tipc_env = PRF_ENV_GET(TIPC, tipc); + + ASSERT_INFO(p_tipc_env != NULL, dest_id, src_id); + if ((state == TIPC_IDLE) && (p_tipc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_tipc_env->p_env[conidx] = (struct tipc_cnx_env *) ke_malloc(sizeof(struct tipc_cnx_env), KE_MEM_ATT_DB); + memset(p_tipc_env->p_env[conidx], 0, sizeof(struct tipc_cnx_env)); + + // config connection, start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + // start discovering CTS on peer + prf_disc_svc_send(&(p_tipc_env->prf_env), conidx, ATT_SVC_CURRENT_TIME); + + p_tipc_env->p_env[conidx]->last_uuid_req = ATT_SVC_CURRENT_TIME; + p_tipc_env->p_env[conidx]->last_svc_req = ATT_SVC_CURRENT_TIME; + + // Go to DISCOVERING state + ke_state_set(dest_id, TIPC_DISCOVERING); + } + // normal connection, get saved att details + else + { + p_tipc_env->p_env[conidx]->cts = p_param->cts; + p_tipc_env->p_env[conidx]->ndcs = p_param->ndcs; + p_tipc_env->p_env[conidx]->rtus = p_param->rtus; + + // send APP confirmation that can start normal connection + tipc_enable_rsp_send(p_tipc_env, conidx, GAP_ERR_NO_ERROR); + } + } + + else if (state != TIPC_FREE) + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // send an error if request fails + if (status != GAP_ERR_NO_ERROR) + { + tipc_enable_rsp_send(p_tipc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref TIPC_RD_CHAR_CMD message. + * Check if the handle exists in profile(already discovered) and send request, otherwise + * error to APP. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int tipc_rd_char_cmd_handler(ke_msg_id_t const msgid, + struct tipc_rd_char_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t status = GAP_ERR_NO_ERROR; + + // Get the address of the environment + struct tipc_env_tag *p_tipc_env = PRF_ENV_GET(TIPC, tipc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if ((ke_state_get(dest_id) == TIPC_IDLE) && (p_tipc_env->p_env[conidx] != NULL)) + { + // Service + struct prf_svc *p_svc = NULL; + // Attribute Handle + uint16_t search_hdl = ATT_INVALID_SEARCH_HANDLE; + + // Next DST Change Service Characteristic + if (((p_param->char_code & TIPC_CHAR_NDCS_MASK) == TIPC_CHAR_NDCS_MASK) && + ((p_param->char_code & ~TIPC_CHAR_NDCS_MASK) < TIPC_CHAR_NDCS_MAX)) + { + p_svc = &p_tipc_env->p_env[conidx]->ndcs.svc; + search_hdl = p_tipc_env->p_env[conidx]->ndcs. + chars[p_param->char_code & ~TIPC_CHAR_NDCS_MASK].val_hdl; + } + // Reference Time Update Service Characteristic + else if (((p_param->char_code & TIPC_CHAR_RTUS_MASK) == TIPC_CHAR_RTUS_MASK) && + ((p_param->char_code & ~TIPC_CHAR_RTUS_MASK) < TIPC_CHAR_RTUS_MAX)) + { + p_svc = &p_tipc_env->p_env[conidx]->rtus.svc; + search_hdl = p_tipc_env->p_env[conidx]->rtus. + chars[p_param->char_code & ~TIPC_CHAR_RTUS_MASK].val_hdl; + } + else + { + p_svc = &p_tipc_env->p_env[conidx]->cts.svc; + + // Current Time Characteristic Descriptor + if (((p_param->char_code & TIPC_DESC_CTS_MASK) == TIPC_DESC_CTS_MASK) && + ((p_param->char_code & ~TIPC_DESC_CTS_MASK) < TIPC_DESC_CTS_MAX)) + { + search_hdl = p_tipc_env->p_env[conidx]->cts. + descs[p_param->char_code & ~TIPC_DESC_CTS_MASK].desc_hdl; + } + // Current Time Service Characteristic + else if (p_param->char_code < TIPC_CHAR_CTS_MAX) + { + search_hdl = p_tipc_env->p_env[conidx]->cts. + chars[p_param->char_code].val_hdl; + } + } + + // Check if handle is viable + if ((search_hdl != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Save char code + p_tipc_env->p_env[conidx]->last_char_code = p_param->char_code; + // Send read request + prf_read_char_send(&(p_tipc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + + ke_state_set(dest_id, TIPC_BUSY); + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_REQ_DISALLOWED; + } + + if (status != GAP_ERR_NO_ERROR) + { + tipc_send_cmp_evt(p_tipc_env, conidx, TIPC_RD_CHAR_CMD_OP_CODE, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref TIPC_CT_NTF_CFG_CMD message. + * It allows configuration of the peer ind/ntf/stop characteristic for a specified characteristic. + * Will return an error code if that cfg char does not exist. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int tipc_ct_ntf_cfg_cmd_handler(ke_msg_id_t const msgid, + struct tipc_ct_ntf_cfg_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct tipc_env_tag *p_tipc_env = PRF_ENV_GET(TIPC, tipc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if ((p_tipc_env->p_env[conidx] != NULL) && (ke_state_get(dest_id) == TIPC_IDLE)) + { + // Only NTF + if ((p_param->cfg_val == PRF_CLI_STOP_NTFIND) || (p_param->cfg_val == PRF_CLI_START_NTF)) + { + uint16_t cfg_hdl = p_tipc_env->p_env[conidx]->cts.descs[TIPC_DESC_CTS_CURR_TIME_CLI_CFG].desc_hdl; + + // check if the handle value exists + if (cfg_hdl != ATT_INVALID_SEARCH_HANDLE) + { + // Send GATT Write Request + prf_gatt_write_ntf_ind(&p_tipc_env->prf_env, conidx, cfg_hdl, p_param->cfg_val); + status = GAP_ERR_NO_ERROR; + + ke_state_set(dest_id, TIPC_BUSY); + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + tipc_send_cmp_evt(p_tipc_env, conidx, TIPC_CT_NTF_CFG_CMD_OP_CODE, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref TIPC_WR_TIME_UPD_CTNL_PT_CMD message. + * Check if the handle exists in profile(already discovered) and send request, otherwise + * error to APP. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int tipc_wr_time_upd_ctnl_pt_cmd_handler(ke_msg_id_t const msgid, + struct tipc_wr_time_upd_ctnl_pt_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct tipc_env_tag *p_tipc_env = PRF_ENV_GET(TIPC, tipc); + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if ((ke_state_get(dest_id) == TIPC_IDLE) && (p_tipc_env->p_env[conidx] != NULL)) + { + // Check provided parameters + if ((p_param->value == TIPS_TIME_UPD_CTNL_PT_GET) || + (p_param->value == TIPS_TIME_UPD_CTNL_PT_CANCEL)) + { + if (p_tipc_env->p_env[conidx]->cts.chars[TIPC_CHAR_RTUS_TIME_UPD_CTNL_PT].char_hdl != + ATT_INVALID_SEARCH_HANDLE) + { + // Send GATT Write Request + prf_gatt_write(&p_tipc_env->prf_env, conidx, + p_tipc_env->p_env[conidx]->rtus.chars[TIPC_CHAR_RTUS_TIME_UPD_CTNL_PT].val_hdl, + (uint8_t *)&p_param->value, sizeof(uint8_t), GATTC_WRITE_NO_RESPONSE); + + status = GAP_ERR_NO_ERROR; + + ke_state_set(dest_id, TIPC_BUSY); + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + tipc_send_cmp_evt(p_tipc_env, conidx, TIPC_WR_TIME_UPD_CTNL_PT_CMD_OP_CODE, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * This generic event is received for different requests, so need to keep track. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t status = PRF_ERR_STOP_DISC_CHAR_MISSING; + bool finished = false; + + // Get the address of the environment + struct tipc_env_tag *p_tipc_env = PRF_ENV_GET(TIPC, tipc); + + if ((state == TIPC_DISCOVERING) && (p_tipc_env->p_env[conidx] != NULL)) + { + if ((p_param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)|| + (p_param->status == ATT_ERR_NO_ERROR)) + { + // check characteristic validity + if (p_tipc_env->p_env[conidx]->nb_svc <= 1) + { + switch (p_tipc_env->p_env[conidx]->last_svc_req) + { + case ATT_SVC_CURRENT_TIME: + { + // Check service (mandatory) + status = prf_check_svc_char_validity(TIPC_CHAR_CTS_MAX, + p_tipc_env->p_env[conidx]->cts.chars, + tipc_cts_char); + + // Check Descriptors (mandatory) + if (status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(TIPC_DESC_CTS_MAX, + p_tipc_env->p_env[conidx]->cts.descs, + tipc_cts_char_desc, + p_tipc_env->p_env[conidx]->cts.chars); + // Prepare to discovery next service + p_tipc_env->p_env[conidx]->last_svc_req = ATT_SVC_NEXT_DST_CHANGE; + } + } break; + + case ATT_SVC_NEXT_DST_CHANGE: + { + // Check service (if found) + if (p_tipc_env->p_env[conidx]->nb_svc) + { + status = prf_check_svc_char_validity(TIPC_CHAR_NDCS_MAX, + p_tipc_env->p_env[conidx]->ndcs.chars, + tipc_ndcs_char); + } + else + { + status = GAP_ERR_NO_ERROR; + } + // Prepare to discovery next service + p_tipc_env->p_env[conidx]->last_svc_req = ATT_SVC_REF_TIME_UPDATE; + } break; + + case ATT_SVC_REF_TIME_UPDATE: + { + // Check service (if found) + if (p_tipc_env->p_env[conidx]->nb_svc) + { + status = prf_check_svc_char_validity(TIPC_CHAR_RTUS_MAX, + p_tipc_env->p_env[conidx]->rtus.chars, + tipc_rtus_char); + } + else + { + status = GAP_ERR_NO_ERROR; + } + + if (status == GAP_ERR_NO_ERROR) + { + // send app the details about the discovered TIPS DB to save + tipc_enable_rsp_send(p_tipc_env, conidx, GAP_ERR_NO_ERROR); + // Discovery is finished + finished = true; + } + } break; + + default: + { + + } break; + } + } + // too many services + else + { + status = PRF_ERR_MULTIPLE_SVC; + } + + if (status == GAP_ERR_NO_ERROR) + { + // reset number of services + p_tipc_env->p_env[conidx]->nb_svc = 0; + + if (!finished) + { + // start discovering following service on peer + prf_disc_svc_send(&(p_tipc_env->prf_env), conidx, p_tipc_env->p_env[conidx]->last_svc_req); + } + } + else + { + // stop discovery procedure + tipc_enable_rsp_send(p_tipc_env, conidx, status); + } + } + } + else if (state == TIPC_BUSY) + { + switch (p_param->operation) + { + case GATTC_WRITE: + { + tipc_send_cmp_evt(p_tipc_env, conidx, TIPC_CT_NTF_CFG_CMD_OP_CODE, p_param->status); + } break; + + case GATTC_READ: + { + tipc_send_cmp_evt(p_tipc_env, conidx, TIPC_RD_CHAR_CMD_OP_CODE, p_param->status); + } break; + + case GATTC_WRITE_NO_RESPONSE: + { + tipc_send_cmp_evt(p_tipc_env, conidx, TIPC_WR_TIME_UPD_CTNL_PT_CMD_OP_CODE, p_param->status); + } break; + + default: + { + + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct tipc_env_tag *p_tipc_env = PRF_ENV_GET(TIPC, tipc); + uint8_t conidx = KE_IDX_GET(dest_id); + + // Build the message + struct tipc_rd_char_ind *p_ind = KE_MSG_ALLOC( + TIPC_RD_CHAR_IND, + prf_dst_task_get(&(p_tipc_env->prf_env), conidx), + dest_id, + tipc_rd_char_ind); + + // Current Time Characteristic + if (p_tipc_env->p_env[conidx]->last_char_code == TIPC_RD_CTS_CURR_TIME) + { + p_ind->op_code = TIPC_RD_CTS_CURR_TIME; + // Unpack Current Time Value. + tipc_unpack_curr_time_value(&(p_ind->value.curr_time), (uint8_t *) p_param->value); + } + // Local Time Information Characteristic + else if (p_tipc_env->p_env[conidx]->last_char_code == TIPC_RD_CTS_LOCAL_TIME_INFO) + { + p_ind->op_code = TIPC_RD_CTS_LOCAL_TIME_INFO; + // Local Time Information Value + p_ind->value.loc_time_info.time_zone = p_param->value[0]; + p_ind->value.loc_time_info.dst_offset = p_param->value[1]; + } + // Reference Time Information Characteristic + else if (p_tipc_env->p_env[conidx]->last_char_code == TIPC_RD_CTS_REF_TIME_INFO) + { + p_ind->op_code = TIPC_RD_CTS_REF_TIME_INFO; + // Reference Time Information Value + p_ind->value.ref_time_info.time_source = p_param->value[0]; + p_ind->value.ref_time_info.time_accuracy = p_param->value[1]; + p_ind->value.ref_time_info.days_update = p_param->value[2]; + p_ind->value.ref_time_info.hours_update = p_param->value[3]; + } + // Time with DST Characteristic + else if (p_tipc_env->p_env[conidx]->last_char_code == TIPC_RD_NDCS_TIME_WITH_DST) + { + p_ind->op_code = TIPC_RD_NDCS_TIME_WITH_DST; + // Time with DST Value + tipc_unpack_time_dst_value(&p_ind->value.time_with_dst, (uint8_t *) p_param->value); + } + // Time Update State Characteristic + else if (p_tipc_env->p_env[conidx]->last_char_code == TIPC_RD_RTUS_TIME_UPD_STATE) + { + p_ind->op_code = TIPC_RD_RTUS_TIME_UPD_STATE; + // Reference Time Information Value + p_ind->value.time_upd_state.current_state = p_param->value[0]; + p_ind->value.time_upd_state.result = p_param->value[1]; + } + // Current Time Characteristic - Client Characteristic Configuration Descriptor + else if (p_tipc_env->p_env[conidx]->last_char_code == TIPC_RD_CTS_CURR_TIME_CLI_CFG) + { + p_ind->op_code = TIPC_RD_CTS_CURR_TIME_CLI_CFG; + // Notification Configuration + memcpy(&p_ind->value.ntf_cfg, &p_param->value[0], sizeof(uint16_t)); + } + + ke_msg_send(p_ind); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct tipc_env_tag *p_tipc_env = PRF_ENV_GET(TIPC, tipc); + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_tipc_env->p_env[conidx] != NULL) + { + if (p_param->handle == p_tipc_env->p_env[conidx]->cts.chars[TIPC_CHAR_CTS_CURR_TIME].val_hdl) + { + // Build a TIPC_CT_IND message + struct tipc_ct_ind *p_ind = KE_MSG_ALLOC( + TIPC_CT_IND, + prf_dst_task_get(&(p_tipc_env->prf_env), conidx), + prf_src_task_get(&(p_tipc_env->prf_env), conidx), + tipc_ct_ind); + + // Unpack Current Time Value. + tipc_unpack_curr_time_value(&(p_ind->ct_val), (uint8_t*) p_param->value); + + ke_msg_send(p_ind); + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(tipc) +{ + {TIPC_ENABLE_REQ, (ke_msg_func_t)tipc_enable_req_handler}, + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + {TIPC_CT_NTF_CFG_CMD, (ke_msg_func_t)tipc_ct_ntf_cfg_cmd_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {TIPC_RD_CHAR_CMD, (ke_msg_func_t)tipc_rd_char_cmd_handler}, + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {TIPC_WR_TIME_UPD_CTNL_PT_CMD, (ke_msg_func_t)tipc_wr_time_upd_ctnl_pt_cmd_handler}, +}; + +void tipc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct tipc_env_tag *p_tipc_env = PRF_ENV_GET(TIPC, tipc); + + p_task_desc->msg_handler_tab = tipc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(tipc_msg_handler_tab); + p_task_desc->state = p_tipc_env->state; + p_task_desc->idx_max = TIPC_IDX_MAX; +} + +#endif /* (BLE_TIP_CLIENT) */ +/// @} TIPCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/api/tips_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/api/tips_task.h new file mode 100644 index 0000000..d5a3832 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/api/tips_task.h @@ -0,0 +1,174 @@ +/** + **************************************************************************************** + * + * @file tips_task.h + * + * @brief Header file - TIPSTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef TIPS_TASK_H_ +#define TIPS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup TIPSTASK Task + * @ingroup TIPS + * @brief Time Profile Server Task + * + * The TIPSTASK is responsible for handling the messages coming in and out of the + * @ref TIPS reporter block of the BLE Host. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "tip_common.h" +#include "rwip_task.h" // Task definitions + +/* + * DEFINES + **************************************************************************************** + */ + + +/// Messages for Time Profile Server +/*@TRACE*/ +enum tips_msg_id +{ + /// Start the Time Profile Server Role - at connection + TIPS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_TIPS), + /// Inform the application about the task creation result + TIPS_ENABLE_RSP, + + /// Update Current Time Request from APP + TIPS_UPD_CURR_TIME_CMD, + + /// Inform APP about a requested read + TIPS_RD_REQ_IND, + /// Read request Response + TIPS_RD_CFM, + + /// Inform APP about modification of Current Time Characteristic Client. Charact. Cfg + TIPS_CURRENT_TIME_CCC_IND, + /// Inform APP about modification of Time Update Control Point Characteristic Value + TIPS_TIME_UPD_CTNL_PT_IND, + /// Complete Event Information + TIPS_CMP_EVT +}; + +/// Operation codes +enum tips_op_codes +{ + /// Database Creation Procedure + TIPS_RESERVED_OP_CODE = 0, + /// Current Time notify Operation Code + TIPS_UPD_CURR_TIME_CMD_OP_CODE = 1, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the @ref TIPS_ENABLE_REQ message +struct tips_enable_req +{ + /// Current Time notification configuration + uint16_t current_time_ntf_en; +}; + +/// Parameters of the @ref TIPS_ENABLE_RSP message +struct tips_enable_rsp +{ + /// Status + uint8_t status; +}; + +/// Parameters of the @ref TIPS_UPD_CURR_TIME_CMD message +struct tips_upd_curr_time_cmd +{ + /// Current Time + struct tip_curr_time current_time; + /** + * Indicate if the new Current Time value can be sent if the current_time_ntf_en parameter is + * set to 1. + * (0 - Disable; 1- Enable) + * + * If the time of the Current Time Server is changed because of reference time update (adjust reason) + * then no notifications shall be sent to the Current Time Service Client within the 15 minutes from + * the last notification, unless one of both of the two statements below are true : + * - The new time information differs by more than 1min from the Current Time Server + * time previous to the update + * - The update was caused by the client (interacting with another service) + */ + uint8_t enable_ntf_send; +}; + +/// Parameters of the @ref TIPS_RD_REQ_IND message +struct tips_rd_req_ind +{ + /// Characteristic code + uint8_t char_code; +}; + +/// Parameters of the @ref TIPS_RD_CFM message +struct tips_rd_cfm +{ + uint8_t op_code; + + union tips_rd_value_tag + { + /// Current Time + struct tip_curr_time curr_time; + /// Local Time Information + struct tip_loc_time_info loc_time_info; + /// Reference Time Information + struct tip_ref_time_info ref_time_info; + /// Time With DST + struct tip_time_with_dst time_with_dst; + /// Time Update State + struct tip_time_upd_state time_upd_state; + } value; +}; + +/// Parameters of the @ref TIPS_CURRENT_TIME_CCC_IND message +struct tips_current_time_ccc_ind +{ + /// Configuration Value + uint16_t cfg_val; +}; + +/// Parameters of the @ref TIPS_TIME_UPD_CTNL_PT_IND message +struct tips_time_upd_ctnl_pt_ind +{ + /// Time Update Control Point Value + tip_time_upd_contr_pt value; +}; + +/// Parameters of the @ref TIPS_CMP_EVT message +struct tips_cmp_evt +{ + /// Operation + uint8_t operation; + /// Status + uint8_t status; +}; + +/// Parameters of the @ref TIPS_CREATE_DB_REQ message +struct tips_db_cfg +{ + /// Database configuration + uint8_t features; +}; + +/// @} TIPSTASK +#endif // TIPS_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/sourcelist.txt new file mode 100644 index 0000000..0ae5fa1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2015 +# +#*************************************************************************************** + + tips.c + tips_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/src/tips.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/src/tips.c new file mode 100644 index 0000000..6e17830 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/src/tips.c @@ -0,0 +1,371 @@ +/** + **************************************************************************************** + * + * @file tips.c + * + * @brief Time Profile Server implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup TIPS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_TIP_SERVER) +#include "attm.h" +#include "tips.h" +#include "tips_task.h" +#include "prf_utils.h" +#include "co_utils.h" + + +#include "ke_mem.h" + +/* + * CTS, NDCS, RTUS ATTRIBUTES + **************************************************************************************** + */ +/// Full CTS Database Description - Used to add attributes into the database +const struct attm_desc cts_att_db[CTS_IDX_NB] = +{ + // Current Time Service Declaration + [CTS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Current Time Characteristic Declaration + [CTS_IDX_CURRENT_TIME_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Current Time Characteristic Value + [CTS_IDX_CURRENT_TIME_VAL] = {ATT_CHAR_CT_TIME, PERM(RD, ENABLE) | PERM(NTF, ENABLE), PERM(RI, ENABLE), CTS_CURRENT_TIME_VAL_LEN}, + // Current Time Characteristic - Client Char. Configuration Descriptor + [CTS_IDX_CURRENT_TIME_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + // Local Time Information Characteristic Declaration + [CTS_IDX_LOCAL_TIME_INFO_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Local Time Information Characteristic Value + [CTS_IDX_LOCAL_TIME_INFO_VAL] = {ATT_CHAR_LOCAL_TIME_INFO, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(struct tip_loc_time_info)}, + + // Reference Time Information Characteristic Declaration + [CTS_IDX_REF_TIME_INFO_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Reference Time Info Characteristic Value + [CTS_IDX_REF_TIME_INFO_VAL] = {ATT_CHAR_REFERENCE_TIME_INFO, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(struct tip_ref_time_info)}, +}; + +/// Full NDCS Database Description - Used to add attributes into the database +const struct attm_desc ndcs_att_db[NDCS_IDX_NB] = +{ + // Next DST Change Service Declaration + [NDCS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Time with DST Characteristic Declaration + [NDCS_IDX_TIME_DST_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Time With DST Characteristic Value + [NDCS_IDX_TIME_DST_VAL] = {ATT_CHAR_TIME_WITH_DST, PERM(RD, ENABLE), PERM(RI, ENABLE), NDCS_TIME_DST_VAL_LEN}, +}; + +/// Full RTUS Database Description - Used to add attributes into the database +const struct attm_desc rtus_att_db[RTUS_IDX_NB] = +{ + // Reference Time Information Service Declaration + [RTUS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + + // Time Update Control Point Characteristic Declaration + [RTUS_IDX_TIME_UPD_CTNL_PT_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Time Update Control Point Characteristic Value + [RTUS_IDX_TIME_UPD_CTNL_PT_VAL] = {ATT_CHAR_TIME_UPDATE_CNTL_POINT, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE), sizeof(tip_time_upd_contr_pt)}, + + // Time Update State Characteristic Declaration + [RTUS_IDX_TIME_UPD_STATE_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // Time Update State Characteristic Value + [RTUS_IDX_TIME_UPD_STATE_VAL] = {ATT_CHAR_TIME_UPDATE_STATE, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(struct tip_time_upd_state)}, +}; + + +/** + **************************************************************************************** + * @brief Initialization of the TIPS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t tips_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct tips_db_cfg *p_params) +{ + // Service content flag + uint32_t cfg_flag= TIPS_CTS_CURRENT_TIME_MASK; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + // Total number of attributes + uint8_t tot_nb_att = CTS_IDX_NB; + + // Allocate TIPS required environment variable + struct tips_env_tag *p_tips_env = + (struct tips_env_tag *) ke_malloc(sizeof(struct tips_env_tag), KE_MEM_ATT_DB); + + p_env->env = (prf_env_t *) p_tips_env; + + //------------------ create the attribute database for the profile ------------------- + + // Check supported attributes + if (GETB(p_params->features, TIPS_NDCS_SUP)) + { + tot_nb_att += NDCS_IDX_NB; + } + + if (GETB(p_params->features, TIPS_RTUS_SUP)) + { + tot_nb_att += RTUS_IDX_NB; + } + + // Check that attribute list can be allocated. + status = attm_reserve_handle_range(p_start_hdl, tot_nb_att); + + if (status == ATT_ERR_NO_ERROR) + { + // Set Configuration Flag Value + if (GETB(p_params->features, TIPS_CTS_LOC_TIME_INFO_SUP)) + { + cfg_flag |= TIPS_CTS_LOC_TIME_INFO_MASK; + } + + if (GETB(p_params->features, TIPS_CTS_REF_TIME_INFO_SUP)) + { + cfg_flag |= TIPS_CTS_REF_TIME_INFO_MASK; + } + + /*---------------------------------------------------* + * Current Time Service Creation + *---------------------------------------------------*/ + status = attm_svc_create_db(p_start_hdl, ATT_SVC_CURRENT_TIME, (uint8_t *)&cfg_flag, + CTS_IDX_NB, &p_tips_env->cts_att_tbl[0], p_env->task, &cts_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, ENABLE)); + + // Update index + p_tips_env->cts_shdl = *p_start_hdl; + *p_start_hdl += CTS_IDX_NB; + + // All attributes are mandatory for NDCS and RTUS + cfg_flag = 0xFF; + + if ((status == ATT_ERR_NO_ERROR) && (GETB(p_params->features, TIPS_NDCS_SUP))) + { + /*---------------------------------------------------* + * Next DST Change Service Creation + *---------------------------------------------------*/ + status = attm_svc_create_db(p_start_hdl, ATT_SVC_NEXT_DST_CHANGE, (uint8_t *)&cfg_flag, + NDCS_IDX_NB, &p_tips_env->ndcs_att_tbl[0], p_env->task, &ndcs_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, ENABLE)); + + // Update index + p_tips_env->ndcs_shdl = *p_start_hdl; + *p_start_hdl += NDCS_IDX_NB; + } + + /*---------------------------------------------------* + * Reference Time Update Service Creation + *---------------------------------------------------*/ + if ((status == ATT_ERR_NO_ERROR) && (GETB(p_params->features, TIPS_RTUS_SUP))) + { + status = attm_svc_create_db(p_start_hdl, ATT_SVC_REF_TIME_UPDATE, (uint8_t *)&cfg_flag, + RTUS_IDX_NB, &p_tips_env->rtus_att_tbl[0], p_env->task, &rtus_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, ENABLE)); + + // Update index + p_tips_env->rtus_shdl = *p_start_hdl; + *p_start_hdl += RTUS_IDX_NB; + } + + // Initialize TIPS environment + p_tips_env->features = p_params->features; + + p_tips_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Multi Instantiated task + p_tips_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_TIPS; + tips_task_init(&(p_env->desc)); + + for (uint8_t idx = 0; idx < BLE_CONNECTION_MAX; idx++) + { + p_tips_env->p_env[idx] = NULL; + } + + // Put TIS in disabled state + ke_state_set(p_env->task, TIPS_IDLE); + } + + return (status); +} + +/** + **************************************************************************************** + * @brief Destruction of the TIPS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void tips_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct tips_env_tag* p_tips_env = (struct tips_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < BLE_CONNECTION_MAX; idx++) + { + if (p_tips_env->p_env[idx] != NULL) + { + ke_free(p_tips_env->p_env[idx]); + } + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_tips_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void tips_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct tips_env_tag *p_tips_env = (struct tips_env_tag *) p_env->env; + + p_tips_env->p_env[conidx] = (struct tips_cnx_env *) + ke_malloc(sizeof(struct tips_cnx_env), KE_MEM_ATT_DB); + + memset(p_tips_env->p_env[conidx], 0, sizeof(struct tips_cnx_env)); + + // Put TIS in idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), TIPS_IDLE); +} + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void tips_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct tips_env_tag *p_tips_env = (struct tips_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_tips_env->p_env[conidx] != NULL) + { + ke_free(p_tips_env->p_env[conidx]); + p_tips_env->p_env[conidx] = NULL; + } +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// TIPS Task interface required by profile manager +const struct prf_task_cbs tips_itf = +{ + (prf_init_fnct) tips_init, + tips_destroy, + tips_create, + tips_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs *tips_prf_itf_get(void) +{ + return &tips_itf; +} + +uint8_t tips_pack_curr_time_value(uint8_t *p_pckd_time, const struct tip_curr_time *p_curr_time_val) +{ + // Date-Time + prf_pack_date_time(p_pckd_time, &(p_curr_time_val->date_time)); + + //Day of Week + *(p_pckd_time + 7) = p_curr_time_val->day_of_week; + + //Fraction 256 + *(p_pckd_time + 8) = p_curr_time_val->fraction_256; + + //Adjust Reason + *(p_pckd_time + 9) = p_curr_time_val->adjust_reason; + + return 10; +} + +uint8_t tips_pack_time_dst_value(uint8_t *p_pckd_time_dst, const struct tip_time_with_dst *p_time_dst_val) +{ + // Date-Time + prf_pack_date_time(p_pckd_time_dst, &(p_time_dst_val->date_time)); + + // DST Offset + *(p_pckd_time_dst + 7) = p_time_dst_val->dst_offset; + + return 8; +} + +void tips_send_cmp_evt(struct tips_env_tag *p_tips_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct tips_cmp_evt *p_evt; + ke_task_id_t src_id = prf_src_task_get(&(p_tips_env->prf_env), conidx); + ke_task_id_t dest_id = prf_dst_task_get(&(p_tips_env->prf_env), conidx); + + // Come back to the Connected state if the state was busy. + if (ke_state_get(src_id) == TIPS_BUSY) + { + ke_state_set(src_id, TIPS_IDLE); + } + + // Send the message to the application + p_evt = KE_MSG_ALLOC(TIPS_CMP_EVT, dest_id, src_id, tips_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //BLE_TIP_SERVER + +/// @} TIPS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/src/tips.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/src/tips.h new file mode 100644 index 0000000..b3e116b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/src/tips.h @@ -0,0 +1,300 @@ +/** + **************************************************************************************** + * + * @file tips.h + * + * @brief Header file - Time Profile Server. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef TIPS_H_ +#define TIPS_H_ + +/** + **************************************************************************************** + * @addtogroup TIPS Time Profile Server + * @ingroup TIP + * @brief Time Profile Server + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_TIP_SERVER) +#include +#include + +#include "tip_common.h" +#include "prf_types.h" +#include "gap.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Time Server task instances +#define TIPS_IDX_MAX (BLE_CONNECTION_MAX) + +/// CTS Configuration Flag Masks +#define TIPS_CTS_CURRENT_TIME_MASK (0x0F) +#define TIPS_CTS_LOC_TIME_INFO_MASK (0x30) +#define TIPS_CTS_REF_TIME_INFO_MASK (0xC0) + +/// Packed Values Length +#define CTS_CURRENT_TIME_VAL_LEN (10) +#define NDCS_TIME_DST_VAL_LEN (8) + +/* + * MACROS + **************************************************************************************** + */ + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the TIPS task +enum +{ + /// idle state + TIPS_IDLE, + /// connected state + TIPS_BUSY, + + /// Number of defined states. + TIPS_STATE_MAX +}; + +/// Database Configuration - Bit Field Flags +enum tips_db_config_bf +{ + /// Current Time Service Local Time Information char. support bit + TIPS_CTS_LOC_TIME_INFO_SUP_POS = 0, + TIPS_CTS_LOC_TIME_INFO_SUP_BIT = CO_BIT(TIPS_CTS_LOC_TIME_INFO_SUP_POS), + + /// Current Time Service Reference Time Information char. support bit + TIPS_CTS_REF_TIME_INFO_SUP_POS = 1, + TIPS_CTS_REF_TIME_INFO_SUP_BIT = CO_BIT(TIPS_CTS_REF_TIME_INFO_SUP_POS), + + /// Next DST Change Service support bit + TIPS_NDCS_SUP_POS = 2, + TIPS_NDCS_SUP_BIT = CO_BIT(TIPS_NDCS_SUP_POS), + + /// Reference Time Update Service support bit + TIPS_RTUS_SUP_POS = 3, + TIPS_RTUS_SUP_BIT = CO_BIT(TIPS_RTUS_SUP_POS), + + /// Current Time Service Current Time Configuration support bit + TIPS_CTS_CURRENT_TIME_CFG_POS = 4, + TIPS_CTS_CURRENT_TIME_CFG_BIT = CO_BIT(TIPS_CTS_CURRENT_TIME_CFG_POS), +}; + +/// CTS Attributes code +enum +{ + CTS_IDX_SVC, + + CTS_IDX_CURRENT_TIME_CHAR, + CTS_IDX_CURRENT_TIME_VAL, + CTS_IDX_CURRENT_TIME_CFG, + + CTS_IDX_LOCAL_TIME_INFO_CHAR, + CTS_IDX_LOCAL_TIME_INFO_VAL, + + CTS_IDX_REF_TIME_INFO_CHAR, + CTS_IDX_REF_TIME_INFO_VAL, + + CTS_IDX_NB, +}; + +/// NDCS Attributes code +enum +{ + NDCS_IDX_SVC, + NDCS_IDX_TIME_DST_CHAR, + NDCS_IDX_TIME_DST_VAL, + + NDCS_IDX_NB, +}; + +/// RTUS Attributes code +enum +{ + RTUS_IDX_SVC, + RTUS_IDX_TIME_UPD_CTNL_PT_CHAR, + RTUS_IDX_TIME_UPD_CTNL_PT_VAL, + RTUS_IDX_TIME_UPD_STATE_CHAR, + RTUS_IDX_TIME_UPD_STATE_VAL, + + RTUS_IDX_NB, +}; + +/// CTS Char. code +enum +{ + CTS_CURRENT_TIME_CHAR, + CTS_LOCAL_TIME_INFO_CHAR, + CTS_REF_TIME_INFO_CHAR, + + CTS_CHAR_MAX, +}; + +/// NDCS Char. code +enum +{ + NDCS_TIME_DST_CHAR, + + NDCS_CHAR_MAX, +}; + +/// RTUS Char. code +enum +{ + RTUS_TIME_UPD_CTNL_PT_CHAR, + RTUS_TIME_UPD_STATE_CHAR, + + RTUS_CHAR_MAX, +}; + +/// Read char. Op code +enum +{ + TIPS_CTS_CURRENT_TIME, + TIPS_CTS_LOCAL_TIME_INFO, + TIPS_CTS_REF_TIME_INFO, + TIPS_NDCS_TIME_DST, + TIPS_RTUS_TIME_UPD_STATE_VAL, + TIPS_CTS_CURRENT_TIME_CLI +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Time Profile Server Instance Environment variable +struct tips_cnx_env +{ + /// NTF State + uint8_t ntf_state; + /// Saved read handle + uint16_t handle; +}; + + +/// Time Profile Server. Environment variable +struct tips_env_tag +{ + /// profile environment + prf_env_t prf_env; + + /// CTS Start Handle + uint16_t cts_shdl; + /// NDCS Start Handle + uint16_t ndcs_shdl; + /// RTUS Start Handle + uint16_t rtus_shdl; + + /// CTS Attribute Table + uint8_t cts_att_tbl[CTS_CHAR_MAX]; + /// NDCS Attribute Table + uint8_t ndcs_att_tbl[NDCS_CHAR_MAX]; + /// NDCS Attribute Table + uint8_t rtus_att_tbl[RTUS_CHAR_MAX]; + + /// Environment variable pointer for each connections + struct tips_cnx_env *p_env[BLE_CONNECTION_MAX]; + + /// Database configuration + uint8_t features; + /// Time update state for the Ctl Pt + uint8_t time_upd_state; + + /// State of different task instances + ke_state_t state[TIPS_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve TIP service profile interface + * + * @return TIP service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *tips_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Pack Current Time value + * + * @param p_curr_time_val Current Time value + **************************************************************************************** + */ +uint8_t tips_pack_curr_time_value(uint8_t *p_pckd_time, + const struct tip_curr_time* p_curr_time_val); + +/** + **************************************************************************************** + * @brief Pack Time With DST value + * + * @param p_time_dst_val Time With DST value + **************************************************************************************** + */ +uint8_t tips_pack_time_dst_value(uint8_t *p_pckd_time_dst, + const struct tip_time_with_dst *p_time_dst_val); + +/** + **************************************************************************************** + * @brief Send an TLPS_CMP_EVT message to a requester. + * + * @param[in] p_tips_env TIP Server environment variable + * @param[in] conidx Connection index + * @param[in] operation Code of the completed operation + * @param[in] status Status of the request + **************************************************************************************** + */ +void tips_send_cmp_evt(struct tips_env_tag *p_tips_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void tips_task_init(struct ke_task_desc *p_task_desc); + + +#endif //BLE_TIP_SERVER + +/// @} TIPS + +#endif // TIPS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/src/tips_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/src/tips_task.c new file mode 100644 index 0000000..42e4072 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/tip/tips/src/tips_task.c @@ -0,0 +1,540 @@ +/** + **************************************************************************************** + * + * @file tips_task.c + * + * @brief Time Profile Server Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup TIPSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_TIP_SERVER) +#include "co_utils.h" +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "tips.h" +#include "tips_task.h" + +#include "prf_utils.h" + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref TIPS_ENABLE_REQ message. + * The handler enables the Time Server Profile. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int tips_enable_req_handler(ke_msg_id_t const msgid, + struct tips_enable_req const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(dest_id); + struct tips_enable_rsp *p_rsp; + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + if (gapc_get_conhdl(conidx) == GAP_INVALID_CONHDL) + { + status = PRF_ERR_DISCONNECTED; + } + else if (ke_state_get(dest_id) == TIPS_IDLE) + { + if (p_param->current_time_ntf_en == PRF_CLI_START_NTF) + { + // Get the address of the environment + struct tips_env_tag *p_tips_env = PRF_ENV_GET(TIPS, tips); + // Enable Bonded Data + SETB(p_tips_env->p_env[conidx]->ntf_state, TIPS_CTS_CURRENT_TIME_CFG, 1); + } + } + else + { + status = PRF_ERR_REQ_DISALLOWED; + } + + // Send to APP the details of the discovered attributes on TIPS + p_rsp = KE_MSG_ALLOC(TIPS_ENABLE_RSP, src_id, dest_id, tips_enable_rsp); + + p_rsp->status = status; + ke_msg_send(p_rsp); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref TIPS_UPD_CURR_TIME_CMD message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int tips_upd_curr_time_cmd_handler(ke_msg_id_t const msgid, + struct tips_upd_curr_time_cmd const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + + // Get the address of the environment + struct tips_env_tag *p_tips_env = PRF_ENV_GET(TIPS, tips); + uint8_t conidx = KE_IDX_GET(dest_id); + + if ((p_tips_env->p_env[conidx] != NULL) && (ke_state_get(dest_id) == TIPS_IDLE)) + { + // Check if Notifications are enabled + if (GETB(p_tips_env->p_env[conidx]->ntf_state,TIPS_CTS_CURRENT_TIME_CFG)) + { + // Check if notification can be sent + if (GETB(p_param->current_time.adjust_reason, TIPS_FLAG_EXT_TIME_UPDATE)) + { + if (p_param->enable_ntf_send == 0) + { + status = PRF_ERR_REQ_DISALLOWED; + } + } + + if (status == GAP_ERR_NO_ERROR) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_meas_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), dest_id, + gattc_send_evt_cmd, CTS_CURRENT_TIME_VAL_LEN); + + // Fill in the p_parameter structure + p_meas_val->operation = GATTC_NOTIFY; + p_meas_val->handle = p_tips_env->cts_shdl + CTS_IDX_CURRENT_TIME_VAL; + // Pack the Current Time value + p_meas_val->length = tips_pack_curr_time_value(p_meas_val->value, &p_param->current_time); + + // Go to idle state + ke_state_set(dest_id, TIPS_BUSY); + // Send the event + ke_msg_send(p_meas_val); + } + } + else + { + status = PRF_ERR_NTF_DISABLED; + } + } + else + { + status = GAP_ERR_INVALID_PARAM; + } + + if (status != GAP_ERR_NO_ERROR) + { + tips_send_cmp_evt(p_tips_env, conidx, TIPS_UPD_CURR_TIME_CMD_OP_CODE, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct tips_env_tag *p_tips_env = PRF_ENV_GET(TIPS, tips); + uint8_t conidx = KE_IDX_GET(src_id); + + if ((ke_state_get(dest_id) == TIPS_IDLE) && (p_tips_env->p_env[conidx] != NULL)) + { + //CTS : Current Time client configuration + if (p_param->handle == p_tips_env->cts_shdl + CTS_IDX_CURRENT_TIME_CFG) + { + uint16_t value = (GETB(p_tips_env->p_env[conidx]->ntf_state, TIPS_CTS_CURRENT_TIME_CFG)) + ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND; + + // Send data to peer device + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC_DYN( + GATTC_READ_CFM, + src_id, dest_id, + gattc_read_cfm, + sizeof(uint16_t)); + + p_cfm->length = sizeof(uint16_t); + memcpy(p_cfm->value, &value, sizeof(uint16_t)); + p_cfm->handle = p_param->handle; + p_cfm->status = ATT_ERR_NO_ERROR; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + else + { + // Inform APP about read request + struct tips_rd_req_ind *p_ind = KE_MSG_ALLOC( + TIPS_RD_REQ_IND, + prf_dst_task_get(&(p_tips_env->prf_env), conidx), + prf_src_task_get(&(p_tips_env->prf_env), conidx), + tips_rd_req_ind); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + // Current Time Service + if (p_param->handle < p_tips_env->cts_shdl + CTS_IDX_NB) + { + // Current Time Char value + if (p_param->handle == p_tips_env->cts_shdl + CTS_IDX_CURRENT_TIME_VAL) + { + p_ind->char_code = TIPS_CTS_CURRENT_TIME; + status = ATT_ERR_NO_ERROR; + } + // Local Time Info Char value + else if ((p_param->handle == p_tips_env->cts_shdl + CTS_IDX_LOCAL_TIME_INFO_VAL) + && (GETB(p_tips_env->features, TIPS_CTS_LOC_TIME_INFO_SUP))) + { + p_ind->char_code = TIPS_CTS_LOCAL_TIME_INFO; + status = ATT_ERR_NO_ERROR; + } + // Reference Time Info Char value + else if ((p_param->handle == p_tips_env->cts_shdl + CTS_IDX_REF_TIME_INFO_VAL) + && (GETB(p_tips_env->features, TIPS_CTS_REF_TIME_INFO_SUP))) + { + p_ind->char_code = TIPS_CTS_REF_TIME_INFO; + status = ATT_ERR_NO_ERROR; + } + } + // Time with DST Char value + else if ((p_param->handle == p_tips_env->ndcs_shdl + NDCS_IDX_TIME_DST_VAL) + && (GETB(p_tips_env->features, TIPS_NDCS_SUP))) + { + p_ind->char_code = TIPS_NDCS_TIME_DST; + status = ATT_ERR_NO_ERROR; + } + // Time Update State + else if ((p_param->handle == p_tips_env->rtus_shdl + RTUS_IDX_TIME_UPD_STATE_VAL) + && (GETB(p_tips_env->features, TIPS_RTUS_SUP))) + { + p_ind->char_code = TIPS_RTUS_TIME_UPD_STATE_VAL; + status = ATT_ERR_NO_ERROR; + } + else + { + // Set error code + status = PRF_ERR_INEXISTENT_HDL; + } + + if (status == ATT_ERR_NO_ERROR) + { + // Save handle + p_tips_env->p_env[conidx]->handle = p_param->handle; + // Send message to the APP + ke_msg_send(p_ind); + // Go to busy state + ke_state_set(dest_id, TIPS_BUSY); + } + else + { + struct gattc_read_cfm *p_cfm; + + // Free message + ke_msg_free(ke_param2msg(p_ind)); + + // Send data to peer device + p_cfm = KE_MSG_ALLOC(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send to peer device. + ke_msg_send(p_cfm); + } + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref TIPS_RD_CFM message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int tips_rd_cfm_handler(ke_msg_id_t const msgid, + struct tips_rd_cfm const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct tips_env_tag *p_tips_env = PRF_ENV_GET(TIPS, tips); + uint8_t conidx = KE_IDX_GET(dest_id); + + if ((ke_state_get(dest_id) == TIPS_BUSY) && (p_tips_env->p_env[conidx] != NULL)) + { + if (p_tips_env->p_env[conidx]->handle != ATT_INVALID_HANDLE) + { + uint8_t status = GAP_ERR_NO_ERROR; + // Send data to peer device + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC_DYN( + GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, conidx), dest_id, + gattc_read_cfm, + sizeof(struct tips_rd_cfm)); + + switch (p_param->op_code) + { + case TIPS_CTS_CURRENT_TIME: + { + // Pack Current Time + p_cfm->length = tips_pack_curr_time_value(p_cfm->value, &p_param->value.curr_time); + } break; + + case TIPS_CTS_LOCAL_TIME_INFO: + { + // Pack Local Time + p_cfm->length = sizeof(struct tip_loc_time_info); + memcpy(p_cfm->value, &p_param->value, p_cfm->length); + } break; + + case TIPS_CTS_REF_TIME_INFO: + { + // Pack Reference Time + p_cfm->length = sizeof(struct tip_ref_time_info); + memcpy(p_cfm->value, &p_param->value, p_cfm->length); + } break; + + case TIPS_NDCS_TIME_DST: + { + // Pack Time with DST + p_cfm->length = tips_pack_time_dst_value(p_cfm->value, &p_param->value.time_with_dst); + } break; + + case TIPS_RTUS_TIME_UPD_STATE_VAL: + { + // Pack Time Update State + p_cfm->length = sizeof(struct tip_time_upd_state); + memcpy(p_cfm->value, &p_param->value, p_cfm->length); + } break; + default: + { + // Return Application error to peer + p_cfm->length = 0; + status = PRF_APP_ERROR; + } break; + } + + // Set parameters + p_cfm->handle = p_tips_env->p_env[conidx]->handle; + p_cfm->status = status; + // Send value to peer device. + ke_msg_send(p_cfm); + // Go to idle state + ke_state_set(dest_id, TIPS_IDLE); + // Reset environment variable + p_tips_env->p_env[conidx]->handle = ATT_INVALID_HANDLE; + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles @ref GATTC_CMP_EVT for GATTC_NOTIFY message meaning that Measurement + * notification has been correctly sent to peer device (but not confirmed by peer device). + * * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + // Get the address of the environment + struct tips_env_tag *p_tips_env = PRF_ENV_GET(TIPS, tips); + uint8_t conidx = KE_IDX_GET(src_id); + + if ((p_tips_env->p_env[conidx] != NULL) && (ke_state_get(dest_id) == TIPS_BUSY)) + { + if (p_param->operation == GATTC_NOTIFY) + { + tips_send_cmp_evt(p_tips_env, conidx, TIPS_UPD_CURR_TIME_CMD_OP_CODE, p_param->status); + } + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GL2C_CODE_ATT_WR_CMD_IND message. + * The handler compares the new values with current ones and notifies them if they changed. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint16_t cfg_value = 0x0000; + uint8_t status = GAP_ERR_NO_ERROR; + // Get the address of the environment + struct tips_env_tag *p_tips_env = PRF_ENV_GET(TIPS, tips); + uint8_t conidx = KE_IDX_GET(src_id); + + struct gattc_write_cfm *p_cfm; + + // CTS : Current Time Char. - Notification Configuration + if (p_param->handle == p_tips_env->cts_shdl + CTS_IDX_CURRENT_TIME_CFG) + { + // Extract value before check + memcpy(&cfg_value, &p_param->value[0], sizeof(uint16_t)); + + // only update configuration if value for stop or notification enable + if ((cfg_value == PRF_CLI_STOP_NTFIND) || (cfg_value == PRF_CLI_START_NTF)) + { + struct tips_current_time_ccc_ind *p_ind; + + if (cfg_value == PRF_CLI_STOP_NTFIND) + { + SETB(p_tips_env->p_env[conidx]->ntf_state, TIPS_CTS_CURRENT_TIME_CFG, 0); + } + else // PRF_CLI_START_NTF + { + SETB(p_tips_env->p_env[conidx]->ntf_state, TIPS_CTS_CURRENT_TIME_CFG, 1); + } + + // Inform APP of configuration change + p_ind = KE_MSG_ALLOC(TIPS_CURRENT_TIME_CCC_IND, + prf_dst_task_get(&p_tips_env->prf_env, conidx), + prf_src_task_get(&p_tips_env->prf_env, conidx), + tips_current_time_ccc_ind); + + p_ind->cfg_val = cfg_value; + + ke_msg_send(p_ind); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + // RTUS : Time Update Control Point Char. - Val + else if (p_param->handle == p_tips_env->rtus_shdl + RTUS_IDX_TIME_UPD_CTNL_PT_VAL) + { + // Check if value to write is in allowed range + if ((p_param->value[0] == TIPS_TIME_UPD_CTNL_PT_GET) || + (p_param->value[0] == TIPS_TIME_UPD_CTNL_PT_CANCEL)) + { + struct tips_time_upd_ctnl_pt_ind *p_ind; + + // Update value + p_tips_env->time_upd_state = p_param->value[0]; + + // Send APP the indication with the new value + p_ind = KE_MSG_ALLOC(TIPS_TIME_UPD_CTNL_PT_IND, + prf_dst_task_get(&p_tips_env->prf_env, conidx), + prf_src_task_get(&p_tips_env->prf_env, conidx), + tips_time_upd_ctnl_pt_ind); + + // Time Update Control Point Characteristic Value + p_ind->value = p_tips_env->time_upd_state; + // Send message + ke_msg_send(p_ind); + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + } + else + { + status = PRF_ERR_NOT_WRITABLE; + } + + // Send write response + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Default State handlers definition +KE_MSG_HANDLER_TAB(tips) +{ + {TIPS_ENABLE_REQ, (ke_msg_func_t)tips_enable_req_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t)gattc_write_req_ind_handler}, + {TIPS_UPD_CURR_TIME_CMD, (ke_msg_func_t)tips_upd_curr_time_cmd_handler}, + {GATTC_READ_REQ_IND, (ke_msg_func_t)gattc_read_req_ind_handler}, + {TIPS_RD_CFM, (ke_msg_func_t)tips_rd_cfm_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, +}; + +void tips_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct tips_env_tag *p_tips_env = PRF_ENV_GET(TIPS, tips); + + p_task_desc->msg_handler_tab = tips_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(tips_msg_handler_tab); + p_task_desc->state = p_tips_env->state; + p_task_desc->idx_max = TIPS_IDX_MAX; +} + +#endif //BLE_TIP_SERVER + +/// @} TIPSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/uds_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/uds_common.h new file mode 100644 index 0000000..c00f3b0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/uds_common.h @@ -0,0 +1,204 @@ +/** + **************************************************************************************** + * + * @file uds_common.h + * + * @brief Header File - User Data Service Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _UDS_COMMON_H_ +#define _UDS_COMMON_H_ + +#include "rwip_config.h" + +#if (BLE_UDS_SERVER) + +#include "prf_types.h" +#include + +/* + * DEFINES + **************************************************************************************** + */ + +/// user control point maximum size +#define UDS_USER_CTRL_PT_MAX_LEN (19) +/// CCC maximum size +#define UDSS_CCC_SIZE sizeof(uint16_t) +/// Maximum extended size +#define UDSS_EXT_SIZE sizeof(uint16_t) +/// string maximum size +#define UDSS_STRING_MAX_SIZE (255) +/// date maximum size +#define UDSS_DATE_MAX_SIZE (sizeof(struct prf_date)) +/// uint8 maximum size +#define UDSS_UINT8_MAX_SIZE (sizeof(uint8_t)) +/// uint16 maximum size +#define UDSS_UINT16_MAX_SIZE (sizeof(uint16_t)) +/// Unknown user +#define UDS_USER_ID_UNKNOWN_USER (0xFF) + +/// Characteristic Index +enum uds_char_id +{ + /// Strings: utf8s + UDS_CHAR_ID_FIRST_NAME = 0, + UDS_CHAR_ID_LAST_NAME = 1, + UDS_CHAR_ID_EMAIL_ADDRESS = 2, + UDS_CHAR_ID_LANGUAGE = 3, + /// Date + UDS_CHAR_ID_DATE_OF_BIRTH = 4, + UDS_CHAR_ID_DATE_OF_THRESHOLD_ASSESSMENT = 5, + /// uint16 + UDS_CHAR_ID_WEIGHT = 6, + UDS_CHAR_ID_HEIGHT = 7, + UDS_CHAR_ID_WAIST_CIRCUMFERENCE = 8, + UDS_CHAR_ID_HIP_CIRCUMFERENCE = 9, + /// uint8 + UDS_CHAR_ID_AGE = 10, + UDS_CHAR_ID_GENDER = 11, + UDS_CHAR_ID_VO2_MAX = 12, + UDS_CHAR_ID_MAX_HEART_RATE = 13, + UDS_CHAR_ID_RESTING_HEART_RATE = 14, + UDS_CHAR_ID_MAXIMUM_RECOMMENDED_HEART_RATE = 15, + UDS_CHAR_ID_AEROBIC_THRESHOLD = 16, + UDS_CHAR_ID_ANAEROBIC_THRESHOLD = 17, + UDS_CHAR_ID_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS = 18, + UDS_CHAR_ID_FAT_BURN_HEART_RATE_LOWER_LIMIT = 19, + UDS_CHAR_ID_FAT_BURN_HEART_RATE_UPPER_LIMIT = 20, + UDS_CHAR_ID_AEROBIC_HEART_RATE_LOWER_LIMIT = 21, + UDS_CHAR_ID_AEROBIC_HEART_RATE_UPPER_LIMIT = 22, + UDS_CHAR_ID_ANAEROBIC_HEART_RATE_LOWER_LIMIT = 23, + UDS_CHAR_ID_ANAEROBIC_HEART_RATE_UPPER_LIMIT = 24, + UDS_CHAR_ID_TWO_ZONE_HEART_RATE_LIMITS = 25, + /// set + UDS_CHAR_ID_FIVE_ZONE_HEART_RATE_LIMITS = 26, + UDS_CHAR_ID_THREE_ZONE_HEART_RATE_LIMITS = 27, + UDS_CHAR_ID_USER_DEFINED_1 = 28, + UDS_CHAR_ID_USER_DEFINED_2 = 29, + UDS_CHAR_ID_USER_DEFINED_3 = 30, + UDS_CHAR_ID_USER_DEFINED_4 = 31, + /// control + UDS_CHAR_ID_DB_CHG_INC = 32, + UDS_CHAR_ID_USER_INDEX = 33, + UDS_CHAR_ID_USER_CTRL_PT = 34, + /// UNKNOWN + UDS_CHAR_ID_UNKNOWN = 255, +}; + +/// User Control Point Op-codes +enum uds_ctrl_pt_op_code +{ + UDS_OP_CODE_RESERVED_00 = 0x00, + UDS_OP_CODE_REGISTER_NEW_USER = 0x01, + UDS_OP_CODE_CONSENT = 0x02, + UDS_OP_CODE_DELETE_USER_DATA = 0x03, + UDS_OP_CODE_RESPONSE_CODE = 0x20, +}; + +/// User Control Point Response +enum uds_ctrl_pt_response +{ + UDS_OP_RESPONSE_RESERVED_00 = 0x00, + UDS_OP_RESPONSE_SUCCESS = 0x01, + UDS_OP_RESPONSE_OP_CODE_NOT_SUPPORTED = 0x02, + UDS_OP_RESPONSE_INVALID_PARAMETER = 0x03, + UDS_OP_RESPONSE_OPERATION_FAILED = 0x04, + UDS_OP_RESPONSE_USER_NOT_AUTHORIZED = 0x05, +}; + +/// UDS Gender characteristic - Gender of the user +enum uds_gender_value +{ + UDS_GENDER_MALE = 0, + UDS_GENDER_FEMALE = 1, + UDS_GENDER_UNSPECIFIED = 2, + // 3 - 255 RFU +}; + +/// UDS Sport Type for Aerobic and Anaerobic Thresholds characteristic +enum uds_sport_type_for_aerobic_and_anaerobic_thresholds_value +{ + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_UNSPECIFIED = 0, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_RUNNING = 1, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_CYCLING = 2, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_ROWING = 3, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_CROSS_TRAINING = 4, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_CLIMBING = 5, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_SKIING = 6, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_SKATING = 7, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_ARM_EXERCISING = 8, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_LOWER_BODY_EXERCISING = 9, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_UPPER_BODY_EXERCISING = 10, + UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_WHOLE_BODY_EXERCISING = 11, + // 13 - 255 RFU +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Date profile information - 4 bytes +struct prf_date +{ + /// year date element + uint16_t year; + /// month date element + uint8_t month; + /// day date element + uint8_t day; +}; + + +/// utf8_s string +struct utf_8_name +{ + uint8_t length; + uint8_t name[__ARRAY_EMPTY]; +}; + +/// Characteristic value +union char_val +{ + /// Date value + struct prf_date date; + /// Database Change Increment value + uint32_t db_chg_inc; + /// User Index value + uint8_t user_idx; + /// All 8 bits values depending on char_idx @see enum udsc_char_idx: + /// Age value + /// Gender of the user @see enum uds_gender_type + /// VO2 Max Unit is in Milliliter per kilogram per minutes with a resolution of 1 + /// Maximum heart rate a user can reach + /// Lowest Heart Rate a user can reach + /// Maximum recommended heart rate is a threshold that may be set to limit exertion. + /// First metabolic threshold. The Unit is beats per minute with a resolution of 1 + /// Second metabolic threshold. The Unit is beats per minute with a resolution of 1 + /// Sport type enumeration @see enum uds_sport_type_for_aerobic_and_anaerobic_thresholds_value + /// Lower limit of the heart rate where the user maximizes the fat burn while exercising + /// Upper limit of the heart rate where the user maximizes the fat burn while exercising + /// Lower limit of the heart rate where the user enhances his endurance while exercising + /// Upper limit of the heart rate where the user enhances his endurance while exercising + /// Lower limit of the heart rate where the user enhances his anaerobic tolerance while exercising + /// Upper limit of the heart rate where the user enhances his anaerobic tolerance while exercising + /// Heart rate limit between the heart rate zones for the 2-zone heart rate definition (Fitness and Fat Burn) + uint8_t uint8; + + /// 16 bits value - Weight + uint16_t uint16; + + /// Heart Rate Limits + uint8_t set[4]; +}; + +#endif // (BLE_UDS_SERVER) +#endif // _UDS_COMMON_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/api/udsc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/api/udsc_task.h new file mode 100644 index 0000000..30eeb5c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/api/udsc_task.h @@ -0,0 +1,330 @@ +/** + **************************************************************************************** + * + * @file udsc_task.h + * + * @brief Header file - User Data Service Collector/Client Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _UDSC_TASK_H_ +#define _UDSC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup UDSCTASK User Data Service Collector Task + * @ingroup UDSC + * @brief User Data Service Profile Collector Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "uds_common.h" + +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Message IDs +/*@TRACE*/ +enum udsc_msg_ids +{ + /// Enable the Profile Collector task - at connection + UDSC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_UDSC), + /// Response to Enable the Profile Collector task - at connection + UDSC_ENABLE_RSP, + + ///*** UDS CHARACTERISTIC READ REQUESTS + UDSC_RD_CHAR_CMD, + + /// Read the CCC of a DB_CHANGE & USER_CTRL_PT characteristic + UDSC_RD_CHAR_CCC_CMD, + + ///*** CHARACTERISTIC WRITE COMMAND + /// Write the CCC of a measurement sensor characteristic + UDSC_WR_CHAR_CMD, + /// Write the CCC of a measurement sensor characteristic + UDSC_WR_CHAR_UTF8_CMD, + + ///*** UDS CHARACTERISTIC READ RESPONSE + UDSC_RD_CHAR_IND, + UDSC_RD_CHAR_UTF8_IND, + + /// Read Response the CCC of a DB_CHANGE & USER_CTRL_PT characteristic + UDSC_RD_CHAR_CCC_IND, + + ///*** CHARACTERISTIC/DESCRIPTOR WRITE REQUESTS + /// Write the CCC of a measurement sensor characteristic + UDSC_WR_USER_CTRL_PT_CMD, + + /// Write the CCC of a DB_CHANGE & USER_CTRL_PT characteristic + UDSC_WR_CHAR_CCC_CMD, + + /// Characteristic DB_CHG_INC Indication from peer + UDSC_DB_CHG_INC_IND, + /// Characteristic User Control Point Indication from peer + UDSC_USER_CTRL_PT_IND, + /// Complete Event Information + UDSC_CMP_EVT, +}; + +/// User Data Service Service Characteristics +enum udsc_char_idx +{ + /// Strings: utf8s + UDSC_CHAR_UDS_FIRST_NAME = 0, + UDSC_CHAR_UDS_LAST_NAME = 1, + UDSC_CHAR_UDS_EMAIL_ADDRESS = 2, + UDSC_CHAR_UDS_LANGUAGE = 3, + /// Date + UDSC_CHAR_UDS_DATE_OF_BIRTH = 4, + UDSC_CHAR_UDS_DATE_OF_THRESHOLD_ASSESSMENT = 5, + /// uint16 + UDSC_CHAR_UDS_WEIGHT = 6, + UDSC_CHAR_UDS_HEIGHT = 7, + UDSC_CHAR_UDS_WAIST_CIRCUMFERENCE = 8, + UDSC_CHAR_UDS_HIP_CIRCUMFERENCE = 9, + /// uint8 + UDSC_CHAR_UDS_AGE = 10, + UDSC_CHAR_UDS_GENDER = 11, + UDSC_CHAR_UDS_VO2_MAX = 12, + UDSC_CHAR_UDS_MAX_HEART_RATE = 13, + UDSC_CHAR_UDS_RESTING_HEART_RATE = 14, + UDSC_CHAR_UDS_MAXIMUM_RECOMMENDED_HEART_RATE = 15, + UDSC_CHAR_UDS_AEROBIC_THRESHOLD = 16, + UDSC_CHAR_UDS_ANAEROBIC_THRESHOLD = 17, + UDSC_CHAR_UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS = 18, + UDSC_CHAR_UDS_FAT_BURN_HEART_RATE_LOWER_LIMIT = 19, + UDSC_CHAR_UDS_FAT_BURN_HEART_RATE_UPPER_LIMIT = 20, + UDSC_CHAR_UDS_AEROBIC_HEART_RATE_LOWER_LIMIT = 21, + UDSC_CHAR_UDS_AEROBIC_HEART_RATE_UPPER_LIMIT = 22, + UDSC_CHAR_UDS_ANAEROBIC_HEART_RATE_LOWER_LIMIT = 23, + UDSC_CHAR_UDS_ANAEROBIC_HEART_RATE_UPPER_LIMIT = 24, + UDSC_CHAR_UDS_TWO_ZONE_HEART_RATE_LIMITS = 25, + /// set + UDSC_CHAR_UDS_FIVE_ZONE_HEART_RATE_LIMITS = 26, + UDSC_CHAR_UDS_THREE_ZONE_HEART_RATE_LIMITS = 27, + + UDSC_CHAR_UDS_USER_DEFINED_1 = 28, + UDSC_CHAR_UDS_USER_DEFINED_2 = 29, + UDSC_CHAR_UDS_USER_DEFINED_3 = 30, + UDSC_CHAR_UDS_USER_DEFINED_4 = 31, + + /// Database Change Increment + UDSC_CHAR_UDS_DB_CHG_INC = 32, + /// User Index + UDSC_CHAR_UDS_USER_INDEX = 33, + /// User Control Point + UDSC_CHAR_UDS_USER_CTRL_PT = 34, + + UDSC_CHAR_UDS_MAX, +}; + +/// User Data Service Service Characteristic Descriptors +enum udsc_desc_idx +{ + /// Database Change Increment Client config + UDSC_DESC_UDS_DB_CHG_INC_CCC, + /// User Control Point Client config + UDSC_DESC_UDS_USER_CTRL_PT_CCC, + /// Extended + UDSC_DESC_UDS_FIRST_NAME_EXT, + UDSC_DESC_UDS_LAST_NAME_EXT, + UDSC_DESC_UDS_EMAIL_ADDRESS_EXT, + UDSC_DESC_UDS_LANGUAGE_EXT, + + UDSC_DESC_UDS_MAX, +}; + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the User Data Service Service + */ +struct udsc_uds_content +{ + /// service info + struct prf_svc svc; + + /// Characteristic info: + /// - Feature + /// - Measurement + struct prf_char_inf chars[UDSC_CHAR_UDS_MAX]; + + /// Descriptor handles: + /// - Client cfg + struct prf_char_desc_inf descs[UDSC_DESC_UDS_MAX]; +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the @ref UDSC_ENABLE_REQ message +struct udsc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values UDSC ES + struct udsc_uds_content uds; +}; + +/// Parameters of the @ref UDSC_ENABLE_RSP message +struct udsc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values UDSC ES + struct udsc_uds_content uds; +}; + +///*** UDS CHARACTERISTIC/DESCRIPTOR READ REQUESTS +/// Parameters of the @ref UDSC_RD_CHAR_CMD message +/// Read the User Data Service Feature +struct udsc_rd_char_cmd +{ + /// Characteristic from @ref enum uds_char_id + uint8_t char_idx; +}; + +/// Parameters of the @ref UDSC_RD_CHAR_CCC_CMD message +/// Read the CCC of a measurement sensor characteristic +struct udsc_rd_char_ccc_cmd +{ + /// Characteristic from @ref enum udsc_char_idx + /// UDSC_CHAR_UDS_DB_CHG_INC, UDSC_CHAR_UDS_USER_CTRL_PT + uint8_t char_idx; +}; + +///*** CHARACTERISTIC/DESCRIPTOR WRITE REQUESTS +/// Parameters of the @ref UDSC_WR_CHAR_CCC_CMD message +/// Write the CCC to a selected characteristic +struct udsc_wr_char_ccc_cmd +{ + /// Characteristic from @ref enum udsc_char_idx + /// UDSC_CHAR_UDS_DB_CHG_INC, UDSC_CHAR_UDS_USER_CTRL_PT + uint8_t char_idx; + /// CCC value + uint16_t ccc; +}; + +///*** UDS CHARACTERISTIC/DESCRIPTOR READ RESPONSE +/// Parameters of the @ref UDSC_RD_CHAR_IND message +/// Read the User Data Service Characteristic +struct udsc_rd_char_ind +{ + /// Characteristic from @ref enum udsc_char_idx + uint8_t char_idx; + /// Characteristic indication value + union char_val value; +}; + +/// Parameters of the @ref UDSC_WR_CHAR_UTF8_CMD message +/// Write to User Data Service UTF8 Characteristic +struct udsc_wr_char_utf8_cmd +{ + /// Characteristic from @ref enum udsc_char_idx + uint8_t char_idx; + /// UTF Name + struct utf_8_name utf_name; +}; + +/// Parameters of the @ref UDSC_WR_CHAR_CMD message +/// Write to User Data Service Characteristic +struct udsc_wr_char_cmd +{ + /// Characteristic from @ref enum udsc_char_idx + uint8_t char_idx; + /// Characteristic value + union char_val value; +}; + +/// Parameters of the @ref UDSC_RD_CHAR_UTF8_IND message +/// Read the User Data Service UTF8 Characteristic +struct udsc_rd_char_utf8_ind +{ + /// Characteristic from @ref enum udsc_char_idx + uint8_t char_idx; + /// UTF Name + struct utf_8_name utf_name; +}; + +/// Parameters of the @ref UDSC_RD_CHAR_CCC_IND message +/// Read the CCC of a measurement sensor characteristic +struct udsc_rd_char_ccc_ind +{ + /// Characteristic from @ref enum udsc_char_idx + /// UDSC_CHAR_UDS_DB_CHG_INC, UDSC_CHAR_UDS_USER_CTRL_PT + uint8_t char_idx; + /// Indication Configuration + uint16_t ccc; +}; + +/// Parameters of the @ref UDSC_DB_CHG_INC_IND message +/// Characteristic Measurement Indication from peer +struct udsc_db_chg_inc_ind +{ + /// Database change increment value + uint32_t value; +}; + +/// Parameters of the @ref UDSC_USER_CTRL_PT_IND message +/// User Data Service User Control Point Characteristic Indication +struct udsc_user_ctrl_pt_ind +{ + /// response op-code =0x20 + uint8_t resp_code; + /// requested op-code + uint8_t req_op_code; + /// Response value + uint8_t resp_value; + /// User ID used for register new user command + uint8_t user_id; + /// Parameter length + uint8_t length; + /// Parameter value - for the future extension to send additional commands + uint8_t parameter[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref UDSC_WR_USER_CTRL_PT_CMD message +/// Write to User Data Service User Control Point Characteristic +struct udsc_wr_user_ctrl_pt_cmd +{ + /// User Control Point Op-codes @see enum uds_ctrl_pt_op_code + uint8_t op_code; + /// User Index + uint8_t user_id; + /// used for sending consent command + uint16_t consent; + /// Parameter length + uint8_t length; + /// Parameter value - for the future extension to send additional commands + uint8_t parameter[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref UDSC_CMP_EVT message +struct udsc_cmp_evt +{ + /// Operation code + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} UDSCTASK + +#endif //(_UDSC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/sourcelist.txt new file mode 100644 index 0000000..a274c5d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2016 +# +#*************************************************************************************** + + udsc.c + udsc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/src/udsc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/src/udsc.c new file mode 100644 index 0000000..d03301f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/src/udsc.c @@ -0,0 +1,242 @@ +/** + **************************************************************************************** + * + * @file udsc.c + * + * @brief User Data Service Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup UDSC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_UDS_CLIENT) +#include "prf.h" +#include "uds_common.h" + +#include "udsc_task.h" +#include "udsc.h" +#include "gap.h" + +#include "ke_mem.h" + +/* + * GLOBAL VARIABLES DECLARATION + **************************************************************************************** + */ + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the UDSC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t udsc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, + uint16_t app_task, uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct udsc_env_tag *p_udsc_env = + (struct udsc_env_tag *) ke_malloc(sizeof(struct udsc_env_tag), KE_MEM_ATT_DB); + + // allocate UDSC required environment variable + p_env->env = (prf_env_t *) p_udsc_env; + + p_udsc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_udsc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_UDSC; + udsc_task_init(&(p_env->desc)); + + for (idx = 0; idx < UDSC_IDX_MAX ; idx++) + { + p_udsc_env->p_env[idx] = NULL; + + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), UDSC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void udsc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct udsc_env_tag* p_udsc_env = (struct udsc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if (p_udsc_env->p_env[conidx] != NULL) + { + if (p_udsc_env->p_env[conidx]->p_op != NULL) + { + ke_free(ke_param2msg(p_udsc_env->p_env[conidx]->p_op)); + } + + ke_free(p_udsc_env->p_env[conidx]); + p_udsc_env->p_env[conidx] = NULL; + } + + // Put UDS Client in Free state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), UDSC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the UDSC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void udsc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct udsc_env_tag *p_udsc_env = (struct udsc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for (idx = 0; idx < UDSC_IDX_MAX ; idx++) + { + udsc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_udsc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void udsc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + // Put UDS Client in Idle state + ke_state_set(KE_BUILD_ID(p_env->task, conidx), UDSC_IDLE); +} + +/// UDSC Task interface required by profile manager +const struct prf_task_cbs udsc_itf = +{ + udsc_init, + udsc_destroy, + udsc_create, + udsc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ +const struct prf_task_cbs *udsc_prf_itf_get(void) +{ + return &udsc_itf; +} + +void udsc_enable_rsp_send(struct udsc_env_tag *p_udsc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on UDSP + struct udsc_enable_rsp *p_rsp = KE_MSG_ALLOC( + UDSC_ENABLE_RSP, + prf_dst_task_get(&(p_udsc_env->prf_env), conidx), + prf_src_task_get(&(p_udsc_env->prf_env), conidx), + udsc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + + p_rsp->uds = p_udsc_env->p_env[conidx]->uds; + + // Register UDSC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_udsc_env->prf_env), conidx, &(p_udsc_env->p_env[conidx]->uds.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_udsc_env->prf_env), conidx), UDSC_BUSY); + } + else + { + memset(&p_rsp->uds, 0, sizeof(p_rsp->uds)); + // Enabled failed - so go back to the FREE state + ke_state_set(prf_src_task_get(&(p_udsc_env->prf_env), conidx), UDSC_FREE); + } + + ke_msg_send(p_rsp); +} + +void udsc_send_cmp_evt(struct udsc_env_tag *p_udsc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct udsc_cmp_evt *p_evt; + + // Go back to the CONNECTED state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_udsc_env->prf_env), conidx)) == UDSC_BUSY) + { + ke_state_set(prf_src_task_get(&(p_udsc_env->prf_env), conidx), UDSC_IDLE); + } + + // Send the message + p_evt = KE_MSG_ALLOC(UDSC_CMP_EVT, + prf_dst_task_get(&(p_udsc_env->prf_env), conidx), + prf_src_task_get(&(p_udsc_env->prf_env), conidx), + udsc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //(BLE_UDS_CLIENT) + +/// @} UDS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/src/udsc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/src/udsc.h new file mode 100644 index 0000000..a87d75e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/src/udsc.h @@ -0,0 +1,194 @@ +/** + **************************************************************************************** + * + * @file udsc.h + * + * @brief Header file - User Data Service - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _UDSC_H_ +#define _UDSC_H_ + +/** + **************************************************************************************** + * @addtogroup UDSC User Data Service Profile Collector + * @ingroup UDSP + * @brief User Data Service Collector + * @{ + **************************************************************************************** + */ + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of User Data Service Task instances +#define UDSC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "uds_common.h" + +#if (BLE_UDS_CLIENT) + +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +//#define CCC_READY + +/* + * ENUMERATIONS + **************************************************************************************** + */ + + +/// Possible states of the UDSC task +enum udsc_states +{ + /// Idle state + UDSC_FREE, + /// Connected state + UDSC_IDLE, + /// Discovering Services + UDSC_DISCOVERING_SVC, + /// Busy state + UDSC_BUSY, + /// Number of defined states. + UDSC_STATE_MAX +}; + +/// Operation Codes for pending operations in the client. +enum udsc_op_codes +{ + /// Reserved operation code + UDSC_RESERVED_OP_CODE = 0, + + /// Read op-codes + UDSC_READ_CHAR_OP_CODE = 1, + + /// Read op-codes + UDSC_READ_CCC_OP_CODE = 2, + + /// Write op-codes. + UDSC_WRITE_CHAR_OP_CODE = 3, + UDSC_WRITE_CCC_OP_CODE = 4, + + UDSC_ENABLE_CMD_OP_CODE = 5 + +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/** + * Stored Environment content/context information for a connection + */ +struct udsc_cnx_env +{ + /// Current operation + void *p_op; + /// Pending operation + uint8_t op_pending; + ///Last requested UUID(to keep track of the two services and char) + uint16_t last_uuid_req; + ///Last service for which something was discovered + uint16_t last_svc_req; + /// Last characteristic code used in a read or a write request + uint16_t last_char_code; + /// Counter used to check service uniqueness + uint8_t nb_svc; + + /// User Data Service Service Characteristics + struct udsc_uds_content uds; +}; + +/// Environmental sensing environment variable +struct udsc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct udsc_cnx_env *p_env[UDSC_IDX_MAX]; + /// State of different task instances + ke_state_t state[UDSC_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Pool of UDS Profile Collector task environments. +extern struct udsc_env_tag **udsc_envs; + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve UDS client profile interface + * + * @return UDS client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs *udsc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send User Data Service ATT DB discovery results to UDSC host. + * + * @param[in] p_udsc_env Profile environment for the connection + * @param[in] conidx Connection Identifier + * @param[in] status Indicates the outcome of the operation + **************************************************************************************** + */ +void udsc_enable_rsp_send(struct udsc_env_tag *p_udsc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send a UDSC_CMP_EVT message to the task which enabled the profile + * + * @param[in] p_udsc_env Profile environment + * @param[in] conidx Connection Identifier + * @param[in] operation Indicates the operation for which the cmp_evt is being sent. + * @param[in] status Indicates the outcome of the operation + * + * @return Error_Code. + **************************************************************************************** + */ +void udsc_send_cmp_evt(struct udsc_env_tag *p_udsc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param task_desc Task descriptor to fill + **************************************************************************************** + */ +void udsc_task_init(struct ke_task_desc *task_desc); + +#endif //(BLE_UDS_CLIENT) + +/// @} UDSC + +#endif //(_UDSC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/src/udsc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/src/udsc_task.c new file mode 100644 index 0000000..840d44f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udsc/src/udsc_task.c @@ -0,0 +1,1387 @@ +/** + **************************************************************************************** + * + * @file udsc_task.c + * + * @brief User Data Service Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup UDSCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_UDS_CLIENT) +#include "uds_common.h" +#include "udsc_task.h" +#include "udsc.h" + +#include "gap.h" +#include "attm.h" +#include "gattc_task.h" +#include "ke_mem.h" +#include "co_utils.h" + + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve User Data Service Service characteristics information +const struct prf_char_def udsc_uds_char[UDSC_CHAR_UDS_MAX] = +{ + [UDSC_CHAR_UDS_DB_CHG_INC] = {ATT_CHAR_DATABASE_CHANGE_INCREMENT, + ATT_MANDATORY, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR | ATT_CHAR_PROP_NTF) }, + + [UDSC_CHAR_UDS_USER_INDEX] = {ATT_CHAR_USER_INDEX, + ATT_MANDATORY, + (ATT_CHAR_PROP_RD) }, + + [UDSC_CHAR_UDS_USER_CTRL_PT] = {ATT_CHAR_USER_CONTROL_POINT, + ATT_MANDATORY, + (ATT_CHAR_PROP_WR | ATT_CHAR_PROP_IND) }, + + /// Strings: utf8s + [UDSC_CHAR_UDS_FIRST_NAME] = {ATT_CHAR_FIRST_NAME, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR | ATT_CHAR_PROP_EXT_PROP) }, + + [UDSC_CHAR_UDS_LAST_NAME] = {ATT_CHAR_LAST_NAME, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR | ATT_CHAR_PROP_EXT_PROP) }, + + [UDSC_CHAR_UDS_EMAIL_ADDRESS] = {ATT_CHAR_EMAIL_ADDRESS, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR | ATT_CHAR_PROP_EXT_PROP) }, + + [UDSC_CHAR_UDS_LANGUAGE] = {ATT_CHAR_LANGUAGE, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR | ATT_CHAR_PROP_EXT_PROP) }, + + /// Date + [UDSC_CHAR_UDS_DATE_OF_BIRTH] = {ATT_CHAR_DATE_OF_BIRTH, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_DATE_OF_THRESHOLD_ASSESSMENT] = {ATT_CHAR_DATE_OF_THRESHOLD_ASSESSMENT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + /// uint16 + [UDSC_CHAR_UDS_WEIGHT] = {ATT_CHAR_WEIGHT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_HEIGHT] = {ATT_CHAR_HEIGHT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_WAIST_CIRCUMFERENCE] = {ATT_CHAR_WAIST_CIRCUMFERENCE, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_HIP_CIRCUMFERENCE] = {ATT_CHAR_HIP_CIRCUMFERENCE, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + /// uint8 + [UDSC_CHAR_UDS_AGE] = {ATT_CHAR_AGE, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_GENDER] = {ATT_CHAR_GENDER, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_VO2_MAX] = {ATT_CHAR_VO2_MAX, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_MAX_HEART_RATE] = {ATT_CHAR_MAX_HEART_RATE, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_RESTING_HEART_RATE] = {ATT_CHAR_RESTING_HEART_RATE, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_MAXIMUM_RECOMMENDED_HEART_RATE] = {ATT_CHAR_MAXIMUM_RECOMMENDED_HEART_RATE, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_AEROBIC_THRESHOLD] = {ATT_CHAR_AEROBIC_THRESHHOLD, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_ANAEROBIC_THRESHOLD] = {ATT_CHAR_ANAEROBIC_THRESHHOLD, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS] = + {ATT_CHAR_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_FAT_BURN_HEART_RATE_LOWER_LIMIT] = {ATT_CHAR_FAT_BURN_HEART_RATE_LOWER_LIMIT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_FAT_BURN_HEART_RATE_UPPER_LIMIT] = {ATT_CHAR_FAT_BURN_HEART_RATE_UPPER_LIMIT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_AEROBIC_HEART_RATE_LOWER_LIMIT] = {ATT_CHAR_AEROBIC_HEART_RATE_LOWER_LIMIT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_AEROBIC_HEART_RATE_UPPER_LIMIT] = {ATT_CHAR_AEROBIC_HEART_RATE_UPPER_LIMIT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_ANAEROBIC_HEART_RATE_LOWER_LIMIT] = {ATT_CHAR_ANAEROBIC_HEART_RATE_LOWER_LIMIT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_ANAEROBIC_HEART_RATE_UPPER_LIMIT] = {ATT_CHAR_ANAEROBIC_HEART_RATE_UPPER_LIMIT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_TWO_ZONE_HEART_RATE_LIMITS] = {ATT_CHAR_TWO_ZONE_HEART_RATE_LIMIT, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + /// set + [UDSC_CHAR_UDS_FIVE_ZONE_HEART_RATE_LIMITS] = {ATT_CHAR_FIVE_ZONE_HEART_RATE_LIMITS, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_THREE_ZONE_HEART_RATE_LIMITS] = {ATT_CHAR_THREE_ZONE_HEART_RATE_LIMITS, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + /// user defined + [UDSC_CHAR_UDS_USER_DEFINED_1] = {ATT_CHAR_FIVE_ZONE_HEART_RATE_LIMITS, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_USER_DEFINED_2] = {ATT_CHAR_THREE_ZONE_HEART_RATE_LIMITS, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + [UDSC_CHAR_UDS_USER_DEFINED_3] = {ATT_CHAR_FIVE_ZONE_HEART_RATE_LIMITS, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, + + [UDSC_CHAR_UDS_USER_DEFINED_4] = {ATT_CHAR_THREE_ZONE_HEART_RATE_LIMITS, + ATT_OPTIONAL, + (ATT_CHAR_PROP_RD | ATT_CHAR_PROP_WR) }, +}; + +/// State machine used to retrieve User Data Service Service characteristic description information +const struct prf_char_desc_def udsc_uds_char_desc[UDSC_DESC_UDS_MAX] = +{ + /// Database Change Increment Client config + [UDSC_DESC_UDS_DB_CHG_INC_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + UDSC_CHAR_UDS_DB_CHG_INC}, + + /// User Control Point Client config + [UDSC_DESC_UDS_USER_CTRL_PT_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + UDSC_CHAR_UDS_USER_CTRL_PT}, + + /// String Extended Properties + [UDSC_DESC_UDS_FIRST_NAME_EXT] = {ATT_DESC_CHAR_EXT_PROPERTIES, + ATT_OPTIONAL, + UDSC_CHAR_UDS_FIRST_NAME}, + + /// String Extended Properties + [UDSC_DESC_UDS_LAST_NAME_EXT] = {ATT_DESC_CHAR_EXT_PROPERTIES, + ATT_OPTIONAL, + UDSC_CHAR_UDS_LAST_NAME}, + + /// String Extended Properties + [UDSC_DESC_UDS_EMAIL_ADDRESS_EXT] = {ATT_DESC_CHAR_EXT_PROPERTIES, + ATT_OPTIONAL, + UDSC_CHAR_UDS_EMAIL_ADDRESS}, + + /// String Extended Properties + [UDSC_DESC_UDS_LANGUAGE_EXT] = {ATT_DESC_CHAR_EXT_PROPERTIES, + ATT_OPTIONAL, + UDSC_CHAR_UDS_LANGUAGE}, +}; + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + do + { + // User Data Service Collector Role Task Environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_udsc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_udsc_env->p_env[conidx] != NULL, dest_id, src_id); + + if (ke_state_get(dest_id) != UDSC_DISCOVERING_SVC) + { + break; + } + + if (attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_USER_DATA)) + { + // Retrieve WS characteristics and descriptors + prf_extract_svc_info(p_ind, UDSC_CHAR_UDS_MAX, &udsc_uds_char[0], &p_udsc_env->p_env[conidx]->uds.chars[0], + UDSC_DESC_UDS_MAX, &udsc_uds_char_desc[0], &p_udsc_env->p_env[conidx]->uds.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_udsc_env->p_env[conidx]->uds.svc.shdl = p_ind->start_hdl; + p_udsc_env->p_env[conidx]->uds.svc.ehdl = p_ind->end_hdl; + + p_udsc_env->p_env[conidx]->nb_svc++; + } + + } while (0); + + return (KE_MSG_CONSUMED); +} +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSC_ENABLE_REQ message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int udsc_enable_req_handler(ke_msg_id_t const msgid, + struct udsc_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + uint8_t state = ke_state_get(dest_id); + // User Data Service Collector Role Task Environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + + ASSERT_INFO(p_udsc_env != NULL, dest_id, src_id); + if ((state == UDSC_IDLE) && (p_udsc_env->p_env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_udsc_env->p_env[conidx] = (struct udsc_cnx_env *) ke_malloc(sizeof(struct udsc_cnx_env), KE_MEM_ATT_DB); + memset(p_udsc_env->p_env[conidx], 0, sizeof(struct udsc_cnx_env)); + + // Start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + // Start discovery with User Data Service + prf_disc_svc_send(&(p_udsc_env->prf_env), conidx, ATT_SVC_USER_DATA); + + p_udsc_env->p_env[conidx]->last_uuid_req = ATT_SVC_USER_DATA; + p_udsc_env->p_env[conidx]->last_svc_req = ATT_SVC_USER_DATA; + + // Go to DISCOVERING SERVICE state + ke_state_set(dest_id, UDSC_DISCOVERING_SVC); + } + // normal connection, get saved att details + else + { + p_udsc_env->p_env[conidx]->uds = p_param->uds; + + //send APP confirmation that can start normal connection to TH + udsc_enable_rsp_send(p_udsc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != UDSC_FREE) + { + // The message will be forwarded towards the good task instance + status = PRF_ERR_REQ_DISALLOWED; + } + + if (status != GAP_ERR_NO_ERROR) + { + // The request is disallowed (profile already enabled for this connection, or not enough memory, ...) + udsc_enable_rsp_send(p_udsc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSC_RD_CHAR_CMD message from the application. + * @brief To read the Feature Characteristic in the peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udsc_rd_char_cmd_handler(ke_msg_id_t const msgid, + struct udsc_rd_char_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == UDSC_IDLE) + { + ASSERT_INFO(p_udsc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_udsc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = ATT_INVALID_SEARCH_HANDLE; + // Service + struct prf_svc *p_svc = &p_udsc_env->p_env[conidx]->uds.svc; + + if (p_param->char_idx < UDSC_CHAR_UDS_MAX) + { + search_hdl = p_udsc_env->p_env[conidx]->uds.chars[p_param->char_idx].val_hdl; + } + // Check if handle is viable + if ((search_hdl != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_udsc_env->p_env[conidx]->op_pending = UDSC_READ_CHAR_OP_CODE; + // keep the characteristic in operation + p_udsc_env->p_env[conidx]->last_char_code = p_param->char_idx; + // Send read request + prf_read_char_send(&(p_udsc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, UDSC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == UDSC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + udsc_send_cmp_evt(p_udsc_env, conidx, UDSC_READ_CHAR_OP_CODE, status); + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSC_RD_CHAR_CCC_CMD message from the application. + * @brief To read the CCC value of the Measurement characteristic in the peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udsc_rd_char_ccc_cmd_handler(ke_msg_id_t const msgid, + struct udsc_rd_char_ccc_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == UDSC_IDLE) + { + ASSERT_INFO(p_udsc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_udsc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = ATT_INVALID_SEARCH_HANDLE; + // Service + struct prf_svc *p_svc = &p_udsc_env->p_env[conidx]->uds.svc; + + if (p_param->char_idx == UDSC_CHAR_UDS_DB_CHG_INC) + { + search_hdl = p_udsc_env->p_env[conidx]->uds.descs[UDSC_DESC_UDS_DB_CHG_INC_CCC].desc_hdl; + } + else if (p_param->char_idx == UDSC_CHAR_UDS_USER_CTRL_PT) + { + search_hdl = p_udsc_env->p_env[conidx]->uds.descs[UDSC_DESC_UDS_USER_CTRL_PT_CCC].desc_hdl; + } + + // Check if handle is viable + if ((search_hdl != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_udsc_env->p_env[conidx]->op_pending = UDSC_READ_CCC_OP_CODE; + // keep the characteristic in operation + p_udsc_env->p_env[conidx]->last_char_code = p_param->char_idx; + // Send read request + prf_read_char_send(&(p_udsc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, UDSC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == UDSC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + udsc_send_cmp_evt(p_udsc_env, conidx, UDSC_READ_CHAR_OP_CODE, status); + } + + return msg_status; +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSC_WR_CHAR_CCC_CMD message. + * Allows the application to write new CCC values to a Characteristic in the peer server + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udsc_wr_char_ccc_cmd_handler(ke_msg_id_t const msgid, + struct udsc_wr_char_ccc_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Get the address of the environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + + if (state == UDSC_IDLE) + { + ASSERT_INFO(p_udsc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_udsc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Service + struct prf_svc *p_svc = &p_udsc_env->p_env[conidx]->uds.svc; + + if (p_param->char_idx == UDSC_CHAR_UDS_DB_CHG_INC) + { + handle = p_udsc_env->p_env[conidx]->uds.descs[UDSC_DESC_UDS_DB_CHG_INC_CCC].desc_hdl; + } + else if (p_param->char_idx == UDSC_CHAR_UDS_USER_CTRL_PT) + { + handle = p_udsc_env->p_env[conidx]->uds.descs[UDSC_DESC_UDS_USER_CTRL_PT_CCC].desc_hdl; + } + + // Check if handle is viable + if ((handle != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_udsc_env->p_env[conidx]->op_pending = UDSC_WRITE_CCC_OP_CODE; + // keep the characteristic in operation + p_udsc_env->p_env[conidx]->last_char_code = p_param->char_idx; + + // Send the write request + prf_gatt_write_ntf_ind(&(p_udsc_env->prf_env), conidx, handle, p_param->ccc); + + // Go to the Busy state + ke_state_set(dest_id, UDSC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + udsc_send_cmp_evt(p_udsc_env, conidx, UDSC_WRITE_CCC_OP_CODE, status); + } + } + else if (state == UDSC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSC_WR_CHAR_UTF8_CMD message. + * Allows the application to write new CCC values to a Characteristic in the peer server + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udsc_wr_char_utf8_cmd_handler(ke_msg_id_t const msgid, + struct udsc_wr_char_utf8_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Get the address of the environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + // Get connection index + + if (state == UDSC_IDLE) + { + ASSERT_INFO(p_udsc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_udsc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Service + struct prf_svc *p_svc = &p_udsc_env->p_env[conidx]->uds.svc; + // Length + uint8_t length; + uint8_t *p_data; + + length = p_param->utf_name.length; + p_data = &p_param->utf_name.name[0]; + + #ifndef USE_EXTRA_CHARS + if (p_param->char_idx <= UDSC_CHAR_UDS_LANGUAGE) + #endif + { + handle = p_udsc_env->p_env[conidx]->uds.chars[p_param->char_idx].val_hdl; + } + + // Check if handle is viable + if ((handle != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_udsc_env->p_env[conidx]->op_pending = UDSC_WRITE_CHAR_OP_CODE; + // keep the characteristic in operation + p_udsc_env->p_env[conidx]->last_char_code = p_param->char_idx; + + // Send the write request + prf_gatt_write(&(p_udsc_env->prf_env), conidx, handle, p_data, length, GATTC_WRITE); + + // Go to the Busy state + ke_state_set(dest_id, UDSC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + udsc_send_cmp_evt(p_udsc_env, conidx, UDSC_WRITE_CHAR_OP_CODE, status); + } + } + else if (state == UDSC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSC_WR_CHAR_CMD message. + * Allows the application to write new CCC values to a Characteristic in the peer server + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udsc_wr_char_cmd_handler(ke_msg_id_t const msgid, + struct udsc_wr_char_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + + if (state == UDSC_IDLE) + { + // Get the address of the environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_udsc_env != NULL, dest_id, src_id); + + // environment variable not ready + if (p_udsc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Service + struct prf_svc *p_svc = &p_udsc_env->p_env[conidx]->uds.svc; + // Length + uint8_t length = 0; + uint8_t data[sizeof(union char_val)]; + uint8_t *p_data = &data[0]; + uint8_t char_idx = p_param->char_idx; + + if (((char_idx >= UDSC_CHAR_UDS_DATE_OF_BIRTH) && (char_idx <= UDSC_CHAR_UDS_THREE_ZONE_HEART_RATE_LIMITS)) || + (char_idx == UDSC_CHAR_UDS_DB_CHG_INC)) + { + handle = p_udsc_env->p_env[conidx]->uds.chars[char_idx].val_hdl; + } + + // Check if handle is viable + if ((handle != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_udsc_env->p_env[conidx]->op_pending = UDSC_WRITE_CHAR_OP_CODE; + // keep the characteristic in operation + p_udsc_env->p_env[conidx]->last_char_code = char_idx; + + if (char_idx == UDSC_CHAR_UDS_DB_CHG_INC) + { + // DB CHG Inc + co_write32p(&data[0], p_param->value.db_chg_inc); + length = sizeof(uint32_t); + } + else if (char_idx == UDSC_CHAR_UDS_FIVE_ZONE_HEART_RATE_LIMITS) + { + // Set + data[0] = p_param->value.set[0]; + data[1] = p_param->value.set[1]; + data[2] = p_param->value.set[2]; + data[3] = p_param->value.set[3]; + length = 4; + } + else if (char_idx == UDSC_CHAR_UDS_THREE_ZONE_HEART_RATE_LIMITS) + { + // Set + data[0] = p_param->value.set[0]; + data[1] = p_param->value.set[1]; + length = 2; + } + else if ((char_idx >= UDSC_CHAR_UDS_DATE_OF_BIRTH) && + (char_idx <= UDSC_CHAR_UDS_DATE_OF_THRESHOLD_ASSESSMENT)) + { + // Date + co_write16p(&data[0], p_param->value.date.year); + data[2] = p_param->value.date.month; + data[3] = p_param->value.date.day; + length = 4; + } + else if ((char_idx >= UDSC_CHAR_UDS_WEIGHT) && (char_idx <= UDSC_CHAR_UDS_HIP_CIRCUMFERENCE)) + { + // uint16 + co_write16p(&data[0], p_param->value.uint16); + length = 2; + } + else if (((char_idx >= UDSC_CHAR_UDS_AGE) && (char_idx <= UDSC_CHAR_UDS_TWO_ZONE_HEART_RATE_LIMITS)) + || (char_idx == UDSC_CHAR_UDS_USER_INDEX)) + { + // uint8 + data[0] = p_param->value.uint8; + length = 1; + } + else + { + // other??? + co_write32p(&data[0], p_param->value.db_chg_inc); + length = 4; + } + + // Send the write request + prf_gatt_write(&(p_udsc_env->prf_env), conidx, handle, p_data, length, GATTC_WRITE); + + // Go to the Busy state + ke_state_set(dest_id, UDSC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + udsc_send_cmp_evt(p_udsc_env, conidx, UDSC_WRITE_CHAR_OP_CODE, status); + } + } + else if (state == UDSC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSC_WR_USER_CTRL_PT_CMD message. + * Allows the application to write new CCC values to a Characteristic in the peer server + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udsc_wr_user_ctrl_pt_cmd_handler(ke_msg_id_t const msgid, + struct udsc_wr_user_ctrl_pt_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t conidx = KE_IDX_GET(dest_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Get the address of the environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + // Get connection index + + if (state == UDSC_IDLE) + { + ASSERT_INFO(p_udsc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_udsc_env->p_env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t handle = ATT_INVALID_SEARCH_HANDLE; + // Service + struct prf_svc *p_svc = &p_udsc_env->p_env[conidx]->uds.svc; + // Length + uint8_t length; + uint8_t data[UDS_USER_CTRL_PT_MAX_LEN]; + uint8_t *p_data = &data[0]; + + handle = p_udsc_env->p_env[conidx]->uds.chars[UDSC_CHAR_UDS_USER_CTRL_PT].val_hdl; + + // Check if handle is viable + if ((handle != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_udsc_env->p_env[conidx]->op_pending = UDSC_WRITE_CHAR_OP_CODE; + // keep the characteristic in operation + p_udsc_env->p_env[conidx]->last_char_code = UDSC_CHAR_UDS_USER_CTRL_PT; + + data[0] = p_param->op_code; + if (p_param->op_code == UDS_OP_CODE_REGISTER_NEW_USER) + { + length = 3; // op-code and consent code + co_write16p(&data[1], p_param->consent); + } + else if (p_param->op_code == UDS_OP_CODE_CONSENT) + { + length = 4; // op-code, user_id and consent code + data[1] = p_param->user_id; + co_write16p(&data[2], p_param->consent); + } + else if (p_param->op_code == UDS_OP_CODE_DELETE_USER_DATA) + { + length = 1; // op-code + } + else + { + // reserved commands - for the future extension + if (p_param->length >= UDS_USER_CTRL_PT_MAX_LEN - 1) //sizeof(op-code) + { + p_param->length = 0; + } + + length = 1 + p_param->length; + + if (p_param->length) + { + memcpy(&data[1], &p_param->parameter[0], p_param->length); + } + } + + // Send the write request + prf_gatt_write(&(p_udsc_env->prf_env), conidx, handle, p_data, length, GATTC_WRITE); + + // Go to the Busy state + ke_state_set(dest_id, UDSC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + udsc_send_cmp_evt(p_udsc_env, conidx, UDSC_WRITE_CHAR_OP_CODE, status); + } + } + else if (state == UDSC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + do + { + // Get the address of the environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + // Status + uint8_t status; + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (p_udsc_env == NULL) + { + break; + } + + if (state == UDSC_DISCOVERING_SVC) + { + if ((p_param->status == GAP_ERR_NO_ERROR) || (p_param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)) + { + // Check service (if found) + if(p_udsc_env->p_env[conidx]->nb_svc) + { + // Check service (mandatory) + status = prf_check_svc_char_validity(UDSC_CHAR_UDS_MAX, + p_udsc_env->p_env[conidx]->uds.chars, + udsc_uds_char); + + // Check Descriptors (mandatory) + if(status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(UDSC_DESC_UDS_MAX, + p_udsc_env->p_env[conidx]->uds.descs, + udsc_uds_char_desc, + p_udsc_env->p_env[conidx]->uds.chars); + } + } + } + + // Raise an ESP_ENABLE_REQ complete event. + ke_state_set(dest_id, UDSC_IDLE); + + udsc_enable_rsp_send(p_udsc_env, conidx, p_param->status); + } + else if (state == UDSC_BUSY) + { + uint8_t op_pending = p_udsc_env->p_env[conidx]->op_pending; + + status = p_param->status; + switch (p_param->operation) + { + case GATTC_READ: + { + // Send the complete event status + udsc_send_cmp_evt(p_udsc_env, conidx, op_pending, status); + + p_udsc_env->p_env[conidx]->op_pending = 0; + ke_state_set(dest_id, UDSC_IDLE); + } break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + // Send the complete event status + udsc_send_cmp_evt(p_udsc_env, conidx, op_pending, p_param->status); + ke_state_set(dest_id, UDSC_IDLE); + + } break; + + case GATTC_REGISTER: + { + if (status != GAP_ERR_NO_ERROR) + { + // Send the complete event error status + udsc_send_cmp_evt(p_udsc_env, conidx, GATTC_REGISTER, p_param->status); + } + // Go to connected state + ke_state_set(dest_id, UDSC_IDLE); + } break; + + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + } while (0); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + do + { + // Get the address of the environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_udsc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_udsc_env->p_env[conidx] != NULL, dest_id, src_id); + + // Find the op_pending - and check it is a valid read code. + uint8_t op_pending = p_udsc_env->p_env[conidx]->op_pending;; + // retrieve the characteristic in operation + uint8_t char_idx = p_udsc_env->p_env[conidx]->last_char_code; + + if (ke_state_get(dest_id) != UDSC_BUSY) + { + break; + } + + if ((op_pending < UDSC_READ_CHAR_OP_CODE) || (op_pending > UDSC_READ_CCC_OP_CODE)) + { + break; + } + + switch (op_pending) + { + case UDSC_READ_CHAR_OP_CODE: + { + if (char_idx <= UDSC_CHAR_UDS_LANGUAGE) + { + //utf8 + uint16_t length = p_param->length; + struct udsc_rd_char_utf8_ind *p_ind = KE_MSG_ALLOC_DYN(UDSC_RD_CHAR_UTF8_IND, + prf_dst_task_get(&(p_udsc_env->prf_env), conidx), + dest_id, + udsc_rd_char_utf8_ind, length); + + p_ind->char_idx = char_idx; + p_ind->utf_name.length = p_param->length; + + for (int i = 0; i < p_ind->utf_name.length; i++) + { + p_ind->utf_name.name[i] = p_param->value[i]; + } + + ke_msg_send(p_ind); + // Keep the Busy state to be treated in gattc_cmp_evt_handler + } + else + { + struct udsc_rd_char_ind *p_ind = KE_MSG_ALLOC(UDSC_RD_CHAR_IND, + prf_dst_task_get(&(p_udsc_env->prf_env), conidx), + dest_id, + udsc_rd_char_ind); + + p_ind->char_idx = char_idx; + + if (char_idx == UDSC_CHAR_UDS_DB_CHG_INC) + { + // DB CHG Inc + p_ind->value.db_chg_inc = co_read32p(&p_param->value[0]); + } + else if (char_idx == UDSC_CHAR_UDS_FIVE_ZONE_HEART_RATE_LIMITS) + { + // Set + p_ind->value.set[0] = p_param->value[0]; + p_ind->value.set[1] = p_param->value[1]; + p_ind->value.set[2] = p_param->value[2]; + p_ind->value.set[3] = p_param->value[3]; + } + else if (char_idx == UDSC_CHAR_UDS_THREE_ZONE_HEART_RATE_LIMITS) + { + // Set + p_ind->value.set[0] = p_param->value[0]; + p_ind->value.set[1] = p_param->value[1]; + } + else if ((char_idx >= UDSC_CHAR_UDS_DATE_OF_BIRTH) && + (char_idx <= UDSC_CHAR_UDS_DATE_OF_THRESHOLD_ASSESSMENT)) + { + // Date + p_ind->value.date.year = co_read16p(&p_param->value[0]); + p_ind->value.date.month = p_param->value[2]; + p_ind->value.date.day = p_param->value[3]; + } + else if ((char_idx >= UDSC_CHAR_UDS_WEIGHT) && (char_idx <= UDSC_CHAR_UDS_HIP_CIRCUMFERENCE)) + { + // uint16 + p_ind->value.uint16 = co_read16p(&p_param->value[0]); + } + else if (((char_idx >= UDSC_CHAR_UDS_AGE) && + (char_idx <= UDSC_CHAR_UDS_TWO_ZONE_HEART_RATE_LIMITS)) || + (char_idx == UDSC_CHAR_UDS_USER_INDEX)) + { + // uint8 + p_ind->value.uint8 = p_param->value[0]; + } + else + { + // other??? + p_ind->value.db_chg_inc = co_read32p(&p_param->value[0]); + } + + ke_msg_send(p_ind); + // Keep the Busy state to be treated in gattc_cmp_evt_handler + } + } break; + + case UDSC_READ_CCC_OP_CODE : + { + struct udsc_rd_char_ccc_ind *p_ind = KE_MSG_ALLOC(UDSC_RD_CHAR_CCC_IND, + prf_dst_task_get(&(p_udsc_env->prf_env), conidx), + dest_id, + udsc_rd_char_ccc_ind); + + p_ind->char_idx = char_idx; + p_ind->ccc = co_read16p(&p_param->value[0]); + + ke_msg_send(p_ind); + // Keep the Busy state to be treated in gattc_cmp_evt_handler + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + } while (0); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + do + { + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + + if (p_udsc_env == NULL) + { + break; + } + + switch (p_param->type) + { + case (GATTC_NOTIFY): + { + if (p_param->handle == p_udsc_env->p_env[conidx]->uds.chars[UDSC_CHAR_UDS_DB_CHG_INC].val_hdl) + { + struct udsc_db_chg_inc_ind *p_ind = KE_MSG_ALLOC(UDSC_DB_CHG_INC_IND, + prf_dst_task_get(&p_udsc_env->prf_env, conidx), + prf_src_task_get(&p_udsc_env->prf_env, conidx), + udsc_db_chg_inc_ind); + + p_ind->value = co_read32p(&p_param->value[0]); + ke_msg_send(p_ind); + } + // else ignore the Notify as Att-Handle is invalid + } break; + + case (GATTC_INDICATE): + { + struct gattc_event_cfm *p_cfm; + + if (p_param->handle == p_udsc_env->p_env[conidx]->uds.chars[UDSC_CHAR_UDS_USER_CTRL_PT].val_hdl) + { + struct udsc_user_ctrl_pt_ind *p_ind; + uint16_t length = 0; + + if (p_param->length > 3) + { + length = p_param->length - 3; + } + + if (length >= UDS_USER_CTRL_PT_MAX_LEN - 3) //sizeof(op-code+length) + { + length = UDS_USER_CTRL_PT_MAX_LEN - 3; + } + + p_ind = KE_MSG_ALLOC_DYN(UDSC_USER_CTRL_PT_IND, + prf_dst_task_get(&p_udsc_env->prf_env, conidx), + prf_src_task_get(&p_udsc_env->prf_env, conidx), + udsc_user_ctrl_pt_ind, length); + + // decode message + p_ind->resp_code = p_param->value[0]; // response op-code =0x20 + p_ind->req_op_code = p_param->value[1]; // requested op-code + p_ind->resp_value = p_param->value[2]; + p_ind->user_id = UDS_USER_ID_UNKNOWN_USER; + + if ((p_ind->req_op_code == UDS_OP_CODE_REGISTER_NEW_USER) && + (p_ind->resp_value == UDS_OP_RESPONSE_SUCCESS)) + { + p_ind->user_id = p_param->value[3]; + + if (length) + { + length--; + } + } + + if (length) + { + memcpy(&p_ind->parameter[0], &p_param->value[3], length); + } + + p_ind->length = length; + + ke_msg_send(p_ind); + } + + // confirm that indication has been correctly received + p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + + } while (0); + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(udsc) +{ + {UDSC_ENABLE_REQ, (ke_msg_func_t)udsc_enable_req_handler}, + + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + + {UDSC_RD_CHAR_CMD, (ke_msg_func_t)udsc_rd_char_cmd_handler}, + {UDSC_RD_CHAR_CCC_CMD, (ke_msg_func_t)udsc_rd_char_ccc_cmd_handler}, + {UDSC_WR_CHAR_CMD, (ke_msg_func_t)udsc_wr_char_cmd_handler}, + {UDSC_WR_CHAR_UTF8_CMD, (ke_msg_func_t)udsc_wr_char_utf8_cmd_handler}, + {UDSC_WR_USER_CTRL_PT_CMD, (ke_msg_func_t)udsc_wr_user_ctrl_pt_cmd_handler}, + {UDSC_WR_CHAR_CCC_CMD, (ke_msg_func_t)udsc_wr_char_ccc_cmd_handler}, +}; + +void udsc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct udsc_env_tag *p_udsc_env = PRF_ENV_GET(UDSC, udsc); + + p_task_desc->msg_handler_tab = udsc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(udsc_msg_handler_tab); + p_task_desc->state = p_udsc_env->state; + p_task_desc->idx_max = UDSC_IDX_MAX; +} + +#endif //(BLE_UDS_CLIENT) + +/// @} UDSCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/api/udss_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/api/udss_task.h new file mode 100644 index 0000000..9074144 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/api/udss_task.h @@ -0,0 +1,264 @@ +/** + **************************************************************************************** + * + * @file udss_task.h + * + * @brief Header file - User Data Service Profile Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _UDSS_TASK_H_ +#define _UDSS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup ENVSTASK Task + * @ingroup ENVS + * @brief User Data Service Profile Task. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_UDS_SERVER) +#include "uds_common.h" + +#include +#include "ke_task.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Used in Complete event to indicate the operation +enum udss_op_codes +{ + UDSS_RESERVED_OP_CODE = 0, + UDSS_READ_OP_CODE = 1, + UDSS_WRITE_OP_CODE = 2, + UDSS_INDICATE_OP_CODE = 3, + UDSS_NOTIFY_OP_CODE = 4 +}; + +/// Messages for User Data Service Profile Sensor +/*@TRACE*/ +enum udss_msg_id +{ + /// Enable the Service task - at connection + UDSS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_UDSS), + /// Response to Enable the Service task - at connection + UDSS_ENABLE_RSP, + + /// Send String Characteristic write update to the APP + UDSS_WR_CHAR_UTF8_REQ_IND, + /// Send Rest Characteristic write update to the APP + UDSS_WR_CHAR_REQ_IND, + + /// write confirmation Characteristic from the APP + UDSS_WR_CHAR_CFM, + + /// Send Rest Characteristic Read Request to the APP + UDSS_RD_CHAR_REQ_IND, + + /// Read confirmation String Characteristic from the APP + UDSS_RD_CHAR_UTF8_CFM, + /// Read confirmation Characteristic from the APP + UDSS_RD_CHAR_CFM, + + /// Write DB_Change Inc Characteristic CCC update to the APP + UDSS_WR_CHAR_CCC_IND, + + /// Indication DB_Change Inc Characteristic from the APP + UDSS_DB_CHG_INC_NOTIFY_CMD, + + /// Send User Control_Point Characteristic write update to the APP + UDSS_WR_USER_CTRL_PT_REQ_IND, + /// Indication User Control_Point Characteristic from the APP + UDSS_USER_CTRL_PT_INDICATE_CMD, + + /// Send a complete event status to the application + UDSS_CMP_EVT, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the initialization function +/// bitmask of enabled Characteristics ref@ uds_char_id +struct udss_db_cfg +{ + /// Database configuration + uint32_t char_mask; + +#ifdef USE_EXTRA_CHARS + // extra UUID to support + uint16_t UUID1; + uint16_t UUID2; +#endif //def USE_EXTRA_CHARS +}; + +/* + * Messages Exchange Parameters + **************************************************************************************** + */ + +/// Parameters of the @ref UDSS_ENABLE_REQ message +struct udss_enable_req +{ + /// Database Change Increment CCC + uint16_t db_chg_inc_ccc; + /// User Control Point CCC + uint16_t user_ctrl_pt_ccc; +}; + +/// Parameters of the @ref UDSS_ENABLE_RSP message +struct udss_enable_rsp +{ + /// Operation Status + uint8_t status; +}; + +/// Parameters of the @ref UDSS_WR_CHAR_UTF8_REQ_IND message +struct udss_wr_char_utf8_req_ind +{ + /// characteristic id @ref uds_char_id + uint8_t char_idx; + /// offset (do we need this for long messages) + uint8_t offset; + /// Actual data for the string utf8 characteristic + struct utf_8_name utf_name; +}; + +/// Parameters of the @ref UDSS_WR_CHAR_REQ_IND message +struct udss_wr_char_req_ind +{ + /// characteristic id @ref uds_char_id + uint8_t char_idx; + /// data for the characteristic + union char_val value; +}; + +/// Parameters of the @ref UDSS_WR_CHAR_CFM message +struct udss_wr_char_cfm +{ + /// characteristic id @ref uds_char_id + uint8_t char_idx; + /// Operation Status + uint8_t status; +}; + +/// Parameters of the @ref UDSS_RD_CHAR_REQ_IND message +struct udss_rd_char_req_ind +{ + /// characteristic id @ref uds_char_id + uint8_t char_idx; +}; + +/// Parameters of the @ref UDSS_RD_CHAR_UTF8_CFM message +struct udss_rd_char_utf8_cfm +{ + /// characteristic id @ref uds_char_id + uint8_t char_idx; + /// Operation Status + uint8_t status; + /// Actual data for the string utf8 characteristic + struct utf_8_name utf_name; +}; + +/// Parameters of the @ref UDSS_RD_CHAR_CFM message +struct udss_rd_char_cfm +{ + /// characteristic id @ref uds_char_id + uint8_t char_idx; + /// Operation Status + uint8_t status; + /// data for the characteristic + union char_val value; +}; + +/// Parameters of the @ref UDSS_WR_CHAR_CCC_IND message +struct udss_wr_char_ccc_ind +{ + /// characteristic id @ref uds_char_id + uint8_t char_idx; + /// Characteristic CCC + uint16_t ind_cfg; +}; + +/// Parameters of the @ref UDSS_DB_CHG_INC_NOTIFY_CMD message +struct udss_db_chg_inc_notify_cmd +{ + /// characteristic value + uint32_t value; +}; + +/// Parameters of the @ref UDSS_WR_USER_CTRL_PT_REQ_IND message +struct udss_wr_user_ctrl_pt_req_ind +{ + /// User Control Point Op Code @see enum uds_ctrl_pt_op_code + uint8_t op_code; + /// User index + uint8_t user_id; + /// Used for sending consent command + uint16_t consent; + /// Parameter length + uint8_t length; + /// for the future extension to send additional commands + uint8_t parameter[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref UDSS_WR_USER_CTRL_PT_CFM message +struct udss_wr_user_ctrl_pt_cfm +{ + /// Operation Status + uint8_t status; +}; + +/// Parameters of the @ref UDSS_USER_CTRL_PT_INDICATE_CMD message +struct udss_user_ctrl_pt_indicate_cmd +{ + /// response op-code =0x20 + uint8_t resp_code; + /// Request Op Code + uint8_t req_op_code; + /// Response Value + uint8_t resp_value; + /// Length of response parameter + uint8_t length; + /// Response parameter + uint8_t parameter[__ARRAY_EMPTY]; +}; + +/* + * Confirmation to the APP after Update, Indicate, Notify messages + **************************************************************************************** + */ +/// Parameters of the @ref UDSS_CMP_EVT message +struct udss_cmp_evt +{ + /// Operation Code + uint8_t operation; + /// Operation Status + uint8_t status; +}; + +#endif //(BLE_UDS_SERVER) + +/// @} ENVSTASK + +#endif //(_UDSS_TASK_H_) + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/sourcelist.txt new file mode 100644 index 0000000..c6b228d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2016 +# +#*************************************************************************************** + + udss.c + udss_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/src/udss.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/src/udss.c new file mode 100644 index 0000000..4bed6a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/src/udss.c @@ -0,0 +1,774 @@ +/** + **************************************************************************************** + * + * @file udss.c + * + * @brief User Data Service Profile implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup UDSS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_UDS_SERVER) +#include "uds_common.h" + +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" + +#include "udss.h" +#include "udss_task.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ +/// default read perm +#define RD_P (PERM(RD, ENABLE) | PERM(RP, NO_AUTH)) +/// default write perm +#define WR_P (PERM(WRITE_REQ, ENABLE) | PERM(WP, AUTH)) +/// default notify perm +#define NTF_P (PERM(NTF, ENABLE) | PERM(NP, AUTH)) +/// ind perm +#define IND_P (PERM(IND, ENABLE) | PERM(IP, AUTH)) + +#define WR_P_UA (PERM(WRITE_REQ, ENABLE) | PERM(WP, UNAUTH)) +/// extended Descriptor Present +#define EXT_P (PERM(EXT,ENABLE)) +/// enable Read Indication (1 = Value not present in Database) +#define RI_P (PERM(RI, ENABLE)) + +/// Full UDSS Database Description - Used to add attributes into the database +const struct attm_desc udss_att_db[] = +{ + // ATT UUID | Permission | EXT PERM | MAX ATT SIZE + // User Data Service Service Declaration + [UDSS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, RD_P, 0, 0}, + + // DataBase Index Increment Characteristic Declaration + [UDSS_IDX_DB_CHG_INC_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // DataBase Index Increment Characteristic Value + [UDSS_IDX_DB_CHG_INC_VAL] = {ATT_CHAR_DATABASE_CHANGE_INCREMENT, RD_P |WR_P |NTF_P, RI_P, sizeof(uint32_t)}, + // Client Characteristic Configuration Descriptor + [UDSS_IDX_DB_CHG_INC_DESC_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, RD_P | WR_P, RI_P , UDSS_CCC_SIZE}, + + // User Index Characteristic Declaration + [UDSS_IDX_USER_INDEX_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Index Characteristic Value + [UDSS_IDX_USER_INDEX_VAL] = {ATT_CHAR_USER_INDEX, RD_P, RI_P, sizeof(uint8_t)}, + + // User Control Point Characteristic Declaration + [UDSS_IDX_USER_CTRL_PT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Control Point Characteristic Value + [UDSS_IDX_USER_CTRL_PT_VAL] = {ATT_CHAR_USER_CONTROL_POINT , WR_P | IND_P, 0, UDS_USER_CTRL_PT_MAX_LEN}, + // Client Characteristic Configuration Descriptor + [UDSS_IDX_USER_CTRL_PT_DESC_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, RD_P | WR_P, RI_P, UDSS_CCC_SIZE}, + + // Strings: utf8s + // User Data Characteristic Declaration + [UDS_IDX_FIRST_NAME_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P | EXT_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_FIRST_NAME_VAL] = {ATT_CHAR_FIRST_NAME, RD_P | WR_P, RI_P, UDSS_STRING_MAX_SIZE}, + // Characteristic Extended Properties Descriptor + [UDS_IDX_FIRST_NAME_EXT] = {ATT_DESC_CHAR_EXT_PROPERTIES, RD_P, 0, UDSS_EXT_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_LAST_NAME_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P | EXT_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_LAST_NAME_VAL] = {ATT_CHAR_LAST_NAME, RD_P | WR_P , RI_P, UDSS_STRING_MAX_SIZE}, + // Characteristic Extended Properties Descriptor + [UDS_IDX_LAST_NAME_EXT] = {ATT_DESC_CHAR_EXT_PROPERTIES, RD_P, 0, UDSS_EXT_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_EMAIL_ADDRESS_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P | EXT_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_EMAIL_ADDRESS_VAL] = {ATT_CHAR_EMAIL_ADDRESS, RD_P | WR_P, RI_P, UDSS_STRING_MAX_SIZE}, + // Characteristic Extended Properties Descriptor + [UDS_IDX_EMAIL_ADDRESS_EXT] = {ATT_DESC_CHAR_EXT_PROPERTIES, RD_P, 0, UDSS_EXT_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_LANGUAGE_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P | EXT_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_LANGUAGE_VAL] = {ATT_CHAR_LANGUAGE, RD_P | WR_P, RI_P, UDSS_STRING_MAX_SIZE}, + // Characteristic Extended Properties Descriptor + [UDS_IDX_LANGUAGE_EXT] = {ATT_DESC_CHAR_EXT_PROPERTIES, RD_P, 0, UDSS_EXT_SIZE}, + + // Date: + // User Data Characteristic Declaration + [UDS_IDX_DATE_OF_BIRTH_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_DATE_OF_BIRTH_VAL] = {ATT_CHAR_DATE_OF_BIRTH, RD_P | WR_P, RI_P, UDSS_DATE_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_DATE_OF_THRESHOLD_ASSESSMENT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_DATE_OF_THRESHOLD_ASSESSMENT_VAL] + = {ATT_CHAR_DATE_OF_THRESHOLD_ASSESSMENT, RD_P | WR_P , RI_P, UDSS_DATE_MAX_SIZE}, + + // uint16: + // User Data Characteristic Declaration + [UDS_IDX_WEIGHT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_WEIGHT_VAL] = {ATT_CHAR_WEIGHT, RD_P | WR_P, RI_P, UDSS_UINT16_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_HEIGHT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_HEIGHT_VAL] = {ATT_CHAR_HEIGHT, RD_P | WR_P, RI_P, UDSS_UINT16_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_WAIST_CIRCUMFERENCE_CHAR]= {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_WAIST_CIRCUMFERENCE_VAL] = {ATT_CHAR_WAIST_CIRCUMFERENCE, RD_P | WR_P, RI_P, UDSS_UINT16_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_HIP_CIRCUMFERENCE_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_HIP_CIRCUMFERENCE_VAL] = {ATT_CHAR_HIP_CIRCUMFERENCE, RD_P | WR_P, RI_P, UDSS_UINT16_MAX_SIZE}, + + // uint8: + // User Data Characteristic Declaration + [UDS_IDX_AGE_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_AGE_VAL] = {ATT_CHAR_AGE, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_GENDER_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_GENDER_VAL] = {ATT_CHAR_GENDER, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_VO2_MAX_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_VO2_MAX_VAL] = {ATT_CHAR_VO2_MAX, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_MAX_HEART_RATE_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_MAX_HEART_RATE_VAL] = {ATT_CHAR_MAX_HEART_RATE, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_RESTING_HEART_RATE_CHAR]= {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_RESTING_HEART_RATE_VAL] = {ATT_CHAR_RESTING_HEART_RATE, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_MAXIMUM_RECOMMENDED_HEART_RATE_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_MAXIMUM_RECOMMENDED_HEART_RATE_VAL] = + {ATT_CHAR_MAXIMUM_RECOMMENDED_HEART_RATE, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_AEROBIC_THRESHHOLD_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_AEROBIC_THRESHHOLD_VAL] = {ATT_CHAR_AEROBIC_THRESHHOLD, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_ANAEROBIC_THRESHHOLD_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_ANAEROBIC_THRESHHOLD_VAL] = {ATT_CHAR_ANAEROBIC_THRESHHOLD, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_CHAR] = + {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + + // User Data Characteristic Value + [UDS_IDX_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_VAL] = + {ATT_CHAR_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS , RD_P | WR_P , RI_P , UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_FAT_BURN_HEART_RATE_LOWER_LIMIT_CHAR] = + {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_FAT_BURN_HEART_RATE_LOWER_LIMIT_VAL] = + {ATT_CHAR_FAT_BURN_HEART_RATE_LOWER_LIMIT ,RD_P | WR_P, RI_P , UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_FAT_BURN_HEART_RATE_UPPER_LIMIT_CHAR] = + {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + + // User Data Characteristic Value + [UDS_IDX_FAT_BURN_HEART_RATE_UPPER_LIMIT_VAL] = + {ATT_CHAR_FAT_BURN_HEART_RATE_UPPER_LIMIT, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_AEROBIC_HEART_RATE_LOWER_LIMIT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_AEROBIC_HEART_RATE_LOWER_LIMIT_VAL] + = {ATT_CHAR_AEROBIC_HEART_RATE_LOWER_LIMIT , RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_AEROBIC_HEART_RATE_UPPER_LIMIT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_AEROBIC_HEART_RATE_UPPER_LIMIT_VAL] + = {ATT_CHAR_AEROBIC_HEART_RATE_UPPER_LIMIT , RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_ANAEROBIC_HEART_RATE_LOWER_LIMIT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_ANAEROBIC_HEART_RATE_LOWER_LIMIT_VAL] + = {ATT_CHAR_ANAEROBIC_HEART_RATE_LOWER_LIMIT, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_ANAEROBIC_HEART_RATE_UPPER_LIMIT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_ANAEROBIC_HEART_RATE_UPPER_LIMIT_VAL] + = {ATT_CHAR_ANAEROBIC_HEART_RATE_UPPER_LIMIT, RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_TWO_ZONE_HEART_RATE_LIMIT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_TWO_ZONE_HEART_RATE_LIMIT_VAL] + = {ATT_CHAR_TWO_ZONE_HEART_RATE_LIMIT , RD_P | WR_P, RI_P, UDSS_UINT8_MAX_SIZE}, + + // set: + // User Data Characteristic Declaration + [UDS_IDX_FIVE_ZONE_HEART_RATE_LIMITS_CHAR]={ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_FIVE_ZONE_HEART_RATE_LIMITS_VAL] + = {ATT_CHAR_FIVE_ZONE_HEART_RATE_LIMITS , RD_P | WR_P, RI_P, 4 * UDSS_UINT8_MAX_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_THREE_ZONE_HEART_RATE_LIMITS_CHAR]={ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_THREE_ZONE_HEART_RATE_LIMITS_VAL] + = {ATT_CHAR_THREE_ZONE_HEART_RATE_LIMITS , RD_P | WR_P, RI_P, 2 * UDSS_UINT8_MAX_SIZE}, + +#ifdef USE_EXTRA_CHARS + // User Data Characteristic Declaration + [UDS_IDX_USER_DEFINED_1_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P | EXT_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_USER_DEFINED_1_VAL] = {ATT_CHAR_LANGUAGE, RD_P | WR_P, RI_P, UDSS_STRING_MAX_SIZE}, + // Characteristic Extended Properties Descriptor + [UDS_IDX_USER_DEFINED_1_EXT] = {ATT_DESC_CHAR_EXT_PROPERTIES, RD_P, 0, UDSS_EXT_SIZE}, + + // User Data Characteristic Declaration + [UDS_IDX_USER_DEFINED_2_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P | EXT_P, 0, 0}, + // User Data Characteristic Value + [UDS_IDX_USER_DEFINED_2_VAL] = {ATT_CHAR_LANGUAGE, RD_P | WR_P, RI_P, UDSS_STRING_MAX_SIZE}, + // Characteristic Extended Properties Descriptor + [UDS_IDX_USER_DEFINED_2_EXT] = {ATT_DESC_CHAR_EXT_PROPERTIES, RD_P, 0, UDSS_EXT_SIZE}, +#endif //def USE_EXTRA_CHARS +}; + +uint8_t udss_char_2_handle(uint16_t *p_handle_raw, uint8_t char_id) +{ + struct udss_env_tag *p_udss_env = PRF_ENV_GET(UDSS, udss); + uint16_t handle = p_udss_env->shdl; + + switch(char_id) + { + // DataBase Change Increment + case UDS_CHAR_ID_DB_CHG_INC: + { + handle += UDSS_IDX_DB_CHG_INC_VAL; + } break; + + // User Index + case UDS_CHAR_ID_USER_INDEX: + { + handle += UDSS_IDX_USER_INDEX_VAL; + } break; + + // User Control Point + case UDS_CHAR_ID_USER_CTRL_PT: + { + handle += UDSS_IDX_USER_CTRL_PT_VAL; + } break; + + default: + { + // bitfield of enabled characteristics + uint32_t mask = p_udss_env->char_mask; + int i; + + //move to the first Characteristic handle + handle += UDS_IDX_FIRST_NAME_VAL; + + if ((char_id >= UDS_CHAR_ID_DB_CHG_INC) || ((mask & ( (uint32_t)1<>= 1; + char_id --; + } + + if (char_id) + { + // next 24 characteristics have 2 attributes(handles) + for (i =0 ; i < (UDS_CHAR_ID_THREE_ZONE_HEART_RATE_LIMITS - UDS_CHAR_ID_DATE_OF_BIRTH + 1); i++) + { + if (char_id == 0) + { + break; + } + + if (mask & 1) + { + handle += 2; + } + + mask >>= 1; + char_id --; + } + } + + // still not found + if (char_id) + { + return ATT_ERR_INVALID_HANDLE; + } + + } break; + } + + *p_handle_raw = handle; + + return ATT_ERR_NO_ERROR; +} + +uint8_t udss_handle_2_char(uint16_t handle_raw) +{ + // result Characteristic Index + uint8_t res_char = UDS_CHAR_ID_UNKNOWN; + struct udss_env_tag *p_udss_env = PRF_ENV_GET(UDSS, udss); + uint16_t handle = handle_raw - p_udss_env->shdl; + + switch(handle) + { + // DataBase Change Increment + case UDSS_IDX_DB_CHG_INC_VAL: + { + res_char = UDS_CHAR_ID_DB_CHG_INC; + } break; + + // User Index + case UDSS_IDX_USER_INDEX_VAL: + { + res_char = UDS_CHAR_ID_USER_INDEX; + } break; + + // User Control Point + case UDSS_IDX_USER_CTRL_PT_VAL: + { + res_char = UDS_CHAR_ID_USER_CTRL_PT; + } break; + + default: + { + if (handle > UDSS_IDX_USER_CTRL_PT_DESC_CCC) + { + int8_t char_id = 0; // count for the characteristic + uint32_t mask = p_udss_env->char_mask; // bitfield of enabled characteristics + int i; + + handle -= UDS_IDX_FIRST_NAME_CHAR; // extract all permanent characteristics + + // first 4 characteristics have 3 attributes(handles) + for (i = 0; i < (UDS_CHAR_ID_LANGUAGE - UDS_CHAR_ID_FIRST_NAME + 1); i++) + { + if (mask & 1) + { + if (handle >= 3) + { + handle -= 3; + } + else + { + res_char = char_id; + return res_char; + } + } + char_id ++; + mask >>= 1; + } + + // next 24 characteristics have 2 attributes(handles) + for (i = 0; i < (UDS_CHAR_ID_THREE_ZONE_HEART_RATE_LIMITS - UDS_CHAR_ID_DATE_OF_BIRTH + 1); i++) + { + if (mask & 1) + { + if (handle >= 2) + { + handle -= 2; + } + else + { + res_char = char_id; + return res_char; + } + } + + char_id ++; + mask >>= 1; + } + } + } break; + } + + return res_char; +} + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the UDSS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ + +static uint8_t udss_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct udss_db_cfg *p_param) +{ + //------------------ create the attribute database for the profile ------------------- + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + // temp index + int i; + + // Bitfield for the ATT database + // mask of enabled attributes per Characteristic + uint16_t flag; + // keeps bit position of the next bit placing + uint16_t bit_start; + uint8_t byte_offs; + uint8_t flag_shift; + uint32_t bitmask; + + // Service attribute flags + uint8_t cfg_flag[12]; + uint32_t mask = p_param->char_mask; // bitfield of enabled characteristics + + memset(&cfg_flag[0], 0, sizeof(cfg_flag)); + // Mandatory Characteristics + cfg_flag[0] = 0xff; + cfg_flag[1] = 0x01; + + bit_start = 9; + // Optional + // first 4 characteristics have 3 attributes(handles) + flag = 0x07; // 3 attributes per characteristic + + for (i = 0; i < (UDS_CHAR_ID_LANGUAGE - UDS_CHAR_ID_FIRST_NAME + 1); i++) + { + if (mask & 1) + { + //Find the byte to put the next enables attributes bitfield in 'flag' + byte_offs = bit_start/BITS_IN_BYTE; + // the start bit in this byte to start writing + flag_shift = bit_start - (byte_offs*BITS_IN_BYTE); + bitmask = flag << flag_shift; //prepare bitfield + cfg_flag[byte_offs] |= (uint8_t)(bitmask & 0xff); + + if ((bitmask>>BITS_IN_BYTE) & 0xff) + { + cfg_flag[byte_offs+1] |= (uint8_t)((bitmask >> BITS_IN_BYTE) & 0xff); + } + } + + mask >>= 1; + //shift by the number of bits as the count of all attributes per characteristic + bit_start += (UDS_IDX_LAST_NAME_CHAR - UDS_IDX_FIRST_NAME_CHAR); + } + + // next 24 characteristics have 2 attributes(handles) + flag = 0x03; // 2 attributes per characteristic + + for (i = 0; i < (UDS_CHAR_ID_THREE_ZONE_HEART_RATE_LIMITS - UDS_CHAR_ID_DATE_OF_BIRTH + 1); i++) + { + if (mask & 1) + { + //Find the byte to put the next enables attributes bitfield in 'flag' + byte_offs = bit_start/BITS_IN_BYTE; + // the start bit in this byte to start writing + flag_shift = bit_start - (byte_offs*BITS_IN_BYTE); + bitmask = flag << flag_shift; //prepare bitfield + cfg_flag[byte_offs] |= (uint8_t)(bitmask & 0xff); + + if ((bitmask>>BITS_IN_BYTE) & 0xff) + { + cfg_flag[byte_offs+1] |= (uint8_t)((bitmask>>BITS_IN_BYTE) & 0xff); + } + } + + mask >>= 1; + //shift by the number of bits as the count of all attributes per characteristic + bit_start += (UDS_IDX_HEIGHT_CHAR - UDS_IDX_WEIGHT_CHAR); + } + + // Add service in the database + status = attm_svc_create_db(p_start_hdl, ATT_SVC_USER_DATA, &cfg_flag[0], + UDSS_IDX_ATT_NB, NULL, p_env->task, &udss_att_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS)) | PERM(SVC_MI, ENABLE)); + + // Check if an error has occurred + if (status == ATT_ERR_NO_ERROR) + { + // Allocate UDSS required environment variable + struct udss_env_tag *p_udss_env = + (struct udss_env_tag *) ke_malloc(sizeof(struct udss_env_tag), KE_MEM_ATT_DB); + // fill default EXT descriptor of the characteristics + uint8_t value[2]; + uint8_t ext_handles[] = {UDS_IDX_FIRST_NAME_EXT,UDS_IDX_LAST_NAME_EXT, + UDS_IDX_EMAIL_ADDRESS_EXT,UDS_IDX_LANGUAGE_EXT}; + + // Initialize UDSS environment + p_env->env = (prf_env_t *) p_udss_env; + p_udss_env->shdl = *p_start_hdl; + p_udss_env->char_mask = p_param->char_mask; + + // Mono Instantiated APP task + p_udss_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Multi Instantiated task + p_udss_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_UDSS; + udss_task_init(&(p_env->desc)); + + // If we are here, database has been fulfilled with success, go to idle state + for (uint8_t idx = 0; idx < BLE_CONNECTION_MAX ; idx++) + { + // Put UDSS in disabled state + ke_state_set(KE_BUILD_ID(p_env->task, idx), UDSS_STATE_FREE); + } + + // prepare the value for the extended descriptor + co_write16p(&value[0], ATT_EXT_WRITABLE_AUX); + // for every characteristic in the list + for (i = 0; i < sizeof(ext_handles) ; i++) + { + if (p_param->char_mask & (1<task, conidx), UDSS_STATE_FREE); + +} + +/** + **************************************************************************************** + * @brief Destruction of the UDSS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void udss_destroy(struct prf_task_env *p_env) +{ + struct udss_env_tag *p_udss_env = (struct udss_env_tag *) p_env->env; + + // free profile environment variables + p_env->env = NULL; + ke_free(p_udss_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void udss_create(struct prf_task_env *p_env, uint8_t conidx) +{ + //struct udss_env_tag* p_udss_env = (struct udss_env_tag*) env->env; + ke_state_set(KE_BUILD_ID(p_env->task, conidx), UDSS_STATE_IDLE); +} + +uint8_t udss_pack_char_value(uint8_t char_id, union char_val *p_value, uint8_t *p_data, uint16_t *p_length) +{ + uint16_t length = 0; + uint8_t status = GAP_ERR_NO_ERROR; + + switch(char_id) + { + // Date + case UDS_CHAR_ID_DATE_OF_BIRTH: + case UDS_CHAR_ID_DATE_OF_THRESHOLD_ASSESSMENT: + { + co_write16p(&p_data[0], p_value->date.year); + p_data[2] = p_value->date.month; + p_data[3] = p_value->date.day; + length = 4; + } break; + + // uint16 + case UDS_CHAR_ID_WEIGHT: + case UDS_CHAR_ID_HEIGHT: + case UDS_CHAR_ID_WAIST_CIRCUMFERENCE: + case UDS_CHAR_ID_HIP_CIRCUMFERENCE: + { + co_write16p(&p_data[0], p_value->uint16); + length = 2; + } break; + + // uint8 + case UDS_CHAR_ID_AGE: + case UDS_CHAR_ID_GENDER: + case UDS_CHAR_ID_VO2_MAX: + case UDS_CHAR_ID_MAX_HEART_RATE: + case UDS_CHAR_ID_RESTING_HEART_RATE: + case UDS_CHAR_ID_MAXIMUM_RECOMMENDED_HEART_RATE: + case UDS_CHAR_ID_AEROBIC_THRESHOLD: + case UDS_CHAR_ID_ANAEROBIC_THRESHOLD: + case UDS_CHAR_ID_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS: + case UDS_CHAR_ID_FAT_BURN_HEART_RATE_LOWER_LIMIT: + case UDS_CHAR_ID_FAT_BURN_HEART_RATE_UPPER_LIMIT: + case UDS_CHAR_ID_AEROBIC_HEART_RATE_LOWER_LIMIT: + case UDS_CHAR_ID_AEROBIC_HEART_RATE_UPPER_LIMIT: + case UDS_CHAR_ID_ANAEROBIC_HEART_RATE_LOWER_LIMIT: + case UDS_CHAR_ID_ANAEROBIC_HEART_RATE_UPPER_LIMIT: + case UDS_CHAR_ID_TWO_ZONE_HEART_RATE_LIMITS: + { + p_data[0] = p_value->uint8; + length = 1; + } break; + + // set + case UDS_CHAR_ID_FIVE_ZONE_HEART_RATE_LIMITS: + { + p_data[0] = p_value->set[0]; + p_data[1] = p_value->set[1]; + p_data[2] = p_value->set[2]; + p_data[3] = p_value->set[3]; + length = 4; + } break; + + case UDS_CHAR_ID_THREE_ZONE_HEART_RATE_LIMITS: + { + p_data[0] = p_value->set[0]; + p_data[1] = p_value->set[1]; + length = 2; + } break; + + case UDS_CHAR_ID_DB_CHG_INC: + { + co_write32p(&p_data[0], p_value->db_chg_inc); + length = 4; + } break; + + case UDS_CHAR_ID_USER_INDEX: + { + p_data[0] = p_value->user_idx; + length = 1; + } break; + + // no packing for these Characteristics - done separately + case UDS_CHAR_ID_USER_CTRL_PT: + // Strings: utf8s + case UDS_CHAR_ID_FIRST_NAME: + case UDS_CHAR_ID_LAST_NAME: + case UDS_CHAR_ID_EMAIL_ADDRESS: + case UDS_CHAR_ID_LANGUAGE: + default: + { + status = PRF_ERR_INVALID_PARAM; + } break; + } + + (*p_length) += length; + + return status; +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// UDSS Task interface required by profile manager +const struct prf_task_cbs udss_itf = +{ + (prf_init_fnct) udss_init, + udss_destroy, + udss_create, + udss_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* udss_prf_itf_get(void) +{ + return &udss_itf; +} + + +#endif //(BLE_UDS_SERVER) + +/// @} UDSS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/src/udss.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/src/udss.h new file mode 100644 index 0000000..e39cdb9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/src/udss.h @@ -0,0 +1,279 @@ +/** + **************************************************************************************** + * + * @file udss.h + * + * @brief Header file - User Data Service Profile Sensor. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _UDSS_H_ +#define _UDSS_H_ + +/** + **************************************************************************************** + * @addtogroup ENVS User Data Service Profile Sensor + * @ingroup ENVS + * @brief User Data Service Profile Sensor + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_UDS_SERVER) +#include "uds_common.h" +#include "udss_task.h" + +#include "prf_types.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of User Data Service Profile role task instances +#define UDSS_IDX_MAX (BLE_CONNECTION_MAX) + +/// used to calculate bitmask for attribute database +#define BITS_IN_BYTE (8) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + /// Possible states of the TIPS task +enum +{ + /// not connected state + UDSS_STATE_FREE, + /// idle state + UDSS_STATE_IDLE, + /// read ind + UDSS_STATE_OP_READ, + /// write ind + UDSS_STATE_OP_WRITE, + /// indicate + UDSS_STATE_OP_INDICATE, + /// Notify + UDSS_STATE_OP_NOTIFY, + + /// Number of defined states. + UDSS_STATE_MAX +}; + +/// User Data Service - Attribute List +enum udss_desc_idx +{ + /// User Data Service + UDSS_IDX_SVC = 0, + /// DataBase Change Increment + UDSS_IDX_DB_CHG_INC_CHAR, + /// value + UDSS_IDX_DB_CHG_INC_VAL, + /// CCC descriptor + UDSS_IDX_DB_CHG_INC_DESC_CCC, + /// User Index + UDSS_IDX_USER_INDEX_CHAR, + /// value + UDSS_IDX_USER_INDEX_VAL, + /// User Control Point + UDSS_IDX_USER_CTRL_PT_CHAR, + /// value + UDSS_IDX_USER_CTRL_PT_VAL, + /// CCC descriptor + UDSS_IDX_USER_CTRL_PT_DESC_CCC, + + /// Strings: utf8s + UDS_IDX_FIRST_NAME_CHAR, + UDS_IDX_FIRST_NAME_VAL, + UDS_IDX_FIRST_NAME_EXT, + UDS_IDX_LAST_NAME_CHAR, + UDS_IDX_LAST_NAME_VAL, + UDS_IDX_LAST_NAME_EXT, + UDS_IDX_EMAIL_ADDRESS_CHAR, + UDS_IDX_EMAIL_ADDRESS_VAL, + UDS_IDX_EMAIL_ADDRESS_EXT, + UDS_IDX_LANGUAGE_CHAR, + UDS_IDX_LANGUAGE_VAL, + UDS_IDX_LANGUAGE_EXT, + /// Date + UDS_IDX_DATE_OF_BIRTH_CHAR, + UDS_IDX_DATE_OF_BIRTH_VAL, + UDS_IDX_DATE_OF_THRESHOLD_ASSESSMENT_CHAR, + UDS_IDX_DATE_OF_THRESHOLD_ASSESSMENT_VAL, + /// uint16 + UDS_IDX_WEIGHT_CHAR, + UDS_IDX_WEIGHT_VAL, + UDS_IDX_HEIGHT_CHAR, + UDS_IDX_HEIGHT_VAL, + UDS_IDX_WAIST_CIRCUMFERENCE_CHAR, + UDS_IDX_WAIST_CIRCUMFERENCE_VAL, + UDS_IDX_HIP_CIRCUMFERENCE_CHAR, + UDS_IDX_HIP_CIRCUMFERENCE_VAL, + /// uint8 + UDS_IDX_AGE_CHAR, + UDS_IDX_AGE_VAL, + UDS_IDX_GENDER_CHAR, + UDS_IDX_GENDER_VAL, + UDS_IDX_VO2_MAX_CHAR, + UDS_IDX_VO2_MAX_VAL, + UDS_IDX_MAX_HEART_RATE_CHAR, + UDS_IDX_MAX_HEART_RATE_VAL, + UDS_IDX_RESTING_HEART_RATE_CHAR, + UDS_IDX_RESTING_HEART_RATE_VAL, + UDS_IDX_MAXIMUM_RECOMMENDED_HEART_RATE_CHAR, + UDS_IDX_MAXIMUM_RECOMMENDED_HEART_RATE_VAL, + UDS_IDX_AEROBIC_THRESHHOLD_CHAR, + UDS_IDX_AEROBIC_THRESHHOLD_VAL, + UDS_IDX_ANAEROBIC_THRESHHOLD_CHAR, + UDS_IDX_ANAEROBIC_THRESHHOLD_VAL, + UDS_IDX_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_CHAR, + UDS_IDX_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS_VAL, + UDS_IDX_FAT_BURN_HEART_RATE_LOWER_LIMIT_CHAR, + UDS_IDX_FAT_BURN_HEART_RATE_LOWER_LIMIT_VAL, + UDS_IDX_FAT_BURN_HEART_RATE_UPPER_LIMIT_CHAR, + UDS_IDX_FAT_BURN_HEART_RATE_UPPER_LIMIT_VAL, + UDS_IDX_AEROBIC_HEART_RATE_LOWER_LIMIT_CHAR, + UDS_IDX_AEROBIC_HEART_RATE_LOWER_LIMIT_VAL, + UDS_IDX_AEROBIC_HEART_RATE_UPPER_LIMIT_CHAR, + UDS_IDX_AEROBIC_HEART_RATE_UPPER_LIMIT_VAL, + UDS_IDX_ANAEROBIC_HEART_RATE_LOWER_LIMIT_CHAR, + UDS_IDX_ANAEROBIC_HEART_RATE_LOWER_LIMIT_VAL, + UDS_IDX_ANAEROBIC_HEART_RATE_UPPER_LIMIT_CHAR, + UDS_IDX_ANAEROBIC_HEART_RATE_UPPER_LIMIT_VAL, + UDS_IDX_TWO_ZONE_HEART_RATE_LIMIT_CHAR, + UDS_IDX_TWO_ZONE_HEART_RATE_LIMIT_VAL, + /// set + UDS_IDX_FIVE_ZONE_HEART_RATE_LIMITS_CHAR, + UDS_IDX_FIVE_ZONE_HEART_RATE_LIMITS_VAL, + UDS_IDX_THREE_ZONE_HEART_RATE_LIMITS_CHAR, + UDS_IDX_THREE_ZONE_HEART_RATE_LIMITS_VAL, + +#ifdef USE_EXTRA_CHARS + UDS_IDX_USER_DEFINED_1_CHAR, + UDS_IDX_USER_DEFINED_1_VAL, + UDS_IDX_USER_DEFINED_1_EXT, + UDS_IDX_USER_DEFINED_2_CHAR, + UDS_IDX_USER_DEFINED_2_VAL, + UDS_IDX_USER_DEFINED_2_EXT, +#endif //def USE_EXTRA_CHARS + + UDSS_IDX_ATT_NB +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// on-going operation +struct udss_operation +{ + /// Handle impacted by operation + uint16_t handle; +}; + +/// User Data Service Profile environment variable +struct udss_env_tag +{ + /// profile environment + prf_env_t prf_env; + + /// User Data Service Service Start Handle + uint16_t shdl; + + /// On-going operation (requested by peer device) + struct udss_operation op[BLE_CONNECTION_MAX]; + + /// State of different task instances + ke_state_t state[UDSS_IDX_MAX]; + + /// Database configuration - Keeps enabled User Data Characteristics + uint32_t char_mask; + /// CCC + uint16_t db_chg_inc_ccc[BLE_CONNECTION_MAX]; + uint16_t user_ctrl_pt_ccc[BLE_CONNECTION_MAX]; +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief convert Characteristic type to 'handle' + * + * @param[in] char_id Characteristic type index see @enum uds_char_id. + * @param[out] p_handle_raw Handle from the GATT request. + * + * @return ATT_ERR_INVALID_HANDLE if this characteristic is not present. + **************************************************************************************** + */ +uint8_t udss_char_2_handle(uint16_t *p_handle_raw, uint8_t char_id); + +/** + **************************************************************************************** + * @brief Converts Handle into Characteristic type and instance. + * + * @param[in] handle_raw Handle from the GATT request. + * + * @return Characteristic type index see @enum uds_char_id. + **************************************************************************************** + */ +uint8_t udss_handle_2_char(uint16_t handle_raw); + +/** + **************************************************************************************** + * @brief Pack Characteristic value depending on Characteristic type + * + * @param[in] char_id - Characteristic Type. + * @param[in] p_value - Structure that keep Characteristic vales. + * @param[out] p_data - Output buffer for packed data. + * @param[out] p_plength - Length of the encoded data. + * + * @return status of the operation. + **************************************************************************************** + */ +uint8_t udss_pack_char_value(uint8_t char_id, union char_val *p_val, uint8_t *p_data, uint16_t *p_length); + +/** + **************************************************************************************** + * @brief Retrieve ENVS service profile interface + * + * @return ENVS service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* udss_prf_itf_get(void); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void udss_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_UDS_SERVER) + +/// @} ENVS + +#endif //(_UDSS_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/src/udss_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/src/udss_task.c new file mode 100644 index 0000000..ca35d8f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/uds/udss/src/udss_task.c @@ -0,0 +1,1084 @@ +/** + **************************************************************************************** + * + * @file udss_task.c + * + * @brief User Data Service Profile Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup UDSSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_UDS_SERVER) +#include "uds_common.h" + +#include "gapc.h" +#include "gattc_task.h" +#include "attm.h" + +#include "udss.h" +#include "udss_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + + // check that task is in idle state + if (ke_state_get(dest_id) == UDSS_STATE_IDLE) + { + // Get the address of the environment + struct udss_env_tag *p_udss_env = PRF_ENV_GET(UDSS, udss); + uint8_t conidx = KE_IDX_GET(src_id); + uint8_t att_idx = p_param->handle - p_udss_env->shdl; + // get the char_idx and dec + uint8_t uds_char_id; + + switch(att_idx) + { + case UDSS_IDX_DB_CHG_INC_DESC_CCC: + case UDSS_IDX_USER_CTRL_PT_DESC_CCC: + { + // Send data to peer device + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + src_id, dest_id, gattc_read_cfm, UDSS_CCC_SIZE); + + p_cfm->handle = p_param->handle; + p_cfm->length = UDSS_CCC_SIZE; + p_cfm->status = GAP_ERR_NO_ERROR; + + co_write16p(p_cfm->value, att_idx == UDSS_IDX_DB_CHG_INC_DESC_CCC ? + p_udss_env->db_chg_inc_ccc[conidx] : p_udss_env->user_ctrl_pt_ccc[conidx]); + + ke_msg_send(p_cfm); + } break; + + default: + { + // retrieve handle information + uds_char_id = udss_handle_2_char(p_param->handle); + + if (uds_char_id != UDS_CHAR_ID_UNKNOWN) + { + struct udss_rd_char_req_ind *p_ind = KE_MSG_ALLOC(UDSS_RD_CHAR_REQ_IND, + prf_dst_task_get(&(p_udss_env->prf_env), conidx), + dest_id, + udss_rd_char_req_ind); + + // Characteristic idx @ref uds_char_id + p_ind->char_idx = uds_char_id; + + // Send the request indication to the application + ke_msg_send(p_ind); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_READ); + } + else + { + // Fill data + struct gattc_read_cfm *p_cfm = KE_MSG_ALLOC(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm); + + p_cfm->handle = p_param->handle; + p_cfm->length = 0; + p_cfm->status = ATT_ERR_REQUEST_NOT_SUPPORTED; + + ke_msg_send(p_cfm); + } + } break; + } + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct udss_env_tag *p_udss_env = PRF_ENV_GET(UDSS, udss); + uint8_t att_idx = p_param->handle - p_udss_env->shdl; + struct gattc_att_info_cfm *p_cfm; + // get the char_idx and dec + uint8_t uds_char_id = udss_handle_2_char(p_param->handle); + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + p_cfm->status = GAP_ERR_NO_ERROR; + + switch (att_idx) + { + case UDSS_IDX_DB_CHG_INC_DESC_CCC: + case UDSS_IDX_USER_CTRL_PT_DESC_CCC: + { + p_cfm->length = UDSS_CCC_SIZE; + } break; + + default: + { + // retrieve handle information + uds_char_id = udss_handle_2_char(p_param->handle); + + switch(uds_char_id) + { + // Strings: utf8s + case UDS_CHAR_ID_FIRST_NAME : + case UDS_CHAR_ID_LAST_NAME : + case UDS_CHAR_ID_EMAIL_ADDRESS: + case UDS_CHAR_ID_LANGUAGE : + { + p_cfm->length = UDSS_STRING_MAX_SIZE; + } break; + + // Date + case UDS_CHAR_ID_DATE_OF_BIRTH : + case UDS_CHAR_ID_DATE_OF_THRESHOLD_ASSESSMENT: + { + p_cfm->length = UDSS_DATE_MAX_SIZE; + } break; + + // uint16 + case UDS_CHAR_ID_WEIGHT : + case UDS_CHAR_ID_HEIGHT : + case UDS_CHAR_ID_WAIST_CIRCUMFERENCE: + case UDS_CHAR_ID_HIP_CIRCUMFERENCE : + { + p_cfm->length = sizeof(uint16_t); + } break; + + // uint8 + case UDS_CHAR_ID_AGE : + case UDS_CHAR_ID_GENDER : + case UDS_CHAR_ID_VO2_MAX : + case UDS_CHAR_ID_MAX_HEART_RATE : + case UDS_CHAR_ID_RESTING_HEART_RATE : + case UDS_CHAR_ID_MAXIMUM_RECOMMENDED_HEART_RATE : + case UDS_CHAR_ID_AEROBIC_THRESHOLD : + case UDS_CHAR_ID_ANAEROBIC_THRESHOLD : + case UDS_CHAR_ID_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS: + case UDS_CHAR_ID_FAT_BURN_HEART_RATE_LOWER_LIMIT : + case UDS_CHAR_ID_FAT_BURN_HEART_RATE_UPPER_LIMIT : + case UDS_CHAR_ID_AEROBIC_HEART_RATE_LOWER_LIMIT : + case UDS_CHAR_ID_AEROBIC_HEART_RATE_UPPER_LIMIT : + case UDS_CHAR_ID_ANAEROBIC_HEART_RATE_LOWER_LIMIT : + case UDS_CHAR_ID_ANAEROBIC_HEART_RATE_UPPER_LIMIT : + case UDS_CHAR_ID_TWO_ZONE_HEART_RATE_LIMITS : + { + p_cfm->length = sizeof(uint8_t); + } break; + + // set + case UDS_CHAR_ID_FIVE_ZONE_HEART_RATE_LIMITS : + { + p_cfm->length = 4; + } break; + + // set + case UDS_CHAR_ID_THREE_ZONE_HEART_RATE_LIMITS: + { + p_cfm->length = 2; + } break; + + // Uint32 + case UDS_CHAR_ID_DB_CHG_INC: + { + p_cfm->length = sizeof(uint32_t); + } break; + + // Control Point + case UDS_CHAR_ID_USER_CTRL_PT: + { + p_cfm->length = UDS_USER_CTRL_PT_MAX_LEN; + } break; + + default: + { + // not expected request + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } break; + } + } break; + } + + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct udss_env_tag *p_udss_env = PRF_ENV_GET(UDSS, udss); + uint8_t conidx = KE_IDX_GET(src_id); + // Message status + int msg_status = KE_MSG_CONSUMED; + // Status + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t att_idx = p_param->handle - p_udss_env->shdl; + + do + { + // Check the connection handle + if (p_udss_env == NULL) + { + break; + } + + // check that task is in idle state + if (ke_state_get(dest_id) == UDSS_STATE_IDLE) + { + // get the char_idx and dec + uint8_t uds_char_id; + + switch(att_idx) + { + case UDSS_IDX_DB_CHG_INC_DESC_CCC: + case UDSS_IDX_USER_CTRL_PT_DESC_CCC: + { + // Get the value + uint16_t ntf_cfg = co_read16p(&p_param->value[0]); + struct udss_wr_char_ccc_ind *p_ind; + struct gattc_write_cfm *p_cfm; + + if (att_idx == UDSS_IDX_DB_CHG_INC_DESC_CCC) + { + p_udss_env->db_chg_inc_ccc[conidx] = ntf_cfg; + } + else + { + p_udss_env->user_ctrl_pt_ccc[conidx] = ntf_cfg; + } + + // Inform the HL about the new configuration + p_ind = KE_MSG_ALLOC(UDSS_WR_CHAR_CCC_IND, + prf_dst_task_get(&p_udss_env->prf_env, conidx), + prf_src_task_get(&p_udss_env->prf_env, conidx), + udss_wr_char_ccc_ind); + + p_ind->char_idx = (att_idx == UDSS_IDX_DB_CHG_INC_DESC_CCC ? + UDS_CHAR_ID_DB_CHG_INC : UDS_CHAR_ID_USER_CTRL_PT); + p_ind->ind_cfg = ntf_cfg; + + ke_msg_send(p_ind); + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } break; + + default: + { + // retrieve handle information + uds_char_id = udss_handle_2_char(p_param->handle); + + switch (uds_char_id) + { + // Strings: utf8s + case UDS_CHAR_ID_FIRST_NAME: + case UDS_CHAR_ID_LAST_NAME: + case UDS_CHAR_ID_EMAIL_ADDRESS: + case UDS_CHAR_ID_LANGUAGE: + { + // Allocate a request indication message for the application + struct udss_wr_char_utf8_req_ind *p_req_ind = KE_MSG_ALLOC_DYN(UDSS_WR_CHAR_UTF8_REQ_IND, + prf_dst_task_get(&p_udss_env->prf_env, conidx), + dest_id, + udss_wr_char_utf8_req_ind, p_param->length); + + // Characteristic idx @ref uds_char_idx + p_req_ind->char_idx = uds_char_id; + // Characteristic String + p_req_ind->offset = p_param->offset; + p_req_ind->utf_name.length = p_param->length; + // actual data for the attribute + memcpy(&p_req_ind->utf_name.name[0], p_param->value, p_param->length); + + // Send the request indication to the application + ke_msg_send(p_req_ind); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_WRITE); + } break; + + // Date + case UDS_CHAR_ID_DATE_OF_BIRTH: + case UDS_CHAR_ID_DATE_OF_THRESHOLD_ASSESSMENT: + { + // Allocate a request indication message for the application + struct udss_wr_char_req_ind *p_req_ind = KE_MSG_ALLOC(UDSS_WR_CHAR_REQ_IND, + prf_dst_task_get(&p_udss_env->prf_env, conidx), + dest_id, + udss_wr_char_req_ind); + + // Characteristic idx @ref uds_char_idx + p_req_ind->char_idx = uds_char_id; + // Characteristic Date + p_req_ind->value.date.year = co_read16p(&p_param->value[0]); + p_req_ind->value.date.month = p_param->value[2]; + p_req_ind->value.date.day = p_param->value[3]; + + // Send the request indication to the application + ke_msg_send(p_req_ind); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_WRITE); + } break; + + // uint16 + case UDS_CHAR_ID_WEIGHT: + case UDS_CHAR_ID_HEIGHT: + case UDS_CHAR_ID_WAIST_CIRCUMFERENCE: + case UDS_CHAR_ID_HIP_CIRCUMFERENCE: + { + // Allocate a request indication message for the application + struct udss_wr_char_req_ind *p_req_ind = KE_MSG_ALLOC(UDSS_WR_CHAR_REQ_IND, + prf_dst_task_get(&p_udss_env->prf_env, conidx), + dest_id, + udss_wr_char_req_ind); + + // Characteristic idx @ref uds_char_idx + p_req_ind->char_idx = uds_char_id; + // Characteristic Uint16 + p_req_ind->value.uint16 = co_read16p(&p_param->value[0]); + + // Send the request indication to the application + ke_msg_send(p_req_ind); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_WRITE); + } break; + + // uint8 + case UDS_CHAR_ID_AGE: + case UDS_CHAR_ID_GENDER: + case UDS_CHAR_ID_VO2_MAX: + case UDS_CHAR_ID_MAX_HEART_RATE: + case UDS_CHAR_ID_RESTING_HEART_RATE: + case UDS_CHAR_ID_MAXIMUM_RECOMMENDED_HEART_RATE: + case UDS_CHAR_ID_AEROBIC_THRESHOLD: + case UDS_CHAR_ID_ANAEROBIC_THRESHOLD: + case UDS_CHAR_ID_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS: + case UDS_CHAR_ID_FAT_BURN_HEART_RATE_LOWER_LIMIT: + case UDS_CHAR_ID_FAT_BURN_HEART_RATE_UPPER_LIMIT: + case UDS_CHAR_ID_AEROBIC_HEART_RATE_LOWER_LIMIT: + case UDS_CHAR_ID_AEROBIC_HEART_RATE_UPPER_LIMIT: + case UDS_CHAR_ID_ANAEROBIC_HEART_RATE_LOWER_LIMIT: + case UDS_CHAR_ID_ANAEROBIC_HEART_RATE_UPPER_LIMIT: + case UDS_CHAR_ID_TWO_ZONE_HEART_RATE_LIMITS: + { + // Allocate a request indication message for the application + struct udss_wr_char_req_ind *p_req_ind = KE_MSG_ALLOC(UDSS_WR_CHAR_REQ_IND, + prf_dst_task_get(&p_udss_env->prf_env, conidx), + dest_id, + udss_wr_char_req_ind); + + // Characteristic idx @ref uds_char_idx + p_req_ind->char_idx = uds_char_id; + // Characteristic Uint8 + p_req_ind->value.uint8 = p_param->value[0]; + + // Send the request indication to the application + ke_msg_send(p_req_ind); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_WRITE); + } break; + + // set + case UDS_CHAR_ID_FIVE_ZONE_HEART_RATE_LIMITS : + { + // Allocate a request indication message for the application + struct udss_wr_char_req_ind *p_req_ind = KE_MSG_ALLOC(UDSS_WR_CHAR_REQ_IND, + prf_dst_task_get(&p_udss_env->prf_env, conidx), + dest_id, + udss_wr_char_req_ind); + + // Characteristic idx @ref uds_char_idx + p_req_ind->char_idx = uds_char_id; + // Characteristic Uint8 + p_req_ind->value.set[0] = p_param->value[0]; + p_req_ind->value.set[1] = p_param->value[1]; + p_req_ind->value.set[2] = p_param->value[2]; + p_req_ind->value.set[3] = p_param->value[3]; + + // Send the request indication to the application + ke_msg_send(p_req_ind); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_WRITE); + } break; + + // set + case UDS_CHAR_ID_THREE_ZONE_HEART_RATE_LIMITS: + { + // Allocate a request indication message for the application + struct udss_wr_char_req_ind *p_req_ind = KE_MSG_ALLOC(UDSS_WR_CHAR_REQ_IND, + prf_dst_task_get(&p_udss_env->prf_env, conidx), + dest_id, + udss_wr_char_req_ind); + + // Characteristic idx @ref uds_char_idx + p_req_ind->char_idx = uds_char_id; + // Characteristic Uint8 + p_req_ind->value.set[0] = p_param->value[0]; + p_req_ind->value.set[1] = p_param->value[1]; + + // Send the request indication to the application + ke_msg_send(p_req_ind); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_WRITE); + } break; + + // Uint32 + case UDS_CHAR_ID_DB_CHG_INC: + { + // Allocate a request indication message for the application + struct udss_wr_char_req_ind *p_req_ind = KE_MSG_ALLOC(UDSS_WR_CHAR_REQ_IND, + prf_dst_task_get(&p_udss_env->prf_env, conidx), + dest_id, + udss_wr_char_req_ind); + + // Characteristic idx @ref uds_char_idx + p_req_ind->char_idx = uds_char_id; + // Characteristic Uint32 + p_req_ind->value.db_chg_inc = co_read32p(&p_param->value[0]); + + // Send the request indication to the application + ke_msg_send(p_req_ind); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_WRITE); + } break; + + // User Control Point + case UDS_CHAR_ID_USER_CTRL_PT: + { + uint8_t op_code = p_param->value[0]; + uint16_t length = 0; + struct udss_wr_user_ctrl_pt_req_ind *p_req_ind; + + if ((op_code == UDS_OP_CODE_REGISTER_NEW_USER) + || (op_code == UDS_OP_CODE_CONSENT) + || (op_code == UDS_OP_CODE_DELETE_USER_DATA)) + { + length = 0; + } + else + { + // unknown op-code - let app decide + // reserved commands - for the future extension + if (p_param->length >= UDS_USER_CTRL_PT_MAX_LEN - 1) //sizeof(op-code) + { + length = 0; + } + else if (p_param->length > 1) //op-code + { + length = p_param->length - 1; + } + } + + // check op-code and immediate response + // this would be an APP responsibility as the Indication of error condition after confirmatin message + // Allocate a request indication message for the application + p_req_ind = KE_MSG_ALLOC_DYN(UDSS_WR_USER_CTRL_PT_REQ_IND, + prf_dst_task_get(&p_udss_env->prf_env, conidx), + dest_id, + udss_wr_user_ctrl_pt_req_ind, length); + + // Request op-code + p_req_ind->op_code = p_param->value[0]; + p_req_ind->length = length; + + if (op_code == UDS_OP_CODE_REGISTER_NEW_USER) + { + // op-code and consent code + p_req_ind->consent = co_read16p(&p_param->value[1]); + } + else if (op_code == UDS_OP_CODE_CONSENT) + { + // op-code, user_id and consent code + p_req_ind->user_id = p_param->value[1]; + p_req_ind->consent = co_read16p(&p_param->value[2]); + } + else if (op_code == UDS_OP_CODE_DELETE_USER_DATA) + { + // op-code + } + else + { + if (length) // copy all parameters + { + // Characteristic Parameter + memcpy(&p_req_ind->parameter[0], &p_param->value[1], length); + } + } + + // Send the request indication to the application + ke_msg_send(p_req_ind); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_WRITE); + } break; + + default: //UDS_CHAR_ID_UNKNOWN + { + // Send the write response to the peer device + struct gattc_write_cfm *p_cfm = KE_MSG_ALLOC( + GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + + p_cfm->handle = p_param->handle; + p_cfm->status = ATT_ERR_REQUEST_NOT_SUPPORTED; + + ke_msg_send(p_cfm); + } break; + } + } break; + } + } + else + { + msg_status = KE_MSG_SAVED; + } + } while (0); + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles @ref GATT_NOTIFY_CMP_EVT message meaning that a notification or an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + do + { + uint8_t conidx = KE_IDX_GET(src_id); + // Get the address of the environment + struct udss_env_tag *p_udss_env = PRF_ENV_GET(UDSS, udss); + + if (p_udss_env == NULL) + { + break; + } + + // Check if a connection exists + switch (p_param->operation) + { + case (GATTC_NOTIFY): + { + struct udss_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(UDSS_CMP_EVT, + prf_dst_task_get(&(p_udss_env->prf_env), conidx), + dest_id, udss_cmp_evt); + + p_cmp_evt->operation = UDSS_NOTIFY_OP_CODE; + p_cmp_evt->status = p_param->status; + + ke_msg_send(p_cmp_evt); + + // go to idle state + ke_state_set(dest_id, UDSS_STATE_IDLE); + } break; + + case (GATTC_INDICATE): + { + struct udss_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(UDSS_CMP_EVT, + prf_dst_task_get(&(p_udss_env->prf_env), conidx), + dest_id, udss_cmp_evt); + + p_cmp_evt->operation = UDSS_INDICATE_OP_CODE; + p_cmp_evt->status = p_param->status; + + ke_msg_send(p_cmp_evt); + + // go to idle state + ke_state_set(dest_id, UDSS_STATE_IDLE); + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } while (0); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSS_ENABLE_REQ message. + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udss_enable_req_handler(ke_msg_id_t const msgid, + struct udss_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct udss_env_tag *p_udss_env = PRF_ENV_GET(UDSS, udss); + struct udss_enable_rsp *p_cmp_evt; + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + + if (ke_state_get(dest_id) == UDSS_STATE_IDLE) + { + uint8_t conidx = KE_IDX_GET(src_id); + + p_udss_env->db_chg_inc_ccc[conidx] = p_param->db_chg_inc_ccc; + p_udss_env->user_ctrl_pt_ccc[conidx] = p_param->user_ctrl_pt_ccc; + status = GAP_ERR_NO_ERROR; + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(UDSS_ENABLE_RSP, src_id, dest_id, udss_enable_rsp); + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSS_WR_CHAR_CFM message. Confirmation from the APP. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udss_wr_char_cfm_handler(ke_msg_id_t const msgid, + struct udss_wr_char_cfm *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + + if (ke_state_get(dest_id) == UDSS_STATE_OP_WRITE) + { + // Send data to peer device + struct gattc_write_cfm *p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, + KE_BUILD_ID(TASK_GATTC, KE_IDX_GET(dest_id)), + dest_id, + gattc_write_cfm); + + uint16_t handle; + + // Fill data + udss_char_2_handle(&handle, p_param->char_idx); + + p_cfm->handle = handle; + p_cfm->status = p_param->status; + ke_msg_send(p_cfm); + + // go to idle state + ke_state_set(dest_id, UDSS_STATE_IDLE); + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSS_DB_CHG_INC_NOTIFY_CMD message. APP request to Send IND. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udss_db_chg_inc_notify_cmd_handler(ke_msg_id_t const msgid, + struct udss_db_chg_inc_notify_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + + // check that task is in idle state + if (ke_state_get(dest_id) == UDSS_STATE_IDLE) + { + // Get the address of the environment + struct udss_env_tag *p_udss_env = PRF_ENV_GET(UDSS, udss); + uint8_t conidx = KE_IDX_GET(dest_id); + + //check the CCC + if (p_udss_env->db_chg_inc_ccc[conidx] & ATT_CCC_START_NTF) + { + uint16_t length = sizeof(uint32_t); + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_udss_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + gattc_send_evt_cmd, length); + + // Fill in the p_parameter structure + p_udss_val->operation = GATTC_NOTIFY; + p_udss_val->handle = p_udss_env->shdl + UDSS_IDX_DB_CHG_INC_VAL; + // pack db inc value in database + co_write32p(&p_udss_val->value[0], p_param->value); + p_udss_val->length = length; + + // send notification to peer device + ke_msg_send(p_udss_val); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_NOTIFY); + } + else + { + struct udss_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(UDSS_CMP_EVT, + src_id, + dest_id, udss_cmp_evt); + + p_cmp_evt->operation = UDSS_NOTIFY_OP_CODE; + p_cmp_evt->status = PRF_ERR_NTF_DISABLED; + + ke_msg_send(p_cmp_evt); + } + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSS_USER_CTRL_PT_INDICATE_CMD message. APP request to Send IND. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udss_user_ctrl_pt_indicate_cmd_handler(ke_msg_id_t const msgid, + struct udss_user_ctrl_pt_indicate_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + + // check that task is in idle state + if (ke_state_get(dest_id) == UDSS_STATE_IDLE) + { + // Get the address of the environment + struct udss_env_tag *p_udss_env = PRF_ENV_GET(UDSS, udss); + uint8_t conidx = KE_IDX_GET(dest_id); + + //check the CCC + if (p_udss_env->user_ctrl_pt_ccc[conidx] & ATT_CCC_START_IND) + { + // Mandatory: resp_op-code, req_op-code, resp_value + uint16_t length = 3 + p_param->length; + struct gattc_send_evt_cmd *p_udss_val; + + if (p_param->length > UDS_USER_CTRL_PT_MAX_LEN) + { + length = UDS_USER_CTRL_PT_MAX_LEN; + } + + // Allocate the GATT indication message + p_udss_val = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + gattc_send_evt_cmd, length); + + // Fill in the p_parameter structure + p_udss_val->operation = GATTC_INDICATE; + p_udss_val->handle = p_udss_env->shdl + UDSS_IDX_USER_CTRL_PT_VAL; + // pack cntrl pt value in database + p_udss_val->value[0] = p_param->resp_code; + p_udss_val->value[1] = p_param->req_op_code; + p_udss_val->value[2] = p_param->resp_value; + + // copy all additional parameters + if (length > 3) + { + memcpy(&p_udss_val->value[3], &p_param->parameter[0], length - 3); + } + p_udss_val->length = length; + + // send indication to peer device + ke_msg_send(p_udss_val); + + // go to busy state + ke_state_set(dest_id, UDSS_STATE_OP_INDICATE); + } + else + { + struct udss_cmp_evt *p_cmp_evt = KE_MSG_ALLOC(UDSS_CMP_EVT, + src_id, + dest_id, udss_cmp_evt); + + p_cmp_evt->operation = UDSS_INDICATE_OP_CODE; + p_cmp_evt->status = PRF_ERR_IND_DISABLED; + + ke_msg_send(p_cmp_evt); + } + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSS_RD_CHAR_UTF8_CFM message. APP read response of one of the CCC read. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udss_rd_char_utf8_cfm_handler(ke_msg_id_t const msgid, + struct udss_rd_char_utf8_cfm *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + + if (ke_state_get(dest_id) == UDSS_STATE_OP_READ) + { + struct gattc_read_cfm *p_cfm; + uint16_t length = 0; + uint16_t handle; + + if (p_param->status == GAP_ERR_NO_ERROR) + { + length = p_param->utf_name.length; + } + + // Send data to peer device + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, KE_IDX_GET(dest_id)), + dest_id, + gattc_read_cfm, length); + + udss_char_2_handle(&handle, p_param->char_idx); + + p_cfm->handle = handle; + p_cfm->length = length; + p_cfm->status = p_param->status; + + if (length) + { + memcpy(&p_cfm->value[0], &p_param->utf_name.name[0], length); + } + + ke_msg_send(p_cfm); + + // go to idle state + ke_state_set(dest_id, UDSS_STATE_IDLE); + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref UDSS_RD_CHAR_CFM message. APP read response of one of the CCC read. + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int udss_rd_char_cfm_handler(ke_msg_id_t const msgid, + struct udss_rd_char_cfm *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + + if (ke_state_get(dest_id) == UDSS_STATE_OP_READ) + { + // Send data to peer device + struct gattc_read_cfm *p_cfm; + uint8_t data[sizeof(union char_val)]; + uint16_t length = 0; + uint16_t handle; + + if (p_param->status == GAP_ERR_NO_ERROR) + { + udss_pack_char_value(p_param->char_idx, &p_param->value, &data[0], &length); + } + + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, + KE_BUILD_ID(TASK_GATTC, KE_IDX_GET(dest_id)), + dest_id, + gattc_read_cfm, length); + + udss_char_2_handle(&handle, p_param->char_idx); + + p_cfm->handle = handle; + p_cfm->length = length; + p_cfm->status = p_param->status; + + if (length) + { + memcpy(&p_cfm->value[0], &data[0], length); + } + + ke_msg_send(p_cfm); + + // go to idle state + ke_state_set(dest_id, UDSS_STATE_IDLE); + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return (msg_status); +} + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(udss) +{ + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, + + {UDSS_ENABLE_REQ, (ke_msg_func_t) udss_enable_req_handler}, + {UDSS_WR_CHAR_CFM, (ke_msg_func_t) udss_wr_char_cfm_handler}, + {UDSS_RD_CHAR_UTF8_CFM, (ke_msg_func_t) udss_rd_char_utf8_cfm_handler}, + {UDSS_RD_CHAR_CFM, (ke_msg_func_t) udss_rd_char_cfm_handler}, + {UDSS_DB_CHG_INC_NOTIFY_CMD, (ke_msg_func_t) udss_db_chg_inc_notify_cmd_handler}, + {UDSS_USER_CTRL_PT_INDICATE_CMD,(ke_msg_func_t) udss_user_ctrl_pt_indicate_cmd_handler}, +}; + +void udss_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct udss_env_tag *p_udss_env = PRF_ENV_GET(UDSS, udss); + + p_task_desc->msg_handler_tab = udss_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(udss_msg_handler_tab); + p_task_desc->state = p_udss_env->state; + p_task_desc->idx_max = UDSS_IDX_MAX; +} + +#endif //(BLE_UDS_SERVER) + +/// @} UDSSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wsc_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wsc_common.h new file mode 100644 index 0000000..98fc847 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wsc_common.h @@ -0,0 +1,152 @@ +/** + **************************************************************************************** + * + * @file wscp_common.h + * + * @brief Header File - Weight SCale Profile common types. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _WSCP_COMMON_H_ +#define _WSCP_COMMON_H_ + +/** + **************************************************************************************** + * @addtogroup WSCP Weight SCale Profile + * @ingroup PROFILE + * @brief Weight SCale Profile + * + * The WSCP enables a collector device to connect and interact with a BLE enabled + * Weighing Scale sharing its current and stored weight data. + * + * This file contains all definitions that are common for the server and the client parts + * of the profile. + ***************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_WSC_CLIENT || BLE_WSC_SERVER) +#include "co_math.h" +#include "prf_types.h" + +/* + * DEFINES + **************************************************************************************** + */ +/// Indicate Measurement Unsuccessful to the Client +#define WSC_MEASUREMENT_UNSUCCESSFUL (0xFFFF) +/// All valid bits of Flags field (bit [0:3]) +#define WSC_MEAS_FLAGS_VALID (0xF) +/// Indicate Unknown User, can be used for Guests +#define WSC_MEAS_USER_ID_UNKNOWN_USER (0xFF) +/// Feature value length +#define WCS_FEAT_VAL_LEN (4) +/// Measurement CCC length +#define WCS_MEAS_CCC_LEN (2) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// WSC Feature Support bit field +enum wsc_feat_bf +{ + /// Time Stamp Supported + WSC_FEAT_TIME_STAMP_SUPP_POS = 0, + WSC_FEAT_TIME_STAMP_SUPP_BIT = CO_BIT(WSC_FEAT_TIME_STAMP_SUPP_POS), + + /// Multiple Users Supported + WSC_FEAT_MULTIPLE_USERS_SUPP_POS = 1, + WSC_FEAT_MULTIPLE_USERS_SUPP_BIT = CO_BIT(WSC_FEAT_MULTIPLE_USERS_SUPP_POS), + + /// BMI Supported + WSC_FEAT_BMI_SUPP_POS = 2, + WSC_FEAT_BMI_SUPP_BIT = CO_BIT(WSC_FEAT_BMI_SUPP_POS), + + /// Weight Measurement Resolution bits[3:6] + WSC_FEAT_WGHT_RESOL_LSB = 3, + WSC_FEAT_WGHT_RESOL_MASK = 0x00000078, + + /// Height Measurement Resolution bits[7:9] + WSC_FEAT_HGHT_RESOL_LSB = 7, + WSC_FEAT_HGHT_RESOL_MASK = 0x00000380, +}; + +/// WSC Feature Measurement Weight Resolution values +enum wsc_feat_wght_resol_value +{ + /// Weight Measurement Resolution not specified + WSC_WGHT_RESOL_NOT_SPECIFIED = 0, + /// Resolution of 0.5 kg or 1 lb + WSC_WGHT_RESOL_05kg_1lb = 1, + /// Resolution of 0.2 kg or 0.5 lb + WSC_WGHT_RESOL_02kg_05lb = 2, + /// Resolution of 0.1 kg or 0.2 lb + WSC_WGHT_RESOL_01kg_02lb = 3, + /// Resolution of 0.05 kg or 0.1 lb + WSC_WGHT_RESOL_005kg_01lb = 4, + /// Resolution of 0.02 kg or 0.05 lb + WSC_WGHT_RESOL_002kg_005lb = 5, + /// Resolution of 0.01 kg or 0.02 lb + WSC_WGHT_RESOL_001kg_002lb = 6, + /// Resolution of 0.005 kg or 0.01 lb + WSC_WGHT_RESOL_0005kg_001lb = 7, + /// Reserved for future use 8 - 15 +}; + +/// WSC Feature Measurement Height Resolution values +enum wsc_feat_hght_resol_value +{ + /// Height Measurement Resolution not specified + WSC_HGHT_RESOL_NOT_SPECIFIED = 0, + /// Resolution of 0.01 meter or 1 inch + WSC_HGHT_RESOL_001mtr_1inch = 1, + /// Resolution of 0.005 meter or 0.5 inch + WSC_HGHT_RESOL_0005mtr_05inch = 2, + /// Resolution of 0.001 meter or 0.1 inch + WSC_HGHT_RESOL_0001mtr_01inch = 3, + /// Reserved for future use 4 - 7 + +}; + +/// WSC Measurement Flags bit field +enum wsc_meas_flags_bf +{ + /// Measurement Units (bit 0) + /// 0 for SI (Weight and Mass in units of kilogram (kg) and Height in units of meter) + /// 1 for Imperial (Weight and Mass in units of pound (lb) and Height in units of inch (in)) + WSC_MEAS_FLAGS_UNITS_IMPERIAL_POS = 0, + WSC_MEAS_FLAGS_UNITS_IMPERIAL_BIT = CO_BIT(WSC_MEAS_FLAGS_UNITS_IMPERIAL_POS), + + /// Time stamp present (bit 1) + /// 0 for not present + /// 1 for present + WSC_MEAS_FLAGS_TIMESTAMP_PRESENT_POS = 1, + WSC_MEAS_FLAGS_TIMESTAMP_PRESENT_BIT = CO_BIT(WSC_MEAS_FLAGS_TIMESTAMP_PRESENT_POS), + + /// User ID present (bit 2) + /// 0 for not present + /// 1 for present + WSC_MEAS_FLAGS_USER_ID_PRESENT_POS = 2, + WSC_MEAS_FLAGS_USER_ID_PRESENT_BIT = CO_BIT(WSC_MEAS_FLAGS_USER_ID_PRESENT_POS), + + /// BMI and Height present (bit 3) + /// 0 for not present + /// 1 for present + WSC_MEAS_FLAGS_BMI_PRESENT_POS = 3, + WSC_MEAS_FLAGS_BMI_PRESENT_BIT = CO_BIT(WSC_MEAS_FLAGS_BMI_PRESENT_POS), +}; + + +/// @} wsc_common + +#endif /* (BLE_WSC_CLIENT || BLE_WSC_SERVER) */ + +#endif /* _WSCP_COMMON_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/api/wscc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/api/wscc_task.h new file mode 100644 index 0000000..5c990fb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/api/wscc_task.h @@ -0,0 +1,204 @@ +/** + **************************************************************************************** + * + * @file wscc_task.h + * + * @brief Header file - Weight SCale ProfileCollector/Client Role Task. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _WSCC_TASK_H_ +#define _WSCC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup WSCCTASK Weight Scale Collector Task + * @ingroup WSCC + * @brief Weight SCale ProfileProfile Collector Task + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "wsc_common.h" +#include "rwip_task.h" // Task definitions +#include "prf_types.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Message IDs +/*@TRACE*/ +enum wscc_msg_ids +{ + /// Enable the Profile Collector task - at connection + WSCC_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_WSCC), + /// Response to Enable the Profile Collector task - at connection + WSCC_ENABLE_RSP, + /// Read the Weight Scale Feature + WSCC_RD_FEAT_CMD, + /// Read the CCC of a measurement sensor characteristic + WSCC_RD_MEAS_CCC_CMD, + /// Write the CCC of a measurement sensor characteristic + WSCC_WR_MEAS_CCC_CMD, + /// Read the Weight Scale Feature + WSCC_FEAT_IND, + /// Read the CCC of a measurement sensor characteristic + WSCC_MEAS_CCC_IND, + /// Characteristic Measurement Indication from peer + WSCC_MEAS_IND, + /// Complete Event Information + WSCC_CMP_EVT, +}; + + +/// Weight Scale Service Characteristics +enum wscc_chars +{ + /// Features + WSCC_CHAR_WSS_FEATURE, + /// Measurement + WSCC_CHAR_WSS_MEAS, + + WSCC_CHAR_WSS_MAX, +}; + +/// Weight Scale Service Characteristic Descriptors +enum wscc_descs +{ + /// Client config + WSCC_DESC_WSS_MEAS_CCC, + + WSCC_DESC_WSS_MAX, +}; + +/* + * API MESSAGE STRUCTURES + **************************************************************************************** + */ + +/** + * Structure containing the characteristics handles, value handles and descriptors for + * the Weight Scale Service + */ +struct wscc_wss_content +{ + /// service info + struct prf_svc svc; + + /// Included service info - Body Composition Service.. + struct prf_incl_svc incl_svc; + + /// Characteristic info: + /// - Feature + /// - Measurement + struct prf_char_inf chars[WSCC_CHAR_WSS_MAX]; + + /// Descriptor handles: + /// - Client cfg + struct prf_char_desc_inf descs[WSCC_DESC_WSS_MAX]; +}; + +/// Parameters of the @ref WSCC_ENABLE_REQ message +struct wscc_enable_req +{ + /// Connection type + uint8_t con_type; + /// Existing handle values WSCC ES + struct wscc_wss_content wss; +}; + +/// Parameters of the @ref WSCC_ENABLE_RSP message +struct wscc_enable_rsp +{ + /// status + uint8_t status; + /// Existing handle values WSCC ES + struct wscc_wss_content wss; +}; + +/// Parameters of the @ref WSCC_RD_FEAT_CMD message +/// Read the Weight Scale Feature +struct wscc_rd_feat_cmd +{ + /// NULL +}; + +/// Parameters of the @ref WSCC_RD_MEAS_CCC_CMD message +/// Read the CCC of a measurement sensor characteristic +struct wscc_rd_meas_ccc_cmd +{ + /// NULL +}; + +/// Parameters of the @ref WSCC_WR_MEAS_CCC_CMD message +/// Write the CCC of a measurement sensor characteristic +struct wscc_wr_meas_ccc_cmd +{ + /// Client Characteristic Configuration read value + uint16_t ccc; +}; + +/// Parameters of the @ref WSCC_FEAT_IND message +/// Read the Weight Scale Feature +struct wscc_feat_ind +{ + /// Weight Scale Feature read value + uint32_t feature; +}; + +/// Parameters of the @ref WSCC_MEAS_CCC_IND message +/// Read the CCC of a measurement sensor characteristic +struct wscc_meas_ccc_ind +{ + /// Client Characteristic Configuration read value + uint16_t ccc; +}; + +/// Parameters of the @ref WSCC_MEAS_IND message +/// Characteristic Measurement Indication from peer +struct wscc_meas_ind +{ + /// Presence of optional fields and measurement units + uint8_t flags; + /// Weight value + uint16_t weight; + /// Weight Resolution + uint8_t wght_resol; + /// Measurement Units + uint8_t meas_u; + /// Time stamp value + struct prf_date_time time_stamp; + /// User ID value + uint8_t user_id; + /// Body Mass Index + uint16_t bmi; + /// Height value + uint16_t height; + /// Height Resolution + uint8_t hght_resol; +}; + +/// Parameters of the @ref WSCC_CMP_EVT message +struct wscc_cmp_evt +{ + /// Operation code + uint8_t operation; + /// Status + uint8_t status; +}; + +/// @} WSCCTASK + +#endif //(_WSCC_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/sourcelist.txt new file mode 100644 index 0000000..c15622a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2016 +# +#*************************************************************************************** + + wscc.c + wscc_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/src/wscc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/src/wscc.c new file mode 100644 index 0000000..44d9fed --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/src/wscc.c @@ -0,0 +1,250 @@ +/** + **************************************************************************************** + * + * @file wscc.c + * + * @brief Weight SCale Profile Collector implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup WSCC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_WSC_CLIENT) +#include "prf.h" +#include "wsc_common.h" + +#include "wscc_task.h" +#include "wscc/src/wscc.h" +#include "gap.h" + +#include "ke_mem.h" + +/* + * GLOBAL VARIABLES DECLARATION + **************************************************************************************** + */ + + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the WSCC module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_params Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t wscc_init(struct prf_task_env *p_env, uint16_t *p_start_hdl, + uint16_t app_task, uint8_t sec_lvl, void *p_params) +{ + uint8_t idx; + //-------------------- allocate memory required for the profile --------------------- + + struct wscc_env_tag *p_wscc_env = + (struct wscc_env_tag* ) ke_malloc(sizeof(struct wscc_env_tag), KE_MEM_ATT_DB); + + // allocate WSCC required environment variable + p_env->env = (prf_env_t*) p_wscc_env; + + p_wscc_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + p_wscc_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_WSCC; + wscc_task_init(&(p_env->desc)); + + for(idx = 0; idx < WSCC_IDX_MAX ; idx++) + { + p_wscc_env->env[idx] = NULL; + // service is ready, go into an Idle state + ke_state_set(KE_BUILD_ID(p_env->task, idx), WSCC_FREE); + } + + return GAP_ERR_NO_ERROR; +} + +/** + **************************************************************************************** + * @brief Clean-up connection dedicated environment parameters + * This function performs cleanup of ongoing operations + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void wscc_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct wscc_env_tag *p_wscc_env = (struct wscc_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + if(p_wscc_env->env[conidx] != NULL) + { + if (p_wscc_env->env[conidx]->operation != NULL) + { + ke_free(ke_param2msg(p_wscc_env->env[conidx]->operation)); + } + + ke_free(p_wscc_env->env[conidx]); + p_wscc_env->env[conidx] = NULL; + // No other profiles unregister + } + + /* Put WSCP Client in Free state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), WSCC_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the WSCC module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void wscc_destroy(struct prf_task_env *p_env) +{ + uint8_t idx; + struct wscc_env_tag *p_wscc_env = (struct wscc_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + for(idx = 0; idx < WSCC_IDX_MAX ; idx++) + { + wscc_cleanup(p_env, idx, 0); + } + + // free profile environment variables + p_env->env = NULL; + ke_free(p_wscc_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void wscc_create(struct prf_task_env *p_env, uint8_t conidx) +{ + /* Put WSC Client in Idle state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), WSCC_IDLE); +} + +/// WSCC Task interface required by profile manager +const struct prf_task_cbs wscc_itf = +{ + wscc_init, + wscc_destroy, + wscc_create, + wscc_cleanup, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* wscc_prf_itf_get(void) +{ + return &wscc_itf; +} + +void wscc_enable_rsp_send(struct wscc_env_tag *p_wscc_env, uint8_t conidx, uint8_t status) +{ + // Send to APP the details of the discovered attributes on WSCP + struct wscc_enable_rsp *p_rsp = KE_MSG_ALLOC( + WSCC_ENABLE_RSP, + prf_dst_task_get(&(p_wscc_env->prf_env), conidx), + prf_src_task_get(&(p_wscc_env->prf_env), conidx), + wscc_enable_rsp); + + p_rsp->status = status; + + if (status == GAP_ERR_NO_ERROR) + { + p_rsp->wss = p_wscc_env->env[conidx]->wss; + + // Register WSCC task in gatt for indication/notifications + prf_register_atthdl2gatt(&(p_wscc_env->prf_env), conidx, &(p_wscc_env->env[conidx]->wss.svc)); + // Go to connected state + ke_state_set(prf_src_task_get(&(p_wscc_env->prf_env), conidx), WSCC_BUSY); + } + else + { + memset(&p_rsp->wss, 0 , sizeof(p_rsp->wss)); + // Enabled failed - so go back to the FREE state + ke_state_set(prf_src_task_get(&(p_wscc_env->prf_env), conidx), WSCC_FREE); + } + + ke_msg_send(p_rsp); +} + +void wscc_send_cmp_evt(struct wscc_env_tag *p_wscc_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + struct wscc_cmp_evt *p_evt = NULL; + + // Free the stored operation if needed + if (p_wscc_env->env[conidx]->operation != NULL) + { + ke_msg_free(ke_param2msg(p_wscc_env->env[conidx]->operation)); + p_wscc_env->env[conidx]->operation = NULL; + p_wscc_env->env[conidx]->op_pending = 0; + } + + // Go back to the CONNECTED state if the state is busy + if (ke_state_get(prf_src_task_get(&(p_wscc_env->prf_env), conidx)) == WSCC_BUSY) + { + ke_state_set(prf_src_task_get(&(p_wscc_env->prf_env), conidx), WSCC_IDLE); + } + + // Send the message + p_evt = KE_MSG_ALLOC(WSCC_CMP_EVT, prf_dst_task_get(&(p_wscc_env->prf_env), conidx), + prf_src_task_get(&(p_wscc_env->prf_env), conidx), + wscc_cmp_evt); + + p_evt->operation = operation; + p_evt->status = status; + + ke_msg_send(p_evt); +} + +#endif //(BLE_WSC_CLIENT) + +/// @} WSCC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/src/wscc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/src/wscc.h new file mode 100644 index 0000000..2d2f53e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/src/wscc.h @@ -0,0 +1,174 @@ +/** + **************************************************************************************** + * + * @file wscc.h + * + * @brief Header file - Weight SCale Profile - Collector Role. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _WSCC_H_ +#define _WSCC_H_ + +/** + **************************************************************************************** + * @addtogroup WSCC Weight Scale Profile Collector + * @ingroup WSCP + * @brief Weight Scale Profile Collector + * @{ + **************************************************************************************** + */ + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Weight Scale Task instances +#define WSCC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "wsc_common.h" + +#if (BLE_WSC_CLIENT) + +#include "ke_task.h" +#include "prf_types.h" +#include "prf_utils.h" + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the WSCC task +enum wscc_states +{ + /// Idle state + WSCC_FREE, + /// Connected state + WSCC_IDLE, + /// Discovering Services + WSCC_DISCOVERING_SVC, + /// Busy state + WSCC_BUSY, + /// Number of defined states. + WSCC_STATE_MAX +}; + +/// Operation Codes for pending operations in the client. +enum wscc_op_codes +{ + /// Read op-codes + WSCC_READ_FEAT_OP_CODE = 0, + /// Read op-codes + WSCC_READ_CCC_OP_CODE = 1, + /// Write op-codes. + WSCC_WRITE_CCC_OP_CODE = 2, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Stored Environment content/context information for a connection +struct wscc_cnx_env +{ + /// Current Operation + void *operation; + + /// Pending operation + uint8_t op_pending; + + /// Counter used to check service uniqueness + uint8_t nb_svc; + + /// Weight Scale Service Characteristics + struct wscc_wss_content wss; +}; + +/// Weight Scale environment variable +struct wscc_env_tag +{ + /// profile environment + prf_env_t prf_env; + /// Environment variable pointer for each connections + struct wscc_cnx_env* env[WSCC_IDX_MAX]; + /// State of different task instances + ke_state_t state[WSCC_IDX_MAX]; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Pool of Weight Scale Collector task environments. +extern struct wscc_env_tag **wscc_envs; + +/* + * GLOBAL FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve WSCP client profile interface + * + * @return WSCP client profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* wscc_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Send Weight Scale ATT DB discovery results to WSCC host. + * + * @param[in] p_wscc_env The profile environment for the connection + * @param[in] conidx Connection Identifier + * @param[in] status Indicates the outcome of the operation + **************************************************************************************** + */ +void wscc_enable_rsp_send(struct wscc_env_tag *p_wscc_env, uint8_t conidx, uint8_t status); + +/** + **************************************************************************************** + * @brief Send a WSCC_CMP_EVT message to the task which enabled the profile + * + * @param[in] p_wscc_env The profile environment + * @param[in] conidx Connection Identifier + * @param[in] operation Indicates the operation for which the cmp_evt is being sent. + * @param[in] status Indicates the outcome of the operation + **************************************************************************************** + */ +void wscc_send_cmp_evt(struct wscc_env_tag *p_wscc_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void wscc_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_WSC_CLIENT) + +/// @} WSCC + +#endif //(_WSCC_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/src/wscc_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/src/wscc_task.c new file mode 100644 index 0000000..6884b16 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscc/src/wscc_task.c @@ -0,0 +1,788 @@ +/** + **************************************************************************************** + * + * @file wscc_task.c + * + * @brief Weight SCale Profile Collector Task implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @addtogroup WSCCTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_WSC_CLIENT) +#include "wsc_common.h" +#include "wscc_task.h" +#include "wscc/src/wscc.h" + +#include "gap.h" +#include "attm.h" +#include "gattc_task.h" +#include "ke_mem.h" +#include "co_utils.h" + + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// State machine used to retrieve Weight Scale Service characteristics information +const struct prf_char_def wscc_wss_char[WSCC_CHAR_WSS_MAX] = +{ + [WSCC_CHAR_WSS_FEATURE] = {ATT_CHAR_WEIGHT_SCALE_FEATURE, + ATT_MANDATORY, + (ATT_CHAR_PROP_RD ) }, + + [WSCC_CHAR_WSS_MEAS] = {ATT_CHAR_WEIGHT_MEASUREMENT, + ATT_MANDATORY, + (ATT_CHAR_PROP_IND) }, +}; + +/// State machine used to retrieve Weight Scale Service characteristic description information +const struct prf_char_desc_def wscc_wss_char_desc[WSCC_DESC_WSS_MAX] = +{ + /// Client config + [WSCC_DESC_WSS_MEAS_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, + ATT_MANDATORY, + WSCC_CHAR_WSS_MEAS}, +}; + + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_SDP_SVC_IND_HANDLER message. + * The handler stores the found service details for service discovery. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_ind Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_sdp_svc_ind_handler(ke_msg_id_t const msgid, + struct gattc_sdp_svc_ind const *p_ind, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + do + { + // Weight Scale Collector Role Task Environment + struct wscc_env_tag *p_wscc_env = PRF_ENV_GET(WSCC, wscc); + uint8_t conidx = KE_IDX_GET(dest_id); + + if ((ke_state_get(dest_id) != WSCC_DISCOVERING_SVC) || p_wscc_env == NULL) + { + break; + } + + ASSERT_INFO(p_wscc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_wscc_env->env[conidx] != NULL, dest_id, src_id); + + if(attm_uuid16_comp((unsigned char *)p_ind->uuid, p_ind->uuid_len, ATT_SVC_WEIGHT_SCALE)) + { + uint8_t fnd_att; + + // Retrieve WS characteristics and descriptors + prf_extract_svc_info(p_ind, WSCC_CHAR_WSS_MAX, &wscc_wss_char[0], &p_wscc_env->env[conidx]->wss.chars[0], + WSCC_DESC_WSS_MAX, &wscc_wss_char_desc[0], &p_wscc_env->env[conidx]->wss.descs[0]); + + //Even if we get multiple responses we only store 1 range + p_wscc_env->env[conidx]->wss.svc.shdl = p_ind->start_hdl; + p_wscc_env->env[conidx]->wss.svc.ehdl = p_ind->end_hdl; + + for (fnd_att = 0; fnd_att < (p_ind->end_hdl - p_ind->start_hdl); fnd_att++) + { + if((p_ind->info[fnd_att].att_type == GATTC_SDP_INC_SVC) && + (attm_uuid16_comp((uint8_t *)&p_ind->info[fnd_att].inc_svc.uuid[0], + p_ind->info[fnd_att].inc_svc.uuid_len,ATT_SVC_BODY_COMPOSITION))) + { + // Retrieve Info on included BCS service + p_wscc_env->env[conidx]->wss.incl_svc.handle = p_ind->start_hdl+ 1 + fnd_att; + p_wscc_env->env[conidx]->wss.incl_svc.start_hdl = p_ind->info[fnd_att].inc_svc.start_hdl; + p_wscc_env->env[conidx]->wss.incl_svc.end_hdl = p_ind->info[fnd_att].inc_svc.end_hdl; + p_wscc_env->env[conidx]->wss.incl_svc.uuid_len = p_ind->info[fnd_att].inc_svc.uuid_len; + memcpy(&p_wscc_env->env[conidx]->wss.incl_svc.uuid[0], + &p_ind->info[fnd_att].inc_svc.uuid[0],p_ind->info[fnd_att].inc_svc.uuid_len); + + break; + } + } + + p_wscc_env->env[conidx]->nb_svc++; + } + + } while(0); + + return (KE_MSG_CONSUMED); +} +/** + **************************************************************************************** + * @brief Handles reception of the @ref WSCC_ENABLE_REQ message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int wscc_enable_req_handler(ke_msg_id_t const msgid, + struct wscc_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + // Weight Scale Collector Role Task Environment + struct wscc_env_tag *p_wscc_env = PRF_ENV_GET(WSCC, wscc); + + ASSERT_INFO(p_wscc_env != NULL, dest_id, src_id); + if ((state == WSCC_IDLE) && (p_wscc_env->env[conidx] == NULL)) + { + // allocate environment variable for task instance + p_wscc_env->env[conidx] = (struct wscc_cnx_env *) ke_malloc(sizeof(struct wscc_cnx_env), KE_MEM_ATT_DB); + memset(p_wscc_env->env[conidx], 0, sizeof(struct wscc_cnx_env)); + + // Start discovering + if (p_param->con_type == PRF_CON_DISCOVERY) + { + // Start discovery with Weight Scale + prf_disc_svc_send(&(p_wscc_env->prf_env), conidx, ATT_SVC_WEIGHT_SCALE); + + // Go to DISCOVERING SERVICE state + ke_state_set(dest_id, WSCC_DISCOVERING_SVC); + } + //normal connection, get saved att details + else + { + p_wscc_env->env[conidx]->wss = p_param->wss; + + //send APP confirmation that can start normal connection to TH + wscc_enable_rsp_send(p_wscc_env, conidx, GAP_ERR_NO_ERROR); + } + } + else if (state != WSCC_FREE) + { + // The message will be forwarded towards the good task instance + status = PRF_ERR_REQ_DISALLOWED; + } + + if(status != GAP_ERR_NO_ERROR) + { + // The request is disallowed (profile already enabled for this connection, or not enough memory, ...) + wscc_enable_rsp_send(p_wscc_env, conidx, status); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref WSCC_RD_FEAT_CMD message from the application. + * @brief To read the Feature Characteristic in the peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int wscc_rd_feat_cmd_handler(ke_msg_id_t const msgid, + struct wscc_rd_feat_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct wscc_env_tag *p_wscc_env = PRF_ENV_GET(WSCC, wscc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == WSCC_IDLE) + { + ASSERT_INFO(p_wscc_env != NULL, dest_id, src_id); + // environment variable not ready + if(p_wscc_env->env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = p_wscc_env->env[conidx]->wss.chars[WSCC_CHAR_WSS_FEATURE].val_hdl; + // Service + struct prf_svc *p_svc = &p_wscc_env->env[conidx]->wss.svc; + + // Check if handle is viable + if ((search_hdl != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_wscc_env->env[conidx]->op_pending = WSCC_READ_FEAT_OP_CODE; + // Send read request + prf_read_char_send(&(p_wscc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, WSCC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == WSCC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + wscc_send_cmp_evt(p_wscc_env, conidx, WSCC_READ_FEAT_OP_CODE, status); + } + + return msg_status; +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref WSCC_RD_MEAS_CCC_CMD message from the application. + * @brief To read the CCC value of the Measurement characteristic in the peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +__STATIC int wscc_rd_meas_ccc_cmd_handler(ke_msg_id_t const msgid, + struct wscc_rd_meas_ccc_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + uint8_t status = PRF_ERR_REQ_DISALLOWED; + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct wscc_env_tag *p_wscc_env = PRF_ENV_GET(WSCC, wscc); + // Get connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (state == WSCC_IDLE) + { + ASSERT_INFO(p_wscc_env != NULL, dest_id, src_id); + // environment variable not ready + if(p_wscc_env->env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t search_hdl = p_wscc_env->env[conidx]->wss.descs[WSCC_DESC_WSS_MEAS_CCC].desc_hdl; + // Service + struct prf_svc *p_svc = &p_wscc_env->env[conidx]->wss.svc; + + // Check if handle is viable + if ((search_hdl != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_wscc_env->env[conidx]->op_pending = WSCC_READ_CCC_OP_CODE; + // Send read request + prf_read_char_send(&(p_wscc_env->prf_env), conidx, p_svc->shdl, p_svc->ehdl, search_hdl); + // Go to the Busy state + ke_state_set(dest_id, WSCC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + } + else if (state == WSCC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + if (status != GAP_ERR_NO_ERROR) + { + wscc_send_cmp_evt(p_wscc_env, conidx, WSCC_READ_CCC_OP_CODE, status); + } + + return msg_status; +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref WSCC_WR_MEAS_CCC_CMD message. + * Allows the application to write new CCC values to a Characteristic in the peer server + * + * @param[in] msgid Id of the message received. + * @param[in] p_cmd Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int wscc_wr_meas_ccc_cmd_handler(ke_msg_id_t const msgid, + struct wscc_wr_meas_ccc_cmd *p_cmd, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t state = ke_state_get(dest_id); + // Status + uint8_t status = GAP_ERR_NO_ERROR; + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Get the address of the environment + struct wscc_env_tag *p_wscc_env = PRF_ENV_GET(WSCC, wscc); + // Get connection index + + if (state == WSCC_IDLE) + { + uint8_t conidx = KE_IDX_GET(dest_id); + + ASSERT_INFO(p_wscc_env != NULL, dest_id, src_id); + // environment variable not ready + if (p_wscc_env->env[conidx] == NULL) + { + status = PRF_APP_ERROR; + } + else + { + // Attribute Handle + uint16_t handle = p_wscc_env->env[conidx]->wss.descs[WSCC_DESC_WSS_MEAS_CCC].desc_hdl; + // Service + struct prf_svc *p_svc = &p_wscc_env->env[conidx]->wss.svc; + + // Check if handle is viable + if ((handle != ATT_INVALID_SEARCH_HANDLE) && (p_svc != NULL)) + { + // Force the operation value + p_wscc_env->env[conidx]->op_pending = WSCC_WRITE_CCC_OP_CODE; + + // Send the write request + prf_gatt_write_ntf_ind(&(p_wscc_env->prf_env), conidx, handle, p_cmd->ccc); + + // Go to the Busy state + ke_state_set(dest_id, WSCC_BUSY); + + status = GAP_ERR_NO_ERROR; + } + else + { + status = PRF_ERR_INEXISTENT_HDL; + } + } + + if (status != GAP_ERR_NO_ERROR) + { + wscc_send_cmp_evt(p_wscc_env, conidx, WSCC_WRITE_CCC_OP_CODE, status); + } + } + else if (state == WSCC_FREE) + { + status = GAP_ERR_DISCONNECTED; + } + else + { + // Another procedure is pending, keep the command for later + msg_status = KE_MSG_SAVED; + status = GAP_ERR_NO_ERROR; + } + + return msg_status; +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_CMP_EVT message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct wscc_env_tag *p_wscc_env = PRF_ENV_GET(WSCC, wscc); + + if (p_wscc_env != NULL) + { + // Status + uint8_t status; + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t state = ke_state_get(dest_id); + + if (state == WSCC_DISCOVERING_SVC) + { + if ((p_param->status == GAP_ERR_NO_ERROR) || (p_param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)) + { + // Check service (if found) + if (p_wscc_env->env[conidx]->nb_svc) + { + // Check service (mandatory) + status = prf_check_svc_char_validity(WSCC_CHAR_WSS_MAX, + p_wscc_env->env[conidx]->wss.chars, + wscc_wss_char); + + // Check Descriptors (mandatory) + if(status == GAP_ERR_NO_ERROR) + { + status = prf_check_svc_char_desc_validity(WSCC_DESC_WSS_MAX, + p_wscc_env->env[conidx]->wss.descs, + wscc_wss_char_desc, + p_wscc_env->env[conidx]->wss.chars); + } + } + } + + // Raise an WSCC_ENABLE_REQ complete event. + ke_state_set(dest_id, WSCC_IDLE); + + wscc_enable_rsp_send(p_wscc_env, conidx, p_param->status); + } + else if (state == WSCC_BUSY) + { + uint8_t op_pending = p_wscc_env->env[conidx]->op_pending; + + status = p_param->status; + + switch (p_param->operation) + { + case GATTC_READ: + { + switch(op_pending) + { + case WSCC_READ_FEAT_OP_CODE: + case WSCC_READ_CCC_OP_CODE: + { + wscc_send_cmp_evt(p_wscc_env, conidx, op_pending, status); + } + break; + + default: + { + break; + } + } + ke_state_set(dest_id, WSCC_IDLE); + } + break; + + case GATTC_WRITE: + case GATTC_WRITE_NO_RESPONSE: + { + // Send the complete event status + wscc_send_cmp_evt(p_wscc_env, conidx, op_pending, status); + ke_state_set(dest_id, WSCC_IDLE); + + } break; + + case GATTC_REGISTER: + { + if (status != GAP_ERR_NO_ERROR) + { + // Send the complete event error status + wscc_send_cmp_evt(p_wscc_env, conidx, GATTC_REGISTER, status); + } + // Go to connected state + ke_state_set(dest_id, WSCC_IDLE); + } break; + + case GATTC_UNREGISTER: + { + // Do nothing + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + } + // else ignore the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_READ_IND message. + * Generic event received after every simple read command sent to peer server. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (ke_state_get(dest_id) == WSCC_BUSY) + { + // Get the address of the environment + struct wscc_env_tag *p_wscc_env = PRF_ENV_GET(WSCC, wscc); + uint8_t conidx = KE_IDX_GET(dest_id); + uint8_t op_pending; + + ASSERT_INFO(p_wscc_env != NULL, dest_id, src_id); + ASSERT_INFO(p_wscc_env->env[conidx] != NULL, dest_id, src_id); + + // Find the op_pending - and check it is a valid read code. + op_pending = p_wscc_env->env[conidx]->op_pending; + if ((op_pending == WSCC_READ_FEAT_OP_CODE) || (op_pending == WSCC_READ_CCC_OP_CODE)) + { + switch (op_pending) + { + case WSCC_READ_FEAT_OP_CODE: + { + struct wscc_feat_ind *p_ind = KE_MSG_ALLOC(WSCC_FEAT_IND, + prf_dst_task_get(&(p_wscc_env->prf_env), conidx), + dest_id, + wscc_feat_ind); + + p_ind->feature = co_read32p(&p_param->value[0]); + + ke_msg_send(p_ind); + } + break; + + case WSCC_READ_CCC_OP_CODE : + { + struct wscc_meas_ccc_ind *p_ind = KE_MSG_ALLOC(WSCC_MEAS_CCC_IND, + prf_dst_task_get(&(p_wscc_env->prf_env), conidx), + dest_id, + wscc_meas_ccc_ind); + + p_ind->ccc = co_read16p(&p_param->value[0]); + + ke_msg_send(p_ind); + } + break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + } + // else drop the message + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_EVENT_IND message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_event_ind_handler(ke_msg_id_t const msgid, + struct gattc_event_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + uint8_t conidx = KE_IDX_GET(dest_id); + // Get the address of the environment + struct wscc_env_tag *p_wscc_env = PRF_ENV_GET(WSCC, wscc); + + if (p_wscc_env != NULL) + { + switch (p_param->type) + { + case (GATTC_INDICATE): + { + struct gattc_event_cfm *p_cfm = NULL; + + if (p_param->handle == p_wscc_env->env[conidx]->wss.chars[WSCC_CHAR_WSS_MEAS].val_hdl) + { + //indication Build a WSCC_WSS_IND message + uint8_t *p_val; + + struct wscc_meas_ind *p_ind = KE_MSG_ALLOC(WSCC_MEAS_IND, + prf_dst_task_get(&p_wscc_env->prf_env, conidx), + prf_src_task_get(&p_wscc_env->prf_env, conidx), + wscc_meas_ind); + + // Read the Flags and restrict to valid values only + p_ind->flags = p_param->value[0] & WSC_MEAS_FLAGS_VALID; + + // decode message + p_val = (uint8_t *)&p_param->value[1]; + // Mandatory weight + p_ind->weight = co_read16p(p_val); + p_val += sizeof(uint16_t); + + // Weight resolution + p_ind->wght_resol = *p_val++; + + // Measurement Units + p_ind->meas_u = *p_val++; + + // Timestamp if present + if (GETB(p_ind->flags, WSC_MEAS_FLAGS_TIMESTAMP_PRESENT)) + { + p_val += prf_unpack_date_time(p_val, &p_ind->time_stamp); + } + + // User Id if present + if (GETB(p_ind->flags, WSC_MEAS_FLAGS_USER_ID_PRESENT)) + { + p_ind->user_id = *p_val++; + } + + // BMI & Height if present + if (GETB(p_ind->flags, WSC_MEAS_FLAGS_BMI_PRESENT)) + { + // BMI + p_ind->bmi = co_read16p(p_val); + p_val += sizeof(uint16_t); + // Height + p_ind->height = co_read16p(p_val); + p_val += sizeof(uint16_t); + // Height Resolution + p_ind->hght_resol = *p_val++; + } + + ke_msg_send(p_ind); + } + + // confirm that indication has been correctly received + p_cfm = KE_MSG_ALLOC(GATTC_EVENT_CFM, src_id, dest_id, gattc_event_cfm); + p_cfm->handle = p_param->handle; + ke_msg_send(p_cfm); + + // else drop the message + } break; + + default: + { + ASSERT_ERR(0); + } break; + } + } + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(wscc) +{ + {WSCC_ENABLE_REQ, (ke_msg_func_t)wscc_enable_req_handler}, + + {GATTC_SDP_SVC_IND, (ke_msg_func_t)gattc_sdp_svc_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + + {GATTC_READ_IND, (ke_msg_func_t)gattc_read_ind_handler}, + {GATTC_EVENT_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {GATTC_EVENT_REQ_IND, (ke_msg_func_t)gattc_event_ind_handler}, + {WSCC_RD_FEAT_CMD, (ke_msg_func_t)wscc_rd_feat_cmd_handler}, + {WSCC_RD_MEAS_CCC_CMD, (ke_msg_func_t)wscc_rd_meas_ccc_cmd_handler}, + {WSCC_WR_MEAS_CCC_CMD, (ke_msg_func_t)wscc_wr_meas_ccc_cmd_handler}, + +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +void wscc_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct wscc_env_tag *p_wscc_env = PRF_ENV_GET(WSCC, wscc); + + p_task_desc->msg_handler_tab = wscc_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(wscc_msg_handler_tab); + p_task_desc->state = p_wscc_env->state; + p_task_desc->idx_max = WSCC_IDX_MAX; +} + +#endif //(BLE_WSC_CLIENT) + +/// @} WSCCTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/api/wscs_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/api/wscs_task.h new file mode 100644 index 0000000..6d62e19 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/api/wscs_task.h @@ -0,0 +1,129 @@ +/** + **************************************************************************************** + * + * @file wscs_task.h + * + * @brief Header file - Weight SCale Profile Sensor Task. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _WSCS_TASK_H_ +#define _WSCS_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup WSCSTASK Task + * @ingroup WSCS + * @brief Weight SCale Profile Task. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include +#include "wsc_common.h" +#include "rwip_task.h" // Task definitions + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Messages for Weight SCale Profile Sensor +/*@TRACE*/ +enum wscs_msg_id +{ + /// Enable the WSCP Sensor task for a connection + WSCS_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_WSCS), + /// Enable the WSCP Sensor task for a connection + WSCS_ENABLE_RSP, + /// Indicate a new IND configuration to the application + /// Send CCC descriptor write update to the APP + WSCS_MEAS_CCC_IND, + + /// Send a WSC Measurement to the peer device (Indication) + WSCS_MEAS_INDICATE_CMD, + + /// Send a complete event status to the application + WSCS_CMP_EVT, +}; + +enum wscs_op_codes +{ + WSCS_MEAS_INDICATE_CMD_OP_CODE = 1, +}; +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Parameters of the initialization function +struct wscs_db_cfg +{ + + /// Weight SCale service Feature Value + uint32_t feature; + /// Body Composition started handle + uint16_t bcs_start_hdl; + +}; + +/// Parameters of the @ref WSCS_ENABLE_REQ message +struct wscs_enable_req +{ + /// CCC for the current connection + uint16_t ind_cfg; +}; + +/// Parameters of the @ref WSCS_ENABLE_RSP message +struct wscs_enable_rsp +{ + /// Status + uint8_t status; +}; + +/// Parameters of the @ref WSCS_MEAS_INDICATE_CMD message +struct wscs_meas_indicate_cmd +{ + /// Presence of optional fields and measurement units + uint8_t flags; + /// Weight value + uint16_t weight; + /// Time Stamp value + struct prf_date_time time_stamp; + /// User ID value + uint8_t user_id; + /// Body Mass Index + uint16_t bmi; + /// Height value + uint16_t height; +}; + +/// Parameters of the @ref WSCS_WR_CCC_IND message +struct wscs_wr_ccc_ind +{ + /// Char. Client Characteristic Configuration + uint16_t ind_cfg; +}; + +/// Parameters of the @ref WSCS_CMP_EVT message +struct wscs_cmp_evt +{ + /// operation + uint8_t operation; + /// Operation Status + uint8_t status; +}; + +/// @} WSCSTASK + +#endif //(_WSCS_TASK_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/sourcelist.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/sourcelist.txt new file mode 100644 index 0000000..5163a2c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/sourcelist.txt @@ -0,0 +1,13 @@ +#*************************************************************************************** +# @file sourcelist.txt +# +# @brief This file lists up all the source code that will be +# compiled and built for XXXX module. +# +# Copyright (C) RivieraWaves 2009-2016 +# +#*************************************************************************************** + + wscs.c + wscs_task.c + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/src/wscs.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/src/wscs.c new file mode 100644 index 0000000..2b6f8e0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/src/wscs.c @@ -0,0 +1,350 @@ +/** + **************************************************************************************** + * + * @file wscs.c + * + * @brief Weight SCale Profile Sensor implementation. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup WSCS + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_WSC_SERVER) +#include "wsc_common.h" + +#include "gap.h" +#include "gattc_task.h" +#include "attm.h" +#include "wscs/src/wscs.h" +#include "wscs_task.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ +/// default read perm +#define RD_P (PERM(RD, ENABLE) | PERM(RP, NO_AUTH)) +/// default write perm +#define WR_P (PERM(WRITE_REQ, ENABLE) | PERM(WP, NO_AUTH)) +/// ind perm +#define IND_P (PERM(IND, ENABLE) | PERM(IP, NO_AUTH)) +/// enable Read Indication (1 = Value not present in Database) +#define EXT_P (PERM(RI, ENABLE)) + + +/// Full WSCS Database Description - Used to add attributes into the database +static const struct attm_desc wscs_att_db[WSCS_IDX_NB] = +{ + /// ATT Index | ATT UUID | Permission | EXT PERM | MAX ATT SIZE + // Weight SCale Service Declaration + [WSCS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, RD_P, 0, 0}, + + [WSCS_IDX_INC_SVC] = {ATT_DECL_INCLUDE, RD_P, 0, 0}, + // Weight SCale Feature + [WSCS_IDX_FEAT_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // Descriptor Value Changed Characteristic Value + [WSCS_IDX_FEAT_VAL] = {ATT_CHAR_WEIGHT_SCALE_FEATURE, RD_P, EXT_P, WSCS_FEAT_VAL_SIZE}, + + // Weight SCale Measurement + [WSCS_IDX_MEAS_CHAR] = {ATT_DECL_CHARACTERISTIC, RD_P, 0, 0}, + // Weight SCale Measurement Characteristic Value + [WSCS_IDX_MEAS_IND] = {ATT_CHAR_WEIGHT_MEASUREMENT, IND_P, 0, WSCS_MEAS_IND_SIZE}, + // Weight SCale Measurement Characteristic - Client Characteristic Configuration Descriptor + [WSCS_IDX_MEAS_CCC] = {ATT_DESC_CLIENT_CHAR_CFG, RD_P | WR_P, EXT_P, sizeof(uint16_t)}, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the WSCS module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] p_env Collector or Service allocated environment data. + * @param[in|out] p_start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] p_param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +static uint8_t wscs_init(struct prf_task_env *p_env, uint16_t *start_hdl, uint16_t app_task, + uint8_t sec_lvl, struct wscs_db_cfg *p_param) +{ + //------------------ create the attribute database for the profile ------------------- + // Service content flag + uint8_t cfg_flag = (1 << WSCS_IDX_NB) - 1; + // DB Creation Status + uint8_t status = ATT_ERR_NO_ERROR; + + // Add service in the database + struct attm_desc wscs_db[WSCS_IDX_NB]; + uint8_t i; + + for (i = 0; i < WSCS_IDX_NB; i++) + memcpy(&wscs_db[i],&wscs_att_db[i],sizeof(struct attm_desc)); + + if (p_param->bcs_start_hdl) + wscs_db[WSCS_IDX_INC_SVC].max_size = p_param->bcs_start_hdl; + + status = attm_svc_create_db(start_hdl, ATT_SVC_WEIGHT_SCALE, (uint8_t *)&cfg_flag, + WSCS_IDX_NB, NULL, p_env->task, &wscs_db[0], + (sec_lvl & (PERM_MASK_SVC_DIS | PERM_MASK_SVC_AUTH | PERM_MASK_SVC_EKS )) | PERM(SVC_MI, ENABLE)); + + // Check if an error has occured + if (status == ATT_ERR_NO_ERROR) + { + // Allocate WSCS required environment variable + struct wscs_env_tag *p_wscs_env = + (struct wscs_env_tag *) ke_malloc(sizeof(struct wscs_env_tag), KE_MEM_ATT_DB); + + // Initialize WSCS environment + + p_env->env = (prf_env_t *) p_wscs_env; + p_wscs_env->shdl = *start_hdl; + p_wscs_env->feature = p_param->feature; + + if (p_param->bcs_start_hdl) + { + p_wscs_env->bcs_included = 0x01; + } + else + { + p_wscs_env->bcs_included = 0x00; + } + + // Mono Instantiated APP task + p_wscs_env->prf_env.app_task = app_task + | (PERM_GET(sec_lvl, SVC_MI) ? PERM(PRF_MI, ENABLE) : PERM(PRF_MI, DISABLE)); + // Multi Instantiated task depending on Multiple user support Feature + p_wscs_env->prf_env.prf_task = p_env->task | PERM(PRF_MI, ENABLE); + + // initialize environment variable + p_env->id = TASK_ID_WSCS; + wscs_task_init(&(p_env->desc)); + + // Initialize CCC per connection + memset(p_wscs_env->prfl_ind_cfg, 0, BLE_CONNECTION_MAX); + // If we are here, database has been fulfilled with success, go to idle state + for(uint8_t idx = 0; idx < BLE_CONNECTION_MAX ; idx++) + { + /* Put WSCS in disabled state */ + ke_state_set(KE_BUILD_ID(p_env->task, idx), WSCS_FREE); + } + } + + return status; +} +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +static void wscs_cleanup(struct prf_task_env *p_env, uint8_t conidx, uint8_t reason) +{ + struct wscs_env_tag *p_wscs_env = (struct wscs_env_tag *) p_env->env; + + // clean-up environment variable allocated for task instance + p_wscs_env->prfl_ind_cfg[conidx] = 0; + + /* Put WSCS in disabled state */ + ke_state_set(KE_BUILD_ID(p_env->task, conidx), WSCS_FREE); +} + +/** + **************************************************************************************** + * @brief Destruction of the WSCS module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] p_env Collector or Service allocated environment data. + **************************************************************************************** + */ +static void wscs_destroy(struct prf_task_env *p_env) +{ + struct wscs_env_tag *p_wscs_env = (struct wscs_env_tag *) p_env->env; + + // cleanup environment variable for each task instances + + // free profile environment variables + p_env->env = NULL; + ke_free(p_wscs_env); +} + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] p_env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +static void wscs_create(struct prf_task_env *p_env, uint8_t conidx) +{ + struct wscs_env_tag *p_wscs_env = (struct wscs_env_tag *) p_env->env; + + p_wscs_env->prfl_ind_cfg[conidx] = 0; + // Change state to IDLE + ke_state_set(KE_BUILD_ID(p_env->task, conidx), WSCS_IDLE); +} + + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// WSCS Task interface required by profile manager +const struct prf_task_cbs wscs_itf = +{ + (prf_init_fnct) wscs_init, + wscs_destroy, + wscs_create, + wscs_cleanup, +}; + +/* + * EXPORTED FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +const struct prf_task_cbs* wscs_prf_itf_get(void) +{ + return &wscs_itf; +} + + +void wscs_send_cmp_evt(struct wscs_env_tag *p_wscs_env, uint8_t conidx, uint8_t operation, uint8_t status) +{ + + struct wscs_cmp_evt *p_evt = KE_MSG_ALLOC(WSCS_CMP_EVT, + prf_dst_task_get(&(p_wscs_env->prf_env), conidx), + prf_src_task_get(&(p_wscs_env->prf_env), conidx), + wscs_cmp_evt); + + p_evt->status = status; + p_evt->operation = operation; + ke_msg_send(p_evt); +} + + +uint8_t wscs_get_wght_resol(uint32_t feature) +{ + uint8_t mass_resol; + + // Imperial - Weight and Mass in units of pound (lb) and Height in units of inch (in) + switch(GETF(feature, WSC_FEAT_WGHT_RESOL)) + { + case WSC_WGHT_RESOL_05kg_1lb: + { + mass_resol = WSC_WGHT_RESOL_05kg_1lb; + } break; + + case WSC_WGHT_RESOL_02kg_05lb: + { + mass_resol = WSC_WGHT_RESOL_02kg_05lb; + } break; + + case WSC_WGHT_RESOL_01kg_02lb: + { + mass_resol = WSC_WGHT_RESOL_01kg_02lb; + } break; + + case WSC_WGHT_RESOL_005kg_01lb: + { + mass_resol = WSC_WGHT_RESOL_005kg_01lb; + } break; + + case WSC_WGHT_RESOL_002kg_005lb: + { + mass_resol = WSC_WGHT_RESOL_002kg_005lb; + } break; + + case WSC_WGHT_RESOL_001kg_002lb: + { + mass_resol = WSC_WGHT_RESOL_001kg_002lb; + } break; + + case WSC_WGHT_RESOL_0005kg_001lb: + { + mass_resol = WSC_WGHT_RESOL_0005kg_001lb; + } break; + + case WSC_WGHT_RESOL_NOT_SPECIFIED: + default: + { + mass_resol = WSC_WGHT_RESOL_NOT_SPECIFIED; + } break; + } + + return mass_resol; +} + +uint8_t wscs_get_hght_resol(uint32_t feature) +{ + uint8_t hght_resol; + + // Imperial - Weight and Mass in units of pound (lb) and Height in units of inch (in) + switch(GETF(feature, WSC_FEAT_HGHT_RESOL)) + { + case WSC_HGHT_RESOL_001mtr_1inch: + { + hght_resol = WSC_HGHT_RESOL_001mtr_1inch; + } break; + + case WSC_HGHT_RESOL_0005mtr_05inch: + { + hght_resol = WSC_HGHT_RESOL_0005mtr_05inch; + } break; + + case WSC_HGHT_RESOL_0001mtr_01inch: + { + hght_resol = WSC_HGHT_RESOL_0001mtr_01inch; + } break; + + case WSC_HGHT_RESOL_NOT_SPECIFIED: + default: + { + hght_resol = WSC_HGHT_RESOL_NOT_SPECIFIED; + } break; + } + + return hght_resol; +} + +#endif //(BLE_WSC_SERVER) + +/// @} WSCS diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/src/wscs.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/src/wscs.h new file mode 100644 index 0000000..5c248c4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/src/wscs.h @@ -0,0 +1,185 @@ +/** + **************************************************************************************** + * + * @file wscs.h + * + * @brief Header file - Weight SCale Profile Sensor. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * $ Rev $ + * + **************************************************************************************** + */ + +#ifndef _WSCS_H_ +#define _WSCS_H_ + +/** + **************************************************************************************** + * @addtogroup WSCS Weight SCale Profile Sensor + * @ingroup CSCP + * @brief Weight SCale Profile Sensor + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_WSC_SERVER) +#include "wsc_common.h" +#include "wscs_task.h" + +#include "prf_types.h" +#include "prf.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of Weight SCale Profile Sensor role task instances +#define WSCS_IDX_MAX (BLE_CONNECTION_MAX) +/// Feature value size 32 bits +#define WSCS_FEAT_VAL_SIZE (4) +/// Measurement Indication size (plus 3 bytes for meas_u, mass_resol and hght_resol) +#define WSCS_MEAS_IND_SIZE (sizeof(struct wscs_meas_indicate_cmd) + 3) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Possible states of the WSCS task +enum wscs_states +{ + /// not connected state + WSCS_FREE, + /// idle state + WSCS_IDLE, + + /// indicate + WSCS_OP_INDICATE, + + /// Number of defined states. + ENVS_STATE_MAX +}; + +/// Weight SCale Service - Attribute List +enum wscs_att_list +{ + /// Weight SCale Service + WSCS_IDX_SVC, + /// Included Body Composition Service + WSCS_IDX_INC_SVC, + /// Weight SCale Feature Characteristic + WSCS_IDX_FEAT_CHAR, + WSCS_IDX_FEAT_VAL, + /// Weight SCale Measurement Characteristic + WSCS_IDX_MEAS_CHAR, + WSCS_IDX_MEAS_IND, + /// CCC Descriptor + WSCS_IDX_MEAS_CCC, + + /// Number of attributes + WSCS_IDX_NB, +}; + + +/* + * STRUCTURES + **************************************************************************************** + */ + +/// Weight SCale Profile Sensor environment variable +struct wscs_env_tag +{ + /// profile environment + prf_env_t prf_env; + + /// Weight SCale Service Start Handle + uint16_t shdl; + /// Feature configuration + uint32_t feature; + /// BCS Service Included + uint8_t bcs_included; + /// CCC for each connections + uint8_t prfl_ind_cfg[BLE_CONNECTION_MAX]; + + /// State of different task instances + ke_state_t state[WSCS_IDX_MAX]; + +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Inform the APP that a procedure has been completed + * + * @param[in] p_wscs_env Weight SCale Sensor environment variable + * @param[in] conidx Connection index + * @param[in] operation Operation code + * @param[in] status Operation status + **************************************************************************************** + */ +void wscs_send_cmp_evt(struct wscs_env_tag *p_wscs_env, uint8_t conidx, uint8_t operation, uint8_t status); + +/** + **************************************************************************************** + * @brief Retrieve WSCP service profile interface + * + * @return Weight Scale service profile interface + **************************************************************************************** + */ +const struct prf_task_cbs* wscs_prf_itf_get(void); + +/** + **************************************************************************************** + * @brief Get Weight Resolution from feature value + * + * @param[in] feature Weight Scale Feature value + * + * @return Mass Resolution + **************************************************************************************** + */ +uint8_t wscs_get_wght_resol(uint32_t feature); + +/** + **************************************************************************************** + * @brief Get Height Resolution from feature value + * + * @param[in] feature Weight Scale Feature value + * + * @return Height Resolution + **************************************************************************************** + */ +uint8_t wscs_get_hght_resol(uint32_t feature); + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Initialize task handler + * + * @param p_task_desc Task descriptor to fill + **************************************************************************************** + */ +void wscs_task_init(struct ke_task_desc *p_task_desc); + +#endif //(BLE_WSC_SERVER) + +/// @} WSCS + +#endif //(_WSCS_H_) diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/src/wscs_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/src/wscs_task.c new file mode 100644 index 0000000..d941c43 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_profile/wscp/wscs/src/wscs_task.c @@ -0,0 +1,536 @@ +/** + **************************************************************************************** + * + * @file wscs_task.c + * + * @brief Weight SCale Profile Sensor Task Implementation. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * $ Rev $ + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup WSCSTASK + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_WSC_SERVER) +#include "wsc_common.h" + +#include "gapc.h" +#include "gattc_task.h" +#include "attm.h" +#include "wscs/src/wscs.h" +#include "wscs_task.h" +#include "prf_utils.h" + +#include "ke_mem.h" +#include "co_utils.h" + +/* + * LOCAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Handles reception of the @ref WSCS_ENABLE_REQ message. + * + * @param[in] msgid Id of the message received + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int wscs_enable_req_handler(ke_msg_id_t const msgid, + struct wscs_enable_req *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Status + uint8_t status = PRF_ERR_REQ_DISALLOWED; + struct wscs_enable_rsp *p_cmp_evt = NULL; + + if (ke_state_get(dest_id) == WSCS_IDLE) + { + // Get the address of the environment + struct wscs_env_tag *p_wscs_env = PRF_ENV_GET(WSCS, wscs); + + // Save indication config + p_wscs_env->prfl_ind_cfg[KE_IDX_GET(src_id)] = p_param->ind_cfg; + status = GAP_ERR_NO_ERROR; + } + + // send completed information to APP task that contains error status + p_cmp_evt = KE_MSG_ALLOC(WSCS_ENABLE_RSP, src_id, dest_id, wscs_enable_rsp); + p_cmp_evt->status = status; + + ke_msg_send(p_cmp_evt); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the read request from peer device + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_read_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_read_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + int msg_status = KE_MSG_CONSUMED; + + // check that task is in idle state + if(ke_state_get(dest_id) == WSCS_IDLE) + { + // Get the address of the environment + struct wscs_env_tag *p_wscs_env = PRF_ENV_GET(WSCS, wscs); + uint8_t att_idx = p_param->handle - p_wscs_env->shdl; + uint8_t value[WCS_FEAT_VAL_LEN]; + uint8_t value_size = 0; + uint8_t status = ATT_ERR_NO_ERROR; + // Send data to peer device + struct gattc_read_cfm *p_cfm = NULL; + + switch(att_idx) + { + case WSCS_IDX_FEAT_VAL: + { + value_size = WCS_FEAT_VAL_LEN; + co_write32p(&(value[0]), p_wscs_env->feature); + } break; + + case WSCS_IDX_MEAS_CCC: + { + value_size = WCS_MEAS_CCC_LEN; + co_write16p(&(value[0]), p_wscs_env->prfl_ind_cfg[KE_IDX_GET(src_id)]); + } break; + + default: + { + if (p_cfm == NULL) + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } + } break; + } + + p_cfm = KE_MSG_ALLOC_DYN(GATTC_READ_CFM, src_id, dest_id, gattc_read_cfm, value_size); + p_cfm->length = value_size; + memcpy(p_cfm->value, value, value_size); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + + // Send value to peer device. + ke_msg_send(p_cfm); + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles reception of the attribute info request message. + * + * @param[in] msgid Id of the message received (probably unused). + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (probably unused). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_att_info_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_att_info_req_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct wscs_env_tag *p_wscs_env = PRF_ENV_GET(WSCS, wscs); + uint8_t att_idx = p_param->handle - p_wscs_env->shdl; + struct gattc_att_info_cfm *p_cfm; + + //Send write response + p_cfm = KE_MSG_ALLOC(GATTC_ATT_INFO_CFM, src_id, dest_id, gattc_att_info_cfm); + p_cfm->handle = p_param->handle; + + // check if it's a client configuration char + if(att_idx == WSCS_IDX_MEAS_CCC) + { + // CCC attribute length = 2 + p_cfm->length = WCS_MEAS_CCC_LEN; + p_cfm->status = GAP_ERR_NO_ERROR; + } + else // not expected request + { + p_cfm->length = 0; + p_cfm->status = ATT_ERR_WRITE_NOT_PERMITTED; + } + + ke_msg_send(p_cfm); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles reception of the @ref WSCS_MEAS_INDICATE_CMD message. + * Send MEASUREMENT INDICATION to the connected peer case of CCC enabled + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int wscs_meas_indicate_cmd_handler(ke_msg_id_t const msgid, + struct wscs_meas_indicate_cmd *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Message status + int msg_status = KE_MSG_CONSUMED; + // Get the address of the environment + struct wscs_env_tag *p_wscs_env = PRF_ENV_GET(WSCS, wscs); + + // check that task is in idle state + if(ke_state_get(dest_id) == WSCS_IDLE) + { + // Connection index + uint8_t conidx = KE_IDX_GET(dest_id); + + if (p_wscs_env->prfl_ind_cfg[conidx] & PRF_CLI_START_IND) + { + // Allocate the GATT notification message + struct gattc_send_evt_cmd *p_ind; + // allocate the maximum block for indication + uint8_t value[WSCS_MEAS_IND_SIZE]; + uint8_t status = ATT_ERR_NO_ERROR; + + // Mask off any illegal bits in the flags field + p_param->flags &= WSC_MEAS_FLAGS_VALID; + // If the Weight indicates Measurement Unsuccessful - 0xFFFF + // The the flags field should not include BMI and Height + + if (p_param->weight == WSC_MEASUREMENT_UNSUCCESSFUL) + { + // Disable all other optional fields other than Timestamp and User ID + SETB(p_param->flags, WSC_MEAS_FLAGS_BMI_PRESENT, 0); + } + else + { + // If Body Composition Service is included then Mandatory to have + // both the Height and BMI fields present (in flags) otherwise + // reject command. + if ((p_wscs_env->bcs_included) && (!GETB(p_param->flags, WSC_MEAS_FLAGS_BMI_PRESENT))) + { + status = PRF_ERR_INVALID_PARAM; + } + } + + //************************************************************** + // Encode the Fields of the Weight Measurement + // if the Application provide flags and fields which do not correspond + // to the features declared by the server, we adjust the flags field to + // ensure we only Indicate with fields compatible with our features. + // Thus the flags fields is encoded last as it will be modifed by checks on + // features. + //******************************************************************** + if (status == ATT_ERR_NO_ERROR) + { + uint16_t length = 0; + + // Flags is 8 bits + length++; + + // Mandatory weight + // pack measured value in database + co_write16p(&value[length], p_param->weight); + length += sizeof(uint16_t); + + // Get Weight Resolution + value[length++] = wscs_get_wght_resol(p_wscs_env->feature); + + // Measurement Units + // 0 for SI and 1 for Imperial + value[length++] = GETB(p_param->flags, WSC_MEAS_FLAGS_UNITS_IMPERIAL); + + // Time Stamp shall be included in flags field if the Server supports Time Stamp feature + if (GETB(p_wscs_env->feature, WSC_FEAT_TIME_STAMP_SUPP)) + { + SETB(p_param->flags, WSC_MEAS_FLAGS_TIMESTAMP_PRESENT, 1); + length += prf_pack_date_time(&value[length], &p_param->time_stamp); + } + else + { + // If Time-Stamp is not supported in the features - it should not be transmitted + SETB(p_param->flags, WSC_MEAS_FLAGS_TIMESTAMP_PRESENT, 0); + } + + // User ID shall be included in flags field if the Server supports Multiple Users feature + if (GETB(p_wscs_env->feature, WSC_FEAT_MULTIPLE_USERS_SUPP)) + { + // If the Multiple users fields is enabled in the features and not present in the flags field + // then an "UNKNOWN/GUEST" user is indicated. + if (!GETB(p_param->flags, WSC_MEAS_FLAGS_USER_ID_PRESENT)) + { + value[length++] = WSC_MEAS_USER_ID_UNKNOWN_USER; + } + else + { + value[length++] = p_param->user_id; + } + + SETB(p_param->flags, WSC_MEAS_FLAGS_USER_ID_PRESENT, 1); + } + else + { + // Shall not be included if the Multiple Users feature is not supported + SETB(p_param->flags, WSC_MEAS_FLAGS_USER_ID_PRESENT, 0); + } + + // BMI & Height if present and enabled in the features. + if (GETB(p_param->flags, WSC_MEAS_FLAGS_BMI_PRESENT)) + { + if (GETB(p_wscs_env->feature, WSC_FEAT_BMI_SUPP)) + { + co_write16p(&value[length], p_param->bmi); + length += sizeof(uint16_t); + co_write16p(&value[length], p_param->height); + length += sizeof(uint16_t); + value[length++] = wscs_get_hght_resol(p_wscs_env->feature); + } + else + { + SETB(p_param->flags, WSC_MEAS_FLAGS_BMI_PRESENT, 0); + } + } + // Finally store the flags in Byte 0 - the flags may have been changed in pre-ceeding steps. + value[0] = p_param->flags; + + // Allocate the GATT notification message + p_ind = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, + KE_BUILD_ID(TASK_GATTC, conidx), + dest_id, + gattc_send_evt_cmd, length); + + // Fill in the parameter structure + p_ind->operation = GATTC_INDICATE; + p_ind->handle = p_wscs_env->shdl + WSCS_IDX_MEAS_IND; + // Pack Measurement record + p_ind->length = length; + memcpy (p_ind->value, &value[0], length); + + // Send the event + ke_msg_send(p_ind); + + // go to busy state + ke_state_set(dest_id, WSCS_OP_INDICATE); + } + else + { + // Send a command complete to the App, indicate msg has wrong parameters. + wscs_send_cmp_evt(p_wscs_env, conidx, WSCS_MEAS_INDICATE_CMD_OP_CODE, status); + } + } + else + { + // Send a command complete to the App indicate msg could not be sent. + wscs_send_cmp_evt(p_wscs_env, conidx, WSCS_MEAS_INDICATE_CMD_OP_CODE, PRF_ERR_IND_DISABLED); + } + } + // else process it later + else + { + msg_status = KE_MSG_SAVED; + } + + return msg_status; +} + + +/** + **************************************************************************************** + * @brief Handles reception of the @ref GATTC_WRITE_REQ_IND message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_write_req_ind_handler(ke_msg_id_t const msgid, + struct gattc_write_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Get the address of the environment + struct wscs_env_tag *p_wscs_env = PRF_ENV_GET(WSCS, wscs); + // Message status + int msg_status = KE_MSG_CONSUMED; + + // Check the connection handle + if (p_wscs_env != NULL) + { + // check that task is in idle state + if(ke_state_get(dest_id) == WSCS_IDLE) + { + // Status + uint8_t status = GAP_ERR_NO_ERROR; + uint8_t att_idx = p_param->handle - p_wscs_env->shdl; + struct gattc_write_cfm *p_cfm = NULL; + + // CSC Measurement Characteristic, Client Characteristic Configuration Descriptor + if (att_idx == WSCS_IDX_MEAS_CCC) + { + uint16_t ntf_cfg; + uint8_t conidx = KE_IDX_GET(src_id); + struct wscs_wr_ccc_ind *p_ind = NULL; + + // Get the value + co_write16p(&ntf_cfg, p_param->value[0]); + p_wscs_env->prfl_ind_cfg[conidx] = ntf_cfg; + + // Inform the HL about the new configuration + p_ind = KE_MSG_ALLOC(WSCS_MEAS_CCC_IND, + prf_dst_task_get(&p_wscs_env->prf_env, conidx), + prf_src_task_get(&p_wscs_env->prf_env, conidx), + wscs_wr_ccc_ind); + + p_ind->ind_cfg = ntf_cfg; + + ke_msg_send(p_ind); + + } + else + { + status = PRF_ERR_INVALID_PARAM; + } + + // Send the write response to the peer device + p_cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm); + p_cfm->handle = p_param->handle; + p_cfm->status = status; + ke_msg_send(p_cfm); + } + else + { + msg_status = KE_MSG_SAVED; + } + } + // else drop the message + + return msg_status; +} + +/** + **************************************************************************************** + * @brief Handles @ref GATT_NOTIFY_CMP_EVT message meaning that an indication + * has been correctly sent to peer device (but not confirmed by peer device). + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +__STATIC int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + // Get the address of the environment + struct wscs_env_tag *p_wscs_env = PRF_ENV_GET(WSCS, wscs); + + do + { + if ((p_wscs_env == NULL) || p_param->operation != GATTC_INDICATE || + (ke_state_get(dest_id) != WSCS_OP_INDICATE)) + { + break; + } + else + { + // Inform the application that a procedure has been completed + wscs_send_cmp_evt(p_wscs_env, + KE_IDX_GET(src_id), + WSCS_MEAS_INDICATE_CMD_OP_CODE, + p_param->status); + + ke_state_set(dest_id, WSCS_IDLE); + } + + } while (0); + + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ + +/// Specifies the default message handlers +KE_MSG_HANDLER_TAB(wscs) +{ + {WSCS_ENABLE_REQ, (ke_msg_func_t) wscs_enable_req_handler}, + /// Send a WSC Measurement to the peer device (Indication) + {WSCS_MEAS_INDICATE_CMD, (ke_msg_func_t) wscs_meas_indicate_cmd_handler}, + + {GATTC_READ_REQ_IND, (ke_msg_func_t) gattc_read_req_ind_handler}, + {GATTC_ATT_INFO_REQ_IND, (ke_msg_func_t) gattc_att_info_req_ind_handler}, + {GATTC_WRITE_REQ_IND, (ke_msg_func_t) gattc_write_req_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t) gattc_cmp_evt_handler}, +}; + +/* + * GLOBAL FUNCTIONS DEFINITIONS + **************************************************************************************** + */ + +void wscs_task_init(struct ke_task_desc *p_task_desc) +{ + // Get the address of the environment + struct wscs_env_tag *p_wscs_env = PRF_ENV_GET(WSCS, wscs); + + p_task_desc->msg_handler_tab = wscs_msg_handler_tab; + p_task_desc->msg_cnt = ARRAY_LEN(wscs_msg_handler_tab); + p_task_desc->state = p_wscs_env->state; + p_task_desc->idx_max = WSCS_IDX_MAX; +} + +#endif //(BLE_WSC_SERVER) + +/// @} WSCSTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/arch/TypeDefine.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/arch/TypeDefine.h new file mode 100644 index 0000000..8adcd94 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/arch/TypeDefine.h @@ -0,0 +1,111 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file TypeDefine.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef __TYPES_H__ +#define __TYPES_H__ + +//------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------ +#include "core_cm0.h" +//------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------ +#define FALSE 0 +#define TRUE 1 + +//#define NULL 0 + +#define REG8(addr) (*(volatile UINT8 *) (addr)) +#define REG16(addr) (*(volatile UINT16 *)(addr)) +#define REG32(addr) (*(volatile UINT32 *)(addr)) + +//------------------------------------------------------------------ +// TypeDefs +//------------------------------------------------------------------ +typedef unsigned char UINT8; /// // standard integer definition +#include "compiler.h" // inline functions + + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * MACROS + **************************************************************************************** + */ +/// Macro to read a platform register +#define REG_PL_RD(addr) (*(volatile uint32_t *)(addr)) + +/// Macro to write a platform register +#define REG_PL_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value) + +/// Macro to read a common ip register +#define REG_IP_RD(addr) (*(volatile uint32_t *)(addr)) + +/// Macro to write a common ip register +#define REG_IP_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value) + +/// Macro to read a BLE register +#define REG_BLE_RD(addr) (*(volatile uint32_t *)(addr)) + +/// Macro to write a BLE register +#define REG_BLE_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value) + +/// Macro to read a BLE control structure field (16-bit wide) +#define EM_BLE_RD(addr) (*(volatile uint16_t *)(addr)) + +/// Macro to write a BLE control structure field (16-bit wide) +#define EM_BLE_WR(addr, value) (*(volatile uint16_t *)(addr)) = (value) + +/// Macro to read a BT register +#define REG_BT_RD(addr) (*(volatile uint32_t *)(addr)) + +/// Macro to write a BT register +#define REG_BT_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value) + +/// Macro to read a BT control structure field (16-bit wide) +#define EM_BT_RD(addr) (*(volatile uint16_t *)(addr)) + +/// Macro to write a BT control structure field (16-bit wide) +#define EM_BT_WR(addr, value) (*(volatile uint16_t *)(addr)) = (value) + +/// Macro to read accelerometer register +#define REG_ACC_RD(addr) (acc_reg_rd((uint8_t)addr)) +/// Macro to write accelerometer register +#define REG_ACC_WR(addr, value) (acc_reg_wr((uint8_t)addr, (uint8_t)value)) + +/// Macro to read RTC register +#define REG_RTC_RD(addr) (rtc_reg_rd((uint8_t)addr)) +/// Macro to write RTC register +#define REG_RTC_WR(addr, value) (rtc_reg_wr((uint8_t)addr, (uint8_t)value)) + +/// Macro to read a EM field (16-bit wide) +#define EM_RD(addr) (*(volatile uint16_t *)(addr)) + +/// Macro to write a EM field (16-bit wide) +#define EM_WR(addr, value) (*(volatile uint16_t *)(addr)) = (value) +/* + * CPU WORD SIZE + **************************************************************************************** + */ +/// ARM is a 32-bit CPU +#define CPU_WORD_SIZE 4 + +/* + * CPU Endianness + **************************************************************************************** + */ +/// ARM is little endian +#define CPU_LE 1 + +/* + * DEBUG configuration + **************************************************************************************** + */ +#if defined(CFG_DBG) +#define PLF_DEBUG 0///1 +#else //CFG_DBG +#define PLF_DEBUG 0 +#endif //CFG_DBG + + +/* + * NVDS + **************************************************************************************** + */ + +/// NVDS +#ifdef CFG_NVDS +#define PLF_NVDS 1 +#else // CFG_NVDS +#define PLF_NVDS 0 +#endif // CFG_NVDS + + +/* + * UART + **************************************************************************************** + */ + +/// UART +#define PLF_UART 1 // 0 // +/*uart enables dma*/ +#define UART_DMA_INT_EN 0 // 1 // + +/*SPIS*/ +#define PLF_SPIS 1 // 0 // +/*SPI enables dma*/ +#define SPI_DMA_INT_EN 1 // 0 // + +#define PLF_MCDL 1 + +#define EIF_API_UART 0x55 +#define EIF_API_SPI 0x66 +/* + * DEFINES + **************************************************************************************** + */ + +/// Possible errors detected by FW +#define RESET_NO_ERROR 0x00000000 +#define RESET_MEM_ALLOC_FAIL 0xF2F2F2F2 + +/// Reset platform and stay in ROM +#define RESET_TO_ROM 0xA5A5A5A5 +/// Reset platform and reload FW +#define RESET_AND_LOAD_FW 0xC3C3C3C3 + +/// Exchange memory size limit +#define EM_SIZE_LIMIT 0x4000 //TODO/Ambiq/32K +/* + * EXPORTED FUNCTION DECLARATION + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Compute size of SW stack used. + * + * This function is compute the maximum size stack used by SW. + * + * @return Size of stack used (in bytes) + **************************************************************************************** + */ +uint16_t get_stack_usage(void); + +/** + **************************************************************************************** + * @brief Re-boot FW. + * + * This function is used to re-boot the FW when error has been detected, it is the end of + * the current FW execution. + * After waiting transfers on UART to be finished, and storing the information that + * FW has re-booted by itself in a non-loaded area, the FW restart by branching at FW + * entry point. + * + * Note: when calling this function, the code after it will not be executed. + * + * @param[in] error Error detected by FW + **************************************************************************************** + */ +void platform_reset(uint32_t error); + +void assert_err(const char* condition, const char* file, int line); + +void eif_assert_param(int param0, int param1, const char* file, int line); + + +void assert_warn(int param0, int param1, const char* file, int line); + +#if PLF_DEBUG +/** + **************************************************************************************** + * @brief Print the assertion error reason and loop forever. + * + * @param condition C string containing the condition. + * @param file C string containing file where the assertion is located. + * @param line Line number in the file where the assertion is located. + **************************************************************************************** + */ +void assert_err(const char* condition, const char* file, int line); + +/** + **************************************************************************************** + * @brief Print the assertion error reason and loop forever. + * The parameter value that is causing the assertion will also be disclosed. + * + * @param param0 parameter value 0. + * @param param1 parameter value 1. + * @param file C string containing file where the assertion is located. + * @param line Line number in the file where the assertion is located. + **************************************************************************************** + */ +void assert_param(int param0, int param1, const char* file, int line); + +/** + **************************************************************************************** + * @brief Print the assertion warning reason. + * + * @param param0 parameter value 0. + * @param param1 parameter value 1. + * @param file C string containing file where the assertion is located. + * @param line Line number in the file where the assertion is located. + **************************************************************************************** + */ +void assert_warn(int param0, int param1, const char* file, int line); + + +/** + **************************************************************************************** + * @brief Dump data value into FW. + * + * @param data start pointer of the data. + * @param length data size to dump + **************************************************************************************** + */ +void dump_data(uint8_t* data, uint16_t length); +#endif //PLF_DEBUG + + +/* + * ASSERTION CHECK + **************************************************************************************** + */ +#if PLF_DEBUG +/// Assertions showing a critical error that could require a full system reset +#define ASSERT_ERR(cond) \ + do { \ + if (!(cond)) { \ + assert_err(#cond, __FILE__, __LINE__); \ + } \ + } while(0) + +/// Assertions showing a critical error that could require a full system reset +#define ASSERT_INFO(cond, param0, param1) \ + do { \ + if (!(cond)) { \ + eif_assert_param((int)param0, (int)param1, __FILE__, __LINE__); \ + } \ + } while(0) + +/// Assertions showing a non-critical problem that has to be fixed by the SW +#define ASSERT_WARN(cond, param0, param1) \ + do { \ + if (!(cond)) { \ + assert_warn((int)param0, (int)param1, __FILE__, __LINE__); \ + } \ + } while(0) + +#define DUMP_DATA(data, length) \ + dump_data((uint8_t*)data, length) + +#else +#define ASSERT_ERR(cond) \ +// do { \ +// if (!(cond)) { \ +// assert_err(#cond, __FILE__, __LINE__); \ +// } \ +// } while(0) + +/// Assertions showing a critical error that could require a full system reset +#define ASSERT_INFO(cond, param0, param1) \ +// do { \ +// if (!(cond)) { \ +// assert_param((int)param0, (int)param1, __FILE__, __LINE__); \ +// } \ +// } while(0) + +/// Assertions showing a non-critical problem that has to be fixed by the SW +#define ASSERT_WARN(cond, param0, param1) \ +//4 + +/// DUMP data array present in the SW. +#define DUMP_DATA(data, length) +#endif //PLF_DEBUG + + +/// Object allocated in shared memory - check linker script +#define __SHARED __attribute__ ((section("shram"))) + +// required to define GLOBAL_INT_** macros as inline assembly. This file is included after +// definition of ASSERT macros as they are used inside ll.h +//#include "ll.h" // ll definitions +/// @} DRIVERS + +void SystemInit (void); + +#endif // _ARCH_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/arch/compiler.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/arch/compiler.h new file mode 100644 index 0000000..6e989f4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/arch/compiler.h @@ -0,0 +1,49 @@ +/** + **************************************************************************************** + * + * @file rvds/compiler.h + * + * @brief Definitions of compiler specific directives. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _COMPILER_H_ +#define _COMPILER_H_ + +#ifdef __ARMCC_VERSION +#elif defined(__ICCARM__) +#elif defined (__GNUC__) +#else +#error "File only included with RVDS!" +#endif // __ARMCC_VERSION +#include "core_cm0.h" + +/// define the static keyword for this compiler +#define __STATIC static + +/// define the force inlining attribute for this compiler +//#define __INLINE __forceinline static + +/// define the IRQ handler attribute for this compiler +#define __IRQ __irq + +/// define the BLE IRQ handler attribute for this compiler +#define __BTIRQ + +/// define the BLE IRQ handler attribute for this compiler +#define __BLEIRQ + +/// define the FIQ handler attribute for this compiler +#define __FIQ __irq + +/// define size of an empty array (used to declare structure with an array size not defined) +#define __ARRAY_EMPTY + +/// Put a variable in a memory maintained during deep sleep +#define __LOWPOWER_SAVED + +#endif // _COMPILER_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/host_lib/n32wb03x_host_lib.lib b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/host_lib/n32wb03x_host_lib.lib new file mode 100644 index 0000000..1e4dd0f Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/host_lib/n32wb03x_host_lib.lib differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ahi/api/ahi.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ahi/api/ahi.h new file mode 100644 index 0000000..2114593 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ahi/api/ahi.h @@ -0,0 +1,122 @@ +/** + **************************************************************************************** + * + * @file ahi.h + * + * @brief This file contains definitions related to the Application Host Interface + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef AHI_H_ +#define AHI_H_ + +/** + **************************************************************************************** + * @addtogroup AHI Application Host Interface + * @ingroup AHI + * @brief Application Host Interface, based on AHI functionality. + * + *@{ + * + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // SW configuration + +#if (AHI_TL_SUPPORT) +#include "rwip.h" // SW interface + +#include "stdbool.h" // boolean definition +#include "ke_msg.h" // kernel message definition +#include "co_list.h" // list API + + + +/* + * Defines + **************************************************************************************** + */ +/// Kernel message type +#define AHI_KE_MSG_TYPE 0x05 +///Kernel message header length for transport through interface between App and SW stack. +#define AHI_KE_MSG_HDR_LEN 8 + +/// GAPM Reset size (LC + KE_HEADER + Reset_operation code) +#define AHI_RESET_MSG_LEN (1+AHI_KE_MSG_HDR_LEN+1) +/// GAPM Reset Message use to resync. +#define AHI_RESET_MSG_BUF {AHI_KE_MSG_TYPE, \ + (GAPM_RESET_CMD & 0xFF), ((GAPM_RESET_CMD >> 8) & 0xFF), \ + (TASK_ID_GAPM & 0xFF), ((TASK_ID_GAPM >> 8) & 0xFF), \ + (TASK_ID_AHI & 0xFF), ((TASK_ID_AHI >> 8) & 0xFF), \ + 0x01, 0x00, GAPM_RESET}; + + +/// Size of the sync pattern (RW!) +#define AHI_SYNC_PATTERN_SIZE 3 +/// Transport layer synchronization pattern +#define AHI_SYNC_PATTERN_BUF "RW!" + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +///Structure for application system interface packet header +struct ahi_kemsghdr +{ + ///Message id + ke_msg_id_t id; + ///Destination task identifier for KE + ke_task_id_t dest_id; + ///Source task identifier for KE + ke_task_id_t src_id; + ///Message parameter length + uint16_t param_len; +}; + + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief AHI initialization function: initializes states and transport. + ***************************************************************************************** + */ +void ahi_init(void); + + +/** + **************************************************************************************** + * @brief Send a data message over the Application to Host Interface + * + * @param[in] msg_type Message type (logical channel) + * @param[in] len Message data length + * @param[in] data Data buffer to send + * @param[in] msg_type Callback called when message is send. It provides message pointer + ***************************************************************************************** + */ +void ahi_send_msg(uint8_t msg_type, uint16_t len, uint8_t* data, void (*tx_callback)(uint8_t*)); + +#endif //AHI_TL_SUPPORT + +/// @} AHI +#endif // AHI_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ahi/api/ahi_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ahi/api/ahi_task.h new file mode 100644 index 0000000..e8127f8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ahi/api/ahi_task.h @@ -0,0 +1,142 @@ +/** + **************************************************************************************** + * + * @file ahi_task.h + * + * @brief This file contains definitions related to the Application Host Interface + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef AHI_TASK_H_ +#define AHI_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup AHI Application Host Interface + *@{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // SW configuration + +#if (AHI_TL_SUPPORT) + +#include "rwip_task.h" // Task definition +#include "rwble_hl.h" // BLE HL default include + +/* + * INSTANCES + **************************************************************************************** + */ +/// Maximum number of instances of the AHI task +#define AHI_IDX_MAX 1 + + + + +#define LEN_PATCH_VERSION 6 + + + +/* + * STATES + **************************************************************************************** + */ +/// Possible states of the AHI task +enum AHI_STATE +{ + /// TX IDLE state + AHI_TX_IDLE, + /// TX ONGOING state + AHI_TX_ONGOING, + /// Number of states. + AHI_STATE_MAX +}; + +/* + * MESSAGES + **************************************************************************************** + */ +/// Message API of the AHI task +/*@TRACE*/ +enum ahi_msg_id +{ + // Module basic command + AHI_CMD_RESET = TASK_FIRST_MSG(TASK_ID_AHI), + AHI_CMD_SLEEP = TASK_FIRST_MSG(TASK_ID_AHI) + 0x01, + AHI_CMD_SET_UART_BAUD = TASK_FIRST_MSG(TASK_ID_AHI) + 0x02, + AHI_CMD_GET_VERSION = TASK_FIRST_MSG(TASK_ID_AHI) + 0x03, + AHI_CMD_GET_NAME = TASK_FIRST_MSG(TASK_ID_AHI) + 0x04, + AHI_CMD_IRQ_RISE_TIME = TASK_FIRST_MSG(TASK_ID_AHI) + 0x05, + AHI_CMD_BYPASS = TASK_FIRST_MSG(TASK_ID_AHI) + 0x06, + + + // General + AHI_CMD_MAC_ADDR = TASK_FIRST_MSG(TASK_ID_AHI) + 0x20, + AHI_CMD_TX_POWER = TASK_FIRST_MSG(TASK_ID_AHI) + 0x21, + AHI_CMD_GET_STATE = TASK_FIRST_MSG(TASK_ID_AHI) + 0x22, + AHI_CMD_MTU = TASK_FIRST_MSG(TASK_ID_AHI) + 0x23, + AHI_CMD_CONN_PARAM = TASK_FIRST_MSG(TASK_ID_AHI) + 0x24, + AHI_CMD_DISCONNECT = TASK_FIRST_MSG(TASK_ID_AHI) + 0x25, + AHI_CMD_RSSI = TASK_FIRST_MSG(TASK_ID_AHI) + 0x26, + AHI_CMD_DLE = TASK_FIRST_MSG(TASK_ID_AHI) + 0x27, + AHI_CMD_SEC_PARAM = TASK_FIRST_MSG(TASK_ID_AHI) + 0x28, + AHI_CMD_BOND_INFO = TASK_FIRST_MSG(TASK_ID_AHI) + 0x29, + AHI_CMD_FREQ_TEST = TASK_FIRST_MSG(TASK_ID_AHI) + 0x2A, + + // BLE Peripheral + AHI_CMD_ADV_DATA = TASK_FIRST_MSG(TASK_ID_AHI) + 0x40, + AHI_CMD_SCAN_RSP_DATA = TASK_FIRST_MSG(TASK_ID_AHI) + 0x41, + AHI_CMD_ADV_PARAM = TASK_FIRST_MSG(TASK_ID_AHI) + 0x42, + AHI_CMD_ADV_START_CONTROL = TASK_FIRST_MSG(TASK_ID_AHI) + 0x43, + AHI_CMD_SEC_REQ = TASK_FIRST_MSG(TASK_ID_AHI) + 0x44, + AHI_CMD_CFG_SVC = TASK_FIRST_MSG(TASK_ID_AHI) + 0x45, + AHI_CMD_SET_READ_REQ_DATA = TASK_FIRST_MSG(TASK_ID_AHI) + 0x46, + AHI_CMD_SET_IND_NTF_DATA = TASK_FIRST_MSG(TASK_ID_AHI) + 0x47, + AHI_CMD_SET_WRITE_REQ_CFM = TASK_FIRST_MSG(TASK_ID_AHI) + 0x48, + + // BLE Central + AHI_CMD_SCAN_PARAM = TASK_FIRST_MSG(TASK_ID_AHI) + 0x60, + AHI_CMD_SCAN_START_CONTROL = TASK_FIRST_MSG(TASK_ID_AHI) + 0x61, + AHI_CMD_CONNECT = TASK_FIRST_MSG(TASK_ID_AHI) + 0x62, + AHI_CMD_START_PAIR = TASK_FIRST_MSG(TASK_ID_AHI) + 0x63, + AHI_CMD_GET_SVC = TASK_FIRST_MSG(TASK_ID_AHI) + 0x64, + AHI_CMD_READ = TASK_FIRST_MSG(TASK_ID_AHI) + 0x65, + AHI_CMD_WRITE = TASK_FIRST_MSG(TASK_ID_AHI) + 0x66, + + // CMD store and trigger + + // MCU Peripheral + + // Closed to user + AHI_CMD_DEBUG_READ_REG = TASK_FIRST_MSG(TASK_ID_AHI) + 0xF0, + AHI_CMD_DEBUG_WRITE_REG = TASK_FIRST_MSG(TASK_ID_AHI) + 0xF1, + AHI_RESERVED = TASK_FIRST_MSG(TASK_ID_AHI) + 0xF2, + + AHI_MSG_ID_LAST +}; + + + + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +#endif //AHI_TL_SUPPORT + +/// @} AHI + +#endif // AHI_TASK_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/att.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/att.h new file mode 100644 index 0000000..afa71c0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/att.h @@ -0,0 +1,1177 @@ +/** + **************************************************************************************** + * + * @file att.h + * + * @brief Header file - ATT. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef ATT_H_ +#define ATT_H_ + +/** + **************************************************************************************** + * @addtogroup ATT Attribute Protocol + * @ingroup HOST + * @brief Attribute Protocol. + * + * The ATT block contains the procedures for discovering, reading, writing + * and indicating attributes to peer device . It also defines a number of items + * that caters to the security aspect of the block as access to some information + * may require both authorization and an authenticated and encrypted physical + * link before an attribute can be read or written + * + * @{ + * + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include + +/* + * DEFINES + **************************************************************************************** + */ + +/// Macro used to convert CPU integer define to LSB first 16-bits UUID +#define ATT_UUID_16(uuid) (uuid) + +/// Invalid attribute handle +#define ATT_INVALID_HDL (0x0000) +/// Invalid attribute idx (used for profiles) +#define ATT_INVALID_IDX (0xff) + +#define ATT_1ST_REQ_START_HDL 0x0001 +#define ATT_1ST_REQ_END_HDL 0xFFFF + +/// Maximum possible attribute handle +#define ATT_MAX_ATTR_HDL ATT_1ST_REQ_END_HDL + +/// Offset of value in signed PDU +#define ATT_SIGNED_PDU_VAL_OFFSET 0x03 + +/// Attribute Features +#define ATT_SERVER_CONFIG 0x0001 +#define ATT_SERVICE_DISC 0x0002 +#define ATT_RELATIONSHIP_DISC 0x0004 +#define ATT_CHAR_DISC 0x0008 +#define ATT_CHAR_DESC_DISC 0x0010 +#define ATT_RD_CHAR_VALUE 0x0020 +#define ATT_WR_CHAR_VALUE 0x0040 +#define ATT_NOTIF_CHAR_VALUE 0x0080 +#define ATT_IND_CHAR_VALUE 0x0100 +#define ATT_RD_CHAR_DESC 0x0200 +#define ATT_WR_CHAR_DESC 0x0400 + +/// Length, number, offset defines +#define ATT_SVC_VALUE_MAX_LEN 0x0030 +#define ATT_CHAR_NAME_MAX_LEN 0x0030 +#define ATT_UUID_16_LEN 0x0002 +#define ATT_UUID_32_LEN 0x0004 +#define ATT_UUID_128_LEN 0x0010 + +/// offset - l2cap header and ATT code +#define ATT_PDU_DATA_OFFSET 0x05 + +/// Characteristic Properties Bit +#define ATT_CHAR_PROP_BCAST 0x01 +#define ATT_CHAR_PROP_RD 0x02 +#define ATT_CHAR_PROP_WR_NO_RESP 0x04 +#define ATT_CHAR_PROP_WR 0x08 +#define ATT_CHAR_PROP_NTF 0x10 +#define ATT_CHAR_PROP_IND 0x20 +#define ATT_CHAR_PROP_AUTH 0x40 +#define ATT_CHAR_PROP_EXT_PROP 0x80 +/// Invalid Attribute Handle +#define ATT_INVALID_SEARCH_HANDLE 0x0000 +#define ATT_INVALID_HANDLE 0x0000 +/// Read Information Request +#define ATT_UUID_FILTER_0 0x00 +#define ATT_UUID_FILTER_2 0x02 +#define ATT_UUID_FILTER_16 0x10 +/// Read Information Response +#define ATT_FORMAT_LEN 0x0001 +#define ATT_FORMAT_16BIT_UUID 0x01 +#define ATT_FORMAT_128BIT_UUID 0x02 +/// For No fix length PDU +#define ATT_HANDLE_LEN 0x0002 +#define ATT_EACHLEN_LEN 0x0001 +#define ATT_PROP_LEN 0x0001 +#define ATT_CODE_LEN 0x0001 +#define ATT_CODE_AND_DATA_LEN 0x0002 +#define ATT_CODE_AND_HANDLE_LEN 0x0003 +#define ATT_CODE_AND_HANDLE_LEN_AND_OFFSET 0x0005 +#define ATT_SIGNATURE_LEN 0x0C + +/// extended characteristics +#define ATT_EXT_RELIABLE_WRITE 0x0001 +#define ATT_EXT_WRITABLE_AUX 0x0002 +#define ATT_EXT_RFU 0xFFFC + +/// PDU size for error response +#define ATT_ERROR_RESP_LEN 0x05 + +/// Offset of value in signed PDU +#define ATT_SIGNED_PDU_VAL_OFFSET 0x03 + +/// Attribute operation code - Method (bit 5 - 0) +#define ATT_OPCODE_METHOD_MASK 0x3F +#define ATT_OPCODE_METHOD_LSB 0 +/// Attribute operation code - Command Flag (bit 6) +#define ATT_OPCODE_CMD_FLAG_BIT 0x40 +#define ATT_OPCODE_CMD_FLAG_POS 6 +/// Attribute operation code - Authentication Signature Flag (bit 7) +#define ATT_OPCODE_AUTH_SIGNATURE_FLAG_BIT 0x80 +#define ATT_OPCODE_AUTH_SIGNATURE_FLAG_POS 7 + +#define ATT_BT_UUID_128 {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, \ + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} + + +/// MAC length +#define ATT_SIGN_MAC_LEN (8) +/// SignCounter length +#define ATT_SIGN_COUNTER_LEN (4) +/// Signature length +#define ATT_SIGN_LEN (ATT_SIGN_MAC_LEN + ATT_SIGN_COUNTER_LEN) + +/// This value ensure to have up to 128 client feature supported would be sufficient for several years. +#define ATT_MAX_CLI_FEAT_LEN 16 + +/* Attribute Specification Defines */ + +/// Common 16-bit Universal Unique Identifier +enum { + ATT_INVALID_UUID = ATT_UUID_16(0x0000), + /*----------------- SERVICES ---------------------*/ + /// Generic Access Profile + ATT_SVC_GENERIC_ACCESS = ATT_UUID_16(0x1800), + /// Attribute Profile + ATT_SVC_GENERIC_ATTRIBUTE = ATT_UUID_16(0x1801), + /// Immediate alert Service + ATT_SVC_IMMEDIATE_ALERT = ATT_UUID_16(0x1802), + /// Link Loss Service + ATT_SVC_LINK_LOSS = ATT_UUID_16(0x1803), + /// Tx Power Service + ATT_SVC_TX_POWER = ATT_UUID_16(0x1804), + /// Current Time Service Service + ATT_SVC_CURRENT_TIME = ATT_UUID_16(0x1805), + /// Reference Time Update Service + ATT_SVC_REF_TIME_UPDATE = ATT_UUID_16(0x1806), + /// Next DST Change Service + ATT_SVC_NEXT_DST_CHANGE = ATT_UUID_16(0x1807), + /// Glucose Service + ATT_SVC_GLUCOSE = ATT_UUID_16(0x1808), + /// Health Thermometer Service + ATT_SVC_HEALTH_THERMOM = ATT_UUID_16(0x1809), + /// Device Information Service + ATT_SVC_DEVICE_INFO = ATT_UUID_16(0x180A), + /// Heart Rate Service + ATT_SVC_HEART_RATE = ATT_UUID_16(0x180D), + /// Phone Alert Status Service + ATT_SVC_PHONE_ALERT_STATUS = ATT_UUID_16(0x180E), + /// Battery Service + ATT_SVC_BATTERY_SERVICE = ATT_UUID_16(0x180F), + /// Blood Pressure Service + ATT_SVC_BLOOD_PRESSURE = ATT_UUID_16(0x1810), + /// Alert Notification Service + ATT_SVC_ALERT_NTF = ATT_UUID_16(0x1811), + /// HID Service + ATT_SVC_HID = ATT_UUID_16(0x1812), + /// Scan Parameters Service + ATT_SVC_SCAN_PARAMETERS = ATT_UUID_16(0x1813), + /// Running Speed and Cadence Service + ATT_SVC_RUNNING_SPEED_CADENCE = ATT_UUID_16(0x1814), + /// Cycling Speed and Cadence Service + ATT_SVC_CYCLING_SPEED_CADENCE = ATT_UUID_16(0x1816), + /// Cycling Power Service + ATT_SVC_CYCLING_POWER = ATT_UUID_16(0x1818), + /// Location and Navigation Service + ATT_SVC_LOCATION_AND_NAVIGATION = ATT_UUID_16(0x1819), + /// Environmental Sensing Service + ATT_SVC_ENVIRONMENTAL_SENSING = ATT_UUID_16(0x181A), + /// Body Composition Service + ATT_SVC_BODY_COMPOSITION = ATT_UUID_16(0x181B), + /// User Data Service + ATT_SVC_USER_DATA = ATT_UUID_16(0x181C), + /// Weight Scale Service + ATT_SVC_WEIGHT_SCALE = ATT_UUID_16(0x181D), + /// Bond Management Service + ATT_SVC_BOND_MANAGEMENT = ATT_UUID_16(0x181E), + /// Continuous Glucose Monitoring Service + ATT_SVC_CONTINUOUS_GLUCOSE_MONITORING = ATT_UUID_16(0x181F), + /// Internet Protocol Support Service + ATT_SVC_IP_SUPPORT = ATT_UUID_16(0x1820), + /// Indoor Positioning Service + ATT_SVC_INDOOR_POSITIONING = ATT_UUID_16(0x1821), + /// Pulse Oximeter Service + ATT_SVC_PULSE_OXIMETER = ATT_UUID_16(0x1822), + /// HTTP Proxy Service + ATT_SVC_HTTP_PROXY = ATT_UUID_16(0x1823), + /// Transport Discovery Service + ATT_SVC_TRANSPORT_DISCOVERY = ATT_UUID_16(0x1824), + /// Object Transfer Service + ATT_SVC_OBJECT_TRANSFER = ATT_UUID_16(0x1825), + /// Mesh Provisioning Service + ATT_SVC_MESH_PROVISIONING = ATT_UUID_16(0x1827), + /// Mesh Proxy Service + ATT_SVC_MESH_PROXY = ATT_UUID_16(0x1828), + + /*------------------- UNITS ---------------------*/ + /// No defined unit + ATT_UNIT_UNITLESS = ATT_UUID_16(0x2700), + /// Length Unit - Metre + ATT_UNIT_METRE = ATT_UUID_16(0x2701), + ///Mass unit - Kilogram + ATT_UNIT_KG = ATT_UUID_16(0x2702), + ///Time unit - second + ATT_UNIT_SECOND = ATT_UUID_16(0x2703), + ///Electric current unit - Ampere + ATT_UNIT_AMPERE = ATT_UUID_16(0x2704), + ///Thermodynamic Temperature unit - Kelvin + ATT_UNIT_KELVIN = ATT_UUID_16(0x2705), + /// Amount of substance unit - mole + ATT_UNIT_MOLE = ATT_UUID_16(0x2706), + ///Luminous intensity unit - candela + ATT_UNIT_CANDELA = ATT_UUID_16(0x2707), + ///Area unit - square metres + ATT_UNIT_SQ_METRE = ATT_UUID_16(0x2710), + ///Colume unit - cubic metres + ATT_UNIT_CUBIC_METRE = ATT_UUID_16(0x2710), + ///Velocity unit - metres per second + ATT_UNIT_METRE_PER_SECOND = ATT_UUID_16(0x2711), + ///Acceleration unit - metres per second squared + ATT_UNIT_METRES_PER_SEC_SQ = ATT_UUID_16(0x2712), + ///Wavenumber unit - reciprocal metre + ATT_UNIT_RECIPROCAL_METRE = ATT_UUID_16(0x2713), + ///Density unit - kilogram per cubic metre + ATT_UNIT_DENS_KG_PER_CUBIC_METRE = ATT_UUID_16(0x2714), + ///Surface density unit - kilogram per square metre + ATT_UNIT_KG_PER_SQ_METRE = ATT_UUID_16(0x2715), + ///Specific volume unit - cubic metre per kilogram + ATT_UNIT_CUBIC_METRE_PER_KG = ATT_UUID_16(0x2716), + ///Current density unit - ampere per square metre + ATT_UNIT_AMPERE_PER_SQ_METRE = ATT_UUID_16(0x2717), + ///Magnetic field strength unit - Ampere per metre + ATT_UNIT_AMPERE_PER_METRE = ATT_UUID_16(0x2718), + ///Amount concentration unit - mole per cubic metre + ATT_UNIT_MOLE_PER_CUBIC_METRE = ATT_UUID_16(0x2719), + ///Mass Concentration unit - kilogram per cubic metre + ATT_UNIT_MASS_KG_PER_CUBIC_METRE = ATT_UUID_16(0x271A), + ///Luminance unit - candela per square metre + ATT_UNIT_CANDELA_PER_SQ_METRE = ATT_UUID_16(0x271B), + ///Refractive index unit + ATT_UNIT_REFRACTIVE_INDEX = ATT_UUID_16(0x271C), + ///Relative permeability unit + ATT_UNIT_RELATIVE_PERMEABILITY = ATT_UUID_16(0x271D), + ///Plane angle unit - radian + ATT_UNIT_RADIAN = ATT_UUID_16(0x2720), + ///Solid angle unit - steradian + ATT_UNIT_STERADIAN = ATT_UUID_16(0x2721), + ///Frequency unit - Hertz + ATT_UNIT_HERTZ = ATT_UUID_16(0x2722), + ///Force unit - Newton + ATT_UNIT_NEWTON = ATT_UUID_16(0x2723), + ///Pressure unit - Pascal + ATT_UNIT_PASCAL = ATT_UUID_16(0x2724), + ///Energy unit - Joule + ATT_UNIT_JOULE = ATT_UUID_16(0x2725), + ///Power unit - Watt + ATT_UNIT_WATT = ATT_UUID_16(0x2726), + ///electric Charge unit - Coulomb + ATT_UNIT_COULOMB = ATT_UUID_16(0x2727), + ///Electric potential difference - Volt + ATT_UNIT_VOLT = ATT_UUID_16(0x2728), + ///Capacitance unit - Farad + ATT_UNIT_FARAD = ATT_UUID_16(0x2729), + ///electric resistance unit - Ohm + ATT_UNIT_OHM = ATT_UUID_16(0x272A), + ///Electric conductance - Siemens + ATT_UNIT_SIEMENS = ATT_UUID_16(0x272B), + ///Magnetic flux unit - Weber + ATT_UNIT_WEBER = ATT_UUID_16(0x272C), + ///Magnetic flux density unit - Tesla + ATT_UNIT_TESLA = ATT_UUID_16(0x272D), + ///Inductance unit - Henry + ATT_UNIT_HENRY = ATT_UUID_16(0x272E), + ///Temperature unit - degree Celsius + ATT_UNIT_CELSIUS = ATT_UUID_16(0x272F), + ///Luminous flux unit - lumen + ATT_UNIT_LUMEN = ATT_UUID_16(0x2730), + ///Illuminance unit - lux + ATT_UNIT_LUX = ATT_UUID_16(0x2731), + ///Activity referred to a radionuclide unit - becquerel + ATT_UNIT_BECQUEREL = ATT_UUID_16(0x2732), + ///Absorbed dose unit - Gray + ATT_UNIT_GRAY = ATT_UUID_16(0x2733), + ///Dose equivalent unit - Sievert + ATT_UNIT_SIEVERT = ATT_UUID_16(0x2734), + ///Catalytic activity unit - Katal + ATT_UNIT_KATAL = ATT_UUID_16(0x2735), + ///Synamic viscosity unit - Pascal second + ATT_UNIT_PASCAL_SECOND = ATT_UUID_16(0x2740), + ///Moment of force unit - Newton metre + ATT_UNIT_NEWTON_METRE = ATT_UUID_16(0x2741), + ///surface tension unit - Newton per metre + ATT_UNIT_NEWTON_PER_METRE = ATT_UUID_16(0x2742), + ///Angular velocity unit - radian per second + ATT_UNIT_RADIAN_PER_SECOND = ATT_UUID_16(0x2743), + ///Angular acceleration unit - radian per second squared + ATT_UNIT_RADIAN_PER_SECOND_SQ = ATT_UUID_16(0x2744), + ///Heat flux density unit - Watt per square metre + ATT_UNIT_WATT_PER_SQ_METRE = ATT_UUID_16(0x2745), + ///HEat capacity unit - Joule per Kelvin + ATT_UNIT_JOULE_PER_KELVIN = ATT_UUID_16(0x2746), + ///Specific heat capacity unit - Joule per kilogram kelvin + ATT_UNIT_JOULE_PER_KG_KELVIN = ATT_UUID_16(0x2747), + ///Specific Energy unit - Joule per kilogram + ATT_UNIT_JOULE_PER_KG = ATT_UUID_16(0x2748), + ///Thermal conductivity - Watt per metre Kelvin + ATT_UNIT_WATT_PER_METRE_KELVIN = ATT_UUID_16(0x2749), + ///Energy Density unit - joule per cubic metre + ATT_UNIT_JOULE_PER_CUBIC_METRE = ATT_UUID_16(0x274A), + ///Electric field strength unit - volt per metre + ATT_UNIT_VOLT_PER_METRE = ATT_UUID_16(0x274B), + ///Electric charge density unit - coulomb per cubic metre + ATT_UNIT_COULOMB_PER_CUBIC_METRE = ATT_UUID_16(0x274C), + ///Surface charge density unit - coulomb per square metre + ATT_UNIT_SURF_COULOMB_PER_SQ_METRE = ATT_UUID_16(0x274D), + ///Electric flux density unit - coulomb per square metre + ATT_UNIT_FLUX_COULOMB_PER_SQ_METRE = ATT_UUID_16(0x274E), + ///Permittivity unit - farad per metre + ATT_UNIT_FARAD_PER_METRE = ATT_UUID_16(0x274F), + ///Permeability unit - henry per metre + ATT_UNIT_HENRY_PER_METRE = ATT_UUID_16(0x2750), + ///Molar energy unit - joule per mole + ATT_UNIT_JOULE_PER_MOLE = ATT_UUID_16(0x2751), + ///Molar entropy unit - joule per mole kelvin + ATT_UNIT_JOULE_PER_MOLE_KELVIN = ATT_UUID_16(0x2752), + ///Exposure unit - coulomb per kilogram + ATT_UNIT_COULOMB_PER_KG = ATT_UUID_16(0x2753), + ///Absorbed dose rate unit - gray per second + ATT_UNIT_GRAY_PER_SECOND = ATT_UUID_16(0x2754), + ///Radiant intensity unit - watt per steradian + ATT_UNIT_WATT_PER_STERADIAN = ATT_UUID_16(0x2755), + ///Radiance unit - watt per square meter steradian + ATT_UNIT_WATT_PER_SQ_METRE_STERADIAN = ATT_UUID_16(0x2756), + ///Catalytic activity concentration unit - katal per cubic metre + ATT_UNIT_KATAL_PER_CUBIC_METRE = ATT_UUID_16(0x2757), + ///Time unit - minute + ATT_UNIT_MINUTE = ATT_UUID_16(0x2760), + ///Time unit - hour + ATT_UNIT_HOUR = ATT_UUID_16(0x2761), + ///Time unit - day + ATT_UNIT_DAY = ATT_UUID_16(0x2762), + ///Plane angle unit - degree + ATT_UNIT_ANGLE_DEGREE = ATT_UUID_16(0x2763), + ///Plane angle unit - minute + ATT_UNIT_ANGLE_MINUTE = ATT_UUID_16(0x2764), + ///Plane angle unit - second + ATT_UNIT_ANGLE_SECOND = ATT_UUID_16(0x2765), + ///Area unit - hectare + ATT_UNIT_HECTARE = ATT_UUID_16(0x2766), + ///Volume unit - litre + ATT_UNIT_LITRE = ATT_UUID_16(0x2767), + ///Mass unit - tonne + ATT_UNIT_TONNE = ATT_UUID_16(0x2768), + ///Pressure unit - bar + ATT_UNIT_BAR = ATT_UUID_16(0x2780), + ///Pressure unit - millimetre of mercury + ATT_UNIT_MM_MERCURY = ATT_UUID_16(0x2781), + ///Length unit - angstrom + ATT_UNIT_ANGSTROM = ATT_UUID_16(0x2782), + ///Length unit - nautical mile + ATT_UNIT_NAUTICAL_MILE = ATT_UUID_16(0x2783), + ///Area unit - barn + ATT_UNIT_BARN = ATT_UUID_16(0x2784), + ///Velocity unit - knot + ATT_UNIT_KNOT = ATT_UUID_16(0x2785), + ///Logarithmic radio quantity unit - neper + ATT_UNIT_NEPER = ATT_UUID_16(0x2786), + ///Logarithmic radio quantity unit - bel + ATT_UNIT_BEL = ATT_UUID_16(0x2787), + ///Length unit - yard + ATT_UNIT_YARD = ATT_UUID_16(0x27A0), + ///Length unit - parsec + ATT_UNIT_PARSEC = ATT_UUID_16(0x27A1), + ///length unit - inch + ATT_UNIT_INCH = ATT_UUID_16(0x27A2), + ///length unit - foot + ATT_UNIT_FOOT = ATT_UUID_16(0x27A3), + ///length unit - mile + ATT_UNIT_MILE = ATT_UUID_16(0x27A4), + ///pressure unit - pound-force per square inch + ATT_UNIT_POUND_FORCE_PER_SQ_INCH = ATT_UUID_16(0x27A5), + ///velocity unit - kilometre per hour + ATT_UNIT_KM_PER_HOUR = ATT_UUID_16(0x27A6), + ///velocity unit - mile per hour + ATT_UNIT_MILE_PER_HOUR = ATT_UUID_16(0x27A7), + ///angular velocity unit - revolution per minute + ATT_UNIT_REVOLUTION_PER_MINUTE = ATT_UUID_16(0x27A8), + ///energy unit - gram calorie + ATT_UNIT_GRAM_CALORIE = ATT_UUID_16(0x27A9), + ///energy unit - kilogram calorie + ATT_UNIT_KG_CALORIE = ATT_UUID_16(0x27AA), + /// energy unit - kilowatt hour + ATT_UNIT_KILOWATT_HOUR = ATT_UUID_16(0x27AB), + ///thermodynamic temperature unit - degree Fahrenheit + ATT_UNIT_FAHRENHEIT = ATT_UUID_16(0x27AC), + ///percentage + ATT_UNIT_PERCENTAGE = ATT_UUID_16(0x27AD), + ///per mille + ATT_UNIT_PER_MILLE = ATT_UUID_16(0x27AE), + ///period unit - beats per minute) + ATT_UNIT_BEATS_PER_MINUTE = ATT_UUID_16(0x27AF), + ///electric charge unit - ampere hours + ATT_UNIT_AMPERE_HOURS = ATT_UUID_16(0x27B0), + ///mass density unit - milligram per decilitre + ATT_UNIT_MILLIGRAM_PER_DECILITRE = ATT_UUID_16(0x27B1), + ///mass density unit - millimole per litre + ATT_UNIT_MILLIMOLE_PER_LITRE = ATT_UUID_16(0x27B2), + ///time unit - year + ATT_UNIT_YEAR = ATT_UUID_16(0x27B3), + ////time unit - month + ATT_UNIT_MONTH = ATT_UUID_16(0x27B4), + + + /*---------------- DECLARATIONS -----------------*/ + /// Primary service Declaration + ATT_DECL_PRIMARY_SERVICE = ATT_UUID_16(0x2800), + /// Secondary service Declaration + ATT_DECL_SECONDARY_SERVICE = ATT_UUID_16(0x2801), + /// Include Declaration + ATT_DECL_INCLUDE = ATT_UUID_16(0x2802), + /// Characteristic Declaration + ATT_DECL_CHARACTERISTIC = ATT_UUID_16(0x2803), + + + /*----------------- DESCRIPTORS -----------------*/ + /// Characteristic extended properties + ATT_DESC_CHAR_EXT_PROPERTIES = ATT_UUID_16(0x2900), + /// Characteristic user description + ATT_DESC_CHAR_USER_DESCRIPTION = ATT_UUID_16(0x2901), + /// Client characteristic configuration + ATT_DESC_CLIENT_CHAR_CFG = ATT_UUID_16(0x2902), + /// Server characteristic configuration + ATT_DESC_SERVER_CHAR_CFG = ATT_UUID_16(0x2903), + /// Characteristic Presentation Format + ATT_DESC_CHAR_PRES_FORMAT = ATT_UUID_16(0x2904), + /// Characteristic Aggregate Format + ATT_DESC_CHAR_AGGREGATE_FORMAT = ATT_UUID_16(0x2905), + /// Valid Range + ATT_DESC_VALID_RANGE = ATT_UUID_16(0x2906), + /// External Report Reference + ATT_DESC_EXT_REPORT_REF = ATT_UUID_16(0x2907), + /// Report Reference + ATT_DESC_REPORT_REF = ATT_UUID_16(0x2908), + /// Environmental Sensing Configuration + ATT_DESC_ES_CONFIGURATION = ATT_UUID_16(0x290B), + /// Environmental Sensing Measurement + ATT_DESC_ES_MEASUREMENT = ATT_UUID_16(0x290C), + /// Environmental Sensing Trigger Setting + ATT_DESC_ES_TRIGGER_SETTING = ATT_UUID_16(0x290D), + + + /*--------------- CHARACTERISTICS ---------------*/ + /// Device name + ATT_CHAR_DEVICE_NAME = ATT_UUID_16(0x2A00), + /// Appearance + ATT_CHAR_APPEARANCE = ATT_UUID_16(0x2A01), + /// Privacy flag + ATT_CHAR_PRIVACY_FLAG = ATT_UUID_16(0x2A02), + /// Reconnection address + ATT_CHAR_RECONNECTION_ADDR = ATT_UUID_16(0x2A03), + /// Peripheral preferred connection parameters + ATT_CHAR_PERIPH_PREF_CON_PARAM = ATT_UUID_16(0x2A04), + /// Service handles changed + ATT_CHAR_SERVICE_CHANGED = ATT_UUID_16(0x2A05), + /// Alert Level characteristic + ATT_CHAR_ALERT_LEVEL = ATT_UUID_16(0x2A06), + /// Tx Power Level + ATT_CHAR_TX_POWER_LEVEL = ATT_UUID_16(0x2A07), + /// Date Time + ATT_CHAR_DATE_TIME = ATT_UUID_16(0x2A08), + /// Day of Week + ATT_CHAR_DAY_WEEK = ATT_UUID_16(0x2A09), + /// Day Date Time + ATT_CHAR_DAY_DATE_TIME = ATT_UUID_16(0x2A0A), + /// Exact time 256 + ATT_CHAR_EXACT_TIME_256 = ATT_UUID_16(0x2A0C), + /// DST Offset + ATT_CHAR_DST_OFFSET = ATT_UUID_16(0x2A0D), + /// Time zone + ATT_CHAR_TIME_ZONE = ATT_UUID_16(0x2A0E), + /// Local time Information + ATT_CHAR_LOCAL_TIME_INFO = ATT_UUID_16(0x2A0F), + /// Time with DST + ATT_CHAR_TIME_WITH_DST = ATT_UUID_16(0x2A11), + /// Time Accuracy + ATT_CHAR_TIME_ACCURACY = ATT_UUID_16(0x2A12), + ///Time Source + ATT_CHAR_TIME_SOURCE = ATT_UUID_16(0x2A13), + /// Reference Time Information + ATT_CHAR_REFERENCE_TIME_INFO = ATT_UUID_16(0x2A14), + /// Time Update Control Point + ATT_CHAR_TIME_UPDATE_CNTL_POINT = ATT_UUID_16(0x2A16), + /// Time Update State + ATT_CHAR_TIME_UPDATE_STATE = ATT_UUID_16(0x2A17), + /// Glucose Measurement + ATT_CHAR_GLUCOSE_MEAS = ATT_UUID_16(0x2A18), + /// Battery Level + ATT_CHAR_BATTERY_LEVEL = ATT_UUID_16(0x2A19), + /// Temperature Measurement + ATT_CHAR_TEMPERATURE_MEAS = ATT_UUID_16(0x2A1C), + /// Temperature Type + ATT_CHAR_TEMPERATURE_TYPE = ATT_UUID_16(0x2A1D), + /// Intermediate Temperature + ATT_CHAR_INTERMED_TEMPERATURE = ATT_UUID_16(0x2A1E), + /// Measurement Interval + ATT_CHAR_MEAS_INTERVAL = ATT_UUID_16(0x2A21), + /// Boot Keyboard Input Report + ATT_CHAR_BOOT_KB_IN_REPORT = ATT_UUID_16(0x2A22), + /// System ID + ATT_CHAR_SYS_ID = ATT_UUID_16(0x2A23), + /// Model Number String + ATT_CHAR_MODEL_NB = ATT_UUID_16(0x2A24), + /// Serial Number String + ATT_CHAR_SERIAL_NB = ATT_UUID_16(0x2A25), + /// Firmware Revision String + ATT_CHAR_FW_REV = ATT_UUID_16(0x2A26), + /// Hardware revision String + ATT_CHAR_HW_REV = ATT_UUID_16(0x2A27), + /// Software Revision String + ATT_CHAR_SW_REV = ATT_UUID_16(0x2A28), + /// Manufacturer Name String + ATT_CHAR_MANUF_NAME = ATT_UUID_16(0x2A29), + /// IEEE Regulatory Certification Data List + ATT_CHAR_IEEE_CERTIF = ATT_UUID_16(0x2A2A), + /// CT Time + ATT_CHAR_CT_TIME = ATT_UUID_16(0x2A2B), + /// Magnetic Declination + ATT_CHAR_MAGN_DECLINE = ATT_UUID_16(0x2A2C), + /// Scan Refresh + ATT_CHAR_SCAN_REFRESH = ATT_UUID_16(0x2A31), + /// Boot Keyboard Output Report + ATT_CHAR_BOOT_KB_OUT_REPORT = ATT_UUID_16(0x2A32), + /// Boot Mouse Input Report + ATT_CHAR_BOOT_MOUSE_IN_REPORT = ATT_UUID_16(0x2A33), + /// Glucose Measurement Context + ATT_CHAR_GLUCOSE_MEAS_CTX = ATT_UUID_16(0x2A34), + /// Blood Pressure Measurement + ATT_CHAR_BLOOD_PRESSURE_MEAS = ATT_UUID_16(0x2A35), + /// Intermediate Cuff Pressure + ATT_CHAR_INTERMEDIATE_CUFF_PRESSURE = ATT_UUID_16(0x2A36), + /// Heart Rate Measurement + ATT_CHAR_HEART_RATE_MEAS = ATT_UUID_16(0x2A37), + /// Body Sensor Location + ATT_CHAR_BODY_SENSOR_LOCATION = ATT_UUID_16(0x2A38), + /// Heart Rate Control Point + ATT_CHAR_HEART_RATE_CNTL_POINT = ATT_UUID_16(0x2A39), + /// Alert Status + ATT_CHAR_ALERT_STATUS = ATT_UUID_16(0x2A3F), + /// Ringer Control Point + ATT_CHAR_RINGER_CNTL_POINT = ATT_UUID_16(0x2A40), + /// Ringer Setting + ATT_CHAR_RINGER_SETTING = ATT_UUID_16(0x2A41), + /// Alert Category ID Bit Mask + ATT_CHAR_ALERT_CAT_ID_BIT_MASK = ATT_UUID_16(0x2A42), + /// Alert Category ID + ATT_CHAR_ALERT_CAT_ID = ATT_UUID_16(0x2A43), + /// Alert Notification Control Point + ATT_CHAR_ALERT_NTF_CTNL_PT = ATT_UUID_16(0x2A44), + /// Unread Alert Status + ATT_CHAR_UNREAD_ALERT_STATUS = ATT_UUID_16(0x2A45), + /// New Alert + ATT_CHAR_NEW_ALERT = ATT_UUID_16(0x2A46), + /// Supported New Alert Category + ATT_CHAR_SUP_NEW_ALERT_CAT = ATT_UUID_16(0x2A47), + /// Supported Unread Alert Category + ATT_CHAR_SUP_UNREAD_ALERT_CAT = ATT_UUID_16(0x2A48), + /// Blood Pressure Feature + ATT_CHAR_BLOOD_PRESSURE_FEATURE = ATT_UUID_16(0x2A49), + /// HID Information + ATT_CHAR_HID_INFO = ATT_UUID_16(0x2A4A), + /// Report Map + ATT_CHAR_REPORT_MAP = ATT_UUID_16(0x2A4B), + /// HID Control Point + ATT_CHAR_HID_CTNL_PT = ATT_UUID_16(0x2A4C), + /// Report + ATT_CHAR_REPORT = ATT_UUID_16(0x2A4D), + /// Protocol Mode + ATT_CHAR_PROTOCOL_MODE = ATT_UUID_16(0x2A4E), + /// Scan Interval Window + ATT_CHAR_SCAN_INTV_WD = ATT_UUID_16(0x2A4F), + /// PnP ID + ATT_CHAR_PNP_ID = ATT_UUID_16(0x2A50), + /// Glucose Feature + ATT_CHAR_GLUCOSE_FEATURE = ATT_UUID_16(0x2A51), + /// Record access control point + ATT_CHAR_REC_ACCESS_CTRL_PT = ATT_UUID_16(0x2A52), + /// RSC Measurement + ATT_CHAR_RSC_MEAS = ATT_UUID_16(0x2A53), + /// RSC Feature + ATT_CHAR_RSC_FEAT = ATT_UUID_16(0x2A54), + /// SC Control Point + ATT_CHAR_SC_CNTL_PT = ATT_UUID_16(0x2A55), + /// CSC Measurement + ATT_CHAR_CSC_MEAS = ATT_UUID_16(0x2A5B), + /// CSC Feature + ATT_CHAR_CSC_FEAT = ATT_UUID_16(0x2A5C), + /// Sensor Location + ATT_CHAR_SENSOR_LOC = ATT_UUID_16(0x2A5D), + /// PLX Spot-Check Measurement + ATT_CHAR_PLX_SPOT_CHECK_MEASUREMENT_LOC = ATT_UUID_16(0x2A5E), + /// PLX Continuous Measurement + ATT_CHAR_PLX_CONTINUOUS_MEASUREMENT_LOC = ATT_UUID_16(0x2A5F), + /// PLX Features + ATT_CHAR_PLX_FEATURES_LOC = ATT_UUID_16(0x2A60), + /// CP Measurement + ATT_CHAR_CP_MEAS = ATT_UUID_16(0x2A63), + /// CP Vector + ATT_CHAR_CP_VECTOR = ATT_UUID_16(0x2A64), + /// CP Feature + ATT_CHAR_CP_FEAT = ATT_UUID_16(0x2A65), + /// CP Control Point + ATT_CHAR_CP_CNTL_PT = ATT_UUID_16(0x2A66), + /// Location and Speed + ATT_CHAR_LOC_SPEED = ATT_UUID_16(0x2A67), + /// Navigation + ATT_CHAR_NAVIGATION = ATT_UUID_16(0x2A68), + /// Position Quality + ATT_CHAR_POS_QUALITY = ATT_UUID_16(0x2A69), + /// LN Feature + ATT_CHAR_LN_FEAT = ATT_UUID_16(0x2A6A), + /// LN Control Point + ATT_CHAR_LN_CNTL_PT = ATT_UUID_16(0x2A6B), + /// Elevation + ATT_CHAR_ELEVATION = ATT_UUID_16(0x2A6C), + /// Pressure + ATT_CHAR_PRESSURE = ATT_UUID_16(0x2A6D), + /// Temperature + ATT_CHAR_TEMPERATURE = ATT_UUID_16(0x2A6E), + /// Humidity + ATT_CHAR_HUMIDITY = ATT_UUID_16(0x2A6F), + /// True Wind Speed + ATT_CHAR_TRUE_WIND_SPEED = ATT_UUID_16(0x2A70), + /// True Wind Direction + ATT_CHAR_TRUE_WIND_DIR = ATT_UUID_16(0x2A71), + /// Apparent Wind Speed + ATT_CHAR_APRNT_WIND_SPEED = ATT_UUID_16(0x2A72), + /// Apparent Wind Direction + ATT_CHAR_APRNT_WIND_DIRECTION = ATT_UUID_16(0x2A73), + /// Gust Factor + ATT_CHAR_GUST_FACTOR = ATT_UUID_16(0x2A74), + /// Pollen Concentration + ATT_CHAR_POLLEN_CONC = ATT_UUID_16(0x2A75), + /// UV Index + ATT_CHAR_UV_INDEX = ATT_UUID_16(0x2A76), + /// Irradiance + ATT_CHAR_IRRADIANCE = ATT_UUID_16(0x2A77), + /// Rainfall + ATT_CHAR_RAINFALL = ATT_UUID_16(0x2A78), + /// Wind Chill + ATT_CHAR_WIND_CHILL = ATT_UUID_16(0x2A79), + /// Heat Index + ATT_CHAR_HEAT_INDEX = ATT_UUID_16(0x2A7A), + /// Dew Point + ATT_CHAR_DEW_POINT = ATT_UUID_16(0x2A7B), + /// Descriptor Value Changed + ATT_CHAR_DESCRIPTOR_VALUE_CHANGED = ATT_UUID_16(0x2A7D), + /// Aerobic Heart Rate Lower Limit + ATT_CHAR_AEROBIC_HEART_RATE_LOWER_LIMIT = ATT_UUID_16(0x2A7E), + /// Aerobic Threshhold + ATT_CHAR_AEROBIC_THRESHHOLD = ATT_UUID_16(0x2A7F), + /// Age + ATT_CHAR_AGE = ATT_UUID_16(0x2A80), + /// Anaerobic Heart Rate Lower Limit + ATT_CHAR_ANAEROBIC_HEART_RATE_LOWER_LIMIT = ATT_UUID_16(0x2A81), + /// Anaerobic Heart Rate Upper Limit + ATT_CHAR_ANAEROBIC_HEART_RATE_UPPER_LIMIT = ATT_UUID_16(0x2A82), + /// Anaerobic Threshhold + ATT_CHAR_ANAEROBIC_THRESHHOLD = ATT_UUID_16(0x2A83), + /// Aerobic Heart Rate Upper Limit + ATT_CHAR_AEROBIC_HEART_RATE_UPPER_LIMIT = ATT_UUID_16(0x2A84), + /// Date Of Birth + ATT_CHAR_DATE_OF_BIRTH = ATT_UUID_16(0x2A85), + /// Date Of Threshold Assessment + ATT_CHAR_DATE_OF_THRESHOLD_ASSESSMENT = ATT_UUID_16(0x2A86), + /// Email Address + ATT_CHAR_EMAIL_ADDRESS = ATT_UUID_16(0x2A87), + /// Fat Burn Heart Rate Lower Limit + ATT_CHAR_FAT_BURN_HEART_RATE_LOWER_LIMIT = ATT_UUID_16(0x2A88), + /// Fat Burn Heart Rate Upper Limit + ATT_CHAR_FAT_BURN_HEART_RATE_UPPER_LIMIT = ATT_UUID_16(0x2A89), + /// First Name + ATT_CHAR_FIRST_NAME = ATT_UUID_16(0x2A8A), + /// Five Zone Heart Rate Limits + ATT_CHAR_FIVE_ZONE_HEART_RATE_LIMITS = ATT_UUID_16(0x2A8B), + /// Gender + ATT_CHAR_GENDER = ATT_UUID_16(0x2A8C), + /// Max Heart Rate + ATT_CHAR_MAX_HEART_RATE = ATT_UUID_16(0x2A8D), + /// Height + ATT_CHAR_HEIGHT = ATT_UUID_16(0x2A8E), + /// Hip Circumference + ATT_CHAR_HIP_CIRCUMFERENCE = ATT_UUID_16(0x2A8F), + /// Last Name + ATT_CHAR_LAST_NAME = ATT_UUID_16(0x2A90), + /// Maximum Recommended Heart Rate + ATT_CHAR_MAXIMUM_RECOMMENDED_HEART_RATE = ATT_UUID_16(0x2A91), + /// Resting Heart Rate + ATT_CHAR_RESTING_HEART_RATE = ATT_UUID_16(0x2A92), + /// Sport Type For Aerobic And Anaerobic Thresholds + ATT_CHAR_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS = ATT_UUID_16(0x2A93), + /// Three Zone Heart Rate Limits + ATT_CHAR_THREE_ZONE_HEART_RATE_LIMITS = ATT_UUID_16(0x2A94), + /// Two Zone Heart Rate Limit + ATT_CHAR_TWO_ZONE_HEART_RATE_LIMIT = ATT_UUID_16(0x2A95), + /// Vo2 Max + ATT_CHAR_VO2_MAX = ATT_UUID_16(0x2A96), + /// Waist Circumference + ATT_CHAR_WAIST_CIRCUMFERENCE = ATT_UUID_16(0x2A97), + /// Weight + ATT_CHAR_WEIGHT = ATT_UUID_16(0x2A98), + /// Database Change Increment + ATT_CHAR_DATABASE_CHANGE_INCREMENT = ATT_UUID_16(0x2A99), + /// User Index + ATT_CHAR_USER_INDEX = ATT_UUID_16(0x2A9A), + /// Body Composition Feature + ATT_CHAR_BODY_COMPOSITION_FEATURE = ATT_UUID_16(0x2A9B), + /// Body Composition Measurement + ATT_CHAR_BODY_COMPOSITION_MEASUREMENT = ATT_UUID_16(0x2A9C), + /// Weight Measurement + ATT_CHAR_WEIGHT_MEASUREMENT = ATT_UUID_16(0x2A9D), + /// Weight Scale Feature + ATT_CHAR_WEIGHT_SCALE_FEATURE = ATT_UUID_16(0x2A9E), + /// User Control Point + ATT_CHAR_USER_CONTROL_POINT = ATT_UUID_16(0x2A9F), + /// Flux Density - 2D + ATT_CHAR_MAGN_FLUX_2D = ATT_UUID_16(0x2AA0), + /// Magnetic Flux Density - 3D + ATT_CHAR_MAGN_FLUX_3D = ATT_UUID_16(0x2AA1), + /// Language string + ATT_CHAR_LANGUAGE = ATT_UUID_16(0x2AA2), + /// Barometric Pressure Trend + ATT_CHAR_BAR_PRES_TREND = ATT_UUID_16(0x2AA3), + /// Central Address Resolution Support + ATT_CHAR_CTL_ADDR_RESOL_SUPP = ATT_UUID_16(0x2AA6), + /// CGM Measurement + ATT_CHAR_CGM_MEASUREMENT = ATT_UUID_16(0x2AA7), + /// CGM Features + ATT_CHAR_CGM_FEATURES = ATT_UUID_16(0x2AA8), + /// CGM Status + ATT_CHAR_CGM_STATUS = ATT_UUID_16(0x2AA9), + /// CGM Session Start + ATT_CHAR_CGM_SESSION_START = ATT_UUID_16(0x2AAA), + /// CGM Session Run + ATT_CHAR_CGM_SESSION_RUN = ATT_UUID_16(0x2AAB), + /// CGM Specific Ops Control Point + ATT_CHAR_CGM_SPECIFIC_OPS_CTRL_PT = ATT_UUID_16(0x2AAC), + /// Resolvable Private Address only + ATT_CHAR_RSLV_PRIV_ADDR_ONLY = ATT_UUID_16(0x2AC9), + /// Mesh Provisioning Data In + ATT_CHAR_MESH_PROV_DATA_IN = ATT_UUID_16(0x2ADB), + /// Mesh Provisioning Data Out + ATT_CHAR_MESH_PROV_DATA_OUT = ATT_UUID_16(0x2ADC), + /// Mesh Proxy Data In + ATT_CHAR_MESH_PROXY_DATA_IN = ATT_UUID_16(0x2ADD), + /// Mesh Proxy Data Out + ATT_CHAR_MESH_PROXY_DATA_OUT = ATT_UUID_16(0x2ADE), + + /// Client Supported Features + ATT_CHAR_CLI_SUP_FEAT = ATT_UUID_16(0x2B29), + /// Database Hash + ATT_CHAR_DB_HASH = ATT_UUID_16(0x2B2A), +}; + +/// Format for Characteristic Presentation +enum { + /// unsigned 1-bit: true or false + ATT_FORMAT_BOOL = 0x01, + /// unsigned 2-bit integer + ATT_FORMAT_2BIT, + /// unsigned 4-bit integer + ATT_FORMAT_NIBBLE, + /// unsigned 8-bit integer + ATT_FORMAT_UINT8, + /// unsigned 12-bit integer + ATT_FORMAT_UINT12, + /// unsigned 16-bit integer + ATT_FORMAT_UINT16, + /// unsigned 24-bit integer + ATT_FORMAT_UINT24, + /// unsigned 32-bit integer + ATT_FORMAT_UINT32, + /// unsigned 48-bit integer + ATT_FORMAT_UINT48, + /// unsigned 64-bit integer + ATT_FORMAT_UINT64, + /// unsigned 128-bit integer + ATT_FORMAT_UINT128, + /// signed 8-bit integer + ATT_FORMAT_SINT8, + /// signed 12-bit integer + ATT_FORMAT_SINT12, + /// signed 16-bit integer + ATT_FORMAT_SINT16, + /// signed 24-bit integer + ATT_FORMAT_SINT24, + /// signed 32-bit integer + ATT_FORMAT_SINT32, + /// signed 48-bit integer + ATT_FORMAT_SINT48, + /// signed 64-bit integer + ATT_FORMAT_SINT64, + /// signed 128-bit integer + ATT_FORMAT_SINT128, + /// IEEE-754 32-bit floating point + ATT_FORMAT_FLOAT32, + /// IEEE-754 64-bit floating point + ATT_FORMAT_FLOAT64, + /// IEEE-11073 16-bit SFLOAT + ATT_FORMAT_SFLOAT, + /// IEEE-11073 32-bit FLOAT + ATT_FORMAT_FLOAT, + /// IEEE-20601 format + ATT_FORMAT_DUINT16, + /// UTF-8 string + ATT_FORMAT_UTF8S, + /// UTF-16 string + ATT_FORMAT_UTF16S, + /// Opaque structure + ATT_FORMAT_STRUCT, + /// Last format + ATT_FORMAT_LAST +}; + + +/// Client Characteristic Configuration Codes +enum att_ccc_val +{ + /// Stop notification/indication + ATT_CCC_STOP_NTFIND = 0x0000, + /// Start notification + ATT_CCC_START_NTF, + /// Start indication + ATT_CCC_START_IND +}; + +/* + * Type Definition + **************************************************************************************** + */ + +/// Attribute length type +typedef uint16_t att_size_t; + + +/// UUID - 128-bit type +struct att_uuid_128 +{ + /// 128-bit UUID + uint8_t uuid[ATT_UUID_128_LEN]; +}; + +/// UUID - 32-bit type +struct att_uuid_32 +{ + /// 32-bit UUID + uint8_t uuid[ATT_UUID_32_LEN]; +}; + + + +/// Characteristic Value Descriptor +struct att_char_desc +{ + /// properties + uint8_t prop; + /// attribute handle + uint8_t attr_hdl[ATT_HANDLE_LEN]; + /// attribute type + uint8_t attr_type[ATT_UUID_16_LEN]; +}; + +/// Characteristic Value Descriptor +struct att_char128_desc +{ + /// properties + uint8_t prop; + /// attribute handle + uint8_t attr_hdl[ATT_HANDLE_LEN]; + /// attribute type + uint8_t attr_type[ATT_UUID_128_LEN]; +}; + +/// Service Value Descriptor - 16-bit +typedef uint16_t att_svc_desc_t; + +/// include service entry element +struct att_incl_desc +{ + /// start handle value of included service + uint16_t start_hdl; + /// end handle value of included service + uint16_t end_hdl; + /// attribute value UUID + uint16_t uuid; +}; + +/// include service entry element +struct att_incl128_desc +{ + /// start handle value of included service + uint16_t start_hdl; + /// end handle value of included service + uint16_t end_hdl; +}; + + +// -------------------------- PDU HANDLER Definition -------------------------- + +/// used to know if PDU handler has been found +#define ATT_PDU_HANDLER_NOT_FOUND (0xff) + +/// Format of a pdu handler function +typedef int (*att_func_t)(uint8_t conidx, void *pdu); + +/// Element of a pdu handler table. +struct att_pdu_handler +{ + /// PDU identifier of the message + uint8_t pdu_id; + /// Pointer to the handler function for the pdu above. + att_func_t handler; +}; + + +// --------------------------- Database permissions ----------------------------- + +/// Macro used to retrieve access permission rights +#define PERM_GET(perm, access)\ + (((perm) & (PERM_MASK_ ## access)) >> (PERM_POS_ ## access)) + +/// Macro used to set a permission value +#define PERM_SET(perm, access, value)\ + perm = ((perm & ~(PERM_MASK_ ## access)) | ((value << (PERM_POS_ ## access)) & (PERM_MASK_ ## access))) + +/// Macro used to retrieve permission value from access and rights on attribute. +#define PERM(access, right) \ + (((PERM_RIGHT_ ## right) << (PERM_POS_ ## access)) & (PERM_MASK_ ## access)) + +/// Macro used to create permission value +#define PERM_VAL(access, perm) \ + ((((perm) << (PERM_POS_ ## access))) & (PERM_MASK_ ## access)) + +/// Macro used know if permission is set or not. +#define PERM_IS_SET(perm, access, right) \ + (((perm) & (((PERM_RIGHT_ ## right) << (PERM_POS_ ## access))) \ + & (PERM_MASK_ ## access)) == PERM(access, right)) + +/// Retrieve attribute security level from attribute right and service right +#define ATT_GET_SEC_LVL(att_right, svc_right) \ + co_max(((att_right) & PERM_RIGHT_AUTH), ((svc_right) & PERM_RIGHT_AUTH)); + +/// Retrieve UUID LEN from UUID Length Permission +#define ATT_UUID_LEN(uuid_len_perm) ((uuid_len_perm == 0) ? ATT_UUID_16_LEN : \ + ((uuid_len_perm == 1) ? ATT_UUID_32_LEN : \ + ((uuid_len_perm == 2) ? ATT_UUID_128_LEN : 0))) + +/// Initialization of attribute element +#define ATT_ELEMT_INIT {{NULL}, false} + +/** + * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ + * |EXT | WS | I | N | WR | WC | RD | B | NP | IP | WP | RP | + * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ + * + * Bit [0-1] : Read Permission (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON) + * Bit [2-3] : Write Permission (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON) + * Bit [4-5] : Indication Permission (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON) + * Bit [6-7] : Notification Permission (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON) + * + * Bit [8] : Extended properties present (only relevant for a characteristic value) + * Bit [9] : Broadcast permission (only relevant for a characteristic value) + * Bit [10] : Write Command accepted + * Bit [11] : Write Signed accepted + * Bit [12] : Write Request accepted + * Bit [13] : Encryption key Size must be 16 bytes + */ +enum attm_perm_mask +{ + /// retrieve all permission info + PERM_MASK_ALL = 0x0000, + /// Read Permission Mask + PERM_MASK_RP = 0x0003, + PERM_POS_RP = 0, + /// Write Permission Mask + PERM_MASK_WP = 0x000C, + PERM_POS_WP = 2, + /// Indication Access Mask + PERM_MASK_IP = 0x0030, + PERM_POS_IP = 4, + /// Notification Access Mask + PERM_MASK_NP = 0x00C0, + PERM_POS_NP = 6, + /// Broadcast descriptor present + PERM_MASK_BROADCAST = 0x0100, + PERM_POS_BROADCAST = 8, + /// Read Access Mask + PERM_MASK_RD = 0x0200, + PERM_POS_RD = 9, + /// Write Command Enabled attribute Mask + PERM_MASK_WRITE_COMMAND = 0x0400, + PERM_POS_WRITE_COMMAND = 10, + /// Write Request Enabled attribute Mask + PERM_MASK_WRITE_REQ = 0x0800, + PERM_POS_WRITE_REQ = 11, + /// Notification Access Mask + PERM_MASK_NTF = 0x1000, + PERM_POS_NTF = 12, + /// Indication Access Mask + PERM_MASK_IND = 0x2000, + PERM_POS_IND = 13, + /// Write Signed Enabled attribute Mask + PERM_MASK_WRITE_SIGNED = 0x4000, + PERM_POS_WRITE_SIGNED = 14, + /// Extended properties descriptor present + PERM_MASK_EXT = 0x8000, + PERM_POS_EXT = 15, + + /// Properties + PERM_MASK_PROP = 0xFF00, + PERM_POS_PROP = 8, +}; + +/** + * Value permission bit field + * + * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ + * | RI |UUID_LEN |EKS | MAX_LEN (RI = 1) / Value Offset (RI = 0) | + * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ + * + * Bit [0-11] : Maximum Attribute Length or Value Offset pointer + * Bit [12] : Encryption key Size must be 16 bytes + * Bit [14-13]: UUID Length (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU) + * Bit [15] : Trigger Read Indication (0 = Value present in Database, 1 = Value not present in Database) + */ +enum attm_value_perm_mask +{ + /// Maximum Attribute Length + PERM_MASK_MAX_LEN = 0x0FFF, + PERM_POS_MAX_LEN = 0, + /// Attribute value Offset + PERM_MASK_VAL_OFFSET = 0x0FFF, + PERM_POS_VAL_OFFSET = 0, + /// Check Encryption key size Mask + PERM_MASK_EKS = 0x1000, + PERM_POS_EKS = 12, + /// UUID Length + PERM_MASK_UUID_LEN = 0x6000, + PERM_POS_UUID_LEN = 13, + /// Read trigger Indication + PERM_MASK_RI = 0x8000, + PERM_POS_RI = 15, +}; + + +/** + * Service permissions + * + * 7 6 5 4 3 2 1 0 + * +----+----+----+----+----+----+----+----+ + * |SEC |UUID_LEN |DIS | AUTH |EKS | MI | + * +----+----+----+----+----+----+----+----+ + * + * Bit [0] : Task that manage service is multi-instantiated (Connection index is conveyed) + * Bit [1] : Encryption key Size must be 16 bytes + * Bit [2-3]: Service Permission (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = Secure Connect) + * Bit [4] : Disable the service + * Bit [5-6]: UUID Length (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU) + * Bit [7] : Secondary Service (0 = Primary Service, 1 = Secondary Service) + */ +enum attm_svc_perm_mask +{ + /// Task that manage service is multi-instantiated + PERM_MASK_SVC_MI = 0x01, + PERM_POS_SVC_MI = 0, + /// Check Encryption key size for service Access + PERM_MASK_SVC_EKS = 0x02, + PERM_POS_SVC_EKS = 1, + /// Service Permission authentication + PERM_MASK_SVC_AUTH = 0x0C, + PERM_POS_SVC_AUTH = 2, + /// Disable the service + PERM_MASK_SVC_DIS = 0x10, + PERM_POS_SVC_DIS = 4, + /// Service UUID Length + PERM_MASK_SVC_UUID_LEN = 0x60, + PERM_POS_SVC_UUID_LEN = 5, + /// Service type Secondary + PERM_MASK_SVC_SECONDARY = 0x80, + PERM_POS_SVC_SECONDARY = 7, +}; + + +/// Attribute & Service access mode +enum +{ + /// Disable access + PERM_RIGHT_DISABLE = 0, + /// Enable access + PERM_RIGHT_ENABLE = 1, +}; + +/// Attribute & Service access rights +enum +{ + /// No Authentication + PERM_RIGHT_NO_AUTH = 0, + /// Access Requires Unauthenticated link + PERM_RIGHT_UNAUTH = 1, + /// Access Requires Authenticated link + PERM_RIGHT_AUTH = 2, + /// Access Requires Secure Connection link + PERM_RIGHT_SEC_CON = 3, +}; + +/// Attribute & Service UUID Length +enum +{ + /// 16 bits UUID + PERM_UUID_16 = 0, + PERM_RIGHT_UUID_16 = 0, + /// 32 bits UUID + PERM_UUID_32 = 1, + PERM_RIGHT_UUID_32 = 1, + /// 128 bits UUID + PERM_UUID_128 = 2, + PERM_RIGHT_UUID_128 = 2, + /// Invalid + PERM_UUID_RFU = 3, +}; + +/// execute flags +enum +{ + /// Cancel All the Reliable Writes + ATT_CANCEL_ALL_PREPARED_WRITES = 0x00, + /// Write All the Reliable Writes + ATT_EXECUTE_ALL_PREPARED_WRITES +}; + + + +/// @} ATT +#endif // ATT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gap.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gap.h new file mode 100644 index 0000000..fb46b58 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gap.h @@ -0,0 +1,689 @@ +/** + **************************************************************************************** + * + * @file gap.h + * + * @brief Header file - GAP. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ +#ifndef GAP_H_ +#define GAP_H_ +/** + **************************************************************************************** + * @addtogroup HOST + * @ingroup ROOT + * @brief Bluetooth Low Energy Host + * + * The HOST layer of the stack contains the higher layer protocols (@ref ATT "ATT", + * @ref SMP "SMP") and transport module (@ref L2C "L2C"). It also includes the Generic + * Access Profile (@ref GAP "GAP"), used for scanning/connection operations. + **************************************************************************************** + */ +/** + **************************************************************************************** + * @addtogroup GAP Generic Access Profile + * @ingroup HOST + * @brief Generic Access Profile. + * + * The GAP module is responsible for providing an API to the application in order to + * configure the device in the desired mode (discoverable, connectable, etc.) and perform + * required actions (scanning, connection, pairing, etc.). To achieve this, the GAP + * interfaces with both the @ref SMP "SMP", @ref L2C "L2C" and the @ref CONTROLLER "CONTROLLER" + * + * @{ + **************************************************************************************** + */ + +#include +#include "compiler.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// BD address length +#define GAP_BD_ADDR_LEN (6) +/// LE Channel map length +#define GAP_LE_CHNL_MAP_LEN (0x05) +/// LE Feature Flags Length +#define GAP_LE_FEATS_LEN (0x08) +/// ADV Data and Scan Response length +#define GAP_ADV_DATA_LEN (0x1F) +#define GAP_SCAN_RSP_DATA_LEN (0x1F) +/// Random number length +#define GAP_RAND_NB_LEN (0x08) +/// Key length +#define GAP_KEY_LEN (16) +/// P256 Key Len +#define GAP_P256_KEY_LEN (0x20) + + +///***** AD Type Flag - Bit set *******/ +/// Limited discovery flag - AD Flag +#define GAP_LE_LIM_DISCOVERABLE_FLG 0x01 +/// General discovery flag - AD Flag +#define GAP_LE_GEN_DISCOVERABLE_FLG 0x02 +/// Legacy BT not supported - AD Flag +#define GAP_BR_EDR_NOT_SUPPORTED 0x04 +/// Dual mode for controller supported (BR/EDR/LE) - AD Flag +#define GAP_SIMUL_BR_EDR_LE_CONTROLLER 0x08 +/// Dual mode for host supported (BR/EDR/LE) - AD Flag +#define GAP_SIMUL_BR_EDR_LE_HOST 0x10 + +/*********** GAP Miscellaneous Defines *************/ +/// Invalid activity index +#define GAP_INVALID_ACTV_IDX 0xFF +/// Invalid connection index +#define GAP_INVALID_CONIDX 0xFF + +/// Invalid connection handle +#define GAP_INVALID_CONHDL 0xFFFF + +/// Connection interval min (N*1.250ms) +#define GAP_CNX_INTERVAL_MIN 6 //(0x06) +/// Connection interval Max (N*1.250ms) +#define GAP_CNX_INTERVAL_MAX 3200 //(0xC80) +/// Connection latency min (N*cnx evt) +#define GAP_CNX_LATENCY_MIN 0 //(0x00) +/// Connection latency Max (N*cnx evt +#define GAP_CNX_LATENCY_MAX 499 //(0x1F3) +/// Supervision TO min (N*10ms) +#define GAP_CNX_SUP_TO_MIN 10 //(0x0A) +/// Supervision TO Max (N*10ms) +#define GAP_CNX_SUP_TO_MAX 3200 //(0xC80) + + + +/// Length of resolvable random address prand part +#define GAP_ADDR_PRAND_LEN (3) +/// Length of resolvable random address hash part +#define GAP_ADDR_HASH_LEN (3) + +/// Number of bytes needed for a bit field indicated presence of a given Advertising Flag value +/// in the Advertising or the Scan Response data +/// Advertising Flags is a 8-bit value, hence 256 value are possible +/// -> 256 / 8 bytes = 32 bytes are needed +#define GAP_AD_TYPE_BITFIELD_BYTES (32) + +/* + * DEFINES - Optional for BLE application usage + **************************************************************************************** + */ + +/// Central idle timer +/// TGAP(conn_pause_central) +/// recommended value: 1 s: (100 for ke timer) +#define GAP_TMR_CONN_PAUSE_CT 0x0064 + +/// Minimum time upon connection establishment before the peripheral +/// starts a connection update procedure: TGAP(conn_pause_peripheral) +/// recommended value: 5 s: (500 for ke timer) +#define GAP_TMR_CONN_PAUSE_PH 0x01F4 + +/// Minimum time to perform scanning when user initiated +/// TGAP(scan_fast_period) +/// recommended value: 30.72 s: (3072 for ke timer) +#define GAP_TMR_SCAN_FAST_PERIOD 0x0C00 + +/// Minimum time to perform advertising when user initiated +/// TGAP(adv_fast_period) +/// recommended value: 30 s: (3000 for ke timer) +#define GAP_TMR_ADV_FAST_PERIOD 0x0BB8 + +/// Scan interval used during Link Layer Scanning State when +/// performing the Limited Discovery procedure +/// TGAP(lim_disc_scan_int) +/// recommended value: 11.25ms; (18 decimal) +#define GAP_LIM_DISC_SCAN_INT 0x0012 + +/// Scan interval in any discovery or connection establishment +/// procedure when user initiated: TGAP(scan_fast_interval) +/// recommended value: 30 to 60 ms; N * 0.625 +#define GAP_SCAN_FAST_INTV 0x0030 + +/// Scan window in any discovery or connection establishment +/// procedure when user initiated: TGAP(scan_fast_window) +/// recommended value: 30 ms; N * 0.625 +#define GAP_SCAN_FAST_WIND 0x0030 + +/// Scan interval in any discovery or connection establishment +/// procedure when background scanning: TGAP(scan_slow_interval1) +/// recommended value: 1.28 s : 0x00CD (205); N * 0.625 +#define GAP_SCAN_SLOW_INTV1 0x00CD + +/// Scan interval in any discovery or connection establishment +/// procedure when background scanning: TGAP(scan_slow_interval2) +/// recommended value: 2.56 s : 0x019A (410); N * 0.625 +#define GAP_SCAN_SLOW_INTV2 0x019A + +/// Scan window in any discovery or connection establishment +/// procedure when background scanning: TGAP(scan_slow_window1) +/// recommended value: 11.25 ms : 0x0012 (18); N * 0.625 +#define GAP_SCAN_SLOW_WIND1 0x0012 + +/// Scan window in any discovery or connection establishment +/// procedure when background scanning: TGAP(scan_slow_window2) +/// recommended value: 22.5 ms : 0x0024 (36); N * 0.625 +#define GAP_SCAN_SLOW_WIND2 0x0024 + +/// Minimum to maximum advertisement interval in any discoverable +/// or connectable mode when user initiated: TGAP(adv_fast_interval1) +/// recommended value: 30 to 60 ms; N * 0.625 +#define GAP_ADV_FAST_INTV1 0x0030 + +/// Minimum to maximum advertisement interval in any discoverable +/// or connectable mode when user initiated: TGAP(adv_fast_interval2) +/// recommended value: 100 to 150 ms; N * 0.625 +#define GAP_ADV_FAST_INTV2 0x0064 + +/// Minimum to maximum advertisement interval in any discoverable or +/// connectable mode when background advertising: TGAP(adv_slow_interval) +/// recommended value: 1 to 1.2 s : 0x00B0 (176); N * 0.625 +#define GAP_ADV_SLOW_INTV 0x00B0 + +/// Minimum to maximum connection interval upon any connection +/// establishment: TGAP(initial_conn_interval) +/// recommended value: 30 to 50 ms ; N * 1.25 ms +#define GAP_INIT_CONN_MIN_INTV 0x0018 +#define GAP_INIT_CONN_MAX_INTV 0x0028 + +/// RW Defines +#define GAP_INQ_SCAN_INTV 0x0012 +#define GAP_INQ_SCAN_WIND 0x0012 + +/// Connection supervision timeout +/// recommended value: 20s +#define GAP_CONN_SUPERV_TIMEOUT 0x07D0 + +/// Minimum connection event +/// default value: 0x0000 +#define GAP_CONN_MIN_CE 0x0000 + +/// Maximum connection event +/// default value: 0xFFFF +#define GAP_CONN_MAX_CE 0xFFFF + +/// Connection latency +/// default value: 0x0000 +#define GAP_CONN_LATENCY 0x0000 + +/// GAP Device name Characteristic +/// Default device name +#define GAP_DEV_NAME "RIVIERAWAVES-BLE" + +/// GAP Appearance or Icon Characteristic - 2 octets +/// Current appearance value is 0x0000 (unknown appearance) +/// Description: +/// http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml +#define GAP_APPEARANCE 0x0000 + +///GAP Peripheral Preferred Connection Parameter - 8 octets +#define GAP_PPCP_CONN_INTV_MAX 0x0064 +#define GAP_PPCP_CONN_INTV_MIN 0x00C8 +#define GAP_PPCP_SLAVE_LATENCY 0x0000 +#define GAP_PPCP_STO_MULT 0x07D0 + +/* + * Macros + **************************************************************************************** + */ + +#define GAP_AD_TYPE_SET_BIT(bitfield, adv_flag) \ + bitfield[adv_flag / 8] |= CO_BIT(adv_flag % 8) + +#define GAP_AD_TYPE_CHECK_BIT(bitfield, adv_flag) \ + (bitfield[adv_flag / 8] & CO_BIT(adv_flag % 8)) + +/* + * Enumerations + **************************************************************************************** + */ +/// GAP Advertising Flags +enum gap_ad_type +{ + /// Flag + GAP_AD_TYPE_FLAGS = 0x01,//!< GAP_AD_TYPE_FLAGS + /// Use of more than 16 bits UUID + GAP_AD_TYPE_MORE_16_BIT_UUID = 0x02,//!< GAP_AD_TYPE_MORE_16_BIT_UUID + /// Complete list of 16 bit UUID + GAP_AD_TYPE_COMPLETE_LIST_16_BIT_UUID = 0x03,//!< GAP_AD_TYPE_COMPLETE_LIST_16_BIT_UUID + /// Use of more than 32 bit UUD + GAP_AD_TYPE_MORE_32_BIT_UUID = 0x04,//!< GAP_AD_TYPE_MORE_32_BIT_UUID + /// Complete list of 32 bit UUID + GAP_AD_TYPE_COMPLETE_LIST_32_BIT_UUID = 0x05,//!< GAP_AD_TYPE_COMPLETE_LIST_32_BIT_UUID + /// Use of more than 128 bit UUID + GAP_AD_TYPE_MORE_128_BIT_UUID = 0x06,//!< GAP_AD_TYPE_MORE_128_BIT_UUID + /// Complete list of 128 bit UUID + GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID = 0x07,//!< GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID + /// Shortened device name + GAP_AD_TYPE_SHORTENED_NAME = 0x08,//!< GAP_AD_TYPE_SHORTENED_NAME + /// Complete device name + GAP_AD_TYPE_COMPLETE_NAME = 0x09,//!< GAP_AD_TYPE_COMPLETE_NAME + /// Transmit power + GAP_AD_TYPE_TRANSMIT_POWER = 0x0A,//!< GAP_AD_TYPE_TRANSMIT_POWER + /// Class of device + GAP_AD_TYPE_CLASS_OF_DEVICE = 0x0D,//!< GAP_AD_TYPE_CLASS_OF_DEVICE + /// Simple Pairing Hash C + GAP_AD_TYPE_SP_HASH_C = 0x0E,//!< GAP_AD_TYPE_SP_HASH_C + /// Simple Pairing Randomizer + GAP_AD_TYPE_SP_RANDOMIZER_R = 0x0F,//!< GAP_AD_TYPE_SP_RANDOMIZER_R + /// Temporary key value + GAP_AD_TYPE_TK_VALUE = 0x10,//!< GAP_AD_TYPE_TK_VALUE + /// Out of Band Flag + GAP_AD_TYPE_OOB_FLAGS = 0x11,//!< GAP_AD_TYPE_OOB_FLAGS + /// Slave connection interval range + GAP_AD_TYPE_SLAVE_CONN_INT_RANGE = 0x12,//!< GAP_AD_TYPE_SLAVE_CONN_INT_RANGE + /// Require 16 bit service UUID + GAP_AD_TYPE_RQRD_16_BIT_SVC_UUID = 0x14,//!< GAP_AD_TYPE_RQRD_16_BIT_SVC_UUID + /// Require 32 bit service UUID + GAP_AD_TYPE_RQRD_32_BIT_SVC_UUID = 0x1F,//!< GAP_AD_TYPE_RQRD_32_BIT_SVC_UUID + /// Require 128 bit service UUID + GAP_AD_TYPE_RQRD_128_BIT_SVC_UUID = 0x15,//!< GAP_AD_TYPE_RQRD_128_BIT_SVC_UUID + /// Service data 16-bit UUID + GAP_AD_TYPE_SERVICE_16_BIT_DATA = 0x16,//!< GAP_AD_TYPE_SERVICE_16_BIT_DATA + /// Service data 32-bit UUID + GAP_AD_TYPE_SERVICE_32_BIT_DATA = 0x20,//!< GAP_AD_TYPE_SERVICE_32_BIT_DATA + /// Service data 128-bit UUID + GAP_AD_TYPE_SERVICE_128_BIT_DATA = 0x21,//!< GAP_AD_TYPE_SERVICE_128_BIT_DATA + /// Public Target Address + GAP_AD_TYPE_PUB_TGT_ADDR = 0x17,//!< GAP_AD_TYPE_PUB_TGT_ADDR + /// Random Target Address + GAP_AD_TYPE_RAND_TGT_ADDR = 0x18,//!< GAP_AD_TYPE_RAND_TGT_ADDR + /// Appearance + GAP_AD_TYPE_APPEARANCE = 0x19,//!< GAP_AD_TYPE_APPEARANCE + /// Advertising Interval + GAP_AD_TYPE_ADV_INTV = 0x1A,//!< GAP_AD_TYPE_ADV_INTV + /// LE Bluetooth Device Address + GAP_AD_TYPE_LE_BT_ADDR = 0x1B,//!< GAP_AD_TYPE_LE_BT_ADDR + /// LE Role + GAP_AD_TYPE_LE_ROLE = 0x1C,//!< GAP_AD_TYPE_LE_ROLE + /// Simple Pairing Hash C-256 + GAP_AD_TYPE_SPAIR_HASH = 0x1D,//!< GAP_AD_TYPE_SPAIR_HASH + /// Simple Pairing Randomizer R-256 + GAP_AD_TYPE_SPAIR_RAND = 0x1E,//!< GAP_AD_TYPE_SPAIR_RAND + /// 3D Information Data + GAP_AD_TYPE_3D_INFO = 0x3D,//!< GAP_AD_TYPE_3D_INFO + + /// Manufacturer specific data + GAP_AD_TYPE_MANU_SPECIFIC_DATA = 0xFF,//!< GAP_AD_TYPE_MANU_SPECIFIC_DATA +}; + +/// Boolean value set +enum +{ + /// Disable + GAP_DISABLE = 0x00, + /// Enable + GAP_ENABLE +}; + + +/// GAP Attribute database handles +/// Generic Access Profile Service +enum +{ + GAP_IDX_PRIM_SVC, + GAP_IDX_CHAR_DEVNAME, + GAP_IDX_DEVNAME, + GAP_IDX_CHAR_ICON, + GAP_IDX_ICON, + GAP_IDX_CHAR_SLAVE_PREF_PARAM, + GAP_IDX_SLAVE_PREF_PARAM, + GAP_IDX_CHAR_CNT_ADDR_RESOL, + GAP_IDX_CNT_ADDR_RESOL, + GAP_IDX_CHAR_RSLV_PRIV_ADDR_ONLY, + GAP_IDX_RSLV_PRIV_ADDR_ONLY, + GAP_IDX_NUMBER +}; + + + +/****************** GAP Role **********************/ +enum gap_role +{ + /// No role set yet + GAP_ROLE_NONE = 0x00, + + /// Observer role + GAP_ROLE_OBSERVER = 0x01, + + /// Broadcaster role + GAP_ROLE_BROADCASTER = 0x02, + + /// Master/Central role + GAP_ROLE_CENTRAL = (0x04 | GAP_ROLE_OBSERVER), + + /// Peripheral/Slave role + GAP_ROLE_PERIPHERAL = (0x08 | GAP_ROLE_BROADCASTER), + + /// Device has all role, both peripheral and central + GAP_ROLE_ALL = (GAP_ROLE_CENTRAL | GAP_ROLE_PERIPHERAL), +}; + +/// IO Capability Values +enum gap_io_cap +{ + /// Display Only + GAP_IO_CAP_DISPLAY_ONLY = 0x00, + /// Display Yes No + GAP_IO_CAP_DISPLAY_YES_NO, + /// Keyboard Only + GAP_IO_CAP_KB_ONLY, + /// No Input No Output + GAP_IO_CAP_NO_INPUT_NO_OUTPUT, + /// Keyboard Display + GAP_IO_CAP_KB_DISPLAY, + GAP_IO_CAP_LAST +}; + +/// TK Type +enum gap_tk_type +{ + /// TK get from out of band method + GAP_TK_OOB = 0x00, + /// TK generated and shall be displayed by local device + GAP_TK_DISPLAY, + /// TK shall be entered by user using device keyboard + GAP_TK_KEY_ENTRY +}; + +/// OOB Data Present Flag Values +enum gap_oob +{ + /// OOB Data not present + GAP_OOB_AUTH_DATA_NOT_PRESENT = 0x00, + /// OOB data present + GAP_OOB_AUTH_DATA_PRESENT, + GAP_OOB_AUTH_DATA_LAST +}; + +/// Authentication mask +enum gap_auth_mask +{ + /// No Flag set + GAP_AUTH_NONE = 0, + /// Bond authentication + GAP_AUTH_BOND = (1 << 0), + /// Man In the middle protection + GAP_AUTH_MITM = (1 << 2), + /// Secure Connection + GAP_AUTH_SEC_CON = (1 << 3), + /// Key Notification + GAP_AUTH_KEY_NOTIF = (1 << 4) +}; + +/// Security Link Level +enum gap_lk_sec_lvl +{ + /// No authentication + GAP_LK_NO_AUTH = 0, + /// Unauthenticated link + GAP_LK_UNAUTH, + /// Authenticated link + GAP_LK_AUTH, + /// Secure Connection link + GAP_LK_SEC_CON, +}; + +/// Authentication Requirements +enum gap_auth +{ + /// No MITM No Bonding + GAP_AUTH_REQ_NO_MITM_NO_BOND = (GAP_AUTH_NONE), + /// No MITM Bonding + GAP_AUTH_REQ_NO_MITM_BOND = (GAP_AUTH_BOND), + /// MITM No Bonding + GAP_AUTH_REQ_MITM_NO_BOND = (GAP_AUTH_MITM), + /// MITM and Bonding + GAP_AUTH_REQ_MITM_BOND = (GAP_AUTH_MITM | GAP_AUTH_BOND), + /// SEC_CON and No Bonding + GAP_AUTH_REQ_SEC_CON_NO_BOND = (GAP_AUTH_SEC_CON | GAP_AUTH_MITM), + /// SEC_CON and Bonding + GAP_AUTH_REQ_SEC_CON_BOND = (GAP_AUTH_SEC_CON | GAP_AUTH_MITM | GAP_AUTH_BOND), + + GAP_AUTH_REQ_LAST, + + /// Mask of authentication features without reserved flag + GAP_AUTH_REQ_MASK = 0x1F, +}; + +/// Pairing level achieved +/// This enum is equivalent to gap_auth but has been added for more clarity +enum gap_pairing_lvl +{ + /// Unauthenticated pairing achieved but without bond data + /// (meaning-less for connection confirmation) + GAP_PAIRING_UNAUTH = 0x00, + /// Authenticated pairing achieved but without bond data + /// (meaning-less for connection confirmation) + GAP_PAIRING_AUTH = 0x04, + /// Secure connection pairing achieved but without bond data + /// (meaning-less for connection confirmation) + GAP_PAIRING_SECURE_CON = 0x0C, + + /// No pairing performed with peer device + /// (meaning-less for connection confirmation) + GAP_PAIRING_NO_BOND = 0x00, + /// Peer device bonded through an unauthenticated pairing. + GAP_PAIRING_BOND_UNAUTH = 0x01, + /// Peer device bonded through an authenticated pairing. + GAP_PAIRING_BOND_AUTH = 0x05, + /// Peer device bonded through a secure connection pairing pairing. + GAP_PAIRING_BOND_SECURE_CON = 0x0D, + + /// Pairing with bond data present Bit + GAP_PAIRING_BOND_PRESENT_BIT = 0x01, + GAP_PAIRING_BOND_PRESENT_POS = 0x00, +}; + +/// Key Distribution Flags +enum gap_kdist +{ + /// No Keys to distribute + GAP_KDIST_NONE = 0x00, + /// Encryption key in distribution + GAP_KDIST_ENCKEY = (1 << 0), + /// IRK (ID key)in distribution + GAP_KDIST_IDKEY = (1 << 1), + /// CSRK(Signature key) in distribution + GAP_KDIST_SIGNKEY= (1 << 2), + /// LTK in distribution + GAP_KDIST_LINKKEY= (1 << 3), + + GAP_KDIST_LAST = (1 << 4) +}; + +/// Security Defines +enum gap_sec_req +{ + /// No security (no authentication and encryption) + GAP_NO_SEC = 0x00, + /// Unauthenticated pairing with encryption + GAP_SEC1_NOAUTH_PAIR_ENC, + /// Authenticated pairing with encryption + GAP_SEC1_AUTH_PAIR_ENC, + /// Unauthenticated pairing with data signing + GAP_SEC2_NOAUTH_DATA_SGN, + /// Authentication pairing with data signing + GAP_SEC2_AUTH_DATA_SGN, + /// Secure Connection pairing with encryption + GAP_SEC1_SEC_CON_PAIR_ENC, +}; + +/// Bit field use to select the preferred TX or RX LE PHY. 0 means no preferences +enum gap_phy +{ + /// No preferred PHY + GAP_PHY_ANY = 0x00, + /// LE 1M PHY preferred for an active link + GAP_PHY_LE_1MBPS = (1 << 0), + /// LE 2M PHY preferred for an active link + GAP_PHY_LE_2MBPS = (1 << 1), + /// LE Coded PHY preferred for an active link + GAP_PHY_LE_CODED = (1 << 2), +}; + +/// Enumeration of TX/RX PHY values +enum gap_phy_val +{ + /// LE 1M PHY (TX or RX) + GAP_PHY_1MBPS = 1, + /// LE 2M PHY (TX or RX) + GAP_PHY_2MBPS = 2, + /// LE Coded PHY (RX Only) + GAP_PHY_CODED = 3, + /// LE Coded PHY with S=8 data coding (TX Only) + GAP_PHY_125KBPS = 3, + /// LE Coded PHY with S=2 data coding (TX Only) + GAP_PHY_500KBPS = 4, +}; + +/// Modulation index +enum gap_modulation_idx +{ + /// Assume transmitter will have a standard modulation index + GAP_MODULATION_STANDARD, + /// Assume transmitter will have a stable modulation index + GAP_MODULATION_STABLE, +}; + +/// Packet Payload type for test mode +enum gap_pkt_pld_type +{ + /// PRBS9 sequence "11111111100000111101..." (in transmission order) + GAP_PKT_PLD_PRBS9, + /// Repeated "11110000" (in transmission order) + GAP_PKT_PLD_REPEATED_11110000, + /// Repeated "10101010" (in transmission order) + GAP_PKT_PLD_REPEATED_10101010, + /// PRBS15 sequence + GAP_PKT_PLD_PRBS15, + /// Repeated "11111111" (in transmission order) sequence + GAP_PKT_PLD_REPEATED_11111111, + /// Repeated "00000000" (in transmission order) sequence + GAP_PKT_PLD_REPEATED_00000000, + /// Repeated "00001111" (in transmission order) sequence + GAP_PKT_PLD_REPEATED_00001111, + /// Repeated "01010101" (in transmission order) sequence + GAP_PKT_PLD_REPEATED_01010101, +}; + +/// Constant Tone Extension type +enum gap_cte_type +{ + /// Allow AoA Constant Tone Extension Response + GAP_CTE_AOA = (1 << 0), + /// Allow AoD Constant Tone Extension Response with 1 us slots + GAP_CTE_AOD_1US_SLOT = (1 << 1), + /// Allow AoD Constant Tone Extension Response with 2 us slots + GAP_CTE_AOD_2US_SLOT = (1 << 2), +}; + +/*************** GAP Structures ********************/ + +/// Device name +/*@TRACE*/ +struct gap_dev_name +{ + /// name length + uint16_t length; + /// name value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Slave preferred connection parameters +/*@TRACE*/ +struct gap_slv_pref +{ + /// Connection interval minimum + uint16_t con_intv_min; + /// Connection interval maximum + uint16_t con_intv_max; + /// Slave latency + uint16_t slave_latency; + /// Connection supervision timeout multiplier + uint16_t conn_timeout; +}; + +///BD Address structure +/*@TRACE*/ +typedef struct +{ + ///6-byte array address value + uint8_t addr[GAP_BD_ADDR_LEN]; +} bd_addr_t; + +///Channel map structure +/*@TRACE*/ +typedef struct +{ + ///5-byte channel map array + uint8_t map[GAP_LE_CHNL_MAP_LEN]; +} le_chnl_map_t; + + +///Random number structure +/*@TRACE*/ +typedef struct +{ + ///8-byte array for random number + uint8_t nb[GAP_RAND_NB_LEN]; +} rand_nb_t; + +/// P256 Public key data format +typedef struct +{ + /// X Coordinate of the key + uint8_t x[GAP_P256_KEY_LEN]; + /// X Coordinate of the key + uint8_t y[GAP_P256_KEY_LEN]; +} public_key_t; + +/// Address information about a device address +/*@TRACE*/ +struct gap_bdaddr +{ + /// BD Address of device + bd_addr_t addr; + /// Address type of the device 0=public/1=private random + uint8_t addr_type; +}; + +/// Resolving list device information +/*@TRACE*/ +struct gap_ral_dev_info +{ + /// Device identity + struct gap_bdaddr addr; + /// Privacy Mode + uint8_t priv_mode; + /// Peer IRK + uint8_t peer_irk[GAP_KEY_LEN]; + /// Local IRK + uint8_t local_irk[GAP_KEY_LEN]; +}; + +/// Generic Security key structure +/*@TRACE*/ +struct gap_sec_key +{ + /// Key value MSB -> LSB + uint8_t key[GAP_KEY_LEN]; +}; + +/// I/Q sample +/*@TRACE*/ +struct gap_iq_sample +{ + /// I sample + int8_t i; + /// Q sample + int8_t q; +}; +/// @} GAP +#endif // GAP_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gapc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gapc_task.h new file mode 100644 index 0000000..ea7bb6e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gapc_task.h @@ -0,0 +1,1306 @@ +/** + **************************************************************************************** + * + * @file gapc_task.h + * + * @brief Generic Access Profile Controller Task Header. + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ +#ifndef _GAPC_TASK_H_ +#define _GAPC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup GAPC_TASK Generic Access Profile Controller Task + * @ingroup GAPC + * @brief Handles ALL messages to/from GAP Controller block. + * + * It handles messages from lower and higher layers related to an ongoing connection. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_task.h" // Task definitions +#include "gap.h" +#include +#include "ke_msg.h" + +/* + * MACROS + **************************************************************************************** + */ + +/* + * DEFINES + **************************************************************************************** + */ + + +/// GAP Controller Task messages +/*@TRACE*/ +enum gapc_msg_id +{ + /* Default event */ + /// Command Complete event + GAPC_CMP_EVT = MSG_ID(GAPC, 0x00), + + /* Connection state information */ + /// Indicate that a connection has been established + GAPC_CONNECTION_REQ_IND = MSG_ID(GAPC, 0x01), + /// Set specific link data configuration. + GAPC_CONNECTION_CFM = MSG_ID(GAPC, 0x02), + + /// Indicate that a link has been disconnected + GAPC_DISCONNECT_IND = MSG_ID(GAPC, 0x03), + + /* Link management command */ + /// Request disconnection of current link command. + GAPC_DISCONNECT_CMD = MSG_ID(GAPC, 0x04), + + /* Peer device info */ + /// Retrieve information command + GAPC_GET_INFO_CMD = MSG_ID(GAPC, 0x05), + /// Peer device attribute DB info such as Device Name, Appearance or Slave Preferred Parameters + GAPC_PEER_ATT_INFO_IND = MSG_ID(GAPC, 0x06), + /// Indication of peer version info + GAPC_PEER_VERSION_IND = MSG_ID(GAPC, 0x07), + /// Indication of peer features info + GAPC_PEER_FEATURES_IND = MSG_ID(GAPC, 0x08), + /// Indication of ongoing connection RSSI + GAPC_CON_RSSI_IND = MSG_ID(GAPC, 0x09), + + /* Device Name Management */ + /// Peer device request local device info such as name, appearance or slave preferred parameters + GAPC_GET_DEV_INFO_REQ_IND = MSG_ID(GAPC, 0x0A), + /// Send requested info to peer device + GAPC_GET_DEV_INFO_CFM = MSG_ID(GAPC, 0x0B), + /// Peer device request to modify local device info such as name or appearance + GAPC_SET_DEV_INFO_REQ_IND = MSG_ID(GAPC, 0x0C), + /// Local device accept or reject device info modification + GAPC_SET_DEV_INFO_CFM = MSG_ID(GAPC, 0x0D), + + /* Connection parameters update */ + /// Perform update of connection parameters command + GAPC_PARAM_UPDATE_CMD = MSG_ID(GAPC, 0x0E), + /// Request of updating connection parameters indication + GAPC_PARAM_UPDATE_REQ_IND = MSG_ID(GAPC, 0x0F), + /// Master confirm or not that parameters proposed by slave are accepted or not + GAPC_PARAM_UPDATE_CFM = MSG_ID(GAPC, 0x10), + /// Connection parameters updated indication + GAPC_PARAM_UPDATED_IND = MSG_ID(GAPC, 0x11), + + /* Bonding procedure */ + /// Start Bonding command procedure + GAPC_BOND_CMD = MSG_ID(GAPC, 0x12), + /// Bonding requested by peer device indication message. + GAPC_BOND_REQ_IND = MSG_ID(GAPC, 0x13), + /// Confirm requested bond information. + GAPC_BOND_CFM = MSG_ID(GAPC, 0x14), + /// Bonding information indication message + GAPC_BOND_IND = MSG_ID(GAPC, 0x15), + + /* Encryption procedure */ + /// Start Encryption command procedure + GAPC_ENCRYPT_CMD = MSG_ID(GAPC, 0x16), + /// Encryption requested by peer device indication message. + GAPC_ENCRYPT_REQ_IND = MSG_ID(GAPC, 0x17), + /// Confirm requested Encryption information. + GAPC_ENCRYPT_CFM = MSG_ID(GAPC, 0x18), + /// Encryption information indication message + GAPC_ENCRYPT_IND = MSG_ID(GAPC, 0x19), + + /* Security request procedure */ + /// Start Security Request command procedure + GAPC_SECURITY_CMD = MSG_ID(GAPC, 0x1A), + /// Security requested by peer device indication message + GAPC_SECURITY_IND = MSG_ID(GAPC, 0x1B), + + /* Signature procedure */ + /// Indicate the current sign counters to the application + GAPC_SIGN_COUNTER_IND = MSG_ID(GAPC, 0x1C), + + /* Device information */ + /// Indication of ongoing connection Channel Map + GAPC_CON_CHANNEL_MAP_IND = MSG_ID(GAPC, 0x1D), + + /* LE Ping */ + /// Update LE Ping timeout value + GAPC_SET_LE_PING_TO_CMD = MSG_ID(GAPC, 0x28), + /// LE Ping timeout indication + GAPC_LE_PING_TO_VAL_IND = MSG_ID(GAPC, 0x29), + /// LE Ping timeout expires indication + GAPC_LE_PING_TO_IND = MSG_ID(GAPC, 0x2A), + + /* LE Data Length extension*/ + /// LE Set Data Length Command + GAPC_SET_LE_PKT_SIZE_CMD = MSG_ID(GAPC, 0x2B), + /// LE Set Data Length Indication + GAPC_LE_PKT_SIZE_IND = MSG_ID(GAPC, 0x2C), + + /* Secure Connections */ + /// Request to inform the remote device when keys have been entered or erased + GAPC_KEY_PRESS_NOTIFICATION_CMD = MSG_ID(GAPC, 0x2D), + /// Indication that a KeyPress has been performed on the peer device. + GAPC_KEY_PRESS_NOTIFICATION_IND = MSG_ID(GAPC, 0x2E), + + /* PHY Management */ + /// Set the PHY configuration for current active link + GAPC_SET_PHY_CMD = MSG_ID(GAPC, 0x2F), + /// Active link PHY configuration. Triggered when configuration is read or during an update. + GAPC_LE_PHY_IND = MSG_ID(GAPC, 0x30), + + /* Channel Selection Algorithm */ + /// Indication of currently used channel selection algorithm + /// @see struct gapc_chan_sel_algo_ind + GAPC_CHAN_SEL_ALGO_IND = MSG_ID(GAPC, 0x31), + + /* Vendor specific connection parameters */ + /// Set the preferred slave latency (for slave only, with RW controller) + GAPC_SET_PREF_SLAVE_LATENCY_CMD = MSG_ID(GAPC, 0x32), + /// Set the preferred slave event duration (for slave only, with RW controller) + GAPC_SET_PREF_SLAVE_EVT_DUR_CMD = MSG_ID(GAPC, 0x33), + /// Set the maximum reception and size and time using DLE negotiation + GAPC_SET_MAX_RX_SIZE_AND_TIME_CMD = MSG_ID(GAPC, 0x3D), + + /// Indication to the task that sends the unknown message + GAPC_UNKNOWN_MSG_IND = MSG_ID(GAPC, 0x34), + + /* Periodic Sync Transfer */ + /// Transfer periodic advertising sync information to peer device + GAPC_PER_ADV_SYNC_TRANS_CMD = MSG_ID(GAPC, 0x35), + + /* Constant Tone Extension */ + /// Constant Tone Extension Transmission configuration command + GAPC_CTE_TX_CFG_CMD = MSG_ID(GAPC, 0x38), + /// Constant Tone Extension Reception configuration command + GAPC_CTE_RX_CFG_CMD = MSG_ID(GAPC, 0x39), + /// Constant Tone Extension request control command (enable / disable) + GAPC_CTE_REQ_CTRL_CMD = MSG_ID(GAPC, 0x3A), + /// Constant Tone Extension Response control command (enable / disable) + GAPC_CTE_RSP_CTRL_CMD = MSG_ID(GAPC, 0x3B), + /// Indicate reception of a IQ Report event over a ble connection + GAPC_CTE_IQ_REPORT_IND = MSG_ID(GAPC, 0x3C), + + + // ---------------------- INTERNAL API ------------------------ + /* Internal messages for timer events, not part of API*/ + /// Signature procedure + GAPC_SIGN_CMD = MSG_ID(GAPC, 0xF0), + /// Signature result + GAPC_SIGN_IND = MSG_ID(GAPC, 0xF1), + + /// Parameter update procedure timeout indication + GAPC_PARAM_UPDATE_TO_IND = MSG_ID(GAPC, 0xF2), + /// Pairing procedure timeout indication + GAPC_SMP_TIMEOUT_TIMER_IND = MSG_ID(GAPC, 0xF3), + /// Pairing repeated attempts procedure timeout indication + GAPC_SMP_REP_ATTEMPTS_TIMER_IND = MSG_ID(GAPC, 0xF4), +}; + + + + +/// request operation type - application interface +/*@TRACE*/ +enum gapc_operation +{ + /* Operation Flags */ + /* No Operation (if nothing has been requested) */ + /* ************************************************ */ + /// No operation + GAPC_NO_OP = 0x00, + + /* Connection management */ + /// Disconnect link + GAPC_DISCONNECT = 0x01, + + /* Connection information */ + /// Retrieve name of peer device. + GAPC_GET_PEER_NAME = 0x02, + /// Retrieve peer device version info. + GAPC_GET_PEER_VERSION = 0x03, + /// Retrieve peer device features. + GAPC_GET_PEER_FEATURES = 0x04, + /// Get Peer device appearance + GAPC_GET_PEER_APPEARANCE = 0x05, + /// Get Peer device Slaved Preferred Parameters + GAPC_GET_PEER_SLV_PREF_PARAMS = 0x06, + /// Retrieve connection RSSI. + GAPC_GET_CON_RSSI = 0x07, + /// Retrieve Connection Channel MAP. + GAPC_GET_CON_CHANNEL_MAP = 0x08, + + /* Connection parameters update */ + /// Perform update of connection parameters. + GAPC_UPDATE_PARAMS = 0x09, + + /* Security procedures */ + /// Start bonding procedure. + GAPC_BOND = 0x0A, + /// Start encryption procedure. + GAPC_ENCRYPT = 0x0B, + /// Start security request procedure + GAPC_SECURITY_REQ = 0x0C, + + /* LE Ping*/ + /// get timer timeout value + GAPC_GET_LE_PING_TO = 0x12, + /// set timer timeout value + GAPC_SET_LE_PING_TO = 0x13, + + /* LE Data Length extension*/ + /// LE Set Data Length + GAPC_SET_LE_PKT_SIZE = 0x14, + + /* Central Address resolution supported*/ + GAPC_GET_ADDR_RESOL_SUPP = 0x15, + /// Resolvable Private Address Only declaration + GAPC_GET_RSLV_PRIV_ADDR_ONLY = 0x1D, + + /* Secure Connections */ + /// Request to inform the remote device when keys have been entered or erased + GAPC_KEY_PRESS_NOTIFICATION = 0x16, + + /* PHY Management */ + /// Set the PHY configuration for current active link + GAPC_SET_PHY = 0x17, + /// Retrieve PHY configuration of active link + GAPC_GET_PHY = 0x18, + + /* Channel Selection Algorithm */ + /// Retrieve Channel Selection Algorithm + GAPC_GET_CHAN_SEL_ALGO = 0x19, + + /* Vendor specific connection parameters */ + /// Set the preferred slave latency (for slave only, with RW controller) + GAPC_SET_PREF_SLAVE_LATENCY = 0x1A, + /// Set the preferred slave event duration (for slave only, with RW controller) + GAPC_SET_PREF_SLAVE_EVT_DUR = 0x1B, + /// Set maximum RX size and time using DLE negotiation + GAPC_SET_MAX_RX_SIZE_AND_TIME = 0x1D, + + /* Periodic Sync Transfer */ + /// Transfer periodic advertising sync information to peer device + GAPC_PER_ADV_SYNC_TRANS = 0x1C, + + /* Constant Tone Extension */ + /// Constant Tone Extension Transmission configuration + GAPC_CTE_TX_CFG = 0x20, + /// Constant Tone Extension Reception configuration + GAPC_CTE_RX_CFG = 0x21, + /// Constant Tone Extension request control (enable / disable) + GAPC_CTE_REQ_CTRL = 0x22, + /// Constant Tone Extension Response control (enable / disable) + GAPC_CTE_RSP_CTRL = 0x23, + + // ---------------------- INTERNAL API ------------------------ + /* Packet signature */ + /// sign an attribute packet + GAPC_SIGN_PACKET = 0xF0, + /// Verify signature or an attribute packet + GAPC_SIGN_CHECK = 0xF1, +}; + +/// Bond event type. +/*@TRACE*/ +enum gapc_bond +{ + /// Bond Pairing request + GAPC_PAIRING_REQ, + /// Respond to Pairing request + GAPC_PAIRING_RSP, + + /// Pairing Finished information + GAPC_PAIRING_SUCCEED, + /// Pairing Failed information + GAPC_PAIRING_FAILED, + + /// Used to retrieve pairing Temporary Key + GAPC_TK_EXCH, + /// Used for Identity Resolving Key exchange + GAPC_IRK_EXCH, + /// Used for Connection Signature Resolving Key exchange + GAPC_CSRK_EXCH, + /// Used for Long Term Key exchange + GAPC_LTK_EXCH, + + /// Bond Pairing request issue, Repeated attempt + GAPC_REPEATED_ATTEMPT, + + /// Out of Band - exchange of confirm and rand. + GAPC_OOB_EXCH, + + /// Numeric Comparison - Exchange of Numeric Value - + GAPC_NC_EXCH +}; + +/// List of device info that should be provided by application +/*@TRACE*/ +enum gapc_dev_info +{ + /// Device Name + GAPC_DEV_NAME, + /// Device Appearance Icon + GAPC_DEV_APPEARANCE, + /// Device Slave preferred parameters + GAPC_DEV_SLV_PREF_PARAMS, + /// Device Central address resolution + GAPC_DEV_CTL_ADDR_RESOL, + /// Resolvable Private address only after bond + GAPC_DEV_RSLV_PRIV_ADDR_ONLY, + /// maximum device info parameter + GAPC_DEV_INFO_MAX, +}; + +/// List of features available on a device +enum gapc_features_list +{ + /// LE encryption + GAPC_ENCRYPT_FEAT_MASK = (1 << 0), + /// Connection Parameters Request Procedure + GAPC_CONN_PARAM_REQ_FEAT_MASK = (1 << 1), + /// Extended Reject Indication + GAPC_EXT_REJECT_IND_FEAT_MASK = (1 << 2), + /// Slave-initiated Features Exchange + GAPC_SLAVE_FEAT_EXCH_FEAT_MASK = (1 << 3), + /// LE ping + GAPC_LE_PING_FEAT_MASK = (1 << 4) +}; + +/// Option for PHY configuration +enum gapc_phy_option +{ + /// No preference for rate used when transmitting on the LE Coded PHY + GAPC_PHY_OPT_LE_CODED_ALL_RATES = (1 << 0), + /// 500kbps rate preferred when transmitting on the LE Coded PHY + GAPC_PHY_OPT_LE_CODED_500K_RATE = (1 << 1), + /// 125kbps when transmitting on the LE Coded PHY + GAPC_PHY_OPT_LE_CODED_125K_RATE = (1 << 2), +}; + +/// Keypress Notification types +enum gapc_key_ntf_type +{ + /// Passkey entry started + GAPC_KEY_NTF_ENTRY_STARTED = 0x00, + /// Passkey digit entered + GAPC_KEY_NTF_DIGIT_ENTERED, + /// Passkey digit erased + GAPC_KEY_NTF_DIGIT_ERASED, + /// Passkey cleared + GAPC_KEY_NTF_CLEARED, + /// Passkey entry completed + GAPC_KEY_NTF_ENTRY_COMPLETED +}; + +/// Client bond information +enum gapc_cli_info +{ + /// Service changed indication enabled + GAPC_SVC_CHANGED_IND_EN_BIT = (1 << 0), + GAPC_SVC_CHANGED_IND_EN_POS = 0, + /// Database updated since last connection + GAPC_DB_UPDATED_BIT = (1 << 1), + GAPC_DB_UPDATED_POS = 1, +}; + +/// Client supported features +enum gapc_cli_feat +{ + /// Robust Cache feature enabled + GAPC_ROBUST_CACHE_EN_BIT = (1 << 0), + GAPC_ROBUST_CACHE_EN_POS = 0, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Operation command structure in order to keep requested operation. +struct gapc_operation_cmd +{ + /// GAP request type + uint8_t operation; +}; + + +/// Command complete event data structure +/*@TRACE*/ +struct gapc_cmp_evt +{ + /// GAP request type + uint8_t operation; + /// Status of the request + uint8_t status; +}; + +/// Indicate that an unknown message has been received +/*@TRACE*/ +struct gapc_unknown_msg_ind +{ + /// Unknown message id + ke_msg_id_t unknown_msg_id; +}; + +/// Indicate that a connection has been established +/*@TRACE*/ +struct gapc_connection_req_ind +{ + /// Connection handle + uint16_t conhdl; + /// Connection interval + uint16_t con_interval; + /// Connection latency + uint16_t con_latency; + /// Link supervision timeout + uint16_t sup_to; + /// Clock accuracy + uint8_t clk_accuracy; + /// Peer address type + uint8_t peer_addr_type; + /// Peer BT address + bd_addr_t peer_addr; + /// Role of device in connection (0 = Master / 1 = Slave) + uint8_t role; +}; + + +/// Set specific link data configuration. +/*@TRACE*/ +struct gapc_connection_cfm +{ + /// Local CSRK value + struct gap_sec_key lcsrk; + /// Local signature counter value + uint32_t lsign_counter; + /// Remote CSRK value + struct gap_sec_key rcsrk; + /// Remote signature counter value + uint32_t rsign_counter; + /// Pairing level (@see enum gap_pairing_lvl) + uint8_t pairing_lvl; + /// Client bond data information (@see enum gapc_cli_info) + uint8_t cli_info; + /// LTK exchanged during pairing. + bool ltk_present; + /// Client supported features (@see enum gapc_cli_feat) + uint8_t cli_feat; + /// Peer GATT Service Start handle + uint16_t gatt_start_handle; + /// Peer GATT Service End Handle + uint16_t gatt_end_handle; + /// Peer Service Change value handle + uint16_t svc_chg_handle; +}; + +/// Request disconnection of current link command. +/*@TRACE*/ +struct gapc_disconnect_cmd +{ + /// GAP request type: + /// - GAPC_DISCONNECT: Disconnect link. + uint8_t operation; + + /// Reason of disconnection + uint8_t reason; +}; + + +/// Indicate that a link has been disconnected +/*@TRACE*/ +struct gapc_disconnect_ind +{ + /// Connection handle + uint16_t conhdl; + /// Reason of disconnection + uint8_t reason; +}; + + +/// Retrieve information command +/*@TRACE*/ +struct gapc_get_info_cmd +{ + /// GAP request type: + /// - GAPC_GET_PEER_NAME: Retrieve name of peer device. + /// - GAPC_GET_PEER_VERSION: Retrieve peer device version info. + /// - GAPC_GET_PEER_FEATURES: Retrieve peer device features. + /// - GAPC_GET_CON_RSSI: Retrieve connection RSSI. + /// - GAPC_GET_CON_CHANNEL_MAP: Retrieve Connection Channel MAP. + /// - GAPC_GET_PEER_APPEARANCE: Get Peer device appearance + /// - GAPC_GET_PEER_SLV_PREF_PARAMS: Get Peer device Slaved Preferred Parameters + /// - GAPC_GET_ADDR_RESOL_SUPP: Address Resolution Supported + /// - GAPC_GET_RSLV_PRIV_ADDR_ONLY: Resolvable Private Address Only declaration + /// - GAPC_GET_LE_PING_TIMEOUT: Retrieve LE Ping Timeout Value + uint8_t operation; +}; + +/// device information data +/*@TRACE + @trc_ref gapc_dev_info*/ +union gapc_dev_info_val +{ + /// Device name + //@trc_union parent.req == GAPC_DEV_NAME + struct gap_dev_name name; + /// Appearance Icon + //@trc_union parent.req == GAPC_DEV_APPEARANCE + uint16_t appearance; + /// Slave preferred parameters + //@trc_union parent.req == GAPC_DEV_SLV_PREF_PARAMS + struct gap_slv_pref slv_pref_params; + /// Central address resolution + //@trc_union parent.req == GAPC_DEV_CTL_ADDR_RESOL + uint8_t ctl_addr_resol; + /// Resolvable Private address only + //@trc_union parent.req == GAPC_DEV_RSLV_PRIV_ADDR_ONLY + uint8_t rslv_priv_addr_only; +}; + +/// Peer device attribute DB info such as Device Name, Appearance or Slave Preferred Parameters +/*@TRACE*/ +struct gapc_peer_att_info_ind +{ + /// Requested information + /// - GAPC_DEV_NAME: Device Name + /// - GAPC_DEV_APPEARANCE: Device Appearance Icon + /// - GAPC_DEV_SLV_PREF_PARAMS: Device Slave preferred parameters + /// - GAPC_GET_ADDR_RESOL_SUPP: Address resolution supported + /// - GAPC_GET_RSLV_PRIV_ADDR_ONLY: Resolvable Private Address Only declaration + uint8_t req; + /// Attribute handle + uint16_t handle; + + /// device information data + union gapc_dev_info_val info; +}; + +/// Indication of peer version info +/*@TRACE*/ +struct gapc_peer_version_ind +{ + /// Manufacturer name + uint16_t compid; + /// LMP subversion + uint16_t lmp_subvers; + /// LMP version + uint8_t lmp_vers; +}; + +/// Indication of peer features info +/*@TRACE*/ +struct gapc_peer_features_ind +{ + /// 8-byte array for LE features + uint8_t features[GAP_LE_FEATS_LEN]; +}; + +/// Indication of ongoing connection RSSI +/*@TRACE*/ +struct gapc_con_rssi_ind +{ + /// RSSI value + int8_t rssi; +}; + +/// Indication of ongoing connection Channel Map +/*@TRACE*/ +struct gapc_con_channel_map_ind +{ + /// channel map value + le_chnl_map_t ch_map; +}; + +/// Sign counter value changed due to packet signing or signature verification. +struct gapc_sign_counter_updated_ind +{ + /// New Local signature counter value + uint32_t lsign_counter; + /// New Remote signature counter value + uint32_t rsign_counter; +}; + +/// Indication of LE Ping +/*@TRACE*/ +struct gapc_le_ping_to_val_ind +{ + ///Authenticated payload timeout + uint16_t timeout; +}; + + +/// Peer device request local device info such as name, appearance or slave preferred parameters +/*@TRACE*/ +struct gapc_get_dev_info_req_ind +{ + /// Requested information + /// - GAPC_DEV_NAME: Device Name + /// - GAPC_DEV_APPEARANCE: Device Appearance Icon + /// - GAPC_DEV_SLV_PREF_PARAMS: Device Slave preferred parameters + uint8_t req; +}; + + + +/// Send requested info to peer device +/*@TRACE*/ +struct gapc_get_dev_info_cfm +{ + /// Requested information + /// - GAPC_DEV_NAME: Device Name + /// - GAPC_DEV_APPEARANCE: Device Appearance Icon + /// - GAPC_DEV_SLV_PREF_PARAMS: Device Slave preferred parameters + uint8_t req; + + /// Peer device information data + union gapc_dev_info_val info; +}; + +/// device information data +/*@TRACE + @trc_ref gapc_dev_info*/ +union gapc_set_dev_info +{ + /// Device name + //@trc_union parent.req == GAPC_DEV_NAME + struct gap_dev_name name; + /// Appearance Icon + //@trc_union parent.req == GAPC_DEV_APPEARANCE + uint16_t appearance; +}; + +/// Peer device request to modify local device info such as name or appearance +/*@TRACE*/ +struct gapc_set_dev_info_req_ind +{ + /// Requested information + /// - GAPC_DEV_NAME: Device Name + /// - GAPC_DEV_APPEARANCE: Device Appearance Icon + uint8_t req; + + /// device information data + union gapc_set_dev_info info; +}; + +/// Local device accept or reject device info modification +/*@TRACE*/ +struct gapc_set_dev_info_cfm +{ + /// Requested information + /// - GAPC_DEV_NAME: Device Name + /// - GAPC_DEV_APPEARANCE: Device Appearance Icon + uint8_t req; + + /// Status code used to know if requested has been accepted or not + uint8_t status; +}; + +/// Connection Parameter used to update connection parameters +struct gapc_conn_param +{ + /// Connection interval minimum + uint16_t intv_min; + /// Connection interval maximum + uint16_t intv_max; + /// Latency + uint16_t latency; + /// Supervision timeout + uint16_t time_out; +}; + +/// Perform update of connection parameters command +/*@TRACE*/ +struct gapc_param_update_cmd +{ + /// GAP request type: + /// - GAPC_UPDATE_PARAMS: Perform update of connection parameters. + uint8_t operation; + /// Internal parameter used to manage internally l2cap packet identifier for signaling + uint8_t pkt_id; + /// Connection interval minimum + uint16_t intv_min; + /// Connection interval maximum + uint16_t intv_max; + /// Latency + uint16_t latency; + /// Supervision timeout + uint16_t time_out; + /// Minimum Connection Event Duration + uint16_t ce_len_min; + /// Maximum Connection Event Duration + uint16_t ce_len_max; +}; + +/// Request of updating connection parameters indication +/*@TRACE*/ +struct gapc_param_update_req_ind +{ + /// Connection interval minimum + uint16_t intv_min; + /// Connection interval maximum + uint16_t intv_max; + /// Latency + uint16_t latency; + /// Supervision timeout + uint16_t time_out; +}; + +/// Connection parameters updated indication +/*@TRACE*/ +struct gapc_param_updated_ind +{ + ///Connection interval value + uint16_t con_interval; + ///Connection latency value + uint16_t con_latency; + ///Supervision timeout + uint16_t sup_to; +}; + +/// Master confirm or not that parameters proposed by slave are accepted or not +/*@TRACE*/ +struct gapc_param_update_cfm +{ + /// True to accept slave connection parameters, False else. + bool accept; + /// Minimum Connection Event Duration + uint16_t ce_len_min; + /// Maximum Connection Event Duration + uint16_t ce_len_max; +}; + +/// Parameters of the @ref GAPC_SET_PREF_SLAVE_LATENCY_CMD message +/*@TRACE*/ +struct gapc_set_pref_slave_latency_cmd +{ + /// GAP request type: + /// - GAPC_SET_PREF_SLAVE_LATENCY: Set preferred slave latency + uint8_t operation; + /// Preferred latency that the controller should use on a connection (in number of connection events) + uint16_t latency; +}; + +/// Parameters of the @ref GAPC_SET_PREF_SLAVE_EVT_DUR_CMD message +/*@TRACE*/ +struct gapc_set_pref_slave_evt_dur_cmd +{ + /// GAP request type: + /// - GAPC_SET_PREF_SLAVE_EVT_DUR : Set preferred slave event duration + uint8_t operation; + /// Preferred event duration that the controller should use on a connection (N * 0.625 ms) + uint16_t duration; + /// Slave transmits a single packet per connection event (False/True) + uint8_t single_tx; +}; + + +/// Parameters of the @ref GAPC_SET_MAX_RX_SIZE_AND_TIME_CMD message +/*@TRACE*/ +struct gapc_set_max_rx_size_and_time_cmd +{ + /// GAP request type: + /// - GAPC_SET_MAX_RX_SIZE_AND_TIME: Set maximum RX size and time using DLE negotiation + uint8_t operation; + /// Maximum RX size (in Bytes) + uint16_t rx_octets; + /// Maximum RX time (in us) + uint16_t rx_time; +}; + + +/// Parameters of the @ref GAPC_PER_ADV_SYNC_TRANS_CMD message +/*@TRACE*/ +struct gapc_per_adv_sync_trans_cmd +{ + /// GAP request type: + /// - GAPC_PER_ADV_SYNC_TRANS : Periodic Advertising Sync Transfer + uint8_t operation; + /// Periodic Advertising or Periodic Sync activity index + uint8_t actv_idx; + /// A value provided by application + uint16_t service_data; +}; + +/// Parameters of the @ref GAPC_CTE_TX_CFG_CMD message +/*@TRACE*/ +struct gapc_cte_tx_cfg_cmd +{ + /// GAP request type: + /// - GAPC_CTE_TX_CFG: Constant Tone Extension Transmission configuration + uint8_t operation; + /// CTE types (bit0: AOA | bit1: AOD-1us | bit2: AOD-2us) (@see enum gap_cte_type) + uint8_t cte_types; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref GAPC_CTE_RX_CFG_CMD message +/*@TRACE*/ +struct gapc_cte_rx_cfg_cmd +{ + /// GAP request type: + /// - GAPC_CTE_RX_CFG: Constant Tone Extension Reception configuration + uint8_t operation; + /// Sampling enable + bool sample_en; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref GAPC_CTE_REQ_CTRL_CMD message +/*@TRACE*/ +struct gapc_cte_req_ctrl_cmd +{ + /// GAP request type: + /// - GAPC_CTE_REQ_CTRL: Constant Tone Extension request control (enable / disable) + uint8_t operation; + /// True to enable TX or RX Constant Tone Extension, False to disable + bool enable; + /// CTE request interval (in number of connection events) + uint16_t interval; + /// Requested CTE length (in 8us unit) + uint8_t cte_len; + /// Requested CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) (@see enum gap_cte_type) + uint8_t cte_type; +}; + +/// Parameters of the @ref GAPC_CTE_RSP_CTRL_CMD message +/*@TRACE*/ +struct gapc_cte_rsp_ctrl_cmd +{ + /// GAP request type: + /// - GAPC_CTE_RSP_CTRL: Constant Tone Extension response control (enable / disable) + uint8_t operation; + /// True to enable TX or RX Constant Tone Extension, False to disable + bool enable; +}; + +/// Indicate reception of a IQ Report event over a BLE connection +/*@TRACE*/ +struct gapc_cte_iq_report_ind +{ + /// Rx PHY (@see enum gap_phy_val) + uint8_t rx_phy; + /// Data channel index + uint8_t data_channel_idx; + /// RSSI (in 0.1 dBm) + int16_t rssi; + /// RSSI antenna ID + uint8_t rssi_antenna_id; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) (@see enum gap_cte_type) + uint8_t cte_type; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Packet status + uint8_t pkt_status; + /// Connection event counter + uint16_t con_evt_cnt; + /// Number of samples + uint8_t nb_samples; + /// I/Q sample + struct gap_iq_sample sample[__ARRAY_EMPTY]; +}; + +/// Pairing parameters +/*@TRACE*/ +struct gapc_pairing +{ + /// IO capabilities (@see gap_io_cap) + uint8_t iocap; + /// OOB information (@see gap_oob) + uint8_t oob; + /// Authentication (@see gap_auth) + /// Note in BT 4.1 the Auth Field is extended to include 'Key Notification' and + /// and 'Secure Connections'. + uint8_t auth; + /// Encryption key size (7 to 16) + uint8_t key_size; + ///Initiator key distribution (@see gap_kdist) + uint8_t ikey_dist; + ///Responder key distribution (@see gap_kdist) + uint8_t rkey_dist; + + /// Device security requirements (minimum security level). (@see gap_sec_req) + uint8_t sec_req; +}; + +/// Long Term Key information +/*@TRACE*/ +struct gapc_ltk +{ + /// Long Term Key + struct gap_sec_key ltk; + /// Encryption Diversifier + uint16_t ediv; + /// Random Number + rand_nb_t randnb; + /// Encryption key size (7 to 16) + uint8_t key_size; +}; +/// Out of Band Information +/*@TRACE*/ +struct gapc_oob +{ + /// Confirm Value + uint8_t conf[GAP_KEY_LEN]; + /// Random Number + uint8_t rand[GAP_KEY_LEN]; +}; + +/*@TRACE*/ +struct gapc_nc +{ + uint8_t value[4]; +}; + +/// Identity Resolving Key information +/*@TRACE*/ +struct gapc_irk +{ + /// Identity Resolving Key + struct gap_sec_key irk; + /// Device BD Identity Address + struct gap_bdaddr addr; +}; + + +/// Start Bonding command procedure +/*@TRACE*/ +struct gapc_bond_cmd +{ + /// GAP request type: + /// - GAPC_BOND: Start bonding procedure. + uint8_t operation; + /// Pairing information + struct gapc_pairing pairing; +}; + +/// Bond procedure requested information data +/*@TRACE + @trc_ref gapc_bond*/ +union gapc_bond_req_data +{ + /// Authentication level (@see gap_auth) (if request = GAPC_PAIRING_REQ) + //@trc_union parent.request == GAPC_PAIRING_REQ + uint8_t auth_req; + /// LTK Key Size (if request = GAPC_LTK_EXCH) + //@trc_union parent.request == GAPC_LTK_EXCH + uint8_t key_size; + /// Device IO used to get TK: (if request = GAPC_TK_EXCH) + /// - GAP_TK_OOB: TK get from out of band method + /// - GAP_TK_DISPLAY: TK generated and shall be displayed by local device + /// - GAP_TK_KEY_ENTRY: TK shall be entered by user using device keyboard + //@trc_union parent.request == GAPC_TK_EXCH + uint8_t tk_type; + + /// Addition OOB Data for the OOB Conf and Rand values + //@trc_union parent.request == GAPC_OOB_EXCH + struct gapc_oob oob_data; + /// Numeric Comparison Data + //@trc_union parent.request == GAPC_NC_EXCH + struct gapc_nc nc_data; +}; + +/// Bonding requested by peer device indication message. +/*@TRACE*/ +struct gapc_bond_req_ind +{ + /// Bond request type (@see gapc_bond) + uint8_t request; + + /// Bond procedure requested information data + union gapc_bond_req_data data; +}; + +/*@TRACE + @trc_ref gapc_bond +*/ +union gapc_bond_cfm_data +{ + /// Pairing Features (request = GAPC_PAIRING_RSP) + //@trc_union parent.request == GAPC_PAIRING_RSP + struct gapc_pairing pairing_feat; + /// LTK (request = GAPC_LTK_EXCH) + //@trc_union parent.request == GAPC_LTK_EXCH + struct gapc_ltk ltk; + /// CSRK (request = GAPC_CSRK_EXCH) + //@trc_union parent.request == GAPC_CSRK_EXCH + struct gap_sec_key csrk; + /// TK (request = GAPC_TK_EXCH) + //@trc_union parent.request == GAPC_TK_EXCH + struct gap_sec_key tk; + /// IRK (request = GAPC_IRK_EXCH) + //@trc_union parent.request == GAPC_IRK_EXCH + struct gapc_irk irk; + /// OOB Confirm and Random from the peer (request = GAPC_OOB_EXCH) + //@trc_union parent.request == GAPC_OOB_EXCH + struct gapc_oob oob; +}; + +/// Confirm requested bond information. +/*@TRACE*/ +struct gapc_bond_cfm +{ + /// Bond request type (@see gapc_bond) + uint8_t request; + /// Request accepted + uint8_t accept; + + /// Bond procedure information data + union gapc_bond_cfm_data data; +}; + +/** + * Pairing information + */ +/*@TRACE*/ +struct gapc_pairing_info +{ + /// Pairing level information (@see gap_pairing_lvl) + uint8_t level; + /// LTK exchanged during pairing. + bool ltk_present; +}; + +/// Bond procedure information data +/*@TRACE + @trc_ref gapc_bond*/ +union gapc_bond_data +{ + /// Pairing information + /// (if info = GAPC_PAIRING_SUCCEED) + //@trc_union parent.info == GAPC_PAIRING_SUCCEED + struct gapc_pairing_info pairing; + /// Pairing failed reason (if info = GAPC_PAIRING_FAILED) + //@trc_union parent.info == GAPC_PAIRING_FAILED + uint8_t reason; + /// Long Term Key information (if info = GAPC_LTK_EXCH) + //@trc_union parent.info == GAPC_LTK_EXCH + struct gapc_ltk ltk; + /// Identity Resolving Key information (if info = GAPC_IRK_EXCH) + //@trc_union parent.info == GAPC_IRK_EXCH + struct gapc_irk irk; + /// Connection Signature Resolving Key information (if info = GAPC_CSRK_EXCH) + //@trc_union parent.info == GAPC_CSRK_EXCH + struct gap_sec_key csrk; +}; + +/// Bonding information indication message +/*@TRACE*/ +struct gapc_bond_ind +{ + /// Bond information type (@see gapc_bond) + uint8_t info; + + /// Bond procedure information data + union gapc_bond_data data; +}; + +/// Start Encryption command procedure +/*@TRACE*/ +struct gapc_encrypt_cmd +{ + /// GAP request type: + /// - GAPC_ENCRYPT: Start encryption procedure. + uint8_t operation; + /// Long Term Key information + struct gapc_ltk ltk; +}; + +/// Encryption requested by peer device indication message. +/*@TRACE*/ +struct gapc_encrypt_req_ind +{ + /// Encryption Diversifier + uint16_t ediv; + /// Random Number + rand_nb_t rand_nb; +}; + +/// Confirm requested Encryption information. +/*@TRACE*/ +struct gapc_encrypt_cfm +{ + /// Indicate if a LTK has been found for the peer device + uint8_t found; + /// Long Term Key + struct gap_sec_key ltk; + /// LTK Key Size + uint8_t key_size; +}; + +/// Encryption information indication message +/*@TRACE*/ +struct gapc_encrypt_ind +{ + /// Pairing level (@see gap_pairing_lvl) + uint8_t pairing_lvl; +}; + +/// Start Security Request command procedure +/*@TRACE*/ +struct gapc_security_cmd +{ + /// GAP request type: + /// - GAPC_SECURITY_REQ: Start security request procedure + uint8_t operation; + /// Authentication level (@see gap_auth) + uint8_t auth; +}; +/// Security requested by peer device indication message +/*@TRACE*/ +struct gapc_security_ind +{ + /// Authentication level (@see gap_auth) + uint8_t auth; +}; + +/// Parameters of the @ref GAPC_SIGN_COUNTER_IND message +/*@TRACE*/ +struct gapc_sign_counter_ind +{ + /// Local SignCounter value + uint32_t local_sign_counter; + /// Peer SignCounter value + uint32_t peer_sign_counter; +}; + + +/// Parameters of the @ref GAPC_SET_LE_PING_TO_CMD message +/*@TRACE*/ +struct gapc_set_le_ping_to_cmd +{ + /// GAP request type: + /// - GAPC_SET_LE_PING_TO : Set the LE Ping timeout value + uint8_t operation; + /// Authenticated payload timeout + uint16_t timeout; +}; + +/// Parameters of the @ref GAPC_SET_LE_PKT_SIZE_CMD message +/*@TRACE*/ +struct gapc_set_le_pkt_size_cmd +{ + /// GAP request type: + /// - GAPC_SET_LE_PKT_SIZE : Set the LE Data length value + uint8_t operation; + ///Preferred maximum number of payload octets that the local Controller should include + ///in a single Link Layer Data Channel PDU. + uint16_t tx_octets; + ///Preferred maximum number of microseconds that the local Controller should use to transmit + ///a single Link Layer Data Channel PDU + uint16_t tx_time; +}; + +/// Parameters of the @ref GAPC_LE_PKT_SIZE_IND message +/*@TRACE*/ +struct gapc_le_pkt_size_ind +{ + ///The maximum number of payload octets in TX + uint16_t max_tx_octets; + ///The maximum time that the local Controller will take to TX + uint16_t max_tx_time; + ///The maximum number of payload octets in RX + uint16_t max_rx_octets; + ///The maximum time that the local Controller will take to RX + uint16_t max_rx_time; +}; + +/// Parameters of the @ref GAPC_KEY_PRESS_NOTIFICATION_CMD message +/*@TRACE*/ +struct gapc_key_press_notif_cmd +{ + /// GAP request type: + /// - GAPC_KEY_PRESS_NOTIFICATION_CMD : Inform the remote device when keys have been entered or erased + uint8_t operation; + /// notification type + uint8_t notification_type; +}; + +/// Parameters of the @ref GAPC_KEY_PRESS_NOTIFICATION_IND message +/*@TRACE*/ +struct gapc_key_press_notif_ind +{ + /// notification type + uint8_t notification_type; +}; + +/// Set the PHY configuration for current active link +/*@TRACE*/ +struct gapc_set_phy_cmd +{ + /// GAP request type: + /// - GAPC_SET_PHY : Set the PHY configuration for current active link + uint8_t operation; + /// Supported LE PHY for data transmission (@see enum gap_phy) + uint8_t tx_phy; + /// Supported LE PHY for data reception (@see enum gap_phy) + uint8_t rx_phy; + /// PHY options (@see enum gapc_phy_option) + uint8_t phy_opt; +}; + +/// Active link PHY configuration. Triggered when configuration is read or during an update. +/*@TRACE*/ +struct gapc_le_phy_ind +{ + /// LE PHY for data transmission (@see enum gap_phy_val) + uint8_t tx_phy; + /// LE PHY for data reception (@see enum gap_phy_val) + uint8_t rx_phy; +}; + +/// Parameters of the @ref GAPC_SIGN_CMD message +/*@TRACE*/ +struct gapc_sign_cmd +{ + /// GAP request type: + /// - GAPC_SIGN_PACKET: Sign an attribute packet + /// - GAPC_SIGN_CHECK: Verify signature or an attribute packet + uint8_t operation; + /// Data PDU length (Bytes) + uint16_t byte_len; + /// Data PDU + SignCounter if generation, Data PDU + SignCounter + MAC if verification + uint8_t msg[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref GAPC_SIGN_IND message +/*@TRACE*/ +struct gapc_sign_ind +{ + /// GAP request type: + /// - GAPC_SIGN_PACKET: Sign an attribute packet + /// - GAPC_SIGN_CHECK: Verify signature or an attribute packet + uint8_t operation; + /// Data PDU length (Bytes) + uint16_t byte_len; + /// Data PDU + SignCounter + MAC + uint8_t signed_msg[__ARRAY_EMPTY]; +}; + +/// Parameters of the @ref GAPC_CHAN_SEL_ALGO_IND +/*@TRACE*/ +struct gapc_chan_sel_algo_ind +{ + /// Used channel selection algorithm + uint8_t chan_sel_algo; +}; + +/// @} GAPC_TASK + +#endif /* _GAPC_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gapm_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gapm_task.h new file mode 100644 index 0000000..9ad7bd4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gapm_task.h @@ -0,0 +1,2047 @@ +/** + **************************************************************************************** + * + * @file gapm_task.h + * + * @brief Generic Access Profile Manager Task Header. + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + + +#ifndef _GAPM_TASK_H_ +#define _GAPM_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup GAPM_TASK Generic Access Profile Manager Task + * @ingroup GAPM + * @brief Handles ALL messages to/from GAP Manager block. + * + * It handles messages from lower and higher layers not related to an ongoing connection. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_task.h" // Task definitions +#include "gap.h" +#include "co_math.h" +#include "ke_msg.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// GAP Manager Message Interface +/*@TRACE*/ +enum gapm_msg_id +{ + /* Default event */ + /// Command Complete event + GAPM_CMP_EVT = MSG_ID(GAPM, 0x00), + + /* Default commands */ + /// Reset link layer and the host command + GAPM_RESET_CMD = MSG_ID(GAPM, 0x02), + + /* Device Configuration */ + /// Set device configuration command + GAPM_SET_DEV_CONFIG_CMD = MSG_ID(GAPM, 0x04), + /// Set device channel map + GAPM_SET_CHANNEL_MAP_CMD = MSG_ID(GAPM, 0x05), + + /* Local device information */ + /// Get local device info command + GAPM_GET_DEV_INFO_CMD = MSG_ID(GAPM, 0x06), + /// Local device version indication event + GAPM_DEV_VERSION_IND = MSG_ID(GAPM, 0x07), + /// Local device BD Address indication event + GAPM_DEV_BDADDR_IND = MSG_ID(GAPM, 0x08), + /// Advertising channel Tx power level + GAPM_DEV_ADV_TX_POWER_IND = MSG_ID(GAPM, 0x09), + /// Indication containing information about memory usage. + GAPM_DBG_MEM_INFO_IND = MSG_ID(GAPM, 0x0A), + /// Indication containing controller antenna information + GAPM_ANTENNA_INF_IND = MSG_ID(GAPM, 0x0B), + + /// Name of peer device indication + GAPM_PEER_NAME_IND = MSG_ID(GAPM, 0x12), + + /* Security / Encryption Toolbox */ + /// Resolve address command + GAPM_RESOLV_ADDR_CMD = MSG_ID(GAPM, 0x14), + /// Indicate that resolvable random address has been solved + GAPM_ADDR_SOLVED_IND = MSG_ID(GAPM, 0x15), + /// Generate a random address. + GAPM_GEN_RAND_ADDR_CMD = MSG_ID(GAPM, 0x16), + /// Use the AES-128 block in the controller + GAPM_USE_ENC_BLOCK_CMD = MSG_ID(GAPM, 0x17), + /// AES-128 block result indication + GAPM_USE_ENC_BLOCK_IND = MSG_ID(GAPM, 0x18), + /// Generate a 8-byte random number + GAPM_GEN_RAND_NB_CMD = MSG_ID(GAPM, 0x19), + /// Random Number Indication + GAPM_GEN_RAND_NB_IND = MSG_ID(GAPM, 0x1A), + + /* Profile Management */ + /// Create new task for specific profile + GAPM_PROFILE_TASK_ADD_CMD = MSG_ID(GAPM, 0x1B), + /// Inform that profile task has been added. + GAPM_PROFILE_ADDED_IND = MSG_ID(GAPM, 0x1C), + + /// Indicate that a message has been received on an unknown task + GAPM_UNKNOWN_TASK_IND = MSG_ID(GAPM, 0x1D), + + /* Data Length Extension */ + /// Suggested Default Data Length indication + GAPM_SUGG_DFLT_DATA_LEN_IND = MSG_ID(GAPM, 0x1E), + /// Maximum Data Length indication + GAPM_MAX_DATA_LEN_IND = MSG_ID(GAPM, 0x1F), + + /* Resolving list for controller-based privacy*/ + /// Resolving address list address indication + GAPM_RAL_ADDR_IND = MSG_ID(GAPM, 0x22), + + /* Set new IRK */ + /// Modify current IRK + GAPM_SET_IRK_CMD = MSG_ID(GAPM, 0x23), + + /* LE Protocol/Service Multiplexer Management */ + /// Register a LE Protocol/Service Multiplexer command + GAPM_LEPSM_REGISTER_CMD = MSG_ID(GAPM, 0x24), + /// Unregister a LE Protocol/Service Multiplexer command + GAPM_LEPSM_UNREGISTER_CMD = MSG_ID(GAPM, 0x25), + + /* LE Test Mode */ + /// Control of the test mode command + GAPM_LE_TEST_MODE_CTRL_CMD = MSG_ID(GAPM, 0x26), + /// Indicate end of test mode + GAPM_LE_TEST_END_IND = MSG_ID(GAPM, 0x27), + /// Indicate reception of a IQ report in LE test mode + GAPM_LE_TEST_IQ_REPORT_IND = MSG_ID(GAPM, 0x2D), + + /// Provide statistic information about ISO exchange + GAPM_ISO_STAT_IND = MSG_ID(GAPM, 0x28), + + /* Secure Connections */ + /// Request to provide DH Key + GAPM_GEN_DH_KEY_CMD = MSG_ID(GAPM, 0x29), + /// Indicates the DH Key computation is complete and available + GAPM_GEN_DH_KEY_IND = MSG_ID(GAPM, 0x2A), + /// Retrieve Public Key + GAPM_GET_PUB_KEY_CMD = MSG_ID(GAPM, 0x2B), + /// Indicates the Public Key Pair value + GAPM_PUB_KEY_IND = MSG_ID(GAPM, 0x2C), + + + /* ************************************************ */ + /* ------------ NEW COMMANDS FOR BLE 5 ------------ */ + /* ************************************************ */ + + /* List Management Operations */ + /// Get local or peer address + /// @see struct gapm_get_ral_addr_cmd + GAPM_GET_RAL_ADDR_CMD = MSG_ID(GAPM, 0x90), + /// Set content of either white list or resolving list or periodic advertiser list + /// @see struct gapm_list_set_wl_cmd + /// @see struct gapm_list_set_ral_cmd + /// @see struct gapm_list_set_pal_cmd + GAPM_LIST_SET_CMD = MSG_ID(GAPM, 0x91), + /// Indicate size of list indicated in GAPM_GET_DEV_CONFIG_CMD message + /// @see struct gapm_list_size_ind + GAPM_LIST_SIZE_IND = MSG_ID(GAPM, 0x92), + + /* Extended Air Operations */ + /// Create an advertising, a scanning, an initiating or a periodic synchronization activity + /// @see struct gapm_activity_create_cmd + /// @see struct gapm_activity_create_adv_cmd + GAPM_ACTIVITY_CREATE_CMD = MSG_ID(GAPM, 0xA0), + /// Start a previously created activity + /// @see struct gapm_activity_start_cmd + GAPM_ACTIVITY_START_CMD = MSG_ID(GAPM, 0xA1), + /// Stop either a given activity or all existing activities + /// @see struct gapm_activity_stop_cmd + GAPM_ACTIVITY_STOP_CMD = MSG_ID(GAPM, 0xA2), + /// Delete either a given activity or all existing activities + /// @see struct gapm_activity_delete_cmd + GAPM_ACTIVITY_DELETE_CMD = MSG_ID(GAPM, 0xA3), + /// Indicate that an activity has well been created + /// @see struct gapm_activity_create_ind + GAPM_ACTIVITY_CREATED_IND = MSG_ID(GAPM, 0xA4), + /// Indicate that an activity has been stopped and can be restarted + /// @see struct gapm_activity_stopped_ind + GAPM_ACTIVITY_STOPPED_IND = MSG_ID(GAPM, 0xA5), + /// Set either advertising data or scan response data or periodic advertising data + /// @see struct gapm_set_adv_data_cmd + GAPM_SET_ADV_DATA_CMD = MSG_ID(GAPM, 0xA6), + /// Indicate reception of an advertising report (periodic or not), a scan response report + /// @see struct gapm_ext_adv_report_ind + GAPM_EXT_ADV_REPORT_IND = MSG_ID(GAPM, 0xA7), + /// Indicate reception of a scan request + /// @see struct gapm_scan_request_ind + GAPM_SCAN_REQUEST_IND = MSG_ID(GAPM, 0xA8), + /// Indicate that synchronization has been successfully established with a periodic advertiser + /// @see struct gapm_sync_established_ind + GAPM_SYNC_ESTABLISHED_IND = MSG_ID(GAPM, 0xA9), + /// Indicate maximum advertising data length supported by controller + /// @see struct gapm_max_adv_data_len_ind + GAPM_MAX_ADV_DATA_LEN_IND = MSG_ID(GAPM, 0xAA), + /// Indicate number of available advertising sets + /// @see struct gapm_nb_adv_sets_ind + GAPM_NB_ADV_SETS_IND = MSG_ID(GAPM, 0xAB), + /// Indicate the transmit powers supported by the controller + /// @see struct gapm_dev_tx_power_ind + GAPM_DEV_TX_PWR_IND = MSG_ID(GAPM, 0xAC), + /// Indicate the RF path compensation values + /// @see struct gapm_dev_rf_path_comp_ind + GAPM_DEV_RF_PATH_COMP_IND = MSG_ID(GAPM, 0xAD), + /// Indication to the task that sends the unknown message + /// @see struct gapm_unknown_msg_ind + GAPM_UNKNOWN_MSG_IND = MSG_ID(GAPM, 0xAE), + /// Control reception or not of Periodic Advertising Report in a Periodic Advertising Sync activity + /// @see struct gapm_per_adv_report_ctrl_cmd + GAPM_PER_ADV_REPORT_CTRL_CMD = MSG_ID(GAPM, 0xAF), + /// Control capturing IQ samples from the Constant Tone Extension of periodic advertising packets + GAPM_PER_SYNC_IQ_SAMPLING_CTRL_CMD = MSG_ID(GAPM, 0xB0), + /// Indicate reception of a IQ Report event over a periodic advertising sync activity + GAPM_PER_ADV_IQ_REPORT_IND = MSG_ID(GAPM, 0xB1), + /// Control CTE transmission in a periodic advertising activity + GAPM_PER_ADV_CTE_TX_CTL_CMD = MSG_ID(GAPM, 0xB2), + + /* ************************************************ */ + /* ---------------- DEBUG COMMANDS ---------------- */ + /* ************************************************ */ + /// Configure the Debug Platform I&Q Sampling generator + GAPM_DBG_IQGEN_CFG_CMD = MSG_ID(GAPM, 0x50), + + /* ************************************************ */ + /* -------------- Internal usage only ------------- */ + /* ************************************************ */ + /// Message received to unknown task received + GAPM_UNKNOWN_TASK_MSG = MSG_ID(GAPM, 0xF0), + + /* Internal messages for timer events, not part of API */ + /// Address renewal timeout indication + GAPM_ADDR_RENEW_TO_IND = MSG_ID(GAPM, 0xF1), + /// Automatic connection establishment timeout indication + GAPM_AUTO_CONN_TO_IND = MSG_ID(GAPM, 0xF2), + + /* Addresses Management */ + /// Renew random private addresses + /// @see struct gapm_addr_renew_cmd + GAPM_ADDR_RENEW_CMD = MSG_ID(GAPM, 0xF3), +}; + + +/// GAP Manager operation type - application interface +/*@TRACE*/ +enum gapm_operation +{ + /* No Operation (if nothing has been requested) */ + /* ************************************************ */ + /// No operation. + GAPM_NO_OP = 0x00, + + /* Default operations */ + /* ************************************************ */ + /// Reset BLE subsystem: LL and HL. + GAPM_RESET = 0x01, + + /* Configuration operations */ + /* ************************************************ */ + /// Set device configuration + GAPM_SET_DEV_CONFIG = 0x03, + /// Set device channel map + GAPM_SET_CHANNEL_MAP = 0x04, + + /* Retrieve device information */ + /* ************************************************ */ + /// Get Local device version + GAPM_GET_DEV_VERSION = 0x05, + /// Get Local device BD Address + GAPM_GET_DEV_BDADDR = 0x06, + /// Get device advertising power level + GAPM_GET_DEV_ADV_TX_POWER = 0x07, + /// Get White List Size. + GAPM_GET_WLIST_SIZE = 0x08, + /// Retrieve Antenna information + GAPM_GET_ANTENNA_INFO = 0x09, + + /* Security / Encryption Toolbox */ + /* ************************************************ */ + /// Resolve device address + GAPM_RESOLV_ADDR = 0x17, + /// Generate a random address + GAPM_GEN_RAND_ADDR = 0x18, + /// Use the controller's AES-128 block + GAPM_USE_ENC_BLOCK = 0x19, + /// Generate a 8-byte random number + GAPM_GEN_RAND_NB = 0x1A, + + /* Profile Management */ + /* ************************************************ */ + /// Create new task for specific profile + GAPM_PROFILE_TASK_ADD = 0x1B, + + /* DEBUG */ + /* ************************************************ */ + /// Get memory usage + GAPM_DBG_GET_MEM_INFO = 0x1C, + /// Perform a platform reset + GAPM_PLF_RESET = 0x1D, + + /* Data Length Extension */ + /* ************************************************ */ + /// Set Suggested Default LE Data Length + GAPM_SET_SUGGESTED_DFLT_LE_DATA_LEN = 0x1E, + /// Get Suggested Default LE Data Length + GAPM_GET_SUGGESTED_DFLT_LE_DATA_LEN = 0x1F, + /// Get Maximum LE Data Length + GAPM_GET_MAX_LE_DATA_LEN = 0x20, + + /* Operation on Resolving List */ + /* ************************************************ */ + /// Get resolving address list size + GAPM_GET_RAL_SIZE = 0x21, + /// Get resolving local address + GAPM_GET_RAL_LOC_ADDR = 0x22, + /// Get resolving peer address + GAPM_GET_RAL_PEER_ADDR = 0x23, + + /* Change current IRK */ + /* ************************************************ */ + /// Set IRK + GAPM_SET_IRK = 0x28, + + /* LE Protocol/Service Multiplexer management */ + /* ************************************************ */ + /// Register a LE Protocol/Service Multiplexer + GAPM_LEPSM_REG = 0x29, + /// Unregister a LE Protocol/Service Multiplexer + GAPM_LEPSM_UNREG = 0x2A, + + /* LE Direct Test Mode */ + /* ************************************************ */ + /// Stop the test mode + GAPM_LE_TEST_STOP = 0x2B, + /// Start RX Test Mode + GAPM_LE_TEST_RX_START = 0x2C, + /// Start TX Test Mode + GAPM_LE_TEST_TX_START = 0x2D, + + /* Secure Connection */ + /* ************************************************ */ + /// Generate DH_Key + GAPM_GEN_DH_KEY = 0x2E, + /// Retrieve Public Key + GAPM_GET_PUB_KEY = 0x2F, + + /* List Management */ + /* ************************************************ */ + /// Set content of white list + GAPM_SET_WL = 0x90, + /// Set content of resolving list + GAPM_SET_RAL = 0x91, + /// Set content of periodic advertiser list + GAPM_SET_PAL = 0x92, + /// Get periodic advertiser list size + GAPM_GET_PAL_SIZE = 0x95, + + /* Air Operations */ + /* ************************************************ */ + /// Create advertising activity + GAPM_CREATE_ADV_ACTIVITY = 0xA0, + /// Create scanning activity + GAPM_CREATE_SCAN_ACTIVITY = 0xA1, + /// Create initiating activity + GAPM_CREATE_INIT_ACTIVITY = 0xA2, + /// Create periodic synchronization activity + GAPM_CREATE_PERIOD_SYNC_ACTIVITY = 0xA3, + /// Start an activity + GAPM_START_ACTIVITY = 0xA4, + /// Stop an activity + GAPM_STOP_ACTIVITY = 0xA5, + /// Stop all activities + GAPM_STOP_ALL_ACTIVITIES = 0xA6, + /// Delete an activity + GAPM_DELETE_ACTIVITY = 0xA7, + /// Delete all activities + GAPM_DELETE_ALL_ACTIVITIES = 0xA8, + /// Set advertising data + GAPM_SET_ADV_DATA = 0xA9, + /// Set scan response data + GAPM_SET_SCAN_RSP_DATA = 0xAA, + /// Set periodic advertising data + GAPM_SET_PERIOD_ADV_DATA = 0xAB, + /// Get number of available advertising sets + GAPM_GET_NB_ADV_SETS = 0xAC, + /// Get maximum advertising data length supported by the controller + GAPM_GET_MAX_LE_ADV_DATA_LEN = 0xAD, + /// Get minimum and maximum transmit powers supported by the controller + GAPM_GET_DEV_TX_PWR = 0xAE, + /// Get the RF Path Compensation values used in the TX Power Level and RSSI calculation + GAPM_GET_DEV_RF_PATH_COMP = 0xAF, + /// Enable/Disable reception of periodic advertising report + GAPM_PER_ADV_REPORT_CTRL = 0xB0, + /// Enable / Disable IQ sampling + GAPM_PER_SYNC_IQ_SAMPLING_CTRL = 0xB1, + /// Enable / Disable CTE transmission + GAPM_PER_ADV_CTE_TX_CTL = 0xB2, + + /* Debug Commands */ + /* ************************************************ */ + /// Configure the Debug Platform I&Q Sampling generator + GAPM_DBG_IQGEN_CFG = 0x50, + + /* Internal Operations */ + /* ************************************************ */ + /// Renew random addresses + GAPM_RENEW_ADDR = 0xF0, +}; + +/// Own BD address source of the device +enum gapm_own_addr +{ + /// Public or Private Static Address according to device address configuration + GAPM_STATIC_ADDR, + /// Generated resolvable private random address + GAPM_GEN_RSLV_ADDR, + /// Generated non-resolvable private random address + GAPM_GEN_NON_RSLV_ADDR, +}; + +/// Device Attribute write permission requirement +enum gapm_write_att_perm +{ + /// Disable write access + GAPM_WRITE_DISABLE = 0, + /// Enable write access - no authentication required + GAPM_WRITE_NO_AUTH = 1, + /// Write access requires unauthenticated link + GAPM_WRITE_UNAUTH = 2, + /// Write access requires authenticated link + GAPM_WRITE_AUTH = 3, + /// Write access requires secure connected link + GAPM_WRITE_SEC_CON = 4 +}; + +/// Attribute database configuration +/// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +/// +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ +/// | DBG|DBGT| RFU |RPAO|RFU |PCP | APP_PERM | NAME_PERM | +/// +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ +/// - Bit [0-2] : Device Name write permission requirements for peer device (@see gapm_write_att_perm) +/// - Bit [3-5] : Device Appearance write permission requirements for peer device (@see gapm_write_att_perm) +/// - Bit [6] : Slave Preferred Connection Parameters present +/// - Bit [7] : Reserved +/// - Bit [8] : Enable presence of Resolvable private address only. +/// - Bit [9-13]: Reserved +/// - Bit [14] : if Debug Mode enabled, forward all L2cap traffic to application +/// - Bit [15] : Enable Debug Mode +enum gapm_att_cfg_flag +{ + /// Device Name write permission requirements for peer device (@see gapm_write_att_perm) + GAPM_ATT_NAME_PERM_MASK = 0x0007, + GAPM_ATT_NAME_PERM_LSB = 0x00, + /// Device Appearance write permission requirements for peer device (@see gapm_write_att_perm) + GAPM_ATT_APPEARENCE_PERM_MASK = 0x0038, + GAPM_ATT_APPEARENCE_PERM_LSB = 0x03, + /// Slave Preferred Connection Parameters present in GAP attribute database. + GAPM_ATT_SLV_PREF_CON_PAR_EN_MASK = 0x0040, + GAPM_ATT_SLV_PREF_CON_PAR_EN_LSB = 0x06, + /// Enable presence of Resolvable private address only. + /// This means that after a bond, device must only use resolvable private address + GAPM_ATT_RSLV_PRIV_ADDR_ONLY_MASK = 0x0100, + GAPM_ATT_RSLV_PRIV_ADDR_ONLY_LSB = 0x08, + /// if Debug Mode enabled, forward all L2cap traffic to application + GAPM_ATT_DBG_L2CAP_TRAFFIC_EN_MASK = 0x4000, + GAPM_ATT_DBG_L2CAP_TRAFFIC_EN_LSB = 0x0E, + /// Enable Debug Mode + GAPM_ATT_DBG_MODE_EN_MASK = 0x8000, + GAPM_ATT_DBG_MODE_EN_LSB = 0x0F, +}; + +/// Pairing mode authorized on the device +/// 7 6 5 4 3 2 1 0 +/// +----+----+----+----+----+----+----+----+ +/// | RFU | SCP| LP | +/// +----+----+----+----+----+----+----+----+ +enum gapm_pairing_mode +{ + /// No pairing authorized + GAPM_PAIRING_DISABLE = 0, + /// Legacy pairing Authorized + GAPM_PAIRING_LEGACY = (1 << 0), + /// Secure Connection pairing Authorized + GAPM_PAIRING_SEC_CON = (1 << 1), +}; + +/// LE Audio Mode Configuration +/// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +/// +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ +/// | RFU | AM0| +/// +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ +enum gapm_audio_cfg_flag +{ + /// LE Audio Mode 0 Supported + GAPM_MASK_AUDIO_AM0_SUP = 0x0001, + GAPM_POS_AUDIO_AM0_SUP = 0x00, +}; + +/// Security level +/// 7 6 5 4 3 2 1 0 +/// +---+---+---+---+---+---+---+---+ +/// |MI | RFU |EKS|SEC_LVL| +/// +---+---+---+---+---+---+---+---+ +/// bit[0-1]: Security level requirement (0=NO_AUTH, 1=UNAUTH, 2=AUTH, 3=SEC_CON) +/// bit[2] : Encryption Key Size length must have 16 bytes +/// bit[7] : Multi-instantiated task +enum gapm_le_psm_sec_mask +{ + /// bit[0-1]: Security level requirement (0=NO_AUTH, 1=UNAUTH, 2=AUTH, 3=SEC_CON) + /// bit[2] : Encryption Key Size length must have 16 bytes + GAPM_LE_PSM_SEC_LVL_MASK = 0x07, + /// bit[7] : Multi-instantiated task + GAPM_LE_PSM_MI_TASK_MASK = 0x80, +}; + +/// Type of activities that can be created +/*@TRACE*/ +enum gapm_actv_type +{ + /// Advertising activity + GAPM_ACTV_TYPE_ADV = 0, + /// Scanning activity + GAPM_ACTV_TYPE_SCAN, + /// Initiating activity + GAPM_ACTV_TYPE_INIT, + /// Periodic synchronization activity + GAPM_ACTV_TYPE_PER_SYNC, +}; + +/// Type of advertising that can be created +enum gapm_adv_type +{ + /// Legacy advertising + GAPM_ADV_TYPE_LEGACY = 0, + /// Extended advertising + GAPM_ADV_TYPE_EXTENDED, + /// Periodic advertising + GAPM_ADV_TYPE_PERIODIC, +}; + +/// Advertising report type +enum gapm_adv_report_type +{ + /// Extended advertising report + GAPM_REPORT_TYPE_ADV_EXT = 0, + /// Legacy advertising report + GAPM_REPORT_TYPE_ADV_LEG, + /// Extended scan response report + GAPM_REPORT_TYPE_SCAN_RSP_EXT, + /// Legacy scan response report + GAPM_REPORT_TYPE_SCAN_RSP_LEG, + /// Periodic advertising report + GAPM_REPORT_TYPE_PER_ADV, +}; + +/// Advertising properties bit field bit positions +enum gapm_adv_prop_bf +{ + /// Indicate that advertising is connectable, reception of CONNECT_REQ or AUX_CONNECT_REQ + /// PDUs is accepted. Not applicable for periodic advertising. + GAPM_ADV_PROP_CONNECTABLE_POS = 0, + GAPM_ADV_PROP_CONNECTABLE_BIT = CO_BIT(GAPM_ADV_PROP_CONNECTABLE_POS), + + /// Indicate that advertising is scannable, reception of SCAN_REQ or AUX_SCAN_REQ PDUs is + /// accepted + GAPM_ADV_PROP_SCANNABLE_POS = 1, + GAPM_ADV_PROP_SCANNABLE_BIT = CO_BIT(GAPM_ADV_PROP_SCANNABLE_POS), + + /// Indicate that advertising targets a specific device. Only apply in following cases: + /// - Legacy advertising: if connectable + /// - Extended advertising: connectable or (non connectable and non discoverable) + GAPM_ADV_PROP_DIRECTED_POS = 2, + GAPM_ADV_PROP_DIRECTED_BIT = CO_BIT(GAPM_ADV_PROP_DIRECTED_POS), + + /// Indicate that High Duty Cycle has to be used for advertising on primary channel + /// Apply only if created advertising is not an extended advertising + GAPM_ADV_PROP_HDC_POS = 3, + GAPM_ADV_PROP_HDC_BIT = CO_BIT(GAPM_ADV_PROP_HDC_POS), + + /// Bit 4 is reserved + GAPM_ADV_PROP_RESERVED_4_POS = 4, + GAPM_ADV_PROP_RESERVED_4_BIT = CO_BIT(GAPM_ADV_PROP_RESERVED_4_POS), + + /// Enable anonymous mode. Device address won't appear in send PDUs + /// Valid only if created advertising is an extended advertising + GAPM_ADV_PROP_ANONYMOUS_POS = 5, + GAPM_ADV_PROP_ANONYMOUS_BIT = CO_BIT(GAPM_ADV_PROP_ANONYMOUS_POS), + + /// Include TX Power in the extended header of the advertising PDU. + /// Valid only if created advertising is not a legacy advertising + GAPM_ADV_PROP_TX_PWR_POS = 6, + GAPM_ADV_PROP_TX_PWR_BIT = CO_BIT(GAPM_ADV_PROP_TX_PWR_POS), + + /// Include TX Power in the periodic advertising PDU. + /// Valid only if created advertising is a periodic advertising + GAPM_ADV_PROP_PER_TX_PWR_POS = 7, + GAPM_ADV_PROP_PER_TX_PWR_BIT = CO_BIT(GAPM_ADV_PROP_PER_TX_PWR_POS), + + /// Indicate if application must be informed about received scan requests PDUs + GAPM_ADV_PROP_SCAN_REQ_NTF_EN_POS = 8, + GAPM_ADV_PROP_SCAN_REQ_NTF_EN_BIT = CO_BIT(GAPM_ADV_PROP_SCAN_REQ_NTF_EN_POS), +}; + +/// Advertising discovery mode +enum gapm_adv_disc_mode +{ + /// Mode in non-discoverable + GAPM_ADV_MODE_NON_DISC = 0, + /// Mode in general discoverable + GAPM_ADV_MODE_GEN_DISC, + /// Mode in limited discoverable + GAPM_ADV_MODE_LIM_DISC, + /// Broadcast mode without presence of AD_TYPE_FLAG in advertising data + GAPM_ADV_MODE_BEACON, + GAPM_ADV_MODE_MAX, +}; + +/// Scanning Types +enum gapm_scan_type +{ + /// General discovery + GAPM_SCAN_TYPE_GEN_DISC = 0, + /// Limited discovery + GAPM_SCAN_TYPE_LIM_DISC, + /// Observer + GAPM_SCAN_TYPE_OBSERVER, + /// Selective observer + GAPM_SCAN_TYPE_SEL_OBSERVER, + /// Connectable discovery + GAPM_SCAN_TYPE_CONN_DISC, + /// Selective connectable discovery + GAPM_SCAN_TYPE_SEL_CONN_DISC, +}; + +/// Scanning properties bit field bit value +enum gapm_scan_prop +{ + /// Scan advertisement on the LE 1M PHY + GAPM_SCAN_PROP_PHY_1M_BIT = (1 << 0), + /// Scan advertisement on the LE Coded PHY + GAPM_SCAN_PROP_PHY_CODED_BIT = (1 << 1), + /// Active scan on LE 1M PHY (Scan Request PDUs may be sent) + GAPM_SCAN_PROP_ACTIVE_1M_BIT = (1 << 2), + /// Active scan on LE Coded PHY (Scan Request PDUs may be sent) + GAPM_SCAN_PROP_ACTIVE_CODED_BIT = (1 << 3), + /// Accept directed advertising packets if we use a RPA and target address cannot be solved by the + /// controller + GAPM_SCAN_PROP_ACCEPT_RPA_BIT = (1 << 4), + /// Filter truncated advertising or scan response reports + GAPM_SCAN_PROP_FILT_TRUNC_BIT = (1 << 5), +}; + +/// Initiating Types +enum gapm_init_type +{ + /// Direct connection establishment, establish a connection with an indicated device + GAPM_INIT_TYPE_DIRECT_CONN_EST = 0, + /// Automatic connection establishment, establish a connection with all devices whose address is + /// present in the white list + GAPM_INIT_TYPE_AUTO_CONN_EST, + /// Name discovery, Establish a connection with an indicated device in order to read content of its + /// Device Name characteristic. Connection is closed once this operation is stopped. + GAPM_INIT_TYPE_NAME_DISC, +}; + +/// Initiating Properties +enum gapm_init_prop +{ + /// Scan connectable advertisements on the LE 1M PHY. Connection parameters for the LE 1M PHY are provided + GAPM_INIT_PROP_1M_BIT = (1 << 0), + /// Connection parameters for the LE 2M PHY are provided + GAPM_INIT_PROP_2M_BIT = (1 << 1), + /// Scan connectable advertisements on the LE Coded PHY. Connection parameters for the LE Coded PHY are provided + GAPM_INIT_PROP_CODED_BIT = (1 << 2), +}; + +/// Advertising report information +enum gapm_adv_report_info +{ + /// Report Type + GAPM_REPORT_INFO_REPORT_TYPE_MASK = 0x07, + /// Report is complete + GAPM_REPORT_INFO_COMPLETE_BIT = (1 << 3), + /// Connectable advertising + GAPM_REPORT_INFO_CONN_ADV_BIT = (1 << 4), + /// Scannable advertising + GAPM_REPORT_INFO_SCAN_ADV_BIT = (1 << 5), + /// Directed advertising + GAPM_REPORT_INFO_DIR_ADV_BIT = (1 << 6), +}; + +/// Filtering policy for duplicated packets +enum gapm_dup_filter_pol +{ + /// Disable filtering of duplicated packets + GAPM_DUP_FILT_DIS = 0, + /// Enable filtering of duplicated packets + GAPM_DUP_FILT_EN, + /// Enable filtering of duplicated packets, reset for each scan period + GAPM_DUP_FILT_EN_PERIOD, +}; + +/// Periodic synchronization types +enum gapm_per_sync_type +{ + /// Do not use periodic advertiser list for synchronization. Use advertiser information provided + /// in the GAPM_ACTIVITY_START_CMD. + GAPM_PER_SYNC_TYPE_GENERAL = 0, + /// Use periodic advertiser list for synchronization + GAPM_PER_SYNC_TYPE_SELECTIVE, + /// Use Periodic advertising sync transfer information send through connection for synchronization + GAPM_PER_SYNC_TYPE_PAST, +}; + +/// PHY Type +enum gapm_phy_type +{ + /// LE 1M + GAPM_PHY_TYPE_LE_1M = 0, + /// LE 2M + GAPM_PHY_TYPE_LE_2M, + /// LE Coded + GAPM_PHY_TYPE_LE_CODED, +}; + +/// ------------------------------------------------------------------------------------- +/// Masks for advertising properties +/// ------------------------------------------------------------------------------------- + +/// Advertising properties configurations for legacy advertising +enum gapm_leg_adv_prop +{ + /// Non connectable non scannable advertising + GAPM_ADV_PROP_NON_CONN_NON_SCAN_MASK = 0x0000, + /// Broadcast non scannable advertising - Discovery mode must be Non Discoverable + GAPM_ADV_PROP_BROADCAST_NON_SCAN_MASK = GAPM_ADV_PROP_NON_CONN_NON_SCAN_MASK, + /// Non connectable scannable advertising + GAPM_ADV_PROP_NON_CONN_SCAN_MASK = GAPM_ADV_PROP_SCANNABLE_BIT, + /// Broadcast non scannable advertising - Discovery mode must be Non Discoverable + GAPM_ADV_PROP_BROADCAST_SCAN_MASK = GAPM_ADV_PROP_NON_CONN_SCAN_MASK, + /// Undirected connectable advertising + GAPM_ADV_PROP_UNDIR_CONN_MASK = GAPM_ADV_PROP_CONNECTABLE_BIT | GAPM_ADV_PROP_SCANNABLE_BIT, + /// Directed connectable advertising + GAPM_ADV_PROP_DIR_CONN_MASK = GAPM_ADV_PROP_DIRECTED_BIT | GAPM_ADV_PROP_CONNECTABLE_BIT, + /// Directed connectable with Low Duty Cycle + GAPM_ADV_PROP_DIR_CONN_LDC_MASK = GAPM_ADV_PROP_DIR_CONN_MASK, + /// Directed connectable with High Duty Cycle + GAPM_ADV_PROP_DIR_CONN_HDC_MASK = GAPM_ADV_PROP_DIR_CONN_MASK | GAPM_ADV_PROP_HDC_BIT, +}; + +/// Advertising properties configurations for extended advertising +enum gapm_ext_adv_prop +{ + /// Non connectable non scannable extended advertising + GAPM_EXT_ADV_PROP_NON_CONN_NON_SCAN_MASK = 0x0000, + /// Non connectable scannable extended advertising + GAPM_EXT_ADV_PROP_NON_CONN_SCAN_MASK = GAPM_ADV_PROP_SCANNABLE_BIT, + /// Non connectable scannable directed extended advertising + GAPM_EXT_ADV_PROP_NON_CONN_SCAN_DIR_MASK = GAPM_ADV_PROP_SCANNABLE_BIT | GAPM_ADV_PROP_DIRECTED_BIT, + /// Non connectable anonymous directed extended advertising + GAPM_EXT_ADV_PROP_ANONYM_DIR_MASK = GAPM_ADV_PROP_ANONYMOUS_BIT | GAPM_ADV_PROP_DIRECTED_BIT, + /// Undirected connectable extended advertising + GAPM_EXT_ADV_PROP_UNDIR_CONN_MASK = GAPM_ADV_PROP_CONNECTABLE_BIT, + /// Directed connectable extended advertising + GAPM_EXT_ADV_PROP_DIR_CONN_MASK = GAPM_ADV_PROP_CONNECTABLE_BIT | GAPM_ADV_PROP_DIRECTED_BIT, +}; + +/// Advertising properties configurations for periodic advertising +enum gapm_per_adv_prop +{ + /// Undirected periodic advertising + GAPM_PER_ADV_PROP_UNDIR_MASK = 0x0000, + /// Directed periodic advertising + GAPM_PER_ADV_PROP_DIR_MASK = GAPM_ADV_PROP_DIRECTED_BIT, +}; + +/// Clock accuracy values +enum gapm_clk_acc +{ + /// 500 ppm + GAPM_CLK_ACC_500 = 0, + /// 250 ppm + GAPM_CLK_ACC_250, + /// 150 ppm + GAPM_CLK_ACC_150, + /// 100 ppm + GAPM_CLK_ACC_100, + /// 75 ppm + GAPM_CLK_ACC_75, + /// 50 ppm + GAPM_CLK_ACC_50, + /// 30 ppm + GAPM_CLK_ACC_30, + /// 20 ppm + GAPM_CLK_ACC_20, +}; + +/// Privacy configuration +enum gapm_priv_cfg +{ + /// Indicate if identity address is a public (0) or static private random (1) address + GAPM_PRIV_CFG_PRIV_ADDR_BIT = (1 << 0), + GAPM_PRIV_CFG_PRIV_ADDR_POS = 0, + /// Reserved + GAPM_PRIV_CFG_RSVD = (1 << 1), + /// Indicate if controller privacy is enabled + GAPM_PRIV_CFG_PRIV_EN_BIT = (1 << 2), + GAPM_PRIV_CFG_PRIV_EN_POS = 2, +}; + +/// Constant Tone Extension sync filtering type +enum gapm_sync_cte_type +{ + /// Do not sync to packets with an AoA Constant Tone Extension + GAPM_CTE_NO_SYNC_WITH_AOA = (1 << 0), + /// Do not sync to packets with an AoD Constant Tone Extension with 1 us slots + GAPM_CTE_NO_SYNC_WITH_AOD_1US_SLOT = (1 << 1), + /// Do not sync to packets with an AoD Constant Tone Extension with 2 us slots + GAPM_CTE_NO_SYNC_WITH_AOD_2US_SLOT = (1 << 2), + /// Do not sync to packets with a type 3 Constant Tone Extension (currently reserved for future use) + GAPM_CTE_NO_SYNC_WITH_TYPE_3 = (1 << 3), + /// Do not sync to packets without a Constant Tone Extension + GAPM_CTE_NO_SYNC_WITHOUT_CTE = (1 << 4), +}; + +/// Supported AoA AoD switching sampling rate +enum gapm_switch_sampling_rate +{ + /// 1 us switching supported for AoD transmission + GAPM_AOD_TX_1_US = (1 << 0), + /// 1 us sampling supported for AoD reception + GAPM_AOD_RX_1_US = (1 << 1), + /// 1 us switching and sampling supported for AoA reception + GAPM_AOA_RX_1_US = (1 << 2), +}; + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Configuration for advertising on primary channel +/*@TRACE*/ +struct gapm_adv_prim_cfg +{ + /// Minimum advertising interval (in unit of 625us). Must be greater than 20ms + uint32_t adv_intv_min; + /// Maximum advertising interval (in unit of 625us). Must be greater than 20ms + uint32_t adv_intv_max; + /// Bit field indicating the channel mapping + uint8_t chnl_map; + /// Indicate on which PHY primary advertising has to be performed (@see enum gapm_phy_type) + /// Note that LE 2M PHY is not allowed and that legacy advertising only support LE 1M PHY + uint8_t phy; +}; + +/// Configuration for advertising on secondary channel +/*@TRACE*/ +struct gapm_adv_second_cfg +{ + /// Maximum number of advertising events the controller can skip before sending the + /// AUX_ADV_IND packets. 0 means that AUX_ADV_IND PDUs shall be sent prior each + /// advertising events + uint8_t max_skip; + /// Indicate on which PHY secondary advertising has to be performed (@see enum gapm_phy_type) + uint8_t phy; + /// Advertising SID + uint8_t adv_sid; +}; + +/// Configuration for periodic advertising +/*@TRACE*/ +struct gapm_adv_period_cfg +{ + /// Minimum advertising interval (in unit of 1.25ms). Must be greater than 20ms + uint16_t adv_intv_min; + /// Maximum advertising interval (in unit of 1.25ms). Must be greater than 20ms + uint16_t adv_intv_max; + /// CTE count (number of CTEs to transmit in each periodic advertising interval, range 0x01 to 0x10) + /// 0 to disable CTE transmission + uint8_t cte_count; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) (@see enum gap_cte_type) + uint8_t cte_type; + /// CTE length (in 8us unit) + uint8_t cte_len; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[__ARRAY_EMPTY]; +}; + +/// Advertising parameters for advertising creation +/*@TRACE*/ +struct gapm_adv_create_param +{ + /// Advertising type (@see enum gapm_adv_type) + uint8_t type; + /// Discovery mode (@see enum gapm_adv_disc_mode) + uint8_t disc_mode; + /// Bit field value provided advertising properties (@see enum gapm_adv_prop for bit signification) + uint16_t prop; + /// Maximum power level at which the advertising packets have to be transmitted + /// (between -127 and 126 dBm) + int8_t max_tx_pwr; + /// Advertising filtering policy (@see enum adv_filter_policy) + uint8_t filter_pol; + /// Peer address configuration (only used in case of directed advertising) + struct gap_bdaddr peer_addr; + /// Configuration for primary advertising + struct gapm_adv_prim_cfg prim_cfg; + /// Configuration for secondary advertising (valid only if advertising type is + /// GAPM_ADV_TYPE_EXTENDED or GAPM_ADV_TYPE_PERIODIC) + struct gapm_adv_second_cfg second_cfg; + /// Configuration for periodic advertising (valid only if advertising type os + /// GAPM_ADV_TYPE_PERIODIC) + struct gapm_adv_period_cfg period_cfg; +}; + +/// Additional advertising parameters +/*@TRACE*/ +struct gapm_adv_param +{ + /// Advertising duration (in unit of 10ms). 0 means that advertising continues + /// until the host disable it + uint16_t duration; + /// Maximum number of extended advertising events the controller shall attempt to send prior to + /// terminating the extending advertising + /// Valid only if extended advertising + uint8_t max_adv_evt; +}; + +/// Scan Window operation parameters +/*@TRACE*/ +struct gapm_scan_wd_op_param +{ + /// Scan interval + uint16_t scan_intv; + /// Scan window + uint16_t scan_wd; +}; + +/// Scanning parameters +/*@TRACE*/ +struct gapm_scan_param +{ + /// Type of scanning to be started (@see enum gapm_scan_type) + uint8_t type; + /// Properties for the scan procedure (@see enum gapm_scan_prop for bit signification) + uint8_t prop; + /// Duplicate packet filtering policy + uint8_t dup_filt_pol; + /// Reserved for future use + uint8_t rsvd; + /// Scan window opening parameters for LE 1M PHY + struct gapm_scan_wd_op_param scan_param_1m; + /// Scan window opening parameters for LE Coded PHY + struct gapm_scan_wd_op_param scan_param_coded; + /// Scan duration (in unit of 10ms). 0 means that the controller will scan continuously until + /// reception of a stop command from the application + uint16_t duration; + /// Scan period (in unit of 1.28s). Time interval betweem two consequent starts of a scan duration + /// by the controller. 0 means that the scan procedure is not periodic + uint16_t period; +}; + +/// Connection parameters +/*@TRACE*/ +struct gapm_conn_param +{ + /// Minimum value for the connection interval (in unit of 1.25ms). Shall be less than or equal to + /// conn_intv_max value. Allowed range is 7.5ms to 4s. + uint16_t conn_intv_min; + /// Maximum value for the connection interval (in unit of 1.25ms). Shall be greater than or equal to + /// conn_intv_min value. Allowed range is 7.5ms to 4s. + uint16_t conn_intv_max; + /// Slave latency. Number of events that can be missed by a connected slave device + uint16_t conn_latency; + /// Link supervision timeout (in unit of 10ms). Allowed range is 100ms to 32s + uint16_t supervision_to; + /// Recommended minimum duration of connection events (in unit of 625us) + uint16_t ce_len_min; + /// Recommended maximum duration of connection events (in unit of 625us) + uint16_t ce_len_max; +}; + +/// Initiating parameters +/*@TRACE*/ +struct gapm_init_param +{ + /// Initiating type (@see enum gapm_init_type) + uint8_t type; + /// Properties for the initiating procedure (@see enum gapm_init_prop for bit signification) + uint8_t prop; + /// Timeout for automatic connection establishment (in unit of 10ms). Cancel the procedure if not all + /// indicated devices have been connected when the timeout occurs. 0 means there is no timeout + uint16_t conn_to; + /// Scan window opening parameters for LE 1M PHY + struct gapm_scan_wd_op_param scan_param_1m; + /// Scan window opening parameters for LE Coded PHY + struct gapm_scan_wd_op_param scan_param_coded; + /// Connection parameters for LE 1M PHY + struct gapm_conn_param conn_param_1m; + /// Connection parameters for LE 2M PHY + struct gapm_conn_param conn_param_2m; + /// Connection parameters for LE Coded PHY + struct gapm_conn_param conn_param_coded; + /// Address of peer device in case white list is not used for connection + struct gap_bdaddr peer_addr; +}; + +/// Periodic advertising information +/*@TRACE*/ +struct gapm_period_adv_addr_cfg +{ + /// Advertiser address information + struct gap_bdaddr addr; + /// Advertising SID + uint8_t adv_sid; +}; + +/// Periodic synchronization parameters +/*@TRACE*/ +struct gapm_per_sync_param +{ + /// Number of periodic advertising that can be skipped after a successful receive. Maximum authorized + /// value is 499 + uint16_t skip; + /// Synchronization timeout for the periodic advertising (in unit of 10ms between 100ms and 163.84s) + uint16_t sync_to; + /// Periodic synchronization type (@see enum gapm_per_sync_type) + uint8_t type; + /// Connection index used for periodic sync info reception (only valid for GAPM_PER_SYNC_TYPE_PAST) + uint8_t conidx; + /// Address of advertiser with which synchronization has to be established (used only if use_pal is false) + struct gapm_period_adv_addr_cfg adv_addr; + /// 1 to disable periodic advertising report, 0 to enable them by default + uint8_t report_disable; + /// Type of Constant Tone Extension device should sync on (@see enum gapm_sync_cte_type). + uint8_t cte_type; +}; + +/// Operation command structure in order to keep requested operation. +struct gapm_operation_cmd +{ + /// GAP request type + uint8_t operation; +}; + +/// Command complete event data structure +/*@TRACE*/ +struct gapm_cmp_evt +{ + /// GAP requested operation + uint8_t operation; + /// Status of the request + uint8_t status; +}; + +/// Reset link layer and the host command +/*@TRACE*/ +struct gapm_reset_cmd +{ + /// GAPM requested operation: + /// - GAPM_RESET: Reset BLE subsystem: LL and HL. + uint8_t operation; +}; + +/// Set device configuration command +/*@TRACE*/ +struct gapm_set_dev_config_cmd +{ + /// GAPM requested operation: + /// - GAPM_SET_DEV_CONFIG: Set device configuration + uint8_t operation; + /// Device Role: Central, Peripheral, Observer, Broadcaster or All roles. + uint8_t role; + + /// -------------- Privacy Config ----------------------- + /// Duration before regenerate device address when privacy is enabled. - in seconds + uint16_t renew_dur; + /// Provided own static private random address + bd_addr_t addr; + /// Device IRK used for resolvable random BD address generation (LSB first) + struct gap_sec_key irk; + /// Privacy configuration bit field (@see enum gapm_priv_cfg for bit signification) + uint8_t privacy_cfg; + + /// -------------- Security Config ----------------------- + + /// Pairing mode authorized (@see enum gapm_pairing_mode) + uint8_t pairing_mode; + + /// -------------- ATT Database Config ----------------------- + + /// GAP service start handle + uint16_t gap_start_hdl; + /// GATT service start handle + uint16_t gatt_start_hdl; + + /// Attribute database configuration (@see enum gapm_att_cfg_flag) + uint16_t att_cfg; + + /// -------------- LE Data Length Extension ----------------------- + ///Suggested value for the Controller's maximum transmitted number of payload octets to be used + uint16_t sugg_max_tx_octets; + ///Suggested value for the Controller's maximum packet transmission time to be used + uint16_t sugg_max_tx_time; + + /// --------------- L2CAP Configuration --------------------------- + /// Maximal MTU acceptable for device + uint16_t max_mtu; + /// Maximal MPS Packet size acceptable for device + uint16_t max_mps; + /// Maximum number of LE Credit based connection that can be established + uint8_t max_nb_lecb; + + /// --------------- LE Audio Mode Supported ----------------------- + /// + /// LE Audio Mode Configuration (@see gapm_audio_cfg_flag) + uint16_t audio_cfg; + + /// ------------------ LE PHY Management ------------------------- + /// Preferred LE PHY for data transmission (@see enum gap_phy) + uint8_t tx_pref_phy; + /// Preferred LE PHY for data reception (@see enum gap_phy) + uint8_t rx_pref_phy; + + /// ------------------ Miscellaneous 2 ---------------------------- + /// RF TX Path Compensation value (from -128dB to 128dB, unit is 0.1dB) + uint16_t tx_path_comp; + /// RF RX Path Compensation value (from -128dB to 128dB, unit is 0.1dB) + uint16_t rx_path_comp; +}; + +/// Set new IRK +/*@TRACE*/ +struct gapm_set_irk_cmd +{ + /// GAPM requested operation: + /// - GAPM_SET_IRK: Set device configuration + uint8_t operation; + /// Device IRK used for resolvable random BD address generation (LSB first) + struct gap_sec_key irk; +}; + +/// Set device channel map +/*@TRACE*/ +struct gapm_set_channel_map_cmd +{ + /// GAPM requested operation: + /// - GAPM_SET_CHANNEL_MAP: Set device channel map. + /// - GAPM_GET_SUGGESTED_DFLT_LE_DATA_LEN: Get Suggested Default LE Data Length + /// - GAPM_GET_MAX_LE_DATA_LEN: Get Maximum LE Data Length + /// - GAPM_GET_NB_ADV_SETS: Read number of advertising sets currently supported by the controller + /// - GAPM_GET_MAX_LE_ADV_DATA_LEN: Get maximum data length for advertising data + + /// + /// - GAPM_GET_ANTENNA_INFO: + uint8_t operation; + /// Channel map + le_chnl_map_t chmap; +}; + +/// Get local device info command +/*@TRACE*/ +struct gapm_get_dev_info_cmd +{ + /// GAPM requested operation: + /// - GAPM_GET_DEV_VERSION: Get Local device version + /// - GAPM_GET_DEV_BDADDR: Get Local device BD Address + /// - GAPM_GET_DEV_ADV_TX_POWER: Get device advertising power level + /// - GAPM_DBG_GET_MEM_INFO: Get memory usage (debug only) + uint8_t operation; +}; + +/// Local device version indication event +/*@TRACE*/ +struct gapm_dev_version_ind +{ + /// HCI version + uint8_t hci_ver; + /// LMP version + uint8_t lmp_ver; + /// Host version + uint8_t host_ver; + /// HCI revision + uint16_t hci_subver; + /// LMP subversion + uint16_t lmp_subver; + /// Host revision + uint16_t host_subver; + /// Manufacturer name + uint16_t manuf_name; +}; + +/// Local device BD Address indication event +/*@TRACE*/ +struct gapm_dev_bdaddr_ind +{ + /// Local device address information + struct gap_bdaddr addr; + /// Activity index + uint8_t actv_idx; +}; + +/// Advertising channel Tx power level indication event +/*@TRACE*/ +struct gapm_dev_adv_tx_power_ind +{ + /// Advertising channel Tx power level + int8_t power_lvl; +}; + + +/// Indication containing controller antenna information +/*@TRACE*/ +struct gapm_antenna_inf_ind +{ + /// Supported switching sampling rates bit field (@see enum gapm_switch_sampling_rate) + uint8_t supp_switching_sampl_rates; + /// Number of antennae + uint8_t antennae_num; + /// Max length of switching pattern (number of antenna IDs in the pattern) + uint8_t max_switching_pattern_len; + /// Max CTE length + uint8_t max_cte_len; +}; + +/// Resolving Address indication event +/*@TRACE*/ +struct gapm_ral_addr_ind +{ + /// Peer or local read operation + uint8_t operation; + /// Resolving List address + struct gap_bdaddr addr; +}; + +/// Resolve Address command +/*@TRACE*/ +struct gapm_resolv_addr_cmd +{ + /// GAPM requested operation: + /// - GAPM_RESOLV_ADDR: Resolve device address + uint8_t operation; + /// Number of provided IRK (sahlle be > 0) + uint8_t nb_key; + /// Resolvable random address to solve + bd_addr_t addr; + /// Array of IRK used for address resolution (MSB -> LSB) + struct gap_sec_key irk[__ARRAY_EMPTY]; +}; + +/// Indicate that resolvable random address has been solved +/*@TRACE*/ +struct gapm_addr_solved_ind +{ + /// Resolvable random address solved + bd_addr_t addr; + /// IRK that correctly solved the random address + struct gap_sec_key irk; +}; + +/// Name of peer device indication +/*@TRACE*/ +struct gapm_peer_name_ind +{ + /// peer device bd address + bd_addr_t addr; + /// peer device address type + uint8_t addr_type; + /// peer device name length + uint8_t name_len; + /// peer device name + uint8_t name[__ARRAY_EMPTY]; +}; + +/// Generate a random address. +/*@TRACE*/ +struct gapm_gen_rand_addr_cmd +{ + /// GAPM requested operation: + /// - GAPM_GEN_RAND_ADDR: Generate a random address + uint8_t operation; + /// Dummy parameter used to store the prand part of the address + uint8_t prand[GAP_ADDR_PRAND_LEN]; + /// Random address type @see gap_rnd_addr_type + /// - BD_ADDR_STATIC: Static random address + /// - BD_ADDR_NON_RSLV: Private non resolvable address + /// - BD_ADDR_RSLV: Private resolvable address + uint8_t rnd_type; +}; + +/// Parameters of the @ref GAPM_USE_ENC_BLOCK_CMD message +/*@TRACE*/ +struct gapm_use_enc_block_cmd +{ + /// Command Operation Code (shall be GAPM_USE_ENC_BLOCK) + uint8_t operation; + /// Operand 1 + uint8_t operand_1[GAP_KEY_LEN]; + /// Operand 2 + uint8_t operand_2[GAP_KEY_LEN]; +}; + +/// Parameters of the @ref GAPM_USE_ENC_BLOCK_IND message +/*@TRACE*/ +struct gapm_use_enc_block_ind +{ + /// Result (16 bytes) + uint8_t result[GAP_KEY_LEN]; +}; + +/// Parameters of the @ref GAPM_GEN_DH_KEY_CMD message +/*@TRACE*/ +struct gapm_gen_dh_key_cmd +{ + /// Command Operation Code (shall be GAPM_GEN_DH_KEY) + uint8_t operation; + /// X coordinate + uint8_t operand_1[GAP_P256_KEY_LEN]; + /// Y coordinate + uint8_t operand_2[GAP_P256_KEY_LEN]; +}; + +/// Parameters of the @ref GAPM_GEN_DH_KEY_IND message +/*@TRACE*/ +struct gapm_gen_dh_key_ind +{ + /// Result (32 bytes) + uint8_t result[GAP_P256_KEY_LEN]; +}; + +/// Parameters of the @ref GAPM_GET_PUB_KEY_CMD message +/*@TRACE*/ +struct gapm_get_pub_key_cmd +{ + /// Command Operation Code (shall be GAPM_GET_PUB_KEY) + uint8_t operation; +}; + +/// Parameters of the @ref GAPM_PUB_KEY_IND message +/*@TRACE*/ +struct gapm_pub_key_ind +{ + /// X coordinate + uint8_t pub_key_x[GAP_P256_KEY_LEN]; + /// Y coordinate + uint8_t pub_key_y[GAP_P256_KEY_LEN]; +}; + +/// Parameters of the @ref GAPM_GEN_RAND_NB_CMD message +/*@TRACE*/ +struct gapm_gen_rand_nb_cmd +{ + /// Command Operation Code (shall be GAPM_GEN_RAND_NB) + uint8_t operation; +}; + +/// Parameters of the @ref GAPM_GEN_RAND_NB_IND message +/*@TRACE*/ +struct gapm_gen_rand_nb_ind +{ + /// Generation Random Number (8 bytes) + rand_nb_t randnb; +}; + +/// Create new task for specific profile +/*@TRACE*/ +struct gapm_profile_task_add_cmd +{ + /// GAPM requested operation: + /// - GAPM_PROFILE_TASK_ADD: Add new profile task + uint8_t operation; + /// Security Level : + /// 7 6 5 4 3 2 1 0 + /// +----+----+----+----+----+----+----+----+ + /// | Reserved |DIS | AUTH |EKS | MI | + /// +----+----+----+----+----+----+----+----+ + /// + /// - MI: 1 - Application task is a Multi-Instantiated task, 0 - Mono-Instantiated + /// Only applies for service - Ignored by collectors: + /// - EKS: Service needs a 16 bytes encryption key + /// - AUTH: 0 - Disable, 1 - Enable, 2 - Unauth, 3 - Auth + /// - DIS: Disable the service + uint8_t sec_lvl; + /// Profile task identifier + uint16_t prf_task_id; + /// Application task number + uint16_t app_task; + /// Service start handle + /// Only applies for services - Ignored by collectors + /// 0: dynamically allocated in Attribute database + uint16_t start_hdl; + /// 32 bits value that contains value to initialize profile (database parameters, etc...) + uint32_t param[__ARRAY_EMPTY]; +}; + +/// Inform that profile task has been added. +/*@TRACE*/ +struct gapm_profile_added_ind +{ + /// Profile task identifier + uint16_t prf_task_id; + /// Profile task number allocated + uint16_t prf_task_nb; + /// Service start handle + /// Only applies for services - Ignored by collectors + uint16_t start_hdl; +}; + +/// Indicate that a message has been received on an unknown task +/*@TRACE*/ +struct gapm_unknown_task_ind +{ + /// Message identifier + uint16_t msg_id; + /// Task identifier + uint16_t task_id; +}; + +/// Indicates suggested default data length +/*@TRACE*/ +struct gapm_sugg_dflt_data_len_ind +{ + ///Host's suggested value for the Controller's maximum transmitted number of payload octets + uint16_t suggted_max_tx_octets; + ///Host's suggested value for the Controller's maximum packet transmission time + uint16_t suggted_max_tx_time; +}; + +/// Indicates maximum data length +/*@TRACE*/ +struct gapm_max_data_len_ind +{ + ///Maximum number of payload octets that the local Controller supports for transmission + uint16_t suppted_max_tx_octets; + ///Maximum time, in microseconds, that the local Controller supports for transmission + uint16_t suppted_max_tx_time; + ///Maximum number of payload octets that the local Controller supports for reception + uint16_t suppted_max_rx_octets; + ///Maximum time, in microseconds, that the local Controller supports for reception + uint16_t suppted_max_rx_time; +}; + +/// Register a LE Protocol/Service Multiplexer command +/*@TRACE*/ +struct gapm_lepsm_register_cmd +{ + /// GAPM requested operation: + /// - GAPM_LEPSM_REG: Register a LE Protocol/Service Multiplexer + uint8_t operation; + /// LE Protocol/Service Multiplexer + uint16_t le_psm; + /// Application task number + uint16_t app_task; + /// Security level + /// 7 6 5 4 3 2 1 0 + /// +---+---+---+---+---+---+---+---+ + /// |MI | RFU |EKS|SEC_LVL| + /// +---+---+---+---+---+---+---+---+ + /// bit[0-1]: Security level requirement (0=NO_AUTH, 1=UNAUTH, 2=AUTH, 3=SEC_CON) + /// bit[2] : Encryption Key Size length must have 16 bytes + /// bit[7] : Does the application task is multi-instantiated or not + uint8_t sec_lvl; +}; + +/// Unregister a LE Protocol/Service Multiplexer command +/*@TRACE*/ +struct gapm_lepsm_unregister_cmd +{ + /// GAPM requested operation: + /// - GAPM_LEPSM_UNREG: Unregister a LE Protocol/Service Multiplexer + uint8_t operation; + /// LE Protocol/Service Multiplexer + uint16_t le_psm; +}; + +/// Control LE Test Mode command +struct gapm_le_test_mode_ctrl_cmd +{ + /// GAPM requested operation: + /// - GAPM_LE_TEST_STOP: Unregister a LE Protocol/Service Multiplexer + /// - GAPM_LE_TEST_RX_START: Start RX Test Mode + /// - GAPM_LE_TEST_TX_START: Start TX Test Mode + uint8_t operation; + /// Tx or Rx Channel (Range 0x00 to 0x27) + uint8_t channel; + /// Length in bytes of payload data in each packet (only valid for TX mode, range 0x00-0xFF) + uint8_t tx_data_length; + /// Packet Payload type (only valid for TX mode @see enum gap_pkt_pld_type) + uint8_t tx_pkt_payload; + /// Test PHY rate (@see enum gap_phy_val) + uint8_t phy; + /// Modulation Index (only valid for RX mode @see enum gap_modulation_idx) + uint8_t modulation_idx; + /// CTE length (in 8us unit) (Expected for RX Mode) + uint8_t cte_len; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) (Expected for TX Mode) + uint8_t cte_type; + /// Slot durations (only valid for RX mode) + uint8_t slot_dur; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[__ARRAY_EMPTY]; +}; + +/// Indicate end of test mode event +struct gapm_le_test_end_ind +{ + /// Number of received packets + uint16_t nb_packet_received; +}; + +/// Indicate reception of a IQ Report event over a direct test mode. +/*@TRACE*/ +struct gapm_le_test_iq_report_ind +{ + /// Data channel index + uint8_t channel_idx; + /// RSSI (in 0.1 dBm) + int16_t rssi; + /// RSSI antenna ID + uint8_t rssi_antenna_id; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) (@see enum gap_cte_type) + uint8_t cte_type; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Packet status + uint8_t pkt_status; + /// Periodic Adv Event Counter + uint16_t pa_evt_cnt; + /// Number of samples + uint8_t nb_samples; + /// I/Q sample + struct gap_iq_sample sample[__ARRAY_EMPTY]; +}; + +/// Provide statistic information about ISO exchange +struct gapm_iso_stat_ind +{ + /// ISO Handle of the isochronous channel (Range 0x0000-0x0EFF) + uint16_t iso_hdl; + + /// Statistics - Number of transmission attempts + uint32_t nb_tx; + /// Statistics - Number of transmission attempts that succeed + uint32_t nb_tx_ok; + /// Statistics - Number of Not granted packet packets + uint32_t nb_tx_not_granted; + + /// Statistics - Number of reception attempt + uint32_t nb_rx; + /// Statistics - Number of reception attempts that succeed + uint32_t nb_rx_ok; + /// Statistics - Number of Not granted packet packets + uint32_t nb_rx_not_granted; + /// Statistics - Number of wrongly received packet (invalid data) + uint32_t nb_rx_data_err; + /// Statistics - Number of CRC Errors + uint32_t nb_rx_crc_err; + /// Statistics - Number of SYNC Errors + uint32_t nb_rx_sync_err; + /// Statistics - Number of received empty packets + uint32_t nb_rx_empty; +}; + +/// Create an advertising, a scanning, an initiating, a periodic synchonization activity command (common) +/*@TRACE*/ +struct gapm_activity_create_cmd +{ + /// GAPM request operation: + /// - GAPM_CREATE_ADV_ACTIVITY: Create advertising activity + /// - GAPM_CREATE_SCAN_ACTIVITY: Create scanning activity + /// - GAPM_CREATE_INIT_ACTIVITY: Create initiating activity + /// - GAPM_CREATE_PERIOD_SYNC_ACTIVITY: Create periodic synchronization activity + uint8_t operation; + /// Own address type (@see enum gapm_own_addr) + uint8_t own_addr_type; +}; + +/// Create an advertising activity command +struct gapm_activity_create_adv_cmd +{ + /// GAPM request operation: + /// - GAPM_CREATE_ADV_ACTIVITY: Create advertising activity + uint8_t operation; + /// Own address type (@see enum gapm_own_addr) + uint8_t own_addr_type; + /// Advertising parameters (optional, shall be present only if operation is GAPM_CREATE_ADV_ACTIVITY) + /// For prop parameter, @see enum gapm_leg_adv_prop, @see enum gapm_ext_adv_prop and @see enum gapm_per_adv_prop for help + struct gapm_adv_create_param adv_param; +}; + +/// Activity parameters +/*@TRACE + @trc_ref gapm_actv_type + */ +union gapm_u_param +{ + /// Additional advertising parameters (for advertising activity) + //@trc_union @activity_map[$parent.actv_idx] == GAPM_ACTV_TYPE_ADV + struct gapm_adv_param adv_add_param; + /// Scan parameters (for scanning activity) + //@trc_union @activity_map[$parent.actv_idx] == GAPM_ACTV_TYPE_SCAN + struct gapm_scan_param scan_param; + /// Initiating parameters (for initiating activity) + //@trc_union @activity_map[$parent.actv_idx] == GAPM_ACTV_TYPE_INIT + struct gapm_init_param init_param; + /// Periodic synchronization parameters (for periodic synchronization activity) + //@trc_union @activity_map[$parent.actv_idx] == GAPM_ACTV_TYPE_PER_SYNC + struct gapm_per_sync_param per_sync_param; +}; + +/// Start a given activity command +/*@TRACE*/ +struct gapm_activity_start_cmd +{ + /// GAPM request operation: + /// - GAPM_START_ACTIVITY: Start a given activity + uint8_t operation; + /// Activity identifier + uint8_t actv_idx; + /// Activity parameters + union gapm_u_param u_param; +}; + +/// Stop one or all activity(ies) command +/*@TRACE*/ +struct gapm_activity_stop_cmd +{ + /// GAPM request operation: + /// - GAPM_STOP_ACTIVITY: Stop a given activity + /// - GAPM_STOP_ALL_ACTIVITIES: Stop all existing activities + uint8_t operation; + /// Activity identifier - used only if operation is GAPM_STOP_ACTIVITY + uint8_t actv_idx; +}; + +/// Delete one or all activity(ies) command +/*@TRACE*/ +struct gapm_activity_delete_cmd +{ + /// GAPM request operation: + /// - GAPM_DELETE_ACTIVITY: Delete a given activity + /// - GAPM_DELETE_ALL_ACTIVITIES: Delete all existing activities + uint8_t operation; + /// Activity identifier - used only if operation is GAPM_STOP_ACTIVITY + uint8_t actv_idx; +}; + +/// Indicate creation of an activity +/*@TRACE + @trc_exec activity_map[$actv_idx] = $actv_type + activity_map = {}*/ +struct gapm_activity_created_ind +{ + /// Activity identifier + uint8_t actv_idx; + /// Activity type (@see enum gapm_actv_type) + uint8_t actv_type; + /// Selected TX power for advertising activity + int8_t tx_pwr; +}; + +/// Indicate that an activity has been stopped +/*@TRACE*/ +struct gapm_activity_stopped_ind +{ + /// Activity identifier + uint8_t actv_idx; + /// Activity type (@see enum gapm_actv_type) + uint8_t actv_type; + /// Activity stop reason + uint8_t reason; + /// In case of periodic advertising, indicate if periodic advertising has been stopped + uint8_t per_adv_stop; +}; + +/// Set advertising, scan response or periodic advertising data command +/*@TRACE*/ +struct gapm_set_adv_data_cmd +{ + /// GAPM request operation: + /// - GAPM_SET_ADV_DATA: Set advertising data + /// - GAPM_SET_SCAN_RSP_DATA: Set scan response data + /// - GAPM_SET_PERIOD_ADV_DATA: Set periodic advertising data + uint8_t operation; + /// Activity identifier + uint8_t actv_idx; + /// Data length + uint16_t length; + /// Data + uint8_t data[__ARRAY_EMPTY]; +}; + +/// Indicate reception of scan request +/*@TRACE*/ +struct gapm_scan_request_ind +{ + /// Activity identifier + uint8_t actv_idx; + /// Transmitter device address + struct gap_bdaddr trans_addr; +}; + +/// Indicate reception of advertising, scan response or periodic advertising data +/*@TRACE*/ +struct gapm_ext_adv_report_ind +{ + /// Activity identifier + uint8_t actv_idx; + /// Bit field providing information about the received report (@see enum gapm_adv_report_info) + uint8_t info; + /// Transmitter device address + struct gap_bdaddr trans_addr; + /// Target address (in case of a directed advertising report) + struct gap_bdaddr target_addr; + /// TX power (in dBm) + int8_t tx_pwr; + /// RSSI (between -127 and +20 dBm) + int8_t rssi; + /// Primary PHY on which advertising report has been received + uint8_t phy_prim; + /// Secondary PHY on which advertising report has been received + uint8_t phy_second; + /// Advertising SID + /// Valid only for periodic advertising report + uint8_t adv_sid; + /// Periodic advertising interval (in unit of 1.25ms, min is 7.5ms) + /// Valid only for periodic advertising report + uint16_t period_adv_intv; + /// Report length + uint16_t length; + /// Report + uint8_t data[__ARRAY_EMPTY]; +}; + +/// Indicate that synchronization has been established with a periodic advertiser +/*@TRACE*/ +struct gapm_sync_established_ind +{ + /// Activity identifier + uint8_t actv_idx; + /// PHY on which synchronization has been established (@see gap_phy_type) + uint8_t phy; + /// Periodic advertising interval (in unit of 1.25ms, min is 7.5ms) + uint16_t intv; + /// Advertising SID + uint8_t adv_sid; + /// Advertiser clock accuracy (@see enum gapm_clk_acc) + uint8_t clk_acc; + /// Advertiser address + struct gap_bdaddr addr; + /// Only valid for a periodic sync transfer sync, else ignore + uint16_t serv_data; +}; + +/// Read local or peer address +/*@TRACE*/ +struct gapm_get_ral_addr_cmd +{ + /// GAPM request operation: + /// - GAPM_GET_RAL_LOC_ADDR: Get resolving local address + /// - GAPM_GET_RAL_PEER_ADDR: Get resolving peer address + uint8_t operation; + /// Peer device identity + struct gap_bdaddr peer_identity; +}; + +/// Set content of either white list or resolving list or periodic advertiser list command (common part) +struct gapm_list_set_cmd +{ + /// GAPM request operation: + /// - GAPM_SET_WHITE_LIST: Set white list content + /// - GAPM_SET_RAL: Set resolving list content + /// - GAPM_SET_PAL: Set periodic advertiser list content + uint8_t operation; + /// Number of entries to be added in the list. 0 means that list content has to be cleared + uint8_t size; +}; + +/// Set content of white list +/*@TRACE*/ +struct gapm_list_set_wl_cmd +{ + /// GAPM request operation: + /// - GAPM_SET_WHITE_LIST: Set white list content + uint8_t operation; + /// Number of entries to be added in the list. 0 means that list content has to be cleared + uint8_t size; + /// List of entries to be added in the list + struct gap_bdaddr wl_info[__ARRAY_EMPTY]; +}; + +/// Set content of resolving list command +/*@TRACE*/ +struct gapm_list_set_ral_cmd +{ + /// GAPM request operation: + /// - GAPM_SET_RAL: Set resolving list content + uint8_t operation; + /// Number of entries to be added in the list. 0 means that list content has to be cleared + uint8_t size; + /// List of entries to be added in the list + struct gap_ral_dev_info ral_info[__ARRAY_EMPTY]; +}; + +/// Set content of periodic advertiser list command +/*@TRACE*/ +struct gapm_list_set_pal_cmd +{ + /// GAPM request operation: + /// - GAPM_SET_PAL: Set periodic advertiser list content + uint8_t operation; + /// Number of entries to be added in the list. 0 means that list content has to be cleared + uint8_t size; + /// List of entries to be added in the list + struct gapm_period_adv_addr_cfg pal_info[__ARRAY_EMPTY]; +}; + +/*@TRACE + @trc_ref gapm_operation + gapm_list_set_cmd = gapm_u_list_set +*/ +union gapm_u_list_set +{ + uint8_t operation; + + //@trc_union operation == GAPM_SET_WL + struct gapm_list_set_wl_cmd list_set_wl_cmd; + //@trc_union operation == GAPM_SET_RAL + struct gapm_list_set_ral_cmd list_set_ral_cmd; + //@trc_union operation == GAPM_SET_PAL + struct gapm_list_set_pal_cmd list_set_pal_cmd; +}; + +/// List Size indication event +/*@TRACE*/ +struct gapm_list_size_ind +{ + /// Operation code, indicate list for which size has been read + /// - GAPM_SET_WHITE_LIST + /// - GAPM_SET_RAL + /// - GAPM_SET_PAL + uint8_t operation; + /// List size + uint8_t size; +}; + +/// Maximum advertising data length indication event +/*@TRACE*/ +struct gapm_max_adv_data_len_ind +{ + /// Maximum advertising data length supported by controller + uint16_t length; +}; + +/// Number of available advertising sets indication event +/*@TRACE*/ +struct gapm_nb_adv_sets_ind +{ + /// Number of available advertising sets + uint8_t nb_adv_sets; +}; + +/// Indicate the transmit powers supported by the controller +/*@TRACE*/ +struct gapm_dev_tx_pwr_ind +{ + /// Minimum TX power + int8_t min_tx_pwr; + /// Maximum TX power + int8_t max_tx_pwr; +}; + +/// Indicate the RF path compensation values +/*@TRACE*/ +struct gapm_dev_rf_path_comp_ind +{ + /// RF TX path compensation + uint16_t tx_path_comp; + /// RF RX path compensation + uint16_t rx_path_comp; +}; + +/// Indicate that an unknown message has been received +/*@TRACE*/ +struct gapm_unknown_msg_ind +{ + /// Unknown message id + ke_msg_id_t unknown_msg_id; +}; + +/// Control reception or not of Periodic Advertising Report in a Periodic Advertising Sync activity +/*@TRACE*/ +struct gapm_per_adv_report_ctrl_cmd +{ + /// GAPM request operation: + /// - GAPM_PER_ADV_REPORT_CTRL: Enable / Disable reception of periodic advertising report + uint8_t operation; + /// Activity identifier + uint8_t actv_idx; + /// True to enable reception of periodic advertising report, false to disable + uint8_t enable; +}; + +/// Control capturing IQ samples from the Constant Tone Extension of periodic advertising packets +/*@TRACE*/ +struct gapm_per_sync_iq_sampling_ctrl_cmd +{ + /// GAPM request operation: + /// - GAPM_PER_SYNC_IQ_SAMPLING_CTRL: Enable / Disable IQ sampling + uint8_t operation; + /// Activity identifier + uint8_t actv_idx; + /// True to enable IQ sampling, false to disable + uint8_t enable; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Max sampled CTEs + uint8_t max_sampl_cte; + /// Length of switching pattern + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[__ARRAY_EMPTY]; +}; + +/// Indicate reception of a IQ Report event over a periodic advertising sync activity +/*@TRACE*/ +struct gapm_per_adv_iq_report_ind +{ + /// Activity identifier + uint8_t actv_idx; + /// Data channel index + uint8_t channel_idx; + /// RSSI (in 0.1 dBm) + int16_t rssi; + /// RSSI antenna ID + uint8_t rssi_antenna_id; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) (@see enum gap_cte_type) + uint8_t cte_type; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Packet status + uint8_t pkt_status; + /// Periodic Adv Event Counter + uint16_t pa_evt_cnt; + /// Number of samples + uint8_t nb_samples; + /// I/Q sample + struct gap_iq_sample sample[__ARRAY_EMPTY]; +}; + +/// Control CTE transmission in a periodic advertising activity +/*@TRACE*/ +struct gapm_per_adv_cte_tx_ctl_cmd +{ + /// GAPM request operation: + /// - GAPM_PER_ADV_CTE_TX_CTL: Control CTE transmission in a periodic advertising activity + uint8_t operation; + /// Activity identifier + uint8_t actv_idx; + /// True to enable CTE transmission, false to disable + uint8_t enable; +}; + +/// Request to renew all currently used random private addresses (non-resolvable or resolvable) +/// For internal use only +/*@TRACE*/ +struct gapm_addr_renew_cmd +{ + /// GAPM request operation: + /// - GAPM_RENEW_ADDR: Renew random private addresses + uint8_t operation; + /// Activity index, used by GAPM ADDR state machine in order to remind for which activity + /// a new address has been generated + uint8_t actv_idx; + /// Index of first created initiating/scanning for which address has been renewed, + /// any initiating/scanning met after shall use the same address if it uses a random + /// address + uint8_t init_scan_actv_idx; +}; + +/// Debug I/Q sample control +/*@TRACE*/ +struct gapm_dbg_iq_ctrl +{ + /// I-sample control + /// 0: up-count from 0x01 + /// 1: down-count from 0xFF + /// 2: Fixed value 0x00 + /// 3: PRBS pattern + /// 4..0xFF: Fixed value + uint8_t i; + /// Q-sample control + /// 0: up-count from 0x01 + /// 1: down-count from 0xFF + /// 2: Fixed value 0x00 + /// 3: PRBS pattern + /// 4..0xFF: Fixed value + uint8_t q; +}; +/// Configure the Debug Platform I&Q Sampling generator +/*@TRACE*/ +struct gapm_dbg_iqgen_cfg_cmd +{ + + /// GAPM request operation: + /// - GAPM_DBG_IQGEN_CFG: Configure the Debug Platform I&Q Sampling generator + uint8_t operation; + /// Number of antenna patterns + uint8_t nb_antenna; + /// Antenna switch/sample control + /// bit[0]: 0: up-sweep; 1: up-down sweep (internal switching mode) + /// bit[1]: 0: 1us intervals; 1: 2us intervals (internal switching mode) + /// bit[2]: 0: internal switching mode; 1: baseband switching mode + uint8_t mode; + /// I/Q sample control + struct gapm_dbg_iq_ctrl iq_ctrl[__ARRAY_EMPTY]; +}; + +/* + * MACROS + **************************************************************************************** + */ + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/// @} GAPM_TASK + +#endif /* _GAPM_TASK_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gatt.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gatt.h new file mode 100644 index 0000000..34577eb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gatt.h @@ -0,0 +1,72 @@ +/** + **************************************************************************************** + * + * @file gatt.h + * + * @brief Header file - GATT. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef GATT_H_ +#define GATT_H_ + +/** + **************************************************************************************** + * @addtogroup GATT Generic Attribute Profile + * @ingroup HOST + * @brief Generic Attribute Profile. + * + * The GATT module is responsible for providing an API for all attribute related operations. + * It is responsible for all the service framework activities using the Attribute protocol + * for discovering services and for reading and writing characteristic values on a peer device. + * To achieve this, the GATT interfaces with @ref ATTM "ATTM", @ref ATTC "ATTC" and the + * @ref ATTS "ATTS". + * + * @{ + **************************************************************************************** + */ +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#include "att.h" + + +/* + * DEFINE DECLARATIONS + **************************************************************************************** + */ + +#if (BLE_ATTS) +/// GATT Attribute database handles +/// Generic Attribute Profile Service +enum gatt_db_att +{ + GATT_IDX_PRIM_SVC, + + GATT_IDX_CHAR_SVC_CHANGED, + GATT_IDX_SVC_CHANGED, + GATT_IDX_SVC_CHANGED_CFG, + + GATT_IDX_CHAR_CLI_SUP_FEAT, + GATT_IDX_CLI_SUP_FEAT, + + GATT_IDX_CHAR_DB_HASH, + GATT_IDX_DB_HASH, + + GATT_IDX_NUMBER +}; +#endif /* (BLE_ATTS)*/ + +/* + * Type Definition + **************************************************************************************** + */ + +/// @} GATT +#endif // GATT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gattc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gattc_task.h new file mode 100644 index 0000000..5512f72 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gattc_task.h @@ -0,0 +1,842 @@ +/** + **************************************************************************************** + * + * @file gattc_task.h + * + * @brief Header file - GATTCTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef GATTC_TASK_H_ +#define GATTC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup GATTCTASK Task + * @ingroup GATTC + * @brief Handles ALL messages to/from GATT Controller block. + * + * The GATTCTASK is responsible for managing the messages coming from + * the attribute layer and host-level layers for dedicated connection. + * The task includes services and characteristic discovery, configuration exchanges + * and attribute value access operations (reading, writing, notification and indication). + * + * Messages may originate from @ref ATTC "ATTC", @ref ATTS "ATTS", @ref GAP "GAP" + * and Application. + * + * @{ + **************************************************************************************** + */ +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "att.h" +#include "gap.h" +#include "rwip_task.h" // Task definitions +#include "compiler.h" +#include +#include "ke_msg.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// GATT Task messages +/*@TRACE*/ +enum gattc_msg_id +{ + /* Default event */ + /// Command Complete event + GATTC_CMP_EVT = MSG_ID(GATTC, 0x00), + + /* ATTRIBUTE CLIENT */ + /// Server configuration request + GATTC_EXC_MTU_CMD = MSG_ID(GATTC, 0x01), + /// Indicate that the ATT MTU has been updated (negotiated) + GATTC_MTU_CHANGED_IND = MSG_ID(GATTC, 0x02), + + /*Discover All Services */ + /*Discover Services by Service UUID*/ + /*Find Included Services*/ + /*Discover Characteristics by UUID*/ + /*Discover All Characteristics of a Service*/ + /*Discover All Characteristic Descriptors*/ + /// Discovery command + GATTC_DISC_CMD = MSG_ID(GATTC, 0x03), + /* GATT -> HL: Events to Upper layer */ + /*Discover All Services*/ + /// Discovery services indication + GATTC_DISC_SVC_IND = MSG_ID(GATTC, 0x04), + /*Find Included Services*/ + /// Discover included services indication + GATTC_DISC_SVC_INCL_IND = MSG_ID(GATTC, 0x05), + /*Discover All Characteristics of a Service*/ + /// Discover characteristic indication + GATTC_DISC_CHAR_IND = MSG_ID(GATTC, 0x06), + /*Discover All Characteristic Descriptors*/ + /// Discovery characteristic descriptor indication + GATTC_DISC_CHAR_DESC_IND = MSG_ID(GATTC, 0x07), + + /*Read Value*/ + /*Read Using UUID*/ + /*Read Long Value*/ + /*Read Multiple Values*/ + /// Read command + GATTC_READ_CMD = MSG_ID(GATTC, 0x08), + /// Read response + GATTC_READ_IND = MSG_ID(GATTC, 0x09), + + /*Write without response*/ + /*Write without response with Authentication*/ + /*Write Characteristic Value*/ + /*Signed Write Characteristic Value*/ + /*Write Long Characteristic Value*/ + /*Characteristic Value Reliable Write*/ + /*Write Characteristic Descriptors*/ + /*Write Long Characteristic Descriptors*/ + /*Characteristic Value Reliable Write*/ + /// Write command request + GATTC_WRITE_CMD = MSG_ID(GATTC, 0x0A), + + /* Cancel / Execute pending write operations */ + /// Execute write characteristic request + GATTC_EXECUTE_WRITE_CMD = MSG_ID(GATTC, 0x0B), + + /* Reception of an indication or notification from peer device. */ + /// peer device triggers an event (notification) + GATTC_EVENT_IND = MSG_ID(GATTC, 0x0C), + /// peer device triggers an event that requires a confirmation (indication) + GATTC_EVENT_REQ_IND = MSG_ID(GATTC, 0x0D), + /// Confirm reception of event (trigger a confirmation message) + GATTC_EVENT_CFM = MSG_ID(GATTC, 0x0E), + + /// Registration to peer device events (Indication/Notification). + GATTC_REG_TO_PEER_EVT_CMD = MSG_ID(GATTC, 0x0F), + + /* -------------------------- ATTRIBUTE SERVER ------------------------------- */ + /*Notify Characteristic*/ + /*Indicate Characteristic*/ + /// send an event to peer device + GATTC_SEND_EVT_CMD = MSG_ID(GATTC, 0x10), + + + /* Indicate that read operation is requested. */ + /// Read command indicated to upper layers. + GATTC_READ_REQ_IND = MSG_ID(GATTC, 0x13), + /// REad command confirmation from upper layers. + GATTC_READ_CFM = MSG_ID(GATTC, 0x14), + + /* Indicate that write operation is requested. */ + /// Write command indicated to upper layers. + GATTC_WRITE_REQ_IND = MSG_ID(GATTC, 0x15), + /// Write command confirmation from upper layers. + GATTC_WRITE_CFM = MSG_ID(GATTC, 0x16), + + /* Indicate that write operation is requested. */ + /// Request Attribute info to upper layer - could be trigger during prepare write + GATTC_ATT_INFO_REQ_IND = MSG_ID(GATTC, 0x17), + /// Attribute info from upper layer confirmation + GATTC_ATT_INFO_CFM = MSG_ID(GATTC, 0x18), + + /* ----------------------- SERVICE DISCOVERY PROCEDURE --------------------------- */ + /// Service Discovery command + GATTC_SDP_SVC_DISC_CMD = MSG_ID(GATTC, 0x19), + /// Service Discovery indicate that a service has been found. + GATTC_SDP_SVC_IND = MSG_ID(GATTC, 0x1A), + + /* -------------------------- TRANSACTION ERROR EVENT ----------------------------- */ + /// Transaction Timeout Error Event no more transaction will be accepted + GATTC_TRANSACTION_TO_ERROR_IND = MSG_ID(GATTC, 0x1B), + /// Indication to the task that sends the unknown message + GATTC_UNKNOWN_MSG_IND = MSG_ID(GATTC, 0x1C), + + /* --------------------------------- ROBUST CACHE --------------------------------- */ + /// Command used to read peer database hash + GATTC_READ_DB_HASH_CMD = MSG_ID(GATTC, 0x20), + /// Provide value of the peer database hash + GATTC_DB_HASH_IND = MSG_ID(GATTC, 0x21), + /// Command used to enable Robust database caching + /// (Register to service changed, Set client supported features and read database hash) + GATTC_ROBUST_DB_CACHE_EN_CMD = MSG_ID(GATTC, 0x22), + /// Informs that peer database updated and need to be refreshed + /// This also means that no more indication/notification will be received till database hash isn't read + GATTC_DB_CACHE_OUT_OF_SYNC_IND = MSG_ID(GATTC, 0x23), + /// Informs that peer device database updated using service changed indication + GATTC_SVC_CHG_REQ_IND = MSG_ID(GATTC, 0x24), + /// Message used to confirm that database updated is understood by application + GATTC_SVC_CHG_CFM = MSG_ID(GATTC, 0x25), + + /* ----------------------------------- GATT INFO ---------------------------------- */ + /// Provide information about GATT for current connection that can be reuse on another connection + GATTC_CON_INFO_IND = MSG_ID(GATTC, 0x28), + + /* ------------------------------- INTERNAL API ----------------------------------- */ + /// Client Response timeout indication + GATTC_CLIENT_RTX_IND = MSG_ID(GATTC, 0x40), + /// Server indication confirmation timeout indication + GATTC_SERVER_RTX_IND = MSG_ID(GATTC, 0x41), +}; + + +/// request operation type - application interface +/*@TRACE*/ +enum gattc_operation +{ + /* Attribute Client Flags */ + /* No Operation (if nothing has been requested) */ + /* ************************************************ */ + /// No operation + GATTC_NO_OP = 0x00, + + /* Operation flags for MTU Exchange */ + /* ************************************************ */ + /// Perform MTU exchange + GATTC_MTU_EXCH = 0x01, + + /* Operation flags for discovery operation */ + /* ************************************************ */ + /// Discover all services + GATTC_DISC_ALL_SVC = 0x02, + /// Discover services by UUID + GATTC_DISC_BY_UUID_SVC = 0x03, + /// Discover included services + GATTC_DISC_INCLUDED_SVC = 0x04, + /// Discover all characteristics + GATTC_DISC_ALL_CHAR = 0x05, + /// Discover characteristic by UUID + GATTC_DISC_BY_UUID_CHAR = 0x06, + /// Discover characteristic descriptor + GATTC_DISC_DESC_CHAR = 0x07, + + /* Operation flags for reading attributes */ + /* ************************************************ */ + /// Read attribute + GATTC_READ = 0x08, + /// Read long attribute + GATTC_READ_LONG = 0x09, + /// Read attribute by UUID + GATTC_READ_BY_UUID = 0x0A, + /// Read multiple attribute + GATTC_READ_MULTIPLE = 0x0B, + + /* Operation flags for writing/modifying attributes */ + /* ************************************************ */ + /// Write attribute + GATTC_WRITE = 0x0C, + /// Write no response + GATTC_WRITE_NO_RESPONSE = 0x0D, + /// Write signed + GATTC_WRITE_SIGNED = 0x0E, + /// Execute write + GATTC_EXEC_WRITE = 0x0F, + + /* Operation flags for registering to peer device */ + /* events */ + /* ************************************************ */ + /// Register to peer device events + GATTC_REGISTER = 0x10, + /// Unregister from peer device events + GATTC_UNREGISTER = 0x11, + + /* Operation flags for sending events to peer device*/ + /* ************************************************ */ + /// Send an attribute notification + GATTC_NOTIFY = 0x12, + /// Send an attribute indication + GATTC_INDICATE = 0x13, + + /* Service Discovery Procedure */ + /* ************************************************ */ + /// Search specific service + GATTC_SDP_DISC_SVC = 0x15, + /// Search for all services + GATTC_SDP_DISC_SVC_ALL = 0x16, + /// Cancel Service Discovery Procedure + GATTC_SDP_DISC_CANCEL = 0x17, + + /* Robust Cache */ + /* ************************************************ */ + /// Read peer database hash + GATTC_READ_DB_HASH = 0x20, + /// Enable Robust database cache feature + GATTC_ROBUST_DB_CACHE_EN = 0x21, + + /* Internal API */ + /* ************************************************ */ + /// Send a service changed indication + GATTC_SVC_CHANGED = 0x40, +}; + +/// Service Discovery Attribute type +/*@TRACE*/ +enum gattc_sdp_att_type +{ + /// No Attribute Information + GATTC_SDP_NONE, + /// Included Service Information + GATTC_SDP_INC_SVC, + /// Characteristic Declaration + GATTC_SDP_ATT_CHAR, + /// Attribute Value + GATTC_SDP_ATT_VAL, + /// Attribute Descriptor + GATTC_SDP_ATT_DESC, +}; + +/// Command complete event data structure +struct gattc_op_cmd +{ + /// GATT request type + uint8_t operation; + /// operation sequence number + uint16_t seq_num; +}; + +/// Command complete event data structure +/*@TRACE*/ +struct gattc_cmp_evt +{ + /// GATT request type + uint8_t operation; + /// Status of the request + uint8_t status; + /// operation sequence number - provided when operation is started + uint16_t seq_num; +}; + + +/// Service Discovery Command Structure +/*@TRACE*/ +struct gattc_exc_mtu_cmd +{ + /// GATT request type + uint8_t operation; + /// operation sequence number + uint16_t seq_num; +}; + +/// Indicate that the ATT MTU has been updated (negotiated) +/*@TRACE*/ +struct gattc_mtu_changed_ind +{ + /// Exchanged MTU value + uint16_t mtu; + /// operation sequence number + uint16_t seq_num; +}; + +/// Service Discovery Command Structure +/*@TRACE*/ +struct gattc_disc_cmd +{ + /// GATT request type + uint8_t operation; + /// UUID length + uint8_t uuid_len; + /// operation sequence number + uint16_t seq_num; + /// start handle range + uint16_t start_hdl; + /// start handle range + uint16_t end_hdl; + /// UUID + uint8_t uuid[__ARRAY_EMPTY]; +}; + + +/// Discover Service indication Structure +/*@TRACE*/ +struct gattc_disc_svc_ind +{ + /// start handle + uint16_t start_hdl; + /// end handle + uint16_t end_hdl; + /// UUID length + uint8_t uuid_len; + /// service UUID + uint8_t uuid[__ARRAY_EMPTY]; +}; + +/// Discover Service indication Structure +/*@TRACE*/ +struct gattc_disc_svc_incl_ind +{ + /// element handle + uint16_t attr_hdl; + /// start handle + uint16_t start_hdl; + /// end handle + uint16_t end_hdl; + /// UUID length + uint8_t uuid_len; + /// included service UUID + uint8_t uuid[__ARRAY_EMPTY]; +}; + +/// Discovery All Characteristic indication Structure +/*@TRACE*/ +struct gattc_disc_char_ind +{ + /// database element handle + uint16_t attr_hdl; + /// pointer attribute handle to UUID + uint16_t pointer_hdl; + /// properties + uint8_t prop; + /// UUID length + uint8_t uuid_len; + /// characteristic UUID + uint8_t uuid[__ARRAY_EMPTY]; +}; + +/// Discovery Characteristic Descriptor indication Structure +/*@TRACE*/ +struct gattc_disc_char_desc_ind +{ + /// database element handle + uint16_t attr_hdl; + /// UUID length + uint8_t uuid_len; + /// Descriptor UUID + uint8_t uuid[__ARRAY_EMPTY]; +}; + + +/// Simple Read (GATTC_READ or GATTC_READ_LONG) +/*@TRACE + gattc_read = gattc_read_simple + gattc_read_long = gattc_read_simple*/ +struct gattc_read_simple +{ + /// attribute handle + uint16_t handle; + /// start offset in data payload + uint16_t offset; + /// Length of data to read (0 = read all) + uint16_t length; +}; + +/// Read by UUID: search UUID and read it's characteristic value (GATTC_READ_BY_UUID) +/// Note: it doesn't perform an automatic read long. +/*@TRACE*/ +struct gattc_read_by_uuid +{ + /// Start handle + uint16_t start_hdl; + /// End handle + uint16_t end_hdl; + /// Size of UUID + uint8_t uuid_len; + /// UUID value + uint8_t uuid[__ARRAY_EMPTY]; +}; + +/// Read Multiple short characteristic (GATTC_READ_MULTIPLE) +/*@TRACE*/ +struct gattc_read_multiple +{ + /// attribute handle + uint16_t handle; + /// Known Handle length (shall be != 0) + uint16_t len; +}; + +/// request union according to read type +/*@TRACE + @trc_ref gattc_operation + */ +union gattc_read_req +{ + /// Simple Read (GATTC_READ or GATTC_READ_LONG) + //@trc_union parent.operation == GATTC_READ or parent.operation == GATTC_READ_LONG + struct gattc_read_simple simple; + /// Read by UUID (GATTC_READ_BY_UUID) + //@trc_union parent.operation == GATTC_READ_BY_UUID + struct gattc_read_by_uuid by_uuid; + /// Read Multiple short characteristic (GATTC_READ_MULTIPLE) + //@trc_union parent.operation == GATTC_READ_MULTIPLE + struct gattc_read_multiple multiple[1]; +}; + +/// Read command (Simple, Long, Multiple, or by UUID) +/*@TRACE*/ +struct gattc_read_cmd +{ + /// request type + uint8_t operation; + /// number of read (only used for multiple read) + uint8_t nb; + /// operation sequence number + uint16_t seq_num; + /// request union according to read type + union gattc_read_req req; +}; + +/// Attribute value read indication +/*@TRACE*/ +struct gattc_read_ind +{ + /// Attribute handle + uint16_t handle; + /// Read offset + uint16_t offset; + /// Read length + uint16_t length; + /// Handle value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Write peer attribute value command +/*@TRACE*/ +struct gattc_write_cmd +{ + /// Request type + uint8_t operation; + /// Perform automatic execution + /// (if false, an ATT Prepare Write will be used this shall be use for reliable write) + bool auto_execute; + /// operation sequence number + uint16_t seq_num; + /// Attribute handle + uint16_t handle; + /// Write offset + uint16_t offset; + /// Write length + uint16_t length; + /// Internal write cursor shall be initialized to 0 + uint16_t cursor; + /// Value to write + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Write peer attribute value command +/*@TRACE*/ +struct gattc_execute_write_cmd +{ + /// Request type + uint8_t operation; + + /// [True = perform/False cancel] pending write operations + bool execute; + /// operation sequence number + uint16_t seq_num; +}; +/// peer device triggers an event (notification) +/*@TRACE*/ +struct gattc_event_ind +{ + /// Event Type + uint8_t type; + /// Data length + uint16_t length; + /// Attribute handle + uint16_t handle; + /// Event Value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// peer device triggers an event that requires a confirmation (indication) +/*@TRACE*/ +struct gattc_event_req_ind +{ + /// Event Type + uint8_t type; + /// Data length + uint16_t length; + /// Attribute handle + uint16_t handle; + /// Event Value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Confirm reception of event (trigger a confirmation message) +/*@TRACE*/ +struct gattc_event_cfm +{ + /// Attribute handle + uint16_t handle; +}; + +/// Register to peer device events command +/*@TRACE*/ +struct gattc_reg_to_peer_evt_cmd +{ + /// Request type + uint8_t operation; + /// operation sequence number + uint16_t seq_num; + /// attribute start handle + uint16_t start_hdl; + /// attribute end handle + uint16_t end_hdl; +}; + +/// Send an event to peer device +/*@TRACE*/ +struct gattc_send_evt_cmd +{ + /// Request type (notification / indication) + uint8_t operation; + /// operation sequence number + uint16_t seq_num; + /// characteristic handle + uint16_t handle; + /// length of packet to send + uint16_t length; + /// data value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Inform that attribute value is requested by lower layers. +/*@TRACE*/ +struct gattc_read_req_ind +{ + /// Handle of the attribute that has to be read + uint16_t handle; +}; + +/// Confirm Read Request requested by GATT to profile +/*@TRACE*/ +struct gattc_read_cfm +{ + /// Handle of the attribute read + uint16_t handle; + /// Data length read + uint16_t length; + /// Status of read command execution by upper layers + uint8_t status; + /// attribute data value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Inform that a modification of database has been requested by peer device. +/*@TRACE*/ +struct gattc_write_req_ind +{ + /// Handle of the attribute that has to be written + uint16_t handle; + /// offset at which the data has to be written + uint16_t offset; + /// Data length to be written + uint16_t length; + /// Data to be written in attribute database + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Confirm modification of database from upper layer when requested by peer device. +/*@TRACE*/ +struct gattc_write_cfm +{ + /// Handle of the attribute written + uint16_t handle; + /// Status of write command execution by upper layers + uint8_t status; +}; + +/// Request Attribute info to upper layer - could be trigger during prepare write +/*@TRACE*/ +struct gattc_att_info_req_ind +{ + /// Handle of the attribute for which info are requested + uint16_t handle; +}; + +/// Attribute info from upper layer confirmation +/*@TRACE*/ +struct gattc_att_info_cfm +{ + /// Handle of the attribute + uint16_t handle; + /// Current length of the attribute + uint16_t length; + /// use to know if it's possible to modify the attribute + /// can contains authorization or application error code. + uint8_t status; +}; + + +/// Service Discovery command +/*@TRACE*/ +struct gattc_sdp_svc_disc_cmd +{ + /// GATT Request Type + /// - GATTC_SDP_DISC_SVC Search specific service + /// - GATTC_SDP_DISC_SVC_ALL Search for all services + /// - GATTC_SDP_DISC_CANCEL Cancel Service Discovery Procedure + uint8_t operation; + /// Service UUID Length + uint8_t uuid_len; + /// operation sequence number + uint16_t seq_num; + /// Search start handle + uint16_t start_hdl; + /// Search end handle + uint16_t end_hdl; + /// Service UUID + uint8_t uuid[ATT_UUID_128_LEN]; +}; + + +/// Information about included service +/*@TRACE*/ +struct gattc_sdp_include_svc +{ + /// Attribute Type + /// - GATTC_SDP_INC_SVC: Included Service Information + uint8_t att_type; + /// Included service UUID Length + uint8_t uuid_len; + /// Included Service UUID + uint8_t uuid[ATT_UUID_128_LEN]; + /// Included service Start Handle + uint16_t start_hdl; + /// Included service End Handle + uint16_t end_hdl; +}; + +/// Information about attribute characteristic +/*@TRACE*/ +struct gattc_sdp_att_char +{ + /// Attribute Type + /// - GATTC_SDP_ATT_CHAR: Characteristic Declaration + uint8_t att_type; + /// Value property + uint8_t prop; + /// Value Handle + uint16_t handle; +}; + +/// Information about attribute +/*@TRACE*/ +struct gattc_sdp_att +{ + /// Attribute Type + /// - GATTC_SDP_ATT_VAL: Attribute Value + /// - GATTC_SDP_ATT_DESC: Attribute Descriptor + uint8_t att_type; + /// Attribute UUID Length + uint8_t uuid_len; + /// Attribute UUID + uint8_t uuid[ATT_UUID_128_LEN]; +}; + +/// Attribute information +/*@TRACE + @trc_ref gattc_sdp_att_type + */ +union gattc_sdp_att_info +{ + /// Attribute Type + uint8_t att_type; + /// Information about attribute characteristic + //@trc_union att_type == GATTC_SDP_ATT_CHAR + struct gattc_sdp_att_char att_char; + /// Information about included service + //@trc_union att_type == GATTC_SDP_INC_SVC + struct gattc_sdp_include_svc inc_svc; + /// Information about attribute + //@trc_union att_type == GATTC_SDP_ATT_VAL or att_type == GATTC_SDP_ATT_DESC + struct gattc_sdp_att att; +}; + + +/// Service Discovery indicate that a service has been found. +/*@TRACE + @trc_arr info $end_hdl - $start_hdl + */ +struct gattc_sdp_svc_ind +{ + /// Service UUID Length + uint8_t uuid_len; + /// Service UUID + uint8_t uuid[ATT_UUID_128_LEN]; + /// Service start handle + uint16_t start_hdl; + /// Service end handle + uint16_t end_hdl; + /// attribute information present in the service + /// (length = end_hdl - start_hdl) + union gattc_sdp_att_info info[__ARRAY_EMPTY]; +}; + +/// Indicate that an unknown message has been received +/*@TRACE*/ +struct gattc_unknown_msg_ind +{ + /// Unknown message id + ke_msg_id_t unknown_msg_id; +}; + +/// Command used to enable Robust database caching +/// (Register to service changed, Set client supported features and read database hash) +/*@TRACE*/ +struct gattc_robust_db_cache_en_cmd +{ + /// GATT Request Type + /// - GATTC_ROBUST_DB_CACHE_EN Enable Robust database caching + uint8_t operation; + /// operation sequence number + uint16_t seq_num; +}; + +/// Command used to read peer database hash +/*@TRACE*/ +struct gattc_read_db_hash_cmd +{ + /// GATT Request Type + /// - GATTC_READ_DB_HASH Read peer database hash + uint8_t operation; + /// operation sequence number + uint16_t seq_num; +}; + +/// Provide value of the peer database hash +/*@TRACE*/ +struct gattc_db_hash_ind +{ + /// Database Hash + uint8_t hash[GAP_KEY_LEN]; +}; + +/// Informs that peer device database updated using service changed indication +/*@TRACE + @trc_arr info $end_hdl - $start_hdl + */ +struct gattc_svc_chg_req_ind +{ + /// Start handle + uint16_t start_handle; + /// End Handle + uint16_t end_handle; +}; + +/// Provide information about GATT for current connection that can be reuse on another connection +/*@TRACE*/ +struct gattc_con_info_ind +{ + // GATT Client Side + /// Peer GATT Service Start handle + uint16_t gatt_start_handle; + /// Peer GATT Service End Handle + uint16_t gatt_end_handle; + /// Peer Service Change value handle + uint16_t svc_chg_handle; + + // GATT Service Side + /// Client bond data information (@see enum gapc_cli_info) + uint8_t cli_info; + /// Client supported features (@see enum gapc_cli_feat) + uint8_t cli_feat; +}; + + +/// @} GATTCTASK +#endif // GATTC_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gattm_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gattm_task.h new file mode 100644 index 0000000..fd32e1b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/gattm_task.h @@ -0,0 +1,465 @@ +/** + **************************************************************************************** + * + * @file gattm_task.h + * + * @brief Header file - GATTMTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef GATTM_TASK_H_ +#define GATTM_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup GATTMTASK Task + * @ingroup GATTM + * @brief Handles ALL GATT block operations not related to a connection. + * + * The GATTMTASK is responsible for managing internal attribute database and state of + * GATT controller which manage GATT block operations related to a connection. + * + * Messages may originate from @ref ATTM "ATTM", @ref GAP "GAP" and Application. + * + * @{ + **************************************************************************************** + */ +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_task.h" // Task definitions +#include "att.h" +#include "gap.h" +#include "ke_msg.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +/// GATT Task messages +/*@TRACE*/ +enum gattm_msg_id +{ + /* Database Management */ + /// Add service in database request + GATTM_ADD_SVC_REQ = MSG_ID(GATTM, 0x00), + /// Add service in database response + GATTM_ADD_SVC_RSP = MSG_ID(GATTM, 0x01), + + /* Service management */ + /// Get permission settings of service request + GATTM_SVC_GET_PERMISSION_REQ = MSG_ID(GATTM, 0x02), + /// Get permission settings of service response + GATTM_SVC_GET_PERMISSION_RSP = MSG_ID(GATTM, 0x03), + /// Set permission settings of service request + GATTM_SVC_SET_PERMISSION_REQ = MSG_ID(GATTM, 0x04), + /// Set permission settings of service response + GATTM_SVC_SET_PERMISSION_RSP = MSG_ID(GATTM, 0x05), + + /* Attribute Manipulation */ + /// Get permission settings of attribute request + GATTM_ATT_GET_PERMISSION_REQ = MSG_ID(GATTM, 0x06), + /// Get permission settings of attribute response + GATTM_ATT_GET_PERMISSION_RSP = MSG_ID(GATTM, 0x07), + /// Set permission settings of attribute request + GATTM_ATT_SET_PERMISSION_REQ = MSG_ID(GATTM, 0x08), + /// Set permission settings of attribute response + GATTM_ATT_SET_PERMISSION_RSP = MSG_ID(GATTM, 0x09), + + /// Get attribute value request + GATTM_ATT_GET_VALUE_REQ = MSG_ID(GATTM, 0x0A), + /// Get attribute value response + GATTM_ATT_GET_VALUE_RSP = MSG_ID(GATTM, 0x0B), + /// Set attribute value request + GATTM_ATT_SET_VALUE_REQ = MSG_ID(GATTM, 0x0C), + /// Set attribute value response + GATTM_ATT_SET_VALUE_RSP = MSG_ID(GATTM, 0x0D), + /// Indication to the task that sends the unknown message + GATTM_UNKNOWN_MSG_IND = MSG_ID(GATTM, 0x0E), + + /* Debug messages */ + /// DEBUG ONLY: Destroy Attribute database request + GATTM_DESTROY_DB_REQ = MSG_ID(GATTM, 0x0F), + /// DEBUG ONLY: Destroy Attribute database response + GATTM_DESTROY_DB_RSP = MSG_ID(GATTM, 0x10), + /// DEBUG ONLY: Retrieve list of services request + GATTM_SVC_GET_LIST_REQ = MSG_ID(GATTM, 0x11), + /// DEBUG ONLY: Retrieve list of services response + GATTM_SVC_GET_LIST_RSP = MSG_ID(GATTM, 0x12), + /// DEBUG ONLY: Retrieve information of attribute request + GATTM_ATT_GET_INFO_REQ = MSG_ID(GATTM, 0x13), + /// DEBUG ONLY: Retrieve information of attribute response + GATTM_ATT_GET_INFO_RSP = MSG_ID(GATTM, 0x14), + /// DEBUG ONLY: Set Service visibility request + GATTM_SVC_VISIBILITY_SET_REQ = MSG_ID(GATTM, 0x15), + /// DEBUG ONLY: Set Service visibility response + GATTM_SVC_VISIBILITY_SET_RSP = MSG_ID(GATTM, 0x16), + + /* GATT Caching */ + /// Compute hash value of the attribute database request + GATTM_ATT_DB_HASH_COMP_REQ = MSG_ID(GATTM, 0x20), + /// Compute hash value of the attribute database response + GATTM_ATT_DB_HASH_COMP_RSP = MSG_ID(GATTM, 0x21), +}; + + +/** + * Attribute Description + */ +/*@TRACE*/ +struct gattm_att_desc +{ + /** Attribute UUID (LSB First) */ + uint8_t uuid[ATT_UUID_128_LEN]; + + /** + * Attribute Permission (@see attm_perm_mask) + */ + uint16_t perm; + + + /** + * Maximum length of the attribute + * + * Note: + * For Included Services and Characteristic Declarations, this field contains targeted + * handle. + * + * For Characteristic Extended Properties, this field contains 2 byte value + * + * Not used Client Characteristic Configuration and Server Characteristic Configuration, + * this field is not used. + */ + uint16_t max_len; + + /** + * Attribute Extended permissions + * + * Extended Value permission bit field + * + * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ + * | RI |UUID_LEN |EKS | Reserved | + * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ + * + * Bit [0-11] : Reserved + * Bit [12] : Encryption key Size must be 16 bytes + * Bit [13-14]: UUID Length (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU) + * Bit [15] : Trigger Read Indication (0 = Value present in Database, 1 = Value not present in Database) + */ + uint16_t ext_perm; +}; + +/** + * Service description + */ +/*@TRACE + @trc_arr atts $nb_att*/ +struct gattm_svc_desc +{ + /// Attribute Start Handle (0 = dynamically allocated) + uint16_t start_hdl; + /// Task identifier that manages service + uint16_t task_id; + + /** + * 7 6 5 4 3 2 1 0 + * +----+----+----+----+----+----+----+----+ + * |SEC |UUID_LEN |DIS | AUTH |EKS | MI | + * +----+----+----+----+----+----+----+----+ + * + * Bit [0] : Task that manage service is multi-instantiated (Connection index is conveyed) + * Bit [1] : Encryption key Size must be 16 bytes + * Bit [2-3]: Service Permission (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = Secure Connect) + * Bit [4] : Disable the service + * Bit [5-6]: UUID Length (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU) + * Bit [7] : Secondary Service (0 = Primary Service, 1 = Secondary Service) + */ + uint8_t perm; + + /// Number of attributes + uint8_t nb_att; + + /** Service UUID */ + uint8_t uuid[ATT_UUID_128_LEN]; + + /** + * List of attribute description present in service. + */ + struct gattm_att_desc atts[__ARRAY_EMPTY]; +}; + + +/// Add service in database request +/*@TRACE*/ +struct gattm_add_svc_req +{ + /// service description + struct gattm_svc_desc svc_desc; +}; + +/// Add service in database response +/*@TRACE*/ +struct gattm_add_svc_rsp +{ + /// Start handle of allocated service in attribute database + uint16_t start_hdl; + /// Return status of service allocation in attribute database. + uint8_t status; +}; + +/* Service management */ +/// Get permission settings of service request +/*@TRACE*/ +struct gattm_svc_get_permission_req +{ + /// Service start attribute handle + uint16_t start_hdl; +}; + +/// Get permission settings of service response +/*@TRACE*/ +struct gattm_svc_get_permission_rsp +{ + /// Service start attribute handle + uint16_t start_hdl; + /// service permission + uint8_t perm; + /// Return status + uint8_t status; +}; + +/// Set permission settings of service request +/*@TRACE*/ +struct gattm_svc_set_permission_req +{ + /// Service start attribute handle + uint16_t start_hdl; + /// service permission + uint8_t perm; +}; + +/// Set permission settings of service response +/*@TRACE*/ +struct gattm_svc_set_permission_rsp +{ + /// Service start attribute handle + uint16_t start_hdl; + /// Return status + uint8_t status; +}; + + +/* Attribute management */ +/// Get permission settings of attribute request +/*@TRACE*/ +struct gattm_att_get_permission_req +{ + /// Handle of the attribute + uint16_t handle; +}; + +/// Get permission settings of attribute response +/*@TRACE*/ +struct gattm_att_get_permission_rsp +{ + /// Handle of the attribute + uint16_t handle; + /// Attribute permission + uint16_t perm; + /// Extended Attribute permission + uint16_t ext_perm; + /// Return status + uint8_t status; +}; + +/// Set permission settings of attribute request +/*@TRACE*/ +struct gattm_att_set_permission_req +{ + /// Handle of the attribute + uint16_t handle; + /// Attribute permission + uint16_t perm; + /// Extended Attribute permission + uint16_t ext_perm; +}; + +/// Set permission settings of attribute response +/*@TRACE*/ +struct gattm_att_set_permission_rsp +{ + /// Handle of the attribute + uint16_t handle; + /// Return status + uint8_t status; +}; + + +/// Get attribute value request +/*@TRACE*/ +struct gattm_att_get_value_req +{ + /// Handle of the attribute + uint16_t handle; +}; + +/// Get attribute value response +/*@TRACE*/ +struct gattm_att_get_value_rsp +{ + /// Handle of the attribute + uint16_t handle; + /// Attribute value length + uint16_t length; + /// Return status + uint8_t status; + /// Attribute value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Set attribute value request +/*@TRACE*/ +struct gattm_att_set_value_req +{ + /// Handle of the attribute + uint16_t handle; + /// Attribute value length + uint16_t length; + /// Attribute value + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Set attribute value response +/*@TRACE*/ +struct gattm_att_set_value_rsp +{ + /// Handle of the attribute + uint16_t handle; + /// Return status + uint8_t status; +}; + +/// Indicate that an unknown message has been received +/*@TRACE*/ +struct gattm_unknown_msg_ind +{ + /// Unknown message id + ke_msg_id_t unknown_msg_id; +}; + +/// DEBUG ONLY: Destroy Attribute database request +/*@TRACE*/ +struct gattm_destroy_db_req +{ + /// New Gap Start Handle + uint16_t gap_hdl; + /// New Gatt Start Handle + uint16_t gatt_hdl; +}; + +/// DEBUG ONLY: Destroy Attribute database Response +/*@TRACE*/ +struct gattm_destroy_db_rsp +{ + /// Return status + uint8_t status; +}; + + +/// Service information +/*@TRACE*/ +struct gattm_svc_info +{ + /// Service start handle + uint16_t start_hdl; + /// Service end handle + uint16_t end_hdl; + /// Service task_id + uint16_t task_id; + /// Service permission + uint8_t perm; +}; + +/// DEBUG ONLY: Retrieve list of services response +/*@TRACE*/ +struct gattm_svc_get_list_rsp +{ + /// Return status + uint8_t status; + /// Number of services + uint8_t nb_svc; + /// Array of information about services + struct gattm_svc_info svc[__ARRAY_EMPTY]; +}; + +/// DEBUG ONLY: Retrieve information of attribute request +/*@TRACE*/ +struct gattm_att_get_info_req +{ + /// Attribute Handle + uint16_t handle; +}; + +/// DEBUG ONLY: Retrieve information of attribute response +/*@TRACE*/ +struct gattm_att_get_info_rsp +{ + /// Return status + uint8_t status; + /// UUID Length + uint8_t uuid_len; + /// Attribute Handle + uint16_t handle; + /// Attribute Permissions + uint16_t perm; + /// Extended Attribute permission + uint16_t ext_perm; + /// UUID value + uint8_t uuid[ATT_UUID_128_LEN]; +}; + +/// DEBUG ONLY: Set Service visibility request +/*@TRACE*/ +struct gattm_svc_visibility_set_req +{ + /// Service handle + uint16_t handle; + /// True to set service visible, false to hide it + bool visible; +}; + +/// DEBUG ONLY: Set Service visibility response +/*@TRACE*/ +struct gattm_svc_visibility_set_rsp +{ + /// Return status + uint8_t status; + /// Service handle + uint16_t handle; +}; + +/// Compute hash value of the attribute database response +/*@TRACE*/ +struct gattm_att_db_hash_comp_rsp +{ + /// Return status + uint8_t status; + /// Computed hash value (valid if status is GAP_ERR_NO_ERROR) + uint8_t hash[GAP_KEY_LEN]; +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/// @} GATTMTASK +#endif // GATTM_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/l2cc_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/l2cc_task.h new file mode 100644 index 0000000..91d9ea7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/l2cc_task.h @@ -0,0 +1,327 @@ +/** + **************************************************************************************** + * + * @file l2cc_task.h + * + * @brief Header file - L2CCTASK. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef L2CC_TASK_H_ +#define L2CC_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup L2CCTASK Task + * @ingroup L2CC + * @brief Handles ALL messages to/from L2CC block. + * + * The L2CC task is responsible for L2CAP attribute and security block handling. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_task.h" // Task definitions +#include "compiler.h" + +#include +#include "ke_msg.h" + +/* + * MACRO DEFINITIONS + **************************************************************************************** + */ + +/// Number of L2CC Deprecated messages +#define L2CC_NB_DEPRECATED_MSG (4) + +/* + * STATES + **************************************************************************************** + */ + +/* + * MESSAGES + **************************************************************************************** + */ + +/// Message API of the L2CC task +/*@TRACE*/ +enum l2cc_msg_id +{ + /// L2CAP Operation completed event + L2CC_CMP_EVT = TASK_FIRST_MSG(TASK_ID_L2CC) + L2CC_NB_DEPRECATED_MSG,//!< L2CC_CMP_EVT + + /* ************* LE Credit Based API ************* */ + /// LE credit based connection request + L2CC_LECB_CONNECT_CMD, //!< L2CC_LECB_CONNECT_CMD + /// LE credit based connection request indication + L2CC_LECB_CONNECT_REQ_IND, //!< L2CC_LECB_CONNECT_REQ_IND + /// LE credit based connection request confirmation + L2CC_LECB_CONNECT_CFM, //!< L2CC_LECB_CONNECT_CFM + /// LE credit based connection indication + L2CC_LECB_CONNECT_IND, //!< L2CC_LECB_CONNECT_IND + /// LE credit based disconnect request + L2CC_LECB_DISCONNECT_CMD, //!< L2CC_LECB_DISCONNECT_CMD + /// LE credit based disconnect indication + L2CC_LECB_DISCONNECT_IND, //!< L2CC_LECB_DISCONNECT_IND + /// LE credit based credit addition + L2CC_LECB_ADD_CMD, //!< L2CC_LECB_ADD_CMD + /// LE credit based credit addition indication + L2CC_LECB_ADD_IND, //!< L2CC_LECB_ADD_IND + + /// Send data over an LE Credit Based Connection + L2CC_LECB_SDU_SEND_CMD, //!< L2CC_LECB_SDU_SEND_CMD + /// Inform that a data packet has been received from a LE Credit Based connection. + L2CC_LECB_SDU_RECV_IND, //!< L2CC_LECB_SDU_RECV_IND + /// Indication to the task that sends the unknown message + L2CC_UNKNOWN_MSG_IND, //!< L2CC_UNKNOWN_MSG_IND + + /* ******************* Debug API ******************* */ + /// Send Debug PDU data + L2CC_DBG_PDU_SEND_CMD, //!< L2CC_DBG_PDU_SEND_CMD + /// Debug PDU data received + L2CC_DBG_PDU_RECV_IND, //!< L2CC_DBG_PDU_RECV_IND + + + /* **************** PDU Internal API ****************** */ + /// Send Legacy PDU data + L2CC_PDU_SEND_CMD, //!< L2CC_PDU_SEND_CMD + /// Legacy PDU data received + L2CC_PDU_RECV_IND, //!< L2CC_PDU_RECV_IND + + /// Timeout indication for a transaction on signaling channel + L2CC_SIGNALING_TRANS_TO_IND, //!< L2CC_SIGNALING_TRANS_TO_IND + L2CC_HCI_ACL_TX_TRIGGER, //TODO CHECK +}; + + +/// request operation type - application interface +enum l2cc_operation +{ + /* Operation Flags */ + /* No Operation (if nothing has been requested) */ + /* ************************************************ */ + /// No operation + L2CC_NO_OP = 0x00, + + /* LE Credit Based */ + /* ************************************************ */ + /// LE credit based connection request + L2CC_LECB_CONNECT, + /// LE credit based disconnection request + L2CC_LECB_DISCONNECT, + /// LE credit addition request + L2CC_LECB_CREDIT_ADD, + /// Send SDU + L2CC_LECB_SDU_SEND, + + /* Debug PDU Transmission (internal) */ + /* ************************************************ */ + /// Send a Debug PDU + L2CC_DBG_PDU_SEND, + + /* PDU Transmission (internal) */ + /* ************************************************ */ + /// Send internal LE Legacy PDU + L2CC_PDU_SEND, +}; + + +/// Default L2Cap SDU definition +/*@TRACE*/ +struct l2cc_sdu +{ + /// Channel Identifier + uint16_t cid; + /// Number of credit used + uint16_t credit; + /// SDU Data length + uint16_t length; + /// data + uint8_t data[__ARRAY_EMPTY]; +}; + + +/// Operation completed event +/*@TRACE*/ +struct l2cc_cmp_evt +{ + /// L2CC request type (@see enum l2cc_operation) + uint8_t operation; + /// Status of request. + uint8_t status; + /// Channel ID + uint16_t cid; + /// Number of peer credit used - only relevant for LECB + uint16_t credit; +}; + +/// LE credit based connection request +/*@TRACE*/ +struct l2cc_lecb_connect_cmd +{ + /// L2CC request type: + /// - L2CC_LECB_CONNECT: LE credit connection + uint8_t operation; + /// parameter used for internal usage + uint8_t pkt_id; + /// LE Protocol/Service Multiplexer + uint16_t le_psm; + /// Local Channel identifier (0: automatically allocate a free channel) + uint16_t local_cid; + /// Credit allocated for the LE Credit Based Connection + /// Shall be at least: floor(((SDU + 2) + (MPS - 1)) / MPS) + 1 + /// To be sure that 1 SDU can be fully received without requesting credits to application + uint16_t local_credit; + /// Maximum SDU size - Shall not exceed device MTU + uint16_t local_mtu; + /// Maximum Packet size - Shall not exceed device MPS + uint16_t local_mps; +}; + +/// LE credit based connection request indication +/*@TRACE*/ +struct l2cc_lecb_connect_req_ind +{ + /// LE Protocol/Service Multiplexer + uint16_t le_psm; + /// Peer Channel identifier + uint16_t peer_cid; + /// Maximum SDU size + uint16_t peer_mtu; + /// Maximum Packet size + uint16_t peer_mps; +}; + +/// LE credit based connection request confirmation +/*@TRACE*/ +struct l2cc_lecb_connect_cfm +{ + /// Peer Channel identifier + uint16_t peer_cid; + /// True to accept the incoming connection, False else + bool accept; + /// Local Channel identifier (0: automatically allocate a free channel) + uint16_t local_cid; + /// Credit allocated for the LE Credit Based Connection + /// Shall be at least: floor(((SDU + 2) + (MPS - 1)) / MPS) + 1 + /// To be sure that 1 SDU can be fully received without requesting credits to application + uint16_t local_credit; + /// Maximum SDU size - Shall not exceed device MTU + uint16_t local_mtu; + /// Maximum Packet size - Shall not exceed device MPS + uint16_t local_mps; +}; + +/// LE credit based connection indication +/*@TRACE*/ +struct l2cc_lecb_connect_ind +{ + /// Status + uint8_t status; + /// LE Protocol/Service Multiplexer + uint16_t le_psm; + /// Local Channel identifier + uint16_t local_cid; + /// Destination Credit for the LE Credit Based Connection + uint16_t peer_credit; + /// Maximum SDU size + uint16_t peer_mtu; + /// Maximum Packet size + uint16_t peer_mps; +}; + +/// LE credit based disconnect request +/*@TRACE*/ +struct l2cc_lecb_disconnect_cmd +{ + /// L2CC request type: + /// - L2CC_LECB_DISCONNECT: LE credit disconnection + uint8_t operation; + /// parameter used for internal usage + uint8_t pkt_id; + /// Local Channel identifier + uint16_t local_cid; +}; + +/// LE credit based disconnect indication +/*@TRACE*/ +struct l2cc_lecb_disconnect_ind +{ + /// Local Channel identifier + uint16_t local_cid; + /// Reason + uint8_t reason; +}; + +/// LE credit based credit addition +/*@TRACE*/ +struct l2cc_lecb_add_cmd +{ + /// L2CC request type: + /// - L2CC_LECB_CREDIT_ADD: LE credit addition + uint8_t operation; + /// parameter used for internal usage + uint8_t pkt_id; + /// Local Channel identifier + uint16_t local_cid; + /// Credit added locally for channel identifier + uint16_t credit; +}; + +///LE credit based credit addition indication +/*@TRACE*/ +struct l2cc_lecb_add_ind +{ + /// Local Channel identifier + uint16_t local_cid; + /// Destination added credit (relative value) + uint16_t peer_added_credit; +}; + +/// Send data over an LE Credit Based Connection +/*@TRACE*/ +struct l2cc_lecb_sdu_send_cmd +{ + /// L2CC request type (@see enum l2cc_operation): + /// - L2CC_LECB_SDU_SEND: Send a SDU + uint8_t operation; + /// offset value information - for internal use only + uint16_t offset; + /// SDU information + struct l2cc_sdu sdu; +}; + +/// Inform that a data packet has been received from a LE Credit Based connection. +/*@TRACE*/ +struct l2cc_lecb_sdu_recv_ind +{ + /// Status information + uint8_t status; + /// offset value information + uint16_t offset; + /// SDU information + struct l2cc_sdu sdu; +}; + +/// Indicate that an unknown message has been received +/*@TRACE*/ +struct l2cc_unknown_msg_ind +{ + /// Unknown message id + ke_msg_id_t unknown_msg_id; +}; + +/// @} L2CCTASK + +#endif // L2CC_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/prf_types.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/prf_types.h new file mode 100644 index 0000000..f81f7ad --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/prf_types.h @@ -0,0 +1,246 @@ +/** + **************************************************************************************** + * + * @file prf_types.h + * + * @brief Header file - Profile Types + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _PRF_TYPES_H_ +#define _PRF_TYPES_H_ + +/** + **************************************************************************************** + * @addtogroup PRF_TYPES + * @ingroup PROFILE + * @brief Definitions of shared profiles types + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "att.h" +#include "compiler.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// Attribute is mandatory +#define ATT_MANDATORY (0xFF) +/// Attribute is optional +#define ATT_OPTIONAL (0x00) + +/// Characteristic Presentation Format Descriptor Size +#define PRF_CHAR_PRES_FMT_SIZE (7) + + +/// Possible values for setting client configuration characteristics +enum prf_cli_conf +{ + /// Stop notification/indication + PRF_CLI_STOP_NTFIND = 0x0000, + /// Start notification + PRF_CLI_START_NTF, + /// Start indication + PRF_CLI_START_IND, +}; + +/// Possible values for setting server configuration characteristics +enum prf_srv_conf +{ + /// Stop Broadcast + PRF_SRV_STOP_BCST = 0x0000, + /// Start Broadcast + PRF_SRV_START_BCST, +}; + +/// Connection type +enum prf_con_type +{ + ///Discovery type connection + PRF_CON_DISCOVERY = 0x00, + /// Normal type connection + PRF_CON_NORMAL = 0x01, +}; + +enum prf_svc_type +{ + PRF_PRIMARY_SERVICE = 0x00, + PRF_SECONDARY_SERVICE = 0x01 +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/** + * Characteristic Presentation Format Descriptor structure + * Packed size is PRF_CHAR_PRES_FMT_SIZE + */ +/// characteristic presentation information +struct prf_char_pres_fmt +{ + /// Unit (The Unit is a UUID) + uint16_t unit; + /// Description + uint16_t description; + /// Format + uint8_t format; + /// Exponent + uint8_t exponent; + /// Name space + uint8_t name_space; +}; + +/** + * date and time structure + * size = 7 bytes + */ +/// Time profile information +struct prf_date_time +{ + /// year time element + uint16_t year; + /// month time element + uint8_t month; + /// day time element + uint8_t day; + /// hour time element + uint8_t hour; + /// minute time element + uint8_t min; + /// second time element + uint8_t sec; +}; + +/** + * SFLOAT: Short Floating Point Type + * + * +----------+----------+---------+ + * | Exponent | Mantissa | Total | + * +------+----------+----------+---------+ + * | size | 4 bits | 12 bits | 16 bits | + * +------+----------+----------+---------+ + */ +typedef uint16_t prf_sfloat; + + + +/// Attribute information +struct prf_att_info +{ + /// Attribute Handle + uint16_t handle; + /// Attribute length + uint16_t length; + /// Status of request + uint8_t status; + /// Attribute value + uint8_t value[__ARRAY_EMPTY]; +}; + + + + +/// service handles +struct prf_svc +{ + /// start handle + uint16_t shdl; + /// end handle + uint16_t ehdl; +}; + +/// service handles +struct prf_incl_svc +{ + /// attribute handle + uint16_t handle; + /// included service start handle + uint16_t start_hdl; + /// included service end handle + uint16_t end_hdl; + /// UUID length + uint8_t uuid_len; + /// UUID + uint8_t uuid[ATT_UUID_128_LEN]; +}; + +/// characteristic info +struct prf_char_inf +{ + /// Characteristic handle + uint16_t char_hdl; + /// Value handle + uint16_t val_hdl; + /// Characteristic properties + uint8_t prop; + /// End of characteristic offset + uint8_t char_ehdl_off; +}; + +/// characteristic description +struct prf_char_desc_inf +{ + /// Descriptor handle + uint16_t desc_hdl; +}; + + +/// Characteristic definition +struct prf_char_def +{ + /// Characteristic UUID + uint16_t uuid; + /// Requirement Attribute Flag + uint8_t req_flag; + /// Mandatory Properties + uint8_t prop_mand; +}; + +/// Characteristic Descriptor definition +struct prf_char_desc_def +{ + /// Characteristic Descriptor uuid + uint16_t uuid; + /// requirement attribute flag + uint8_t req_flag; + /// Corresponding characteristic code + uint8_t char_code; +}; + +/// Message structure used to inform APP that a profile client role has been disabled +struct prf_client_disable_ind +{ + /// Status + uint8_t status; +}; + + + +/// Message structure used to inform APP that an error has occured in the profile server role task +struct prf_server_error_ind +{ + /// Message ID + uint16_t msg_id; + /// Status + uint8_t status; +}; + + +/// @} PRF_TYPES + +#endif /* _PRF_TYPES_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/rwble_hl_error.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/rwble_hl_error.h new file mode 100644 index 0000000..d4ccfce --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api/rwble_hl_error.h @@ -0,0 +1,530 @@ +/** + **************************************************************************************** + * + * @file rwble_hl_error.h + * + * @brief File that contains all error codes. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef RWBLE_HL_ERROR_H_ +#define RWBLE_HL_ERROR_H_ + + +/** + **************************************************************************************** + * @addtogroup ROOT + * @brief High layer error codes + * + * This module contains the primitives that allow an application accessing and running the + * BLE protocol stack + * + * @{ + **************************************************************************************** + */ + + + +/// Error code from HCI TO HL Range - from 0x90 to 0xD0 +#define RW_ERR_HCI_TO_HL(err) (((err) != 0) ? ((err) + 0x90) : (0)) + + +/// Error code from HL TO HCI Range - from 0x90 to 0xD0 +#define RW_ERR_HL_TO_HCI(err) (((err) > 0x90) ? ((err) - 0x90) : (0)) + +/** + * SMP Pairing Failed Reasons + */ +enum smp_pair_fail_reason +{ + /** + * Passkey Entry Failed (0x01) + * The user input of passkey failed, for example, the user cancelled the operation. + */ + SMP_ERROR_PASSKEY_ENTRY_FAILED = 0x01, + /** + * OOB Not Available (0x02) + * The OOB Data is not available. + */ + SMP_ERROR_OOB_NOT_AVAILABLE, + /** + * Authentication Requirements (0x03) + * The pairing procedure cannot be performed as authentication requirements cannot be + * met due to IO capabilities of one or both devices. + */ + SMP_ERROR_AUTH_REQ, + /** + * Confirm Value Failed (0x04) + * The confirm value does not match the calculated confirm value. + */ + SMP_ERROR_CONF_VAL_FAILED, + /** + * Pairing Not Supported (0x05) + * Pairing is not supported by the device. + */ + SMP_ERROR_PAIRING_NOT_SUPP, + /** + * Encryption Key Size (0x06) + * The resultant encryption key size is insufficient for the security requirements of + * this device. + */ + SMP_ERROR_ENC_KEY_SIZE, + /** + * Command Not Supported (0x07) + * The SMP command received is not supported on this device. + */ + SMP_ERROR_CMD_NOT_SUPPORTED, + /** + * Unspecified Reason (0x08) + * Pairing failed due to an unspecified reason. + */ + SMP_ERROR_UNSPECIFIED_REASON, + /** + * Repeated Attempts (0x09) + * Pairing or Authentication procedure is disallowed because too little time has elapsed + * since last pairing request or security request. + */ + SMP_ERROR_REPEATED_ATTEMPTS, + /** + * Invalid Parameters (0x0A) + * The command length is invalid or a parameter is outside of the specified range. + */ + SMP_ERROR_INVALID_PARAM, + /** + * DHKey Check Failed (0x0B) + * Indicates to the remote device that the DHKey Check value received doesn't + * match the one calculated by the local device. + */ + SMP_ERROR_DHKEY_CHECK_FAILED, + /** + * Numeric Comparison Failed (0x0C) + * Indicates that the confirm values in the numeric comparison protocol do not match. + */ + SMP_ERROR_NUMERIC_COMPARISON_FAILED, + /** + * BR/EDR pairing in progress (0x0D) + * Indicates that the pairing over the LE transport failed due to a Pairing Request sent + * over the BR/EDR transport in process. + */ + SMP_ERROR_BREDR_PAIRING_IN_PROGRESS, + /** + * Cross-transport Key Derivation/Generation not allowed (0x0E) + * + * Indicates that the BR/EDR Link Key generated on the BR/EDR transport cannot be + * used to derive and distribute keys for the LE transport. + */ + SMP_ERROR_CROSS_TRANSPORT_KEY_GENERATION_NOT_ALLOWED, +}; + +/** + * List all HL error codes + */ +enum hl_err +{ + /// No error + GAP_ERR_NO_ERROR = 0x00, + + // ---------------------------------------------------------------------------------- + // ------------------------- ATT Specific Error ------------------------------------ + // ---------------------------------------------------------------------------------- + /// No error + ATT_ERR_NO_ERROR = 0x00, + /// 0x01: Handle is invalid + ATT_ERR_INVALID_HANDLE = 0x01, + /// 0x02: Read permission disabled + ATT_ERR_READ_NOT_PERMITTED = 0x02, + /// 0x03: Write permission disabled + ATT_ERR_WRITE_NOT_PERMITTED = 0x03, + /// 0x04: Incorrect PDU + ATT_ERR_INVALID_PDU = 0x04, + /// 0x05: Authentication privilege not enough + ATT_ERR_INSUFF_AUTHEN = 0x05, + /// 0x06: Request not supported or not understood + ATT_ERR_REQUEST_NOT_SUPPORTED = 0x06, + /// 0x07: Incorrect offset value + ATT_ERR_INVALID_OFFSET = 0x07, + /// 0x08: Authorization privilege not enough + ATT_ERR_INSUFF_AUTHOR = 0x08, + /// 0x09: Capacity queue for reliable write reached + ATT_ERR_PREPARE_QUEUE_FULL = 0x09, + /// 0x0A: Attribute requested not existing + ATT_ERR_ATTRIBUTE_NOT_FOUND = 0x0A, + /// 0x0B: Attribute requested not long + ATT_ERR_ATTRIBUTE_NOT_LONG = 0x0B, + /// 0x0C: Encryption size not sufficient + ATT_ERR_INSUFF_ENC_KEY_SIZE = 0x0C, + /// 0x0D: Invalid length of the attribute value + ATT_ERR_INVALID_ATTRIBUTE_VAL_LEN = 0x0D, + /// 0x0E: Operation not fit to condition + ATT_ERR_UNLIKELY_ERR = 0x0E, + /// 0x0F: Attribute requires encryption before operation + ATT_ERR_INSUFF_ENC = 0x0F, + /// 0x10: Attribute grouping not supported + ATT_ERR_UNSUPP_GRP_TYPE = 0x10, + /// 0x11: Resources not sufficient to complete the request + ATT_ERR_INSUFF_RESOURCE = 0x11, + /// 0x12: The server requests the client to rediscover the database. + ATT_ERR_DB_OUT_OF_SYNC = 0x12, + /// 0x13: The attribute parameter value was not allowed. + ATT_ERR_VALUE_NOT_ALLOWED = 0x13, + /// 0x80: Application error (also used in PRF Errors) + ATT_ERR_APP_ERROR = 0x80, + + // ---------------------------------------------------------------------------------- + // -------------------------- L2C Specific Error ------------------------------------ + // ---------------------------------------------------------------------------------- + /// Message cannot be sent because connection lost. (disconnected) + L2C_ERR_CONNECTION_LOST = 0x30, + /// Invalid PDU length exceed MTU + L2C_ERR_INVALID_MTU_EXCEED = 0x31, + /// Invalid PDU length exceed MPS + L2C_ERR_INVALID_MPS_EXCEED = 0x32, + /// Invalid Channel ID + L2C_ERR_INVALID_CID = 0x33, + /// Invalid PDU + L2C_ERR_INVALID_PDU = 0x34, + /// Connection refused - no resources available + L2C_ERR_NO_RES_AVAIL = 0x35, + /// Connection refused - insufficient authentication + L2C_ERR_INSUFF_AUTHEN = 0x36, + /// Connection refused - insufficient authorization + L2C_ERR_INSUFF_AUTHOR = 0x37, + /// Connection refused - insufficient encryption key size + L2C_ERR_INSUFF_ENC_KEY_SIZE = 0x38, + /// Connection Refused - insufficient encryption + L2C_ERR_INSUFF_ENC = 0x39, + /// Connection refused - LE_PSM not supported + L2C_ERR_LEPSM_NOT_SUPP = 0x3A, + /// No more credit + L2C_ERR_INSUFF_CREDIT = 0x3B, + /// Command not understood by peer device + L2C_ERR_NOT_UNDERSTOOD = 0x3C, + /// Credit error, invalid number of credit received + L2C_ERR_CREDIT_ERROR = 0x3D, + /// Channel identifier already allocated + L2C_ERR_CID_ALREADY_ALLOC = 0x3E, + /// Unknown PDU + L2C_ERR_UNKNOWN_PDU = 0x3F, + + + // ---------------------------------------------------------------------------------- + // -------------------------- GAP Specific Error ------------------------------------ + // ---------------------------------------------------------------------------------- + /// Invalid parameters set + GAP_ERR_INVALID_PARAM = 0x40, + /// Problem with protocol exchange, get unexpected response + GAP_ERR_PROTOCOL_PROBLEM = 0x41, + /// Request not supported by software configuration + GAP_ERR_NOT_SUPPORTED = 0x42, + /// Request not allowed in current state. + GAP_ERR_COMMAND_DISALLOWED = 0x43, + /// Requested operation canceled. + GAP_ERR_CANCELED = 0x44, + /// Requested operation timeout. + GAP_ERR_TIMEOUT = 0x45, + /// Link connection lost during operation. + GAP_ERR_DISCONNECTED = 0x46, + /// Search algorithm finished, but no result found + GAP_ERR_NOT_FOUND = 0x47, + /// Request rejected by peer device + GAP_ERR_REJECTED = 0x48, + /// Problem with privacy configuration + GAP_ERR_PRIVACY_CFG_PB = 0x49, + /// Duplicate or invalid advertising data + GAP_ERR_ADV_DATA_INVALID = 0x4A, + /// Insufficient resources + GAP_ERR_INSUFF_RESOURCES = 0x4B, + /// Unexpected Error + GAP_ERR_UNEXPECTED = 0x4C, + /// Feature mismatch + GAP_ERR_MISMATCH = 0x4D, + + // ---------------------------------------------------------------------------------- + // ------------------------- GATT Specific Error ------------------------------------ + // ---------------------------------------------------------------------------------- + /// Problem with ATTC protocol response + GATT_ERR_INVALID_ATT_LEN = 0x50, + /// Error in service search + GATT_ERR_INVALID_TYPE_IN_SVC_SEARCH = 0x51, + /// Invalid write data + GATT_ERR_WRITE = 0x52, + /// Signed write error + GATT_ERR_SIGNED_WRITE = 0x53, + /// No attribute client defined + GATT_ERR_ATTRIBUTE_CLIENT_MISSING = 0x54, + /// No attribute server defined + GATT_ERR_ATTRIBUTE_SERVER_MISSING = 0x55, + /// Permission set in service/attribute are invalid + GATT_ERR_INVALID_PERM = 0x56, + + // ---------------------------------------------------------------------------------- + // ------------------------- SMP Specific Error ------------------------------------- + // ---------------------------------------------------------------------------------- + // SMP Protocol Errors detected on local device + /// The user input of pass key failed, for example, the user canceled the operation. + SMP_ERROR_LOC_PASSKEY_ENTRY_FAILED = 0x61, + /// The OOB Data is not available. + SMP_ERROR_LOC_OOB_NOT_AVAILABLE = 0x62, + /// The pairing procedure cannot be performed as authentication requirements cannot be met + /// due to IO capabilities of one or both devices. + SMP_ERROR_LOC_AUTH_REQ = 0x63, + /// The confirm value does not match the calculated confirm value. + SMP_ERROR_LOC_CONF_VAL_FAILED = 0x64, + /// Pairing is not supported by the device. + SMP_ERROR_LOC_PAIRING_NOT_SUPP = 0x65, + /// The resultant encryption key size is insufficient for the security requirements of + /// this device. + SMP_ERROR_LOC_ENC_KEY_SIZE = 0x66, + /// The SMP command received is not supported on this device. + SMP_ERROR_LOC_CMD_NOT_SUPPORTED = 0x67, + /// Pairing failed due to an unspecified reason. + SMP_ERROR_LOC_UNSPECIFIED_REASON = 0x68, + /// Pairing or Authentication procedure is disallowed because too little time has elapsed + /// since last pairing request or security request. + SMP_ERROR_LOC_REPEATED_ATTEMPTS = 0x69, + /// The command length is invalid or a parameter is outside of the specified range. + SMP_ERROR_LOC_INVALID_PARAM = 0x6A, + /// Indicates to the remote device that the DHKey Check value received doesn't + /// match the one calculated by the local device. + SMP_ERROR_LOC_DHKEY_CHECK_FAILED = 0x6B, + /// Indicates that the confirm values in the numeric comparison protocol do not match. + SMP_ERROR_LOC_NUMERIC_COMPARISON_FAILED = 0x6C, + /// Indicates that the pairing over the LE transport failed due to a Pairing Request sent + /// over the BR/EDR transport in process. + SMP_ERROR_LOC_BREDR_PAIRING_IN_PROGRESS = 0x6D, + /// Indicates that the BR/EDR Link Key generated on the BR/EDR transport cannot be + /// used to derive and distribute keys for the LE transport. + SMP_ERROR_LOC_CROSS_TRANSPORT_KEY_GENERATION_NOT_ALLOWED = 0x6E, + // SMP Protocol Errors detected by remote device + /// The user input of passkey failed, for example, the user canceled the operation. + SMP_ERROR_REM_PASSKEY_ENTRY_FAILED = 0x71, + /// The OOB Data is not available. + SMP_ERROR_REM_OOB_NOT_AVAILABLE = 0x72, + /// The pairing procedure cannot be performed as authentication requirements cannot be + /// met due to IO capabilities of one or both devices. + SMP_ERROR_REM_AUTH_REQ = 0x73, + /// The confirm value does not match the calculated confirm value. + SMP_ERROR_REM_CONF_VAL_FAILED = 0x74, + /// Pairing is not supported by the device. + SMP_ERROR_REM_PAIRING_NOT_SUPP = 0x75, + /// The resultant encryption key size is insufficient for the security requirements of + /// this device. + SMP_ERROR_REM_ENC_KEY_SIZE = 0x76, + /// The SMP command received is not supported on this device. + SMP_ERROR_REM_CMD_NOT_SUPPORTED = 0x77, + /// Pairing failed due to an unspecified reason. + SMP_ERROR_REM_UNSPECIFIED_REASON = 0x78, + /// Pairing or Authentication procedure is disallowed because too little time has elapsed + /// since last pairing request or security request. + SMP_ERROR_REM_REPEATED_ATTEMPTS = 0x79, + /// The command length is invalid or a parameter is outside of the specified range. + SMP_ERROR_REM_INVALID_PARAM = 0x7A, + /// Indicates to the remote device that the DHKey Check value received doesn't + /// match the one calculated by the local device. + SMP_ERROR_REM_DHKEY_CHECK_FAILED = 0x7B, + /// Indicates that the confirm values in the numeric comparison protocol do not match. + SMP_ERROR_REM_NUMERIC_COMPARISON_FAILED = 0x7C, + /// Indicates that the pairing over the LE transport failed due to a Pairing Request sent + /// over the BR/EDR transport in process. + SMP_ERROR_REM_BREDR_PAIRING_IN_PROGRESS = 0x7D, + /// Indicates that the BR/EDR Link Key generated on the BR/EDR transport cannot be + /// used to derive and distribute keys for the LE transport. + SMP_ERROR_REM_CROSS_TRANSPORT_KEY_GENERATION_NOT_ALLOWED = 0x7E, + // SMP Errors triggered by local device + /// The provided resolvable address has not been resolved. + SMP_ERROR_ADDR_RESOLV_FAIL = 0x20, + /// The Signature Verification Failed + SMP_ERROR_SIGN_VERIF_FAIL = 0x21, + /// The encryption procedure failed because the slave device didn't find the LTK + /// needed to start an encryption session. + SMP_ERROR_ENC_KEY_MISSING = 0x22, + /// The encryption procedure failed because the slave device doesn't support the + /// encryption feature. + SMP_ERROR_ENC_NOT_SUPPORTED = 0x23, + /// A timeout has occurred during the start encryption session. + SMP_ERROR_ENC_TIMEOUT = 0x24, + + // ---------------------------------------------------------------------------------- + //------------------------ Profiles specific error codes ---------------------------- + // ---------------------------------------------------------------------------------- + /// Application Error + PRF_APP_ERROR = 0x80, + /// Invalid parameter in request + PRF_ERR_INVALID_PARAM = 0x81, + /// Inexistent handle for sending a read/write characteristic request + PRF_ERR_INEXISTENT_HDL = 0x82, + /// Discovery stopped due to missing attribute according to specification + PRF_ERR_STOP_DISC_CHAR_MISSING = 0x83, + /// Too many SVC instances found -> protocol violation + PRF_ERR_MULTIPLE_SVC = 0x84, + /// Discovery stopped due to found attribute with incorrect properties + PRF_ERR_STOP_DISC_WRONG_CHAR_PROP = 0x85, + /// Too many Char. instances found-> protocol violation + PRF_ERR_MULTIPLE_CHAR = 0x86, + /// Attribute write not allowed + PRF_ERR_NOT_WRITABLE = 0x87, + /// Attribute read not allowed + PRF_ERR_NOT_READABLE = 0x88, + /// Request not allowed + PRF_ERR_REQ_DISALLOWED = 0x89, + /// Notification Not Enabled + PRF_ERR_NTF_DISABLED = 0x8A, + /// Indication Not Enabled + PRF_ERR_IND_DISABLED = 0x8B, + /// Feature not supported by profile + PRF_ERR_FEATURE_NOT_SUPPORTED = 0x8C, + /// Read value has an unexpected length + PRF_ERR_UNEXPECTED_LEN = 0x8D, + /// Disconnection occurs + PRF_ERR_DISCONNECTED = 0x8E, + /// Procedure Timeout + PRF_ERR_PROC_TIMEOUT = 0x8F, + /// Client characteristic configuration improperly configured + PRF_CCCD_IMPR_CONFIGURED = 0xFD, + /// Procedure already in progress + PRF_PROC_IN_PROGRESS = 0xFE, + /// Out of Range + PRF_OUT_OF_RANGE = 0xFF, + + // ---------------------------------------------------------------------------------- + //-------------------- LL Error codes conveyed to upper layer ----------------------- + // ---------------------------------------------------------------------------------- + /// Unknown HCI Command + LL_ERR_UNKNOWN_HCI_COMMAND = 0x91, + /// Unknown Connection Identifier + LL_ERR_UNKNOWN_CONNECTION_ID = 0x92, + /// Hardware Failure + LL_ERR_HARDWARE_FAILURE = 0x93, + /// BT Page Timeout + LL_ERR_PAGE_TIMEOUT = 0x94, + /// Authentication failure + LL_ERR_AUTH_FAILURE = 0x95, + /// Pin code missing + LL_ERR_PIN_MISSING = 0x96, + /// Memory capacity exceed + LL_ERR_MEMORY_CAPA_EXCEED = 0x97, + /// Connection Timeout + LL_ERR_CON_TIMEOUT = 0x98, + /// Connection limit Exceed + LL_ERR_CON_LIMIT_EXCEED = 0x99, + /// Synchronous Connection limit exceed + LL_ERR_SYNC_CON_LIMIT_DEV_EXCEED = 0x9A, + /// ACL Connection exits + LL_ERR_ACL_CON_EXISTS = 0x9B, + /// Command Disallowed + LL_ERR_COMMAND_DISALLOWED = 0x9C, + /// Connection rejected due to limited resources + LL_ERR_CONN_REJ_LIMITED_RESOURCES = 0x9D, + /// Connection rejected due to security reason + LL_ERR_CONN_REJ_SECURITY_REASONS = 0x9E, + /// Connection rejected due to unacceptable BD Addr + LL_ERR_CONN_REJ_UNACCEPTABLE_BDADDR = 0x9F, + /// Connection rejected due to Accept connection timeout + LL_ERR_CONN_ACCEPT_TIMEOUT_EXCEED = 0xA0, + /// Not Supported + LL_ERR_UNSUPPORTED = 0xA1, + /// invalid parameters + LL_ERR_INVALID_HCI_PARAM = 0xA2, + /// Remote user terminate connection + LL_ERR_REMOTE_USER_TERM_CON = 0xA3, + /// Remote device terminate connection due to low resources + LL_ERR_REMOTE_DEV_TERM_LOW_RESOURCES = 0xA4, + /// Remote device terminate connection due to power off + LL_ERR_REMOTE_DEV_POWER_OFF = 0xA5, + /// Connection terminated by local host + LL_ERR_CON_TERM_BY_LOCAL_HOST = 0xA6, + /// Repeated attempts + LL_ERR_REPEATED_ATTEMPTS = 0xA7, + /// Pairing not Allowed + LL_ERR_PAIRING_NOT_ALLOWED = 0xA8, + /// Unknown PDU Error + LL_ERR_UNKNOWN_LMP_PDU = 0xA9, + /// Unsupported remote feature + LL_ERR_UNSUPPORTED_REMOTE_FEATURE = 0xAA, + /// Sco Offset rejected + LL_ERR_SCO_OFFSET_REJECTED = 0xAB, + /// SCO Interval Rejected + LL_ERR_SCO_INTERVAL_REJECTED = 0xAC, + /// SCO air mode Rejected + LL_ERR_SCO_AIR_MODE_REJECTED = 0xAD, + /// Invalid LMP parameters + LL_ERR_INVALID_LMP_PARAM = 0xAE, + /// Unspecified error + LL_ERR_UNSPECIFIED_ERROR = 0xAF, + /// Unsupported LMP Parameter value + LL_ERR_UNSUPPORTED_LMP_PARAM_VALUE = 0xB0, + /// Role Change Not allowed + LL_ERR_ROLE_CHANGE_NOT_ALLOWED = 0xB1, + /// LMP Response timeout + LL_ERR_LMP_RSP_TIMEOUT = 0xB2, + /// LMP Collision + LL_ERR_LMP_COLLISION = 0xB3, + /// LMP Pdu not allowed + LL_ERR_LMP_PDU_NOT_ALLOWED = 0xB4, + /// Encryption mode not accepted + LL_ERR_ENC_MODE_NOT_ACCEPT = 0xB5, + /// Link Key Cannot be changed + LL_ERR_LINK_KEY_CANT_CHANGE = 0xB6, + /// Quality of Service not supported + LL_ERR_QOS_NOT_SUPPORTED = 0xB7, + /// Error, instant passed + LL_ERR_INSTANT_PASSED = 0xB8, + /// Pairing with unit key not supported + LL_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUP = 0xB9, + /// Transaction collision + LL_ERR_DIFF_TRANSACTION_COLLISION = 0xBA, + /// Unacceptable parameters + LL_ERR_QOS_UNACCEPTABLE_PARAM = 0xBC, + /// Quality of Service rejected + LL_ERR_QOS_REJECTED = 0xBD, + /// Channel class not supported + LL_ERR_CHANNEL_CLASS_NOT_SUP = 0xBE, + /// Insufficient security + LL_ERR_INSUFFICIENT_SECURITY = 0xBF, + /// Parameters out of mandatory range + LL_ERR_PARAM_OUT_OF_MAND_RANGE = 0xC0, + /// Role switch pending + LL_ERR_ROLE_SWITCH_PEND = 0xC2, + /// Reserved slot violation + LL_ERR_RESERVED_SLOT_VIOLATION = 0xC4, + /// Role Switch fail + LL_ERR_ROLE_SWITCH_FAIL = 0xC5, + /// Error, EIR too large + LL_ERR_EIR_TOO_LARGE = 0xC6, + /// Simple pairing not supported by host + LL_ERR_SP_NOT_SUPPORTED_HOST = 0xC7, + /// Host pairing is busy + LL_ERR_HOST_BUSY_PAIRING = 0xC8, + /// Controller is busy + LL_ERR_CONTROLLER_BUSY = 0xCA, + /// Unacceptable connection initialization + LL_ERR_UNACCEPTABLE_CONN_INT = 0xCB, + /// Direct Advertising Timeout + LL_ERR_DIRECT_ADV_TO = 0xCC, + /// Connection Terminated due to a MIC failure + LL_ERR_TERMINATED_MIC_FAILURE = 0xCD, + /// Connection failed to be established + LL_ERR_CONN_FAILED_TO_BE_EST = 0xCE, + /// MAC Connection Failed + LL_ERR_MAC_CONN_FAILED = 0xCF, + /// Coarse Clock Adjustment Rejected but Will Try to Adjust Using Clock Dragging + LL_ERR_CCA_REJ_USE_CLOCK_DRAG = 0xD0, + /// Type0 Submap Not Defined + LL_ERR_TYPE0_SUBMAP_NOT_DEFINED = 0xD1, + /// Unknown Advertising Identifier + LL_ERR_UNKNOWN_ADVERTISING_ID = 0xD2, + /// Limit Reached + LL_ERR_LIMIT_REACHED = 0xD3, + /// Operation Cancelled by Host + LL_ERR_OPERATION_CANCELED_BY_HOST = 0xD4, + /// Packet Too Long + LL_ERR_PKT_TOO_LONG = 0xD5, +}; + +/// @} RWBLE_HL_ERROR_H + +#endif // RWBLE_HL_ERROR_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/attm.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/attm.h new file mode 100644 index 0000000..d6e21ad --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/attm.h @@ -0,0 +1,431 @@ +/** + **************************************************************************************** + * + * @file attm.h + * + * @brief Header file - ATTM. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef ATTM_H_ +#define ATTM_H_ + +/** + **************************************************************************************** + * @addtogroup ATTM Attribute Manager + * @ingroup ATT + * @brief Attribute Manager + * + * The ATTM is the attribute manager of the Attribute Profile block and + * is responsible for managing messages and providing generic attribute + * functionalities to @ref ATTC "ATTC" and @ref ATTS "ATTS". + * + * + * @{ + * + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#include +#include + +#include "co_error.h" +#include "att.h" +#include "ke_task.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/// update attribute permission on specific handle +#define ATTMDB_UPDATE_PERM(handle, access, right)\ + attm_att_update_perm(handle, (PERM_MASK_ ## access), PERM(access, right)) + +#define ATTMDB_UPDATE_PERM_VAL(handle, access, val)\ + attm_att_update_perm(handle, (PERM_MASK_ ## access), ((val) << (PERM_POS_ ## access))) + + + +/* + * DATA STRUCTURES + **************************************************************************************** + */ + +/// Internal 16bits UUID service description +struct attm_desc +{ + /// 16 bits UUID LSB First + uint16_t uuid; + /// Attribute Permissions (@see enum attm_perm_mask) + uint16_t perm; + /// Attribute Extended Permissions (@see enum attm_value_perm_mask) + uint16_t ext_perm; + /// Attribute Max Size + /// note: for characteristic declaration contains handle offset + /// note: for included service, contains target service handle + uint16_t max_size; +}; + + +/// Internal 128bits UUID service description +struct attm_desc_128 +{ + /// 128 bits UUID LSB First + uint8_t uuid[ATT_UUID_128_LEN]; + /// Attribute Permissions (@see enum attm_perm_mask) + uint16_t perm; + /// Attribute Extended Permissions (@see enum attm_value_perm_mask) + uint16_t ext_perm; + /// Attribute Max Size + /// note: for characteristic declaration contains handle offset + /// note: for included service, contains target service handle + uint16_t max_size; +}; + +/// Service Value Descriptor - 128-bit +typedef uint8_t att_svc_desc128_t[ATT_UUID_128_LEN]; + +#if (BLE_CENTRALH || BLE_PERIPHERAL) +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Compare if two UUIDs matches + * + * @param[in] uuid_a UUID A value + * @param[in] uuid_a_len UUID A length + * @param[in] uuid_b UUID B value + * @param[in] uuid_b_len UUID B length + * + * @return true if UUIDs matches, false otherwise + **************************************************************************************** + */ +bool attm_uuid_comp(const uint8_t *uuid_a, uint8_t uuid_a_len, const uint8_t *uuid_b, uint8_t uuid_b_len); + + +/** + **************************************************************************************** + * @brief Check if two UUIDs matches (2nd UUID is a 16 bits UUID with LSB First) + * + * @param[in] uuid_a UUID A value + * @param[in] uuid_a_len UUID A length + * @param[in] uuid_b UUID B 16 bit value + * + * @return true if UUIDs matches, false otherwise + **************************************************************************************** + */ +bool attm_uuid16_comp(const uint8_t *uuid_a, uint8_t uuid_a_len, uint16_t uuid_b); + + +/** + **************************************************************************************** + * @brief Convert UUID value to 128 bit UUID + * + * @param[out] uuid128 converted 32-bit Bluetooth UUID to 128-bit UUID + * @param[in] uuid UUID to convert to 128-bit UUID + * @param[in] uuid_len UUID length + * + **************************************************************************************** + */ +void attm_convert_to128(uint8_t *uuid128, const uint8_t *uuid, uint8_t uuid_len); + +/** + **************************************************************************************** + * @brief Check if it's a Bluetooth 16-bits UUID for 128-bit input + * + * @param[in] uuid 128-bit UUID + * + * @return true if uuid is a Bluetooth 16-bit UUID, false else. + **************************************************************************************** + */ +bool attm_is_bt16_uuid(const uint8_t *uuid); + +/** + **************************************************************************************** + * @brief Check if it's a Bluetooth 32 bits UUID for 128-bit input + * + * @param[in] uuid 128-bit UUID + * + * @return true if uuid is a Bluetooth 32-bits UUID, false else. + **************************************************************************************** + */ +bool attm_is_bt32_uuid(const uint8_t *uuid); + + +#if (BLE_ATTS) +/** + **************************************************************************************** + * @brief Function use to ease service database creation. + * Use @see attmdb_add_service function of attmdb module to create service database, + * then use @see attmdb_add_attribute function of attmdb module to create attributes + * according to database description array given in parameter. + * + * @note: database description array shall be const to reduce memory consumption (only ROM) + * @note: It supports only 16 bits UUIDs + * + * @note: If shdl = 0, it return handle using first available handle (shdl is + * modified); else it verifies if start handle given can be used to allocates handle range. + * + * @param[in|out] shdl Service start handle. + * @param[in] uuid Service UUID + * @param[in|out] cfg_flag Configuration Flag, each bit matches with an attribute of + * att_db (Max: 32 attributes); if the bit is set to 1, the + * attribute will be added in the service. + * @param[in] max_nb_att Number of attributes in the service + * @param[in|out] att_tbl Array which will be fulfilled with the difference between + * each characteristic handle and the service start handle. + * This array is useful if several characteristics are optional + * within the service, can be set to NULL if not needed. + * @param[in] dest_id Task ID linked to the service. This task will be notified + * each time the service content is modified by a peer device. + * @param[in|out] att_db Table containing all attributes information + * @param[in] svc_perm Service permission (@see enum attm_svc_perm_mask) + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If database creation succeeds. + * - @ref ATT_ERR_INVALID_HANDLE: If start_hdl given in parameter + nb of attribute override + * some existing services handles. + * - @ref ATT_ERR_INSUFF_RESOURCE: There is not enough memory to allocate service buffer. + * or of new attribute cannot be added because all expected + * attributes already added or buffer overflow detected during + * allocation + **************************************************************************************** + */ +uint8_t attm_svc_create_db(uint16_t *shdl, uint16_t uuid, uint8_t *cfg_flag, uint8_t max_nb_att, + uint8_t *att_tbl, ke_task_id_t const dest_id, + const struct attm_desc *att_db, uint8_t svc_perm); + + +/** + **************************************************************************************** + * @brief Function use to ease service database creation. + * Use @see attmdb_add_service function of attmdb module to create service database, + * then use @see attmdb_add_attribute function of attmdb module to create attributes + * according to database description array given in parameter. + * + * @note: database description array shall be const to reduce memory consumption (only ROM) + * @note: It supports 128, 32 and 16 bits UUIDs + * + * @note: If shdl = 0, it return handle using first available handle (shdl is + * modified); else it verifies if start handle given can be used to allocates handle range. + * + * @param[in|out] shdl Service start handle. + * @param[in] uuid Service UUID + * @param[in|out] cfg_flag Configuration Flag, each bit matches with an attribute of + * att_db (Max: 32 attributes); if the bit is set to 1, the + * attribute will be added in the service. + * @param[in] max_nb_att Number of attributes in the service + * @param[in|out] att_tbl Array which will be fulfilled with the difference between + * each characteristic handle and the service start handle. + * This array is useful if several characteristics are optional + * within the service, can be set to NULL if not needed. + * @param[in] dest_id Task ID linked to the service. This task will be notified + * each time the service content is modified by a peer device. + * @param[in|out] att_db Table containing all attributes information + * @param[in] svc_perm Service permission (@see enum attm_svc_perm_mask) + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If database creation succeeds. + * - @ref ATT_ERR_INVALID_HANDLE: If start_hdl given in parameter + nb of attribute override + * some existing services handles. + * - @ref ATT_ERR_INSUFF_RESOURCE: There is not enough memory to allocate service buffer. + * or of new attribute cannot be added because all expected + * attributes already added or buffer overflow detected during + * allocation + **************************************************************************************** + */ +uint8_t attm_svc_create_db_128(uint16_t *shdl, const uint8_t* uuid, uint8_t *cfg_flag, uint8_t max_nb_att, + uint8_t *att_tbl, ke_task_id_t const dest_id, + const struct attm_desc_128 *att_db, uint8_t svc_perm); + +/** + **************************************************************************************** + * @brief Control visibility of a service from peer device. service present in database + * but cannot be access by a peer device. + * + * @param[in] handle Service handle. + * @param[in] hide True to hide the service, False to restore visibility + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If service allocation succeeds. + * - @ref ATT_ERR_INVALID_HANDLE: If start_hdl given in parameter or UUIDs value invalid + **************************************************************************************** + */ +uint8_t attmdb_svc_visibility_set(uint16_t handle, bool hide); + +/** + **************************************************************************************** + * @brief Function use to verify if several services can be allocated on a contiguous + * handle range. If this command succeed, it means that service allocation will succeed. + * + * If start_hdl = 0, it return handle using first available handle (start_hdl is + * modified); else it verifies if start handle given can be used to allocates handle range. + * + * @param[in|out] start_hdl Service start handle. + * @param[in] nb_att Number of handle to allocate (containing service handles) + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If service allocation succeeds. + * - @ref ATT_ERR_INVALID_HANDLE: If start_hdl given in parameter or UUIDs value invalid + **************************************************************************************** + */ +uint8_t attm_reserve_handle_range(uint16_t* start_hdl, uint8_t nb_att); + + + +/** + **************************************************************************************** + * @brief Update attribute value + * + * Updating attribute value do not trigger any notification or indication, this shall be + * handled by GATT task. + * + * @param[in] handle Attribute handle. + * @param[in] length Size of new attribute value + * @param[in] offset Data offset of in the payload to set + * @param[in] value Attribute value payload + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If attribute value update succeeds + * - @ref ATT_ERR_INVALID_HANDLE: If handle doesn't exist in database + * - @ref ATT_ERR_REQUEST_NOT_SUPPORTED: If attribute data not present in database or + * cannot be modified + * - @ref ATT_ERR_INVALID_ATTRIBUTE_VAL_LEN: If new value length exceeds maximum attribute + * value length. + * + **************************************************************************************** + */ +uint8_t attm_att_set_value(uint16_t handle, att_size_t length, att_size_t offset, uint8_t* value); + +/** + **************************************************************************************** + * @brief Retrieve attribute value + + * + * @param[in] handle Attribute handle. + * @param[out] length Size of attribute value + * @param[out] value Pointer to attribute value payload + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If request succeeds + * - @ref ATT_ERR_INVALID_HANDLE: If handle doesn't exist in database + * - @ref ATT_ERR_REQUEST_NOT_SUPPORTED: If attribute data not present in database + **************************************************************************************** + */ +uint8_t attm_get_value(uint16_t handle, att_size_t* length, uint8_t** value); + + +/** + **************************************************************************************** + * @brief Update attribute permission + * + * @param[in] handle Attribute handle. + * - @ref ATT_ERR_REQUEST_NOT_SUPPORTED: If attribute data not present in database + * @param[in] perm New attribute permission + * @param[in] ext_perm New attribute extended permission + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If request succeeds + * - @ref ATT_ERR_INVALID_HANDLE: If handle doesn't exist in database + * - @ref ATT_ERR_REQUEST_NOT_SUPPORTED: If attribute permission is fixed + **************************************************************************************** + */ +uint8_t attm_att_set_permission(uint16_t handle, uint16_t perm, uint16_t ext_perm); + + +/** + **************************************************************************************** + * @brief Reset some permissions bit in the Handle passed as parameter. + * + * @param[in] handle Attribute handle. + * @param[in] access_mask Access mask of permission to update + * @param[in] perm New value of the permission to update + * + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If request succeeds + * - @ref ATT_ERR_INVALID_HANDLE: If handle doesn't exist in database + * - @ref ATT_ERR_REQUEST_NOT_SUPPORTED: If attribute permission is fixed + **************************************************************************************** + */ +uint8_t attm_att_update_perm(uint16_t handle, uint16_t access_mask, uint16_t perm); + +/** + **************************************************************************************** + * @brief Update attribute service permission + * + * @param[in] handle Attribute handle. + * @param[in] perm New attribute permission + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If request succeeds + * - @ref ATT_ERR_INVALID_HANDLE: If handle doesn't exist in database + **************************************************************************************** + */ +uint8_t attm_svc_set_permission(uint16_t handle, uint8_t perm); + + +/** + **************************************************************************************** + * @brief Retrieve attribute service permission + * + * @param[in] handle Attribute handle. + * @param[out] perm Permission value to return + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If request succeeds + * - @ref ATT_ERR_INVALID_HANDLE: If handle doesn't exist in database + **************************************************************************************** + */ +uint8_t attm_svc_get_permission(uint16_t handle, uint8_t* perm); + + +/** + **************************************************************************************** + * @brief Clear database + * + * For debug purpose only, this function clear the database and unalloc all services + * within database. + * + * This function shall be used only for qualification and tests in order to manually + * change database without modifying software. + **************************************************************************************** + */ +void attmdb_destroy(void); + +/** + **************************************************************************************** + * @brief Initialize Attribute Database (clear it) + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void attm_init(uint8_t reset); + +uint16_t attm_att_get_perm(uint16_t handle); + +#endif // (BLE_ATTS) + +#endif // #if (BLE_CENTRALH || BLE_PERIPHERAL) +/// @} ATTM +#endif // ATTM_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gapc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gapc.h new file mode 100644 index 0000000..d5ab597 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gapc.h @@ -0,0 +1,282 @@ +/** + **************************************************************************************** + * + * @file gapc.h + * + * @brief Generic Access Profile Controller Header. + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + + +#ifndef _GAPC_H_ +#define _GAPC_H_ + +/** + **************************************************************************************** + * @addtogroup GAPC Generic Access Profile Controller + * @ingroup GAP + * @brief Generic Access Profile Controller. + * + * The GAP Controller module is responsible for providing an API to the application in + * to perform GAP action related to a BLE connection (pairing, update parameters, + * disconnect ...). GAP controller is multi-instantiated, one task instance per BLE + * connection. + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_GAPC) + +#include "ke_task.h" +#include "gap.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +/// Operation type +enum gapc_op_type +{ + /// Operation used to manage Link (update params, get peer info) + GAPC_OP_LINK_INFO = 0x00, + + /// Operation used to manage SMP + GAPC_OP_SMP = 0x01, + + /// Operation used to manage connection update + GAPC_OP_LINK_UPD = 0x02, + + /// Max number of operations + GAPC_OP_MAX +}; + +/// Link security status. This status represents the authentication/authorization/bonding levels of the connection +enum gapc_lk_sec_req +{ + /// Link is bonded + GAPC_LK_BONDED, + /// Link is Encrypted + GAPC_LK_ENCRYPTED, + /// Link LTK Exchanged during pairing + GAPC_LK_LTK_PRESENT, +}; + +/// Information source. +enum gapc_smp_addr_src +{ + /// Local info. + GAPC_SMP_INFO_LOCAL, + /// Peer info. + GAPC_SMP_INFO_PEER, + /// Maximum info source. + GAPC_SMP_INFO_MAX +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Pairing Information +struct gapc_smp_pair_info; + + +/// GAPC_SMP environment structure +struct gapc_smp_env +{ + /** + * Pairing Information - This structure is allocated at the beginning of a pairing + * or procedure. It is freed when a disconnection occurs or at the end of + * the pairing procedure. If not enough memory can be found, the procedure will fail + * with an "Unspecified Reason" error + */ + struct gapc_smp_pair_info* pair; + + /// CSRK values (Local and remote) + struct gap_sec_key csrk[GAPC_SMP_INFO_MAX]; + + /// signature counter values (Local and remote) + uint32_t sign_counter[GAPC_SMP_INFO_MAX]; + + /// Repeated Attempt Timer value + uint16_t rep_att_timer_val; + + /// Encryption key size + uint8_t key_size; + + /** + * Contains the current state of the two timers needed in the GAPC_SMP task + * Bit 0 - Is Timeout Timer running + * Bit 1 - Is Repeated Attempt Timer running + * Bit 2 - Has task reached a SMP Timeout + */ + uint8_t timer_state; + + /// State of the current procedure + uint8_t state; +}; + +/// GAP controller environment variable structure. +struct gapc_env_tag +{ + /// Request operation Kernel message + void* operation[GAPC_OP_MAX]; + + /// Source task id of requested disconnection + ke_task_id_t disc_requester; + /// Destination task ID for asynchronous events not linked to an operation + ke_task_id_t dest_task_id; + + /* Connection parameters to keep */ + + /// Security Management Protocol environment variables + struct gapc_smp_env smp; + + /// connection handle + uint16_t conhdl; + + /// Configuration fields (@see enum gapc_fields) + uint8_t fields; + + /// BD Address used for the link that should be kept + struct gap_bdaddr src[GAPC_SMP_INFO_MAX]; + + /// Relevant information of peer LE features 8-byte array + uint8_t features; + /// Channel Selection Algorithm + uint8_t chan_sel_algo; +}; + + + +/* + * MACROS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieve connection index from connection handle. + * + * @param[in] conhdl Connection handle + * + * @return Return found connection index, GAP_INVALID_CONIDX if not found. + **************************************************************************************** + */ +uint8_t gapc_get_conidx(uint16_t conhdl); + +/** + **************************************************************************************** + * @brief Retrieve connection handle from connection index. + * + * @param[in] conidx Connection index + * + * @return Return found connection handle, GAP_INVALID_CONHDL if not found. + **************************************************************************************** + */ +uint16_t gapc_get_conhdl(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Retrieve connection role from connection index. + * + * @param[in] conidx Connection index + * + * @return Return found connection role + **************************************************************************************** + */ +uint8_t gapc_get_role(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Set resolvable address used for connection establishment as local address. + * + * @brief conidx Connection index + * @brief p_addr Pointer to the resolvable address used by either advertising activity or + * resolvable activity. + **************************************************************************************** + */ +void gapc_set_local_addr(uint8_t conidx, uint8_t *p_addr); + +/** + **************************************************************************************** + * @brief Retrieve connection address information on current link. + * + * @param[in] conidx Connection index + * @param[in] src Connection information source + * + * @return Return found connection address + **************************************************************************************** + */ +struct gap_bdaddr* gapc_get_bdaddr(uint8_t conidx, uint8_t src); + +/** + **************************************************************************************** + * @brief Get destination task id for asynchronous event, meaning events that are not + * linked to an operation. + * Note the provided connection index shall be valid (gapc_env[conidx] is not NULL) + * + * @param[in] conidx Connection Index + * + * @return ID of the destination task. + **************************************************************************************** + */ +ke_task_id_t gapc_get_dest_task(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Check if current link support security requirements. + * + * @param[in] conidx Connection index + * @param[in] sec_req Link security requirement to test + * + * @return True if link requirement is supported, False else. + **************************************************************************************** + */ +bool gapc_is_sec_set(uint8_t conidx, uint8_t sec_req); + +/** + **************************************************************************************** + * @brief Retrieve Link Security level + * + * @param[in] conidx Connection index + * + * @return Link Security level. + **************************************************************************************** + */ +uint8_t gapc_lk_sec_lvl_get(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Retrieve the encryption key size of the connection + * + * @param[in] conidx Connection index + * + * @return encryption key size (size is 7 - 16 byte range) + * + **************************************************************************************** + */ +uint8_t gapc_enc_keysize_get(uint8_t conidx); + +#endif // (BLE_GAPC) +/// @} GAPC + +#endif /* _GAPC_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gapm.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gapm.h new file mode 100644 index 0000000..c66ada8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gapm.h @@ -0,0 +1,438 @@ +/** + **************************************************************************************** + * + * @file gapm.h + * + * @brief Generic Access Profile Manager Header. + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + + +#ifndef _GAPM_H_ +#define _GAPM_H_ + +/** + **************************************************************************************** + * @addtogroup GAPM Generic Access Profile Manager + * @ingroup GAP + * @brief Generic Access Profile Manager. + * + * The GAP Manager module is responsible for providing an API to the application in order + * to manage all non connected stuff such as configuring device to go in desired mode + * (discoverable, connectable, etc.) and perform required actions (scanning, connection, + * etc.). GAP Manager is also responsible of managing GAP Controller state according to + * corresponding BLE connection states. + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#include "ke_task.h" +#include "gap.h" +#include "gapm_task.h" + +/* + * DEFINES + **************************************************************************************** + */ +/// Bit checking +#define GAPM_ISBITSET(flag, mask) (((flag)&(mask)) == mask) +/// Maximum number of advertising reports from different advertisers that can be reassembled in parallel +#define GAPM_REPORT_NB_MAX (5) + +/* + * STRUCTURE DEFINITION + **************************************************************************************** + */ + +/// Contain a received fragment of advertising or scan response report +struct gapm_report_elem +{ + /// List Header + struct co_list_hdr list_hdr; + /// Data length + uint8_t data_len; + /// Data + uint8_t data[]; +}; + +/// Contain a list of fragments received for an advertising or scan response report sent +/// by a given advertiser +struct gapm_report_list +{ + /// List of received reports (@see struct gapm_report_elem) + struct co_list report_list; + /// Advertiser address + struct gap_bdaddr adv_addr; + /// Received length + uint16_t length; +}; + +/// GAP Manager activity structure (common part for advertising, scanning, +/// initiating and periodic synchronization activities) +struct gapm_actv_tag +{ + /// Function to be called for activity start + uint8_t (*cb_actv_start)(struct gapm_actv_tag *, struct gapm_activity_start_cmd *); + /// Function to be called for activity stop + void (*cb_actv_stop)(struct gapm_actv_tag *); + /// Function to be called for activity delete + void (*cb_actv_delete)(struct gapm_actv_tag *); + + /// Identifier + uint8_t idx; + /// Type (@see enum gapm_actv_type) + uint8_t type; + /// Subtype - meaning depends on activity type + /// - Advertising activity: @see enum gapm_adv_type + /// - Scanning activity: @see enum gapm_scan_type + /// - Initiating activity: @see enum gapm_init_type + /// - Periodic Synchronization activity: @see enum gapm_per_sync_type + uint8_t subtype; + /// State (@see enum gapm_actv_state) + uint8_t state; + /// Information bit field, meaning depends on activity type + uint8_t info; + /// Own address type + uint8_t own_addr_type; + /// Next expected HCI event opcode + uint16_t next_exp_opcode; + /// Task ID of task that has requested creation of the activity + ke_task_id_t requester; + /// BD Address used by the activity (can be different if controller privacy is used and + /// application chose to use a resolvable private address) + bd_addr_t addr; +}; + +/// GAP Manager activity structure for advertising activity +struct gapm_actv_adv_tag +{ + /// Common activity parameters + struct gapm_actv_tag common; + /// Data offset for the set advertising data procedure + uint16_t data_offset; + /// Advertising mode (@see enum gapm_adv_disc_mode) + uint8_t mode; + /// Stored status + uint8_t kept_status; + /// Selected TX power + uint8_t tx_pwr; + /// Additional information (@see enum gapm_adv_add_info_bf) + uint8_t add_info; +}; + +/// GAP Manager activity structure for scanning activity +struct gapm_actv_scan_tag +{ + /// Common activity parameters + struct gapm_actv_tag common; + /// Lists containing fragments for GAPM_REPORT_NB_MAX reports that can be received in parallel + struct gapm_report_list report_lists[GAPM_REPORT_NB_MAX]; + /// Scan filtering Array + struct gap_bdaddr *p_scan_filter; +}; + +/// GAP Manager activity structure for initiating activity +struct gapm_actv_init_tag +{ + /// Common activity parameters + struct gapm_actv_tag common; + /// Initiating parameters + struct gapm_init_param init_param; + /// Number of connection to be established for automatic connection + /// -> Number of devices in the white list when GAPM_ACTIVITY_START_CMD is received + uint8_t nb_auto_conn; + /// Stored status + uint8_t kept_status; +}; + +/// GAP Manager activity structure for periodic synchronization activity +struct gapm_actv_per_sync_tag +{ + /// Common activity parameters + struct gapm_actv_tag common; + /// List of received reports fragment (@see struct gapm_report_elem) + struct co_list report_list; + /// Received length + uint16_t length; + /// Synchronization Handle + uint16_t sync_hdl; + #if (BLE_CENTRALH || BLE_PERIPHERAL) + /// Connection index where PAST sync info is expected + uint8_t conidx; + #endif // (BLE_CENTRALH || BLE_PERIPHERAL) + +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize Generic Access Profile Manager Module. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void gapm_init(uint8_t init_type); + + +/** + **************************************************************************************** + * @brief Retrieve Task Identifier from Task number + * (automatically update index of task in returned task id) + * + * @param task Task number + * @return Task Identifier + **************************************************************************************** + */ +ke_task_id_t gapm_get_id_from_task(ke_msg_id_t task); + +/** + **************************************************************************************** + * @brief Retrieve Task Number from Task Identifier + * (automatically update index of task in returned task id) + * + * @param id Task Identifier + * @return Task Number + **************************************************************************************** + */ +ke_task_id_t gapm_get_task_from_id(ke_msg_id_t id); + + + +#if (BLE_GAPC) + + +/** + **************************************************************************************** + * @brief A link has been disconnected, clean-up host stack for this connection. + * + * @param[in] conidx Connection Index + * @param[in] conhdl Connection Handle + * @param[in] reason Reason of the disconnection + * + **************************************************************************************** + */ +void gapm_con_cleanup(uint8_t conidx, uint16_t conhdl, uint8_t reason); + +#endif // (BLE_GAPC) + + +/** + **************************************************************************************** + * @brief Retrieve device identity key. + * + * @return Device Identity Key + **************************************************************************************** + */ +struct gap_sec_key* gapm_get_irk(void); + + +/** + **************************************************************************************** + * @brief Retrieve local public address. + * + * @return Return local public address + **************************************************************************************** + */ +bd_addr_t* gapm_get_bdaddr(void); + + + +#if (BLE_ISO_MODE_0_PROTOCOL) +/** + **************************************************************************************** + * @brief Return if LE Audio Mode 0 is supported or not + * + * @return True if supported, False else + **************************************************************************************** + */ +bool gapm_is_audio_am0_sup(void); +#endif // (BLE_ISO_MODE_0_PROTOCOL) + +/** + **************************************************************************************** + * @brief Retrieve the device address type (@see enum gapm_addr_type) + * + * @return address type + **************************************************************************************** + */ +uint8_t gapm_get_address_type(void); + + +#if (BLE_ATTS) + +/** + **************************************************************************************** + * @brief Get if preferred connection parameters present in GAP ATT database + * + * @return True if referred connection parameters present in GAP ATT database, False else + **************************************************************************************** + */ +bool gapm_is_pref_con_param_pres(void); + +/** + **************************************************************************************** + * @brief retrieve gap attribute handle from attribute index. + * + * @param[in] att_idx Attribute index + * + * @return Attribute handle + **************************************************************************************** + */ +uint16_t gapm_get_att_handle(uint8_t att_idx); + +#endif // (BLE_ATTS) + +/** + **************************************************************************************** + * @brief Retrieve if Legacy pairing is supported on local device + * + * @return True if legacy pairing is supported + **************************************************************************************** + */ +bool gapm_is_legacy_pairing_supp(void); + + +/** + **************************************************************************************** + * @brief Retrieve if Secure Connection pairing is supported on local device + * + * @return True if Secure Connection pairing is supported + **************************************************************************************** + */ +bool gapm_is_sec_con_pairing_supp(void); + + +#if (BLE_LECB) +/** + **************************************************************************************** + * @brief Check if LECB connection can be registered (established) + * + * @param[in] le_psm LE Protocol/Service Multiplexer + * @param[in] conidx Connection index for app_task computation + * @param[out] app_task Destination application/profile task + * @param[out] sec_lvl Security level requirements + * + * + * @return GAP_ERR_NOT_FOUND if LE_PSM not register, GAP_ERR_NO_ERROR else + **************************************************************************************** + */ +uint8_t gapm_le_psm_get_info(uint16_t le_psm, uint8_t conidx, ke_task_id_t *app_task, uint8_t *sec_lvl); + + +/** + **************************************************************************************** + * @brief Check if LECB connection can be registered (established) + * + * @param[in] le_psm LE Protocol/Service Multiplexer + * @param[in] peer_con_init Info to know if connection is initiated by peer device + * + * @return L2C_ERR_NO_RES_AVAIL if all LECB link are established, GAP_ERR_NO_ERROR else + **************************************************************************************** + */ +uint8_t gapm_lecb_register(uint16_t le_psm, bool peer_con_init); + + +/** + **************************************************************************************** + * @brief Unregister an existing LECB connection + * + * @param[in] le_psm LE Protocol/Service Multiplexer + * @param[in] peer_con_init Info to know if connection is initiated by peer device + * + * @return GAP_ERR_NO_ERROR + **************************************************************************************** + */ +uint8_t gapm_lecb_unregister(uint16_t le_psm, bool peer_con_init); + +#endif // (BLE_LECB) + +/** + **************************************************************************************** + * @brief Return the maximal MTU value + * + * @param[out] Maximal MTU value + **************************************************************************************** + */ +uint16_t gapm_get_max_mtu(void); + +/** + **************************************************************************************** + * @brief Return the maximal MPS value + * + * @param[out] Maximal MPS value + **************************************************************************************** + */ +uint16_t gapm_get_max_mps(void); + +#if (RW_DEBUG) +/** + **************************************************************************************** + * @brief Check If Debug mode feature is enabled or not + * + * @return true if enabled, false else. + * + **************************************************************************************** + */ +bool gapm_dbg_mode_en(void); + +/** + **************************************************************************************** + * @brief Check If received L2CAP packet must be forwarded to the application + * + * @return true if enabled, false else. + * + **************************************************************************************** + */ +bool gapm_dbg_fwd_traffic(void); + +/** + **************************************************************************************** + * @brief Force the GAP service start handle + **************************************************************************************** + */ +void gapm_set_svc_start_hdl(uint16_t start_hdl); +#endif // (RW_DEBUG) + +/** + **************************************************************************************** + * Retrieve if current connection index is used for a discovery purpose such as + * Name discovery + * + * @param conidx Index of the specific connection + * + * @return true if connection has a discovery purpose, False else + **************************************************************************************** + */ +bool gapm_is_disc_connection(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Get information about a non connected activity + * + * @param[in] actv_idx Activity Identifier + * @param[in] p_act_type Activity Type (enum gapm_actv_type) + * @param[in] p_act_sub_type Activity Sub Type, depends on activity + * @param[in] p_handle Lower Layer activity handle (adv_handle, sync_handle) + * + * @return GAP_ERR_NO_ERROR if activity exists else GAP_ERR_COMMAND_DISALLOWED + **************************************************************************************** + */ +uint8_t gapm_actv_info_get(uint8_t actv_idx, uint8_t* p_act_type, uint8_t* p_act_sub_type, uint16_t *p_handle); + +/// @} GAPM + +#endif /* _GAPM_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gattc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gattc.h new file mode 100644 index 0000000..f2fa2cc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gattc.h @@ -0,0 +1,209 @@ +/** + **************************************************************************************** + * + * @file gattc.h + * + * @brief Header file - GATT Controller. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef GATTC_H_ +#define GATTC_H_ + +/** + **************************************************************************************** + * @addtogroup GATTC Generic Attribute Profile Controller + * @ingroup GATT + * @brief Generic Attribute Profile Controller. + * + * This GATT module is responsible for providing an API for all attribute related operations + * related to a BLE connection. + * It is responsible for all the service framework activities using the Attribute protocol + * for discovering services and for reading and writing characteristic values on a peer device. + * To achieve this, the GATT interfaces with @ref ATTC "ATTC" and the @ref ATTS "ATTS". + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +/* kernel task */ +#include "rwip_config.h" +#if (BLE_GATTC) + +#include "co_list.h" + + +/* + * DEFINES + **************************************************************************************** + */ + +/// Operation type +enum gattc_op_type +{ + #if (BLE_ATTS) + /// Operation used to Server Request operations + GATTC_OP_SERVER, + #endif // (BLE_ATTS) + + #if (BLE_ATTC) + /// Operation used to Client Request operations + GATTC_OP_CLIENT, + /// Service Discovery Procedure operation + GATTC_OP_SDP, + /// Operation used to enable Client features + GATTC_OP_FEAT, + #endif // (BLE_ATTC) + + /// Max number of operations + GATTC_OP_MAX +}; + +/* + * TYPES DEFINITIONS + **************************************************************************************** + */ + +#if (BLE_ATTC) +/// Attribute Client environment variable requirements +struct attc_env +{ + /// List of ATT message used to aggregate long value in a single buffer. + struct co_list rsp_list; + /// List that contains peer device event registration + struct co_list reg_evt; + /// List that contains data for service discovery + struct co_list sdp_data; + + /// GATT Service Start handle + uint16_t gatt_start_handle; + /// Number of attributes present in GATT service + uint8_t gatt_nb_att; + /// Service Change value handle offset + uint8_t svc_chg_offset; + /// Prepare write error + uint8_t prep_wr_err; +}; +#endif // (BLE_ATTC) + + +#if (BLE_ATTS) +/// Attribute server environment variables +struct atts_env +{ + /// This is used to merge save all the prepare write request received , + /// before receiving the execute or cancel or disconnection. + struct co_list prep_wr_req_list; + /// This list is used to put any data in order to send a response to peer device + struct co_list rsp; + /// List of PDU to process + struct co_list pdu_queue; + /// This structure is used to store in cache latest attribute read value + struct gattc_read_cfm* read_cache; + /// Number of attributes found + uint8_t nb_att_fd; + + /// Client bond data information (@see enum gattc_cli_info) + uint8_t cli_info; +}; +#endif // (BLE_ATTS) + +/// GATT controller environment variable structure. +struct gattc_env_tag +{ + /// Request operation Kernel message + void* operation[GATTC_OP_MAX]; + + #if (BLE_ATTC) + /// Client specific environment + struct attc_env client; + #endif // (BLE_ATTC) + + #if (BLE_ATTS) + /// Server specific environment + struct atts_env server; + #endif // (BLE_ATTS) + + /// Current MTU Size + uint16_t mtu_size; + + /// A transaction timeout occurs, reject next attribute commands + bool trans_timeout; + /// Used to know if MTU exchange already done. + bool mtu_exch; +}; + +/* + * MACRO DEFINITIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Created link connection parameters (from bond data) has been set, connection ready to be used. + * + * @note cli_info and cli_feat are considered only if bond == true + * + * @param[in] conidx Connection Index + * @param[in] bond Used to know if link correspond to a bonded device + * @param[in] cli_info Client bond information (@see enum gapc_cli_info) + * @param[in] cli_feat Get Peer client supported features enabled in previous link (@see enum gapc_cli_feat) + * @param[in] gatt_start_handle Peer GATT Service Start handle + * @param[in] gatt_end_handle Peer GATT Service End Handle + * @param[in] svc_chg_handle Peer Service Change value handle + **************************************************************************************** + */ +void gattc_con_enable(uint8_t conidx, bool bond, uint8_t cli_info, uint8_t cli_feat, + uint16_t gatt_start_handle, uint16_t gatt_end_handle, uint16_t svc_chg_handle); + +/** + **************************************************************************************** + * @brief Gets the negotiated MTU. This function gets the negotiated MTU. + * + * @param[in] conidx connection index + * + * @return MTU negotiated + * + **************************************************************************************** + */ +uint16_t gattc_get_mtu(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Sets the negotiated MTU This function stores the negotiated MTU. + * + * @param[in] conidx connection index + * @param[in] mtu negotiated MTU + * + * @return status indicates if the MTU setting operation is successful + * + **************************************************************************************** + */ +void gattc_set_mtu(uint8_t conidx, uint16_t mtu); + +/** + **************************************************************************************** + * @brief Informs peer device database has been updated + * + * @param[in] conidx connection index + **************************************************************************************** + */ +void gattc_db_updated(uint8_t conidx); + +#endif /* (BLE_GATTC) */ + +/// @} GATTC +#endif // GATTC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gattm.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gattm.h new file mode 100644 index 0000000..3ad205a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/gattm.h @@ -0,0 +1,132 @@ +/** + **************************************************************************************** + * + * @file gattm.h + * + * @brief Header file - GATT Manager. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef GATTM_H_ +#define GATTM_H_ + + + +/** + **************************************************************************************** + * @addtogroup GATTM Generic Attribute Profile Manager + * @ingroup GATT + * @brief Generic Attribute Profile. + * + * The GATT manager module is responsible for providing an API for all action operations + * not related to a connection. It's responsible to managing internal database. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +/* kernel task */ +#include "rwip_config.h" + +#if (BLE_CENTRALH || BLE_PERIPHERAL) +#include +#include + +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the GATT manager module. + * This function performs all the initialization steps of the GATT module. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + * + **************************************************************************************** + */ +void gattm_init(uint8_t init_type); + + +/** + **************************************************************************************** + * @brief Initialize GATT attribute database + * + * @param[in] start_hdl Service Start Handle + * + * @return status code of attribute database initialization + * Command status code: + * - @ref ATT_ERR_NO_ERROR: If database creation succeeds. + * - @ref ATT_ERR_INVALID_HANDLE: If start_hdl given in parameter + nb of attribute override + * some existing services handles. + * - @ref ATT_ERR_INSUFF_RESOURCE: There is not enough memory to allocate service buffer. + * or of new attribute cannot be added because all expected + * attributes already add + **************************************************************************************** + */ +uint8_t gattm_init_attr(uint16_t start_hdl); + +/** + **************************************************************************************** + * @brief Initialize GATT resources for connection. + * + * @param[in] conidx connection record index + * @param[in] role device role after connection establishment + * + **************************************************************************************** + */ +void gattm_create(uint8_t conidx); +/** + **************************************************************************************** + * @brief Cleanup GATT resources for connection + * + * @param[in] conidx connection record index + * + **************************************************************************************** + */ +void gattm_cleanup(uint8_t conidx); + + +#if (BLE_ATTS) + +/** + **************************************************************************************** + * @brief Convert attribute handle to GATT database attribute index. + * + * @param[in] handle Attribute Handle + * + * @return GATT database attribute index (ATT_INVALID_IDX if not found) + **************************************************************************************** + */ +uint8_t gattm_att_hdl_to_idx(uint16_t handle); + +/** + **************************************************************************************** + * @brief Convert GATT database attribute index to attribute handle. + * + * @param[in] att_idx GATT database attribute index + * + * @return Attribute Handle (ATT_INVALID_HANDLE if not found) + **************************************************************************************** + */ +uint16_t gattm_att_idx_to_hdl(uint8_t att_idx); +#endif //(BLE_ATTS) +#endif /* (BLE_CENTRALH || BLE_PERIPHERAL) */ + +/// @} GATTM +#endif // GATTM_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/l2cc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/l2cc.h new file mode 100644 index 0000000..e94bd10 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/l2cc.h @@ -0,0 +1,263 @@ +/** + **************************************************************************************** + * + * @file l2cc.h + * + * @brief Header file - L2CC. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef L2CC_H_ +#define L2CC_H_ + +/** + **************************************************************************************** + * @addtogroup L2CC L2CAP Controller + * @ingroup L2C + * @brief L2CAP block for data processing and per device connection + * + * The L2CC is responsible for all the data processing related + * functions of the L2CAP block per device connection. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_L2CC) + +#include "l2cc_task.h" +#include "l2cc_pdu.h" + +#include +#include +#include "co_list.h" +#include "ke_task.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Generic way to creates and allocate a Signaling PDU message that can be then + * sent to peer device + * + * @param[in] conidx Connection Index + * @param[in] code PDU code + * @param[in] src_id Source task ID + * + * @return Pointer to the PDU payload + **************************************************************************************** + */ +#define L2CC_SIG_PDU_ALLOC(conidx, code, src_id, type) \ + ((struct type*) l2cc_pdu_alloc(conidx, L2C_CID_LE_SIGNALING, code, src_id, 0)) + +/// from PDU, retrieve the send command +#define L2CC_PDU_TO_CMD(_pdu) \ + ((struct l2cc_pdu_send_cmd*) (((uint8_t*)_pdu) - offsetof(struct l2cc_pdu_send_cmd, pdu.data.code))) + +/// from PDU, retrieve the receive indication +#define L2CC_PDU_TO_IND(_pdu) \ + ((struct l2cc_pdu_recv_ind*) (((uint8_t*)_pdu) - offsetof(struct l2cc_pdu_recv_ind, pdu.data.code))) + + +/** + **************************************************************************************** + * @brief Generic way to creates and allocate a SMP PDU message that can be then sent to + * peer device + * + * @param[in] conidx Connection Index + * @param[in] code PDU code + * @param[in] src_id Source task ID + * + * @return Pointer to the PDU payload + **************************************************************************************** + */ +#define L2CC_SMP_PDU_ALLOC(conidx, code, src_id, type) \ + ((struct type*) l2cc_pdu_alloc(conidx, L2C_CID_SECURITY, code, src_id, 0)) + + +/** + **************************************************************************************** + * @brief Generic way to creates and allocate an ATT PDU message that can be then sent to + * peer device + * + * @param[in] conidx Connection Index + * @param[in] code PDU code + * @param[in] src_id Source task ID + * + * @return Pointer to the PDU payload + **************************************************************************************** + */ +#define L2CC_ATT_PDU_ALLOC(conidx, code, src_id, type)\ + ((struct type*) l2cc_pdu_alloc(conidx, L2C_CID_ATTRIBUTE, code, src_id, 0)) + + +/** + **************************************************************************************** + * @brief Generic way to creates and allocate an ATT PDU message that can be then sent to + * peer device + * + * @param[in] conidx Connection Index + * @param[in] code PDU code + * @param[in] src_id Source task ID + * @param[in] length Dynamic payload length to allocate + * + * @return Pointer to the PDU payload + **************************************************************************************** + */ +#define L2CC_ATT_PDU_ALLOC_DYN(conidx, code, src_id, type, length)\ + ((struct type*) l2cc_pdu_alloc(conidx, L2C_CID_ATTRIBUTE, code, src_id, length)) + +/* + * INTERNAL MESSAGES API TYPES + **************************************************************************************** + */ + + + +/// Send Debug PDU data +/*@TRACE*/ +struct l2cc_dbg_pdu_send_cmd +{ + /// L2CC request type (@see enum l2cc_operation): + /// - L2CC_DBG_PDU_SEND: Send a PDU + uint8_t operation; + /// offset value information + uint16_t offset; + /// PDU Data + struct l2cc_dbg_pdu pdu; +}; + +/// Debug PDU data received +/*@TRACE*/ +struct l2cc_dbg_pdu_recv_ind +{ + /// Status information + uint8_t status; + /// offset value information + uint16_t offset; + /// PDU Data + struct l2cc_dbg_pdu pdu; +}; + +/// Send Legacy PDU data +/*@TRACE*/ +struct l2cc_pdu_send_cmd +{ + /// L2CC request type (@see enum l2cc_operation): + /// - L2CC_PDU_SEND: Send internal LE Legacy PDU + uint8_t operation; + /// offset value information + uint16_t offset; + /// PDU Data + struct l2cc_pdu pdu; +}; + + +/// Legacy PDU data received +/*@TRACE*/ +struct l2cc_pdu_recv_ind +{ + /// Status information + uint8_t status; + /// offset value information + uint16_t offset; + /// PDU Data + struct l2cc_pdu pdu; +}; + +/// Operation type +enum l2cc_op_type +{ + /// Operation used for signaling protocol message exchange + L2CC_OP_SIG = 0x00, + /// Max number of operations + L2CC_OP_MAX, +}; + +/* + * STRUCTURES + **************************************************************************************** + */ + + + +/// L2CAP environment structure +struct l2cc_env_tag +{ + /// Ongoing operation + void* operation[L2CC_OP_MAX]; + + /// Buffer in TX queue + struct co_list tx_queue; + /// Buffer currently receiving data + struct ke_msg* rx_buffer; + #if (BLE_LECB) + /// List of LE credit based connections + struct co_list lecb_list; + #endif // (BLE_LECB) + + /// Length of PDU still expected + uint16_t rx_pdu_rem_len; + /// Number of ACL buffer waiting to be transmitted. + uint8_t nb_tx_pending; + + /// Cursor into the the received header + uint8_t rx_cursor; + /// Expected cursor header length + uint8_t rx_exp_len; + /// Temporary buffer for reception of an l2cap packet + uint8_t rx_buf[L2C_HEADER_LEN + L2C_MIN_LE_MTUSIG]; +}; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Generic way to creates and allocate a PDU message that can be then sent to peer + * device + * + * @note use L2CC_SIG_PDU_ALLOC, L2CC_SMP_PDU_ALLOC, L2CC_ATT_PDU_ALLOC + * or L2CC_ATT_PDU_ALLOC_DYN instead of direct function call + * + * @param[in] conidx Connection Index + * @param[in] cid Channel Identifier + * @param[in] code PDU code + * @param[in] src_id Source task ID + * @param[in] length Dynamic payload length to allocate + * + * @return Generic pointer to the PDU payload + **************************************************************************************** + */ +void* l2cc_pdu_alloc(uint8_t conidx, uint16_t cid, uint8_t code, ke_task_id_t src_id, uint16_t length); + +/** + **************************************************************************************** + * @brief Generic way to send the PDU message + * + * @param[in] pdu PDU message to send to peer device + **************************************************************************************** + */ +void l2cc_pdu_send(void* pdu); + +#endif //(BLE_L2CC) + +/// @} L2CC + +#endif // L2CC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/l2cc_pdu.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/l2cc_pdu.h new file mode 100644 index 0000000..d19980c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/l2cc_pdu.h @@ -0,0 +1,1226 @@ +/** + **************************************************************************************** + * + * @file l2cc_pdu.h + * + * @brief Header file - L2CAP Controller PDU packer / unpacker + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _L2CC_PDU_H_ +#define _L2CC_PDU_H_ + +/** + **************************************************************************************** + * @addtogroup L2CC_PDU L2Cap Controller PDU generator/extractor + * @ingroup L2CC + * @brief This module is in charge to pack or unpack L2CAP packets + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "co_bt.h" +#include "gap.h" +#include "att.h" +#include "compiler.h" + +/* + * MACROS + **************************************************************************************** + */ + + +/* + * DEFINES + **************************************************************************************** + */ + +/// Minimal authorized MTU value (defined by Bluetooth SIG) +#define L2C_MIN_LE_MTUSIG (23) +/// Minimal authorized MTU value if secure connection is supported +#define L2C_MIN_LE_MTU_SEC_CON (65) + +/// L2CAP mode supported for BLE - only mode accepted +#define L2C_MODE_BASIC_L2CAP (0x00) + +/// Packet partition +#define L2C_CID_LEN (2) +#define L2C_LENGTH_LEN (2) +#define L2C_CODE_LEN (1) +#define L2C_HEADER_LEN (L2C_CID_LEN + L2C_LENGTH_LEN) +#define L2C_SDU_LEN (2) +#define L2C_LECB_HEADER_LEN (L2C_HEADER_LEN + L2C_SDU_LEN) + +/// Maximum credit +#define L2C_LECB_MAX_CREDIT 0xFFFF + + +/* result for connection parameter update response */ +#define L2C_CONN_PARAM_ACCEPT 0x0000 +#define L2C_CONN_PARAM_REJECT 0x0001 + +/* command reject reasons */ +enum l2cc_pdu_err +{ + L2C_CMD_NOT_UNDERSTOOD = 0x0000, + L2C_MTU_SIG_EXCEEDED = 0x0001, + L2C_INVALID_CID = 0x0002, +}; + +/// Check if channel ID is within the correct range +#define L2C_IS_DYNAMIC_CID(cid) ((cid >= L2C_CID_DYN_MIN) && (cid <= L2C_CID_DYN_MAX)) + +/// Check if LE PSM is within the correct range +#define L2C_IS_VALID_LEPSM(lepsm) (lepsm != L2C_LEPSM_RESERVED) + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/** L2CAP LE PSM limits */ +enum l2cc_lepsm_limits +{ + /// Reserved + L2C_LEPSM_RESERVED = 0x0000, + /// Fixed minimum range SIG assigned + L2C_LEPSM_FIXED_MIN = 0x0001, + /// Fixed maximum range SIG assigned + L2C_LEPSM_FIXED_MAX = 0x007F, + /// Dynamic minimum range SIG assigned + L2C_LEPSM_DYN_MIN = 0x0080, + /// Dynamic maximum range SIG assigned + L2C_LEPSM_DYN_MAX = 0x00FF, + /// Reserved minimum range SIG assigned + L2C_LEPSM_RSV_MIN = 0x0100, + /// Reserved maximum range SIG assigned + L2C_LEPSM_RSV_MAX = 0xFFFF, +}; + +/** L2CAP channels id */ +/*@TRACE*/ +enum l2cc_cid +{ + /// Reserved channel id + L2C_CID_RESERVED = 0x0000, + /// Attribute channel id + L2C_CID_ATTRIBUTE = 0x0004, + /// Signaling channel id + L2C_CID_LE_SIGNALING = 0x0005, + /// Security channel id + L2C_CID_SECURITY = 0x0006, + /// Dynamically allocated minimum range + L2C_CID_DYN_MIN = 0x0040, + /// Dynamically allocated maximum range + L2C_CID_DYN_MAX = 0x007F, +}; + + +/// signaling codes +/*@TRACE*/ +enum l2cc_signaling_code +{ + /// Reserved code + L2C_CODE_RESERVED = 0x00, + /// Reject request + L2C_CODE_REJECT = 0x01, + /// Connection request + L2C_CODE_CONNECTION_REQ = 0x02, + /// Connection response + L2C_CODE_CONNECTION_RESP = 0x03, + /// Configuration request + L2C_CODE_CONFIGURATION_REQ = 0x04, + /// Configuration response + L2C_CODE_CONFIGURATION_RESP = 0x05, + /// Disconnection request + L2C_CODE_DISCONNECTION_REQ = 0x06, + /// Disconnection response + L2C_CODE_DISCONNECTION_RESP = 0x07, + /// Echo request + L2C_CODE_ECHO_REQ = 0x08, + /// Echo response + L2C_CODE_ECHO_RESP = 0x09, + /// Information request + L2C_CODE_INFORMATION_REQ = 0x0A, + /// Information response + L2C_CODE_INFORMATION_RESP = 0x0B, + /// Create channel request + L2C_CODE_CREATE_CHANNEL_REQ = 0x0C, + /// Create channel response + L2C_CODE_CREATE_CHANNEL_RESP = 0x0D, + /// Move channel request + L2C_CODE_MOVE_CHANNEL_REQ = 0x0E, + /// Move channel response + L2C_CODE_MOVE_CHANNEL_RESP = 0x0F, + /// Move channel confirmation + L2C_CODE_MOVE_CHANNEL_CFM = 0x10, + /// Move channel confirmation response + L2C_CODE_MOVE_CHANNEL_CFM_RESP = 0x11, + /// Connection Parameter Update Request + L2C_CODE_CONN_PARAM_UPD_REQ = 0x12, + /// Connection Parameter Update Response + L2C_CODE_CONN_PARAM_UPD_RESP = 0x13, + /// LE Credit Based Connection request + L2C_CODE_LE_CB_CONN_REQ = 0x14, + /// LE Credit Based Connection response + L2C_CODE_LE_CB_CONN_RESP = 0x15, + /// LE Flow Control Credit + L2C_CODE_LE_FLOW_CONTROL_CREDIT = 0x16, + + /// max number of signaling codes + L2C_CODE_SIGNALING_MAX +}; + + +/// security codes +/*@TRACE*/ +enum l2cc_security_code +{ + /// Pairing Request + L2C_CODE_PAIRING_REQ = 0x01, + /// Pairing Response + L2C_CODE_PAIRING_RESP = 0x02, + /// Pairing Confirm + L2C_CODE_PAIRING_CFM = 0x03, + /// Pairing Random + L2C_CODE_PAIRING_RANDOM = 0x04, + /// Pairing Failed + L2C_CODE_PAIRING_FAILED = 0x05, + /// Encryption Information + L2C_CODE_ENCRYPTION_INF = 0x06, + /// Master Identification + L2C_CODE_MASTER_ID = 0x07, + /// Identity Information + L2C_CODE_IDENTITY_INF = 0x08, + /// Identity Address Information + L2C_CODE_ID_ADDR_INF = 0x09, + /// Signing Information + L2C_CODE_SIGNING_INF = 0x0A, + /// Security Request + L2C_CODE_SECURITY_REQ = 0x0B, + /// Pairing Public Keys + L2C_CODE_PUBLIC_KEY = 0x0C, + /// Pairing DHKey Check + L2C_CODE_DHKEY_CHECK = 0x0D, + /// Pairing Keypress Notification + L2C_CODE_KEYPRESS_NOTIFICATION = 0x0E, + /// max number of security codes + L2C_CODE_SECURITY_MAX +}; + + +/// attribute protocol PDU codes +/*@TRACE*/ +enum l2cc_attribute_code +{ + /// Error response + L2C_CODE_ATT_ERR_RSP = 0x01, + /// Exchange MTU Request + L2C_CODE_ATT_MTU_REQ = 0x02, + /// Exchange MTU Response + L2C_CODE_ATT_MTU_RSP = 0x03, + /// Find Information Request + L2C_CODE_ATT_FIND_INFO_REQ = 0x04, + /// Find Information Response + L2C_CODE_ATT_FIND_INFO_RSP = 0x05, + /// Find By Type Value Request + L2C_CODE_ATT_FIND_BY_TYPE_REQ = 0x06, + /// Find By Type Value Response + L2C_CODE_ATT_FIND_BY_TYPE_RSP = 0x07, + /// Read By Type Request + L2C_CODE_ATT_RD_BY_TYPE_REQ = 0x08, + /// Read By Type Response + L2C_CODE_ATT_RD_BY_TYPE_RSP = 0x09, + /// Read Request + L2C_CODE_ATT_RD_REQ = 0x0A, + /// Read Response + L2C_CODE_ATT_RD_RSP = 0x0B, + /// Read Blob Request + L2C_CODE_ATT_RD_BLOB_REQ = 0x0C, + /// Read Blob Response + L2C_CODE_ATT_RD_BLOB_RSP = 0x0D, + /// Read Multiple Request + L2C_CODE_ATT_RD_MULT_REQ = 0x0E, + /// Read Multiple Response + L2C_CODE_ATT_RD_MULT_RSP = 0x0F, + /// Read by Group Type Request + L2C_CODE_ATT_RD_BY_GRP_TYPE_REQ = 0x10, + /// Read By Group Type Response + L2C_CODE_ATT_RD_BY_GRP_TYPE_RSP = 0x11, + /// Write Request + L2C_CODE_ATT_WR_REQ = 0x12, + /// Write Response + L2C_CODE_ATT_WR_RSP = 0x13, + /// Write Command + L2C_CODE_ATT_WR_CMD_INFO = 0x14, + L2C_CODE_ATT_WR_CMD = 0x52, + /// Signed Write Command + L2C_CODE_ATT_SIGN_WR_CMD_INFO = 0x15, + L2C_CODE_ATT_SIGN_WR_CMD = 0xD2, + /// Prepare Write Request + L2C_CODE_ATT_PREP_WR_REQ = 0x16, + /// Prepare Write Response + L2C_CODE_ATT_PREP_WR_RSP = 0x17, + /// Execute Write Request + L2C_CODE_ATT_EXE_WR_REQ = 0x18, + /// Execute Write Response + L2C_CODE_ATT_EXE_WR_RSP = 0x19, + /// Handle Value Notification + L2C_CODE_ATT_HDL_VAL_NTF = 0x1B, + /// Handle Value Indication + L2C_CODE_ATT_HDL_VAL_IND = 0x1D, + /// Handle Value Confirmation + L2C_CODE_ATT_HDL_VAL_CFM = 0x1E, + + /// max number of security codes + L2C_CODE_ATT_MAX +}; + +/// LE Connection oriented PDU codes +enum l2cc_le_connor_code +{ + /// Data frame + L2C_CODE_CON_DATA = 0x01, + + /// max number of connection oriented codes + L2C_CODE_CON_MAX +}; + +/// Result values for LE Credit Based Connection Response +enum l2cc_cb_resp_value +{ + /// connection successful + L2C_CB_CON_SUCCESS = 0x0000, + /// Reserved + L2C_CB_CON_RSV1, + /// Connection refused - LE_PSM not supported + L2C_CB_CON_LEPSM_NOT_SUPP, + /// Reserved + L2C_CB_CON_RSV2, + /// Connection refused - no resources available + L2C_CB_CON_NO_RES_AVAIL, + /// Connection refused - insufficient authentication + L2C_CB_CON_INS_AUTH, + /// Connection refused - insufficient authorization + L2C_CB_CON_INS_AUTHOR, + /// Connection refused - insufficient encryption key size + L2C_CB_CON_INS_EKS, + /// Connection Refused - insufficient encryption + L2C_CB_CON_INS_ENCRYPTION, + + /* ESR 09 error codes */ + /// Connection Refused - invalid Source CID + L2C_CB_CON_INVALID_SRC_CID, + /// Connection Refused - Source CID already allocated + L2C_CB_CON_SRC_CID_ALREADY_ALLOC, + /// Connection Refused - Unacceptable parameters + L2C_CB_CON_UNACCEPTABLE_PARAM +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Disconnection Request +/*@TRACE*/ +struct l2cc_disconnection_req +{ + /// Signaling code - 0x06 + uint8_t code; + /// Packet Identifier + uint8_t pkt_id; + /// data length + uint16_t length; + /// Destination CID + uint16_t dcid; + /// Source CID + uint16_t scid; +}; + +/// Disconnection Response +/*@TRACE*/ +struct l2cc_disconnection_resp +{ + /// Signaling code - 0x07 + uint8_t code; + /// Packet Identifier + uint8_t pkt_id; + /// data length + uint16_t length; + /// Destination CID + uint16_t dcid; + /// Source CID + uint16_t scid; +}; + +/// Connection Parameter Update Request +/*@TRACE*/ +struct l2cc_conn_param_upd_req +{ + /// Signaling code - 0x12 + uint8_t code; + /// Packet Identifier + uint8_t pkt_id; + /// data length + uint16_t length; + /// minimum value for the connection event interval + uint16_t intv_min; + /// maximum value for the connection event interval + uint16_t intv_max; + /// slave latency parameter + uint16_t latency; + /// connection timeout parameter + uint16_t timeout; +}; + +/// Connection Parameter Update Response +/*@TRACE*/ +struct l2cc_conn_param_upd_resp +{ + /// Signaling code - 0x13 + uint8_t code; + /// Packet Identifier + uint8_t pkt_id; + /// data length + uint16_t length; + /// Result field indicates the response to the Connection Parameter Update Request + /// - 0x0000 Connection Parameters accepted + /// - 0x0001 Connection Parameters rejected + uint16_t response; +}; + +/// LE Credit based connection request +/*@TRACE*/ +struct l2cc_le_cb_conn_req +{ + /// Signaling code - 0x14 + uint8_t code; + /// Packet Identifier + uint8_t pkt_id; + /// data length + uint16_t length; + /// LE Protocol/Service Multiplexer + uint16_t le_psm; + /// Source CID + uint16_t scid; + /// Maximum Transmission Unit + uint16_t mtu; + /// Maximum PDU Size + uint16_t mps; + /// Initial credits + uint16_t initial_credits; +}; + +/// LE Credit based connection response +/*@TRACE*/ +struct l2cc_le_cb_conn_resp +{ + /// Signaling code - 0x15 + uint8_t code; + /// Packet Identifier + uint8_t pkt_id; + /// data length + uint16_t length; + /// Destination CID + uint16_t dcid; + /// Maximum Transmission Unit + uint16_t mtu; + /// Maximum PDU Size + uint16_t mps; + /// Initial credits + uint16_t initial_credits; + /// Result + uint16_t result; +}; + +/// LE Flow Control Credit +/*@TRACE*/ +struct l2cc_le_flow_control_credit +{ + /// Signaling code - 0x16 + uint8_t code; + /// Packet Identifier + uint8_t pkt_id; + /// data length + uint16_t length; + /// CID + uint16_t cid; + /// Credits + uint16_t credits; +}; + +/// Command Reject +/*@TRACE*/ +struct l2cc_reject +{ + /// Signaling code - 0x01 + uint8_t code; + /// Packet Identifier + uint8_t pkt_id; + /// data length + uint16_t length; + /// The Reason field describes why the Request packet was rejected + /// - 0x0000 Command not understood + /// - 0x0001 Signaling MTU exceeded + /// - 0x0002 Invalid CID in request + uint16_t reason; + /// Optional parameters total length + uint16_t opt_len; + ///16-byte array for optional parameters + uint8_t opt[__ARRAY_EMPTY]; +}; + + +/// Pairing Request +/*@TRACE*/ +struct l2cc_pairing_req +{ + /// security code - 0x01 + uint8_t code; + /// IO Capability + uint8_t iocap; + /// OOB data flag + uint8_t oob; + /// AuthReq + uint8_t auth; + /// Maximum Encryption Key Size + uint8_t key_size; + /// Initiator Key Distribution + uint8_t ikey_dist; + /// Responder Key Distribution + uint8_t rkey_dist; +}; +/// Pairing Response +/*@TRACE*/ +struct l2cc_pairing_resp +{ + /// security code - 0x02 + uint8_t code; + /// IO Capability + uint8_t iocap; + /// OOB data flag + uint8_t oob; + /// AuthReq + uint8_t auth; + /// Maximum Encryption Key Size + uint8_t key_size; + /// Initiator Key Distribution + uint8_t ikey_dist; + /// Responder Key Distribution + uint8_t rkey_dist; +}; +/// Pairing Confirm +/*@TRACE*/ +struct l2cc_pairing_cfm +{ + /// security code - 0x03 + uint8_t code; + ///Confirm value + uint8_t cfm_val[CFM_LEN]; +}; +/// Pairing Random +/*@TRACE*/ +struct l2cc_pairing_random +{ + /// security code - 0x04 + uint8_t code; + ///Random value + uint8_t random[RAND_VAL_LEN]; +}; +/// Pairing Failed +/*@TRACE*/ +struct l2cc_pairing_failed +{ + /// security code - 0x05 + uint8_t code; + /// The Reason field indicates why the pairing failed + uint8_t reason; +}; +/// Encryption Information +/*@TRACE*/ +struct l2cc_encryption_inf +{ + /// security code - 0x06 + uint8_t code; + ///16-byte array for LTK value + uint8_t ltk[GAP_KEY_LEN]; +}; +/// Master Identification +/*@TRACE*/ +struct l2cc_master_id +{ + /// security code - 0x07 + uint8_t code; + /// key diversifier + uint16_t ediv; + ///8-byte array for random number + uint8_t nb[GAP_RAND_NB_LEN]; +}; +/// Identity Information +/*@TRACE*/ +struct l2cc_identity_inf +{ + /// security code - 0x08 + uint8_t code; + ///16-byte array for IRK value + uint8_t irk[GAP_KEY_LEN]; +}; +/// Identity Address Information +/*@TRACE*/ +struct l2cc_id_addr_inf +{ + /// security code - 0x09 + uint8_t code; + /// BD Address Type + uint8_t addr_type; + /// BD Address + bd_addr_t addr; +}; +/// Signing Information +/*@TRACE*/ +struct l2cc_signing_inf +{ + /// security code - 0x0A + uint8_t code; + ///16-byte array for CSRK value + uint8_t csrk[GAP_KEY_LEN]; +}; +/// Security Request +/*@TRACE*/ +struct l2cc_security_req +{ + /// security code - 0x0B + uint8_t code; + /// AuthReq + uint8_t auth; +}; + +/// Public Key (x,y) +/*@TRACE*/ +struct l2cc_public_key +{ + /// security code - 0x0C + uint8_t code; + /// X and Y co-ordinates of the Public Key + uint8_t x[GAP_P256_KEY_LEN]; + uint8_t y[GAP_P256_KEY_LEN]; +}; + +/// DH Key Check +/*@TRACE*/ +struct l2cc_dhkey_check +{ + /// security code - 0x0D + uint8_t code; + uint8_t check[DHKEY_CHECK_LEN]; +}; +/// Keypress Notification - PassKey method only +/*@TRACE*/ +struct l2cc_keypress_notification +{ + /// security code - 0x0E + uint8_t code; + + uint8_t notification_type; +}; + + +/* Attribute protocol PDUs */ + +/// Error response +/*@TRACE*/ +struct l2cc_att_err_rsp +{ + /// Error Response - 0x01 + uint8_t code; + /// The request that generated this error response + uint8_t op_code; + /// The attribute handle that generated this error response + uint16_t handle; + ///The reason why the request has generated an error response + uint8_t reason; +}; + +/// Exchange MTU Request +/*@TRACE*/ +struct l2cc_att_mtu_req +{ + /// Exchange MTU Request - 0x02 + uint8_t code; + /// Client Rx MTU size + uint16_t mtu_size; +}; + +/// Exchange MTU Response +/*@TRACE*/ +struct l2cc_att_mtu_rsp +{ + /// Exchange MTU Response - 0x03 + uint8_t code; + /// Server Rx MTU size + uint16_t mtu_size; +}; + +/// Find Information Request +/*@TRACE*/ +struct l2cc_att_find_info_req +{ + /// Find Information Request - 0x04 + uint8_t code; + /// First requested handle number + uint16_t shdl; + /// Last requested handle number + uint16_t ehdl; +}; + +/// Find Information Response +/*@TRACE*/ +struct l2cc_att_find_info_rsp +{ + /// Find Information Response - 0x05 + uint8_t code; + /// The format of the information data. + uint8_t format; + /// Data length + uint16_t data_len; + ///The information data whose format is determined by the Format field + uint8_t data[__ARRAY_EMPTY]; +}; + +/// Find By Type Value Request +/*@TRACE*/ +struct l2cc_att_find_by_type_req +{ + /// Find By Type Value Request - 0x06 + uint8_t code; + /// First requested handle number + uint16_t shdl; + /// Last requested handle number + uint16_t ehdl; + /// 2 octet UUID to find + uint16_t type; + /// Attribute value length + uint16_t val_len; + /// Attribute value to find + uint8_t val[__ARRAY_EMPTY]; +}; + +/// Find By Type Value Response +/*@TRACE*/ +struct l2cc_att_find_by_type_rsp +{ + /// Find By Type Value Response - 0x07 + uint8_t code; + /// data length + uint16_t data_len; + /// A list of 1 or more Handle Informations. + uint8_t data[__ARRAY_EMPTY]; +}; + +/// Read By Type Request +/*@TRACE*/ +struct l2cc_att_rd_by_type_req +{ + /// Read By Type Request - 0x08 + uint8_t code; + /// Starting Handle + uint16_t shdl; + /// Ending Handle + uint16_t ehdl; + /// Attribute uuid length + uint16_t uuid_len; + /// Attribute type uuid + uint8_t uuid[__ARRAY_EMPTY]; +}; + +/// Read By Type Response +/*@TRACE*/ +struct l2cc_att_rd_by_type_rsp +{ + /// Read By Type Response - 0x09 + uint8_t code; + /// size of each attribute handle listed + uint8_t each_len; + /// Attribute Data length + uint16_t data_len; + /// A list of Attribute Data. + uint8_t data[__ARRAY_EMPTY]; +}; + +/// Read Request +/*@TRACE*/ +struct l2cc_att_rd_req +{ + /// Read Request - 0x0A + uint8_t code; + /// Attribute Handle + uint16_t handle; +}; + +/// Read Response +/*@TRACE*/ +struct l2cc_att_rd_rsp +{ + /// Read Response - 0x0B + uint8_t code; + /// value length + uint16_t value_len; + /// The value of the attribute with the handle given + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Read Blob Request +/*@TRACE*/ +struct l2cc_att_rd_blob_req +{ + /// Read Blob Request - 0x0C + uint8_t code; + /// Attribute Handle + uint16_t handle; + /// The offset of the first octet to be read + uint16_t offset; +}; + +/// Read Blob Response +/*@TRACE*/ +struct l2cc_att_rd_blob_rsp +{ + /// Read Blob Response - 0x0D + uint8_t code; + /// value length + uint16_t value_len; + /// Part of the value of the attribute with the handle given + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Read Multiple Request +/*@TRACE*/ +struct l2cc_att_rd_mult_req +{ + /// Read Multiple Request - 0x0E + uint8_t code; + /// Number of handles + uint16_t nb_handles; + /// A set of two or more attribute handles. + uint16_t handles[__ARRAY_EMPTY]; +}; + +/// Read Multiple Response +/*@TRACE*/ +struct l2cc_att_rd_mult_rsp +{ + /// Read Multiple Response - 0x0F + uint8_t code; + /// value length + uint16_t value_len; + /// A set of two or more values. + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Read by Group Type Request +/*@TRACE*/ +struct l2cc_att_rd_by_grp_type_req +{ + /// Read by Group Type Request - 0x10 + uint8_t code; + /// First requested handle number + uint16_t shdl; + /// Last requested handle number + uint16_t ehdl; + /// Attribute uuid length + uint16_t uuid_len; + /// Attribute type uuid (2 or 16 octet UUID) + uint8_t uuid[__ARRAY_EMPTY]; +}; + +/// Read By Group Type Response +/*@TRACE*/ +struct l2cc_att_rd_by_grp_type_rsp +{ + /// Read By Group Type Response - 0x11 + uint8_t code; + /// size of each attribute handle listed + uint8_t each_len; + /// Attribute Data length + uint16_t data_len; + /// A list of Attribute Data. + uint8_t data[__ARRAY_EMPTY]; +}; + +/// Write Request +/*@TRACE*/ +struct l2cc_att_wr_req +{ + /// Write Request - 0x12 + uint8_t code; + /// The handle of the attribute to be written + uint16_t handle; + /// Value length + uint16_t value_len; + /// The value to be written to the attribute + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Write Response +/*@TRACE*/ +struct l2cc_att_wr_rsp +{ + /// Write Response - 0x13 + uint8_t code; +}; + +/// Write Command +/*@TRACE + * l2cc_att_wr_cmd_info = l2cc_att_wr_cmd + */ +struct l2cc_att_wr_cmd +{ + /// Write Command - 0x52 + uint8_t code; + /// The handle of the attribute to be written + uint16_t handle; + /// Value length + uint16_t value_len; + /// The value to be written to the attribute + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Signed Write Command +/*@TRACE + * l2cc_att_sign_wr_cmd_info = l2cc_att_sign_wr_cmd + */ +struct l2cc_att_sign_wr_cmd +{ + /// Write Command - 0xD2 + uint8_t code; + /// The handle of the attribute to be written + uint16_t handle; + /// Attribute Data length + uint16_t value_len; + /// The value to be written to the attribute + /// + 12 bytes of signatures: + /// Authentication signature for the Attribute Upload, Attribute Handle and Attribute + /// Value Parameters + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Prepare Write Request +/*@TRACE*/ +struct l2cc_att_prep_wr_req +{ + /// Prepare Write Request - 0x16 + uint8_t code; + /// The handle of the attribute to be written + uint16_t handle; + /// The offset of the first octet to be written + uint16_t offset; + /// Value length + uint16_t value_len; + /// The value to be written to the attribute + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Prepare Write Response +/*@TRACE*/ +struct l2cc_att_prep_wr_rsp +{ + /// Prepare Write Response - 0x17 + uint8_t code; + /// The handle of the attribute to be written + uint16_t handle; + /// The offset of the first octet to be written + uint16_t offset; + /// Value length + uint16_t value_len; + /// The value to be written to the attribute + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Execute Write Request +/*@TRACE*/ +struct l2cc_att_exe_wr_req +{ + /// Execute Write Request - 0x18 + uint8_t code; + /// 0x00 - Cancel all prepared writes + /// 0x01 - Immediately write all pending prepared values + uint8_t flags; +}; + +/// Execute Write Response +/*@TRACE*/ +struct l2cc_att_exe_wr_rsp +{ + /// Prepare Write Response - 0x19 + uint8_t code; +}; + +/// Handle Value Notification +/*@TRACE*/ +struct l2cc_att_hdl_val_ntf +{ + /// Handle Value Notification - 0x1B + uint8_t code; + /// The handle of the attribute to be written + uint16_t handle; + /// Value length + uint16_t value_len; + /// The current value of the attribute + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Handle Value Indication +/*@TRACE*/ +struct l2cc_att_hdl_val_ind +{ + /// Handle Value Indication - 0x1D + uint8_t code; + /// The handle of the attribute to be written + uint16_t handle; + /// Value length + uint16_t value_len; + /// The current value of the attribute + uint8_t value[__ARRAY_EMPTY]; +}; + +/// Handle Value Confirmation +/*@TRACE*/ +struct l2cc_att_hdl_val_cfm +{ + /// Handle Value Confirmation - 0x1E + uint8_t code; +}; + +/* LE Credit Based PDUs */ + +/// LE Generic send data request (includes total SDU Length) +/*@TRACE*/ +struct l2cc_lecb_send_data_req +{ + /// Code variable (RFU) + uint8_t code; + /// SDU data length + uint16_t sdu_data_len; + /// Data + uint8_t sdu_data[__ARRAY_EMPTY]; +}; + + +struct l2cc_pdu_data_t +{ + /// L2Cap packet code. + uint8_t code; +}; + +/*@TRACE + @trc_ref l2cc_cid, l2cc_signaling_code, l2cc_attribute_code, l2cc_security_code + */ +union l2cc_pdu_data +{ + /// L2Cap packet code. + uint8_t code; + + /* LE Credit Based packets */ + /// LE send first frame + //@trc_union parent.chan_id >= L2C_CID_DYN_MIN and parent.chan_id <= L2C_CID_DYN_MAX + struct l2cc_lecb_send_data_req send_lecb_data_req; + + /* Connection Signaling Packets */ + /// Command Reject + //@trc_union code == L2C_CODE_REJECT and parent.chan_id == L2C_CID_LE_SIGNALING + struct l2cc_reject reject; + /// Connection Parameter Update Request + //@trc_union code == L2C_CODE_CONN_PARAM_UPD_REQ and parent.chan_id == L2C_CID_LE_SIGNALING + struct l2cc_conn_param_upd_req update_req; + /// Connection Parameter Update Response + //@trc_union code == L2C_CODE_CONN_PARAM_UPD_RESP and parent.chan_id == L2C_CID_LE_SIGNALING + struct l2cc_conn_param_upd_resp update_rsp; + /// LE Credit based connection request + //@trc_union code == L2C_CODE_LE_CB_CONN_REQ and parent.chan_id == L2C_CID_LE_SIGNALING + struct l2cc_le_cb_conn_req credit_con_req; + /// LE Credit based connection response + //@trc_union code == L2C_CODE_LE_CB_CONN_RESP and parent.chan_id == L2C_CID_LE_SIGNALING + struct l2cc_le_cb_conn_resp credit_con_rsp; + /// LE Flow Control Credit + //@trc_union code == L2C_CODE_LE_FLOW_CONTROL_CREDIT and parent.chan_id == L2C_CID_LE_SIGNALING + struct l2cc_le_flow_control_credit flow_ctl_credit; + /// LE disconnection request + //@trc_union code == L2C_CODE_DISCONNECTION_REQ and parent.chan_id == L2C_CID_LE_SIGNALING + struct l2cc_disconnection_req disc_req; + /// LE disconnection response + //@trc_union code == L2C_CODE_DISCONNECTION_RESP and parent.chan_id == L2C_CID_LE_SIGNALING + struct l2cc_disconnection_resp disc_rsp; + + /* Security manager PDUs */ + /// Pairing Request + //@trc_union code == L2C_CODE_PAIRING_REQ and parent.chan_id == L2C_CID_SECURITY + struct l2cc_pairing_req pairing_req; + /// Pairing Response + //@trc_union code == L2C_CODE_PAIRING_RESP and parent.chan_id == L2C_CID_SECURITY + struct l2cc_pairing_resp pairing_rsp; + /// Pairing Confirm + //@trc_union code == L2C_CODE_PAIRING_CFM and parent.chan_id == L2C_CID_SECURITY + struct l2cc_pairing_cfm pairing_cfm; + /// Pairing Random + //@trc_union code == L2C_CODE_PAIRING_RANDOM and parent.chan_id == L2C_CID_SECURITY + struct l2cc_pairing_random pairing_random; + /// Pairing Failed + //@trc_union code == L2C_CODE_PAIRING_FAILED and parent.chan_id == L2C_CID_SECURITY + struct l2cc_pairing_failed pairing_failed; + /// Encryption Information + //@trc_union code == L2C_CODE_ENCRYPTION_INF and parent.chan_id == L2C_CID_SECURITY + struct l2cc_encryption_inf encryption_inf; + /// Master Identification + //@trc_union code == L2C_CODE_MASTER_ID and parent.chan_id == L2C_CID_SECURITY + struct l2cc_master_id master_id; + /// Identity Information + //@trc_union code == L2C_CODE_IDENTITY_INF and parent.chan_id == L2C_CID_SECURITY + struct l2cc_identity_inf identity_inf; + /// Identity Address Information + //@trc_union code == L2C_CODE_ID_ADDR_INF and parent.chan_id == L2C_CID_SECURITY + struct l2cc_id_addr_inf id_addr_inf; + /// Signing Information + //@trc_union code == L2C_CODE_SIGNING_INF and parent.chan_id == L2C_CID_SECURITY + struct l2cc_signing_inf signing_inf; + /// Security Request + //@trc_union code == L2C_CODE_SECURITY_REQ and parent.chan_id == L2C_CID_SECURITY + struct l2cc_security_req security_req; + /// Public Keys + //@trc_union code == L2C_CODE_PUBLIC_KEY and parent.chan_id == L2C_CID_SECURITY + struct l2cc_public_key public_key; + /// Key Press Notification + //@trc_union code == L2C_CODE_KEYPRESS_NOTIFICATION and parent.chan_id == L2C_CID_SECURITY + struct l2cc_keypress_notification keypress_notification; + /// DH Key Check + //@trc_union code == L2C_CODE_DHKEY_CHECK and parent.chan_id == L2C_CID_SECURITY + struct l2cc_dhkey_check dhkey_check; + + /* Attribute protocol PDUs */ + /// Error response + //@trc_union code == L2C_CODE_ATT_ERR_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_err_rsp err_rsp; + /// Exchange MTU Request + //@trc_union code == L2C_CODE_ATT_MTU_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_mtu_req mtu_req; + /// Exchange MTU Response + //@trc_union code == L2C_CODE_ATT_MTU_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_mtu_rsp mtu_rsp; + /// Find Information Request + //@trc_union code == L2C_CODE_ATT_FIND_INFO_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_find_info_req find_info_req; + /// Find Information Response + //@trc_union code == L2C_CODE_ATT_FIND_INFO_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_find_info_rsp find_info_rsp; + /// Find By Type Value Request + //@trc_union code == L2C_CODE_ATT_FIND_BY_TYPE_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_find_by_type_req find_by_type_req; + /// Find By Type Value Response + //@trc_union code == L2C_CODE_ATT_FIND_BY_TYPE_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_find_by_type_rsp find_by_type_rsp; + /// Read By Type Request + //@trc_union code == L2C_CODE_ATT_RD_BY_TYPE_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_rd_by_type_req rd_by_type_req; + /// Read By Type Response + //@trc_union code == L2C_CODE_ATT_RD_BY_TYPE_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_rd_by_type_rsp rd_by_type_rsp; + /// Read Request + //@trc_union code == L2C_CODE_ATT_RD_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_rd_req rd_req; + /// Read Response + //@trc_union code == L2C_CODE_ATT_RD_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_rd_rsp rd_rsp; + /// Read Blob Request + //@trc_union code == L2C_CODE_ATT_RD_BLOB_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_rd_blob_req rd_blob_req; + /// Read Blob Response + //@trc_union code == L2C_CODE_ATT_RD_BLOB_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_rd_blob_rsp rd_blob_rsp; + /// Read Multiple Request + //@trc_union code == L2C_CODE_ATT_RD_MULT_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_rd_mult_req rd_mult_req; + /// Read Multiple Response + //@trc_union code == L2C_CODE_ATT_RD_MULT_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_rd_mult_rsp rd_mult_rsp; + /// Read by Group Type Request + //@trc_union code == L2C_CODE_ATT_RD_BY_GRP_TYPE_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_rd_by_grp_type_req rd_by_grp_type_req; + /// Read By Group Type Response + //@trc_union code == L2C_CODE_ATT_RD_BY_GRP_TYPE_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_rd_by_grp_type_rsp rd_by_grp_type_rsp; + /// Write Request + //@trc_union code == L2C_CODE_ATT_WR_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_wr_req wr_req; + /// Write Response + //@trc_union code == L2C_CODE_ATT_WR_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_wr_rsp wr_rsp; + /// Write Command + //@trc_union code == L2C_CODE_ATT_WR_CMD and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_wr_cmd wr_cmd; + /// Signed Write Command + //@trc_union code == L2C_CODE_ATT_SIGN_WR_CMD and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_sign_wr_cmd sign_wr_cmd; + /// Prepare Write Request + //@trc_union code == L2C_CODE_ATT_PREP_WR_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_prep_wr_req prep_wr_req; + /// Prepare Write Response + //@trc_union code == L2C_CODE_ATT_PREP_WR_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_prep_wr_rsp prep_wr_rsp; + /// Execute Write Request + //@trc_union code == L2C_CODE_ATT_EXE_WR_REQ and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_exe_wr_req exe_wr_req; + /// Execute Write Response + //@trc_union code == L2C_CODE_ATT_EXE_WR_RSP and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_exe_wr_rsp exe_wr_rsp; + /// Handle Value Notification + //@trc_union code == L2C_CODE_ATT_HDL_VAL_NTF and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_hdl_val_ntf hdl_val_ntf; + /// Handle Value Indication + //@trc_union code == L2C_CODE_ATT_HDL_VAL_IND and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_hdl_val_ind hdl_val_ind; + /// Handle Value Confirmation + //@trc_union code == L2C_CODE_ATT_HDL_VAL_CFM and parent.chan_id == L2C_CID_ATTRIBUTE + struct l2cc_att_hdl_val_cfm hdl_val_cfm; +}; + +/// Default L2Cap PDU definition +/*@TRACE*/ +struct l2cc_pdu +{ + /// L2Cap Payload Length + uint16_t payld_len; + /// L2Cap Channel ID + uint16_t chan_id; + /// Data PDU definition + union l2cc_pdu_data data; +}; + + +/// Default L2Cap DBG pdu definition +/*@TRACE*/ +struct l2cc_dbg_pdu +{ + /// Data length + uint16_t length; + /// data + uint8_t data[__ARRAY_EMPTY]; +}; + +/// Default L2Cap SDU definition +struct l2cc_sdu; + + +/// @} L2CC_PDU + + +#endif /* _L2CC_PDU_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/l2cm.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/l2cm.h new file mode 100644 index 0000000..7a11dab --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/l2cm.h @@ -0,0 +1,127 @@ +/** + **************************************************************************************** + * + * @file l2cm.h + * + * @brief Header file - L2CM. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef L2CM_H_ +#define L2CM_H_ + +/** + **************************************************************************************** + * @addtogroup L2C Logical Link Control and Adaptation Protocol + * @ingroup HOST + * @brief Logical Link Control and Adaptation Protocol - BLE Host. + * + * The L2C module is responsible for L2CAP provides connection-oriented + * and connection-less data services to upper layer protocols with protocol + * multiplexing capability and segmentation and re-assembly operation. + * + * @{ + **************************************************************************************** + */ +/** + **************************************************************************************** + * @addtogroup L2CM L2CAP Manager + * @ingroup L2C + * @brief L2CAP block for signaling and resource management functions + * + * The L2CM is an internal L2CAP block responsible for managing + * the signaling messages and propagation of connection and disconnection + * related L2CAP messages within the Host. + * + * @{ + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_L2CM) +#include +#include + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Create and Initialize the L2CAP manager task. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + * + **************************************************************************************** + */ +void l2cm_init(uint8_t init_type); + + + +/** + **************************************************************************************** + * @brief Allocates an L2CAP resource. + * + * @param[in] conidx connection index + * + **************************************************************************************** + */ +void l2cm_create(uint8_t conidx); + +/** + **************************************************************************************** + * @brief De-initializes the L2CAP resources for specified link. + * + * @param[in] conidx connection index + * + **************************************************************************************** + */ +void l2cm_cleanup(uint8_t conidx); + + +/** + **************************************************************************************** + * @brief Sets link layer buffer size capacity + * + * @param[in] pkt_len length of the packet + * @param[in] nb_acl number of acl + * + **************************************************************************************** + */ +void l2cm_set_link_layer_buff_size(uint16_t pkt_len, uint16_t nb_acl); + +/** + **************************************************************************************** + * @brief Retrieve number of low layer buffer available + * + * @return Number of low layer buffer available + **************************************************************************************** + */ +uint16_t l2cm_get_nb_buffer_available(void); + +/// @} L2CM + +#endif //(BLE_L2CM) + +#endif // L2CM_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/prf.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/prf.h new file mode 100644 index 0000000..28ca751 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/prf.h @@ -0,0 +1,363 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file prf.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +#ifndef _PRF_H_ +#define _PRF_H_ + +/** + **************************************************************************************** + * @addtogroup PROFILE PROFILES + * @ingroup ROOT + * @brief Bluetooth Low Energy Host Profiles + * + * The PROFILE of the stack contains the profile layers (@ref PROX "PROXIMITY", + * @ref HTP "HTP",@ref FIND "FIND ME" @ref BPS "Blood Pressure"). + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup PRF + * @ingroup PROFILE + * @brief Definitions of Profile management API + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_PROFILES) + +#include "ke_task.h" +#include "gapm_task.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/** + * Profile task fields + * + * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ + * | MI | TASK Number | + * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ + * + * Bit [0-14] : Task number value + * Bit [15] : Task is multi-instantiated (Connection index is conveyed) + */ +enum prf_perm_mask +{ + /// Task number value + PERM_MASK_PRF_TASK = 0x7FFF, + PERM_POS_PRF_TASK = 0, + /// Task is multi-instantiated + PERM_MASK_PRF_MI = 0x8000, + PERM_POS_PRF_MI = 15, +}; +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/// Profile Environment Data +typedef struct prf_env +{ + /// Application Task Number - if MSB bit set, Multi-Instantiated task + ke_task_id_t app_task; + /// Profile Task Number - if MSB bit set, Multi-Instantiated task + ke_task_id_t prf_task; +} prf_env_t; + + + +/// Profile task environment variable definition to dynamically allocate a Task. +struct prf_task_env +{ + /// Profile Task description + struct ke_task_desc desc; + /// pointer to the allocated memory used by profile during runtime. + prf_env_t* env; + /// Profile Task Number + ke_task_id_t task; + /// Profile Task Identifier + ke_task_id_t id; +}; + +/** + **************************************************************************************** + * @brief Initialization of the Profile module. + * This function performs all the initializations of the Profile module. + * - Creation of database (if it's a service) + * - Allocation of profile required memory + * - Initialization of task descriptor to register application + * - Task State array + * - Number of tasks + * - Default task handler + * + * @param[out] env Collector or Service allocated environment data. + * @param[in|out] start_hdl Service start handle (0 - dynamically allocated), only applies for services. + * @param[in] app_task Application task number. + * @param[in] sec_lvl Security level (AUTH, EKS and MI field of @see enum attm_value_perm_mask) + * @param[in] param Configuration parameters of profile collector or service (32 bits aligned) + * + * @return status code to know if profile initialization succeed or not. + **************************************************************************************** + */ +typedef uint8_t (*prf_init_fnct) (struct prf_task_env* env, uint16_t* start_hdl, uint16_t app_task, uint8_t sec_lvl, void* params); + +/** + **************************************************************************************** + * @brief Destruction of the Profile module - due to a reset for instance. + * This function clean-up allocated memory (attribute database is destroyed by another + * procedure) + * + * @param[in|out] env Collector or Service allocated environment data. + **************************************************************************************** + */ +typedef void (*prf_destroy_fnct) (struct prf_task_env* env); + +/** + **************************************************************************************** + * @brief Handles Connection creation + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + **************************************************************************************** + */ +typedef void (*prf_create_fnct) (struct prf_task_env* env, uint8_t conidx); + +/** + **************************************************************************************** + * @brief Handles Disconnection + * + * @param[in|out] env Collector or Service allocated environment data. + * @param[in] conidx Connection index + * @param[in] reason Detach reason + **************************************************************************************** + */ +typedef void (*prf_cleanup_fnct) (struct prf_task_env* env, uint8_t conidx, uint8_t reason); + +/// Profile task callbacks. +struct prf_task_cbs +{ + /// Initialization callback + prf_init_fnct init; + /// Destroy profile callback + prf_destroy_fnct destroy; + /// Connection callback + prf_create_fnct create; + /// Disconnection callback + prf_cleanup_fnct cleanup; +}; + + +/// Profile Manager environment structure +struct prf_env_tag +{ + /// Array of profile tasks that can be managed by Profile manager. + struct prf_task_env prf[BLE_NB_PROFILES]; +}; + +/// Profile get function struct +struct prf_get_func_t +{ + uint16_t task_id; + const struct prf_task_cbs* (*prf_itf_get_func)(void); +}; +struct prf_get_itf_tag +{ + uint8_t prf_num; + struct prf_get_func_t get_func_list[BLE_NB_PROFILES]; +}; + +/* + * MACROS + **************************************************************************************** + */ + + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ +extern struct prf_env_tag prf_env; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Perform Profile initialization + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void prf_init(uint8_t init_type); + + +/** + **************************************************************************************** + * @brief Create Profile (collector or service) task creation and initialize it. + * + * @param[in|out] params Collector or Service parameter used for profile task creation + * @param[out] prf_task Allocated Task number + * + * @return status of adding profile task + **************************************************************************************** + */ +uint8_t prf_add_profile(struct gapm_profile_task_add_cmd * params, ke_task_id_t *prf_task); + + +/** + **************************************************************************************** + * @brief Link creation event, update profiles states. + * + * @param[in] conidx connection index + * + **************************************************************************************** + */ +void prf_create(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Link disconnection event, clean-up profiles. + * + * @param[in] conidx connection index + * @param[in] reason detach reason + * + **************************************************************************************** + */ +void prf_cleanup(uint8_t conidx, uint8_t reason); + + + +/** + **************************************************************************************** + * @brief Retrieve environment variable allocated for a profile + * + * @param[in] prf_id Profile Task Identifier + * + * @return Environment variable allocated for a profile + **************************************************************************************** + */ +prf_env_t* prf_env_get(uint16_t prf_id); + + +/** + **************************************************************************************** + * @brief Retrieve source profile task number value + * + * @param[in] env Profile Environment + * @param[in] conidx Connection index + * + * @return Source profile task number value + **************************************************************************************** + */ +ke_task_id_t prf_src_task_get(prf_env_t* env, uint8_t conidx); + +/** + **************************************************************************************** + * @brief Retrieve destination application task number value + * + * @param[in] env Profile Environment + * @param[in] conidx Connection index + * + * @return Destination application task number value + **************************************************************************************** + */ +ke_task_id_t prf_dst_task_get(prf_env_t* env, uint8_t conidx); + + +/** + **************************************************************************************** + * @brief Retrieve Task Identifier from Task number + * (automatically update index of task in returned task id) + * + * @param task Task number + * @return Task Identifier + **************************************************************************************** + */ +ke_task_id_t prf_get_id_from_task(ke_msg_id_t task); + +/** + **************************************************************************************** + * @brief Retrieve Task Number from Task Identifier + * (automatically update index of task in returned task id) + * + * @param id Task Identifier + * @return Task Number + **************************************************************************************** + */ +ke_task_id_t prf_get_task_from_id(ke_msg_id_t id); +bool prf_get_itf_func_register(struct prf_get_func_t *prf); +#endif // (BLE_PROFILES) + +/// @} PRF + +#endif /* _PRF_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/prf_utils.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/prf_utils.h new file mode 100644 index 0000000..b8c06b8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/prf_utils.h @@ -0,0 +1,398 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file prf_utils.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _PRF_UTILS_H_ +#define _PRF_UTILS_H_ + +/** + **************************************************************************************** + * @addtogroup PRF_UTILS + * @ingroup PROFILE + * + * @brief Definitions of shared profiles functions that can be used by several profiles + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#if (BLE_SERVER_PRF || BLE_CLIENT_PRF) +#include "ke_msg.h" +#include "prf_types.h" +#include "gattc_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "attm.h" +#include "prf.h" +#endif /* (BLE_SERVER_PRF || BLE_CLIENT_PRF) */ + +/* + * MACROS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Macro used to called the prf_client_get_env function. + * + * @param prf_id Profile Task ID (In Upper case, ex: HTPC, DISC, ...) + * @param type Profile task type (In lower case, ex: htpc, disc, ...) + **************************************************************************************** + */ +#define PRF_ENV_GET(prf_id, type) \ + ((struct type ## _env_tag *)prf_env_get((TASK_ID_##prf_id))) + + + +// 16 bits attributes in a 128 bits array +#define ATT_16_TO_128_ARRAY(uuid) { (uuid) & 0xFF, (uuid >> 8) & 0xFF, 0,0,0,0,0,0,0,0,0,0,0,0,0,0 } +// +#define ATT_128_PRIMARY_SERVICE ATT_16_TO_128_ARRAY(ATT_DECL_PRIMARY_SERVICE) +#define ATT_128_CHARACTERISTIC ATT_16_TO_128_ARRAY(ATT_DECL_CHARACTERISTIC) +#define ATT_128_CLIENT_CHAR_CFG ATT_16_TO_128_ARRAY(ATT_DESC_CLIENT_CHAR_CFG) + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +#if (BLE_BATT_SERVER) +/** + **************************************************************************************** + * @brief Pack Characteristic Presentation Format descriptor value + **************************************************************************************** + */ +void prf_pack_char_pres_fmt(uint8_t *packed_val, const struct prf_char_pres_fmt* char_pres_fmt); +#endif // (BLE_BATT_SERVER) + +#if (BLE_BATT_CLIENT) +/** + **************************************************************************************** + * @brief Unpack Characteristic Presentation Format descriptor value + **************************************************************************************** + */ +void prf_unpack_char_pres_fmt(const uint8_t *packed_val, struct prf_char_pres_fmt* char_pres_fmt); +#endif // (BLE_BATT_CLIENT) + +#if (BLE_CLIENT_PRF) +/** + **************************************************************************************** + * @brief Request peer device to read an attribute + * + * @param[in] prf_env Pointer to profile information + * + * @param conidx Connection index + * @param shdl Search Start Handle + * @param ehdl Search End Handle + * + * @param valhdl Value Handle + * + * @note: if attribute is invalid, nothing is registered + **************************************************************************************** + */ +void prf_read_char_send(prf_env_t *prf_env, uint8_t conidx, + uint16_t shdl, uint16_t ehdl, uint16_t valhdl); + + +/** + **************************************************************************************** + * @brief register attribute handle in GATT + * + * @param[in] prf_env Pointer to profile information + * + * @param conidx Connection index + * @param svc Service to register + * + * @note: if attribute is invalid, nothing is registered + **************************************************************************************** + */ +void prf_register_atthdl2gatt(prf_env_t *prf_env, uint8_t conidx, struct prf_svc *svc); + +/** + **************************************************************************************** + * @brief Unregister attribute handle in GATT + * + * @param[in] prf_env Pointer to profile information + * + * @param conidx Connection index + * @param svc Service to register + * + * @note: if attribute is invalid, nothing is registered + **************************************************************************************** + */ +void prf_unregister_atthdl2gatt(prf_env_t *prf_env, uint8_t conidx, struct prf_svc *svc); + +/** + **************************************************************************************** + * @brief Request service discovery on peer device. + * + * This request will be used to retrieve start and end handles of the service. + * + * @param[in] prf_env Pointer to profile information + * + * @param conidx Connection index + * @param uuid Service UUID + **************************************************************************************** + */ +void prf_disc_svc_send(prf_env_t *prf_env,uint8_t conidx, uint16_t uuid); + +/** + **************************************************************************************** + * @brief Request service characteristic discovery on peer device. + * + * This request service to provide all its service characteristic information. + * + * @param[in] env Pointer to profile information + * @param[in] svc pointer to service handles (start and end handles) + * @param[in] conidx Connection index + **************************************************************************************** + */ +void prf_disc_char_all_send( prf_env_t *env, struct prf_svc *svc, uint8_t conidx); + +/** + **************************************************************************************** + * @brief Request characteristic descriptor discovery in a generic manner. + * + * It will request discovery of all characteristic descriptors for the giben service + * + * @param[in] env Pointer to profile information + * @param[in] charact characteristic info + * @param[in] conidx Connection index + **************************************************************************************** + */ +void prf_disc_char_desc_send(prf_env_t *env, struct prf_char_inf * charact, uint8_t conidx); + +/** + **************************************************************************************** + * @brief Look for requested descriptors in the list provided by the + * gattc_disc_char_ind message. + * + * @param[in] nb_descs Length of provided arrays (descs and descs_req) + * @param[in] descs Descriptors + * @param[in] descs_req Descriptors requirements + * @param[in] param List of found descriptors + * @param[in] last_char_code Characteristics code of the characteristic for which the + * gatt_disc_char_desc_req has been sent + **************************************************************************************** + */ +void prf_search_descs(uint8_t nb_descs, + struct prf_char_desc_inf* descs, const struct prf_char_desc_def* descs_req, + const struct gattc_disc_char_desc_ind* param, + uint8_t last_char_code); + +/** + **************************************************************************************** + * @brief Write peer characteristic using GATT. + * + * It will request write modification of peer handle + * + * @param[in] prf_env Pointer to profile information + * @param[in] conidx Connection index + * @param[in] handle Peer handle to modify + * @param[in] value New Peer handle value + * @param[in] length Value length + **************************************************************************************** + */ +void prf_gatt_write(prf_env_t *prf_env, uint8_t conidx, + uint16_t handle, uint8_t* value, uint16_t length, uint8_t operation); + +/** + **************************************************************************************** + * @brief Modify peer client configuration descriptor using GATT + * + * It will request write modification of peer client configuration descriptor handle + * + * @param[in] prf_env Pointer to profile information + * + * @param[in] conidx Connection index + * @param[in] handle Peer client configuration descriptor handle to modify + * + * @param[in] ntf_ind_cfg Indication/Notification configuration + **************************************************************************************** + */ +void prf_gatt_write_ntf_ind(prf_env_t *prf_env, uint8_t conidx, uint16_t handle, + uint16_t ntf_ind_cfg); + +/** + **************************************************************************************** + * @brief Check service characteristic validity + * + * For each characteristic in service it verifies handles. + * + * If some handles are not present, it checks if they shall be present or they are optional. + * + * @param nb_chars Number of Characteristics in the service + * @param chars Characteristics values (char handles, val handles, properties) + * @param chars_req Characteristics requirements. + * + * @return 0x1 if service is valid, 0x00 else. + **************************************************************************************** + */ +uint8_t prf_check_svc_char_validity(uint8_t nb_chars, + const struct prf_char_inf* chars, + const struct prf_char_def* chars_req); + +/** + **************************************************************************************** + * @brief Check service characteristic descriptors validity + * + * For each characteristic descriptors in service it verifies handles. + * + * If some handles are not present, according to characteristic properties it verify if + * descriptor is optional or not. + * + * @param descs_size Number of Characteristic descriptors in the service + * @param descs Characteristic descriptors values (handles) + * @param descs_req Characteristics descriptors requirements. + * + * @return 0x1 if service is valid, 0x00 else. + **************************************************************************************** + */ +uint8_t prf_check_svc_char_desc_validity(uint8_t descs_size, + const struct prf_char_desc_inf* descs, + const struct prf_char_desc_def* descs_req, + const struct prf_char_inf* chars); + +/** + **************************************************************************************** + * @brief Extract information of the service according to the service description + * + * @param param Service information + * @param nb_chars Length of provided arrays (chars and chars_req) + * @param chars_req Characteristics requirements + * @param chars Characteristics + * @param nb_descs Length of provided arrays (descs and descs_req) + * @param descs_req Descriptors requirements + * @param descs Descriptors + **************************************************************************************** + */ +void prf_extract_svc_info(const struct gattc_sdp_svc_ind* param, + uint8_t nb_chars, const struct prf_char_def* chars_req, struct prf_char_inf* chars, + uint8_t nb_descs, const struct prf_char_desc_def* descs_req, struct prf_char_desc_inf* descs); + +#endif //(BLE_CLIENT_PRF) + + +#if (BLE_CLIENT_PRF || BLE_TIP_SERVER || BLE_AN_SERVER || BLE_PAS_SERVER) + +/** + **************************************************************************************** + * @brief The function is used to send information about peer attribute value + * + * @param[in] prf_env Pointer to the profile environment variable + * @param[in] conidx Connection index + * @param[in] msg_id Profile message ID to trigger + * @param[in] status Response status code + * @param[in] read_ind GATT read message indication + **************************************************************************************** + */ +void prf_client_att_info_rsp(prf_env_t *prf_env, uint8_t conidx, uint16_t msg_id, + uint8_t status, struct gattc_read_ind const* read_ind); + +#endif //(BLE_CLIENT_PRF || BLE_TIP_SERVER || BLE_AN_SERVER || BLE_PAS_SERVER) + +#if (BLE_SERVER_PRF || BLE_CLIENT_PRF) +/** + **************************************************************************************** + * @brief Pack date time value + * + * @param[out] packed_date packed date time + * @param[in] date_time structure date time + * + * @return size of packed value + **************************************************************************************** + */ +uint8_t prf_pack_date_time(uint8_t *packed_date, const struct prf_date_time* date_time); + +/** + **************************************************************************************** + * @brief Unpack date time value + * + * @param[in] packed_date packed date time + * @param[out] date_time structure date time + * + * @return size of packed value + **************************************************************************************** + */ +uint8_t prf_unpack_date_time(uint8_t *packed_date, struct prf_date_time* date_time); + +#endif /* (BLE_SERVER_PRF || BLE_CLIENT_PRF) */ + +#if ((BLE_CGM_SERVER || BLE_CGM_CLIENT)) +/** + **************************************************************************************** + * @brief calculate E2E-CRC according to the profile specification + * @param[in] buf Pointer to the byte buffer for the crc calculation. + * @param[in] length Length of the buffer for calculation. + * @return E2E-CRC according to the specification. + **************************************************************************************** + */ +uint16_t prf_e2e_crc(const uint8_t * buf, uint16_t length); + +#endif /* ((BLE_CGM_SERVER || BLE_CGM_CLIENT)) */ + + +/// @} prf_utils + +#endif /* _PRF_UTILS_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/prf_utils_128.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/prf_utils_128.h new file mode 100644 index 0000000..f39c63e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/prf_utils_128.h @@ -0,0 +1,177 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file prf_utils_128.h + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _PRF_UTILS_128_H_ +#define _PRF_UTILS_128_H_ + +/** + **************************************************************************************** + * @addtogroup PRF_UTILS + * @ingroup PROFILE + * + * @brief Definitions of shared profiles functions that can be used by several profiles + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwprf_config.h" + +#if (BLE_CLIENT_PRF) +#include "ke_msg.h" +#include "prf_types.h" +#include "gattc_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "attm_db.h" +#include "prf.h" +#endif /* (BLE_CLIENT_PRF) */ + +/* + * MACROS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +#if (BLE_CLIENT_PRF) + +/// Characteristic definition +struct prf_char_def_128 +{ + /// Characteristic UUID + uint8_t uuid[ATT_UUID_128_LEN]; + /// Requirement Attribute Flag + uint8_t req_flag; + /// Mandatory Properties + uint8_t prop_mand; +}; + +/** + **************************************************************************************** + * @brief Request service discovery with 128-bit UUID on peer device. + * + * This request will be used to retrieve start and end handles of the service. + * + * @param con_info Pointer to connection information (connection handle, app task id, + * profile task id) + * + * @param uuid_128 128-bit service UUID + **************************************************************************************** + */ +void prf_disc_svc_send_128(prf_env_t* env, uint8_t *uuid_128, uint8_t conidx); + +/** + **************************************************************************************** + * @brief Check validity for service characteristic with 128-bit UUID + * + * For each characteristic in service it verifies handles. + * + * If some handles are not present, it checks if they shall be present or they are optional. + * + * @param nb_chars Number of Characteristics in the service + * @param chars Characteristics values (char handles, val handles, properties) + * @param chars_req Characteristics requirements. + * + * @return 0x1 if service is valid, 0x00 else. + **************************************************************************************** + */ +uint8_t prf_check_svc_char_validity_128(uint8_t nb_chars, + const struct prf_char_inf* chars, + const struct prf_char_def_128* chars_req); + +/** + **************************************************************************************** + * @brief Look for requested characteristics in the list provided by the + * gattc_disc_char_ind message. + * + * @param svc_ehdl End handle of the service for which characteristics are discovered + * @param nb_chars Length of provided arrays (chars and chars_req) + * @param chars Characteristics + * @param chars_req Characteristics requirements + * @param param List of found characteristics + * @param last_found_char Characteristics code of the last characteristic that has been found. + **************************************************************************************** + */ +void prf_search_chars_128(uint16_t svc_ehdl, uint8_t nb_chars, + struct prf_char_inf* chars, const struct prf_char_def_128* chars_req, + const struct gattc_disc_char_ind* param, + uint8_t* last_found_char); + +void prf_disc_svc_sdp_send_128(prf_env_t *prf_env, uint8_t conidx,const uint8_t* uuid_128); +void prf_disc_char_by_uuid_128_send(prf_env_t *prf_env, uint8_t conidx, const uint8_t *uuid_128); +void prf_extract_svc_sdp_info_128(const struct gattc_sdp_svc_ind *param, + uint8_t nb_chars, + const struct prf_char_def_128* chars_req, + struct prf_char_inf* chars, + uint8_t nb_descs, + const struct prf_char_desc_def* descs_req, + struct prf_char_desc_inf* descs); + +#endif //(BLE_CLIENT_PRF) + + +/// @} prf_utils + +#endif /* _PRF_UTILS_128_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/rwble_hl.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/rwble_hl.h new file mode 100644 index 0000000..483c219 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/rwble_hl.h @@ -0,0 +1,54 @@ +/** + **************************************************************************************** + * + * @file rwble_hl.h + * + * @brief Entry points of the BLE HL software + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef RWBLE_HL_H_ +#define RWBLE_HL_H_ + +#include +#include // standard boolean definitions +/** + **************************************************************************************** + * @addtogroup ROOT + * @brief Entry points of the BLE Host stack + * + * This module contains the primitives that allow an application accessing and running the + * BLE protocol stack + * + * @{ + **************************************************************************************** + */ + + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Initialize the BLE Host stack. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void rwble_hl_init(uint8_t init_type); + +/// @} RWBLE_HL + +#endif // RWBLE_HL_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/rwble_hl_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/rwble_hl_config.h new file mode 100644 index 0000000..91c8c48 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/rwble_hl_config.h @@ -0,0 +1,276 @@ +/** + **************************************************************************************** + * + * @file rwble_hl_config.h + * + * @brief Configuration of the BLE protocol stack (max number of supported connections, + * type of partitioning, etc.) + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef RWBLE_HL_CONFIG_H_ +#define RWBLE_HL_CONFIG_H_ +#include "rwip_config.h" +/** + **************************************************************************************** + * @addtogroup ROOT + * @{ + * @name BLE stack configuration + * @{ + **************************************************************************************** + */ + +#include "rwble_hl_error.h" + +/* + * DEFINES - Mandatory for BLE Host Layers + **************************************************************************************** + */ + +/// Maximum time to remain advertising when in the Limited +/// Discover able mode: TGAP(lim_adv_timeout) +/// required value: 180s: (18000 for ke timer) +#define GAP_TMR_LIM_ADV_TIMEOUT 0x4650 + +/// Minimum time to perform scanning when performing +/// the General Discovery procedure: TGAP(gen_disc_scan_min) +/// recommended value: 10.24s: (1024 for ke timer) +#define GAP_TMR_GEN_DISC_SCAN 0x0400 + +/// Minimum time to perform scanning when performing the +/// Limited Discovery procedure: TGAP(lim_disc_scan_min) +/// recommended value: 10.24s: (1024 for ke timer) +#define GAP_TMR_LIM_DISC_SCAN 0x0400 + +/// Minimum time interval between private address change +/// TGAP(private_addr_int) +/// recommended value: 15 minutes +/// Minimum value 150s +#define GAP_TMR_PRIV_ADDR_MIN (150) +/// Maximum time interval between private address change +/// 0xA1B8 (approximately 11.5 hours) +#define GAP_TMR_PRIV_ADDR_MAX (0xA1B8) + + +/// Timer used in connection parameter update procedure +/// TGAP(conn_param_timeout) +/// recommended value: 30 s: (3000 for ke timer) +#define GAP_TMR_CONN_PARAM_TIMEOUT 0x0BB8 + +/// Timer used in LE credit based connection procedure +/// TGAP(lecb_conn_timeout) +/// recommended value: 30 s: (3000 for ke timer) +#define GAP_TMR_LECB_CONN_TIMEOUT 0x0BB8 + +/// Timer used in LE credit based disconnection procedure +/// TGAP(lecb_disconn_timeout) +/// recommended value: 30 s: (3000 for ke timer) +#define GAP_TMR_LECB_DISCONN_TIMEOUT 0x0BB8 + +/// Maximal authorized MTU value - Implementation supports up to (2^12 -1) = 4095 bytes +#define GAP_MAX_LE_MTU (2048) + +/// Maximum GAP device name size +#define GAP_MAX_NAME_SIZE (0x20) + + + + +/// Maximum Transmission Unit +#define ATT_DEFAULT_MTU (23) +/// 30 seconds transaction timer +#define ATT_TRANS_RTX (0x0BB8) +/// Acceptable encryption key size - strict access +#define ATT_SEC_ENC_KEY_SIZE (0x10) + + +/// Maximum attribute value length +#define ATT_MAX_VALUE (GAP_MAX_LE_MTU) + + +/******************************************************************************************/ +/* ------------------------- BLE PARTITIONING -------------------------------------*/ +/******************************************************************************************/ + + +/******************************************************************************************/ +/* -------------------------- INTERFACES ----------------------------------------*/ +/******************************************************************************************/ + + +#if BLE_APP_PRESENT +#define APP_MAIN_TASK TASK_APP +#else // BLE_APP_PRESENT +#define APP_MAIN_TASK TASK_AHI +#endif // BLE_APP_PRESENT + +// Host Controller Interface (Host side) +#define BLEHL_HCIH_ITF HCIH_ITF + +/******************************************************************************************/ +/* -------------------------- COEX SETUP ----------------------------------------*/ +/******************************************************************************************/ + +///WLAN coex +#define BLEHL_WLAN_COEX RW_WLAN_COEX +///WLAN test mode +#define BLEHL_WLAN_COEX_TEST RW_WLAN_COEX_TEST + +/******************************************************************************************/ +/* -------------------------- HOST MODULES ----------------------------------------*/ +/******************************************************************************************/ + +#define BLE_GAPM 1 +#if (BLE_OBSERVERH) +#define BLE_GAPM_HEAP_ENV_SIZE (sizeof(struct gapm_actv_scan_tag) + KE_HEAP_MEM_RESERVED) +#elif (BLE_PERIPHERAL) +#define BLE_GAPM_HEAP_ENV_SIZE (sizeof(struct gapm_actv_adv_tag) + KE_HEAP_MEM_RESERVED) +#else //(BLE_PERIPHERAL) +#define BLE_GAPM_HEAP_ENV_SIZE 0 +#endif //(BLE_PERIPHERAL) + +#if (BLE_CENTRALH || BLE_PERIPHERAL) +#define BLE_GAPC 1 +#define BLE_GAPC_HEAP_ENV_SIZE (sizeof(struct gapc_env_tag) + KE_HEAP_MEM_RESERVED) +#else //(BLE_CENTRALH || BLE_PERIPHERAL) +#define BLE_GAPC 0 +#define BLE_GAPC_HEAP_ENV_SIZE 0 +#endif //(BLE_CENTRALH || BLE_PERIPHERAL) + +#if (BLE_CENTRALH || BLE_PERIPHERAL) +#define BLE_L2CM 1 +#define BLE_L2CC 1 +#define BLE_ATTM 1 +#define BLE_GATTM 1 +#define BLE_GATTC 1 +#define BLE_GATTC_HEAP_ENV_SIZE (sizeof(struct gattc_env_tag) + KE_HEAP_MEM_RESERVED) +#define BLE_L2CC_HEAP_ENV_SIZE (sizeof(struct l2cc_env_tag) + KE_HEAP_MEM_RESERVED) +#else //(BLE_CENTRALH || BLE_PERIPHERAL) +#define BLE_L2CM 0 +#define BLE_L2CC 0 +#define BLE_ATTC 0 +#define BLE_ATTS 0 +#define BLE_ATTM 0 +#define BLE_GATTM 0 +#define BLE_GATTC 0 +#define BLE_GATTC_HEAP_ENV_SIZE 0 +#define BLE_L2CC_HEAP_ENV_SIZE 0 +#endif //(BLE_CENTRALH || BLE_PERIPHERAL) + +/******************************************************************************************/ +/* -------------------------- ATT DB ----------------------------------------*/ +/******************************************************************************************/ + +//ATT DB,Testing and Qualification related flags +#if (BLE_CENTRAL || BLE_PERIPHERAL) + /// Support of External DB Management + #if defined(CFG_EXT_DB) + #define BLE_EXT_ATT_DB 1 + #else + #define BLE_EXT_ATT_DB 0 + #endif // defined(CFG_EXT_DB) +#else + #define BLE_EXT_ATT_DB 0 +#endif // (BLE_CENTRAL || BLE_PERIPHERAL) +/******************************************************************************************/ +/* -------------------------- PROFILES ----------------------------------------*/ +/******************************************************************************************/ +//#ifdef CFG_PRF +//#define BLE_PROFILES (1) +///// Number of Profile tasks managed by GAP manager. +//#define BLE_NB_PROFILES (CFG_NB_PRF) +//#include "rwprf_config.h" +//#else +//#define BLE_PROFILES (0) +//#define BLE_NB_PROFILES (0) +//#endif // CFG_PRF + + +#ifndef BLE_ATTS +#if (BLE_CENTRALH || BLE_PERIPHERAL || defined(CFG_ATTS)) +#define BLE_ATTS 1 +#else +#define BLE_ATTS 0 +#endif // (BLE_CENTRALH || BLE_PERIPHERAL || defined(CFG_ATTS)) +#endif // BLE_ATTS + + +#define CFG_ATTC //lxm add + +#ifndef BLE_ATTC +#if (BLE_CENTRAL || defined(CFG_ATTC)) +#define BLE_ATTC 1 +#else +#define BLE_ATTC 0 +#endif // (BLE_CENTRAL || defined(CFG_ATTC)) +#endif // BLE_ATTC + +//#ifndef BLE_LECB //TODO ding.yuanwu +////#if (BLE_CENTRALH || BLE_PERIPHERAL) +////#define BLE_LECB 1 +////#else +////#define BLE_LECB 0 +////#endif // (BLE_CENTRALH || defined(CFG_ATTC)) +////#endif // BLE_LECB + + +/// Attribute Server +#if (BLE_ATTS) +#define BLE_ATTS 1 +#else +#define BLE_ATTS 0 +#endif //(BLE_ATTS) + + +/// Size of the heap +#if (BLE_CENTRALH || BLE_PERIPHERAL) + /// some heap must be reserved for attribute database + #if (BLE_ATTS || BLE_ATTC) + /// Can be tuned based on supported profiles + #define BLEHL_HEAP_DB_SIZE (3072) + #else + #define BLEHL_HEAP_DB_SIZE (0) + #endif /* (BLE_ATTS || BLE_ATTC) */ + + #if (BLE_EMB_PRESENT) + /// Needed "security" heap size for reception of max supported MTU through prepare write procedure + /// If retention memory is used, this additionnal heap can be part of the size allocated for the retention memory + #define BLEHL_HEAP_DATA_THP_SIZE (3 * GAP_MAX_LE_MTU) + #else // !(BLE_EMB_PRESENT) + #define BLEHL_HEAP_DATA_THP_SIZE (4 * GAP_MAX_LE_MTU) + #endif // (BLE_EMB_PRESENT) + + /// message size per connection + #define BLEHL_HEAP_MSG_SIZE_PER_CON (400) + + #define BLEHL_HEAP_MSG_SIZE (((BLEHL_HEAP_MSG_SIZE_PER_CON * BLE_CONNECTION_MAX) > BLEHL_HEAP_DATA_THP_SIZE) \ + ? (BLEHL_HEAP_MSG_SIZE_PER_CON * BLE_CONNECTION_MAX) : BLEHL_HEAP_DATA_THP_SIZE) +#elif (BLE_MESH) + #define BLEHL_HEAP_MSG_SIZE (1024) + #define BLEHL_HEAP_DB_SIZE (3072) +#else + #define BLEHL_HEAP_MSG_SIZE (256) + #define BLEHL_HEAP_DB_SIZE (0) +#endif /* #if (BLE_CENTRALH || BLE_PERIPHERAL) */ + + + + +/// Number of BLE HL tasks +#define BLEHL_TASK_SIZE BLE_HOST_TASK_SIZE + BLE_PRF_TASK_SIZE + +/// Size of environment variable needed on BLE Host Stack for one link +#define BLEHL_HEAP_ENV_SIZE ( BLE_CONNECTION_MAX * ( BLE_GAPC_HEAP_ENV_SIZE \ + + BLE_GATTC_HEAP_ENV_SIZE \ + + BLE_L2CC_HEAP_ENV_SIZE ) \ + + BLE_ACTIVITY_MAX * BLE_GAPM_HEAP_ENV_SIZE ) + + +/// @} BLE stack configuration +/// @} ROOT + +#endif // RWBLE_HL_CONFIG_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/rwprf_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/rwprf_config.h new file mode 100644 index 0000000..f5f4fe8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc/rwprf_config.h @@ -0,0 +1,632 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwprf_config.h + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +#ifndef _RWPRF_CONFIG_H_ +#define _RWPRF_CONFIG_H_ + +/** + **************************************************************************************** + * @addtogroup PRF_CONFIG + * @ingroup PROFILE + * @brief Profile configuration + * + * @{ + **************************************************************************************** + */ + +//ATT DB,Testing and Qualification related flags +#if (BLE_CENTRALH || BLE_PERIPHERAL) +/// Proximity Profile Monitor Role +#if defined(CFG_PRF_PXPM) +#define BLE_PROX_MONITOR 1 +#else +#define BLE_PROX_MONITOR 0 +#endif // defined(CFG_PRF_PXPM) + +/// Proximity Profile Reporter Role +#if defined(CFG_PRF_PXPR) +#define BLE_PROX_REPORTER 1 +#else +#define BLE_PROX_REPORTER 0 +#endif // defined(CFG_PRF_PXPR) + +///Find Me Profile Locator role +#if defined(CFG_PRF_FMPL) +#define BLE_FINDME_LOCATOR 1 +#else +#define BLE_FINDME_LOCATOR 0 +#endif // defined(CFG_PRF_FMPL) + +///Find Me Profile Target role +#if defined(CFG_PRF_FMPT) +#define BLE_FINDME_TARGET 1 +#else +#define BLE_FINDME_TARGET 0 +#endif // defined(CFG_PRF_FMPT) + +///Health Thermometer Profile Collector Role +#if defined(CFG_PRF_HTPC) +#define BLE_HT_COLLECTOR 1 +#else +#define BLE_HT_COLLECTOR 0 +#endif // defined(CFG_PRF_HTPC) + +///Health Thermometer Profile Thermometer Role +#if defined(CFG_PRF_HTPT) +#define BLE_HT_THERMOM 1 +#else +#define BLE_HT_THERMOM 0 +#endif // defined(CFG_PRF_HTPT) + +///Device Information Service Client Role +#if defined(CFG_PRF_DISC) +#define BLE_DIS_CLIENT 1 +#else +#define BLE_DIS_CLIENT 0 +#endif // defined(CFG_PRF_DISC) + +///Device Information Service Server Role +#if defined(CFG_PRF_DISS) +#define BLE_DIS_SERVER 1 +#else +#define BLE_DIS_SERVER 0 +#endif // defined(CFG_PRF_DISS) + +///Blood Pressure Profile Collector Role +#if defined(CFG_PRF_BLPC) +#define BLE_BP_COLLECTOR 1 +#else +#define BLE_BP_COLLECTOR 0 +#endif // defined(CFG_PRF_BLPC) + +///Blood Pressure Profile Sensor Role +#if defined(CFG_PRF_BLPS) +#define BLE_BP_SENSOR 1 +#else +#define BLE_BP_SENSOR 0 +#endif // defined(CFG_PRF_BLPS) + +///Time Profile Client Role +#if defined(CFG_PRF_TIPC) +#define BLE_TIP_CLIENT 1 +#else +#define BLE_TIP_CLIENT 0 +#endif // defined(CFG_PRF_TIPC) + +///Time Profile Server Role +#if defined(CFG_PRF_TIPS) +#define BLE_TIP_SERVER 1 +#else +#define BLE_TIP_SERVER 0 +#endif // defined(CFG_PRF_TIPS) + +///Heart Rate Profile Collector Role +#if defined(CFG_PRF_HRPC) +#define BLE_HR_COLLECTOR 1 +#else +#define BLE_HR_COLLECTOR 0 +#endif // defined(CFG_PRF_HRPC) + +///Heart Rate Profile Sensor Role +#if defined(CFG_PRF_HRPS) +#define BLE_HR_SENSOR 1 +#else +#define BLE_HR_SENSOR 0 +#endif // defined(CFG_PRF_HRPS) + +///Scan Parameter Profile Client Role +#if defined(CFG_PRF_SCPPC) +#define BLE_SP_CLIENT 1 +#else +#define BLE_SP_CLIENT 0 +#endif // defined(CFG_PRF_SCPPC) + +///Scan Parameter Profile Server Role +#if defined(CFG_PRF_SCPPS) +#define BLE_SP_SERVER 1 +#else +#define BLE_SP_SERVER 0 +#endif // defined(CFG_PRF_SCPPS) + +///Battery Service Client Role +#if defined(CFG_PRF_BASC) +#define BLE_BATT_CLIENT 1 +#else +#define BLE_BATT_CLIENT 0 +#endif // defined(CFG_PRF_BASC) + +///Battery Service Server Role +#if defined(CFG_PRF_BASS) +#define BLE_BATT_SERVER 1 +#else +#define BLE_BATT_SERVER 0 +#endif // defined(CFG_PRF_BASS) + +///HID Device Role +#if defined(CFG_PRF_HOGPD) +#define BLE_HID_DEVICE 1 +#else +#define BLE_HID_DEVICE 0 +#endif // defined(CFG_PRF_HOGPD) + +///HID Boot Host Role +#if defined(CFG_PRF_HOGPBH) +#define BLE_HID_BOOT_HOST 1 +#else +#define BLE_HID_BOOT_HOST 0 +#endif // defined(CFG_PRF_HOGPBH) + +///HID Report Host Role +#if defined(CFG_PRF_HOGPRH) +#define BLE_HID_REPORT_HOST 1 +#else +#define BLE_HID_REPORT_HOST 0 +#endif // defined(CFG_PRF_HOGPRH) + +/// Glucose Profile Collector Role +#if defined(CFG_PRF_GLPC) +#define BLE_GL_COLLECTOR 1 +#else +#define BLE_GL_COLLECTOR 0 +#endif // defined(CFG_PRF_GLPC) + +/// Glucose Profile Sensor Role +#if defined(CFG_PRF_GLPS) +#define BLE_GL_SENSOR 1 +#else +#define BLE_GL_SENSOR 0 +#endif // defined(CFG_PRF_GLPS) + +/// Running Speed and Cadence Profile Collector Role +#if defined(CFG_PRF_RSCPC) +#define BLE_RSC_COLLECTOR 1 +#else +#define BLE_RSC_COLLECTOR 0 +#endif // defined(CFG_PRF_RSCPC) + +/// Running Speed and Cadence Profile Server Role +#if defined(CFG_PRF_RSCPS) +#define BLE_RSC_SENSOR 1 +#else +#define BLE_RSC_SENSOR 0 +#endif // defined(CFG_PRF_RSCPS) + +/// Cycling Speed and Cadence Profile Collector Role +#if defined(CFG_PRF_CSCPC) +#define BLE_CSC_COLLECTOR 1 +#else +#define BLE_CSC_COLLECTOR 0 +#endif // defined(CFG_PRF_CSCPC) + +/// Cycling Speed and Cadence Profile Server Role +#if defined(CFG_PRF_CSCPS) +#define BLE_CSC_SENSOR 1 +#else +#define BLE_CSC_SENSOR 0 +#endif // defined(CFG_PRF_CSCPS) + +/// Cycling Power Profile Collector Role +#if defined(CFG_PRF_CPPC) +#define BLE_CP_COLLECTOR 1 +#else +#define BLE_CP_COLLECTOR 0 +#endif // defined (CFG_PRF_CPPC) + +/// Cycling Power Profile Server Role +#if defined(CFG_PRF_CPPS) +#define BLE_CP_SENSOR 1 +#else +#define BLE_CP_SENSOR 0 +#endif // defined (CFG_PRF_CPPS) + +/// Location and Navigation Profile Collector Role +#if defined(CFG_PRF_LANC) +#define BLE_LN_COLLECTOR 1 +#else +#define BLE_LN_COLLECTOR 0 +#endif // defined (CFG_PRF_LANC) + +/// Location and Navigation Profile Server Role +#if defined(CFG_PRF_LANS) +#define BLE_LN_SENSOR 1 +#else +#define BLE_LN_SENSOR 0 +#endif // defined (CFG_PRF_LANS) + +/// Alert Notification Profile Client Role +#if defined(CFG_PRF_ANPC) +#define BLE_AN_CLIENT 1 +#else +#define BLE_AN_CLIENT 0 +#endif // defined(CFG_PRF_ANPC) + +/// Alert Notification Profile Server Role +#if defined(CFG_PRF_ANPS) +#define BLE_AN_SERVER 1 +#else +#define BLE_AN_SERVER 0 +#endif // defined(CFG_PRF_ANPS) + +/// Phone Alert Status Profile Client Role +#if defined(CFG_PRF_PASPC) +#define BLE_PAS_CLIENT 1 +#else +#define BLE_PAS_CLIENT 0 +#endif // defined(CFG_PRF_PASPC) + +/// Phone Alert Status Profile Server Role +#if defined(CFG_PRF_PASPS) +#define BLE_PAS_SERVER 1 +#else +#define BLE_PAS_SERVER 0 +#endif // defined(CFG_PRF_PASPS) + +/// Internet Protocol Support Profile Server Role +#if defined(CFG_PRF_IPSS) +#define BLE_IPS_SERVER 1 +#else +#define BLE_IPS_SERVER 0 +#endif // defined(CFG_PRF_IPSS) + +/// Internet Protocol Support Profile Client Role +#if defined(CFG_PRF_IPSC) +#define BLE_IPS_CLIENT 1 +#else +#define BLE_IPS_CLIENT 0 +#endif // defined(CFG_PRF_IPSC) + +/// Environmental Sensing Profile Server Role +#if defined(CFG_PRF_ENVS) +#define BLE_ENV_SERVER 1 +#else +#define BLE_ENV_SERVER 0 +#endif // defined(CFG_PRF_ENVS) + +/// Environmental Sensing Profile Client Role +#if defined(CFG_PRF_ENVC) +#define BLE_ENV_CLIENT 1 +#else +#define BLE_ENV_CLIENT 0 +#endif // defined(CFG_PRF_ENVC) + +/// Weight Scale Profile Server Role +#if defined(CFG_PRF_WSCS) +#define BLE_WSC_SERVER 1 +#else +#define BLE_WSC_SERVER 0 +#endif // defined(CFG_PRF_WSCS) + +/// Weight Scale Profile Client Role +#if defined(CFG_PRF_WSCC) +#define BLE_WSC_CLIENT 1 +#else +#define BLE_WSC_CLIENT 0 +#endif // defined(CFG_PRF_WSCC) + +/// Body Composition Server Role +#if defined(CFG_PRF_BCSS) +#define BLE_BCS_SERVER 1 +#else +#define BLE_BCS_SERVER 0 +#endif // defined(CFG_PRF_BCSS) + +/// Body Composition Client Role +#if defined(CFG_PRF_BCSC) +#define BLE_BCS_CLIENT 1 +#else +#define BLE_BCS_CLIENT 0 +#endif // defined(CFG_PRF_BCSC) + +/// User Data Service Server Role +#if defined(CFG_PRF_UDSS) +#define BLE_UDS_SERVER 1 +#else +#define BLE_UDS_SERVER 0 +#endif // defined(CFG_PRF_UDSS) + +/// User Data Service Client Role +#if defined(CFG_PRF_UDSC) +#define BLE_UDS_CLIENT 1 +#else +#define BLE_UDS_CLIENT 0 +#endif // defined(CFG_PRF_UDSC) + +/// Wireless Power Transfer Profile Server Role +#if defined(CFG_PRF_WPTS) +#define BLE_WPT_SERVER 1 +#else +#define BLE_WPT_SERVER 0 +#endif // defined(CFG_PRF_WPTS) + +/// Wireless Power Transfer Profile Client Role +#if defined(CFG_PRF_WPTC) +#define BLE_WPT_CLIENT 1 +#else +#define BLE_WPT_CLIENT 0 +#endif // defined(CFG_PRF_WPTC) + +/// Pulse Oximeter Profile Server Role +#if defined(CFG_PRF_PLXS) +#define BLE_PLX_SERVER 1 +#else +#define BLE_PLX_SERVER 0 +#endif // defined(CFG_PRF_PLXS) + +/// Pulse Oximete Profile Client Role +#if defined(CFG_PRF_PLXC) +#define BLE_PLX_CLIENT 1 +#else +#define BLE_PLX_CLIENT 0 +#endif // defined(CFG_PRF_PLXC) + +/// Continuous Glucose Monitoring Profile Server Role +#if defined(CFG_PRF_CGMS) +#define BLE_CGM_SERVER 1 +#else +#define BLE_CGM_SERVER 0 +#endif // defined(CFG_PRF_CGMS) + +/// Continuous Glucose Monitoring Profile Client Role +#if defined(CFG_PRF_CGMC) +#define BLE_CGM_CLIENT 1 +#else +#define BLE_CGM_CLIENT 0 +#endif // defined(CFG_PRF_CGMC) + +/// Throughput tester profile for debug usage +#if defined(CFG_PRF_THPP) +#define BLE_DBG_THPP 1 +#else +#define BLE_DBG_THPP 0 +#endif // defined(CFG_PRF_DISS) + +/// raw data transfer server server +#if defined(CFG_PRF_RDTSS) +#define BLE_RDTSS_SERVER 1 +#else +#define BLE_RDTSS_SERVER 0 +#endif // defined(CFG_PRF_RDTSS) + +/// raw data transfer Profile client +#if defined(CFG_PRF_RDTSC) +#define BLE_RDTS_CLIENT 1 +#else +#define BLE_RDTS_CLIENT 0 +#endif // defined(CFG_PRF_RDTSS) + +/// raw data transfer server server in 16bit uuid +#if defined(CFG_PRF_RDTSS_16BIT) +#define BLE_RDTSS_16BIT_SERVER 1 +#else +#define BLE_RDTSS_16BIT_SERVER 0 +#endif // defined(CFG_PRF_RDTSS_16BIT) + +/// raw data transfer Profile client in 16bit uuid +#if defined(CFG_PRF_RDTSC_16BIT) +#define BLE_RDTS_16BIT_CLIENT 1 +#else +#define BLE_RDTS_16BIT_CLIENT 0 +#endif // defined(CFG_PRF_RDTSC_16BIT) + +/// Apple Notification Center Service Client Role +#if defined(CFG_PRF_ANCC) +#define BLE_ANC_CLIENT 1 +#else +#define BLE_ANC_CLIENT 0 +#endif //defined(CFG_PRF_ANCC) + +#define BLE_RDTS_ENABLE (BLE_RDTSS_SERVER || BLE_RDTSS_16BIT_SERVER ) + +/// BLE_CLIENT_PRF indicates if at least one client profile is present +#if (BLE_PROX_MONITOR || BLE_FINDME_LOCATOR || BLE_HT_COLLECTOR || BLE_BP_COLLECTOR \ + || BLE_HR_COLLECTOR || BLE_DIS_CLIENT || BLE_TIP_CLIENT || BLE_SP_CLIENT \ + || BLE_BATT_CLIENT || BLE_GL_COLLECTOR || BLE_HID_BOOT_HOST || BLE_HID_REPORT_HOST \ + || BLE_RSC_COLLECTOR || BLE_CSC_COLLECTOR || BLE_CP_COLLECTOR || BLE_LN_COLLECTOR || BLE_AN_CLIENT \ + || BLE_PAS_CLIENT || BLE_IPS_CLIENT || BLE_ENV_CLIENT || BLE_WSC_CLIENT \ + || BLE_UDS_CLIENT || BLE_BCS_CLIENT || BLE_WPT_CLIENT || BLE_PLX_CLIENT \ + || BLE_CGM_CLIENT || BLE_DBG_THPP || BLE_RDTS_CLIENT || BLE_ANC_CLIENT || BLE_RDTS_16BIT_CLIENT) +#define BLE_CLIENT_PRF 1 +#else +#define BLE_CLIENT_PRF 0 +#endif //(BLE_PROX_MONITOR || BLE_FINDME_LOCATOR ...) + +/// BLE_SERVER_PRF indicates if at least one server profile is present +#if (BLE_PROX_REPORTER || BLE_FINDME_TARGET || BLE_HT_THERMOM || BLE_BP_SENSOR \ + || BLE_TIP_SERVER || BLE_HR_SENSOR || BLE_DIS_SERVER || BLE_SP_SERVER \ + || BLE_BATT_SERVER || BLE_HID_DEVICE || BLE_GL_SENSOR || BLE_RSC_SENSOR \ + || BLE_CSC_SENSOR || BLE_CP_SENSOR || BLE_LN_SENSOR || BLE_AN_SERVER \ + || BLE_PAS_SERVER || BLE_IPS_SERVER || BLE_ENV_SERVER || BLE_WSC_SERVER \ + || BLE_UDS_SERVER || BLE_BCS_SERVER || BLE_WPT_SERVER || BLE_PLX_SERVER \ + || BLE_CGM_SERVER || BLE_DBG_THPP) +#define BLE_SERVER_PRF 1 +#else +#define BLE_SERVER_PRF 0 +#endif //(BLE_PROX_REPORTER || BLE_FINDME_TARGET ...) + +//Force ATT parts depending on profile roles or compile options +/// Attribute Client +#if (BLE_CLIENT_PRF) +#define BLE_ATTC 1 +#endif //(BLE_CLIENT_PRF) + +/// Attribute Server +#if (BLE_SERVER_PRF) +#define BLE_ATTS 1 +#endif //(BLE_SERVER_PRF) + + +#elif (BLE_OBSERVERH || BLE_BROADCASTER) +/// Proximity Profile Monitor Role +#define BLE_PROX_MONITOR 0 +/// Proximity Profile Reporter Role +#define BLE_PROX_REPORTER 0 +///Find Me Profile Locator role +#define BLE_FINDME_LOCATOR 0 +///Find Me Profile Target role +#define BLE_FINDME_TARGET 0 +///Health Thermometer Profile Collector Role +#define BLE_HT_COLLECTOR 0 +///Health Thermometer Profile Thermometer Role +#define BLE_HT_THERMOM 0 +///Blood Pressure Profile Collector Role +#define BLE_BP_COLLECTOR 0 +///Blood Pressure Profile Sensor Role +#define BLE_BP_SENSOR 0 +///Heart Rate Profile Collector Role +#define BLE_HR_COLLECTOR 0 +///Heart Rate Profile Sensor Role +#define BLE_HR_SENSOR 0 +///Time Profile Client Role +#define BLE_TIP_CLIENT 0 +///Time Profile Server Role +#define BLE_TIP_SERVER 0 +/// Device Information Service Client Role +#define BLE_DIS_CLIENT 0 +/// Device Information Service Server Role +#define BLE_DIS_SERVER 0 +/// Scan Parameter Profile Client Role +#define BLE_SP_CLIENT 0 +/// Scan Parameter Profile Server Role +#define BLE_SP_SERVER 0 +/// Battery Service Client Role +#define BLE_BATT_CLIENT 0 +/// Battery Service Server Role +#define BLE_BATT_SERVER 0 +/// HID Device Role +#define BLE_HID_DEVICE 0 +/// HID Boot Host Role +#define BLE_HID_BOOT_HOST 0 +/// HID Report Host Role +#define BLE_HID_REPORT_HOST 0 +/// Glucose Profile Collector Role +#define BLE_GL_COLLECTOR 0 +/// Glucose Profile Sensor Role +#define BLE_GL_SENSOR 0 +/// Running Speed and Cadence Collector Role +#define BLE_RSC_COLLECTOR 0 +/// Running Speed and Cadence Server Role +#define BLE_RSC_SENSOR 0 +/// Cycling Speed and Cadence Collector Role +#define BLE_CSC_COLLECTOR 0 +/// Cycling Speed and Cadence Server Role +#define BLE_CSC_SENSOR 0 +/// Cycling Power Collector Role +#define BLE_CP_COLLECTOR 0 +/// Cycling Power Server Role +#define BLE_CP_SENSOR 0 +/// Location and Navigation Collector Role +#define BLE_LN_COLLECTOR 0 +/// Location and Navigation Server Role +#define BLE_LN_SENSOR 0 +/// Alert Notification Client Role +#define BLE_AN_CLIENT 0 +/// Alert Notification Server Role +#define BLE_AN_SERVER 0 +/// Phone Alert Status Client Role +#define BLE_PAS_CLIENT 0 +/// Phone Alert Status Server Role +#define BLE_PAS_SERVER 0 +/// Internet Protocol Support Profile Server Role +#define BLE_IPS_SERVER 0 +/// Internet Protocol Support Profile Client Role +#define BLE_IPS_CLIENT 0 +/// Environmental Sensing Profile Server Role +#define BLE_ENV_SERVER 0 +/// Environmental Sensing Profile Client Role +#define BLE_ENV_CLIENT 0 +/// Weight Scale Profile Server Role +#define BLE_WSC_SERVER 0 +/// Weight Scale Profile Client Role +#define BLE_WSC_CLIENT 0 +/// Body Composition Profile Client Role +#define BLE_BCS_CLIENT 0 +/// Body Composition Profile Server Role +#define BLE_BCS_SERVER 0 +/// User Data Service Server Role +#define BLE_UDS_SERVER 0 +/// User Data Service Client Role +#define BLE_UDS_CLIENT 0 +/// Wireless Power Transfer Profile Server Role +#define BLE_WPT_SERVER 0 +/// Wireless Power Transfer Profile Client Role +#define BLE_WPT_CLIENT 0 +/// Pulse Oximete Profile Server Role +#define BLE_PLX_SERVER 0 +/// Pulse Oximete Profile Client Role +#define BLE_PLX_CLIENT 0 +/// Pulse Oximete Profile Server Role +#define BLE_CGM_SERVER 0 +/// Pulse Oximete Profile Client Role +#define BLE_CGM_CLIENT 0 + +/// Throughput tester profile for debug usage +#define BLE_DBG_THPP 0 + +//Force ATT parts to 0 +/// External database management +#define BLE_EXT_ATTS_DB 0 +/// Profile Server +#define BLE_SERVER_PRF 0 +/// Profile Client +#define BLE_CLIENT_PRF 0 +#endif //(BLE_OBSERVERH || BLE_BROADCASTER) + + +/// @} PRF_CONFIG + +#endif /* _RWPRF_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/att/lib_att.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/att/lib_att.c new file mode 100644 index 0000000..bfc2b72 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/att/lib_att.c @@ -0,0 +1,124 @@ +#include "gattm_int.h" + +uint8_t attm_att_set_permission(uint16_t handle, uint16_t perm, uint16_t ext_perm) +{ + struct attm_elmt elmt = ATT_ELEMT_INIT; + uint8_t status = attmdb_get_attribute(handle, &elmt); + + if(status == ATT_ERR_NO_ERROR) + { + if( attmdb_uuid16_comp(&elmt, ATT_DECL_PRIMARY_SERVICE) + || attmdb_uuid16_comp(&elmt, ATT_DECL_SECONDARY_SERVICE) + || attmdb_uuid16_comp(&elmt, ATT_DECL_CHARACTERISTIC) + || attmdb_uuid16_comp(&elmt, ATT_DECL_INCLUDE) + || attmdb_uuid16_comp(&elmt, ATT_DESC_CHAR_EXT_PROPERTIES)) + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } + else + { + struct attm_att_desc* att = elmt.info.att; + struct attm_elmt prev_elmt = ATT_ELEMT_INIT; + + // Check if database Hash updated due to characteristic update + if( (attmdb_get_attribute(handle - 1, &prev_elmt) == ATT_ERR_NO_ERROR) + && attmdb_uuid16_comp(&prev_elmt, ATT_DECL_CHARACTERISTIC)) + { + if(PERM_GET(att->perm, PROP) != PERM_GET(perm, PROP)) + { + // Database updated + gattm_db_updated(); + } + } + + /* update attribute permissions */ + att->perm = perm; + + /* update attribute extended permissions */ + if(PERM_GET(ext_perm, EKS)) + { + att->info.max_length |= PERM_MASK_EKS; + } + else + { + att->info.max_length &= ~PERM_MASK_EKS; + } + } + } + + return (status); +} + +uint8_t attm_att_set_value(uint16_t handle, att_size_t length, att_size_t offset, uint8_t* value) +{ + struct attm_elmt elmt = ATT_ELEMT_INIT; + uint8_t status = attmdb_get_attribute(handle, &elmt); + + if(status == ATT_ERR_NO_ERROR) + { + // value can not be set for following parameters + if( attmdb_uuid16_comp(&elmt, ATT_DECL_PRIMARY_SERVICE) + || attmdb_uuid16_comp(&elmt, ATT_DECL_SECONDARY_SERVICE) + || attmdb_uuid16_comp(&elmt, ATT_DECL_CHARACTERISTIC) + || attmdb_uuid16_comp(&elmt, ATT_DECL_INCLUDE) + || attmdb_uuid16_comp(&elmt, ATT_DESC_CHAR_EXT_PROPERTIES) + || attmdb_uuid16_comp(&elmt, ATT_DESC_CLIENT_CHAR_CFG) + || attmdb_uuid16_comp(&elmt, ATT_DESC_SERVER_CHAR_CFG)) + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } + else + { + // check if data present in attribute + if(PERM_GET(elmt.info.att->info.max_length, RI) == 0) + { + struct attm_att_value* val = (struct attm_att_value*) + (((uint8_t*)elmt.info.att) + PERM_GET(elmt.info.att->info.offset, VAL_OFFSET)); + + if((offset) > val->length) + { + status = ATT_ERR_INVALID_OFFSET; + } + /* check if value length is not too big */ + if((length+offset) > val->max_length) + { + status = ATT_ERR_INVALID_ATTRIBUTE_VAL_LEN; + } + /* update attribute value + length */ + else + { + // copy data + memcpy(&(val->value[offset]), value, length); + val->length = length; + } + } + // attribute value cannot be set + else + { + status = ATT_ERR_REQUEST_NOT_SUPPORTED; + } + } + } + + return (status); +} + +uint8_t attm_reserve_handle_range(uint16_t* start_hdl, uint8_t nb_att) +{ + struct gattm_svc_desc svc_desc; + uint8_t status; + + // create a fake service description containing handle range to allocate + svc_desc.start_hdl = *start_hdl; + svc_desc.nb_att = nb_att - 1; + + // use check service handle to verify if the handle range can be allocated + status = attmdb_svc_check_hdl(&svc_desc); + + // update service start handle that should be used for service allocation + *start_hdl = svc_desc.start_hdl; + + //return if service range can be allocated or not. + return (status); +} + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gap/gapc_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gap/gapc_int.h new file mode 100644 index 0000000..11f883b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gap/gapc_int.h @@ -0,0 +1,394 @@ +/** + **************************************************************************************** + * + * @file gapc_int.h + * + * @brief Generic Access Profile Controller Internal Header. + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ +#ifndef _GAPC_INT_H_ +#define _GAPC_INT_H_ + +/** + **************************************************************************************** + * @addtogroup GAPC_INT Generic Access Profile Controller Internals + * @ingroup GAPC + * @brief Handles ALL Internal GAPC API + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_GAPC) +#include "gapc.h" +#include "gapc_task.h" +#include "co_bt.h" +/* + * MACROS + **************************************************************************************** + */ + + +/* + * DEFINES + **************************************************************************************** + */ + +/// number of GAP Controller Process +#define GAPC_IDX_MAX BLE_CONNECTION_MAX + + +/** + * Repeated Attempts Timer Configuration + */ +/// Repeated Attempts Timer default value (x10ms) +#define GAPC_SMP_REP_ATTEMPTS_TIMER_DEF_VAL (200) //2s +/// Repeated Attempts Timer max value (x10ms) +#define GAPC_SMP_REP_ATTEMPTS_TIMER_MAX_VAL (3000) //30s +/// Repeated Attempts Timer multiplier +#define GAPC_SMP_REP_ATTEMPTS_TIMER_MULT (2) + + +/// states of GAP Controller task +enum gapc_state_id +{ + /// Connection ready state + GAPC_READY, + + /// Link Operation on-going + GAPC_LINK_INFO_BUSY = (1 << GAPC_OP_LINK_INFO), + /// SMP Operation on-going + GAPC_SMP_BUSY = (1 << GAPC_OP_SMP), + /// Update Operation on-going + GAPC_LINK_UPD_BUSY = (1 << GAPC_OP_LINK_UPD), + /// SMP start encryption on-going + GAPC_ENCRYPT_BUSY = (1 << GAPC_OP_MAX), + + /// Disconnection on-going + GAPC_DISC_BUSY = 0x1F, + /// Free state + GAPC_FREE = 0X3F, + + /// Number of defined states. + GAPC_STATE_MAX +}; + +/// fields definitions. +/// Configuration fields: +/// 7 6 5 4 3 2 1 0 +/// +----+----+----+----+----+----+----+----+ +/// |RFU |SCEN|ROLE|LTK |ENC |BOND| SEC_LVL | +/// +----+----+----+----+----+----+----+----+ +enum gapc_fields +{ + /// Link Security Level + GAPC_SEC_LVL_LSB = 0, + GAPC_SEC_LVL_MASK = 0x03, + /// Link Bonded or not + GAPC_BONDED_POS = 2, + GAPC_BONDED_BIT = 0x04, + /// Encrypted connection or not + GAPC_ENCRYPTED_POS = 3, + GAPC_ENCRYPTED_BIT = 0x08, + /// Ltk present and exchanged during pairing + GAPC_LTK_PRESENT_POS = 4, + GAPC_LTK_PRESENT_BIT = 0x10, + /// Local connection role + GAPC_ROLE_POS = 5, + GAPC_ROLE_BIT = 0x20, + /// Used to know if secure connection is enabled + GAPC_SC_EN_POS = 6, + GAPC_SC_EN_BIT = 0x40, +}; +/* + * TYPE DECLARATIONS + **************************************************************************************** + */ + +struct l2cc_pdu; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ +extern struct gapc_env_tag* gapc_env[GAPC_IDX_MAX]; + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize Generic Access Profile Controller Module. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + * + **************************************************************************************** + */ +void gapc_init(uint8_t init_type); + + +/** + **************************************************************************************** + * @brief A connection has been created, initialize Controller task. + * + * This function find first available task index available for new connection. + * It triggers also connection event to task that has requested the connection. + * + * @param[in] msgid Message id for normal or enhanced privacy + * @param[in] con_params Connection parameters from lower layers + * @param[in] requester Task that request the connection to send indication(s) + * @param[in] laddr Local BD Address + * @param[in] laddr_type Local BD Address Type (PUBLIC or RAND) + * + * @return Connection index allocated to the new connection. + **************************************************************************************** + */ +uint8_t gapc_con_create(ke_msg_id_t const msgid, struct hci_le_enh_con_cmp_evt const *con_params, + ke_task_id_t requester, bd_addr_t* laddr, uint8_t laddr_type); + +/** + **************************************************************************************** + * @brief A connection has been disconnected, uninitialized Controller task. + * + * unregister connection, and destroy environment variable allocated for current connection. + * + * @param[in] conidx Connection index + * + * @return Connection index of the connection. + **************************************************************************************** + */ +uint8_t gapc_con_cleanup(uint8_t conidx); + + +/** + **************************************************************************************** + * @brief Send Disconnection indication to specific task + * + * @param[in] conidx Connection index + * @param[in] reason Disconnection reason + * @param[in] conhdl Connection handle + * @param[in] dest_id Message destination ID + * + **************************************************************************************** + */ +void gapc_send_disconect_ind(uint8_t conidx, uint8_t reason, uint8_t conhdl, + ke_task_id_t dest_id); + + + +/** + * @brief Send a complete event of ongoing executed operation to requester. + * It also clean-up variable used for ongoing operation. + * + * @param[in] conidx Connection index + * @param[in] op_type Operation type. + * @param[in] status Status of completed operation + */ +void gapc_send_complete_evt(uint8_t conidx, uint8_t op_type, uint8_t status); + +/** + **************************************************************************************** + * @brief Send operation completed message with status error code not related to a + * running operation. + * + * @param[in] conidx Connection index + * @param[in] operation Operation code + * @param[in] requester requester of operation + * @param[in] status Error status code + **************************************************************************************** + */ +void gapc_send_error_evt(uint8_t conidx, uint8_t operation, const ke_task_id_t requester, uint8_t status); + + +/** + **************************************************************************************** + * @brief Get operation on going + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return operation code on going + **************************************************************************************** + */ +uint8_t gapc_get_operation(uint8_t conidx, uint8_t op_type); + +/** + **************************************************************************************** + * @brief Get operation pointer + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return operation pointer on going + **************************************************************************************** + */ +void* gapc_get_operation_ptr(uint8_t conidx, uint8_t op_type); + + +/** + **************************************************************************************** + * @brief Set operation pointer + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * @param[in] op Operation pointer. + * + **************************************************************************************** + */ +void gapc_set_operation_ptr(uint8_t conidx, uint8_t op_type, void* op); + +/** + **************************************************************************************** + * @brief Operation execution not finish, request kernel to reschedule it in order to + * continue its execution + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return if operation has been rescheduled (not done if operation pointer is null) + **************************************************************************************** + */ +bool gapc_reschedule_operation(uint8_t conidx, uint8_t op_type); + +/** + **************************************************************************************** + * @brief Get requester of on going operation + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return ID of task that requested to execute the operation + **************************************************************************************** + */ +ke_task_id_t gapc_get_requester(uint8_t conidx, uint8_t op_type); + +/** + **************************************************************************************** + * @brief Update link authentication level + * + * @param[in] conidx Connection index + * @param[in] auth Link authentication level + * @param[in] ltk_present Link paired and an LTK has been exchanged + * + **************************************************************************************** + */ +void gapc_auth_set(uint8_t conidx, uint8_t auth, bool ltk_present); + +/** + **************************************************************************************** + * @brief Retrieve link authentication level + * + * @param[in] conidx Connection index + * @return Link authentication level + **************************************************************************************** + */ +uint8_t gapc_auth_get(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Update task state + * + * @param[in] conidx Connection index + * @param[in] state to update + * @param[in] set state to busy (true) or idle (false) + * + **************************************************************************************** + */ +void gapc_update_state(uint8_t conidx, ke_state_t state, bool busy); + + +/** + **************************************************************************************** + * @brief Checks connection parameters values + * + * @param[in] intv_max maximum interval + * @param[in] intv_min minimum interval + * @param[in] latency latency + * @param[in] timeout timeout value + * + * @return true if OK, false if not OK + **************************************************************************************** + */ +bool gapc_param_update_sanity(uint16_t intv_max, uint16_t intv_min, uint16_t latency, uint16_t timeout); + +/** + **************************************************************************************** + * @brief Get channel selection algorithm used for a given connection identified + * by its connection index + * + * @param[in] conidx Connection index + * + * @return Channel selection algorithm used (0 if algo #1, 1 if algo #2) + **************************************************************************************** + */ +uint8_t gapc_get_chan_sel_algo(uint8_t conidx); + + +/** + **************************************************************************************** + * @brief Handle reception of a SMP PDU sent by the peer device. + * + * @param[in] conidx Connection Index + * @param[in] pdu Unpacked PDU + * @param[in] status status of the execution + **************************************************************************************** + */ +void gapc_smp_pdu_recv(uint8_t conidx, struct l2cc_pdu *pdu, uint8_t status); + +/** + **************************************************************************************** + * @brief Clean-up SMP operation + * + * @param[in] conidx Connection Index + **************************************************************************************** + */ +void gapc_smp_cleanup(uint8_t conidx); + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Check if current operation can be processed or not. + * if it can be proceed, initialize an operation request. + * If a command complete event with error code can be triggered. + * + * Function returns how the message should be handled by message handler. + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * @param[in] op_msg Requested operation message (note op_msg cannot be null) + * @param[in] supp_ops Supported operations array. + * Latest array value shall be GAPC_NO_OP. + * + * @return operation can be executed if message status equals KE_MSG_NO_FREE, + * else nothing to do, just exit from the handler. + **************************************************************************************** + */ +int gapc_process_op(uint8_t conidx, uint8_t op_type, void* op_msg, enum gapc_operation* supp_ops); + + + + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +#endif // (BLE_GAPC) +/// @} GAPC_INT + +#endif /* _GAPC_INT_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gap/gapc_sig.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gap/gapc_sig.h new file mode 100644 index 0000000..f336b32 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gap/gapc_sig.h @@ -0,0 +1,64 @@ +/** + **************************************************************************************** + * + * @file gapc_sig.h + * + * @brief Generic Access Profile Controller Signaling PDU Handler. + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + +#ifndef _GAPC_SIG_H_ +#define _GAPC_SIG_H_ + + +/** + **************************************************************************************** + * @addtogroup GAPC_SIG Generic Access Profile Controller Signaling PDU Handler. + * @ingroup GAPC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_GAPC) +#include "l2cc_pdu.h" + + +#if (BLE_CENTRALH) +/** + **************************************************************************************** + * @brief Sends parameter response + * + * @param[in] conidx connection index + * @param[in] result response result + * @param[in] pkt_id Packet identifier + **************************************************************************************** + */ +void gapc_sig_send_param_resp(uint8_t conidx, uint16_t result, uint8_t pkt_id); +#endif // (BLE_CENTRALH) + +/** + **************************************************************************************** + * @brief Handles reception of L2CAP signaling messages from peer device. + * + * @param[in] conidx Connection Index + * @param[in] pdu PDU Received + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int gapc_sig_pdu_recv_handler(uint8_t conidx, struct l2cc_pdu *pdu); + +#endif // (BLE_GAPC) + +#endif // _GAPC_SIG_H_ + +/// @} GAPC_SIG diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gap/gapm_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gap/gapm_int.h new file mode 100644 index 0000000..03f6856 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gap/gapm_int.h @@ -0,0 +1,799 @@ +/** + **************************************************************************************** + * + * @file gapm_int.h + * + * @brief Generic Access Profile Manager Internal Header. + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + + +#ifndef _GAPM_INT_H_ +#define _GAPM_INT_H_ + +/** + **************************************************************************************** + * @addtogroup GAPM_INT Generic Access Profile Manager Internal + * @ingroup GAPM + * @brief defines for internal GAPM usage + * + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "gapm.h" +#include "gapm_task.h" +#include "co_bt.h" + + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of GAP Manager process +#define GAPM_IDX_MAX 0x01 + +/// Scan filter size +#define GAPM_SCAN_FILTER_SIZE 10 + +/// check if current role is supported by configuration +#define GAPM_IS_ROLE_SUPPORTED(role_type)\ + ((gapm_env.role & (role_type)) == (role_type)) + +/// Number of supported activities in host +#define GAPM_ACTV_NB (BLE_ACTIVITY_MAX) +/// Invalid activity identifier +#define GAPM_ACTV_INVALID_IDX (0xFF) + +/* + * INTERNAL API TYPES + **************************************************************************************** + */ + + +/// Retrieve information about memory usage +struct gapm_dbg_get_mem_info_cmd +{ + /// GAPM requested operation: + /// - GAPM_DBG_GET_MEM_INFO: Get memory usage + uint8_t operation; +}; + +/// Indication containing information about memory usage. +/*@TRACE*/ +struct gapm_dbg_mem_info_ind +{ + /// peak of memory usage measured + uint32_t max_mem_used; + /// memory size currently used into each heaps. + uint16_t mem_used[KE_MEM_BLOCK_MAX]; +}; + + +/// Operation type +enum gapm_op_type +{ + /// Configuration operation + GAPM_OP_CFG = 0x00, + + /// Air mode operation (scanning, advertising, connection establishment) + /// Note: Restriction, only one air operation supported. + GAPM_OP_AIR = 0x01, + /// GAP State for DH Key Generation + GAPM_OP_DHKEY = 0x02, + /// Max number of operations + GAPM_OP_MAX +}; + +/// GAPM states +enum gapm_state_id +{ + /// Idle state - no on going operation + GAPM_IDLE, + + /// Busy state - Configuration operation on going + GAPM_CFG_BUSY = 1 << GAPM_OP_CFG, + /// Busy state - Air operation on going + GAPM_AIR_BUSY = 1 << GAPM_OP_AIR, + /// Busy state - DH Key Calculation operation on going + GAPM_DHKEY_BUSY = 1 << GAPM_OP_DHKEY, + + /// Reset state - Reset operation on going + GAPM_DEVICE_SETUP = 1 << GAPM_OP_MAX, + + GAPM_STATE_MAX +}; + +/// Device configuration flags +/// 7 6 5 4 3 2 1 0 +/// +-----+----+----+----+----+----+----+----+ +/// | RFU |RPAO| CP | GA | RE |CTLP|HSTP|ADDR| +/// +-----+----+----+----+----+----+----+----+ +/// - Bit [0-2]: Address Type @see enum gapm_cfg_flag +/// Bit 0: 0 = Public address, 1 = Private address +/// Bit 2: 0 = Controller-based Privacy disabled, 1 = enabled +/// +/// - Bit [3] : Address to renew (only if privacy is enabled, 1 address to renew else 0) +/// - Bit [4] : Generated Address type (1 = Resolvable, 0 = Non Resolvable) +/// - Bit [5] : Preferred Connection parameters present in GAP DB +/// Configuration flag bit description +enum gapm_cfg_flag_def +{ + /// Address Type + GAPM_ADDR_TYPE_MASK = 0x07, + GAPM_ADDR_TYPE_LSB = 0, + /// Address to renew + GAPM_ADDR_RENEW_MASK = 0x08, + GAPM_ADDR_RENEW_LSB = 3, + /// Generated Address type + GAPM_RESOLV_ADDR_MASK = 0x10, + GAPM_RESOLV_ADDR_LSB = 4, + /// Preferred Connection parameters present in GAP DB + GAPM_PREF_CON_PAR_PRES_MASK = 0x20, + GAPM_PREF_CON_PAR_PRES_LSB = 5, +}; + +#if (RW_DEBUG) +/// Device configuration flags +/// 7 6 5 4 3 2 1 0 +/// +-----+----+----+----+----+----+----+----+ +/// | RFU |DBGT| DBG| +/// +-----+----+----+----+----+----+----+----+ +/// - Bit [0]: Enable Debug mode +/// - Bit [1]: Forward all L2cap traffic +enum gapm_dbg_cfg +{ + /// Enable Debug mode + GAPM_DBG_MODE_EN_MASK = 0x01, + GAPM_DBG_MODE_EN_LSB = 0x00, + + /// Enable Debug mode + GAPM_DBG_L2CAP_TRAFFIC_FWD_EN_MASK = 0x02, + GAPM_DBG_L2CAP_TRAFFIC_FWD_EN_LSB = 0x01, +}; +#endif // (RW_DEBUG) + +/// Activity states +enum gapm_actv_state +{ + /// Activity is being created - next state is CREATED + GAPM_ACTV_CREATING = 0, + /// Activity has been successfully created + GAPM_ACTV_CREATED, + /// Activity is being started - next state is STARTED + GAPM_ACTV_STARTING, + /// Activity has been successfully started + GAPM_ACTV_STARTED, + /// Activity is being stopped - next state is CREATED + GAPM_ACTV_STOPPING, + /// Activity is being deleted - no next state + GAPM_ACTV_DELETING, +}; + +/// Connection role +enum gapm_conn_role +{ + /// Master + GAPM_ROLE_MASTER = 0, + /// Slave + GAPM_ROLE_SLAVE, +}; + +/* + * MACROS + **************************************************************************************** + */ +/// Macro used to retrieve field +#define GAPM_F_GET(data, field)\ + (((data) & (GAPM_MASK_ ## field)) >> (GAPM_POS_ ## field)) + +/// Macro used to set field +#define GAPM_F_SET(data, field, val)\ + (data) = (((data) & ~(GAPM_MASK_ ## field)) \ + | ((val << (GAPM_POS_ ## field)) & (GAPM_MASK_ ## field))) + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Information about registered LE_PSM +struct gapm_le_psm_info +{ + /// List header structure to put information within a list + struct co_list_hdr hdr; + + /// LE Protocol/Service Multiplexer + uint16_t le_psm; + + /// Registered task identifier + ke_task_id_t task_id; + + /// Security level + /// 7 6 5 4 3 2 1 0 + /// +---+---+---+---+---+---+---+---+ + /// |MI | RFU |EKS|SEC_LVL| + /// +---+---+---+---+---+---+---+---+ + /// bit[0-1]: Security level requirement (0=NO_AUTH, 1=UNAUTH, 2=AUTH, 3=SEC_CON) + /// bit[2] : Encryption Key Size length must have 16 bytes + /// bit[7] : Multi-instantiated task + uint8_t sec_lvl; + + /// Number of established link + uint8_t nb_est_lk; +}; + +/// GAP Manager environment structure +struct gapm_env_tag +{ + /// Request operation Kernel message + void* operation[GAPM_OP_MAX]; + + /// Array of pointers to the allocated activities + struct gapm_actv_tag *actvs[GAPM_ACTV_NB]; + + #if (BLE_LECB) + /// Registered list of LE Protocol/Service Multiplexer for LE Credit Based Connection + struct co_list reg_le_psm; + #endif // (BLE_LECB) + + #if (BLE_CENTRALH || BLE_PERIPHERAL) + /// Bit field use to know if periodic ADV sync transfer establishment on-going onto a specific connection index + uint32_t past_estab_bf; + #endif // (BLE_CENTRALH || BLE_PERIPHERAL) + + /// Task that receive test mode events. + uint16_t test_report_task; + + #if (BLE_ATTS) + /// GAP service start handle + uint16_t svc_start_hdl; + #endif // (BLE_ATTS) + + #if (BLE_BROADCASTER) + /// Maximum length of advertising data that can be pushed to the controller + uint16_t max_adv_data_len; + #endif //(BLE_BROADCASTER) + + /// Duration before regenerate device address when privacy is enabled. - in seconds + uint16_t renew_dur; + /// Device IRK used for resolvable random BD address generation (MSB -> LSB) + struct gap_sec_key irk; + + /// Current device Address + bd_addr_t addr; + /// Device Role + uint8_t role; + /// Number of BLE connection + uint8_t connections; + /// Device configuration flags - (@see enum gapm_cfg_flag_def) + uint8_t cfg_flags; + /// Pairing mode authorized (see enum gapm_pairing_mode) + uint8_t pairing_mode; + /// Maximum device MTU size + uint16_t max_mtu; + /// Maximum device MPS size + uint16_t max_mps; + + #if(BLE_ISO_MODE_0_PROTOCOL) + /// Audio configuration flag (see gapm_audio_cfg_flag) + uint16_t audio_cfg; + #endif // (BLE_ISO_MODE_0_PROTOCOL) + + #if (BLE_LECB) + /// Maximum number of allowed LE Credit Based channels + uint8_t max_nb_lecb; + /// Current number of LE Credit Based channel connections established + uint8_t nb_lecb; + #endif // (BLE_LECB) + + #if (BLE_BROADCASTER) + /// Number of advertising sets supported by controller + uint8_t max_adv_set; + /// Number of created advertising activities + uint8_t nb_adv_actv; + #endif //(BLE_BROADCASTER) + #if (BLE_OBSERVERH) + /// Activity identifier for currently started scanning activity + uint8_t scan_actv_idx; + #endif //(BLE_OBSERVERH) + #if (BLE_CENTRALH) + /// Activity identifier for currently started initiating activity + uint8_t init_actv_idx; + #endif //(BLE_CENTRALH) + /// Activity identifier currently used for air operation + uint8_t actv_idx; + + #if (BLE_OBSERVERH) + /// Activity in Periodic sync establishment state + uint8_t per_sync_estab_actv_idx; + #endif //(BLE_OBSERVERH) + + /// Number of created activities + uint8_t created_actvs; + /// Number of started activities + uint8_t started_actvs; + /// Number of started activities that can lead to connection establishment (connectable + /// advertising or initiating) + uint8_t connect_actvs; + /// Number of devices in the white list + uint8_t nb_dev_wl; + /// State of GAPM ADDR module + uint8_t gapm_addr_state; + + #if (RW_DEBUG) + /// Debug configuration @see gapm_dbg_cfg + uint8_t dbg_cfg; + #endif // (RW_DEBUG) +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ +/// GAP Manager environment variable. +extern struct gapm_env_tag gapm_env; + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize GAP attribute database + * + * @param[in] start_hdl Service Start Handle + * @param[in] feat Attribute database features + * + * @return status code of attribute database initialization + * - @ref ATT_ERR_NO_ERROR: If database creation succeeds. + * - @ref ATT_ERR_INVALID_HANDLE: If start_hdl given in parameter + nb of attribute override + * some existing services handles. + * - @ref ATT_ERR_INSUFF_RESOURCE: There is not enough memory to allocate service buffer. + * or of new attribute cannot be added because all expected + * attributes already add + **************************************************************************************** + */ +uint8_t gapm_init_attr(uint16_t start_hdl, uint32_t feat); + +/** + **************************************************************************************** + * @brief Send operation completed message according to operation type. + * Perform also am operation clean-up + * + * @param[in] op_type Operation type + * @param[in] status Command status + ***************************************************************************************** + */ +void gapm_send_complete_evt(uint8_t op_type, uint8_t status); + +/** + **************************************************************************************** + * @brief Send operation completed message with status error code not related to a + * running operation. + * + * @param[in] operation Operation code + * @param[in] requester requester of operation + * @param[in] status Error status code + **************************************************************************************** + */ +void gapm_send_error_evt(uint8_t operation, const ke_task_id_t requester, uint8_t status); + + +/** + **************************************************************************************** + * @brief Get operation pointer + * + * @param[in] op_type Operation type. + * + * @return operation pointer on going + **************************************************************************************** + */ +__INLINE void* gapm_get_operation_ptr(uint8_t op_type) +{ + ASSERT_ERR(op_type < GAPM_OP_MAX); + // return operation pointer + return gapm_env.operation[op_type]; +} + + +/** + **************************************************************************************** + * @brief Set operation pointer + * + * @param[in] op_type Operation type. + * @param[in] op Operation pointer. + * + **************************************************************************************** + */ +__INLINE void gapm_set_operation_ptr(uint8_t op_type, void* op) +{ + ASSERT_ERR(op_type < GAPM_OP_MAX); + // update operation pointer + gapm_env.operation[op_type] = op; +} + + +/** + **************************************************************************************** + * @brief Check if current operation can be processed or not. + * if it can be proceed, initialize an operation request. + * If a command complete event with error code can be triggered. + * + * Function returns how the message should be handled by message handler. + * + * @param[in] op_type Operation type. + * @param[in] op_msg Requested operation message (note op_msg cannot be null) + * @param[in] supp_ops Supported operations array. + * Latest array value shall be GAPM_NO_OP. + * + * @return operation can be executed if message status equals KE_MSG_NO_FREE, + * else nothing to do, just exit from the handler. + **************************************************************************************** + */ +int gapm_process_op(uint8_t op_type, void* op_msg, enum gapm_operation* supp_ops); + +/** + **************************************************************************************** + * @brief Get operation on going + * + * @param[in] op_type Operation type. + * + * @return operation code on going + **************************************************************************************** + */ +uint8_t gapm_get_operation(uint8_t op_type); + +/** + **************************************************************************************** + * @brief Get requester of on going operation + * + * @param[in] op_type Operation type. + * + * @return task that requests to execute the operation + **************************************************************************************** + */ +ke_task_id_t gapm_get_requester(uint8_t op_type); + + + + +#if (BLE_GAPC) +/** + **************************************************************************************** + * @brief A connection has been created, initialize host stack to be ready for connection. + * + * @param[in] msgid Message id + * @param[in] con_params Connection parameters from lower layers + * + * @return Connection index allocated to the new connection. + **************************************************************************************** + */ +uint8_t gapm_con_create(ke_msg_id_t const msgid, struct hci_le_enh_con_cmp_evt const *con_params); +#endif // (BLE_GAPC) + +/** + **************************************************************************************** + * @brief Checks validity of the address type + * + * @param[in] addr_type Address type + **************************************************************************************** + */ +uint8_t gapm_addr_check( uint8_t addr_type); + +/** + **************************************************************************************** + * @brief Checks validity of the Data Length Suggested values + * + * @param[in] sugg_oct Suggested octets + * @param[in] sugg_time Suggested time + **************************************************************************************** + */ +uint8_t gapm_dle_val_check(uint16_t sugg_oct, uint16_t sugg_time); + + + +/** + **************************************************************************************** + * @brief Update task state + * + * @param[in] operation that modify the state + * @param[in] set state to busy (true) or idle (false) + * + **************************************************************************************** + */ +void gapm_update_state(uint8_t operation, bool busy); + + + +#if (BLE_LECB) + + +/** + **************************************************************************************** + * @brief Find Information about LE_PSM registered in GAPM + * + * @param[in] le_psm LE Protocol/Service Multiplexer + * + * @return Null if not found or LE_PSM info structure + **************************************************************************************** + */ +struct gapm_le_psm_info* gapm_le_psm_find(uint16_t le_psm); + + +/** + **************************************************************************************** + * @brief Remove all registered LE_PSM + **************************************************************************************** + */ +void gapm_le_psm_cleanup(void); +#endif // (BLE_LECB) + +/** + **************************************************************************************** + * @brief Reset the environment by cleaning all existing activities + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void gapm_actv_reset(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Allocate an activity structure for a given identifier. Provided identifer is + * then no more marked as available. + * It is considered here that provided activity identifier is an available one. + * + * @param[in] actv_idx Activity index + * @param[in] size Size of the activity structure to be allocated + * + * @return Pointer to the allocated activity structure + **************************************************************************************** + */ +struct gapm_actv_tag *gapm_actv_alloc(uint8_t actv_idx, uint8_t size); + +/** + **************************************************************************************** + * @brief Retrieve activity for which an HCI command complete event has been received. + * Note that at any time only one HCI command complete event can be expected by GAPM. + * Hence only one activity can be found. + * This function also check that the operation code of the complete command well + * match with the command that has been sent for the foun activity. + * + * @param[in|out] pp_actv Pointer to the variable that will contain address of + * activity structure for which command complete event + * has been received. + * @param[in] opcode Command operation code for which a command complete event has + * been received + * + * @return true if activity has been retrieved, else false + **************************************************************************************** + */ +bool gapm_actv_retrieve_cmd_cmp_evt(struct gapm_actv_tag **pp_actv, uint16_t opcode); + +/** + **************************************************************************************** + * @brief Get own address type to be sent in HCI commands. + * + * @param[in] app_addr_type Address type provided by application using GAPM_SET_DEV_CONFIG_CMD. + * + * @return Own address type value + * - 0: Public Device Address + * - 1: Random Device Address + * - 2: Controller generates the RPA based on the local IRK from the resolving list. + * If the resolving list contains no matching entry, use the public address + * - 3: Controller generates the RPA based on the local IRK from the resolving list. + * If the resolving list contains no matching entry, use the random address that has + * been set using HCI LE Set Advertising Set Random Address. + **************************************************************************************** + */ +uint8_t gapm_actv_get_hci_own_addr_type(uint8_t app_addr_type); + +/** + **************************************************************************************** + * @brief Notify the activity module that activity creation procedure is over. + * + * @param[in] p_actv Pointer to the structure describing the created activity + * @param[in] error Indicate if an error has been raised during activity creation + **************************************************************************************** + */ +void gapm_actv_created(struct gapm_actv_tag *p_actv, uint8_t error); + +/** + **************************************************************************************** + * @brief Notify the activity module that a start activity procedure is over + * + * @param[in] p_actv Pointer to the structure describing the started activity + * @param[in] error Indicate if an error has been raised during activity start procedure + **************************************************************************************** + */ +void gapm_actv_started(struct gapm_actv_tag *p_actv, uint8_t error); + +/** + **************************************************************************************** + * @brief Notify the activity module that an activity has well been stopped. + * + * @param[in] p_actv Pointer to the structure describing the stopped activity + * @param[in] status Activity stop operation status + **************************************************************************************** + */ +void gapm_actv_stopped(struct gapm_actv_tag *p_actv, uint8_t status); + +/** + **************************************************************************************** + * @brief Function used once an activity has been cleaned and can be deleted + * + * @param[in] p_actv Pointer to the structure describing the stopped activity + * @param[in] error Indicate if activity has well been stopped + **************************************************************************************** + */ +void gapm_actv_deleted(struct gapm_actv_tag *p_actv); + +/** + **************************************************************************************** + * @brief Callback function used by GAPM ADDR module in order to inform the GAPM ACTV + * module that a random address (generated or not) has been set in the controller + * upon its request. + * + * @param[in] p_actv Pointer to the activity structure for which random address has + * been set. + **************************************************************************************** + */ +void gapm_actv_rand_addr_set_ind(struct gapm_actv_tag *p_actv); + +#if (BLE_BROADCASTER) +/** + **************************************************************************************** + * @brief Allocate an activity structure to be used for an advertising activity. + * + * @param[in] actv_idx Allocated activity identifier + * @param[in] p_param GAPM_ACTIVITY_CREATE_CMD message parameters + **************************************************************************************** + */ +uint8_t gapm_adv_create(uint8_t actv_idx, struct gapm_activity_create_adv_cmd *p_param); +#endif //(BLE_BROADCASTER) + +#if (BLE_OBSERVERH) +/** + **************************************************************************************** + * @brief Clean content of a scan activity, more specifically the stored fragments + * of advertising report and the filtering list. + * + * @param[in] p_actv Pointer to the scanning activity structure. + **************************************************************************************** + */ +void gapm_scan_actv_clean(struct gapm_actv_tag *p_actv); + +/** + **************************************************************************************** + * @brief Allocate an activity structure to be used for a scanning activity. + * + * @param[in] actv_idx Allocated activity identifier + * @param[in] p_param GAPM_ACTIVITY_CREATE_CMD message parameters + * + * @return GAP_ERR_NO_ERROR if creation of activity can be started, + * GAP_ERR_COMMAND_DISALLOWED if activity cannot be started + * GAP_ERR_INSUFF_RESOURCES if not enough memory is found for activity structure + * allocation. + **************************************************************************************** + */ +uint8_t gapm_scan_create(uint8_t actv_idx, struct gapm_activity_create_cmd *p_param); +#endif //(BLE_OBSERVERH) + +#if (BLE_CENTRALH) +/** + **************************************************************************************** + * @brief Allocate an activity structure to be used for an initiating activity. + * + * @param[in] actv_idx Allocated activity identifier + * @param[in] p_param GAPM_ACTIVITY_CREATE_CMD message parameters + **************************************************************************************** + */ +uint8_t gapm_init_create(uint8_t actv_idx, struct gapm_activity_create_cmd *p_param); + +/** + **************************************************************************************** + * @brief Function used by GAPM_ACTV module to inform GAPM_INIT that a new connection + * has been established. + * If current initiating type is a name discovery, it triggers sending of a GAPC_GET_INFO_CMD + * in order to retrieve the peer device name. + * If current initiating type is an automatic connection establishment, a new HCI LE + * Extended Create Connection command will be sent to the controller if not all device in + * the white list have been connected. + * If no more connection is expected, the activity is stopped. + * + * @param[in] conidx Connection index allocated for the newly established connection + * + * @return True if the activity has to be stopped, else false. + **************************************************************************************** + */ +bool gapm_init_connection_ind(uint8_t conidx); +#endif //(BLE_CENTRALH) + +#if (BLE_OBSERVERH) + /** + **************************************************************************************** + * @brief Allocate an activity structure to be used for a periodic synchronization activity. + * + * @param[in] actv_idx Allocated activity identifier + * @param[in] p_param GAPM_ACTIVITY_CREATE_CMD message parameters + * + * @return GAP_ERR_NO_ERROR if activity creation has ended properly, GAP_ERR_INSUFF_RESOURCES + * if no available memory has been found for activity allocation. + **************************************************************************************** + */ +uint8_t gapm_per_sync_create(uint8_t actv_idx, struct gapm_activity_create_cmd *p_param); + +/** + **************************************************************************************** + * @brief Request to clear all report fragments stored in the periodic synchronization + * activity + * + * @param[in] p_actv_per_sync Pointer to the activity structure + **************************************************************************************** + */ +void gapm_per_sync_clear_fragments(struct gapm_actv_per_sync_tag *p_actv_per_sync); +#endif //(BLE_OBSERVERH) + +/** + **************************************************************************************** + * @brief Initialize GAPM address manager module + **************************************************************************************** + */ +void gapm_addr_init(void); + +/** + **************************************************************************************** + * @brief Function to be used to check if address type provided for a scanning or an + * initiating activity is valid or not. + * As a same address shall be shared between all these activities, all created scanning and + * initiating activities shall have the same address type. + * + * @param[in] addr_type Address type to be checked + * + * @return true if provided address type is valid, else false + **************************************************************************************** + */ +bool gapm_is_addr_type_valid(uint8_t addr_type); + +/** + **************************************************************************************** + * @brief Request to clear all report fragments stored in the periodic synchronization + * activity + * + * @param[in] p_actv Pointer to the activity structure for which a random has to be + * generated and/or set in the controller. + **************************************************************************************** + */ +void gapm_addr_set_rand_addr(struct gapm_actv_tag *p_actv); + +/** + **************************************************************************************** + * @brief Sends a basic HCI command (with no parameter) + * + * @param[in] opcode Command opcode + **************************************************************************************** + */ +void hci_basic_cmd_send_2_controller(uint16_t opcode); + + +/* + * TASK DESCRIPTOR DECLARATIONS + **************************************************************************************** + */ + +/// @} GAPM_INT + +#endif /* _GAPM_INT_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/attc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/attc.h new file mode 100644 index 0000000..be2a938 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/attc.h @@ -0,0 +1,127 @@ +/** + **************************************************************************************** + * + * @file attc.h + * + * @brief Header file - ATTC. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef ATTC_H_ +#define ATTC_H_ + +/** + **************************************************************************************** + * @addtogroup ATTC Attribute Client + * @ingroup ATT + * @brief Attribute Protocol Client + * + * The ATTC module is responsible for handling messages intended for the attribute + * profile client. It has defined interfaces with @ref ATTM "ATTM". + * + * @{ + * + **************************************************************************************** + */ +#include "rwip_config.h" + +#include +#include "l2cc.h" +#include "ke_task.h" + +#if (BLE_ATTC) +/* + * INCLUDE FILES + **************************************************************************************** + */ +/* + * DEFINES + **************************************************************************************** + */ + +/// Allocate a Attribute PDU packet for a specific attribute request. +#define ATTC_ALLOCATE_ATT_REQ(conidx, opcode, pdu_type, value_len)\ + L2CC_ATT_PDU_ALLOC_DYN(conidx, opcode, KE_BUILD_ID(TASK_GATTC, conidx), pdu_type, value_len) + +/* + * DATA STRUCTURES + **************************************************************************************** + */ + +/// Peer device event registration +struct attc_register_evt +{ + /// list header + struct co_list_hdr hdr; + /// Attribute start handle + uint16_t start_hdl; + /// Attribute end handle + uint16_t end_hdl; + /// Task to be notified + ke_task_id_t task; +}; + + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Sends Indication reception confirmation message + * + * @param[in] conidx connection index + * + **************************************************************************************** + */ +void attc_send_hdl_cfm(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Sends write execute. + * + * @param[in] conidx connection index + * @param[in] flag write execute flag (write or discard) + * + **************************************************************************************** + */ +void attc_send_execute(uint8_t conidx, uint8_t flag); + + +/** + **************************************************************************************** + * @brief Send a PDU Attribute request packet + * + * @param[in] conidx Index of the connection with the peer device + * @param[in] pdu PDU Packet + **************************************************************************************** + */ +void attc_send_att_req(uint8_t conidx, void *pdu); + +#endif /* (BLE_ATTC) */ + +#if (BLE_CENTRALH || BLE_PERIPHERAL) +/** + **************************************************************************************** + * @brief Handles reception of PDU Packet + * + * @param[in] conidx Index of the connection with the peer device + * @param[in] param Received PDU Packet + * + * @return If message has been proceed or consumed + **************************************************************************************** + */ +int attc_l2cc_pdu_recv_handler(uint8_t conidx, struct l2cc_pdu_recv_ind *param); +#endif /* #if (BLE_CENTRALH || BLE_PERIPHERAL) */ + +/// @} ATTC +#endif // ATT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/attm_db.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/attm_db.h new file mode 100644 index 0000000..5f05bc3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/attm_db.h @@ -0,0 +1,420 @@ +/** + **************************************************************************************** + * + * @file attm_db.h + * + * @brief Header file - ATTM. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef ATTM_DB_H_ +#define ATTM_DB_H_ + +/** + **************************************************************************************** + * @addtogroup ATTDB Database + * @ingroup ATTM + * @brief Attribute Protocol Database + * + * The ATTDB module is responsible for providing different sets of attribute databases + * for Attribute Profile server. + * + * This module can be tailored by client, to match the requirement of the desired database. + * + * @{ + * + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_ATTS) +#include +#include "rwip_config.h" +#include "ke_task.h" +#include "attm.h" +#include "gattm_task.h" +#include "co_bt.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/** + * Extended Service permissions + * + * 7 6 5 4 3 2 1 0 + * +----+----+----+----+----+----+----+----+ + * | RFU |HIDE| + * +----+----+----+----+----+----+----+----+ + * + * Bit [0] : Hide service visibility + * Bit [1-7]: Reserved for future use + */ +enum attm_ext_svc_perm_mask +{ + /// Service visibility - Hide = 1 + PERM_MASK_EXT_SVC_HIDE = 0x01, + PERM_POS_EXT_SVC_HIDE = 0, +}; + + +/* + * TYPE DEFINITION + **************************************************************************************** + */ +#if(BLE_ATTS) + +/** + **************************************************************************************** + * @brief Callback definition used to retrieve value of database hash + * + * @param[in] status Execution status + * @param[in] p_hash Hash value computed + * @param[in] cb_info Source info used to retrieve requester + **************************************************************************************** + */ +typedef void (*attmdb_hash_res_cb) (uint8_t status, const uint8_t* p_hash, uint32_t cb_info); + +/** + * Attribute Description + */ +struct attm_att_desc +{ + /** + * 16 bits UUID or data offset used to retrieve 32 or 128 bits UUID in service memory block + */ + uint16_t uuid; + + /** + * Attribute Permission (@see attm_perm_mask) + */ + uint16_t perm; + + /** + * value information (@see attm_value_perm_mask) + */ + union att_info + { + /// attribute max length (RI = 1) + uint16_t max_length; + + /// attribute value offset pointer (RI = 0) + uint16_t offset; + } info; +}; + +/// attribute value if present in database +struct attm_att_value +{ + /// Maximum attribute length + uint16_t max_length; + /// currrent attribute length that can be read. + uint16_t length; + ///value data pointer + uint8_t value[__ARRAY_EMPTY]; +}; + +/// service description +struct attm_svc_desc +{ + /// Service Start Handle + uint16_t start_hdl; + /// Service End Handle + uint16_t end_hdl; + /// Task identifier that manages service + uint16_t task_id; + + /// Service Permission (@see attm_svc_perm_mask) + uint8_t perm; + /// Extended Service Permission (@see attm_ext_svc_perm_mask) + uint8_t ext_perm; + + /// Service 16 bits UUID (LSB First) or data offset used to retrieve 32 or 128 bits + /// UUID in service memory block + uint16_t uuid; +}; + +/** + * Service description present in attribute database + */ +struct attm_svc +{ + /// Next Service + struct attm_svc* next; + /// service description + struct attm_svc_desc svc; + /// List of attribute description present in service. + struct attm_att_desc atts[__ARRAY_EMPTY]; +}; + +/// Attribute element information +struct attm_elmt +{ + /// element info + union elem_info + { + /// attribute info pointer + struct attm_att_desc* att; + + /// service info pointer + struct attm_svc_desc* svc; + } info; + + /// use to know if current element is a service or an attribute + bool service; +}; + +/// Structure use to compute data hash +struct attm_db_hash_input +{ + /// function that handle computation result + attmdb_hash_res_cb res_cb; + /// value of the hash to compute + uint8_t value[__ARRAY_EMPTY]; +}; + + +/// ATTM General Information Manager +struct attm_db +{ + /// Hash input pointer used for hash computation + struct attm_db_hash_input* p_hash_input; + + /** + * ************************************************************************************** + * @brief Attribute database + * + * The Attribute database is a list of attribute services sorted by handle number. + * This database shall be initiate by GAP, GATT, profiles and application process at + * startup and must not change during runtime. + * + * Database initialization shall be deterministic in order to always have service handle + * at same position in database during all product life-cycle. This is required since + * database client can save position of services in database to not perform service + * discovery at each connection. + *************************************************************************************** + */ + struct attm_svc* svcs; + + /** + *************************************************************************************** + * Last attribute service searched. + * + * Used as a cached variable, it's used to reduce handle search duration. + *************************************************************************************** + */ + struct attm_svc* cache; + + /// Database hash value + uint8_t hash[KEY_LEN]; + + /// Used to know if database hash is valid or not + bool hash_valid; + + /** + * Temporary value used for read operation on service and characteristics attributes + */ + uint8_t temp_val[ATT_UUID_128_LEN + ATT_HANDLE_LEN + ATT_HANDLE_LEN]; +}; + + + + + +#endif //(BLE_ATTS) + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + * Check if Service handle Range can be allocated in Database, and if handle should be + * dynamically allocated, calculate first available handle range. + * + * @param[in|out] svc_desc Service information to add in DB + * + * @return status of operation + */ +uint8_t attmdb_svc_check_hdl(struct gattm_svc_desc* svc_desc); + +/** + **************************************************************************************** + * @brief Add a service in database. + * + * According to service start handle and number of attribute, ATTM DB allocate a set of + * attribute handles, then using other parameters it allocate a buffer used to describe + * service, and allocate attributes + their values. + * + * If start_hdl = 0, it allocated service using first available handle (start_hdl is + * modified); else it will allocate service according to given start handle. + * + * + * @param[in|out] svc_desc Service description. + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If service allocation succeeds. + * - @ref ATT_ERR_INVALID_HANDLE: If start_hdl given in parameter or UUIDs value invalid + * - @ref ATT_ERR_INSUFF_RESOURCE: There is not enough memory to allocate service buffer. + **************************************************************************************** + */ +uint8_t attmdb_add_service(struct gattm_svc_desc* svc_desc); + +/** + **************************************************************************************** + * @brief Compute Hash of the internal database. + * + * + * @param[in] res_cb Callback that will handle the result. + * @param[in] cb_info Requester source information value returned in callback + * + * @return Command status code (if GAP_ERR_NO_ERROR, wait for callback execution) + **************************************************************************************** + */ +uint8_t attmdb_hash_compute(attmdb_hash_res_cb res_cb, uint32_t cb_info); + +/** + **************************************************************************************** + * @brief Search in database from which service attribute handle comes from. + * + * @param[in] handle Attribute handle. + * + * @return Services that contains attribute handle; NULL if handle not available in + * database. + **************************************************************************************** + */ +struct attm_svc * attmdb_get_service(uint16_t handle); + +/** + **************************************************************************************** + * @brief Search in database Attribute pointer using attribute handle. + * + * @param[in] handle Attribute handle. + * @param[out] elmt Attribute element to fill + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If attribute found. + * - @ref ATT_ERR_INVALID_HANDLE: If No Attribute found + **************************************************************************************** + */ +uint8_t attmdb_get_attribute(uint16_t handle, struct attm_elmt*elmt); + +/** + **************************************************************************************** + * @brief Retrieve attribute at or after specified handle + * + * Retrieve first attribute with handle >= parameter handle. + * Parameter handle is updated according found attribute. + * + * @param[in|out] handle Attribute handle. + * @param[out] elmt Attribute element to fill + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If attribute found. + * - @ref ATT_ERR_INVALID_HANDLE: If No Attribute found + **************************************************************************************** + */ +uint8_t attmdb_get_next_att(uint16_t * handle, struct attm_elmt*elmt); + +/** + **************************************************************************************** + * Check if attribute element UUID is equals to uuid given in parameter. + * + * @param elmt Attribute element that can be a UUID 16 or 128 bits + * @param uuid16 UUID 16 bits to compare + * + * @return True if UUIDs matches, False else. + **************************************************************************************** + */ +bool attmdb_uuid16_comp(struct attm_elmt *elmt, uint16_t uuid16); + +/** + **************************************************************************************** + * @brief Retrieve attribute value Max Length + * + * @param[in] elmt Attribute element information + * @param[out] length Max length Size of attribute value + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If request succeeds + * - @ref ATT_ERR_REQUEST_NOT_SUPPORTED: If attribute is read only + **************************************************************************************** + */ +uint8_t attmdb_get_max_len(struct attm_elmt* elmt, att_size_t* length); + + +/** + **************************************************************************************** + * @brief Retrieve attribute UUID + * + * @param[in] elmt Attribute information. + * @param[out] uuid_len Size of attribute UUID + * @param[out] uuid UUID value to update + * @param[in] srv_uuid For a service, if set, return service UUID + * @param[in] air Prepare UUID for the air (For a 32 bit UUID, returns a 128 bit UUID) + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If request succeeds + * - @ref ATT_ERR_INVALID_HANDLE: If handle doesn't exist in database + **************************************************************************************** + */ +uint8_t attmdb_get_uuid(struct attm_elmt *elmt, uint8_t* uuid_len, uint8_t* uuid, bool srv_uuid, bool air); + +/** + **************************************************************************************** + * @brief Retrieve attribute permission + * If access mask is set, service authentication or encryption key size value can be loaded. + * + * @param[in] handle Attribute handle. + * @param[out] perm Permission value to return + * @param[in] mode_mask Mode Access mask to check type of access + * parameter (0 return full attribute permission) + * @param[in] perm_mask Permission Access mask to check only specific permission + * @param[in|out] elmt Attribute information + * + * @return Command status code: + * - @ref ATT_ERR_NO_ERROR: If request succeeds + * - @ref ATT_ERR_INVALID_HANDLE: If handle doesn't exist in database. + * - @ref ATT_ERR_REQUEST_NOT_SUPPORTED: If mode is disabled. + * - @ref ATT_ERR_INSUFF_AUTHOR: when service is disabled. + * - @ref ATT_ERR_INSUFF_ENC_KEY_SIZE: + **************************************************************************************** + */ +uint8_t attmdb_att_get_permission(uint16_t handle, uint16_t* perm, uint16_t mode_mask, + uint16_t perm_mask, struct attm_elmt *elmt); + + +#if (RW_DEBUG) + +/** + **************************************************************************************** + * @brief Retrieve number of services. + * + * @return number of services + **************************************************************************************** + */ +uint8_t attmdb_get_nb_svc(void); + +/** + **************************************************************************************** + * @brief Retrieve services informations + * + * @param[in] svc_info Services information array to update + **************************************************************************************** + */ +void attmdb_get_svc_info(struct gattm_svc_info* svc_info); +#endif /* (RW_DEBUG) */ + +#endif // #if (BLE_ATTS) + +/// @} ATTDB +#endif // ATTM_DB_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/atts.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/atts.h new file mode 100644 index 0000000..6330ee5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/atts.h @@ -0,0 +1,159 @@ +/** + **************************************************************************************** + * + * @file atts.h + * + * @brief Header file - ATTS. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef ATTS_H_ +#define ATTS_H_ + +/** + **************************************************************************************** + * @addtogroup ATTS Attribute Server + * @ingroup ATT + * @brief Attribute Protocol Server + * + * The ATTS module is responsible for handling messages intended for the attribute + * profile server. It has defined interfaces with @ref ATTM "ATTM". + * + * + * @{ + * + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_ATTS) +#include "att.h" +#include "compiler.h" +#include +#include "co_list.h" +#include "gattc_task.h" +#include "l2cc.h" + +/* + * DEFINES + **************************************************************************************** + */ + + + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + + +/** + * Confirmation of write signed (signature verified) + * + * @param[in] conidx Connection Index + * @param[in] length Signed Data Length + * @param[in] sign_data Signed Data + */ +void atts_write_signed_cfm(uint8_t conidx, uint16_t length, uint8_t* sign_data); + + +/** + **************************************************************************************** + * @brief Send an attribute error response to peer. + * + * @param[in] conidx Index of the connection with the peer device + * @param[in] opcode failing operation code + * @param[in] uuid attribute UUID + * @param[in] error error code + **************************************************************************************** + */ +void atts_send_error(uint8_t conidx, uint8_t opcode, uint16_t uuid, uint8_t error); + + +/** + **************************************************************************************** + * @brief Format the Write Response PDU and send it after receiving a Write Request PDU + * @param[in] conidx Index of the connection with the peer device + * @param[in] atthdl Attribute handle for which to send the response + * @param[in] status ATT error code + **************************************************************************************** + */ +void atts_write_rsp_send(uint8_t conidx, uint16_t atthdl, uint8_t status); + + +/** + **************************************************************************************** + * @brief Sends a value notification/indication command + * + * @param[in] conidx Connection Index + * @param[in] event Event parameters to send + * + * @return If notification can be sent or not + **************************************************************************************** + */ +uint8_t atts_send_event(uint8_t conidx, struct gattc_send_evt_cmd *event); + + +/** + * @brief Clear allocated prepare write temporary data. + * + * @param[in] conidx connection index + */ +void atts_clear_prep_data(uint8_t conidx); + + +/** + * @brief Clear allocated temporary data used for ATTS response. + * + * @param[in] conidx connection index + */ +void atts_clear_rsp_data(uint8_t conidx); + +/** + * @brief Clear temporary attribute read data present in cache. + * + * @param[in] conidx connection index + */ +void atts_clear_read_cache(uint8_t conidx); + +/** + * @brief Process execution of a received ATTS PDU. + * + * @param conidx connection index + */ +void atts_process_pdu(uint8_t conidx); + +/// @} ATTS +#endif /* (BLE_ATTS) */ + +#if (BLE_CENTRALH || BLE_PERIPHERAL) +/** + **************************************************************************************** + * @brief Handles reception of PDU Packet + * + * @param[in] conidx Index of the connection with the peer device + * @param[in] param Received PDU Packet + * + * @return If message has been proceed or consumed + **************************************************************************************** + */ +int atts_l2cc_pdu_recv_handler(uint8_t conidx, struct l2cc_pdu_recv_ind *param); +#endif /* #if (BLE_CENTRALH || BLE_PERIPHERAL) */ + +uint16_t atts_get_dest_task(uint8_t conidx, uint16_t handle); + +#endif // ATTS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/gatt.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/gatt.h new file mode 100644 index 0000000..34577eb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/gatt.h @@ -0,0 +1,72 @@ +/** + **************************************************************************************** + * + * @file gatt.h + * + * @brief Header file - GATT. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef GATT_H_ +#define GATT_H_ + +/** + **************************************************************************************** + * @addtogroup GATT Generic Attribute Profile + * @ingroup HOST + * @brief Generic Attribute Profile. + * + * The GATT module is responsible for providing an API for all attribute related operations. + * It is responsible for all the service framework activities using the Attribute protocol + * for discovering services and for reading and writing characteristic values on a peer device. + * To achieve this, the GATT interfaces with @ref ATTM "ATTM", @ref ATTC "ATTC" and the + * @ref ATTS "ATTS". + * + * @{ + **************************************************************************************** + */ +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#include "att.h" + + +/* + * DEFINE DECLARATIONS + **************************************************************************************** + */ + +#if (BLE_ATTS) +/// GATT Attribute database handles +/// Generic Attribute Profile Service +enum gatt_db_att +{ + GATT_IDX_PRIM_SVC, + + GATT_IDX_CHAR_SVC_CHANGED, + GATT_IDX_SVC_CHANGED, + GATT_IDX_SVC_CHANGED_CFG, + + GATT_IDX_CHAR_CLI_SUP_FEAT, + GATT_IDX_CLI_SUP_FEAT, + + GATT_IDX_CHAR_DB_HASH, + GATT_IDX_DB_HASH, + + GATT_IDX_NUMBER +}; +#endif /* (BLE_ATTS)*/ + +/* + * Type Definition + **************************************************************************************** + */ + +/// @} GATT +#endif // GATT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/gattc_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/gattc_int.h new file mode 100644 index 0000000..4af0353 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/gattc_int.h @@ -0,0 +1,322 @@ +/** + **************************************************************************************** + * + * @file gattc_int.h + * + * @brief Header file - GATTC_INT. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef GATTC_TASK_INT_H_ +#define GATTC_TASK_INT_H_ + +/** + **************************************************************************************** + * @addtogroup GATTC_INT Internals + * @ingroup GATTC + * @brief Internal features of the GATTC module + * + * @{ + **************************************************************************************** + */ +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_GATTC) +#include "gattc.h" +#include "gattc_task.h" +#include "ke_task.h" + +/* + * DEFINES + **************************************************************************************** + */ +/// retrieve on-going operation command +#define GATT_OPERATION_CMD(conidx, op_type, cmd) \ + ((struct cmd*) gattc_get_operation_ptr(conidx, op_type)) + +#define GATT_WRITE_ERROR_CODE (0xFFFF) + + +/// number of GATT Controller Process +#define GATTC_IDX_MAX BLE_CONNECTION_MAX + + + +/// states of GATT Controller task +enum gattc_state_id +{ + /// Connection ready state + GATTC_READY = 0, + #if (BLE_ATTC) + /// Client operation on-going + GATTC_CLIENT_BUSY = (1 << GATTC_OP_CLIENT), + /// Service Discovery Procedure operation on-going + GATTC_SDP_BUSY = (1 << GATTC_OP_SDP), + #endif // (BLE_ATTC) + #if (BLE_ATTS) + /// Server operation on-going + GATTC_SERVER_BUSY = (1 << GATTC_OP_SERVER), + #endif // (BLE_ATTS) + /// Connection started but ATTS not ready + GATTC_CONNECTED = (1 << (GATTC_OP_MAX + 1)), + + /// Free state + GATTC_FREE = (1 << (GATTC_OP_MAX + 2)), + /// Number of defined states. + GATTC_STATE_MAX +}; + +/// GATT Client information +enum gattc_cli_info +{ + /// Service changed indication enabled by client + GATTC_CLI_SVC_CHANGED_IND_EN_BIT = (1 << 0), + GATTC_CLI_SVC_CHANGED_IND_EN_POS = 0, + /// Robust Cache feature enabled + GATTC_CLI_ROBUST_CACHE_EN_BIT = (1 << 1), + GATTC_CLI_ROBUST_CACHE_EN_POS = 1, + /// Client is change aware (or not, used if robust cache enabled) + GATTC_CLI_CHG_AWARE_BIT = (1 << 2), + GATTC_CLI_CHG_AWARE_POS = 2, + /// If database has changed and peer supports robust cache, first ATT request must trigger a + /// Database out of sync error + GATTC_CLI_ATT_REQ_ALLOWED_BIT = (1 << 3), + GATTC_CLI_ATT_REQ_ALLOWED_POS = 3, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ +extern struct gattc_env_tag* gattc_env[GATTC_IDX_MAX]; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Initialization of the GATT controller module. + * This function performs all the initialization steps of the GATT module. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + * + **************************************************************************************** + */ +void gattc_init(uint8_t init_type); + + +/** + **************************************************************************************** + * @brief Initialize GATT controller for connection. + * + * @param[in] conidx connection record index + * @param[in] role device role after connection establishment + * + **************************************************************************************** + */ +void gattc_create(uint8_t conidx); + + + +/** + **************************************************************************************** + * @brief Cleanup GATT controller resources for connection + * + * @param[in] conidx connection record index + * @param[in] disconnect True if disconnection occurs else request due to init or reset + * + **************************************************************************************** + */ +void gattc_cleanup(uint8_t conidx, bool disconnect); + +/** + * @brief Send a complete event of ongoing executed operation to requester. + * It also clean-up variable used for ongoing operation. + * + * @param[in] conidx Connection index + * @param[in] op_type Operation type. + * @param[in] status Status of completed operation + */ +void gattc_send_complete_evt(uint8_t conidx, uint8_t op_type, uint8_t status); + +/** + **************************************************************************************** + * @brief Send operation completed message with status error code not related to a + * running operation. + * + * @param[in] conidx Connection index + * @param[in] operation Operation code + * @param[in] seq_num Operation sequence number + * @param[in] requester requester of operation + * @param[in] status Error status code + **************************************************************************************** + */ +void gattc_send_error_evt(uint8_t conidx, uint8_t operation, uint16_t seq_num, const ke_task_id_t requester, uint8_t status); + +/** + **************************************************************************************** + * @brief Check if current operation can be processed or not. + * if it can be proceed, initialize an operation request. + * If a command complete event with error code can be triggered. + * + * Function returns how the message should be handled by message handler. + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * @param[in] op_msg Requested operation message (note op_msg cannot be null) + * @param[in] supp_ops Supported operations array. + * Latest array value shall be GATTC_NO_OP. + * + * @return operation can be executed if message status equals KE_MSG_NO_FREE, + * else nothing to do, just exit from the handler. + **************************************************************************************** + */ +int gattc_process_op(uint8_t conidx, uint8_t op_type, void* op_msg, enum gattc_operation* supp_ops); + +/** + **************************************************************************************** + * @brief Get operation on going + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return operation code on going + **************************************************************************************** + */ +uint8_t gattc_get_operation(uint8_t conidx, uint8_t op_type); + +/** + **************************************************************************************** + * @brief Get operation pointer + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return operation pointer on going + **************************************************************************************** + */ +void* gattc_get_operation_ptr(uint8_t conidx, uint8_t op_type); + + +/** + **************************************************************************************** + * @brief Set operation pointer + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * @param[in] op Operation pointer. + * + **************************************************************************************** + */ +void gattc_set_operation_ptr(uint8_t conidx, uint8_t op_type, void* op); + +/** + **************************************************************************************** + * @brief Operation execution not finish, request kernel to reschedule it in order to + * continue its execution + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return if operation has been rescheduled (not done if operation pointer is null) + **************************************************************************************** + */ +bool gattc_reschedule_operation(uint8_t conidx, uint8_t op_type); + +/** + **************************************************************************************** + * @brief Get requester of on going operation + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return task that requests to execute the operation + **************************************************************************************** + */ +ke_task_id_t gattc_get_requester(uint8_t conidx, uint8_t op_type); + + + +/** + **************************************************************************************** + * @brief Get Operation Sequence Number + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return Sequence number provided for operation execution + **************************************************************************************** + */ +uint16_t gattc_get_op_seq_num(uint8_t conidx, uint8_t op_type); + + +/** + **************************************************************************************** + * @brief Update task state + * + * @param[in] conidx Connection index + * @param[in] state to update + * @param[in] set state to busy (true) or idle (false) + * + **************************************************************************************** + */ +void gattc_update_state(uint8_t conidx, ke_state_t state, bool busy); + +#if (BLE_ATTS) +/** + **************************************************************************************** + * @brief Check if we have a database out of sync error + * + * @param[in] conidx Connection index + * @param[in] code Attribute request + * + * @return true if we have a database out of sync error, else false + **************************************************************************************** + */ +bool gattc_is_db_out_of_sync(uint8_t conidx, uint8_t code); + +/** + **************************************************************************************** + * @brief Sends the service change indication to peer client device + * + * @param[in] conidx Connection index + * @param[in] start_handle Database Start handle + * @param[in] end_handle Database End handle + **************************************************************************************** + */ +void gattc_svc_chg_ind_send(uint8_t conidx, uint16_t start_handle, uint16_t end_handle); +#endif // (BLE_ATTS) + +/** + **************************************************************************************** + * @brief Send to application the connection information related to GATT + * + * @param[in] conidx Connection index + **************************************************************************************** + */ +void gattc_con_info_send(uint8_t conidx); + +uint8_t gattc_get_l2c_code(uint8_t conidx); + +#endif // (BLE_GATTC) + +/// @} GATTCTASK +#endif // GATTC_INT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/gattm_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/gattm_int.h new file mode 100644 index 0000000..86b32fa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt/gattm_int.h @@ -0,0 +1,89 @@ +/** + **************************************************************************************** + * + * @file gattm_int.h + * + * @brief Internal Header file - GATTM. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef GATTM_INT_H_ +#define GATTM_INT_H_ + +/** + **************************************************************************************** + * @addtogroup GATTM_INT Task + * @ingroup GATTM + * @brief Internal function required for GATTM usage + * @{ + **************************************************************************************** + */ +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "ke_task.h" +#include "gattm_task.h" + +//#include "../attm/attm_db.h" +#include "attm_db.h" //change 21.05.19 lxm + +/* + * DEFINES + **************************************************************************************** + */ + +/// number of GATT Process +#define GATTM_IDX_MAX 0x01 + + +/// GATT database default features +#define GATT_DB_DEFAULT_FEAT 0x00FF + +/// states of GATT task +enum gattm_state_id +{ + /// idle state + GATTM_IDLE, + /// busy state + GATTM_BUSY, + /// Number of defined states. + GATTM_STATE_MAX +}; + +/// GATT General Information Manager +struct gattm_env_tag +{ + #if (BLE_ATTS) + /// Environment data needed by attribute database + struct attm_db db; + + /// GATT service start handle + uint16_t svc_start_hdl; + #endif // (BLE_ATTS) +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ +extern struct gattm_env_tag gattm_env; + +/* + * FUNCTIONS DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Informs that database has been updated + **************************************************************************************** + */ +void gattm_db_updated(void); + +/// @} GATTM_INT +#endif // GATTM_INT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_int.h new file mode 100644 index 0000000..e4904e1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_int.h @@ -0,0 +1,210 @@ +/** + **************************************************************************************** + * + * @file l2cc_int.h + * + * @brief Header file - L2CCTASK that contains internal API. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef L2CC_INT_H_ +#define L2CC_INT_H_ + +/** + **************************************************************************************** + * @addtogroup L2CCINT Internals + * @ingroup L2CC + * @brief Internal API for L2CC module + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#if (BLE_L2CC) + +#include "l2cc_task.h" +#include "l2cc.h" + +/* + * MACRO DEFINITIONS + **************************************************************************************** + */ + + +/// Maximum number of instances of the L2CC task +#define L2CC_IDX_MAX (BLE_CONNECTION_MAX) + +/* + * STATES + **************************************************************************************** + */ + + + +/// states of L2CAP Controller task +enum l2cc_state_id +{ + /// Connection ready state + L2CC_READY, + /// LE signaling protocol busy + L2CC_SIG_BUSY = (1 << L2CC_OP_SIG), + /// Free state + L2CC_FREE = 0X3F, + + /// Number of defined states. + L2CC_STATE_MAX +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/// L2CAP environment pool +extern struct l2cc_env_tag *l2cc_env[L2CC_IDX_MAX]; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Create and Initialize the L2CAP controller task. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + * + **************************************************************************************** + */ +void l2cc_init(uint8_t init_type); + +/** +struct l2cc_pdu_recv_ind; + * + **************************************************************************************** + * @brief Initialize the link layer controller task. + * + * @param[in] conidx Connection index + * + **************************************************************************************** + */ +void l2cc_create(uint8_t conidx); + +/** + **************************************************************************************** + * @brief De-initialize the task. + * + * @param[in] conidx Connection index + * @param[in] reset true if it's requested by a reset; false if it's boot initialization + **************************************************************************************** + */ +void l2cc_cleanup(uint8_t conidx, bool reset); + +/** + **************************************************************************************** + * @brief Update task state + * + * @param[in] conidx Connection index + * @param[in] state to update + * @param[in] set state to busy (true) or idle (false) + * + **************************************************************************************** + */ +void l2cc_update_state(uint8_t conidx, ke_state_t state, bool busy); + + +/** + * @brief Complete the operation by cleanning-up variable used and end a complete event to operation requester. + * + * @param[in] conidx Connection index + * @param[in] op_type Operation type. + * @param[in] status Status of completed operation + */ +void l2cc_op_complete(uint8_t conidx, uint8_t op_type, uint8_t status); + +/** + **************************************************************************************** + * @brief Send operation completed message with status error code not related to a + * running operation. + * + * @param[in] conidx Connection index + * @param[in] operation Operation code + * @param[in] requester requester of operation + * @param[in] status Error status code + * @param[in] cid Channel Identifier + * @param[in] credit number of used credit (0 on signaling channel) + **************************************************************************************** + */ +void l2cc_send_cmp_evt(uint8_t conidx, uint8_t operation, const ke_task_id_t requester, uint8_t status, uint16_t cid, + uint16_t credit); + + +/** + **************************************************************************************** + * @brief Get operation on going + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return operation code on going + **************************************************************************************** + */ +uint8_t l2cc_get_operation(uint8_t conidx, uint8_t op_type); + +/** + **************************************************************************************** + * @brief Get operation pointer + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * + * @return operation pointer on going + **************************************************************************************** + */ +void* l2cc_get_operation_ptr(uint8_t conidx, uint8_t op_type); + + +/** + **************************************************************************************** + * @brief Set operation pointer + * + * @param[in] conidx Connection Index + * @param[in] op_type Operation type. + * @param[in] op Operation pointer. + * + **************************************************************************************** + */ +void l2cc_set_operation_ptr(uint8_t conidx, uint8_t op_type, void* op); + + + + +/** + **************************************************************************************** + * @brief Perform data packet TX over HCI (call of this function is handled by L2CM + * + * @param[in] conidx Connection Index + * @param[in] nb_buffer Number of available TX buffers + **************************************************************************************** + */ +void l2cc_data_send(uint8_t conidx, uint8_t nb_buffer); + + + + + + +#endif //(BLE_L2CC) + +/// @} L2CCINT + +#endif // L2CC_INT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_lecb.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_lecb.h new file mode 100644 index 0000000..70fe6c0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_lecb.h @@ -0,0 +1,262 @@ +/** + **************************************************************************************** + * + * @file l2cc_pdu.h + * + * @brief Header file - L2CAP LE Credit Based connection management + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + + +#ifndef _L2CC_LECB_H_ +#define _L2CC_LECB_H_ + +/** + **************************************************************************************** + * @addtogroup L2CC_LECB L2Cap Controller LE Credit Based connection management + * @ingroup L2CC + * @brief This module is in charge of LECB connection management + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_LECB) + +/* + * DEFINES + **************************************************************************************** + */ +/// LE Credit Based fields. +enum l2cc_lecb_fields +{ + /// LE Protocol Service Multiplexer + L2CC_LECB_LEPSM, + /// Local channel ID + L2CC_LECB_LOCAL_CID, + /// Peer channel ID + L2CC_LECB_PEER_CID, +}; + + +/// Status of the LE Credit Based connection +/// +/// 7 6 5 4 3 2 1 0 +/// +----+----+----+----+----+----+----+----+ +/// | RFU |P_I |TX_W|CON | +/// +----+----+----+----+----+----+----+----+ +/// +/// bit [2] : Local(0)/Peer (1) initiated connection +/// bit [1] : TX in Wait state (segment transmission not finished) +/// bit [0] : LECB Connected +enum l2cc_lecb_state +{ + /// Peer initiated connection + L2CC_LECB_PEER_INIT_BIT = (1<<2), + L2CC_LECB_PEER_INIT_POS = (2), + + /// TX in Wait state (segment transmission not finished) + L2CC_LECB_TX_WAIT_BIT = (1<<1), + L2CC_LECB_TX_WAIT_POS = (1), + + /// Channel Connected + L2CC_LECB_CONNECTED_BIT = (1<<0), + L2CC_LECB_CONNECTED_POS = (0), +}; + + + + + +/* + * MACRO DEFINITIONS + **************************************************************************************** + */ + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + + +/// LE credit based information for a link started or on-going. +struct l2cc_lecb_info +{ + /// Pointer to the following list + struct co_list_hdr hdr; + /// SDU waiting to be transfered (required for segmentation algorithm) + struct l2cc_lecb_sdu_send_cmd* tx_sdu; + /// SDU waiting to be received (required for reassembly algorithm) + struct l2cc_lecb_sdu_recv_ind* rx_sdu; + + /// LE Protocol/Service Multiplexer + uint16_t le_psm; + + /// Local channel ID + uint16_t local_cid; + /// Local Maximum Transmission Unit + uint16_t local_mtu; + /// Local Maximum Packet Size + uint16_t local_mps; + /// Local credit + uint16_t local_credit; + + /// Peer channel ID + uint16_t peer_cid; + /// Peer Maximum Transmission Unit + uint16_t peer_mtu; + /// Peer Maximum Packet Size + uint16_t peer_mps; + /// Peer credit + uint16_t peer_credit; + + /// Task id requested connection + ke_task_id_t task_id; + + /// Status of the LE Credit Based connection (@see enum l2cc_lecb_state) + uint8_t state; + + /// disconnection reason + uint8_t disc_reason; + + /// Packet identifier - used for LECB negotiation + uint8_t pkt_id; +}; + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Search LE Credit Based channel depending on the parameter + * + * @param[in] conidx Connection Index + * @param[in] field Search field (@see enum l2cc_lecb_fields) + * @param[in] value Field value to search + * + * @return Returns NULL or pointer to the LE Credit Based channel info + **************************************************************************************** + */ +struct l2cc_lecb_info* l2cc_lecb_find(uint8_t conidx, uint8_t field, uint16_t value); + +/** + **************************************************************************************** + * @brief End of LECB Connection, free information, and send disconnect indication + * + * @param[in] conidx Connection Index + * @param[in] lecb LE Credit Based Connection information + * @param[in] disconnect_ind True, sends disconnect indication + **************************************************************************************** + */ +void l2cc_lecb_free(uint8_t conidx, struct l2cc_lecb_info* lecb, bool disconnect_ind); + + +/** + **************************************************************************************** + * @brief Sends LE credit based connection request + * + * @param[in] conidx connection index + * @param[in] pkt_id Packet identifier + * @param[in] scid Source channel ID + * @param[in] credits Credits + * @param[in] mps Maximum Packet Size + * @param[in] mtu Maximum Transfer Unit + **************************************************************************************** + */ +void l2cc_lecb_send_con_req(uint8_t conidx, uint8_t pkt_id, uint16_t le_psm, uint16_t scid, uint16_t credits, + uint16_t mps, uint16_t mtu); + +/** + **************************************************************************************** + * @brief Sends LE credit based connection response + * + * @param[in] conidx connection index + * @param[in] status status of the connection + * @param[in] pkt_id Packet identifier + * @param[in] dcid Destination channel ID + * @param[in] credits Credits + * @param[in] mps Maximum Packet Size + * @param[in] mtu Maximum Transfer Unit + **************************************************************************************** + */ +void l2cc_lecb_send_con_rsp(uint8_t conidx, uint16_t status, uint8_t pkt_id, + uint16_t dcid, uint16_t credits, uint16_t mps, uint16_t mtu); + +/** + **************************************************************************************** + * @brief Sends LE credit based disconnection request + * + * @param[in] conidx connection index + * @param[in] pkt_id Packet identifier + * @param[in] dcid Destination channel ID + * @param[in] scid Source channel ID + **************************************************************************************** + */ +void l2cc_lecb_send_disc_req(uint8_t conidx, uint8_t pkt_id, uint16_t scid, uint16_t dcid); + +/** + **************************************************************************************** + * @brief Sends LE credit based disconnection response + * + * @param[in] conidx connection index + * @param[in] pkt_id Packet identifier + * @param[in] dcid Destination channel ID + * @param[in] scid Source channel ID + **************************************************************************************** + */ +void l2cc_lecb_send_disc_rsp(uint8_t conidx, uint8_t pkt_id, uint16_t dcid, uint16_t scid); +/** + **************************************************************************************** + * @brief Sends LE credit based Flow Control credit add message + * + * @param[in] conidx connection index + * @param[in] pkt_id Packet identifier + * @param[in] cid Source Channel ID + * @param[in] credits Credits + **************************************************************************************** + */ +void l2cc_lecb_send_credit_add(uint8_t conidx, uint8_t pkt_id, uint16_t cid, uint16_t credits); + + +/** + **************************************************************************************** + * @brief Due to an error on LECB link, initiate a disconnection of the channel + * + * @param[in] conidx connection index + * @param[in] lecb Information of the channel + * @param[in] disc_reason Disconnection reason + * + **************************************************************************************** + */ +void l2cc_lecb_init_disconnect(uint8_t conidx, struct l2cc_lecb_info* lecb, uint8_t disc_reason); + +/** + **************************************************************************************** + * @brief Retrieve LECB error Code from Host error code + * + * @param[in] h_err Host Error code + * + * @return LECB Error code + **************************************************************************************** + */ +uint16_t l2cc_lecb_h2l_err(uint8_t h_err); + +#endif //(BLE_LECB) + +/// @} L2CC_LECB + +#endif /* _L2CC_LECB_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_pdu_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_pdu_int.h new file mode 100644 index 0000000..d509ef2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_pdu_int.h @@ -0,0 +1,193 @@ +/** + **************************************************************************************** + * + * @file l2cc_pdu_int.h + * + * @brief Header file - L2CAP Controller PDU packer / unpacker (internal) + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + + +#ifndef _L2CC_PDU_INT_H_ +#define _L2CC_PDU_INT_H_ + +/** + **************************************************************************************** + * @addtogroup L2CC_PDU_INT L2Cap Controller (internal) + * @ingroup L2CC + * @brief This module is in charge to pack or unpack L2CAP packets + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_L2CC) + +#include "l2cc_pdu.h" + +/* + * MACROS + **************************************************************************************** + */ + + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * Pack PDU from firmware readable data to a L2CAP packet using generic method. + * (no segmentation) + * + * @param[in] p_pdu Pointer to the unpacked PDU structure + * @param[in|out] p_offset Pointer to address where the next part of PDU will be read + * @param[in|out] p_length Pointer to the length of payload that has been packed + * @param[in|out] p_buffer Pointer to address where the next part of PDU will be written + * @param[in|out] pb_flag Packet Boundary flags + * + * @return GAP_ERR_NO_ERROR if packing succeed, else another error code. + **************************************************************************************** + */ +uint8_t l2cc_pdu_pack(struct l2cc_pdu *p_pdu, uint16_t *p_offset, uint16_t *p_length, uint8_t *p_buffer, uint8_t *pb_flag); + +/** + **************************************************************************************** + * Unpack L2Cap PDU in a generic format that can be used by firmware using generic method. + * (no reassembly) + * + * @param[in] conidx Connection Index + * @param[in] p_pdu Pointer to the unpacked PDU structure + * @param[in|out] p_offset Pointer to address where the next part of PDU will be written + * @param[in|out] p_rem_len Pointer to the remaining length value of PDU to receive + * @param[in|out] p_buffer Pointer to address where the next part of PDU will be read + * @param[in] pkt_length Length of the received packet + * @param[in] pb_flag Packet Boundary flags + * + * @return GAP_ERR_NO_ERROR if packing succeed, else another error code. + **************************************************************************************** + */ +uint8_t l2cc_pdu_unpack(uint8_t conidx, struct l2cc_pdu *p_pdu, uint16_t *p_offset, uint16_t *p_rem_len, + const uint8_t *p_buffer, uint16_t pkt_length, uint8_t pb_flag); + +#if (RW_DEBUG) +/** + **************************************************************************************** + * Pack DBG PDU (any kind of PDU generated by Host) from firmware readable data to a L2CAP + * packet (no segmentation) + * + * @param[in] conidx Connection Index + * @param[in] pdu Pointer to the Debug PDU to send + * @param[in|out] p_length Pointer to the length of payload that has been packed + * @param[in|out] buffer Pointer to address where the next part of PDU will be written + * @param[in|out] offset Pointer to address where the next part of PDU will be read + * @param[in|out] pb_flag Packet Boundary flags + * + * @return GAP_ERR_NO_ERROR if packing succeed, else another error code. + **************************************************************************************** + */ +uint8_t l2cc_dbg_pdu_pack(struct l2cc_dbg_pdu *pdu, uint16_t *length, uint8_t *buffer, uint16_t* offset,uint8_t *pb_flag); + + +/** + **************************************************************************************** + * Unpack L2Cap PDU in a generic format that can be used by firmware for debugging + * (no reassembly) + * + * @param[in|out] sdu Pointer to the unpacked SDU structure + * @param[in] buffer Pointer to address where the next part of PDU will be read + * @param[in] length Length of the received packet + * @param[in|out] offset Pointer to address where the next part of PDU will be written + * @param[in] pb_flag Packet Boundary flags + * + * @return GAP_ERR_NO_ERROR if packing succeed, else another error code. + **************************************************************************************** + */ +uint8_t l2cc_dbg_pdu_unpack(struct l2cc_dbg_pdu *pdu, uint8_t *buffer, uint16_t length, uint16_t* offset, uint8_t pb_flag); +#endif // (RW_DEBUG) + +#if (BLE_LECB) +/** + **************************************************************************************** + * Pack LE Credit Based channel PDU from firmware readable data to a L2CAP packet + * + * @param[in] conidx Connection Index + * @param[in] pdu Pointer to the SDU to send + * @param[out] length Pointer to the length of payload that has been packed + * @param[in|out] buffer Pointer to address where the next part of PDU will be written + * @param[in|out] offset Pointer to address where the next part of PDU will be read + * @param[in|out] pdu_len PDU length to transmitt + * @param[in] pb_flag Packet Boundary flags + * + * @return GAP_ERR_NO_ERROR if packing succeed, else another error code. + **************************************************************************************** + */ +uint8_t l2cc_lecb_pdu_pack(uint8_t conidx, struct l2cc_sdu *sdu, uint16_t *length, uint8_t *buffer, uint16_t* offset, + uint16_t pdu_len, uint8_t pb_flag); + + +/** + **************************************************************************************** + * Unpack L2Cap LECB SDU in a generic format that can be used by firmware + * + * @param[in|out] sdu Pointer to the unpacked SDU structure + * @param[in] buffer Pointer to address where the next part of PDU will be read + * @param[in] length Length of the received packet + * @param[in|out] offset Pointer to address where the next part of PDU will be written + * @param[in|out] pdu_remain_len Pointer to the data length still expected on segment + * @param[in] pb_flag Packet Boundary flags + * + * @return GAP_ERR_NO_ERROR if packing succeed, else another error code. + **************************************************************************************** + */ +uint8_t l2cc_lecb_pdu_unpack(uint8_t conidx, struct l2cc_sdu *sdu, uint8_t *buffer, uint16_t length, uint16_t* offset, + uint16_t* pdu_remain_len, uint8_t pb_flag); + +#endif //(BLE_LECB) + +/** + **************************************************************************************** + * @brief New message received, initialize reception of the buffer + * - if a PDU not fully received, drop it. + * + * @param[in] conidx Connection Index + **************************************************************************************** + */ +void l2cc_pdu_rx_init(uint8_t conidx); + +/** + **************************************************************************************** + * @brief Check the PDU packet header channel ID, Length, in order to: + * - verify if no error detected + * - allocate or retrieve the RX message for expected destination task + * + * @param[in] conidx Connection Index + * @param[in|out] pp_buffer Buffer received, pointer updated according to header length + * @param[in|out] p_rx_length Received length, updated according to extracted header length + **************************************************************************************** + */ +void l2cc_pdu_header_check(uint8_t conidx, uint8_t** pp_buffer, uint16_t* p_rx_length); + + +/// @} L2CC_PDU_INT + +#endif //(BLE_L2CC) + +#endif /* _L2CC_PDU_INT_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_sig.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_sig.h new file mode 100644 index 0000000..e16bfeb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cc_sig.h @@ -0,0 +1,96 @@ +/** + **************************************************************************************** + * + * @file l2cc_sig.h + * + * @brief L2CAP Controller Controller Signaling PDU Handler. + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + +#ifndef _L2CC_SIG_H_ +#define _L2CC_SIG_H_ + + +/** + **************************************************************************************** + * @addtogroup L2CC_SIG L2CAP Controller Signaling PDU Handler. + * @ingroup L2CC + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_L2CC) + +#include "l2cc.h" +#include "l2cc_task.h" + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * MACRO DEFINITIONS + **************************************************************************************** + */ + + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Send an L2Cap command rejected signaling packet with command not understood + * error code. + * + * @param[in] conidx Connection Index + * @param[in] pkt_id Packet identifier + * + * @param[in] reason The Reason field describes why the Request packet was rejected + * @param[in] opt1 Optional param 1 + * @param[in] opt2 Optional param 2 + **************************************************************************************** + */ +void l2cc_sig_send_cmd_reject(uint8_t conidx, uint8_t pkt_id, uint16_t reason, uint16_t opt1, uint16_t opt2); + + +/** + **************************************************************************************** + * @brief Handles reception of L2CAP signaling messages from peer device. + * + * @param[in] conidx Connection Index + * @param[in] pdu PDU Received + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int l2cc_sig_pdu_recv_handler(uint8_t conidx, struct l2cc_pdu *pdu); + + + + +#endif // (BLE_L2CC) + +#endif // _L2CC_SIG_H_ + +/// @} L2CC_SIG diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cm_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cm_int.h new file mode 100644 index 0000000..dd38887 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c/l2cm_int.h @@ -0,0 +1,128 @@ +/** + **************************************************************************************** + * + * @file l2cm_int.h + * + * @brief Header file - L2CM internal. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ + +#ifndef L2CM_INT_H_ +#define L2CM_INT_H_ + +/** + **************************************************************************************** + * @addtogroup L2C_INT Logical Link Control and Adaptation Protocol internals + * @ingroup HOST + * @brief Logical Link Control and Adaptation Protocol - Internal API. + * + * @{ + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (BLE_L2CM) +#include +#include +#include "compiler.h" +#include "l2cm.h" + +/* + * INCLUDE FILES + **************************************************************************************** + */ + + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/// L2CAP Manager environment structure to be saved +struct l2cm_env_tag +{ + #if (BLE_L2CC) + /// bit field used to know per connection if TX activity is on-going + uint32_t con_tx_state; + #endif // (BLE_L2CC) + /// Lower Layer buffers length + uint16_t le_acl_data_pkt_len; + /// Total number of available Lower Layer buffers + uint16_t le_acl_total_nb_acl_pkt; + /// Number of available Lower Layer buffers + uint16_t nb_buffer_avail; + }; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ +extern struct l2cm_env_tag l2cm_env; +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Acquire low layer LE ACL packet + **************************************************************************************** + */ +__INLINE void l2cm_buffer_acquire(void) +{ + l2cm_env.nb_buffer_avail--; +} + +/** + **************************************************************************************** + * @brief Release low layer LE ACL packet + * + * @parm[in] nb Number of buffer to release. + **************************************************************************************** + */ +__INLINE void l2cm_buffer_release(uint16_t nb) +{ + l2cm_env.nb_buffer_avail += nb; +} + + +/** + **************************************************************************************** + * @brief Retrieve low layer LE ACL Buffers size + * + * @return size of LE ACL Buffers + **************************************************************************************** + */ + __INLINE uint16_t l2cm_get_buffer_size(void) + { + return l2cm_env.le_acl_data_pkt_len; + } + + +/** + **************************************************************************************** + * @brief Set if TX queue for specific connection is empty or not. + * + * If not empty, it will request L2CM to start transmission of buffers + * + * @param[in] conidx Connection index + * @param[in] busy False if TX buffer queue is empty, True else + * + **************************************************************************************** + */ +void l2cm_tx_status(uint8_t conidx, bool busy); + +/// @} L2CM_INT + +#endif //(BLE_L2CM) + +#endif // L2CM_INT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/api/em_map_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/api/em_map_ble.h new file mode 100644 index 0000000..c6301c0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/api/em_map_ble.h @@ -0,0 +1,384 @@ +/** + **************************************************************************************** + * + * @file em_map_ble.h + * + * @brief Mapping of BLE section in exchange memory + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + +#ifndef EM_MAP_BLE_H_ +#define EM_MAP_BLE_H_ + +/** + **************************************************************************************** + * @addtogroup EM Exchange Memory + * @ingroup CONTROLLER + * @brief Mapping of BLE section in exchange memory + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#include // integer +#include "co_llcp.h" +#include "co_math.h" // For use of CO_ALIGN4_HI +#include "_reg_em_ble_cs.h" // EM Control Structure +#include "_reg_em_ble_tx_desc.h" // BLE EM TX descriptors +#include "_reg_em_ble_rx_desc.h" // BLE EM RX descriptors +#include "_reg_em_ble_rx_cte_desc.h" // BLE EM RX CTE descriptors +#include "_reg_em_ble_wpal.h" // BLE EM White and periodic list +#include "_reg_em_ble_ral.h" // BLE EM resolving list + +#if (BLE_ISO_PRESENT) +#include "_reg_em_ble_tx_iso_desc.h" // BLE EM TX ISO descriptors +#include "_reg_em_ble_rx_iso_desc.h" // BLE EM RX ISO descriptors +#include "_reg_em_ble_tx_iso_buf.h" // BLE EM TX Buffer description +#include "_reg_em_ble_rx_iso_buf.h" // BLE EM RX Buffer description +#endif // (BLE_ISO_PRESENT) + +/* + * CONTROL STRUCTURES + **************************************************************************************** + */ + +/** + * Control Structures area definition + * + * - LINK (N) + * - SCAN/INIT + */ +#define EM_BLE_CS_OFFSET (EM_BLE_OFFSET) +#define EM_BLE_CS_NB (BLE_ACTIVITY_MAX + (BLE_OBSERVER*3) + BLE_CENTRAL) +#define EM_BLE_CS_END (EM_BLE_CS_OFFSET + EM_BLE_CS_NB * REG_EM_BLE_CS_SIZE) + + +#if ((REG_EM_BLE_CS_SIZE % 4) != 0) +#error "CS Pointers must be 32 bits aligned" +#endif // ((REG_EM_BLE_CS_SIZE % 4) != 0) + +/** + * Control Structures indexes definition + */ +#define EM_BLE_CS_ACT_ID_TO_INDEX(act_id) (act_id) +#define EM_BLE_CS_IDX_TO_ACT_ID(cs_idx) (cs_idx) + +#if (BLE_OBSERVER) +#define EM_BLE_CS_EXT_SCAN_IDX2 (EM_BLE_CS_NB - 1) +#define EM_BLE_CS_AUX_SCAN_IDX1 (EM_BLE_CS_NB - 2) +#define EM_BLE_CS_AUX_SCAN_IDX2 (EM_BLE_CS_NB - 3) +#endif // (BLE_OBSERVER) +#if (BLE_CENTRAL) +#define EM_BLE_CS_EXT_INIT_IDX2 (EM_BLE_CS_NB - 4) +#endif // (BLE_CENTRAL) + +#define EM_BLE_CS_INDEX_MAX (EM_BLE_CS_NB) + +/** + * Frame Format + * Bluetooth state and device activity used for frequency selection and TDD frame format. See section 3.5 for further details + * Note this field is automatically updated by the RW-BT Core when changing from Page to Master Page Response mode. + * + * - 0000x: Do not use + * - 00010: Master Connect + * - 00011: Slave Connect + * - 00100: Low Duty Cycle Advertiser + * - 00101: High Duty Cycle Advertiser + * - 00110: Extended Advertiser + * - 00111: Do not use + * - 01000: Passive Scanner + * - 01001: Active Scanner + * - 01010: Extended Passive Scanner + * - 01011: Extended Active Scanner + * - 0110x: Do not use + * - 01110: Initiator + * - 01111: Extended Initiator + * - 10xxx: Do not use + * - 110xx: Do not use + * - 11100: Tx Test Mode + * - 11101: Rx Test Mode + * - 11110: Tx / Rx Test Mode + * - 11111: Do not use + */ +enum em_ble_cd_fmt +{ + EM_BLE_CS_FMT_MST_CONNECT = (0x02), + EM_BLE_CS_FMT_SLV_CONNECT = (0x03), + EM_BLE_CS_FMT_LDC_ADV = (0x04), + EM_BLE_CS_FMT_HDC_ADV = (0x05), + EM_BLE_CS_FMT_EXT_ADV = (0x06), + EM_BLE_CS_FMT_PASSIVE_SCAN = (0x08), + EM_BLE_CS_FMT_ACTIVE_SCAN = (0x09), + EM_BLE_CS_FMT_EXT_PASSIVE_SCAN = (0x0A), + EM_BLE_CS_FMT_EXT_ACTIVE_SCAN = (0x0B), + EM_BLE_CS_FMT_CHAN_SCAN = (0x0C), + EM_BLE_CS_FMT_INITIATOR = (0x0E), + EM_BLE_CS_FMT_EXT_INITIATOR = (0x0F), + EM_BLE_CS_FMT_TX_TEST = (0x1C), + EM_BLE_CS_FMT_RX_TEST = (0x1D), + EM_BLE_CS_FMT_TXRX_TEXT = (0x1E), +}; + +/// Maximum value of RXWINSZ field (16383) +#define EM_BLE_CS_RXWINSZ_MAX ((1 << 14)-1) + +/// Maximum value of MAXFRMTIME field (65535) +#define EM_BLE_CS_MAXEVTIME_MAX ((1 << 16)-1) + + /// MIC Mode +enum ENC_MIC +{ + /// AES-CCM with MIC + ENC_MIC_PRESENT = 0, + /// AES-CCM MIC-less + ENC_MIC_LESS = 1, +}; + +/// Encryption Mode +enum ENC_MODE +{ + /// AES-CCM nonce use Packet/Payload counter + ENC_MODE_PKT_PLD_CNT = 0, + /// AES-CCM nonce use Event counter + ENC_MODE_EVT_CNT = 1, +}; + + +/* + * WHITE LIST + **************************************************************************************** + */ + +/// White list area definition +#define EM_BLE_WPAL_OFFSET CO_ALIGN4_HI(EM_BLE_CS_END) +#define EM_BLE_WPAL_SIZE (BLE_WHITELIST_MAX * REG_EM_BLE_WPAL_SIZE) +#define EM_BLE_WPAL_END (EM_BLE_WPAL_OFFSET + EM_BLE_WPAL_SIZE) + +#if ((REG_EM_BLE_WPAL_SIZE % 4) != 0) +#error "WPAL Pointers must be 32 bits aligned" +#endif // ((REG_EM_BLE_WPAL_SIZE % 4) != 0) +/* + * RESOLVING LIST + **************************************************************************************** + */ + +/// Resolving list area definition +#define EM_BLE_RAL_OFFSET CO_ALIGN4_HI(EM_BLE_WPAL_END) +#define EM_BLE_RAL_SIZE (BLE_RESOL_ADDR_LIST_MAX * REG_EM_BLE_RAL_SIZE) +#define EM_BLE_RAL_END (EM_BLE_RAL_OFFSET + EM_BLE_RAL_SIZE) + +#if ((REG_EM_BLE_RAL_SIZE % 4) != 0) +#error "RAL Pointers must be 32 bits aligned" +#endif // ((REG_EM_BLE_RAL_SIZE % 4) != 0) +/* + * RX DESCRIPTORS + **************************************************************************************** + */ + +/// RX Descriptors area definition +#define EM_BLE_RX_DESC_OFFSET CO_ALIGN4_HI(EM_BLE_RAL_END) +#define EM_BLE_RX_DESC_NB (BLE_RX_DESC_NB) +#define EM_BLE_RX_DESC_END (EM_BLE_RX_DESC_OFFSET + EM_BLE_RX_DESC_NB * REG_EM_BLE_RX_DESC_SIZE) + +#if ((REG_EM_BLE_RX_DESC_SIZE % 4) != 0) +#error "TX Descriptors must be 32 bits aligned" +#endif // ((REG_EM_BLE_TX_DESC_SIZE % 4) != 0) +/* + * TX DESCRIPTORS + **************************************************************************************** + */ + +/** + * TX Descriptors area definition + * + * - N per connection + * - 1 per advertising data buffer + */ +#define EM_BLE_TX_DESC_OFFSET CO_ALIGN4_HI(EM_BLE_RX_DESC_END) +#define EM_BLE_TX_DESC_NB (BLE_TX_DESC_NB) +#define EM_BLE_TX_DESC_END (EM_BLE_TX_DESC_OFFSET + EM_BLE_TX_DESC_NB * REG_EM_BLE_TX_DESC_SIZE) + +#define EM_BLE_TXDESC_INDEX(act_id, idx) (BLE_NB_TX_DESC_PER_ACT * act_id + idx) + +#if ((REG_EM_BLE_TX_DESC_SIZE % 4) != 0) +#error "TX Descriptors must be 32 bits aligned" +#endif // ((REG_EM_BLE_TX_DESC_SIZE % 4) != 0) +/* + * LLCP TX BUFFERS + **************************************************************************************** + */ + +/// LLCP TX buffers area definition +#define EM_BLE_LLCPTXBUF_OFFSET CO_ALIGN4_HI(EM_BLE_TX_DESC_END) +#define EM_BLE_LLCPTXBUF_NB (2*BLE_ACTIVITY_MAX) +#define EM_BLE_LLCPTXBUF_SIZE (LL_PDU_LENGTH_MAX) +#define EM_BLE_LLCPTXBUF_END (EM_BLE_LLCPTXBUF_OFFSET + EM_BLE_LLCPTXBUF_NB * EM_BLE_LLCPTXBUF_SIZE) + + +/* + * ADV EXTENDED HEADERS TX BUFFER + **************************************************************************************** + */ + +/// Advertising TX buffer area definition +#define EM_BLE_ADVEXTHDRTXBUF_OFFSET CO_ALIGN4_HI(EM_BLE_LLCPTXBUF_END) +#define EM_BLE_ADVEXTHDRTXBUF_NB (BLE_ACTIVITY_MAX) +#define EM_BLE_ADVEXTHDRTXBUF_SIZE (39 + 6*(BLE_ADV_FRAG_NB_TX - 1)) +#define EM_BLE_ADVEXTHDRTXBUF_END (EM_BLE_ADVEXTHDRTXBUF_OFFSET + EM_BLE_ADVEXTHDRTXBUF_NB * EM_BLE_ADVEXTHDRTXBUF_SIZE) + +#define EM_BLE_ADVEXTHDRTXBUF_OFF(act_id) (EM_BLE_ADVEXTHDRTXBUF_OFFSET + act_id * EM_BLE_ADVEXTHDRTXBUF_SIZE) + +/* + * ADVERTISING DATA TX BUFFERS + **************************************************************************************** + */ + + /// Advertising data TX buffers area definition + #define EM_BLE_ADVDATATXBUF_OFFSET CO_ALIGN4_HI(EM_BLE_ADVEXTHDRTXBUF_END) + #define EM_BLE_ADVDATATXBUF_NB (BLE_ADV_BUF_NB_TX) + #define EM_BLE_ADVDATATXBUF_SIZE (BLE_ADV_FRAG_NB_TX*BLE_ADV_FRAG_SIZE_TX) + #define EM_BLE_ADVDATATXBUF_END (EM_BLE_ADVDATATXBUF_OFFSET + EM_BLE_ADVDATATXBUF_NB * EM_BLE_ADVDATATXBUF_SIZE) + + +/* + * AUX_CONNECT_REQ TX BUFFER + **************************************************************************************** + */ + +/// Aux Connect Req TX buffer area definition +#define EM_BLE_AUXCONNECTREQTXBUF_OFFSET CO_ALIGN4_HI(EM_BLE_ADVDATATXBUF_END) +#define EM_BLE_AUXCONNECTREQTXBUF_NB (1) +#define EM_BLE_AUXCONNECTREQTXBUF_SIZE (0x66) // 3 * PDU_CON_REQ_LEN +#define EM_BLE_AUXCONNECTREQTXBUF_END (EM_BLE_AUXCONNECTREQTXBUF_OFFSET + EM_BLE_AUXCONNECTREQTXBUF_NB * EM_BLE_AUXCONNECTREQTXBUF_SIZE) + + +/* + * ACL RX BUFFERS + **************************************************************************************** + */ + +/// Data RX buffers area definition +#define EM_BLE_DATARXBUF_OFFSET CO_ALIGN4_HI(EM_BLE_AUXCONNECTREQTXBUF_END) +#define EM_BLE_DATARXBUF_NB (BLE_DATA_BUF_NB_RX) +#define EM_BLE_DATARXBUF_SIZE (256) +#define EM_BLE_DATARXBUF_END (EM_BLE_DATARXBUF_OFFSET + EM_BLE_DATARXBUF_NB * EM_BLE_DATARXBUF_SIZE) + +/* + * ACL TX BUFFERS + **************************************************************************************** + */ + +/// ACL TX buffers area definition +#define EM_BLE_ACLTXBUF_OFFSET CO_ALIGN4_HI(EM_BLE_DATARXBUF_END) +#define EM_BLE_ACLTXBUF_NB (BLE_ACL_BUF_NB_TX) +#define EM_BLE_ACLTXBUF_SIZE (256) +#define EM_BLE_ACLTXBUF_END (EM_BLE_ACLTXBUF_OFFSET + EM_BLE_ACLTXBUF_NB * EM_BLE_ACLTXBUF_SIZE) + + +#if (BLE_ISO_PRESENT) + +/* + * ISO TX/RX Descriptors + **************************************************************************************** + */ +/** + * ISO Descriptors area definition + * Pool to be used for TX and RX ISO descriptors. It is assumed that both kind of descriptors + * have exactly the same length. + * For each ICO channel or ISO Mode 0 connection, 2 RX ISO descriptors and 2 TX ISO descriptors will be taken from this pool + * For each ICL channel, either 4 RX ISO descriptors or 4 TX ISO descriptors will be taken from this pool. + */ +#define EM_BLE_ISO_DESC_OFFSET CO_ALIGN4_HI(EM_BLE_ACLTXBUF_END) +#define EM_BLE_ISO_DESC_NB (BLE_ISO_DESC_NB) +#define EM_BLE_ISO_DESC_SIZE (REG_EM_BLE_TX_ISO_DESC_SIZE) +#define EM_BLE_ISO_DESC_END (EM_BLE_ISO_DESC_OFFSET + EM_BLE_ISO_DESC_NB * EM_BLE_ISO_DESC_SIZE) + +/// !!!! REMINDER: TX and RX ISO descriptors have the same size !!!! Can use REG_EM_BLE_TX_ISO_DESC_SIZE and REG_EM_BLE_RX_ISO_DESC_SIZE +#define EM_BLE_TX_ISO_DESC_OFFSET (EM_BLE_ISO_DESC_OFFSET) +#define EM_BLE_RX_ISO_DESC_OFFSET (EM_BLE_ISO_DESC_OFFSET) +#if (REG_EM_BLE_TX_ISO_DESC_SIZE != REG_EM_BLE_RX_ISO_DESC_SIZE) +#error "TX and RX ISO descriptors shall have the same size" +#endif // (REG_EM_BLE_TX_ISO_DESC_SIZE != REG_EM_BLE_RX_ISO_DESC_SIZE) +#if ((REG_EM_BLE_TX_ISO_DESC_SIZE % 4) != 0) +#error "TX/RX ISO Descriptor must be 32 bits aligned" +#endif // ((REG_EM_BLE_TX_ISO_DESC_SIZE % 4) != 0) + +/* + * ISO TX/RX DATA BUFFERS + **************************************************************************************** + */ +/// RX/TX Isochronous buffer area definition +#define EM_BLE_ISO_BUF_OFFSET CO_ALIGN4_HI(EM_BLE_ISO_DESC_END) +#define EM_BLE_ISO_BUFFER_NB (BLE_ISO_BUF_NB) +#define EM_BLE_ISO_BUFFER_SIZE (REG_EM_BLE_TX_ISO_BUF_SIZE) +#define EM_BLE_ISO_BUFFER_END (EM_BLE_ISO_BUF_OFFSET + EM_BLE_ISO_BUFFER_NB * EM_BLE_ISO_BUFFER_SIZE) + +/// !!!! REMINDER: TX and RX ISO buffer have the same size !!!! Can use REG_EM_BLE_TX_ISO_BUF_SIZE and REG_EM_BLE_RX_ISO_BUF_SIZE +#define EM_BLE_TX_ISO_BUF_OFFSET (EM_BLE_ISO_BUF_OFFSET) +#define EM_BLE_RX_ISO_BUF_OFFSET (EM_BLE_ISO_BUF_OFFSET) +#if (REG_EM_BLE_TX_ISO_BUF_SIZE != REG_EM_BLE_RX_ISO_BUF_SIZE) +#error "TX and RX ISO buffer shall have the same size" +#endif // (REG_EM_BLE_TX_ISO_DESC_SIZE != REG_EM_BLE_RX_ISO_DESC_SIZE) +#if ((REG_EM_BLE_TX_ISO_BUF_SIZE % 4) != 0) +#error "TX/RX ISO Buffers must be 32 bits aligned" +#endif // ((REG_EM_BLE_TX_ISO_BUF_SIZE % 4) != 0) + +#else +#define EM_BLE_ISO_BUFFER_END (EM_BLE_ACLTXBUF_END) +#endif // (BLE_ISO_PRESENT) + +/* + * RX DESCRIPTORS FOR DIRECTION FINDING + **************************************************************************************** + */ +/// RX CTE Descriptors area definition +#define EM_BLE_RX_CTE_DESC_OFFSET CO_ALIGN4_HI(EM_BLE_ISO_BUFFER_END) +#if (BLE_CON_CTE_REQ | BLE_CONLESS_CTE_RX) +#define EM_BLE_RX_CTE_DESC_NB (BLE_RX_CTE_DESC_NB) +#define EM_BLE_RX_CTE_DESC_END (EM_BLE_RX_CTE_DESC_OFFSET + EM_BLE_RX_CTE_DESC_NB * REG_EM_BLE_RX_CTE_DESC_SIZE) +#else // (BLE_CON_CTE_REQ | BLE_CONLESS_CTE_RX) +#define EM_BLE_RX_CTE_DESC_END (EM_BLE_RX_CTE_DESC_OFFSET) +#endif // (BLE_CON_CTE_REQ | BLE_CONLESS_CTE_RX) + +/* + * ANTENNA IDs FOR DIRECTION FINDING + **************************************************************************************** + */ +/// Area definition for Tx antenna IDs +#define EM_BLE_TX_ANTENNA_ID_OFFSET CO_ALIGN4_HI(EM_BLE_RX_CTE_DESC_END) +#if (BLE_AOA | BLE_AOD) +#define EM_BLE_TX_ANTENNA_ID_NB (BLE_MAX_SW_PAT_LEN) +#define EM_BLE_TX_ANTENNA_ID_END (EM_BLE_TX_ANTENNA_ID_OFFSET + EM_BLE_TX_ANTENNA_ID_NB) +#else // (BLE_CON_CTE_REQ | BLE_CONLESS_CTE_RX) +#define EM_BLE_TX_ANTENNA_ID_END (EM_BLE_TX_ANTENNA_ID_OFFSET) +#endif // (BLE_CON_CTE_REQ | BLE_CONLESS_CTE_RX) + +/// Area definition for Rx antenna IDs +#define EM_BLE_RX_ANTENNA_ID_OFFSET CO_ALIGN4_HI(EM_BLE_TX_ANTENNA_ID_END) +#if (BLE_AOA | BLE_AOD) +#define EM_BLE_RX_ANTENNA_ID_NB (BLE_MAX_SW_PAT_LEN) +#define EM_BLE_RX_ANTENNA_ID_END (EM_BLE_RX_ANTENNA_ID_OFFSET + EM_BLE_RX_ANTENNA_ID_NB) +#else // (BLE_CON_CTE_REQ | BLE_CONLESS_CTE_RX) +#define EM_BLE_RX_ANTENNA_ID_END (EM_BLE_RX_ANTENNA_ID_OFFSET) +#endif // (BLE_CON_CTE_REQ | BLE_CONLESS_CTE_RX) + +/* + * END + **************************************************************************************** + */ +#define EM_BLE_END (EM_BLE_RX_ANTENNA_ID_END) + +/// @} EM + +#endif // EM_MAP_BLE_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/api/rwble.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/api/rwble.h new file mode 100644 index 0000000..79a85d0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/api/rwble.h @@ -0,0 +1,79 @@ +/** + **************************************************************************************** + * + * @file rwble.h + * + * @brief Entry points of the BLE software + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + +#ifndef RWBLE_H_ +#define RWBLE_H_ + +/** + **************************************************************************************** + * @addtogroup ROOT + * @brief Entry points of the BLE stack + * + * This module contains the primitives that allow an application accessing and running the + * BLE protocol stack + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include // standard integer definitions +#include // standard boolean definitions +#include "rwip_config.h" // stack configuration +#include "compiler.h" + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize the BLE stack. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void rwble_init(uint8_t init_type); + + +/** + **************************************************************************************** + * @brief Return true if no BLE activity on going + * + **************************************************************************************** + */ +bool rwble_activity_ongoing_check(void); + +/** + **************************************************************************************** + * @brief RWBLE interrupt service routine + * + * This function is the interrupt service handler of RWBLE. + * + **************************************************************************************** + */ +__BLEIRQ void rwble_isr(void); + +/// @} RWBLE + +#endif // RWBLE_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/api/rwble_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/api/rwble_config.h new file mode 100644 index 0000000..78e2a4b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/api/rwble_config.h @@ -0,0 +1,489 @@ +/** + **************************************************************************************** + * + * @file rwble_config.h + * + * @brief Configuration of the BLE lower layer stack + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + +#ifndef RWBLE_CONFIG_H_ +#define RWBLE_CONFIG_H_ + +/** + **************************************************************************************** + * @addtogroup ROOT + * @{ + * @name BLE LL stack configuration + * @{ + **************************************************************************************** + */ +/******************************************************************************************/ +/* -------------------------- FEATURE SETUP --------------------------------------*/ +/******************************************************************************************/ +#define BLE_FEATURES_BYTE0_NS ( (1 << BLE_FEAT_ENC ) \ + | (1 << BLE_FEAT_CON_PARAM_REQ_PROC ) \ + | (1 << BLE_FEAT_EXT_REJ_IND ) \ + | (1 << BLE_FEAT_SLAVE_INIT_FEAT_EXCHG ) \ + | (1 << BLE_FEAT_PING ) \ + | (1 << BLE_FEAT_DATA_PKT_LEN_EXT ) \ + | (1 << BLE_FEAT_LL_PRIVACY ) \ + | (1 << BLE_FEAT_EXT_SCAN_FILT_POLICY ) ) + +/// Features byte 1 +#define BLE_FEATURES_BYTE1_NS ( (BLE_PHY_2MBPS_SUPPORT << (BLE_FEAT_2M_PHY - 8) ) \ + | (1 << (BLE_FEAT_EXT_ADV - 8) ) \ + | (1 << (BLE_FEAT_PER_ADV - 8) )) \ + | (1 << (BLE_FEAT_CHAN_SEL_ALGO_2 - 8) ) + + +#define BLE_FEATURES_BYTE2_NS ( (1 << (BLE_FEAT_MIN_NUM_USED_CHAN_PROC - 16) ) \ + | (BLE_CON_CTE_REQ << (BLE_FEAT_CON_CTE_REQ - 16) ) \ + | (BLE_CON_CTE_RSP << (BLE_FEAT_CON_CTE_RSP - 16) ) \ + | (BLE_CONLESS_CTE_TX << (BLE_FEAT_CONLESS_CTE_TX - 16) ) \ + | (BLE_CONLESS_CTE_RX << (BLE_FEAT_CONLESS_CTE_RX - 16) ) \ + | (/*BLE_AOD*/ 0 << (BLE_FEAT_AOD - 16) ) \ + | (/*BLE_AOA */ 0 << (BLE_FEAT_AOA - 16) ) \ + | ((BLE_CON_CTE_REQ | BLE_CONLESS_CTE_RX) << (BLE_FEAT_CTE_RX - 16) ) ) + +#define BLE_FEATURES_BYTE3_NS ((1 << (BLE_FEAT_PER_ADV_SYNC_TRANSF_TX - 24) ) \ + | (1 << (BLE_FEAT_PER_ADV_SYNC_TRANSF_RX - 24) ) \ + | (1 << (BLE_FEAT_SLEEP_CLK_ACC_UPD - 24) ) \ + | (1 << (BLE_FEAT_PUB_KEY_VALID - 24) ) ) +/// Features byte 0 +#define BLE_FEATURES_BYTE0 ( (1 << BLE_FEAT_ENC ) \ + | (1 << BLE_FEAT_CON_PARAM_REQ_PROC ) \ + | (1 << BLE_FEAT_EXT_REJ_IND ) \ + | (1 << BLE_FEAT_SLAVE_INIT_FEAT_EXCHG ) \ + | (1 << BLE_FEAT_PING ) \ + | (1 << BLE_FEAT_DATA_PKT_LEN_EXT ) \ + | (1 << BLE_FEAT_LL_PRIVACY ) \ + | (1 << BLE_FEAT_EXT_SCAN_FILT_POLICY ) ) +/// Features byte 1 +#define BLE_FEATURES_BYTE1 ( (BLE_PHY_2MBPS_SUPPORT << (BLE_FEAT_2M_PHY - 8) ) \ + | (BLE_STABLE_MOD_IDX_TX_SUPPORT << (BLE_FEAT_STABLE_MOD_IDX_TX - 8) ) \ + | (BLE_STABLE_MOD_IDX_RX_SUPPORT << (BLE_FEAT_STABLE_MOD_IDX_RX - 8) ) \ + | (BLE_PHY_CODED_SUPPORT << (BLE_FEAT_CODED_PHY - 8) ) \ + | (1 << (BLE_FEAT_EXT_ADV - 8) ) \ + | (1 << (BLE_FEAT_PER_ADV - 8) ) \ + | (1 << (BLE_FEAT_CHAN_SEL_ALGO_2 - 8) ) \ + | (BLE_PWR_CLASS_1_SUPPORT << (BLE_FEAT_PWR_CLASS_1 - 8) ) ) + +/// Features byte 2 +#define BLE_FEATURES_BYTE2 ( (1 << (BLE_FEAT_MIN_NUM_USED_CHAN_PROC - 16) ) \ + | (BLE_CON_CTE_REQ << (BLE_FEAT_CON_CTE_REQ - 16) ) \ + | (BLE_CON_CTE_RSP << (BLE_FEAT_CON_CTE_RSP - 16) ) \ + | (BLE_CONLESS_CTE_TX << (BLE_FEAT_CONLESS_CTE_TX - 16) ) \ + | (BLE_CONLESS_CTE_RX << (BLE_FEAT_CONLESS_CTE_RX - 16) ) \ + | (BLE_AOD << (BLE_FEAT_AOD - 16) ) \ + | (BLE_AOA << (BLE_FEAT_AOA - 16) ) \ + | ((BLE_CON_CTE_REQ | BLE_CONLESS_CTE_RX) << (BLE_FEAT_CTE_RX - 16) ) ) + +/// Features byte 3 +#define BLE_FEATURES_BYTE3 ( (1 << (BLE_FEAT_PER_ADV_SYNC_TRANSF_TX - 24) ) \ + | (1 << (BLE_FEAT_PER_ADV_SYNC_TRANSF_RX - 24) ) \ + | (1 << (BLE_FEAT_SLEEP_CLK_ACC_UPD - 24) ) \ + | (1 << (BLE_FEAT_PUB_KEY_VALID - 24) ) ) + +/// Features byte 4 +#define BLE_FEATURES_BYTE4 (0) + +/// Features byte 5 +#define BLE_FEATURES_BYTE5 (0) + +/// Features byte 6 +#define BLE_FEATURES_BYTE6 (0) + +/// Features byte 7 +#define BLE_FEATURES_BYTE7 (0) + +/// States byte 0 +#define BLE_STATES_BYTE0 ( BLE_NON_CON_ADV_STATE | BLE_DISC_ADV_STATE\ + | BLE_CON_ADV_STATE | BLE_HDC_DIRECT_ADV_STATE\ + | BLE_PASS_SCAN_STATE | BLE_ACTIV_SCAN_STATE\ + | BLE_INIT_MASTER_STATE | BLE_CON_SLAVE_STATE) + +/// States byte 1 +#define BLE_STATES_BYTE1 ( BLE_NON_CON_ADV_PASS_SCAN_STATE | BLE_DISC_ADV_PASS_SCAN_STATE\ + | BLE_CON_ADV_PASS_SCAN_STATE | BLE_HDC_DIRECT_ADV_PASS_SCAN_STATE\ + | BLE_NON_CON_ADV_ACTIV_SCAN_STATE | BLE_DISC_ADV_ACTIV_SCAN_STATE\ + | BLE_CON_ADV_ACTIV_SCAN_STATE | BLE_HDC_DIRECT_ADV_ACTIV_SCAN_STATE) + +/// States byte 2 +#define BLE_STATES_BYTE2 ( BLE_NON_CON_ADV_INIT_STATE | BLE_DISC_ADV_INIT_STATE\ + | BLE_NON_CON_ADV_MASTER_STATE | BLE_DISC_ADV_MASTER_STATE\ + | BLE_NON_CON_ADV_SLAVE_STATE | BLE_DISC_ADV_SLAVE_STATE\ + | BLE_PASS_SCAN_INIT_STATE | BLE_ACTIV_SCAN_INIT_STATE) + +/// States byte 3 +#define BLE_STATES_BYTE3 ( BLE_PASS_SCAN_MASTER_STATE | BLE_ACTIV_SCAN_MASTER_STATE\ + | BLE_PASS_SCAN_SLAVE_STATE | BLE_ACTIV_SCAN_SLAVE_STATE\ + | BLE_INIT_MASTER_MASTER_STATE | BLE_LDC_DIRECT_ADV_STATE\ + | BLE_LDC_DIRECT_ADV_PASS_SCAN_STATE | BLE_LDC_DIRECT_ADV_ACTIV_SCAN_STATE) + +/// States byte 4 +#define BLE_STATES_BYTE4 ( BLE_CON_ADV_INIT_MASTER_SLAVE_STATE | BLE_HDC_DIRECT_ADV_INIT_MASTER_SLAVE_STATE\ + | BLE_LDC_DIRECT_ADV_INIT_MASTER_SLAVE_STATE | BLE_CON_ADV_MASTER_SLAVE_STATE\ + | BLE_HDC_DIRECT_ADV_MASTER_SLAVE_STATE | BLE_LDC_DIRECT_ADV_MASTER_SLAVE_STATE\ + | BLE_CON_ADV_SLAVE_SLAVE_STATE | BLE_HDC_DIRECT_ADV_SLAVE_SLAVE_STATE) + +/// States byte 5 +#define BLE_STATES_BYTE5 ( BLE_LDC_DIRECT_ADV_SLAVE_SLAVE_STATE | BLE_INIT_MASTER_SLAVE_STATE) + +/// States byte 6 +#define BLE_STATES_BYTE6 0x0 +/// States byte 7 +#define BLE_STATES_BYTE7 0x0 + + +/******************************************************************************************/ +/* -------------------------- GENERAL SETUP --------------------------------------*/ +/******************************************************************************************/ + +/************************************ + * KE message heap * + ************************************ + * + * LLD->LLC/LLM messages: + * - connection < 6 + * - advertising adv end 56 + * - scan max adv chain 1650 + * - initiating init end 56 + * - per adv tx 2 + * - per adv rx max adv chain 1650 + * - encryption 16 + * => 1650 + 16 + (N-1) x 56 + * + * HCI params stored by LLM: + * - advertising 26 + * - scan 16 + * - initiating 58 + * - per adv tx 8 + * - per adv rx 14 + * => 58 + (N-1) x 26 + * + * LLCP TX queue: + * - Max 3 LLCP in the queue per link + * - Average 10 bytes per PDU + * - N x 3 x (12 + 10) = N x 66 + * + * HCI commands reception: + * - N commands of max 255 bytes + * - N x 255 + * + * HCI events: + * - Max advertising reports in TX queue: N x 255 + * - + 1 100-bytes event per activity: N x 100 + * + * Kernel timers: + * - 1 timer per connection + * - N x 12 + * + * Due to high probability of fragmentation, and sizes of the Kernel message headers, the total of above additions is + * doubled. + */ + +#define BLE_HEAP_MSG_SIZE ( 1650 * BLE_OBSERVER \ + + 2 * ( (16 + (BLE_ACTIVITY_MAX-1) * 56) \ + + (58 + (BLE_ACTIVITY_MAX-1) * 26) \ + + (BLE_ACTIVITY_MAX * 66) \ + + (HCI_NB_CMD_PKTS * 255) \ + + (BLE_OBSERVER * BLE_MAX_NB_ADV_REP_FRAG * 255 + BLE_ACTIVITY_MAX * 100) \ + + (BLE_ACTIVITY_MAX * 12) \ + ) ) + +/************************************ + * Environments heap * + ************************************ + * + * Max env usage per activity: + * - connection 84 (LLC) + 144 228 + * - advertising 140 140 + * - scan 32 + 2 x 108 + 16 264 + * - initiating 84 + 3 x 80 324 + * - per adv tx 80 80 + * - per adv rx 96 96 + * + * It is possible to have one initiating + 1 scan + (N-2) other activities. + * Add 2 activities to consider Heap fragmentation. + * + * Heap size = 330 + 270 + (N-2 x 230) + 2 x 230 = 600 + N x 230 + */ +#define BLE_HEAP_ENV_SIZE (330*BLE_CENTRAL + 270*BLE_OBSERVER + BLE_ACTIVITY_MAX * 230) + +/// Normal Rx window size (in us) +#define BLE_NORMAL_WIN_SIZE 20 //14 //TODO ding.yuanwu +#define BLE_NORMAL_WIN_SIZE_HW 20 //14 +/// Normal Rx window size for coded phy (in us) +// In Long Range, the symbol for the Access Address is 8 times longer than the symbol for 1Mbps. +#define BLE_PHY_CODED_NORMAL_WIN_SIZE (BLE_NORMAL_WIN_SIZE * 8) + + +/// Number of devices in the white list +#define BLE_WHITELIST_MAX (BLE_ACTIVITY_MAX + 2) + +/// Number of devices in the Resolution Address List +/// This have to be tuned according to the core frequency. Worst case is having in scan mode +/// all IRK and valid in resolving list and device receive a Direct Adv Report that contains +/// RPAs for InitA and AdvA +#define BLE_RESOL_ADDR_LIST_MAX (BLE_RAL_MAX) + +/// Number of RX data buffers (common for all activities) +#define BLE_DATA_BUF_NB_RX (BLE_RX_DESC_NB + 3) +/// Guard space reserved for HCI ACL header in BLE RX buffers +#define BLE_ACL_RX_BUF_HEADER_SPACE (HCI_ACL_HDR_LEN + 1) //TODO_VAR + +/// Number of TX ACL data buffers +#define BLE_ACL_BUF_NB_TX (BLE_ACTIVITY_MAX + 2) //TODO_VAR + +/// Number of advertising data buffers +#define BLE_ADV_BUF_NB_TX (BLE_ACTIVITY_MAX) +/// Number of advertising or scan response data fragments in extended advertising PDU chain +#define BLE_ADV_FRAG_NB_TX (5) +/// Size of advertising or scan response data fragments in extended advertising PDU chain +#define BLE_ADV_FRAG_SIZE_TX (254) +/// Maximum advertising data length +#define BLE_CFG_MAX_ADV_DATA_LEN (BLE_ADV_FRAG_NB_TX * BLE_ADV_FRAG_SIZE_TX) + +/// Maximum number of Rx Descriptors that can be used during the reception of Auxiliary chained +/// advertising packet on Secondary advertising channels (0: no limit) +#define BLE_ADV_FRAG_NB_RX_MAX (7) + +/// Define the AUX Frame Space duration +#if defined(CFG_AFS_EXT) +// Aux Frame Space extended for scanner Aux offload testing +#define BLE_AFS_DUR (3000) // 3.0ms +#else // !(CFG_DBG_AUX_OFFLOAD) +// Packed advertising - Minimum AUX Frame Space +#define BLE_AFS_DUR (BLE_MAFS_DUR) +#endif // (CFG_DBG_AUX_OFFLOAD) + +/// Data packet transmission size and duration +/// These values represent what the device supports +#define BLE_MIN_OCTETS (27) // number of octets +#define BLE_MIN_TIME (328) // in us +#define BLE_MAX_OCTETS (251) // number of octets +#define BLE_MAX_TIME (17040) // in us + +/// Number of devices capacity for the scan duplicate filtering +#if (BLE_OBSERVER) +#define BLE_DUPLICATE_FILTER_MAX (10) +#endif //(BLE_OBSERVER) + +/// Number of TX descriptors per BLE connection [2|3|4] +#define BLE_NB_TX_DESC_PER_CON 2 + +/// Number of TX descriptors per advertising set +#define BLE_NB_TX_DESC_PER_ADV (2+BLE_ADV_FRAG_NB_TX) + +/// Number of TX descriptors per BLE activity (maximum needed for connection or advertising) +#if (BLE_NB_TX_DESC_PER_CON > BLE_NB_TX_DESC_PER_ADV) +#define BLE_NB_TX_DESC_PER_ACT (BLE_NB_TX_DESC_PER_CON) +#else //(BLE_NB_TX_DESC_PER_CON > BLE_NB_TX_DESC_PER_ADV) +#define BLE_NB_TX_DESC_PER_ACT (BLE_NB_TX_DESC_PER_ADV) +#endif //(BLE_NB_TX_DESC_PER_CON > BLE_NB_TX_DESC_PER_ADV) + +/// Number of RX descriptors +#define BLE_RX_DESC_NB (11) +/// Number of TX descriptors +#define BLE_TX_DESC_NB (BLE_NB_TX_DESC_PER_ACT * BLE_ACTIVITY_MAX) + +/// Legacy advertising HCI interface +#define BLE_ADV_LEGACY_ITF (HCI_TL_SUPPORT) + +/// Low energy event mask (should be the standard value if device is in controller-only) +#if ((BLE_EMB_PRESENT) && (!BLE_HOST_PRESENT)) +#define BLE_EVT_MASK {0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} +#else // (!(BLE_EMB_PRESENT) || (BLE_HOST_PRESENT)) +/// Low energy event mask (should be the custom mask if device is in full-stack) +#define BLE_EVT_MASK {0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00} +#endif // ((BLE_EMB_PRESENT) && (!BLE_HOST_PRESENT)) + +/******************************************************************************************/ +/* -------------------------- DEBUG SETUP ----------------------------------------*/ +/******************************************************************************************/ + +#define BLE_TEST_MODE_SUPPORT (1) + +/******************************************************************************************/ +/* -------------------- CHANNEL ASSESSMENT SETUP --------------------------*/ +/******************************************************************************************/ + +/// RSSI threshold for interference detection (in dBm) +#define BLE_CH_ASSESS_RSSI_INTERF_THR (-70) + +/// Channel map update period (in sec) +#define BLE_CH_MAP_UPDATE_PERIOD 4 + +/// Maximum duration without receiving a packet before considering a channel quality unknown (in slots) (2 secs) +#define BLE_CH_ASSESS_VALID_TO 0x1900 + +/// Maximum duration without receiving a packet before reintroducing a channel to the map (in slots) (20 secs) +#define BLE_CH_REASSESS_TO 0x7D00 + +/// Maximum counter value for channel assessment +#define BLE_CH_ASSESS_COUNT_MAX 4 +/// Counter threshold to consider a channel good +#define BLE_CH_ASSESS_COUNT_THR_GOOD 2 +/// Counter threshold to consider a channel bad +#define BLE_CH_ASSESS_COUNT_THR_BAD -2 +/// Minimum counter value for channel assessment +#define BLE_CH_ASSESS_COUNT_MIN -4 + + +/******************************************************************************************/ +/* -------------------------- Direction finding (AoA/AoD) -------------------------*/ +/******************************************************************************************/ + +/// Number of antennae used for constant tone extension transmission or reception +#define BLE_ANTENNA_NB 4 + +/// Maximum length of switching pattern +#define BLE_MAX_SW_PAT_LEN 12 + +/// Number of RX descriptors used for constant tone extension reception +#define BLE_RX_CTE_DESC_NB BLE_RX_DESC_NB + + +/******************************************************************************************/ +/* ----------------------- SUPPORTED HCI COMMANDS --------------------------------*/ +/******************************************************************************************/ + +//byte0 +#define BLE_CMDS_BYTE0 BLE_DISC_CMD +//byte2 +#define BLE_CMDS_BYTE2 BLE_RD_REM_VERS_CMD +//byte5 +#define BLE_CMDS_BYTE5 (BLE_SET_EVT_MSK_CMD | BLE_RESET_CMD) +//byte10 +#define BLE_CMDS_BYTE10 (BLE_HL_NB_CMP_PKT_CMD | BLE_RD_TX_PWR_CMD\ + |BLE_HL_BUF_SIZE_CMD | BLE_SET_CTRL_TO_HL_FCTRL_CMD) +//byte14 +#define BLE_CMDS_BYTE14 (BLE_RD_LOC_VERS_CMD | BLE_RD_LOC_SUP_FEAT_CMD) +//byte15 +#define BLE_CMDS_BYTE15 (BLE_RD_BD_ADDR_CMD | BLE_RD_RSSI_CMD) +//byte22 +#define BLE_CMDS_BYTE22 (BLE_SET_EVT_MSK_PG2_CMD) +//byte25 +#define BLE_CMDS_BYTE25 (BLE_LE_SET_EVT_MSK_CMD | BLE_LE_RD_BUF_SIZE_CMD\ + |BLE_LE_RD_LOC_SUP_FEAT_CMD | BLE_LE_SET_RAND_ADDR_CMD\ + |BLE_LE_SET_ADV_PARAM_CMD | BLE_LE_RD_ADV_TX_PWR_CMD\ + |BLE_LE_SET_ADV_DATA_CMD) +//byte26 +#define BLE_CMDS_BYTE26 (BLE_LE_SET_SC_RSP_DATA_CMD | BLE_LE_SET_ADV_EN_CMD\ + |BLE_LE_SET_SC_PARAM_CMD | BLE_LE_SET_SC_EN_CMD\ + |BLE_LE_CREAT_CNX_CMD | BLE_LE_CREAT_CNX_CNL_CMD\ + |BLE_LE_RD_WL_SIZE_CMD | BLE_LE_CLEAR_WL_CMD) +//byte27 +#define BLE_CMDS_BYTE27 (BLE_LE_ADD_DEV_WL_CMD | BLE_LE_REM_DEV_WL_CMD\ + |BLE_LE_CNX_UPDATE_CMD | BLE_LE_SET_HL_CH_CLASS_CMD\ + |BLE_LE_RD_CH_MAP_CMD | BLE_LE_RD_REM_FEAT_CMD\ + |BLE_LE_ENCRYPT_CMD | BLE_LE_RAND_CMD) +//byte28 +#define BLE_CMDS_BYTE28 (BLE_LE_START_ENC_CMD | BLE_LE_LTK_REQ_RPLY_CMD\ + |BLE_LE_LTK_REQ_NEG_RPLY_CMD | BLE_LE_RD_SUPP_STATES_CMD\ + |BLE_LE_RX_TEST_V1_CMD | BLE_LE_TX_TEST_V1_CMD\ + |BLE_LE_STOP_TEST_CMD) +//byte32 +#define BLE_CMDS_BYTE32 (BLE_RD_AUTH_PAYL_TO_CMD | BLE_WR_AUTH_PAYL_TO_CMD) +//byte33 +#define BLE_CMDS_BYTE33 (BLE_LE_REM_CON_PARA_REQ_RPLY_CMD | BLE_LE_REM_CON_PARA_REQ_NEG_RPLY_CMD\ + | BLE_LE_SET_DATA_LEN_CMD | BLE_LE_RD_SUGGTED_DFT_DATA_LEN_CMD) +//byte34 +#define BLE_CMDS_BYTE34 ( BLE_LE_WR_SUGGTED_DFT_DATA_LEN_CMD \ + | BLE_LE_RD_LOC_P256_PUB_KEY_CMD \ + | BLE_LE_GEN_DHKEY_V1_CMD \ + | BLE_LE_ADD_DEV_TO_RESOLV_LIST_CMD \ + | BLE_LE_REM_DEV_FROM_RESOLV_LIST_CMD \ + | BLE_LE_CLEAR_RESOLV_LIST_CMD \ + | BLE_LE_RD_RESOLV_LIST_SIZE_CMD \ + | BLE_LE_RD_PEER_RESOLV_ADDR_CMD ) +//byte35 +#define BLE_CMDS_BYTE35 ( BLE_LE_RD_LOCAL_RESOLV_ADDR_CMD \ + | BLE_LE_SET_ADDR_RESOL_CMD \ + | BLE_LE_SET_RESOLV_PRIV_ADDR_TO_CMD \ + | BLE_LE_RD_MAX_DATA_LEN_CMD \ + | BLE_LE_RD_PHY_CMD \ + | BLE_LE_SET_DFT_PHY_CMD \ + | BLE_LE_SET_PHY_CMD \ + | BLE_LE_RX_TEST_V2_CMD ) +//byte36 +#define BLE_CMDS_BYTE36 ( BLE_LE_TX_TEST_V2_CMD \ + | BLE_LE_SET_ADV_SET_RAND_ADDR_CMD \ + | BLE_LE_SET_EXT_ADV_PARAM_CMD \ + | BLE_LE_SET_EXT_ADV_DATA_CMD \ + | BLE_LE_SET_EXT_SCAN_RSP_DATA_CMD \ + | BLE_LE_SET_EXT_ADV_EN_CMD \ + | BLE_LE_RD_MAX_ADV_DATA_LEN_CMD \ + | BLE_LE_RD_NB_SUPP_ADV_SETS_CMD ) +//byte37 +#define BLE_CMDS_BYTE37 ( BLE_LE_RMV_ADV_SET_CMD \ + | BLE_LE_CLEAR_ADV_SETS_CMD \ + | BLE_LE_SET_PER_ADV_PARAM_CMD \ + | BLE_LE_SET_PER_ADV_DATA_CMD \ + | BLE_LE_SET_PER_ADV_EN_CMD \ + | BLE_LE_SET_EXT_SCAN_PARAM_CMD \ + | BLE_LE_SET_EXT_SCAN_EN_CMD \ + | BLE_LE_EXT_CREATE_CON_CMD ) +//byte38 +#define BLE_CMDS_BYTE38 ( BLE_LE_PER_ADV_CREATE_SYNC_CMD \ + | BLE_LE_PER_ADV_CREATE_SYNC_CANCEL_CMD \ + | BLE_LE_PER_ADV_TERM_SYNC_CMD \ + | BLE_LE_ADD_DEV_TO_PER_ADV_LIST_CMD \ + | BLE_LE_RMV_DEV_FROM_PER_ADV_LIST_CMD \ + | BLE_LE_CLEAR_PER_ADV_LIST_CMD \ + | BLE_LE_RD_PER_ADV_LIST_SIZE_CMD \ + | BLE_LE_RD_TX_PWR_CMD ) +//byte39 +#define BLE_CMDS_BYTE39 ( BLE_LE_RD_RF_PATH_COMP_CMD \ + | BLE_LE_WR_RF_PATH_COMP_CMD \ + | BLE_LE_SET_PRIV_MODE_CMD \ + | BLE_LE_RX_TEST_V3_CMD \ + | BLE_LE_TX_TEST_V3_CMD \ + | BLE_LE_SET_CONLESS_CTE_TX_PARAM_CMD \ + | BLE_LE_SET_CONLESS_CTE_TX_EN_CMD \ + | BLE_LE_SET_CONLESS_IQ_SAMPL_EN_CMD ) +//byte40 +#define BLE_CMDS_BYTE40 ( BLE_LE_SET_CON_CTE_RX_PARAM_CMD \ + | BLE_LE_SET_CON_CTE_TX_PARAM_CMD \ + | BLE_LE_CON_CTE_REQ_EN_CMD \ + | BLE_LE_CON_CTE_RSP_EN_CMD \ + | BLE_LE_RD_ANTENNA_INF_CMD \ + | BLE_LE_SET_PER_ADV_RX_EN_CMD \ + | BLE_LE_PER_ADV_SYNC_TRANSF_CMD \ + | BLE_LE_PER_ADV_SET_INFO_TRANSF_CMD ) +//byte41 +#define BLE_CMDS_BYTE41 ( BLE_LE_SET_PER_ADV_SYNC_TRANSF_PARAM_CMD \ + | BLE_LE_SET_DFT_PER_ADV_SYNC_TRANSF_PARAM_CMD \ + | BLE_LE_GEN_DHKEY_V2_CMD \ + | BLE_LE_MOD_SLP_CLK_ACC_CMD ) + + +/******************************************************************************************/ +/* ------------------------ CONNECTION HANDLE ----------------------------------------*/ +/******************************************************************************************/ + +/// Bit set for BLE connection handles +#define BLE_CONHDL_MIN (0) +#define BLE_CONHDL_MAX (BLE_CONHDL_MIN + BLE_ACTIVITY_MAX - 1) +#define BLE_LINKID_TO_CONHDL(link_id) ((uint16_t) (BLE_CONHDL_MIN + (link_id))) +#define BLE_CONHDL_TO_LINKID(conhdl) ((uint8_t) ((conhdl) - BLE_CONHDL_MIN)) + +/// Bit set for BLE sync handles (used in periodic advertising receiver mode) +#define BLE_SYNCHDL_MIN (0) +#define BLE_SYNCHDL_MAX (BLE_SYNCHDL_MIN + BLE_ACTIVITY_MAX - 1) +#define BLE_ACTID_TO_SYNCHDL(act_id) ((uint16_t) (BLE_SYNCHDL_MIN + (act_id))) +#define BLE_SYNCHDL_TO_ACTID(synchdl) ((uint8_t) ((synchdl) - BLE_SYNCHDL_MIN)) + +/// AM0 Channel handle mapping +#define BLE_AM0HDL_MIN (0x300) +#define BLE_CHANHDL_TO_AM0HDL(chanhdl) ((uint16_t) (BLE_AM0HDL_MIN + (chanhdl))) +#define BLE_AM0HDL_TO_CHANHDL(am0) ((uint8_t) ((am0) - BLE_AM0HDL_MIN)) + +/// @} BLE stack configuration +/// @} ROOT + +#endif // RWBLE_CONFIG_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/ble_util_buf.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/ble_util_buf.h new file mode 100644 index 0000000..dd40cd1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/ble_util_buf.h @@ -0,0 +1,251 @@ +/** + **************************************************************************************** + * + * @file ble_util_buf.h + * + * @brief Main API file for the BLE EM buffer management system + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + +#ifndef BLE_UTIL_BUF_H_ +#define BLE_UTIL_BUF_H_ + +/** + **************************************************************************************** + * @defgroup BLE_UTIL_BUF BLE EM buffer management system + * @ingroup ROOT + * @brief BLE EM buffer management system + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include // standard integer +#include "co_list.h" // common list definition + +/* + * DEFINES + **************************************************************************************** + */ + +/// ACL data: handle and data length decoding +#define BLE_EM_ACL_DATA_LEN_LSB (0) +#define BLE_EM_ACL_DATA_LEN_MASK (0x03FF) +/// Packet boundary flag +#define BLE_EM_ACL_PBF_LSB (12) +#define BLE_EM_ACL_PBF_MASK (0x3000) +/// Broadcast flag +#define BLE_EM_ACL_BF_LSB (14) +#define BLE_EM_ACL_BF_MASK (0xC000) + +#if (BLE_ISO_PRESENT) +#define BLE_UTIL_ISODESC_INVALID 0xFF +#endif // (BLE_ISO_PRESENT) + +/* + * STRUCTURE DEFINITION + **************************************************************************************** + */ + +/// EM LLCP buffer element +struct ble_em_llcp_buf_elt +{ + /// List header + struct co_list_hdr hdr; + /// EM buffer pointer + uint16_t buf_ptr; + /// Data length (in bytes) + uint8_t length; +}; + +/// EM ACL buffer element +struct ble_em_acl_buf_elt +{ + /// List header + struct co_list_hdr hdr; + /// EM buffer pointer + uint16_t buf_ptr; + /// Data length (in bytes) + Data Flags (PBF + BF) + uint16_t data_len_flags; +}; + +/// EM advertising data buffer element +struct ble_em_adv_buf_elt +{ + /// List header + struct co_list_hdr hdr; + /// EM buffer pointer + uint16_t buf_ptr; + /// Data length (in bytes) + uint16_t length; +}; + +#if (BLE_ISO_PRESENT) +/// EM ISO TX/RX Buffer +struct ble_em_iso_buf_elt +{ + /// List header + struct co_list_hdr hdr; + /// EM buffer pointer + uint16_t buf_ptr; + /// Buffer index + uint8_t buf_idx; +}; +#endif // (BLE_ISO_PRESENT) + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize BLE EM buffers management system + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void ble_util_buf_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Allocate a LLCP TX buffer + * + * @return Pointer to LLCP TX buffer, NULL if no buffer available + **************************************************************************************** + */ +struct ble_em_llcp_buf_elt* ble_util_buf_llcp_tx_alloc(void); + +/** + **************************************************************************************** + * @brief Free a LLCP TX buffer + * + * @param[in] buf Pointer to LLCP TX buffer + **************************************************************************************** + */ +void ble_util_buf_llcp_tx_free(uint16_t buf); + +/** + **************************************************************************************** + * @brief Allocate a RX buffer + * + * @return Pointer to RX buffer, NULL if no buffer available + **************************************************************************************** + */ +uint16_t ble_util_buf_rx_alloc(void); + +/** + **************************************************************************************** + * @brief Free a RX buffer + * + * @param[in] buf Pointer to RX buffer + **************************************************************************************** + */ +void ble_util_buf_rx_free(uint16_t buf); + +/** + **************************************************************************************** + * @brief Allocate a ACL TX buffer + * + * @return Pointer to ACL TX buffer, NULL if no buffer available + **************************************************************************************** + */ +uint16_t ble_util_buf_acl_tx_alloc(void); + + +/** + **************************************************************************************** + * @brief Retrieve TX buffer Element + * + * @return Pointer to ACL TX buffer element + **************************************************************************************** + */ +struct ble_em_acl_buf_elt* ble_util_buf_acl_tx_elt_get(uint16_t buf); + +/** + **************************************************************************************** + * @brief Free a ACL TX buffer + * + * @param[in] buf Pointer to ACL TX buffer + **************************************************************************************** + */ +void ble_util_buf_acl_tx_free(uint16_t buf); + +/** + **************************************************************************************** + * @brief Allocate an advertising data TX buffer + * + * @return Pointer to advertising data TX buffer, NULL if no buffer available + **************************************************************************************** + */ +uint16_t ble_util_buf_adv_tx_alloc(void); + +/** + **************************************************************************************** + * @brief Free an advertising data TX buffer + * + * @param[in] buf Pointer to advertising data TX buffer + **************************************************************************************** + */ +void ble_util_buf_adv_tx_free(uint16_t buf); + +#if (BLE_ISO_PRESENT) +/** + **************************************************************************************** + * @brief Allocate an Isochronous data TX/RX buffer + * + * @param[out] index Index of Isochronous data TX/RX buffer + * + * @return Pointer to Isochronous data TX/RX buffer, NULL if no buffer available + **************************************************************************************** + */ +uint16_t ble_util_buf_iso_alloc(uint8_t* index); + +/** + **************************************************************************************** + * @brief Free an Isochronous data TX/RX buffer + * + * @param[in] index Index of Isochronous data TX/RX buffer + **************************************************************************************** + */ +void ble_util_buf_iso_free(uint8_t index); + +/** + **************************************************************************************** + * @brief Initialize BLE ISO descriptors management system + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void ble_util_isodesc_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Allocate an ISO descriptor + * + * @return Descriptor index allocated + **************************************************************************************** + */ +uint8_t ble_util_isodesc_alloc(void); + +/** + **************************************************************************************** + * @brief Free an ISO descriptor + * + * @param[in] desc_idx Index number of ISO descriptor + **************************************************************************************** + */ +void ble_util_isodesc_free(uint8_t desc_idx); + +#endif // (BLE_ISO_PRESENT) + +/// @} BLE_UTIL_BUF + +#endif // BLE_UTIL_BUF_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llc.h new file mode 100644 index 0000000..26756a3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llc.h @@ -0,0 +1,194 @@ +/** + **************************************************************************************** + * + * @file llc.h + * + * @brief Main API file for the Link Layer Controller + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + +#ifndef LLC_H_ +#define LLC_H_ + +/** + **************************************************************************************** + * @defgroup LLC Link Layer Controller + * @ingroup ROOT + * @brief BLE Lower Layers + * + * The CONTROLLER contains the modules allowing the link establishment, maintenance and management. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" +#if(BLE_CENTRAL || BLE_PERIPHERAL) +#include "ke_task.h" // kernel task definitions +#include "co_bt.h" +#include "co_llcp.h" + +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * ENUMERATION DEFINITIONS + **************************************************************************************** + */ + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// API structure to be set by LLM and used by the LLC for each new link +struct llc_init_parameters +{ + /// Access address + struct access_addr aa; + + /// CRC init + struct crc_init crcinit; + + /// Window size (in units of 1,25 ms, i.e. 2 slots) + uint8_t winsize; + + /// Window offset (in units of 1,25 ms, i.e. 2 slots) + uint16_t winoffset; + + /// Interval (in units of 1,25 ms, i.e. 2 slots) + uint16_t interval; + + /// Latency + uint16_t latency; + + /// Timeout (in units of 10 ms, i.e. 16 slots) + uint16_t timeout; + + /// Channel mapping + struct le_chnl_map chm; + + /// Hopping increment (random value in the range of 5 to 16) + uint8_t hop_inc; + + /** + * Master Sleep clock accuracy (only for slave) + * 0 251 ppm to 500 ppm + * 1 151 ppm to 250 ppm + * 2 101 ppm to 150 ppm + * 3 76 ppm to 100 ppm + * 4 51 ppm to 75 ppm + * 5 31 ppm to 50 ppm + * 6 21 ppm to 30 ppm + * 7 0 ppm to 20 ppm + */ + uint8_t master_sca; + + /// CONNECT_REQ packet fine timer count (in us) + uint16_t fine_cnt_rxsync; + + /// CONNECT_REQ packet base timer count (timestamp, in slots) + uint32_t base_cnt_rxsync; + + /// First anchor point timestamp (in slots, master only) + uint32_t first_anchor_ts; + + /// Connection transmit/receive rate (@see enum lld_rate) + uint8_t rate; + + /// Role (0: Master | 1: Slave) + uint8_t role; + + /// Indicates whether channel selection algorithm #2 will be used or not + bool ch_sel_2; + + /// Indicates whether the AUX_CONNECT_REQ PDU was used or not (true for AUX_CONNECT_REQ, false for CONNECT_IND) + bool aux_connect_req; + + // Default Data Length parameters + /// Suggested value for the Controller's maximum transmitted number of payload octets + uint16_t suggested_max_tx_octets; + /// Suggested value for the Controller's maximum packet transmission time (in us) + uint16_t suggested_max_tx_time; + + // Default PHY parameters + /// Default TX preferred PHY to use (@see enum le_phy_mask) + uint8_t tx_phys; + /// Default RX preferred PHY to use (@see enum le_phy_mask) + uint8_t rx_phys; + + // Default PAST parameters + /// Mode (@see enum per_adv_sync_info_rec_mode) + uint8_t past_mode; + /// The number of periodic advertising packets that can be skipped after a successful receive + uint16_t past_skip; + /// Sync timeout (Time=N*10ms) + uint16_t past_sync_to; + /// CTE type (@see enum sync_cte_type) + uint8_t past_cte_type; +}; + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Initialization/Reset of the BLE LLC task + * + * This function initializes the LLC task, as well as the environment of the LLC + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void llc_init(uint8_t init_type); + + +/** + **************************************************************************************** + * @brief Start an initialize a new LLC environment + * + * @param[in] link_id link identifier. + * @param[in] con_params All parameters needed to start the LLC + * @param[in] pref Link preferences (set by host) + * + * @return If the environment allocation and initialization has been done or not. + **************************************************************************************** + */ +uint8_t llc_start(uint8_t link_id, struct llc_init_parameters *con_params); + +/** + **************************************************************************************** + * @brief Handles a planner request to move the activity + * + * @param[in] id sch_plan identifier. + **************************************************************************************** + */ +void llc_con_move_cbk(uint16_t id); + +/** + **************************************************************************************** + * @brief Modify sleep clock accuracy + * + * @param[in] link_id Link identifier + * @param[in] action Switch to more or less accurate clock (@see enum clk_acc_action) + **************************************************************************************** + */ +void llc_clk_acc_modify(uint8_t link_id, uint8_t action); + +#endif// (BLE_CENTRAL || BLE_PERIPHERAL) + +/// @} LLC + +#endif // LLC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llc/llc_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llc/llc_int.h new file mode 100644 index 0000000..3d63283 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llc/llc_int.h @@ -0,0 +1,1068 @@ +/** + **************************************************************************************** + * + * @file llc_int.h + * + * @brief Link layer controller internal definition + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + +#ifndef LLC_INT_H_ +#define LLC_INT_H_ + +/** + **************************************************************************************** + * @addtogroup LLC Link layer Controller + * @{ + **************************************************************************************** + */ +#include "rwip_task.h" // Task definitions + + + + + +/* + * INSTANCES + **************************************************************************************** + */ +/// Maximum number of instances of the LLC task +#define LLC_IDX_MAX BLE_ACTIVITY_MAX + +/* + * DEFINE + **************************************************************************************** + */ +///The master should allow a minimum of 6 connection events that the slave will be listening +///for before the instant occurs +#define LLC_PROC_SWITCH_INSTANT_DELAY (9) + +/* + * MESSAGES + **************************************************************************************** + */ + +/// Message API of the LLC task +/*@TRACE + * llc_encrypt_ind = aes_func_res_ind */ +enum llc_msg_id +{ + LLC_MSG_ID_MSG_FIRST = TASK_FIRST_MSG(TASK_ID_LLC), + + /* + * ************** Msg LLC->LLC**************** + */ + /// Local procedure LLCP Time out + LLC_LOC_LLCP_RSP_TO = LLC_MSG_ID_MSG_FIRST, + /// Remote procedure LLCP Time out + LLC_REM_LLCP_RSP_TO, + /// Authenticated Payload timeout event + LLC_AUTH_PAYL_REAL_TO, + /// Authenticated Payload Near timeout event + LLC_AUTH_PAYL_NEARLY_TO, + /// Link is stopped, clean-up environment + LLC_STOPPED_IND, + /// Triggered when encryption has been performed + LLC_ENCRYPT_IND, + #if (BLE_CON_CTE_REQ) + /// Constant Tone Extension request timeout + LLC_CTE_REQ_TO, + #endif // (BLE_CON_CTE_REQ) + + /* + * ************ Local Procedures ************* + */ + /// Version exchange procedure + LLC_OP_VER_EXCH_IND, + /// Features exchange procedure + LLC_OP_FEATS_EXCH_IND, + /// Disconnection procedure + LLC_OP_DISCONNECT_IND, + /// Encryption procedure + LLC_OP_ENCRYPT_IND, + /// Data Length update procedure + LLC_OP_DL_UPD_IND, + /// Connection update procedure + LLC_OP_CON_UPD_IND, + /// LE Ping exchange + LLC_OP_LE_PING_IND, + /// Channel map update procedure + LLC_OP_CH_MAP_UPD_IND, + /// PHY update procedure + LLC_OP_PHY_UPD_IND, + #if (BLE_CON_CTE_REQ | BLE_CON_CTE_RSP) + /// Constant Tone Extension procedure + LLC_OP_CTE_IND, + #endif // (BLE_CON_CTE_REQ | BLE_CON_CTE_RSP) + /// Clock accuracy exchange procedure + LLC_OP_CLK_ACC_IND, + /// Periodic Advertising Sync Transfer procedure + LLC_OP_PAST_IND, +}; + + + + +/* + * STATES + **************************************************************************************** + */ +/// Procedures type definition +enum llc_proc_type +{ + /** Local initiated procedure + * + * @startuml llc_local_proc_init.png + * participant HCI + * participant LLC + * alt Procedure initiated by host + * HCI --> LLC : HCI_XXX_CMD + * LLC -> LLC: hci_xxx_cmd_handler() + * activate LLC + * note over LLC #aqua: Allocate and fill procedure message + * LLC --> LLC : LLC_OP_XXX_IND + * note right: send message to local task instance \nto flow control procedure + * LLC --> HCI : HCI_CMD_STAT_EVENT + * deactivate LLC + * else Procedure initiated by controller + * ... -> LLC: llc_xxx_proc_start() + * activate LLC + * note over LLC #aqua: Allocate and fill procedure message + * LLC --> LLC : LLC_OP_XXX_IND + * note right: send message to local task instance \nto flow control procedure + * deactivate LLC + * end + * @enduml + * + * Example of simple local procedure + * + * @startuml llc_local_proc_msc.png + * participant HCI + * participant ... + * participant LLC + * participant LLD + * ... --> LLC : LLC_OP_XXX_IND + * LLC -> LLC: llc_op_xxx_ind_handler() + * activate LLC + * hnote over LLC #lightgreen: Register Procedure\nLOCAL_PROC = busy + * LLC -> LLC: llc_op_xxx_continue(START) + * activate LLC + * note over LLC #aqua: state = WAIT_XXX_RSP\nStart transaction timer + * LLC --> LLD: LLCP_XXX_REQ + * deactivate LLC + * deactivate LLC + * ... wait for LLCP response ... + * LLD --> LLC: LLCP_XXX_RSP + * LLC -> LLC: llcp_xxx_rsp_handler() + * activate LLC + * note over LLC: copy information + * LLC -> LLC: llc_op_xxx_continue(XXX_RSP) + * activate LLC + * note over LLC #aqua: state = Done\nStop transaction timer + * hnote over LLC #lightgreen: Unregister Procedure\nLOCAL_PROC = idle + * LLC --> HCI: HCI_XXX_INFO_CMP_EVT + * deactivate LLC + * deactivate LLC + * @enduml + * + */ + LLC_PROC_LOCAL, + /** Remote initiated procedure + * + * + * Example of simple remote procedure + * + * @startuml llc_remote_proc_msc.png + * participant HCI + * participant LLC + * participant LLC_LLCP + * participant LLD + * LLD --> LLC: LLCP_XXX_REQ + * LLC -> LLC: llcp_xxx_req_handler() + * activate LLC + * hnote over LLC #lightgreen: Allocate procedure message\nRegister Procedure\nREMOTE_PROC = busy + * LLC -> LLC: llc_op_xxx_continue(START) + * activate LLC + * note over LLC #aqua: state = WAIT_HCI_XXX_RSP + * LLC --> HCI: HCI_XXX_REQ_EVT + * deactivate LLC + * deactivate LLC + * ... wait for HCI response ... + * HCI --> LLC: HCI_XXX_REQ_REPLY_CMD + * LLC -> LLC: hci_xxx_req_reply_cmd_handler() + * activate LLC + * note over LLC: copy information + * LLC --> HCI: HCI_CMD_CMP_EVT + * LLC -> LLC: llc_op_xxx_continue(HCI_XXX_RSP) + * activate LLC + * note over LLC #aqua: state = WAIT_LLCP_ACK + * LLC --> LLD: LLCP_XXX_RSP + * deactivate LLC + * deactivate LLC + * ... wait for LLCP Baseband ACK ... + * LLD --> LLC_LLCP: LLD_LLCP_TX_CFM + * LLC_LLCP -> LLC_LLCP: lld_llcp_tx_cfm_handler() + * activate LLC_LLCP + * LLC_LLCP -\ LLC: llcp_xxx_rsp_ack_handler() + * activate LLC + * LLC -> LLC: llc_op_xxx_continue(LLCP_ACK) + * activate LLC + * note over LLC #aqua: state = Done + * hnote over LLC #lightgreen: Unregister Procedure\nREMOTE_PROC = idle + * LLC -/ LLC_LLCP + * deactivate LLC + * deactivate LLC + * deactivate LLC_LLCP + * @enduml + * + */ + LLC_PROC_REMOTE, + /// Max number of operations + LLC_PROC_MAX +}; + +/// Possible states of the LLC task +enum llc_state_id +{ + /// Connection ready state + LLC_IDLE = 0x00, + /// Local procedure on-going + LLC_LOC_PROC_BUSY = (1 << LLC_PROC_LOCAL), + /// Remote procedure on-going + LLC_REM_PROC_BUSY = (1 << LLC_PROC_REMOTE), + + /// Not connected + LLC_FREE = 0xFF, +}; +// + + + +/// Procedure identifier +/*@TRACE*/ +enum llc_proc_id +{ + /// No procedure on-going + LLC_PROC_NONE, + /// Disconnection procedure + LLC_PROC_DISCONNECT, + /// Version Exchange procedure + LLC_PROC_VERSION_EXCHANGE, + /// Pause Encryption or Encryption Start procedure + LLC_PROC_ENCRYPT, + /// Feature Exchange procedure + LLC_PROC_FEATURE_EXCHANGE, + /// Connection update + LLC_PROC_CON_UPDATE, + /// Channel map update + LLC_PROC_CH_MAP_UPDATE, + /// Data Length update + LLC_PROC_DL_UPDATE, + /// LE Ping exchange + LLC_PROC_LE_PING, + /// PHY Update procedure + LLC_PROC_PHY_UPDATE, + #if (BLE_CON_CTE_REQ | BLE_CON_CTE_RSP) + /// Constant Tone Extension procedure + LLC_PROC_CTE, + #endif // (BLE_CON_CTE_REQ | BLE_CON_CTE_RSP) + /// Clock accuracy Exchange procedure + LLC_PROC_CLK_ACC, +}; + + +/// List of unexpected error received during a procedure +enum llc_error_type +{ + /// Disconnection detected + LLC_ERR_DISCONNECT, + /// LLCP Unknown PDU received + LLC_ERR_LLCP_UNKNOWN_RSP, + /// LLCP Reject PDU received + LLC_ERR_LLCP_REJECT_IND, + /// LLCP Reject Extended PDU received + LLC_ERR_LLCP_REJECT_IND_EXT, +}; + + +/** LLCP state used for some operation flow control + * + * @startuml llc_llcp_state.png + * state "IDLE" as idle + * state "PAUSE_ENC" as pause + * state "START_ENC" as enc + * state "TERMINATE" as terminate + * idle -down-> terminate : disconnect + * enc -down-> terminate : disconnect + * pause -down-> terminate : disconnect + * idle -right-> pause : re-encrypt + * idle --> enc : encrypt + * pause --> enc : paused + * enc --> idle : encrypted + * @enduml + * + */ +enum llc_llcp_state +{ + /// No specific on-going procedure + LLC_LLCP_IDLE, + /// Pause encryption procedure on-going + LLC_LLCP_PAUSE_ENC, + /// Start encryption procedure on-going + LLC_LLCP_START_ENC, + /// Link termination procedure on-going + LLC_LLCP_TERMINATE, +}; + +/// LLCP direction used to configure the flow control +enum llc_llcp_dir +{ + LLC_LLCP_DIR_RX = 0, + LLC_LLCP_DIR_TX = 1, + LLC_LLCP_DIR_BOTH = 2, +}; + +/// Bit field definitions for LLCP states +/// 7 6 5 4 3 2 1 0 +/// +----+----+----+----+----+----+----+----+ +/// | RFU | TX | RX | +/// +----+----+----+----+----+----+----+----+ +enum llc_llcp_state_bf +{ + /// RX field position + LLC_LLCP_RX_LSB = 0, + LLC_LLCP_RX_MASK = (0x3), + + /// TX field position + LLC_LLCP_TX_LSB = 2, + LLC_LLCP_TX_MASK = (0xC), +}; + + +/// Flow control bit field to flow control procedures requested by host and controller (autonomous) +/// +/// 7 6 5 4 3 2 1 0 +/// +-------+----+----+----+----+----+----+----+ +/// | L_C_UP| PHY|S_DL|C_UP|ENC |FEAT| VER|DISC| +/// +-------+----+----+----+----+----+----+----+ +/// +enum llc_flow_ctrl +{ + /// HCI Disconnect requested by host + LLC_HCI_DISCONNECT_REQ_POS = 0, + LLC_HCI_DISCONNECT_REQ_BIT = (1 << 0), + + /// HCI Read Remote Version requested by host + LLC_HCI_RD_REM_VER_REQ_POS = 1, + LLC_HCI_RD_REM_VER_REQ_BIT = (1 << 1), + + /// HCI Read Remote features requested by host + LLC_HCI_RD_REM_FEAT_REQ_POS = 2, + LLC_HCI_RD_REM_FEAT_REQ_BIT = (1 << 2), + + /// HCI Start Encryption requested by host + LLC_HCI_START_ENCRYPT_REQ_POS = 3, + LLC_HCI_START_ENCRYPT_REQ_BIT = (1 << 3), + + /// HCI Connection Update requested by host + LLC_HCI_CON_UPDATE_REQ_POS = 4, + LLC_HCI_CON_UPDATE_REQ_BIT = (1 << 4), + + /// HCI Set Data Length requested by host + LLC_HCI_SET_DATA_LEN_REQ_POS = 5, + LLC_HCI_SET_DATA_LEN_REQ_BIT = (1 << 5), + + /// HCI Set PHY requested by host + LLC_HCI_SET_PHY_REQ_POS = 6, + LLC_HCI_SET_PHY_REQ_BIT = (1 << 6), + + /// Local Connection Update requested by controller + LLC_LOC_CON_UPDATE_REQ_POS = 7, + LLC_LOC_CON_UPDATE_REQ_BIT = (1 << 7), +}; + + + + +/// Link information bit field +/// +/// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +/// +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+ +/// | | | | | | CK_A | ENC_S|CH UPD| PF_R | LDIS | ENC | INST | LV_S | PV_R | TX_O | ROLE | +/// +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+ +/// +enum llc_info +{ + /// Device is master of the link + LLC_INFO_MASTER_ROLE_POS = 0, + LLC_INFO_MASTER_ROLE_BIT = (1 << 0), + + /// LLCP buffer TX on-going + LLC_LLCP_TX_ONGOING_POS = 1, + LLC_LLCP_TX_ONGOING_BIT = (1 << 1), + + /// Peer version information received + LLC_INFO_PEER_VERSION_RECV_POS = 2, + LLC_INFO_PEER_VERSION_RECV_BIT = (1 << 2), + + /// Local version information sent + LLC_INFO_LOCAL_VERSION_SENT_POS = 3, + LLC_INFO_LOCAL_VERSION_SENT_BIT = (1 << 3), + + /// Procedure with instant on-going + LLC_INFO_INSTANT_PROC_POS = 4, + LLC_INFO_INSTANT_PROC_BIT = (1 << 4), + + /// Current Link is encrypted + LLC_INFO_LINK_ENCRYPTED_POS = 5, + LLC_INFO_LINK_ENCRYPTED_BIT = (1 << 5), + + /// Discard LLCP reception debug feature + LLC_INFO_DBG_LLCP_DISCARD_POS = 6, + LLC_INFO_DBG_LLCP_DISCARD_BIT = (1 << 6), + + /// Peer feature information received + LLC_INFO_PEER_FEATURE_RECV_POS = 7, + LLC_INFO_PEER_FEATURE_RECV_BIT = (1 << 7), + + /// Local channel map update ongoing + LLC_INFO_LOC_CH_MAP_UPD_POS = 8, + LLC_INFO_LOC_CH_MAP_UPD_BIT = (1 << 8), + + /// Encryption start ongoing + LLC_INFO_ENC_START_POS = 9, + LLC_INFO_ENC_START_BIT = (1 << 9), + + /// Accurate clock indicated + LLC_INFO_CLK_ACC_POS = 10, + LLC_INFO_CLK_ACC_BIT = (1 << 10), +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/** + * Local or Remote procedure callback used to inform if an unexpected error is raised during procedure execution + * + * @param[in] link_id Link Identifier + * @param[in] error_type Error type (@see enum llc_error_type) + * @param[in] param Parameter according to error type: + * - LLC_ERR_DISCONNECT: reason + * - LLC_ERR_LLCP_UNKNOWN_RSP: struct ll_unknown_rsp* + * - LLC_ERR_LLCP_REJECT_IND: struct ll_reject_ind* + * - LLC_ERR_LLCP_REJECT_IND_EXT: struct ll_reject_ext_ind* + */ +/*@TRACE*/ +typedef void (*llc_proc_error_cb) (uint8_t link_id, uint8_t error_type, void* param); + + + +/// Version information structure +typedef struct +{ + /// LMP version + uint8_t lmp_vers; + /// Manufacturer ID + uint16_t compid; + /// LMP subversion + uint16_t subvers; +} llc_version_t; + + +/// Information about on-going procedure +/*@TRACE*/ +typedef struct +{ + /// Unexpected Error callback + llc_proc_error_cb error_cb; + /// Procedure identifier + //@trc_ref llc_proc_id + uint8_t id; + /// Current procedure state + uint8_t state; + /// Timer procedure state, shall not be modified by procedure (@see enum llc_timer_state) + //@trc_ref llc_timer_state + uint8_t timer_state; +} llc_procedure_t; + + +/// LE Ping information +typedef struct{ + /// Authenticated payload timeout (N*10ms) + uint16_t auth_payl_to; + /// Authenticated payload timeout (N*10ms), Near timer duration + uint16_t auth_near_payl_to; +} llc_le_ping_t; + + +#if (BLE_CON_CTE_REQ) +/// CTE information +typedef struct{ + /// RX parameters received + bool param_received; + /// Sampling enable + bool sampl_en; + /// Request active + bool req_active; + /// CTE request interval (in number of connection events) + uint16_t cte_req_intv; + /// Requested CTE length (in 8us unit) + uint8_t req_cte_len; + /// Requested CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) + uint8_t req_cte_type; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; +} llc_cte_rx_t; +#endif // (BLE_CON_CTE_REQ) + +#if (BLE_CON_CTE_RSP) +/// CTE information +typedef struct{ + /// RX parameters received + bool param_received; + /// CTE TX enable + bool en; + /// Used CTE types (bit0: AOA | bit1: AOD-1us | bit2: AOD-2us) + uint8_t cte_types; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; +} llc_cte_tx_t; +#endif // (BLE_CON_CTE_RSP) + +/// Information about connection parameters +typedef struct +{ + /// Current channel map used for connection + struct le_chnl_map ch_map; + + /// Interval (in units of 1,25 ms, i.e. 2 slots) + uint16_t interval; + /// Latency (in units of event) + uint16_t latency; + /// Link supervision timeout (in units of 10 ms) + uint16_t timeout; + + // **** Data Length Management **** + ///the maximum number of octets that the local device will send to the remote device + uint16_t max_tx_octets; + ///the maximum number of octets that the local device is able to receive from the remote device + uint16_t max_rx_octets; + + ///the maximum number of microsecond that the local device will take to transmit to the remote + uint16_t max_tx_time; + ///the maximum number of microsecond that the local device can take to receive from the remote device + uint16_t max_rx_time; + + // **** PHY Management **** + /// Current TX PHY (@see enum le_phy_value) + uint8_t tx_phy; + /// Current RX PHY (@see enum le_phy_value) + uint8_t rx_phy; + + // **** Min Used Channels Management **** + /// PHY(s) for which the slave has a minimum number of used channels requirement + uint8_t min_used_ch_phys; + /// minimum number of channels to be used on the specified PHY + uint8_t min_used_ch; + +} llc_con_params_t; + +/// Information received from LL_PER_SYNC_IND +typedef struct +{ + /// SyncInfo + struct sync_info syncinfo; + /// ID (provided by the Host) + uint16_t id; + /// Connection event counter of the LLCP reception + uint16_t con_evt_cnt_rx; + /// Connection event counter + uint16_t con_evt_cnt; + /// Last periodic advertising event counter + uint16_t last_pa_evt_cnt; + /// Advertising Set ID, advertiser address type and sleep clock accuracy + uint8_t sid_atype_sca; + /// Periodic advertising PHY (@see enum le_phy_mask) + uint8_t phy; + /// Periodic advertiser address + struct bd_addr adva; + /// Periodic advertiser RPA (unresolved RPA if advertiser address is a resolved identity address, 0 otherwise) + struct bd_addr adv_rpa; + /// Sync Connection event counter + uint16_t sync_con_evt_cnt; +} llc_past_rx_info_t; + +/// Periodic advertising sync transfer parameters +typedef struct +{ + /// Information received from LL_PER_SYNC_IND (temporarily stored during address resolution) + llc_past_rx_info_t rx_info; + + // **** PAST RX **** + /// Mode (@see enum per_adv_sync_info_rec_mode) + uint8_t mode; + /// The number of periodic advertising packets that can be skipped after a successful receive + uint16_t skip; + /// Sync timeout (Time=N*10ms) + uint16_t sync_to; + /// CTE type (@see enum sync_cte_type) + uint8_t cte_type; +} llc_past_param_t; + +/// LLC environment structure +struct llc_env_tag +{ + /// Procedure Kernel message saved + llc_procedure_t* procedure[LLC_PROC_MAX]; + /// Current connection parameters + llc_con_params_t con_params; + + /// Queue of LLCP to be sent + struct co_list llcp_tx_queue; + /// Remote device feature exchange and used by the stack + struct features rem_feats; + ///version exchange env + llc_version_t rem_ver; + /// LE Ping information + llc_le_ping_t le_ping; + #if (BLE_CON_CTE_REQ) + /// CTE RX information + llc_cte_rx_t cte_rx; + #endif // (BLE_CON_CTE_REQ) + #if (BLE_CON_CTE_RSP) + /// CTE TX information + llc_cte_tx_t cte_tx; + #endif // (BLE_CON_CTE_RSP) + + /// Periodic Advertising Sync Transfer parameters + llc_past_param_t past; + + // Data Length + /// Suggested value for the Controller's maximum transmitted number of payload octets + uint16_t suggested_max_tx_octets; + /// Suggested value for the Controller's maximum packet transmission time (in us) + uint16_t suggested_max_tx_time; + /// Suggested value for the Controller's maximum received number of payload octets + uint16_t suggested_max_rx_octets; + /// Suggested value for the Controller's maximum packet reception time (in us) + uint16_t suggested_max_rx_time; + + // PHY Management + /// Phy options indicated by Host (@see enum le_phy_opt) (by default 0 if never set by Host) + uint16_t phy_opt; + /// Default TX preferred PHY to use (@see enum le_phy_mask) + uint8_t tx_phys; + /// Default RX preferred PHY to use (@see enum le_phy_mask) + uint8_t rx_phys; + + /// Information about current link status (@see enum llc_info) + uint16_t link_info; + /// Information about the current link state (@see enum llc_llcp_state) + uint8_t llcp_state; + /// Flow control information of HCI commands and local (autonomous) procedures (see enum llc_flow_ctrl) + uint8_t flow_ctrl; + /// Disconnection reason + uint8_t disc_reason; + /// Indicate L2CAP start fragment is pending + bool l2cap_start; + /// Indicate connection driver is stopping or has already stopped + bool con_stop; +}; + +/// AES function execution result +struct llc_encrypt_ind +{ + /// Status of AES execution + uint8_t status; + /// Result of the + uint8_t result[KEY_LEN]; +}; + + +/* + * GLOBAL VARIABLE DECLARATIONS + ***************************************************************************************** + */ + +/// LLC task descriptor +extern const struct ke_task_desc TASK_DESC_LLC; + +/// LLM environment variable +extern struct llc_env_tag* llc_env[]; + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Perform a Link environment variable clean-up due to disconnection or reset + * + * @param[in] link_id Link Identifier + **************************************************************************************** + */ +void llc_cleanup(uint8_t link_id, bool reset); + + +/** + **************************************************************************************** + * @brief Stop the link to ensure that all host request are correctly answered. + * + * It restore the message queue to force finishing postponed operations and then + * send a message to fully stop the link. + * + * @param[in] link_id Link Identifier + **************************************************************************************** + */ +void llc_stop(uint8_t link_id); + +#if (BLE_CENTRAL || BLE_PERIPHERAL) +/** + **************************************************************************************** + * @brief Check if the feature is supported + * + * @param[in] link_id Link identifier + * @param[in] feature Feature to check (@see enum ble_feature) + * + * @return True if peer device feature support is expected, False if not supported + **************************************************************************************** + */ +__INLINE bool llc_le_feature_check(uint8_t link_id, uint8_t feature) +{ + bool ret = false; + + if(link_id < BLE_ACTIVITY_MAX) + { + struct llc_env_tag* llc_env_ptr = llc_env[link_id]; + if(llc_env_ptr != NULL) + { + ret = ((llc_env_ptr->rem_feats.feats[feature >> 3] & (1<<(feature & 0x7))) != 0) ? true : false; + } + } + return (ret); +} + +/** + **************************************************************************************** + * @brief Set/Force if peer feature is supported + * + * @param[in] link_id Link identifier + * @param[in] feature Feature to check (@see enum ble_feature) + * @param[in] enable True to enable the feature, false else + **************************************************************************************** + */ +__INLINE void llc_le_feature_set(uint8_t link_id, uint8_t feature, bool enable) +{ + if(link_id < BLE_ACTIVITY_MAX) + { + struct llc_env_tag* llc_env_ptr = llc_env[link_id]; + if(llc_env_ptr != NULL) + { + if(enable) + { + llc_env_ptr->rem_feats.feats[feature >> 3] |= (1<<(feature & 0x7)); + } + else + { + llc_env_ptr->rem_feats.feats[feature >> 3] &= ~(1<<(feature & 0x7)); + } + } + } +} + +/** + **************************************************************************************** + * @brief Check if the link is disconnecting or not established + * + * @param[in] link_id Link identifier + * + * @return True if a link is disconnecting or already in not connected state, False else + **************************************************************************************** + */ +__INLINE bool llc_is_disconnecting(uint8_t link_id) +{ + bool res = true; + if(link_id < BLE_ACTIVITY_MAX) + { + struct llc_env_tag* llc_env_ptr = llc_env[link_id]; + if(llc_env_ptr != NULL) + { + res = (GETF(llc_env_ptr->llcp_state, LLC_LLCP_RX) == LLC_LLCP_TERMINATE); + } + } + return (res); +} +#endif //(BLE_CENTRAL || BLE_PERIPHERAL) + +/** + **************************************************************************************** + * @brief Update the link state according to on-going activity + * + * When the state goes to terminate, it cannot return to another state. + * Also when LLCP TX state is updated, LLCP module in informed to update the TX Queue list + * if some LLCP transmission are paused. + * + * LLC can set asymmetric RX/TX configuration during encryption procedures. + * When setting Idle or Terminate states, both directions shall be configured at the same time. + * + * @param[in] link_id Link identifier + * @param[in] dir Direction (0:RX | 1:TX | 2:both) + * @param[in] state New state to apply + **************************************************************************************** + */ +void llc_llcp_state_set(uint8_t link_id, uint8_t dir, uint8_t state); + + +/* ************************************************************************************ */ +/* ******************** PROCEDURE MANAGEMENT ********************** */ +/* ************************************************************************************ */ + +/** + **************************************************************************************** + * @brief Register/Start a procedure + * + * @param[in] link_id Link identifier + * @param[in] proc_type Local or Remote Procedure (@see enum llc_proc_type) + * @param[in] params Procedure parameters + **************************************************************************************** + */ +void llc_proc_reg(uint8_t link_id, uint8_t proc_type, llc_procedure_t *params); + +/** + **************************************************************************************** + * @brief Unregister/finish a procedure + * + * @param[in] link_id Link identifier + * @param[in] proc_type Local or Remote Procedure (@see enum llc_proc_type) + **************************************************************************************** + */ +void llc_proc_unreg(uint8_t link_id, uint8_t proc_type); + +/** + **************************************************************************************** + * @brief Retrieve current procedure + * + * @param[in] link_id Link identifier + * @param[in] proc_type Local or Remote Procedure (@see enum llc_proc_type) + * + * @return current procedure type or LLC_PROC_NONE if not started (@see enum llc_proc_id_type) + **************************************************************************************** + */ +uint8_t llc_proc_id_get(uint8_t link_id, uint8_t proc_type); + +/** + **************************************************************************************** + * @brief Retrieve procedure state + * + * @param[in] proc procedure + * + * @return procedure state + **************************************************************************************** + */ +uint8_t llc_proc_state_get(llc_procedure_t *proc); + +/** + **************************************************************************************** + * @brief Set the procedure state + * + * @param[in] proc procedure + * @param[in] link_id link identifier + * @param[in] proc_state new procedure state + **************************************************************************************** + */ +void llc_proc_state_set(llc_procedure_t *proc, uint8_t link_id, uint8_t proc_state); + +/** + **************************************************************************************** + * @brief Retrieve pointer on the current procedure + * + * @param[in] link_id Link identifier + * @param[in] proc_type Local or Remote Procedure (@see enum llc_proc_type) + * + * @return Pointer on the current procedure type or NULL if not used + ***************************************************************************************** + */ +llc_procedure_t * llc_proc_get(uint8_t link_id, uint8_t proc_type); + + +/** + **************************************************************************************** + * @brief Inform on-going procedure that an unexpected error event happens + * + * @param[in] link_id Link identifier + * @param[in] proc_type Local or Remote Procedure (@see enum llc_proc_type) + * @param[in] error_type Type of procedure error detected (@see enum llc_error_type) + * @param[in] param Parameter according to error type (@see llc_proc_error_cb) + ***************************************************************************************** + */ +void llc_proc_err_ind(uint8_t link_id, uint8_t proc_type, uint8_t error_type, void* param); + +/** + **************************************************************************************** + * @brief Enable or Disable Local or Remote procedure LLCP transaction timer + * + * @param[in] link_id Link identifier + * @param[in] proc_type Local or Remote Procedure (@see enum llc_proc_type) + * @param[in] enable True to enable/restart the LLCP transaction timer, False to clear it + ***************************************************************************************** + */ +void llc_proc_timer_set(uint8_t link_id, uint8_t proc_type, bool enable); + +/** + **************************************************************************************** + * @brief Pause or Resume Local or Remote procedure LLCP transaction timer + * + * (if a timer is already started, it will be paused until resume is requested, see state + * machine described in @see enum llc_timer_state) + * + * @param[in] link_id Link identifier + * @param[in] proc_type Local or Remote Procedure (@see enum llc_proc_type) + * @param[in] enable True to pause the LLCP transaction timer, False to resume it + ***************************************************************************************** + */ +void llc_proc_timer_pause_set(uint8_t link_id, uint8_t proc_type, bool enable); +/** + **************************************************************************************** + * @brief Check if a procedure is not entering in collision with another one. + * + * @param[in] link_id Link Identifier + * @param[in] proc_id New procedure to start + * + * @return CO_ERROR_NO_ERROR if no collision; + * CO_ERROR_LMP_COLLISION or CO_ERROR_DIFF_TRANSACTION_COLLISION else. + **************************************************************************************** + */ +uint8_t llc_proc_collision_check(uint8_t link_id, uint8_t proc_id); + + + + +/* ************************************************************************************ */ +/* ************************* HCI HELPERS ********************** */ +/* ************************************************************************************ */ + + +/** + **************************************************************************************** + * @brief Send HCI CC event returning a status only + * + * @param[in] link_id Link Identifier + * @param[in] opcode HCI Operation code + * @param[in] status HCI CC status code + **************************************************************************************** + */ +void llc_cmd_cmp_send(uint8_t link_id, uint16_t opcode, uint8_t status); + +/** + **************************************************************************************** + * @brief Send HCI CS event + * + * @param[in] link_id Link Identifier + * @param[in] opcode HCI Operation code + * @param[in] status HCI CS status code + **************************************************************************************** + */ +void llc_cmd_stat_send(uint8_t link_id, uint16_t opcode, uint8_t status); + + + +/* ************************************************************************************ */ +/* ************************* Procedure start ********************** */ +/* ************************************************************************************ */ + +/** + **************************************************************************************** + * @brief Immediate Disconnection + * + * @param[in] link_id Link Identifier + * @param[in] reason Reason of disconnection + * @param[in] immediate True: Try to stop event as soon as possible + * False: Wait for new connection event to be programmed + **************************************************************************************** + */ +void llc_disconnect(uint8_t link_id, uint8_t reason, bool immediate); + +/** + **************************************************************************************** + * @brief Initiate the termination procedure + * + * @param[in] link_id Link Identifier + * @param[in] reason Reason of disconnection + **************************************************************************************** + */ +void llc_init_term_proc(uint8_t link_id, uint8_t reason); + +/** + **************************************************************************************** + * @brief Set the authenticated payload timeout and compute the timer margin. + * + * @param[in] link_id Link Identifier + * @param[in] auth_payl_to Authenticated payload timeout + * + * @return CO_ERROR_NO_ERROR if succeed; CO_ERROR_INVALID_HCI_PARAM else. + **************************************************************************************** + */ +uint8_t llc_le_ping_set(uint8_t link_id, uint16_t auth_payl_to); + +/** + **************************************************************************************** + * @brief Restart the authenticated payload timeout timer (and its margin timer) + * to check if encrypted link is still alive + * + * @param[in] link_id Link Identifier + * @param[in] auth_payl_to Authenticated payload timeout + **************************************************************************************** + */ +void llc_le_ping_restart(uint8_t link_id); + +/** + **************************************************************************************** + * Start PHY update procedure + * + * @param[in] link_id Link identifier + **************************************************************************************** + */ +void phy_upd_proc_start(uint8_t link_id); + +/** + **************************************************************************************** + * Start data length update procedure + * + * @param[in] link_id Link identifier + **************************************************************************************** + */ +void dl_upd_proc_start(uint8_t link_id); + +#if BLE_CON_CTE_REQ +/** + **************************************************************************************** + * @brief Disable CTE request + * + * @param[in] link_id Link Identifier + **************************************************************************************** + */ +void llc_cte_req_dis(uint8_t link_id); +#endif // BLE_CON_CTE_REQ +#if BLE_CON_CTE_RSP +/** + **************************************************************************************** + * @brief Disable CTE response + * + * @param[in] link_id Link Identifier + **************************************************************************************** + */ +void llc_cte_rsp_dis(uint8_t link_id); +#endif // BLE_CON_CTE_RSP + +/// @} LLC + +#endif // LLC_INT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llc/llc_llcp.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llc/llc_llcp.h new file mode 100644 index 0000000..08341bd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llc/llc_llcp.h @@ -0,0 +1,125 @@ +/** + **************************************************************************************** + * + * @file llc_llcp.h + * + * @brief Functions for control pdu transmission/reception handling + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef LLC_CNTL_H_ +#define LLC_CNTL_H_ + +/** + **************************************************************************************** + * @addtogroup LLCLLCP LLCLLCP + * @ingroup LLC + * @brief Functions for control pdu transmission/reception handling + * + * This module implements the functions allowing the handling of the transmission and + * reception of the control pdu. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "co_llcp.h" + +#if (BLE_PERIPHERAL || BLE_CENTRAL) + +/* + * MACROS + **************************************************************************************** + */ + +/* + * type definition + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Callback used to inform procedure when LLCP packet transmitted has been + * baseband acknowledged + * + * @param[in] link_id Link identifier on which the pdu will be sent. + * @param[in] op_code LLCP operation code + * + **************************************************************************************** + */ +typedef void (*llc_llcp_tx_cfm_cb) (uint8_t link_id, uint8_t op_code); + +/** + **************************************************************************************** + * @brief Callback used to handle LLCP message + * + * @param[in] link_id Link identifier on which the pdu will be sent. + * @param[in] pdu LLCP PDU information received + * @param[in] event_cnt Event counter value when PDU has been received + * + * @return status code of handler: + * - CO_ERROR_NO_ERROR: Nothing more to do + * - CO_ERROR_TERMINATED_MIC_FAILURE: Immediately disconnect the link + * - others: Send an LLCP_REJECT_IND or LLCP_REJECT_IND_EXT + **************************************************************************************** + */ +typedef uint8_t (*llc_llcp_pdu_handler_func_t)(uint8_t link_id, union llcp_pdu *pdu, uint16_t event_cnt); + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Sends the programmed LLCP PDU on the given link identifier. + * + * @param[in] link_id The link identifier on which the LLCP has to be transmitted + * @param[in] pdu Pointer on the PDU to be sent + * @param[in] tx_cfm_cb Pointer to the function to call when LLCP packet TX is done. + **************************************************************************************** + */ +void llc_llcp_send(uint8_t link_id, union llcp_pdu *pdu, llc_llcp_tx_cfm_cb tx_cfm_cb); + + + +/** + **************************************************************************************** + * @brief Link state have changed, check if some pending LLCP has to be transmitted + * + * @param[in] link_id The link identifier + **************************************************************************************** + */ +void llc_llcp_tx_check(uint8_t link_id); + + +/** + **************************************************************************************** + * @brief Sends the (extended) reject indication pdu. + * + * This function allocates an sets header and parameters of the pdu before pushing it in + * the tx queue. + * + * @param[in] link_id Link identifier on which the PDU will be sent. + * @param[in] rej_opcode Rejected Operation code. + * @param[in] reason The reason to be put in the Reject Indication PDU + * @param[in] tx_cfm_cb Pointer to the function to call when LLCP packet TX is done. + **************************************************************************************** + */ +void llc_ll_reject_ind_pdu_send(uint8_t link_id, uint8_t rej_opcode, uint8_t reason, llc_llcp_tx_cfm_cb tx_cfm_cb); + +#endif // #if (BLE_PERIPHERAL || BLE_CENTRAL) + + + +/// @} LLCLLCP + +#endif // LLC_CNTL_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/lld.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/lld.h new file mode 100644 index 0000000..d37ff8b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/lld.h @@ -0,0 +1,2131 @@ +/** +**************************************************************************************** +* +* @file lld.h +* +* @brief LLD API +* +* Copyright (C) RivieraWaves 2009-2016 +* +* +**************************************************************************************** +*/ + +#ifndef LLD_H_ +#define LLD_H_ + +/** + **************************************************************************************** + * @defgroup LLD Link Driver + * @ingroup ROOT + * @brief LLD module handles the real-time job of Bluetooth operations. + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // stack configuration + +#include // integer +#include // boolean +#include // BLE standard definitions +#include "ble_util_buf.h" // BLE buffers management +#include "rwip_task.h" // Task definitions +#if (BLE_ISO_PRESENT) +#include "data_path.h" // Used for Isochronous channels +#endif // (BLE_ISO_PRESENT) + + + +/* + * DEFINES + ***************************************************************************************** + */ + +/* + * ENUMERATION DEFINITIONS + **************************************************************************************** + */ + + +/* + * MESSAGES IDENTIFIERS + **************************************************************************************** + */ + +/// Message API of the LLM task +/*@TRACE*/ +enum lld_msg_id +{ + LLD_MSG_ID_FIRST = TASK_FIRST_MSG(TASK_ID_LLD), + + /* + * ************** Msg LD->LLM**************** + */ + LLD_ADV_REP_IND, + LLD_SCAN_REQ_IND, + LLD_SYNC_START_REQ, + LLD_PER_ADV_REP_IND, + LLD_PER_ADV_RX_END_IND, + LLD_SCAN_END_IND, + LLD_ADV_END_IND, + LLD_PER_ADV_END_IND, + LLD_INIT_END_IND, + LLD_TEST_END_IND, + #if BLE_CONLESS_CTE_RX + LLD_CONLESS_CTE_RX_IND, + #endif // BLE_CONLESS_CTE_RX + + /* + * ************** Msg LLD->LLC**************** + */ + LLD_LLCP_RX_IND, + LLD_LLCP_TX_CFM, + LLD_ACL_RX_IND, + LLD_ACL_TX_CFM, + LLD_CON_PARAM_UPD_CFM, + LLD_CH_MAP_UPD_CFM, + LLD_PHY_UPD_CFM, + LLD_DISC_IND, + LLD_CON_ESTAB_IND, + LLD_CON_OFFSET_UPD_IND, + #if BLE_CON_CTE_REQ + LLD_CON_CTE_RX_IND, + #endif // BLE_CON_CTE_REQ + +}; + +/* + * MESSAGES STRUCTURES + **************************************************************************************** + */ + +/// Advertising report indication structure +/*@TRACE*/ +struct lld_adv_rep_ind +{ + /// Peer device address match + bool peer_add_match; + + /// local add Match + bool local_add_match; + + /// Address of the RAL Structure for which RPA resolution is successful + uint16_t rxralptr; + + /// Peer device address + struct bd_addr peer_id_addr; + + /// Target device address + struct bd_addr target_id_addr; + + /// Advertising Data Info field (Data ID + Set ID) + uint16_t adi; + + /// Indicate if Advertising Data Info field is present + bool adi_present; + + /// Privacy error + bool priv_err; + + /// Activity identifier + uint8_t act_id; + + /** + * Bit + * 0 Connectable advertising + * 1 Scannable advertising + * 2 Directed advertising + * 3 Scan response + * 4 Legacy advertising PDUs used + */ + uint8_t evt_type; + + /** + * Data status + * 00b Complete + * 01b Incomplete, more data to come + * 10b Incomplete, data truncated, no more to come + * 11b Reserved for future use + */ + uint8_t data_status; + + /** + * Peer address type + * 0x00 Public Device Address + * 0x01 Random Device Address + * 0xFF None - Anonymous + */ + uint8_t addr_type; + + /// RxAdd (0: Public | 1: Random) + uint8_t rx_rxadd; + + /// Primary PHY (@see enum lld_rate) + uint8_t rate1; + + /// Secondary PHY (@see enum lld_rate) + uint8_t rate2; + + // Tx Power + uint8_t tx_power; + + /// Received signal strength in dBm + int8_t rssi; + + /// Periodic advertising interval + uint16_t interval; + + /// Data length in bytes + uint8_t data_len; + + /// Chain ID (differentiate interleaved chains - chain 1, chain 2) + uint8_t chain; + + /// EM buffer to read & free. Valid if data_len != 0. + uint16_t em_buf; + + /// Data offset + uint8_t data_offset; +}; + +// SyncInfo RX request for initiating a Periodic Scan +/*@TRACE*/ +struct lld_sync_start_req +{ + /// Activity identifier + uint8_t act_id; + + // SyncInfo + struct sync_info syncinfo; + + /// The clock value of the reference time (in half-slot) + uint32_t base_cnt; + + /// The fine timer value the reference time (in half-us) + uint16_t fine_cnt; + + /// The bit rate of periodic advertising (@see enum lld_rate) + uint8_t rate; + + /// Advertising SID + uint8_t adv_sid; + + /// Address of the RAL Structure for which RPA resolution is successful + uint16_t rxralptr; + + /// Advertising address type (0: public / 1: random) + uint8_t adv_addr_type; + + /// Advertiser address + struct bd_addr adv_addr; + + /// max Skip after receive + uint16_t skip; + + /// Sync timeout (Time=N*10ms) + uint16_t sync_to; +}; + +/// Periodic advertising report indication structure +/*@TRACE*/ +struct lld_per_adv_rep_ind +{ + /// Activity identifier + uint8_t act_id; + + /// Advertiser rate (@see enum lld_rate) + uint8_t rate; + + /// Periodic advertising interval (Time=N*1.25ms) + uint16_t interval; + + /// Activity offset in slots (625 us) + uint16_t act_offset; + + /// value of the sync event counter when the packet is received + uint16_t ref_evt_cnt; + + /// Advertiser clock accuracy + uint8_t adv_ca; + + /// Tx Power + uint8_t tx_power; + + /// RSSI + int8_t rssi; + + /// Data Status + uint8_t data_status; + + /// Data length in bytes + uint8_t data_len; + + /// EM buffer to read & free. Valid if data_len != 0. + uint16_t em_buf; + + /// Data offset + uint8_t data_offset; + + /// CTE Type (0x00: A0A, 0x01: AoD 1 us, 0x02: AoD 2us, 0xFF: No CTE, All other values: RFU) + uint8_t cte_type; + + /// Used to know if ACAD data present in the received ADV packet - 0 means not present + uint8_t acad_len; + + /// offset of ACAD data content in the EM Buffer + uint8_t acad_offset; +}; + +/// Periodic advertising RX end indication structure +/*@TRACE*/ +struct lld_per_adv_rx_end_ind +{ + /// Activity identifier + uint8_t act_id; + + /// Status of the advertising sync + uint8_t status; +}; + +/// Scan request indication structure +/*@TRACE*/ +struct lld_scan_req_ind +{ + /// Activity identifier + uint8_t act_id; + + /** + * Scanner address type + * 0x00 Public Device Address + * 0x01 Random Device Address + * 0x02 Public Identity Address (Corresponds to Resolved Private Address) + * 0x03 Random (static) Identity Address (Corresponds to Resolved Private Address) + * 0x04-0xFF Reserved for future use + */ + uint8_t addr_type; + + /// Scanner address + struct bd_addr addr; +}; + +/// Advertising end indication structure +/*@TRACE*/ +struct lld_adv_end_ind +{ + /// Activity identifier + uint8_t act_id; + + /// Status (BLE error code) + uint8_t status; + + /// Access address + struct access_addr aa; + + /// CRC init + struct crc_init crcinit; + + /// Local resolvable private address used for advertising + struct bd_addr local_rpa; + + /// Peer resolvable private address of initiator or peer address indicated in CONNECT_REQ packet + struct bd_addr peer_rpa; + + /// Initiator identity address + struct bd_addr peer_id_addr; + + /// Window size (in units of 1,25 ms, i.e. 2 slots) + uint8_t winsize; + + /// Window offset (in units of 1,25 ms, i.e. 2 slots) + uint16_t winoffset; + + /// Interval (in units of 1,25 ms, i.e. 2 slots) + uint16_t interval; + + /// Latency + uint16_t latency; + + /// Timeout (in units of 10 ms, i.e. 16 slots) + uint16_t timeout; + + /// Channel mapping + struct le_chnl_map chm; + + /// Hopping increment (random value in the range of 5 to 16) + uint8_t hop_inc; + + /** + * Master Sleep clock accuracy (only for slave) + * 0 251 ppm to 500 ppm + * 1 151 ppm to 250 ppm + * 2 101 ppm to 150 ppm + * 3 76 ppm to 100 ppm + * 4 51 ppm to 75 ppm + * 5 31 ppm to 50 ppm + * 6 21 ppm to 30 ppm + * 7 0 ppm to 20 ppm + */ + uint8_t master_sca; + + /// CONNECT_REQ packet fine timer count (in us) + uint16_t fine_cnt_rxsync; + + /// CONNECT_REQ packet base timer count (timestamp, in slots) + uint32_t base_cnt_rxsync; + + /// PHY rate to be used for the connection (0: 1Mbps | 1: 2 Mbps | 2: 125 Kbps | 3: 500 Kbps) + uint8_t con_rate; + + /// Connection status (True: device connected | False: device not connected) + bool connected; + + /// Indicates whether channel selection algorithm #2 will be used or not + bool ch_sel_2; + + /** + * Peer address type + * 0x00 Public Device Address + * 0x01 Random Device Address + * 0x02 Public Identity Address (Corresponds to peer’s Resolvable Private Address) + * 0x03 Random (static) Identity Address (Corresponds to peer’s Resolvable Private Address) + * 0x04 - 0xFF Reserved for future use + */ + uint8_t peer_addr_type; + + /// Number of completed extended advertising events + uint8_t nb_ext_adv_evts; +}; + +/// Periodic advertising end indication structure +struct lld_per_adv_end_ind +{ + /// Activity identifier + uint8_t act_id; + + /// Status (BLE error code) + uint8_t status; +}; + +/// Scanning end indication structure +/*@TRACE*/ +struct lld_scan_end_ind +{ + /// Status (BLE error code) + uint8_t status; + + /// Activity identifier used for advertising + uint8_t act_id; +}; + +/// Test mode end indication structure +/*@TRACE*/ +struct lld_test_end_ind +{ + /// Status (BLE error code) + uint8_t status; + + /// Number of packets received + uint16_t nb_pkt_recv; +}; + +/// Initiating end indication structure +/*@TRACE*/ +struct lld_init_end_ind +{ + /// Activity identifier + uint8_t act_id; + + /// Connection status (True: device connected | False: device not connected) + bool connected; + + /// Local resolvable private address used for initiating + struct bd_addr local_rpa; + + /// Peer resolvable private address of advertiser or peer address indicated in ADV packet + struct bd_addr peer_rpa; + + /// Advertiser identity address + struct bd_addr peer_id_addr; + + /// access address + struct access_addr aa; + + /// Connection interval (in units of 1,25 ms, i.e. 2 slots) + uint16_t con_intv; + + /// Connection offset in slots (625 us) + uint16_t con_offset; + + /// First anchor point (timestamp, in slots) + uint32_t base_con_txwin; + + /** + * Peer address type + * 0x00 Public Device Address + * 0x01 Random Device Address + * 0x02 Public Identity Address (Corresponds to peer’s Resolvable Private Address) + * 0x03 Random (static) Identity Address (Corresponds to peer’s Resolvable Private Address) + * 0x04 - 0xFF Reserved for future use + */ + uint8_t peer_addr_type; + + /// Channel map for use on the connection + struct le_chnl_map ch_map; + + /// Index of initiating PHY used + uint8_t phy_idx; + + /// PHY rate to be used for the connection (0: 1Mbps | 1: 2 Mbps | 2: 125 Kbps | 3: 500 Kbps) + uint8_t con_rate; + + /// Connection latency + uint16_t con_latency; + + /// Connection supervision timeout in 10ms (N * 10ms) + uint16_t superv_to; + + /// CRC init + struct crc_init crcinit; + + /// Window size + uint8_t winsize; + + /// Hopping increment + uint8_t hop_inc; + + /// Master sleep clock accuracy + uint8_t m_sca; + + /// TX power of peer device + uint8_t tx_power; + + /// ADI collision - mismatch on AdvDataInfo + bool adi_collision; + + /// Indicates whether channel selection algorithm #2 will be used or not + bool ch_sel_2; +}; + +/// LLD disconnection indication structure +/*@TRACE*/ +struct lld_disc_ind +{ + /// Driver disconnection reason + uint8_t reason; +}; + +/// LLD LLCP reception indication structure +/*@TRACE*/ +struct lld_llcp_rx_ind +{ + /// Event counter when the packet has been received + uint16_t event_cnt; + /// PDU length + uint8_t length; + /// EM buffer containing PDU + uint16_t em_buf; +}; + +/// LLD ACL reception indication structure +/*@TRACE*/ +struct lld_acl_rx_ind +{ + /// EM buffer containing PDU + uint16_t em_buf; + /// Data length + Data Flags (PBF + BF) + uint16_t data_len; + /// LLID + uint8_t llid; +}; + +/// LLD connection established indication structure +/*@TRACE*/ +struct lld_con_estab_ind +{ + /// Connection offset in slots (625 us) + uint16_t con_offset; +}; + +/// LLD connection offset update indication structure +/*@TRACE*/ +struct lld_con_offset_upd_ind +{ + /// Connection offset in slots (625 us) + uint16_t con_offset; +}; + +#if BLE_CON_CTE_REQ +/// LLD connection CTE RX indication structure +/*@TRACE*/ +struct lld_con_cte_rx_ind +{ + /// RX CTE descriptor index + uint8_t em_rx_cte_desc_idx; + /// CTE time (in 8us unit) + uint8_t cte_time; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) + uint8_t cte_type; + /// Number of IQ samples + uint8_t nb_iq_samp; + /// PHY (@see enum le_phy_value) + uint8_t phy; + /// Channel index + uint8_t channel_idx; + /// RSSI (in 0.1 dBm) + int16_t rssi; + /// RSSI antenna ID + uint8_t rssi_antenna_id; + /// connEventCounter + uint16_t con_evt_cnt; +}; +#endif // BLE_CON_CTE_REQ + +#if BLE_CONLESS_CTE_RX +/// LLD connection CTE RX indication structure +/*@TRACE*/ +struct lld_conless_cte_rx_ind +{ + /// Activity identifier + uint8_t act_id; + /// RX CTE descriptor index + uint8_t em_rx_cte_desc_idx; + /// Data channel index + uint8_t channel_idx; + /// RSSI (in 0.1 dBm) + int16_t rssi; + /// RSSI antenna ID + uint8_t rssi_antenna_id; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) + uint8_t cte_type; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// paEventCounter + uint16_t pa_evt_cnt; + /// Sample_count + uint8_t sample_cnt; +}; +#endif // BLE_CONLESS_CTE_RX + +/* + * STRUCTURE DEFINITIONS + **************************************************************************************** + */ + +/// Channel assessment data +struct lld_ch_assess_data +{ + /// Timestamp of last received packet for each frequency + uint32_t timestamp[DATA_CHANNEL_NB]; + + /// Channel quality level for each frequency + int8_t level[DATA_CHANNEL_NB]; +}; + +/// Advertising parameters structure +struct lld_adv_params +{ + /// BD Address of the local device + struct bd_addr own_addr; + + /// BD Address of the peer device (only for directed advertising) + struct bd_addr peer_addr; + + /// Primary advertising interval + uint32_t prim_adv_intv; + + /// Initial advertising data buffer + uint16_t init_adv_data_buf; + + /// Initial scan response data buffer + uint16_t init_scan_rsp_data_buf; + + /// Initial advertising data length + uint16_t init_adv_data_len; + + /// Initial scan response data length + uint16_t init_scan_rsp_data_len; + + /// Advertising event properties + uint16_t adv_evt_properties; + + /// Duration (N * 10 ms), 0x0000 No advertising duration. Advertising to continue until the Host disables it. + uint16_t duration; + + /// Maximum number of extended advertising events + uint8_t max_ext_adv_evt; + + /// Primary advertising channel map + uint8_t prim_adv_ch_map; + + /** + * Local address type + * 0x00 Public Device Address (default) + * 0x01 Random Device Address + * 0x02 Controller generates Resolvable Private Address based on the local IRK from resolving list. If resolving + * list contains no matching entry, use public address. + * 0x03 Controller generates Resolvable Private Address based on the local IRK from resolving list. If resolving + * list contains no matching entry, use random address from LE_Set_Random_Address. + */ + uint8_t own_addr_type; + + /** + * Peer address type (only for directed advertising) + * 0x00 Public Device Address (default) or Public Identity Address + * 0x01 Random Device Address or Random (static) Identity Address + * 0x02 - 0xFF Reserved for future use + */ + uint8_t peer_addr_type; + + /** + * Advertising filter policy: + * 0x00 Process scan and connection requests from all devices (i.e., the White List is not in use) (default). + * 0x01 Process connection requests from all devices and only scan requests from devices that are in the White List. + * 0x02 Process scan requests from all devices and only connection requests from devices that are in the White List. + * 0x03 Process scan and connection requests only from devices in the White List. + * 0x04 - 0xFF Reserved for future use. + */ + uint8_t adv_filter_policy; + + /// Advertising Tx power + int8_t adv_tx_pwr; + + /// Primary advertising PHY + uint8_t prim_adv_phy; + + /// Secondary advertising max skip + uint8_t sec_adv_max_skip; + + /// Secondary advertising PHY + uint8_t sec_adv_phy; + + /// Advertising SID + uint8_t adv_sid; + + /// Scan request notification enable + uint8_t scan_req_notif_en; + + /// Address resolution enabled + bool addr_resolution_en; + + /// Index of the RAL entry corresponding to peer + uint8_t ral_idx; +}; + +#if BLE_CONLESS_CTE_TX +/// Periodic advertising CTE parameters structure +struct lld_per_adv_cte_params +{ + /// CTE length (in 8us unit) + uint8_t cte_len; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) + uint8_t cte_type; + /// CTE count (number of CTEs to transmit in each periodic advertising interval, range 0x01 to 0x10) + uint8_t cte_count; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[BLE_MAX_SW_PAT_LEN]; +}; +#endif // BLE_CONLESS_CTE_TX + +/// Periodic advertising parameters structure +struct lld_per_adv_params +{ + /// Periodic advertising interval expressed in units of 1.25 ms + uint16_t per_adv_intv; + + /// Periodic advertising properties + uint16_t per_adv_properties; + + /// Initial periodic advertising data buffer + uint16_t init_adv_data_buf; + + /// Initial periodic advertising data length + uint16_t init_adv_data_len; + + /// Periodic advertising offset in slots (625 us) + uint16_t per_adv_offset; + + /** + * Local address type + * 0x00 Public Device Address (default) + * 0x01 Random Device Address + * 0x02 Controller generates Resolvable Private Address based on the local IRK from resolving list. If resolving + * list contains no matching entry, use public address. + * 0x03 Controller generates Resolvable Private Address based on the local IRK from resolving list. If resolving + * list contains no matching entry, use random address from LE_Set_Random_Address. + */ + uint8_t own_addr_type; + + /// Periodic advertising Tx power + int8_t adv_tx_pwr; + + /// Secondary advertising PHY + uint8_t sec_adv_phy; + + #if BLE_CONLESS_CTE_TX + struct lld_per_adv_cte_params cte_params; + #endif // BLE_CONLESS_CTE_TX +}; + +/// Scanning parameters structure +struct lld_scan_params +{ + /// BD Address of the local device + struct bd_addr own_addr; + + /// Extended scanning + bool ext_scan; + + /// Scanning PHYs (bit0: 1M PHY, bit2: coded PHY) + uint8_t scan_phys; + + /// Scan interval in slots (625 us) + uint16_t intv_1m; // 1M PHY + uint16_t intv_c; // coded PHY + + /// Scan window in slots (625 us) + uint16_t win_1m; // 1M PHY + uint16_t win_c; // coded PHY + + /** + * Scanning type + * 0x00 Passive Scanning. No SCAN_REQ packets shall be sent (default) + * 0x01 Active scanning. SCAN_REQ packets may be sent. + * 0x02 - 0xFF Reserved for future use + */ + uint8_t type_1m; // 1M PHY + uint8_t type_c; // coded PHY + + /** + * Local address type + * 0x00 Public Device Address (default) + * 0x01 Random Device Address + * 0x02 Controller generates Resolvable Private Address based on the local IRK from resolving list. If resolving + * list contains no matching entry, use public address. + * 0x03 Controller generates Resolvable Private Address based on the local IRK from resolving list. If resolving + * list contains no matching entry, use random address from LE_Set_Random_Address. + */ + uint8_t own_addr_type; + + /** + * Scan filter policy: + * 0x00 Accept all + * - advertisement packets except directed advertising packets not addressed to this device (default) + * 0x01 Accept only + * - advertisement packets from devices where the advertiser’s address is in the White list. + * - Directed advertising packets which are not addressed for this device shall be ignored. + * 0x02 Accept all + * - undirected advertisement packets, and + * - directed advertising packets where the initiator address is a resolvable private address, and + * - directed advertising packets addressed to this device. + * 0x03 Accept all + * - advertisement packets from devices where the advertiser’s address is in the White list, and + * - directed advertising packets where the initiator address is a resolvable private address, and + * - directed advertising packets addressed to this device. + * 0x04 - 0xFF Reserved for future use. + */ + uint8_t filter_policy; + + /// Address resolution enabled + bool addr_resolution_en; + + /// Scan duration (N * 10 ms) | 0x0000: Scan continuously until explicitly disable + uint16_t duration; +}; + +#if BLE_CONLESS_CTE_RX +/// Sync CTE parameters structure +struct lld_sync_cte_params +{ + /// Sampling enable + uint8_t sampl_en; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Max sampled CTEs + uint8_t max_sampl_cte; + /// Length of switching pattern + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[BLE_MAX_SW_PAT_LEN]; +}; +#endif // BLE_CONLESS_CTE_RX + +/// Sync parameters structure +struct lld_sync_params +{ + // SyncInfo + const struct sync_info* p_syncinfo; + + /// The clock value of the reference time (in half-slot) + uint32_t base_cnt; + + /// The fine timer value the reference time (in half-us) + uint16_t fine_cnt; + + /// The bit rate of periodic advertising (@see enum lld_rate) + uint8_t rate; + + /// Advertising SID + uint8_t adv_sid; + + /// max Skip after receive + uint16_t skip; + + /// Sync timeout (Time=N*10ms) + uint16_t sync_to; + + /// Additional drift to consider on given time reference (in half-us) + uint16_t add_drift; + + /// Specifies whether to only synchronize to periodic advertising with certain types of CTE (@see enum sync_cte_type) + uint8_t sync_cte_type; +}; + +/// Initiating parameters PHY sub-structure +struct lld_init_phy_params +{ + /// Scan interval in slots (625 us) + uint16_t intv; + + /// Scan window in slots (625 us) + uint16_t win; + + /// Connection interval (in units of 1,25 ms, i.e. 2 slots) + uint16_t con_intv; + + /// Connection offset in slots (625 us) + uint16_t con_offset; + + /// Connection latency + uint16_t con_latency; + + /// Connection supervision timeout in 10ms (N * 10ms) + uint16_t superv_to; +}; + +/// Initiating parameters structure +struct lld_init_params +{ + /// BD Address of the local device + struct bd_addr own_addr; + + /// BD Address of the peer device (only if White List is not used) + struct bd_addr peer_addr; + + /// Channel map to use for the connection + struct le_chnl_map ch_map; + + /// Extended initiating + bool ext_init; + + /// Scanning PHYs (bit0: 1M PHY, bit1: 2M PHY, bit2: coded PHY) + uint8_t init_phys; + + /// Activity identifier + uint8_t act_id; + + /** + * Local address type + * 0x00 Public Device Address (default) + * 0x01 Random Device Address + * 0x02 To generate RPA from resolving list. If no matching entry, use public address. + * 0x03 To generate RPA from resolving list. If no matching entry, use random address. + */ + uint8_t own_addr_type; + + /** + * Peer address type (only if White List is not used) + * 0x00 Public Device Address + * 0x01 Random Device Address + * 0x02 - 0xFF Reserved for future use + */ + uint8_t peer_addr_type; + + /** + * Initiator filter policy: + * 0x00 White list is not used to determine which advertiser to connect to. Peer_Address_Type and Peer_Address + * shall be used. + * 0x01 White list is used to determine which advertiser to connect to. Peer_Address_Type and Peer_Address shall + * be ignored. + * 0x02 - 0xFF Reserved for future use. + */ + uint8_t filter_policy; + + /** + * Parameters for Initiating PHY(s) + * The parameters are ordered in the same order as the set bits in the init_phys parameter, starting from bit 0. + * The number of elements is determined by the number of bits set in the Initiating_PHYs parameter. + */ + struct lld_init_phy_params phy[MAX_INIT_PHYS]; + + /// Address resolution enabled + bool addr_resolution_en; +}; + +/// Connection parameters structure +struct lld_con_params +{ + /// Access address + struct access_addr aa; + + /// CRC init + struct crc_init crcinit; + + /// Window size (in units of 1,25 ms, i.e. 2 slots) + uint8_t winsize; + + /// Window offset (in units of 1,25 ms, i.e. 2 slots) + uint16_t winoffset; + + /// Interval (in units of 1,25 ms, i.e. 2 slots) + uint16_t interval; + + /// Latency + uint16_t latency; + + /// Timeout (in units of 10 ms, i.e. 16 slots) + uint16_t timeout; + + /// Channel mapping + struct le_chnl_map chm; + + /// Hopping increment (random value in the range of 5 to 16) + uint8_t hop_inc; + + /** + * Master Sleep clock accuracy (only for slave) + * 0 251 ppm to 500 ppm + * 1 151 ppm to 250 ppm + * 2 101 ppm to 150 ppm + * 3 76 ppm to 100 ppm + * 4 51 ppm to 75 ppm + * 5 31 ppm to 50 ppm + * 6 21 ppm to 30 ppm + * 7 0 ppm to 20 ppm + */ + uint8_t master_sca; + + /// CONNECT_REQ packet fine timer count (in half-us) + uint16_t fine_cnt_rxsync; + + /// CONNECT_REQ packet base timer count (timestamp, in half-slots) + uint32_t base_cnt_rxsync; + + /// First anchor point timestamp (in half-slots, master only) + uint32_t first_anchor_ts; + + /// Role (0: Master | 1: Slave) + uint8_t role; + + /// Connection transmit/receive rate (@see enum lld_rate) + uint8_t rate; + + /// Indicates whether channel selection algorithm #2 will be used or not + bool ch_sel_2; + + /// Indicates whether the AUX_CONNECT_REQ PDU was used or not (true for AUX_CONNECT_REQ, false for CONNECT_IND) + bool aux_connect_req; +}; + +#if (BLE_ISO_MODE_0) +/// Audio parameters structure +struct lld_con_audio_params +{ + /// Reception Data Path : pointer must be filled + const struct data_path_itf* rx_dp; + /// Transmission Data Path : pointer must be filled + const struct data_path_itf* tx_dp; + /// Configure transmitter size in bytes + uint8_t tx_size; + /// Configure receiver size in bytes + uint8_t rx_size; + /// Salve audio source enabled + bool slv_src_enable; +}; +#endif //(BLE_ISO_MODE_0) + +/// Test mode parameters structure +struct lld_test_params +{ + /// Type (0: RX | 1: TX) + uint8_t type; + + /// RF channel, N = (F - 2402) / 2 + uint8_t channel; + + /// Length of test data + uint8_t data_len; + + /** + * Packet payload + * 0x00 PRBS9 sequence "11111111100000111101" (in transmission order) as described in [Vol 6] Part F, Section 4.1.5 + * 0x01 Repeated "11110000" (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x02 Repeated "10101010" (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x03 PRBS15 sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x04 Repeated "11111111" (in transmission order) sequence + * 0x05 Repeated "00000000" (in transmission order) sequence + * 0x06 Repeated "00001111" (in transmission order) sequence + * 0x07 Repeated "01010101" (in transmission order) sequence + * 0x08-0xFF Reserved for future use + */ + uint8_t payload; + + /** + * Tx/Rx PHY + * For Tx PHY: + * 0x00 Reserved for future use + * 0x01 LE 1M PHY + * 0x02 LE 2M PHY + * 0x03 LE Coded PHY with S=8 data coding + * 0x04 LE Coded PHY with S=2 data coding + * 0x05-0xFF Reserved for future use + * For Rx PHY: + * 0x00 Reserved for future use + * 0x01 LE 1M PHY + * 0x02 LE 2M PHY + * 0x03 LE Coded PHY + * 0x04-0xFF Reserved for future use + */ + uint8_t phy; + + /** + * CTE length + * 0x00 No Constant Tone Extension + * 0x02 - 0x14 Length of the Constant Tone Extension in 8 us units + * All other values Reserved for future use + */ + uint8_t cte_len; + + /** + * CTE type + * 0x00 AoA Constant Tone Extension + * 0x01 AoD Constant Tone Extension with 1 us slots + * 0x02 AoD Constant Tone Extension with 2 us slots + * All other values Reserved for future use + */ + uint8_t cte_type; + + /** + * Slot durations + * 0x01 Switching and sampling slots are 1 us each + * 0x02 Switching and sampling slots are 2 us each + * All other values Reserved for future use + */ + uint8_t slot_dur; + + /** + * Length of switching pattern + * 0x02 - 0x4B The number of Antenna IDs in the pattern + * All other values Reserved for future use + */ + uint8_t switching_pattern_len; + + /// Antenna IDs + uint8_t antenna_id[BLE_MAX_SW_PAT_LEN]; +}; + +/* + * EXPORTED VARIABLES DECALRATION + **************************************************************************************** + */ + +/* + * FUNCTIONS DECLARATION + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize the LLD module + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void lld_init(uint8_t init_type); + +/** + * *************************************************************************************** + * @brief Read BLE clock + * + * @return Clock value (in half-slots, i.e. units of 312.5 us) + **************************************************************************************** + */ +uint32_t lld_read_clock(void); + +/** + **************************************************************************************** + * @brief Get local SCA + * + * @return local_sca Local SCA, physical low power clock accuracy (@see enum SCA) + **************************************************************************************** + */ +uint8_t lld_local_sca_get(void); + + +/** + **************************************************************************************** + * @brief Get channel assessment + * + * @return Pointer to channel assessment data + **************************************************************************************** + */ +struct lld_ch_assess_data* lld_ch_assess_data_get(void); + +/** + * *************************************************************************************** + * @brief Renew the resolvable private addresses + **************************************************************************************** + */ +void lld_rpa_renew(void); + +/** + **************************************************************************************** + * @brief Add a device to white list + * + * @param[in] position Position of the device in the list + * @param[in] bd_addr BD Address + * @param[in] bd_addr_type BD Address type (0: public | 1: random | 0xFF: anonymous adv) + **************************************************************************************** + */ +void lld_white_list_add(uint8_t position, struct bd_addr *bd_addr, uint8_t bd_addr_type); + +/** + **************************************************************************************** + * @brief Remove a device from white list + * + * @param[in] position Position of the device in the list + * @param[in] bd_addr BD Address + * @param[in] bd_addr_type BD Address type (0: public | 1: random | 0xFF: anonymous adv) + **************************************************************************************** + */ +void lld_white_list_rem(uint8_t position, struct bd_addr *bd_addr, uint8_t bd_addr_type); + +/** + **************************************************************************************** + * @brief Add a device to periodic advertiser list + * + * @param[in] position Position of the device in the list + * @param[in] bd_addr BD Address + * @param[in] bd_addr_type BD Address type (0: public | 1: random) + * @param[in] adv_sid Advertising Set ID + **************************************************************************************** + */ +void lld_per_adv_list_add(uint8_t position, struct bd_addr *bd_addr, uint8_t bd_addr_type, uint8_t adv_sid); + +/** + **************************************************************************************** + * @brief Remove a device from periodic advertiser list + * + * @param[in] position Position of the device in the list + * @param[in] bd_addr BD Address + * @param[in] bd_addr_type BD Address type (0: public | 1: random) + * @param[in] adv_sids Bit field of advertising Set IDs to remove, 1 bit per ADV_SID + **************************************************************************************** + */ +void lld_per_adv_list_rem(uint8_t position, struct bd_addr *bd_addr, uint8_t bd_addr_type, uint16_t adv_sids); + +/** + **************************************************************************************** + * @brief Clear resolving list + **************************************************************************************** + */ +void lld_res_list_clear(void); + +/** + **************************************************************************************** + * @brief Add a device to resolving list + * + * @param[in] position Position in RAL + * @param[in] bd_addr Peer's BD Address + * @param[in] peer_irk Peer identification resolving key + * @param[in] localr_irk Local identification resolving key + * @param[in] bd_addr_type Peer's BD Address type (0: public | 1: random) + * @param[in] connected True: device is connected | false: not connected + * @param[in] in_wl True: device is in white list | false: not in white list + **************************************************************************************** + */ +void lld_res_list_add(uint8_t position, struct bd_addr const *bd_addr, struct irk const *peer_irk, struct irk const *local_irk, uint8_t bd_addr_type, bool connected, bool in_wl); + +/** + **************************************************************************************** + * @brief Remove a device from resolving list + * + * @param[in] position Position in RAL + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +void lld_res_list_rem(uint8_t position); + +/** + **************************************************************************************** + * @brief Update status of a device privacy: network privacy or device privacy + * + * @param[in] position Position in RAL + * @param[in] privacy_mode 0: network privacy / 1: device privacy + **************************************************************************************** + */ +void lld_res_list_priv_mode_update(uint8_t position, uint8_t privacy_mode); + +/** + **************************************************************************************** + * @brief Update status of a device connected or disconnected + * + * @param[in] position Position in RAL + * @param[in] connected True: device connected / False: device disconnected + **************************************************************************************** + */ +void lld_res_list_peer_update(uint8_t position, bool connected); + +/** + **************************************************************************************** + * @brief Get the current peer resolvable address used for a peer device + * + * @param[in] position Position in RAL + * @param[out] peer_res_addr Peer resolvable address + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_res_list_peer_rpa_get(uint8_t position, struct bd_addr *peer_res_addr); + +/** + **************************************************************************************** + * @brief Get the current local resolvable address used for a peer device + * + * @param[in] position Position in RAL + * @param[out] local_res_addr Local resolvable address + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_res_list_local_rpa_get(uint8_t position, struct bd_addr *local_res_addr); + + +#if (BLE_BROADCASTER) +/** + **************************************************************************************** + * @brief Start Advertising + * + * @param[in] act_id Activity identifier + * @param[in] params Pointer to extended advertising parameters structure + * + * @return status 0: success | 1-255: error (BLE error code) + **************************************************************************************** + */ +uint8_t lld_adv_start(uint8_t act_id, struct lld_adv_params* params); + +/** + **************************************************************************************** + * @brief Stop Advertising + * + * @param[in] act_id Activity identifier + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_adv_stop(uint8_t act_id); + +/** + **************************************************************************************** + * @brief Update Advertising data + * + * Note: the Host can only update the advertising data less than 252 bytes (see HCI:7.8.54) + * + * @param[in] act_id Activity identifier + * @param[in] len Length of the data, in range [0:252] + * @param[in] buffer EM buffer containing the data + **************************************************************************************** + */ +void lld_adv_adv_data_update(uint8_t act_id, uint8_t len, uint16_t buffer); + +/** + **************************************************************************************** + * @brief Update advertising duration + * + * @param[in] act_id Activity identifier + * @param[in] duration Advertising duration (N * 10 ms) | 0x0000: infinite + **************************************************************************************** + */ +void lld_adv_duration_update(uint8_t act_id, uint16_t duration); + +/** + **************************************************************************************** + * @brief Update advertising random address + * + * @param[in] act_id Activity identifier + * @param[in] addr Random address + **************************************************************************************** + */ +void lld_adv_rand_addr_update(uint8_t act_id, struct bd_addr addr); + +/** + **************************************************************************************** + * @brief Reset the event count, update the duration and the maximum number of extended advertising events + * + * @param[in] act_id Activity identifier + * @param[in] duration Advertising duration (N * 10 ms) | 0x0000: infinite + * @param[in] max_ext_adv_evt Maximum number of extended advertising events + **************************************************************************************** + */ +void lld_adv_restart(uint8_t act_id, uint16_t duration, uint8_t max_ext_adv_evt); + +/** + **************************************************************************************** + * @brief Update Scan response data + * + * Note: the Host may can only update the advertising data less than 252 bytes (see HCI:7.8.55) + * + * @param[in] act_id Activity identifier + * @param[in] len Length of the data, in range [0:252] + * @param[in] buffer EM buffer containing the data + **************************************************************************************** + */ +void lld_adv_scan_rsp_data_update(uint8_t act_id, uint8_t len, uint16_t buffer); + +/** + **************************************************************************************** + * @brief Read the TX power used for advertising + * + * @param[in] act_id Activity identifier + * + * @return Used TX power in dBm, signed integer, range between -70dBm and 20dBm. + **************************************************************************************** + */ +uint8_t lld_adv_tx_pwr_get(uint8_t act_id); + +/** + **************************************************************************************** + * @brief Start Periodic advertising + * + * @param[in] act_id Activity identifier + * @param[in] params Pointer to extended advertising parameters structure + * + * @return status 0: success | 1-255: error (BLE error code) + **************************************************************************************** + */ +uint8_t lld_per_adv_start(uint8_t act_id, struct lld_per_adv_params* params); + +/** + **************************************************************************************** + * @brief Stop Periodic advertising + * + * @param[in] act_id Activity identifier + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_per_adv_stop(uint8_t act_id); + +/** + **************************************************************************************** + * @brief Update Periodic advertising data + * + * Note: the Host may can only update the advertising data less than 252 bytes (see HCI:7.8.54) + * + * @param[in] act_id Activity identifier + * @param[in] len Length of the data, in range [0:252] + * @param[in] buffer EM buffer containing the data + **************************************************************************************** + */ +void lld_per_adv_data_update(uint8_t act_id, uint8_t len, uint16_t buffer); + + +/** + **************************************************************************************** + * @brief Initiate periodic advertising channel map update + * + * @param[in] act_id Activity ID + * @param[in] map New channel map to be applied + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_per_adv_ch_map_update(uint8_t act_id, struct le_chnl_map *map); + +/** + **************************************************************************************** + * @brief Get info from a periodic advertiser + * + * @param[in] act_id Activity ID + * @param[out] phy Periodic advertising PHY (@see enum lld_rate) + * @param[out] intv Periodic advertising interval in units of 1.25 ms + * @param[out] aa Periodic advertising Access Address + * @param[out] crcinit Periodic advertising CRC Initialization value + * @param[out] sync_ind_ts Timestamp of the AUX_SYNC_IND packet (in 312.5 us half-slots) + * @param[out] pa_evt_cnt Corresponding paEventCounter value (in half-us) + * @param[out] map Corresponding channel map + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_per_adv_info_get(uint8_t act_id, uint8_t* phy, uint16_t* intv, struct access_addr* aa, struct crc_init* crcinit, uint32_t* sync_ind_ts, uint16_t* pa_evt_cnt, struct le_chnl_map *map); + +/** + **************************************************************************************** + * @brief Set the connectionless LLD channel map + * + * @param[in] map New channel map for connectionless activities + **************************************************************************************** + */ +void lld_ch_map_set(const struct le_chnl_map *map); + +/** + **************************************************************************************** + * @brief Update extended advertising sync info + * + * @param[in] act_id Extended advertising activity identifier + * @param[in] per_adv_id Periodic advertising activity identifier + * @param[in] per_adv_interval Periodic advertising interval + **************************************************************************************** + */ +void lld_adv_sync_info_update(uint8_t act_id, uint8_t per_adv_id, uint16_t per_adv_interval); + +#if BLE_CONLESS_CTE_TX +/** + **************************************************************************************** + * @brief Start Periodic advertising CTE Tx + * + * @param[in] act_id Activity identifier + * @param[in] params Pointer to periodic advertising CTE parameters structure + * + * @return status 0: success | 1-255: error (BLE error code) + **************************************************************************************** + */ +uint8_t lld_per_adv_cte_start(uint8_t act_id, struct lld_per_adv_cte_params* params); + +/** + **************************************************************************************** + * @brief Stop Periodic advertising CTE Tx + * + * @param[in] act_id Activity identifier + * + * @return status 0: success | 1-255: error (BLE error code) + **************************************************************************************** + */ +uint8_t lld_per_adv_cte_stop(uint8_t act_id); +#endif // BLE_CONLESS_CTE_TX +#endif // (BLE_BROADCASTER) + +#if (BLE_OBSERVER) +/** + **************************************************************************************** + * @brief Start Scanning + * + * @param[in] act_id Activitiy ID + * @param[in] params Pointer to Scanning parameters structure + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_scan_start(uint8_t act_id, struct lld_scan_params* params); + +/** + **************************************************************************************** + * @brief Stop Scanning + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_scan_stop(void); + +/** + **************************************************************************************** + * @brief Update scanning parameters + * + * @param[in] duration Scan duration (N * 10 ms) | 0x0000: Scan continuously until explicitly disable + * @param[in] period Scan period (N * 1.28 sec) | 0x0000: Periodic scanning disabled + * @param[in] bd_addr new random address | NULL: no update + **************************************************************************************** + */ +uint8_t lld_scan_params_update(uint16_t duration, uint16_t period, struct bd_addr *bd_addr); + +/** + **************************************************************************************** + * @brief Restart Scanning + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_scan_restart(void); + +/** + **************************************************************************************** + * @brief Start Periodic Advertising RX (Create Sync) + * + * @param[in] act_id Activity ID + * @param[in] options Sync options (@see enum per_sync_opt) + * @param[in] adv_sid Advertising SID + * @param[in] adv_addr_type Advertising address type + * @param[in] adv_addr Advertiser address + * + * @return status 0: success | 1-255: error (BLE error code) + **************************************************************************************** + */ +uint8_t lld_scan_create_sync(uint8_t act_id, uint8_t options, uint8_t adv_sid, uint8_t adv_addr_type, struct bd_addr * adv_addr); + +/** + **************************************************************************************** + * @brief Stop Create Sync for Periodic Scan Rx (Cancel Sync) + * + * @param[in] act_id Activity ID + * + * @return status 0: success | 1-255: error (BLE error code) + **************************************************************************************** + */ +uint8_t lld_scan_create_sync_cancel(uint8_t act_id); + +/** + **************************************************************************************** + * @brief Start Periodic Advertising Rx + * + * @param[in] act_id Activity ID + * @param[in] params Pointer to Scanning parameters structure + * + * @return status 0: success | 1-255: error (BLE error code) +**************************************************************************************** +*/ +uint8_t lld_sync_start(uint8_t act_id, struct lld_sync_params* params); + +/** + **************************************************************************************** + * @brief Update channel map on a periodic advertiser + * + * @param[in] act_id Activity ID + * @param[in] map Pointer to the new channel map to be applied + * @param[in] instant Instant when the new channel map has to be applied + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_sync_ch_map_update(uint8_t act_id, struct le_chnl_map *map, uint16_t instant); + +/** + **************************************************************************************** + * @brief Stop Periodic Advertising RX (Terminate Sync) + * + * @param[in] act_id Activity ID + * + * @return status 0: success | 1-255: error (BLE error code) + **************************************************************************************** + */ +uint8_t lld_sync_stop(uint8_t act_id); + +#if BLE_CONLESS_CTE_RX +/** + **************************************************************************************** + * @brief Start Periodic advertising IQ sampling + * + * @param[in] act_id Activity identifier + * @param[in] params Pointer to periodic advertising CTE parameters structure + * + * @return status 0: success | 1-255: error (BLE error code) + **************************************************************************************** + */ +uint8_t lld_sync_cte_start(uint8_t act_id, struct lld_sync_cte_params* params); + +/** + **************************************************************************************** + * @brief Stop Periodic advertising IQ sampling + * + * @param[in] act_id Activity identifier + * + * @return status 0: success | 1-255: error (BLE error code) + **************************************************************************************** + */ +uint8_t lld_sync_cte_stop(uint8_t act_id); +#endif // BLE_CONLESS_CTE_RX + +#endif // (BLE_OBSERVER) + + + +#if (BLE_CENTRAL) +/** + **************************************************************************************** + * @brief Start Initiating + * + * @param[in] params Pointer to Initiating parameters structure + * + * @return status 0: success | 1-255: error (BLE error code) + **************************************************************************************** + */ +uint8_t lld_init_start(struct lld_init_params* params); + +/** + **************************************************************************************** + * @brief Stop Initiating + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_init_stop(void); + +#endif // (BLE_CENTRAL) + + +#if (BLE_CENTRAL || BLE_PERIPHERAL) +/** + **************************************************************************************** + * @brief Start link + * + * @param[in] link_id Link identifier + * @param[in] params Pointer to Connection parameters structure + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_start(uint8_t link_id, struct lld_con_params* params); + +/** + **************************************************************************************** + * @brief Stop link + * + * @param[in] link_id Link identifier + * @param[in] immediate Immediate execution of the event stop + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_stop(uint8_t link_id, bool immediate); + +/** + **************************************************************************************** + * @brief Send an LLCP packet + * + * @param[in] link_id Link identifier + * @param[in] buf_elt Buffer element of the LLCP to send + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_llcp_tx(uint8_t link_id, struct ble_em_llcp_buf_elt* buf_elt); + +/** + **************************************************************************************** + * @brief Send an ACL packet + * + * @param[in] link_id Link identifier + * @param[in] buf_elt Buffer element of the data to send + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_data_tx(uint8_t link_id, struct ble_em_acl_buf_elt* buf_elt); + +/** + **************************************************************************************** + * @brief Set ACL data flow + * + * @param[in] link_id Link identifier + * @param[in] enable True: data flow ON / False: data flow OFF + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_data_flow_set(uint8_t link_id, bool enable); + +/** + **************************************************************************************** + * @brief Update link parameters + * + * @param[in] link_id Link identifier + * @param[in] win_size Window size (in units of 1,25 ms, i.e. 2 slots) + * @param[in] win_off Window offset (in units of 1,25 ms, i.e. 2 slots) + * @param[in] interval Interval (in units of 1,25 ms, i.e. 2 slots) + * @param[in] latency Slave latency + * @param[in] timeout Timeout (in units of 10 ms, i.e. 16 slots) + * @param[in] instant Instant when the new parameters have to be applied (when connection event counter equals the instant) + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_param_update(uint8_t link_id, uint8_t win_size, uint16_t win_off, uint16_t interval, uint16_t latency, + uint16_t timeout, uint16_t instant); + +/** + **************************************************************************************** + * @brief Update channel map + * + * @param[in] link_id Link identifier + * @param[in] map Pointer to the new channel map to be applied + * @param[in] instant Instant when the new channel map has to be applied (when connection event counter equals the instant) + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_ch_map_update(uint8_t link_id, struct le_chnl_map *map, uint16_t instant); + +/** + **************************************************************************************** + * @brief Update data length + * + * @param[in] link_id Link identifier + * @param[in] eff_tx_time Maximum effective transmit time (in us) + * @param[in] eff_tx_octets Maximum effective transmit size (in bytes) + * @param[in] eff_rx_time Maximum effective receive time (in us) + * @param[in] eff_rx_octets Maximum effective receive size (in bytes) + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_data_len_update(uint8_t link_id, uint16_t eff_tx_time, uint16_t eff_tx_octets, uint16_t eff_rx_time, uint16_t eff_rx_octets); + +/** + **************************************************************************************** + * @brief Update PHYs + * + * @param[in] link_id Link identifier + * @param[in] tx_rate Transmit rate to be set (@see enum lld_rate) + * @param[in] rx_rate Receive rate to be set (@see enum lld_rate) + * @param[in] instant Instant where the new rates have to be applied (when connection event counter equals the instant) + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_phys_update(uint8_t link_id, uint8_t tx_rate, uint8_t rx_rate, uint16_t instant); + +/** + **************************************************************************************** + * @brief Update TX length as per the new connection interval + * + * @param[in] link_id Link identifier + * @param[in] interval Interval (in units of 1,25 ms, i.e. 2 slots) + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_tx_len_update_for_intv(uint8_t link_id, uint16_t interval); + +/** + **************************************************************************************** + * @brief Update TX length as per the new TX rate + * + * @param[in] link_id Link identifier + * @param[in] tx_rate Transmit rate to be set (@see enum lld_rate) + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_tx_len_update_for_rate(uint8_t link_id, uint8_t tx_rate); + +/** + **************************************************************************************** + * @brief Gets current event counter + * + * @param[in] link_id Link identifier + * + * @return Current event counter value + **************************************************************************************** + */ +uint16_t lld_con_event_counter_get(uint8_t link_id); + +/** + **************************************************************************************** + * Compute offset between a connection instant and another activity event with provided + * interval reference that follows + * + * @param[in] link_id Link Identifier + * @param[in] evt_cnt Reference connection event counter + * @param[in] interval Activity interval (1.25ms unit) + * @param[in] act_offset Activity Offset (625us unit) + * + * @return Computed offset with connection interval and provided interval (us unit) + **************************************************************************************** + */ +int32_t lld_con_activity_offset_compute(uint8_t link_id, uint16_t evt_cnt, uint16_t interval, uint16_t act_offset); + +/** + * Compute planning activity offset of the activity to create according to a specific offset range in us. + * + * @param[in] link_id Link Identifier + * @param[in] evt_cnt Reference connection event counter + * @param[in] interval Activity interval (1.25ms unit) + * @param[in|out] offset_min New activity minimum offset in us after connection reference + * @param[in|out] offset_max New activity maximum offset in us after connection reference + * + * @return Computed Activity offset in slots + */ +uint16_t lld_con_activity_act_offset_compute(uint8_t link_id, uint16_t evt_cnt, uint16_t interval, + uint32_t *offset_min, uint32_t *offset_max); + +/** + **************************************************************************************** + * @brief Set encryption mode in TX direction + * + * @param[in] link_id Link identifier + * @param[in] enable false: disabled | true: enabled + **************************************************************************************** + */ +void lld_con_tx_enc(uint8_t link_id, bool enable); + +/** + **************************************************************************************** + * @brief Set encryption mode in RX direction + * + * @param[in] link_id Link identifier + * @param[in] enable false: disabled | true: enabled + **************************************************************************************** + */ +void lld_con_rx_enc(uint8_t link_id, bool enable); + +/** + **************************************************************************************** + * @brief Load encryption Key + * + * @param[in] link_id Link identifier + * @param[in] key Encryption key + * @param[in] iv Initialization Vector (for AES encryption only) + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +void lld_con_enc_key_load(uint8_t link_id, struct ltk *key, struct initialization_vector *iv); + +/** + **************************************************************************************** + * @brief Get the current TX power + * + * @param[in] link_id Link identifier + * @param[in] modulation Modulation (1:GFSK | 2:DQPSK | 3:8DPSK) + * + * @return Current TX power in dBm + **************************************************************************************** + */ +uint8_t lld_con_current_tx_power_get(uint8_t link_id, uint8_t mod); + +/** + **************************************************************************************** + * @brief Get the received RSSI + * + * @param[in] link_id Link identifier + * + * @return rssi RSSI in dBm + **************************************************************************************** + */ +int8_t lld_con_rssi_get(uint8_t link_id); + +/** + **************************************************************************************** + * @brief Get the connection offset + * + * @param[in] link_id Link identifier + * + * @return con_offset Connection offset in slots (625 us) + **************************************************************************************** + */ +uint16_t lld_con_offset_get(uint8_t link_id); + +/** + **************************************************************************************** + * @brief Set peer SCA + * + * @param[in] link_id Link identifier + * @param[in] peer_sca Peer SCA (@see enum SCA) + **************************************************************************************** + */ +void lld_con_peer_sca_set(uint8_t link_id, uint8_t peer_sca); + +/** + **************************************************************************************** + * @brief Get connection event time + * + * @param[in] link_id Link identifier + * @param[out] con_evt_cnt Connection event counter + * @param[out] con_evt_time_hs Time of the connection event, in 312.5 us half-slots + * @param[out] con_evt_time_hus Time of the connection event, in half-us + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_time_get(uint8_t link_id, uint16_t* con_evt_cnt, uint32_t* con_evt_time_hs, uint16_t* con_evt_time_hus); +#endif // (BLE_CENTRAL || BLE_PERIPHERAL) + +#if (BLE_PERIPHERAL) +/** + **************************************************************************************** + * @brief Set the preferred slave latency + * + * @param[in] link_id Link identifier + * @param[in] latency Preferred slave latency (in number of connection events) + **************************************************************************************** + */ +void lld_con_pref_slave_latency_set(uint8_t link_id, uint16_t latency); + +/** + **************************************************************************************** + * @brief Set the preferred slave event duration + * + * @param[in] link_id Link identifier + * @param[in] Duration Preferred slave event duration (N * 0.625 ms) + **************************************************************************************** + */ +void lld_con_pref_slave_evt_dur_set(uint8_t link_id, uint16_t duration, bool single_tx); +#endif // (BLE_PERIPHERAL) + +#if (BLE_ISO_MODE_0) + +/** + **************************************************************************************** + * @brief Inform that Isochronous mode is set-up and mic less encryption is required + * + * @param[in] link_id Link identifier + **************************************************************************************** + */ +void lld_con_audio_use_mic_less(uint8_t link_id); + +/** + **************************************************************************************** + * @brief Start audio + * + * @param[in] link_id Link identifier + * @param[in] iso_channel Isochronous channel + * @param[in] params Configuration parameters + * + * @return Executions status + **************************************************************************************** + */ +uint8_t lld_con_audio_start(uint8_t link_id, uint8_t iso_channel, struct lld_con_audio_params* params); + +/** + **************************************************************************************** + * @brief Stop audio + * + * @param[in] link_id Link identifier + * + * @return Excecutions status + **************************************************************************************** + */ +uint8_t lld_con_audio_stop(uint8_t link_id); + +#endif //(BLE_ISO_MODE_0) + +#if BLE_CON_CTE_REQ +/** + **************************************************************************************** + * @brief Enable reception of CTE on connection + * + * @param[in] link_id Link identifier + * @param[in] slot_dur Slot durations (1: 1us | 2: 2us) + * @param[in] switching_pattern_len Length of switching pattern (number of antenna IDs in the pattern) + ***************************************************************************************** + */ +void lld_con_cte_rx_en(uint8_t link_id, uint8_t slot_dur, uint8_t switching_pattern_len); + +/** + **************************************************************************************** + * @brief Disable reception of CTE on connection + * + * @param[in] link_id Link identifier + ***************************************************************************************** + */ +void lld_con_cte_rx_dis(uint8_t link_id); +#endif // BLE_CON_CTE_REQ + +#if BLE_CON_CTE_RSP +/** + **************************************************************************************** + * @brief Configure antenna switching for connection CTE Tx + * + * @param[in] link_id Link identifier + * @param[in] switching_pattern_len Length of switching pattern (number of antenna IDs in the pattern) + * @param[in] cte_types CTE types (bit0: AOA | bit1: AOD-1us | bit2: AOD-2us) + ***************************************************************************************** + */ +void lld_con_cte_tx_ant_switch_config(uint8_t link_id, uint8_t switching_pattern_len, uint8_t cte_types); + +/** + **************************************************************************************** + * @brief Set connection CTE Tx parameters + * + * @param[in] link_id Link identifier + * @param[in] cte_len CTE length in 8 us units (0: No CTE | Range: 0x02 - 0x14) + * @param[in] cte_type CTE type (0x00: AOA | 0x01: AOD-1us | 0x02: AOD-2us) + ***************************************************************************************** + */ +void lld_con_cte_tx_param_set(uint8_t link_id, uint8_t cte_len, uint8_t cte_type); +#endif // BLE_CON_CTE_RSP + +/** + **************************************************************************************** + * @brief Start test mode (RX or TX) + * + * @param[in] params Pointer to Scanning parameters structure + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_test_start(struct lld_test_params* params); + +/** + **************************************************************************************** + * @brief Stop test mode + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_test_stop(void); + +#if (RW_DEBUG) +/** + **************************************************************************************** + * @brief Read BLE core register + * + * @param[in] reg_addr Register address + * + * @return reg_value Register value + **************************************************************************************** + */ +uint16_t lld_reg_rd(uint16_t reg_addr); + +/** + **************************************************************************************** + * @brief Write BLE core register + * + * @param[in] reg_addr Register address + * @param[in] reg_value Register value + **************************************************************************************** + */ +void lld_reg_wr(uint16_t reg_addr, uint16_t reg_value); +#endif // (RW_DEBUG) + +/** + **************************************************************************************** + * @brief Get connection synchronization information + * + * @param[in] link_id Link identifier + * @param[in] ref_con_evt_cnt Reference connection event count + * @param[in] ref_con_evt_ts Reference connection event timestamp (in 312.5 us half-slots) + * @param[in] ref_con_evt_bit_off Reference connection event bit offset (in half-us) + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_con_sync_info_get(uint8_t link_id, uint16_t* ref_con_evt_cnt, uint32_t* ref_con_evt_ts, uint16_t* ref_con_evt_bit_off); + +/** + **************************************************************************************** + * @brief Get sync info from a periodic sync activity + * + * @param[in] act_id Activity ID + * @param[out] phy Periodic advertising PHY (@see enum lld_rate) + * @param[out] intv Periodic advertising interval in units of 1.25 ms + * @param[out] aa Periodic advertising Access Address + * @param[out] crcinit Periodic advertising CRC Initialization value + * @param[out] sync_ind_ts Timestamp of the AUX_SYNC_IND packet (in 312.5 us half-slots) + * @param[out] sync_ind_bit_off Bit offset of the AUX_SYNC_IND packet (in half-us) + * @param[out] pa_evt_cnt Corresponding paEventCounter value + * @param[out] map Corresponding channel map + * @param[out] sca Periodic advertising Sleep Clock Accuracy + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_sync_info_get(uint8_t act_id, uint8_t* phy, uint16_t* intv, struct access_addr* aa, struct crc_init* crcinit, uint32_t* sync_ind_ts, uint16_t* sync_ind_bit_off, uint16_t* pa_evt_cnt, struct le_chnl_map *map, uint8_t* sca); + +/// @} LLD +#endif // LLD_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/lld/lld_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/lld/lld_int.h new file mode 100644 index 0000000..209fda2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/lld/lld_int.h @@ -0,0 +1,400 @@ +/** +**************************************************************************************** +* +* @file lld_int.h +* +* @brief LLD Internal API +* +* Copyright (C) RivieraWaves 2009-2016 +* +**************************************************************************************** +*/ + +#ifndef LLD_INT_H_ +#define LLD_INT_H_ + +/** + **************************************************************************************** + * @addtogroup LLD + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // stack configuration + +#include // integer +#include // boolean + +#include "lld.h" + + +/* + * MACROS + **************************************************************************************** + */ + + +/* + * CONSTANT DEFINITIONS + **************************************************************************************** + */ + +/// Allocate an event with an associated data structure +#define LLD_ALLOC_EVT(data_struct) (struct data_struct *) ke_malloc(sizeof(struct data_struct), KE_MEM_ENV); + +/// Initialize memory of an event and an associated data structure +#define LLD_INIT_EVT(evt, data_struct) memset(evt , 0, sizeof(struct data_struct)); + +#if 0 //(RW_BLE_WLAN_COEX) || (RW_BLE_MWS_COEX) +/// Coexistence disabled +#define BLECOEX_DISABLED 0 +/// Coexistence enabled +#define BLECOEX_ENABLED 1 + +/// Coexistence Definitions +#define BLEMPRIO_CONREQ 0 +#define BLEMPRIO_LLCP 1 +#define BLEMPRIO_DATA 2 +#define BLEMPRIO_INITSC 3 +#define BLEMPRIO_ACTSC 4 +#define BLEMPRIO_CONADV 5 +#define BLEMPRIO_NCONADV 6 +#define BLEMPRIO_PASSC 7 +#endif // (RW_BLE_WLAN_COEX) || (RW_BLE_MWS_COEX) + +/// Undefined BT clock value +#define LLD_CLOCK_UNDEF 0xFFFFFFFF + +/// Max fine counter value +#define LLD_FINECNT_MAX (HALF_SLOT_SIZE - 1) + +/// Adv packet error masking +#define LLD_ADV_ERR_MASK (EM_BLE_SYNC_ERR_BIT|EM_BLE_LEN_ERR_BIT|EM_BLE_CRC_ERR_BIT|EM_BLE_PRIV_ERR_BIT|EM_BLE_TYPE_ERR_BIT) + +/// ADV_INT (time between two ADV_XXX packets) in us +#define BLE_ADV_INT_US (729) + +/// Minimum scan window size when advertising using legacy PDUs in us +#define BLE_ADV_MIN_SCAN_WIN_SIZE_US (40) + +/// Calculate AUX OFFSET in usecs from AuxPtr AUX Offset and Offset Units fields +#define AUX_OFFSET_USECS(aux_offset, offset_units) ((aux_offset) * ((offset_units)?300:30)) + +/// AUX OFFSET Offset Units in usecs +#define AUX_OFFSET_UNIT_USECS(offset_units) ((offset_units)?300:30) + +/// Calculate drift in ppm from local drift and AuxPtr CA field +#define AUX_DRIFT_PPM(local_drift, ca) ((local_drift) + ((ca)?50:500)) + +/// Margin for event time reservation (in half-us) +#define BLE_RESERVATION_TIME_MARGIN_HUS (2 * IP_PREFETCHABORT_TIME_US) + +/// AUX_PTR Thresholds, below which HW manages AuxPtr automatically in same event (granularity 16us, 0 disabled) +#define LLD_TX_AUX_PTR_THR (0xFF) // 255 x 16 = 4080us (max value) +#define LLD_RX_AUX_PTR_THR (150) // 150 x 16 = 2520us (optimized for SW offload) + +/// Maximum supported CTE IQ samples - CTE RX descriptors dimensioned REG_EM_BLE_RX_CTE_DESC_SIZE to accommodate maximum +// An IQ sample is taken each usec during the reference period (8us) and one each sample slot thereafter. +// This results in 8 reference IQ samples, 1 to 37 IQ samples with 2 us slots, and 2 to 74 IQ samples with 1 us slots, meaning 9 to 82 samples in total. +#define LLD_MAX_CTE_IQ_SAMPLES (82) + +/// Hoping mode +enum lld_hop_mode +{ + /// Frequency Hopping Scheme #1 + LLD_HOP_MODE_CHAN_SEL_1 = 0, + /// Frequency Hopping Scheme #2 + LLD_HOP_MODE_CHAN_SEL_2 = 1, + /// Primary Advertising Channel randomized order mode + LLD_HOP_MODE_RAND_PRIM_ADV_CH = 3, +}; + +/* + * STRUCTURE DEFINITIONS + **************************************************************************************** + */ + +/// LLD environment structure +struct lld_env_tag +{ + /// Channel assessment data + struct lld_ch_assess_data ch_assess; + + /// ADV_SIDs bit field for PAL entries + uint16_t adv_sids[BLE_WHITELIST_MAX]; + + /// Maximum value of the local clock drift (in ppm) + uint16_t local_drift; + + /// Local sleep clock accuracy (see @enum SCA) + uint16_t local_sca; + + /// Current RX descriptor index [0:N-1] + uint8_t curr_rxdesc_index; + + /// LE Coded PHY 500 Kbps selection (false: 125 Kbps, true: 500 Kbps) + bool le_coded_phy_500; + + /// Connectionless channel map lookup table (more time-efficient than parsing a bitmap every time) + uint8_t ch_map_tab[DATA_CHANNEL_NB]; + + /// Number of used channels in the connectionless channel map + uint8_t nb_used_ch; +}; + +/// LLD Scheduling information for next AUX channel +struct lld_calc_aux_rx_out +{ + /// Timestamp (in half-slots) and delay (in half-us) from slot boundary for AUX offload channel receive + rwip_time_t time; + + /// Sync window size for the AUX offload channel (us) + uint32_t sync_win_size_us; + + /// Channel index for AUX offload channel + uint8_t ch_idx; + + /// PHY rate for AUX offload channel (@see enum lld_rate) + uint8_t rate; +}; + +/* + * VARIABLE DECLARATION + ***************************************************************************************** + */ + +/// Table indicating the expected sync position depending on the rate used +extern uint16_t lld_exp_sync_pos_tab[]; + +/// LLD environment variable +extern struct lld_env_tag lld_env; + +/* + * FUNCTIONS DECLARATION + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Free current RX descriptor + **************************************************************************************** + */ +void lld_rxdesc_free(void); + +/** + **************************************************************************************** + * @brief Check if the current RX descriptor is consumed by a given activity + * + * @param[in] label representing the activity (as indicated in the CS) + * + * @return True if current RX descriptor is consumed by the activity identified by label + **************************************************************************************** + */ +bool lld_rxdesc_check(uint8_t label); + +/** + **************************************************************************************** + * @brief Assess a RF channel + * + * @param[in] channel Channel index + * @param[in] rx_ok True: reception is correct | False: reception is corrupted + * @param[in] timestamp Timestamp of the assessment + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +void lld_channel_assess(uint8_t channel, bool rx_ok, uint32_t timestamp); + +/** + **************************************************************************************** + * @brief Search if a device is in resolving address list + * + * @param[in] bd_addr BD Address + * @param[in] bd_addr_type BD Address type (0: public | 1: random) + * + * @return position of the device in the list (Max value if not found) + **************************************************************************************** + */ +uint8_t lld_ral_search(const struct bd_addr *bd_addr, uint8_t bd_addr_type); + +#if (BLE_BROADCASTER) +/** + **************************************************************************************** + * @brief Initialize advertising driver + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void lld_adv_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Initialize periodic advertising driver + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void lld_per_adv_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Get sync info from a periodic advertiser + * + * @param[in] act_id Activity ID + * @param[out] sync_ind_ts Timestamp of the AUX_SYNC_IND packet + * @param[out] pa_evt_cnt Corresponding paEventCounter value + * @param[out] map Corresponding channel map + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_per_adv_sync_info_get(uint8_t act_id, uint32_t* sync_ind_ts, uint16_t* pa_evt_cnt, struct le_chnl_map *map); + +/** + **************************************************************************************** + * @brief Get initialization info from a periodic advertiser + * + * @param[in] act_id Activity ID + * @param[out] aa Periodic advertising Access Address + * @param[out] crcinit Periodic advertising CRC Initialization value + * @param[out] chm Periodic advertising Channel Map + * + * @return status 0: success | 1-255: error + **************************************************************************************** + */ +uint8_t lld_per_adv_init_info_get(uint8_t act_id, struct access_addr* aa, struct crc_init* crcinit, struct le_chnl_map* chm); + +/** + **************************************************************************************** + * @brief Select an auxiliary channel index + * + * @return ch_idx Selected channel index + **************************************************************************************** + */ +uint8_t lld_ch_idx_get(void); +#endif // (BLE_BROADCASTER) + +/** + **************************************************************************************** + * @brief Generating the Access Address for a new Link. + * + * The function will generate the following 4 bytes: + * |Byte 3 | Byte 2 | Byte 1 | Byte 0 | + * |CT1 | PRAND_4MSB | CT2 | PRAND_4LSB | CT2 | INCRAND_4MSB | CT2 | INCRAND_4LSB| + * + * The AA shall be a random 32-bit value, generated by the device in the Initiating State. + * It shall have no more than six consecutive zeros or ones. + * It shall not be the advertising channel packets’ Access Address. + * It shall not be a sequence that differs from the advertising channel packets’ Access Address by only one bit. + * It shall not have all four octets equal. + * It shall have no more than 24 transitions. + * It shall have a minimum of two transitions in the most significant six bits + * + * For each new generated AA, + * - PRAND is a pseudo random 1 byte number. + * - INCRAND is an initially generated random number, increased by 1 for each AA + * - CT2 is toggled between the two values + * - CT1 is again toggled between the 3 possible values + * + * Considering the formats of CT1 and CT2, the rules for AA generation are respected: + * - since CT2 is put between bytes, and has two equal bits on each half, + * it ensures no more than 6 consecutive bits inside the address. CT1 also. + * + * - CT2 and CT1 ensure that the newly generated address is different and at least 1 bit + * different from the advertising access address + * + * - since CT1 != CT2 , the four bytes of the AA can never be equal + * + * - Since in a 32 bit number there are 31 transitions, and the neighboring equal bits + * in CT1 and CT2 represent 7 transitions, there can never be more than 31-7=24 + * transitions in the AA + * + * - The format of CT1 ensures at least two transitions in the most significant 6 bits. + * + * BT5.0 Requirements: + * + * 1/ On an implementation that also supports the LE Coded PHY the Access Address shall also + * meet the following requirements: + * It shall have at least three ones in the least significant 8 bits. + * It shall have no more than eleven transitions in the least significant 16 bits. + * - CT2 format selected to satisfy these requirements. + * + * 2/ It shall not be the Access Address for any enabled periodic advertising. + * - The act_id is now passed as an arguemnt to AA generation to ensure unique values. + * + * @param acc_addr Pointer to the 4 byte array space for the AA. + * + * + ***************************************************************************************** + */ +void lld_aa_gen(uint8_t *acc_addr, uint8_t act_id); + +/** + **************************************************************************************** + * @brief Calculate an AUX RX activity + * + * @param[in] ux_rx_out Scheduling information for next AUX channel + * @param[out] index_pkt current RX descriptor index + * @param[out] aux_data received Aux data + * + * @return offload true: offload. false: no offload + **************************************************************************************** + */ +bool lld_calc_aux_rx(struct lld_calc_aux_rx_out* aux_rx_out, uint8_t index_pkt, uint32_t aux_data); + + +#if (BLE_OBSERVER) +/** + **************************************************************************************** + * @brief Initialize scanning driver + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ + +void lld_scan_init(uint8_t init_type); + +/** +**************************************************************************************** +* @brief Initialize periodic advertising Rx driver +* @param[in] init_type Type of initialization (@see enum rwip_init_type) +**************************************************************************************** +*/ +void lld_sync_init(uint8_t init_type); + +#endif // (BLE_OBSERVER) + +#if (BLE_CENTRAL) +/** + **************************************************************************************** + * @brief Initialize initiating driver + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void lld_init_init(uint8_t init_type); +#endif // (BLE_CENTRAL) + +#if (BLE_CENTRAL || BLE_PERIPHERAL) +/** + **************************************************************************************** + * @brief Initialize connection driver + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void lld_con_init(uint8_t init_type); + +#endif // (BLE_CENTRAL || BLE_PERIPHERAL) + +/** + **************************************************************************************** + * @brief Initialize test driver + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void lld_test_init(uint8_t init_type); + + +/// @} LLD +#endif // LLD_INT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llm.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llm.h new file mode 100644 index 0000000..84286b1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llm.h @@ -0,0 +1,404 @@ +/** + **************************************************************************************** + * + * @file llm.h + * + * @brief Main API file for the Link Layer manager + * + * Copyright (C) RivieraWaves 2009-2015 + * + **************************************************************************************** + */ + +#ifndef LLM_H_ +#define LLM_H_ + +/** + **************************************************************************************** + * @defgroup LLM Link Layer Manager + * @ingroup ROOT + * @brief BLE Lower Layers + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_task.h" // Task definitions +#include "co_bt.h" // BLE standard definitions + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Parameters for syncing to a periodic advertiser +struct llm_per_adv_sync_params +{ + /// Activity identifier + uint8_t act_id; + + /// SyncInfo + struct sync_info syncinfo; + + /// The clock value of the reference time (in half-slot) + uint32_t base_cnt; + + /// The fine timer value the reference time (in half-us) + uint16_t fine_cnt; + + /// ID (provided by the Host) + uint16_t id; + + /// The bit rate of periodic advertising (@see enum lld_rate) + uint8_t rate; + + /// Advertising SID + uint8_t adv_sid; + + /// Advertising address type (0: Public / 1: Random) + uint8_t adv_addr_type; + + /// Advertiser address + struct bd_addr adv_addr; + + /// Advertiser RPA (unresolved RPA if advertiser address is a resolved identity address, 0 otherwise) + struct bd_addr adv_rpa; + + /// max Skip after receive + uint16_t skip; + + /// Sync timeout (Time=N*10ms) + uint16_t sync_to; + + /// Additional drift to consider on given time reference (in half-us) + uint16_t add_drift; + + /// Advertising report initial state (enable/disable) + bool adv_rep_en; + + /// Specifies whether to only synchronize to periodic advertising with certain types of CTE (@see enum sync_cte_type) + uint8_t sync_cte_type; +}; + + +/* + * MESSAGES + **************************************************************************************** + */ + +/// Message API of the LLM task +/*@TRACE + * llm_pub_key_gen_ind = ecc_result_ind + * llm_dh_key_gen_ind = ecc_result_ind + * llm_encrypt_ind = aes_func_res_ind*/ +enum llm_msg_id +{ + LLM_MSG_ID_FIRST = TASK_FIRST_MSG(TASK_ID_LLM),//!< LLM_MSG_ID_FIRST + + #if (BLE_OBSERVER) + /// Send ACAD Data information + LLM_ACAD_DATA_IND, //!< LLM_ACAD_DATA_IND + #endif // (BLE_OBSERVER) + + /* + * ************** Msg LLM->LLC**************** + */ + #if (BLE_CENTRAL || BLE_PERIPHERAL) + /// Indicate that the channel map has to be updated on link connection + LLM_CH_MAP_UPDATE_IND, //!< LLM_CH_MAP_UPDATE_IND + #endif //(BLE_CENTRAL || BLE_PERIPHERAL) + + /* + * ************** Msg LLM->LLM**************** + */ + LLM_SCAN_PERIOD_TO, //!< LLM_SCAN_PERIOD_TO + LLM_CH_MAP_TO, //!< LLM_CH_MAP_TO + #if (BLE_CENTRAL || BLE_BROADCASTER) + LLM_NEW_HOST_CLASS_TO, + #endif //(BLE_CENTRAL || BLE_BROADCASTER) + LLM_RPA_RENEW_TO, //!< LLM_RPA_RENEW_TO + /// Inform that encryption has been performed + LLM_ENCRYPT_IND, //!< LLM_ENCRYPT_IND + + LLM_PUB_KEY_GEN_IND, //!< LLM_PUB_KEY_GEN_IND + LLM_DH_KEY_GEN_IND, //!< LLM_DH_KEY_GEN_IND + LLM_SOFT_FLOW_CTRL_TIMEOUT_CMD, + LLM_SET_UART_SEND_MODE_CMD, +}; + +/// LLM Encryption Request parameters structure +/*@TRACE*/ +struct llm_encrypt_req +{ + ///Long term key structure + struct ltk key; + ///Pointer to buffer with plain data to encrypt - 16 bytes + uint8_t plain_data[ENC_DATA_LEN]; +}; + +/// LLM Encryption indication structure +/*@TRACE*/ +struct llm_encrypt_rsp +{ + /// Status of the encryption + uint8_t status; + ///Encrypted data + uint8_t encrypted_data[ENC_DATA_LEN]; +}; + + +/// AES function execution result +/*@TRACE*/ +struct llm_encrypt_ind +{ + /// Status of AES execution + uint8_t status; + /// Result of the + uint8_t result[KEY_LEN]; +}; + + +#if (BLE_OBSERVER) +/// LLM ACAD data indication structure +/*@TRACE*/ +struct llm_acad_data_ind +{ + /// Sync handle + uint16_t sync_handle; + /// Status the indication - use to detect loss of periodic sync + uint8_t status; + /// ADV Data Type + uint8_t ad_type; + /// Reference event counter of the periodic advertiser when report received + uint16_t ref_evt_cnt; + + /// length of the data field + uint8_t data_len; + /// ACAD Data + uint8_t data[__ARRAY_EMPTY]; +}; +#endif // (BLE_OBSERVER) + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the BLE LLM task + * + * This function initializes the the LLM task, as well as the environment of the LLM + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void llm_init(uint8_t init_type); + +#if (BLE_CENTRAL || BLE_PERIPHERAL) +/** + **************************************************************************************** + * @brief This function handles LE link disconnection. + * + * @param[in] link_id Link Identifier + **************************************************************************************** + */ +void llm_link_disc(uint8_t link_id); + +/** + **************************************************************************************** + * @brief Indicate activity requires accurate clock + * + * @param[in] act_id Activity ID + * @param[in] clk_acc True if activity requires accurate clock + **************************************************************************************** + */ +void llm_clk_acc_set(uint8_t act_id, bool clk_acc); +#endif // (BLE_CENTRAL || BLE_PERIPHERAL) + +/** + **************************************************************************************** + * @brief This function is used to get the master channel map + * + * @return Pointer to master channel map + **************************************************************************************** + */ +struct le_chnl_map* llm_master_ch_map_get(void); + +/** + **************************************************************************************** + * @brief This function is used to check if an event is unmasked/masked + * + * @param[in] event_id Bit position of the event in the mask (see standard specification part II.E.7.8.1) + * + * @return True: event allowed | False: event masked + **************************************************************************************** + */ +bool llm_le_evt_mask_check(uint8_t event_id); + +/** + **************************************************************************************** + * @brief Retrieve LE Local Supported features + * + * @return Local feature mask + **************************************************************************************** + */ +const struct le_features* llm_le_features_get(void); + +/** + **************************************************************************************** + * @brief This function is used to get the RF Tx path compensation value + * + * @return RF Tx path compensation value (Range: -128.0 dB <= N <= 128.0 dB, Units: 0.1 dB) + **************************************************************************************** + */ +int16_t llm_tx_path_comp_get(void); + +/** + **************************************************************************************** + * @brief This function is used to get the RF Rx path compensation value + * + * @return RF Rx path compensation value (Range: -128.0 dB <= N <= 128.0 dB, Units: 0.1 dB) + **************************************************************************************** + */ +int16_t llm_rx_path_comp_get(void); + +/** + **************************************************************************************** + * @brief This function returns a pointer to the interval element of the link_id provided. + * + * @param[in] link_id Link Identifier + * + * @return Pointer to the associated interval element + **************************************************************************************** + */ +struct sch_plan_elt_tag *llm_plan_elt_get(uint8_t link_id); + +/** + **************************************************************************************** + * @brief Get available activity index + * + * @param[out] act_id Activity Identifier allocated + * + * @return - CO_ERROR_NO_ERROR: if succeed + * - CO_ERROR_CON_LIMIT_EXCEED: if no activity available + **************************************************************************************** + */ +uint8_t llm_activity_free_get(uint8_t* act_id); +/** + **************************************************************************************** + * @brief Free activity handle related to the activity + * + * @param[in] act_id Activity Identifier + **************************************************************************************** + */ +void llm_activity_free_set(uint8_t act_id); + +/** + **************************************************************************************** + * @brief Get advertising activity identifiers + * + * @param[in] adv_hdl Advertising handle + * @param[out] ext_adv_id Extended advertising ID + * @param[out] per_adv_id Periodic advertising ID + * + * @return - CO_ERROR_NO_ERROR: if succeed + * - CO_ERROR_UNKNOWN_ADVERTISING_ID: if no advertising set exists + * - CO_ERROR_COMMAND_DISALLOWED: if periodic advertising not in progress + **************************************************************************************** + */ +uint8_t llm_adv_act_id_get(uint8_t adv_hdl, uint8_t* ext_adv_id, uint8_t* per_adv_id); + +/** + **************************************************************************************** + * @brief Get periodic advertising train identifiers + * + * @param[in] act_id Activity ID of extended advertising + * @param[out] sid Advertising SID + * @param[out] atype Advertising address type (0: public, 1: random) + * @param[out] adva Advertising address (RPA if address is resolvable) + * + * @return - CO_ERROR_NO_ERROR: if succeed + * - CO_ERROR_COMMAND_DISALLOWED: if periodic advertising not in progress + **************************************************************************************** + */ +uint8_t llm_adv_set_id_get(uint8_t act_id, uint8_t* sid, uint8_t* atype, struct bd_addr* adva); + +#if (BLE_ISO_MODE_0) +/** + **************************************************************************************** + * @brief Get if Activity is an active link + * + * @param[out] act_id Activity Identifier + * + * @return true if in connected state, false else + **************************************************************************************** + */ +bool llm_iso_link_active(uint8_t act_id); +#endif // (BLE_ISO_MODE_0) + + +/** + **************************************************************************************** + * @brief Get if Activity is ongoing + * + * @return true if active + **************************************************************************************** + */ +bool llm_activity_ongoing_check(void); + +/** + **************************************************************************************** + * @brief Attach a task with a periodic scanner to receive specific AD Type data + * + * @param[in] sync_act_id Sync activity ID + * @param[in] ad_type AD Type to retrieve in ACAD data + * @param[in] task Task that expect the LLM_ACAD_DATA_IND message + * + * @return CO_ERROR_NO_ERROR if the periodic sync is found + **************************************************************************************** + */ +uint8_t llm_scan_sync_acad_attach(uint8_t sync_act_id, uint8_t ad_type, uint16_t task); + +/** + **************************************************************************************** + * @brief Get periodic sync information + * + * @param[in] sync_act_id Sync activity ID + * @param[out] sid Extended advertising set identifier + * @param[out] atype Extended advertiser address type (0: public | 1: random) + * @param[out] adva Extended advertiser address (for resolvable addresses, this is the unresolved version) + * + * @return - CO_ERROR_NO_ERROR: if succeed + * - CO_ERROR_UNKNOWN_ADVERTISING_ID: if the sync activity does not exist + **************************************************************************************** + */ +uint8_t llm_scan_sync_info_get(uint8_t sync_act_id, uint8_t* sid, uint8_t* atype, struct bd_addr* adva); + +/** + **************************************************************************************** + * @brief Synchronize to a periodic advertising + * + * param[in] params Input parameters (@see llm_per_adv_sync_params) + * + * @return 0 if synchronization attempt is started, >0 if issue + **************************************************************************************** + */ +uint8_t llm_per_adv_sync(struct llm_per_adv_sync_params * params); + +/** + **************************************************************************************** + * @brief Get pointer of the RAL table in RAM + * + * @return pointer of the RAL table in RAM + **************************************************************************************** + */ +struct ral_entry* llm_ral_get(void); + +/// @} LLM + +#endif // LLM_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llm/llm_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llm/llm_int.h new file mode 100644 index 0000000..75f7d43 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llm/llm_int.h @@ -0,0 +1,634 @@ +/** + **************************************************************************************** + * + * @file llm.h + * + * @brief Link layer manager internal definition + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + +#ifndef LLM_INT_H_ +#define LLM_INT_H_ + +/** + **************************************************************************************** + * @addtogroup LLM Link layer Manager + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include // standard integer +#include // standard boolean + +#include "co_bt.h" // BT defines +#include "sch_plan.h" // Scheduling Planner + +/* + * DEFINES + **************************************************************************************** + */ + +/// Maximum number of instances of the LLM task +#define LLM_IDX_MAX 1 + +/// Invalid activity identifier +#define LLM_ACT_IDX_INVL 0xFF + +/// Invalid advertising handle (assigned to legacy advertising for internal management) +#define LLM_ADV_HDL_INVL 0xFF + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/** + * Information bit field for advertising duplicate filtering + * 15:10 9:8 7:6 5:4 3:2 1 0 + * +---------------------------------------+--------------+--------------+--------------+--------------+------+------+ + * | | CHAIN2_CODED | CHAIN2_1M | CHAIN1_CODED | CHAIN1_1M | RST | EN | + * +---------------------------------------+--------------+--------------+--------------+--------------+------+------+ + */ +enum adv_dup_filt_info +{ + /// Duplicate filtering enabled + LLM_ADV_DUP_FILT_EN_POS = 0, + LLM_ADV_DUP_FILT_EN_BIT = (1 << 0), + + /// Duplicate filtering reset at each scan period + LLM_ADV_DUP_FILT_RST_POS = 1, + LLM_ADV_DUP_FILT_RST_BIT = (1 << 1), + + /// Advertising report chain status from 1M scan + LLM_ADV_DUP_FILT_CHAIN1_1M_LSB = 2, + LLM_ADV_DUP_FILT_CHAIN1_1M_MASK = (0x3 << 2), + + /// Advertising report chain status from coded scan + LLM_ADV_DUP_FILT_CHAIN1_CODED_LSB = 4, + LLM_ADV_DUP_FILT_CHAIN1_CODED_MASK = (0x3 << 4), + + /// Advertising report chain status from 1M scan + LLM_ADV_DUP_FILT_CHAIN2_1M_LSB = 6, + LLM_ADV_DUP_FILT_CHAIN2_1M_MASK = (0x3 << 6), + + /// Advertising report chain status from coded scan + LLM_ADV_DUP_FILT_CHAIN2_CODED_LSB = 8, + LLM_ADV_DUP_FILT_CHAIN2_CODED_MASK = (0x3 << 8), + + /** + * 0: No chain + * 1: A valid advertising report chain is ongoing + * 2: A filtered advertising report chain is ongoing + */ + LLM_ADV_CHAIN_NO = 0, + LLM_ADV_CHAIN_VALID = 1, + LLM_ADV_CHAIN_FILTERED = 2, +}; + +/// Status bits for a device list entry +/// +/// 7 6 5 4 3 2 1 0 +/// +------+------+------+------+------+-------+-------+------+ +/// | | | | | | IN_PL | IN_WL | USED | +/// +------+------+------+------+------+-------+-------+------+ +/// +enum dev_list_stat +{ + /// Device list entry is used + LLM_DEV_LIST_ENTRY_USED_POS = 0, + LLM_DEV_LIST_ENTRY_USED_BIT = (1 << 0), + + /// Device is in white list + LLM_DEV_IN_WL_POS = 1, + LLM_DEV_IN_WL_BIT = (1 << 1), + + /// Device is in periodic advertiser list + LLM_DEV_IN_PL_POS = 2, + LLM_DEV_IN_PL_BIT = (1 << 2), +}; + +/// Advertising interface version, see HCI:3.1.1 +enum adv_itf_version +{ + /// Interface not yet detected + LLM_ADV_ITF_UNKNOWN = 0, + /// Legacy interface + LLM_ADV_ITF_LEGACY, + /// Extended interface + LLM_ADV_ITF_EXTENDED, +}; + +/** + * Periodic advertising reports enable/disable (only used for periodic sync) + * + * 7..3 2 1 0 + * +--------------+-------+--------+------+ + * | RSVD | CHAIN | SWITCH | EN | + * +--------------+-------+--------+------+ + */ +enum per_adv_rep_en +{ + /// Reports enable/disable + LLM_PER_ADV_REP_EN_EN_POS = 0, + LLM_PER_ADV_REP_EN_EN_BIT = (1 << 0), + + /// Indicate a chain is ongoing + LLM_PER_ADV_REP_EN_CHAIN_POS = 1, + LLM_PER_ADV_REP_EN_CHAIN_BIT = (1 << 1), + + /// Reports enable/disable + LLM_PER_ADV_REP_EN_SWITCH_POS = 2, + LLM_PER_ADV_REP_EN_SWITCH_BIT = (1 << 2), +}; + +/// States of an activity +enum LLM_ACTIVITY_STATE +{ + LLM_FREE, + LLM_ADV_RSVD, + LLM_ADV_EN, + LLM_ADV_STOPPING, + LLM_CON_RSVD, + LLM_INITIATING, + LLM_SCAN_RSVD, + LLM_SCAN_EN, + LLM_SCAN_STOPPING, + LLM_CONNECTED, + LLM_PER_ADV_RSVD, + LLM_PER_ADV_PENDING, // This state means that the host has enabled per adv but the driver has not been started yet + LLM_PER_ADV_EN, + LLM_PER_ADV_STOPPING, + LLM_PER_SCAN_SYNCING, + LLM_PER_SCAN_SYNCED, + LLM_PER_SCAN_STOPPING, + LLM_PER_SCAN_SYNCING_FROM_SYNC_TRANSF, +}; + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Device list entry structure +struct dev_list_entry +{ + /// BD address + struct bd_addr addr; + + /// Advertising Set IDs (for periodic advertiser list), 1 bit per ADV_SID + uint16_t adv_sids; + + /** Address type + * 0x00 Public Device Address or Public Identity Address + * 0x01 Random Device Address or Random (static) Identity Address + * 0xFF Address type of devices sending anonymous advertisements + */ + uint8_t addr_type; + + /** Bit field indicating: + * bit 0: entry is used + * bit 1: device is in white list + * bit 2: device is in periodic advertiser list + */ + uint8_t status; +}; + +/// Information about one single advertiser discovered +struct adv_dup_filt_entry +{ + /// Advertising device address + struct bd_addr adv_addr; + + /// Advertising Data ID (if Set ID is valid) + uint16_t did; + + /// Periodic advertising interval + uint16_t per_adv_intv; + + /** + * Bit + * 0 Connectable advertising + * 1 Scannable advertising + * 2 Directed advertising + * 3 Scan response + * 4 Legacy advertising PDUs used + */ + uint8_t adv_evt_type; + + /** + * Peer address type + * 0x00 Public Device Address + * 0x01 Random Device Address + * 0x02 Public Identity Address (Corresponds to Resolved Private Address) + * 0x03 Random (static) Identity Address (Corresponds to Resolved Private Address) + * 0x04-0xFF Reserved for future use + */ + uint8_t addr_type; + + /// Advertising Set ID + uint8_t sid; +}; + +#if (BLE_OBSERVER) +/// Advertising duplicate filtering table information structure +struct adv_dup_filt_tab_info +{ + /// Table listing all found advertisers + struct adv_dup_filt_entry tab[BLE_DUPLICATE_FILTER_MAX]; + + /// Current position in the table for placing the next discovered advertiser + uint8_t curr_pos; + + /// Number of discovered advertisers in the table + uint8_t nb_adv; +}; +#endif //(BLE_OBSERVER) + +/// Channel map parameters structure +struct llm_ch_map_info +{ + /// Channel classification from Host + struct le_chnl_map host_ch_class; + + /// Master channel map (map used for all master links) + struct le_chnl_map master_ch_map; + + /// Channel map management state + uint8_t active; + + /** + * Block the HCI LE Set Host Channel Classification Command during 1 second, as per standard + * The interval between two successive commands sent shall be at least one second. + */ + bool new_host_class; +}; + +/// Information about extended advertising data or scan response data received from Host +struct llm_adv_tx_info +{ + /// EM buffer containing complete advertising or extended scan response data received from Host + uint16_t curr_buf; + + /// Total length of advertising or scan response data in the current buffer + uint16_t curr_len; + + /// EM buffer containing advertising data or extended scan response data in construction from Host + uint16_t new_buf; + + /// Total length of advertising or scan response data in the new buffer + uint16_t new_len; +}; + +/// Specific information for advertiser +struct llm_adv_info +{ + /// Information about extended advertising data received from Host + struct llm_adv_tx_info adv_data; + + /// Information about extended scan response data received from Host + struct llm_adv_tx_info scan_rsp_data; + + /// Local BD address + struct bd_addr bd_addr; + + /// Local RPA + struct bd_addr local_rpa; + + #if BLE_CONLESS_CTE_TX + /// Pointer to CTE parameters received from the Host (field valid for ext adv only, not per adv) + struct hci_le_set_conless_cte_tx_param_cmd const *cte_tx_params; + + /// Indicates whether CTE has been enabled (true) or not (false) (field valid for ext adv only, not per adv) + bool cte_en; + #endif // BLE_CONLESS_CTE_TX + + /// Selected extended advertising Tx power (selected by LLM, applied by LLD) + int8_t tx_pwr; + + /// Per adv linked to the set: ID of the periodic advertising + uint8_t per_act_id; + + /// The ID of the resulting connection if advertising is connectable + uint8_t con_act_id; +}; + +/// Specific information for periodic advertiser +struct llm_per_adv_info +{ + /// Information about extended advertising data received from Host + struct llm_adv_tx_info adv_data; + + /** + * Associated activity ID: + */ + uint8_t ass_act_id; +}; + +/// Specific information for periodic synchronization +struct llm_sync_info +{ + #if BLE_CONLESS_CTE_RX + /// Pointer to CTE parameters received from the Host (for periodic scanning) + struct hci_le_set_conless_iq_sampl_en_cmd const *cte_rx_params; + #endif // BLE_CONLESS_CTE_RX + + /// Peer identity BD address + struct bd_addr bd_addr; + + /// Peer RPA (used by PAST feature) + struct bd_addr peer_rpa; + + /// Service data (value provided by the Host during periodic advertising sync transfer, stored temporarily during sync establishment) + uint16_t serv_data; + + /// Advertising SID (for periodic scanning) + uint8_t adv_sid; + + /// Periodic advertising PHY (for periodic scanning) + uint8_t per_adv_phy; + + // Periodic Sync ACAD data transfer: + /// Adv data type to transfer + uint8_t ad_type; + /// Task identifier that expect the advertising data. + /// - TASK_NONE ==> means no activity expect ACAD data + uint16_t dst_id; + /** + * Associated activity ID: + * + * Its meaning depends on the activity: + * - Scan: + * - not used + * - Periodic sync + * - Only when syncing from a periodic advertising sync transfer, it + * links to the connection where the info has been received from. Used + * to report synchronization result to the Host + */ + uint8_t ass_act_id; + + /// Periodic advertising reports enable/disable (only used for periodic sync) (@see enum per_adv_rep_en) + uint8_t per_adv_rep_en; + + /// Peer device address type (@see enum addr_type) + uint8_t addr_type; +}; + +/// Specific information for connection +struct llm_con_info +{ + /// Peer BD address (identity) + struct bd_addr bd_addr; + + /// Peer device address type (@see enum addr_type) + uint8_t addr_type; + + /// Role (0x00: MASTER / 0x01: SLAVE) (for connection) + uint8_t role; +}; + +/// Specific information for scanning +struct llm_scan_info +{ + ///Scan duration (Time=N*10ms) | 0x0000: Scan continuously until explicitly disable + uint16_t duration; + ///Scan period (Time=N*1.28sec) | 0x0000: Periodic scanning disabled + uint16_t period; +}; + + +/// State for all activities +struct llm_act_info +{ + /// Pointer to parameters received from the Host (advertising, scanning or initiating) + void const * host_params; + + /// Interval element linked to this activity + struct sch_plan_elt_tag plan_elt; + + union + { + /// Scanning specific activity info + struct llm_scan_info scan; + /// Advertising specific activity info + struct llm_adv_info adv; + /// Periodic advertising specific activity info + struct llm_per_adv_info per_adv; + /// Periodic sync specific activity info + struct llm_sync_info sync; + /// Connection specific activity info + struct llm_con_info con; + } info; + + + /// State + uint8_t state; +}; + +/// LLM environment structure +struct llm_env_tag +{ + /// RAL content + struct ral_entry ral[BLE_RESOL_ADDR_LIST_MAX]; + + /// Bit field indicating the accurate clock is required (for each activity, indexed by activity ID) + uint32_t act_clk_acc; + + /// LE Event mask + struct evt_mask le_event_mask; + + /// State and parameters for all activities + struct llm_act_info act_info[BLE_ACTIVITY_MAX]; + + /// Local public BD address + struct bd_addr local_pub_addr; + + /// Local random BD address + struct bd_addr local_rand_addr; + + /// Channel map management parameters + struct llm_ch_map_info ch_map_info; + + /// Device list information table + struct dev_list_entry dev_list[BLE_WHITELIST_MAX]; + + #if (BLE_CENTRAL || BLE_PERIPHERAL) + // Default Data Length parameters + /// Suggested value for the Controller's maximum transmitted number of payload octets + uint16_t suggested_max_tx_octets; + /// Suggested value for the Controller's maximum packet transmission time (in us) + uint16_t suggested_max_tx_time; + + // Default PHY parameters + /// Phy options indicated by Host (@see enum le_phy_opt) (by default 0 if never set by Host) + uint16_t phy_opt; + /// Default TX preferred PHY to use (@see enum le_phy_mask) + uint8_t tx_phys; + /// Default RX preferred PHY to use (@see enum le_phy_mask) + uint8_t rx_phys; + + // Default PAST parameters + /// Mode (@see enum per_adv_sync_info_rec_mode) + uint8_t past_mode; + /// The number of periodic advertising packets that can be skipped after a successful receive + uint16_t past_skip; + /// Sync timeout (Time=N*10ms) + uint16_t past_sync_to; + /// CTE type (@see enum sync_cte_type) + uint8_t past_cte_type; + #endif //(BLE_CENTRAL || BLE_PERIPHERAL) + + /// Private P256 key for secure connection + uint8_t secret_key256[PRIV_KEY_256_LEN]; + + /// Resolvable private addresses renew timeout (in seconds) + uint16_t rpa_renew_to; + /// Address resolution enabled + bool addr_resolution_en; + + /// RF Rx path compensation value (Range: -128.0 dB <= N <= 128.0 dB, Units: 0.1 dB) + int16_t rx_path_comp; + /// RF Tx path compensation value (Range: -128.0 dB <= N <= 128.0 dB, Units: 0.1 dB) + int16_t tx_path_comp; + + #if (BLE_OBSERVER) + /// Advertising duplicate filtering table information + struct adv_dup_filt_tab_info dup_filt; + + /// Information bit field for duplicate filtering (@see enum adv_dup_filt_info) + uint16_t adv_dup_filt_info; + + /// Enable scanning for extended advertising PDUs + bool ext_scan; + #endif //(BLE_OBSERVER) + + #if (BLE_BROADCASTER) + /// Number of extended advertising sets that are stopping + uint8_t nb_ext_adv_sets_stopping; + #endif //(BLE_BROADCASTER) + + #if (BLE_ADV_LEGACY_ITF) + /// Indicate if the interface version the Host is using (legacy/extended), see HCI:3.1.1 + uint8_t adv_itf_version; + #endif //(BLE_ADV_LEGACY_ITF) + + #if (BLE_CENTRAL || BLE_PERIPHERAL) + /// Connection move enable + uint8_t con_move_en; + #endif // (BLE_CENTRAL || BLE_PERIPHERAL) + + /// Enable channel assessment usage when building channel maps + bool ch_ass_en; +}; + + +/* + * GLOBAL VARIABLE DECLARATIONS + ***************************************************************************************** + */ + + /// LLM task message handlers table +extern const struct ke_task_desc TASK_DESC_LLM; + +/// LLM environment variable +extern struct llm_env_tag llm_env; + +/// LLM local supported features +extern uint8_t const llm_local_supp_feats[FEATURE_PAGE_MAX][FEATS_LEN]; + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +#if (BLE_BROADCASTER) +/** + **************************************************************************************** + * @brief Retrieve Advertising identifier from advertising handle. + * + * @param[in] adv_hdl Advertising Handle + * @param[out] adv_param if not null, used to return advertising parameter that correspond to the handle. + * + * @return Activity identifier, or invalid identifier if not found + **************************************************************************************** + */ +uint8_t llm_adv_hdl_to_id(uint16_t adv_hdl, struct hci_le_set_ext_adv_param_cmd** adv_param); +#endif // (BLE_BROADCASTER) + +/// Send HCI CC event returning a status only +void llm_cmd_cmp_send(uint16_t opcode, uint8_t status); + +/// Send HCI CS event +void llm_cmd_stat_send(uint16_t opcode, uint8_t status); + +#if (BLE_CENTRAL || BLE_PERIPHERAL || BLE_OBSERVER) +/// Check if a device is already connected +bool llm_is_dev_connected(struct bd_addr const *peer_addr, uint8_t peer_addr_type); +#endif //(BLE_CENTRAL || BLE_PERIPHERAL || BLE_OBSERVER) + +#if (BLE_OBSERVER) +/// Check if a device is a synchronized periodic advertiser +bool llm_is_dev_synced(struct bd_addr const *peer_addr, uint8_t peer_addr_type, uint8_t adv_sid); +#endif //(BLE_OBSERVER) + +/** + **************************************************************************************** + * @brief Find an empty entry in device list + * + * @return position of an empty entry in the list (Max value if not found) + **************************************************************************************** + */ +uint8_t llm_dev_list_empty_entry(void); + +/** + **************************************************************************************** + * @brief Search if a device is in device list + * + * @param[in] bd_addr BD Address + * @param[in] bd_addr_type BD Address type (0: public | 1: random) + * + * @return position of the device in the list (Max value if not found) + **************************************************************************************** + */ +uint8_t llm_dev_list_search(const struct bd_addr *bd_addr, uint8_t bd_addr_type); + +/** + **************************************************************************************** + * @brief Search if a device is in resolving address list + * + * @param[in] bd_addr BD Address + * @param[in] bd_addr_type BD Address type (0: public | 1: random) + * + * @return position of the device in the list (Max value if not found) + **************************************************************************************** + */ +uint8_t llm_ral_search(const struct bd_addr *bd_addr, uint8_t bd_addr_type); + +/** + **************************************************************************************** + * @brief Check if resolving list is empty + * + * @return True: empty | False: not empty + **************************************************************************************** + */ +bool llm_ral_is_empty(void); + +/** + **************************************************************************************** + * @brief Entry point to update the channel map + **************************************************************************************** + */ +void llm_ch_map_update(void); + +/// @} LLM + +#endif // LLM_INT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/em/api/em_map.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/em/api/em_map.h new file mode 100644 index 0000000..88f24c6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/em/api/em_map.h @@ -0,0 +1,283 @@ +/** + **************************************************************************************** + * + * @file em_map.h + * + * @brief Mapping of the exchange memory + * + * Copyright (C) RivieraWaves 2009-2015 + * + **************************************************************************************** + */ + +#ifndef EM_MAP_H_ +#define EM_MAP_H_ + +/** + **************************************************************************************** + * @addtogroup EM EM + * @ingroup IP + * @brief Mapping of the different common area in the exchange memory + * + * @{ + **************************************************************************************** + */ +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#include +#include +#include +#include "co_math.h" // For use of CO_ALIGN4_HI + +#include "_reg_em_et.h" + +/// Retrieve Exchange memory address to set into HW interface +#define REG_EM_ADDR_GET(elem, idx) (REG_EM_##elem##_ADDR_GET(idx) >> 2) +/// Retrieve Exchange index from address load from HW interface +#define REG_EM_IDX_GET(elem, addr) ((((addr)<<2) - (EM_##elem##_OFFSET))/(REG_EM_##elem##_SIZE)) + +/// Exchange memory base address +#define EM_BASE_ADDR REG_EM_ET_BASE_ADDR + +/// Null pointer in EM offset space +#define EM_PTR_NULL (0x0000) + + +/* + **************************************************************************************** + ********************** Common EM part ********************** + **************************************************************************************** + */ +/// Start of the common EM part +#define EM_COMMON_OFFSET (0) + +/* + * EXCHANGE TABLE + **************************************************************************************** + */ + +/// Exchange table area definition +#define EM_EXCH_TABLE_LEN 16 +#define EM_ET_OFFSET (EM_COMMON_OFFSET) +#define EM_ET_END (EM_ET_OFFSET + EM_EXCH_TABLE_LEN * REG_EM_ET_SIZE) + +/** + * MODEn[3:0] + * + * 0x0: No mode selected, nothing to be performed + * 0x1: BR/EDR Mode + * 0x2: BLE Mode + * 0x3-0xF: Reserved for future use - + */ +#define EM_ET_MODE_NONE 0x00 +#define EM_ET_MODE_BREDR 0x01 +#define EM_ET_MODE_BLE 0x02 + +/// exchange table entry status +enum em_et_status +{ + /// 000: Exchange Table entry associated event is ready for processing. + EM_ET_STATUS_READY = 0x00,//!< EM_ET_STATUS_READY + /// 001: Exchange Table entry is waiting for start (already read by Event Scheduler) + EM_ET_STATUS_UNDER_PROCESS = 0x01,//!< EM_ET_STATUS_UNDER_PROCESS + /// 010: Exchange Table entry associated event is started + EM_ET_STATUS_STARTED = 0x02,//!< EM_ET_STATUS_STARTED + /// 011: Exchange Table entry associated event is terminated (normal termination) + EM_ET_STATUS_TERM_NORMAL = 0x03,//!< EM_ET_STATUS_TERM_NORMAL + /// 100: Exchange Table entry associated event is terminated (abort termination under prio bandwidth) + EM_ET_STATUS_TERM_ABORT_IN_PRIO_BW = 0x04,//!< EM_ET_STATUS_TERM_ABORT_IN_PRIO_BW + /// 101: Exchange Table entry associated event is terminated (abort termination after prio bandwidth) + EM_ET_STATUS_TERM_ABORT = 0x05,//!< EM_ET_STATUS_TERM_ABORT + /// 110: Exchange Table entry associated event is skipped + EM_ET_STATUS_SKIPPED = 0x06,//!< EM_ET_STATUS_SKIPPED + /// 111: Reserved for future use +}; + +/** + * ISOBUFSELn + * Used to select Isochronous channel Buffer Pointer + * 0x0: Uses ISO<0/1/2>PTR0 + * 0x1: Uses ISO<0/1/2>PTR1 + */ +#define EM_ET_ISO_PTR0 0x00 +#define EM_ET_ISO_PTR1 0x01 + +/** + * ISOn + * Indicates a Isochronous connection event is programmed + * 0x0: Not an Isochronous Channel event + * 0x1: Isochronous Channel event + */ +#define EM_ET_ISO_NOTPROGRAMMED 0x00 +#define EM_ET_ISO_PROGRAMMED 0x01 + +/** + * ISOCHANn[1:0] + * Meaningful if ISOn = 1 + * 00: Select Isochronous channel 0. + * 01: Select Isochronous channel 1. + * 10: Select Isochronous channel 2. + * 11: Trash received isochronous packet / Sent null length packet if ET-ISO = 1 / No Tx if ET-ISO = 0 + */ +#define EM_ET_ISO_CHANNEL_0 0x00 +#define EM_ET_ISO_CHANNEL_1 0x01 +#define EM_ET_ISO_CHANNEL_2 0x02 +#define EM_ET_ISO_NOCHANNEL 0x03 + + +/** + * RSVDn + * Indicates a reserved event + * 0x0: Not a reserved event (ISO connection re-Tx) + * 0x1: Reserved event (ISO connection primary event) + */ +#define EM_ET_ISO_NOT_RSVD 0x00 +#define EM_ET_ISO_RSVD 0x01 +/* + * FREQUENCY TABLE + **************************************************************************************** + */ + +/// Frequency table area definition +#define EM_FT_OFFSET (EM_ET_END) + +/// number of frequencies / Depends on RF target +#if defined(CFG_RF_ATLAS) + /// IcyTRx requires 40 x 32-bit words for Frequency table + 40 byte for VCO sub-band table + #define EM_RF_FREQ_TABLE_LEN 160 + #define EM_RF_VCO_TABLE_LEN 40 +#else + #if BT_EMB_PRESENT + /// Ripple/ExtRC requires 80 x 8-bit words for Frequency table / No VCO sub-band table + #define EM_RF_FREQ_TABLE_LEN 80 + #define EM_RF_VCO_TABLE_LEN 0 + #elif BLE_EMB_PRESENT + /// Ripple/ExtRC requires 40 x 8-bit words for Frequency table / No VCO sub-band table + #define EM_RF_FREQ_TABLE_LEN 40 + #define EM_RF_VCO_TABLE_LEN 0 + #endif // BT_EMB_PRESENT/BLE_EMB_PRESENT +#endif + +#define EM_FT_END (EM_FT_OFFSET + (EM_RF_VCO_TABLE_LEN + EM_RF_FREQ_TABLE_LEN) * sizeof(uint8_t)) + +/* + * RF SW SPI + **************************************************************************************** + */ +/// RF SW-Driven SPI transfers area definition +#if defined(CFG_RF_ATLAS) + /// IcyTYRx (Former Atlas) SW Driven SPI space + #define EM_RF_SW_SPI_OFFSET (EM_FT_END) + #define EM_RF_SW_SPI_SIZE_MAX 136 + #define EM_RF_SW_SPI_END (EM_RF_SW_SPI_OFFSET + EM_RF_SW_SPI_SIZE_MAX) + +#elif defined(CFG_RF_BTIPT) + /// BTIPT RF SW Driven SPI space + #define EM_RF_SW_SPI_OFFSET (EM_FT_END) + #define EM_RF_SW_SPI_SIZE_MAX 100 + #define EM_RF_SW_SPI_END (EM_RF_SW_SPI_OFFSET + EM_RF_SW_SPI_SIZE_MAX) +#elif defined(CFG_RF_CALYPSO) + /// CALYPSO RF SW Driven SPI space + #define EM_RF_SW_SPI_OFFSET (EM_FT_END) + #define EM_RF_SW_SPI_SIZE_MAX 100 + #define EM_RF_SW_SPI_END (EM_RF_SW_SPI_OFFSET + EM_RF_SW_SPI_SIZE_MAX) +#else + /// Ripple SW Driven SPI space + /// RF-SW-SPI transfers area definition + #define EM_RF_SW_SPI_OFFSET (EM_FT_END) + #define EM_RF_SW_SPI_SIZE_MAX 8 + #define EM_RF_SW_SPI_END (EM_RF_SW_SPI_OFFSET + EM_RF_SW_SPI_SIZE_MAX) +#endif + + + +/* + * RF HW SPI + **************************************************************************************** + */ +/// RF HW-Driven SPI transfers area definition +#if defined(CFG_RF_ATLAS) + /// IcyTYRx (Former Atlas) SW Driven SPI space + #define EM_RF_HW_SPI_OFFSET (EM_RF_SW_SPI_END) + #define EM_RF_HW_SPI_SIZE_MAX 100 + #define EM_RF_HW_SPI_END (EM_RF_HW_SPI_OFFSET + EM_RF_HW_SPI_SIZE_MAX) + +#elif defined(CFG_RF_BTIPT) + /// BTIPT RF SW Driven SPI space + #define EM_RF_HW_SPI_OFFSET (EM_RF_SW_SPI_END) + #define EM_RF_HW_SPI_SIZE_MAX 0x100 + #define EM_RF_HW_SPI_END (EM_RF_HW_SPI_OFFSET + EM_RF_HW_SPI_SIZE_MAX) + +#elif defined(CFG_RF_CALYPSO) + /// CALYPSO RF SW Driven SPI space + #define EM_RF_HW_SPI_OFFSET (EM_RF_SW_SPI_END) + #define EM_RF_HW_SPI_SIZE_MAX 0x100 + #define EM_RF_HW_SPI_END (EM_RF_HW_SPI_OFFSET + EM_RF_HW_SPI_SIZE_MAX) + +#else + /// Ripple SW Driven SPI space + /// RF-SW-SPI transfers area definition + #define EM_RF_HW_SPI_OFFSET (EM_RF_SW_SPI_END) + #define EM_RF_HW_SPI_SIZE_MAX 0 + #define EM_RF_HW_SPI_END (EM_RF_HW_SPI_OFFSET + EM_RF_HW_SPI_SIZE_MAX) +#endif + + +/// End of the common EM part +#define EM_COMMON_END (EM_RF_HW_SPI_END) + +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/* + * ENCRYPTION + **************************************************************************************** + */ + +/// Encryption area definition +#define EM_ENC_OFFSET CO_ALIGN4_HI(EM_COMMON_END) +#define EM_ENC_IN_OFFSET (EM_ENC_OFFSET) +#define EM_ENC_IN_SIZE (16) +#define EM_ENC_OUT_OFFSET (EM_ENC_IN_OFFSET + EM_ENC_IN_SIZE) +#define EM_ENC_OUT_SIZE (16) +#define EM_ENC_END (EM_ENC_OFFSET + EM_ENC_IN_SIZE + EM_ENC_OUT_SIZE) + +#endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + +/* + **************************************************************************************** + ********************** BLE EM part ********************** + **************************************************************************************** + */ + +#define EM_BLE_OFFSET CO_ALIGN4_HI(EM_ENC_END) +#if BLE_EMB_PRESENT +#include "em_map_ble.h" +#else // BLE_EMB_PRESENT +#define EM_BLE_END (EM_BLE_OFFSET) +#endif // BLE_EMB_PRESENT + +/* + **************************************************************************************** + ********************** BT EM part ********************** + **************************************************************************************** + */ + +#define EM_BT_OFFSET CO_ALIGN4_HI(EM_BLE_END) +#if BT_EMB_PRESENT +#include "em_map_bt.h" +#else // BT_EMB_PRESENT +#define EM_BT_END (EM_BT_OFFSET) +#endif //BT_EMB_PRESENT + + +/* + * RF SPI part + **************************************************************************************** + */ + + +/// @} IPDEXMEM + +#endif // EM_MAP_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/hci/api/hci.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/hci/api/hci.h new file mode 100644 index 0000000..4a6e285 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/hci/api/hci.h @@ -0,0 +1,515 @@ +/** + **************************************************************************************** + * + * @file hci.h + * + * @brief This file contains definitions related to the HCI module. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef HCI_H_ +#define HCI_H_ + +/** + **************************************************************************************** + * @addtogroup HCI Host Controller Interface + * @ingroup ROOT + * @brief HCI module handling communication between lower and higher layers in split + * architecture. + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // SW configuration + +#if (HCI_PRESENT) + +#include // standard definition +#include // standard integer +#include "co_bt.h" // BT standard definitions + +#include "rwip_task.h" // Task definitions + +/* + * DEFINES + **************************************************************************************** + */ + +#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT) +#if (BLE_CENTRAL || BLE_PERIPHERAL) +#define HCI_BLE_CON_SUPPORT 1 +#else // (BLE_CENTRAL || BLE_PERIPHERAL) +#define HCI_BLE_CON_SUPPORT 0 +#endif // (BLE_CENTRAL || BLE_PERIPHERAL) +#else //(BLE_EMB_PRESENT || BLE_HOST_PRESENT) +#define HCI_BLE_CON_SUPPORT 0 +#endif //(BLE_EMB_PRESENT || BLE_HOST_PRESENT) + +/// Length of HCI Reset Message +#define HCI_RESET_MSG_LEN 4 + +/// HCI Reset Message use to resync. +#define HCI_RESET_MSG_BUF {HCI_CMD_MSG_TYPE, (HCI_RESET_CMD_OPCODE & 0xFF), ((HCI_RESET_CMD_OPCODE >> 8) & 0xFF), 0} + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Message API of the HCI task +/*@TRACE*/ +enum hci_msg_id +{ + HCI_MSG_ID_FIRST = TASK_FIRST_MSG(TASK_ID_HCI), + + HCI_CMD_CMP_EVENT, + HCI_CMD_STAT_EVENT, + HCI_EVENT, + HCI_LE_EVENT, + + HCI_COMMAND, + + #if (HCI_BLE_CON_SUPPORT || BT_EMB_PRESENT) + HCI_ACL_DATA, + #endif // (HCI_BLE_CON_SUPPORT) + + #if BT_EMB_PRESENT + #if VOICE_OVER_HCI + HCI_SYNC_DATA, + #endif //VOICE_OVER_HCI + #endif //BT_EMB_PRESENT + + HCI_DBG_EVT, + + HCI_MSG_ID_LAST +}; + +/// Status of HCI command header processing +enum HCI_CMD_HDR +{ + /// Header is correct + HCI_CMD_HDR_STATUS_OK, + /// Opcode is unknown + HCI_CMD_HDR_STATUS_UNKNOWN, + /// Header is not correct + HCI_CMD_HDR_STATUS_FAIL +}; + + + +///HCI Command header components structure +struct hci_cmd_hdr +{ + /// Opcode field + uint16_t opcode; + ///Parameter length - the number of bytes of the command parameters + uint8_t parlen; +}; + +///HCI ACL data packets header structure +struct hci_acl_hdr +{ + ///Connection handle & Data Flags + uint16_t hdl_flags; + ///Data length in number of bytes + uint16_t datalen; +}; + +#if (BT_EMB_PRESENT) +#if (VOICE_OVER_HCI) +///HCI synchronous data packets header structure +struct hci_sync_hdr +{ + /// Connection handle & Data Flags + uint16_t conhdl_flags; + /// Data total length in number of bytes + uint8_t data_total_len; +}; +#endif // (VOICE_OVER_HCI) +#endif // (BT_EMB_PRESENT) + +///HCI Event header components structure - contains all details possible in an event +struct hci_evt_hdr +{ + ///Event code + uint8_t code; + ///Event parameters length + uint8_t parlen; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** +**************************************************************************************** +* @brief Initialize HCI (including transport) +* +* @param[in] init_type Type of initialization (@see enum rwip_init_type) +***************************************************************************************** +*/ +void hci_init(uint8_t init_type); + +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/** + **************************************************************************************** + * @brief Function called when an internal task needs to send a HCI message to Host + * + * This function decides whether the message is sent externally onto HCI Transport Layer + * or redirected into an internal task of the other side of the HCI. + * + * The input message ID, length and parameters must be filled. + * In case the message is an HCI command or event, the source ID must be filled with the + * command opcode or event code. + * In case the message concerns a particular BT or BLE link, the destination ID must be + * filled with the associated link ID. + * + * @param[in] param Pointer to the parameters of the Kernel message carrying the HCI message + ***************************************************************************************** + */ +void hci_send_2_host(void *param); +#endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + +#if BLE_HOST_PRESENT +/** + **************************************************************************************** + * @brief Function called when an internal task needs to send a HCI message to Controller + * + * This function decides whether the message is sent externally onto HCI Transport Layer + * or redirected into an internal task of the other side of the HCI. + * + * The input message ID, length and parameters must be filled. + * In case the message is an HCI command or event, the source ID must be filled with the + * command opcode or event code. + * In case the message concerns a particular BT or BLE link, the destination ID must be + * filled with the associated link ID. + * + * @param[in] param Pointer to the parameters of the Kernel message carrying the HCI message + ***************************************************************************************** + */ +void hci_send_2_controller(void *param); + +/** + **************************************************************************************** + * @brief function used to send a basic command, without parameters to the controller. + * + * @param[in] opcode Operation code of the command + ***************************************************************************************** + */ +void hci_basic_cmd_send_2_controller(uint16_t opcode); +#endif //BLE_HOST_PRESENT + +#if (BLE_EMB_PRESENT && HCI_BLE_CON_SUPPORT) +/** + **************************************************************************************** + * @brief Register connection handle for a BLE connection + * + * @param[in] link_id BLE connection link ID + ***************************************************************************************** + */ +void hci_ble_conhdl_register(uint8_t link_id); + +/** + **************************************************************************************** + * @brief Unregister a BLE connection + * + * @param[in] link_id BLE connection link ID + ***************************************************************************************** + */ +void hci_ble_conhdl_unregister(uint8_t link_id); +#endif //(BLE_EMB_PRESENT && !BLE_HOST_PRESENT && HCI_BLE_CON_SUPPORT) + +#if (BT_EMB_PRESENT) +/** + **************************************************************************************** + * @brief Register BD address for a BT ACL connection + * + * @param[in] link_id BT ACL connection link ID + * @param[in] bd_addr Pointer to the device BD address associated to the connection + ***************************************************************************************** + */ +void hci_bt_acl_bdaddr_register(uint8_t link_id, struct bd_addr* bd_addr); +/** + **************************************************************************************** + * @brief Register connection handle for a BT ACL connection + * + * @param[in] link_id BT ACL connection link ID + ***************************************************************************************** + */ +void hci_bt_acl_conhdl_register(uint8_t link_id); + +/** + **************************************************************************************** + * @brief Unregister a BT ACL connection + * + * @param[in] link_id BT ACL connection link ID + ***************************************************************************************** + */ +void hci_bt_acl_bdaddr_unregister(uint8_t link_id); + +#endif //(BT_EMB_PRESENT) + +/** + **************************************************************************************** + * @brief Set the event mask + * + * @param[in] evt_msk Pointer to the new event mask + * @param[in] page indicate which event page should be changed + * + * @return The status of the event mask saving + ***************************************************************************************** + */ +uint8_t hci_evt_mask_set(struct evt_mask const *evt_msk, uint8_t page); + +#if (BT_EMB_PRESENT) +/** + **************************************************************************************** + * @brief Add an event filter according to the parameters of the HCI command + * + * Note: the consistency of the parameters according to the input has already been checked by HCI during the special + * unpacking. + * + * @param[in] param Pointer to the HCI parameter + * + * @return The status of the filter addition + ***************************************************************************************** + */ +uint8_t hci_evt_filter_add(struct hci_set_evt_filter_cmd const *param); + +#if (MAX_NB_SYNC > 0) +/** + **************************************************************************************** + * @brief Get voice setting (for SCO auto-accept via event filter) + * + * @return Voice settings + ***************************************************************************************** + */ +uint16_t hci_voice_settings_get(void); + +/** + **************************************************************************************** + * @brief Set voice setting (for SCO auto-accept via event filter) + * + * @param[in] voice_settings Voice settings + * + * @return Status (0: Success | Others: failure) + ***************************************************************************************** + */ +uint8_t hci_voice_settings_set(uint16_t voice_settings); +#endif // (MAX_NB_SYNC > 0) +#endif //(BT_EMB_PRESENT) + +#if (HCI_TL_SUPPORT) +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/** + **************************************************************************************** + * @brief Get the maximum parameter size for a specific command + * + * This function is used by TL to know the theoretical maximum parameters size for a + * specific HCI command. + * Note: if the command is not supported by HCI (unknown), the maximum possible value of + * 255 bytes is returned. + * + * @param[in] opcode Opcode received + * + * @return The command maximum parameters size / 255 if command is unknown + ***************************************************************************************** + */ +uint8_t hci_cmd_get_max_param_size(uint16_t opcode); + +/** + **************************************************************************************** + * @brief Indicates that a HCI command has been received + * + * This function is used by TL to indicate the reception of a HCI command. + * + * @param[in] opcode Command Opcode + * @param[in] length Parameters length + * @param[in] payload Pointer to payload + ***************************************************************************************** + */ +void hci_cmd_received(uint16_t opcode, uint8_t length, uint8_t *payload); + +/** + **************************************************************************************** + * @brief Allocates the reception buffer for ACL TX data + * + * @param[in] hdl_flags Connection handle and data flags from HCI ACL packet header + * @param[in] len Length to receive (from HCI ACL packet header) + * + * @return Buffer for data reception (NULL if not possible to allocate one) + ***************************************************************************************** + */ +uint8_t* hci_acl_tx_data_alloc(uint16_t hdl_flags, uint16_t len); + +/** + **************************************************************************************** + * @brief Indicates that a HCI ACL TX data packet has been received + * + * This function is used by TL to indicate the reception of a HCI ACL TX data. + * + * @param[in] hdl_flags Connection handle and data flags from HCI ACL packet header + * @param[out] datalen Data length + * @param[in] payload Pointer to payload + ***************************************************************************************** + */ +void hci_acl_tx_data_received(uint16_t hdl_flags, uint16_t datalen, uint8_t * payload); + +#if (BT_EMB_PRESENT) +#if (VOICE_OVER_HCI) +/** + **************************************************************************************** + * @brief Allocates the reception buffer for Sync TX data + * + * @param[in] conhdl_flags Connection handle and data flags from HCI Sync packet header + * @param[in] len Length to receive (from HCI Sync packet header) + * + * @return Buffer for data reception (NULL if not possible to allocate one) + ***************************************************************************************** + */ +uint8_t* hci_sync_tx_data_alloc(uint16_t conhdl_flags, uint8_t len); + +/** + **************************************************************************************** + * @brief Indicates that a HCI Sync TX data packet has been received + * + * This function is used by TL to indicate the reception of a HCI Sync TX data. + * + * @param[in] conhdl_flags Connection handle and data flags from HCI Sync packet header + * @param[in] len Length to receive (from HCI Sync packet header) + * @param[in] payload Pointer to payload + ***************************************************************************************** + */ +void hci_sync_tx_data_received(uint16_t conhdl_flags, uint8_t len, uint8_t * payload); +#endif // (VOICE_OVER_HCI) +#endif // (BT_EMB_PRESENT) +#endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + +#if ((BLE_HOST_PRESENT) && (!BLE_EMB_PRESENT)) +/** + **************************************************************************************** + * @brief Allocates the reception buffer for ACL RX data + * + * @param[in] hdl_flags Connection handle and data flags from HCI ACL RX packet header + * @param[in] len Length to receive (from HCI ACL packet header) + * + * @return Buffer for data reception (NULL if not possible to allocate one) + ***************************************************************************************** + */ +uint8_t* hci_acl_rx_data_alloc(uint16_t hdl_flags, uint16_t len); + +/** + **************************************************************************************** + * @brief Indicates that a HCI ACL RX data packet has been received + * + * This function is used by TL to indicate the reception of a HCI ACL RX data. + * + * @param[in] hdl_flags Connection handle and data flags from HCI ACL packet header + * @param[out] datalen Data length + * @param[in] payload Pointer to payload + ***************************************************************************************** + */ +void hci_acl_rx_data_received(uint16_t hdl_flags, uint16_t datalen, uint8_t * payload); + +/** + **************************************************************************************** + * @brief Indicates that a HCI event has been received + * + * This function is used by TL to indicate the reception of a HCI event. + * + * @param[in] code Event code + * @param[in] length Parameters length + * @param[in] payload Pointer to payload + * + * @return status of receive operation + ***************************************************************************************** + */ +uint8_t hci_evt_received(uint8_t code, uint8_t length, uint8_t *payload); +#endif // ((BLE_HOST_PRESENT) && (!BLE_EMB_PRESENT)) + +#endif // HCI_TL_SUPPORT + +//common for both BLE & BT +/** + **************************************************************************************** + * @brief process HostBufferSize + * + * @param[in] acl_pkt_len ACL packet length + * @param[in] nb_acl_pkts Number of ACL packets + * + * @return status + ***************************************************************************************** + */ +uint8_t hci_fc_acl_buf_size_set(uint16_t acl_pkt_len, uint16_t nb_acl_pkts); +/** + **************************************************************************************** + * @brief process HostBufferSize + * + * @param[in] sync_pkt_len SYNC packet length + * @param[in] nb_sync_pkts Number of SYNC packets + * + * @return status + ***************************************************************************************** + */ +uint8_t hci_fc_sync_buf_size_set(uint8_t sync_pkt_len, uint16_t nb_sync_pkts); + +/** + **************************************************************************************** + * @brief set the state of the ACL flow control + * + * @param[in] flow_enable boolean state of control + * + * @return status + ***************************************************************************************** + */ +uint8_t hci_fc_acl_en(bool flow_enable); + +/** + **************************************************************************************** + * @brief set the state of the SYNC flow control + * + * @param[in] flow_enable boolean state of control + ***************************************************************************************** + */ +void hci_fc_sync_en(bool flow_enable); + +/** + **************************************************************************************** + * @brief update data packet counters according to HostNumberOfCompletePackets + * + * @param[in] acl_pkt_nb accumulated number for ACL handles + ***************************************************************************************a** + */ +void hci_fc_host_nb_acl_pkts_complete(uint16_t acl_pkt_nb); + +/** + **************************************************************************************** + * @brief update data packet counters according to HostNumberOfCompletePackets + * + * @param[in] sync_pkt_nb accumulated number for SCO handles + ***************************************************************************************a** + */ +void hci_fc_host_nb_sync_pkts_complete(uint16_t sync_pkt_nb); + +#endif //HCI_PRESENT + +/// @} HCI + +#endif // HCI_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_alarm.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_alarm.h new file mode 100644 index 0000000..4a947c4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_alarm.h @@ -0,0 +1,138 @@ +/** +**************************************************************************************** +* +* @file sch_alarm.h +* +* @brief sch_alarm main module +* +* Copyright (C) RivieraWaves 2009-2017 +* +* +**************************************************************************************** +*/ + +#ifndef _SCH_ALARM_H_ +#define _SCH_ALARM_H_ + +/** + **************************************************************************************** + * @addtogroup SCH + * @brief Entry points of the Scheduling alaram module + * + * @{ + **************************************************************************************** + */ + +#include "rwip_config.h" + +#include // Standard integer definitions +#include // Standard boolean definitions +#include "co_list.h" // List management functions definitions + + +/* + * MACROS + **************************************************************************************** + */ + + + +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * DEFINITIONS + **************************************************************************************** + */ + +/// SCH_ALARM error codes +enum sch_alarm_error +{ + /// SCH_ALARM request succeed + SCH_ALARM_ERROR_OK = 0, + /// SCH_ALARM request rejected error + SCH_ALARM_ERROR_REJECTED, + /// SCH_ALARM element not found error + SCH_ALARM_ERROR_NOT_FOUND, + /// SCH_ALARM request rejected due to bandwidth full error + SCH_ALARM_ERROR_BW_FULL +}; + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Alarm element structure +struct sch_alarm_tag +{ + /// List element for chaining in the Even Arbiter lists + struct co_list_hdr hdr; + + /// Timestamp of alarm expiry (in BT half-slots) + uint32_t timestamp; + + /// Call back function invoked upon alarm expiry + void (*cb_alarm)(struct sch_alarm_tag*); +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize the Scheduling alarm. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void sch_alarm_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Alarm interrupt handler + * + * This function is called under interrupt when an alarm is triggered. + * + **************************************************************************************** + */ +void sch_alarm_timer_isr(void); + +/** + **************************************************************************************** + * @brief Set an alarm + * + * If the alarm specify an instant in the past, the alarm is scheduled for earliest + * possible time. + * + * @param[in] elt Pointer to the alarm element to be programmed + **************************************************************************************** + */ +void sch_alarm_set(struct sch_alarm_tag* elt); + +/** + **************************************************************************************** + * @brief Clear an alarm + * + * @param[in] elt Pointer to the alarm element to be cleared + * + * @return 0 - no error / 1:255 - error + **************************************************************************************** + */ +uint8_t sch_alarm_clear(struct sch_alarm_tag* elt); + +///@} SCH_ALARM + +#endif // _SCH_ALARM_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_arb.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_arb.h new file mode 100644 index 0000000..d339d5e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_arb.h @@ -0,0 +1,270 @@ +/** +**************************************************************************************** +* +* @file SCH_ARB.h +* +* @brief SCH_ARB main module +* +* Copyright (C) RivieraWaves 2009-2017 +* +* +**************************************************************************************** +*/ + +#ifndef _SCH_ARB_H_ +#define _SCH_ARB_H_ + +/** + **************************************************************************************** + * @addtogroup SCH + * @brief Entry points of the Scheduling Arbiter module + * + * This module contains the primitives that allow stacks to schedule an event or frame. + * + * @{ + **************************************************************************************** + */ + +#include "rwip_config.h" + +#include // Standard integer definitions +#include // Standard boolean definitions +#include "co_list.h" // List management functions definitions +#include "rwip.h" // For rwip_time_t + + +/* + * MACROS + **************************************************************************************** + */ + + + +/* + * DEFINES + **************************************************************************************** + */ + +/// Default BW 2 slots +#define SCH_ARB_BW_USED_DFT_SLOT (2) +#define SCH_ARB_BW_USED_DFT_US (SCH_ARB_BW_USED_DFT_SLOT*SLOT_SIZE) + + +/// Set ASAP settings +#define SCH_ARB_ASAP_STG_SET(evt, type, phase, resched_att, prio_inc) evt->asap_settings = ( (((type) << 14) & 0xC000) | (((phase) << 11) & 0x3800) | (((resched_att) << 4) & 0x03F0) | (((prio_inc) << 0) & 0x000F) ); +/// Get/Set type from ASAP settings +#define SCH_ARB_ASAP_STG_TYPE_GET(evt) ((uint8_t)((evt->asap_settings & 0xC000) >> 14)) +#define SCH_ARB_ASAP_STG_TYPE_SET(evt, type) ( evt->asap_settings = ((evt->asap_settings & ~(0xC000)) | (((type) << 14) & 0xC000)) ) +/// Get phase from ASAP settings +#define SCH_ARB_ASAP_STG_PHASE_GET(evt) ((uint8_t)((evt->asap_settings & 0x3800) >> 11)) +/// Get/Set rescheduling attempts from ASAP settings +#define SCH_ARB_ASAP_STG_RESCHED_ATT_GET(evt) ((uint8_t)((evt->asap_settings & 0x03F0) >> 4)) +#define SCH_ARB_ASAP_STG_RESCHED_ATT_SET(evt, resched_att) ( evt->asap_settings = ((evt->asap_settings & ~(0x03F0)) | (((resched_att) << 4) & 0x03F0)) ) +/// Get priority increment from ASAP settings +#define SCH_ARB_ASAP_STG_PRIO_INC_GET(evt) ((uint8_t)((evt->asap_settings & 0x000F) >> 0)) + +/// Maximum SCH_ARB element duration in half-us +#define SCH_ARB_MAX_DURATION (400000) + + +/* + * DEFINITIONS + **************************************************************************************** + */ + +/// SCH_ARB error codes +enum sch_arb_error +{ + /// SCH_ARB request succeed + SCH_ARB_ERROR_OK = 0, + /// SCH_ARB request rejected error + SCH_ARB_ERROR_REJECTED, + /// SCH_ARB element not found error + SCH_ARB_ERROR_NOT_FOUND, + /// SCH_ARB request rejected due to bandwidth full error + SCH_ARB_ERROR_BW_FULL +}; + +/// ASAP type definition +/*@TRACE*/ +enum sch_arb_elt_asap_type +{ + /// 00: No ASAP + SCH_ARB_FLAG_NO_ASAP = 0, + /// 01: ASAP no limit + SCH_ARB_FLAG_ASAP_NO_LIMIT, + /// 10: ASAP with limit + SCH_ARB_FLAG_ASAP_LIMIT, + SCH_ARB_FLAG_MAX +}; + +/// ASAP slot parity definition +enum sch_arb_elt_asap_phase +{ + SCH_ARB_PHASE_0, + SCH_ARB_PHASE_1, + SCH_ARB_PHASE_2, + SCH_ARB_PHASE_3, + SCH_ARB_NO_PHASE, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + + +/// Scheduling Arbiter Element +/*@TRACE*/ +struct sch_arb_elt_tag +{ + /// List element for chaining in the Even Arbiter lists + struct co_list_hdr hdr; + + /// Programming time expressed in half-slots and half-us + rwip_time_t time; + + /// Scheduling time limit in base time (half-slots) (only for ASAP LIMIT requests) + uint32_t asap_limit; + + /// Minimum duration of the event or frame (in half-us) + uint32_t duration_min; + + /** + * ASAP settings field + * bit |15 14|13 12 11| 10 | 9..4 | 3..0 | + * def | TYPE | Phase | To protect | Resched att | Prio inc | + * + * Type: + * - 00: No ASAP + * - 01: ASAP no limit + * - 10: ASAP with limit + * - 11: ASAP with limit, no parity check + * + * Phase: (only for ASAP requests) + * - 0: phase 0 + * - 1: phase 1 + * - 2: phase 2 + * - 3: phase 3 + * - 4: don't care + * + * Number of rescheduling attempts: + * - The remaining number of rescheduling attempts. + * - Rescheduling happens when the event is overlapped by a higher priority event + * - Only used for ASAP requests + * + * Priority increment: + * - The current priority value is incremented each time the event is overlapped by a new insertion and postponed + * - Only used for ASAP requests + */ + /*@trc_desc + *bit |15..14| 13..11 | 10 | 9..4 | 3..0 | + *def | Type | Phase | Rsvd | Resched_att | Prio_inc | + * + *Phase: only if Type = 01..11 + *Resched_att: only if Type = 01..11 + *Prio_inc: only if Type = 01..11 + * + *@trc_ref Type: + * - 00: No ASAP + * - 01: ASAP no limit + * - 10: ASAP with limit + * - 11: ASAP with limit and no parity check + * + *@trc_ref Phase: + * - 000: phase 0 + * - 001: phase 1 + * - 010: phase 2 + * - 011: phase 3 + * - 100: don-t care + */ + uint16_t asap_settings; + + /// Current priority + uint8_t current_prio; + /// Latency to notify to stop the activity before next activity is notified to start (in half-slots, 0 if no stop required) + uint8_t stop_latency; + + /************************************************************************************ + * ISR CALLBACKS + ************************************************************************************/ + + /// Start notification call back function + void (*cb_start)(struct sch_arb_elt_tag*); + /// Stop notification call back function + void (*cb_stop)(struct sch_arb_elt_tag*); + /// Cancel notification call back function + void (*cb_cancel)(struct sch_arb_elt_tag*); +}; + + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize the Scheduling Arbiter. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void sch_arb_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Insert a new reservation in the schedule + * + * @param[in] elt Pointer to the element to be inserted + * + * @return No error if element is inserted. + **************************************************************************************** + */ +uint8_t sch_arb_insert(struct sch_arb_elt_tag *elt); + +/** + **************************************************************************************** + * @brief Remove a reservation + * + * @param[in] elt Pointer to the element to be removed from current ptr + * @param[in] not_waiting True: activity is already started | False: may be waiting or not + * + **************************************************************************************** + */ +uint8_t sch_arb_remove(struct sch_arb_elt_tag *elt, bool not_waiting); + +/** + **************************************************************************************** + * @brief Start of event/frame interrupt handler + * + * This function is called under interrupt when a start of event/frame interrupt is + * generated by the BLE/BT core. + * + **************************************************************************************** + */ +void sch_arb_event_start_isr(void); + + +/** + **************************************************************************************** + * @brief Software interrupt handler + * + * This function is called under interrupt when a SW interrupt is generated by the BLE/BT + * core. + * + **************************************************************************************** + */ +void sch_arb_sw_isr(void); + + +///@} SCH_ARB + +#endif // _SCH_ARB_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_plan.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_plan.h new file mode 100644 index 0000000..a136710 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_plan.h @@ -0,0 +1,230 @@ +/** +**************************************************************************************** +* +* @file SCH_PLAN.h +* +* @brief SCH_PLAN main module +* +* Copyright (C) RivieraWaves 2009-2018 +* +* +**************************************************************************************** +*/ + +#ifndef _SCH_PLAN_H_ +#define _SCH_PLAN_H_ + +/** + **************************************************************************************** + * @addtogroup SCH + * @brief Entry points of the Scheduling Planner module + * + * This module contains the primitives that allow stacks to plan periodic activities + * + * @{ + **************************************************************************************** + */ + +#include // Standard integer definitions +#include // Standard boolean definitions +#include "co_list.h" // List management functions definitions + + +/* + * MACROS + **************************************************************************************** + */ + + + +/* + * DEFINES + **************************************************************************************** + */ + + + +/* + * DEFINITIONS + **************************************************************************************** + */ + +/// SCH_PLAN error codes +enum sch_plan_error +{ + /// SCH_PLAN request succeed + SCH_PLAN_ERROR_OK = 0, + /// SCH_PLAN request rejected error + SCH_PLAN_ERROR_REJECTED, + /// SCH_PLAN element not found error + SCH_PLAN_ERROR_NOT_FOUND, + /// SCH_PLAN request rejected due to bandwidth full error + SCH_PLAN_ERROR_BW_FULL +}; + +/// SCH_PLAN mobility levels +enum sch_plan_mb_lvl +{ + /// SCH_PLAN mobility level 0 (not movable) + SCH_PLAN_MB_LVL_0 = 0, + /// SCH_PLAN mobility level 1 + SCH_PLAN_MB_LVL_1, + /// SCH_PLAN mobility level 2 + SCH_PLAN_MB_LVL_2, + /// SCH_PLAN mobility level 3 + SCH_PLAN_MB_LVL_3, + /// SCH_PLAN mobility level 4 + SCH_PLAN_MB_LVL_4 +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Interval element strcuture +struct sch_plan_elt_tag +{ + /// List element for chaining in the Interval list + struct co_list_hdr hdr; + /// Interval used (in slots) + uint32_t interval; + /// Offset used (in slots) + uint32_t offset; + /// Minimum duration (in slots) + uint32_t duration_min; + /// Maximum duration (in slots) + uint32_t duration_max; + /// Connection handle used + uint16_t conhdl; + /// Mobility level + uint8_t mobility; + /************************************************************************************ + * ISR CALLBACKS + ************************************************************************************/ + /// Move notification call back function + void (*cb_move)(uint16_t id); + +}; + +/// API request parameters +struct sch_plan_req_param +{ + /// Interval minimum requested (in slots) + uint32_t interval_min; + /// Interval maximum requested (in slots) + uint32_t interval_max; + /// Duration minimum requested (in slots) + uint32_t duration_min; + /// Duration maximum requested (in slots) + uint32_t duration_max; + /// Connection handle + uint16_t conhdl; + /// Preferred periodicity (in slots) + uint8_t pref_period; + /// Odd offset or even offset + bool odd_offset; + /// Interval returned (in slots) + uint32_t interval; + /// Min offset returned (in slots) + uint32_t offset_min; + /// Max offset returned (in slots) + uint32_t offset_max; +}; + +/// API check parameters +struct sch_plan_chk_param +{ + /// Interval (in slots) + uint32_t interval; + /// Duration minimum requested (in slots) + uint32_t duration_min; + /// Offset requested (in slots) + uint32_t offset; + /// Connection handle + uint16_t conhdl; +}; + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize the Scheduling Planner. + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void sch_plan_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Insert the element in the common element queue + **************************************************************************************** + */ +void sch_plan_set(struct sch_plan_elt_tag *elt_to_add); + +/** + **************************************************************************************** + * @brief Remove the element from the common element queue + **************************************************************************************** + */ +void sch_plan_rem(struct sch_plan_elt_tag *elt_to_remove); + +/** + **************************************************************************************** + * @brief Choose appropriate parameters for the activity + * + * @param[in] input_param parameters used to compute output values + * + * @param[in] output_param appropriate parameters for the activity + * + * @return See sch_plan_error error codes + **************************************************************************************** + */ +uint8_t sch_plan_req(struct sch_plan_req_param* req_param); + +/** + **************************************************************************************** + * @brief Check if the provided offset is acceptable + * + * @param[in] input_param parameters used to perform the check + * + * @param[in] output_param offset used for the interval + * + * @return See sch_plan_error error codes + **************************************************************************************** + */ +uint8_t sch_plan_chk(struct sch_plan_chk_param* chk_param); + +/** + **************************************************************************************** + * @brief Choose an appropriate offset according to the interval with a required air duration + * + * @param[in] link_id Link identifier + * @param[in] role Role of the activity + * @param[in] interval Activity interval (in slots) + * @param[in] duration Activity event duration (in slots) + * @param[in|out] min_offset Minimum Activity offset as input/computed (in slots) + * @param[in|out] max_offset Maximum Activity offset as input/computed (in slots) + * + * @return - SCH_PLAN_ERROR_OK if succeed + * - SCH_PLAN_ERROR_REJECTED if invalid parameters + * - SCH_PLAN_ERROR_BW_FULL if not able to find available bandwidth + **************************************************************************************** + */ +uint8_t sch_plan_position_range_compute(uint8_t link_id, uint8_t role, uint16_t interval, uint16_t duration, + uint16_t* min_offset, uint16_t* max_offset); + + +///@} SCH_PLAN + +#endif // _SCH_PLAN_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_prog.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_prog.h new file mode 100644 index 0000000..739388d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_prog.h @@ -0,0 +1,268 @@ +/** +**************************************************************************************** +* +* @file sch_prog.h +* +* @brief Scheduling Programmer API +* +* Copyright (C) RivieraWaves 2009-2017 +* +**************************************************************************************** +*/ + +#ifndef SCH_PROG_H_ +#define SCH_PROG_H_ + +/** + **************************************************************************************** + * @defgroup SCH_PROG Scheduling Programmer + * @ingroup SCH + * @brief Responsible for programming BT/BLE frames. + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // stack configuration + +#include // integer +#include // boolean + +/* + * DEFINES + **************************************************************************************** + */ + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Mode +enum SCH_FRAME_TYPE +{ + SCH_PROG_BLE, + SCH_PROG_BT, +}; + +/// Frame type +enum SCH_FRAME_IRQ +{ + /// Normal End of Event + SCH_FRAME_IRQ_EOF = 0x00, + /// End of event due to an abort + SCH_FRAME_IRQ_EOF_ABORT = 0x01, + /// SKIP Event IRQ + SCH_FRAME_IRQ_SKIP = 0x04, + /// RX ACL IRQ + SCH_FRAME_IRQ_RX = 0x02, + /// TX ACL IRQ + SCH_FRAME_IRQ_TX = 0x03, + + #if (BLE_ISO_PRESENT) + /// RX ISO IRQ + SCH_FRAME_IRQ_RX_ISO = 0x05, + /// TX ISO IRQ + SCH_FRAME_IRQ_TX_ISO = 0x06, + #endif // (BLE_ISO_PRESENT) +}; + +#if BT_EMB_PRESENT +/// Frame type +enum SCH_BT_FRAME_TYPE +{ + SCH_BT_FRAME_TYPE_NORMAL = 0x00, + SCH_BT_FRAME_TYPE_SNIFF = 0x01, + SCH_BT_FRAME_TYPE_ESCO = 0x02, + SCH_BT_FRAME_TYPE_CSB = 0x03, + SCH_BT_FRAME_TYPE_ESCO_RETX = 0x04, +}; +#endif //BT_EMB_PRESENT + + +/* + * STRUCTURE DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Callback for interrupt related to the frame + * + * @param[in] timestamp Timestamp of the programmed frame (in BLE slots, based on local clock) + * @param[in] dummy Dummy value (provided by the driver when programming the frame via sch_prog_push) + * @param[in] irq_type IRQ type (0: End Of Frame | 1: RX) + **************************************************************************************** + */ +typedef void (*frm_cbk_t)(uint32_t timestamp, uint32_t dummy, uint8_t irq_type); + +#if BT_EMB_PRESENT +/** + **************************************************************************************** + * @brief Callback for interrupt related to the clock IRQ + * + * @param[in] clock Clock when the IRQ happened + * @param[in] id Identification value + **************************************************************************************** + */ +typedef void (*clk_cbk_t)(uint32_t clock, uint8_t id); +#endif //BT_EMB_PRESENT + +#if BLE_EMB_PRESENT +/// Additional parameters for BLE frame +struct sch_prog_params_ble +{ + /// Advertising channel type: 0x0: AE Start on Primary channel | 0x1: AE Start on Secondary channel + uint8_t ae_nps; + /// Reserved audio event (0: reTx, 1:primary) + uint8_t rsvd; + /// Isochronous event (0: normal event | 1: iso event) + uint8_t iso; +}; +#endif //BLE_EMB_PRESENT + +#if BT_EMB_PRESENT +/// Additional parameters for BT frame +struct sch_prog_params_bt +{ + /// Frame type (0: normal | 1: sniff | 2: ESCO | 3: CSB) + uint8_t frm_type; + /// Voice channel + uint8_t vxchan; +}; +#endif //BT_EMB_PRESENT + +/// Parameters for a programmed frame +struct sch_prog_params +{ + /// Callback for handling interrupts related to the frame + frm_cbk_t frm_cbk; + /// Timestamp (in half-slots, based on local clock) and event offset (in half-us) of the programmed frame + rwip_time_t time; + /// Bandwidth duration of the event using priority 1 (in half us) + uint32_t bandwidth; + /// Dummy value reported when an event happen during the frame or the frame is completed + uint32_t dummy; + /// Priority during duration of bandwidth + uint8_t prio_1; + /// Priority after bandwidth elapsed + uint8_t prio_2; + /// Priority after trigger conditions + uint8_t prio_3; + /// Priority when specific action occurs during the event + uint8_t pti_prio; + /// Control structure index + uint8_t cs_idx; + /// Mode (0: BLE, 1:BT) + uint8_t mode; + + union + { + #if BLE_EMB_PRESENT + /// Additional parameters for BLE frame + struct sch_prog_params_ble ble; + #endif //BLE_EMB_PRESENT + + #if BT_EMB_PRESENT + /// Additional parameters for BT frame + struct sch_prog_params_bt bt; + #endif //BT_EMB_PRESENT + } add; +}; + + +/* + * FUNCTIONS DECLARATION + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize the SCH_PROG module + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void sch_prog_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Handle "RX" interrupt + * + * @param[in] et_idx Entry index that trigger the ISR (@note Valid only with 5.0 + ISO HW) + **************************************************************************************** + */ +void sch_prog_rx_isr(uint8_t et_idx); + +/** + **************************************************************************************** + * @brief Handle FIFO interrupt + **************************************************************************************** + */ +void sch_prog_fifo_isr(void); + +/** +**************************************************************************************** +* @brief Push a new programmed frame +* +* @param[in] params Parameters structure +**************************************************************************************** +*/ +void sch_prog_push(struct sch_prog_params* params); + +#if BT_EMB_PRESENT +/** + **************************************************************************************** + * @brief Enable the programming of an activity + * + * @param[in] clk_cbk Callback for handling interrupts related to the clock + * @param[in] id Identification value + * @param[in] sr_size Size of the sub rating pattern (in number of bits), 0 if no sub rating + * @param[in] sr_val Sub rating pattern value, representing the clock LSBs when interrupt is raised + **************************************************************************************** + */ +void sch_prog_enable(clk_cbk_t clk_cbk, uint8_t id, uint8_t sr_size, uint8_t sr_val); + +/** + **************************************************************************************** + * @brief Disable the programming of an activity + * + * @param[in] id Identification value + **************************************************************************************** + */ +void sch_prog_disable(uint8_t id); + +/** + **************************************************************************************** + * @brief Handle "clock" interrupt + **************************************************************************************** + */ +void sch_prog_clk_isr(void); + +/** + **************************************************************************************** + * @brief Handle "Skip" interrupt + * + * @param[in] et_idx Entry index that trigger the ISR (@note Valid only with 5.0 + ISO HW) + **************************************************************************************** + */ +void sch_prog_skip_isr(uint8_t et_idx); + +/** + **************************************************************************************** + * @brief Handle "End of Event" interrupt + * + * @param[in] et_idx Entry index that trigger the ISR (@note Valid only with 5.0 + ISO HW) + **************************************************************************************** + */ +void sch_prog_end_isr(uint8_t et_idx); + +#endif //BT_EMB_PRESENT + +/// @} SCH_PROG +#endif // SCH_PROG_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_slice.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_slice.h new file mode 100644 index 0000000..303ac8d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api/sch_slice.h @@ -0,0 +1,181 @@ +/** +**************************************************************************************** +* +* @file sch_slice.h +* +* @brief LD Scheduling Parameters API +* +* Copyright (C) RivieraWaves 2009-2015 +* +**************************************************************************************** +*/ + +#ifndef SCH_SLICE_H_ +#define SCH_SLICE_H_ + +/** + **************************************************************************************** + * @defgroup SCHSLICE Scheduling parameters + * @ingroup SCH + * @brief Responsible for selecting the optimal scheduling parameters. + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // stack configuration + +#include // integer +#include // boolean + +/* + * DEFINES + **************************************************************************************** + */ + +/// Undefined BT clock value +#define SCH_CLOCK_UNDEF 0xFFFFFFFF + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Activity type +enum activity_type +{ + #if BLE_EMB_PRESENT + BLE_SCAN, + BLE_INIT, + BLE_HDC_ADV, + BLE_PER_ADV, + BLE_CON, + #endif //BLE_EMB_PRESENT + + #if BT_EMB_PRESENT + BT_INQ, + BT_PAGE, + BT_ISCAN, + BT_PSCAN, + BT_SSCAN, + BT_SNIFF, + BT_SCO, + #endif //BT_EMB_PRESENT +}; + + +/* + * STRUCTURE DEFINITIONS + **************************************************************************************** + */ + +/// SCH SLICE parameters structure +struct sch_slice_params_tag +{ + /// End of ongoing foreground activity (inq, page, HDC adv) (in BT half-slot clock, SCH_CLOCK_UNDEF if inactive) + uint32_t fg_end_ts; + + /// Scan / Inq / Page event duration (in half-us) + uint16_t scan_evt_dur; + + #if BT_EMB_PRESENT + /// ACL event duration size (in half-us) + uint16_t acl_evt_dur; + + /// SCO retx are allowed to reserve + bool sco_retx_allowed; + #endif //BT_EMB_PRESENT +}; + + +/* + * VARIABLE DECLARATION + **************************************************************************************** + */ + +/// SCH SLICE parameters variable +extern struct sch_slice_params_tag sch_slice_params; + + +/* + * FUNCTIONS DECLARATION + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize the SCH_SLICE module + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void sch_slice_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Add a background activity + * + * @param[in] type Activity type (@see @enum activity_type) + **************************************************************************************** + */ +void sch_slice_bg_add(uint8_t type); + +/** + **************************************************************************************** + * @brief Remove a background activity + * + * @param[in] type Activity type (@see @enum activity_type) + **************************************************************************************** + */ +void sch_slice_bg_remove(uint8_t type); + +/** + **************************************************************************************** + * @brief Add a foreground activity + * + * @param[in] type Activity type (@see @enum activity_type) + * @param[in] end_ts Timestamp of the activity end (in half-slot clock) + **************************************************************************************** + */ +void sch_slice_fg_add(uint8_t type, uint32_t end_ts); + +/** + **************************************************************************************** + * @brief Remove a foreground activity + * + * @param[in] type Activity type (@see @enum activity_type) + **************************************************************************************** + */ +void sch_slice_fg_remove(uint8_t type); + +/** + **************************************************************************************** + * @brief Add a periodic activity + * + * @param[in] type Activity type (@see @enum activity_type) + * @param[in] id Identifier of the activity (depending on the activity type) + * @param[in] intv Interval (in half-slot) + * @param[in] duration Events duration (in half-us) + * @param[in] retx Potential retransmissions (applicable to SCO only) + **************************************************************************************** + */ +void sch_slice_per_add(uint8_t type, uint8_t id, uint32_t intv, uint16_t duration, bool retx); + +/** + **************************************************************************************** + * @brief Remove a periodic activity + * + * @param[in] type Activity type (@see @enum activity_type) + * @param[in] id Identifier of the activity (depending on the activity type) + **************************************************************************************** + */ +void sch_slice_per_remove(uint8_t type, uint8_t id); + +/// @} SCHSLICE +#endif // SCH_SLICE_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/aes/api/aes.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/aes/api/aes.h new file mode 100644 index 0000000..14eb88c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/aes/api/aes.h @@ -0,0 +1,368 @@ +/** + **************************************************************************************** + * + * @file aes.h + * + * @brief Header file for AES crypto module + * + * Copyright (C) RivieraWaves 2017-2018 + * + **************************************************************************************** + */ + +#ifndef AES_H_ +#define AES_H_ + +/** + **************************************************************************************** + * @defgroup AES Crypto module + * @ingroup ROOT + * @brief AES Crypto module + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#include "co_bt.h" // Common defines + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Call back definition of the function that can handle result of an AES based algorithm + * + * @param[in] status Execution status + * @param[in] aes_res 16 bytes block result + * @param[in] src_info Information provided by requester + **************************************************************************************** + */ +typedef void (*aes_func_result_cb) (uint8_t status, const uint8_t* aes_res, uint32_t src_info); + +/** + **************************************************************************************** + * @brief Call back definition of the function that can handle result of AES-CCM Cipher/Decipher + * + * @param[in] mic_error True if a MIC error detected when Decipher, False else + * In case of MIC error output message is considered invalid + * @param[in] src_info Information provided by requester + **************************************************************************************** + */ +typedef void (*aes_ccm_func_result_cb) (bool mic_error, uint32_t src_info); + +#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT) +/** + **************************************************************************************** + * @brief Call back definition of the Resolvable Private Address resolution function + * + * @param[in] index Index of the IRK used to resolve the provided RPA (number of IRK if not resolved) + * @param[in] src_info Information provided by requester + **************************************************************************************** + */ +typedef void (*aes_rpa_func_result_cb) (uint8_t index, uint32_t src_info); +#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT) + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize AES function management + * +* @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void aes_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Handler of AES execution (HW accelerator if BLE controller present, HCI Encrypt for BLE Host Stack) + * + * @param[in] status Status of AES execution + * @param[in] result 16 bytes result of AES execution + **************************************************************************************** + */ +void aes_result_handler(uint8_t status, uint8_t* result); + +/** + **************************************************************************************** + * @brief Perform an AES encryption - result within callback + * @param[in] key Key used for the encryption + * @param[in] val Value to encrypt using AES + * @param[in] copy Copy parameters because source is destroyed + * @param[in] res_cb Function that will handle the AES based result (16 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_encrypt(const uint8_t* key, const uint8_t *val, bool copy, aes_func_result_cb res_cb, uint32_t src_info); + +/** + **************************************************************************************** + * @brief Generate a random number using AES encryption - result within callback + * + * @param[in] res_cb Function that will handle the AES based result (16 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_rand(aes_func_result_cb res_cb, uint32_t src_info); + +#if (BLE_HOST_PRESENT) + +/** + **************************************************************************************** + * @brief Compute Confirm value + * + * @param[in] k Key used for aes functions + * @param[in] r Random number + * @param[in] p1 p1 = pres || preq || rat’ || iat’ + * @param[in] p2 p2 = padding || ia || ra + * @param[in] res_cb Function that will handle the AES based result (16 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_c1(const uint8_t* k, const uint8_t* r, const uint8_t* p1, const uint8_t* p2, + aes_func_result_cb res_cb, uint32_t src_info); + +/** + **************************************************************************************** + * @brief Compute LE Secure Connections Confirm Value Generation Function f4 + * + * @param[in] u U is 256 bits + * @param[in] v V is 256 bits + * @param[in] x X is 128 bits + * @param[in] z Z is 8 bits + * @param[in] res_cb Function that will handle the AES based result (16 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_f4(const uint8_t* u, const uint8_t* v, const uint8_t* x, uint8_t z, + aes_func_result_cb res_cb, uint32_t src_info); + +/** + **************************************************************************************** + * @brief Compute LE Secure Connections Key Generation Function f5 + * + * @param[in] w W is 256 bits + * @param[in] n1 N1 is 128 bits + * @param[in] n2 N2 is 128 bits + * @param[in] a1 A1 is 56 bits + * @param[in] a2 A2 is 56 bits + * @param[in] res_cb Function that will handle the AES based result (16 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_f5(const uint8_t* w, const uint8_t* n1, const uint8_t* n2, const uint8_t* a1, const uint8_t* a2, + aes_func_result_cb res_cb, uint32_t src_info); + + +/** + **************************************************************************************** + * @brief Compute LE Secure Connections Check Value Generation Function f6 + * + * @param[in] w W is 128 bits + * @param[in] n1 N1 is 128 bits + * @param[in] n2 N2 is 128 bits + * @param[in] r R is 128 bits + * @param[in] iocap IOcap is 24 bits + * @param[in] a1 A1 is 56 bits + * @param[in] a2 A2 is 56 bits + * + * @param[in] res_cb Function that will handle the AES based result (16 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_f6(const uint8_t* w, const uint8_t* n1, const uint8_t* n2, const uint8_t* r, const uint8_t* iocap, + const uint8_t* a1, const uint8_t* a2, aes_func_result_cb res_cb, uint32_t src_info); + +/** + **************************************************************************************** + * @brief Compute LE Secure Connections Numeric Comparison Value Generation Function g2 + * + * @param[in] u U is 256 bits + * @param[in] v V is 256 bits + * @param[in] x X is 128 bits + * @param[in] y Y is 128 bits + * + * @param[in] res_cb Function that will handle the AES based result (16 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_g2(const uint8_t* u, const uint8_t* v, const uint8_t* x, const uint8_t* y, + aes_func_result_cb res_cb, uint32_t src_info); +#endif // (BLE_HOST_PRESENT) + + + +#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT) + +/** + **************************************************************************************** + * @brief Start the AES CMAC crypto function. Allocate memory for the CMAC and + * begins the subkey generation + * + * @param[in] key Pointer to the Key to be used + * @param[in] message Pointer to the block of data the data on which the CMAC is performed + * @param[in] message_len Length (in bytes) of the block of data M + * @param[in] res_cb Function that will handle the AES based result (16 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_cmac(const uint8_t* key, const uint8_t* message, uint16_t message_len, + aes_func_result_cb res_cb, uint32_t src_info); + +#if (BLE_MESH) + +/** + **************************************************************************************** + * @brief Start the AES S1 crypto function. + * + * @param[in] message Message used to generate Salted key + * @param[in] message_len Length (in bytes) of the block of data M + * @param[in] res_cb Function that will handle the AES based result (16 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_s1(const uint8_t* message, uint8_t message_len, aes_func_result_cb res_cb, uint32_t src_info); + +/** + **************************************************************************************** + * @brief Start the AES K1 crypto function. + * + * @param[in] salt Salted Key to use + * @param[in] n Value of N + * @param[in] n_len Length of N + * @param[in] p Value of P + * @param[in] p_len Length of P + * @param[in] res_cb Function that will handle the AES based result (16 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_k1(const uint8_t* salt, const uint8_t* n, uint8_t n_len, const uint8_t* p, uint8_t p_len, + aes_func_result_cb res_cb, uint32_t src_info); + +/** + **************************************************************************************** + * @brief Start the AES K2 crypto function. + * + * @param[in] n Value of N - 128 bits + * @param[in] p Value of P + * @param[in] p_len Length of P + * @param[in] res_cb Function that will handle the AES based result (33 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_k2(const uint8_t* n, const uint8_t* p, uint8_t p_len, aes_func_result_cb res_cb, uint32_t src_info); + + +/** + **************************************************************************************** + * @brief Start the AES K3 crypto function. + * + * @param[in] n Value of N - 128 bits + * @param[in] res_cb Function that will handle the AES based result (8 bytes) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_k3(const uint8_t* n, aes_func_result_cb res_cb, uint32_t src_info); + +/** + **************************************************************************************** + * @brief Start the AES K4 crypto function. + * + * @param[in] n Value of N - 128 bits + * @param[in] res_cb Function that will handle the AES based result (1 byte) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_k4(const uint8_t* n, aes_func_result_cb res_cb, uint32_t src_info); + + +/** + **************************************************************************************** + * @brief Start the AES CCM crypto function. Allocate memory for the CCM and start processing it + * Execute result callback at end of function execution + * + * @param[in] key Pointer to the Key to be used + * @param[in] nonce 13 Bytes Nonce to use for cipher/decipher + * @param[in] in_message Input message for AES-CCM exectuion + * @param[out] out_message Output message that will contain cipher+mic or decipher data + * @param[in] message_len Length of Input/Output message without mic + * @param[in] mic_len Length of the mic to use (2, 4, 6, 8, 10, 12, 14, 16 valid) + * @param[in] cipher True to encrypt message, False to decrypt it. + * @param[in] add_auth_data Additional Authentication data used for computation of MIC + * @param[in] add_auth_data_len Length of Additional Authentication data + * @param[in] res_cb Function that will handle the AES CCM result + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_ccm(const uint8_t* key, const uint8_t* nonce, const uint8_t* in_message, + uint8_t* out_message, uint16_t message_len, uint8_t mic_len, bool cipher, + const uint8_t* add_auth_data, uint8_t add_auth_data_len, aes_ccm_func_result_cb res_cb, uint32_t src_info); +#endif // (BLE_MESH) + +/** + **************************************************************************************** + * @brief Group Session Key Derivation Function h8 + * + * @param[in] k K is a 128bits data + * @param[in] s S is a 128bits key + * @param[in] keyId KeyID is a 32 bits data + * @param[in] res_cb Function that will handle the AES CCM result + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_h8(const uint8_t* k, const uint8_t* s, const uint8_t* key_id, aes_func_result_cb res_cb, uint32_t src_info); + +/** + **************************************************************************************** + * @brief Group Long Term Key Generation Function h9 + * + * @param[in] w W is a 128bits data + * @param[in] keyId KeyID is a 32 bits data + * @param[in] res_cb Function that will handle the AES CCM result + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_h9(const uint8_t* w, const uint8_t* key_id, aes_func_result_cb res_cb, uint32_t src_info); + +#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT) + +#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT) +/** + **************************************************************************************** + * @brief Resolvable Private Address generation Function + * + * @param[in] irk Pointer to IRK (local IRK to generate a local RPA) + * @param[in] res_cb Function that will handle the AES RPA generation result (address generated in the 6 LSBs of the returned buffer) + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_rpa_gen(struct irk* irk, aes_func_result_cb res_cb, uint32_t src_info); + +/** + **************************************************************************************** + * @brief Resolvable Private Address resolution Function + * + * @param[in] nb_irk Number of IRKs provided + * @param[in] irk Table of IRKs (stored internally to AES RPA, caller can destroy the table) + * @param[in] addr BD address to resolve + * @param[in] res_cb Function that will handle the AES RPA resolution result + * @param[in] src_info Information used retrieve requester + **************************************************************************************** + */ +void aes_rpa_resolve(uint8_t nb_irk, struct irk* irk, struct bd_addr* addr, aes_rpa_func_result_cb res_cb, uint32_t src_info); + +#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT) + +/// @} AES +/// +#endif /* AES_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/aes/api/aes_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/aes/api/aes_int.h new file mode 100644 index 0000000..eeffe81 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/aes/api/aes_int.h @@ -0,0 +1,197 @@ +/** + **************************************************************************************** + * + * @file aes_int.h + * + * @brief Header file for AES Internal crypto module + * + * Copyright (C) RivieraWaves 2017-2018 + * + **************************************************************************************** + */ + +#ifndef AES_INT_H_ +#define AES_INT_H_ + +/** + **************************************************************************************** + * @defgroup AES_INT + * @ingroup AES + * @brief AES_INT Crypto internal definitions + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#include "aes.h" + + +#include "co_bt.h" // Common defines +#include "co_list.h" // List usage + +/* + * Defines + **************************************************************************************** + */ + +// Size of an a AES Message block in bytes +#define AES_BLOCK_SIZE 16 + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ +struct aes_func_env; + +/** + **************************************************************************************** + * Callback used to continue execution of the AES based function. + * + * @param[in] aes_result Result of the AES (aes(key , val)) + * + * @return True if function execution is over + **************************************************************************************** + */ +typedef bool (*aes_func_continue_cb) (struct aes_func_env* aes_env, uint8_t* aes_result); + +/// Environment variable required for an AES based function +/// This structure must be Header of all function environment variables +struct aes_func_env +{ + /// used to put AES function in the AES execution queue + struct co_list_hdr hdr; + /// AES continue callback + aes_func_continue_cb aes_continue_cb; + /// AES End callback + aes_func_result_cb aes_res_cb; + + /// Key to use for the AES execution + const uint8_t* key; + /// Value to use for AES Cypher/Decypher + const uint8_t* val; + /// Information put in source id message to retrieve requester + uint32_t src_info; +}; + +#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT) +// Structure definition of the AES CMAC algorithm +struct aes_cmac_env +{ + /// AES Environment structure + struct aes_func_env aes_env; + + /// M: Pointer to the message to be authenticated + const uint8_t* message; // pointer to memory allocated by calling function + + /// K: authentication key + const uint8_t* auth_key; + + /// T: message authentication code + uint8_t auth_code[AES_BLOCK_SIZE]; + + /// Length of the message + uint16_t message_len; + /// Number of blocks (1 block = 16 bytes) + uint8_t num_blocks; + /// Current block to process + uint8_t cur_block; +}; +#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT) + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + +/// zero block +extern const uint8_t aes_cmac_zero[AES_BLOCK_SIZE]; + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Allocate environment for the AES based function execution + * + * @param[in] size Size of the environment to allocate (must be >= sizeof(struct aes_func_env)) + * @param[in] aes_continue_cb Callback used to send the AES result + * @param[in] res_cb Function that will handle end of AES Based algorithm + * @param[in] src_info Information used to retrieve requester + * + * @return Allocated environment variable + **************************************************************************************** + */ +struct aes_func_env* aes_alloc(uint16_t size, aes_func_continue_cb aes_continue_cb, aes_func_result_cb res_cb, + uint32_t src_info); + +/** + **************************************************************************************** + * @brief AES Cypher request function. + * + * This will queue AES request in the AES execution queue + * When the AES result is received, the AES continue callback is executed. + * + * If AES continue function returns that AES execution is over, a message will be send to destination task + * with latest AES result. + * + * @param[in] env AES environment + * @param[in] key Key used for cyphering + * @param[in] val Value to cypher + **************************************************************************************** + */ +void aes_start(struct aes_func_env* env, const uint8_t* key, const uint8_t *val); + +#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT) +/** + **************************************************************************************** + * @brief Start the AES CMAC crypto function. Allocate memory for the CMAC and + * begins the subkey generation + * + * @param[in] enc AES CMAC Environment + * @param[in] key Pointer to the Key to be used + * @param[in] message Pointer to the block of data the data on which the CMAC is performed + * @param[in] message_len Length (in bytes) of the block of data M + **************************************************************************************** + */ +void aes_cmac_start(struct aes_cmac_env* env, const uint8_t* key, const uint8_t* message, uint16_t message_len); + +/** + **************************************************************************************** + * @brief Continue AES CMAC algorithm + * + * @param[in] env AES CMAC Environment + * @param[in] aes_res AES Result + * + * @return True if algorithm is over, False else + **************************************************************************************** + */ +bool aes_cmac_continue(struct aes_cmac_env* env, uint8_t* aes_res); + +/** + * @brief Perform a XOR of two numbers. + * + * @param[out] result Output 128 bits number: result = a ^ b + * @param[in] a first 128 bits operand + * @param[in] b second 128 bits operand + * @param[in] size number of bytes to XOR + */ +void aes_xor_128(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size); + +/** + * @brief Perform shift left of a 128 bits numvber + * + * @param[in] input Input 128 bits number + * @param[out] output Output 128 bits number: output = input << 1 + */ +void aes_shift_left_128(const uint8_t* input,uint8_t* output); +#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT) + +/// @} AES_INT +/// +#endif /* AES_INT_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_bt.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_bt.h new file mode 100644 index 0000000..ba42fd7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_bt.h @@ -0,0 +1,62 @@ +/** + **************************************************************************************** + * + * @file co_bt.h + * + * @brief This file contains the common Bluetooth defines, enumerations and structures + * definitions for use by all modules in RW stack. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef CO_BT_H_ +#define CO_BT_H_ + +/** + **************************************************************************************** + * @addtogroup COMMON Common SW Block + * @ingroup ROOT + * @brief The Common RW SW Block. + * + * The COMMON is the block with Bluetooth definitions and structures shared + * to all the protocol stack blocks. This also contain software wide error code + * definitions, mathematical functions, help functions, list and buffer definitions. + * + * @{ + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup CO_BT Common Bluetooth defines + * @ingroup COMMON + * @brief Common Bluetooth definitions and structures. + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include // standard boolean definitions +#include // standard definitions +#include // standard integer definitions + +/* + * DEFINES + **************************************************************************************** + */ + +#include "co_bt_defines.h" // Bluetooth defines +#include "co_lmp.h" // Bluetooth LMP definitions +#include "co_hci.h" // Bluetooth HCI definitions +#include "co_error.h" // Bluetooth error codes definitions + +/// @} CO_BT +#endif // CO_BT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_bt_defines.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_bt_defines.h new file mode 100644 index 0000000..8dc7266 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_bt_defines.h @@ -0,0 +1,3217 @@ +/** + **************************************************************************************** + * + * @file co_bt_defines.h + * + * @brief This file contains the common Bluetooth defines, enumerations and structures + * definitions for use by all modules in RW stack. + * + * Copyright (C) RivieraWaves 2009-2016 + * + * + **************************************************************************************** + */ +#include "stdint.h" + +#ifndef CO_BT_DEFINES_H_ +#define CO_BT_DEFINES_H_ + + +/** + **************************************************************************************** + * @addtogroup CO_BT_DEFINES Common Bluetooth defines + * @ingroup CO_BT + * @brief Common Bluetooth definitions and structures. + * + * @{ + **************************************************************************************** + */ + + +/* + * DEFINES + **************************************************************************************** + */ + +/// Bluetooth technologies version +#define BT40_VERSION (6) +#define BT41_VERSION (7) +#define BT42_VERSION (8) +#define BT50_VERSION (9) +#define BT51_VERSION (10) + +/** + * BD Address format (values in bytes) + * | 3B | 1B | 2B | + * | LAP | UAP | NAP | + */ +#define BD_ADDR_LEN 6 +#define BD_ADDR_LAP_POS 0 +#define BD_ADDR_LAP_LEN 3 +#define BD_ADDR_UAP_POS BD_ADDR_LAP_LEN +#define BD_ADDR_UAP_LEN 1 +#define BD_ADDR_NAP_POS BD_ADDR_UAP_LEN +#define BD_ADDR_NAP_LEN 2 + +/** + * Resolvable private Address format (values in bytes) + * | 3B | 3B | + * | PRAND | HASH | + */ +/// Length of resolvable random address prand part +#define BD_ADDR_PRAND_LEN (3) +/// Length of resolvable random address hash part +#define BD_ADDR_HASH_LEN (3) + +/// Random Address type +enum random_addr_type +{ + /// Mask over the 2 MSBs + BD_ADDR_RND_ADDR_TYPE_MSK = 0xC0, + + /// Static random address - 11 (MSB->LSB) + BD_ADDR_STATIC = 0xC0, + /// Private non resolvable address - 00 (MSB->LSB) + BD_ADDR_NON_RSLV = 0x00, + /// Private resolvable address - 01 (MSB->LSB) + BD_ADDR_RSLV = 0x40, +}; + +///Length of fields in Bluetooth messages, in number of bytes +#define EVT_MASK_LEN 8 +#define DEV_CLASS_LEN 3 +#define ACO_LEN 12 +#define SRES_LEN 0x04 +#define ACCESS_ADDR_LEN 0x04 +#define LE_PASSKEY_LEN 0x04 +#define BD_NAME_SIZE 0xF8 // Was 0x20 for BLE HL +#define ADV_DATA_LEN 0x1F +#define EXT_ADV_DATA_MAX_LEN 229 // HCI:7.7.65.13 +#define PER_ADV_DATA_MAX_LEN 247 // 248 // HCI:7.7.65.16 +#define BLE_DATA_LEN 0x1B +#define SCAN_RSP_DATA_LEN 0x1F +#define CONNECT_REQ_DATA_LEN 0x16 +#define LE_CHNL_MAP_LEN 0x05 +#define CHNL_MAP_LEN 0x0A +#define KEY_LEN 0x10 +#define PIN_CODE_MIN_LEN 0x01 +#define PIN_CODE_MAX_LEN 0x10 +#define PRIV_KEY_192_LEN 24 +#define PUB_KEY_192_LEN 48 +#define PRIV_KEY_256_LEN 32 +#define PUB_KEY_256_LEN 64 +#define CFM_LEN 0x10 +#define ENC_DATA_LEN 0x10 +#define RAND_VAL_LEN 0x10 +#define RAND_NB_LEN 0x08 +#define LE_FEATS_LEN 0x08 +#define SUPP_CMDS_LEN 0x40 +#define FEATS_LEN 0x08 +#define NAME_VECT_SIZE 14 +#define LMP_FEATS_LEN 0x08 +#define LE_STATES_LEN 0x08 +#define WHITE_LIST_LEN 0x0A +#define LE_FREQ_LEN 0x28 +#define LE_DATA_FREQ_LEN 0x25 +#define CRC_INIT_LEN 0x03 +#define SESS_KEY_DIV_LEN 0x08 +#define INIT_VECT_LEN 0x04 +#define MIC_LEN 0x04 +#define IV_LEN 0x08 +#define SK_DIV_LEN 0x10 + +// Session Key Diversifier Master or slave +#define SKD_M_OFFSET 0x00 +#define SKD_S_OFFSET 0x08 +// Initialization Vector Master or slave +#define IV_M_OFFSET 0x00 +#define IV_S_OFFSET 0x04 + +// BT 4.2 - Secure Connections +#define PUBLIC_KEY_P256_LEN 0x20 +#define DHKEY_CHECK_LEN 0x10 + +#define DH_KEY_LEN 0x20 + +// BT 5.0 - Slot Availability Masks + +#define SAM_SUBMAPS_LEN 12 +#define SAM_TYPE0_SUBMAP_LEN 14 + +#define SAM_SLOT_NOT_AVAILABLE 0 +#define SAM_SLOT_TX_AVAILABLE 1 +#define SAM_SLOT_RX_AVAILABLE 2 +#define SAM_SLOT_TX_RX_AVAILABLE 3 + +#define SAM_INDEX_MAX 3 +#define SAM_INDEX_CONTINUE 3 +#define SAM_DISABLED 0xFF + +#define SAM_UPDATE_INVALIDATE_MAPS 0 +#define SAM_UPDATE_IMMEDIATE 1 +#define SAM_UPDATE_AT_SUBINTERVAL 2 + +#define T_SAM_SM_MIN 2 +#define T_SAM_SM_MAX 56 + +#define SAM_SLOTS_SUBMAPPED 0 +#define SAM_SLOTS_AVAILABLE 1 +#define SAM_SLOTS_UNAVAILABLE 2 + + +/// Maximum maskable event code +#define EVT_MASK_CODE_MAX EVT_MASK_LEN * 8 + +/// Default event mask +#define EVT_MASK_DEFAULT {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x9F, 0x00, 0x20} + +/// Advertising and Data Channel Indices (chapter 6.B.1.4.1) +#define DATA_CHANNEL_MIN 0 +#define DATA_CHANNEL_MAX 36 +#define DATA_CHANNEL_NB 37 +#define ADV_CHANNEL_37 37 +#define ADV_CHANNEL_38 38 +#define ADV_CHANNEL_39 39 + +/// Minimum number of used channel in the map (chapter 6.B.4.5.8.1) +#define DATA_CHANNEL_USED_NB_MIN 2 + +/// Advertising interval (in 625us slot) (chapter 2.E.7.8.5) +#define ADV_INTERVAL_MIN 0x0020 //(20 ms) +#define ADV_INTERVAL_MAX 0x4000 //(10.24 sec) +#define ADV_INTERVAL_DFT 0x0800 //(1.28 sec) + +/// Scanning interval (in 625us slot) (chapter 2.E.7.8.10) +#define SCAN_INTERVAL_MIN 0x0004 //(2.5 ms) +#define SCAN_INTERVAL_MAX 0x4000 //(10.24 sec) +#define SCAN_INTERVAL_DFT 0x0010 //(10 ms) + +/// Scanning window (in 625us slot) (chapter 2.E.7.8.10) +#define SCAN_WINDOW_MIN 0x0004 //(2.5 ms) +#define SCAN_WINDOW_MAX 0x4000 //(10.24 sec) +#define SCAN_WINDOW_DFT 0x0010 //(10 ms) + +/// Sync Timeout (in Time = N*10ms) +#define SYNC_TIMEOUT_MIN 0x000A //(100 ms) +#define SYNC_TIMEOUT_MAX 0x4000 //(163.84 s) + +/// Advertising SID valid Range +#define SYNC_SID_MIN 0x00 +#define SYNC_SID_MAX 0x0F + +/// Periodic Adv Skip valid Range +#define SYNC_SKIP_MIN 0x0000 +#define SYNC_SKIP_MAX 0x01F3 + +/// Connection interval (N*1.250ms) (chapter 2.E.7.8.12) +#if defined(CFG_ISO_MODE_0) +#define CON_INTERVAL_MIN_AUDIO 0x0002 //(2.5 msec) +#define CON_INTERVAL_MIN CON_INTERVAL_MIN_AUDIO +#else // !defined(CFG_ISO_MODE_0) +#define CON_INTERVAL_MIN 0x0006 //(7.5 msec) +#endif // defined(CFG_ISO_MODE_0) +#define CON_INTERVAL_MAX 0x0C80 //(4 sec) +/// Connection latency (N*cnx evt) (chapter 2.E.7.8.12) +#define CON_LATENCY_MIN 0x0000 +#define CON_LATENCY_MAX 0x01F3 // (499) +/// Supervision TO (N*10ms) (chapter 2.E.7.8.12) +#define CON_SUP_TO_MIN 0x000A //(100 msec) +#define CON_SUP_TO_MAX 0x0C80 //(32 sec) + +/// Format of the Advertising packets +#define ADV_ADDR_OFFSET 0 +#define ADV_ADDR_LEN BD_ADDR_LEN +#define ADV_DATA_OFFSET (ADV_ADDR_OFFSET + ADV_ADDR_LEN) + +/// List of supported BLE Features LL:4.6 +enum ble_feature +{ + //byte 0 + BLE_FEAT_ENC = (0), + BLE_FEAT_CON_PARAM_REQ_PROC = (1), + BLE_FEAT_EXT_REJ_IND = (2), + BLE_FEAT_SLAVE_INIT_FEAT_EXCHG = (3), + BLE_FEAT_PING = (4), + BLE_FEAT_DATA_PKT_LEN_EXT = (5), + BLE_FEAT_LL_PRIVACY = (6), + BLE_FEAT_EXT_SCAN_FILT_POLICY = (7), + //byte 1 + BLE_FEAT_2M_PHY = (8), + BLE_FEAT_STABLE_MOD_IDX_TX = (9), + BLE_FEAT_STABLE_MOD_IDX_RX = (10), + BLE_FEAT_CODED_PHY = (11), + BLE_FEAT_EXT_ADV = (12), + BLE_FEAT_PER_ADV = (13), + BLE_FEAT_CHAN_SEL_ALGO_2 = (14), + BLE_FEAT_PWR_CLASS_1 = (15), + //byte 2 + BLE_FEAT_MIN_NUM_USED_CHAN_PROC = (16), + BLE_FEAT_CON_CTE_REQ = (17), + BLE_FEAT_CON_CTE_RSP = (18), + BLE_FEAT_CONLESS_CTE_TX = (19), + BLE_FEAT_CONLESS_CTE_RX = (20), + BLE_FEAT_AOD = (21), + BLE_FEAT_AOA = (22), + BLE_FEAT_CTE_RX = (23), + //byte 3 + BLE_FEAT_PER_ADV_SYNC_TRANSF_TX = (24), + BLE_FEAT_PER_ADV_SYNC_TRANSF_RX = (25), + BLE_FEAT_SLEEP_CLK_ACC_UPD = (26), + BLE_FEAT_PUB_KEY_VALID = (27), +}; + +/// BLE supported states +//byte 0 +#define BLE_NON_CON_ADV_STATE 0x01 +#define BLE_DISC_ADV_STATE 0x02 +#define BLE_CON_ADV_STATE 0x04 +#define BLE_HDC_DIRECT_ADV_STATE 0x08 +#define BLE_PASS_SCAN_STATE 0x10 +#define BLE_ACTIV_SCAN_STATE 0x20 +#define BLE_INIT_MASTER_STATE 0x40 +#define BLE_CON_SLAVE_STATE 0x80 + +//byte 1 +#define BLE_NON_CON_ADV_PASS_SCAN_STATE 0x01 +#define BLE_DISC_ADV_PASS_SCAN_STATE 0x02 +#define BLE_CON_ADV_PASS_SCAN_STATE 0x04 +#define BLE_HDC_DIRECT_ADV_PASS_SCAN_STATE 0x08 +#define BLE_NON_CON_ADV_ACTIV_SCAN_STATE 0x10 +#define BLE_DISC_ADV_ACTIV_SCAN_STATE 0x20 +#define BLE_CON_ADV_ACTIV_SCAN_STATE 0x40 +#define BLE_HDC_DIRECT_ADV_ACTIV_SCAN_STATE 0x80 + +//byte 2 +#define BLE_NON_CON_ADV_INIT_STATE 0x01 +#define BLE_DISC_ADV_INIT_STATE 0x02 +#define BLE_NON_CON_ADV_MASTER_STATE 0x04 +#define BLE_DISC_ADV_MASTER_STATE 0x08 +#define BLE_NON_CON_ADV_SLAVE_STATE 0x10 +#define BLE_DISC_ADV_SLAVE_STATE 0x20 +#define BLE_PASS_SCAN_INIT_STATE 0x40 +#define BLE_ACTIV_SCAN_INIT_STATE 0x80 + +//byte 3 +#define BLE_PASS_SCAN_MASTER_STATE 0x01 +#define BLE_ACTIV_SCAN_MASTER_STATE 0x02 +#define BLE_PASS_SCAN_SLAVE_STATE 0x04 +#define BLE_ACTIV_SCAN_SLAVE_STATE 0x08 +#define BLE_INIT_MASTER_MASTER_STATE 0x10 +#define BLE_LDC_DIRECT_ADV_STATE 0x20 +#define BLE_LDC_DIRECT_ADV_PASS_SCAN_STATE 0x40 +#define BLE_LDC_DIRECT_ADV_ACTIV_SCAN_STATE 0x80 + +//byte 4 +#define BLE_CON_ADV_INIT_MASTER_SLAVE_STATE 0x01 +#define BLE_HDC_DIRECT_ADV_INIT_MASTER_SLAVE_STATE 0x02 +#define BLE_LDC_DIRECT_ADV_INIT_MASTER_SLAVE_STATE 0x04 +#define BLE_CON_ADV_MASTER_SLAVE_STATE 0x08 +#define BLE_HDC_DIRECT_ADV_MASTER_SLAVE_STATE 0x10 +#define BLE_LDC_DIRECT_ADV_MASTER_SLAVE_STATE 0x20 +#define BLE_CON_ADV_SLAVE_SLAVE_STATE 0x40 +#define BLE_HDC_DIRECT_ADV_SLAVE_SLAVE_STATE 0x80 + +//byte 5 +#define BLE_LDC_DIRECT_ADV_SLAVE_SLAVE_STATE 0x01 +#define BLE_INIT_MASTER_SLAVE_STATE 0x02 + +/// BLE supported commands +//byte0 +#define BLE_DISC_CMD 0x20 +//byte2 +#define BLE_RD_REM_VERS_CMD 0x80 +//byte5 +#define BLE_SET_EVT_MSK_CMD 0x40 +#define BLE_RESET_CMD 0x80 +//byte10 +#define BLE_RD_TX_PWR_CMD 0x04 +#define BLE_SET_CTRL_TO_HL_FCTRL_CMD 0x20 +#define BLE_HL_BUF_SIZE_CMD 0x40 +#define BLE_HL_NB_CMP_PKT_CMD 0x80 +//byte14 +#define BLE_RD_LOC_VERS_CMD 0x08 +#define BLE_RD_LOC_SUP_FEAT_CMD 0x20 +//byte15 +#define BLE_RD_BD_ADDR_CMD 0x02 +#define BLE_RD_RSSI_CMD 0x20 +//byte22 +#define BLE_SET_EVT_MSK_PG2_CMD 0x04 +//byte25 +#define BLE_LE_SET_EVT_MSK_CMD 0x01 +#define BLE_LE_RD_BUF_SIZE_CMD 0x02 +#define BLE_LE_RD_LOC_SUP_FEAT_CMD 0x04 +#define BLE_LE_SET_RAND_ADDR_CMD 0x10 +#define BLE_LE_SET_ADV_PARAM_CMD 0x20 +#define BLE_LE_RD_ADV_TX_PWR_CMD 0x40 +#define BLE_LE_SET_ADV_DATA_CMD 0x80 +//byte26 +#define BLE_LE_SET_SC_RSP_DATA_CMD 0x01 +#define BLE_LE_SET_ADV_EN_CMD 0x02 +#define BLE_LE_SET_SC_PARAM_CMD 0x04 +#define BLE_LE_SET_SC_EN_CMD 0x08 +#define BLE_LE_CREAT_CNX_CMD 0x10 +#define BLE_LE_CREAT_CNX_CNL_CMD 0x20 +#define BLE_LE_RD_WL_SIZE_CMD 0x40 +#define BLE_LE_CLEAR_WL_CMD 0x80 +//byte27 +#define BLE_LE_ADD_DEV_WL_CMD 0x01 +#define BLE_LE_REM_DEV_WL_CMD 0x02 +#define BLE_LE_CNX_UPDATE_CMD 0x04 +#define BLE_LE_SET_HL_CH_CLASS_CMD 0x08 +#define BLE_LE_RD_CH_MAP_CMD 0x10 +#define BLE_LE_RD_REM_FEAT_CMD 0x20 +#define BLE_LE_ENCRYPT_CMD 0x40 +#define BLE_LE_RAND_CMD 0x80 +//byte28 +#define BLE_LE_START_ENC_CMD 0x01 +#define BLE_LE_LTK_REQ_RPLY_CMD 0x02 +#define BLE_LE_LTK_REQ_NEG_RPLY_CMD 0x04 +#define BLE_LE_RD_SUPP_STATES_CMD 0x08 +#define BLE_LE_RX_TEST_V1_CMD 0x10 +#define BLE_LE_TX_TEST_V1_CMD 0x20 +#define BLE_LE_STOP_TEST_CMD 0x40 + +//byte32 +#define BLE_RD_AUTH_PAYL_TO_CMD 0x10 +#define BLE_WR_AUTH_PAYL_TO_CMD 0x20 + + +//byte33 +#define BLE_LE_REM_CON_PARA_REQ_RPLY_CMD 0x10 +#define BLE_LE_REM_CON_PARA_REQ_NEG_RPLY_CMD 0x20 +#define BLE_LE_SET_DATA_LEN_CMD 0x40 +#define BLE_LE_RD_SUGGTED_DFT_DATA_LEN_CMD 0x80 + +//byte34 +#define BLE_LE_WR_SUGGTED_DFT_DATA_LEN_CMD 0x01 +#define BLE_LE_RD_LOC_P256_PUB_KEY_CMD 0x02 +#define BLE_LE_GEN_DHKEY_V1_CMD 0x04 +#define BLE_LE_ADD_DEV_TO_RESOLV_LIST_CMD 0x08 +#define BLE_LE_REM_DEV_FROM_RESOLV_LIST_CMD 0x10 +#define BLE_LE_CLEAR_RESOLV_LIST_CMD 0x20 +#define BLE_LE_RD_RESOLV_LIST_SIZE_CMD 0x40 +#define BLE_LE_RD_PEER_RESOLV_ADDR_CMD 0x80 + +//byte35 +#define BLE_LE_RD_LOCAL_RESOLV_ADDR_CMD 0x01 +#define BLE_LE_SET_ADDR_RESOL_CMD 0x02 +#define BLE_LE_SET_RESOLV_PRIV_ADDR_TO_CMD 0x04 +#define BLE_LE_RD_MAX_DATA_LEN_CMD 0x08 +#define BLE_LE_RD_PHY_CMD 0x10 +#define BLE_LE_SET_DFT_PHY_CMD 0x20 +#define BLE_LE_SET_PHY_CMD 0x40 +#define BLE_LE_RX_TEST_V2_CMD 0x80 +//byte36 +#define BLE_LE_TX_TEST_V2_CMD 0x01 +#define BLE_LE_SET_ADV_SET_RAND_ADDR_CMD 0x02 +#define BLE_LE_SET_EXT_ADV_PARAM_CMD 0x04 +#define BLE_LE_SET_EXT_ADV_DATA_CMD 0x08 +#define BLE_LE_SET_EXT_SCAN_RSP_DATA_CMD 0x10 +#define BLE_LE_SET_EXT_ADV_EN_CMD 0x20 +#define BLE_LE_RD_MAX_ADV_DATA_LEN_CMD 0x40 +#define BLE_LE_RD_NB_SUPP_ADV_SETS_CMD 0x80 +//byte37 +#define BLE_LE_RMV_ADV_SET_CMD 0x01 +#define BLE_LE_CLEAR_ADV_SETS_CMD 0x02 +#define BLE_LE_SET_PER_ADV_PARAM_CMD 0x04 +#define BLE_LE_SET_PER_ADV_DATA_CMD 0x08 +#define BLE_LE_SET_PER_ADV_EN_CMD 0x10 +#define BLE_LE_SET_EXT_SCAN_PARAM_CMD 0x20 +#define BLE_LE_SET_EXT_SCAN_EN_CMD 0x40 +#define BLE_LE_EXT_CREATE_CON_CMD 0x80 +//byte38 +#define BLE_LE_PER_ADV_CREATE_SYNC_CMD 0x01 +#define BLE_LE_PER_ADV_CREATE_SYNC_CANCEL_CMD 0x02 +#define BLE_LE_PER_ADV_TERM_SYNC_CMD 0x04 +#define BLE_LE_ADD_DEV_TO_PER_ADV_LIST_CMD 0x08 +#define BLE_LE_RMV_DEV_FROM_PER_ADV_LIST_CMD 0x10 +#define BLE_LE_CLEAR_PER_ADV_LIST_CMD 0x20 +#define BLE_LE_RD_PER_ADV_LIST_SIZE_CMD 0x40 +#define BLE_LE_RD_TX_PWR_CMD 0x80 +//byte39 +#define BLE_LE_RD_RF_PATH_COMP_CMD 0x01 +#define BLE_LE_WR_RF_PATH_COMP_CMD 0x02 +#define BLE_LE_SET_PRIV_MODE_CMD 0x04 +#define BLE_LE_RX_TEST_V3_CMD 0x08 +#define BLE_LE_TX_TEST_V3_CMD 0x10 +#define BLE_LE_SET_CONLESS_CTE_TX_PARAM_CMD 0x20 +#define BLE_LE_SET_CONLESS_CTE_TX_EN_CMD 0x40 +#define BLE_LE_SET_CONLESS_IQ_SAMPL_EN_CMD 0x80 +//byte40 +#define BLE_LE_SET_CON_CTE_RX_PARAM_CMD 0x01 +#define BLE_LE_SET_CON_CTE_TX_PARAM_CMD 0x02 +#define BLE_LE_CON_CTE_REQ_EN_CMD 0x04 +#define BLE_LE_CON_CTE_RSP_EN_CMD 0x08 +#define BLE_LE_RD_ANTENNA_INF_CMD 0x10 +#define BLE_LE_SET_PER_ADV_RX_EN_CMD 0x20 +#define BLE_LE_PER_ADV_SYNC_TRANSF_CMD 0x40 +#define BLE_LE_PER_ADV_SET_INFO_TRANSF_CMD 0x80 +//byte41 +#define BLE_LE_SET_PER_ADV_SYNC_TRANSF_PARAM_CMD 0x01 +#define BLE_LE_SET_DFT_PER_ADV_SYNC_TRANSF_PARAM_CMD 0x02 +#define BLE_LE_GEN_DHKEY_V2_CMD 0x04 +#define BLE_LE_MOD_SLP_CLK_ACC_CMD 0x10 + + +// Inquiry Length HCI:7.1.1 +#define INQ_LEN_MIN 0x01 +#define INQ_LEN_MAX 0x30 + +// Inquiry Length HCI:7.1.3 +#define INQ_MIN_PER_LEN_MIN 0x0002 +#define INQ_MIN_PER_LEN_MAX 0xFFFE +#define INQ_MAX_PER_LEN_MIN 0x0003 +#define INQ_MAX_PER_LEN_MAX 0xFFFF + +// IAC support +#define NB_IAC_MIN 0x01 +#define NB_IAC_MAX 0x40 + +/// Most significant bit of the Bluetooth clock (in 312.5us half-slots) +#define BT_CLOCK_MSB (1L << 27) + +/// Logical Transport Adresses BB:4.2 +#define LT_ADDR_BCST 0x00 +#define LT_ADDR_MIN 0x01 +#define LT_ADDR_MAX 0x07 + +/// Link type HCI:7.7.3 +#define SCO_TYPE 0 +#define ACL_TYPE 1 +#define ESCO_TYPE 2 +#define UNKNOWN_TYPE 3 // Used in LM +#define LE_TYPE 4 + + +/// Allow Role Switch HCI:4.6.8 +#define MASTER_ROLE 0 +#define SLAVE_ROLE 1 +#define UNKNOWN_ROLE 0xFF //Used in LC to init the links role + +/// Link policy HCI:4.6.9 and HCI:4.6.10 +#define POLICY_SWITCH 0x0001 +#define POLICY_HOLD 0x0002 +#define POLICY_SNIFF 0x0004 +#define POLICY_PARK 0x0008 + +/// Allow Role Switch HCI:4.5.5 +#define ROLE_SWITCH_NOT_ALLOWED 0 +#define ROLE_SWITCH_ALLOWED 1 + +/// AcceptConnection Role HCI:4.5.8 +#define ACCEPT_SWITCH_TO_MASTER 0 +#define ACCEPT_REMAIN_SLAVE 1 + +/// Packet Type Flags HCI:7.1.14 +#define PACKET_TYPE_EDR_MSK 0x330E +#define PACKET_TYPE_GFSK_MSK 0xCCF8 +#define PACKET_TYPE_NO_2_DH1_FLAG 0x0002 +#define PACKET_TYPE_NO_3_DH1_FLAG 0x0004 +#define PACKET_TYPE_DM1_FLAG 0x0008 +#define PACKET_TYPE_DH1_FLAG 0x0010 +#define PACKET_TYPE_HV1_FLAG 0x0020 +#define PACKET_TYPE_HV2_FLAG 0x0040 +#define PACKET_TYPE_HV3_FLAG 0x0080 +#define PACKET_TYPE_NO_2_DH3_FLAG 0x0100 +#define PACKET_TYPE_NO_3_DH3_FLAG 0x0200 +#define PACKET_TYPE_DM3_FLAG 0x0400 +#define PACKET_TYPE_DH3_FLAG 0x0800 +#define PACKET_TYPE_NO_2_DH5_FLAG 0x1000 +#define PACKET_TYPE_NO_3_DH5_FLAG 0x2000 +#define PACKET_TYPE_DM5_FLAG 0x4000 +#define PACKET_TYPE_DH5_FLAG 0x8000 + +/// Synchronous Packet Types HCI:7.1.14 +#define SYNC_PACKET_TYPE_HV1_FLAG 0x0001 +#define SYNC_PACKET_TYPE_HV2_FLAG 0x0002 +#define SYNC_PACKET_TYPE_HV3_FLAG 0x0004 +#define SYNC_PACKET_TYPE_EV3_FLAG 0x0008 +#define SYNC_PACKET_TYPE_EV4_FLAG 0x0010 +#define SYNC_PACKET_TYPE_EV5_FLAG 0x0020 + +#define SYNC_PACKET_TYPE_NO_EV3_2_FLAG 0x0040 +#define SYNC_PACKET_TYPE_NO_EV3_3_FLAG 0x0080 +#define SYNC_PACKET_TYPE_NO_EV5_2_FLAG 0x0100 +#define SYNC_PACKET_TYPE_NO_EV5_3_FLAG 0x0200 + +#define SYNC_PACKET_TYPE_EV3_2_FLAG 0x0040 +#define SYNC_PACKET_TYPE_EV3_3_FLAG 0x0080 +#define SYNC_PACKET_TYPE_EV5_2_FLAG 0x0100 +#define SYNC_PACKET_TYPE_EV5_3_FLAG 0x0200 + +/// RWBT 1.2 +#define SYNC_EV3_PACKET_SIZE 30 +#define SYNC_EV4_PACKET_SIZE 120 +#define SYNC_EV5_PACKET_SIZE 180 + +/// Packet Boundary Flag HCI:5.4.2 +#define PBF_1ST_NF_HL_FRAG 0x00 // Non-flushable packets +#define PBF_CONT_HL_FRAG 0x01 +#define PBF_1ST_HL_FRAG 0x02 +#define PBF_CMP_PDU 0x03 +#define PBF_MASK 0x03 + +/// Broadcast Flag HCI:5.4.2 +#define BCF_P2P 0x00 +#define BCF_ACTIVE_SLV_BCST 0x01 +#define BCF_PARK_SLV_BCST 0x02 +#define BCF_MASK 0x03 + +/// Synchronous Packet Status Flag HCI:5.4.3 +#define CORRECTLY_RX_FLAG 0x00 +#define POSSIBLY_INVALID_FLAG 0x01 +#define NO_RX_DATA_FLAG 0x02 +#define PARTIALLY_LOST_FLAG 0x03 + +/// Park mode defines LMP:3.17 +#define MACCESS_MSK 0x0F +#define ACCSCHEM_MSK 0xF0 + +/// Support 3 feature pages +#define FEATURE_PAGE_MAX 3 + +#define FEATURE_PAGE_0 0 +#define FEATURE_PAGE_1 1 +#define FEATURE_PAGE_2 2 + +/// Feature mask definition LMP:3.3 +#define B0_3_SLOT_POS 0 +#define B0_3_SLOT_MSK 0x01 +#define B0_5_SLOT_POS 1 +#define B0_5_SLOT_MSK 0x02 +#define B0_ENC_POS 2 +#define B0_ENC_MSK 0x04 +#define B0_SLOT_OFF_POS 3 +#define B0_SLOT_OFF_MSK 0x08 +#define B0_TIMING_ACCU_POS 4 +#define B0_TIMING_ACCU_MSK 0x10 +#define B0_ROLE_SWITCH_POS 5 +#define B0_ROLE_SWITCH_MSK 0x20 +#define B0_HOLD_MODE_POS 6 +#define B0_HOLD_MODE_MSK 0x40 +#define B0_SNIFF_MODE_POS 7 +#define B0_SNIFF_MODE_MSK 0x80 + +#define B1_PARK_POS 0 +#define B1_PARK_MSK 0x01 +#define B1_RSSI_POS 1 +#define B1_RSSI_MSK 0x02 +#define B1_CQDDR_POS 2 +#define B1_CQDDR_MSK 0x04 +#define B1_SCO_POS 3 +#define B1_SCO_MSK 0x08 +#define B1_HV2_POS 4 +#define B1_HV2_MSK 0x10 +#define B1_HV3_POS 5 +#define B1_HV3_MSK 0x20 +#define B1_MULAW_POS 6 +#define B1_MULAW_MSK 0x40 +#define B1_ALAW_POS 7 +#define B1_ALAW_MSK 0x80 + +#define B2_CVSD_POS 0 +#define B2_CVSD_MSK 0x01 +#define B2_PAGING_PAR_NEGO_POS 1 +#define B2_PAGING_PAR_NEGO_MSK 0x02 +#define B2_PWR_CTRL_POS 2 +#define B2_PWR_CTRL_MSK 0x04 +#define B2_TRANSPARENT_SCO_POS 3 +#define B2_TRANSPARENT_SCO_MSK 0x08 +#define B2_FLOW_CTRL_LAG_POS 4 +#define B2_FLOW_CTRL_LAG_MSK 0x70 +#define B2_BCAST_ENC_POS 7 +#define B2_BCAST_ENC_MSK 0x80 + +#define B3_EDR_2MBPS_ACL_POS 1 +#define B3_EDR_2MBPS_ACL_MSK 0x02 +#define B3_EDR_3MBPS_ACL_POS 2 +#define B3_EDR_3MBPS_ACL_MSK 0x04 +#define B3_ENH_INQSCAN_POS 3 +#define B3_ENH_INQSCAN_MSK 0x08 +#define B3_INT_INQSCAN_POS 4 +#define B3_INT_INQSCAN_MSK 0x10 +#define B3_INT_PAGESCAN_POS 5 +#define B3_INT_PAGESCAN_MSK 0x20 +#define B3_RSSI_INQ_RES_POS 6 +#define B3_RSSI_INQ_RES_MSK 0x40 +#define B3_ESCO_EV3_POS 7 +#define B3_ESCO_EV3_MSK 0x80 + +#define B4_EV4_PKT_POS 0 +#define B4_EV4_PKT_MSK 0x01 +#define B4_EV5_PKT_POS 1 +#define B4_EV5_PKT_MSK 0x02 +#define B4_AFH_CAP_SLV_POS 3 +#define B4_AFH_CAP_SLV_MSK 0x08 +#define B4_AFH_CLASS_SLV_POS 4 +#define B4_AFH_CLASS_SLV_MSK 0x10 +#define B4_BR_EDR_NOT_SUPP_POS 5 +#define B4_BR_EDR_NOT_SUPP_MSK 0x20 +#define B4_LE_SUPP_POS 6 +#define B4_LE_SUPP_MSK 0x40 +#define B4_3_SLOT_EDR_ACL_POS 7 +#define B4_3_SLOT_EDR_ACL_MSK 0x80 + +#define B5_5_SLOT_EDR_ACL_POS 0 +#define B5_5_SLOT_EDR_ACL_MSK 0x01 +#define B5_SSR_POS 1 +#define B5_SSR_MSK 0x02 +#define B5_PAUSE_ENC_POS 2 +#define B5_PAUSE_ENC_MSK 0x04 +#define B5_AFH_CAP_MST_POS 3 +#define B5_AFH_CAP_MST_MSK 0x08 +#define B5_AFH_CLASS_MST_POS 4 +#define B5_AFH_CLASS_MST_MSK 0x10 +#define B5_EDR_ESCO_2MBPS_POS 5 +#define B5_EDR_ESCO_2MBPS_MSK 0x20 +#define B5_EDR_ESCO_3MBPS_POS 6 +#define B5_EDR_ESCO_3MBPS_MSK 0x40 +#define B5_3_SLOT_EDR_ESCO_POS 7 +#define B5_3_SLOT_EDR_ESCO_MSK 0x80 + +#define B6_EIR_POS 0 +#define B6_EIR_MSK 0x01 +#define B6_SIM_LE_BREDR_DEV_CAP_POS 1 +#define B6_SIM_LE_BREDR_DEV_CAP_MSK 0x02 +#define B6_SSP_POS 3 +#define B6_SSP_MSK 0x08 +#define B6_ENCAPS_PDU_POS 4 +#define B6_ENCAPS_PDU_MSK 0x10 +#define B6_ERR_DATA_REP_POS 5 +#define B6_ERR_DATA_REP_MSK 0x20 +#define B6_NONFLUSH_PBF_POS 6 +#define B6_NONFLUSH_PBF_MSK 0x40 + +#define B7_LST_CHANGE_EVT_POS 0 +#define B7_LST_CHANGE_EVT_MSK 0x01 +#define B7_INQRES_TXPOW_POS 1 +#define B7_INQRES_TXPOW_MSK 0x02 +#define B7_ENH_PWR_CTRL_POS 2 +#define B7_ENH_PWR_CTRL_MSK 0x04 +#define B7_EXT_FEATS_POS 7 +#define B7_EXT_FEATS_MSK 0x80 + +/// Extended feature mask definition page 1 LMP:3.3 +#define B0_HOST_SSP_POS 0 +#define B0_HOST_SSP_MSK 0x01 +#define B0_HOST_LE_POS 1 +#define B0_HOST_LE_MSK 0x02 +#define B0_HOST_LE_BR_EDR_POS 2 +#define B0_HOST_LE_BR_EDR_MSK 0x04 +#define B0_HOST_SECURE_CON_POS 3 +#define B0_HOST_SECURE_CON_MSK 0x08 + +/// Extended feature mask definition page 2 LMP:3.3 +#define B0_CSB_MASTER_POS 0 +#define B0_CSB_MASTER_MSK 0x01 +#define B0_CSB_SLAVE_POS 1 +#define B0_CSB_SLAVE_MSK 0x02 +#define B0_SYNC_TRAIN_POS 2 +#define B0_SYNC_TRAIN_MSK 0x04 +#define B0_SYNC_SCAN_POS 3 +#define B0_SYNC_SCAN_MSK 0x08 +#define B0_INQ_RES_NOTIF_EVT_POS 4 +#define B0_INQ_RES_NOTIF_EVT_MSK 0x10 +#define B0_GEN_INTERL_SCAN_POS 5 +#define B0_GEN_INTERL_SCAN_MSK 0x20 +#define B0_COARSE_CLK_ADJ_POS 6 +#define B0_COARSE_CLK_ADJ_MSK 0x40 + +#define B1_SEC_CON_CTRL_POS 0 +#define B1_SEC_CON_CTRL_MSK 0x01 +#define B1_PING_POS 1 +#define B1_PING_MSK 0x02 +#define B1_SAM_POS 2 +#define B1_SAM_MSK 0x04 +#define B1_TRAIN_NUDGING_POS 3 +#define B1_TRAIN_NUDGING_MSK 0x08 + +/// Features definitions +#define FEAT_3_SLOT_BIT_POS 0 +#define FEAT_5_SLOT_BIT_POS 1 +#define FEAT_ENC_BIT_POS 2 +#define FEAT_SLOT_OFFSET_BIT_POS 3 +#define FEAT_TIMING_ACC_BIT_POS 4 +#define FEAT_SWITCH_BIT_POS 5 +#define FEAT_HOLD_BIT_POS 6 +#define FEAT_SNIFF_BIT_POS 7 + +#define FEAT_PARK_BIT_POS 8 +#define FEAT_RSSI_BIT_POS 9 +#define FEAT_QUALITY_BIT_POS 10 +#define FEAT_SCO_BIT_POS 11 +#define FEAT_HV2_BIT_POS 12 +#define FEAT_HV3_BIT_POS 13 +#define FEAT_ULAW_BIT_POS 14 +#define FEAT_ALAW_BIT_POS 15 + +#define FEAT_CVSD_BIT_POS 16 +#define FEAT_PAGING_BIT_POS 17 +#define FEAT_POWER_BIT_POS 18 +#define FEAT_TRANSP_SCO_BIT_POS 19 +#define FEAT_BCAST_ENCRYPT_BIT_POS 23 + +#define FEAT_EDR_2MB_BIT_POS 25 +#define FEAT_EDR_3MB_BIT_POS 26 +#define FEAT_ENH_INQSCAN_BIT_POS 27 +#define FEAT_INT_INQSCAN_BIT_POS 28 +#define FEAT_INT_PAGESCAN_BIT_POS 29 +#define FEAT_RSSI_INQRES_BIT_POS 30 +#define FEAT_EV3_BIT_POS 31 + +#define FEAT_EV4_BIT_POS 32 +#define FEAT_EV5_BIT_POS 33 +#define FEAT_AFH_CAPABLE_S_BIT_POS 35 +#define FEAT_AFH_CLASS_S_BIT_POS 36 +#define FEAT_BR_EDR_NO_SUPP_BIT_POS 37 +#define FEAT_LE_BIT_POS 38 +#define FEAT_3_SLOT_EDR_BIT_POS 39 +#define FEAT_5_SLOT_EDR_BIT_POS 40 +#define FEAT_SNIFF_SUBRAT_BIT_POS 41 +#define FEAT_PAUSE_ENCRYPT_BIT_POS 42 +#define FEAT_AFH_CAPABLE_M_BIT_POS 43 +#define FEAT_AFH_CLASS_M_BIT_POS 44 +#define FEAT_EDR_ESCO_2MB_BIT_POS 45 +#define FEAT_EDR_ESCO_3MB_BIT_POS 46 +#define FEAT_3_SLOT_EDR_ESCO_BIT_POS 47 +#define FEAT_EIR_BIT_POS 48 +#define FEAT_LE_BR_EDR_BIT_POS 49 +#define FEAT_SSP_BIT_POS 51 +#define FEAT_ENCAP_PDU_BIT_POS 52 +#define FEAT_ERRO_DATA_REP_BIT_POS 53 +#define FEAT_NFLUSH_PBF_BIT_POS 54 +#define FEAT_LSTO_CHG_EVT_BIT_POS 56 +#define FEAT_INQ_TXPWR_BIT_POS 57 +#define FEAT_EPC_BIT_POS 58 +#define FEAT_EXT_FEATS_BIT_POS 63 +#define FEAT_SSP_HOST_BIT_POS 64 +#define FEAT_LE_HOST_BIT_POS 65 +#define FEAT_LE_BR_EDR_HOST_BIT_POS 66 +#define FEAT_SEC_CON_HOST_BIT_POS 67 + +#define FEAT_CSB_MASTER_BIT_POS 128 +#define FEAT_CSB_SLAVE_BIT_POS 129 +#define FEAT_SYNC_TRAIN_BIT_POS 130 +#define FEAT_SYNC_SCAN_BIT_POS 131 +#define FEAT_INQ_RES_NOTIF_EVT_BIT_POS 132 +#define FEAT_GEN_INTERL_SCAN_BIT_POS 133 +#define FEAT_COARSE_CLK_ADJ_BIT_POS 134 +#define FEAT_SEC_CON_CTRL_BIT_POS 136 +#define FEAT_PING_BIT_POS 137 +#define FEAT_SAM_BIT_POS 138 +#define FEAT_TRAIN_NUDGING_BIT_POS 139 + +/// Maximum number of feature bits per page (8 bytes x 8 bits) +#define MAX_FEAT_BITS_PER_PAGE 64 + +/// Poll interval defines LMP:5.2 +#define POLL_INTERVAL_MIN 0x0006 +#define POLL_INTERVAL_DFT 0x0028 +#define POLL_INTERVAL_MAX 0x1000 + +/// Power Adjustment Request LMP:5.2 +#define PWR_ADJ_REQ_DEC_1_STEP 0x00 +#define PWR_ADJ_REQ_INC_1_STEP 0x01 +#define PWR_ADJ_REQ_INC_MAX 0x02 + +/// Power Adjustment Response LMP:5.2 +#define PWR_ADJ_RES_GFSK_POS 0 +#define PWR_ADJ_RES_GFSK_MASK 0x03 +#define PWR_ADJ_RES_DQPSK_POS 2 +#define PWR_ADJ_RES_DQPSK_MASK 0x0C +#define PWR_ADJ_RES_8DPSK_POS 4 +#define PWR_ADJ_RES_8DPSK_MASK 0x30 + +#define PWR_ADJ_RES_NOT_SUPP 0x00 +#define PWR_ADJ_RES_CHG_1_STEP 0x01 +#define PWR_ADJ_RES_MAX 0x02 +#define PWR_ADJ_RES_MIN 0x03 + +/// Nb of Broadcast retransmissions defines +#define NB_BROADCAST_DFT 0x01 + +/// Nb of Broadcast CLK_ADJ PDU Baseband:4.1.14.1 +#define NB_BROADCAST_CLK_ADJ 0x06 + +/// Min PCA clk_adj_instant (in slots) LMP:4.1.14.1 +#define PCA_INSTANT_MIN 12 + +/// Piconet Clock Adjustment clk_adj_mode LMP:4.1.14.1 +#define CLK_ADJ_BEFORE_INSTANT 0 +#define CLK_ADJ_AFTER_INSTANT 1 + + +/// Different packet types BaseBand:6.7 +/* Packet and buffer sizes. These sizes do not include payload header (except for FHS + * packet where there is no payload header) since payload header is written or read by + * the RWBT in a different control structure part (TX/RXPHDR) */ +#define FHS_PACKET_SIZE 18 +#define DM1_PACKET_SIZE 17 +#define DH1_PACKET_SIZE 27 +#define DH1_2_PACKET_SIZE 54 +#define DH1_3_PACKET_SIZE 83 +#define DV_ACL_PACKET_SIZE 9 +#define DM3_PACKET_SIZE 121 +#define DH3_PACKET_SIZE 183 +#define DH3_2_PACKET_SIZE 367 +#define DH3_3_PACKET_SIZE 552 +#define DM5_PACKET_SIZE 224 +#define DH5_PACKET_SIZE 339 +#define DH5_2_PACKET_SIZE 679 +#define DH5_3_PACKET_SIZE 1021 +#define AUX1_PACKET_SIZE 29 + +#define HV1_PACKET_SIZE 10 +#define HV2_PACKET_SIZE 20 +#define HV3_PACKET_SIZE 30 +#define EV3_PACKET_SIZE 30 +#define EV3_2_PACKET_SIZE 60 +#define EV3_3_PACKET_SIZE 90 +#define EV4_PACKET_SIZE 120 +#define EV5_PACKET_SIZE 180 +#define EV5_2_PACKET_SIZE 360 +#define EV5_3_PACKET_SIZE 540 + +/// SCO Packet coding LMP:5.2 +#define SCO_PACKET_HV1 0x00 +#define SCO_PACKET_HV2 0x01 +#define SCO_PACKET_HV3 0x02 + +/// eSCO Packet coding LMP:5.2 +#define ESCO_PACKET_NULL 0x00 +#define ESCO_PACKET_EV3 0x07 +#define ESCO_PACKET_EV4 0x0C +#define ESCO_PACKET_EV5 0x0D +#define ESCO_PACKET_EV3_2 0x26 +#define ESCO_PACKET_EV3_3 0x37 +#define ESCO_PACKET_EV5_2 0x2C +#define ESCO_PACKET_EV5_3 0x3D + +/// Max number of HV packet BaseBand:4.4.2.1 +#define MAX_NB_HV1 1 +#define MAX_NB_HV2 2 +#define MAX_NB_HV3 3 + +/// Tsco (ScoInterval) BaseBand:4.4.2.1 +#define TSCO_HV1 2 +#define TSCO_HV2 4 +#define TSCO_HV3 6 + +/* Inquiry train repetition length , Baseband :Table 10.4 + * - 256 repetitions if no SCO + * - 512 repetitions if 1 SCO + * - 768 repetitions if 2 SCO */ +#define INQ_TRAIN_LENGTH_NO_SCO 256 +#define INQ_TRAIN_LENGTH_1_SCO 512 +#define INQ_TRAIN_LENGTH_2_SCO 768 + +/* Counter for train length, Npage (N*16 slots) depends on the slave page scan mode and + * the number of active SCO: + * | SR mode | no SCO | one SCO | two SCO | + * | R0 | >=1 | >=2 | >=3 | + * | R1 | >=128 | >=256 | >=384 | + * | R2 | >=256 | >=512 | >=768 | */ +#define PAGE_TRAIN_LENGTH_R0 1 +#define PAGE_TRAIN_LENGTH_R1 128 +#define PAGE_TRAIN_LENGTH_R2 256 + +/// Synchronisation defines +#define NORMAL_SYNC_POS (64 + 4) // End of Synchro word at bit 68 (64 + 4) +#define SLOT_SIZE 625 // A slot is 625 us +#define HALF_SLOT_SIZE 625 // A half slot is 312.5 us (in half us) +#define HALF_SLOT_TIME_MIN (0) // Minimum offset within a half-slot is 0 half-us +#define HALF_SLOT_TIME_MAX (HALF_SLOT_SIZE - 1) // Maximum offset within a half-slot is 624 half-us + +/// Baseband timeout default value, Baseband timers: 1.1 +#define PAGE_RESP_TO_DEF 8 +#define INQ_RESP_TO_DEF 128 +#define NEW_CONNECTION_TO 32 + +/// LMP Response Timeout (in sec) +#define LMP_RSP_TO 30 +/// LLCP Response Timeout (in units of 10 ms) +#define LLCP_RSP_TO 4000 // 40 secs + +/// Athenticated Payload Timeout (in units of 10 ms) +#define AUTH_PAYL_TO_DFT 0x0BB8 // 30 secs +#define AUTH_PAYL_TO_MIN 0x0001 + +/// Voice mute pattern defines +#define MU_LAW_MUTE 0xFF +#define ALAW_CVSD_MUTE 0x55 +#define TRANSP_MUTE 0x00 + +/// Air Mode LMP:5.2 +#define MU_LAW_MODE 0 +#define A_LAW_MODE 1 +#define CVSD_MODE 2 +#define TRANS_MODE 3 + +/// eSCO negotiation State LMP:5.2 +#define ESCO_NEGO_INIT 0 +#define ESCO_NEGO_LATEST_POSSIBLE 1 +#define ESCO_NEGO_SLOT_VIOLATION 2 +#define ESCO_NEGO_LAT_VIOLATION 3 +#define ESCO_NEGO_UNSUPPORTED 4 + +#define SCO_BANDWIDTH 8000 +#define SYNC_BANDWIDTH_DONT_CARE 0xFFFFFFFF + +#define SYNC_MIN_LATENCY 0x0004 +#define SYNC_MAX_LATENCY_ESCO_S1 0x0007 +#define SYNC_MAX_LATENCY_ESCO_S2 0x0007 +#define SYNC_MAX_LATENCY_ESCO_S3 0x000A +#define SYNC_DONT_CARE_LATENCY 0xFFFF + +#define SYNC_NO_RE_TX 0x00 +#define SYNC_RE_TX_POWER 0x01 +#define SYNC_RE_TX_QUALITY 0x02 +#define SYNC_RE_TX_DONT_CARE 0xFF + +/// Timing Control Flags LMP:5.2 +#define TIM_CHANGE_FLAG 0x01 +#define INIT2_FLAG 0x02 +#define ACCESS_WIN_FLAG 0x04 + +/// Sniff request parameters LMP:5.2 +#define SNIFF_INTERVAL_MIN 0x0006 +#define SNIFF_INTERVAL_MAX 0x0540 +#define SNIFF_TIMEOUT_MAX 0x0028 + +/// Packet Type Table defines LMP:4.1.11 +#define PACKET_TABLE_1MBPS 0x00 +#define PACKET_TABLE_2_3MBPS 0x01 + +/// Data Rate defines LMP:5.2 +#define FEC_RATE_MSK 0x01 +#define USE_FEC_RATE 0x00 +#define NO_FEC_RATE 0x01 +#define PREF_PACK_MSK 0x06 +#define NO_PREF_PACK_SIZE 0x00 +#define USE_1_SLOT_PACKET 0x02 +#define USE_3_SLOT_PACKET 0x04 +#define USE_5_SLOT_PACKET 0x06 +#define PREF_EDR_MSK 0x18 +#define USE_DM1_ONLY 0x00 +#define USE_2_MBPS_RATE 0x08 +#define USE_3_MBPS_RATE 0x10 +#define PREF_PACK_EDR_MSK 0x60 +#define USE_1_SLOT_EDR_PKT 0x20 +#define USE_3_SLOT_EDR_PKT 0x40 +#define USE_5_SLOT_EDR_PKT 0x60 + +/// EIR Data Size HCI:6.24 +#define EIR_DATA_SIZE 240 + +/// Voice setting HCI:4.7.29 & 4.7.30 +#define INPUT_COD_LIN 0x0000 +#define INPUT_COD_MULAW 0x0100 +#define INPUT_COD_ALAW 0x0200 +#define INPUT_COD_MSK 0x0300 +#define INPUT_COD_OFF 8 +#define INPUT_DATA_1COMP 0x0000 +#define INPUT_DATA_2COMP 0x0040 +#define INPUT_DATA_SMAG 0x0080 +#define INPUT_DATA_UNSIGNED 0x00C0 +#define INPUT_DATAFORM_MSK 0x00C0 +#define INPUT_DATAFORM_OFF 6 +#define INPUT_SAMP_8BIT 0x0000 +#define INPUT_SAMP_16BIT 0x0020 +#define INPUT_SAMPSIZE_MSK 0x0020 +#define INPUT_SAMPSIZE_OFF 5 +#define LIN_PCM_BIT_POS_MSK 0x001C +#define LIN_PCM_BIT_POS_OFF 2 +#define AIR_COD_CVSD 0x0000 +#define AIR_COD_MULAW 0x0001 +#define AIR_COD_ALAW 0x0002 +#define AIR_COD_TRANS 0x0003 +#define AIR_COD_MSK 0x0003 +#define AIR_COD_OFF 0 + +/// ScanEnable HCI:6.1 +#define BOTH_SCAN_DISABLE 0 +#define INQUIRY_SCAN_ENABLE 1 +#define PAGE_SCAN_ENABLE 2 +#define BOTH_SCAN_ENABLE 3 + +/// PageScanInterval HCI:6.8 +#define PAGE_SCAN_INTV_MIN 0x0012 +#define PAGE_SCAN_INTV_MAX 0x1000 +#define PAGE_SCAN_INTV_DFT 0x0800 + +/// PageScanWindow HCI:6.9 +#define PAGE_SCAN_WIN_MIN 0x0011 +#define PAGE_SCAN_WIN_MAX 0x1000 +#define PAGE_SCAN_WIN_DFT 0x0012 + +/// InquiryScanInterval HCI:6.2 +#define INQ_SCAN_INTV_MIN 0x0012 +#define INQ_SCAN_INTV_MAX 0x1000 +#define INQ_SCAN_INTV_DFT 0x1000 + +/// InquiryScanWindow HCI:6.3 +#define INQ_SCAN_WIN_MIN 0x0011 +#define INQ_SCAN_WIN_MAX 0x1000 +#define INQ_SCAN_WIN_DFT 0x0012 + +/// General/Unlimited Inquiry Access Code (GIAC) +#define GIAC_LAP_0 0x33 +#define GIAC_LAP_1 0x8B +#define GIAC_LAP_2 0x9E + +/// Limited Dedicated Inquiry Access Code (LIAC) +#define LIAC_LAP_0 0x00 +#define LIAC_LAP_1 0x8B +#define LIAC_LAP_2 0x9E + +/// Maximum Dedicated Inquiry Access Code (DIAC MAX) +#define DIAC_MAX_LAP_0 0x3F +#define DIAC_MAX_LAP_1 0x8B +#define DIAC_MAX_LAP_2 0x9E + +/// PIN Type HCI:6.13 +#define VARIABLE_PIN 0 +#define FIXED_PIN 1 + +/// ConnectionAcceptTimeout HCI:6.7 +#define CON_ACCEPT_TO_MIN 0x00A0 +#define CON_ACCEPT_TO_MAX 0xB540 +#define CON_ACCEPT_TO_DFT 0x1FA0 + +/// PageTimeout HCI:6.6 +#define PAGE_TO_MIN 0x0016 +#define PAGE_TO_MAX 0xFFFF +#define PAGE_TO_DFT 0x2000 + +/// Clock offset valid flag in clock offset field HCI:7.1.5/7.1.19 +#define CLK_OFFSET_VALID_FLAG_POS 15 +#define CLK_OFFSET_VALID_FLAG_MSK 0x8000 + +/// AuthenticationEnable HCI:4.7.24 +#define AUTH_DISABLED 0x00 // Default +#define AUTH_ENABLED 0x01 + +/// EncryptionMode HCI:4.7.26 +#define ENC_DISABLED 0x00 // Default +#define ENC_PP_ENABLED 0x01 +#define ENC_PP_BC_ENABLED 0x02 + +/// AutomaticFlushTimeout HCI:4.7.32 +#define AUTO_FLUSH_TIMEOUT_MAX 0x07FF +#define AUTO_FLUSH_TIMEOUT_OFF 0x0000 +#define AUTO_FLUSH_TIMEOUT_DFT AUTO_FLUSH_TIMEOUT_OFF // Default (no automatic flush timeout) + +/// Link Supervision Time Out (in slots) HCI:6.21 +#define LSTO_OFF 0x0000 +#define LSTO_MIN 0x0001 +#define LSTO_DFT 0x7D00 // Default is 20 s +#define LSTO_MAX 0xFFFF + +/// PageScanRepetitionMode HCI:4.5.5 +#define R0 0x00 +#define R1 0x01 +#define R2 0x02 +#define PAGESCAN_REP_DEF R1 // Default + +/// PageScanPeriodMode HCI:4.7.49 +#define P0 0x00 // Default +#define P1 0x01 +#define P2 0x02 + +/// PageScanMode HCI:4.7.51 +#define MANDATORY_PAGE_SCAN_MODE 0x00 // Default + +#define OPT_PAGE_SCAN_MODE_1 0x01 +#define OPT_PAGE_SCAN_MODE_2 0x02 +#define OPT_PAGE_SCAN_MODE_3 0x03 + +/// Encryption Enable HCI:4.5.17 +#define ENCRYPTION_OFF 0x00 +#define ENCRYPTION_ON 0x01 + +/// Country Code HCI:4.8.4 +#define NORTH_AMERICA_EUROPE 0x00 +#define FRANCE 0x01 +#define SPAIN 0x02 +#define JAPAN 0x03 + +/// Loopback mode HCI:7.6.2 +#define NO_LOOPBACK 0x00 // Default +#define LOCAL_LOOPBACK 0x01 +#define REMOTE_LOOPBACK 0x02 + +/// Erroneous Data Reporting HCI:7.3.65 +#define ERR_DATA_REP_DIS 0x00 // Default +#define ERR_DATA_REP_EN 0x01 + +/// LM modes HCI:7.7.20 +#define LM_ACTIVE_MODE 0x00 +#define LM_HOLD_MODE 0x01 +#define LM_SNIFF_MODE 0x02 +#define LM_PARK_MODE 0x03 + +/// Key Type HCI:7.7.24 +#define COMB_KEY 0 +//#define LOCAL_UNIT_KEY 1 // deprecated since BT5.1 +//#define REMOTE_UNIT_KEY 2 // deprecated since BT5.1 +#define DEBUG_COMB_KEY 3 +#define UNAUTH_COMB_KEY_192 4 +#define AUTH_COMB_KEY_192 5 +#define CHANGED_COMB_KEY 6 +#define UNAUTH_COMB_KEY_256 7 +#define AUTH_COMB_KEY_256 8 + +/// Key Flag HCI:5.4.18 +#define SEMI_PERMANENT_KEY 0x00 +#define TEMPORARY_KEY 0x01 + +/// QOS Service Type HCI:4.6.6 +#define QOS_NO_TRAFFIC 0x00 +#define QOS_BEST_EFFORT 0x01 +#define QOS_GUARANTEED 0x02 +#define QOS_NOTSPECIFIED 0xFF + +#define QOS_WILD_CARD 0xFFFFFFFF + +/// RSSI golden range +#define RSSI_GOLDEN_RG 0x00 + +/// Inquiry TX power level (in dBm) HCI:7.3.62 +#define INQ_TX_PWR_DBM_MIN -70 +#define INQ_TX_PWR_DBM_DFT 0 +#define INQ_TX_PWR_DBM_MAX +20 + +/// Bluetooth Test Mode defines Bluetooth Test Mode: Table 3.2 + +#define PAUSE_MODE 0x00 +#define TXTEST0_MODE 0x01 +#define TXTEST1_MODE 0x02 +#define TXTEST10_MODE 0x03 +#define PRAND_MODE 0x04 +#define ACLLOOP_MODE 0x05 +#define SCOLOOP_MODE 0x06 +#define ACLNOWHIT_MODE 0x07 +#define SCONOWHIT_MODE 0x08 +#define TXTEST1100_MODE 0x09 +#define EXITTEST_MODE 0xFF + +#define HOPSINGLE 0x00 +#define HOPUSA 0x01 + +#define FIXTXPOW 0x00 +#define ADAPTTXPOW 0x01 + +/// Maximum frequency value for test mode HCI:7.8.28 +#define TEST_FREQ_MAX 39 +/// Minimum PHY value for test mode HCI:7.8.50 +#define TEST_PHY_MIN 0x01 +/// Maximum PHY value for the receiver test mode HCI:7.8.50 +#define RX_TEST_PHY_MAX 0x03 +/// Maximum PHY value for the transmitter test mode HCI:7.8.51 +#define TX_TEST_PHY_MAX 0x04 + +/// Packet type parameter bit field of LMP_test_control +#define LMP_TEST_CTRL_PKT_TYPE_CODE_POS 0 +#define LMP_TEST_CTRL_PKT_TYPE_CODE_MSK 0x0F +#define LMP_TEST_CTRL_PKT_TYPE_LINK_POS 4 +#define LMP_TEST_CTRL_PKT_TYPE_LINK_MSK 0xF0 +#define TEST_ACLSCO 0 +#define TEST_ESCO 1 +#define TEST_EDRACL 2 +#define TEST_EDRESCO 3 + +/// LMP_encapsulated_header parameters LMP:5.3 +#define LMP_ENCAPS_P192_MAJ_TYPE 1 +#define LMP_ENCAPS_P192_MIN_TYPE 1 +#define LMP_ENCAPS_P192_PAYL_LEN 48 +#define LMP_ENCAPS_P192_PAYL_NB 3 +#define LMP_ENCAPS_P256_MAJ_TYPE 1 +#define LMP_ENCAPS_P256_MIN_TYPE 2 +#define LMP_ENCAPS_P256_PAYL_LEN 64 +#define LMP_ENCAPS_P256_PAYL_NB 4 + +/// Number of bits in the passkey code used during Secure Simple Pairing +#define SSP_PASSKEY_NB_BITS 20 + +// Event Filter HCI 4.7.3 + +/// Filter type +#define CLEAR_ALL_FILTER_TYPE 0x00 +#define INQUIRY_FILTER_TYPE 0x01 +#define CONNECTION_FILTER_TYPE 0x02 + +/// Filter size +#define CLEAR_ALL_FILTER_SIZE 0 + +/// Inquiry & Connection Setup Filter Condition Type +#define ALL_FILTER_CONDITION_TYPE 0x00 +#define CLASS_FILTER_CONDITION_TYPE 0x01 +#define BD_ADDR_FILTER_CONDITION_TYPE 0x02 + +/// Auto Accept Flag +#define DO_NOT_AUTO_ACCEPT_CONNECTION 0x01 +#define ACCEPT_CONNECTION_SLAVE 0x02 +#define ACCEPT_CONNECTION_MASTER 0x03 + +/// Event Mask HCI 4.7.1 +#define NO_EVENTS_SPECIFIED_FILTER 0x00000000 +#define INQUIRY_COMPLETE_EVENT_FILTER 0x00000001 +#define INQUIRY_RESULT_EVENT_FILTER 0x00000002 +#define CONNECTION_COMPLETE_EVENT_FILTER 0x00000004 +#define CONNECTION_REQUEST_EVENT_FILTER 0x00000008 +#define DISCONNECTION_COMPLETE_EVENT_FILTER 0x00000010 +#define AUTHENTICATION_COMPLETE_EVENT_FILTER 0x00000020 +#define REMOTE_NAME_REQUEST_COMPLETE_EVENT_FILTER 0x00000040 +#define ENCRYPTION_CHANGE_EVENT_FILTER 0x00000080 +#define CHANGE_CONNECTION_LINK_KEY_COMPLETE_EVENT_FILTER 0x00000100 +#define MASTER_LINK_KEY_COMPLETE_EVENT_FILTER 0x00000200 +#define READ_REMOTE_SUPPORTED_FEATURES_COMPLETE_EVENT_FILTER 0x00000400 +#define READ_REMOTE_VERSION_INFORMATION_COMPLETE_EVENT_FILTER 0x00000800 +#define QOS_SETUP_COMPLETE_EVENT_FILTER 0x00001000 +#define COMMAND_COMPLETE_EVENT_FILTER 0x00002000 // Unchecked */ +#define COMMAND_STATUS_EVENT_FILTER 0x00004000 // Unchecked */ +#define HARDWARE_ERROR_EVENT_FILTER 0x00008000 +#define FLUSH_OCCURRED_EVENT_FILTER 0x00010000 +#define ROLE_CHANGE_EVENT_FILTER 0x00020000 +#define NUMBER_OF_COMPLETED_PACKETS_EVENT_FILTER 0x00040000 // Unchecked */ +#define MODE_CHANGE_EVENT_FILTER 0x00080000 +#define RETURN_LINK_KEYS_EVENT_FILTER 0x00100000 +#define PIN_CODE_REQUEST_EVENT_FILTER 0x00200000 +#define LINK_KEY_REQUEST_EVENT_FILTER 0x00400000 +#define LINK_KEY_NOTIFICATION_EVENT_FILTER 0x00800000 +#define LOOPBACK_COMMAND_EVENT_FILTER 0x01000000 // Not implemented */ +#define DATA_BUFFER_OVERFLOW_EVENT_FILTER 0x02000000 +#define MAX_SLOTS_CHANGE_EVENT_FILTER 0x04000000 +#define READ_CLOCK_OFFSET_COMPLETE_EVENT_FILTER 0x08000000 +#define CONNECTION_PACKET_TYPE_CHANGED_EVENT_FILTER 0x10000000 +#define QOS_VIOLATION_EVENT_FILTER 0x20000000 +#define PAGE_SCAN_MODE_CHANGE_EVENT_FILTER 0x40000000 // Deprecated */ +#define PAGE_SCAN_REPETITION_MODE_CHANGE_EVENT_FILTER 0x80000000 + +#define FLOW_SPECIFICATION_COMPLETE_EVENT_FILTER 0x00000001 +#define INQUIRY_RESULT_WITH_RSSI_EVENT_FILTER 0x00000002 +#define READ_REMOTE_EXTENDED_FEATURES_COMPLETE_EVENT_FILTER 0x00000004 +#define SYNCHRONOUS_CONNECTION_COMPLETE_EVENT_FILTER 0x00000800 +#define SYNCHRONOUS_CONNECTION_CHANGE_EVENT_FILTER 0x00001000 +#define SNIFF_SUBRATING_EVENT_FILTER 0x00002000 +#define EXTENDED_INQUIRY_RESULT_EVENT_FILTER 0x00004000 +#define ENCRYPTION_KEY_REFRESH_COMPLETE_EVENT_FILTER 0x00008000 +#define IO_CAPABILITY_REQUEST_EVENT_FILTER 0x00010000 +#define IO_CAPABILITY_REQUEST_REPLY_EVENT_FILTER 0x00020000 +#define USER_CONFIRMATION_REQUEST_EVENT_FILTER 0x00040000 +#define USER_PASSKEY_REQUEST_EVENT_FILTER 0x00080000 +#define REMOTE_OOB_DATA_REQUEST_EVENT_FILTER 0x00100000 +#define SIMPLE_PAIRING_COMPLETE_EVENT_FILTER 0x00200000 +#define LINK_SUPERVISION_TIMEOUT_CHANGE_EVENT_FILTER 0x00800000 +#define ENHANCED_FLUSH_COMPLETE_EVENT_FILTER 0x01000000 +#define USER_PASSKEY_NOTIFICATION_EVENT_FILTER 0x04000000 +#define KEYPRESS_NOTIFICATION_EVENT_FILTER 0x08000000 +#define REM_HOST_SUPPORTED_FEATURES_NOTIFICATION_EVENT_FILTER 0x10000000 + +/// HostControllerToHostFlowControl (ACL) HCI 7.3.40 +#define FLOW_CONTROL_OFF 0x00 +#define FLOW_CONTROL_ACL 0x01 +#define FLOW_CONTROL_SCO 0x02 +#define FLOW_CONTROL_ACL_SCO 0x03 + +/// SynchroinousFlowControlEnable (SCO) HCI 7.3.39 +#define SYNC_FLOW_CONTROL_OFF 0x00 +#define SYNC_FLOW_CONTROL_ON 0x01 + +/// Tx Power HCI:4.7.37 +#define CURRENT_TX_POWER 0x00 +#define MAX_TX_POWER 0x01 + +/// Flow_direction HCI:7.2.13 +#define FLOW_DIR_OUT 0x00 +#define FLOW_DIR_IN 0x01 + +/// Drift and Jitter default value LMP 5.2 +#define DRIFT_BLE_DFT 500 +#define DRIFT_BT_DFT 250 +#define JITTER_DFT 10 +#define DRIFT_BT_ACTIVE_MAX 20 // BB:2.2.5 + +/// MAX LP Clock Jitter allowed by the specification (in us) (Core 4.2 - vol 6, -B - 4.2.2) +#define BLE_MAX_JITTER (16) + +/// Read Stored Link Key HCI:4.7.8 +#define LINK_KEY_BD_ADDR 0x00 +#define LINK_KEY_ALL 0x01 + +/// Read/Write Hold Mode Activity HCI:4.7.35 and 4.7.36 +#define HOLD_MODE_ACTIV_DEFAULT 0x00 +#define HOLD_MODE_ACTIV_SUSP_PAGE_SCAN 0x01 +#define HOLD_MODE_ACTIV_SUSP_INQUIRY_SCAN 0x02 +#define HOLD_MODE_ACTIV_SUSP_PERIODIC_INQ 0x04 +#define HOLD_MODE_ACTIV_NOT_MASK 0xF8 + +/// AFH Mode +#define AFH_DISABLED 0x00 +#define AFH_ENABLED 0x01 + +/// AFH Reporting Mode +#define AFH_REPORTING_DISABLED 0x00 +#define AFH_REPORTING_ENABLED 0x01 + +/// AFH channel assessment Mode +#define AFH_CH_ASS_DISABLED 0x00 +#define AFH_CH_ASS_ENABLED 0x01 + +/// AFH MIn/Max interval, in BT slots (1s - 30s) +#define AFH_REPORT_INTERVAL_MIN 0x0640 +#define AFH_REPORT_INTERVAL_MAX 0xBB80 + +/// Channel classification values for frequency pairs +#define AFH_CH_CLASS_UNKNOWN 0x0 +#define AFH_CH_CLASS_GOOD 0x1 +#define AFH_CH_CLASS_RESERVED 0x2 +#define AFH_CH_CLASS_BAD 0x3 + +/// Maximum number of frequencies used in adapted channel hopping sequence +#define AFH_NB_CHANNEL_MIN 20 +#define AFH_NB_CHANNEL_MAX 79 + +/// Number of frequencies available in standard hopping sequence +#define HOP_NB_CHANNEL 79 + +/// Base frequency in MHz of first BT hop channel [f=2402+k MHz, k=0,...,78] +#define HOP_CHANNEL_BASE_MHZ 2402 + +/// Maximum number of frequencies used in synchronization train BB:2.6.4.8 +#define SYNC_TRAIN_CHANNEL_NB 3 +/// Indices of frequencies used in synchronization train +#define SYNC_TRAIN_CHANNEL_0 0 +#define SYNC_TRAIN_CHANNEL_1 24 +#define SYNC_TRAIN_CHANNEL_2 78 + +/// Maximum delay in synchronization train (in slots) BB:2.7.2 +#define SYNC_TRAIN_DELAY_MAX_DFT 16 +/// Maximum delay in synchronization train for Coarse clock adjustment (in slots) BB:2.7.2 +#define SYNC_TRAIN_DELAY_MAX_CLK_ADJ 4 +/// Synchronization train interval for Coarse clock adjustment (in slots) BB:2.7.2 +#define SYNC_TRAIN_INTV_CLK_ADJ 32 + +/// Future CSB instant value offset for Coarse clock adjustment (in slots) BB: 8.11.2 +#define SYNC_TRAIN_CSB_INSTANT_OFFSET_CLK_ADJ 1600 + +/// Minimum value for synchronization train interval (in slots) HCI:7.3.90 +#define SYNC_TRAIN_INTV_MIN 0x20 +/// Minimum value for synchronization train timeout (in slots) HCI:7.3.90 +#define SYNC_TRAIN_TO_MIN 0x00000002 +/// Maximum value for synchronization train timeout (in slots) HCI:7.3.90 +#define SYNC_TRAIN_TO_MAX 0x07FFFFFE + +/// Default value for synchronization train interval (in slots) HCI:6.36 +#define SYNC_TRAIN_INTV_DEFAULT 0x80 +/// Default value for synchronization train timeout (in slots) HCI:6.37 +#define SYNC_TRAIN_TO_DEFAULT 0x0002EE00 +/// Default value for synchronization scan timeout for CCA recovery mode (in slots) BB: Appendix B.1.8 +#define SYNC_TRAIN_TO_CCA_RM_DEFAULT 0x8000 +/// Default value for synchronization train service data HCI:6.39 +#define SYNC_TRAIN_SVC_DATA_DEFAULT 0x00 + +/// Minimum value for synchronization scan timeout (in slots) HCI:7.1.52 +#define SYNC_SCAN_TO_MIN 0x22 +/// Minimum value for synchronization scan window (in slots) HCI:7.1.52 +#define SYNC_SCAN_WIN_MIN 0x22 +/// Minimum value for synchronization scan interval (in slots) HCI:7.1.52 +#define SYNC_SCAN_INTV_MIN 0x02 + +/// Default value for synchronization scan timeout (in slots) BB: Apppendix B +#define SYNC_SCAN_TO_DEFAULT 0x2000 +/// Default value for synchronization scan timeout for CCA recovery mode (in slots) BB: Appendix B.1.9 +#define SYNC_SCAN_TO_CCA_RM_DEFAULT 0x8000 +/// Recommended value for synchronization scan window (91.25ms) GAP: Appendix A +#define SYNC_SCAN_WIN_DEFAULT 0x0092 +/// Recommended value for synchronization scan interval (320 ms) GAP: Appendix A +#define SYNC_SCAN_INTV_DEFAULT 0x0200 + + +/// CSB receive enable HCI:7.1.50 +#define CSB_RX_MODE_DIS 0x00 +#define CSB_RX_MODE_EN 0x01 + +/// CSB fragment HCI:7.2.88 +#define CSB_CONTINUATION_FRAGMENT 0 +#define CSB_STARTING_FRAGMENT 1 +#define CSB_ENDING_FRAGMENT 2 +#define CSB_NO_FRAGMENTATION 3 + +/// CSB max fragment size HCI:7.2.88 +#define CSB_FRAGMENT_SIZE_MAX 0xFF + +/// MWS Channel_Enable +#define MWS_CHANNEL_DISABLED 0x00 +#define MWS_CHANNEL_ENABLED 0x01 + +/// MWS Channel_Type +#define MWS_TDD_CHANNEL_TYPE 0x00 +#define MWS_FDD_CHANNEL_TYPE 0x01 + +/// MWS Transport_Layer +#define MWS_SIGNALING_ONLY 0x00 +#define MWS_WCI_1 0x01 +#define MWS_WCI_2 0x02 +#define MWS_TRANSPORT_TYPE_MAX 0x02 + +/// MWS PATTERN Index +#define MWS_PATTERN_INDEX_MAX 2 + +/// MWS PATTERN IntervalType +#define MWS_PATTERN_NO_TXRX 0 +#define MWS_PATTERN_TX_ALLOWED 1 +#define MWS_PATTERN_RX_ALLOWED 2 +#define MWS_PATTERN_TXRX_ALLOWED 3 +#define MWS_PATTERN_EXT_FRAME 4 +#define MWS_PATTERN_TYPE_MAX 4 + + +/// MWS Ext_Num_Periods +#define MWS_EXT_NUM_PERIODS_MIN 0x01 +#define MWS_EXT_NUM_PERIODS_MAX 0x32 + +/// MWS Period_Type +#define MWS_PERIOD_TYPE_DOWNLINK 0x00 +#define MWS_PERIOD_TYPE_UPLINK 0x01 +#define MWS_PERIOD_TYPE_BIDIRECTIONAL 0x02 +#define MWS_PERIOD_TYPE_GUARD_PERIOD 0x03 +#define MWS_PERIOD_TYPE_RESERVED 0x04 + +/// MWS inactivity duration 7B(WCI-1):3.1.4. +#define MWS_INACT_DUR_INFINITE 0x1F + + +/// Simple pairing mode HCI:7.3.58/HCI:7.3.59 +#define SP_MODE_DIS 0x00 +#define SP_MODE_EN 0x01 + +/// Inquiry Scan Type and Page Scan Type HCI:6.4/HCI:6.11 +#define STANDARD_SCAN 0x00 +#define INTERLACED_SCAN 0x01 + +/// Default interlace offset used for frequency selection during interlaced inquiry/page scan BB:8.3.1/8.4.1 +#define INTERLACE_OFFSET_DFT 16 + +/// Inquiry Mode +#define STANDARD_INQUIRY 0x00 +#define RSSI_INQUIRY 0x01 +#define EXTENDED_INQUIRY 0x02 + +/// Maximum number of link keys Host can write via HCI Write Stored Link Key Command +#define NB_LINK_KEY 0x0B + +/// LMP Version +#define BT_LMP_V1_0 0 +#define BT_LMP_V1_1 1 +#define BT_LMP_V1_2 2 +#define BT_LMP_V2_0 3 +#define BT_LMP_V2_1 4 +#define BT_LMP_V3_0 5 +#define BT_LMP_V4_0 6 +#define BT_LMP_V4_1 7 + +/// WhichClock parameter +#define LOCAL_CLOCK 0 +#define PICONET_CLOCK 1 + +/// Clock Accuracy parameter +#define CLOCK_ACCURACY_UNKNOWN 0xFFFF + +#define SP_PASSKEY_STARTED 0x00 +#define SP_PASSKEY_DIGIT_ENTERED 0x01 +#define SP_PASSKEY_DIGIT_ERASED 0x02 +#define SP_PASSKEY_CLEARED 0x03 +#define SP_PASSKEY_COMPLETED 0x04 + +// Flags for ld_util_get_nb_acl function +/// Flag for master link +#define MASTER_FLAG 0x01 +/// Flag for slave link +#define SLAVE_FLAG 0x02 + + +/// BLE packet info in bytes +#define BLE_PKT_HDR_LEN (2) +#define BLE_PKT_CRC_LEN (3) +#define BLE_PKT_ACCESS_LEN (4) + +/// IFS duration in us +#define BLE_IFS_DUR (150) + +/// MAFS duration in us +#define BLE_MAFS_DUR (300) + +/// Offset threshold in us, below which Offset Units is set to 0 +#define OFFSET_THRESHOLD 245700 + +/// Maximum offset value (in us) that can be represented by the Sync Packet Offset +#define OFFSET_LIMIT 2457300 + +/// Offset adjust value in us +#define OFFSET_ADJUST 2457600 + +/// Maximum time difference (in us) between lastPaEventCount and EventCounter +#define OFFSET_DIFF_MAX 5000000 + +/// CTE defines + +/** + * Sync CTE type, specifies whether to only sync to periodic advertising with certain types of + * Constant Tone Extension (HCI:7.8.67) + */ +enum sync_cte_type +{ + NO_SYNC_AOA_BIT = (0x01) , + NO_SYNC_AOA_POS = (0) , + NO_SYNC_AOD_1US_BIT = (0x02) , + NO_SYNC_AOD_1US_POS = (1) , + NO_SYNC_AOD_2US_BIT = (0x04) , + NO_SYNC_AOD_2US_POS = (2) , + NO_SYNC_NO_CTE_BIT = (0x10) , + NO_SYNC_NO_CTE_POS = (4) , + +}; + +/// Modulation index +#define STANDARD_MOD_IDX (0) +#define STABLE_MOD_IDX (1) + +/// CTE length (in number of 8us periods) +#define NO_CTE (0) +#define CTE_LEN_MIN (0x02) +#define CTE_LEN_MAX (0x14) + +/// CTE type +#define CTE_TYPE_AOA (0) +#define CTE_TYPE_AOD_1US (1) +#define CTE_TYPE_AOD_2US (2) +#define CTE_TYPE_NO_CTE (0xFF) + +/// CTE types +enum cte_types +{ + CTE_TYPES_AOA_BIT = (0x01) , + CTE_TYPES_AOA_POS = (0) , + CTE_TYPES_AOD_1US_BIT = (0x02) , + CTE_TYPES_AOD_1US_POS = (1) , + CTE_TYPES_AOD_2US_BIT = (0x04) , + CTE_TYPES_AOD_2US_POS = (2) , +}; + +/// Slot durations (in us) +#define SLOT_DUR_1US (1) +#define SLOT_DUR_2US (2) + +/// Length of switching pattern +#define MIN_SWITCHING_PATTERN_LEN (0x02) +#define MAX_SWITCHING_PATTERN_LEN (0x4B) + +/// CTE count +#define MIN_CTE_CNT (0x01) +#define MAX_CTE_CNT (0x10) + +/// CTE enable +#define CTE_DIS (0) +#define CTE_EN (1) + +/// Sampling enable +#define IQ_SAMPL_DIS (0) +#define IQ_SAMPL_EN (1) + +/// CTE request interval (in number of connection events) HCI:7.8.85 +#define CTE_ASAP (0x0000) +#define MIN_CTE_INTV (0x0001) +#define MAX_CTE_INTV (0xFFFF) + +/// Supported switching sampling rates +#define AOD_TX_1_US (0x01) +#define AOD_RX_1_US (0x02) +#define AOA_RX_1_US (0x04) + +/// Number of antennae +#define MIN_ANTENNAE_NUM (0x01) +#define MAX_ANTENNAE_NUM (0x4B) + +/// Sample count +#define MIN_SAMPLE_CNT (0x09) +#define MAX_SAMPLE_CNT (0x52) + +/// No valid sample available +#define NO_VALID_SAMPLE (0x80) + +/// CTE packet status HCI:7.7.65.21 +#define CTE_PKT_STAT_CRC_OK (0x00) +#define CTE_PKT_STAT_CRC_KO_LEN_USED (0x01) +#define CTE_PKT_STAT_CRC_KO_OTHER_WAY (0x02) +#define CTE_PKT_STAT_INSUF_RES (0xFF) + +/// Periodic advertising sync transfer defines + +/** + * Periodic advertising sync information reception mode HCI:7.8.91 + * 0x00 - No attempt is made to synchronize to the periodic advertising and no HCI_LE_Periodic_Advertising_Sync_Transfer_Received event is sent to the Host. + * 0x01 - An HCI_LE_Periodic_Advertising_Sync_Transfer_Received event is sent to the Host. HCI_LE_Periodic_Advertising_Report events will be disabled. + * 0x02 - An HCI_LE_Periodic_Advertising_Sync_Transfer_Received event is sent to the Host. HCI_LE_Periodic_Advertising_Report events will be enabled. + */ +enum per_adv_sync_info_rec_mode +{ + NO_SYNC = 0x00, + SYNC_REP_DIS = 0x01, + SYNC_REP_EN = 0x02, +}; + +/** + * Private key type HCI:7.8.93 + * 0x00 - Use the generated private key + * 0x01 - Use the debug private key + */ +enum priv_key_type +{ + USE_GEN_PRIV_KEY = 0x00, + USE_DBG_PRIV_KEY = 0x01, +}; + +/** + * Action on clock accuracy HCI:7.8.94 + * 0x00 - Switch to a more accurate clock + * 0x01 - Switch to a less accurate clock + */ +enum clk_acc_action +{ + SWITCH_TO_MORE_ACC_CLK = 0x00, + SWITCH_TO_LESS_ACC_CLK = 0x01, +}; + +/// BLE event mask +enum le_evt_mask +{ + LE_EVT_MASK_CON_CMP_EVT_BIT = 0, + LE_EVT_MASK_CON_CMP_EVT_MSK = 0x00000001, + LE_EVT_MASK_ADV_REP_EVT_BIT = 1, + LE_EVT_MASK_ADV_REP_EVT_MSK = 0x00000002, + LE_EVT_MASK_CON_UPD_EVT_BIT = 2, + LE_EVT_MASK_CON_UPD_EVT_MSK = 0x00000004, + LE_EVT_MASK_CON_RD_REM_FEAT_EVT_BIT = 3, + LE_EVT_MASK_CON_RD_REM_FEAT_EVT_MSK = 0x00000008, + LE_EVT_MASK_LG_TR_KEY_REQ_EVT_BIT = 4, + LE_EVT_MASK_LG_TR_KEY_REQ_EVT_MSK = 0x00000010, + LE_EVT_MASK_REM_CON_PARA_REQ_EVT_BIT = 5, + LE_EVT_MASK_REM_CON_PARA_REQ_EVT_MSK = 0x00000020, + LE_EVT_MASK_DATA_LEN_CHG_EVT_BIT = 6, + LE_EVT_MASK_DATA_LEN_CHG_EVT_MSK = 0x00000040, + LE_EVT_MASK_RD_LOC_P256_PUB_KEY_CMP_EVT_BIT = 7, + LE_EVT_MASK_RD_LOC_P256_PUB_KEY_CMP_EVT_MSK = 0x00000080, + LE_EVT_MASK_GEN_DHKEY_CMP_EVT_BIT = 8, + LE_EVT_MASK_GEN_DHKEY_CMP_EVT_MSK = 0x00000100, + LE_EVT_MASK_ENH_CON_CMP_EVT_BIT = 9, + LE_EVT_MASK_ENH_CON_CMP_EVT_MSK = 0x00000200, + LE_EVT_MASK_DIR_ADV_REP_EVT_BIT = 10, + LE_EVT_MASK_DIR_ADV_REP_EVT_MSK = 0x00000400, + LE_EVT_MASK_PHY_UPD_CMP_EVT_BIT = 11, + LE_EVT_MASK_PHY_UPD_CMP_EVT_MSK = 0x00000800, + LE_EVT_MASK_EXT_ADV_REPORT_EVT_BIT = 12, + LE_EVT_MASK_EXT_ADV_REPORT_EVT_MSK = 0x00001000, + LE_EVT_MASK_PER_ADV_SYNC_EST_EVT_BIT = 13, + LE_EVT_MASK_PER_ADV_SYNC_EST_EVT_MSK = 0x00002000, + LE_EVT_MASK_PER_ADV_REPORT_EVT_BIT = 14, + LE_EVT_MASK_PER_ADV_REPORT_EVT_MSK = 0x00004000, + LE_EVT_MASK_PER_ADV_SYNC_LOST_EVT_BIT = 15, + LE_EVT_MASK_PER_ADV_SYNC_LOST_EVT_MSK = 0x00008000, + LE_EVT_MASK_EXT_SCAN_TIMEOUT_EVT_BIT = 16, + LE_EVT_MASK_EXT_SCAN_TIMEOUT_EVT_MSK = 0x00010000, + LE_EVT_MASK_EXT_ADV_SET_TERMINATED_EVT_BIT = 17, + LE_EVT_MASK_EVT_ADV_SET_TERMINATED_EVT_MSK = 0x00020000, + LE_EVT_MASK_SCAN_REQ_RECEIVED_EVT_BIT = 18, + LE_EVT_MASK_SCAN_REQ_RECEIVED_EVT_MSK = 0x00040000, + LE_EVT_MASK_CH_SEL_ALGO_EVT_BIT = 19, + LE_EVT_MASK_CH_SEL_ALGO_EVT_MSK = 0x00080000, + LE_EVT_MASK_CONLESS_IQ_REPORT_EVT_BIT = 20, + LE_EVT_MASK_CONLESS_IQ_REPORT_EVT_MSK = 0x00100000, + LE_EVT_MASK_CON_IQ_REPORT_EVT_BIT = 21, + LE_EVT_MASK_CON_IQ_REPORT_EVT_MSK = 0x00200000, + LE_EVT_MASK_CTE_REQ_FAILED_EVT_BIT = 22, + LE_EVT_MASK_CTE_REQ_FAILED_EVT_MSK = 0x00400000, + LE_EVT_MASK_PER_ADV_SYNC_TRANSF_REC_EVT_BIT = 23, + LE_EVT_MASK_PER_ADV_SYNC_TRANSF_REC_EVT_MSK = 0x00800000, + + LE_EVT_MASK_DFT = 0x0000001F, +}; + +/// Enhanced Synchronous Connection HCI:7.1.41 & 7.1.42 +#define CODING_FORMAT_ULAW 0x00 +#define CODING_FORMAT_ALAW 0x01 +#define CODING_FORMAT_CVSD 0x02 +#define CODING_FORMAT_TRANSP 0x03 +#define CODING_FORMAT_LINPCM 0x04 +#define CODING_FORMAT_MSBC 0x05 +#define CODING_FORMAT_VENDSPEC 0xFF + +#define PCM_FORMAT_NA 0x00 +#define PCM_FORMAT_1SCOMP 0x01 +#define PCM_FORMAT_2SCOMP 0x02 +#define PCM_FORMAT_SIGNMAG 0x03 +#define PCM_FORMAT_UNSIGNED 0x04 + +#define PCM_SAMPLE_SIZE_8BITS 8 +#define PCM_SAMPLE_SIZE_16BITS 16 + +#define AUDIO_DATA_PATH_HCI 0 +#define AUDIO_DATA_PATH_PCM 1 + +/// Default maximum number of slots per packet +#define MAX_SLOT_DFT 1 + +/// Packet type code interpretation possibilities BB:6.5 +#define ID_NUL_TYPE 0x0 +#define POLL_TYPE 0x1 +#define FHS_TYPE 0x2 +#define DM1_TYPE 0x3 +#define DH1_TYPE 0x4 +#define DH1_2_TYPE 0x4 +#define DH1_3_TYPE 0x8 +#define HV1_TYPE 0x5 +#define HV2_TYPE 0x6 +#define EV3_2_TYPE 0x6 +#define HV3_TYPE 0x7 +#define EV3_TYPE 0x7 +#define EV3_3_TYPE 0x7 +#define DV_TYPE 0x8 +#define AUX1_TYPE 0x9 +#define DM3_TYPE 0xA +#define DH3_TYPE 0xB +#define DH3_2_TYPE 0xA +#define DH3_3_TYPE 0xB +#define EV4_TYPE 0xC +#define EV5_2_TYPE 0xC +#define EV5_TYPE 0xD +#define EV5_3_TYPE 0xD +#define DM5_TYPE 0xE +#define DH5_TYPE 0xF +#define DH5_2_TYPE 0xE +#define DH5_3_TYPE 0xF + +/// Format of the FHS payload BB:6.5.1.4 +#define FHS_PAR_BITS_POS 0 +#define FHS_PAR_BITS_LEN 34 +#define FHS_PAR_BITS_END (FHS_PAR_BITS_POS + FHS_PAR_BITS_LEN) +#define FHS_LAP_POS FHS_PAR_BITS_END +#define FHS_LAP_LEN 24 +#define FHS_LAP_END (FHS_LAP_POS + FHS_LAP_LEN) +#define FHS_EIR_POS FHS_LAP_END +#define FHS_EIR_LEN 1 +#define FHS_EIR_END (FHS_EIR_POS + FHS_EIR_LEN) +#define FHS_UNDEF_POS FHS_EIR_END +#define FHS_UNDEF_LEN 1 +#define FHS_UNDEF_END (FHS_UNDEF_POS + FHS_UNDEF_LEN) +#define FHS_SR_POS FHS_UNDEF_END +#define FHS_SR_LEN 2 +#define FHS_SR_END (FHS_SR_POS + FHS_SR_LEN) +#define FHS_RSVD_POS FHS_SR_END +#define FHS_RSVD_LEN 2 +#define FHS_RSVD_END (FHS_RSVD_POS + FHS_RSVD_LEN) +#define FHS_UAP_POS FHS_RSVD_END +#define FHS_UAP_LEN 8 +#define FHS_UAP_END (FHS_UAP_POS + FHS_UAP_LEN) +#define FHS_NAP_POS FHS_UAP_END +#define FHS_NAP_LEN 16 +#define FHS_NAP_END (FHS_NAP_POS + FHS_NAP_LEN) +#define FHS_CLASS_OF_DEV_POS FHS_NAP_END +#define FHS_CLASS_OF_DEV_LEN 24 +#define FHS_CLASS_OF_DEV_END (FHS_CLASS_OF_DEV_POS + FHS_CLASS_OF_DEV_LEN) +#define FHS_LT_ADDR_POS FHS_CLASS_OF_DEV_END +#define FHS_LT_ADDR_LEN 3 +#define FHS_LT_ADDR_END (FHS_LT_ADDR_POS + FHS_LT_ADDR_LEN) +#define FHS_CLK_POS FHS_LT_ADDR_END +#define FHS_CLK_LEN 26 +#define FHS_CLK_END (FHS_CLK_POS + FHS_CLK_LEN) +#define FHS_PAGE_SCAN_MODE_POS FHS_CLK_END +#define FHS_PAGE_SCAN_MODE_LEN 3 +#define FHS_PAGE_SCAN_MODE_END (FHS_PAGE_SCAN_MODE_POS + FHS_PAGE_SCAN_MODE_LEN) + +/// Format of the STP payload BB:8.11.2 +#define STP_CLK_POS 0 +#define STP_CLK_LEN 4 +#define STP_FUT_CSB_INST_POS 4 +#define STP_FUT_CSB_INST_LEN 4 +#define STP_AFH_CH_MAP_POS 8 +#define STP_AFH_CH_MAP_LEN 10 +#define STP_MST_BD_ADDR_POS 18 +#define STP_MST_BD_ADDR_LEN 6 +#define STP_CSB_INTV_POS 24 +#define STP_CSB_INTV_LEN 2 +#define STP_CSB_LT_ADDR_POS 26 +#define STP_CSB_LT_ADDR_LEN 1 +#define STP_SVC_DATA_POS 27 +#define STP_SVC_DATA_LEN 1 +#define STP_PACKET_SIZE 28 + +/// CSB Receive status HCI:7.7.69 +#define CSB_RX_OK 0x00 +#define CSB_RX_KO 0x01 + +/// HCI 7.8.33 LE Set Data Length Command +/// Preferred minimum number of payload octets +#define LE_MIN_OCTETS (27) +/// Preferred minimum number of microseconds +#define LE_MIN_TIME (328) +/// Preferred minimum number of microseconds LL:4.5.10 +#define LE_MIN_TIME_CODED (2704) +/// Preferred maximum number of payload octets +#define LE_MAX_OCTETS (251) +/// Preferred maximum number of microseconds +#define LE_MAX_TIME (2120) +/// Preferred maximum number of microseconds LL:4.5.10 +#define LE_MAX_TIME_CODED (17040) + +/// LE LL 2.1.2 Access Address +#define LE_ADV_CH_ACC_ADDR_H 0x8E89 +#define LE_ADV_CH_ACC_ADDR_L 0xBED6 + +/// Resolvable private address timeout (in seconds) HCI:7.8.45 +#define RPA_TO_MAX 0xA1B8 // approximately 11.5 hours +#define RPA_TO_DFT 0x0384 // 900 seconds or 15 minutes +#define RPA_TO_MIN 0x0001 // 1 second + +/// Max scanning PHYs which can be set HCI:7.8.64 +#define MAX_SCAN_PHYS 2 + +/// Max initiating PHYs which can be set HCI:7.8.66 +#define MAX_INIT_PHYS 3 + +/// Ext Scanning interval (in 625us slot) (chapter 2.E.7.8.64) +#define EXT_SCAN_INTERVAL_MIN 0x0004 //(2.5 ms) +#define EXT_SCAN_INTERVAL_MAX 0xFFFF //(40.96 sec) + +/// Ext Scanning window (in 625us slot) (chapter 2.E.7.8.64) +#define EXT_SCAN_WINDOW_MIN 0x0004 //(2.5 ms) +#define EXT_SCAN_WINDOW_MAX 0xFFFF //(40.96 sec) + +/// Duration of 1MBPS PDU of specified payload length in microseconds (chapter 6.B.2.1) +#define PDU_1MBPS_LEN_US(n_bytes) ((8 + (2 + n_bytes))*8) // (1 + 4 + (2 + payload_len) + 3)*8 + +/// Duration of 2MBPS PDU of specified payload length in microseconds (chapter 6.B.2.1) +#define PDU_2MBPS_LEN_US(n_bytes) ((9 + (2 + n_bytes))*4) // (2 + 4 + (2 + payload_len) + 3)*4 + +/// Duration of 500KBPS PDU of specified payload length in microseconds (chapter 6.B.2.2) +#define PDU_500KBPS_LEN_US(n_bytes) (430 + (2 + n_bytes)*16) // 80 + 256 + 16 + 24 + (2 + payload_len)*8*2 + 24*2 + 3*2 + +/// Duration of 125KBPS PDU of specified payload length in microseconds (chapter 6.B.2.2) +#define PDU_125KBPS_LEN_US(n_bytes) (592 + (2 + n_bytes)*64) // 80 + 256 + 16 + 24 + (2 + payload_len)*8*8 + 24*8 + 3*8 + +/// Maximum length of BLE advertising channel PDU payloads ((chapter 6.B.2.3)) +#define PDU_ADV_PAYLOAD_LEN_MAX 255 + +// The total amount of Host Advertising Data before fragmentation shall not exceed 1650 octets (chapter 6.B.2.3.4.9). +#define HOST_ADV_DATA_LEN_MAX 1650 + +/// SyncInfo Sync Packet Offset unspecified (chapter 6.B.2.3) +#define PER_SYNC_OFFSET_UNSPECIFIED 0 + +/// SyncInfo Sync Interval min in 1.25ms units (chapter 6.B.2.3) +#define PER_SYNC_INTERVAL_MIN 6 // (7.5ms) + +/// Ext Adv Report - ADV SID - Define for no ADI filed in the PDU HCI:7.7.65.13 +#define REP_ADV_NO_ADI 0xFF + +/// Ext Adv Report - Tx Power & RSSI dBm - Define for information not available HCI:7.7.65.13 +#define REP_ADV_DBM_UNKNOWN 127 + +/// Periodic Advertising Report - Unused parameter - mandatory value HCI:7.7.65.15 +#define PER_ADV_REPORT_TRAIL_BYTE 0xFF + +/// Maximum advertising handle HCI:7.8.53 +#define ADV_HDL_MAX 0xEF + +/// Maximum advertising Set ID HCI:7.8.53 +#define ADV_SID_MAX 0x0F + +/// Advertising_Tx_Power, Host has no preference HCI:7.8.53 +#define ADV_TX_PWR_NO_PREF 127 + +/// Address type of devices sending anonymous advertisements, HCI 7.8.16 +#define ANONYMOUS_ADV_ADDR_TYPE 0xFF + +/// Invalid param_req offset, 2.4.2.16 LL_CONNECTION_PARAM_REQ +#define PARAM_REQ_INVALID_OFFSET 0xFFFF +/* + * *********************************************************** + * ISOCHRONOUS CHANNEL DEFINES + * *********************************************************** + */ + +/// Size of payload count +#define BLE_PLD_CNT_SIZE (5) +/// Invalid Isochronous handle +#define BLE_INVALID_ISOHDL (0xFFFF) + + +/* + * ENUMERATIONS + **************************************************************************************** + */ + +/// Specify if Host has no preference into all_phys parameter HCI:7.8.48 / HCI:7.8.49 +enum le_phys_preference +{ + /// The Host has no preference among the transmitter PHYs supported by the Controller + ALL_PHYS_TX_NO_PREF = (1 << 0), + /// The Host has no preference among the receiver PHYs supported by the Controller + ALL_PHYS_RX_NO_PREF = (1 << 1), +}; + +/// Specify what PHY the Controller has changed for TX/RX. HCI:7.7.65.12 +/*@TRACE*/ +enum le_phy_value +{ + PHY_UNDEF_VALUE = 0, + PHY_1MBPS_VALUE = 1, + PHY_2MBPS_VALUE = 2, + PHY_CODED_VALUE = 3, +}; + +/// Specify what PHY Host prefers to use for RX or TX HCI:7.8.48 / HCI:7.8.49 +enum le_phy_mask +{ + /// The Host prefers to use the LE 1M transmitter/receiver PHY (possibly among others) + PHY_1MBPS_BIT = (1<<0), + PHY_1MBPS_POS = (0), + /// The Host prefers to use the LE 2M transmitter/receiver PHY (possibly among others) + PHY_2MBPS_BIT = (1<<1), + PHY_2MBPS_POS = (1), + /// The Host prefers to use the LE Coded transmitter/receiver PHY (possibly among others) + PHY_CODED_BIT = (1<<2), + PHY_CODED_POS = (2), + /// The Host prefers to use the LE Coded transmitter/receiver PHY (possibly among others) + PHY_ALL = (PHY_1MBPS_BIT | PHY_2MBPS_BIT | PHY_CODED_BIT), +}; + +/// Specify what rate Host prefers to use in transmission on coded PHY. HCI:7.8.49 +enum le_phy_opt +{ + /// The Host has no preferred coding when transmitting on the LE Coded PHY + PHY_OPT_NO_LE_CODED_TX_PREF, + /// The Host prefers that S=2 coding be used when transmitting on the LE Coded PHY + PHY_OPT_S2_LE_CODED_TX_PREF, + /// The Host prefers that S=8 coding be used when transmitting on the LE Coded PHY + PHY_OPT_S8_LE_CODED_TX_PREF, +}; + + +enum le_phy_mode +{ + PHYS_MOD_STANDARD , + PHYS_MOD_STABLE , + PHYS_MOD_MAX, +}; + +///Transmit Power level types +enum +{ + ///Current Power Level + TX_PW_LVL_CURRENT = 0x00, + ///Maximum power level + TX_PW_LVL_MAX, +}; + +///Controller to Host flow control +enum +{ + /// C-> H flow control off + FLOW_CTRL_OFF = 0x00, + ///C->H ACL flow control on only + FLOW_CTRL_ON_ACL_OFF_SYNC, + ///C->H Sync flow control on only + FLOW_CTRL_OFF_ACL_ON_SYNC, + ///C->H ACL and Sync flow control on + FLOW_CTRL_ON_ACL_ON_SYNC, +}; + +///LE Supported Host enable +enum +{ + ///Disable LE supported Host + LE_SUPP_HOST_DIS = 0x00, + ///Enable LE Supported Host + LE_SUPP_HOST_EN, +}; + +///Simultaneous LE Host enable +enum +{ + ///Disable LE simultaneous Host disable + SIMULT_LE_HOST_DIS = 0x00, + ///Enable LE simultaneous Host disable + SIMULT_LE_HOST_EN, +}; + +///Advertising HCI Type +enum +{ + ///Connectable Undirected advertising + ADV_CONN_UNDIR = 0x00, + ///Connectable high duty cycle directed advertising + ADV_CONN_DIR, + ///Discoverable undirected advertising + ADV_DISC_UNDIR, + ///Non-connectable undirected advertising + ADV_NONCONN_UNDIR, + ///Connectable low duty cycle directed advertising + ADV_CONN_DIR_LDC, +}; + +///Advertising event properties values for legacy PDUs +enum +{ + ///Connectable and scannable undirected + ADV_IND = 0x13, + ///Connectable directed (low duty cycle) + ADV_DIRECT_LO_IND = 0x15, + ///Connectable directed (high duty cycle) + ADV_DIRECT_HI_IND = 0x1D, + ///Connectable directed (received) + ADV_DIRECT_IND = 0x15, + ///Scannable undirected + ADV_SCAN_IND = 0x12, + ///Non-connectable and non-scannable undirected + ADV_NONCONN_IND = 0x10, + ///Scan response to an ADV_IND + SCAN_RSP_TO_ADV_IND = 0x1B, + ///Scan response to an ADV_SCAN_IND + SCAN_RSP_TO_ADV_SCAN_IND = 0x1A, +}; + +///Advertising event properties masks +enum +{ + ///Connectable advertising + ADV_CON = 0x01, + ///Scannable advertising + ADV_SCAN = 0x02, + ///Directed advertising + ADV_DIRECT = 0x04, + ///High duty cycle directed connectable advertising + ADV_DIRECT_HI = 0x08, + ///Use legacy advertising PDUs + ADV_LEGACY = 0x10, + ///Omit advertiser's address from all PDUs ("anonymous advertising") + ADV_ANONYMOUS = 0x20, + ///Include TxPower in the extended header of the advertising PDU + ADV_TX_PWR = 0x40, +}; + +///Scanning HCI Type +enum +{ + ///Scan request + SCAN_REQ, + ///Scan response + SCAN_RSP, +}; + +///BD address type +enum addr_type +{ + ///Public BD address + ADDR_PUBLIC = 0x00, + ///Random BD Address + ADDR_RAND, + /// Controller generates Resolvable Private Address based on the + /// local IRK from resolving list. If resolving list contains no matching + /// entry, use public address. + ADDR_RPA_OR_PUBLIC, + /// Controller generates Resolvable Private Address based on the + /// local IRK from resolving list. If resolving list contains no matching + /// entry, use random address. + ADDR_RPA_OR_RAND, + /// mask used to determine Address type in the air + ADDR_MASK = 0x01, + /// mask used to determine if an address is an RPA + ADDR_RPA_MASK = 0x02, + /// Random device address (controller unable to resolve) + ADDR_RAND_UNRESOLVED = 0xFE, + /// No address provided (anonymous advertisement) + ADDR_NONE = 0xFF, +}; + +///Privacy mode type +enum +{ + ///Network privacy mode + PRIV_TYPE_NETWORK = 0x00, + ///Device privacy mode + PRIV_TYPE_DEVICE = 0x01, +}; + +/// Random Address type (2 MSB of the LE BD Address) +enum rnd_addr_type +{ + /// Static random address - 11 (MSB->LSB) + RND_STATIC_ADDR = 0xC0, + /// Private non resolvable address - 00 (MSB->LSB) + RND_NON_RSLV_ADDR = 0x00, + /// Private resolvable address - 01 (MSB->LSB) + RND_RSLV_ADDR = 0x40, +}; + +///Advertising channels enables +enum adv_channel_map +{ + ///Byte value for advertising channel map for channel 37 enable + ADV_CHNL_37_EN = 0x01, + ///Byte value for advertising channel map for channel 38 enable + ADV_CHNL_38_EN = 0x02, + ///Byte value for advertising channel map for channel 39 enable + ADV_CHNL_39_EN = 0x04, + ///Byte value for advertising channel map for channel 37, 38 and 39 enable + ADV_ALL_CHNLS_EN = 0x07, +}; + +///Advertising filter policy +enum adv_filter_policy +{ + ///Allow both scan and connection requests from anyone + ADV_ALLOW_SCAN_ANY_CON_ANY = 0x00, + ///Allow both scan req from White List devices only and connection req from anyone + ADV_ALLOW_SCAN_WLST_CON_ANY, + ///Allow both scan req from anyone and connection req from White List devices only + ADV_ALLOW_SCAN_ANY_CON_WLST, + ///Allow scan and connection requests from White List devices only + ADV_ALLOW_SCAN_WLST_CON_WLST, + ADV_ALLOW_SCAN_END, +}; + +///Advertising enables +enum +{ + ///Disable advertising + ADV_DIS = 0x00, + ///Enable advertising + ADV_EN, +}; + +///LE Scan type +enum +{ + ///Passive scan + SCAN_PASSIVE = 0x00, + ///Active scan + SCAN_ACTIVE, +}; + +///Scan filter policy +enum scan_filter_policy +{ + ///Allow advertising packets from anyone + SCAN_ALLOW_ADV_ALL = 0x00, + ///Allow advertising packets from White List devices only + SCAN_ALLOW_ADV_WLST, + ///Allow advertising packets from anyone and Direct adv using RPA in InitA + SCAN_ALLOW_ADV_ALL_AND_INIT_RPA, + ///Allow advertising packets from White List devices only and Direct adv using RPA in InitA + SCAN_ALLOW_ADV_WLST_AND_INIT_RPA, +}; + +///Le Scan enables +enum +{ + ///Disable scan + SCAN_DIS = 0x00, + ///Enable scan + SCAN_EN, +}; + +///Filter duplicates +enum scan_dup_filter_policy +{ + ///Disable filtering of duplicate packets + SCAN_FILT_DUPLIC_DIS = 0x00, + ///Enable filtering of duplicate packets + SCAN_FILT_DUPLIC_EN, + ///Enable filtering of duplicate packets per scan period + SCAN_FILT_DUPLIC_EN_PER_PERIOD, +}; + +///Initiator Filter policy +enum +{ + ///Initiator will ignore White List + INIT_FILT_IGNORE_WLST = 0x00, + ///Initiator will use White List + INIT_FILT_USE_WLST, +}; + +///Periodic Synchronization Filter policy +enum +{ + ///Use the Advertising SID, Advertising Address Type and Advertising Address parameters to determine + ///which advertiser to listen to + PER_SYNC_FILT_IGNORE_PAL = 0x00, + ///Use the Periodic Advertiser List to determine which advertiser to listen to + PER_SYNC_FILT_USE_PAL, +}; + +/// Periodic Synchronization Options +enum per_sync_opt +{ + /** + * Use the Periodic Advertiser List to determine which advertiser to listen to, otherwise use the Advertising SID, + * Advertising Address Type and Advertising Address parameters + */ + PER_SYNC_FILT_USE_PAL_POS = 0, + PER_SYNC_FILT_USE_PAL_BIT = 0x01, + /// Periodic advertising reports initially enabled or disabled (default enabled) + PER_SYNC_REP_INIT_DIS_POS = 1, + PER_SYNC_REP_INIT_DIS_BIT = 0x02, +}; + +///Transmitter test Packet Payload Type +enum +{ + ///Pseudo-random 9 TX test payload type + PAYL_PSEUDO_RAND_9 = 0x00, + ///11110000 TX test payload type + PAYL_11110000, + ///10101010 TX test payload type + PAYL_10101010, + ///Pseudo-random 15 TX test payload type + PAYL_PSEUDO_RAND_15, + ///All 1s TX test payload type + PAYL_ALL_1, + ///All 0s TX test payload type + PAYL_ALL_0, + ///00001111 TX test payload type + PAYL_00001111, + ///01010101 TX test payload type + PAYL_01010101, +}; + +/// Constant defining the role +enum +{ + ///Master role + ROLE_MASTER, + ///Slave role + ROLE_SLAVE, +}; + +/// Constant clock accuracy +enum SCA +{ + ///Clock accuracy at 500PPM + SCA_500PPM, + ///Clock accuracy at 250PPM + SCA_250PPM, + ///Clock accuracy at 150PPM + SCA_150PPM, + ///Clock accuracy at 100PPM + SCA_100PPM, + ///Clock accuracy at 75PPM + SCA_75PPM, + ///Clock accuracy at 50PPM + SCA_50PPM, + ///Clock accuracy at 30PPM + SCA_30PPM, + ///Clock accuracy at 20PPM + SCA_20PPM +}; + +///Advertising pdu Type +/*@TRACE*/ +enum ble_adv_type +{ + /// Undirected advertising + BLE_ADV_IND = 0x00, + /// Directed advertising + BLE_ADV_DIRECT_IND = 0x01, + /// Non Connectable advertising + BLE_ADV_NONCONN_IND = 0x02, + /// Scan Request on primary channel + BLE_SCAN_REQ = 0x03, + /// Scan Response on secondary channel + BLE_AUX_SCAN_REQ = 0x03, + + /// Scan Response + BLE_SCAN_RSP = 0x04, + /// Connect Request on primary channel + BLE_CONNECT_IND = 0x05, + /// Connect Request on secondary channel + BLE_AUX_CONNECT_REQ = 0x05, + + /// Discoverable advertising + BLE_ADV_SCAN_IND = 0x06, + + /// Extended Advertising indication on primary channel + BLE_ADV_EXT_IND = 0x07, + + /// ADV data indication on secondary channel + BLE_AUX_ADV_IND = 0x07, + /// Scan response data on secondary channel + BLE_AUX_SCAN_RSP = 0x07, + /// Periodic Advertising packet on secondary channel + BLE_AUX_SYNC_IND = 0x07, + /// Continuation of advertising data on secondary channel + BLE_AUX_CHAIN_IND = 0x07, + /// Response of the AUX_CONNECT_REQ on secondary channel to confirm that connection is accepted + BLE_AUX_CONNECT_RSP = 0x08, + + /// Reserved + BLE_RESERVED_PDU_TYPE, +}; + + +/// LE Advertising Report Event Type HCI:7.7.65.2 +enum +{ + /// Connectable undirected advertising + ADV_IND_EVT = 0x00, + /// Connectable directed advertising + ADV_DIRECT_IND_EVT, + /// Scannable undirected advertising + ADV_SCAN_IND_EVT, + /// Non connectable undirected advertising + ADV_NONCONN_IND_EVT, + /// Scan Response + SCAN_RSP_EVT, + /// Reserved + RESERVED_ADV_EVT_TYPES, +}; + +/// LE Extended Advertising Report Event Type Bit Mask HCI:7.7.65.13 + +/// Connectable advertising event +#define CON_ADV_EVT_MSK 0x01 +/// Scannable advertising event +#define SCAN_ADV_EVT_MSK 0x02 +/// Directed advertising event +#define DIR_ADV_EVT_MSK 0x04 +/// Scan Response +#define SCAN_RSP_EVT_MSK 0x08 +/// Legacy advertising PDUs +#define LGCY_ADV_EVT_MSK 0x10 + +/// Connectable undirected advertising +#define LGCY_ADV_IND_EVT 0x13 //LGCY_ADV_EVT_MSK|SCAN_ADV_EVT_MSK|CON_ADV_EVT_MSK +/// Connectable directed advertising +#define LGCY_ADV_DIRECT_IND_EVT 0x15 //LGCY_ADV_EVT_MSK|DIR_ADV_EVT_MSK|CON_ADV_EVT_MSK +/// Scannable undirected advertising +#define LGCY_ADV_SCAN_IND_EVT 0x12 //LGCY_ADV_EVT_MSK|SCAN_ADV_EVT_MSK +/// Non connectable undirected advertising +#define LGCY_ADV_NONCONN_IND_EVT 0x10 //LGCY_ADV_EVT_MSK +/// Scan Response to ADV_IND +#define LGCY_SCAN_RSP_TO_ADV_IND_EVT 0x1B //LGCY_ADV_EVT_MSK|SCAN_RSP_EVT_MSK|SCAN_ADV_EVT_MSK|CON_ADV_EVT_MSK +/// Scan Response to ADV_SCAN_IND +#define LGCY_SCAN_RSP_TO_ADV_SCAN_IND_EVT 0x1A //LGCY_ADV_EVT_MSK|SCAN_RSP_EVT_MSK|SCAN_ADV_EVT_MSK + +/// Offset of data status field in event type value +#define ADV_EVT_DATA_STATUS_LSB 5 +/// Mask for data status field in event type value +#define ADV_EVT_DATA_STATUS_MASK 0x0060 +/// Data status of extended advertising event - Complete +#define ADV_EVT_DATA_STATUS_COMPLETE 0 +/// Data status of extended advertising event - Incomplete, more data to come +#define ADV_EVT_DATA_STATUS_INCOMPLETE 1 +/// Data status of extended advertising event - Incomplete, data truncated, no more to come +#define ADV_EVT_DATA_STATUS_TRUNCATED 2 +/// Data status of extended advertising event - Reserved for future use +#define ADV_EVT_DATA_STATUS_RESERVED 3 + +/// Data status of periodic advertising event - Complete +#define PER_ADV_EVT_DATA_STATUS_COMPLETE 0 +/// Data status of periodic advertising event - Incomplete, more data to come +#define PER_ADV_EVT_DATA_STATUS_INCOMPLETE 1 +/// Data status of periodic advertising event - Incomplete, data truncated, no more to come +#define PER_ADV_EVT_DATA_STATUS_TRUNCATED 2 + +/// LLID packet +enum +{ + /// Reserved for future use + LLID_ISO, + /// Continue + LLID_CONTINUE, + /// Start + LLID_START, + /// Control + LLID_CNTL +}; + +/// Remote OOB Data present parameter value HCI:7.1.29 +enum +{ + REM_OOB_DATA_NO = 0x00, + REM_OOB_DATA_P192 = 0x01, + REM_OOB_DATA_P256 = 0x02, + REM_OOB_DATA_P192_P256 = 0x03, +}; + +/// Encryption enabled parameter in HCI_Enc_Chg_Evt HCI:7.7.8 +enum +{ + ENC_OFF = 0x00, + ENC_BRDER_E0_LE_AESCCM = 0x01, + ENC_BREDR_AESCC = 0x02, +}; + +/// Combined duration of Preamble and Access Address depending on the PHY used (in us) +#define BLE_PREAMBLE_ACCESS_ADDR_DUR_1MBPS (5*8) +#define BLE_PREAMBLE_ACCESS_ADDR_DUR_2MBPS (6*4) +#define BLE_PREAMBLE_ACCESS_ADDR_DUR_125KBPS (80+256) +#define BLE_PREAMBLE_ACCESS_ADDR_DUR_500KBPS (80+256) + + + +/// size of the Maximum Adv Extended header length +#define BLE_EXT_MAX_HEADER_LEN (63) + +/// size of the LEN & MODE info preceeding the extended header +#define BLE_EXT_ADV_PRE_HEADER_LEN (1) +/// size of the FLAGS info at start of the extended header +#define BLE_EXT_ADV_HEADER_FLAGS_LEN (1) +/// size of the extended header in bytes (pre-header + flags) +#define BLE_EXT_ADV_HEADER_LEN (2) +/// Size of CTE info in extended header +#define BLE_EXT_CTE_INFO_LEN (1) +/// Size of ADV Data Info in extended header +#define BLE_EXT_ADI_LEN (2) +/// Size of Aux Pointer info in extended header +#define BLE_EXT_AUX_PTR_LEN (3) +/// Size of Sync PTR info in extended header +#define BLE_EXT_SYNC_LEN (18) +/// Size of TX Power info in extended header +#define BLE_EXT_TX_PWR_LEN (1) +/// Size of ACAD Data for ICL stream info - Not Encrypted +#define BLE_EXT_ACAD_ICL_STREAM_INFO_LEN (28) +/// Size of ACAD Data for ICL stream info - Encrypted +/// AD Type reserved for Stream info ACAD data +/// TODO [FBE] put 0x29 for the moment +#define BLE_EXT_ACAD_ICL_STREAM_INFO_AD_TYPE (0x29) +#define BLE_EXT_ACAD_ICL_STREAM_INFO_ENC_LEN (57) +/// Size of the Channel Map Update Indication in extended header +#define BLE_EXT_CHM_UPD_IND_LEN (9) +/// AD Types for ACAD data +#define BLE_EXT_ACAD_CHANNEL_MAP_UPDATE_INDICATION_AD_TYPE (0x28) + +/// Extended Header Flags +enum ble_ext_header_flags +{ + // AdvA + ADVA_BIT = 0x01, + ADVA_POS = 0, + // TargetA + TARGETA_BIT = 0x02, + TARGETA_POS = 1, + // SuppInfo + SUPPINFO_BIT = 0x04, + SUPPINFO_POS = 2, + // AdvDataInfo (ADI) + ADI_BIT = 0x08, + ADI_POS = 3, + // AuxPtr + AUXPTR_BIT = 0x10, + AUXPTR_POS = 4, + // SyncInfo + SYNCINFO_BIT = 0x20, + SYNCINFO_POS = 5, + // TxPower + TXPOWER_BIT = 0x40, + TXPOWER_POS = 6, +}; + +/// AUX pointer description +enum ble_aux_ptr +{ + // Aux LL Channel + BLE_AUX_LL_CHANNEL_MASK = 0x0000003F, + BLE_AUX_LL_CHANNEL_LSB = 0, + // Aux Clock Accuracy + BLE_AUX_CA_BIT = 0x00000040, + BLE_AUX_CA_POS = 6, + // Aux Offset Unit + BLE_AUX_OFFSET_UNIT_BIT = 0x00000080, + BLE_AUX_OFFSET_UNIT_POS = 7, + // Aux ADV offset + BLE_AUX_OFFSET_MASK = 0x001FFF00, + BLE_AUX_OFFSET_LSB = 8, + // Aux PHY + BLE_AUX_PHY_MASK = 0x00E00000, + BLE_AUX_PHY_LSB = 21, +}; + +/// CTEInfo field description +enum ble_cte_info +{ + // CTETime (5 bits) + BLE_CTE_INFO_CTE_TIME_MASK = 0x0000001F, + BLE_CTE_INFO_CTE_TIME_LSB = 0, + // RFU (1 bit) + BLE_CTE_INFO_RFU_BIT = 0x00000020, + BLE_CTE_INFO_RFU_POS = 5, + // CTEType (2 bits) + BLE_CTE_INFO_CTE_TYPE_MASK = 0x000000C0, + BLE_CTE_INFO_CTE_TYPE_LSB = 6, +}; + +/// Aux PHY values LL:2.3.4.5 +enum aux_phy +{ + AUX_PHY_1MBPS = 0, + AUX_PHY_2MBPS = 1, + AUX_PHY_CODED = 2, +}; + +/// SyncInfo - various fileds description +enum syncinfo_fields +{ + /// SyncInfo - Sync Offset description (13 bits) + BLE_SYNC_OFFSET_MASK = 0x1FFF, + BLE_SYNC_OFFSET_LSB = 0, + + /// SyncInfo - Offset Units description (1 bit) + BLE_SYNC_OFFSET_UNITS_BIT = 0x2000, + BLE_SYNC_OFFSET_UNITS_POS = 13, + + /// SyncInfo - Offset Adjust description (1 bit) + BLE_SYNC_OFFSET_ADJUST_BIT = 0x4000, + BLE_SYNC_OFFSET_ADJUST_POS = 14, + + /// SyncInfo[8] - ChM description (5 bits of 37 bits) + BLE_SYNC_CHMAP_END_MASK = 0x1F, + BLE_SYNC_CHMAP_END_LSB = 0, + + /// SyncInfo[8] - SCA description (3 bits) + BLE_SYNC_SCA_MASK = 0xE0, + BLE_SYNC_SCA_LSB = 5, +}; + +/// AdvDataInfo (ADI) field description +enum ble_adi +{ + // Advertising Data ID (DID) + BLE_ADI_DID_MASK = 0x0FFF, + BLE_ADI_DID_LSB = 0, + // Advertising Set ID (SID) + BLE_ADI_SID_MASK = 0xF000, + BLE_ADI_SID_LSB = 12, +}; + +/// Advertising mode +enum ble_adv_mode +{ + /// Non connectable and non scannable mode + BLE_MODE_NON_CON_SCAN = 0, + /// Connectable Mode (accept connection request) + BLE_MODE_CONNECTABLE = 1, + /// Scannable Mode (accept scan request) + BLE_MODE_SCANNABLE = 2, + /// Reserved Advertising mode + BLE_MODE_RESERVED = 3, +}; + +/// Advertising data operation +enum adv_data_op +{ + /// Intermediate fragment of fragmented extended advertising data + ADV_DATA_OP_INTERMEDIATE_FRAG = 0, + /// First fragment of fragmented extended advertising data + ADV_DATA_OP_FIRST_FRAG = 1, + /// Last fragment of fragmented extended advertising data + ADV_DATA_OP_LAST_FRAG = 2, + /// Complete extended advertising data + ADV_DATA_OP_COMPLETE = 3, + /// Unchanged data (just update the Advertising DID) + ADV_DATA_OP_UNCHANGED_DATA = 4, +}; + +/// Advertising data fragment preference +enum adv_data_frag_pref +{ + /// The Controller may fragment all Host advertising data + ADV_DATA_MAY_FRAG = 0, + /// The Controller should not fragment nor minimize fragmentation of Host advertising data + ADV_DATA_SHOULD_NOT_FRAG = 1, +}; + +/* + * STRUCTURE DEFINITONS + **************************************************************************************** + */ + +///BD name structure +struct bd_name +{ + ///length for name + uint8_t namelen; + ///array of bytes for name + uint8_t name[BD_NAME_SIZE]; +}; + +///Structure device name +/*@TRACE*/ +struct device_name +{ + ///array of bytes for name + uint8_t name[BD_NAME_SIZE]; +}; + +///Structure name vector +/*@TRACE*/ +struct name_vect +{ + uint8_t vect[NAME_VECT_SIZE]; +}; + +/// lap structure +/*@TRACE*/ +struct lap +{ + /// LAP + uint8_t A[BD_ADDR_LAP_LEN]; +}; + +/// class structure +/*@TRACE*/ +struct devclass +{ + /// class + uint8_t A[DEV_CLASS_LEN]; +}; + +///Extended inquiry response structure +/*@TRACE*/ +struct eir +{ + /// eir data + uint8_t data[EIR_DATA_SIZE]; +}; + +///Event mask structure +/*@TRACE*/ +struct evt_mask +{ + ///8-byte array for mask value + uint8_t mask[EVT_MASK_LEN]; +}; + +///Host number of completed packets structure, for 1 connection handle +struct host_cmpl_pkts +{ + ///Connection handle + uint16_t con_hdl; + ///Number of completed packets + uint16_t nb_cmpl_pkts; +}; + +///BD Address structure +/*@TRACE*/ +struct bd_addr +{ + ///6-byte array address value + uint8_t addr[BD_ADDR_LEN]; +}; + + + +///Access Address structure +/*@TRACE*/ +struct access_addr +{ + ///4-byte array access address + uint8_t addr[ACCESS_ADDR_LEN]; +}; + +///Advertising data structure +/*@TRACE*/ +struct adv_data +{ + ///Maximum length data bytes array + uint8_t data[ADV_DATA_LEN]; +}; + +///Scan response data structure +/*@TRACE*/ +struct scan_rsp_data +{ + ///Maximum length data bytes array + uint8_t data[SCAN_RSP_DATA_LEN]; +}; + +///Channel map structure +/*@TRACE*/ +struct chnl_map +{ + ///10-bytes channel map array + uint8_t map[CHNL_MAP_LEN]; +}; + +///Channel map structure +/*@TRACE*/ +struct le_chnl_map +{ + ///5-byte channel map array + uint8_t map[LE_CHNL_MAP_LEN]; +}; + +/// External frame period (duration & type) structure +struct ext_fr_period +{ + /// Period_Duration + uint16_t duration; + /// Period_Type + uint8_t type; +}; + +/// MWS scan frequency (low & high) structure +struct mws_scan_freq +{ + ///Scan_Frequency_Low + uint16_t low; + ///Scan_Frequency_High + uint16_t high; +}; + +/// MWS pattern interval (duration & type) structure +struct mws_pattern_intv +{ + ///MWS_PATTERN_IntervalDuration + uint16_t duration; + ///MWS_PATTERN_IntervalType + uint8_t type; +}; + + +/// MWS transport rates structure +struct mws_trans_rate +{ + ///To_MWS_Baud_Rate + uint32_t to_mws_baud_rate; + ///From_MWS_Baud_Rate + uint32_t from_mws_baud_rate; +}; + +/// MWS transports strucutre +struct mws_transport +{ + ///Transport_Layer + uint8_t layer_id; + ///Num_Baud_Rates + uint8_t num_baud_rates; + ///To/From_MWS_Baud_Rates + struct mws_trans_rate *rates; +}; + + +/// SAM submaps structure +struct sam_submaps +{ + //12-byte SAM submaps array of 2-bit fields + //The nth (numbering from 0) such field defines the submap type of the nth submap in the map: + // - SAM_SLOTS_SUBMAPPED: Each slot is individually available or unavailable as configured. + // - SAM_SLOTS_AVAILABLE: All slots are available for transmission and reception. + // - SAM_SLOTS_UNAVAILABLE: All slots are unavailable for transmission and reception. + // - Other: Reserved for future use. + uint8_t map[SAM_SUBMAPS_LEN]; +}; + +/// SAM type0 submap structure +struct sam_type0_submap +{ + //14-byte type0 submap array of 2-bit fields + //The nth (numbering from 0) such field defines the submap type of the nth submap in the map: + // - SAM_SLOT_NOT_AVAILABLE: The slot is not available for transmision or reception. + // - SAM_SLOT_TX_AVAILABLE: The slot is available for transmission but not reception. + // - SAM_SLOT_RX_AVAILABLE: The slot is available for reception but not transmission. + // - SAM_SLOT_TX_RX_AVAILABLE: The slot is available for both transmission and reception. + uint8_t map[SAM_TYPE0_SUBMAP_LEN]; +}; + +///Long Term Key structure +/*@TRACE*/ +struct ltk +{ + ///16-byte array for LTK value + uint8_t ltk[KEY_LEN]; +}; + +///Identity Resolving Key structure +/*@TRACE*/ +struct irk +{ + ///16-byte array for IRK value + uint8_t key[KEY_LEN]; +}; + +/// Initialization vector (for AES-CCM encryption) +/*@TRACE*/ +struct initialization_vector +{ + ///8-byte array + uint8_t vect[IV_LEN]; +}; + +/// Bluetooth address with link key +struct bd_addr_plus_key +{ + /// BD Address + struct bd_addr bd_addr; + /// Link Key + struct ltk link_key; +}; + +///Random number structure +/*@TRACE*/ +struct rand_nb +{ + ///8-byte array for random number + uint8_t nb[RAND_NB_LEN]; +}; + +///Advertising report structure +/*@TRACE*/ +struct adv_report +{ + ///Event type: + /// - ADV_CONN_UNDIR: Connectable Undirected advertising + /// - ADV_CONN_DIR: Connectable directed advertising + /// - ADV_DISC_UNDIR: Discoverable undirected advertising + /// - ADV_NONCONN_UNDIR: Non-connectable undirected advertising + uint8_t evt_type; + ///Advertising address type: public/random + uint8_t adv_addr_type; + ///Advertising address value + struct bd_addr adv_addr; + ///Data length in advertising packet + uint8_t data_len; + ///Data of advertising packet + uint8_t data[ADV_DATA_LEN]; + ///RSSI value for advertising packet (in dBm, between -127 and +20 dBm) + int8_t rssi; +}; + +///Direct Advertising report structure +/*@TRACE*/ +struct dir_adv_report +{ + ///Event type: + /// - ADV_CONN_DIR: Connectable directed advertising + uint8_t evt_type; + ///Address type: public/random + uint8_t addr_type; + ///Address value + struct bd_addr addr; + ///Direct address type: public/random + uint8_t dir_addr_type; + ///Direct address value + struct bd_addr dir_addr; + ///RSSI value for advertising packet (in dBm, between -127 and +20 dBm) + int8_t rssi; +}; + +///Exteneded Advertising report structure +/*@TRACE*/ +struct ext_adv_report +{ + ///Event type + uint16_t evt_type; + ///Advertising address type: public/random + uint8_t adv_addr_type; + ///Advertising address value + struct bd_addr adv_addr; + ///Primary PHY + uint8_t phy; + ///Secondary PHY + uint8_t phy2; + ///Advertising SID + uint8_t adv_sid; + ///Tx Power + uint8_t tx_power; + ///RSSI value for advertising packet (in dBm, between -127 and +20 dBm) + int8_t rssi; + ///Periodic Advertising interval (Time=N*1.25ms) + uint16_t interval; + ///Direct address type + uint8_t dir_addr_type; + ///Direct address value + struct bd_addr dir_addr; + ///Data length in advertising packet + uint8_t data_len; + ///Data of advertising packet + uint8_t data[EXT_ADV_DATA_MAX_LEN]; +}; + +///Supported LE Features structure +/*@TRACE*/ +struct le_features +{ + ///8-byte array for LE features + uint8_t feats[LE_FEATS_LEN]; +}; + +///Simple pairing hash structure +/*@TRACE*/ +struct hash +{ + ///16-byte array for LTK value + uint8_t C[KEY_LEN]; +}; + +///Simple pairing randomizer structure +/*@TRACE*/ +struct randomizer +{ + ///16-byte array for LTK value + uint8_t R[KEY_LEN]; +}; + +///Pin code structure +/*@TRACE*/ +struct pin_code +{ + ///16-byte array for PIN value + uint8_t pin[PIN_CODE_MAX_LEN]; +}; + +///Sres structure +/*@TRACE*/ +struct sres_nb +{ + ///8-byte array for random number + uint8_t nb[SRES_LEN]; +}; + +///aco structure +/*@TRACE*/ +struct aco +{ + ///8-byte array for random number + uint8_t a[ACO_LEN]; +}; + +///struct byte 16 to stay align with the sdl version +/*@TRACE*/ +struct byte16 +{ + uint8_t A[16]; +}; + +///Controller number of completed packets structure +/*@TRACE*/ +struct nb_cmpl_pk +{ + ///Connection handle + uint16_t con_hdl; + ///Controller number of data packets that have been completed since last time + uint16_t nb_hc_cmpl_pkts; +}; + +///Supported Features structure +/*@TRACE*/ +struct features +{ + ///8-byte array for features + uint8_t feats[FEATS_LEN]; +}; + +///Supported commands structure +/*@TRACE*/ +struct supp_cmds +{ + ///64-byte array for supported commands + uint8_t cmds[SUPP_CMDS_LEN]; +}; + +///Supported LMP features structure +struct lmp_features +{ + ///8-byte array for LMp features + uint8_t feats[FEATS_LEN]; +}; + +///Simple pairing IO capabilities +struct io_capability +{ + ///IO capability + uint8_t io_cap; + /// Out Of Band Data present + bool oob_data_present; + ///Authentication Requirement + uint8_t aut_req; +}; + +///Public key +struct pub_key_192 +{ + uint8_t p_key[PUB_KEY_192_LEN/2]; +}; + +///Public key +struct pub_key_256 +{ + uint8_t p_key[PUB_KEY_256_LEN/2]; +}; + +///Simple pairing public keys 192 +struct sp_pub_key_192 +{ + ///Public key X + struct pub_key_192 X; + ///Public key Y + struct pub_key_192 Y; +}; + +///Simple pairing public keys 256 +struct sp_pub_key_256 +{ + ///Public key X + struct pub_key_256 X; + ///Public key Y + struct pub_key_256 Y; +}; + +///Supported LE states structure +/*@TRACE*/ +struct le_states +{ + ///8-byte array for LE states + uint8_t supp_states[LE_STATES_LEN]; +}; + +///White List element structure +struct white_list +{ + ///BD address of device entry + struct bd_addr wl_bdaddr; + ///BD address type of device entry + uint8_t wl_bdaddr_type; +}; + +///RAL element structure +struct ral_entry +{ + /// Peer ID address + struct bd_addr bd_addr; + /// Peer address type + uint8_t addr_type; + /// Local IRK + struct irk local_irk; + /// Peer IRK + struct irk peer_irk; +}; + +///CRC initial value structure +/*@TRACE*/ +struct crc_init +{ + ///3-byte array CRC initial value + uint8_t crc[CRC_INIT_LEN]; +}; + +///Session key diversifier master or slave structure +/*@TRACE*/ +struct sess_k_div_x +{ + ///8-byte array for diversifier value + uint8_t skdiv[SESS_KEY_DIV_LEN]; +}; + +///Session key diversifier structure +struct sess_k_div +{ + ///16-byte array for session key diversifier. + uint8_t skd[2*SESS_KEY_DIV_LEN]; +}; + +///Initiator vector +/*@TRACE*/ +struct init_vect +{ + ///4-byte array for vector + uint8_t iv[INIT_VECT_LEN]; +}; + +/*@TRACE*/ +typedef struct t_public_key +{ + uint8_t x[PUBLIC_KEY_P256_LEN]; + uint8_t y[PUBLIC_KEY_P256_LEN]; + +} t_public_key; + +/// structure connection request LLData +struct pdu_con_req_lldata +{ + /// Access address + struct access_addr aa; + + /// CRC init + struct crc_init crcinit; + + /// Window size (in units of 1,25 ms, i.e. 2 slots) + uint8_t winsize; + + /// Window offset (in units of 1,25 ms, i.e. 2 slots) + uint16_t winoffset; + + /// Interval (in units of 1,25 ms, i.e. 2 slots) + uint16_t interval; + + /// Latency + uint16_t latency; + + /// Timeout (in units of 10 ms, i.e. 16 slots) + uint16_t timeout; + + /// Channel mapping + struct le_chnl_map chm; + + /// Hopping + uint8_t hop_sca; +}; + +/// structure connection request +struct pdu_con_req +{ + /// Initiator address + struct bd_addr inita; + + /// Advertiser address + struct bd_addr adva; + + /// LLData + struct pdu_con_req_lldata lldata; +}; + +/// structure advertising syncinfo field +/*@TRACE*/ +struct sync_info +{ + /// Sync offset (in offset units) + uint16_t sync_offset; + + /// Offset units (0: 30us, 1: 300us) + uint8_t offset_units; + + /// Offset adjust (0: no action, 1: add 2.4576 seconds) + uint8_t offset_adjust; + + /// Interval (in units of 1,25 ms, i.e. 2 slots) + uint16_t interval; + + /// Channel mapping + struct le_chnl_map ch_map; + + /// Clock accuracy (@see enum SCA) + uint8_t sca; + + /// Access address + struct access_addr aa; + + /// CRC init + struct crc_init crcinit; + + /// Event counter + uint16_t evt_counter; +}; + +/// @} CO_BT_DEFINES +#endif // CO_BT_DEFINES_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_endian.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_endian.h new file mode 100644 index 0000000..d54cac3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_endian.h @@ -0,0 +1,349 @@ +/** + **************************************************************************************** + * + * @file co_endian.h + * + * @brief Common endianness conversion functions + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _CO_ENDIAN_H_ +#define _CO_ENDIAN_H_ + +#include // standard integer definitions +#include "rwip_config.h" // stack configuration +#include "arch.h" // architectural platform definition + +/** + **************************************************************************************** + * @defgroup CO_ENDIAN Endianness + * @ingroup COMMON + * @brief Endianness conversion functions. + * + * This set of functions converts values between the local system + * and a external one. It is inspired from the htonl-like functions + * from the standard C library. + * + * Example: + * @code + * struct eth_header *header = get_header(); // get pointer on Eth II packet header + * uint16_t eth_id; // will contain the type of the packet + * eth_id = co_ntohs(header->eth_id); // retrieve the type with correct endianness + * @endcode + * + * @{ + * **************************************************************************************** + * */ + + +/** + **************************************************************************************** + * @brief Swap bytes of an array of bytes + * . + * The swap is done in every case. Should not be called directly. + * + * @param[in] p_val_out The output value. + * @param[in] p_val_in The input value. + * + * @param[in] len number of bytes to swap + **************************************************************************************** + */ +__INLINE void co_bswap(uint8_t* p_val_out, const uint8_t* p_val_in, uint16_t len) +{ + while (len > 0) + { + len--; + *p_val_out = p_val_in[len]; + p_val_out++; + } +} +/// @} CO_ENDIAN + +/** + **************************************************************************************** + * @brief Swap bytes of a 32 bits value. + * The swap is done in every case. Should not be called directly. + * @param[in] val32 The 32 bits value to swap. + * @return The 32 bit swapped value. + **************************************************************************************** + */ +__INLINE uint32_t co_bswap32(uint32_t val32) +{ + return (val32<<24) | ((val32<<8)&0xFF0000) | ((val32>>8)&0xFF00) | ((val32>>24)&0xFF); +} + +/** + **************************************************************************************** + * @brief Swap bytes of a 24 bits value. + * The swap is done in every case. Should not be called directly. + * @param[in] val24 The 24 bits value to swap. + * @return The 24 bit swapped value. + **************************************************************************************** + */ +__INLINE uint32_t co_bswap24(uint32_t val24) +{ + return ((val24<<16)&0xFF0000) | ((val24)&0xFF00) | ((val24>>16)&0xFF); +} + +/** + **************************************************************************************** + * @brief Swap bytes of a 16 bits value. + * The swap is done in every case. Should not be called directly. + * @param[in] val16 The 16 bit value to swap. + * @return The 16 bit swapped value. + **************************************************************************************** + */ +__INLINE uint16_t co_bswap16(uint16_t val16) +{ + return ((val16<<8)&0xFF00) | ((val16>>8)&0xFF); +} +/// @} CO_ENDIAN + + + + +/** + * **************************************************************************************** + * @defgroup CO_ENDIAN_NET Endianness (Network) + * @ingroup CO_ENDIAN + * @brief Endianness conversion functions for Network data + * + * Converts values between the local system and big-endian network data + * (e.g. IP, Ethernet, but NOT WLAN). + * + * The \b host term in the descriptions of these functions refers + * to the local system, i.e. \b application or \b embedded system. + * Therefore, these functions will behave differently depending on which + * side they are used. The reason of this terminology is to keep the + * same name than the standard C function. + * + * Behavior will depends on the endianness of the host: + * - little endian: swap bytes; + * - big endian: identity function. + * + * @{ + * **************************************************************************************** + * */ + +/** + **************************************************************************************** + * @brief Convert host to network long word. + * + * @param[in] hostlong Long word value to convert. + * + * @return The converted long word. + **************************************************************************************** + */ +__INLINE uint32_t co_htonl(uint32_t hostlong) +{ + #if (!CPU_LE) + return hostlong; + #else + return co_bswap32(hostlong); + #endif // CPU_LE +} + +/** + **************************************************************************************** + * @brief Convert host to network long 24-bit value. + * + * @param[in] val24 24-bit value to convert. + * + * @return The converted 24-but value. + **************************************************************************************** + */ +__INLINE uint32_t co_hton24(uint32_t host24) +{ + #if (!CPU_LE) + return host24; + #else + return co_bswap24(host24); + #endif // CPU_LE +} + +/** + **************************************************************************************** + * @brief Convert host to network short word. + * + * @param[in] hostshort Short word value to convert. + * + * @return The converted short word. + **************************************************************************************** + */ +__INLINE uint16_t co_htons(uint16_t hostshort) +{ + #if (!CPU_LE) + return hostshort; + #else + return co_bswap16(hostshort); + #endif // CPU_LE +} + +/** + **************************************************************************************** + * @brief Convert network to host long word. + * + * @param[in] netlong Long word value to convert. + * + * @return The converted long word. + **************************************************************************************** + */ +__INLINE uint32_t co_ntohl(uint32_t netlong) +{ + return co_htonl(netlong); +} + +/** + **************************************************************************************** + * @brief Convert network to host 24-bit value. + * + * @param[in] val24 24-bit to convert. + * + * @return The converted 24-bit value. + **************************************************************************************** + */ +__INLINE uint32_t co_ntoh24(uint32_t val24) +{ + return co_hton24(val24); +} + +/** + **************************************************************************************** + * @brief Convert network to host short word. + * + * @param[in] netshort Short word value to convert. + * + * @return The converted short word. + **************************************************************************************** + */ +__INLINE uint16_t co_ntohs(uint16_t netshort) +{ + return co_htons(netshort); +} +/// @} CO_ENDIAN_NET + +/** + * **************************************************************************************** + * @defgroup CO_ENDIAN_BT Endianness (BT) + * @ingroup CO_ENDIAN + * @brief Endianness conversion functions for Bluetooth data (HCI and protocol) + * + * Converts values between the local system and little-endian Bluetooth data. + * + * The \b host term in the descriptions of these functions refers + * to the local system (check \ref CO_ENDIAN_NET "this comment"). + * + * Behavior will depends on the endianness of the host: + * - little endian: identity function; + * - big endian: swap bytes. + * + * @addtogroup CO_ENDIAN_BT + * @{ + * **************************************************************************************** + * */ + + +/** + **************************************************************************************** + * @brief Convert Bluetooth to host 24-bit value. + * + * @param[in] val24 24-bit to convert. + * + * @return The converted 24-bit value. + **************************************************************************************** + */ +__INLINE uint32_t co_htob24(uint32_t val24) +{ + #if (CPU_LE) + return val24; + #else + return co_hton24(val24); + #endif // CPU_LE +} + +/** + **************************************************************************************** + * @brief Convert host to Bluetooth long word. + * + * @param[in] hostlong Long word value to convert. + * + * @return The converted long word. + **************************************************************************************** + */ +__INLINE uint32_t co_htobl(uint32_t hostlong) +{ + #if (CPU_LE) + return hostlong; + #else + return co_bswap32(hostlong); + #endif // CPU_LE +} + +/** + **************************************************************************************** + * @brief Convert host to Bluetooth short word. + * + * @param[in] hostshort Short word value to convert. + * + * @return The converted short word. + **************************************************************************************** + */ +__INLINE uint16_t co_htobs(uint16_t hostshort) +{ + #if (CPU_LE) + return hostshort; + #else + return co_bswap16(hostshort); + #endif // CPU_LE +} + + +/** + **************************************************************************************** + * @brief Convert Bluetooth to host 24-bit value. + * + * @param[in] val24 24-bit to convert. + * + * @return The converted 24-bit value. + **************************************************************************************** + */ +__INLINE uint32_t co_btoh24(uint32_t val24) +{ + return co_htob24(val24); +} + +/** + **************************************************************************************** + * @brief Convert Bluetooth to host long word. + * + * @param[in] btlong Long word value to convert. + * + * @return The converted long word. + **************************************************************************************** + */ +__INLINE uint32_t co_btohl(uint32_t btlong) +{ + return co_htobl(btlong); +} + + +/** + **************************************************************************************** + * @brief Convert Bluetooth to host short word. + * + * @param[in] btshort Short word value to convert. + * + * @return The converted short word. + **************************************************************************************** + */ +__INLINE uint16_t co_btohs(uint16_t btshort) +{ + return co_htobs(btshort); +} +/// @} CO_ENDIAN + +#endif // _CO_ENDIAN_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_error.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_error.h new file mode 100644 index 0000000..2da3647 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_error.h @@ -0,0 +1,116 @@ +/** + **************************************************************************************** + * + * @file co_error.h + * + * @brief List of codes for error in RW Software. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef CO_ERROR_H_ +#define CO_ERROR_H_ + +/** + **************************************************************************************** + * @addtogroup CO_ERROR Error Codes + * @ingroup COMMON + * @brief Defines error codes in messages. + * + * @{ + **************************************************************************************** + */ + +/* + * DEFINES + **************************************************************************************** + */ +enum co_error +{ +/***************************************************** + *** ERROR CODES *** + *****************************************************/ + + CO_ERROR_NO_ERROR = 0x00, + CO_ERROR_UNKNOWN_HCI_COMMAND = 0x01, + CO_ERROR_UNKNOWN_CONNECTION_ID = 0x02, + CO_ERROR_HARDWARE_FAILURE = 0x03, + CO_ERROR_PAGE_TIMEOUT = 0x04, + CO_ERROR_AUTH_FAILURE = 0x05, + CO_ERROR_PIN_MISSING = 0x06, + CO_ERROR_MEMORY_CAPA_EXCEED = 0x07, + CO_ERROR_CON_TIMEOUT = 0x08, + CO_ERROR_CON_LIMIT_EXCEED = 0x09, + CO_ERROR_SYNC_CON_LIMIT_DEV_EXCEED = 0x0A, + CO_ERROR_CON_ALREADY_EXISTS = 0x0B, + CO_ERROR_COMMAND_DISALLOWED = 0x0C, + CO_ERROR_CONN_REJ_LIMITED_RESOURCES = 0x0D, + CO_ERROR_CONN_REJ_SECURITY_REASONS = 0x0E, + CO_ERROR_CONN_REJ_UNACCEPTABLE_BDADDR = 0x0F, + CO_ERROR_CONN_ACCEPT_TIMEOUT_EXCEED = 0x10, + CO_ERROR_UNSUPPORTED = 0x11, + CO_ERROR_INVALID_HCI_PARAM = 0x12, + CO_ERROR_REMOTE_USER_TERM_CON = 0x13, + CO_ERROR_REMOTE_DEV_TERM_LOW_RESOURCES = 0x14, + CO_ERROR_REMOTE_DEV_POWER_OFF = 0x15, + CO_ERROR_CON_TERM_BY_LOCAL_HOST = 0x16, + CO_ERROR_REPEATED_ATTEMPTS = 0x17, + CO_ERROR_PAIRING_NOT_ALLOWED = 0x18, + CO_ERROR_UNKNOWN_LMP_PDU = 0x19, + CO_ERROR_UNSUPPORTED_REMOTE_FEATURE = 0x1A, + CO_ERROR_SCO_OFFSET_REJECTED = 0x1B, + CO_ERROR_SCO_INTERVAL_REJECTED = 0x1C, + CO_ERROR_SCO_AIR_MODE_REJECTED = 0x1D, + CO_ERROR_INVALID_LMP_PARAM = 0x1E, + CO_ERROR_UNSPECIFIED_ERROR = 0x1F, + CO_ERROR_UNSUPPORTED_LMP_PARAM_VALUE = 0x20, + CO_ERROR_ROLE_CHANGE_NOT_ALLOWED = 0x21, + CO_ERROR_LMP_RSP_TIMEOUT = 0x22, + CO_ERROR_LMP_COLLISION = 0x23, + CO_ERROR_LMP_PDU_NOT_ALLOWED = 0x24, + CO_ERROR_ENC_MODE_NOT_ACCEPT = 0x25, + CO_ERROR_LINK_KEY_CANT_CHANGE = 0x26, + CO_ERROR_QOS_NOT_SUPPORTED = 0x27, + CO_ERROR_INSTANT_PASSED = 0x28, + CO_ERROR_PAIRING_WITH_UNIT_KEY_NOT_SUP = 0x29, + CO_ERROR_DIFF_TRANSACTION_COLLISION = 0x2A, + CO_ERROR_QOS_UNACCEPTABLE_PARAM = 0x2C, + CO_ERROR_QOS_REJECTED = 0x2D, + CO_ERROR_CHANNEL_CLASS_NOT_SUP = 0x2E, + CO_ERROR_INSUFFICIENT_SECURITY = 0x2F, + CO_ERROR_PARAM_OUT_OF_MAND_RANGE = 0x30, + CO_ERROR_ROLE_SWITCH_PEND = 0x32, /* LM_ROLE_SWITCH_PENDING */ + CO_ERROR_RESERVED_SLOT_VIOLATION = 0x34, /* LM_RESERVED_SLOT_VIOLATION */ + CO_ERROR_ROLE_SWITCH_FAIL = 0x35, /* LM_ROLE_SWITCH_FAILED */ + CO_ERROR_EIR_TOO_LARGE = 0x36, /* LM_EXTENDED_INQUIRY_RESPONSE_TOO_LARGE */ + CO_ERROR_SP_NOT_SUPPORTED_HOST = 0x37, + CO_ERROR_HOST_BUSY_PAIRING = 0x38, + CO_ERROR_CONTROLLER_BUSY = 0x3A, + CO_ERROR_UNACCEPTABLE_CONN_PARAM = 0x3B, + CO_ERROR_ADV_TO = 0x3C, + CO_ERROR_TERMINATED_MIC_FAILURE = 0x3D, + CO_ERROR_CONN_FAILED_TO_BE_EST = 0x3E, + CO_ERROR_CCA_REJ_USE_CLOCK_DRAG = 0x40, + CO_ERROR_TYPE0_SUBMAP_NOT_DEFINED = 0x41, + CO_ERROR_UNKNOWN_ADVERTISING_ID = 0x42, + CO_ERROR_LIMIT_REACHED = 0x43, + CO_ERROR_OPERATION_CANCELED_BY_HOST = 0x44, + CO_ERROR_PKT_TOO_LONG = 0x45, + + CO_ERROR_UNDEFINED = 0xFF, + + +/***************************************************** + *** HW ERROR CODES *** + *****************************************************/ + + CO_ERROR_HW_UART_OUT_OF_SYNC = 0x00, + CO_ERROR_HW_MEM_ALLOC_FAIL = 0x01, +}; + +/// @} CO_ERROR + +#endif // CO_ERROR_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_hci.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_hci.h new file mode 100644 index 0000000..66a6f9a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_hci.h @@ -0,0 +1,6022 @@ +/** + **************************************************************************************** + * + * @file co_hci.h + * + * @brief This file contains the HCI Bluetooth defines, enumerations and structures + * definitions for use by all modules in RW stack. + * + * Copyright (C) RivieraWaves 2009-2015 + * + **************************************************************************************** + */ + + +#ifndef CO_HCI_H_ +#define CO_HCI_H_ + +/** + **************************************************************************************** + * @addtogroup COMMON Common SW Block + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include // standard boolean definitions +#include // standard definitions +#include // standard integer definitions +#include "co_bt_defines.h" +#include "rwip_config.h" // IP configuration +#include "n32wb03x.h" +#include "compiler.h" // compiler definitions +//#include "nvds.h" +/* + * DEFINES + **************************************************************************************** + */ + + +/******************************************************************************************/ +/* ------------------------- H4TL DEFINITIONS Part IV.A -----------------------------*/ +/******************************************************************************************/ + +///HCI Transport Header length - change if different transport +#define HCI_TRANSPORT_HDR_LEN 0x01 + +///UART header: command message type +#define HCI_CMD_MSG_TYPE 0x01 + +///UART header: ACL data message type +#define HCI_ACL_MSG_TYPE 0x02 + +///UART header: Synchronous data message type +#define HCI_SYNC_MSG_TYPE 0x03 + +///UART header: event message type +#define HCI_EVT_MSG_TYPE 0x04 + +/******************************************************************************************/ +/* ------------------------- HCI DEFINITIONS Part II.E -----------------------------*/ +/******************************************************************************************/ + +///HCI Command Opcode byte length +#define HCI_CMD_OPCODE_LEN (0x02) + +///HCI Event code byte length +#define HCI_EVT_CODE_LEN (0x01) + +///HCI Command/Event parameter length field byte length +#define HCI_CMDEVT_PARLEN_LEN (0x01) + +///HCI Command header length +#define HCI_CMD_HDR_LEN (HCI_CMD_OPCODE_LEN + HCI_CMDEVT_PARLEN_LEN) + +///HCI Event header length +#define HCI_EVT_HDR_LEN (HCI_EVT_CODE_LEN + HCI_CMDEVT_PARLEN_LEN) + +/// HCI ACL header: handle and flags decoding +enum hci_acl_hdr_fields +{ + /// bits[00:11]: Connection handle + HCI_ACL_HDR_HDL_LSB = (0), + HCI_ACL_HDR_HDL_MASK = (0x0FFF), + /// bits[12:13]: Packet boundary flag + HCI_ACL_HDR_PB_FLAG_LSB = (12), + HCI_ACL_HDR_PB_FLAG_MASK = (0x3000), + /// bits[14:15]: Broadcast flag + HCI_ACL_HDR_BC_FLAG_LSB = (14), + HCI_ACL_HDR_BC_FLAG_MASK = (0xC000), + /// Packet boundary and Broadcast flags + HCI_ACL_HDR_DATA_FLAGS_LSB = (12), + HCI_ACL_HDR_DATA_FLAGS_MASK = (0xF000), +}; + +#define HCI_ACL_HDR_HDL_FLAGS_POS (0) +#define HCI_ACL_HDR_HDL_FLAGS_LEN (2) +/// HCI ACL header: data length field length +#define HCI_ACL_HDR_DATA_LEN_POS (HCI_ACL_HDR_HDL_FLAGS_LEN) +#define HCI_ACL_HDR_DATA_LEN_LEN (2) + +///HCI ACL data packet header length +#define HCI_ACL_HDR_LEN (HCI_ACL_HDR_HDL_FLAGS_LEN + HCI_ACL_HDR_DATA_LEN_LEN) + +/// HCI Synchronous header: handle and flags decoding +enum hci_syn_hdr_fields +{ + /// bits[00:11]: Connection handle + HCI_SYNC_HDR_HDL_LSB = (0), + HCI_SYNC_HDR_HDL_MASK = (0x0FFF), + /// bits[12:13]: Packet status flag + HCI_SYNC_HDR_PSF_LSB = (12), + HCI_SYNC_HDR_PSF_MASK = (0x3000), + /// bits[14:15]: RFU + HCI_SYNC_HDR_RFU_LSB = (14), + HCI_SYNC_HDR_RFU_MASK = (0xC000), +}; + +#define HCI_SYNC_HDR_HDL_FLAGS_POS (0) +#define HCI_SYNC_HDR_HDL_FLAGS_LEN (2) + + +/// HCI Synchronous header: data length field length +#define HCI_SYNC_HDR_DATA_LEN_POS (HCI_SYNC_HDR_HDL_FLAGS_LEN) +#define HCI_SYNC_HDR_DATA_LEN_LEN (1) +#define HCI_SYNC_MAX_DATA_SIZE (255) + +///HCI sync data packet header length +#define HCI_SYNC_HDR_LEN (HCI_SYNC_HDR_HDL_FLAGS_LEN + HCI_SYNC_HDR_DATA_LEN_LEN) + +///HCI Command Complete Event minimum parameter length: 1(nb_pk)+2(opcode) +#define HCI_CCEVT_HDR_PARLEN (0x03) + +///HCI Command Complete Event header length:1(code)+1(len)+1(pk)+2(opcode) +#define HCI_CCEVT_HDR_LEN (HCI_EVT_HDR_LEN + HCI_CCEVT_HDR_PARLEN) + +///HCI Basic Command Complete Event packet length +#define HCI_CCEVT_BASIC_LEN (HCI_CCEVT_HDR_LEN + 1) + +///HCI Command Status Event parameter length - constant +#define HCI_CSEVT_PARLEN (0x04) + +///HCI Command Status Event length:1(code)+1(len)+1(st)+1(pk)+2(opcode) +#define HCI_CSEVT_LEN (HCI_EVT_HDR_LEN + HCI_CSEVT_PARLEN) + +///HCI Reset Command parameter length +#define HCI_RESET_CMD_PARLEN 0 + +/// Default return parameter length for HCI Command Complete Event +#define HCI_CCEVT_BASIC_RETPAR_LEN 1 + +/// Max HCI commands param size +#define HCI_MAX_CMD_PARAM_SIZE 255 + +/// Macro to extract OCF from OPCODE +#define HCI_OP2OCF(opcode) ((opcode) & 0x03FF) + +/// Macro to extract OGF from OPCODE +#define HCI_OP2OGF(opcode) ((opcode) >> 10 & 0x003F) + +/// Macro to create OPCODE from OGF and OCF +#define HCI_OPCODE(ocf, ogf) (((ogf) << 10) | ocf) + +/// Maximum length of HCI advertising data fragments +#define HCI_ADV_DATA_FRAG_MAX_LEN 252 + + +/************************************************************************************** + ************** HCI COMMANDS **************** + **************************************************************************************/ + +///HCI enumeration of possible Command OGF values. +enum +{ + ///HCI Link Control Commands Group OGF code + LK_CNTL_OGF = 0x01, + ///HCI Link Policy Commands Group OGF code + LK_POL_OGF, + ///HCI Controller and Baseband Commands Group OGF code + CNTLR_BB_OGF, + ///HCI Information Parameters Commands Group OGF code + INFO_PAR_OGF, + ///HCI Status Commands Group OGF code + STAT_PAR_OGF, + ///HCI Test Commands Group OGF code + TEST_OGF, + ///HCI Low Energy Commands Group OGF code + LE_CNTLR_OGF=0x08, + ///HCI Vendor Specific Group OGF code + VS_OGF = 0x3F, + MAX_OGF +}; + + +///Commands Opcodes: OGF(6b) | OCF(10b) +/* Some Abbreviation used in names: + * - LK = Link Key + * - RD = Read + * - WR = Write + * - REM = Remote + * - STG = Settings + * - CON = Connection + * - CHG = Change + * - DFT = Default + * - PER = Periodic + */ + +///HCI enumeration of possible Command OP Codes. +/*@TRACE*/ +enum hci_opcode +{ + HCI_NO_OPERATION_CMD_OPCODE = 0x0000, + + //Link Control Commands + HCI_INQ_CMD_OPCODE = 0x0401, + HCI_INQ_CANCEL_CMD_OPCODE = 0x0402, + HCI_PER_INQ_MODE_CMD_OPCODE = 0x0403, + HCI_EXIT_PER_INQ_MODE_CMD_OPCODE = 0x0404, + HCI_CREATE_CON_CMD_OPCODE = 0x0405, + HCI_DISCONNECT_CMD_OPCODE = 0x0406, + HCI_CREATE_CON_CANCEL_CMD_OPCODE = 0x0408, + HCI_ACCEPT_CON_REQ_CMD_OPCODE = 0x0409, + HCI_REJECT_CON_REQ_CMD_OPCODE = 0x040A, + HCI_LK_REQ_REPLY_CMD_OPCODE = 0x040B, + HCI_LK_REQ_NEG_REPLY_CMD_OPCODE = 0x040C, + HCI_PIN_CODE_REQ_REPLY_CMD_OPCODE = 0x040D, + HCI_PIN_CODE_REQ_NEG_REPLY_CMD_OPCODE = 0x040E, + HCI_CHG_CON_PKT_TYPE_CMD_OPCODE = 0x040F, + HCI_AUTH_REQ_CMD_OPCODE = 0x0411, + HCI_SET_CON_ENC_CMD_OPCODE = 0x0413, + HCI_CHG_CON_LK_CMD_OPCODE = 0x0415, + HCI_MASTER_LK_CMD_OPCODE = 0x0417, + HCI_REM_NAME_REQ_CMD_OPCODE = 0x0419, + HCI_REM_NAME_REQ_CANCEL_CMD_OPCODE = 0x041A, + HCI_RD_REM_SUPP_FEATS_CMD_OPCODE = 0x041B, + HCI_RD_REM_EXT_FEATS_CMD_OPCODE = 0x041C, + HCI_RD_REM_VER_INFO_CMD_OPCODE = 0x041D, + HCI_RD_CLK_OFF_CMD_OPCODE = 0x041F, + HCI_RD_LMP_HDL_CMD_OPCODE = 0x0420, + HCI_SETUP_SYNC_CON_CMD_OPCODE = 0x0428, + HCI_ACCEPT_SYNC_CON_REQ_CMD_OPCODE = 0x0429, + HCI_REJECT_SYNC_CON_REQ_CMD_OPCODE = 0x042A, + HCI_IO_CAP_REQ_REPLY_CMD_OPCODE = 0x042B, + HCI_USER_CFM_REQ_REPLY_CMD_OPCODE = 0x042C, + HCI_USER_CFM_REQ_NEG_REPLY_CMD_OPCODE = 0x042D, + HCI_USER_PASSKEY_REQ_REPLY_CMD_OPCODE = 0x042E, + HCI_USER_PASSKEY_REQ_NEG_REPLY_CMD_OPCODE = 0x042F, + HCI_REM_OOB_DATA_REQ_REPLY_CMD_OPCODE = 0x0430, + HCI_REM_OOB_DATA_REQ_NEG_REPLY_CMD_OPCODE = 0x0433, + HCI_IO_CAP_REQ_NEG_REPLY_CMD_OPCODE = 0x0434, + HCI_ENH_SETUP_SYNC_CON_CMD_OPCODE = 0x043D, + HCI_ENH_ACCEPT_SYNC_CON_CMD_OPCODE = 0x043E, + HCI_TRUNC_PAGE_CMD_OPCODE = 0x043F, + HCI_TRUNC_PAGE_CAN_CMD_OPCODE = 0x0440, + HCI_SET_CON_SLV_BCST_CMD_OPCODE = 0x0441, + HCI_SET_CON_SLV_BCST_REC_CMD_OPCODE = 0x0442, + HCI_START_SYNC_TRAIN_CMD_OPCODE = 0x0443, + HCI_REC_SYNC_TRAIN_CMD_OPCODE = 0x0444, + HCI_REM_OOB_EXT_DATA_REQ_REPLY_CMD_OPCODE = 0x0445, + + //Link Policy Commands + HCI_HOLD_MODE_CMD_OPCODE = 0x0801, + HCI_SNIFF_MODE_CMD_OPCODE = 0x0803, + HCI_EXIT_SNIFF_MODE_CMD_OPCODE = 0x0804, + HCI_PARK_STATE_CMD_OPCODE = 0x0805, + HCI_EXIT_PARK_STATE_CMD_OPCODE = 0x0806, + HCI_QOS_SETUP_CMD_OPCODE = 0x0807, + HCI_ROLE_DISCOVERY_CMD_OPCODE = 0x0809, + HCI_SWITCH_ROLE_CMD_OPCODE = 0x080B, + HCI_RD_LINK_POL_STG_CMD_OPCODE = 0x080C, + HCI_WR_LINK_POL_STG_CMD_OPCODE = 0x080D, + HCI_RD_DFT_LINK_POL_STG_CMD_OPCODE = 0x080E, + HCI_WR_DFT_LINK_POL_STG_CMD_OPCODE = 0x080F, + HCI_FLOW_SPEC_CMD_OPCODE = 0x0810, + HCI_SNIFF_SUB_CMD_OPCODE = 0x0811, + + //Controller and Baseband Commands + HCI_SET_EVT_MASK_CMD_OPCODE = 0x0C01, + HCI_RESET_CMD_OPCODE = 0x0C03, + HCI_SET_EVT_FILTER_CMD_OPCODE = 0x0C05, + HCI_FLUSH_CMD_OPCODE = 0x0C08, + HCI_RD_PIN_TYPE_CMD_OPCODE = 0x0C09, + HCI_WR_PIN_TYPE_CMD_OPCODE = 0x0C0A, + HCI_CREATE_NEW_UNIT_KEY_CMD_OPCODE = 0x0C0B, + HCI_RD_STORED_LK_CMD_OPCODE = 0x0C0D, + HCI_WR_STORED_LK_CMD_OPCODE = 0x0C11, + HCI_DEL_STORED_LK_CMD_OPCODE = 0x0C12, + HCI_WR_LOCAL_NAME_CMD_OPCODE = 0x0C13, + HCI_RD_LOCAL_NAME_CMD_OPCODE = 0x0C14, + HCI_RD_CON_ACCEPT_TO_CMD_OPCODE = 0x0C15, + HCI_WR_CON_ACCEPT_TO_CMD_OPCODE = 0x0C16, + HCI_RD_PAGE_TO_CMD_OPCODE = 0x0C17, + HCI_WR_PAGE_TO_CMD_OPCODE = 0x0C18, + HCI_RD_SCAN_EN_CMD_OPCODE = 0x0C19, + HCI_WR_SCAN_EN_CMD_OPCODE = 0x0C1A, + HCI_RD_PAGE_SCAN_ACT_CMD_OPCODE = 0x0C1B, + HCI_WR_PAGE_SCAN_ACT_CMD_OPCODE = 0x0C1C, + HCI_RD_INQ_SCAN_ACT_CMD_OPCODE = 0x0C1D, + HCI_WR_INQ_SCAN_ACT_CMD_OPCODE = 0x0C1E, + HCI_RD_AUTH_EN_CMD_OPCODE = 0x0C1F, + HCI_WR_AUTH_EN_CMD_OPCODE = 0x0C20, + HCI_RD_CLASS_OF_DEV_CMD_OPCODE = 0x0C23, + HCI_WR_CLASS_OF_DEV_CMD_OPCODE = 0x0C24, + HCI_RD_VOICE_STG_CMD_OPCODE = 0x0C25, + HCI_WR_VOICE_STG_CMD_OPCODE = 0x0C26, + HCI_RD_AUTO_FLUSH_TO_CMD_OPCODE = 0x0C27, + HCI_WR_AUTO_FLUSH_TO_CMD_OPCODE = 0x0C28, + HCI_RD_NB_BDCST_RETX_CMD_OPCODE = 0x0C29, + HCI_WR_NB_BDCST_RETX_CMD_OPCODE = 0x0C2A, + HCI_RD_HOLD_MODE_ACTIVITY_CMD_OPCODE = 0x0C2B, + HCI_WR_HOLD_MODE_ACTIVITY_CMD_OPCODE = 0x0C2C, + HCI_RD_TX_PWR_LVL_CMD_OPCODE = 0x0C2D, + HCI_RD_SYNC_FLOW_CTRL_EN_CMD_OPCODE = 0x0C2E, + HCI_WR_SYNC_FLOW_CTRL_EN_CMD_OPCODE = 0x0C2F, + HCI_SET_CTRL_TO_HOST_FLOW_CTRL_CMD_OPCODE = 0x0C31, + HCI_HOST_BUF_SIZE_CMD_OPCODE = 0x0C33, + HCI_HOST_NB_CMP_PKTS_CMD_OPCODE = 0x0C35, + HCI_RD_LINK_SUPV_TO_CMD_OPCODE = 0x0C36, + HCI_WR_LINK_SUPV_TO_CMD_OPCODE = 0x0C37, + HCI_RD_NB_SUPP_IAC_CMD_OPCODE = 0x0C38, + HCI_RD_CURR_IAC_LAP_CMD_OPCODE = 0x0C39, + HCI_WR_CURR_IAC_LAP_CMD_OPCODE = 0x0C3A, + HCI_SET_AFH_HOST_CH_CLASS_CMD_OPCODE = 0x0C3F, + HCI_RD_INQ_SCAN_TYPE_CMD_OPCODE = 0x0C42, + HCI_WR_INQ_SCAN_TYPE_CMD_OPCODE = 0x0C43, + HCI_RD_INQ_MODE_CMD_OPCODE = 0x0C44, + HCI_WR_INQ_MODE_CMD_OPCODE = 0x0C45, + HCI_RD_PAGE_SCAN_TYPE_CMD_OPCODE = 0x0C46, + HCI_WR_PAGE_SCAN_TYPE_CMD_OPCODE = 0x0C47, + HCI_RD_AFH_CH_ASSESS_MODE_CMD_OPCODE = 0x0C48, + HCI_WR_AFH_CH_ASSESS_MODE_CMD_OPCODE = 0x0C49, + HCI_RD_EXT_INQ_RSP_CMD_OPCODE = 0x0C51, + HCI_WR_EXT_INQ_RSP_CMD_OPCODE = 0x0C52, + HCI_REFRESH_ENC_KEY_CMD_OPCODE = 0x0C53, + HCI_RD_SP_MODE_CMD_OPCODE = 0x0C55, + HCI_WR_SP_MODE_CMD_OPCODE = 0x0C56, + HCI_RD_LOC_OOB_DATA_CMD_OPCODE = 0x0C57, + HCI_RD_INQ_RSP_TX_PWR_LVL_CMD_OPCODE = 0x0C58, + HCI_WR_INQ_TX_PWR_LVL_CMD_OPCODE = 0x0C59, + HCI_RD_DFT_ERR_DATA_REP_CMD_OPCODE = 0x0C5A, + HCI_WR_DFT_ERR_DATA_REP_CMD_OPCODE = 0x0C5B, + HCI_ENH_FLUSH_CMD_OPCODE = 0x0C5F, + HCI_SEND_KEYPRESS_NOTIF_CMD_OPCODE = 0x0C60, + HCI_SET_EVT_MASK_PAGE_2_CMD_OPCODE = 0x0C63, + HCI_RD_FLOW_CNTL_MODE_CMD_OPCODE = 0x0C66, + HCI_WR_FLOW_CNTL_MODE_CMD_OPCODE = 0x0C67, + HCI_RD_ENH_TX_PWR_LVL_CMD_OPCODE = 0x0C68, + HCI_RD_LE_HOST_SUPP_CMD_OPCODE = 0x0C6C, + HCI_WR_LE_HOST_SUPP_CMD_OPCODE = 0x0C6D, + HCI_SET_MWS_CHANNEL_PARAMS_CMD_OPCODE = 0x0C6E, + HCI_SET_EXTERNAL_FRAME_CONFIG_CMD_OPCODE = 0x0C6F, + HCI_SET_MWS_SIGNALING_CMD_OPCODE = 0x0C70, + HCI_SET_MWS_TRANSPORT_LAYER_CMD_OPCODE = 0x0C71, + HCI_SET_MWS_SCAN_FREQ_TABLE_CMD_OPCODE = 0x0C72, + HCI_SET_MWS_PATTERN_CONFIG_CMD_OPCODE = 0x0C73, + HCI_SET_RES_LT_ADDR_CMD_OPCODE = 0x0C74, + HCI_DEL_RES_LT_ADDR_CMD_OPCODE = 0x0C75, + HCI_SET_CON_SLV_BCST_DATA_CMD_OPCODE = 0x0C76, + HCI_RD_SYNC_TRAIN_PARAM_CMD_OPCODE = 0x0C77, + HCI_WR_SYNC_TRAIN_PARAM_CMD_OPCODE = 0x0C78, + HCI_RD_SEC_CON_HOST_SUPP_CMD_OPCODE = 0x0C79, + HCI_WR_SEC_CON_HOST_SUPP_CMD_OPCODE = 0x0C7A, + HCI_RD_AUTH_PAYL_TO_CMD_OPCODE = 0x0C7B, + HCI_WR_AUTH_PAYL_TO_CMD_OPCODE = 0x0C7C, + HCI_RD_LOC_OOB_EXT_DATA_CMD_OPCODE = 0x0C7D, + HCI_RD_EXT_PAGE_TO_CMD_OPCODE = 0x0C7E, + HCI_WR_EXT_PAGE_TO_CMD_OPCODE = 0x0C7F, + HCI_RD_EXT_INQ_LEN_CMD_OPCODE = 0x0C80, + HCI_WR_EXT_INQ_LEN_CMD_OPCODE = 0x0C81, + + //Info Params + HCI_RD_LOCAL_VER_INFO_CMD_OPCODE = 0x1001, + HCI_RD_LOCAL_SUPP_CMDS_CMD_OPCODE = 0x1002, + HCI_RD_LOCAL_SUPP_FEATS_CMD_OPCODE = 0x1003, + HCI_RD_LOCAL_EXT_FEATS_CMD_OPCODE = 0x1004, + HCI_RD_BUFF_SIZE_CMD_OPCODE = 0x1005, + HCI_RD_BD_ADDR_CMD_OPCODE = 0x1009, + HCI_RD_LOCAL_SUPP_CODECS_CMD_OPCODE = 0x100B, + HCI_RD_LOCAL_SP_OPT_CMD_OPCODE = 0x100C, + + //Status Params + HCI_RD_FAIL_CONTACT_CNT_CMD_OPCODE = 0x1401, + HCI_RST_FAIL_CONTACT_CNT_CMD_OPCODE = 0x1402, + HCI_RD_LINK_QUAL_CMD_OPCODE = 0x1403, + HCI_RD_RSSI_CMD_OPCODE = 0x1405, + HCI_RD_AFH_CH_MAP_CMD_OPCODE = 0x1406, + HCI_RD_CLK_CMD_OPCODE = 0x1407, + HCI_RD_ENC_KEY_SIZE_CMD_OPCODE = 0x1408, + HCI_GET_MWS_TRANSPORT_LAYER_CONFIG_CMD_OPCODE = 0x140C, + + //Testing Commands + HCI_RD_LOOPBACK_MODE_CMD_OPCODE = 0x1801, + HCI_WR_LOOPBACK_MODE_CMD_OPCODE = 0x1802, + HCI_EN_DUT_MODE_CMD_OPCODE = 0x1803, + HCI_WR_SP_DBG_MODE_CMD_OPCODE = 0x1804, + HCI_WR_SEC_CON_TEST_MODE_CMD_OPCODE = 0x180A, + + /// LE Commands Opcodes + HCI_LE_SET_EVT_MASK_CMD_OPCODE = 0x2001, + HCI_LE_RD_BUFF_SIZE_CMD_OPCODE = 0x2002, + HCI_LE_RD_LOCAL_SUPP_FEATS_CMD_OPCODE = 0x2003, + HCI_LE_SET_RAND_ADDR_CMD_OPCODE = 0x2005, + HCI_LE_SET_ADV_PARAM_CMD_OPCODE = 0x2006, + HCI_LE_RD_ADV_CHNL_TX_PW_CMD_OPCODE = 0x2007, + HCI_LE_SET_ADV_DATA_CMD_OPCODE = 0x2008, + HCI_LE_SET_SCAN_RSP_DATA_CMD_OPCODE = 0x2009, + HCI_LE_SET_ADV_EN_CMD_OPCODE = 0x200A, + HCI_LE_SET_SCAN_PARAM_CMD_OPCODE = 0x200B, + HCI_LE_SET_SCAN_EN_CMD_OPCODE = 0x200C, + HCI_LE_CREATE_CON_CMD_OPCODE = 0x200D, + HCI_LE_CREATE_CON_CANCEL_CMD_OPCODE = 0x200E, + HCI_LE_RD_WLST_SIZE_CMD_OPCODE = 0x200F, + HCI_LE_CLEAR_WLST_CMD_OPCODE = 0x2010, + HCI_LE_ADD_DEV_TO_WLST_CMD_OPCODE = 0x2011, + HCI_LE_RMV_DEV_FROM_WLST_CMD_OPCODE = 0x2012, + HCI_LE_CON_UPDATE_CMD_OPCODE = 0x2013, + HCI_LE_SET_HOST_CH_CLASS_CMD_OPCODE = 0x2014, + HCI_LE_RD_CHNL_MAP_CMD_OPCODE = 0x2015, + HCI_LE_RD_REM_FEATS_CMD_OPCODE = 0x2016, + HCI_LE_ENC_CMD_OPCODE = 0x2017, + HCI_LE_RAND_CMD_OPCODE = 0x2018, + HCI_LE_START_ENC_CMD_OPCODE = 0x2019, + HCI_LE_LTK_REQ_REPLY_CMD_OPCODE = 0x201A, + HCI_LE_LTK_REQ_NEG_REPLY_CMD_OPCODE = 0x201B, + HCI_LE_RD_SUPP_STATES_CMD_OPCODE = 0x201C, + HCI_LE_RX_TEST_V1_CMD_OPCODE = 0x201D, + HCI_LE_TX_TEST_V1_CMD_OPCODE = 0x201E, + HCI_LE_TEST_END_CMD_OPCODE = 0x201F, + HCI_LE_REM_CON_PARAM_REQ_REPLY_CMD_OPCODE = 0x2020, + HCI_LE_REM_CON_PARAM_REQ_NEG_REPLY_CMD_OPCODE = 0x2021, + HCI_LE_SET_DATA_LEN_CMD_OPCODE = 0x2022, + HCI_LE_RD_SUGGTED_DFT_DATA_LEN_CMD_OPCODE = 0x2023, + HCI_LE_WR_SUGGTED_DFT_DATA_LEN_CMD_OPCODE = 0x2024, + HCI_LE_RD_LOC_P256_PUB_KEY_CMD_OPCODE = 0x2025, + HCI_LE_GEN_DHKEY_V1_CMD_OPCODE = 0x2026, + HCI_LE_ADD_DEV_TO_RSLV_LIST_CMD_OPCODE = 0x2027, + HCI_LE_RMV_DEV_FROM_RSLV_LIST_CMD_OPCODE = 0x2028, + HCI_LE_CLEAR_RSLV_LIST_CMD_OPCODE = 0x2029, + HCI_LE_RD_RSLV_LIST_SIZE_CMD_OPCODE = 0x202A, + HCI_LE_RD_PEER_RSLV_ADDR_CMD_OPCODE = 0x202B, + HCI_LE_RD_LOC_RSLV_ADDR_CMD_OPCODE = 0x202C, + HCI_LE_SET_ADDR_RESOL_EN_CMD_OPCODE = 0x202D, + HCI_LE_SET_RSLV_PRIV_ADDR_TO_CMD_OPCODE = 0x202E, + HCI_LE_RD_MAX_DATA_LEN_CMD_OPCODE = 0x202F, + HCI_LE_RD_PHY_CMD_OPCODE = 0x2030, + HCI_LE_SET_DFT_PHY_CMD_OPCODE = 0x2031, + HCI_LE_SET_PHY_CMD_OPCODE = 0x2032, + HCI_LE_RX_TEST_V2_CMD_OPCODE = 0x2033, + HCI_LE_TX_TEST_V2_CMD_OPCODE = 0x2034, + HCI_LE_SET_ADV_SET_RAND_ADDR_CMD_OPCODE = 0x2035, + HCI_LE_SET_EXT_ADV_PARAM_CMD_OPCODE = 0x2036, + HCI_LE_SET_EXT_ADV_DATA_CMD_OPCODE = 0x2037, + HCI_LE_SET_EXT_SCAN_RSP_DATA_CMD_OPCODE = 0x2038, + HCI_LE_SET_EXT_ADV_EN_CMD_OPCODE = 0x2039, + HCI_LE_RD_MAX_ADV_DATA_LEN_CMD_OPCODE = 0x203A, + HCI_LE_RD_NB_SUPP_ADV_SETS_CMD_OPCODE = 0x203B, + HCI_LE_RMV_ADV_SET_CMD_OPCODE = 0x203C, + HCI_LE_CLEAR_ADV_SETS_CMD_OPCODE = 0x203D, + HCI_LE_SET_PER_ADV_PARAM_CMD_OPCODE = 0x203E, + HCI_LE_SET_PER_ADV_DATA_CMD_OPCODE = 0x203F, + HCI_LE_SET_PER_ADV_EN_CMD_OPCODE = 0x2040, + HCI_LE_SET_EXT_SCAN_PARAM_CMD_OPCODE = 0x2041, + HCI_LE_SET_EXT_SCAN_EN_CMD_OPCODE = 0x2042, + HCI_LE_EXT_CREATE_CON_CMD_OPCODE = 0x2043, + HCI_LE_PER_ADV_CREATE_SYNC_CMD_OPCODE = 0x2044, + HCI_LE_PER_ADV_CREATE_SYNC_CANCEL_CMD_OPCODE = 0x2045, + HCI_LE_PER_ADV_TERM_SYNC_CMD_OPCODE = 0x2046, + HCI_LE_ADD_DEV_TO_PER_ADV_LIST_CMD_OPCODE = 0x2047, + HCI_LE_RMV_DEV_FROM_PER_ADV_LIST_CMD_OPCODE = 0x2048, + HCI_LE_CLEAR_PER_ADV_LIST_CMD_OPCODE = 0x2049, + HCI_LE_RD_PER_ADV_LIST_SIZE_CMD_OPCODE = 0x204A, + HCI_LE_RD_TX_PWR_CMD_OPCODE = 0x204B, + HCI_LE_RD_RF_PATH_COMP_CMD_OPCODE = 0x204C, + HCI_LE_WR_RF_PATH_COMP_CMD_OPCODE = 0x204D, + HCI_LE_SET_PRIV_MODE_CMD_OPCODE = 0x204E, + HCI_LE_RX_TEST_V3_CMD_OPCODE = 0x204F, + HCI_LE_TX_TEST_V3_CMD_OPCODE = 0x2050, + HCI_LE_SET_CONLESS_CTE_TX_PARAM_CMD_OPCODE = 0x2051, + HCI_LE_SET_CONLESS_CTE_TX_EN_CMD_OPCODE = 0x2052, + HCI_LE_SET_CONLESS_IQ_SAMPL_EN_CMD_OPCODE = 0x2053, + HCI_LE_SET_CON_CTE_RX_PARAM_CMD_OPCODE = 0x2054, + HCI_LE_SET_CON_CTE_TX_PARAM_CMD_OPCODE = 0x2055, + HCI_LE_CON_CTE_REQ_EN_CMD_OPCODE = 0x2056, + HCI_LE_CON_CTE_RSP_EN_CMD_OPCODE = 0x2057, + HCI_LE_RD_ANTENNA_INF_CMD_OPCODE = 0x2058, + HCI_LE_SET_PER_ADV_REC_EN_CMD_OPCODE = 0x2059, + HCI_LE_PER_ADV_SYNC_TRANSF_CMD_OPCODE = 0x205A, + HCI_LE_PER_ADV_SET_INFO_TRANSF_CMD_OPCODE = 0x205B, + HCI_LE_SET_PER_ADV_SYNC_TRANSF_PARAM_CMD_OPCODE = 0x205C, + HCI_LE_SET_DFT_PER_ADV_SYNC_TRANSF_PARAM_CMD_OPCODE = 0x205D, + HCI_LE_GEN_DHKEY_V2_CMD_OPCODE = 0x205E, + HCI_LE_MOD_SLEEP_CLK_ACC_CMD_OPCODE = 0x205F, + + ///Debug commands - OGF = 0x3F (spec) + HCI_DBG_RD_MEM_CMD_OPCODE = 0xFC01, + HCI_DBG_WR_MEM_CMD_OPCODE = 0xFC02, + HCI_DBG_DEL_PAR_CMD_OPCODE = 0xFC03, + HCI_DBG_ID_FLASH_CMD_OPCODE = 0xFC05, + HCI_DBG_ER_FLASH_CMD_OPCODE = 0xFC06, + HCI_DBG_WR_FLASH_CMD_OPCODE = 0xFC07, + HCI_DBG_RD_FLASH_CMD_OPCODE = 0xFC08, + HCI_DBG_RD_PAR_CMD_OPCODE = 0xFC09, + HCI_DBG_WR_PAR_CMD_OPCODE = 0xFC0A, + HCI_DBG_WLAN_COEX_CMD_OPCODE = 0xFC0B, + HCI_DBG_WLAN_COEXTST_SCEN_CMD_OPCODE = 0xFC0D, + HCI_DBG_BT_SEND_LMP_CMD_OPCODE = 0xFC0E, + HCI_DBG_SET_LOCAL_CLOCK_CMD_OPCODE = 0xFC0F, + HCI_DBG_RD_KE_STATS_CMD_OPCODE = 0xFC10, + HCI_DBG_PLF_RESET_CMD_OPCODE = 0xFC11, + HCI_DBG_RD_MEM_INFO_CMD_OPCODE = 0xFC12, + HCI_VS_SET_PREF_SLAVE_LATENCY_CMD_OPCODE = 0xFC13, + HCI_VS_SET_PREF_SLAVE_EVT_DUR_CMD_OPCODE = 0xFC14, + HCI_VS_SET_MAX_RX_SIZE_AND_TIME_CMD_OPCODE = 0xFC15, + HCI_DBG_BLE_REG_RD_CMD_OPCODE = 0xFC30, + HCI_DBG_BLE_REG_WR_CMD_OPCODE = 0xFC31, + HCI_DBG_SEND_LLCP_CMD_OPCODE = 0xFC35, + HCI_DBG_LLCP_DISCARD_CMD_OPCODE = 0xFC36, + HCI_DBG_RF_REG_RD_CMD_OPCODE = 0xFC39, + HCI_DBG_RF_REG_WR_CMD_OPCODE = 0xFC3A, + HCI_DBG_RF_SWITCH_CLK_CMD_OPCODE = 0xFC3C, + HCI_DBG_RF_WR_DATA_TX_CMD_OPCODE = 0xFC3D, + HCI_DBG_RF_RD_DATA_RX_CMD_OPCODE = 0xFC3E, + HCI_DBG_RF_CNTL_TX_CMD_OPCODE = 0xFC3F, + HCI_DBG_RF_SYNC_P_CNTL_CMD_OPCODE = 0xFC40, + + + #if (RW_DEBUG && BT_EMB_PRESENT) + HCI_DBG_BT_DISCARD_LMP_EN_CMD_OPCODE = 0xFC44, + #endif //RW_DEBUG && BT_EMB_PRESENT + + HCI_DBG_MWS_COEX_CMD_OPCODE = 0xFC45, + HCI_DBG_MWS_COEXTST_SCEN_CMD_OPCODE = 0xFC46, + #if (BT_READ_PICONET_CLOCK) + HCI_VS_RD_PICONET_CLOCK_CMD_OPCODE = 0xFC50, + #endif // (BT_READ_PICONET_CLOCK) + + #if (BLE_ISO_MODE_0) + /// Vendor Specific commands for ISO Mode 0 + HCI_VS_SETUP_AM0_CHAN_CMD_OPCODE = 0xFC54, + HCI_VS_REMOVE_AM0_CHAN_CMD_OPCODE = 0xFC55, + HCI_VS_CONTROL_AM0_CHAN_CMD_OPCODE = 0xFC56, + #endif // (BLE_ISO_MODE_0) + + #if CRYPTO_UT + HCI_DBG_TEST_CRYPTO_FUNC_CMD_OPCODE = 0xFC60, + #endif //CRYPTO_UT + + #if RW_DEBUG + HCI_DBG_TEST_SCH_PLAN_SET_CMD_OPCODE = 0xFC61, + HCI_DBG_TEST_SCH_PLAN_REM_CMD_OPCODE = 0xFC62, + HCI_DBG_TEST_SCH_PLAN_CHK_CMD_OPCODE = 0xFC63, + HCI_DBG_TEST_SCH_PLAN_REQ_CMD_OPCODE = 0xFC64, + #endif //RW_DEBUG + + #if BLE_IQ_GEN + HCI_DBG_IQGEN_CFG_CMD_OPCODE = 0xFC65, + #endif //BLE_IQ_GEN + +}; + +/************************************************************************************** + ************** HCI EVENTS **************** + **************************************************************************************/ + +///Event Codes +/*@TRACE*/ +enum hci_evt_code +{ + HCI_INQ_CMP_EVT_CODE = 0x01, + HCI_INQ_RES_EVT_CODE = 0x02, + HCI_CON_CMP_EVT_CODE = 0x03, + HCI_CON_REQ_EVT_CODE = 0x04, + HCI_DISC_CMP_EVT_CODE = 0x05, + HCI_AUTH_CMP_EVT_CODE = 0x06, + HCI_REM_NAME_REQ_CMP_EVT_CODE = 0x07, + HCI_ENC_CHG_EVT_CODE = 0x08, + HCI_CHG_CON_LK_CMP_EVT_CODE = 0x09, + HCI_MASTER_LK_CMP_EVT_CODE = 0x0A, + HCI_RD_REM_SUPP_FEATS_CMP_EVT_CODE = 0x0B, + HCI_RD_REM_VER_INFO_CMP_EVT_CODE = 0x0C, + HCI_QOS_SETUP_CMP_EVT_CODE = 0x0D, + HCI_CMD_CMP_EVT_CODE = 0x0E, + HCI_CMD_STATUS_EVT_CODE = 0x0F, + HCI_HW_ERR_EVT_CODE = 0x10, + HCI_FLUSH_OCCURRED_EVT_CODE = 0x11, + HCI_ROLE_CHG_EVT_CODE = 0x12, + HCI_NB_CMP_PKTS_EVT_CODE = 0x13, + HCI_MODE_CHG_EVT_CODE = 0x14, + HCI_RETURN_LINK_KEYS_EVT_CODE = 0x15, + HCI_PIN_CODE_REQ_EVT_CODE = 0x16, + HCI_LK_REQ_EVT_CODE = 0x17, + HCI_LK_NOTIF_EVT_CODE = 0x18, + HCI_DATA_BUF_OVFLW_EVT_CODE = 0x1A, + HCI_MAX_SLOT_CHG_EVT_CODE = 0x1B, + HCI_RD_CLK_OFF_CMP_EVT_CODE = 0x1C, + HCI_CON_PKT_TYPE_CHG_EVT_CODE = 0x1D, + HCI_QOS_VIOL_EVT_CODE = 0x1E, + HCI_PAGE_SCAN_REPET_MODE_CHG_EVT_CODE = 0x20, + HCI_FLOW_SPEC_CMP_EVT_CODE = 0x21, + HCI_INQ_RES_WITH_RSSI_EVT_CODE = 0x22, + HCI_RD_REM_EXT_FEATS_CMP_EVT_CODE = 0x23, + HCI_SYNC_CON_CMP_EVT_CODE = 0x2C, + HCI_SYNC_CON_CHG_EVT_CODE = 0x2D, + HCI_SNIFF_SUB_EVT_CODE = 0x2E, + HCI_EXT_INQ_RES_EVT_CODE = 0x2F, + HCI_ENC_KEY_REFRESH_CMP_EVT_CODE = 0x30, + HCI_IO_CAP_REQ_EVT_CODE = 0x31, + HCI_IO_CAP_RSP_EVT_CODE = 0x32, + HCI_USER_CFM_REQ_EVT_CODE = 0x33, + HCI_USER_PASSKEY_REQ_EVT_CODE = 0x34, + HCI_REM_OOB_DATA_REQ_EVT_CODE = 0x35, + HCI_SP_CMP_EVT_CODE = 0x36, + HCI_LINK_SUPV_TO_CHG_EVT_CODE = 0x38, + HCI_ENH_FLUSH_CMP_EVT_CODE = 0x39, + HCI_USER_PASSKEY_NOTIF_EVT_CODE = 0x3B, + HCI_KEYPRESS_NOTIF_EVT_CODE = 0x3C, + HCI_REM_HOST_SUPP_FEATS_NOTIF_EVT_CODE = 0x3D, + HCI_LE_META_EVT_CODE = 0x3E, + HCI_MAX_EVT_MSK_PAGE_1_CODE = 0x40, + HCI_SYNC_TRAIN_CMP_EVT_CODE = 0x4F, + HCI_SYNC_TRAIN_REC_EVT_CODE = 0x50, + HCI_CON_SLV_BCST_REC_EVT_CODE = 0x51, + HCI_CON_SLV_BCST_TO_EVT_CODE = 0x52, + HCI_TRUNC_PAGE_CMP_EVT_CODE = 0x53, + HCI_SLV_PAGE_RSP_TO_EVT_CODE = 0x54, + HCI_CON_SLV_BCST_CH_MAP_CHG_EVT_CODE = 0x55, + HCI_AUTH_PAYL_TO_EXP_EVT_CODE = 0x57, + HCI_SAM_STATUS_CHANGE_EVT_CODE = 0x58, + HCI_MAX_EVT_MSK_PAGE_2_CODE = 0x59, + HCI_DBG_META_EVT_CODE = 0xFF, +}; + +/*@TRACE*/ +enum hci_le_evt_subcode +{ + /// LE Events Subcodes + HCI_LE_CON_CMP_EVT_SUBCODE = 0x01, + HCI_LE_ADV_REPORT_EVT_SUBCODE = 0x02, + HCI_LE_CON_UPDATE_CMP_EVT_SUBCODE = 0x03, + HCI_LE_RD_REM_FEATS_CMP_EVT_SUBCODE = 0x04, + HCI_LE_LTK_REQUEST_EVT_SUBCODE = 0x05, + HCI_LE_REM_CON_PARAM_REQ_EVT_SUBCODE = 0x06, + HCI_LE_DATA_LEN_CHG_EVT_SUBCODE = 0x07, + HCI_LE_RD_LOC_P256_PUB_KEY_CMP_EVT_SUBCODE = 0x08, + HCI_LE_GEN_DHKEY_CMP_EVT_SUBCODE = 0x09, + HCI_LE_ENH_CON_CMP_EVT_SUBCODE = 0x0A, + HCI_LE_DIR_ADV_REP_EVT_SUBCODE = 0x0B, + HCI_LE_PHY_UPD_CMP_EVT_SUBCODE = 0x0C, + HCI_LE_EXT_ADV_REPORT_EVT_SUBCODE = 0x0D, + HCI_LE_PER_ADV_SYNC_EST_EVT_SUBCODE = 0x0E, + HCI_LE_PER_ADV_REPORT_EVT_SUBCODE = 0x0F, + HCI_LE_PER_ADV_SYNC_LOST_EVT_SUBCODE = 0x10, + HCI_LE_SCAN_TIMEOUT_EVT_SUBCODE = 0x11, + HCI_LE_ADV_SET_TERMINATED_EVT_SUBCODE = 0x12, + HCI_LE_SCAN_REQ_RCVD_EVT_SUBCODE = 0x13, + HCI_LE_CH_SEL_ALGO_EVT_SUBCODE = 0x14, + HCI_LE_CONLESS_IQ_REPORT_EVT_SUBCODE = 0x15, + HCI_LE_CON_IQ_REPORT_EVT_SUBCODE = 0x16, + HCI_LE_CTE_REQ_FAILED_EVT_SUBCODE = 0x17, + HCI_LE_PER_ADV_SYNC_TRANSF_REC_EVT_SUBCODE = 0x18, +}; + +#if (RW_DEBUG || BLE_ISOGEN) +/*@TRACE*/ +enum hci_vs_evt_subcode +{ + #if (RW_DEBUG) + /// DBG Events Subcodes + HCI_DBG_ASSERT_EVT_SUBCODE = 0x02, + #endif //(RW_DEBUG) + + #if (BLE_ISOGEN) + /// VS ISO Gen Statistics Status + HCI_VS_ISOGEN_STAT_EVT_SUBCODE = 0x03, + #endif // (BLE_ISOGEN) +}; +#endif //(RW_DEBUG || BLE_ISOGEN) + +/// Event mask page enum +enum hci_evt_mask_page +{ + /// page 0 + HCI_PAGE_0, + /// page 1 + HCI_PAGE_1, + /// page 2 + HCI_PAGE_2, + /// Default + HCI_PAGE_DFT, + /// LE event + HCI_PAGE_LE, +}; + +#if (BLE_ISO_PRESENT) +#if (BLE_ISO_MODE_0) +/// Current audio mode +enum iso_am0_ctrl +{ + // Stop Audio Mode 0 Stream + ISO_AM0_CRL_DISABLE, + // Start Audio Mode 0 Stream + ISO_AM0_CRL_ENABLE, +}; +#endif // (BLE_ISO_MODE_0) + + +/// Isochronous Channel Direction selection +enum iso_rx_tx_select +{ + /// Isochronous tx buffer selection: Host to Controller + ISO_TX_SEL, + /// Isochronous rx buffer selection: Controller to Host + ISO_RX_SEL +}; + +/// Isochronous Channel data path selection +enum iso_dp_type +{ + /// Data Path direction is disabled + ISO_DP_DISABLE = 0x00, + /// Voice over HCI Data Path + ISO_DP_VOHCI = 0x01, + + // -------- VENDOR SPECIFIC --------- // + + /// ISO over HCI Data Path + ISO_DP_ISOOHCI = 0xF0, + /// PCM Data path + ISO_DP_PCM = 0xF1, + /// ISO Payload Generator + ISO_DP_ISOGEN = 0xF2, +}; + +#endif // (BLE_ISO_PRESENT) + + + +/************************************************************************************** + ************** HCI MESSAGE STRUCTURES **************** + **************************************************************************************/ + +/// HCI ACL data packet structure +/*@TRACE*/ +struct hci_acl_data +{ + /// bits[00:11]: Connection handle + /// bits[12:13]: Packet boundary flag + /// bits[14:15]: Broadcast flag + uint16_t conhdl_pb_bc_flag; + /// length of the data + uint16_t length; + /// Memory Pointer address + uint32_t buf_ptr; +}; + +/// HCI Synchronous data packet structure +/*@TRACE*/ +struct hci_sync_data +{ + /// bits[00:11]: Connection handle + /// bits[12:13]: Packet status flag + uint16_t conhdl_psf; + /// length of the data + uint8_t length; + /// EM buffer pointer + uint16_t buf_ptr; +}; + + +/* + * HCI COMMANDS PARAMETERS (to classify) + **************************************************************************************** + */ + +/// HCI basic command structure with connection handle +/*@TRACE + * hci_rd_rssi_cmd = hci_basic_conhdl_cmd + * hci_le_rd_chnl_map_cmd = hci_basic_conhdl_cmd + * hci_le_ltk_req_neg_reply_cmd = hci_basic_conhdl_cmd*/ +struct hci_basic_conhdl_cmd +{ + /// connection handle + uint16_t conhdl; +}; + +/// HCI basic command structure with BD address +struct hci_basic_bd_addr_cmd +{ + ///BdAddr + struct bd_addr bd_addr; +}; + +/// HCI Accept connection request command structure +/*@TRACE*/ +struct hci_accept_con_req_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Page Scan Repetition Mode + uint8_t role; +}; + +/// HCI Accept synchronous connection request command structure +/*@TRACE*/ +struct hci_accept_sync_con_req_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Transmit bandwidth + uint32_t tx_bw; + ///Receive bandwidth + uint32_t rx_bw; + ///Max latency + uint16_t max_lat; + ///Voice settings + uint16_t vx_set; + ///Retransmission effort + uint8_t retx_eff; + ///Packet type + uint16_t pkt_type ; +}; + +/// HCI Enhanced Accept synchronous connection request command structure +/*@TRACE*/ +struct hci_enh_accept_sync_con_cmd +{ + + struct bd_addr bd_addr; // BD address + uint32_t tx_bw; // Transmit Bandwidth (in B/sec) + uint32_t rx_bw; // Receive Bandwidth (in B/sec) + uint8_t tx_cod_fmt[5]; // Transmit Coding Format + uint8_t rx_cod_fmt[5]; // Receive Coding Format + uint16_t tx_cod_fr_sz; // Transmit Codec Frame Size (in B) + uint16_t rx_cod_fr_sz; // Receive Codec Frame Size (in B) + uint32_t in_bw; // Input Bandwidth (in B/sec) + uint32_t out_bw; // Output Bandwidth (in B/sec) + uint8_t in_cod_fmt[5]; // Input Coding Format + uint8_t out_cod_fmt[5]; // Output Coding Format + uint16_t in_cod_data_sz; // Input Coded Data Size (in bits) + uint16_t out_cod_data_sz; // Output Coded Data Size (in bits) + uint8_t in_data_fmt; // Input PCM Data Format + uint8_t out_data_fmt; // Output PCM Data Format + uint8_t in_msb_pos; // Input PCM Sample Payload MSB Position (in bits) + uint8_t out_msb_pos; // Output PCM Sample Payload MSB Position (in bits) + uint8_t in_data_path; // Input Data Path + uint8_t out_data_path; // Output Data Path + uint8_t in_tr_unit_sz; // Input Transport Unit Size (in bits) + uint8_t out_tr_unit_sz; // Output Transport Unit Size (in bits) + uint16_t max_lat; // Max Latency (in ms) + uint16_t packet_type; // Packet Type + uint8_t retx_eff; // Retransmission Effort + + +}; + +/// HCI reject connection request command structure +/*@TRACE*/ +struct hci_reject_con_req_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Reason + uint8_t reason; +}; + +/// HCI reject synchronous connection request command structure +/*@TRACE*/ +struct hci_reject_sync_con_req_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Reason + uint8_t reason; +}; + +/// HCI link key request reply command structure +/*@TRACE*/ +struct hci_lk_req_reply_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Key + struct ltk key; +}; + +/// HCI link key request reply command structure +/*@TRACE*/ +struct hci_pin_code_req_reply_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Pin code length + uint8_t pin_len; + ///Key + struct pin_code pin; +}; + +/// HCI switch role command structure +/*@TRACE*/ +struct hci_switch_role_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Read all flag + uint8_t role; +}; + +/// HCI flow specification command parameters structure +/*@TRACE*/ +struct hci_flow_spec_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Flags + uint8_t flags; + ///Flow direction + uint8_t flow_dir; + ///Service type + uint8_t serv_type; + ///Token rate + uint32_t tk_rate; + ///Token buffer size + uint32_t tk_buf_sz; + ///Peak bandwidth + uint32_t pk_bw; + ///Access latency + uint32_t acc_lat; +}; + +/// HCI enhanced flush command parameters structure +/*@TRACE*/ +struct hci_enh_flush_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Packet Type + uint8_t pkt_type; +}; + +/// HCI command complete event structure for the read auto flush TO command +struct hci_rd_auto_flush_to_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Flush timeout + uint16_t flush_to; +}; + +/// HCI write flush timeout command parameters structure +/*@TRACE*/ +struct hci_wr_auto_flush_to_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Flush timeout + uint16_t flush_to; +}; + +/// HCI change connection packet type command parameters structure +/*@TRACE*/ +struct hci_chg_con_pkt_type_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Packet type + uint16_t pkt_type; +}; + +/// HCI read link policy settings command parameters structure +/*@TRACE*/ +struct hci_rd_link_pol_stg_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Link policy + uint16_t lnk_policy; +}; + +/// HCI read link policy settings command parameters structure +/*@TRACE*/ +struct hci_wr_link_pol_stg_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Link policy + uint16_t lnk_policy; +}; + +/// HCI sniff mode request command parameters structure +/*@TRACE*/ +struct hci_sniff_mode_cmd +{ + ///Connection handle + uint16_t conhdl; + /// Maximum interval (in slots) + uint16_t max_int; + /// Minimum interval (in slots) + uint16_t min_int; + /// Attempts (number of receive slots) (in slots) + uint16_t attempt; + /// Timeout (number of receive slots) (in slots) + uint16_t timeout; +}; + +/// HCI sniff subrating mode request command parameters structure +/*@TRACE*/ +struct hci_sniff_sub_cmd +{ + ///Connection handle + uint16_t conhdl; + /// Maximum latency used to calculate the maximum sniff subrate that the remote device may use (in slots) + uint16_t max_lat; + /// Minimum base sniff subrate timeout that the remote device may use (in slots) + uint16_t min_rem_to; + /// Minimum base sniff subrate timeout that the local device may use (in slots) + uint16_t min_loc_to; +}; + +/// HCI role discovery complete event parameters structure +/*@TRACE*/ +struct hci_role_discovery_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Role + uint8_t role; + +}; + +/// HCI read failed contact counter command parameters structure +/*@TRACE*/ +struct hci_rd_fail_contact_cnt_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Fail contact counter + uint16_t fail_cnt; +}; + +/// HCI read link quality complete event parameters structure +/*@TRACE*/ +struct hci_rd_link_qual_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Quality type + uint8_t quality; +}; + +/// HCI read afh channel map complete event parameters structure +/*@TRACE*/ +struct hci_rd_afh_ch_map_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + /// AFH mode + uint8_t afh_mode; + /// AFH channel map + struct chnl_map afh_map; +}; + +/// HCI read lmp handle complete event parameters structure +/*@TRACE*/ +struct hci_rd_lmp_hdl_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///lmp handle + uint8_t lmp_hdl; + ///rsvd + uint32_t rsvd; +}; + +/// HCI read remote extended features command parameters structure +/*@TRACE*/ +struct hci_rd_rem_ext_feats_cmd +{ + ///Connection handle + uint16_t conhdl; + ///page number + uint8_t pg_nb; +}; + +/// HCI read encryption key size complete event parameters structure +/*@TRACE*/ +struct hci_rd_enc_key_size_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Key size + uint8_t key_sz; +}; + +/// HCI read enhanced transmit power command parameters structure +/*@TRACE*/ +struct hci_rd_enh_tx_pwr_lvl_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Type + uint8_t type; +}; + +/// HCI read enhanced transmit power complete event parameters structure +/*@TRACE*/ +struct hci_rd_enh_tx_pwr_lvl_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Transmit power GFSK + uint8_t pw_gfsk; + ///Transmit power DQPSK + uint8_t pw_dqpsk; + ///Transmit power 8DPSK + uint8_t pw_8dpsk; +}; + + +/* + * HCI LINK CONTROL COMMANDS PARAMETERS + **************************************************************************************** + */ + +/// Format of the message of the Group: LINK_CONTROL_COMMANDS +/// HCI Inquiry command parameters structure +/*@TRACE*/ +struct hci_inq_cmd +{ + ///Lap + struct lap lap; + ///Inquiry Length in units of 1.28 s + uint8_t inq_len; + ///Number of response + uint8_t nb_rsp; +}; +/*@TRACE*/ +struct hci_per_inq_mode_cmd +{ + ///Maximum period length + uint16_t max_per_len; + ///Minimum period length + uint16_t min_per_len; + ///lap + struct lap lap; + ///Inquiry length in units of 1.28 s + uint8_t inq_len; + ///Number of response + uint8_t nb_rsp; +}; +/*@TRACE*/ +struct hci_create_con_cmd +{ + /// BdAddr + struct bd_addr bd_addr; + /// Packet Type + uint16_t pkt_type; + /// Page Scan Repetition Mode + uint8_t page_scan_rep_mode; + /// Reserved + uint8_t rsvd; + /** + * Clock Offset + * + * Bits 14-0 : Bits 16-2 of CLKNslave-CLK + * Bit 15 : Clock_Offset_Valid_Flag + * Invalid Clock Offset = 0 + * Valid Clock Offset = 1 + */ + uint16_t clk_off; + /// Allow Switch + uint8_t switch_en; +}; + +/// HCI disconnect command structure +/*@TRACE*/ +struct hci_disconnect_cmd +{ + /// connection handle + uint16_t conhdl; + /// reason + uint8_t reason; +}; + +/// HCI master link key command structure +/*@TRACE*/ +struct hci_master_lk_cmd +{ + ///Key flag + uint8_t key_flag; +}; + +/// HCI authentication request command parameters structure +/*@TRACE*/ +struct hci_set_con_enc_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Encryption mode + uint8_t enc_en; +}; + +/*@TRACE*/ +struct hci_rem_name_req_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Page Scan Repetition Mode + uint8_t page_scan_rep_mode; + ///Reserved + uint8_t rsvd; + /** + * Clock Offset + * + * Bits 14-0 : Bits 16-2 of CLKNslave-CLK + * Bit 15 : Clock_Offset_Valid_Flag + * Invalid Clock Offset = 0 + * Valid Clock Offset = 1 + */ + uint16_t clk_off; +}; + +/// HCI remote name request complete event structure +/*@TRACE*/ +struct hci_rem_name_req_cmp_evt +{ + /// Status + uint8_t status; + /// BD Addr + struct bd_addr bd_addr; + /// Name + struct device_name name; +}; + +/// HCI setup synchronous connection command structure +/*@TRACE*/ +struct hci_setup_sync_con_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Transmit bandwidth + uint32_t tx_bw; + ///Receive bandwidth + uint32_t rx_bw; + ///Max latency + uint16_t max_lat; + ///Voice setting + uint16_t vx_set; + ///Retransmission effort + uint8_t retx_eff; + ///Packet type + uint16_t pkt_type; +}; + +/// HCI setup synchronous connection command structure +/*@TRACE*/ +struct hci_enh_setup_sync_con_cmd +{ + uint16_t conhdl; // Connection Handle + uint32_t tx_bw; // Transmit Bandwidth (in B/sec) + uint32_t rx_bw; // Receive Bandwidth (in B/sec) + uint8_t tx_cod_fmt[5]; // Transmit Coding Format + uint8_t rx_cod_fmt[5]; // Receive Coding Format + uint16_t tx_cod_fr_sz; // Transmit Codec Frame Size (in B) + uint16_t rx_cod_fr_sz; // Receive Codec Frame Size (in B) + uint32_t in_bw; // Input Bandwidth (in B/sec) + uint32_t out_bw; // Output Bandwidth (in B/sec) + uint8_t in_cod_fmt[5]; // Input Coding Format + uint8_t out_cod_fmt[5]; // Output Coding Format + uint16_t in_cod_data_sz; // Input Coded Data Size (in bits) + uint16_t out_cod_data_sz; // Output Coded Data Size (in bits) + uint8_t in_data_fmt; // Input PCM Data Format + uint8_t out_data_fmt; // Output PCM Data Format + uint8_t in_msb_pos; // Input PCM Sample Payload MSB Position (in bits) + uint8_t out_msb_pos; // Output PCM Sample Payload MSB Position (in bits) + uint8_t in_data_path; // Input Data Path + uint8_t out_data_path; // Output Data Path + uint8_t in_tr_unit_sz; // Input Transport Unit Size (in bits) + uint8_t out_tr_unit_sz; // Output Transport Unit Size (in bits) + uint16_t max_lat; // Max Latency (in ms) + uint16_t packet_type; // Packet Type + uint8_t retx_eff; // Retransmission Effort +}; + +/// HCI io capability request reply command structure +/*@TRACE*/ +struct hci_io_cap_req_reply_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///IO capability + uint8_t io_capa; + ///OOB data present + uint8_t oob_data_pres; + ///Authentication requirements + uint8_t auth_req; + +}; + +/// HCI io capability request negative reply command structure +/*@TRACE*/ +struct hci_io_cap_req_neg_reply_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Reason + uint8_t reason; +}; + +/// HCI user pass key request reply command structure +/*@TRACE*/ +struct hci_user_passkey_req_reply_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Numeric value + uint32_t num_val; +}; + +/// HCI remote oob data request reply command structure +/*@TRACE*/ +struct hci_rem_oob_data_req_reply_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///hash part + struct hash oob_c; + ///random part + struct randomizer oob_r; +}; + +/// HCI send key press notification command structure +/*@TRACE*/ +struct hci_send_keypress_notif_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Notification type + uint8_t notif_type; +}; + +/// HCI truncated page command structure +/*@TRACE*/ +struct hci_trunc_page_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + /// Page Scan Repetition Mode + uint8_t page_scan_rep_mode; + /** + * Clock Offset + * + * Bits 14-0 : Bits 16-2 of CLKNslave-CLK + * Bit 15 : Clock_Offset_Valid_Flag + * Invalid Clock Offset = 0 + * Valid Clock Offset = 1 + */ + uint16_t clk_off; +}; + +/// HCI truncated page cancel command structure +/*@TRACE*/ +struct hci_trunc_page_can_cmd +{ + ///BdAddr + struct bd_addr bd_addr; +}; + +/// HCI set connectionless slave broadcast command structure +/*@TRACE*/ +struct hci_set_con_slv_bcst_cmd +{ + /// Enable + uint8_t enable; + /// LT_ADDR + uint8_t lt_addr; + /// LPO_Allowed + uint8_t lpo_allowed; + /// Packet_Type + uint16_t packet_type; + /// Interval_Min (in slots) + uint16_t interval_min; + /// Interval_Max (in slots) + uint16_t interval_max; + /// CSB_supervisionTO (in slots) + uint16_t csb_supv_to; +}; + +/// HCI set connectionless slave broadcast command complete event structure +/*@TRACE*/ +struct hci_set_con_slv_bcst_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// LT_ADDR + uint8_t lt_addr; + /// Interval (in slots) + uint16_t interval; +}; + +/// HCI set connectionless slave broadcast receive command structure +/*@TRACE*/ +struct hci_set_con_slv_bcst_rec_cmd +{ + /// Enable + uint8_t enable; + /// BD_ADDR + struct bd_addr bd_addr; + /// LT_ADDR + uint8_t lt_addr; + /// Interval (in slots) + uint16_t interval; + /// Clock_Offset (28 bits) - (CLKNslave - CLK) modulo 2^28 + uint32_t clock_offset; + /// Next_Connectionless_Slave_Broadcast_Clock (28 bits) + uint32_t next_csb_clock; + /// CSB_supervisionTO (in slots) + uint16_t csb_supv_to; + /// Remote_Timing_Accuracy (in ppm) + uint8_t remote_timing_accuracy; + /// Skip + uint8_t skip; + /// Packet_Type + uint16_t packet_type; + /// AFH_Channel_Map + struct chnl_map afh_ch_map; +}; + +/// HCI set connectionless slave broadcast receive command complete event structure +/*@TRACE*/ +struct hci_set_con_slv_bcst_rec_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// BD_ADDR + struct bd_addr bd_addr; + /// LT_ADDR + uint8_t lt_addr; +}; + +/// HCI Receive Synchronization Train command structure +/*@TRACE*/ +struct hci_rec_sync_train_cmd +{ + /// BD_ADDR + struct bd_addr bd_addr; + /// Synchronization_scanTO (in slots) + uint16_t sync_scan_to; + /// Sync_Scan_Window (in slots) + uint16_t sync_scan_win; + /// Sync_Scan_Interval (in slots) + uint16_t sync_scan_int; +}; + +/// HCI remote oob extended data request reply command structure +/*@TRACE*/ +struct hci_rem_oob_ext_data_req_reply_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///hash part + struct hash oob_c_192; + ///random part + struct randomizer oob_r_192; + ///hash part + struct hash oob_c_256; + ///random part + struct randomizer oob_r_256; +}; + +/*@TRACE*/ +struct hci_le_gen_dhkey_v1_cmd +{ + /// Remote P-256 public key + uint8_t public_key[64]; +}; + +/*@TRACE*/ +struct hci_le_gen_dhkey_v2_cmd +{ + /// Remote P-256 public key + uint8_t public_key[64]; + + /// Private key type (@see enum priv_key_type) + uint8_t key_type; +}; + +/*@TRACE*/ +struct hci_le_mod_sleep_clk_acc_cmd +{ + /// Switch to more or less accurate clock (@see enum clk_acc_action) + uint8_t action; +}; + + +/* + * HCI LINK POLICY COMMANDS PARAMETERS + **************************************************************************************** + */ + +/// HCI setup quality of service command structure +/*@TRACE*/ +struct hci_qos_setup_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Flags + uint8_t flags; + ///Service type + uint8_t serv_type; + ///Token rate + uint32_t tok_rate; + ///Peak bandwidth + uint32_t pk_bw; + ///Latency + uint32_t lat; + ///Delay variation + uint32_t del_var; +}; + +/// HCI command complete event structure for read default link policy command structure +/*@TRACE*/ +struct hci_rd_dft_link_pol_stg_cmd_cmp_evt +{ + ///Status of the command reception + uint8_t status; + ///Link policy + uint16_t link_pol_stg; +}; + +/*@TRACE*/ +struct hci_wr_dft_link_pol_stg_cmd +{ + ///Link policy + uint16_t link_pol_stg; +}; + +/* + * HCI CONTROL & BASEBAND COMMANDS PARAMETERS + **************************************************************************************** + */ + +/// HCI set event mask command structure +/*@TRACE*/ +struct hci_set_evt_mask_cmd +{ + ///Event Mask + struct evt_mask event_mask; +}; + +/// HCI set event filter command structure +/*@TRACE*/ +struct hci_set_evt_filter_cmd +{ + /// Filter type + uint8_t filter_type; + + /// Filters + union hci_filter + { + uint8_t clear_all_filter_reserved; + + /// Inquiry Result Filter + struct inq_res_filter + { + /// Filter Condition type + uint8_t cond_type; + + /// Filter conditions + union hci_inq_filter_cond + { + /// Reserved value (Inquiry Result Filter - condition type 0x00 has no condition) + uint8_t cond_0_reserved; + + /// Inquiry Result Filter Condition - condition type 0x01 + struct inq_res_filter_cond_1 + { + /// Class_of_Device + struct devclass class_of_dev; + /// Class_of_Device_Mask + struct devclass class_of_dev_msk; + } cond_1; + + /// Inquiry Result Filter Condition - condition type 0x02 + struct inq_res_filter_cond_2 + { + /// BD Address + struct bd_addr bd_addr; + } cond_2; + } cond; + } inq_res; + + /// Connection Setup Filter + struct con_set_filter + { + /// Filter Condition type + uint8_t cond_type; + + /// Filter conditions + union hci_con_filter_cond + { + /// Connection Setup Filter Condition - condition type 0x00 + struct con_set_filter_cond_0 + { + /// Auto_Accept_Flag + uint8_t auto_accept; + } cond_0; + + /// Connection Setup Filter Condition - condition type 0x01 + struct con_set_filter_cond_1 + { + /// Class_of_Device + struct devclass class_of_dev; + /// Class_of_Device_Mask + struct devclass class_of_dev_msk; + /// Auto_Accept_Flag + uint8_t auto_accept; + } cond_1; + + /// Connection Setup Filter Condition - condition type 0x02 + struct con_set_filter_cond_2 + { + /// BD Address + struct bd_addr bd_addr; + /// Auto_Accept_Flag + uint8_t auto_accept; + } cond_2; + } cond; + + } con_set; + + } filter; +}; + +/// HCI command completed event structure for the flush command +/*@TRACE*/ +struct hci_flush_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; +}; + +/// HCI command complete event structure for the Read pin type command +/*@TRACE*/ +struct hci_rd_pin_type_cmd_cmp_evt +{ + ///Status of the command + uint8_t status; + ///PIN type + uint8_t pin_type; +}; + +/*@TRACE*/ +struct hci_wr_pin_type_cmd +{ + ///PIN type + uint8_t pin_type; +}; + +/*@TRACE*/ +struct hci_rd_stored_lk_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Read all flag + uint8_t rd_all_flag; +}; + +/// HCI command complete event structure for read stored link key command +/*@TRACE*/ +struct hci_rd_stored_lk_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Maximum number of key + uint16_t num_key_max; + ///Read number of key + uint16_t num_key_rd; +}; + +#if BT_EMB_PRESENT +/*@TRACE*/ +struct hci_wr_stored_lk_cmd +{ + /// Number of key to write + uint8_t num_key_wr; + + /// BD Address + Key table + struct bd_addr_plus_key link_keys[HCI_MAX_CMD_PARAM_SIZE / sizeof(struct bd_addr_plus_key)]; +}; +#endif //BT_EMB_PRESENT + +/// HCI command complete event structure for write stored link key command +/*@TRACE*/ +struct hci_wr_stored_lk_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///number of key written + uint8_t num_key_wr; +}; + +/*@TRACE*/ +struct hci_del_stored_lk_cmd +{ + ///BdAddr + struct bd_addr bd_addr; + ///Delete all flag + uint8_t del_all_flag; +}; + +/// HCI command complete event structure for delete stored link key command +/*@TRACE*/ +struct hci_del_stored_lk_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Read number of key + uint16_t num_key_del; +}; + +/*@TRACE*/ +struct hci_wr_local_name_cmd +{ + ///Name + struct device_name name; +}; + +/// HCI command complete event structure for the read local name command +/*@TRACE*/ +struct hci_rd_local_name_cmd_cmp_evt +{ + ///Status of the command + uint8_t status; + ///Name + uint8_t name[BD_NAME_SIZE]; +}; + +/// HCI command complete event structure for the Read connection accept to command +/*@TRACE*/ +struct hci_rd_con_accept_to_cmd_cmp_evt +{ + ///Status of the command + uint8_t status; + /// Connection accept timeout (in slots) + uint16_t con_acc_to; +}; + +/*@TRACE*/ +struct hci_wr_con_accept_to_cmd +{ + /// Connection accept timeout (in slots) + uint16_t con_acc_to; +}; + +/// HCI command complete event structure for the Read page to command +/*@TRACE*/ +struct hci_rd_page_to_cmd_cmp_evt +{ + ///Status of the command + uint8_t status; + /// Page timeout (in slots) + uint16_t page_to; +}; + +/*@TRACE*/ +struct hci_wr_page_to_cmd +{ + /// Page timeout (in slots) + uint16_t page_to; +}; + +/// HCI command complete event structure for the Read scan enable command +/*@TRACE*/ +struct hci_rd_scan_en_cmd_cmp_evt +{ + ///Status of the command + uint8_t status; + ///Status of the scan enable + uint8_t scan_en; +}; + +/*@TRACE*/ +struct hci_wr_scan_en_cmd +{ + ///Status of the scan enable + uint8_t scan_en; +}; + +/// HCI command complete event structure for the Read scan activity command +/*@TRACE*/ +struct hci_rd_page_scan_act_cmd_cmp_evt +{ + ///Status of the command + uint8_t status; + /// Page scan interval (in slots) + uint16_t page_scan_intv; + /// Page scan window (in slots) + uint16_t page_scan_win; +}; + +/*@TRACE*/ +struct hci_wr_page_scan_act_cmd +{ + /// Page scan interval (in slots) + uint16_t page_scan_intv; + /// Page scan window (in slots) + uint16_t page_scan_win; +}; + +/// HCI command complete event structure for the Read inquiry scan activity command +/*@TRACE*/ +struct hci_rd_inq_scan_act_cmd_cmp_evt +{ + /// Status of the command + uint8_t status; + /// Inquiry scan interval (in slots) + uint16_t inq_scan_intv; + /// Inquiry scan window (in slots) + uint16_t inq_scan_win; +}; + +/*@TRACE*/ +struct hci_wr_inq_scan_act_cmd +{ + /// Inquiry scan interval (in slots) + uint16_t inq_scan_intv; + /// Inquiry scan window (in slots) + uint16_t inq_scan_win; +}; + +/// HCI command complete event structure for the Read authentication command +/*@TRACE*/ +struct hci_rd_auth_en_cmd_cmp_evt +{ + ///Status of the command + uint8_t status; + ///Value of the authentication + uint8_t auth_en; +}; + +/*@TRACE*/ +struct hci_wr_auth_en_cmd +{ + ///Value of the authentication + uint8_t auth_en; +}; + +/// HCI command complete event structure for the read class of device command +/*@TRACE*/ +struct hci_rd_class_of_dev_cmd_cmp_evt +{ + ///Status of the command + uint8_t status; + ///Class of device + struct devclass class_of_dev; +}; + +/*@TRACE*/ +struct hci_wr_class_of_dev_cmd +{ + ///Class of device + struct devclass class_of_dev; +}; + +/// HCI read voice settings complete event +/*@TRACE*/ +struct hci_rd_voice_stg_cmd_cmp_evt +{ + ///Status of the command reception + uint8_t status; + /// Voice setting + uint16_t voice_stg; +}; + +/*@TRACE*/ +struct hci_wr_voice_stg_cmd +{ + /// voice setting + uint16_t voice_stg; +}; + +/// HCI command complete event structure for read number of broadcast retrans command +/*@TRACE*/ +struct hci_rd_nb_bdcst_retx_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Read number of broadcast retransmission + uint8_t num_bcst_ret; +}; + +/*@TRACE*/ +struct hci_wr_nb_bdcst_retx_cmd +{ + ///Read number of broadcast retransmission + uint8_t num_bcst_ret; +}; + +/// HCI command complete event structure for the Read Synchronous Flow Control command +/*@TRACE*/ +struct hci_rd_sync_flow_ctrl_en_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Synchronous flow control enable + uint8_t sync_flow_ctrl_en; +}; + +/*@TRACE*/ +struct hci_wr_sync_flow_ctrl_en_cmd +{ + /// Synchronous Flow Control enable + uint8_t sync_flow_ctrl_en; +}; + +///HCI set controller to host flow control command +/*@TRACE*/ +struct hci_set_ctrl_to_host_flow_ctrl_cmd +{ + ///Flow control enable for controller + uint8_t flow_cntl; +}; + +///HCI host buffer size command +/*@TRACE*/ +struct hci_host_buf_size_cmd +{ + ///Host ACL packet length + uint16_t acl_pkt_len; + ///Host synchronous packet length + uint8_t sync_pkt_len; + ///Host Total number of ACL packets allowed + uint16_t nb_acl_pkts; + ///Host total number of synchronous packets allowed + uint16_t nb_sync_pkts; +}; + +#if BT_EMB_PRESENT +///HCI host number of completed packets command +/*@TRACE*/ +struct hci_host_nb_cmp_pkts_cmd +{ + ///Number of handles for which the completed packets number is given + uint8_t nb_of_hdl; + ///Array of connection handles + uint16_t con_hdl[MAX_NB_ACTIVE_ACL]; + ///Array of number of completed packets values for connection handles. + uint16_t nb_comp_pkt[MAX_NB_ACTIVE_ACL]; +}; +#elif BLE_EMB_PRESENT || BLE_HOST_PRESENT +///HCI host number of completed packets command +/*@TRACE*/ +struct hci_host_nb_cmp_pkts_cmd +{ + ///Number of handles for which the completed packets number is given + uint8_t nb_of_hdl; + ///Array of connection handles + uint16_t con_hdl[BLE_ACTIVITY_MAX+1]; // ensure that at least 1 element is present + ///Array of number of completed packets values for connection handles. + uint16_t nb_comp_pkt[BLE_ACTIVITY_MAX+1]; // ensure that at least 1 element is present +}; +#endif //BLE_EMB_PRESENT || BLE_HOST_PRESENT + +/// HCI read link supervision timeout command parameters structure +struct hci_rd_link_supv_to_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Link supervision timeout + uint16_t lsto_val; +}; + +/// HCI write link supervision timeout command parameters structure +/*@TRACE*/ +struct hci_wr_link_supv_to_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Link supervision timeout + uint16_t lsto_val; +}; + +/// HCI command complete event structure for the nb of supported IAC command +/*@TRACE*/ +struct hci_rd_nb_supp_iac_cmd_cmp_evt +{ + ///Status of the command + uint8_t status; + ///nb_of iac + uint8_t nb_iac; +}; + +/// HCI command complete event structure for read current IAC LAP command +/*@TRACE*/ +struct hci_rd_curr_iac_lap_cmd_cmp_evt +{ + ///Status of the command + uint8_t status; + ///nb of current iac + uint8_t nb_curr_iac; + ///lap + struct lap iac_lap; +}; + +/// HCI write current IAC LAP command structure +/*@TRACE*/ +struct hci_wr_curr_iac_lap_cmd +{ + /// Number of current iac laps + uint8_t nb_curr_iac; + ///lap + struct lap iac_lap[(HCI_MAX_CMD_PARAM_SIZE / BD_ADDR_LAP_LEN) - 1]; +}; + +/*@TRACE*/ +struct hci_set_afh_host_ch_class_cmd +{ + ///AFH channel map + struct chnl_map afh_ch; +}; + +/// HCI command complete event structure for write inquiry scan type command structure +/*@TRACE*/ +struct hci_rd_inq_scan_type_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + /// Inquiry scan type + uint8_t inq_scan_type; +}; + +/*@TRACE*/ +struct hci_wr_inq_scan_type_cmd +{ + /// Inquiry scan type + uint8_t inq_scan_type; +}; + +/// HCI command complete event structure for read inquiry mode command structure +/*@TRACE*/ +struct hci_rd_inq_mode_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + /// Inquiry mode + uint8_t inq_mode; +}; + +/*@TRACE*/ +struct hci_wr_inq_mode_cmd +{ + /// Inquiry mode + uint8_t inq_mode; +}; + +/// HCI command complete event structure for write page scan type command structure +/*@TRACE*/ +struct hci_rd_page_scan_type_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + /// Page scan type + uint8_t page_scan_type; +}; + +/*@TRACE*/ +struct hci_wr_page_scan_type_cmd +{ + /// Page scan type + uint8_t page_scan_type; +}; + +/// HCI command complete event structure for read assessment mode command structure +/*@TRACE*/ +struct hci_rd_afh_ch_assess_mode_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///AFH channel assessment mode + uint8_t afh_ch_ass_mode; +}; + +/*@TRACE*/ +struct hci_wr_afh_ch_assess_mode_cmd +{ + ///AFH channel assessment mode + uint8_t afh_ch_ass_mode; +}; + +/// HCI command complete event structure for remote name request cancel command +/*@TRACE*/ +struct hci_rd_ext_inq_rsp_cmd_cmp_evt +{ + ///status + uint8_t status; + ///FEC required + uint8_t fec_req; + ///Extended inquiry response + struct eir eir; +}; + +/*@TRACE*/ +struct hci_wr_ext_inq_rsp_cmd +{ + ///FEC required + uint8_t fec_req; + ///Extended inquiry response + struct eir eir; +}; + +/// HCI command complete event structure for remote name request cancel command +/*@TRACE*/ +struct hci_rd_sp_mode_cmd_cmp_evt +{ + ///status + uint8_t status; + ///Simple pairing mode + uint8_t sp_mode; +}; + +/*@TRACE*/ +struct hci_wr_sp_mode_cmd +{ + ///Simple pairing mode + uint8_t sp_mode; +}; + +/// HCI command complete event structure for read oob data command +/*@TRACE*/ +struct hci_rd_loc_oob_data_cmd_cmp_evt +{ + ///status + uint8_t status; + ///hash part + struct hash oob_c; + ///random part + struct randomizer oob_r; +}; + +/// HCI command complete event structure for read inquiry response transmit power command +/*@TRACE*/ +struct hci_rd_inq_rsp_tx_pwr_lvl_cmd_cmp_evt +{ + ///status + uint8_t status; + ///TX power + uint8_t tx_pwr; +}; + +/*@TRACE*/ +struct hci_wr_inq_tx_pwr_lvl_cmd +{ + ///TX power + int8_t tx_pwr; +}; + +/// HCI command complete event structure for read erroneous data reporting command +/*@TRACE*/ +struct hci_rd_dft_err_data_rep_cmd_cmp_evt +{ + ///status + uint8_t status; + ///Erroneous data reporting + uint8_t err_data_rep; +}; + +/*@TRACE*/ +struct hci_wr_dft_err_data_rep_cmd +{ + ///Erroneous data reporting + uint8_t err_data_rep; +}; + +/// HCI read LE Host Supported complete event +/*@TRACE*/ +struct hci_rd_le_host_supp_cmd_cmp_evt +{ + ///Status + uint8_t status; + ///LE_Supported_Host + uint8_t le_supported_host; + ///Simultaneous_LE_Host + uint8_t simultaneous_le_host; +}; + +/// HCI write LE Host Supported command +/*@TRACE*/ +struct hci_wr_le_host_supp_cmd +{ + ///LE_Supported_Host + uint8_t le_supported_host; + ///Simultaneous_LE_Host + uint8_t simultaneous_le_host; +}; + +/// HCI Set MWS Channel Parameters command +/*@TRACE*/ +struct hci_set_mws_channel_params_cmd +{ + ///MWS_Channel_Enable + uint8_t mws_channel_enable; + ///MWS_RX_Center_Frequency + uint16_t mws_rx_center_frequency; + ///MWS_TX_Center_Frequency + uint16_t mws_tx_center_frequency; + ///MWS_RX_Channel_Bandwidth + uint16_t mws_rx_channel_bandwidth; + ///MWS_TX_Channel_Bandwidth + uint16_t mws_tx_channel_bandwidth; + ///MWS_Channel_Type + uint8_t mws_channel_type; +}; + +/// HCI Set External Frame Configuration command +/*@TRACE*/ +struct hci_set_external_frame_config_cmd +{ + /// Ext_Frame_Duration + uint16_t ext_fr_duration; + /// Ext_Frame_Sync_Assert_Offset + int16_t ext_fr_sync_assert_offset; + /// Ext_Frame_Sync_Assert_Jitter + uint16_t ext_fr_sync_assert_jitter; + /// Ext_Frame_Num_Periods + uint8_t ext_fr_num_periods; + /// Period Durations & Types + struct ext_fr_period period[1/*__ARRAY_EMPTY*/]; +}; + +/// HCI Set MWS Signaling command +/*@TRACE*/ +struct hci_set_mws_signaling_cmd +{ + ///MWS_RX_Assert_Offset + int16_t mws_rx_assert_offset; + ///MWS_RX_Assert_Jitter + uint16_t mws_rx_assert_jitter; + ///MWS_RX_Deassert_Offset + int16_t mws_rx_deassert_offset; + ///MWS_RX_Deassert_Jitter + uint16_t mws_rx_deassert_jitter; + ///MWS_TX_Assert_Offset + int16_t mws_tx_assert_offset; + ///MWS_TX_Assert_Jitter + uint16_t mws_tx_assert_jitter; + ///MWS_TX_Deassert_Offset + int16_t mws_tx_deassert_offset; + ///MWS_TX_Deassert_Jitter + uint16_t mws_tx_deassert_jitter; + ///MWS_Pattern_Assert_Offset + int16_t mws_pattern_assert_offset; + ///MWS_Pattern_Assert_Jitter + uint16_t mws_pattern_assert_jitter; + ///MWS_Inactivity_Duration_Assert_Offset + int16_t mws_inactivity_duration_assert_offset; + ///MWS_Inactivity_Duration_Assert_Jitter + uint16_t mws_inactivity_duration_assert_jitter; + ///MWS_Scan_Frequency_Assert_Offset + int16_t mws_scan_frequency_assert_offset; + ///MWS_Scan_Frequency_Assert_Jitter + uint16_t mws_scan_frequency_assert_jitter; + ///MWS_Priority_Assert_Offset_Request + uint16_t mws_priority_assert_offset_request; +}; + +/// HCI Set MWS Signaling command complete event +/*@TRACE*/ +struct hci_set_mws_signaling_cmd_cmp_evt +{ + ///Status + uint8_t status; + ///Bluetooth_Rx_Priority_Assert_Offset + int16_t bt_rx_prio_assert_offset; + ///Bluetooth_Rx_Priority_Assert_Jitter + uint16_t bt_rx_prio_assert_jitter; + ///Bluetooth_Rx_Priority_Deassert_Offset + int16_t bt_rx_prio_deassert_offset; + ///Bluetooth_Rx_Priority_Deassert_Jitter + uint16_t bt_rx_prio_deassert_jitter; + ///802_Rx_Priority_Assert_Offset + int16_t _802_rx_prio_assert_offset; + ///802_Rx_Priority_Assert_Jitter + uint16_t _802_rx_prio_assert_jitter; + ///802_Rx_Priority_Deassert_Offset + int16_t _802_rx_prio_deasssert_offset; + ///802_Rx_Priority_Deassert_Jitter + uint16_t _802_rx_prio_deassert_jitter; + ///Bluetooth_Tx_On_Assert_Offset + int16_t bt_tx_on_assert_offset; + ///Bluetooth_Tx_On_Assert_Jitter + uint16_t bt_tx_on_assert_jitter; + ///Bluetooth_Tx_On_Deassert_Offset + int16_t bt_tx_on_deassert_offset; + ///Bluetooth_Tx_On_Deassert_Jitter + uint16_t bt_tx_on_deassert_jitter; + ///802_Tx_On_Assert_Offset + int16_t _802_tx_on_assert_offset; + ///802_Tx_On_Assert_Jitter + uint16_t _802_tx_on_assert_jitter; + ///802_Tx_On_Deassert_Offset + int16_t _802_tx_on_deassert_offset; + ///802_Tx_On_Deassert_Jitter + uint16_t _802_tx_on_deassert_jitter; +}; + +/// HCI Set MWS Transport Layer command +/*@TRACE*/ +struct hci_set_mws_transport_layer_cmd +{ + ///Transport_Layer + uint8_t transport_layer; + ///To_MWS_Baud_Rate + uint32_t to_mws_baud_rate; + ///From_MWS_Baud_Rate + uint32_t from_mws_baud_rate; +}; + +/// HCI Set MWS Scan Frequency Table command +/*@TRACE*/ +struct hci_set_mws_scan_freq_table_cmd +{ + ///Num_Scan_Frequencies + uint8_t num_scan_frequencies; + ///Scan_Frequencys Low & High + struct mws_scan_freq scan_freq[1/*__ARRAY_EMPTY*/]; +}; + +/// HCI Set MWS Pattern Configuration command +/*@TRACE*/ +struct hci_set_mws_pattern_config_cmd +{ + ///MWS_PATTERN_Index + uint8_t mws_pattern_index; + ///MWS_PATTERN_NumIntervals + uint8_t num_intervals; + ///MWS_PATTERN_Interval Duration & Type + struct mws_pattern_intv intv[1/*__ARRAY_EMPTY*/]; +}; + +/// Hci Get MWS Transport Layer Configuration command complete event +/*@TRACE*/ +struct hci_get_mws_transport_layer_config_cmd_cmp_evt +{ + ///Status + uint8_t status; + ///Num_Transports + uint8_t num_transports; + ///Transport_Layers + struct mws_transport tran[1/*__ARRAY_EMPTY*/]; +}; + +/// HCI read Secure Connections Host Support complete event +/*@TRACE*/ +struct hci_rd_sec_con_host_supp_cmd_cmp_evt +{ + ///Status + uint8_t status; + /// Secure Connections Host Support + uint8_t sec_con_host_supp; +}; + +/// HCI write Secure Connections Host Support command +/*@TRACE*/ +struct hci_wr_sec_con_host_supp_cmd +{ + /// Secure Connections Host Support + uint8_t sec_con_host_supp; +}; + +/// HCI write Secure Connections Test Mode command +struct hci_wr_sec_con_test_mode_cmd +{ + /// Connection handle + uint16_t conhdl; + /// DM1 ACL-U mode (0: disabled | 1: enabled) + uint8_t dm1_acl_u_mode; + /// eSCO loopback mode (0: disabled | 1: enabled) + uint8_t esco_loopback_mode; +}; + +/// HCI write Secure Connections Test Mode complete event +struct hci_wr_sec_con_test_mode_cmd_cmp_evt +{ + ///Status + uint8_t status; + /// Connection handle + uint16_t conhdl; +}; + +/// HCI Set Reserved LT_ADDR command +/*@TRACE*/ +struct hci_set_res_lt_addr_cmd +{ + /// LT_ADDR + uint8_t lt_addr; +}; + +/// HCI Set Reserved LT_ADDR command complete event +/*@TRACE*/ +struct hci_set_res_lt_addr_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// LT_ADDR + uint8_t lt_addr; +}; + +/// HCI Delete Reserved LT_ADDR command +/*@TRACE*/ +struct hci_del_res_lt_addr_cmd +{ + /// LT_ADDR + uint8_t lt_addr; +}; + +/// HCI Delete Reserved LT_ADDR command complete event +/*@TRACE*/ +struct hci_del_res_lt_addr_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// LT_ADDR + uint8_t lt_addr; +}; + +/// HCI Set Connectionless Slave Broadcast Data command +/*@TRACE*/ +struct hci_set_con_slv_bcst_data_cmd +{ + /// LT_ADDR + uint8_t lt_addr; + /// Fragment + uint8_t fragment; + /// Data_Length (in bytes) + uint8_t data_length; + /// Data + uint8_t data[__ARRAY_EMPTY]; +}; + +/// HCI Set Connectionless Slave Broadcast Data command complete event +/*@TRACE*/ +struct hci_set_con_slv_bcst_data_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// LT_ADDR + uint8_t lt_addr; +}; + +/// HCI Read Synchronization Train Parameters command complete event +/*@TRACE*/ +struct hci_rd_sync_train_param_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Sync_Train_Interval (in slots) + uint16_t sync_train_int; + /// synchronization_trainTO (in slots) + uint32_t sync_train_to; + /// Service_Data + uint8_t service_data; +}; + +/// HCI Write Synchronization Train Parameters command +/*@TRACE*/ +struct hci_wr_sync_train_param_cmd +{ + /// Interval_Min (in slots) + uint16_t int_min; + /// Interval_Max (in slots) + uint16_t int_max; + /// synchronization_trainTO (in slots) + uint32_t sync_train_to; + /// Service_Data + uint8_t service_data; +}; + +/// HCI Write Synchronization Train Parameters command complete event +/*@TRACE*/ +struct hci_wr_sync_train_param_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Sync_Train_Interval (in slots) + uint16_t sync_train_int; +}; + +// HCI Synchronization Train Complete event +struct hci_sync_train_cmp_evt +{ + /// Status + uint8_t status; +}; + +/// HCI read authenticated payload timeout command +/*@TRACE*/ +struct hci_rd_auth_payl_to_cmd +{ + ///Connection handle + uint16_t conhdl; +}; + +/// HCI command complete event structure for the Read Authenticated Payload Timeout Command +/*@TRACE*/ +struct hci_rd_auth_payl_to_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Authenticated payload timeout + uint16_t auth_payl_to; +}; + +/// HCI command complete event structure for read oob extended data command +/*@TRACE*/ +struct hci_rd_loc_oob_ext_data_cmd_cmp_evt +{ + ///status + uint8_t status; + ///hash part + struct hash oob_c_192; + ///random part + struct randomizer oob_r_192; + ///hash part + struct hash oob_c_256; + ///random part + struct randomizer oob_r_256; +}; + +/// HCI read Extended Page Timeout CC event +/*@TRACE*/ +struct hci_rd_ext_page_to_cmd_cmp_evt +{ + /// Status + uint8_t status; + /** + * Extended Page Timeout measured in Number of Baseband slots. Interval Length = N * 0.625 msec (1 Baseband slot) + * Range for N: 0x0000 (default) - 0xFFFF + * Time Range: 0 - 40.9 Seconds + */ + uint16_t ext_page_to; +}; + +/// HCI write Extended Page Timeout +/*@TRACE*/ +struct hci_wr_ext_page_to_cmd +{ + /** + * Extended Page Timeout measured in Number of Baseband slots. Interval Length = N * 0.625 msec (1 Baseband slot) + * Range for N: 0x0000 (default) - 0xFFFF + * Time Range: 0 - 40.9 Seconds + */ + uint16_t ext_page_to; +}; + +/// HCI read Extended Inquiry Length CC event +/*@TRACE*/ +struct hci_rd_ext_inq_len_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Extended Inquiry Length + uint16_t ext_inq_len; +}; + +/// HCI write Extended Inquiry Length +/*@TRACE*/ +struct hci_wr_ext_inq_len_cmd +{ + /// Extended Inquiry Length + uint16_t ext_inq_len; +}; + +/* + * HCI INFORMATIONAL PARAMETERS COMMANDS PARAMETERS + **************************************************************************************** + */ + +///HCI command complete event structure for read local version information +/*@TRACE*/ +struct hci_rd_local_ver_info_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///HCI version number + uint8_t hci_ver; + ///HCI revision number + uint16_t hci_rev; + ///LMP version + uint8_t lmp_ver; + ///manufacturer name + uint16_t manuf_name; + ///LMP Subversion + uint16_t lmp_subver; +}; + +///HCI command complete event structure for read local supported commands +/*@TRACE*/ +struct hci_rd_local_supp_cmds_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Supported Commands structure + struct supp_cmds local_cmds; +}; + +/// HCI command complete event structure for read local supported features command +/*@TRACE*/ +struct hci_rd_local_supp_feats_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Local supported features + struct features feats; +}; + +/*@TRACE*/ +struct hci_rd_local_ext_feats_cmd +{ + ///Page number + uint8_t page_nb; +}; + +/// HCI command complete event structure for read local extended features command +/*@TRACE*/ +struct hci_rd_local_ext_feats_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Page number + uint8_t page_nb; + ///Maximum page number + uint8_t page_nb_max; + ///Extended LMP features + struct features ext_feats; +}; + +///HCI command complete event structure for the Read Buffer Size Command +/*@TRACE*/ +struct hci_rd_buff_size_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///ACL data packet length controller can receive from host + uint16_t hc_data_pk_len; + ///Synchronous data packet length controller can receive from host + uint8_t hc_sync_pk_len; + ///Total number of ACL data packets controller can receive from host + uint16_t hc_tot_nb_data_pkts; + ///Total number of synchronous data packets controller can receive from host + uint16_t hc_tot_nb_sync_pkts; +}; + +///HCI command complete event structure for read bd address +/*@TRACE*/ +struct hci_rd_bd_addr_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///BD address + struct bd_addr local_addr; +}; + +/// HCI command complete event structure for read local supported codecs +/*@TRACE*/ +struct hci_rd_local_supp_codecs_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + uint8_t nb_supp_codecs; + uint8_t nb_supp_vendor_specific_codecs; + +// ///Supported Codecs structure +// struct supp_codecs local_codecs; +}; + +/// HCI command complete event structure for read local simple pairing options +struct hci_rd_local_sp_opt_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + /// Simple Pairing options (bit 0: Remote public key validation) + uint8_t sp_opt; + /// Maximum Encryption Key Size (in octets) + uint8_t max_enc_key_size; +}; + +/* + * HCI STATUS PARAMETERS COMMANDS PARAMETERS + **************************************************************************************** + */ + +/// HCI command complete event structure for read rssi +/*@TRACE*/ +struct hci_rd_rssi_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///RSSI value + uint8_t rssi; +}; + +/*@TRACE*/ +struct hci_rd_clk_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Which clock + uint8_t clk_type; +}; + +/// HCI read clock command structure +/*@TRACE*/ +struct hci_rd_clk_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///clock + uint32_t clk; + ///Accuracy + uint16_t clk_acc; +}; + + +/* + * HCI TESTING COMMANDS PARAMETERS + **************************************************************************************** + */ + +/// HCI command complete event structure for read loop back mode command +/*@TRACE*/ +struct hci_rd_loopback_mode_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Local supported features + uint8_t lb_mode; +}; + +/*@TRACE*/ +struct hci_wr_loopback_mode_cmd +{ + ///Local supported features + uint8_t lb_mode; +}; + +/*@TRACE*/ +struct hci_wr_sp_dbg_mode_cmd +{ + ///Simple pairing mode + uint8_t sp_mode; +}; + + +/* + * HCI LE CONTROLLER COMMANDS PARAMETERS + **************************************************************************************** + */ + +///HCI LE Set Event Mask Command parameters structure +/*@TRACE*/ +struct hci_le_set_evt_mask_cmd +{ + ///LE Event Mask + struct evt_mask le_mask; +}; + +///HCI LE Set Random Address Command parameters structure +/*@TRACE*/ +struct hci_le_set_rand_addr_cmd +{ + ///Random address to set + struct bd_addr rand_addr; +}; + +///HCI LE Set Advertising Parameters Command parameters structure +/*@TRACE*/ +struct hci_le_set_adv_param_cmd +{ + ///Minimum interval for advertising + uint16_t adv_intv_min; + ///Maximum interval for advertising + uint16_t adv_intv_max; + ///Advertising type + uint8_t adv_type; + ///Own address type: public=0 / random=1 / rpa_or_pub=2 / rpa_or_rnd=3 + uint8_t own_addr_type; + ///Peer address type: public=0 / random=1 + uint8_t peer_addr_type; + ///Peer Bluetooth device address + struct bd_addr peer_addr; + ///Advertising channel map + uint8_t adv_chnl_map; + ///Advertising filter policy + uint8_t adv_filt_policy; +}; + +///HCI LE Set Advertising Data Command parameters structure +/*@TRACE*/ +struct hci_le_set_adv_data_cmd +{ + ///Advertising data length + uint8_t adv_data_len; + ///Advertising data - maximum 31 bytes + struct adv_data data; +}; + +///HCI LE Set Scan Response Data Command parameters structure +/*@TRACE*/ +struct hci_le_set_scan_rsp_data_cmd +{ + ///Scan response data length + uint8_t scan_rsp_data_len; + ///Scan response data - maximum 31 bytes + struct scan_rsp_data data; +}; + +///HCI LE Set Advertise Enable Command parameters structure +/*@TRACE*/ +struct hci_le_set_adv_en_cmd +{ + ///Advertising enable - 0=disabled, 1=enabled + uint8_t adv_en; +}; + +///HCI LE Set Scan Parameters Command parameters structure +/*@TRACE*/ +struct hci_le_set_scan_param_cmd +{ + ///Scan type - 0=passive / 1=active + uint8_t scan_type; + ///Scan interval + uint16_t scan_intv; + ///Scan window size + uint16_t scan_window; + ///Own address type - public=0 / random=1 / rpa_or_pub=2 / rpa_or_rnd=3 + uint8_t own_addr_type; + ///Scan filter policy + uint8_t scan_filt_policy; +}; + +///HCI LE Set Scan Enable Command parameters structure +/*@TRACE*/ +struct hci_le_set_scan_en_cmd +{ + ///Scan enable - 0=disabled, 1=enabled + uint8_t scan_en; + ///Enable for duplicates filtering - 0 =disabled/ 1=enabled + uint8_t filter_duplic; +}; + +///HCI LE Create Connection Command parameters structure +/*@TRACE*/ +struct hci_le_create_con_cmd +{ + ///Scan interval (N * 0.625 ms) + uint16_t scan_intv; + ///Scan window size (N * 0.625 ms) + uint16_t scan_window; + ///Initiator filter policy + uint8_t init_filt_policy; + ///Peer address type - public=0 / random=1 / rpa_or_pub=2 / rpa_or_rnd=3 + uint8_t peer_addr_type; + ///Peer BD address + struct bd_addr peer_addr; + ///Own address type - public=0 / random=1 / rpa_or_pub=2 / rpa_or_rnd=3 + uint8_t own_addr_type; + ///Minimum of connection interval (N * 1.25 ms) + uint16_t con_intv_min; + ///Maximum of connection interval (N * 1.25 ms) + uint16_t con_intv_max; + ///Connection latency + uint16_t con_latency; + ///Link supervision timeout + uint16_t superv_to; + ///Minimum CE length (N * 0.625 ms) + uint16_t ce_len_min; + ///Maximum CE length (N * 0.625 ms) + uint16_t ce_len_max; +}; + +///HCI LE Add Device to White List Command parameters structure +/*@TRACE*/ +struct hci_le_add_dev_to_wlst_cmd +{ + ///Type of address of the device to be added to the White List - 0=public/1=random + uint8_t dev_addr_type; + ///Address of device to be added to White List + struct bd_addr dev_addr; +}; + +///HCI LE Remove Device from White List Command parameters structure +/*@TRACE*/ +struct hci_le_rmv_dev_from_wlst_cmd +{ + ///Type of address of the device to be removed from the White List - 0=public/1=random + uint8_t dev_addr_type; + ///Address of device to be removed from White List + struct bd_addr dev_addr; +}; + +///HCI LE Set Extended Scan Paramaters Command parameters structure +/*@TRACE*/ +struct hci_le_set_ext_scan_param_cmd +{ + ///Own address type public/random/rpa + uint8_t own_addr_type; + ///Scanning filter policy + uint8_t scan_filt_policy; + ///Indicates the PHY(s) on which the advertising packets should be received + uint8_t scan_phys; + ///Paramaters for PHY(s) + struct scan_phy_param + { + ///Scaning Type: passive/active + uint8_t scan_type; + ///Scan interval (slots) + uint16_t scan_intv; + ///Scan window size (slots) + uint16_t scan_window; + } phy[MAX_SCAN_PHYS]; +}; + +///HCI LE Set Extended Scan Enable Command parameters structure +/*@TRACE*/ +struct hci_le_set_ext_scan_en_cmd +{ + ///Scan enable - 0=disabled, 1=enabled + uint8_t scan_en; + ///Filter duplicates - 0=disabled, 1=enabled, 2=enabled & reset each scan period + uint8_t filter_duplic; + ///Scan duration (Time=N*10ms) | 0x0000: Scan continuously until explicitly disable + uint16_t duration; + ///Scan period (Time=N*1.28sec) | 0x0000: Periodic scanning disabled + uint16_t period; +}; + +/*@TRACE*/ +struct init_phy_param +{ + ///Scan interval (N * 0.625 ms) + uint16_t scan_interval; + ///Scan window size (N * 0.625 ms) + uint16_t scan_window; + ///Minimum of connection interval (N * 1.25 ms) + uint16_t con_intv_min; + ///Maximum of connection interval (N * 1.25 ms) + uint16_t con_intv_max; + ///Connection latency + uint16_t con_latency; + ///Link supervision timeout + uint16_t superv_to; + ///Minimum CE length (N * 0.625 ms) + uint16_t ce_len_min; + ///Maximum CE length (N * 0.625 ms) + uint16_t ce_len_max; +}; + +///HCI LE Extended Create Connection Command parameters structure +/*@TRACE*/ +struct hci_le_ext_create_con_cmd +{ + ///Initiator filter policy + uint8_t init_filter_policy; + ///Own address type public/random/rpa + uint8_t own_addr_type; + ///Peer address type public/random/rpa + uint8_t peer_addr_type; + ///Peer address + struct bd_addr peer_addr; + ///Indicates the PHY(s) on which the advertising packets should be received + uint8_t init_phys; + ///Paramaters for PHY(s) + struct init_phy_param phy[MAX_INIT_PHYS]; +}; + +///HCI LE Periodic Advertising Create Sync Command parameters structure +/*@TRACE*/ +struct hci_le_per_adv_create_sync_cmd +{ + /// Options (@see enum per_sync_opt) + uint8_t options; + ///Advertising SID + uint8_t adv_sid; + ///Advertising address type + uint8_t adv_addr_type; + ///Advertiser address + struct bd_addr adv_addr; + ///max Skip after receive + uint16_t skip; + ///Sync timeout (Time=N*10ms) + uint16_t sync_to; + /// Sync CTE type (@see enum sync_cte_type) + uint8_t sync_cte_type; +}; + +///HCI LE Periodic Advertising Terminate Sync Command parameters structure +/*@TRACE*/ +struct hci_le_per_adv_term_sync_cmd +{ + ///Sync handle + uint16_t sync_handle; +}; + +///HCI LE Add Device to Periodic Advertiser List Command parameters structure +/*@TRACE*/ +struct hci_le_add_dev_to_per_adv_list_cmd +{ + ///Advertiser address type + uint8_t adv_addr_type; + ///Advertiser address + struct bd_addr adv_addr; + ///Advertising SID + uint8_t adv_sid; +}; + +///HCI LE Remove Device from Periodic Advertiser List Command parameters structure +/*@TRACE*/ +struct hci_le_rmv_dev_from_per_adv_list_cmd +{ + ///Advertiser address type + uint8_t adv_addr_type; + ///Advertiser address + struct bd_addr adv_addr; + ///Advertising SID + uint8_t adv_sid; +}; + +///HCI LE Set Privacy Mode Command parameters structure +/*@TRACE*/ +struct hci_le_set_priv_mode_cmd +{ + ///Peer identity address type + uint8_t peer_addr_type; + ///Peer identity address + struct bd_addr peer_addr; + ///Privacy mode + uint8_t priv_mode; +}; + +///HCI LE Set Host Channel Classification Command parameters structure +/*@TRACE*/ +struct hci_le_set_host_ch_class_cmd +{ + ///Channel map + struct le_chnl_map chmap; +}; + + +///HCI LE Receiver Test v1 Command parameters structure +/*@TRACE*/ +struct hci_le_rx_test_v1_cmd +{ + /// RX channel, range: 0x00 to 0x27 + uint8_t rx_channel; +}; + +///HCI LE Transmitter Test v1 Command parameters structure +/*@TRACE*/ +struct hci_le_tx_test_v1_cmd +{ + /// TX channel, range: 0x00 to 0x27 + uint8_t tx_channel; + /// Length of test data in bytes, range: 0x00 to 0xFF + uint8_t test_data_len; + /** + * Packet payload + * 0x00 PRBS9 sequence "11111111100000111101" (in transmission order) as described in [Vol 6] Part F, Section 4.1.5 + * 0x01 Repeated "11110000" (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x02 Repeated "10101010" (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x03 PRBS15 sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x04 Repeated "11111111" (in transmission order) sequence + * 0x05 Repeated "00000000" (in transmission order) sequence + * 0x06 Repeated "00001111" (in transmission order) sequence + * 0x07 Repeated "01010101" (in transmission order) sequence + * 0x08-0xFF Reserved for future use + */ + uint8_t pkt_payl; +}; + +///HCI LE Encrypt Command parameters structure +/*@TRACE*/ +struct hci_le_enc_cmd +{ + ///Long term key structure + struct ltk key; + ///Pointer to buffer with plain data to encrypt - 16 bytes + uint8_t plain_data[16]; +}; + +/// HCI LE Connection Update Command parameters structure +/*@TRACE*/ +struct hci_le_con_update_cmd +{ + ///Connection Handle + uint16_t conhdl; + ///Minimum of connection interval (units of 1.25 ms) + uint16_t con_intv_min; + ///Maximum of connection interval (units of 1.25 ms) + uint16_t con_intv_max; + ///Connection latency (units of connection event) + uint16_t con_latency; + ///Link supervision timeout (units of 10 ms) + uint16_t superv_to; + ///Minimum of CE length (units of 0.625 ms) + uint16_t ce_len_min; + ///Maximum of CE length (units of 0.625 ms) + uint16_t ce_len_max; +}; + +/// HCI LE Start Encryption Command parameters structure +/*@TRACE*/ +struct hci_le_start_enc_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Random number - 8B + struct rand_nb nb; + ///Encryption Diversifier + uint16_t enc_div; + ///Long term key + struct ltk ltk; +}; + +/// HCI long term key request reply command parameters structure +/*@TRACE*/ +struct hci_le_ltk_req_reply_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Long term key + struct ltk ltk; +}; + +/// HCI long term key request negative reply command parameters structure +/*@TRACE*/ +struct hci_le_ltk_req_neg_reply_cmd +{ + ///Connection handle + uint16_t conhdl; +}; + +/// HCI LE remote connection parameter request reply command parameters structure +/*@TRACE*/ +struct hci_le_rem_con_param_req_reply_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Interval_Min + uint16_t interval_min; + ///Interval_Max + uint16_t interval_max; + ///Latency + uint16_t latency; + ///Timeout + uint16_t timeout; + ///Minimum_CE_Length + uint16_t min_ce_len; + ///Maximum_CE_Length + uint16_t max_ce_len; +}; + +/// HCI LE remote connection parameter request negative reply command parameters structure +/*@TRACE*/ +struct hci_le_rem_con_param_req_neg_reply_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Reason + uint8_t reason; +}; + + +/// HCI LE Set Data Length Command parameters structure +/*@TRACE*/ +struct hci_le_set_data_len_cmd +{ + ///Connection Handle + uint16_t conhdl; + ///Preferred maximum number of payload octets that the local Controller should include + ///in a single Link Layer Data Channel PDU. + uint16_t tx_octets; + ///Preferred maximum number of microseconds that the local Controller should use to transmit + ///a single Link Layer Data Channel PDU + uint16_t tx_time; +}; + +/// HCI LE Read Suggested Default Data Length Command +/*@TRACE*/ +struct hci_le_wr_suggted_dft_data_len_cmd +{ + ///Suggested value for the Controller's maximum transmitted number of payload octets to be used + uint16_t suggted_max_tx_octets; + ///Suggested value for the Controller's maximum packet transmission time to be used + uint16_t suggted_max_tx_time; +}; + +/// HCI LE Add Device to Resolving List Command +/*@TRACE*/ +struct hci_le_add_dev_to_rslv_list_cmd +{ + /// Peer Identity Address Type + uint8_t peer_id_addr_type; + /// Peer Identity Address + struct bd_addr peer_id_addr; + /// Peer IRK + struct irk peer_irk; + /// Local IRK + struct irk local_irk; +}; + +/// HCI LE Remove Device From Resolving List Command +/*@TRACE*/ +struct hci_le_rmv_dev_from_rslv_list_cmd +{ + /// Peer Identity Address Type + uint8_t peer_id_addr_type; + /// Peer Identity Address + struct bd_addr peer_id_addr; +}; + +/// HCI LE Read Peer Resolvable Address Command +/*@TRACE*/ +struct hci_le_rd_peer_rslv_addr_cmd +{ + /// Peer Identity Address Type + uint8_t peer_id_addr_type; + /// Peer Identity Address + struct bd_addr peer_id_addr; +}; + +/// HCI LE Read Local Resolvable Address Command +/*@TRACE*/ +struct hci_le_rd_loc_rslv_addr_cmd +{ + /// Peer Identity Address Type + uint8_t peer_id_addr_type; + /// Peer Identity Address + struct bd_addr peer_id_addr; +}; + +/// HCI LE Set Address Resolution Enable Command +/*@TRACE*/ +struct hci_le_set_addr_resol_en_cmd +{ + /// Address Resolution Enable + uint8_t enable; +}; + +/// HCI LE Set Resolvable Private Address Timeout Command +/*@TRACE*/ +struct hci_le_set_rslv_priv_addr_to_cmd +{ + /// RPA Timeout + uint16_t rpa_timeout; +}; + +/* + * HCI EVENTS PARAMETERS + **************************************************************************************** + */ + +/// HCI inquiry complete event structure +/*@TRACE*/ +struct hci_inq_cmp_evt +{ + ///Status of the procedure + uint8_t status; +}; + + +/// HCI Inquiry result event structure (with only 1 result) +/*@TRACE*/ +struct hci_inq_res_evt +{ + + ///Number of response + uint8_t nb_rsp; + ///BdAddr + struct bd_addr bd_addr; + ///Page Scan Repetition Mode + uint8_t page_scan_rep_mode; + ///Reserved + uint8_t reserved1; + ///Reserved + uint8_t reserved2; + ///class of device + struct devclass class_of_dev; + ///Clock Offset + uint16_t clk_off; + +}; + +/// HCI Inquiry result with rssi event structure (with only 1 result) +/*@TRACE*/ +struct hci_inq_res_with_rssi_evt +{ + ///Number of response + uint8_t nb_rsp; + ///BdAddr + struct bd_addr bd_addr; + ///Page Scan Repetition Mode + uint8_t page_scan_rep_mode; + ///Reserved + uint8_t reserved1; + ///class of device + struct devclass class_of_dev; + ///Clock Offset + uint16_t clk_off; + ///Rssi + uint8_t rssi; + +}; + +/// HCI Extended inquiry result indication structure (with only 1 result) +/*@TRACE*/ +struct hci_ext_inq_res_evt +{ + ///Number of response + uint8_t nb_rsp; + ///BdAddr + struct bd_addr bd_addr; + ///Page Scan Repetition Mode + uint8_t page_scan_rep_mode; + ///Reserved + uint8_t reserved1; + ///class of device + struct devclass class_of_dev; + ///Clock Offset + uint16_t clk_off; + ///RSSi + uint8_t rssi; + ///Extended inquiry response data + struct eir eir; +}; + +/// HCI disconnect complete event structure +/*@TRACE*/ +struct hci_disc_cmp_evt +{ + ///Status of received command + uint8_t status; + ///Connection Handle + uint16_t conhdl; + ///Reason for disconnection + uint8_t reason; +}; + +/// HCI basic command complete event structure +/*@TRACE + * hci_dbg_wr_par_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_dbg_llcp_discard_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_reset_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_set_evt_mask_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_per_adv_en_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_create_con_cancel_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_evt_mask_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_host_ch_class_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_wr_suggted_dft_data_len_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_dft_phy_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_rmv_dev_from_wlst_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_adv_param_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_adv_data_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_scan_rsp_data_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_adv_en_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_scan_param_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_scan_en_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_rand_addr_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_addr_resol_en_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_set_rslv_priv_addr_to_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_rmv_dev_from_rslv_list_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_create_con_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_dbg_plf_reset_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * hci_le_wr_rf_path_comp_cmd_cmp_evt = hci_basic_cmd_cmp_evt + * */ +struct hci_basic_cmd_cmp_evt +{ + ///Status of the command reception + uint8_t status; +}; + +/// HCI basic command complete event structure with connection handle +/*@TRACE*/ +struct hci_basic_conhdl_cmd_cmp_evt +{ + /// status + uint8_t status; + /// connection handle + uint16_t conhdl; +}; + +/// HCI basic command complete event structure with BD address +struct hci_basic_bd_addr_cmd_cmp_evt +{ + ///status + uint8_t status; + ///BdAddr + struct bd_addr bd_addr; +}; + +/// HCI basic event structure with status and BD address +struct hci_basic_stat_bd_addr_evt +{ + ///status + uint8_t status; + ///BdAddr + struct bd_addr bd_addr; +}; + +/// HCI basic event including a connection handle as parameter +struct hci_basic_conhdl_evt +{ + ///Connection handle + uint16_t conhdl; +}; + +/// HCI complete event with status only. +/*@TRACE*/ +struct hci_cmd_stat_event +{ + /// Status of the command reception + uint8_t status; +}; + +/// HCI number of packet complete event structure +/*@TRACE*/ +struct hci_nb_cmp_pkts_evt +{ + /// number of handles + uint8_t nb_of_hdl; + /// connection handle + uint16_t conhdl[1]; + /// number of completed packets + uint16_t nb_comp_pkt[1]; +}; + +/// HCI data buffer overflow event structure +/*@TRACE*/ +struct hci_data_buf_ovflw_evt +{ + ///Link type + uint8_t link_type; +}; + +/// HCI Hardware Error Event parameters structure +/*@TRACE*/ +struct hci_hw_err_evt +{ + /// HW error code + uint8_t hw_code; +}; + +/// HCI encryption change event structure +struct hci_enc_change_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Encryption enabled information + uint8_t enc_stat; +}; + +/// HCI encryption key refresh complete event structure +/*@TRACE + * hci_enc_key_refresh_evt = hci_enc_key_ref_cmp_evt */ +struct hci_enc_key_ref_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; +}; + +/// HCI Authenticated Payload Timeout Expired Event structure +/*@TRACE*/ +struct hci_auth_payl_to_exp_evt +{ + ///Connection handle + uint16_t conhdl; +}; + +/// HCI command complete event structure for create connection +/*@TRACE*/ +struct hci_con_cmp_evt +{ + /// Status + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Bluetooth Device address + struct bd_addr bd_addr; + ///Link type + uint8_t link_type; + ///Encryption state + uint8_t enc_en; +}; + +/// HCI command complete event structure for qos setup +/*@TRACE*/ +struct hci_qos_setup_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Flags + uint8_t flags; + ///Service type + uint8_t serv_type; + ///Token rate + uint32_t tok_rate; + ///Peak bandwidth + uint32_t pk_bw; + ///Latency + uint32_t lat; + ///Delay variation + uint32_t del_var; +}; + +/// HCI flow specification complete event parameters structure +/*@TRACE*/ +struct hci_flow_spec_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Flags + uint8_t flags; + ///Flow direction + uint8_t flow_dir; + ///Service type + uint8_t serv_type; + ///Token rate + uint32_t tk_rate; + ///Token buffer size + uint32_t tk_buf_sz; + ///Peak bandwidth + uint32_t pk_bw; + ///Access latency + uint32_t acc_lat; +}; + +/// HCI role change event parameters structure +/*@TRACE*/ +struct hci_role_chg_evt +{ + ///Status + uint8_t status; + ///BD address + struct bd_addr bd_addr; + ///New role + uint8_t new_role; +}; + +/// HCI complete event structure for the read clock offset command +/*@TRACE*/ +struct hci_rd_clk_off_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Clock offset + uint16_t clk_off_val; +}; + +/// HCI event structure for the flush occurred event +/*@TRACE*/ +struct hci_flush_occurred_evt +{ + ///Connection handle + uint16_t conhdl; +}; + +/// HCI max slot change event structure +/*@TRACE*/ +struct hci_max_slot_chg_evt +{ + ///Connection handle + uint16_t conhdl; + ///Max slot + uint8_t max_slot; +}; + +/// HCI sniff subrating event parameters structure +/*@TRACE*/ +struct hci_sniff_sub_evt +{ + ///Status. + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Maximum transmit latency + uint16_t max_lat_tx; + ///Maximum receive latency + uint16_t max_lat_rx; + ///Minimum remote TO + uint16_t min_rem_to; + ///Minimum local TO + uint16_t min_loc_to; +}; + +/// HCI read remote extended features complete event parameters structure +/*@TRACE*/ +struct hci_rd_rem_ext_feats_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///page number + uint8_t pg_nb; + ///page number max + uint8_t pg_nb_max; + ///ext LMP features + struct features ext_feats; +}; + +/// HCI read remote extended features complete event parameters structure +/*@TRACE*/ +struct hci_rem_host_supp_feats_notif_evt +{ + ///BD address + struct bd_addr bd_addr; + ///ext lmp features + struct features ext_feats; +}; + +/// HCI command complete event structure for the read remote supported features command +/*@TRACE*/ +struct hci_rd_rem_supp_feats_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Remote features + struct features rem_feats; +}; + +/// HCI command complete event structure for the read remote information version command +/*@TRACE*/ +struct hci_rd_rem_ver_info_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///LMP version + uint8_t vers; + ///Manufacturer name + uint16_t compid; + ///LMP subversion + uint16_t subvers; +}; + +/// HCI encryption change event structure +/*@TRACE*/ +struct hci_enc_chg_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Encryption enabled information + uint8_t enc_stat; +}; + +/// HCI mode change event structure +/*@TRACE*/ +struct hci_mode_chg_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Current mode + uint8_t cur_mode; + /// Interval + uint16_t interv; +}; + +/// HCI simple pairing complete event structure +/*@TRACE*/ +struct hci_sp_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Bluetooth Device address + struct bd_addr bd_addr; +}; + +/// HCI Authentication complete event structure +/*@TRACE*/ +struct hci_auth_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; +}; + +/// HCI change connection link key complete event structure +/*@TRACE*/ +struct hci_chg_con_lk_cmp_evt +{ + ///Status + uint8_t status; + ///Connection handle + uint16_t conhdl; +}; + +/// HCI encryption key refresh complete event structure +/*@TRACE*/ +struct hci_enc_key_refresh_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; +}; + +/// HCI master link key complete event structure +/*@TRACE*/ +struct hci_master_lk_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Key flag + uint8_t key_flag; +}; +/// HCI synchronous link connection complete event structure +/*@TRACE*/ +struct hci_sync_con_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///BD address + struct bd_addr bd_addr; + ///Link type + uint8_t lk_type; + ///Transmit interval + uint8_t tx_int; + ///Retransmission window + uint8_t ret_win; + ///rx packet length + uint16_t rx_pkt_len; + ///tx packet length + uint16_t tx_pkt_len; + ///Air mode + uint8_t air_mode; + +}; + +/// HCI synchronous connection change event structure +/*@TRACE*/ +struct hci_sync_con_chg_evt +{ + ///Status for command reception + uint8_t status; + ///Synchronous Connection handle + uint16_t sync_conhdl; + ///Transmit interval + uint8_t tx_int; + ///Retransmission window + uint8_t ret_win; + ///rx packet length + uint16_t rx_pkt_len; + ///tx packet length + uint16_t tx_pkt_len; +}; + +/// HCI connection packet type change event structure +/*@TRACE*/ +struct hci_con_pkt_type_chg_evt +{ + ///Status for command reception + uint8_t status; + ///Synchronous Connection handle + uint16_t sync_conhdl; + ///Synchronous packet type + uint16_t pkt_type; +}; + +/// HCI link supervision timeout change event structure +/*@TRACE*/ +struct hci_link_supv_to_chg_evt +{ + ///Connection handle + uint16_t conhdl; + ///Link supervision timeout + uint16_t lsto_val; +}; + +/// HCI link key request event structure +/*@TRACE*/ +struct hci_lk_req_evt +{ + ///BD address + struct bd_addr bd_addr; +}; + +/// HCI encryption key refresh event structure +/*@TRACE*/ +struct hci_enc_key_refresh_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; +}; + +/// HCI connection request event structure +/*@TRACE*/ +struct hci_con_req_evt +{ + ///BD address + struct bd_addr bd_addr; + ///Class of device + struct devclass classofdev; + ///link type + uint8_t lk_type; +}; + +/// HCI quality of service violation event structure +/*@TRACE*/ +struct hci_qos_viol_evt +{ + ///Connection handle + uint16_t conhdl; +}; + +/// HCI io capability response event structure +/*@TRACE*/ +struct hci_io_cap_rsp_evt +{ + ///BdAddr + struct bd_addr bd_addr; + ///IO capability + uint8_t io_capa; + ///OOB data present + uint8_t oob_data_pres; + ///Authentication requirements + uint8_t auth_req; + +}; + +/// HCI IO capability response event structure +/*@TRACE*/ +struct hci_io_cap_req_evt +{ + ///BdAddr + struct bd_addr bd_addr; +}; + +/// HCI Return link keys event structure +/*@TRACE*/ +struct hci_return_link_keys_evt +{ + ///Number of Keys + uint8_t num_keys; + ///BdAddr + struct bd_addr bd_addr; + ///Key + struct ltk key; +}; + +/// HCI pin code request event structure +/*@TRACE*/ +struct hci_pin_code_req_evt +{ + ///BdAddr + struct bd_addr bd_addr; +}; + +/// HCI user passkey request event structure +/*@TRACE*/ +struct hci_user_passkey_req_evt +{ + ///BdAddr + struct bd_addr bd_addr; +}; + +/// HCI user passkey notification event structure +/*@TRACE*/ +struct hci_user_passkey_notif_evt +{ + ///BdAddr + struct bd_addr bd_addr; + ///Passkey + uint32_t passkey; +}; + +/// HCI remote OOB data request event structure +/*@TRACE*/ +struct hci_rem_oob_data_req_evt +{ + ///BdAddr + struct bd_addr bd_addr; +}; + +/// HCI user confirmation request event structure +/*@TRACE*/ +struct hci_user_cfm_req_evt +{ + ///BdAddr + struct bd_addr bd_addr; + ///Passkey + uint32_t passkey; +}; + +/// HCI keypress notification event structure +/*@TRACE*/ +struct hci_keypress_notif_evt +{ + ///BdAddr + struct bd_addr bd_addr; + ///type + uint8_t type; +}; + +/// HCI link key notification event structure +/*@TRACE*/ +struct hci_lk_notif_evt +{ + ///BdAddr + struct bd_addr bd_addr; + ///Key + struct ltk key; + ///type + uint8_t key_type; +}; + +/// HCI SAM status change event strucutre +struct hci_sam_status_change_evt +{ + ///Connection handle + uint16_t conhdl; + ///Local SAM index + uint8_t loc_idx; + ///Local SAM TX availability + uint8_t loc_tx_av; + ///Local SAM RX availability + uint8_t loc_rx_av; + ///Remote SAM index + uint8_t rem_idx; + ///Remote SAM TX availability + uint8_t rem_tx_av; + ///Remote SAM RX availability + uint8_t rem_rx_av; +}; + + +/* + * HCI LE META EVENTS PARAMETERS + **************************************************************************************** + */ + + +// LE event structures + +/// HCI command complete event structure for the Read Local Supported Features +/*@TRACE*/ +struct hci_le_rd_local_supp_feats_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Local LE supported features + struct le_features feats; +}; + +/// HCI command complete event structure for the Read Advertising Channel Tx Power Command +/*@TRACE + * hci_le_rd_adv_chnl_tx_pw_cmd_cmp_evt = hci_rd_adv_chnl_tx_pw_cmd_cmp_evt*/ +struct hci_rd_adv_chnl_tx_pw_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Advertising channel Tx power level + int8_t adv_tx_pw_lvl; +}; + +///HCI command complete event structure for the Read White List Size Command +/*@TRACE*/ +struct hci_le_rd_wlst_size_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///White List size + uint8_t wlst_size; +}; + +///HCI command complete event structure for the Read Buffer Size Command +/*@TRACE*/ +struct hci_le_rd_buff_size_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///ACL data packet length that can be sent from host to controller + uint16_t hc_data_pk_len; + ///Total number of ACL data packets that can be sent from host to controller. + uint8_t hc_tot_nb_data_pkts; +}; + +///HCI command complete event structure for LE Rand Command +/*@TRACE*/ +struct hci_le_rand_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Random number + struct rand_nb nb; +}; + +///HCI command complete event structure for Read Supported States Command +/*@TRACE*/ +struct hci_le_rd_supp_states_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///LE supported states response + struct le_states states; +}; + +///HCI command complete event structure for Test End +/*@TRACE + * * hci_le_test_end_cmd_cmp_evt = hci_test_end_cmd_cmp_evt*/ +struct hci_test_end_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Number of RX packets - null if TX test was the ended one + uint16_t nb_packet_received; +}; + +///HCI LE Encrypt complete event structure +/*@TRACE*/ +struct hci_le_enc_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Encrypted data to return to command source. + uint8_t encrypted_data[ENC_DATA_LEN]; +}; + +#if BLE_EMB_PRESENT || BLE_HOST_PRESENT +///HCI LE advertising report event structure +/*@TRACE*/ +struct hci_le_adv_report_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Number of advertising reports in this event + uint8_t nb_reports; + ///Advertising reports structures array + struct adv_report adv_rep[BLE_ADV_REPORTS_MAX]; +}; + +///HCI LE extended advertising report event structure +/*@TRACE*/ +struct hci_le_ext_adv_report_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Number of advertising reports in this event + uint8_t nb_reports; + ///Paramaters for each report + struct ext_adv_report adv_rep[BLE_ADV_REPORTS_MAX]; +}; + +///HCI LE periodic advertising sync established event structure +/*@TRACE + * hci_le_periodic_adv_sync_est_evt = hci_le_per_adv_sync_est_evt*/ +struct hci_le_per_adv_sync_est_evt +{ + ///LE Subevent code + uint8_t subcode; + /// Status of the advertising sync + uint8_t status; + /// Sync Handle to be used + uint16_t sync_handle; + /// Advertising SID + uint8_t adv_sid; + ///Advertising address type: public/random + uint8_t adv_addr_type; + ///Advertising address value + struct bd_addr adv_addr; + /// Advertiser PHY (@enum le_phy_value) + uint8_t phy; + /// Advertising interval (Time=N*1.25ms) + uint16_t interval; + /// Advertiser clock accuracy (@see enum SCA) + uint8_t adv_ca; +}; + +///HCI LE periodic advertising report event structure +/*@TRACE + * hci_le_periodic_adv_report_evt = hci_le_per_adv_report_evt*/ +struct hci_le_per_adv_report_evt +{ + ///LE Subevent code + uint8_t subcode; + /// Sync Handle to be used + uint16_t sync_handle; + /// Tx Power + uint8_t tx_power; + /// RSSI + uint8_t rssi; + /// CTE type + uint8_t cte_type; + /// Data Status + uint8_t status; + ///Data length in advertising packet + uint8_t data_len; + ///Data of advertising packet + uint8_t data[PER_ADV_DATA_MAX_LEN]; +}; + +///HCI LE periodic advertising sync lost event structure +/*@TRACE + * hci_le_periodic_adv_sync_lost_evt = hci_le_per_adv_sync_lost_evt*/ +struct hci_le_per_adv_sync_lost_evt +{ + ///LE Subevent code + uint8_t subcode; + /// Sync Handle to be used + uint16_t sync_handle; +}; + +///HCI LE scan timeout event structure +/*@TRACE*/ +struct hci_le_scan_timeout_evt +{ + ///LE Subevent code + uint8_t subcode; +}; + +#endif //BLE_EMB_PRESENT || BLE_HOST_PRESENT + +/// HCI command complete event structure for Read Channel Map Command +/*@TRACE*/ +struct hci_le_rd_chnl_map_cmd_cmp_evt +{ + ///Status of command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Channel map + struct le_chnl_map ch_map; +}; + +/// HCI command complete event structure for Long Term Key Request Reply Command +/*@TRACE*/ +struct hci_le_ltk_req_reply_cmd_cmp_evt +{ + ///Status of command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; +}; + +/// HCI command complete event structure for Long Term Key Request Negative Reply Command +/*@TRACE*/ +struct hci_le_ltk_req_neg_reply_cmd_cmp_evt +{ + ///Status of command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; +}; + +/// HCI command complete event structure for LE Read Suggested Default Data Length Command +/*@TRACE*/ +struct hci_le_rd_suggted_dft_data_len_cmd_cmp_evt +{ + ///Status of command reception + uint8_t status; + ///Host's suggested value for the Controller's maximum transmitted number of payload octets + uint16_t suggted_max_tx_octets; + ///Host's suggested value for the Controller's maximum packet transmission time + uint16_t suggted_max_tx_time; +}; +/// HCI command complete event structure for LE Read Maximum Data Length Command +/*@TRACE*/ +struct hci_le_rd_max_data_len_cmd_cmp_evt +{ + ///Status of command reception + uint8_t status; + ///Maximum number of payload octets that the local Controller supports for transmission + uint16_t suppted_max_tx_octets; + ///Maximum time, in microseconds, that the local Controller supports for transmission + uint16_t suppted_max_tx_time; + ///Maximum number of payload octets that the local Controller supports for reception + uint16_t suppted_max_rx_octets; + ///Maximum time, in microseconds, that the local Controller supports for reception + uint16_t suppted_max_rx_time; +}; + +/// HCI LE Read Peer Resolvable Address Command Complete Event +/*@TRACE*/ +struct hci_le_rd_peer_rslv_addr_cmd_cmp_evt +{ + ///Status + uint8_t status; + /// Peer Resolvable Address + struct bd_addr peer_rslv_addr; +}; + +/// HCI LE Read Local Resolvable Address Command Complete Event +/*@TRACE*/ +struct hci_le_rd_loc_rslv_addr_cmd_cmp_evt +{ + ///Status + uint8_t status; + /// Local Resolvable Address + struct bd_addr loc_rslv_addr; +}; + +/// HCI LE Read Resolving List Size Command Complete Event +/*@TRACE*/ +struct hci_le_rd_rslv_list_size_cmd_cmp_evt +{ + ///Status + uint8_t status; + /// Resolving List Size + uint8_t size; +}; + + +/// HCI write authenticated payload timeout command +/*@TRACE*/ +struct hci_wr_auth_payl_to_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Authenticated payload timeout (N*10ms) + uint16_t auth_payl_to; +}; + +/// HCI command complete event structure for the Write Authenticated Payload Timeout Command +/*@TRACE*/ +struct hci_wr_auth_payl_to_cmd_cmp_evt +{ + /// Status of the command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; +}; + +/// HCI command complete event structure for HCI LE Connection Update Command +/*@TRACE*/ +struct hci_le_con_update_cmp_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Status of received command + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Connection interval value + uint16_t con_interval; + ///Connection latency value + uint16_t con_latency; + ///Supervision timeout + uint16_t sup_to; +}; + +/// HCI command complete event structure for create connection +/*@TRACE*/ +struct hci_le_con_cmp_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Status of received command + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Device role - 0=Master/ 1=Slave + uint8_t role; + ///Peer address type - 0=public/1=random + uint8_t peer_addr_type; + ///Peer address + struct bd_addr peer_addr; + ///Connection interval + uint16_t con_interval; + ///Connection latency + uint16_t con_latency; + ///Link supervision timeout + uint16_t sup_to; + ///Master clock accuracy + uint8_t clk_accuracy; +}; + +/// HCI LE read remote used feature command parameters structure +/*@TRACE*/ +struct hci_le_rd_rem_feats_cmd +{ + ///Connection handle + uint16_t conhdl; +}; + +/// HCI command complete event structure for HCI LE read remote feature Command +/*@TRACE*/ +struct hci_le_rd_rem_feats_cmd_cmp_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Status of received command + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Le Features + struct le_features le_feats; +}; + +/// HCI command structure for the read transmit power level command +/*@TRACE*/ +struct hci_rd_tx_pwr_lvl_cmd +{ + ///Connection handle + uint16_t conhdl; + ///Power Level type: current or maximum + uint8_t type; +}; + +/// HCI command complete event structure for the read transmit power level command +/*@TRACE*/ +struct hci_rd_tx_pwr_lvl_cmd_cmp_evt +{ + ///Status for command reception + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Value of TX power level + uint8_t tx_pow_lvl; +}; + +/// HCI read remote information version command parameters structure +/*@TRACE*/ +struct hci_rd_rem_ver_info_cmd +{ + ///Connection handle + uint16_t conhdl; +}; + +/// HCI LE remote connection parameter request event +/*@TRACE*/ +struct hci_le_rem_con_param_req_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Connection handle + uint16_t conhdl; + ///Interval_Min + uint16_t interval_min; + ///Interval_Max + uint16_t interval_max; + ///Latency + uint16_t latency; + ///Timeout + uint16_t timeout; +}; + + +/// HCI command complete event structure for enhance create connection +/*@TRACE*/ +struct hci_le_enh_con_cmp_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Status of received command + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///Device role - 0=Master/ 1=Slave + uint8_t role; + ///Peer address type - 0=public/1=random + uint8_t peer_addr_type; + ///Peer address + struct bd_addr peer_addr; + ///Local Resolvable Private Address + struct bd_addr loc_rslv_priv_addr; + ///Peer Resolvable Private Address + struct bd_addr peer_rslv_priv_addr; + ///Connection interval + uint16_t con_interval; + ///Connection latency + uint16_t con_latency; + ///Link supervision timeout + uint16_t sup_to; + ///Master clock accuracy + uint8_t clk_accuracy; +}; + +struct hci_generate_dhkey_cmp_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Status of received command + uint8_t status; + /// The 32 byte Diffie Helman Key + uint8_t dh_key[32]; +}; + +struct hci_rd_local_p256_public_key_cmp_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Status of received command + uint8_t status; + /// The 32 byte Diffie Helman Key + uint8_t public_key[64]; + +}; + +#if BLE_EMB_PRESENT || BLE_HOST_PRESENT +/// HCI LE Direct Advertising Report Event +/*@TRACE*/ +struct hci_le_dir_adv_rep_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Number of reports + uint8_t nb_reports; + ///Direct Advertising reports structures array + struct dir_adv_report adv_rep[BLE_ADV_REPORTS_MAX]; +}; +#endif //BLE_EMB_PRESENT || BLE_HOST_PRESENT + +/// Connected LE event +struct hci_le_con_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Connection handle + uint16_t conhdl; +}; + +/// HCI command complete event structure for HCI LE read remote used feature Command +/*@TRACE*/ +struct hci_le_ltk_request_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Connection handle + uint16_t conhdl; + ///Random number + struct rand_nb rand; + ///Encryption diversifier + uint16_t ediv; +}; + +/// HCI LE META event LE Data Length Change Event +/*@TRACE*/ +struct hci_le_data_len_chg_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Connection handle + uint16_t conhdl; + ///The maximum number of payload octets in TX + uint16_t max_tx_octets; + ///The maximum time that the local Controller will take to TX + uint16_t max_tx_time; + ///The maximum number of payload octets in RX + uint16_t max_rx_octets; + ///The maximum time that the local Controller will take to RX + uint16_t max_rx_time; +}; + + +/// HCI Synchronization Train Received Event +/*@TRACE*/ +struct hci_sync_train_rec_evt +{ + /// Status + uint8_t status; + /// BD_ADDR + struct bd_addr bd_addr; + /// Clock_Offset (28 bits) - (CLKNslave - CLK) modulo 2^28 + uint32_t clock_offset; + /// AFH_Channel_Map + struct chnl_map afh_ch_map; + /// LT_ADDR + uint8_t lt_addr; + /// Next_Broadcast_Instant (28 bits) + uint32_t next_bcst_instant; + /// Connectionless_Slave_Broadcast_Interval (in slots) + uint16_t csb_int; + /// Service_Data + uint8_t service_data; +}; + +/// HCI Connectionless Slave Broadcast Receive Event +/*@TRACE*/ +struct hci_con_slv_bcst_rec_evt +{ + /// BD_ADDR + struct bd_addr bd_addr; + /// LT_ADDR + uint8_t lt_addr; + /// CLK (28 bits) + uint32_t clk; + /// Offset (28 bits) - (CLKNslave - CLK) modulo 2^28 + uint32_t offset; + /// Receive Status + uint8_t receive_status; + /// Fragment + uint8_t fragment; + /// Data_Length (in bytes) + uint8_t data_length; + /// Data + uint8_t data[__ARRAY_EMPTY]; +}; + +/// HCI Connectionless Slave Broadcast Timeout Event +/*@TRACE*/ +struct hci_con_slv_bcst_to_evt +{ + /// BD_ADDR + struct bd_addr bd_addr; + /// LT_ADDR + uint8_t lt_addr; +}; + +/// HCI Connectionless Slave Broadcast Channel Map Change Event +/*@TRACE*/ +struct hci_con_slv_bcst_ch_map_chg_evt +{ + /// Channel_Map + struct chnl_map ch_map; +}; + +/*@TRACE*/ +struct hci_le_gen_dhkey_cmp_evt +{ + ///LE Subevent code + uint8_t subcode; + uint8_t status; + uint8_t dh_key[32]; +}; + +/*@TRACE*/ +struct hci_le_rd_loc_p256_pub_key_cmp_evt +{ + ///LE Subevent code + uint8_t subcode; + uint8_t status; + t_public_key public_key; +}; + + +/// HCI command structure for the LE receiver test v3 command +/*@TRACE*/ +struct hci_le_rx_test_v3_cmd +{ + /// RX channel, range: 0x00 to 0x27 + uint8_t rx_channel; + /// PHY (@enum le_phy_value) + uint8_t phy; + /// Modulation index (0: standard | 1: stable) + uint8_t mod_idx; + /// Expected CTE length in 8us units, range: 0x02 to 0x14 + uint8_t exp_cte_len; + /// Expected CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) + uint8_t exp_cte_type; + /// Slot durations (1: 1 us | 2: 2 us) + uint8_t slot_dur; + /// Length of switching pattern (number of antenna IDs in the pattern), range: 0x02 to 0x4B + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[MAX_SWITCHING_PATTERN_LEN]; +}; + +/// HCI command structure for the LE transmitter test v3 command +/*@TRACE*/ +struct hci_le_tx_test_v3_cmd +{ + /// TX channel, range: 0x00 to 0x27 + uint8_t tx_channel; + /// Length of test data in bytes, range: 0x00 to 0xFF + uint8_t test_data_len; + /** + * Packet payload + * 0x00 PRBS9 sequence "11111111100000111101" (in transmission order) as described in [Vol 6] Part F, Section 4.1.5 + * 0x01 Repeated "11110000" (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x02 Repeated "10101010" (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x03 PRBS15 sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x04 Repeated "11111111" (in transmission order) sequence + * 0x05 Repeated "00000000" (in transmission order) sequence + * 0x06 Repeated "00001111" (in transmission order) sequence + * 0x07 Repeated "01010101" (in transmission order) sequence + * 0x08-0xFF Reserved for future use + */ + uint8_t pkt_payl; + /// PHY (@enum le_phy_value) + uint8_t phy; + /// CTE length (in 8us unit) + uint8_t cte_len; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) + uint8_t cte_type; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[MAX_SWITCHING_PATTERN_LEN]; +}; + +/// HCI command structure for the LE set connectionless CTE transmit parameters command +/*@TRACE*/ +struct hci_le_set_conless_cte_tx_param_cmd +{ + /// Advertising handle + uint8_t adv_hdl; + /// CTE length (in 8us unit) + uint8_t cte_len; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) + uint8_t cte_type; + /// CTE count (number of CTEs to transmit in each periodic advertising interval, range 0x01 to 0x10) + uint8_t cte_count; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[MAX_SWITCHING_PATTERN_LEN]; +}; + +/// HCI command structure for the LE set connectionless CTE transmit enable command +/*@TRACE*/ +struct hci_le_set_conless_cte_tx_en_cmd +{ + /// Advertising handle + uint8_t adv_hdl; + /// CTE enable + uint8_t cte_en; +}; + +/// HCI command structure for LE set connectionless IQ sampling enable command +/*@TRACE*/ +struct hci_le_set_conless_iq_sampl_en_cmd +{ + /// Sync handle + uint16_t sync_hdl; + /// Sampling enable + uint8_t sampl_en; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Max sampled CTEs + uint8_t max_sampl_cte; + /// Length of switching pattern + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[MAX_SWITCHING_PATTERN_LEN]; +}; + +/// HCI command structure for the LE set connection CTE receive parameters command +/*@TRACE*/ +struct hci_le_set_con_cte_rx_param_cmd +{ + /// Connection handle + uint16_t conhdl; + /// Sampling enable + uint8_t sampl_en; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[MAX_SWITCHING_PATTERN_LEN]; +}; + +/// HCI command structure for the LE set connection CTE transmit parameters command +/*@TRACE*/ +struct hci_le_set_con_cte_tx_param_cmd +{ + /// Connection handle + uint16_t conhdl; + /// CTE types (bit0: AOA | bit1: AOD-1us | bit2: AOD-2us) + uint8_t cte_types; + /// Length of switching pattern (number of antenna IDs in the pattern) + uint8_t switching_pattern_len; + /// Antenna IDs + uint8_t antenna_id[MAX_SWITCHING_PATTERN_LEN]; +}; + +/// HCI command structure for the LE connection CTE request enable command +/*@TRACE*/ +struct hci_le_con_cte_req_en_cmd +{ + /// Connection handle + uint16_t conhdl; + /// Enable + uint8_t en; + /// CTE request interval (in number of connection events) + uint16_t cte_req_intv; + /// Requested CTE length (in 8us unit) + uint8_t req_cte_len; + /// Requested CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) + uint8_t req_cte_type; +}; + +/// HCI command structure for the LE connection CTE response enable command +/*@TRACE*/ +struct hci_le_con_cte_rsp_en_cmd +{ + /// Connection handle + uint16_t conhdl; + /// Enable + uint8_t en; +}; + +/// HCI command structure for LE set connectionless IQ sampling enable command complete event +/*@TRACE*/ +struct hci_le_set_conless_iq_sampl_en_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Sync handle + uint16_t sync_hdl; +}; + +/// HCI command structure for LE read antenna information command complete event +/*@TRACE*/ +struct hci_le_rd_antenna_inf_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Supported switching sampling rates + uint8_t supp_switching_sampl_rates; + /// Number of antennae + uint8_t antennae_num; + /// Max length of switching pattern (number of antenna IDs in the pattern) + uint8_t max_switching_pattern_len; + /// Max CTE length + uint8_t max_cte_len; +}; + +/// HCI command structure for the LE set periodic advertising receive enable command +/*@TRACE*/ +struct hci_le_set_per_adv_rec_en_cmd +{ + /// Sync handle + uint16_t sync_hdl; + /// Enable + uint8_t en; +}; + +/// HCI command structure for the LE set periodic advertising receive enable command +/*@TRACE*/ +struct hci_le_per_adv_sync_transf_cmd +{ + /// Connection handle + uint16_t conhdl; + /// Service data (value provided by the Host) + uint16_t serv_data; + /// Sync handle + uint16_t sync_hdl; +}; + +/// HCI command structure for the LE Periodic Advertising Set Info Transfer command +/*@TRACE*/ +struct hci_le_per_adv_set_info_transf_cmd +{ + /// Connection handle + uint16_t conhdl; + /// Service data (value provided by the Host) + uint16_t serv_data; + /// Advertising handle + uint8_t adv_hdl; +}; + +/// HCI command structure for the LE Set Periodic Advertising Sync Transfer Parameters command +/*@TRACE*/ +struct hci_le_set_per_adv_sync_transf_param_cmd +{ + /// Connection handle + uint16_t conhdl; + /// Mode (@see enum per_adv_sync_info_rec_mode) + uint8_t mode; + /// The number of periodic advertising packets that can be skipped after a successful receive + uint16_t skip; + /// Sync timeout (Time=N*10ms) + uint16_t sync_to; + /// CTE type (@see enum sync_cte_type) + uint8_t cte_type; +}; + +/// HCI command structure for the LE Set Default Periodic Advertising Sync Transfer Parameters command +/*@TRACE*/ +struct hci_le_set_dft_per_adv_sync_transf_param_cmd +{ + /// Mode (@see enum per_adv_sync_info_rec_mode) + uint8_t mode; + /// The number of periodic advertising packets that can be skipped after a successful receive + uint16_t skip; + /// Sync timeout (Time=N*10ms) + uint16_t sync_to; + /// CTE type (@see enum sync_cte_type) + uint8_t cte_type; +}; + +/// HCI command structure for the LE Periodic Advertising Sync Transfer Received event +/*@TRACE*/ +struct hci_le_per_adv_sync_transf_rec_evt +{ + /// LE Subevent code + uint8_t subcode; + /// Status + uint8_t status; + /// Connection handle + uint16_t conhdl; + /// Service data (value provided by the Host) + uint16_t serv_data; + /// Sync handle + uint16_t sync_hdl; + /// Advertising SID + uint8_t adv_sid; + ///Advertising address type: public/random + uint8_t adv_addr_type; + ///Advertising address value + struct bd_addr adv_addr; + /// Advertiser PHY (@enum le_phy_value) + uint8_t phy; + /// Advertising interval (Time=N*1.25ms) + uint16_t interval; + /// Advertiser clock accuracy (@see enum SCA) + uint8_t adv_ca; +}; + + +/* + * HCI VENDOR SPECIFIC COMMANDS PARAMETERS + **************************************************************************************** + */ + +/// Buffer structure +/*@TRACE*/ +struct buffer_tag +{ + /// length of buffer + uint8_t length; + /// data of 128 bytes length + uint8_t data[128]; +}; + +/// Common structure for Command Complete Event of HCI Debug Read Memory/Flash/Param complete event parameters - vendor specific +/*@TRACE + * hci_dbg_rd_mem_cmd_cmp_evt = hci_dbg_basic_rd_data_cmd_cmp_evt + * hci_dbg_rd_flash_cmd_cmp_evt = hci_dbg_basic_rd_data_cmd_cmp_evt + * hci_dbg_rd_par_cmd_cmp_evt = hci_dbg_basic_rd_data_cmd_cmp_evt + * */ +struct hci_dbg_basic_rd_data_cmd_cmp_evt +{ + ///Status + uint8_t status; + ///buffer structure to return + struct buffer_tag buf; +}; + +///HCI Debug read memory variable command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_rd_mem_cmd +{ + ///Start address to read + uint32_t start_addr; + ///Access size + uint8_t type; + ///Length to read + uint8_t length; +}; + +///HCI Debug write memory variable command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_wr_mem_cmd +{ + ///Start address to read + uint32_t start_addr; + ///Access size + uint8_t type; + ///buffer structure to return + struct buffer_tag buf; +}; + +///HCI Debug delete parameter command parameters - vendor specific +/*@TRACE + * hci_dbg_del_par_cmd = hci_dbg_del_param_cmd*/ +struct hci_dbg_del_param_cmd +{ + ///Parameter tag + uint16_t param_tag; +}; + +///HCI Debug erase flash command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_er_flash_cmd +{ + ///Flash type + uint8_t flashtype; + ///Start offset address + uint32_t startoffset; + ///Size to erase + uint32_t size; +}; + +///HCI Debug write flash command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_wr_flash_cmd +{ + ///Flash type + uint8_t flashtype; + ///Start offset address + uint32_t startoffset; + ///buffer structure + struct buffer_tag buf; +}; + +///HCI Debug read flash command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_rd_flash_cmd +{ + ///Flash type + uint8_t flashtype; + ///Start offset address + uint32_t startoffset; + ///Size to read + uint8_t size; +}; + +///HCI Debug read parameter command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_rd_par_cmd +{ + ///Parameter tag + uint16_t param_tag; +}; + +///HCI Debug read parameters command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_wr_par_cmd +{ + ///Parameter tag + uint16_t param_tag; + ///Structure buffer + struct buffer_tag buf; +}; + +#if CRYPTO_UT +///HCI Debug Test cryptographic functions command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_test_crypto_func_cmd +{ + /// Id of Function to be tested + uint8_t function; + /// Structure buffer + struct buffer_tag buf; +}; +#endif //CRYPTO_UT + +#if (BT_READ_PICONET_CLOCK) +struct hci_vs_rd_piconet_clock_cmd +{ + ///Connection handle of the link + uint16_t conhdl; + ///Pulse trigger management + uint8_t trig_pulse; + ///Clock type (0=native clock, 1=piconet clock of conhndl) + uint8_t clk_type; +}; + +struct hci_vs_rd_piconet_clock_cmd_cmp_evt +{ + /// Status + uint8_t status; + ///Connection handle of the link + uint16_t conhdl; + /// Local timestamp(position in half slots) + uint32_t loc_clk_hslt; + /// Local timestamp fractional part (in half us) + uint16_t loc_clk_hus; + /// Piconet timestamp(position in half slots) + uint32_t pic_clk_off_hslt; + /// Piconet bit offset (in half us) + uint16_t pic_bit_off_hus; +}; +#endif //(BT_READ_PICONET_CLOCK) + + +#if RW_DEBUG +///HCI Debug Test scheduling planner set function command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_test_sch_plan_set_cmd +{ + /// Activity identifier + uint32_t id; + /// Interval (in slots) + uint32_t interval; + /// Offset (in slots) + uint32_t offset; + /// Minimum duration (in slots) + uint32_t duration_min; + /// Maximum duration (in slots) + uint32_t duration_max; + /// Indicate activity is movable + bool mobility_level; +}; + +///HCI Debug Test scheduling planner set function command complete event parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_test_sch_plan_set_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Activity identifier + uint32_t moved_id; +}; + +///HCI Debug Test scheduling planner remove function command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_test_sch_plan_rem_cmd +{ + /// Activity identifier + uint32_t id; +}; + +///HCI Debug Test scheduling planner check function command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_test_sch_plan_chk_cmd +{ + /// Activity identifier + uint32_t id; + /// Interval (in slots) + uint32_t interval; + /// Offset (in slots) + uint32_t offset; + /// Minimum duration (in slots) + uint32_t duration_min; +}; + +///HCI Debug Test scheduling planner request function command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_test_sch_plan_req_cmd +{ + /// Activity identifier + uint32_t id; + /// Minimum interval (in slots) + uint32_t interval_min; + /// Maximum interval (in slots) + uint32_t interval_max; + /// Minimum duration (in slots) + uint32_t duration_min; + /// Maximum duration (in slots) + uint32_t duration_max; + /// Period (in slots) + uint8_t period; +}; + +///HCI Debug Test scheduling planner request function command complete event parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_test_sch_plan_req_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Interval (in slots) + uint32_t interval; + /// Minimum offset (in slots) + uint32_t offset_min; + /// Maximum offset (in slots) + uint32_t offset_max; +}; +#endif //RW_DEBUG + +///HCI Debug Read Kernel Statistics complete event parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_rd_ke_stats_cmd_cmp_evt +{ + ///Status + uint8_t status; + ///Max message sent + uint8_t max_msg_sent; + ///Max message saved + uint8_t max_msg_saved; + ///Max timer used + uint8_t max_timer_used; + ///Max heap used + uint16_t max_heap_used; + ///Max stack used + uint16_t max_stack_used; +}; + + +/// HCI Debug Read information about memory usage. - vendor specific +/*@TRACE*/ +struct hci_dbg_rd_mem_info_cmd_cmp_evt +{ + ///Status + uint8_t status; + /// memory size currently used into each heaps. + uint16_t mem_used[KE_MEM_BLOCK_MAX]; + /// peak of memory usage measured + uint32_t max_mem_used; +}; + +///HCI Debug identify Flash command complete event parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_id_flash_cmd_cmp_evt +{ + ///Status + uint8_t status; + ///Flash identity + uint8_t flash_id; +}; + +///HCI Debug RF Register read command +/*@TRACE*/ +struct hci_dbg_rf_reg_rd_cmd +{ + /// register address + uint16_t addr; +}; + +///HCI Debug RF Register read command complete event +/*@TRACE*/ +struct hci_dbg_rf_reg_rd_cmd_cmp_evt +{ + /// status + uint8_t status; + /// register address + uint16_t addr; + /// register value + uint32_t value; +}; + +///HCI Debug RF Register write command +/*@TRACE*/ +struct hci_dbg_rf_reg_wr_cmd +{ + /// register address + uint16_t addr; + /// register value + uint32_t value; +}; + +///HCI Debug RF Register write command complete event +/*@TRACE*/ +struct hci_dbg_rf_reg_wr_cmd_cmp_evt +{ + /// status + uint8_t status; + /// address + uint16_t addr; +}; + +///HCI Debug platform reset command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_plf_reset_cmd +{ + /// reason + uint8_t reason; +}; + +#if (RW_DEBUG && BT_EMB_PRESENT) +/// Send LMP Packets +/*@TRACE*/ +struct hci_dbg_bt_send_lmp_cmd +{ + /// Connection handle + uint16_t conhdl; + ///buffer structure to return + struct buffer_tag buf; +}; + +/// Discard LMP Packets +/*@TRACE*/ +struct hci_dbg_bt_discard_lmp_en_cmd +{ + /// Connection handle + uint16_t conhdl; + /// Enable/Disable LMP discard (0: disable / 1: enable) + uint8_t enable; +}; + +/// Set local clock +/*@TRACE*/ +struct hci_dbg_set_local_clock_cmd +{ + /// Clock (in half-slots) + uint32_t clock; +}; +#endif //(RW_DEBUG && BT_EMB_PRESENT) + +#if (RW_WLAN_COEX) +///HCI Debug wlan coexistence command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_wlan_coex_cmd +{ + /// State + uint8_t state; +}; +#if (RW_WLAN_COEX_TEST) +///HCI Debug wlan coexistence test scenario command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_wlan_coextst_scen_cmd +{ + /// Scenario + uint32_t scenario; +}; +#endif //RW_WLAN_COEX_TEST +#endif //RW_WLAN_COEX + +#if (RW_MWS_COEX) +///HCI Debug mws coexistence command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_mws_coex_cmd +{ + /// State + uint8_t state; +}; +#if (RW_MWS_COEX_TEST) +///HCI Debug mws coexistence test scenario command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_mws_coextst_scen_cmd +{ + /// Scenario + uint32_t scenario; +}; +#endif //RW_MWS_COEX_TEST +#endif //RW_MWS_COEX + +#if BLE_IQ_GEN +///HCI Debug I&Q samples generator command parameters - vendor specific +/// Maximum number of supported antenna patterns +#define DBG_IQGEN_MAX_ANTENNA (8) +/*@TRACE*/ +struct hci_dbg_iqgen_cfg_cmd +{ + /// Number of antenna patterns + uint8_t nb_antenna; + /// Antenna switch/sample control + // bit[0]: 0: up-sweep; 1: up-down sweep (internal switching mode) + // bit[1]: 0: 1us intervals; 1: 2us intervals (internal switching mode) + // bit[2]: 0: internal switching mode; 1: baseband switching mode + uint8_t mode; + /// I/Q sample control + struct + { + /// I-sample control + /// 0: up-count from 0x01 + /// 1: down-count from 0xFF + /// 2: Fixed value 0x00 + /// 3: PRBS pattern + /// 4..0xFF: Fixed value + uint8_t i; + /// Q-sample control + /// 0: up-count from 0x01 + /// 1: down-count from 0xFF + /// 2: Fixed value 0x00 + /// 3: PRBS pattern + /// 4..0xFF: Fixed value + uint8_t q; + } iq_ctrl[DBG_IQGEN_MAX_ANTENNA]; +}; +#endif //BLE_IQ_GEN + +#if (BLE_ISO_MODE_0) +/// HCI VS Setup Audio Mode 0 channel command parameters +/*@TRACE*/ +struct hci_vs_setup_am0_chan_cmd +{ + /// Handle that identify an ACL link between a Master and a Slave device that is requesting + /// an Audio Mode 0 Channel (range 0x0000-0x0EFF) + uint16_t conhdl; + + // *** Data path settings *** + /// Host to Controller nominal data rate in octets per second + uint32_t tx_bandwidth; + /// Controller to Host nominal data rate in octets per second + uint32_t rx_bandwidth; + /// Host to Controller Data path type + /// 0x00 Disabled + /// 0x01 HCI + /// 0x02-0xFE Logical_Channel_Number. The meaning of the logical channels will be vendor specific. + /// 0xFF Test Mode + uint8_t tx_data_path; + /// Controller to Host Data path type + /// 0x00 Disabled + /// 0x01 HCI + /// 0x02-0xFE Logical_Channel_Number. The meaning of the logical channels will be vendor specific. + /// 0xFF Test Mode + uint8_t rx_data_path; + /// The number of bits in each unit of data received from the Host over the data transport. (Range 0x01 - 0xFB) + uint8_t tx_size; + /// The number of bits in each unit of data sent to the Host over the data transport. (Range 0x01 - 0xFB) + uint8_t rx_size; +}; + +/// Used to read the maximum size of the data portion of isochronous packets +/// no parameter on command, only need to specify returned parameters +struct hci_vs_setup_am0_chan_cmd_cmp_evt +{ + /// 0x00 - Request succeed ; 0x01-0xFF Failed reason + uint8_t status; + /// Handle that identify an ACL link between a Master and a Slave device that is requesting + /// an Audio Mode 0 Channel (range 0x0000-0x0EFF) + uint16_t conhdl; + /// Channel_Handle to be used to identify an Audio Mode 0 Channel (range 0x0000-0x0EFF) + uint16_t am0_hdl; +}; + + +/// Removes existing Audio Mode 0 channel command parameters +/*@TRACE*/ +struct hci_vs_remove_am0_chan_cmd +{ + /// Channel_Handles used to identify Audio Mode 0 Channel (range 0x0000-0x0EFF) + uint16_t am0_hdl; +}; + + +/// Used to Control the channel that will b.e part of an Audio Mode 0 Connection +/*@TRACE*/ +struct hci_vs_control_am0_chan_cmd +{ + /// Channel_Handles used to identify Audio Mode 0 Channel (range 0x0000-0x0EFF) + uint16_t am0_hdl; + /// Control if the stream should be Enabled (0x01) or Disabled (0x00) + uint8_t enable; + /// Control if slave audio source is enabled or not + uint8_t slv_src_enable; +}; + +/// HCI basic command complete event structure with AM0 Channel handle +/*@TRACE*/ +struct hci_vs_basic_am0_cmd_cmp_evt +{ + /// status + uint8_t status; + /// Channel_Handles used to identify Audio Mode 0 Channel (range 0x0000-0x0EFF) + uint16_t am0_hdl; +}; +#endif // (BLE_ISO_MODE_0) + + +///HCI Debug HW Register Read command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_ble_reg_rd_cmd +{ + /// register address + uint16_t reg_addr; +}; + +///HCI Debug HW Register write command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_ble_reg_wr_cmd +{ + /// register address + uint16_t reg_addr; + /// extra parameter + uint16_t reserved; + /// register value + uint32_t reg_value; +}; + +///HCI Debug HW Register Read Complete event parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_ble_reg_rd_cmd_cmp_evt +{ + /// status + uint8_t status; + /// register address + uint16_t reg_addr; + /// register value + uint32_t reg_value; +}; + +///HCI Debug HW Register Write Complete event parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_ble_reg_wr_cmd_cmp_evt +{ + /// status + uint8_t status; + /// register address + uint16_t reg_addr; +}; + +#if (BLE_EMB_PRESENT) +///HCI Vendor Specific Set Preferred Slave Latency command parameters +/*@TRACE*/ +struct hci_vs_set_pref_slave_latency_cmd +{ + /// Connection handle + uint16_t conhdl; + /// Preferred latency (in number of connection events) + uint16_t latency; +}; + +///HCI Vendor Specific Set Preferred Slave event duration command parameters +/*@TRACE*/ +struct hci_vs_set_pref_slave_evt_dur_cmd +{ + /// Connection handle + uint16_t conhdl; + /// Preferred event duration (N * 0.625 ms) + uint16_t duration; + /// Slave transmits a single packet per connection event (False/True) + uint8_t single_tx; +}; + +///HCI Vendor Specific Set Maximum RX size and time command parameters +/*@TRACE*/ +struct hci_vs_set_max_rx_size_and_time_cmd +{ + /// Connection handle + uint16_t conhdl; + /// Maximum RX size (in B) + uint16_t rx_octets; + /// Maximum RX time (in us) + uint16_t rx_time; +}; + +/// Send LLCP Packets +/*@TRACE*/ +struct hci_dbg_send_llcp_cmd +{ + /// Connection handle + uint16_t conhdl; + ///buffer structure to return + struct buffer_tag buf; +}; + +///HCI Debug LLC discard command parameters - vendor specific +/*@TRACE*/ +struct hci_dbg_llcp_discard_cmd +{ + /// Handle pointing to the connection for which LLCP commands have to be discarded + uint16_t conhdl; + /// Flag indicating if the discarding has to be enabled or disabled + uint8_t enable; +}; +#endif //BLE_EMB_PRESENT + +#if (RW_DEBUG) +/// HCI DBG Meta Event indicating a SW assertion +//TODO[AAL] exception (associated to HCI_DBG_EVT) +/*@TRACE*/ +struct hci_dbg_assert_evt +{ + ///DBG Subevent code + uint8_t subcode; + /// Assert type (warning/error) + //@trc_ref assert_type + uint8_t type; + /// Line number + uint32_t line; + /// Param0 + uint32_t param0; + /// Param1 + uint32_t param1; + /// File name + uint8_t file[__ARRAY_EMPTY]; +}; +#endif //(RW_DEBUG) + +#if(BLE_ISOGEN) +/// Event is used to provide statistics about ISO Gen +/*@TRACE*/ +struct hci_vs_isogen_stat_evt +{ + /// VS Subevent code + uint8_t subcode; + + /// ISO Handle of the isochronous channel (Range 0x0000-0x0EFF) + uint16_t iso_hdl; + + /// Statistics - Number of transmission attempts + uint32_t nb_tx; + /// Statistics - Number of transmission attempts that succeed + uint32_t nb_tx_ok; + /// Statistics - Number of Not granted packet packets + uint32_t nb_tx_not_granted; + + /// Statistics - Number of reception attempt + uint32_t nb_rx; + /// Statistics - Number of reception attempts that succeed + uint32_t nb_rx_ok; + /// Statistics - Number of Not granted packet packets + uint32_t nb_rx_not_granted; + /// Statistics - Number of wrongly received packet (invalid data) + uint32_t nb_rx_data_err; + /// Statistics - Number of CRC Errors + uint32_t nb_rx_crc_err; + /// Statistics - Number of SYNC Errors + uint32_t nb_rx_sync_err; + /// Statistics - Number of received empty packets + uint32_t nb_rx_empty; +}; +#endif // (BLE_ISOGEN) + + +/// HCI LE Read PHY command +/*@TRACE*/ +struct hci_le_rd_phy_cmd +{ + /// Connection Handle + uint16_t conhdl; +}; + +/// HCI LE Set Default PHY Command +/*@TRACE*/ +struct hci_le_set_dft_phy_cmd +{ + /// Preferred PHYS selection + uint8_t all_phys; + /// Preferred PHYS for TX + uint8_t tx_phys; + /// Preferred PHYS for RX + uint8_t rx_phys; +}; + +/// HCI LE Set PHY Command +/*@TRACE*/ +struct hci_le_set_phy_cmd +{ + /// Connection Handle + uint16_t conhdl; + /// Preferred PHYS selection + uint8_t all_phys; + /// Preferred PHYS for TX + uint8_t tx_phys; + /// Preferred PHYS for RX + uint8_t rx_phys; + /// PHY options + uint16_t phy_opt; +}; + +/// HCI LE Set Extended Advertising Parameters Command Complete Event +/*@TRACE*/ +struct hci_le_set_ext_adv_param_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Selected Tx power + int8_t sel_tx_pwr; +}; + +/// HCI LE Receiver Test v2 Command +/*@TRACE*/ +struct hci_le_rx_test_v2_cmd +{ + /// RX channel, range: 0x00 to 0x27 + uint8_t rx_channel; + /// PHY (@enum le_phy_value) + uint8_t phy; + /// Modulation index (0: standard | 1: stable) + uint8_t mod_idx; +}; + +/// HCI LE Transmitter Test v2 Command +/*@TRACE*/ +struct hci_le_tx_test_v2_cmd +{ + /// TX channel, range: 0x00 to 0x27 + uint8_t tx_channel; + /// Length of test data in bytes, range: 0x00 to 0xFF + uint8_t test_data_len; + /** + * Packet payload + * 0x00 PRBS9 sequence "11111111100000111101" (in transmission order) as described in [Vol 6] Part F, Section 4.1.5 + * 0x01 Repeated "11110000" (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x02 Repeated "10101010" (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x03 PRBS15 sequence as described in [Vol 6] Part F, Section 4.1.5 + * 0x04 Repeated "11111111" (in transmission order) sequence + * 0x05 Repeated "00000000" (in transmission order) sequence + * 0x06 Repeated "00001111" (in transmission order) sequence + * 0x07 Repeated "01010101" (in transmission order) sequence + * 0x08-0xFF Reserved for future use + */ + uint8_t pkt_payl; + /// PHY (@enum le_phy_value) + uint8_t phy; +}; + +///HCI LE Set Advertising Set Random Address Command parameters structure +/*@TRACE*/ +struct hci_le_set_adv_set_rand_addr_cmd +{ + /// Advertising handle + uint8_t adv_hdl; + /// Advertising random address + struct bd_addr rand_addr; +}; + +///HCI LE Set Extended Advertising Parameters Command parameters structure +/*@TRACE*/ +struct hci_le_set_ext_adv_param_cmd +{ + /// Advertising handle + uint8_t adv_hdl; + /// Advertising event properties + uint16_t adv_evt_properties; + /// Primary advertising minimum interval + uint8_t prim_adv_intv_min[3]; + /// Primary advertising maximum interval + uint8_t prim_adv_intv_max[3]; + /// Primary advertising channel map + uint8_t prim_adv_chnl_map; + /// Own address type: public=0 / random=1 / rpa_or_pub=2 / rpa_or_rnd=3 + uint8_t own_addr_type; + /// Peer address type: public=0 / random=1 + uint8_t peer_addr_type; + /// Peer Bluetooth device address + struct bd_addr peer_addr; + /// Advertising filter policy + uint8_t adv_filt_policy; + /// Advertising Tx power + int8_t adv_tx_pwr; + /// Primary advertising PHY + uint8_t prim_adv_phy; + /// Secondary advertising max skip + uint8_t sec_adv_max_skip; + /// Secondary advertising PHY + uint8_t sec_adv_phy; + /// Advertising SID + uint8_t adv_sid; + /// Scan request notification enable + uint8_t scan_req_notif_en; +}; + +///HCI LE Set Extended Advertising Data Command parameters structure +/*@TRACE*/ +struct hci_le_set_ext_adv_data_cmd +{ + /// Advertising handle + uint8_t adv_hdl; + /** + * Operation + * 0x00 Intermediate fragment of fragmented extended advertising data + * 0x01 First fragment of fragmented extended advertising data + * 0x02 Last fragment of fragmented extended advertising data + * 0x03 Complete extended advertising data + * 0x04 [ID7300_r06] Unchanged data (just update the Advertising DID) + * All other values Reserved for future use + */ + uint8_t operation; + /** + * Fragment preference + * 0x00 The Controller may fragment all Host advertising data + * 0x01 The Controller should not fragment nor minimize fragmentation of Host advertising data + * All other values Reserved for future use + */ + uint8_t frag_pref; + /// Advertising Data Length (0-252 bytes) + uint8_t data_len; + /// Advertising data + uint8_t data[__ARRAY_EMPTY]; +}; + +///HCI LE Set Extended Scan Response Data Command parameters structure +/*@TRACE*/ +struct hci_le_set_ext_scan_rsp_data_cmd +{ + /// Advertising handle + uint8_t adv_hdl; + /** + * Operation + * 0x00 Intermediate fragment of fragmented extended advertising data + * 0x01 First fragment of fragmented extended advertising data + * 0x02 Last fragment of fragmented extended advertising data + * 0x03 Complete extended advertising data + * 0x04 [ID7300_r06] Unchanged data (just update the Advertising DID) + * All other values Reserved for future use + */ + uint8_t operation; + /** + * Fragment preference + * 0x00 The Controller may fragment all Host advertising data + * 0x01 The Controller should not fragment nor minimize fragmentation of Host advertising data + * All other values Reserved for future use + */ + uint8_t frag_pref; + /// Scan Response Data Length (0-252 bytes) + uint8_t data_len; + /// Advertising data + uint8_t data[__ARRAY_EMPTY]; +}; + +#if BLE_EMB_PRESENT || BLE_HOST_PRESENT +///HCI LE Set Extended Advertising Enable Command parameters structure +/*@TRACE*/ +struct hci_le_set_ext_adv_en_cmd +{ + /// Enable + uint8_t enable; + /// Number of sets (1 - 0x3F) + uint8_t nb_sets; + /// Advertising handle + uint8_t adv_hdl[BLE_ACTIVITY_MAX]; + /// Duration (N * 10 ms), 0x0000 No advertising duration. Advertising to continue until the Host disables it. + uint16_t duration[BLE_ACTIVITY_MAX]; + /// Maximum number of extended advertising events + uint8_t max_ext_adv_evt[BLE_ACTIVITY_MAX]; +}; +#endif //BLE_EMB_PRESENT || BLE_HOST_PRESENT + +///HCI LE Read Maximum Advertising Data Length Command complete event +/*@TRACE*/ +struct hci_le_rd_max_adv_data_len_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Maximum advertising data length + uint16_t max_adv_data_len; +}; + +///HCI LE Remove Advertising Set Command parameters structure +/*@TRACE + * hci_le_rmv_adv_set_cmd = hci_le_rem_adv_set_cmd*/ +struct hci_le_rem_adv_set_cmd +{ + /// Advertising handle + uint8_t adv_hdl; +}; + +///HCI LE Read Number of Supported Advertising Sets Command complete event +/*@TRACE*/ +struct hci_le_rd_nb_supp_adv_sets_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Number of supported advertising sets + uint8_t nb_supp_adv_sets; +}; + +///HCI LE Read Transmit Power Command complete event +/*@TRACE*/ +struct hci_le_rd_tx_pwr_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// Minimum TX Power + uint8_t min_tx_pwr; + /// Maximum TX Power + uint8_t max_tx_pwr; +}; + +///HCI LE Read RF Path Compensation Command complete event +/*@TRACE*/ +struct hci_le_rd_rf_path_comp_cmd_cmp_evt +{ + /// Status + uint8_t status; + /// RF TX Path Compensation + int16_t tx_path_comp; + /// RF RX Path Compensation + int16_t rx_path_comp; +}; + +///HCI LE Write RF Path Compensation Command complete event +/*@TRACE*/ +struct hci_le_wr_rf_path_comp_cmd +{ + /// RF TX Path Compensation + int16_t tx_path_comp; + /// RF RX Path Compensation + int16_t rx_path_comp; +}; + +///HCI LE Set Periodic Advertising Parameters Command parameters structure +/*@TRACE*/ +struct hci_le_set_per_adv_param_cmd +{ + /// Advertising handle + uint8_t adv_hdl; + /// Minimum advertising interval for periodic advertising + uint16_t adv_intv_min; + /// Maximum advertising interval for periodic advertising + uint16_t adv_intv_max; + /// Advertising properties + uint16_t adv_prop; +}; + +///HCI LE Set Periodic Advertising Data Command parameters structure +/*@TRACE*/ +struct hci_le_set_per_adv_data_cmd +{ + /// Advertising handle + uint8_t adv_hdl; + /** + * Operation + * 0x00 Intermediate fragment of fragmented periodic advertising data + * 0x01 First fragment of fragmented periodic advertising data + * 0x02 Last fragment of fragmented periodic advertising data + * 0x03 Complete periodic advertising data + * All other values Reserved for future use + */ + uint8_t operation; + /// Advertising Data Length (0-252 bytes) + uint8_t data_len; + /// Advertising data + uint8_t data[__ARRAY_EMPTY]; +}; + +///HCI LE Set Periodic Advertising Enable Command parameters structure +/*@TRACE*/ +struct hci_le_set_per_adv_en_cmd +{ + /// Enable + uint8_t enable; + /// Advertising handle + uint8_t adv_hdl; +}; + +///HCI LE Advertising Set Terminated event +/*@TRACE + * hci_le_adv_set_terminated_evt = hci_le_adv_set_term_evt*/ +struct hci_le_adv_set_term_evt +{ + /// LE Subevent code + uint8_t subcode; + /// Status + uint8_t status; + /// Advertising handle + uint8_t adv_hdl; + /// Connection handle + uint16_t conhdl; + /// Num_Completed_Extended_Advertising_Events + uint8_t nb_cmp_ext_adv_evt; +}; + +///HCI LE Scan Request Received event +/*@TRACE*/ +struct hci_le_scan_req_rcvd_evt +{ + /// LE Subevent code + uint8_t subcode; + /// Advertising handle + uint8_t adv_hdl; + /// Scanner address type: public=0 / random=1 / rpa_or_pub=2 / rpa_or_rnd=3 + uint8_t scan_addr_type; + /// Scanner address + struct bd_addr scan_addr; +}; + +///HCI LE Read Periodic Advertiser List Size Command complete event +/*@TRACE*/ +struct hci_le_rd_per_adv_list_size_cmd_cmp_evt +{ + ///Status + uint8_t status; + /// Periodic Advertiser List Size + uint8_t size; +}; + +///HCI LE Channel Selection Algorithm event +/*@TRACE*/ +struct hci_le_ch_sel_algo_evt +{ + /// LE Subevent code + uint8_t subcode; + /// Connection handle + uint16_t conhdl; + /// Channel selection algorithm + uint8_t ch_sel_algo; +}; + +/// HCI LE read PHY Command complete event +/*@TRACE*/ +struct hci_le_rd_phy_cmd_cmp_evt +{ + ///Status of received command + uint8_t status; + /// Connection Handle + uint16_t conhdl; + /// Current configured PHY for TX + //@trc_ref le_phy_value + uint8_t tx_phy; + /// Current configured PHY for RX + //@trc_ref le_phy_value + uint8_t rx_phy; +}; + +/// HCI LE PHY Update Complete event +/*@TRACE*/ +struct hci_le_phy_upd_cmp_evt +{ + ///LE Subevent code + uint8_t subcode; + ///Status of received command + uint8_t status; + ///Connection handle + uint16_t conhdl; + ///TX phy chosen + //@trc_ref le_phy_value + uint8_t tx_phy; + ///RX phy chosen + //@trc_ref le_phy_value + uint8_t rx_phy; +}; + +///HCI LE Connectionless IQ Report event +/*@TRACE*/ +struct hci_le_conless_iq_report_evt +{ + /// LE Subevent code + uint8_t subcode; + /// Sync handle + uint16_t sync_hdl; + /// Data channel index + uint8_t channel_idx; + /// RSSI (in 0.1 dBm) + int16_t rssi; + /// RSSI antenna ID + uint8_t rssi_antenna_id; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) + uint8_t cte_type; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Packet status + uint8_t pkt_status; + /// paEventCounter + uint16_t pa_evt_cnt; + /// Sample_count + uint8_t sample_cnt; + /// I/Q sample + struct + { + /// I sample + int8_t i; + /// Q sample + int8_t q; + } iq_sample[MAX_SAMPLE_CNT]; +}; + +///HCI LE Connection IQ Report event +/*@TRACE*/ +struct hci_le_con_iq_report_evt +{ + /// LE Subevent code + uint8_t subcode; + /// Connection handle + uint16_t conhdl; + /// Rx PHY (@see enum le_phy_value) + uint8_t rx_phy; + /// Data channel index + uint8_t data_channel_idx; + /// RSSI (in 0.1 dBm) + int16_t rssi; + /// RSSI antenna ID + uint8_t rssi_antenna_id; + /// CTE type (0: AOA | 1: AOD-1us | 2: AOD-2us) + uint8_t cte_type; + /// Slot durations (1: 1us | 2: 2us) + uint8_t slot_dur; + /// Packet status + uint8_t pkt_status; + /// connEventCounter + uint16_t con_evt_cnt; + /// Sample_count + uint8_t sample_cnt; + /// I/Q sample + struct + { + /// I sample + int8_t i; + /// Q sample + int8_t q; + } iq_sample[MAX_SAMPLE_CNT]; +}; + +///HCI LE CTE Request Failed event +/*@TRACE*/ +struct hci_le_cte_req_failed_evt +{ + /// LE Subevent code + uint8_t subcode; + /// Status + uint8_t status; + /// Connection handle + uint16_t conhdl; +}; + +struct hci_naz_unblock_read_cmd +{ + /// status + uint8_t value; +}; + +/// @} CO_BT +#endif // CO_HCI_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_list.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_list.h new file mode 100644 index 0000000..c2050d8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_list.h @@ -0,0 +1,302 @@ +/** + **************************************************************************************** + * + * @file co_list.h + * + * @brief Common list structures definitions + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _CO_LIST_H_ +#define _CO_LIST_H_ + +/** + ***************************************************************************************** + * @defgroup CO_LIST List management + * @ingroup COMMON + * + * @brief List management. + * + * This module contains the list structures and handling functions. + * @{ + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include // standard definition +#include // boolean definition +#include // for NULL and size_t +#include "rwip_config.h" // stack configuration +#include "compiler.h" // for __INLINE + + +/* + * DEFINES + **************************************************************************************** + */ + +/// structure of a list element header +/*@TRACE*/ +struct co_list_hdr +{ + /// Pointer to next co_list_hdr + struct co_list_hdr *next; +}; + +/// simplify type name of list element header +typedef struct co_list_hdr co_list_hdr_t; + +/// structure of a list +struct co_list +{ + /// pointer to first element of the list + struct co_list_hdr *first; + /// pointer to the last element + struct co_list_hdr *last; + + #if (KE_PROFILING) + /// number of element in the list + uint32_t cnt; + /// max number of element in the list + uint32_t maxcnt; + /// min number of element in the list + uint32_t mincnt; + #endif //KE_PROFILING +}; + +/// simplify type name of list +typedef struct co_list co_list_t; + +/* + * MACROS + **************************************************************************************** + */ +/// pop a specific element from the list +#define CO_LIST_POP_ELT(list, elt) co_list_extract(&(list), &(elt->hdr)); + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Initialize a list to defaults values. + * + * @param list Pointer to the list structure. + **************************************************************************************** + */ +void co_list_init(struct co_list *list); + +/** + **************************************************************************************** + * @brief Construct a list of free elements representing a pool + * + * @param list Pointer to the list structure + * @param pool Pointer to the pool to be initialized + * @param elmt_size Size of one element of the pool + * @param elmt_cnt Nb of elements available in the pool + **************************************************************************************** + */ +void co_list_pool_init(struct co_list *list, + void *pool, + size_t elmt_size, + uint32_t elmt_cnt); + +/** + **************************************************************************************** + * @brief Add an element as last on the list. + * + * @param list Pointer to the list structure + * @param list_hdr Pointer to the header to add at the end of the list + * + **************************************************************************************** + */ +void co_list_push_back(struct co_list *list, struct co_list_hdr *list_hdr); + +/** + **************************************************************************************** + * @brief Append a sequence of elements at the end of a list. + * + * Note: the elements to append shall be linked together + * + * @param list Pointer to the list structure + * @param first_hdr Pointer to the first element to append + * @param last_hdr Pointer to the last element to append + **************************************************************************************** + */ +void co_list_push_back_sublist(struct co_list *list, struct co_list_hdr *first_hdr, struct co_list_hdr *last_hdr); + +/** + **************************************************************************************** + * @brief Add an element as first on the list. + * + * @param list Pointer to the list structure + * @param list_hdr Pointer to the header to add at the beginning of the list + **************************************************************************************** + */ +void co_list_push_front(struct co_list *list, struct co_list_hdr *list_hdr); + +/** + **************************************************************************************** + * @brief Extract the first element of the list. + * @param list Pointer to the list structure + * @return The pointer to the element extracted, and NULL if the list is empty. + **************************************************************************************** + */ +struct co_list_hdr *co_list_pop_front(struct co_list *list); + +/** + **************************************************************************************** + * @brief Search for a given element in the list, and extract it if found. + * + * @param list Pointer to the list structure + * @param list_hdr Element to extract + * + * @return true if the element is found in the list, false otherwise + **************************************************************************************** + */ +bool co_list_extract(struct co_list *list, struct co_list_hdr *list_hdr); + +/** + **************************************************************************************** + * @brief Extract an element when the previous element is known + * + * Note: the element to remove shall follow immediately the reference within the list + * + * @param list Pointer to the list structure + * @param elt_ref_hdr Pointer to the referenced element (NULL if element to extract is the first in the list) + * @param elt_to_rem_hdr Pointer to the element to be extracted + **************************************************************************************** + */ +void co_list_extract_after(struct co_list *list, struct co_list_hdr *elt_ref_hdr, struct co_list_hdr *elt_to_rem_hdr); + +/** + **************************************************************************************** + * @brief Extract a sub-list when the previous element is known + * + * Note: the elements to remove shall be linked together and follow immediately the reference element + * + * @param[in] list Pointer to the list structure + * @param[in] ref_hdr Pointer to the referenced element (NULL if first element to extract is first in the list) + * @param[in] last_hdr Pointer to the last element to extract () + **************************************************************************************** + */ +void co_list_extract_sublist(struct co_list *list, struct co_list_hdr *ref_hdr, struct co_list_hdr *last_hdr); + +/** + **************************************************************************************** + * @brief Searched a given element in the list. + * + * @param list Pointer to the list structure + * @param list_hdr Pointer to the searched element + * + * @return true if the element is found in the list, false otherwise + **************************************************************************************** + */ +bool co_list_find(struct co_list *list, struct co_list_hdr *list_hdr); + +/** + **************************************************************************************** + * @brief Merge two lists in a single one. + * + * This function appends the list pointed by list2 to the list pointed by list1. Once the + * merge is done, it empties list2. + * + * @param list1 Pointer to the destination list + * @param list2 Pointer to the list to append to list1 + **************************************************************************************** + */ +void co_list_merge(struct co_list *list1, struct co_list *list2); + +/** + **************************************************************************************** + * @brief Insert a given element in the list before the referenced element. + * + * @param list Pointer to the list structure + * @param elt_ref_hdr Pointer to the referenced element + * @param elt_to_add_hdr Pointer to the element to be inserted + * + * @return true if the element is found in the list, false otherwise + **************************************************************************************** + */ +void co_list_insert_before(struct co_list *list, + struct co_list_hdr *elt_ref_hdr, struct co_list_hdr *elt_to_add_hdr); + +/** + **************************************************************************************** + * @brief Insert a given element in the list after the referenced element. + * + * @param list Pointer to the list structure + * @param elt_ref_hdr Pointer to the referenced element + * @param elt_to_add_hdr Pointer to the element to be inserted + * + * @return true if the element is found in the list, false otherwise + **************************************************************************************** + */ +void co_list_insert_after(struct co_list *list, + struct co_list_hdr *elt_ref_hdr, struct co_list_hdr *elt_to_add_hdr); + + +/** + **************************************************************************************** + * @brief Count number of elements present in the list + * + * @param list Pointer to the list structure + * + * @return Number of elements present in the list + **************************************************************************************** + */ +uint16_t co_list_size(struct co_list *list); + +/** + **************************************************************************************** + * @brief Test if the list is empty. + * @param list Pointer to the list structure. + * @return true if the list is empty, false else otherwise. + **************************************************************************************** + */ +__INLINE bool co_list_is_empty(const struct co_list *const list) +{ + bool listempty; + listempty = (list->first == NULL); + return (listempty); +} + +/** + **************************************************************************************** + * @brief Pick the first element from the list without removing it. + * + * @param list Pointer to the list structure. + * + * @return First element address. Returns NULL pointer if the list is empty. + **************************************************************************************** + */ +__INLINE struct co_list_hdr *co_list_pick(const struct co_list *const list) +{ + return(list->first); +} + + +/** + **************************************************************************************** + * @brief Return following element of a list element. + * + * @param list_hdr Pointer to the list element. + * + * @return The pointer to the next element. + **************************************************************************************** + */ +__INLINE struct co_list_hdr *co_list_next(const struct co_list_hdr *const list_hdr) +{ + return(list_hdr->next); +} + +/// @} CO_LIST +#endif // _CO_LIST_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_llcp.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_llcp.h new file mode 100644 index 0000000..b75b69d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_llcp.h @@ -0,0 +1,734 @@ +/** + **************************************************************************************** + * + * @file co_llcp.h + * + * @brief This file contains the LLCP Bluetooth defines, enumerations and structures + * definitions for use by all modules in RW stack. + * + * Copyright (C) RivieraWaves 2009-2015 + * + **************************************************************************************** + */ + +#ifndef CO_LLCP_H_ +#define CO_LLCP_H_ + +/** + **************************************************************************************** + * @addtogroup CO_BT + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "co_bt.h" +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Control packet op_code +/*@TRACE*/ +enum co_llcp_op_code +{ + LL_CONNECTION_UPDATE_IND_OPCODE = 0x00, + LL_CHANNEL_MAP_IND_OPCODE = 0x01, + LL_TERMINATE_IND_OPCODE = 0x02, + LL_ENC_REQ_OPCODE = 0x03, + LL_ENC_RSP_OPCODE = 0x04, + LL_START_ENC_REQ_OPCODE = 0x05, + LL_START_ENC_RSP_OPCODE = 0x06, + LL_UNKNOWN_RSP_OPCODE = 0x07, + LL_FEATURE_REQ_OPCODE = 0x08, + LL_FEATURE_RSP_OPCODE = 0x09, + LL_PAUSE_ENC_REQ_OPCODE = 0x0A, + LL_PAUSE_ENC_RSP_OPCODE = 0x0B, + LL_VERSION_IND_OPCODE = 0x0C, + LL_REJECT_IND_OPCODE = 0x0D, + LL_SLAVE_FEATURE_REQ_OPCODE = 0x0E, + LL_CONNECTION_PARAM_REQ_OPCODE = 0x0F, + LL_CONNECTION_PARAM_RSP_OPCODE = 0x10, + LL_REJECT_EXT_IND_OPCODE = 0x11, + LL_PING_REQ_OPCODE = 0x12, + LL_PING_RSP_OPCODE = 0x13, + LL_LENGTH_REQ_OPCODE = 0x14, + LL_LENGTH_RSP_OPCODE = 0x15, + LL_PHY_REQ_OPCODE = 0x16, + LL_PHY_RSP_OPCODE = 0x17, + LL_PHY_UPDATE_IND_OPCODE = 0x18, + LL_MIN_USED_CHANNELS_IND_OPCODE = 0x19, + LL_CTE_REQ_OPCODE = 0x1A, + LL_CTE_RSP_OPCODE = 0x1B, + LL_PER_SYNC_IND_OPCODE = 0x1C, + LL_CLK_ACC_REQ_OPCODE = 0x1D, + LL_CLK_ACC_RSP_OPCODE = 0x1E, + + /// Opcode length + LL_OPCODE_MAX_OPCODE, + LL_OPCODE_DEBUG = 0xFF, +}; + +/// LLCP PDU lengths (including op_code) +enum co_llcp_length +{ + LL_CONNECTION_UPDATE_IND_LEN = 12, + LL_CHANNEL_MAP_IND_LEN = 8, + LL_TERMINATE_IND_LEN = 2, + LL_ENC_REQ_LEN = 23, + LL_ENC_RSP_LEN = 13, + LL_START_ENC_REQ_LEN = 1, + LL_START_ENC_RSP_LEN = 1, + LL_UNKNOWN_RSP_LEN = 2, + LL_FEATURE_REQ_LEN = 9, + LL_FEATURE_RSP_LEN = 9, + LL_PAUSE_ENC_REQ_LEN = 1, + LL_PAUSE_ENC_RSP_LEN = 1, + LL_VERSION_IND_LEN = 6, + LL_REJECT_IND_LEN = 2, + LL_SLAVE_FEATURE_REQ_LEN = 9, + LL_REJECT_EXT_IND_LEN = 3, + LL_CONNECTION_PARAM_REQ_LEN = 24, + LL_CONNECTION_PARAM_RSP_LEN = 24, + LL_PING_REQ_LEN = 1, + LL_PING_RSP_LEN = 1, + LL_LENGTH_REQ_LEN = 9, + LL_LENGTH_RSP_LEN = 9, + LL_PHY_REQ_LEN = 3, + LL_PHY_RSP_LEN = 3, + LL_PHY_UPDATE_IND_LEN = 5, + LL_MIN_USED_CHANNELS_IND_LEN = 3, + LL_CTE_REQ_LEN = 2, + LL_CTE_RSP_LEN = 1, + LL_PER_SYNC_IND_LEN = 35, + LL_CLK_ACC_REQ_LEN = 2, + LL_CLK_ACC_RSP_LEN = 2, + + LL_PDU_LENGTH_MAX = 35 +}; + +/// PDU lengths +enum co_pdu_length +{ + PDU_SCAN_REQ_LEN = 12, + PDU_CON_REQ_LEN = 34, + PDU_CON_RSP_LEN = 14, +}; + + +/// Bit field definitions for combination of advertising Set ID, advertiser address type and sleep clock accuracy in LL_PER_SYNC_IND +/// 7 6 5 4 3 2 1 0 +/// +----+----+----+-------+----+----+----+----+ +/// | SCA | AType | SID | +/// +----+----+----+-------+----+----+----+----+ +enum co_llcp_sid_atype_sca +{ + /// Advertising SID + LLCP_PER_SYNC_IND_SID_LSB = 0, + LLCP_PER_SYNC_IND_SID_MASK = (0x0F), + + /// Advertiser address type + LLCP_PER_SYNC_IND_ATYPE_POS = 4, + LLCP_PER_SYNC_IND_ATYPE_BIT = (0x10), + + /// Sleep clock accuracy (@see enum SCA) + LLCP_PER_SYNC_IND_SCA_LSB = 5, + LLCP_PER_SYNC_IND_SCA_MASK = (0xE0), +}; + +/* + * MESSAGES + **************************************************************************************** + */ + +/// LL_DEFAULT structure (for packet with no parameter) +/*@TRACE + * @NO_PAD +*/ +struct ll_default +{ + /// op_code + uint8_t op_code; +}; + +/// LL_CONNECTION_UPDATE_IND structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_connection_update_ind +{ + /// op_code + uint8_t op_code; + /// window size (units of 1.25 ms) + uint8_t win_size; + /// window offset (units of 1.25 ms) + uint16_t win_off; + /// interval (units of 1.25 ms) + uint16_t interv; + /// connection latency (unit of connection event) + uint16_t latency; + /// link supervision timeout (unit of 10 ms) + uint16_t timeout; + /// instant (unit of connection event) + uint16_t instant; +}; + +/// LL_CHANNEL_MAP_IND structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_channel_map_ind +{ + /// op_code + uint8_t op_code; + /// channel mapping + struct le_chnl_map ch_map; + /// instant + uint16_t instant; +}; + +/// LL_TERMINATE_IND structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_terminate_ind +{ + /// op_code + uint8_t op_code; + /// termination code + uint8_t err_code; +}; + +/// LL_ENC_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_enc_req +{ + /// op_code + uint8_t op_code; + /// random value + struct rand_nb rand; + /// ediv + uint16_t ediv; + /// skdm + struct sess_k_div_x skdm; + /// ivm + struct init_vect ivm; +}; + +/// LL_ENC_RSP structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_enc_rsp +{ + /// op_code + uint8_t op_code; + /// skds + struct sess_k_div_x skds; + /// ivs + struct init_vect ivs; +}; + +/// LL_START_ENC_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_start_enc_req +{ + /// op_code + uint8_t op_code; +}; + +/// LL_START_ENC_RSP structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_start_enc_rsp +{ + /// op_code + uint8_t op_code; +}; + +/// LL_UNKNOWN_RSP structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_unknown_rsp +{ + /// op_code + uint8_t op_code; + /// unknown type + uint8_t unk_type; +}; + +/// LL_FEATURE_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_feature_req +{ + /// op_code + uint8_t op_code; + /// le features + struct le_features feats; +}; + + +/// LL_FEATURE_RSP structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_feature_rsp +{ + /// op_code + uint8_t op_code; + /// le features + struct le_features feats; +}; + +/// LL_PAUSE_ENC_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_pause_enc_req +{ + /// op_code + uint8_t op_code; +}; + +/// LL_PAUSE_ENC_RSP structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_pause_enc_rsp +{ + /// op_code + uint8_t op_code; +}; + +/// LL_VERSION_IND structure +/*@TRACE + * @NO_PAD +*/ +struct ll_version_ind +{ + /// op_code + uint8_t op_code; + /// version + uint8_t vers; + /// company id + uint16_t compid; + /// sub version + uint16_t subvers; +}; + +/// LL_REJECT_IND structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_reject_ind +{ + /// op_code + uint8_t op_code; + /// reject reason + uint8_t err_code; +}; + +/// LL_SLAVE_FEATURE_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_slave_feature_req +{ + /// op_code + uint8_t op_code; + /// le features + struct le_features feats; +}; + +/// LL_CONNECTION_PARAM_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_connection_param_req +{ + /// op_code + uint8_t op_code; + /// minimum value of connInterval (units of 1.25 ms) + uint16_t interval_min; + /// maximum value of connInterval (units of 1.25 ms) + uint16_t interval_max; + /// connSlaveLatency value (unit of connection event) + uint16_t latency; + /// connSupervisionTimeout value (unit of 10 ms) + uint16_t timeout; + /// preferred periodicity (units of 1.25 ms) + uint8_t pref_period; + /// ReferenceConnEventCount (unit of connection event) + uint16_t ref_con_event_count; + /// Offset0 (units of 1.25 ms) + uint16_t offset0; + /// Offset1 (units of 1.25 ms) + uint16_t offset1; + /// Offset2 (units of 1.25 ms) + uint16_t offset2; + /// Offset3 (units of 1.25 ms) + uint16_t offset3; + /// Offset4 (units of 1.25 ms) + uint16_t offset4; + /// Offset5 (units of 1.25 ms) + uint16_t offset5; +}; + +/// LL_CONNECTION_PARAM_RSP structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_connection_param_rsp +{ + /// op_code + uint8_t op_code; + /// minimum value of connInterval (units of 1.25 ms) + uint16_t interval_min; + /// maximum value of connInterval (units of 1.25 ms) + uint16_t interval_max; + /// connSlaveLatency value (unit of connection event) + uint16_t latency; + /// connSupervisionTimeout value (unit of 10 ms) + uint16_t timeout; + /// preferred periodicity (units of 1.25 ms) + uint8_t pref_period; + /// ReferenceConnEventCount (unit of connection event) + uint16_t ref_con_event_count; + /// Offset0 (units of 1.25 ms) + uint16_t offset0; + /// Offset1 (units of 1.25 ms) + uint16_t offset1; + /// Offset2 (units of 1.25 ms) + uint16_t offset2; + /// Offset3 (units of 1.25 ms) + uint16_t offset3; + /// Offset4 (units of 1.25 ms) + uint16_t offset4; + /// Offset5 (units of 1.25 ms) + uint16_t offset5; +}; + +/// LL_REJECT_EXT_IND structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_reject_ext_ind +{ + /// op_code + uint8_t op_code; + /// rejected op_code + uint8_t rej_op_code; + /// reject reason + uint8_t err_code; +}; + +/// LL_PING_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_ping_req +{ + /// op_code + uint8_t op_code; +}; + +/// LL_PING_RSP structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_ping_rsp +{ + /// op_code + uint8_t op_code; +}; + +/// LL_LENGTH_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_length_req +{ + /// op_code + uint8_t op_code; + /// The max size in reception (unit of byte) + uint16_t max_rx_octets; + /// The max time in reception (unit of microsecond) + uint16_t max_rx_time; + /// The max size in transmission (unit of byte) + uint16_t max_tx_octets; + /// The max time in transmission (unit of microsecond) + uint16_t max_tx_time; +}; + +/// LL_LENGTH_RSP structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_length_rsp +{ + /// op_code + uint8_t op_code; + /// The max size in reception (unit of byte) + uint16_t max_rx_octets; + /// The max time in reception (unit of microsecond) + uint16_t max_rx_time; + /// The max size in transmission (unit of byte) + uint16_t max_tx_octets; + /// The max time in transmission (unit of microsecond) + uint16_t max_tx_time; +}; +/// LL_PHY_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_phy_req +{ + /// op_code + uint8_t op_code; + /// Tx phy selection + uint8_t tx_phys; + /// Rx phy selection + uint8_t rx_phys; +}; + +/// LL_PHY_RSP structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_phy_rsp +{ + /// op_code + uint8_t op_code; + /// Tx phy selection + uint8_t tx_phys; + /// Rx phy selection + uint8_t rx_phys; +}; + +/// LL_PHY_UPDATE_IND structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_phy_update_ind +{ + /// op_code + uint8_t op_code; + /// master to slave phy selected + uint8_t m_to_s_phy; + /// slave to master phy selected + uint8_t s_to_m_phy; + /// Instant + uint16_t instant; +}; + +/// LL_MIN_USED_CHANNELS_IND structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_min_used_channels_ind +{ + /// op_code + uint8_t op_code; + /// PHY(s) for which the slave has a minimum number of used channels requirement + uint8_t phys; + /// minimum number of channels to be used on the specified PHY + uint8_t min_used_ch; +}; + +/** + * CTE length and type bit field definition + * + * | 5 bits | 1b | 2 bits | + * | MinCTELenReq | RFU | CTETypeReq | + * + * - MinCTELenReq: minimum CTE length (x 8us) + * - CTETypeReq: 0-AoA, 1-AoD_1us, 2-AoD_2us, 3-RFU + */ +enum cte_len_type +{ + CTE_TYPE_REQ_MASK = 0xC0, + CTE_TYPE_REQ_LSB = 6, + + MIN_CTE_LEN_REQ_MASK = 0x1F, + MIN_CTE_LEN_REQ_LSB = 0, +}; + +/// LL_CTE_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_cte_req +{ + /// op_code + uint8_t op_code; + /// CTE length and type (@see enum cte_len_type) + uint8_t cte_len_type; +}; + +/// LL_PER_SYNC_IND structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_per_sync_ind +{ + /// op_code + uint8_t op_code; + /// ID (provided by the Host) + uint16_t id; + /// Sync Info (TODO ref definition or spec) + uint8_t sync_info[18]; + /// Connection event counter + uint16_t con_evt_cnt; + /// Last periodic advertising event counter + uint16_t last_pa_evt_cnt; + /// Advertising Set ID, advertiser address type and sleep clock accuracy + uint8_t sid_atype_sca; + /// Periodic advertising PHY (@see enum le_phy_mask) + uint8_t phy; + /// Periodic advertiser address + struct bd_addr adva; + /// Sync Connection event counter + uint16_t sync_con_evt_cnt; +}; + +/// LL_CLK_ACC_REQ structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_clk_acc_req +{ + /// op_code + uint8_t op_code; + /// SCA (@see enum SCA) + uint8_t sca; +}; + +/// LL_CLK_ACC_RSP structure. +/*@TRACE + * @NO_PAD +*/ +struct ll_clk_acc_rsp +{ + /// op_code + uint8_t op_code; + /// SCA (@see enum SCA) + uint8_t sca; +}; + +/// LLCP pdu format +/*@TRACE + @trc_ref co_llcp_op_code + */ +union llcp_pdu +{ + /// op_code + uint8_t op_code; + + //@trc_union op_code == LL_CONNECTION_UPDATE_IND_OPCODE + struct ll_connection_update_ind con_update_ind; + + //@trc_union op_code == LL_CHANNEL_MAP_IND_OPCODE + struct ll_channel_map_ind channel_map_ind; + + //@trc_union op_code == LL_TERMINATE_IND_OPCODE + struct ll_terminate_ind terminate_ind; + + //@trc_union op_code == LL_ENC_REQ_OPCODE + struct ll_enc_req enc_req; + + //@trc_union op_code == LL_ENC_RSP_OPCODE + struct ll_enc_rsp enc_rsp; + + //@trc_union op_code == LL_START_ENC_REQ_OPCODE + struct ll_start_enc_req start_enc_req; + + //@trc_union op_code == LL_START_ENC_RSP_OPCODE + struct ll_start_enc_rsp start_enc_rsp; + + //@trc_union op_code == LL_UNKNOWN_RSP_OPCODE + struct ll_unknown_rsp unknown_rsp; + + //@trc_union op_code == LL_FEATURE_REQ_OPCODE + struct ll_feature_req feats_req; + + //@trc_union op_code == LL_FEATURE_RSP_OPCODE + struct ll_feature_rsp feats_rsp; + + //@trc_union op_code == LL_PAUSE_ENC_REQ_OPCODE + struct ll_pause_enc_req pause_enc_req; + + //@trc_union op_code == LL_PAUSE_ENC_RSP_OPCODE + struct ll_pause_enc_rsp pause_enc_rsp; + + //@trc_union op_code == LL_VERSION_IND_OPCODE + struct ll_version_ind vers_ind; + + //@trc_union op_code == LL_REJECT_IND_OPCODE + struct ll_reject_ind reject_ind; + + //@trc_union op_code == LL_SLAVE_FEATURE_REQ_OPCODE + struct ll_slave_feature_req slave_feature_req; + + //@trc_union op_code == LL_CONNECTION_PARAM_REQ_OPCODE + struct ll_connection_param_req con_param_req; + + //@trc_union op_code == LL_CONNECTION_PARAM_RSP_OPCODE + struct ll_connection_param_rsp con_param_rsp; + + //@trc_union op_code == LL_REJECT_EXT_IND_OPCODE + struct ll_reject_ext_ind reject_ind_ext; + + //@trc_union op_code == LL_PING_REQ_OPCODE + struct ll_ping_req ping_req; + + //@trc_union op_code == LL_PING_RSP_OPCODE + struct ll_ping_rsp ping_rsp; + + //@trc_union op_code == LL_LENGTH_REQ_OPCODE + struct ll_length_req length_req; + + //@trc_union op_code == LL_LENGTH_RSP_OPCODE + struct ll_length_rsp length_rsp; + + //@trc_union op_code == LL_PHY_REQ_OPCODE + struct ll_phy_req phy_req; + + //@trc_union op_code == LL_PHY_RSP_OPCODE + struct ll_phy_rsp phy_rsp; + + //@trc_union op_code == LL_PHY_UPDATE_IND_OPCODE + struct ll_phy_update_ind phy_upd_ind; + + //@trc_union op_code == LL_MIN_USED_CHANNELS_IND_OPCODE + struct ll_min_used_channels_ind min_used_channels_ind; + + //@trc_union op_code == LL_CLK_ACC_REQ_OPCODE + struct ll_clk_acc_req clk_acc_req; + + //@trc_union op_code == LL_CLK_ACC_RSP_OPCODE + struct ll_clk_acc_rsp clk_acc_rsp; + + //@trc_union op_code == LL_PER_SYNC_IND_OPCODE + struct ll_per_sync_ind per_sync_ind; +}; + +/// @} CO_BT +#endif // CO_LLCP_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_lmp.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_lmp.h new file mode 100644 index 0000000..08705a9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_lmp.h @@ -0,0 +1,1566 @@ +/** + **************************************************************************************** + * + * @file co_lmp.h + * + * @brief This file contains the HCI Bluetooth defines, enumerations and structures + * definitions for use by all modules in RW stack. + * + * Copyright (C) RivieraWaves 2009-2015 + * + **************************************************************************************** + */ + +#ifndef CO_LMP_H_ +#define CO_LMP_H_ + +/** + **************************************************************************************** + * @addtogroup CO_BT + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "co_bt.h" +/* + * DEFINES + **************************************************************************************** + */ + +/// LMP Opcodes +/*@TRACE*/ +enum co_lmp_opcode +{ + LMP_NAME_REQ_OPCODE = 1 , + LMP_NAME_RES_OPCODE = 2 , + LMP_ACCEPTED_OPCODE = 3 , + LMP_NOT_ACCEPTED_OPCODE = 4 , + LMP_CLK_OFF_REQ_OPCODE = 5 , + LMP_CLK_OFF_RES_OPCODE = 6 , + LMP_DETACH_OPCODE = 7 , + LMP_INRAND_OPCODE = 8 , + LMP_COMBKEY_OPCODE = 9 , + LMP_UNITKEY_OPCODE = 10 , + LMP_AURAND_OPCODE = 11 , + LMP_SRES_OPCODE = 12 , + LMP_TEMPRAND_OPCODE = 13 , + LMP_TEMPKEY_OPCODE = 14 , + LMP_ENC_MODE_REQ_OPCODE = 15 , + LMP_ENC_KEY_SIZE_REQ_OPCODE = 16 , + LMP_START_ENC_REQ_OPCODE = 17 , + LMP_STOP_ENC_REQ_OPCODE = 18 , + LMP_SWITCH_REQ_OPCODE = 19 , + LMP_HOLD_OPCODE = 20 , + LMP_HOLD_REQ_OPCODE = 21 , + LMP_SNIFF_REQ_OPCODE = 23 , + LMP_UNSNIFF_REQ_OPCODE = 24 , + LMP_PARK_REQ_OPCODE = 25 , + LMP_SET_BSWIN_OPCODE = 27 , + LMP_MODIF_BEACON_OPCODE = 28 , + LMP_UNPARK_BD_REQ_OPCODE = 29 , + LMP_UNPARK_PM_REQ_OPCODE = 30 , + LMP_INCR_PWR_REQ_OPCODE = 31 , + LMP_DECR_PWR_REQ_OPCODE = 32 , + LMP_MAX_PWR_OPCODE = 33 , + LMP_MIN_PWR_OPCODE = 34 , + LMP_AUTO_RATE_OPCODE = 35 , + LMP_PREF_RATE_OPCODE = 36 , + LMP_VER_REQ_OPCODE = 37 , + LMP_VER_RES_OPCODE = 38 , + LMP_FEATS_REQ_OPCODE = 39 , + LMP_FEATS_RES_OPCODE = 40 , + LMP_QOS_OPCODE = 41 , + LMP_QOS_REQ_OPCODE = 42 , + LMP_SCO_LINK_REQ_OPCODE = 43 , + LMP_RMV_SCO_LINK_REQ_OPCODE = 44 , + LMP_MAX_SLOT_OPCODE = 45 , + LMP_MAX_SLOT_REQ_OPCODE = 46 , + LMP_TIMING_ACCU_REQ_OPCODE = 47 , + LMP_TIMING_ACCU_RES_OPCODE = 48 , + LMP_SETUP_CMP_OPCODE = 49 , + LMP_USE_SEMI_PERM_KEY_OPCODE = 50 , + LMP_HOST_CON_REQ_OPCODE = 51 , + LMP_SLOT_OFF_OPCODE = 52 , + LMP_PAGE_MODE_REQ_OPCODE = 53 , + LMP_PAGE_SCAN_MODE_REQ_OPCODE = 54 , + LMP_SUPV_TO_OPCODE = 55 , + LMP_TEST_ACTIVATE_OPCODE = 56 , + LMP_TEST_CTRL_OPCODE = 57 , + LMP_ENC_KEY_SIZE_MASK_REQ_OPCODE = 58 , + LMP_ENC_KEY_SIZE_MASK_RES_OPCODE = 59 , + LMP_SET_AFH_OPCODE = 60 , + LMP_ENCAPS_HDR_OPCODE = 61 , + LMP_ENCAPS_PAYL_OPCODE = 62 , + LMP_SP_CFM_OPCODE = 63 , + LMP_SP_NB_OPCODE = 64 , + LMP_DHKEY_CHK_OPCODE = 65 , + LMP_PAUSE_ENC_AES_REQ_OPCODE = 66 , + LMP_ESC1_OPCODE = 124, + LMP_ESC2_OPCODE = 125, + LMP_ESC3_OPCODE = 126, + LMP_ESC4_OPCODE = 127, +}; + +/// LMP Escape 4 Extended Opcodes +enum co_lmp_ext_opcode +{ + LMP_ACCEPTED_EXT_EXTOPCODE = 1, + LMP_NOT_ACCEPTED_EXT_EXTOPCODE = 2, + LMP_FEATS_REQ_EXT_EXTOPCODE = 3, + LMP_FEATS_RES_EXT_EXTOPCODE = 4, + LMP_CLK_ADJ_EXTOPCODE = 5, + LMP_CLK_ADJ_ACK_EXTOPCODE = 6, + LMP_CLK_ADJ_REQ_EXTOPCODE = 7, + LMP_PKT_TYPE_TBL_REQ_EXTOPCODE = 11, + LMP_ESCO_LINK_REQ_EXTOPCODE = 12, + LMP_RMV_ESCO_LINK_REQ_EXTOPCODE = 13, + LMP_CH_CLASS_REQ_EXTOPCODE = 16, + LMP_CH_CLASS_EXTOPCODE = 17, + LMP_SSR_REQ_EXTOPCODE = 21, + LMP_SSR_RES_EXTOPCODE = 22, + LMP_PAUSE_ENC_REQ_EXTOPCODE = 23, + LMP_RESUME_ENC_REQ_EXTOPCODE = 24, + LMP_IO_CAP_REQ_EXTOPCODE = 25, + LMP_IO_CAP_RES_EXTOPCODE = 26, + LMP_NUM_COMPARISON_FAIL_EXTOPCODE = 27, + LMP_PASSKEY_FAIL_EXTOPCODE = 28, + LMP_OOB_FAIL_EXTOPCODE = 29, + LMP_KEYPRESS_NOTIF_EXTOPCODE = 30, + LMP_PWR_CTRL_REQ_EXTOPCODE = 31, + LMP_PWR_CTRL_RES_EXTOPCODE = 32, + LMP_PING_REQ_EXTOPCODE = 33, + LMP_PING_RES_EXTOPCODE = 34, + LMP_SAM_SET_TYPE0_EXTOPCODE = 35, + LMP_SAM_DEFINE_MAP_EXTOPCODE = 36, + LMP_SAM_SWITCH_EXTOPCODE = 37, +}; + +/// PDU lengths (including opcode) +enum co_lmp_pdu_length +{ + LMP_NAME_REQ_LEN = 2 , + LMP_NAME_RES_LEN = 17, + LMP_ACCEPTED_LEN = 2 , + LMP_NOT_ACCEPTED_LEN = 3 , + LMP_CLK_OFF_REQ_LEN = 1 , + LMP_CLK_OFF_RES_LEN = 3 , + LMP_DETACH_LEN = 2 , + LMP_INRAND_LEN = 17, + LMP_COMBKEY_LEN = 17, + LMP_UNITKEY_LEN = 17, + LMP_AURAND_LEN = 17, + LMP_SRES_LEN = 5 , + LMP_TEMPRAND_LEN = 17, + LMP_TEMPKEY_LEN = 17, + LMP_ENC_MODE_REQ_LEN = 2 , + LMP_ENC_KEY_SIZE_REQ_LEN = 2 , + LMP_START_ENC_REQ_LEN = 17, + LMP_STOP_ENC_REQ_LEN = 1 , + LMP_SWITCH_REQ_LEN = 5 , + LMP_HOLD_LEN = 7 , + LMP_HOLD_REQ_LEN = 7 , + LMP_SNIFF_REQ_LEN = 10, + LMP_UNSNIFF_REQ_LEN = 1 , + LMP_PARK_REQ_LEN = 17, + LMP_INCR_PWR_REQ_LEN = 2 , + LMP_DECR_PWR_REQ_LEN = 2 , + LMP_MAX_PWR_LEN = 1 , + LMP_MIN_PWR_LEN = 1 , + LMP_AUTO_RATE_LEN = 1 , + LMP_PREF_RATE_LEN = 2 , + LMP_VER_REQ_LEN = 6 , + LMP_VER_RES_LEN = 6 , + LMP_FEATS_REQ_LEN = 9 , + LMP_FEATS_RES_LEN = 9 , + LMP_QOS_LEN = 4 , + LMP_QOS_REQ_LEN = 4 , + LMP_SCO_LINK_REQ_LEN = 7 , + LMP_RMV_SCO_LINK_REQ_LEN = 3 , + LMP_MAX_SLOT_LEN = 2 , + LMP_MAX_SLOT_REQ_LEN = 2 , + LMP_TIMING_ACCU_REQ_LEN = 1 , + LMP_TIMING_ACCU_RES_LEN = 3 , + LMP_SETUP_CMP_LEN = 1 , + LMP_USE_SEMI_PERM_KEY_LEN = 1 , + LMP_HOST_CON_REQ_LEN = 1 , + LMP_SLOT_OFF_LEN = 9 , + LMP_PAGE_MODE_REQ_LEN = 3 , + LMP_PAGE_SCAN_MODE_REQ_LEN = 3 , + LMP_SUPV_TO_LEN = 3 , + LMP_TEST_ACTIVATE_LEN = 1 , + LMP_TEST_CTRL_LEN = 10, + LMP_ENC_KEY_SIZE_MASK_REQ_LEN = 1 , + LMP_ENC_KEY_SIZE_MASK_RES_LEN = 3 , + LMP_SET_AFH_LEN = 16, + LMP_ENCAPS_HDR_LEN = 4 , + LMP_ENCAPS_PAYL_LEN = 17, + LMP_SP_CFM_LEN = 17, + LMP_SP_NB_LEN = 17, + LMP_DHKEY_CHK_LEN = 17, + LMP_PAUSE_ENC_AES_REQ_LEN = 17, +}; + +/// LMP Escape 4 Extended PDU length (including opcode and ext opcode) +enum co_lmp_ext_pdu_length +{ + LMP_ACCEPTED_EXT_LEN = 4 , + LMP_NOT_ACCEPTED_EXT_LEN = 5 , + LMP_FEATS_REQ_EXT_LEN = 12, + LMP_FEATS_RES_EXT_LEN = 12, + LMP_CLK_ADJ_LEN = 15, + LMP_CLK_ADJ_ACK_LEN = 3 , + LMP_CLK_ADJ_REQ_LEN = 6 , + LMP_PKT_TYPE_TBL_REQ_LEN = 3 , + LMP_ESCO_LINK_REQ_LEN = 16, + LMP_RMV_ESCO_LINK_REQ_LEN = 4 , + LMP_CH_CLASS_REQ_LEN = 7 , + LMP_CH_CLASS_LEN = 12, + LMP_SSR_REQ_LEN = 9 , + LMP_SSR_RES_LEN = 9 , + LMP_PAUSE_ENC_REQ_LEN = 2 , + LMP_RESUME_ENC_REQ_LEN = 2 , + LMP_IO_CAP_REQ_LEN = 5 , + LMP_IO_CAP_RES_LEN = 5 , + LMP_NUM_COMPARISON_FAIL_LEN = 2 , + LMP_PASSKEY_FAIL_LEN = 2 , + LMP_OOB_FAIL_LEN = 2 , + LMP_KEYPRESS_NOTIF_LEN = 3 , + LMP_PWR_CTRL_REQ_LEN = 3 , + LMP_PWR_CTRL_RES_LEN = 3 , + LMP_PING_REQ_LEN = 2 , + LMP_PING_RES_LEN = 2 , + LMP_SAM_SET_TYPE0_LEN = 17, + LMP_SAM_DEFINE_MAP_LEN = 17, + LMP_SAN_SWITCH_LEN = 9, +}; + +/// Maximum LMP PDU size (including opcode and ext opcode) +#define LMP_MAX_PDU_SIZE DM1_PACKET_SIZE + +/** + * Opcode and TrID in the first byte + * + * 7 6 5 4 3 2 1 0 + * +----+----+----+----+----+----+----+----+ + * | opcode | Tid| + * +----+----+----+----+----+----+----+----+ + */ +enum lmp_opcode_trid +{ + /// Position of transaction ID in 1st byte + LMP_TR_ID_POS = 0, + LMP_TR_ID_BIT = 0x01, + /// Position of opcode in 1st byte + LMP_OPCODE_LSB = 1, + LMP_OPCODE_MASK = 0xFE, +}; + +#define LMP_OPCODE(opcode, tr_id) (((opcode << LMP_OPCODE_LSB) & LMP_OPCODE_MASK) | ((tr_id << LMP_TR_ID_POS) & LMP_TR_ID_BIT)) +/* + * MESSAGES + **************************************************************************************** + */ + +///LMP_name_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_name_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Offset + uint8_t offset; +}; + +///LMP_name_res PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_name_res +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Offset + uint8_t offset; + ///Name Length + uint8_t length; + ///Name Fragment + struct name_vect name_frag; +}; + +///LMP_accepted PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_accepted +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Opcode of the original LMP + uint8_t orig_opcode; +}; + +///LMP_not_accepted PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_not_accepted +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Opcode of the original LMP + uint8_t orig_opcode; + ///Reason for not accepting the PDU (error code) + uint8_t reason; +}; + +///LMP_clkoffset_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_clk_off_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_clkoffset_res PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_clk_off_res +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Clock Offset value + uint16_t clk_offset ; +}; + +///LMP_detach PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_detach +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Reason to detach + uint8_t reason; +}; + +///LMP_in_rand PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_inrand +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Random number + struct ltk random; +}; + +///LMP_comb_key PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_combkey +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Random number + struct ltk random; +}; + +///LMP_unit_key PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_unitkey +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Key + struct ltk key; +}; + +///LMP_au_rand PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_aurand +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Random number + struct ltk random; +}; + +///LMP_sres PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_sres +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Authentication Response + struct sres_nb Sres; +}; + +///LMP_temp_rand PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_temprand +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Random number + struct ltk random; +}; + +///LMP_temp_key PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_tempkey +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Key + struct ltk key; +}; + +///LMP_encryption_mode_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_enc_mode_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Encryption Mode + uint8_t enc_mode; +}; + +///LMP_encryption_key_size_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_enc_key_size_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Key Size + uint8_t key_size; +}; + +///LMP_start_encryption_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_start_enc_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Random number + struct ltk random; +}; + +///LMP_stop_encryption_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_stop_enc_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_switch_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_switch_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Switch Instant + uint32_t switch_inst; +}; + +///LMP_sniff_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_sniff_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + /// Timing Control Flags (bit 1: initialization method 1 or 2) + uint8_t flags; + /// Offset (in slots) + uint16_t d_sniff; + /// Interval (in slots) + uint16_t t_sniff; + /// Attempts (number of receive slots) (in slots) + uint16_t sniff_attempt; + /// Timeout (number of receive slots) (in slots) + uint16_t sniff_to; +}; + +///LMP_unsniff_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_unsniff_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_incr_power_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_incr_pwr_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///For future use + uint8_t reserved; +}; + +///LMP_decr_power_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_decr_pwr_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///For future use + uint8_t reserved; +}; + +///LMP_max_power PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_max_pwr +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_min_power PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_min_pwr +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_auto_rate PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_auto_rate +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_preferred_rate PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_pref_rate +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Data Rate + uint8_t rate; +}; + +///LMP_version_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_ver_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Version number + uint8_t ver; + ///Company ID + uint16_t co_id; + ///Subversion number + uint16_t subver; +}; + +///LMP_version_res PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_ver_res +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Version number + uint8_t ver; + ///Company ID + uint16_t co_id; + ///Subversion number + uint16_t subver; +}; + +///LMP_features_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_feats_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Features + struct features feats; +}; + +///LMP_features_res PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_feats_res +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Features + struct features feats; +}; + +///LMP_quality_of_service PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_qos +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Poll interval + uint16_t poll_intv; + ///Nbc + uint8_t nbc; +}; + + +///LMP_quality_of_service_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_qos_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Poll interval + uint16_t poll_intv; + ///Nbc + uint8_t nbc; +}; + +///LMP_SCO_link_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_sco_link_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///SCO handle + uint8_t sco_hdl; + ///timing control flags + uint8_t flags; + ///Dsco + uint8_t d_sco; + ///Tsco + uint8_t t_sco; + ///SCO packet + uint8_t sco_pkt; + ///Air mode + uint8_t air_mode; +}; + +///LMP_remove_SCO_link_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_rmv_sco_link_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///SCO handle + uint8_t sco_hdl; + ///Reason for its removal(error code) + uint8_t reason; +}; + +///LMP_max_slot PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_max_slot +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Max slots + uint8_t max_slots; +}; + + +///LMP_max_slot_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_max_slot_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Max slots + uint8_t max_slots; +}; + +///LMP_timing_accuracy_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_timing_accu_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_timing_accuracy_res PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_timing_accu_res +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Drift + uint8_t drift; + ///Jitter + uint8_t jitter; +}; + +///LMP_setup_complete PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_setup_cmp +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_use_semi_permanent_key PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_use_semi_perm_key +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_host_connection_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_host_con_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_slot_offset PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_slot_off +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Slot Offset + uint16_t slot_off; + ///BD Address + struct bd_addr addr; +}; + +///LMP_page_mode_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_page_mode_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Paging scheme + uint8_t page_scheme; + ///Paging scheme settings + uint8_t page_stg; +}; + +///LMP_page_scan_mode_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_page_scan_mode_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Paging scheme + uint8_t page_scheme; + ///Paging scheme settings + uint8_t page_stg; +}; + +///LMP_supervision_timeout PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_supv_to +{ + ///Opcode (including transaction ID) + uint8_t opcode; + /// Supervision Timeout (in slots, 0 means infinite timeout) + uint16_t supv_to; +}; + +///LMP_test_activate PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_test_activate +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_test_control PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_test_ctrl +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Test Scenario + uint8_t scenario; + ///Hopping Mode + uint8_t hop; + ///Tx frequency + uint8_t tx_freq; + ///Rx Frequency + uint8_t rx_freq; + ///Power Control Mode + uint8_t pwr_ctrl; + ///Poll period + uint8_t poll_period; + ///Packet type + uint8_t pkt_type; + ///length of test data + uint16_t data_len; +}; + +///LMP_encryption_key_size_mask_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_enc_key_size_mask_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; +}; + +///LMP_encryption_key_size_mask_res PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_enc_key_size_mask_res +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Encryption Key Size Mask + uint16_t mask; +}; + +///LMP_set_AFH PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_set_afh +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///AFH Instant + uint32_t instant; + ///AFH Mode + uint8_t mode; + ///AFH channel map + struct chnl_map map; +}; + +///LMP_encapsulated_header PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_encaps_hdr +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Encapsulated major type + uint8_t maj_type; + ///Encapsulated minor type + uint8_t min_type; + ///Encapsulated Payload Length + uint8_t payl_len; +}; + +///LMP_encapsulated_payload PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_encaps_payl +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Encapsulated data + struct byte16 data; +}; + +///LMP_Simple_Pairing_Confirm PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_sp_cfm +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Commitment Value + struct byte16 commitment_val ; +}; + +///LMP_Simple_Pairing_Number PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_sp_nb +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///nonce Value + struct byte16 nonce; +}; + +///LMP_DHkey_check PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_dhkey_chk +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Confirmation Value + struct ltk cfm_val; +}; + +///LMP_pause_encryption_aes_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_pause_enc_aes_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + /// Random Number + struct ltk rand; +}; + +/* + * Extended PDUs parameter structures - Escape 4 + ****************************************************************************************/ + +///LMP_accepted_ext PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_accepted_ext +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Escape opcode of the original LMP + uint8_t orig_esc_opcode; + ///Extended opcode of the original LMP + uint8_t orig_ext_opcode; +}; + +///LMP_not_accepted_ext PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_not_accepted_ext +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Escape opcode of the original LMP + uint8_t orig_esc_opcode; + ///Extended opcode of the original LMP + uint8_t orig_ext_opcode; + ///Reason + uint8_t reason; +}; + +///LMP_features_req_ext PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_feats_req_ext +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Features page + uint8_t page; + ///Max supported page + uint8_t max_page; + ///Extended features + struct features ext_feats; +}; + +///LMP_features_res_ext PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_feats_res_ext +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Features page + uint8_t page; + ///Max supported page + uint8_t max_page; + ///Extended features + struct features ext_feats; +}; + +///LMP_clk_adj PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_clk_adj +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Coarse clock adjustment Event ID + uint8_t clk_adj_id; + ///Coarse clock adjustment instant + uint32_t clk_adj_instant; + ///Coarse clock adjustment intraslot alignment offset + int16_t clk_adj_us; + ///Coarse clock adjustment slot offset + uint8_t clk_adj_slots; + ///Coarse clock adjustment mode (before/after instant) + uint8_t clk_adj_mode; + ///Coarse clock adjustment PDU CLK instant + uint32_t clk_adj_clk; +}; + +///LMP_clk_adj_ack PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_clk_adj_ack +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Coarse clock adjustment Event ID + uint8_t clk_adj_id; +}; + +///LMP_clk_adj_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_clk_adj_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Coarse clock adjustment intraslot alignment offset + int16_t clk_adj_us; + ///Coarse clock adjustment slot offset + uint8_t clk_adj_slots; + ///Corase clock adjustment period + uint8_t clk_adj_period; +}; + +///LMP_packet_type_table_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_pkt_type_tbl_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Packet Type table + uint8_t pkt_type_tbl; +}; + +///LMP_SAM_define_map PDU structure +struct lmp_sam_define_map +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///SAM Index + uint8_t index; + ///Tsam-sm + uint8_t t_sam_sm; + ///Nsam-sm + uint8_t n_sam_sm; + ///SAM Submaps + struct sam_submaps submaps; +}; + +///LMP_SAM_set_type0 PDU structure +struct lmp_sam_set_type0 +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Update mode + uint8_t update_mode; + ///SAM Type0 submap + struct sam_type0_submap submap; +}; + +///LMP_SAM_switch PDU structure +struct lmp_sam_switch +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///SAM Index + uint8_t index; + ///timing control flags + uint8_t flags; + ///Dsam + uint8_t d_sam; + ///SAM instant + uint32_t instant; +}; + +///LMP_eSCO_link_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_esco_link_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///eSCO handle + uint8_t esco_hdl; + ///eSCo LT Address + uint8_t esco_lt_addr; + ///timing control flags + uint8_t flags; + ///Desco + uint8_t d_esco; + ///t_esco + uint8_t t_esco; + ///Wesco + uint8_t w_esco; + ///eSCO packet type M2S + uint8_t m2s_pkt_type; + ///eSCO packet type S2M + uint8_t s2m_pkt_type; + ///Packet Length M2S + uint16_t m2s_pkt_len; + ///Packet Length S2m + uint16_t s2m_pkt_len; + ///Air Mode + uint8_t air_mode; + ///Negotiation state + uint8_t negt_st; +}; + +///LMP_remove_eSCO_link_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_rmv_esco_link_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///eSCO handle + uint8_t esco_hdl; + ///Reason + uint8_t reason; +}; + +///LMP_channel_classification_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_ch_class_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///AFH reporting mode + uint8_t rep_mode; + ///AFH min interval + uint16_t min_intv; + ///AFH max interval + uint16_t max_intv; +}; + +///LMP_channel_classification PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_ch_class +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///AFh channel classification + struct chnl_map ch_class; +}; + +///LMP_sniff_subrating_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_ssr_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + /// Maximum sniff sub-rate (in number of sniff events) + uint8_t max_subrate; + /// Minimum sniff mode timeout (in slots) + uint16_t min_to; + /// Sniff sub-rating instant (in slots, master clock value) + uint32_t instant; +}; + +///LMP_sniff_subrating_res PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_ssr_res +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + /// Maximum sniff sub-rate (in number of sniff events) + uint8_t max_subrate; + /// Minimum sniff mode timeout (in slots) + uint16_t min_to; + /// Sniff sub-rating instant (in slots, master clock value) + uint32_t instant; +}; + +///LMP_pause_encryption_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_pause_enc_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; +}; + +///LMP_resume_encryption_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_resume_enc_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; +}; + +///LMP_IO_capability_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_io_cap_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///IO Capabilities + uint8_t io_cap; + /// OOB Authentication data + uint8_t oob_auth_data; + ///Authentication requirements + uint8_t auth_req; +}; + + +///LMP_IO_capability_res PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_io_cap_res +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///IO Capabilities + uint8_t io_cap; + /// OOB Authentication data + uint8_t oob_auth_data; + ///Authentication requirements + uint8_t auth_req; +}; + +///LMP_numeric_comparison_failed PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_num_comparison_fail +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; +}; + +///LMP_passkey_failed PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_passkey_fail +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; +}; + +///LMP_oob_failed PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_oob_fail +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; +}; + +///LMP_keypress_notification PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_keypress_notif +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Notification Type + uint8_t type; +}; + +///LMP_power_control_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_pwr_ctrl_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Power adjustment request + uint8_t pwr_adj; + +}; + +///LMP_power_control_res PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_pwr_ctrl_res +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; + ///Power adjustment response + uint8_t pwr_adj; +}; + +/// LMP_ping_req PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_ping_req +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; +}; + +/// LMP_ping_res PDU structure +/*@TRACE + * @NO_PAD +*/ +struct lmp_ping_res +{ + ///Opcode (including transaction ID) + uint8_t opcode; + ///Extended opcode + uint8_t ext_opcode; +}; + +/// Union of all the LMP message structures +union lmp_pdu +{ + struct lmp_name_req name_req ; + struct lmp_name_res name_res ; + struct lmp_accepted accepted ; + struct lmp_not_accepted not_accepted ; + struct lmp_clk_off_req clk_off_req ; + struct lmp_clk_off_res clk_off_res ; + struct lmp_detach detach ; + struct lmp_inrand inrand ; + struct lmp_combkey combkey ; + struct lmp_unitkey unitkey ; + struct lmp_aurand aurand ; + struct lmp_sres sres ; + struct lmp_temprand temprand ; + struct lmp_tempkey tempkey ; + struct lmp_enc_mode_req enc_mode_req ; + struct lmp_enc_key_size_req enc_key_size_req ; + struct lmp_start_enc_req start_enc_req ; + struct lmp_stop_enc_req stop_enc_req ; + struct lmp_switch_req switch_req ; + struct lmp_sniff_req sniff_req ; + struct lmp_unsniff_req unsniff_req ; + struct lmp_incr_pwr_req incr_pwr_req ; + struct lmp_decr_pwr_req decr_pwr_req ; + struct lmp_max_pwr max_pwr ; + struct lmp_min_pwr min_pwr ; + struct lmp_auto_rate auto_rate ; + struct lmp_pref_rate pref_rate ; + struct lmp_ver_req ver_req ; + struct lmp_ver_res ver_res ; + struct lmp_feats_req feats_req ; + struct lmp_feats_res feats_res ; + struct lmp_clk_adj clk_adj ; + struct lmp_clk_adj_ack clk_adj_ack ; + struct lmp_clk_adj_req clk_adj_req ; + struct lmp_qos qos ; + struct lmp_qos_req qos_req ; + struct lmp_sco_link_req sco_link_req ; + struct lmp_rmv_sco_link_req rmv_sco_link_req ; + struct lmp_max_slot max_slot ; + struct lmp_max_slot_req max_slot_req ; + struct lmp_timing_accu_req timing_accu_req ; + struct lmp_timing_accu_res timing_accu_res ; + struct lmp_setup_cmp setup_cmp ; + struct lmp_use_semi_perm_key use_semi_perm_key ; + struct lmp_host_con_req host_con_req ; + struct lmp_slot_off slot_off ; + struct lmp_page_mode_req page_mode_req ; + struct lmp_page_scan_mode_req page_scan_mode_req ; + struct lmp_supv_to supv_to ; + struct lmp_test_activate test_activate ; + struct lmp_test_ctrl test_ctrl ; + struct lmp_enc_key_size_mask_req enc_key_size_mask_req ; + struct lmp_enc_key_size_mask_res enc_key_size_mask_res ; + struct lmp_set_afh set_afh ; + struct lmp_encaps_hdr encaps_hdr ; + struct lmp_encaps_payl encaps_payl ; + struct lmp_sp_cfm sp_cfm ; + struct lmp_sp_nb sp_nb ; + struct lmp_dhkey_chk dhkey_chk ; + struct lmp_accepted_ext accepted_ext ; + struct lmp_not_accepted_ext not_accepted_ext ; + struct lmp_feats_req_ext feats_req_ext ; + struct lmp_feats_res_ext feats_res_ext ; + struct lmp_pkt_type_tbl_req pkt_type_tbl_req ; + struct lmp_sam_define_map sam_define_map ; + struct lmp_sam_set_type0 sam_set_type0 ; + struct lmp_sam_switch sam_switch ; + struct lmp_esco_link_req esco_link_req ; + struct lmp_rmv_esco_link_req rmv_esco_link_req ; + struct lmp_ch_class_req ch_class_req ; + struct lmp_ch_class ch_class ; + struct lmp_ssr_req ssr_req ; + struct lmp_ssr_res ssr_res ; + struct lmp_pause_enc_req pause_enc_req ; + struct lmp_resume_enc_req resume_enc_req ; + struct lmp_io_cap_req io_cap_req ; + struct lmp_io_cap_res io_cap_res ; + struct lmp_num_comparison_fail num_comparison_fail ; + struct lmp_passkey_fail passkey_fail ; + struct lmp_oob_fail oob_fail ; + struct lmp_keypress_notif keypress_notif ; + struct lmp_pwr_ctrl_req pwr_ctrl_req ; + struct lmp_pwr_ctrl_res pwr_ctrl_res ; + struct lmp_ping_req ping_req ; + struct lmp_ping_res ping_res ; +}; + + +/// @} CO_BT +#endif // CO_LMP_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_math.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_math.h new file mode 100644 index 0000000..8fc9aab --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_math.h @@ -0,0 +1,289 @@ +/** + **************************************************************************************** + * + * @file co_math.h + * + * @brief Common optimized math functions + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _CO_MATH_H_ +#define _CO_MATH_H_ + +/** + ***************************************************************************************** + * @defgroup CO_MATH Math functions + * @ingroup COMMON + * @brief Optimized math functions and other computations. + * + * @{ + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include // standard integer definitions +#include // boolean definitions +#include // standard library +#include "compiler.h" // for __INLINE +#include "arch.h" // for ASSERT_ERR + +extern void srand (unsigned int seed); +//extern int rand (void); + +/* + * MACROS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Return value with one bit set. + * + * @param[in] pos Position of the bit to set. + * + * @return Value with one bit set. There is no return type since this is a macro and this + * will be resolved by the compiler upon assignment to an l-value. + **************************************************************************************** + */ +#define CO_BIT(pos) (1UL<<(pos)) + +/** + **************************************************************************************** + * @brief Align val on the multiple of 4 equal or nearest higher. + * @param[in] val Value to align. + * @return Value aligned. + **************************************************************************************** + */ +#define CO_ALIGN4_HI(val) (((val)+3)&~3) + + +/** + **************************************************************************************** + * @brief Align val on the multiple of 4 equal or nearest lower. + * @param[in] val Value to align. + * @return Value aligned. + **************************************************************************************** + */ +#define CO_ALIGN4_LO(val) ((val)&~3) + +/** + **************************************************************************************** + * @brief Align val on the multiple of 2 equal or nearest higher. + * @param[in] val Value to align. + * @return Value aligned. + **************************************************************************************** + */ +#define CO_ALIGN2_HI(val) (((val)+1)&~1) + + +/** + **************************************************************************************** + * @brief Align val on the multiple of 2 equal or nearest lower. + * @param[in] val Value to align. + * @return Value aligned. + **************************************************************************************** + */ +#define CO_ALIGN2_LO(val) ((val)&~1) + +/** + **************************************************************************************** + * Perform a division and ceil up the result + * + * @param[in] val Value to divide + * @param[in] div Divide value + * @return ceil(val/div) + **************************************************************************************** + */ +#define CO_DIVIDE_CEIL(val, div) (((val) + ((div) - 1))/ (div)) + +/** + **************************************************************************************** + * Perform a division and round the result + * + * @param[in] val Value to divide + * @param[in] div Divide value + * @return round(val/div) + **************************************************************************************** + */ +#define CO_DIVIDE_ROUND(val, div) (((val) + ((div) >> 1))/ (div)) + +/** + **************************************************************************************** + * Perform a modulo operation + * + * @param[in] val Dividend + * @param[in] div Divisor + * @return val/div) + **************************************************************************************** + */ +//#define CO_MOD(val, div) ((val) % (div)) +__INLINE uint32_t co_mod(uint32_t val, uint32_t div) +{ + ASSERT_ERR(div); + return ((val) % (div)); +} +#define CO_MOD(val, div) co_mod(val, div) + + +/* + * FUNCTION DEFINTIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Count leading zeros. + * @param[in] val Value to count the number of leading zeros on. + * @return Number of leading zeros when value is written as 32 bits. + **************************************************************************************** + */ +__INLINE uint32_t co_clz(uint32_t val) +{ +#if defined(__ICCARM__) + return __CLZ(val); +#elif defined(__CC_ARM__) + return __builtin_clz(val); + #elif defined(__GNUC__) + if (val == 0) + { + return 32; + } + return __builtin_clz(val); + #else + uint32_t i; + for (i = 0; i < 32; i++) + { + if (val & CO_BIT(31 - i)) + break; + } + return i; + #endif // defined(__arm__) +} + +/** + **************************************************************************************** + * @brief Count trailing zeros. + * @param[in] val Value to count the number of trailing zeros on. + * @return Number of trailing zeros when value is written as 32 bits. + **************************************************************************************** + */ +//TODO/Ambiq +#if 0 +__INLINE uint32_t co_ctz(uint32_t val) +{ + #if defined(__arm__) + return __builtin_ctz(val); + #elif defined(__GNUC__) + if (val == 0) + { + return 32; + } + return __builtin_ctz(val); + #else + uint32_t i; + for (i = 0; i < 32; i++) + { + if (val & CO_BIT(i)) + break; + } + return i; + #endif // defined(__arm__) +} +#endif +/** + **************************************************************************************** + * @brief Function to initialize the random seed. + * @param[in] seed The seed number to use to generate the random sequence. + **************************************************************************************** + */ +__INLINE void co_random_init(uint32_t seed) +{ + srand(seed); +} + +/** + **************************************************************************************** + * @brief Function to get an 8 bit random number. + * @return Random byte value. + **************************************************************************************** + */ +__INLINE uint8_t co_rand_byte(void) +{ + return (uint8_t)(rand() & 0xFF); +} + +/** + **************************************************************************************** + * @brief Function to get an 16 bit random number. + * @return Random half word value. + **************************************************************************************** + */ +__INLINE uint16_t co_rand_hword(void) +{ + return (uint16_t)(rand() & 0xFFFF); +} + +/** + **************************************************************************************** + * @brief Function to get an 32 bit random number. + * @return Random word value. + **************************************************************************************** + */ +__INLINE uint32_t co_rand_word(void) +{ + return (uint32_t)(rand() & 0xFFFFFFFF); +} + +/** + **************************************************************************************** + * @brief Function to return the smallest of 2 unsigned 32 bits words. + * @return The smallest value. + **************************************************************************************** + */ +__INLINE uint32_t co_min(uint32_t a, uint32_t b) +{ + return a < b ? a : b; +} + +/** + **************************************************************************************** + * @brief Function to return the smallest of 2 signed 32 bits words. + * @return The smallest value. + **************************************************************************************** + */ +static __INLINE int32_t co_min_s(int32_t a, int32_t b) +{ + return a < b ? a : b; +} + +/** + **************************************************************************************** + * @brief Function to return the greatest of 2 unsigned 32 bits words. + * @return The greatest value. + **************************************************************************************** + */ +__INLINE uint32_t co_max(uint32_t a, uint32_t b) +{ + return a > b ? a : b; +} + +/** + **************************************************************************************** + * @brief Function to return the absolute value of a signed integer. + * @return The absolute value. + **************************************************************************************** + */ +__INLINE int co_abs(int val) +{ + return val < 0 ? val*(-1) : val; +} + +/// @} CO_MATH + + +#endif // _CO_MATH_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_utils.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_utils.h new file mode 100644 index 0000000..46b7e06 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_utils.h @@ -0,0 +1,692 @@ +/** + **************************************************************************************** + * + * @file co_utils.h + * + * @brief Common utilities definitions + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ +#ifndef _CO_UTILS_H_ +#define _CO_UTILS_H_ + +/** + **************************************************************************************** + * @defgroup CO_UTILS Utilities + * @ingroup COMMON + * @brief Common utilities + * + * This module contains the common utilities functions and macros. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include // standard definitions +#include // standard definitions +#include "co_bt.h" // common bt definitions +#include "rwip_config.h" // SW configuration +#include "rwip.h" // SW configuration +#include "compiler.h" // for inline functions + + +/* + * MACRO DEFINITIONS + **************************************************************************************** + */ + +/// Common constants - bit field definitions +#define BIT0 0x0001 +#define BIT1 0x0002 +#define BIT2 0x0004 +#define BIT3 0x0008 +#define BIT4 0x0010 +#define BIT5 0x0020 +#define BIT6 0x0040 +#define BIT7 0x0080 +#define BIT8 0x0100 +#define BIT9 0x0200 +#define BIT10 0x0400 +#define BIT11 0x0800 +#define BIT12 0x1000 +#define BIT13 0x2000 +#define BIT14 0x4000 +#define BIT15 0x8000 + +/// Number of '1' bits in a byte +#define NB_ONE_BITS(byte) (one_bits[byte & 0x0F] + one_bits[byte >> 4]) + +/// Get the number of elements within an array, give also number of rows in a 2-D array +#define ARRAY_LEN(array) (sizeof((array))/sizeof((array)[0])) + +/// Get the number of columns within a 2-D array +#define ARRAY_NB_COLUMNS(array) (sizeof((array[0]))/sizeof((array)[0][0])) + + +/// Macro for LMP message handler function declaration or definition +#define LMP_MSG_HANDLER(msg_name) __STATIC int lmp_##msg_name##_handler(struct lmp_##msg_name const *param, \ + ke_task_id_t const dest_id) +/// Macro for LMP message handler function declaration or definition +#define LLCP_MSG_HANDLER(msg_name) __STATIC int llcp_##msg_name##_handler(struct llcp_##msg_name const *param, \ + ke_task_id_t const dest_id) + +/// Macro for HCI message handler function declaration or definition (for multi-instantiated tasks) +#define HCI_CMD_HANDLER_C(cmd_name, param_struct) __STATIC int hci_##cmd_name##_cmd_handler(param_struct const *param, \ + ke_task_id_t const dest_id, \ + uint16_t opcode) + +/// Macro for HCI message handler function declaration or definition (with parameters) +#define HCI_CMD_HANDLER(cmd_name, param_struct) __STATIC int hci_##cmd_name##_cmd_handler(param_struct const *param, \ + uint16_t opcode) + +/// Macro for HCI message handler function declaration or definition (with parameters) +#define HCI_CMD_HANDLER_TAB(task) __STATIC const struct task##_hci_cmd_handler task##_hci_command_handler_tab[] = + + +/// MACRO to build a subversion field from the Minor and Release fields +#define CO_SUBVERSION_BUILD(minor, release) (((minor) << 8) | (release)) + + +/// Macro to get a structure from one of its structure field +#define CONTAINER_OF(ptr, type, member) ((type *)( (char *)ptr - offsetof(type,member) )) + + +/// Increment value and make sure it's never greater or equals max (else wrap to 0) +#define CO_VAL_INC(_val, _max) \ + (_val) = (_val) + 1; \ + if((_val) >= (_max)) (_val) = 0 + +/* + * ENUMERATIONS DEFINITIONS + **************************************************************************************** + */ + +/// Status returned by generic packer-unpacker +enum CO_UTIL_PACK_STATUS +{ + CO_UTIL_PACK_OK, + CO_UTIL_PACK_IN_BUF_OVFLW, + CO_UTIL_PACK_OUT_BUF_OVFLW, + CO_UTIL_PACK_WRONG_FORMAT, + CO_UTIL_PACK_ERROR, +}; + + +/// Rate information +/*@TRACE*/ +enum phy_rate +{ + /// 1 Mbits/s Rate + CO_RATE_1MBPS = 0, + /// 2 Mbits/s Rate + CO_RATE_2MBPS = 1, + /// 125 Kbits/s Rate + CO_RATE_125KBPS = 2, + /// 500 Kbits/s Rate + CO_RATE_500KBPS = 3, + /// Undefined rate (used for reporting when no packet is received) + CO_RATE_UNDEF = 4, + + CO_RATE_MAX = 4, +}; + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + + +/* + * CONSTANT DECLARATIONS + **************************************************************************************** + */ + +/// Number of '1' bits in values from 0 to 15, used to fasten bit counting +extern const unsigned char one_bits[16]; + +/// Conversion table Sleep Clock Accuracy to PPM +extern const uint16_t co_sca2ppm[]; + +/// NULL BD address +extern const struct bd_addr co_null_bdaddr; + +/// Default BD address +extern const struct bd_addr co_default_bdaddr; + +/// NULL Key +extern const uint8_t co_null_key[KEY_LEN]; + +/// Table for converting rate to PHY +extern const uint8_t co_rate_to_phy[]; + +/// Table for converting PHY to rate (Warning: the coded PHY is converted to 125K by default) +extern const uint8_t co_phy_to_rate[]; + +/// Convert PHY mask (with one single bit set) to a value +extern const uint8_t co_phy_mask_to_value[]; + +/// Convert PHY a value to the corresponding mask bit +extern const uint8_t co_phy_value_to_mask[]; + +/// Convert Rate value to the corresponding PHY mask bit +extern const uint8_t co_rate_to_phy_mask[]; + +/// Convert PHY mask bit to the corresponding Rate value +extern const uint8_t co_phy_mask_to_rate[]; + +/* + * OPERATIONS ON BT CLOCK + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Clocks addition with 2 operands + * + * @param[in] clock_a 1st operand value (in BT half-slots) + * @param[in] clock_b 2nd operand value (in BT half-slots) + * @return result operation result (in BT half-slots) + **************************************************************************************** + */ +#define CLK_ADD_2(clock_a, clock_b) ((uint32_t)(((clock_a) + (clock_b)) & RWIP_MAX_CLOCK_TIME)) + +/** + **************************************************************************************** + * @brief Clocks addition with 3 operands + * + * @param[in] clock_a 1st operand value (in BT half-slots) + * @param[in] clock_b 2nd operand value (in BT half-slots) + * @param[in] clock_c 3rd operand value (in BT half-slots) + * @return result operation result (in BT half-slots) + **************************************************************************************** + */ +#define CLK_ADD_3(clock_a, clock_b, clock_c) ((uint32_t)(((clock_a) + (clock_b) + (clock_c)) & RWIP_MAX_CLOCK_TIME)) + +/** + **************************************************************************************** + * @brief Clocks subtraction + * + * @param[in] clock_a 1st operand value (in BT half-slots) + * @param[in] clock_b 2nd operand value (in BT half-slots) + * @return result operation result (in BT half-slots) + **************************************************************************************** + */ +#define CLK_SUB(clock_a, clock_b) ((uint32_t)(((clock_a) - (clock_b)) & RWIP_MAX_CLOCK_TIME)) + +/** + **************************************************************************************** + * @brief Clocks time difference + * + * @param[in] clock_a 1st operand value (in BT half-slots) + * @param[in] clock_b 2nd operand value (in BT half-slots) + * @return result return the time difference from clock A to clock B + * - result < 0 => clock_b is in the past + * - result == 0 => clock_a is equal to clock_b + * - result > 0 => clock_b is in the future + **************************************************************************************** + */ +#define CLK_DIFF(clock_a, clock_b) ( (CLK_SUB((clock_b), (clock_a)) > ((RWIP_MAX_CLOCK_TIME+1) >> 1)) ? \ + ((int32_t)((-CLK_SUB((clock_a), (clock_b))))) : ((int32_t)((CLK_SUB((clock_b), (clock_a))))) ) + + + +/// macro to extract a field from a value containing several fields +/// @param[in] __r bit field value +/// @param[in] __f field name +/// @return the value of the register masked and shifted +#define GETF(__r, __f) \ + (( (__r) & (__f##_MASK) ) >> (__f##_LSB)) + +/// macro to set a field value into a value containing several fields. +/// @param[in] __r bit field value +/// @param[in] __f field name +/// @param[in] __v value to put in field +#define SETF(__r, __f, __v) \ + do { \ + ASSERT_INFO( ( ( ( (__v) << (__f##_LSB) ) & ( ~(__f##_MASK) ) ) ) == 0 ,(__f##_MASK), (__v)); \ + __r = (((__r) & ~(__f##_MASK)) | (__v) << (__f##_LSB)); \ + } while (0) + + + +/// macro to extract a bit field from a value containing several fields +/// @param[in] __r bit field value +/// @param[in] __b bit field name +/// @return the value of the register masked and shifted +#define GETB(__r, __b) \ + (( (__r) & (__b##_BIT) ) >> (__b##_POS)) + +/// macro to set a bit field value into a value containing several fields. +/// @param[in] __r bit field value +/// @param[in] __b bit field name +/// @param[in] __v value to put in field +#define SETB(__r, __b, __v) \ + do { \ + ASSERT_ERR( ( ( ( (__v ? 1 : 0) << (__b##_POS) ) & ( ~(__b##_BIT) ) ) ) == 0 ); \ + __r = (((__r) & ~(__b##_BIT)) | (__v ? 1 : 0) << (__b##_POS)); \ + } while (0) + +/// macro to toggle a bit into a value containing several bits. +/// @param[in] __r bit field value +/// @param[in] __b bit field name +#define TOGB(__r, __b) \ + do { \ + __r = ((__r) ^ (__b##_BIT)); \ + } while (0) + +/** + **************************************************************************************** + * @brief Check if clock_a is equal to clock_b + * + * @param[in] clock_a Clock A value (in BT half-slots) + * @param[in] clock_b Clock B value (in BT half-slots) + * @return result True: clock_a lower than or equal to clock_b | False: else + **************************************************************************************** + */ +#define CLK_EQ(clock_a, clock_b) (clock_b == clock_a) + +/** + **************************************************************************************** + * @brief Check if clock_a is lower than or equal to clock_b + * + * @param[in] clock_a Clock A value (in BT half-slots) + * @param[in] clock_b Clock B value (in BT half-slots) + * @return result True: clock_a lower than or equal to clock_b | False: else + **************************************************************************************** + */ +#define CLK_LOWER_EQ(clock_a, clock_b) (CLK_SUB(clock_b, clock_a) < (RWIP_MAX_CLOCK_TIME >> 1)) + +/** + **************************************************************************************** + * @brief Check if clock A is lower than or equal to clock B (with half-us precision) + * + * @param[in] int_a Integer part of clock A (in BT half-slots) + * @param[in] fract_a Fractional part of clock A (in half-us) (range: 0 to 624) + * @param[in] int_b Integer part of clock B (in BT half-slots) + * @param[in] fract_b Fractional part of clock B (in half-us) (range: 0 to 624) + * @return result True: clock A lower than or equal to clock B | False: else + **************************************************************************************** + */ +#define CLK_LOWER_EQ_HUS(int_a, fract_a, int_b, fract_b) ( CLK_GREATER_THAN(int_b, int_a) \ + || ( CLK_EQ(int_a, int_b) \ + && (fract_a <= fract_b) ) ) \ + +/** + **************************************************************************************** + * @brief Check if clock_a is greater than clock_b + * + * @param[in] clock_a Clock A value (in BT half-slots) + * @param[in] clock_b Clock B value (in BT half-slots) + * @return result True: clock_a is greater than clock_b | False: else + **************************************************************************************** + */ +#define CLK_GREATER_THAN(clock_a, clock_b) !(CLK_LOWER_EQ(clock_a, clock_b)) + +/** + **************************************************************************************** + * @brief Check if clock A is greater than clock B (with half-us precision) + * + * @param[in] int_a Integer part of clock A (in BT half-slots) + * @param[in] fract_a Fractional part of clock A (in half-us) (range: 0 to 624) + * @param[in] int_b Integer part of clock B (in BT half-slots) + * @param[in] fract_b Fractional part of clock B (in half-us) (range: 0 to 624) + * @return result True: clock A greater than clock B | False: else + **************************************************************************************** + */ +#define CLK_GREATER_THAN_HUS(int_a, fract_a, int_b, fract_b) ( CLK_GREATER_THAN(int_a, int_b) \ + || ( CLK_EQ(int_a, int_b) \ + && (fract_a > fract_b) ) ) \ + +#if (BLE_EMB_PRESENT) +/** + ****************************************************************************** + * @brief Compare 2 BLE instants (connection event counter) + * @param[in] instant_a 1st operand value (connection event counter) + * @param[in] instant_b 2nd operand value (connection event counter) + * @return result True: B is greater or equal to A | False: B is smaller than A + ****************************************************************************** + */ +#define CO_BLE_INSTANT_PASSED(instant_a, instant_b) ((uint16_t)(instant_b - instant_a) < 32767) + +/** + ****************************************************************************** + * @brief Compute difference between two event counter + * @param[in] evt_cnt_a 1st operand value (connection event counter) + * @param[in] evt_cnt_b 2nd operand value (connection event counter) + * @return result return the time difference from evt_cnt_a to evt_cnt_b + * - result < 0 => evt_cnt_b is in the past + * - result == 0 => evt_cnt_a is equal to evt_cnt_b + * - result > 0 => evt_cnt_b is in the future + ****************************************************************************** + */ +#define CO_BLE_EVT_CNT_DIFF(evt_cnt_a, evt_cnt_b) ((((uint16_t) (evt_cnt_b)) - ((uint16_t) (evt_cnt_a)) > 32768) \ + ? ((int16_t)(-(((uint16_t) (evt_cnt_a)) - ((uint16_t) (evt_cnt_b))))) \ + : ((int16_t)(-(((uint16_t) (evt_cnt_b)) - ((uint16_t) (evt_cnt_a)))))) + +#endif //BLE_EMB_PRESENT + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Read an aligned 32 bit word. + * @param[in] ptr32 The address of the first byte of the 32 bit word. + * @return The 32 bit value. + **************************************************************************************** + */ +__INLINE uint32_t co_read32(void const *ptr32) +{ + return *((uint32_t*)ptr32); +} + +/** + **************************************************************************************** + * @brief Read an aligned 16 bits word. + * @param[in] ptr16 The address of the first byte of the 16 bits word. + * @return The 16 bits value. + **************************************************************************************** + */ +__INLINE uint16_t co_read16(void const *ptr16) +{ + return *((uint16_t*)ptr16); +} + +/** + **************************************************************************************** + * @brief Write an aligned 32 bits word. + * @param[in] ptr32 The address of the first byte of the 32 bits word. + * @param[in] value The value to write. + **************************************************************************************** + */ +__INLINE void co_write32(void const *ptr32, uint32_t value) +{ + *(uint32_t*)ptr32 = value; +} + +/** + **************************************************************************************** + * @brief Write an aligned 16 bits word. + * @param[in] ptr16 The address of the first byte of the 16 bits word. + * @param[in] value The value to write. + **************************************************************************************** + */ +__INLINE void co_write16(void const *ptr16, uint32_t value) +{ + *(uint16_t*)ptr16 = value; +} + +/** + **************************************************************************************** + * @brief Write a 8 bits word. + * @param[in] ptr8 The address of the first byte of the 8 bits word. + * @param[in] value The value to write. + **************************************************************************************** + */ +__INLINE void co_write8(void const *ptr8, uint32_t value) +{ + *(uint8_t*)ptr8 = value; +} + +/** + **************************************************************************************** + * @brief Read a packed 16 bits word. + * @param[in] ptr16 The address of the first byte of the 16 bits word. + * @return The 16 bits value. + **************************************************************************************** + */ +__INLINE uint16_t co_read16p(void const *ptr16) +{ + uint16_t value = ((uint8_t *)ptr16)[0] | ((uint8_t *)ptr16)[1] << 8; + return value; +} + +/** + **************************************************************************************** + * @brief Read a packed 24 bits word. + * @param[in] ptr24 The address of the first byte of the 24 bits word. + * @return The 24 bits value. + **************************************************************************************** + */ +__INLINE uint32_t co_read24p(void const *ptr24) +{ + uint16_t addr_l, addr_h; + addr_l = co_read16p(ptr24); + addr_h = *((uint8_t *)ptr24 + 2) & 0x00FF; + return ((uint32_t)addr_l | (uint32_t)addr_h << 16); +} + +/** + **************************************************************************************** + * @brief Write a packed 24 bits word. + * @param[in] ptr24 The address of the first byte of the 24 bits word. + * @param[in] value The value to write. + **************************************************************************************** + */ +__INLINE void co_write24p(void const *ptr24, uint32_t value) +{ + uint8_t *ptr=(uint8_t*)ptr24; + + *ptr++ = (uint8_t)(value&0xff); + *ptr++ = (uint8_t)((value&0xff00)>>8); + *ptr++ = (uint8_t)((value&0xff0000)>>16); +} + +/** + **************************************************************************************** + * @brief Read a packed 32 bits word. + * @param[in] ptr32 The address of the first byte of the 32 bits word. + * @return The 32 bits value. + **************************************************************************************** + */ +__INLINE uint32_t co_read32p(void const *ptr32) +{ + uint16_t addr_l, addr_h; + addr_l = co_read16p(ptr32); + addr_h = co_read16p((uint8_t *)ptr32 + 2); + return ((uint32_t)addr_l | (uint32_t)addr_h << 16); +} +/** + **************************************************************************************** + * @brief Write a packed 32 bits word. + * @param[in] ptr32 The address of the first byte of the 32 bits word. + * @param[in] value The value to write. + **************************************************************************************** + */ +__INLINE void co_write32p(void const *ptr32, uint32_t value) +{ + uint8_t *ptr=(uint8_t*)ptr32; + + *ptr++ = (uint8_t)(value&0xff); + *ptr++ = (uint8_t)((value&0xff00)>>8); + *ptr++ = (uint8_t)((value&0xff0000)>>16); + *ptr = (uint8_t)((value&0xff000000)>>24); +} + +/** + **************************************************************************************** + * @brief Write a packed 16 bits word. + * @param[in] ptr16 The address of the first byte of the 16 bits word. + * @param[in] value The value to write. + **************************************************************************************** + */ +static __INLINE void co_write16p(void const *ptr16, uint16_t value) +{ + uint8_t *ptr=(uint8_t*)ptr16; + + *ptr++ = value&0xff; + *ptr = (value&0xff00)>>8; +} + +#if (RW_DEBUG || DISPLAY_SUPPORT) + +/** + **************************************************************************************** + * @brief Convert bytes to hexadecimal string + * + * @param[out] dest Pointer to the destination string (must be 2x longer than input table) + * @param[in] src Pointer to the bytes table + * @param[in] nb_bytes Number of bytes to display in the string + **************************************************************************************** + */ +void co_bytes_to_string(char* dest, uint8_t* src, uint8_t nb_bytes); +#endif //(RW_DEBUG || DISPLAY_SUPPORT) + +/** + **************************************************************************************** + * @brief Compares two Bluetooth device addresses + * + * This function checks if the two bd address are equal. + * + * @param[in] bd_address1 Pointer on the first bd address to be compared. + * @param[in] bd_address2 Pointer on the second bd address to be compared. + * + * @return result of the comparison (true: equal | false: different). + **************************************************************************************** + */ +bool co_bdaddr_compare(struct bd_addr const *bd_address1, struct bd_addr const *bd_address2); + +#if (BLE_EMB_PRESENT) +/** + ****************************************************************************** + * @brief Count the number of good channels in a LE map + * @param[in] map Channel Map (bit fields for the 40 BT RF channels) + * @return Number of good channels + ****************************************************************************** + */ +uint8_t co_nb_good_le_channels(const struct le_chnl_map* map); +#endif //BLE_EMB_PRESENT + +#if (BT_EMB_PRESENT) + +/** + ****************************************************************************** + * @brief Convert an duration in baseband slot to a duration in number of ticks. + * @param[in] slot_cnt Duration in number of baseband slot + * @return Duration (in number of ticks). + ****************************************************************************** + */ +uint32_t co_slot_to_duration(uint32_t slot_cnt); + +/** + ****************************************************************************** + * @brief Count the number of good channels in a map + * @param[in] map Channel Map (bit fields for the 79 BT RF channels) + * @return Number of good channels + ****************************************************************************** + */ +uint8_t co_nb_good_channels(const struct chnl_map* map); + +#endif //BT_EMB_PRESENT + +/** + **************************************************************************************** + * @brief Pack parameters from a C structure to a packed buffer + * + * This function packs parameters according to a specific format. It takes care of the + * endianess, padding, required by the compiler. + * + * By default output format is LSB but it can be changed with first character of format string + * - < : LSB output format + * - > : MSB output format + * + * Format strings are the mechanism used to specify the expected layout when packing and unpacking data. They are built + * up from Format Characters, which specify the type of data being packed/unpacked. + * - B : byte - 8bits value + * - H : word - 16bits value + * - L : long - 32-bits value + * - D : 24 bits value + * - XXB: table of several bytes, where XX is the byte number, in decimal + * - XXG: Number of several bytes, where XX is the byte number, in decimal - subject to be swapped according to endianess + * - nB : table size over 1 byte, followed by the table of bytes + * - NB : table size over 2 bytes, followed by the table of bytes + * + * Example: "BBLH12BLnB" => 1 byte | 1 byte | 1 long | 1 short | 12-bytes table | 1 long | table size over 1 byte | n-bytes table + * + * Note: the function works in the same buffer + * + * @param[out] out Output Data Buffer + * @param[in] in Input Data Buffer + * @param[out] out_len Output size of packed data (in bytes) + * @param[in] in_len Input buffer size (in bytes) + * @param[in] format Parameters format + * + * @return Status of the packing operation + ***************************************************************************************** + */ +uint8_t co_util_pack(uint8_t* out, uint8_t* in, uint16_t* out_len, uint16_t in_len, const char* format); + +/** + **************************************************************************************** + * @brief Unpack parameters from an unpacked buffer to a C structure + * + * This function unpacks parameters according to a specific format. It takes care of the + * endianess, padding, required by the compiler. + * + * By default input format is LSB but it can be changed with first character of format string + * - < : LSB input format + * - > : MSB input format + * + * Format strings are the mechanism used to specify the expected layout when packing and unpacking data. They are built + * up from Format Characters, which specify the type of data being packed/unpacked. + * - B : byte - 8bits value + * - H : word - 16bits value + * - L : long - 32-bits value + * - D : 24 bits value + * - XXB: table of several bytes, where XX is the byte number, in decimal + * - XXG: Number of several bytes, where XX is the byte number, in decimal - subject to be swapped according to endianess + * - nB : table size over 1 byte, followed by the table of bytes + * - NB : table size over 2 bytes, followed by the table of bytes + * + * Example: "BBLH12BLnB" => 1 byte | 1 byte | 1 long | 1 short | 12-bytes table | 1 long | table size over 1 byte | n-bytes table + * + * Note: the output buffer provided must be large enough to contain the unpacked data. + * Note2: if a NULL output buffer is provided, the function does not copy the unpacked parameters. It still parses the + * format string and input buffer to return the number of unpacked bytes. Can be used to compute the expected unpacked + * buffer size. + * + * @param[out] out Unpacked parameters buffer + * @param[in] in Packed parameters buffer + * @param[inout] out_len Input: buffer size / Output: size of unpacked data (in bytes) + * @param[in] in_len Size of the packed data (in bytes) + * @param[in] format Parameters format + * + * @return Status of the unpacking operation + ***************************************************************************************** + */ +uint8_t co_util_unpack(uint8_t* out, uint8_t* in, uint16_t* out_len, uint16_t in_len, const char* format); + + +#if (BLE_EMB_PRESENT) + +/** + ***************************************************************************************** + * @brief Get BLE packet duration in us according to PHY and packet size + * + * @param[in] len PDU size in octets + * @param[in] rate PHY Rate (@see enum lld_phy) + * + * @return packet duration in us. + ***************************************************************************************** + */ +uint16_t co_ble_pkt_dur_in_us(uint8_t len, uint8_t rate); +#endif // (BLE_EMB_PRESENT) +/// @} CO_UTILS + +#endif // _CO_UTILS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_version.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_version.h new file mode 100644 index 0000000..49b8a4f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api/co_version.h @@ -0,0 +1,46 @@ +/** + **************************************************************************************** + * + * @file co_version.h + * + * @brief Version definitions for BT5.1 + * + * Copyright (C) RivieraWaves 2009-2018 + * + * + **************************************************************************************** + */ + +#ifndef _CO_VERSION_H_ +#define _CO_VERSION_H_ +/** + **************************************************************************************** + * @defgroup CO_VERSION Version Defines + * @ingroup COMMON + * + * @brief Bluetooth Controller Version definitions. + * + * @{ + **************************************************************************************** + */ +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "co_bt.h" // BT standard definitions + + +/// RWBT SW Major Version +#define RWBT_SW_VERSION_MAJOR (BT51_VERSION) +/// RWBT SW Minor Version +#define RWBT_SW_VERSION_MINOR 0 +/// RWBT SW Build Version +#define RWBT_SW_VERSION_BUILD 9 +/// RWBT SW Major Version +#define RWBT_SW_VERSION_SUB_BUILD 0 + + +/// @} CO_VERSION + + +#endif // _CO_VERSION_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg.h new file mode 100644 index 0000000..4f077ad --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg.h @@ -0,0 +1,66 @@ +/** +**************************************************************************************** +* +* @file dbg.h +* +* @brief Debug function +* +* Copyright (C) RivieraWaves 2009-2015 +* +* +**************************************************************************************** +*/ +#ifndef DBG_H_ +#define DBG_H_ + +/** +**************************************************************************************** +* @addtogroup DBG +* @ingroup CONTROLLER +* @brief Debug +* +* @{ +**************************************************************************************** +*/ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // stack configuration + +#include "dbg_swdiag.h" // sw profiling definitions + +#include "dbg_trc.h" // debug tracer definition + +/* + * FUNCTION DECLARATION + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialization of the BT Debug task + * + * This function initializes the the DBG task + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void dbg_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Send back to host status of platform reset request. + * + * @param status Reset error code + * + **************************************************************************************** + */ +void dbg_platform_reset_complete(uint32_t error); + +///@} DBG + +#endif // DBG_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_iqgen.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_iqgen.h new file mode 100644 index 0000000..9098d66 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_iqgen.h @@ -0,0 +1,153 @@ +/** +**************************************************************************************** +* +* @file dbg_iqgen.h +* +* @brief I&Q Samples Generator API. +* +* Copyright (C) RivieraWaves 2018 +* +* +**************************************************************************************** +*/ + +#ifndef DBG_IQGEN_H_ +#define DBG_IQGEN_H_ + +/** + **************************************************************************************** + * @addtogroup DBGIQGEN + * @ingroup IQ + * @brief Debug SW - I&Q samples Generator. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if BLE_IQ_GEN + +#include "reg_iqgen.h" // I&Q sample generator register functions + +/* + * CONSTANT DEFINITIONS + **************************************************************************************** + */ + +/// Maximum number of supported antenna patterns +#define DBG_IQGEN_MAX_ANTENNA (8) + +/// bit defintitions for debug configuration +#define DBG_IQGEN_PATTERN_MODE_BIT (1<<0) +#define DBG_IQGEN_TIMING_MODE_BIT (1<<1) +#define DBG_IQGEN_ANT_ID_MODE_BIT (2<<1) + + +/// I&Q samples generation control +enum dbg_iqgen_ctnl +{ + /// I&Q samples up count + DBG_IQGEN_UPCOUNT = 0, + /// I&Q samples down count + DBG_IQGEN_DOWNCOUNT = 1, + /// I&Q samples fixed value + DBG_IQGEN_FIXEDVAL = 2, + /// I&Q samples PRBS + DBG_IQGEN_PRBSPATTERN = 3, +}; + +/// I&Q samples generation antenna sweep pattern +enum dbg_iqgen_antenna_pattern +{ + /// antenna up-sweep + DBG_IQGEN_ANT_UPSWEEP = 0, + /// antenna up-down sweep + DBG_IQGEN_ANT_UPDNSWEEP = 1, +}; + +/// I&Q samples generation timing mode +enum dbg_iqgen_timing_mode +{ + /// 1us switching/sampling interval + DBG_IQGEN_1US_INTV = 0, + /// 2us switching/sampling interval + DBG_IQGEN_2US_INTV = 1, +}; + +/// antenna switch enable mode +enum dbg_iqgen_antenna_switch_mode +{ + /// Accepts antenna ID switching inputs from baseband + DBG_IQGEN_BASEBAND_SWITCHING = 0, + /// Antenna switching is internally enabled + DBG_IQGEN_INTERNAL_SWITCHING = 1, + +}; + + +/* + * VARIABLE DECLARATION + **************************************************************************************** + */ + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Enable I&Q sample generator + * + * @param[in] nb_antenna Number of antenna (valid range 1-8) + * @param[in] pattern_mode Antenna sweep pattern (@see enum dbg_iqgen_antenna_pattern) + * @param[in] timing_mode Timing interval mode (@see enum dbg_iqgen_timing_mode) + * @param[in] ant_switch_mode Antenna switching mode (@see enum dbg_iqgen_antenna_switch_mode) + * + **************************************************************************************** + */ +void dbg_iqgen_config_enable(uint8_t nb_antenna, uint8_t pattern_mode, uint8_t timing_mode, uint8_t ant_switch_mode); + +/** + **************************************************************************************** + * @brief Disable I&Q sample generator + * + **************************************************************************************** + */ +void dbg_iqgen_disable(); + +/** + **************************************************************************************** + * @brief Configure I&Q samples for a specific antenna + * + * @param[in] antenna ID antenna id (valid range 0-7) + * @param[in] i_cntl configuration mode for I-samples (@see enum dbg_iqgen_cntl) + * @param[in] q_cntl configuration mode for Q-samples (@see enum dbg_iqgen_cntl) + * @param[in] i_val I-samples initial value + * @param[in] q_val Q-samples initial value + * + **************************************************************************************** + */ +void dbg_iqgen_antenna_config(uint8_t antenna_id, uint8_t i_cntl, uint8_t q_cntl, uint8_t i_val, uint8_t q_val); + + +/** +**************************************************************************************** +* @brief I&Q Generator configure +* +* @param[in] param configuration structure (@see hci_dbg_iqgen_cfg_cmd) +**************************************************************************************** +*/ +uint8_t dbg_iqgen_config(struct hci_dbg_iqgen_cfg_cmd const *cfg); + +#endif //BLE_IQ_GEN + +/// @} DBGIQGEN + +#endif // DBG_IQGEN_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_mwsgen.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_mwsgen.h new file mode 100644 index 0000000..f550451 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_mwsgen.h @@ -0,0 +1,212 @@ +/** +**************************************************************************************** +* +* @file dbg_mwsgen.h +* +* @brief MWS/WLAN Generator API. +* +* Copyright (C) RivieraWaves 2015 +* +* +**************************************************************************************** +*/ + +#ifndef DBG_MWSGEN_H_ +#define DBG_MWSGEN_H_ + +/** + **************************************************************************************** + * @addtogroup DBGMWSGEN + * @ingroup DBG + * @brief Debug SW - MWS/WLAN Generator. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" + +#if (RW_WLAN_COEX_TEST) || (RW_MWS_COEX_TEST) + +#include "reg_mwsgen.h" // MWS Event Generator register functions + +/* + * CONSTANT DEFINITIONS + **************************************************************************************** + */ + +#if (RW_WLAN_COEX) +/// WLAN coexistence disabled +#define DBG_COEX_WLAN_DISABLED 0 +/// WLAN coexistence enabled +#define DBG_COEX_WLAN_ENABLED 1 +#endif + +#if (RW_MWS_COEX) +/// MWS coexistence disabled +#define DBG_COEX_MWS_DISABLED 0 +/// MWS coexistence enabled +#define DBG_COEX_MWS_ENABLED 1 +#endif + +/* + * VARIABLE DECLARATION + **************************************************************************************** + */ +#if (RW_WLAN_COEX_TEST) +extern uint32_t dbg_coex_scenario; +#endif // RW_WLAN_COEX_TEST + +#if (RW_MWS_COEX_TEST) +extern uint32_t dbg_coex_scenario; +#endif // RW_MWS_COEX_TEST + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +#if (RW_MWS_COEX_TEST) +/** + **************************************************************************************** + * @brief Set the scenario for the unitary testing. + * + * @param[in] scenario Scenario type + * + * @return none + * + **************************************************************************************** + */ +uint8_t dbg_mwscoex_scen_set(uint32_t scenario); + +/** + **************************************************************************************** + * @brief Initialize and configure MWS event generator registers to be in MWS mode. + **************************************************************************************** + */ +void dbg_mwsgen_init(void); + +/** + **************************************************************************************** + * @brief Configure MWS generator + * + * @param[in] period Period of the mws signal (us) + * @param[in] duty_cycle Duration of the high level (us) + * @param[in] tx_act Duration of the tx activity (us) + * @param[in] rx_act Duration of the rx activity (us) + * + **************************************************************************************** + */ +void dbg_mwsgen_config(uint32_t period, uint32_t duty_cycle, uint32_t tx_act, uint32_t rx_act); + +/** + **************************************************************************************** + * @brief Configure the WLAN COEX mode for BT. + * + * @param[in] txmode + * @param[in] rxmode + * @param[in] txmsk + * @param[in] rxmsk + * @param[in] txfmsk + * @param[in] rxfmsk + * @param[in] scanfmsk + * @param[in] knudge + * + **************************************************************************************** + */ +void dbg_mws_config(uint8_t txmode, uint8_t rxmode, uint8_t txmsk, uint8_t rxmsk, uint8_t txfms, uint8_t rxfmsk, uint8_t scanfmsk, uint8_t knudge); + +/** + **************************************************************************************** + * @brief Start the MWS signal generator. + * + **************************************************************************************** + */ +void dbg_mwsgen_start(void); + +/** + **************************************************************************************** + * @brief Stop the MWS signal generator. + * + **************************************************************************************** + */ +void dbg_mwsgen_stop(void); +#endif // RW_MWS_COEX_TEST + +#if (RW_WLAN_COEX_TEST) +/** + **************************************************************************************** + * @brief Set the scenario for the unitary testing. + * + * @param[in] scenario Scenario type + * + * @return none + * + **************************************************************************************** + */ + +uint8_t dbg_wlcoex_scen_set(uint32_t scenario); + +/** + **************************************************************************************** + * @brief Initialize and configure MWS event generator registers to be in WLAN mode. + **************************************************************************************** + */ +void dbg_wlangen_init(void); + +/** + **************************************************************************************** + * @brief Set the period and duty cycle for the wlrxbsy signal. + * + * @param[in] period Period of the wlrxbsy signal (us) + * @param[in] duty_cycle Duration of the high level (us) + * @param[in] tx_act Duration of the tx activity (us) + * @param[in] rx_act Duration of the rx activity (us) + * + **************************************************************************************** + */ +void dbg_wlangen_config(uint32_t period, uint32_t duty_cycle, uint32_t tx_act, uint32_t rx_act); + +/** + **************************************************************************************** + * @brief Configure the WLAN COEX mode for BT. + * + * @param[in] txmode + * @param[in] rxmode + * @param[in] txmsk + * @param[in] rxmsk + * @param[in] txthr + * @param[in] rxthr + * @param[in] pduration + * @param[in] pdelay + * + **************************************************************************************** + */ +void dbg_wlan_config(uint8_t txmode, uint8_t rxmode, uint8_t txmsk, uint8_t rxmsk, uint8_t txthr, uint8_t rxthr, uint8_t pduration, uint8_t pdelay); + +/** + **************************************************************************************** + * @brief Start the wlrxbs signal generator. + * + **************************************************************************************** + */ +void dbg_wlangen_start(void); + +/** + **************************************************************************************** + * @brief Stop the wlrxbs signal generator. + * + **************************************************************************************** + */ +void dbg_wlangen_stop(void); +#endif // RW_WLAN_COEX_TEST + +#endif // (RW_WLAN_COEX_TEST) || (RW_MWS_COEX_TEST) + +/// @} DBGMWSGEN + +#endif // DBG_MWSGEN_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_swdiag.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_swdiag.h new file mode 100644 index 0000000..3541c61 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_swdiag.h @@ -0,0 +1,1197 @@ +/** +**************************************************************************************** +* +* @file dbg_swdiag.h +* +* @brief SW profiling module +* +* Copyright (C) RivieraWaves 2009-2015 +* +* +**************************************************************************************** +*/ + +#ifndef DBG_SWDIAG_H_ +#define DBG_SWDIAG_H_ + +/** + **************************************************************************************** + * @addtogroup DBGSWDIAG Diag + * @ingroup DBG + * @brief Debug SW profiling module + * + * SW profiling is a debug feature that provides user a configurable way to analyze SW execution performance or + * behavior, such as timings, state machines, bit field values and so on. + * It manages the SW state representation over HW digital diagnostic signals (diagports), from the signals selection to + * the toggling of real HW signals. + * HW signals representing the SW execution could then be watched on a logic analyzer in parallel with HW internal + * signals, that could be very useful for low level debugging. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" // stack configuration + +#if (!RW_SWDIAG) + +/// Macro used to set a SW diag to specific value +#define DBG_SWDIAG(bank , field , value) + +#else //RW_SWDIAG + +#if (BT_DUAL_MODE) +#include "reg_ipcore.h" // btdm core registers +#else // !(BT_DUAL_MODE) +#if (BT_EMB_PRESENT) // TODO not fully agree with this +#include "reg_btcore.h" // bt core registers +#elif (BLE_EMB_PRESENT) +#include "reg_blecore.h" // ble core registers +#endif //BT_EMB_PRESENT / BLE_EMB_PRESENT +#endif // (BT_DUAL_MODE) + +/* + * DEFINES + **************************************************************************************** + */ + +/// Number of HW diagport banks +#define DBG_SWDIAG_NB_HW_BANKS 4 + +/// Undefined configuration +#define DBG_SWDIAG_UNDEFINED 0xFF + + +/* + * MACROS + **************************************************************************************** + */ +#if (BT_DUAL_MODE) +#define SW_DIAG_SET ip_swprofiling_set +#define SW_DIAG_GET ip_swprofiling_get +#else // !(BT_DUAL_MODE) +#if (BT_EMB_PRESENT) +#define SW_DIAG_SET bt_swprofiling_set +#define SW_DIAG_GET bt_swprofiling_get +#elif (BLE_EMB_PRESENT) +#define SW_DIAG_SET ble_swprofiling_set +#define SW_DIAG_GET ble_swprofiling_get +#endif //BT_EMB_PRESENT / BLE_EMB_PRESENT +#endif // (BT_DUAL_MODE) + +/// Macro used to set a SW diag to specific value +#define DBG_SWDIAG(bank , field , value) \ + if(sw_to_hw[DBG_SWDIAG_##bank] != DBG_SWDIAG_UNDEFINED) \ + { \ + SW_DIAG_SET( ((SW_DIAG_GET()) & (~(DBG_SWDIAG_##bank##_##field##_MASK << (8 * sw_to_hw[DBG_SWDIAG_##bank])))) | ((((value << DBG_SWDIAG_##bank##_##field##_OFFSET) & DBG_SWDIAG_##bank##_##field##_MASK) << (8*sw_to_hw[DBG_SWDIAG_##bank]))) ); \ + } + + +/* + * SW DIAGS MAP + **************************************************************************************** + */ + +enum dbg_swdiag +{ + /** + ****************************************************************************************** + * @brief BANK 0 : BT_ISR + ****************************************************************************************** + */ + DBG_SWDIAG_BT_ISR = 0, + + DBG_SWDIAG_BT_ISR_CLK_OFFSET = 0, + DBG_SWDIAG_BT_ISR_CLK_MASK = 0x01, + + DBG_SWDIAG_BT_ISR_RX_OFFSET = 1, + DBG_SWDIAG_BT_ISR_RX_MASK = 0x02, + + DBG_SWDIAG_BT_ISR_SLP_OFFSET = 2, + DBG_SWDIAG_BT_ISR_SLP_MASK = 0x04, + + DBG_SWDIAG_BT_ISR_GROSSTGT_OFFSET = 3, + DBG_SWDIAG_BT_ISR_GROSSTGT_MASK = 0x08, + + DBG_SWDIAG_BT_ISR_FRAME_OFFSET = 4, + DBG_SWDIAG_BT_ISR_FRAME_MASK = 0x10, + + DBG_SWDIAG_BT_ISR_FINETGT_OFFSET = 5, + DBG_SWDIAG_BT_ISR_FINETGT_MASK = 0x20, + + DBG_SWDIAG_BT_ISR_SKET_OFFSET = 6, + DBG_SWDIAG_BT_ISR_SKET_MASK = 0x40, + + DBG_SWDIAG_BT_ISR_SW_OFFSET = 7, + DBG_SWDIAG_BT_ISR_SW_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 1 : SLEEP + ****************************************************************************************** + */ + DBG_SWDIAG_SLEEP = 1, + + DBG_SWDIAG_SLEEP_SLEEP_OFFSET = 0, + DBG_SWDIAG_SLEEP_SLEEP_MASK = 0x01, + + DBG_SWDIAG_SLEEP_FUNC_OFFSET = 1, + DBG_SWDIAG_SLEEP_FUNC_MASK = 0x02, + + DBG_SWDIAG_SLEEP_WAKEUP_END_OFFSET = 2, + DBG_SWDIAG_SLEEP_WAKEUP_END_MASK = 0x04, + + DBG_SWDIAG_SLEEP_ALGO_OFFSET = 4, + DBG_SWDIAG_SLEEP_ALGO_MASK = 0xF0, + + /** + ****************************************************************************************** + * @brief BANK 2 : ISR + ****************************************************************************************** + */ + DBG_SWDIAG_ISR = 2, + + DBG_SWDIAG_ISR_UART_OFFSET = 0, + DBG_SWDIAG_ISR_UART_MASK = 0x01, + + DBG_SWDIAG_ISR_BT_OFFSET = 1, + DBG_SWDIAG_ISR_BT_MASK = 0x02, + + DBG_SWDIAG_ISR_PS2_OFFSET = 1, + DBG_SWDIAG_ISR_PS2_MASK = 0x02, + + DBG_SWDIAG_ISR_BLE_OFFSET = 2, + DBG_SWDIAG_ISR_BLE_MASK = 0x04, + + DBG_SWDIAG_ISR_RWIP_OFFSET = 3, + DBG_SWDIAG_ISR_RWIP_MASK = 0x08, + + DBG_SWDIAG_ISR_GPIO_OFFSET = 4, + DBG_SWDIAG_ISR_GPIO_MASK = 0x10, + + DBG_SWDIAG_ISR_RTC0_OFFSET = 5, + DBG_SWDIAG_ISR_RTC0_MASK = 0x20, + + DBG_SWDIAG_ISR_BTDM_OFFSET = 5, + DBG_SWDIAG_ISR_BTDM_MASK = 0x20, + + DBG_SWDIAG_ISR_SPI_OFFSET = 6, + DBG_SWDIAG_ISR_SPI_MASK = 0x40, + + DBG_SWDIAG_ISR_WFI_OFFSET = 7, + DBG_SWDIAG_ISR_WFI_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 3 : BLEISR + ****************************************************************************************** + */ + DBG_SWDIAG_BLE_ISR = 3, + + DBG_SWDIAG_BLE_ISR_RXINT_OFFSET = 0, + DBG_SWDIAG_BLE_ISR_RXINT_MASK = 0x01, + + DBG_SWDIAG_BLE_ISR_TXINT_OFFSET = 1, + DBG_SWDIAG_BLE_ISR_TXINT_MASK = 0x02, + + DBG_SWDIAG_BLE_ISR_EVENTINT_OFFSET = 2, + DBG_SWDIAG_BLE_ISR_EVENTINT_MASK = 0x04, + + DBG_SWDIAG_BLE_ISR_SKIPINT_OFFSET = 3, + DBG_SWDIAG_BLE_ISR_SKIPINT_MASK = 0x08, + + DBG_SWDIAG_BLE_ISR_ERRORINT_OFFSET = 4, + DBG_SWDIAG_BLE_ISR_ERRORINT_MASK = 0x10, + + DBG_SWDIAG_BLE_ISR_AUDIO0INT_OFFSET = 5, + DBG_SWDIAG_BLE_ISR_AUDIO0INT_MASK = 0x20, + + DBG_SWDIAG_BLE_ISR_AUDIO1INT_OFFSET = 6, + DBG_SWDIAG_BLE_ISR_AUDIO1INT_MASK = 0x40, + + DBG_SWDIAG_BLE_ISR_AUDIO2INT_OFFSET = 7, + DBG_SWDIAG_BLE_ISR_AUDIO2INT_MASK = 0x80, + + DBG_SWDIAG_BLE_ISR_RXISOINT_OFFSET = 5, + DBG_SWDIAG_BLE_ISR_RXISOINT_MASK = 0x20, + + DBG_SWDIAG_BLE_ISR_TXISOINT_OFFSET = 6, + DBG_SWDIAG_BLE_ISR_TXISOINT_MASK = 0x40, + + /** + ****************************************************************************************** + * @brief BANK 4 : FLASH + ****************************************************************************************** + */ + DBG_SWDIAG_FLASH = 4, + + DBG_SWDIAG_FLASH_STATE_OFFSET = 0, + DBG_SWDIAG_FLASH_STATE_MASK = 0x07, + + DBG_SWDIAG_FLASH_SUBSTATE_OFFSET = 3, + DBG_SWDIAG_FLASH_SUBSTATE_MASK = 0x38, + + DBG_SWDIAG_FLASH_MANAGE_OFFSET = 6, + DBG_SWDIAG_FLASH_MANAGE_MASK = 0x40, + + DBG_SWDIAG_FLASH_CALLBACK_OFFSET = 7, + DBG_SWDIAG_FLASH_CALLBACK_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 5 : Reserved + ****************************************************************************************** + */ + + /** + ****************************************************************************************** + * @brief BANK 6 : Event execution overview. + ****************************************************************************************** + */ + DBG_SWDIAG_EVT = 6, + + DBG_SWDIAG_EVT_TIMER_OFFSET = 0, + DBG_SWDIAG_EVT_TIMER_MASK = 0x01, + + DBG_SWDIAG_EVT_MESSAGE_OFFSET = 1, + DBG_SWDIAG_EVT_MESSAGE_MASK = 0x02, + + /** + ****************************************************************************************** + * @brief BANK 8 : AFH + ****************************************************************************************** + */ + DBG_SWDIAG_AFH = 8, + + DBG_SWDIAG_AFH_TO_OFFSET = 0, + DBG_SWDIAG_AFH_TO_MASK = 0x01, + + DBG_SWDIAG_AFH_LMP_TX_OFFSET = 1, + DBG_SWDIAG_AFH_LMP_TX_MASK = 0x02, + + DBG_SWDIAG_AFH_CLASS_RX_OFFSET = 2, + DBG_SWDIAG_AFH_CLASS_RX_MASK = 0x04, + + DBG_SWDIAG_AFH_HOST_OFFSET = 3, + DBG_SWDIAG_AFH_HOST_MASK = 0x08, + + DBG_SWDIAG_AFH_REPORT_TO_OFFSET = 4, + DBG_SWDIAG_AFH_REPORT_TO_MASK = 0x10, + + DBG_SWDIAG_AFH_HSSI_OFFSET = 5, + DBG_SWDIAG_AFH_HSSI_MASK = 0x20, + + DBG_SWDIAG_AFH_CFM_OFFSET = 6, + DBG_SWDIAG_AFH_CFM_MASK = 0x40, + + DBG_SWDIAG_AFH_LMP_RX_OFFSET = 7, + DBG_SWDIAG_AFH_LMP_RX_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 9 : SWITCH + ****************************************************************************************** + */ + DBG_SWDIAG_SWITCH = 9, + + DBG_SWDIAG_SWITCH_LOOP_OFFSET = 0, + DBG_SWDIAG_SWITCH_LOOP_MASK = 0x01, + + DBG_SWDIAG_SWITCH_SM_OFFSET = 1, + DBG_SWDIAG_SWITCH_SM_MASK = 0x06, + + DBG_SWDIAG_SWITCH_RSW_FAIL_OFFSET = 3, + DBG_SWDIAG_SWITCH_RSW_FAIL_MASK = 0x08, + + /** + ****************************************************************************************** + * @brief BANK 11 : VALUE8 + ****************************************************************************************** + */ + DBG_SWDIAG_VALUE8 = 11, + + DBG_SWDIAG_VALUE8_VALUE_OFFSET = 0, + DBG_SWDIAG_VALUE8_VALUE_MASK = 0xFF, + + /** + ****************************************************************************************** + * @brief BANK 12 : VALUE16 + ****************************************************************************************** + */ + DBG_SWDIAG_VALUE16 = 12, + + DBG_SWDIAG_VALUE16_VALUE_OFFSET = 0, + DBG_SWDIAG_VALUE16_VALUE_MASK = 0xFF, + + /** + ****************************************************************************************** + * @brief BANK 13 : SNIFF + ****************************************************************************************** + */ + DBG_SWDIAG_SNIFF = 13, + + DBG_SWDIAG_SNIFF_EVT_START_OFFSET = 0, + DBG_SWDIAG_SNIFF_EVT_START_MASK = 0x01, + + DBG_SWDIAG_SNIFF_EVT_CANCELED_OFFSET = 1, + DBG_SWDIAG_SNIFF_EVT_CANCELED_MASK = 0x02, + + DBG_SWDIAG_SNIFF_FRM_ISR_OFFSET = 2, + DBG_SWDIAG_SNIFF_FRM_ISR_MASK = 0x04, + + DBG_SWDIAG_SNIFF_RX_ISR_OFFSET = 3, + DBG_SWDIAG_SNIFF_RX_ISR_MASK = 0x08, + + DBG_SWDIAG_SNIFF_SCHED_OFFSET = 4, + DBG_SWDIAG_SNIFF_SCHED_MASK = 0x10, + + /** + ****************************************************************************************** + * @brief BANK 14 : SCO + ****************************************************************************************** + */ + DBG_SWDIAG_SCO = 14, + + DBG_SWDIAG_SCO_EVT_START_OFFSET = 0, + DBG_SWDIAG_SCO_EVT_START_MASK = 0x01, + + DBG_SWDIAG_SCO_EVT_STOP_OFFSET = 1, + DBG_SWDIAG_SCO_EVT_STOP_MASK = 0x02, + + DBG_SWDIAG_SCO_EVT_CANCELED_OFFSET = 2, + DBG_SWDIAG_SCO_EVT_CANCELED_MASK = 0x04, + + DBG_SWDIAG_SCO_FRM_ISR_OFFSET = 3, + DBG_SWDIAG_SCO_FRM_ISR_MASK = 0x08, + + DBG_SWDIAG_SCO_RESCHED_OFFSET = 4, + DBG_SWDIAG_SCO_RESCHED_MASK = 0x10, + + DBG_SWDIAG_SCO_UPDATE_OFFSET = 5, + DBG_SWDIAG_SCO_UPDATE_MASK = 0x60, + + DBG_SWDIAG_SCO_AUDIO_ISR_OFFSET = 7, + DBG_SWDIAG_SCO_AUDIO_ISR_MASK = 0x80, + + + /** + ****************************************************************************************** + * @brief BANK 17 : PAGE + ****************************************************************************************** + */ + DBG_SWDIAG_PAGE = 17, + + DBG_SWDIAG_PAGE_PSCAN_EVT_START_OFFSET = 0, + DBG_SWDIAG_PAGE_PSCAN_EVT_START_MASK = 0x01, + + DBG_SWDIAG_PAGE_PSCAN_EVT_CANCELED_OFFSET = 1, + DBG_SWDIAG_PAGE_PSCAN_EVT_CANCELED_MASK = 0x02, + + DBG_SWDIAG_PAGE_PSCAN_FRM_ISR_OFFSET = 2, + DBG_SWDIAG_PAGE_PSCAN_FRM_ISR_MASK = 0x04, + + DBG_SWDIAG_PAGE_PSCAN_KE_EVT_OFFSET = 3, + DBG_SWDIAG_PAGE_PSCAN_KE_EVT_MASK = 0x08, + + DBG_SWDIAG_PAGE_PAGE_EVT_START_OFFSET = 4, + DBG_SWDIAG_PAGE_PAGE_EVT_START_MASK = 0x10, + + DBG_SWDIAG_PAGE_PAGE_EVT_CANCELED_OFFSET = 5, + DBG_SWDIAG_PAGE_PAGE_EVT_CANCELED_MASK = 0x20, + + DBG_SWDIAG_PAGE_PAGE_FRM_ISR_OFFSET = 6, + DBG_SWDIAG_PAGE_PAGE_FRM_ISR_MASK = 0x40, + + DBG_SWDIAG_PAGE_PAGE_STEP_OFFSET = 7, + DBG_SWDIAG_PAGE_PAGE_STEP_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 18 : INQ + ****************************************************************************************** + */ + DBG_SWDIAG_INQ = 18, + + DBG_SWDIAG_INQ_ISCAN_EVT_START_OFFSET = 0, + DBG_SWDIAG_INQ_ISCAN_EVT_START_MASK = 0x01, + + DBG_SWDIAG_INQ_ISCAN_EVT_CANCELED_OFFSET = 1, + DBG_SWDIAG_INQ_ISCAN_EVT_CANCELED_MASK = 0x02, + + DBG_SWDIAG_INQ_ISCAN_FRM_ISR_OFFSET = 2, + DBG_SWDIAG_INQ_ISCAN_FRM_ISR_MASK = 0x04, + + DBG_SWDIAG_INQ_INQ_EVT_START_OFFSET = 3, + DBG_SWDIAG_INQ_INQ_EVT_START_MASK = 0x08, + + DBG_SWDIAG_INQ_INQ_EVT_CANCELED_OFFSET = 4, + DBG_SWDIAG_INQ_INQ_EVT_CANCELED_MASK = 0x10, + + DBG_SWDIAG_INQ_INQ_FRM_ISR_OFFSET = 5, + DBG_SWDIAG_INQ_INQ_FRM_ISR_MASK = 0x20, + + /** + ****************************************************************************************** + * @brief BANK 19 : ACL + ****************************************************************************************** + */ + DBG_SWDIAG_ACL = 19, + + DBG_SWDIAG_ACL_EVT_START_OFFSET = 0, + DBG_SWDIAG_ACL_EVT_START_MASK = 0x01, + + DBG_SWDIAG_ACL_EVT_STOP_OFFSET = 1, + DBG_SWDIAG_ACL_EVT_STOP_MASK = 0x02, + + DBG_SWDIAG_ACL_EVT_CANCELED_OFFSET = 2, + DBG_SWDIAG_ACL_EVT_CANCELED_MASK = 0x04, + + DBG_SWDIAG_ACL_FRM_ISR_OFFSET = 3, + DBG_SWDIAG_ACL_FRM_ISR_MASK = 0x08, + + DBG_SWDIAG_ACL_CLK_ISR_OFFSET = 4, + DBG_SWDIAG_ACL_CLK_ISR_MASK = 0x10, + + DBG_SWDIAG_ACL_PROG_EN_OFFSET = 5, + DBG_SWDIAG_ACL_PROG_EN_MASK = 0x20, + + DBG_SWDIAG_ACL_SKET_ISR_OFFSET = 6, + DBG_SWDIAG_ACL_SKET_ISR_MASK = 0x40, + + DBG_SWDIAG_ACL_PARITY_OFFSET = 7, + DBG_SWDIAG_ACL_PARITY_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 20 : RSW + ****************************************************************************************** + */ + DBG_SWDIAG_RSW = 20, + + DBG_SWDIAG_RSW_EVT_START_OFFSET = 0, + DBG_SWDIAG_RSW_EVT_START_MASK = 0x01, + + DBG_SWDIAG_RSW_EVT_CANCELED_OFFSET = 1, + DBG_SWDIAG_RSW_EVT_CANCELED_MASK = 0x02, + + DBG_SWDIAG_RSW_FRM_ISR_OFFSET = 2, + DBG_SWDIAG_RSW_FRM_ISR_MASK = 0x04, + + DBG_SWDIAG_RSW_STEP_OFFSET = 3, + DBG_SWDIAG_RSW_STEP_MASK = 0x08, + + DBG_SWDIAG_RSW_TX_SLOTOFF_OFFSET = 4, + DBG_SWDIAG_RSW_TX_SLOTOFF_MASK = 0x10, + + DBG_SWDIAG_RSW_TX_PARITY_OFFSET = 5, + DBG_SWDIAG_RSW_TX_PARITY_MASK = 0x20, + + DBG_SWDIAG_RSW_TDD_PARITY_OFFSET = 6, + DBG_SWDIAG_RSW_TDD_PARITY_MASK = 0x40, + + /** + ****************************************************************************************** + * @brief BANK 21 : TX + ****************************************************************************************** + */ + DBG_SWDIAG_TX = 21, + + DBG_SWDIAG_TX_LMP_TX_OFFSET = 0, + DBG_SWDIAG_TX_LMP_TX_MASK = 0x01, + + DBG_SWDIAG_TX_ACL_TX_OFFSET = 1, + DBG_SWDIAG_TX_ACL_TX_MASK = 0x02, + + DBG_SWDIAG_TX_SW_IDX_OFFSET = 2, + DBG_SWDIAG_TX_SW_IDX_MASK = 0x04, + + DBG_SWDIAG_TX_HW_IDX_OFFSET = 3, + DBG_SWDIAG_TX_HW_IDX_MASK = 0x08, + + DBG_SWDIAG_TX_TX_CNT_OFFSET = 4, + DBG_SWDIAG_TX_TX_CNT_MASK = 0x30, + + /** + ****************************************************************************************** + * @brief BANK 22 : DATA + ****************************************************************************************** + */ + DBG_SWDIAG_DATA = 22, + + DBG_SWDIAG_DATA_LMP_TX_OFFSET = 0, + DBG_SWDIAG_DATA_LMP_TX_MASK = 0x01, + + DBG_SWDIAG_DATA_ACL_TX_OFFSET = 1, + DBG_SWDIAG_DATA_ACL_TX_MASK = 0x02, + + DBG_SWDIAG_DATA_LMP_RX_OFFSET = 2, + DBG_SWDIAG_DATA_LMP_RX_MASK = 0x04, + + DBG_SWDIAG_DATA_ACL_RX_OFFSET = 3, + DBG_SWDIAG_DATA_ACL_RX_MASK = 0x08, + + DBG_SWDIAG_DATA_LMP_ACK_OFFSET = 4, + DBG_SWDIAG_DATA_LMP_ACK_MASK = 0x10, + + DBG_SWDIAG_DATA_ACL_ACK_OFFSET = 5, + DBG_SWDIAG_DATA_ACL_ACK_MASK = 0x20, + + /** + ****************************************************************************************** + * @brief BANK 23 : ECDH + ****************************************************************************************** + */ + DBG_SWDIAG_ECDH = 23, + + DBG_SWDIAG_ECDH_BUSY_OFFSET = 0, + DBG_SWDIAG_ECDH_BUSY_MASK = 0x01, + + DBG_SWDIAG_ECDH_COMPUTE_OFFSET = 1, + DBG_SWDIAG_ECDH_COMPUTE_MASK = 0x02, + + DBG_SWDIAG_ECDH_MULT_OFFSET = 2, + DBG_SWDIAG_ECDH_MULT_MASK = 0x04, + + DBG_SWDIAG_ECDH_END_OFFSET = 3, + DBG_SWDIAG_ECDH_END_MASK = 0x08, + + DBG_SWDIAG_ECDH_INV_OFFSET = 4, + DBG_SWDIAG_ECDH_INV_MASK = 0x10, + + /** + ****************************************************************************************** + * @brief BANK 24 : PCA + ****************************************************************************************** + */ + DBG_SWDIAG_PCA = 24, + + DBG_SWDIAG_PCA_FRAME_SYNC_INT_OFFSET = 0, + DBG_SWDIAG_PCA_FRAME_SYNC_INT_MASK = 0x01, + + DBG_SWDIAG_PCA_MTOFF_LT_INT_OFFSET = 1, + DBG_SWDIAG_PCA_MTOFF_LT_INT_MASK = 0x02, + + DBG_SWDIAG_PCA_SLOT_INT_OFFSET = 2, + DBG_SWDIAG_PCA_SLOT_INT_MASK = 0x04, + + DBG_SWDIAG_PCA_COARSE_CLK_ADJ_OFFSET = 3, + DBG_SWDIAG_PCA_COARSE_CLK_ADJ_MASK = 0x08, + + DBG_SWDIAG_PCA_EVT_START_OFFSET = 4, + DBG_SWDIAG_PCA_EVT_START_MASK = 0x10, + + DBG_SWDIAG_PCA_EVT_CANCELED_OFFSET = 5, + DBG_SWDIAG_PCA_EVT_CANCELED_MASK = 0x20, + + DBG_SWDIAG_PCA_ALARM_INSTANT_OFFSET = 6, + DBG_SWDIAG_PCA_ALARM_INSTANT_MASK = 0x40, + + DBG_SWDIAG_PCA_CLK_DRAG_OFFSET = 7, + DBG_SWDIAG_PCA_CLK_DRAG_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 25 : BCST + ****************************************************************************************** + */ + DBG_SWDIAG_BCST = 25, + + DBG_SWDIAG_BCST_FRM_ISR_OFFSET = 0, + DBG_SWDIAG_BCST_FRM_ISR_MASK = 0x01, + + DBG_SWDIAG_BCST_EVT_START_OFFSET = 1, + DBG_SWDIAG_BCST_EVT_START_MASK = 0x02, + + DBG_SWDIAG_BCST_SKET_ISR_OFFSET = 2, + DBG_SWDIAG_BCST_SKET_ISR_MASK = 0x04, + + DBG_SWDIAG_BCST_EVT_CANCELED_OFFSET = 3, + DBG_SWDIAG_BCST_EVT_CANCELED_MASK = 0x08, + + DBG_SWDIAG_BCST_ACL_TX_OFFSET = 4, + DBG_SWDIAG_BCST_ACL_TX_MASK = 0x10, + + DBG_SWDIAG_BCST_LMP_TX_OFFSET = 5, + DBG_SWDIAG_BCST_LMP_TX_MASK = 0x20, + + DBG_SWDIAG_BCST_PDU_TX_CFM_OFFSET = 6, + DBG_SWDIAG_BCST_PDU_TX_CFM_MASK = 0x40, + + DBG_SWDIAG_BCST_PDU_RX_OFFSET = 7, + DBG_SWDIAG_BCST_PDU_RX_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief IP_ISR - 26 + ****************************************************************************************** + */ + DBG_SWDIAG_IP_ISR = 26, + + DBG_SWDIAG_IP_ISR_CLKNINT_OFFSET = 0, + DBG_SWDIAG_IP_ISR_CLKNINT_MASK = 0x01, + + DBG_SWDIAG_IP_ISR_FINETGTINT_OFFSET = 1, + DBG_SWDIAG_IP_ISR_FINETGTINT_MASK = 0x02, + + DBG_SWDIAG_IP_ISR_GROSSTGTINT_OFFSET = 2, + DBG_SWDIAG_IP_ISR_GROSSTGTINT_MASK = 0x04, + + DBG_SWDIAG_IP_ISR_SLPINT_OFFSET = 3, + DBG_SWDIAG_IP_ISR_SLPINT_MASK = 0x08, + + DBG_SWDIAG_IP_ISR_CRYPTINT_OFFSET = 4, + DBG_SWDIAG_IP_ISR_CRYPTINT_MASK = 0x10, + + DBG_SWDIAG_IP_ISR_SWINT_OFFSET = 5, + DBG_SWDIAG_IP_ISR_SWINT_MASK = 0x20, + + DBG_SWDIAG_IP_ISR_TIMESTAMPINT_OFFSET = 6, + DBG_SWDIAG_IP_ISR_TIMESTAMPINT_MASK = 0x40, + + DBG_SWDIAG_IP_ISR_FIFOINT_OFFSET = 7, + DBG_SWDIAG_IP_ISR_FIFOINT_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief RSA Algorithm - 27 + ****************************************************************************************** + */ + DBG_SWDIAG_RSA = 27, + + DBG_SWDIAG_RSA_BUSY_OFFSET = 0, + DBG_SWDIAG_RSA_BUSY_MASK = 0x01, + + DBG_SWDIAG_RSA_COMPUTE_OFFSET = 1, + DBG_SWDIAG_RSA_COMPUTE_MASK = 0x02, + + /** + ****************************************************************************************** + * @brief SYNC SCAN - 28 + ****************************************************************************************** + */ + DBG_SWDIAG_SSCAN = 28, + + DBG_SWDIAG_SSCAN_FRM_ISR_OFFSET = 0, + DBG_SWDIAG_SSCAN_FRM_ISR_MASK = 0x01, + + DBG_SWDIAG_SSCAN_EVT_START_OFFSET = 1, + DBG_SWDIAG_SSCAN_EVT_START_MASK = 0x02, + + DBG_SWDIAG_SSCAN_START_OFFSET = 2, + DBG_SWDIAG_SSCAN_START_MASK = 0x04, + + DBG_SWDIAG_SSCAN_EVT_CANCELED_OFFSET = 3, + DBG_SWDIAG_SSCAN_EVT_CANCELED_MASK = 0x08, + + DBG_SWDIAG_SSCAN_FRM_CBK_OFFSET = 4, + DBG_SWDIAG_SSCAN_FRM_CBK_MASK = 0x10, + + DBG_SWDIAG_SSCAN_STP_RX_OFFSET = 5, + DBG_SWDIAG_SSCAN_STP_RX_MASK = 0x20, + + DBG_SWDIAG_SSCAN_STP_RX_OK_OFFSET = 6, + DBG_SWDIAG_SSCAN_STP_RX_OK_MASK = 0x40, + + DBG_SWDIAG_SSCAN_TIMEOUT_OFFSET = 7, + DBG_SWDIAG_SSCAN_TIMEOUT_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 29 : LE SCAN + ****************************************************************************************** + */ + DBG_SWDIAG_LESCAN = 29, + + DBG_SWDIAG_LESCAN_START_OFFSET = 0, + DBG_SWDIAG_LESCAN_START_MASK = 0x01, + + DBG_SWDIAG_LESCAN_STOP_OFFSET = 1, + DBG_SWDIAG_LESCAN_STOP_MASK = 0x02, + + DBG_SWDIAG_LESCAN_EVT_START_OFFSET = 2, + DBG_SWDIAG_LESCAN_EVT_START_MASK = 0x04, + + DBG_SWDIAG_LESCAN_EVT_CANCELED_OFFSET = 3, + DBG_SWDIAG_LESCAN_EVT_CANCELED_MASK = 0x08, + + DBG_SWDIAG_LESCAN_FRM_RX_ISR_OFFSET = 4, + DBG_SWDIAG_LESCAN_FRM_RX_ISR_MASK = 0x10, + + DBG_SWDIAG_LESCAN_FRM_EOF_ISR_OFFSET = 5, + DBG_SWDIAG_LESCAN_FRM_EOF_ISR_MASK = 0x20, + + DBG_SWDIAG_LESCAN_SCHED_OFFSET = 6, + DBG_SWDIAG_LESCAN_SCHED_MASK = 0x40, + + DBG_SWDIAG_LESCAN_PKT_RX_OFFSET = 7, + DBG_SWDIAG_LESCAN_PKT_RX_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 30 : SCH_PROG + ****************************************************************************************** + */ + DBG_SWDIAG_SCH_PROG = 30, + + DBG_SWDIAG_SCH_PROG_RXTX_ISR_OFFSET = 0, + DBG_SWDIAG_SCH_PROG_RXTX_ISR_MASK = 0x01, + + DBG_SWDIAG_SCH_PROG_END_ISR_OFFSET = 1, + DBG_SWDIAG_SCH_PROG_END_ISR_MASK = 0x02, + + DBG_SWDIAG_SCH_PROG_PROG_PUSH_OFFSET = 2, + DBG_SWDIAG_SCH_PROG_PROG_PUSH_MASK = 0x04, + + DBG_SWDIAG_SCH_PROG_SKIP_OFFSET = 3, + DBG_SWDIAG_SCH_PROG_SKIP_MASK = 0x08, + + DBG_SWDIAG_SCH_PROG_NB_PROG_OFFSET = 4, + DBG_SWDIAG_SCH_PROG_NB_PROG_MASK = 0xF0, + + /** + ****************************************************************************************** + * @brief BANK 31 : LE INITIATING + ****************************************************************************************** + */ + DBG_SWDIAG_LEINIT = 31, + + DBG_SWDIAG_LEINIT_START_OFFSET = 0, + DBG_SWDIAG_LEINIT_START_MASK = 0x01, + + DBG_SWDIAG_LEINIT_STOP_OFFSET = 1, + DBG_SWDIAG_LEINIT_STOP_MASK = 0x02, + + DBG_SWDIAG_LEINIT_EVT_START_OFFSET = 2, + DBG_SWDIAG_LEINIT_EVT_START_MASK = 0x04, + + DBG_SWDIAG_LEINIT_EVT_CANCELED_OFFSET = 3, + DBG_SWDIAG_LEINIT_EVT_CANCELED_MASK = 0x08, + + DBG_SWDIAG_LEINIT_FRM_CBK_OFFSET = 4, + DBG_SWDIAG_LEINIT_FRM_CBK_MASK = 0x10, + + DBG_SWDIAG_LEINIT_FRM_EOF_ISR_OFFSET = 5, + DBG_SWDIAG_LEINIT_FRM_EOF_ISR_MASK = 0x20, + + DBG_SWDIAG_LEINIT_SCHED_OFFSET = 6, + DBG_SWDIAG_LEINIT_SCHED_MASK = 0x40, + + DBG_SWDIAG_LEINIT_PKT_RX_OFFSET = 7, + DBG_SWDIAG_LEINIT_PKT_RX_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 32 : LE ADVERTISING + ****************************************************************************************** + */ + DBG_SWDIAG_LEADV = 32, + + DBG_SWDIAG_LEADV_START_OFFSET = 0, + DBG_SWDIAG_LEADV_START_MASK = 0x01, + + DBG_SWDIAG_LEADV_STOP_OFFSET = 1, + DBG_SWDIAG_LEADV_STOP_MASK = 0x02, + + DBG_SWDIAG_LEADV_EVT_START_OFFSET = 2, + DBG_SWDIAG_LEADV_EVT_START_MASK = 0x04, + + DBG_SWDIAG_LEADV_EVT_CANCELED_OFFSET = 3, + DBG_SWDIAG_LEADV_EVT_CANCELED_MASK = 0x08, + + DBG_SWDIAG_LEADV_RX_ISR_OFFSET = 4, + DBG_SWDIAG_LEADV_RX_ISR_MASK = 0x10, + + DBG_SWDIAG_LEADV_FRM_ISR_OFFSET = 5, + DBG_SWDIAG_LEADV_FRM_ISR_MASK = 0x20, + + DBG_SWDIAG_LEADV_SCHED_OFFSET = 6, + DBG_SWDIAG_LEADV_SCHED_MASK = 0x40, + + DBG_SWDIAG_LEADV_PKT_RX_OFFSET = 7, + DBG_SWDIAG_LEADV_PKT_RX_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 33 : LE CONNECTION + ****************************************************************************************** + */ + DBG_SWDIAG_LECON = 33, + + DBG_SWDIAG_LECON_START_OFFSET = 0, + DBG_SWDIAG_LECON_START_MASK = 0x01, + + DBG_SWDIAG_LECON_STOP_OFFSET = 1, + DBG_SWDIAG_LECON_STOP_MASK = 0x02, + + DBG_SWDIAG_LECON_EVT_START_OFFSET = 2, + DBG_SWDIAG_LECON_EVT_START_MASK = 0x04, + + DBG_SWDIAG_LECON_EVT_CANCELED_OFFSET = 3, + DBG_SWDIAG_LECON_EVT_CANCELED_MASK = 0x08, + + DBG_SWDIAG_LECON_RX_ISR_OFFSET = 4, + DBG_SWDIAG_LECON_RX_ISR_MASK = 0x10, + + DBG_SWDIAG_LECON_FRM_ISR_OFFSET = 5, + DBG_SWDIAG_LECON_FRM_ISR_MASK = 0x20, + + DBG_SWDIAG_LECON_SCHED_OFFSET = 6, + DBG_SWDIAG_LECON_SCHED_MASK = 0x40, + + DBG_SWDIAG_LECON_TX_ISR_OFFSET = 7, + DBG_SWDIAG_LECON_TX_ISR_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 34 : LE DATA + ****************************************************************************************** + */ + DBG_SWDIAG_LEDATA = 34, + + DBG_SWDIAG_LEDATA_LLCP_TX_OFFSET = 0, + DBG_SWDIAG_LEDATA_LLCP_TX_MASK = 0x01, + + DBG_SWDIAG_LEDATA_ACL_TX_OFFSET = 1, + DBG_SWDIAG_LEDATA_ACL_TX_MASK = 0x02, + + DBG_SWDIAG_LEDATA_LLCP_RX_OFFSET = 2, + DBG_SWDIAG_LEDATA_LLCP_RX_MASK = 0x04, + + DBG_SWDIAG_LEDATA_ACL_RX_OFFSET = 3, + DBG_SWDIAG_LEDATA_ACL_RX_MASK = 0x08, + + DBG_SWDIAG_LEDATA_LLCP_ACK_OFFSET = 4, + DBG_SWDIAG_LEDATA_LLCP_ACK_MASK = 0x10, + + DBG_SWDIAG_LEDATA_ACL_ACK_OFFSET = 5, + DBG_SWDIAG_LEDATA_ACL_ACK_MASK = 0x20, + + /** + ****************************************************************************************** + * @brief BANK 35 : LETX + ****************************************************************************************** + */ + DBG_SWDIAG_LETX = 35, + + DBG_SWDIAG_LETX_LLCP_TX_OFFSET = 0, + DBG_SWDIAG_LETX_LLCP_TX_MASK = 0x01, + + DBG_SWDIAG_LETX_ACL_TX_OFFSET = 1, + DBG_SWDIAG_LETX_ACL_TX_MASK = 0x02, + + DBG_SWDIAG_LETX_SW_IDX_OFFSET = 2, + DBG_SWDIAG_LETX_SW_IDX_MASK = 0x04, + + DBG_SWDIAG_LETX_HW_IDX_OFFSET = 3, + DBG_SWDIAG_LETX_HW_IDX_MASK = 0x08, + + DBG_SWDIAG_LETX_TX_CNT_OFFSET = 4, + DBG_SWDIAG_LETX_TX_CNT_MASK = 0x30, + + /** + ****************************************************************************************** + * @brief BANK 36 : LE PERIODIC ADVERTISING + ****************************************************************************************** + */ + DBG_SWDIAG_LEPERADV = 36, + + DBG_SWDIAG_LEPERADV_START_OFFSET = 0, + DBG_SWDIAG_LEPERADV_START_MASK = 0x01, + + DBG_SWDIAG_LEPERADV_STOP_OFFSET = 1, + DBG_SWDIAG_LEPERADV_STOP_MASK = 0x02, + + DBG_SWDIAG_LEPERADV_EVT_START_OFFSET = 2, + DBG_SWDIAG_LEPERADV_EVT_START_MASK = 0x04, + + DBG_SWDIAG_LEPERADV_EVT_CANCELED_OFFSET = 3, + DBG_SWDIAG_LEPERADV_EVT_CANCELED_MASK = 0x08, + + DBG_SWDIAG_LEPERADV_RX_ISR_OFFSET = 4, + DBG_SWDIAG_LEPERADV_RX_ISR_MASK = 0x10, + + DBG_SWDIAG_LEPERADV_FRM_ISR_OFFSET = 5, + DBG_SWDIAG_LEPERADV_FRM_ISR_MASK = 0x20, + + DBG_SWDIAG_LEPERADV_SCHED_OFFSET = 6, + DBG_SWDIAG_LEPERADV_SCHED_MASK = 0x40, + + /** + ****************************************************************************************** + * @brief BANK 37 : LE SYNC + ****************************************************************************************** + */ + DBG_SWDIAG_LESYNC = 37, + + DBG_SWDIAG_LESYNC_START_OFFSET = 0, + DBG_SWDIAG_LESYNC_START_MASK = 0x01, + + DBG_SWDIAG_LESYNC_STOP_OFFSET = 1, + DBG_SWDIAG_LESYNC_STOP_MASK = 0x02, + + DBG_SWDIAG_LESYNC_EVT_START_OFFSET = 2, + DBG_SWDIAG_LESYNC_EVT_START_MASK = 0x04, + + DBG_SWDIAG_LESYNC_EVT_CANCELED_OFFSET = 3, + DBG_SWDIAG_LESYNC_EVT_CANCELED_MASK = 0x08, + + DBG_SWDIAG_LESYNC_FRM_RX_ISR_OFFSET = 4, + DBG_SWDIAG_LESYNC_FRM_RX_ISR_MASK = 0x10, + + DBG_SWDIAG_LESYNC_FRM_EOF_ISR_OFFSET = 5, + DBG_SWDIAG_LESYNC_FRM_EOF_ISR_MASK = 0x20, + + DBG_SWDIAG_LESYNC_SCHED_OFFSET = 6, + DBG_SWDIAG_LESYNC_SCHED_MASK = 0x40, + + DBG_SWDIAG_LESYNC_PKT_RX_OFFSET = 7, + DBG_SWDIAG_LESYNC_PKT_RX_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 38 : ADV REPORT FILTER + ****************************************************************************************** + */ + DBG_SWDIAG_LEADVFILT = 38, + + DBG_SWDIAG_LEADVFILT_OK_OFFSET = 0, + DBG_SWDIAG_LEADVFILT_OK_MASK = 0x01, + + DBG_SWDIAG_LEADVFILT_KO_OFFSET = 1, + DBG_SWDIAG_LEADVFILT_KO_MASK = 0x02, + + DBG_SWDIAG_LEADVFILT_CHAIN_STAT_1M_OFFSET = 2, + DBG_SWDIAG_LEADVFILT_CHAIN_STAT_1M_MASK = 0x0C, + + DBG_SWDIAG_LEADVFILT_CNT_OFFSET = 4, + DBG_SWDIAG_LEADVFILT_CNT_MASK = 0xF0, + + /** + ****************************************************************************************** + * @brief BANK 39 : ACL_TX + ****************************************************************************************** + */ + DBG_SWDIAG_ACL_TX = 39, + + DBG_SWDIAG_ACL_TX_TRAFFIC_OFFSET = 0, + DBG_SWDIAG_ACL_TX_TRAFFIC_MASK = 0xFF, + + /** + ****************************************************************************************** + * @brief BANK 40 : ACL_RX + ****************************************************************************************** + */ + DBG_SWDIAG_ACL_RX = 40, + + DBG_SWDIAG_ACL_RX_TRAFFIC_OFFSET = 0, + DBG_SWDIAG_ACL_RX_TRAFFIC_MASK = 0xFF, + + /** + ****************************************************************************************** + * @brief BANK 41 : ISOOHCI (Audio over Application-Host-interface) + ****************************************************************************************** + */ + DBG_SWDIAG_ISOOHCI = 41, + + DBG_SWDIAG_ISOOHCI_RX_ISO_OFFSET = 0, + DBG_SWDIAG_ISOOHCI_RX_ISO_MASK = 0x01, + + DBG_SWDIAG_ISOOHCI_TX_ISO_OFFSET = 1, + DBG_SWDIAG_ISOOHCI_TX_ISO_MASK = 0x02, + + DBG_SWDIAG_ISOOHCI_RX_TOG_OFFSET = 2, + DBG_SWDIAG_ISOOHCI_RX_TOG_MASK = 0x04, + + DBG_SWDIAG_ISOOHCI_TX_TOG_OFFSET = 3, + DBG_SWDIAG_ISOOHCI_TX_TOG_MASK = 0x08, + + /** + ****************************************************************************************** + * @brief BANK 44 : ISO Generator Data Path + ****************************************************************************************** + */ + DBG_SWDIAG_ISOGEN = 44, + + DBG_SWDIAG_ISOGEN_RX_OK_OFFSET = 0, + DBG_SWDIAG_ISOGEN_RX_OK_MASK = 0x01, + + DBG_SWDIAG_ISOGEN_RX_NOT_GRANT_OFFSET = 1, + DBG_SWDIAG_ISOGEN_RX_NOT_GRANT_MASK = 0x02, + + DBG_SWDIAG_ISOGEN_RX_CRC_ERR_OFFSET = 2, + DBG_SWDIAG_ISOGEN_RX_CRC_ERR_MASK = 0x04, + + DBG_SWDIAG_ISOGEN_RX_SYNC_ERR_OFFSET = 3, + DBG_SWDIAG_ISOGEN_RX_SYNC_ERR_MASK = 0x08, + + DBG_SWDIAG_ISOGEN_RX_DATA_ERR_OFFSET = 4, + DBG_SWDIAG_ISOGEN_RX_DATA_ERR_MASK = 0x10, + + DBG_SWDIAG_ISOGEN_RX_EMPTY_OFFSET = 5, + DBG_SWDIAG_ISOGEN_RX_EMPTY_MASK = 0x20, + + DBG_SWDIAG_ISOGEN_TX_OK_OFFSET = 6, + DBG_SWDIAG_ISOGEN_TX_OK_MASK = 0x40, + + DBG_SWDIAG_ISOGEN_TX_NOT_GRANT_OFFSET = 7, + DBG_SWDIAG_ISOGEN_TX_NOT_GRANT_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 46 : ISOGEN TEST + ****************************************************************************************** + */ + DBG_SWDIAG_TST = 46, + + DBG_SWDIAG_TST_RX_GET_OFFSET = 0, + DBG_SWDIAG_TST_RX_GET_MASK = 0x01, + + DBG_SWDIAG_TST_RX_ISR_OFFSET = 1, + DBG_SWDIAG_TST_RX_ISR_MASK = 0x02, + + /** + ****************************************************************************************** + * @brief BANK 47 : SCH ARB + ****************************************************************************************** + */ + DBG_SWDIAG_SCH_ARB = 47, + + DBG_SWDIAG_SCH_ARB_INSERT_OFFSET = 0, + DBG_SWDIAG_SCH_ARB_INSERT_MASK = 0x01, + + DBG_SWDIAG_SCH_ARB_INSERT_ERR_OFFSET = 1, + DBG_SWDIAG_SCH_ARB_INSERT_ERR_MASK = 0x02, + + DBG_SWDIAG_SCH_ARB_REMOVE_OFFSET = 2, + DBG_SWDIAG_SCH_ARB_REMOVE_MASK = 0x04, + + DBG_SWDIAG_SCH_ARB_EVT_START_OFFSET = 3, + DBG_SWDIAG_SCH_ARB_EVT_START_MASK = 0x08, + + DBG_SWDIAG_SCH_ARB_SW_ISR_OFFSET = 4, + DBG_SWDIAG_SCH_ARB_SW_ISR_MASK = 0x10, + + DBG_SWDIAG_SCH_ARB_PROG_TIMER_OFFSET = 5, + DBG_SWDIAG_SCH_ARB_PROG_TIMER_MASK = 0x20, + + DBG_SWDIAG_SCH_ARB_ELT_CANCEL_OFFSET = 6, + DBG_SWDIAG_SCH_ARB_ELT_CANCEL_MASK = 0x40, + + DBG_SWDIAG_SCH_ARB_CONFLICT_OFFSET = 7, + DBG_SWDIAG_SCH_ARB_CONFLICT_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 48 : SAM + ****************************************************************************************** + */ + DBG_SWDIAG_SAM = 48, + + DBG_SWDIAG_SAM_RMAP_OFFSET_CFG_OFFSET = 0, + DBG_SWDIAG_SAM_RMAP_OFFSET_CFG_MASK = 0x01, + + DBG_SWDIAG_SAM_CFG_OFFSET = 1, + DBG_SWDIAG_SAM_CFG_MASK = 0x02, + + DBG_SWDIAG_SAM_LMAP_SET_OFFSET = 2, + DBG_SWDIAG_SAM_LMAP_SET_MASK = 0x04, + + DBG_SWDIAG_SAM_RMAP_SET_OFFSET = 3, + DBG_SWDIAG_SAM_RMAP_SET_MASK = 0x08, + + DBG_SWDIAG_SAM_RMAP_REFRESH_OFFSET = 4, + DBG_SWDIAG_SAM_RMAP_REFRESH_MASK = 0x10, + + DBG_SWDIAG_SAM_LMAP_EN_OFFSET = 5, + DBG_SWDIAG_SAM_LMAP_EN_MASK = 0x20, + + DBG_SWDIAG_SAM_RMAP_EN_OFFSET = 6, + DBG_SWDIAG_SAM_RMAP_EN_MASK = 0x40, + + DBG_SWDIAG_SAM_LSUBMAP_CFG_OFFSET = 7, + DBG_SWDIAG_SAM_LSUBMAP_CFG_MASK = 0x80, + + /** + ****************************************************************************************** + * @brief BANK 49 : MESH_DEMO_DISPLAY_LIGHT + ****************************************************************************************** + */ + DBG_SWDIAG_LIGHT = 49, + + DBG_SWDIAG_LIGHT_LIGHTNESS0_OFFSET = 0, + DBG_SWDIAG_LIGHT_LIGHTNESS0_MASK = 0x01, + + DBG_SWDIAG_LIGHT_LIGHTNESS1_OFFSET = 1, + DBG_SWDIAG_LIGHT_LIGHTNESS1_MASK = 0x02, + + DBG_SWDIAG_LIGHT_LIGHTNESS2_OFFSET = 2, + DBG_SWDIAG_LIGHT_LIGHTNESS2_MASK = 0x04, + + DBG_SWDIAG_LIGHT_LIGHTNESS3_OFFSET = 3, + DBG_SWDIAG_LIGHT_LIGHTNESS3_MASK = 0x08, + + DBG_SWDIAG_LIGHT_LIGHTNESS4_OFFSET = 4, + DBG_SWDIAG_LIGHT_LIGHTNESS4_MASK = 0x10, + + DBG_SWDIAG_LIGHT_LIGHTNESS5_OFFSET = 5, + DBG_SWDIAG_LIGHT_LIGHTNESS5_MASK = 0x20, + + DBG_SWDIAG_LIGHT_LIGHTNESS6_OFFSET = 6, + DBG_SWDIAG_LIGHT_LIGHTNESS6_MASK = 0x40, + + DBG_SWDIAG_LIGHT_LIGHTNESS7_OFFSET = 7, + DBG_SWDIAG_LIGHT_LIGHTNESS7_MASK = 0x80, + + /// Number of SW profiles - to increase when new bank are added + DBG_SWDIAG_NB_PROFILES = 50, +}; + + +/* + * GLOBAL VARIABLE DECLARATION + **************************************************************************************** + */ + +/// Allocate HW banks to SW profiles +extern uint8_t sw_to_hw[DBG_SWDIAG_NB_PROFILES]; + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** +****************************************************************************************** +* @brief Initialize SW profiling module +****************************************************************************************** +*/ +void dbg_swdiag_init(void); + +/** +****************************************************************************************** +* @brief Read the SW profiling configuration. +* +* @return SW profile configuration +****************************************************************************************** +*/ +uint32_t dbg_swdiag_read(void); + +/** +****************************************************************************************** +* @brief Write the SW profiling configuration. +* +* @param[in] profile SW profiling configuration to apply +****************************************************************************************** +*/ +void dbg_swdiag_write(uint32_t profile); + +#endif //RW_SWDIAG + +/// @} DBGSWDIAG + +#endif // DBG_SWDIAG_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_trc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_trc.h new file mode 100644 index 0000000..9ddff0b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_trc.h @@ -0,0 +1,1609 @@ +/** + **************************************************************************************** + * + * @file dbg_trc.h + * + * @brief This file contains definitions related to the Tracer module. + * + * Copyright (C) RivieraWaves 2009-2015 + * + **************************************************************************************** + */ + +#ifndef DBG_TRC_H_ +#define DBG_TRC_H_ + +/** +**************************************************************************************** +* @addtogroup TRACER +* @ingroup TRACER +* @brief Tracer module sends traces through UART +* @{ +**************************************************************************************** +*/ + +#include "rwip_config.h" +#if (TRACER_PRESENT) + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include + +#if (TRC_KE_MSG || TRC_KE_TMR) +#include "ke_msg.h" +#endif /*(TRC_KE_MSG || TRC_KE_TMR)*/ + +#if (TRC_ARB) +#include "sch_arb.h" +#endif /*(TRC_ARB) */ + +#if (TRC_ADV) +#include "lld.h" +#endif /*(TRC_ADV)*/ + +/* + * DEFINES + **************************************************************************************** + */ +#define TRC_GRP_B(__t) (__t##_BIT) +#define TRC_GRP_P(__t) (__t##_POS) + +#define TRC_MSG_TYPE 0x06 + +#define TRC_OPCODE_LEN (1) +#define TRC_PDULEN_LEN (2) +#define TRC_MSG_HDR_LEN (TRC_OPCODE_LEN + TRC_PDULEN_LEN) + +#define TRC_CFG_WORD_LEN (4) + +/* + * ENUMERATION DEFINITION + **************************************************************************************** + */ +/// Possible types of trace (parameter, size, conversion_to_string) +/*@TRACE*/ +enum trace_types +{ + #if TRC_KE_MSG + /* @TRACE_DEF + * TRC_NAME: trc_ke_msg_send + * TRC_VARS: msg_id_names = get_elements(TASK_API_ID, "'@%s_msg_id'%(#.lower().rsplit('_', 1)[1])") + * TRC_UNION: ("Parameters", "$Message_id", msg_id_names, "#.lower()") + * @NO_PAD + * + * ('Message_id' , uint16_t, "@['%s_msg_id'%(@TASK_API_ID.name(int($Message_id >> 8)).rsplit('_',1)[1].lower())].name(int($Message_id))", msg_id_names), + * ('Destination_task_id', uint16_t, "@KE_TASK_TYPE.name(int($Destination_task_id & 0x00FF))", '@KE_TASK_TYPE'), + * ('Source_task_id', uint16_t, "@KE_TASK_TYPE.name(int($Source_task_id & 0x00FF))", '@KE_TASK_TYPE'), + * ('Parameter_length', uint16_t), + * ('Parameters', "union", CArray(uint8_t, '$Parameter_length')) + */ + KE_MSG_SEND = 0x00, + + /* @TRACE_DEF + * TRC_NAME: trc_ke_msg_handled + * TRC_VARS: msg_id_names = get_elements(TASK_API_ID, "'@%s_msg_id'%(#.lower().rsplit('_', 1)[1])") + * @NO_PAD + * + * ('Message_id' , uint16_t, "@['%s_msg_id'%(@TASK_API_ID.name(int($Message_id >> 8)).rsplit('_',1)[1].lower())].name(int($Message_id))", msg_id_names), + * ('Destination_task_id', uint16_t, "@KE_TASK_TYPE.name(int($Destination_task_id & 0x00FF))", '@KE_TASK_TYPE'), + * ('Source_task_id', uint16_t, "@KE_TASK_TYPE.name(int($Source_task_id & 0x00FF))", '@KE_TASK_TYPE'), + * ('Message_status', uint8_t, "@ke_msg_status_tag.name(int($Message_status))", '@ke_msg_status_tag') + */ + KE_MSG_HANDLED = 0x01, + #endif /*TRC_KE_MSG*/ + + #if TRC_KE_TMR + /* @TRACE_DEF + * TRC_NAME: trc_ke_tmr_set + * TRC_VARS: msg_id_names = get_elements(TASK_API_ID, "'@%s_msg_id'%(#.lower().rsplit('_', 1)[1])") + * @NO_PAD + * + * ('Target_time' , uint32_t), + * ('Task_ID', uint16_t, "@KE_TASK_TYPE.name(int($Task_ID & 0x00FF))", '@KE_TASK_TYPE'), + * ('Message_id', uint16_t, "@['%s_msg_id'%(@TASK_API_ID.name(int($Message_id >> 8)).rsplit('_',1)[1].lower())].name(int($Message_id))", msg_id_names) + */ + KE_TMR_SET = 0x02, + + /* @TRACE_DEF + * TRC_NAME: trc_ke_tmr_clr + * TRC_VARS: msg_id_names = get_elements(TASK_API_ID, "'@%s_msg_id'%(#.lower().rsplit('_', 1)[1])") + * @NO_PAD + * + * + * ('Target_time' , uint32_t), + * ('Task_ID', uint16_t, "@KE_TASK_TYPE.name(int($Task_ID & 0x00FF))", '@KE_TASK_TYPE'), + * ('Message_id', uint16_t, "@['%s_msg_id'%(@TASK_API_ID.name(int($Message_id >> 8)).rsplit('_',1)[1].lower())].name(int($Message_id))", msg_id_names) + */ + KE_TMR_CLR = 0x03, + + /* @TRACE_DEF + * TRC_NAME: trc_ke_tmr_exp + * TRC_VARS: msg_id_names = get_elements(TASK_API_ID, "'@%s_msg_id'%(#.lower().rsplit('_', 1)[1])") + * @NO_PAD + * + * ('Target_time' , uint32_t), + * ('Task_ID', uint16_t, "@KE_TASK_TYPE.name(int($Task_ID & 0x00FF))", '@KE_TASK_TYPE'), + * ('Message_id', uint16_t, "@['%s_msg_id'%(@TASK_API_ID.name(int($Message_id >> 8)).rsplit('_',1)[1].lower())].name(int($Message_id))", msg_id_names) + */ + KE_TMR_EXP = 0x04, + #endif /*TRC_KE_TMR*/ + + #if TRC_KE_EVT + /* @TRACE_DEF + * TRC_NAME: trc_ke_evt_set + * @NO_PAD + * + * ('Event_type', uint8_t, "@KE_EVENT_TYPE.name(int($Event_type))", '@KE_EVENT_TYPE'), + */ + KE_EVT_SET = 0x05, + + /* @TRACE_DEF + * TRC_NAME: trc_ke_evt_handled + * @NO_PAD + * + * ('Event_type', uint8_t, "@KE_EVENT_TYPE.name(int($Event_type))", '@KE_EVENT_TYPE') + */ + KE_EVT_HANDLED = 0x06, + + #endif /* TRC_KE_EVT */ + + #if TRC_MEM + /* @TRACE_DEF + * TRC_NAME: trc_mem_alloc + * @NO_PAD + * + * ('Heap_ID', uint8_t, "@KE_MEM_HEAP.name(int($Heap_ID))", '@KE_MEM_HEAP'), + * ('Block_address', uint32_t), + * ('Size', uint32_t), + */ + MEM_ALLOC = 0x07, + + /* @TRACE_DEF + * TRC_NAME: trc_mem_free + * @NO_PAD + * + * ('Heap_ID', uint8_t, "@KE_MEM_HEAP.name(int($Heap_ID))", '@KE_MEM_HEAP'), + * ('Block_address', uint32_t), + * ('Size', uint32_t), + */ + MEM_FREE = 0x08, + + #endif /*TRC_MEM*/ + + #if TRC_SLEEP + /* @TRACE_DEF + * TRC_NAME: trc_sleep_enter + */ + SLEEP_ENTER = 0x09, + + /* @TRACE_DEF + * TRC_NAME: trc_sleep_wakeup + */ + SLEEP_WAKEUP = 0x0A, + #endif /*TRC_SLEEP*/ + + #if TRC_SW_ASS + //TODO[AAL] add support for strings in rwdt_types + ASSERT_WARNING = 0x0B, + ASSERT_ERROR = 0x0C, + #endif /*TRC_SW_ASS*/ + + #if TRC_PROG + /* @TRACE_DEF + * TRC_NAME: trc_et_prog + * @NO_PAD + * + * ('Entry_index', uint8_t), + * ('Entry_value', ET), + */ + ET_PROG = 0x0D, + + /* @TRACE_DEF + * TRC_NAME: trc_conn_evt_cnt + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Event_counter', uint16_t), + */ + CONN_EVT_CNT = 0x0E, + + /* @TRACE_DEF + * TRC_NAME: trc_frm_cmp_bt + * @NO_PAD + * + * ('Timestamp_programmed_frame', uint32_t), + * ('Frame_identifier', uint8_t), + * ('Callback_for_interrupt_handling', uint32_t) + */ + FRM_CMP_BT = 0x0F, + /* @TRACE_DEF + * TRC_NAME: trc_frm_cmp_ble + * @NO_PAD + * + * ('Timestamp_programmed_frame', uint32_t), + * ('Frame_identifier', uint8_t), + * ('Callback_for_interrupt_handling', uint32_t) + */ + FRM_CMP_BLE = 0x10, + #endif /*TRC_PROG*/ + + #if TRC_CS_BLE + /* @TRACE_DEF + * TRC_NAME: trc_cs_ble + * @NO_PAD + * + * ('Control_structure', CS), + */ + CS_BLE = 0x11, + #endif /*TRC_CS_BLE*/ + + #if TRC_CS_BT + CS_BT = 0x12, + #endif /*TRC_CS_BT*/ + + #if TRC_RX_DESC + /* @TRACE_DEF + * TRC_NAME: trc_rx_desc + * @NO_PAD + * + * ('Driver_type', uint8_t, "@lld_driver_types.name(int($Driver_type))", '@lld_driver_types'), + * ('Connection_index', uint8_t), + * ('Rx_descriptor', RX_DESC) + */ + RX_DESC = 0x13, + #endif /*TRC_RX_DESC*/ + + #if TRC_LLCP + /* @TRACE_DEF + * TRC_NAME: trc_llcp_tx + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Data_Length', uint8_t), + * ('LLCP_pdu', llcp_pdu) + */ + LLCP_TX = 0x14, + + /* @TRACE_DEF + * TRC_NAME: trc_llcp_rx + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Data_Length', uint8_t), + * ('LLCP_pdu', llcp_pdu) + */ + LLCP_RX = 0x15, + + /* @TRACE_DEF + * TRC_NAME: trc_llcp_ack + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Data_Length', uint8_t), + * ('LLCP_pdu', llcp_pdu) + */ + LLCP_ACK = 0x16, + #endif /*TRC_LLCP*/ + + #if TRC_LMP + /* @TRACE_DEF + * TRC_NAME: trc_lmp_tx + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Data_Length', uint8_t), + * ('TrID', uint8_t), + * ('Opcode', uint8_t), + * ('Data', CArray(uint8_t, '$Data_Length')), + */ + LMP_TX = 0x17, + + /* @TRACE_DEF + * TRC_NAME: trc_lmp_rx + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Data_Length', uint8_t), + * ('TrID', uint8_t), + * ('Opcode', uint8_t), + * ('Data', CArray(uint8_t, '$Data_Length')), + */ + LMP_RX = 0x18, + + /* @TRACE_DEF + * TRC_NAME: trc_lmp_ack + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Data_Length', uint8_t), + * ('TrID', uint8_t), + * ('Opcode', uint8_t), + * ('Data', CArray(uint8_t, '$Data_Length')), + */ + LMP_ACK = 0x19, + #endif /*TRC_LMP*/ + + #if TRC_L2CAP + /* @TRACE_DEF + * TRC_NAME: trc_l2cap_tx + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Data_Length', uint16_t), + * ('l2cc_pdu', l2cc_pdu) + */ + L2CAP_TX = 0x1A, + + /* @TRACE_DEF + * TRC_NAME: trc_l2cap_rx + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Data_Length', uint16_t), + * ('l2cc_pdu', l2cc_pdu), + */ + L2CAP_RX = 0x1B, + + /* @TRACE_DEF + * TRC_NAME: trc_l2cap_ack + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Number_acknowledged_packets', uint16_t), + */ + L2CAP_ACK = 0x1C, + #endif /*TRC_L2CAP*/ + + #if TRC_ARB + /* @TRACE_DEF + * TRC_NAME: trc_sch_arb_req + * @NO_PAD + * + * ('Target_time', uint32_t), + * ('elt_address', uint32_t), + * ('Status', uint8_t), + * ('sch_arb_elt', sch_arb_elt_tag) + */ + SCH_ARB_REQ = 0x1D, + + /* @TRACE_DEF + * TRC_NAME: trc_sch_arb_canc + * @NO_PAD + * + * ('elt_address', uint32_t), + */ + SCH_ARB_CANC = 0x1E, + + /* @TRACE_DEF + * TRC_NAME: trc_sch_arb_rem + * @NO_PAD + * + * ('elt_address', uint32_t), + */ + SCH_ARB_REM = 0x1F, + + /* @TRACE_DEF + * TRC_NAME: trc_sch_arb_start + * @NO_PAD + * + * ('elt_address', uint32_t), + */ + SCH_ARB_START = 0x20, + + /* @TRACE_DEF + * TRC_NAME: trc_sch_arb_shift + * @NO_PAD + * + * ('elt_address', uint32_t), + * ('Current_prio', uint8_t), + * ('Duration_min', uint32_t), + * ('Timestamp', uint32_t), + */ + SCH_ARB_SHIFT = 0x21, + #endif /*TRC_ARB*/ + + #if TRC_LC_STATE_TRANS + LC_ST = 0x22, + #endif /*TRC_LC_STATE_TRANS*/ + + #if TRC_LLC_STATE_TRANS + /* @TRACE_DEF + * TRC_NAME: trc_llc_st + * TRC_VARS: llc_proc_states = get_elements(llc_proc_id, "'@llc_%s_state'%(#.split('_', 2)[2].lower())") + * @NO_PAD + * + * ('Connection_handle', uint16_t), + * ('Procedure_ID', uint8_t, '@llc_proc_id.name(int($Procedure_ID))', '@llc_proc_id'), + * ('Previous_state', uint8_t, "@['_llc_%s_state'%(@llc_proc_id.name(int($Procedure_ID)).split('_', 2)[2].lower())].name(int($Previous_state))", llc_proc_states), + * ('Current_state', uint8_t, "@['llc_%s_state'%(@llc_proc_id.name(int($Procedure_ID)).split('_', 2)[2].lower())].name(int($Current_state))", llc_proc_states), + */ + LLC_ST = 0x23, + #endif /*TRC_LLC_STATE_TRANS*/ + + #if TRC_HCI + /* @TRACE_DEF + * TRC_NAME: trc_hci_cmd + * TRC_UNION: ("Parameters", "$Hci_opcode", hci_opcode, "#.rsplit('_OPCODE', 1)[0].lower()") + * @NO_PAD + * + * ('Hci_opcode', uint16_t, '@hci_opcode.name(int($Hci_opcode))', '@hci_opcode'), + * ('Param_length', uint16_t), + * ('Parameters', "union", CArray(uint8_t, '$Param_length')) + */ + HCI_CMD = 0x24, + + + /* @TRACE_DEF + * TRC_NAME: trc_hci_cmd_stat_evt + * TRC_UNION: ("Parameters", "$Hci_opcode", hci_opcode, "'%s_cmp_evt'%(#.rsplit('_OPCODE', 1)[0].lower())") + * @NO_PAD + * + * ('Hci_opcode', uint16_t, '@hci_opcode.name(int($Hci_opcode))', '@hci_opcode'), + * ('Param_length', uint16_t), + * ('Parameters', "union", CArray(uint8_t, '$Param_length')) + */ + HCI_CMD_STAT_EVT = 0x25, + + + /* @TRACE_DEF + * TRC_NAME: trc_hci_cmd_cmp_evt + * TRC_UNION: ("Parameters", "$Hci_opcode", hci_opcode, "'%s_cmp_evt'%(#.rsplit('_OPCODE', 1)[0].lower())") + * @NO_PAD + * + * ('Hci_opcode', uint16_t, '@hci_opcode.name(int($Hci_opcode))', '@hci_opcode'), + * ('Param_length', uint16_t), + * ('Parameters', "union", CArray(uint8_t, '$Param_length')) + */ + HCI_CMD_CMP_EVT = 0x26, + + /* @TRACE_DEF + * TRC_NAME: trc_hci_evt + * TRC_UNION: ("Parameters", "$Hci_evt_code", hci_evt_code, "#.rsplit('_CODE', 1)[0].lower()") + * @NO_PAD + * + * ('Hci_evt_code', uint16_t, '@hci_evt_code.name(int($Hci_evt_code))', '@hci_evt_code'), + * ('Param_length', uint16_t), + * ('Parameters', "union", CArray(uint8_t, '$Param_length')) + */ + HCI_EVT = 0x27, + + /* @TRACE_DEF + * TRC_NAME: trc_hci_le_evt + * TRC_UNION: ("Parameters", "$Hci_le_subcode", hci_le_evt_subcode, "#.rsplit('_SUBCODE', 1)[0].lower()") + * @NO_PAD + * + * ('Hci_le_subcode', uint16_t, '@hci_le_evt_subcode.name(int($Hci_le_subcode))', '@hci_le_evt_subcode'), + * ('Param_length', uint16_t), + * ('Parameters', "union", CArray(uint8_t, '$Param_length')) + */ + HCI_LE_EVT = 0x28, + #endif /*TRC_HCI*/ + + #if TRC_ADV + /* @TRACE_DEF + * TRC_NAME: trc_adv_init_rx + * + * ('adv_pdu', trc_init_rx_pdu) + */ + ADV_INIT_RX = 0x29, + + /* @TRACE_DEF + * TRC_NAME: trc_adv_init_tx + * + * ('adv_pdu', trc_adv_tx_pdu) + */ + ADV_INIT_TX = 0x30, + + /* @TRACE_DEF + * TRC_NAME: trc_adv_scan_rx + * + * ('adv_pdu', trc_scan_rx_pdu) + */ + ADV_SCAN_RX = 0x31, + + /* @TRACE_DEF + * TRC_NAME: trc_adv_scan_tx + * + * ('adv_pdu', trc_adv_tx_pdu) + */ + ADV_SCAN_TX = 0x32, + + /* @TRACE_DEF + * TRC_NAME: trc_adv_adv_rx + * TRC_UNION: ("payload", "$packet_type", ble_adv_type, [ + * ('BLE_CONNECT_IND', 'connect_req'), + * ('BLE_SCAN_REQ', 'scan_req'), + * ]) + * @NO_PAD + * + * ('packet_type', uint8_t, '@ble_adv_type.name(int($packet_type))', '@ble_adv_type'), + * ('used_channel', uint8_t), + * ('payload_length', uint8_t), + * ('payload', "union", CArray(uint8_t, '$payload_length')) + */ + ADV_ADV_RX = 0x33, + + /* @TRACE_DEF + * TRC_NAME: trc_adv_adv_tx + * + * ('adv_pdu', trc_adv_tx_pdu) + */ + ADV_ADV_TX = 0x34, + #endif /*TRC_ADV*/ + + #if TRC_ACL + /* @TRACE_DEF + * TRC_NAME: trc_acl_rx + * + * ('adv_pdu', trc_acl_rx_pdu) + */ + ACL_RX = 0x35, + + /* @TRACE_DEF + * TRC_NAME: trc_acl_prog_tx + * + * ('adv_pdu', trc_acl_tx_pdu) + */ + ACL_PROG_TX = 0x36, + + /* @TRACE_DEF + * TRC_NAME: trc_acl_ack_tx + * + * ('adv_pdu', trc_acl_tx_pdu) + */ + ACL_ACK_TX = 0x37, + #endif /*TRC_ACL*/ + + #if TRC_CUSTOM + /* @TRACE_DEF + * TRC_NAME: trc_custom + * TRC_UNION: ("Data", "$Trace_type", custom_trace_types, "#.lower()") + * + * ('Custom_trace_ID', uint8_t), + * ('Trace_type', uint8_t, "@custom_trace_types.name(int($Trace_type))", '@custom_trace_types'), + * ('Data', "union"), + */ + CUSTOM = 0x38, + #endif /*TRC_CUSTOM*/ +}; + +/// Configuration word bit field +/// +/// 7 6 5 4 3 2 1 0 +/// +-------+-------+-------+-------+-------+-------+-------+-------+ +/// |CS_BLE | PROG |SW_ASS | SLEEP | MEM |KE_EVT |KE_TMR |KE_MSG | +/// +-------+-------+-------+-------+-------+-------+-------+-------+ +/// +/// 15 14 13 12 11 10 9 8 +/// +-------+-------+-------+-------+-------+-------+-------+-------+ +/// | LC_ST |LLC_ST | ARB | L2CAP | LMP | LLCP |RX_DESC| CS_BT | +/// +-------+-------+-------+-------+-------+-------+-------+-------+ +/// +/// 23 22 21 20 19 18 17 16 +/// +-------+-------+-------+-------+-------+-------+-------+-------+ +/// | | | | |CUSTOM | ACL | ADV | HCI | +/// +-------+-------+-------+-------+-------+-------+-------+-------+ +/// +/// 31 30 29 28 27 26 25 24 +/// +-------+-------+-------+-------+-------+-------+-------+-------+ +/// | | | | | | | | | +/// +-------+-------+-------+-------+-------+-------+-------+-------+ +/// +enum dbg_trc_cfg_fields +{ + /// Kernel message + TRC_KE_MSG_POS = 0, + TRC_KE_MSG_BIT = 0x00000001, + + /// Kernel timer + TRC_KE_TMR_POS = 1, + TRC_KE_TMR_BIT = 0x00000002, + + /// Kernel event + TRC_KE_EVT_POS = 2, + TRC_KE_EVT_BIT = 0x00000004, + + /// Memory allocation and deallocation + TRC_MEM_POS = 3, + TRC_MEM_BIT = 0x00000008, + + /// Sleep mode + TRC_SLEEP_POS = 4, + TRC_SLEEP_BIT = 0x00000010, + + /// Software Assert + TRC_SW_ASS_POS = 5, + TRC_SW_ASS_BIT = 0x00000020, + + /// Programming of the exchange table, updating of the event counter and handling of "End of Event" interrupt + TRC_PROG_POS = 6, + TRC_PROG_BIT = 0x00000040, + + /// BLE Control structure + TRC_CS_BLE_POS = 7, + TRC_CS_BLE_BIT = 0x00000080, + + /// BT Control structure + TRC_CS_BT_POS = 8, + TRC_CS_BT_BIT = 0x00000100, + + /// Processing of RX descriptors at each LLD driver + TRC_RX_DESC_POS = 9, + TRC_RX_DESC_BIT = 0x00000200, + + /// LLCP transmission, reception and acknowledgment + TRC_LLCP_POS = 10, + TRC_LLCP_BIT = 0x00000400, + + /// LMP transmission, reception and acknowledgment + TRC_LMP_POS = 11, + TRC_LMP_BIT = 0x00000800, + + /// L2CAP transmission, reception and acknowledgment + TRC_L2CAP_POS = 12, + TRC_L2CAP_BIT = 0x00001000, + + /// Scheduling request, cancellation, shift and remove + TRC_ARB_POS = 13, + TRC_ARB_BIT = 0x00002000, + + /// LLC state transition + TRC_LLC_STATE_TRANS_POS = 14, + TRC_LLC_STATE_TRANS_BIT = 0x00004000, + + /// LC state transition + TRC_LC_STATE_TRANS_POS = 15, + TRC_LC_STATE_TRANS_BIT = 0x00008000, + + /// HCI messages (in Full embedded mode) + TRC_HCI_POS = 16, + TRC_HCI_BIT = 0x00010000, + + /// Advertising pdu + TRC_ADV_POS = 17, + TRC_ADV_BIT = 0x00020000, + + /// ACL pdu + TRC_ACL_POS = 18, + TRC_ACL_BIT = 0x00040000, + + /// Custom trace + TRC_CUSTOM_POS = 19, + TRC_CUSTOM_BIT = 0x00080000, +}; + +/// Tracer packet types +enum dbg_trc_pkt_types +{ + /// Trace message + TRACE = 0x01, + /// Configuration message + TRACER_CFG = 0x02, + /// Acknowledgment message + TRACER_ACK = 0x03 +}; + +#if (TRC_RX_DESC) +/// LLD driver types +/*@TRACE*/ +enum lld_driver_types +{ + LLD_SCAN = 0x01, + LLD_INIT = 0x02, + LLD_ADV = 0x03, + LLD_CON = 0x04, +}; +#endif /*(TRC_RX_DESC)*/ + +#if (TRC_CUSTOM) +/// Custom trace types +/*@TRACE*/ +enum custom_trace_types +{ + UINT8_T = 0x01, + UINT16_T = 0x02, + UINT32_T = 0x03, + VOID = 0x04, +}; +#endif /*(TRC_CUSTOM)*/ +#endif /*(TRACER_PRESENT)*/ + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATION + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Request a new trace + * + * This function checks the current configuration of the tracer + * + **************************************************************************************** + */ +#if (TRACER_PRESENT && TRC_KE_MSG) +/** + **************************************************************************************** + * @brief Trace request API for kernel message pushed in the send queue + * + * This function is called when a kernel message is pushed in the send queue. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "kernel message" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] msg Kernel message + **************************************************************************************** + */ +void dbg_trc_req_ke_msg_send(struct ke_msg const *msg); + +/// Macro used to send trace request API for kernel message send +#define TRC_REQ_KE_MSG_SEND(msg) \ + dbg_trc_req_ke_msg_send(msg); + +/** + **************************************************************************************** + * @brief Trace request API for kernel message handled + * + * This function is called when a task handles a message + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "kernel message" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] id Kernel message id + * @param[in] dest_id Destination kernel identifier + * @param[in] src_id Source kernel identifier + * @param[in] msg_status Status returned by the kernel message handler + **************************************************************************************** + */ +void dbg_trc_req_ke_msg_handled(ke_msg_id_t const id, ke_task_id_t const dest_id, ke_task_id_t const src_id, uint8_t const msg_status); + +/// Macro used to send trace request API for kernel message handled +#define TRC_REQ_KE_MSG_HANDLED(id, dest_id, src_id, msg_status) \ + dbg_trc_req_ke_msg_handled(id, dest_id, src_id, msg_status); +#else /*TRACER_PRESENT && TRC_KE_MSG*/ +#define TRC_REQ_KE_MSG_SEND(msg) +#define TRC_REQ_KE_MSG_HANDLED(id, dest_id, src_id, msg_status) +#endif /*TRACER_PRESENT && TRC_KE_MSG*/ + +#if (TRACER_PRESENT && TRC_KE_TMR) +/** + **************************************************************************************** + * @brief Trace request API for kernel timer + * + * This function is called when a kernel timer is set, cleared or expired. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "kernel timer" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] tmr_trc_type Trace type for kernel timer (timer set, cleared and expired of @see enum trace_types) + * @param[in] target_time Timer time value + * @param[in] task_id Timer task identifier + * @param[in] msg_id Timer message identifier + **************************************************************************************** + */ +void dbg_trc_req_ke_tmr(uint8_t const tmr_trc_type, uint32_t const target_time, ke_task_id_t const task_id, ke_msg_id_t const msg_id); + +/// Macro used to send trace request API for kernel timer set +#define TRC_REQ_KE_TMR_SET(target_time, task_id, msg_id) \ + dbg_trc_req_ke_tmr(KE_TMR_SET, target_time, task_id, msg_id); + +/// Macro used to send trace request API for kernel timer cleared +#define TRC_REQ_KE_TMR_CLR(target_time, task_id, msg_id) \ + dbg_trc_req_ke_tmr(KE_TMR_CLR,target_time, task_id, msg_id); + +/// Macro used to send trace request API for kernel timer expired +#define TRC_REQ_KE_TMR_EXP(target_time, task_id, msg_id) \ + dbg_trc_req_ke_tmr(KE_TMR_EXP,target_time, task_id, msg_id); +#else /*(TRACER_PRESENT && TRC_KE_TMR)*/ +#define TRC_REQ_KE_TMR_SET(target_time, task_id, msg_id) +#define TRC_REQ_KE_TMR_CLR(target_time, task_id, msg_id) +#define TRC_REQ_KE_TMR_EXP(target_time, task_id, msg_id) +#endif /*(TRACER_PRESENT && TRC_KE_TMR)*/ + +#if (TRACER_PRESENT && TRC_KE_EVT) +/** + **************************************************************************************** + * @brief Trace request API for kernel event + * + * This function is called when a kernel event is set or handled. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "kernel event" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] evt_req_type Trace type for kernel event (event set and handled of @see enum trace_types) + * @param[in] event_type Type of event + **************************************************************************************** + */ +void dbg_trc_req_ke_evt(uint8_t const evt_trc_type, uint8_t const event_type); + +/// Macro used to send trace request API for kernel event set +#define TRC_REQ_KE_EVT_SET(evt_type) \ + dbg_trc_req_ke_evt(KE_EVT_SET, evt_type); + +/// Macro used to send trace request API for kernel event handled +#define TRC_REQ_KE_EVT_HANDLED(evt_type) \ + dbg_trc_req_ke_evt(KE_EVT_HANDLED, evt_type); +#else /*(TRACER_PRESENT && TRC_KE_EVT)*/ +#define TRC_REQ_KE_EVT_SET(evt_type) +#define TRC_REQ_KE_EVT_HANDLED(evt_type) +#endif /*(TRACER_PRESENT && TRC_KE_EVT)*/ + +#if (TRACER_PRESENT && TRC_MEM) +/** + **************************************************************************************** + * @brief Trace request API for memory management + * + * This function is called when the memory is allocated or freed. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "memory" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] mem_trc_type Trace type for memory management (memory alloc and free of @see enum trace_types) + * @param[in] heap_id Heap identifier + * @param[in] blk_address Address of the used memory block + * @param[in] size Size of the memory area that has been allocated or freed. + **************************************************************************************** + */ +void dbg_trc_req_mem(uint8_t const mem_trc_type, uint8_t const heap_id, void const *blk_address, uint32_t const size); + +/// Macro used to send trace request API for memory allocation +#define TRC_REQ_MEM_ALLOC(heap_id, blk_address, size) \ + dbg_trc_req_mem(MEM_ALLOC, heap_id, blk_address, size); + +/// Macro used to send trace request API for memory deallocation +#define TRC_REQ_MEM_FREE(heap_id, blk_address, size) \ + dbg_trc_req_mem(MEM_FREE, heap_id, blk_address, size); + +#else /*(TRACER_PRESENT && TRC_MEM)*/ +#define TRC_REQ_MEM_ALLOC(heap_id, blk_address, size) +#define TRC_REQ_MEM_FREE(heap_id, blk_address, size) +#endif/*(TRACER_PRESENT && TRC_MEM)*/ + +#if (TRACER_PRESENT && TRC_SLEEP) +/** + **************************************************************************************** + * @brief Trace request API for sleep mode + * + * This function is called when the IP enter in deep sleep and when it wakes up. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "sleep" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] sleep_trc_type Trace type for sleep mode (sleep enter and wakeup of @see enum trace_types) + **************************************************************************************** + */ +void dbg_trc_req_deep_sleep(uint8_t const sleep_trc_type); + +/// Macro used to send trace request API when the IP enters in deep sleep +#define TRC_REQ_SLEEP() \ + dbg_trc_req_deep_sleep(SLEEP_ENTER); + +/// Macro used to send trace request API when the IP wakes up from deep sleep +#define TRC_REQ_WAKEUP() \ + dbg_trc_req_deep_sleep(SLEEP_WAKEUP); + +#else /*(TRACER_PRESENT && TRC_SLEEP)*/ +#define TRC_REQ_SLEEP() +#define TRC_REQ_WAKEUP() +#endif /*(TRACER_PRESENT && TRC_SLEEP)*/ + +#if (TRACER_PRESENT && TRC_SW_ASS) +/** + **************************************************************************************** + * @brief Trace request API for software asserts + * + * This function is called when an assertion statement is evaluated as true. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "sw assertions" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] ass_trc_type Trace type for assertions (assert warning and assert error of @see enum trace_types) + * @param[in] filename Name of the file that triggered the assertion + * @param[in] code_line Line of code where the assertion was triggered + * @param[in] param0 Parameter value 0 + * @param[in] param1 Parameter value 1 + **************************************************************************************** + */ +void dbg_trc_req_sw_ass(uint8_t const ass_trc_type, char const *filename, uint16_t const code_line, uint32_t const param0, uint32_t const param1); + +/// Macro used to send trace request API when an assert warning is evaluated as true +#define TRC_REQ_SW_ASS_WARN(filename, code_line, param0, param1) \ + dbg_trc_req_sw_ass(ASSERT_WARNING, filename, code_line, param0, param1); + +/// Macro used to send trace request API when an assert warning is evaluated as true +#define TRC_REQ_SW_ASS_ERR(filename, code_line, param0, param1) \ + dbg_trc_req_sw_ass(ASSERT_ERROR, filename, code_line, param0, param1); + +#else /*(TRACER_PRESENT && TRC_SW_ASS)*/ +#define TRC_REQ_SW_ASS_WARN(filename, code_line, param0, param1) +#define TRC_REQ_SW_ASS_ERR(filename, code_line, param0, param1) +#endif /*(TRACER_PRESENT && TRC_SW_ASS)*/ + +#if (TRACER_PRESENT && TRC_PROG) +/** + **************************************************************************************** + * @brief Trace request API for exchange table programming + * + * This function is called when the exchange table is programmed. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "programming" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] elt_idx Index of the programmed entry in the ET + **************************************************************************************** + */ +void dbg_trc_req_et_prog(uint8_t const elt_idx); + +#define TRC_REQ_ET_PROG(elt_idx) \ + dbg_trc_req_et_prog(elt_idx); + +/** + **************************************************************************************** + * @brief Trace request API for connection event counter programming + * + * This function is called when the connection event counter is set. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "programming" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] conhdl Connection handle + * @param[in] value Value of connection event counter + **************************************************************************************** + */ +void dbg_trc_req_evt_cnt(uint16_t const conhdl, uint16_t const value); +#define TRC_REQ_EVT_CNT(conhdl, value) \ + dbg_trc_req_evt_cnt(conhdl, value); +/** + **************************************************************************************** + * @brief Trace request API for frame completion + * + * This function is called when a frame is completed. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "programming" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] timestamp Timestamp of the programmed frame (in BLE slots, based on local clock) + * @param[in] frm_id Frame identifier + * @param[in] frm_cbk Callback for handling interrupts related to the frame + **************************************************************************************** + */ +void dbg_trc_req_frm_cmp(uint32_t const timestamp, uint8_t const frm_id, uint32_t const frm_cbk); + +#define TRC_REQ_FRM_CMP(timestamp, frm_id, frm_cbk) \ + dbg_trc_req_frm_cmp(timestamp, frm_id, frm_cbk); + +#else /*(TRACER_PRESENT && TRC_PROG)*/ +#define TRC_REQ_ET_PROG(elt_idx) +#define TRC_REQ_EVT_CNT(conhdl, value) +#define TRC_REQ_FRM_CMP(timestamp, frm_id, frm_cbk) +#endif /*(TRACER_PRESENT && TRC_PROG)*/ + +#if (TRACER_PRESENT && TRC_CS_BLE) +/** + **************************************************************************************** + * @brief Trace request API for control structure programming in BLE + * + * This function is called when a control structure is modified. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "BLE control structure" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] cs_addr Address of the control structure in the exchange memory + **************************************************************************************** + */ +void dbg_trc_req_cs_ble(uint16_t const cs_addr); + +#define TRC_REQ_CS_BLE(cs_addr) \ + dbg_trc_req_cs_ble(cs_addr); + +#else /*(TRACER_PRESENT && TRC_CS_BLE)*/ +#define TRC_REQ_CS_BLE(cs_addr) +#endif /*(TRACER_PRESENT && TRC_CS_BLE)*/ + +#if (TRACER_PRESENT && TRC_CS_BT) +/** + **************************************************************************************** + * @brief Trace request API for control structure programming in BT + * + * This function is called when a control structure is modified. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "BT control structure" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] cs_addr Address of the control structure in the exchange memory + **************************************************************************************** + */ +void dbg_trc_req_cs_bt(uint16_t const cs_addr); + +#define TRC_REQ_CS_BT(cs_addr) \ + dbg_trc_req_cs_bt(cs_addr); +#else /*(TRACER_PRESENT && TRC_CS_BT)*/ +#define TRC_REQ_CS_BT(cs_addr) +#endif /*(TRACER_PRESENT && TRC_CS_BT)*/ + +#if (TRACER_PRESENT && TRC_RX_DESC) +/** + **************************************************************************************** + * @brief Trace request API for processing of rx descriptors + * + * This function is called when a packet is received and a driver processes a rx descriptor. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "Rx descriptor" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] drv_type LLD driver (@see enum driver_type) + * @param[in] act_id Activity identifier + * @param[in] rx_desc_add Address of the rx descriptor in the exchange memory + **************************************************************************************** + */ +void dbg_trc_req_rx_desc(uint8_t const drv_type, uint8_t const act_id, uint16_t const rx_desc_add); + +#define TRC_REQ_RX_DESC(drv_type, act_id, rx_desc_add) \ + dbg_trc_req_rx_desc(drv_type, act_id, rx_desc_add); + +#else /*(TRACER_PRESENT && TRC_RX_DESC)*/ +#define TRC_REQ_RX_DESC(drv_type, act_id, rx_desc_add) +#endif /*(TRACER_PRESENT && TRC_RX_DESC) */ + +#if (TRACER_PRESENT && TRC_LLCP) +/** + **************************************************************************************** + * @brief Trace request API for llcp packets transmission, reception and acknowledgment + * + * This function is called when a llcp packet is transmitted, received or acknowledged. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "LLCP" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] llcp_trc_type Trace type for llcp (llcp tx, llcp rx and llcp ack of @see enum trace_types) + * @param[in] conhdl Connection handle + * @param[in] data_len Data length (in bytes) + * @param[in] pdu_data PDU Data + **************************************************************************************** + */ +void dbg_trc_req_llcp(uint8_t const llcp_trc_type, uint16_t const conhdl, uint8_t const data_len, uint8_t const *pdu_data); + +/// Macro used to send trace request API when an llcp packet is transmitted +#define TRC_REQ_LLCP_TX(conhdl, data_len, pdu_data) \ + dbg_trc_req_llcp(LLCP_TX, conhdl, data_len, pdu_data); + +/// Macro used to send trace request API when an llcp packet is received +#define TRC_REQ_LLCP_RX(conhdl, data_len, pdu_data) \ + dbg_trc_req_llcp(LLCP_RX, conhdl, data_len, pdu_data); + +/// Macro used to send trace request API when an llcp packet is acknowledged +#define TRC_REQ_LLCP_ACK(conhdl, data_len, pdu_data) \ + dbg_trc_req_llcp(LLCP_ACK, conhdl, data_len, pdu_data); +#else /*(TRACER_PRESENT && TRC_LLCP)*/ +#define TRC_REQ_LLCP_TX(conhdl, data_len, pdu_data) +#define TRC_REQ_LLCP_RX(conhdl, data_len, pdu_data) +#define TRC_REQ_LLCP_ACK(conhdl, data_len, pdu_data) +#endif /*(TRACER_PRESENT && TRC_LLCP) */ + +#if (TRACER_PRESENT && TRC_LMP) +/** + **************************************************************************************** + * @brief request API for lmp packets transmission, reception and acknowledgment + * + * This function is called when a lmp packet is transmitted, received or acknowledged. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "LMP" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] lmp_trc_type Trace type for lmp (lmp tx, lmp rx and lmp ack of @see enum trace_types) + * @param[in] conhdl Connection handle + * @param[in] data_len Data length (in bytes) + * @param[in] pdu_data PDU Data + **************************************************************************************** + */ +void dbg_trc_req_lmp(uint8_t const lmp_trc_type, uint16_t const conhdl, uint8_t const data_len, uint8_t const *pdu_data); + +/// Macro used to send trace request API when an lmp packet is transmitted +#define TRC_REQ_LMP_TX(conhdl, data_len, pdu_data) \ + dbg_trc_req_lmp(LMP_TX, conhdl, data_len, pdu_data); + +/// Macro used to send trace request API when an lmp packet is received +#define TRC_REQ_LMP_RX(conhdl, data_len, pdu_data) \ + dbg_trc_req_lmp(LMP_RX, conhdl, data_len, pdu_data); + +/// Macro used to send trace request API when an lmp packet is acknowledged +#define TRC_REQ_LMP_ACK(conhdl, data_len, pdu_data) \ + dbg_trc_req_lmp(LMP_ACK, conhdl, data_len, pdu_data); + +#else /*(TRACER_PRESENT && TRC_LMP)*/ +#define TRC_REQ_LMP_TX(conhdl, data_len, pdu_data) +#define TRC_REQ_LMP_RX(conhdl, data_len, pdu_data) +#define TRC_REQ_LMP_ACK(conhdl, data_len, pdu_data) +#endif /*(TRACER_PRESENT && TRC_LMP)*/ + +#if (TRACER_PRESENT && TRC_L2CAP) +/** + **************************************************************************************** + * @brief Trace request API for l2cap packets transmission and reception + * + * This function is called when a l2cap packet is transmitted or received. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "L2CAP" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] l2cap_trc_type Trace type for l2cap (l2cap tx and l2cap rx of @see enum trace_types) + * @param[in] conhdl Connection handle + * @param[in] data_len Data length (in bytes) + * @param[in] buf_ptr Memory pointer address + **************************************************************************************** + */ +void dbg_trc_req_l2cap(uint8_t const l2cap_trc_type, uint16_t const conhdl, uint16_t const data_len, uint32_t const buf_ptr); + +/// Macro used to send trace request API when an l2cap packet is transmitted +#define TRC_REQ_L2CAP_TX(conhdl, tx_len, buf_ptr) \ + dbg_trc_req_l2cap(L2CAP_TX, conhdl, tx_len, buf_ptr); + +/// Macro used to send trace request API when an l2cap packet is received +#define TRC_REQ_L2CAP_RX(conhdl, tx_len, buf_ptr) \ + dbg_trc_req_l2cap(L2CAP_RX, conhdl, tx_len, buf_ptr); + +/** + **************************************************************************************** + * @brief Trace request API for l2cap packet acknowledgment + * + * This function is called when l2cap packets are acknowledged. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "L2CAP" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] conhdl Connection handle + * @param[in] num_ack_pkts Number of acknowledged l2cap packets + **************************************************************************************** + */ +void dbg_trc_req_l2cap_ack(uint16_t const conhdl, uint16_t const num_ack_pkts); + +#define TRC_REQ_L2CAP_ACK(conhdl, num_ack_pkts) \ + dbg_trc_req_l2cap_ack(conhdl, num_ack_pkts); + +#else /*(TRACER_PRESENT && TRC_L2CAP)*/ +#define TRC_REQ_L2CAP_TX(conhdl, tx_len, buf_ptr) +#define TRC_REQ_L2CAP_RX(conhdl, tx_len, buf_ptr) +#define TRC_REQ_L2CAP_ACK(conhdl, num_ack_pkts) +#endif/*(TRACER_PRESENT && TRC_L2CAP) */ + +#if (TRACER_PRESENT && TRC_ARB) +/** + **************************************************************************************** + * @brief Trace request API for cancellation, removal and starting of events + * + * This function is called when an event starts, is removed or is cancelled. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "EA" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] sch_arb_trc_type Trace type for Scheduling Arbiter (cancel, remove and start of @see enum trace_types) + * @param[in] sch_arb_elt Pointer to the Scheduling Arbiter element + **************************************************************************************** + */ +void dbg_trc_req_sch_arb(uint8_t const sch_arb_trc_type, const struct sch_arb_elt_tag *sch_arb_elt); + +/// Macro used to send trace request API when an event is cancelled +#define TRC_REQ_SCH_ARB_CANC(sch_arb_elt) \ + dbg_trc_req_sch_arb(SCH_ARB_CANC, sch_arb_elt); + +/// Macro used to send trace request API when an event is removed +#define TRC_REQ_SCH_ARB_REM(sch_arb_elt) \ + dbg_trc_req_sch_arb(SCH_ARB_REM, sch_arb_elt); + +/// Macro used to send trace request API when an event starts +#define TRC_REQ_SCH_ARB_START(sch_arb_elt) \ + dbg_trc_req_sch_arb(SCH_ARB_START, sch_arb_elt); + +/** + **************************************************************************************** + * @brief Trace request API for shifting of events + * + * This function is called when an event is shifted. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "EA" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] sch_arb_elt Pointer to the Scheduling Arbiter element + **************************************************************************************** + */ +void dbg_trc_req_sch_arb_shift(const struct sch_arb_elt_tag *sch_arb_elt); + +#define TRC_REQ_SCH_ARB_SHIFT(sch_arb_elt) \ + dbg_trc_req_sch_arb_shift(sch_arb_elt); +/** + **************************************************************************************** + * @brief Trace request API for pushing of event in the waiting queue + * + * This function is called when an event is pushed in the waiting queue. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "EA" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] sch_arb_elt Pointer to the Scheduling Arbiter element + **************************************************************************************** + */ +void dbg_trc_req_sch_arb_insert(uint32_t const target_time, uint8_t const status, const struct sch_arb_elt_tag *sch_arb_elt); + +#define TRC_REQ_SCH_ARB_INSERT(target_time, status, sch_arb_elt) \ + dbg_trc_req_sch_arb_insert(target_time, status, sch_arb_elt); + +#else /*(TRACER_PRESENT && TRC_ARB)*/ +#define TRC_REQ_SCH_ARB_CANC(sch_arb_elt) +#define TRC_REQ_SCH_ARB_REM(sch_arb_elt) +#define TRC_REQ_SCH_ARB_START(sch_arb_elt) +#define TRC_REQ_SCH_ARB_SHIFT(sch_arb_elt) +#define TRC_REQ_SCH_ARB_INSERT(target_time, status, sch_arb_elt) +#endif /*(TRACER_PRESENT && TRC_ARB)*/ + +#if (TRACER_PRESENT && TRC_LC_STATE_TRANS) +/** + **************************************************************************************** + * @brief Trace request API for lc procedure state transition + * + * This function is called when an lc procedure changes its state. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "LC state transition" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] conhdl Connection handle + * @param[in] proc_type LC procedure + * @param[in] prev_state Previous procedure state + * @param[in] curr_state Current procedure state + **************************************************************************************** + */ +void dbg_trc_req_lc_state_trans(uint16_t const conhdl, uint8_t const proc_type, uint8_t const prev_state, uint8_t const curr_state); + +#define TRC_REQ_LC_STATE_TRANS(conhdl, proc_type, prev_state, curr_state) \ + dbg_trc_req_lc_state_trans(conhdl, proc_type, prev_state, curr_state); + +#else /*(TRACER_PRESENT && TRC_LC_STATE_TRANS)*/ +#define TRC_REQ_LC_STATE_TRANS(conhdl, proc_type, prev_state, curr_state) +#endif /*(TRACER_PRESENT && TRC_LC_STATE_TRANS)*/ + +#if (TRACER_PRESENT && TRC_LLC_STATE_TRANS) +/** + **************************************************************************************** + * @brief Trace request API for llc procedure state transition + * + * This function is called when an llcp procedure changes its state. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "LLC state transition" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] conhdl Connection handle + * @param[in] proc_type LLC procedure + * @param[in] prev_state Previous procedure state + * @param[in] curr_state Current procedure state + **************************************************************************************** + */ +void dbg_trc_req_llc_state_trans(uint16_t const conhdl, uint8_t const proc_type, uint8_t const prev_state, uint8_t const curr_state); + +#define TRC_REQ_LLC_STATE_TRANS(conhdl, proc_type, prev_state, curr_state) \ + dbg_trc_req_llc_state_trans(conhdl, proc_type, prev_state, curr_state); + +#else /*(TRACER_PRESENT && TRC_LLC_STATE_TRANS)*/ +#define TRC_REQ_LLC_STATE_TRANS(conhdl, proc_type, prev_state, curr_state) +#endif /*(TRACER_PRESENT && TRC_LLC_STATE_TRANS)*/ + +#if (TRACER_PRESENT && TRC_HCI) +/** + **************************************************************************************** + * @brief Trace request API for HCI messages (in FE mode) + * + * This function is called when a HCI command is received. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "HCI" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] opcode HCI opcode + * @param[in] par_len HCI parameter length + * @param[in] params unpacked HCI parameters + **************************************************************************************** + */ +void dbg_trc_req_hci_cmd(uint16_t const opcode, uint16_t const par_len, uint32_t const *params); + +/** + **************************************************************************************** + * @brief Trace request API for HCI messages (in FE mode) + * + * This function is called when a HCI event is sent. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "HCI" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] hci_evt_type Type of hci event (@see enum trace_types) + * @param[in] opcode HCI opcode + * @param[in] par_len HCI parameter length + * @param[in] params unpacked HCI parameters + **************************************************************************************** + */ +void dbg_trc_req_hci_evt(uint8_t const hci_evt_type, uint16_t const opcode, uint16_t const par_len, uint32_t const *params); + +/// Macro used to send trace request API when a HCI command is received +#define TRC_REQ_HCI_CMD(opcode, par_len, params) \ + dbg_trc_req_hci_cmd(opcode, par_len, params); + +/// Macro used to send trace request API when a HCI command status event is sent +#define TRC_REQ_HCI_CMD_STAT_EVT(opcode, par_len, params) \ + dbg_trc_req_hci_evt(HCI_CMD_STAT_EVT, opcode, par_len, params); + +/// Macro used to send trace request API when a HCI command complete event is sent +#define TRC_REQ_HCI_CMD_CMP_EVT(opcode, par_len, params) \ + dbg_trc_req_hci_evt(HCI_CMD_CMP_EVT, opcode, par_len, params); + +/// Macro used to send trace request API when a HCI event is sent +#define TRC_REQ_HCI_EVT(opcode, par_len, params) \ + dbg_trc_req_hci_evt(HCI_EVT, opcode, par_len, params); + +/// Macro used to send trace request API when a HCI LE event is sent +#define TRC_REQ_HCI_LE_EVT(opcode, par_len, params) \ + dbg_trc_req_hci_evt(HCI_LE_EVT, (uint16_t) opcode, par_len, params); + + +#else /*(TRACER_PRESENT && TRC_HCI)*/ +#define TRC_REQ_HCI_CMD(opcode, par_len, params) +#define TRC_REQ_HCI_CMD_STAT_EVT(opcode, par_len, params) +#define TRC_REQ_HCI_CMD_CMP_EVT(opcode, par_len, params) +#define TRC_REQ_HCI_EVT(opcode, par_len, params) +#define TRC_REQ_HCI_LE_EVT(opcode, par_len, params) +#endif /*(TRACER_PRESENT && TRC_HCI)*/ + +#if (TRACER_PRESENT && TRC_ADV) + +//struct trc_scan_req +//{ +// /// Scanner address type +// //@trc_ref addr_type +// uint8_t scan_addr_type; +// +// /// Scanner address +// struct bd_addr scan_addr; +// +// /// Scan request +// struct scan_req data; +//}; +// +//struct trc_connect_req +//{ +// /// Initiator address type +// //@trc_ref addr_type +// uint8_t init_addr_type; +// +// /// Initiator address +// struct bd_addr init_addr; +// +// /// Connect request +// struct connect_req data; +//}; +// +// @trc_ref ble_adv_type +// */ +//union trc_adv_rx_payload +//{ +// //@trc_union packet_type == BLE_CONNECT_IND +// struct trc_connect_req conn_req; +// +// //@trc_union packet_type == BLE_SCAN_REQ +// struct trc_scan_req scan_req; +//}; +// +//struct trc_adv_rx_pdu_hdr +//{ +// ///Packet type +// //@trc_ref ble_adv_type +// uint8_t packet_type; +// +// ///Channel used +// uint8_t used_channel; +//}; +// +//struct trc_adv_rx_pdu +//{ +// ///Header +// struct trc_adv_rx_pdu_hdr header; +// +// ///Payload +// union trc_adv_rx_payload payload; +//}; + +/*@TRACE*/ +struct trc_scan_rx_pdu +{ + ///Packet type + //@trc_ref ble_adv_type + uint8_t packet_type; + + ///Channel used + uint8_t used_channel; + + /// Scanner device address + struct bd_addr scanner_addr; + + /// Scanner address type + //@trc_ref addr_type + uint8_t scanner_addr_type; + + /// Data length in bytes + uint8_t data_len; + + /// Data + uint8_t data[__ARRAY_EMPTY]; +}; + + +/*@TRACE*/ +struct trc_init_rx_pdu +{ + ///Packet type + //@trc_ref ble_adv_type + uint8_t packet_type; + + ///Channel used + uint8_t used_channel; + + /// Advertiser device address + struct bd_addr adv_addr; + + /// Peer device address type + //@trc_ref addr_type + uint8_t adv_addr_type; +}; + + +/*@TRACE*/ +struct trc_adv_tx_pdu +{ + ///Packet type + //@trc_ref ble_adv_type + uint8_t packet_type; + + ///Advertising channel map + uint8_t advertising_channel_map; + + /// BD Address of the advertiser + struct bd_addr adv_addr; +}; + +/*@TRACE*/ +struct trc_init_tx_pdu +{ + ///Packet type + //@trc_ref ble_adv_type + uint8_t packet_type; + + ///Advertising channel map + uint8_t advertising_channel_map; + + /// Peer device address + struct bd_addr peer_id_addr; +}; + +void dbg_trc_req_init_rx_pdu(const uint8_t index_pkt, uint16_t rxdataptr); +void dbg_trc_req_init_tx_pdu(const uint8_t index_pkt, struct bd_addr const addr); +void dbg_trc_req_adv_rx_pdu(const uint8_t index_pkt, const uint8_t data_len, void const *data); +void dbg_trc_req_adv_tx_pdu(const uint8_t adv_txdesc_idx, const uint8_t cs_idx); +void dbg_trc_req_scan_rx_pdu(const uint8_t index_pkt, struct lld_adv_rep_ind const* ind); +void dbg_trc_req_scan_tx_pdu(const uint8_t txdesc_idx, const uint8_t cs_idx); + +#define TRC_REQ_INIT_RX_PDU(index_pkt, addr) \ + dbg_trc_req_init_rx_pdu(index_pkt, addr); +#define TRC_REQ_INIT_TX_PDU(index_pkt, addr) \ + dbg_trc_req_init_tx_pdu(index_pkt, addr); + +#define TRC_REQ_ADV_RX_PDU(index_pkt, data_len, data) \ + dbg_trc_req_adv_rx_pdu(index_pkt, data_len, data); +#define TRC_REQ_ADV_TX_PDU(adv_txdesc_idx, cs_idx) \ + dbg_trc_req_adv_tx_pdu(adv_txdesc_idx, cs_idx); + +#define TRC_REQ_SCAN_RX_PDU(pkt_type, ind) \ + dbg_trc_req_scan_rx_pdu(pkt_type, ind); +#define TRC_REQ_SCAN_TX_PDU(txdesc_idx, cs_idx) \ + dbg_trc_req_scan_tx_pdu(txdesc_idx, cs_idx); + +#else +#define TRC_REQ_INIT_RX_PDU(index_pkt, addr) +#define TRC_REQ_INIT_TX_PDU(txdesc_idx, cs_idx) +#define TRC_REQ_ADV_RX_PDU(index_pkt, addr, addr_type) +#define TRC_REQ_ADV_TX_PDU(adv_txdesc_idx, cs_idx) +#define TRC_REQ_SCAN_RX_PDU(pkt_type, ind) +#define TRC_REQ_SCAN_TX_PDU(txdesc_idx, cs_idx) +#endif /*(TRACER_PRESENT && TRC_ADV)*/ + +#if (TRACER_PRESENT && TRC_ACL) +/*@TRACE*/ +struct trc_acl_tx_pdu +{ + uint16_t txdataptr; + + ///Data length + uint16_t data_len; + + ///Data + uint8_t data[__ARRAY_EMPTY]; +}; + +/*@TRACE*/ +struct trc_acl_rx_pdu +{ + ///Data length + uint16_t data_len; + + ///Data + uint8_t data[__ARRAY_EMPTY]; +}; + +void dbg_trc_req_acl_rx_pdu(struct lld_acl_rx_ind const* msg); +void dbg_trc_req_acl_tx_pdu(const uint8_t trc_acl_tx_type, const uint8_t txdesc_idx); + +#define TRC_REQ_ACL_RX_PDU(msg) \ + dbg_trc_req_acl_rx_pdu(msg); + +#define TRC_REQ_ACL_ACK_TX_PDU(txdesc_idx) \ + dbg_trc_req_acl_tx_pdu(ACL_ACK_TX, txdesc_idx); + +#define TRC_REQ_ACL_PROG_TX_PDU(txdesc_idx) \ + dbg_trc_req_acl_tx_pdu(ACL_PROG_TX, txdesc_idx); + +#else +#define TRC_REQ_ACL_RX_PDU(msg) +#define TRC_REQ_ACL_PROG_TX_PDU(txdesc_idx) +#define TRC_REQ_ACL_ACK_TX_PDU(txdesc_idx) +#endif /*(TRACER_PRESENT && TRC_ACL)*/ + +#if (TRACER_PRESENT && TRC_CUSTOM) +/** + **************************************************************************************** + * @brief Trace request API for custom traces + * + * This function is called to send a custom trace. + * + * It checks the current tracer configuration and writes the trace in memory if the trace + * group "custom" (@see enum tracer_cfg_fields) is enabled. + * + * @param[in] trc_id Trace request identifier (progressive number that identifies the caller) + * @param[in] data_type Type of data (@see enum custom_trace_types) + * @param[in] data Pointer to the data to send + **************************************************************************************** + */ +void dbg_trc_req_custom(const uint8_t trc_id, const uint8_t data_type, void const *data); +#define TRC_REQ_CUSTOM(trc_id, data_type, data) \ + dbg_trc_req_custom(trc_id, data_type, data); +#else /*(TRACER_PRESENT && TRC_CUSTOM)*/ +#define TRC_REQ_CUSTOM(trc_id, data_type, data) +#endif /*(TRACER_PRESENT && TRC_CUSTOM)*/ + +#if (TRACER_PRESENT) +/** + **************************************************************************************** + * @brief Configuration received + * + * This function checks if the received configuration can be adopted and acknowledges it + * + **************************************************************************************** + */ +void dbg_trc_cfg_received(); + +/** + **************************************************************************************** + * @brief Get the reception buffer for configuration word + * + * @return Buffer for payload reception of tracer configuration packets + **************************************************************************************** + */ +uint8_t* dbg_trc_pay_buff_get(); +#endif /*(TRACER_PRESENT)*/ +///@} TRACER +#endif // DBG_TRC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_trc_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_trc_config.h new file mode 100644 index 0000000..9cf2f32 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_trc_config.h @@ -0,0 +1,237 @@ +/** + **************************************************************************************** + * + * @file dbg_trc_config.h + * + * @brief Configuration of the Tracer module + * + * Copyright (C) RivieraWaves 2009-2016 + * + **************************************************************************************** + */ + +#ifndef DBG_TRC_CONFIG_H_ +#define DBG_TRC_CONFIG_H_ + +/** + **************************************************************************************** + * @addtogroup TRACER + * @{ + * @name Tracer module configuration + * @{ + **************************************************************************************** + */ + +#if defined CFG_TRC_ALL +#define TRC_KE_MSG 1 +#define TRC_KE_TMR 1 +#define TRC_KE_EVT 1 +#define TRC_MEM 1 +#define TRC_SW_ASS 1 +#define TRC_CUSTOM 1 + +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +#define TRC_ARB 1 +#define TRC_PROG 1 +#define TRC_SLEEP 1 +#else // (BLE_EMB_PRESENT || BT_EMB_PRESENT) +#define TRC_ARB 0 +#define TRC_PROG 0 +#define TRC_SLEEP 0 +#endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + +#if (BLE_EMB_PRESENT) +#define TRC_CS_BLE 1 +#define TRC_LLCP 1 +#define TRC_LLC_STATE_TRANS 1 +#define TRC_RX_DESC 1 +#define TRC_ADV 1 +#define TRC_ACL 1 +#else /*(BLE_EMB_PRESENT)*/ +#define TRC_CS_BLE 0 +#define TRC_LLCP 0 +#define TRC_LLC_STATE_TRANS 0 +#define TRC_RX_DESC 0 +#define TRC_ADV 0 +#define TRC_ACL 0 +#endif /*(BLE_EMB_PRESENT)*/ + +#if (BLE_EMB_PRESENT && BLE_HOST_PRESENT) +#define TRC_HCI 1 +#else /*(BLE_EMB_PRESENT && BLE_HOST_PRESENT)*/ +#define TRC_HCI 0 +#endif /*(BLE_EMB_PRESENT && BLE_HOST_PRESENT)*/ + +#if (BLE_HOST_PRESENT) +#define TRC_L2CAP 1 +#else +#define TRC_L2CAP 0 +#endif /*(BLE_HOST_PRESENT)*/ + +#if (BT_EMB_PRESENT) +#define TRC_CS_BT 1 +#define TRC_LMP 1 +#define TRC_LC_STATE_TRANS 1 +#else +#define TRC_CS_BT 0 +#define TRC_LMP 0 +#define TRC_LC_STATE_TRANS 0 +#endif /*(BT_EMB_PRESENT)*/ + +#else /*(CFG_TRC_ALL)*/ + +#if defined CFG_TRC_KE_MSG +#define TRC_KE_MSG 1 +#else +#define TRC_KE_MSG 0 +#endif /*(CFG_TRC_KE_MSG)*/ + +#if defined CFG_TRC_KE_TMR +#define TRC_KE_TMR 1 +#else +#define TRC_KE_TMR 0 +#endif /*CFG_TRC_KE_TMR*/ + +#if defined CFG_TRC_KE_EVT +#define TRC_KE_EVT 1 +#else +#define TRC_KE_EVT 0 +#endif /*CFG_TRC_KE_EVT*/ + +#if defined CFG_TRC_MEM +#define TRC_MEM 1 +#else +#define TRC_MEM 0 +#endif /*CFG_TRC_MEM*/ + + +#if defined CFG_TRC_SW_ASS +#define TRC_SW_ASS 1 +#else +#define TRC_SW_ASS 0 +#endif /*CFG_TRC_SW_ASS*/ + +#if defined CFG_TRC_CUSTOM +#define TRC_CUSTOM 1 +#else +#define TRC_CUSTOM 0 +#endif /*CFG_TRC_CUSTOM*/ + +#if (BLE_EMB_PRESENT) +#if defined CFG_TRC_CS_BLE +#define TRC_CS_BLE 1 +#else +#define TRC_CS_BLE 0 +#endif /*(CFG_TRC_CS_BLE)*/ + +#if defined CFG_TRC_LLCP +#define TRC_LLCP 1 +#else +#define TRC_LLCP 0 +#endif /*(CFG_TRC_LLCP)*/ + +#if defined CFG_TRC_LLC_STATE_TRANS +#define TRC_LLC_STATE_TRANS 1 +#else +#define TRC_LLC_STATE_TRANS 0 +#endif /*(CFG_TRC_LLC_STATE_TRANS)*/ + +#if defined CFG_TRC_ARB +#define TRC_ARB 1 +#else +#define TRC_ARB 0 +#endif /*CFG_TRC_ARB*/ + +#if defined CFG_TRC_RX_DESC +#define TRC_RX_DESC 1 +#else +#define TRC_RX_DESC 0 +#endif /*CFG_TRC_RX_DESC*/ + +#if defined CFG_TRC_PROG +#define TRC_PROG 1 +#else +#define TRC_PROG 0 +#endif /*CFG_TRC_PROG*/ + +#if defined CFG_TRC_SLEEP +#define TRC_SLEEP 1 +#else +#define TRC_SLEEP 0 +#endif /*CFG_TRC_SLEEP*/ + +#if defined CFG_TRC_ADV +#define TRC_ADV 1 +#else +#define TRC_ADV 0 +#endif /*(CFG_TRC_ADV)*/ + +#if defined CFG_TRC_ACL +#define TRC_ACL 1 +#else +#define TRC_ACL 0 +#endif /*(CFG_TRC_ACL)*/ + +#else /*(BLE_EMB_PRESENT)*/ + +#define TRC_CS_BLE 0 +#define TRC_LLCP 0 +#define TRC_LLC_STATE_TRANS 0 +#define TRC_ARB 0 +#define TRC_RX_DESC 0 +#define TRC_PROG 0 +#define TRC_SLEEP 0 +#define TRC_ADV 0 +#define TRC_ACL 0 +#endif /*(BLE_EMB_PRESENT)*/ + +#if (BLE_EMB_PRESENT && BLE_HOST_PRESENT) +#if defined CFG_TRC_HCI +#define TRC_HCI 1 +#else +#define TRC_HCI 0 +#endif /*CFG_TRC_HCI*/ +#else /*(BLE_EMB_PRESENT && BLE_HOST_PRESENT)*/ +#define TRC_HCI 0 +#endif /*(BLE_EMB_PRESENT && BLE_HOST_PRESENT)*/ + +#if (BLE_HOST_PRESENT) +#if defined CFG_TRC_L2CAP +#define TRC_L2CAP 1 +#else +#define TRC_L2CAP 0 +#endif /*CFG_TRC_L2CAP*/ +#else /*BLE_HOST_PRESENT*/ +#define TRC_L2CAP 0 +#endif /*BLE_HOST_PRESENT*/ + +#if (BT_EMB_PRESENT) +#if defined CFG_TRC_CS_BT +#define TRC_CS_BT 1 +#else +#define TRC_CS_BT 0 +#endif /*CFG_TRC_CS_BT*/ + +#if defined CFG_TRC_LMP +#define TRC_LMP 1 +#else +#define TRC_LMP 0 +#endif /*CFG_TRC_LMP*/ + +#if defined CFG_TRC_LC_STATE_TRANS +#define TRC_LC_STATE_TRANS 1 +#else +#define TRC_LC_STATE_TRANS 0 +#endif /*CFG_TRC_LC_STATE_TRANS*/ + +#else /*BT_EMB_PRESENT*/ + +#define TRC_CS_BT 0 +#define TRC_LMP 0 +#define TRC_LC_STATE_TRANS 0 + +#endif /*BT_EMB_PRESENT*/ + +#endif /* CFG_TRC_ALL */ +/// @} TRACER +#endif /* DBG_TRC_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_trc_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_trc_int.h new file mode 100644 index 0000000..cf2f8e0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api/dbg_trc_int.h @@ -0,0 +1,159 @@ +/** + **************************************************************************************** + * + * @file dbg_trc_int.h + * + * @brief This file contains definitions related to the Tracer module. + * + * Copyright (C) RivieraWaves 2009-2015 + * + **************************************************************************************** + */ + +#ifndef DBG_TRC_INT_H_ +#define DBG_TRC_INT_H_ + +/** + **************************************************************************************** + * @addtogroup TRACER + * @{ + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (TRACER_PRESENT) +#include // standard definitions +#include // boolean + +/* + * DEFINES + **************************************************************************************** + */ + +///Channel index length +#define CHANNEL_ID_LEN 1 + +///lengths of trace packet fields +#define SEQ_NUM_LEN 2 +#define TIMESTAMP_LEN 4 +#define TRC_CODE_LEN 1 + +#define TRC_FIX_LEN \ + CHANNEL_ID_LEN +\ + TRC_MSG_HDR_LEN +\ + SEQ_NUM_LEN +\ + TIMESTAMP_LEN +\ + TRC_CODE_LEN + +/** + **************************************************************************************** + * @brief Convenient wrapper to trc_mem_alloc() + * + * This macro calls trc_mem_alloc() passing as parameter the length of the trace packet + * + * @param[in] trace_pay Trace payload length + * + * @return Pointer to trace code field(or NULL if the trace cannot be written) + **************************************************************************************** + */ +#define TRC_MEM_ALLOC(trace_pay) \ + dbg_trc_mem_alloc(TRC_FIX_LEN + trace_pay) + +typedef uint8_t trc_id_t; +typedef uint8_t trc_opcode_t; + +/* + * STRUCTURES DEFINITIONS + **************************************************************************************** + */ +///Tracer Environment context structure +struct dbg_trc_env_tag +{ + /// Current tracer configuration word + uint32_t curr_cw; + + /// Compiled tracer configuration word + uint32_t compiled_cw; +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **************************************************************************************** + */ +///Tracer environment context +extern struct dbg_trc_env_tag dbg_trc_env; + +/* + * TRANSPORT LAYER FUNCTION DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief initialize tracer TL + **************************************************************************************** + */ +void dbg_trc_tl_init(); + +/** + **************************************************************************************** + * @brief trigger the transmission of tracer packets + **************************************************************************************** + */ +void dbg_trc_tx_trigger(void); + +/* + * MEMORY FUNCTION DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief Initialize tracer memory + **************************************************************************************** + */ +void dbg_trc_mem_init(); + +/** + **************************************************************************************** + * @brief Try to write a trace in memory. + * @param[in] trace_len Trace packet length (expressed in bytes) + * + * @return Pointer to trace code field(or NULL if the trace cannot be written) + **************************************************************************************** + */ +uint8_t *dbg_trc_mem_alloc(uint16_t const trace_len); + +/** + **************************************************************************************** + * @brief Try to read a trace from the memory. + * + * @return Pointer to the total size of the trace (or NULL if the trace cannot be read) + **************************************************************************************** + */ +uint8_t *dbg_trc_mem_read(); + +/** + **************************************************************************************** + * @brief Deallocate a trace from the memory. + * + * This function marks the trace block pointed by the reading pointer as invalid and moves + * it to the next trace block + * + **************************************************************************************** + */ +void dbg_trc_mem_dealloc(); + +/** + **************************************************************************************** + * @brief Initialization of the tracer + * + * This function initializes the tracer + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void dbg_trc_init(uint8_t init_type); + +#endif /* TRACER_PRESENT */ +/// @} TRACER +#endif /* DBG_TRC_INT_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ecc_p256/api/ecc_p256.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ecc_p256/api/ecc_p256.h new file mode 100644 index 0000000..0b1cc61 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ecc_p256/api/ecc_p256.h @@ -0,0 +1,131 @@ +/** + **************************************************************************************** + * + * @file ecc_p256.h + * + * @brief ECC functions for P256 + * + * Copyright (C) RivieraWaves 2009-2015 + * + **************************************************************************************** + */ + +#ifndef ECC_P256_H_ +#define ECC_P256_H_ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" +#include +#include +#include "ke_task.h" + +/* + * DEFINES + **************************************************************************************** + */ + +#define ECC_PUBLICKEY_GENERATION 0x01 +#define ECC_DHKEY_GENERATION 0x02 + + +/* + * STRUCTURE DEFINITIONS + **************************************************************************************** + */ + +/// Multiplication result message structure +/*@TRACE*/ +struct ecc_result_ind +{ + uint8_t key_res_x[32]; + uint8_t key_res_y[32]; +}; + + +/* + * VARIABLE DECLARATION + **************************************************************************************** + */ + +/// Debug Private Key +extern const uint8_t DebugE256SecretKey[32]; + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initialize Elliptic Curve algorithm + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + **************************************************************************************** + */ +void ecc_init(uint8_t init_type); + +/** + **************************************************************************************** + * @brief Generate a Secret Key compliant with ECC P256 algorithm + * + * If key is forced, just check its validity + * + * @param[out] secret_key Private key - MSB First + * @param[in] forced True if provided key is forced, else generate it. + **************************************************************************************** + */ +void ecc_gen_new_secret_key(uint8_t* secret_key, bool forced); + +/** + **************************************************************************************** + * @brief Generate a new Public key pair using ECC P256 algorithm + * + * @param[in] secret_key Private key - MSB First + * @param[in] blocking Force to run full algorithm without continue mode + **************************************************************************************** + */ +void ecc_gen_new_public_key(uint8_t* secret_key256, ke_msg_id_t msg_id, ke_task_id_t task_id); + +/** + **************************************************************************************** + * @brief Generate a new DHKey using ECC P256 algorithm + * + * @param[in] key_type Type of key to generate (1: public key | 2: DH key) + * @param[in] secret_key Private key - MSB First + * @param[in] pub_key_x Peer public key x coordinate - LSB First + * @param[in] pub_key_y Peer public key y coordinate - LSB First + * @param[in] msg_id Message task ID for the result indication + * @param[in] task_id Client task ID (Task type + instance) + * + * @return status 0 if key generation is started, > 0 otherwise + **************************************************************************************** + */ +uint8_t ecc_generate_key256(uint8_t key_type, const uint8_t* secret_key, const uint8_t* public_key_x, const uint8_t* public_key_y, ke_msg_id_t msg_id, ke_task_id_t task_id); + +/** + **************************************************************************************** + * @brief Abort a current DHKey generation procedure + * + * @param[in] task_id Client task ID (Task type + instance) + **************************************************************************************** + */ +void ecc_abort_key256_generation(ke_task_id_t task_id); + +/** + **************************************************************************************** + * @brief Retrieve debug private and public keys + * + * @param[out] secret_key Private key - MSB First + * @param[out] pub_key_x Public key x coordinate - LSB First + * @param[out] pub_key_y Public key y coordinate - LSB First + **************************************************************************************** + */ +void ecc_get_debug_Keys(uint8_t*secret_key, uint8_t* pub_key_x, uint8_t* pub_key_y); + + +#endif /* ECC_P256_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/h4tl/api/h4tl.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/h4tl/api/h4tl.h new file mode 100644 index 0000000..100df26 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/h4tl/api/h4tl.h @@ -0,0 +1,229 @@ +/** + **************************************************************************************** + * + * @file h4tl.h + * + * @brief H4 UART Transport Layer header file. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef H4TL_H_ +#define H4TL_H_ + +/** + **************************************************************************************** + * @addtogroup H4TL H4 UART Transport Layer + * @ingroup H4TL + * @brief H4 UART Transport Layer + * + * This module creates the abstraction between External UART driver and HCI generic functions + * (designed for H4 UART transport layer). + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // stack configuration + +#if (H4TL_SUPPORT) +#include "rwip.h" // SW interface + +#include // standard integer definition +#include // standard boolean definition +#include "ahi.h" + + +/// Size of the RX Buffer that can both receive the header and valid packet to exit from out of sync mode +#if (AHI_TL_SUPPORT) +#define RX_TMP_BUFF_SIZE AHI_RESET_MSG_LEN +#elif (HCI_TL_SUPPORT) +#define RX_TMP_BUFF_SIZE HCI_RESET_MSG_LEN +#endif // (AHI_TL_SUPPORT) or (HCI_TL_SUPPORT) + + +///H4TL RX states +enum H4TL_STATE_RX +{ + ///H4TL RX Start State - receive message type + H4TL_STATE_RX_START, + ///H4TL RX Header State - receive message header + H4TL_STATE_RX_HDR, + ///H4TL RX Header State - receive (rest of) message payload + H4TL_STATE_RX_PAYL, + ///H4TL RX Out Of Sync state - receive message type + H4TL_STATE_RX_OUT_OF_SYNC +}; + + + +///H4TL queue type +enum H4TL_QUEUE +{ + /// HCI/AHI Tx Queue + H4TL_TX_QUEUE_MSG, + +#if (BLE_ISOOHCI) + /// ISO Tx Queue + H4TL_TX_QUEUE_ISO, +#endif // (BLE_ISOOHCI) + +#if (TRACER_PRESENT) + /// Tracer Message Queue + H4TL_TX_QUEUE_TRACER, +#endif // (TRACER_PRESENT) + + /// Maximum number of TX queue + H4TL_TX_QUEUE_MAX, + + /// Queue in Idle mode + H4TL_TX_QUEUE_IDLE = 0xFF, +}; +/* + * STRUCTURES DEFINITION + **************************************************************************************** + */ + +/// Information about message under transmission +struct h4tl_tx_info +{ + /// message buffer + uint8_t* buf; + /// Tx callback + void (*callback)(void); + /// buffer length + uint16_t buf_len; + /// Priority + uint8_t prio; +}; + + +/// H4TL Environment context structure +struct h4tl_env_tag +{ + /// pointer to External interface api + + const struct rwip_eif_api* ext_if; + ///Pointer to space reserved for received payload. + uint8_t* curr_payl_buff; + /// Ensure that array is 32bits aligned + /// Latest received message header, or used to receive a message allowing to exit from out of sync + uint8_t rx_buf[RX_TMP_BUFF_SIZE]; + + ///Rx state - can be receiving message type, header, payload or error + uint8_t rx_state; + ///Latest received message type: CMD/EVT/ACL. + uint8_t rx_type; + /// Transport layer interface + uint8_t tl_itf; + + /// Maximum Tx queue + struct h4tl_tx_info tx_queue[H4TL_TX_QUEUE_MAX]; + + /// Information about on-going transmission + uint8_t tx_active_queue; +}; +/* + * DEFINES + **************************************************************************************** + */ + +/// Size of the logical channel identifier for H4 messages +#define H4TL_LOGICAL_CHANNEL_LEN (1) + +/** + * Number of H4TL interfaces + * + * * NB=2: AHI and HCI: for Host-only stack with external app + * - HCI has index 0 + * - AHI has index 1 + * * NB=1: AHI or HCI: for all other partitions + * + * Note: it is not possible to have no channel (H4TL must not be included in build in this case) + */ +#if (!BLE_EMB_PRESENT && HCI_TL_SUPPORT && AHI_TL_SUPPORT) +#define H4TL_NB_CHANNEL 2 +#else // (!BLE_EMB_PRESENT && HCI_TL_SUPPORT && AHI_TL_SUPPORT) +#define H4TL_NB_CHANNEL 1 +#endif // (!BLE_EMB_PRESENT && HCI_TL_SUPPORT && AHI_TL_SUPPORT) + + +/* + * GLOBAL VARIABLE DECLARATIONS + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ +/** + **************************************************************************************** + * @brief H4TL transport initialization. + * + * Puts the External Interface driver in reception, waiting for simple 1 byte message type. Space for + * reception is allocated with ke_msg_alloc and the pointer is handed to env.rx. RX + * interrupt is enabled. + * + * @param[in] tl_type Transport Layer Interface (@see enum h4tl_itf) + * @param[in] eif External interface API + * + ***************************************************************************************** + */ +void h4tl_init(uint8_t tl_type, const struct rwip_eif_api* eif); + +static void h4tl_read_start(struct h4tl_env_tag* env); +/** + **************************************************************************************** + * @brief H4TL write function. + * + * @param[in] type Type of the buffer to be transmitted. It can take one of the following + * values: + * - @ref HCI_EVT_MSG_TYPE for event message + * - @ref HCI_ACL_MSG_TYPE for ACL data + * - @ref HCI_SYNC_MSG_TYPE for synchronous data + * + * @param[in] buf Pointer to the buffer to be transmitted. @note The buffer passed as + * parameter must have one free byte before the first payload byte, so that the H4TL + * module can put the type byte as first transmitted data. + * + * @param[in] len Length of the buffer to be transmitted. + * @param[in] tx_callback Callback for indicating the end of transfer + ***************************************************************************************** + */ +void h4tl_write(uint8_t type, uint8_t *buf, uint16_t len, void (*tx_callback)(void)); + +/** + **************************************************************************************** + * @brief Start External Interface input flow + * + ***************************************************************************************** + */ +void h4tl_start(void); + +/** + **************************************************************************************** + * @brief Stop External Interface input flow if possible + * + * @return true if External Interface flow was stopped, false otherwise + ***************************************************************************************** + */ +//bool h4tl_stop(void); + +void h4tl_read_start_next(void); + +#endif //H4TL_SUPPORT + +/// @} H4TL + +#endif // H4TL_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke.h new file mode 100644 index 0000000..5f6c115 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke.h @@ -0,0 +1,103 @@ +/** + **************************************************************************************** + * + * @file ke.h + * + * @brief This file contains the definition of the kernel environment. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _KE_H_ +#define _KE_H_ + +/** + **************************************************************************************** + * @addtogroup ENV Environment + * @ingroup KERNEL + * @brief Kernel Environment + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // stack configuration + +#include // standard boolean definitions +#include // standard integer definitions + +/* + * ENUMERATION + **************************************************************************************** + */ + +/// Kernel Error Status +enum KE_STATUS +{ + KE_SUCCESS = 0, + KE_FAIL +}; + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief This function performs all the initializations of the kernel. + * + * It initializes first the heap, then the message queues and the events. Then if required + * it initializes the trace. + * + **************************************************************************************** + */ +void ke_init(void); + +/** + **************************************************************************************** + * @brief This function flushes all messages, timers and events currently pending in the + * kernel. + * + **************************************************************************************** + */ +void ke_flush(void); + +/** + **************************************************************************************** + * @brief This function checks if sleep is possible or kernel is processing + * + * @return True if sleep is allowed, false otherwise + **************************************************************************************** + */ +bool ke_sleep_check(void); + +#if (KE_PROFILING) +/** + **************************************************************************************** + * @brief This function gets the statistics of the kernel usage. + * + * @param[out] max_msg_sent Max message sent + * @param[out] max_msg_saved Max message saved + * @param[out] max_timer_used Max timer used + * @param[out] max_heap_used Max heap used + **************************************************************************************** + */ +enum KE_STATUS ke_stats_get(uint8_t* max_msg_sent, + uint8_t* max_msg_saved, + uint8_t* max_timer_used, + uint16_t* max_heap_used); +#endif //KE_PROFILING + +/// @} KE + +#endif // _KE_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_env.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_env.h new file mode 100644 index 0000000..02c5412 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_env.h @@ -0,0 +1,66 @@ +/** + **************************************************************************************** + * + * @file ke_env.h + * + * @brief This file contains the definition of the kernel. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _KE_ENV_H_ +#define _KE_ENV_H_ + +/** + **************************************************************************************** + * @addtogroup ENV Environment + * @ingroup KERNEL + * @brief Kernel Environment + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" // stack configuration +#include "ke_event.h" // kernel event +#include "co_list.h" // kernel queue definition + +// forward declaration +struct mblock_free; + +/// Kernel environment definition +struct ke_env_tag +{ + /// Queue of sent messages but not yet delivered to receiver + struct co_list queue_sent; + /// Queue of messages delivered but not consumed by receiver + struct co_list queue_saved; + /// Queue of timers + struct co_list queue_timer; + + /// Root pointer = pointer to first element of heap linked lists + struct mblock_free * heap[KE_MEM_BLOCK_MAX]; + /// Size of heaps + uint16_t heap_size[KE_MEM_BLOCK_MAX]; + + #if (KE_PROFILING) + /// Size of heap used + uint16_t heap_used[KE_MEM_BLOCK_MAX]; + /// Maximum heap memory used + uint32_t max_heap_used; + #endif //KE_PROFILING +}; + +/// Kernel environment +extern struct ke_env_tag ke_env; + +/// @} ENV + +#endif // _KE_ENV_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_event.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_event.h new file mode 100644 index 0000000..dca64f3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_event.h @@ -0,0 +1,152 @@ +/** + **************************************************************************************** + * + * @file ke_event.h + * + * @brief This file contains the definition related to kernel events. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _KE_EVENT_H_ +#define _KE_EVENT_H_ + +/** + **************************************************************************************** + * @addtogroup EVT Events and Schedule + * @ingroup KERNEL + * @brief Event scheduling module. + * + * The KE_EVT module implements event scheduling functions. It can be used to + * implement deferred actions. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" // stack configuration + +#include // standard integer definition + + +/* + * CONSTANTS + **************************************************************************************** + */ + + +/// Status of ke_task API functions +enum KE_EVENT_STATUS +{ + KE_EVENT_OK = 0, + KE_EVENT_FAIL, + KE_EVENT_UNKNOWN, + KE_EVENT_CAPA_EXCEEDED, + KE_EVENT_ALREADY_EXISTS, +}; + + +/* + * TYPE DEFINITION + **************************************************************************************** + */ + + + + +/* + * FUNCTION PROTOTYPES + **************************************************************************************** + */ + + + +/** + **************************************************************************************** + * @brief Initialize Kernel event module. + **************************************************************************************** + */ +void ke_event_init(void); + +/** + **************************************************************************************** + * @brief Register an event callback. + * + * @param[in] event_type Event type. + * @param[in] p_callback Pointer to callback function. + * + * @return Status + **************************************************************************************** + */ +uint8_t ke_event_callback_set(uint8_t event_type, void (*p_callback)(void)); + +/** + **************************************************************************************** + * @brief Set an event + * + * This primitive sets one event. It will trigger the call to the corresponding event + * handler in the next scheduling call. + * + * @param[in] event_type Event to be set. + **************************************************************************************** + */ +void ke_event_set(uint8_t event_type); + +/** + **************************************************************************************** + * @brief Clear an event + * + * @param[in] event_type Event to be cleared. + **************************************************************************************** + */ +void ke_event_clear(uint8_t event_type); + +/** + **************************************************************************************** + * @brief Get the status of an event + * + * @param[in] event_type Event to get. + * + * @return Event status (0: not set / 1: set) + **************************************************************************************** + */ +uint8_t ke_event_get(uint8_t event_type); + +/** + **************************************************************************************** + * @brief Get all event status + * + * @return Events bit field + **************************************************************************************** + */ +uint32_t ke_event_get_all(void); + +/** + **************************************************************************************** + * @brief Flush all pending events. + **************************************************************************************** + */ +void ke_event_flush(void); + +/** + **************************************************************************************** + * @brief Event scheduler entry point. + * + * This primitive is the entry point of Kernel event scheduling. + **************************************************************************************** + */ +void ke_event_schedule(void); + + + +/// @} EVT + +#endif //_KE_EVENT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_mem.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_mem.h new file mode 100644 index 0000000..e399508 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_mem.h @@ -0,0 +1,153 @@ +/** + **************************************************************************************** + * + * @file ke_mem.h + * + * @brief API for the heap management module. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _KE_MEM_H_ +#define _KE_MEM_H_ + +#include "rwip_config.h" // IP configuration +#include // standard integer +#include // standard includes + +/** + **************************************************************************************** + * @defgroup MEM Memory + * @ingroup KERNEL + * @brief Heap management module. + * + * This module implements heap management functions that allow initializing heap, + * allocating and freeing memory. + * + * @{ + **************************************************************************************** + */ + +// forward declarations +struct mblock_free; + +/** + **************************************************************************************** + * @brief Heap initialization. + * + * This function performs the following operations: + * - sanity checks + * - check memory allocated is at least large enough to hold two block descriptors to hold + * start and end + * - initialize the first and last descriptors + * - save heap into kernel environment variable. + * + * @param[in] type Memory type. + * @param[in|out] heap Heap pointer + * @param[in] heap_size Size of the heap + * + * + **************************************************************************************** + */ +void ke_mem_init(uint8_t type, uint8_t* heap, uint16_t heap_size); + +/** + **************************************************************************************** + * @brief Allocation of a block of memory. + * + * Allocates a memory block whose size is size; if no memory is available return NULL + * + * @param[in] size Size of the memory area that need to be allocated. + * @param[in] type Type of memory block + * + * @return A pointer to the allocated memory area. + * + **************************************************************************************** + */ +void *ke_malloc(uint32_t size, uint8_t type); + + +/** + **************************************************************************************** + * @brief Check if it's possible to allocate a block of memory with a specific size. + * + * @param[in] size Size of the memory area that need to be allocated. + * @param[in] type Type of memory block + * + * @return True if memory block can be allocated, False else. + * + **************************************************************************************** + */ +bool ke_check_malloc(uint32_t size, uint8_t type); + +/** + **************************************************************************************** + * @brief Freeing of a block of memory. + * + * Free the memory area pointed by mem_ptr : mark the block as free and insert it in + * the pool of free block. + * + * @param[in] mem_ptr Pointer to the memory area that need to be freed. + * + **************************************************************************************** + */ +void ke_free(void *mem_ptr); + + +/** + **************************************************************************************** + * @brief Check if current heap is empty or not (not used) + * + * @param[in] type Type of memory heap block + * + * @return true if heap not used, false else. + **************************************************************************************** + */ +bool ke_mem_is_empty(uint8_t type); + + + +/** + **************************************************************************************** + * @brief Check if current pointer is free or not + * + * @param[in] mem_ptr pointer to a memory block + * + * @return true if already free, false else. + **************************************************************************************** + */ +bool ke_is_free(void* mem_ptr); + +#if (KE_PROFILING) + +/** + **************************************************************************************** + * @brief Retrieve memory usage of selected heap. + * + * @param[in] type Type of memory heap block + * + * @return current memory usage of current heap. + **************************************************************************************** + */ +uint16_t ke_get_mem_usage(uint8_t type); + + +/** + **************************************************************************************** + * @brief Retrieve max memory usage of all heap. + * This command also resets max measured value. + * + * @return max memory usage of all heap. + **************************************************************************************** + */ +uint32_t ke_get_max_mem_usage(void); + +#endif // (KE_PROFILING) + +///@} MEM + +#endif // _KE_MEM_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_msg.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_msg.h new file mode 100644 index 0000000..a2802c0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_msg.h @@ -0,0 +1,320 @@ +/** + **************************************************************************************** + * + * @file ke_msg.h + * + * @brief This file contains the definition related to message scheduling. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _KE_MSG_H_ +#define _KE_MSG_H_ + +/** + **************************************************************************************** + * @defgroup MSG Message Exchange + * @ingroup KERNEL + * @brief Message scheduling module. + * + * The MSG module implements message scheduling functions. + + * A kernel message has an ID, a receiver task ID and a source task ID. + * In most cases, it also has parameters which are defined in + * a structure dynamically embedded in the message structure, + * so the whole message will be managed internally as one block. + * + * A message can also have one extra parameter which is referenced + * in the normal parameter structure. This extra block is assumed + * to be large by the kernel and will be moved by DMA if needed. + * This feature allows moving MMPDU from LMAC to UMAC. + * + * In order to send a message, a function first have to allocate + * the memory for this message. It can be done with the wrapper + * macro KE_MSG_ALLOC() (which will call ke_msg_alloc()). + + * The message can then be sent with ke_msg_send(). The kernel + * will take care of freeing the allocated memory. + + * If the message has no parameters, the ke_msg_send_basic() function + * can be used. + * + * @{ + **************************************************************************************** + */ + +#include // standard definition +#include // standard integer +#include // standard boolean +#include "arch.h" // architectural definition +#include "compiler.h" // compiler definition +#include "co_list.h" // list definition + +/// Task Identifier. Composed by the task type and the task index. +typedef uint16_t ke_task_id_t; + +/// Builds the task identifier from the type and the index of that task. +#define KE_BUILD_ID(type, index) ( (ke_task_id_t)(((index) << 8)|(type)) ) + +/// Retrieves task type from task id. +#define KE_TYPE_GET(ke_task_id) ((ke_task_id) & 0xFF) + +/// Retrieves task index number from task id. +#define KE_IDX_GET(ke_task_id) (((ke_task_id) >> 8) & 0xFF) + +/// Task State +typedef uint8_t ke_state_t; + +/// Message Identifier. The number of messages is limited to 0xFFFF. +/// The message ID is divided in two parts: +/// bits[15~8]: task index (no more than 255 tasks support) +/// bits[7~0]: message index(no more than 255 messages per task) +/*@TRACE*/ +typedef uint16_t ke_msg_id_t; + +/// Message structure. +struct ke_msg +{ + struct co_list_hdr hdr; ///< List header for chaining + + ke_msg_id_t id; ///< Message id. + ke_task_id_t dest_id; ///< Destination kernel identifier. + ke_task_id_t src_id; ///< Source kernel identifier. + uint16_t param_len; ///< Parameter embedded struct length. + uint32_t param[__ARRAY_EMPTY]; ///< Parameter embedded struct. Must be word-aligned. +}; + + +/// Status returned by a task when handling a message +/*@TRACE*/ +enum ke_msg_status_tag +{ + KE_MSG_CONSUMED = 0, ///< consumed, msg and ext are freed by the kernel + KE_MSG_NO_FREE, ///< consumed, nothing is freed by the kernel + KE_MSG_SAVED, ///< not consumed, will be pushed in the saved queue +}; + +/** + **************************************************************************************** + * @brief Convert a parameter pointer to a message pointer + * + * @param[in] param_ptr Pointer to the parameter member of a ke_msg + * Usually retrieved by a ke_msg_alloc() + * + * @return The pointer to the ke_msg + **************************************************************************************** + */ +__INLINE struct ke_msg * ke_param2msg(void const *param_ptr) +{ + return (struct ke_msg*) (((uint8_t*)param_ptr) - offsetof(struct ke_msg, param)); +} + +/** + **************************************************************************************** + * @brief Convert a message pointer to a parameter pointer + * + * @param[in] msg Pointer to the ke_msg. + * + * @return The pointer to the param member + **************************************************************************************** + */ +__INLINE void * ke_msg2param(struct ke_msg const *msg) +{ + return (void*) (((uint8_t*) msg) + offsetof(struct ke_msg, param)); +} + +/** + **************************************************************************************** + * @brief Convenient wrapper to ke_msg_alloc() + * + * This macro calls ke_msg_alloc() and cast the returned pointer to the + * appropriate structure. Can only be used if a parameter structure exists + * for this message (otherwise, use ke_msg_send_basic()). + * + * @param[in] id Message identifier + * @param[in] dest Destination Identifier + * @param[in] src Source Identifier + * @param[in] param_str parameter structure tag + * + * @return Pointer to the parameter member of the ke_msg. + **************************************************************************************** + */ +#define KE_MSG_ALLOC(id, dest, src, param_str) \ + (struct param_str*) ke_msg_alloc(id, dest, src, sizeof(struct param_str)) + +/** + **************************************************************************************** + * @brief Convenient wrapper to ke_msg_free() + * + * This macro calls ke_msg_free() with the appropriate msg pointer as parameter, according + * to the message parameter pointer passed. + * + * @param[in] param_ptr parameter structure pointer + **************************************************************************************** + */ +#define KE_MSG_FREE(param_ptr) ke_msg_free(ke_param2msg((param_ptr))) + +/** + **************************************************************************************** + * @brief Convenient wrapper to ke_msg_alloc() + * + * This macro calls ke_msg_alloc() and cast the returned pointer to the + * appropriate structure with a variable length. Can only be used if a parameter structure exists + * for this message (otherwise, use ke_msg_send_basic()).Can only be used if the data array is + * located at the end of the structure. + * + * @param[in] id Message identifier + * @param[in] dest Destination Identifier + * @param[in] src Source Identifier + * @param[in] param_str parameter structure tag + * @param[in] length length for the data + * + * @return Pointer to the parameter member of the ke_msg. + **************************************************************************************** + */ +#define KE_MSG_ALLOC_DYN(id, dest, src, param_str,length) (struct param_str*)ke_msg_alloc(id, dest, src, \ + (sizeof(struct param_str) + (length))); + +/** + **************************************************************************************** + * @brief Allocate memory for a message + * + * This primitive allocates memory for a message that has to be sent. The memory + * is allocated dynamically on the heap and the length of the variable parameter + * structure has to be provided in order to allocate the correct size. + * + * Several additional parameters are provided which will be preset in the message + * and which may be used internally to choose the kind of memory to allocate. + * + * The memory allocated will be automatically freed by the kernel, after the + * pointer has been sent to ke_msg_send(). If the message is not sent, it must + * be freed explicitly with ke_msg_free(). + * + * Allocation failure is considered critical and should not happen. + * + * @param[in] id Message identifier + * @param[in] dest_id Destination Task Identifier + * @param[in] src_id Source Task Identifier + * @param[in] param_len Size of the message parameters to be allocated + * + * @return Pointer to the parameter member of the ke_msg. If the parameter + * structure is empty, the pointer will point to the end of the message + * and should not be used (except to retrieve the message pointer or to + * send the message) + **************************************************************************************** + */ +void *ke_msg_alloc(ke_msg_id_t const id, ke_task_id_t const dest_id, + ke_task_id_t const src_id, uint16_t const param_len); + +/** + **************************************************************************************** + * @brief Message sending. + * + * Send a message previously allocated with any ke_msg_alloc()-like functions. + * + * The kernel will take care of freeing the message memory. + * + * Once the function have been called, it is not possible to access its data + * anymore as the kernel may have copied the message and freed the original + * memory. + * + * @param[in] param_ptr Pointer to the parameter member of the message that + * should be sent. + **************************************************************************************** + */ + +void ke_msg_send(void const *param_ptr); + +/** + **************************************************************************************** + * @brief Basic message sending. + * + * Send a message that has a zero length parameter member. No allocation is + * required as it will be done internally. + * + * @param[in] id Message identifier + * @param[in] dest_id Destination Identifier + * @param[in] src_id Source Identifier + **************************************************************************************** + */ +void ke_msg_send_basic(ke_msg_id_t const id, ke_task_id_t const dest_id, ke_task_id_t const src_id); + +/** + **************************************************************************************** + * @brief Message forwarding. + * + * Forward a message to another task by changing its destination and source tasks IDs. + * + * @param[in] param_ptr Pointer to the parameter member of the message that + * should be sent. + * @param[in] dest_id New destination task of the message. + * @param[in] src_id New source task of the message. + **************************************************************************************** + */ +void ke_msg_forward(void const *param_ptr, ke_task_id_t const dest_id, ke_task_id_t const src_id); + +/** + **************************************************************************************** + * @brief Message forwarding. + * + * Forward a message to another task by changing its message ID and its destination and source tasks IDs. + * + * @param[in] param_ptr Pointer to the parameter member of the message that + * should be sent. + * @param[in] msg_id New ID of the message. + * @param[in] dest_id New destination task of the message. + * @param[in] src_id New source task of the message. + **************************************************************************************** + */ +void ke_msg_forward_new_id(void const *param_ptr, + ke_msg_id_t const msg_id, ke_task_id_t const dest_id, ke_task_id_t const src_id); + +/** + **************************************************************************************** + * @brief Free allocated message + * + * @param[in] msg Pointer to the message to be freed (not the parameter member!) + **************************************************************************************** + */ +void ke_msg_free(struct ke_msg const *param); + + + +/** + **************************************************************************************** + * @brief Retrieve destination task identifier of a kernel message + * + * @param[in] param_ptr Pointer to the parameter member of the message. + * + * @return message destination task + **************************************************************************************** + */ +ke_msg_id_t ke_msg_dest_id_get(void const *param_ptr); + + + +/** + **************************************************************************************** + * @brief Retrieve source task identifier of a kernel message + * + * @param[in] param_ptr Pointer to the parameter member of the message. + * + * @return message source task + **************************************************************************************** + */ +ke_msg_id_t ke_msg_src_id_get(void const *param_ptr); + +/** + * Used to know if message is present in kernel queue or not. + * + * @param[in] param_ptr Pointer to the parameter member of the message. + * + * @return True if message is present in Kernel Queue, False else. + */ +bool ke_msg_in_queue(void const *param_ptr); +/// @} MSG + +#endif // _KE_MSG_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_queue.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_queue.h new file mode 100644 index 0000000..f899f5c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_queue.h @@ -0,0 +1,107 @@ +/** + **************************************************************************************** + * + * @file ke_queue.h + * + * @brief This file contains the definition of the message object, queue element + * object and queue object + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _KE_QUEUE_H_ +#define _KE_QUEUE_H_ + +/** + **************************************************************************************** + * @addtogroup QUEUE Queues and Lists + * @ingroup KERNEL + * @brief Queue management module + * + * This module implements the functions used for managing message queues. + * These functions must not be called under IRQ! + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include // standard integer +#include // standard boolean +#include "compiler.h" // compiler definitions +#include "co_list.h" // list definition + +/* + * FUNCTION PROTOTYPES + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Pop entry to the queue + * + * @param[in] queue Pointer to the queue. + * @param[in] element Pointer to the element. + **************************************************************************************** + */ +__INLINE void ke_queue_push(struct co_list *const queue, struct co_list_hdr *const element) +{ + co_list_push_back(queue, element); +} + +/** + **************************************************************************************** + * @brief Pop entry from the queue + * + * @param[in] queue Pointer to the queue. + * + * @return Pointer to the element. + **************************************************************************************** + */ +__INLINE struct co_list_hdr *ke_queue_pop(struct co_list *const queue) +{ + return co_list_pop_front(queue); +} + +/** + **************************************************************************************** + * @brief Extracts an element matching a given algorithm. + * + * @param[in] queue Pointer to the queue. + * @param[in] func Matching function. + * @param[in] arg Match argument. + * + * @return Pointer to the element found and removed (NULL otherwise). + **************************************************************************************** + */ +struct co_list_hdr *ke_queue_extract(struct co_list * const queue, + bool (*func)(struct co_list_hdr const * elmt, uint32_t arg), + uint32_t arg); + +/** + **************************************************************************************** + * @brief Insert an element in a sorted queue. + * + * This primitive use a comparison function from the parameter list to select where the + * element must be inserted. + * + * @param[in] queue Pointer to the queue. + * @param[in] element Pointer to the element to insert. + * @param[in] cmp Comparison function (return true if first element has to be inserted + * before the second one). + * + * @return Pointer to the element found and removed (NULL otherwise). + **************************************************************************************** + */ +void ke_queue_insert(struct co_list * const queue, struct co_list_hdr * const element, + bool (*cmp)(struct co_list_hdr const *elementA, + struct co_list_hdr const *elementB)); + +/// @} QUEUE + +#endif // _KE_QUEUE_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_task.h new file mode 100644 index 0000000..42b101a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_task.h @@ -0,0 +1,221 @@ +/** + **************************************************************************************** + * + * @file ke_task.h + * + * @brief This file contains the definition related to kernel task management. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _KE_TASK_H_ +#define _KE_TASK_H_ + +/** + **************************************************************************************** + * @defgroup TASK Task and Process + * @ingroup KERNEL + * @brief Task management module. + * + * This module implements the functions used for managing tasks. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include // standard integer +#include // standard boolean + +#include "rwip_config.h" // stack configuration +#include "compiler.h" // compiler defines, INLINE +#include "ke_msg.h" // kernel message defines + +/* Default Message handler code to handle several message type in same handler. */ +#define KE_MSG_DEFAULT_HANDLER (0xFFFF) +/* Invalid task */ +#define KE_TASK_INVALID (0xFFFF) +/* Used to know if a message is not present in kernel queue */ +#define KE_MSG_NOT_IN_QUEUE ((struct co_list_hdr *) 0xFFFFFFFF) + +/// Status of ke_task API functions +enum KE_TASK_STATUS +{ + KE_TASK_OK = 0, + KE_TASK_FAIL, + KE_TASK_UNKNOWN, + KE_TASK_CAPA_EXCEEDED, + KE_TASK_ALREADY_EXISTS, +}; + + +#define MSG_T(msg) ((ke_task_id_t)((msg) >> 8)) +#define MSG_I(msg) ((msg) & ((1<<8)-1)) + +/// Format of a task message handler function +typedef int (*ke_msg_func_t)(ke_msg_id_t const msgid, void const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id); + +/// Macro for message handler function declaration or definition +#define KE_MSG_HANDLER(msg_name, param_struct) __STATIC int msg_name##_handler(ke_msg_id_t const msgid, \ + param_struct const *param, \ + ke_task_id_t const dest_id, \ + ke_task_id_t const src_id) + +#define KE_MSG_HANDLER_NO_STATIC(msg_name, param_struct) int msg_name##_handler(ke_msg_id_t const msgid, \ + param_struct const *param, \ + ke_task_id_t const dest_id, \ + ke_task_id_t const src_id) + +/// Macro for message handlers table declaration or definition +#define KE_MSG_HANDLER_TAB(task) __STATIC const struct ke_msg_handler task##_msg_handler_tab[] = + +/// Element of a message handler table. +struct ke_msg_handler +{ + /// Id of the handled message. + ke_msg_id_t id; + /// Pointer to the handler function for the msgid above. + ke_msg_func_t func; +}; + +/// Task descriptor grouping all information required by the kernel for the scheduling. +struct ke_task_desc +{ + /// Pointer to the message handler table + const struct ke_msg_handler* msg_handler_tab; + /// Pointer to the state table (one element for each instance). + ke_state_t* state; + /// Maximum index of supported instances of the task. + uint16_t idx_max; + /// Number of messages handled + uint16_t msg_cnt; +}; + +/* + * FUNCTION PROTOTYPES + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Initialize Kernel task module. + **************************************************************************************** + */ +void ke_task_init(void); + +/** + **************************************************************************************** + * @brief Create a task. + * + * @param[in] task_type Task type. + * @param[in] p_task_desc Pointer to task descriptor. + * + * @return Status + **************************************************************************************** + */ +uint8_t ke_task_create(uint8_t task_type, struct ke_task_desc const * p_task_desc); + +/** + **************************************************************************************** + * @brief Delete a task. + * + * @param[in] task_type Task type. + * + * @return Status + **************************************************************************************** + */ +uint8_t ke_task_delete(uint8_t task_type); + +/** + **************************************************************************************** + * @brief Retrieve the state of a task. + * + * @param[in] id Task id. + * + * @return Current state of the task + **************************************************************************************** + */ +ke_state_t ke_state_get(ke_task_id_t const id); + +/** + **************************************************************************************** + * @brief Set the state of the task identified by its Task Id. + * + * In this function we also handle the SAVE service: when a task state changes we + * try to activate all the messages currently saved in the save queue for the given + * task identifier. + * + * @param[in] id Identifier of the task instance whose state is going to be modified + * @param[in] state_id New State + * + **************************************************************************************** + */ +void ke_state_set(ke_task_id_t const id, ke_state_t const state_id); + +/** + **************************************************************************************** + * @brief Generic message handler to consume message without handling it in the task. + * + * @param[in] msgid Id of the message received (probably unused) + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id TaskId of the receiving task. + * @param[in] src_id TaskId of the sending task. + * + * @return KE_MSG_CONSUMED + **************************************************************************************** + */ +int ke_msg_discard(ke_msg_id_t const msgid, void const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id); + +/** + **************************************************************************************** + * @brief Generic message handler to consume message without handling it in the task. + * + * @param[in] msgid Id of the message received (probably unused) + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id TaskId of the receiving task. + * @param[in] src_id TaskId of the sending task. + * + * @return KE_MSG_CONSUMED + **************************************************************************************** + */ +int ke_msg_save(ke_msg_id_t const msgid, void const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id); + + + +/** + **************************************************************************************** + * @brief This function flushes all messages, currently pending in the kernel for a + * specific task. + * + * @param[in] task The Task Identifier that shall be flushed. + **************************************************************************************** + */ +void ke_task_msg_flush(ke_task_id_t task); + + +/** + **************************************************************************************** + * @brief Check validity of a task. If task type or task instance does not exist, + * return invalid task + * + * @param[in] task Task Identifier to check. + * + * @return Task identifier if valid, invalid identifier else. + **************************************************************************************** + */ +ke_task_id_t ke_task_check(ke_task_id_t task); + +/// @} TASK + +#endif // _KE_TASK_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_timer.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_timer.h new file mode 100644 index 0000000..46fbc37 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api/ke_timer.h @@ -0,0 +1,148 @@ +/** + **************************************************************************************** + * + * @file ke_timer.h + * + * @brief This file contains the definitions used for timer management + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef _KE_TIMER_H_ +#define _KE_TIMER_H_ + +/** + **************************************************************************************** + * @defgroup TIMER BT Time + * @ingroup KERNEL + * @brief Timer management module. + * + * This module implements the functions used for managing kernel timers. + * + **************************************************************************************** + */ + +#include "rwip.h" // RW definitions +#include "rwip_config.h" // stack configuration +#include "ke_msg.h" // messaging definition + + +/* + * DEFINITIONS + **************************************************************************************** + */ + + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Timer Object +struct ke_timer +{ + /// next ke timer + struct ke_timer *next; + /// message identifier + ke_msg_id_t id; + /// task identifier + ke_task_id_t task; + /// time value + rwip_time_t time; +}; + + +/* + * FUNCTION PROTOTYPES + **************************************************************************************** + */ + + +/** + **************************************************************************************** + * @brief Initialize Kernel timer module. + **************************************************************************************** + */ +void ke_timer_init(void); + +/** + **************************************************************************************** + * @brief Set a timer. + * + * The function first cancel the timer if it is already existing, then + * it creates a new one. The timer can be one-shot or periodic, i.e. it + * will be automatically set again after each trigger. + * + * When the timer expires, a message is sent to the task provided as + * argument, with the timer id as message id. + * + * The timer is programmed in time units (TU is 1ms). + * + * @param[in] timer_id Timer identifier (message identifier type). + * @param[in] task_id Task identifier which will be notified + * @param[in] delay Delay in time units. + **************************************************************************************** + */ +void ke_timer_set(ke_msg_id_t const timer_id, ke_task_id_t const task, uint32_t delay); + +/** + **************************************************************************************** + * @brief Remove an registered timer. + * + * This function search for the timer identified by its id and its task id. + * If found it is stopped and freed, otherwise an error message is returned. + * + * @param[in] timer_id Timer identifier. + * @param[in] task Task identifier. + **************************************************************************************** + */ +void ke_timer_clear(ke_msg_id_t const timerid, ke_task_id_t const task); + +/** + **************************************************************************************** + * @brief Checks if a requested timer is active. + * + * This function pops the first timer from the timer queue and notifies the appropriate + * task by sending a kernel message. If the timer is periodic, it is set again; + * if it is one-shot, the timer is freed. The function checks also the next timers + * and process them if they have expired or are about to expire. + **************************************************************************************** + */ +bool ke_timer_active(ke_msg_id_t const timer_id, ke_task_id_t const task_id); + +/** + **************************************************************************************** + * @brief Adjust all kernel timers by specified adjustment delay. + * + * This function updates all timers to align to a new SCLK after a system clock adjust. + **************************************************************************************** + */ +void ke_timer_adjust_all(uint32_t delay); + +/** + **************************************************************************************** + * @brief Compute the authorized sleep time until next kernel timer event + * + * The function takes as argument the current time to compute the sleep time. + * + * if some timer are programmed it return the sleep time between current time and + * first timer expiration. + * + * If there is no timer programmed, function return false meaning that platform should not + * consider the kernel timer to decide the sleep time duration. + * + * @param[in] current_time Current system time + * @param[out] sleep_time Computed sleep duration + * + * @return true sleep time has been computed ; false if there is no programed timer, + meaning that sleep_time is not relevant and can be ignored. + **************************************************************************************** + */ +bool ke_sleep_time_get(uint32_t current_time, int32_t* sleep_time); + +/// @} TIMER + +#endif // _KE_TIMER_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip.h new file mode 100644 index 0000000..be60172 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip.h @@ -0,0 +1,592 @@ +/** +**************************************************************************************** +* +* @file rwip.h +* +* @brief RW IP SW main module +* +* Copyright (C) RivieraWaves 2009-2015 +* +* +**************************************************************************************** +*/ +#ifndef _RWIP_H_ +#define _RWIP_H_ + +/** + **************************************************************************************** + * @addtogroup ROOT + * @brief Entry points of the RW IP stacks/modules + * + * This module contains the primitives that allow an application accessing and running the + * RW IP protocol stacks / modules. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" // stack configuration + +#include // standard integer definitions +#include // standard boolean definitions + + +/* + * DEFINES + **************************************************************************************** + */ +/// Maximum value of a Bluetooth clock (in 312.5us half slots) +#define RWIP_MAX_CLOCK_TIME ((1L<<28) - 1) +/// Maximum value of a 10ms Bluetooth clock +#define RWIP_MAX_10MS_TIME ((1L<<23) - 1) +/// retrieve 10ms time according to clock time +#define RWIP_CLOCK_TO_10MS_TIME(clock) ((clock) >> 5) +/// retrieve clock time according to 10ms time +#define RWIP_10MS_TIME_TO_CLOCK(time) ((time) << 5) +/// Invalid target time +#define RWIP_INVALID_TARGET_TIME (0xFFFFFFFFL) + + +/// result of sleep state. +enum rwip_sleep_state +{ + /// Some activity pending, can not enter in sleep state + RWIP_ACTIVE = 0, + /// CPU can be put in sleep state + RWIP_CPU_SLEEP, + /// IP could enter in deep sleep + RWIP_DEEP_SLEEP, +}; + + +/// Definition of the bits preventing the system from sleeping +enum prevent_sleep +{ + /// Flag indicating that the wake up process is ongoing + RW_WAKE_UP_ONGOING = 0x0001, + /// Flag indicating that an TX transfer is ongoing on Transport Layer + RW_TL_TX_ONGOING = 0x0002, + /// Flag indicating that an RX transfer is ongoing on Transport Layer + RW_TL_RX_ONGOING = 0x0004, + /// Flag indicating the IP is in sleep, to avoid running sleep algorithm while already entering sleep + RW_DEEP_SLEEP = 0x0008, + /// Flag indicating that an encryption is ongoing + RW_CRYPT_ONGOING = 0x0010, + /// Flag indicating that controller shall not sleep due to not CSB LPO_Allowed + RW_CSB_NOT_LPO_ALLOWED = 0x0040, + /// Flag indicating the MWS/WLAN Event Generator is in operation + RW_MWS_WLAN_EVENT_GENERATOR_ACTIVE = 0x0080, + /// Flag to indicate that platform does not support deep sleep + RW_PLF_DEEP_SLEEP_DISABLED = 0x0100, + /// Flag to indicate that a baseband frame is ongoing + RW_BB_FRAME_ONGOING = 0x0200, + /// Flag to indicate that BLE Hopping computation on-going + RW_HOP_CALC_ONGOING = 0x0400, + /// Flag to indicate that BT is in active mode (ACL, SCO) + RW_BT_ACTIVE_MODE = 0x0800, + /// Flag to indicate that BLE requires active mode + RW_BLE_ACTIVE_MODE = 0x1000, +}; + +/// Parameters - Possible Returned Status +enum PARAM_STATUS +{ + /// PARAM status OK + PARAM_OK, + /// generic PARAM status KO + PARAM_FAIL, + /// PARAM ID unrecognized + PARAM_ID_NOT_DEFINED, + /// No space for PARAM + PARAM_NO_SPACE_AVAILABLE, + /// Length violation + PARAM_LENGTH_OUT_OF_RANGE, + /// PARAM parameter locked + PARAM_PARAM_LOCKED, + /// PARAM corrupted + PARAM_CORRUPT +}; + +/** + * External interface type types. + */ +enum rwip_eif_types +{ + /// Host Controller Interface - Controller part + RWIP_EIF_HCIC, + + /// Host Controller Interface - Host part + RWIP_EIF_HCIH, + + /// Application Host interface + RWIP_EIF_AHI, +}; + + +/// Enumeration of External Interface status codes +enum rwip_eif_status +{ + /// EIF status OK + RWIP_EIF_STATUS_OK, + /// EIF status KO + RWIP_EIF_STATUS_ERROR, + +#if (BLE_EMB_PRESENT == 0) + /// External interface detached + RWIP_EIF_STATUS_DETACHED, + /// External interface attached + RWIP_EIF_STATUS_ATTACHED, +#endif // (BLE_EMB_PRESENT == 0) +}; + +/// Enumeration of RF modulations +enum rwip_rf_mod +{ + MOD_GFSK = 0x01, + MOD_DQPSK = 0x02, + MOD_8DPSK = 0x03, +}; + +#if RW_DEBUG +/// Assert type +/*@TRACE*/ +enum assert_type +{ + ASSERT_TYPE_WARNING = 0, + ASSERT_TYPE_ERROR = 1, +}; +#endif //RW_DEBUG + +/// Types of initialization of the IP +enum rwip_init_type +{ + /// IP initialization + RWIP_INIT = 0, + /// IP first reset (done once after initialization, before protocol stack is used) + RWIP_1ST_RST, + /// Normal IP reset (can be done at any time when protocol stack is in use) + RWIP_RST, +}; + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// Time information +/*@TRACE*/ +typedef struct +{ + /// Integer part of the time (in half-slot) + uint32_t hs; + /// Fractional part of the time (in half-us) (range: 0-624) + uint32_t hus; +} rwip_time_t; + +/// API functions of the RF driver that are used by the BLE or BT software +struct rwip_rf_api +{ + /// Function called upon HCI reset command reception + void (*reset)(void); + /// Function called to enable/disable force AGC mechanism (true: en / false : dis) + void (*force_agc_enable)(bool); + /// Function called when TX power has to be decreased for a specific link id + bool (*txpwr_dec)(uint8_t); + /// Function called when TX power has to be increased for a specific link id + bool (*txpwr_inc)(uint8_t); + /// Function called when TX power has to be set to max for a specific link id + void (*txpwr_max_set)(uint8_t); + /// Function called to convert a TX power CS power field into the corresponding value in dBm + uint8_t (*txpwr_dbm_get)(uint8_t, uint8_t); + /// Function called to convert a power in dBm into a control structure tx power field + uint8_t (*txpwr_cs_get)(int8_t, bool); + /// Function called to convert the RSSI read from the control structure into a real RSSI + int8_t (*rssi_convert)(uint8_t); + /// Function used to read a RF register + uint32_t (*reg_rd)(uint32_t); + /// Function used to write a RF register + void (*reg_wr)(uint32_t, uint32_t); + /// Function called to put the RF in deep sleep mode + void (*sleep)(void); + /// Index of minimum TX power + uint8_t txpwr_min; + /// Index of maximum TX power + uint8_t txpwr_max; + /// RSSI high threshold ('real' signed value in dBm) + int8_t rssi_high_thr; + /// RSSI low threshold ('real' signed value in dBm) + int8_t rssi_low_thr; + /// interferer threshold ('real' signed value in dBm) + int8_t rssi_interf_thr; + /// RF wakeup delay (in slots) + uint8_t wakeup_delay; +}; + +/// API functions of the parameters that are used by the BLE or BT software +struct rwip_param_api +{ + /** + * Get a parameter value + * @param[in] param_id Parameter identifier + * @param[in/out] lengthPtr Pointer to the length of the parameter (input: contain max length, output contain the effective param length, in bytes) + * @param[out] buf Pointer to the buffer be filled with the parameter value + * @return status 0: success | >0 : error + */ + uint8_t (*get) (uint8_t param_id, uint8_t * lengthPtr, uint8_t *buf); + + /** + * Set a parameter value + * @param[in] param_id Parameter identifier + * @param[in/out] length Length of the parameter (in bytes) + * @param[out] buf Pointer to the buffer containing the parameter value + * @return status 0: success | >0 : error + */ + uint8_t (*set) (uint8_t param_id, uint8_t length, uint8_t *buf); + + /** + * Delete a parameter + * @param[in] param_id Parameter identifier + * @return status 0: success | >0 : error + */ + uint8_t (*del) (uint8_t param_id); +}; + +/// Internal API for priority +struct rwip_prio +{ + ///value + uint8_t value; + ///Increment + uint8_t increment; +}; +/** + **************************************************************************************** + * @brief Function called when packet transmission/reception is finished. + + * @param[in] dummy Dummy data pointer returned to callback when operation is over. + * @param[in] status Ok if action correctly performed, else reason status code. + ***************************************************************************************** + */ +typedef void (*rwip_eif_callback) (void*, uint8_t); + +/** + * Transport layer communication interface. + */ +struct rwip_eif_api +{ + /** + ************************************************************************************* + * @brief Starts a data reception. + * + * @param[out] bufptr Pointer to the RX buffer + * @param[in] size Size of the expected reception + * @param[in] callback Pointer to the function called back when transfer finished + * @param[in] dummy Dummy data pointer returned to callback when reception is finished + ************************************************************************************* + */ + void (*read) (uint8_t *bufptr, uint32_t size, rwip_eif_callback callback, void* dummy); + + /** + ************************************************************************************* + * @brief Starts a data transmission. + * + * @param[in] bufptr Pointer to the TX buffer + * @param[in] size Size of the transmission + * @param[in] callback Pointer to the function called back when transfer finished + * @param[in] dummy Dummy data pointer returned to callback when transmission is finished + ************************************************************************************* + */ + void (*write)(uint8_t *bufptr, uint32_t size, rwip_eif_callback callback, void* dummy); + + /** + ************************************************************************************* + * @brief Enable Interface flow. + ************************************************************************************* + */ + void (*flow_on)(void); + + /** + ************************************************************************************* + * @brief Disable Interface flow. + * + * @return True if flow has been disabled, False else. + ************************************************************************************* + */ + void (*flow_off)(void); +}; + +/* + * VARIABLE DECLARATION +***************************************************************************************** + */ + +/// API for RF driver +extern struct rwip_rf_api rwip_rf; +/// API for parameters +extern struct rwip_param_api rwip_param; +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/// API for dual mode priority +extern const struct rwip_prio rwip_priority[RWIP_PRIO_IDX_MAX]; +#if (RW_WLAN_COEX || RW_MWS_COEX) +/// API for COEX configuration +extern const uint8_t rwip_coex_cfg[RWIP_COEX_CFG_MAX]; +#endif //(RW_WLAN_COEX || RW_MWS_COEX) +/// Programming delay, margin for programming the baseband in advance of each activity (in half-slots) +extern uint8_t rwip_prog_delay; +#endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + +/* + * MACROS + **************************************************************************************** + */ + +/// Get Event status flag +#if (BT_EMB_PRESENT || BLE_EMB_PRESENT) +#if (RW_WLAN_COEX || RW_MWS_COEX) +#define RWIP_COEX_GET(coex_cfg_idx, bit_field) \ + (uint8_t)(((rwip_coex_cfg[RWIP_COEX_ ## coex_cfg_idx ##_IDX]) >> RWIP_ ## bit_field ## _POS ) & RWIP_COEX_BIT_MASK) +#else //!(RW_WLAN_COEX || RW_MWS_COEX) +#define RWIP_COEX_GET(coex_cfg_idx, bit_field) 0 +#endif //(RW_WLAN_COEX || RW_MWS_COEX) +#endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + +/* + * FUNCTION DECLARATION +***************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Initializes the RW BT SW. + * + **************************************************************************************** + */ +void rwip_init(uint32_t error); + +/** + **************************************************************************************** + * @brief Reset the RW BT SW. + * + **************************************************************************************** + */ +void rwip_reset(void); + + + +#if (BT_EMB_PRESENT) + +#if PCA_SUPPORT +/** + **************************************************************************************** + * @brief Check if clock dragging limitation + * + * @return true if clock dragging must be used + **************************************************************************************** + */ +bool rwip_pca_clock_dragging_only(void); +#endif //PCA_SUPPORT +#endif // (BT_EMB_PRESENT) + +#if (BT_EMB_PRESENT || BLE_EMB_PRESENT) +#if (RW_MWS_COEX) +/** + **************************************************************************************** + * @brief Enable/Disable the MWS coexistence interface. + * + * @param[in] CoexSetting Coexistence value + * + **************************************************************************************** + */ +void rwip_mwscoex_set(bool state); +#endif //RW_MWS_COEX + +#if (RW_WLAN_COEX) +/** + **************************************************************************************** + * @brief Enable/Disable the Wireless LAN coexistence interface. + * + * @param[in] CoexSetting Coexistence value + * + **************************************************************************************** + */ +void rwip_wlcoex_set(bool state); +#endif //RW_WLAN_COEX +#endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + +/** + **************************************************************************************** + * @brief Function to implement in platform in order to retrieve each external interface API + * + * @param[in] idx External interface index + * + * @return External interface api structure + **************************************************************************************** + */ +extern const struct rwip_eif_api* rwip_eif_get(uint8_t idx); + +#if RW_DEBUG +/** + **************************************************************************************** + * @brief Raises an assertion message to the control interface (if present) + * + * @param[in] file File name + * @param[in] line Line number + * @param[in] param0 Parameter 0 (custom value given by the assert instruction) + * @param[in] param1 Parameter 1 (custom value given by the assert instruction) + * @param[in] type 0: warning / 1: error + **************************************************************************************** + */ +void rwip_assert(const char * file, int line, int param0, int param1, uint8_t type); +#endif //RW_DEBUG + + +/* ************************************************************************************** + * Driver functions + * ************************************************************************************** + */ + +/** + **************************************************************************************** + * @brief Retrieved sampled time + * + * @note Shall be called within a critical section + * + * @return current time sampled (@see rwip_time_t) + **************************************************************************************** + */ +rwip_time_t rwip_time_get(void); + + +#if (BT_EMB_PRESENT) +/** + **************************************************************************************** + * @brief Set current time + * + * @param clock value in half-slots + **************************************************************************************** + */ +void rwip_time_set(uint32_t clock); +#endif // (BT_EMB_PRESENT) + +/** + **************************************************************************************** + * @brief Set the 1 ms target timer + * + * @note if target is RWIP_INVALID_TARGET_TIME, not timer are programmed + * + * @param[in] target 1ms Timer target value + **************************************************************************************** + */ +void rwip_timer_1ms_set(rwip_time_t target); + +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/** + **************************************************************************************** + * @brief Set the a half slot target timer + * + * @note if target is RWIP_INVALID_TARGET_TIME, not timer are programmed + * + * @param[in] target Half Slot Timer target value + **************************************************************************************** + */ +void rwip_timer_hs_set(uint32_t target); + +/** + **************************************************************************************** + * @brief Set the a half slot target timer + * + * @note if target is RWIP_INVALID_TARGET_TIME, not timer are programmed + * + * @param[in] target Half Slot Timer target value + * @param[in] half_us_delay Half us timer delay in corresponding half slot (range [0:624]) + **************************************************************************************** + */ +void rwip_timer_hus_set(uint32_t target, uint32_t half_us_delay); +#endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + +/** + **************************************************************************************** + * @brief Start AES encryption + * + * The exchange memory must be filled before calling this function. + * This function expect to be called from a BLE Module + * + * @param[in] key AES Encryption key must be 16 bytes + * @param[in] val 16 bytes value array to encrypt using AES + **************************************************************************************** + */ +void rwip_aes_encrypt(const uint8_t *key, const uint8_t* val); + +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/** + **************************************************************************************** + * @brief Request a Software interrupt to be triggered + **************************************************************************************** + */ +void rwip_sw_int_req(void); +#endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + +/** + **************************************************************************************** + * @brief Invoke the sleep function. + * + * @return sleep status (@see enum rwip_sleep_state) + **************************************************************************************** + */ +uint8_t rwip_sleep(void); + +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/** + **************************************************************************************** + * @brief Handle the common core interrupts. + **************************************************************************************** + */ +void rwip_isr(void); +#endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + +/** + **************************************************************************************** + * @brief Set a bit in the prevent sleep bit field, in order to prevent the system from + * going to sleep + * + * @param[in] prv_slp_bit Bit to be set in the prevent sleep bit field + **************************************************************************************** + */ +void rwip_prevent_sleep_set(uint16_t prv_slp_bit); + +/** + **************************************************************************************** + * @brief Clears a bit in the prevent sleep bit field, in order to allow the system + * going to sleep + * + * @param[in] prv_slp_bit Bit to be cleared in the prevent sleep bit field + **************************************************************************************** + */ +void rwip_prevent_sleep_clear(uint16_t prv_slp_bit); + +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/** + **************************************************************************************** + * @brief Check if the system is permanently active (e.g. for BT ACL connection) + * + * @return false: system might sleep | true: system stays active + **************************************************************************************** + */ +bool rwip_active_check(void); +#endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + +/** + **************************************************************************************** + * @brief Schedule all pending events. + * + **************************************************************************************** + */ +void rwip_schedule(void); + +///@} ROOT + +#endif // _RWIP_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip_config.h new file mode 100644 index 0000000..5e0c744 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip_config.h @@ -0,0 +1,1421 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwip_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef RWIP_CONFIG_H_ +#define RWIP_CONFIG_H_ + +/** + **************************************************************************************** + * @addtogroup ROOT + * @{ + * + * Information about RW SW IP options and flags + * + * BT_DUAL_MODE BT/BLE Dual Mode + * BT_STD_MODE BT Only + * BLE_STD_MODE BLE Only + * + * BT_EMB_PRESENT BT controller exists + * BLE_EMB_PRESENT BLE controller exists + * BLE_HOST_PRESENT BLE host exists + * + * @name RW Stack Configuration + * @{ + **************************************************************************************** + */ +#include "n32wb03x.h" +#include "app_user_config.h" +#include "ns_log.h" +/* + * DEFINES + **************************************************************************************** + */ +#define BLE_NB_PROFILES 10 +#define BLE_PROFILES BLE_NB_PROFILES +#define CFG_HOST +#define CFG_APP +#define CFG_PRF +#define CFG_APP_PRF 1 + +#define CFG_AHITL 1 +#define CFG_HCITL 1 +#define CFG_APP_SEC + + + + +#define CFG_BLE 1 +#define CFG_EMB 1 +//#define CFG_BLE_MESH 1 + +//#define CFG_ALLROLES 1 + +#define CFG_PERIPHERAL +#define CFG_BROADCASTER +#define CFG_CENTRAL +#define CFG_OBSERVER +#define BLE_OBSERVER 1 +#define BLE_CENTRAL 1 +#define BLE_OBSERVERH 1 +#define BLE_CENTRALH 1 + +#define CFG_RAL 2 //TODO VAR +#define CFG_ACT 4 +#define CFG_CON 4 + + +#define CFG_CON_CTE_REQ 1 +#define CFG_CON_CTE_RSP 1 +#define CFG_CONLESS_CTE_TX 1 +#define CFG_CONLESS_CTE_RX 1 +#define CFG_AOD 1 +#define CFG_AOA 1 + +//#define CFG_AODH 1 +//#define CFG_AOAH 1 + +#define CFG_ECC 1 + +//#define CFG_ECCH 1 +//#define CFG_LECB 1 +// +//TEST DEFINE +#define TEST_CALLBACK 1 +//#define TEST_OTA 1 +//#define MTU_247_DLE 1 + +/******************************************************************************************/ +/* ------------------------- STACK PARTITIONING -----------------------------------*/ +/******************************************************************************************/ + +#if defined(CFG_LECB) + #define BLE_LECB (1) +#else + #define BLE_LECB (0) +#endif + +#if defined(CFG_BT) +#define BT_EMB_PRESENT 1 +#else // defined(CFG_BT) +#define BT_EMB_PRESENT 0 +#endif // defined(CFG_BT) + +#if defined(CFG_BLE) && defined(CFG_EMB) +#define BLE_EMB_PRESENT 1 +#else // defined(CFG_BLE) && defined(CFG_EMB) +#define BLE_EMB_PRESENT 0 +#endif // defined(CFG_BLE) && defined(CFG_EMB) + +#if defined(CFG_BLE) && defined(CFG_HOST) +#define BLE_HOST_PRESENT 1 +#else // defined(CFG_BLE) && defined(CFG_HOST) +#define BLE_HOST_PRESENT 0 +#endif // defined(CFG_BLE) && defined(CFG_HOST) + +#if defined(CFG_BLE) && defined(CFG_APP) +#define BLE_APP_PRESENT 1 +#else // defined(CFG_BLE) && defined(CFG_APP) +#define BLE_APP_PRESENT 0 +#endif // defined(CFG_BLE) && defined(CFG_APP) + +#define BT_DUAL_MODE (BT_EMB_PRESENT && BLE_EMB_PRESENT) +#define HCI_PRESENT 1 + +/// Flag indicating that Mesh is supported +#if defined(CFG_BLE_MESH) +#define BLE_MESH 1 +#else // !defined(CFG_BLE_MESH) +#define BLE_MESH 0 +#endif // defined(CFG_BLE_MESH) + +/******************************************************************************************/ +/* ------------------------- INTERFACES DEFINITIONS -------------------------------*/ +/******************************************************************************************/ + +/// Application Host Interface +#if defined(CFG_AHITL) +#define AHI_TL_SUPPORT 1 +#else // defined(CFG_AHITL) +#define AHI_TL_SUPPORT 0 +#endif // defined(CFG_AHITL) + + +/// Host Controller Interface Support (defines if HCI parser is present or not) +#if defined(CFG_HCITL) +#define HCI_TL_SUPPORT 1 +#else //defined(CFG_HCITL) +#define HCI_TL_SUPPORT 0 +#endif //defined(CFG_HCITL) + + +#if BLE_HOST_PRESENT +#define H4TL_SUPPORT ((AHI_TL_SUPPORT) + (HCI_TL_SUPPORT)) +#else // !BLE_HOST_PRESENT +#define H4TL_SUPPORT (HCI_TL_SUPPORT) +#endif // BLE_HOST_PRESENT + +/// Number of HCI commands the stack can handle simultaneously +#define HCI_NB_CMD_PKTS (5 * HCI_TL_SUPPORT) + +/******************************************************************************************/ +/* -------------------------- BLE COMMON DEFINITIONS ------------------------------*/ +/******************************************************************************************/ +/// Kernel Heap memory sized reserved for allocate dynamically connection environment +#define KE_HEAP_MEM_RESERVED (4) + +#if defined(CFG_BLE) + +/// Broadcaster +#if (defined(CFG_BROADCASTER) || defined(CFG_PERIPHERAL) || defined(CFG_ALLROLES)) +#define BLE_BROADCASTER 1 +#else +#define BLE_BROADCASTER 0 +#endif // (defined(CFG_BROADCASTER) || defined(CFG_PERIPHERAL) || defined(CFG_ALLROLES)) + +/// Observer +#if (defined(CFG_OBSERVER) || defined(CFG_CENTRAL) || defined(CFG_ALLROLES)) +#define BLE_OBSERVER 1 +#else +#define BLE_OBSERVER 0 +#endif // (defined(CFG_OBSERVER) || defined(CFG_CENTRAL) || defined(CFG_ALLROLES)) + +/// Central +#if (defined(CFG_CENTRAL) || defined(CFG_ALLROLES)) +#define BLE_CENTRAL 1 +#else +#define BLE_CENTRAL 0 +#endif // (defined(CFG_CENTRAL) || defined(CFG_ALLROLES)) + +/// Peripheral +#if (defined(CFG_PERIPHERAL) || defined(CFG_ALLROLES)) +#define BLE_PERIPHERAL 1 +#else +#define BLE_PERIPHERAL 0 +#endif // (defined(CFG_PERIPHERAL) || defined(CFG_ALLROLES)) + +#if ((BLE_BROADCASTER+BLE_OBSERVER+BLE_PERIPHERAL+BLE_CENTRAL) == 0) + #error "No application role defined" +#endif // ((BLE_BROADCASTER+BLE_OBSERVER+BLE_PERIPHERAL+BLE_CENTRAL) == 0) + +/// Maximum number of devices in RAL +#define BLE_RAL_MAX (CFG_RAL) + +/// Maximum number of simultaneous BLE activities (scan, connection, advertising, initiating) +#define BLE_ACTIVITY_MAX (CFG_ACT) + +#if (BLE_HOST_PRESENT) +/// Maximum number of simultaneous connections +#if (BLE_CENTRAL || BLE_PERIPHERAL) + #define BLE_CONNECTION_MAX (CFG_CON) +#else + #define BLE_CONNECTION_MAX (0) +#endif /* #if (BLE_CENTRAL || BLE_PERIPHERAL) */ + +#if (BLE_CONNECTION_MAX > BLE_ACTIVITY_MAX) // TODO_CHECK +#error "Number of connections must be strictly less than number of activities" +#endif // (BLE_CONNECTION_MAX >= BLE_ACTIVITY_MAX) +#endif // (BLE_HOST_PRESENT) + +/// Max advertising reports before sending the info to the host +#define BLE_ADV_REPORTS_MAX (1) + +#if (BLE_EMB_PRESENT) +/// Maximum number of ADV reports in the HCI queue to Host +#define BLE_MAX_NB_ADV_REP_FRAG (4 * HCI_TL_SUPPORT) +/// Maximum number of IQ reports in the HCI queue to Host +#define BLE_MAX_NB_IQ_REP (4 * HCI_TL_SUPPORT) +#endif // (BLE_EMB_PRESENT) +#endif //defined(CFG_BLE) + + +/******************************************************************************************/ +/* -------------------------- Direction finding (AoA/AoD) -------------------------*/ +/******************************************************************************************/ + +#if defined(CFG_CON_CTE_REQ) + #define BLE_CON_CTE_REQ (1) +#else // defined(CFG_CON_CTE_REQ) + #define BLE_CON_CTE_REQ (0) +#endif // defined(CFG_CON_CTE_REQ) + +#if defined(CFG_CON_CTE_RSP) + #define BLE_CON_CTE_RSP (1) +#else // defined(CFG_CON_CTE_RSP) + #define BLE_CON_CTE_RSP (0) +#endif // defined(CFG_CON_CTE_RSP) + +#if defined(CFG_CONLESS_CTE_TX) + #define BLE_CONLESS_CTE_TX (1) +#else // defined(CFG_CONLESS_CTE_TX) + #define BLE_CONLESS_CTE_TX (0) +#endif // defined(CFG_CONLESS_CTE_TX) + +#if defined(CFG_CONLESS_CTE_RX) + #define BLE_CONLESS_CTE_RX (1) +#else // defined(CFG_CONLESS_CTE_RX) + #define BLE_CONLESS_CTE_RX (0) +#endif // defined(CFG_CONLESS_CTE_RX) + +#if defined(CFG_AOD) + #define BLE_AOD (1) +#else // defined(CFG_AOD) + #define BLE_AOD (0) +#endif // defined(CFG_AOD) + +#if defined(CFG_AODH) + #define BLE_AODH (1) +#else // defined(CFG_AODH) + #define BLE_AODH (0) +#endif // defined(CFG_AODH) + +#if defined(CFG_AOA) + #define BLE_AOA (1) +#else // defined(CFG_AOA) + #define BLE_AOA (0) +#endif // defined(CFG_AOA) + +#if defined(CFG_AOAH) + #define BLE_AOAH (1) +#else // defined(CFG_AOAH) + #define BLE_AOAH (0) +#endif // defined(CFG_AOAH) + +#if defined(CFG_ECC) + #define BLE_ECC (1) +#else + #define BLE_ECC (0) +#endif + +#if defined(CFG_ECCH) + #define BLE_ECCH (1) +#else + #define BLE_ECCH (0) +#endif + +/******************************************************************************************/ +/* -------------------------- ISOCHRONOUS CONFIGURATION -------------------------*/ +/******************************************************************************************/ + +// check if isochronous is enabled or not +#if (defined(CFG_ISO_CON) && (CFG_ISO_CON > 0) && (defined(CFG_ISO_MODE_0))) + #define BLE_ISO_PRESENT (1) +#else // !(defined(CFG_ISO_CON) && (CFG_ISO_CON > 0)) + #define BLE_ISO_PRESENT (0) +#endif // (defined(CFG_ISO_CON) && (CFG_ISO_CON > 0)) + +// *** Definition of supported isochronous mode *** + +// Isochronous Mode 0 - Proprietary mode +#if (BLE_ISO_PRESENT && defined(CFG_ISO_MODE_0)) + #define BLE_ISO_MODE_0 (BLE_CENTRAL | BLE_PERIPHERAL) + #define BLE_ISO_MODE_0_PROTOCOL (BLE_ISO_MODE_0 & BLE_HOST_PRESENT) + #define BLE_ISO_MODE_0_PROFILE (BLE_ISO_MODE_0 & BLE_HOST_PRESENT) + #define BLE_RSA (BLE_ISO_MODE_0_PROFILE) +#else + #define BLE_ISO_MODE_0 (0) + #define BLE_ISO_MODE_0_PROTOCOL (0) + #define BLE_ISO_MODE_0_PROFILE (0) + #define BLE_RSA (0) +#endif // (BLE_ISO_PRESENT && defined(CFG_AUDIO)) + +#if (BLE_ISO_PRESENT) + /// Maximum number of ISO channel / streams + #define BLE_ISO_CHANNEL_MAX (CFG_ISO_CON) + #define BLE_ISO_STREAM_MAX (CFG_ISO_CON) + + /// Maximum number of octets that can be received/transmitted over Isochronous channels + #define BLE_MAX_ISO_OCTETS (251) // number of octets + + /// Define number of ISO TX/RX buffers per isochronous channel + #define BLE_NB_ISO_BUFF_PER_CHAN (4) + + /// Define number of ISO descriptors per isochronous channel + /// Must be equal to max(BLE_NB_ISODESC_PER_ICL_CHAN, BLE_NB_RX_ISODESC_PER_ICO_CHAN + BLE_NB_TX_ISODESC_PER_ICO_CHAN) + #define BLE_NB_ISODESC_PER_CHAN (4) + + /// Number of ISO Descriptors - one descriptor required for update sub-event: 1 per stream + #define BLE_ISO_DESC_NB ((BLE_ISO_CHANNEL_MAX * (BLE_NB_ISODESC_PER_CHAN)) + BLE_ISO_STREAM_MAX) + /// Number of ISO buffers + #define BLE_ISO_BUF_NB (BLE_ISO_CHANNEL_MAX * BLE_NB_ISO_BUFF_PER_CHAN) +#endif // (BLE_ISO_PRESENT) + + +/// Check status of Isochronous Data path drivers + +/// Proprietary ISO over HCI +#if defined(CFG_ISOOHCI) + #define BLE_ISOOHCI (BLE_ISO_PRESENT) +#else + #define BLE_ISOOHCI (0) +#endif + +/// Internal ISO generator for validation purpose +#if defined(CFG_ISOGEN) + #define BLE_ISOGEN (BLE_ISO_PRESENT) +#else + #define BLE_ISOGEN (0) +#endif + +/// Platform PCM +#if defined(CFG_PCM) + #define BLE_ISO_PCM (BLE_ISO_PRESENT) +#else // !defined(CFG_PCM) + #define BLE_ISO_PCM (0) +#endif // defined(CFG_PCM) + +/******************************************************************************************/ +/* -------------------------- DISPLAY SETUP -------------------------------------*/ +/******************************************************************************************/ + +/// Display controller enable/disable +#if defined(CFG_DISPLAY) +#define DISPLAY_SUPPORT 1 +#else +#define DISPLAY_SUPPORT 0 +#endif //CFG_DISPLAY + +/******************************************************************************************/ +/* -------------------------- GPIO SETUP -------------------------------------*/ +/******************************************************************************************/ + +/// Display controller enable/disable +#if defined(CFG_GPIO) +#define GPIO_SUPPORT 1 +#else +#define GPIO_SUPPORT 0 +#endif //CFG_GPIO + +/******************************************************************************************/ +/* -------------------------- RTC SETUP -------------------------------------*/ +/******************************************************************************************/ + +/// RTC enable/disable +#if defined(CFG_RTC) +#define RTC_SUPPORT 1 +#else +#define RTC_SUPPORT 0 +#endif //CFG_RTC + +/******************************************************************************************/ +/* -------------------------- PS2 SETUP -------------------------------------*/ +/******************************************************************************************/ + +/// PS2 enable/disable +#if defined(CFG_PS2) +#define PS2_SUPPORT 1 +#else +#define PS2_SUPPORT 0 +#endif //CFG_PS2 + + +/******************************************************************************************/ +/* -------------------------- TRACER SETUP -------------------------------------*/ +/******************************************************************************************/ + +/// tracer enable/disable +#if defined(CFG_TRC_EN) + #define TRACER_PRESENT 1 + #include "dbg_trc_config.h" +#else + #define TRACER_PRESENT 0 +#endif // CFG_TRC_EN + +/******************************************************************************************/ +/* ------------------------- DEEP SLEEP SETUP -------------------------------------*/ +/******************************************************************************************/ + +/// Use 32K Hz Clock if set to 1 else 32,768k is used +//#define HZ32000 (GAIA_SUPPORT) + + +//TODO_CHECK +/// Time to wake-up Radio Module (in us) +#define SLEEP_RM_WAKEUP_DELAY 100 +/// Time for stabilization of the high frequency oscillator following a sleep-timer expiry (in us) +#define SLEEP_OSC_NORMAL_WAKEUP_DELAY 800 +/// Time for stabilization of the high frequency oscillator following an external wake-up request (in us) +#define SLEEP_OSC_EXT_WAKEUP_DELAY 800 + +/******************************************************************************************/ +/* -------------------------- BASEBAND SETUP -------------------------------------*/ +/******************************************************************************************/ +//TODO_CHECK IF NEED TO BE VAR +/// Default programming delay, margin for programming the baseband in advance of each activity (in half-slots) +#define IP_PROG_DELAY_DFT (1) + +/** + * Prefetch time (in us) + * - Radio power up: 110us (worst case) + * - EM fetch: 30us (worst case at 26Mhz) + * - HW logic: 10us (worst case at 26Mhz) + */ +#define IP_PREFETCH_TIME_US (150) + +/** + * Prefetch Abort time (in us) + * + * - EM fetch: + * - HW CS Update is 18 access + * - HW Tx Desc Update is 1 access + * - HW Rx Desc Update is 5 access + * => EM update at 26MHz Tx, Rx and CS is (18+1+5)*0.04*4 = 4us + * - HW logic: 10us (worst case) + * - Radio power down: 26 us for Ripple + * + * Prefetch abort time = prefetch time + 4 + 10 + 26 + */ +#define IP_PREFETCHABORT_TIME_US (190) + +/******************************************************************************************/ +/* -------------------------- RADIO SETUP ----------------------------------------*/ +/******************************************************************************************/ + +/// Power control features +#define RF_TXPWR 1 +/// Class of device +#define RF_CLASS1 0 + +/******************************************************************************************/ +/* ------------------------- SUPPORTED RADIO PHY ------------------------------------*/ +/******************************************************************************************/ + +#if defined(CFG_RF_ATLAS) +#define BLE_PHY_1MBPS_SUPPORT 1 +#define BLE_PHY_2MBPS_SUPPORT 1 +#define BLE_PHY_CODED_SUPPORT 1 +#define BLE_STABLE_MOD_IDX_TX_SUPPORT 0 +#define BLE_STABLE_MOD_IDX_RX_SUPPORT 0 +#define BLE_PWR_CLASS_1_SUPPORT 0 +#elif defined(CFG_RF_BTIPT) +#define BLE_PHY_1MBPS_SUPPORT 1 +#define BLE_PHY_2MBPS_SUPPORT 1 +#define BLE_PHY_CODED_SUPPORT 1 +#define BLE_STABLE_MOD_IDX_TX_SUPPORT 0 +#define BLE_STABLE_MOD_IDX_RX_SUPPORT 0 +#define BLE_PWR_CLASS_1_SUPPORT 0 +#elif defined(CFG_RF_CALYPSO) +#define BLE_PHY_1MBPS_SUPPORT 1 +#define BLE_PHY_2MBPS_SUPPORT 1 +#define BLE_PHY_CODED_SUPPORT 0 +#define BLE_STABLE_MOD_IDX_TX_SUPPORT 0 +#define BLE_STABLE_MOD_IDX_RX_SUPPORT 0 +#define BLE_PWR_CLASS_1_SUPPORT 0 +#elif defined(CFG_RF_EXTRC) +#define BLE_PHY_1MBPS_SUPPORT 1 +#define BLE_PHY_2MBPS_SUPPORT 1 +#define BLE_PHY_CODED_SUPPORT 0 +#define BLE_STABLE_MOD_IDX_TX_SUPPORT 0 +#define BLE_STABLE_MOD_IDX_RX_SUPPORT 0 +#define BLE_PWR_CLASS_1_SUPPORT 0 +#else // RIPPLE +#define BLE_PHY_1MBPS_SUPPORT 1 +#define BLE_PHY_2MBPS_SUPPORT 1 +#define BLE_PHY_CODED_SUPPORT 1 +#define BLE_STABLE_MOD_IDX_TX_SUPPORT 0 +#define BLE_STABLE_MOD_IDX_RX_SUPPORT 0 +#define BLE_PWR_CLASS_1_SUPPORT 0 +#endif + +/******************************************************************************************/ +/* ------------------------- COEXISTENCE SETUP ------------------------------------*/ +/******************************************************************************************/ + +/// WLAN Coexistence +#if defined(CFG_WLAN_COEX) + #define RW_WLAN_COEX 1 + #define RW_WLAN_COEX_TEST (defined(CFG_WLAN_COEX_TEST)) +#else + #define RW_WLAN_COEX 0 + #define RW_WLAN_COEX_TEST 0 +#endif // defined(CFG_WLAN_COEX) + +/// MWS Coexistence +#if defined(CFG_MWS_COEX) + #define RW_MWS_COEX 1 + #define RW_MWS_COEX_TEST (defined(CFG_MWS_COEX_TEST)) +#else + #define RW_MWS_COEX 0 + #define RW_MWS_COEX_TEST 0 +#endif // defined(CFG_MWS_COEX) + +/******************************************************************************************/ +/* ----------------------- SLOT AVAILABILITY MASKS -----------------------------------*/ +/******************************************************************************************/ + +/// Maximum support peer SAM map size +#define RW_MAX_PEER_SAM_MAP_SLOTS (256) +#define RW_PEER_SAM_MAP_MAX_LEN (RW_MAX_PEER_SAM_MAP_SLOTS/4) // 2-bit field per slot + +/******************************************************************************************/ +/* -------------------- SECURE CONNECTIONS SETUP --------------------------------------*/ +/******************************************************************************************/ +#if defined(CFG_ECC_16_BITS_ALGO) +#define ECC_MULT_ALGO_TYPE (16) +#else // !defined(CFG_ECC_16_BITS_ALGO) +#define ECC_MULT_ALGO_TYPE (32) +#endif // defined(CFG_ECC_16_BITS_ALGO) +#if defined(CFG_CRYPTO_UT) +#define CRYPTO_UT (1) +#else //defined(CFG_CRYPTO_UT) +#define CRYPTO_UT (0) +#endif //defined(CFG_CRYPTO_UT) + +/******************************************************************************************/ +/* -------------------------- DEBUG SETUP ----------------------------------------*/ +/******************************************************************************************/ + +/// Flag indicating if debug mode is activated or not +#if defined(CFG_DBG) + #define RW_DEBUG ((BLE_EMB_PRESENT) || (BT_EMB_PRESENT) || (BLE_HOST_PRESENT)) +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) + #define RW_SWDIAG 1 +#else + #define RW_SWDIAG 0 +#endif + #define KE_PROFILING 1 +#else + #define RW_DEBUG 0 + #define RW_SWDIAG 0 + #define KE_PROFILING 0 +#endif /* CFG_DBG */ + +/// Flag indicating if Read/Write memory commands are supported or not +#if defined(CFG_DBG_MEM) + #define RW_DEBUG_MEM 1 +#else //CFG_DBG_MEM + #define RW_DEBUG_MEM 0 +#endif //CFG_DBG_MEM + +/// Flag indicating if Flash debug commands are supported or not +#if defined(CFG_DBG_FLASH) + #define RW_DEBUG_FLASH 1 +#else //CFG_DBG_FLASH + #define RW_DEBUG_FLASH 0 +#endif //CFG_DBG_FLASH + +/// Flag indicating if CPU stack profiling commands are supported or not +#if defined(CFG_DBG_STACK_PROF) + #define RW_DEBUG_STACK_PROF 1 +#else + #define RW_DEBUG_STACK_PROF 0 +#endif // defined (CFG_DBG_STACK_PROF) + +/// Scheduling Planner unit test (HCI debug commands to test scheduling planner functions) +#define SCH_PLAN_UT (1) + +/// BLE I&Q sample Generator control interface +#define BLE_IQ_GEN (RW_DEBUG && (BLE_CON_CTE_REQ | BLE_CONLESS_CTE_RX)) + + +/******************************************************************************************/ +/* -------------------------- VS SETUP --------------------------------------*/ +/******************************************************************************************/ + +/// Read piconnect clock +#if defined (CFG_BT_READ_PICONET_CLOCK) +#define BT_READ_PICONET_CLOCK 1 +#else +#define BT_READ_PICONET_CLOCK 0 +#endif //defined (CFG_BT_READ_PICONET_CLOCK) + +/******************************************************************************************/ +/* -------------------------- NVDS SETUP --------------------------------------*/ +/******************************************************************************************/ + +/// Flag indicating if NVDS feature is supported or not +#if defined(CFG_NVDS) + #define NVDS_SUPPORT 1 +#else //CFG_DBG_NVDS + #define NVDS_SUPPORT 0 +#endif //CFG_DBG_NVDS + +/******************************************************************************************/ +/* -------------------------- MISC SETUP --------------------------------------*/ +/******************************************************************************************/ +/// Manufacturer: RivieraWaves SAS +#define RW_COMP_ID 0x0060 + +/******************************************************************************************/ +/* ------------------------- BT / BLE / BLE HL CONFIG -------------------------------*/ +/******************************************************************************************/ + +#if (BT_EMB_PRESENT) +#include "rwbt_config.h" // bt stack configuration +#endif //BT_EMB_PRESENT + +#if (BLE_EMB_PRESENT) +#include "rwble_config.h" // ble stack configuration +#endif //BLE_EMB_PRESENT + +#if (BLE_HOST_PRESENT) +#include "rwble_hl_config.h" // ble Host stack configuration +#endif //BLE_HOST_PRESENT + +#if defined(CFG_APP) +#include "rwapp_config.h" // Application configuration +#endif // defined(CFG_APP) + +#if defined(CFG_PRF) +#include "rwprf_config.h" // Application configuration +#endif // defined(CFG_APP) + +/******************************************************************************************/ +/* ------------------------- KERNEL SETUP -------------------------------------*/ +/******************************************************************************************/ + +/// Event types definition +/*@TRACE*/ +enum KE_EVENT_TYPE +{ + #if DISPLAY_SUPPORT + KE_EVENT_DISPLAY, + #endif //DISPLAY_SUPPORT + + #if RTC_SUPPORT + KE_EVENT_RTC_1S_TICK, + #endif //RTC_SUPPORT + + #if BLE_RSA + KE_EVENT_RSA_SIGN, + #endif //BLE_RSA + + KE_EVENT_ECC_MULTIPLICATION, + + #if BT_EMB_PRESENT + KE_EVENT_P192_PUB_KEY_GEN, + #endif // BT_EMB_PRESENT + + #if (BLE_MESH) + KE_EVENT_BLE_MESH_DJOB , + #endif // (BLE_MESH) + + #if (BLE_EMB_PRESENT || BT_EMB_PRESENT) + KE_EVENT_AES_END, + #endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + + KE_EVENT_KE_MESSAGE, + KE_EVENT_KE_TIMER, + + #if (AHI_TL_SUPPORT) + KE_EVENT_AHI_TX_DONE , + #endif //(AHI_TL_SUPPORT) + + + #if (TRACER_PRESENT) + KE_EVENT_TRC, + #endif /*(TRACER_PRESENT)*/ + + #if H4TL_SUPPORT + KE_EVENT_H4TL_TX, + #if (BLE_EMB_PRESENT || BT_EMB_PRESENT) + KE_EVENT_H4TL_CMD_HDR_RX, + KE_EVENT_H4TL_CMD_PLD_RX, + #endif //(BLE_EMB_PRESENT || BT_EMB_PRESENT) + #if (((BLE_EMB_PRESENT || BLE_HOST_PRESENT) && (BLE_CENTRAL || BLE_PERIPHERAL)) || BT_EMB_PRESENT) + KE_EVENT_H4TL_ACL_HDR_RX, + #endif //(((BLE_EMB_PRESENT || BLE_HOST_PRESENT) && (BLE_CENTRAL || BLE_PERIPHERAL)) || BT_EMB_PRESENT) + #endif //H4TL_SUPPORT + + #if (BLE_HOST_PRESENT) + #if (BLE_L2CC) + KE_EVENT_L2CAP_TX, + #endif //(BLE_L2CC) + #endif// (BLE_HOST_PRESENT) + + #if BT_EMB_PRESENT + KE_EVENT_BT_PSCAN_PROC, + #endif //BT_EMB_PRESENT + + #if (BLE_ISOOHCI) + KE_EVENT_ISOOHCI_IN_DEFER, + KE_EVENT_ISOOHCI_OUT_DEFER, + #endif //(BLE_ISOOHCI) + + //KE_EVENT_LSI calib + KE_EVENT_LSI_CALIB, + + KE_EVENT_MAX, +}; + +/// Tasks types definition +/*@TRACE*/ +enum KE_TASK_TYPE +{ + #if (BT_EMB_PRESENT) + // BT Controller Tasks + TASK_LM, + TASK_LC, + TASK_LB, + #endif // (BT_EMB_PRESENT) + + #if (BLE_EMB_PRESENT) + // Link Layer Tasks + TASK_LLM, + TASK_LLC, + #if (BLE_ISO_PRESENT) + TASK_LLI, + #endif // (BLE_ISO_PRESENT) + #endif // (BLE_EMB_PRESENT) + +#if ((BLE_EMB_PRESENT) || (BT_EMB_PRESENT)) + TASK_DBG, +#endif // ((BLE_EMB_PRESENT) || (BT_EMB_PRESENT)) + +#if (DISPLAY_SUPPORT) + TASK_DISPLAY, +#endif // (DISPLAY_SUPPORT) + +#if (BLE_APP_PRESENT) + TASK_APP, +#endif // (BLE_APP_PRESENT) + +#if (BLE_HOST_PRESENT) + TASK_L2CC, // L2CAP Controller Task + TASK_GATTM, // Generic Attribute Profile Manager Task + TASK_GATTC, // Generic Attribute Profile Controller Task + TASK_GAPM, // Generic Access Profile Manager + TASK_GAPC, // Generic Access Profile Controller + + // allocate a certain number of profiles task + TASK_PRF_MAX = (TASK_GAPC + BLE_NB_PROFILES), + + #if (BLE_ISO_MODE_0_PROTOCOL) + TASK_AM0, // BLE Audio Mode 0 Task + #endif // (BLE_ISO_MODE_0_PROTOCOL) +#endif // (BLE_HOST_PRESENT) + +#if (AHI_TL_SUPPORT) + TASK_AHI, +#endif // (AHI_TL_SUPPORT) + + /// Maximum number of tasks + TASK_MAX, + + TASK_NONE = 0xFF, +}; + +/// Kernel memory heaps types. +/*@TRACE*/ +enum KE_MEM_HEAP +{ + /// Memory allocated for environment variables + KE_MEM_ENV, + #if (BLE_HOST_PRESENT) + /// Memory allocated for Attribute database + KE_MEM_ATT_DB, + #endif // (BLE_HOST_PRESENT) + /// Memory allocated for kernel messages + KE_MEM_KE_MSG, + /// Non Retention memory block + KE_MEM_NON_RETENTION, + KE_MEM_BLOCK_MAX, +}; + + + +#if (BT_EMB_PRESENT) +#define BT_HEAP_MSG_SIZE_ BT_HEAP_MSG_SIZE +#define BT_HEAP_ENV_SIZE_ BT_HEAP_ENV_SIZE +#else +#define BT_HEAP_MSG_SIZE_ 0 +#define BT_HEAP_ENV_SIZE_ 0 +#endif //BT_EMB_PRESENT + +#if (BLE_EMB_PRESENT) +#define BLE_HEAP_MSG_SIZE_ BLE_HEAP_MSG_SIZE +#define BLE_HEAP_ENV_SIZE_ BLE_HEAP_ENV_SIZE +#else +#define BLE_HEAP_MSG_SIZE_ 0 +#define BLE_HEAP_ENV_SIZE_ 0 +#endif //BLE_EMB_PRESENT + +#if (BLE_HOST_PRESENT) + +#define BLEHL_HEAP_MSG_SIZE_ BLEHL_HEAP_MSG_SIZE +#define BLEHL_HEAP_ENV_SIZE_ BLEHL_HEAP_ENV_SIZE +#define BLEHL_HEAP_DB_SIZE_ BLEHL_HEAP_DB_SIZE +#else +#define BLEHL_HEAP_MSG_SIZE_ 0 +#define BLEHL_HEAP_ENV_SIZE_ 0 +#define BLEHL_HEAP_DB_SIZE_ 0 +#endif //BLE_HOST_PRESENT + +#if (BT_EMB_PRESENT || BLE_EMB_PRESENT) +#define ECC_HEAP_NON_RET_SIZE_ (328*2) // Could only have 2 ECC computations simultaneously +#else // (BT_EMB_PRESENT || BLE_EMB_PRESENT) +#define ECC_HEAP_NON_RET_SIZE_ 0 +#endif // (BT_EMB_PRESENT || BLE_EMB_PRESENT) + +/// Kernel Message Heap +#define RWIP_HEAP_MSG_SIZE ( BT_HEAP_MSG_SIZE_ + \ + BLE_HEAP_MSG_SIZE_ + \ + BLEHL_HEAP_MSG_SIZE_ ) + +/// Size of Environment heap +#define RWIP_HEAP_ENV_SIZE ( BT_HEAP_ENV_SIZE_ + \ + BLE_HEAP_ENV_SIZE_ + \ + BLEHL_HEAP_ENV_SIZE_ ) + + +/// Size of Attribute database heap +#define RWIP_HEAP_DB_SIZE ( BLEHL_HEAP_DB_SIZE_ ) + +/** + * Size of non-retention heap + * + * This heap can be used to split the RAM into 2 parts: + * - an always-on part that can handle a certain number of links + * - a secondary memory that could be powered-off when not used, and retained only when used + * + * With such mechanism, the previous heaps need to be reduced so that they can contain all required data + * in a light scenario (few connections, few profiles). Then the non-retention heap is sized in order to + * cover the worst case scenario (max connections, max profiles, etc ...) + * + * The current size show what is already known as not needing to be retained during deep sleep. + */ +#define RWIP_HEAP_NON_RET_SIZE ( ECC_HEAP_NON_RET_SIZE_ ) + +//TODO_CHECK VAR +/// Minimum sleep time to enter in deep sleep (in half slot). +#define RWIP_MINIMUM_SLEEP_TIME 16//(10) + +/******************************************************************************************/ +/* ------------------------- CONFIGURABLE PARAMETERS -----------------------------*/ +/******************************************************************************************/ + +/// Bit field definitions for channel assessment enable parameter +enum param_ch_ass_en +{ + /// Indicate channel assessment enabled for BLE + CH_ASS_EN_BLE_POS = 0, + CH_ASS_EN_BLE_BIT = (0x1), + /// Indicate channel assessment enabled for BT + CH_ASS_EN_BT_POS = 1, + CH_ASS_EN_BT_BIT = (0x2), +}; + +/// List of parameters identifiers +enum PARAM_ID +{ + /// Definition of the tag associated to each parameters + /// Local Bd Address + PARAM_ID_BD_ADDRESS = 0x01, + /// Device Name + PARAM_ID_DEVICE_NAME = 0x02, + /// Radio Drift + PARAM_ID_LPCLK_DRIFT = 0x07, + /// Radio Jitter + PARAM_ID_LPCLK_JITTER = 0x08, + /// External wake-up time + PARAM_ID_EXT_WAKEUP_TIME = 0x0D, + /// Oscillator wake-up time + PARAM_ID_OSC_WAKEUP_TIME = 0x0E, + /// Radio wake-up time + PARAM_ID_RM_WAKEUP_TIME = 0x0F, + /// UART baudrate + PARAM_ID_UART_BAUDRATE = 0x10, + /// Enable sleep mode + PARAM_ID_SLEEP_ENABLE = 0x11, + /// Enable External Wakeup + PARAM_ID_EXT_WAKEUP_ENABLE = 0x12, + /// SP Private Key 192 + PARAM_ID_SP_PRIVATE_KEY_P192 = 0x13, + /// SP Public Key 192 + PARAM_ID_SP_PUBLIC_KEY_P192 = 0x14, + + /// Activity Move Configuration (enables/disables activity move for BLE connections and BT (e)SCO links) + PARAM_ID_ACTIVITY_MOVE_CONFIG = 0x15, + + /// Enable/disable scanning for extended advertising PDUs + PARAM_ID_SCAN_EXT_ADV = 0x16, + + /// Duration of the schedule reservation for long activities such as scan, inquiry, page, HDC advertising + PARAM_ID_SCHED_SCAN_DUR = 0x17, + + /// Programming delay, margin for programming the baseband in advance of each activity (in half-slots) + PARAM_ID_PROG_DELAY = 0x18, + + /// Enable/disable channel assessment for BT and/or BLE + PARAM_ID_CH_ASS_EN = 0x19, + + /// Synchronous links configuration + PARAM_ID_SYNC_CONFIG = 0x2C, + /// PCM Settings + PARAM_ID_PCM_SETTINGS = 0x2D, + /// Sleep algorithm duration + PARAM_ID_SLEEP_ALGO_DUR = 0x2E, + /// Tracer configuration + PARAM_ID_TRACER_CONFIG = 0x2F, + + /// Diagport configuration + PARAM_ID_DIAG_BT_HW = 0x30, + PARAM_ID_DIAG_BLE_HW = 0x31, + PARAM_ID_DIAG_SW = 0x32, + PARAM_ID_DIAG_DM_HW = 0x33, + PARAM_ID_DIAG_PLF = 0x34, + + /// IDC selection (for audio demo) + PARAM_ID_IDCSEL_PLF = 0x37, + + /// RSSI threshold tags + PARAM_ID_RSSI_HIGH_THR = 0x3A, + PARAM_ID_RSSI_LOW_THR = 0x3B, + PARAM_ID_RSSI_INTERF_THR = 0x3C, + + /// RF BTIPT + PARAM_ID_RF_BTIPT_VERSION = 0x3E, + PARAM_ID_RF_BTIPT_XO_SETTING = 0x3F, + PARAM_ID_RF_BTIPT_GAIN_SETTING = 0x40, + + PARAM_ID_BT_LINK_KEY_FIRST = 0x60, + PARAM_ID_BT_LINK_KEY_LAST = 0x67, + + PARAM_ID_BLE_LINK_KEY_FIRST = 0x70, + PARAM_ID_BLE_LINK_KEY_LAST = 0x7F, + /// SC Private Key (Low Energy) + PARAM_ID_LE_PRIVATE_KEY_P256 = 0x80, + /// SC Public Key (Low Energy) + PARAM_ID_LE_PUBLIC_KEY_P256 = 0x81, + /// SC Debug: Used Fixed Private Key from NVDS (Low Energy) + PARAM_ID_LE_DBG_FIXED_P256_KEY = 0x82, + /// SP Private Key (classic BT) + PARAM_ID_SP_PRIVATE_KEY_P256 = 0x83, + /// SP Public Key (classic BT) + PARAM_ID_SP_PUBLIC_KEY_P256 = 0x84, + + /// LE Coded PHY 500 Kbps selection + PARAM_ID_LE_CODED_PHY_500 = 0x85, + + /// Application specific + PARAM_ID_APP_SPECIFIC_FIRST = 0x90, + PARAM_ID_APP_SPECIFIC_LAST = 0xAF, + + /// Mesh NVDS values + PARAM_ID_MESH_SPECIFIC_FIRST = 0xB0, + PARAM_ID_MESH_SPECIFIC_LAST = 0xF0, +}; + +/// List of parameters lengths +enum PARAM_LEN +{ + // Definition of length associated to each parameters + /// Local Bd Address + PARAM_LEN_BD_ADDRESS = 6, + /// Device Name + PARAM_LEN_DEVICE_NAME = 248, + /// Low power clock drift + PARAM_LEN_LPCLK_DRIFT = 2, + /// Low power clock jitter + PARAM_LEN_LPCLK_JITTER = 1, + /// External wake-up time + PARAM_LEN_EXT_WAKEUP_TIME = 2, + /// Oscillator wake-up time + PARAM_LEN_OSC_WAKEUP_TIME = 2, + /// Radio wake-up time + PARAM_LEN_RM_WAKEUP_TIME = 2, + /// UART baudrate + PARAM_LEN_UART_BAUDRATE = 4, + /// Enable sleep mode + PARAM_LEN_SLEEP_ENABLE = 1, + /// Enable External Wakeup + PARAM_LEN_EXT_WAKEUP_ENABLE = 1, + /// SP Private Key 192 + PARAM_LEN_SP_PRIVATE_KEY_P192 = 24, + /// SP Public Key 192 + PARAM_LEN_SP_PUBLIC_KEY_P192 = 48, + + /// Activity Move Configuration + PARAM_LEN_ACTIVITY_MOVE_CONFIG = 1, + + /// Enable/disable scanning for extended advertising PDUs + PARAM_LEN_SCAN_EXT_ADV = 1, + + /// Duration of the schedule reservation for long activities such as scan, inquiry, page, HDC advertising + PARAM_LEN_SCHED_SCAN_DUR = 2, + + /// Programming delay, margin for programming the baseband in advance of each activity (in half-slots) + PARAM_LEN_PROG_DELAY = 1, + + /// Enable/disable channel assessment for BT and/or BLE + PARAM_LEN_CH_ASS_EN = 1, + + /// Synchronous links configuration + PARAM_LEN_SYNC_CONFIG = 2, + /// PCM Settings + PARAM_LEN_PCM_SETTINGS = 8, + /// Tracer configuration + PARAM_LEN_TRACER_CONFIG = 4, + + /// Diagport configuration + PARAM_LEN_DIAG_BT_HW = 4, + PARAM_LEN_DIAG_BLE_HW = 4, + PARAM_LEN_DIAG_SW = 4, + PARAM_LEN_DIAG_DM_HW = 4, + PARAM_LEN_DIAG_PLF = 4, + + /// IDC selection (for audio demo) + PARAM_LEN_IDCSEL_PLF = 4, + + /// RSSI thresholds + PARAM_LEN_RSSI_THR = 1, + + /// RF BTIPT + PARAM_LEN_RF_BTIPT_VERSION = 1, + PARAM_LEN_RF_BTIPT_XO_SETTING = 1, + PARAM_LEN_RF_BTIPT_GAIN_SETTING = 2, + + /// Link keys + PARAM_LEN_BT_LINK_KEY = 22, + PARAM_LEN_BLE_LINK_KEY = 48, + + /// P256 + PARAM_LEN_PRIVATE_KEY_P256 = 32, + PARAM_LEN_PUBLIC_KEY_P256 = 64, + PARAM_LEN_DBG_FIXED_P256_KEY = 1, + + /// LE Coded PHY 500 Kbps selection + PARAM_LEN_LE_CODED_PHY_500 = 1, +}; + +/******************************************************************************************/ +/* ------------------------- BT-BLE COEX -----------------------------------*/ +/******************************************************************************************/ + +///To let the HW using the default values set in the registers +#define RW_BLE_PTI_PRIO_AUTO 15 + +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/// Enable and diable definition for the PTI +///Enable TX busy signal +#define RWIP_PTI_TXEN 1 +///Disable TX busy signal +#define RWIP_PTI_TXDIS 0 +/// Tx busy position +#define RWIP_TXBSY_POS 0 + +///Enable RX busy signal +#define RWIP_PTI_RXEN 1 +///Disable RX busy signal +#define RWIP_PTI_RXDIS 0 +/// Rx busy position +#define RWIP_RXBSY_POS 1 + +///Enable do not abort TX +#define RWIP_PTI_DNABORTEN 1 +///Disable do not abort TX +#define RWIP_PTI_DNABORTDIS 0 +/// Do not abort busy position +#define RWIP_DNABORT_POS 2 + +/// SAM disabled +#define RWIP_SAM_DIS 0 +/// SAM enabled +#define RWIP_SAM_EN 1 +/// SAM enable position +#define RWIP_SAMEN_POS 3 + +/// Bit masking +#define RWIP_COEX_BIT_MASK 1 + +/// Coex configuration index +enum rwip_coex_config_idx +{ + #if (BT_EMB_PRESENT) + RWIP_COEX_MSSWITCH_IDX, + RWIP_COEX_SNIFFATT_IDX, + RWIP_COEX_PAGE_IDX, + RWIP_COEX_PSCAN_IDX, + RWIP_COEX_INQ_IDX, + RWIP_COEX_INQRES_IDX, + RWIP_COEX_SCORSVD_IDX, + RWIP_COEX_BCAST_IDX, + RWIP_COEX_CONNECT_IDX, + #endif //#if (BT_EMB_PRESENT) + #if (BLE_EMB_PRESENT) + RWIP_COEX_CON_IDX, + RWIP_COEX_CON_DATA_IDX, + RWIP_COEX_ADV_IDX, + RWIP_COEX_SCAN_IDX, + RWIP_COEX_INIT_IDX, + #endif // #if (BLE_EMB_PRESENT) + /// Max configuration index + RWIP_COEX_CFG_MAX, +}; +#endif //(BLE_EMB_PRESENT || BT_EMB_PRESENT) + +/******************************************************************************************/ +/* ------------------------- BT-BLE PRIORITIES -----------------------------------*/ +/******************************************************************************************/ +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/// Priority index definition +enum rwip_prio_idx +{ + #if (BT_EMB_PRESENT) + /// ACL event default priority + RWIP_PRIO_ACL_DFT_IDX, + /// ACL event priority with activity + RWIP_PRIO_ACL_ACT_IDX, + /// ACL Role Switch event default priority + RWIP_PRIO_ACL_RSW_IDX, + /// ACL sniff event default priority + RWIP_PRIO_ACL_SNIFF_DFT_IDX, + /// ACL sniff transition event default priority + RWIP_PRIO_ACL_SNIFF_TRANS_IDX, + #if MAX_NB_SYNC + /// SCO event default priority + RWIP_PRIO_SCO_DFT_IDX, + #endif //MAX_NB_SYNC + /// Broadcast ACL event default priority + RWIP_PRIO_BCST_DFT_IDX, + /// Broadcast ACL event with LMP activity priority + RWIP_PRIO_BCST_ACT_IDX, + /// CSB RX event default priority + RWIP_PRIO_CSB_RX_DFT_IDX, + /// CSB TX event default priority + RWIP_PRIO_CSB_TX_DFT_IDX, + /// Inquiry event default priority + RWIP_PRIO_INQ_DFT_IDX, + /// Inquiry Scan event default priority + RWIP_PRIO_ISCAN_DFT_IDX, + /// Page event default priority + RWIP_PRIO_PAGE_DFT_IDX, + /// Page event default priority + RWIP_PRIO_PAGE_1ST_PKT_IDX, + /// Page first packet event default priority + RWIP_PRIO_PCA_DFT_IDX, + /// Page scan event default priority + RWIP_PRIO_PSCAN_DFT_IDX, + /// Page scan event priority increment when canceled + RWIP_PRIO_PSCAN_1ST_PKT_IDX, + /// Synchronization Scan event default priority + RWIP_PRIO_SSCAN_DFT_IDX, + /// Synchronization Train event default priority + RWIP_PRIO_STRAIN_DFT_IDX, + #endif //#if (BT_EMB_PRESENT) + #if (BLE_EMB_PRESENT) + /// Default priority for scanning events + RWIP_PRIO_SCAN_IDX, + /// Default priority for auxillary scan/init (no_asap) rx events + RWIP_PRIO_AUX_RX_IDX, + /// Default priority for periodic adv rx events + RWIP_PRIO_PER_ADV_RX_DFT_IDX, + /// Default priority for initiating events + RWIP_PRIO_INIT_IDX, + /// LE connection events default priority + RWIP_PRIO_CONNECT_DFT_IDX, + /// LE connection events priority with activity + RWIP_PRIO_CONNECT_ACT_IDX, + /// Default priority for advertising events + RWIP_PRIO_ADV_IDX, + /// Default priority for advertising high duty cycle events + RWIP_PRIO_ADV_HDC_IDX, + /// Default priority for aux advertising events + RWIP_PRIO_ADV_AUX_IDX, + /// Default priority for periodic advertising events + RWIP_PRIO_PER_ADV_IDX, + /// Default priority for resolvable private addresses renewal event + RWIP_PRIO_RPA_RENEW_IDX, + #endif // #if (BLE_EMB_PRESENT) + RWIP_PRIO_IDX_MAX +}; +/// Default priority value definition +enum rwip_prio_dft +{ + #if (BT_EMB_PRESENT) + /// ACL event default priority + RWIP_PRIO_ACL_DFT = 5, + /// ACL event priority with activity + RWIP_PRIO_ACL_ACT = 10, + /// ACL Role Switch event default priority + RWIP_PRIO_ACL_RSW = 20, + /// ACL sniff event default priority + RWIP_PRIO_ACL_SNIFF_DFT = 15, + /// ACL sniff transition event default priority + RWIP_PRIO_ACL_SNIFF_TRANS = 10, + #if MAX_NB_SYNC + /// SCO event default priority + RWIP_PRIO_SCO_DFT = 18, + #endif //MAX_NB_SYNC + /// Broadcast ACL event default priority + RWIP_PRIO_BCST_DFT = 5, + /// Broadcast ACL event with LMP activity priority + RWIP_PRIO_BCST_ACT = 10, + /// CSB RX event default priority + RWIP_PRIO_CSB_RX_DFT = 10, + /// CSB TX event default priority + RWIP_PRIO_CSB_TX_DFT = 10, + /// Inquiry event default priority + RWIP_PRIO_INQ_DFT = 5, + /// Inquiry Scan event default priority + RWIP_PRIO_ISCAN_DFT = 5, + /// Page event default priority + RWIP_PRIO_PAGE_DFT = 8, + /// Page first packet event default priority + RWIP_PRIO_PAGE_1ST_PKT = 20, + /// PCA event default priority + RWIP_PRIO_PCA_DFT = 20, + /// Page scan event default priority + RWIP_PRIO_PSCAN_DFT = 8, + /// Page scan event priority increment when canceled + RWIP_PRIO_PSCAN_1ST_PKT = 20, + /// Synchronization Scan event default priority + RWIP_PRIO_SSCAN_DFT = 10, + /// Synchronization Train event default priority + RWIP_PRIO_STRAIN_DFT = 10, + #endif //#if (BT_EMB_PRESENT) + #if (BLE_EMB_PRESENT) + /// Default priority for scanning events + RWIP_PRIO_SCAN_DFT = 5, + /// Default priority for auxillary scan/init (no_asap) rx events + RWIP_PRIO_AUX_RX_DFT = 12, + /// Default priority for periodic adv rx events + RWIP_PRIO_PER_ADV_RX_DFT = 16, + /// Active priority for periodic adv rx events + RWIP_PRIO_INIT_DFT = 10, + /// LE connection events default priority + RWIP_PRIO_CONNECT_DFT = 14, + /// LE connection events priority with activity + RWIP_PRIO_CONNECT_ACT = 16, + /// Default priority for advertising events + RWIP_PRIO_ADV_DFT = 5, + /// Default priority for advertising high duty cycle events + RWIP_PRIO_ADV_HDC_DFT = 10, + /// Default priority for aux advertising events + RWIP_PRIO_ADV_AUX_DFT = 12, + /// Default priority for periodic advertising events + RWIP_PRIO_PER_ADV_DFT = 10, + /// Default priority for resolvable private addresses renewal event + RWIP_PRIO_RPA_RENEW_DFT = 10, + #endif // #if (BLE_EMB_PRESENT) + /// Max priority + RWIP_PRIO_MAX = 31, +}; +/// Default increment value definition +enum rwip_incr_dft +{ + #if (BT_EMB_PRESENT) + /// ACL event default increment + RWIP_INCR_ACL_DFT = 1, + /// ACL event increment with activity + RWIP_INCR_ACL_ACT = 1, + /// ACL Role Switch event default increment + RWIP_INCR_ACL_RSW = 1, + /// ACL sniff event default increment + RWIP_INCR_ACL_SNIFF_DFT = 1, + /// ACL sniff transition event default increment + RWIP_INCR_ACL_SNIFF_TRANS = 1, + #if MAX_NB_SYNC + /// SCO event default increment + RWIP_INCR_SCO_DFT = 1, + #endif //MAX_NB_SYNC + /// Broadcast ACL event default increment + RWIP_INCR_BCST_DFT = 1, + /// Broadcast ACL event with LMP activity increment + RWIP_INCR_BCST_ACT = 1, + /// CSB RX event default increment + RWIP_INCR_CSB_RX_DFT = 1, + /// CSB TX event default increment + RWIP_INCR_CSB_TX_DFT = 1, + /// Inquiry event default increment + RWIP_INCR_INQ_DFT = 1, + /// Inquiry Scan event default increment + RWIP_INCR_ISCAN_DFT = 1, + /// Page event default increment + RWIP_INCR_PAGE_DFT = 1, + /// Page event default increment + RWIP_INCR_PAGE_1ST_PKT = 2, + /// Page first packet event default increment + RWIP_INCR_PCA_DFT = 1, + /// Page scan event default increment + RWIP_INCR_PSCAN_DFT = 1, + /// Page scan event increment increment when canceled + RWIP_INCR_PSCAN_1ST_PKT = 1, + /// Synchronization Scan event default increment + RWIP_INCR_SSCAN_DFT = 1, + /// Synchronization Train event default increment + RWIP_INCR_STRAIN_DFT = 1, + #endif //#if (BT_EMB_PRESENT) + #if (BLE_EMB_PRESENT) + /// Default increment for scanning events + RWIP_INCR_SCAN_DFT = 1, + /// Default increment for auxillary scan/init (no_asap) rx events + RWIP_INCR_AUX_RX_DFT = 1, + /// Default increment for periodic adv rx events + RWIP_INCR_PER_ADV_RX_DFT = 1, + /// Default increment for initiating events + RWIP_INCR_INIT_DFT = 1, + /// LE connection events default increment + RWIP_INCR_CONNECT_DFT = 1, + /// LE connection events increment with activity + RWIP_INCR_CONNECT_ACT = 1, + /// Default increment for advertising events + RWIP_INCR_ADV_DFT = 1, + /// Default increment for advertising high duty cycle events + RWIP_INCR_ADV_HDC_PRIO_DFT = 1, + /// Default increment for aux advertising events + RWIP_INCR_ADV_AUX_DFT = 1, + /// Default increment for periodic advertising events + RWIP_INCR_PER_ADV_DFT = 1, + /// Default increment for resolvable private addresses renewal event + RWIP_INCR_RPA_RENEW_DFT = 1, + #endif // #if (BLE_EMB_PRESENT) +}; +#endif //#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/// @} BT Stack Configuration +/// @} ROOT + +#endif //RWIP_CONFIG_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip_int.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip_int.h new file mode 100644 index 0000000..dc0e878 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip_int.h @@ -0,0 +1,101 @@ +/** +**************************************************************************************** +* +* @file rwip_int.h +* +* @brief RW IP internal SW main module +* +* Copyright (C) RivieraWaves 2009-2015 +* +* +**************************************************************************************** +*/ +#ifndef _RWIP_INT_H_ +#define _RWIP_INT_H_ + +/** + **************************************************************************************** + * @addtogroup ROOT + * @brief Entry points of the RW IP stacks/modules + * + * This module contains the primitives that allow an application accessing and running the + * RW IP protocol stacks / modules. + * + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include "rwip_config.h" // stack configuration + +#include // standard integer definitions +#include // standard boolean definitions + + +/* + * DEFINES + **************************************************************************************** + */ + + +/* + * STRUCTURE DEFINITIONS + **************************************************************************************** + */ + +/// RWIP Environment structure +struct rwip_env_tag +{ + #if (BLE_EMB_PRESENT || BT_EMB_PRESENT) + /// Half slot target timer (in half slots) + uint32_t timer_hs_target; + /// Half us target timer (integer part, in half slots) + uint32_t timer_hus_target; + #endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + /// 1 ms target timer (in rwip_time_t) + rwip_time_t timer_1ms_target; + #if (BLE_EMB_PRESENT || BT_EMB_PRESENT) + /// Contains sleep duration accumulated timing error (32kHz: 1/2 half us | 32.768kHz: 1/256 half-us) + uint32_t sleep_acc_error; + /// Power_up delay (in LP clock cycle unit, depends on Low power clock frequency) + uint32_t lp_cycle_wakeup_delay; + /// Duration of sleep and wake-up algorithm (depends on CPU speed) expressed in half us. + uint16_t sleep_algo_dur; + #endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + /// Prevent sleep bit field + uint16_t prevent_sleep; + #if (BLE_EMB_PRESENT || BT_EMB_PRESENT) + /// External wake-up support + bool ext_wakeup_enable; + #endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) +}; + + +/* + * GLOBAL DEFINITIONS + **************************************************************************************** + */ + +/// RW SW environment +extern struct rwip_env_tag rwip_env; + + +/* + * FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + * Initialization of the RW IP Common core driver + * + * @param[in] init_type Type of initialization (@see enum rwip_init_type) + */ +void rwip_driver_init(uint8_t init_type); + + +///@} ROOT + +#endif // _RWIP_INT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip_task.h new file mode 100644 index 0000000..5bdfbcb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api/rwip_task.h @@ -0,0 +1,240 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwip_task.h + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef RWIP_TASK_H_ +#define RWIP_TASK_H_ + +/** + **************************************************************************************** + * @addtogroup ROOT + * @{ + * + * Information about RW SW TASK + * + * @name RW TASK Configuration + * @{ + **************************************************************************************** + */ + +#include + +/* + * DEFINES + **************************************************************************************** + */ + + +/// Build the first message ID of a task. (in fact a ke_msg_id_t) +#define TASK_FIRST_MSG(task) ((uint16_t)((task) << 8)) + +/// Builds the task identifier from the type and the index of that task. +#define TASK_BUILD(type, index) ((uint16_t)(((index) << 8)|(type)) ) + +/// Retrieves task type from task id. +#define TASK_TYPE_GET(ke_task_id) (((uint16_t)ke_task_id) & 0xFF) + +/// Retrieves task index number from task id. +#define TASK_IDX_GET(ke_task_id) ((((uint16_t)ke_task_id) >> 8) & 0xFF) + +/// Message identifier index +#define MSG_ID(task, idx) (TASK_FIRST_MSG((TASK_ID_ ## task)) + idx) + +/// Tasks types definition, this value shall be in [0-254] range +/*@TRACE*/ +enum TASK_API_ID +{ + // ----------------------------------------------------------------------------------- + // ---------------------- Controller Task identifer ---------------------------------- + // ----------------------------------------------------------------------------------- + // Link Layer Tasks + TASK_ID_LLM = 0,//!< TASK_ID_LLM + TASK_ID_LLC = 1,//!< TASK_ID_LLC + TASK_ID_LLD = 2,//!< TASK_ID_LLD + TASK_ID_LLI = 3,//!< TASK_ID_LLI + + TASK_ID_DBG = 4,//!< TASK_ID_DBG + + // BT Controller Tasks + TASK_ID_LM = 5,//!< TASK_ID_LM + TASK_ID_LC = 6,//!< TASK_ID_LC + TASK_ID_LB = 7,//!< TASK_ID_LB + TASK_ID_LD = 8,//!< TASK_ID_LD + + // ----------------------------------------------------------------------------------- + // --------------------- BLE HL TASK API Identifiers --------------------------------- + // --------------------- SHALL NOT BE CHANGED --------------------------------- + // ----------------------------------------------------------------------------------- + + TASK_ID_L2CC = 10, // L2CAP Controller Task + TASK_ID_GATTM = 11, // Generic Attribute Profile Manager Task + TASK_ID_GATTC = 12, // Generic Attribute Profile Controller Task + TASK_ID_GAPM = 13, // Generic Access Profile Manager + TASK_ID_GAPC = 14, // Generic Access Profile Controller + TASK_ID_APP = 15, // Application API + + // ----------------------------------------------------------------------------------- + // --------------------- TRANSPORT AND PLATFORM TASKS -------------------------------- + // ----------------------------------------------------------------------------------- + TASK_ID_AHI = 16, // Application Host Interface + TASK_ID_HCI = 17, //!< TASK_ID_HCI + TASK_ID_DISPLAY = 19, //!< TASK_ID_DISPLAY + + // ----------------------------------------------------------------------------------- + // --------------------- BLE Profile TASK API Identifiers ---------------------------- + // --------------------- SHALL NOT BE CHANGED --------------------------------- + // ----------------------------------------------------------------------------------- + TASK_ID_DISS = 20, // Device Information Service Server Task + TASK_ID_DISC = 21, // Device Information Service Client Task + + TASK_ID_PROXM = 22, // Proximity Monitor Task + TASK_ID_PROXR = 23, // Proximity Reporter Task + + TASK_ID_FINDL = 24, // Find Me Locator Task + TASK_ID_FINDT = 25, // Find Me Target Task + + TASK_ID_HTPC = 26, // Health Thermometer Collector Task + TASK_ID_HTPT = 27, // Health Thermometer Sensor Task + + TASK_ID_BLPS = 28, // Blood Pressure Sensor Task + TASK_ID_BLPC = 29, // Blood Pressure Collector Task + + TASK_ID_HRPS = 30, // Heart Rate Sensor Task + TASK_ID_HRPC = 31, // Heart Rate Collector Task + + TASK_ID_TIPS = 32, // Time Server Task + TASK_ID_TIPC = 33, // Time Client Task + + TASK_ID_SCPPS = 34, // Scan Parameter Profile Server Task + TASK_ID_SCPPC = 35, // Scan Parameter Profile Client Task + + TASK_ID_BASS = 36, // Battery Service Server Task + TASK_ID_BASC = 37, // Battery Service Client Task + + TASK_ID_HOGPD = 38, // HID Device Task + TASK_ID_HOGPBH = 39, // HID Boot Host Task + TASK_ID_HOGPRH = 40, // HID Report Host Task + + TASK_ID_GLPS = 41, // Glucose Profile Sensor Task + TASK_ID_GLPC = 42, // Glucose Profile Collector Task + + TASK_ID_RSCPS = 43, // Running Speed and Cadence Profile Server Task + TASK_ID_RSCPC = 44, // Running Speed and Cadence Profile Collector Task + + TASK_ID_CSCPS = 45, // Cycling Speed and Cadence Profile Server Task + TASK_ID_CSCPC = 46, // Cycling Speed and Cadence Profile Client Task + + TASK_ID_ANPS = 47, // Alert Notification Profile Server Task + TASK_ID_ANPC = 48, // Alert Notification Profile Client Task + + TASK_ID_PASPS = 49, // Phone Alert Status Profile Server Task + TASK_ID_PASPC = 50, // Phone Alert Status Profile Client Task + + TASK_ID_CPPS = 51, // Cycling Power Profile Server Task + TASK_ID_CPPC = 52, // Cycling Power Profile Client Task + + TASK_ID_LANS = 53, // Location and Navigation Profile Server Task + TASK_ID_LANC = 54, // Location and Navigation Profile Client Task + + TASK_ID_IPSS = 55, // Internet Protocol Support Profile Server Task + TASK_ID_IPSC = 56, // Internet Protocol Support Profile Client Task + + TASK_ID_ENVS = 57, // Environmental Sensing Profile Server Task + TASK_ID_ENVC = 58, // Environmental Sensing Profile Client Task + + TASK_ID_WSCS = 59, // Weight Scale Profile Server Task + TASK_ID_WSCC = 60, // Weight Scale Profile Client Task + + TASK_ID_UDSS = 61, // User Data Service Server Task + TASK_ID_UDSC = 62, // User Data Service Client Task + + TASK_ID_BCSS = 63, // Body Composition Server Task + TASK_ID_BCSC = 64, // Body Composition Client Task + + TASK_ID_WPTS = 65, // Wireless Power Transfer Profile Server Task + TASK_ID_WPTC = 66, // Wireless Power Transfer Profile Client Task + + TASK_ID_PLXS = 67, // Pulse Oximeter Profile Server Task + TASK_ID_PLXC = 68, // Pulse Oximeter Profile Client Task + + TASK_ID_CGMS = 69, // Continuous Glucose Monitoring Server Task + TASK_ID_CGMC = 70, // Continuous Glucose Monitoring Client Task + + TASK_ID_RDTSS = 71, // Raw data transfer server task + TASK_ID_RDTSS_16BIT = 72, // Raw data transfer server in 16bit uuid task + + TASK_ID_NS_IUS = 73, + TASK_ID_RDTSC = 74, // Raw data transfer client task + + TASK_ID_ANCC = 75, // Apple Notification Center Service Client Task + TASK_ID_RDTSC_16BIT = 76, // Raw data transfer client in 16bit uuid task + + TASK_ID_MESH = 200, // Mesh Task + + /* 240 -> 241 reserved for Audio Mode 0 */ + TASK_ID_AM0 = 240, // BLE Audio Mode 0 Task + TASK_ID_AM0_HAS = 241, // BLE Audio Mode 0 Hearing Aid Service Task + + + TASK_ID_THPP = 242, // Throughput profile tester used for debugging + + TASK_ID_INVALID = 0xFF, // Invalid Task Identifier +}; + +/// @} BT Stack Configuration +/// @} ROOT + +#endif //RWIP_CONFIG_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_blecore.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_blecore.h new file mode 100644 index 0000000..e271af9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_blecore.h @@ -0,0 +1,10 @@ +#ifndef __REG_BLECORE_H_ +#define __REG_BLECORE_H_ + +#define REG_BLECORE_SIZE 396 + +#define REG_BLECORE_BASE_ADDR 0x50200000 + + +#endif // __REG_BLECORE_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_cs.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_cs.h new file mode 100644 index 0000000..cadce5f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_cs.h @@ -0,0 +1,10 @@ +#ifndef __REG_EM_BLE_CS_H_ +#define __REG_EM_BLE_CS_H_ + +#define REG_EM_BLE_CS_SIZE 112 + +#define REG_EM_BLE_CS_BASE_ADDR EXCHANGE_MEM_BASE + + +#endif // __REG_EM_BLE_CS_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_ral.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_ral.h new file mode 100644 index 0000000..a5b98a5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_ral.h @@ -0,0 +1,10 @@ +#ifndef __REG_EM_BLE_RAL_H_ +#define __REG_EM_BLE_RAL_H_ + +#define REG_EM_BLE_RAL_SIZE 56 + +#define REG_EM_BLE_RAL_BASE_ADDR EXCHANGE_MEM_BASE + + +#endif // __REG_EM_BLE_RAL_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_rx_cte_desc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_rx_cte_desc.h new file mode 100644 index 0000000..2e4cd9d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_rx_cte_desc.h @@ -0,0 +1,10 @@ +#ifndef __REG_EM_BLE_RX_CTE_DESC_H_ +#define __REG_EM_BLE_RX_CTE_DESC_H_ + +#define REG_EM_BLE_RX_CTE_DESC_SIZE 168 + +#define REG_EM_BLE_RX_CTE_DESC_BASE_ADDR EXCHANGE_MEM_BASE + + +#endif // __REG_EM_BLE_RX_CTE_DESC_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_rx_desc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_rx_desc.h new file mode 100644 index 0000000..d5b01af --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_rx_desc.h @@ -0,0 +1,10 @@ +#ifndef __REG_EM_BLE_RX_DESC_H_ +#define __REG_EM_BLE_RX_DESC_H_ + +#define REG_EM_BLE_RX_DESC_SIZE 28 + +#define REG_EM_BLE_RX_DESC_BASE_ADDR EXCHANGE_MEM_BASE + + +#endif // __REG_EM_BLE_RX_DESC_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_tx_desc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_tx_desc.h new file mode 100644 index 0000000..66fbe54 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_tx_desc.h @@ -0,0 +1,10 @@ +#ifndef __REG_EM_BLE_TX_DESC_H_ +#define __REG_EM_BLE_TX_DESC_H_ + +#define REG_EM_BLE_TX_DESC_SIZE 16 + +#define REG_EM_BLE_TX_DESC_BASE_ADDR EXCHANGE_MEM_BASE + + +#endif // __REG_EM_BLE_TX_DESC_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_wpal.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_wpal.h new file mode 100644 index 0000000..6b733d9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_ble_wpal.h @@ -0,0 +1,10 @@ +#ifndef __REG_EM_BLE_WPAL_H_ +#define __REG_EM_BLE_WPAL_H_ + +#define REG_EM_BLE_WPAL_SIZE 12 + +#define REG_EM_BLE_WPAL_BASE_ADDR EXCHANGE_MEM_BASE + + +#endif // __REG_EM_BLE_WPAL_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_et.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_et.h new file mode 100644 index 0000000..80a8dd3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_em_et.h @@ -0,0 +1,10 @@ +#ifndef __REG_EM_ET_H_ +#define __REG_EM_ET_H_ + +#define REG_EM_ET_SIZE 16 + +#define REG_EM_ET_BASE_ADDR EXCHANGE_MEM_BASE + + +#endif // __REG_EM_ET_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_ipcore.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_ipcore.h new file mode 100644 index 0000000..30e1708 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/_reg_ipcore.h @@ -0,0 +1,10 @@ +#ifndef __REG_IPCORE_H_ +#define __REG_IPCORE_H_ + +#define REG_IPCORE_SIZE 392 + +#define REG_IPCORE_BASE_ADDR BASEBAND_REG_BASE + + +#endif // __REG_IPCORE_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_access.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_access.h new file mode 100644 index 0000000..549e3be --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_access.h @@ -0,0 +1,143 @@ +/** + **************************************************************************************** + * + * @file reg_access.h + * + * @brief File implementing the basic primitives for register accesses + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef REG_ACCESS_H_ +#define REG_ACCESS_H_ + +/** + **************************************************************************************** + * @addtogroup REG REG_ACCESS + * @ingroup DRIVERS + * + * @brief Basic primitives for register access + * + * @{ + **************************************************************************************** + */ + + +/* + * INCLUDE FILES + **************************************************************************************** + */ +#include // string functions +#include "n32wb03x.h" + +#if defined(CFG_EMB) +#include "co_utils.h" +#include "em_map.h" // EM Map +#endif // defined(CFG_EMB) +/* + * DEFINES + **************************************************************************************** + */ + +/* + * MACROS + **************************************************************************************** + */ +/// Macro to read a platform register +#define REG_PL_RD(addr) (*(volatile uint32_t *)(addr)) + +/// Macro to write a platform register +#define REG_PL_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value) + +/// Macro to read a BLE register +#define REG_BLE_RD(addr) (*(volatile uint32_t *)(addr)) + +/// Macro to write a BLE register +#define REG_BLE_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value) + +/// Macro to read a BLE control structure field (16-bit wide) +#define EM_BLE_RD(addr) (*(volatile uint16_t *)(addr)) + +/// Macro to write a BLE control structure field (16-bit wide) +#define EM_BLE_WR(addr, value) (*(volatile uint16_t *)(addr)) = (value) + +/// Macro to read a BT register +#define REG_BT_RD(addr) (*(volatile uint32_t *)(addr)) + +/// Macro to write a BT register +#define REG_BT_WR(addr, value) (*(volatile uint32_t *)(addr)) = (value) + +/// Macro to read a BT control structure field (16-bit wide) +#define EM_BT_RD(addr) (*(volatile uint16_t *)(addr)) + +/// Macro to write a BT control structure field (16-bit wide) +#define EM_BT_WR(addr, value) (*(volatile uint16_t *)(addr)) = (value) + +/// Macro to read a EM field (16-bit wide) +#define EM_RD(addr) (*(volatile uint16_t *)(addr)) + +/// Macro to write a EM field (16-bit wide) +#define EM_WR(addr, value) (*(volatile uint16_t *)(addr)) = (value) +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +#if (defined(CFG_BT) || (defined(CFG_BLE) && defined(CFG_EMB))) +/// Read bytes from EM +__INLINE void em_rd(void *sys_addr, uint16_t em_addr, uint16_t len) +{ + memcpy(sys_addr, (void *)(em_addr + EM_BASE_ADDR), len); +} +/// Write bytes to EM +__INLINE void em_wr(void const *sys_addr, uint16_t em_addr, uint16_t len) +{ + memcpy((void *)(em_addr + EM_BASE_ADDR), sys_addr, len); +} + +/// Fill an EM space with the same value +__INLINE void em_set(int value, uint16_t em_addr, uint16_t len) +{ + memset((void *)(em_addr + EM_BASE_ADDR), value, len); +} + +/// Read 32-bits value from EM +__INLINE uint32_t em_rd32p(uint16_t em_addr) +{ + return co_read32p((void *)(em_addr + EM_BASE_ADDR)); +} +/// Write 32-bits value to EM +__INLINE void em_wr32p(uint16_t em_addr, uint32_t value) +{ + co_write32p((void *)(em_addr + EM_BASE_ADDR), value); +} + +/// Read 16-bits value from EM +__INLINE uint16_t em_rd16p(uint16_t em_addr) +{ + return co_read16p((void *)(em_addr + EM_BASE_ADDR)); +} +/// Write 16-bits value to EM +static __INLINE void em_wr16p(uint16_t em_addr, uint16_t value) +{ + co_write16p((void *)(em_addr + EM_BASE_ADDR), value); +} + +/// Read 8-bits value from EM +__INLINE uint8_t em_rd8p(uint16_t em_addr) +{ + return *((uint8_t *)(em_addr + EM_BASE_ADDR)); +} +/// Write 8-bits value to EM +__INLINE void em_wr8p(uint16_t em_addr, uint8_t value) +{ + *(uint8_t *)(em_addr + EM_BASE_ADDR) = value; +} +#endif // (defined(CFG_BT) || (defined(CFG_BLE) && defined(CFG_EMB))) + +/// @} REG + +#endif // REG_ACCESS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_blecore.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_blecore.h new file mode 100644 index 0000000..5cf9297 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_blecore.h @@ -0,0 +1,8744 @@ +#ifndef _REG_BLECORE_H_ +#define _REG_BLECORE_H_ + +#include +#include "_reg_blecore.h" +#include "compiler.h" +#include "arch.h" +#include "reg_access.h" + +#define REG_BLECORE_COUNT 99 + +#define REG_BLECORE_DECODING_MASK 0x000001FF + +/** + * @brief RWBLECNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31      MASTER_SOFT_RST   0
+ *     30    MASTER_TGSOFT_RST   0
+ *     29         REG_SOFT_RST   0
+ *     28   RADIOCNTL_SOFT_RST   0
+ *     27            SWINT_REQ   0
+ *     26         RFTEST_ABORT   0
+ *     25         ADVERT_ABORT   0
+ *     24           SCAN_ABORT   0
+ *     20               MD_DSB   0
+ *     19               SN_DSB   0
+ *     18             NESN_DSB   0
+ *     17            CRYPT_DSB   0
+ *     16           LRPMAP_DSB   0
+ *     15            LRFEC_DSB   0
+ *     14             WHIT_DSB   0
+ *     13              CRC_DSB   0
+ *     12        HOP_REMAP_DSB   0
+ *     11     RXCTEERR_RETX_EN   0
+ *     10   ANONYMOUS_ADV_FILT_EN   0
+ *     09        ADVERTFILT_EN   0
+ *     08             RWBLE_EN   0
+ *  03:00           RXWINSZDEF   0x0
+ * 
+ */ +#define BLE_RWBLECNTL_ADDR BASEBAND_REG_BASE +0x0 // 0x50800000 +#define BLE_RWBLECNTL_OFFSET 0x00000000 +#define BLE_RWBLECNTL_INDEX 0x00000000 +#define BLE_RWBLECNTL_RESET 0x00000000 + +__INLINE uint32_t ble_rwblecntl_get(void) +{ + return REG_BLE_RD(BLE_RWBLECNTL_ADDR); +} + +__INLINE void ble_rwblecntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_RWBLECNTL_ADDR, value); +} + +// field definitions +#define BLE_MASTER_SOFT_RST_BIT ((uint32_t)0x80000000) +#define BLE_MASTER_SOFT_RST_POS 31 +#define BLE_MASTER_TGSOFT_RST_BIT ((uint32_t)0x40000000) +#define BLE_MASTER_TGSOFT_RST_POS 30 +#define BLE_REG_SOFT_RST_BIT ((uint32_t)0x20000000) +#define BLE_REG_SOFT_RST_POS 29 +#define BLE_RADIOCNTL_SOFT_RST_BIT ((uint32_t)0x10000000) +#define BLE_RADIOCNTL_SOFT_RST_POS 28 +#define BLE_SWINT_REQ_BIT ((uint32_t)0x08000000) +#define BLE_SWINT_REQ_POS 27 +#define BLE_RFTEST_ABORT_BIT ((uint32_t)0x04000000) +#define BLE_RFTEST_ABORT_POS 26 +#define BLE_ADVERT_ABORT_BIT ((uint32_t)0x02000000) +#define BLE_ADVERT_ABORT_POS 25 +#define BLE_SCAN_ABORT_BIT ((uint32_t)0x01000000) +#define BLE_SCAN_ABORT_POS 24 +#define BLE_MD_DSB_BIT ((uint32_t)0x00100000) +#define BLE_MD_DSB_POS 20 +#define BLE_SN_DSB_BIT ((uint32_t)0x00080000) +#define BLE_SN_DSB_POS 19 +#define BLE_NESN_DSB_BIT ((uint32_t)0x00040000) +#define BLE_NESN_DSB_POS 18 +#define BLE_CRYPT_DSB_BIT ((uint32_t)0x00020000) +#define BLE_CRYPT_DSB_POS 17 +#define BLE_LRPMAP_DSB_BIT ((uint32_t)0x00010000) +#define BLE_LRPMAP_DSB_POS 16 +#define BLE_LRFEC_DSB_BIT ((uint32_t)0x00008000) +#define BLE_LRFEC_DSB_POS 15 +#define BLE_WHIT_DSB_BIT ((uint32_t)0x00004000) +#define BLE_WHIT_DSB_POS 14 +#define BLE_CRC_DSB_BIT ((uint32_t)0x00002000) +#define BLE_CRC_DSB_POS 13 +#define BLE_HOP_REMAP_DSB_BIT ((uint32_t)0x00001000) +#define BLE_HOP_REMAP_DSB_POS 12 +#define BLE_RXCTEERR_RETX_EN_BIT ((uint32_t)0x00000800) +#define BLE_RXCTEERR_RETX_EN_POS 11 +#define BLE_ANONYMOUS_ADV_FILT_EN_BIT ((uint32_t)0x00000400) +#define BLE_ANONYMOUS_ADV_FILT_EN_POS 10 +#define BLE_ADVERTFILT_EN_BIT ((uint32_t)0x00000200) +#define BLE_ADVERTFILT_EN_POS 9 +#define BLE_RWBLE_EN_BIT ((uint32_t)0x00000100) +#define BLE_RWBLE_EN_POS 8 +#define BLE_RXWINSZDEF_MASK ((uint32_t)0x0000000F) +#define BLE_RXWINSZDEF_LSB 0 +#define BLE_RXWINSZDEF_WIDTH ((uint32_t)0x00000004) + +#define BLE_MASTER_SOFT_RST_RST 0x0 +#define BLE_MASTER_TGSOFT_RST_RST 0x0 +#define BLE_REG_SOFT_RST_RST 0x0 +#define BLE_RADIOCNTL_SOFT_RST_RST 0x0 +#define BLE_SWINT_REQ_RST 0x0 +#define BLE_RFTEST_ABORT_RST 0x0 +#define BLE_ADVERT_ABORT_RST 0x0 +#define BLE_SCAN_ABORT_RST 0x0 +#define BLE_MD_DSB_RST 0x0 +#define BLE_SN_DSB_RST 0x0 +#define BLE_NESN_DSB_RST 0x0 +#define BLE_CRYPT_DSB_RST 0x0 +#define BLE_LRPMAP_DSB_RST 0x0 +#define BLE_LRFEC_DSB_RST 0x0 +#define BLE_WHIT_DSB_RST 0x0 +#define BLE_CRC_DSB_RST 0x0 +#define BLE_HOP_REMAP_DSB_RST 0x0 +#define BLE_RXCTEERR_RETX_EN_RST 0x0 +#define BLE_ANONYMOUS_ADV_FILT_EN_RST 0x0 +#define BLE_ADVERTFILT_EN_RST 0x0 +#define BLE_RWBLE_EN_RST 0x0 +#define BLE_RXWINSZDEF_RST 0x0 + +__INLINE void ble_rwblecntl_pack(uint8_t mastersoftrst, uint8_t mastertgsoftrst, uint8_t regsoftrst, uint8_t radiocntlsoftrst, uint8_t swintreq, uint8_t rftestabort, uint8_t advertabort, uint8_t scanabort, uint8_t mddsb, uint8_t sndsb, uint8_t nesndsb, uint8_t cryptdsb, uint8_t lrpmapdsb, uint8_t lrfecdsb, uint8_t whitdsb, uint8_t crcdsb, uint8_t hopremapdsb, uint8_t rxcteerrretxen, uint8_t anonymousadvfilten, uint8_t advertfilten, uint8_t rwbleen, uint8_t rxwinszdef) +{ + ASSERT_ERR((((uint32_t)mastersoftrst << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)mastertgsoftrst << 30) & ~((uint32_t)0x40000000)) == 0); + ASSERT_ERR((((uint32_t)regsoftrst << 29) & ~((uint32_t)0x20000000)) == 0); + ASSERT_ERR((((uint32_t)radiocntlsoftrst << 28) & ~((uint32_t)0x10000000)) == 0); + ASSERT_ERR((((uint32_t)swintreq << 27) & ~((uint32_t)0x08000000)) == 0); + ASSERT_ERR((((uint32_t)rftestabort << 26) & ~((uint32_t)0x04000000)) == 0); + ASSERT_ERR((((uint32_t)advertabort << 25) & ~((uint32_t)0x02000000)) == 0); + ASSERT_ERR((((uint32_t)scanabort << 24) & ~((uint32_t)0x01000000)) == 0); + ASSERT_ERR((((uint32_t)mddsb << 20) & ~((uint32_t)0x00100000)) == 0); + ASSERT_ERR((((uint32_t)sndsb << 19) & ~((uint32_t)0x00080000)) == 0); + ASSERT_ERR((((uint32_t)nesndsb << 18) & ~((uint32_t)0x00040000)) == 0); + ASSERT_ERR((((uint32_t)cryptdsb << 17) & ~((uint32_t)0x00020000)) == 0); + ASSERT_ERR((((uint32_t)lrpmapdsb << 16) & ~((uint32_t)0x00010000)) == 0); + ASSERT_ERR((((uint32_t)lrfecdsb << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)whitdsb << 14) & ~((uint32_t)0x00004000)) == 0); + ASSERT_ERR((((uint32_t)crcdsb << 13) & ~((uint32_t)0x00002000)) == 0); + ASSERT_ERR((((uint32_t)hopremapdsb << 12) & ~((uint32_t)0x00001000)) == 0); + ASSERT_ERR((((uint32_t)rxcteerrretxen << 11) & ~((uint32_t)0x00000800)) == 0); + ASSERT_ERR((((uint32_t)anonymousadvfilten << 10) & ~((uint32_t)0x00000400)) == 0); + ASSERT_ERR((((uint32_t)advertfilten << 9) & ~((uint32_t)0x00000200)) == 0); + ASSERT_ERR((((uint32_t)rwbleen << 8) & ~((uint32_t)0x00000100)) == 0); + ASSERT_ERR((((uint32_t)rxwinszdef << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, ((uint32_t)mastersoftrst << 31) | ((uint32_t)mastertgsoftrst << 30) | ((uint32_t)regsoftrst << 29) | ((uint32_t)radiocntlsoftrst << 28) | ((uint32_t)swintreq << 27) | ((uint32_t)rftestabort << 26) | ((uint32_t)advertabort << 25) | ((uint32_t)scanabort << 24) | ((uint32_t)mddsb << 20) | ((uint32_t)sndsb << 19) | ((uint32_t)nesndsb << 18) | ((uint32_t)cryptdsb << 17) | ((uint32_t)lrpmapdsb << 16) | ((uint32_t)lrfecdsb << 15) | ((uint32_t)whitdsb << 14) | ((uint32_t)crcdsb << 13) | ((uint32_t)hopremapdsb << 12) | ((uint32_t)rxcteerrretxen << 11) | ((uint32_t)anonymousadvfilten << 10) | ((uint32_t)advertfilten << 9) | ((uint32_t)rwbleen << 8) | ((uint32_t)rxwinszdef << 0)); +} + +__INLINE void ble_rwblecntl_unpack(uint8_t* mastersoftrst, uint8_t* mastertgsoftrst, uint8_t* regsoftrst, uint8_t* radiocntlsoftrst, uint8_t* swintreq, uint8_t* rftestabort, uint8_t* advertabort, uint8_t* scanabort, uint8_t* mddsb, uint8_t* sndsb, uint8_t* nesndsb, uint8_t* cryptdsb, uint8_t* lrpmapdsb, uint8_t* lrfecdsb, uint8_t* whitdsb, uint8_t* crcdsb, uint8_t* hopremapdsb, uint8_t* rxcteerrretxen, uint8_t* anonymousadvfilten, uint8_t* advertfilten, uint8_t* rwbleen, uint8_t* rxwinszdef) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + + *mastersoftrst = (localVal & ((uint32_t)0x80000000)) >> 31; + *mastertgsoftrst = (localVal & ((uint32_t)0x40000000)) >> 30; + *regsoftrst = (localVal & ((uint32_t)0x20000000)) >> 29; + *radiocntlsoftrst = (localVal & ((uint32_t)0x10000000)) >> 28; + *swintreq = (localVal & ((uint32_t)0x08000000)) >> 27; + *rftestabort = (localVal & ((uint32_t)0x04000000)) >> 26; + *advertabort = (localVal & ((uint32_t)0x02000000)) >> 25; + *scanabort = (localVal & ((uint32_t)0x01000000)) >> 24; + *mddsb = (localVal & ((uint32_t)0x00100000)) >> 20; + *sndsb = (localVal & ((uint32_t)0x00080000)) >> 19; + *nesndsb = (localVal & ((uint32_t)0x00040000)) >> 18; + *cryptdsb = (localVal & ((uint32_t)0x00020000)) >> 17; + *lrpmapdsb = (localVal & ((uint32_t)0x00010000)) >> 16; + *lrfecdsb = (localVal & ((uint32_t)0x00008000)) >> 15; + *whitdsb = (localVal & ((uint32_t)0x00004000)) >> 14; + *crcdsb = (localVal & ((uint32_t)0x00002000)) >> 13; + *hopremapdsb = (localVal & ((uint32_t)0x00001000)) >> 12; + *rxcteerrretxen = (localVal & ((uint32_t)0x00000800)) >> 11; + *anonymousadvfilten = (localVal & ((uint32_t)0x00000400)) >> 10; + *advertfilten = (localVal & ((uint32_t)0x00000200)) >> 9; + *rwbleen = (localVal & ((uint32_t)0x00000100)) >> 8; + *rxwinszdef = (localVal & ((uint32_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t ble_rwblecntl_master_soft_rst_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_rwblecntl_master_soft_rst_setf(uint8_t mastersoftrst) +{ + ASSERT_ERR((((uint32_t)mastersoftrst << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)mastersoftrst << 31)); +} + +__INLINE uint8_t ble_rwblecntl_master_tgsoft_rst_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x40000000)) >> 30); +} + +__INLINE void ble_rwblecntl_master_tgsoft_rst_setf(uint8_t mastertgsoftrst) +{ + ASSERT_ERR((((uint32_t)mastertgsoftrst << 30) & ~((uint32_t)0x40000000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x40000000)) | ((uint32_t)mastertgsoftrst << 30)); +} + +__INLINE uint8_t ble_rwblecntl_reg_soft_rst_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x20000000)) >> 29); +} + +__INLINE void ble_rwblecntl_reg_soft_rst_setf(uint8_t regsoftrst) +{ + ASSERT_ERR((((uint32_t)regsoftrst << 29) & ~((uint32_t)0x20000000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x20000000)) | ((uint32_t)regsoftrst << 29)); +} + +__INLINE uint8_t ble_rwblecntl_radiocntl_soft_rst_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x10000000)) >> 28); +} + +__INLINE void ble_rwblecntl_radiocntl_soft_rst_setf(uint8_t radiocntlsoftrst) +{ + ASSERT_ERR((((uint32_t)radiocntlsoftrst << 28) & ~((uint32_t)0x10000000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x10000000)) | ((uint32_t)radiocntlsoftrst << 28)); +} + +__INLINE uint8_t ble_rwblecntl_swint_req_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x08000000)) >> 27); +} + +__INLINE void ble_rwblecntl_swint_req_setf(uint8_t swintreq) +{ + ASSERT_ERR((((uint32_t)swintreq << 27) & ~((uint32_t)0x08000000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x08000000)) | ((uint32_t)swintreq << 27)); +} + +__INLINE uint8_t ble_rwblecntl_rftest_abort_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x04000000)) >> 26); +} + +__INLINE void ble_rwblecntl_rftest_abort_setf(uint8_t rftestabort) +{ + ASSERT_ERR((((uint32_t)rftestabort << 26) & ~((uint32_t)0x04000000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x04000000)) | ((uint32_t)rftestabort << 26)); +} + +__INLINE uint8_t ble_rwblecntl_advert_abort_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x02000000)) >> 25); +} + +__INLINE void ble_rwblecntl_advert_abort_setf(uint8_t advertabort) +{ + ASSERT_ERR((((uint32_t)advertabort << 25) & ~((uint32_t)0x02000000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x02000000)) | ((uint32_t)advertabort << 25)); +} + +__INLINE uint8_t ble_rwblecntl_scan_abort_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x01000000)) >> 24); +} + +__INLINE void ble_rwblecntl_scan_abort_setf(uint8_t scanabort) +{ + ASSERT_ERR((((uint32_t)scanabort << 24) & ~((uint32_t)0x01000000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x01000000)) | ((uint32_t)scanabort << 24)); +} + +__INLINE uint8_t ble_rwblecntl_md_dsb_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00100000)) >> 20); +} + +__INLINE void ble_rwblecntl_md_dsb_setf(uint8_t mddsb) +{ + ASSERT_ERR((((uint32_t)mddsb << 20) & ~((uint32_t)0x00100000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00100000)) | ((uint32_t)mddsb << 20)); +} + +__INLINE uint8_t ble_rwblecntl_sn_dsb_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00080000)) >> 19); +} + +__INLINE void ble_rwblecntl_sn_dsb_setf(uint8_t sndsb) +{ + ASSERT_ERR((((uint32_t)sndsb << 19) & ~((uint32_t)0x00080000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00080000)) | ((uint32_t)sndsb << 19)); +} + +__INLINE uint8_t ble_rwblecntl_nesn_dsb_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00040000)) >> 18); +} + +__INLINE void ble_rwblecntl_nesn_dsb_setf(uint8_t nesndsb) +{ + ASSERT_ERR((((uint32_t)nesndsb << 18) & ~((uint32_t)0x00040000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00040000)) | ((uint32_t)nesndsb << 18)); +} + +__INLINE uint8_t ble_rwblecntl_crypt_dsb_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00020000)) >> 17); +} + +__INLINE void ble_rwblecntl_crypt_dsb_setf(uint8_t cryptdsb) +{ + ASSERT_ERR((((uint32_t)cryptdsb << 17) & ~((uint32_t)0x00020000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00020000)) | ((uint32_t)cryptdsb << 17)); +} + +__INLINE uint8_t ble_rwblecntl_lrpmap_dsb_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00010000)) >> 16); +} + +__INLINE void ble_rwblecntl_lrpmap_dsb_setf(uint8_t lrpmapdsb) +{ + ASSERT_ERR((((uint32_t)lrpmapdsb << 16) & ~((uint32_t)0x00010000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00010000)) | ((uint32_t)lrpmapdsb << 16)); +} + +__INLINE uint8_t ble_rwblecntl_lrfec_dsb_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ble_rwblecntl_lrfec_dsb_setf(uint8_t lrfecdsb) +{ + ASSERT_ERR((((uint32_t)lrfecdsb << 15) & ~((uint32_t)0x00008000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)lrfecdsb << 15)); +} + +__INLINE uint8_t ble_rwblecntl_whit_dsb_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00004000)) >> 14); +} + +__INLINE void ble_rwblecntl_whit_dsb_setf(uint8_t whitdsb) +{ + ASSERT_ERR((((uint32_t)whitdsb << 14) & ~((uint32_t)0x00004000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00004000)) | ((uint32_t)whitdsb << 14)); +} + +__INLINE uint8_t ble_rwblecntl_crc_dsb_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00002000)) >> 13); +} + +__INLINE void ble_rwblecntl_crc_dsb_setf(uint8_t crcdsb) +{ + ASSERT_ERR((((uint32_t)crcdsb << 13) & ~((uint32_t)0x00002000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00002000)) | ((uint32_t)crcdsb << 13)); +} + +__INLINE uint8_t ble_rwblecntl_hop_remap_dsb_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00001000)) >> 12); +} + +__INLINE void ble_rwblecntl_hop_remap_dsb_setf(uint8_t hopremapdsb) +{ + ASSERT_ERR((((uint32_t)hopremapdsb << 12) & ~((uint32_t)0x00001000)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00001000)) | ((uint32_t)hopremapdsb << 12)); +} + +__INLINE uint8_t ble_rwblecntl_rxcteerr_retx_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00000800)) >> 11); +} + +__INLINE void ble_rwblecntl_rxcteerr_retx_en_setf(uint8_t rxcteerrretxen) +{ + ASSERT_ERR((((uint32_t)rxcteerrretxen << 11) & ~((uint32_t)0x00000800)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00000800)) | ((uint32_t)rxcteerrretxen << 11)); +} + +__INLINE uint8_t ble_rwblecntl_anonymous_adv_filt_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00000400)) >> 10); +} + +__INLINE void ble_rwblecntl_anonymous_adv_filt_en_setf(uint8_t anonymousadvfilten) +{ + ASSERT_ERR((((uint32_t)anonymousadvfilten << 10) & ~((uint32_t)0x00000400)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00000400)) | ((uint32_t)anonymousadvfilten << 10)); +} + +__INLINE uint8_t ble_rwblecntl_advertfilt_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00000200)) >> 9); +} + +__INLINE void ble_rwblecntl_advertfilt_en_setf(uint8_t advertfilten) +{ + ASSERT_ERR((((uint32_t)advertfilten << 9) & ~((uint32_t)0x00000200)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00000200)) | ((uint32_t)advertfilten << 9)); +} + +__INLINE uint8_t ble_rwblecntl_rwble_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x00000100)) >> 8); +} + +__INLINE void ble_rwblecntl_rwble_en_setf(uint8_t rwbleen) +{ + ASSERT_ERR((((uint32_t)rwbleen << 8) & ~((uint32_t)0x00000100)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x00000100)) | ((uint32_t)rwbleen << 8)); +} + +__INLINE uint8_t ble_rwblecntl_rxwinszdef_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECNTL_ADDR); + return ((localVal & ((uint32_t)0x0000000F)) >> 0); +} + +__INLINE void ble_rwblecntl_rxwinszdef_setf(uint8_t rxwinszdef) +{ + ASSERT_ERR((((uint32_t)rxwinszdef << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_RWBLECNTL_ADDR, (REG_BLE_RD(BLE_RWBLECNTL_ADDR) & ~((uint32_t)0x0000000F)) | ((uint32_t)rxwinszdef << 0)); +} + +/** + * @brief VERSION register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24                  TYP   0xA
+ *  23:16                  REL   0x0
+ *  15:08                  UPG   0xD
+ *  07:00                BUILD   0x0
+ * 
+ */ +#define BLE_VERSION_ADDR BASEBAND_REG_BASE +0x4 // 0x50800004 +#define BLE_VERSION_OFFSET 0x00000004 +#define BLE_VERSION_INDEX 0x00000001 +#define BLE_VERSION_RESET 0x0A000D00 + +__INLINE uint32_t ble_version_get(void) +{ + return REG_BLE_RD(BLE_VERSION_ADDR); +} + +// field definitions +#define BLE_TYP_MASK ((uint32_t)0xFF000000) +#define BLE_TYP_LSB 24 +#define BLE_TYP_WIDTH ((uint32_t)0x00000008) +#define BLE_REL_MASK ((uint32_t)0x00FF0000) +#define BLE_REL_LSB 16 +#define BLE_REL_WIDTH ((uint32_t)0x00000008) +#define BLE_UPG_MASK ((uint32_t)0x0000FF00) +#define BLE_UPG_LSB 8 +#define BLE_UPG_WIDTH ((uint32_t)0x00000008) +#define BLE_BUILD_MASK ((uint32_t)0x000000FF) +#define BLE_BUILD_LSB 0 +#define BLE_BUILD_WIDTH ((uint32_t)0x00000008) + +#define BLE_TYP_RST 0xA +#define BLE_REL_RST 0x0 +#define BLE_UPG_RST 0xD +#define BLE_BUILD_RST 0x0 + +__INLINE void ble_version_unpack(uint8_t* typ, uint8_t* rel, uint8_t* upg, uint8_t* build) +{ + uint32_t localVal = REG_BLE_RD(BLE_VERSION_ADDR); + + *typ = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rel = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *upg = (localVal & ((uint32_t)0x0000FF00)) >> 8; + *build = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_version_typ_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_VERSION_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE uint8_t ble_version_rel_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_VERSION_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE uint8_t ble_version_upg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_VERSION_ADDR); + return ((localVal & ((uint32_t)0x0000FF00)) >> 8); +} + +__INLINE uint8_t ble_version_build_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_VERSION_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +/** + * @brief RWBLECONF register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31               DMMODE   0
+ *     28           CORRELATOR   1
+ *     27              USERXLR   1
+ *     26              USETXLR   1
+ *     24               USEISO   1
+ *     21             WLANCOEX   1
+ *  20:16                 RFIF   0x1
+ *     15               USEDBG   1
+ *     14             DECIPHER   0
+ *  13:08              CLK_SEL   0x8
+ *     07              INTMODE   1
+ *     06             BUS_TYPE   0
+ *  04:00           ADDR_WIDTH   0xD
+ * 
+ */ +#define BLE_RWBLECONF_ADDR BASEBAND_REG_BASE +0x8 //0x50800008 +#define BLE_RWBLECONF_OFFSET 0x00000008 +#define BLE_RWBLECONF_INDEX 0x00000002 +#define BLE_RWBLECONF_RESET 0x1D21888D + +__INLINE uint32_t ble_rwbleconf_get(void) +{ + return REG_BLE_RD(BLE_RWBLECONF_ADDR); +} + +// field definitions +#define BLE_DMMODE_BIT ((uint32_t)0x80000000) +#define BLE_DMMODE_POS 31 +#define BLE_CORRELATOR_BIT ((uint32_t)0x10000000) +#define BLE_CORRELATOR_POS 28 +#define BLE_USERXLR_BIT ((uint32_t)0x08000000) +#define BLE_USERXLR_POS 27 +#define BLE_USETXLR_BIT ((uint32_t)0x04000000) +#define BLE_USETXLR_POS 26 +#define BLE_USEISO_BIT ((uint32_t)0x01000000) +#define BLE_USEISO_POS 24 +#define BLE_WLANCOEX_BIT ((uint32_t)0x00200000) +#define BLE_WLANCOEX_POS 21 +#define BLE_RFIF_MASK ((uint32_t)0x001F0000) +#define BLE_RFIF_LSB 16 +#define BLE_RFIF_WIDTH ((uint32_t)0x00000005) +#define BLE_USEDBG_BIT ((uint32_t)0x00008000) +#define BLE_USEDBG_POS 15 +#define BLE_DECIPHER_BIT ((uint32_t)0x00004000) +#define BLE_DECIPHER_POS 14 +#define BLE_CLK_SEL_MASK ((uint32_t)0x00003F00) +#define BLE_CLK_SEL_LSB 8 +#define BLE_CLK_SEL_WIDTH ((uint32_t)0x00000006) +#define BLE_INTMODE_BIT ((uint32_t)0x00000080) +#define BLE_INTMODE_POS 7 +#define BLE_BUS_TYPE_BIT ((uint32_t)0x00000040) +#define BLE_BUS_TYPE_POS 6 +#define BLE_ADDR_WIDTH_MASK ((uint32_t)0x0000001F) +#define BLE_ADDR_WIDTH_LSB 0 +#define BLE_ADDR_WIDTH_WIDTH ((uint32_t)0x00000005) + +#define BLE_DMMODE_RST 0x0 +#define BLE_CORRELATOR_RST 0x1 +#define BLE_USERXLR_RST 0x1 +#define BLE_USETXLR_RST 0x1 +#define BLE_USEISO_RST 0x1 +#define BLE_WLANCOEX_RST 0x1 +#define BLE_RFIF_RST 0x1 +#define BLE_USEDBG_RST 0x1 +#define BLE_DECIPHER_RST 0x0 +#define BLE_CLK_SEL_RST 0x8 +#define BLE_INTMODE_RST 0x1 +#define BLE_BUS_TYPE_RST 0x0 +#define BLE_ADDR_WIDTH_RST 0xD + +__INLINE void ble_rwbleconf_unpack(uint8_t* dmmode, uint8_t* correlator, uint8_t* userxlr, uint8_t* usetxlr, uint8_t* useiso, uint8_t* wlancoex, uint8_t* rfif, uint8_t* usedbg, uint8_t* decipher, uint8_t* clksel, uint8_t* intmode, uint8_t* bustype, uint8_t* addrwidth) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + + *dmmode = (localVal & ((uint32_t)0x80000000)) >> 31; + *correlator = (localVal & ((uint32_t)0x10000000)) >> 28; + *userxlr = (localVal & ((uint32_t)0x08000000)) >> 27; + *usetxlr = (localVal & ((uint32_t)0x04000000)) >> 26; + *useiso = (localVal & ((uint32_t)0x01000000)) >> 24; + *wlancoex = (localVal & ((uint32_t)0x00200000)) >> 21; + *rfif = (localVal & ((uint32_t)0x001F0000)) >> 16; + *usedbg = (localVal & ((uint32_t)0x00008000)) >> 15; + *decipher = (localVal & ((uint32_t)0x00004000)) >> 14; + *clksel = (localVal & ((uint32_t)0x00003F00)) >> 8; + *intmode = (localVal & ((uint32_t)0x00000080)) >> 7; + *bustype = (localVal & ((uint32_t)0x00000040)) >> 6; + *addrwidth = (localVal & ((uint32_t)0x0000001F)) >> 0; +} + +__INLINE uint8_t ble_rwbleconf_dmmode_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE uint8_t ble_rwbleconf_correlator_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x10000000)) >> 28); +} + +__INLINE uint8_t ble_rwbleconf_userxlr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x08000000)) >> 27); +} + +__INLINE uint8_t ble_rwbleconf_usetxlr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x04000000)) >> 26); +} + +__INLINE uint8_t ble_rwbleconf_useiso_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x01000000)) >> 24); +} + +__INLINE uint8_t ble_rwbleconf_wlancoex_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x00200000)) >> 21); +} + +__INLINE uint8_t ble_rwbleconf_rfif_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x001F0000)) >> 16); +} + +__INLINE uint8_t ble_rwbleconf_usedbg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE uint8_t ble_rwbleconf_decipher_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x00004000)) >> 14); +} + +__INLINE uint8_t ble_rwbleconf_clk_sel_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x00003F00)) >> 8); +} + +__INLINE uint8_t ble_rwbleconf_intmode_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE uint8_t ble_rwbleconf_bus_type_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE uint8_t ble_rwbleconf_addr_width_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RWBLECONF_ADDR); + return ((localVal & ((uint32_t)0x0000001F)) >> 0); +} + +/** + * @brief INTCNTL0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     16          ERRORINTMSK   0
+ *     06          ISORXINTMSK   0
+ *     05          ISOTXINTMSK   0
+ *     04             RXINTMSK   0
+ *     03             TXINTMSK   0
+ *     02        SKIPEVTINTMSK   0
+ *     01         ENDEVTINTMSK   1
+ *     00       STARTEVTINTMSK   1
+ * 
+ */ +#define BLE_INTCNTL0_ADDR BASEBAND_REG_BASE +0xC // 0x5080000C +#define BLE_INTCNTL0_OFFSET 0x0000000C +#define BLE_INTCNTL0_INDEX 0x00000003 +#define BLE_INTCNTL0_RESET 0x00000003 + +__INLINE uint32_t ble_intcntl0_get(void) +{ + return REG_BLE_RD(BLE_INTCNTL0_ADDR); +} + +__INLINE void ble_intcntl0_set(uint32_t value) +{ + REG_BLE_WR(BLE_INTCNTL0_ADDR, value); +} + +// field definitions +#define BLE_ERRORINTMSK_BIT ((uint32_t)0x00010000) +#define BLE_ERRORINTMSK_POS 16 +#define BLE_ISORXINTMSK_BIT ((uint32_t)0x00000040) +#define BLE_ISORXINTMSK_POS 6 +#define BLE_ISOTXINTMSK_BIT ((uint32_t)0x00000020) +#define BLE_ISOTXINTMSK_POS 5 +#define BLE_RXINTMSK_BIT ((uint32_t)0x00000010) +#define BLE_RXINTMSK_POS 4 +#define BLE_TXINTMSK_BIT ((uint32_t)0x00000008) +#define BLE_TXINTMSK_POS 3 +#define BLE_SKIPEVTINTMSK_BIT ((uint32_t)0x00000004) +#define BLE_SKIPEVTINTMSK_POS 2 +#define BLE_ENDEVTINTMSK_BIT ((uint32_t)0x00000002) +#define BLE_ENDEVTINTMSK_POS 1 +#define BLE_STARTEVTINTMSK_BIT ((uint32_t)0x00000001) +#define BLE_STARTEVTINTMSK_POS 0 + +#define BLE_ERRORINTMSK_RST 0x0 +#define BLE_ISORXINTMSK_RST 0x0 +#define BLE_ISOTXINTMSK_RST 0x0 +#define BLE_RXINTMSK_RST 0x0 +#define BLE_TXINTMSK_RST 0x0 +#define BLE_SKIPEVTINTMSK_RST 0x0 +#define BLE_ENDEVTINTMSK_RST 0x1 +#define BLE_STARTEVTINTMSK_RST 0x1 + +__INLINE void ble_intcntl0_pack(uint8_t errorintmsk, uint8_t isorxintmsk, uint8_t isotxintmsk, uint8_t rxintmsk, uint8_t txintmsk, uint8_t skipevtintmsk, uint8_t endevtintmsk, uint8_t startevtintmsk) +{ + ASSERT_ERR((((uint32_t)errorintmsk << 16) & ~((uint32_t)0x00010000)) == 0); + ASSERT_ERR((((uint32_t)isorxintmsk << 6) & ~((uint32_t)0x00000040)) == 0); + ASSERT_ERR((((uint32_t)isotxintmsk << 5) & ~((uint32_t)0x00000020)) == 0); + ASSERT_ERR((((uint32_t)rxintmsk << 4) & ~((uint32_t)0x00000010)) == 0); + ASSERT_ERR((((uint32_t)txintmsk << 3) & ~((uint32_t)0x00000008)) == 0); + ASSERT_ERR((((uint32_t)skipevtintmsk << 2) & ~((uint32_t)0x00000004)) == 0); + ASSERT_ERR((((uint32_t)endevtintmsk << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)startevtintmsk << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_INTCNTL0_ADDR, ((uint32_t)errorintmsk << 16) | ((uint32_t)isorxintmsk << 6) | ((uint32_t)isotxintmsk << 5) | ((uint32_t)rxintmsk << 4) | ((uint32_t)txintmsk << 3) | ((uint32_t)skipevtintmsk << 2) | ((uint32_t)endevtintmsk << 1) | ((uint32_t)startevtintmsk << 0)); +} + +__INLINE void ble_intcntl0_unpack(uint8_t* errorintmsk, uint8_t* isorxintmsk, uint8_t* isotxintmsk, uint8_t* rxintmsk, uint8_t* txintmsk, uint8_t* skipevtintmsk, uint8_t* endevtintmsk, uint8_t* startevtintmsk) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL0_ADDR); + + *errorintmsk = (localVal & ((uint32_t)0x00010000)) >> 16; + *isorxintmsk = (localVal & ((uint32_t)0x00000040)) >> 6; + *isotxintmsk = (localVal & ((uint32_t)0x00000020)) >> 5; + *rxintmsk = (localVal & ((uint32_t)0x00000010)) >> 4; + *txintmsk = (localVal & ((uint32_t)0x00000008)) >> 3; + *skipevtintmsk = (localVal & ((uint32_t)0x00000004)) >> 2; + *endevtintmsk = (localVal & ((uint32_t)0x00000002)) >> 1; + *startevtintmsk = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_intcntl0_errorintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00010000)) >> 16); +} + +__INLINE void ble_intcntl0_errorintmsk_setf(uint8_t errorintmsk) +{ + ASSERT_ERR((((uint32_t)errorintmsk << 16) & ~((uint32_t)0x00010000)) == 0); + REG_BLE_WR(BLE_INTCNTL0_ADDR, (REG_BLE_RD(BLE_INTCNTL0_ADDR) & ~((uint32_t)0x00010000)) | ((uint32_t)errorintmsk << 16)); +} + +__INLINE uint8_t ble_intcntl0_isorxintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE void ble_intcntl0_isorxintmsk_setf(uint8_t isorxintmsk) +{ + ASSERT_ERR((((uint32_t)isorxintmsk << 6) & ~((uint32_t)0x00000040)) == 0); + REG_BLE_WR(BLE_INTCNTL0_ADDR, (REG_BLE_RD(BLE_INTCNTL0_ADDR) & ~((uint32_t)0x00000040)) | ((uint32_t)isorxintmsk << 6)); +} + +__INLINE uint8_t ble_intcntl0_isotxintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE void ble_intcntl0_isotxintmsk_setf(uint8_t isotxintmsk) +{ + ASSERT_ERR((((uint32_t)isotxintmsk << 5) & ~((uint32_t)0x00000020)) == 0); + REG_BLE_WR(BLE_INTCNTL0_ADDR, (REG_BLE_RD(BLE_INTCNTL0_ADDR) & ~((uint32_t)0x00000020)) | ((uint32_t)isotxintmsk << 5)); +} + +__INLINE uint8_t ble_intcntl0_rxintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE void ble_intcntl0_rxintmsk_setf(uint8_t rxintmsk) +{ + ASSERT_ERR((((uint32_t)rxintmsk << 4) & ~((uint32_t)0x00000010)) == 0); + REG_BLE_WR(BLE_INTCNTL0_ADDR, (REG_BLE_RD(BLE_INTCNTL0_ADDR) & ~((uint32_t)0x00000010)) | ((uint32_t)rxintmsk << 4)); +} + +__INLINE uint8_t ble_intcntl0_txintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE void ble_intcntl0_txintmsk_setf(uint8_t txintmsk) +{ + ASSERT_ERR((((uint32_t)txintmsk << 3) & ~((uint32_t)0x00000008)) == 0); + REG_BLE_WR(BLE_INTCNTL0_ADDR, (REG_BLE_RD(BLE_INTCNTL0_ADDR) & ~((uint32_t)0x00000008)) | ((uint32_t)txintmsk << 3)); +} + +__INLINE uint8_t ble_intcntl0_skipevtintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE void ble_intcntl0_skipevtintmsk_setf(uint8_t skipevtintmsk) +{ + ASSERT_ERR((((uint32_t)skipevtintmsk << 2) & ~((uint32_t)0x00000004)) == 0); + REG_BLE_WR(BLE_INTCNTL0_ADDR, (REG_BLE_RD(BLE_INTCNTL0_ADDR) & ~((uint32_t)0x00000004)) | ((uint32_t)skipevtintmsk << 2)); +} + +__INLINE uint8_t ble_intcntl0_endevtintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ble_intcntl0_endevtintmsk_setf(uint8_t endevtintmsk) +{ + ASSERT_ERR((((uint32_t)endevtintmsk << 1) & ~((uint32_t)0x00000002)) == 0); + REG_BLE_WR(BLE_INTCNTL0_ADDR, (REG_BLE_RD(BLE_INTCNTL0_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)endevtintmsk << 1)); +} + +__INLINE uint8_t ble_intcntl0_startevtintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ble_intcntl0_startevtintmsk_setf(uint8_t startevtintmsk) +{ + ASSERT_ERR((((uint32_t)startevtintmsk << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_INTCNTL0_ADDR, (REG_BLE_RD(BLE_INTCNTL0_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)startevtintmsk << 0)); +} + +/** + * @brief INTSTAT0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     16         ERRORINTSTAT   0
+ * 
+ */ +#define BLE_INTSTAT0_ADDR BASEBAND_REG_BASE +0x10 // 0x50800010 +#define BLE_INTSTAT0_OFFSET 0x00000010 +#define BLE_INTSTAT0_INDEX 0x00000004 +#define BLE_INTSTAT0_RESET 0x00000000 + +__INLINE uint32_t ble_intstat0_get(void) +{ + return REG_BLE_RD(BLE_INTSTAT0_ADDR); +} + +// field definitions +#define BLE_ERRORINTSTAT_BIT ((uint32_t)0x00010000) +#define BLE_ERRORINTSTAT_POS 16 + +#define BLE_ERRORINTSTAT_RST 0x0 + +__INLINE uint8_t ble_intstat0_errorintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTSTAT0_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00010000)) == 0); + return (localVal >> 16); +} + +/** + * @brief INTACK0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     16          ERRORINTACK   0
+ * 
+ */ +#define BLE_INTACK0_ADDR BASEBAND_REG_BASE +0x14 //0x50800014 +#define BLE_INTACK0_OFFSET 0x00000014 +#define BLE_INTACK0_INDEX 0x00000005 +#define BLE_INTACK0_RESET 0x00000000 + +__INLINE uint32_t ble_intack0_get(void) +{ + return REG_BLE_RD(BLE_INTACK0_ADDR); +} + +__INLINE void ble_intack0_clear(uint32_t value) +{ + REG_BLE_WR(BLE_INTACK0_ADDR, value); +} + +// field definitions +#define BLE_ERRORINTACK_BIT ((uint32_t)0x00010000) +#define BLE_ERRORINTACK_POS 16 + +#define BLE_ERRORINTACK_RST 0x0 + +__INLINE uint8_t ble_intack0_errorintack_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTACK0_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00010000)) == 0); + return (localVal >> 16); +} + +__INLINE void ble_intack0_errorintack_clearf(uint8_t errorintack) +{ + ASSERT_ERR((((uint32_t)errorintack << 16) & ~((uint32_t)0x00010000)) == 0); + REG_BLE_WR(BLE_INTACK0_ADDR, (uint32_t)errorintack << 16); +} + +/** + * @brief INTCNTL1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  30:28         CLKNINTSRMSK   0x0
+ *  27:24         CLKNINTSRVAL   0x0
+ *     15           FIFOINTMSK   1
+ *     06   TIMESTAMPTGT2INTMSK   0
+ *     05   TIMESTAMPTGT1INTMSK   0
+ *     04        FINETGTINTMSK   0
+ *     03             SWINTMSK   0
+ *     02          CRYPTINTMSK   0
+ *     01            SLPINTMSK   1
+ *     00           CLKNINTMSK   1
+ * 
+ */ +#define BLE_INTCNTL1_ADDR BASEBAND_REG_BASE +0x18 //0x50800018 +#define BLE_INTCNTL1_OFFSET 0x00000018 +#define BLE_INTCNTL1_INDEX 0x00000006 +#define BLE_INTCNTL1_RESET 0x00008003 + +__INLINE uint32_t ble_intcntl1_get(void) +{ + return REG_BLE_RD(BLE_INTCNTL1_ADDR); +} + +__INLINE void ble_intcntl1_set(uint32_t value) +{ + REG_BLE_WR(BLE_INTCNTL1_ADDR, value); +} + +// field definitions +#define BLE_CLKNINTSRMSK_MASK ((uint32_t)0x70000000) +#define BLE_CLKNINTSRMSK_LSB 28 +#define BLE_CLKNINTSRMSK_WIDTH ((uint32_t)0x00000003) +#define BLE_CLKNINTSRVAL_MASK ((uint32_t)0x0F000000) +#define BLE_CLKNINTSRVAL_LSB 24 +#define BLE_CLKNINTSRVAL_WIDTH ((uint32_t)0x00000004) +#define BLE_FIFOINTMSK_BIT ((uint32_t)0x00008000) +#define BLE_FIFOINTMSK_POS 15 +#define BLE_TIMESTAMPTGT2INTMSK_BIT ((uint32_t)0x00000040) +#define BLE_TIMESTAMPTGT2INTMSK_POS 6 +#define BLE_TIMESTAMPTGT1INTMSK_BIT ((uint32_t)0x00000020) +#define BLE_TIMESTAMPTGT1INTMSK_POS 5 +#define BLE_FINETGTINTMSK_BIT ((uint32_t)0x00000010) +#define BLE_FINETGTINTMSK_POS 4 +#define BLE_SWINTMSK_BIT ((uint32_t)0x00000008) +#define BLE_SWINTMSK_POS 3 +#define BLE_CRYPTINTMSK_BIT ((uint32_t)0x00000004) +#define BLE_CRYPTINTMSK_POS 2 +#define BLE_SLPINTMSK_BIT ((uint32_t)0x00000002) +#define BLE_SLPINTMSK_POS 1 +#define BLE_CLKNINTMSK_BIT ((uint32_t)0x00000001) +#define BLE_CLKNINTMSK_POS 0 + +#define BLE_CLKNINTSRMSK_RST 0x0 +#define BLE_CLKNINTSRVAL_RST 0x0 +#define BLE_FIFOINTMSK_RST 0x1 +#define BLE_TIMESTAMPTGT2INTMSK_RST 0x0 +#define BLE_TIMESTAMPTGT1INTMSK_RST 0x0 +#define BLE_FINETGTINTMSK_RST 0x0 +#define BLE_SWINTMSK_RST 0x0 +#define BLE_CRYPTINTMSK_RST 0x0 +#define BLE_SLPINTMSK_RST 0x1 +#define BLE_CLKNINTMSK_RST 0x1 + +__INLINE void ble_intcntl1_pack(uint8_t clknintsrmsk, uint8_t clknintsrval, uint8_t fifointmsk, uint8_t timestamptgt2intmsk, uint8_t timestamptgt1intmsk, uint8_t finetgtintmsk, uint8_t swintmsk, uint8_t cryptintmsk, uint8_t slpintmsk, uint8_t clknintmsk) +{ + ASSERT_ERR((((uint32_t)clknintsrmsk << 28) & ~((uint32_t)0x70000000)) == 0); + ASSERT_ERR((((uint32_t)clknintsrval << 24) & ~((uint32_t)0x0F000000)) == 0); + ASSERT_ERR((((uint32_t)fifointmsk << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)timestamptgt2intmsk << 6) & ~((uint32_t)0x00000040)) == 0); + ASSERT_ERR((((uint32_t)timestamptgt1intmsk << 5) & ~((uint32_t)0x00000020)) == 0); + ASSERT_ERR((((uint32_t)finetgtintmsk << 4) & ~((uint32_t)0x00000010)) == 0); + ASSERT_ERR((((uint32_t)swintmsk << 3) & ~((uint32_t)0x00000008)) == 0); + ASSERT_ERR((((uint32_t)cryptintmsk << 2) & ~((uint32_t)0x00000004)) == 0); + ASSERT_ERR((((uint32_t)slpintmsk << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)clknintmsk << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, ((uint32_t)clknintsrmsk << 28) | ((uint32_t)clknintsrval << 24) | ((uint32_t)fifointmsk << 15) | ((uint32_t)timestamptgt2intmsk << 6) | ((uint32_t)timestamptgt1intmsk << 5) | ((uint32_t)finetgtintmsk << 4) | ((uint32_t)swintmsk << 3) | ((uint32_t)cryptintmsk << 2) | ((uint32_t)slpintmsk << 1) | ((uint32_t)clknintmsk << 0)); +} + +__INLINE void ble_intcntl1_unpack(uint8_t* clknintsrmsk, uint8_t* clknintsrval, uint8_t* fifointmsk, uint8_t* timestamptgt2intmsk, uint8_t* timestamptgt1intmsk, uint8_t* finetgtintmsk, uint8_t* swintmsk, uint8_t* cryptintmsk, uint8_t* slpintmsk, uint8_t* clknintmsk) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + + *clknintsrmsk = (localVal & ((uint32_t)0x70000000)) >> 28; + *clknintsrval = (localVal & ((uint32_t)0x0F000000)) >> 24; + *fifointmsk = (localVal & ((uint32_t)0x00008000)) >> 15; + *timestamptgt2intmsk = (localVal & ((uint32_t)0x00000040)) >> 6; + *timestamptgt1intmsk = (localVal & ((uint32_t)0x00000020)) >> 5; + *finetgtintmsk = (localVal & ((uint32_t)0x00000010)) >> 4; + *swintmsk = (localVal & ((uint32_t)0x00000008)) >> 3; + *cryptintmsk = (localVal & ((uint32_t)0x00000004)) >> 2; + *slpintmsk = (localVal & ((uint32_t)0x00000002)) >> 1; + *clknintmsk = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_intcntl1_clknintsrmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x70000000)) >> 28); +} + +__INLINE void ble_intcntl1_clknintsrmsk_setf(uint8_t clknintsrmsk) +{ + ASSERT_ERR((((uint32_t)clknintsrmsk << 28) & ~((uint32_t)0x70000000)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, (REG_BLE_RD(BLE_INTCNTL1_ADDR) & ~((uint32_t)0x70000000)) | ((uint32_t)clknintsrmsk << 28)); +} + +__INLINE uint8_t ble_intcntl1_clknintsrval_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x0F000000)) >> 24); +} + +__INLINE void ble_intcntl1_clknintsrval_setf(uint8_t clknintsrval) +{ + ASSERT_ERR((((uint32_t)clknintsrval << 24) & ~((uint32_t)0x0F000000)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, (REG_BLE_RD(BLE_INTCNTL1_ADDR) & ~((uint32_t)0x0F000000)) | ((uint32_t)clknintsrval << 24)); +} + +__INLINE uint8_t ble_intcntl1_fifointmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ble_intcntl1_fifointmsk_setf(uint8_t fifointmsk) +{ + ASSERT_ERR((((uint32_t)fifointmsk << 15) & ~((uint32_t)0x00008000)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, (REG_BLE_RD(BLE_INTCNTL1_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)fifointmsk << 15)); +} + +__INLINE uint8_t ble_intcntl1_timestamptgt2intmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE void ble_intcntl1_timestamptgt2intmsk_setf(uint8_t timestamptgt2intmsk) +{ + ASSERT_ERR((((uint32_t)timestamptgt2intmsk << 6) & ~((uint32_t)0x00000040)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, (REG_BLE_RD(BLE_INTCNTL1_ADDR) & ~((uint32_t)0x00000040)) | ((uint32_t)timestamptgt2intmsk << 6)); +} + +__INLINE uint8_t ble_intcntl1_timestamptgt1intmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE void ble_intcntl1_timestamptgt1intmsk_setf(uint8_t timestamptgt1intmsk) +{ + ASSERT_ERR((((uint32_t)timestamptgt1intmsk << 5) & ~((uint32_t)0x00000020)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, (REG_BLE_RD(BLE_INTCNTL1_ADDR) & ~((uint32_t)0x00000020)) | ((uint32_t)timestamptgt1intmsk << 5)); +} + +__INLINE uint8_t ble_intcntl1_finetgtintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE void ble_intcntl1_finetgtintmsk_setf(uint8_t finetgtintmsk) +{ + ASSERT_ERR((((uint32_t)finetgtintmsk << 4) & ~((uint32_t)0x00000010)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, (REG_BLE_RD(BLE_INTCNTL1_ADDR) & ~((uint32_t)0x00000010)) | ((uint32_t)finetgtintmsk << 4)); +} + +__INLINE uint8_t ble_intcntl1_swintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE void ble_intcntl1_swintmsk_setf(uint8_t swintmsk) +{ + ASSERT_ERR((((uint32_t)swintmsk << 3) & ~((uint32_t)0x00000008)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, (REG_BLE_RD(BLE_INTCNTL1_ADDR) & ~((uint32_t)0x00000008)) | ((uint32_t)swintmsk << 3)); +} + +__INLINE uint8_t ble_intcntl1_cryptintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE void ble_intcntl1_cryptintmsk_setf(uint8_t cryptintmsk) +{ + ASSERT_ERR((((uint32_t)cryptintmsk << 2) & ~((uint32_t)0x00000004)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, (REG_BLE_RD(BLE_INTCNTL1_ADDR) & ~((uint32_t)0x00000004)) | ((uint32_t)cryptintmsk << 2)); +} + +__INLINE uint8_t ble_intcntl1_slpintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ble_intcntl1_slpintmsk_setf(uint8_t slpintmsk) +{ + ASSERT_ERR((((uint32_t)slpintmsk << 1) & ~((uint32_t)0x00000002)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, (REG_BLE_RD(BLE_INTCNTL1_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)slpintmsk << 1)); +} + +__INLINE uint8_t ble_intcntl1_clknintmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ble_intcntl1_clknintmsk_setf(uint8_t clknintmsk) +{ + ASSERT_ERR((((uint32_t)clknintmsk << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_INTCNTL1_ADDR, (REG_BLE_RD(BLE_INTCNTL1_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)clknintmsk << 0)); +} + +/** + * @brief INTSTAT1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15          FIFOINTSTAT   0
+ *     06   TIMESTAMPTGT2INTSTAT   0
+ *     05   TIMESTAMPTGT1INTSTAT   0
+ *     04       FINETGTINTSTAT   0
+ *     03            SWINTSTAT   0
+ *     02         CRYPTINTSTAT   0
+ *     01           SLPINTSTAT   0
+ *     00          CLKNINTSTAT   0
+ * 
+ */ +#define BLE_INTSTAT1_ADDR BASEBAND_REG_BASE +0x1C //0x5080001C +#define BLE_INTSTAT1_OFFSET 0x0000001C +#define BLE_INTSTAT1_INDEX 0x00000007 +#define BLE_INTSTAT1_RESET 0x00000000 + +__INLINE uint32_t ble_intstat1_get(void) +{ + return REG_BLE_RD(BLE_INTSTAT1_ADDR); +} + +// field definitions +#define BLE_FIFOINTSTAT_BIT ((uint32_t)0x00008000) +#define BLE_FIFOINTSTAT_POS 15 +#define BLE_TIMESTAMPTGT2INTSTAT_BIT ((uint32_t)0x00000040) +#define BLE_TIMESTAMPTGT2INTSTAT_POS 6 +#define BLE_TIMESTAMPTGT1INTSTAT_BIT ((uint32_t)0x00000020) +#define BLE_TIMESTAMPTGT1INTSTAT_POS 5 +#define BLE_FINETGTINTSTAT_BIT ((uint32_t)0x00000010) +#define BLE_FINETGTINTSTAT_POS 4 +#define BLE_SWINTSTAT_BIT ((uint32_t)0x00000008) +#define BLE_SWINTSTAT_POS 3 +#define BLE_CRYPTINTSTAT_BIT ((uint32_t)0x00000004) +#define BLE_CRYPTINTSTAT_POS 2 +#define BLE_SLPINTSTAT_BIT ((uint32_t)0x00000002) +#define BLE_SLPINTSTAT_POS 1 +#define BLE_CLKNINTSTAT_BIT ((uint32_t)0x00000001) +#define BLE_CLKNINTSTAT_POS 0 + +#define BLE_FIFOINTSTAT_RST 0x0 +#define BLE_TIMESTAMPTGT2INTSTAT_RST 0x0 +#define BLE_TIMESTAMPTGT1INTSTAT_RST 0x0 +#define BLE_FINETGTINTSTAT_RST 0x0 +#define BLE_SWINTSTAT_RST 0x0 +#define BLE_CRYPTINTSTAT_RST 0x0 +#define BLE_SLPINTSTAT_RST 0x0 +#define BLE_CLKNINTSTAT_RST 0x0 + +__INLINE void ble_intstat1_unpack(uint8_t* fifointstat, uint8_t* timestamptgt2intstat, uint8_t* timestamptgt1intstat, uint8_t* finetgtintstat, uint8_t* swintstat, uint8_t* cryptintstat, uint8_t* slpintstat, uint8_t* clknintstat) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTSTAT1_ADDR); + + *fifointstat = (localVal & ((uint32_t)0x00008000)) >> 15; + *timestamptgt2intstat = (localVal & ((uint32_t)0x00000040)) >> 6; + *timestamptgt1intstat = (localVal & ((uint32_t)0x00000020)) >> 5; + *finetgtintstat = (localVal & ((uint32_t)0x00000010)) >> 4; + *swintstat = (localVal & ((uint32_t)0x00000008)) >> 3; + *cryptintstat = (localVal & ((uint32_t)0x00000004)) >> 2; + *slpintstat = (localVal & ((uint32_t)0x00000002)) >> 1; + *clknintstat = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_intstat1_fifointstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE uint8_t ble_intstat1_timestamptgt2intstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE uint8_t ble_intstat1_timestamptgt1intstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE uint8_t ble_intstat1_finetgtintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE uint8_t ble_intstat1_swintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE uint8_t ble_intstat1_cryptintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE uint8_t ble_intstat1_slpintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE uint8_t ble_intstat1_clknintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +/** + * @brief INTACK1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15           FIFOINTACK   0
+ *     06   TIMESTAMPTGT2INTACK   0
+ *     05   TIMESTAMPTGT1INTACK   0
+ *     04        FINETGTINTACK   0
+ *     03             SWINTACK   0
+ *     02          CRYPTINTACK   0
+ *     01            SLPINTACK   0
+ *     00           CLKNINTACK   0
+ * 
+ */ +#define BLE_INTACK1_ADDR BASEBAND_REG_BASE +0x20 //0x50800020 +#define BLE_INTACK1_OFFSET 0x00000020 +#define BLE_INTACK1_INDEX 0x00000008 +#define BLE_INTACK1_RESET 0x00000000 + +__INLINE uint32_t ble_intack1_get(void) +{ + return REG_BLE_RD(BLE_INTACK1_ADDR); +} + +__INLINE void ble_intack1_clear(uint32_t value) +{ + REG_BLE_WR(BLE_INTACK1_ADDR, value); +} + +// field definitions +#define BLE_FIFOINTACK_BIT ((uint32_t)0x00008000) +#define BLE_FIFOINTACK_POS 15 +#define BLE_TIMESTAMPTGT2INTACK_BIT ((uint32_t)0x00000040) +#define BLE_TIMESTAMPTGT2INTACK_POS 6 +#define BLE_TIMESTAMPTGT1INTACK_BIT ((uint32_t)0x00000020) +#define BLE_TIMESTAMPTGT1INTACK_POS 5 +#define BLE_FINETGTINTACK_BIT ((uint32_t)0x00000010) +#define BLE_FINETGTINTACK_POS 4 +#define BLE_SWINTACK_BIT ((uint32_t)0x00000008) +#define BLE_SWINTACK_POS 3 +#define BLE_CRYPTINTACK_BIT ((uint32_t)0x00000004) +#define BLE_CRYPTINTACK_POS 2 +#define BLE_SLPINTACK_BIT ((uint32_t)0x00000002) +#define BLE_SLPINTACK_POS 1 +#define BLE_CLKNINTACK_BIT ((uint32_t)0x00000001) +#define BLE_CLKNINTACK_POS 0 + +#define BLE_FIFOINTACK_RST 0x0 +#define BLE_TIMESTAMPTGT2INTACK_RST 0x0 +#define BLE_TIMESTAMPTGT1INTACK_RST 0x0 +#define BLE_FINETGTINTACK_RST 0x0 +#define BLE_SWINTACK_RST 0x0 +#define BLE_CRYPTINTACK_RST 0x0 +#define BLE_SLPINTACK_RST 0x0 +#define BLE_CLKNINTACK_RST 0x0 + +__INLINE void ble_intack1_pack(uint8_t fifointack, uint8_t timestamptgt2intack, uint8_t timestamptgt1intack, uint8_t finetgtintack, uint8_t swintack, uint8_t cryptintack, uint8_t slpintack, uint8_t clknintack) +{ + ASSERT_ERR((((uint32_t)fifointack << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)timestamptgt2intack << 6) & ~((uint32_t)0x00000040)) == 0); + ASSERT_ERR((((uint32_t)timestamptgt1intack << 5) & ~((uint32_t)0x00000020)) == 0); + ASSERT_ERR((((uint32_t)finetgtintack << 4) & ~((uint32_t)0x00000010)) == 0); + ASSERT_ERR((((uint32_t)swintack << 3) & ~((uint32_t)0x00000008)) == 0); + ASSERT_ERR((((uint32_t)cryptintack << 2) & ~((uint32_t)0x00000004)) == 0); + ASSERT_ERR((((uint32_t)slpintack << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)clknintack << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_INTACK1_ADDR, ((uint32_t)fifointack << 15) | ((uint32_t)timestamptgt2intack << 6) | ((uint32_t)timestamptgt1intack << 5) | ((uint32_t)finetgtintack << 4) | ((uint32_t)swintack << 3) | ((uint32_t)cryptintack << 2) | ((uint32_t)slpintack << 1) | ((uint32_t)clknintack << 0)); +} + +__INLINE void ble_intack1_unpack(uint8_t* fifointack, uint8_t* timestamptgt2intack, uint8_t* timestamptgt1intack, uint8_t* finetgtintack, uint8_t* swintack, uint8_t* cryptintack, uint8_t* slpintack, uint8_t* clknintack) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTACK1_ADDR); + + *fifointack = (localVal & ((uint32_t)0x00008000)) >> 15; + *timestamptgt2intack = (localVal & ((uint32_t)0x00000040)) >> 6; + *timestamptgt1intack = (localVal & ((uint32_t)0x00000020)) >> 5; + *finetgtintack = (localVal & ((uint32_t)0x00000010)) >> 4; + *swintack = (localVal & ((uint32_t)0x00000008)) >> 3; + *cryptintack = (localVal & ((uint32_t)0x00000004)) >> 2; + *slpintack = (localVal & ((uint32_t)0x00000002)) >> 1; + *clknintack = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_intack1_fifointack_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ble_intack1_fifointack_clearf(uint8_t fifointack) +{ + ASSERT_ERR((((uint32_t)fifointack << 15) & ~((uint32_t)0x00008000)) == 0); + REG_BLE_WR(BLE_INTACK1_ADDR, (uint32_t)fifointack << 15); +} + +__INLINE uint8_t ble_intack1_timestamptgt2intack_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE void ble_intack1_timestamptgt2intack_clearf(uint8_t timestamptgt2intack) +{ + ASSERT_ERR((((uint32_t)timestamptgt2intack << 6) & ~((uint32_t)0x00000040)) == 0); + REG_BLE_WR(BLE_INTACK1_ADDR, (uint32_t)timestamptgt2intack << 6); +} + +__INLINE uint8_t ble_intack1_timestamptgt1intack_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE void ble_intack1_timestamptgt1intack_clearf(uint8_t timestamptgt1intack) +{ + ASSERT_ERR((((uint32_t)timestamptgt1intack << 5) & ~((uint32_t)0x00000020)) == 0); + REG_BLE_WR(BLE_INTACK1_ADDR, (uint32_t)timestamptgt1intack << 5); +} + +__INLINE uint8_t ble_intack1_finetgtintack_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE void ble_intack1_finetgtintack_clearf(uint8_t finetgtintack) +{ + ASSERT_ERR((((uint32_t)finetgtintack << 4) & ~((uint32_t)0x00000010)) == 0); + REG_BLE_WR(BLE_INTACK1_ADDR, (uint32_t)finetgtintack << 4); +} + +__INLINE uint8_t ble_intack1_swintack_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE void ble_intack1_swintack_clearf(uint8_t swintack) +{ + ASSERT_ERR((((uint32_t)swintack << 3) & ~((uint32_t)0x00000008)) == 0); + REG_BLE_WR(BLE_INTACK1_ADDR, (uint32_t)swintack << 3); +} + +__INLINE uint8_t ble_intack1_cryptintack_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE void ble_intack1_cryptintack_clearf(uint8_t cryptintack) +{ + ASSERT_ERR((((uint32_t)cryptintack << 2) & ~((uint32_t)0x00000004)) == 0); + REG_BLE_WR(BLE_INTACK1_ADDR, (uint32_t)cryptintack << 2); +} + +__INLINE uint8_t ble_intack1_slpintack_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ble_intack1_slpintack_clearf(uint8_t slpintack) +{ + ASSERT_ERR((((uint32_t)slpintack << 1) & ~((uint32_t)0x00000002)) == 0); + REG_BLE_WR(BLE_INTACK1_ADDR, (uint32_t)slpintack << 1); +} + +__INLINE uint8_t ble_intack1_clknintack_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ble_intack1_clknintack_clearf(uint8_t clknintack) +{ + ASSERT_ERR((((uint32_t)clknintack << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_INTACK1_ADDR, (uint32_t)clknintack << 0); +} + +/** + * @brief ACTFIFOSTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:28          SKIP_ET_IDX   0x0
+ *  27:24       CURRENT_ET_IDX   0x0
+ *     15              ACTFLAG   0
+ *     06         ISORXINTSTAT   0
+ *     05         ISOTXINTSTAT   0
+ *     04            RXINTSTAT   0
+ *     03            TXINTSTAT   0
+ *     02       SKIPACTINTSTAT   0
+ *     01        ENDACTINTSTAT   0
+ *     00      STARTACTINTSTAT   0
+ * 
+ */ +#define BLE_ACTFIFOSTAT_ADDR BASEBAND_REG_BASE +0x24 //0x50800024 +#define BLE_ACTFIFOSTAT_OFFSET 0x00000024 +#define BLE_ACTFIFOSTAT_INDEX 0x00000009 +#define BLE_ACTFIFOSTAT_RESET 0x00000000 + +__INLINE uint32_t ble_actfifostat_get(void) +{ + return REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); +} + +// field definitions +#define BLE_SKIP_ET_IDX_MASK ((uint32_t)0xF0000000) +#define BLE_SKIP_ET_IDX_LSB 28 +#define BLE_SKIP_ET_IDX_WIDTH ((uint32_t)0x00000004) +#define BLE_CURRENT_ET_IDX_MASK ((uint32_t)0x0F000000) +#define BLE_CURRENT_ET_IDX_LSB 24 +#define BLE_CURRENT_ET_IDX_WIDTH ((uint32_t)0x00000004) +#define BLE_ACTFLAG_BIT ((uint32_t)0x00008000) +#define BLE_ACTFLAG_POS 15 +#define BLE_ISORXINTSTAT_BIT ((uint32_t)0x00000040) +#define BLE_ISORXINTSTAT_POS 6 +#define BLE_ISOTXINTSTAT_BIT ((uint32_t)0x00000020) +#define BLE_ISOTXINTSTAT_POS 5 +#define BLE_RXINTSTAT_BIT ((uint32_t)0x00000010) +#define BLE_RXINTSTAT_POS 4 +#define BLE_TXINTSTAT_BIT ((uint32_t)0x00000008) +#define BLE_TXINTSTAT_POS 3 +#define BLE_SKIPACTINTSTAT_BIT ((uint32_t)0x00000004) +#define BLE_SKIPACTINTSTAT_POS 2 +#define BLE_ENDACTINTSTAT_BIT ((uint32_t)0x00000002) +#define BLE_ENDACTINTSTAT_POS 1 +#define BLE_STARTACTINTSTAT_BIT ((uint32_t)0x00000001) +#define BLE_STARTACTINTSTAT_POS 0 + +#define BLE_SKIP_ET_IDX_RST 0x0 +#define BLE_CURRENT_ET_IDX_RST 0x0 +#define BLE_ACTFLAG_RST 0x0 +#define BLE_ISORXINTSTAT_RST 0x0 +#define BLE_ISOTXINTSTAT_RST 0x0 +#define BLE_RXINTSTAT_RST 0x0 +#define BLE_TXINTSTAT_RST 0x0 +#define BLE_SKIPACTINTSTAT_RST 0x0 +#define BLE_ENDACTINTSTAT_RST 0x0 +#define BLE_STARTACTINTSTAT_RST 0x0 + +__INLINE void ble_actfifostat_unpack(uint8_t* skipetidx, uint8_t* currentetidx, uint8_t* actflag, uint8_t* isorxintstat, uint8_t* isotxintstat, uint8_t* rxintstat, uint8_t* txintstat, uint8_t* skipactintstat, uint8_t* endactintstat, uint8_t* startactintstat) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + + *skipetidx = (localVal & ((uint32_t)0xF0000000)) >> 28; + *currentetidx = (localVal & ((uint32_t)0x0F000000)) >> 24; + *actflag = (localVal & ((uint32_t)0x00008000)) >> 15; + *isorxintstat = (localVal & ((uint32_t)0x00000040)) >> 6; + *isotxintstat = (localVal & ((uint32_t)0x00000020)) >> 5; + *rxintstat = (localVal & ((uint32_t)0x00000010)) >> 4; + *txintstat = (localVal & ((uint32_t)0x00000008)) >> 3; + *skipactintstat = (localVal & ((uint32_t)0x00000004)) >> 2; + *endactintstat = (localVal & ((uint32_t)0x00000002)) >> 1; + *startactintstat = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_actfifostat_skip_et_idx_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0xF0000000)) >> 28); +} + +__INLINE uint8_t ble_actfifostat_current_et_idx_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x0F000000)) >> 24); +} + +__INLINE uint8_t ble_actfifostat_actflag_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE uint8_t ble_actfifostat_isorxintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE uint8_t ble_actfifostat_isotxintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE uint8_t ble_actfifostat_rxintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE uint8_t ble_actfifostat_txintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE uint8_t ble_actfifostat_skipactintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE uint8_t ble_actfifostat_endactintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE uint8_t ble_actfifostat_startactintstat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +/** + * @brief CURRENTRXDESCPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00     CURRENTRXDESCPTR   0x0
+ * 
+ */ +#define BLE_CURRENTRXDESCPTR_ADDR BASEBAND_REG_BASE +0x28 //0x50800028 +#define BLE_CURRENTRXDESCPTR_OFFSET 0x00000028 +#define BLE_CURRENTRXDESCPTR_INDEX 0x0000000A +#define BLE_CURRENTRXDESCPTR_RESET 0x00000000 + +__INLINE uint32_t ble_currentrxdescptr_get(void) +{ + return REG_BLE_RD(BLE_CURRENTRXDESCPTR_ADDR); +} + +__INLINE void ble_currentrxdescptr_set(uint32_t value) +{ + REG_BLE_WR(BLE_CURRENTRXDESCPTR_ADDR, value); +} + +// field definitions +#define BLE_CURRENTRXDESCPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_CURRENTRXDESCPTR_LSB 0 +#define BLE_CURRENTRXDESCPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_CURRENTRXDESCPTR_RST 0x0 + +__INLINE uint16_t ble_currentrxdescptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_CURRENTRXDESCPTR_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_currentrxdescptr_setf(uint16_t currentrxdescptr) +{ + ASSERT_ERR((((uint32_t)currentrxdescptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_CURRENTRXDESCPTR_ADDR, (uint32_t)currentrxdescptr << 0); +} + +/** + * @brief ETPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00                ETPTR   0x0
+ * 
+ */ +#define BLE_ETPTR_ADDR BASEBAND_REG_BASE +0x2C //0x5080002C +#define BLE_ETPTR_OFFSET 0x0000002C +#define BLE_ETPTR_INDEX 0x0000000B +#define BLE_ETPTR_RESET 0x00000000 + +__INLINE uint32_t ble_etptr_get(void) +{ + return REG_BLE_RD(BLE_ETPTR_ADDR); +} + +__INLINE void ble_etptr_set(uint32_t value) +{ + REG_BLE_WR(BLE_ETPTR_ADDR, value); +} + +// field definitions +#define BLE_ETPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_ETPTR_LSB 0 +#define BLE_ETPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_ETPTR_RST 0x0 + +__INLINE uint16_t ble_etptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ETPTR_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_etptr_setf(uint16_t etptr) +{ + ASSERT_ERR((((uint32_t)etptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_ETPTR_ADDR, (uint32_t)etptr << 0); +} + +/** + * @brief DEEPSLCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31           EXTWKUPDSB   0
+ *     15      DEEP_SLEEP_STAT   0
+ *     03   DEEP_SLEEP_CORR_EN   0
+ *     02        DEEP_SLEEP_ON   0
+ *     01       RADIO_SLEEP_EN   0
+ *     00         OSC_SLEEP_EN   0
+ * 
+ */ +#define BLE_DEEPSLCNTL_ADDR BASEBAND_REG_BASE +0x30 //0x50800030 +#define BLE_DEEPSLCNTL_OFFSET 0x00000030 +#define BLE_DEEPSLCNTL_INDEX 0x0000000C +#define BLE_DEEPSLCNTL_RESET 0x00000000 + +__INLINE uint32_t ble_deepslcntl_get(void) +{ + return REG_BLE_RD(BLE_DEEPSLCNTL_ADDR); +} + +__INLINE void ble_deepslcntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_DEEPSLCNTL_ADDR, value); +} + +// field definitions +#define BLE_EXTWKUPDSB_BIT ((uint32_t)0x80000000) +#define BLE_EXTWKUPDSB_POS 31 +#define BLE_DEEP_SLEEP_STAT_BIT ((uint32_t)0x00008000) +#define BLE_DEEP_SLEEP_STAT_POS 15 +#define BLE_DEEP_SLEEP_CORR_EN_BIT ((uint32_t)0x00000008) +#define BLE_DEEP_SLEEP_CORR_EN_POS 3 +#define BLE_DEEP_SLEEP_ON_BIT ((uint32_t)0x00000004) +#define BLE_DEEP_SLEEP_ON_POS 2 +#define BLE_RADIO_SLEEP_EN_BIT ((uint32_t)0x00000002) +#define BLE_RADIO_SLEEP_EN_POS 1 +#define BLE_OSC_SLEEP_EN_BIT ((uint32_t)0x00000001) +#define BLE_OSC_SLEEP_EN_POS 0 + +#define BLE_EXTWKUPDSB_RST 0x0 +#define BLE_DEEP_SLEEP_STAT_RST 0x0 +#define BLE_DEEP_SLEEP_CORR_EN_RST 0x0 +#define BLE_DEEP_SLEEP_ON_RST 0x0 +#define BLE_RADIO_SLEEP_EN_RST 0x0 +#define BLE_OSC_SLEEP_EN_RST 0x0 + +__INLINE void ble_deepslcntl_pack(uint8_t extwkupdsb, uint8_t deepsleepcorren, uint8_t deepsleepon, uint8_t radiosleepen, uint8_t oscsleepen) +{ + ASSERT_ERR((((uint32_t)extwkupdsb << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)deepsleepcorren << 3) & ~((uint32_t)0x00000008)) == 0); + ASSERT_ERR((((uint32_t)deepsleepon << 2) & ~((uint32_t)0x00000004)) == 0); + ASSERT_ERR((((uint32_t)radiosleepen << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)oscsleepen << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_DEEPSLCNTL_ADDR, ((uint32_t)extwkupdsb << 31) | ((uint32_t)deepsleepcorren << 3) | ((uint32_t)deepsleepon << 2) | ((uint32_t)radiosleepen << 1) | ((uint32_t)oscsleepen << 0)); +} + +__INLINE void ble_deepslcntl_unpack(uint8_t* extwkupdsb, uint8_t* deepsleepstat, uint8_t* deepsleepcorren, uint8_t* deepsleepon, uint8_t* radiosleepen, uint8_t* oscsleepen) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEEPSLCNTL_ADDR); + + *extwkupdsb = (localVal & ((uint32_t)0x80000000)) >> 31; + *deepsleepstat = (localVal & ((uint32_t)0x00008000)) >> 15; + *deepsleepcorren = (localVal & ((uint32_t)0x00000008)) >> 3; + *deepsleepon = (localVal & ((uint32_t)0x00000004)) >> 2; + *radiosleepen = (localVal & ((uint32_t)0x00000002)) >> 1; + *oscsleepen = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_deepslcntl_extwkupdsb_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_deepslcntl_extwkupdsb_setf(uint8_t extwkupdsb) +{ + ASSERT_ERR((((uint32_t)extwkupdsb << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_DEEPSLCNTL_ADDR, (REG_BLE_RD(BLE_DEEPSLCNTL_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)extwkupdsb << 31)); +} + +__INLINE uint8_t ble_deepslcntl_deep_sleep_stat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE uint8_t ble_deepslcntl_deep_sleep_corr_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE void ble_deepslcntl_deep_sleep_corr_en_setf(uint8_t deepsleepcorren) +{ + ASSERT_ERR((((uint32_t)deepsleepcorren << 3) & ~((uint32_t)0x00000008)) == 0); + REG_BLE_WR(BLE_DEEPSLCNTL_ADDR, (REG_BLE_RD(BLE_DEEPSLCNTL_ADDR) & ~((uint32_t)0x00000008)) | ((uint32_t)deepsleepcorren << 3)); +} + +__INLINE uint8_t ble_deepslcntl_deep_sleep_on_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE void ble_deepslcntl_deep_sleep_on_setf(uint8_t deepsleepon) +{ + ASSERT_ERR((((uint32_t)deepsleepon << 2) & ~((uint32_t)0x00000004)) == 0); + REG_BLE_WR(BLE_DEEPSLCNTL_ADDR, (REG_BLE_RD(BLE_DEEPSLCNTL_ADDR) & ~((uint32_t)0x00000004)) | ((uint32_t)deepsleepon << 2)); +} + +__INLINE uint8_t ble_deepslcntl_radio_sleep_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ble_deepslcntl_radio_sleep_en_setf(uint8_t radiosleepen) +{ + ASSERT_ERR((((uint32_t)radiosleepen << 1) & ~((uint32_t)0x00000002)) == 0); + REG_BLE_WR(BLE_DEEPSLCNTL_ADDR, (REG_BLE_RD(BLE_DEEPSLCNTL_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)radiosleepen << 1)); +} + +__INLINE uint8_t ble_deepslcntl_osc_sleep_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ble_deepslcntl_osc_sleep_en_setf(uint8_t oscsleepen) +{ + ASSERT_ERR((((uint32_t)oscsleepen << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_DEEPSLCNTL_ADDR, (REG_BLE_RD(BLE_DEEPSLCNTL_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)oscsleepen << 0)); +} + +/** + * @brief DEEPSLWKUP register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00           DEEPSLTIME   0x0
+ * 
+ */ +#define BLE_DEEPSLWKUP_ADDR BASEBAND_REG_BASE +0x34 //0x50800034 +#define BLE_DEEPSLWKUP_OFFSET 0x00000034 +#define BLE_DEEPSLWKUP_INDEX 0x0000000D +#define BLE_DEEPSLWKUP_RESET 0x00000000 + +__INLINE uint32_t ble_deepslwkup_get(void) +{ + return REG_BLE_RD(BLE_DEEPSLWKUP_ADDR); +} + +__INLINE void ble_deepslwkup_set(uint32_t value) +{ + REG_BLE_WR(BLE_DEEPSLWKUP_ADDR, value); +} + +// field definitions +#define BLE_DEEPSLTIME_MASK ((uint32_t)0xFFFFFFFF) +#define BLE_DEEPSLTIME_LSB 0 +#define BLE_DEEPSLTIME_WIDTH ((uint32_t)0x00000020) + +#define BLE_DEEPSLTIME_RST 0x0 + +__INLINE uint32_t ble_deepslwkup_deepsltime_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEEPSLWKUP_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_deepslwkup_deepsltime_setf(uint32_t deepsltime) +{ + ASSERT_ERR((((uint32_t)deepsltime << 0) & ~((uint32_t)0xFFFFFFFF)) == 0); + REG_BLE_WR(BLE_DEEPSLWKUP_ADDR, (uint32_t)deepsltime << 0); +} + +/** + * @brief DEEPSLSTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00            DEEPSLDUR   0x0
+ * 
+ */ +#define BLE_DEEPSLSTAT_ADDR BASEBAND_REG_BASE +0x38 //0x50800038 +#define BLE_DEEPSLSTAT_OFFSET 0x00000038 +#define BLE_DEEPSLSTAT_INDEX 0x0000000E +#define BLE_DEEPSLSTAT_RESET 0x00000000 + +__INLINE uint32_t ble_deepslstat_get(void) +{ + return REG_BLE_RD(BLE_DEEPSLSTAT_ADDR); +} + +// field definitions +#define BLE_DEEPSLDUR_MASK ((uint32_t)0xFFFFFFFF) +#define BLE_DEEPSLDUR_LSB 0 +#define BLE_DEEPSLDUR_WIDTH ((uint32_t)0x00000020) + +#define BLE_DEEPSLDUR_RST 0x0 + +__INLINE uint32_t ble_deepslstat_deepsldur_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEEPSLSTAT_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief ENBPRESET register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:21                TWEXT   0x0
+ *  20:10                TWOSC   0x0
+ *  09:00                 TWRM   0x0
+ * 
+ */ +#define BLE_ENBPRESET_ADDR BASEBAND_REG_BASE +0x3C //0x5080003C +#define BLE_ENBPRESET_OFFSET 0x0000003C +#define BLE_ENBPRESET_INDEX 0x0000000F +#define BLE_ENBPRESET_RESET 0x00000000 + +__INLINE uint32_t ble_enbpreset_get(void) +{ + return REG_BLE_RD(BLE_ENBPRESET_ADDR); +} + +__INLINE void ble_enbpreset_set(uint32_t value) +{ + REG_BLE_WR(BLE_ENBPRESET_ADDR, value); +} + +// field definitions +#define BLE_TWEXT_MASK ((uint32_t)0xFFE00000) +#define BLE_TWEXT_LSB 21 +#define BLE_TWEXT_WIDTH ((uint32_t)0x0000000B) +#define BLE_TWOSC_MASK ((uint32_t)0x001FFC00) +#define BLE_TWOSC_LSB 10 +#define BLE_TWOSC_WIDTH ((uint32_t)0x0000000B) +#define BLE_TWRM_MASK ((uint32_t)0x000003FF) +#define BLE_TWRM_LSB 0 +#define BLE_TWRM_WIDTH ((uint32_t)0x0000000A) + +#define BLE_TWEXT_RST 0x0 +#define BLE_TWOSC_RST 0x0 +#define BLE_TWRM_RST 0x0 + +__INLINE void ble_enbpreset_pack(uint16_t twext, uint16_t twosc, uint16_t twrm) +{ + ASSERT_ERR((((uint32_t)twext << 21) & ~((uint32_t)0xFFE00000)) == 0); + ASSERT_ERR((((uint32_t)twosc << 10) & ~((uint32_t)0x001FFC00)) == 0); + ASSERT_ERR((((uint32_t)twrm << 0) & ~((uint32_t)0x000003FF)) == 0); + REG_BLE_WR(BLE_ENBPRESET_ADDR, ((uint32_t)twext << 21) | ((uint32_t)twosc << 10) | ((uint32_t)twrm << 0)); +} + +__INLINE void ble_enbpreset_unpack(uint16_t* twext, uint16_t* twosc, uint16_t* twrm) +{ + uint32_t localVal = REG_BLE_RD(BLE_ENBPRESET_ADDR); + + *twext = (localVal & ((uint32_t)0xFFE00000)) >> 21; + *twosc = (localVal & ((uint32_t)0x001FFC00)) >> 10; + *twrm = (localVal & ((uint32_t)0x000003FF)) >> 0; +} + +__INLINE uint16_t ble_enbpreset_twext_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ENBPRESET_ADDR); + return ((localVal & ((uint32_t)0xFFE00000)) >> 21); +} + +__INLINE void ble_enbpreset_twext_setf(uint16_t twext) +{ + ASSERT_ERR((((uint32_t)twext << 21) & ~((uint32_t)0xFFE00000)) == 0); + REG_BLE_WR(BLE_ENBPRESET_ADDR, (REG_BLE_RD(BLE_ENBPRESET_ADDR) & ~((uint32_t)0xFFE00000)) | ((uint32_t)twext << 21)); +} + +__INLINE uint16_t ble_enbpreset_twosc_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ENBPRESET_ADDR); + return ((localVal & ((uint32_t)0x001FFC00)) >> 10); +} + +__INLINE void ble_enbpreset_twosc_setf(uint16_t twosc) +{ + ASSERT_ERR((((uint32_t)twosc << 10) & ~((uint32_t)0x001FFC00)) == 0); + REG_BLE_WR(BLE_ENBPRESET_ADDR, (REG_BLE_RD(BLE_ENBPRESET_ADDR) & ~((uint32_t)0x001FFC00)) | ((uint32_t)twosc << 10)); +} + +__INLINE uint16_t ble_enbpreset_twrm_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ENBPRESET_ADDR); + return ((localVal & ((uint32_t)0x000003FF)) >> 0); +} + +__INLINE void ble_enbpreset_twrm_setf(uint16_t twrm) +{ + ASSERT_ERR((((uint32_t)twrm << 0) & ~((uint32_t)0x000003FF)) == 0); + REG_BLE_WR(BLE_ENBPRESET_ADDR, (REG_BLE_RD(BLE_ENBPRESET_ADDR) & ~((uint32_t)0x000003FF)) | ((uint32_t)twrm << 0)); +} + +/** + * @brief FINECNTCORR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00          FINECNTCORR   0x0
+ * 
+ */ +#define BLE_FINECNTCORR_ADDR BASEBAND_REG_BASE +0x40 //0x50800040 +#define BLE_FINECNTCORR_OFFSET 0x00000040 +#define BLE_FINECNTCORR_INDEX 0x00000010 +#define BLE_FINECNTCORR_RESET 0x00000000 + +__INLINE uint32_t ble_finecntcorr_get(void) +{ + return REG_BLE_RD(BLE_FINECNTCORR_ADDR); +} + +__INLINE void ble_finecntcorr_set(uint32_t value) +{ + REG_BLE_WR(BLE_FINECNTCORR_ADDR, value); +} + +// field definitions +#define BLE_FINECNTCORR_MASK ((uint32_t)0x000003FF) +#define BLE_FINECNTCORR_LSB 0 +#define BLE_FINECNTCORR_WIDTH ((uint32_t)0x0000000A) + +#define BLE_FINECNTCORR_RST 0x0 + +__INLINE uint16_t ble_finecntcorr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_FINECNTCORR_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_finecntcorr_setf(uint16_t finecntcorr) +{ + ASSERT_ERR((((uint32_t)finecntcorr << 0) & ~((uint32_t)0x000003FF)) == 0); + REG_BLE_WR(BLE_FINECNTCORR_ADDR, (uint32_t)finecntcorr << 0); +} + +/** + * @brief CLKNCNTCORR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31            ABS_DELTA   0
+ *  27:00          CLKNCNTCORR   0x0
+ * 
+ */ +#define BLE_CLKNCNTCORR_ADDR BASEBAND_REG_BASE +0x44 // 0x50800044 +#define BLE_CLKNCNTCORR_OFFSET 0x00000044 +#define BLE_CLKNCNTCORR_INDEX 0x00000011 +#define BLE_CLKNCNTCORR_RESET 0x00000000 + +__INLINE uint32_t ble_clkncntcorr_get(void) +{ + return REG_BLE_RD(BLE_CLKNCNTCORR_ADDR); +} + +__INLINE void ble_clkncntcorr_set(uint32_t value) +{ + REG_BLE_WR(BLE_CLKNCNTCORR_ADDR, value); +} + +// field definitions +#define BLE_ABS_DELTA_BIT ((uint32_t)0x80000000) +#define BLE_ABS_DELTA_POS 31 +#define BLE_CLKNCNTCORR_MASK ((uint32_t)0x0FFFFFFF) +#define BLE_CLKNCNTCORR_LSB 0 +#define BLE_CLKNCNTCORR_WIDTH ((uint32_t)0x0000001C) + +#define BLE_ABS_DELTA_RST 0x0 +#define BLE_CLKNCNTCORR_RST 0x0 + +__INLINE void ble_clkncntcorr_pack(uint8_t absdelta, uint32_t clkncntcorr) +{ + ASSERT_ERR((((uint32_t)absdelta << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)clkncntcorr << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_BLE_WR(BLE_CLKNCNTCORR_ADDR, ((uint32_t)absdelta << 31) | ((uint32_t)clkncntcorr << 0)); +} + +__INLINE void ble_clkncntcorr_unpack(uint8_t* absdelta, uint32_t* clkncntcorr) +{ + uint32_t localVal = REG_BLE_RD(BLE_CLKNCNTCORR_ADDR); + + *absdelta = (localVal & ((uint32_t)0x80000000)) >> 31; + *clkncntcorr = (localVal & ((uint32_t)0x0FFFFFFF)) >> 0; +} + +__INLINE uint8_t ble_clkncntcorr_abs_delta_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_CLKNCNTCORR_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_clkncntcorr_abs_delta_setf(uint8_t absdelta) +{ + ASSERT_ERR((((uint32_t)absdelta << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_CLKNCNTCORR_ADDR, (REG_BLE_RD(BLE_CLKNCNTCORR_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)absdelta << 31)); +} + +__INLINE uint32_t ble_clkncntcorr_clkncntcorr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_CLKNCNTCORR_ADDR); + return ((localVal & ((uint32_t)0x0FFFFFFF)) >> 0); +} + +__INLINE void ble_clkncntcorr_clkncntcorr_setf(uint32_t clkncntcorr) +{ + ASSERT_ERR((((uint32_t)clkncntcorr << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_BLE_WR(BLE_CLKNCNTCORR_ADDR, (REG_BLE_RD(BLE_CLKNCNTCORR_ADDR) & ~((uint32_t)0x0FFFFFFF)) | ((uint32_t)clkncntcorr << 0)); +} + +/** + * @brief DIAGCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31             DIAG3_EN   0
+ *  30:24                DIAG3   0x0
+ *     23             DIAG2_EN   0
+ *  22:16                DIAG2   0x0
+ *     15             DIAG1_EN   0
+ *  14:08                DIAG1   0x0
+ *     07             DIAG0_EN   0
+ *  06:00                DIAG0   0x0
+ * 
+ */ +#define BLE_DIAGCNTL_ADDR BASEBAND_REG_BASE +0x50 //0x50800050 +#define BLE_DIAGCNTL_OFFSET 0x00000050 +#define BLE_DIAGCNTL_INDEX 0x00000014 +#define BLE_DIAGCNTL_RESET 0x00000000 + +__INLINE uint32_t ble_diagcntl_get(void) +{ + return REG_BLE_RD(BLE_DIAGCNTL_ADDR); +} + +__INLINE void ble_diagcntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_DIAGCNTL_ADDR, value); +} + +// field definitions +#define BLE_DIAG3_EN_BIT ((uint32_t)0x80000000) +#define BLE_DIAG3_EN_POS 31 +#define BLE_DIAG3_MASK ((uint32_t)0x7F000000) +#define BLE_DIAG3_LSB 24 +#define BLE_DIAG3_WIDTH ((uint32_t)0x00000007) +#define BLE_DIAG2_EN_BIT ((uint32_t)0x00800000) +#define BLE_DIAG2_EN_POS 23 +#define BLE_DIAG2_MASK ((uint32_t)0x007F0000) +#define BLE_DIAG2_LSB 16 +#define BLE_DIAG2_WIDTH ((uint32_t)0x00000007) +#define BLE_DIAG1_EN_BIT ((uint32_t)0x00008000) +#define BLE_DIAG1_EN_POS 15 +#define BLE_DIAG1_MASK ((uint32_t)0x00007F00) +#define BLE_DIAG1_LSB 8 +#define BLE_DIAG1_WIDTH ((uint32_t)0x00000007) +#define BLE_DIAG0_EN_BIT ((uint32_t)0x00000080) +#define BLE_DIAG0_EN_POS 7 +#define BLE_DIAG0_MASK ((uint32_t)0x0000007F) +#define BLE_DIAG0_LSB 0 +#define BLE_DIAG0_WIDTH ((uint32_t)0x00000007) + +#define BLE_DIAG3_EN_RST 0x0 +#define BLE_DIAG3_RST 0x0 +#define BLE_DIAG2_EN_RST 0x0 +#define BLE_DIAG2_RST 0x0 +#define BLE_DIAG1_EN_RST 0x0 +#define BLE_DIAG1_RST 0x0 +#define BLE_DIAG0_EN_RST 0x0 +#define BLE_DIAG0_RST 0x0 + +__INLINE void ble_diagcntl_pack(uint8_t diag3en, uint8_t diag3, uint8_t diag2en, uint8_t diag2, uint8_t diag1en, uint8_t diag1, uint8_t diag0en, uint8_t diag0) +{ + ASSERT_ERR((((uint32_t)diag3en << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)diag3 << 24) & ~((uint32_t)0x7F000000)) == 0); + ASSERT_ERR((((uint32_t)diag2en << 23) & ~((uint32_t)0x00800000)) == 0); + ASSERT_ERR((((uint32_t)diag2 << 16) & ~((uint32_t)0x007F0000)) == 0); + ASSERT_ERR((((uint32_t)diag1en << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)diag1 << 8) & ~((uint32_t)0x00007F00)) == 0); + ASSERT_ERR((((uint32_t)diag0en << 7) & ~((uint32_t)0x00000080)) == 0); + ASSERT_ERR((((uint32_t)diag0 << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_DIAGCNTL_ADDR, ((uint32_t)diag3en << 31) | ((uint32_t)diag3 << 24) | ((uint32_t)diag2en << 23) | ((uint32_t)diag2 << 16) | ((uint32_t)diag1en << 15) | ((uint32_t)diag1 << 8) | ((uint32_t)diag0en << 7) | ((uint32_t)diag0 << 0)); +} + +__INLINE void ble_diagcntl_unpack(uint8_t* diag3en, uint8_t* diag3, uint8_t* diag2en, uint8_t* diag2, uint8_t* diag1en, uint8_t* diag1, uint8_t* diag0en, uint8_t* diag0) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGCNTL_ADDR); + + *diag3en = (localVal & ((uint32_t)0x80000000)) >> 31; + *diag3 = (localVal & ((uint32_t)0x7F000000)) >> 24; + *diag2en = (localVal & ((uint32_t)0x00800000)) >> 23; + *diag2 = (localVal & ((uint32_t)0x007F0000)) >> 16; + *diag1en = (localVal & ((uint32_t)0x00008000)) >> 15; + *diag1 = (localVal & ((uint32_t)0x00007F00)) >> 8; + *diag0en = (localVal & ((uint32_t)0x00000080)) >> 7; + *diag0 = (localVal & ((uint32_t)0x0000007F)) >> 0; +} + +__INLINE uint8_t ble_diagcntl_diag3_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_diagcntl_diag3_en_setf(uint8_t diag3en) +{ + ASSERT_ERR((((uint32_t)diag3en << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_DIAGCNTL_ADDR, (REG_BLE_RD(BLE_DIAGCNTL_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)diag3en << 31)); +} + +__INLINE uint8_t ble_diagcntl_diag3_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x7F000000)) >> 24); +} + +__INLINE void ble_diagcntl_diag3_setf(uint8_t diag3) +{ + ASSERT_ERR((((uint32_t)diag3 << 24) & ~((uint32_t)0x7F000000)) == 0); + REG_BLE_WR(BLE_DIAGCNTL_ADDR, (REG_BLE_RD(BLE_DIAGCNTL_ADDR) & ~((uint32_t)0x7F000000)) | ((uint32_t)diag3 << 24)); +} + +__INLINE uint8_t ble_diagcntl_diag2_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x00800000)) >> 23); +} + +__INLINE void ble_diagcntl_diag2_en_setf(uint8_t diag2en) +{ + ASSERT_ERR((((uint32_t)diag2en << 23) & ~((uint32_t)0x00800000)) == 0); + REG_BLE_WR(BLE_DIAGCNTL_ADDR, (REG_BLE_RD(BLE_DIAGCNTL_ADDR) & ~((uint32_t)0x00800000)) | ((uint32_t)diag2en << 23)); +} + +__INLINE uint8_t ble_diagcntl_diag2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x007F0000)) >> 16); +} + +__INLINE void ble_diagcntl_diag2_setf(uint8_t diag2) +{ + ASSERT_ERR((((uint32_t)diag2 << 16) & ~((uint32_t)0x007F0000)) == 0); + REG_BLE_WR(BLE_DIAGCNTL_ADDR, (REG_BLE_RD(BLE_DIAGCNTL_ADDR) & ~((uint32_t)0x007F0000)) | ((uint32_t)diag2 << 16)); +} + +__INLINE uint8_t ble_diagcntl_diag1_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ble_diagcntl_diag1_en_setf(uint8_t diag1en) +{ + ASSERT_ERR((((uint32_t)diag1en << 15) & ~((uint32_t)0x00008000)) == 0); + REG_BLE_WR(BLE_DIAGCNTL_ADDR, (REG_BLE_RD(BLE_DIAGCNTL_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)diag1en << 15)); +} + +__INLINE uint8_t ble_diagcntl_diag1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x00007F00)) >> 8); +} + +__INLINE void ble_diagcntl_diag1_setf(uint8_t diag1) +{ + ASSERT_ERR((((uint32_t)diag1 << 8) & ~((uint32_t)0x00007F00)) == 0); + REG_BLE_WR(BLE_DIAGCNTL_ADDR, (REG_BLE_RD(BLE_DIAGCNTL_ADDR) & ~((uint32_t)0x00007F00)) | ((uint32_t)diag1 << 8)); +} + +__INLINE uint8_t ble_diagcntl_diag0_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE void ble_diagcntl_diag0_en_setf(uint8_t diag0en) +{ + ASSERT_ERR((((uint32_t)diag0en << 7) & ~((uint32_t)0x00000080)) == 0); + REG_BLE_WR(BLE_DIAGCNTL_ADDR, (REG_BLE_RD(BLE_DIAGCNTL_ADDR) & ~((uint32_t)0x00000080)) | ((uint32_t)diag0en << 7)); +} + +__INLINE uint8_t ble_diagcntl_diag0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x0000007F)) >> 0); +} + +__INLINE void ble_diagcntl_diag0_setf(uint8_t diag0) +{ + ASSERT_ERR((((uint32_t)diag0 << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_DIAGCNTL_ADDR, (REG_BLE_RD(BLE_DIAGCNTL_ADDR) & ~((uint32_t)0x0000007F)) | ((uint32_t)diag0 << 0)); +} + +/** + * @brief DIAGSTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24            DIAG3STAT   0x0
+ *  23:16            DIAG2STAT   0x0
+ *  15:08            DIAG1STAT   0x0
+ *  07:00            DIAG0STAT   0x0
+ * 
+ */ +#define BLE_DIAGSTAT_ADDR BASEBAND_REG_BASE +0x54 //0x50800054 +#define BLE_DIAGSTAT_OFFSET 0x00000054 +#define BLE_DIAGSTAT_INDEX 0x00000015 +#define BLE_DIAGSTAT_RESET 0x00000000 + +__INLINE uint32_t ble_diagstat_get(void) +{ + return REG_BLE_RD(BLE_DIAGSTAT_ADDR); +} + +// field definitions +#define BLE_DIAG3STAT_MASK ((uint32_t)0xFF000000) +#define BLE_DIAG3STAT_LSB 24 +#define BLE_DIAG3STAT_WIDTH ((uint32_t)0x00000008) +#define BLE_DIAG2STAT_MASK ((uint32_t)0x00FF0000) +#define BLE_DIAG2STAT_LSB 16 +#define BLE_DIAG2STAT_WIDTH ((uint32_t)0x00000008) +#define BLE_DIAG1STAT_MASK ((uint32_t)0x0000FF00) +#define BLE_DIAG1STAT_LSB 8 +#define BLE_DIAG1STAT_WIDTH ((uint32_t)0x00000008) +#define BLE_DIAG0STAT_MASK ((uint32_t)0x000000FF) +#define BLE_DIAG0STAT_LSB 0 +#define BLE_DIAG0STAT_WIDTH ((uint32_t)0x00000008) + +#define BLE_DIAG3STAT_RST 0x0 +#define BLE_DIAG2STAT_RST 0x0 +#define BLE_DIAG1STAT_RST 0x0 +#define BLE_DIAG0STAT_RST 0x0 + +__INLINE void ble_diagstat_unpack(uint8_t* diag3stat, uint8_t* diag2stat, uint8_t* diag1stat, uint8_t* diag0stat) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGSTAT_ADDR); + + *diag3stat = (localVal & ((uint32_t)0xFF000000)) >> 24; + *diag2stat = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *diag1stat = (localVal & ((uint32_t)0x0000FF00)) >> 8; + *diag0stat = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_diagstat_diag3stat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGSTAT_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE uint8_t ble_diagstat_diag2stat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGSTAT_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE uint8_t ble_diagstat_diag1stat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGSTAT_ADDR); + return ((localVal & ((uint32_t)0x0000FF00)) >> 8); +} + +__INLINE uint8_t ble_diagstat_diag0stat_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DIAGSTAT_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +/** + * @brief DEBUGADDMAX register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:16           REG_ADDMAX   0x0
+ *  15:00            EM_ADDMAX   0x0
+ * 
+ */ +#define BLE_DEBUGADDMAX_ADDR BASEBAND_REG_BASE +0x58 //0x50800058 +#define BLE_DEBUGADDMAX_OFFSET 0x00000058 +#define BLE_DEBUGADDMAX_INDEX 0x00000016 +#define BLE_DEBUGADDMAX_RESET 0x00000000 + +__INLINE uint32_t ble_debugaddmax_get(void) +{ + return REG_BLE_RD(BLE_DEBUGADDMAX_ADDR); +} + +__INLINE void ble_debugaddmax_set(uint32_t value) +{ + REG_BLE_WR(BLE_DEBUGADDMAX_ADDR, value); +} + +// field definitions +#define BLE_REG_ADDMAX_MASK ((uint32_t)0xFFFF0000) +#define BLE_REG_ADDMAX_LSB 16 +#define BLE_REG_ADDMAX_WIDTH ((uint32_t)0x00000010) +#define BLE_EM_ADDMAX_MASK ((uint32_t)0x0000FFFF) +#define BLE_EM_ADDMAX_LSB 0 +#define BLE_EM_ADDMAX_WIDTH ((uint32_t)0x00000010) + +#define BLE_REG_ADDMAX_RST 0x0 +#define BLE_EM_ADDMAX_RST 0x0 + +__INLINE void ble_debugaddmax_pack(uint16_t regaddmax, uint16_t emaddmax) +{ + ASSERT_ERR((((uint32_t)regaddmax << 16) & ~((uint32_t)0xFFFF0000)) == 0); + ASSERT_ERR((((uint32_t)emaddmax << 0) & ~((uint32_t)0x0000FFFF)) == 0); + REG_BLE_WR(BLE_DEBUGADDMAX_ADDR, ((uint32_t)regaddmax << 16) | ((uint32_t)emaddmax << 0)); +} + +__INLINE void ble_debugaddmax_unpack(uint16_t* regaddmax, uint16_t* emaddmax) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEBUGADDMAX_ADDR); + + *regaddmax = (localVal & ((uint32_t)0xFFFF0000)) >> 16; + *emaddmax = (localVal & ((uint32_t)0x0000FFFF)) >> 0; +} + +__INLINE uint16_t ble_debugaddmax_reg_addmax_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEBUGADDMAX_ADDR); + return ((localVal & ((uint32_t)0xFFFF0000)) >> 16); +} + +__INLINE void ble_debugaddmax_reg_addmax_setf(uint16_t regaddmax) +{ + ASSERT_ERR((((uint32_t)regaddmax << 16) & ~((uint32_t)0xFFFF0000)) == 0); + REG_BLE_WR(BLE_DEBUGADDMAX_ADDR, (REG_BLE_RD(BLE_DEBUGADDMAX_ADDR) & ~((uint32_t)0xFFFF0000)) | ((uint32_t)regaddmax << 16)); +} + +__INLINE uint16_t ble_debugaddmax_em_addmax_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEBUGADDMAX_ADDR); + return ((localVal & ((uint32_t)0x0000FFFF)) >> 0); +} + +__INLINE void ble_debugaddmax_em_addmax_setf(uint16_t emaddmax) +{ + ASSERT_ERR((((uint32_t)emaddmax << 0) & ~((uint32_t)0x0000FFFF)) == 0); + REG_BLE_WR(BLE_DEBUGADDMAX_ADDR, (REG_BLE_RD(BLE_DEBUGADDMAX_ADDR) & ~((uint32_t)0x0000FFFF)) | ((uint32_t)emaddmax << 0)); +} + +/** + * @brief DEBUGADDMIN register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:16           REG_ADDMIN   0x0
+ *  15:00            EM_ADDMIN   0x0
+ * 
+ */ +#define BLE_DEBUGADDMIN_ADDR BASEBAND_REG_BASE +0x5C //0x5080005C +#define BLE_DEBUGADDMIN_OFFSET 0x0000005C +#define BLE_DEBUGADDMIN_INDEX 0x00000017 +#define BLE_DEBUGADDMIN_RESET 0x00000000 + +__INLINE uint32_t ble_debugaddmin_get(void) +{ + return REG_BLE_RD(BLE_DEBUGADDMIN_ADDR); +} + +__INLINE void ble_debugaddmin_set(uint32_t value) +{ + REG_BLE_WR(BLE_DEBUGADDMIN_ADDR, value); +} + +// field definitions +#define BLE_REG_ADDMIN_MASK ((uint32_t)0xFFFF0000) +#define BLE_REG_ADDMIN_LSB 16 +#define BLE_REG_ADDMIN_WIDTH ((uint32_t)0x00000010) +#define BLE_EM_ADDMIN_MASK ((uint32_t)0x0000FFFF) +#define BLE_EM_ADDMIN_LSB 0 +#define BLE_EM_ADDMIN_WIDTH ((uint32_t)0x00000010) + +#define BLE_REG_ADDMIN_RST 0x0 +#define BLE_EM_ADDMIN_RST 0x0 + +__INLINE void ble_debugaddmin_pack(uint16_t regaddmin, uint16_t emaddmin) +{ + ASSERT_ERR((((uint32_t)regaddmin << 16) & ~((uint32_t)0xFFFF0000)) == 0); + ASSERT_ERR((((uint32_t)emaddmin << 0) & ~((uint32_t)0x0000FFFF)) == 0); + REG_BLE_WR(BLE_DEBUGADDMIN_ADDR, ((uint32_t)regaddmin << 16) | ((uint32_t)emaddmin << 0)); +} + +__INLINE void ble_debugaddmin_unpack(uint16_t* regaddmin, uint16_t* emaddmin) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEBUGADDMIN_ADDR); + + *regaddmin = (localVal & ((uint32_t)0xFFFF0000)) >> 16; + *emaddmin = (localVal & ((uint32_t)0x0000FFFF)) >> 0; +} + +__INLINE uint16_t ble_debugaddmin_reg_addmin_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEBUGADDMIN_ADDR); + return ((localVal & ((uint32_t)0xFFFF0000)) >> 16); +} + +__INLINE void ble_debugaddmin_reg_addmin_setf(uint16_t regaddmin) +{ + ASSERT_ERR((((uint32_t)regaddmin << 16) & ~((uint32_t)0xFFFF0000)) == 0); + REG_BLE_WR(BLE_DEBUGADDMIN_ADDR, (REG_BLE_RD(BLE_DEBUGADDMIN_ADDR) & ~((uint32_t)0xFFFF0000)) | ((uint32_t)regaddmin << 16)); +} + +__INLINE uint16_t ble_debugaddmin_em_addmin_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DEBUGADDMIN_ADDR); + return ((localVal & ((uint32_t)0x0000FFFF)) >> 0); +} + +__INLINE void ble_debugaddmin_em_addmin_setf(uint16_t emaddmin) +{ + ASSERT_ERR((((uint32_t)emaddmin << 0) & ~((uint32_t)0x0000FFFF)) == 0); + REG_BLE_WR(BLE_DEBUGADDMIN_ADDR, (REG_BLE_RD(BLE_DEBUGADDMIN_ADDR) & ~((uint32_t)0x0000FFFF)) | ((uint32_t)emaddmin << 0)); +} + +/** + * @brief ERRORTYPESTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     22   DFCNTL_EMACC_ERROR   0
+ *     21           FIFOINTOVF   0
+ *     20            PHY_ERROR   0
+ *     19   TXAEHEADER_PTR_ERROR   0
+ *     18       TMAFS_UNDERRUN   0
+ *     17         RAL_UNDERRUN   0
+ *     16            RAL_ERROR   0
+ *     15     RXDATA_PTR_ERROR   0
+ *     14     TXDATA_PTR_ERROR   0
+ *     13   RXDESC_EMPTY_ERROR   0
+ *     12   TXDESC_EMPTY_ERROR   0
+ *     11       CSFORMAT_ERROR   0
+ *     10        LLCHMAP_ERROR   0
+ *     09         ADV_UNDERRUN   0
+ *     08         IFS_UNDERRUN   0
+ *     07           LIST_ERROR   0
+ *     06   EVT_CNTL_APFM_ERROR   0
+ *     05   ACT_SCHDL_APFM_ERROR   0
+ *     04   ACT_SCHDL_ENTRY_ERROR   0
+ *     03    RADIO_EMACC_ERROR   0
+ *     02   PKTCNTL_EMACC_ERROR   0
+ *     01        RXCRYPT_ERROR   0
+ *     00        TXCRYPT_ERROR   0
+ * 
+ */ +#define BLE_ERRORTYPESTAT_ADDR BASEBAND_REG_BASE +0x60 //0x50800060 +#define BLE_ERRORTYPESTAT_OFFSET 0x00000060 +#define BLE_ERRORTYPESTAT_INDEX 0x00000018 +#define BLE_ERRORTYPESTAT_RESET 0x00000000 + +__INLINE uint32_t ble_errortypestat_get(void) +{ + return REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); +} + +// field definitions +#define BLE_DFCNTL_EMACC_ERROR_BIT ((uint32_t)0x00400000) +#define BLE_DFCNTL_EMACC_ERROR_POS 22 +#define BLE_FIFOINTOVF_BIT ((uint32_t)0x00200000) +#define BLE_FIFOINTOVF_POS 21 +#define BLE_PHY_ERROR_BIT ((uint32_t)0x00100000) +#define BLE_PHY_ERROR_POS 20 +#define BLE_TXAEHEADER_PTR_ERROR_BIT ((uint32_t)0x00080000) +#define BLE_TXAEHEADER_PTR_ERROR_POS 19 +#define BLE_TMAFS_UNDERRUN_BIT ((uint32_t)0x00040000) +#define BLE_TMAFS_UNDERRUN_POS 18 +#define BLE_RAL_UNDERRUN_BIT ((uint32_t)0x00020000) +#define BLE_RAL_UNDERRUN_POS 17 +#define BLE_RAL_ERROR_BIT ((uint32_t)0x00010000) +#define BLE_RAL_ERROR_POS 16 +#define BLE_RXDATA_PTR_ERROR_BIT ((uint32_t)0x00008000) +#define BLE_RXDATA_PTR_ERROR_POS 15 +#define BLE_TXDATA_PTR_ERROR_BIT ((uint32_t)0x00004000) +#define BLE_TXDATA_PTR_ERROR_POS 14 +#define BLE_RXDESC_EMPTY_ERROR_BIT ((uint32_t)0x00002000) +#define BLE_RXDESC_EMPTY_ERROR_POS 13 +#define BLE_TXDESC_EMPTY_ERROR_BIT ((uint32_t)0x00001000) +#define BLE_TXDESC_EMPTY_ERROR_POS 12 +#define BLE_CSFORMAT_ERROR_BIT ((uint32_t)0x00000800) +#define BLE_CSFORMAT_ERROR_POS 11 +#define BLE_LLCHMAP_ERROR_BIT ((uint32_t)0x00000400) +#define BLE_LLCHMAP_ERROR_POS 10 +#define BLE_ADV_UNDERRUN_BIT ((uint32_t)0x00000200) +#define BLE_ADV_UNDERRUN_POS 9 +#define BLE_IFS_UNDERRUN_BIT ((uint32_t)0x00000100) +#define BLE_IFS_UNDERRUN_POS 8 +#define BLE_LIST_ERROR_BIT ((uint32_t)0x00000080) +#define BLE_LIST_ERROR_POS 7 +#define BLE_EVT_CNTL_APFM_ERROR_BIT ((uint32_t)0x00000040) +#define BLE_EVT_CNTL_APFM_ERROR_POS 6 +#define BLE_ACT_SCHDL_APFM_ERROR_BIT ((uint32_t)0x00000020) +#define BLE_ACT_SCHDL_APFM_ERROR_POS 5 +#define BLE_ACT_SCHDL_ENTRY_ERROR_BIT ((uint32_t)0x00000010) +#define BLE_ACT_SCHDL_ENTRY_ERROR_POS 4 +#define BLE_RADIO_EMACC_ERROR_BIT ((uint32_t)0x00000008) +#define BLE_RADIO_EMACC_ERROR_POS 3 +#define BLE_PKTCNTL_EMACC_ERROR_BIT ((uint32_t)0x00000004) +#define BLE_PKTCNTL_EMACC_ERROR_POS 2 +#define BLE_RXCRYPT_ERROR_BIT ((uint32_t)0x00000002) +#define BLE_RXCRYPT_ERROR_POS 1 +#define BLE_TXCRYPT_ERROR_BIT ((uint32_t)0x00000001) +#define BLE_TXCRYPT_ERROR_POS 0 + +#define BLE_DFCNTL_EMACC_ERROR_RST 0x0 +#define BLE_FIFOINTOVF_RST 0x0 +#define BLE_PHY_ERROR_RST 0x0 +#define BLE_TXAEHEADER_PTR_ERROR_RST 0x0 +#define BLE_TMAFS_UNDERRUN_RST 0x0 +#define BLE_RAL_UNDERRUN_RST 0x0 +#define BLE_RAL_ERROR_RST 0x0 +#define BLE_RXDATA_PTR_ERROR_RST 0x0 +#define BLE_TXDATA_PTR_ERROR_RST 0x0 +#define BLE_RXDESC_EMPTY_ERROR_RST 0x0 +#define BLE_TXDESC_EMPTY_ERROR_RST 0x0 +#define BLE_CSFORMAT_ERROR_RST 0x0 +#define BLE_LLCHMAP_ERROR_RST 0x0 +#define BLE_ADV_UNDERRUN_RST 0x0 +#define BLE_IFS_UNDERRUN_RST 0x0 +#define BLE_LIST_ERROR_RST 0x0 +#define BLE_EVT_CNTL_APFM_ERROR_RST 0x0 +#define BLE_ACT_SCHDL_APFM_ERROR_RST 0x0 +#define BLE_ACT_SCHDL_ENTRY_ERROR_RST 0x0 +#define BLE_RADIO_EMACC_ERROR_RST 0x0 +#define BLE_PKTCNTL_EMACC_ERROR_RST 0x0 +#define BLE_RXCRYPT_ERROR_RST 0x0 +#define BLE_TXCRYPT_ERROR_RST 0x0 + +__INLINE void ble_errortypestat_unpack(uint8_t* dfcntlemaccerror, uint8_t* fifointovf, uint8_t* phyerror, uint8_t* txaeheaderptrerror, uint8_t* tmafsunderrun, uint8_t* ralunderrun, uint8_t* ralerror, uint8_t* rxdataptrerror, uint8_t* txdataptrerror, uint8_t* rxdescemptyerror, uint8_t* txdescemptyerror, uint8_t* csformaterror, uint8_t* llchmaperror, uint8_t* advunderrun, uint8_t* ifsunderrun, uint8_t* listerror, uint8_t* evtcntlapfmerror, uint8_t* actschdlapfmerror, uint8_t* actschdlentryerror, uint8_t* radioemaccerror, uint8_t* pktcntlemaccerror, uint8_t* rxcrypterror, uint8_t* txcrypterror) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + + *dfcntlemaccerror = (localVal & ((uint32_t)0x00400000)) >> 22; + *fifointovf = (localVal & ((uint32_t)0x00200000)) >> 21; + *phyerror = (localVal & ((uint32_t)0x00100000)) >> 20; + *txaeheaderptrerror = (localVal & ((uint32_t)0x00080000)) >> 19; + *tmafsunderrun = (localVal & ((uint32_t)0x00040000)) >> 18; + *ralunderrun = (localVal & ((uint32_t)0x00020000)) >> 17; + *ralerror = (localVal & ((uint32_t)0x00010000)) >> 16; + *rxdataptrerror = (localVal & ((uint32_t)0x00008000)) >> 15; + *txdataptrerror = (localVal & ((uint32_t)0x00004000)) >> 14; + *rxdescemptyerror = (localVal & ((uint32_t)0x00002000)) >> 13; + *txdescemptyerror = (localVal & ((uint32_t)0x00001000)) >> 12; + *csformaterror = (localVal & ((uint32_t)0x00000800)) >> 11; + *llchmaperror = (localVal & ((uint32_t)0x00000400)) >> 10; + *advunderrun = (localVal & ((uint32_t)0x00000200)) >> 9; + *ifsunderrun = (localVal & ((uint32_t)0x00000100)) >> 8; + *listerror = (localVal & ((uint32_t)0x00000080)) >> 7; + *evtcntlapfmerror = (localVal & ((uint32_t)0x00000040)) >> 6; + *actschdlapfmerror = (localVal & ((uint32_t)0x00000020)) >> 5; + *actschdlentryerror = (localVal & ((uint32_t)0x00000010)) >> 4; + *radioemaccerror = (localVal & ((uint32_t)0x00000008)) >> 3; + *pktcntlemaccerror = (localVal & ((uint32_t)0x00000004)) >> 2; + *rxcrypterror = (localVal & ((uint32_t)0x00000002)) >> 1; + *txcrypterror = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_errortypestat_dfcntl_emacc_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00400000)) >> 22); +} + +__INLINE uint8_t ble_errortypestat_fifointovf_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00200000)) >> 21); +} + +__INLINE uint8_t ble_errortypestat_phy_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00100000)) >> 20); +} + +__INLINE uint8_t ble_errortypestat_txaeheader_ptr_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00080000)) >> 19); +} + +__INLINE uint8_t ble_errortypestat_tmafs_underrun_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00040000)) >> 18); +} + +__INLINE uint8_t ble_errortypestat_ral_underrun_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00020000)) >> 17); +} + +__INLINE uint8_t ble_errortypestat_ral_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00010000)) >> 16); +} + +__INLINE uint8_t ble_errortypestat_rxdata_ptr_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE uint8_t ble_errortypestat_txdata_ptr_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00004000)) >> 14); +} + +__INLINE uint8_t ble_errortypestat_rxdesc_empty_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00002000)) >> 13); +} + +__INLINE uint8_t ble_errortypestat_txdesc_empty_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00001000)) >> 12); +} + +__INLINE uint8_t ble_errortypestat_csformat_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000800)) >> 11); +} + +__INLINE uint8_t ble_errortypestat_llchmap_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000400)) >> 10); +} + +__INLINE uint8_t ble_errortypestat_adv_underrun_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000200)) >> 9); +} + +__INLINE uint8_t ble_errortypestat_ifs_underrun_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000100)) >> 8); +} + +__INLINE uint8_t ble_errortypestat_list_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE uint8_t ble_errortypestat_evt_cntl_apfm_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE uint8_t ble_errortypestat_act_schdl_apfm_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE uint8_t ble_errortypestat_act_schdl_entry_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE uint8_t ble_errortypestat_radio_emacc_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE uint8_t ble_errortypestat_pktcntl_emacc_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE uint8_t ble_errortypestat_rxcrypt_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE uint8_t ble_errortypestat_txcrypt_error_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +/** + * @brief SWPROFILING register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31             SWPROF31   0
+ *     30             SWPROF30   0
+ *     29             SWPROF29   0
+ *     28             SWPROF28   0
+ *     27             SWPROF27   0
+ *     26             SWPROF26   0
+ *     25             SWPROF25   0
+ *     24             SWPROF24   0
+ *     23             SWPROF23   0
+ *     22             SWPROF22   0
+ *     21             SWPROF21   0
+ *     20             SWPROF20   0
+ *     19             SWPROF19   0
+ *     18             SWPROF18   0
+ *     17             SWPROF17   0
+ *     16             SWPROF16   0
+ *     15             SWPROF15   0
+ *     14             SWPROF14   0
+ *     13             SWPROF13   0
+ *     12             SWPROF12   0
+ *     11             SWPROF11   0
+ *     10             SWPROF10   0
+ *     09              SWPROF9   0
+ *     08              SWPROF8   0
+ *     07              SWPROF7   0
+ *     06              SWPROF6   0
+ *     05              SWPROF5   0
+ *     04              SWPROF4   0
+ *     03              SWPROF3   0
+ *     02              SWPROF2   0
+ *     01              SWPROF1   0
+ *     00              SWPROF0   0
+ * 
+ */ +#define BLE_SWPROFILING_ADDR BASEBAND_REG_BASE +0x64 //0x50800064 +#define BLE_SWPROFILING_OFFSET 0x00000064 +#define BLE_SWPROFILING_INDEX 0x00000019 +#define BLE_SWPROFILING_RESET 0x00000000 + +__INLINE uint32_t ble_swprofiling_get(void) +{ + return REG_BLE_RD(BLE_SWPROFILING_ADDR); +} + +__INLINE void ble_swprofiling_set(uint32_t value) +{ + REG_BLE_WR(BLE_SWPROFILING_ADDR, value); +} + +// field definitions +#define BLE_SWPROF31_BIT ((uint32_t)0x80000000) +#define BLE_SWPROF31_POS 31 +#define BLE_SWPROF30_BIT ((uint32_t)0x40000000) +#define BLE_SWPROF30_POS 30 +#define BLE_SWPROF29_BIT ((uint32_t)0x20000000) +#define BLE_SWPROF29_POS 29 +#define BLE_SWPROF28_BIT ((uint32_t)0x10000000) +#define BLE_SWPROF28_POS 28 +#define BLE_SWPROF27_BIT ((uint32_t)0x08000000) +#define BLE_SWPROF27_POS 27 +#define BLE_SWPROF26_BIT ((uint32_t)0x04000000) +#define BLE_SWPROF26_POS 26 +#define BLE_SWPROF25_BIT ((uint32_t)0x02000000) +#define BLE_SWPROF25_POS 25 +#define BLE_SWPROF24_BIT ((uint32_t)0x01000000) +#define BLE_SWPROF24_POS 24 +#define BLE_SWPROF23_BIT ((uint32_t)0x00800000) +#define BLE_SWPROF23_POS 23 +#define BLE_SWPROF22_BIT ((uint32_t)0x00400000) +#define BLE_SWPROF22_POS 22 +#define BLE_SWPROF21_BIT ((uint32_t)0x00200000) +#define BLE_SWPROF21_POS 21 +#define BLE_SWPROF20_BIT ((uint32_t)0x00100000) +#define BLE_SWPROF20_POS 20 +#define BLE_SWPROF19_BIT ((uint32_t)0x00080000) +#define BLE_SWPROF19_POS 19 +#define BLE_SWPROF18_BIT ((uint32_t)0x00040000) +#define BLE_SWPROF18_POS 18 +#define BLE_SWPROF17_BIT ((uint32_t)0x00020000) +#define BLE_SWPROF17_POS 17 +#define BLE_SWPROF16_BIT ((uint32_t)0x00010000) +#define BLE_SWPROF16_POS 16 +#define BLE_SWPROF15_BIT ((uint32_t)0x00008000) +#define BLE_SWPROF15_POS 15 +#define BLE_SWPROF14_BIT ((uint32_t)0x00004000) +#define BLE_SWPROF14_POS 14 +#define BLE_SWPROF13_BIT ((uint32_t)0x00002000) +#define BLE_SWPROF13_POS 13 +#define BLE_SWPROF12_BIT ((uint32_t)0x00001000) +#define BLE_SWPROF12_POS 12 +#define BLE_SWPROF11_BIT ((uint32_t)0x00000800) +#define BLE_SWPROF11_POS 11 +#define BLE_SWPROF10_BIT ((uint32_t)0x00000400) +#define BLE_SWPROF10_POS 10 +#define BLE_SWPROF9_BIT ((uint32_t)0x00000200) +#define BLE_SWPROF9_POS 9 +#define BLE_SWPROF8_BIT ((uint32_t)0x00000100) +#define BLE_SWPROF8_POS 8 +#define BLE_SWPROF7_BIT ((uint32_t)0x00000080) +#define BLE_SWPROF7_POS 7 +#define BLE_SWPROF6_BIT ((uint32_t)0x00000040) +#define BLE_SWPROF6_POS 6 +#define BLE_SWPROF5_BIT ((uint32_t)0x00000020) +#define BLE_SWPROF5_POS 5 +#define BLE_SWPROF4_BIT ((uint32_t)0x00000010) +#define BLE_SWPROF4_POS 4 +#define BLE_SWPROF3_BIT ((uint32_t)0x00000008) +#define BLE_SWPROF3_POS 3 +#define BLE_SWPROF2_BIT ((uint32_t)0x00000004) +#define BLE_SWPROF2_POS 2 +#define BLE_SWPROF1_BIT ((uint32_t)0x00000002) +#define BLE_SWPROF1_POS 1 +#define BLE_SWPROF0_BIT ((uint32_t)0x00000001) +#define BLE_SWPROF0_POS 0 + +#define BLE_SWPROF31_RST 0x0 +#define BLE_SWPROF30_RST 0x0 +#define BLE_SWPROF29_RST 0x0 +#define BLE_SWPROF28_RST 0x0 +#define BLE_SWPROF27_RST 0x0 +#define BLE_SWPROF26_RST 0x0 +#define BLE_SWPROF25_RST 0x0 +#define BLE_SWPROF24_RST 0x0 +#define BLE_SWPROF23_RST 0x0 +#define BLE_SWPROF22_RST 0x0 +#define BLE_SWPROF21_RST 0x0 +#define BLE_SWPROF20_RST 0x0 +#define BLE_SWPROF19_RST 0x0 +#define BLE_SWPROF18_RST 0x0 +#define BLE_SWPROF17_RST 0x0 +#define BLE_SWPROF16_RST 0x0 +#define BLE_SWPROF15_RST 0x0 +#define BLE_SWPROF14_RST 0x0 +#define BLE_SWPROF13_RST 0x0 +#define BLE_SWPROF12_RST 0x0 +#define BLE_SWPROF11_RST 0x0 +#define BLE_SWPROF10_RST 0x0 +#define BLE_SWPROF9_RST 0x0 +#define BLE_SWPROF8_RST 0x0 +#define BLE_SWPROF7_RST 0x0 +#define BLE_SWPROF6_RST 0x0 +#define BLE_SWPROF5_RST 0x0 +#define BLE_SWPROF4_RST 0x0 +#define BLE_SWPROF3_RST 0x0 +#define BLE_SWPROF2_RST 0x0 +#define BLE_SWPROF1_RST 0x0 +#define BLE_SWPROF0_RST 0x0 + +__INLINE void ble_swprofiling_pack(uint8_t swprof31, uint8_t swprof30, uint8_t swprof29, uint8_t swprof28, uint8_t swprof27, uint8_t swprof26, uint8_t swprof25, uint8_t swprof24, uint8_t swprof23, uint8_t swprof22, uint8_t swprof21, uint8_t swprof20, uint8_t swprof19, uint8_t swprof18, uint8_t swprof17, uint8_t swprof16, uint8_t swprof15, uint8_t swprof14, uint8_t swprof13, uint8_t swprof12, uint8_t swprof11, uint8_t swprof10, uint8_t swprof9, uint8_t swprof8, uint8_t swprof7, uint8_t swprof6, uint8_t swprof5, uint8_t swprof4, uint8_t swprof3, uint8_t swprof2, uint8_t swprof1, uint8_t swprof0) +{ + ASSERT_ERR((((uint32_t)swprof31 << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)swprof30 << 30) & ~((uint32_t)0x40000000)) == 0); + ASSERT_ERR((((uint32_t)swprof29 << 29) & ~((uint32_t)0x20000000)) == 0); + ASSERT_ERR((((uint32_t)swprof28 << 28) & ~((uint32_t)0x10000000)) == 0); + ASSERT_ERR((((uint32_t)swprof27 << 27) & ~((uint32_t)0x08000000)) == 0); + ASSERT_ERR((((uint32_t)swprof26 << 26) & ~((uint32_t)0x04000000)) == 0); + ASSERT_ERR((((uint32_t)swprof25 << 25) & ~((uint32_t)0x02000000)) == 0); + ASSERT_ERR((((uint32_t)swprof24 << 24) & ~((uint32_t)0x01000000)) == 0); + ASSERT_ERR((((uint32_t)swprof23 << 23) & ~((uint32_t)0x00800000)) == 0); + ASSERT_ERR((((uint32_t)swprof22 << 22) & ~((uint32_t)0x00400000)) == 0); + ASSERT_ERR((((uint32_t)swprof21 << 21) & ~((uint32_t)0x00200000)) == 0); + ASSERT_ERR((((uint32_t)swprof20 << 20) & ~((uint32_t)0x00100000)) == 0); + ASSERT_ERR((((uint32_t)swprof19 << 19) & ~((uint32_t)0x00080000)) == 0); + ASSERT_ERR((((uint32_t)swprof18 << 18) & ~((uint32_t)0x00040000)) == 0); + ASSERT_ERR((((uint32_t)swprof17 << 17) & ~((uint32_t)0x00020000)) == 0); + ASSERT_ERR((((uint32_t)swprof16 << 16) & ~((uint32_t)0x00010000)) == 0); + ASSERT_ERR((((uint32_t)swprof15 << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)swprof14 << 14) & ~((uint32_t)0x00004000)) == 0); + ASSERT_ERR((((uint32_t)swprof13 << 13) & ~((uint32_t)0x00002000)) == 0); + ASSERT_ERR((((uint32_t)swprof12 << 12) & ~((uint32_t)0x00001000)) == 0); + ASSERT_ERR((((uint32_t)swprof11 << 11) & ~((uint32_t)0x00000800)) == 0); + ASSERT_ERR((((uint32_t)swprof10 << 10) & ~((uint32_t)0x00000400)) == 0); + ASSERT_ERR((((uint32_t)swprof9 << 9) & ~((uint32_t)0x00000200)) == 0); + ASSERT_ERR((((uint32_t)swprof8 << 8) & ~((uint32_t)0x00000100)) == 0); + ASSERT_ERR((((uint32_t)swprof7 << 7) & ~((uint32_t)0x00000080)) == 0); + ASSERT_ERR((((uint32_t)swprof6 << 6) & ~((uint32_t)0x00000040)) == 0); + ASSERT_ERR((((uint32_t)swprof5 << 5) & ~((uint32_t)0x00000020)) == 0); + ASSERT_ERR((((uint32_t)swprof4 << 4) & ~((uint32_t)0x00000010)) == 0); + ASSERT_ERR((((uint32_t)swprof3 << 3) & ~((uint32_t)0x00000008)) == 0); + ASSERT_ERR((((uint32_t)swprof2 << 2) & ~((uint32_t)0x00000004)) == 0); + ASSERT_ERR((((uint32_t)swprof1 << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)swprof0 << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, ((uint32_t)swprof31 << 31) | ((uint32_t)swprof30 << 30) | ((uint32_t)swprof29 << 29) | ((uint32_t)swprof28 << 28) | ((uint32_t)swprof27 << 27) | ((uint32_t)swprof26 << 26) | ((uint32_t)swprof25 << 25) | ((uint32_t)swprof24 << 24) | ((uint32_t)swprof23 << 23) | ((uint32_t)swprof22 << 22) | ((uint32_t)swprof21 << 21) | ((uint32_t)swprof20 << 20) | ((uint32_t)swprof19 << 19) | ((uint32_t)swprof18 << 18) | ((uint32_t)swprof17 << 17) | ((uint32_t)swprof16 << 16) | ((uint32_t)swprof15 << 15) | ((uint32_t)swprof14 << 14) | ((uint32_t)swprof13 << 13) | ((uint32_t)swprof12 << 12) | ((uint32_t)swprof11 << 11) | ((uint32_t)swprof10 << 10) | ((uint32_t)swprof9 << 9) | ((uint32_t)swprof8 << 8) | ((uint32_t)swprof7 << 7) | ((uint32_t)swprof6 << 6) | ((uint32_t)swprof5 << 5) | ((uint32_t)swprof4 << 4) | ((uint32_t)swprof3 << 3) | ((uint32_t)swprof2 << 2) | ((uint32_t)swprof1 << 1) | ((uint32_t)swprof0 << 0)); +} + +__INLINE void ble_swprofiling_unpack(uint8_t* swprof31, uint8_t* swprof30, uint8_t* swprof29, uint8_t* swprof28, uint8_t* swprof27, uint8_t* swprof26, uint8_t* swprof25, uint8_t* swprof24, uint8_t* swprof23, uint8_t* swprof22, uint8_t* swprof21, uint8_t* swprof20, uint8_t* swprof19, uint8_t* swprof18, uint8_t* swprof17, uint8_t* swprof16, uint8_t* swprof15, uint8_t* swprof14, uint8_t* swprof13, uint8_t* swprof12, uint8_t* swprof11, uint8_t* swprof10, uint8_t* swprof9, uint8_t* swprof8, uint8_t* swprof7, uint8_t* swprof6, uint8_t* swprof5, uint8_t* swprof4, uint8_t* swprof3, uint8_t* swprof2, uint8_t* swprof1, uint8_t* swprof0) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + + *swprof31 = (localVal & ((uint32_t)0x80000000)) >> 31; + *swprof30 = (localVal & ((uint32_t)0x40000000)) >> 30; + *swprof29 = (localVal & ((uint32_t)0x20000000)) >> 29; + *swprof28 = (localVal & ((uint32_t)0x10000000)) >> 28; + *swprof27 = (localVal & ((uint32_t)0x08000000)) >> 27; + *swprof26 = (localVal & ((uint32_t)0x04000000)) >> 26; + *swprof25 = (localVal & ((uint32_t)0x02000000)) >> 25; + *swprof24 = (localVal & ((uint32_t)0x01000000)) >> 24; + *swprof23 = (localVal & ((uint32_t)0x00800000)) >> 23; + *swprof22 = (localVal & ((uint32_t)0x00400000)) >> 22; + *swprof21 = (localVal & ((uint32_t)0x00200000)) >> 21; + *swprof20 = (localVal & ((uint32_t)0x00100000)) >> 20; + *swprof19 = (localVal & ((uint32_t)0x00080000)) >> 19; + *swprof18 = (localVal & ((uint32_t)0x00040000)) >> 18; + *swprof17 = (localVal & ((uint32_t)0x00020000)) >> 17; + *swprof16 = (localVal & ((uint32_t)0x00010000)) >> 16; + *swprof15 = (localVal & ((uint32_t)0x00008000)) >> 15; + *swprof14 = (localVal & ((uint32_t)0x00004000)) >> 14; + *swprof13 = (localVal & ((uint32_t)0x00002000)) >> 13; + *swprof12 = (localVal & ((uint32_t)0x00001000)) >> 12; + *swprof11 = (localVal & ((uint32_t)0x00000800)) >> 11; + *swprof10 = (localVal & ((uint32_t)0x00000400)) >> 10; + *swprof9 = (localVal & ((uint32_t)0x00000200)) >> 9; + *swprof8 = (localVal & ((uint32_t)0x00000100)) >> 8; + *swprof7 = (localVal & ((uint32_t)0x00000080)) >> 7; + *swprof6 = (localVal & ((uint32_t)0x00000040)) >> 6; + *swprof5 = (localVal & ((uint32_t)0x00000020)) >> 5; + *swprof4 = (localVal & ((uint32_t)0x00000010)) >> 4; + *swprof3 = (localVal & ((uint32_t)0x00000008)) >> 3; + *swprof2 = (localVal & ((uint32_t)0x00000004)) >> 2; + *swprof1 = (localVal & ((uint32_t)0x00000002)) >> 1; + *swprof0 = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_swprofiling_swprof31_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_swprofiling_swprof31_setf(uint8_t swprof31) +{ + ASSERT_ERR((((uint32_t)swprof31 << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)swprof31 << 31)); +} + +__INLINE uint8_t ble_swprofiling_swprof30_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x40000000)) >> 30); +} + +__INLINE void ble_swprofiling_swprof30_setf(uint8_t swprof30) +{ + ASSERT_ERR((((uint32_t)swprof30 << 30) & ~((uint32_t)0x40000000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x40000000)) | ((uint32_t)swprof30 << 30)); +} + +__INLINE uint8_t ble_swprofiling_swprof29_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x20000000)) >> 29); +} + +__INLINE void ble_swprofiling_swprof29_setf(uint8_t swprof29) +{ + ASSERT_ERR((((uint32_t)swprof29 << 29) & ~((uint32_t)0x20000000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x20000000)) | ((uint32_t)swprof29 << 29)); +} + +__INLINE uint8_t ble_swprofiling_swprof28_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x10000000)) >> 28); +} + +__INLINE void ble_swprofiling_swprof28_setf(uint8_t swprof28) +{ + ASSERT_ERR((((uint32_t)swprof28 << 28) & ~((uint32_t)0x10000000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x10000000)) | ((uint32_t)swprof28 << 28)); +} + +__INLINE uint8_t ble_swprofiling_swprof27_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x08000000)) >> 27); +} + +__INLINE void ble_swprofiling_swprof27_setf(uint8_t swprof27) +{ + ASSERT_ERR((((uint32_t)swprof27 << 27) & ~((uint32_t)0x08000000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x08000000)) | ((uint32_t)swprof27 << 27)); +} + +__INLINE uint8_t ble_swprofiling_swprof26_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x04000000)) >> 26); +} + +__INLINE void ble_swprofiling_swprof26_setf(uint8_t swprof26) +{ + ASSERT_ERR((((uint32_t)swprof26 << 26) & ~((uint32_t)0x04000000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x04000000)) | ((uint32_t)swprof26 << 26)); +} + +__INLINE uint8_t ble_swprofiling_swprof25_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x02000000)) >> 25); +} + +__INLINE void ble_swprofiling_swprof25_setf(uint8_t swprof25) +{ + ASSERT_ERR((((uint32_t)swprof25 << 25) & ~((uint32_t)0x02000000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x02000000)) | ((uint32_t)swprof25 << 25)); +} + +__INLINE uint8_t ble_swprofiling_swprof24_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x01000000)) >> 24); +} + +__INLINE void ble_swprofiling_swprof24_setf(uint8_t swprof24) +{ + ASSERT_ERR((((uint32_t)swprof24 << 24) & ~((uint32_t)0x01000000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x01000000)) | ((uint32_t)swprof24 << 24)); +} + +__INLINE uint8_t ble_swprofiling_swprof23_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00800000)) >> 23); +} + +__INLINE void ble_swprofiling_swprof23_setf(uint8_t swprof23) +{ + ASSERT_ERR((((uint32_t)swprof23 << 23) & ~((uint32_t)0x00800000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00800000)) | ((uint32_t)swprof23 << 23)); +} + +__INLINE uint8_t ble_swprofiling_swprof22_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00400000)) >> 22); +} + +__INLINE void ble_swprofiling_swprof22_setf(uint8_t swprof22) +{ + ASSERT_ERR((((uint32_t)swprof22 << 22) & ~((uint32_t)0x00400000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00400000)) | ((uint32_t)swprof22 << 22)); +} + +__INLINE uint8_t ble_swprofiling_swprof21_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00200000)) >> 21); +} + +__INLINE void ble_swprofiling_swprof21_setf(uint8_t swprof21) +{ + ASSERT_ERR((((uint32_t)swprof21 << 21) & ~((uint32_t)0x00200000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00200000)) | ((uint32_t)swprof21 << 21)); +} + +__INLINE uint8_t ble_swprofiling_swprof20_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00100000)) >> 20); +} + +__INLINE void ble_swprofiling_swprof20_setf(uint8_t swprof20) +{ + ASSERT_ERR((((uint32_t)swprof20 << 20) & ~((uint32_t)0x00100000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00100000)) | ((uint32_t)swprof20 << 20)); +} + +__INLINE uint8_t ble_swprofiling_swprof19_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00080000)) >> 19); +} + +__INLINE void ble_swprofiling_swprof19_setf(uint8_t swprof19) +{ + ASSERT_ERR((((uint32_t)swprof19 << 19) & ~((uint32_t)0x00080000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00080000)) | ((uint32_t)swprof19 << 19)); +} + +__INLINE uint8_t ble_swprofiling_swprof18_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00040000)) >> 18); +} + +__INLINE void ble_swprofiling_swprof18_setf(uint8_t swprof18) +{ + ASSERT_ERR((((uint32_t)swprof18 << 18) & ~((uint32_t)0x00040000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00040000)) | ((uint32_t)swprof18 << 18)); +} + +__INLINE uint8_t ble_swprofiling_swprof17_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00020000)) >> 17); +} + +__INLINE void ble_swprofiling_swprof17_setf(uint8_t swprof17) +{ + ASSERT_ERR((((uint32_t)swprof17 << 17) & ~((uint32_t)0x00020000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00020000)) | ((uint32_t)swprof17 << 17)); +} + +__INLINE uint8_t ble_swprofiling_swprof16_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00010000)) >> 16); +} + +__INLINE void ble_swprofiling_swprof16_setf(uint8_t swprof16) +{ + ASSERT_ERR((((uint32_t)swprof16 << 16) & ~((uint32_t)0x00010000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00010000)) | ((uint32_t)swprof16 << 16)); +} + +__INLINE uint8_t ble_swprofiling_swprof15_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ble_swprofiling_swprof15_setf(uint8_t swprof15) +{ + ASSERT_ERR((((uint32_t)swprof15 << 15) & ~((uint32_t)0x00008000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)swprof15 << 15)); +} + +__INLINE uint8_t ble_swprofiling_swprof14_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00004000)) >> 14); +} + +__INLINE void ble_swprofiling_swprof14_setf(uint8_t swprof14) +{ + ASSERT_ERR((((uint32_t)swprof14 << 14) & ~((uint32_t)0x00004000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00004000)) | ((uint32_t)swprof14 << 14)); +} + +__INLINE uint8_t ble_swprofiling_swprof13_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00002000)) >> 13); +} + +__INLINE void ble_swprofiling_swprof13_setf(uint8_t swprof13) +{ + ASSERT_ERR((((uint32_t)swprof13 << 13) & ~((uint32_t)0x00002000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00002000)) | ((uint32_t)swprof13 << 13)); +} + +__INLINE uint8_t ble_swprofiling_swprof12_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00001000)) >> 12); +} + +__INLINE void ble_swprofiling_swprof12_setf(uint8_t swprof12) +{ + ASSERT_ERR((((uint32_t)swprof12 << 12) & ~((uint32_t)0x00001000)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00001000)) | ((uint32_t)swprof12 << 12)); +} + +__INLINE uint8_t ble_swprofiling_swprof11_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000800)) >> 11); +} + +__INLINE void ble_swprofiling_swprof11_setf(uint8_t swprof11) +{ + ASSERT_ERR((((uint32_t)swprof11 << 11) & ~((uint32_t)0x00000800)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000800)) | ((uint32_t)swprof11 << 11)); +} + +__INLINE uint8_t ble_swprofiling_swprof10_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000400)) >> 10); +} + +__INLINE void ble_swprofiling_swprof10_setf(uint8_t swprof10) +{ + ASSERT_ERR((((uint32_t)swprof10 << 10) & ~((uint32_t)0x00000400)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000400)) | ((uint32_t)swprof10 << 10)); +} + +__INLINE uint8_t ble_swprofiling_swprof9_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000200)) >> 9); +} + +__INLINE void ble_swprofiling_swprof9_setf(uint8_t swprof9) +{ + ASSERT_ERR((((uint32_t)swprof9 << 9) & ~((uint32_t)0x00000200)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000200)) | ((uint32_t)swprof9 << 9)); +} + +__INLINE uint8_t ble_swprofiling_swprof8_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000100)) >> 8); +} + +__INLINE void ble_swprofiling_swprof8_setf(uint8_t swprof8) +{ + ASSERT_ERR((((uint32_t)swprof8 << 8) & ~((uint32_t)0x00000100)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000100)) | ((uint32_t)swprof8 << 8)); +} + +__INLINE uint8_t ble_swprofiling_swprof7_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE void ble_swprofiling_swprof7_setf(uint8_t swprof7) +{ + ASSERT_ERR((((uint32_t)swprof7 << 7) & ~((uint32_t)0x00000080)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000080)) | ((uint32_t)swprof7 << 7)); +} + +__INLINE uint8_t ble_swprofiling_swprof6_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE void ble_swprofiling_swprof6_setf(uint8_t swprof6) +{ + ASSERT_ERR((((uint32_t)swprof6 << 6) & ~((uint32_t)0x00000040)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000040)) | ((uint32_t)swprof6 << 6)); +} + +__INLINE uint8_t ble_swprofiling_swprof5_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE void ble_swprofiling_swprof5_setf(uint8_t swprof5) +{ + ASSERT_ERR((((uint32_t)swprof5 << 5) & ~((uint32_t)0x00000020)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000020)) | ((uint32_t)swprof5 << 5)); +} + +__INLINE uint8_t ble_swprofiling_swprof4_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE void ble_swprofiling_swprof4_setf(uint8_t swprof4) +{ + ASSERT_ERR((((uint32_t)swprof4 << 4) & ~((uint32_t)0x00000010)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000010)) | ((uint32_t)swprof4 << 4)); +} + +__INLINE uint8_t ble_swprofiling_swprof3_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE void ble_swprofiling_swprof3_setf(uint8_t swprof3) +{ + ASSERT_ERR((((uint32_t)swprof3 << 3) & ~((uint32_t)0x00000008)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000008)) | ((uint32_t)swprof3 << 3)); +} + +__INLINE uint8_t ble_swprofiling_swprof2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE void ble_swprofiling_swprof2_setf(uint8_t swprof2) +{ + ASSERT_ERR((((uint32_t)swprof2 << 2) & ~((uint32_t)0x00000004)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000004)) | ((uint32_t)swprof2 << 2)); +} + +__INLINE uint8_t ble_swprofiling_swprof1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ble_swprofiling_swprof1_setf(uint8_t swprof1) +{ + ASSERT_ERR((((uint32_t)swprof1 << 1) & ~((uint32_t)0x00000002)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)swprof1 << 1)); +} + +__INLINE uint8_t ble_swprofiling_swprof0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ble_swprofiling_swprof0_setf(uint8_t swprof0) +{ + ASSERT_ERR((((uint32_t)swprof0 << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_SWPROFILING_ADDR, (REG_BLE_RD(BLE_SWPROFILING_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)swprof0 << 0)); +} + +/** + * @brief RADIOCNTL0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  29:16               SPIPTR   0x0
+ *     07               SPICFG   0
+ *  05:04              SPIFREQ   0x0
+ *     01              SPICOMP   1
+ *     00                SPIGO   0
+ * 
+ */ +#define BLE_RADIOCNTL0_ADDR BASEBAND_REG_BASE +0x70 //0x50800070 +#define BLE_RADIOCNTL0_OFFSET 0x00000070 +#define BLE_RADIOCNTL0_INDEX 0x0000001C +#define BLE_RADIOCNTL0_RESET 0x00000002 + +__INLINE uint32_t ble_radiocntl0_get(void) +{ + return REG_BLE_RD(BLE_RADIOCNTL0_ADDR); +} + +__INLINE void ble_radiocntl0_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOCNTL0_ADDR, value); +} + +// field definitions +#define BLE_SPIPTR_MASK ((uint32_t)0x3FFF0000) +#define BLE_SPIPTR_LSB 16 +#define BLE_SPIPTR_WIDTH ((uint32_t)0x0000000E) +#define BLE_SPICFG_BIT ((uint32_t)0x00000080) +#define BLE_SPICFG_POS 7 +#define BLE_SPIFREQ_MASK ((uint32_t)0x00000030) +#define BLE_SPIFREQ_LSB 4 +#define BLE_SPIFREQ_WIDTH ((uint32_t)0x00000002) +#define BLE_SPICOMP_BIT ((uint32_t)0x00000002) +#define BLE_SPICOMP_POS 1 +#define BLE_SPIGO_BIT ((uint32_t)0x00000001) +#define BLE_SPIGO_POS 0 + +#define BLE_SPIPTR_RST 0x0 +#define BLE_SPICFG_RST 0x0 +#define BLE_SPIFREQ_RST 0x0 +#define BLE_SPICOMP_RST 0x1 +#define BLE_SPIGO_RST 0x0 + +__INLINE void ble_radiocntl0_pack(uint16_t spiptr, uint8_t spicfg, uint8_t spifreq, uint8_t spigo) +{ + ASSERT_ERR((((uint32_t)spiptr << 16) & ~((uint32_t)0x3FFF0000)) == 0); + ASSERT_ERR((((uint32_t)spicfg << 7) & ~((uint32_t)0x00000080)) == 0); + ASSERT_ERR((((uint32_t)spifreq << 4) & ~((uint32_t)0x00000030)) == 0); + ASSERT_ERR((((uint32_t)spigo << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_RADIOCNTL0_ADDR, ((uint32_t)spiptr << 16) | ((uint32_t)spicfg << 7) | ((uint32_t)spifreq << 4) | ((uint32_t)spigo << 0)); +} + +__INLINE void ble_radiocntl0_unpack(uint16_t* spiptr, uint8_t* spicfg, uint8_t* spifreq, uint8_t* spicomp, uint8_t* spigo) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL0_ADDR); + + *spiptr = (localVal & ((uint32_t)0x3FFF0000)) >> 16; + *spicfg = (localVal & ((uint32_t)0x00000080)) >> 7; + *spifreq = (localVal & ((uint32_t)0x00000030)) >> 4; + *spicomp = (localVal & ((uint32_t)0x00000002)) >> 1; + *spigo = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint16_t ble_radiocntl0_spiptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL0_ADDR); + return ((localVal & ((uint32_t)0x3FFF0000)) >> 16); +} + +__INLINE void ble_radiocntl0_spiptr_setf(uint16_t spiptr) +{ + ASSERT_ERR((((uint32_t)spiptr << 16) & ~((uint32_t)0x3FFF0000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL0_ADDR, (REG_BLE_RD(BLE_RADIOCNTL0_ADDR) & ~((uint32_t)0x3FFF0000)) | ((uint32_t)spiptr << 16)); +} + +__INLINE uint8_t ble_radiocntl0_spicfg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE void ble_radiocntl0_spicfg_setf(uint8_t spicfg) +{ + ASSERT_ERR((((uint32_t)spicfg << 7) & ~((uint32_t)0x00000080)) == 0); + REG_BLE_WR(BLE_RADIOCNTL0_ADDR, (REG_BLE_RD(BLE_RADIOCNTL0_ADDR) & ~((uint32_t)0x00000080)) | ((uint32_t)spicfg << 7)); +} + +__INLINE uint8_t ble_radiocntl0_spifreq_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000030)) >> 4); +} + +__INLINE void ble_radiocntl0_spifreq_setf(uint8_t spifreq) +{ + ASSERT_ERR((((uint32_t)spifreq << 4) & ~((uint32_t)0x00000030)) == 0); + REG_BLE_WR(BLE_RADIOCNTL0_ADDR, (REG_BLE_RD(BLE_RADIOCNTL0_ADDR) & ~((uint32_t)0x00000030)) | ((uint32_t)spifreq << 4)); +} + +__INLINE uint8_t ble_radiocntl0_spicomp_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE uint8_t ble_radiocntl0_spigo_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ble_radiocntl0_spigo_setf(uint8_t spigo) +{ + ASSERT_ERR((((uint32_t)spigo << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_RADIOCNTL0_ADDR, (REG_BLE_RD(BLE_RADIOCNTL0_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)spigo << 0)); +} + +/** + * @brief RADIOCNTL1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31          FORCEAGC_EN   0
+ *     30              FORCEIQ   0
+ *     29               RXDNSL   0
+ *     28               TXDNSL   0
+ *  27:16      FORCEAGC_LENGTH   0x0
+ *     15      SYNC_PULSE_MODE   0
+ *     14       SYNC_PULSE_SRC   0
+ *     13            DPCORR_EN   0
+ *     12           JEF_SELECT   0
+ *  09:04               XRFSEL   0x0
+ *  03:00           SUBVERSION   0x0
+ * 
+ */ +#define BLE_RADIOCNTL1_ADDR BASEBAND_REG_BASE +0x74 //0x50800074 +#define BLE_RADIOCNTL1_OFFSET 0x00000074 +#define BLE_RADIOCNTL1_INDEX 0x0000001D +#define BLE_RADIOCNTL1_RESET 0x00000000 + +__INLINE uint32_t ble_radiocntl1_get(void) +{ + return REG_BLE_RD(BLE_RADIOCNTL1_ADDR); +} + +__INLINE void ble_radiocntl1_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, value); +} + +// field definitions +#define BLE_FORCEAGC_EN_BIT ((uint32_t)0x80000000) +#define BLE_FORCEAGC_EN_POS 31 +#define BLE_FORCEIQ_BIT ((uint32_t)0x40000000) +#define BLE_FORCEIQ_POS 30 +#define BLE_RXDNSL_BIT ((uint32_t)0x20000000) +#define BLE_RXDNSL_POS 29 +#define BLE_TXDNSL_BIT ((uint32_t)0x10000000) +#define BLE_TXDNSL_POS 28 +#define BLE_FORCEAGC_LENGTH_MASK ((uint32_t)0x0FFF0000) +#define BLE_FORCEAGC_LENGTH_LSB 16 +#define BLE_FORCEAGC_LENGTH_WIDTH ((uint32_t)0x0000000C) +#define BLE_SYNC_PULSE_MODE_BIT ((uint32_t)0x00008000) +#define BLE_SYNC_PULSE_MODE_POS 15 +#define BLE_SYNC_PULSE_SRC_BIT ((uint32_t)0x00004000) +#define BLE_SYNC_PULSE_SRC_POS 14 +#define BLE_DPCORR_EN_BIT ((uint32_t)0x00002000) +#define BLE_DPCORR_EN_POS 13 +#define BLE_JEF_SELECT_BIT ((uint32_t)0x00001000) +#define BLE_JEF_SELECT_POS 12 +#define BLE_XRFSEL_MASK ((uint32_t)0x000003F0) +#define BLE_XRFSEL_LSB 4 +#define BLE_XRFSEL_WIDTH ((uint32_t)0x00000006) +#define BLE_SUBVERSION_MASK ((uint32_t)0x0000000F) +#define BLE_SUBVERSION_LSB 0 +#define BLE_SUBVERSION_WIDTH ((uint32_t)0x00000004) + +#define BLE_FORCEAGC_EN_RST 0x0 +#define BLE_FORCEIQ_RST 0x0 +#define BLE_RXDNSL_RST 0x0 +#define BLE_TXDNSL_RST 0x0 +#define BLE_FORCEAGC_LENGTH_RST 0x0 +#define BLE_SYNC_PULSE_MODE_RST 0x0 +#define BLE_SYNC_PULSE_SRC_RST 0x0 +#define BLE_DPCORR_EN_RST 0x0 +#define BLE_JEF_SELECT_RST 0x0 +#define BLE_XRFSEL_RST 0x0 +#define BLE_SUBVERSION_RST 0x0 + +__INLINE void ble_radiocntl1_pack(uint8_t forceagcen, uint8_t forceiq, uint8_t rxdnsl, uint8_t txdnsl, uint16_t forceagclength, uint8_t syncpulsemode, uint8_t syncpulsesrc, uint8_t dpcorren, uint8_t jefselect, uint8_t xrfsel, uint8_t subversion) +{ + ASSERT_ERR((((uint32_t)forceagcen << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)forceiq << 30) & ~((uint32_t)0x40000000)) == 0); + ASSERT_ERR((((uint32_t)rxdnsl << 29) & ~((uint32_t)0x20000000)) == 0); + ASSERT_ERR((((uint32_t)txdnsl << 28) & ~((uint32_t)0x10000000)) == 0); + ASSERT_ERR((((uint32_t)forceagclength << 16) & ~((uint32_t)0x0FFF0000)) == 0); + ASSERT_ERR((((uint32_t)syncpulsemode << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)syncpulsesrc << 14) & ~((uint32_t)0x00004000)) == 0); + ASSERT_ERR((((uint32_t)dpcorren << 13) & ~((uint32_t)0x00002000)) == 0); + ASSERT_ERR((((uint32_t)jefselect << 12) & ~((uint32_t)0x00001000)) == 0); + ASSERT_ERR((((uint32_t)xrfsel << 4) & ~((uint32_t)0x000003F0)) == 0); + ASSERT_ERR((((uint32_t)subversion << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, ((uint32_t)forceagcen << 31) | ((uint32_t)forceiq << 30) | ((uint32_t)rxdnsl << 29) | ((uint32_t)txdnsl << 28) | ((uint32_t)forceagclength << 16) | ((uint32_t)syncpulsemode << 15) | ((uint32_t)syncpulsesrc << 14) | ((uint32_t)dpcorren << 13) | ((uint32_t)jefselect << 12) | ((uint32_t)xrfsel << 4) | ((uint32_t)subversion << 0)); +} + +__INLINE void ble_radiocntl1_unpack(uint8_t* forceagcen, uint8_t* forceiq, uint8_t* rxdnsl, uint8_t* txdnsl, uint16_t* forceagclength, uint8_t* syncpulsemode, uint8_t* syncpulsesrc, uint8_t* dpcorren, uint8_t* jefselect, uint8_t* xrfsel, uint8_t* subversion) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + + *forceagcen = (localVal & ((uint32_t)0x80000000)) >> 31; + *forceiq = (localVal & ((uint32_t)0x40000000)) >> 30; + *rxdnsl = (localVal & ((uint32_t)0x20000000)) >> 29; + *txdnsl = (localVal & ((uint32_t)0x10000000)) >> 28; + *forceagclength = (localVal & ((uint32_t)0x0FFF0000)) >> 16; + *syncpulsemode = (localVal & ((uint32_t)0x00008000)) >> 15; + *syncpulsesrc = (localVal & ((uint32_t)0x00004000)) >> 14; + *dpcorren = (localVal & ((uint32_t)0x00002000)) >> 13; + *jefselect = (localVal & ((uint32_t)0x00001000)) >> 12; + *xrfsel = (localVal & ((uint32_t)0x000003F0)) >> 4; + *subversion = (localVal & ((uint32_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t ble_radiocntl1_forceagc_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_radiocntl1_forceagc_en_setf(uint8_t forceagcen) +{ + ASSERT_ERR((((uint32_t)forceagcen << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)forceagcen << 31)); +} + +__INLINE uint8_t ble_radiocntl1_forceiq_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x40000000)) >> 30); +} + +__INLINE void ble_radiocntl1_forceiq_setf(uint8_t forceiq) +{ + ASSERT_ERR((((uint32_t)forceiq << 30) & ~((uint32_t)0x40000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x40000000)) | ((uint32_t)forceiq << 30)); +} + +__INLINE uint8_t ble_radiocntl1_rxdnsl_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x20000000)) >> 29); +} + +__INLINE void ble_radiocntl1_rxdnsl_setf(uint8_t rxdnsl) +{ + ASSERT_ERR((((uint32_t)rxdnsl << 29) & ~((uint32_t)0x20000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x20000000)) | ((uint32_t)rxdnsl << 29)); +} + +__INLINE uint8_t ble_radiocntl1_txdnsl_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x10000000)) >> 28); +} + +__INLINE void ble_radiocntl1_txdnsl_setf(uint8_t txdnsl) +{ + ASSERT_ERR((((uint32_t)txdnsl << 28) & ~((uint32_t)0x10000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x10000000)) | ((uint32_t)txdnsl << 28)); +} + +__INLINE uint16_t ble_radiocntl1_forceagc_length_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x0FFF0000)) >> 16); +} + +__INLINE void ble_radiocntl1_forceagc_length_setf(uint16_t forceagclength) +{ + ASSERT_ERR((((uint32_t)forceagclength << 16) & ~((uint32_t)0x0FFF0000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x0FFF0000)) | ((uint32_t)forceagclength << 16)); +} + +__INLINE uint8_t ble_radiocntl1_sync_pulse_mode_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ble_radiocntl1_sync_pulse_mode_setf(uint8_t syncpulsemode) +{ + ASSERT_ERR((((uint32_t)syncpulsemode << 15) & ~((uint32_t)0x00008000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)syncpulsemode << 15)); +} + +__INLINE uint8_t ble_radiocntl1_sync_pulse_src_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00004000)) >> 14); +} + +__INLINE void ble_radiocntl1_sync_pulse_src_setf(uint8_t syncpulsesrc) +{ + ASSERT_ERR((((uint32_t)syncpulsesrc << 14) & ~((uint32_t)0x00004000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x00004000)) | ((uint32_t)syncpulsesrc << 14)); +} + +__INLINE uint8_t ble_radiocntl1_dpcorr_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00002000)) >> 13); +} + +__INLINE void ble_radiocntl1_dpcorr_en_setf(uint8_t dpcorren) +{ + ASSERT_ERR((((uint32_t)dpcorren << 13) & ~((uint32_t)0x00002000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x00002000)) | ((uint32_t)dpcorren << 13)); +} + +__INLINE uint8_t ble_radiocntl1_jef_select_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00001000)) >> 12); +} + +__INLINE void ble_radiocntl1_jef_select_setf(uint8_t jefselect) +{ + ASSERT_ERR((((uint32_t)jefselect << 12) & ~((uint32_t)0x00001000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x00001000)) | ((uint32_t)jefselect << 12)); +} + +__INLINE uint8_t ble_radiocntl1_xrfsel_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x000003F0)) >> 4); +} + +__INLINE void ble_radiocntl1_xrfsel_setf(uint8_t xrfsel) +{ + ASSERT_ERR((((uint32_t)xrfsel << 4) & ~((uint32_t)0x000003F0)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x000003F0)) | ((uint32_t)xrfsel << 4)); +} + +__INLINE uint8_t ble_radiocntl1_subversion_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x0000000F)) >> 0); +} + +__INLINE void ble_radiocntl1_subversion_setf(uint8_t subversion) +{ + ASSERT_ERR((((uint32_t)subversion << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_RADIOCNTL1_ADDR, (REG_BLE_RD(BLE_RADIOCNTL1_ADDR) & ~((uint32_t)0x0000000F)) | ((uint32_t)subversion << 0)); +} + +/** + * @brief RADIOCNTL2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:30       LRSYNCCOMPMODE   0x3
+ *     29       RXCITERMBYPASS   0
+ *  28:24           LRVTBFLUSH   0x8
+ *  23:22               PHYMSK   0x0
+ *  21:20            LRSYNCERR   0x0
+ *  18:16              SYNCERR   0x0
+ *  13:00        FREQTABLE_PTR   0x40
+ * 
+ */ +#define BLE_RADIOCNTL2_ADDR BASEBAND_REG_BASE +0x78 //0x50800078 +#define BLE_RADIOCNTL2_OFFSET 0x00000078 +#define BLE_RADIOCNTL2_INDEX 0x0000001E +#define BLE_RADIOCNTL2_RESET 0xC8000040 + +__INLINE uint32_t ble_radiocntl2_get(void) +{ + return REG_BLE_RD(BLE_RADIOCNTL2_ADDR); +} + +__INLINE void ble_radiocntl2_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOCNTL2_ADDR, value); +} + +// field definitions +#define BLE_LRSYNCCOMPMODE_MASK ((uint32_t)0xC0000000) +#define BLE_LRSYNCCOMPMODE_LSB 30 +#define BLE_LRSYNCCOMPMODE_WIDTH ((uint32_t)0x00000002) +#define BLE_RXCITERMBYPASS_BIT ((uint32_t)0x20000000) +#define BLE_RXCITERMBYPASS_POS 29 +#define BLE_LRVTBFLUSH_MASK ((uint32_t)0x1F000000) +#define BLE_LRVTBFLUSH_LSB 24 +#define BLE_LRVTBFLUSH_WIDTH ((uint32_t)0x00000005) +#define BLE_PHYMSK_MASK ((uint32_t)0x00C00000) +#define BLE_PHYMSK_LSB 22 +#define BLE_PHYMSK_WIDTH ((uint32_t)0x00000002) +#define BLE_LRSYNCERR_MASK ((uint32_t)0x00300000) +#define BLE_LRSYNCERR_LSB 20 +#define BLE_LRSYNCERR_WIDTH ((uint32_t)0x00000002) +#define BLE_SYNCERR_MASK ((uint32_t)0x00070000) +#define BLE_SYNCERR_LSB 16 +#define BLE_SYNCERR_WIDTH ((uint32_t)0x00000003) +#define BLE_FREQTABLE_PTR_MASK ((uint32_t)0x00003FFF) +#define BLE_FREQTABLE_PTR_LSB 0 +#define BLE_FREQTABLE_PTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_LRSYNCCOMPMODE_RST 0x3 +#define BLE_RXCITERMBYPASS_RST 0x0 +#define BLE_LRVTBFLUSH_RST 0x8 +#define BLE_PHYMSK_RST 0x0 +#define BLE_LRSYNCERR_RST 0x0 +#define BLE_SYNCERR_RST 0x0 +#define BLE_FREQTABLE_PTR_RST 0x40 + +__INLINE void ble_radiocntl2_pack(uint8_t lrsynccompmode, uint8_t rxcitermbypass, uint8_t lrvtbflush, uint8_t phymsk, uint8_t lrsyncerr, uint8_t syncerr, uint16_t freqtableptr) +{ + ASSERT_ERR((((uint32_t)lrsynccompmode << 30) & ~((uint32_t)0xC0000000)) == 0); + ASSERT_ERR((((uint32_t)rxcitermbypass << 29) & ~((uint32_t)0x20000000)) == 0); + ASSERT_ERR((((uint32_t)lrvtbflush << 24) & ~((uint32_t)0x1F000000)) == 0); + ASSERT_ERR((((uint32_t)phymsk << 22) & ~((uint32_t)0x00C00000)) == 0); + ASSERT_ERR((((uint32_t)lrsyncerr << 20) & ~((uint32_t)0x00300000)) == 0); + ASSERT_ERR((((uint32_t)syncerr << 16) & ~((uint32_t)0x00070000)) == 0); + ASSERT_ERR((((uint32_t)freqtableptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_RADIOCNTL2_ADDR, ((uint32_t)lrsynccompmode << 30) | ((uint32_t)rxcitermbypass << 29) | ((uint32_t)lrvtbflush << 24) | ((uint32_t)phymsk << 22) | ((uint32_t)lrsyncerr << 20) | ((uint32_t)syncerr << 16) | ((uint32_t)freqtableptr << 0)); +} + +__INLINE void ble_radiocntl2_unpack(uint8_t* lrsynccompmode, uint8_t* rxcitermbypass, uint8_t* lrvtbflush, uint8_t* phymsk, uint8_t* lrsyncerr, uint8_t* syncerr, uint16_t* freqtableptr) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL2_ADDR); + + *lrsynccompmode = (localVal & ((uint32_t)0xC0000000)) >> 30; + *rxcitermbypass = (localVal & ((uint32_t)0x20000000)) >> 29; + *lrvtbflush = (localVal & ((uint32_t)0x1F000000)) >> 24; + *phymsk = (localVal & ((uint32_t)0x00C00000)) >> 22; + *lrsyncerr = (localVal & ((uint32_t)0x00300000)) >> 20; + *syncerr = (localVal & ((uint32_t)0x00070000)) >> 16; + *freqtableptr = (localVal & ((uint32_t)0x00003FFF)) >> 0; +} + +__INLINE uint8_t ble_radiocntl2_lrsynccompmode_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL2_ADDR); + return ((localVal & ((uint32_t)0xC0000000)) >> 30); +} + +__INLINE void ble_radiocntl2_lrsynccompmode_setf(uint8_t lrsynccompmode) +{ + ASSERT_ERR((((uint32_t)lrsynccompmode << 30) & ~((uint32_t)0xC0000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL2_ADDR, (REG_BLE_RD(BLE_RADIOCNTL2_ADDR) & ~((uint32_t)0xC0000000)) | ((uint32_t)lrsynccompmode << 30)); +} + +__INLINE uint8_t ble_radiocntl2_rxcitermbypass_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL2_ADDR); + return ((localVal & ((uint32_t)0x20000000)) >> 29); +} + +__INLINE void ble_radiocntl2_rxcitermbypass_setf(uint8_t rxcitermbypass) +{ + ASSERT_ERR((((uint32_t)rxcitermbypass << 29) & ~((uint32_t)0x20000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL2_ADDR, (REG_BLE_RD(BLE_RADIOCNTL2_ADDR) & ~((uint32_t)0x20000000)) | ((uint32_t)rxcitermbypass << 29)); +} + +__INLINE uint8_t ble_radiocntl2_lrvtbflush_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL2_ADDR); + return ((localVal & ((uint32_t)0x1F000000)) >> 24); +} + +__INLINE void ble_radiocntl2_lrvtbflush_setf(uint8_t lrvtbflush) +{ + ASSERT_ERR((((uint32_t)lrvtbflush << 24) & ~((uint32_t)0x1F000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL2_ADDR, (REG_BLE_RD(BLE_RADIOCNTL2_ADDR) & ~((uint32_t)0x1F000000)) | ((uint32_t)lrvtbflush << 24)); +} + +__INLINE uint8_t ble_radiocntl2_phymsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL2_ADDR); + return ((localVal & ((uint32_t)0x00C00000)) >> 22); +} + +__INLINE void ble_radiocntl2_phymsk_setf(uint8_t phymsk) +{ + ASSERT_ERR((((uint32_t)phymsk << 22) & ~((uint32_t)0x00C00000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL2_ADDR, (REG_BLE_RD(BLE_RADIOCNTL2_ADDR) & ~((uint32_t)0x00C00000)) | ((uint32_t)phymsk << 22)); +} + +__INLINE uint8_t ble_radiocntl2_lrsyncerr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL2_ADDR); + return ((localVal & ((uint32_t)0x00300000)) >> 20); +} + +__INLINE void ble_radiocntl2_lrsyncerr_setf(uint8_t lrsyncerr) +{ + ASSERT_ERR((((uint32_t)lrsyncerr << 20) & ~((uint32_t)0x00300000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL2_ADDR, (REG_BLE_RD(BLE_RADIOCNTL2_ADDR) & ~((uint32_t)0x00300000)) | ((uint32_t)lrsyncerr << 20)); +} + +__INLINE uint8_t ble_radiocntl2_syncerr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL2_ADDR); + return ((localVal & ((uint32_t)0x00070000)) >> 16); +} + +__INLINE void ble_radiocntl2_syncerr_setf(uint8_t syncerr) +{ + ASSERT_ERR((((uint32_t)syncerr << 16) & ~((uint32_t)0x00070000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL2_ADDR, (REG_BLE_RD(BLE_RADIOCNTL2_ADDR) & ~((uint32_t)0x00070000)) | ((uint32_t)syncerr << 16)); +} + +__INLINE uint16_t ble_radiocntl2_freqtable_ptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL2_ADDR); + return ((localVal & ((uint32_t)0x00003FFF)) >> 0); +} + +__INLINE void ble_radiocntl2_freqtable_ptr_setf(uint16_t freqtableptr) +{ + ASSERT_ERR((((uint32_t)freqtableptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_RADIOCNTL2_ADDR, (REG_BLE_RD(BLE_RADIOCNTL2_ADDR) & ~((uint32_t)0x00003FFF)) | ((uint32_t)freqtableptr << 0)); +} + +/** + * @brief RADIOCNTL3 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:30           RXRATE3CFG   0x3
+ *  29:28           RXRATE2CFG   0x2
+ *  27:26           RXRATE1CFG   0x1
+ *  25:24           RXRATE0CFG   0x0
+ *     18       RXSYNC_ROUTING   0
+ *  17:16          RXVALID_BEH   0x0
+ *  15:14           TXRATE3CFG   0x3
+ *  13:12           TXRATE2CFG   0x2
+ *  11:10           TXRATE1CFG   0x1
+ *  09:08           TXRATE0CFG   0x0
+ *  01:00          TXVALID_BEH   0x0
+ * 
+ */ +#define BLE_RADIOCNTL3_ADDR BASEBAND_REG_BASE +0x7C //0x5080007C +#define BLE_RADIOCNTL3_OFFSET 0x0000007C +#define BLE_RADIOCNTL3_INDEX 0x0000001F +#define BLE_RADIOCNTL3_RESET 0xE400E400 + +__INLINE uint32_t ble_radiocntl3_get(void) +{ + return REG_BLE_RD(BLE_RADIOCNTL3_ADDR); +} + +__INLINE void ble_radiocntl3_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, value); +} + +// field definitions +#define BLE_RXRATE3CFG_MASK ((uint32_t)0xC0000000) +#define BLE_RXRATE3CFG_LSB 30 +#define BLE_RXRATE3CFG_WIDTH ((uint32_t)0x00000002) +#define BLE_RXRATE2CFG_MASK ((uint32_t)0x30000000) +#define BLE_RXRATE2CFG_LSB 28 +#define BLE_RXRATE2CFG_WIDTH ((uint32_t)0x00000002) +#define BLE_RXRATE1CFG_MASK ((uint32_t)0x0C000000) +#define BLE_RXRATE1CFG_LSB 26 +#define BLE_RXRATE1CFG_WIDTH ((uint32_t)0x00000002) +#define BLE_RXRATE0CFG_MASK ((uint32_t)0x03000000) +#define BLE_RXRATE0CFG_LSB 24 +#define BLE_RXRATE0CFG_WIDTH ((uint32_t)0x00000002) +#define BLE_RXSYNC_ROUTING_BIT ((uint32_t)0x00040000) +#define BLE_RXSYNC_ROUTING_POS 18 +#define BLE_RXVALID_BEH_MASK ((uint32_t)0x00030000) +#define BLE_RXVALID_BEH_LSB 16 +#define BLE_RXVALID_BEH_WIDTH ((uint32_t)0x00000002) +#define BLE_TXRATE3CFG_MASK ((uint32_t)0x0000C000) +#define BLE_TXRATE3CFG_LSB 14 +#define BLE_TXRATE3CFG_WIDTH ((uint32_t)0x00000002) +#define BLE_TXRATE2CFG_MASK ((uint32_t)0x00003000) +#define BLE_TXRATE2CFG_LSB 12 +#define BLE_TXRATE2CFG_WIDTH ((uint32_t)0x00000002) +#define BLE_TXRATE1CFG_MASK ((uint32_t)0x00000C00) +#define BLE_TXRATE1CFG_LSB 10 +#define BLE_TXRATE1CFG_WIDTH ((uint32_t)0x00000002) +#define BLE_TXRATE0CFG_MASK ((uint32_t)0x00000300) +#define BLE_TXRATE0CFG_LSB 8 +#define BLE_TXRATE0CFG_WIDTH ((uint32_t)0x00000002) +#define BLE_TXVALID_BEH_MASK ((uint32_t)0x00000003) +#define BLE_TXVALID_BEH_LSB 0 +#define BLE_TXVALID_BEH_WIDTH ((uint32_t)0x00000002) + +#define BLE_RXRATE3CFG_RST 0x3 +#define BLE_RXRATE2CFG_RST 0x2 +#define BLE_RXRATE1CFG_RST 0x1 +#define BLE_RXRATE0CFG_RST 0x0 +#define BLE_RXSYNC_ROUTING_RST 0x0 +#define BLE_RXVALID_BEH_RST 0x0 +#define BLE_TXRATE3CFG_RST 0x3 +#define BLE_TXRATE2CFG_RST 0x2 +#define BLE_TXRATE1CFG_RST 0x1 +#define BLE_TXRATE0CFG_RST 0x0 +#define BLE_TXVALID_BEH_RST 0x0 + +__INLINE void ble_radiocntl3_pack(uint8_t rxrate3cfg, uint8_t rxrate2cfg, uint8_t rxrate1cfg, uint8_t rxrate0cfg, uint8_t rxsyncrouting, uint8_t rxvalidbeh, uint8_t txrate3cfg, uint8_t txrate2cfg, uint8_t txrate1cfg, uint8_t txrate0cfg, uint8_t txvalidbeh) +{ + ASSERT_ERR((((uint32_t)rxrate3cfg << 30) & ~((uint32_t)0xC0000000)) == 0); + ASSERT_ERR((((uint32_t)rxrate2cfg << 28) & ~((uint32_t)0x30000000)) == 0); + ASSERT_ERR((((uint32_t)rxrate1cfg << 26) & ~((uint32_t)0x0C000000)) == 0); + ASSERT_ERR((((uint32_t)rxrate0cfg << 24) & ~((uint32_t)0x03000000)) == 0); + ASSERT_ERR((((uint32_t)rxsyncrouting << 18) & ~((uint32_t)0x00040000)) == 0); + ASSERT_ERR((((uint32_t)rxvalidbeh << 16) & ~((uint32_t)0x00030000)) == 0); + ASSERT_ERR((((uint32_t)txrate3cfg << 14) & ~((uint32_t)0x0000C000)) == 0); + ASSERT_ERR((((uint32_t)txrate2cfg << 12) & ~((uint32_t)0x00003000)) == 0); + ASSERT_ERR((((uint32_t)txrate1cfg << 10) & ~((uint32_t)0x00000C00)) == 0); + ASSERT_ERR((((uint32_t)txrate0cfg << 8) & ~((uint32_t)0x00000300)) == 0); + ASSERT_ERR((((uint32_t)txvalidbeh << 0) & ~((uint32_t)0x00000003)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, ((uint32_t)rxrate3cfg << 30) | ((uint32_t)rxrate2cfg << 28) | ((uint32_t)rxrate1cfg << 26) | ((uint32_t)rxrate0cfg << 24) | ((uint32_t)rxsyncrouting << 18) | ((uint32_t)rxvalidbeh << 16) | ((uint32_t)txrate3cfg << 14) | ((uint32_t)txrate2cfg << 12) | ((uint32_t)txrate1cfg << 10) | ((uint32_t)txrate0cfg << 8) | ((uint32_t)txvalidbeh << 0)); +} + +__INLINE void ble_radiocntl3_unpack(uint8_t* rxrate3cfg, uint8_t* rxrate2cfg, uint8_t* rxrate1cfg, uint8_t* rxrate0cfg, uint8_t* rxsyncrouting, uint8_t* rxvalidbeh, uint8_t* txrate3cfg, uint8_t* txrate2cfg, uint8_t* txrate1cfg, uint8_t* txrate0cfg, uint8_t* txvalidbeh) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + + *rxrate3cfg = (localVal & ((uint32_t)0xC0000000)) >> 30; + *rxrate2cfg = (localVal & ((uint32_t)0x30000000)) >> 28; + *rxrate1cfg = (localVal & ((uint32_t)0x0C000000)) >> 26; + *rxrate0cfg = (localVal & ((uint32_t)0x03000000)) >> 24; + *rxsyncrouting = (localVal & ((uint32_t)0x00040000)) >> 18; + *rxvalidbeh = (localVal & ((uint32_t)0x00030000)) >> 16; + *txrate3cfg = (localVal & ((uint32_t)0x0000C000)) >> 14; + *txrate2cfg = (localVal & ((uint32_t)0x00003000)) >> 12; + *txrate1cfg = (localVal & ((uint32_t)0x00000C00)) >> 10; + *txrate0cfg = (localVal & ((uint32_t)0x00000300)) >> 8; + *txvalidbeh = (localVal & ((uint32_t)0x00000003)) >> 0; +} + +__INLINE uint8_t ble_radiocntl3_rxrate3cfg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0xC0000000)) >> 30); +} + +__INLINE void ble_radiocntl3_rxrate3cfg_setf(uint8_t rxrate3cfg) +{ + ASSERT_ERR((((uint32_t)rxrate3cfg << 30) & ~((uint32_t)0xC0000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0xC0000000)) | ((uint32_t)rxrate3cfg << 30)); +} + +__INLINE uint8_t ble_radiocntl3_rxrate2cfg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0x30000000)) >> 28); +} + +__INLINE void ble_radiocntl3_rxrate2cfg_setf(uint8_t rxrate2cfg) +{ + ASSERT_ERR((((uint32_t)rxrate2cfg << 28) & ~((uint32_t)0x30000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0x30000000)) | ((uint32_t)rxrate2cfg << 28)); +} + +__INLINE uint8_t ble_radiocntl3_rxrate1cfg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0x0C000000)) >> 26); +} + +__INLINE void ble_radiocntl3_rxrate1cfg_setf(uint8_t rxrate1cfg) +{ + ASSERT_ERR((((uint32_t)rxrate1cfg << 26) & ~((uint32_t)0x0C000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0x0C000000)) | ((uint32_t)rxrate1cfg << 26)); +} + +__INLINE uint8_t ble_radiocntl3_rxrate0cfg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0x03000000)) >> 24); +} + +__INLINE void ble_radiocntl3_rxrate0cfg_setf(uint8_t rxrate0cfg) +{ + ASSERT_ERR((((uint32_t)rxrate0cfg << 24) & ~((uint32_t)0x03000000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0x03000000)) | ((uint32_t)rxrate0cfg << 24)); +} + +__INLINE uint8_t ble_radiocntl3_rxsync_routing_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0x00040000)) >> 18); +} + +__INLINE void ble_radiocntl3_rxsync_routing_setf(uint8_t rxsyncrouting) +{ + ASSERT_ERR((((uint32_t)rxsyncrouting << 18) & ~((uint32_t)0x00040000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0x00040000)) | ((uint32_t)rxsyncrouting << 18)); +} + +__INLINE uint8_t ble_radiocntl3_rxvalid_beh_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0x00030000)) >> 16); +} + +__INLINE void ble_radiocntl3_rxvalid_beh_setf(uint8_t rxvalidbeh) +{ + ASSERT_ERR((((uint32_t)rxvalidbeh << 16) & ~((uint32_t)0x00030000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0x00030000)) | ((uint32_t)rxvalidbeh << 16)); +} + +__INLINE uint8_t ble_radiocntl3_txrate3cfg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0x0000C000)) >> 14); +} + +__INLINE void ble_radiocntl3_txrate3cfg_setf(uint8_t txrate3cfg) +{ + ASSERT_ERR((((uint32_t)txrate3cfg << 14) & ~((uint32_t)0x0000C000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0x0000C000)) | ((uint32_t)txrate3cfg << 14)); +} + +__INLINE uint8_t ble_radiocntl3_txrate2cfg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0x00003000)) >> 12); +} + +__INLINE void ble_radiocntl3_txrate2cfg_setf(uint8_t txrate2cfg) +{ + ASSERT_ERR((((uint32_t)txrate2cfg << 12) & ~((uint32_t)0x00003000)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0x00003000)) | ((uint32_t)txrate2cfg << 12)); +} + +__INLINE uint8_t ble_radiocntl3_txrate1cfg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0x00000C00)) >> 10); +} + +__INLINE void ble_radiocntl3_txrate1cfg_setf(uint8_t txrate1cfg) +{ + ASSERT_ERR((((uint32_t)txrate1cfg << 10) & ~((uint32_t)0x00000C00)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0x00000C00)) | ((uint32_t)txrate1cfg << 10)); +} + +__INLINE uint8_t ble_radiocntl3_txrate0cfg_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0x00000300)) >> 8); +} + +__INLINE void ble_radiocntl3_txrate0cfg_setf(uint8_t txrate0cfg) +{ + ASSERT_ERR((((uint32_t)txrate0cfg << 8) & ~((uint32_t)0x00000300)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0x00000300)) | ((uint32_t)txrate0cfg << 8)); +} + +__INLINE uint8_t ble_radiocntl3_txvalid_beh_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOCNTL3_ADDR); + return ((localVal & ((uint32_t)0x00000003)) >> 0); +} + +__INLINE void ble_radiocntl3_txvalid_beh_setf(uint8_t txvalidbeh) +{ + ASSERT_ERR((((uint32_t)txvalidbeh << 0) & ~((uint32_t)0x00000003)) == 0); + REG_BLE_WR(BLE_RADIOCNTL3_ADDR, (REG_BLE_RD(BLE_RADIOCNTL3_ADDR) & ~((uint32_t)0x00000003)) | ((uint32_t)txvalidbeh << 0)); +} + +/** + * @brief RADIOPWRUPDN0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24       SYNC_POSITION0   0x0
+ *  23:16             RXPWRUP0   0x0
+ *  14:08             TXPWRDN0   0x0
+ *  07:00             TXPWRUP0   0x0
+ * 
+ */ +#define BLE_RADIOPWRUPDN0_ADDR BASEBAND_REG_BASE +0x80 //0x50800080 +#define BLE_RADIOPWRUPDN0_OFFSET 0x00000080 +#define BLE_RADIOPWRUPDN0_INDEX 0x00000020 +#define BLE_RADIOPWRUPDN0_RESET 0x00000000 + +__INLINE uint32_t ble_radiopwrupdn0_get(void) +{ + return REG_BLE_RD(BLE_RADIOPWRUPDN0_ADDR); +} + +__INLINE void ble_radiopwrupdn0_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOPWRUPDN0_ADDR, value); +} + +// field definitions +#define BLE_SYNC_POSITION0_MASK ((uint32_t)0xFF000000) +#define BLE_SYNC_POSITION0_LSB 24 +#define BLE_SYNC_POSITION0_WIDTH ((uint32_t)0x00000008) +#define BLE_RXPWRUP0_MASK ((uint32_t)0x00FF0000) +#define BLE_RXPWRUP0_LSB 16 +#define BLE_RXPWRUP0_WIDTH ((uint32_t)0x00000008) +#define BLE_TXPWRDN0_MASK ((uint32_t)0x00007F00) +#define BLE_TXPWRDN0_LSB 8 +#define BLE_TXPWRDN0_WIDTH ((uint32_t)0x00000007) +#define BLE_TXPWRUP0_MASK ((uint32_t)0x000000FF) +#define BLE_TXPWRUP0_LSB 0 +#define BLE_TXPWRUP0_WIDTH ((uint32_t)0x00000008) + +#define BLE_SYNC_POSITION0_RST 0x0 +#define BLE_RXPWRUP0_RST 0x0 +#define BLE_TXPWRDN0_RST 0x0 +#define BLE_TXPWRUP0_RST 0x0 + +__INLINE void ble_radiopwrupdn0_pack(uint8_t syncposition0, uint8_t rxpwrup0, uint8_t txpwrdn0, uint8_t txpwrup0) +{ + ASSERT_ERR((((uint32_t)syncposition0 << 24) & ~((uint32_t)0xFF000000)) == 0); + ASSERT_ERR((((uint32_t)rxpwrup0 << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)txpwrdn0 << 8) & ~((uint32_t)0x00007F00)) == 0); + ASSERT_ERR((((uint32_t)txpwrup0 << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN0_ADDR, ((uint32_t)syncposition0 << 24) | ((uint32_t)rxpwrup0 << 16) | ((uint32_t)txpwrdn0 << 8) | ((uint32_t)txpwrup0 << 0)); +} + +__INLINE void ble_radiopwrupdn0_unpack(uint8_t* syncposition0, uint8_t* rxpwrup0, uint8_t* txpwrdn0, uint8_t* txpwrup0) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN0_ADDR); + + *syncposition0 = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rxpwrup0 = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *txpwrdn0 = (localVal & ((uint32_t)0x00007F00)) >> 8; + *txpwrup0 = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_radiopwrupdn0_sync_position0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN0_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE void ble_radiopwrupdn0_sync_position0_setf(uint8_t syncposition0) +{ + ASSERT_ERR((((uint32_t)syncposition0 << 24) & ~((uint32_t)0xFF000000)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN0_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN0_ADDR) & ~((uint32_t)0xFF000000)) | ((uint32_t)syncposition0 << 24)); +} + +__INLINE uint8_t ble_radiopwrupdn0_rxpwrup0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN0_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_radiopwrupdn0_rxpwrup0_setf(uint8_t rxpwrup0) +{ + ASSERT_ERR((((uint32_t)rxpwrup0 << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN0_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN0_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)rxpwrup0 << 16)); +} + +__INLINE uint8_t ble_radiopwrupdn0_txpwrdn0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN0_ADDR); + return ((localVal & ((uint32_t)0x00007F00)) >> 8); +} + +__INLINE void ble_radiopwrupdn0_txpwrdn0_setf(uint8_t txpwrdn0) +{ + ASSERT_ERR((((uint32_t)txpwrdn0 << 8) & ~((uint32_t)0x00007F00)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN0_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN0_ADDR) & ~((uint32_t)0x00007F00)) | ((uint32_t)txpwrdn0 << 8)); +} + +__INLINE uint8_t ble_radiopwrupdn0_txpwrup0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN0_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +__INLINE void ble_radiopwrupdn0_txpwrup0_setf(uint8_t txpwrup0) +{ + ASSERT_ERR((((uint32_t)txpwrup0 << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN0_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN0_ADDR) & ~((uint32_t)0x000000FF)) | ((uint32_t)txpwrup0 << 0)); +} + +/** + * @brief RADIOPWRUPDN1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24       SYNC_POSITION1   0x0
+ *  23:16             RXPWRUP1   0x0
+ *  14:08             TXPWRDN1   0x0
+ *  07:00             TXPWRUP1   0x0
+ * 
+ */ +#define BLE_RADIOPWRUPDN1_ADDR BASEBAND_REG_BASE +0x84 // 0x50800084 +#define BLE_RADIOPWRUPDN1_OFFSET 0x00000084 +#define BLE_RADIOPWRUPDN1_INDEX 0x00000021 +#define BLE_RADIOPWRUPDN1_RESET 0x00000000 + +__INLINE uint32_t ble_radiopwrupdn1_get(void) +{ + return REG_BLE_RD(BLE_RADIOPWRUPDN1_ADDR); +} + +__INLINE void ble_radiopwrupdn1_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOPWRUPDN1_ADDR, value); +} + +// field definitions +#define BLE_SYNC_POSITION1_MASK ((uint32_t)0xFF000000) +#define BLE_SYNC_POSITION1_LSB 24 +#define BLE_SYNC_POSITION1_WIDTH ((uint32_t)0x00000008) +#define BLE_RXPWRUP1_MASK ((uint32_t)0x00FF0000) +#define BLE_RXPWRUP1_LSB 16 +#define BLE_RXPWRUP1_WIDTH ((uint32_t)0x00000008) +#define BLE_TXPWRDN1_MASK ((uint32_t)0x00007F00) +#define BLE_TXPWRDN1_LSB 8 +#define BLE_TXPWRDN1_WIDTH ((uint32_t)0x00000007) +#define BLE_TXPWRUP1_MASK ((uint32_t)0x000000FF) +#define BLE_TXPWRUP1_LSB 0 +#define BLE_TXPWRUP1_WIDTH ((uint32_t)0x00000008) + +#define BLE_SYNC_POSITION1_RST 0x0 +#define BLE_RXPWRUP1_RST 0x0 +#define BLE_TXPWRDN1_RST 0x0 +#define BLE_TXPWRUP1_RST 0x0 + +__INLINE void ble_radiopwrupdn1_pack(uint8_t syncposition1, uint8_t rxpwrup1, uint8_t txpwrdn1, uint8_t txpwrup1) +{ + ASSERT_ERR((((uint32_t)syncposition1 << 24) & ~((uint32_t)0xFF000000)) == 0); + ASSERT_ERR((((uint32_t)rxpwrup1 << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)txpwrdn1 << 8) & ~((uint32_t)0x00007F00)) == 0); + ASSERT_ERR((((uint32_t)txpwrup1 << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN1_ADDR, ((uint32_t)syncposition1 << 24) | ((uint32_t)rxpwrup1 << 16) | ((uint32_t)txpwrdn1 << 8) | ((uint32_t)txpwrup1 << 0)); +} + +__INLINE void ble_radiopwrupdn1_unpack(uint8_t* syncposition1, uint8_t* rxpwrup1, uint8_t* txpwrdn1, uint8_t* txpwrup1) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN1_ADDR); + + *syncposition1 = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rxpwrup1 = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *txpwrdn1 = (localVal & ((uint32_t)0x00007F00)) >> 8; + *txpwrup1 = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_radiopwrupdn1_sync_position1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN1_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE void ble_radiopwrupdn1_sync_position1_setf(uint8_t syncposition1) +{ + ASSERT_ERR((((uint32_t)syncposition1 << 24) & ~((uint32_t)0xFF000000)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN1_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN1_ADDR) & ~((uint32_t)0xFF000000)) | ((uint32_t)syncposition1 << 24)); +} + +__INLINE uint8_t ble_radiopwrupdn1_rxpwrup1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN1_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_radiopwrupdn1_rxpwrup1_setf(uint8_t rxpwrup1) +{ + ASSERT_ERR((((uint32_t)rxpwrup1 << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN1_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN1_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)rxpwrup1 << 16)); +} + +__INLINE uint8_t ble_radiopwrupdn1_txpwrdn1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN1_ADDR); + return ((localVal & ((uint32_t)0x00007F00)) >> 8); +} + +__INLINE void ble_radiopwrupdn1_txpwrdn1_setf(uint8_t txpwrdn1) +{ + ASSERT_ERR((((uint32_t)txpwrdn1 << 8) & ~((uint32_t)0x00007F00)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN1_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN1_ADDR) & ~((uint32_t)0x00007F00)) | ((uint32_t)txpwrdn1 << 8)); +} + +__INLINE uint8_t ble_radiopwrupdn1_txpwrup1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN1_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +__INLINE void ble_radiopwrupdn1_txpwrup1_setf(uint8_t txpwrup1) +{ + ASSERT_ERR((((uint32_t)txpwrup1 << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN1_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN1_ADDR) & ~((uint32_t)0x000000FF)) | ((uint32_t)txpwrup1 << 0)); +} + +/** + * @brief RADIOPWRUPDN2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24       SYNC_POSITION2   0x0
+ *  23:16             RXPWRUP2   0x0
+ *  14:08             TXPWRDN2   0x0
+ *  07:00             TXPWRUP2   0x0
+ * 
+ */ +#define BLE_RADIOPWRUPDN2_ADDR BASEBAND_REG_BASE +0x88 // 0x50800088 +#define BLE_RADIOPWRUPDN2_OFFSET 0x00000088 +#define BLE_RADIOPWRUPDN2_INDEX 0x00000022 +#define BLE_RADIOPWRUPDN2_RESET 0x00000000 + +__INLINE uint32_t ble_radiopwrupdn2_get(void) +{ + return REG_BLE_RD(BLE_RADIOPWRUPDN2_ADDR); +} + +__INLINE void ble_radiopwrupdn2_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOPWRUPDN2_ADDR, value); +} + +// field definitions +#define BLE_SYNC_POSITION2_MASK ((uint32_t)0xFF000000) +#define BLE_SYNC_POSITION2_LSB 24 +#define BLE_SYNC_POSITION2_WIDTH ((uint32_t)0x00000008) +#define BLE_RXPWRUP2_MASK ((uint32_t)0x00FF0000) +#define BLE_RXPWRUP2_LSB 16 +#define BLE_RXPWRUP2_WIDTH ((uint32_t)0x00000008) +#define BLE_TXPWRDN2_MASK ((uint32_t)0x00007F00) +#define BLE_TXPWRDN2_LSB 8 +#define BLE_TXPWRDN2_WIDTH ((uint32_t)0x00000007) +#define BLE_TXPWRUP2_MASK ((uint32_t)0x000000FF) +#define BLE_TXPWRUP2_LSB 0 +#define BLE_TXPWRUP2_WIDTH ((uint32_t)0x00000008) + +#define BLE_SYNC_POSITION2_RST 0x0 +#define BLE_RXPWRUP2_RST 0x0 +#define BLE_TXPWRDN2_RST 0x0 +#define BLE_TXPWRUP2_RST 0x0 + +__INLINE void ble_radiopwrupdn2_pack(uint8_t syncposition2, uint8_t rxpwrup2, uint8_t txpwrdn2, uint8_t txpwrup2) +{ + ASSERT_ERR((((uint32_t)syncposition2 << 24) & ~((uint32_t)0xFF000000)) == 0); + ASSERT_ERR((((uint32_t)rxpwrup2 << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)txpwrdn2 << 8) & ~((uint32_t)0x00007F00)) == 0); + ASSERT_ERR((((uint32_t)txpwrup2 << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN2_ADDR, ((uint32_t)syncposition2 << 24) | ((uint32_t)rxpwrup2 << 16) | ((uint32_t)txpwrdn2 << 8) | ((uint32_t)txpwrup2 << 0)); +} + +__INLINE void ble_radiopwrupdn2_unpack(uint8_t* syncposition2, uint8_t* rxpwrup2, uint8_t* txpwrdn2, uint8_t* txpwrup2) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN2_ADDR); + + *syncposition2 = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rxpwrup2 = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *txpwrdn2 = (localVal & ((uint32_t)0x00007F00)) >> 8; + *txpwrup2 = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_radiopwrupdn2_sync_position2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN2_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE void ble_radiopwrupdn2_sync_position2_setf(uint8_t syncposition2) +{ + ASSERT_ERR((((uint32_t)syncposition2 << 24) & ~((uint32_t)0xFF000000)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN2_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN2_ADDR) & ~((uint32_t)0xFF000000)) | ((uint32_t)syncposition2 << 24)); +} + +__INLINE uint8_t ble_radiopwrupdn2_rxpwrup2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN2_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_radiopwrupdn2_rxpwrup2_setf(uint8_t rxpwrup2) +{ + ASSERT_ERR((((uint32_t)rxpwrup2 << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN2_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN2_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)rxpwrup2 << 16)); +} + +__INLINE uint8_t ble_radiopwrupdn2_txpwrdn2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN2_ADDR); + return ((localVal & ((uint32_t)0x00007F00)) >> 8); +} + +__INLINE void ble_radiopwrupdn2_txpwrdn2_setf(uint8_t txpwrdn2) +{ + ASSERT_ERR((((uint32_t)txpwrdn2 << 8) & ~((uint32_t)0x00007F00)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN2_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN2_ADDR) & ~((uint32_t)0x00007F00)) | ((uint32_t)txpwrdn2 << 8)); +} + +__INLINE uint8_t ble_radiopwrupdn2_txpwrup2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN2_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +__INLINE void ble_radiopwrupdn2_txpwrup2_setf(uint8_t txpwrup2) +{ + ASSERT_ERR((((uint32_t)txpwrup2 << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN2_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN2_ADDR) & ~((uint32_t)0x000000FF)) | ((uint32_t)txpwrup2 << 0)); +} + +/** + * @brief RADIOPWRUPDN3 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  14:08             TXPWRDN3   0x0
+ *  07:00             TXPWRUP3   0x0
+ * 
+ */ +#define BLE_RADIOPWRUPDN3_ADDR BASEBAND_REG_BASE +0x8C //0x5080008C +#define BLE_RADIOPWRUPDN3_OFFSET 0x0000008C +#define BLE_RADIOPWRUPDN3_INDEX 0x00000023 +#define BLE_RADIOPWRUPDN3_RESET 0x00000000 + +__INLINE uint32_t ble_radiopwrupdn3_get(void) +{ + return REG_BLE_RD(BLE_RADIOPWRUPDN3_ADDR); +} + +__INLINE void ble_radiopwrupdn3_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOPWRUPDN3_ADDR, value); +} + +// field definitions +#define BLE_TXPWRDN3_MASK ((uint32_t)0x00007F00) +#define BLE_TXPWRDN3_LSB 8 +#define BLE_TXPWRDN3_WIDTH ((uint32_t)0x00000007) +#define BLE_TXPWRUP3_MASK ((uint32_t)0x000000FF) +#define BLE_TXPWRUP3_LSB 0 +#define BLE_TXPWRUP3_WIDTH ((uint32_t)0x00000008) + +#define BLE_TXPWRDN3_RST 0x0 +#define BLE_TXPWRUP3_RST 0x0 + +__INLINE void ble_radiopwrupdn3_pack(uint8_t txpwrdn3, uint8_t txpwrup3) +{ + ASSERT_ERR((((uint32_t)txpwrdn3 << 8) & ~((uint32_t)0x00007F00)) == 0); + ASSERT_ERR((((uint32_t)txpwrup3 << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN3_ADDR, ((uint32_t)txpwrdn3 << 8) | ((uint32_t)txpwrup3 << 0)); +} + +__INLINE void ble_radiopwrupdn3_unpack(uint8_t* txpwrdn3, uint8_t* txpwrup3) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN3_ADDR); + + *txpwrdn3 = (localVal & ((uint32_t)0x00007F00)) >> 8; + *txpwrup3 = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_radiopwrupdn3_txpwrdn3_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN3_ADDR); + return ((localVal & ((uint32_t)0x00007F00)) >> 8); +} + +__INLINE void ble_radiopwrupdn3_txpwrdn3_setf(uint8_t txpwrdn3) +{ + ASSERT_ERR((((uint32_t)txpwrdn3 << 8) & ~((uint32_t)0x00007F00)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN3_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN3_ADDR) & ~((uint32_t)0x00007F00)) | ((uint32_t)txpwrdn3 << 8)); +} + +__INLINE uint8_t ble_radiopwrupdn3_txpwrup3_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOPWRUPDN3_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +__INLINE void ble_radiopwrupdn3_txpwrup3_setf(uint8_t txpwrup3) +{ + ASSERT_ERR((((uint32_t)txpwrup3 << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_RADIOPWRUPDN3_ADDR, (REG_BLE_RD(BLE_RADIOPWRUPDN3_ADDR) & ~((uint32_t)0x000000FF)) | ((uint32_t)txpwrup3 << 0)); +} + +/** + * @brief RADIOTXRXTIM0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  22:16            RFRXTMDA0   0x0
+ *  14:08           RXPATHDLY0   0x0
+ *  06:00           TXPATHDLY0   0x0
+ * 
+ */ +#define BLE_RADIOTXRXTIM0_ADDR BASEBAND_REG_BASE +0x90 //0x50800090 +#define BLE_RADIOTXRXTIM0_OFFSET 0x00000090 +#define BLE_RADIOTXRXTIM0_INDEX 0x00000024 +#define BLE_RADIOTXRXTIM0_RESET 0x00000000 + +__INLINE uint32_t ble_radiotxrxtim0_get(void) +{ + return REG_BLE_RD(BLE_RADIOTXRXTIM0_ADDR); +} + +__INLINE void ble_radiotxrxtim0_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOTXRXTIM0_ADDR, value); +} + +// field definitions +#define BLE_RFRXTMDA0_MASK ((uint32_t)0x007F0000) +#define BLE_RFRXTMDA0_LSB 16 +#define BLE_RFRXTMDA0_WIDTH ((uint32_t)0x00000007) +#define BLE_RXPATHDLY0_MASK ((uint32_t)0x00007F00) +#define BLE_RXPATHDLY0_LSB 8 +#define BLE_RXPATHDLY0_WIDTH ((uint32_t)0x00000007) +#define BLE_TXPATHDLY0_MASK ((uint32_t)0x0000007F) +#define BLE_TXPATHDLY0_LSB 0 +#define BLE_TXPATHDLY0_WIDTH ((uint32_t)0x00000007) + +#define BLE_RFRXTMDA0_RST 0x0 +#define BLE_RXPATHDLY0_RST 0x0 +#define BLE_TXPATHDLY0_RST 0x0 + +__INLINE void ble_radiotxrxtim0_pack(uint8_t rfrxtmda0, uint8_t rxpathdly0, uint8_t txpathdly0) +{ + ASSERT_ERR((((uint32_t)rfrxtmda0 << 16) & ~((uint32_t)0x007F0000)) == 0); + ASSERT_ERR((((uint32_t)rxpathdly0 << 8) & ~((uint32_t)0x00007F00)) == 0); + ASSERT_ERR((((uint32_t)txpathdly0 << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM0_ADDR, ((uint32_t)rfrxtmda0 << 16) | ((uint32_t)rxpathdly0 << 8) | ((uint32_t)txpathdly0 << 0)); +} + +__INLINE void ble_radiotxrxtim0_unpack(uint8_t* rfrxtmda0, uint8_t* rxpathdly0, uint8_t* txpathdly0) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM0_ADDR); + + *rfrxtmda0 = (localVal & ((uint32_t)0x007F0000)) >> 16; + *rxpathdly0 = (localVal & ((uint32_t)0x00007F00)) >> 8; + *txpathdly0 = (localVal & ((uint32_t)0x0000007F)) >> 0; +} + +__INLINE uint8_t ble_radiotxrxtim0_rfrxtmda0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM0_ADDR); + return ((localVal & ((uint32_t)0x007F0000)) >> 16); +} + +__INLINE void ble_radiotxrxtim0_rfrxtmda0_setf(uint8_t rfrxtmda0) +{ + ASSERT_ERR((((uint32_t)rfrxtmda0 << 16) & ~((uint32_t)0x007F0000)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM0_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM0_ADDR) & ~((uint32_t)0x007F0000)) | ((uint32_t)rfrxtmda0 << 16)); +} + +__INLINE uint8_t ble_radiotxrxtim0_rxpathdly0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM0_ADDR); + return ((localVal & ((uint32_t)0x00007F00)) >> 8); +} + +__INLINE void ble_radiotxrxtim0_rxpathdly0_setf(uint8_t rxpathdly0) +{ + ASSERT_ERR((((uint32_t)rxpathdly0 << 8) & ~((uint32_t)0x00007F00)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM0_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM0_ADDR) & ~((uint32_t)0x00007F00)) | ((uint32_t)rxpathdly0 << 8)); +} + +__INLINE uint8_t ble_radiotxrxtim0_txpathdly0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM0_ADDR); + return ((localVal & ((uint32_t)0x0000007F)) >> 0); +} + +__INLINE void ble_radiotxrxtim0_txpathdly0_setf(uint8_t txpathdly0) +{ + ASSERT_ERR((((uint32_t)txpathdly0 << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM0_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM0_ADDR) & ~((uint32_t)0x0000007F)) | ((uint32_t)txpathdly0 << 0)); +} + +/** + * @brief RADIOTXRXTIM1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  22:16            RFRXTMDA1   0x0
+ *  14:08           RXPATHDLY1   0x0
+ *  06:00           TXPATHDLY1   0x0
+ * 
+ */ +#define BLE_RADIOTXRXTIM1_ADDR BASEBAND_REG_BASE +0x94 // 0x50800094 +#define BLE_RADIOTXRXTIM1_OFFSET 0x00000094 +#define BLE_RADIOTXRXTIM1_INDEX 0x00000025 +#define BLE_RADIOTXRXTIM1_RESET 0x00000000 + +__INLINE uint32_t ble_radiotxrxtim1_get(void) +{ + return REG_BLE_RD(BLE_RADIOTXRXTIM1_ADDR); +} + +__INLINE void ble_radiotxrxtim1_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOTXRXTIM1_ADDR, value); +} + +// field definitions +#define BLE_RFRXTMDA1_MASK ((uint32_t)0x007F0000) +#define BLE_RFRXTMDA1_LSB 16 +#define BLE_RFRXTMDA1_WIDTH ((uint32_t)0x00000007) +#define BLE_RXPATHDLY1_MASK ((uint32_t)0x00007F00) +#define BLE_RXPATHDLY1_LSB 8 +#define BLE_RXPATHDLY1_WIDTH ((uint32_t)0x00000007) +#define BLE_TXPATHDLY1_MASK ((uint32_t)0x0000007F) +#define BLE_TXPATHDLY1_LSB 0 +#define BLE_TXPATHDLY1_WIDTH ((uint32_t)0x00000007) + +#define BLE_RFRXTMDA1_RST 0x0 +#define BLE_RXPATHDLY1_RST 0x0 +#define BLE_TXPATHDLY1_RST 0x0 + +__INLINE void ble_radiotxrxtim1_pack(uint8_t rfrxtmda1, uint8_t rxpathdly1, uint8_t txpathdly1) +{ + ASSERT_ERR((((uint32_t)rfrxtmda1 << 16) & ~((uint32_t)0x007F0000)) == 0); + ASSERT_ERR((((uint32_t)rxpathdly1 << 8) & ~((uint32_t)0x00007F00)) == 0); + ASSERT_ERR((((uint32_t)txpathdly1 << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM1_ADDR, ((uint32_t)rfrxtmda1 << 16) | ((uint32_t)rxpathdly1 << 8) | ((uint32_t)txpathdly1 << 0)); +} + +__INLINE void ble_radiotxrxtim1_unpack(uint8_t* rfrxtmda1, uint8_t* rxpathdly1, uint8_t* txpathdly1) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM1_ADDR); + + *rfrxtmda1 = (localVal & ((uint32_t)0x007F0000)) >> 16; + *rxpathdly1 = (localVal & ((uint32_t)0x00007F00)) >> 8; + *txpathdly1 = (localVal & ((uint32_t)0x0000007F)) >> 0; +} + +__INLINE uint8_t ble_radiotxrxtim1_rfrxtmda1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM1_ADDR); + return ((localVal & ((uint32_t)0x007F0000)) >> 16); +} + +__INLINE void ble_radiotxrxtim1_rfrxtmda1_setf(uint8_t rfrxtmda1) +{ + ASSERT_ERR((((uint32_t)rfrxtmda1 << 16) & ~((uint32_t)0x007F0000)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM1_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM1_ADDR) & ~((uint32_t)0x007F0000)) | ((uint32_t)rfrxtmda1 << 16)); +} + +__INLINE uint8_t ble_radiotxrxtim1_rxpathdly1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM1_ADDR); + return ((localVal & ((uint32_t)0x00007F00)) >> 8); +} + +__INLINE void ble_radiotxrxtim1_rxpathdly1_setf(uint8_t rxpathdly1) +{ + ASSERT_ERR((((uint32_t)rxpathdly1 << 8) & ~((uint32_t)0x00007F00)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM1_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM1_ADDR) & ~((uint32_t)0x00007F00)) | ((uint32_t)rxpathdly1 << 8)); +} + +__INLINE uint8_t ble_radiotxrxtim1_txpathdly1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM1_ADDR); + return ((localVal & ((uint32_t)0x0000007F)) >> 0); +} + +__INLINE void ble_radiotxrxtim1_txpathdly1_setf(uint8_t txpathdly1) +{ + ASSERT_ERR((((uint32_t)txpathdly1 << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM1_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM1_ADDR) & ~((uint32_t)0x0000007F)) | ((uint32_t)txpathdly1 << 0)); +} + +/** + * @brief RADIOTXRXTIM2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24      RXFLUSHPATHDLY2   0x0
+ *  23:16            RFRXTMDA2   0x0
+ *  15:08           RXPATHDLY2   0x0
+ *  06:00           TXPATHDLY2   0x0
+ * 
+ */ +#define BLE_RADIOTXRXTIM2_ADDR BASEBAND_REG_BASE +0x98 //0x50800098 +#define BLE_RADIOTXRXTIM2_OFFSET 0x00000098 +#define BLE_RADIOTXRXTIM2_INDEX 0x00000026 +#define BLE_RADIOTXRXTIM2_RESET 0x00000000 + +__INLINE uint32_t ble_radiotxrxtim2_get(void) +{ + return REG_BLE_RD(BLE_RADIOTXRXTIM2_ADDR); +} + +__INLINE void ble_radiotxrxtim2_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOTXRXTIM2_ADDR, value); +} + +// field definitions +#define BLE_RXFLUSHPATHDLY2_MASK ((uint32_t)0xFF000000) +#define BLE_RXFLUSHPATHDLY2_LSB 24 +#define BLE_RXFLUSHPATHDLY2_WIDTH ((uint32_t)0x00000008) +#define BLE_RFRXTMDA2_MASK ((uint32_t)0x00FF0000) +#define BLE_RFRXTMDA2_LSB 16 +#define BLE_RFRXTMDA2_WIDTH ((uint32_t)0x00000008) +#define BLE_RXPATHDLY2_MASK ((uint32_t)0x0000FF00) +#define BLE_RXPATHDLY2_LSB 8 +#define BLE_RXPATHDLY2_WIDTH ((uint32_t)0x00000008) +#define BLE_TXPATHDLY2_MASK ((uint32_t)0x0000007F) +#define BLE_TXPATHDLY2_LSB 0 +#define BLE_TXPATHDLY2_WIDTH ((uint32_t)0x00000007) + +#define BLE_RXFLUSHPATHDLY2_RST 0x0 +#define BLE_RFRXTMDA2_RST 0x0 +#define BLE_RXPATHDLY2_RST 0x0 +#define BLE_TXPATHDLY2_RST 0x0 + +__INLINE void ble_radiotxrxtim2_pack(uint8_t rxflushpathdly2, uint8_t rfrxtmda2, uint8_t rxpathdly2, uint8_t txpathdly2) +{ + ASSERT_ERR((((uint32_t)rxflushpathdly2 << 24) & ~((uint32_t)0xFF000000)) == 0); + ASSERT_ERR((((uint32_t)rfrxtmda2 << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)rxpathdly2 << 8) & ~((uint32_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint32_t)txpathdly2 << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM2_ADDR, ((uint32_t)rxflushpathdly2 << 24) | ((uint32_t)rfrxtmda2 << 16) | ((uint32_t)rxpathdly2 << 8) | ((uint32_t)txpathdly2 << 0)); +} + +__INLINE void ble_radiotxrxtim2_unpack(uint8_t* rxflushpathdly2, uint8_t* rfrxtmda2, uint8_t* rxpathdly2, uint8_t* txpathdly2) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM2_ADDR); + + *rxflushpathdly2 = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rfrxtmda2 = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *rxpathdly2 = (localVal & ((uint32_t)0x0000FF00)) >> 8; + *txpathdly2 = (localVal & ((uint32_t)0x0000007F)) >> 0; +} + +__INLINE uint8_t ble_radiotxrxtim2_rxflushpathdly2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM2_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE void ble_radiotxrxtim2_rxflushpathdly2_setf(uint8_t rxflushpathdly2) +{ + ASSERT_ERR((((uint32_t)rxflushpathdly2 << 24) & ~((uint32_t)0xFF000000)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM2_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM2_ADDR) & ~((uint32_t)0xFF000000)) | ((uint32_t)rxflushpathdly2 << 24)); +} + +__INLINE uint8_t ble_radiotxrxtim2_rfrxtmda2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM2_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_radiotxrxtim2_rfrxtmda2_setf(uint8_t rfrxtmda2) +{ + ASSERT_ERR((((uint32_t)rfrxtmda2 << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM2_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM2_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)rfrxtmda2 << 16)); +} + +__INLINE uint8_t ble_radiotxrxtim2_rxpathdly2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM2_ADDR); + return ((localVal & ((uint32_t)0x0000FF00)) >> 8); +} + +__INLINE void ble_radiotxrxtim2_rxpathdly2_setf(uint8_t rxpathdly2) +{ + ASSERT_ERR((((uint32_t)rxpathdly2 << 8) & ~((uint32_t)0x0000FF00)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM2_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM2_ADDR) & ~((uint32_t)0x0000FF00)) | ((uint32_t)rxpathdly2 << 8)); +} + +__INLINE uint8_t ble_radiotxrxtim2_txpathdly2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM2_ADDR); + return ((localVal & ((uint32_t)0x0000007F)) >> 0); +} + +__INLINE void ble_radiotxrxtim2_txpathdly2_setf(uint8_t txpathdly2) +{ + ASSERT_ERR((((uint32_t)txpathdly2 << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM2_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM2_ADDR) & ~((uint32_t)0x0000007F)) | ((uint32_t)txpathdly2 << 0)); +} + +/** + * @brief RADIOTXRXTIM3 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24      RXFLUSHPATHDLY3   0x0
+ *  22:16            RFRXTMDA3   0x0
+ *  06:00           TXPATHDLY3   0x0
+ * 
+ */ +#define BLE_RADIOTXRXTIM3_ADDR BASEBAND_REG_BASE +0x9C //0x5080009C +#define BLE_RADIOTXRXTIM3_OFFSET 0x0000009C +#define BLE_RADIOTXRXTIM3_INDEX 0x00000027 +#define BLE_RADIOTXRXTIM3_RESET 0x00000000 + +__INLINE uint32_t ble_radiotxrxtim3_get(void) +{ + return REG_BLE_RD(BLE_RADIOTXRXTIM3_ADDR); +} + +__INLINE void ble_radiotxrxtim3_set(uint32_t value) +{ + REG_BLE_WR(BLE_RADIOTXRXTIM3_ADDR, value); +} + +// field definitions +#define BLE_RXFLUSHPATHDLY3_MASK ((uint32_t)0xFF000000) +#define BLE_RXFLUSHPATHDLY3_LSB 24 +#define BLE_RXFLUSHPATHDLY3_WIDTH ((uint32_t)0x00000008) +#define BLE_RFRXTMDA3_MASK ((uint32_t)0x007F0000) +#define BLE_RFRXTMDA3_LSB 16 +#define BLE_RFRXTMDA3_WIDTH ((uint32_t)0x00000007) +#define BLE_TXPATHDLY3_MASK ((uint32_t)0x0000007F) +#define BLE_TXPATHDLY3_LSB 0 +#define BLE_TXPATHDLY3_WIDTH ((uint32_t)0x00000007) + +#define BLE_RXFLUSHPATHDLY3_RST 0x0 +#define BLE_RFRXTMDA3_RST 0x0 +#define BLE_TXPATHDLY3_RST 0x0 + +__INLINE void ble_radiotxrxtim3_pack(uint8_t rxflushpathdly3, uint8_t rfrxtmda3, uint8_t txpathdly3) +{ + ASSERT_ERR((((uint32_t)rxflushpathdly3 << 24) & ~((uint32_t)0xFF000000)) == 0); + ASSERT_ERR((((uint32_t)rfrxtmda3 << 16) & ~((uint32_t)0x007F0000)) == 0); + ASSERT_ERR((((uint32_t)txpathdly3 << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM3_ADDR, ((uint32_t)rxflushpathdly3 << 24) | ((uint32_t)rfrxtmda3 << 16) | ((uint32_t)txpathdly3 << 0)); +} + +__INLINE void ble_radiotxrxtim3_unpack(uint8_t* rxflushpathdly3, uint8_t* rfrxtmda3, uint8_t* txpathdly3) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM3_ADDR); + + *rxflushpathdly3 = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rfrxtmda3 = (localVal & ((uint32_t)0x007F0000)) >> 16; + *txpathdly3 = (localVal & ((uint32_t)0x0000007F)) >> 0; +} + +__INLINE uint8_t ble_radiotxrxtim3_rxflushpathdly3_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM3_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE void ble_radiotxrxtim3_rxflushpathdly3_setf(uint8_t rxflushpathdly3) +{ + ASSERT_ERR((((uint32_t)rxflushpathdly3 << 24) & ~((uint32_t)0xFF000000)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM3_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM3_ADDR) & ~((uint32_t)0xFF000000)) | ((uint32_t)rxflushpathdly3 << 24)); +} + +__INLINE uint8_t ble_radiotxrxtim3_rfrxtmda3_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM3_ADDR); + return ((localVal & ((uint32_t)0x007F0000)) >> 16); +} + +__INLINE void ble_radiotxrxtim3_rfrxtmda3_setf(uint8_t rfrxtmda3) +{ + ASSERT_ERR((((uint32_t)rfrxtmda3 << 16) & ~((uint32_t)0x007F0000)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM3_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM3_ADDR) & ~((uint32_t)0x007F0000)) | ((uint32_t)rfrxtmda3 << 16)); +} + +__INLINE uint8_t ble_radiotxrxtim3_txpathdly3_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RADIOTXRXTIM3_ADDR); + return ((localVal & ((uint32_t)0x0000007F)) >> 0); +} + +__INLINE void ble_radiotxrxtim3_txpathdly3_setf(uint8_t txpathdly3) +{ + ASSERT_ERR((((uint32_t)txpathdly3 << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_RADIOTXRXTIM3_ADDR, (REG_BLE_RD(BLE_RADIOTXRXTIM3_ADDR) & ~((uint32_t)0x0000007F)) | ((uint32_t)txpathdly3 << 0)); +} + +/** + * @brief SPIPTRCNTL0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  29:16             TXOFFPTR   0x0
+ *  13:00              TXONPTR   0x0
+ * 
+ */ +#define BLE_SPIPTRCNTL0_ADDR BASEBAND_REG_BASE +0xA0 //0x508000A0 +#define BLE_SPIPTRCNTL0_OFFSET 0x000000A0 +#define BLE_SPIPTRCNTL0_INDEX 0x00000028 +#define BLE_SPIPTRCNTL0_RESET 0x00000000 + +__INLINE uint32_t ble_spiptrcntl0_get(void) +{ + return REG_BLE_RD(BLE_SPIPTRCNTL0_ADDR); +} + +__INLINE void ble_spiptrcntl0_set(uint32_t value) +{ + REG_BLE_WR(BLE_SPIPTRCNTL0_ADDR, value); +} + +// field definitions +#define BLE_TXOFFPTR_MASK ((uint32_t)0x3FFF0000) +#define BLE_TXOFFPTR_LSB 16 +#define BLE_TXOFFPTR_WIDTH ((uint32_t)0x0000000E) +#define BLE_TXONPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_TXONPTR_LSB 0 +#define BLE_TXONPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_TXOFFPTR_RST 0x0 +#define BLE_TXONPTR_RST 0x0 + +__INLINE void ble_spiptrcntl0_pack(uint16_t txoffptr, uint16_t txonptr) +{ + ASSERT_ERR((((uint32_t)txoffptr << 16) & ~((uint32_t)0x3FFF0000)) == 0); + ASSERT_ERR((((uint32_t)txonptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_SPIPTRCNTL0_ADDR, ((uint32_t)txoffptr << 16) | ((uint32_t)txonptr << 0)); +} + +__INLINE void ble_spiptrcntl0_unpack(uint16_t* txoffptr, uint16_t* txonptr) +{ + uint32_t localVal = REG_BLE_RD(BLE_SPIPTRCNTL0_ADDR); + + *txoffptr = (localVal & ((uint32_t)0x3FFF0000)) >> 16; + *txonptr = (localVal & ((uint32_t)0x00003FFF)) >> 0; +} + +__INLINE uint16_t ble_spiptrcntl0_txoffptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SPIPTRCNTL0_ADDR); + return ((localVal & ((uint32_t)0x3FFF0000)) >> 16); +} + +__INLINE void ble_spiptrcntl0_txoffptr_setf(uint16_t txoffptr) +{ + ASSERT_ERR((((uint32_t)txoffptr << 16) & ~((uint32_t)0x3FFF0000)) == 0); + REG_BLE_WR(BLE_SPIPTRCNTL0_ADDR, (REG_BLE_RD(BLE_SPIPTRCNTL0_ADDR) & ~((uint32_t)0x3FFF0000)) | ((uint32_t)txoffptr << 16)); +} + +__INLINE uint16_t ble_spiptrcntl0_txonptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SPIPTRCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00003FFF)) >> 0); +} + +__INLINE void ble_spiptrcntl0_txonptr_setf(uint16_t txonptr) +{ + ASSERT_ERR((((uint32_t)txonptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_SPIPTRCNTL0_ADDR, (REG_BLE_RD(BLE_SPIPTRCNTL0_ADDR) & ~((uint32_t)0x00003FFF)) | ((uint32_t)txonptr << 0)); +} + +/** + * @brief SPIPTRCNTL1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  29:16             RXOFFPTR   0x0
+ *  13:00              RXONPTR   0x0
+ * 
+ */ +#define BLE_SPIPTRCNTL1_ADDR BASEBAND_REG_BASE +0xA4 //0x508000A4 +#define BLE_SPIPTRCNTL1_OFFSET 0x000000A4 +#define BLE_SPIPTRCNTL1_INDEX 0x00000029 +#define BLE_SPIPTRCNTL1_RESET 0x00000000 + +__INLINE uint32_t ble_spiptrcntl1_get(void) +{ + return REG_BLE_RD(BLE_SPIPTRCNTL1_ADDR); +} + +__INLINE void ble_spiptrcntl1_set(uint32_t value) +{ + REG_BLE_WR(BLE_SPIPTRCNTL1_ADDR, value); +} + +// field definitions +#define BLE_RXOFFPTR_MASK ((uint32_t)0x3FFF0000) +#define BLE_RXOFFPTR_LSB 16 +#define BLE_RXOFFPTR_WIDTH ((uint32_t)0x0000000E) +#define BLE_RXONPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_RXONPTR_LSB 0 +#define BLE_RXONPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_RXOFFPTR_RST 0x0 +#define BLE_RXONPTR_RST 0x0 + +__INLINE void ble_spiptrcntl1_pack(uint16_t rxoffptr, uint16_t rxonptr) +{ + ASSERT_ERR((((uint32_t)rxoffptr << 16) & ~((uint32_t)0x3FFF0000)) == 0); + ASSERT_ERR((((uint32_t)rxonptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_SPIPTRCNTL1_ADDR, ((uint32_t)rxoffptr << 16) | ((uint32_t)rxonptr << 0)); +} + +__INLINE void ble_spiptrcntl1_unpack(uint16_t* rxoffptr, uint16_t* rxonptr) +{ + uint32_t localVal = REG_BLE_RD(BLE_SPIPTRCNTL1_ADDR); + + *rxoffptr = (localVal & ((uint32_t)0x3FFF0000)) >> 16; + *rxonptr = (localVal & ((uint32_t)0x00003FFF)) >> 0; +} + +__INLINE uint16_t ble_spiptrcntl1_rxoffptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SPIPTRCNTL1_ADDR); + return ((localVal & ((uint32_t)0x3FFF0000)) >> 16); +} + +__INLINE void ble_spiptrcntl1_rxoffptr_setf(uint16_t rxoffptr) +{ + ASSERT_ERR((((uint32_t)rxoffptr << 16) & ~((uint32_t)0x3FFF0000)) == 0); + REG_BLE_WR(BLE_SPIPTRCNTL1_ADDR, (REG_BLE_RD(BLE_SPIPTRCNTL1_ADDR) & ~((uint32_t)0x3FFF0000)) | ((uint32_t)rxoffptr << 16)); +} + +__INLINE uint16_t ble_spiptrcntl1_rxonptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SPIPTRCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00003FFF)) >> 0); +} + +__INLINE void ble_spiptrcntl1_rxonptr_setf(uint16_t rxonptr) +{ + ASSERT_ERR((((uint32_t)rxonptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_SPIPTRCNTL1_ADDR, (REG_BLE_RD(BLE_SPIPTRCNTL1_ADDR) & ~((uint32_t)0x00003FFF)) | ((uint32_t)rxonptr << 0)); +} + +/** + * @brief SPIPTRCNTL2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  29:16          RXLENGTHPTR   0x0
+ *  13:00              RSSIPTR   0x0
+ * 
+ */ +#define BLE_SPIPTRCNTL2_ADDR BASEBAND_REG_BASE +0xA8 //0x508000A8 +#define BLE_SPIPTRCNTL2_OFFSET 0x000000A8 +#define BLE_SPIPTRCNTL2_INDEX 0x0000002A +#define BLE_SPIPTRCNTL2_RESET 0x00000000 + +__INLINE uint32_t ble_spiptrcntl2_get(void) +{ + return REG_BLE_RD(BLE_SPIPTRCNTL2_ADDR); +} + +__INLINE void ble_spiptrcntl2_set(uint32_t value) +{ + REG_BLE_WR(BLE_SPIPTRCNTL2_ADDR, value); +} + +// field definitions +#define BLE_RXLENGTHPTR_MASK ((uint32_t)0x3FFF0000) +#define BLE_RXLENGTHPTR_LSB 16 +#define BLE_RXLENGTHPTR_WIDTH ((uint32_t)0x0000000E) +#define BLE_RSSIPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_RSSIPTR_LSB 0 +#define BLE_RSSIPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_RXLENGTHPTR_RST 0x0 +#define BLE_RSSIPTR_RST 0x0 + +__INLINE void ble_spiptrcntl2_pack(uint16_t rxlengthptr, uint16_t rssiptr) +{ + ASSERT_ERR((((uint32_t)rxlengthptr << 16) & ~((uint32_t)0x3FFF0000)) == 0); + ASSERT_ERR((((uint32_t)rssiptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_SPIPTRCNTL2_ADDR, ((uint32_t)rxlengthptr << 16) | ((uint32_t)rssiptr << 0)); +} + +__INLINE void ble_spiptrcntl2_unpack(uint16_t* rxlengthptr, uint16_t* rssiptr) +{ + uint32_t localVal = REG_BLE_RD(BLE_SPIPTRCNTL2_ADDR); + + *rxlengthptr = (localVal & ((uint32_t)0x3FFF0000)) >> 16; + *rssiptr = (localVal & ((uint32_t)0x00003FFF)) >> 0; +} + +__INLINE uint16_t ble_spiptrcntl2_rxlengthptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SPIPTRCNTL2_ADDR); + return ((localVal & ((uint32_t)0x3FFF0000)) >> 16); +} + +__INLINE void ble_spiptrcntl2_rxlengthptr_setf(uint16_t rxlengthptr) +{ + ASSERT_ERR((((uint32_t)rxlengthptr << 16) & ~((uint32_t)0x3FFF0000)) == 0); + REG_BLE_WR(BLE_SPIPTRCNTL2_ADDR, (REG_BLE_RD(BLE_SPIPTRCNTL2_ADDR) & ~((uint32_t)0x3FFF0000)) | ((uint32_t)rxlengthptr << 16)); +} + +__INLINE uint16_t ble_spiptrcntl2_rssiptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SPIPTRCNTL2_ADDR); + return ((localVal & ((uint32_t)0x00003FFF)) >> 0); +} + +__INLINE void ble_spiptrcntl2_rssiptr_setf(uint16_t rssiptr) +{ + ASSERT_ERR((((uint32_t)rssiptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_SPIPTRCNTL2_ADDR, (REG_BLE_RD(BLE_SPIPTRCNTL2_ADDR) & ~((uint32_t)0x00003FFF)) | ((uint32_t)rssiptr << 0)); +} + +/** + * @brief SPIPTRCNTL3 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00          RXPKTTYPPTR   0x0
+ * 
+ */ +#define BLE_SPIPTRCNTL3_ADDR BASEBAND_REG_BASE +0xAC // 0x508000AC +#define BLE_SPIPTRCNTL3_OFFSET 0x000000AC +#define BLE_SPIPTRCNTL3_INDEX 0x0000002B +#define BLE_SPIPTRCNTL3_RESET 0x00000000 + +__INLINE uint32_t ble_spiptrcntl3_get(void) +{ + return REG_BLE_RD(BLE_SPIPTRCNTL3_ADDR); +} + +__INLINE void ble_spiptrcntl3_set(uint32_t value) +{ + REG_BLE_WR(BLE_SPIPTRCNTL3_ADDR, value); +} + +// field definitions +#define BLE_RXPKTTYPPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_RXPKTTYPPTR_LSB 0 +#define BLE_RXPKTTYPPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_RXPKTTYPPTR_RST 0x0 + +__INLINE uint16_t ble_spiptrcntl3_rxpkttypptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SPIPTRCNTL3_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_spiptrcntl3_rxpkttypptr_setf(uint16_t rxpkttypptr) +{ + ASSERT_ERR((((uint32_t)rxpkttypptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_SPIPTRCNTL3_ADDR, (uint32_t)rxpkttypptr << 0); +} + +/** + * @brief AESCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     01             AES_MODE   0
+ *     00            AES_START   0
+ * 
+ */ +#define BLE_AESCNTL_ADDR BASEBAND_REG_BASE +0xB0 //0x508000B0 +#define BLE_AESCNTL_OFFSET 0x000000B0 +#define BLE_AESCNTL_INDEX 0x0000002C +#define BLE_AESCNTL_RESET 0x00000000 + +__INLINE uint32_t ble_aescntl_get(void) +{ + return REG_BLE_RD(BLE_AESCNTL_ADDR); +} + +__INLINE void ble_aescntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_AESCNTL_ADDR, value); +} + +// field definitions +#define BLE_AES_MODE_BIT ((uint32_t)0x00000002) +#define BLE_AES_MODE_POS 1 +#define BLE_AES_START_BIT ((uint32_t)0x00000001) +#define BLE_AES_START_POS 0 + +#define BLE_AES_MODE_RST 0x0 +#define BLE_AES_START_RST 0x0 + +__INLINE void ble_aescntl_pack(uint8_t aesmode, uint8_t aesstart) +{ + ASSERT_ERR((((uint32_t)aesmode << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)aesstart << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_AESCNTL_ADDR, ((uint32_t)aesmode << 1) | ((uint32_t)aesstart << 0)); +} + +__INLINE void ble_aescntl_unpack(uint8_t* aesmode, uint8_t* aesstart) +{ + uint32_t localVal = REG_BLE_RD(BLE_AESCNTL_ADDR); + + *aesmode = (localVal & ((uint32_t)0x00000002)) >> 1; + *aesstart = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_aescntl_aes_mode_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_AESCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ble_aescntl_aes_mode_setf(uint8_t aesmode) +{ + ASSERT_ERR((((uint32_t)aesmode << 1) & ~((uint32_t)0x00000002)) == 0); + REG_BLE_WR(BLE_AESCNTL_ADDR, (REG_BLE_RD(BLE_AESCNTL_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)aesmode << 1)); +} + +__INLINE uint8_t ble_aescntl_aes_start_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_AESCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ble_aescntl_aes_start_setf(uint8_t aesstart) +{ + ASSERT_ERR((((uint32_t)aesstart << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_AESCNTL_ADDR, (REG_BLE_RD(BLE_AESCNTL_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)aesstart << 0)); +} + +/** + * @brief AESKEY31_0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00           AESKEY31_0   0x0
+ * 
+ */ +#define BLE_AESKEY31_0_ADDR BASEBAND_REG_BASE +0xB4 // 0x508000B4 +#define BLE_AESKEY31_0_OFFSET 0x000000B4 +#define BLE_AESKEY31_0_INDEX 0x0000002D +#define BLE_AESKEY31_0_RESET 0x00000000 + +__INLINE uint32_t ble_aeskey31_0_get(void) +{ + return REG_BLE_RD(BLE_AESKEY31_0_ADDR); +} + +__INLINE void ble_aeskey31_0_set(uint32_t value) +{ + REG_BLE_WR(BLE_AESKEY31_0_ADDR, value); +} + +// field definitions +#define BLE_AESKEY31_0_MASK ((uint32_t)0xFFFFFFFF) +#define BLE_AESKEY31_0_LSB 0 +#define BLE_AESKEY31_0_WIDTH ((uint32_t)0x00000020) + +#define BLE_AESKEY31_0_RST 0x0 + +__INLINE uint32_t ble_aeskey31_0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_AESKEY31_0_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_aeskey31_0_setf(uint32_t aeskey310) +{ + ASSERT_ERR((((uint32_t)aeskey310 << 0) & ~((uint32_t)0xFFFFFFFF)) == 0); + REG_BLE_WR(BLE_AESKEY31_0_ADDR, (uint32_t)aeskey310 << 0); +} + +/** + * @brief AESKEY63_32 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00          AESKEY63_32   0x0
+ * 
+ */ +#define BLE_AESKEY63_32_ADDR BASEBAND_REG_BASE +0xB8 // 0x508000B8 +#define BLE_AESKEY63_32_OFFSET 0x000000B8 +#define BLE_AESKEY63_32_INDEX 0x0000002E +#define BLE_AESKEY63_32_RESET 0x00000000 + +__INLINE uint32_t ble_aeskey63_32_get(void) +{ + return REG_BLE_RD(BLE_AESKEY63_32_ADDR); +} + +__INLINE void ble_aeskey63_32_set(uint32_t value) +{ + REG_BLE_WR(BLE_AESKEY63_32_ADDR, value); +} + +// field definitions +#define BLE_AESKEY63_32_MASK ((uint32_t)0xFFFFFFFF) +#define BLE_AESKEY63_32_LSB 0 +#define BLE_AESKEY63_32_WIDTH ((uint32_t)0x00000020) + +#define BLE_AESKEY63_32_RST 0x0 + +__INLINE uint32_t ble_aeskey63_32_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_AESKEY63_32_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_aeskey63_32_setf(uint32_t aeskey6332) +{ + ASSERT_ERR((((uint32_t)aeskey6332 << 0) & ~((uint32_t)0xFFFFFFFF)) == 0); + REG_BLE_WR(BLE_AESKEY63_32_ADDR, (uint32_t)aeskey6332 << 0); +} + +/** + * @brief AESKEY95_64 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00          AESKEY95_64   0x0
+ * 
+ */ +#define BLE_AESKEY95_64_ADDR BASEBAND_REG_BASE +0xBC //0x508000BC +#define BLE_AESKEY95_64_OFFSET 0x000000BC +#define BLE_AESKEY95_64_INDEX 0x0000002F +#define BLE_AESKEY95_64_RESET 0x00000000 + +__INLINE uint32_t ble_aeskey95_64_get(void) +{ + return REG_BLE_RD(BLE_AESKEY95_64_ADDR); +} + +__INLINE void ble_aeskey95_64_set(uint32_t value) +{ + REG_BLE_WR(BLE_AESKEY95_64_ADDR, value); +} + +// field definitions +#define BLE_AESKEY95_64_MASK ((uint32_t)0xFFFFFFFF) +#define BLE_AESKEY95_64_LSB 0 +#define BLE_AESKEY95_64_WIDTH ((uint32_t)0x00000020) + +#define BLE_AESKEY95_64_RST 0x0 + +__INLINE uint32_t ble_aeskey95_64_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_AESKEY95_64_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_aeskey95_64_setf(uint32_t aeskey9564) +{ + ASSERT_ERR((((uint32_t)aeskey9564 << 0) & ~((uint32_t)0xFFFFFFFF)) == 0); + REG_BLE_WR(BLE_AESKEY95_64_ADDR, (uint32_t)aeskey9564 << 0); +} + +/** + * @brief AESKEY127_96 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00         AESKEY127_96   0x0
+ * 
+ */ +#define BLE_AESKEY127_96_ADDR BASEBAND_REG_BASE +0xC0 //0x508000C0 +#define BLE_AESKEY127_96_OFFSET 0x000000C0 +#define BLE_AESKEY127_96_INDEX 0x00000030 +#define BLE_AESKEY127_96_RESET 0x00000000 + +__INLINE uint32_t ble_aeskey127_96_get(void) +{ + return REG_BLE_RD(BLE_AESKEY127_96_ADDR); +} + +__INLINE void ble_aeskey127_96_set(uint32_t value) +{ + REG_BLE_WR(BLE_AESKEY127_96_ADDR, value); +} + +// field definitions +#define BLE_AESKEY127_96_MASK ((uint32_t)0xFFFFFFFF) +#define BLE_AESKEY127_96_LSB 0 +#define BLE_AESKEY127_96_WIDTH ((uint32_t)0x00000020) + +#define BLE_AESKEY127_96_RST 0x0 + +__INLINE uint32_t ble_aeskey127_96_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_AESKEY127_96_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_aeskey127_96_setf(uint32_t aeskey12796) +{ + ASSERT_ERR((((uint32_t)aeskey12796 << 0) & ~((uint32_t)0xFFFFFFFF)) == 0); + REG_BLE_WR(BLE_AESKEY127_96_ADDR, (uint32_t)aeskey12796 << 0); +} + +/** + * @brief AESPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00               AESPTR   0x0
+ * 
+ */ +#define BLE_AESPTR_ADDR BASEBAND_REG_BASE +0xC4 //0x508000C4 +#define BLE_AESPTR_OFFSET 0x000000C4 +#define BLE_AESPTR_INDEX 0x00000031 +#define BLE_AESPTR_RESET 0x00000000 + +__INLINE uint32_t ble_aesptr_get(void) +{ + return REG_BLE_RD(BLE_AESPTR_ADDR); +} + +__INLINE void ble_aesptr_set(uint32_t value) +{ + REG_BLE_WR(BLE_AESPTR_ADDR, value); +} + +// field definitions +#define BLE_AESPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_AESPTR_LSB 0 +#define BLE_AESPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_AESPTR_RST 0x0 + +__INLINE uint16_t ble_aesptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_AESPTR_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_aesptr_setf(uint16_t aesptr) +{ + ASSERT_ERR((((uint32_t)aesptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_AESPTR_ADDR, (uint32_t)aesptr << 0); +} + +/** + * @brief TXMICVAL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00             TXMICVAL   0x0
+ * 
+ */ +#define BLE_TXMICVAL_ADDR BASEBAND_REG_BASE +0xC8 //0x508000C8 +#define BLE_TXMICVAL_OFFSET 0x000000C8 +#define BLE_TXMICVAL_INDEX 0x00000032 +#define BLE_TXMICVAL_RESET 0x00000000 + +__INLINE uint32_t ble_txmicval_get(void) +{ + return REG_BLE_RD(BLE_TXMICVAL_ADDR); +} + +// field definitions +#define BLE_TXMICVAL_MASK ((uint32_t)0xFFFFFFFF) +#define BLE_TXMICVAL_LSB 0 +#define BLE_TXMICVAL_WIDTH ((uint32_t)0x00000020) + +#define BLE_TXMICVAL_RST 0x0 + +__INLINE uint32_t ble_txmicval_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_TXMICVAL_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief RXMICVAL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00             RXMICVAL   0x0
+ * 
+ */ +#define BLE_RXMICVAL_ADDR BASEBAND_REG_BASE +0xCC //0x508000CC +#define BLE_RXMICVAL_OFFSET 0x000000CC +#define BLE_RXMICVAL_INDEX 0x00000033 +#define BLE_RXMICVAL_RESET 0x00000000 + +__INLINE uint32_t ble_rxmicval_get(void) +{ + return REG_BLE_RD(BLE_RXMICVAL_ADDR); +} + +// field definitions +#define BLE_RXMICVAL_MASK ((uint32_t)0xFFFFFFFF) +#define BLE_RXMICVAL_LSB 0 +#define BLE_RXMICVAL_WIDTH ((uint32_t)0x00000020) + +#define BLE_RXMICVAL_RST 0x0 + +__INLINE uint32_t ble_rxmicval_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RXMICVAL_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief RFTESTCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31           INFINITERX   0
+ *     27           RXPKTCNTEN   0
+ *  25:24        PERCOUNT_MODE   0x0
+ *     15           INFINITETX   0
+ *     14          TXLENGTHSRC   0
+ *     13             PRBSTYPE   0
+ *     12             TXPLDSRC   0
+ *     11           TXPKTCNTEN   0
+ *  07:00             TXLENGTH   0x0
+ * 
+ */ +#define BLE_RFTESTCNTL_ADDR BASEBAND_REG_BASE +0xD0 //0x508000D0 +#define BLE_RFTESTCNTL_OFFSET 0x000000D0 +#define BLE_RFTESTCNTL_INDEX 0x00000034 +#define BLE_RFTESTCNTL_RESET 0x00000000 + +__INLINE uint32_t ble_rftestcntl_get(void) +{ + return REG_BLE_RD(BLE_RFTESTCNTL_ADDR); +} + +__INLINE void ble_rftestcntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, value); +} + +// field definitions +#define BLE_INFINITERX_BIT ((uint32_t)0x80000000) +#define BLE_INFINITERX_POS 31 +#define BLE_RXPKTCNTEN_BIT ((uint32_t)0x08000000) +#define BLE_RXPKTCNTEN_POS 27 +#define BLE_PERCOUNT_MODE_MASK ((uint32_t)0x03000000) +#define BLE_PERCOUNT_MODE_LSB 24 +#define BLE_PERCOUNT_MODE_WIDTH ((uint32_t)0x00000002) +#define BLE_INFINITETX_BIT ((uint32_t)0x00008000) +#define BLE_INFINITETX_POS 15 +#define BLE_TXLENGTHSRC_BIT ((uint32_t)0x00004000) +#define BLE_TXLENGTHSRC_POS 14 +#define BLE_PRBSTYPE_BIT ((uint32_t)0x00002000) +#define BLE_PRBSTYPE_POS 13 +#define BLE_TXPLDSRC_BIT ((uint32_t)0x00001000) +#define BLE_TXPLDSRC_POS 12 +#define BLE_TXPKTCNTEN_BIT ((uint32_t)0x00000800) +#define BLE_TXPKTCNTEN_POS 11 +#define BLE_TXLENGTH_MASK ((uint32_t)0x000000FF) +#define BLE_TXLENGTH_LSB 0 +#define BLE_TXLENGTH_WIDTH ((uint32_t)0x00000008) + +#define BLE_INFINITERX_RST 0x0 +#define BLE_RXPKTCNTEN_RST 0x0 +#define BLE_PERCOUNT_MODE_RST 0x0 +#define BLE_INFINITETX_RST 0x0 +#define BLE_TXLENGTHSRC_RST 0x0 +#define BLE_PRBSTYPE_RST 0x0 +#define BLE_TXPLDSRC_RST 0x0 +#define BLE_TXPKTCNTEN_RST 0x0 +#define BLE_TXLENGTH_RST 0x0 + +__INLINE void ble_rftestcntl_pack(uint8_t infiniterx, uint8_t rxpktcnten, uint8_t percountmode, uint8_t infinitetx, uint8_t txlengthsrc, uint8_t prbstype, uint8_t txpldsrc, uint8_t txpktcnten, uint8_t txlength) +{ + ASSERT_ERR((((uint32_t)infiniterx << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)rxpktcnten << 27) & ~((uint32_t)0x08000000)) == 0); + ASSERT_ERR((((uint32_t)percountmode << 24) & ~((uint32_t)0x03000000)) == 0); + ASSERT_ERR((((uint32_t)infinitetx << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)txlengthsrc << 14) & ~((uint32_t)0x00004000)) == 0); + ASSERT_ERR((((uint32_t)prbstype << 13) & ~((uint32_t)0x00002000)) == 0); + ASSERT_ERR((((uint32_t)txpldsrc << 12) & ~((uint32_t)0x00001000)) == 0); + ASSERT_ERR((((uint32_t)txpktcnten << 11) & ~((uint32_t)0x00000800)) == 0); + ASSERT_ERR((((uint32_t)txlength << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, ((uint32_t)infiniterx << 31) | ((uint32_t)rxpktcnten << 27) | ((uint32_t)percountmode << 24) | ((uint32_t)infinitetx << 15) | ((uint32_t)txlengthsrc << 14) | ((uint32_t)prbstype << 13) | ((uint32_t)txpldsrc << 12) | ((uint32_t)txpktcnten << 11) | ((uint32_t)txlength << 0)); +} + +__INLINE void ble_rftestcntl_unpack(uint8_t* infiniterx, uint8_t* rxpktcnten, uint8_t* percountmode, uint8_t* infinitetx, uint8_t* txlengthsrc, uint8_t* prbstype, uint8_t* txpldsrc, uint8_t* txpktcnten, uint8_t* txlength) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTCNTL_ADDR); + + *infiniterx = (localVal & ((uint32_t)0x80000000)) >> 31; + *rxpktcnten = (localVal & ((uint32_t)0x08000000)) >> 27; + *percountmode = (localVal & ((uint32_t)0x03000000)) >> 24; + *infinitetx = (localVal & ((uint32_t)0x00008000)) >> 15; + *txlengthsrc = (localVal & ((uint32_t)0x00004000)) >> 14; + *prbstype = (localVal & ((uint32_t)0x00002000)) >> 13; + *txpldsrc = (localVal & ((uint32_t)0x00001000)) >> 12; + *txpktcnten = (localVal & ((uint32_t)0x00000800)) >> 11; + *txlength = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_rftestcntl_infiniterx_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTCNTL_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_rftestcntl_infiniterx_setf(uint8_t infiniterx) +{ + ASSERT_ERR((((uint32_t)infiniterx << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, (REG_BLE_RD(BLE_RFTESTCNTL_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)infiniterx << 31)); +} + +__INLINE uint8_t ble_rftestcntl_rxpktcnten_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTCNTL_ADDR); + return ((localVal & ((uint32_t)0x08000000)) >> 27); +} + +__INLINE void ble_rftestcntl_rxpktcnten_setf(uint8_t rxpktcnten) +{ + ASSERT_ERR((((uint32_t)rxpktcnten << 27) & ~((uint32_t)0x08000000)) == 0); + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, (REG_BLE_RD(BLE_RFTESTCNTL_ADDR) & ~((uint32_t)0x08000000)) | ((uint32_t)rxpktcnten << 27)); +} + +__INLINE uint8_t ble_rftestcntl_percount_mode_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTCNTL_ADDR); + return ((localVal & ((uint32_t)0x03000000)) >> 24); +} + +__INLINE void ble_rftestcntl_percount_mode_setf(uint8_t percountmode) +{ + ASSERT_ERR((((uint32_t)percountmode << 24) & ~((uint32_t)0x03000000)) == 0); + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, (REG_BLE_RD(BLE_RFTESTCNTL_ADDR) & ~((uint32_t)0x03000000)) | ((uint32_t)percountmode << 24)); +} + +__INLINE uint8_t ble_rftestcntl_infinitetx_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTCNTL_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ble_rftestcntl_infinitetx_setf(uint8_t infinitetx) +{ + ASSERT_ERR((((uint32_t)infinitetx << 15) & ~((uint32_t)0x00008000)) == 0); + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, (REG_BLE_RD(BLE_RFTESTCNTL_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)infinitetx << 15)); +} + +__INLINE uint8_t ble_rftestcntl_txlengthsrc_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTCNTL_ADDR); + return ((localVal & ((uint32_t)0x00004000)) >> 14); +} + +__INLINE void ble_rftestcntl_txlengthsrc_setf(uint8_t txlengthsrc) +{ + ASSERT_ERR((((uint32_t)txlengthsrc << 14) & ~((uint32_t)0x00004000)) == 0); + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, (REG_BLE_RD(BLE_RFTESTCNTL_ADDR) & ~((uint32_t)0x00004000)) | ((uint32_t)txlengthsrc << 14)); +} + +__INLINE uint8_t ble_rftestcntl_prbstype_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTCNTL_ADDR); + return ((localVal & ((uint32_t)0x00002000)) >> 13); +} + +__INLINE void ble_rftestcntl_prbstype_setf(uint8_t prbstype) +{ + ASSERT_ERR((((uint32_t)prbstype << 13) & ~((uint32_t)0x00002000)) == 0); + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, (REG_BLE_RD(BLE_RFTESTCNTL_ADDR) & ~((uint32_t)0x00002000)) | ((uint32_t)prbstype << 13)); +} + +__INLINE uint8_t ble_rftestcntl_txpldsrc_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTCNTL_ADDR); + return ((localVal & ((uint32_t)0x00001000)) >> 12); +} + +__INLINE void ble_rftestcntl_txpldsrc_setf(uint8_t txpldsrc) +{ + ASSERT_ERR((((uint32_t)txpldsrc << 12) & ~((uint32_t)0x00001000)) == 0); + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, (REG_BLE_RD(BLE_RFTESTCNTL_ADDR) & ~((uint32_t)0x00001000)) | ((uint32_t)txpldsrc << 12)); +} + +__INLINE uint8_t ble_rftestcntl_txpktcnten_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000800)) >> 11); +} + +__INLINE void ble_rftestcntl_txpktcnten_setf(uint8_t txpktcnten) +{ + ASSERT_ERR((((uint32_t)txpktcnten << 11) & ~((uint32_t)0x00000800)) == 0); + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, (REG_BLE_RD(BLE_RFTESTCNTL_ADDR) & ~((uint32_t)0x00000800)) | ((uint32_t)txpktcnten << 11)); +} + +__INLINE uint8_t ble_rftestcntl_txlength_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTCNTL_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +__INLINE void ble_rftestcntl_txlength_setf(uint8_t txlength) +{ + ASSERT_ERR((((uint32_t)txlength << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_RFTESTCNTL_ADDR, (REG_BLE_RD(BLE_RFTESTCNTL_ADDR) & ~((uint32_t)0x000000FF)) | ((uint32_t)txlength << 0)); +} + +/** + * @brief RFTESTTXSTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00             TXPKTCNT   0x0
+ * 
+ */ +#define BLE_RFTESTTXSTAT_ADDR BASEBAND_REG_BASE +0xD4 //0x508000D4 +#define BLE_RFTESTTXSTAT_OFFSET 0x000000D4 +#define BLE_RFTESTTXSTAT_INDEX 0x00000035 +#define BLE_RFTESTTXSTAT_RESET 0x00000000 + +__INLINE uint32_t ble_rftesttxstat_get(void) +{ + return REG_BLE_RD(BLE_RFTESTTXSTAT_ADDR); +} + +// field definitions +#define BLE_TXPKTCNT_MASK ((uint32_t)0xFFFFFFFF) +#define BLE_TXPKTCNT_LSB 0 +#define BLE_TXPKTCNT_WIDTH ((uint32_t)0x00000020) + +#define BLE_TXPKTCNT_RST 0x0 + +__INLINE uint32_t ble_rftesttxstat_txpktcnt_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTTXSTAT_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief RFTESTRXSTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00             RXPKTCNT   0x0
+ * 
+ */ +#define BLE_RFTESTRXSTAT_ADDR BASEBAND_REG_BASE +0xD8 // 0x508000D8 +#define BLE_RFTESTRXSTAT_OFFSET 0x000000D8 +#define BLE_RFTESTRXSTAT_INDEX 0x00000036 +#define BLE_RFTESTRXSTAT_RESET 0x00000000 + +__INLINE uint32_t ble_rftestrxstat_get(void) +{ + return REG_BLE_RD(BLE_RFTESTRXSTAT_ADDR); +} + +// field definitions +#define BLE_RXPKTCNT_MASK ((uint32_t)0xFFFFFFFF) +#define BLE_RXPKTCNT_LSB 0 +#define BLE_RXPKTCNT_WIDTH ((uint32_t)0x00000020) + +#define BLE_RXPKTCNT_RST 0x0 + +__INLINE uint32_t ble_rftestrxstat_rxpktcnt_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RFTESTRXSTAT_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief TIMGENCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  25:16   PREFETCHABORT_TIME   0x1FE
+ *  08:00        PREFETCH_TIME   0x96
+ * 
+ */ +#define BLE_TIMGENCNTL_ADDR BASEBAND_REG_BASE +0xE0 // 0x508000E0 +#define BLE_TIMGENCNTL_OFFSET 0x000000E0 +#define BLE_TIMGENCNTL_INDEX 0x00000038 +#define BLE_TIMGENCNTL_RESET 0x01FE0096 + +__INLINE uint32_t ble_timgencntl_get(void) +{ + return REG_BLE_RD(BLE_TIMGENCNTL_ADDR); +} + +__INLINE void ble_timgencntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_TIMGENCNTL_ADDR, value); +} + +// field definitions +#define BLE_PREFETCHABORT_TIME_MASK ((uint32_t)0x03FF0000) +#define BLE_PREFETCHABORT_TIME_LSB 16 +#define BLE_PREFETCHABORT_TIME_WIDTH ((uint32_t)0x0000000A) +#define BLE_PREFETCH_TIME_MASK ((uint32_t)0x000001FF) +#define BLE_PREFETCH_TIME_LSB 0 +#define BLE_PREFETCH_TIME_WIDTH ((uint32_t)0x00000009) + +#define BLE_PREFETCHABORT_TIME_RST 0x1FE +#define BLE_PREFETCH_TIME_RST 0x96 + +__INLINE void ble_timgencntl_pack(uint16_t prefetchaborttime, uint16_t prefetchtime) +{ + ASSERT_ERR((((uint32_t)prefetchaborttime << 16) & ~((uint32_t)0x03FF0000)) == 0); + ASSERT_ERR((((uint32_t)prefetchtime << 0) & ~((uint32_t)0x000001FF)) == 0); + REG_BLE_WR(BLE_TIMGENCNTL_ADDR, ((uint32_t)prefetchaborttime << 16) | ((uint32_t)prefetchtime << 0)); +} + +__INLINE void ble_timgencntl_unpack(uint16_t* prefetchaborttime, uint16_t* prefetchtime) +{ + uint32_t localVal = REG_BLE_RD(BLE_TIMGENCNTL_ADDR); + + *prefetchaborttime = (localVal & ((uint32_t)0x03FF0000)) >> 16; + *prefetchtime = (localVal & ((uint32_t)0x000001FF)) >> 0; +} + +__INLINE uint16_t ble_timgencntl_prefetchabort_time_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_TIMGENCNTL_ADDR); + return ((localVal & ((uint32_t)0x03FF0000)) >> 16); +} + +__INLINE void ble_timgencntl_prefetchabort_time_setf(uint16_t prefetchaborttime) +{ + ASSERT_ERR((((uint32_t)prefetchaborttime << 16) & ~((uint32_t)0x03FF0000)) == 0); + REG_BLE_WR(BLE_TIMGENCNTL_ADDR, (REG_BLE_RD(BLE_TIMGENCNTL_ADDR) & ~((uint32_t)0x03FF0000)) | ((uint32_t)prefetchaborttime << 16)); +} + +__INLINE uint16_t ble_timgencntl_prefetch_time_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_TIMGENCNTL_ADDR); + return ((localVal & ((uint32_t)0x000001FF)) >> 0); +} + +__INLINE void ble_timgencntl_prefetch_time_setf(uint16_t prefetchtime) +{ + ASSERT_ERR((((uint32_t)prefetchtime << 0) & ~((uint32_t)0x000001FF)) == 0); + REG_BLE_WR(BLE_TIMGENCNTL_ADDR, (REG_BLE_RD(BLE_TIMGENCNTL_ADDR) & ~((uint32_t)0x000001FF)) | ((uint32_t)prefetchtime << 0)); +} + +/** + * @brief FINETIMTGT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  27:00           FINETARGET   0x0
+ * 
+ */ +#define BLE_FINETIMTGT_ADDR BASEBAND_REG_BASE +0xE4 //0x508000E4 +#define BLE_FINETIMTGT_OFFSET 0x000000E4 +#define BLE_FINETIMTGT_INDEX 0x00000039 +#define BLE_FINETIMTGT_RESET 0x00000000 + +__INLINE uint32_t ble_finetimtgt_get(void) +{ + return REG_BLE_RD(BLE_FINETIMTGT_ADDR); +} + +__INLINE void ble_finetimtgt_set(uint32_t value) +{ + REG_BLE_WR(BLE_FINETIMTGT_ADDR, value); +} + +// field definitions +#define BLE_FINETARGET_MASK ((uint32_t)0x0FFFFFFF) +#define BLE_FINETARGET_LSB 0 +#define BLE_FINETARGET_WIDTH ((uint32_t)0x0000001C) + +#define BLE_FINETARGET_RST 0x0 + +__INLINE uint32_t ble_finetimtgt_finetarget_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_FINETIMTGT_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x0FFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_finetimtgt_finetarget_setf(uint32_t finetarget) +{ + ASSERT_ERR((((uint32_t)finetarget << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_BLE_WR(BLE_FINETIMTGT_ADDR, (uint32_t)finetarget << 0); +} + +/** + * @brief CLKNTGT1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  27:00             CLKNTGT1   0x0
+ * 
+ */ +#define BLE_CLKNTGT1_ADDR BASEBAND_REG_BASE +0xE8 //0x508000E8 +#define BLE_CLKNTGT1_OFFSET 0x000000E8 +#define BLE_CLKNTGT1_INDEX 0x0000003A +#define BLE_CLKNTGT1_RESET 0x00000000 + +__INLINE uint32_t ble_clkntgt1_get(void) +{ + return REG_BLE_RD(BLE_CLKNTGT1_ADDR); +} + +__INLINE void ble_clkntgt1_set(uint32_t value) +{ + REG_BLE_WR(BLE_CLKNTGT1_ADDR, value); +} + +// field definitions +#define BLE_CLKNTGT1_MASK ((uint32_t)0x0FFFFFFF) +#define BLE_CLKNTGT1_LSB 0 +#define BLE_CLKNTGT1_WIDTH ((uint32_t)0x0000001C) + +#define BLE_CLKNTGT1_RST 0x0 + +__INLINE uint32_t ble_clkntgt1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_CLKNTGT1_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x0FFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_clkntgt1_setf(uint32_t clkntgt1) +{ + ASSERT_ERR((((uint32_t)clkntgt1 << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_BLE_WR(BLE_CLKNTGT1_ADDR, (uint32_t)clkntgt1 << 0); +} + +/** + * @brief HMICROSECTGT1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00        HMICROSECTGT1   0x0
+ * 
+ */ +#define BLE_HMICROSECTGT1_ADDR BASEBAND_REG_BASE +0xEC //0x508000EC +#define BLE_HMICROSECTGT1_OFFSET 0x000000EC +#define BLE_HMICROSECTGT1_INDEX 0x0000003B +#define BLE_HMICROSECTGT1_RESET 0x00000000 + +__INLINE uint32_t ble_hmicrosectgt1_get(void) +{ + return REG_BLE_RD(BLE_HMICROSECTGT1_ADDR); +} + +__INLINE void ble_hmicrosectgt1_set(uint32_t value) +{ + REG_BLE_WR(BLE_HMICROSECTGT1_ADDR, value); +} + +// field definitions +#define BLE_HMICROSECTGT1_MASK ((uint32_t)0x000003FF) +#define BLE_HMICROSECTGT1_LSB 0 +#define BLE_HMICROSECTGT1_WIDTH ((uint32_t)0x0000000A) + +#define BLE_HMICROSECTGT1_RST 0x0 + +__INLINE uint16_t ble_hmicrosectgt1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_HMICROSECTGT1_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_hmicrosectgt1_setf(uint16_t hmicrosectgt1) +{ + ASSERT_ERR((((uint32_t)hmicrosectgt1 << 0) & ~((uint32_t)0x000003FF)) == 0); + REG_BLE_WR(BLE_HMICROSECTGT1_ADDR, (uint32_t)hmicrosectgt1 << 0); +} + +/** + * @brief CLKNTGT2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  27:00             CLKNTGT2   0x0
+ * 
+ */ +#define BLE_CLKNTGT2_ADDR BASEBAND_REG_BASE +0xF0 //0x508000F0 +#define BLE_CLKNTGT2_OFFSET 0x000000F0 +#define BLE_CLKNTGT2_INDEX 0x0000003C +#define BLE_CLKNTGT2_RESET 0x00000000 + +__INLINE uint32_t ble_clkntgt2_get(void) +{ + return REG_BLE_RD(BLE_CLKNTGT2_ADDR); +} + +__INLINE void ble_clkntgt2_set(uint32_t value) +{ + REG_BLE_WR(BLE_CLKNTGT2_ADDR, value); +} + +// field definitions +#define BLE_CLKNTGT2_MASK ((uint32_t)0x0FFFFFFF) +#define BLE_CLKNTGT2_LSB 0 +#define BLE_CLKNTGT2_WIDTH ((uint32_t)0x0000001C) + +#define BLE_CLKNTGT2_RST 0x0 + +__INLINE uint32_t ble_clkntgt2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_CLKNTGT2_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x0FFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_clkntgt2_setf(uint32_t clkntgt2) +{ + ASSERT_ERR((((uint32_t)clkntgt2 << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_BLE_WR(BLE_CLKNTGT2_ADDR, (uint32_t)clkntgt2 << 0); +} + +/** + * @brief HMICROSECTGT2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00        HMICROSECTGT2   0x0
+ * 
+ */ +#define BLE_HMICROSECTGT2_ADDR BASEBAND_REG_BASE +0xF4 //0x508000F4 +#define BLE_HMICROSECTGT2_OFFSET 0x000000F4 +#define BLE_HMICROSECTGT2_INDEX 0x0000003D +#define BLE_HMICROSECTGT2_RESET 0x00000000 + +__INLINE uint32_t ble_hmicrosectgt2_get(void) +{ + return REG_BLE_RD(BLE_HMICROSECTGT2_ADDR); +} + +__INLINE void ble_hmicrosectgt2_set(uint32_t value) +{ + REG_BLE_WR(BLE_HMICROSECTGT2_ADDR, value); +} + +// field definitions +#define BLE_HMICROSECTGT2_MASK ((uint32_t)0x000003FF) +#define BLE_HMICROSECTGT2_LSB 0 +#define BLE_HMICROSECTGT2_WIDTH ((uint32_t)0x0000000A) + +#define BLE_HMICROSECTGT2_RST 0x0 + +__INLINE uint16_t ble_hmicrosectgt2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_HMICROSECTGT2_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_hmicrosectgt2_setf(uint16_t hmicrosectgt2) +{ + ASSERT_ERR((((uint32_t)hmicrosectgt2 << 0) & ~((uint32_t)0x000003FF)) == 0); + REG_BLE_WR(BLE_HMICROSECTGT2_ADDR, (uint32_t)hmicrosectgt2 << 0); +} + +/** + * @brief SLOTCLK register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31                 SAMP   0
+ *     30             CLKN_UPD   0
+ *  27:00                 SCLK   0x0
+ * 
+ */ +#define BLE_SLOTCLK_ADDR BASEBAND_REG_BASE +0xF8 // 0x508000F8 +#define BLE_SLOTCLK_OFFSET 0x000000F8 +#define BLE_SLOTCLK_INDEX 0x0000003E +#define BLE_SLOTCLK_RESET 0x00000000 + +__INLINE uint32_t ble_slotclk_get(void) +{ + return REG_BLE_RD(BLE_SLOTCLK_ADDR); +} + +__INLINE void ble_slotclk_set(uint32_t value) +{ + REG_BLE_WR(BLE_SLOTCLK_ADDR, value); +} + +// field definitions +#define BLE_SAMP_BIT ((uint32_t)0x80000000) +#define BLE_SAMP_POS 31 +#define BLE_CLKN_UPD_BIT ((uint32_t)0x40000000) +#define BLE_CLKN_UPD_POS 30 +#define BLE_SCLK_MASK ((uint32_t)0x0FFFFFFF) +#define BLE_SCLK_LSB 0 +#define BLE_SCLK_WIDTH ((uint32_t)0x0000001C) + +#define BLE_SAMP_RST 0x0 +#define BLE_CLKN_UPD_RST 0x0 +#define BLE_SCLK_RST 0x0 + +__INLINE void ble_slotclk_pack(uint8_t samp, uint8_t clknupd, uint32_t sclk) +{ + ASSERT_ERR((((uint32_t)samp << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)clknupd << 30) & ~((uint32_t)0x40000000)) == 0); + ASSERT_ERR((((uint32_t)sclk << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_BLE_WR(BLE_SLOTCLK_ADDR, ((uint32_t)samp << 31) | ((uint32_t)clknupd << 30) | ((uint32_t)sclk << 0)); +} + +__INLINE void ble_slotclk_unpack(uint8_t* samp, uint8_t* clknupd, uint32_t* sclk) +{ + uint32_t localVal = REG_BLE_RD(BLE_SLOTCLK_ADDR); + + *samp = (localVal & ((uint32_t)0x80000000)) >> 31; + *clknupd = (localVal & ((uint32_t)0x40000000)) >> 30; + *sclk = (localVal & ((uint32_t)0x0FFFFFFF)) >> 0; +} + +__INLINE uint8_t ble_slotclk_samp_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SLOTCLK_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_slotclk_samp_setf(uint8_t samp) +{ + ASSERT_ERR((((uint32_t)samp << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_SLOTCLK_ADDR, (REG_BLE_RD(BLE_SLOTCLK_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)samp << 31)); +} + +__INLINE uint8_t ble_slotclk_clkn_upd_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SLOTCLK_ADDR); + return ((localVal & ((uint32_t)0x40000000)) >> 30); +} + +__INLINE void ble_slotclk_clkn_upd_setf(uint8_t clknupd) +{ + ASSERT_ERR((((uint32_t)clknupd << 30) & ~((uint32_t)0x40000000)) == 0); + REG_BLE_WR(BLE_SLOTCLK_ADDR, (REG_BLE_RD(BLE_SLOTCLK_ADDR) & ~((uint32_t)0x40000000)) | ((uint32_t)clknupd << 30)); +} + +__INLINE uint32_t ble_slotclk_sclk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SLOTCLK_ADDR); + return ((localVal & ((uint32_t)0x0FFFFFFF)) >> 0); +} + +__INLINE void ble_slotclk_sclk_setf(uint32_t sclk) +{ + ASSERT_ERR((((uint32_t)sclk << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_BLE_WR(BLE_SLOTCLK_ADDR, (REG_BLE_RD(BLE_SLOTCLK_ADDR) & ~((uint32_t)0x0FFFFFFF)) | ((uint32_t)sclk << 0)); +} + +/** + * @brief FINETIMECNT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00              FINECNT   0x0
+ * 
+ */ +#define BLE_FINETIMECNT_ADDR BASEBAND_REG_BASE +0xFC // 0x508000FC +#define BLE_FINETIMECNT_OFFSET 0x000000FC +#define BLE_FINETIMECNT_INDEX 0x0000003F +#define BLE_FINETIMECNT_RESET 0x00000000 + +__INLINE uint32_t ble_finetimecnt_get(void) +{ + return REG_BLE_RD(BLE_FINETIMECNT_ADDR); +} + +// field definitions +#define BLE_FINECNT_MASK ((uint32_t)0x000003FF) +#define BLE_FINECNT_LSB 0 +#define BLE_FINECNT_WIDTH ((uint32_t)0x0000000A) + +#define BLE_FINECNT_RST 0x0 + +__INLINE uint16_t ble_finetimecnt_finecnt_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_FINETIMECNT_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +/** + * @brief ACTSCHCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31            START_ACT   0
+ *  03:00            ENTRY_IDX   0x0
+ * 
+ */ +#define BLE_ACTSCHCNTL_ADDR BASEBAND_REG_BASE +0x100 // 0x50800100 +#define BLE_ACTSCHCNTL_OFFSET 0x00000100 +#define BLE_ACTSCHCNTL_INDEX 0x00000040 +#define BLE_ACTSCHCNTL_RESET 0x00000000 + +__INLINE uint32_t ble_actschcntl_get(void) +{ + return REG_BLE_RD(BLE_ACTSCHCNTL_ADDR); +} + +__INLINE void ble_actschcntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_ACTSCHCNTL_ADDR, value); +} + +// field definitions +#define BLE_START_ACT_BIT ((uint32_t)0x80000000) +#define BLE_START_ACT_POS 31 +#define BLE_ENTRY_IDX_MASK ((uint32_t)0x0000000F) +#define BLE_ENTRY_IDX_LSB 0 +#define BLE_ENTRY_IDX_WIDTH ((uint32_t)0x00000004) + +#define BLE_START_ACT_RST 0x0 +#define BLE_ENTRY_IDX_RST 0x0 + +__INLINE void ble_actschcntl_pack(uint8_t startact, uint8_t entryidx) +{ + ASSERT_ERR((((uint32_t)startact << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)entryidx << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_ACTSCHCNTL_ADDR, ((uint32_t)startact << 31) | ((uint32_t)entryidx << 0)); +} + +__INLINE void ble_actschcntl_unpack(uint8_t* startact, uint8_t* entryidx) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTSCHCNTL_ADDR); + + *startact = (localVal & ((uint32_t)0x80000000)) >> 31; + *entryidx = (localVal & ((uint32_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t ble_actschcntl_start_act_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTSCHCNTL_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_actschcntl_start_act_setf(uint8_t startact) +{ + ASSERT_ERR((((uint32_t)startact << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_ACTSCHCNTL_ADDR, (REG_BLE_RD(BLE_ACTSCHCNTL_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)startact << 31)); +} + +__INLINE uint8_t ble_actschcntl_entry_idx_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTSCHCNTL_ADDR); + return ((localVal & ((uint32_t)0x0000000F)) >> 0); +} + +__INLINE void ble_actschcntl_entry_idx_setf(uint8_t entryidx) +{ + ASSERT_ERR((((uint32_t)entryidx << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_ACTSCHCNTL_ADDR, (REG_BLE_RD(BLE_ACTSCHCNTL_ADDR) & ~((uint32_t)0x0000000F)) | ((uint32_t)entryidx << 0)); +} + +/** + * @brief STARTEVTCLKNTS register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  27:00       STARTEVTCLKNTS   0x0
+ * 
+ */ +#define BLE_STARTEVTCLKNTS_ADDR BASEBAND_REG_BASE +0x104 // 0x50800104 +#define BLE_STARTEVTCLKNTS_OFFSET 0x00000104 +#define BLE_STARTEVTCLKNTS_INDEX 0x00000041 +#define BLE_STARTEVTCLKNTS_RESET 0x00000000 + +__INLINE uint32_t ble_startevtclknts_get(void) +{ + return REG_BLE_RD(BLE_STARTEVTCLKNTS_ADDR); +} + +// field definitions +#define BLE_STARTEVTCLKNTS_MASK ((uint32_t)0x0FFFFFFF) +#define BLE_STARTEVTCLKNTS_LSB 0 +#define BLE_STARTEVTCLKNTS_WIDTH ((uint32_t)0x0000001C) + +#define BLE_STARTEVTCLKNTS_RST 0x0 + +__INLINE uint32_t ble_startevtclknts_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_STARTEVTCLKNTS_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x0FFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief STARTEVTFINECNTTS register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00    STARTEVTFINECNTTS   0x0
+ * 
+ */ +#define BLE_STARTEVTFINECNTTS_ADDR BASEBAND_REG_BASE +0x108 // 0x50800108 +#define BLE_STARTEVTFINECNTTS_OFFSET 0x00000108 +#define BLE_STARTEVTFINECNTTS_INDEX 0x00000042 +#define BLE_STARTEVTFINECNTTS_RESET 0x00000000 + +__INLINE uint32_t ble_startevtfinecntts_get(void) +{ + return REG_BLE_RD(BLE_STARTEVTFINECNTTS_ADDR); +} + +// field definitions +#define BLE_STARTEVTFINECNTTS_MASK ((uint32_t)0x000003FF) +#define BLE_STARTEVTFINECNTTS_LSB 0 +#define BLE_STARTEVTFINECNTTS_WIDTH ((uint32_t)0x0000000A) + +#define BLE_STARTEVTFINECNTTS_RST 0x0 + +__INLINE uint16_t ble_startevtfinecntts_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_STARTEVTFINECNTTS_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +/** + * @brief ENDEVTCLKNTS register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  27:00         ENDEVTCLKNTS   0x0
+ * 
+ */ +#define BLE_ENDEVTCLKNTS_ADDR BASEBAND_REG_BASE +0x10C //0x5080010C +#define BLE_ENDEVTCLKNTS_OFFSET 0x0000010C +#define BLE_ENDEVTCLKNTS_INDEX 0x00000043 +#define BLE_ENDEVTCLKNTS_RESET 0x00000000 + +__INLINE uint32_t ble_endevtclknts_get(void) +{ + return REG_BLE_RD(BLE_ENDEVTCLKNTS_ADDR); +} + +// field definitions +#define BLE_ENDEVTCLKNTS_MASK ((uint32_t)0x0FFFFFFF) +#define BLE_ENDEVTCLKNTS_LSB 0 +#define BLE_ENDEVTCLKNTS_WIDTH ((uint32_t)0x0000001C) + +#define BLE_ENDEVTCLKNTS_RST 0x0 + +__INLINE uint32_t ble_endevtclknts_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ENDEVTCLKNTS_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x0FFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief ENDEVTFINECNTTS register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00      ENDEVTFINECNTTS   0x0
+ * 
+ */ +#define BLE_ENDEVTFINECNTTS_ADDR BASEBAND_REG_BASE +0x110 //0x50800110 +#define BLE_ENDEVTFINECNTTS_OFFSET 0x00000110 +#define BLE_ENDEVTFINECNTTS_INDEX 0x00000044 +#define BLE_ENDEVTFINECNTTS_RESET 0x00000000 + +__INLINE uint32_t ble_endevtfinecntts_get(void) +{ + return REG_BLE_RD(BLE_ENDEVTFINECNTTS_ADDR); +} + +// field definitions +#define BLE_ENDEVTFINECNTTS_MASK ((uint32_t)0x000003FF) +#define BLE_ENDEVTFINECNTTS_LSB 0 +#define BLE_ENDEVTFINECNTTS_WIDTH ((uint32_t)0x0000000A) + +#define BLE_ENDEVTFINECNTTS_RST 0x0 + +__INLINE uint16_t ble_endevtfinecntts_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ENDEVTFINECNTTS_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +/** + * @brief SKIPEVTCLKNTS register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  27:00        SKIPEVTCLKNTS   0x0
+ * 
+ */ +#define BLE_SKIPEVTCLKNTS_ADDR BASEBAND_REG_BASE +0x114 // 0x50800114 +#define BLE_SKIPEVTCLKNTS_OFFSET 0x00000114 +#define BLE_SKIPEVTCLKNTS_INDEX 0x00000045 +#define BLE_SKIPEVTCLKNTS_RESET 0x00000000 + +__INLINE uint32_t ble_skipevtclknts_get(void) +{ + return REG_BLE_RD(BLE_SKIPEVTCLKNTS_ADDR); +} + +// field definitions +#define BLE_SKIPEVTCLKNTS_MASK ((uint32_t)0x0FFFFFFF) +#define BLE_SKIPEVTCLKNTS_LSB 0 +#define BLE_SKIPEVTCLKNTS_WIDTH ((uint32_t)0x0000001C) + +#define BLE_SKIPEVTCLKNTS_RST 0x0 + +__INLINE uint32_t ble_skipevtclknts_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SKIPEVTCLKNTS_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x0FFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief SKIPEVTFINECNTTS register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00     SKIPEVTFINECNTTS   0x0
+ * 
+ */ +#define BLE_SKIPEVTFINECNTTS_ADDR BASEBAND_REG_BASE +0x118 // 0x50800118 +#define BLE_SKIPEVTFINECNTTS_OFFSET 0x00000118 +#define BLE_SKIPEVTFINECNTTS_INDEX 0x00000046 +#define BLE_SKIPEVTFINECNTTS_RESET 0x00000000 + +__INLINE uint32_t ble_skipevtfinecntts_get(void) +{ + return REG_BLE_RD(BLE_SKIPEVTFINECNTTS_ADDR); +} + +// field definitions +#define BLE_SKIPEVTFINECNTTS_MASK ((uint32_t)0x000003FF) +#define BLE_SKIPEVTFINECNTTS_LSB 0 +#define BLE_SKIPEVTFINECNTTS_WIDTH ((uint32_t)0x0000000A) + +#define BLE_SKIPEVTFINECNTTS_RST 0x0 + +__INLINE uint16_t ble_skipevtfinecntts_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SKIPEVTFINECNTTS_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +/** + * @brief ADVTIM register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24        TX_AUXPTR_THR   0x0
+ *  23:16        RX_AUXPTR_THR   0x0
+ *  13:00               ADVINT   0x0
+ * 
+ */ +#define BLE_ADVTIM_ADDR BASEBAND_REG_BASE +0x120 // 0x50800120 +#define BLE_ADVTIM_OFFSET 0x00000120 +#define BLE_ADVTIM_INDEX 0x00000048 +#define BLE_ADVTIM_RESET 0x00000000 + +__INLINE uint32_t ble_advtim_get(void) +{ + return REG_BLE_RD(BLE_ADVTIM_ADDR); +} + +__INLINE void ble_advtim_set(uint32_t value) +{ + REG_BLE_WR(BLE_ADVTIM_ADDR, value); +} + +// field definitions +#define BLE_TX_AUXPTR_THR_MASK ((uint32_t)0xFF000000) +#define BLE_TX_AUXPTR_THR_LSB 24 +#define BLE_TX_AUXPTR_THR_WIDTH ((uint32_t)0x00000008) +#define BLE_RX_AUXPTR_THR_MASK ((uint32_t)0x00FF0000) +#define BLE_RX_AUXPTR_THR_LSB 16 +#define BLE_RX_AUXPTR_THR_WIDTH ((uint32_t)0x00000008) +#define BLE_ADVINT_MASK ((uint32_t)0x00003FFF) +#define BLE_ADVINT_LSB 0 +#define BLE_ADVINT_WIDTH ((uint32_t)0x0000000E) + +#define BLE_TX_AUXPTR_THR_RST 0x0 +#define BLE_RX_AUXPTR_THR_RST 0x0 +#define BLE_ADVINT_RST 0x0 + +__INLINE void ble_advtim_pack(uint8_t txauxptrthr, uint8_t rxauxptrthr, uint16_t advint) +{ + ASSERT_ERR((((uint32_t)txauxptrthr << 24) & ~((uint32_t)0xFF000000)) == 0); + ASSERT_ERR((((uint32_t)rxauxptrthr << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)advint << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_ADVTIM_ADDR, ((uint32_t)txauxptrthr << 24) | ((uint32_t)rxauxptrthr << 16) | ((uint32_t)advint << 0)); +} + +__INLINE void ble_advtim_unpack(uint8_t* txauxptrthr, uint8_t* rxauxptrthr, uint16_t* advint) +{ + uint32_t localVal = REG_BLE_RD(BLE_ADVTIM_ADDR); + + *txauxptrthr = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rxauxptrthr = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *advint = (localVal & ((uint32_t)0x00003FFF)) >> 0; +} + +__INLINE uint8_t ble_advtim_tx_auxptr_thr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ADVTIM_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE void ble_advtim_tx_auxptr_thr_setf(uint8_t txauxptrthr) +{ + ASSERT_ERR((((uint32_t)txauxptrthr << 24) & ~((uint32_t)0xFF000000)) == 0); + REG_BLE_WR(BLE_ADVTIM_ADDR, (REG_BLE_RD(BLE_ADVTIM_ADDR) & ~((uint32_t)0xFF000000)) | ((uint32_t)txauxptrthr << 24)); +} + +__INLINE uint8_t ble_advtim_rx_auxptr_thr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ADVTIM_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_advtim_rx_auxptr_thr_setf(uint8_t rxauxptrthr) +{ + ASSERT_ERR((((uint32_t)rxauxptrthr << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_ADVTIM_ADDR, (REG_BLE_RD(BLE_ADVTIM_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)rxauxptrthr << 16)); +} + +__INLINE uint16_t ble_advtim_advint_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ADVTIM_ADDR); + return ((localVal & ((uint32_t)0x00003FFF)) >> 0); +} + +__INLINE void ble_advtim_advint_setf(uint16_t advint) +{ + ASSERT_ERR((((uint32_t)advint << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_ADVTIM_ADDR, (REG_BLE_RD(BLE_ADVTIM_ADDR) & ~((uint32_t)0x00003FFF)) | ((uint32_t)advint << 0)); +} + +/** + * @brief ACTSCANCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  24:16              BACKOFF   0x1
+ *  08:00           UPPERLIMIT   0x1
+ * 
+ */ +#define BLE_ACTSCANCNTL_ADDR BASEBAND_REG_BASE +0x124 // 0x50800124 +#define BLE_ACTSCANCNTL_OFFSET 0x00000124 +#define BLE_ACTSCANCNTL_INDEX 0x00000049 +#define BLE_ACTSCANCNTL_RESET 0x00010001 + +__INLINE uint32_t ble_actscancntl_get(void) +{ + return REG_BLE_RD(BLE_ACTSCANCNTL_ADDR); +} + +__INLINE void ble_actscancntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_ACTSCANCNTL_ADDR, value); +} + +// field definitions +#define BLE_BACKOFF_MASK ((uint32_t)0x01FF0000) +#define BLE_BACKOFF_LSB 16 +#define BLE_BACKOFF_WIDTH ((uint32_t)0x00000009) +#define BLE_UPPERLIMIT_MASK ((uint32_t)0x000001FF) +#define BLE_UPPERLIMIT_LSB 0 +#define BLE_UPPERLIMIT_WIDTH ((uint32_t)0x00000009) + +#define BLE_BACKOFF_RST 0x1 +#define BLE_UPPERLIMIT_RST 0x1 + +__INLINE void ble_actscancntl_pack(uint16_t backoff, uint16_t upperlimit) +{ + ASSERT_ERR((((uint32_t)backoff << 16) & ~((uint32_t)0x01FF0000)) == 0); + ASSERT_ERR((((uint32_t)upperlimit << 0) & ~((uint32_t)0x000001FF)) == 0); + REG_BLE_WR(BLE_ACTSCANCNTL_ADDR, ((uint32_t)backoff << 16) | ((uint32_t)upperlimit << 0)); +} + +__INLINE void ble_actscancntl_unpack(uint16_t* backoff, uint16_t* upperlimit) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTSCANCNTL_ADDR); + + *backoff = (localVal & ((uint32_t)0x01FF0000)) >> 16; + *upperlimit = (localVal & ((uint32_t)0x000001FF)) >> 0; +} + +__INLINE uint16_t ble_actscancntl_backoff_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTSCANCNTL_ADDR); + return ((localVal & ((uint32_t)0x01FF0000)) >> 16); +} + +__INLINE void ble_actscancntl_backoff_setf(uint16_t backoff) +{ + ASSERT_ERR((((uint32_t)backoff << 16) & ~((uint32_t)0x01FF0000)) == 0); + REG_BLE_WR(BLE_ACTSCANCNTL_ADDR, (REG_BLE_RD(BLE_ACTSCANCNTL_ADDR) & ~((uint32_t)0x01FF0000)) | ((uint32_t)backoff << 16)); +} + +__INLINE uint16_t ble_actscancntl_upperlimit_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_ACTSCANCNTL_ADDR); + return ((localVal & ((uint32_t)0x000001FF)) >> 0); +} + +__INLINE void ble_actscancntl_upperlimit_setf(uint16_t upperlimit) +{ + ASSERT_ERR((((uint32_t)upperlimit << 0) & ~((uint32_t)0x000001FF)) == 0); + REG_BLE_WR(BLE_ACTSCANCNTL_ADDR, (REG_BLE_RD(BLE_ACTSCANCNTL_ADDR) & ~((uint32_t)0x000001FF)) | ((uint32_t)upperlimit << 0)); +} + +/** + * @brief WPALCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  23:16            WPALNBDEV   0x0
+ *  13:00          WPALBASEPTR   0x0
+ * 
+ */ +#define BLE_WPALCNTL_ADDR BASEBAND_REG_BASE +0x130 // 0x50800130 +#define BLE_WPALCNTL_OFFSET 0x00000130 +#define BLE_WPALCNTL_INDEX 0x0000004C +#define BLE_WPALCNTL_RESET 0x00000000 + +__INLINE uint32_t ble_wpalcntl_get(void) +{ + return REG_BLE_RD(BLE_WPALCNTL_ADDR); +} + +__INLINE void ble_wpalcntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_WPALCNTL_ADDR, value); +} + +// field definitions +#define BLE_WPALNBDEV_MASK ((uint32_t)0x00FF0000) +#define BLE_WPALNBDEV_LSB 16 +#define BLE_WPALNBDEV_WIDTH ((uint32_t)0x00000008) +#define BLE_WPALBASEPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_WPALBASEPTR_LSB 0 +#define BLE_WPALBASEPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_WPALNBDEV_RST 0x0 +#define BLE_WPALBASEPTR_RST 0x0 + +__INLINE void ble_wpalcntl_pack(uint8_t wpalnbdev, uint16_t wpalbaseptr) +{ + ASSERT_ERR((((uint32_t)wpalnbdev << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)wpalbaseptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_WPALCNTL_ADDR, ((uint32_t)wpalnbdev << 16) | ((uint32_t)wpalbaseptr << 0)); +} + +__INLINE void ble_wpalcntl_unpack(uint8_t* wpalnbdev, uint16_t* wpalbaseptr) +{ + uint32_t localVal = REG_BLE_RD(BLE_WPALCNTL_ADDR); + + *wpalnbdev = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *wpalbaseptr = (localVal & ((uint32_t)0x00003FFF)) >> 0; +} + +__INLINE uint8_t ble_wpalcntl_wpalnbdev_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_WPALCNTL_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_wpalcntl_wpalnbdev_setf(uint8_t wpalnbdev) +{ + ASSERT_ERR((((uint32_t)wpalnbdev << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_WPALCNTL_ADDR, (REG_BLE_RD(BLE_WPALCNTL_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)wpalnbdev << 16)); +} + +__INLINE uint16_t ble_wpalcntl_wpalbaseptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_WPALCNTL_ADDR); + return ((localVal & ((uint32_t)0x00003FFF)) >> 0); +} + +__INLINE void ble_wpalcntl_wpalbaseptr_setf(uint16_t wpalbaseptr) +{ + ASSERT_ERR((((uint32_t)wpalbaseptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_WPALCNTL_ADDR, (REG_BLE_RD(BLE_WPALCNTL_ADDR) & ~((uint32_t)0x00003FFF)) | ((uint32_t)wpalbaseptr << 0)); +} + +/** + * @brief WPALCURRENTPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00       WPALCURRENTPTR   0x0
+ * 
+ */ +#define BLE_WPALCURRENTPTR_ADDR BASEBAND_REG_BASE +0x134 // 0x50800134 +#define BLE_WPALCURRENTPTR_OFFSET 0x00000134 +#define BLE_WPALCURRENTPTR_INDEX 0x0000004D +#define BLE_WPALCURRENTPTR_RESET 0x00000000 + +__INLINE uint32_t ble_wpalcurrentptr_get(void) +{ + return REG_BLE_RD(BLE_WPALCURRENTPTR_ADDR); +} + +__INLINE void ble_wpalcurrentptr_set(uint32_t value) +{ + REG_BLE_WR(BLE_WPALCURRENTPTR_ADDR, value); +} + +// field definitions +#define BLE_WPALCURRENTPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_WPALCURRENTPTR_LSB 0 +#define BLE_WPALCURRENTPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_WPALCURRENTPTR_RST 0x0 + +__INLINE uint16_t ble_wpalcurrentptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_WPALCURRENTPTR_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_wpalcurrentptr_setf(uint16_t wpalcurrentptr) +{ + ASSERT_ERR((((uint32_t)wpalcurrentptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_WPALCURRENTPTR_ADDR, (uint32_t)wpalcurrentptr << 0); +} + +/** + * @brief SEARCH_TIMEOUT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  05:00       SEARCH_TIMEOUT   0x10
+ * 
+ */ +#define BLE_SEARCH_TIMEOUT_ADDR BASEBAND_REG_BASE +0x138 //0x50800138 +#define BLE_SEARCH_TIMEOUT_OFFSET 0x00000138 +#define BLE_SEARCH_TIMEOUT_INDEX 0x0000004E +#define BLE_SEARCH_TIMEOUT_RESET 0x00000010 + +__INLINE uint32_t ble_search_timeout_get(void) +{ + return REG_BLE_RD(BLE_SEARCH_TIMEOUT_ADDR); +} + +__INLINE void ble_search_timeout_set(uint32_t value) +{ + REG_BLE_WR(BLE_SEARCH_TIMEOUT_ADDR, value); +} + +// field definitions +#define BLE_SEARCH_TIMEOUT_MASK ((uint32_t)0x0000003F) +#define BLE_SEARCH_TIMEOUT_LSB 0 +#define BLE_SEARCH_TIMEOUT_WIDTH ((uint32_t)0x00000006) + +#define BLE_SEARCH_TIMEOUT_RST 0x10 + +__INLINE uint8_t ble_search_timeout_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_SEARCH_TIMEOUT_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x0000003F)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_search_timeout_setf(uint8_t searchtimeout) +{ + ASSERT_ERR((((uint32_t)searchtimeout << 0) & ~((uint32_t)0x0000003F)) == 0); + REG_BLE_WR(BLE_SEARCH_TIMEOUT_ADDR, (uint32_t)searchtimeout << 0); +} + +/** + * @brief COEXIFCNTL0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  21:20       MWSSCANFREQMSK   0x0
+ *  19:18        WLCRXPRIOMODE   0x0
+ *  17:16        WLCTXPRIOMODE   0x0
+ *  15:14          MWSTXFRQMSK   0x0
+ *  13:12          MWSRXFRQMSK   0x0
+ *  11:10             MWSTXMSK   0x0
+ *  09:08             MWSRXMSK   0x0
+ *  07:06            WLANTXMSK   0x0
+ *  05:04            WLANRXMSK   0x1
+ *     03            MWSWCI_EN   0
+ *     02           MWSCOEX_EN   0
+ *     01           SYNCGEN_EN   0
+ *     00          WLANCOEX_EN   0
+ * 
+ */ +#define BLE_COEXIFCNTL0_ADDR BASEBAND_REG_BASE +0x140 // 0x50800140 +#define BLE_COEXIFCNTL0_OFFSET 0x00000140 +#define BLE_COEXIFCNTL0_INDEX 0x00000050 +#define BLE_COEXIFCNTL0_RESET 0x00000010 + +__INLINE uint32_t ble_coexifcntl0_get(void) +{ + return REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); +} + +__INLINE void ble_coexifcntl0_set(uint32_t value) +{ + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, value); +} + +// field definitions +#define BLE_MWSSCANFREQMSK_MASK ((uint32_t)0x00300000) +#define BLE_MWSSCANFREQMSK_LSB 20 +#define BLE_MWSSCANFREQMSK_WIDTH ((uint32_t)0x00000002) +#define BLE_WLCRXPRIOMODE_MASK ((uint32_t)0x000C0000) +#define BLE_WLCRXPRIOMODE_LSB 18 +#define BLE_WLCRXPRIOMODE_WIDTH ((uint32_t)0x00000002) +#define BLE_WLCTXPRIOMODE_MASK ((uint32_t)0x00030000) +#define BLE_WLCTXPRIOMODE_LSB 16 +#define BLE_WLCTXPRIOMODE_WIDTH ((uint32_t)0x00000002) +#define BLE_MWSTXFRQMSK_MASK ((uint32_t)0x0000C000) +#define BLE_MWSTXFRQMSK_LSB 14 +#define BLE_MWSTXFRQMSK_WIDTH ((uint32_t)0x00000002) +#define BLE_MWSRXFRQMSK_MASK ((uint32_t)0x00003000) +#define BLE_MWSRXFRQMSK_LSB 12 +#define BLE_MWSRXFRQMSK_WIDTH ((uint32_t)0x00000002) +#define BLE_MWSTXMSK_MASK ((uint32_t)0x00000C00) +#define BLE_MWSTXMSK_LSB 10 +#define BLE_MWSTXMSK_WIDTH ((uint32_t)0x00000002) +#define BLE_MWSRXMSK_MASK ((uint32_t)0x00000300) +#define BLE_MWSRXMSK_LSB 8 +#define BLE_MWSRXMSK_WIDTH ((uint32_t)0x00000002) +#define BLE_WLANTXMSK_MASK ((uint32_t)0x000000C0) +#define BLE_WLANTXMSK_LSB 6 +#define BLE_WLANTXMSK_WIDTH ((uint32_t)0x00000002) +#define BLE_WLANRXMSK_MASK ((uint32_t)0x00000030) +#define BLE_WLANRXMSK_LSB 4 +#define BLE_WLANRXMSK_WIDTH ((uint32_t)0x00000002) +#define BLE_MWSWCI_EN_BIT ((uint32_t)0x00000008) +#define BLE_MWSWCI_EN_POS 3 +#define BLE_MWSCOEX_EN_BIT ((uint32_t)0x00000004) +#define BLE_MWSCOEX_EN_POS 2 +#define BLE_SYNCGEN_EN_BIT ((uint32_t)0x00000002) +#define BLE_SYNCGEN_EN_POS 1 +#define BLE_WLANCOEX_EN_BIT ((uint32_t)0x00000001) +#define BLE_WLANCOEX_EN_POS 0 + +#define BLE_MWSSCANFREQMSK_RST 0x0 +#define BLE_WLCRXPRIOMODE_RST 0x0 +#define BLE_WLCTXPRIOMODE_RST 0x0 +#define BLE_MWSTXFRQMSK_RST 0x0 +#define BLE_MWSRXFRQMSK_RST 0x0 +#define BLE_MWSTXMSK_RST 0x0 +#define BLE_MWSRXMSK_RST 0x0 +#define BLE_WLANTXMSK_RST 0x0 +#define BLE_WLANRXMSK_RST 0x1 +#define BLE_MWSWCI_EN_RST 0x0 +#define BLE_MWSCOEX_EN_RST 0x0 +#define BLE_SYNCGEN_EN_RST 0x0 +#define BLE_WLANCOEX_EN_RST 0x0 + +__INLINE void ble_coexifcntl0_pack(uint8_t mwsscanfreqmsk, uint8_t wlcrxpriomode, uint8_t wlctxpriomode, uint8_t mwstxfrqmsk, uint8_t mwsrxfrqmsk, uint8_t mwstxmsk, uint8_t mwsrxmsk, uint8_t wlantxmsk, uint8_t wlanrxmsk, uint8_t mwswcien, uint8_t mwscoexen, uint8_t syncgenen, uint8_t wlancoexen) +{ + ASSERT_ERR((((uint32_t)mwsscanfreqmsk << 20) & ~((uint32_t)0x00300000)) == 0); + ASSERT_ERR((((uint32_t)wlcrxpriomode << 18) & ~((uint32_t)0x000C0000)) == 0); + ASSERT_ERR((((uint32_t)wlctxpriomode << 16) & ~((uint32_t)0x00030000)) == 0); + ASSERT_ERR((((uint32_t)mwstxfrqmsk << 14) & ~((uint32_t)0x0000C000)) == 0); + ASSERT_ERR((((uint32_t)mwsrxfrqmsk << 12) & ~((uint32_t)0x00003000)) == 0); + ASSERT_ERR((((uint32_t)mwstxmsk << 10) & ~((uint32_t)0x00000C00)) == 0); + ASSERT_ERR((((uint32_t)mwsrxmsk << 8) & ~((uint32_t)0x00000300)) == 0); + ASSERT_ERR((((uint32_t)wlantxmsk << 6) & ~((uint32_t)0x000000C0)) == 0); + ASSERT_ERR((((uint32_t)wlanrxmsk << 4) & ~((uint32_t)0x00000030)) == 0); + ASSERT_ERR((((uint32_t)mwswcien << 3) & ~((uint32_t)0x00000008)) == 0); + ASSERT_ERR((((uint32_t)mwscoexen << 2) & ~((uint32_t)0x00000004)) == 0); + ASSERT_ERR((((uint32_t)syncgenen << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)wlancoexen << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, ((uint32_t)mwsscanfreqmsk << 20) | ((uint32_t)wlcrxpriomode << 18) | ((uint32_t)wlctxpriomode << 16) | ((uint32_t)mwstxfrqmsk << 14) | ((uint32_t)mwsrxfrqmsk << 12) | ((uint32_t)mwstxmsk << 10) | ((uint32_t)mwsrxmsk << 8) | ((uint32_t)wlantxmsk << 6) | ((uint32_t)wlanrxmsk << 4) | ((uint32_t)mwswcien << 3) | ((uint32_t)mwscoexen << 2) | ((uint32_t)syncgenen << 1) | ((uint32_t)wlancoexen << 0)); +} + +__INLINE void ble_coexifcntl0_unpack(uint8_t* mwsscanfreqmsk, uint8_t* wlcrxpriomode, uint8_t* wlctxpriomode, uint8_t* mwstxfrqmsk, uint8_t* mwsrxfrqmsk, uint8_t* mwstxmsk, uint8_t* mwsrxmsk, uint8_t* wlantxmsk, uint8_t* wlanrxmsk, uint8_t* mwswcien, uint8_t* mwscoexen, uint8_t* syncgenen, uint8_t* wlancoexen) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + + *mwsscanfreqmsk = (localVal & ((uint32_t)0x00300000)) >> 20; + *wlcrxpriomode = (localVal & ((uint32_t)0x000C0000)) >> 18; + *wlctxpriomode = (localVal & ((uint32_t)0x00030000)) >> 16; + *mwstxfrqmsk = (localVal & ((uint32_t)0x0000C000)) >> 14; + *mwsrxfrqmsk = (localVal & ((uint32_t)0x00003000)) >> 12; + *mwstxmsk = (localVal & ((uint32_t)0x00000C00)) >> 10; + *mwsrxmsk = (localVal & ((uint32_t)0x00000300)) >> 8; + *wlantxmsk = (localVal & ((uint32_t)0x000000C0)) >> 6; + *wlanrxmsk = (localVal & ((uint32_t)0x00000030)) >> 4; + *mwswcien = (localVal & ((uint32_t)0x00000008)) >> 3; + *mwscoexen = (localVal & ((uint32_t)0x00000004)) >> 2; + *syncgenen = (localVal & ((uint32_t)0x00000002)) >> 1; + *wlancoexen = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_coexifcntl0_mwsscanfreqmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00300000)) >> 20); +} + +__INLINE void ble_coexifcntl0_mwsscanfreqmsk_setf(uint8_t mwsscanfreqmsk) +{ + ASSERT_ERR((((uint32_t)mwsscanfreqmsk << 20) & ~((uint32_t)0x00300000)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x00300000)) | ((uint32_t)mwsscanfreqmsk << 20)); +} + +__INLINE uint8_t ble_coexifcntl0_wlcrxpriomode_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x000C0000)) >> 18); +} + +__INLINE void ble_coexifcntl0_wlcrxpriomode_setf(uint8_t wlcrxpriomode) +{ + ASSERT_ERR((((uint32_t)wlcrxpriomode << 18) & ~((uint32_t)0x000C0000)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x000C0000)) | ((uint32_t)wlcrxpriomode << 18)); +} + +__INLINE uint8_t ble_coexifcntl0_wlctxpriomode_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00030000)) >> 16); +} + +__INLINE void ble_coexifcntl0_wlctxpriomode_setf(uint8_t wlctxpriomode) +{ + ASSERT_ERR((((uint32_t)wlctxpriomode << 16) & ~((uint32_t)0x00030000)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x00030000)) | ((uint32_t)wlctxpriomode << 16)); +} + +__INLINE uint8_t ble_coexifcntl0_mwstxfrqmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x0000C000)) >> 14); +} + +__INLINE void ble_coexifcntl0_mwstxfrqmsk_setf(uint8_t mwstxfrqmsk) +{ + ASSERT_ERR((((uint32_t)mwstxfrqmsk << 14) & ~((uint32_t)0x0000C000)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x0000C000)) | ((uint32_t)mwstxfrqmsk << 14)); +} + +__INLINE uint8_t ble_coexifcntl0_mwsrxfrqmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00003000)) >> 12); +} + +__INLINE void ble_coexifcntl0_mwsrxfrqmsk_setf(uint8_t mwsrxfrqmsk) +{ + ASSERT_ERR((((uint32_t)mwsrxfrqmsk << 12) & ~((uint32_t)0x00003000)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x00003000)) | ((uint32_t)mwsrxfrqmsk << 12)); +} + +__INLINE uint8_t ble_coexifcntl0_mwstxmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000C00)) >> 10); +} + +__INLINE void ble_coexifcntl0_mwstxmsk_setf(uint8_t mwstxmsk) +{ + ASSERT_ERR((((uint32_t)mwstxmsk << 10) & ~((uint32_t)0x00000C00)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x00000C00)) | ((uint32_t)mwstxmsk << 10)); +} + +__INLINE uint8_t ble_coexifcntl0_mwsrxmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000300)) >> 8); +} + +__INLINE void ble_coexifcntl0_mwsrxmsk_setf(uint8_t mwsrxmsk) +{ + ASSERT_ERR((((uint32_t)mwsrxmsk << 8) & ~((uint32_t)0x00000300)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x00000300)) | ((uint32_t)mwsrxmsk << 8)); +} + +__INLINE uint8_t ble_coexifcntl0_wlantxmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x000000C0)) >> 6); +} + +__INLINE void ble_coexifcntl0_wlantxmsk_setf(uint8_t wlantxmsk) +{ + ASSERT_ERR((((uint32_t)wlantxmsk << 6) & ~((uint32_t)0x000000C0)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x000000C0)) | ((uint32_t)wlantxmsk << 6)); +} + +__INLINE uint8_t ble_coexifcntl0_wlanrxmsk_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000030)) >> 4); +} + +__INLINE void ble_coexifcntl0_wlanrxmsk_setf(uint8_t wlanrxmsk) +{ + ASSERT_ERR((((uint32_t)wlanrxmsk << 4) & ~((uint32_t)0x00000030)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x00000030)) | ((uint32_t)wlanrxmsk << 4)); +} + +__INLINE uint8_t ble_coexifcntl0_mwswci_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE void ble_coexifcntl0_mwswci_en_setf(uint8_t mwswcien) +{ + ASSERT_ERR((((uint32_t)mwswcien << 3) & ~((uint32_t)0x00000008)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x00000008)) | ((uint32_t)mwswcien << 3)); +} + +__INLINE uint8_t ble_coexifcntl0_mwscoex_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE void ble_coexifcntl0_mwscoex_en_setf(uint8_t mwscoexen) +{ + ASSERT_ERR((((uint32_t)mwscoexen << 2) & ~((uint32_t)0x00000004)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x00000004)) | ((uint32_t)mwscoexen << 2)); +} + +__INLINE uint8_t ble_coexifcntl0_syncgen_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ble_coexifcntl0_syncgen_en_setf(uint8_t syncgenen) +{ + ASSERT_ERR((((uint32_t)syncgenen << 1) & ~((uint32_t)0x00000002)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)syncgenen << 1)); +} + +__INLINE uint8_t ble_coexifcntl0_wlancoex_en_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ble_coexifcntl0_wlancoex_en_setf(uint8_t wlancoexen) +{ + ASSERT_ERR((((uint32_t)wlancoexen << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL0_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL0_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)wlancoexen << 0)); +} + +/** + * @brief COEXIFCNTL1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  28:24            WLCPRXTHR   0x0
+ *  20:16            WLCPTXTHR   0x0
+ *  14:08         WLCPDURATION   0x0
+ *  06:00            WLCPDELAY   0x0
+ * 
+ */ +#define BLE_COEXIFCNTL1_ADDR BASEBAND_REG_BASE +0x144 //0x50800144 +#define BLE_COEXIFCNTL1_OFFSET 0x00000144 +#define BLE_COEXIFCNTL1_INDEX 0x00000051 +#define BLE_COEXIFCNTL1_RESET 0x00000000 + +__INLINE uint32_t ble_coexifcntl1_get(void) +{ + return REG_BLE_RD(BLE_COEXIFCNTL1_ADDR); +} + +__INLINE void ble_coexifcntl1_set(uint32_t value) +{ + REG_BLE_WR(BLE_COEXIFCNTL1_ADDR, value); +} + +// field definitions +#define BLE_WLCPRXTHR_MASK ((uint32_t)0x1F000000) +#define BLE_WLCPRXTHR_LSB 24 +#define BLE_WLCPRXTHR_WIDTH ((uint32_t)0x00000005) +#define BLE_WLCPTXTHR_MASK ((uint32_t)0x001F0000) +#define BLE_WLCPTXTHR_LSB 16 +#define BLE_WLCPTXTHR_WIDTH ((uint32_t)0x00000005) +#define BLE_WLCPDURATION_MASK ((uint32_t)0x00007F00) +#define BLE_WLCPDURATION_LSB 8 +#define BLE_WLCPDURATION_WIDTH ((uint32_t)0x00000007) +#define BLE_WLCPDELAY_MASK ((uint32_t)0x0000007F) +#define BLE_WLCPDELAY_LSB 0 +#define BLE_WLCPDELAY_WIDTH ((uint32_t)0x00000007) + +#define BLE_WLCPRXTHR_RST 0x0 +#define BLE_WLCPTXTHR_RST 0x0 +#define BLE_WLCPDURATION_RST 0x0 +#define BLE_WLCPDELAY_RST 0x0 + +__INLINE void ble_coexifcntl1_pack(uint8_t wlcprxthr, uint8_t wlcptxthr, uint8_t wlcpduration, uint8_t wlcpdelay) +{ + ASSERT_ERR((((uint32_t)wlcprxthr << 24) & ~((uint32_t)0x1F000000)) == 0); + ASSERT_ERR((((uint32_t)wlcptxthr << 16) & ~((uint32_t)0x001F0000)) == 0); + ASSERT_ERR((((uint32_t)wlcpduration << 8) & ~((uint32_t)0x00007F00)) == 0); + ASSERT_ERR((((uint32_t)wlcpdelay << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL1_ADDR, ((uint32_t)wlcprxthr << 24) | ((uint32_t)wlcptxthr << 16) | ((uint32_t)wlcpduration << 8) | ((uint32_t)wlcpdelay << 0)); +} + +__INLINE void ble_coexifcntl1_unpack(uint8_t* wlcprxthr, uint8_t* wlcptxthr, uint8_t* wlcpduration, uint8_t* wlcpdelay) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL1_ADDR); + + *wlcprxthr = (localVal & ((uint32_t)0x1F000000)) >> 24; + *wlcptxthr = (localVal & ((uint32_t)0x001F0000)) >> 16; + *wlcpduration = (localVal & ((uint32_t)0x00007F00)) >> 8; + *wlcpdelay = (localVal & ((uint32_t)0x0000007F)) >> 0; +} + +__INLINE uint8_t ble_coexifcntl1_wlcprxthr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL1_ADDR); + return ((localVal & ((uint32_t)0x1F000000)) >> 24); +} + +__INLINE void ble_coexifcntl1_wlcprxthr_setf(uint8_t wlcprxthr) +{ + ASSERT_ERR((((uint32_t)wlcprxthr << 24) & ~((uint32_t)0x1F000000)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL1_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL1_ADDR) & ~((uint32_t)0x1F000000)) | ((uint32_t)wlcprxthr << 24)); +} + +__INLINE uint8_t ble_coexifcntl1_wlcptxthr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL1_ADDR); + return ((localVal & ((uint32_t)0x001F0000)) >> 16); +} + +__INLINE void ble_coexifcntl1_wlcptxthr_setf(uint8_t wlcptxthr) +{ + ASSERT_ERR((((uint32_t)wlcptxthr << 16) & ~((uint32_t)0x001F0000)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL1_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL1_ADDR) & ~((uint32_t)0x001F0000)) | ((uint32_t)wlcptxthr << 16)); +} + +__INLINE uint8_t ble_coexifcntl1_wlcpduration_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00007F00)) >> 8); +} + +__INLINE void ble_coexifcntl1_wlcpduration_setf(uint8_t wlcpduration) +{ + ASSERT_ERR((((uint32_t)wlcpduration << 8) & ~((uint32_t)0x00007F00)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL1_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL1_ADDR) & ~((uint32_t)0x00007F00)) | ((uint32_t)wlcpduration << 8)); +} + +__INLINE uint8_t ble_coexifcntl1_wlcpdelay_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL1_ADDR); + return ((localVal & ((uint32_t)0x0000007F)) >> 0); +} + +__INLINE void ble_coexifcntl1_wlcpdelay_setf(uint8_t wlcpdelay) +{ + ASSERT_ERR((((uint32_t)wlcpdelay << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL1_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL1_ADDR) & ~((uint32_t)0x0000007F)) | ((uint32_t)wlcpdelay << 0)); +} + +/** + * @brief COEXIFCNTL2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  11:08         RX_ANT_DELAY   0x0
+ *  03:00         TX_ANT_DELAY   0x0
+ * 
+ */ +#define BLE_COEXIFCNTL2_ADDR BASEBAND_REG_BASE +0x148 //0x50800148 +#define BLE_COEXIFCNTL2_OFFSET 0x00000148 +#define BLE_COEXIFCNTL2_INDEX 0x00000052 +#define BLE_COEXIFCNTL2_RESET 0x00000000 + +__INLINE uint32_t ble_coexifcntl2_get(void) +{ + return REG_BLE_RD(BLE_COEXIFCNTL2_ADDR); +} + +__INLINE void ble_coexifcntl2_set(uint32_t value) +{ + REG_BLE_WR(BLE_COEXIFCNTL2_ADDR, value); +} + +// field definitions +#define BLE_RX_ANT_DELAY_MASK ((uint32_t)0x00000F00) +#define BLE_RX_ANT_DELAY_LSB 8 +#define BLE_RX_ANT_DELAY_WIDTH ((uint32_t)0x00000004) +#define BLE_TX_ANT_DELAY_MASK ((uint32_t)0x0000000F) +#define BLE_TX_ANT_DELAY_LSB 0 +#define BLE_TX_ANT_DELAY_WIDTH ((uint32_t)0x00000004) + +#define BLE_RX_ANT_DELAY_RST 0x0 +#define BLE_TX_ANT_DELAY_RST 0x0 + +__INLINE void ble_coexifcntl2_pack(uint8_t rxantdelay, uint8_t txantdelay) +{ + ASSERT_ERR((((uint32_t)rxantdelay << 8) & ~((uint32_t)0x00000F00)) == 0); + ASSERT_ERR((((uint32_t)txantdelay << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL2_ADDR, ((uint32_t)rxantdelay << 8) | ((uint32_t)txantdelay << 0)); +} + +__INLINE void ble_coexifcntl2_unpack(uint8_t* rxantdelay, uint8_t* txantdelay) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL2_ADDR); + + *rxantdelay = (localVal & ((uint32_t)0x00000F00)) >> 8; + *txantdelay = (localVal & ((uint32_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t ble_coexifcntl2_rx_ant_delay_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL2_ADDR); + return ((localVal & ((uint32_t)0x00000F00)) >> 8); +} + +__INLINE void ble_coexifcntl2_rx_ant_delay_setf(uint8_t rxantdelay) +{ + ASSERT_ERR((((uint32_t)rxantdelay << 8) & ~((uint32_t)0x00000F00)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL2_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL2_ADDR) & ~((uint32_t)0x00000F00)) | ((uint32_t)rxantdelay << 8)); +} + +__INLINE uint8_t ble_coexifcntl2_tx_ant_delay_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_COEXIFCNTL2_ADDR); + return ((localVal & ((uint32_t)0x0000000F)) >> 0); +} + +__INLINE void ble_coexifcntl2_tx_ant_delay_setf(uint8_t txantdelay) +{ + ASSERT_ERR((((uint32_t)txantdelay << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_COEXIFCNTL2_ADDR, (REG_BLE_RD(BLE_COEXIFCNTL2_ADDR) & ~((uint32_t)0x0000000F)) | ((uint32_t)txantdelay << 0)); +} + +/** + * @brief BLEMPRIO0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:28                BLEM7   0x3
+ *  27:24                BLEM6   0x4
+ *  23:20                BLEM5   0x8
+ *  19:16                BLEM4   0x9
+ *  15:12                BLEM3   0xA
+ *  11:08                BLEM2   0xD
+ *  07:04                BLEM1   0xE
+ *  03:00                BLEM0   0xF
+ * 
+ */ +#define BLE_BLEMPRIO0_ADDR BASEBAND_REG_BASE +0x14C // 0x5080014C +#define BLE_BLEMPRIO0_OFFSET 0x0000014C +#define BLE_BLEMPRIO0_INDEX 0x00000053 +#define BLE_BLEMPRIO0_RESET 0x3489ADEF + +__INLINE uint32_t ble_blemprio0_get(void) +{ + return REG_BLE_RD(BLE_BLEMPRIO0_ADDR); +} + +__INLINE void ble_blemprio0_set(uint32_t value) +{ + REG_BLE_WR(BLE_BLEMPRIO0_ADDR, value); +} + +// field definitions +#define BLE_BLEM7_MASK ((uint32_t)0xF0000000) +#define BLE_BLEM7_LSB 28 +#define BLE_BLEM7_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM6_MASK ((uint32_t)0x0F000000) +#define BLE_BLEM6_LSB 24 +#define BLE_BLEM6_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM5_MASK ((uint32_t)0x00F00000) +#define BLE_BLEM5_LSB 20 +#define BLE_BLEM5_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM4_MASK ((uint32_t)0x000F0000) +#define BLE_BLEM4_LSB 16 +#define BLE_BLEM4_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM3_MASK ((uint32_t)0x0000F000) +#define BLE_BLEM3_LSB 12 +#define BLE_BLEM3_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM2_MASK ((uint32_t)0x00000F00) +#define BLE_BLEM2_LSB 8 +#define BLE_BLEM2_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM1_MASK ((uint32_t)0x000000F0) +#define BLE_BLEM1_LSB 4 +#define BLE_BLEM1_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM0_MASK ((uint32_t)0x0000000F) +#define BLE_BLEM0_LSB 0 +#define BLE_BLEM0_WIDTH ((uint32_t)0x00000004) + +#define BLE_BLEM7_RST 0x3 +#define BLE_BLEM6_RST 0x4 +#define BLE_BLEM5_RST 0x8 +#define BLE_BLEM4_RST 0x9 +#define BLE_BLEM3_RST 0xA +#define BLE_BLEM2_RST 0xD +#define BLE_BLEM1_RST 0xE +#define BLE_BLEM0_RST 0xF + +__INLINE void ble_blemprio0_pack(uint8_t blem7, uint8_t blem6, uint8_t blem5, uint8_t blem4, uint8_t blem3, uint8_t blem2, uint8_t blem1, uint8_t blem0) +{ + ASSERT_ERR((((uint32_t)blem7 << 28) & ~((uint32_t)0xF0000000)) == 0); + ASSERT_ERR((((uint32_t)blem6 << 24) & ~((uint32_t)0x0F000000)) == 0); + ASSERT_ERR((((uint32_t)blem5 << 20) & ~((uint32_t)0x00F00000)) == 0); + ASSERT_ERR((((uint32_t)blem4 << 16) & ~((uint32_t)0x000F0000)) == 0); + ASSERT_ERR((((uint32_t)blem3 << 12) & ~((uint32_t)0x0000F000)) == 0); + ASSERT_ERR((((uint32_t)blem2 << 8) & ~((uint32_t)0x00000F00)) == 0); + ASSERT_ERR((((uint32_t)blem1 << 4) & ~((uint32_t)0x000000F0)) == 0); + ASSERT_ERR((((uint32_t)blem0 << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_BLEMPRIO0_ADDR, ((uint32_t)blem7 << 28) | ((uint32_t)blem6 << 24) | ((uint32_t)blem5 << 20) | ((uint32_t)blem4 << 16) | ((uint32_t)blem3 << 12) | ((uint32_t)blem2 << 8) | ((uint32_t)blem1 << 4) | ((uint32_t)blem0 << 0)); +} + +__INLINE void ble_blemprio0_unpack(uint8_t* blem7, uint8_t* blem6, uint8_t* blem5, uint8_t* blem4, uint8_t* blem3, uint8_t* blem2, uint8_t* blem1, uint8_t* blem0) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO0_ADDR); + + *blem7 = (localVal & ((uint32_t)0xF0000000)) >> 28; + *blem6 = (localVal & ((uint32_t)0x0F000000)) >> 24; + *blem5 = (localVal & ((uint32_t)0x00F00000)) >> 20; + *blem4 = (localVal & ((uint32_t)0x000F0000)) >> 16; + *blem3 = (localVal & ((uint32_t)0x0000F000)) >> 12; + *blem2 = (localVal & ((uint32_t)0x00000F00)) >> 8; + *blem1 = (localVal & ((uint32_t)0x000000F0)) >> 4; + *blem0 = (localVal & ((uint32_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t ble_blemprio0_blem7_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO0_ADDR); + return ((localVal & ((uint32_t)0xF0000000)) >> 28); +} + +__INLINE void ble_blemprio0_blem7_setf(uint8_t blem7) +{ + ASSERT_ERR((((uint32_t)blem7 << 28) & ~((uint32_t)0xF0000000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO0_ADDR, (REG_BLE_RD(BLE_BLEMPRIO0_ADDR) & ~((uint32_t)0xF0000000)) | ((uint32_t)blem7 << 28)); +} + +__INLINE uint8_t ble_blemprio0_blem6_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO0_ADDR); + return ((localVal & ((uint32_t)0x0F000000)) >> 24); +} + +__INLINE void ble_blemprio0_blem6_setf(uint8_t blem6) +{ + ASSERT_ERR((((uint32_t)blem6 << 24) & ~((uint32_t)0x0F000000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO0_ADDR, (REG_BLE_RD(BLE_BLEMPRIO0_ADDR) & ~((uint32_t)0x0F000000)) | ((uint32_t)blem6 << 24)); +} + +__INLINE uint8_t ble_blemprio0_blem5_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO0_ADDR); + return ((localVal & ((uint32_t)0x00F00000)) >> 20); +} + +__INLINE void ble_blemprio0_blem5_setf(uint8_t blem5) +{ + ASSERT_ERR((((uint32_t)blem5 << 20) & ~((uint32_t)0x00F00000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO0_ADDR, (REG_BLE_RD(BLE_BLEMPRIO0_ADDR) & ~((uint32_t)0x00F00000)) | ((uint32_t)blem5 << 20)); +} + +__INLINE uint8_t ble_blemprio0_blem4_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO0_ADDR); + return ((localVal & ((uint32_t)0x000F0000)) >> 16); +} + +__INLINE void ble_blemprio0_blem4_setf(uint8_t blem4) +{ + ASSERT_ERR((((uint32_t)blem4 << 16) & ~((uint32_t)0x000F0000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO0_ADDR, (REG_BLE_RD(BLE_BLEMPRIO0_ADDR) & ~((uint32_t)0x000F0000)) | ((uint32_t)blem4 << 16)); +} + +__INLINE uint8_t ble_blemprio0_blem3_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO0_ADDR); + return ((localVal & ((uint32_t)0x0000F000)) >> 12); +} + +__INLINE void ble_blemprio0_blem3_setf(uint8_t blem3) +{ + ASSERT_ERR((((uint32_t)blem3 << 12) & ~((uint32_t)0x0000F000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO0_ADDR, (REG_BLE_RD(BLE_BLEMPRIO0_ADDR) & ~((uint32_t)0x0000F000)) | ((uint32_t)blem3 << 12)); +} + +__INLINE uint8_t ble_blemprio0_blem2_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO0_ADDR); + return ((localVal & ((uint32_t)0x00000F00)) >> 8); +} + +__INLINE void ble_blemprio0_blem2_setf(uint8_t blem2) +{ + ASSERT_ERR((((uint32_t)blem2 << 8) & ~((uint32_t)0x00000F00)) == 0); + REG_BLE_WR(BLE_BLEMPRIO0_ADDR, (REG_BLE_RD(BLE_BLEMPRIO0_ADDR) & ~((uint32_t)0x00000F00)) | ((uint32_t)blem2 << 8)); +} + +__INLINE uint8_t ble_blemprio0_blem1_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO0_ADDR); + return ((localVal & ((uint32_t)0x000000F0)) >> 4); +} + +__INLINE void ble_blemprio0_blem1_setf(uint8_t blem1) +{ + ASSERT_ERR((((uint32_t)blem1 << 4) & ~((uint32_t)0x000000F0)) == 0); + REG_BLE_WR(BLE_BLEMPRIO0_ADDR, (REG_BLE_RD(BLE_BLEMPRIO0_ADDR) & ~((uint32_t)0x000000F0)) | ((uint32_t)blem1 << 4)); +} + +__INLINE uint8_t ble_blemprio0_blem0_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO0_ADDR); + return ((localVal & ((uint32_t)0x0000000F)) >> 0); +} + +__INLINE void ble_blemprio0_blem0_setf(uint8_t blem0) +{ + ASSERT_ERR((((uint32_t)blem0 << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_BLEMPRIO0_ADDR, (REG_BLE_RD(BLE_BLEMPRIO0_ADDR) & ~((uint32_t)0x0000000F)) | ((uint32_t)blem0 << 0)); +} + +/** + * @brief BLEMPRIO1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:28               BLEM15   0x3
+ *  27:24               BLEM14   0x4
+ *  23:20               BLEM13   0x8
+ *  19:16               BLEM12   0x9
+ *  15:12               BLEM11   0xA
+ *  11:08               BLEM10   0xF
+ *  07:04                BLEM9   0xD
+ *  03:00                BLEM8   0xC
+ * 
+ */ +#define BLE_BLEMPRIO1_ADDR BASEBAND_REG_BASE +0x150 // 0x50800150 +#define BLE_BLEMPRIO1_OFFSET 0x00000150 +#define BLE_BLEMPRIO1_INDEX 0x00000054 +#define BLE_BLEMPRIO1_RESET 0x3489AFDC + +__INLINE uint32_t ble_blemprio1_get(void) +{ + return REG_BLE_RD(BLE_BLEMPRIO1_ADDR); +} + +__INLINE void ble_blemprio1_set(uint32_t value) +{ + REG_BLE_WR(BLE_BLEMPRIO1_ADDR, value); +} + +// field definitions +#define BLE_BLEM15_MASK ((uint32_t)0xF0000000) +#define BLE_BLEM15_LSB 28 +#define BLE_BLEM15_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM14_MASK ((uint32_t)0x0F000000) +#define BLE_BLEM14_LSB 24 +#define BLE_BLEM14_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM13_MASK ((uint32_t)0x00F00000) +#define BLE_BLEM13_LSB 20 +#define BLE_BLEM13_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM12_MASK ((uint32_t)0x000F0000) +#define BLE_BLEM12_LSB 16 +#define BLE_BLEM12_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM11_MASK ((uint32_t)0x0000F000) +#define BLE_BLEM11_LSB 12 +#define BLE_BLEM11_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM10_MASK ((uint32_t)0x00000F00) +#define BLE_BLEM10_LSB 8 +#define BLE_BLEM10_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM9_MASK ((uint32_t)0x000000F0) +#define BLE_BLEM9_LSB 4 +#define BLE_BLEM9_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM8_MASK ((uint32_t)0x0000000F) +#define BLE_BLEM8_LSB 0 +#define BLE_BLEM8_WIDTH ((uint32_t)0x00000004) + +#define BLE_BLEM15_RST 0x3 +#define BLE_BLEM14_RST 0x4 +#define BLE_BLEM13_RST 0x8 +#define BLE_BLEM12_RST 0x9 +#define BLE_BLEM11_RST 0xA +#define BLE_BLEM10_RST 0xF +#define BLE_BLEM9_RST 0xD +#define BLE_BLEM8_RST 0xC + +__INLINE void ble_blemprio1_pack(uint8_t blem15, uint8_t blem14, uint8_t blem13, uint8_t blem12, uint8_t blem11, uint8_t blem10, uint8_t blem9, uint8_t blem8) +{ + ASSERT_ERR((((uint32_t)blem15 << 28) & ~((uint32_t)0xF0000000)) == 0); + ASSERT_ERR((((uint32_t)blem14 << 24) & ~((uint32_t)0x0F000000)) == 0); + ASSERT_ERR((((uint32_t)blem13 << 20) & ~((uint32_t)0x00F00000)) == 0); + ASSERT_ERR((((uint32_t)blem12 << 16) & ~((uint32_t)0x000F0000)) == 0); + ASSERT_ERR((((uint32_t)blem11 << 12) & ~((uint32_t)0x0000F000)) == 0); + ASSERT_ERR((((uint32_t)blem10 << 8) & ~((uint32_t)0x00000F00)) == 0); + ASSERT_ERR((((uint32_t)blem9 << 4) & ~((uint32_t)0x000000F0)) == 0); + ASSERT_ERR((((uint32_t)blem8 << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_BLEMPRIO1_ADDR, ((uint32_t)blem15 << 28) | ((uint32_t)blem14 << 24) | ((uint32_t)blem13 << 20) | ((uint32_t)blem12 << 16) | ((uint32_t)blem11 << 12) | ((uint32_t)blem10 << 8) | ((uint32_t)blem9 << 4) | ((uint32_t)blem8 << 0)); +} + +__INLINE void ble_blemprio1_unpack(uint8_t* blem15, uint8_t* blem14, uint8_t* blem13, uint8_t* blem12, uint8_t* blem11, uint8_t* blem10, uint8_t* blem9, uint8_t* blem8) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO1_ADDR); + + *blem15 = (localVal & ((uint32_t)0xF0000000)) >> 28; + *blem14 = (localVal & ((uint32_t)0x0F000000)) >> 24; + *blem13 = (localVal & ((uint32_t)0x00F00000)) >> 20; + *blem12 = (localVal & ((uint32_t)0x000F0000)) >> 16; + *blem11 = (localVal & ((uint32_t)0x0000F000)) >> 12; + *blem10 = (localVal & ((uint32_t)0x00000F00)) >> 8; + *blem9 = (localVal & ((uint32_t)0x000000F0)) >> 4; + *blem8 = (localVal & ((uint32_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t ble_blemprio1_blem15_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO1_ADDR); + return ((localVal & ((uint32_t)0xF0000000)) >> 28); +} + +__INLINE void ble_blemprio1_blem15_setf(uint8_t blem15) +{ + ASSERT_ERR((((uint32_t)blem15 << 28) & ~((uint32_t)0xF0000000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO1_ADDR, (REG_BLE_RD(BLE_BLEMPRIO1_ADDR) & ~((uint32_t)0xF0000000)) | ((uint32_t)blem15 << 28)); +} + +__INLINE uint8_t ble_blemprio1_blem14_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO1_ADDR); + return ((localVal & ((uint32_t)0x0F000000)) >> 24); +} + +__INLINE void ble_blemprio1_blem14_setf(uint8_t blem14) +{ + ASSERT_ERR((((uint32_t)blem14 << 24) & ~((uint32_t)0x0F000000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO1_ADDR, (REG_BLE_RD(BLE_BLEMPRIO1_ADDR) & ~((uint32_t)0x0F000000)) | ((uint32_t)blem14 << 24)); +} + +__INLINE uint8_t ble_blemprio1_blem13_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO1_ADDR); + return ((localVal & ((uint32_t)0x00F00000)) >> 20); +} + +__INLINE void ble_blemprio1_blem13_setf(uint8_t blem13) +{ + ASSERT_ERR((((uint32_t)blem13 << 20) & ~((uint32_t)0x00F00000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO1_ADDR, (REG_BLE_RD(BLE_BLEMPRIO1_ADDR) & ~((uint32_t)0x00F00000)) | ((uint32_t)blem13 << 20)); +} + +__INLINE uint8_t ble_blemprio1_blem12_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO1_ADDR); + return ((localVal & ((uint32_t)0x000F0000)) >> 16); +} + +__INLINE void ble_blemprio1_blem12_setf(uint8_t blem12) +{ + ASSERT_ERR((((uint32_t)blem12 << 16) & ~((uint32_t)0x000F0000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO1_ADDR, (REG_BLE_RD(BLE_BLEMPRIO1_ADDR) & ~((uint32_t)0x000F0000)) | ((uint32_t)blem12 << 16)); +} + +__INLINE uint8_t ble_blemprio1_blem11_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO1_ADDR); + return ((localVal & ((uint32_t)0x0000F000)) >> 12); +} + +__INLINE void ble_blemprio1_blem11_setf(uint8_t blem11) +{ + ASSERT_ERR((((uint32_t)blem11 << 12) & ~((uint32_t)0x0000F000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO1_ADDR, (REG_BLE_RD(BLE_BLEMPRIO1_ADDR) & ~((uint32_t)0x0000F000)) | ((uint32_t)blem11 << 12)); +} + +__INLINE uint8_t ble_blemprio1_blem10_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO1_ADDR); + return ((localVal & ((uint32_t)0x00000F00)) >> 8); +} + +__INLINE void ble_blemprio1_blem10_setf(uint8_t blem10) +{ + ASSERT_ERR((((uint32_t)blem10 << 8) & ~((uint32_t)0x00000F00)) == 0); + REG_BLE_WR(BLE_BLEMPRIO1_ADDR, (REG_BLE_RD(BLE_BLEMPRIO1_ADDR) & ~((uint32_t)0x00000F00)) | ((uint32_t)blem10 << 8)); +} + +__INLINE uint8_t ble_blemprio1_blem9_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO1_ADDR); + return ((localVal & ((uint32_t)0x000000F0)) >> 4); +} + +__INLINE void ble_blemprio1_blem9_setf(uint8_t blem9) +{ + ASSERT_ERR((((uint32_t)blem9 << 4) & ~((uint32_t)0x000000F0)) == 0); + REG_BLE_WR(BLE_BLEMPRIO1_ADDR, (REG_BLE_RD(BLE_BLEMPRIO1_ADDR) & ~((uint32_t)0x000000F0)) | ((uint32_t)blem9 << 4)); +} + +__INLINE uint8_t ble_blemprio1_blem8_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO1_ADDR); + return ((localVal & ((uint32_t)0x0000000F)) >> 0); +} + +__INLINE void ble_blemprio1_blem8_setf(uint8_t blem8) +{ + ASSERT_ERR((((uint32_t)blem8 << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_BLEMPRIO1_ADDR, (REG_BLE_RD(BLE_BLEMPRIO1_ADDR) & ~((uint32_t)0x0000000F)) | ((uint32_t)blem8 << 0)); +} + +/** + * @brief BLEMPRIO2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:28          BLEMDEFAULT   0x3
+ *  11:08               BLEM18   0x2
+ *  07:04               BLEM17   0x7
+ *  03:00               BLEM16   0x7
+ * 
+ */ +#define BLE_BLEMPRIO2_ADDR BASEBAND_REG_BASE +0x154 //0x50800154 +#define BLE_BLEMPRIO2_OFFSET 0x00000154 +#define BLE_BLEMPRIO2_INDEX 0x00000055 +#define BLE_BLEMPRIO2_RESET 0x30000277 + +__INLINE uint32_t ble_blemprio2_get(void) +{ + return REG_BLE_RD(BLE_BLEMPRIO2_ADDR); +} + +__INLINE void ble_blemprio2_set(uint32_t value) +{ + REG_BLE_WR(BLE_BLEMPRIO2_ADDR, value); +} + +// field definitions +#define BLE_BLEMDEFAULT_MASK ((uint32_t)0xF0000000) +#define BLE_BLEMDEFAULT_LSB 28 +#define BLE_BLEMDEFAULT_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM18_MASK ((uint32_t)0x00000F00) +#define BLE_BLEM18_LSB 8 +#define BLE_BLEM18_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM17_MASK ((uint32_t)0x000000F0) +#define BLE_BLEM17_LSB 4 +#define BLE_BLEM17_WIDTH ((uint32_t)0x00000004) +#define BLE_BLEM16_MASK ((uint32_t)0x0000000F) +#define BLE_BLEM16_LSB 0 +#define BLE_BLEM16_WIDTH ((uint32_t)0x00000004) + +#define BLE_BLEMDEFAULT_RST 0x3 +#define BLE_BLEM18_RST 0x2 +#define BLE_BLEM17_RST 0x7 +#define BLE_BLEM16_RST 0x7 + +__INLINE void ble_blemprio2_pack(uint8_t blemdefault, uint8_t blem18, uint8_t blem17, uint8_t blem16) +{ + ASSERT_ERR((((uint32_t)blemdefault << 28) & ~((uint32_t)0xF0000000)) == 0); + ASSERT_ERR((((uint32_t)blem18 << 8) & ~((uint32_t)0x00000F00)) == 0); + ASSERT_ERR((((uint32_t)blem17 << 4) & ~((uint32_t)0x000000F0)) == 0); + ASSERT_ERR((((uint32_t)blem16 << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_BLEMPRIO2_ADDR, ((uint32_t)blemdefault << 28) | ((uint32_t)blem18 << 8) | ((uint32_t)blem17 << 4) | ((uint32_t)blem16 << 0)); +} + +__INLINE void ble_blemprio2_unpack(uint8_t* blemdefault, uint8_t* blem18, uint8_t* blem17, uint8_t* blem16) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO2_ADDR); + + *blemdefault = (localVal & ((uint32_t)0xF0000000)) >> 28; + *blem18 = (localVal & ((uint32_t)0x00000F00)) >> 8; + *blem17 = (localVal & ((uint32_t)0x000000F0)) >> 4; + *blem16 = (localVal & ((uint32_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t ble_blemprio2_blemdefault_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO2_ADDR); + return ((localVal & ((uint32_t)0xF0000000)) >> 28); +} + +__INLINE void ble_blemprio2_blemdefault_setf(uint8_t blemdefault) +{ + ASSERT_ERR((((uint32_t)blemdefault << 28) & ~((uint32_t)0xF0000000)) == 0); + REG_BLE_WR(BLE_BLEMPRIO2_ADDR, (REG_BLE_RD(BLE_BLEMPRIO2_ADDR) & ~((uint32_t)0xF0000000)) | ((uint32_t)blemdefault << 28)); +} + +__INLINE uint8_t ble_blemprio2_blem18_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO2_ADDR); + return ((localVal & ((uint32_t)0x00000F00)) >> 8); +} + +__INLINE void ble_blemprio2_blem18_setf(uint8_t blem18) +{ + ASSERT_ERR((((uint32_t)blem18 << 8) & ~((uint32_t)0x00000F00)) == 0); + REG_BLE_WR(BLE_BLEMPRIO2_ADDR, (REG_BLE_RD(BLE_BLEMPRIO2_ADDR) & ~((uint32_t)0x00000F00)) | ((uint32_t)blem18 << 8)); +} + +__INLINE uint8_t ble_blemprio2_blem17_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO2_ADDR); + return ((localVal & ((uint32_t)0x000000F0)) >> 4); +} + +__INLINE void ble_blemprio2_blem17_setf(uint8_t blem17) +{ + ASSERT_ERR((((uint32_t)blem17 << 4) & ~((uint32_t)0x000000F0)) == 0); + REG_BLE_WR(BLE_BLEMPRIO2_ADDR, (REG_BLE_RD(BLE_BLEMPRIO2_ADDR) & ~((uint32_t)0x000000F0)) | ((uint32_t)blem17 << 4)); +} + +__INLINE uint8_t ble_blemprio2_blem16_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_BLEMPRIO2_ADDR); + return ((localVal & ((uint32_t)0x0000000F)) >> 0); +} + +__INLINE void ble_blemprio2_blem16_setf(uint8_t blem16) +{ + ASSERT_ERR((((uint32_t)blem16 << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_BLE_WR(BLE_BLEMPRIO2_ADDR, (REG_BLE_RD(BLE_BLEMPRIO2_ADDR) & ~((uint32_t)0x0000000F)) | ((uint32_t)blem16 << 0)); +} + +/** + * @brief RALCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  23:16             RALNBDEV   0x0
+ *  13:00           RALBASEPTR   0x0
+ * 
+ */ +#define BLE_RALCNTL_ADDR BASEBAND_REG_BASE +0x160 //0x50800160 +#define BLE_RALCNTL_OFFSET 0x00000160 +#define BLE_RALCNTL_INDEX 0x00000058 +#define BLE_RALCNTL_RESET 0x00000000 + +__INLINE uint32_t ble_ralcntl_get(void) +{ + return REG_BLE_RD(BLE_RALCNTL_ADDR); +} + +__INLINE void ble_ralcntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_RALCNTL_ADDR, value); +} + +// field definitions +#define BLE_RALNBDEV_MASK ((uint32_t)0x00FF0000) +#define BLE_RALNBDEV_LSB 16 +#define BLE_RALNBDEV_WIDTH ((uint32_t)0x00000008) +#define BLE_RALBASEPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_RALBASEPTR_LSB 0 +#define BLE_RALBASEPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_RALNBDEV_RST 0x0 +#define BLE_RALBASEPTR_RST 0x0 + +__INLINE void ble_ralcntl_pack(uint8_t ralnbdev, uint16_t ralbaseptr) +{ + ASSERT_ERR((((uint32_t)ralnbdev << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)ralbaseptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_RALCNTL_ADDR, ((uint32_t)ralnbdev << 16) | ((uint32_t)ralbaseptr << 0)); +} + +__INLINE void ble_ralcntl_unpack(uint8_t* ralnbdev, uint16_t* ralbaseptr) +{ + uint32_t localVal = REG_BLE_RD(BLE_RALCNTL_ADDR); + + *ralnbdev = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *ralbaseptr = (localVal & ((uint32_t)0x00003FFF)) >> 0; +} + +__INLINE uint8_t ble_ralcntl_ralnbdev_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RALCNTL_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_ralcntl_ralnbdev_setf(uint8_t ralnbdev) +{ + ASSERT_ERR((((uint32_t)ralnbdev << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_RALCNTL_ADDR, (REG_BLE_RD(BLE_RALCNTL_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)ralnbdev << 16)); +} + +__INLINE uint16_t ble_ralcntl_ralbaseptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RALCNTL_ADDR); + return ((localVal & ((uint32_t)0x00003FFF)) >> 0); +} + +__INLINE void ble_ralcntl_ralbaseptr_setf(uint16_t ralbaseptr) +{ + ASSERT_ERR((((uint32_t)ralbaseptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_RALCNTL_ADDR, (REG_BLE_RD(BLE_RALCNTL_ADDR) & ~((uint32_t)0x00003FFF)) | ((uint32_t)ralbaseptr << 0)); +} + +/** + * @brief RALCURRENTPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00        RALCURRENTPTR   0x0
+ * 
+ */ +#define BLE_RALCURRENTPTR_ADDR BASEBAND_REG_BASE +0x164 //0x50800164 +#define BLE_RALCURRENTPTR_OFFSET 0x00000164 +#define BLE_RALCURRENTPTR_INDEX 0x00000059 +#define BLE_RALCURRENTPTR_RESET 0x00000000 + +__INLINE uint32_t ble_ralcurrentptr_get(void) +{ + return REG_BLE_RD(BLE_RALCURRENTPTR_ADDR); +} + +__INLINE void ble_ralcurrentptr_set(uint32_t value) +{ + REG_BLE_WR(BLE_RALCURRENTPTR_ADDR, value); +} + +// field definitions +#define BLE_RALCURRENTPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_RALCURRENTPTR_LSB 0 +#define BLE_RALCURRENTPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_RALCURRENTPTR_RST 0x0 + +__INLINE uint16_t ble_ralcurrentptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RALCURRENTPTR_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_ralcurrentptr_setf(uint16_t ralcurrentptr) +{ + ASSERT_ERR((((uint32_t)ralcurrentptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_RALCURRENTPTR_ADDR, (uint32_t)ralcurrentptr << 0); +} + +/** + * @brief RAL_LOCAL_RND register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31            LRND_INIT   0
+ *  21:00             LRND_VAL   0x3F0F0F
+ * 
+ */ +#define BLE_RAL_LOCAL_RND_ADDR BASEBAND_REG_BASE +0x168 //0x50800168 +#define BLE_RAL_LOCAL_RND_OFFSET 0x00000168 +#define BLE_RAL_LOCAL_RND_INDEX 0x0000005A +#define BLE_RAL_LOCAL_RND_RESET 0x003F0F0F + +__INLINE uint32_t ble_ral_local_rnd_get(void) +{ + return REG_BLE_RD(BLE_RAL_LOCAL_RND_ADDR); +} + +__INLINE void ble_ral_local_rnd_set(uint32_t value) +{ + REG_BLE_WR(BLE_RAL_LOCAL_RND_ADDR, value); +} + +// field definitions +#define BLE_LRND_INIT_BIT ((uint32_t)0x80000000) +#define BLE_LRND_INIT_POS 31 +#define BLE_LRND_VAL_MASK ((uint32_t)0x003FFFFF) +#define BLE_LRND_VAL_LSB 0 +#define BLE_LRND_VAL_WIDTH ((uint32_t)0x00000016) + +#define BLE_LRND_INIT_RST 0x0 +#define BLE_LRND_VAL_RST 0x3F0F0F + +__INLINE void ble_ral_local_rnd_pack(uint8_t lrndinit, uint32_t lrndval) +{ + ASSERT_ERR((((uint32_t)lrndinit << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)lrndval << 0) & ~((uint32_t)0x003FFFFF)) == 0); + REG_BLE_WR(BLE_RAL_LOCAL_RND_ADDR, ((uint32_t)lrndinit << 31) | ((uint32_t)lrndval << 0)); +} + +__INLINE void ble_ral_local_rnd_unpack(uint8_t* lrndinit, uint32_t* lrndval) +{ + uint32_t localVal = REG_BLE_RD(BLE_RAL_LOCAL_RND_ADDR); + + *lrndinit = (localVal & ((uint32_t)0x80000000)) >> 31; + *lrndval = (localVal & ((uint32_t)0x003FFFFF)) >> 0; +} + +__INLINE uint8_t ble_ral_local_rnd_lrnd_init_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RAL_LOCAL_RND_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_ral_local_rnd_lrnd_init_setf(uint8_t lrndinit) +{ + ASSERT_ERR((((uint32_t)lrndinit << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_RAL_LOCAL_RND_ADDR, (REG_BLE_RD(BLE_RAL_LOCAL_RND_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)lrndinit << 31)); +} + +__INLINE uint32_t ble_ral_local_rnd_lrnd_val_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RAL_LOCAL_RND_ADDR); + return ((localVal & ((uint32_t)0x003FFFFF)) >> 0); +} + +__INLINE void ble_ral_local_rnd_lrnd_val_setf(uint32_t lrndval) +{ + ASSERT_ERR((((uint32_t)lrndval << 0) & ~((uint32_t)0x003FFFFF)) == 0); + REG_BLE_WR(BLE_RAL_LOCAL_RND_ADDR, (REG_BLE_RD(BLE_RAL_LOCAL_RND_ADDR) & ~((uint32_t)0x003FFFFF)) | ((uint32_t)lrndval << 0)); +} + +/** + * @brief RAL_PEER_RND register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31            PRND_INIT   0
+ *  21:00             PRND_VAL   0x30F0F0
+ * 
+ */ +#define BLE_RAL_PEER_RND_ADDR BASEBAND_REG_BASE +0x16C //0x5080016C +#define BLE_RAL_PEER_RND_OFFSET 0x0000016C +#define BLE_RAL_PEER_RND_INDEX 0x0000005B +#define BLE_RAL_PEER_RND_RESET 0x0030F0F0 + +__INLINE uint32_t ble_ral_peer_rnd_get(void) +{ + return REG_BLE_RD(BLE_RAL_PEER_RND_ADDR); +} + +__INLINE void ble_ral_peer_rnd_set(uint32_t value) +{ + REG_BLE_WR(BLE_RAL_PEER_RND_ADDR, value); +} + +// field definitions +#define BLE_PRND_INIT_BIT ((uint32_t)0x80000000) +#define BLE_PRND_INIT_POS 31 +#define BLE_PRND_VAL_MASK ((uint32_t)0x003FFFFF) +#define BLE_PRND_VAL_LSB 0 +#define BLE_PRND_VAL_WIDTH ((uint32_t)0x00000016) + +#define BLE_PRND_INIT_RST 0x0 +#define BLE_PRND_VAL_RST 0x30F0F0 + +__INLINE void ble_ral_peer_rnd_pack(uint8_t prndinit, uint32_t prndval) +{ + ASSERT_ERR((((uint32_t)prndinit << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)prndval << 0) & ~((uint32_t)0x003FFFFF)) == 0); + REG_BLE_WR(BLE_RAL_PEER_RND_ADDR, ((uint32_t)prndinit << 31) | ((uint32_t)prndval << 0)); +} + +__INLINE void ble_ral_peer_rnd_unpack(uint8_t* prndinit, uint32_t* prndval) +{ + uint32_t localVal = REG_BLE_RD(BLE_RAL_PEER_RND_ADDR); + + *prndinit = (localVal & ((uint32_t)0x80000000)) >> 31; + *prndval = (localVal & ((uint32_t)0x003FFFFF)) >> 0; +} + +__INLINE uint8_t ble_ral_peer_rnd_prnd_init_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RAL_PEER_RND_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ble_ral_peer_rnd_prnd_init_setf(uint8_t prndinit) +{ + ASSERT_ERR((((uint32_t)prndinit << 31) & ~((uint32_t)0x80000000)) == 0); + REG_BLE_WR(BLE_RAL_PEER_RND_ADDR, (REG_BLE_RD(BLE_RAL_PEER_RND_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)prndinit << 31)); +} + +__INLINE uint32_t ble_ral_peer_rnd_prnd_val_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_RAL_PEER_RND_ADDR); + return ((localVal & ((uint32_t)0x003FFFFF)) >> 0); +} + +__INLINE void ble_ral_peer_rnd_prnd_val_setf(uint32_t prndval) +{ + ASSERT_ERR((((uint32_t)prndval << 0) & ~((uint32_t)0x003FFFFF)) == 0); + REG_BLE_WR(BLE_RAL_PEER_RND_ADDR, (REG_BLE_RD(BLE_RAL_PEER_RND_ADDR) & ~((uint32_t)0x003FFFFF)) | ((uint32_t)prndval << 0)); +} + +/** + * @brief DFCNTL0_1US register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24    RXSAMPSTINST0_1US   0x0
+ *  23:16      RXSWSTINST0_1US   0x0
+ *  07:00      TXSWSTINST0_1US   0x0
+ * 
+ */ +#define BLE_DFCNTL0_1US_ADDR BASEBAND_REG_BASE +0x170 //0x50800170 +#define BLE_DFCNTL0_1US_OFFSET 0x00000170 +#define BLE_DFCNTL0_1US_INDEX 0x0000005C +#define BLE_DFCNTL0_1US_RESET 0x00000000 + +__INLINE uint32_t ble_dfcntl0_1us_get(void) +{ + return REG_BLE_RD(BLE_DFCNTL0_1US_ADDR); +} + +__INLINE void ble_dfcntl0_1us_set(uint32_t value) +{ + REG_BLE_WR(BLE_DFCNTL0_1US_ADDR, value); +} + +// field definitions +#define BLE_RXSAMPSTINST0_1US_MASK ((uint32_t)0xFF000000) +#define BLE_RXSAMPSTINST0_1US_LSB 24 +#define BLE_RXSAMPSTINST0_1US_WIDTH ((uint32_t)0x00000008) +#define BLE_RXSWSTINST0_1US_MASK ((uint32_t)0x00FF0000) +#define BLE_RXSWSTINST0_1US_LSB 16 +#define BLE_RXSWSTINST0_1US_WIDTH ((uint32_t)0x00000008) +#define BLE_TXSWSTINST0_1US_MASK ((uint32_t)0x000000FF) +#define BLE_TXSWSTINST0_1US_LSB 0 +#define BLE_TXSWSTINST0_1US_WIDTH ((uint32_t)0x00000008) + +#define BLE_RXSAMPSTINST0_1US_RST 0x0 +#define BLE_RXSWSTINST0_1US_RST 0x0 +#define BLE_TXSWSTINST0_1US_RST 0x0 + +__INLINE void ble_dfcntl0_1us_pack(uint8_t rxsampstinst01us, uint8_t rxswstinst01us, uint8_t txswstinst01us) +{ + ASSERT_ERR((((uint32_t)rxsampstinst01us << 24) & ~((uint32_t)0xFF000000)) == 0); + ASSERT_ERR((((uint32_t)rxswstinst01us << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)txswstinst01us << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_DFCNTL0_1US_ADDR, ((uint32_t)rxsampstinst01us << 24) | ((uint32_t)rxswstinst01us << 16) | ((uint32_t)txswstinst01us << 0)); +} + +__INLINE void ble_dfcntl0_1us_unpack(uint8_t* rxsampstinst01us, uint8_t* rxswstinst01us, uint8_t* txswstinst01us) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL0_1US_ADDR); + + *rxsampstinst01us = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rxswstinst01us = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *txswstinst01us = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_dfcntl0_1us_rxsampstinst0_1us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL0_1US_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE void ble_dfcntl0_1us_rxsampstinst0_1us_setf(uint8_t rxsampstinst01us) +{ + ASSERT_ERR((((uint32_t)rxsampstinst01us << 24) & ~((uint32_t)0xFF000000)) == 0); + REG_BLE_WR(BLE_DFCNTL0_1US_ADDR, (REG_BLE_RD(BLE_DFCNTL0_1US_ADDR) & ~((uint32_t)0xFF000000)) | ((uint32_t)rxsampstinst01us << 24)); +} + +__INLINE uint8_t ble_dfcntl0_1us_rxswstinst0_1us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL0_1US_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_dfcntl0_1us_rxswstinst0_1us_setf(uint8_t rxswstinst01us) +{ + ASSERT_ERR((((uint32_t)rxswstinst01us << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_DFCNTL0_1US_ADDR, (REG_BLE_RD(BLE_DFCNTL0_1US_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)rxswstinst01us << 16)); +} + +__INLINE uint8_t ble_dfcntl0_1us_txswstinst0_1us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL0_1US_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +__INLINE void ble_dfcntl0_1us_txswstinst0_1us_setf(uint8_t txswstinst01us) +{ + ASSERT_ERR((((uint32_t)txswstinst01us << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_DFCNTL0_1US_ADDR, (REG_BLE_RD(BLE_DFCNTL0_1US_ADDR) & ~((uint32_t)0x000000FF)) | ((uint32_t)txswstinst01us << 0)); +} + +/** + * @brief DFCNTL0_2US register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24    RXSAMPSTINST0_2US   0x0
+ *  23:16      RXSWSTINST0_2US   0x0
+ *  07:00      TXSWSTINST0_2US   0x0
+ * 
+ */ +#define BLE_DFCNTL0_2US_ADDR BASEBAND_REG_BASE +0x174 //0x50800174 +#define BLE_DFCNTL0_2US_OFFSET 0x00000174 +#define BLE_DFCNTL0_2US_INDEX 0x0000005D +#define BLE_DFCNTL0_2US_RESET 0x00000000 + +__INLINE uint32_t ble_dfcntl0_2us_get(void) +{ + return REG_BLE_RD(BLE_DFCNTL0_2US_ADDR); +} + +__INLINE void ble_dfcntl0_2us_set(uint32_t value) +{ + REG_BLE_WR(BLE_DFCNTL0_2US_ADDR, value); +} + +// field definitions +#define BLE_RXSAMPSTINST0_2US_MASK ((uint32_t)0xFF000000) +#define BLE_RXSAMPSTINST0_2US_LSB 24 +#define BLE_RXSAMPSTINST0_2US_WIDTH ((uint32_t)0x00000008) +#define BLE_RXSWSTINST0_2US_MASK ((uint32_t)0x00FF0000) +#define BLE_RXSWSTINST0_2US_LSB 16 +#define BLE_RXSWSTINST0_2US_WIDTH ((uint32_t)0x00000008) +#define BLE_TXSWSTINST0_2US_MASK ((uint32_t)0x000000FF) +#define BLE_TXSWSTINST0_2US_LSB 0 +#define BLE_TXSWSTINST0_2US_WIDTH ((uint32_t)0x00000008) + +#define BLE_RXSAMPSTINST0_2US_RST 0x0 +#define BLE_RXSWSTINST0_2US_RST 0x0 +#define BLE_TXSWSTINST0_2US_RST 0x0 + +__INLINE void ble_dfcntl0_2us_pack(uint8_t rxsampstinst02us, uint8_t rxswstinst02us, uint8_t txswstinst02us) +{ + ASSERT_ERR((((uint32_t)rxsampstinst02us << 24) & ~((uint32_t)0xFF000000)) == 0); + ASSERT_ERR((((uint32_t)rxswstinst02us << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)txswstinst02us << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_DFCNTL0_2US_ADDR, ((uint32_t)rxsampstinst02us << 24) | ((uint32_t)rxswstinst02us << 16) | ((uint32_t)txswstinst02us << 0)); +} + +__INLINE void ble_dfcntl0_2us_unpack(uint8_t* rxsampstinst02us, uint8_t* rxswstinst02us, uint8_t* txswstinst02us) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL0_2US_ADDR); + + *rxsampstinst02us = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rxswstinst02us = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *txswstinst02us = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_dfcntl0_2us_rxsampstinst0_2us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL0_2US_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE void ble_dfcntl0_2us_rxsampstinst0_2us_setf(uint8_t rxsampstinst02us) +{ + ASSERT_ERR((((uint32_t)rxsampstinst02us << 24) & ~((uint32_t)0xFF000000)) == 0); + REG_BLE_WR(BLE_DFCNTL0_2US_ADDR, (REG_BLE_RD(BLE_DFCNTL0_2US_ADDR) & ~((uint32_t)0xFF000000)) | ((uint32_t)rxsampstinst02us << 24)); +} + +__INLINE uint8_t ble_dfcntl0_2us_rxswstinst0_2us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL0_2US_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_dfcntl0_2us_rxswstinst0_2us_setf(uint8_t rxswstinst02us) +{ + ASSERT_ERR((((uint32_t)rxswstinst02us << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_DFCNTL0_2US_ADDR, (REG_BLE_RD(BLE_DFCNTL0_2US_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)rxswstinst02us << 16)); +} + +__INLINE uint8_t ble_dfcntl0_2us_txswstinst0_2us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL0_2US_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +__INLINE void ble_dfcntl0_2us_txswstinst0_2us_setf(uint8_t txswstinst02us) +{ + ASSERT_ERR((((uint32_t)txswstinst02us << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_DFCNTL0_2US_ADDR, (REG_BLE_RD(BLE_DFCNTL0_2US_ADDR) & ~((uint32_t)0x000000FF)) | ((uint32_t)txswstinst02us << 0)); +} + +/** + * @brief DFCNTL1_1US register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24    RXSAMPSTINST1_1US   0x0
+ *  23:16      RXSWSTINST1_1US   0x0
+ *  07:00      TXSWSTINST1_1US   0x0
+ * 
+ */ +#define BLE_DFCNTL1_1US_ADDR BASEBAND_REG_BASE +0x178 //0x50800178 +#define BLE_DFCNTL1_1US_OFFSET 0x00000178 +#define BLE_DFCNTL1_1US_INDEX 0x0000005E +#define BLE_DFCNTL1_1US_RESET 0x00000000 + +__INLINE uint32_t ble_dfcntl1_1us_get(void) +{ + return REG_BLE_RD(BLE_DFCNTL1_1US_ADDR); +} + +__INLINE void ble_dfcntl1_1us_set(uint32_t value) +{ + REG_BLE_WR(BLE_DFCNTL1_1US_ADDR, value); +} + +// field definitions +#define BLE_RXSAMPSTINST1_1US_MASK ((uint32_t)0xFF000000) +#define BLE_RXSAMPSTINST1_1US_LSB 24 +#define BLE_RXSAMPSTINST1_1US_WIDTH ((uint32_t)0x00000008) +#define BLE_RXSWSTINST1_1US_MASK ((uint32_t)0x00FF0000) +#define BLE_RXSWSTINST1_1US_LSB 16 +#define BLE_RXSWSTINST1_1US_WIDTH ((uint32_t)0x00000008) +#define BLE_TXSWSTINST1_1US_MASK ((uint32_t)0x000000FF) +#define BLE_TXSWSTINST1_1US_LSB 0 +#define BLE_TXSWSTINST1_1US_WIDTH ((uint32_t)0x00000008) + +#define BLE_RXSAMPSTINST1_1US_RST 0x0 +#define BLE_RXSWSTINST1_1US_RST 0x0 +#define BLE_TXSWSTINST1_1US_RST 0x0 + +__INLINE void ble_dfcntl1_1us_pack(uint8_t rxsampstinst11us, uint8_t rxswstinst11us, uint8_t txswstinst11us) +{ + ASSERT_ERR((((uint32_t)rxsampstinst11us << 24) & ~((uint32_t)0xFF000000)) == 0); + ASSERT_ERR((((uint32_t)rxswstinst11us << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)txswstinst11us << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_DFCNTL1_1US_ADDR, ((uint32_t)rxsampstinst11us << 24) | ((uint32_t)rxswstinst11us << 16) | ((uint32_t)txswstinst11us << 0)); +} + +__INLINE void ble_dfcntl1_1us_unpack(uint8_t* rxsampstinst11us, uint8_t* rxswstinst11us, uint8_t* txswstinst11us) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL1_1US_ADDR); + + *rxsampstinst11us = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rxswstinst11us = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *txswstinst11us = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_dfcntl1_1us_rxsampstinst1_1us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL1_1US_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE void ble_dfcntl1_1us_rxsampstinst1_1us_setf(uint8_t rxsampstinst11us) +{ + ASSERT_ERR((((uint32_t)rxsampstinst11us << 24) & ~((uint32_t)0xFF000000)) == 0); + REG_BLE_WR(BLE_DFCNTL1_1US_ADDR, (REG_BLE_RD(BLE_DFCNTL1_1US_ADDR) & ~((uint32_t)0xFF000000)) | ((uint32_t)rxsampstinst11us << 24)); +} + +__INLINE uint8_t ble_dfcntl1_1us_rxswstinst1_1us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL1_1US_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_dfcntl1_1us_rxswstinst1_1us_setf(uint8_t rxswstinst11us) +{ + ASSERT_ERR((((uint32_t)rxswstinst11us << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_DFCNTL1_1US_ADDR, (REG_BLE_RD(BLE_DFCNTL1_1US_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)rxswstinst11us << 16)); +} + +__INLINE uint8_t ble_dfcntl1_1us_txswstinst1_1us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL1_1US_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +__INLINE void ble_dfcntl1_1us_txswstinst1_1us_setf(uint8_t txswstinst11us) +{ + ASSERT_ERR((((uint32_t)txswstinst11us << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_DFCNTL1_1US_ADDR, (REG_BLE_RD(BLE_DFCNTL1_1US_ADDR) & ~((uint32_t)0x000000FF)) | ((uint32_t)txswstinst11us << 0)); +} + +/** + * @brief DFCNTL1_2US register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24    RXSAMPSTINST1_2US   0x0
+ *  23:16      RXSWSTINST1_2US   0x0
+ *  07:00      TXSWSTINST1_2US   0x0
+ * 
+ */ +#define BLE_DFCNTL1_2US_ADDR BASEBAND_REG_BASE +0x17C // 0x5080017C +#define BLE_DFCNTL1_2US_OFFSET 0x0000017C +#define BLE_DFCNTL1_2US_INDEX 0x0000005F +#define BLE_DFCNTL1_2US_RESET 0x00000000 + +__INLINE uint32_t ble_dfcntl1_2us_get(void) +{ + return REG_BLE_RD(BLE_DFCNTL1_2US_ADDR); +} + +__INLINE void ble_dfcntl1_2us_set(uint32_t value) +{ + REG_BLE_WR(BLE_DFCNTL1_2US_ADDR, value); +} + +// field definitions +#define BLE_RXSAMPSTINST1_2US_MASK ((uint32_t)0xFF000000) +#define BLE_RXSAMPSTINST1_2US_LSB 24 +#define BLE_RXSAMPSTINST1_2US_WIDTH ((uint32_t)0x00000008) +#define BLE_RXSWSTINST1_2US_MASK ((uint32_t)0x00FF0000) +#define BLE_RXSWSTINST1_2US_LSB 16 +#define BLE_RXSWSTINST1_2US_WIDTH ((uint32_t)0x00000008) +#define BLE_TXSWSTINST1_2US_MASK ((uint32_t)0x000000FF) +#define BLE_TXSWSTINST1_2US_LSB 0 +#define BLE_TXSWSTINST1_2US_WIDTH ((uint32_t)0x00000008) + +#define BLE_RXSAMPSTINST1_2US_RST 0x0 +#define BLE_RXSWSTINST1_2US_RST 0x0 +#define BLE_TXSWSTINST1_2US_RST 0x0 + +__INLINE void ble_dfcntl1_2us_pack(uint8_t rxsampstinst12us, uint8_t rxswstinst12us, uint8_t txswstinst12us) +{ + ASSERT_ERR((((uint32_t)rxsampstinst12us << 24) & ~((uint32_t)0xFF000000)) == 0); + ASSERT_ERR((((uint32_t)rxswstinst12us << 16) & ~((uint32_t)0x00FF0000)) == 0); + ASSERT_ERR((((uint32_t)txswstinst12us << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_DFCNTL1_2US_ADDR, ((uint32_t)rxsampstinst12us << 24) | ((uint32_t)rxswstinst12us << 16) | ((uint32_t)txswstinst12us << 0)); +} + +__INLINE void ble_dfcntl1_2us_unpack(uint8_t* rxsampstinst12us, uint8_t* rxswstinst12us, uint8_t* txswstinst12us) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL1_2US_ADDR); + + *rxsampstinst12us = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rxswstinst12us = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *txswstinst12us = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ble_dfcntl1_2us_rxsampstinst1_2us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL1_2US_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE void ble_dfcntl1_2us_rxsampstinst1_2us_setf(uint8_t rxsampstinst12us) +{ + ASSERT_ERR((((uint32_t)rxsampstinst12us << 24) & ~((uint32_t)0xFF000000)) == 0); + REG_BLE_WR(BLE_DFCNTL1_2US_ADDR, (REG_BLE_RD(BLE_DFCNTL1_2US_ADDR) & ~((uint32_t)0xFF000000)) | ((uint32_t)rxsampstinst12us << 24)); +} + +__INLINE uint8_t ble_dfcntl1_2us_rxswstinst1_2us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL1_2US_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE void ble_dfcntl1_2us_rxswstinst1_2us_setf(uint8_t rxswstinst12us) +{ + ASSERT_ERR((((uint32_t)rxswstinst12us << 16) & ~((uint32_t)0x00FF0000)) == 0); + REG_BLE_WR(BLE_DFCNTL1_2US_ADDR, (REG_BLE_RD(BLE_DFCNTL1_2US_ADDR) & ~((uint32_t)0x00FF0000)) | ((uint32_t)rxswstinst12us << 16)); +} + +__INLINE uint8_t ble_dfcntl1_2us_txswstinst1_2us_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCNTL1_2US_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +__INLINE void ble_dfcntl1_2us_txswstinst1_2us_setf(uint8_t txswstinst12us) +{ + ASSERT_ERR((((uint32_t)txswstinst12us << 0) & ~((uint32_t)0x000000FF)) == 0); + REG_BLE_WR(BLE_DFCNTL1_2US_ADDR, (REG_BLE_RD(BLE_DFCNTL1_2US_ADDR) & ~((uint32_t)0x000000FF)) | ((uint32_t)txswstinst12us << 0)); +} + +/** + * @brief DFCURRENTPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00         DFCURRENTPTR   0x0
+ * 
+ */ +#define BLE_DFCURRENTPTR_ADDR BASEBAND_REG_BASE +0x180 //0x50800180 +#define BLE_DFCURRENTPTR_OFFSET 0x00000180 +#define BLE_DFCURRENTPTR_INDEX 0x00000060 +#define BLE_DFCURRENTPTR_RESET 0x00000000 + +__INLINE uint32_t ble_dfcurrentptr_get(void) +{ + return REG_BLE_RD(BLE_DFCURRENTPTR_ADDR); +} + +__INLINE void ble_dfcurrentptr_set(uint32_t value) +{ + REG_BLE_WR(BLE_DFCURRENTPTR_ADDR, value); +} + +// field definitions +#define BLE_DFCURRENTPTR_MASK ((uint32_t)0x00003FFF) +#define BLE_DFCURRENTPTR_LSB 0 +#define BLE_DFCURRENTPTR_WIDTH ((uint32_t)0x0000000E) + +#define BLE_DFCURRENTPTR_RST 0x0 + +__INLINE uint16_t ble_dfcurrentptr_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFCURRENTPTR_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ble_dfcurrentptr_setf(uint16_t dfcurrentptr) +{ + ASSERT_ERR((((uint32_t)dfcurrentptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_BLE_WR(BLE_DFCURRENTPTR_ADDR, (uint32_t)dfcurrentptr << 0); +} + +/** + * @brief DFANTCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15       RXPRIMIDCNTLEN   0
+ *  14:08          RXPRIMANTID   0x0
+ *     07       TXPRIMIDCNTLEN   0
+ *  06:00          TXPRIMANTID   0x0
+ * 
+ */ +#define BLE_DFANTCNTL_ADDR BASEBAND_REG_BASE +0x184 //0x50800184 +#define BLE_DFANTCNTL_OFFSET 0x00000184 +#define BLE_DFANTCNTL_INDEX 0x00000061 +#define BLE_DFANTCNTL_RESET 0x00000000 + +__INLINE uint32_t ble_dfantcntl_get(void) +{ + return REG_BLE_RD(BLE_DFANTCNTL_ADDR); +} + +__INLINE void ble_dfantcntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_DFANTCNTL_ADDR, value); +} + +// field definitions +#define BLE_RXPRIMIDCNTLEN_BIT ((uint32_t)0x00008000) +#define BLE_RXPRIMIDCNTLEN_POS 15 +#define BLE_RXPRIMANTID_MASK ((uint32_t)0x00007F00) +#define BLE_RXPRIMANTID_LSB 8 +#define BLE_RXPRIMANTID_WIDTH ((uint32_t)0x00000007) +#define BLE_TXPRIMIDCNTLEN_BIT ((uint32_t)0x00000080) +#define BLE_TXPRIMIDCNTLEN_POS 7 +#define BLE_TXPRIMANTID_MASK ((uint32_t)0x0000007F) +#define BLE_TXPRIMANTID_LSB 0 +#define BLE_TXPRIMANTID_WIDTH ((uint32_t)0x00000007) + +#define BLE_RXPRIMIDCNTLEN_RST 0x0 +#define BLE_RXPRIMANTID_RST 0x0 +#define BLE_TXPRIMIDCNTLEN_RST 0x0 +#define BLE_TXPRIMANTID_RST 0x0 + +__INLINE void ble_dfantcntl_pack(uint8_t rxprimidcntlen, uint8_t rxprimantid, uint8_t txprimidcntlen, uint8_t txprimantid) +{ + ASSERT_ERR((((uint32_t)rxprimidcntlen << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)rxprimantid << 8) & ~((uint32_t)0x00007F00)) == 0); + ASSERT_ERR((((uint32_t)txprimidcntlen << 7) & ~((uint32_t)0x00000080)) == 0); + ASSERT_ERR((((uint32_t)txprimantid << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_DFANTCNTL_ADDR, ((uint32_t)rxprimidcntlen << 15) | ((uint32_t)rxprimantid << 8) | ((uint32_t)txprimidcntlen << 7) | ((uint32_t)txprimantid << 0)); +} + +__INLINE void ble_dfantcntl_unpack(uint8_t* rxprimidcntlen, uint8_t* rxprimantid, uint8_t* txprimidcntlen, uint8_t* txprimantid) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFANTCNTL_ADDR); + + *rxprimidcntlen = (localVal & ((uint32_t)0x00008000)) >> 15; + *rxprimantid = (localVal & ((uint32_t)0x00007F00)) >> 8; + *txprimidcntlen = (localVal & ((uint32_t)0x00000080)) >> 7; + *txprimantid = (localVal & ((uint32_t)0x0000007F)) >> 0; +} + +__INLINE uint8_t ble_dfantcntl_rxprimidcntlen_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFANTCNTL_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ble_dfantcntl_rxprimidcntlen_setf(uint8_t rxprimidcntlen) +{ + ASSERT_ERR((((uint32_t)rxprimidcntlen << 15) & ~((uint32_t)0x00008000)) == 0); + REG_BLE_WR(BLE_DFANTCNTL_ADDR, (REG_BLE_RD(BLE_DFANTCNTL_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)rxprimidcntlen << 15)); +} + +__INLINE uint8_t ble_dfantcntl_rxprimantid_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFANTCNTL_ADDR); + return ((localVal & ((uint32_t)0x00007F00)) >> 8); +} + +__INLINE void ble_dfantcntl_rxprimantid_setf(uint8_t rxprimantid) +{ + ASSERT_ERR((((uint32_t)rxprimantid << 8) & ~((uint32_t)0x00007F00)) == 0); + REG_BLE_WR(BLE_DFANTCNTL_ADDR, (REG_BLE_RD(BLE_DFANTCNTL_ADDR) & ~((uint32_t)0x00007F00)) | ((uint32_t)rxprimantid << 8)); +} + +__INLINE uint8_t ble_dfantcntl_txprimidcntlen_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFANTCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE void ble_dfantcntl_txprimidcntlen_setf(uint8_t txprimidcntlen) +{ + ASSERT_ERR((((uint32_t)txprimidcntlen << 7) & ~((uint32_t)0x00000080)) == 0); + REG_BLE_WR(BLE_DFANTCNTL_ADDR, (REG_BLE_RD(BLE_DFANTCNTL_ADDR) & ~((uint32_t)0x00000080)) | ((uint32_t)txprimidcntlen << 7)); +} + +__INLINE uint8_t ble_dfantcntl_txprimantid_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFANTCNTL_ADDR); + return ((localVal & ((uint32_t)0x0000007F)) >> 0); +} + +__INLINE void ble_dfantcntl_txprimantid_setf(uint8_t txprimantid) +{ + ASSERT_ERR((((uint32_t)txprimantid << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_BLE_WR(BLE_DFANTCNTL_ADDR, (REG_BLE_RD(BLE_DFANTCNTL_ADDR) & ~((uint32_t)0x0000007F)) | ((uint32_t)txprimantid << 0)); +} + +/** + * @brief DFIFCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     07        ANTSWITCH_BEH   0
+ *     06          SAMPREQ_BEH   0
+ *  05:04        SAMPVALID_BEH   0x0
+ *  03:02             IF_WIDTH   0x3
+ *     01        MSB_LSB_ORDER   0
+ *     00         SYMBOL_ORDER   0
+ * 
+ */ +#define BLE_DFIFCNTL_ADDR BASEBAND_REG_BASE +0x188 //0x50800188 +#define BLE_DFIFCNTL_OFFSET 0x00000188 +#define BLE_DFIFCNTL_INDEX 0x00000062 +#define BLE_DFIFCNTL_RESET 0x0000000C + +__INLINE uint32_t ble_dfifcntl_get(void) +{ + return REG_BLE_RD(BLE_DFIFCNTL_ADDR); +} + +__INLINE void ble_dfifcntl_set(uint32_t value) +{ + REG_BLE_WR(BLE_DFIFCNTL_ADDR, value); +} + +// field definitions +#define BLE_ANTSWITCH_BEH_BIT ((uint32_t)0x00000080) +#define BLE_ANTSWITCH_BEH_POS 7 +#define BLE_SAMPREQ_BEH_BIT ((uint32_t)0x00000040) +#define BLE_SAMPREQ_BEH_POS 6 +#define BLE_SAMPVALID_BEH_MASK ((uint32_t)0x00000030) +#define BLE_SAMPVALID_BEH_LSB 4 +#define BLE_SAMPVALID_BEH_WIDTH ((uint32_t)0x00000002) +#define BLE_IF_WIDTH_MASK ((uint32_t)0x0000000C) +#define BLE_IF_WIDTH_LSB 2 +#define BLE_IF_WIDTH_WIDTH ((uint32_t)0x00000002) +#define BLE_MSB_LSB_ORDER_BIT ((uint32_t)0x00000002) +#define BLE_MSB_LSB_ORDER_POS 1 +#define BLE_SYMBOL_ORDER_BIT ((uint32_t)0x00000001) +#define BLE_SYMBOL_ORDER_POS 0 + +#define BLE_ANTSWITCH_BEH_RST 0x0 +#define BLE_SAMPREQ_BEH_RST 0x0 +#define BLE_SAMPVALID_BEH_RST 0x0 +#define BLE_IF_WIDTH_RST 0x3 +#define BLE_MSB_LSB_ORDER_RST 0x0 +#define BLE_SYMBOL_ORDER_RST 0x0 + +__INLINE void ble_dfifcntl_pack(uint8_t antswitchbeh, uint8_t sampreqbeh, uint8_t sampvalidbeh, uint8_t ifwidth, uint8_t msblsborder, uint8_t symbolorder) +{ + ASSERT_ERR((((uint32_t)antswitchbeh << 7) & ~((uint32_t)0x00000080)) == 0); + ASSERT_ERR((((uint32_t)sampreqbeh << 6) & ~((uint32_t)0x00000040)) == 0); + ASSERT_ERR((((uint32_t)sampvalidbeh << 4) & ~((uint32_t)0x00000030)) == 0); + ASSERT_ERR((((uint32_t)ifwidth << 2) & ~((uint32_t)0x0000000C)) == 0); + ASSERT_ERR((((uint32_t)msblsborder << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)symbolorder << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_DFIFCNTL_ADDR, ((uint32_t)antswitchbeh << 7) | ((uint32_t)sampreqbeh << 6) | ((uint32_t)sampvalidbeh << 4) | ((uint32_t)ifwidth << 2) | ((uint32_t)msblsborder << 1) | ((uint32_t)symbolorder << 0)); +} + +__INLINE void ble_dfifcntl_unpack(uint8_t* antswitchbeh, uint8_t* sampreqbeh, uint8_t* sampvalidbeh, uint8_t* ifwidth, uint8_t* msblsborder, uint8_t* symbolorder) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFIFCNTL_ADDR); + + *antswitchbeh = (localVal & ((uint32_t)0x00000080)) >> 7; + *sampreqbeh = (localVal & ((uint32_t)0x00000040)) >> 6; + *sampvalidbeh = (localVal & ((uint32_t)0x00000030)) >> 4; + *ifwidth = (localVal & ((uint32_t)0x0000000C)) >> 2; + *msblsborder = (localVal & ((uint32_t)0x00000002)) >> 1; + *symbolorder = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ble_dfifcntl_antswitch_beh_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFIFCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE void ble_dfifcntl_antswitch_beh_setf(uint8_t antswitchbeh) +{ + ASSERT_ERR((((uint32_t)antswitchbeh << 7) & ~((uint32_t)0x00000080)) == 0); + REG_BLE_WR(BLE_DFIFCNTL_ADDR, (REG_BLE_RD(BLE_DFIFCNTL_ADDR) & ~((uint32_t)0x00000080)) | ((uint32_t)antswitchbeh << 7)); +} + +__INLINE uint8_t ble_dfifcntl_sampreq_beh_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFIFCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE void ble_dfifcntl_sampreq_beh_setf(uint8_t sampreqbeh) +{ + ASSERT_ERR((((uint32_t)sampreqbeh << 6) & ~((uint32_t)0x00000040)) == 0); + REG_BLE_WR(BLE_DFIFCNTL_ADDR, (REG_BLE_RD(BLE_DFIFCNTL_ADDR) & ~((uint32_t)0x00000040)) | ((uint32_t)sampreqbeh << 6)); +} + +__INLINE uint8_t ble_dfifcntl_sampvalid_beh_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFIFCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000030)) >> 4); +} + +__INLINE void ble_dfifcntl_sampvalid_beh_setf(uint8_t sampvalidbeh) +{ + ASSERT_ERR((((uint32_t)sampvalidbeh << 4) & ~((uint32_t)0x00000030)) == 0); + REG_BLE_WR(BLE_DFIFCNTL_ADDR, (REG_BLE_RD(BLE_DFIFCNTL_ADDR) & ~((uint32_t)0x00000030)) | ((uint32_t)sampvalidbeh << 4)); +} + +__INLINE uint8_t ble_dfifcntl_if_width_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFIFCNTL_ADDR); + return ((localVal & ((uint32_t)0x0000000C)) >> 2); +} + +__INLINE void ble_dfifcntl_if_width_setf(uint8_t ifwidth) +{ + ASSERT_ERR((((uint32_t)ifwidth << 2) & ~((uint32_t)0x0000000C)) == 0); + REG_BLE_WR(BLE_DFIFCNTL_ADDR, (REG_BLE_RD(BLE_DFIFCNTL_ADDR) & ~((uint32_t)0x0000000C)) | ((uint32_t)ifwidth << 2)); +} + +__INLINE uint8_t ble_dfifcntl_msb_lsb_order_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFIFCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ble_dfifcntl_msb_lsb_order_setf(uint8_t msblsborder) +{ + ASSERT_ERR((((uint32_t)msblsborder << 1) & ~((uint32_t)0x00000002)) == 0); + REG_BLE_WR(BLE_DFIFCNTL_ADDR, (REG_BLE_RD(BLE_DFIFCNTL_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)msblsborder << 1)); +} + +__INLINE uint8_t ble_dfifcntl_symbol_order_getf(void) +{ + uint32_t localVal = REG_BLE_RD(BLE_DFIFCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ble_dfifcntl_symbol_order_setf(uint8_t symbolorder) +{ + ASSERT_ERR((((uint32_t)symbolorder << 0) & ~((uint32_t)0x00000001)) == 0); + REG_BLE_WR(BLE_DFIFCNTL_ADDR, (REG_BLE_RD(BLE_DFIFCNTL_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)symbolorder << 0)); +} + + +#endif // _REG_BLECORE_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_cs.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_cs.h new file mode 100644 index 0000000..b7f531f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_cs.h @@ -0,0 +1,3796 @@ +#ifndef _REG_EM_BLE_CS_H_ +#define _REG_EM_BLE_CS_H_ + +#include +#include "_reg_em_ble_cs.h" +#include "compiler.h" +#include "arch.h" +#include "em_map.h" +#include "reg_access.h" +#include "co_utils.h" + +#define REG_EM_BLE_CS_COUNT 56 + +#define REG_EM_BLE_CS_DECODING_MASK 0x0000007F + +#define REG_EM_BLE_CS_ADDR_GET(idx) (EM_BLE_CS_OFFSET + (idx) * REG_EM_BLE_CS_SIZE) + +/** + * @brief CNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     10             TXBSY_EN   0
+ *     09             RXBSY_EN   0
+ *     08              DNABORT   0
+ *  04:00               FORMAT   0x0
+ * 
+ */ +#define EM_BLE_CNTL_ADDR (EXCHANGE_MEM_BASE + EM_BLE_CS_OFFSET) +#define EM_BLE_CNTL_INDEX 0x00000000 +#define EM_BLE_CNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_cntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_cntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_TXBSY_EN_BIT ((uint16_t)0x00000400) +#define EM_BLE_TXBSY_EN_POS 10 +#define EM_BLE_RXBSY_EN_BIT ((uint16_t)0x00000200) +#define EM_BLE_RXBSY_EN_POS 9 +#define EM_BLE_DNABORT_BIT ((uint16_t)0x00000100) +#define EM_BLE_DNABORT_POS 8 +#define EM_BLE_FORMAT_MASK ((uint16_t)0x0000001F) +#define EM_BLE_FORMAT_LSB 0 +#define EM_BLE_FORMAT_WIDTH ((uint16_t)0x00000005) + +#define EM_BLE_TXBSY_EN_RST 0x0 +#define EM_BLE_RXBSY_EN_RST 0x0 +#define EM_BLE_DNABORT_RST 0x0 +#define EM_BLE_FORMAT_RST 0x0 + +__INLINE void em_ble_cntl_pack(int elt_idx, uint8_t txbsyen, uint8_t rxbsyen, uint8_t dnabort, uint8_t format) +{ + ASSERT_ERR((((uint16_t)txbsyen << 10) & ~((uint16_t)0x00000400)) == 0); + ASSERT_ERR((((uint16_t)rxbsyen << 9) & ~((uint16_t)0x00000200)) == 0); + ASSERT_ERR((((uint16_t)dnabort << 8) & ~((uint16_t)0x00000100)) == 0); + ASSERT_ERR((((uint16_t)format << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_BLE_WR(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)txbsyen << 10) | ((uint16_t)rxbsyen << 9) | ((uint16_t)dnabort << 8) | ((uint16_t)format << 0)); +} + +__INLINE void em_ble_cntl_unpack(int elt_idx, uint8_t* txbsyen, uint8_t* rxbsyen, uint8_t* dnabort, uint8_t* format) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *txbsyen = (localVal & ((uint16_t)0x00000400)) >> 10; + *rxbsyen = (localVal & ((uint16_t)0x00000200)) >> 9; + *dnabort = (localVal & ((uint16_t)0x00000100)) >> 8; + *format = (localVal & ((uint16_t)0x0000001F)) >> 0; +} + +__INLINE uint8_t em_ble_cntl_txbsy_en_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000400)) >> 10); +} + +__INLINE void em_ble_cntl_txbsy_en_setf(int elt_idx, uint8_t txbsyen) +{ + ASSERT_ERR((((uint16_t)txbsyen << 10) & ~((uint16_t)0x00000400)) == 0); + EM_BLE_WR(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000400)) | ((uint16_t)txbsyen << 10)); +} + +__INLINE uint8_t em_ble_cntl_rxbsy_en_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000200)) >> 9); +} + +__INLINE void em_ble_cntl_rxbsy_en_setf(int elt_idx, uint8_t rxbsyen) +{ + ASSERT_ERR((((uint16_t)rxbsyen << 9) & ~((uint16_t)0x00000200)) == 0); + EM_BLE_WR(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000200)) | ((uint16_t)rxbsyen << 9)); +} + +__INLINE uint8_t em_ble_cntl_dnabort_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000100)) >> 8); +} + +__INLINE void em_ble_cntl_dnabort_setf(int elt_idx, uint8_t dnabort) +{ + ASSERT_ERR((((uint16_t)dnabort << 8) & ~((uint16_t)0x00000100)) == 0); + EM_BLE_WR(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000100)) | ((uint16_t)dnabort << 8)); +} + +__INLINE uint8_t em_ble_cntl_format_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000001F)) >> 0); +} + +__INLINE void em_ble_cntl_format_setf(int elt_idx, uint8_t format) +{ + ASSERT_ERR((((uint16_t)format << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_BLE_WR(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_CNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000001F)) | ((uint16_t)format << 0)); +} + +/** + * @brief LINKCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  12:08              LINKLBL   0x0
+ *     06                  SAS   0
+ *     05        NULLRXLLIDFLT   0
+ *     04             MIC_MODE   0
+ *     03           CRYPT_MODE   0
+ *     02           TXCRYPT_EN   0
+ *     01           RXCRYPT_EN   0
+ *     00            PRIV_NPUB   0
+ * 
+ */ +#define EM_BLE_LINKCNTL_ADDR (EXCHANGE_MEM_BASE+0x02 + EM_BLE_CS_OFFSET) +#define EM_BLE_LINKCNTL_INDEX 0x00000001 +#define EM_BLE_LINKCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_linkcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_linkcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_LINKLBL_MASK ((uint16_t)0x00001F00) +#define EM_BLE_LINKLBL_LSB 8 +#define EM_BLE_LINKLBL_WIDTH ((uint16_t)0x00000005) +#define EM_BLE_SAS_BIT ((uint16_t)0x00000040) +#define EM_BLE_SAS_POS 6 +#define EM_BLE_NULLRXLLIDFLT_BIT ((uint16_t)0x00000020) +#define EM_BLE_NULLRXLLIDFLT_POS 5 +#define EM_BLE_MIC_MODE_BIT ((uint16_t)0x00000010) +#define EM_BLE_MIC_MODE_POS 4 +#define EM_BLE_CRYPT_MODE_BIT ((uint16_t)0x00000008) +#define EM_BLE_CRYPT_MODE_POS 3 +#define EM_BLE_TXCRYPT_EN_BIT ((uint16_t)0x00000004) +#define EM_BLE_TXCRYPT_EN_POS 2 +#define EM_BLE_RXCRYPT_EN_BIT ((uint16_t)0x00000002) +#define EM_BLE_RXCRYPT_EN_POS 1 +#define EM_BLE_PRIV_NPUB_BIT ((uint16_t)0x00000001) +#define EM_BLE_PRIV_NPUB_POS 0 + +#define EM_BLE_LINKLBL_RST 0x0 +#define EM_BLE_SAS_RST 0x0 +#define EM_BLE_NULLRXLLIDFLT_RST 0x0 +#define EM_BLE_MIC_MODE_RST 0x0 +#define EM_BLE_CRYPT_MODE_RST 0x0 +#define EM_BLE_TXCRYPT_EN_RST 0x0 +#define EM_BLE_RXCRYPT_EN_RST 0x0 +#define EM_BLE_PRIV_NPUB_RST 0x0 + +__INLINE void em_ble_linkcntl_pack(int elt_idx, uint8_t linklbl, uint8_t sas, uint8_t nullrxllidflt, uint8_t micmode, uint8_t cryptmode, uint8_t txcrypten, uint8_t rxcrypten, uint8_t privnpub) +{ + ASSERT_ERR((((uint16_t)linklbl << 8) & ~((uint16_t)0x00001F00)) == 0); + ASSERT_ERR((((uint16_t)sas << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)nullrxllidflt << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)micmode << 4) & ~((uint16_t)0x00000010)) == 0); + ASSERT_ERR((((uint16_t)cryptmode << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)txcrypten << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)rxcrypten << 1) & ~((uint16_t)0x00000002)) == 0); + ASSERT_ERR((((uint16_t)privnpub << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)linklbl << 8) | ((uint16_t)sas << 6) | ((uint16_t)nullrxllidflt << 5) | ((uint16_t)micmode << 4) | ((uint16_t)cryptmode << 3) | ((uint16_t)txcrypten << 2) | ((uint16_t)rxcrypten << 1) | ((uint16_t)privnpub << 0)); +} + +__INLINE void em_ble_linkcntl_unpack(int elt_idx, uint8_t* linklbl, uint8_t* sas, uint8_t* nullrxllidflt, uint8_t* micmode, uint8_t* cryptmode, uint8_t* txcrypten, uint8_t* rxcrypten, uint8_t* privnpub) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *linklbl = (localVal & ((uint16_t)0x00001F00)) >> 8; + *sas = (localVal & ((uint16_t)0x00000040)) >> 6; + *nullrxllidflt = (localVal & ((uint16_t)0x00000020)) >> 5; + *micmode = (localVal & ((uint16_t)0x00000010)) >> 4; + *cryptmode = (localVal & ((uint16_t)0x00000008)) >> 3; + *txcrypten = (localVal & ((uint16_t)0x00000004)) >> 2; + *rxcrypten = (localVal & ((uint16_t)0x00000002)) >> 1; + *privnpub = (localVal & ((uint16_t)0x00000001)) >> 0; +} + +__INLINE uint8_t em_ble_linkcntl_linklbl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00001F00)) >> 8); +} + +__INLINE void em_ble_linkcntl_linklbl_setf(int elt_idx, uint8_t linklbl) +{ + ASSERT_ERR((((uint16_t)linklbl << 8) & ~((uint16_t)0x00001F00)) == 0); + EM_BLE_WR(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00001F00)) | ((uint16_t)linklbl << 8)); +} + +__INLINE uint8_t em_ble_linkcntl_sas_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_ble_linkcntl_sas_setf(int elt_idx, uint8_t sas) +{ + ASSERT_ERR((((uint16_t)sas << 6) & ~((uint16_t)0x00000040)) == 0); + EM_BLE_WR(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)sas << 6)); +} + +__INLINE uint8_t em_ble_linkcntl_nullrxllidflt_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_linkcntl_nullrxllidflt_setf(int elt_idx, uint8_t nullrxllidflt) +{ + ASSERT_ERR((((uint16_t)nullrxllidflt << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)nullrxllidflt << 5)); +} + +__INLINE uint8_t em_ble_linkcntl_mic_mode_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000010)) >> 4); +} + +__INLINE void em_ble_linkcntl_mic_mode_setf(int elt_idx, uint8_t micmode) +{ + ASSERT_ERR((((uint16_t)micmode << 4) & ~((uint16_t)0x00000010)) == 0); + EM_BLE_WR(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000010)) | ((uint16_t)micmode << 4)); +} + +__INLINE uint8_t em_ble_linkcntl_crypt_mode_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_linkcntl_crypt_mode_setf(int elt_idx, uint8_t cryptmode) +{ + ASSERT_ERR((((uint16_t)cryptmode << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)cryptmode << 3)); +} + +__INLINE uint8_t em_ble_linkcntl_txcrypt_en_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_linkcntl_txcrypt_en_setf(int elt_idx, uint8_t txcrypten) +{ + ASSERT_ERR((((uint16_t)txcrypten << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)txcrypten << 2)); +} + +__INLINE uint8_t em_ble_linkcntl_rxcrypt_en_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000002)) >> 1); +} + +__INLINE void em_ble_linkcntl_rxcrypt_en_setf(int elt_idx, uint8_t rxcrypten) +{ + ASSERT_ERR((((uint16_t)rxcrypten << 1) & ~((uint16_t)0x00000002)) == 0); + EM_BLE_WR(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000002)) | ((uint16_t)rxcrypten << 1)); +} + +__INLINE uint8_t em_ble_linkcntl_priv_npub_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000001)) >> 0); +} + +__INLINE void em_ble_linkcntl_priv_npub_setf(int elt_idx, uint8_t privnpub) +{ + ASSERT_ERR((((uint16_t)privnpub << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_LINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000001)) | ((uint16_t)privnpub << 0)); +} + +/** + * @brief ISOLINKCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:11           STREAM_LBL   0x0
+ *  10:08            GROUP_LBL   0x0
+ *     03          ISOSYNCMODE   0
+ *     02            ISOSYNCEN   0
+ *  01:00              ISOTYPE   0x0
+ * 
+ */ +#define EM_BLE_ISOLINKCNTL_ADDR (EXCHANGE_MEM_BASE+0x04 + EM_BLE_CS_OFFSET) +#define EM_BLE_ISOLINKCNTL_INDEX 0x00000002 +#define EM_BLE_ISOLINKCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_isolinkcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_isolinkcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_STREAM_LBL_MASK ((uint16_t)0x0000F800) +#define EM_BLE_STREAM_LBL_LSB 11 +#define EM_BLE_STREAM_LBL_WIDTH ((uint16_t)0x00000005) +#define EM_BLE_GROUP_LBL_MASK ((uint16_t)0x00000700) +#define EM_BLE_GROUP_LBL_LSB 8 +#define EM_BLE_GROUP_LBL_WIDTH ((uint16_t)0x00000003) +#define EM_BLE_ISOSYNCMODE_BIT ((uint16_t)0x00000008) +#define EM_BLE_ISOSYNCMODE_POS 3 +#define EM_BLE_ISOSYNCEN_BIT ((uint16_t)0x00000004) +#define EM_BLE_ISOSYNCEN_POS 2 +#define EM_BLE_ISOTYPE_MASK ((uint16_t)0x00000003) +#define EM_BLE_ISOTYPE_LSB 0 +#define EM_BLE_ISOTYPE_WIDTH ((uint16_t)0x00000002) + +#define EM_BLE_STREAM_LBL_RST 0x0 +#define EM_BLE_GROUP_LBL_RST 0x0 +#define EM_BLE_ISOSYNCMODE_RST 0x0 +#define EM_BLE_ISOSYNCEN_RST 0x0 +#define EM_BLE_ISOTYPE_RST 0x0 + +__INLINE void em_ble_isolinkcntl_pack(int elt_idx, uint8_t streamlbl, uint8_t grouplbl, uint8_t isosyncmode, uint8_t isosyncen, uint8_t isotype) +{ + ASSERT_ERR((((uint16_t)streamlbl << 11) & ~((uint16_t)0x0000F800)) == 0); + ASSERT_ERR((((uint16_t)grouplbl << 8) & ~((uint16_t)0x00000700)) == 0); + ASSERT_ERR((((uint16_t)isosyncmode << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)isosyncen << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)isotype << 0) & ~((uint16_t)0x00000003)) == 0); + EM_BLE_WR(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)streamlbl << 11) | ((uint16_t)grouplbl << 8) | ((uint16_t)isosyncmode << 3) | ((uint16_t)isosyncen << 2) | ((uint16_t)isotype << 0)); +} + +__INLINE void em_ble_isolinkcntl_unpack(int elt_idx, uint8_t* streamlbl, uint8_t* grouplbl, uint8_t* isosyncmode, uint8_t* isosyncen, uint8_t* isotype) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *streamlbl = (localVal & ((uint16_t)0x0000F800)) >> 11; + *grouplbl = (localVal & ((uint16_t)0x00000700)) >> 8; + *isosyncmode = (localVal & ((uint16_t)0x00000008)) >> 3; + *isosyncen = (localVal & ((uint16_t)0x00000004)) >> 2; + *isotype = (localVal & ((uint16_t)0x00000003)) >> 0; +} + +__INLINE uint8_t em_ble_isolinkcntl_stream_lbl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000F800)) >> 11); +} + +__INLINE void em_ble_isolinkcntl_stream_lbl_setf(int elt_idx, uint8_t streamlbl) +{ + ASSERT_ERR((((uint16_t)streamlbl << 11) & ~((uint16_t)0x0000F800)) == 0); + EM_BLE_WR(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000F800)) | ((uint16_t)streamlbl << 11)); +} + +__INLINE uint8_t em_ble_isolinkcntl_group_lbl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000700)) >> 8); +} + +__INLINE void em_ble_isolinkcntl_group_lbl_setf(int elt_idx, uint8_t grouplbl) +{ + ASSERT_ERR((((uint16_t)grouplbl << 8) & ~((uint16_t)0x00000700)) == 0); + EM_BLE_WR(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000700)) | ((uint16_t)grouplbl << 8)); +} + +__INLINE uint8_t em_ble_isolinkcntl_isosyncmode_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_isolinkcntl_isosyncmode_setf(int elt_idx, uint8_t isosyncmode) +{ + ASSERT_ERR((((uint16_t)isosyncmode << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)isosyncmode << 3)); +} + +__INLINE uint8_t em_ble_isolinkcntl_isosyncen_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_isolinkcntl_isosyncen_setf(int elt_idx, uint8_t isosyncen) +{ + ASSERT_ERR((((uint16_t)isosyncen << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)isosyncen << 2)); +} + +__INLINE uint8_t em_ble_isolinkcntl_isotype_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000003)) >> 0); +} + +__INLINE void em_ble_isolinkcntl_isotype_setf(int elt_idx, uint8_t isotype) +{ + ASSERT_ERR((((uint16_t)isotype << 0) & ~((uint16_t)0x00000003)) == 0); + EM_BLE_WR(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOLINKCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000003)) | ((uint16_t)isotype << 0)); +} + +/** + * @brief THRCNTL_RATECNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:12                RXTHR   0x0
+ *  11:08                TXTHR   0x0
+ *  05:04             AUX_RATE   0x0
+ *  03:02               RXRATE   0x0
+ *  01:00               TXRATE   0x0
+ * 
+ */ +#define EM_BLE_THRCNTL_RATECNTL_ADDR (EXCHANGE_MEM_BASE+0x06 + EM_BLE_CS_OFFSET) +#define EM_BLE_THRCNTL_RATECNTL_INDEX 0x00000003 +#define EM_BLE_THRCNTL_RATECNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_thrcntl_ratecntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_thrcntl_ratecntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_RXTHR_MASK ((uint16_t)0x0000F000) +#define EM_BLE_RXTHR_LSB 12 +#define EM_BLE_RXTHR_WIDTH ((uint16_t)0x00000004) +#define EM_BLE_TXTHR_MASK ((uint16_t)0x00000F00) +#define EM_BLE_TXTHR_LSB 8 +#define EM_BLE_TXTHR_WIDTH ((uint16_t)0x00000004) +#define EM_BLE_AUX_RATE_MASK ((uint16_t)0x00000030) +#define EM_BLE_AUX_RATE_LSB 4 +#define EM_BLE_AUX_RATE_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_RXRATE_MASK ((uint16_t)0x0000000C) +#define EM_BLE_RXRATE_LSB 2 +#define EM_BLE_RXRATE_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_TXRATE_MASK ((uint16_t)0x00000003) +#define EM_BLE_TXRATE_LSB 0 +#define EM_BLE_TXRATE_WIDTH ((uint16_t)0x00000002) + +#define EM_BLE_RXTHR_RST 0x0 +#define EM_BLE_TXTHR_RST 0x0 +#define EM_BLE_AUX_RATE_RST 0x0 +#define EM_BLE_RXRATE_RST 0x0 +#define EM_BLE_TXRATE_RST 0x0 + +__INLINE void em_ble_thrcntl_ratecntl_pack(int elt_idx, uint8_t rxthr, uint8_t txthr, uint8_t auxrate, uint8_t rxrate, uint8_t txrate) +{ + ASSERT_ERR((((uint16_t)rxthr << 12) & ~((uint16_t)0x0000F000)) == 0); + ASSERT_ERR((((uint16_t)txthr << 8) & ~((uint16_t)0x00000F00)) == 0); + ASSERT_ERR((((uint16_t)auxrate << 4) & ~((uint16_t)0x00000030)) == 0); + ASSERT_ERR((((uint16_t)rxrate << 2) & ~((uint16_t)0x0000000C)) == 0); + ASSERT_ERR((((uint16_t)txrate << 0) & ~((uint16_t)0x00000003)) == 0); + + //TODO zengjun CHECK + if ((CO_RATE_2MBPS == auxrate) || (CO_RATE_2MBPS == rxrate )) + { +//// RFC->ABBCR0 = 0x000F00C0; + } + else + { +//// RFC->ABBCR0 = 0x000F0000; + } + //SCU->MCGR_b.RFCCLKEN = g_clock_off_define; + + EM_BLE_WR(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)rxthr << 12) | ((uint16_t)txthr << 8) | ((uint16_t)auxrate << 4) | ((uint16_t)rxrate << 2) | ((uint16_t)txrate << 0)); +} + +__INLINE void em_ble_thrcntl_ratecntl_unpack(int elt_idx, uint8_t* rxthr, uint8_t* txthr, uint8_t* auxrate, uint8_t* rxrate, uint8_t* txrate) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *rxthr = (localVal & ((uint16_t)0x0000F000)) >> 12; + *txthr = (localVal & ((uint16_t)0x00000F00)) >> 8; + *auxrate = (localVal & ((uint16_t)0x00000030)) >> 4; + *rxrate = (localVal & ((uint16_t)0x0000000C)) >> 2; + *txrate = (localVal & ((uint16_t)0x00000003)) >> 0; +} + +__INLINE uint8_t em_ble_thrcntl_ratecntl_rxthr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000F000)) >> 12); +} + +__INLINE void em_ble_thrcntl_ratecntl_rxthr_setf(int elt_idx, uint8_t rxthr) +{ + ASSERT_ERR((((uint16_t)rxthr << 12) & ~((uint16_t)0x0000F000)) == 0); + EM_BLE_WR(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000F000)) | ((uint16_t)rxthr << 12)); +} + +__INLINE uint8_t em_ble_thrcntl_ratecntl_txthr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000F00)) >> 8); +} + +__INLINE void em_ble_thrcntl_ratecntl_txthr_setf(int elt_idx, uint8_t txthr) +{ + ASSERT_ERR((((uint16_t)txthr << 8) & ~((uint16_t)0x00000F00)) == 0); + EM_BLE_WR(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000F00)) | ((uint16_t)txthr << 8)); +} + +__INLINE uint8_t em_ble_thrcntl_ratecntl_aux_rate_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000030)) >> 4); +} + +__INLINE void em_ble_thrcntl_ratecntl_aux_rate_setf(int elt_idx, uint8_t auxrate) +{ + ASSERT_ERR((((uint16_t)auxrate << 4) & ~((uint16_t)0x00000030)) == 0); + EM_BLE_WR(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000030)) | ((uint16_t)auxrate << 4)); +} + +__INLINE uint8_t em_ble_thrcntl_ratecntl_rxrate_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000000C)) >> 2); +} + +__INLINE void em_ble_thrcntl_ratecntl_rxrate_setf(int elt_idx, uint8_t rxrate) +{ + ASSERT_ERR((((uint16_t)rxrate << 2) & ~((uint16_t)0x0000000C)) == 0); + EM_BLE_WR(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000000C)) | ((uint16_t)rxrate << 2)); +} + +__INLINE uint8_t em_ble_thrcntl_ratecntl_txrate_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000003)) >> 0); +} + +__INLINE void em_ble_thrcntl_ratecntl_txrate_setf(int elt_idx, uint8_t txrate) +{ + ASSERT_ERR((((uint16_t)txrate << 0) & ~((uint16_t)0x00000003)) == 0); + EM_BLE_WR(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_THRCNTL_RATECNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000003)) | ((uint16_t)txrate << 0)); +} + +/** + * @brief LEBDADDR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00               BDADDR   0x0
+ * 
+ */ +#define EM_BLE_LEBDADDR_ADDR (EXCHANGE_MEM_BASE+0x08 + EM_BLE_CS_OFFSET) +#define EM_BLE_LEBDADDR_INDEX 0x00000004 +#define EM_BLE_LEBDADDR_RESET 0x00000000 +#define EM_BLE_LEBDADDR_COUNT 3 + +__INLINE uint16_t em_ble_lebdaddr_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + return EM_BLE_RD(EM_BLE_LEBDADDR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_lebdaddr_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 2); + EM_BLE_WR(EM_BLE_LEBDADDR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_BDADDR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_BDADDR_LSB 0 +#define EM_BLE_BDADDR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_BDADDR_RST 0x0 + +__INLINE uint16_t em_ble_lebdaddr_bdaddr_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + uint16_t localVal = EM_BLE_RD(EM_BLE_LEBDADDR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_lebdaddr_bdaddr_setf(int elt_idx, int reg_idx, uint16_t bdaddr) +{ + ASSERT_ERR(reg_idx <= 2); + ASSERT_ERR((((uint16_t)bdaddr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_LEBDADDR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2, (uint16_t)bdaddr << 0); +} + +/** + * @brief SYNCWL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00            SYNCWORDL   0x0
+ * 
+ */ +#define EM_BLE_SYNCWL_ADDR (EXCHANGE_MEM_BASE+0x0E + EM_BLE_CS_OFFSET) +#define EM_BLE_SYNCWL_INDEX 0x00000007 +#define EM_BLE_SYNCWL_RESET 0x00000000 + +__INLINE uint16_t em_ble_syncwl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_SYNCWL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_syncwl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_SYNCWL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_SYNCWORDL_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_SYNCWORDL_LSB 0 +#define EM_BLE_SYNCWORDL_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_SYNCWORDL_RST 0x0 + +__INLINE uint16_t em_ble_syncwl_syncwordl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_SYNCWL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_syncwl_syncwordl_setf(int elt_idx, uint16_t syncwordl) +{ + ASSERT_ERR((((uint16_t)syncwordl << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_SYNCWL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)syncwordl << 0); +} + +/** + * @brief SYNCWH register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00            SYNCWORDH   0x0
+ * 
+ */ +#define EM_BLE_SYNCWH_ADDR (EXCHANGE_MEM_BASE+0x10 + EM_BLE_CS_OFFSET) +#define EM_BLE_SYNCWH_INDEX 0x00000008 +#define EM_BLE_SYNCWH_RESET 0x00000000 + +__INLINE uint16_t em_ble_syncwh_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_SYNCWH_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_syncwh_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_SYNCWH_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_SYNCWORDH_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_SYNCWORDH_LSB 0 +#define EM_BLE_SYNCWORDH_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_SYNCWORDH_RST 0x0 + +__INLINE uint16_t em_ble_syncwh_syncwordh_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_SYNCWH_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_syncwh_syncwordh_setf(int elt_idx, uint16_t syncwordh) +{ + ASSERT_ERR((((uint16_t)syncwordh << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_SYNCWH_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)syncwordh << 0); +} + +/** + * @brief CRCINIT0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00             CRCINIT0   0x0
+ * 
+ */ +#define EM_BLE_CRCINIT0_ADDR (EXCHANGE_MEM_BASE+0x12 + EM_BLE_CS_OFFSET) +#define EM_BLE_CRCINIT0_INDEX 0x00000009 +#define EM_BLE_CRCINIT0_RESET 0x00000000 + +__INLINE uint16_t em_ble_crcinit0_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_CRCINIT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_crcinit0_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_CRCINIT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_CRCINIT0_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_CRCINIT0_LSB 0 +#define EM_BLE_CRCINIT0_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_CRCINIT0_RST 0x0 + +__INLINE uint16_t em_ble_crcinit0_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CRCINIT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_crcinit0_setf(int elt_idx, uint16_t crcinit0) +{ + ASSERT_ERR((((uint16_t)crcinit0 << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_CRCINIT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)crcinit0 << 0); +} + +/** + * @brief CRCINIT1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08          RXMAXCTEBUF   0x0
+ *  07:00             CRCINIT1   0x0
+ * 
+ */ +#define EM_BLE_CRCINIT1_ADDR (EXCHANGE_MEM_BASE+0x14 + EM_BLE_CS_OFFSET) +#define EM_BLE_CRCINIT1_INDEX 0x0000000A +#define EM_BLE_CRCINIT1_RESET 0x00000000 + +__INLINE uint16_t em_ble_crcinit1_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_CRCINIT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_crcinit1_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_CRCINIT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_RXMAXCTEBUF_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_RXMAXCTEBUF_LSB 8 +#define EM_BLE_RXMAXCTEBUF_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_CRCINIT1_MASK ((uint16_t)0x000000FF) +#define EM_BLE_CRCINIT1_LSB 0 +#define EM_BLE_CRCINIT1_WIDTH ((uint16_t)0x00000008) + +#define EM_BLE_RXMAXCTEBUF_RST 0x0 +#define EM_BLE_CRCINIT1_RST 0x0 + +__INLINE void em_ble_crcinit1_pack(int elt_idx, uint8_t rxmaxctebuf, uint8_t crcinit1) +{ + ASSERT_ERR((((uint16_t)rxmaxctebuf << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)crcinit1 << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_CRCINIT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)rxmaxctebuf << 8) | ((uint16_t)crcinit1 << 0)); +} + +__INLINE void em_ble_crcinit1_unpack(int elt_idx, uint8_t* rxmaxctebuf, uint8_t* crcinit1) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CRCINIT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *rxmaxctebuf = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *crcinit1 = (localVal & ((uint16_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t em_ble_crcinit1_rxmaxctebuf_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CRCINIT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_crcinit1_rxmaxctebuf_setf(int elt_idx, uint8_t rxmaxctebuf) +{ + ASSERT_ERR((((uint16_t)rxmaxctebuf << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_CRCINIT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_CRCINIT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)rxmaxctebuf << 8)); +} + +__INLINE uint8_t em_ble_crcinit1_crcinit1_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CRCINIT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x000000FF)) >> 0); +} + +__INLINE void em_ble_crcinit1_crcinit1_setf(int elt_idx, uint8_t crcinit1) +{ + ASSERT_ERR((((uint16_t)crcinit1 << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_CRCINIT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_CRCINIT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x000000FF)) | ((uint16_t)crcinit1 << 0)); +} + +/** + * @brief FILTPOL_RALCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08        FILTER_POLICY   0x0
+ *     04         RAL_RESOL_EN   0
+ *     03       PERADV_FILT_EN   0
+ *     02        LOCAL_RPA_SEL   0
+ *     01             RAL_MODE   0
+ *     00               RAL_EN   0
+ * 
+ */ +#define EM_BLE_FILTPOL_RALCNTL_ADDR (EXCHANGE_MEM_BASE+0x16 + EM_BLE_CS_OFFSET) +#define EM_BLE_FILTPOL_RALCNTL_INDEX 0x0000000B +#define EM_BLE_FILTPOL_RALCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_filtpol_ralcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_filtpol_ralcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_FILTER_POLICY_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_FILTER_POLICY_LSB 8 +#define EM_BLE_FILTER_POLICY_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_RAL_RESOL_EN_BIT ((uint16_t)0x00000010) +#define EM_BLE_RAL_RESOL_EN_POS 4 +#define EM_BLE_PERADV_FILT_EN_BIT ((uint16_t)0x00000008) +#define EM_BLE_PERADV_FILT_EN_POS 3 +#define EM_BLE_LOCAL_RPA_SEL_BIT ((uint16_t)0x00000004) +#define EM_BLE_LOCAL_RPA_SEL_POS 2 +#define EM_BLE_RAL_MODE_BIT ((uint16_t)0x00000002) +#define EM_BLE_RAL_MODE_POS 1 +#define EM_BLE_RAL_EN_BIT ((uint16_t)0x00000001) +#define EM_BLE_RAL_EN_POS 0 + +#define EM_BLE_FILTER_POLICY_RST 0x0 +#define EM_BLE_RAL_RESOL_EN_RST 0x0 +#define EM_BLE_PERADV_FILT_EN_RST 0x0 +#define EM_BLE_LOCAL_RPA_SEL_RST 0x0 +#define EM_BLE_RAL_MODE_RST 0x0 +#define EM_BLE_RAL_EN_RST 0x0 + +__INLINE void em_ble_filtpol_ralcntl_pack(int elt_idx, uint8_t filterpolicy, uint8_t ralresolen, uint8_t peradvfilten, uint8_t localrpasel, uint8_t ralmode, uint8_t ralen) +{ + ASSERT_ERR((((uint16_t)filterpolicy << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)ralresolen << 4) & ~((uint16_t)0x00000010)) == 0); + ASSERT_ERR((((uint16_t)peradvfilten << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)localrpasel << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)ralmode << 1) & ~((uint16_t)0x00000002)) == 0); + ASSERT_ERR((((uint16_t)ralen << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)filterpolicy << 8) | ((uint16_t)ralresolen << 4) | ((uint16_t)peradvfilten << 3) | ((uint16_t)localrpasel << 2) | ((uint16_t)ralmode << 1) | ((uint16_t)ralen << 0)); +} + +__INLINE void em_ble_filtpol_ralcntl_unpack(int elt_idx, uint8_t* filterpolicy, uint8_t* ralresolen, uint8_t* peradvfilten, uint8_t* localrpasel, uint8_t* ralmode, uint8_t* ralen) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *filterpolicy = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *ralresolen = (localVal & ((uint16_t)0x00000010)) >> 4; + *peradvfilten = (localVal & ((uint16_t)0x00000008)) >> 3; + *localrpasel = (localVal & ((uint16_t)0x00000004)) >> 2; + *ralmode = (localVal & ((uint16_t)0x00000002)) >> 1; + *ralen = (localVal & ((uint16_t)0x00000001)) >> 0; +} + +__INLINE uint8_t em_ble_filtpol_ralcntl_filter_policy_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_filtpol_ralcntl_filter_policy_setf(int elt_idx, uint8_t filterpolicy) +{ + ASSERT_ERR((((uint16_t)filterpolicy << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)filterpolicy << 8)); +} + +__INLINE uint8_t em_ble_filtpol_ralcntl_ral_resol_en_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000010)) >> 4); +} + +__INLINE void em_ble_filtpol_ralcntl_ral_resol_en_setf(int elt_idx, uint8_t ralresolen) +{ + ASSERT_ERR((((uint16_t)ralresolen << 4) & ~((uint16_t)0x00000010)) == 0); + EM_BLE_WR(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000010)) | ((uint16_t)ralresolen << 4)); +} + +__INLINE uint8_t em_ble_filtpol_ralcntl_peradv_filt_en_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_filtpol_ralcntl_peradv_filt_en_setf(int elt_idx, uint8_t peradvfilten) +{ + ASSERT_ERR((((uint16_t)peradvfilten << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)peradvfilten << 3)); +} + +__INLINE uint8_t em_ble_filtpol_ralcntl_local_rpa_sel_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_filtpol_ralcntl_local_rpa_sel_setf(int elt_idx, uint8_t localrpasel) +{ + ASSERT_ERR((((uint16_t)localrpasel << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)localrpasel << 2)); +} + +__INLINE uint8_t em_ble_filtpol_ralcntl_ral_mode_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000002)) >> 1); +} + +__INLINE void em_ble_filtpol_ralcntl_ral_mode_setf(int elt_idx, uint8_t ralmode) +{ + ASSERT_ERR((((uint16_t)ralmode << 1) & ~((uint16_t)0x00000002)) == 0); + EM_BLE_WR(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000002)) | ((uint16_t)ralmode << 1)); +} + +__INLINE uint8_t em_ble_filtpol_ralcntl_ral_en_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000001)) >> 0); +} + +__INLINE void em_ble_filtpol_ralcntl_ral_en_setf(int elt_idx, uint8_t ralen) +{ + ASSERT_ERR((((uint16_t)ralen << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_FILTPOL_RALCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000001)) | ((uint16_t)ralen << 0)); +} + +/** + * @brief HOPCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15                FH_EN   0
+ *  14:13             HOP_MODE   0x0
+ *  12:08              HOP_INT   0x0
+ *  05:00               CH_IDX   0x0
+ * 
+ */ +#define EM_BLE_HOPCNTL_ADDR (EXCHANGE_MEM_BASE+0x18 + EM_BLE_CS_OFFSET) +#define EM_BLE_HOPCNTL_INDEX 0x0000000C +#define EM_BLE_HOPCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_hopcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_hopcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_FH_EN_BIT ((uint16_t)0x00008000) +#define EM_BLE_FH_EN_POS 15 +#define EM_BLE_HOP_MODE_MASK ((uint16_t)0x00006000) +#define EM_BLE_HOP_MODE_LSB 13 +#define EM_BLE_HOP_MODE_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_HOP_INT_MASK ((uint16_t)0x00001F00) +#define EM_BLE_HOP_INT_LSB 8 +#define EM_BLE_HOP_INT_WIDTH ((uint16_t)0x00000005) +#define EM_BLE_CH_IDX_MASK ((uint16_t)0x0000003F) +#define EM_BLE_CH_IDX_LSB 0 +#define EM_BLE_CH_IDX_WIDTH ((uint16_t)0x00000006) + +#define EM_BLE_FH_EN_RST 0x0 +#define EM_BLE_HOP_MODE_RST 0x0 +#define EM_BLE_HOP_INT_RST 0x0 +#define EM_BLE_CH_IDX_RST 0x0 + +__INLINE void em_ble_hopcntl_pack(int elt_idx, uint8_t fhen, uint8_t hopmode, uint8_t hopint, uint8_t chidx) +{ + ASSERT_ERR((((uint16_t)fhen << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)hopmode << 13) & ~((uint16_t)0x00006000)) == 0); + ASSERT_ERR((((uint16_t)hopint << 8) & ~((uint16_t)0x00001F00)) == 0); + ASSERT_ERR((((uint16_t)chidx << 0) & ~((uint16_t)0x0000003F)) == 0); + EM_BLE_WR(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)fhen << 15) | ((uint16_t)hopmode << 13) | ((uint16_t)hopint << 8) | ((uint16_t)chidx << 0)); +} + +__INLINE void em_ble_hopcntl_unpack(int elt_idx, uint8_t* fhen, uint8_t* hopmode, uint8_t* hopint, uint8_t* chidx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *fhen = (localVal & ((uint16_t)0x00008000)) >> 15; + *hopmode = (localVal & ((uint16_t)0x00006000)) >> 13; + *hopint = (localVal & ((uint16_t)0x00001F00)) >> 8; + *chidx = (localVal & ((uint16_t)0x0000003F)) >> 0; +} + +__INLINE uint8_t em_ble_hopcntl_fh_en_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_hopcntl_fh_en_setf(int elt_idx, uint8_t fhen) +{ + ASSERT_ERR((((uint16_t)fhen << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)fhen << 15)); +} + +__INLINE uint8_t em_ble_hopcntl_hop_mode_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00006000)) >> 13); +} + +__INLINE void em_ble_hopcntl_hop_mode_setf(int elt_idx, uint8_t hopmode) +{ + ASSERT_ERR((((uint16_t)hopmode << 13) & ~((uint16_t)0x00006000)) == 0); + EM_BLE_WR(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00006000)) | ((uint16_t)hopmode << 13)); +} + +__INLINE uint8_t em_ble_hopcntl_hop_int_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00001F00)) >> 8); +} + +__INLINE void em_ble_hopcntl_hop_int_setf(int elt_idx, uint8_t hopint) +{ + ASSERT_ERR((((uint16_t)hopint << 8) & ~((uint16_t)0x00001F00)) == 0); + EM_BLE_WR(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00001F00)) | ((uint16_t)hopint << 8)); +} + +__INLINE uint8_t em_ble_hopcntl_ch_idx_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000003F)) >> 0); +} + +__INLINE void em_ble_hopcntl_ch_idx_setf(int elt_idx, uint8_t chidx) +{ + ASSERT_ERR((((uint16_t)chidx << 0) & ~((uint16_t)0x0000003F)) == 0); + EM_BLE_WR(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_HOPCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000003F)) | ((uint16_t)chidx << 0)); +} + +/** + * @brief TXRXCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15          RXBUFF_FULL   0
+ *     14            LASTEMPTY   0
+ *     13                   SN   0
+ *     12                 NESN   0
+ *     11           RXBFMICERR   0
+ *     10            RXMAFSERR   0
+ *     09          ENDS_ON_SAC   0
+ *     08            EXT_PA_EN   0
+ *  07:00                TXPWR   0x0
+ * 
+ */ +#define EM_BLE_TXRXCNTL_ADDR (EXCHANGE_MEM_BASE+0x1A + EM_BLE_CS_OFFSET) +#define EM_BLE_TXRXCNTL_INDEX 0x0000000D +#define EM_BLE_TXRXCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_txrxcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_txrxcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_RXBUFF_FULL_BIT ((uint16_t)0x00008000) +#define EM_BLE_RXBUFF_FULL_POS 15 +#define EM_BLE_LASTEMPTY_BIT ((uint16_t)0x00004000) +#define EM_BLE_LASTEMPTY_POS 14 +#define EM_BLE_SN_BIT ((uint16_t)0x00002000) +#define EM_BLE_SN_POS 13 +#define EM_BLE_NESN_BIT ((uint16_t)0x00001000) +#define EM_BLE_NESN_POS 12 +#define EM_BLE_RXBFMICERR_BIT ((uint16_t)0x00000800) +#define EM_BLE_RXBFMICERR_POS 11 +#define EM_BLE_RXMAFSERR_BIT ((uint16_t)0x00000400) +#define EM_BLE_RXMAFSERR_POS 10 +#define EM_BLE_ENDS_ON_SAC_BIT ((uint16_t)0x00000200) +#define EM_BLE_ENDS_ON_SAC_POS 9 +#define EM_BLE_EXT_PA_EN_BIT ((uint16_t)0x00000100) +#define EM_BLE_EXT_PA_EN_POS 8 +#define EM_BLE_TXPWR_MASK ((uint16_t)0x000000FF) +#define EM_BLE_TXPWR_LSB 0 +#define EM_BLE_TXPWR_WIDTH ((uint16_t)0x00000008) + +#define EM_BLE_RXBUFF_FULL_RST 0x0 +#define EM_BLE_LASTEMPTY_RST 0x0 +#define EM_BLE_SN_RST 0x0 +#define EM_BLE_NESN_RST 0x0 +#define EM_BLE_RXBFMICERR_RST 0x0 +#define EM_BLE_RXMAFSERR_RST 0x0 +#define EM_BLE_ENDS_ON_SAC_RST 0x0 +#define EM_BLE_EXT_PA_EN_RST 0x0 +#define EM_BLE_TXPWR_RST 0x0 + +__INLINE void em_ble_txrxcntl_pack(int elt_idx, uint8_t rxbufffull, uint8_t lastempty, uint8_t sn, uint8_t nesn, uint8_t rxbfmicerr, uint8_t rxmafserr, uint8_t endsonsac, uint8_t extpaen, uint8_t txpwr) +{ + ASSERT_ERR((((uint16_t)rxbufffull << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)lastempty << 14) & ~((uint16_t)0x00004000)) == 0); + ASSERT_ERR((((uint16_t)sn << 13) & ~((uint16_t)0x00002000)) == 0); + ASSERT_ERR((((uint16_t)nesn << 12) & ~((uint16_t)0x00001000)) == 0); + ASSERT_ERR((((uint16_t)rxbfmicerr << 11) & ~((uint16_t)0x00000800)) == 0); + ASSERT_ERR((((uint16_t)rxmafserr << 10) & ~((uint16_t)0x00000400)) == 0); + ASSERT_ERR((((uint16_t)endsonsac << 9) & ~((uint16_t)0x00000200)) == 0); + ASSERT_ERR((((uint16_t)extpaen << 8) & ~((uint16_t)0x00000100)) == 0); + ASSERT_ERR((((uint16_t)txpwr << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)rxbufffull << 15) | ((uint16_t)lastempty << 14) | ((uint16_t)sn << 13) | ((uint16_t)nesn << 12) | ((uint16_t)rxbfmicerr << 11) | ((uint16_t)rxmafserr << 10) | ((uint16_t)endsonsac << 9) | ((uint16_t)extpaen << 8) | ((uint16_t)txpwr << 0)); +} + +__INLINE void em_ble_txrxcntl_unpack(int elt_idx, uint8_t* rxbufffull, uint8_t* lastempty, uint8_t* sn, uint8_t* nesn, uint8_t* rxbfmicerr, uint8_t* rxmafserr, uint8_t* endsonsac, uint8_t* extpaen, uint8_t* txpwr) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *rxbufffull = (localVal & ((uint16_t)0x00008000)) >> 15; + *lastempty = (localVal & ((uint16_t)0x00004000)) >> 14; + *sn = (localVal & ((uint16_t)0x00002000)) >> 13; + *nesn = (localVal & ((uint16_t)0x00001000)) >> 12; + *rxbfmicerr = (localVal & ((uint16_t)0x00000800)) >> 11; + *rxmafserr = (localVal & ((uint16_t)0x00000400)) >> 10; + *endsonsac = (localVal & ((uint16_t)0x00000200)) >> 9; + *extpaen = (localVal & ((uint16_t)0x00000100)) >> 8; + *txpwr = (localVal & ((uint16_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t em_ble_txrxcntl_rxbuff_full_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_txrxcntl_rxbuff_full_setf(int elt_idx, uint8_t rxbufffull) +{ + ASSERT_ERR((((uint16_t)rxbufffull << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)rxbufffull << 15)); +} + +__INLINE uint8_t em_ble_txrxcntl_lastempty_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00004000)) >> 14); +} + +__INLINE void em_ble_txrxcntl_lastempty_setf(int elt_idx, uint8_t lastempty) +{ + ASSERT_ERR((((uint16_t)lastempty << 14) & ~((uint16_t)0x00004000)) == 0); + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00004000)) | ((uint16_t)lastempty << 14)); +} + +__INLINE uint8_t em_ble_txrxcntl_sn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00002000)) >> 13); +} + +__INLINE void em_ble_txrxcntl_sn_setf(int elt_idx, uint8_t sn) +{ + ASSERT_ERR((((uint16_t)sn << 13) & ~((uint16_t)0x00002000)) == 0); + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00002000)) | ((uint16_t)sn << 13)); +} + +__INLINE uint8_t em_ble_txrxcntl_nesn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00001000)) >> 12); +} + +__INLINE void em_ble_txrxcntl_nesn_setf(int elt_idx, uint8_t nesn) +{ + ASSERT_ERR((((uint16_t)nesn << 12) & ~((uint16_t)0x00001000)) == 0); + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00001000)) | ((uint16_t)nesn << 12)); +} + +__INLINE uint8_t em_ble_txrxcntl_rxbfmicerr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000800)) >> 11); +} + +__INLINE void em_ble_txrxcntl_rxbfmicerr_setf(int elt_idx, uint8_t rxbfmicerr) +{ + ASSERT_ERR((((uint16_t)rxbfmicerr << 11) & ~((uint16_t)0x00000800)) == 0); + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000800)) | ((uint16_t)rxbfmicerr << 11)); +} + +__INLINE uint8_t em_ble_txrxcntl_rxmafserr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000400)) >> 10); +} + +__INLINE void em_ble_txrxcntl_rxmafserr_setf(int elt_idx, uint8_t rxmafserr) +{ + ASSERT_ERR((((uint16_t)rxmafserr << 10) & ~((uint16_t)0x00000400)) == 0); + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000400)) | ((uint16_t)rxmafserr << 10)); +} + +__INLINE uint8_t em_ble_txrxcntl_ends_on_sac_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000200)) >> 9); +} + +__INLINE void em_ble_txrxcntl_ends_on_sac_setf(int elt_idx, uint8_t endsonsac) +{ + ASSERT_ERR((((uint16_t)endsonsac << 9) & ~((uint16_t)0x00000200)) == 0); + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000200)) | ((uint16_t)endsonsac << 9)); +} + +__INLINE uint8_t em_ble_txrxcntl_ext_pa_en_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000100)) >> 8); +} + +__INLINE void em_ble_txrxcntl_ext_pa_en_setf(int elt_idx, uint8_t extpaen) +{ + ASSERT_ERR((((uint16_t)extpaen << 8) & ~((uint16_t)0x00000100)) == 0); + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000100)) | ((uint16_t)extpaen << 8)); +} + +__INLINE uint8_t em_ble_txrxcntl_txpwr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x000000FF)) >> 0); +} + +__INLINE void em_ble_txrxcntl_txpwr_setf(int elt_idx, uint8_t txpwr) +{ + ASSERT_ERR((((uint16_t)txpwr << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_TXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x000000FF)) | ((uint16_t)txpwr << 0)); +} + +/** + * @brief RXDFCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     08              DFRSPEN   0
+ *  07:06             DFSWCNTL   0x0
+ *  05:04           DFSAMPCNTL   0x0
+ *  03:02               DFTYPE   0x0
+ *     01           DFFILTEREN   0
+ *     00                 DFEN   0
+ * 
+ */ +#define EM_BLE_RXDFCNTL_ADDR (EXCHANGE_MEM_BASE+0x1C + EM_BLE_CS_OFFSET) +#define EM_BLE_RXDFCNTL_INDEX 0x0000000E +#define EM_BLE_RXDFCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxdfcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_rxdfcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_DFRSPEN_BIT ((uint16_t)0x00000100) +#define EM_BLE_DFRSPEN_POS 8 +#define EM_BLE_DFSWCNTL_MASK ((uint16_t)0x000000C0) +#define EM_BLE_DFSWCNTL_LSB 6 +#define EM_BLE_DFSWCNTL_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_DFSAMPCNTL_MASK ((uint16_t)0x00000030) +#define EM_BLE_DFSAMPCNTL_LSB 4 +#define EM_BLE_DFSAMPCNTL_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_DFTYPE_MASK ((uint16_t)0x0000000C) +#define EM_BLE_DFTYPE_LSB 2 +#define EM_BLE_DFTYPE_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_DFFILTEREN_BIT ((uint16_t)0x00000002) +#define EM_BLE_DFFILTEREN_POS 1 +#define EM_BLE_DFEN_BIT ((uint16_t)0x00000001) +#define EM_BLE_DFEN_POS 0 + +#define EM_BLE_DFRSPEN_RST 0x0 +#define EM_BLE_DFSWCNTL_RST 0x0 +#define EM_BLE_DFSAMPCNTL_RST 0x0 +#define EM_BLE_DFTYPE_RST 0x0 +#define EM_BLE_DFFILTEREN_RST 0x0 +#define EM_BLE_DFEN_RST 0x0 + +__INLINE void em_ble_rxdfcntl_pack(int elt_idx, uint8_t dfrspen, uint8_t dfswcntl, uint8_t dfsampcntl, uint8_t dftype, uint8_t dffilteren, uint8_t dfen) +{ + ASSERT_ERR((((uint16_t)dfrspen << 8) & ~((uint16_t)0x00000100)) == 0); + ASSERT_ERR((((uint16_t)dfswcntl << 6) & ~((uint16_t)0x000000C0)) == 0); + ASSERT_ERR((((uint16_t)dfsampcntl << 4) & ~((uint16_t)0x00000030)) == 0); + ASSERT_ERR((((uint16_t)dftype << 2) & ~((uint16_t)0x0000000C)) == 0); + ASSERT_ERR((((uint16_t)dffilteren << 1) & ~((uint16_t)0x00000002)) == 0); + ASSERT_ERR((((uint16_t)dfen << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)dfrspen << 8) | ((uint16_t)dfswcntl << 6) | ((uint16_t)dfsampcntl << 4) | ((uint16_t)dftype << 2) | ((uint16_t)dffilteren << 1) | ((uint16_t)dfen << 0)); +} + +__INLINE void em_ble_rxdfcntl_unpack(int elt_idx, uint8_t* dfrspen, uint8_t* dfswcntl, uint8_t* dfsampcntl, uint8_t* dftype, uint8_t* dffilteren, uint8_t* dfen) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *dfrspen = (localVal & ((uint16_t)0x00000100)) >> 8; + *dfswcntl = (localVal & ((uint16_t)0x000000C0)) >> 6; + *dfsampcntl = (localVal & ((uint16_t)0x00000030)) >> 4; + *dftype = (localVal & ((uint16_t)0x0000000C)) >> 2; + *dffilteren = (localVal & ((uint16_t)0x00000002)) >> 1; + *dfen = (localVal & ((uint16_t)0x00000001)) >> 0; +} + +__INLINE uint8_t em_ble_rxdfcntl_dfrspen_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000100)) >> 8); +} + +__INLINE void em_ble_rxdfcntl_dfrspen_setf(int elt_idx, uint8_t dfrspen) +{ + ASSERT_ERR((((uint16_t)dfrspen << 8) & ~((uint16_t)0x00000100)) == 0); + EM_BLE_WR(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000100)) | ((uint16_t)dfrspen << 8)); +} + +__INLINE uint8_t em_ble_rxdfcntl_dfswcntl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x000000C0)) >> 6); +} + +__INLINE void em_ble_rxdfcntl_dfswcntl_setf(int elt_idx, uint8_t dfswcntl) +{ + ASSERT_ERR((((uint16_t)dfswcntl << 6) & ~((uint16_t)0x000000C0)) == 0); + EM_BLE_WR(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x000000C0)) | ((uint16_t)dfswcntl << 6)); +} + +__INLINE uint8_t em_ble_rxdfcntl_dfsampcntl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000030)) >> 4); +} + +__INLINE void em_ble_rxdfcntl_dfsampcntl_setf(int elt_idx, uint8_t dfsampcntl) +{ + ASSERT_ERR((((uint16_t)dfsampcntl << 4) & ~((uint16_t)0x00000030)) == 0); + EM_BLE_WR(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000030)) | ((uint16_t)dfsampcntl << 4)); +} + +__INLINE uint8_t em_ble_rxdfcntl_dftype_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000000C)) >> 2); +} + +__INLINE void em_ble_rxdfcntl_dftype_setf(int elt_idx, uint8_t dftype) +{ + ASSERT_ERR((((uint16_t)dftype << 2) & ~((uint16_t)0x0000000C)) == 0); + EM_BLE_WR(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000000C)) | ((uint16_t)dftype << 2)); +} + +__INLINE uint8_t em_ble_rxdfcntl_dffilteren_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000002)) >> 1); +} + +__INLINE void em_ble_rxdfcntl_dffilteren_setf(int elt_idx, uint8_t dffilteren) +{ + ASSERT_ERR((((uint16_t)dffilteren << 1) & ~((uint16_t)0x00000002)) == 0); + EM_BLE_WR(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000002)) | ((uint16_t)dffilteren << 1)); +} + +__INLINE uint8_t em_ble_rxdfcntl_dfen_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000001)) >> 0); +} + +__INLINE void em_ble_rxdfcntl_dfen_setf(int elt_idx, uint8_t dfen) +{ + ASSERT_ERR((((uint16_t)dfen << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXDFCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000001)) | ((uint16_t)dfen << 0)); +} + +/** + * @brief RXWINCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15               RXWIDE   0
+ *  14:00              RXWINSZ   0x0
+ * 
+ */ +#define EM_BLE_RXWINCNTL_ADDR (EXCHANGE_MEM_BASE+0x1E + EM_BLE_CS_OFFSET) +#define EM_BLE_RXWINCNTL_INDEX 0x0000000F +#define EM_BLE_RXWINCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxwincntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXWINCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_rxwincntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXWINCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_RXWIDE_BIT ((uint16_t)0x00008000) +#define EM_BLE_RXWIDE_POS 15 +#define EM_BLE_RXWINSZ_MASK ((uint16_t)0x00007FFF) +#define EM_BLE_RXWINSZ_LSB 0 +#define EM_BLE_RXWINSZ_WIDTH ((uint16_t)0x0000000F) + +#define EM_BLE_RXWIDE_RST 0x0 +#define EM_BLE_RXWINSZ_RST 0x0 + +__INLINE void em_ble_rxwincntl_pack(int elt_idx, uint8_t rxwide, uint16_t rxwinsz) +{ + ASSERT_ERR((((uint16_t)rxwide << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)rxwinsz << 0) & ~((uint16_t)0x00007FFF)) == 0); + EM_BLE_WR(EM_BLE_RXWINCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)rxwide << 15) | ((uint16_t)rxwinsz << 0)); +} + +__INLINE void em_ble_rxwincntl_unpack(int elt_idx, uint8_t* rxwide, uint16_t* rxwinsz) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXWINCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *rxwide = (localVal & ((uint16_t)0x00008000)) >> 15; + *rxwinsz = (localVal & ((uint16_t)0x00007FFF)) >> 0; +} + +__INLINE uint8_t em_ble_rxwincntl_rxwide_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXWINCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_rxwincntl_rxwide_setf(int elt_idx, uint8_t rxwide) +{ + ASSERT_ERR((((uint16_t)rxwide << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_RXWINCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXWINCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)rxwide << 15)); +} + +__INLINE uint16_t em_ble_rxwincntl_rxwinsz_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXWINCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00007FFF)) >> 0); +} + +__INLINE void em_ble_rxwincntl_rxwinsz_setf(int elt_idx, uint16_t rxwinsz) +{ + ASSERT_ERR((((uint16_t)rxwinsz << 0) & ~((uint16_t)0x00007FFF)) == 0); + EM_BLE_WR(EM_BLE_RXWINCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXWINCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00007FFF)) | ((uint16_t)rxwinsz << 0)); +} + +/** + * @brief ISOTXDESCPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00         ISOTXDESCPTR   0x0
+ * 
+ */ +#define EM_BLE_ISOTXDESCPTR_ADDR (EXCHANGE_MEM_BASE+0x20 + EM_BLE_CS_OFFSET) +#define EM_BLE_ISOTXDESCPTR_INDEX 0x00000010 +#define EM_BLE_ISOTXDESCPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_isotxdescptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_ISOTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_isotxdescptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_ISOTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_ISOTXDESCPTR_MASK ((uint16_t)0x00003FFF) +#define EM_BLE_ISOTXDESCPTR_LSB 0 +#define EM_BLE_ISOTXDESCPTR_WIDTH ((uint16_t)0x0000000E) + +#define EM_BLE_ISOTXDESCPTR_RST 0x0 + +__INLINE uint16_t em_ble_isotxdescptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_isotxdescptr_setf(int elt_idx, uint16_t isotxdescptr) +{ + ASSERT_ERR((((uint16_t)isotxdescptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_ISOTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)isotxdescptr << 0); +} + +/** + * @brief ISORXDESCPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00         ISORXDESCPTR   0x0
+ * 
+ */ +#define EM_BLE_ISORXDESCPTR_ADDR (EXCHANGE_MEM_BASE+0x22 + EM_BLE_CS_OFFSET) +#define EM_BLE_ISORXDESCPTR_INDEX 0x00000011 +#define EM_BLE_ISORXDESCPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_isorxdescptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_ISORXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_isorxdescptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_ISORXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_ISORXDESCPTR_MASK ((uint16_t)0x00003FFF) +#define EM_BLE_ISORXDESCPTR_LSB 0 +#define EM_BLE_ISORXDESCPTR_WIDTH ((uint16_t)0x0000000E) + +#define EM_BLE_ISORXDESCPTR_RST 0x0 + +__INLINE uint16_t em_ble_isorxdescptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISORXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_isorxdescptr_setf(int elt_idx, uint16_t isorxdescptr) +{ + ASSERT_ERR((((uint16_t)isorxdescptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_ISORXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)isorxdescptr << 0); +} + +/** + * @brief ACLTXDESCPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00         ACLTXDESCPTR   0x0
+ * 
+ */ +#define EM_BLE_ACLTXDESCPTR_ADDR (EXCHANGE_MEM_BASE+0x24 + EM_BLE_CS_OFFSET) +#define EM_BLE_ACLTXDESCPTR_INDEX 0x00000012 +#define EM_BLE_ACLTXDESCPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_acltxdescptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_ACLTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_acltxdescptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_ACLTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_ACLTXDESCPTR_MASK ((uint16_t)0x00003FFF) +#define EM_BLE_ACLTXDESCPTR_LSB 0 +#define EM_BLE_ACLTXDESCPTR_WIDTH ((uint16_t)0x0000000E) + +#define EM_BLE_ACLTXDESCPTR_RST 0x0 + +__INLINE uint16_t em_ble_acltxdescptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ACLTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_acltxdescptr_setf(int elt_idx, uint16_t acltxdescptr) +{ + ASSERT_ERR((((uint16_t)acltxdescptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_ACLTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)acltxdescptr << 0); +} + +/** + * @brief RXDFANTPATTCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15                DFRSP   0
+ *  12:08         MAX_SAMP_CTE   0x0
+ *  06:00   RX_ANT_PATT_LENGTH   0x0
+ * 
+ */ +#define EM_BLE_RXDFANTPATTCNTL_ADDR (EXCHANGE_MEM_BASE+0x26 + EM_BLE_CS_OFFSET) +#define EM_BLE_RXDFANTPATTCNTL_INDEX 0x00000013 +#define EM_BLE_RXDFANTPATTCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxdfantpattcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_rxdfantpattcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_DFRSP_BIT ((uint16_t)0x00008000) +#define EM_BLE_DFRSP_POS 15 +#define EM_BLE_MAX_SAMP_CTE_MASK ((uint16_t)0x00001F00) +#define EM_BLE_MAX_SAMP_CTE_LSB 8 +#define EM_BLE_MAX_SAMP_CTE_WIDTH ((uint16_t)0x00000005) +#define EM_BLE_RX_ANT_PATT_LENGTH_MASK ((uint16_t)0x0000007F) +#define EM_BLE_RX_ANT_PATT_LENGTH_LSB 0 +#define EM_BLE_RX_ANT_PATT_LENGTH_WIDTH ((uint16_t)0x00000007) + +#define EM_BLE_DFRSP_RST 0x0 +#define EM_BLE_MAX_SAMP_CTE_RST 0x0 +#define EM_BLE_RX_ANT_PATT_LENGTH_RST 0x0 + +__INLINE void em_ble_rxdfantpattcntl_pack(int elt_idx, uint8_t dfrsp, uint8_t maxsampcte, uint8_t rxantpattlength) +{ + ASSERT_ERR((((uint16_t)dfrsp << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)maxsampcte << 8) & ~((uint16_t)0x00001F00)) == 0); + ASSERT_ERR((((uint16_t)rxantpattlength << 0) & ~((uint16_t)0x0000007F)) == 0); + EM_BLE_WR(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)dfrsp << 15) | ((uint16_t)maxsampcte << 8) | ((uint16_t)rxantpattlength << 0)); +} + +__INLINE void em_ble_rxdfantpattcntl_unpack(int elt_idx, uint8_t* dfrsp, uint8_t* maxsampcte, uint8_t* rxantpattlength) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *dfrsp = (localVal & ((uint16_t)0x00008000)) >> 15; + *maxsampcte = (localVal & ((uint16_t)0x00001F00)) >> 8; + *rxantpattlength = (localVal & ((uint16_t)0x0000007F)) >> 0; +} + +__INLINE uint8_t em_ble_rxdfantpattcntl_dfrsp_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_rxdfantpattcntl_dfrsp_setf(int elt_idx, uint8_t dfrsp) +{ + ASSERT_ERR((((uint16_t)dfrsp << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)dfrsp << 15)); +} + +__INLINE uint8_t em_ble_rxdfantpattcntl_max_samp_cte_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00001F00)) >> 8); +} + +__INLINE void em_ble_rxdfantpattcntl_max_samp_cte_setf(int elt_idx, uint8_t maxsampcte) +{ + ASSERT_ERR((((uint16_t)maxsampcte << 8) & ~((uint16_t)0x00001F00)) == 0); + EM_BLE_WR(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00001F00)) | ((uint16_t)maxsampcte << 8)); +} + +__INLINE uint8_t em_ble_rxdfantpattcntl_rx_ant_patt_length_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000007F)) >> 0); +} + +__INLINE void em_ble_rxdfantpattcntl_rx_ant_patt_length_setf(int elt_idx, uint8_t rxantpattlength) +{ + ASSERT_ERR((((uint16_t)rxantpattlength << 0) & ~((uint16_t)0x0000007F)) == 0); + EM_BLE_WR(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000007F)) | ((uint16_t)rxantpattlength << 0)); +} + +/** + * @brief RXDFANTSWPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00    RX_ANTENNA_ID_PTR   0x0
+ * 
+ */ +#define EM_BLE_RXDFANTSWPTR_ADDR (EXCHANGE_MEM_BASE+0x28 + EM_BLE_CS_OFFSET) +#define EM_BLE_RXDFANTSWPTR_INDEX 0x00000014 +#define EM_BLE_RXDFANTSWPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxdfantswptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXDFANTSWPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_rxdfantswptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXDFANTSWPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_RX_ANTENNA_ID_PTR_MASK ((uint16_t)0x00003FFF) +#define EM_BLE_RX_ANTENNA_ID_PTR_LSB 0 +#define EM_BLE_RX_ANTENNA_ID_PTR_WIDTH ((uint16_t)0x0000000E) + +#define EM_BLE_RX_ANTENNA_ID_PTR_RST 0x0 + +__INLINE uint16_t em_ble_rxdfantswptr_rx_antenna_id_ptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDFANTSWPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_rxdfantswptr_rx_antenna_id_ptr_setf(int elt_idx, uint16_t rxantennaidptr) +{ + ASSERT_ERR((((uint16_t)rxantennaidptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_RXDFANTSWPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)rxantennaidptr << 0); +} + +/** + * @brief TXDFANTPATTCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  06:00   TX_ANT_PATT_LENGTH   0x0
+ * 
+ */ +#define EM_BLE_TXDFANTPATTCNTL_ADDR (EXCHANGE_MEM_BASE+0x2A + EM_BLE_CS_OFFSET) +#define EM_BLE_TXDFANTPATTCNTL_INDEX 0x00000015 +#define EM_BLE_TXDFANTPATTCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_txdfantpattcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_txdfantpattcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_TX_ANT_PATT_LENGTH_MASK ((uint16_t)0x0000007F) +#define EM_BLE_TX_ANT_PATT_LENGTH_LSB 0 +#define EM_BLE_TX_ANT_PATT_LENGTH_WIDTH ((uint16_t)0x00000007) + +#define EM_BLE_TX_ANT_PATT_LENGTH_RST 0x0 + +__INLINE uint8_t em_ble_txdfantpattcntl_tx_ant_patt_length_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000007F)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_txdfantpattcntl_tx_ant_patt_length_setf(int elt_idx, uint8_t txantpattlength) +{ + ASSERT_ERR((((uint16_t)txantpattlength << 0) & ~((uint16_t)0x0000007F)) == 0); + EM_BLE_WR(EM_BLE_TXDFANTPATTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)txantpattlength << 0); +} + +/** + * @brief TXDFANTSWPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00    TX_ANTENNA_ID_PTR   0x0
+ * 
+ */ +#define EM_BLE_TXDFANTSWPTR_ADDR (EXCHANGE_MEM_BASE+0x2C + EM_BLE_CS_OFFSET) +#define EM_BLE_TXDFANTSWPTR_INDEX 0x00000016 +#define EM_BLE_TXDFANTSWPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_txdfantswptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXDFANTSWPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_txdfantswptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXDFANTSWPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_TX_ANTENNA_ID_PTR_MASK ((uint16_t)0x00003FFF) +#define EM_BLE_TX_ANTENNA_ID_PTR_LSB 0 +#define EM_BLE_TX_ANTENNA_ID_PTR_WIDTH ((uint16_t)0x0000000E) + +#define EM_BLE_TX_ANTENNA_ID_PTR_RST 0x0 + +__INLINE uint16_t em_ble_txdfantswptr_tx_antenna_id_ptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXDFANTSWPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_txdfantswptr_tx_antenna_id_ptr_setf(int elt_idx, uint16_t txantennaidptr) +{ + ASSERT_ERR((((uint16_t)txantennaidptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_TXDFANTSWPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)txantennaidptr << 0); +} + +/** + * @brief WINOFFSET register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00            WINOFFSET   0x0
+ * 
+ */ +#define EM_BLE_WINOFFSET_ADDR (EXCHANGE_MEM_BASE+0x2E + EM_BLE_CS_OFFSET) +#define EM_BLE_WINOFFSET_INDEX 0x00000017 +#define EM_BLE_WINOFFSET_RESET 0x00000000 + +__INLINE uint16_t em_ble_winoffset_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_WINOFFSET_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_winoffset_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_WINOFFSET_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_WINOFFSET_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_WINOFFSET_LSB 0 +#define EM_BLE_WINOFFSET_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_WINOFFSET_RST 0x0 + +__INLINE uint16_t em_ble_winoffset_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_WINOFFSET_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_winoffset_setf(int elt_idx, uint16_t winoffset) +{ + ASSERT_ERR((((uint16_t)winoffset << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_WINOFFSET_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)winoffset << 0); +} + +/** + * @brief MINEVTIME register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00            MINEVTIME   0x0
+ * 
+ */ +#define EM_BLE_MINEVTIME_ADDR (EXCHANGE_MEM_BASE+0x2E + EM_BLE_CS_OFFSET) +#define EM_BLE_MINEVTIME_INDEX 0x00000017 +#define EM_BLE_MINEVTIME_RESET 0x00000000 + +__INLINE uint16_t em_ble_minevtime_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_MINEVTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_minevtime_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_MINEVTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_MINEVTIME_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_MINEVTIME_LSB 0 +#define EM_BLE_MINEVTIME_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_MINEVTIME_RST 0x0 + +__INLINE uint16_t em_ble_minevtime_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_MINEVTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_minevtime_setf(int elt_idx, uint16_t minevtime) +{ + ASSERT_ERR((((uint16_t)minevtime << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_MINEVTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)minevtime << 0); +} + +/** + * @brief MAXEVTIME register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00            MAXEVTIME   0x0
+ * 
+ */ +#define EM_BLE_MAXEVTIME_ADDR (EXCHANGE_MEM_BASE+0x30 + EM_BLE_CS_OFFSET) +#define EM_BLE_MAXEVTIME_INDEX 0x00000018 +#define EM_BLE_MAXEVTIME_RESET 0x00000000 + +__INLINE uint16_t em_ble_maxevtime_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_MAXEVTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_maxevtime_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_MAXEVTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_MAXEVTIME_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_MAXEVTIME_LSB 0 +#define EM_BLE_MAXEVTIME_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_MAXEVTIME_RST 0x0 + +__INLINE uint16_t em_ble_maxevtime_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_MAXEVTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_maxevtime_setf(int elt_idx, uint16_t maxevtime) +{ + ASSERT_ERR((((uint16_t)maxevtime << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_MAXEVTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)maxevtime << 0); +} + +/** + * @brief CONNINTERVAL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00         CONNINTERVAL   0x0
+ * 
+ */ +#define EM_BLE_CONNINTERVAL_ADDR (EXCHANGE_MEM_BASE+0x32 + EM_BLE_CS_OFFSET) +#define EM_BLE_CONNINTERVAL_INDEX 0x00000019 +#define EM_BLE_CONNINTERVAL_RESET 0x00000000 + +__INLINE uint16_t em_ble_conninterval_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_CONNINTERVAL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_conninterval_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_CONNINTERVAL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_CONNINTERVAL_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_CONNINTERVAL_LSB 0 +#define EM_BLE_CONNINTERVAL_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_CONNINTERVAL_RST 0x0 + +__INLINE uint16_t em_ble_conninterval_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CONNINTERVAL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_conninterval_setf(int elt_idx, uint16_t conninterval) +{ + ASSERT_ERR((((uint16_t)conninterval << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_CONNINTERVAL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)conninterval << 0); +} + +/** + * @brief CHMAP0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00             LLCHMAP0   0xFFFF
+ * 
+ */ +#define EM_BLE_CHMAP0_ADDR (EXCHANGE_MEM_BASE+0x32 + EM_BLE_CS_OFFSET) +#define EM_BLE_CHMAP0_INDEX 0x00000019 +#define EM_BLE_CHMAP0_RESET 0x0000FFFF + +__INLINE uint16_t em_ble_chmap0_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_CHMAP0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_chmap0_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_CHMAP0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_LLCHMAP0_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_LLCHMAP0_LSB 0 +#define EM_BLE_LLCHMAP0_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_LLCHMAP0_RST 0xFFFF + +__INLINE uint16_t em_ble_chmap0_llchmap0_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CHMAP0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_chmap0_llchmap0_setf(int elt_idx, uint16_t llchmap0) +{ + ASSERT_ERR((((uint16_t)llchmap0 << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_CHMAP0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)llchmap0 << 0); +} + +/** + * @brief CHMAP1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00             LLCHMAP1   0xFFFF
+ * 
+ */ +#define EM_BLE_CHMAP1_ADDR (EXCHANGE_MEM_BASE+0x34 + EM_BLE_CS_OFFSET) +#define EM_BLE_CHMAP1_INDEX 0x0000001A +#define EM_BLE_CHMAP1_RESET 0x0000FFFF + +__INLINE uint16_t em_ble_chmap1_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_CHMAP1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_chmap1_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_CHMAP1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_LLCHMAP1_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_LLCHMAP1_LSB 0 +#define EM_BLE_LLCHMAP1_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_LLCHMAP1_RST 0xFFFF + +__INLINE uint16_t em_ble_chmap1_llchmap1_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CHMAP1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_chmap1_llchmap1_setf(int elt_idx, uint16_t llchmap1) +{ + ASSERT_ERR((((uint16_t)llchmap1 << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_CHMAP1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)llchmap1 << 0); +} + +/** + * @brief CHMAP2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:10               CH_AUX   0x0
+ *  07:05             ADVCHMAP   0x7
+ *  04:00             LLCHMAP2   0x1F
+ * 
+ */ +#define EM_BLE_CHMAP2_ADDR (EXCHANGE_MEM_BASE+0x36 + EM_BLE_CS_OFFSET) +#define EM_BLE_CHMAP2_INDEX 0x0000001B +#define EM_BLE_CHMAP2_RESET 0x000000FF + +__INLINE uint16_t em_ble_chmap2_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_chmap2_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_CH_AUX_MASK ((uint16_t)0x0000FC00) +#define EM_BLE_CH_AUX_LSB 10 +#define EM_BLE_CH_AUX_WIDTH ((uint16_t)0x00000006) +#define EM_BLE_ADVCHMAP_MASK ((uint16_t)0x000000E0) +#define EM_BLE_ADVCHMAP_LSB 5 +#define EM_BLE_ADVCHMAP_WIDTH ((uint16_t)0x00000003) +#define EM_BLE_LLCHMAP2_MASK ((uint16_t)0x0000001F) +#define EM_BLE_LLCHMAP2_LSB 0 +#define EM_BLE_LLCHMAP2_WIDTH ((uint16_t)0x00000005) + +#define EM_BLE_CH_AUX_RST 0x0 +#define EM_BLE_ADVCHMAP_RST 0x7 +#define EM_BLE_LLCHMAP2_RST 0x1F + +__INLINE void em_ble_chmap2_pack(int elt_idx, uint8_t chaux, uint8_t advchmap, uint8_t llchmap2) +{ + ASSERT_ERR((((uint16_t)chaux << 10) & ~((uint16_t)0x0000FC00)) == 0); + ASSERT_ERR((((uint16_t)advchmap << 5) & ~((uint16_t)0x000000E0)) == 0); + ASSERT_ERR((((uint16_t)llchmap2 << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_BLE_WR(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)chaux << 10) | ((uint16_t)advchmap << 5) | ((uint16_t)llchmap2 << 0)); +} + +__INLINE void em_ble_chmap2_unpack(int elt_idx, uint8_t* chaux, uint8_t* advchmap, uint8_t* llchmap2) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *chaux = (localVal & ((uint16_t)0x0000FC00)) >> 10; + *advchmap = (localVal & ((uint16_t)0x000000E0)) >> 5; + *llchmap2 = (localVal & ((uint16_t)0x0000001F)) >> 0; +} + +__INLINE uint8_t em_ble_chmap2_ch_aux_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000FC00)) >> 10); +} + +__INLINE void em_ble_chmap2_ch_aux_setf(int elt_idx, uint8_t chaux) +{ + ASSERT_ERR((((uint16_t)chaux << 10) & ~((uint16_t)0x0000FC00)) == 0); + EM_BLE_WR(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000FC00)) | ((uint16_t)chaux << 10)); +} + +__INLINE uint8_t em_ble_chmap2_advchmap_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x000000E0)) >> 5); +} + +__INLINE void em_ble_chmap2_advchmap_setf(int elt_idx, uint8_t advchmap) +{ + ASSERT_ERR((((uint16_t)advchmap << 5) & ~((uint16_t)0x000000E0)) == 0); + EM_BLE_WR(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x000000E0)) | ((uint16_t)advchmap << 5)); +} + +__INLINE uint8_t em_ble_chmap2_llchmap2_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000001F)) >> 0); +} + +__INLINE void em_ble_chmap2_llchmap2_setf(int elt_idx, uint8_t llchmap2) +{ + ASSERT_ERR((((uint16_t)llchmap2 << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_BLE_WR(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_CHMAP2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000001F)) | ((uint16_t)llchmap2 << 0)); +} + +/** + * @brief RXMAXAUXCHAIN register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:11          MAXRXCHDESC   0x0
+ *  10:00          MAXRXCHBYTE   0x0
+ * 
+ */ +#define EM_BLE_RXMAXAUXCHAIN_ADDR (EXCHANGE_MEM_BASE+0x38 + EM_BLE_CS_OFFSET) +#define EM_BLE_RXMAXAUXCHAIN_INDEX 0x0000001C +#define EM_BLE_RXMAXAUXCHAIN_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxmaxauxchain_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXMAXAUXCHAIN_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_rxmaxauxchain_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXMAXAUXCHAIN_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_MAXRXCHDESC_MASK ((uint16_t)0x0000F800) +#define EM_BLE_MAXRXCHDESC_LSB 11 +#define EM_BLE_MAXRXCHDESC_WIDTH ((uint16_t)0x00000005) +#define EM_BLE_MAXRXCHBYTE_MASK ((uint16_t)0x000007FF) +#define EM_BLE_MAXRXCHBYTE_LSB 0 +#define EM_BLE_MAXRXCHBYTE_WIDTH ((uint16_t)0x0000000B) + +#define EM_BLE_MAXRXCHDESC_RST 0x0 +#define EM_BLE_MAXRXCHBYTE_RST 0x0 + +__INLINE void em_ble_rxmaxauxchain_pack(int elt_idx, uint8_t maxrxchdesc, uint16_t maxrxchbyte) +{ + ASSERT_ERR((((uint16_t)maxrxchdesc << 11) & ~((uint16_t)0x0000F800)) == 0); + ASSERT_ERR((((uint16_t)maxrxchbyte << 0) & ~((uint16_t)0x000007FF)) == 0); + EM_BLE_WR(EM_BLE_RXMAXAUXCHAIN_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)maxrxchdesc << 11) | ((uint16_t)maxrxchbyte << 0)); +} + +__INLINE void em_ble_rxmaxauxchain_unpack(int elt_idx, uint8_t* maxrxchdesc, uint16_t* maxrxchbyte) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXMAXAUXCHAIN_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *maxrxchdesc = (localVal & ((uint16_t)0x0000F800)) >> 11; + *maxrxchbyte = (localVal & ((uint16_t)0x000007FF)) >> 0; +} + +__INLINE uint8_t em_ble_rxmaxauxchain_maxrxchdesc_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXMAXAUXCHAIN_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000F800)) >> 11); +} + +__INLINE void em_ble_rxmaxauxchain_maxrxchdesc_setf(int elt_idx, uint8_t maxrxchdesc) +{ + ASSERT_ERR((((uint16_t)maxrxchdesc << 11) & ~((uint16_t)0x0000F800)) == 0); + EM_BLE_WR(EM_BLE_RXMAXAUXCHAIN_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXMAXAUXCHAIN_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000F800)) | ((uint16_t)maxrxchdesc << 11)); +} + +__INLINE uint16_t em_ble_rxmaxauxchain_maxrxchbyte_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXMAXAUXCHAIN_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x000007FF)) >> 0); +} + +__INLINE void em_ble_rxmaxauxchain_maxrxchbyte_setf(int elt_idx, uint16_t maxrxchbyte) +{ + ASSERT_ERR((((uint16_t)maxrxchbyte << 0) & ~((uint16_t)0x000007FF)) == 0); + EM_BLE_WR(EM_BLE_RXMAXAUXCHAIN_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXMAXAUXCHAIN_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x000007FF)) | ((uint16_t)maxrxchbyte << 0)); +} + +/** + * @brief RXMAXBUF register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08          ISORXMAXBUF   0x0
+ *  07:00          ACLRXMAXBUF   0x0
+ * 
+ */ +#define EM_BLE_RXMAXBUF_ADDR (EXCHANGE_MEM_BASE+0x38 + EM_BLE_CS_OFFSET) +#define EM_BLE_RXMAXBUF_INDEX 0x0000001C +#define EM_BLE_RXMAXBUF_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxmaxbuf_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXMAXBUF_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_rxmaxbuf_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXMAXBUF_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_ISORXMAXBUF_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_ISORXMAXBUF_LSB 8 +#define EM_BLE_ISORXMAXBUF_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_ACLRXMAXBUF_MASK ((uint16_t)0x000000FF) +#define EM_BLE_ACLRXMAXBUF_LSB 0 +#define EM_BLE_ACLRXMAXBUF_WIDTH ((uint16_t)0x00000008) + +#define EM_BLE_ISORXMAXBUF_RST 0x0 +#define EM_BLE_ACLRXMAXBUF_RST 0x0 + +__INLINE void em_ble_rxmaxbuf_pack(int elt_idx, uint8_t isorxmaxbuf, uint8_t aclrxmaxbuf) +{ + ASSERT_ERR((((uint16_t)isorxmaxbuf << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)aclrxmaxbuf << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_RXMAXBUF_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)isorxmaxbuf << 8) | ((uint16_t)aclrxmaxbuf << 0)); +} + +__INLINE void em_ble_rxmaxbuf_unpack(int elt_idx, uint8_t* isorxmaxbuf, uint8_t* aclrxmaxbuf) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXMAXBUF_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *isorxmaxbuf = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *aclrxmaxbuf = (localVal & ((uint16_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t em_ble_rxmaxbuf_isorxmaxbuf_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXMAXBUF_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_rxmaxbuf_isorxmaxbuf_setf(int elt_idx, uint8_t isorxmaxbuf) +{ + ASSERT_ERR((((uint16_t)isorxmaxbuf << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_RXMAXBUF_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXMAXBUF_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)isorxmaxbuf << 8)); +} + +__INLINE uint8_t em_ble_rxmaxbuf_aclrxmaxbuf_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXMAXBUF_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x000000FF)) >> 0); +} + +__INLINE void em_ble_rxmaxbuf_aclrxmaxbuf_setf(int elt_idx, uint8_t aclrxmaxbuf) +{ + ASSERT_ERR((((uint16_t)aclrxmaxbuf << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_RXMAXBUF_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_RXMAXBUF_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x000000FF)) | ((uint16_t)aclrxmaxbuf << 0)); +} + +/** + * @brief RXMAXTIME register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  12:00            RXMAXTIME   0x0
+ * 
+ */ +#define EM_BLE_RXMAXTIME_ADDR (EXCHANGE_MEM_BASE+0x3A + EM_BLE_CS_OFFSET) +#define EM_BLE_RXMAXTIME_INDEX 0x0000001D +#define EM_BLE_RXMAXTIME_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxmaxtime_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXMAXTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_rxmaxtime_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXMAXTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_RXMAXTIME_MASK ((uint16_t)0x00001FFF) +#define EM_BLE_RXMAXTIME_LSB 0 +#define EM_BLE_RXMAXTIME_WIDTH ((uint16_t)0x0000000D) + +#define EM_BLE_RXMAXTIME_RST 0x0 + +__INLINE uint16_t em_ble_rxmaxtime_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXMAXTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00001FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_rxmaxtime_setf(int elt_idx, uint16_t rxmaxtime) +{ + ASSERT_ERR((((uint16_t)rxmaxtime << 0) & ~((uint16_t)0x00001FFF)) == 0); + EM_BLE_WR(EM_BLE_RXMAXTIME_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)rxmaxtime << 0); +} + +/** + * @brief SK register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00                   SK   0x0
+ * 
+ */ +#define EM_BLE_SK_ADDR (EXCHANGE_MEM_BASE+0x3C + EM_BLE_CS_OFFSET) +#define EM_BLE_SK_INDEX 0x0000001E +#define EM_BLE_SK_RESET 0x00000000 +#define EM_BLE_SK_COUNT 8 + +__INLINE uint16_t em_ble_sk_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 7); + return EM_BLE_RD(EM_BLE_SK_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_sk_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 7); + EM_BLE_WR(EM_BLE_SK_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_SK_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_SK_LSB 0 +#define EM_BLE_SK_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_SK_RST 0x0 + +__INLINE uint16_t em_ble_sk_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 7); + uint16_t localVal = EM_BLE_RD(EM_BLE_SK_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_sk_setf(int elt_idx, int reg_idx, uint16_t sk) +{ + ASSERT_ERR(reg_idx <= 7); + ASSERT_ERR((((uint16_t)sk << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_SK_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2, (uint16_t)sk << 0); +} + +/** + * @brief ADV_BD_ADDR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00          ADV_BD_ADDR   0x0
+ * 
+ */ +#define EM_BLE_ADV_BD_ADDR_ADDR (EXCHANGE_MEM_BASE+0x3C + EM_BLE_CS_OFFSET) +#define EM_BLE_ADV_BD_ADDR_INDEX 0x0000001E +#define EM_BLE_ADV_BD_ADDR_RESET 0x00000000 +#define EM_BLE_ADV_BD_ADDR_COUNT 3 + +__INLINE uint16_t em_ble_adv_bd_addr_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + return EM_BLE_RD(EM_BLE_ADV_BD_ADDR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_adv_bd_addr_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 2); + EM_BLE_WR(EM_BLE_ADV_BD_ADDR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_ADV_BD_ADDR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_ADV_BD_ADDR_LSB 0 +#define EM_BLE_ADV_BD_ADDR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_ADV_BD_ADDR_RST 0x0 + +__INLINE uint16_t em_ble_adv_bd_addr_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + uint16_t localVal = EM_BLE_RD(EM_BLE_ADV_BD_ADDR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_adv_bd_addr_setf(int elt_idx, int reg_idx, uint16_t advbdaddr) +{ + ASSERT_ERR(reg_idx <= 2); + ASSERT_ERR((((uint16_t)advbdaddr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_ADV_BD_ADDR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2, (uint16_t)advbdaddr << 0); +} + +/** + * @brief PEER_RALPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00          PEER_RALPTR   0x0
+ * 
+ */ +#define EM_BLE_PEER_RALPTR_ADDR (EXCHANGE_MEM_BASE+0x3C + EM_BLE_CS_OFFSET) +#define EM_BLE_PEER_RALPTR_INDEX 0x0000001E +#define EM_BLE_PEER_RALPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_peer_ralptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_PEER_RALPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_peer_ralptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_PEER_RALPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_PEER_RALPTR_MASK ((uint16_t)0x00003FFF) +#define EM_BLE_PEER_RALPTR_LSB 0 +#define EM_BLE_PEER_RALPTR_WIDTH ((uint16_t)0x0000000E) + +#define EM_BLE_PEER_RALPTR_RST 0x0 + +__INLINE uint16_t em_ble_peer_ralptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_PEER_RALPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_peer_ralptr_setf(int elt_idx, uint16_t peerralptr) +{ + ASSERT_ERR((((uint16_t)peerralptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_PEER_RALPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)peerralptr << 0); +} + +/** + * @brief ADV_BD_ADDR_TYPE register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     00     ADV_BD_ADDR_TYPE   0
+ * 
+ */ +#define EM_BLE_ADV_BD_ADDR_TYPE_ADDR (EXCHANGE_MEM_BASE+0x42 + EM_BLE_CS_OFFSET) +#define EM_BLE_ADV_BD_ADDR_TYPE_INDEX 0x00000021 +#define EM_BLE_ADV_BD_ADDR_TYPE_RESET 0x00000000 + +__INLINE uint16_t em_ble_adv_bd_addr_type_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_ADV_BD_ADDR_TYPE_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_adv_bd_addr_type_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_ADV_BD_ADDR_TYPE_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_ADV_BD_ADDR_TYPE_BIT ((uint16_t)0x00000001) +#define EM_BLE_ADV_BD_ADDR_TYPE_POS 0 + +#define EM_BLE_ADV_BD_ADDR_TYPE_RST 0x0 + +__INLINE uint8_t em_ble_adv_bd_addr_type_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ADV_BD_ADDR_TYPE_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00000001)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_adv_bd_addr_type_setf(int elt_idx, uint8_t advbdaddrtype) +{ + ASSERT_ERR((((uint16_t)advbdaddrtype << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_ADV_BD_ADDR_TYPE_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)advbdaddrtype << 0); +} + +/** + * @brief AUXTXDESCPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00         AUXTXDESCPTR   0x0
+ * 
+ */ +#define EM_BLE_AUXTXDESCPTR_ADDR (EXCHANGE_MEM_BASE+0x44 + EM_BLE_CS_OFFSET) +#define EM_BLE_AUXTXDESCPTR_INDEX 0x00000022 +#define EM_BLE_AUXTXDESCPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_auxtxdescptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_AUXTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_auxtxdescptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_AUXTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_AUXTXDESCPTR_MASK ((uint16_t)0x00003FFF) +#define EM_BLE_AUXTXDESCPTR_LSB 0 +#define EM_BLE_AUXTXDESCPTR_WIDTH ((uint16_t)0x0000000E) + +#define EM_BLE_AUXTXDESCPTR_RST 0x0 + +__INLINE uint16_t em_ble_auxtxdescptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_AUXTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_auxtxdescptr_setf(int elt_idx, uint16_t auxtxdescptr) +{ + ASSERT_ERR((((uint16_t)auxtxdescptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_AUXTXDESCPTR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)auxtxdescptr << 0); +} + +/** + * @brief IV register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00                   IV   0x0
+ * 
+ */ +#define EM_BLE_IV_ADDR (EXCHANGE_MEM_BASE+0x4C + EM_BLE_CS_OFFSET) +#define EM_BLE_IV_INDEX 0x00000026 +#define EM_BLE_IV_RESET 0x00000000 +#define EM_BLE_IV_COUNT 4 + +__INLINE uint16_t em_ble_iv_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 3); + return EM_BLE_RD(EM_BLE_IV_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_iv_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 3); + EM_BLE_WR(EM_BLE_IV_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_IV_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_IV_LSB 0 +#define EM_BLE_IV_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_IV_RST 0x0 + +__INLINE uint16_t em_ble_iv_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 3); + uint16_t localVal = EM_BLE_RD(EM_BLE_IV_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_iv_setf(int elt_idx, int reg_idx, uint16_t iv) +{ + ASSERT_ERR(reg_idx <= 3); + ASSERT_ERR((((uint16_t)iv << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_IV_ADDR + elt_idx * REG_EM_BLE_CS_SIZE + reg_idx * 2, (uint16_t)iv << 0); +} + +/** + * @brief WINOFFSET_2M register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00         WINOFFSET_2M   0x0
+ * 
+ */ +#define EM_BLE_WINOFFSET_2M_ADDR (EXCHANGE_MEM_BASE+0x46 + EM_BLE_CS_OFFSET) +#define EM_BLE_WINOFFSET_2M_INDEX 0x00000023 +#define EM_BLE_WINOFFSET_2M_RESET 0x00000000 + +__INLINE uint16_t em_ble_winoffset_2m_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_WINOFFSET_2M_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_winoffset_2m_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_WINOFFSET_2M_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_WINOFFSET_2M_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_WINOFFSET_2M_LSB 0 +#define EM_BLE_WINOFFSET_2M_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_WINOFFSET_2M_RST 0x0 + +__INLINE uint16_t em_ble_winoffset_2m_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_WINOFFSET_2M_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_winoffset_2m_setf(int elt_idx, uint16_t winoffset2m) +{ + ASSERT_ERR((((uint16_t)winoffset2m << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_WINOFFSET_2M_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)winoffset2m << 0); +} + +/** + * @brief CONNINTERVAL_2M register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00      CONNINTERVAL_2M   0x0
+ * 
+ */ +#define EM_BLE_CONNINTERVAL_2M_ADDR (EXCHANGE_MEM_BASE+0x48 + EM_BLE_CS_OFFSET) +#define EM_BLE_CONNINTERVAL_2M_INDEX 0x00000024 +#define EM_BLE_CONNINTERVAL_2M_RESET 0x00000000 + +__INLINE uint16_t em_ble_conninterval_2m_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_CONNINTERVAL_2M_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_conninterval_2m_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_CONNINTERVAL_2M_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_CONNINTERVAL_2M_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_CONNINTERVAL_2M_LSB 0 +#define EM_BLE_CONNINTERVAL_2M_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_CONNINTERVAL_2M_RST 0x0 + +__INLINE uint16_t em_ble_conninterval_2m_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CONNINTERVAL_2M_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_conninterval_2m_setf(int elt_idx, uint16_t conninterval2m) +{ + ASSERT_ERR((((uint16_t)conninterval2m << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_CONNINTERVAL_2M_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)conninterval2m << 0); +} + +/** + * @brief WINOFFSET_LR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00         WINOFFSET_LR   0x0
+ * 
+ */ +#define EM_BLE_WINOFFSET_LR_ADDR (EXCHANGE_MEM_BASE+0x4A + EM_BLE_CS_OFFSET) +#define EM_BLE_WINOFFSET_LR_INDEX 0x00000025 +#define EM_BLE_WINOFFSET_LR_RESET 0x00000000 + +__INLINE uint16_t em_ble_winoffset_lr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_WINOFFSET_LR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_winoffset_lr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_WINOFFSET_LR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_WINOFFSET_LR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_WINOFFSET_LR_LSB 0 +#define EM_BLE_WINOFFSET_LR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_WINOFFSET_LR_RST 0x0 + +__INLINE uint16_t em_ble_winoffset_lr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_WINOFFSET_LR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_winoffset_lr_setf(int elt_idx, uint16_t winoffsetlr) +{ + ASSERT_ERR((((uint16_t)winoffsetlr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_WINOFFSET_LR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)winoffsetlr << 0); +} + +/** + * @brief CONNINTERVAL_LR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00      CONNINTERVAL_LR   0x0
+ * 
+ */ +#define EM_BLE_CONNINTERVAL_LR_ADDR (EXCHANGE_MEM_BASE+0x4C + EM_BLE_CS_OFFSET) +#define EM_BLE_CONNINTERVAL_LR_INDEX 0x00000026 +#define EM_BLE_CONNINTERVAL_LR_RESET 0x00000000 + +__INLINE uint16_t em_ble_conninterval_lr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_CONNINTERVAL_LR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_conninterval_lr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_CONNINTERVAL_LR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_CONNINTERVAL_LR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_CONNINTERVAL_LR_LSB 0 +#define EM_BLE_CONNINTERVAL_LR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_CONNINTERVAL_LR_RST 0x0 + +__INLINE uint16_t em_ble_conninterval_lr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_CONNINTERVAL_LR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_conninterval_lr_setf(int elt_idx, uint16_t connintervallr) +{ + ASSERT_ERR((((uint16_t)connintervallr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_CONNINTERVAL_LR_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)connintervallr << 0); +} + +/** + * @brief TXWINOFFSET register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00          TXWINOFFSET   0x0
+ * 
+ */ +#define EM_BLE_TXWINOFFSET_ADDR (EXCHANGE_MEM_BASE+0x54 + EM_BLE_CS_OFFSET) +#define EM_BLE_TXWINOFFSET_INDEX 0x0000002A +#define EM_BLE_TXWINOFFSET_RESET 0x00000000 + +__INLINE uint16_t em_ble_txwinoffset_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXWINOFFSET_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_txwinoffset_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXWINOFFSET_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_TXWINOFFSET_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_TXWINOFFSET_LSB 0 +#define EM_BLE_TXWINOFFSET_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_TXWINOFFSET_RST 0x0 + +__INLINE uint16_t em_ble_txwinoffset_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXWINOFFSET_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_txwinoffset_setf(int elt_idx, uint16_t txwinoffset) +{ + ASSERT_ERR((((uint16_t)txwinoffset << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_TXWINOFFSET_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)txwinoffset << 0); +} + +/** + * @brief TXCCMPKTCNT0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00         TXCCMPKTCNT0   0x0
+ * 
+ */ +#define EM_BLE_TXCCMPKTCNT0_ADDR (EXCHANGE_MEM_BASE+0x54 + EM_BLE_CS_OFFSET) +#define EM_BLE_TXCCMPKTCNT0_INDEX 0x0000002A +#define EM_BLE_TXCCMPKTCNT0_RESET 0x00000000 + +__INLINE uint16_t em_ble_txccmpktcnt0_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXCCMPKTCNT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_txccmpktcnt0_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXCCMPKTCNT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_TXCCMPKTCNT0_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_TXCCMPKTCNT0_LSB 0 +#define EM_BLE_TXCCMPKTCNT0_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_TXCCMPKTCNT0_RST 0x0 + +__INLINE uint16_t em_ble_txccmpktcnt0_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXCCMPKTCNT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_txccmpktcnt0_setf(int elt_idx, uint16_t txccmpktcnt0) +{ + ASSERT_ERR((((uint16_t)txccmpktcnt0 << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_TXCCMPKTCNT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)txccmpktcnt0 << 0); +} + +/** + * @brief EXTADVSTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     07             PREV_CTE   0
+ *     06             PREV_PAM   0
+ *     05             PREV_LAM   0
+ *  04:03        PREV_ADV_MODE   0x0
+ *  02:00    PREV_ADV_PKT_TYPE   0x0
+ * 
+ */ +#define EM_BLE_EXTADVSTAT_ADDR (EXCHANGE_MEM_BASE+0x56 + EM_BLE_CS_OFFSET) +#define EM_BLE_EXTADVSTAT_INDEX 0x0000002B +#define EM_BLE_EXTADVSTAT_RESET 0x00000000 + +__INLINE uint16_t em_ble_extadvstat_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_extadvstat_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_PREV_CTE_BIT ((uint16_t)0x00000080) +#define EM_BLE_PREV_CTE_POS 7 +#define EM_BLE_PREV_PAM_BIT ((uint16_t)0x00000040) +#define EM_BLE_PREV_PAM_POS 6 +#define EM_BLE_PREV_LAM_BIT ((uint16_t)0x00000020) +#define EM_BLE_PREV_LAM_POS 5 +#define EM_BLE_PREV_ADV_MODE_MASK ((uint16_t)0x00000018) +#define EM_BLE_PREV_ADV_MODE_LSB 3 +#define EM_BLE_PREV_ADV_MODE_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_PREV_ADV_PKT_TYPE_MASK ((uint16_t)0x00000007) +#define EM_BLE_PREV_ADV_PKT_TYPE_LSB 0 +#define EM_BLE_PREV_ADV_PKT_TYPE_WIDTH ((uint16_t)0x00000003) + +#define EM_BLE_PREV_CTE_RST 0x0 +#define EM_BLE_PREV_PAM_RST 0x0 +#define EM_BLE_PREV_LAM_RST 0x0 +#define EM_BLE_PREV_ADV_MODE_RST 0x0 +#define EM_BLE_PREV_ADV_PKT_TYPE_RST 0x0 + +__INLINE void em_ble_extadvstat_pack(int elt_idx, uint8_t prevcte, uint8_t prevpam, uint8_t prevlam, uint8_t prevadvmode, uint8_t prevadvpkttype) +{ + ASSERT_ERR((((uint16_t)prevcte << 7) & ~((uint16_t)0x00000080)) == 0); + ASSERT_ERR((((uint16_t)prevpam << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)prevlam << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)prevadvmode << 3) & ~((uint16_t)0x00000018)) == 0); + ASSERT_ERR((((uint16_t)prevadvpkttype << 0) & ~((uint16_t)0x00000007)) == 0); + EM_BLE_WR(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)prevcte << 7) | ((uint16_t)prevpam << 6) | ((uint16_t)prevlam << 5) | ((uint16_t)prevadvmode << 3) | ((uint16_t)prevadvpkttype << 0)); +} + +__INLINE void em_ble_extadvstat_unpack(int elt_idx, uint8_t* prevcte, uint8_t* prevpam, uint8_t* prevlam, uint8_t* prevadvmode, uint8_t* prevadvpkttype) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *prevcte = (localVal & ((uint16_t)0x00000080)) >> 7; + *prevpam = (localVal & ((uint16_t)0x00000040)) >> 6; + *prevlam = (localVal & ((uint16_t)0x00000020)) >> 5; + *prevadvmode = (localVal & ((uint16_t)0x00000018)) >> 3; + *prevadvpkttype = (localVal & ((uint16_t)0x00000007)) >> 0; +} + +__INLINE uint8_t em_ble_extadvstat_prev_cte_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000080)) >> 7); +} + +__INLINE void em_ble_extadvstat_prev_cte_setf(int elt_idx, uint8_t prevcte) +{ + ASSERT_ERR((((uint16_t)prevcte << 7) & ~((uint16_t)0x00000080)) == 0); + EM_BLE_WR(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000080)) | ((uint16_t)prevcte << 7)); +} + +__INLINE uint8_t em_ble_extadvstat_prev_pam_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_ble_extadvstat_prev_pam_setf(int elt_idx, uint8_t prevpam) +{ + ASSERT_ERR((((uint16_t)prevpam << 6) & ~((uint16_t)0x00000040)) == 0); + EM_BLE_WR(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)prevpam << 6)); +} + +__INLINE uint8_t em_ble_extadvstat_prev_lam_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_extadvstat_prev_lam_setf(int elt_idx, uint8_t prevlam) +{ + ASSERT_ERR((((uint16_t)prevlam << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)prevlam << 5)); +} + +__INLINE uint8_t em_ble_extadvstat_prev_adv_mode_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000018)) >> 3); +} + +__INLINE void em_ble_extadvstat_prev_adv_mode_setf(int elt_idx, uint8_t prevadvmode) +{ + ASSERT_ERR((((uint16_t)prevadvmode << 3) & ~((uint16_t)0x00000018)) == 0); + EM_BLE_WR(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000018)) | ((uint16_t)prevadvmode << 3)); +} + +__INLINE uint8_t em_ble_extadvstat_prev_adv_pkt_type_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000007)) >> 0); +} + +__INLINE void em_ble_extadvstat_prev_adv_pkt_type_setf(int elt_idx, uint8_t prevadvpkttype) +{ + ASSERT_ERR((((uint16_t)prevadvpkttype << 0) & ~((uint16_t)0x00000007)) == 0); + EM_BLE_WR(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_EXTADVSTAT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000007)) | ((uint16_t)prevadvpkttype << 0)); +} + +/** + * @brief TXCCMPKTCNT1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00         TXCCMPKTCNT1   0x0
+ * 
+ */ +#define EM_BLE_TXCCMPKTCNT1_ADDR (EXCHANGE_MEM_BASE+0x56 + EM_BLE_CS_OFFSET) +#define EM_BLE_TXCCMPKTCNT1_INDEX 0x0000002B +#define EM_BLE_TXCCMPKTCNT1_RESET 0x00000000 + +__INLINE uint16_t em_ble_txccmpktcnt1_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXCCMPKTCNT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_txccmpktcnt1_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXCCMPKTCNT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_TXCCMPKTCNT1_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_TXCCMPKTCNT1_LSB 0 +#define EM_BLE_TXCCMPKTCNT1_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_TXCCMPKTCNT1_RST 0x0 + +__INLINE uint16_t em_ble_txccmpktcnt1_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXCCMPKTCNT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_txccmpktcnt1_setf(int elt_idx, uint16_t txccmpktcnt1) +{ + ASSERT_ERR((((uint16_t)txccmpktcnt1 << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_TXCCMPKTCNT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)txccmpktcnt1 << 0); +} + +/** + * @brief TXCCMPKTCNT2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  06:00         TXCCMPKTCNT2   0x0
+ * 
+ */ +#define EM_BLE_TXCCMPKTCNT2_ADDR (EXCHANGE_MEM_BASE+0x58 + EM_BLE_CS_OFFSET) +#define EM_BLE_TXCCMPKTCNT2_INDEX 0x0000002C +#define EM_BLE_TXCCMPKTCNT2_RESET 0x00000000 + +__INLINE uint16_t em_ble_txccmpktcnt2_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXCCMPKTCNT2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_txccmpktcnt2_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXCCMPKTCNT2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_TXCCMPKTCNT2_MASK ((uint16_t)0x0000007F) +#define EM_BLE_TXCCMPKTCNT2_LSB 0 +#define EM_BLE_TXCCMPKTCNT2_WIDTH ((uint16_t)0x00000007) + +#define EM_BLE_TXCCMPKTCNT2_RST 0x0 + +__INLINE uint8_t em_ble_txccmpktcnt2_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXCCMPKTCNT2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000007F)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_txccmpktcnt2_setf(int elt_idx, uint8_t txccmpktcnt2) +{ + ASSERT_ERR((((uint16_t)txccmpktcnt2 << 0) & ~((uint16_t)0x0000007F)) == 0); + EM_BLE_WR(EM_BLE_TXCCMPKTCNT2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)txccmpktcnt2 << 0); +} + +/** + * @brief RXCCMPKTCNT0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00         RXCCMPKTCNT0   0x0
+ * 
+ */ +#define EM_BLE_RXCCMPKTCNT0_ADDR (EXCHANGE_MEM_BASE+0x5A + EM_BLE_CS_OFFSET) +#define EM_BLE_RXCCMPKTCNT0_INDEX 0x0000002D +#define EM_BLE_RXCCMPKTCNT0_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxccmpktcnt0_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXCCMPKTCNT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_rxccmpktcnt0_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXCCMPKTCNT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_RXCCMPKTCNT0_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_RXCCMPKTCNT0_LSB 0 +#define EM_BLE_RXCCMPKTCNT0_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_RXCCMPKTCNT0_RST 0x0 + +__INLINE uint16_t em_ble_rxccmpktcnt0_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCCMPKTCNT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_rxccmpktcnt0_setf(int elt_idx, uint16_t rxccmpktcnt0) +{ + ASSERT_ERR((((uint16_t)rxccmpktcnt0 << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RXCCMPKTCNT0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)rxccmpktcnt0 << 0); +} + +/** + * @brief RXCCMPKTCNT1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00         RXCCMPKTCNT1   0x0
+ * 
+ */ +#define EM_BLE_RXCCMPKTCNT1_ADDR (EXCHANGE_MEM_BASE+0x5C + EM_BLE_CS_OFFSET) +#define EM_BLE_RXCCMPKTCNT1_INDEX 0x0000002E +#define EM_BLE_RXCCMPKTCNT1_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxccmpktcnt1_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXCCMPKTCNT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_rxccmpktcnt1_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXCCMPKTCNT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_RXCCMPKTCNT1_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_RXCCMPKTCNT1_LSB 0 +#define EM_BLE_RXCCMPKTCNT1_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_RXCCMPKTCNT1_RST 0x0 + +__INLINE uint16_t em_ble_rxccmpktcnt1_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCCMPKTCNT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_rxccmpktcnt1_setf(int elt_idx, uint16_t rxccmpktcnt1) +{ + ASSERT_ERR((((uint16_t)rxccmpktcnt1 << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RXCCMPKTCNT1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)rxccmpktcnt1 << 0); +} + +/** + * @brief RXCCMPKTCNT2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  06:00         RXCCMPKTCNT2   0x0
+ * 
+ */ +#define EM_BLE_RXCCMPKTCNT2_ADDR (EXCHANGE_MEM_BASE+0x5E + EM_BLE_CS_OFFSET) +#define EM_BLE_RXCCMPKTCNT2_INDEX 0x0000002F +#define EM_BLE_RXCCMPKTCNT2_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxccmpktcnt2_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXCCMPKTCNT2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_rxccmpktcnt2_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXCCMPKTCNT2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_RXCCMPKTCNT2_MASK ((uint16_t)0x0000007F) +#define EM_BLE_RXCCMPKTCNT2_LSB 0 +#define EM_BLE_RXCCMPKTCNT2_WIDTH ((uint16_t)0x00000007) + +#define EM_BLE_RXCCMPKTCNT2_RST 0x0 + +__INLINE uint8_t em_ble_rxccmpktcnt2_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCCMPKTCNT2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000007F)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_rxccmpktcnt2_setf(int elt_idx, uint8_t rxccmpktcnt2) +{ + ASSERT_ERR((((uint16_t)rxccmpktcnt2 << 0) & ~((uint16_t)0x0000007F)) == 0); + EM_BLE_WR(EM_BLE_RXCCMPKTCNT2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)rxccmpktcnt2 << 0); +} + +/** + * @brief EVTCNT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00               EVTCNT   0x0
+ * 
+ */ +#define EM_BLE_EVTCNT_ADDR (EXCHANGE_MEM_BASE+0x60 + EM_BLE_CS_OFFSET) +#define EM_BLE_EVTCNT_INDEX 0x00000030 +#define EM_BLE_EVTCNT_RESET 0x00000000 + +__INLINE uint16_t em_ble_evtcnt_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_EVTCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_evtcnt_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_EVTCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_EVTCNT_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_EVTCNT_LSB 0 +#define EM_BLE_EVTCNT_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_EVTCNT_RST 0x0 + +__INLINE uint16_t em_ble_evtcnt_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_EVTCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_evtcnt_setf(int elt_idx, uint16_t evtcnt) +{ + ASSERT_ERR((((uint16_t)evtcnt << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_EVTCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)evtcnt << 0); +} + +/** + * @brief EVTCNT_OFFSET0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00       EVTCNT_OFFSET0   0x0
+ * 
+ */ +#define EM_BLE_EVTCNT_OFFSET0_ADDR (EXCHANGE_MEM_BASE+0x62 + EM_BLE_CS_OFFSET) +#define EM_BLE_EVTCNT_OFFSET0_INDEX 0x00000031 +#define EM_BLE_EVTCNT_OFFSET0_RESET 0x00000000 + +__INLINE uint16_t em_ble_evtcnt_offset0_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_EVTCNT_OFFSET0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_evtcnt_offset0_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_EVTCNT_OFFSET0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_EVTCNT_OFFSET0_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_EVTCNT_OFFSET0_LSB 0 +#define EM_BLE_EVTCNT_OFFSET0_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_EVTCNT_OFFSET0_RST 0x0 + +__INLINE uint16_t em_ble_evtcnt_offset0_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_EVTCNT_OFFSET0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_evtcnt_offset0_setf(int elt_idx, uint16_t evtcntoffset0) +{ + ASSERT_ERR((((uint16_t)evtcntoffset0 << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_EVTCNT_OFFSET0_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)evtcntoffset0 << 0); +} + +/** + * @brief EVTCNT_OFFSET1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00       EVTCNT_OFFSET1   0x0
+ * 
+ */ +#define EM_BLE_EVTCNT_OFFSET1_ADDR (EXCHANGE_MEM_BASE+0x64 + EM_BLE_CS_OFFSET) +#define EM_BLE_EVTCNT_OFFSET1_INDEX 0x00000032 +#define EM_BLE_EVTCNT_OFFSET1_RESET 0x00000000 + +__INLINE uint16_t em_ble_evtcnt_offset1_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_EVTCNT_OFFSET1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_evtcnt_offset1_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_EVTCNT_OFFSET1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_EVTCNT_OFFSET1_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_EVTCNT_OFFSET1_LSB 0 +#define EM_BLE_EVTCNT_OFFSET1_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_EVTCNT_OFFSET1_RST 0x0 + +__INLINE uint16_t em_ble_evtcnt_offset1_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_EVTCNT_OFFSET1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_evtcnt_offset1_setf(int elt_idx, uint16_t evtcntoffset1) +{ + ASSERT_ERR((((uint16_t)evtcntoffset1 << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_EVTCNT_OFFSET1_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)evtcntoffset1 << 0); +} + +/** + * @brief EVTCNT_OFFSET2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  06:00       EVTCNT_OFFSET2   0x0
+ * 
+ */ +#define EM_BLE_EVTCNT_OFFSET2_ADDR (EXCHANGE_MEM_BASE+0x66 + EM_BLE_CS_OFFSET) +#define EM_BLE_EVTCNT_OFFSET2_INDEX 0x00000033 +#define EM_BLE_EVTCNT_OFFSET2_RESET 0x00000000 + +__INLINE uint16_t em_ble_evtcnt_offset2_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_EVTCNT_OFFSET2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_evtcnt_offset2_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_EVTCNT_OFFSET2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_EVTCNT_OFFSET2_MASK ((uint16_t)0x0000007F) +#define EM_BLE_EVTCNT_OFFSET2_LSB 0 +#define EM_BLE_EVTCNT_OFFSET2_WIDTH ((uint16_t)0x00000007) + +#define EM_BLE_EVTCNT_OFFSET2_RST 0x0 + +__INLINE uint8_t em_ble_evtcnt_offset2_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_EVTCNT_OFFSET2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000007F)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_evtcnt_offset2_setf(int elt_idx, uint8_t evtcntoffset2) +{ + ASSERT_ERR((((uint16_t)evtcntoffset2 << 0) & ~((uint16_t)0x0000007F)) == 0); + EM_BLE_WR(EM_BLE_EVTCNT_OFFSET2_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (uint16_t)evtcntoffset2 << 0); +} + +/** + * @brief ISOEVTCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08             FLUSHCNT   0x0
+ *  07:00            SUBEVTCNT   0x0
+ * 
+ */ +#define EM_BLE_ISOEVTCNTL_ADDR (EXCHANGE_MEM_BASE+0x68 + EM_BLE_CS_OFFSET) +#define EM_BLE_ISOEVTCNTL_INDEX 0x00000034 +#define EM_BLE_ISOEVTCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_isoevtcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_ISOEVTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_isoevtcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_ISOEVTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_FLUSHCNT_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_FLUSHCNT_LSB 8 +#define EM_BLE_FLUSHCNT_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_SUBEVTCNT_MASK ((uint16_t)0x000000FF) +#define EM_BLE_SUBEVTCNT_LSB 0 +#define EM_BLE_SUBEVTCNT_WIDTH ((uint16_t)0x00000008) + +#define EM_BLE_FLUSHCNT_RST 0x0 +#define EM_BLE_SUBEVTCNT_RST 0x0 + +__INLINE void em_ble_isoevtcntl_pack(int elt_idx, uint8_t flushcnt, uint8_t subevtcnt) +{ + ASSERT_ERR((((uint16_t)flushcnt << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)subevtcnt << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_ISOEVTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)flushcnt << 8) | ((uint16_t)subevtcnt << 0)); +} + +__INLINE void em_ble_isoevtcntl_unpack(int elt_idx, uint8_t* flushcnt, uint8_t* subevtcnt) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOEVTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *flushcnt = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *subevtcnt = (localVal & ((uint16_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t em_ble_isoevtcntl_flushcnt_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOEVTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_isoevtcntl_flushcnt_setf(int elt_idx, uint8_t flushcnt) +{ + ASSERT_ERR((((uint16_t)flushcnt << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_ISOEVTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOEVTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)flushcnt << 8)); +} + +__INLINE uint8_t em_ble_isoevtcntl_subevtcnt_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOEVTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x000000FF)) >> 0); +} + +__INLINE void em_ble_isoevtcntl_subevtcnt_setf(int elt_idx, uint8_t subevtcnt) +{ + ASSERT_ERR((((uint16_t)subevtcnt << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_ISOEVTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOEVTCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x000000FF)) | ((uint16_t)subevtcnt << 0)); +} + +/** + * @brief ISOTXRXCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15       ISORXBUFF_FULL   0
+ *     14         ISOLASTEMPTY   0
+ *     13                ISOMD   0
+ *     12                ISOSN   0
+ *     11              ISONESN   0
+ *     09              ISORETX   0
+ *     08              ISORSVD   0
+ *     03           ISOWAITACK   0
+ *     02            ISOLASTMD   0
+ *     01          ISOLASTNESN   0
+ *     00            ISOLASTSN   0
+ * 
+ */ +#define EM_BLE_ISOTXRXCNTL_ADDR (EXCHANGE_MEM_BASE+0x6A + EM_BLE_CS_OFFSET) +#define EM_BLE_ISOTXRXCNTL_INDEX 0x00000035 +#define EM_BLE_ISOTXRXCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_isotxrxcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +__INLINE void em_ble_isotxrxcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, value); +} + +// field definitions +#define EM_BLE_ISORXBUFF_FULL_BIT ((uint16_t)0x00008000) +#define EM_BLE_ISORXBUFF_FULL_POS 15 +#define EM_BLE_ISOLASTEMPTY_BIT ((uint16_t)0x00004000) +#define EM_BLE_ISOLASTEMPTY_POS 14 +#define EM_BLE_ISOMD_BIT ((uint16_t)0x00002000) +#define EM_BLE_ISOMD_POS 13 +#define EM_BLE_ISOSN_BIT ((uint16_t)0x00001000) +#define EM_BLE_ISOSN_POS 12 +#define EM_BLE_ISONESN_BIT ((uint16_t)0x00000800) +#define EM_BLE_ISONESN_POS 11 +#define EM_BLE_ISORETX_BIT ((uint16_t)0x00000200) +#define EM_BLE_ISORETX_POS 9 +#define EM_BLE_ISORSVD_BIT ((uint16_t)0x00000100) +#define EM_BLE_ISORSVD_POS 8 +#define EM_BLE_ISOWAITACK_BIT ((uint16_t)0x00000008) +#define EM_BLE_ISOWAITACK_POS 3 +#define EM_BLE_ISOLASTMD_BIT ((uint16_t)0x00000004) +#define EM_BLE_ISOLASTMD_POS 2 +#define EM_BLE_ISOLASTNESN_BIT ((uint16_t)0x00000002) +#define EM_BLE_ISOLASTNESN_POS 1 +#define EM_BLE_ISOLASTSN_BIT ((uint16_t)0x00000001) +#define EM_BLE_ISOLASTSN_POS 0 + +#define EM_BLE_ISORXBUFF_FULL_RST 0x0 +#define EM_BLE_ISOLASTEMPTY_RST 0x0 +#define EM_BLE_ISOMD_RST 0x0 +#define EM_BLE_ISOSN_RST 0x0 +#define EM_BLE_ISONESN_RST 0x0 +#define EM_BLE_ISORETX_RST 0x0 +#define EM_BLE_ISORSVD_RST 0x0 +#define EM_BLE_ISOWAITACK_RST 0x0 +#define EM_BLE_ISOLASTMD_RST 0x0 +#define EM_BLE_ISOLASTNESN_RST 0x0 +#define EM_BLE_ISOLASTSN_RST 0x0 + +__INLINE void em_ble_isotxrxcntl_pack(int elt_idx, uint8_t isorxbufffull, uint8_t isolastempty, uint8_t isomd, uint8_t isosn, uint8_t isonesn, uint8_t isoretx, uint8_t isorsvd, uint8_t isowaitack, uint8_t isolastmd, uint8_t isolastnesn, uint8_t isolastsn) +{ + ASSERT_ERR((((uint16_t)isorxbufffull << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)isolastempty << 14) & ~((uint16_t)0x00004000)) == 0); + ASSERT_ERR((((uint16_t)isomd << 13) & ~((uint16_t)0x00002000)) == 0); + ASSERT_ERR((((uint16_t)isosn << 12) & ~((uint16_t)0x00001000)) == 0); + ASSERT_ERR((((uint16_t)isonesn << 11) & ~((uint16_t)0x00000800)) == 0); + ASSERT_ERR((((uint16_t)isoretx << 9) & ~((uint16_t)0x00000200)) == 0); + ASSERT_ERR((((uint16_t)isorsvd << 8) & ~((uint16_t)0x00000100)) == 0); + ASSERT_ERR((((uint16_t)isowaitack << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)isolastmd << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)isolastnesn << 1) & ~((uint16_t)0x00000002)) == 0); + ASSERT_ERR((((uint16_t)isolastsn << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, ((uint16_t)isorxbufffull << 15) | ((uint16_t)isolastempty << 14) | ((uint16_t)isomd << 13) | ((uint16_t)isosn << 12) | ((uint16_t)isonesn << 11) | ((uint16_t)isoretx << 9) | ((uint16_t)isorsvd << 8) | ((uint16_t)isowaitack << 3) | ((uint16_t)isolastmd << 2) | ((uint16_t)isolastnesn << 1) | ((uint16_t)isolastsn << 0)); +} + +__INLINE void em_ble_isotxrxcntl_unpack(int elt_idx, uint8_t* isorxbufffull, uint8_t* isolastempty, uint8_t* isomd, uint8_t* isosn, uint8_t* isonesn, uint8_t* isoretx, uint8_t* isorsvd, uint8_t* isowaitack, uint8_t* isolastmd, uint8_t* isolastnesn, uint8_t* isolastsn) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *isorxbufffull = (localVal & ((uint16_t)0x00008000)) >> 15; + *isolastempty = (localVal & ((uint16_t)0x00004000)) >> 14; + *isomd = (localVal & ((uint16_t)0x00002000)) >> 13; + *isosn = (localVal & ((uint16_t)0x00001000)) >> 12; + *isonesn = (localVal & ((uint16_t)0x00000800)) >> 11; + *isoretx = (localVal & ((uint16_t)0x00000200)) >> 9; + *isorsvd = (localVal & ((uint16_t)0x00000100)) >> 8; + *isowaitack = (localVal & ((uint16_t)0x00000008)) >> 3; + *isolastmd = (localVal & ((uint16_t)0x00000004)) >> 2; + *isolastnesn = (localVal & ((uint16_t)0x00000002)) >> 1; + *isolastsn = (localVal & ((uint16_t)0x00000001)) >> 0; +} + +__INLINE uint8_t em_ble_isotxrxcntl_isorxbuff_full_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_isotxrxcntl_isorxbuff_full_setf(int elt_idx, uint8_t isorxbufffull) +{ + ASSERT_ERR((((uint16_t)isorxbufffull << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)isorxbufffull << 15)); +} + +__INLINE uint8_t em_ble_isotxrxcntl_isolastempty_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00004000)) >> 14); +} + +__INLINE void em_ble_isotxrxcntl_isolastempty_setf(int elt_idx, uint8_t isolastempty) +{ + ASSERT_ERR((((uint16_t)isolastempty << 14) & ~((uint16_t)0x00004000)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00004000)) | ((uint16_t)isolastempty << 14)); +} + +__INLINE uint8_t em_ble_isotxrxcntl_isomd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00002000)) >> 13); +} + +__INLINE void em_ble_isotxrxcntl_isomd_setf(int elt_idx, uint8_t isomd) +{ + ASSERT_ERR((((uint16_t)isomd << 13) & ~((uint16_t)0x00002000)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00002000)) | ((uint16_t)isomd << 13)); +} + +__INLINE uint8_t em_ble_isotxrxcntl_isosn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00001000)) >> 12); +} + +__INLINE void em_ble_isotxrxcntl_isosn_setf(int elt_idx, uint8_t isosn) +{ + ASSERT_ERR((((uint16_t)isosn << 12) & ~((uint16_t)0x00001000)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00001000)) | ((uint16_t)isosn << 12)); +} + +__INLINE uint8_t em_ble_isotxrxcntl_isonesn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000800)) >> 11); +} + +__INLINE void em_ble_isotxrxcntl_isonesn_setf(int elt_idx, uint8_t isonesn) +{ + ASSERT_ERR((((uint16_t)isonesn << 11) & ~((uint16_t)0x00000800)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000800)) | ((uint16_t)isonesn << 11)); +} + +__INLINE uint8_t em_ble_isotxrxcntl_isoretx_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000200)) >> 9); +} + +__INLINE void em_ble_isotxrxcntl_isoretx_setf(int elt_idx, uint8_t isoretx) +{ + ASSERT_ERR((((uint16_t)isoretx << 9) & ~((uint16_t)0x00000200)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000200)) | ((uint16_t)isoretx << 9)); +} + +__INLINE uint8_t em_ble_isotxrxcntl_isorsvd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000100)) >> 8); +} + +__INLINE void em_ble_isotxrxcntl_isorsvd_setf(int elt_idx, uint8_t isorsvd) +{ + ASSERT_ERR((((uint16_t)isorsvd << 8) & ~((uint16_t)0x00000100)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000100)) | ((uint16_t)isorsvd << 8)); +} + +__INLINE uint8_t em_ble_isotxrxcntl_isowaitack_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_isotxrxcntl_isowaitack_setf(int elt_idx, uint8_t isowaitack) +{ + ASSERT_ERR((((uint16_t)isowaitack << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)isowaitack << 3)); +} + +__INLINE uint8_t em_ble_isotxrxcntl_isolastmd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_isotxrxcntl_isolastmd_setf(int elt_idx, uint8_t isolastmd) +{ + ASSERT_ERR((((uint16_t)isolastmd << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)isolastmd << 2)); +} + +__INLINE uint8_t em_ble_isotxrxcntl_isolastnesn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000002)) >> 1); +} + +__INLINE void em_ble_isotxrxcntl_isolastnesn_setf(int elt_idx, uint8_t isolastnesn) +{ + ASSERT_ERR((((uint16_t)isolastnesn << 1) & ~((uint16_t)0x00000002)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000002)) | ((uint16_t)isolastnesn << 1)); +} + +__INLINE uint8_t em_ble_isotxrxcntl_isolastsn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x00000001)) >> 0); +} + +__INLINE void em_ble_isotxrxcntl_isolastsn_setf(int elt_idx, uint8_t isolastsn) +{ + ASSERT_ERR((((uint16_t)isolastsn << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE, (EM_BLE_RD(EM_BLE_ISOTXRXCNTL_ADDR + elt_idx * REG_EM_BLE_CS_SIZE) & ~((uint16_t)0x00000001)) | ((uint16_t)isolastsn << 0)); +} + +/** + * @brief TXRXDESCCNT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08         ACLRXDESCCNT   0x0
+ *  07:00         ACLTXDESCCNT   0x0
+ * 
+ */ +#define EM_BLE_TXRXDESCCNT_ADDR (EXCHANGE_MEM_BASE+0x6C + EM_BLE_CS_OFFSET) +#define EM_BLE_TXRXDESCCNT_INDEX 0x00000036 +#define EM_BLE_TXRXDESCCNT_RESET 0x00000000 + +__INLINE uint16_t em_ble_txrxdesccnt_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXRXDESCCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +// field definitions +#define EM_BLE_ACLRXDESCCNT_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_ACLRXDESCCNT_LSB 8 +#define EM_BLE_ACLRXDESCCNT_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_ACLTXDESCCNT_MASK ((uint16_t)0x000000FF) +#define EM_BLE_ACLTXDESCCNT_LSB 0 +#define EM_BLE_ACLTXDESCCNT_WIDTH ((uint16_t)0x00000008) + +#define EM_BLE_ACLRXDESCCNT_RST 0x0 +#define EM_BLE_ACLTXDESCCNT_RST 0x0 + +__INLINE void em_ble_txrxdesccnt_unpack(int elt_idx, uint8_t* aclrxdesccnt, uint8_t* acltxdesccnt) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXDESCCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *aclrxdesccnt = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *acltxdesccnt = (localVal & ((uint16_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t em_ble_txrxdesccnt_aclrxdesccnt_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXDESCCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE uint8_t em_ble_txrxdesccnt_acltxdesccnt_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXRXDESCCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x000000FF)) >> 0); +} + +/** + * @brief ISOTXRXPKTCNT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08         ISORXPKTCNTL   0x0
+ *  07:00         ISOTXPKTCNTL   0x0
+ * 
+ */ +#define EM_BLE_ISOTXRXPKTCNT_ADDR (EXCHANGE_MEM_BASE+0x6E + EM_BLE_CS_OFFSET) +#define EM_BLE_ISOTXRXPKTCNT_INDEX 0x00000037 +#define EM_BLE_ISOTXRXPKTCNT_RESET 0x00000000 + +__INLINE uint16_t em_ble_isotxrxpktcnt_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_ISOTXRXPKTCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); +} + +// field definitions +#define EM_BLE_ISORXPKTCNTL_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_ISORXPKTCNTL_LSB 8 +#define EM_BLE_ISORXPKTCNTL_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_ISOTXPKTCNTL_MASK ((uint16_t)0x000000FF) +#define EM_BLE_ISOTXPKTCNTL_LSB 0 +#define EM_BLE_ISOTXPKTCNTL_WIDTH ((uint16_t)0x00000008) + +#define EM_BLE_ISORXPKTCNTL_RST 0x0 +#define EM_BLE_ISOTXPKTCNTL_RST 0x0 + +__INLINE void em_ble_isotxrxpktcnt_unpack(int elt_idx, uint8_t* isorxpktcntl, uint8_t* isotxpktcntl) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXPKTCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + + *isorxpktcntl = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *isotxpktcntl = (localVal & ((uint16_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t em_ble_isotxrxpktcnt_isorxpktcntl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXPKTCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE uint8_t em_ble_isotxrxpktcnt_isotxpktcntl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_ISOTXRXPKTCNT_ADDR + elt_idx * REG_EM_BLE_CS_SIZE); + return ((localVal & ((uint16_t)0x000000FF)) >> 0); +} + + +#endif // _REG_EM_BLE_CS_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_ral.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_ral.h new file mode 100644 index 0000000..4a7c0c6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_ral.h @@ -0,0 +1,547 @@ +#ifndef _REG_EM_BLE_RAL_H_ +#define _REG_EM_BLE_RAL_H_ + +#include +#include "_reg_em_ble_ral.h" +#include "compiler.h" +#include "arch.h" +#include "em_map.h" +#include "reg_access.h" + +#define REG_EM_BLE_RAL_COUNT 28 + +#define REG_EM_BLE_RAL_DECODING_MASK 0x0000003F + +#define REG_EM_BLE_RAL_ADDR_GET(idx) (EM_BLE_RAL_OFFSET + (idx) * REG_EM_BLE_RAL_SIZE) + +/** + * @brief RAL_INFO register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15          ENTRY_VALID   0
+ *     14            CONNECTED   0
+ *     13            IN_WHLIST   0
+ *     12       IN_PERADV_LIST   0
+ *     11                  PEF   0
+ *     07      LOCAL_RPA_VALID   0
+ *     06      LOCAL_RPA_RENEW   0
+ *     05      LOCAL_IRK_VALID   0
+ *     03       PEER_RPA_VALID   0
+ *     02       PEER_RPA_RENEW   0
+ *     01       PEER_IRK_VALID   0
+ *     00         PEER_ID_TYPE   0
+ * 
+ */ +#define EM_BLE_RAL_INFO_ADDR (EXCHANGE_MEM_BASE + EM_BLE_RAL_OFFSET) +#define EM_BLE_RAL_INFO_INDEX 0x00000000 +#define EM_BLE_RAL_INFO_RESET 0x00000000 + +__INLINE uint16_t em_ble_ral_info_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); +} + +__INLINE void em_ble_ral_info_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, value); +} + +// field definitions +#define EM_BLE_ENTRY_VALID_BIT ((uint16_t)0x00008000) +#define EM_BLE_ENTRY_VALID_POS 15 +#define EM_BLE_CONNECTED_BIT ((uint16_t)0x00004000) +#define EM_BLE_CONNECTED_POS 14 +#define EM_BLE_IN_WHLIST_BIT ((uint16_t)0x00002000) +#define EM_BLE_IN_WHLIST_POS 13 +#define EM_BLE_IN_PERADV_LIST_BIT ((uint16_t)0x00001000) +#define EM_BLE_IN_PERADV_LIST_POS 12 +#define EM_BLE_PEF_BIT ((uint16_t)0x00000800) +#define EM_BLE_PEF_POS 11 +#define EM_BLE_LOCAL_RPA_VALID_BIT ((uint16_t)0x00000080) +#define EM_BLE_LOCAL_RPA_VALID_POS 7 +#define EM_BLE_LOCAL_RPA_RENEW_BIT ((uint16_t)0x00000040) +#define EM_BLE_LOCAL_RPA_RENEW_POS 6 +#define EM_BLE_LOCAL_IRK_VALID_BIT ((uint16_t)0x00000020) +#define EM_BLE_LOCAL_IRK_VALID_POS 5 +#define EM_BLE_PEER_RPA_VALID_BIT ((uint16_t)0x00000008) +#define EM_BLE_PEER_RPA_VALID_POS 3 +#define EM_BLE_PEER_RPA_RENEW_BIT ((uint16_t)0x00000004) +#define EM_BLE_PEER_RPA_RENEW_POS 2 +#define EM_BLE_PEER_IRK_VALID_BIT ((uint16_t)0x00000002) +#define EM_BLE_PEER_IRK_VALID_POS 1 +#define EM_BLE_PEER_ID_TYPE_BIT ((uint16_t)0x00000001) +#define EM_BLE_PEER_ID_TYPE_POS 0 + +#define EM_BLE_ENTRY_VALID_RST 0x0 +#define EM_BLE_CONNECTED_RST 0x0 +#define EM_BLE_IN_WHLIST_RST 0x0 +#define EM_BLE_IN_PERADV_LIST_RST 0x0 +#define EM_BLE_PEF_RST 0x0 +#define EM_BLE_LOCAL_RPA_VALID_RST 0x0 +#define EM_BLE_LOCAL_RPA_RENEW_RST 0x0 +#define EM_BLE_LOCAL_IRK_VALID_RST 0x0 +#define EM_BLE_PEER_RPA_VALID_RST 0x0 +#define EM_BLE_PEER_RPA_RENEW_RST 0x0 +#define EM_BLE_PEER_IRK_VALID_RST 0x0 +#define EM_BLE_PEER_ID_TYPE_RST 0x0 + +__INLINE void em_ble_ral_info_pack(int elt_idx, uint8_t entryvalid, uint8_t connected, uint8_t inwhlist, uint8_t inperadvlist, uint8_t pef, uint8_t localrpavalid, uint8_t localrparenew, uint8_t localirkvalid, uint8_t peerrpavalid, uint8_t peerrparenew, uint8_t peerirkvalid, uint8_t peeridtype) +{ + ASSERT_ERR((((uint16_t)entryvalid << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)connected << 14) & ~((uint16_t)0x00004000)) == 0); + ASSERT_ERR((((uint16_t)inwhlist << 13) & ~((uint16_t)0x00002000)) == 0); + ASSERT_ERR((((uint16_t)inperadvlist << 12) & ~((uint16_t)0x00001000)) == 0); + ASSERT_ERR((((uint16_t)pef << 11) & ~((uint16_t)0x00000800)) == 0); + ASSERT_ERR((((uint16_t)localrpavalid << 7) & ~((uint16_t)0x00000080)) == 0); + ASSERT_ERR((((uint16_t)localrparenew << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)localirkvalid << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)peerrpavalid << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)peerrparenew << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)peerirkvalid << 1) & ~((uint16_t)0x00000002)) == 0); + ASSERT_ERR((((uint16_t)peeridtype << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, ((uint16_t)entryvalid << 15) | ((uint16_t)connected << 14) | ((uint16_t)inwhlist << 13) | ((uint16_t)inperadvlist << 12) | ((uint16_t)pef << 11) | ((uint16_t)localrpavalid << 7) | ((uint16_t)localrparenew << 6) | ((uint16_t)localirkvalid << 5) | ((uint16_t)peerrpavalid << 3) | ((uint16_t)peerrparenew << 2) | ((uint16_t)peerirkvalid << 1) | ((uint16_t)peeridtype << 0)); +} + +__INLINE void em_ble_ral_info_unpack(int elt_idx, uint8_t* entryvalid, uint8_t* connected, uint8_t* inwhlist, uint8_t* inperadvlist, uint8_t* pef, uint8_t* localrpavalid, uint8_t* localrparenew, uint8_t* localirkvalid, uint8_t* peerrpavalid, uint8_t* peerrparenew, uint8_t* peerirkvalid, uint8_t* peeridtype) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + + *entryvalid = (localVal & ((uint16_t)0x00008000)) >> 15; + *connected = (localVal & ((uint16_t)0x00004000)) >> 14; + *inwhlist = (localVal & ((uint16_t)0x00002000)) >> 13; + *inperadvlist = (localVal & ((uint16_t)0x00001000)) >> 12; + *pef = (localVal & ((uint16_t)0x00000800)) >> 11; + *localrpavalid = (localVal & ((uint16_t)0x00000080)) >> 7; + *localrparenew = (localVal & ((uint16_t)0x00000040)) >> 6; + *localirkvalid = (localVal & ((uint16_t)0x00000020)) >> 5; + *peerrpavalid = (localVal & ((uint16_t)0x00000008)) >> 3; + *peerrparenew = (localVal & ((uint16_t)0x00000004)) >> 2; + *peerirkvalid = (localVal & ((uint16_t)0x00000002)) >> 1; + *peeridtype = (localVal & ((uint16_t)0x00000001)) >> 0; +} + +__INLINE uint8_t em_ble_ral_info_entry_valid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_ral_info_entry_valid_setf(int elt_idx, uint8_t entryvalid) +{ + ASSERT_ERR((((uint16_t)entryvalid << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)entryvalid << 15)); +} + +__INLINE uint8_t em_ble_ral_info_connected_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00004000)) >> 14); +} + +__INLINE void em_ble_ral_info_connected_setf(int elt_idx, uint8_t connected) +{ + ASSERT_ERR((((uint16_t)connected << 14) & ~((uint16_t)0x00004000)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00004000)) | ((uint16_t)connected << 14)); +} + +__INLINE uint8_t em_ble_ral_info_in_whlist_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00002000)) >> 13); +} + +__INLINE void em_ble_ral_info_in_whlist_setf(int elt_idx, uint8_t inwhlist) +{ + ASSERT_ERR((((uint16_t)inwhlist << 13) & ~((uint16_t)0x00002000)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00002000)) | ((uint16_t)inwhlist << 13)); +} + +__INLINE uint8_t em_ble_ral_info_in_peradv_list_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00001000)) >> 12); +} + +__INLINE void em_ble_ral_info_in_peradv_list_setf(int elt_idx, uint8_t inperadvlist) +{ + ASSERT_ERR((((uint16_t)inperadvlist << 12) & ~((uint16_t)0x00001000)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00001000)) | ((uint16_t)inperadvlist << 12)); +} + +__INLINE uint8_t em_ble_ral_info_pef_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00000800)) >> 11); +} + +__INLINE void em_ble_ral_info_pef_setf(int elt_idx, uint8_t pef) +{ + ASSERT_ERR((((uint16_t)pef << 11) & ~((uint16_t)0x00000800)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00000800)) | ((uint16_t)pef << 11)); +} + +__INLINE uint8_t em_ble_ral_info_local_rpa_valid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00000080)) >> 7); +} + +__INLINE void em_ble_ral_info_local_rpa_valid_setf(int elt_idx, uint8_t localrpavalid) +{ + ASSERT_ERR((((uint16_t)localrpavalid << 7) & ~((uint16_t)0x00000080)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00000080)) | ((uint16_t)localrpavalid << 7)); +} + +__INLINE uint8_t em_ble_ral_info_local_rpa_renew_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_ble_ral_info_local_rpa_renew_setf(int elt_idx, uint8_t localrparenew) +{ + ASSERT_ERR((((uint16_t)localrparenew << 6) & ~((uint16_t)0x00000040)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)localrparenew << 6)); +} + +__INLINE uint8_t em_ble_ral_info_local_irk_valid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_ral_info_local_irk_valid_setf(int elt_idx, uint8_t localirkvalid) +{ + ASSERT_ERR((((uint16_t)localirkvalid << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)localirkvalid << 5)); +} + +__INLINE uint8_t em_ble_ral_info_peer_rpa_valid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_ral_info_peer_rpa_valid_setf(int elt_idx, uint8_t peerrpavalid) +{ + ASSERT_ERR((((uint16_t)peerrpavalid << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)peerrpavalid << 3)); +} + +__INLINE uint8_t em_ble_ral_info_peer_rpa_renew_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_ral_info_peer_rpa_renew_setf(int elt_idx, uint8_t peerrparenew) +{ + ASSERT_ERR((((uint16_t)peerrparenew << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)peerrparenew << 2)); +} + +__INLINE uint8_t em_ble_ral_info_peer_irk_valid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00000002)) >> 1); +} + +__INLINE void em_ble_ral_info_peer_irk_valid_setf(int elt_idx, uint8_t peerirkvalid) +{ + ASSERT_ERR((((uint16_t)peerirkvalid << 1) & ~((uint16_t)0x00000002)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00000002)) | ((uint16_t)peerirkvalid << 1)); +} + +__INLINE uint8_t em_ble_ral_info_peer_id_type_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + return ((localVal & ((uint16_t)0x00000001)) >> 0); +} + +__INLINE void em_ble_ral_info_peer_id_type_setf(int elt_idx, uint8_t peeridtype) +{ + ASSERT_ERR((((uint16_t)peeridtype << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (EM_BLE_RD(EM_BLE_RAL_INFO_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE) & ~((uint16_t)0x00000001)) | ((uint16_t)peeridtype << 0)); +} + +/** + * @brief RAL_PEER_SID register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00         RAL_PEER_SID   0x0
+ * 
+ */ +#define EM_BLE_RAL_PEER_SID_ADDR (EXCHANGE_MEM_BASE+0x02 + EM_BLE_RAL_OFFSET) +#define EM_BLE_RAL_PEER_SID_INDEX 0x00000001 +#define EM_BLE_RAL_PEER_SID_RESET 0x00000000 + +__INLINE uint16_t em_ble_ral_peer_sid_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RAL_PEER_SID_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); +} + +__INLINE void em_ble_ral_peer_sid_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RAL_PEER_SID_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, value); +} + +// field definitions +#define EM_BLE_RAL_PEER_SID_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_RAL_PEER_SID_LSB 0 +#define EM_BLE_RAL_PEER_SID_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_RAL_PEER_SID_RST 0x0 + +__INLINE uint16_t em_ble_ral_peer_sid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_PEER_SID_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_ral_peer_sid_setf(int elt_idx, uint16_t ralpeersid) +{ + ASSERT_ERR((((uint16_t)ralpeersid << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RAL_PEER_SID_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE, (uint16_t)ralpeersid << 0); +} + +/** + * @brief RAL_PEER_IRK register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00             PEER_IRK   0x0
+ * 
+ */ +#define EM_BLE_RAL_PEER_IRK_ADDR (EXCHANGE_MEM_BASE+0x04 + EM_BLE_RAL_OFFSET) +#define EM_BLE_RAL_PEER_IRK_INDEX 0x00000002 +#define EM_BLE_RAL_PEER_IRK_RESET 0x00000000 +#define EM_BLE_RAL_PEER_IRK_COUNT 8 + +__INLINE uint16_t em_ble_ral_peer_irk_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 7); + return EM_BLE_RD(EM_BLE_RAL_PEER_IRK_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_ral_peer_irk_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 7); + EM_BLE_WR(EM_BLE_RAL_PEER_IRK_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_PEER_IRK_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_PEER_IRK_LSB 0 +#define EM_BLE_PEER_IRK_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_PEER_IRK_RST 0x0 + +__INLINE uint16_t em_ble_ral_peer_irk_peer_irk_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 7); + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_PEER_IRK_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_ral_peer_irk_peer_irk_setf(int elt_idx, int reg_idx, uint16_t peerirk) +{ + ASSERT_ERR(reg_idx <= 7); + ASSERT_ERR((((uint16_t)peerirk << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RAL_PEER_IRK_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2, (uint16_t)peerirk << 0); +} + +/** + * @brief RAL_PEER_RPA register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00             PEER_RPA   0x0
+ * 
+ */ +#define EM_BLE_RAL_PEER_RPA_ADDR (EXCHANGE_MEM_BASE+0x14 + EM_BLE_RAL_OFFSET) +#define EM_BLE_RAL_PEER_RPA_INDEX 0x0000000A +#define EM_BLE_RAL_PEER_RPA_RESET 0x00000000 +#define EM_BLE_RAL_PEER_RPA_COUNT 3 + +__INLINE uint16_t em_ble_ral_peer_rpa_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + return EM_BLE_RD(EM_BLE_RAL_PEER_RPA_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_ral_peer_rpa_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 2); + EM_BLE_WR(EM_BLE_RAL_PEER_RPA_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_PEER_RPA_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_PEER_RPA_LSB 0 +#define EM_BLE_PEER_RPA_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_PEER_RPA_RST 0x0 + +__INLINE uint16_t em_ble_ral_peer_rpa_peer_rpa_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_PEER_RPA_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_ral_peer_rpa_peer_rpa_setf(int elt_idx, int reg_idx, uint16_t peerrpa) +{ + ASSERT_ERR(reg_idx <= 2); + ASSERT_ERR((((uint16_t)peerrpa << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RAL_PEER_RPA_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2, (uint16_t)peerrpa << 0); +} + +/** + * @brief RAL_PEER_ID register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00              PEER_ID   0x0
+ * 
+ */ +#define EM_BLE_RAL_PEER_ID_ADDR (EXCHANGE_MEM_BASE+0x1A + EM_BLE_RAL_OFFSET) +#define EM_BLE_RAL_PEER_ID_INDEX 0x0000000D +#define EM_BLE_RAL_PEER_ID_RESET 0x00000000 +#define EM_BLE_RAL_PEER_ID_COUNT 3 + +__INLINE uint16_t em_ble_ral_peer_id_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + return EM_BLE_RD(EM_BLE_RAL_PEER_ID_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_ral_peer_id_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 2); + EM_BLE_WR(EM_BLE_RAL_PEER_ID_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_PEER_ID_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_PEER_ID_LSB 0 +#define EM_BLE_PEER_ID_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_PEER_ID_RST 0x0 + +__INLINE uint16_t em_ble_ral_peer_id_peer_id_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_PEER_ID_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_ral_peer_id_peer_id_setf(int elt_idx, int reg_idx, uint16_t peerid) +{ + ASSERT_ERR(reg_idx <= 2); + ASSERT_ERR((((uint16_t)peerid << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RAL_PEER_ID_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2, (uint16_t)peerid << 0); +} + +/** + * @brief RAL_LOCAL_IRK register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00            LOCAL_IRK   0x0
+ * 
+ */ +#define EM_BLE_RAL_LOCAL_IRK_ADDR (EXCHANGE_MEM_BASE+0x20 + EM_BLE_RAL_OFFSET) +#define EM_BLE_RAL_LOCAL_IRK_INDEX 0x00000010 +#define EM_BLE_RAL_LOCAL_IRK_RESET 0x00000000 +#define EM_BLE_RAL_LOCAL_IRK_COUNT 8 + +__INLINE uint16_t em_ble_ral_local_irk_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 7); + return EM_BLE_RD(EM_BLE_RAL_LOCAL_IRK_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_ral_local_irk_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 7); + EM_BLE_WR(EM_BLE_RAL_LOCAL_IRK_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_LOCAL_IRK_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_LOCAL_IRK_LSB 0 +#define EM_BLE_LOCAL_IRK_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_LOCAL_IRK_RST 0x0 + +__INLINE uint16_t em_ble_ral_local_irk_local_irk_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 7); + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_LOCAL_IRK_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_ral_local_irk_local_irk_setf(int elt_idx, int reg_idx, uint16_t localirk) +{ + ASSERT_ERR(reg_idx <= 7); + ASSERT_ERR((((uint16_t)localirk << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RAL_LOCAL_IRK_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2, (uint16_t)localirk << 0); +} + +/** + * @brief RAL_LOCAL_RPA register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00            LOCAL_RPA   0x0
+ * 
+ */ +#define EM_BLE_RAL_LOCAL_RPA_ADDR (EXCHANGE_MEM_BASE+0x30 + EM_BLE_RAL_OFFSET) +#define EM_BLE_RAL_LOCAL_RPA_INDEX 0x00000018 +#define EM_BLE_RAL_LOCAL_RPA_RESET 0x00000000 +#define EM_BLE_RAL_LOCAL_RPA_COUNT 3 + +__INLINE uint16_t em_ble_ral_local_rpa_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + return EM_BLE_RD(EM_BLE_RAL_LOCAL_RPA_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_ral_local_rpa_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 2); + EM_BLE_WR(EM_BLE_RAL_LOCAL_RPA_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_LOCAL_RPA_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_LOCAL_RPA_LSB 0 +#define EM_BLE_LOCAL_RPA_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_LOCAL_RPA_RST 0x0 + +__INLINE uint16_t em_ble_ral_local_rpa_local_rpa_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + uint16_t localVal = EM_BLE_RD(EM_BLE_RAL_LOCAL_RPA_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_ral_local_rpa_local_rpa_setf(int elt_idx, int reg_idx, uint16_t localrpa) +{ + ASSERT_ERR(reg_idx <= 2); + ASSERT_ERR((((uint16_t)localrpa << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RAL_LOCAL_RPA_ADDR + elt_idx * REG_EM_BLE_RAL_SIZE + reg_idx * 2, (uint16_t)localrpa << 0); +} + + +#endif // _REG_EM_BLE_RAL_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_rx_cte_desc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_rx_cte_desc.h new file mode 100644 index 0000000..d8d64d2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_rx_cte_desc.h @@ -0,0 +1,173 @@ +#ifndef _REG_EM_BLE_RX_CTE_DESC_H_ +#define _REG_EM_BLE_RX_CTE_DESC_H_ + +#include +#include "_reg_em_ble_rx_cte_desc.h" +#include "compiler.h" +#include "arch.h" +#include "em_map.h" +#include "reg_access.h" + +#define REG_EM_BLE_RX_CTE_DESC_COUNT 3 + +#define REG_EM_BLE_RX_CTE_DESC_DECODING_MASK 0x00000007 + +#define REG_EM_BLE_RX_CTE_DESC_ADDR_GET(idx) (EM_BLE_RX_CTE_DESC_OFFSET + (idx) * REG_EM_BLE_RX_CTE_DESC_SIZE) + +/** + * @brief RXCTECNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15               RXDONE   0
+ *  13:00            RXNEXTPTR   0x0
+ * 
+ */ +#define EM_BLE_RXCTECNTL_ADDR (EXCHANGE_MEM_BASE + EM_BLE_RX_CTE_DESC_OFFSET) +#define EM_BLE_RXCTECNTL_INDEX 0x00000000 +#define EM_BLE_RXCTECNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxctecntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXCTECNTL_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE); +} + +__INLINE void em_ble_rxctecntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXCTECNTL_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXDONE_BIT ((uint16_t)0x00008000) +#define EM_BLE_RXDONE_POS 15 +#define EM_BLE_RXNEXTPTR_MASK ((uint16_t)0x00003FFF) +#define EM_BLE_RXNEXTPTR_LSB 0 +#define EM_BLE_RXNEXTPTR_WIDTH ((uint16_t)0x0000000E) + +#define EM_BLE_RXDONE_RST 0x0 +#define EM_BLE_RXNEXTPTR_RST 0x0 + +__INLINE void em_ble_rxctecntl_pack(int elt_idx, uint8_t rxdone, uint16_t rxnextptr) +{ + ASSERT_ERR((((uint16_t)rxdone << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)rxnextptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_RXCTECNTL_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE, ((uint16_t)rxdone << 15) | ((uint16_t)rxnextptr << 0)); +} + +__INLINE void em_ble_rxctecntl_unpack(int elt_idx, uint8_t* rxdone, uint16_t* rxnextptr) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCTECNTL_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE); + + *rxdone = (localVal & ((uint16_t)0x00008000)) >> 15; + *rxnextptr = (localVal & ((uint16_t)0x00003FFF)) >> 0; +} + +__INLINE uint8_t em_ble_rxctecntl_rxdone_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCTECNTL_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_rxctecntl_rxdone_setf(int elt_idx, uint8_t rxdone) +{ + ASSERT_ERR((((uint16_t)rxdone << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_RXCTECNTL_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXCTECNTL_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)rxdone << 15)); +} + +__INLINE uint16_t em_ble_rxctecntl_rxnextptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCTECNTL_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE); + return ((localVal & ((uint16_t)0x00003FFF)) >> 0); +} + +__INLINE void em_ble_rxctecntl_rxnextptr_setf(int elt_idx, uint16_t rxnextptr) +{ + ASSERT_ERR((((uint16_t)rxnextptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_RXCTECNTL_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXCTECNTL_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE) & ~((uint16_t)0x00003FFF)) | ((uint16_t)rxnextptr << 0)); +} + +/** + * @brief RXCTESAMPBUF register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08                 RX_Q   0x0
+ *  07:00                 RX_I   0x0
+ * 
+ */ +#define EM_BLE_RXCTESAMPBUF_ADDR (EXCHANGE_MEM_BASE+0x04 + EM_BLE_RX_CTE_DESC_OFFSET) +#define EM_BLE_RXCTESAMPBUF_INDEX 0x00000002 +#define EM_BLE_RXCTESAMPBUF_RESET 0x00000000 +#define EM_BLE_RXCTESAMPBUF_COUNT 82 + +__INLINE uint16_t em_ble_rxctesampbuf_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 81); + return EM_BLE_RD(EM_BLE_RXCTESAMPBUF_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_rxctesampbuf_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 81); + EM_BLE_WR(EM_BLE_RXCTESAMPBUF_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_RX_Q_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_RX_Q_LSB 8 +#define EM_BLE_RX_Q_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_RX_I_MASK ((uint16_t)0x000000FF) +#define EM_BLE_RX_I_LSB 0 +#define EM_BLE_RX_I_WIDTH ((uint16_t)0x00000008) + +#define EM_BLE_RX_Q_RST 0x0 +#define EM_BLE_RX_I_RST 0x0 + +__INLINE void em_ble_rxctesampbuf_pack(int elt_idx, int reg_idx, uint8_t rxq, uint8_t rxi) +{ + ASSERT_ERR(reg_idx <= 81); + ASSERT_ERR((((uint16_t)rxq << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)rxi << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_RXCTESAMPBUF_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE + reg_idx * 2, ((uint16_t)rxq << 8) | ((uint16_t)rxi << 0)); +} + +__INLINE void em_ble_rxctesampbuf_unpack(int elt_idx, int reg_idx, uint8_t* rxq, uint8_t* rxi) +{ + ASSERT_ERR(reg_idx <= 81); + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCTESAMPBUF_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE + reg_idx * 2); + + *rxq = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *rxi = (localVal & ((uint16_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t em_ble_rxctesampbuf_rx_q_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 81); + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCTESAMPBUF_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE + reg_idx * 2); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_rxctesampbuf_rx_q_setf(int elt_idx, int reg_idx, uint8_t rxq) +{ + ASSERT_ERR(reg_idx <= 81); + ASSERT_ERR((((uint16_t)rxq << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_RXCTESAMPBUF_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE + reg_idx * 2, (EM_BLE_RD(EM_BLE_RXCTESAMPBUF_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE + reg_idx * 2) & ~((uint16_t)0x0000FF00)) | ((uint16_t)rxq << 8)); +} + +__INLINE uint8_t em_ble_rxctesampbuf_rx_i_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 81); + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCTESAMPBUF_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE + reg_idx * 2); + return ((localVal & ((uint16_t)0x000000FF)) >> 0); +} + +__INLINE void em_ble_rxctesampbuf_rx_i_setf(int elt_idx, int reg_idx, uint8_t rxi) +{ + ASSERT_ERR(reg_idx <= 81); + ASSERT_ERR((((uint16_t)rxi << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_RXCTESAMPBUF_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE + reg_idx * 2, (EM_BLE_RD(EM_BLE_RXCTESAMPBUF_ADDR + elt_idx * REG_EM_BLE_RX_CTE_DESC_SIZE + reg_idx * 2) & ~((uint16_t)0x000000FF)) | ((uint16_t)rxi << 0)); +} + + +#endif // _REG_EM_BLE_RX_CTE_DESC_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_rx_desc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_rx_desc.h new file mode 100644 index 0000000..1cf8894 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_rx_desc.h @@ -0,0 +1,1969 @@ +#ifndef _REG_EM_BLE_RX_DESC_H_ +#define _REG_EM_BLE_RX_DESC_H_ + +#include +#include "_reg_em_ble_rx_desc.h" +#include "compiler.h" +#include "arch.h" +#include "em_map.h" +#include "reg_access.h" + +#define REG_EM_BLE_RX_DESC_COUNT 14 + +#define REG_EM_BLE_RX_DESC_DECODING_MASK 0x0000001F + +#define REG_EM_BLE_RX_DESC_ADDR_GET(idx) (EM_BLE_RX_DESC_OFFSET + (idx) * REG_EM_BLE_RX_DESC_SIZE) + +/** + * @brief RXCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15               RXDONE   0
+ *  13:00            RXNEXTPTR   0x0
+ * 
+ */ +#define EM_BLE_RXCNTL_ADDR (EXCHANGE_MEM_BASE + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXCNTL_INDEX 0x00000000 +#define EM_BLE_RXCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXCNTL_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXCNTL_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXDONE_BIT ((uint16_t)0x00008000) +#define EM_BLE_RXDONE_POS 15 +#define EM_BLE_RXNEXTPTR_MASK ((uint16_t)0x00003FFF) +#define EM_BLE_RXNEXTPTR_LSB 0 +#define EM_BLE_RXNEXTPTR_WIDTH ((uint16_t)0x0000000E) + +#define EM_BLE_RXDONE_RST 0x0 +#define EM_BLE_RXNEXTPTR_RST 0x0 + +__INLINE void em_ble_rxcntl_pack(int elt_idx, uint8_t rxdone, uint16_t rxnextptr) +{ + ASSERT_ERR((((uint16_t)rxdone << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)rxnextptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_RXCNTL_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, ((uint16_t)rxdone << 15) | ((uint16_t)rxnextptr << 0)); +} + +__INLINE void em_ble_rxcntl_unpack(int elt_idx, uint8_t* rxdone, uint16_t* rxnextptr) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCNTL_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *rxdone = (localVal & ((uint16_t)0x00008000)) >> 15; + *rxnextptr = (localVal & ((uint16_t)0x00003FFF)) >> 0; +} + +__INLINE uint8_t em_ble_rxcntl_rxdone_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCNTL_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_rxcntl_rxdone_setf(int elt_idx, uint8_t rxdone) +{ + ASSERT_ERR((((uint16_t)rxdone << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_RXCNTL_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXCNTL_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)rxdone << 15)); +} + +__INLINE uint16_t em_ble_rxcntl_rxnextptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCNTL_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00003FFF)) >> 0); +} + +__INLINE void em_ble_rxcntl_rxnextptr_setf(int elt_idx, uint16_t rxnextptr) +{ + ASSERT_ERR((((uint16_t)rxnextptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_RXCNTL_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXCNTL_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00003FFF)) | ((uint16_t)rxnextptr << 0)); +} + +/** + * @brief RXSTATCE register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15             RXCTEERR   0
+ *     07             NESN_ERR   0
+ *     06               SN_ERR   0
+ *     05             LLID_ERR   0
+ *     04              MIC_ERR   0
+ *     03              CRC_ERR   0
+ *     02              LEN_ERR   0
+ *     01           RXTIME_ERR   0
+ *     00             SYNC_ERR   0
+ * 
+ */ +#define EM_BLE_RXSTATCE_ADDR (EXCHANGE_MEM_BASE+0x02 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXSTATCE_INDEX 0x00000001 +#define EM_BLE_RXSTATCE_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxstatce_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxstatce_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXCTEERR_BIT ((uint16_t)0x00008000) +#define EM_BLE_RXCTEERR_POS 15 +#define EM_BLE_NESN_ERR_BIT ((uint16_t)0x00000080) +#define EM_BLE_NESN_ERR_POS 7 +#define EM_BLE_SN_ERR_BIT ((uint16_t)0x00000040) +#define EM_BLE_SN_ERR_POS 6 +#define EM_BLE_LLID_ERR_BIT ((uint16_t)0x00000020) +#define EM_BLE_LLID_ERR_POS 5 +#define EM_BLE_MIC_ERR_BIT ((uint16_t)0x00000010) +#define EM_BLE_MIC_ERR_POS 4 +#define EM_BLE_CRC_ERR_BIT ((uint16_t)0x00000008) +#define EM_BLE_CRC_ERR_POS 3 +#define EM_BLE_LEN_ERR_BIT ((uint16_t)0x00000004) +#define EM_BLE_LEN_ERR_POS 2 +#define EM_BLE_RXTIME_ERR_BIT ((uint16_t)0x00000002) +#define EM_BLE_RXTIME_ERR_POS 1 +#define EM_BLE_SYNC_ERR_BIT ((uint16_t)0x00000001) +#define EM_BLE_SYNC_ERR_POS 0 + +#define EM_BLE_RXCTEERR_RST 0x0 +#define EM_BLE_NESN_ERR_RST 0x0 +#define EM_BLE_SN_ERR_RST 0x0 +#define EM_BLE_LLID_ERR_RST 0x0 +#define EM_BLE_MIC_ERR_RST 0x0 +#define EM_BLE_CRC_ERR_RST 0x0 +#define EM_BLE_LEN_ERR_RST 0x0 +#define EM_BLE_RXTIME_ERR_RST 0x0 +#define EM_BLE_SYNC_ERR_RST 0x0 + +__INLINE void em_ble_rxstatce_pack(int elt_idx, uint8_t rxcteerr, uint8_t nesnerr, uint8_t snerr, uint8_t lliderr, uint8_t micerr, uint8_t crcerr, uint8_t lenerr, uint8_t rxtimeerr, uint8_t syncerr) +{ + ASSERT_ERR((((uint16_t)rxcteerr << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)nesnerr << 7) & ~((uint16_t)0x00000080)) == 0); + ASSERT_ERR((((uint16_t)snerr << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)lliderr << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)micerr << 4) & ~((uint16_t)0x00000010)) == 0); + ASSERT_ERR((((uint16_t)crcerr << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)lenerr << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)rxtimeerr << 1) & ~((uint16_t)0x00000002)) == 0); + ASSERT_ERR((((uint16_t)syncerr << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, ((uint16_t)rxcteerr << 15) | ((uint16_t)nesnerr << 7) | ((uint16_t)snerr << 6) | ((uint16_t)lliderr << 5) | ((uint16_t)micerr << 4) | ((uint16_t)crcerr << 3) | ((uint16_t)lenerr << 2) | ((uint16_t)rxtimeerr << 1) | ((uint16_t)syncerr << 0)); +} + +__INLINE void em_ble_rxstatce_unpack(int elt_idx, uint8_t* rxcteerr, uint8_t* nesnerr, uint8_t* snerr, uint8_t* lliderr, uint8_t* micerr, uint8_t* crcerr, uint8_t* lenerr, uint8_t* rxtimeerr, uint8_t* syncerr) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *rxcteerr = (localVal & ((uint16_t)0x00008000)) >> 15; + *nesnerr = (localVal & ((uint16_t)0x00000080)) >> 7; + *snerr = (localVal & ((uint16_t)0x00000040)) >> 6; + *lliderr = (localVal & ((uint16_t)0x00000020)) >> 5; + *micerr = (localVal & ((uint16_t)0x00000010)) >> 4; + *crcerr = (localVal & ((uint16_t)0x00000008)) >> 3; + *lenerr = (localVal & ((uint16_t)0x00000004)) >> 2; + *rxtimeerr = (localVal & ((uint16_t)0x00000002)) >> 1; + *syncerr = (localVal & ((uint16_t)0x00000001)) >> 0; +} + +__INLINE uint8_t em_ble_rxstatce_rxcteerr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_rxstatce_rxcteerr_setf(int elt_idx, uint8_t rxcteerr) +{ + ASSERT_ERR((((uint16_t)rxcteerr << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)rxcteerr << 15)); +} + +__INLINE uint8_t em_ble_rxstatce_nesn_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000080)) >> 7); +} + +__INLINE void em_ble_rxstatce_nesn_err_setf(int elt_idx, uint8_t nesnerr) +{ + ASSERT_ERR((((uint16_t)nesnerr << 7) & ~((uint16_t)0x00000080)) == 0); + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000080)) | ((uint16_t)nesnerr << 7)); +} + +__INLINE uint8_t em_ble_rxstatce_sn_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_ble_rxstatce_sn_err_setf(int elt_idx, uint8_t snerr) +{ + ASSERT_ERR((((uint16_t)snerr << 6) & ~((uint16_t)0x00000040)) == 0); + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)snerr << 6)); +} + +__INLINE uint8_t em_ble_rxstatce_llid_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_rxstatce_llid_err_setf(int elt_idx, uint8_t lliderr) +{ + ASSERT_ERR((((uint16_t)lliderr << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)lliderr << 5)); +} + +__INLINE uint8_t em_ble_rxstatce_mic_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000010)) >> 4); +} + +__INLINE void em_ble_rxstatce_mic_err_setf(int elt_idx, uint8_t micerr) +{ + ASSERT_ERR((((uint16_t)micerr << 4) & ~((uint16_t)0x00000010)) == 0); + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000010)) | ((uint16_t)micerr << 4)); +} + +__INLINE uint8_t em_ble_rxstatce_crc_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_rxstatce_crc_err_setf(int elt_idx, uint8_t crcerr) +{ + ASSERT_ERR((((uint16_t)crcerr << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)crcerr << 3)); +} + +__INLINE uint8_t em_ble_rxstatce_len_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_rxstatce_len_err_setf(int elt_idx, uint8_t lenerr) +{ + ASSERT_ERR((((uint16_t)lenerr << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)lenerr << 2)); +} + +__INLINE uint8_t em_ble_rxstatce_rxtime_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000002)) >> 1); +} + +__INLINE void em_ble_rxstatce_rxtime_err_setf(int elt_idx, uint8_t rxtimeerr) +{ + ASSERT_ERR((((uint16_t)rxtimeerr << 1) & ~((uint16_t)0x00000002)) == 0); + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000002)) | ((uint16_t)rxtimeerr << 1)); +} + +__INLINE uint8_t em_ble_rxstatce_sync_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000001)) >> 0); +} + +__INLINE void em_ble_rxstatce_sync_err_setf(int elt_idx, uint8_t syncerr) +{ + ASSERT_ERR((((uint16_t)syncerr << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000001)) | ((uint16_t)syncerr << 0)); +} + +/** + * @brief RXSTATADV register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15             RXCTEERR   0
+ *     11         FOLLOWAUXPTR   0
+ *     10     DEV_FILTERING_OK   0
+ *     09               IN_WHL   0
+ *     08          IN_PERADVAL   0
+ *     07       PEER_ADD_MATCH   0
+ *     06         BDADDR_MATCH   0
+ *     05             TYPE_ERR   0
+ *     04             PRIV_ERR   0
+ *     03              CRC_ERR   0
+ *     02              LEN_ERR   0
+ *     01           RXTIME_ERR   0
+ *     00             SYNC_ERR   0
+ * 
+ */ +#define EM_BLE_RXSTATADV_ADDR (EXCHANGE_MEM_BASE+0x02 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXSTATADV_INDEX 0x00000001 +#define EM_BLE_RXSTATADV_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxstatadv_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxstatadv_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXCTEERR_BIT ((uint16_t)0x00008000) +#define EM_BLE_RXCTEERR_POS 15 +#define EM_BLE_FOLLOWAUXPTR_BIT ((uint16_t)0x00000800) +#define EM_BLE_FOLLOWAUXPTR_POS 11 +#define EM_BLE_DEV_FILTERING_OK_BIT ((uint16_t)0x00000400) +#define EM_BLE_DEV_FILTERING_OK_POS 10 +#define EM_BLE_IN_WHL_BIT ((uint16_t)0x00000200) +#define EM_BLE_IN_WHL_POS 9 +#define EM_BLE_IN_PERADVAL_BIT ((uint16_t)0x00000100) +#define EM_BLE_IN_PERADVAL_POS 8 +#define EM_BLE_PEER_ADD_MATCH_BIT ((uint16_t)0x00000080) +#define EM_BLE_PEER_ADD_MATCH_POS 7 +#define EM_BLE_BDADDR_MATCH_BIT ((uint16_t)0x00000040) +#define EM_BLE_BDADDR_MATCH_POS 6 +#define EM_BLE_TYPE_ERR_BIT ((uint16_t)0x00000020) +#define EM_BLE_TYPE_ERR_POS 5 +#define EM_BLE_PRIV_ERR_BIT ((uint16_t)0x00000010) +#define EM_BLE_PRIV_ERR_POS 4 +#define EM_BLE_CRC_ERR_BIT ((uint16_t)0x00000008) +#define EM_BLE_CRC_ERR_POS 3 +#define EM_BLE_LEN_ERR_BIT ((uint16_t)0x00000004) +#define EM_BLE_LEN_ERR_POS 2 +#define EM_BLE_RXTIME_ERR_BIT ((uint16_t)0x00000002) +#define EM_BLE_RXTIME_ERR_POS 1 +#define EM_BLE_SYNC_ERR_BIT ((uint16_t)0x00000001) +#define EM_BLE_SYNC_ERR_POS 0 + +#define EM_BLE_RXCTEERR_RST 0x0 +#define EM_BLE_FOLLOWAUXPTR_RST 0x0 +#define EM_BLE_DEV_FILTERING_OK_RST 0x0 +#define EM_BLE_IN_WHL_RST 0x0 +#define EM_BLE_IN_PERADVAL_RST 0x0 +#define EM_BLE_PEER_ADD_MATCH_RST 0x0 +#define EM_BLE_BDADDR_MATCH_RST 0x0 +#define EM_BLE_TYPE_ERR_RST 0x0 +#define EM_BLE_PRIV_ERR_RST 0x0 +#define EM_BLE_CRC_ERR_RST 0x0 +#define EM_BLE_LEN_ERR_RST 0x0 +#define EM_BLE_RXTIME_ERR_RST 0x0 +#define EM_BLE_SYNC_ERR_RST 0x0 + +__INLINE void em_ble_rxstatadv_pack(int elt_idx, uint8_t rxcteerr, uint8_t followauxptr, uint8_t devfilteringok, uint8_t inwhl, uint8_t inperadval, uint8_t peeraddmatch, uint8_t bdaddrmatch, uint8_t typeerr, uint8_t priverr, uint8_t crcerr, uint8_t lenerr, uint8_t rxtimeerr, uint8_t syncerr) +{ + ASSERT_ERR((((uint16_t)rxcteerr << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)followauxptr << 11) & ~((uint16_t)0x00000800)) == 0); + ASSERT_ERR((((uint16_t)devfilteringok << 10) & ~((uint16_t)0x00000400)) == 0); + ASSERT_ERR((((uint16_t)inwhl << 9) & ~((uint16_t)0x00000200)) == 0); + ASSERT_ERR((((uint16_t)inperadval << 8) & ~((uint16_t)0x00000100)) == 0); + ASSERT_ERR((((uint16_t)peeraddmatch << 7) & ~((uint16_t)0x00000080)) == 0); + ASSERT_ERR((((uint16_t)bdaddrmatch << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)typeerr << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)priverr << 4) & ~((uint16_t)0x00000010)) == 0); + ASSERT_ERR((((uint16_t)crcerr << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)lenerr << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)rxtimeerr << 1) & ~((uint16_t)0x00000002)) == 0); + ASSERT_ERR((((uint16_t)syncerr << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, ((uint16_t)rxcteerr << 15) | ((uint16_t)followauxptr << 11) | ((uint16_t)devfilteringok << 10) | ((uint16_t)inwhl << 9) | ((uint16_t)inperadval << 8) | ((uint16_t)peeraddmatch << 7) | ((uint16_t)bdaddrmatch << 6) | ((uint16_t)typeerr << 5) | ((uint16_t)priverr << 4) | ((uint16_t)crcerr << 3) | ((uint16_t)lenerr << 2) | ((uint16_t)rxtimeerr << 1) | ((uint16_t)syncerr << 0)); +} + +__INLINE void em_ble_rxstatadv_unpack(int elt_idx, uint8_t* rxcteerr, uint8_t* followauxptr, uint8_t* devfilteringok, uint8_t* inwhl, uint8_t* inperadval, uint8_t* peeraddmatch, uint8_t* bdaddrmatch, uint8_t* typeerr, uint8_t* priverr, uint8_t* crcerr, uint8_t* lenerr, uint8_t* rxtimeerr, uint8_t* syncerr) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *rxcteerr = (localVal & ((uint16_t)0x00008000)) >> 15; + *followauxptr = (localVal & ((uint16_t)0x00000800)) >> 11; + *devfilteringok = (localVal & ((uint16_t)0x00000400)) >> 10; + *inwhl = (localVal & ((uint16_t)0x00000200)) >> 9; + *inperadval = (localVal & ((uint16_t)0x00000100)) >> 8; + *peeraddmatch = (localVal & ((uint16_t)0x00000080)) >> 7; + *bdaddrmatch = (localVal & ((uint16_t)0x00000040)) >> 6; + *typeerr = (localVal & ((uint16_t)0x00000020)) >> 5; + *priverr = (localVal & ((uint16_t)0x00000010)) >> 4; + *crcerr = (localVal & ((uint16_t)0x00000008)) >> 3; + *lenerr = (localVal & ((uint16_t)0x00000004)) >> 2; + *rxtimeerr = (localVal & ((uint16_t)0x00000002)) >> 1; + *syncerr = (localVal & ((uint16_t)0x00000001)) >> 0; +} + +__INLINE uint8_t em_ble_rxstatadv_rxcteerr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_rxstatadv_rxcteerr_setf(int elt_idx, uint8_t rxcteerr) +{ + ASSERT_ERR((((uint16_t)rxcteerr << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)rxcteerr << 15)); +} + +__INLINE uint8_t em_ble_rxstatadv_followauxptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000800)) >> 11); +} + +__INLINE void em_ble_rxstatadv_followauxptr_setf(int elt_idx, uint8_t followauxptr) +{ + ASSERT_ERR((((uint16_t)followauxptr << 11) & ~((uint16_t)0x00000800)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000800)) | ((uint16_t)followauxptr << 11)); +} + +__INLINE uint8_t em_ble_rxstatadv_dev_filtering_ok_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000400)) >> 10); +} + +__INLINE void em_ble_rxstatadv_dev_filtering_ok_setf(int elt_idx, uint8_t devfilteringok) +{ + ASSERT_ERR((((uint16_t)devfilteringok << 10) & ~((uint16_t)0x00000400)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000400)) | ((uint16_t)devfilteringok << 10)); +} + +__INLINE uint8_t em_ble_rxstatadv_in_whl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000200)) >> 9); +} + +__INLINE void em_ble_rxstatadv_in_whl_setf(int elt_idx, uint8_t inwhl) +{ + ASSERT_ERR((((uint16_t)inwhl << 9) & ~((uint16_t)0x00000200)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000200)) | ((uint16_t)inwhl << 9)); +} + +__INLINE uint8_t em_ble_rxstatadv_in_peradval_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000100)) >> 8); +} + +__INLINE void em_ble_rxstatadv_in_peradval_setf(int elt_idx, uint8_t inperadval) +{ + ASSERT_ERR((((uint16_t)inperadval << 8) & ~((uint16_t)0x00000100)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000100)) | ((uint16_t)inperadval << 8)); +} + +__INLINE uint8_t em_ble_rxstatadv_peer_add_match_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000080)) >> 7); +} + +__INLINE void em_ble_rxstatadv_peer_add_match_setf(int elt_idx, uint8_t peeraddmatch) +{ + ASSERT_ERR((((uint16_t)peeraddmatch << 7) & ~((uint16_t)0x00000080)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000080)) | ((uint16_t)peeraddmatch << 7)); +} + +__INLINE uint8_t em_ble_rxstatadv_bdaddr_match_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_ble_rxstatadv_bdaddr_match_setf(int elt_idx, uint8_t bdaddrmatch) +{ + ASSERT_ERR((((uint16_t)bdaddrmatch << 6) & ~((uint16_t)0x00000040)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)bdaddrmatch << 6)); +} + +__INLINE uint8_t em_ble_rxstatadv_type_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_rxstatadv_type_err_setf(int elt_idx, uint8_t typeerr) +{ + ASSERT_ERR((((uint16_t)typeerr << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)typeerr << 5)); +} + +__INLINE uint8_t em_ble_rxstatadv_priv_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000010)) >> 4); +} + +__INLINE void em_ble_rxstatadv_priv_err_setf(int elt_idx, uint8_t priverr) +{ + ASSERT_ERR((((uint16_t)priverr << 4) & ~((uint16_t)0x00000010)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000010)) | ((uint16_t)priverr << 4)); +} + +__INLINE uint8_t em_ble_rxstatadv_crc_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_rxstatadv_crc_err_setf(int elt_idx, uint8_t crcerr) +{ + ASSERT_ERR((((uint16_t)crcerr << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)crcerr << 3)); +} + +__INLINE uint8_t em_ble_rxstatadv_len_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_rxstatadv_len_err_setf(int elt_idx, uint8_t lenerr) +{ + ASSERT_ERR((((uint16_t)lenerr << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)lenerr << 2)); +} + +__INLINE uint8_t em_ble_rxstatadv_rxtime_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000002)) >> 1); +} + +__INLINE void em_ble_rxstatadv_rxtime_err_setf(int elt_idx, uint8_t rxtimeerr) +{ + ASSERT_ERR((((uint16_t)rxtimeerr << 1) & ~((uint16_t)0x00000002)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000002)) | ((uint16_t)rxtimeerr << 1)); +} + +__INLINE uint8_t em_ble_rxstatadv_sync_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000001)) >> 0); +} + +__INLINE void em_ble_rxstatadv_sync_err_setf(int elt_idx, uint8_t syncerr) +{ + ASSERT_ERR((((uint16_t)syncerr << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000001)) | ((uint16_t)syncerr << 0)); +} + +/** + * @brief RXSTATISOM0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:11         RXSTREAM_LBL   0x0
+ *  10:08          RXGROUP_LBL   0x0
+ *     07             NESN_ERR   0
+ *     06               SN_ERR   0
+ *     05             LLID_ERR   0
+ *     04              MIC_ERR   0
+ *     03              CRC_ERR   0
+ *     02              LEN_ERR   0
+ *     01           RXTIME_ERR   0
+ *     00             SYNC_ERR   0
+ * 
+ */ +#define EM_BLE_RXSTATISOM0_ADDR (EXCHANGE_MEM_BASE+0x02 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXSTATISOM0_INDEX 0x00000001 +#define EM_BLE_RXSTATISOM0_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxstatisom0_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxstatisom0_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXSTREAM_LBL_MASK ((uint16_t)0x0000F800) +#define EM_BLE_RXSTREAM_LBL_LSB 11 +#define EM_BLE_RXSTREAM_LBL_WIDTH ((uint16_t)0x00000005) +#define EM_BLE_RXGROUP_LBL_MASK ((uint16_t)0x00000700) +#define EM_BLE_RXGROUP_LBL_LSB 8 +#define EM_BLE_RXGROUP_LBL_WIDTH ((uint16_t)0x00000003) +#define EM_BLE_NESN_ERR_BIT ((uint16_t)0x00000080) +#define EM_BLE_NESN_ERR_POS 7 +#define EM_BLE_SN_ERR_BIT ((uint16_t)0x00000040) +#define EM_BLE_SN_ERR_POS 6 +#define EM_BLE_LLID_ERR_BIT ((uint16_t)0x00000020) +#define EM_BLE_LLID_ERR_POS 5 +#define EM_BLE_MIC_ERR_BIT ((uint16_t)0x00000010) +#define EM_BLE_MIC_ERR_POS 4 +#define EM_BLE_CRC_ERR_BIT ((uint16_t)0x00000008) +#define EM_BLE_CRC_ERR_POS 3 +#define EM_BLE_LEN_ERR_BIT ((uint16_t)0x00000004) +#define EM_BLE_LEN_ERR_POS 2 +#define EM_BLE_RXTIME_ERR_BIT ((uint16_t)0x00000002) +#define EM_BLE_RXTIME_ERR_POS 1 +#define EM_BLE_SYNC_ERR_BIT ((uint16_t)0x00000001) +#define EM_BLE_SYNC_ERR_POS 0 + +#define EM_BLE_RXSTREAM_LBL_RST 0x0 +#define EM_BLE_RXGROUP_LBL_RST 0x0 +#define EM_BLE_NESN_ERR_RST 0x0 +#define EM_BLE_SN_ERR_RST 0x0 +#define EM_BLE_LLID_ERR_RST 0x0 +#define EM_BLE_MIC_ERR_RST 0x0 +#define EM_BLE_CRC_ERR_RST 0x0 +#define EM_BLE_LEN_ERR_RST 0x0 +#define EM_BLE_RXTIME_ERR_RST 0x0 +#define EM_BLE_SYNC_ERR_RST 0x0 + +__INLINE void em_ble_rxstatisom0_pack(int elt_idx, uint8_t rxstreamlbl, uint8_t rxgrouplbl, uint8_t nesnerr, uint8_t snerr, uint8_t lliderr, uint8_t micerr, uint8_t crcerr, uint8_t lenerr, uint8_t rxtimeerr, uint8_t syncerr) +{ + ASSERT_ERR((((uint16_t)rxstreamlbl << 11) & ~((uint16_t)0x0000F800)) == 0); + ASSERT_ERR((((uint16_t)rxgrouplbl << 8) & ~((uint16_t)0x00000700)) == 0); + ASSERT_ERR((((uint16_t)nesnerr << 7) & ~((uint16_t)0x00000080)) == 0); + ASSERT_ERR((((uint16_t)snerr << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)lliderr << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)micerr << 4) & ~((uint16_t)0x00000010)) == 0); + ASSERT_ERR((((uint16_t)crcerr << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)lenerr << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)rxtimeerr << 1) & ~((uint16_t)0x00000002)) == 0); + ASSERT_ERR((((uint16_t)syncerr << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, ((uint16_t)rxstreamlbl << 11) | ((uint16_t)rxgrouplbl << 8) | ((uint16_t)nesnerr << 7) | ((uint16_t)snerr << 6) | ((uint16_t)lliderr << 5) | ((uint16_t)micerr << 4) | ((uint16_t)crcerr << 3) | ((uint16_t)lenerr << 2) | ((uint16_t)rxtimeerr << 1) | ((uint16_t)syncerr << 0)); +} + +__INLINE void em_ble_rxstatisom0_unpack(int elt_idx, uint8_t* rxstreamlbl, uint8_t* rxgrouplbl, uint8_t* nesnerr, uint8_t* snerr, uint8_t* lliderr, uint8_t* micerr, uint8_t* crcerr, uint8_t* lenerr, uint8_t* rxtimeerr, uint8_t* syncerr) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *rxstreamlbl = (localVal & ((uint16_t)0x0000F800)) >> 11; + *rxgrouplbl = (localVal & ((uint16_t)0x00000700)) >> 8; + *nesnerr = (localVal & ((uint16_t)0x00000080)) >> 7; + *snerr = (localVal & ((uint16_t)0x00000040)) >> 6; + *lliderr = (localVal & ((uint16_t)0x00000020)) >> 5; + *micerr = (localVal & ((uint16_t)0x00000010)) >> 4; + *crcerr = (localVal & ((uint16_t)0x00000008)) >> 3; + *lenerr = (localVal & ((uint16_t)0x00000004)) >> 2; + *rxtimeerr = (localVal & ((uint16_t)0x00000002)) >> 1; + *syncerr = (localVal & ((uint16_t)0x00000001)) >> 0; +} + +__INLINE uint8_t em_ble_rxstatisom0_rxstream_lbl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000F800)) >> 11); +} + +__INLINE void em_ble_rxstatisom0_rxstream_lbl_setf(int elt_idx, uint8_t rxstreamlbl) +{ + ASSERT_ERR((((uint16_t)rxstreamlbl << 11) & ~((uint16_t)0x0000F800)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x0000F800)) | ((uint16_t)rxstreamlbl << 11)); +} + +__INLINE uint8_t em_ble_rxstatisom0_rxgroup_lbl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000700)) >> 8); +} + +__INLINE void em_ble_rxstatisom0_rxgroup_lbl_setf(int elt_idx, uint8_t rxgrouplbl) +{ + ASSERT_ERR((((uint16_t)rxgrouplbl << 8) & ~((uint16_t)0x00000700)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000700)) | ((uint16_t)rxgrouplbl << 8)); +} + +__INLINE uint8_t em_ble_rxstatisom0_nesn_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000080)) >> 7); +} + +__INLINE void em_ble_rxstatisom0_nesn_err_setf(int elt_idx, uint8_t nesnerr) +{ + ASSERT_ERR((((uint16_t)nesnerr << 7) & ~((uint16_t)0x00000080)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000080)) | ((uint16_t)nesnerr << 7)); +} + +__INLINE uint8_t em_ble_rxstatisom0_sn_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_ble_rxstatisom0_sn_err_setf(int elt_idx, uint8_t snerr) +{ + ASSERT_ERR((((uint16_t)snerr << 6) & ~((uint16_t)0x00000040)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)snerr << 6)); +} + +__INLINE uint8_t em_ble_rxstatisom0_llid_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_rxstatisom0_llid_err_setf(int elt_idx, uint8_t lliderr) +{ + ASSERT_ERR((((uint16_t)lliderr << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)lliderr << 5)); +} + +__INLINE uint8_t em_ble_rxstatisom0_mic_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000010)) >> 4); +} + +__INLINE void em_ble_rxstatisom0_mic_err_setf(int elt_idx, uint8_t micerr) +{ + ASSERT_ERR((((uint16_t)micerr << 4) & ~((uint16_t)0x00000010)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000010)) | ((uint16_t)micerr << 4)); +} + +__INLINE uint8_t em_ble_rxstatisom0_crc_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_rxstatisom0_crc_err_setf(int elt_idx, uint8_t crcerr) +{ + ASSERT_ERR((((uint16_t)crcerr << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)crcerr << 3)); +} + +__INLINE uint8_t em_ble_rxstatisom0_len_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_rxstatisom0_len_err_setf(int elt_idx, uint8_t lenerr) +{ + ASSERT_ERR((((uint16_t)lenerr << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)lenerr << 2)); +} + +__INLINE uint8_t em_ble_rxstatisom0_rxtime_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000002)) >> 1); +} + +__INLINE void em_ble_rxstatisom0_rxtime_err_setf(int elt_idx, uint8_t rxtimeerr) +{ + ASSERT_ERR((((uint16_t)rxtimeerr << 1) & ~((uint16_t)0x00000002)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000002)) | ((uint16_t)rxtimeerr << 1)); +} + +__INLINE uint8_t em_ble_rxstatisom0_sync_err_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000001)) >> 0); +} + +__INLINE void em_ble_rxstatisom0_sync_err_setf(int elt_idx, uint8_t syncerr) +{ + ASSERT_ERR((((uint16_t)syncerr << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXSTATISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000001)) | ((uint16_t)syncerr << 0)); +} + +/** + * @brief RXPHCE register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08                RXLEN   0x0
+ *  07:06             RXACLRFU   0x0
+ *     05                 RXCP   0
+ *     04                 RXMD   0
+ *     03                 RXSN   0
+ *     02               RXNESN   0
+ *  01:00               RXLLID   0x0
+ * 
+ */ +#define EM_BLE_RXPHCE_ADDR (EXCHANGE_MEM_BASE+0x04 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXPHCE_INDEX 0x00000002 +#define EM_BLE_RXPHCE_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxphce_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxphce_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXLEN_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_RXLEN_LSB 8 +#define EM_BLE_RXLEN_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_RXACLRFU_MASK ((uint16_t)0x000000C0) +#define EM_BLE_RXACLRFU_LSB 6 +#define EM_BLE_RXACLRFU_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_RXCP_BIT ((uint16_t)0x00000020) +#define EM_BLE_RXCP_POS 5 +#define EM_BLE_RXMD_BIT ((uint16_t)0x00000010) +#define EM_BLE_RXMD_POS 4 +#define EM_BLE_RXSN_BIT ((uint16_t)0x00000008) +#define EM_BLE_RXSN_POS 3 +#define EM_BLE_RXNESN_BIT ((uint16_t)0x00000004) +#define EM_BLE_RXNESN_POS 2 +#define EM_BLE_RXLLID_MASK ((uint16_t)0x00000003) +#define EM_BLE_RXLLID_LSB 0 +#define EM_BLE_RXLLID_WIDTH ((uint16_t)0x00000002) + +#define EM_BLE_RXLEN_RST 0x0 +#define EM_BLE_RXACLRFU_RST 0x0 +#define EM_BLE_RXCP_RST 0x0 +#define EM_BLE_RXMD_RST 0x0 +#define EM_BLE_RXSN_RST 0x0 +#define EM_BLE_RXNESN_RST 0x0 +#define EM_BLE_RXLLID_RST 0x0 + +__INLINE void em_ble_rxphce_pack(int elt_idx, uint8_t rxlen, uint8_t rxaclrfu, uint8_t rxcp, uint8_t rxmd, uint8_t rxsn, uint8_t rxnesn, uint8_t rxllid) +{ + ASSERT_ERR((((uint16_t)rxlen << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)rxaclrfu << 6) & ~((uint16_t)0x000000C0)) == 0); + ASSERT_ERR((((uint16_t)rxcp << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)rxmd << 4) & ~((uint16_t)0x00000010)) == 0); + ASSERT_ERR((((uint16_t)rxsn << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)rxnesn << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)rxllid << 0) & ~((uint16_t)0x00000003)) == 0); + EM_BLE_WR(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, ((uint16_t)rxlen << 8) | ((uint16_t)rxaclrfu << 6) | ((uint16_t)rxcp << 5) | ((uint16_t)rxmd << 4) | ((uint16_t)rxsn << 3) | ((uint16_t)rxnesn << 2) | ((uint16_t)rxllid << 0)); +} + +__INLINE void em_ble_rxphce_unpack(int elt_idx, uint8_t* rxlen, uint8_t* rxaclrfu, uint8_t* rxcp, uint8_t* rxmd, uint8_t* rxsn, uint8_t* rxnesn, uint8_t* rxllid) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *rxlen = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *rxaclrfu = (localVal & ((uint16_t)0x000000C0)) >> 6; + *rxcp = (localVal & ((uint16_t)0x00000020)) >> 5; + *rxmd = (localVal & ((uint16_t)0x00000010)) >> 4; + *rxsn = (localVal & ((uint16_t)0x00000008)) >> 3; + *rxnesn = (localVal & ((uint16_t)0x00000004)) >> 2; + *rxllid = (localVal & ((uint16_t)0x00000003)) >> 0; +} + +__INLINE uint8_t em_ble_rxphce_rxlen_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_rxphce_rxlen_setf(int elt_idx, uint8_t rxlen) +{ + ASSERT_ERR((((uint16_t)rxlen << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)rxlen << 8)); +} + +__INLINE uint8_t em_ble_rxphce_rxaclrfu_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x000000C0)) >> 6); +} + +__INLINE void em_ble_rxphce_rxaclrfu_setf(int elt_idx, uint8_t rxaclrfu) +{ + ASSERT_ERR((((uint16_t)rxaclrfu << 6) & ~((uint16_t)0x000000C0)) == 0); + EM_BLE_WR(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x000000C0)) | ((uint16_t)rxaclrfu << 6)); +} + +__INLINE uint8_t em_ble_rxphce_rxcp_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_rxphce_rxcp_setf(int elt_idx, uint8_t rxcp) +{ + ASSERT_ERR((((uint16_t)rxcp << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)rxcp << 5)); +} + +__INLINE uint8_t em_ble_rxphce_rxmd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000010)) >> 4); +} + +__INLINE void em_ble_rxphce_rxmd_setf(int elt_idx, uint8_t rxmd) +{ + ASSERT_ERR((((uint16_t)rxmd << 4) & ~((uint16_t)0x00000010)) == 0); + EM_BLE_WR(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000010)) | ((uint16_t)rxmd << 4)); +} + +__INLINE uint8_t em_ble_rxphce_rxsn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_rxphce_rxsn_setf(int elt_idx, uint8_t rxsn) +{ + ASSERT_ERR((((uint16_t)rxsn << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)rxsn << 3)); +} + +__INLINE uint8_t em_ble_rxphce_rxnesn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_rxphce_rxnesn_setf(int elt_idx, uint8_t rxnesn) +{ + ASSERT_ERR((((uint16_t)rxnesn << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)rxnesn << 2)); +} + +__INLINE uint8_t em_ble_rxphce_rxllid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000003)) >> 0); +} + +__INLINE void em_ble_rxphce_rxllid_setf(int elt_idx, uint8_t rxllid) +{ + ASSERT_ERR((((uint16_t)rxllid << 0) & ~((uint16_t)0x00000003)) == 0); + EM_BLE_WR(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000003)) | ((uint16_t)rxllid << 0)); +} + +/** + * @brief RXPHADV register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08             RXADVLEN   0x0
+ *     07              RXRXADD   0
+ *     06              RXTXADD   0
+ *     05             RXCHSEL2   0
+ *     04             RXADVRFU   0
+ *  03:00               RXTYPE   0x0
+ * 
+ */ +#define EM_BLE_RXPHADV_ADDR (EXCHANGE_MEM_BASE+0x04 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXPHADV_INDEX 0x00000002 +#define EM_BLE_RXPHADV_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxphadv_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxphadv_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXADVLEN_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_RXADVLEN_LSB 8 +#define EM_BLE_RXADVLEN_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_RXRXADD_BIT ((uint16_t)0x00000080) +#define EM_BLE_RXRXADD_POS 7 +#define EM_BLE_RXTXADD_BIT ((uint16_t)0x00000040) +#define EM_BLE_RXTXADD_POS 6 +#define EM_BLE_RXCHSEL2_BIT ((uint16_t)0x00000020) +#define EM_BLE_RXCHSEL2_POS 5 +#define EM_BLE_RXADVRFU_BIT ((uint16_t)0x00000010) +#define EM_BLE_RXADVRFU_POS 4 +#define EM_BLE_RXTYPE_MASK ((uint16_t)0x0000000F) +#define EM_BLE_RXTYPE_LSB 0 +#define EM_BLE_RXTYPE_WIDTH ((uint16_t)0x00000004) + +#define EM_BLE_RXADVLEN_RST 0x0 +#define EM_BLE_RXRXADD_RST 0x0 +#define EM_BLE_RXTXADD_RST 0x0 +#define EM_BLE_RXCHSEL2_RST 0x0 +#define EM_BLE_RXADVRFU_RST 0x0 +#define EM_BLE_RXTYPE_RST 0x0 + +__INLINE void em_ble_rxphadv_pack(int elt_idx, uint8_t rxadvlen, uint8_t rxrxadd, uint8_t rxtxadd, uint8_t rxchsel2, uint8_t rxadvrfu, uint8_t rxtype) +{ + ASSERT_ERR((((uint16_t)rxadvlen << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)rxrxadd << 7) & ~((uint16_t)0x00000080)) == 0); + ASSERT_ERR((((uint16_t)rxtxadd << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)rxchsel2 << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)rxadvrfu << 4) & ~((uint16_t)0x00000010)) == 0); + ASSERT_ERR((((uint16_t)rxtype << 0) & ~((uint16_t)0x0000000F)) == 0); + EM_BLE_WR(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, ((uint16_t)rxadvlen << 8) | ((uint16_t)rxrxadd << 7) | ((uint16_t)rxtxadd << 6) | ((uint16_t)rxchsel2 << 5) | ((uint16_t)rxadvrfu << 4) | ((uint16_t)rxtype << 0)); +} + +__INLINE void em_ble_rxphadv_unpack(int elt_idx, uint8_t* rxadvlen, uint8_t* rxrxadd, uint8_t* rxtxadd, uint8_t* rxchsel2, uint8_t* rxadvrfu, uint8_t* rxtype) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *rxadvlen = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *rxrxadd = (localVal & ((uint16_t)0x00000080)) >> 7; + *rxtxadd = (localVal & ((uint16_t)0x00000040)) >> 6; + *rxchsel2 = (localVal & ((uint16_t)0x00000020)) >> 5; + *rxadvrfu = (localVal & ((uint16_t)0x00000010)) >> 4; + *rxtype = (localVal & ((uint16_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t em_ble_rxphadv_rxadvlen_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_rxphadv_rxadvlen_setf(int elt_idx, uint8_t rxadvlen) +{ + ASSERT_ERR((((uint16_t)rxadvlen << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)rxadvlen << 8)); +} + +__INLINE uint8_t em_ble_rxphadv_rxrxadd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000080)) >> 7); +} + +__INLINE void em_ble_rxphadv_rxrxadd_setf(int elt_idx, uint8_t rxrxadd) +{ + ASSERT_ERR((((uint16_t)rxrxadd << 7) & ~((uint16_t)0x00000080)) == 0); + EM_BLE_WR(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000080)) | ((uint16_t)rxrxadd << 7)); +} + +__INLINE uint8_t em_ble_rxphadv_rxtxadd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_ble_rxphadv_rxtxadd_setf(int elt_idx, uint8_t rxtxadd) +{ + ASSERT_ERR((((uint16_t)rxtxadd << 6) & ~((uint16_t)0x00000040)) == 0); + EM_BLE_WR(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)rxtxadd << 6)); +} + +__INLINE uint8_t em_ble_rxphadv_rxchsel2_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_rxphadv_rxchsel2_setf(int elt_idx, uint8_t rxchsel2) +{ + ASSERT_ERR((((uint16_t)rxchsel2 << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)rxchsel2 << 5)); +} + +__INLINE uint8_t em_ble_rxphadv_rxadvrfu_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000010)) >> 4); +} + +__INLINE void em_ble_rxphadv_rxadvrfu_setf(int elt_idx, uint8_t rxadvrfu) +{ + ASSERT_ERR((((uint16_t)rxadvrfu << 4) & ~((uint16_t)0x00000010)) == 0); + EM_BLE_WR(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000010)) | ((uint16_t)rxadvrfu << 4)); +} + +__INLINE uint8_t em_ble_rxphadv_rxtype_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000000F)) >> 0); +} + +__INLINE void em_ble_rxphadv_rxtype_setf(int elt_idx, uint8_t rxtype) +{ + ASSERT_ERR((((uint16_t)rxtype << 0) & ~((uint16_t)0x0000000F)) == 0); + EM_BLE_WR(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHADV_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x0000000F)) | ((uint16_t)rxtype << 0)); +} + +/** + * @brief RXPHISOM0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08                RXLEN   0x0
+ *  07:05           RXISOM0RFU   0x0
+ *     04                 RXMD   0
+ *     03                 RXSN   0
+ *     02               RXNESN   0
+ *  01:00               RXLLID   0x0
+ * 
+ */ +#define EM_BLE_RXPHISOM0_ADDR (EXCHANGE_MEM_BASE+0x04 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXPHISOM0_INDEX 0x00000002 +#define EM_BLE_RXPHISOM0_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxphisom0_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxphisom0_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXLEN_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_RXLEN_LSB 8 +#define EM_BLE_RXLEN_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_RXISOM0RFU_MASK ((uint16_t)0x000000E0) +#define EM_BLE_RXISOM0RFU_LSB 5 +#define EM_BLE_RXISOM0RFU_WIDTH ((uint16_t)0x00000003) +#define EM_BLE_RXMD_BIT ((uint16_t)0x00000010) +#define EM_BLE_RXMD_POS 4 +#define EM_BLE_RXSN_BIT ((uint16_t)0x00000008) +#define EM_BLE_RXSN_POS 3 +#define EM_BLE_RXNESN_BIT ((uint16_t)0x00000004) +#define EM_BLE_RXNESN_POS 2 +#define EM_BLE_RXLLID_MASK ((uint16_t)0x00000003) +#define EM_BLE_RXLLID_LSB 0 +#define EM_BLE_RXLLID_WIDTH ((uint16_t)0x00000002) + +#define EM_BLE_RXLEN_RST 0x0 +#define EM_BLE_RXISOM0RFU_RST 0x0 +#define EM_BLE_RXMD_RST 0x0 +#define EM_BLE_RXSN_RST 0x0 +#define EM_BLE_RXNESN_RST 0x0 +#define EM_BLE_RXLLID_RST 0x0 + +__INLINE void em_ble_rxphisom0_pack(int elt_idx, uint8_t rxlen, uint8_t rxisom0rfu, uint8_t rxmd, uint8_t rxsn, uint8_t rxnesn, uint8_t rxllid) +{ + ASSERT_ERR((((uint16_t)rxlen << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)rxisom0rfu << 5) & ~((uint16_t)0x000000E0)) == 0); + ASSERT_ERR((((uint16_t)rxmd << 4) & ~((uint16_t)0x00000010)) == 0); + ASSERT_ERR((((uint16_t)rxsn << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)rxnesn << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)rxllid << 0) & ~((uint16_t)0x00000003)) == 0); + EM_BLE_WR(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, ((uint16_t)rxlen << 8) | ((uint16_t)rxisom0rfu << 5) | ((uint16_t)rxmd << 4) | ((uint16_t)rxsn << 3) | ((uint16_t)rxnesn << 2) | ((uint16_t)rxllid << 0)); +} + +__INLINE void em_ble_rxphisom0_unpack(int elt_idx, uint8_t* rxlen, uint8_t* rxisom0rfu, uint8_t* rxmd, uint8_t* rxsn, uint8_t* rxnesn, uint8_t* rxllid) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *rxlen = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *rxisom0rfu = (localVal & ((uint16_t)0x000000E0)) >> 5; + *rxmd = (localVal & ((uint16_t)0x00000010)) >> 4; + *rxsn = (localVal & ((uint16_t)0x00000008)) >> 3; + *rxnesn = (localVal & ((uint16_t)0x00000004)) >> 2; + *rxllid = (localVal & ((uint16_t)0x00000003)) >> 0; +} + +__INLINE uint8_t em_ble_rxphisom0_rxlen_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_rxphisom0_rxlen_setf(int elt_idx, uint8_t rxlen) +{ + ASSERT_ERR((((uint16_t)rxlen << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)rxlen << 8)); +} + +__INLINE uint8_t em_ble_rxphisom0_rxisom0rfu_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x000000E0)) >> 5); +} + +__INLINE void em_ble_rxphisom0_rxisom0rfu_setf(int elt_idx, uint8_t rxisom0rfu) +{ + ASSERT_ERR((((uint16_t)rxisom0rfu << 5) & ~((uint16_t)0x000000E0)) == 0); + EM_BLE_WR(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x000000E0)) | ((uint16_t)rxisom0rfu << 5)); +} + +__INLINE uint8_t em_ble_rxphisom0_rxmd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000010)) >> 4); +} + +__INLINE void em_ble_rxphisom0_rxmd_setf(int elt_idx, uint8_t rxmd) +{ + ASSERT_ERR((((uint16_t)rxmd << 4) & ~((uint16_t)0x00000010)) == 0); + EM_BLE_WR(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000010)) | ((uint16_t)rxmd << 4)); +} + +__INLINE uint8_t em_ble_rxphisom0_rxsn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_rxphisom0_rxsn_setf(int elt_idx, uint8_t rxsn) +{ + ASSERT_ERR((((uint16_t)rxsn << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)rxsn << 3)); +} + +__INLINE uint8_t em_ble_rxphisom0_rxnesn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_rxphisom0_rxnesn_setf(int elt_idx, uint8_t rxnesn) +{ + ASSERT_ERR((((uint16_t)rxnesn << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)rxnesn << 2)); +} + +__INLINE uint8_t em_ble_rxphisom0_rxllid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000003)) >> 0); +} + +__INLINE void em_ble_rxphisom0_rxllid_setf(int elt_idx, uint8_t rxllid) +{ + ASSERT_ERR((((uint16_t)rxllid << 0) & ~((uint16_t)0x00000003)) == 0); + EM_BLE_WR(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHISOM0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000003)) | ((uint16_t)rxllid << 0)); +} + +/** + * @brief RXCHASS register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:14                 RATE   0x0
+ *  13:08          USED_CH_IDX   0x0
+ *  07:00                 RSSI   0x0
+ * 
+ */ +#define EM_BLE_RXCHASS_ADDR (EXCHANGE_MEM_BASE+0x06 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXCHASS_INDEX 0x00000003 +#define EM_BLE_RXCHASS_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxchass_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxchass_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RATE_MASK ((uint16_t)0x0000C000) +#define EM_BLE_RATE_LSB 14 +#define EM_BLE_RATE_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_USED_CH_IDX_MASK ((uint16_t)0x00003F00) +#define EM_BLE_USED_CH_IDX_LSB 8 +#define EM_BLE_USED_CH_IDX_WIDTH ((uint16_t)0x00000006) +#define EM_BLE_RSSI_MASK ((uint16_t)0x000000FF) +#define EM_BLE_RSSI_LSB 0 +#define EM_BLE_RSSI_WIDTH ((uint16_t)0x00000008) + +#define EM_BLE_RATE_RST 0x0 +#define EM_BLE_USED_CH_IDX_RST 0x0 +#define EM_BLE_RSSI_RST 0x0 + +__INLINE void em_ble_rxchass_pack(int elt_idx, uint8_t rate, uint8_t usedchidx, uint8_t rssi) +{ + ASSERT_ERR((((uint16_t)rate << 14) & ~((uint16_t)0x0000C000)) == 0); + ASSERT_ERR((((uint16_t)usedchidx << 8) & ~((uint16_t)0x00003F00)) == 0); + ASSERT_ERR((((uint16_t)rssi << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, ((uint16_t)rate << 14) | ((uint16_t)usedchidx << 8) | ((uint16_t)rssi << 0)); +} + +__INLINE void em_ble_rxchass_unpack(int elt_idx, uint8_t* rate, uint8_t* usedchidx, uint8_t* rssi) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *rate = (localVal & ((uint16_t)0x0000C000)) >> 14; + *usedchidx = (localVal & ((uint16_t)0x00003F00)) >> 8; + *rssi = (localVal & ((uint16_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t em_ble_rxchass_rate_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000C000)) >> 14); +} + +__INLINE void em_ble_rxchass_rate_setf(int elt_idx, uint8_t rate) +{ + ASSERT_ERR((((uint16_t)rate << 14) & ~((uint16_t)0x0000C000)) == 0); + EM_BLE_WR(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x0000C000)) | ((uint16_t)rate << 14)); +} + +__INLINE uint8_t em_ble_rxchass_used_ch_idx_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00003F00)) >> 8); +} + +__INLINE void em_ble_rxchass_used_ch_idx_setf(int elt_idx, uint8_t usedchidx) +{ + ASSERT_ERR((((uint16_t)usedchidx << 8) & ~((uint16_t)0x00003F00)) == 0); + EM_BLE_WR(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00003F00)) | ((uint16_t)usedchidx << 8)); +} + +__INLINE uint8_t em_ble_rxchass_rssi_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x000000FF)) >> 0); +} + +__INLINE void em_ble_rxchass_rssi_setf(int elt_idx, uint8_t rssi) +{ + ASSERT_ERR((((uint16_t)rssi << 0) & ~((uint16_t)0x000000FF)) == 0); + EM_BLE_WR(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXCHASS_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x000000FF)) | ((uint16_t)rssi << 0)); +} + +/** + * @brief RXCLKNSYNC0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00          CLKNRXSYNC0   0x0
+ * 
+ */ +#define EM_BLE_RXCLKNSYNC0_ADDR (EXCHANGE_MEM_BASE+0x08 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXCLKNSYNC0_INDEX 0x00000004 +#define EM_BLE_RXCLKNSYNC0_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxclknsync0_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXCLKNSYNC0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +// field definitions +#define EM_BLE_CLKNRXSYNC0_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_CLKNRXSYNC0_LSB 0 +#define EM_BLE_CLKNRXSYNC0_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_CLKNRXSYNC0_RST 0x0 + +__INLINE uint16_t em_ble_rxclknsync0_clknrxsync0_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCLKNSYNC0_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief RXCLKNSYNC1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  11:00          CLKNRXSYNC1   0x0
+ * 
+ */ +#define EM_BLE_RXCLKNSYNC1_ADDR (EXCHANGE_MEM_BASE+0x0A + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXCLKNSYNC1_INDEX 0x00000005 +#define EM_BLE_RXCLKNSYNC1_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxclknsync1_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXCLKNSYNC1_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +// field definitions +#define EM_BLE_CLKNRXSYNC1_MASK ((uint16_t)0x00000FFF) +#define EM_BLE_CLKNRXSYNC1_LSB 0 +#define EM_BLE_CLKNRXSYNC1_WIDTH ((uint16_t)0x0000000C) + +#define EM_BLE_CLKNRXSYNC1_RST 0x0 + +__INLINE uint16_t em_ble_rxclknsync1_clknrxsync1_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCLKNSYNC1_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00000FFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief RXFCNTSYNC register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:11            RXLINKLBL   0x0
+ *  09:00           FCNTRXSYNC   0x0
+ * 
+ */ +#define EM_BLE_RXFCNTSYNC_ADDR (EXCHANGE_MEM_BASE+0x0C + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXFCNTSYNC_INDEX 0x00000006 +#define EM_BLE_RXFCNTSYNC_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxfcntsync_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXFCNTSYNC_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +// field definitions +#define EM_BLE_RXLINKLBL_MASK ((uint16_t)0x0000F800) +#define EM_BLE_RXLINKLBL_LSB 11 +#define EM_BLE_RXLINKLBL_WIDTH ((uint16_t)0x00000005) +#define EM_BLE_FCNTRXSYNC_MASK ((uint16_t)0x000003FF) +#define EM_BLE_FCNTRXSYNC_LSB 0 +#define EM_BLE_FCNTRXSYNC_WIDTH ((uint16_t)0x0000000A) + +#define EM_BLE_RXLINKLBL_RST 0x0 +#define EM_BLE_FCNTRXSYNC_RST 0x0 + +__INLINE void em_ble_rxfcntsync_unpack(int elt_idx, uint8_t* rxlinklbl, uint16_t* fcntrxsync) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXFCNTSYNC_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *rxlinklbl = (localVal & ((uint16_t)0x0000F800)) >> 11; + *fcntrxsync = (localVal & ((uint16_t)0x000003FF)) >> 0; +} + +__INLINE uint8_t em_ble_rxfcntsync_rxlinklbl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXFCNTSYNC_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000F800)) >> 11); +} + +__INLINE uint16_t em_ble_rxfcntsync_fcntrxsync_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXFCNTSYNC_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x000003FF)) >> 0); +} + +/** + * @brief RXWPALPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00            RXWPALPTR   0x0
+ * 
+ */ +#define EM_BLE_RXWPALPTR_ADDR (EXCHANGE_MEM_BASE+0x0E + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXWPALPTR_INDEX 0x00000007 +#define EM_BLE_RXWPALPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxwpalptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXWPALPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxwpalptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXWPALPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXWPALPTR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_RXWPALPTR_LSB 0 +#define EM_BLE_RXWPALPTR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_RXWPALPTR_RST 0x0 + +__INLINE uint16_t em_ble_rxwpalptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXWPALPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_rxwpalptr_setf(int elt_idx, uint16_t rxwpalptr) +{ + ASSERT_ERR((((uint16_t)rxwpalptr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RXWPALPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (uint16_t)rxwpalptr << 0); +} + +/** + * @brief RXRALPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00             RXRALPTR   0x0
+ * 
+ */ +#define EM_BLE_RXRALPTR_ADDR (EXCHANGE_MEM_BASE+0x10 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXRALPTR_INDEX 0x00000008 +#define EM_BLE_RXRALPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxralptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXRALPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxralptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXRALPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXRALPTR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_RXRALPTR_LSB 0 +#define EM_BLE_RXRALPTR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_RXRALPTR_RST 0x0 + +__INLINE uint16_t em_ble_rxralptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXRALPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_rxralptr_setf(int elt_idx, uint16_t rxralptr) +{ + ASSERT_ERR((((uint16_t)rxralptr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RXRALPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (uint16_t)rxralptr << 0); +} + +/** + * @brief RXAEHEADER register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15               RXRSVD   0
+ *     14                RXPOW   0
+ *     13               RXSYNC   0
+ *     12             RXAUXPTR   0
+ *     11                RXADI   0
+ *     10                RXCTE   0
+ *     09               RXTGTA   0
+ *     08               RXADVA   0
+ *  07:06             RXAEMODE   0x0
+ *  05:00           RXAELENGTH   0x0
+ * 
+ */ +#define EM_BLE_RXAEHEADER_ADDR (EXCHANGE_MEM_BASE+0x12 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXAEHEADER_INDEX 0x00000009 +#define EM_BLE_RXAEHEADER_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxaeheader_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxaeheader_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXRSVD_BIT ((uint16_t)0x00008000) +#define EM_BLE_RXRSVD_POS 15 +#define EM_BLE_RXPOW_BIT ((uint16_t)0x00004000) +#define EM_BLE_RXPOW_POS 14 +#define EM_BLE_RXSYNC_BIT ((uint16_t)0x00002000) +#define EM_BLE_RXSYNC_POS 13 +#define EM_BLE_RXAUXPTR_BIT ((uint16_t)0x00001000) +#define EM_BLE_RXAUXPTR_POS 12 +#define EM_BLE_RXADI_BIT ((uint16_t)0x00000800) +#define EM_BLE_RXADI_POS 11 +#define EM_BLE_RXCTE_BIT ((uint16_t)0x00000400) +#define EM_BLE_RXCTE_POS 10 +#define EM_BLE_RXTGTA_BIT ((uint16_t)0x00000200) +#define EM_BLE_RXTGTA_POS 9 +#define EM_BLE_RXADVA_BIT ((uint16_t)0x00000100) +#define EM_BLE_RXADVA_POS 8 +#define EM_BLE_RXAEMODE_MASK ((uint16_t)0x000000C0) +#define EM_BLE_RXAEMODE_LSB 6 +#define EM_BLE_RXAEMODE_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_RXAELENGTH_MASK ((uint16_t)0x0000003F) +#define EM_BLE_RXAELENGTH_LSB 0 +#define EM_BLE_RXAELENGTH_WIDTH ((uint16_t)0x00000006) + +#define EM_BLE_RXRSVD_RST 0x0 +#define EM_BLE_RXPOW_RST 0x0 +#define EM_BLE_RXSYNC_RST 0x0 +#define EM_BLE_RXAUXPTR_RST 0x0 +#define EM_BLE_RXADI_RST 0x0 +#define EM_BLE_RXCTE_RST 0x0 +#define EM_BLE_RXTGTA_RST 0x0 +#define EM_BLE_RXADVA_RST 0x0 +#define EM_BLE_RXAEMODE_RST 0x0 +#define EM_BLE_RXAELENGTH_RST 0x0 + +__INLINE void em_ble_rxaeheader_pack(int elt_idx, uint8_t rxrsvd, uint8_t rxpow, uint8_t rxsync, uint8_t rxauxptr, uint8_t rxadi, uint8_t rxcte, uint8_t rxtgta, uint8_t rxadva, uint8_t rxaemode, uint8_t rxaelength) +{ + ASSERT_ERR((((uint16_t)rxrsvd << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)rxpow << 14) & ~((uint16_t)0x00004000)) == 0); + ASSERT_ERR((((uint16_t)rxsync << 13) & ~((uint16_t)0x00002000)) == 0); + ASSERT_ERR((((uint16_t)rxauxptr << 12) & ~((uint16_t)0x00001000)) == 0); + ASSERT_ERR((((uint16_t)rxadi << 11) & ~((uint16_t)0x00000800)) == 0); + ASSERT_ERR((((uint16_t)rxcte << 10) & ~((uint16_t)0x00000400)) == 0); + ASSERT_ERR((((uint16_t)rxtgta << 9) & ~((uint16_t)0x00000200)) == 0); + ASSERT_ERR((((uint16_t)rxadva << 8) & ~((uint16_t)0x00000100)) == 0); + ASSERT_ERR((((uint16_t)rxaemode << 6) & ~((uint16_t)0x000000C0)) == 0); + ASSERT_ERR((((uint16_t)rxaelength << 0) & ~((uint16_t)0x0000003F)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, ((uint16_t)rxrsvd << 15) | ((uint16_t)rxpow << 14) | ((uint16_t)rxsync << 13) | ((uint16_t)rxauxptr << 12) | ((uint16_t)rxadi << 11) | ((uint16_t)rxcte << 10) | ((uint16_t)rxtgta << 9) | ((uint16_t)rxadva << 8) | ((uint16_t)rxaemode << 6) | ((uint16_t)rxaelength << 0)); +} + +__INLINE void em_ble_rxaeheader_unpack(int elt_idx, uint8_t* rxrsvd, uint8_t* rxpow, uint8_t* rxsync, uint8_t* rxauxptr, uint8_t* rxadi, uint8_t* rxcte, uint8_t* rxtgta, uint8_t* rxadva, uint8_t* rxaemode, uint8_t* rxaelength) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *rxrsvd = (localVal & ((uint16_t)0x00008000)) >> 15; + *rxpow = (localVal & ((uint16_t)0x00004000)) >> 14; + *rxsync = (localVal & ((uint16_t)0x00002000)) >> 13; + *rxauxptr = (localVal & ((uint16_t)0x00001000)) >> 12; + *rxadi = (localVal & ((uint16_t)0x00000800)) >> 11; + *rxcte = (localVal & ((uint16_t)0x00000400)) >> 10; + *rxtgta = (localVal & ((uint16_t)0x00000200)) >> 9; + *rxadva = (localVal & ((uint16_t)0x00000100)) >> 8; + *rxaemode = (localVal & ((uint16_t)0x000000C0)) >> 6; + *rxaelength = (localVal & ((uint16_t)0x0000003F)) >> 0; +} + +__INLINE uint8_t em_ble_rxaeheader_rxrsvd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_rxaeheader_rxrsvd_setf(int elt_idx, uint8_t rxrsvd) +{ + ASSERT_ERR((((uint16_t)rxrsvd << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)rxrsvd << 15)); +} + +__INLINE uint8_t em_ble_rxaeheader_rxpow_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00004000)) >> 14); +} + +__INLINE void em_ble_rxaeheader_rxpow_setf(int elt_idx, uint8_t rxpow) +{ + ASSERT_ERR((((uint16_t)rxpow << 14) & ~((uint16_t)0x00004000)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00004000)) | ((uint16_t)rxpow << 14)); +} + +__INLINE uint8_t em_ble_rxaeheader_rxsync_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00002000)) >> 13); +} + +__INLINE void em_ble_rxaeheader_rxsync_setf(int elt_idx, uint8_t rxsync) +{ + ASSERT_ERR((((uint16_t)rxsync << 13) & ~((uint16_t)0x00002000)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00002000)) | ((uint16_t)rxsync << 13)); +} + +__INLINE uint8_t em_ble_rxaeheader_rxauxptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00001000)) >> 12); +} + +__INLINE void em_ble_rxaeheader_rxauxptr_setf(int elt_idx, uint8_t rxauxptr) +{ + ASSERT_ERR((((uint16_t)rxauxptr << 12) & ~((uint16_t)0x00001000)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00001000)) | ((uint16_t)rxauxptr << 12)); +} + +__INLINE uint8_t em_ble_rxaeheader_rxadi_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000800)) >> 11); +} + +__INLINE void em_ble_rxaeheader_rxadi_setf(int elt_idx, uint8_t rxadi) +{ + ASSERT_ERR((((uint16_t)rxadi << 11) & ~((uint16_t)0x00000800)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000800)) | ((uint16_t)rxadi << 11)); +} + +__INLINE uint8_t em_ble_rxaeheader_rxcte_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000400)) >> 10); +} + +__INLINE void em_ble_rxaeheader_rxcte_setf(int elt_idx, uint8_t rxcte) +{ + ASSERT_ERR((((uint16_t)rxcte << 10) & ~((uint16_t)0x00000400)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000400)) | ((uint16_t)rxcte << 10)); +} + +__INLINE uint8_t em_ble_rxaeheader_rxtgta_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000200)) >> 9); +} + +__INLINE void em_ble_rxaeheader_rxtgta_setf(int elt_idx, uint8_t rxtgta) +{ + ASSERT_ERR((((uint16_t)rxtgta << 9) & ~((uint16_t)0x00000200)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000200)) | ((uint16_t)rxtgta << 9)); +} + +__INLINE uint8_t em_ble_rxaeheader_rxadva_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000100)) >> 8); +} + +__INLINE void em_ble_rxaeheader_rxadva_setf(int elt_idx, uint8_t rxadva) +{ + ASSERT_ERR((((uint16_t)rxadva << 8) & ~((uint16_t)0x00000100)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000100)) | ((uint16_t)rxadva << 8)); +} + +__INLINE uint8_t em_ble_rxaeheader_rxaemode_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x000000C0)) >> 6); +} + +__INLINE void em_ble_rxaeheader_rxaemode_setf(int elt_idx, uint8_t rxaemode) +{ + ASSERT_ERR((((uint16_t)rxaemode << 6) & ~((uint16_t)0x000000C0)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x000000C0)) | ((uint16_t)rxaemode << 6)); +} + +__INLINE uint8_t em_ble_rxaeheader_rxaelength_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000003F)) >> 0); +} + +__INLINE void em_ble_rxaeheader_rxaelength_setf(int elt_idx, uint8_t rxaelength) +{ + ASSERT_ERR((((uint16_t)rxaelength << 0) & ~((uint16_t)0x0000003F)) == 0); + EM_BLE_WR(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXAEHEADER_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x0000003F)) | ((uint16_t)rxaelength << 0)); +} + +/** + * @brief RXDATAPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00            RXDATAPTR   0x0
+ * 
+ */ +#define EM_BLE_RXDATAPTR_ADDR (EXCHANGE_MEM_BASE+0x14 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXDATAPTR_INDEX 0x0000000A +#define EM_BLE_RXDATAPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxdataptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXDATAPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxdataptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXDATAPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXDATAPTR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_RXDATAPTR_LSB 0 +#define EM_BLE_RXDATAPTR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_RXDATAPTR_RST 0x0 + +__INLINE uint16_t em_ble_rxdataptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXDATAPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_rxdataptr_setf(int elt_idx, uint16_t rxdataptr) +{ + ASSERT_ERR((((uint16_t)rxdataptr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RXDATAPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (uint16_t)rxdataptr << 0); +} + +/** + * @brief RXPHCTE register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08           NBRXIQSAMP   0x0
+ *  07:06            RXCTETYPE   0x0
+ *     05             RXCTERFU   0
+ *  04:00            RXCTETIME   0x0
+ * 
+ */ +#define EM_BLE_RXPHCTE_ADDR (EXCHANGE_MEM_BASE+0x16 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXPHCTE_INDEX 0x0000000B +#define EM_BLE_RXPHCTE_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxphcte_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxphcte_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_NBRXIQSAMP_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_NBRXIQSAMP_LSB 8 +#define EM_BLE_NBRXIQSAMP_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_RXCTETYPE_MASK ((uint16_t)0x000000C0) +#define EM_BLE_RXCTETYPE_LSB 6 +#define EM_BLE_RXCTETYPE_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_RXCTERFU_BIT ((uint16_t)0x00000020) +#define EM_BLE_RXCTERFU_POS 5 +#define EM_BLE_RXCTETIME_MASK ((uint16_t)0x0000001F) +#define EM_BLE_RXCTETIME_LSB 0 +#define EM_BLE_RXCTETIME_WIDTH ((uint16_t)0x00000005) + +#define EM_BLE_NBRXIQSAMP_RST 0x0 +#define EM_BLE_RXCTETYPE_RST 0x0 +#define EM_BLE_RXCTERFU_RST 0x0 +#define EM_BLE_RXCTETIME_RST 0x0 + +__INLINE void em_ble_rxphcte_pack(int elt_idx, uint8_t nbrxiqsamp, uint8_t rxctetype, uint8_t rxcterfu, uint8_t rxctetime) +{ + ASSERT_ERR((((uint16_t)nbrxiqsamp << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)rxctetype << 6) & ~((uint16_t)0x000000C0)) == 0); + ASSERT_ERR((((uint16_t)rxcterfu << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)rxctetime << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_BLE_WR(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, ((uint16_t)nbrxiqsamp << 8) | ((uint16_t)rxctetype << 6) | ((uint16_t)rxcterfu << 5) | ((uint16_t)rxctetime << 0)); +} + +__INLINE void em_ble_rxphcte_unpack(int elt_idx, uint8_t* nbrxiqsamp, uint8_t* rxctetype, uint8_t* rxcterfu, uint8_t* rxctetime) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + + *nbrxiqsamp = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *rxctetype = (localVal & ((uint16_t)0x000000C0)) >> 6; + *rxcterfu = (localVal & ((uint16_t)0x00000020)) >> 5; + *rxctetime = (localVal & ((uint16_t)0x0000001F)) >> 0; +} + +__INLINE uint8_t em_ble_rxphcte_nbrxiqsamp_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_rxphcte_nbrxiqsamp_setf(int elt_idx, uint8_t nbrxiqsamp) +{ + ASSERT_ERR((((uint16_t)nbrxiqsamp << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)nbrxiqsamp << 8)); +} + +__INLINE uint8_t em_ble_rxphcte_rxctetype_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x000000C0)) >> 6); +} + +__INLINE void em_ble_rxphcte_rxctetype_setf(int elt_idx, uint8_t rxctetype) +{ + ASSERT_ERR((((uint16_t)rxctetype << 6) & ~((uint16_t)0x000000C0)) == 0); + EM_BLE_WR(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x000000C0)) | ((uint16_t)rxctetype << 6)); +} + +__INLINE uint8_t em_ble_rxphcte_rxcterfu_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_rxphcte_rxcterfu_setf(int elt_idx, uint8_t rxcterfu) +{ + ASSERT_ERR((((uint16_t)rxcterfu << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)rxcterfu << 5)); +} + +__INLINE uint8_t em_ble_rxphcte_rxctetime_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000001F)) >> 0); +} + +__INLINE void em_ble_rxphcte_rxctetime_setf(int elt_idx, uint8_t rxctetime) +{ + ASSERT_ERR((((uint16_t)rxctetime << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_BLE_WR(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (EM_BLE_RD(EM_BLE_RXPHCTE_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE) & ~((uint16_t)0x0000001F)) | ((uint16_t)rxctetime << 0)); +} + +/** + * @brief RXCTEPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00             RXCTEPTR   0x0
+ * 
+ */ +#define EM_BLE_RXCTEPTR_ADDR (EXCHANGE_MEM_BASE+0x18 + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXCTEPTR_INDEX 0x0000000C +#define EM_BLE_RXCTEPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxcteptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXCTEPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxcteptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXCTEPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RXCTEPTR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_RXCTEPTR_LSB 0 +#define EM_BLE_RXCTEPTR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_RXCTEPTR_RST 0x0 + +__INLINE uint16_t em_ble_rxcteptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXCTEPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_rxcteptr_setf(int elt_idx, uint16_t rxcteptr) +{ + ASSERT_ERR((((uint16_t)rxcteptr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RXCTEPTR_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (uint16_t)rxcteptr << 0); +} + +/** + * @brief RXRESERVED register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00                 RSVD   0x0
+ * 
+ */ +#define EM_BLE_RXRESERVED_ADDR (EXCHANGE_MEM_BASE+0x1A + EM_BLE_RX_DESC_OFFSET) +#define EM_BLE_RXRESERVED_INDEX 0x0000000D +#define EM_BLE_RXRESERVED_RESET 0x00000000 + +__INLINE uint16_t em_ble_rxreserved_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_RXRESERVED_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); +} + +__INLINE void em_ble_rxreserved_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_RXRESERVED_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_RSVD_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_RSVD_LSB 0 +#define EM_BLE_RSVD_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_RSVD_RST 0x0 + +__INLINE uint16_t em_ble_rxreserved_rsvd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_RXRESERVED_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_rxreserved_rsvd_setf(int elt_idx, uint16_t rsvd) +{ + ASSERT_ERR((((uint16_t)rsvd << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_RXRESERVED_ADDR + elt_idx * REG_EM_BLE_RX_DESC_SIZE, (uint16_t)rsvd << 0); +} + + +#endif // _REG_EM_BLE_RX_DESC_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_tx_desc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_tx_desc.h new file mode 100644 index 0000000..52341c0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_tx_desc.h @@ -0,0 +1,974 @@ +#ifndef _REG_EM_BLE_TX_DESC_H_ +#define _REG_EM_BLE_TX_DESC_H_ + +#include +#include "_reg_em_ble_tx_desc.h" +#include "compiler.h" +#include "arch.h" +#include "em_map.h" +#include "reg_access.h" + +#define REG_EM_BLE_TX_DESC_COUNT 8 + +#define REG_EM_BLE_TX_DESC_DECODING_MASK 0x0000000F + +#define REG_EM_BLE_TX_DESC_ADDR_GET(idx) (EM_BLE_TX_DESC_OFFSET + (idx) * REG_EM_BLE_TX_DESC_SIZE) + +/** + * @brief TXCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15               TXDONE   0
+ *  13:00             NEXT_PTR   0x0
+ * 
+ */ +#define EM_BLE_TXCNTL_ADDR (EXCHANGE_MEM_BASE + EM_BLE_TX_DESC_OFFSET) +#define EM_BLE_TXCNTL_INDEX 0x00000000 +#define EM_BLE_TXCNTL_RESET 0x00000000 + +__INLINE uint16_t em_ble_txcntl_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXCNTL_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); +} + +__INLINE void em_ble_txcntl_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXCNTL_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_TXDONE_BIT ((uint16_t)0x00008000) +#define EM_BLE_TXDONE_POS 15 +#define EM_BLE_NEXT_PTR_MASK ((uint16_t)0x00003FFF) +#define EM_BLE_NEXT_PTR_LSB 0 +#define EM_BLE_NEXT_PTR_WIDTH ((uint16_t)0x0000000E) + +#define EM_BLE_TXDONE_RST 0x0 +#define EM_BLE_NEXT_PTR_RST 0x0 + +__INLINE void em_ble_txcntl_pack(int elt_idx, uint8_t txdone, uint16_t nextptr) +{ + ASSERT_ERR((((uint16_t)txdone << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)nextptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_TXCNTL_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, ((uint16_t)txdone << 15) | ((uint16_t)nextptr << 0)); +} + +__INLINE void em_ble_txcntl_unpack(int elt_idx, uint8_t* txdone, uint16_t* nextptr) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXCNTL_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + + *txdone = (localVal & ((uint16_t)0x00008000)) >> 15; + *nextptr = (localVal & ((uint16_t)0x00003FFF)) >> 0; +} + +__INLINE uint8_t em_ble_txcntl_txdone_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXCNTL_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_txcntl_txdone_setf(int elt_idx, uint8_t txdone) +{ + ASSERT_ERR((((uint16_t)txdone << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_TXCNTL_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXCNTL_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)txdone << 15)); +} + +__INLINE uint16_t em_ble_txcntl_next_ptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXCNTL_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00003FFF)) >> 0); +} + +__INLINE void em_ble_txcntl_next_ptr_setf(int elt_idx, uint16_t nextptr) +{ + ASSERT_ERR((((uint16_t)nextptr << 0) & ~((uint16_t)0x00003FFF)) == 0); + EM_BLE_WR(EM_BLE_TXCNTL_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXCNTL_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00003FFF)) | ((uint16_t)nextptr << 0)); +} + +/** + * @brief TXPHCE register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08                TXLEN   0x0
+ *  07:06             TXACLRFU   0x0
+ *     05                 TXCP   0
+ *     04                 TXMD   0
+ *     03                 TXSN   0
+ *     02               TXNESN   0
+ *  01:00               TXLLID   0x0
+ * 
+ */ +#define EM_BLE_TXPHCE_ADDR (EXCHANGE_MEM_BASE+0x02 + EM_BLE_TX_DESC_OFFSET) +#define EM_BLE_TXPHCE_INDEX 0x00000001 +#define EM_BLE_TXPHCE_RESET 0x00000000 + +__INLINE uint16_t em_ble_txphce_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); +} + +__INLINE void em_ble_txphce_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_TXLEN_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_TXLEN_LSB 8 +#define EM_BLE_TXLEN_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_TXACLRFU_MASK ((uint16_t)0x000000C0) +#define EM_BLE_TXACLRFU_LSB 6 +#define EM_BLE_TXACLRFU_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_TXCP_BIT ((uint16_t)0x00000020) +#define EM_BLE_TXCP_POS 5 +#define EM_BLE_TXMD_BIT ((uint16_t)0x00000010) +#define EM_BLE_TXMD_POS 4 +#define EM_BLE_TXSN_BIT ((uint16_t)0x00000008) +#define EM_BLE_TXSN_POS 3 +#define EM_BLE_TXNESN_BIT ((uint16_t)0x00000004) +#define EM_BLE_TXNESN_POS 2 +#define EM_BLE_TXLLID_MASK ((uint16_t)0x00000003) +#define EM_BLE_TXLLID_LSB 0 +#define EM_BLE_TXLLID_WIDTH ((uint16_t)0x00000002) + +#define EM_BLE_TXLEN_RST 0x0 +#define EM_BLE_TXACLRFU_RST 0x0 +#define EM_BLE_TXCP_RST 0x0 +#define EM_BLE_TXMD_RST 0x0 +#define EM_BLE_TXSN_RST 0x0 +#define EM_BLE_TXNESN_RST 0x0 +#define EM_BLE_TXLLID_RST 0x0 + +__INLINE void em_ble_txphce_pack(int elt_idx, uint8_t txlen, uint8_t txaclrfu, uint8_t txcp, uint8_t txmd, uint8_t txsn, uint8_t txnesn, uint8_t txllid) +{ + ASSERT_ERR((((uint16_t)txlen << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)txaclrfu << 6) & ~((uint16_t)0x000000C0)) == 0); + ASSERT_ERR((((uint16_t)txcp << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)txmd << 4) & ~((uint16_t)0x00000010)) == 0); + ASSERT_ERR((((uint16_t)txsn << 3) & ~((uint16_t)0x00000008)) == 0); + ASSERT_ERR((((uint16_t)txnesn << 2) & ~((uint16_t)0x00000004)) == 0); + ASSERT_ERR((((uint16_t)txllid << 0) & ~((uint16_t)0x00000003)) == 0); + EM_BLE_WR(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, ((uint16_t)txlen << 8) | ((uint16_t)txaclrfu << 6) | ((uint16_t)txcp << 5) | ((uint16_t)txmd << 4) | ((uint16_t)txsn << 3) | ((uint16_t)txnesn << 2) | ((uint16_t)txllid << 0)); +} + +__INLINE void em_ble_txphce_unpack(int elt_idx, uint8_t* txlen, uint8_t* txaclrfu, uint8_t* txcp, uint8_t* txmd, uint8_t* txsn, uint8_t* txnesn, uint8_t* txllid) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + + *txlen = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *txaclrfu = (localVal & ((uint16_t)0x000000C0)) >> 6; + *txcp = (localVal & ((uint16_t)0x00000020)) >> 5; + *txmd = (localVal & ((uint16_t)0x00000010)) >> 4; + *txsn = (localVal & ((uint16_t)0x00000008)) >> 3; + *txnesn = (localVal & ((uint16_t)0x00000004)) >> 2; + *txllid = (localVal & ((uint16_t)0x00000003)) >> 0; +} + +__INLINE uint8_t em_ble_txphce_txlen_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_txphce_txlen_setf(int elt_idx, uint8_t txlen) +{ + ASSERT_ERR((((uint16_t)txlen << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)txlen << 8)); +} + +__INLINE uint8_t em_ble_txphce_txaclrfu_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x000000C0)) >> 6); +} + +__INLINE void em_ble_txphce_txaclrfu_setf(int elt_idx, uint8_t txaclrfu) +{ + ASSERT_ERR((((uint16_t)txaclrfu << 6) & ~((uint16_t)0x000000C0)) == 0); + EM_BLE_WR(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x000000C0)) | ((uint16_t)txaclrfu << 6)); +} + +__INLINE uint8_t em_ble_txphce_txcp_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_txphce_txcp_setf(int elt_idx, uint8_t txcp) +{ + ASSERT_ERR((((uint16_t)txcp << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)txcp << 5)); +} + +__INLINE uint8_t em_ble_txphce_txmd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000010)) >> 4); +} + +__INLINE void em_ble_txphce_txmd_setf(int elt_idx, uint8_t txmd) +{ + ASSERT_ERR((((uint16_t)txmd << 4) & ~((uint16_t)0x00000010)) == 0); + EM_BLE_WR(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000010)) | ((uint16_t)txmd << 4)); +} + +__INLINE uint8_t em_ble_txphce_txsn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000008)) >> 3); +} + +__INLINE void em_ble_txphce_txsn_setf(int elt_idx, uint8_t txsn) +{ + ASSERT_ERR((((uint16_t)txsn << 3) & ~((uint16_t)0x00000008)) == 0); + EM_BLE_WR(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000008)) | ((uint16_t)txsn << 3)); +} + +__INLINE uint8_t em_ble_txphce_txnesn_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000004)) >> 2); +} + +__INLINE void em_ble_txphce_txnesn_setf(int elt_idx, uint8_t txnesn) +{ + ASSERT_ERR((((uint16_t)txnesn << 2) & ~((uint16_t)0x00000004)) == 0); + EM_BLE_WR(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000004)) | ((uint16_t)txnesn << 2)); +} + +__INLINE uint8_t em_ble_txphce_txllid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000003)) >> 0); +} + +__INLINE void em_ble_txphce_txllid_setf(int elt_idx, uint8_t txllid) +{ + ASSERT_ERR((((uint16_t)txllid << 0) & ~((uint16_t)0x00000003)) == 0); + EM_BLE_WR(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHCE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000003)) | ((uint16_t)txllid << 0)); +} + +/** + * @brief TXPHADV register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08             TXADVLEN   0x0
+ *     07              TXRXADD   0
+ *     06              TXTXADD   0
+ *     05             TXCHSEL2   0
+ *     04             TXADVRFU   0
+ *  03:00               TXTYPE   0x0
+ * 
+ */ +#define EM_BLE_TXPHADV_ADDR (EXCHANGE_MEM_BASE+0x02 + EM_BLE_TX_DESC_OFFSET) +#define EM_BLE_TXPHADV_INDEX 0x00000001 +#define EM_BLE_TXPHADV_RESET 0x00000000 + +__INLINE uint16_t em_ble_txphadv_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); +} + +__INLINE void em_ble_txphadv_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_TXADVLEN_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_TXADVLEN_LSB 8 +#define EM_BLE_TXADVLEN_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_TXRXADD_BIT ((uint16_t)0x00000080) +#define EM_BLE_TXRXADD_POS 7 +#define EM_BLE_TXTXADD_BIT ((uint16_t)0x00000040) +#define EM_BLE_TXTXADD_POS 6 +#define EM_BLE_TXCHSEL2_BIT ((uint16_t)0x00000020) +#define EM_BLE_TXCHSEL2_POS 5 +#define EM_BLE_TXADVRFU_BIT ((uint16_t)0x00000010) +#define EM_BLE_TXADVRFU_POS 4 +#define EM_BLE_TXTYPE_MASK ((uint16_t)0x0000000F) +#define EM_BLE_TXTYPE_LSB 0 +#define EM_BLE_TXTYPE_WIDTH ((uint16_t)0x00000004) + +#define EM_BLE_TXADVLEN_RST 0x0 +#define EM_BLE_TXRXADD_RST 0x0 +#define EM_BLE_TXTXADD_RST 0x0 +#define EM_BLE_TXCHSEL2_RST 0x0 +#define EM_BLE_TXADVRFU_RST 0x0 +#define EM_BLE_TXTYPE_RST 0x0 + +__INLINE void em_ble_txphadv_pack(int elt_idx, uint8_t txadvlen, uint8_t txrxadd, uint8_t txtxadd, uint8_t txchsel2, uint8_t txadvrfu, uint8_t txtype) +{ + ASSERT_ERR((((uint16_t)txadvlen << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)txrxadd << 7) & ~((uint16_t)0x00000080)) == 0); + ASSERT_ERR((((uint16_t)txtxadd << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)txchsel2 << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)txadvrfu << 4) & ~((uint16_t)0x00000010)) == 0); + ASSERT_ERR((((uint16_t)txtype << 0) & ~((uint16_t)0x0000000F)) == 0); + EM_BLE_WR(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, ((uint16_t)txadvlen << 8) | ((uint16_t)txrxadd << 7) | ((uint16_t)txtxadd << 6) | ((uint16_t)txchsel2 << 5) | ((uint16_t)txadvrfu << 4) | ((uint16_t)txtype << 0)); +} + +__INLINE void em_ble_txphadv_unpack(int elt_idx, uint8_t* txadvlen, uint8_t* txrxadd, uint8_t* txtxadd, uint8_t* txchsel2, uint8_t* txadvrfu, uint8_t* txtype) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + + *txadvlen = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *txrxadd = (localVal & ((uint16_t)0x00000080)) >> 7; + *txtxadd = (localVal & ((uint16_t)0x00000040)) >> 6; + *txchsel2 = (localVal & ((uint16_t)0x00000020)) >> 5; + *txadvrfu = (localVal & ((uint16_t)0x00000010)) >> 4; + *txtype = (localVal & ((uint16_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t em_ble_txphadv_txadvlen_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_txphadv_txadvlen_setf(int elt_idx, uint8_t txadvlen) +{ + ASSERT_ERR((((uint16_t)txadvlen << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)txadvlen << 8)); +} + +__INLINE uint8_t em_ble_txphadv_txrxadd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000080)) >> 7); +} + +__INLINE void em_ble_txphadv_txrxadd_setf(int elt_idx, uint8_t txrxadd) +{ + ASSERT_ERR((((uint16_t)txrxadd << 7) & ~((uint16_t)0x00000080)) == 0); + EM_BLE_WR(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000080)) | ((uint16_t)txrxadd << 7)); +} + +__INLINE uint8_t em_ble_txphadv_txtxadd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_ble_txphadv_txtxadd_setf(int elt_idx, uint8_t txtxadd) +{ + ASSERT_ERR((((uint16_t)txtxadd << 6) & ~((uint16_t)0x00000040)) == 0); + EM_BLE_WR(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)txtxadd << 6)); +} + +__INLINE uint8_t em_ble_txphadv_txchsel2_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_txphadv_txchsel2_setf(int elt_idx, uint8_t txchsel2) +{ + ASSERT_ERR((((uint16_t)txchsel2 << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)txchsel2 << 5)); +} + +__INLINE uint8_t em_ble_txphadv_txadvrfu_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000010)) >> 4); +} + +__INLINE void em_ble_txphadv_txadvrfu_setf(int elt_idx, uint8_t txadvrfu) +{ + ASSERT_ERR((((uint16_t)txadvrfu << 4) & ~((uint16_t)0x00000010)) == 0); + EM_BLE_WR(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000010)) | ((uint16_t)txadvrfu << 4)); +} + +__INLINE uint8_t em_ble_txphadv_txtype_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000000F)) >> 0); +} + +__INLINE void em_ble_txphadv_txtype_setf(int elt_idx, uint8_t txtype) +{ + ASSERT_ERR((((uint16_t)txtype << 0) & ~((uint16_t)0x0000000F)) == 0); + EM_BLE_WR(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHADV_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x0000000F)) | ((uint16_t)txtype << 0)); +} + +/** + * @brief TXDATAPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00            TXDATAPTR   0x0
+ * 
+ */ +#define EM_BLE_TXDATAPTR_ADDR (EXCHANGE_MEM_BASE+0x04 + EM_BLE_TX_DESC_OFFSET) +#define EM_BLE_TXDATAPTR_INDEX 0x00000002 +#define EM_BLE_TXDATAPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_txdataptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXDATAPTR_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); +} + +__INLINE void em_ble_txdataptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXDATAPTR_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_TXDATAPTR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_TXDATAPTR_LSB 0 +#define EM_BLE_TXDATAPTR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_TXDATAPTR_RST 0x0 + +__INLINE uint16_t em_ble_txdataptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXDATAPTR_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_txdataptr_setf(int elt_idx, uint16_t txdataptr) +{ + ASSERT_ERR((((uint16_t)txdataptr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_TXDATAPTR_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (uint16_t)txdataptr << 0); +} + +/** + * @brief TXAEHEADER register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15               TXRSVD   0
+ *     14                TXPOW   0
+ *     13               TXSYNC   0
+ *     12             TXAUXPTR   0
+ *     11                TXADI   0
+ *     10               TXSUPP   0
+ *     09               TXTGTA   0
+ *     08               TXADVA   0
+ *  07:06             TXAEMODE   0x0
+ *  05:00           TXAELENGTH   0x0
+ * 
+ */ +#define EM_BLE_TXAEHEADER_ADDR (EXCHANGE_MEM_BASE+0x06 + EM_BLE_TX_DESC_OFFSET) +#define EM_BLE_TXAEHEADER_INDEX 0x00000003 +#define EM_BLE_TXAEHEADER_RESET 0x00000000 + +__INLINE uint16_t em_ble_txaeheader_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); +} + +__INLINE void em_ble_txaeheader_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_TXRSVD_BIT ((uint16_t)0x00008000) +#define EM_BLE_TXRSVD_POS 15 +#define EM_BLE_TXPOW_BIT ((uint16_t)0x00004000) +#define EM_BLE_TXPOW_POS 14 +#define EM_BLE_TXSYNC_BIT ((uint16_t)0x00002000) +#define EM_BLE_TXSYNC_POS 13 +#define EM_BLE_TXAUXPTR_BIT ((uint16_t)0x00001000) +#define EM_BLE_TXAUXPTR_POS 12 +#define EM_BLE_TXADI_BIT ((uint16_t)0x00000800) +#define EM_BLE_TXADI_POS 11 +#define EM_BLE_TXSUPP_BIT ((uint16_t)0x00000400) +#define EM_BLE_TXSUPP_POS 10 +#define EM_BLE_TXTGTA_BIT ((uint16_t)0x00000200) +#define EM_BLE_TXTGTA_POS 9 +#define EM_BLE_TXADVA_BIT ((uint16_t)0x00000100) +#define EM_BLE_TXADVA_POS 8 +#define EM_BLE_TXAEMODE_MASK ((uint16_t)0x000000C0) +#define EM_BLE_TXAEMODE_LSB 6 +#define EM_BLE_TXAEMODE_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_TXAELENGTH_MASK ((uint16_t)0x0000003F) +#define EM_BLE_TXAELENGTH_LSB 0 +#define EM_BLE_TXAELENGTH_WIDTH ((uint16_t)0x00000006) + +#define EM_BLE_TXRSVD_RST 0x0 +#define EM_BLE_TXPOW_RST 0x0 +#define EM_BLE_TXSYNC_RST 0x0 +#define EM_BLE_TXAUXPTR_RST 0x0 +#define EM_BLE_TXADI_RST 0x0 +#define EM_BLE_TXSUPP_RST 0x0 +#define EM_BLE_TXTGTA_RST 0x0 +#define EM_BLE_TXADVA_RST 0x0 +#define EM_BLE_TXAEMODE_RST 0x0 +#define EM_BLE_TXAELENGTH_RST 0x0 + +__INLINE void em_ble_txaeheader_pack(int elt_idx, uint8_t txrsvd, uint8_t txpow, uint8_t txsync, uint8_t txauxptr, uint8_t txadi, uint8_t txsupp, uint8_t txtgta, uint8_t txadva, uint8_t txaemode, uint8_t txaelength) +{ + ASSERT_ERR((((uint16_t)txrsvd << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)txpow << 14) & ~((uint16_t)0x00004000)) == 0); + ASSERT_ERR((((uint16_t)txsync << 13) & ~((uint16_t)0x00002000)) == 0); + ASSERT_ERR((((uint16_t)txauxptr << 12) & ~((uint16_t)0x00001000)) == 0); + ASSERT_ERR((((uint16_t)txadi << 11) & ~((uint16_t)0x00000800)) == 0); + ASSERT_ERR((((uint16_t)txsupp << 10) & ~((uint16_t)0x00000400)) == 0); + ASSERT_ERR((((uint16_t)txtgta << 9) & ~((uint16_t)0x00000200)) == 0); + ASSERT_ERR((((uint16_t)txadva << 8) & ~((uint16_t)0x00000100)) == 0); + ASSERT_ERR((((uint16_t)txaemode << 6) & ~((uint16_t)0x000000C0)) == 0); + ASSERT_ERR((((uint16_t)txaelength << 0) & ~((uint16_t)0x0000003F)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, ((uint16_t)txrsvd << 15) | ((uint16_t)txpow << 14) | ((uint16_t)txsync << 13) | ((uint16_t)txauxptr << 12) | ((uint16_t)txadi << 11) | ((uint16_t)txsupp << 10) | ((uint16_t)txtgta << 9) | ((uint16_t)txadva << 8) | ((uint16_t)txaemode << 6) | ((uint16_t)txaelength << 0)); +} + +__INLINE void em_ble_txaeheader_unpack(int elt_idx, uint8_t* txrsvd, uint8_t* txpow, uint8_t* txsync, uint8_t* txauxptr, uint8_t* txadi, uint8_t* txsupp, uint8_t* txtgta, uint8_t* txadva, uint8_t* txaemode, uint8_t* txaelength) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + + *txrsvd = (localVal & ((uint16_t)0x00008000)) >> 15; + *txpow = (localVal & ((uint16_t)0x00004000)) >> 14; + *txsync = (localVal & ((uint16_t)0x00002000)) >> 13; + *txauxptr = (localVal & ((uint16_t)0x00001000)) >> 12; + *txadi = (localVal & ((uint16_t)0x00000800)) >> 11; + *txsupp = (localVal & ((uint16_t)0x00000400)) >> 10; + *txtgta = (localVal & ((uint16_t)0x00000200)) >> 9; + *txadva = (localVal & ((uint16_t)0x00000100)) >> 8; + *txaemode = (localVal & ((uint16_t)0x000000C0)) >> 6; + *txaelength = (localVal & ((uint16_t)0x0000003F)) >> 0; +} + +__INLINE uint8_t em_ble_txaeheader_txrsvd_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_txaeheader_txrsvd_setf(int elt_idx, uint8_t txrsvd) +{ + ASSERT_ERR((((uint16_t)txrsvd << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)txrsvd << 15)); +} + +__INLINE uint8_t em_ble_txaeheader_txpow_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00004000)) >> 14); +} + +__INLINE void em_ble_txaeheader_txpow_setf(int elt_idx, uint8_t txpow) +{ + ASSERT_ERR((((uint16_t)txpow << 14) & ~((uint16_t)0x00004000)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00004000)) | ((uint16_t)txpow << 14)); +} + +__INLINE uint8_t em_ble_txaeheader_txsync_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00002000)) >> 13); +} + +__INLINE void em_ble_txaeheader_txsync_setf(int elt_idx, uint8_t txsync) +{ + ASSERT_ERR((((uint16_t)txsync << 13) & ~((uint16_t)0x00002000)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00002000)) | ((uint16_t)txsync << 13)); +} + +__INLINE uint8_t em_ble_txaeheader_txauxptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00001000)) >> 12); +} + +__INLINE void em_ble_txaeheader_txauxptr_setf(int elt_idx, uint8_t txauxptr) +{ + ASSERT_ERR((((uint16_t)txauxptr << 12) & ~((uint16_t)0x00001000)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00001000)) | ((uint16_t)txauxptr << 12)); +} + +__INLINE uint8_t em_ble_txaeheader_txadi_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000800)) >> 11); +} + +__INLINE void em_ble_txaeheader_txadi_setf(int elt_idx, uint8_t txadi) +{ + ASSERT_ERR((((uint16_t)txadi << 11) & ~((uint16_t)0x00000800)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000800)) | ((uint16_t)txadi << 11)); +} + +__INLINE uint8_t em_ble_txaeheader_txsupp_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000400)) >> 10); +} + +__INLINE void em_ble_txaeheader_txsupp_setf(int elt_idx, uint8_t txsupp) +{ + ASSERT_ERR((((uint16_t)txsupp << 10) & ~((uint16_t)0x00000400)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000400)) | ((uint16_t)txsupp << 10)); +} + +__INLINE uint8_t em_ble_txaeheader_txtgta_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000200)) >> 9); +} + +__INLINE void em_ble_txaeheader_txtgta_setf(int elt_idx, uint8_t txtgta) +{ + ASSERT_ERR((((uint16_t)txtgta << 9) & ~((uint16_t)0x00000200)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000200)) | ((uint16_t)txtgta << 9)); +} + +__INLINE uint8_t em_ble_txaeheader_txadva_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000100)) >> 8); +} + +__INLINE void em_ble_txaeheader_txadva_setf(int elt_idx, uint8_t txadva) +{ + ASSERT_ERR((((uint16_t)txadva << 8) & ~((uint16_t)0x00000100)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000100)) | ((uint16_t)txadva << 8)); +} + +__INLINE uint8_t em_ble_txaeheader_txaemode_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x000000C0)) >> 6); +} + +__INLINE void em_ble_txaeheader_txaemode_setf(int elt_idx, uint8_t txaemode) +{ + ASSERT_ERR((((uint16_t)txaemode << 6) & ~((uint16_t)0x000000C0)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x000000C0)) | ((uint16_t)txaemode << 6)); +} + +__INLINE uint8_t em_ble_txaeheader_txaelength_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000003F)) >> 0); +} + +__INLINE void em_ble_txaeheader_txaelength_setf(int elt_idx, uint8_t txaelength) +{ + ASSERT_ERR((((uint16_t)txaelength << 0) & ~((uint16_t)0x0000003F)) == 0); + EM_BLE_WR(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAEHEADER_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x0000003F)) | ((uint16_t)txaelength << 0)); +} + +/** + * @brief TXAUXPTR0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:08      TXAUXOFFSET_LSB   0x0
+ *     07     TXAUXOFFSET_UNIT   0
+ *     06             TXAUX_CA   0
+ *  05:00             TX_LL_CH   0x0
+ * 
+ */ +#define EM_BLE_TXAUXPTR0_ADDR (EXCHANGE_MEM_BASE+0x08 + EM_BLE_TX_DESC_OFFSET) +#define EM_BLE_TXAUXPTR0_INDEX 0x00000004 +#define EM_BLE_TXAUXPTR0_RESET 0x00000000 + +__INLINE uint16_t em_ble_txauxptr0_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); +} + +__INLINE void em_ble_txauxptr0_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_TXAUXOFFSET_LSB_MASK ((uint16_t)0x0000FF00) +#define EM_BLE_TXAUXOFFSET_LSB_LSB 8 +#define EM_BLE_TXAUXOFFSET_LSB_WIDTH ((uint16_t)0x00000008) +#define EM_BLE_TXAUXOFFSET_UNIT_BIT ((uint16_t)0x00000080) +#define EM_BLE_TXAUXOFFSET_UNIT_POS 7 +#define EM_BLE_TXAUX_CA_BIT ((uint16_t)0x00000040) +#define EM_BLE_TXAUX_CA_POS 6 +#define EM_BLE_TX_LL_CH_MASK ((uint16_t)0x0000003F) +#define EM_BLE_TX_LL_CH_LSB 0 +#define EM_BLE_TX_LL_CH_WIDTH ((uint16_t)0x00000006) + +#define EM_BLE_TXAUXOFFSET_LSB_RST 0x0 +#define EM_BLE_TXAUXOFFSET_UNIT_RST 0x0 +#define EM_BLE_TXAUX_CA_RST 0x0 +#define EM_BLE_TX_LL_CH_RST 0x0 + +__INLINE void em_ble_txauxptr0_pack(int elt_idx, uint8_t txauxoffsetlsb, uint8_t txauxoffsetunit, uint8_t txauxca, uint8_t txllch) +{ + ASSERT_ERR((((uint16_t)txauxoffsetlsb << 8) & ~((uint16_t)0x0000FF00)) == 0); + ASSERT_ERR((((uint16_t)txauxoffsetunit << 7) & ~((uint16_t)0x00000080)) == 0); + ASSERT_ERR((((uint16_t)txauxca << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)txllch << 0) & ~((uint16_t)0x0000003F)) == 0); + EM_BLE_WR(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, ((uint16_t)txauxoffsetlsb << 8) | ((uint16_t)txauxoffsetunit << 7) | ((uint16_t)txauxca << 6) | ((uint16_t)txllch << 0)); +} + +__INLINE void em_ble_txauxptr0_unpack(int elt_idx, uint8_t* txauxoffsetlsb, uint8_t* txauxoffsetunit, uint8_t* txauxca, uint8_t* txllch) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + + *txauxoffsetlsb = (localVal & ((uint16_t)0x0000FF00)) >> 8; + *txauxoffsetunit = (localVal & ((uint16_t)0x00000080)) >> 7; + *txauxca = (localVal & ((uint16_t)0x00000040)) >> 6; + *txllch = (localVal & ((uint16_t)0x0000003F)) >> 0; +} + +__INLINE uint8_t em_ble_txauxptr0_txauxoffset_lsb_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000FF00)) >> 8); +} + +__INLINE void em_ble_txauxptr0_txauxoffset_lsb_setf(int elt_idx, uint8_t txauxoffsetlsb) +{ + ASSERT_ERR((((uint16_t)txauxoffsetlsb << 8) & ~((uint16_t)0x0000FF00)) == 0); + EM_BLE_WR(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x0000FF00)) | ((uint16_t)txauxoffsetlsb << 8)); +} + +__INLINE uint8_t em_ble_txauxptr0_txauxoffset_unit_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000080)) >> 7); +} + +__INLINE void em_ble_txauxptr0_txauxoffset_unit_setf(int elt_idx, uint8_t txauxoffsetunit) +{ + ASSERT_ERR((((uint16_t)txauxoffsetunit << 7) & ~((uint16_t)0x00000080)) == 0); + EM_BLE_WR(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000080)) | ((uint16_t)txauxoffsetunit << 7)); +} + +__INLINE uint8_t em_ble_txauxptr0_txaux_ca_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_ble_txauxptr0_txaux_ca_setf(int elt_idx, uint8_t txauxca) +{ + ASSERT_ERR((((uint16_t)txauxca << 6) & ~((uint16_t)0x00000040)) == 0); + EM_BLE_WR(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)txauxca << 6)); +} + +__INLINE uint8_t em_ble_txauxptr0_tx_ll_ch_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000003F)) >> 0); +} + +__INLINE void em_ble_txauxptr0_tx_ll_ch_setf(int elt_idx, uint8_t txllch) +{ + ASSERT_ERR((((uint16_t)txllch << 0) & ~((uint16_t)0x0000003F)) == 0); + EM_BLE_WR(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAUXPTR0_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x0000003F)) | ((uint16_t)txllch << 0)); +} + +/** + * @brief TXAUXPTR1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  07:05            TXAUX_PHY   0x0
+ *  04:00      TXAUXOFFSET_MSB   0x0
+ * 
+ */ +#define EM_BLE_TXAUXPTR1_ADDR (EXCHANGE_MEM_BASE+0x0A + EM_BLE_TX_DESC_OFFSET) +#define EM_BLE_TXAUXPTR1_INDEX 0x00000005 +#define EM_BLE_TXAUXPTR1_RESET 0x00000000 + +__INLINE uint16_t em_ble_txauxptr1_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXAUXPTR1_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); +} + +__INLINE void em_ble_txauxptr1_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXAUXPTR1_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_TXAUX_PHY_MASK ((uint16_t)0x000000E0) +#define EM_BLE_TXAUX_PHY_LSB 5 +#define EM_BLE_TXAUX_PHY_WIDTH ((uint16_t)0x00000003) +#define EM_BLE_TXAUXOFFSET_MSB_MASK ((uint16_t)0x0000001F) +#define EM_BLE_TXAUXOFFSET_MSB_LSB 0 +#define EM_BLE_TXAUXOFFSET_MSB_WIDTH ((uint16_t)0x00000005) + +#define EM_BLE_TXAUX_PHY_RST 0x0 +#define EM_BLE_TXAUXOFFSET_MSB_RST 0x0 + +__INLINE void em_ble_txauxptr1_pack(int elt_idx, uint8_t txauxphy, uint8_t txauxoffsetmsb) +{ + ASSERT_ERR((((uint16_t)txauxphy << 5) & ~((uint16_t)0x000000E0)) == 0); + ASSERT_ERR((((uint16_t)txauxoffsetmsb << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_BLE_WR(EM_BLE_TXAUXPTR1_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, ((uint16_t)txauxphy << 5) | ((uint16_t)txauxoffsetmsb << 0)); +} + +__INLINE void em_ble_txauxptr1_unpack(int elt_idx, uint8_t* txauxphy, uint8_t* txauxoffsetmsb) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAUXPTR1_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + + *txauxphy = (localVal & ((uint16_t)0x000000E0)) >> 5; + *txauxoffsetmsb = (localVal & ((uint16_t)0x0000001F)) >> 0; +} + +__INLINE uint8_t em_ble_txauxptr1_txaux_phy_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAUXPTR1_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x000000E0)) >> 5); +} + +__INLINE void em_ble_txauxptr1_txaux_phy_setf(int elt_idx, uint8_t txauxphy) +{ + ASSERT_ERR((((uint16_t)txauxphy << 5) & ~((uint16_t)0x000000E0)) == 0); + EM_BLE_WR(EM_BLE_TXAUXPTR1_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAUXPTR1_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x000000E0)) | ((uint16_t)txauxphy << 5)); +} + +__INLINE uint8_t em_ble_txauxptr1_txauxoffset_msb_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAUXPTR1_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000001F)) >> 0); +} + +__INLINE void em_ble_txauxptr1_txauxoffset_msb_setf(int elt_idx, uint8_t txauxoffsetmsb) +{ + ASSERT_ERR((((uint16_t)txauxoffsetmsb << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_BLE_WR(EM_BLE_TXAUXPTR1_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXAUXPTR1_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x0000001F)) | ((uint16_t)txauxoffsetmsb << 0)); +} + +/** + * @brief TXAEDATAPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00          TXAEDATAPTR   0x0
+ * 
+ */ +#define EM_BLE_TXAEDATAPTR_ADDR (EXCHANGE_MEM_BASE+0x0C + EM_BLE_TX_DESC_OFFSET) +#define EM_BLE_TXAEDATAPTR_INDEX 0x00000006 +#define EM_BLE_TXAEDATAPTR_RESET 0x00000000 + +__INLINE uint16_t em_ble_txaedataptr_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXAEDATAPTR_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); +} + +__INLINE void em_ble_txaedataptr_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXAEDATAPTR_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_TXAEDATAPTR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_TXAEDATAPTR_LSB 0 +#define EM_BLE_TXAEDATAPTR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_TXAEDATAPTR_RST 0x0 + +__INLINE uint16_t em_ble_txaedataptr_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXAEDATAPTR_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_txaedataptr_setf(int elt_idx, uint16_t txaedataptr) +{ + ASSERT_ERR((((uint16_t)txaedataptr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_TXAEDATAPTR_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (uint16_t)txaedataptr << 0); +} + +/** + * @brief TXPHCTE register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  07:06            TXCTETYPE   0x0
+ *     05             TXCTERFU   0
+ *  04:00            TXCTETIME   0x0
+ * 
+ */ +#define EM_BLE_TXPHCTE_ADDR (EXCHANGE_MEM_BASE+0x0E + EM_BLE_TX_DESC_OFFSET) +#define EM_BLE_TXPHCTE_INDEX 0x00000007 +#define EM_BLE_TXPHCTE_RESET 0x00000000 + +__INLINE uint16_t em_ble_txphcte_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); +} + +__INLINE void em_ble_txphcte_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, value); +} + +// field definitions +#define EM_BLE_TXCTETYPE_MASK ((uint16_t)0x000000C0) +#define EM_BLE_TXCTETYPE_LSB 6 +#define EM_BLE_TXCTETYPE_WIDTH ((uint16_t)0x00000002) +#define EM_BLE_TXCTERFU_BIT ((uint16_t)0x00000020) +#define EM_BLE_TXCTERFU_POS 5 +#define EM_BLE_TXCTETIME_MASK ((uint16_t)0x0000001F) +#define EM_BLE_TXCTETIME_LSB 0 +#define EM_BLE_TXCTETIME_WIDTH ((uint16_t)0x00000005) + +#define EM_BLE_TXCTETYPE_RST 0x0 +#define EM_BLE_TXCTERFU_RST 0x0 +#define EM_BLE_TXCTETIME_RST 0x0 + +__INLINE void em_ble_txphcte_pack(int elt_idx, uint8_t txctetype, uint8_t txcterfu, uint8_t txctetime) +{ + ASSERT_ERR((((uint16_t)txctetype << 6) & ~((uint16_t)0x000000C0)) == 0); + ASSERT_ERR((((uint16_t)txcterfu << 5) & ~((uint16_t)0x00000020)) == 0); + ASSERT_ERR((((uint16_t)txctetime << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_BLE_WR(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, ((uint16_t)txctetype << 6) | ((uint16_t)txcterfu << 5) | ((uint16_t)txctetime << 0)); +} + +__INLINE void em_ble_txphcte_unpack(int elt_idx, uint8_t* txctetype, uint8_t* txcterfu, uint8_t* txctetime) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + + *txctetype = (localVal & ((uint16_t)0x000000C0)) >> 6; + *txcterfu = (localVal & ((uint16_t)0x00000020)) >> 5; + *txctetime = (localVal & ((uint16_t)0x0000001F)) >> 0; +} + +__INLINE uint8_t em_ble_txphcte_txctetype_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x000000C0)) >> 6); +} + +__INLINE void em_ble_txphcte_txctetype_setf(int elt_idx, uint8_t txctetype) +{ + ASSERT_ERR((((uint16_t)txctetype << 6) & ~((uint16_t)0x000000C0)) == 0); + EM_BLE_WR(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x000000C0)) | ((uint16_t)txctetype << 6)); +} + +__INLINE uint8_t em_ble_txphcte_txcterfu_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x00000020)) >> 5); +} + +__INLINE void em_ble_txphcte_txcterfu_setf(int elt_idx, uint8_t txcterfu) +{ + ASSERT_ERR((((uint16_t)txcterfu << 5) & ~((uint16_t)0x00000020)) == 0); + EM_BLE_WR(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x00000020)) | ((uint16_t)txcterfu << 5)); +} + +__INLINE uint8_t em_ble_txphcte_txctetime_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE); + return ((localVal & ((uint16_t)0x0000001F)) >> 0); +} + +__INLINE void em_ble_txphcte_txctetime_setf(int elt_idx, uint8_t txctetime) +{ + ASSERT_ERR((((uint16_t)txctetime << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_BLE_WR(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE, (EM_BLE_RD(EM_BLE_TXPHCTE_ADDR + elt_idx * REG_EM_BLE_TX_DESC_SIZE) & ~((uint16_t)0x0000001F)) | ((uint16_t)txctetime << 0)); +} + + +#endif // _REG_EM_BLE_TX_DESC_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_wpal.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_wpal.h new file mode 100644 index 0000000..ce749f6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_ble_wpal.h @@ -0,0 +1,215 @@ +#ifndef _REG_EM_BLE_WPAL_H_ +#define _REG_EM_BLE_WPAL_H_ + +#include +#include "_reg_em_ble_wpal.h" +#include "compiler.h" +#include "arch.h" +#include "em_map.h" +#include "reg_access.h" + +#define REG_EM_BLE_WPAL_COUNT 6 + +#define REG_EM_BLE_WPAL_DECODING_MASK 0x0000000F + +#define REG_EM_BLE_WPAL_ADDR_GET(idx) (EM_BLE_WPAL_OFFSET + (idx) * REG_EM_BLE_WPAL_SIZE) + +/** + * @brief LIST_INFO register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15          ENTRY_VALID   0
+ *     14               IDTYPE   0
+ *     01                IN_WL   0
+ *     00           IN_PERADVL   0
+ * 
+ */ +#define EM_BLE_LIST_INFO_ADDR (EXCHANGE_MEM_BASE + EM_BLE_WPAL_OFFSET) +#define EM_BLE_LIST_INFO_INDEX 0x00000000 +#define EM_BLE_LIST_INFO_RESET 0x00000000 + +__INLINE uint16_t em_ble_list_info_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE); +} + +__INLINE void em_ble_list_info_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE, value); +} + +// field definitions +#define EM_BLE_ENTRY_VALID_BIT ((uint16_t)0x00008000) +#define EM_BLE_ENTRY_VALID_POS 15 +#define EM_BLE_IDTYPE_BIT ((uint16_t)0x00004000) +#define EM_BLE_IDTYPE_POS 14 +#define EM_BLE_IN_WL_BIT ((uint16_t)0x00000002) +#define EM_BLE_IN_WL_POS 1 +#define EM_BLE_IN_PERADVL_BIT ((uint16_t)0x00000001) +#define EM_BLE_IN_PERADVL_POS 0 + +#define EM_BLE_ENTRY_VALID_RST 0x0 +#define EM_BLE_IDTYPE_RST 0x0 +#define EM_BLE_IN_WL_RST 0x0 +#define EM_BLE_IN_PERADVL_RST 0x0 + +__INLINE void em_ble_list_info_pack(int elt_idx, uint8_t entryvalid, uint8_t idtype, uint8_t inwl, uint8_t inperadvl) +{ + ASSERT_ERR((((uint16_t)entryvalid << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)idtype << 14) & ~((uint16_t)0x00004000)) == 0); + ASSERT_ERR((((uint16_t)inwl << 1) & ~((uint16_t)0x00000002)) == 0); + ASSERT_ERR((((uint16_t)inperadvl << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE, ((uint16_t)entryvalid << 15) | ((uint16_t)idtype << 14) | ((uint16_t)inwl << 1) | ((uint16_t)inperadvl << 0)); +} + +__INLINE void em_ble_list_info_unpack(int elt_idx, uint8_t* entryvalid, uint8_t* idtype, uint8_t* inwl, uint8_t* inperadvl) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE); + + *entryvalid = (localVal & ((uint16_t)0x00008000)) >> 15; + *idtype = (localVal & ((uint16_t)0x00004000)) >> 14; + *inwl = (localVal & ((uint16_t)0x00000002)) >> 1; + *inperadvl = (localVal & ((uint16_t)0x00000001)) >> 0; +} + +__INLINE uint8_t em_ble_list_info_entry_valid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_ble_list_info_entry_valid_setf(int elt_idx, uint8_t entryvalid) +{ + ASSERT_ERR((((uint16_t)entryvalid << 15) & ~((uint16_t)0x00008000)) == 0); + EM_BLE_WR(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE, (EM_BLE_RD(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)entryvalid << 15)); +} + +__INLINE uint8_t em_ble_list_info_idtype_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE); + return ((localVal & ((uint16_t)0x00004000)) >> 14); +} + +__INLINE void em_ble_list_info_idtype_setf(int elt_idx, uint8_t idtype) +{ + ASSERT_ERR((((uint16_t)idtype << 14) & ~((uint16_t)0x00004000)) == 0); + EM_BLE_WR(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE, (EM_BLE_RD(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE) & ~((uint16_t)0x00004000)) | ((uint16_t)idtype << 14)); +} + +__INLINE uint8_t em_ble_list_info_in_wl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE); + return ((localVal & ((uint16_t)0x00000002)) >> 1); +} + +__INLINE void em_ble_list_info_in_wl_setf(int elt_idx, uint8_t inwl) +{ + ASSERT_ERR((((uint16_t)inwl << 1) & ~((uint16_t)0x00000002)) == 0); + EM_BLE_WR(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE, (EM_BLE_RD(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE) & ~((uint16_t)0x00000002)) | ((uint16_t)inwl << 1)); +} + +__INLINE uint8_t em_ble_list_info_in_peradvl_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE); + return ((localVal & ((uint16_t)0x00000001)) >> 0); +} + +__INLINE void em_ble_list_info_in_peradvl_setf(int elt_idx, uint8_t inperadvl) +{ + ASSERT_ERR((((uint16_t)inperadvl << 0) & ~((uint16_t)0x00000001)) == 0); + EM_BLE_WR(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE, (EM_BLE_RD(EM_BLE_LIST_INFO_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE) & ~((uint16_t)0x00000001)) | ((uint16_t)inperadvl << 0)); +} + +/** + * @brief LIST_BDADDR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00              LBDADDR   0x0
+ * 
+ */ +#define EM_BLE_LIST_BDADDR_ADDR (EXCHANGE_MEM_BASE+0x02 + EM_BLE_WPAL_OFFSET) +#define EM_BLE_LIST_BDADDR_INDEX 0x00000001 +#define EM_BLE_LIST_BDADDR_RESET 0x00000000 +#define EM_BLE_LIST_BDADDR_COUNT 3 + +__INLINE uint16_t em_ble_list_bdaddr_get(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + return EM_BLE_RD(EM_BLE_LIST_BDADDR_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE + reg_idx * 2); +} + +__INLINE void em_ble_list_bdaddr_set(int elt_idx, int reg_idx, uint16_t value) +{ + ASSERT_ERR(reg_idx <= 2); + EM_BLE_WR(EM_BLE_LIST_BDADDR_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE + reg_idx * 2, value); +} + +// field definitions +#define EM_BLE_LBDADDR_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_LBDADDR_LSB 0 +#define EM_BLE_LBDADDR_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_LBDADDR_RST 0x0 + +__INLINE uint16_t em_ble_list_bdaddr_lbdaddr_getf(int elt_idx, int reg_idx) +{ + ASSERT_ERR(reg_idx <= 2); + uint16_t localVal = EM_BLE_RD(EM_BLE_LIST_BDADDR_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE + reg_idx * 2); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_list_bdaddr_lbdaddr_setf(int elt_idx, int reg_idx, uint16_t lbdaddr) +{ + ASSERT_ERR(reg_idx <= 2); + ASSERT_ERR((((uint16_t)lbdaddr << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_LIST_BDADDR_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE + reg_idx * 2, (uint16_t)lbdaddr << 0); +} + +/** + * @brief LIST_SID register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00                 LSID   0x0
+ * 
+ */ +#define EM_BLE_LIST_SID_ADDR (EXCHANGE_MEM_BASE+0x08 + EM_BLE_WPAL_OFFSET) +#define EM_BLE_LIST_SID_INDEX 0x00000004 +#define EM_BLE_LIST_SID_RESET 0x00000000 + +__INLINE uint16_t em_ble_list_sid_get(int elt_idx) +{ + return EM_BLE_RD(EM_BLE_LIST_SID_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE); +} + +__INLINE void em_ble_list_sid_set(int elt_idx, uint16_t value) +{ + EM_BLE_WR(EM_BLE_LIST_SID_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE, value); +} + +// field definitions +#define EM_BLE_LSID_MASK ((uint16_t)0x0000FFFF) +#define EM_BLE_LSID_LSB 0 +#define EM_BLE_LSID_WIDTH ((uint16_t)0x00000010) + +#define EM_BLE_LSID_RST 0x0 + +__INLINE uint16_t em_ble_list_sid_lsid_getf(int elt_idx) +{ + uint16_t localVal = EM_BLE_RD(EM_BLE_LIST_SID_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_ble_list_sid_lsid_setf(int elt_idx, uint16_t lsid) +{ + ASSERT_ERR((((uint16_t)lsid << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_BLE_WR(EM_BLE_LIST_SID_ADDR + elt_idx * REG_EM_BLE_WPAL_SIZE, (uint16_t)lsid << 0); +} + + +#endif // _REG_EM_BLE_WPAL_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_et.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_et.h new file mode 100644 index 0000000..45c2d51 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_em_et.h @@ -0,0 +1,751 @@ +#ifndef _REG_EM_ET_H_ +#define _REG_EM_ET_H_ + +#include +#include "_reg_em_et.h" +#include "compiler.h" +#include "arch.h" +#include "em_map.h" +#include "reg_access.h" + +#define REG_EM_ET_COUNT 8 + +#define REG_EM_ET_DECODING_MASK 0x0000000F + +#define REG_EM_ET_ADDR_GET(idx) (EM_ET_OFFSET + (idx) * REG_EM_ET_SIZE) + +/** + * @brief BT_EXTAB register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:11            SCH_PRIO1   0x0
+ *     10                  SPA   0
+ *     09                  CSB   0
+ *     08                SNIFF   0
+ *     07                 RSVD   0
+ *     06                 eSCO   0
+ *  05:03               STATUS   0x0
+ *  02:00                 MODE   0x0
+ * 
+ */ +#define EM_BT_EXTAB_ADDR (EXCHANGE_MEM_BASE + EM_ET_OFFSET) +#define EM_BT_EXTAB_INDEX 0x00000000 +#define EM_BT_EXTAB_RESET 0x00000000 + +__INLINE uint16_t em_bt_extab_get(int elt_idx) +{ + return EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); +} + +__INLINE void em_bt_extab_set(int elt_idx, uint16_t value) +{ + EM_WR(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, value); +} + +// field definitions +#define EM_SCH_PRIO1_MASK ((uint16_t)0x0000F800) +#define EM_SCH_PRIO1_LSB 11 +#define EM_SCH_PRIO1_WIDTH ((uint16_t)0x00000005) +#define EM_SPA_BIT ((uint16_t)0x00000400) +#define EM_SPA_POS 10 +#define EM_CSB_BIT ((uint16_t)0x00000200) +#define EM_CSB_POS 9 +#define EM_SNIFF_BIT ((uint16_t)0x00000100) +#define EM_SNIFF_POS 8 +#define EM_RSVD_BIT ((uint16_t)0x00000080) +#define EM_RSVD_POS 7 +#define EM_E_SCO_BIT ((uint16_t)0x00000040) +#define EM_E_SCO_POS 6 +#define EM_STATUS_MASK ((uint16_t)0x00000038) +#define EM_STATUS_LSB 3 +#define EM_STATUS_WIDTH ((uint16_t)0x00000003) +#define EM_MODE_MASK ((uint16_t)0x00000007) +#define EM_MODE_LSB 0 +#define EM_MODE_WIDTH ((uint16_t)0x00000003) + +#define EM_SCH_PRIO1_RST 0x0 +#define EM_SPA_RST 0x0 +#define EM_CSB_RST 0x0 +#define EM_SNIFF_RST 0x0 +#define EM_RSVD_RST 0x0 +#define EM_E_SCO_RST 0x0 +#define EM_STATUS_RST 0x0 +#define EM_MODE_RST 0x0 + +__INLINE void em_bt_extab_pack(int elt_idx, uint8_t schprio1, uint8_t spa, uint8_t csb, uint8_t sniff, uint8_t rsvd, uint8_t esco, uint8_t status, uint8_t mode) +{ + ASSERT_ERR((((uint16_t)schprio1 << 11) & ~((uint16_t)0x0000F800)) == 0); + ASSERT_ERR((((uint16_t)spa << 10) & ~((uint16_t)0x00000400)) == 0); + ASSERT_ERR((((uint16_t)csb << 9) & ~((uint16_t)0x00000200)) == 0); + ASSERT_ERR((((uint16_t)sniff << 8) & ~((uint16_t)0x00000100)) == 0); + ASSERT_ERR((((uint16_t)rsvd << 7) & ~((uint16_t)0x00000080)) == 0); + ASSERT_ERR((((uint16_t)esco << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)status << 3) & ~((uint16_t)0x00000038)) == 0); + ASSERT_ERR((((uint16_t)mode << 0) & ~((uint16_t)0x00000007)) == 0); + EM_WR(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, ((uint16_t)schprio1 << 11) | ((uint16_t)spa << 10) | ((uint16_t)csb << 9) | ((uint16_t)sniff << 8) | ((uint16_t)rsvd << 7) | ((uint16_t)esco << 6) | ((uint16_t)status << 3) | ((uint16_t)mode << 0)); +} + +__INLINE void em_bt_extab_unpack(int elt_idx, uint8_t* schprio1, uint8_t* spa, uint8_t* csb, uint8_t* sniff, uint8_t* rsvd, uint8_t* esco, uint8_t* status, uint8_t* mode) +{ + uint16_t localVal = EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + + *schprio1 = (localVal & ((uint16_t)0x0000F800)) >> 11; + *spa = (localVal & ((uint16_t)0x00000400)) >> 10; + *csb = (localVal & ((uint16_t)0x00000200)) >> 9; + *sniff = (localVal & ((uint16_t)0x00000100)) >> 8; + *rsvd = (localVal & ((uint16_t)0x00000080)) >> 7; + *esco = (localVal & ((uint16_t)0x00000040)) >> 6; + *status = (localVal & ((uint16_t)0x00000038)) >> 3; + *mode = (localVal & ((uint16_t)0x00000007)) >> 0; +} + +__INLINE uint8_t em_bt_extab_sch_prio1_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x0000F800)) >> 11); +} + +__INLINE void em_bt_extab_sch_prio1_setf(int elt_idx, uint8_t schprio1) +{ + ASSERT_ERR((((uint16_t)schprio1 << 11) & ~((uint16_t)0x0000F800)) == 0); + EM_WR(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x0000F800)) | ((uint16_t)schprio1 << 11)); +} + +__INLINE uint8_t em_bt_extab_spa_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000400)) >> 10); +} + +__INLINE void em_bt_extab_spa_setf(int elt_idx, uint8_t spa) +{ + ASSERT_ERR((((uint16_t)spa << 10) & ~((uint16_t)0x00000400)) == 0); + EM_WR(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000400)) | ((uint16_t)spa << 10)); +} + +__INLINE uint8_t em_bt_extab_csb_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000200)) >> 9); +} + +__INLINE void em_bt_extab_csb_setf(int elt_idx, uint8_t csb) +{ + ASSERT_ERR((((uint16_t)csb << 9) & ~((uint16_t)0x00000200)) == 0); + EM_WR(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000200)) | ((uint16_t)csb << 9)); +} + +__INLINE uint8_t em_bt_extab_sniff_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000100)) >> 8); +} + +__INLINE void em_bt_extab_sniff_setf(int elt_idx, uint8_t sniff) +{ + ASSERT_ERR((((uint16_t)sniff << 8) & ~((uint16_t)0x00000100)) == 0); + EM_WR(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000100)) | ((uint16_t)sniff << 8)); +} + +__INLINE uint8_t em_bt_extab_rsvd_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000080)) >> 7); +} + +__INLINE void em_bt_extab_rsvd_setf(int elt_idx, uint8_t rsvd) +{ + ASSERT_ERR((((uint16_t)rsvd << 7) & ~((uint16_t)0x00000080)) == 0); + EM_WR(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000080)) | ((uint16_t)rsvd << 7)); +} + +__INLINE uint8_t em_bt_extab_e_sco_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_bt_extab_e_sco_setf(int elt_idx, uint8_t esco) +{ + ASSERT_ERR((((uint16_t)esco << 6) & ~((uint16_t)0x00000040)) == 0); + EM_WR(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)esco << 6)); +} + +__INLINE uint8_t em_bt_extab_status_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000038)) >> 3); +} + +__INLINE void em_bt_extab_status_setf(int elt_idx, uint8_t status) +{ + ASSERT_ERR((((uint16_t)status << 3) & ~((uint16_t)0x00000038)) == 0); + EM_WR(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000038)) | ((uint16_t)status << 3)); +} + +__INLINE uint8_t em_bt_extab_mode_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000007)) >> 0); +} + +__INLINE void em_bt_extab_mode_setf(int elt_idx, uint8_t mode) +{ + ASSERT_ERR((((uint16_t)mode << 0) & ~((uint16_t)0x00000007)) == 0); + EM_WR(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_BT_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000007)) | ((uint16_t)mode << 0)); +} + +/** + * @brief LE_EXTAB register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:11            SCH_PRIO1   0x0
+ *     10                  SPA   0
+ *     08               AE_NPS   0
+ *     07                 RSVD   0
+ *     06                  ISO   0
+ *  05:03               STATUS   0x0
+ *  02:00                 MODE   0x0
+ * 
+ */ +#define EM_LE_EXTAB_ADDR (EXCHANGE_MEM_BASE + EM_ET_OFFSET) +#define EM_LE_EXTAB_INDEX 0x00000000 +#define EM_LE_EXTAB_RESET 0x00000000 + +__INLINE uint16_t em_le_extab_get(int elt_idx) +{ + return EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); +} + +__INLINE void em_le_extab_set(int elt_idx, uint16_t value) +{ + EM_WR(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, value); +} + +// field definitions +#define EM_SCH_PRIO1_MASK ((uint16_t)0x0000F800) +#define EM_SCH_PRIO1_LSB 11 +#define EM_SCH_PRIO1_WIDTH ((uint16_t)0x00000005) +#define EM_SPA_BIT ((uint16_t)0x00000400) +#define EM_SPA_POS 10 +#define EM_AE_NPS_BIT ((uint16_t)0x00000100) +#define EM_AE_NPS_POS 8 +#define EM_RSVD_BIT ((uint16_t)0x00000080) +#define EM_RSVD_POS 7 +#define EM_ISO_BIT ((uint16_t)0x00000040) +#define EM_ISO_POS 6 +#define EM_STATUS_MASK ((uint16_t)0x00000038) +#define EM_STATUS_LSB 3 +#define EM_STATUS_WIDTH ((uint16_t)0x00000003) +#define EM_MODE_MASK ((uint16_t)0x00000007) +#define EM_MODE_LSB 0 +#define EM_MODE_WIDTH ((uint16_t)0x00000003) + +#define EM_SCH_PRIO1_RST 0x0 +#define EM_SPA_RST 0x0 +#define EM_AE_NPS_RST 0x0 +#define EM_RSVD_RST 0x0 +#define EM_ISO_RST 0x0 +#define EM_STATUS_RST 0x0 +#define EM_MODE_RST 0x0 + +__INLINE void em_le_extab_pack(int elt_idx, uint8_t schprio1, uint8_t spa, uint8_t aenps, uint8_t rsvd, uint8_t iso, uint8_t status, uint8_t mode) +{ + ASSERT_ERR((((uint16_t)schprio1 << 11) & ~((uint16_t)0x0000F800)) == 0); + ASSERT_ERR((((uint16_t)spa << 10) & ~((uint16_t)0x00000400)) == 0); + ASSERT_ERR((((uint16_t)aenps << 8) & ~((uint16_t)0x00000100)) == 0); + ASSERT_ERR((((uint16_t)rsvd << 7) & ~((uint16_t)0x00000080)) == 0); + ASSERT_ERR((((uint16_t)iso << 6) & ~((uint16_t)0x00000040)) == 0); + ASSERT_ERR((((uint16_t)status << 3) & ~((uint16_t)0x00000038)) == 0); + ASSERT_ERR((((uint16_t)mode << 0) & ~((uint16_t)0x00000007)) == 0); + EM_WR(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, ((uint16_t)schprio1 << 11) | ((uint16_t)spa << 10) | ((uint16_t)aenps << 8) | ((uint16_t)rsvd << 7) | ((uint16_t)iso << 6) | ((uint16_t)status << 3) | ((uint16_t)mode << 0)); +} + +__INLINE void em_le_extab_unpack(int elt_idx, uint8_t* schprio1, uint8_t* spa, uint8_t* aenps, uint8_t* rsvd, uint8_t* iso, uint8_t* status, uint8_t* mode) +{ + uint16_t localVal = EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + + *schprio1 = (localVal & ((uint16_t)0x0000F800)) >> 11; + *spa = (localVal & ((uint16_t)0x00000400)) >> 10; + *aenps = (localVal & ((uint16_t)0x00000100)) >> 8; + *rsvd = (localVal & ((uint16_t)0x00000080)) >> 7; + *iso = (localVal & ((uint16_t)0x00000040)) >> 6; + *status = (localVal & ((uint16_t)0x00000038)) >> 3; + *mode = (localVal & ((uint16_t)0x00000007)) >> 0; +} + +__INLINE uint8_t em_le_extab_sch_prio1_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x0000F800)) >> 11); +} + +__INLINE void em_le_extab_sch_prio1_setf(int elt_idx, uint8_t schprio1) +{ + ASSERT_ERR((((uint16_t)schprio1 << 11) & ~((uint16_t)0x0000F800)) == 0); + EM_WR(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x0000F800)) | ((uint16_t)schprio1 << 11)); +} + +__INLINE uint8_t em_le_extab_spa_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000400)) >> 10); +} + +__INLINE void em_le_extab_spa_setf(int elt_idx, uint8_t spa) +{ + ASSERT_ERR((((uint16_t)spa << 10) & ~((uint16_t)0x00000400)) == 0); + EM_WR(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000400)) | ((uint16_t)spa << 10)); +} + +__INLINE uint8_t em_le_extab_ae_nps_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000100)) >> 8); +} + +__INLINE void em_le_extab_ae_nps_setf(int elt_idx, uint8_t aenps) +{ + ASSERT_ERR((((uint16_t)aenps << 8) & ~((uint16_t)0x00000100)) == 0); + EM_WR(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000100)) | ((uint16_t)aenps << 8)); +} + +__INLINE uint8_t em_le_extab_rsvd_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000080)) >> 7); +} + +__INLINE void em_le_extab_rsvd_setf(int elt_idx, uint8_t rsvd) +{ + ASSERT_ERR((((uint16_t)rsvd << 7) & ~((uint16_t)0x00000080)) == 0); + EM_WR(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000080)) | ((uint16_t)rsvd << 7)); +} + +__INLINE uint8_t em_le_extab_iso_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000040)) >> 6); +} + +__INLINE void em_le_extab_iso_setf(int elt_idx, uint8_t iso) +{ + ASSERT_ERR((((uint16_t)iso << 6) & ~((uint16_t)0x00000040)) == 0); + EM_WR(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000040)) | ((uint16_t)iso << 6)); +} + +__INLINE uint8_t em_le_extab_status_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000038)) >> 3); +} + +__INLINE void em_le_extab_status_setf(int elt_idx, uint8_t status) +{ + ASSERT_ERR((((uint16_t)status << 3) & ~((uint16_t)0x00000038)) == 0); + EM_WR(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000038)) | ((uint16_t)status << 3)); +} + +__INLINE uint8_t em_le_extab_mode_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000007)) >> 0); +} + +__INLINE void em_le_extab_mode_setf(int elt_idx, uint8_t mode) +{ + ASSERT_ERR((((uint16_t)mode << 0) & ~((uint16_t)0x00000007)) == 0); + EM_WR(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_LE_EXTAB_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000007)) | ((uint16_t)mode << 0)); +} + +/** + * @brief RAWSTP0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  15:00              RAWSTP0   0x0
+ * 
+ */ +#define EM_RAWSTP0_ADDR (EXCHANGE_MEM_BASE+0x02 + EM_ET_OFFSET) +#define EM_RAWSTP0_INDEX 0x00000001 +#define EM_RAWSTP0_RESET 0x00000000 + +__INLINE uint16_t em_rawstp0_get(int elt_idx) +{ + return EM_RD(EM_RAWSTP0_ADDR + elt_idx * REG_EM_ET_SIZE); +} + +__INLINE void em_rawstp0_set(int elt_idx, uint16_t value) +{ + EM_WR(EM_RAWSTP0_ADDR + elt_idx * REG_EM_ET_SIZE, value); +} + +// field definitions +#define EM_RAWSTP0_MASK ((uint16_t)0x0000FFFF) +#define EM_RAWSTP0_LSB 0 +#define EM_RAWSTP0_WIDTH ((uint16_t)0x00000010) + +#define EM_RAWSTP0_RST 0x0 + +__INLINE uint16_t em_rawstp0_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_RAWSTP0_ADDR + elt_idx * REG_EM_ET_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x0000FFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_rawstp0_setf(int elt_idx, uint16_t rawstp0) +{ + ASSERT_ERR((((uint16_t)rawstp0 << 0) & ~((uint16_t)0x0000FFFF)) == 0); + EM_WR(EM_RAWSTP0_ADDR + elt_idx * REG_EM_ET_SIZE, (uint16_t)rawstp0 << 0); +} + +/** + * @brief RAWSTP1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  11:00              RAWSTP1   0x0
+ * 
+ */ +#define EM_RAWSTP1_ADDR (EXCHANGE_MEM_BASE+0x04 + EM_ET_OFFSET) +#define EM_RAWSTP1_INDEX 0x00000002 +#define EM_RAWSTP1_RESET 0x00000000 + +__INLINE uint16_t em_rawstp1_get(int elt_idx) +{ + return EM_RD(EM_RAWSTP1_ADDR + elt_idx * REG_EM_ET_SIZE); +} + +__INLINE void em_rawstp1_set(int elt_idx, uint16_t value) +{ + EM_WR(EM_RAWSTP1_ADDR + elt_idx * REG_EM_ET_SIZE, value); +} + +// field definitions +#define EM_RAWSTP1_MASK ((uint16_t)0x00000FFF) +#define EM_RAWSTP1_LSB 0 +#define EM_RAWSTP1_WIDTH ((uint16_t)0x0000000C) + +#define EM_RAWSTP1_RST 0x0 + +__INLINE uint16_t em_rawstp1_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_RAWSTP1_ADDR + elt_idx * REG_EM_ET_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00000FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_rawstp1_setf(int elt_idx, uint16_t rawstp1) +{ + ASSERT_ERR((((uint16_t)rawstp1 << 0) & ~((uint16_t)0x00000FFF)) == 0); + EM_WR(EM_RAWSTP1_ADDR + elt_idx * REG_EM_ET_SIZE, (uint16_t)rawstp1 << 0); +} + +/** + * @brief FINESTP register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00              FINESTP   0x0
+ * 
+ */ +#define EM_FINESTP_ADDR (EXCHANGE_MEM_BASE+0x06 + EM_ET_OFFSET) +#define EM_FINESTP_INDEX 0x00000003 +#define EM_FINESTP_RESET 0x00000000 + +__INLINE uint16_t em_finestp_get(int elt_idx) +{ + return EM_RD(EM_FINESTP_ADDR + elt_idx * REG_EM_ET_SIZE); +} + +__INLINE void em_finestp_set(int elt_idx, uint16_t value) +{ + EM_WR(EM_FINESTP_ADDR + elt_idx * REG_EM_ET_SIZE, value); +} + +// field definitions +#define EM_FINESTP_MASK ((uint16_t)0x000003FF) +#define EM_FINESTP_LSB 0 +#define EM_FINESTP_WIDTH ((uint16_t)0x0000000A) + +#define EM_FINESTP_RST 0x0 + +__INLINE uint16_t em_finestp_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_FINESTP_ADDR + elt_idx * REG_EM_ET_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_finestp_setf(int elt_idx, uint16_t finestp) +{ + ASSERT_ERR((((uint16_t)finestp << 0) & ~((uint16_t)0x000003FF)) == 0); + EM_WR(EM_FINESTP_ADDR + elt_idx * REG_EM_ET_SIZE, (uint16_t)finestp << 0); +} + +/** + * @brief CSPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  14:00                CSPTR   0x0
+ * 
+ */ +#define EM_CSPTR_ADDR (EXCHANGE_MEM_BASE+0x08 + EM_ET_OFFSET) +#define EM_CSPTR_INDEX 0x00000004 +#define EM_CSPTR_RESET 0x00000000 + +__INLINE uint16_t em_csptr_get(int elt_idx) +{ + return EM_RD(EM_CSPTR_ADDR + elt_idx * REG_EM_ET_SIZE); +} + +__INLINE void em_csptr_set(int elt_idx, uint16_t value) +{ + EM_WR(EM_CSPTR_ADDR + elt_idx * REG_EM_ET_SIZE, value); +} + +// field definitions +#define EM_CSPTR_MASK ((uint16_t)0x00007FFF) +#define EM_CSPTR_LSB 0 +#define EM_CSPTR_WIDTH ((uint16_t)0x0000000F) + +#define EM_CSPTR_RST 0x0 + +__INLINE uint16_t em_csptr_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_CSPTR_ADDR + elt_idx * REG_EM_ET_SIZE); + ASSERT_ERR((localVal & ~((uint16_t)0x00007FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void em_csptr_setf(int elt_idx, uint16_t csptr) +{ + ASSERT_ERR((((uint16_t)csptr << 0) & ~((uint16_t)0x00007FFF)) == 0); + EM_WR(EM_CSPTR_ADDR + elt_idx * REG_EM_ET_SIZE, (uint16_t)csptr << 0); +} + +/** + * @brief PRIOBW register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15          PRIOBW_UNIT   0
+ *  14:00               PRIOBW   0x0
+ * 
+ */ +#define EM_PRIOBW_ADDR (EXCHANGE_MEM_BASE+0x0A + EM_ET_OFFSET) +#define EM_PRIOBW_INDEX 0x00000005 +#define EM_PRIOBW_RESET 0x00000000 + +__INLINE uint16_t em_priobw_get(int elt_idx) +{ + return EM_RD(EM_PRIOBW_ADDR + elt_idx * REG_EM_ET_SIZE); +} + +__INLINE void em_priobw_set(int elt_idx, uint16_t value) +{ + EM_WR(EM_PRIOBW_ADDR + elt_idx * REG_EM_ET_SIZE, value); +} + +// field definitions +#define EM_PRIOBW_UNIT_BIT ((uint16_t)0x00008000) +#define EM_PRIOBW_UNIT_POS 15 +#define EM_PRIOBW_MASK ((uint16_t)0x00007FFF) +#define EM_PRIOBW_LSB 0 +#define EM_PRIOBW_WIDTH ((uint16_t)0x0000000F) + +#define EM_PRIOBW_UNIT_RST 0x0 +#define EM_PRIOBW_RST 0x0 + +__INLINE void em_priobw_pack(int elt_idx, uint8_t priobwunit, uint16_t priobw) +{ + ASSERT_ERR((((uint16_t)priobwunit << 15) & ~((uint16_t)0x00008000)) == 0); + ASSERT_ERR((((uint16_t)priobw << 0) & ~((uint16_t)0x00007FFF)) == 0); + EM_WR(EM_PRIOBW_ADDR + elt_idx * REG_EM_ET_SIZE, ((uint16_t)priobwunit << 15) | ((uint16_t)priobw << 0)); +} + +__INLINE void em_priobw_unpack(int elt_idx, uint8_t* priobwunit, uint16_t* priobw) +{ + uint16_t localVal = EM_RD(EM_PRIOBW_ADDR + elt_idx * REG_EM_ET_SIZE); + + *priobwunit = (localVal & ((uint16_t)0x00008000)) >> 15; + *priobw = (localVal & ((uint16_t)0x00007FFF)) >> 0; +} + +__INLINE uint8_t em_priobw_priobw_unit_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_PRIOBW_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00008000)) >> 15); +} + +__INLINE void em_priobw_priobw_unit_setf(int elt_idx, uint8_t priobwunit) +{ + ASSERT_ERR((((uint16_t)priobwunit << 15) & ~((uint16_t)0x00008000)) == 0); + EM_WR(EM_PRIOBW_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_PRIOBW_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00008000)) | ((uint16_t)priobwunit << 15)); +} + +__INLINE uint16_t em_priobw_priobw_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_PRIOBW_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00007FFF)) >> 0); +} + +__INLINE void em_priobw_priobw_setf(int elt_idx, uint16_t priobw) +{ + ASSERT_ERR((((uint16_t)priobw << 0) & ~((uint16_t)0x00007FFF)) == 0); + EM_WR(EM_PRIOBW_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_PRIOBW_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00007FFF)) | ((uint16_t)priobw << 0)); +} + +/** + * @brief PRIOLVL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  12:08            SCH_PRIO3   0x0
+ *  04:00            SCH_PRIO2   0x0
+ * 
+ */ +#define EM_PRIOLVL_ADDR (EXCHANGE_MEM_BASE+0x0C + EM_ET_OFFSET) +#define EM_PRIOLVL_INDEX 0x00000006 +#define EM_PRIOLVL_RESET 0x00000000 + +__INLINE uint16_t em_priolvl_get(int elt_idx) +{ + return EM_RD(EM_PRIOLVL_ADDR + elt_idx * REG_EM_ET_SIZE); +} + +__INLINE void em_priolvl_set(int elt_idx, uint16_t value) +{ + EM_WR(EM_PRIOLVL_ADDR + elt_idx * REG_EM_ET_SIZE, value); +} + +// field definitions +#define EM_SCH_PRIO3_MASK ((uint16_t)0x00001F00) +#define EM_SCH_PRIO3_LSB 8 +#define EM_SCH_PRIO3_WIDTH ((uint16_t)0x00000005) +#define EM_SCH_PRIO2_MASK ((uint16_t)0x0000001F) +#define EM_SCH_PRIO2_LSB 0 +#define EM_SCH_PRIO2_WIDTH ((uint16_t)0x00000005) + +#define EM_SCH_PRIO3_RST 0x0 +#define EM_SCH_PRIO2_RST 0x0 + +__INLINE void em_priolvl_pack(int elt_idx, uint8_t schprio3, uint8_t schprio2) +{ + ASSERT_ERR((((uint16_t)schprio3 << 8) & ~((uint16_t)0x00001F00)) == 0); + ASSERT_ERR((((uint16_t)schprio2 << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_WR(EM_PRIOLVL_ADDR + elt_idx * REG_EM_ET_SIZE, ((uint16_t)schprio3 << 8) | ((uint16_t)schprio2 << 0)); +} + +__INLINE void em_priolvl_unpack(int elt_idx, uint8_t* schprio3, uint8_t* schprio2) +{ + uint16_t localVal = EM_RD(EM_PRIOLVL_ADDR + elt_idx * REG_EM_ET_SIZE); + + *schprio3 = (localVal & ((uint16_t)0x00001F00)) >> 8; + *schprio2 = (localVal & ((uint16_t)0x0000001F)) >> 0; +} + +__INLINE uint8_t em_priolvl_sch_prio3_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_PRIOLVL_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00001F00)) >> 8); +} + +__INLINE void em_priolvl_sch_prio3_setf(int elt_idx, uint8_t schprio3) +{ + ASSERT_ERR((((uint16_t)schprio3 << 8) & ~((uint16_t)0x00001F00)) == 0); + EM_WR(EM_PRIOLVL_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_PRIOLVL_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00001F00)) | ((uint16_t)schprio3 << 8)); +} + +__INLINE uint8_t em_priolvl_sch_prio2_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_PRIOLVL_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x0000001F)) >> 0); +} + +__INLINE void em_priolvl_sch_prio2_setf(int elt_idx, uint8_t schprio2) +{ + ASSERT_ERR((((uint16_t)schprio2 << 0) & ~((uint16_t)0x0000001F)) == 0); + EM_WR(EM_PRIOLVL_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_PRIOLVL_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x0000001F)) | ((uint16_t)schprio2 << 0)); +} + +/** + * @brief PTI_VXCHAN register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  12:08             PTI_PRIO   0x0
+ *  01:00               VXCHAN   0x0
+ * 
+ */ +#define EM_PTI_VXCHAN_ADDR (EXCHANGE_MEM_BASE+0x0E + EM_ET_OFFSET) +#define EM_PTI_VXCHAN_INDEX 0x00000007 +#define EM_PTI_VXCHAN_RESET 0x00000000 + +__INLINE uint16_t em_pti_vxchan_get(int elt_idx) +{ + return EM_RD(EM_PTI_VXCHAN_ADDR + elt_idx * REG_EM_ET_SIZE); +} + +__INLINE void em_pti_vxchan_set(int elt_idx, uint16_t value) +{ + EM_WR(EM_PTI_VXCHAN_ADDR + elt_idx * REG_EM_ET_SIZE, value); +} + +// field definitions +#define EM_PTI_PRIO_MASK ((uint16_t)0x00001F00) +#define EM_PTI_PRIO_LSB 8 +#define EM_PTI_PRIO_WIDTH ((uint16_t)0x00000005) +#define EM_VXCHAN_MASK ((uint16_t)0x00000003) +#define EM_VXCHAN_LSB 0 +#define EM_VXCHAN_WIDTH ((uint16_t)0x00000002) + +#define EM_PTI_PRIO_RST 0x0 +#define EM_VXCHAN_RST 0x0 + +__INLINE void em_pti_vxchan_pack(int elt_idx, uint8_t ptiprio, uint8_t vxchan) +{ + ASSERT_ERR((((uint16_t)ptiprio << 8) & ~((uint16_t)0x00001F00)) == 0); + ASSERT_ERR((((uint16_t)vxchan << 0) & ~((uint16_t)0x00000003)) == 0); + EM_WR(EM_PTI_VXCHAN_ADDR + elt_idx * REG_EM_ET_SIZE, ((uint16_t)ptiprio << 8) | ((uint16_t)vxchan << 0)); +} + +__INLINE void em_pti_vxchan_unpack(int elt_idx, uint8_t* ptiprio, uint8_t* vxchan) +{ + uint16_t localVal = EM_RD(EM_PTI_VXCHAN_ADDR + elt_idx * REG_EM_ET_SIZE); + + *ptiprio = (localVal & ((uint16_t)0x00001F00)) >> 8; + *vxchan = (localVal & ((uint16_t)0x00000003)) >> 0; +} + +__INLINE uint8_t em_pti_vxchan_pti_prio_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_PTI_VXCHAN_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00001F00)) >> 8); +} + +__INLINE void em_pti_vxchan_pti_prio_setf(int elt_idx, uint8_t ptiprio) +{ + ASSERT_ERR((((uint16_t)ptiprio << 8) & ~((uint16_t)0x00001F00)) == 0); + EM_WR(EM_PTI_VXCHAN_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_PTI_VXCHAN_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00001F00)) | ((uint16_t)ptiprio << 8)); +} + +__INLINE uint8_t em_pti_vxchan_vxchan_getf(int elt_idx) +{ + uint16_t localVal = EM_RD(EM_PTI_VXCHAN_ADDR + elt_idx * REG_EM_ET_SIZE); + return ((localVal & ((uint16_t)0x00000003)) >> 0); +} + +__INLINE void em_pti_vxchan_vxchan_setf(int elt_idx, uint8_t vxchan) +{ + ASSERT_ERR((((uint16_t)vxchan << 0) & ~((uint16_t)0x00000003)) == 0); + EM_WR(EM_PTI_VXCHAN_ADDR + elt_idx * REG_EM_ET_SIZE, (EM_RD(EM_PTI_VXCHAN_ADDR + elt_idx * REG_EM_ET_SIZE) & ~((uint16_t)0x00000003)) | ((uint16_t)vxchan << 0)); +} + + +#endif // _REG_EM_ET_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_ipcore.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_ipcore.h new file mode 100644 index 0000000..0c00eed --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/reg_ipcore.h @@ -0,0 +1,3911 @@ +#ifndef _REG_IPCORE_H_ +#define _REG_IPCORE_H_ + +#include +#include "_reg_ipcore.h" +#include "compiler.h" +#include "arch.h" +#include "reg_access.h" + +#define REG_IPCORE_COUNT 98 + +#define REG_IPCORE_DECODING_MASK 0x000001FF + +/** + * @brief RWDMCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31      MASTER_SOFT_RST   0
+ *     30    MASTER_TGSOFT_RST   0
+ *     29         REG_SOFT_RST   0
+ *     28   RADIOCNTL_SOFT_RST   0
+ *     27            SWINT_REQ   0
+ * 
+ */ +#define IP_RWDMCNTL_ADDR BASEBAND_REG_BASE+0 //0x50800000 +#define IP_RWDMCNTL_OFFSET 0x00000000 +#define IP_RWDMCNTL_INDEX 0x00000000 +#define IP_RWDMCNTL_RESET 0x00000000 + +__INLINE uint32_t ip_rwdmcntl_get(void) +{ + return REG_IP_RD(IP_RWDMCNTL_ADDR); +} + +__INLINE void ip_rwdmcntl_set(uint32_t value) +{ + REG_IP_WR(IP_RWDMCNTL_ADDR, value); +} + +// field definitions +#define IP_MASTER_SOFT_RST_BIT ((uint32_t)0x80000000) +#define IP_MASTER_SOFT_RST_POS 31 +#define IP_MASTER_TGSOFT_RST_BIT ((uint32_t)0x40000000) +#define IP_MASTER_TGSOFT_RST_POS 30 +#define IP_REG_SOFT_RST_BIT ((uint32_t)0x20000000) +#define IP_REG_SOFT_RST_POS 29 +#define IP_RADIOCNTL_SOFT_RST_BIT ((uint32_t)0x10000000) +#define IP_RADIOCNTL_SOFT_RST_POS 28 +#define IP_SWINT_REQ_BIT ((uint32_t)0x08000000) +#define IP_SWINT_REQ_POS 27 + +#define IP_MASTER_SOFT_RST_RST 0x0 +#define IP_MASTER_TGSOFT_RST_RST 0x0 +#define IP_REG_SOFT_RST_RST 0x0 +#define IP_RADIOCNTL_SOFT_RST_RST 0x0 +#define IP_SWINT_REQ_RST 0x0 + +__INLINE void ip_rwdmcntl_pack(uint8_t mastersoftrst, uint8_t mastertgsoftrst, uint8_t regsoftrst, uint8_t radiocntlsoftrst, uint8_t swintreq) +{ + ASSERT_ERR((((uint32_t)mastersoftrst << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)mastertgsoftrst << 30) & ~((uint32_t)0x40000000)) == 0); + ASSERT_ERR((((uint32_t)regsoftrst << 29) & ~((uint32_t)0x20000000)) == 0); + ASSERT_ERR((((uint32_t)radiocntlsoftrst << 28) & ~((uint32_t)0x10000000)) == 0); + ASSERT_ERR((((uint32_t)swintreq << 27) & ~((uint32_t)0x08000000)) == 0); + REG_IP_WR(IP_RWDMCNTL_ADDR, ((uint32_t)mastersoftrst << 31) | ((uint32_t)mastertgsoftrst << 30) | ((uint32_t)regsoftrst << 29) | ((uint32_t)radiocntlsoftrst << 28) | ((uint32_t)swintreq << 27)); +} + +__INLINE void ip_rwdmcntl_unpack(uint8_t* mastersoftrst, uint8_t* mastertgsoftrst, uint8_t* regsoftrst, uint8_t* radiocntlsoftrst, uint8_t* swintreq) +{ + uint32_t localVal = REG_IP_RD(IP_RWDMCNTL_ADDR); + + *mastersoftrst = (localVal & ((uint32_t)0x80000000)) >> 31; + *mastertgsoftrst = (localVal & ((uint32_t)0x40000000)) >> 30; + *regsoftrst = (localVal & ((uint32_t)0x20000000)) >> 29; + *radiocntlsoftrst = (localVal & ((uint32_t)0x10000000)) >> 28; + *swintreq = (localVal & ((uint32_t)0x08000000)) >> 27; +} + +__INLINE uint8_t ip_rwdmcntl_master_soft_rst_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RWDMCNTL_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ip_rwdmcntl_master_soft_rst_setf(uint8_t mastersoftrst) +{ + ASSERT_ERR((((uint32_t)mastersoftrst << 31) & ~((uint32_t)0x80000000)) == 0); + REG_IP_WR(IP_RWDMCNTL_ADDR, (REG_IP_RD(IP_RWDMCNTL_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)mastersoftrst << 31)); +} + +__INLINE uint8_t ip_rwdmcntl_master_tgsoft_rst_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RWDMCNTL_ADDR); + return ((localVal & ((uint32_t)0x40000000)) >> 30); +} + +__INLINE void ip_rwdmcntl_master_tgsoft_rst_setf(uint8_t mastertgsoftrst) +{ + ASSERT_ERR((((uint32_t)mastertgsoftrst << 30) & ~((uint32_t)0x40000000)) == 0); + REG_IP_WR(IP_RWDMCNTL_ADDR, (REG_IP_RD(IP_RWDMCNTL_ADDR) & ~((uint32_t)0x40000000)) | ((uint32_t)mastertgsoftrst << 30)); +} + +__INLINE uint8_t ip_rwdmcntl_reg_soft_rst_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RWDMCNTL_ADDR); + return ((localVal & ((uint32_t)0x20000000)) >> 29); +} + +__INLINE void ip_rwdmcntl_reg_soft_rst_setf(uint8_t regsoftrst) +{ + ASSERT_ERR((((uint32_t)regsoftrst << 29) & ~((uint32_t)0x20000000)) == 0); + REG_IP_WR(IP_RWDMCNTL_ADDR, (REG_IP_RD(IP_RWDMCNTL_ADDR) & ~((uint32_t)0x20000000)) | ((uint32_t)regsoftrst << 29)); +} + +__INLINE uint8_t ip_rwdmcntl_radiocntl_soft_rst_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RWDMCNTL_ADDR); + return ((localVal & ((uint32_t)0x10000000)) >> 28); +} + +__INLINE void ip_rwdmcntl_radiocntl_soft_rst_setf(uint8_t radiocntlsoftrst) +{ + ASSERT_ERR((((uint32_t)radiocntlsoftrst << 28) & ~((uint32_t)0x10000000)) == 0); + REG_IP_WR(IP_RWDMCNTL_ADDR, (REG_IP_RD(IP_RWDMCNTL_ADDR) & ~((uint32_t)0x10000000)) | ((uint32_t)radiocntlsoftrst << 28)); +} + +__INLINE uint8_t ip_rwdmcntl_swint_req_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RWDMCNTL_ADDR); + return ((localVal & ((uint32_t)0x08000000)) >> 27); +} + +__INLINE void ip_rwdmcntl_swint_req_setf(uint8_t swintreq) +{ + ASSERT_ERR((((uint32_t)swintreq << 27) & ~((uint32_t)0x08000000)) == 0); + REG_IP_WR(IP_RWDMCNTL_ADDR, (REG_IP_RD(IP_RWDMCNTL_ADDR) & ~((uint32_t)0x08000000)) | ((uint32_t)swintreq << 27)); +} + +/** + * @brief VERSION register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24                  TYP   0xA
+ *  23:16                  REL   0x0
+ *  15:08                  UPG   0x7
+ *  07:00                BUILD   0x0
+ * 
+ */ +#define IP_VERSION_ADDR BASEBAND_REG_BASE +0x4 //0x50800004 +#define IP_VERSION_OFFSET 0x00000004 +#define IP_VERSION_INDEX 0x00000001 +#define IP_VERSION_RESET 0x0A000700 + +__INLINE uint32_t ip_version_get(void) +{ + return REG_IP_RD(IP_VERSION_ADDR); +} + +// field definitions +#define IP_TYP_MASK ((uint32_t)0xFF000000) +#define IP_TYP_LSB 24 +#define IP_TYP_WIDTH ((uint32_t)0x00000008) +#define IP_REL_MASK ((uint32_t)0x00FF0000) +#define IP_REL_LSB 16 +#define IP_REL_WIDTH ((uint32_t)0x00000008) +#define IP_UPG_MASK ((uint32_t)0x0000FF00) +#define IP_UPG_LSB 8 +#define IP_UPG_WIDTH ((uint32_t)0x00000008) +#define IP_BUILD_MASK ((uint32_t)0x000000FF) +#define IP_BUILD_LSB 0 +#define IP_BUILD_WIDTH ((uint32_t)0x00000008) + +#define IP_TYP_RST 0xA +#define IP_REL_RST 0x0 +#define IP_UPG_RST 0x7 +#define IP_BUILD_RST 0x0 + +__INLINE void ip_version_unpack(uint8_t* typ, uint8_t* rel, uint8_t* upg, uint8_t* build) +{ + uint32_t localVal = REG_IP_RD(IP_VERSION_ADDR); + + *typ = (localVal & ((uint32_t)0xFF000000)) >> 24; + *rel = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *upg = (localVal & ((uint32_t)0x0000FF00)) >> 8; + *build = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ip_version_typ_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_VERSION_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE uint8_t ip_version_rel_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_VERSION_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE uint8_t ip_version_upg_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_VERSION_ADDR); + return ((localVal & ((uint32_t)0x0000FF00)) >> 8); +} + +__INLINE uint8_t ip_version_build_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_VERSION_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +/** + * @brief INTCNTL0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     16          ERRORINTMSK   0
+ * 
+ */ +#define IP_INTCNTL0_ADDR BASEBAND_REG_BASE +0xC //0x5080000C +#define IP_INTCNTL0_OFFSET 0x0000000C +#define IP_INTCNTL0_INDEX 0x00000003 +#define IP_INTCNTL0_RESET 0x00000000 + +__INLINE uint32_t ip_intcntl0_get(void) +{ + return REG_IP_RD(IP_INTCNTL0_ADDR); +} + +__INLINE void ip_intcntl0_set(uint32_t value) +{ + REG_IP_WR(IP_INTCNTL0_ADDR, value); +} + +// field definitions +#define IP_ERRORINTMSK_BIT ((uint32_t)0x00010000) +#define IP_ERRORINTMSK_POS 16 + +#define IP_ERRORINTMSK_RST 0x0 + +__INLINE uint8_t ip_intcntl0_errorintmsk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL0_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00010000)) == 0); + return (localVal >> 16); +} + +__INLINE void ip_intcntl0_errorintmsk_setf(uint8_t errorintmsk) +{ + ASSERT_ERR((((uint32_t)errorintmsk << 16) & ~((uint32_t)0x00010000)) == 0); + REG_IP_WR(IP_INTCNTL0_ADDR, (uint32_t)errorintmsk << 16); +} + +/** + * @brief INTSTAT0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     16         ERRORINTSTAT   0
+ * 
+ */ +#define IP_INTSTAT0_ADDR BASEBAND_REG_BASE +0x10 // 0x50800010 +#define IP_INTSTAT0_OFFSET 0x00000010 +#define IP_INTSTAT0_INDEX 0x00000004 +#define IP_INTSTAT0_RESET 0x00000000 + +__INLINE uint32_t ip_intstat0_get(void) +{ + return REG_IP_RD(IP_INTSTAT0_ADDR); +} + +// field definitions +#define IP_ERRORINTSTAT_BIT ((uint32_t)0x00010000) +#define IP_ERRORINTSTAT_POS 16 + +#define IP_ERRORINTSTAT_RST 0x0 + +__INLINE uint8_t ip_intstat0_errorintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTSTAT0_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00010000)) == 0); + return (localVal >> 16); +} + +/** + * @brief INTACK0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     16          ERRORINTACK   0
+ * 
+ */ +#define IP_INTACK0_ADDR BASEBAND_REG_BASE +0x14 // 0x50800014 +#define IP_INTACK0_OFFSET 0x00000014 +#define IP_INTACK0_INDEX 0x00000005 +#define IP_INTACK0_RESET 0x00000000 + +__INLINE uint32_t ip_intack0_get(void) +{ + return REG_IP_RD(IP_INTACK0_ADDR); +} + +__INLINE void ip_intack0_clear(uint32_t value) +{ + REG_IP_WR(IP_INTACK0_ADDR, value); +} + +// field definitions +#define IP_ERRORINTACK_BIT ((uint32_t)0x00010000) +#define IP_ERRORINTACK_POS 16 + +#define IP_ERRORINTACK_RST 0x0 + +__INLINE uint8_t ip_intack0_errorintack_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTACK0_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00010000)) == 0); + return (localVal >> 16); +} + +__INLINE void ip_intack0_errorintack_clearf(uint8_t errorintack) +{ + ASSERT_ERR((((uint32_t)errorintack << 16) & ~((uint32_t)0x00010000)) == 0); + REG_IP_WR(IP_INTACK0_ADDR, (uint32_t)errorintack << 16); +} + +/** + * @brief INTCNTL1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  30:28         CLKNINTSRMSK   0x0
+ *  27:24         CLKNINTSRVAL   0x0
+ *     15           FIFOINTMSK   1
+ *     06   TIMESTAMPTGT2INTMSK   0
+ *     05   TIMESTAMPTGT1INTMSK   0
+ *     04        FINETGTINTMSK   0
+ *     03             SWINTMSK   0
+ *     02          CRYPTINTMSK   0
+ *     01            SLPINTMSK   1
+ *     00           CLKNINTMSK   1
+ * 
+ */ +#define IP_INTCNTL1_ADDR BASEBAND_REG_BASE +0x18 // 0x50800018 +#define IP_INTCNTL1_OFFSET 0x00000018 +#define IP_INTCNTL1_INDEX 0x00000006 +#define IP_INTCNTL1_RESET 0x00008003 + +__INLINE uint32_t ip_intcntl1_get(void) +{ + return REG_IP_RD(IP_INTCNTL1_ADDR); +} + +__INLINE void ip_intcntl1_set(uint32_t value) +{ + REG_IP_WR(IP_INTCNTL1_ADDR, value); +} + +// field definitions +#define IP_CLKNINTSRMSK_MASK ((uint32_t)0x70000000) +#define IP_CLKNINTSRMSK_LSB 28 +#define IP_CLKNINTSRMSK_WIDTH ((uint32_t)0x00000003) +#define IP_CLKNINTSRVAL_MASK ((uint32_t)0x0F000000) +#define IP_CLKNINTSRVAL_LSB 24 +#define IP_CLKNINTSRVAL_WIDTH ((uint32_t)0x00000004) +#define IP_FIFOINTMSK_BIT ((uint32_t)0x00008000) +#define IP_FIFOINTMSK_POS 15 +#define IP_TIMESTAMPTGT2INTMSK_BIT ((uint32_t)0x00000040) +#define IP_TIMESTAMPTGT2INTMSK_POS 6 +#define IP_TIMESTAMPTGT1INTMSK_BIT ((uint32_t)0x00000020) +#define IP_TIMESTAMPTGT1INTMSK_POS 5 +#define IP_FINETGTINTMSK_BIT ((uint32_t)0x00000010) +#define IP_FINETGTINTMSK_POS 4 +#define IP_SWINTMSK_BIT ((uint32_t)0x00000008) +#define IP_SWINTMSK_POS 3 +#define IP_CRYPTINTMSK_BIT ((uint32_t)0x00000004) +#define IP_CRYPTINTMSK_POS 2 +#define IP_SLPINTMSK_BIT ((uint32_t)0x00000002) +#define IP_SLPINTMSK_POS 1 +#define IP_CLKNINTMSK_BIT ((uint32_t)0x00000001) +#define IP_CLKNINTMSK_POS 0 + +#define IP_CLKNINTSRMSK_RST 0x0 +#define IP_CLKNINTSRVAL_RST 0x0 +#define IP_FIFOINTMSK_RST 0x1 +#define IP_TIMESTAMPTGT2INTMSK_RST 0x0 +#define IP_TIMESTAMPTGT1INTMSK_RST 0x0 +#define IP_FINETGTINTMSK_RST 0x0 +#define IP_SWINTMSK_RST 0x0 +#define IP_CRYPTINTMSK_RST 0x0 +#define IP_SLPINTMSK_RST 0x1 +#define IP_CLKNINTMSK_RST 0x1 + +__INLINE void ip_intcntl1_pack(uint8_t clknintsrmsk, uint8_t clknintsrval, uint8_t fifointmsk, uint8_t timestamptgt2intmsk, uint8_t timestamptgt1intmsk, uint8_t finetgtintmsk, uint8_t swintmsk, uint8_t cryptintmsk, uint8_t slpintmsk, uint8_t clknintmsk) +{ + ASSERT_ERR((((uint32_t)clknintsrmsk << 28) & ~((uint32_t)0x70000000)) == 0); + ASSERT_ERR((((uint32_t)clknintsrval << 24) & ~((uint32_t)0x0F000000)) == 0); + ASSERT_ERR((((uint32_t)fifointmsk << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)timestamptgt2intmsk << 6) & ~((uint32_t)0x00000040)) == 0); + ASSERT_ERR((((uint32_t)timestamptgt1intmsk << 5) & ~((uint32_t)0x00000020)) == 0); + ASSERT_ERR((((uint32_t)finetgtintmsk << 4) & ~((uint32_t)0x00000010)) == 0); + ASSERT_ERR((((uint32_t)swintmsk << 3) & ~((uint32_t)0x00000008)) == 0); + ASSERT_ERR((((uint32_t)cryptintmsk << 2) & ~((uint32_t)0x00000004)) == 0); + ASSERT_ERR((((uint32_t)slpintmsk << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)clknintmsk << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, ((uint32_t)clknintsrmsk << 28) | ((uint32_t)clknintsrval << 24) | ((uint32_t)fifointmsk << 15) | ((uint32_t)timestamptgt2intmsk << 6) | ((uint32_t)timestamptgt1intmsk << 5) | ((uint32_t)finetgtintmsk << 4) | ((uint32_t)swintmsk << 3) | ((uint32_t)cryptintmsk << 2) | ((uint32_t)slpintmsk << 1) | ((uint32_t)clknintmsk << 0)); +} + +__INLINE void ip_intcntl1_unpack(uint8_t* clknintsrmsk, uint8_t* clknintsrval, uint8_t* fifointmsk, uint8_t* timestamptgt2intmsk, uint8_t* timestamptgt1intmsk, uint8_t* finetgtintmsk, uint8_t* swintmsk, uint8_t* cryptintmsk, uint8_t* slpintmsk, uint8_t* clknintmsk) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + + *clknintsrmsk = (localVal & ((uint32_t)0x70000000)) >> 28; + *clknintsrval = (localVal & ((uint32_t)0x0F000000)) >> 24; + *fifointmsk = (localVal & ((uint32_t)0x00008000)) >> 15; + *timestamptgt2intmsk = (localVal & ((uint32_t)0x00000040)) >> 6; + *timestamptgt1intmsk = (localVal & ((uint32_t)0x00000020)) >> 5; + *finetgtintmsk = (localVal & ((uint32_t)0x00000010)) >> 4; + *swintmsk = (localVal & ((uint32_t)0x00000008)) >> 3; + *cryptintmsk = (localVal & ((uint32_t)0x00000004)) >> 2; + *slpintmsk = (localVal & ((uint32_t)0x00000002)) >> 1; + *clknintmsk = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ip_intcntl1_clknintsrmsk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x70000000)) >> 28); +} + +__INLINE void ip_intcntl1_clknintsrmsk_setf(uint8_t clknintsrmsk) +{ + ASSERT_ERR((((uint32_t)clknintsrmsk << 28) & ~((uint32_t)0x70000000)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, (REG_IP_RD(IP_INTCNTL1_ADDR) & ~((uint32_t)0x70000000)) | ((uint32_t)clknintsrmsk << 28)); +} + +__INLINE uint8_t ip_intcntl1_clknintsrval_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x0F000000)) >> 24); +} + +__INLINE void ip_intcntl1_clknintsrval_setf(uint8_t clknintsrval) +{ + ASSERT_ERR((((uint32_t)clknintsrval << 24) & ~((uint32_t)0x0F000000)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, (REG_IP_RD(IP_INTCNTL1_ADDR) & ~((uint32_t)0x0F000000)) | ((uint32_t)clknintsrval << 24)); +} + +__INLINE uint8_t ip_intcntl1_fifointmsk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ip_intcntl1_fifointmsk_setf(uint8_t fifointmsk) +{ + ASSERT_ERR((((uint32_t)fifointmsk << 15) & ~((uint32_t)0x00008000)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, (REG_IP_RD(IP_INTCNTL1_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)fifointmsk << 15)); +} + +__INLINE uint8_t ip_intcntl1_timestamptgt2intmsk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE void ip_intcntl1_timestamptgt2intmsk_setf(uint8_t timestamptgt2intmsk) +{ + ASSERT_ERR((((uint32_t)timestamptgt2intmsk << 6) & ~((uint32_t)0x00000040)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, (REG_IP_RD(IP_INTCNTL1_ADDR) & ~((uint32_t)0x00000040)) | ((uint32_t)timestamptgt2intmsk << 6)); +} + +__INLINE uint8_t ip_intcntl1_timestamptgt1intmsk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE void ip_intcntl1_timestamptgt1intmsk_setf(uint8_t timestamptgt1intmsk) +{ + ASSERT_ERR((((uint32_t)timestamptgt1intmsk << 5) & ~((uint32_t)0x00000020)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, (REG_IP_RD(IP_INTCNTL1_ADDR) & ~((uint32_t)0x00000020)) | ((uint32_t)timestamptgt1intmsk << 5)); +} + +__INLINE uint8_t ip_intcntl1_finetgtintmsk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE void ip_intcntl1_finetgtintmsk_setf(uint8_t finetgtintmsk) +{ + ASSERT_ERR((((uint32_t)finetgtintmsk << 4) & ~((uint32_t)0x00000010)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, (REG_IP_RD(IP_INTCNTL1_ADDR) & ~((uint32_t)0x00000010)) | ((uint32_t)finetgtintmsk << 4)); +} + +__INLINE uint8_t ip_intcntl1_swintmsk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE void ip_intcntl1_swintmsk_setf(uint8_t swintmsk) +{ + ASSERT_ERR((((uint32_t)swintmsk << 3) & ~((uint32_t)0x00000008)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, (REG_IP_RD(IP_INTCNTL1_ADDR) & ~((uint32_t)0x00000008)) | ((uint32_t)swintmsk << 3)); +} + +__INLINE uint8_t ip_intcntl1_cryptintmsk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE void ip_intcntl1_cryptintmsk_setf(uint8_t cryptintmsk) +{ + ASSERT_ERR((((uint32_t)cryptintmsk << 2) & ~((uint32_t)0x00000004)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, (REG_IP_RD(IP_INTCNTL1_ADDR) & ~((uint32_t)0x00000004)) | ((uint32_t)cryptintmsk << 2)); +} + +__INLINE uint8_t ip_intcntl1_slpintmsk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ip_intcntl1_slpintmsk_setf(uint8_t slpintmsk) +{ + ASSERT_ERR((((uint32_t)slpintmsk << 1) & ~((uint32_t)0x00000002)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, (REG_IP_RD(IP_INTCNTL1_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)slpintmsk << 1)); +} + +__INLINE uint8_t ip_intcntl1_clknintmsk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ip_intcntl1_clknintmsk_setf(uint8_t clknintmsk) +{ + ASSERT_ERR((((uint32_t)clknintmsk << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_INTCNTL1_ADDR, (REG_IP_RD(IP_INTCNTL1_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)clknintmsk << 0)); +} + +/** + * @brief INTSTAT1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15          FIFOINTSTAT   0
+ *     06   TIMESTAMPTGT2INTSTAT   0
+ *     05   TIMESTAMPTGT1INTSTAT   0
+ *     04       FINETGTINTSTAT   0
+ *     03            SWINTSTAT   0
+ *     02         CRYPTINTSTAT   0
+ *     01           SLPINTSTAT   0
+ *     00          CLKNINTSTAT   0
+ * 
+ */ +#define IP_INTSTAT1_ADDR BASEBAND_REG_BASE +0x1C // 0x5080001C +#define IP_INTSTAT1_OFFSET 0x0000001C +#define IP_INTSTAT1_INDEX 0x00000007 +#define IP_INTSTAT1_RESET 0x00000000 + +__INLINE uint32_t ip_intstat1_get(void) +{ + return REG_IP_RD(IP_INTSTAT1_ADDR); +} + +// field definitions +#define IP_FIFOINTSTAT_BIT ((uint32_t)0x00008000) +#define IP_FIFOINTSTAT_POS 15 +#define IP_TIMESTAMPTGT2INTSTAT_BIT ((uint32_t)0x00000040) +#define IP_TIMESTAMPTGT2INTSTAT_POS 6 +#define IP_TIMESTAMPTGT1INTSTAT_BIT ((uint32_t)0x00000020) +#define IP_TIMESTAMPTGT1INTSTAT_POS 5 +#define IP_FINETGTINTSTAT_BIT ((uint32_t)0x00000010) +#define IP_FINETGTINTSTAT_POS 4 +#define IP_SWINTSTAT_BIT ((uint32_t)0x00000008) +#define IP_SWINTSTAT_POS 3 +#define IP_CRYPTINTSTAT_BIT ((uint32_t)0x00000004) +#define IP_CRYPTINTSTAT_POS 2 +#define IP_SLPINTSTAT_BIT ((uint32_t)0x00000002) +#define IP_SLPINTSTAT_POS 1 +#define IP_CLKNINTSTAT_BIT ((uint32_t)0x00000001) +#define IP_CLKNINTSTAT_POS 0 + +#define IP_FIFOINTSTAT_RST 0x0 +#define IP_TIMESTAMPTGT2INTSTAT_RST 0x0 +#define IP_TIMESTAMPTGT1INTSTAT_RST 0x0 +#define IP_FINETGTINTSTAT_RST 0x0 +#define IP_SWINTSTAT_RST 0x0 +#define IP_CRYPTINTSTAT_RST 0x0 +#define IP_SLPINTSTAT_RST 0x0 +#define IP_CLKNINTSTAT_RST 0x0 + +__INLINE void ip_intstat1_unpack(uint8_t* fifointstat, uint8_t* timestamptgt2intstat, uint8_t* timestamptgt1intstat, uint8_t* finetgtintstat, uint8_t* swintstat, uint8_t* cryptintstat, uint8_t* slpintstat, uint8_t* clknintstat) +{ + uint32_t localVal = REG_IP_RD(IP_INTSTAT1_ADDR); + + *fifointstat = (localVal & ((uint32_t)0x00008000)) >> 15; + *timestamptgt2intstat = (localVal & ((uint32_t)0x00000040)) >> 6; + *timestamptgt1intstat = (localVal & ((uint32_t)0x00000020)) >> 5; + *finetgtintstat = (localVal & ((uint32_t)0x00000010)) >> 4; + *swintstat = (localVal & ((uint32_t)0x00000008)) >> 3; + *cryptintstat = (localVal & ((uint32_t)0x00000004)) >> 2; + *slpintstat = (localVal & ((uint32_t)0x00000002)) >> 1; + *clknintstat = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ip_intstat1_fifointstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE uint8_t ip_intstat1_timestamptgt2intstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE uint8_t ip_intstat1_timestamptgt1intstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE uint8_t ip_intstat1_finetgtintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE uint8_t ip_intstat1_swintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE uint8_t ip_intstat1_cryptintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE uint8_t ip_intstat1_slpintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE uint8_t ip_intstat1_clknintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTSTAT1_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +/** + * @brief INTACK1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     15           FIFOINTACK   0
+ *     06   TIMESTAMPTGT2INTACK   0
+ *     05   TIMESTAMPTGT1INTACK   0
+ *     04        FINETGTINTACK   0
+ *     03             SWINTACK   0
+ *     02          CRYPTINTACK   0
+ *     01            SLPINTACK   0
+ *     00           CLKNINTACK   0
+ * 
+ */ +#define IP_INTACK1_ADDR BASEBAND_REG_BASE +0x20 // 0x50800020 +#define IP_INTACK1_OFFSET 0x00000020 +#define IP_INTACK1_INDEX 0x00000008 +#define IP_INTACK1_RESET 0x00000000 + +__INLINE uint32_t ip_intack1_get(void) +{ + return REG_IP_RD(IP_INTACK1_ADDR); +} + +__INLINE void ip_intack1_clear(uint32_t value) +{ + REG_IP_WR(IP_INTACK1_ADDR, value); +} + +// field definitions +#define IP_FIFOINTACK_BIT ((uint32_t)0x00008000) +#define IP_FIFOINTACK_POS 15 +#define IP_TIMESTAMPTGT2INTACK_BIT ((uint32_t)0x00000040) +#define IP_TIMESTAMPTGT2INTACK_POS 6 +#define IP_TIMESTAMPTGT1INTACK_BIT ((uint32_t)0x00000020) +#define IP_TIMESTAMPTGT1INTACK_POS 5 +#define IP_FINETGTINTACK_BIT ((uint32_t)0x00000010) +#define IP_FINETGTINTACK_POS 4 +#define IP_SWINTACK_BIT ((uint32_t)0x00000008) +#define IP_SWINTACK_POS 3 +#define IP_CRYPTINTACK_BIT ((uint32_t)0x00000004) +#define IP_CRYPTINTACK_POS 2 +#define IP_SLPINTACK_BIT ((uint32_t)0x00000002) +#define IP_SLPINTACK_POS 1 +#define IP_CLKNINTACK_BIT ((uint32_t)0x00000001) +#define IP_CLKNINTACK_POS 0 + +#define IP_FIFOINTACK_RST 0x0 +#define IP_TIMESTAMPTGT2INTACK_RST 0x0 +#define IP_TIMESTAMPTGT1INTACK_RST 0x0 +#define IP_FINETGTINTACK_RST 0x0 +#define IP_SWINTACK_RST 0x0 +#define IP_CRYPTINTACK_RST 0x0 +#define IP_SLPINTACK_RST 0x0 +#define IP_CLKNINTACK_RST 0x0 + +__INLINE void ip_intack1_pack(uint8_t fifointack, uint8_t timestamptgt2intack, uint8_t timestamptgt1intack, uint8_t finetgtintack, uint8_t swintack, uint8_t cryptintack, uint8_t slpintack, uint8_t clknintack) +{ + ASSERT_ERR((((uint32_t)fifointack << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)timestamptgt2intack << 6) & ~((uint32_t)0x00000040)) == 0); + ASSERT_ERR((((uint32_t)timestamptgt1intack << 5) & ~((uint32_t)0x00000020)) == 0); + ASSERT_ERR((((uint32_t)finetgtintack << 4) & ~((uint32_t)0x00000010)) == 0); + ASSERT_ERR((((uint32_t)swintack << 3) & ~((uint32_t)0x00000008)) == 0); + ASSERT_ERR((((uint32_t)cryptintack << 2) & ~((uint32_t)0x00000004)) == 0); + ASSERT_ERR((((uint32_t)slpintack << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)clknintack << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_INTACK1_ADDR, ((uint32_t)fifointack << 15) | ((uint32_t)timestamptgt2intack << 6) | ((uint32_t)timestamptgt1intack << 5) | ((uint32_t)finetgtintack << 4) | ((uint32_t)swintack << 3) | ((uint32_t)cryptintack << 2) | ((uint32_t)slpintack << 1) | ((uint32_t)clknintack << 0)); +} + +__INLINE void ip_intack1_unpack(uint8_t* fifointack, uint8_t* timestamptgt2intack, uint8_t* timestamptgt1intack, uint8_t* finetgtintack, uint8_t* swintack, uint8_t* cryptintack, uint8_t* slpintack, uint8_t* clknintack) +{ + uint32_t localVal = REG_IP_RD(IP_INTACK1_ADDR); + + *fifointack = (localVal & ((uint32_t)0x00008000)) >> 15; + *timestamptgt2intack = (localVal & ((uint32_t)0x00000040)) >> 6; + *timestamptgt1intack = (localVal & ((uint32_t)0x00000020)) >> 5; + *finetgtintack = (localVal & ((uint32_t)0x00000010)) >> 4; + *swintack = (localVal & ((uint32_t)0x00000008)) >> 3; + *cryptintack = (localVal & ((uint32_t)0x00000004)) >> 2; + *slpintack = (localVal & ((uint32_t)0x00000002)) >> 1; + *clknintack = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ip_intack1_fifointack_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ip_intack1_fifointack_clearf(uint8_t fifointack) +{ + ASSERT_ERR((((uint32_t)fifointack << 15) & ~((uint32_t)0x00008000)) == 0); + REG_IP_WR(IP_INTACK1_ADDR, (uint32_t)fifointack << 15); +} + +__INLINE uint8_t ip_intack1_timestamptgt2intack_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE void ip_intack1_timestamptgt2intack_clearf(uint8_t timestamptgt2intack) +{ + ASSERT_ERR((((uint32_t)timestamptgt2intack << 6) & ~((uint32_t)0x00000040)) == 0); + REG_IP_WR(IP_INTACK1_ADDR, (uint32_t)timestamptgt2intack << 6); +} + +__INLINE uint8_t ip_intack1_timestamptgt1intack_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE void ip_intack1_timestamptgt1intack_clearf(uint8_t timestamptgt1intack) +{ + ASSERT_ERR((((uint32_t)timestamptgt1intack << 5) & ~((uint32_t)0x00000020)) == 0); + REG_IP_WR(IP_INTACK1_ADDR, (uint32_t)timestamptgt1intack << 5); +} + +__INLINE uint8_t ip_intack1_finetgtintack_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE void ip_intack1_finetgtintack_clearf(uint8_t finetgtintack) +{ + ASSERT_ERR((((uint32_t)finetgtintack << 4) & ~((uint32_t)0x00000010)) == 0); + REG_IP_WR(IP_INTACK1_ADDR, (uint32_t)finetgtintack << 4); +} + +__INLINE uint8_t ip_intack1_swintack_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE void ip_intack1_swintack_clearf(uint8_t swintack) +{ + ASSERT_ERR((((uint32_t)swintack << 3) & ~((uint32_t)0x00000008)) == 0); + REG_IP_WR(IP_INTACK1_ADDR, (uint32_t)swintack << 3); +} + +__INLINE uint8_t ip_intack1_cryptintack_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE void ip_intack1_cryptintack_clearf(uint8_t cryptintack) +{ + ASSERT_ERR((((uint32_t)cryptintack << 2) & ~((uint32_t)0x00000004)) == 0); + REG_IP_WR(IP_INTACK1_ADDR, (uint32_t)cryptintack << 2); +} + +__INLINE uint8_t ip_intack1_slpintack_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ip_intack1_slpintack_clearf(uint8_t slpintack) +{ + ASSERT_ERR((((uint32_t)slpintack << 1) & ~((uint32_t)0x00000002)) == 0); + REG_IP_WR(IP_INTACK1_ADDR, (uint32_t)slpintack << 1); +} + +__INLINE uint8_t ip_intack1_clknintack_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_INTACK1_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ip_intack1_clknintack_clearf(uint8_t clknintack) +{ + ASSERT_ERR((((uint32_t)clknintack << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_INTACK1_ADDR, (uint32_t)clknintack << 0); +} + +/** + * @brief ACTFIFOSTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:28          SKIP_ET_IDX   0x0
+ *  27:24       CURRENT_ET_IDX   0x0
+ *     15              ACTFLAG   0
+ *     06         ISORXINTSTAT   0
+ *     05         ISOTXINTSTAT   0
+ *     04            RXINTSTAT   0
+ *     03            TXINTSTAT   0
+ *     02       SKIPACTINTSTAT   0
+ *     01        ENDACTINTSTAT   0
+ *     00      STARTACTINTSTAT   0
+ * 
+ */ +#define IP_ACTFIFOSTAT_ADDR BASEBAND_REG_BASE +0x24 //0x50800024 +#define IP_ACTFIFOSTAT_OFFSET 0x00000024 +#define IP_ACTFIFOSTAT_INDEX 0x00000009 +#define IP_ACTFIFOSTAT_RESET 0x00000000 + +__INLINE uint32_t ip_actfifostat_get(void) +{ + return REG_IP_RD(IP_ACTFIFOSTAT_ADDR); +} + +// field definitions +#define IP_SKIP_ET_IDX_MASK ((uint32_t)0xF0000000) +#define IP_SKIP_ET_IDX_LSB 28 +#define IP_SKIP_ET_IDX_WIDTH ((uint32_t)0x00000004) +#define IP_CURRENT_ET_IDX_MASK ((uint32_t)0x0F000000) +#define IP_CURRENT_ET_IDX_LSB 24 +#define IP_CURRENT_ET_IDX_WIDTH ((uint32_t)0x00000004) +#define IP_ACTFLAG_BIT ((uint32_t)0x00008000) +#define IP_ACTFLAG_POS 15 +#define IP_ISORXINTSTAT_BIT ((uint32_t)0x00000040) +#define IP_ISORXINTSTAT_POS 6 +#define IP_ISOTXINTSTAT_BIT ((uint32_t)0x00000020) +#define IP_ISOTXINTSTAT_POS 5 +#define IP_RXINTSTAT_BIT ((uint32_t)0x00000010) +#define IP_RXINTSTAT_POS 4 +#define IP_TXINTSTAT_BIT ((uint32_t)0x00000008) +#define IP_TXINTSTAT_POS 3 +#define IP_SKIPACTINTSTAT_BIT ((uint32_t)0x00000004) +#define IP_SKIPACTINTSTAT_POS 2 +#define IP_ENDACTINTSTAT_BIT ((uint32_t)0x00000002) +#define IP_ENDACTINTSTAT_POS 1 +#define IP_STARTACTINTSTAT_BIT ((uint32_t)0x00000001) +#define IP_STARTACTINTSTAT_POS 0 + +#define IP_SKIP_ET_IDX_RST 0x0 +#define IP_CURRENT_ET_IDX_RST 0x0 +#define IP_ACTFLAG_RST 0x0 +#define IP_ISORXINTSTAT_RST 0x0 +#define IP_ISOTXINTSTAT_RST 0x0 +#define IP_RXINTSTAT_RST 0x0 +#define IP_TXINTSTAT_RST 0x0 +#define IP_SKIPACTINTSTAT_RST 0x0 +#define IP_ENDACTINTSTAT_RST 0x0 +#define IP_STARTACTINTSTAT_RST 0x0 + +__INLINE void ip_actfifostat_unpack(uint8_t* skipetidx, uint8_t* currentetidx, uint8_t* actflag, uint8_t* isorxintstat, uint8_t* isotxintstat, uint8_t* rxintstat, uint8_t* txintstat, uint8_t* skipactintstat, uint8_t* endactintstat, uint8_t* startactintstat) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + + *skipetidx = (localVal & ((uint32_t)0xF0000000)) >> 28; + *currentetidx = (localVal & ((uint32_t)0x0F000000)) >> 24; + *actflag = (localVal & ((uint32_t)0x00008000)) >> 15; + *isorxintstat = (localVal & ((uint32_t)0x00000040)) >> 6; + *isotxintstat = (localVal & ((uint32_t)0x00000020)) >> 5; + *rxintstat = (localVal & ((uint32_t)0x00000010)) >> 4; + *txintstat = (localVal & ((uint32_t)0x00000008)) >> 3; + *skipactintstat = (localVal & ((uint32_t)0x00000004)) >> 2; + *endactintstat = (localVal & ((uint32_t)0x00000002)) >> 1; + *startactintstat = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ip_actfifostat_skip_et_idx_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0xF0000000)) >> 28); +} + +__INLINE uint8_t ip_actfifostat_current_et_idx_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x0F000000)) >> 24); +} + +__INLINE uint8_t ip_actfifostat_actflag_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE uint8_t ip_actfifostat_isorxintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE uint8_t ip_actfifostat_isotxintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE uint8_t ip_actfifostat_rxintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE uint8_t ip_actfifostat_txintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE uint8_t ip_actfifostat_skipactintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE uint8_t ip_actfifostat_endactintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE uint8_t ip_actfifostat_startactintstat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTFIFOSTAT_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +/** + * @brief ETPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00                ETPTR   0x0
+ * 
+ */ +#define IP_ETPTR_ADDR BASEBAND_REG_BASE +0x2C //0x5080002C +#define IP_ETPTR_OFFSET 0x0000002C +#define IP_ETPTR_INDEX 0x0000000B +#define IP_ETPTR_RESET 0x00000000 + +__INLINE uint32_t ip_etptr_get(void) +{ + return REG_IP_RD(IP_ETPTR_ADDR); +} + +__INLINE void ip_etptr_set(uint32_t value) +{ + REG_IP_WR(IP_ETPTR_ADDR, value); +} + +// field definitions +#define IP_ETPTR_MASK ((uint32_t)0x00003FFF) +#define IP_ETPTR_LSB 0 +#define IP_ETPTR_WIDTH ((uint32_t)0x0000000E) + +#define IP_ETPTR_RST 0x0 + +__INLINE uint16_t ip_etptr_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ETPTR_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_etptr_setf(uint16_t etptr) +{ + ASSERT_ERR((((uint32_t)etptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_IP_WR(IP_ETPTR_ADDR, (uint32_t)etptr << 0); +} + +/** + * @brief DEEPSLCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31           EXTWKUPDSB   0
+ *     15      DEEP_SLEEP_STAT   0
+ *     03   DEEP_SLEEP_CORR_EN   0
+ *     02        DEEP_SLEEP_ON   0
+ *     01       RADIO_SLEEP_EN   0
+ *     00         OSC_SLEEP_EN   0
+ * 
+ */ +#define IP_DEEPSLCNTL_ADDR BASEBAND_REG_BASE +0x30 //0x50800030 +#define IP_DEEPSLCNTL_OFFSET 0x00000030 +#define IP_DEEPSLCNTL_INDEX 0x0000000C +#define IP_DEEPSLCNTL_RESET 0x00000000 + +__INLINE uint32_t ip_deepslcntl_get(void) +{ + return REG_IP_RD(IP_DEEPSLCNTL_ADDR); +} + +__INLINE void ip_deepslcntl_set(uint32_t value) +{ + REG_IP_WR(IP_DEEPSLCNTL_ADDR, value); +} + +// field definitions +#define IP_EXTWKUPDSB_BIT ((uint32_t)0x80000000) +#define IP_EXTWKUPDSB_POS 31 +#define IP_DEEP_SLEEP_STAT_BIT ((uint32_t)0x00008000) +#define IP_DEEP_SLEEP_STAT_POS 15 +#define IP_DEEP_SLEEP_CORR_EN_BIT ((uint32_t)0x00000008) +#define IP_DEEP_SLEEP_CORR_EN_POS 3 +#define IP_DEEP_SLEEP_ON_BIT ((uint32_t)0x00000004) +#define IP_DEEP_SLEEP_ON_POS 2 +#define IP_RADIO_SLEEP_EN_BIT ((uint32_t)0x00000002) +#define IP_RADIO_SLEEP_EN_POS 1 +#define IP_OSC_SLEEP_EN_BIT ((uint32_t)0x00000001) +#define IP_OSC_SLEEP_EN_POS 0 + +#define IP_EXTWKUPDSB_RST 0x0 +#define IP_DEEP_SLEEP_STAT_RST 0x0 +#define IP_DEEP_SLEEP_CORR_EN_RST 0x0 +#define IP_DEEP_SLEEP_ON_RST 0x0 +#define IP_RADIO_SLEEP_EN_RST 0x0 +#define IP_OSC_SLEEP_EN_RST 0x0 + +__INLINE void ip_deepslcntl_pack(uint8_t extwkupdsb, uint8_t deepsleepcorren, uint8_t deepsleepon, uint8_t radiosleepen, uint8_t oscsleepen) +{ + ASSERT_ERR((((uint32_t)extwkupdsb << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)deepsleepcorren << 3) & ~((uint32_t)0x00000008)) == 0); + ASSERT_ERR((((uint32_t)deepsleepon << 2) & ~((uint32_t)0x00000004)) == 0); + ASSERT_ERR((((uint32_t)radiosleepen << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)oscsleepen << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_DEEPSLCNTL_ADDR, ((uint32_t)extwkupdsb << 31) | ((uint32_t)deepsleepcorren << 3) | ((uint32_t)deepsleepon << 2) | ((uint32_t)radiosleepen << 1) | ((uint32_t)oscsleepen << 0)); +} + +__INLINE void ip_deepslcntl_unpack(uint8_t* extwkupdsb, uint8_t* deepsleepstat, uint8_t* deepsleepcorren, uint8_t* deepsleepon, uint8_t* radiosleepen, uint8_t* oscsleepen) +{ + uint32_t localVal = REG_IP_RD(IP_DEEPSLCNTL_ADDR); + + *extwkupdsb = (localVal & ((uint32_t)0x80000000)) >> 31; + *deepsleepstat = (localVal & ((uint32_t)0x00008000)) >> 15; + *deepsleepcorren = (localVal & ((uint32_t)0x00000008)) >> 3; + *deepsleepon = (localVal & ((uint32_t)0x00000004)) >> 2; + *radiosleepen = (localVal & ((uint32_t)0x00000002)) >> 1; + *oscsleepen = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ip_deepslcntl_extwkupdsb_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ip_deepslcntl_extwkupdsb_setf(uint8_t extwkupdsb) +{ + ASSERT_ERR((((uint32_t)extwkupdsb << 31) & ~((uint32_t)0x80000000)) == 0); + REG_IP_WR(IP_DEEPSLCNTL_ADDR, (REG_IP_RD(IP_DEEPSLCNTL_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)extwkupdsb << 31)); +} + +__INLINE uint8_t ip_deepslcntl_deep_sleep_stat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE uint8_t ip_deepslcntl_deep_sleep_corr_en_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE void ip_deepslcntl_deep_sleep_corr_en_setf(uint8_t deepsleepcorren) +{ + ASSERT_ERR((((uint32_t)deepsleepcorren << 3) & ~((uint32_t)0x00000008)) == 0); + REG_IP_WR(IP_DEEPSLCNTL_ADDR, (REG_IP_RD(IP_DEEPSLCNTL_ADDR) & ~((uint32_t)0x00000008)) | ((uint32_t)deepsleepcorren << 3)); +} + +__INLINE uint8_t ip_deepslcntl_deep_sleep_on_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE void ip_deepslcntl_deep_sleep_on_setf(uint8_t deepsleepon) +{ + ASSERT_ERR((((uint32_t)deepsleepon << 2) & ~((uint32_t)0x00000004)) == 0); + REG_IP_WR(IP_DEEPSLCNTL_ADDR, (REG_IP_RD(IP_DEEPSLCNTL_ADDR) & ~((uint32_t)0x00000004)) | ((uint32_t)deepsleepon << 2)); +} + +__INLINE uint8_t ip_deepslcntl_radio_sleep_en_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ip_deepslcntl_radio_sleep_en_setf(uint8_t radiosleepen) +{ + ASSERT_ERR((((uint32_t)radiosleepen << 1) & ~((uint32_t)0x00000002)) == 0); + REG_IP_WR(IP_DEEPSLCNTL_ADDR, (REG_IP_RD(IP_DEEPSLCNTL_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)radiosleepen << 1)); +} + +__INLINE uint8_t ip_deepslcntl_osc_sleep_en_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEEPSLCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ip_deepslcntl_osc_sleep_en_setf(uint8_t oscsleepen) +{ + ASSERT_ERR((((uint32_t)oscsleepen << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_DEEPSLCNTL_ADDR, (REG_IP_RD(IP_DEEPSLCNTL_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)oscsleepen << 0)); +} + +/** + * @brief DEEPSLWKUP register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00           DEEPSLTIME   0x0
+ * 
+ */ +#define IP_DEEPSLWKUP_ADDR BASEBAND_REG_BASE +0x34 // 0x50800034 +#define IP_DEEPSLWKUP_OFFSET 0x00000034 +#define IP_DEEPSLWKUP_INDEX 0x0000000D +#define IP_DEEPSLWKUP_RESET 0x00000000 + +__INLINE uint32_t ip_deepslwkup_get(void) +{ + return REG_IP_RD(IP_DEEPSLWKUP_ADDR); +} + +__INLINE void ip_deepslwkup_set(uint32_t value) +{ + REG_IP_WR(IP_DEEPSLWKUP_ADDR, value); +} + +// field definitions +#define IP_DEEPSLTIME_MASK ((uint32_t)0xFFFFFFFF) +#define IP_DEEPSLTIME_LSB 0 +#define IP_DEEPSLTIME_WIDTH ((uint32_t)0x00000020) + +#define IP_DEEPSLTIME_RST 0x0 + +__INLINE uint32_t ip_deepslwkup_deepsltime_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEEPSLWKUP_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_deepslwkup_deepsltime_setf(uint32_t deepsltime) +{ + ASSERT_ERR((((uint32_t)deepsltime << 0) & ~((uint32_t)0xFFFFFFFF)) == 0); + REG_IP_WR(IP_DEEPSLWKUP_ADDR, (uint32_t)deepsltime << 0); +} + +/** + * @brief DEEPSLSTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00            DEEPSLDUR   0x0
+ * 
+ */ +#define IP_DEEPSLSTAT_ADDR BASEBAND_REG_BASE +0x38 // 0x50800038 +#define IP_DEEPSLSTAT_OFFSET 0x00000038 +#define IP_DEEPSLSTAT_INDEX 0x0000000E +#define IP_DEEPSLSTAT_RESET 0x00000000 + +__INLINE uint32_t ip_deepslstat_get(void) +{ + return REG_IP_RD(IP_DEEPSLSTAT_ADDR); +} + +// field definitions +#define IP_DEEPSLDUR_MASK ((uint32_t)0xFFFFFFFF) +#define IP_DEEPSLDUR_LSB 0 +#define IP_DEEPSLDUR_WIDTH ((uint32_t)0x00000020) + +#define IP_DEEPSLDUR_RST 0x0 + +__INLINE uint32_t ip_deepslstat_deepsldur_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEEPSLSTAT_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief ENBPRESET register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:21                TWEXT   0xA0
+ *  20:10                TWOSC   0xA0
+ *  09:00                 TWRM   0x20
+ * 
+ */ +#define IP_ENBPRESET_ADDR BASEBAND_REG_BASE +0x3C // 0x5080003C +#define IP_ENBPRESET_OFFSET 0x0000003C +#define IP_ENBPRESET_INDEX 0x0000000F +#define IP_ENBPRESET_RESET 0x14028020 + +__INLINE uint32_t ip_enbpreset_get(void) +{ + return REG_IP_RD(IP_ENBPRESET_ADDR); +} + +__INLINE void ip_enbpreset_set(uint32_t value) +{ + REG_IP_WR(IP_ENBPRESET_ADDR, value); +} + +// field definitions +#define IP_TWEXT_MASK ((uint32_t)0xFFE00000) +#define IP_TWEXT_LSB 21 +#define IP_TWEXT_WIDTH ((uint32_t)0x0000000B) +#define IP_TWOSC_MASK ((uint32_t)0x001FFC00) +#define IP_TWOSC_LSB 10 +#define IP_TWOSC_WIDTH ((uint32_t)0x0000000B) +#define IP_TWRM_MASK ((uint32_t)0x000003FF) +#define IP_TWRM_LSB 0 +#define IP_TWRM_WIDTH ((uint32_t)0x0000000A) + +#define IP_TWEXT_RST 0xA0 +#define IP_TWOSC_RST 0xA0 +#define IP_TWRM_RST 0x20 + +__INLINE void ip_enbpreset_pack(uint16_t twext, uint16_t twosc, uint16_t twrm) +{ + ASSERT_ERR((((uint32_t)twext << 21) & ~((uint32_t)0xFFE00000)) == 0); + ASSERT_ERR((((uint32_t)twosc << 10) & ~((uint32_t)0x001FFC00)) == 0); + ASSERT_ERR((((uint32_t)twrm << 0) & ~((uint32_t)0x000003FF)) == 0); + REG_IP_WR(IP_ENBPRESET_ADDR, ((uint32_t)twext << 21) | ((uint32_t)twosc << 10) | ((uint32_t)twrm << 0)); +} + +__INLINE void ip_enbpreset_unpack(uint16_t* twext, uint16_t* twosc, uint16_t* twrm) +{ + uint32_t localVal = REG_IP_RD(IP_ENBPRESET_ADDR); + + *twext = (localVal & ((uint32_t)0xFFE00000)) >> 21; + *twosc = (localVal & ((uint32_t)0x001FFC00)) >> 10; + *twrm = (localVal & ((uint32_t)0x000003FF)) >> 0; +} + +__INLINE uint16_t ip_enbpreset_twext_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ENBPRESET_ADDR); + return ((localVal & ((uint32_t)0xFFE00000)) >> 21); +} + +__INLINE void ip_enbpreset_twext_setf(uint16_t twext) +{ + ASSERT_ERR((((uint32_t)twext << 21) & ~((uint32_t)0xFFE00000)) == 0); + REG_IP_WR(IP_ENBPRESET_ADDR, (REG_IP_RD(IP_ENBPRESET_ADDR) & ~((uint32_t)0xFFE00000)) | ((uint32_t)twext << 21)); +} + +__INLINE uint16_t ip_enbpreset_twosc_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ENBPRESET_ADDR); + return ((localVal & ((uint32_t)0x001FFC00)) >> 10); +} + +__INLINE void ip_enbpreset_twosc_setf(uint16_t twosc) +{ + ASSERT_ERR((((uint32_t)twosc << 10) & ~((uint32_t)0x001FFC00)) == 0); + REG_IP_WR(IP_ENBPRESET_ADDR, (REG_IP_RD(IP_ENBPRESET_ADDR) & ~((uint32_t)0x001FFC00)) | ((uint32_t)twosc << 10)); +} + +__INLINE uint16_t ip_enbpreset_twrm_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ENBPRESET_ADDR); + return ((localVal & ((uint32_t)0x000003FF)) >> 0); +} + +__INLINE void ip_enbpreset_twrm_setf(uint16_t twrm) +{ + ASSERT_ERR((((uint32_t)twrm << 0) & ~((uint32_t)0x000003FF)) == 0); + REG_IP_WR(IP_ENBPRESET_ADDR, (REG_IP_RD(IP_ENBPRESET_ADDR) & ~((uint32_t)0x000003FF)) | ((uint32_t)twrm << 0)); +} + +/** + * @brief FINECNTCORR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00          FINECNTCORR   0x0
+ * 
+ */ +#define IP_FINECNTCORR_ADDR BASEBAND_REG_BASE +0x40 //0x50800040 +#define IP_FINECNTCORR_OFFSET 0x00000040 +#define IP_FINECNTCORR_INDEX 0x00000010 +#define IP_FINECNTCORR_RESET 0x00000000 + +__INLINE uint32_t ip_finecntcorr_get(void) +{ + return REG_IP_RD(IP_FINECNTCORR_ADDR); +} + +__INLINE void ip_finecntcorr_set(uint32_t value) +{ + REG_IP_WR(IP_FINECNTCORR_ADDR, value); +} + +// field definitions +#define IP_FINECNTCORR_MASK ((uint32_t)0x000003FF) +#define IP_FINECNTCORR_LSB 0 +#define IP_FINECNTCORR_WIDTH ((uint32_t)0x0000000A) + +#define IP_FINECNTCORR_RST 0x0 + +__INLINE uint16_t ip_finecntcorr_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_FINECNTCORR_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_finecntcorr_setf(uint16_t finecntcorr) +{ + ASSERT_ERR((((uint32_t)finecntcorr << 0) & ~((uint32_t)0x000003FF)) == 0); + REG_IP_WR(IP_FINECNTCORR_ADDR, (uint32_t)finecntcorr << 0); +} + +/** + * @brief CLKNCNTCORR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31            ABS_DELTA   0
+ *  27:00          CLKNCNTCORR   0x0
+ * 
+ */ +#define IP_CLKNCNTCORR_ADDR BASEBAND_REG_BASE +0x44 // 0x50800044 +#define IP_CLKNCNTCORR_OFFSET 0x00000044 +#define IP_CLKNCNTCORR_INDEX 0x00000011 +#define IP_CLKNCNTCORR_RESET 0x00000000 + +__INLINE uint32_t ip_clkncntcorr_get(void) +{ + return REG_IP_RD(IP_CLKNCNTCORR_ADDR); +} + +__INLINE void ip_clkncntcorr_set(uint32_t value) +{ + REG_IP_WR(IP_CLKNCNTCORR_ADDR, value); +} + +// field definitions +#define IP_ABS_DELTA_BIT ((uint32_t)0x80000000) +#define IP_ABS_DELTA_POS 31 +#define IP_CLKNCNTCORR_MASK ((uint32_t)0x0FFFFFFF) +#define IP_CLKNCNTCORR_LSB 0 +#define IP_CLKNCNTCORR_WIDTH ((uint32_t)0x0000001C) + +#define IP_ABS_DELTA_RST 0x0 +#define IP_CLKNCNTCORR_RST 0x0 + +__INLINE void ip_clkncntcorr_pack(uint8_t absdelta, uint32_t clkncntcorr) +{ + ASSERT_ERR((((uint32_t)absdelta << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)clkncntcorr << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_IP_WR(IP_CLKNCNTCORR_ADDR, ((uint32_t)absdelta << 31) | ((uint32_t)clkncntcorr << 0)); +} + +__INLINE void ip_clkncntcorr_unpack(uint8_t* absdelta, uint32_t* clkncntcorr) +{ + uint32_t localVal = REG_IP_RD(IP_CLKNCNTCORR_ADDR); + + *absdelta = (localVal & ((uint32_t)0x80000000)) >> 31; + *clkncntcorr = (localVal & ((uint32_t)0x0FFFFFFF)) >> 0; +} + +__INLINE uint8_t ip_clkncntcorr_abs_delta_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_CLKNCNTCORR_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ip_clkncntcorr_abs_delta_setf(uint8_t absdelta) +{ + ASSERT_ERR((((uint32_t)absdelta << 31) & ~((uint32_t)0x80000000)) == 0); + REG_IP_WR(IP_CLKNCNTCORR_ADDR, (REG_IP_RD(IP_CLKNCNTCORR_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)absdelta << 31)); +} + +__INLINE uint32_t ip_clkncntcorr_clkncntcorr_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_CLKNCNTCORR_ADDR); + return ((localVal & ((uint32_t)0x0FFFFFFF)) >> 0); +} + +__INLINE void ip_clkncntcorr_clkncntcorr_setf(uint32_t clkncntcorr) +{ + ASSERT_ERR((((uint32_t)clkncntcorr << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_IP_WR(IP_CLKNCNTCORR_ADDR, (REG_IP_RD(IP_CLKNCNTCORR_ADDR) & ~((uint32_t)0x0FFFFFFF)) | ((uint32_t)clkncntcorr << 0)); +} + +/** + * @brief DIAGCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31             DIAG3_EN   0
+ *  29:24                DIAG3   0x0
+ *     23             DIAG2_EN   0
+ *  21:16                DIAG2   0x0
+ *     15             DIAG1_EN   0
+ *  13:08                DIAG1   0x0
+ *     07             DIAG0_EN   0
+ *  05:00                DIAG0   0x0
+ * 
+ */ +#define IP_DIAGCNTL_ADDR BASEBAND_REG_BASE +0x50 // 0x50800050 +#define IP_DIAGCNTL_OFFSET 0x00000050 +#define IP_DIAGCNTL_INDEX 0x00000014 +#define IP_DIAGCNTL_RESET 0x00000000 + +__INLINE uint32_t ip_diagcntl_get(void) +{ + return REG_IP_RD(IP_DIAGCNTL_ADDR); +} + +__INLINE void ip_diagcntl_set(uint32_t value) +{ + REG_IP_WR(IP_DIAGCNTL_ADDR, value); +} + +// field definitions +#define IP_DIAG3_EN_BIT ((uint32_t)0x80000000) +#define IP_DIAG3_EN_POS 31 +#define IP_DIAG3_MASK ((uint32_t)0x3F000000) +#define IP_DIAG3_LSB 24 +#define IP_DIAG3_WIDTH ((uint32_t)0x00000006) +#define IP_DIAG2_EN_BIT ((uint32_t)0x00800000) +#define IP_DIAG2_EN_POS 23 +#define IP_DIAG2_MASK ((uint32_t)0x003F0000) +#define IP_DIAG2_LSB 16 +#define IP_DIAG2_WIDTH ((uint32_t)0x00000006) +#define IP_DIAG1_EN_BIT ((uint32_t)0x00008000) +#define IP_DIAG1_EN_POS 15 +#define IP_DIAG1_MASK ((uint32_t)0x00003F00) +#define IP_DIAG1_LSB 8 +#define IP_DIAG1_WIDTH ((uint32_t)0x00000006) +#define IP_DIAG0_EN_BIT ((uint32_t)0x00000080) +#define IP_DIAG0_EN_POS 7 +#define IP_DIAG0_MASK ((uint32_t)0x0000003F) +#define IP_DIAG0_LSB 0 +#define IP_DIAG0_WIDTH ((uint32_t)0x00000006) + +#define IP_DIAG3_EN_RST 0x0 +#define IP_DIAG3_RST 0x0 +#define IP_DIAG2_EN_RST 0x0 +#define IP_DIAG2_RST 0x0 +#define IP_DIAG1_EN_RST 0x0 +#define IP_DIAG1_RST 0x0 +#define IP_DIAG0_EN_RST 0x0 +#define IP_DIAG0_RST 0x0 + +__INLINE void ip_diagcntl_pack(uint8_t diag3en, uint8_t diag3, uint8_t diag2en, uint8_t diag2, uint8_t diag1en, uint8_t diag1, uint8_t diag0en, uint8_t diag0) +{ + ASSERT_ERR((((uint32_t)diag3en << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)diag3 << 24) & ~((uint32_t)0x3F000000)) == 0); + ASSERT_ERR((((uint32_t)diag2en << 23) & ~((uint32_t)0x00800000)) == 0); + ASSERT_ERR((((uint32_t)diag2 << 16) & ~((uint32_t)0x003F0000)) == 0); + ASSERT_ERR((((uint32_t)diag1en << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)diag1 << 8) & ~((uint32_t)0x00003F00)) == 0); + ASSERT_ERR((((uint32_t)diag0en << 7) & ~((uint32_t)0x00000080)) == 0); + ASSERT_ERR((((uint32_t)diag0 << 0) & ~((uint32_t)0x0000003F)) == 0); + REG_IP_WR(IP_DIAGCNTL_ADDR, ((uint32_t)diag3en << 31) | ((uint32_t)diag3 << 24) | ((uint32_t)diag2en << 23) | ((uint32_t)diag2 << 16) | ((uint32_t)diag1en << 15) | ((uint32_t)diag1 << 8) | ((uint32_t)diag0en << 7) | ((uint32_t)diag0 << 0)); +} + +__INLINE void ip_diagcntl_unpack(uint8_t* diag3en, uint8_t* diag3, uint8_t* diag2en, uint8_t* diag2, uint8_t* diag1en, uint8_t* diag1, uint8_t* diag0en, uint8_t* diag0) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGCNTL_ADDR); + + *diag3en = (localVal & ((uint32_t)0x80000000)) >> 31; + *diag3 = (localVal & ((uint32_t)0x3F000000)) >> 24; + *diag2en = (localVal & ((uint32_t)0x00800000)) >> 23; + *diag2 = (localVal & ((uint32_t)0x003F0000)) >> 16; + *diag1en = (localVal & ((uint32_t)0x00008000)) >> 15; + *diag1 = (localVal & ((uint32_t)0x00003F00)) >> 8; + *diag0en = (localVal & ((uint32_t)0x00000080)) >> 7; + *diag0 = (localVal & ((uint32_t)0x0000003F)) >> 0; +} + +__INLINE uint8_t ip_diagcntl_diag3_en_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ip_diagcntl_diag3_en_setf(uint8_t diag3en) +{ + ASSERT_ERR((((uint32_t)diag3en << 31) & ~((uint32_t)0x80000000)) == 0); + REG_IP_WR(IP_DIAGCNTL_ADDR, (REG_IP_RD(IP_DIAGCNTL_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)diag3en << 31)); +} + +__INLINE uint8_t ip_diagcntl_diag3_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x3F000000)) >> 24); +} + +__INLINE void ip_diagcntl_diag3_setf(uint8_t diag3) +{ + ASSERT_ERR((((uint32_t)diag3 << 24) & ~((uint32_t)0x3F000000)) == 0); + REG_IP_WR(IP_DIAGCNTL_ADDR, (REG_IP_RD(IP_DIAGCNTL_ADDR) & ~((uint32_t)0x3F000000)) | ((uint32_t)diag3 << 24)); +} + +__INLINE uint8_t ip_diagcntl_diag2_en_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x00800000)) >> 23); +} + +__INLINE void ip_diagcntl_diag2_en_setf(uint8_t diag2en) +{ + ASSERT_ERR((((uint32_t)diag2en << 23) & ~((uint32_t)0x00800000)) == 0); + REG_IP_WR(IP_DIAGCNTL_ADDR, (REG_IP_RD(IP_DIAGCNTL_ADDR) & ~((uint32_t)0x00800000)) | ((uint32_t)diag2en << 23)); +} + +__INLINE uint8_t ip_diagcntl_diag2_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x003F0000)) >> 16); +} + +__INLINE void ip_diagcntl_diag2_setf(uint8_t diag2) +{ + ASSERT_ERR((((uint32_t)diag2 << 16) & ~((uint32_t)0x003F0000)) == 0); + REG_IP_WR(IP_DIAGCNTL_ADDR, (REG_IP_RD(IP_DIAGCNTL_ADDR) & ~((uint32_t)0x003F0000)) | ((uint32_t)diag2 << 16)); +} + +__INLINE uint8_t ip_diagcntl_diag1_en_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ip_diagcntl_diag1_en_setf(uint8_t diag1en) +{ + ASSERT_ERR((((uint32_t)diag1en << 15) & ~((uint32_t)0x00008000)) == 0); + REG_IP_WR(IP_DIAGCNTL_ADDR, (REG_IP_RD(IP_DIAGCNTL_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)diag1en << 15)); +} + +__INLINE uint8_t ip_diagcntl_diag1_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x00003F00)) >> 8); +} + +__INLINE void ip_diagcntl_diag1_setf(uint8_t diag1) +{ + ASSERT_ERR((((uint32_t)diag1 << 8) & ~((uint32_t)0x00003F00)) == 0); + REG_IP_WR(IP_DIAGCNTL_ADDR, (REG_IP_RD(IP_DIAGCNTL_ADDR) & ~((uint32_t)0x00003F00)) | ((uint32_t)diag1 << 8)); +} + +__INLINE uint8_t ip_diagcntl_diag0_en_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE void ip_diagcntl_diag0_en_setf(uint8_t diag0en) +{ + ASSERT_ERR((((uint32_t)diag0en << 7) & ~((uint32_t)0x00000080)) == 0); + REG_IP_WR(IP_DIAGCNTL_ADDR, (REG_IP_RD(IP_DIAGCNTL_ADDR) & ~((uint32_t)0x00000080)) | ((uint32_t)diag0en << 7)); +} + +__INLINE uint8_t ip_diagcntl_diag0_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGCNTL_ADDR); + return ((localVal & ((uint32_t)0x0000003F)) >> 0); +} + +__INLINE void ip_diagcntl_diag0_setf(uint8_t diag0) +{ + ASSERT_ERR((((uint32_t)diag0 << 0) & ~((uint32_t)0x0000003F)) == 0); + REG_IP_WR(IP_DIAGCNTL_ADDR, (REG_IP_RD(IP_DIAGCNTL_ADDR) & ~((uint32_t)0x0000003F)) | ((uint32_t)diag0 << 0)); +} + +/** + * @brief DIAGSTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:24            DIAG3STAT   0x0
+ *  23:16            DIAG2STAT   0x0
+ *  15:08            DIAG1STAT   0x0
+ *  07:00            DIAG0STAT   0x0
+ * 
+ */ +#define IP_DIAGSTAT_ADDR BASEBAND_REG_BASE +0x54 //0x50800054 +#define IP_DIAGSTAT_OFFSET 0x00000054 +#define IP_DIAGSTAT_INDEX 0x00000015 +#define IP_DIAGSTAT_RESET 0x00000000 + +__INLINE uint32_t ip_diagstat_get(void) +{ + return REG_IP_RD(IP_DIAGSTAT_ADDR); +} + +// field definitions +#define IP_DIAG3STAT_MASK ((uint32_t)0xFF000000) +#define IP_DIAG3STAT_LSB 24 +#define IP_DIAG3STAT_WIDTH ((uint32_t)0x00000008) +#define IP_DIAG2STAT_MASK ((uint32_t)0x00FF0000) +#define IP_DIAG2STAT_LSB 16 +#define IP_DIAG2STAT_WIDTH ((uint32_t)0x00000008) +#define IP_DIAG1STAT_MASK ((uint32_t)0x0000FF00) +#define IP_DIAG1STAT_LSB 8 +#define IP_DIAG1STAT_WIDTH ((uint32_t)0x00000008) +#define IP_DIAG0STAT_MASK ((uint32_t)0x000000FF) +#define IP_DIAG0STAT_LSB 0 +#define IP_DIAG0STAT_WIDTH ((uint32_t)0x00000008) + +#define IP_DIAG3STAT_RST 0x0 +#define IP_DIAG2STAT_RST 0x0 +#define IP_DIAG1STAT_RST 0x0 +#define IP_DIAG0STAT_RST 0x0 + +__INLINE void ip_diagstat_unpack(uint8_t* diag3stat, uint8_t* diag2stat, uint8_t* diag1stat, uint8_t* diag0stat) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGSTAT_ADDR); + + *diag3stat = (localVal & ((uint32_t)0xFF000000)) >> 24; + *diag2stat = (localVal & ((uint32_t)0x00FF0000)) >> 16; + *diag1stat = (localVal & ((uint32_t)0x0000FF00)) >> 8; + *diag0stat = (localVal & ((uint32_t)0x000000FF)) >> 0; +} + +__INLINE uint8_t ip_diagstat_diag3stat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGSTAT_ADDR); + return ((localVal & ((uint32_t)0xFF000000)) >> 24); +} + +__INLINE uint8_t ip_diagstat_diag2stat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGSTAT_ADDR); + return ((localVal & ((uint32_t)0x00FF0000)) >> 16); +} + +__INLINE uint8_t ip_diagstat_diag1stat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGSTAT_ADDR); + return ((localVal & ((uint32_t)0x0000FF00)) >> 8); +} + +__INLINE uint8_t ip_diagstat_diag0stat_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DIAGSTAT_ADDR); + return ((localVal & ((uint32_t)0x000000FF)) >> 0); +} + +/** + * @brief DEBUGADDMAX register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:16           REG_ADDMAX   0x0
+ *  15:00            EM_ADDMAX   0x0
+ * 
+ */ +#define IP_DEBUGADDMAX_ADDR BASEBAND_REG_BASE +0x58 // 0x50800058 +#define IP_DEBUGADDMAX_OFFSET 0x00000058 +#define IP_DEBUGADDMAX_INDEX 0x00000016 +#define IP_DEBUGADDMAX_RESET 0x00000000 + +__INLINE uint32_t ip_debugaddmax_get(void) +{ + return REG_IP_RD(IP_DEBUGADDMAX_ADDR); +} + +__INLINE void ip_debugaddmax_set(uint32_t value) +{ + REG_IP_WR(IP_DEBUGADDMAX_ADDR, value); +} + +// field definitions +#define IP_REG_ADDMAX_MASK ((uint32_t)0xFFFF0000) +#define IP_REG_ADDMAX_LSB 16 +#define IP_REG_ADDMAX_WIDTH ((uint32_t)0x00000010) +#define IP_EM_ADDMAX_MASK ((uint32_t)0x0000FFFF) +#define IP_EM_ADDMAX_LSB 0 +#define IP_EM_ADDMAX_WIDTH ((uint32_t)0x00000010) + +#define IP_REG_ADDMAX_RST 0x0 +#define IP_EM_ADDMAX_RST 0x0 + +__INLINE void ip_debugaddmax_pack(uint16_t regaddmax, uint16_t emaddmax) +{ + ASSERT_ERR((((uint32_t)regaddmax << 16) & ~((uint32_t)0xFFFF0000)) == 0); + ASSERT_ERR((((uint32_t)emaddmax << 0) & ~((uint32_t)0x0000FFFF)) == 0); + REG_IP_WR(IP_DEBUGADDMAX_ADDR, ((uint32_t)regaddmax << 16) | ((uint32_t)emaddmax << 0)); +} + +__INLINE void ip_debugaddmax_unpack(uint16_t* regaddmax, uint16_t* emaddmax) +{ + uint32_t localVal = REG_IP_RD(IP_DEBUGADDMAX_ADDR); + + *regaddmax = (localVal & ((uint32_t)0xFFFF0000)) >> 16; + *emaddmax = (localVal & ((uint32_t)0x0000FFFF)) >> 0; +} + +__INLINE uint16_t ip_debugaddmax_reg_addmax_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEBUGADDMAX_ADDR); + return ((localVal & ((uint32_t)0xFFFF0000)) >> 16); +} + +__INLINE void ip_debugaddmax_reg_addmax_setf(uint16_t regaddmax) +{ + ASSERT_ERR((((uint32_t)regaddmax << 16) & ~((uint32_t)0xFFFF0000)) == 0); + REG_IP_WR(IP_DEBUGADDMAX_ADDR, (REG_IP_RD(IP_DEBUGADDMAX_ADDR) & ~((uint32_t)0xFFFF0000)) | ((uint32_t)regaddmax << 16)); +} + +__INLINE uint16_t ip_debugaddmax_em_addmax_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEBUGADDMAX_ADDR); + return ((localVal & ((uint32_t)0x0000FFFF)) >> 0); +} + +__INLINE void ip_debugaddmax_em_addmax_setf(uint16_t emaddmax) +{ + ASSERT_ERR((((uint32_t)emaddmax << 0) & ~((uint32_t)0x0000FFFF)) == 0); + REG_IP_WR(IP_DEBUGADDMAX_ADDR, (REG_IP_RD(IP_DEBUGADDMAX_ADDR) & ~((uint32_t)0x0000FFFF)) | ((uint32_t)emaddmax << 0)); +} + +/** + * @brief DEBUGADDMIN register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:16           REG_ADDMIN   0x0
+ *  15:00            EM_ADDMIN   0x0
+ * 
+ */ +#define IP_DEBUGADDMIN_ADDR BASEBAND_REG_BASE +0x5C // 0x5080005C +#define IP_DEBUGADDMIN_OFFSET 0x0000005C +#define IP_DEBUGADDMIN_INDEX 0x00000017 +#define IP_DEBUGADDMIN_RESET 0x00000000 + +__INLINE uint32_t ip_debugaddmin_get(void) +{ + return REG_IP_RD(IP_DEBUGADDMIN_ADDR); +} + +__INLINE void ip_debugaddmin_set(uint32_t value) +{ + REG_IP_WR(IP_DEBUGADDMIN_ADDR, value); +} + +// field definitions +#define IP_REG_ADDMIN_MASK ((uint32_t)0xFFFF0000) +#define IP_REG_ADDMIN_LSB 16 +#define IP_REG_ADDMIN_WIDTH ((uint32_t)0x00000010) +#define IP_EM_ADDMIN_MASK ((uint32_t)0x0000FFFF) +#define IP_EM_ADDMIN_LSB 0 +#define IP_EM_ADDMIN_WIDTH ((uint32_t)0x00000010) + +#define IP_REG_ADDMIN_RST 0x0 +#define IP_EM_ADDMIN_RST 0x0 + +__INLINE void ip_debugaddmin_pack(uint16_t regaddmin, uint16_t emaddmin) +{ + ASSERT_ERR((((uint32_t)regaddmin << 16) & ~((uint32_t)0xFFFF0000)) == 0); + ASSERT_ERR((((uint32_t)emaddmin << 0) & ~((uint32_t)0x0000FFFF)) == 0); + REG_IP_WR(IP_DEBUGADDMIN_ADDR, ((uint32_t)regaddmin << 16) | ((uint32_t)emaddmin << 0)); +} + +__INLINE void ip_debugaddmin_unpack(uint16_t* regaddmin, uint16_t* emaddmin) +{ + uint32_t localVal = REG_IP_RD(IP_DEBUGADDMIN_ADDR); + + *regaddmin = (localVal & ((uint32_t)0xFFFF0000)) >> 16; + *emaddmin = (localVal & ((uint32_t)0x0000FFFF)) >> 0; +} + +__INLINE uint16_t ip_debugaddmin_reg_addmin_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEBUGADDMIN_ADDR); + return ((localVal & ((uint32_t)0xFFFF0000)) >> 16); +} + +__INLINE void ip_debugaddmin_reg_addmin_setf(uint16_t regaddmin) +{ + ASSERT_ERR((((uint32_t)regaddmin << 16) & ~((uint32_t)0xFFFF0000)) == 0); + REG_IP_WR(IP_DEBUGADDMIN_ADDR, (REG_IP_RD(IP_DEBUGADDMIN_ADDR) & ~((uint32_t)0xFFFF0000)) | ((uint32_t)regaddmin << 16)); +} + +__INLINE uint16_t ip_debugaddmin_em_addmin_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DEBUGADDMIN_ADDR); + return ((localVal & ((uint32_t)0x0000FFFF)) >> 0); +} + +__INLINE void ip_debugaddmin_em_addmin_setf(uint16_t emaddmin) +{ + ASSERT_ERR((((uint32_t)emaddmin << 0) & ~((uint32_t)0x0000FFFF)) == 0); + REG_IP_WR(IP_DEBUGADDMIN_ADDR, (REG_IP_RD(IP_DEBUGADDMIN_ADDR) & ~((uint32_t)0x0000FFFF)) | ((uint32_t)emaddmin << 0)); +} + +/** + * @brief ERRORTYPESTAT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     03   ACT_SCHDL_APFM_ERROR   0
+ *     02   ACT_SCHDL_ENTRY_ERROR   0
+ *     01         FIFOWRITEERR   0
+ *     00    RADIO_EMACC_ERROR   0
+ * 
+ */ +#define IP_ERRORTYPESTAT_ADDR BASEBAND_REG_BASE +0x60 //0x50800060 +#define IP_ERRORTYPESTAT_OFFSET 0x00000060 +#define IP_ERRORTYPESTAT_INDEX 0x00000018 +#define IP_ERRORTYPESTAT_RESET 0x00000000 + +__INLINE uint32_t ip_errortypestat_get(void) +{ + return REG_IP_RD(IP_ERRORTYPESTAT_ADDR); +} + +// field definitions +#define IP_ACT_SCHDL_APFM_ERROR_BIT ((uint32_t)0x00000008) +#define IP_ACT_SCHDL_APFM_ERROR_POS 3 +#define IP_ACT_SCHDL_ENTRY_ERROR_BIT ((uint32_t)0x00000004) +#define IP_ACT_SCHDL_ENTRY_ERROR_POS 2 +#define IP_FIFOWRITEERR_BIT ((uint32_t)0x00000002) +#define IP_FIFOWRITEERR_POS 1 +#define IP_RADIO_EMACC_ERROR_BIT ((uint32_t)0x00000001) +#define IP_RADIO_EMACC_ERROR_POS 0 + +#define IP_ACT_SCHDL_APFM_ERROR_RST 0x0 +#define IP_ACT_SCHDL_ENTRY_ERROR_RST 0x0 +#define IP_FIFOWRITEERR_RST 0x0 +#define IP_RADIO_EMACC_ERROR_RST 0x0 + +__INLINE void ip_errortypestat_unpack(uint8_t* actschdlapfmerror, uint8_t* actschdlentryerror, uint8_t* fifowriteerr, uint8_t* radioemaccerror) +{ + uint32_t localVal = REG_IP_RD(IP_ERRORTYPESTAT_ADDR); + + *actschdlapfmerror = (localVal & ((uint32_t)0x00000008)) >> 3; + *actschdlentryerror = (localVal & ((uint32_t)0x00000004)) >> 2; + *fifowriteerr = (localVal & ((uint32_t)0x00000002)) >> 1; + *radioemaccerror = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ip_errortypestat_act_schdl_apfm_error_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE uint8_t ip_errortypestat_act_schdl_entry_error_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE uint8_t ip_errortypestat_fifowriteerr_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE uint8_t ip_errortypestat_radio_emacc_error_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ERRORTYPESTAT_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +/** + * @brief SWPROFILING register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31             SWPROF31   0
+ *     30             SWPROF30   0
+ *     29             SWPROF29   0
+ *     28             SWPROF28   0
+ *     27             SWPROF27   0
+ *     26             SWPROF26   0
+ *     25             SWPROF25   0
+ *     24             SWPROF24   0
+ *     23             SWPROF23   0
+ *     22             SWPROF22   0
+ *     21             SWPROF21   0
+ *     20             SWPROF20   0
+ *     19             SWPROF19   0
+ *     18             SWPROF18   0
+ *     17             SWPROF17   0
+ *     16             SWPROF16   0
+ *     15             SWPROF15   0
+ *     14             SWPROF14   0
+ *     13             SWPROF13   0
+ *     12             SWPROF12   0
+ *     11             SWPROF11   0
+ *     10             SWPROF10   0
+ *     09              SWPROF9   0
+ *     08              SWPROF8   0
+ *     07              SWPROF7   0
+ *     06              SWPROF6   0
+ *     05              SWPROF5   0
+ *     04              SWPROF4   0
+ *     03              SWPROF3   0
+ *     02              SWPROF2   0
+ *     01              SWPROF1   0
+ *     00              SWPROF0   0
+ * 
+ */ +#define IP_SWPROFILING_ADDR BASEBAND_REG_BASE +0x64 // 0x50800064 +#define IP_SWPROFILING_OFFSET 0x00000064 +#define IP_SWPROFILING_INDEX 0x00000019 +#define IP_SWPROFILING_RESET 0x00000000 + +__INLINE uint32_t ip_swprofiling_get(void) +{ + return REG_IP_RD(IP_SWPROFILING_ADDR); +} + +__INLINE void ip_swprofiling_set(uint32_t value) +{ + REG_IP_WR(IP_SWPROFILING_ADDR, value); +} + +// field definitions +#define IP_SWPROF31_BIT ((uint32_t)0x80000000) +#define IP_SWPROF31_POS 31 +#define IP_SWPROF30_BIT ((uint32_t)0x40000000) +#define IP_SWPROF30_POS 30 +#define IP_SWPROF29_BIT ((uint32_t)0x20000000) +#define IP_SWPROF29_POS 29 +#define IP_SWPROF28_BIT ((uint32_t)0x10000000) +#define IP_SWPROF28_POS 28 +#define IP_SWPROF27_BIT ((uint32_t)0x08000000) +#define IP_SWPROF27_POS 27 +#define IP_SWPROF26_BIT ((uint32_t)0x04000000) +#define IP_SWPROF26_POS 26 +#define IP_SWPROF25_BIT ((uint32_t)0x02000000) +#define IP_SWPROF25_POS 25 +#define IP_SWPROF24_BIT ((uint32_t)0x01000000) +#define IP_SWPROF24_POS 24 +#define IP_SWPROF23_BIT ((uint32_t)0x00800000) +#define IP_SWPROF23_POS 23 +#define IP_SWPROF22_BIT ((uint32_t)0x00400000) +#define IP_SWPROF22_POS 22 +#define IP_SWPROF21_BIT ((uint32_t)0x00200000) +#define IP_SWPROF21_POS 21 +#define IP_SWPROF20_BIT ((uint32_t)0x00100000) +#define IP_SWPROF20_POS 20 +#define IP_SWPROF19_BIT ((uint32_t)0x00080000) +#define IP_SWPROF19_POS 19 +#define IP_SWPROF18_BIT ((uint32_t)0x00040000) +#define IP_SWPROF18_POS 18 +#define IP_SWPROF17_BIT ((uint32_t)0x00020000) +#define IP_SWPROF17_POS 17 +#define IP_SWPROF16_BIT ((uint32_t)0x00010000) +#define IP_SWPROF16_POS 16 +#define IP_SWPROF15_BIT ((uint32_t)0x00008000) +#define IP_SWPROF15_POS 15 +#define IP_SWPROF14_BIT ((uint32_t)0x00004000) +#define IP_SWPROF14_POS 14 +#define IP_SWPROF13_BIT ((uint32_t)0x00002000) +#define IP_SWPROF13_POS 13 +#define IP_SWPROF12_BIT ((uint32_t)0x00001000) +#define IP_SWPROF12_POS 12 +#define IP_SWPROF11_BIT ((uint32_t)0x00000800) +#define IP_SWPROF11_POS 11 +#define IP_SWPROF10_BIT ((uint32_t)0x00000400) +#define IP_SWPROF10_POS 10 +#define IP_SWPROF9_BIT ((uint32_t)0x00000200) +#define IP_SWPROF9_POS 9 +#define IP_SWPROF8_BIT ((uint32_t)0x00000100) +#define IP_SWPROF8_POS 8 +#define IP_SWPROF7_BIT ((uint32_t)0x00000080) +#define IP_SWPROF7_POS 7 +#define IP_SWPROF6_BIT ((uint32_t)0x00000040) +#define IP_SWPROF6_POS 6 +#define IP_SWPROF5_BIT ((uint32_t)0x00000020) +#define IP_SWPROF5_POS 5 +#define IP_SWPROF4_BIT ((uint32_t)0x00000010) +#define IP_SWPROF4_POS 4 +#define IP_SWPROF3_BIT ((uint32_t)0x00000008) +#define IP_SWPROF3_POS 3 +#define IP_SWPROF2_BIT ((uint32_t)0x00000004) +#define IP_SWPROF2_POS 2 +#define IP_SWPROF1_BIT ((uint32_t)0x00000002) +#define IP_SWPROF1_POS 1 +#define IP_SWPROF0_BIT ((uint32_t)0x00000001) +#define IP_SWPROF0_POS 0 + +#define IP_SWPROF31_RST 0x0 +#define IP_SWPROF30_RST 0x0 +#define IP_SWPROF29_RST 0x0 +#define IP_SWPROF28_RST 0x0 +#define IP_SWPROF27_RST 0x0 +#define IP_SWPROF26_RST 0x0 +#define IP_SWPROF25_RST 0x0 +#define IP_SWPROF24_RST 0x0 +#define IP_SWPROF23_RST 0x0 +#define IP_SWPROF22_RST 0x0 +#define IP_SWPROF21_RST 0x0 +#define IP_SWPROF20_RST 0x0 +#define IP_SWPROF19_RST 0x0 +#define IP_SWPROF18_RST 0x0 +#define IP_SWPROF17_RST 0x0 +#define IP_SWPROF16_RST 0x0 +#define IP_SWPROF15_RST 0x0 +#define IP_SWPROF14_RST 0x0 +#define IP_SWPROF13_RST 0x0 +#define IP_SWPROF12_RST 0x0 +#define IP_SWPROF11_RST 0x0 +#define IP_SWPROF10_RST 0x0 +#define IP_SWPROF9_RST 0x0 +#define IP_SWPROF8_RST 0x0 +#define IP_SWPROF7_RST 0x0 +#define IP_SWPROF6_RST 0x0 +#define IP_SWPROF5_RST 0x0 +#define IP_SWPROF4_RST 0x0 +#define IP_SWPROF3_RST 0x0 +#define IP_SWPROF2_RST 0x0 +#define IP_SWPROF1_RST 0x0 +#define IP_SWPROF0_RST 0x0 + +__INLINE void ip_swprofiling_pack(uint8_t swprof31, uint8_t swprof30, uint8_t swprof29, uint8_t swprof28, uint8_t swprof27, uint8_t swprof26, uint8_t swprof25, uint8_t swprof24, uint8_t swprof23, uint8_t swprof22, uint8_t swprof21, uint8_t swprof20, uint8_t swprof19, uint8_t swprof18, uint8_t swprof17, uint8_t swprof16, uint8_t swprof15, uint8_t swprof14, uint8_t swprof13, uint8_t swprof12, uint8_t swprof11, uint8_t swprof10, uint8_t swprof9, uint8_t swprof8, uint8_t swprof7, uint8_t swprof6, uint8_t swprof5, uint8_t swprof4, uint8_t swprof3, uint8_t swprof2, uint8_t swprof1, uint8_t swprof0) +{ + ASSERT_ERR((((uint32_t)swprof31 << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)swprof30 << 30) & ~((uint32_t)0x40000000)) == 0); + ASSERT_ERR((((uint32_t)swprof29 << 29) & ~((uint32_t)0x20000000)) == 0); + ASSERT_ERR((((uint32_t)swprof28 << 28) & ~((uint32_t)0x10000000)) == 0); + ASSERT_ERR((((uint32_t)swprof27 << 27) & ~((uint32_t)0x08000000)) == 0); + ASSERT_ERR((((uint32_t)swprof26 << 26) & ~((uint32_t)0x04000000)) == 0); + ASSERT_ERR((((uint32_t)swprof25 << 25) & ~((uint32_t)0x02000000)) == 0); + ASSERT_ERR((((uint32_t)swprof24 << 24) & ~((uint32_t)0x01000000)) == 0); + ASSERT_ERR((((uint32_t)swprof23 << 23) & ~((uint32_t)0x00800000)) == 0); + ASSERT_ERR((((uint32_t)swprof22 << 22) & ~((uint32_t)0x00400000)) == 0); + ASSERT_ERR((((uint32_t)swprof21 << 21) & ~((uint32_t)0x00200000)) == 0); + ASSERT_ERR((((uint32_t)swprof20 << 20) & ~((uint32_t)0x00100000)) == 0); + ASSERT_ERR((((uint32_t)swprof19 << 19) & ~((uint32_t)0x00080000)) == 0); + ASSERT_ERR((((uint32_t)swprof18 << 18) & ~((uint32_t)0x00040000)) == 0); + ASSERT_ERR((((uint32_t)swprof17 << 17) & ~((uint32_t)0x00020000)) == 0); + ASSERT_ERR((((uint32_t)swprof16 << 16) & ~((uint32_t)0x00010000)) == 0); + ASSERT_ERR((((uint32_t)swprof15 << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)swprof14 << 14) & ~((uint32_t)0x00004000)) == 0); + ASSERT_ERR((((uint32_t)swprof13 << 13) & ~((uint32_t)0x00002000)) == 0); + ASSERT_ERR((((uint32_t)swprof12 << 12) & ~((uint32_t)0x00001000)) == 0); + ASSERT_ERR((((uint32_t)swprof11 << 11) & ~((uint32_t)0x00000800)) == 0); + ASSERT_ERR((((uint32_t)swprof10 << 10) & ~((uint32_t)0x00000400)) == 0); + ASSERT_ERR((((uint32_t)swprof9 << 9) & ~((uint32_t)0x00000200)) == 0); + ASSERT_ERR((((uint32_t)swprof8 << 8) & ~((uint32_t)0x00000100)) == 0); + ASSERT_ERR((((uint32_t)swprof7 << 7) & ~((uint32_t)0x00000080)) == 0); + ASSERT_ERR((((uint32_t)swprof6 << 6) & ~((uint32_t)0x00000040)) == 0); + ASSERT_ERR((((uint32_t)swprof5 << 5) & ~((uint32_t)0x00000020)) == 0); + ASSERT_ERR((((uint32_t)swprof4 << 4) & ~((uint32_t)0x00000010)) == 0); + ASSERT_ERR((((uint32_t)swprof3 << 3) & ~((uint32_t)0x00000008)) == 0); + ASSERT_ERR((((uint32_t)swprof2 << 2) & ~((uint32_t)0x00000004)) == 0); + ASSERT_ERR((((uint32_t)swprof1 << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)swprof0 << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, ((uint32_t)swprof31 << 31) | ((uint32_t)swprof30 << 30) | ((uint32_t)swprof29 << 29) | ((uint32_t)swprof28 << 28) | ((uint32_t)swprof27 << 27) | ((uint32_t)swprof26 << 26) | ((uint32_t)swprof25 << 25) | ((uint32_t)swprof24 << 24) | ((uint32_t)swprof23 << 23) | ((uint32_t)swprof22 << 22) | ((uint32_t)swprof21 << 21) | ((uint32_t)swprof20 << 20) | ((uint32_t)swprof19 << 19) | ((uint32_t)swprof18 << 18) | ((uint32_t)swprof17 << 17) | ((uint32_t)swprof16 << 16) | ((uint32_t)swprof15 << 15) | ((uint32_t)swprof14 << 14) | ((uint32_t)swprof13 << 13) | ((uint32_t)swprof12 << 12) | ((uint32_t)swprof11 << 11) | ((uint32_t)swprof10 << 10) | ((uint32_t)swprof9 << 9) | ((uint32_t)swprof8 << 8) | ((uint32_t)swprof7 << 7) | ((uint32_t)swprof6 << 6) | ((uint32_t)swprof5 << 5) | ((uint32_t)swprof4 << 4) | ((uint32_t)swprof3 << 3) | ((uint32_t)swprof2 << 2) | ((uint32_t)swprof1 << 1) | ((uint32_t)swprof0 << 0)); +} + +__INLINE void ip_swprofiling_unpack(uint8_t* swprof31, uint8_t* swprof30, uint8_t* swprof29, uint8_t* swprof28, uint8_t* swprof27, uint8_t* swprof26, uint8_t* swprof25, uint8_t* swprof24, uint8_t* swprof23, uint8_t* swprof22, uint8_t* swprof21, uint8_t* swprof20, uint8_t* swprof19, uint8_t* swprof18, uint8_t* swprof17, uint8_t* swprof16, uint8_t* swprof15, uint8_t* swprof14, uint8_t* swprof13, uint8_t* swprof12, uint8_t* swprof11, uint8_t* swprof10, uint8_t* swprof9, uint8_t* swprof8, uint8_t* swprof7, uint8_t* swprof6, uint8_t* swprof5, uint8_t* swprof4, uint8_t* swprof3, uint8_t* swprof2, uint8_t* swprof1, uint8_t* swprof0) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + + *swprof31 = (localVal & ((uint32_t)0x80000000)) >> 31; + *swprof30 = (localVal & ((uint32_t)0x40000000)) >> 30; + *swprof29 = (localVal & ((uint32_t)0x20000000)) >> 29; + *swprof28 = (localVal & ((uint32_t)0x10000000)) >> 28; + *swprof27 = (localVal & ((uint32_t)0x08000000)) >> 27; + *swprof26 = (localVal & ((uint32_t)0x04000000)) >> 26; + *swprof25 = (localVal & ((uint32_t)0x02000000)) >> 25; + *swprof24 = (localVal & ((uint32_t)0x01000000)) >> 24; + *swprof23 = (localVal & ((uint32_t)0x00800000)) >> 23; + *swprof22 = (localVal & ((uint32_t)0x00400000)) >> 22; + *swprof21 = (localVal & ((uint32_t)0x00200000)) >> 21; + *swprof20 = (localVal & ((uint32_t)0x00100000)) >> 20; + *swprof19 = (localVal & ((uint32_t)0x00080000)) >> 19; + *swprof18 = (localVal & ((uint32_t)0x00040000)) >> 18; + *swprof17 = (localVal & ((uint32_t)0x00020000)) >> 17; + *swprof16 = (localVal & ((uint32_t)0x00010000)) >> 16; + *swprof15 = (localVal & ((uint32_t)0x00008000)) >> 15; + *swprof14 = (localVal & ((uint32_t)0x00004000)) >> 14; + *swprof13 = (localVal & ((uint32_t)0x00002000)) >> 13; + *swprof12 = (localVal & ((uint32_t)0x00001000)) >> 12; + *swprof11 = (localVal & ((uint32_t)0x00000800)) >> 11; + *swprof10 = (localVal & ((uint32_t)0x00000400)) >> 10; + *swprof9 = (localVal & ((uint32_t)0x00000200)) >> 9; + *swprof8 = (localVal & ((uint32_t)0x00000100)) >> 8; + *swprof7 = (localVal & ((uint32_t)0x00000080)) >> 7; + *swprof6 = (localVal & ((uint32_t)0x00000040)) >> 6; + *swprof5 = (localVal & ((uint32_t)0x00000020)) >> 5; + *swprof4 = (localVal & ((uint32_t)0x00000010)) >> 4; + *swprof3 = (localVal & ((uint32_t)0x00000008)) >> 3; + *swprof2 = (localVal & ((uint32_t)0x00000004)) >> 2; + *swprof1 = (localVal & ((uint32_t)0x00000002)) >> 1; + *swprof0 = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ip_swprofiling_swprof31_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ip_swprofiling_swprof31_setf(uint8_t swprof31) +{ + ASSERT_ERR((((uint32_t)swprof31 << 31) & ~((uint32_t)0x80000000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)swprof31 << 31)); +} + +__INLINE uint8_t ip_swprofiling_swprof30_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x40000000)) >> 30); +} + +__INLINE void ip_swprofiling_swprof30_setf(uint8_t swprof30) +{ + ASSERT_ERR((((uint32_t)swprof30 << 30) & ~((uint32_t)0x40000000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x40000000)) | ((uint32_t)swprof30 << 30)); +} + +__INLINE uint8_t ip_swprofiling_swprof29_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x20000000)) >> 29); +} + +__INLINE void ip_swprofiling_swprof29_setf(uint8_t swprof29) +{ + ASSERT_ERR((((uint32_t)swprof29 << 29) & ~((uint32_t)0x20000000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x20000000)) | ((uint32_t)swprof29 << 29)); +} + +__INLINE uint8_t ip_swprofiling_swprof28_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x10000000)) >> 28); +} + +__INLINE void ip_swprofiling_swprof28_setf(uint8_t swprof28) +{ + ASSERT_ERR((((uint32_t)swprof28 << 28) & ~((uint32_t)0x10000000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x10000000)) | ((uint32_t)swprof28 << 28)); +} + +__INLINE uint8_t ip_swprofiling_swprof27_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x08000000)) >> 27); +} + +__INLINE void ip_swprofiling_swprof27_setf(uint8_t swprof27) +{ + ASSERT_ERR((((uint32_t)swprof27 << 27) & ~((uint32_t)0x08000000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x08000000)) | ((uint32_t)swprof27 << 27)); +} + +__INLINE uint8_t ip_swprofiling_swprof26_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x04000000)) >> 26); +} + +__INLINE void ip_swprofiling_swprof26_setf(uint8_t swprof26) +{ + ASSERT_ERR((((uint32_t)swprof26 << 26) & ~((uint32_t)0x04000000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x04000000)) | ((uint32_t)swprof26 << 26)); +} + +__INLINE uint8_t ip_swprofiling_swprof25_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x02000000)) >> 25); +} + +__INLINE void ip_swprofiling_swprof25_setf(uint8_t swprof25) +{ + ASSERT_ERR((((uint32_t)swprof25 << 25) & ~((uint32_t)0x02000000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x02000000)) | ((uint32_t)swprof25 << 25)); +} + +__INLINE uint8_t ip_swprofiling_swprof24_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x01000000)) >> 24); +} + +__INLINE void ip_swprofiling_swprof24_setf(uint8_t swprof24) +{ + ASSERT_ERR((((uint32_t)swprof24 << 24) & ~((uint32_t)0x01000000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x01000000)) | ((uint32_t)swprof24 << 24)); +} + +__INLINE uint8_t ip_swprofiling_swprof23_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00800000)) >> 23); +} + +__INLINE void ip_swprofiling_swprof23_setf(uint8_t swprof23) +{ + ASSERT_ERR((((uint32_t)swprof23 << 23) & ~((uint32_t)0x00800000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00800000)) | ((uint32_t)swprof23 << 23)); +} + +__INLINE uint8_t ip_swprofiling_swprof22_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00400000)) >> 22); +} + +__INLINE void ip_swprofiling_swprof22_setf(uint8_t swprof22) +{ + ASSERT_ERR((((uint32_t)swprof22 << 22) & ~((uint32_t)0x00400000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00400000)) | ((uint32_t)swprof22 << 22)); +} + +__INLINE uint8_t ip_swprofiling_swprof21_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00200000)) >> 21); +} + +__INLINE void ip_swprofiling_swprof21_setf(uint8_t swprof21) +{ + ASSERT_ERR((((uint32_t)swprof21 << 21) & ~((uint32_t)0x00200000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00200000)) | ((uint32_t)swprof21 << 21)); +} + +__INLINE uint8_t ip_swprofiling_swprof20_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00100000)) >> 20); +} + +__INLINE void ip_swprofiling_swprof20_setf(uint8_t swprof20) +{ + ASSERT_ERR((((uint32_t)swprof20 << 20) & ~((uint32_t)0x00100000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00100000)) | ((uint32_t)swprof20 << 20)); +} + +__INLINE uint8_t ip_swprofiling_swprof19_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00080000)) >> 19); +} + +__INLINE void ip_swprofiling_swprof19_setf(uint8_t swprof19) +{ + ASSERT_ERR((((uint32_t)swprof19 << 19) & ~((uint32_t)0x00080000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00080000)) | ((uint32_t)swprof19 << 19)); +} + +__INLINE uint8_t ip_swprofiling_swprof18_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00040000)) >> 18); +} + +__INLINE void ip_swprofiling_swprof18_setf(uint8_t swprof18) +{ + ASSERT_ERR((((uint32_t)swprof18 << 18) & ~((uint32_t)0x00040000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00040000)) | ((uint32_t)swprof18 << 18)); +} + +__INLINE uint8_t ip_swprofiling_swprof17_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00020000)) >> 17); +} + +__INLINE void ip_swprofiling_swprof17_setf(uint8_t swprof17) +{ + ASSERT_ERR((((uint32_t)swprof17 << 17) & ~((uint32_t)0x00020000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00020000)) | ((uint32_t)swprof17 << 17)); +} + +__INLINE uint8_t ip_swprofiling_swprof16_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00010000)) >> 16); +} + +__INLINE void ip_swprofiling_swprof16_setf(uint8_t swprof16) +{ + ASSERT_ERR((((uint32_t)swprof16 << 16) & ~((uint32_t)0x00010000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00010000)) | ((uint32_t)swprof16 << 16)); +} + +__INLINE uint8_t ip_swprofiling_swprof15_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ip_swprofiling_swprof15_setf(uint8_t swprof15) +{ + ASSERT_ERR((((uint32_t)swprof15 << 15) & ~((uint32_t)0x00008000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)swprof15 << 15)); +} + +__INLINE uint8_t ip_swprofiling_swprof14_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00004000)) >> 14); +} + +__INLINE void ip_swprofiling_swprof14_setf(uint8_t swprof14) +{ + ASSERT_ERR((((uint32_t)swprof14 << 14) & ~((uint32_t)0x00004000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00004000)) | ((uint32_t)swprof14 << 14)); +} + +__INLINE uint8_t ip_swprofiling_swprof13_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00002000)) >> 13); +} + +__INLINE void ip_swprofiling_swprof13_setf(uint8_t swprof13) +{ + ASSERT_ERR((((uint32_t)swprof13 << 13) & ~((uint32_t)0x00002000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00002000)) | ((uint32_t)swprof13 << 13)); +} + +__INLINE uint8_t ip_swprofiling_swprof12_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00001000)) >> 12); +} + +__INLINE void ip_swprofiling_swprof12_setf(uint8_t swprof12) +{ + ASSERT_ERR((((uint32_t)swprof12 << 12) & ~((uint32_t)0x00001000)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00001000)) | ((uint32_t)swprof12 << 12)); +} + +__INLINE uint8_t ip_swprofiling_swprof11_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000800)) >> 11); +} + +__INLINE void ip_swprofiling_swprof11_setf(uint8_t swprof11) +{ + ASSERT_ERR((((uint32_t)swprof11 << 11) & ~((uint32_t)0x00000800)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000800)) | ((uint32_t)swprof11 << 11)); +} + +__INLINE uint8_t ip_swprofiling_swprof10_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000400)) >> 10); +} + +__INLINE void ip_swprofiling_swprof10_setf(uint8_t swprof10) +{ + ASSERT_ERR((((uint32_t)swprof10 << 10) & ~((uint32_t)0x00000400)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000400)) | ((uint32_t)swprof10 << 10)); +} + +__INLINE uint8_t ip_swprofiling_swprof9_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000200)) >> 9); +} + +__INLINE void ip_swprofiling_swprof9_setf(uint8_t swprof9) +{ + ASSERT_ERR((((uint32_t)swprof9 << 9) & ~((uint32_t)0x00000200)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000200)) | ((uint32_t)swprof9 << 9)); +} + +__INLINE uint8_t ip_swprofiling_swprof8_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000100)) >> 8); +} + +__INLINE void ip_swprofiling_swprof8_setf(uint8_t swprof8) +{ + ASSERT_ERR((((uint32_t)swprof8 << 8) & ~((uint32_t)0x00000100)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000100)) | ((uint32_t)swprof8 << 8)); +} + +__INLINE uint8_t ip_swprofiling_swprof7_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE void ip_swprofiling_swprof7_setf(uint8_t swprof7) +{ + ASSERT_ERR((((uint32_t)swprof7 << 7) & ~((uint32_t)0x00000080)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000080)) | ((uint32_t)swprof7 << 7)); +} + +__INLINE uint8_t ip_swprofiling_swprof6_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000040)) >> 6); +} + +__INLINE void ip_swprofiling_swprof6_setf(uint8_t swprof6) +{ + ASSERT_ERR((((uint32_t)swprof6 << 6) & ~((uint32_t)0x00000040)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000040)) | ((uint32_t)swprof6 << 6)); +} + +__INLINE uint8_t ip_swprofiling_swprof5_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000020)) >> 5); +} + +__INLINE void ip_swprofiling_swprof5_setf(uint8_t swprof5) +{ + ASSERT_ERR((((uint32_t)swprof5 << 5) & ~((uint32_t)0x00000020)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000020)) | ((uint32_t)swprof5 << 5)); +} + +__INLINE uint8_t ip_swprofiling_swprof4_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000010)) >> 4); +} + +__INLINE void ip_swprofiling_swprof4_setf(uint8_t swprof4) +{ + ASSERT_ERR((((uint32_t)swprof4 << 4) & ~((uint32_t)0x00000010)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000010)) | ((uint32_t)swprof4 << 4)); +} + +__INLINE uint8_t ip_swprofiling_swprof3_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000008)) >> 3); +} + +__INLINE void ip_swprofiling_swprof3_setf(uint8_t swprof3) +{ + ASSERT_ERR((((uint32_t)swprof3 << 3) & ~((uint32_t)0x00000008)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000008)) | ((uint32_t)swprof3 << 3)); +} + +__INLINE uint8_t ip_swprofiling_swprof2_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000004)) >> 2); +} + +__INLINE void ip_swprofiling_swprof2_setf(uint8_t swprof2) +{ + ASSERT_ERR((((uint32_t)swprof2 << 2) & ~((uint32_t)0x00000004)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000004)) | ((uint32_t)swprof2 << 2)); +} + +__INLINE uint8_t ip_swprofiling_swprof1_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ip_swprofiling_swprof1_setf(uint8_t swprof1) +{ + ASSERT_ERR((((uint32_t)swprof1 << 1) & ~((uint32_t)0x00000002)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)swprof1 << 1)); +} + +__INLINE uint8_t ip_swprofiling_swprof0_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SWPROFILING_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ip_swprofiling_swprof0_setf(uint8_t swprof0) +{ + ASSERT_ERR((((uint32_t)swprof0 << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_SWPROFILING_ADDR, (REG_IP_RD(IP_SWPROFILING_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)swprof0 << 0)); +} + +/** + * @brief RADIOCNTL0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  29:16               SPIPTR   0x0
+ *     07               SPICFG   0
+ *  05:04              SPIFREQ   0x0
+ *     01              SPICOMP   1
+ *     00                SPIGO   0
+ * 
+ */ +#define IP_RADIOCNTL0_ADDR BASEBAND_REG_BASE +0x70 // 0x50800070 +#define IP_RADIOCNTL0_OFFSET 0x00000070 +#define IP_RADIOCNTL0_INDEX 0x0000001C +#define IP_RADIOCNTL0_RESET 0x00000002 + +__INLINE uint32_t ip_radiocntl0_get(void) +{ + return REG_IP_RD(IP_RADIOCNTL0_ADDR); +} + +__INLINE void ip_radiocntl0_set(uint32_t value) +{ + REG_IP_WR(IP_RADIOCNTL0_ADDR, value); +} + +// field definitions +#define IP_SPIPTR_MASK ((uint32_t)0x3FFF0000) +#define IP_SPIPTR_LSB 16 +#define IP_SPIPTR_WIDTH ((uint32_t)0x0000000E) +#define IP_SPICFG_BIT ((uint32_t)0x00000080) +#define IP_SPICFG_POS 7 +#define IP_SPIFREQ_MASK ((uint32_t)0x00000030) +#define IP_SPIFREQ_LSB 4 +#define IP_SPIFREQ_WIDTH ((uint32_t)0x00000002) +#define IP_SPICOMP_BIT ((uint32_t)0x00000002) +#define IP_SPICOMP_POS 1 +#define IP_SPIGO_BIT ((uint32_t)0x00000001) +#define IP_SPIGO_POS 0 + +#define IP_SPIPTR_RST 0x0 +#define IP_SPICFG_RST 0x0 +#define IP_SPIFREQ_RST 0x0 +#define IP_SPICOMP_RST 0x1 +#define IP_SPIGO_RST 0x0 + +__INLINE void ip_radiocntl0_pack(uint16_t spiptr, uint8_t spicfg, uint8_t spifreq, uint8_t spigo) +{ + ASSERT_ERR((((uint32_t)spiptr << 16) & ~((uint32_t)0x3FFF0000)) == 0); + ASSERT_ERR((((uint32_t)spicfg << 7) & ~((uint32_t)0x00000080)) == 0); + ASSERT_ERR((((uint32_t)spifreq << 4) & ~((uint32_t)0x00000030)) == 0); + ASSERT_ERR((((uint32_t)spigo << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_RADIOCNTL0_ADDR, ((uint32_t)spiptr << 16) | ((uint32_t)spicfg << 7) | ((uint32_t)spifreq << 4) | ((uint32_t)spigo << 0)); +} + +__INLINE void ip_radiocntl0_unpack(uint16_t* spiptr, uint8_t* spicfg, uint8_t* spifreq, uint8_t* spicomp, uint8_t* spigo) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL0_ADDR); + + *spiptr = (localVal & ((uint32_t)0x3FFF0000)) >> 16; + *spicfg = (localVal & ((uint32_t)0x00000080)) >> 7; + *spifreq = (localVal & ((uint32_t)0x00000030)) >> 4; + *spicomp = (localVal & ((uint32_t)0x00000002)) >> 1; + *spigo = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint16_t ip_radiocntl0_spiptr_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL0_ADDR); + return ((localVal & ((uint32_t)0x3FFF0000)) >> 16); +} + +__INLINE void ip_radiocntl0_spiptr_setf(uint16_t spiptr) +{ + ASSERT_ERR((((uint32_t)spiptr << 16) & ~((uint32_t)0x3FFF0000)) == 0); + REG_IP_WR(IP_RADIOCNTL0_ADDR, (REG_IP_RD(IP_RADIOCNTL0_ADDR) & ~((uint32_t)0x3FFF0000)) | ((uint32_t)spiptr << 16)); +} + +__INLINE uint8_t ip_radiocntl0_spicfg_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE void ip_radiocntl0_spicfg_setf(uint8_t spicfg) +{ + ASSERT_ERR((((uint32_t)spicfg << 7) & ~((uint32_t)0x00000080)) == 0); + REG_IP_WR(IP_RADIOCNTL0_ADDR, (REG_IP_RD(IP_RADIOCNTL0_ADDR) & ~((uint32_t)0x00000080)) | ((uint32_t)spicfg << 7)); +} + +__INLINE uint8_t ip_radiocntl0_spifreq_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000030)) >> 4); +} + +__INLINE void ip_radiocntl0_spifreq_setf(uint8_t spifreq) +{ + ASSERT_ERR((((uint32_t)spifreq << 4) & ~((uint32_t)0x00000030)) == 0); + REG_IP_WR(IP_RADIOCNTL0_ADDR, (REG_IP_RD(IP_RADIOCNTL0_ADDR) & ~((uint32_t)0x00000030)) | ((uint32_t)spifreq << 4)); +} + +__INLINE uint8_t ip_radiocntl0_spicomp_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE uint8_t ip_radiocntl0_spigo_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL0_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ip_radiocntl0_spigo_setf(uint8_t spigo) +{ + ASSERT_ERR((((uint32_t)spigo << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_RADIOCNTL0_ADDR, (REG_IP_RD(IP_RADIOCNTL0_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)spigo << 0)); +} + +/** + * @brief RADIOCNTL1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31          FORCEAGC_EN   0
+ *     30              FORCEIQ   0
+ *     29               RXDNSL   0
+ *     28               TXDNSL   0
+ *  27:16      FORCEAGC_LENGTH   0x0
+ *     15      SYNC_PULSE_MODE   0
+ *     14       SYNC_PULSE_SRC   0
+ *     13            DPCORR_EN   0
+ *     12           JEF_SELECT   0
+ *  09:04               XRFSEL   0x0
+ *  03:00           SUBVERSION   0x0
+ * 
+ */ +#define IP_RADIOCNTL1_ADDR BASEBAND_REG_BASE +0x74 //0x50800074 +#define IP_RADIOCNTL1_OFFSET 0x00000074 +#define IP_RADIOCNTL1_INDEX 0x0000001D +#define IP_RADIOCNTL1_RESET 0x00000000 + +__INLINE uint32_t ip_radiocntl1_get(void) +{ + return REG_IP_RD(IP_RADIOCNTL1_ADDR); +} + +__INLINE void ip_radiocntl1_set(uint32_t value) +{ + REG_IP_WR(IP_RADIOCNTL1_ADDR, value); +} + +// field definitions +#define IP_FORCEAGC_EN_BIT ((uint32_t)0x80000000) +#define IP_FORCEAGC_EN_POS 31 +#define IP_FORCEIQ_BIT ((uint32_t)0x40000000) +#define IP_FORCEIQ_POS 30 +#define IP_RXDNSL_BIT ((uint32_t)0x20000000) +#define IP_RXDNSL_POS 29 +#define IP_TXDNSL_BIT ((uint32_t)0x10000000) +#define IP_TXDNSL_POS 28 +#define IP_FORCEAGC_LENGTH_MASK ((uint32_t)0x0FFF0000) +#define IP_FORCEAGC_LENGTH_LSB 16 +#define IP_FORCEAGC_LENGTH_WIDTH ((uint32_t)0x0000000C) +#define IP_SYNC_PULSE_MODE_BIT ((uint32_t)0x00008000) +#define IP_SYNC_PULSE_MODE_POS 15 +#define IP_SYNC_PULSE_SRC_BIT ((uint32_t)0x00004000) +#define IP_SYNC_PULSE_SRC_POS 14 +#define IP_DPCORR_EN_BIT ((uint32_t)0x00002000) +#define IP_DPCORR_EN_POS 13 +#define IP_JEF_SELECT_BIT ((uint32_t)0x00001000) +#define IP_JEF_SELECT_POS 12 +#define IP_XRFSEL_MASK ((uint32_t)0x000003F0) +#define IP_XRFSEL_LSB 4 +#define IP_XRFSEL_WIDTH ((uint32_t)0x00000006) +#define IP_SUBVERSION_MASK ((uint32_t)0x0000000F) +#define IP_SUBVERSION_LSB 0 +#define IP_SUBVERSION_WIDTH ((uint32_t)0x00000004) + +#define IP_FORCEAGC_EN_RST 0x0 +#define IP_FORCEIQ_RST 0x0 +#define IP_RXDNSL_RST 0x0 +#define IP_TXDNSL_RST 0x0 +#define IP_FORCEAGC_LENGTH_RST 0x0 +#define IP_SYNC_PULSE_MODE_RST 0x0 +#define IP_SYNC_PULSE_SRC_RST 0x0 +#define IP_DPCORR_EN_RST 0x0 +#define IP_JEF_SELECT_RST 0x0 +#define IP_XRFSEL_RST 0x0 +#define IP_SUBVERSION_RST 0x0 + +__INLINE void ip_radiocntl1_pack(uint8_t forceagcen, uint8_t forceiq, uint8_t rxdnsl, uint8_t txdnsl, uint16_t forceagclength, uint8_t syncpulsemode, uint8_t syncpulsesrc, uint8_t dpcorren, uint8_t jefselect, uint8_t xrfsel, uint8_t subversion) +{ + ASSERT_ERR((((uint32_t)forceagcen << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)forceiq << 30) & ~((uint32_t)0x40000000)) == 0); + ASSERT_ERR((((uint32_t)rxdnsl << 29) & ~((uint32_t)0x20000000)) == 0); + ASSERT_ERR((((uint32_t)txdnsl << 28) & ~((uint32_t)0x10000000)) == 0); + ASSERT_ERR((((uint32_t)forceagclength << 16) & ~((uint32_t)0x0FFF0000)) == 0); + ASSERT_ERR((((uint32_t)syncpulsemode << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)syncpulsesrc << 14) & ~((uint32_t)0x00004000)) == 0); + ASSERT_ERR((((uint32_t)dpcorren << 13) & ~((uint32_t)0x00002000)) == 0); + ASSERT_ERR((((uint32_t)jefselect << 12) & ~((uint32_t)0x00001000)) == 0); + ASSERT_ERR((((uint32_t)xrfsel << 4) & ~((uint32_t)0x000003F0)) == 0); + ASSERT_ERR((((uint32_t)subversion << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, ((uint32_t)forceagcen << 31) | ((uint32_t)forceiq << 30) | ((uint32_t)rxdnsl << 29) | ((uint32_t)txdnsl << 28) | ((uint32_t)forceagclength << 16) | ((uint32_t)syncpulsemode << 15) | ((uint32_t)syncpulsesrc << 14) | ((uint32_t)dpcorren << 13) | ((uint32_t)jefselect << 12) | ((uint32_t)xrfsel << 4) | ((uint32_t)subversion << 0)); +} + +__INLINE void ip_radiocntl1_unpack(uint8_t* forceagcen, uint8_t* forceiq, uint8_t* rxdnsl, uint8_t* txdnsl, uint16_t* forceagclength, uint8_t* syncpulsemode, uint8_t* syncpulsesrc, uint8_t* dpcorren, uint8_t* jefselect, uint8_t* xrfsel, uint8_t* subversion) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + + *forceagcen = (localVal & ((uint32_t)0x80000000)) >> 31; + *forceiq = (localVal & ((uint32_t)0x40000000)) >> 30; + *rxdnsl = (localVal & ((uint32_t)0x20000000)) >> 29; + *txdnsl = (localVal & ((uint32_t)0x10000000)) >> 28; + *forceagclength = (localVal & ((uint32_t)0x0FFF0000)) >> 16; + *syncpulsemode = (localVal & ((uint32_t)0x00008000)) >> 15; + *syncpulsesrc = (localVal & ((uint32_t)0x00004000)) >> 14; + *dpcorren = (localVal & ((uint32_t)0x00002000)) >> 13; + *jefselect = (localVal & ((uint32_t)0x00001000)) >> 12; + *xrfsel = (localVal & ((uint32_t)0x000003F0)) >> 4; + *subversion = (localVal & ((uint32_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t ip_radiocntl1_forceagc_en_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ip_radiocntl1_forceagc_en_setf(uint8_t forceagcen) +{ + ASSERT_ERR((((uint32_t)forceagcen << 31) & ~((uint32_t)0x80000000)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)forceagcen << 31)); +} + +__INLINE uint8_t ip_radiocntl1_forceiq_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x40000000)) >> 30); +} + +__INLINE void ip_radiocntl1_forceiq_setf(uint8_t forceiq) +{ + ASSERT_ERR((((uint32_t)forceiq << 30) & ~((uint32_t)0x40000000)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x40000000)) | ((uint32_t)forceiq << 30)); +} + +__INLINE uint8_t ip_radiocntl1_rxdnsl_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x20000000)) >> 29); +} + +__INLINE void ip_radiocntl1_rxdnsl_setf(uint8_t rxdnsl) +{ + ASSERT_ERR((((uint32_t)rxdnsl << 29) & ~((uint32_t)0x20000000)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x20000000)) | ((uint32_t)rxdnsl << 29)); +} + +__INLINE uint8_t ip_radiocntl1_txdnsl_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x10000000)) >> 28); +} + +__INLINE void ip_radiocntl1_txdnsl_setf(uint8_t txdnsl) +{ + ASSERT_ERR((((uint32_t)txdnsl << 28) & ~((uint32_t)0x10000000)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x10000000)) | ((uint32_t)txdnsl << 28)); +} + +__INLINE uint16_t ip_radiocntl1_forceagc_length_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x0FFF0000)) >> 16); +} + +__INLINE void ip_radiocntl1_forceagc_length_setf(uint16_t forceagclength) +{ + ASSERT_ERR((((uint32_t)forceagclength << 16) & ~((uint32_t)0x0FFF0000)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x0FFF0000)) | ((uint32_t)forceagclength << 16)); +} + +__INLINE uint8_t ip_radiocntl1_sync_pulse_mode_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ip_radiocntl1_sync_pulse_mode_setf(uint8_t syncpulsemode) +{ + ASSERT_ERR((((uint32_t)syncpulsemode << 15) & ~((uint32_t)0x00008000)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)syncpulsemode << 15)); +} + +__INLINE uint8_t ip_radiocntl1_sync_pulse_src_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00004000)) >> 14); +} + +__INLINE void ip_radiocntl1_sync_pulse_src_setf(uint8_t syncpulsesrc) +{ + ASSERT_ERR((((uint32_t)syncpulsesrc << 14) & ~((uint32_t)0x00004000)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x00004000)) | ((uint32_t)syncpulsesrc << 14)); +} + +__INLINE uint8_t ip_radiocntl1_dpcorr_en_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00002000)) >> 13); +} + +__INLINE void ip_radiocntl1_dpcorr_en_setf(uint8_t dpcorren) +{ + ASSERT_ERR((((uint32_t)dpcorren << 13) & ~((uint32_t)0x00002000)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x00002000)) | ((uint32_t)dpcorren << 13)); +} + +__INLINE uint8_t ip_radiocntl1_jef_select_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x00001000)) >> 12); +} + +__INLINE void ip_radiocntl1_jef_select_setf(uint8_t jefselect) +{ + ASSERT_ERR((((uint32_t)jefselect << 12) & ~((uint32_t)0x00001000)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x00001000)) | ((uint32_t)jefselect << 12)); +} + +__INLINE uint8_t ip_radiocntl1_xrfsel_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x000003F0)) >> 4); +} + +__INLINE void ip_radiocntl1_xrfsel_setf(uint8_t xrfsel) +{ + ASSERT_ERR((((uint32_t)xrfsel << 4) & ~((uint32_t)0x000003F0)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x000003F0)) | ((uint32_t)xrfsel << 4)); +} + +__INLINE uint8_t ip_radiocntl1_subversion_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RADIOCNTL1_ADDR); + return ((localVal & ((uint32_t)0x0000000F)) >> 0); +} + +__INLINE void ip_radiocntl1_subversion_setf(uint8_t subversion) +{ + ASSERT_ERR((((uint32_t)subversion << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_IP_WR(IP_RADIOCNTL1_ADDR, (REG_IP_RD(IP_RADIOCNTL1_ADDR) & ~((uint32_t)0x0000000F)) | ((uint32_t)subversion << 0)); +} + +/** + * @brief AESCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     01             AES_MODE   0
+ *     00            AES_START   0
+ * 
+ */ +#define IP_AESCNTL_ADDR BASEBAND_REG_BASE +0xB0 // 0x508000B0 +#define IP_AESCNTL_OFFSET 0x000000B0 +#define IP_AESCNTL_INDEX 0x0000002C +#define IP_AESCNTL_RESET 0x00000000 + +__INLINE uint32_t ip_aescntl_get(void) +{ + return REG_IP_RD(IP_AESCNTL_ADDR); +} + +__INLINE void ip_aescntl_set(uint32_t value) +{ + REG_IP_WR(IP_AESCNTL_ADDR, value); +} + +// field definitions +#define IP_AES_MODE_BIT ((uint32_t)0x00000002) +#define IP_AES_MODE_POS 1 +#define IP_AES_START_BIT ((uint32_t)0x00000001) +#define IP_AES_START_POS 0 + +#define IP_AES_MODE_RST 0x0 +#define IP_AES_START_RST 0x0 + +__INLINE void ip_aescntl_pack(uint8_t aesmode, uint8_t aesstart) +{ + ASSERT_ERR((((uint32_t)aesmode << 1) & ~((uint32_t)0x00000002)) == 0); + ASSERT_ERR((((uint32_t)aesstart << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_AESCNTL_ADDR, ((uint32_t)aesmode << 1) | ((uint32_t)aesstart << 0)); +} + +__INLINE void ip_aescntl_unpack(uint8_t* aesmode, uint8_t* aesstart) +{ + uint32_t localVal = REG_IP_RD(IP_AESCNTL_ADDR); + + *aesmode = (localVal & ((uint32_t)0x00000002)) >> 1; + *aesstart = (localVal & ((uint32_t)0x00000001)) >> 0; +} + +__INLINE uint8_t ip_aescntl_aes_mode_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_AESCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000002)) >> 1); +} + +__INLINE void ip_aescntl_aes_mode_setf(uint8_t aesmode) +{ + ASSERT_ERR((((uint32_t)aesmode << 1) & ~((uint32_t)0x00000002)) == 0); + REG_IP_WR(IP_AESCNTL_ADDR, (REG_IP_RD(IP_AESCNTL_ADDR) & ~((uint32_t)0x00000002)) | ((uint32_t)aesmode << 1)); +} + +__INLINE uint8_t ip_aescntl_aes_start_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_AESCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000001)) >> 0); +} + +__INLINE void ip_aescntl_aes_start_setf(uint8_t aesstart) +{ + ASSERT_ERR((((uint32_t)aesstart << 0) & ~((uint32_t)0x00000001)) == 0); + REG_IP_WR(IP_AESCNTL_ADDR, (REG_IP_RD(IP_AESCNTL_ADDR) & ~((uint32_t)0x00000001)) | ((uint32_t)aesstart << 0)); +} + +/** + * @brief AESKEY31_0 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00           AESKEY31_0   0x0
+ * 
+ */ +#define IP_AESKEY31_0_ADDR BASEBAND_REG_BASE +0xB4 //0x508000B4 +#define IP_AESKEY31_0_OFFSET 0x000000B4 +#define IP_AESKEY31_0_INDEX 0x0000002D +#define IP_AESKEY31_0_RESET 0x00000000 + +__INLINE uint32_t ip_aeskey31_0_get(void) +{ + return REG_IP_RD(IP_AESKEY31_0_ADDR); +} + +__INLINE void ip_aeskey31_0_set(uint32_t value) +{ + REG_IP_WR(IP_AESKEY31_0_ADDR, value); +} + +// field definitions +#define IP_AESKEY31_0_MASK ((uint32_t)0xFFFFFFFF) +#define IP_AESKEY31_0_LSB 0 +#define IP_AESKEY31_0_WIDTH ((uint32_t)0x00000020) + +#define IP_AESKEY31_0_RST 0x0 + +__INLINE uint32_t ip_aeskey31_0_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_AESKEY31_0_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_aeskey31_0_setf(uint32_t aeskey310) +{ + ASSERT_ERR((((uint32_t)aeskey310 << 0) & ~((uint32_t)0xFFFFFFFF)) == 0); + REG_IP_WR(IP_AESKEY31_0_ADDR, (uint32_t)aeskey310 << 0); +} + +/** + * @brief AESKEY63_32 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00          AESKEY63_32   0x0
+ * 
+ */ +#define IP_AESKEY63_32_ADDR BASEBAND_REG_BASE +0xB8 // 0x508000B8 +#define IP_AESKEY63_32_OFFSET 0x000000B8 +#define IP_AESKEY63_32_INDEX 0x0000002E +#define IP_AESKEY63_32_RESET 0x00000000 + +__INLINE uint32_t ip_aeskey63_32_get(void) +{ + return REG_IP_RD(IP_AESKEY63_32_ADDR); +} + +__INLINE void ip_aeskey63_32_set(uint32_t value) +{ + REG_IP_WR(IP_AESKEY63_32_ADDR, value); +} + +// field definitions +#define IP_AESKEY63_32_MASK ((uint32_t)0xFFFFFFFF) +#define IP_AESKEY63_32_LSB 0 +#define IP_AESKEY63_32_WIDTH ((uint32_t)0x00000020) + +#define IP_AESKEY63_32_RST 0x0 + +__INLINE uint32_t ip_aeskey63_32_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_AESKEY63_32_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_aeskey63_32_setf(uint32_t aeskey6332) +{ + ASSERT_ERR((((uint32_t)aeskey6332 << 0) & ~((uint32_t)0xFFFFFFFF)) == 0); + REG_IP_WR(IP_AESKEY63_32_ADDR, (uint32_t)aeskey6332 << 0); +} + +/** + * @brief AESKEY95_64 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00          AESKEY95_64   0x0
+ * 
+ */ +#define IP_AESKEY95_64_ADDR BASEBAND_REG_BASE +0xBC //0x508000BC +#define IP_AESKEY95_64_OFFSET 0x000000BC +#define IP_AESKEY95_64_INDEX 0x0000002F +#define IP_AESKEY95_64_RESET 0x00000000 + +__INLINE uint32_t ip_aeskey95_64_get(void) +{ + return REG_IP_RD(IP_AESKEY95_64_ADDR); +} + +__INLINE void ip_aeskey95_64_set(uint32_t value) +{ + REG_IP_WR(IP_AESKEY95_64_ADDR, value); +} + +// field definitions +#define IP_AESKEY95_64_MASK ((uint32_t)0xFFFFFFFF) +#define IP_AESKEY95_64_LSB 0 +#define IP_AESKEY95_64_WIDTH ((uint32_t)0x00000020) + +#define IP_AESKEY95_64_RST 0x0 + +__INLINE uint32_t ip_aeskey95_64_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_AESKEY95_64_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_aeskey95_64_setf(uint32_t aeskey9564) +{ + ASSERT_ERR((((uint32_t)aeskey9564 << 0) & ~((uint32_t)0xFFFFFFFF)) == 0); + REG_IP_WR(IP_AESKEY95_64_ADDR, (uint32_t)aeskey9564 << 0); +} + +/** + * @brief AESKEY127_96 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00         AESKEY127_96   0x0
+ * 
+ */ +#define IP_AESKEY127_96_ADDR BASEBAND_REG_BASE +0xC0 // 0x508000C0 +#define IP_AESKEY127_96_OFFSET 0x000000C0 +#define IP_AESKEY127_96_INDEX 0x00000030 +#define IP_AESKEY127_96_RESET 0x00000000 + +__INLINE uint32_t ip_aeskey127_96_get(void) +{ + return REG_IP_RD(IP_AESKEY127_96_ADDR); +} + +__INLINE void ip_aeskey127_96_set(uint32_t value) +{ + REG_IP_WR(IP_AESKEY127_96_ADDR, value); +} + +// field definitions +#define IP_AESKEY127_96_MASK ((uint32_t)0xFFFFFFFF) +#define IP_AESKEY127_96_LSB 0 +#define IP_AESKEY127_96_WIDTH ((uint32_t)0x00000020) + +#define IP_AESKEY127_96_RST 0x0 + +__INLINE uint32_t ip_aeskey127_96_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_AESKEY127_96_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_aeskey127_96_setf(uint32_t aeskey12796) +{ + ASSERT_ERR((((uint32_t)aeskey12796 << 0) & ~((uint32_t)0xFFFFFFFF)) == 0); + REG_IP_WR(IP_AESKEY127_96_ADDR, (uint32_t)aeskey12796 << 0); +} + +/** + * @brief AESPTR register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  13:00               AESPTR   0x0
+ * 
+ */ +#define IP_AESPTR_ADDR BASEBAND_REG_BASE +0xC4 //0x508000C4 +#define IP_AESPTR_OFFSET 0x000000C4 +#define IP_AESPTR_INDEX 0x00000031 +#define IP_AESPTR_RESET 0x00000000 + +__INLINE uint32_t ip_aesptr_get(void) +{ + return REG_IP_RD(IP_AESPTR_ADDR); +} + +__INLINE void ip_aesptr_set(uint32_t value) +{ + REG_IP_WR(IP_AESPTR_ADDR, value); +} + +// field definitions +#define IP_AESPTR_MASK ((uint32_t)0x00003FFF) +#define IP_AESPTR_LSB 0 +#define IP_AESPTR_WIDTH ((uint32_t)0x0000000E) + +#define IP_AESPTR_RST 0x0 + +__INLINE uint16_t ip_aesptr_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_AESPTR_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x00003FFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_aesptr_setf(uint16_t aesptr) +{ + ASSERT_ERR((((uint32_t)aesptr << 0) & ~((uint32_t)0x00003FFF)) == 0); + REG_IP_WR(IP_AESPTR_ADDR, (uint32_t)aesptr << 0); +} + +/** + * @brief TXMICVAL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00             TXMICVAL   0x0
+ * 
+ */ +#define IP_TXMICVAL_ADDR BASEBAND_REG_BASE +0xC8 //0x508000C8 +#define IP_TXMICVAL_OFFSET 0x000000C8 +#define IP_TXMICVAL_INDEX 0x00000032 +#define IP_TXMICVAL_RESET 0x00000000 + +__INLINE uint32_t ip_txmicval_get(void) +{ + return REG_IP_RD(IP_TXMICVAL_ADDR); +} + +// field definitions +#define IP_TXMICVAL_MASK ((uint32_t)0xFFFFFFFF) +#define IP_TXMICVAL_LSB 0 +#define IP_TXMICVAL_WIDTH ((uint32_t)0x00000020) + +#define IP_TXMICVAL_RST 0x0 + +__INLINE uint32_t ip_txmicval_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_TXMICVAL_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief RXMICVAL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  31:00             RXMICVAL   0x0
+ * 
+ */ +#define IP_RXMICVAL_ADDR BASEBAND_REG_BASE +0xCC //0x508000CC +#define IP_RXMICVAL_OFFSET 0x000000CC +#define IP_RXMICVAL_INDEX 0x00000033 +#define IP_RXMICVAL_RESET 0x00000000 + +__INLINE uint32_t ip_rxmicval_get(void) +{ + return REG_IP_RD(IP_RXMICVAL_ADDR); +} + +// field definitions +#define IP_RXMICVAL_MASK ((uint32_t)0xFFFFFFFF) +#define IP_RXMICVAL_LSB 0 +#define IP_RXMICVAL_WIDTH ((uint32_t)0x00000020) + +#define IP_RXMICVAL_RST 0x0 + +__INLINE uint32_t ip_rxmicval_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_RXMICVAL_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0xFFFFFFFF)) == 0); + return (localVal >> 0); +} + +/** + * @brief TIMGENCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  25:16   PREFETCHABORT_TIME   0x1DF
+ *  08:00        PREFETCH_TIME   0xBD
+ * 
+ */ +#define IP_TIMGENCNTL_ADDR BASEBAND_REG_BASE +0xE0 //0x508000E0 +#define IP_TIMGENCNTL_OFFSET 0x000000E0 +#define IP_TIMGENCNTL_INDEX 0x00000038 +#define IP_TIMGENCNTL_RESET 0x01DF00BD + +__INLINE uint32_t ip_timgencntl_get(void) +{ + return REG_IP_RD(IP_TIMGENCNTL_ADDR); +} + +__INLINE void ip_timgencntl_set(uint32_t value) +{ + REG_IP_WR(IP_TIMGENCNTL_ADDR, value); +} + +// field definitions +#define IP_PREFETCHABORT_TIME_MASK ((uint32_t)0x03FF0000) +#define IP_PREFETCHABORT_TIME_LSB 16 +#define IP_PREFETCHABORT_TIME_WIDTH ((uint32_t)0x0000000A) +#define IP_PREFETCH_TIME_MASK ((uint32_t)0x000001FF) +#define IP_PREFETCH_TIME_LSB 0 +#define IP_PREFETCH_TIME_WIDTH ((uint32_t)0x00000009) + +#define IP_PREFETCHABORT_TIME_RST 0x1DF +#define IP_PREFETCH_TIME_RST 0xBD + +__INLINE void ip_timgencntl_pack(uint16_t prefetchaborttime, uint16_t prefetchtime) +{ + ASSERT_ERR((((uint32_t)prefetchaborttime << 16) & ~((uint32_t)0x03FF0000)) == 0); + ASSERT_ERR((((uint32_t)prefetchtime << 0) & ~((uint32_t)0x000001FF)) == 0); + REG_IP_WR(IP_TIMGENCNTL_ADDR, ((uint32_t)prefetchaborttime << 16) | ((uint32_t)prefetchtime << 0)); +} + +__INLINE void ip_timgencntl_unpack(uint16_t* prefetchaborttime, uint16_t* prefetchtime) +{ + uint32_t localVal = REG_IP_RD(IP_TIMGENCNTL_ADDR); + + *prefetchaborttime = (localVal & ((uint32_t)0x03FF0000)) >> 16; + *prefetchtime = (localVal & ((uint32_t)0x000001FF)) >> 0; +} + +__INLINE uint16_t ip_timgencntl_prefetchabort_time_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_TIMGENCNTL_ADDR); + return ((localVal & ((uint32_t)0x03FF0000)) >> 16); +} + +__INLINE void ip_timgencntl_prefetchabort_time_setf(uint16_t prefetchaborttime) +{ + ASSERT_ERR((((uint32_t)prefetchaborttime << 16) & ~((uint32_t)0x03FF0000)) == 0); + REG_IP_WR(IP_TIMGENCNTL_ADDR, (REG_IP_RD(IP_TIMGENCNTL_ADDR) & ~((uint32_t)0x03FF0000)) | ((uint32_t)prefetchaborttime << 16)); +} + +__INLINE uint16_t ip_timgencntl_prefetch_time_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_TIMGENCNTL_ADDR); + return ((localVal & ((uint32_t)0x000001FF)) >> 0); +} + +__INLINE void ip_timgencntl_prefetch_time_setf(uint16_t prefetchtime) +{ + ASSERT_ERR((((uint32_t)prefetchtime << 0) & ~((uint32_t)0x000001FF)) == 0); + REG_IP_WR(IP_TIMGENCNTL_ADDR, (REG_IP_RD(IP_TIMGENCNTL_ADDR) & ~((uint32_t)0x000001FF)) | ((uint32_t)prefetchtime << 0)); +} + +/** + * @brief FINETIMTGT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  27:00           FINETARGET   0x0
+ * 
+ */ +#define IP_FINETIMTGT_ADDR BASEBAND_REG_BASE +0xE4 //0x508000E4 +#define IP_FINETIMTGT_OFFSET 0x000000E4 +#define IP_FINETIMTGT_INDEX 0x00000039 +#define IP_FINETIMTGT_RESET 0x00000000 + +__INLINE uint32_t ip_finetimtgt_get(void) +{ + return REG_IP_RD(IP_FINETIMTGT_ADDR); +} + +__INLINE void ip_finetimtgt_set(uint32_t value) +{ + REG_IP_WR(IP_FINETIMTGT_ADDR, value); +} + +// field definitions +#define IP_FINETARGET_MASK ((uint32_t)0x0FFFFFFF) +#define IP_FINETARGET_LSB 0 +#define IP_FINETARGET_WIDTH ((uint32_t)0x0000001C) + +#define IP_FINETARGET_RST 0x0 + +__INLINE uint32_t ip_finetimtgt_finetarget_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_FINETIMTGT_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x0FFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_finetimtgt_finetarget_setf(uint32_t finetarget) +{ + ASSERT_ERR((((uint32_t)finetarget << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_IP_WR(IP_FINETIMTGT_ADDR, (uint32_t)finetarget << 0); +} + +/** + * @brief CLKNTGT1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  27:00             CLKNTGT1   0x0
+ * 
+ */ +#define IP_CLKNTGT1_ADDR BASEBAND_REG_BASE +0xE8 // 0x508000E8 +#define IP_CLKNTGT1_OFFSET 0x000000E8 +#define IP_CLKNTGT1_INDEX 0x0000003A +#define IP_CLKNTGT1_RESET 0x00000000 + +__INLINE uint32_t ip_clkntgt1_get(void) +{ + return REG_IP_RD(IP_CLKNTGT1_ADDR); +} + +__INLINE void ip_clkntgt1_set(uint32_t value) +{ + REG_IP_WR(IP_CLKNTGT1_ADDR, value); +} + +// field definitions +#define IP_CLKNTGT1_MASK ((uint32_t)0x0FFFFFFF) +#define IP_CLKNTGT1_LSB 0 +#define IP_CLKNTGT1_WIDTH ((uint32_t)0x0000001C) + +#define IP_CLKNTGT1_RST 0x0 + +__INLINE uint32_t ip_clkntgt1_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_CLKNTGT1_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x0FFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_clkntgt1_setf(uint32_t clkntgt1) +{ + ASSERT_ERR((((uint32_t)clkntgt1 << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_IP_WR(IP_CLKNTGT1_ADDR, (uint32_t)clkntgt1 << 0); +} + +/** + * @brief HMICROSECTGT1 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00        HMICROSECTGT1   0x0
+ * 
+ */ +#define IP_HMICROSECTGT1_ADDR BASEBAND_REG_BASE +0xEC //0x508000EC +#define IP_HMICROSECTGT1_OFFSET 0x000000EC +#define IP_HMICROSECTGT1_INDEX 0x0000003B +#define IP_HMICROSECTGT1_RESET 0x00000000 + +__INLINE uint32_t ip_hmicrosectgt1_get(void) +{ + return REG_IP_RD(IP_HMICROSECTGT1_ADDR); +} + +__INLINE void ip_hmicrosectgt1_set(uint32_t value) +{ + REG_IP_WR(IP_HMICROSECTGT1_ADDR, value); +} + +// field definitions +#define IP_HMICROSECTGT1_MASK ((uint32_t)0x000003FF) +#define IP_HMICROSECTGT1_LSB 0 +#define IP_HMICROSECTGT1_WIDTH ((uint32_t)0x0000000A) + +#define IP_HMICROSECTGT1_RST 0x0 + +__INLINE uint16_t ip_hmicrosectgt1_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_HMICROSECTGT1_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_hmicrosectgt1_setf(uint16_t hmicrosectgt1) +{ + ASSERT_ERR((((uint32_t)hmicrosectgt1 << 0) & ~((uint32_t)0x000003FF)) == 0); + REG_IP_WR(IP_HMICROSECTGT1_ADDR, (uint32_t)hmicrosectgt1 << 0); +} + +/** + * @brief CLKNTGT2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  27:00             CLKNTGT2   0x0
+ * 
+ */ +#define IP_CLKNTGT2_ADDR BASEBAND_REG_BASE +0xF0 //0x508000F0 +#define IP_CLKNTGT2_OFFSET 0x000000F0 +#define IP_CLKNTGT2_INDEX 0x0000003C +#define IP_CLKNTGT2_RESET 0x00000000 + +__INLINE uint32_t ip_clkntgt2_get(void) +{ + return REG_IP_RD(IP_CLKNTGT2_ADDR); +} + +__INLINE void ip_clkntgt2_set(uint32_t value) +{ + REG_IP_WR(IP_CLKNTGT2_ADDR, value); +} + +// field definitions +#define IP_CLKNTGT2_MASK ((uint32_t)0x0FFFFFFF) +#define IP_CLKNTGT2_LSB 0 +#define IP_CLKNTGT2_WIDTH ((uint32_t)0x0000001C) + +#define IP_CLKNTGT2_RST 0x0 + +__INLINE uint32_t ip_clkntgt2_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_CLKNTGT2_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x0FFFFFFF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_clkntgt2_setf(uint32_t clkntgt2) +{ + ASSERT_ERR((((uint32_t)clkntgt2 << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_IP_WR(IP_CLKNTGT2_ADDR, (uint32_t)clkntgt2 << 0); +} + +/** + * @brief HMICROSECTGT2 register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00        HMICROSECTGT2   0x0
+ * 
+ */ +#define IP_HMICROSECTGT2_ADDR BASEBAND_REG_BASE +0xF4 //0x508000F4 +#define IP_HMICROSECTGT2_OFFSET 0x000000F4 +#define IP_HMICROSECTGT2_INDEX 0x0000003D +#define IP_HMICROSECTGT2_RESET 0x00000000 + +__INLINE uint32_t ip_hmicrosectgt2_get(void) +{ + return REG_IP_RD(IP_HMICROSECTGT2_ADDR); +} + +__INLINE void ip_hmicrosectgt2_set(uint32_t value) +{ + REG_IP_WR(IP_HMICROSECTGT2_ADDR, value); +} + +// field definitions +#define IP_HMICROSECTGT2_MASK ((uint32_t)0x000003FF) +#define IP_HMICROSECTGT2_LSB 0 +#define IP_HMICROSECTGT2_WIDTH ((uint32_t)0x0000000A) + +#define IP_HMICROSECTGT2_RST 0x0 + +__INLINE uint16_t ip_hmicrosectgt2_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_HMICROSECTGT2_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +__INLINE void ip_hmicrosectgt2_setf(uint16_t hmicrosectgt2) +{ + ASSERT_ERR((((uint32_t)hmicrosectgt2 << 0) & ~((uint32_t)0x000003FF)) == 0); + REG_IP_WR(IP_HMICROSECTGT2_ADDR, (uint32_t)hmicrosectgt2 << 0); +} + +/** + * @brief SLOTCLK register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31                 SAMP   0
+ *     30             CLKN_UPD   0
+ *  27:00                 SCLK   0x0
+ * 
+ */ +#define IP_SLOTCLK_ADDR BASEBAND_REG_BASE +0xF8 //0x508000F8 +#define IP_SLOTCLK_OFFSET 0x000000F8 +#define IP_SLOTCLK_INDEX 0x0000003E +#define IP_SLOTCLK_RESET 0x00000000 + +__INLINE uint32_t ip_slotclk_get(void) +{ + return REG_IP_RD(IP_SLOTCLK_ADDR); +} + +__INLINE void ip_slotclk_set(uint32_t value) +{ + REG_IP_WR(IP_SLOTCLK_ADDR, value); +} + +// field definitions +#define IP_SAMP_BIT ((uint32_t)0x80000000) +#define IP_SAMP_POS 31 +#define IP_CLKN_UPD_BIT ((uint32_t)0x40000000) +#define IP_CLKN_UPD_POS 30 +#define IP_SCLK_MASK ((uint32_t)0x0FFFFFFF) +#define IP_SCLK_LSB 0 +#define IP_SCLK_WIDTH ((uint32_t)0x0000001C) + +#define IP_SAMP_RST 0x0 +#define IP_CLKN_UPD_RST 0x0 +#define IP_SCLK_RST 0x0 + +__INLINE void ip_slotclk_pack(uint8_t samp, uint8_t clknupd, uint32_t sclk) +{ + ASSERT_ERR((((uint32_t)samp << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)clknupd << 30) & ~((uint32_t)0x40000000)) == 0); + ASSERT_ERR((((uint32_t)sclk << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_IP_WR(IP_SLOTCLK_ADDR, ((uint32_t)samp << 31) | ((uint32_t)clknupd << 30) | ((uint32_t)sclk << 0)); +} + +__INLINE void ip_slotclk_unpack(uint8_t* samp, uint8_t* clknupd, uint32_t* sclk) +{ + uint32_t localVal = REG_IP_RD(IP_SLOTCLK_ADDR); + + *samp = (localVal & ((uint32_t)0x80000000)) >> 31; + *clknupd = (localVal & ((uint32_t)0x40000000)) >> 30; + *sclk = (localVal & ((uint32_t)0x0FFFFFFF)) >> 0; +} + +__INLINE uint8_t ip_slotclk_samp_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SLOTCLK_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ip_slotclk_samp_setf(uint8_t samp) +{ + ASSERT_ERR((((uint32_t)samp << 31) & ~((uint32_t)0x80000000)) == 0); + REG_IP_WR(IP_SLOTCLK_ADDR, (REG_IP_RD(IP_SLOTCLK_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)samp << 31)); +} + +__INLINE uint8_t ip_slotclk_clkn_upd_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SLOTCLK_ADDR); + return ((localVal & ((uint32_t)0x40000000)) >> 30); +} + +__INLINE void ip_slotclk_clkn_upd_setf(uint8_t clknupd) +{ + ASSERT_ERR((((uint32_t)clknupd << 30) & ~((uint32_t)0x40000000)) == 0); + REG_IP_WR(IP_SLOTCLK_ADDR, (REG_IP_RD(IP_SLOTCLK_ADDR) & ~((uint32_t)0x40000000)) | ((uint32_t)clknupd << 30)); +} + +__INLINE uint32_t ip_slotclk_sclk_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_SLOTCLK_ADDR); + return ((localVal & ((uint32_t)0x0FFFFFFF)) >> 0); +} + +__INLINE void ip_slotclk_sclk_setf(uint32_t sclk) +{ + ASSERT_ERR((((uint32_t)sclk << 0) & ~((uint32_t)0x0FFFFFFF)) == 0); + REG_IP_WR(IP_SLOTCLK_ADDR, (REG_IP_RD(IP_SLOTCLK_ADDR) & ~((uint32_t)0x0FFFFFFF)) | ((uint32_t)sclk << 0)); +} + +/** + * @brief FINETIMECNT register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *  09:00              FINECNT   0x0
+ * 
+ */ +#define IP_FINETIMECNT_ADDR BASEBAND_REG_BASE +0xFC //0x508000FC +#define IP_FINETIMECNT_OFFSET 0x000000FC +#define IP_FINETIMECNT_INDEX 0x0000003F +#define IP_FINETIMECNT_RESET 0x00000000 + +__INLINE uint32_t ip_finetimecnt_get(void) +{ + return REG_IP_RD(IP_FINETIMECNT_ADDR); +} + +// field definitions +#define IP_FINECNT_MASK ((uint32_t)0x000003FF) +#define IP_FINECNT_LSB 0 +#define IP_FINECNT_WIDTH ((uint32_t)0x0000000A) + +#define IP_FINECNT_RST 0x0 + +__INLINE uint16_t ip_finetimecnt_finecnt_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_FINETIMECNT_ADDR); + ASSERT_ERR((localVal & ~((uint32_t)0x000003FF)) == 0); + return (localVal >> 0); +} + +/** + * @brief ACTSCHCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31            START_ACT   0
+ *  03:00            ENTRY_IDX   0x0
+ * 
+ */ +#define IP_ACTSCHCNTL_ADDR BASEBAND_REG_BASE +0x100 // 0x50800100 +#define IP_ACTSCHCNTL_OFFSET 0x00000100 +#define IP_ACTSCHCNTL_INDEX 0x00000040 +#define IP_ACTSCHCNTL_RESET 0x00000000 + +__INLINE uint32_t ip_actschcntl_get(void) +{ + return REG_IP_RD(IP_ACTSCHCNTL_ADDR); +} + +__INLINE void ip_actschcntl_set(uint32_t value) +{ + REG_IP_WR(IP_ACTSCHCNTL_ADDR, value); +} + +// field definitions +#define IP_START_ACT_BIT ((uint32_t)0x80000000) +#define IP_START_ACT_POS 31 +#define IP_ENTRY_IDX_MASK ((uint32_t)0x0000000F) +#define IP_ENTRY_IDX_LSB 0 +#define IP_ENTRY_IDX_WIDTH ((uint32_t)0x00000004) + +#define IP_START_ACT_RST 0x0 +#define IP_ENTRY_IDX_RST 0x0 + +__INLINE void ip_actschcntl_pack(uint8_t startact, uint8_t entryidx) +{ + ASSERT_ERR((((uint32_t)startact << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)entryidx << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_IP_WR(IP_ACTSCHCNTL_ADDR, ((uint32_t)startact << 31) | ((uint32_t)entryidx << 0)); +} + +__INLINE void ip_actschcntl_unpack(uint8_t* startact, uint8_t* entryidx) +{ + uint32_t localVal = REG_IP_RD(IP_ACTSCHCNTL_ADDR); + + *startact = (localVal & ((uint32_t)0x80000000)) >> 31; + *entryidx = (localVal & ((uint32_t)0x0000000F)) >> 0; +} + +__INLINE uint8_t ip_actschcntl_start_act_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTSCHCNTL_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ip_actschcntl_start_act_setf(uint8_t startact) +{ + ASSERT_ERR((((uint32_t)startact << 31) & ~((uint32_t)0x80000000)) == 0); + REG_IP_WR(IP_ACTSCHCNTL_ADDR, (REG_IP_RD(IP_ACTSCHCNTL_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)startact << 31)); +} + +__INLINE uint8_t ip_actschcntl_entry_idx_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_ACTSCHCNTL_ADDR); + return ((localVal & ((uint32_t)0x0000000F)) >> 0); +} + +__INLINE void ip_actschcntl_entry_idx_setf(uint8_t entryidx) +{ + ASSERT_ERR((((uint32_t)entryidx << 0) & ~((uint32_t)0x0000000F)) == 0); + REG_IP_WR(IP_ACTSCHCNTL_ADDR, (REG_IP_RD(IP_ACTSCHCNTL_ADDR) & ~((uint32_t)0x0000000F)) | ((uint32_t)entryidx << 0)); +} + +/** + * @brief DFANCNTL register definition + *
+ *   Bits           Field Name   Reset Value
+ *  -----   ------------------   -----------
+ *     31     BTRXPRIMIDCNTLEN   0
+ *  30:24        BTRXPRIMANTID   0x0
+ *     23     BTTXPRIMIDCNTLEN   0
+ *  22:16        BTTXPRIMANTID   0x0
+ *     15     LERXPRIMIDCNTLEN   0
+ *  14:08        LERXPRIMANTID   0x0
+ *     07     LETXPRIMIDCNTLEN   0
+ *  06:00        LETXPRIMANTID   0x0
+ * 
+ */ +#define IP_DFANCNTL_ADDR BASEBAND_REG_BASE +0x184 // 0x50800184 +#define IP_DFANCNTL_OFFSET 0x00000184 +#define IP_DFANCNTL_INDEX 0x00000061 +#define IP_DFANCNTL_RESET 0x00000000 + +__INLINE uint32_t ip_dfancntl_get(void) +{ + return REG_IP_RD(IP_DFANCNTL_ADDR); +} + +__INLINE void ip_dfancntl_set(uint32_t value) +{ + REG_IP_WR(IP_DFANCNTL_ADDR, value); +} + +// field definitions +#define IP_BTRXPRIMIDCNTLEN_BIT ((uint32_t)0x80000000) +#define IP_BTRXPRIMIDCNTLEN_POS 31 +#define IP_BTRXPRIMANTID_MASK ((uint32_t)0x7F000000) +#define IP_BTRXPRIMANTID_LSB 24 +#define IP_BTRXPRIMANTID_WIDTH ((uint32_t)0x00000007) +#define IP_BTTXPRIMIDCNTLEN_BIT ((uint32_t)0x00800000) +#define IP_BTTXPRIMIDCNTLEN_POS 23 +#define IP_BTTXPRIMANTID_MASK ((uint32_t)0x007F0000) +#define IP_BTTXPRIMANTID_LSB 16 +#define IP_BTTXPRIMANTID_WIDTH ((uint32_t)0x00000007) +#define IP_LERXPRIMIDCNTLEN_BIT ((uint32_t)0x00008000) +#define IP_LERXPRIMIDCNTLEN_POS 15 +#define IP_LERXPRIMANTID_MASK ((uint32_t)0x00007F00) +#define IP_LERXPRIMANTID_LSB 8 +#define IP_LERXPRIMANTID_WIDTH ((uint32_t)0x00000007) +#define IP_LETXPRIMIDCNTLEN_BIT ((uint32_t)0x00000080) +#define IP_LETXPRIMIDCNTLEN_POS 7 +#define IP_LETXPRIMANTID_MASK ((uint32_t)0x0000007F) +#define IP_LETXPRIMANTID_LSB 0 +#define IP_LETXPRIMANTID_WIDTH ((uint32_t)0x00000007) + +#define IP_BTRXPRIMIDCNTLEN_RST 0x0 +#define IP_BTRXPRIMANTID_RST 0x0 +#define IP_BTTXPRIMIDCNTLEN_RST 0x0 +#define IP_BTTXPRIMANTID_RST 0x0 +#define IP_LERXPRIMIDCNTLEN_RST 0x0 +#define IP_LERXPRIMANTID_RST 0x0 +#define IP_LETXPRIMIDCNTLEN_RST 0x0 +#define IP_LETXPRIMANTID_RST 0x0 + +__INLINE void ip_dfancntl_pack(uint8_t btrxprimidcntlen, uint8_t btrxprimantid, uint8_t bttxprimidcntlen, uint8_t bttxprimantid, uint8_t lerxprimidcntlen, uint8_t lerxprimantid, uint8_t letxprimidcntlen, uint8_t letxprimantid) +{ + ASSERT_ERR((((uint32_t)btrxprimidcntlen << 31) & ~((uint32_t)0x80000000)) == 0); + ASSERT_ERR((((uint32_t)btrxprimantid << 24) & ~((uint32_t)0x7F000000)) == 0); + ASSERT_ERR((((uint32_t)bttxprimidcntlen << 23) & ~((uint32_t)0x00800000)) == 0); + ASSERT_ERR((((uint32_t)bttxprimantid << 16) & ~((uint32_t)0x007F0000)) == 0); + ASSERT_ERR((((uint32_t)lerxprimidcntlen << 15) & ~((uint32_t)0x00008000)) == 0); + ASSERT_ERR((((uint32_t)lerxprimantid << 8) & ~((uint32_t)0x00007F00)) == 0); + ASSERT_ERR((((uint32_t)letxprimidcntlen << 7) & ~((uint32_t)0x00000080)) == 0); + ASSERT_ERR((((uint32_t)letxprimantid << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_IP_WR(IP_DFANCNTL_ADDR, ((uint32_t)btrxprimidcntlen << 31) | ((uint32_t)btrxprimantid << 24) | ((uint32_t)bttxprimidcntlen << 23) | ((uint32_t)bttxprimantid << 16) | ((uint32_t)lerxprimidcntlen << 15) | ((uint32_t)lerxprimantid << 8) | ((uint32_t)letxprimidcntlen << 7) | ((uint32_t)letxprimantid << 0)); +} + +__INLINE void ip_dfancntl_unpack(uint8_t* btrxprimidcntlen, uint8_t* btrxprimantid, uint8_t* bttxprimidcntlen, uint8_t* bttxprimantid, uint8_t* lerxprimidcntlen, uint8_t* lerxprimantid, uint8_t* letxprimidcntlen, uint8_t* letxprimantid) +{ + uint32_t localVal = REG_IP_RD(IP_DFANCNTL_ADDR); + + *btrxprimidcntlen = (localVal & ((uint32_t)0x80000000)) >> 31; + *btrxprimantid = (localVal & ((uint32_t)0x7F000000)) >> 24; + *bttxprimidcntlen = (localVal & ((uint32_t)0x00800000)) >> 23; + *bttxprimantid = (localVal & ((uint32_t)0x007F0000)) >> 16; + *lerxprimidcntlen = (localVal & ((uint32_t)0x00008000)) >> 15; + *lerxprimantid = (localVal & ((uint32_t)0x00007F00)) >> 8; + *letxprimidcntlen = (localVal & ((uint32_t)0x00000080)) >> 7; + *letxprimantid = (localVal & ((uint32_t)0x0000007F)) >> 0; +} + +__INLINE uint8_t ip_dfancntl_btrxprimidcntlen_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DFANCNTL_ADDR); + return ((localVal & ((uint32_t)0x80000000)) >> 31); +} + +__INLINE void ip_dfancntl_btrxprimidcntlen_setf(uint8_t btrxprimidcntlen) +{ + ASSERT_ERR((((uint32_t)btrxprimidcntlen << 31) & ~((uint32_t)0x80000000)) == 0); + REG_IP_WR(IP_DFANCNTL_ADDR, (REG_IP_RD(IP_DFANCNTL_ADDR) & ~((uint32_t)0x80000000)) | ((uint32_t)btrxprimidcntlen << 31)); +} + +__INLINE uint8_t ip_dfancntl_btrxprimantid_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DFANCNTL_ADDR); + return ((localVal & ((uint32_t)0x7F000000)) >> 24); +} + +__INLINE void ip_dfancntl_btrxprimantid_setf(uint8_t btrxprimantid) +{ + ASSERT_ERR((((uint32_t)btrxprimantid << 24) & ~((uint32_t)0x7F000000)) == 0); + REG_IP_WR(IP_DFANCNTL_ADDR, (REG_IP_RD(IP_DFANCNTL_ADDR) & ~((uint32_t)0x7F000000)) | ((uint32_t)btrxprimantid << 24)); +} + +__INLINE uint8_t ip_dfancntl_bttxprimidcntlen_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DFANCNTL_ADDR); + return ((localVal & ((uint32_t)0x00800000)) >> 23); +} + +__INLINE void ip_dfancntl_bttxprimidcntlen_setf(uint8_t bttxprimidcntlen) +{ + ASSERT_ERR((((uint32_t)bttxprimidcntlen << 23) & ~((uint32_t)0x00800000)) == 0); + REG_IP_WR(IP_DFANCNTL_ADDR, (REG_IP_RD(IP_DFANCNTL_ADDR) & ~((uint32_t)0x00800000)) | ((uint32_t)bttxprimidcntlen << 23)); +} + +__INLINE uint8_t ip_dfancntl_bttxprimantid_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DFANCNTL_ADDR); + return ((localVal & ((uint32_t)0x007F0000)) >> 16); +} + +__INLINE void ip_dfancntl_bttxprimantid_setf(uint8_t bttxprimantid) +{ + ASSERT_ERR((((uint32_t)bttxprimantid << 16) & ~((uint32_t)0x007F0000)) == 0); + REG_IP_WR(IP_DFANCNTL_ADDR, (REG_IP_RD(IP_DFANCNTL_ADDR) & ~((uint32_t)0x007F0000)) | ((uint32_t)bttxprimantid << 16)); +} + +__INLINE uint8_t ip_dfancntl_lerxprimidcntlen_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DFANCNTL_ADDR); + return ((localVal & ((uint32_t)0x00008000)) >> 15); +} + +__INLINE void ip_dfancntl_lerxprimidcntlen_setf(uint8_t lerxprimidcntlen) +{ + ASSERT_ERR((((uint32_t)lerxprimidcntlen << 15) & ~((uint32_t)0x00008000)) == 0); + REG_IP_WR(IP_DFANCNTL_ADDR, (REG_IP_RD(IP_DFANCNTL_ADDR) & ~((uint32_t)0x00008000)) | ((uint32_t)lerxprimidcntlen << 15)); +} + +__INLINE uint8_t ip_dfancntl_lerxprimantid_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DFANCNTL_ADDR); + return ((localVal & ((uint32_t)0x00007F00)) >> 8); +} + +__INLINE void ip_dfancntl_lerxprimantid_setf(uint8_t lerxprimantid) +{ + ASSERT_ERR((((uint32_t)lerxprimantid << 8) & ~((uint32_t)0x00007F00)) == 0); + REG_IP_WR(IP_DFANCNTL_ADDR, (REG_IP_RD(IP_DFANCNTL_ADDR) & ~((uint32_t)0x00007F00)) | ((uint32_t)lerxprimantid << 8)); +} + +__INLINE uint8_t ip_dfancntl_letxprimidcntlen_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DFANCNTL_ADDR); + return ((localVal & ((uint32_t)0x00000080)) >> 7); +} + +__INLINE void ip_dfancntl_letxprimidcntlen_setf(uint8_t letxprimidcntlen) +{ + ASSERT_ERR((((uint32_t)letxprimidcntlen << 7) & ~((uint32_t)0x00000080)) == 0); + REG_IP_WR(IP_DFANCNTL_ADDR, (REG_IP_RD(IP_DFANCNTL_ADDR) & ~((uint32_t)0x00000080)) | ((uint32_t)letxprimidcntlen << 7)); +} + +__INLINE uint8_t ip_dfancntl_letxprimantid_getf(void) +{ + uint32_t localVal = REG_IP_RD(IP_DFANCNTL_ADDR); + return ((localVal & ((uint32_t)0x0000007F)) >> 0); +} + +__INLINE void ip_dfancntl_letxprimantid_setf(uint8_t letxprimantid) +{ + ASSERT_ERR((((uint32_t)letxprimantid << 0) & ~((uint32_t)0x0000007F)) == 0); + REG_IP_WR(IP_DFANCNTL_ADDR, (REG_IP_RD(IP_DFANCNTL_ADDR) & ~((uint32_t)0x0000007F)) | ((uint32_t)letxprimantid << 0)); +} + + +#endif // _REG_IPCORE_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/rf.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/rf.h new file mode 100644 index 0000000..26b3229 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api/rf.h @@ -0,0 +1,53 @@ +/** + **************************************************************************************** + * + * @file rf.h + * + * @brief Common header file for all radios. + * + * Copyright (C) RivieraWaves 2009-2015 + * + * + **************************************************************************************** + */ + +#ifndef RF_H_ +#define RF_H_ + +/** + **************************************************************************************** + * @addtogroup RF + * @ingroup DRIVERS + * @brief Common definitions for radio modules. + * + * This module declares the functions and constants that have to be defined for all RF. + * + * @{ + **************************************************************************************** + */ + + +/* + * FUNCTION DECLARATIONS + **************************************************************************************** + */ + +struct rwip_rf_api; // forward declaration to avoid including rw.h + +/** + ***************************************************************************************** + * @brief Initialization of RF. + * + * This function initializes the RF and fills the structure containing the function + * pointers and parameters required by the RW BT stack. + * + * @param[out] api Pointer to the BT RF API structure + * + ***************************************************************************************** + */ +void rf_init(struct rwip_rf_api *api); +void llhwc_phy_prerx(void); + +/// @} RF + +#endif // RF_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/ble_stack_common.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/ble_stack_common.h new file mode 100644 index 0000000..9ec01da --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/ble_stack_common.h @@ -0,0 +1,889 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ble_stack_common.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __BLE_STACK_COMMON_H_ +#define __BLE_STACK_COMMON_H_ + +#include "rwip.h" +#include "global_var.h" +#include "Typedefine.h" +#include "co_bt_defines.h" +#include "prf.h" +#include "rwip_int.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Configer define ------------------------------------------------------------*/ +#ifndef _PATCH_LATENCY_ +#define _PATCH_LATENCY_ 0 +#endif +#ifndef _PATCH_ENC_RESPONDSE_ +#define _PATCH_ENC_RESPONDSE_ 0 +#endif + +#if ((_PATCH_LATENCY_) || (_PATCH_ENC_RESPONDSE_)) +#define _PATCH_LLD_COM_ 1 +#else +#define _PATCH_LLD_COM_ 0 +#endif + +#ifndef _PATCH_KE_TIMER_SET_ +#define _PATCH_KE_TIMER_SET_ 1 +#endif + +#ifndef _PATCH_KE_MSG_SET_ +#define _PATCH_KE_MSG_SET_ 0 +#endif + +#ifndef _PATCH_MULTI_CON_ +#define _PATCH_MULTI_CON_ 1 +#endif + +#ifndef _3_CONN_ +#define _3_CONN_ 1 +#endif + +/* Private define ------------------------------------------------------------*/ +#define PATCH ((PATCH_Module*)(PATCH_BASE+0x14)) +#define RCC_AHB_PERIPH_PATCH ((uint32_t)0x00000020) + +#define PATCH_REPLACE_ADDR_0 0x00021dd4 //lld_con_start +#define PATCH_REPLACE_ADDR_1 0x00021218 //lld_con_llcp_tx +#define PATCH_REPLACE_ADDR_2 0x00020aec //lld_con_data_len_update +#define PATCH_REPLACE_ADDR_3 0x00020a38 //lld_con_data_flow_set +#define PATCH_REPLACE_ADDR_4 0x000180bC //ke tiemr +#define PATCH_REPLACE_ADDR_5 0x000180C0 //ke tiemr +#define PATCH_REPLACE_ADDR_6 0x000178AC //ke msg +#define PATCH_REPLACE_ADDR_7 0x0001db34 //MULTI_CON +#define PATCH_REPLACE_ADDR_8 0x0001db40 //MULTI_CON +#define PATCH_REPLACE_ADDR_9 0x000261C0 //3_CONN + +#define PATCH_0_FUNC_OFFSET 0x13d1 +#define PATCH_1_FUNC_OFFSET 0x1331 +#define PATCH_2_FUNC_OFFSET 0x12bd +#define PATCH_3_FUNC_OFFSET 0x1219 + +#define np_lld_con_frm_cbk 0x479 +#define np_lld_con_evt_canceled_cbk 0x1a1 +#define np_lld_con_evt_start_cbk 0x1e1 + + + + +#define PATCH_ROM_ADDR_0 (PATCH_REPLACE_ADDR_0 & 0xFFFFFFC0) +#define PATCH_ROM_ADDR_1 (PATCH_REPLACE_ADDR_1 & 0xFFFFFFC0) +#define PATCH_ROM_ADDR_2 (PATCH_REPLACE_ADDR_2 & 0xFFFFFFC0) +#define PATCH_ROM_ADDR_3 (PATCH_REPLACE_ADDR_3 & 0xFFFFFFC0) +#define PATCH_ROM_ADDR_4 (PATCH_REPLACE_ADDR_4 & 0xFFFFFFC0) +#define PATCH_ROM_ADDR_5 (PATCH_REPLACE_ADDR_5 & 0xFFFFFFC0) +#define PATCH_ROM_ADDR_6 (PATCH_REPLACE_ADDR_6 & 0xFFFFFFC0) +#define PATCH_ROM_ADDR_7 (PATCH_REPLACE_ADDR_7 & 0xFFFFFFC0) +#define PATCH_ROM_ADDR_8 (PATCH_REPLACE_ADDR_8 & 0xFFFFFFC0) +#define PATCH_ROM_ADDR_9 (PATCH_REPLACE_ADDR_9 & 0xFFFFFFC0) + +#define PATCH_RAM_ADDR_OFFSET_0 ((PATCH_REPLACE_ADDR_0 & 0x3F) + 0x4) +#define PATCH_RAM_ADDR_OFFSET_1 ((PATCH_REPLACE_ADDR_1 & 0x3F) + 0x4) +#define PATCH_RAM_ADDR_OFFSET_2 ((PATCH_REPLACE_ADDR_2 & 0x3F) + 0xC) //special +#define PATCH_RAM_ADDR_OFFSET_3 ((PATCH_REPLACE_ADDR_3 & 0x3F) + 0x4) +#define PATCH_RAM_ADDR_OFFSET_4 ((PATCH_REPLACE_ADDR_4 & 0x3F) + 4) +#define PATCH_RAM_ADDR_OFFSET_5 ((PATCH_REPLACE_ADDR_5 & 0x3F) + 0) +#define PATCH_RAM_ADDR_OFFSET_6 ((PATCH_REPLACE_ADDR_6 & 0x3F) + 4) +#define PATCH_RAM_ADDR_OFFSET_8 ((PATCH_REPLACE_ADDR_8 & 0x3F) + 0) + +/* Public typedef -----------------------------------------------------------*/ +typedef struct +{ + __IO uint32_t RomAddrx:12; + __IO uint32_t PatchAddrx:10; + uint32_t Reserved:10; + +} PATCHDATAx_Type; + +typedef struct +{ + uint32_t PATCHEN; + PATCHDATAx_Type PATCHDATAx[16]; + +} PATCH_Module; +/* Public define ------------------------------------------------------------*/ +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + + +#if (_PATCH_LLD_COM_) + +#define np_lld_con_frm_cbk_addr 0x20000D00 +#define np_lld_con_evt_canceled_cbk_addr 0x20000D04 +#define np_lld_con_evt_start_cbk_addr 0x20000D08 + +static __align(64) unsigned char patch_0_Array[0x40] = +{ + 0xff, 0xff, 0xff, 0x07, 0xff, 0x7f, 0x00, 0x00, 0xcc, 0x03, 0x00, 0x20, 0x71, 0x02, 0x00, 0x00, + 0x91, 0xd7, 0x02, 0x00, 0x00, 0x4a, 0x10, 0x47, 0x11, 0x11, 0x11, 0x11, 0x85, 0x00, 0x70, 0x59, + 0x0c, 0x27, 0x0c, 0x46, 0x00, 0x28, 0x7d, 0xd1, 0x00, 0x21, 0x98, 0x20, 0xf5, 0xf7, 0x1e, 0xfe, + 0x70, 0x51, 0x05, 0x00, 0x76, 0xd0, 0x00, 0x20, 0x00, 0x90, 0x03, 0xf0, 0x0f, 0xfe, 0x05, 0x90 +}; +static __align(64) unsigned char patch_1_Array[0x40] = +{ + 0x00, 0x2c, 0xf2, 0xda, 0x00, 0x20, 0x28, 0x60, 0x68, 0x60, 0xa8, 0x60, 0xe8, 0x60, 0x70, 0xbd, + 0x70, 0x47, 0x00, 0x00, 0x10, 0x04, 0x00, 0x20, 0x00, 0x4a, 0x10, 0x47, 0x11, 0x11, 0x11, 0x11, + 0x10, 0x86, 0x01, 0x22, 0x82, 0xf3, 0x10, 0x88, 0x01, 0x9a, 0x24, 0x4b, 0x95, 0x00, 0x5a, 0x59, + 0x00, 0x2a, 0x3f, 0xd0, 0x17, 0x46, 0x80, 0x37, 0x51, 0x62, 0x78, 0x88, 0x08, 0x21, 0x08, 0x43 +}; +static __align(64) unsigned char patch_2_Array[0x40] = +{ + 0xa2, 0x64, 0x43, 0x8f, 0x52, 0x1b, 0x5b, 0x1e, 0x12, 0x01, 0x12, 0x09, 0x43, 0x87, 0x8a, 0x42, + 0xf2, 0xd8, 0x00, 0x22, 0x29, 0x46, 0x01, 0x98, 0x00, 0xf0, 0xd6, 0xff, 0x00, 0x20, 0x86, 0xf3, + 0x10, 0x88, 0x03, 0xb0, 0xf0, 0xbd, 0x00, 0x00, 0x10, 0x04, 0x00, 0x20, 0x38, 0xb5, 0x04, 0x9c, + 0x00, 0x94, 0x01, 0x4c, 0xa0, 0x47, 0x38, 0xbd, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x4c, 0xbd, 0x00 +}; + +static __align(64) unsigned char patch_3_Array[0x40] = +{ + 0x01, 0x22, 0x82, 0xf3, 0x10, 0x88, 0x09, 0x4d, 0x82, 0x00, 0xaa, 0x58, 0x00, 0x2a, 0x09, 0xd0, + 0x70, 0x22, 0x50, 0x43, 0x06, 0x4a, 0x80, 0x18, 0x40, 0x8d, 0x06, 0x4a, 0xc0, 0xb2, 0x52, 0x69, + 0x90, 0x47, 0x03, 0x46, 0x84, 0xf3, 0x10, 0x88, 0x18, 0x46, 0x70, 0xbd, 0x10, 0x04, 0x00, 0x20, + 0x40, 0xc1, 0x02, 0x40, 0x74, 0x02, 0x00, 0x20, 0x00, 0x4a, 0x10, 0x47, 0x11, 0x11, 0x11, 0x11 +}; + + +#define ramcode_array_len 0x17b0 +#define ramcode_array_crc 0x5961 +static __align(0x100) unsigned char lld_con_Array[] ={ +0x40,0xba,0x70,0x47,0xc0,0xba,0x70,0x47,0x30,0xb5,0x0b,0x46,0x01,0x46,0x00,0x20, +0x20,0x22,0x01,0x24,0x09,0xe0,0x0d,0x46,0xd5,0x40,0x9d,0x42,0x05,0xd3,0x1d,0x46, +0x95,0x40,0x49,0x1b,0x25,0x46,0x95,0x40,0x40,0x19,0x15,0x46,0x52,0x1e,0x00,0x2d, +0xf1,0xdc,0x30,0xbd,0xd2,0xb2,0x01,0xe0,0x02,0x70,0x40,0x1c,0x49,0x1e,0xfb,0xd2, +0x70,0x47,0x00,0x22,0xf6,0xe7,0x10,0xb5,0x13,0x46,0x0a,0x46,0x04,0x46,0x19,0x46, +0xff,0xf7,0xf0,0xff,0x20,0x46,0x10,0xbd,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd, +0x1d,0x5a,0x02,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x19,0xc5,0x02,0x00, +0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x37,0x7e,0x00,0x00,0x03,0xb4,0x01,0x48, +0x01,0x90,0x01,0xbd,0x35,0xc8,0x02,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd, +0x79,0x7a,0x00,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0xaf,0x7f,0x00,0x00, +0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x0d,0x78,0x00,0x00,0x03,0xb4,0x01,0x48, +0x01,0x90,0x01,0xbd,0xd9,0x7b,0x01,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd, +0xc5,0xbe,0x02,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x05,0x06,0x02,0x00, +0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x1d,0x5d,0x02,0x00,0x03,0xb4,0x01,0x48, +0x01,0x90,0x01,0xbd,0x39,0x7b,0x01,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd, +0xb1,0x7b,0x01,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x15,0x05,0x02,0x00, +0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x49,0x5d,0x02,0x00,0x03,0xb4,0x01,0x48, +0x01,0x90,0x01,0xbd,0xc1,0x12,0x02,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd, +0x4d,0xae,0x02,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x19,0xbc,0x02,0x00, +0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x2d,0x7a,0x01,0x00,0x70,0xb5,0x13,0x4b, +0x80,0x00,0x1c,0x58,0x12,0x48,0x80,0x34,0x00,0x78,0x13,0x4b,0x10,0x1a,0x11,0x4a, +0xc0,0x1e,0x50,0x43,0x62,0x7c,0x40,0x08,0x52,0x00,0x9a,0x5a,0x25,0x79,0x80,0x1a, +0xe2,0x88,0x96,0x38,0x90,0x42,0x00,0xd3,0x10,0x46,0x49,0x00,0x5a,0x5a,0x80,0x1a, +0xa2,0x78,0x53,0x06,0x09,0x4a,0x51,0x5a,0x01,0xd5,0x8a,0x00,0x80,0x1a,0xff,0xf7, +0x43,0xff,0x85,0x42,0x00,0xd3,0x05,0x46,0xa5,0x72,0x70,0xbd,0x10,0x04,0x00,0x20, +0xd8,0x00,0x00,0x20,0x71,0x02,0x00,0x00,0xe0,0xe4,0x02,0x00,0xd8,0xe4,0x02,0x00, +0x00,0x28,0x1a,0xd0,0x10,0xb5,0x04,0x46,0xff,0xf7,0x56,0xff,0x01,0x46,0x62,0x6e, +0xa0,0x6c,0x80,0x18,0x00,0x01,0x00,0x09,0xa0,0x64,0x20,0x46,0x40,0x30,0x42,0x8f, +0x52,0x1c,0x42,0x87,0x05,0x4a,0xa0,0x7d,0x52,0x7a,0x80,0x18,0xa0,0x75,0x80,0x34, +0x20,0x7b,0x01,0x22,0x00,0xf0,0xae,0xfc,0x10,0xbd,0x70,0x47,0x91,0xd7,0x02,0x00, +0x00,0x28,0x7d,0xd0,0xf0,0xb5,0x05,0x46,0x06,0x46,0x80,0x35,0x8b,0xb0,0x28,0x7b, +0x00,0x21,0x09,0x91,0x08,0x90,0xa9,0x78,0xc9,0x06,0x04,0xd4,0x71,0x6a,0x00,0x29, +0x01,0xd0,0x00,0xf0,0x75,0xfe,0x34,0x46,0x40,0x34,0x20,0x8f,0x61,0x8f,0x40,0x18, +0x20,0x87,0x08,0x9f,0x70,0x21,0x4f,0x43,0x57,0x49,0x79,0x18,0x00,0x91,0x08,0x86, +0x68,0x88,0xff,0x21,0x01,0x31,0x88,0x43,0x68,0x80,0x80,0x05,0x15,0xd5,0x60,0x8f, +0xe9,0x7a,0x48,0x43,0xe1,0x8f,0x40,0x18,0x25,0x21,0xff,0xf7,0xe5,0xfe,0x08,0xb2, +0x00,0x28,0x01,0xda,0x25,0x30,0x00,0xb2,0x4c,0x4a,0xc1,0xb2,0xbb,0x18,0x1a,0x8d, +0x92,0x09,0x92,0x01,0x0a,0x43,0x1a,0x85,0xe0,0x87,0x00,0x20,0x60,0x87,0xa8,0x78, +0xc0,0x07,0x19,0xd0,0xf0,0x6c,0x46,0x49,0x40,0x1c,0x40,0x08,0x88,0x42,0x0b,0xd9, +0x44,0x49,0x4a,0x1e,0x80,0x18,0xff,0xf7,0xc7,0xfe,0x01,0x21,0xc9,0x03,0x01,0x43, +0x3e,0x48,0x38,0x18,0xc1,0x85,0x07,0xe0,0xc1,0x03,0x01,0x20,0xc0,0x03,0x08,0x18, +0x3a,0x49,0x00,0x0c,0x79,0x18,0xc8,0x85,0xa1,0x79,0x00,0x29,0x3f,0xd0,0x20,0x8f, +0xa2,0x88,0x80,0x1a,0x38,0x4a,0x80,0xb2,0x90,0x42,0x38,0xd2,0x30,0x46,0x20,0x30, +0x02,0x29,0x18,0xd1,0x31,0x46,0x34,0x31,0x4a,0x78,0x09,0x78,0x12,0x02,0x0a,0x43, +0x00,0x99,0x4a,0x80,0x31,0x46,0x36,0x31,0x4a,0x78,0x0b,0x78,0x11,0x02,0x00,0x9a, +0x19,0x43,0x91,0x80,0x00,0x99,0x02,0x7e,0xcb,0x88,0x5b,0x09,0x5b,0x01,0x00,0xe0, +0x49,0xe0,0x13,0x43,0xcb,0x80,0xa1,0x79,0x03,0x29,0x10,0xd1,0x23,0x49,0x43,0x7d, +0x79,0x18,0xca,0x8a,0x9c,0x46,0x0c,0x23,0x9a,0x43,0x63,0x46,0x9b,0x00,0x1a,0x43, +0xca,0x82,0x00,0x7d,0xca,0x8a,0x92,0x08,0x92,0x00,0x02,0x43,0xca,0x82,0xa0,0x79, +0x01,0x28,0x02,0xd1,0xe0,0x78,0x00,0x28,0x01,0xd0,0x01,0x20,0x09,0x90,0x1b,0x48, +0x01,0x68,0x00,0x29,0x01,0xd1,0x1a,0x49,0x01,0x60,0x00,0x91,0x70,0x68,0x01,0x90, +0xb0,0x68,0x02,0x90,0x69,0x46,0x08,0x98,0x08,0x76,0x08,0x98,0x04,0x90,0x30,0x69, +0x03,0x90,0xb0,0x7d,0x08,0x75,0x00,0x20,0x48,0x75,0x88,0x75,0x0f,0x22,0xca,0x75, +0x88,0x76,0x08,0x77,0x48,0x76,0x68,0x46,0xff,0xf7,0x84,0xfe,0x68,0x7b,0x02,0x28, +0x01,0xd0,0x01,0x20,0x68,0x73,0x09,0x98,0x00,0x28,0x02,0xd0,0x28,0x7b,0x00,0xf0, +0xfb,0xfe,0x0b,0xb0,0xf0,0xbd,0x70,0x47,0x80,0xc1,0x02,0x40,0x40,0xc1,0x02,0x40, +0xff,0x3f,0x00,0x00,0x71,0x02,0x00,0x00,0xff,0x7f,0x00,0x00,0x00,0x0d,0x00,0x20, +0x79,0x84,0x00,0x20,0xf0,0xb5,0x06,0x46,0x30,0x49,0x80,0x00,0x0d,0x58,0x83,0xb0, +0x2c,0x46,0x80,0x34,0xa0,0x7a,0x27,0x46,0x00,0x1d,0xa1,0x7c,0xc0,0xb2,0xff,0xf7, +0x5f,0xfe,0x00,0x90,0x2a,0x4a,0x70,0x00,0x10,0x5c,0x61,0x7c,0x00,0x1d,0xc0,0xb2, +0xff,0xf7,0x56,0xfe,0x21,0x89,0x88,0x42,0x00,0xd3,0x08,0x46,0x00,0x99,0x08,0x18, +0xe7,0x21,0x89,0x00,0x01,0x90,0x40,0x18,0x22,0x49,0xff,0xf7,0x15,0xfe,0x22,0x4a, +0x69,0x6e,0x12,0x78,0x8a,0x1a,0x92,0x1e,0x54,0x08,0x84,0x42,0x00,0xd9,0x24,0x1a, +0xb8,0x78,0xc0,0x07,0x19,0xd0,0x1d,0x48,0x02,0x89,0x28,0x46,0x40,0x30,0x00,0x90, +0xc0,0x8e,0x10,0x18,0x48,0x43,0x19,0x21,0x89,0x01,0xff,0xf7,0xfd,0xfd,0x15,0x49, +0x10,0x30,0x4a,0x1e,0x80,0x18,0xff,0xf7,0xf7,0xfd,0x24,0x1a,0x00,0x98,0x80,0x8e, +0x00,0x28,0x02,0xd0,0x84,0x42,0x00,0xd3,0x04,0x46,0x70,0x20,0x46,0x43,0x10,0x48, +0x30,0x18,0x04,0x80,0x0f,0x48,0x30,0x18,0xc4,0x87,0x01,0x98,0x55,0x21,0x40,0x00, +0xc9,0x00,0x40,0x18,0xe8,0x65,0x28,0x61,0x00,0x21,0x00,0x91,0x83,0xb2,0x39,0x7b, +0x04,0x20,0x6a,0x6e,0xff,0xf7,0x12,0xfe,0x03,0xb0,0xf0,0xbd,0x10,0x04,0x00,0x20, +0xf8,0x0c,0x00,0x20,0x71,0x02,0x00,0x00,0xd8,0x00,0x00,0x20,0xcc,0x03,0x00,0x20, +0x80,0xc1,0x02,0x40,0x40,0xc1,0x02,0x40,0xf0,0xb5,0x0b,0x06,0x9b,0x0d,0x6e,0x4c, +0x83,0xb0,0x05,0x2a,0x0d,0xd2,0x15,0x00,0x7d,0x44,0x2d,0x79,0x6d,0x19,0xaf,0x44, +0x02,0x0a,0x12,0x1c,0xa3,0x00,0xcb,0xb2,0x01,0x46,0x00,0x22,0x18,0x46,0x00,0xf0, +0xd9,0xf8,0x03,0xb0,0xf0,0xbd,0xcb,0xb2,0x01,0x46,0x01,0x22,0x18,0x46,0x00,0xf0, +0xd1,0xf8,0x03,0xb0,0xf0,0xbd,0xe3,0x58,0xca,0xb2,0x00,0x2b,0xf9,0xd0,0x01,0x46, +0x10,0x46,0x00,0xf0,0x1f,0xf9,0x03,0xb0,0xf0,0xbd,0xc8,0xb2,0x00,0x90,0xe6,0x58, +0x00,0x2e,0xf8,0xd0,0x34,0x46,0x01,0x46,0x80,0x34,0x20,0x7b,0x37,0x46,0xc2,0x00, +0x10,0x1a,0xa2,0x7b,0x80,0x18,0x28,0x37,0x02,0x97,0xc0,0xb2,0x0f,0x02,0x51,0xe0, +0x48,0x88,0x82,0x07,0x88,0x88,0x92,0x0f,0x01,0x2a,0x09,0xd0,0x02,0x2a,0x07,0xd0, +0x03,0x2a,0x29,0xd1,0xff,0xf7,0xc0,0xfd,0x79,0x1c,0xff,0x22,0x4b,0x48,0x21,0xe0, +0x49,0x88,0x09,0x0a,0x04,0x29,0x04,0xd9,0xa2,0x78,0x52,0x06,0x01,0xd5,0x09,0x1f, +0x89,0xb2,0x00,0x29,0x18,0xd0,0xb5,0x6a,0x40,0x18,0xea,0x88,0xa9,0x88,0x92,0x05, +0x92,0x0d,0x89,0x18,0x88,0x42,0x0f,0xd3,0x02,0x98,0xff,0xf7,0xab,0xfd,0x30,0x6b, +0xa8,0x42,0x01,0xd1,0x00,0x20,0x30,0x63,0xa8,0x88,0xff,0xf7,0xa9,0xfd,0x79,0x1c, +0xff,0x22,0x3b,0x48,0xff,0xf7,0xaa,0xfd,0x3a,0x48,0x01,0x78,0x1c,0x20,0x41,0x43, +0x39,0x48,0x08,0x18,0x81,0x08,0x01,0x98,0x89,0x00,0x09,0x18,0x37,0x48,0x08,0x18, +0x41,0x88,0x10,0x22,0x91,0x43,0x41,0x80,0x20,0x7c,0x02,0x21,0x40,0x1e,0x20,0x74, +0xa0,0x7b,0x40,0x1c,0xff,0xf7,0x40,0xfd,0xa1,0x73,0x20,0x7b,0xc2,0x00,0x10,0x1a, +0x40,0x18,0xc0,0xb2,0x21,0x7c,0x00,0x29,0x0f,0xd0,0x2a,0x4a,0x1c,0x23,0x11,0x78, +0x00,0x01,0x59,0x43,0x28,0x4b,0x01,0x90,0xc9,0x18,0x89,0x08,0x89,0x00,0x09,0x18, +0x26,0x48,0x09,0x18,0x0d,0x88,0xed,0x0b,0x9a,0xd1,0x61,0x88,0x08,0x20,0x81,0x43, +0x20,0x7c,0x00,0x28,0x00,0xd0,0x01,0x20,0xc0,0x00,0x01,0x43,0x61,0x80,0x00,0x98, +0x00,0xf0,0x8e,0xfc,0x03,0xb0,0xf0,0xbd,0xe4,0x58,0xcd,0xb2,0x00,0x2c,0xf9,0xd0, +0xff,0xf7,0x3a,0xfd,0x06,0x46,0x01,0x21,0x20,0x46,0xff,0xf7,0x65,0xfd,0x20,0x46, +0x80,0x30,0x01,0x46,0x40,0x7b,0x02,0x28,0x16,0xd0,0xa2,0x6c,0x60,0x6e,0x10,0x18, +0x02,0x01,0x12,0x09,0x20,0x46,0x40,0x30,0xa2,0x64,0x42,0x8f,0x52,0x1c,0x42,0x87, +0x0f,0x4a,0xa0,0x7d,0x52,0x7a,0x80,0x18,0xa0,0x75,0x08,0x7b,0x01,0x22,0x31,0x46, +0x00,0xf0,0x88,0xfa,0x03,0xb0,0xf0,0xbd,0x16,0x22,0x01,0x21,0x28,0x46,0xff,0xf7, +0x49,0xfd,0x03,0xb0,0xf0,0xbd,0x00,0x00,0x10,0x04,0x00,0x20,0x0d,0x02,0x00,0x00, +0x0f,0x02,0x00,0x00,0x03,0x01,0x00,0x20,0x8b,0x05,0x00,0x00,0x00,0xc0,0x02,0x40, +0x91,0xd7,0x02,0x00,0xf8,0xb5,0x07,0x46,0x81,0x00,0x28,0x48,0x16,0x46,0x44,0x58, +0x00,0x2c,0x22,0xd0,0x01,0x21,0x20,0x46,0xff,0xf7,0x26,0xfd,0x25,0x46,0x80,0x35, +0x68,0x7b,0x02,0x28,0x0f,0xd0,0xff,0xf7,0xef,0xfc,0x01,0x46,0x6a,0x88,0x04,0x20, +0x93,0x07,0x13,0xd5,0x53,0x07,0x11,0xd4,0x12,0x07,0x0f,0xd4,0x46,0x22,0x12,0x5d, +0x01,0x2a,0x0b,0xd0,0x0b,0xe0,0xa8,0x78,0x00,0x06,0x01,0xd5,0x3d,0x22,0x00,0xe0, +0x16,0x22,0x01,0x21,0x38,0x46,0xff,0xf7,0x0d,0xfd,0xf8,0xbd,0x05,0x20,0x63,0x6e, +0xa2,0x6c,0xd2,0x18,0x12,0x01,0x12,0x09,0xa2,0x64,0x22,0x46,0x40,0x32,0x53,0x8f, +0x5b,0x1c,0x53,0x87,0x0e,0x4a,0x00,0x2e,0x05,0xd0,0x40,0x00,0x80,0x18,0xa3,0x7d, +0x40,0x78,0x18,0x18,0x01,0xe0,0x40,0x00,0x10,0x5c,0xa0,0x75,0x68,0x88,0x22,0x46, +0xc0,0x05,0x03,0xd5,0x20,0x6d,0x92,0x6d,0x90,0x42,0x01,0xd0,0x01,0x22,0x00,0xe0, +0x00,0x22,0x38,0x46,0x00,0xf0,0x1e,0xfa,0xf8,0xbd,0x00,0x00,0x10,0x04,0x00,0x20, +0x91,0xd7,0x02,0x00,0xf3,0xb5,0x8d,0xb0,0x0d,0x98,0xf8,0x49,0x80,0x00,0x0c,0x58, +0x04,0x26,0x25,0x46,0x80,0x35,0x68,0x88,0x30,0x43,0x68,0x80,0x0d,0x98,0xff,0xf7, +0xd7,0xfc,0x00,0x28,0x7b,0xd0,0xf2,0x48,0x0c,0x90,0x0d,0x98,0x27,0x46,0x00,0x02, +0x04,0x90,0xf0,0x48,0x40,0x37,0x0b,0x90,0x0c,0x98,0x1c,0x21,0x00,0x7b,0x48,0x43, +0xed,0x49,0x40,0x18,0x03,0x90,0x41,0x89,0x06,0x91,0x81,0x89,0x05,0x91,0x89,0x07, +0x89,0x0f,0x00,0x91,0xc1,0x89,0xca,0xb2,0x89,0x04,0x89,0x0e,0x02,0x91,0x00,0x21, +0x09,0x92,0x01,0x91,0x0e,0x46,0x07,0x91,0x61,0x6d,0x08,0x91,0x06,0x99,0xc9,0x07, +0x7e,0xd1,0x69,0x88,0xca,0x07,0x04,0xd0,0x42,0x8a,0x00,0x8a,0x16,0x04,0x06,0x43, +0x26,0x65,0xc8,0x05,0x75,0xd4,0xff,0x20,0x01,0x30,0x01,0x43,0x69,0x80,0xc8,0x07, +0x0a,0xd0,0xb8,0x79,0x01,0x28,0x07,0xd1,0xb8,0x78,0x00,0x28,0x04,0xd0,0x01,0x20, +0xf8,0x70,0x0d,0x98,0x00,0xf0,0xe0,0xfc,0x38,0x8f,0xb8,0x87,0x69,0x88,0xc8,0x07, +0x36,0xd0,0x03,0x98,0x80,0x8a,0x27,0x22,0x80,0x05,0x80,0x0d,0x12,0x01,0x10,0x1a, +0x6a,0x7c,0xce,0x4b,0x52,0x00,0x9a,0x5a,0x52,0x00,0x80,0x1a,0x00,0xb2,0x00,0x28, +0x07,0xda,0xcb,0x4a,0x76,0x1e,0x80,0x18,0x36,0x01,0x00,0xb2,0x36,0x09,0x00,0x28, +0xf8,0xdb,0xf8,0x85,0xa6,0x64,0x66,0x65,0x88,0x07,0x1d,0xd4,0x02,0x20,0x01,0x43, +0x69,0x80,0xc8,0x07,0x39,0xd0,0x04,0x99,0x85,0x20,0x02,0x23,0xff,0x22,0x80,0x00, +0x49,0x1c,0xff,0xf7,0x6b,0xfc,0x06,0x46,0x60,0x6d,0x61,0x6e,0x40,0x08,0x49,0x08, +0xff,0xf7,0xfa,0xfb,0x31,0x80,0x30,0x46,0xff,0xf7,0x66,0xfc,0x25,0xe0,0x87,0xe1, +0xa0,0x6c,0x20,0x65,0x60,0x65,0xdf,0xe7,0xc8,0x07,0x1e,0xd0,0x60,0x6d,0x41,0x08, +0x08,0x98,0x40,0x08,0x08,0x1a,0x61,0x6e,0x00,0x01,0x00,0x09,0x49,0x08,0xff,0xf7, +0xe3,0xfb,0x00,0x29,0x11,0xd0,0x04,0x99,0x02,0x23,0xff,0x22,0xad,0x48,0x49,0x1c, +0xff,0xf7,0x44,0xfc,0x06,0x46,0x60,0x6d,0x61,0x6e,0x40,0x08,0x49,0x08,0xff,0xf7, +0xd3,0xfb,0x31,0x80,0x30,0x46,0xff,0xf7,0x3f,0xfc,0x68,0x88,0x41,0x05,0x01,0xe0, +0x8c,0xe0,0x09,0xe0,0x08,0xd4,0x81,0x07,0x06,0xd5,0x05,0x99,0x49,0x07,0x03,0xd5, +0x01,0x21,0x89,0x02,0x08,0x43,0x68,0x80,0x06,0x98,0x00,0x07,0x7e,0xd4,0x20,0x6d, +0xa0,0x65,0x01,0x20,0x01,0x90,0x06,0x98,0x66,0x21,0x08,0x42,0x76,0xd1,0x06,0x98, +0xc0,0x06,0x06,0xd5,0x69,0x88,0x80,0x20,0x01,0x43,0x69,0x80,0x02,0x20,0x68,0x73, +0xbf,0xe0,0x05,0x98,0x06,0x0a,0x14,0xd0,0x00,0x98,0x00,0x28,0x66,0xd0,0x04,0x2e, +0x04,0xd9,0xa8,0x78,0x80,0x06,0x01,0xd5,0x36,0x1f,0xb6,0xb2,0x03,0x98,0x80,0x8b, +0x08,0x90,0x00,0x98,0x03,0x28,0x0e,0xd0,0x01,0x28,0x1b,0xd0,0x02,0x28,0x19,0xd0, +0xa7,0xe0,0x68,0x88,0x04,0x21,0x88,0x43,0x05,0x99,0xc9,0x06,0xc9,0x0f,0x89,0x00, +0x08,0x43,0x68,0x80,0x9d,0xe0,0xb0,0x1d,0x83,0xb2,0x04,0x99,0x83,0x20,0xff,0x22, +0x80,0x00,0x49,0x1c,0xff,0xf7,0xea,0xfb,0x86,0x70,0x08,0x99,0x81,0x80,0x39,0x8f, +0x01,0x80,0x0b,0xe0,0x04,0x99,0x06,0x23,0xff,0x22,0x7b,0x48,0x49,0x1c,0xff,0xf7, +0xdd,0xfb,0x08,0x99,0x01,0x80,0x46,0x80,0x00,0x99,0x01,0x71,0xff,0xf7,0xdc,0xfb, +0x03,0x98,0x00,0x8c,0x0a,0x90,0x00,0x28,0x5e,0xd0,0x05,0x98,0x80,0x06,0x75,0xd5, +0x06,0x98,0x00,0x28,0x72,0xd1,0x04,0x99,0x0c,0x23,0xff,0x22,0x6f,0x48,0x49,0x1c, +0xff,0xf7,0xc4,0xfb,0x06,0x46,0x03,0x98,0xc0,0x8b,0x00,0x90,0xc0,0x06,0xc0,0x0e, +0x70,0x70,0x00,0x98,0x00,0x06,0x80,0x0f,0xb0,0x70,0x69,0x7c,0x68,0x48,0x40,0x5c, +0x30,0x71,0x02,0x98,0x70,0x71,0x67,0x48,0xc1,0x69,0x09,0x98,0x88,0x47,0x01,0x46, +0x0a,0x20,0x41,0x43,0xf1,0x80,0x00,0x20,0x30,0x72,0x00,0xe0,0x51,0xe0,0x38,0x8f, +0x70,0x81,0x00,0x98,0x1c,0x21,0x00,0x0a,0xf0,0x70,0x5f,0x48,0x5f,0x4a,0x00,0x78, +0x41,0x43,0x89,0x18,0x89,0x08,0x89,0x00,0xff,0x31,0xc4,0x31,0x89,0x08,0x89,0x00, +0xff,0x31,0x1c,0x31,0x89,0x08,0x89,0x00,0xff,0x31,0x8a,0x08,0x58,0x49,0x92,0x00, +0x51,0x18,0x89,0x08,0x89,0x00,0x69,0x31,0x89,0x08,0x89,0x00,0x00,0x02,0x09,0x18, +0x54,0x48,0x08,0x18,0x81,0x08,0x54,0x48,0x89,0x00,0x08,0x18,0x81,0x08,0x0a,0x98, +0x89,0x00,0x40,0x1a,0xa8,0x21,0xff,0xf7,0x0f,0xfb,0x30,0x70,0x30,0x46,0xff,0xf7, +0x7b,0xfb,0x01,0x20,0x07,0x90,0x19,0xe0,0x00,0x98,0x03,0x28,0x16,0xd1,0x4b,0x49, +0x08,0x98,0x40,0x18,0x00,0x78,0x1b,0x28,0x10,0xd1,0x05,0x98,0x80,0x06,0x0d,0xd4, +0x04,0x99,0x0c,0x23,0xff,0x22,0x3d,0x48,0x49,0x1c,0xff,0xf7,0x5f,0xfb,0x00,0x21, +0x41,0x70,0xc1,0x70,0xff,0xf7,0x60,0xfb,0x01,0x20,0x07,0x90,0x03,0x99,0x00,0x20, +0x88,0x83,0xff,0xf7,0x11,0xfb,0x00,0x90,0x36,0x48,0xc1,0x69,0x09,0x98,0x88,0x47, +0x06,0x46,0x01,0x98,0x00,0x28,0x04,0xd1,0x0b,0x98,0x10,0x21,0x41,0x56,0xb1,0x42, +0x08,0xda,0x00,0x9a,0x01,0x99,0x02,0x98,0xff,0xf7,0x4c,0xfb,0x01,0x98,0x00,0x28, +0x00,0xd0,0xee,0x74,0x00,0xbf,0x00,0xbf,0x07,0x98,0x00,0x28,0x36,0xd1,0x03,0x98, +0x00,0x8c,0x00,0x28,0x32,0xd0,0x28,0x49,0x1c,0x22,0x09,0x78,0x0b,0x46,0x53,0x43, +0x26,0x4a,0x09,0x02,0x9a,0x18,0x92,0x08,0x92,0x00,0xff,0x32,0xc4,0x32,0x92,0x08, +0x92,0x00,0xff,0x32,0x1c,0x32,0x92,0x08,0x92,0x00,0xff,0x32,0x93,0x08,0x20,0x4a, +0x9b,0x00,0x9a,0x18,0x92,0x08,0x92,0x00,0x69,0x32,0x92,0x08,0x92,0x00,0x52,0x18, +0x1c,0x49,0x51,0x18,0x8a,0x08,0x1c,0x49,0x92,0x00,0x51,0x18,0x8e,0x08,0xb6,0x00, +0x80,0x1b,0xa8,0x21,0xff,0xf7,0xa0,0xfa,0x80,0xb2,0xa8,0x21,0x48,0x43,0x31,0x18, +0x16,0x48,0x08,0x18,0x01,0x88,0x49,0x04,0x49,0x0c,0x01,0x80,0xff,0xf7,0x10,0xfb, +0x0d,0x98,0xff,0xf7,0xf5,0xfa,0x00,0x28,0x22,0xd0,0x25,0xe6,0x10,0x04,0x00,0x20, +0xcc,0x03,0x00,0x20,0x94,0x02,0x00,0x20,0x80,0xc5,0x02,0x40,0x18,0x00,0x00,0x20, +0x71,0x02,0x00,0x00,0x15,0x02,0x00,0x00,0x0e,0x02,0x00,0x00,0x16,0x02,0x00,0x00, +0x76,0xd7,0x02,0x00,0x74,0x02,0x00,0x20,0x03,0x01,0x00,0x20,0x8b,0x05,0x00,0x00, +0xdb,0x13,0x00,0x00,0x03,0x03,0x00,0x00,0x03,0x06,0x00,0x00,0x00,0xc0,0x02,0x40, +0x0f,0xb0,0xf0,0xbd,0xf7,0xb5,0x8c,0xb0,0x0c,0x98,0x81,0x00,0xe5,0x48,0x44,0x58, +0x00,0x20,0x0a,0x90,0x26,0x46,0x00,0x90,0x80,0x36,0x01,0x94,0x71,0x7c,0xe2,0x48, +0x40,0x5c,0x03,0x28,0x0d,0xd0,0x0e,0x20,0x40,0x00,0x04,0x90,0x70,0x88,0xa5,0x6c, +0x81,0x07,0x37,0xd5,0xc0,0x07,0x35,0xd0,0x00,0x20,0x30,0x75,0x00,0x2a,0x02,0xd0, +0x30,0xe0,0x70,0x20,0xf0,0xe7,0x21,0x46,0x40,0x31,0x48,0x8e,0x00,0x28,0x29,0xd0, +0x72,0x88,0x53,0x05,0x26,0xd5,0x53,0x07,0x24,0xd4,0x12,0x07,0x22,0xd4,0x8a,0x79, +0x00,0x2a,0x13,0xd0,0x8b,0x88,0x01,0x2a,0x00,0xd0,0x00,0x22,0x9a,0x1a,0x0b,0x8f, +0x92,0xb2,0x9c,0x46,0x9b,0x1a,0x9f,0xb2,0xcc,0x4b,0x9f,0x42,0x12,0xd3,0x63,0x46, +0xd2,0x1a,0x52,0x1e,0x90,0x42,0x00,0xd3,0x10,0x46,0x80,0xb2,0x00,0x28,0x09,0xd0, +0x62,0x6e,0x42,0x43,0x52,0x19,0x15,0x01,0x4a,0x8f,0x2d,0x09,0x10,0x18,0x48,0x87, +0x01,0x20,0x30,0x75,0x0d,0x98,0xc2,0x4b,0x40,0x1b,0x00,0x01,0x00,0x09,0x98,0x42, +0x0e,0xd2,0x20,0x46,0x62,0x6e,0x40,0x30,0x51,0x19,0x0d,0x01,0x41,0x8f,0x2d,0x09, +0x49,0x1c,0x41,0x87,0x0d,0x99,0x49,0x1b,0x09,0x01,0x09,0x09,0x99,0x42,0xf3,0xd3, +0xa0,0x6d,0x27,0x46,0x40,0x37,0x05,0x90,0xb8,0x79,0x01,0x28,0x42,0xd1,0xf8,0x78, +0x00,0x28,0x3f,0xd1,0x38,0x8f,0x79,0x8f,0x40,0x18,0xb9,0x88,0x40,0x1a,0x81,0xb2, +0xae,0x48,0x81,0x42,0x36,0xd2,0xb8,0x78,0x00,0x28,0x1d,0xd1,0xa0,0x8f,0x40,0x19, +0x05,0x01,0x70,0x88,0x2d,0x09,0xc1,0x07,0x04,0xd0,0x39,0x88,0x49,0x08,0x49,0x19, +0x0d,0x01,0x2d,0x09,0x61,0x6b,0x61,0x66,0xe1,0x8f,0x79,0x86,0xa1,0x6b,0xa1,0x66, +0x01,0x21,0xb9,0x70,0xc0,0x07,0x05,0xd0,0x30,0x7b,0xff,0xf7,0x57,0xfa,0xb0,0x78, +0xc0,0x07,0x01,0xd1,0x01,0x20,0xf8,0x70,0x05,0x95,0x38,0x8f,0x79,0x8f,0x40,0x18, +0xb9,0x88,0x40,0x1a,0x81,0xb2,0x48,0x1e,0x80,0xb2,0x00,0x29,0x0a,0xd0,0x62,0x6e, +0x05,0x99,0x89,0x1a,0x09,0x01,0x09,0x09,0x05,0x91,0x01,0x46,0x40,0x1e,0x80,0xb2, +0x00,0x29,0xf5,0xd1,0xb0,0x78,0x80,0x07,0x01,0xd5,0xa0,0x6e,0x02,0xe0,0x60,0x6e, +0x06,0x21,0x48,0x43,0x03,0x90,0x05,0x98,0x28,0x1a,0x01,0x01,0x03,0x98,0x09,0x09, +0x81,0x42,0x7d,0xd2,0x8b,0x48,0x09,0x90,0x20,0x46,0x20,0x30,0x08,0x90,0x02,0x95, +0xb0,0x78,0xc0,0x07,0x75,0xd0,0x70,0x7c,0x06,0x90,0x00,0x20,0x07,0x90,0x2e,0x20, +0x38,0x5e,0x00,0x90,0x21,0x6d,0x68,0x1a,0x00,0x01,0x00,0x09,0x04,0x90,0xff,0xf7, +0x1b,0xfa,0x00,0x28,0x01,0xd0,0x14,0x20,0x01,0xe0,0x09,0x98,0x00,0x89,0xf9,0x8e, +0x40,0x18,0x04,0x99,0x48,0x43,0x19,0x21,0x89,0x01,0xff,0xf7,0x85,0xf9,0x01,0x46, +0x80,0x00,0x40,0x31,0xff,0x30,0x01,0x30,0x04,0x90,0xb0,0x78,0x80,0x07,0x07,0xd4, +0x01,0x20,0x07,0x90,0x38,0x8e,0x74,0x4a,0x50,0x43,0x04,0x9a,0x80,0x18,0x04,0x90, +0xb8,0x79,0x01,0x28,0x05,0xd1,0xb8,0x78,0x00,0x28,0x02,0xd0,0xf8,0x78,0x00,0x28, +0x03,0xd0,0x07,0x98,0x00,0x28,0x07,0xd0,0x0e,0xe0,0x38,0x88,0x6a,0x49,0x48,0x43, +0x04,0x99,0x40,0x18,0x04,0x90,0x07,0xe0,0x67,0x4a,0x60,0x6e,0x50,0x43,0x40,0x08, +0xff,0x38,0x2d,0x38,0x88,0x42,0x2b,0xd9,0x04,0x98,0x41,0x08,0x07,0x91,0x62,0x49, +0x07,0x98,0xff,0xf7,0x51,0xf9,0x02,0x99,0x09,0x1a,0x09,0x01,0x09,0x09,0x02,0x91, +0x5d,0x49,0x48,0x43,0x07,0x99,0x09,0x1a,0x00,0x98,0x40,0x1a,0x00,0x90,0x08,0xd5, +0x02,0x98,0x59,0x49,0x40,0x1e,0x00,0x01,0x00,0x09,0x02,0x90,0x00,0x98,0x40,0x18, +0x00,0x90,0x01,0x99,0x88,0x60,0xb8,0x79,0x03,0x28,0x0e,0xd1,0x38,0x8f,0x79,0x8f, +0x40,0x18,0xb9,0x88,0x40,0x1a,0x81,0xb2,0x4c,0x48,0x81,0x42,0x05,0xd2,0x01,0xe0, +0x75,0xe0,0x0f,0xe0,0x08,0x98,0x40,0x7d,0x06,0x90,0x47,0x48,0x06,0x99,0x40,0x5c, +0x03,0x28,0x02,0xd1,0x04,0x98,0xc4,0x30,0x04,0x90,0xe1,0x6d,0x04,0x98,0x09,0x18, +0x01,0x98,0x01,0x61,0x01,0x98,0x02,0x99,0x41,0x60,0x01,0x98,0xff,0xf7,0xa2,0xf9, +0x00,0x28,0x5f,0xd0,0x01,0x98,0x81,0x7d,0x40,0x48,0x40,0x7a,0x08,0x18,0x01,0x99, +0x88,0x75,0x60,0x6e,0x40,0x19,0x05,0x01,0x78,0x8f,0x2d,0x09,0x40,0x1c,0x80,0xb2, +0x78,0x87,0xb9,0x79,0x01,0x29,0x42,0xd1,0xf9,0x78,0x00,0x29,0x3f,0xd1,0x39,0x8f, +0x08,0x18,0xb9,0x88,0x40,0x1a,0x81,0xb2,0x30,0x48,0x81,0x42,0x37,0xd2,0xb8,0x78, +0x00,0x28,0x1e,0xd1,0xa0,0x8f,0x40,0x19,0x05,0x01,0x70,0x88,0x2d,0x09,0xc1,0x07, +0x04,0xd0,0x39,0x88,0x49,0x08,0x49,0x19,0x0d,0x01,0x2d,0x09,0x61,0x6b,0x61,0x66, +0xe1,0x8f,0x79,0x86,0xa1,0x6b,0xa1,0x66,0xc0,0x07,0x02,0xd0,0x30,0x7b,0xff,0xf7, +0x5d,0xf9,0x01,0x20,0xb8,0x70,0xa1,0x6e,0x03,0x91,0xb1,0x78,0xc9,0x07,0x00,0xd1, +0xf8,0x70,0x05,0x95,0x38,0x8f,0x79,0x8f,0x40,0x18,0xb9,0x88,0x40,0x1a,0x81,0xb2, +0x48,0x1e,0x80,0xb2,0x00,0x29,0x0a,0xd0,0x62,0x6e,0x05,0x99,0x89,0x1a,0x09,0x01, +0x09,0x09,0x05,0x91,0x01,0x46,0x40,0x1e,0x80,0xb2,0x00,0x29,0xf5,0xd1,0x05,0x98, +0x28,0x1a,0x01,0x01,0x03,0x98,0x09,0x09,0x81,0x42,0x00,0xd2,0x0f,0xe7,0x0a,0x98, +0x00,0x28,0x0b,0xd0,0x00,0x20,0x70,0x73,0xa5,0x64,0xb0,0x78,0xc0,0x07,0x03,0xd0, +0x00,0x98,0xb8,0x85,0x04,0x98,0xe0,0x64,0x0f,0xb0,0xf0,0xbd,0xb0,0x78,0x80,0x07, +0x01,0xd5,0x08,0x22,0x00,0xe0,0x3e,0x22,0x01,0x21,0x0c,0x98,0xff,0xf7,0xfa,0xf8, +0x0f,0xb0,0xf0,0xbd,0x10,0x04,0x00,0x20,0x76,0xd7,0x02,0x00,0xff,0x7f,0x00,0x00, +0xff,0xff,0xff,0x07,0xcc,0x03,0x00,0x20,0x71,0x02,0x00,0x00,0x91,0xd7,0x02,0x00, +0xf0,0xb5,0x99,0x49,0x80,0x00,0x0f,0x58,0x89,0xb0,0x38,0x6b,0x00,0x28,0x08,0xd1, +0xb8,0x6a,0x38,0x63,0x00,0x28,0x04,0xd0,0xc0,0x88,0x81,0x05,0x89,0x0d,0x80,0x20, +0xc1,0x53,0x3c,0x46,0x80,0x34,0x60,0x88,0x3d,0x6b,0xc1,0x06,0x09,0xd5,0x00,0x2d, +0x07,0xd0,0x21,0x88,0x00,0x29,0x02,0xd1,0x29,0x68,0x00,0x29,0x01,0xd0,0x01,0x21, +0x00,0xe0,0x00,0x21,0x01,0x91,0x7a,0x6a,0x00,0x92,0x0a,0x43,0x42,0xd0,0x81,0x04, +0x01,0xd4,0xc0,0x06,0x01,0xd4,0x01,0x20,0x00,0xe0,0x00,0x20,0x05,0x90,0x20,0x7c, +0x10,0x26,0x02,0x28,0x16,0xd0,0x04,0x90,0x34,0xd2,0x00,0x20,0x02,0x90,0x00,0x98, +0x00,0x28,0x33,0xd0,0x86,0x79,0x80,0x88,0x03,0x21,0x03,0x91,0x7b,0x49,0x06,0x90, +0x40,0x18,0x00,0x78,0x1b,0x28,0x27,0xd0,0x00,0x20,0x02,0x90,0x00,0x20,0x78,0x62, +0x00,0x90,0x4f,0xe0,0xe0,0x7b,0x02,0x21,0x40,0x1c,0xff,0xf7,0x3d,0xf8,0x20,0x7b, +0xc2,0x00,0x10,0x1a,0x08,0x18,0x05,0x99,0xc0,0xb2,0x00,0x29,0x12,0xd1,0x70,0x49, +0x00,0x01,0x0a,0x78,0x1c,0x21,0x4a,0x43,0x6e,0x49,0x51,0x18,0x89,0x08,0x89,0x00, +0x09,0x18,0x6a,0x48,0x08,0x18,0x01,0x88,0xc9,0x0b,0x03,0xd1,0x41,0x88,0xb1,0x43, +0x31,0x43,0x41,0x80,0x09,0xb0,0xf0,0xbd,0x01,0x20,0xd6,0xe7,0x01,0x98,0x00,0x28, +0xf8,0xd0,0x20,0x88,0x00,0x28,0x08,0xd1,0x28,0x68,0x00,0x28,0x05,0xd0,0x05,0x46, +0x38,0x63,0xc0,0x88,0x80,0x05,0x80,0x0d,0x20,0x80,0xe8,0x88,0xa9,0x88,0x82,0x05, +0x92,0x0d,0x26,0x88,0x89,0x18,0x89,0x1b,0x89,0xb2,0x06,0x91,0x81,0x04,0x89,0x0f, +0x01,0x29,0x00,0xd0,0x02,0x21,0x03,0x91,0xa1,0x7a,0x8e,0x42,0x00,0xd3,0x0e,0x46, +0x03,0x21,0x09,0x03,0x88,0x43,0x01,0x21,0x09,0x03,0x40,0x18,0xe8,0x80,0x20,0x88, +0x80,0x1b,0x20,0x80,0x20,0x7b,0xc1,0x00,0x0a,0x1a,0x01,0x92,0xe0,0x7b,0x11,0x18, +0xc9,0xb2,0x07,0x91,0x02,0x21,0x40,0x1c,0xfe,0xf7,0xe6,0xff,0x01,0x9a,0x88,0x18, +0xc0,0xb2,0x84,0x46,0x60,0x88,0xc1,0x06,0x09,0xd5,0x00,0x2d,0x07,0xd0,0x21,0x88, +0x00,0x29,0x02,0xd1,0x29,0x68,0x00,0x29,0x01,0xd0,0x01,0x21,0x00,0xe0,0x00,0x21, +0x01,0x91,0x41,0x06,0x01,0xd5,0x36,0x1d,0xb6,0xb2,0x05,0x99,0x00,0x29,0x06,0xd1, +0x01,0x99,0x00,0x29,0x01,0xd1,0xc0,0x07,0x01,0xd0,0x01,0x20,0x00,0xe0,0x00,0x20, +0x07,0x9b,0x32,0x02,0x9e,0x46,0x02,0x9b,0x00,0x01,0x5b,0x01,0x1a,0x43,0x02,0x43, +0x03,0x99,0x33,0x4e,0x0a,0x43,0x30,0x78,0x1c,0x21,0x48,0x43,0x31,0x49,0x73,0x46, +0x40,0x18,0x81,0x08,0x89,0x00,0x18,0x01,0x0b,0x18,0x2c,0x49,0x5b,0x18,0x5a,0x80, +0x33,0x78,0x1c,0x26,0x73,0x43,0x2b,0x4e,0x06,0x9a,0x9b,0x19,0x9b,0x08,0x9b,0x00, +0x1b,0x18,0x5b,0x18,0x9a,0x80,0x05,0x9a,0x00,0x2a,0x13,0xd1,0x24,0x4b,0x62,0x46, +0x1e,0x78,0x1c,0x23,0x5e,0x43,0x23,0x4b,0x12,0x01,0xf3,0x18,0x9b,0x08,0x9b,0x00, +0x9a,0x18,0x52,0x18,0x13,0x88,0xdb,0x0b,0x04,0xd1,0x56,0x88,0x10,0x23,0x9e,0x43, +0x1e,0x43,0x56,0x80,0x02,0x9a,0x00,0x2a,0x0e,0xd0,0xa3,0x7d,0x62,0x7d,0x9b,0x01, +0x13,0x43,0x17,0x4a,0x1c,0x26,0x12,0x78,0x72,0x43,0x16,0x4e,0x92,0x19,0x92,0x08, +0x92,0x00,0x12,0x18,0x52,0x18,0xd3,0x81,0x11,0x4a,0x13,0x78,0x1c,0x22,0x53,0x43, +0x10,0x4a,0x9a,0x18,0x92,0x08,0x92,0x00,0x10,0x18,0x40,0x18,0x01,0x88,0x49,0x04, +0x49,0x0c,0x01,0x80,0xe0,0x7b,0x02,0x21,0x40,0x1c,0xfe,0xf7,0x65,0xff,0xe1,0x73, +0x20,0x7c,0x40,0x1c,0x20,0x74,0x04,0x98,0x40,0x1c,0xc0,0xb2,0x04,0x90,0x02,0x28, +0x00,0xd2,0x02,0xe7,0x09,0xb0,0xf0,0xbd,0x10,0x04,0x00,0x20,0x00,0xc0,0x02,0x40, +0x03,0x01,0x00,0x20,0x8b,0x05,0x00,0x00,0xf8,0xb5,0x06,0x46,0x27,0x49,0x80,0x00, +0x0c,0x58,0x35,0x02,0x20,0x46,0x40,0x30,0x00,0x90,0x80,0x79,0x01,0x28,0x04,0xd0, +0x02,0x28,0x12,0xd0,0x03,0x28,0x3d,0xd1,0x13,0xe0,0x21,0x20,0x69,0x1c,0xff,0x22, +0x00,0x01,0xfe,0xf7,0x8b,0xff,0x62,0x6e,0x80,0x34,0xa1,0x7c,0x30,0x46,0xfe,0xf7, +0xcd,0xff,0x30,0x46,0xff,0xf7,0xf6,0xf8,0x2c,0xe0,0x69,0x1c,0xff,0x22,0x18,0x48, +0x26,0xe0,0x20,0x46,0x20,0x30,0x22,0x46,0x41,0x7d,0x80,0x32,0x51,0x74,0x07,0x7d, +0xa9,0x23,0x1b,0x01,0x97,0x74,0x02,0x2f,0x01,0xd0,0x03,0x2f,0x04,0xd1,0xd0,0x88, +0x98,0x42,0x00,0xd8,0x18,0x46,0xd0,0x80,0x02,0x29,0x01,0xd0,0x03,0x29,0x04,0xd1, +0x10,0x89,0x98,0x42,0x00,0xd8,0x18,0x46,0x10,0x81,0x39,0x46,0x30,0x46,0x62,0x6e, +0xfe,0xf7,0xa4,0xff,0x30,0x46,0xff,0xf7,0xcd,0xf8,0x69,0x1c,0xff,0x22,0x05,0x48, +0xfe,0xf7,0x54,0xff,0x00,0x98,0x00,0x21,0x81,0x71,0xf8,0xbd,0x10,0x04,0x00,0x20, +0x11,0x02,0x00,0x00,0x12,0x02,0x00,0x00,0xf3,0xb5,0x83,0xb0,0x0c,0x20,0xef,0xf3, +0x10,0x86,0x01,0x22,0x82,0xf3,0x10,0x88,0x03,0x9a,0x97,0x00,0x22,0x4a,0xd4,0x59, +0x00,0x2c,0x3c,0xd0,0x25,0x46,0x80,0x35,0x68,0x88,0x10,0x22,0x90,0x43,0x0a,0x01, +0x10,0x43,0x68,0x80,0x00,0x29,0x31,0xd0,0x03,0x98,0xff,0xf7,0x51,0xfe,0x28,0x7c, +0x00,0x28,0x2b,0xd0,0x68,0x7b,0x00,0x28,0x28,0xd1,0xa8,0x78,0xc0,0x07,0x25,0xd0, +0x28,0x7d,0x00,0x28,0x22,0xd0,0x14,0x48,0xc0,0x59,0x01,0x90,0xfe,0xf7,0xf4,0xfe, +0x00,0x90,0xa7,0x6c,0x65,0x6e,0x38,0x1a,0x00,0x01,0x00,0x09,0x85,0x42,0x15,0xd2, +0x29,0x46,0xfe,0xf7,0xc1,0xfe,0x80,0xb2,0x45,0x43,0x79,0x1b,0x09,0x01,0x09,0x09, +0xa1,0x64,0x40,0x34,0x61,0x8f,0x08,0x1a,0x60,0x87,0x00,0x21,0x01,0x98,0xfe,0xf7, +0x0b,0xff,0x01,0x22,0x00,0x99,0x03,0x98,0xff,0xf7,0x44,0xfc,0x00,0x20,0x86,0xf3, +0x10,0x88,0x05,0xb0,0xf0,0xbd,0x00,0x00,0x10,0x04,0x00,0x20,0xf8,0xb5,0x06,0x46, +0x0c,0x20,0xef,0xf3,0x10,0x87,0x01,0x24,0x84,0xf3,0x10,0x88,0x16,0x4c,0xb5,0x00, +0x64,0x59,0x00,0x2c,0x25,0xd0,0x25,0x46,0x80,0x34,0xa2,0x80,0xe1,0x80,0x13,0x4a, +0x1b,0x20,0x71,0x00,0x50,0x52,0x23,0x81,0xa1,0x7c,0xa9,0x22,0x12,0x01,0x02,0x29, +0x01,0xd0,0x03,0x29,0x04,0xd1,0xe0,0x88,0x90,0x42,0x00,0xd8,0x10,0x46,0xe0,0x80, +0x60,0x7c,0x02,0x28,0x01,0xd0,0x03,0x28,0x03,0xd1,0x93,0x42,0x00,0xd8,0x13,0x46, +0x23,0x81,0x30,0x46,0x6a,0x6e,0xfe,0xf7,0x11,0xff,0x30,0x46,0xff,0xf7,0x3a,0xf8, +0x00,0x20,0x87,0xf3,0x10,0x88,0xf8,0xbd,0x10,0x04,0x00,0x20,0xf8,0x0c,0x00,0x20, +0xf3,0xb5,0x83,0xb0,0x0c,0x20,0xef,0xf3,0x10,0x86,0x01,0x22,0x82,0xf3,0x10,0x88, +0x03,0x9a,0x97,0x00,0x21,0x4a,0xd4,0x59,0x00,0x2c,0x3b,0xd0,0x25,0x46,0x80,0x35, +0x61,0x62,0x68,0x88,0x08,0x21,0x08,0x43,0x68,0x80,0x69,0x7b,0x00,0x29,0x01,0xd0, +0xc0,0x06,0x2e,0xd5,0x03,0x98,0xff,0xf7,0xc3,0xfd,0x68,0x7b,0x00,0x28,0x28,0xd1, +0xa8,0x78,0xc0,0x07,0x25,0xd0,0x28,0x7d,0x00,0x28,0x22,0xd0,0x13,0x48,0xc0,0x59, +0x01,0x90,0xfe,0xf7,0x69,0xfe,0x00,0x90,0xa7,0x6c,0x65,0x6e,0x38,0x1a,0x00,0x01, +0x00,0x09,0x85,0x42,0x15,0xd2,0x29,0x46,0xfe,0xf7,0x36,0xfe,0x80,0xb2,0x45,0x43, +0x79,0x1b,0x09,0x01,0x09,0x09,0xa1,0x64,0x40,0x34,0x61,0x8f,0x08,0x1a,0x60,0x87, +0x00,0x21,0x01,0x98,0xfe,0xf7,0x80,0xfe,0x01,0x22,0x00,0x99,0x03,0x98,0xff,0xf7, +0xb9,0xfb,0x00,0x20,0x86,0xf3,0x10,0x88,0x05,0xb0,0xf0,0xbd,0x10,0x04,0x00,0x20, +0xf3,0xb5,0x87,0xb0,0x07,0x98,0xe5,0x4e,0x87,0x00,0xf0,0x59,0x0c,0x24,0x0d,0x46, +0x00,0x28,0x7c,0xd1,0x00,0x21,0x98,0x20,0xfe,0xf7,0xa2,0xfe,0xf0,0x51,0x00,0x28, +0x75,0xd0,0x06,0x46,0x00,0x20,0x00,0x90,0xfe,0xf7,0x2e,0xfe,0x05,0x90,0x07,0x98, +0x02,0x90,0x98,0x21,0x30,0x46,0xfe,0xf7,0x1c,0xfe,0xd9,0x49,0x08,0x68,0x00,0x28, +0x01,0xd1,0xd8,0x48,0x08,0x60,0xd8,0x48,0x02,0x68,0x00,0x2a,0x01,0xd1,0xd7,0x4a, +0x02,0x60,0x0a,0x68,0x32,0x62,0x01,0x68,0x00,0x27,0xf7,0x61,0xd4,0x48,0xb7,0x60, +0xb1,0x61,0x81,0x7a,0xb1,0x75,0x01,0x21,0x49,0x03,0xb1,0x82,0x34,0x46,0x80,0x34, +0x07,0x98,0x20,0x73,0x60,0x88,0xcf,0x4a,0x43,0x08,0x28,0x46,0x20,0x30,0x03,0x90, +0x00,0x79,0x5b,0x00,0x03,0x43,0xc8,0x10,0x83,0x43,0x30,0x46,0x63,0x80,0x40,0x30, +0x01,0x90,0x07,0x87,0x47,0x87,0xc7,0x87,0xe9,0x79,0x89,0x00,0x01,0x86,0x29,0x89, +0x89,0x00,0x31,0x66,0x69,0x89,0x89,0x00,0x71,0x66,0xa9,0x89,0x41,0x86,0xe9,0x89, +0x49,0x01,0xb1,0x66,0x69,0x7d,0xe1,0x72,0xa9,0x7d,0x49,0x00,0x51,0x5a,0xc1,0x86, +0x10,0x20,0x03,0x43,0x63,0x80,0x27,0x74,0xa7,0x73,0xe7,0x73,0x77,0x62,0x37,0x63, +0x27,0x80,0x1b,0x21,0xa1,0x80,0x03,0x98,0x40,0x79,0x02,0x28,0x45,0xd0,0x03,0x28, +0x43,0xd0,0xff,0x20,0x49,0x30,0xe0,0x80,0x07,0x98,0xb3,0x4a,0x40,0x00,0x11,0x52, +0xe0,0x88,0x20,0x81,0xa1,0x72,0x03,0x98,0x40,0x79,0x60,0x74,0x03,0x98,0x40,0x79, +0xa0,0x74,0xe7,0x74,0xa0,0x78,0xc0,0x07,0x04,0xd0,0x20,0x7b,0x00,0xe0,0x41,0xe1, +0xfe,0xf7,0x14,0xfe,0x03,0x98,0x02,0x9b,0x00,0x79,0x00,0x28,0x28,0xd0,0x03,0x20, +0x70,0x21,0x4b,0x43,0xa5,0x49,0x5f,0x18,0x04,0x97,0x38,0x82,0x03,0x98,0x11,0x21, +0x40,0x79,0x09,0x02,0x82,0x00,0x11,0x43,0x01,0x43,0xf9,0x82,0x02,0x98,0x20,0x21, +0x00,0x02,0x08,0x43,0x78,0x82,0x28,0x88,0xf8,0x83,0x68,0x88,0x38,0x84,0xa8,0x88, +0x78,0x84,0xa8,0x79,0xb9,0x8c,0x09,0x0a,0x09,0x02,0x01,0x43,0xb9,0x84,0x03,0x98, +0x80,0x79,0x00,0x28,0x06,0xd0,0x01,0x22,0x05,0xe0,0xa9,0x20,0x00,0x01,0xba,0xe7, +0x02,0x20,0xd5,0xe7,0x00,0x22,0xe0,0x7a,0x01,0x21,0xc9,0x03,0x52,0x03,0xc0,0x06, +0x11,0x43,0xc0,0x0c,0x01,0x43,0x39,0x85,0x8d,0x48,0x00,0x21,0x18,0x18,0x02,0x90, +0x01,0x87,0x61,0x88,0x01,0x20,0x40,0x02,0x81,0x43,0x03,0x98,0x80,0x79,0x00,0x28, +0x7e,0xd0,0x00,0x20,0x40,0x02,0x01,0x43,0x86,0x48,0x61,0x80,0x40,0x7b,0x78,0x85, +0x07,0x98,0xfe,0xf7,0x07,0xff,0x02,0x99,0xfb,0x20,0x08,0x81,0x02,0x99,0x00,0x20, +0x48,0x81,0x61,0x7c,0x80,0x48,0x40,0x5c,0x03,0x28,0x6a,0xd0,0x0e,0x20,0x41,0x08, +0x00,0x20,0xf9,0x85,0x69,0x7c,0x2a,0x7c,0x09,0x02,0x11,0x43,0x02,0x9a,0x51,0x80, +0xe9,0x7c,0xaa,0x7c,0x09,0x02,0x11,0x43,0x02,0x9a,0x91,0x80,0x69,0x7d,0x2a,0x7d, +0x09,0x02,0x11,0x43,0x02,0x9a,0xd1,0x80,0x78,0x87,0xf9,0x8e,0xc9,0x09,0xc9,0x01, +0xf9,0x86,0x38,0x87,0x01,0x21,0xb9,0x85,0x02,0x99,0x48,0x86,0x02,0x99,0x88,0x86, +0x02,0x99,0xc8,0x86,0x00,0x27,0x20,0x7b,0xc1,0x00,0x08,0x1a,0x02,0x90,0xc0,0x19, +0xc2,0xb2,0x78,0x1c,0x02,0x21,0x06,0x92,0xfe,0xf7,0x06,0xfd,0x02,0x98,0x1c,0x23, +0x08,0x18,0x66,0x49,0x00,0x06,0x09,0x78,0x00,0x0d,0x59,0x43,0x64,0x4b,0x06,0x9a, +0xc9,0x18,0x89,0x08,0x89,0x00,0x08,0x18,0x83,0x08,0x01,0x20,0xc0,0x03,0x18,0x43, +0x13,0x01,0xca,0x18,0x5f,0x49,0x51,0x18,0x08,0x80,0x5c,0x49,0x1c,0x22,0x09,0x78, +0x00,0x20,0x51,0x43,0x5a,0x4a,0x89,0x18,0x89,0x08,0x89,0x00,0xca,0x18,0x59,0x49, +0x51,0x18,0x48,0x80,0x55,0x49,0x1c,0x22,0x09,0x78,0x51,0x43,0x54,0x4a,0x89,0x18, +0x89,0x08,0x89,0x00,0xca,0x18,0x53,0x49,0x51,0x18,0x88,0x80,0x7f,0x1c,0x02,0x2f, +0xc1,0xdb,0x4e,0x48,0x1c,0x21,0x00,0x78,0x48,0x43,0x4d,0x49,0x40,0x18,0x01,0xe0, +0x32,0xe0,0x33,0xe0,0x81,0x08,0x20,0x7b,0x70,0x22,0x89,0x00,0x50,0x43,0x08,0x18, +0x04,0x99,0x80,0x08,0x88,0x86,0x61,0x88,0xc8,0x07,0x29,0xd0,0x03,0x9a,0x46,0x4b, +0x52,0x79,0xe8,0x69,0x52,0x00,0x9a,0x5a,0x2b,0x8b,0x52,0x00,0x9a,0x18,0x92,0xb2, +0x42,0x4d,0x07,0x46,0x00,0x92,0xaa,0x42,0x08,0xd3,0x6b,0x42,0xd2,0x18,0x40,0x1c, +0x92,0xb2,0x00,0x01,0x00,0x09,0x00,0x92,0xaa,0x42,0xf7,0xd2,0x37,0x65,0x01,0x9b, +0x00,0x9a,0xda,0x85,0x03,0x9a,0xd2,0x79,0x00,0x2a,0x10,0xd0,0x03,0x9a,0x52,0x79, +0x02,0x2a,0x0e,0xd2,0x08,0x22,0x0d,0xe0,0x01,0x20,0x4b,0xe7,0x70,0x20,0x5e,0xe7, +0x2a,0x6a,0x32,0x65,0x01,0x9a,0x00,0x20,0xd0,0x85,0x28,0x6a,0x0b,0xe0,0x04,0x22, +0x00,0xe0,0x0c,0x22,0x80,0x18,0x01,0x9a,0x33,0x6e,0x12,0x8e,0x18,0x18,0x52,0x08, +0x10,0x18,0x00,0x01,0x00,0x09,0x32,0x6d,0x72,0x65,0xb2,0x65,0xb0,0x64,0xc8,0x07, +0x00,0xd0,0x00,0x98,0x02,0xb2,0x01,0x98,0x82,0x85,0xc8,0x07,0x04,0xd0,0x01,0x98, +0x22,0x4b,0x00,0x8e,0x58,0x43,0x06,0xe0,0x63,0x7c,0x1b,0x48,0xc0,0x5c,0x03,0x28, +0x05,0xd0,0x0e,0x20,0x40,0x00,0xf0,0x64,0xc8,0x07,0x03,0xd1,0x01,0xe0,0x70,0x20, +0xf8,0xe7,0x00,0x22,0xb2,0x60,0x01,0x22,0x05,0x99,0x07,0x98,0xff,0xf7,0xf2,0xf9, +0x00,0x20,0x00,0x90,0x30,0x8a,0x21,0x7b,0x83,0xb2,0x04,0x20,0x72,0x6e,0xfe,0xf7, +0x8d,0xfc,0x00,0x24,0x20,0x46,0x09,0xb0,0xf0,0xbd,0x00,0x00,0x10,0x04,0x00,0x20, +0x04,0x0d,0x00,0x20,0xa1,0x81,0x00,0x20,0x08,0x0d,0x00,0x20,0xe1,0x81,0x00,0x20, +0x91,0xd7,0x02,0x00,0x50,0xd7,0x02,0x00,0xf8,0x0c,0x00,0x20,0x40,0xc1,0x02,0x40, +0x80,0xc1,0x02,0x40,0x94,0x02,0x00,0x20,0x76,0xd7,0x02,0x00,0x03,0x01,0x00,0x20, +0x8b,0x05,0x00,0x00,0x00,0xc0,0x02,0x40,0xd0,0xe4,0x02,0x00,0x71,0x02,0x00,0x00, +}; + +#endif //(_PATCH_LLD_COM_) +#if (_PATCH_KE_TIMER_SET_) + +static __align(64) unsigned char patch_4_Array[0x40] = +{ + 0x11, 0xd8, 0x0d, 0x49, 0x08, 0x68, 0x49, 0x68, 0x13, 0xf0, 0x08, 0xfb, 0x04, 0x98, 0xef, 0xf7, + 0x8e, 0xff, 0x04, 0x46, 0xc1, 0x88, 0x80, 0x88, 0xff, 0x22, 0xff, 0xf7, 0x9d, 0xfd, 0x20, 0x46, + 0xff, 0xf7, 0x3a, 0xfc, 0xb3, 0xe7, 0x05, 0xb0, 0xf0, 0xbd, 0x00, 0x00, 0xff, 0xff, 0xff, 0x07, + 0xd8, 0x01, 0x00, 0x20, 0xc8, 0x01, 0x00, 0x20, 0x30, 0xd7, 0x02, 0x00, 0x00, 0x4b, 0x18, 0x47 +}; +static __align(64) unsigned char patch_5_Array[0x40] = +{ + 0xfb, 0xfd, 0x06, 0x46, 0x05, 0x20, 0x30, 0x70, 0x75, 0x80, 0x00, 0x99, 0xb1, 0x81, 0x30, 0x1d, + 0x39, 0x46, 0xe5, 0xf7, 0x73, 0xfd, 0x30, 0x46, 0xf9, 0xf7, 0x0e, 0xff, 0x0e, 0x22, 0x29, 0x46, + 0x20, 0x46, 0xff, 0xf7, 0x45, 0xfd, 0x07, 0xb0, 0xf0, 0xbd, 0x00, 0x2e, 0x0c, 0xd0, 0x53, 0x4b, + 0x05, 0x22, 0x03, 0x21, 0x28, 0x46, 0xfd, 0xf7, 0x33, 0xfe, 0x12, 0x22, 0x29, 0x46, 0x20, 0x46, +}; + + +const static __align(4) unsigned char fun_5_Array[] ={ +0xf7,0xb5,0x86,0xb0,0x00,0x20,0x02,0x90,0x5c,0x48,0x15,0x46,0x04,0x69,0x5c,0x48, +0x0e,0x46,0x82,0x42,0x01,0xd9,0x05,0x46,0x02,0xe0,0x00,0x2d,0x00,0xd1,0x01,0x25, +0x00,0x2c,0x08,0xd0,0xa1,0x88,0x06,0x98,0x81,0x42,0x04,0xd1,0xe0,0x88,0xb0,0x42, +0x01,0xd1,0x01,0x20,0x02,0x90,0x53,0x48,0x03,0x90,0x84,0x46,0x06,0x98,0x01,0x04, +0x31,0x43,0x00,0x20,0x00,0x2c,0x1c,0xd0,0x0a,0x0c,0xa7,0x88,0x8b,0xb2,0x97,0x42, +0x07,0xd1,0xe7,0x88,0x9f,0x42,0x04,0xd1,0x00,0x28,0x07,0xd0,0x21,0x68,0x01,0x60, +0x07,0xe0,0x20,0x46,0x24,0x68,0x00,0x2c,0xef,0xd1,0x0a,0xe0,0x61,0x46,0x22,0x68, +0x0a,0x60,0x21,0x68,0x00,0x29,0x02,0xd0,0x00,0x20,0x20,0x60,0x01,0xe0,0x61,0x46, +0x48,0x60,0x00,0x2c,0x07,0xd1,0x02,0x21,0x10,0x20,0x00,0xf0,0x95,0xf8,0x06,0x99, +0x81,0x80,0x04,0x46,0xc6,0x80,0x28,0x01,0x05,0x21,0x00,0xf0,0x77,0xf8,0x07,0x46, +0x7d,0x20,0x0e,0x46,0x46,0x43,0xef,0xf3,0x10,0x85,0x01,0x20,0x80,0xf3,0x10,0x88, +0x68,0x46,0x00,0xf0,0x87,0xf8,0x85,0xf3,0x10,0x88,0x00,0x98,0x04,0x90,0xc0,0x19, +0x05,0x01,0x01,0x99,0x27,0x20,0x2d,0x09,0x8e,0x19,0x00,0x01,0x05,0x91,0x86,0x42, +0x03,0xd9,0x6d,0x1c,0x2d,0x01,0x2d,0x09,0x36,0x1a,0xe6,0x60,0xa5,0x60,0x03,0x98, +0x29,0x4f,0x86,0x46,0x00,0x20,0x84,0x46,0x70,0x46,0x00,0x68,0x00,0x28,0x13,0xd0, +0xa2,0x68,0xe1,0x68,0x00,0x91,0xc3,0x68,0x81,0x68,0x01,0x93,0x53,0x1a,0x1b,0x01, +0x1b,0x09,0xbb,0x42,0x0a,0xd2,0x91,0x42,0x03,0xd1,0x01,0x9a,0x00,0x99,0x91,0x42, +0x04,0xd9,0x84,0x46,0x00,0x68,0xe9,0xe7,0x72,0x46,0x54,0x60,0x20,0x60,0x60,0x46, +0x00,0x28,0x01,0xd0,0x04,0x60,0x01,0xe0,0x71,0x46,0x0c,0x60,0x13,0x48,0x02,0x99, +0x00,0x69,0x00,0x29,0x01,0xd1,0xa0,0x42,0x03,0xd1,0xc1,0x68,0x80,0x68,0x00,0xf0, +0x47,0xf8,0xef,0xf3,0x10,0x84,0x01,0x20,0x80,0xf3,0x10,0x88,0x02,0xa8,0x00,0xf0, +0x39,0xf8,0x84,0xf3,0x10,0x88,0x03,0x99,0x02,0x98,0x01,0x91,0x29,0x1a,0x09,0x01, +0x09,0x09,0x00,0x90,0xb9,0x42,0x04,0xd2,0xa8,0x42,0x05,0xd1,0x01,0x98,0x86,0x42, +0x02,0xd8,0x03,0x20,0x00,0xf0,0x32,0xf8,0x09,0xb0,0xf0,0xbd,0xc8,0x01,0x00,0x20, +0xff,0xff,0x7f,0x02,0xd8,0x01,0x00,0x20,0xff,0xff,0xff,0x07,0x30,0xb5,0x0b,0x46, +0x01,0x46,0x00,0x20,0x20,0x22,0x01,0x24,0x09,0xe0,0x0d,0x46,0xd5,0x40,0x9d,0x42, +0x05,0xd3,0x1d,0x46,0x95,0x40,0x49,0x1b,0x25,0x46,0x95,0x40,0x40,0x19,0x15,0x46, +0x52,0x1e,0x00,0x2d,0xf1,0xdc,0x30,0xbd,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd, +0x2d,0x7a,0x01,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x5d,0xb6,0x02,0x00, +0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x9d,0xb6,0x02,0x00,0x03,0xb4,0x01,0x48, +0x01,0x90,0x01,0xbd,0xad,0x78,0x01,0x00,0x30,0xb4,0xc3,0x68,0x82,0x68,0x88,0x68, +0x08,0x4d,0x14,0x1a,0x24,0x01,0xc9,0x68,0x24,0x09,0xac,0x42,0x03,0xd2,0x90,0x42, +0x04,0xd1,0x8b,0x42,0x02,0xd8,0x30,0xbc,0x01,0x20,0x70,0x47,0x30,0xbc,0x00,0x20, +0x70,0x47,0x00,0x00,0xff,0xff,0xff,0x07,0x0a,0x0c,0x83,0x88,0x89,0xb2,0x93,0x42, +0x04,0xd1,0xc0,0x88,0x88,0x42,0x01,0xd1,0x01,0x20,0x70,0x47,0x00,0x20,0x70,0x47, +0x70,0xb4,0x05,0x46,0x00,0x68,0x00,0x22,0x00,0x28,0x10,0xd0,0x0b,0x0c,0x86,0x88, +0x8c,0xb2,0x9e,0x42,0x07,0xd1,0xc6,0x88,0xa6,0x42,0x04,0xd1,0x01,0x68,0x00,0x2a, +0x07,0xd0,0x11,0x60,0x06,0xe0,0x02,0x46,0x00,0x68,0x00,0x28,0xef,0xd1,0x70,0xbc, +0x70,0x47,0x29,0x60,0x01,0x68,0x00,0x29,0x03,0xd0,0x00,0x21,0x01,0x60,0x70,0xbc, +0x70,0x47,0x6a,0x60,0x70,0xbc,0x70,0x47,0xf0,0xb5,0x10,0x4f,0x02,0x68,0x86,0x46, +0x00,0x25,0x00,0x2a,0x10,0xd0,0xc8,0x68,0x8c,0x68,0x93,0x68,0x84,0x46,0xe0,0x1a, +0x00,0x01,0x00,0x09,0xd6,0x68,0xb8,0x42,0x08,0xd2,0xa3,0x42,0x01,0xd1,0xb4,0x45, +0x04,0xd9,0x15,0x46,0x12,0x68,0xec,0xe7,0x70,0x46,0x41,0x60,0x0a,0x60,0x00,0x2d, +0x01,0xd0,0x29,0x60,0xf0,0xbd,0x70,0x46,0x01,0x60,0xf0,0xbd,0xff,0xff,0xff,0x07, +0x70,0xb5,0x84,0xb0,0x04,0x46,0x0e,0x46,0xef,0xf3,0x10,0x85,0x01,0x20,0x80,0xf3, +0x10,0x88,0x02,0xa8,0xff,0xf7,0x76,0xff,0x85,0xf3,0x10,0x88,0x02,0x98,0x03,0x99, +0x02,0x46,0x00,0x90,0x01,0x91,0xa0,0x1a,0x00,0x01,0x07,0x49,0x00,0x09,0x88,0x42, +0x04,0xd2,0xa2,0x42,0x05,0xd1,0x01,0x98,0x86,0x42,0x02,0xd8,0x01,0x20,0x04,0xb0, +0x70,0xbd,0x00,0x20,0x04,0xb0,0x70,0xbd,0xff,0xff,0xff,0x07,0x30,0xb5,0x83,0xb0, +0x04,0x46,0xef,0xf3,0x10,0x85,0x01,0x20,0x80,0xf3,0x10,0x88,0x68,0x46,0xff,0xf7, +0x51,0xff,0x85,0xf3,0x10,0x88,0x01,0x99,0x00,0x98,0x61,0x60,0x20,0x60,0x03,0xb0, +0x30,0xbd,0x00,0x00, +}; +#endif + +#if (_PATCH_KE_MSG_SET_) +static __align(64) unsigned char patch_6_Array[] = +{ + 0x33,0x1a,0x2a,0x46,0x9a,0x40,0x0a,0x42,0x02,0xd1,0x40,0x1c,0x20,0x28,0xf7,0xd3, + 0x30,0x1a,0x00,0x06,0x80,0x0d,0x00,0x19,0x40,0x68,0x00,0x28,0x00,0xd0,0x80,0x47, + 0x21,0x68,0x00,0x29,0xeb,0xd1,0x70,0xbd,0xf8,0x01,0x00,0x20,0x00,0x49,0x08,0x47, + 0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +static __align(4) unsigned char fun_6_Array[] ={ +0x10,0xb4,0xef,0xf3,0x10,0x81,0x01,0x22,0x82,0xf3,0x10,0x88,0x13,0x46,0x0a,0x28, +0x04,0xd2,0x06,0x4a,0x83,0x40,0x14,0x68,0x1c,0x43,0x14,0x60,0x01,0x20,0x04,0x4a, +0xc0,0x03,0x10,0x60,0x81,0xf3,0x10,0x88,0x10,0xbc,0x70,0x47,0xf8,0x01,0x00,0x20, +0x00,0xe2,0x00,0xe0,0x40,0xba,0x70,0x47,0xc0,0xba,0x70,0x47, +}; +#endif + +#if (_PATCH_MULTI_CON_) +static __align(64) unsigned char patch_7_Array[] = +{ + 0x4b,0x75,0x00,0x2d,0x05,0xd0,0x39,0x8f,0x00,0x29,0x02,0xd0,0x00,0x99,0x89,0x79, + 0x00,0xe0,0x00,0x21,0x11,0x76,0xfa,0xf7,0x4b,0xf8,0x04,0x4d,0x28,0x59,0xf9,0xf7, + 0xfb,0xfe,0x00,0x20,0x28,0x51,0x05,0xb0,0xf0,0xbd,0x00,0x00,0x00,0x04,0x00,0x20, + 0x07,0x02,0x00,0x00, //0xf0,0xb5,0x0c,0x46,0x93,0xb0,0x09,0x78,0x0b,0x91,0x48,0x22, + 0x38,0xb5,0x04,0x9c,0x00,0x94,0x01,0x4c,0xa0,0x47,0x38,0xbd +}; + +static __align(64) unsigned char patch_8_Array[] = +{ + 0x51,0x43,0xf8,0x4a,0x26,0x46,0x8f,0x18,0x39,0x46,0x20,0x36,0xfd,0x6d,0x70,0x7d, + 0x80,0x31,0x11,0x91,0xc9,0x7f,0xa0,0x37,0x0e,0x91,0x22,0x46,0x39,0x78,0x15,0x32, + 0x0f,0x92,0xf1,0x4a,0x10,0x92,0x03,0x29,0x2b,0xd0,0x00,0x28,0x73,0xd0,0xf1,0x7d, + 0x0f,0x98,0x0c,0xf0,0x0d,0xf8,0x00,0x28,0x6f,0xd0,0x68,0x88,0x69,0x46,0x08,0x83 +}; + +static __align(4) unsigned char fun_8_Array[] ={ +0xf0,0xb5,0x97,0xb0,0x08,0x78,0x0c,0x46,0x0f,0x90,0x00,0x20,0x14,0x90,0x0f,0x98, +0x48,0x21,0x48,0x43,0xfe,0x49,0x22,0x46,0x40,0x18,0x06,0x46,0x80,0x36,0x10,0x90, +0xf1,0x7f,0x00,0x91,0xc5,0x6d,0xa0,0x30,0x16,0x90,0x01,0x78,0x15,0x32,0x27,0x46, +0x12,0x92,0x20,0x37,0xf7,0x4a,0x15,0x92,0x03,0x29,0x2a,0xd0,0x61,0x78,0x3c,0x29, +0x49,0xd0,0x43,0x29,0x47,0xd0,0x78,0x7d,0x00,0x28,0x7d,0xd0,0xf9,0x7d,0x12,0x98, +0x00,0xf0,0xfc,0xf9,0x00,0x28,0x78,0xd0,0x69,0x88,0x68,0x46,0x81,0x84,0x68,0x7a, +0x29,0x7a,0x00,0x04,0x09,0x02,0x08,0x43,0xe9,0x79,0x08,0x43,0x06,0x90,0xa9,0x7a, +0x08,0xa8,0x41,0x72,0xe9,0x7a,0x81,0x72,0x29,0x7b,0xc1,0x72,0x29,0x46,0x0d,0x31, +0x0e,0x38,0x0e,0x91,0x00,0xf0,0x2f,0xfa,0xa8,0x78,0x40,0x07,0x33,0xd5,0x00,0x21, +0x32,0xe0,0x90,0x7e,0x01,0x28,0x06,0xd0,0x50,0x7e,0x40,0x1e,0x00,0x06,0x00,0x0e, +0x50,0x76,0x03,0xd0,0x06,0xe0,0x00,0x21,0xdb,0x48,0x01,0xe0,0x00,0x21,0xdb,0x48, +0x00,0xf0,0xd2,0xf9,0x16,0x9a,0x01,0x21,0x11,0x70,0xa9,0x78,0xd4,0x48,0xc9,0x07, +0x5c,0xd0,0x00,0x99,0x48,0x23,0x59,0x43,0x08,0x18,0x00,0x22,0xa0,0x30,0x02,0x70, +0xff,0x20,0xf0,0x77,0x52,0xe0,0x01,0x22,0x02,0x70,0xa8,0x78,0xcc,0x49,0xc0,0x07, +0x4c,0xd0,0x00,0x98,0x48,0x23,0x58,0x43,0x40,0x18,0x00,0x22,0xa0,0x30,0x02,0x70, +0xff,0x20,0xf0,0x77,0x42,0xe0,0xe9,0x7c,0x08,0xa8,0x01,0x73,0x29,0x7d,0x41,0x73, +0x69,0x7d,0x81,0x73,0xa9,0x7d,0xc1,0x73,0x69,0x7d,0x01,0x74,0x29,0x7e,0x41,0x74, +0x69,0x7e,0x81,0x74,0xb1,0x89,0x68,0x46,0x81,0x81,0xf1,0x89,0xc1,0x81,0x31,0x8a, +0x01,0x82,0x10,0x99,0x40,0x31,0x8a,0x8f,0x82,0x83,0xc9,0x8f,0x01,0x84,0xb1,0x88, +0xc1,0x83,0xf1,0x88,0x41,0x84,0x00,0x21,0xc1,0x84,0x08,0xa8,0x01,0x72,0xb8,0x48, +0x81,0x78,0x08,0xa8,0xc1,0x74,0x01,0xe0,0x4d,0xe1,0x1b,0xe0,0x02,0x26,0x06,0x75, +0x00,0x29,0x02,0xd0,0xa8,0x78,0x40,0x07,0x02,0xd4,0xe8,0x7a,0x80,0x07,0x05,0xd5, +0x29,0x7b,0x0e,0x98,0x00,0xf0,0x7e,0xf9,0x08,0xa9,0x08,0x75,0x03,0xa9,0x0f,0x98, +0x00,0xf0,0x7e,0xf9,0x00,0x28,0x01,0xd1,0x16,0x98,0x06,0x70,0x60,0x78,0x3c,0x28, +0x70,0xd0,0x30,0xe1,0x62,0x88,0x69,0x46,0x0a,0x82,0xa2,0x88,0x4a,0x82,0xa2,0x79, +0x0a,0x75,0xe2,0x79,0x4a,0x75,0x20,0x7a,0x88,0x75,0xe0,0x7e,0xc8,0x75,0xa0,0x8b, +0x08,0x83,0xe0,0x8b,0x48,0x83,0x20,0x8c,0x88,0x83,0x60,0x8c,0xc8,0x83,0x21,0x46, +0x24,0x31,0x08,0xa8,0x00,0xf0,0xa4,0xf9,0x78,0x7a,0x08,0xa9,0x48,0x71,0xb8,0x7a, +0x88,0x71,0xa0,0x8d,0x69,0x46,0x08,0x85,0x20,0x6b,0x0b,0x90,0x00,0x20,0x0c,0x90, +0x01,0x20,0x08,0xa9,0x48,0x75,0x38,0x7d,0x08,0x75,0xb8,0x7d,0x88,0x75,0xa8,0x78, +0xc0,0x06,0xc0,0x17,0x40,0x1c,0xc8,0x75,0x8e,0x48,0x69,0x46,0x02,0x8a,0x0a,0x87, +0x42,0x8a,0x4a,0x87,0x82,0x7d,0x08,0xa9,0x0a,0x77,0xc2,0x7d,0x4a,0x77,0x02,0x7e, +0x8a,0x77,0x42,0x8b,0x10,0xa9,0x0a,0x80,0x82,0x8b,0x4a,0x80,0x80,0x7f,0x08,0x71, +0x04,0xa9,0x00,0x98,0x00,0xf0,0x32,0xf9,0x00,0x98,0x48,0x21,0x48,0x43,0x7c,0x49, +0x40,0x18,0x03,0x90,0x7c,0x30,0x12,0x99,0x00,0xf0,0x5d,0xf9,0x03,0x98,0xf9,0x7d, +0x80,0x30,0x81,0x70,0x03,0x99,0x09,0x22,0xa0,0x31,0x0a,0x70,0x01,0x21,0xc1,0x70, +0x03,0x98,0x00,0x21,0x81,0x66,0xe1,0x8b,0x49,0x00,0x41,0x66,0x05,0x21,0xc1,0x66, +0x01,0x67,0x15,0x99,0x60,0x30,0xc9,0x7e,0x00,0x29,0x04,0xd0,0x72,0x49,0x81,0x61, +0x01,0x21,0x02,0xe0,0x2a,0xe0,0x00,0x21,0x81,0x61,0x81,0x75,0x00,0x99,0x81,0x82, +0xf9,0x7d,0x12,0x98,0x00,0xf0,0xf6,0xf8,0x02,0x28,0x02,0xd2,0x01,0x21,0x00,0xf0, +0x03,0xf9,0xf9,0x7d,0x12,0x98,0x00,0xf0,0x05,0xf9,0x06,0x28,0x0c,0xd2,0x0a,0x21, +0x5f,0x4a,0x41,0x43,0x89,0x18,0xff,0x31,0x81,0x31,0x49,0x7f,0x89,0x07,0x03,0xd5, +0xfa,0x7d,0x12,0x99,0x00,0xf0,0xfc,0xf8,0x00,0x98,0x00,0xf0,0xff,0xf8,0x16,0x99, +0x01,0x20,0x08,0x70,0xff,0x20,0xf0,0x77,0x01,0x20,0x14,0x90,0x09,0x20,0x00,0xf0, +0xfb,0xf8,0x21,0x46,0x0f,0x31,0x05,0x91,0x00,0x28,0x4e,0xd0,0x20,0x23,0x3e,0x22, +0x00,0x21,0x56,0x48,0x00,0xf0,0xf6,0xf8,0x06,0x46,0x0a,0x20,0x30,0x70,0x14,0x98, +0x00,0x28,0x01,0xd0,0x00,0x20,0x00,0xe0,0x3c,0x20,0x70,0x70,0x01,0x20,0x30,0x71, +0x00,0x98,0x70,0x80,0x14,0x98,0x00,0x28,0x2c,0xd0,0xb0,0x1d,0x12,0x99,0x00,0xf0, +0xf2,0xf8,0xf8,0x7d,0x70,0x71,0xe8,0x7a,0x80,0x07,0x06,0xd5,0x21,0x46,0x30,0x46, +0x09,0x31,0x0c,0x30,0x00,0xf0,0xe7,0xf8,0x03,0xe0,0x30,0x46,0x0c,0x30,0x00,0xf0, +0xdd,0xf8,0xf8,0x7d,0x80,0x07,0x05,0xd5,0x30,0x46,0x12,0x30,0x05,0x99,0x00,0xf0, +0xda,0xf8,0x03,0xe0,0x30,0x46,0x12,0x30,0x00,0xf0,0xd0,0xf8,0xe0,0x8b,0x30,0x83, +0x20,0x8c,0x70,0x83,0x60,0x8c,0xb0,0x83,0xb8,0x7a,0xb0,0x77,0x30,0x46,0x00,0xf0, +0xbf,0xf8,0x3a,0xe0,0x28,0x7b,0x70,0x71,0x29,0x46,0x0d,0x31,0xb0,0x1d,0x00,0xf0, +0xc2,0xf8,0x30,0x46,0x00,0xf0,0xb4,0xf8,0x3d,0xe0,0x14,0x23,0x3e,0x22,0x00,0x21, +0x2e,0x48,0x00,0xf0,0xa7,0xf8,0x01,0x21,0x06,0x46,0x01,0x70,0x14,0x98,0x00,0x28, +0x0d,0xd0,0x00,0x20,0x70,0x70,0x31,0x71,0x00,0x98,0x70,0x80,0xf8,0x7d,0x82,0x07, +0x09,0xd5,0x71,0x71,0xb0,0x1d,0x05,0x99,0x00,0xf0,0xa5,0xf8,0x0a,0xe0,0x3c,0x20, +0x70,0x70,0x30,0x46,0x1d,0xe0,0xc0,0x07,0xc0,0x0f,0x70,0x71,0xb0,0x1d,0x12,0x99, +0x00,0xf0,0x99,0xf8,0xe0,0x8b,0xb0,0x81,0x20,0x8c,0xf0,0x81,0x60,0x8c,0x30,0x82, +0xb8,0x7a,0xb0,0x74,0x30,0x46,0x00,0xf0,0x83,0xf8,0x06,0x23,0x3e,0x22,0x00,0x21, +0x16,0x48,0x00,0xf0,0x77,0xf8,0x14,0x21,0x01,0x70,0x00,0x99,0x41,0x80,0xb9,0x7d, +0x01,0x71,0x00,0xf0,0x75,0xf8,0x15,0x98,0x80,0x7e,0x02,0x28,0x26,0xd1,0x60,0x78, +0x14,0x99,0x08,0x43,0x22,0xd0,0x08,0x23,0x3e,0x22,0x00,0x21,0x0b,0x48,0x00,0xf0, +0x61,0xf8,0x12,0x21,0x01,0x70,0x61,0x78,0x41,0x70,0x29,0x78,0x81,0x70,0x0f,0xe0, +0x40,0x04,0x00,0x20,0xc0,0x06,0x00,0x20,0x0a,0x20,0x00,0x00,0x39,0x20,0x00,0x00, +0x40,0x06,0x00,0x20,0x00,0x06,0x00,0x20,0xb1,0xa2,0x01,0x00,0x04,0x11,0x00,0x00, +0x00,0x99,0x81,0x80,0x39,0x7e,0x81,0x71,0x00,0xf0,0x4a,0xf8,0x00,0x20,0x17,0xb0, +0xf0,0xbd,0x00,0x00,0x40,0xba,0x70,0x47,0xc0,0xba,0x70,0x47,0x03,0xb4,0x01,0x48, +0x01,0x90,0x01,0xbd,0x91,0x9b,0x02,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd, +0xe1,0x98,0x02,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x7d,0x9f,0x02,0x00, +0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x49,0xfa,0x01,0x00,0x03,0xb4,0x01,0x48, +0x01,0x90,0x01,0xbd,0x09,0xd3,0x01,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd, +0x6d,0x5b,0x02,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x3d,0x99,0x02,0x00, +0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0xe1,0x90,0x02,0x00,0x03,0xb4,0x01,0x48, +0x01,0x90,0x01,0xbd,0x55,0x07,0x01,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd, +0xd5,0x9c,0x02,0x00,0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x39,0x7b,0x01,0x00, +0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0x79,0x6d,0x01,0x00,0x00,0x21,0x01,0x80, +0x41,0x80,0x81,0x80,0x70,0x47,0x0a,0x78,0x02,0x70,0x4b,0x78,0x43,0x70,0x8a,0x78, +0x82,0x70,0xca,0x78,0xc2,0x70,0x0b,0x79,0x03,0x71,0x4a,0x79,0x42,0x71,0x70,0x47, +0x0a,0x68,0x02,0x60,0x0b,0x79,0x03,0x71,0x70,0x47,0x00,0x00, +}; +#endif + +#if (_3_CONN_) +static __align(64) unsigned char patch_9_Array[] = +{ + 0x49,0x7b,0x41,0x70,0x05,0x70,0xf1,0xf7,0xf3,0xfc,0x20,0x68,0xf1,0xf7,0xa4,0xfb, + 0x25,0x60,0x03,0xb0,0xf0,0xbd,0x00,0x00,0x24,0x00,0x00,0x20,0x00,0x80,0x02,0x40, + 0x80,0xc1,0x02,0x40,0x06,0x02,0x00,0x00,0xf8,0xb5,0x4e,0x78,0x48,0x21,0xf0,0xb2, + 0x48,0x43,0x23,0x49,0x21,0x4d,0x41,0x18,0x0c,0x46,0xaa,0x7e,0xa0,0x34,0x00,0x27 +}; +#endif + +/* Public function prototypes -----------------------------------------------*/ + +static __inline void patchx_enable(uint32_t patch_num, uint32_t dst_addr, uint32_t src_addr) +{ + if(patch_num >= 16) + return; + PATCH->PATCHDATAx[patch_num].RomAddrx = dst_addr >> 6; + PATCH->PATCHDATAx[patch_num].PatchAddrx = src_addr >> 6; + PATCH->PATCHEN |= 1<< patch_num; +} + + + +extern void RCC_EnableAHBPeriphClk(uint32_t RCC_AHBPeriph, FunctionalState Cmd); +static __inline void NS_BLE_PATCH_INIT(void) +{ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_PATCH, ENABLE); + + #if (_PATCH_LLD_COM_) + REG32(np_lld_con_frm_cbk_addr) = (uint32_t)lld_con_Array + np_lld_con_frm_cbk; + REG32(np_lld_con_evt_canceled_cbk_addr) = (uint32_t)lld_con_Array + np_lld_con_evt_canceled_cbk; + REG32(np_lld_con_evt_start_cbk_addr) = (uint32_t)lld_con_Array + np_lld_con_evt_start_cbk; + + //patch 0 + REG32(patch_0_Array+PATCH_RAM_ADDR_OFFSET_0) = (uint32_t)lld_con_Array+PATCH_0_FUNC_OFFSET; + patchx_enable(0, PATCH_ROM_ADDR_0, (uint32_t)patch_0_Array); + + //patch 1 + REG32(patch_1_Array+PATCH_RAM_ADDR_OFFSET_1) = (uint32_t)lld_con_Array+PATCH_1_FUNC_OFFSET; + patchx_enable(1, PATCH_ROM_ADDR_1, (uint32_t)patch_1_Array); + + //patch 2 + REG32(patch_2_Array+PATCH_RAM_ADDR_OFFSET_2) = (uint32_t)lld_con_Array+PATCH_2_FUNC_OFFSET; + patchx_enable(2, PATCH_ROM_ADDR_2, (uint32_t)patch_2_Array); + + //patch 3 + REG32(patch_3_Array+PATCH_RAM_ADDR_OFFSET_3) = (uint32_t)lld_con_Array+PATCH_3_FUNC_OFFSET; + patchx_enable(3, PATCH_ROM_ADDR_3, (uint32_t)patch_3_Array); + #endif //(_PATCH_LATENCY_) + + #if (_PATCH_KE_TIMER_SET_) + patchx_enable(4, PATCH_ROM_ADDR_4, (uint32_t)patch_4_Array); + REG32(patch_5_Array+PATCH_RAM_ADDR_OFFSET_5) = (uint32_t)fun_5_Array+1; + patchx_enable(5, PATCH_ROM_ADDR_5, (uint32_t)patch_5_Array); + #endif + + #if (_PATCH_KE_MSG_SET_) + REG32(patch_6_Array+PATCH_RAM_ADDR_OFFSET_6) = (uint32_t)fun_6_Array+1; + patchx_enable(6, PATCH_ROM_ADDR_6, (uint32_t)patch_6_Array); + #endif + + #if (_PATCH_MULTI_CON_) + patchx_enable(7, PATCH_ROM_ADDR_7, (uint32_t)patch_7_Array); + REG32(patch_8_Array+PATCH_RAM_ADDR_OFFSET_8) = (uint32_t)fun_8_Array+1; + patchx_enable(8, PATCH_ROM_ADDR_8, (uint32_t)patch_8_Array); + #endif + + #if (_3_CONN_) + patchx_enable(9, PATCH_ROM_ADDR_9, (uint32_t)patch_9_Array); + #endif +} + + +static __inline void NS_BLE_STACK_INIT() +{ + PWR->VTOR_REG = 0; + g_modem_flag = MODEM_CHIP; + g_app_init_branch = false; + g_clock_src = HSI_CLK; + g_system_hsi_clk = HSI_VALUE; + g_cal_hsi_cnt_value = HSI_64M_VAL; + g_delay_div_param = 79; + g_delay_us_div_param = 8; + llm_local_le_feats.feats[0] = 0xff; + llm_local_le_feats.feats[1] = 0xff; + llm_local_le_feats.feats[2] = 0xff; + llm_local_le_feats.feats[3] = 0x07; + llm_local_le_feats.feats[4] = 0x00; + llm_local_le_feats.feats[5] = 0x00; + llm_local_le_feats.feats[6] = 0x00; + llm_local_le_feats.feats[7] = 0x00; + REG32(0x200000dc) =(uint32_t) prf_add_profile; + REG32(0x200000e0) =(uint32_t) prf_get_task_from_id; + REG32(0x200000e4) =(uint32_t) prf_get_id_from_task; + rwip_init(RESET_NO_ERROR); + +} + + +#ifdef __cplusplus +} +#endif + +#endif /* __BLE_STACK_COMMON_H_*/ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/global_func.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/global_func.h new file mode 100644 index 0000000..ff5f860 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/global_func.h @@ -0,0 +1,150 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file global_func.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/* Includes ------------------------------------------------------------------*/ +#include +#include +#include +#include "n32wb03x.h" +#include "global_var.h" +#include "Typedefine.h" + +#include "rwip_config.h" // SW configuration +#include "compiler.h" +#include "co_version.h" // version information +#include "co_utils.h" +#include "co_bt.h" // Common BT Definitions +#include "co_math.h" // Common Maths Definition +#include "co_bt_defines.h" + + +#include "arch.h" // Platform architecture definition +#include "em_map.h" +#include "rf.h" + +#include "rwip.h" // RW definitions +#include "rwip_int.h" // RW internal definitions +#include "rwip_task.h" // Task definitions + +#include "sch_alarm.h" // for the half slot target ISR +#include "sch_arb.h" // for the half us target ISR +#include "sch_prog.h" // for the fifo/clock ISRs +#include "reg_ipcore.h" +#include "reg_blecore.h" +#include "aes.h" // AES result function +#include "rwble.h" // for sleep and wake-up specific functions +#include "lld.h" // for AES encryption handler + +#include "ke.h" // kernel definition +#include "ke_event.h" // kernel event +#include "ke_timer.h" // definitions for timer +#include "ke_mem.h" // kernel memory manager +#include "ke_task.h" // Kernel Task + + +#include "rwble_hl.h" // BLE HL definitions +#include "l2cc.h" +#include "llm_int.h" +#include "ahi_task.h" +#include "co_hci.h" +#include "hci.h" +#include "attm.h" +#include "atts.h" +#include "prf.h" +#include "gap.h" +#include "gapm.h" +#include "gapm_int.h" +#include "gapm_task.h" // GAP Manager Task API +#include "gapc.h" +#include "gapc_task.h" // GAP Controller Task API Definition +#include "gattm_int.h" +#include "gattc.h" +#include "gatt.h" + +#include "ble_stack_common.h" +#include "ns_adv_data_def.h" + +#ifndef _GLOBAL_FUNC_H_ +#define _GLOBAL_FUNC_H_ + +/* Public typedef -----------------------------------------------------------*/ +typedef void (*IRQ_HANNDLE_FUN) (void); + +/* Public define ------------------------------------------------------------*/ +#define GLOBAL_INT_DISABLE() \ +uint32_t ui32IntStatus = 0; \ +do{ \ + ui32IntStatus = __get_PRIMASK();\ + __set_PRIMASK(1); \ +}while(0) + +#define GLOBAL_INT_RESTORE() \ +do{ \ + __set_PRIMASK(ui32IntStatus);\ +}while(0) + + +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ + +extern uint32_t calib_lsi_clk(void); +extern void EXTI_PA11_Configuration(void); +extern uint32_t ModuleIrqRegister(IRQn_Type irqn,IRQ_HANNDLE_FUN fun); +extern uint32_t ModuleIrqRemoval(IRQn_Type irqn); + +extern void rwip_slp_isr(void); +extern void rf_tx_power_set(rf_tx_power_t pwr); +#endif //_GLOBAL_FUNC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/global_var.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/global_var.h new file mode 100644 index 0000000..ff00166 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/global_var.h @@ -0,0 +1,277 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file global_var.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef __GLOBAL_VER_H__ +#define __GLOBAL_VER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stdint.h" +#include "stdbool.h" + +/* Public typedef -----------------------------------------------------------*/ +typedef enum +{ + TX_POWER_0_DBM = 0, /* 0 dBm */ + TX_POWER_Neg2_DBM, /* -2 dBm */ + TX_POWER_Neg4_DBM, /* -4 dBm */ + TX_POWER_Neg8_DBM, /* -8 dBm */ + TX_POWER_Neg15_DBM, /* -12 dBm */ + TX_POWER_Neg20_DBM, /* -16 dBm */ + TX_POWER_Pos2_DBM, /* +2 dBm */ + TX_POWER_Pos3_DBM, /* +3 dBm */ + TX_POWER_Pos4_DBM, /* +4 dBm */ + TX_POWER_Pos6_DBM, /* +6 dBm */ + + TX_POWER_MAX_VAL = TX_POWER_Pos6_DBM, +}rf_tx_power_t; + +static const uint8_t TXPWR_MAP[][3]= +{ +0, 0x17, 0x13, /* 0 dBm */ +0, 0x17, 0x10, /* -2 dBm */ +0, 0x17, 0x0e, /* -4 dBm */ +0, 0x17, 0x09, /* -8 dBm */ +0, 0x17, 0x04, /* -12 dBm */ +0, 0x17, 0x00, /* -16 dBm */ +0, 0x17, 0x18, /* +2 dBm */ +1, 0x17, 0x14, /* +3 dBm */ +1, 0x17, 0x15, /* +4 dBm */ +1, 0x17, 0x19, /* +6 dBm */ +}; + +/* Public define ------------------------------------------------------------*/ + + + +/* Public variables ---------------------------------------------------------*/ + +#define N32WB02X_FLASH 2 +#define N32WB02X_CHIP 1 + +//N32WB02X_CHIP +#define N32WB02X_TYPE N32WB02X_CHIP + +#define HSE_CLK 1 +#define HSI_CLK 0 +extern uint8_t g_clock_src; +extern uint8_t g_phy_2mbps_support; +extern uint8_t g_auto_start_data_length_req; +extern uint32_t g_system_hsi_clk; +extern uint8_t g_sleep_sleep_enable; +extern uint8_t g_sleep_status_flag; +extern uint8_t g_status_io_stat; +extern uint32_t g_timeoutcnt; //TODO add global var + +//32k----global var +extern uint32_t g_lsi_accuracy; +extern uint32_t g_lsi_count_n_syscle; +extern uint32_t g_lsi_1_syscle_cal_value; +extern uint32_t g_lsi_1_syscle_cnt_value; +extern uint8_t g_recalib_lsi_flag; //0 no recalib 1: recalib + + +//32M----global var +extern uint32_t g_hsi_accuracy; +extern uint16_t g_calib_stat_flag; +extern uint8_t g_recalib_hsi_flag; //0 no recalib 1: recalib + + +//64M 2048 96M 3072 +#define HSI_32M_VAL 1024 +#define HSI_64M_VAL 2048 +#define HSI_96M_VAL 3072 +extern uint16_t g_cal_hsi_cnt_value; //64M + +//modem flag +#define MODEM_CHIP 1 +extern uint8_t g_modem_flag; + + +extern bool g_hci_transport_onff; + +//modify hci +#define HCI_TRANS_NORMAL 0 +#define HCI_TRANS_SOFT_FLOW 1 +extern uint8_t g_hci_transport_type; //0: traditional mode 1: modify mode + +#define STAGE_IDLE 0x20 +#define STAGE_TX 0x40 +#define STAGE_RX 0x80 +#define STAGE_IDLE_DMA_LEN 3 +extern uint8_t g_hci_transport_process; //0x00: idle 0x40: tx process 0x80: rx process +extern uint16_t g_acl_tx_sch_interval; +extern uint8_t acl_flow_ctrl_num; +extern uint8_t acl_flow_ctrl; + + +extern uint8_t* g_soft_flow_tx_buf; +extern uint16_t g_soft_flow_tx_len; +extern void (*g_soft_flow_tx_callback)(void*, uint8_t); +extern void * g_soft_flow_tx_dummy; +extern uint16_t g_soft_flow_rx_len; +extern uint16_t g_length_2_data_intv; + +#define HCI_LPUART 0x0 +#define HCI_SPI 0x1 +extern uint8_t g_hci_ch_type; + + +extern uint32_t g_uart_irq_wakeup_time; +extern uint32_t g_spi_data_ready_2_irq_rise; + +extern uint32_t dma_recv_data_time_window_size; +extern uint32_t g_uart_bps; + + +extern uint32_t g_saverc32kcnt; +extern uint8_t g_delay_div_param; +extern uint8_t g_delay_us_div_param; + + + +/// Radio Drift +extern uint16_t g_lpclk_drift; // 500ppm +///IFS +extern uint8_t g_rx_ifs; +extern uint8_t g_tx_ifs; + +extern uint16_t g_adv_int_undirect; +extern uint16_t g_adv_int_direct; + +extern uint16_t g_max_octets; +extern uint16_t g_max_time; + +extern uint16_t g_company_id; +extern uint8_t g_version_sw_major; +extern uint8_t g_version_sw_minor; +extern uint8_t g_version_sw_build; + +extern bool g_loop_test; +extern bool g_ota_test; +extern bool g_ota_test_mtu_247_dle; +extern bool g_app_init_branch; +extern uint16_t g_adv_intv; +extern uint16_t g_uart_change_delay; +extern uint8_t g_delay_recv_more_data; +extern uint16_t g_uart_irq_rise_wait_time; +extern uint8_t g_ltk_req_neg_reply; +extern uint8_t g_debug_printf; + +extern uint16_t g_twrm; +extern uint16_t g_twosc; +extern uint16_t g_twext; +extern uint8_t rwip_prog_delay; + +extern uint16_t g_rc32k_trim; +extern uint8_t (* prf_add_profile_ptr)(void * params, uint16_t *prf_task); +extern uint16_t (*prf_get_task_from_id_ptr)(uint16_t ); +extern uint16_t (*prf_get_id_from_task_ptr)(uint16_t task); +extern void (*SVC_IRQHandler_ptr)(uint8_t); +extern void (*NMI_IRQHandler_ptr)(void) ; +extern void (*HardFault_Handler_ptr)(void); +extern void (*SysTick_IRQHandler_ptr)(void); +extern void (*PendSV_IRQHandler_ptr)(void); + +extern bool g_ramcode_work_flag; +extern uint8_t g_sch_prog_fifo_iar_branch; +extern uint8_t g_sch_arb_insert_branch; +extern bool g_le_coded_phy_500; +#define BT_DEFAULT_BDADDR {{0x11, 0x22, 0x33, 0x33, 0x22, 0x33}} +extern struct bd_addr g_co_default_bdaddr; + +//extern uint8_t BLE_NORMAL_WIN_SIZE; +//extern uint8_t BLE_RX_DESC_NB; +//extern uint8_t RWIP_MINIMUM_SLEEP_TIME; +extern uint16_t SCH_SCAN_EVT_DUR_DFT; +extern struct le_features llm_local_le_feats; + +extern uint32_t g_rwip_patch_addr; +extern uint16_t g_rwip_patch_addr_size; +extern uint32_t g_eeprom_start_addr; + +extern uint32_t g_rwip_heap_env; +extern uint16_t g_rwip_heap_env_size; +extern uint32_t g_rwip_heap_db; +extern uint16_t g_rwip_heap_db_size; +extern uint32_t g_rwip_heap_msg; +extern uint32_t g_rwip_heap_msg_size; +extern uint32_t g_rwip_heap_non_ret; +extern uint32_t g_rwip_heap_non_ret_size; + +extern uint8_t* utils_recv_buf_ptr; +extern uint16_t utils_max_buf_len; + +extern uint8_t* g_attr_table; +extern uint16_t ATTR_TABLE_LENGTH; + +extern uint8_t* g_app_tx_buf_ptr; +extern uint16_t g_app_tx_buf_len; + +extern uint8_t* g_app_bone_table_ptr; +extern uint16_t g_app_bone_table_size; +extern struct prf_task_cbs* g_cbs; + +void reinit_params(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __GLOBAL_VER_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip.c new file mode 100644 index 0000000..a4c1cee --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip.c @@ -0,0 +1,401 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwip.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#include "rwip_config.h" // RW SW configuration + +#if (NVDS_SUPPORT) +#include "nvds.h" // NVDS definitions +#endif // NVDS_SUPPORT + +#if (BT_EMB_PRESENT) +#include "rwbt.h" // rwbt definitions +#endif //BT_EMB_PRESENT + +#if (BLE_EMB_PRESENT) +#include "rwble.h" // rwble definitions +#endif //BLE_EMB_PRESENT + +#if (BLE_HOST_PRESENT) +#include "rwble_hl.h" // BLE HL definitions +#include "gapc.h" +#include "gapm.h" +#include "gattc.h" +#include "l2cc.h" +#endif //BLE_HOST_PRESENT + + +#if (BT_EMB_PRESENT) +#include "ld.h" +#endif //BT_EMB_PRESENT + +#if (DISPLAY_SUPPORT) +#include "display.h" // display definitions +#include "co_utils.h" // toolbox +//#include "plf.h" // platform definition +#if (BT_EMB_PRESENT) +#include "reg_btcore.h" +#endif // (BT_EMB_PRESENT) +#if (BLE_EMB_PRESENT) +#include "reg_blecore.h" +#endif // (BLE_EMB_PRESENT) +#if (BT_DUAL_MODE) +#include "reg_ipcore.h" +#endif // (BT_DUAL_MODE) +#endif //DISPLAY_SUPPORT + +#if (BT_EMB_PRESENT || BLE_EMB_PRESENT) +#include "sch_arb.h" // Scheduling Arbiter +#include "sch_prog.h" // Scheduling Programmer +#include "sch_plan.h" // Scheduling Planner +#include "sch_slice.h" // Scheduling Slicer +#include "sch_alarm.h" // Scheduling Alarm +#endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + +#if (BT_EMB_PRESENT || BLE_EMB_PRESENT) +#include "rf.h" // RF definitions +#endif //BT_EMB_PRESENT || BLE_EMB_PRESENT + +#if (H4TL_SUPPORT) +#include "h4tl.h" +#endif //H4TL_SUPPORT + +#if (AHI_TL_SUPPORT) +#include "ahi.h" +#endif //AHI_TL_SUPPORT + +#if (HCI_PRESENT) +#include "hci.h" // HCI definition +#endif //HCI_PRESENT + + +#if (BT_EMB_PRESENT || BLE_EMB_PRESENT) +#include "ecc_p256.h" // ECC P256 library +#endif // (BT_EMB_PRESENT || BLE_EMB_PRESENT) + +#include "aes.h" // For AES functions + +#if (BLE_EMB_PRESENT) +#include "reg_blecore.h" // ble core registers +#endif //BLE_EMB_PRESENT + +#if (BT_EMB_PRESENT) +#include "reg_btcore.h" // bt core registers +#endif //BT_EMB_PRESENT + +#include "dbg.h" // debug definition +#include "global_func.h" + +#define rwip_rst_state REG32(0X20000000) + +extern void llhwc_phy_prerx_flash(void); +#ifdef READ_HSE_MCO_FROM_TRIM_DEMO +extern void read_hse_freq_and_config_demo(void); +#endif +void rwip_init(uint32_t error) +{ + // IP initialization + rwip_rst_state = RWIP_INIT; + + // Initialize kernel + ke_init(); + + // Initialize memory heap used by kernel. + // Memory allocated for environment variables + //ke_mem_init(KE_MEM_ENV, (uint8_t*)rwip_heap_env, RWIP_CALC_HEAP_LEN_IN_BYTES(RWIP_HEAP_ENV_SIZE)); + ke_mem_init(KE_MEM_ENV, (uint8_t*)g_rwip_heap_env, g_rwip_heap_env_size); + + #if (BLE_HOST_PRESENT) + // Memory allocated for Attribute database + //ke_mem_init(KE_MEM_ATT_DB, (uint8_t*)rwip_heap_db, RWIP_CALC_HEAP_LEN_IN_BYTES(RWIP_HEAP_DB_SIZE)); + ke_mem_init(KE_MEM_ATT_DB, (uint8_t*)g_rwip_heap_db, g_rwip_heap_db_size); + + #endif // (BLE_HOST_PRESENT) + // Memory allocated for kernel messages + //ke_mem_init(KE_MEM_KE_MSG, (uint8_t*)rwip_heap_msg, RWIP_CALC_HEAP_LEN_IN_BYTES(RWIP_HEAP_MSG_SIZE)); + ke_mem_init(KE_MEM_KE_MSG, (uint8_t*)g_rwip_heap_msg, g_rwip_heap_msg_size); + + // Non Retention memory block + //ke_mem_init(KE_MEM_NON_RETENTION, (uint8_t*)rwip_heap_non_ret, RWIP_CALC_HEAP_LEN_IN_BYTES(RWIP_HEAP_NON_RET_SIZE)); + ke_mem_init(KE_MEM_NON_RETENTION, (uint8_t*)g_rwip_heap_non_ret, g_rwip_heap_non_ret_size); + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + #if (RW_DEBUG) + // Initialize the debug process + dbg_init(rwip_rst_state); + #endif //(RW_DEBUG) + #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + + //DONE TRANSPLANT + // Initialize RF + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + + REG32(MODEM_BASE +0x59*4) |= 0xF0; + rf_init(&rwip_rf); + + ble_radiopwrupdn0_pack( 0,0x50,0x02,0x50); + ble_radiotxrxtim1_pack( 0x0f,0x8,0x0); + ble_radiopwrupdn2_pack( 0x00,0x6a,0x08,0x58); + ble_radiopwrupdn3_pack( 0x05,0x42); + ble_radiotxrxtim2_pack( 6,0x5,5,15); + ble_radiotxrxtim3_pack( 3,0xf,15); + ble_radiocntl2_pack(0,0,0,3,1,0,EM_FT_OFFSET>>2); + + llhwc_phy_prerx_flash(); + #endif //BT_EMB_PRESENT || BLE_EMB_PRESENT +#if READ_HSE_MCO_FROM_TRIM_DEMO + read_hse_freq_and_config_demo(); +#endif + #if (DISPLAY_SUPPORT) + // Initialize display module + display_init(); + + // Add some configuration information to display + display_add_config(); + #endif //DISPLAY_SUPPORT + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + // Initialize Diffie Hellman Elliptic Curve Algorithm + #if (BLE_ECC) + ecc_init(rwip_rst_state); + #endif //(BLE_ECC) + #endif // (BT_EMB_PRESENT || BLE_EMB_PRESENT) + + if(g_hci_transport_onff) + { + // Initialize H4TL + #if (H4TL_SUPPORT) + #if (H4TL_NB_CHANNEL > 1) + h4tl_init(1, rwip_eif_get(1)); + #endif // (H4TL_NB_CHANNEL > 1) + h4tl_init(0, rwip_eif_get(0)); + #endif //(H4TL_SUPPORT) + } + #if (HCI_PRESENT) + // Initialize the HCI + hci_init(rwip_rst_state); + #endif //HCI_PRESENT + + #if (AHI_TL_SUPPORT) + // Initialize the Application Host Interface + ahi_init(); + #endif //AHI_TL_SUPPORT + + #if (BLE_HOST_PRESENT) + // Initialize BLE Host stack + rwble_hl_init(rwip_rst_state); + #endif //BLE_HOST_PRESENT + + #if (BT_EMB_PRESENT) + // Initialize BT + rwbt_init(); + #endif //BT_EMB_PRESENT + + #if (BLE_EMB_PRESENT) + // Initialize BLE + rwble_init(rwip_rst_state); + #endif //BLE_EMB_PRESENT + + // Initialize IP core driver + rwip_driver_init(rwip_rst_state); + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + #if (RW_WLAN_COEX) + rwip_wlcoex_set(1); + #endif //(RW_WLAN_COEX) + #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + + #if (BT_EMB_PRESENT || (BLE_EMB_PRESENT && !BLE_HOST_PRESENT)) + // If FW initializes due to FW reset, send the message to Host + if(error != RESET_NO_ERROR) + { + if(error == RESET_TO_ROM || error == RESET_AND_LOAD_FW) + { + // Send platform reset command complete if requested by user + dbg_platform_reset_complete(error); + } + else + { + // Allocate a message structure for hardware error event + struct hci_hw_err_evt *evt = KE_MSG_ALLOC(HCI_EVENT, 0, HCI_HW_ERR_EVT_CODE, hci_hw_err_evt); + + // Fill the HW error code + switch(error) + { + case RESET_MEM_ALLOC_FAIL: evt->hw_code = CO_ERROR_HW_MEM_ALLOC_FAIL; break; + default: ASSERT_INFO(0, error, 0); break; + } + + // Send the message + hci_send_2_host(evt); + } + } + #endif //(BT_EMB_PRESENT || (BLE_EMB_PRESENT && !BLE_HOST_PRESENT)) + + /* + ************************************************************************************ + * Application initialization + ************************************************************************************ + */ +// #if (BLE_APP_PRESENT) +// // Initialize APP +// if(g_app_init_branch) +// { +// app_init(); +// } +// #endif //BLE_APP_PRESENT + + // Move to IP first reset state + rwip_rst_state = RWIP_1ST_RST; + + #if ((!BLE_HOST_PRESENT && BLE_EMB_PRESENT) || BT_EMB_PRESENT) + // Make a full initialization in split-emb mode + rwip_reset(); + #endif // ((!BLE_HOST_PRESENT && BLE_EMB_PRESENT) || BT_EMB_PRESENT) +} + + + +void rwip_reset(void) +{ + // Disable interrupts until reset procedure is completed + GLOBAL_INT_DISABLE(); + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + #if (RW_DEBUG) + // Reset dbg + dbg_init(rwip_rst_state); + #endif //(RW_DEBUG) + #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + + //Clear all message and timer pending + ke_flush(); + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + // Reset Diffie Hellman Elliptic Curve Algorithm + #if (BLE_ECC) + ecc_init(rwip_rst_state); + #endif //(BLE_ECC) + #endif // (BT_EMB_PRESENT || BLE_EMB_PRESENT) + + #if (HCI_PRESENT) + // Reset the HCI + hci_init(rwip_rst_state); + #endif //HCI_PRESENT + + #if (BLE_HOST_PRESENT) + // Initialize BLE Host stack + rwble_hl_init(rwip_rst_state); + #endif //BLE_HOST_PRESENT + + #if (BT_EMB_PRESENT) + if (rwip_rst_state == RWIP_RST) + { + // Reset BT + rwbt_reset(); + } + #endif //BT_EMB_PRESENT + + #if (BLE_EMB_PRESENT) + // Reset BLE + rwble_init(rwip_rst_state); + #endif //BLE_EMB_PRESENT + + // Reset AES + aes_init(rwip_rst_state); + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + // Reset Scheduling blocks + sch_arb_init(rwip_rst_state); + sch_prog_init(rwip_rst_state); + sch_plan_init(rwip_rst_state); + sch_alarm_init(rwip_rst_state); + sch_slice_init(rwip_rst_state); + #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + + #if (BLE_EMB_PRESENT || BT_EMB_PRESENT) + // Initialize IP core driver + rwip_driver_init(rwip_rst_state); + #endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + #if (RW_WLAN_COEX) + rwip_wlcoex_set(1); + #endif //(RW_WLAN_COEX) + + + if (rwip_rst_state == RWIP_RST) + { + // Reset the RF + rwip_rf.reset(); + } + #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + + + #if (DISPLAY_SUPPORT) + // Restart display module + display_resume(); + #endif //DISPLAY_SUPPORT + + // Move to normal IP reset state + rwip_rst_state = RWIP_RST; + + // Restore interrupts once reset procedure is completed + GLOBAL_INT_RESTORE(); +} + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip_driver.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip_driver.c new file mode 100644 index 0000000..1e1e881 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip_driver.c @@ -0,0 +1,597 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwip_driver.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#include "rwip_config.h" // RW SW configuration +#include "global_func.h" +#include "ns_ble.h" +extern __INLINE uint32_t co_max(uint32_t a, uint32_t b); +extern uint32_t OTPTrim_Read(uint32_t address, uint8_t* p_data, uint32_t byte_length); + +/* + * DEFINES + **************************************************************************************** + */ +#if (BLE_EMB_PRESENT || BT_EMB_PRESENT) +/// Sleep Duration Value in periodic wake-up mode in Half slots +#define MAX_SLEEP_DURATION_PERIODIC_WAKEUP 0x0640 // 0.5s + +/// Sleep Duration Value in external wake-up mode +#define MAX_SLEEP_DURATION_EXTERNAL_WAKEUP 0x7FFFFFF //(41943039ms) 0x7D00 //10s + +/** + * Inverse an intra-half-slot value (in half-us), from/to following formats: + * - A: elapsed time from the previous half-slot (in half-us) + * - B: remaining time to the next half-slot (in half-us) + * The function from A to B or from B to A. + * ____________________________________________________________________________________________________ + * Half-slot N-1 | Half-slot N | Half-slot N+1 + * ____________________________|______________________________________|________________________________ + * |<---------- A ---------->|<---- B --->| + * ____________________________|______________________________________|________________________________ + */ +#define HALF_SLOT_INV(x) (HALF_SLOT_SIZE - x - 1) + +#endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + +#ifndef TRIM_RADIO_FREQUENCY_ENABLE +#define TRIM_RADIO_FREQUENCY_ENABLE 1 +#endif + +#if TRIM_RADIO_FREQUENCY_ENABLE +#define STANDARD_MCO_FREQ 8000000 +#define TRIM_STORED_MARK 0xAA55 +#define TRIM_STORE_ADDR3 0x3000 + +typedef struct{ + uint16_t mark; + uint8_t user_mac[6]; + uint32_t f_cal; +}trim3_stored_t; +static uint32_t actual_frequency = 0xffffffff; +static uint32_t modem_reg_bc,modem_reg_bd,modem_reg_be; + +uint32_t radio_read_trim_mco_freq(void) +{ + trim3_stored_t trim3_read ={0}; + //read radio trim frim otp3 + OTPTrim_Read(TRIM_STORE_ADDR3, (uint8_t*)&trim3_read, sizeof(trim3_stored_t)); + if(trim3_read.mark == TRIM_STORED_MARK) + { + return trim3_read.f_cal; + } + return 0; // without trim value stored +} + +bool radio_read_trim_mac_address(uint8_t *p_mac) +{ + trim3_stored_t trim3_read ={0}; + //read radio trim frim otp3 + OTPTrim_Read(TRIM_STORE_ADDR3, (uint8_t*)&trim3_read, sizeof(trim3_stored_t)); + + if(trim3_read.mark == TRIM_STORED_MARK) + { + memcpy(p_mac,trim3_read.user_mac,6); + return true; + } + return false; // without trim value stored +} + +/* call initial and after sleep, */ +void radio_freq_cal_from_trim(void) +{ + if(actual_frequency < 8008000 && actual_frequency > 7002000 ) + { + REG32(MODEM_BASE + 0x2F0 ) = modem_reg_bc; //0xbc * 4 + REG32(MODEM_BASE + 0x2F4 ) = modem_reg_bd; //0xbd * 4 + REG32(MODEM_BASE + 0x2F8 ) = modem_reg_be; //0xbe * 4 + } +} + +void radio_hse_mco_set(uint32_t mco_freq) +{ + int32_t delta_fref; + float err; + uint32_t delta_k; + + actual_frequency = mco_freq; + delta_fref = STANDARD_MCO_FREQ - actual_frequency; + err = (float)delta_fref / (float)actual_frequency; + + if(delta_fref > 0) + { + delta_k = (uint32_t)(9838592 * err); + modem_reg_bc = (delta_k >> 16) & 0x1; + modem_reg_bd = (delta_k >> 8) & 0xff; + modem_reg_be = delta_k & 0xff; + } + else if(delta_fref < 0) + { + delta_k = 131072 + 9838592 * err; + modem_reg_bc = ((delta_k >> 16) & 0x1) | 0x2; + modem_reg_bd = (delta_k >> 8) & 0xff; + modem_reg_be = delta_k & 0xff; + } + radio_freq_cal_from_trim(); +} +#ifdef READ_HSE_MCO_FROM_TRIM_DEMO +/* demo function to read triming of HSE and set offset */ +void read_hse_freq_and_config_demo(void) +{ + uint32_t real_mco_freq; + real_mco_freq = radio_read_trim_mco_freq(); + radio_hse_mco_set(real_mco_freq); + NS_LOG_DEBUG("Radio trim freq:%d\r\n",real_mco_freq); +} +#endif +#endif +/** + **************************************************************************************** + * @brief Converts a duration in lp cycles into a duration in half us. + * + * The function converts a duration in lp cycles into a duration is half us, according to the + * low power clock frequency (32768Hz or 32000Hz). + * + * To do this the following formula are applied: + * + * Tus = (x*30.517578125)*2 = (30*x + x/2 + x/64 + x/512)*2 = (61*x + (x*8 + x)/256) for a 32.768kHz clock or + * Tus = (x*31.25)*2 = (31*x + x/4) * 2 = (62*x + x/2) for a 32kHz clock + * + * @param[in] lpcycles duration in lp cycles + * @param[in|out] error_corr Insert and retrieve error created by truncating the LP Cycle Time to a half us (32kHz: 1/2 half us | 32.768kHz: 1/256 half-us) + * + * @return duration in half us + **************************************************************************************** + */ +__STATIC __INLINE uint64_t rwip_lpcycles_2_hus(uint32_t lpcycles, uint32_t *error_corr) +{ + uint64_t res; + + *error_corr = lpcycles + *error_corr; + res = *error_corr >> 1; + *error_corr = *error_corr - (res << 1); + +// float tmep = (float)g_lsi_1_syscle_cnt_value/1000.0; + double tmep = (double)g_lsi_1_syscle_cnt_value/1000.0; + res = (((uint64_t)62 * lpcycles + res)*tmep); + + return(res); +} + +/** + **************************************************************************************** + * @brief Converts a duration in half slots into a number of low power clock cycles. + * The function converts a duration in half slots into a number of low power clock cycles. + * Sleep clock runs at either 32768Hz or 32000Hz, so this function divides the value in + * slots by 10.24 or 10 depending on the case. + * To do this the following formulae are applied: + * + * N = x * 10.24 = (1024 * x)/100 for a 32.768kHz clock or + * N = x * 10 for a 32kHz clock + * + * @param[in] hs_cnt The value in half slot count + * + * @return The number of low power clock cycles corresponding to the slot count + * + **************************************************************************************** + */ +__STATIC __INLINE int32_t rwip_slot_2_lpcycles(int32_t hs_cnt) +{ + uint32_t lpcycles; + + //1 hslot 10 lpcycle 312.5 * 1000/800 +// lpcycles = hs_cnt * 10 * 1000/g_lsi_1_syscle_cnt_value; + lpcycles = ((uint64_t)hs_cnt) * 10000 /g_lsi_1_syscle_cnt_value; + lpcycles--; + + return(lpcycles); +} + + +/** + **************************************************************************************** + * @brief Wake-up from Core sleep. + * + * Compute and apply the clock correction according to duration of the deep sleep. + **************************************************************************************** + */ +__STATIC void rwip_wakeup(void) +{ + uint16_t fintetime_correction; + // duration in half us + uint64_t dur_hus; + // duration in half slot + uint32_t dur_hslot; + // Get the number of low power sleep period + uint32_t slp_period = ip_deepslstat_get(); + + // Sleep is over now + rwip_prevent_sleep_clear(RW_DEEP_SLEEP); + + // Prevent going to deep sleep until a slot interrupt is received + rwip_prevent_sleep_set(RW_WAKE_UP_ONGOING); + + // Compensate the base time counter and fine time counter by the number of slept periods + dur_hus = rwip_lpcycles_2_hus(slp_period, &(rwip_env.sleep_acc_error)); + // Compute the sleep duration (based on number of low power clock cycles) + dur_hslot = dur_hus / HALF_SLOT_SIZE; + + // retrieve halfslot sleep duration + fintetime_correction = (HALF_SLOT_SIZE-1) - (dur_hus - ((uint64_t)dur_hslot)*HALF_SLOT_SIZE); + // The correction values are then deduced from the sleep duration in us + ip_clkncntcorr_pack(/*absdelta*/ 1, /*clkncntcorr*/ dur_hslot); + + // The correction values are then deduced from the sleep duration in us + ip_finecntcorr_setf(fintetime_correction); + + // Start the correction + ip_deepslcntl_deep_sleep_corr_en_setf(1); + + // Enable the RWBT slot interrupt + ip_intcntl1_clknintsrmsk_setf(0); + ip_intcntl1_clknintmsk_setf(1); + ip_intack1_clear(IP_CLKNINTACK_BIT); + +} + + +uint8_t rwip_sleep(void) +{ + uint8_t sleep_res = RWIP_ACTIVE; + + do + { + if(g_sleep_sleep_enable == 0) //sleep condition param 0: not sleep 1: allow to sleep + { + break; + } + + #if (BLE_EMB_PRESENT || BT_EMB_PRESENT) + int32_t sleep_duration; + rwip_time_t current_time; + #endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + + /************************************************************************ + ************** CHECK KERNEL EVENTS ************** + ************************************************************************/ + + // Check if some kernel processing is ongoing (during wakeup, kernel events are not processed) + if (((rwip_env.prevent_sleep & RW_WAKE_UP_ONGOING) == 0) && !ke_sleep_check()) + { + break; + } + + // Processor sleep can be enabled + sleep_res = RWIP_CPU_SLEEP; + + /************************************************************************ + ************** CHECK RW FLAGS ************** + ************************************************************************/ + // First check if no pending procedure prevent from going to sleep + if (rwip_env.prevent_sleep != 0) + { + break; + } + + #if (BLE_EMB_PRESENT || BT_EMB_PRESENT) + + /************************************************************************ + ************** Retrieve Current time ************** + ************************************************************************/ + current_time = rwip_time_get(); + // Consider 2 half-slots for clock correction (worst case: 1 half-slot before correction, 1 half-slot after correction) + current_time.hs += 2; + + // Remove 1 more slot because next slot will be started at end of function +// if((HALF_SLOT_INV(current_time.hus)) < rwip_env.sleep_algo_dur) + { + current_time.hs += 1; + } + // Be sure that we don't exceed the clock wrapping time + current_time.hs &= RWIP_MAX_CLOCK_TIME; + + /************************************************************************ + ******* COMPUTE SLEEP TIME ACCORDING TO 1 MS AND HALF SLOT TIMER ****** + ************************************************************************/ + + // put sleep duration to maximum value + sleep_duration = (rwip_env.ext_wakeup_enable) ? MAX_SLEEP_DURATION_EXTERNAL_WAKEUP : MAX_SLEEP_DURATION_PERIODIC_WAKEUP; + + // check if 1ms timer is active + if(rwip_env.timer_1ms_target.hs != RWIP_INVALID_TARGET_TIME) + { + int32_t duration = CLK_DIFF(current_time.hs, rwip_env.timer_1ms_target.hs); + // update sleep duration to minimum value + sleep_duration = co_min_s(sleep_duration, duration); + } + + // check if Half slot timer is active + if(rwip_env.timer_hs_target != RWIP_INVALID_TARGET_TIME) + { + int32_t duration = CLK_DIFF(current_time.hs, rwip_env.timer_hs_target); + // update sleep duration to minimum value + sleep_duration = co_min_s(sleep_duration, duration); + } + + // check if Half us timer is active + if(rwip_env.timer_hus_target != RWIP_INVALID_TARGET_TIME) + { + int32_t duration = CLK_DIFF(current_time.hs, rwip_env.timer_hus_target); + // update sleep duration to minimum value + sleep_duration = co_min_s(sleep_duration, duration); + } + + // A timer ISR is not yet handled or will be raised soon + // note the sleep duration could be negative, that's why it's useful to check if a minimum requirement is ok + // at least one half slot. + if(sleep_duration <= RWIP_MINIMUM_SLEEP_TIME) + { + break; + } + + if(app_env.lsc_cfg != BLE_LSC_LSE_32768HZ) + { + if((RCC->OSCFCSR & 0x01)) + { + uint32_t count_value=0; + count_value = RCC->OSCFCLSICNT; + g_lsi_1_syscle_cnt_value = (count_value / g_lsi_count_n_syscle) + (count_value % g_lsi_count_n_syscle) / (g_lsi_count_n_syscle/2); + } + } + /************************************************************************ + ************** CHECK SLEEP TIME ************** + ************************************************************************/ + + ////printf("sleep_duration = %x\r\n", sleep_duration); + sleep_duration = rwip_slot_2_lpcycles(sleep_duration); + // check if sleep duration is sufficient according to wake-up delay + + // //printf("sleep_duration = %x\r\n", sleep_duration); + if(sleep_duration < rwip_env.lp_cycle_wakeup_delay + 1) + { + break; + } + + sleep_res = RWIP_DEEP_SLEEP; + + /************************************************************************ + ************** PROGRAM CORE DEEP SLEEP ************** + ************************************************************************/ + // Program wake-up time + ip_deepslwkup_set(sleep_duration); + + // Prevent re-entering sleep, until it effectively sleeps and wakes up + rwip_prevent_sleep_set(RW_DEEP_SLEEP); + + /************************************************************************ + ************** SWITCH OFF RF ************** + ************************************************************************/ + rwip_rf.sleep(); + #endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + + + } while(0); + + return sleep_res; +} +__STATIC uint8_t modem_setmode[2] = {0xa0,0x00}; +__STATIC __INLINE void llhwc_setmode_reg_config(void) +{ + if(app_env.scan_actv_idx != 0xff || + app_env.init_actv_idx != 0xff || + scan_env.scan_enable) + { + REG32(MODEM_BASE +0xc2 *4) = modem_setmode[0]; + REG32(MODEM_BASE +0xc7 *4) = modem_setmode[1]; + //setmode1m from 0x104 to 0x109 + REG32(MODEM_BASE +0x104 *4) = 0x00027e12; + //setmode2m from 0x10a to 0x10f + REG32(MODEM_BASE +0x10A *4) = 0x00037e12; + //setmodelr from 0x110 to 0x11f + REG32(MODEM_BASE +0x110 *4) = 0x00027e12; + } + else{ + //setmode1m from 0x104 to 0x109 + REG32(MODEM_BASE +0x104 *4) = 0x00027e02; + REG32(MODEM_BASE +0x105 *4) = 0x00a0c202; + REG32(MODEM_BASE +0x106 *4) = 0x0000c712; + + //setmode2m from 0x10a to 0x10f + REG32(MODEM_BASE +0x10A *4) = 0x00037e02; + REG32(MODEM_BASE +0x10B *4) = 0x00a0c202; + REG32(MODEM_BASE +0x10C *4) = 0x0080c712; + //setmodelr from 0x110 to 0x11f + REG32(MODEM_BASE +0x110 *4) = 0x00027e02; + REG32(MODEM_BASE +0x111 *4) = 0x00e0c202; + REG32(MODEM_BASE +0x112 *4) = 0x0000c712; + } +} + +void llhwc_modem_setmode(uint8_t phy) +{ + if(phy == GAP_PHY_2MBPS) + { + modem_setmode[0] = 0xa0; + modem_setmode[1] = 0x80; + } + else if(phy == GAP_PHY_CODED || + phy == GAP_PHY_500KBPS) + { + modem_setmode[0] = 0xe0; + modem_setmode[1] = 0x00; + } + else //if(phy == GAP_PHY_1MBPS) + { + modem_setmode[0] = 0xa0; + modem_setmode[1] = 0x00; + } + + llhwc_setmode_reg_config(); + +} + +void llhwc_phy_prerx_flash(void) +{ + //reduce pll spur (only valid for version b) + REG32(0x40011004) = 0x20; + + //enable rssi notch filter + REG32(MODEM_BASE +0xff *4) = 0x01; + REG32(MODEM_BASE +0x56 *4) = 0x05; + REG32(MODEM_BASE +0xff *4) = 0x00; + REG32(MODEM_BASE +0xd4 *4) = 0x0b; + + llhwc_setmode_reg_config(); + + //PRETX from 0x11c to 0x12b + REG32(MODEM_BASE +0x11c *4) = 0x00f85902; //manually control vcoendly + REG32(MODEM_BASE +0x11d *4) = 0x00855b02; //turn on vdd_ana + REG32(MODEM_BASE +0x11e *4) = 0x00805a02; //enable bias current + REG32(MODEM_BASE +0x11f *4) = 0x00855d02; //turn on vdd_fsynvco + REG32(MODEM_BASE +0x120 *4) = 0x50805f02; //turn on vdd_adc and delay 20us + REG32(MODEM_BASE +0x121 *4) = 0x78080002; //turn on pll and delay 30us + REG32(MODEM_BASE +0x122 *4) = 0x00080a02; //enable iqdiv tx mode + REG32(MODEM_BASE +0x123 *4) = 0x50ac6e02; //turn on vdd_rffe and vdd_pa and delay 20us + REG32(MODEM_BASE +0x124 *4) = 0x00fc5902; //manually control vcoendly + REG32(MODEM_BASE +0x125 *4) = 0x00c80002; //turn on tx + REG32(MODEM_BASE +0x126 *4) = 0x14137012; //turn on paen and delay 5us + + //POSTTX from 0x12c to 0x137 + REG32(MODEM_BASE +0x12c *4) = 0x14037002; + REG32(MODEM_BASE +0x131 *4) = 0x00286e02; + REG32(MODEM_BASE +0x133 *4) = 0x00055d02; + REG32(MODEM_BASE +0x134 *4) = 0x00055b12; + + //PRERX from 0x138 to 0x147 + REG32(MODEM_BASE +0x138 *4) = 0x00f85902; //manually control vcoendly + REG32(MODEM_BASE +0x139 *4) = 0x00845b02; //turn on vdd_ana + REG32(MODEM_BASE +0x13A *4) = 0x00805a02; //enable bias current + REG32(MODEM_BASE +0x13B *4) = 0x00855d02; //turn on vdd_fsynvco + REG32(MODEM_BASE +0x13C *4) = 0x50805f02; //turn on vdd_adc and delay 20us + REG32(MODEM_BASE +0x13D *4) = 0x78080002; //turn on pll and delay 30us + REG32(MODEM_BASE +0x13E *4) = 0x00060a02; //enable iqdiv rx mode + REG32(MODEM_BASE +0x13F *4) = 0x502c6e02; //turn on vdd_rffe and delay 20us + REG32(MODEM_BASE +0x140 *4) = 0x00bfc302; //turn on rxdata and clk + REG32(MODEM_BASE +0x141 *4) = 0x00fc5902; //manually control vcoendly + REG32(MODEM_BASE +0x142 *4) = 0x00ac0012; //turn on rx + + //POSTRX from 0x148 to 0x153 + REG32(MODEM_BASE +0x14C *4) = 0x00286e02; + REG32(MODEM_BASE +0x14E *4) = 0x00055d12; + + + #if TRIM_RADIO_FREQUENCY_ENABLE + radio_freq_cal_from_trim(); + #endif +} + +/** + * @brief set rf tx power + * @param + * @return + * @note + */ +rf_tx_power_t g_rf_tx_power = TX_POWER_0_DBM; +void rf_tx_power_set(rf_tx_power_t pwr) +{ + if( pwr > TX_POWER_MAX_VAL) + { + //error + return; + } + + g_rf_tx_power = pwr; + if(TXPWR_MAP[g_rf_tx_power][0]) + { + REG32(0x40007014) &= ~(0x300); + REG32(0x40007014) |= 0x200; + REG32(0x40007020) &= ~(0x3f << 14); + REG32(0x40007020) |= (0x2e << 14); + } + else + { + REG32(0x40007014) &= ~(0x300); + REG32(0x40007020) &= ~(0x3f << 14); + REG32(0x40007020) |= (0x04 << 14); + } + REG32(0x4002255C) = TXPWR_MAP[g_rf_tx_power][1]; + REG32(0x4002258C) = TXPWR_MAP[g_rf_tx_power][2]; +} + +void rwip_slp_isr(void) +{ + // Check interrupt status and call the appropriate handlers + uint32_t irq_stat = ip_intstat1_get(); + if (irq_stat & IP_SLPINTSTAT_BIT) + { + // ack Sleep wakeup interrupt + ip_intack1_slpintack_clearf(1); + //Handle wake-up + rwip_wakeup(); + //when Baseband wake up then we need initialize the modem register + //rf_set_modem_register(); //TODO + //llhwc_phy_initialization(); + llhwc_phy_prerx_flash(); + + //rf tx power update after sleep + REG32(0x4002255C) = TXPWR_MAP[g_rf_tx_power][1]; + REG32(0x4002258C) = TXPWR_MAP[g_rf_tx_power][2]; + + g_sleep_status_flag = 0; //BB_ACTIVE + } +} + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip_host.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip_host.c new file mode 100644 index 0000000..353a204 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip_host.c @@ -0,0 +1,390 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwip_host.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#if (NVDS_SUPPORT) +#include "nvds.h" // NVDS definitions +#endif // NVDS_SUPPORT + +#if (BT_EMB_PRESENT) +#include "rwbt.h" // rwbt definitions +#endif //BT_EMB_PRESENT + +#if (BLE_EMB_PRESENT) +#include "rwble.h" // rwble definitions +#endif //BLE_EMB_PRESENT + +#if (BLE_HOST_PRESENT) +#include "rwble_hl.h" // BLE HL definitions +#include "gapc.h" +#include "gapm.h" +#include "gattc.h" +#include "l2cc.h" +#endif //BLE_HOST_PRESENT + +#if (BLE_APP_PRESENT) +#include "app.h" // Application definitions +#endif //BLE_APP_PRESENT + +//#include "led.h" // led definitions + +#if (BT_EMB_PRESENT) +#include "ld.h" +#endif //BT_EMB_PRESENT + +#if (DISPLAY_SUPPORT) +#include "display.h" // display definitions +#include "co_utils.h" // toolbox +//#include "plf.h" // platform definition +#if (BT_EMB_PRESENT) +#include "reg_btcore.h" +#endif // (BT_EMB_PRESENT) +#if (BLE_EMB_PRESENT) +#include "reg_blecore.h" +#endif // (BLE_EMB_PRESENT) +#if (BT_DUAL_MODE) +#include "reg_ipcore.h" +#endif // (BT_DUAL_MODE) +#endif //DISPLAY_SUPPORT + +#if (BT_EMB_PRESENT || BLE_EMB_PRESENT) +#include "sch_arb.h" // Scheduling Arbiter +#include "sch_prog.h" // Scheduling Programmer +#include "sch_plan.h" // Scheduling Planner +#include "sch_slice.h" // Scheduling Slicer +#include "sch_alarm.h" // Scheduling Alarm +#endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + +#if (BT_EMB_PRESENT || BLE_EMB_PRESENT) +#include "rf.h" // RF definitions +#endif //BT_EMB_PRESENT || BLE_EMB_PRESENT + +#if (H4TL_SUPPORT) +#include "h4tl.h" +#endif //H4TL_SUPPORT + +#if (AHI_TL_SUPPORT) +#include "ahi.h" +#endif //AHI_TL_SUPPORT + +#if (HCI_PRESENT) +#include "hci.h" // HCI definition +#endif //HCI_PRESENT + +#if (BT_EMB_PRESENT || BLE_EMB_PRESENT) +#include "ecc_p256.h" // ECC P256 library +#endif // (BT_EMB_PRESENT || BLE_EMB_PRESENT) + +#include "aes.h" // For AES functions + +#if (BLE_EMB_PRESENT) +#include "reg_blecore.h" // ble core registers +#endif //BLE_EMB_PRESENT + +#if (BT_EMB_PRESENT) +#include "reg_btcore.h" // bt core registers +#endif //BT_EMB_PRESENT + +#include "dbg.h" // debug definition +#include "global_func.h" + +#define rwip_rst_state REG32(0X20000000) + +extern void llhwc_phy_prerx_flash(void); + +void rwip_init(uint32_t error) +{ + // IP initialization + rwip_rst_state = RWIP_INIT; + + // Initialize kernel + ke_init(); + + // Initialize memory heap used by kernel. + // Memory allocated for environment variables + //ke_mem_init(KE_MEM_ENV, (uint8_t*)rwip_heap_env, RWIP_CALC_HEAP_LEN_IN_BYTES(RWIP_HEAP_ENV_SIZE)); + ke_mem_init(KE_MEM_ENV, (uint8_t*)g_rwip_heap_env, g_rwip_heap_env_size); + + #if (BLE_HOST_PRESENT) + // Memory allocated for Attribute database + //ke_mem_init(KE_MEM_ATT_DB, (uint8_t*)rwip_heap_db, RWIP_CALC_HEAP_LEN_IN_BYTES(RWIP_HEAP_DB_SIZE)); + ke_mem_init(KE_MEM_ATT_DB, (uint8_t*)g_rwip_heap_db, g_rwip_heap_db_size); + + #endif // (BLE_HOST_PRESENT) + // Memory allocated for kernel messages + //ke_mem_init(KE_MEM_KE_MSG, (uint8_t*)rwip_heap_msg, RWIP_CALC_HEAP_LEN_IN_BYTES(RWIP_HEAP_MSG_SIZE)); + ke_mem_init(KE_MEM_KE_MSG, (uint8_t*)g_rwip_heap_msg, g_rwip_heap_msg_size); + + // Non Retention memory block + //ke_mem_init(KE_MEM_NON_RETENTION, (uint8_t*)rwip_heap_non_ret, RWIP_CALC_HEAP_LEN_IN_BYTES(RWIP_HEAP_NON_RET_SIZE)); + ke_mem_init(KE_MEM_NON_RETENTION, (uint8_t*)g_rwip_heap_non_ret, g_rwip_heap_non_ret_size); + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + #if (RW_DEBUG) + // Initialize the debug process + dbg_init(rwip_rst_state); + #endif //(RW_DEBUG) + #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + + //DONE TRANSPLANT + // Initialize RF + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + rf_init(&rwip_rf); + + + REG32(BASEBAND_REG_BASE +0x80) = 0x006a0242; //0x00400242; + llhwc_phy_prerx_flash(); + #endif //BT_EMB_PRESENT || BLE_EMB_PRESENT + + #if (DISPLAY_SUPPORT) + // Initialize display module + display_init(); + + // Add some configuration information to display + display_add_config(); + #endif //DISPLAY_SUPPORT + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + // Initialize Diffie Hellman Elliptic Curve Algorithm + #if (BLE_ECC) + ecc_init(rwip_rst_state); + #endif //(BLE_ECC) + #endif // (BT_EMB_PRESENT || BLE_EMB_PRESENT) + + if(g_hci_transport_onff) + { + // Initialize H4TL + #if (H4TL_SUPPORT) + #if (H4TL_NB_CHANNEL > 1) + h4tl_init(1, rwip_eif_get(1)); + #endif // (H4TL_NB_CHANNEL > 1) + h4tl_init(0, rwip_eif_get(0)); + #endif //(H4TL_SUPPORT) + } + #if (HCI_PRESENT) + // Initialize the HCI + hci_init(rwip_rst_state); + #endif //HCI_PRESENT + + #if (AHI_TL_SUPPORT) + // Initialize the Application Host Interface + ahi_init(); + #endif //AHI_TL_SUPPORT + + #if (BLE_HOST_PRESENT) + // Initialize BLE Host stack + rwble_hl_init(rwip_rst_state); + #endif //BLE_HOST_PRESENT + + #if (BT_EMB_PRESENT) + // Initialize BT + rwbt_init(); + #endif //BT_EMB_PRESENT + + #if (BLE_EMB_PRESENT) + // Initialize BLE + rwble_init(rwip_rst_state); + #endif //BLE_EMB_PRESENT + + // Initialize IP core driver + rwip_driver_init(rwip_rst_state); + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + #if (RW_WLAN_COEX) + rwip_wlcoex_set(1); + #endif //(RW_WLAN_COEX) + #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + + #if (BT_EMB_PRESENT || (BLE_EMB_PRESENT && !BLE_HOST_PRESENT)) + // If FW initializes due to FW reset, send the message to Host + if(error != RESET_NO_ERROR) + { + if(error == RESET_TO_ROM || error == RESET_AND_LOAD_FW) + { + // Send platform reset command complete if requested by user + dbg_platform_reset_complete(error); + } + else + { + // Allocate a message structure for hardware error event + struct hci_hw_err_evt *evt = KE_MSG_ALLOC(HCI_EVENT, 0, HCI_HW_ERR_EVT_CODE, hci_hw_err_evt); + + // Fill the HW error code + switch(error) + { + case RESET_MEM_ALLOC_FAIL: evt->hw_code = CO_ERROR_HW_MEM_ALLOC_FAIL; break; + default: ASSERT_INFO(0, error, 0); break; + } + + // Send the message + hci_send_2_host(evt); + } + } + #endif //(BT_EMB_PRESENT || (BLE_EMB_PRESENT && !BLE_HOST_PRESENT)) + + /* + ************************************************************************************ + * Application initialization + ************************************************************************************ + */ +// #if (BLE_APP_PRESENT) +// // Initialize APP +// if(g_app_init_branch) +// { +// app_init(); +// } +// #endif //BLE_APP_PRESENT + + // Move to IP first reset state + rwip_rst_state = RWIP_1ST_RST; + + #if ((!BLE_HOST_PRESENT && BLE_EMB_PRESENT) || BT_EMB_PRESENT) + // Make a full initialization in split-emb mode + rwip_reset(); + #endif // ((!BLE_HOST_PRESENT && BLE_EMB_PRESENT) || BT_EMB_PRESENT) +} + + + +void rwip_reset(void) +{ + // Disable interrupts until reset procedure is completed + GLOBAL_INT_DISABLE(); + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + #if (RW_DEBUG) + // Reset dbg + dbg_init(rwip_rst_state); + #endif //(RW_DEBUG) + #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + + //Clear all message and timer pending + ke_flush(); + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + // Reset Diffie Hellman Elliptic Curve Algorithm + #if (BLE_ECC) + ecc_init(rwip_rst_state); + #endif //(BLE_ECC) + #endif // (BT_EMB_PRESENT || BLE_EMB_PRESENT) + + #if (HCI_PRESENT) + // Reset the HCI + hci_init(rwip_rst_state); + #endif //HCI_PRESENT + + #if (BLE_HOST_PRESENT) + // Initialize BLE Host stack + rwble_hl_init(rwip_rst_state); //TODO check + #endif //BLE_HOST_PRESENT + + #if (BT_EMB_PRESENT) + if (rwip_rst_state == RWIP_RST) + { + // Reset BT + rwbt_reset(); + } + #endif //BT_EMB_PRESENT + + #if (BLE_EMB_PRESENT) + // Reset BLE + rwble_init(rwip_rst_state); + #endif //BLE_EMB_PRESENT + + // Reset AES + aes_init(rwip_rst_state); + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + // Reset Scheduling blocks + sch_arb_init(rwip_rst_state); + sch_prog_init(rwip_rst_state); + sch_plan_init(rwip_rst_state); + sch_alarm_init(rwip_rst_state); + sch_slice_init(rwip_rst_state); + #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + + #if (BLE_EMB_PRESENT || BT_EMB_PRESENT) + // Initialize IP core driver + rwip_driver_init(rwip_rst_state); + #endif // (BLE_EMB_PRESENT || BT_EMB_PRESENT) + + #if (BT_EMB_PRESENT || BLE_EMB_PRESENT) + #if (RW_WLAN_COEX) + rwip_wlcoex_set(1); + #endif //(RW_WLAN_COEX) + + + if (rwip_rst_state == RWIP_RST) + { + // Reset the RF + rwip_rf.reset(); + } + #endif //(BT_EMB_PRESENT || BLE_EMB_PRESENT) + + + #if (DISPLAY_SUPPORT) + // Restart display module + display_resume(); + #endif //DISPLAY_SUPPORT + + // Move to normal IP reset state + rwip_rst_state = RWIP_RST; + + // Restore interrupts once reset procedure is completed + GLOBAL_INT_RESTORE(); +} + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/symdef/symbol_g15.obj b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/symdef/symbol_g15.obj new file mode 100644 index 0000000..496605c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/symdef/symbol_g15.obj @@ -0,0 +1,1066 @@ +## ARM Linker, 5060528: Last Updated: Tue May 25 20:40:17 2021 +;0x00000000 N __ARM_use_no_argv +;0x000000c0 N __Vectors_Size +;0x00000000 D __Vectors +;0x000000c0 D __Vectors_End +;0x000000c1 T __main +;0x000000c1 T _main_stk +;0x000000c5 T _main_scatterload +;0x000000c9 T __main_after_scatterload +;0x000000c9 T _main_clock +;0x000000c9 T _main_cpp_init +;0x000000c9 T _main_init +;0x000000d1 T __rt_final_cpp +;0x000000d1 T __rt_final_exit +;0x000000d5 T __asm___12_global_var_c_182c16a4____REV16 +;0x000000d9 T __asm___12_global_var_c_182c16a4____REVSH +;0x000000dd T __stark_reinit +;0x00001001 T delay_cycles +;0x000000e1 T __asm___5_irq_c_c8460081____REV16 +;0x000000e5 T __asm___5_irq_c_c8460081____REVSH +;0x000000e9 T HardFault_IRQHandler +;0x00000101 T Reset_IRQHandler +;0x00000109 T MemManage_IRQHandler +;0x0000010b T BusFault_IRQHandler +;0x0000010d T UsageFault_IRQHandler +;0x00000111 T DebugMon_IRQHandler +;0x00002455 T PendSV_IRQHandler +;0x00000117 T Spi1_I2s1_IRQhandler +;0x00000929 T __aeabi_uidiv +;0x00000929 T __aeabi_uidivmod +;0x00000955 T __aeabi_idiv +;0x00000955 T __aeabi_idivmod +;0x0000097d T rand +;0x0000098f T srand +;0x000009a1 T ___aeabi_memcpy8$move +;0x000009a1 T __aeabi_memcpy +;0x000009a1 T __aeabi_memcpy4 +;0x000009a1 T __aeabi_memmove +;0x000009a1 T __aeabi_memmove4 +;0x000009a1 T __aeabi_memmove8 +;0x000009e1 T __aeabi_memset +;0x000009e1 T __aeabi_memset4 +;0x000009e1 T __aeabi_memset8 +;0x000009ef T __aeabi_memclr +;0x000009ef T __aeabi_memclr4 +;0x000009ef T __aeabi_memclr8 +;0x000009f3 T _memset$wrapper +;0x00000a05 T memcmp +;0x00000a21 T __scatterload +;0x00000a21 T __scatterload_rt2 +;0x00000a45 T __decompress +;0x00000a45 T __decompress1 +0x00000a9d T Adc_IRQHandler +0x00000abd T Add2SelfBigHex256 +0x00000b05 T AddBigHex256 +0x00000b55 T AddBigHexModP256 +0x00000ba5 T AddP256 +0x00000bd5 T AddPdiv2_256 +0x00000cdd T BT_set_advert_data +;0x00000d69 T BleCypt_IRQHandler +;0x00000d89 T BleError_IRQHandler +;0x00000da9 T BleFifo_IRQHandler +;0x00000dc9 T BleFinetgt_IRQHandler +;0x00000de9 T BleHslot_IRQHandler +;0x00000e05 T BleSlp_IRQHandler +;0x00000e25 T BleSw_IRQHandler +;0x00000e41 T BleTimestamptg1_IRQHandler +;0x00000e61 T BleTimestamptg2_IRQHandler +;0x00000ea1 T DMA_ConfigInt +;0x00000eb1 T DMA_DeInit +;0x00000f39 T DMA_EnableChannel +;0x00000f51 T DMA_GetCurrDataCounter +;0x00000f59 T DMA_Init +;0x00000f99 T DMA_RequestRemap +;0x00000fa1 T DmaCh1234_IRQHandler +;0x00000fc1 T DmaCh1234_Int_Err_Handler +;0x00000fc5 T DmaCh5_IRQHandler +;0x00001009 T EXTI_InitPeripheral +0x00001079 T EXTI_PA11_Configuration +;0x00000fe5 T Exti0_1_IRQHandler +;0x000010b5 T Exti2_3_IRQHandler +;0x000010d1 T Exti4_15_IRQHandler +;0x000010f1 T GF_Jacobian_Point_Addition256 +;0x00001645 T GF_Jacobian_Point_Double256 +;0x000017d1 T GPIO_InitPeripheral +;0x00001925 T GPIO_ReadInputDataBit +;0x00001933 T GPIO_ResetBits +;0x00001937 T GPIO_SetBits +;0x0000193d T HardFault_Handler_C +;0x0000194d T Hdiv_IRQHandler +;0x00002191 T I2c_IRQHandler +;0x000021b1 T KeyScan_IRQHandler +;0x000021d1 T LPUart_IRQHandler +0x00002211 T ModuleIrqRegister +0x0000223d T ModuleIrqRemoval +;0x00002271 T MultiplyBigHexByUint32_256 +;0x000022c1 T MultiplyBigHexModP256 +;0x00002441 T NMI_IRQHandler +;0x00002465 T QspiFlash_IRQHandler +;0x00002481 T RAMFUNC_FLAG +;0x000024dd T RCC_EnableAHBPeriphClk +;0x000024f5 T RCC_EnableAPB1PeriphClk +;0x00002525 T RCC_EnableAPB2PeriphClk +;0x0000253d T Rcc_IRQHandler +;0x00002559 T Rtc_IRQHandler +;0x00002575 T SPI_Enable +;0x00002589 T SPI_Init +;0x000025c9 T SVC_IRQHandler +0x000025d9 T Spi2_IRQHandler +0x000025f9 T SubtractBigHex256 +0x00002655 T SubtractBigHexMod256 +0x00002751 T SubtractFromSelfBigHex256 +0x000027a5 T SubtractFromSelfBigHexSign256 +0x0000286d T SysTick_IRQHandler +0x00002895 T Tim1BrkUpRrgCom_IRQHandler +0x000028b5 T Tim1Cc_IRQHandler +0x000028d5 T Tim3_IRQHandler +0x000028f5 T Tim6_IRQHandler +0x00002915 T Usart1_IRQHandler +0x00002935 T Usart2_IRQHandler +0x00002955 T Wdt_IRQHandler +;0x00002971 T __2printf +0x00002985 T __ARM_common_ll_muluu +0x000029b7 T __ARM_common_memclr1_5 +0x000029c5 T __ARM_common_memclr1_6 +0x000029d5 T __ARM_common_memclr1_8 +0x000029e9 T __ARM_common_memclr2_10 +0x000029f7 T __ARM_common_memclr2_6 +0x00002a01 T __ARM_common_memclr2_8 +0x00002a0d T __ARM_common_memcpy1_5 +0x00002a23 T __ARM_common_memcpy1_6 +0x00002a3d T __ARM_common_memcpy1_8 +0x00002a5f T __ARM_common_memcpy2_5 +0x00002a6d T __ARM_common_memcpy2_6 +0x00002a7b T __ARM_common_memcpy2_8 +0x00002a8d T __ARM_common_memcpy4_5 +0x00002a97 T __ARM_common_memset1_5 +0x00002aa5 T __ARM_common_memset4_5 +0x00002ae1 T __scatterload_copy +0x00002aef T __scatterload_null +0x00002af1 T __scatterload_zeroinit +0x00002b1d T acl_flow_ctrl_send +0x00002b5d T aes_alloc +0x00002b75 T aes_c1 +0x00002bf9 T aes_cmac +0x00002c45 T aes_cmac_continue +0x00002d71 T aes_cmac_start +0x00002da1 T aes_encrypt +0x00002e35 T aes_f4 +0x00002e89 T aes_init +0x00002ed9 T aes_rand +0x00002f09 T aes_result_handler +0x00002f61 T aes_rpa_gen +0x00002ff5 T aes_rpa_resolve +0x000030d9 T aes_shift_left_128 +0x00003101 T aes_start +0x00003131 T aes_xor_128 +0x000043b1 T ahi_init +0x00004425 T ahi_send_msg +0x0000452d T app2ahi_evt_cmd_cmp +0x00004599 T app2ahi_evt_other +;0x000045f1 T app_add_svc +;0x00004651 T app_adv_fsm_next +;0x0000480d T app_create_advertising +;0x0000485d T app_delete_advertising +;0x00004881 T app_disconnect +;0x000048ad T app_get_dev_name +;0x000048c5 T app_init +;0x00004af1 T app_obus_add +;0x00004b69 T app_obus_init +;0x00004bd1 T app_sec_get_bond_status +;0x00004c11 T app_sec_send_security_req +;0x00004c35 T app_send_gapm_reset_cmd +;0x00004c51 T app_stop_advertising +;0x00004ca9 T app_update_adv_state +;0x00004cb1 T app_update_param +0x00004cf5 T appc_data_lenght_extend +0x00004d25 T appm_exchange_mtu +0x00004e3d T attc_l2cc_pdu_recv_handler +0x00004e8d T attc_send_att_req +0x00004eb9 T attm_att_get_perm +0x00004ed1 T attm_att_update_perm +0x00004f4d T attm_convert_to128 +0x00004f95 T attm_get_value +0x00005119 T attm_init +0x0000513d T attm_is_bt16_uuid +0x00005175 T attm_is_bt32_uuid +0x000051b5 T attm_svc_create_db +0x000052ab T attm_svc_create_db_128 +0x000053d1 T attm_svc_get_permission +0x000053ef T attm_uuid16_comp +0x000053fd T attm_uuid_comp +0x00005469 T attmdb_add_service +0x000054e9 T attmdb_att_get_permission +0x0000563d T attmdb_destroy +0x0000566d T attmdb_get_attribute +0x000056a1 T attmdb_get_max_len +0x00005715 T attmdb_get_next_att +0x00005799 T attmdb_get_service +0x000057ed T attmdb_get_uuid +0x000058d5 T attmdb_hash_compute +0x00005dfd T attmdb_svc_check_hdl +0x00006065 T attmdb_uuid16_comp +0x000060a9 T atts_clear_prep_data +0x000060e5 T atts_clear_read_cache +0x00006105 T atts_clear_rsp_data +0x000067b9 T atts_get_dest_task +0x00006861 T atts_l2cc_pdu_recv_handler +0x00006af1 T atts_process_pdu +0x000071d9 T atts_send_error +0x000071fd T atts_send_event +0x000073b5 T atts_write_rsp_send +0x0000746b T atts_write_signed_cfm +0x000074b1 T baseband_init +0x00007549 T bigHexInversion256 +0x0000777d T ble_util_buf_acl_tx_alloc +0x000077a5 T ble_util_buf_acl_tx_elt_get +0x0000780d T ble_util_buf_acl_tx_free +0x0000788d T ble_util_buf_adv_tx_alloc +0x000078b5 T ble_util_buf_adv_tx_free +0x0000791d T ble_util_buf_init +0x00007a5d T ble_util_buf_llcp_tx_alloc +0x00007a79 T ble_util_buf_llcp_tx_free +0x00007ac9 T ble_util_buf_rx_alloc +0x00007ae1 T ble_util_buf_rx_free +0x00007b51 T calib_clk_init +0x00007b65 T calib_hsi_clk +0x00007c1d T calib_lsi_clk +;0x00007d09 T check_calib_clk +0x00007e17 T co_bdaddr_compare +0x00007e37 T co_ble_pkt_dur_in_us +0x00007e69 T co_list_extract +0x00007ea3 T co_list_extract_after +0x00007ebd T co_list_extract_sublist +0x00007ed3 T co_list_init +0x00007edb T co_list_insert_after +0x00007f3d T co_list_insert_before +0x00007f8d T co_list_pool_init +0x00007faf T co_list_pop_front +0x00007fc3 T co_list_push_back +0x00007fe3 T co_list_push_back_sublist +0x00008003 T co_list_push_front +0x0000801b T co_list_size +0x00008031 T co_nb_good_le_channels +0x00008059 T co_util_pack +0x00008241 T co_util_unpack +0x00008471 T delay_n_10us +0x00008489 T delay_n_ms +0x000084a9 T delay_n_us +0x000084c1 T dl_upd_proc_start +0x00008531 T dma_lpuart_read +0x000085f9 T dma_lpuart_rx_len +0x00008615 T dma_soft_flow_ctrl_read +0x00008751 T dma_soft_flow_ctrl_write +0x00008885 T dma_spis_read +0x00008951 T dma_spis_rx_len +0x0000896d T dma_spis_tx_len +0x00008989 T dma_spis_write +0x00008b4d T ecc_gen_new_public_key +0x00008b6d T ecc_gen_new_secret_key +0x00008c65 T ecc_generate_key256 +0x00008ff5 T ecc_init +0x00009575 T entry_shutdown +;0x000095a5 T entry_sleep +;0x00009639 T entry_standby +;0x00009691 T entry_wakeup +;0x00009971 T fputc +0x0000998d T gapc_auth_get +0x000099c5 T gapc_auth_set +0x00009a25 T gapc_bond_cfm_handler +0x00009c81 T gapc_bond_cmd_handler +0x0000a101 T gapc_con_cleanup +0x0000a111 T gapc_con_create +0x0000a505 T gapc_enc_keysize_get +0x0000a521 T gapc_encrypt_cfm_handler +0x0000a5c9 T gapc_encrypt_cmd_handler +0x0000a74d T gapc_get_bdaddr +0x0000a771 T gapc_get_chan_sel_algo +0x0000a789 T gapc_get_conhdl +0x0000a7a9 T gapc_get_conidx +0x0000a7d5 T gapc_get_dest_task +0x0000ab1d T gapc_get_operation +0x0000ab39 T gapc_get_operation_ptr +0x0000ab49 T gapc_get_requester +0x0000ab69 T gapc_get_role +0x0000ab89 T gapc_hci_handler +0x0000abfd T gapc_init +0x0000ac51 T gapc_is_sec_set +0x0000ace1 T gapc_lk_sec_lvl_get +0x0000af89 T gapc_param_update_sanity +0x0000b039 T gapc_per_adv_sync_trans_cmd_handler +0x0000b0f1 T gapc_process_op +0x0000b191 T gapc_reschedule_operation +0x0000b1c5 T gapc_security_cmd_handler +0x0000b261 T gapc_send_complete_evt +0x0000b2d5 T gapc_send_disconect_ind +0x0000b2f9 T gapc_send_error_evt +0x0000b469 T gapc_set_local_addr +0x0000b4d9 T gapc_set_operation_ptr +0x0000b601 T gapc_sig_pdu_recv_handler +0x0000b639 T gapc_sign_cmd_handler +0x0000bb21 T gapc_smp_cleanup +0x0000bc6d T gapc_smp_gapm_cmp_evt_handler +0x0000c15d T gapc_smp_pdu_recv +0x0000c5b9 T gapc_smp_rep_attempts_timer_handler +0x0000c7f1 T gapc_smp_timeout_timer_ind_handler +0x0000ca65 T gapc_update_state +0x0000ca9d T gapm_activity_create_cmd_handler +0x0000cb7d T gapm_activity_delete_cmd_handler +0x0000cc0d T gapm_activity_start_cmd_handler +0x0000cc7d T gapm_activity_stop_cmd_handler +0x0000cd55 T gapm_actv_alloc +0x0000cd85 T gapm_actv_created +0x0000cdf9 T gapm_actv_deleted +0x0000ce75 T gapm_actv_get_hci_own_addr_type +0x0000ce99 T gapm_actv_info_get +0x0000cedd T gapm_actv_rand_addr_set_ind +0x0000cef9 T gapm_actv_reset +0x0000cf49 T gapm_actv_retrieve_cmd_cmp_evt +0x0000cf81 T gapm_actv_started +0x0000cfad T gapm_actv_stopped +0x0000d119 T gapm_addr_init +0x0000d135 T gapm_addr_renew_cmd_handler +0x0000d1d9 T gapm_addr_renew_to_ind_handler +0x0000d201 T gapm_addr_set_rand_addr +0x0000d265 T gapm_adv_create +;0x0000d96d T gapm_cmp_evt_handler +0x0000d989 T gapm_con_cleanup +0x0000d9bd T gapm_con_create +0x0000da29 T gapm_dev_bdaddr_ind_handler +0x0000da6d T gapm_dle_val_check +0x0000da8d T gapm_gen_rand_addr_cmd_handler +0x0000db31 T gapm_get_address_type +0x0000db41 T gapm_get_att_handle +0x0000db85 T gapm_get_bdaddr +0x0000db8d T gapm_get_dev_info_cmd_handler +0x0000dcc1 T gapm_get_id_from_task +0x0000dd15 T gapm_get_irk +0x0000dd1d T gapm_get_max_mtu +0x0000dd29 T gapm_get_operation +0x0000dd41 T gapm_get_ral_addr_cmd_handler +0x0000dd99 T gapm_get_requester +0x0000ddb5 T gapm_get_task_from_id +0x0000de5d T gapm_init +0x0000defd T gapm_is_legacy_pairing_supp +0x0000df0d T gapm_is_pref_con_param_pres +0x0000df1d T gapm_is_sec_con_pairing_supp +0x0000df2d T gapm_le_test_mode_ctrl_cmd_handler +0x0000e01d T gapm_lepsm_register_cmd_handler +0x0000e045 T gapm_lepsm_unregister_cmd_handler +0x0000e06d T gapm_list_set_cmd_handler +0x0000e271 T gapm_process_op +0x0000e355 T gapm_profile_task_add_cmd_handler +0x0000e3d9 T gapm_reset_cmd_handler +0x0000e44d T gapm_resolv_addr_cmd_handler +0x0000e49d T gapm_send_complete_evt +0x0000e4e5 T gapm_send_error_evt +0x0000e509 T gapm_set_adv_data_cmd_handler +0x0000e669 T gapm_set_channel_map_cmd_handler +0x0000e6c9 T gapm_set_dev_config_cmd_handler +0x0000e839 T gapm_set_irk_cmd_handler +0x0000ea51 T gapm_use_enc_block_cmd_handler +0x0000ebcd T gattc_cleanup +0x0000ed79 T gattc_con_enable +0x0000ee29 T gattc_con_info_send +0x0000ee9d T gattc_create +0x0000ef1d T gattc_db_updated +0x0000eff5 T gattc_get_l2c_code +0x0000f005 T gattc_get_mtu +0x0000f015 T gattc_get_operation +0x0000f031 T gattc_get_operation_ptr +0x0000f041 T gattc_init +0x0000f099 T gattc_is_db_out_of_sync +0x0000f251 T gattc_process_op +0x0000f565 T gattc_send_complete_evt +0x0000f5c5 T gattc_send_error_evt +0x0000f649 T gattc_set_mtu +0x0000f6b1 T gattc_set_operation_ptr +0x0000f6c1 T gattc_svc_att_info_req_ind_handler +0x0000f70d T gattc_svc_chg_ind_send +0x0000f761 T gattc_svc_read_req_ind_handler +0x0000f7fd T gattc_svc_write_req_ind_handler +0x0000f931 T gattc_update_state +0x0000fb05 T gattm_att_hdl_to_idx +0x0000fb25 T gattm_att_idx_to_hdl +0x0000fb6d T gattm_cleanup +0x0000fb77 T gattm_create +0x0000fb81 T gattm_db_updated +0x0000fbc9 T gattm_init +0x0000fee1 T h4tl_init +0x0000ff89 T h4tl_read_start_next +0x00010249 T h4tl_write +0x000102b5 T handle_all_data +0x000103d9 T hci_acl_data_handler +0x00010545 T hci_acl_tx_data_alloc +0x000105ad T hci_acl_tx_data_received +0x00010605 T hci_acl_tx_trigger +0x00010665 T hci_basic_cmd_cmp_evt_cfg_handler +0x000106f1 T hci_basic_cmd_cmp_evt_rl_cfg_handler +0x0001073d T hci_basic_cmd_send_2_controller +0x00010755 T hci_ble_conhdl_register +0x00010765 T hci_ble_conhdl_unregister +0x00010775 T hci_cmd_get_max_param_size +0x00010789 T hci_cmd_received +0x00010acd T hci_command_handler +0x00010b59 T hci_disconnect_cmd_handler +0x00010bf1 T hci_enc_chg_evt_handler +0x00010c13 T hci_enc_key_refr_evt_handler +0x00010c35 T hci_evt_mask_set +0x00010c8d T hci_fc_acl_buf_size_set +0x00010ca1 T hci_fc_acl_en +0x00010cd5 T hci_fc_acl_packet_sent +0x00010ce9 T hci_fc_check_host_available_nb_acl_packets +0x00010d0d T hci_fc_host_nb_acl_pkts_complete +0x00010d25 T hci_fc_init +0x00010e25 T hci_init +0x00010e71 T hci_le_add_dev_to_per_adv_list_cmd_handler +0x000111fd T hci_le_adv_set_term_evt_handler +0x00011281 T hci_le_ch_sel_algo_evt_handler +0x000112a5 T hci_le_clear_adv_sets_cmd_handler +0x00011319 T hci_le_clear_per_adv_list_cmd_handler +0x00011445 T hci_le_cmd_cmp_evt_addr_handler +0x00011465 T hci_le_cmd_cmp_evt_adv_handler +0x00011679 T hci_le_cmd_cmp_evt_list_handler +0x000117c9 T hci_le_con_cte_req_en_cmd_handler +0x00011909 T hci_le_con_cte_rsp_en_cmd_handler +0x00011b09 T hci_le_con_upd_cmd_handler +0x00011e41 T hci_le_create_con_cancel_cmd_handler +0x00011ea1 T hci_le_create_con_cmd_handler +0x00012275 T hci_le_enh_con_cmp_evt_handler +0x0001246d T hci_le_ext_create_con_cmd_handler +0x000129bd T hci_le_ltk_req_neg_reply_cmd_handler +0x00012a59 T hci_le_ltk_req_reply_cmd_handler +0x00012acd T hci_le_ltk_request_evt_handler +0x00012bf1 T hci_le_per_adv_create_sync_cancel_cmd_handler +0x00012cc5 T hci_le_per_adv_create_sync_cmd_handler +0x00012d89 T hci_le_per_adv_set_info_transf_cmd_handler +0x00012e31 T hci_le_per_adv_sync_transf_cmd_handler +0x00012ec1 T hci_le_per_adv_term_sync_cmd_handler +0x00012fc1 T hci_le_rd_adv_ch_tx_pw_cmd_handler +0x0001300d T hci_le_rd_adv_chnl_tx_pw_cmd_cmp_evt_handler +0x000130b5 T hci_le_rd_chnl_map_cmd_handler +0x000131dd T hci_le_rd_max_adv_data_len_cmd_handler +0x00013219 T hci_le_rd_max_data_len_cmd_cmp_evt_handler +0x0001328d T hci_le_rd_nb_supp_adv_sets_cmd_cmp_evt_handler +0x000132c9 T hci_le_rd_nb_supp_adv_sets_cmd_handler +0x00013371 T hci_le_rd_per_adv_list_size_cmd_handler +0x00013401 T hci_le_rd_phy_cmd_handler +0x00013459 T hci_le_rd_ral_addr_cmd_cmp_evt_handler +0x000134c5 T hci_le_rd_ral_size_cmd_cmp_evt_handler +0x00013521 T hci_le_rd_rem_feats_cmd_handler +0x00013675 T hci_le_rd_rf_path_comp_cmd_cmp_evt_handler +0x00013715 T hci_le_rd_suggted_dft_data_len_cmd_cmp_evt_handler +0x000137b5 T hci_le_rd_tx_pwr_cmd_cmp_evt_handler +0x0001386d T hci_le_rd_wlst_size_cmd_cmp_evt_handler +0x000138c9 T hci_le_read_max_adv_data_len_cmd_cmp_evt_handler +0x00013961 T hci_le_rem_con_param_req_neg_reply_cmd_handler +0x000139c5 T hci_le_rem_con_param_req_reply_cmd_handler +0x00013a59 T hci_le_rmv_adv_set_cmd_handler +0x00013ac1 T hci_le_rmv_dev_from_per_adv_list_cmd_handler +0x00013c2d T hci_le_rx_test_v1_cmd_handler +0x00013c6f T hci_le_rx_test_v2_cmd_handler +0x00013cc1 T hci_le_rx_test_v3_cmd_handler +0x00013d65 T hci_le_scan_req_rcvd_evt_handler +0x00013df5 T hci_le_set_adv_data_cmd_handler +0x00013ead T hci_le_set_adv_en_cmd_handler +0x000140f9 T hci_le_set_adv_param_cmd_handler +0x00014269 T hci_le_set_adv_set_rand_addr_cmd_handler +0x000142d5 T hci_le_set_con_cte_rx_param_cmd_handler +0x000143f1 T hci_le_set_con_cte_tx_param_cmd_handler +0x000144e5 T hci_le_set_conless_cte_tx_en_cmd_handler +0x000145b9 T hci_le_set_conless_cte_tx_param_cmd_handler +0x0001466d T hci_le_set_conless_iq_sampl_en_cmd_handler +0x00014779 T hci_le_set_data_len_cmd_handler +0x00014969 T hci_le_set_ext_adv_data_cmd_handler +0x00014af5 T hci_le_set_ext_adv_en_cmd_handler +0x000150e5 T hci_le_set_ext_adv_param_cmd_handler +0x000152d1 T hci_le_set_ext_scan_en_cmd_handler +0x0001551d T hci_le_set_ext_scan_param_cmd_handler +0x00015725 T hci_le_set_ext_scan_rsp_data_cmd_handler +0x000158cd T hci_le_set_per_adv_data_cmd_handler +0x000159f9 T hci_le_set_per_adv_en_cmd_handler +0x00015c25 T hci_le_set_per_adv_param_cmd_handler +0x00015d05 T hci_le_set_per_adv_rec_en_cmd_handler +0x00015d5d T hci_le_set_per_adv_sync_transf_param_cmd_handler +0x00015dd5 T hci_le_set_phy_cmd_handler +0x00016039 T hci_le_set_scan_en_cmd_handler +0x000161f1 T hci_le_set_scan_param_cmd_handler +0x00016311 T hci_le_set_scan_rsp_data_cmd_handler +0x000163c9 T hci_le_start_enc_cmd_handler +0x0001649d T hci_le_test_end_cmd_handler +0x000164c9 T hci_le_tx_test_v1_cmd_handler +0x00016519 T hci_le_tx_test_v2_cmd_handler +0x00016575 T hci_le_tx_test_v3_cmd_handler +0x000166a9 T hci_look_for_cmd_desc +0x00016705 T hci_look_for_evt_desc +0x0001672d T hci_look_for_le_evt_desc +0x000167ef T hci_past_cmd_cmp_evt_handler +0x0001687d T hci_rd_auth_payl_to_cmd_handler +0x000169d9 T hci_rd_local_ver_info_cmd_cmp_evt_handler +0x00016a79 T hci_rd_rem_ver_info_cmd_handler +0x00016be1 T hci_rd_rssi_cmd_handler +0x00016c55 T hci_rd_tx_pwr_lvl_cmd_handler +0x00016cf9 T hci_send_2_controller +0x00016d79 T hci_send_2_host +0x00016f25 T hci_test_end_cmd_cmp_evt_handler +0x00016f75 T hci_tl_init +0x00016fcd T hci_tl_send +0x000173d9 T hci_vs_set_max_rx_size_and_time_cmd_handler +0x000174fd T hci_vs_set_pref_slave_evt_dur_cmd_handler +0x00017591 T hci_vs_set_pref_slave_latency_cmd_handler +0x00017611 T hci_wr_auth_payl_to_cmd_handler +0x00017671 T initdata_config +0x0001772d T interface_check +0x000177c5 T interface_reinit +0x00017805 T ke_event_callback_set +0x0001781d T ke_event_clear +0x00017845 T ke_event_get_all +0x00017851 T ke_event_init +0x00017871 T ke_event_schedule +0x000178ad T ke_event_set +0x000178d5 T ke_flush +0x00017919 T ke_free +0x000179e5 T ke_init +0x00017a15 T ke_is_free +0x00017a2d T ke_malloc +0x00017afd T ke_mem_init +0x00017b39 T ke_msg_alloc +0x00017b6b T ke_msg_discard +0x00017b71 T ke_msg_forward +0x00017b9d T ke_msg_free +0x00017ba5 T ke_msg_in_queue +0x00017bb1 T ke_msg_send +0x00017bd9 T ke_msg_send_basic +0x00017c25 T ke_msg_src_id_get +0x00017c2b T ke_queue_extract +0x00017c6d T ke_queue_insert +0x00017ca1 T ke_sleep_check +0x00017cb5 T ke_state_get +0x00017cd9 T ke_state_set +0x00017d41 T ke_task_check +0x00017d61 T ke_task_create +0x00017d95 T ke_task_delete +0x00017dc1 T ke_task_init +0x00017ddd T ke_task_msg_flush +0x00017f51 T ke_timer_active +0x00017f7d T ke_timer_clear +0x00017ff5 T ke_timer_init +0x000180bd T ke_timer_set +0x000182b5 T l2cc_cleanup +0x0001844f T l2cc_cmp_evt_handler +0x0001847d T l2cc_create +0x000184c5 T l2cc_data_send +0x000186a9 T l2cc_init +0x00018741 T l2cc_pdu_alloc +0x0001876d T l2cc_pdu_header_check +0x000188c5 T l2cc_pdu_pack +0x00018c41 T l2cc_pdu_rx_init +0x00018cbd T l2cc_pdu_send +0x00018d25 T l2cc_pdu_unpack +0x00018f55 T l2cc_send_cmp_evt +0x00018f81 T l2cc_sig_pdu_recv_handler +0x00018fc9 T l2cc_sig_send_cmd_reject +0x00019021 T l2cm_cleanup +0x0001903d T l2cm_create +0x00019045 T l2cm_get_nb_buffer_available +0x00019051 T l2cm_init +0x000190d9 T l2cm_set_link_layer_buff_size +0x000190e9 T l2cm_tx_status +0x00019119 T ll_channel_map_ind_handler +0x000191b5 T ll_clk_acc_req_handler +0x00019209 T ll_clk_acc_rsp_handler +0x00019245 T ll_connection_param_req_handler +0x0001931d T ll_connection_param_rsp_handler +0x000193b5 T ll_connection_update_ind_handler +0x000194d1 T ll_cte_req_handler +0x00019545 T ll_cte_rsp_handler +0x00019565 T ll_enc_req_handler +0x0001962d T ll_enc_rsp_handler +0x000196a5 T ll_feature_req_handler +0x0001972d T ll_feature_rsp_handler +0x00019781 T ll_length_req_handler +0x000198d5 T ll_length_rsp_handler +0x00019951 T ll_min_used_channels_ind_handler +0x000199d1 T ll_pause_enc_req_handler +0x00019a3d T ll_pause_enc_rsp_handler +0x00019a95 T ll_per_sync_ind_handler +0x00019bf5 T ll_phy_req_handler +0x00019ca5 T ll_phy_rsp_handler +0x00019d21 T ll_phy_update_ind_handler +0x00019db5 T ll_ping_req_handler +0x00019dc9 T ll_ping_rsp_handler +0x00019e25 T ll_slave_feature_req_handler +0x00019ead T ll_start_enc_req_handler +0x00019efd T ll_start_enc_rsp_handler +0x00019f4d T ll_terminate_ind_handler +0x00019fb1 T ll_version_ind_handler +0x0001a051 T llc_auth_payl_nearly_to_handler +0x0001a0b1 T llc_auth_payl_real_to_handler +0x0001a141 T llc_cleanup +0x0001a1a5 T llc_clk_acc_modify +0x0001a275 T llc_cmd_cmp_send +0x0001a295 T llc_cmd_stat_send +0x0001a2b1 T llc_con_move_cbk +0x0001a45d T llc_cte_req_dis +0x0001a47d T llc_cte_req_to_handler +0x0001a50d T llc_cte_rsp_dis +0x0001a521 T llc_disconnect +0x0001a729 T llc_encrypt_ind_handler +0x0001a9c1 T llc_init +0x0001aa65 T llc_init_term_proc +0x0001ab19 T llc_le_ping_restart +0x0001ab55 T llc_le_ping_set +0x0001abe1 T llc_ll_reject_ind_pdu_send +0x0001ac6d T llc_llcp_send +0x0001ace9 T llc_llcp_state_set +0x0001ada5 T llc_llcp_tx_check +0x0001bd71 T llc_op_ch_map_upd_ind_handler +0x0001bdd5 T llc_op_clk_acc_ind_handler +0x0001be2d T llc_op_con_upd_ind_handler +0x0001bebd T llc_op_cte_ind_handler +0x0001bf15 T llc_op_disconnect_ind_handler +0x0001bf81 T llc_op_dl_upd_ind_handler +0x0001c015 T llc_op_encrypt_ind_handler +0x0001c07d T llc_op_feats_exch_ind_handler +0x0001c115 T llc_op_le_ping_ind_handler +0x0001c171 T llc_op_past_ind_handler +0x0001c401 T llc_op_phy_upd_ind_handler +0x0001c4a5 T llc_op_ver_exch_ind_handler +0x0001c91d T llc_proc_collision_check +0x0001c955 T llc_proc_err_ind +0x0001c985 T llc_proc_get +0x0001c99d T llc_proc_id_get +0x0001c9b9 T llc_proc_reg +0x0001c9ed T llc_proc_state_get +0x0001c9f1 T llc_proc_state_set +0x0001c9f5 T llc_proc_timer_pause_set +0x0001ca4d T llc_proc_timer_set +0x0001caa5 T llc_proc_unreg +0x0001d309 T llc_start +0x0001d4fd T llc_stop +0x0001d531 T llc_stopped_ind_handler +0x0001d649 T lld_aa_gen +0x0001d6c9 T lld_acl_rx_ind_handler +0x0001d755 T lld_acl_tx_cfm_handler +0x0001d855 T lld_adv_adv_data_update +0x0001da55 T lld_adv_duration_update +0x0001db35 T lld_adv_end_ind_handler +0x0001dfd9 T lld_adv_evt_start_cbk +0x0001efc9 T lld_adv_init +0x0001f33d T lld_adv_rand_addr_update +0x0001f391 T lld_adv_rep_ind_handler +0x0001f891 T lld_adv_restart +0x0001fa11 T lld_adv_scan_rsp_data_update +0x0001fa49 T lld_adv_start +0x00020101 T lld_adv_stop +0x00020309 T lld_adv_sync_info_update +0x00020339 T lld_calc_aux_rx +0x00020465 T lld_ch_assess_data_get +0x0002046d T lld_ch_idx_get +0x00020491 T lld_ch_map_set +0x000204dd T lld_ch_map_upd_cfm_handler +0x00020515 T lld_channel_assess +0x0002054d T lld_con_activity_offset_compute +0x000205c5 T lld_con_ch_map_update +0x000206ed T lld_con_cte_rx_dis +0x00020721 T lld_con_cte_rx_en +0x000207e9 T lld_con_cte_rx_ind_handler +0x00020945 T lld_con_cte_tx_ant_switch_config +0x000209e1 T lld_con_cte_tx_param_set +0x000209f9 T lld_con_current_tx_power_get +0x00020a39 T lld_con_data_flow_set +0x00020aed T lld_con_data_len_update +0x00020b2d T lld_con_data_tx +0x00020bdd T lld_con_enc_key_load +0x00020c51 T lld_con_estab_ind_handler +0x00020c79 T lld_con_event_counter_get +0x000211d9 T lld_con_init +0x00021219 T lld_con_llcp_tx +0x00021325 T lld_con_offset_get +0x00021359 T lld_con_offset_upd_ind_handler +0x00021395 T lld_con_param_upd_cfm_handler +0x00021405 T lld_con_param_update +0x00021479 T lld_con_peer_sca_set +0x000214a1 T lld_con_phys_update +0x00021501 T lld_con_pref_slave_evt_dur_set +0x0002153d T lld_con_pref_slave_latency_set +0x00021565 T lld_con_rssi_get +0x00021a4d T lld_con_rx_enc +0x00021dd5 T lld_con_start +0x0002216d T lld_con_stop +0x000221c1 T lld_con_sync_info_get +0x00022215 T lld_con_time_get +0x0002224d T lld_con_tx_enc +0x000222ed T lld_con_tx_len_update_for_intv +0x00022329 T lld_con_tx_len_update_for_rate +0x000225e1 T lld_conless_cte_rx_ind_handler +0x000229dd T lld_disc_ind_handler +0x00022a21 T lld_init +0x00022b01 T lld_init_connect_req_pack +0x00022c19 T lld_init_end_ind_handler +0x00023205 T lld_init_init +0x00023921 T lld_init_start +0x00023f95 T lld_init_stop +0x00024045 T lld_llcp_rx_ind_handler +0x0002419d T lld_llcp_tx_cfm_handler +0x000241e1 T lld_local_sca_get +0x000242ad T lld_per_adv_ch_map_update +0x00024569 T lld_per_adv_cte_start +0x000245b5 T lld_per_adv_cte_stop +0x00024601 T lld_per_adv_data_update +0x00024679 T lld_per_adv_end_ind_handler +0x00024e89 T lld_per_adv_info_get +0x00024f19 T lld_per_adv_init +0x00024f51 T lld_per_adv_init_info_get +0x00024fa5 T lld_per_adv_list_add +0x00025041 T lld_per_adv_list_rem +0x000250b9 T lld_per_adv_rep_ind_handler +0x00025429 T lld_per_adv_rx_end_ind_handler +0x00025655 T lld_per_adv_start +0x000258a5 T lld_per_adv_stop +0x00025935 T lld_per_adv_sync_info_get +0x00025989 T lld_phy_upd_cfm_handler +0x000259c1 T lld_ral_search +0x00025a1d T lld_read_clock +0x00025a2d T lld_res_list_add +0x00025ae1 T lld_res_list_clear +0x00025b01 T lld_res_list_local_rpa_get +0x00025b35 T lld_res_list_peer_rpa_get +0x00025b6d T lld_res_list_peer_update +0x00025b89 T lld_res_list_priv_mode_update +0x00025bad T lld_res_list_rem +0x00025bc5 T lld_rpa_renew +0x00025d1d T lld_rxdesc_check +0x00025d49 T lld_rxdesc_free +0x00026071 T lld_scan_create_sync +0x000260b9 T lld_scan_create_sync_cancel +0x000261e9 T lld_scan_end_ind_handler +0x000266c5 T lld_scan_init +0x00026715 T lld_scan_params_update +0x000272c1 T lld_scan_req_ind_handler +0x0002730d T lld_scan_restart +0x00027371 T lld_scan_start +0x00027831 T lld_scan_stop +0x000279c5 T lld_sync_ch_map_update +0x00027a39 T lld_sync_cte_start +0x00027a81 T lld_sync_cte_stop +0x00027ca5 T lld_sync_info_get +0x00027d31 T lld_sync_init +0x00028545 T lld_sync_start +0x00028701 T lld_sync_start_req_handler +0x000287e5 T lld_sync_stop +0x00028859 T lld_test_end_ind_handler +0x00028af9 T lld_test_init +0x00028b25 T lld_test_start +0x00028fa1 T lld_test_stop +0x00029059 T lld_white_list_add +0x000290e1 T lld_white_list_rem +0x00029145 T llhwc_phy_initialization +0x00029315 T llhwc_phy_prerx +0x00029401 T llm_activity_free_get +0x00029459 T llm_adv_act_id_get +0x000294b5 T llm_adv_hdl_to_id +0x00029599 T llm_adv_set_id_get +0x00029705 T llm_ch_map_update +0x00029845 T llm_ch_map_update_ind_handler +0x000298b1 T llm_clk_acc_set +0x000298e1 T llm_cmd_cmp_send +0x000298fd T llm_cmd_stat_send +0x00029919 T llm_dev_list_empty_entry +0x0002993d T llm_dev_list_search +0x000299e9 T llm_hci_command_handler +0x00029a1d T llm_init +0x00029b91 T llm_is_dev_connected +0x00029be5 T llm_is_dev_synced +0x00029cd5 T llm_le_evt_mask_check +0x00029cf9 T llm_le_features_get +0x00029d01 T llm_link_disc +0x00029ddd T llm_master_ch_map_get +0x00029e21 T llm_per_adv_sync +0x00029efd T llm_plan_elt_get +0x00029f4d T llm_ral_get +0x00029f55 T llm_ral_is_empty +0x00029f7d T llm_ral_search +0x00029fd5 T llm_rx_path_comp_get +0x00029fe1 T llm_scan_period_to_handler +0x0002a0e5 T llm_scan_sync_info_get +0x0002a155 T llm_tx_path_comp_get +0x0002a161 T lpuart_init +0x0002a215 T lpuart_send_array +;0x0002a249 T main +0x0002a3a9 T notEqual256 +0x0002a731 T phy_upd_proc_start +0x0002a785 T platform_reset +0x0002a7bd T pmu_hck_config +;0x0002a7e5 T prf_add_profile +;0x0002a875 T prf_cleanup +;0x0002a8b5 T prf_create +;0x0002a8ed T prf_env_get +;0x0002a91d T prf_get_id_from_task +;0x0002a955 T prf_get_task_from_id +;0x0002a98d T prf_init +0x0002aa05 T recv_more_data +0x0002aa81 T reinit_params +0x0002aae1 T rf_init +0x0002ac85 T rwble_hl_init +0x0002aca1 T rwble_init +0x0002acdd T rwble_int_init +0x0002ae31 T rwble_isr +0x0002ae4d T rwip_active_check +0x0002ae61 T rwip_aes_encrypt +0x0002af21 T rwip_clockn_isr +0x0002afe5 T rwip_crypt_isr +0x0002b025 T rwip_driver_init +0x0002b16d T rwip_eif_get +0x0002b17d T rwip_fifo_isr +0x0002b195 T rwip_finetgt_isr +;0x0002b1c1 T rwip_init +0x0002b2b5 T rwip_prevent_sleep_clear +0x0002b2d1 T rwip_prevent_sleep_set +;0x0002b2ed T rwip_reset +0x0002b3a1 T rwip_schedule +;0x0002b3b9 T rwip_sleep +;0x0002b529 T rwip_slp_isr +0x0002b61d T rwip_sw_int_req +0x0002b63d T rwip_sw_isr +0x0002b65d T rwip_time_get +0x0002b69d T rwip_timer_1ms_set +0x0002b6f1 T rwip_timer_hs_set +0x0002b721 T rwip_timer_hus_set +0x0002b761 T rwip_timestamptgt1_isr +0x0002b78d T rwip_timestamptgt2_isr +0x0002b7d5 T sch_alarm_init +0x0002b859 T sch_alarm_set +0x0002b8f1 T sch_alarm_timer_isr +0x0002ba25 T sch_arb_elt_cancel +0x0002bb29 T sch_arb_event_start_isr +0x0002bbed T sch_arb_init +0x0002bc19 T sch_arb_insert +0x0002bec5 T sch_arb_remove +0x0002bf29 T sch_arb_sw_isr +0x0002bf5d T sch_plan_chk +0x0002bf6d T sch_plan_init +0x0002c231 T sch_plan_rem +0x0002c241 T sch_plan_req +0x0002c30d T sch_plan_set +0x0002c381 T sch_prog_end_isr +0x0002c3ed T sch_prog_fifo_isr +0x0002c4d9 T sch_prog_init +0x0002c519 T sch_prog_push +0x0002c651 T sch_prog_skip_isr +0x0002c6c5 T sch_slice_bg_add +0x0002c6dd T sch_slice_bg_remove +0x0002c6f5 T sch_slice_compute +0x0002c7a1 T sch_slice_fg_add +0x0002c7c1 T sch_slice_fg_remove +0x0002c7f1 T sch_slice_init +0x0002c835 T sch_slice_per_add +0x0002c85d T sch_slice_per_remove +0x0002c885 T sleep_condition_check +0x0002c91d T soft_flow_ctrl_init +0x0002c969 T soft_flow_ctrl_tx_process +0x0002c9dd T specialModP256 +0x0002cad5 T spis_init +0x0002cb39 T stage_idle_irq_handler +0x0002cbb5 T stage_idle_reset +0x0002cc25 T stage_rx_irq_handler +0x0002cc41 T stage_tx_irq_handler +0x0002cd21 T stage_tx_len_irq_handler +0x0002cd89 T user_exe_operation +0x0002d011 T user_prf_itf_get +0x0002d045 T utils_data_ready_off +0x0002d055 T utils_data_ready_on +0x0002d085 T utils_flow_off +0x0002d0b1 T utils_flow_on +0x0002d0d9 T utils_get_tx_len +0x0002d121 T utils_hci_cmd_check +0x0002d1b9 T utils_hci_cmd_reset +0x0002d22d T utils_io_init +0x0002d289 T utils_io_sleep +0x0002d33d T utils_read +0x0002d4c9 T utils_read_wakeup_stat +0x0002d4d9 T utils_wakeup_int_enable +0x0002d521 T utils_write +0x0002d691 T wakeup_irq_handler +0x0002d740 D one_bits +0x0002d750 D co_sca2ppm +0x0002d760 D co_null_bdaddr +0x0002d766 D co_null_key +0x0002d776 D co_rate_to_phy +0x0002d77b D co_phy_to_rate +0x0002d77f D co_phy_mask_to_value +0x0002d784 D co_phy_value_to_mask +0x0002d788 D co_rate_to_phy_mask +0x0002d78c D co_phy_mask_to_rate +0x0002d791 D rwip_priority +0x0002d7a7 D aes_cmac_zero +0x0002d7b8 D BasePoint_x_256 +0x0002d7d8 D BasePoint_y_256 +0x0002d7f8 D maxSecretKey_256 +0x0002d818 D DebugE256PublicKey_x +0x0002d838 D DebugE256PublicKey_y +0x0002d858 D DebugE256SecretKey +0x0002d878 D coef_B +0x0002d8a4 D bigHexP256 +0x0002d8d0 D veryBigHexP256 +0x0002d920 D ecc_Jacobian_InfinityPoint256 +0x0002d9a4 D ECC_4Win_Look_up_table +0x0002e4bc D TASK_DESC_LLC +0x0002e4c8 D LLM_AA_CT2 +0x0002e4ca D LLM_AA_CT1 +0x0002e4d0 D connect_req_dur_tab +0x0002e4d8 D byte_tx_time +0x0002e4e0 D fixed_tx_time +0x0002e4e8 D lld_init_max_aux_dur_tab +0x0002e4f0 D lld_scan_map_legacy_pdu_to_evt_type +0x0002e4f8 D lld_scan_max_aux_dur_tab +0x0002e500 D lld_sync_max_aux_dur_tab +;0x0002e8b8 D TASK_DESC_LLM +0x0002e8e4 D hci_cmd_desc_tab_lk_ctrl +0x0002e8fc D hci_cmd_desc_tab_ctrl_bb +0x0002e968 D hci_cmd_desc_tab_info_par +0x0002e998 D hci_cmd_desc_tab_stat_par +0x0002e9a4 D hci_cmd_desc_tab_le +0x0002ee0c D hci_cmd_desc_tab_vs +0x0002ee48 D hci_cmd_desc_root_tab +0x0002ee78 D hci_evt_desc_tab +0x0002eec0 D hci_evt_le_desc_tab +0x0002ef90 D utils_api +;0x0002f138 D TASK_DESC_APP +0x0002f148 D ambiq_speed_att_db_128 +;0x0002f224 D init_addr +;0x0002f299 D init_data +;0x0002f30e D init_delay +0x0002f3f8 D attc_handlers +0x0002f434 D atts_handlers +0x0002f514 D TASK_DESC_GATTC +0x0002f530 D TASK_DESC_GATTM +0x0002f62c D gapc_sig_handlers +0x0002f7bc D TASK_DESC_GAPC +0x0002fa08 D TASK_DESC_GAPM +0x0002fb28 D l2cc_sig_handlers +0x0002fb88 D TASK_DESC_L2CC +0x0002fb9c D TASK_DESC_AHI +0x20000000 D rwip_rst_state +0x20000004 D ecc_env +0x20000010 D aa_gen +0x20000018 D lld_exp_sync_pos_tab +0x2000004c D sch_slice_params +0x20000054 D hci_ext_host +0x20000060 D g_modem_flag +0x20000061 D g_clock_src +0x20000062 D g_hci_transport_onff +0x20000063 D g_delay_div_param +0x20000064 D g_delay_us_div_param +0x20000068 D g_cal_hsi_cnt_value +0x2000006c D g_system_hsi_clk +0x20000070 D g_user_set_stack_start +0x20000074 D g_rwip_patch_addr +0x20000078 D g_phy_2mbps_support +0x20000079 D g_auto_start_data_length_req +0x2000007a D g_sleep_sleep_enable +0x2000007b D g_status_io_stat +0x2000007c D g_timeoutcnt +0x20000080 D g_sleep_status_flag +0x20000084 D g_lsi_count_n_syscle +0x20000088 D g_lsi_accuracy +0x2000008c D g_lsi_1_syscle_cal_value +0x20000090 D g_lsi_1_syscle_cnt_value +0x20000094 D g_recalib_hsi_flag +0x20000098 D g_hsi_accuracy +0x2000009c D g_hci_transport_type +0x2000009d D g_hci_transport_process +0x2000009e D acl_flow_ctrl_num +0x2000009f D acl_flow_ctrl +0x200000a0 D g_acl_tx_sch_interval +0x200000a4 D dma_recv_data_time_window_size +0x200000a8 D g_length_2_data_intv +0x200000ac D g_soft_flow_tx_dummy +0x200000b0 D g_soft_flow_rx_len +0x200000b2 D g_hci_ch_type +0x200000b4 D g_uart_bps +0x200000b8 D g_uart_irq_wakeup_time +0x200000bc D g_spi_data_ready_2_irq_rise +0x200000c0 D g_lpclk_drift +0x200000c4 D g_rc32k_trim +0x200000c6 D g_sch_prog_fifo_iar_branch +0x200000c7 D g_sch_arb_insert_branch +0x200000c8 D g_le_coded_phy_500 +0x20000065 D g_loop_test +0x20000066 D g_ota_test +0x20000067 D g_ota_test_mtu_247_dle +0x200000c9 D g_app_init_branch +0x200000ca D g_adv_intv +0x200000d2 D g_twrm +0x200000d4 D g_twosc +0x200000d6 D g_twext +0x200000d8 D rwip_prog_delay +0x200000d9 D g_ramcode_work_flag +0x200000dc D prf_add_profile_ptr +0x200000e0 D prf_get_task_from_id_ptr +0x200000e4 D prf_get_id_from_task_ptr +0x200000fc D g_co_default_bdaddr +0x20000102 D BLE_NORMAL_WIN_SIZE +0x20000103 D BLE_RX_DESC_NB +0x20000104 D RWIP_MINIMUM_SLEEP_TIME +0x20000106 D SCH_SCAN_EVT_DUR_DFT +0x20000108 D llm_local_le_feats +0x20000110 D g_attr_table +0x20000114 D ATTR_TABLE_LENGTH +0x20000118 D g_rwip_heap_env +0x2000011c D g_rwip_heap_env_size +0x20000120 D g_rwip_heap_db +0x20000124 D g_rwip_heap_db_size +0x20000128 D g_rwip_heap_non_ret +0x2000012c D g_rwip_heap_non_ret_size +0x20000130 D g_rwip_heap_msg +0x20000134 D g_rwip_heap_msg_size +0x20000138 D utils_recv_buf_ptr +0x2000013c D utils_max_buf_len +0x20000140 D g_soft_flow_tx_buf +0x20000144 D g_soft_flow_tx_len +0x20000148 D g_app_tx_buf_ptr +0x2000014c D g_app_tx_buf_len +0x20000150 D g_app_bone_table_ptr +0x20000154 D g_app_bone_table_size +0x2000015c D g_soft_flow_tx_callback +0x20000160 D utils_recv_len +0x20000162 D g_recv_len +0x2000018c D s_dma_spis_set_rx_len +0x2000018e D s_dma_spis_set_tx_len +0x20000190 D s_dma_lpuart_set_len +0x20000194 D TASK_DESC_APP_SEC +;0x200001a0 D app_sec_env +0x200001a1 D g_version +;0x200001a7 D app_state +0x200001a8 D ota_test_mode +0x200001ac D ota_send_num_idx +0x200001b0 D gattc_state +0x200001b4 D gattm_state +0x200001b5 D gapc_state +0x200001b9 D gapm_state +0x200001ba D l2cc_state +0x200001be D ahi_state +0x200001c4 D __stdout +0x200001c8 D ke_env +0x20000274 D rwip_rf +0x200002a8 D rwip_env +0x200002c8 D aes_env +0x200002fc D llc_env +0x2000030c D lld_env +0x20000430 D lld_sync_env +0x20000440 D llm_env +0x20000978 D hci_env +0x200009b4 D hci_tl_acl_env +0x20000a3c D utils_env +;0x20000a50 D app_env +0x20000b30 D user_prf_env +0x20000b58 D gattc_env +0x20000b68 D gattm_env +0x20000ba0 D gapc_env +0x20000bb0 D gapm_env +0x20000c00 D l2cc_env +0x20000c10 D l2cm_env +;0x20000c1c D prf_env +0x20000ce4 D ahi_env diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/symdef/symbol_g15_central.obj b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/symdef/symbol_g15_central.obj new file mode 100644 index 0000000..b8414c8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_ble_stack/symdef/symbol_g15_central.obj @@ -0,0 +1,1066 @@ +## ARM Linker, 5060528: Last Updated: Tue May 25 20:40:17 2021 +;0x00000000 N __ARM_use_no_argv +;0x000000c0 N __Vectors_Size +;0x00000000 D __Vectors +;0x000000c0 D __Vectors_End +;0x000000c1 T __main +;0x000000c1 T _main_stk +;0x000000c5 T _main_scatterload +;0x000000c9 T __main_after_scatterload +;0x000000c9 T _main_clock +;0x000000c9 T _main_cpp_init +;0x000000c9 T _main_init +;0x000000d1 T __rt_final_cpp +;0x000000d1 T __rt_final_exit +;0x000000d5 T __asm___12_global_var_c_182c16a4____REV16 +;0x000000d9 T __asm___12_global_var_c_182c16a4____REVSH +;0x000000dd T __stark_reinit +;0x00001001 T delay_cycles +;0x000000e1 T __asm___5_irq_c_c8460081____REV16 +;0x000000e5 T __asm___5_irq_c_c8460081____REVSH +;0x000000e9 T HardFault_IRQHandler +;0x00000101 T Reset_IRQHandler +;0x00000109 T MemManage_IRQHandler +;0x0000010b T BusFault_IRQHandler +;0x0000010d T UsageFault_IRQHandler +;0x00000111 T DebugMon_IRQHandler +;0x00002455 T PendSV_IRQHandler +;0x00000117 T Spi1_I2s1_IRQhandler +;0x00000929 T __aeabi_uidiv +;0x00000929 T __aeabi_uidivmod +;0x00000955 T __aeabi_idiv +;0x00000955 T __aeabi_idivmod +;0x0000097d T rand +;0x0000098f T srand +;0x000009a1 T ___aeabi_memcpy8$move +;0x000009a1 T __aeabi_memcpy +;0x000009a1 T __aeabi_memcpy4 +;0x000009a1 T __aeabi_memmove +;0x000009a1 T __aeabi_memmove4 +;0x000009a1 T __aeabi_memmove8 +;0x000009e1 T __aeabi_memset +;0x000009e1 T __aeabi_memset4 +;0x000009e1 T __aeabi_memset8 +;0x000009ef T __aeabi_memclr +;0x000009ef T __aeabi_memclr4 +;0x000009ef T __aeabi_memclr8 +;0x000009f3 T _memset$wrapper +;0x00000a05 T memcmp +;0x00000a21 T __scatterload +;0x00000a21 T __scatterload_rt2 +;0x00000a45 T __decompress +;0x00000a45 T __decompress1 +0x00000a9d T Adc_IRQHandler +0x00000abd T Add2SelfBigHex256 +0x00000b05 T AddBigHex256 +0x00000b55 T AddBigHexModP256 +0x00000ba5 T AddP256 +0x00000bd5 T AddPdiv2_256 +0x00000cdd T BT_set_advert_data +;0x00000d69 T BleCypt_IRQHandler +;0x00000d89 T BleError_IRQHandler +;0x00000da9 T BleFifo_IRQHandler +;0x00000dc9 T BleFinetgt_IRQHandler +;0x00000de9 T BleHslot_IRQHandler +;0x00000e05 T BleSlp_IRQHandler +;0x00000e25 T BleSw_IRQHandler +;0x00000e41 T BleTimestamptg1_IRQHandler +;0x00000e61 T BleTimestamptg2_IRQHandler +;0x00000ea1 T DMA_ConfigInt +;0x00000eb1 T DMA_DeInit +;0x00000f39 T DMA_EnableChannel +;0x00000f51 T DMA_GetCurrDataCounter +;0x00000f59 T DMA_Init +;0x00000f99 T DMA_RequestRemap +;0x00000fa1 T DmaCh1234_IRQHandler +;0x00000fc1 T DmaCh1234_Int_Err_Handler +;0x00000fc5 T DmaCh5_IRQHandler +;0x00001009 T EXTI_InitPeripheral +0x00001079 T EXTI_PA11_Configuration +;0x00000fe5 T Exti0_1_IRQHandler +;0x000010b5 T Exti2_3_IRQHandler +;0x000010d1 T Exti4_15_IRQHandler +;0x000010f1 T GF_Jacobian_Point_Addition256 +;0x00001645 T GF_Jacobian_Point_Double256 +;0x000017d1 T GPIO_InitPeripheral +;0x00001925 T GPIO_ReadInputDataBit +;0x00001933 T GPIO_ResetBits +;0x00001937 T GPIO_SetBits +;0x0000193d T HardFault_Handler_C +;0x0000194d T Hdiv_IRQHandler +;0x00002191 T I2c_IRQHandler +;0x000021b1 T KeyScan_IRQHandler +;0x000021d1 T LPUart_IRQHandler +0x00002211 T ModuleIrqRegister +0x0000223d T ModuleIrqRemoval +;0x00002271 T MultiplyBigHexByUint32_256 +;0x000022c1 T MultiplyBigHexModP256 +;0x00002441 T NMI_IRQHandler +;0x00002465 T QspiFlash_IRQHandler +;0x00002481 T RAMFUNC_FLAG +;0x000024dd T RCC_EnableAHBPeriphClk +;0x000024f5 T RCC_EnableAPB1PeriphClk +;0x00002525 T RCC_EnableAPB2PeriphClk +;0x0000253d T Rcc_IRQHandler +;0x00002559 T Rtc_IRQHandler +;0x00002575 T SPI_Enable +;0x00002589 T SPI_Init +;0x000025c9 T SVC_IRQHandler +0x000025d9 T Spi2_IRQHandler +0x000025f9 T SubtractBigHex256 +0x00002655 T SubtractBigHexMod256 +0x00002751 T SubtractFromSelfBigHex256 +0x000027a5 T SubtractFromSelfBigHexSign256 +0x0000286d T SysTick_IRQHandler +0x00002895 T Tim1BrkUpRrgCom_IRQHandler +0x000028b5 T Tim1Cc_IRQHandler +0x000028d5 T Tim3_IRQHandler +0x000028f5 T Tim6_IRQHandler +0x00002915 T Usart1_IRQHandler +0x00002935 T Usart2_IRQHandler +0x00002955 T Wdt_IRQHandler +;0x00002971 T __2printf +0x00002985 T __ARM_common_ll_muluu +0x000029b7 T __ARM_common_memclr1_5 +0x000029c5 T __ARM_common_memclr1_6 +0x000029d5 T __ARM_common_memclr1_8 +0x000029e9 T __ARM_common_memclr2_10 +0x000029f7 T __ARM_common_memclr2_6 +0x00002a01 T __ARM_common_memclr2_8 +0x00002a0d T __ARM_common_memcpy1_5 +0x00002a23 T __ARM_common_memcpy1_6 +0x00002a3d T __ARM_common_memcpy1_8 +0x00002a5f T __ARM_common_memcpy2_5 +0x00002a6d T __ARM_common_memcpy2_6 +0x00002a7b T __ARM_common_memcpy2_8 +0x00002a8d T __ARM_common_memcpy4_5 +0x00002a97 T __ARM_common_memset1_5 +0x00002aa5 T __ARM_common_memset4_5 +0x00002ae1 T __scatterload_copy +0x00002aef T __scatterload_null +0x00002af1 T __scatterload_zeroinit +0x00002b1d T acl_flow_ctrl_send +0x00002b5d T aes_alloc +0x00002b75 T aes_c1 +0x00002bf9 T aes_cmac +0x00002c45 T aes_cmac_continue +0x00002d71 T aes_cmac_start +0x00002da1 T aes_encrypt +0x00002e35 T aes_f4 +0x00002e89 T aes_init +0x00002ed9 T aes_rand +0x00002f09 T aes_result_handler +0x00002f61 T aes_rpa_gen +0x00002ff5 T aes_rpa_resolve +0x000030d9 T aes_shift_left_128 +0x00003101 T aes_start +0x00003131 T aes_xor_128 +0x000043b1 T ahi_init +0x00004425 T ahi_send_msg +0x0000452d T app2ahi_evt_cmd_cmp +0x00004599 T app2ahi_evt_other +;0x000045f1 T app_add_svc +;0x00004651 T app_adv_fsm_next +;0x0000480d T app_create_advertising +;0x0000485d T app_delete_advertising +;0x00004881 T app_disconnect +;0x000048ad T app_get_dev_name +;0x000048c5 T app_init +;0x00004af1 T app_obus_add +;0x00004b69 T app_obus_init +;0x00004bd1 T app_sec_get_bond_status +;0x00004c11 T app_sec_send_security_req +;0x00004c35 T app_send_gapm_reset_cmd +;0x00004c51 T app_stop_advertising +;0x00004ca9 T app_update_adv_state +;0x00004cb1 T app_update_param +0x00004cf5 T appc_data_lenght_extend +0x00004d25 T appm_exchange_mtu +;0x00004e3d T attc_l2cc_pdu_recv_handler +;0x00004e8d T attc_send_att_req +;0x00004eb9 T attm_att_get_perm +;0x00004ed1 T attm_att_update_perm +;0x00004f4d T attm_convert_to128 +;0x00004f95 T attm_get_value +;0x00005119 T attm_init +;0x0000513d T attm_is_bt16_uuid +;0x00005175 T attm_is_bt32_uuid +;0x000051b5 T attm_svc_create_db +;0x000052ab T attm_svc_create_db_128 +;0x000053d1 T attm_svc_get_permission +;0x000053ef T attm_uuid16_comp +;0x000053fd T attm_uuid_comp +;0x00005469 T attmdb_add_service +;0x000054e9 T attmdb_att_get_permission +;0x0000563d T attmdb_destroy +;0x0000566d T attmdb_get_attribute +;0x000056a1 T attmdb_get_max_len +;0x00005715 T attmdb_get_next_att +;0x00005799 T attmdb_get_service +;0x000057ed T attmdb_get_uuid +;0x000058d5 T attmdb_hash_compute +;0x00005dfd T attmdb_svc_check_hdl +;0x00006065 T attmdb_uuid16_comp +;0x000060a9 T atts_clear_prep_data +;0x000060e5 T atts_clear_read_cache +;0x00006105 T atts_clear_rsp_data +;0x000067b9 T atts_get_dest_task +;0x00006861 T atts_l2cc_pdu_recv_handler +;0x00006af1 T atts_process_pdu +;0x000071d9 T atts_send_error +;0x000071fd T atts_send_event +;0x000073b5 T atts_write_rsp_send +;0x0000746b T atts_write_signed_cfm +0x000074b1 T baseband_init +0x00007549 T bigHexInversion256 +0x0000777d T ble_util_buf_acl_tx_alloc +0x000077a5 T ble_util_buf_acl_tx_elt_get +0x0000780d T ble_util_buf_acl_tx_free +0x0000788d T ble_util_buf_adv_tx_alloc +0x000078b5 T ble_util_buf_adv_tx_free +0x0000791d T ble_util_buf_init +0x00007a5d T ble_util_buf_llcp_tx_alloc +0x00007a79 T ble_util_buf_llcp_tx_free +0x00007ac9 T ble_util_buf_rx_alloc +0x00007ae1 T ble_util_buf_rx_free +0x00007b51 T calib_clk_init +0x00007b65 T calib_hsi_clk +0x00007c1d T calib_lsi_clk +;0x00007d09 T check_calib_clk +0x00007e17 T co_bdaddr_compare +0x00007e37 T co_ble_pkt_dur_in_us +0x00007e69 T co_list_extract +0x00007ea3 T co_list_extract_after +0x00007ebd T co_list_extract_sublist +0x00007ed3 T co_list_init +0x00007edb T co_list_insert_after +0x00007f3d T co_list_insert_before +0x00007f8d T co_list_pool_init +0x00007faf T co_list_pop_front +0x00007fc3 T co_list_push_back +0x00007fe3 T co_list_push_back_sublist +0x00008003 T co_list_push_front +0x0000801b T co_list_size +0x00008031 T co_nb_good_le_channels +0x00008059 T co_util_pack +0x00008241 T co_util_unpack +0x00008471 T delay_n_10us +0x00008489 T delay_n_ms +0x000084a9 T delay_n_us +0x000084c1 T dl_upd_proc_start +0x00008531 T dma_lpuart_read +0x000085f9 T dma_lpuart_rx_len +0x00008615 T dma_soft_flow_ctrl_read +0x00008751 T dma_soft_flow_ctrl_write +0x00008885 T dma_spis_read +0x00008951 T dma_spis_rx_len +0x0000896d T dma_spis_tx_len +0x00008989 T dma_spis_write +0x00008b4d T ecc_gen_new_public_key +0x00008b6d T ecc_gen_new_secret_key +0x00008c65 T ecc_generate_key256 +0x00008ff5 T ecc_init +0x00009575 T entry_shutdown +;0x000095a5 T entry_sleep +;0x00009639 T entry_standby +;0x00009691 T entry_wakeup +;0x00009971 T fputc +;0x0000998d T gapc_auth_get +;0x000099c5 T gapc_auth_set +;0x00009a25 T gapc_bond_cfm_handler +;0x00009c81 T gapc_bond_cmd_handler +;0x0000a101 T gapc_con_cleanup +;0x0000a111 T gapc_con_create +;0x0000a505 T gapc_enc_keysize_get +;0x0000a521 T gapc_encrypt_cfm_handler +;0x0000a5c9 T gapc_encrypt_cmd_handler +;0x0000a74d T gapc_get_bdaddr +;0x0000a771 T gapc_get_chan_sel_algo +;0x0000a789 T gapc_get_conhdl +;0x0000a7a9 T gapc_get_conidx +;0x0000a7d5 T gapc_get_dest_task +;0x0000ab1d T gapc_get_operation +;0x0000ab39 T gapc_get_operation_ptr +;0x0000ab49 T gapc_get_requester +;0x0000ab69 T gapc_get_role +;0x0000ab89 T gapc_hci_handler +;0x0000abfd T gapc_init +;0x0000ac51 T gapc_is_sec_set +;0x0000ace1 T gapc_lk_sec_lvl_get +;0x0000af89 T gapc_param_update_sanity +;0x0000b039 T gapc_per_adv_sync_trans_cmd_handler +;0x0000b0f1 T gapc_process_op +;0x0000b191 T gapc_reschedule_operation +;0x0000b1c5 T gapc_security_cmd_handler +;0x0000b261 T gapc_send_complete_evt +;0x0000b2d5 T gapc_send_disconect_ind +;0x0000b2f9 T gapc_send_error_evt +;0x0000b469 T gapc_set_local_addr +;0x0000b4d9 T gapc_set_operation_ptr +;0x0000b601 T gapc_sig_pdu_recv_handler +;0x0000b639 T gapc_sign_cmd_handler +;0x0000bb21 T gapc_smp_cleanup +;0x0000bc6d T gapc_smp_gapm_cmp_evt_handler +;0x0000c15d T gapc_smp_pdu_recv +;0x0000c5b9 T gapc_smp_rep_attempts_timer_handler +;0x0000c7f1 T gapc_smp_timeout_timer_ind_handler +;0x0000ca65 T gapc_update_state +;0x0000ca9d T gapm_activity_create_cmd_handler +;0x0000cb7d T gapm_activity_delete_cmd_handler +;0x0000cc0d T gapm_activity_start_cmd_handler +;0x0000cc7d T gapm_activity_stop_cmd_handler +;0x0000cd55 T gapm_actv_alloc +;0x0000cd85 T gapm_actv_created +;0x0000cdf9 T gapm_actv_deleted +;0x0000ce75 T gapm_actv_get_hci_own_addr_type +;0x0000ce99 T gapm_actv_info_get +;0x0000cedd T gapm_actv_rand_addr_set_ind +;0x0000cef9 T gapm_actv_reset +;0x0000cf49 T gapm_actv_retrieve_cmd_cmp_evt +;0x0000cf81 T gapm_actv_started +;0x0000cfad T gapm_actv_stopped +;0x0000d119 T gapm_addr_init +;0x0000d135 T gapm_addr_renew_cmd_handler +;0x0000d1d9 T gapm_addr_renew_to_ind_handler +;0x0000d201 T gapm_addr_set_rand_addr +;0x0000d265 T gapm_adv_create +;0x0000d96d T gapm_cmp_evt_handler +;0x0000d989 T gapm_con_cleanup +;0x0000d9bd T gapm_con_create +;0x0000da29 T gapm_dev_bdaddr_ind_handler +;0x0000da6d T gapm_dle_val_check +;0x0000da8d T gapm_gen_rand_addr_cmd_handler +;0x0000db31 T gapm_get_address_type +;0x0000db41 T gapm_get_att_handle +;0x0000db85 T gapm_get_bdaddr +;0x0000db8d T gapm_get_dev_info_cmd_handler +;0x0000dcc1 T gapm_get_id_from_task +;0x0000dd15 T gapm_get_irk +;0x0000dd1d T gapm_get_max_mtu +;0x0000dd29 T gapm_get_operation +;0x0000dd41 T gapm_get_ral_addr_cmd_handler +;0x0000dd99 T gapm_get_requester +;0x0000ddb5 T gapm_get_task_from_id +;0x0000de5d T gapm_init +;0x0000defd T gapm_is_legacy_pairing_supp +;0x0000df0d T gapm_is_pref_con_param_pres +;0x0000df1d T gapm_is_sec_con_pairing_supp +;0x0000df2d T gapm_le_test_mode_ctrl_cmd_handler +;0x0000e01d T gapm_lepsm_register_cmd_handler +;0x0000e045 T gapm_lepsm_unregister_cmd_handler +;0x0000e06d T gapm_list_set_cmd_handler +;0x0000e271 T gapm_process_op +;0x0000e355 T gapm_profile_task_add_cmd_handler +;0x0000e3d9 T gapm_reset_cmd_handler +;0x0000e44d T gapm_resolv_addr_cmd_handler +;0x0000e49d T gapm_send_complete_evt +;0x0000e4e5 T gapm_send_error_evt +;0x0000e509 T gapm_set_adv_data_cmd_handler +;0x0000e669 T gapm_set_channel_map_cmd_handler +;0x0000e6c9 T gapm_set_dev_config_cmd_handler +;0x0000e839 T gapm_set_irk_cmd_handler +;0x0000ea51 T gapm_use_enc_block_cmd_handler +;0x0000ebcd T gattc_cleanup +;0x0000ed79 T gattc_con_enable +;0x0000ee29 T gattc_con_info_send +;0x0000ee9d T gattc_create +;0x0000ef1d T gattc_db_updated +;0x0000eff5 T gattc_get_l2c_code +;0x0000f005 T gattc_get_mtu +;0x0000f015 T gattc_get_operation +;0x0000f031 T gattc_get_operation_ptr +;0x0000f041 T gattc_init +;0x0000f099 T gattc_is_db_out_of_sync +;0x0000f251 T gattc_process_op +;0x0000f565 T gattc_send_complete_evt +;0x0000f5c5 T gattc_send_error_evt +;0x0000f649 T gattc_set_mtu +;0x0000f6b1 T gattc_set_operation_ptr +;0x0000f6c1 T gattc_svc_att_info_req_ind_handler +;0x0000f70d T gattc_svc_chg_ind_send +;0x0000f761 T gattc_svc_read_req_ind_handler +;0x0000f7fd T gattc_svc_write_req_ind_handler +;0x0000f931 T gattc_update_state +;0x0000fb05 T gattm_att_hdl_to_idx +;0x0000fb25 T gattm_att_idx_to_hdl +;0x0000fb6d T gattm_cleanup +;0x0000fb77 T gattm_create +;0x0000fb81 T gattm_db_updated +;0x0000fbc9 T gattm_init +0x0000fee1 T h4tl_init +0x0000ff89 T h4tl_read_start_next +0x00010249 T h4tl_write +0x000102b5 T handle_all_data +0x000103d9 T hci_acl_data_handler +0x00010545 T hci_acl_tx_data_alloc +0x000105ad T hci_acl_tx_data_received +0x00010605 T hci_acl_tx_trigger +;0x00010665 T hci_basic_cmd_cmp_evt_cfg_handler +;0x000106f1 T hci_basic_cmd_cmp_evt_rl_cfg_handler +0x0001073d T hci_basic_cmd_send_2_controller +0x00010755 T hci_ble_conhdl_register +0x00010765 T hci_ble_conhdl_unregister +0x00010775 T hci_cmd_get_max_param_size +0x00010789 T hci_cmd_received +0x00010acd T hci_command_handler +0x00010b59 T hci_disconnect_cmd_handler +;0x00010bf1 T hci_enc_chg_evt_handler +;0x00010c13 T hci_enc_key_refr_evt_handler +0x00010c35 T hci_evt_mask_set +0x00010c8d T hci_fc_acl_buf_size_set +0x00010ca1 T hci_fc_acl_en +0x00010cd5 T hci_fc_acl_packet_sent +0x00010ce9 T hci_fc_check_host_available_nb_acl_packets +0x00010d0d T hci_fc_host_nb_acl_pkts_complete +0x00010d25 T hci_fc_init +0x00010e25 T hci_init +0x00010e71 T hci_le_add_dev_to_per_adv_list_cmd_handler +;0x000111fd T hci_le_adv_set_term_evt_handler +;0x00011281 T hci_le_ch_sel_algo_evt_handler +0x000112a5 T hci_le_clear_adv_sets_cmd_handler +0x00011319 T hci_le_clear_per_adv_list_cmd_handler +;0x00011445 T hci_le_cmd_cmp_evt_addr_handler +;0x00011465 T hci_le_cmd_cmp_evt_adv_handler +;0x00011679 T hci_le_cmd_cmp_evt_list_handler +0x000117c9 T hci_le_con_cte_req_en_cmd_handler +0x00011909 T hci_le_con_cte_rsp_en_cmd_handler +0x00011b09 T hci_le_con_upd_cmd_handler +0x00011e41 T hci_le_create_con_cancel_cmd_handler +0x00011ea1 T hci_le_create_con_cmd_handler +;0x00012275 T hci_le_enh_con_cmp_evt_handler +0x0001246d T hci_le_ext_create_con_cmd_handler +0x000129bd T hci_le_ltk_req_neg_reply_cmd_handler +0x00012a59 T hci_le_ltk_req_reply_cmd_handler +;0x00012acd T hci_le_ltk_request_evt_handler +0x00012bf1 T hci_le_per_adv_create_sync_cancel_cmd_handler +0x00012cc5 T hci_le_per_adv_create_sync_cmd_handler +0x00012d89 T hci_le_per_adv_set_info_transf_cmd_handler +0x00012e31 T hci_le_per_adv_sync_transf_cmd_handler +0x00012ec1 T hci_le_per_adv_term_sync_cmd_handler +0x00012fc1 T hci_le_rd_adv_ch_tx_pw_cmd_handler +;0x0001300d T hci_le_rd_adv_chnl_tx_pw_cmd_cmp_evt_handler +0x000130b5 T hci_le_rd_chnl_map_cmd_handler +0x000131dd T hci_le_rd_max_adv_data_len_cmd_handler +;0x00013219 T hci_le_rd_max_data_len_cmd_cmp_evt_handler +;0x0001328d T hci_le_rd_nb_supp_adv_sets_cmd_cmp_evt_handler +0x000132c9 T hci_le_rd_nb_supp_adv_sets_cmd_handler +0x00013371 T hci_le_rd_per_adv_list_size_cmd_handler +0x00013401 T hci_le_rd_phy_cmd_handler +;0x00013459 T hci_le_rd_ral_addr_cmd_cmp_evt_handler +;0x000134c5 T hci_le_rd_ral_size_cmd_cmp_evt_handler +0x00013521 T hci_le_rd_rem_feats_cmd_handler +;0x00013675 T hci_le_rd_rf_path_comp_cmd_cmp_evt_handler +;0x00013715 T hci_le_rd_suggted_dft_data_len_cmd_cmp_evt_handler +;0x000137b5 T hci_le_rd_tx_pwr_cmd_cmp_evt_handler +;0x0001386d T hci_le_rd_wlst_size_cmd_cmp_evt_handler +;0x000138c9 T hci_le_read_max_adv_data_len_cmd_cmp_evt_handler +0x00013961 T hci_le_rem_con_param_req_neg_reply_cmd_handler +0x000139c5 T hci_le_rem_con_param_req_reply_cmd_handler +0x00013a59 T hci_le_rmv_adv_set_cmd_handler +0x00013ac1 T hci_le_rmv_dev_from_per_adv_list_cmd_handler +0x00013c2d T hci_le_rx_test_v1_cmd_handler +0x00013c6f T hci_le_rx_test_v2_cmd_handler +0x00013cc1 T hci_le_rx_test_v3_cmd_handler +;0x00013d65 T hci_le_scan_req_rcvd_evt_handler +0x00013df5 T hci_le_set_adv_data_cmd_handler +0x00013ead T hci_le_set_adv_en_cmd_handler +0x000140f9 T hci_le_set_adv_param_cmd_handler +0x00014269 T hci_le_set_adv_set_rand_addr_cmd_handler +0x000142d5 T hci_le_set_con_cte_rx_param_cmd_handler +0x000143f1 T hci_le_set_con_cte_tx_param_cmd_handler +0x000144e5 T hci_le_set_conless_cte_tx_en_cmd_handler +0x000145b9 T hci_le_set_conless_cte_tx_param_cmd_handler +0x0001466d T hci_le_set_conless_iq_sampl_en_cmd_handler +0x00014779 T hci_le_set_data_len_cmd_handler +0x00014969 T hci_le_set_ext_adv_data_cmd_handler +0x00014af5 T hci_le_set_ext_adv_en_cmd_handler +0x000150e5 T hci_le_set_ext_adv_param_cmd_handler +0x000152d1 T hci_le_set_ext_scan_en_cmd_handler +0x0001551d T hci_le_set_ext_scan_param_cmd_handler +0x00015725 T hci_le_set_ext_scan_rsp_data_cmd_handler +0x000158cd T hci_le_set_per_adv_data_cmd_handler +0x000159f9 T hci_le_set_per_adv_en_cmd_handler +0x00015c25 T hci_le_set_per_adv_param_cmd_handler +0x00015d05 T hci_le_set_per_adv_rec_en_cmd_handler +0x00015d5d T hci_le_set_per_adv_sync_transf_param_cmd_handler +0x00015dd5 T hci_le_set_phy_cmd_handler +0x00016039 T hci_le_set_scan_en_cmd_handler +0x000161f1 T hci_le_set_scan_param_cmd_handler +0x00016311 T hci_le_set_scan_rsp_data_cmd_handler +0x000163c9 T hci_le_start_enc_cmd_handler +0x0001649d T hci_le_test_end_cmd_handler +0x000164c9 T hci_le_tx_test_v1_cmd_handler +0x00016519 T hci_le_tx_test_v2_cmd_handler +0x00016575 T hci_le_tx_test_v3_cmd_handler +0x000166a9 T hci_look_for_cmd_desc +0x00016705 T hci_look_for_evt_desc +0x0001672d T hci_look_for_le_evt_desc +;0x000167ef T hci_past_cmd_cmp_evt_handler +0x0001687d T hci_rd_auth_payl_to_cmd_handler +;0x000169d9 T hci_rd_local_ver_info_cmd_cmp_evt_handler +0x00016a79 T hci_rd_rem_ver_info_cmd_handler +0x00016be1 T hci_rd_rssi_cmd_handler +0x00016c55 T hci_rd_tx_pwr_lvl_cmd_handler +0x00016cf9 T hci_send_2_controller +0x00016d79 T hci_send_2_host +;0x00016f25 T hci_test_end_cmd_cmp_evt_handler +0x00016f75 T hci_tl_init +0x00016fcd T hci_tl_send +0x000173d9 T hci_vs_set_max_rx_size_and_time_cmd_handler +0x000174fd T hci_vs_set_pref_slave_evt_dur_cmd_handler +0x00017591 T hci_vs_set_pref_slave_latency_cmd_handler +0x00017611 T hci_wr_auth_payl_to_cmd_handler +0x00017671 T initdata_config +0x0001772d T interface_check +0x000177c5 T interface_reinit +0x00017805 T ke_event_callback_set +0x0001781d T ke_event_clear +0x00017845 T ke_event_get_all +0x00017851 T ke_event_init +0x00017871 T ke_event_schedule +0x000178ad T ke_event_set +0x000178d5 T ke_flush +0x00017919 T ke_free +0x000179e5 T ke_init +0x00017a15 T ke_is_free +0x00017a2d T ke_malloc +0x00017afd T ke_mem_init +0x00017b39 T ke_msg_alloc +0x00017b6b T ke_msg_discard +0x00017b71 T ke_msg_forward +0x00017b9d T ke_msg_free +0x00017ba5 T ke_msg_in_queue +0x00017bb1 T ke_msg_send +0x00017bd9 T ke_msg_send_basic +0x00017c25 T ke_msg_src_id_get +0x00017c2b T ke_queue_extract +0x00017c6d T ke_queue_insert +0x00017ca1 T ke_sleep_check +0x00017cb5 T ke_state_get +0x00017cd9 T ke_state_set +0x00017d41 T ke_task_check +0x00017d61 T ke_task_create +0x00017d95 T ke_task_delete +0x00017dc1 T ke_task_init +0x00017ddd T ke_task_msg_flush +0x00017f51 T ke_timer_active +0x00017f7d T ke_timer_clear +0x00017ff5 T ke_timer_init +0x000180bd T ke_timer_set +;0x000182b5 T l2cc_cleanup +;0x0001844f T l2cc_cmp_evt_handler +;0x0001847d T l2cc_create +;0x000184c5 T l2cc_data_send +;0x000186a9 T l2cc_init +;0x00018741 T l2cc_pdu_alloc +;0x0001876d T l2cc_pdu_header_check +;0x000188c5 T l2cc_pdu_pack +;0x00018c41 T l2cc_pdu_rx_init +;0x00018cbd T l2cc_pdu_send +;0x00018d25 T l2cc_pdu_unpack +;0x00018f55 T l2cc_send_cmp_evt +;0x00018f81 T l2cc_sig_pdu_recv_handler +;0x00018fc9 T l2cc_sig_send_cmd_reject +;0x00019021 T l2cm_cleanup +;0x0001903d T l2cm_create +;0x00019045 T l2cm_get_nb_buffer_available +;0x00019051 T l2cm_init +;0x000190d9 T l2cm_set_link_layer_buff_size +;0x000190e9 T l2cm_tx_status +0x00019119 T ll_channel_map_ind_handler +0x000191b5 T ll_clk_acc_req_handler +0x00019209 T ll_clk_acc_rsp_handler +0x00019245 T ll_connection_param_req_handler +0x0001931d T ll_connection_param_rsp_handler +0x000193b5 T ll_connection_update_ind_handler +0x000194d1 T ll_cte_req_handler +0x00019545 T ll_cte_rsp_handler +0x00019565 T ll_enc_req_handler +0x0001962d T ll_enc_rsp_handler +0x000196a5 T ll_feature_req_handler +0x0001972d T ll_feature_rsp_handler +0x00019781 T ll_length_req_handler +0x000198d5 T ll_length_rsp_handler +0x00019951 T ll_min_used_channels_ind_handler +0x000199d1 T ll_pause_enc_req_handler +0x00019a3d T ll_pause_enc_rsp_handler +0x00019a95 T ll_per_sync_ind_handler +0x00019bf5 T ll_phy_req_handler +0x00019ca5 T ll_phy_rsp_handler +0x00019d21 T ll_phy_update_ind_handler +0x00019db5 T ll_ping_req_handler +0x00019dc9 T ll_ping_rsp_handler +0x00019e25 T ll_slave_feature_req_handler +0x00019ead T ll_start_enc_req_handler +0x00019efd T ll_start_enc_rsp_handler +0x00019f4d T ll_terminate_ind_handler +0x00019fb1 T ll_version_ind_handler +0x0001a051 T llc_auth_payl_nearly_to_handler +0x0001a0b1 T llc_auth_payl_real_to_handler +0x0001a141 T llc_cleanup +0x0001a1a5 T llc_clk_acc_modify +0x0001a275 T llc_cmd_cmp_send +0x0001a295 T llc_cmd_stat_send +0x0001a2b1 T llc_con_move_cbk +0x0001a45d T llc_cte_req_dis +0x0001a47d T llc_cte_req_to_handler +0x0001a50d T llc_cte_rsp_dis +0x0001a521 T llc_disconnect +0x0001a729 T llc_encrypt_ind_handler +0x0001a9c1 T llc_init +0x0001aa65 T llc_init_term_proc +0x0001ab19 T llc_le_ping_restart +0x0001ab55 T llc_le_ping_set +0x0001abe1 T llc_ll_reject_ind_pdu_send +0x0001ac6d T llc_llcp_send +0x0001ace9 T llc_llcp_state_set +0x0001ada5 T llc_llcp_tx_check +0x0001bd71 T llc_op_ch_map_upd_ind_handler +0x0001bdd5 T llc_op_clk_acc_ind_handler +0x0001be2d T llc_op_con_upd_ind_handler +0x0001bebd T llc_op_cte_ind_handler +0x0001bf15 T llc_op_disconnect_ind_handler +0x0001bf81 T llc_op_dl_upd_ind_handler +0x0001c015 T llc_op_encrypt_ind_handler +0x0001c07d T llc_op_feats_exch_ind_handler +0x0001c115 T llc_op_le_ping_ind_handler +0x0001c171 T llc_op_past_ind_handler +0x0001c401 T llc_op_phy_upd_ind_handler +0x0001c4a5 T llc_op_ver_exch_ind_handler +0x0001c91d T llc_proc_collision_check +0x0001c955 T llc_proc_err_ind +0x0001c985 T llc_proc_get +0x0001c99d T llc_proc_id_get +0x0001c9b9 T llc_proc_reg +0x0001c9ed T llc_proc_state_get +0x0001c9f1 T llc_proc_state_set +0x0001c9f5 T llc_proc_timer_pause_set +0x0001ca4d T llc_proc_timer_set +0x0001caa5 T llc_proc_unreg +0x0001d309 T llc_start +0x0001d4fd T llc_stop +0x0001d531 T llc_stopped_ind_handler +0x0001d649 T lld_aa_gen +0x0001d6c9 T lld_acl_rx_ind_handler +0x0001d755 T lld_acl_tx_cfm_handler +0x0001d855 T lld_adv_adv_data_update +0x0001da55 T lld_adv_duration_update +0x0001db35 T lld_adv_end_ind_handler +0x0001dfd9 T lld_adv_evt_start_cbk +0x0001efc9 T lld_adv_init +0x0001f33d T lld_adv_rand_addr_update +0x0001f391 T lld_adv_rep_ind_handler +0x0001f891 T lld_adv_restart +0x0001fa11 T lld_adv_scan_rsp_data_update +0x0001fa49 T lld_adv_start +0x00020101 T lld_adv_stop +0x00020309 T lld_adv_sync_info_update +0x00020339 T lld_calc_aux_rx +0x00020465 T lld_ch_assess_data_get +0x0002046d T lld_ch_idx_get +0x00020491 T lld_ch_map_set +0x000204dd T lld_ch_map_upd_cfm_handler +0x00020515 T lld_channel_assess +0x0002054d T lld_con_activity_offset_compute +0x000205c5 T lld_con_ch_map_update +0x000206ed T lld_con_cte_rx_dis +0x00020721 T lld_con_cte_rx_en +0x000207e9 T lld_con_cte_rx_ind_handler +0x00020945 T lld_con_cte_tx_ant_switch_config +0x000209e1 T lld_con_cte_tx_param_set +0x000209f9 T lld_con_current_tx_power_get +0x00020a39 T lld_con_data_flow_set +0x00020aed T lld_con_data_len_update +0x00020b2d T lld_con_data_tx +0x00020bdd T lld_con_enc_key_load +0x00020c51 T lld_con_estab_ind_handler +0x00020c79 T lld_con_event_counter_get +0x000211d9 T lld_con_init +0x00021219 T lld_con_llcp_tx +0x00021325 T lld_con_offset_get +0x00021359 T lld_con_offset_upd_ind_handler +0x00021395 T lld_con_param_upd_cfm_handler +0x00021405 T lld_con_param_update +0x00021479 T lld_con_peer_sca_set +0x000214a1 T lld_con_phys_update +0x00021501 T lld_con_pref_slave_evt_dur_set +0x0002153d T lld_con_pref_slave_latency_set +0x00021565 T lld_con_rssi_get +0x00021a4d T lld_con_rx_enc +0x00021dd5 T lld_con_start +0x0002216d T lld_con_stop +0x000221c1 T lld_con_sync_info_get +0x00022215 T lld_con_time_get +0x0002224d T lld_con_tx_enc +0x000222ed T lld_con_tx_len_update_for_intv +0x00022329 T lld_con_tx_len_update_for_rate +0x000225e1 T lld_conless_cte_rx_ind_handler +0x000229dd T lld_disc_ind_handler +0x00022a21 T lld_init +0x00022b01 T lld_init_connect_req_pack +0x00022c19 T lld_init_end_ind_handler +0x00023205 T lld_init_init +0x00023921 T lld_init_start +0x00023f95 T lld_init_stop +0x00024045 T lld_llcp_rx_ind_handler +0x0002419d T lld_llcp_tx_cfm_handler +0x000241e1 T lld_local_sca_get +0x000242ad T lld_per_adv_ch_map_update +0x00024569 T lld_per_adv_cte_start +0x000245b5 T lld_per_adv_cte_stop +0x00024601 T lld_per_adv_data_update +0x00024679 T lld_per_adv_end_ind_handler +0x00024e89 T lld_per_adv_info_get +0x00024f19 T lld_per_adv_init +0x00024f51 T lld_per_adv_init_info_get +0x00024fa5 T lld_per_adv_list_add +0x00025041 T lld_per_adv_list_rem +0x000250b9 T lld_per_adv_rep_ind_handler +0x00025429 T lld_per_adv_rx_end_ind_handler +0x00025655 T lld_per_adv_start +0x000258a5 T lld_per_adv_stop +0x00025935 T lld_per_adv_sync_info_get +0x00025989 T lld_phy_upd_cfm_handler +0x000259c1 T lld_ral_search +0x00025a1d T lld_read_clock +0x00025a2d T lld_res_list_add +0x00025ae1 T lld_res_list_clear +0x00025b01 T lld_res_list_local_rpa_get +0x00025b35 T lld_res_list_peer_rpa_get +0x00025b6d T lld_res_list_peer_update +0x00025b89 T lld_res_list_priv_mode_update +0x00025bad T lld_res_list_rem +0x00025bc5 T lld_rpa_renew +0x00025d1d T lld_rxdesc_check +0x00025d49 T lld_rxdesc_free +0x00026071 T lld_scan_create_sync +0x000260b9 T lld_scan_create_sync_cancel +0x000261e9 T lld_scan_end_ind_handler +0x000266c5 T lld_scan_init +0x00026715 T lld_scan_params_update +0x000272c1 T lld_scan_req_ind_handler +0x0002730d T lld_scan_restart +0x00027371 T lld_scan_start +0x00027831 T lld_scan_stop +0x000279c5 T lld_sync_ch_map_update +0x00027a39 T lld_sync_cte_start +0x00027a81 T lld_sync_cte_stop +0x00027ca5 T lld_sync_info_get +0x00027d31 T lld_sync_init +0x00028545 T lld_sync_start +0x00028701 T lld_sync_start_req_handler +0x000287e5 T lld_sync_stop +0x00028859 T lld_test_end_ind_handler +0x00028af9 T lld_test_init +0x00028b25 T lld_test_start +0x00028fa1 T lld_test_stop +0x00029059 T lld_white_list_add +0x000290e1 T lld_white_list_rem +0x00029145 T llhwc_phy_initialization +0x00029315 T llhwc_phy_prerx +0x00029401 T llm_activity_free_get +0x00029459 T llm_adv_act_id_get +0x000294b5 T llm_adv_hdl_to_id +0x00029599 T llm_adv_set_id_get +0x00029705 T llm_ch_map_update +0x00029845 T llm_ch_map_update_ind_handler +0x000298b1 T llm_clk_acc_set +0x000298e1 T llm_cmd_cmp_send +0x000298fd T llm_cmd_stat_send +0x00029919 T llm_dev_list_empty_entry +0x0002993d T llm_dev_list_search +0x000299e9 T llm_hci_command_handler +0x00029a1d T llm_init +0x00029b91 T llm_is_dev_connected +0x00029be5 T llm_is_dev_synced +0x00029cd5 T llm_le_evt_mask_check +0x00029cf9 T llm_le_features_get +0x00029d01 T llm_link_disc +0x00029ddd T llm_master_ch_map_get +0x00029e21 T llm_per_adv_sync +0x00029efd T llm_plan_elt_get +0x00029f4d T llm_ral_get +0x00029f55 T llm_ral_is_empty +0x00029f7d T llm_ral_search +0x00029fd5 T llm_rx_path_comp_get +0x00029fe1 T llm_scan_period_to_handler +0x0002a0e5 T llm_scan_sync_info_get +0x0002a155 T llm_tx_path_comp_get +0x0002a161 T lpuart_init +0x0002a215 T lpuart_send_array +;0x0002a249 T main +0x0002a3a9 T notEqual256 +0x0002a731 T phy_upd_proc_start +0x0002a785 T platform_reset +0x0002a7bd T pmu_hck_config +;0x0002a7e5 T prf_add_profile +;0x0002a875 T prf_cleanup +;0x0002a8b5 T prf_create +;0x0002a8ed T prf_env_get +;0x0002a91d T prf_get_id_from_task +;0x0002a955 T prf_get_task_from_id +;0x0002a98d T prf_init +0x0002aa05 T recv_more_data +0x0002aa81 T reinit_params +0x0002aae1 T rf_init +;0x0002ac85 T rwble_hl_init +0x0002aca1 T rwble_init +0x0002acdd T rwble_int_init +0x0002ae31 T rwble_isr +0x0002ae4d T rwip_active_check +0x0002ae61 T rwip_aes_encrypt +0x0002af21 T rwip_clockn_isr +0x0002afe5 T rwip_crypt_isr +0x0002b025 T rwip_driver_init +0x0002b16d T rwip_eif_get +0x0002b17d T rwip_fifo_isr +0x0002b195 T rwip_finetgt_isr +;0x0002b1c1 T rwip_init +0x0002b2b5 T rwip_prevent_sleep_clear +0x0002b2d1 T rwip_prevent_sleep_set +;0x0002b2ed T rwip_reset +0x0002b3a1 T rwip_schedule +;0x0002b3b9 T rwip_sleep +;0x0002b529 T rwip_slp_isr +0x0002b61d T rwip_sw_int_req +0x0002b63d T rwip_sw_isr +0x0002b65d T rwip_time_get +0x0002b69d T rwip_timer_1ms_set +0x0002b6f1 T rwip_timer_hs_set +0x0002b721 T rwip_timer_hus_set +0x0002b761 T rwip_timestamptgt1_isr +0x0002b78d T rwip_timestamptgt2_isr +0x0002b7d5 T sch_alarm_init +0x0002b859 T sch_alarm_set +0x0002b8f1 T sch_alarm_timer_isr +0x0002ba25 T sch_arb_elt_cancel +0x0002bb29 T sch_arb_event_start_isr +0x0002bbed T sch_arb_init +0x0002bc19 T sch_arb_insert +0x0002bec5 T sch_arb_remove +0x0002bf29 T sch_arb_sw_isr +0x0002bf5d T sch_plan_chk +0x0002bf6d T sch_plan_init +0x0002c231 T sch_plan_rem +0x0002c241 T sch_plan_req +0x0002c30d T sch_plan_set +0x0002c381 T sch_prog_end_isr +0x0002c3ed T sch_prog_fifo_isr +0x0002c4d9 T sch_prog_init +0x0002c519 T sch_prog_push +0x0002c651 T sch_prog_skip_isr +0x0002c6c5 T sch_slice_bg_add +0x0002c6dd T sch_slice_bg_remove +0x0002c6f5 T sch_slice_compute +0x0002c7a1 T sch_slice_fg_add +0x0002c7c1 T sch_slice_fg_remove +0x0002c7f1 T sch_slice_init +0x0002c835 T sch_slice_per_add +0x0002c85d T sch_slice_per_remove +0x0002c885 T sleep_condition_check +0x0002c91d T soft_flow_ctrl_init +0x0002c969 T soft_flow_ctrl_tx_process +0x0002c9dd T specialModP256 +0x0002cad5 T spis_init +0x0002cb39 T stage_idle_irq_handler +0x0002cbb5 T stage_idle_reset +0x0002cc25 T stage_rx_irq_handler +0x0002cc41 T stage_tx_irq_handler +0x0002cd21 T stage_tx_len_irq_handler +0x0002cd89 T user_exe_operation +0x0002d011 T user_prf_itf_get +0x0002d045 T utils_data_ready_off +0x0002d055 T utils_data_ready_on +0x0002d085 T utils_flow_off +0x0002d0b1 T utils_flow_on +0x0002d0d9 T utils_get_tx_len +0x0002d121 T utils_hci_cmd_check +0x0002d1b9 T utils_hci_cmd_reset +0x0002d22d T utils_io_init +0x0002d289 T utils_io_sleep +0x0002d33d T utils_read +0x0002d4c9 T utils_read_wakeup_stat +0x0002d4d9 T utils_wakeup_int_enable +0x0002d521 T utils_write +0x0002d691 T wakeup_irq_handler +0x0002d740 D one_bits +0x0002d750 D co_sca2ppm +0x0002d760 D co_null_bdaddr +0x0002d766 D co_null_key +0x0002d776 D co_rate_to_phy +0x0002d77b D co_phy_to_rate +0x0002d77f D co_phy_mask_to_value +0x0002d784 D co_phy_value_to_mask +0x0002d788 D co_rate_to_phy_mask +0x0002d78c D co_phy_mask_to_rate +0x0002d791 D rwip_priority +0x0002d7a7 D aes_cmac_zero +0x0002d7b8 D BasePoint_x_256 +0x0002d7d8 D BasePoint_y_256 +0x0002d7f8 D maxSecretKey_256 +0x0002d818 D DebugE256PublicKey_x +0x0002d838 D DebugE256PublicKey_y +0x0002d858 D DebugE256SecretKey +0x0002d878 D coef_B +0x0002d8a4 D bigHexP256 +0x0002d8d0 D veryBigHexP256 +0x0002d920 D ecc_Jacobian_InfinityPoint256 +0x0002d9a4 D ECC_4Win_Look_up_table +0x0002e4bc D TASK_DESC_LLC +0x0002e4c8 D LLM_AA_CT2 +0x0002e4ca D LLM_AA_CT1 +0x0002e4d0 D connect_req_dur_tab +0x0002e4d8 D byte_tx_time +0x0002e4e0 D fixed_tx_time +0x0002e4e8 D lld_init_max_aux_dur_tab +0x0002e4f0 D lld_scan_map_legacy_pdu_to_evt_type +0x0002e4f8 D lld_scan_max_aux_dur_tab +0x0002e500 D lld_sync_max_aux_dur_tab +;0x0002e8b8 D TASK_DESC_LLM +0x0002e8e4 D hci_cmd_desc_tab_lk_ctrl +0x0002e8fc D hci_cmd_desc_tab_ctrl_bb +0x0002e968 D hci_cmd_desc_tab_info_par +0x0002e998 D hci_cmd_desc_tab_stat_par +0x0002e9a4 D hci_cmd_desc_tab_le +0x0002ee0c D hci_cmd_desc_tab_vs +0x0002ee48 D hci_cmd_desc_root_tab +0x0002ee78 D hci_evt_desc_tab +0x0002eec0 D hci_evt_le_desc_tab +0x0002ef90 D utils_api +;0x0002f138 D TASK_DESC_APP +0x0002f148 D ambiq_speed_att_db_128 +;0x0002f224 D init_addr +;0x0002f299 D init_data +;0x0002f30e D init_delay +;0x0002f3f8 D attc_handlers +;0x0002f434 D atts_handlers +;0x0002f514 D TASK_DESC_GATTC +;0x0002f530 D TASK_DESC_GATTM +;0x0002f62c D gapc_sig_handlers +;0x0002f7bc D TASK_DESC_GAPC +;0x0002fa08 D TASK_DESC_GAPM +;0x0002fb28 D l2cc_sig_handlers +;0x0002fb88 D TASK_DESC_L2CC +0x0002fb9c D TASK_DESC_AHI +0x20000000 D rwip_rst_state +0x20000004 D ecc_env +0x20000010 D aa_gen +0x20000018 D lld_exp_sync_pos_tab +0x2000004c D sch_slice_params +0x20000054 D hci_ext_host +0x20000060 D g_modem_flag +0x20000061 D g_clock_src +0x20000062 D g_hci_transport_onff +0x20000063 D g_delay_div_param +0x20000064 D g_delay_us_div_param +0x20000068 D g_cal_hsi_cnt_value +0x2000006c D g_system_hsi_clk +0x20000070 D g_user_set_stack_start +0x20000074 D g_rwip_patch_addr +0x20000078 D g_phy_2mbps_support +0x20000079 D g_auto_start_data_length_req +0x2000007a D g_sleep_sleep_enable +0x2000007b D g_status_io_stat +0x2000007c D g_timeoutcnt +0x20000080 D g_sleep_status_flag +0x20000084 D g_lsi_count_n_syscle +0x20000088 D g_lsi_accuracy +0x2000008c D g_lsi_1_syscle_cal_value +0x20000090 D g_lsi_1_syscle_cnt_value +0x20000094 D g_recalib_hsi_flag +0x20000098 D g_hsi_accuracy +0x2000009c D g_hci_transport_type +0x2000009d D g_hci_transport_process +0x2000009e D acl_flow_ctrl_num +0x2000009f D acl_flow_ctrl +0x200000a0 D g_acl_tx_sch_interval +0x200000a4 D dma_recv_data_time_window_size +0x200000a8 D g_length_2_data_intv +0x200000ac D g_soft_flow_tx_dummy +0x200000b0 D g_soft_flow_rx_len +0x200000b2 D g_hci_ch_type +0x200000b4 D g_uart_bps +0x200000b8 D g_uart_irq_wakeup_time +0x200000bc D g_spi_data_ready_2_irq_rise +0x200000c0 D g_lpclk_drift +0x200000c4 D g_rc32k_trim +0x200000c6 D g_sch_prog_fifo_iar_branch +0x200000c7 D g_sch_arb_insert_branch +0x200000c8 D g_le_coded_phy_500 +0x20000065 D g_loop_test +0x20000066 D g_ota_test +0x20000067 D g_ota_test_mtu_247_dle +0x200000c9 D g_app_init_branch +0x200000ca D g_adv_intv +0x200000d2 D g_twrm +0x200000d4 D g_twosc +0x200000d6 D g_twext +0x200000d8 D rwip_prog_delay +0x200000d9 D g_ramcode_work_flag +0x200000dc D prf_add_profile_ptr +0x200000e0 D prf_get_task_from_id_ptr +0x200000e4 D prf_get_id_from_task_ptr +0x200000fc D g_co_default_bdaddr +0x20000102 D BLE_NORMAL_WIN_SIZE +0x20000103 D BLE_RX_DESC_NB +0x20000104 D RWIP_MINIMUM_SLEEP_TIME +0x20000106 D SCH_SCAN_EVT_DUR_DFT +0x20000108 D llm_local_le_feats +0x20000110 D g_attr_table +0x20000114 D ATTR_TABLE_LENGTH +0x20000118 D g_rwip_heap_env +0x2000011c D g_rwip_heap_env_size +0x20000120 D g_rwip_heap_db +0x20000124 D g_rwip_heap_db_size +0x20000128 D g_rwip_heap_non_ret +0x2000012c D g_rwip_heap_non_ret_size +0x20000130 D g_rwip_heap_msg +0x20000134 D g_rwip_heap_msg_size +0x20000138 D utils_recv_buf_ptr +0x2000013c D utils_max_buf_len +0x20000140 D g_soft_flow_tx_buf +0x20000144 D g_soft_flow_tx_len +0x20000148 D g_app_tx_buf_ptr +0x2000014c D g_app_tx_buf_len +0x20000150 D g_app_bone_table_ptr +0x20000154 D g_app_bone_table_size +0x2000015c D g_soft_flow_tx_callback +0x20000160 D utils_recv_len +0x20000162 D g_recv_len +0x2000018c D s_dma_spis_set_rx_len +0x2000018e D s_dma_spis_set_tx_len +0x20000190 D s_dma_lpuart_set_len +0x20000194 D TASK_DESC_APP_SEC +;0x200001a0 D app_sec_env +0x200001a1 D g_version +;0x200001a7 D app_state +0x200001a8 D ota_test_mode +0x200001ac D ota_send_num_idx +0x200001b0 D gattc_state +0x200001b4 D gattm_state +0x200001b5 D gapc_state +0x200001b9 D gapm_state +0x200001ba D l2cc_state +0x200001be D ahi_state +0x200001c4 D __stdout +0x200001c8 D ke_env +0x20000274 D rwip_rf +0x200002a8 D rwip_env +0x200002c8 D aes_env +0x200002fc D llc_env +0x2000030c D lld_env +0x20000430 D lld_sync_env +0x20000440 D llm_env +0x20000978 D hci_env +0x200009b4 D hci_tl_acl_env +0x20000a3c D utils_env +;0x20000a50 D app_env +0x20000b30 D user_prf_env +0x20000b58 D gattc_env +0x20000b68 D gattm_env +0x20000ba0 D gapc_env +0x20000bb0 D gapm_env +0x20000c00 D l2cc_env +0x20000c10 D l2cm_env +;0x20000c1c D prf_env +0x20000ce4 D ahi_env diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/adv/ns_adv_data_def.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/adv/ns_adv_data_def.h new file mode 100644 index 0000000..1e6b8a5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/adv/ns_adv_data_def.h @@ -0,0 +1,206 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_adv_data_def.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +#ifndef _NS_ADV_DATA_DEF_H_ +#define _NS_ADV_DATA_DEF_H_ + +#include + +/* + * Advertising Data types. + * See https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Generic%20Access%20Profile.pdf +*/ +#define ADV_TYPE_FLAGS "\x01" /* Flags */ +#define ADV_TYPE_INCOMPLETE_LIST_16BIT_SERVICE_IDS "\x02" /* Incomplete list of 16-bit Service IDs */ +#define ADV_TYPE_COMPLETE_LIST_16BIT_SERVICE_IDS "\x03" /* Complete list of 16-bit Service IDs */ +#define ADV_TYPE_INCOMPLETE_LIST_32BIT_SERVICE_IDS "\x04" /* Incomplete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */ +#define ADV_TYPE_COMPLETE_LIST_32BIT_SERVICE_IDS "\x05" /* Complete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */ +#define ADV_TYPE_INCOMPLETE_LIST_128BIT_SERVICE_IDS "\x06" /* Incomplete list of 128-bit Service IDs */ +#define ADV_TYPE_COMPLETE_LIST_128BIT_SERVICE_IDS "\x07" /* Complete list of 128-bit Service IDs */ +#define ADV_TYPE_SHORTENED_LOCAL_NAME "\x08" /* Shortened Local Name */ +#define ADV_TYPE_COMPLETE_LOCAL_NAME "\x09" /* Complete Local Name */ +#define ADV_TYPE_TX_POWER_LEVEL "\x0A" /* TX Power Level (in dBm) */ +#define ADV_TYPE_CLASS_OF_DEVICE "\x0D" /* Class of Device */ +#define ADV_TYPE_SIMPLE_PAIRING_HASH_C "\x0E" /* Simple Pairing Hash C */ +#define ADV_TYPE_SIMPLE_PAIRING_RANDOM_R "\x0F" /* Simple Pairing Randomizer R */ +#define ADV_TYPE_DEVICE_ID "\x10" /* Device ID */ +#define ADV_TYPE_SECURITY_MAN_OUT_OF_BAND_FLAGS "\x11" /* Security Manager Out of Band Flags */ +#define ADV_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE "\x12" /* Slave Connection Interval Range */ +#define ADV_TYPE_LIST_16BIT_SOLICITATION_UUIDS "\x14" /* List of 16-bit Service Solicitation UUIDs */ +#define ADV_TYPE_LIST_32BIT_SOLICITATION_UUIDS "\x1F" /* List of 32-bit Service Solicitation UUIDs */ +#define ADV_TYPE_LIST_128BIT_SOLICITATION_UUIDS "\x15" /* List of 128-bit Service Solicitation UUIDs */ +#define ADV_TYPE_SERVICE_DATA_16BIT_UUID "\x16" /* Service Data - 16-bit UUID */ +#define ADV_TYPE_SERVICE_DATA_32BIT_UUID "\x20" /* Service Data - 32-bit UUID */ +#define ADV_TYPE_SERVICE_DATA_128BIT_UUID "\x21" /* Service Data - 128-bit UUID */ +#define ADV_TYPE_LE_SECURE_CON_CONFIRM_VAL "\x22" /* LE Secure Connections Confirmation Value */ +#define ADV_TYPE_LE_SECURE_CON_RANDOM_VAL "\x23" /* LE Secure Connections Random Value */ +#define ADV_TYPE_PUBLIC_TARGET_ADDRESS "\x17" /* Public Target Address */ +#define ADV_TYPE_RANDOM_TARGET_ADDRESS "\x18" /* Random Target Address */ +#define ADV_TYPE_APPEARANCE "\x19" /* Appearance */ +#define ADV_TYPE_ADVERTISING_INTERVAL "\x1A" /* Advertising Interval */ +#define ADV_TYPE_LE_BLUETOOTH_DEVICE_ADDRESS "\x1B" /* LE Bluetooth Device Address */ +#define ADV_TYPE_LE_ROLE "\x1C" /* LE Role */ +#define ADV_TYPE_SIMPLE_PAIRING_HASH_C256 "\x1D" /* Simple Pairing Hash C-256 */ +#define ADV_TYPE_SIMPLE_PAIRING_RANDOM_C256 "\x1E" /* Simple Pairing Randomizer R-256 */ +#define ADV_TYPE_INFO_DATA_3D "\x3D" /* 3D Information Data */ +#define ADV_TYPE_MANUFACTURER_SPECIFIC_DATA "\xFF" /* Manufacturer Specific Data */ + +/* + * AD Type Flag - Bit set. + */ +#define ADV_FLAG_LE_LIMITED_DISCOVERABLE "\x01" /* LE Limited Discoverable Mode */ +#define ADV_FLAG_LE_GENERAL_DISCOVERABLE "\x02" /* LE General Discoverable Mode */ +#define ADV_FLAG_BREDR_NOT_SUPPORTED "\x04" /* BR/EDR Not Supported */ +#define ADV_FLAG_SIMULTANEOUS_LE_BREDR_C "\x08" /* Simultaneous LE and BR/EDR to Same Device Capable (Controller) */ +#define ADV_FLAG_SIMULTANEOUS_LE_BREDR_H "\x10" /* Simultaneous LE and BR/EDR to Same Device Capable (Host) */ + +/* + * 16bit Service UUIDs in air format. + * See https://btprodspecificationrefs.blob.core.windows.net/assigned-values/16-bit%20UUID%20Numbers%20Document.pdf + */ +#define ADV_UUID_ALERT_NOTIFICATION_SERVICE "\x11\x18" /* Alert Notification Service */ +#define ADV_UUID_BATTERY_SERVICE "\x0F\x18" /* Battery Service */ +#define ADV_UUID_BLOOD_PRESSURE_SERVICE "\x10\x18" /* Blood Pressure */ +#define ADV_UUID_CURRENT_TIME_SERVICE "\x05\x18" /* Current Time Service */ +#define ADV_UUID_CYCLING_SPEED_AND_CADENCE "\x16\x18" /* Cycling Speed and Cadence */ +#define ADV_UUID_DEVICE_INFORMATION_SERVICE "\x0A\x18" /* Device Information Service */ +#define ADV_UUID_GLUCOSE_SERVICE "\x08\x18" /* Glucose */ +#define ADV_UUID_HEALTH_THERMOMETER_SERVICE "\x09\x18" /* Health Thermometer */ +#define ADV_UUID_HEART_RATE_SERVICE "\x0D\x18" /* Heart Rate */ +#define ADV_UUID_HUMAN_INTERFACE_DEVICE_SERVICE "\x12\x18" /* Human Interface Device */ +#define ADV_UUID_IMMEDIATE_ALERT_SERVICE "\x02\x18" /* Immediate Alert */ +#define ADV_UUID_LINK_LOSS_SERVICE "\x03\x18" /* Link Loss */ +#define ADV_UUID_NEXT_DST_CHANGE_SERVICE "\x07\x18" /* Next DST Change Service */ +#define ADV_UUID_PHONE_ALERT_STATUS_SERVICE "\x0E\x18" /* Phone Alert Status Service */ +#define ADV_UUID_REFERENCE_TIME_UPDATE_SERVICE "\x06\x18" /* Reference Time Update Service */ +#define ADV_UUID_RUNNING_SPEED_AND_CADENCE "\x14\x18" /* Running Speed and Cadence */ +#define ADV_UUID_SCAN_PARAMETERS_SERVICE "\x13\x18" /* Scan Parameters */ +#define ADV_UUID_TX_POWER_SERVICE "\x04\x18" /* Tx Power */ +#define ADV_UUID_GENERIC_ACCESS_SERVICE "\x00\x18" /* Generic Access */ +#define ADV_UUID_GENERIC_ATTRIBUTE_SERVICE "\x01\x18" /* Generic Attribute */ +#define ADV_UUID_SCAN_PARAMETERS_SERVICE "\x13\x18" /* Scan Parameters */ +#define ADV_UUID_AUTOMATION_IO_SERVICE "\x15\x18" /* Automation IO */ +#define ADV_UUID_CYCLING_POWER_SERVICE "\x18\x18" /* Cycling Power */ +#define ADV_UUID_LOCATION_NAVIGATION_SERVICE "\x19\x18" /* Location and Navigation */ +#define ADV_UUID_ENVIROMENT_SENSE_SERVICE "\x1A\x18" /* Environmental Sensing */ +#define ADV_UUID_BODY_COMPOSITION_SERVICE "\x1B\x18" /* Body Composition */ +#define ADV_UUID_USER_DATA_SERVICE "\x1C\x18" /* User Data */ +#define ADV_UUID_WEIGHT_SCALE_SERVICE "\x1D\x18" /* Weight Scale */ +#define ADV_UUID_BOND_MANAGMENT_SERVICE "\x1E\x18" /* Bond Management */ +#define ADV_UUID_GLUCOSE_CONTINUOUS_SERVICE "\x1F\x18" /* Continuous Glucose Monitoring */ +#define ADV_UUID_INTERNET_PROTOCOL_SERVICE "\x20\x18" /* Internet Protocol Support */ +#define ADV_UUID_INDOOR_POSITION_SERVICE "\x21\x18" /* Indoor Positioning */ +#define ADV_UUID_PULSE_OXIMETER_SERVICE "\x22\x18" /* Pulse Oximeter */ + +/* + * Values for the Appearance AD type in air format. + * See https://specificationrefs.bluetooth.com/assigned-values/Appearance%20Values.pdf + */ +#define ADV_APPEARANCE_UNKNOWN "\x00\x00" /* Unknown of unspecified appearance type */ +#define ADV_APPEARANCE_GENERIC_PHONE "\x40\x00" /* Generic Phone */ +#define ADV_APPEARANCE_GENERIC_COMPUTER "\x80\x00" /* Generic Computer */ +#define ADV_APPEARANCE_GENERIC_WATCH "\xC0\x00" /* Generic Watch */ +#define ADV_APPEARANCE_WATCH_SPORTS_WATCH "\xC1\x00" /* Sports Watch */ +#define ADV_APPEARANCE_GENERIC_CLOCK "\x00\x01" /* Generic Clock */ +#define ADV_APPEARANCE_GENERIC_DISPLAY "\x40\x01" /* Generic Display */ +#define ADV_APPEARANCE_GENERIC_REMOTE_CONTROL "\x80\x01" /* Generic Remote Control */ +#define ADV_APPEARANCE_GENERIC_EYE_GLASSES "\x0C\x01" /* Generic Eye Glasses */ +#define ADV_APPEARANCE_GENERIC_TAG "\x00\x02" /* Generic Tag */ +#define ADV_APPEARANCE_GENERIC_KEYRING "\x40\x02" /* Generic Keyring */ +#define ADV_APPEARANCE_GENERIC_MEDIA_PLAYER "\x80\x02" /* Generic Media Player */ +#define ADV_APPEARANCE_GENERIC_BARCODE_SCANNER "\xC0\x02" /* Generic Barcode Scanner */ +#define ADV_APPEARANCE_GENERIC_THERMOMETER "\x00\x03" /* Generic Thermometer */ +#define ADV_APPEARANCE_THERMOMETER_EAR "\x01\x03" /* Ear Thermometer */ +#define ADV_APPEARANCE_GENERIC_HEART_RATE_SENSOR "\x40\x03" /* Generic Heart Rate Sensor */ +#define ADV_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT "\x41\x03" /* Belt Heart Rate Sensor */ +#define ADV_APPEARANCE_GENERIC_BLOOD_PRESSURE "\x80\x03" /* Generic Blood Pressure */ +#define ADV_APPEARANCE_BLOOD_PRESSURE_ARM "\x81\x03" /* Arm Blood Pressure */ +#define ADV_APPEARANCE_BLOOD_PRESSURE_WRIST "\x82\x03" /* Wrist Blood Pressure */ +#define ADV_APPEARANCE_HUMAN_INTERFACE_DEVICE_HID "\xC0\x03" /* Human Interface Device (HID) */ +#define ADV_APPEARANCE_KEYBOARD "\xC1\x03" /* Keyboard */ +#define ADV_APPEARANCE_MOUSE "\xC2\x03" /* Mouse */ +#define ADV_APPEARANCE_JOYSTICK "\xC3\x03" /* Joystick */ +#define ADV_APPEARANCE_GAMEPAD "\xC4\x03" /* Gamepad */ +#define ADV_APPEARANCE_DIGITIZER_TABLET "\xC5\x03" /* Digitizer Tablet */ +#define ADV_APPEARANCE_CARD_READER "\xC6\x03" /* Card Read */ +#define ADV_APPEARANCE_DIGITAL_PEN "\xC7\x03" /* Digital Pen */ +#define ADV_APPEARANCE_BARCODE_SCANNER "\xC8\x03" /* Barcode Scanner */ +#define ADV_APPEARANCE_GENERIC_GLUCOSE_METER "\x00\x04" /* Generic Glucose Meter */ +#define ADV_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR "\x40\x04" /* Generic Running/Walking Sensor */ +#define ADV_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE "\x41\x04" /* In Shoe Running/Walking Sensor */ +#define ADV_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE "\x42\x04" /* On Shoe Running/Walking Sensor */ +#define ADV_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP "\x43\x04" /* On Hip Running/Walking Sensor */ +#define ADV_APPEARANCE_GENERIC_CYCLING "\x80\x04" /* Generic Cycling */ +#define ADV_APPEARANCE_CYCLING_CYCLING_COMPUTER "\x81\x04" /* Cycling Computer */ +#define ADV_APPEARANCE_CYCLING_SPEED_SENSOR "\x82\x04" /* Cycling Speed Senspr */ +#define ADV_APPEARANCE_CYCLING_CADENCE_SENSOR "\x83\x04" /* Cycling Cadence Sensor */ +#define ADV_APPEARANCE_CYCLING_POWER_SENSOR "\x84\x04" /* Cycling Power Sensor */ +#define ADV_APPEARANCE_CYCLING_SPEED_AND_CADENCE_SENSOR "\x85\x04" /* Cycling Speed and Cadence Sensor */ +#define ADV_APPEARANCE_PULSE_OXIMETER_GENERIC "\x40\x0C" /* Generic Pulse Oximeter */ +#define ADV_APPEARANCE_PULSE_OXIMETER_FINGERTIP "\x41\x0C" /* Fingertip Pulse Oximeter */ +#define ADV_APPEARANCE_PULSE_OXIMETER_WRIST_WORN "\x42\x0C" /* Wrist Worn Pulse Oximeter */ +#define ADV_APPEARANCE_OUTDOOR_GENERIC "\x40\x14" /* Generic Outdoor */ +#define ADV_APPEARANCE_OUTDOOR_LOCATION_DISPLAY_DEVICE "\x41\x14" /* Outdoor Location Display Device */ +#define ADV_APPEARANCE_OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE "\x42\x14" /* Outdoor Location and Navigation Display Device */ +#define ADV_APPEARANCE_OUTDOOR_LOCATION_POD "\x43\x14" /* Outdoor Location Pod */ +#define ADV_APPEARANCE_OUTDOOR_LOCATION_AND_NAVIGATION_POD "\x44\x14" /* Outdoor Location and Navigation Pod */ + + +#endif // _NS_ADV_DATA_DEF_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/aes_cbc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/aes_cbc.c new file mode 100644 index 0000000..6b991c8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/aes_cbc.c @@ -0,0 +1,226 @@ +/** + **************************************************************************************** + * * + * @file aes_cbc.c + * + * @brief Definition file for AES CBC crypto module functions + * + * Copyright (C) NSING Technologies Inc. + * + * + * + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + Algorithm AES-CBC + + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + + + * + Input : K ( 128-bit key ) + + * + Input : iv ( 128-bit iv ) + + * + : M ( message to be encipher or decipher) + + * + : len ( length of the message in octets ) + + * + Output : O ( message after encipher or decipher) + + * + + + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + + + * + Constants: const_Zero is 0x00000000000000000000000000000000 + + * + const_Bsize is 16 + + * + + + * + Variables: M_i is the i-th block (i=1..ceil(len/const_Bsize)) + + * + n for number of blocks to be processed + + * + r for number of octets of last block + + * + O for number of octets of last block + + * + + + * + Step 1. n := ceil(len/const_Bsize); + + * + Step 2. X := iv; + + * + Step 3. for i := 0 to n-1 do + + * + begin + + * + Y := X XOR M_i; + + * + X := AES-128(K,Y); + + * + O := O+X + + * + end + + * + Step 4. return O; + + * + + + * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup AES + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT) + +#include "arch.h" // architecture defines +#include "aes_int.h" // AES internals +#include // for memcpy function +#include "co_math.h" +#include "ns_aes.h" + + + +struct aes_cbc_env +{ + /// AES Environment structure + struct aes_func_env aes_env; + + /// M: Pointer to the message to be cypher + const uint8_t* message; // pointer to memory allocated by calling function + const uint8_t* iv; + + /// O: message to output + uint8_t* output; + + /// K: authentication key + uint8_t key_cache[AES_BLOCK_SIZE]; + uint8_t val_cache[AES_BLOCK_SIZE]; + /// Length of the message + uint16_t message_len; + /// Number of blocks (1 block = 16 bytes) + uint8_t num_blocks; + /// Current block to process + uint8_t cur_block; +}; + +void aes_cbc_start(struct aes_cbc_env* env, const uint8_t* key, const uint8_t* iv, const uint8_t* in_message, + uint8_t* out_message, uint16_t message_len); +bool aes_cbc_continue(struct aes_cbc_env* env, uint8_t* aes_res); + +/* + * EXPORTED FUNCTION DEFINITIONS + **************************************************************************************** + */ + + +void ns_aes_cbc(const uint8_t* key, const uint8_t* iv, const uint8_t* in_message, uint8_t* out_message, + bool cipher, uint16_t message_len, aes_func_result_cb res_cb) +{ + struct aes_cbc_env* aes_cbc; + uint32_t src_info; + if(cipher) + { + src_info = 0; + } + else{ + src_info = DECRYPT_SRC_MARK; + } + // Allocate AES CBC environent memory + aes_cbc = (struct aes_cbc_env*) aes_alloc(sizeof(struct aes_cbc_env), + (aes_func_continue_cb) aes_cbc_continue, res_cb, src_info); + + // start execution AES CBC + aes_cbc_start(aes_cbc, key, iv, in_message, out_message, message_len); +} + +void aes_cbc_start(struct aes_cbc_env* env, const uint8_t* key, const uint8_t* iv, const uint8_t* in_message, + uint8_t* out_message, uint16_t message_len) +{ + // copy information needed for AES-CBC execution + env->message = in_message; + env->output = out_message; + env->message_len = message_len; + env->iv = iv; + ns_ase_swap_array(env->key_cache,key,AES_BLOCK_SIZE); //swap array + // Step 1: + // initialize execution parameters + // num_blocks = ceil(message_len / block_size) + env->num_blocks = (env->message_len + AES_BLOCK_SIZE - 1) / AES_BLOCK_SIZE; + env->cur_block = 0; + // X := iv + + // Step 2: handle Blocks M_1 + const uint8_t *m_i = &(env->message[((env->cur_block) * AES_BLOCK_SIZE)]); + // start execution of the AES-CBC computation + + if(env->aes_env.src_info == DECRYPT_SRC_MARK) + { + ns_ase_swap_array(env->val_cache,m_i,AES_BLOCK_SIZE); //swap array + // Start AES execution + ns_aes_start(&(env->aes_env), env->key_cache, env->val_cache); + } + else{ + // Y := X XOR M_1 + // X := AES-128(K,Y) + ns_aes_xor_128_swap(env->val_cache, iv, m_i, AES_BLOCK_SIZE); + + // Start AES execution + ns_aes_start(&(env->aes_env), env->key_cache, env->val_cache); + } +} + +bool aes_cbc_continue(struct aes_cbc_env* env, uint8_t* aes_res) +{ + bool finished = false; + // To optimize the AES-CBC algorithm, SW is implemented as follow: + // + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + // + Step 1. n := ceil(len/block_size); (already done in init) + + // + X := iv; + + // + + + // + Step 2. + + // + Y := X XOR M_0; + + // + X := AES-128(K,Y); + + // + + + // + Step 3. + + // + for i = 1 , i < n , i++ do + + // + begin + + // + Y := X XOR M_i; + + // + X := AES-128(K,Y); + + // + O := O + X; + + // + end + + // + + + // + + + // + Step 4. return O; + + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + // O := O + X; + uint8_t *o_i = &(env->output[((env->cur_block) * AES_BLOCK_SIZE)]); + if(env->aes_env.src_info == DECRYPT_SRC_MARK) + { + ns_aes_xor_128_msb(o_i, env->iv, aes_res, AES_BLOCK_SIZE); + env->iv = &(env->message[((env->cur_block) * AES_BLOCK_SIZE)]); + } + else{ + ns_ase_swap_array((void*)o_i, aes_res, AES_BLOCK_SIZE); + } + + env->cur_block++; + // Step 3: handle Blocks M_2 ==> M_(n) + if(env->cur_block < env->num_blocks) + { + const uint8_t *m_i = &(env->message[((env->cur_block) * AES_BLOCK_SIZE)]); + + if(env->aes_env.src_info == DECRYPT_SRC_MARK) + { + ns_ase_swap_array(env->val_cache,m_i,AES_BLOCK_SIZE); //swap array + } + else{ + // Y := X XOR M_i + ns_aes_xor_128_swap(env->val_cache, o_i, m_i, AES_BLOCK_SIZE); + } + // X := AES-128(K,Y) + ns_aes_start(&(env->aes_env), env->key_cache, env->val_cache); + } + else + { + // Step 4 Return result + // mark AES-CBC over + finished = true; + } + + return finished; +} + +#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT) + +/// @} AES_CBC diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/aes_ccm.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/aes_ccm.c new file mode 100644 index 0000000..1ef5525 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/aes_ccm.c @@ -0,0 +1,486 @@ +/** + **************************************************************************************** + * * + * @file aes_ccm.c + * + * @brief Definition file for AES CCM crypto module functions + * + * Copyright (C) RivieraWaves 2017-2018 + * + * + * Algorithm described in RFC 3610 + * + **************************************************************************************** + */ + +/** + **************************************************************************************** + * @addtogroup AES + * @{ + **************************************************************************************** + */ + +/* + * INCLUDE FILES + **************************************************************************************** + */ + +#include "rwip_config.h" + +#include "arch.h" // For architecture platform defines +#include "aes_int.h" // AES internals +#include // for memcpy function +#include "co_utils.h" // for Bit field access +#include "co_endian.h"// For endianess requiements + +/* + * DEFINES + **************************************************************************************** + */ +/// Size of supported Nonce size +#define AES_CCM_NONCE_SIZE (13) + +/// Bit Field used to know where we are in AES-CCM execution +/// 7 6 5 4 3 2 1 0 +/// +-----+-----+-----+-----+-----+-----+-----+-----+ +/// | RFU |BLK_0|DATA |AUTH |M_GEN|CIPH | +/// +-----+-----+-----+-----+-----+-----+-----+-----+ +/// +enum aes_ccm_state_field +{ + /// True if ciphering, False if deciphering data. + AES_CCM_CIPHER_POS = 0, + AES_CCM_CIPHER_BIT = (1<<0), + /// True if AES execution is for MAC generation or Encryption + AES_CCM_MAC_GEN_POS = 1, + AES_CCM_MAC_GEN_BIT = (1<<1), + /// True if Authenticated optional data is under process + AES_CCM_AUTH_POS = 2, + AES_CCM_AUTH_BIT = (1<<2), + /// True if data is under process + AES_CCM_DATA_POS = 3, + AES_CCM_DATA_BIT = (1<<3), + /// True if execute B_0 or A_0 block + AES_CCM_BLOCK_0_POS = 4, + AES_CCM_BLOCK_0_BIT = (1<<4), +}; + +/// Bit Field used to know where we are in AES-CCM execution +/// 7 6 5 4 3 2 1 0 +/// +-----+-----+-----+-----+-----+-----+-----+-----+ +/// |RSVD |Adata| M' | L' | +/// +-----+-----+-----+-----+-----+-----+-----+-----+ +/// +enum aes_ccm_b_0_flag +{ + /// bit[7] - RSVD + AES_CCM_B_0_RSVD_POS = 7, + AES_CCM_B_0_RSVD_BIT = (1<<7), + /// bit[6] - Adata + AES_CCM_B_0_ADATA_POS = 6, + AES_CCM_B_0_ADATA_BIT = (1<<6), + /// bit[5:3] - M' + AES_CCM_B_0_M_PRIME_LSB = 3, + AES_CCM_B_0_M_PRIME_MASK = 0x38, + /// bit[2:0] - L' + AES_CCM_B_0_L_PRIME_LSB = 0, + AES_CCM_B_0_L_PRIME_MASK = 0x07, +}; + + +/* + * TYPES DEFINITION + ***************************************************************************************** + */ + +/// Structure definition of the AES CCM algorithm +struct aes_ccm_env +{ + /// AES Environment structure + struct aes_func_env aes_env; + /// Function to call at end of AES-CCM algorithm + aes_ccm_func_result_cb cb_result; + /// Encryption key + const uint8_t* key; + /// Additional authenticated data + const uint8_t* add_auth_data; + /// Pointer to the input message to be cipher/decipher + const uint8_t* in_message; + /// Pointer to the output message ==> will contain cipher text or data + uint8_t* out_message; + + /// Length of the message + uint16_t message_len; + /// Block Cursor of process data + uint8_t cursor; + + /// Nonce information (copied in [2:14] used to ease creation of B_0 and A_i) + uint8_t nonce[AES_BLOCK_SIZE]; + /// MAC Result of the CBC-MAC computation + uint8_t mac[AES_BLOCK_SIZE]; + + /// Additional authenticated data length + uint8_t add_auth_data_len; + /// MIC size + uint8_t mic_len; + /// State of AES-CCM execution bit field (@see enum aes_ccm_state_field) + uint8_t state; +}; + +/* + * GLOBAL VARIABLE DEFINITION + ***************************************************************************************** + */ + + +/* + * MODULE INTERNAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + + +/* + * LOCAL FUNCTION DEFINITIONS + **************************************************************************************** + */ + +/** + * @brief Perform a XOR of two numbers (output and first parameters are LSB). + * + * @param[out] result Output number: result = a ^ b => LSB (128 bits block) + * @param[in] a first operand LSB (128 bits block) + * @param[in] b second operand MSB + * @param[in] size number of bytes to XOR + * @param[in] offset Position offset in the payload + */ +__STATIC void aes_ccm_xor_128_lsb(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size, uint8_t offset) +{ + int8_t i; + offset = AES_BLOCK_SIZE - offset - 1; + + for(i = 0; i < size ; i++) + { + result[offset - i] = a[offset - i] ^ b[i]; + } +} + +/** + * @brief Perform a XOR of two numbers (output and first parameters are MSB). + * + * @param[out] result Output number: result = a ^ b => MSB (variable size block) + * @param[in] a first operand MSB (variable size block) + * @param[in] b second operand LSB (128 bits block) + * @param[in] size number of bytes to XOR + */ +__STATIC void aes_ccm_xor_128_msb(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size) +{ + int8_t i; + + for(i = 0; i < size ; i++) + { + result[i] = a[i] ^ b[AES_BLOCK_SIZE - i - 1]; + } +} + +/** + **************************************************************************************** + * @brief Continue AES-CCM execution according to current AES-CCM execution state + * This function always request a new AES computation to be performed + * + * @param[in] env Pointer to the AES CCM environment variable + **************************************************************************************** + */ +__STATIC void aes_ccm_continue(struct aes_ccm_env* env) +{ + uint8_t* aes_val_ptr = NULL; + + // CBC-MAC generation step + if(GETB(env->state, AES_CCM_MAC_GEN)) + { + // Create B_0 block - to compute X_1 block + if(GETB(env->state, AES_CCM_BLOCK_0)) + { + // Set B_0 Flag field + SETB(env->nonce[15], AES_CCM_B_0_RSVD, 0); + SETB(env->nonce[15], AES_CCM_B_0_ADATA, (env->add_auth_data_len > 0)); + SETF(env->nonce[15], AES_CCM_B_0_M_PRIME, (env->mic_len -2) / 2); + SETF(env->nonce[15], AES_CCM_B_0_L_PRIME, 1); // Length field is 2 bytes (L' = L - 1) + // Set B_0 Message Length field + co_write16p(&(env->nonce[0]), env->message_len); + + aes_val_ptr = env->nonce; + } + // Create B_i blocks - to compute X_i blocks + else + { + aes_val_ptr = env->mac; + + // B_i blocks generated with authenticated data + if(GETB(env->state, AES_CCM_AUTH)) + { + uint16_t offset = (AES_BLOCK_SIZE * env->cursor); + uint8_t block_size = AES_BLOCK_SIZE; + uint8_t mac_offset = 2; + + // if computed offset is > 0, take in account the first two bytes used for auth data length + if(offset > 0) + { + offset -= 2; + mac_offset = 0; + } + else + { + block_size -= 2; + } + + // Two first bytes contains authenticated data + if(offset == 0) + { + uint16_t auth_len = co_htons(env->add_auth_data_len); + + // B_1 = X_1 ^ (len || a[0:14]) + aes_ccm_xor_128_lsb(env->mac, env->mac, (uint8_t*) &(auth_len), 2, 0); + } + + // Size of Auth data block to XOR + if(block_size > (env->add_auth_data_len - offset)) + { + block_size = (env->add_auth_data_len - offset); + } + + // B_i = X_i ^ a + aes_ccm_xor_128_lsb(env->mac, env->mac, env->add_auth_data + offset, block_size, mac_offset); + } + // B_i blocks generated with plain data + else // if (GETB(env->state, AES_CCM_DATA)) + { + // nothing to do + } + } + } + else + { + uint8_t counter = GETB(env->state, AES_CCM_BLOCK_0) ? 0 : (1 + env->cursor); + + // Set A_i Flag field + env->nonce[15] = 1; // Flag = L' ==> Length field is 2 bytes (L' = L - 1) + // Set Counter value + co_write16p(&(env->nonce[0]), counter); + + aes_val_ptr = env->nonce; + } + + // execute next AES operation + aes_start(&(env->aes_env), env->key, aes_val_ptr); +} + +/** + **************************************************************************************** + * @brief Process result of AES block to continue AES-CCM execution + * + * @param[in] env Pointer to the AES CCM environment variable + * @param[in] aes_res Result of AES execution + * + * @return True if AES-CCM is over, False else + **************************************************************************************** + */ +__STATIC bool aes_ccm_process_e(struct aes_ccm_env* env, uint8_t* aes_res) +{ + bool finished = false; + uint8_t i; + + // CBC-MAC generation step + if(GETB(env->state, AES_CCM_MAC_GEN)) + { + // put result in MAC block + memcpy(env->mac, aes_res, AES_BLOCK_SIZE); + + // Handle X_1 block + if(GETB(env->state, AES_CCM_BLOCK_0)) + { + // B_0 processed + SETB(env->state, AES_CCM_BLOCK_0, false); + + // check if additional auth data present + if(env->add_auth_data_len > 0) + { + // if yes process it for MAC generation + SETB(env->state, AES_CCM_AUTH, true); + env->cursor = 0; + } + // process only the data + else + { + // start data processing + SETB(env->state, AES_CCM_MAC_GEN, false); + SETB(env->state, AES_CCM_AUTH, false); + SETB(env->state, AES_CCM_DATA, true); + env->cursor = 0; + } + } + else if(GETB(env->state, AES_CCM_AUTH)) + { + env->cursor++; + + // check if there is additional data to process + if(env->add_auth_data_len < ((env->cursor * AES_BLOCK_SIZE) -2)) + { + // start data processing + SETB(env->state, AES_CCM_MAC_GEN, false); + SETB(env->state, AES_CCM_AUTH, false); + SETB(env->state, AES_CCM_DATA, true); + env->cursor = 0; + } + } + // Handle X_i Data block + else // if (GETB(env->state, AES_CCM_DATA)) + { + uint16_t offset = (AES_BLOCK_SIZE * env->cursor); + + // next step is handled by Encrypt algorithm + SETB(env->state, AES_CCM_MAC_GEN, false); + + // Check if all the data has been processed + if(offset >= env->message_len) + { + // compute the A_0 block for MIC + SETB(env->state, AES_CCM_DATA, false); + SETB(env->state, AES_CCM_BLOCK_0, true); + } + } + } + else + { + // Handle S_0 block - MIC + if(GETB(env->state, AES_CCM_BLOCK_0)) + { + bool mic_error = false; + + // Cipher: Generate the MIC and return + if(GETB(env->state, AES_CCM_CIPHER)) + { + uint8_t* out_mic = env->out_message + env->message_len; + + // MIC = first_M_bytes (T ^ S_0) + for(i = 0 ; i < env->mic_len ; i++) + { + out_mic[i] = (env->mac[AES_BLOCK_SIZE-i-1] ^ aes_res[AES_BLOCK_SIZE-i-1]); + } + } + // Decipher: Retrieve MIC and Check if value is ok + else + { + const uint8_t* in_mic = env->in_message + env->message_len; + + // MAC= first_M_bytes (T ^ S_0) + for(i = 0 ; i < env->mic_len ; i++) + { + if(env->mac[AES_BLOCK_SIZE-i-1] != (in_mic[i] ^ aes_res[AES_BLOCK_SIZE-i-1])) + { + mic_error = true; + break; + } + } + } + + if(env->cb_result != NULL) + { + env->cb_result(mic_error, env->aes_env.src_info); + } + + finished = true; + } + // Handle S_i Data block + else // if (GETB(env->state, AES_CCM_DATA)) + { + uint16_t offset = (AES_BLOCK_SIZE * env->cursor); + uint8_t len = (offset + AES_BLOCK_SIZE > env->message_len) + ? (env->message_len - offset) + : AES_BLOCK_SIZE; + const uint8_t* in_msg = env->in_message + offset; + uint8_t* out_msg = env->out_message + offset; + + // execute two XOR to prepare MAC algorithm and execute Encryption/Decryption algorithm + // + // +--------------------+---------------------+ + // | CIPHER | DECIPHER | + // +--------------------+---------------------+ + // | MAC = IN ^ MAC | OUT = IN ^ AES_RES | + // +--------------------+---------------------+ + // | OUT = IN ^ AES_RES | MAC = OUT ^ MAC | + // +--------------------+---------------------+ + // + if(GETB(env->state, AES_CCM_CIPHER)) + { + + // MAC = IN ^ MAC + aes_ccm_xor_128_lsb(env->mac, env->mac, in_msg, len, 0); + + // OUT = IN ^ AES_RES + aes_ccm_xor_128_msb(out_msg, in_msg, aes_res, len); + } + else + { + // OUT = IN ^ AES_RES + aes_ccm_xor_128_msb(out_msg, in_msg, aes_res, len); + // MAC = OUT ^ MAC + aes_ccm_xor_128_lsb(env->mac, env->mac, out_msg, len, 0); + } + + // next step is handled by MAC generation algorithm + SETB(env->state, AES_CCM_MAC_GEN, true); + env->cursor++; + } + } + + // check if AES-CCM algorithm must be continued + if(!finished) + { + aes_ccm_continue(env); + } + + return finished; +} + + +/* + * EXPORTED FUNCTION DEFINITIONS + **************************************************************************************** + */ +void aes_ccm(const uint8_t* key, const uint8_t* nonce, const uint8_t* in_message, + uint8_t* out_message, uint16_t message_len, uint8_t mic_len, bool cipher, + const uint8_t* add_auth_data, uint8_t add_auth_data_len, aes_ccm_func_result_cb res_cb, uint32_t src_info) +{ + struct aes_ccm_env* env; + int i; + // Allocate AES CCM environent memory + env = (struct aes_ccm_env*) aes_alloc(sizeof(struct aes_ccm_env), (aes_func_continue_cb)aes_ccm_process_e, NULL, src_info); + + // copy information needed for AES-CCM execution + env->cb_result = res_cb; + env->key = key; + env->add_auth_data = add_auth_data; + env->in_message = in_message; + env->out_message = out_message; + env->add_auth_data_len = add_auth_data_len; + env->message_len = message_len; + env->mic_len = mic_len; + + // Put NONCE in LSB format + for(i = 0 ; i < AES_CCM_NONCE_SIZE ; i++) + { + env->nonce[2+i] = nonce[AES_CCM_NONCE_SIZE-i-1]; + } + + // Initialize execution of the AES-CCM function + SETB(env->state, AES_CCM_CIPHER, cipher); + SETB(env->state, AES_CCM_MAC_GEN, true); + SETB(env->state, AES_CCM_AUTH, false); + SETB(env->state, AES_CCM_DATA, false); + SETB(env->state, AES_CCM_BLOCK_0, true); + + // Start first execution step + aes_ccm_continue(env); +} + +/// @} AES_CCM diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/ns_aes.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/ns_aes.c new file mode 100644 index 0000000..0c74743 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/ns_aes.c @@ -0,0 +1,337 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_aes.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "ns_aes.h" +#include "ns_log.h" +/* Private typedef -----------------------------------------------------------*/ +/// Structure definition used for AES with a cache +struct aes_cache_env +{ + /// AES Environment structure + struct aes_func_env aes_env; + /// Cached Key + uint8_t key_cache[KEY_LEN]; + /// Cached value + uint8_t val_cache[KEY_LEN]; +}; +/// AES environment structure +struct aes_env_tag +{ + /// List of AES function to execute + struct co_list queue; + /// AES under execution + bool aes_ongoing; +}; +extern struct aes_env_tag aes_env; +/* Private define ------------------------------------------------------------*/ + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +//volatile bool m_aes_ready = false; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief conver data betweem big endian and little endian + * + * @param[out] p_out Output number: p_out = (MSB <=> LSB) + * @param[in] p_in input data to swap + * @param[in] size number of bytes to swap + */ +void ns_ase_swap_array(uint8_t * p_out, uint8_t const * p_in, uint8_t size) +{ + uint8_t const * p_first = p_in; + uint8_t * p_last = p_out + size - 1; + while (p_last >= p_out) + { + *p_last = *p_first; + p_first++; + p_last--; + } +} + +/** + * @brief Perform a XOR of two numbers (output parameters are LSB). + * + * @param[out] result Output number: result = ((a ^ b) => LSB) + * @param[in] a first operand MSB + * @param[in] b second operand MSB + * @param[in] size number of bytes to XOR + */ +void ns_aes_xor_128_swap(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size) +{ + uint8_t i; + uint8_t offset = size - 1; + + for(i = 0; i < size ; i++) + { + result[offset - i] = a[i] ^ b[i]; + } +} +/** + * @brief Perform a XOR of two numbers (output and first parameters are LSB). + * + * @param[out] result Output number: result = a ^ b => LSB (128 bits block) + * @param[in] a first operand LSB (128 bits block) + * @param[in] b second operand MSB + * @param[in] size number of bytes to XOR + * @param[in] offset Position offset in the payload + */ +void ns_aes_xor_128_lsb(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size, uint8_t offset) +{ + uint8_t i; + offset = AES_BLOCK_SIZE - offset - 1; + + for(i = 0; i < size ; i++) + { + result[offset - i] = a[offset - i] ^ b[i]; + } +} + + +/** + * @brief Perform a XOR of two numbers (output and first parameters are MSB). + * + * @param[out] result Output number: result = a ^ b => MSB (variable size block) + * @param[in] a first operand MSB (variable size block) + * @param[in] b second operand LSB (128 bits block) + * @param[in] size number of bytes to XOR + */ +void ns_aes_xor_128_msb(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size) +{ + uint8_t i; + + for(i = 0; i < size ; i++) + { + result[i] = a[i] ^ b[AES_BLOCK_SIZE - i - 1]; + } +} + +#if AES_DECRYPT_ENABLE +/** + * @brief AES result handler + * @param + * @return + * @note Note + */ +void ns_aes_result_handler(uint8_t status, uint8_t* result) +{ + // extract first element of the list that contains + struct aes_func_env* env = (struct aes_func_env*) co_list_pop_front(&(aes_env.queue)); + struct aes_func_env* env_next = (struct aes_func_env*) co_list_pick(&(aes_env.queue)); + aes_env.aes_ongoing = false; + + // Reset mode to encrypt + ip_aescntl_aes_mode_setf(0); + // Prepare new AES Run if requested + if(env_next != NULL) + { + aes_env.aes_ongoing = true; + if(env_next->src_info == DECRYPT_SRC_MARK) + { + ip_aescntl_aes_mode_setf(1); + } + rwip_aes_encrypt(env_next->key, env_next->val); + } + + // Check that AES result has a requester + if(env) + { + bool finished = true; + + // check status of current result + if(status == CO_ERROR_NO_ERROR) + { + // continue function computation + if(env->aes_continue_cb != NULL) + { + finished = env->aes_continue_cb(env, result); + } + } + + // if function execution is over + if(finished) + { + // Inform requester of end of AES based algorithm + if(env->aes_res_cb != NULL) + { + env->aes_res_cb(status, result, env->src_info); + } + + // remove function environment + ke_free(env); + } + } +} +/** + * + * @brief Handles crypto event (to provide results out of interrupt context + * + */ +__STATIC void ns_rwip_crypt_evt_handler(void) +{ + uint8_t aes_result[KEY_LEN]; + + // Clear event + ke_event_clear(KE_EVENT_AES_END); + + // Load AES result + em_rd(aes_result, EM_ENC_OUT_OFFSET, KEY_LEN); + + // inform AES result handler + ns_aes_result_handler(CO_ERROR_NO_ERROR, aes_result); +} + + +bool ns_aes_continue_cb(struct aes_cache_env* aes_env, uint8_t* aes_res) +{ + uint8_t res_cache[KEY_LEN]; + ns_ase_swap_array(res_cache, aes_res, KEY_LEN); + aes_env->aes_env.aes_res_cb(true,res_cache,aes_env->aes_env.src_info); + aes_env->aes_env.aes_res_cb = NULL; //result has been return, cancel res_cb + return true; +} + + +/** + * @brief aes deciphering + * @param + * @return + * @note Note + */ +void ns_aes_deciphering(uint8_t *key, uint8_t *val, aes_func_result_cb res_cb) +{ + // allocate environment for the AES execution + struct aes_cache_env* env = (struct aes_cache_env*) aes_alloc(sizeof(struct aes_cache_env), + (aes_func_continue_cb)ns_aes_continue_cb, res_cb, DECRYPT_SRC_MARK); + + // Copy keys and val + ns_ase_swap_array(env->key_cache, key, KEY_LEN); + ns_ase_swap_array(env->val_cache, val, KEY_LEN); + + // Start AES execution + ns_aes_start(&(env->aes_env), env->key_cache, env->val_cache); +} + +#endif +/** + * @brief aes ciphering + * @param + * @return + * @note Note + */ +void ns_aes_ciphering(uint8_t *key, uint8_t *val, aes_func_result_cb res_cb) +{ + // allocate environment for the AES execution + struct aes_cache_env* env = (struct aes_cache_env*) aes_alloc(sizeof(struct aes_cache_env), + (aes_func_continue_cb)ns_aes_continue_cb, res_cb, 0); + + // Copy keys and val + ns_ase_swap_array(env->key_cache, key, KEY_LEN); + ns_ase_swap_array(env->val_cache, val, KEY_LEN); + + // Start AES execution + ns_aes_start(&(env->aes_env), env->key_cache, env->val_cache); +} + + +/** + * @brief AES Cypher request function. + * + * This will queue AES request in the AES execution queue + * When the AES result is received, the AES continue callback is executed. + * + * If AES continue function returns that AES execution is over, a message will be send to destination task + * with latest AES result. + * + * @param[in] env AES environment + * @param[in] key Key used for cyphering + * @param[in] val Value to cypher + */ +void ns_aes_start(struct aes_func_env* env, const uint8_t* key, const uint8_t *val) +{ + // put function environment at end of list. + co_list_push_back(&(aes_env.queue), &(env->hdr)); + + // store parameter information + env->key = key; + env->val = val; + + // AES encryption can be immediately performed + if(!aes_env.aes_ongoing) + { + if(env->src_info == DECRYPT_SRC_MARK) + { + // decrypt mode + ip_aescntl_aes_mode_setf(1); + //config AES event callback + ke_event_callback_set(KE_EVENT_AES_END, &ns_rwip_crypt_evt_handler); + } + aes_env.aes_ongoing = true; + rwip_aes_encrypt(env->key, env->val); + } +} + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/ns_aes.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/ns_aes.h new file mode 100644 index 0000000..292b72b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/aes/ns_aes.h @@ -0,0 +1,135 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_aes.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ +#ifndef __NS_AES_H__ +#define __NS_AES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes -----------------------------------------------------------------*/ +#include "global_func.h" +#include "aes.h" +#include "aes_int.h" +/* Public typedef -----------------------------------------------------------*/ + +/* Public define ------------------------------------------------------------*/ +#ifndef AES_DECRYPT_ENABLE +#define AES_DECRYPT_ENABLE 0 +#endif +#define DECRYPT_SRC_MARK 0xffffffff +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +void ns_ase_swap_array(uint8_t * p_out, uint8_t const * p_in, uint8_t size); +void ns_aes_xor_128_swap(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size); +void ns_aes_xor_128_lsb(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size, uint8_t offset); +void ns_aes_xor_128_msb(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size); + +void ns_aes_start(struct aes_func_env* env, const uint8_t* key, const uint8_t *val); +#if AES_DECRYPT_ENABLE +void ns_aes_deciphering(uint8_t *key, uint8_t *val, aes_func_result_cb res_cb); +#endif +void ns_aes_ciphering(uint8_t *key, uint8_t *val, aes_func_result_cb res_cb); + + + +/** + * @brief Start the AES CBC crypto function. Allocate memory for the CBC and start processing it + * Execute result callback at end of function execution + * + * @param[in] key Pointer to the Key to be used + * @param[in] iv 16 Bytes iv to use for cipher/decipher + * @param[in] in_message Input message for AES-CBC exectuion + * @param[out] out_message Output message that will contain cipher or decipher data + * @param[in] message_len Length of Input/Output message without mic + * @param[in] cipher True to encrypt message, False to decrypt it. + * @param[in] res_cb Function that will handle the AES CCM result + */ +void ns_aes_cbc(const uint8_t* key, const uint8_t* iv, const uint8_t* in_message, uint8_t* out_message, + bool cipher, uint16_t message_len, aes_func_result_cb res_cb); + + +/** + * @brief Start the AES CCM crypto function. Allocate memory for the CCM and start processing it + * Execute result callback at end of function execution + * + * @param[in] key Pointer to the Key to be used (LSB mode!!!!) + * @param[in] nonce 13 Bytes Nonce to use for cipher/decipher (MSB) + * @param[in] in_message Input message for AES-CCM exectuion (MSB) + * @param[out] out_message Output message that will contain cipher+mic or decipher data + * @param[in] message_len Length of Input/Output message without mic + * @param[in] mic_len Length of the mic to use (2, 4, 6, 8, 10, 12, 14, 16 valid) + * @param[in] cipher True to encrypt message, False to decrypt it. + * @param[in] add_auth_data Additional Authentication data used for computation of MIC (MSB) + * @param[in] add_auth_data_len Length of Additional Authentication data + * @param[in] res_cb Function that will handle the AES CCM result + * @param[in] src_info Information used retrieve requester + */ +void aes_ccm(const uint8_t* key, const uint8_t* nonce, const uint8_t* in_message, + uint8_t* out_message, uint16_t message_len, uint8_t mic_len, bool cipher, + const uint8_t* add_auth_data, uint8_t add_auth_data_len, aes_ccm_func_result_cb res_cb, uint32_t src_info); +#define ns_aes_ccm aes_ccm + +#endif /* __NS_AES_H__ */ +/** + * @} + */ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble.c new file mode 100644 index 0000000..2194201 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble.c @@ -0,0 +1,1745 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + +/** + * @file ns_ble.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_PRESENT) +#include "ns_sleep.h" +#include "ns_ble.h" +#include "ns_ble_task.h" +#if (BLE_APP_SEC) +#include "ns_sec.h" // Application security Definition +#endif // (BLE_APP_SEC) +#if (NS_TIMER_ENABLE) +#include "ns_timer.h" +#endif //NS_TIMER_ENABLE + + +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private typedef -----------------------------------------------------------*/ + +/* Private variables ---------------------------------------------------------*/ +static __align(4) unsigned char rwip_fifo_isr_codeArray[] ={ +0x03,0xb4,0x01,0x48,0x01,0x90,0x01,0xbd,0xed,0xc3,0x02,0x00,0x10,0xb5,0x07,0x4c, +0xe0,0x69,0x00,0x04,0x08,0xd5,0xff,0xf7,0xf3,0xff,0x05,0x48,0x00,0x78,0x00,0x28, +0x02,0xd1,0x01,0x20,0xc0,0x03,0x20,0x62,0x10,0xbd,0x00,0x00,0x00,0x80,0x02,0x40, +0xc6,0x00,0x00,0x20}; + +/// List of functions used to create the database +struct ns_ble_add_prf_evn_t add_prf_evn; +struct ns_ble_prf_evn_t ble_prf_evn; + +/// Application Environment Structure +struct app_env_tag app_env; +struct ns_gap_params_t gap_env; +struct ns_adv_params_t adv_env; +struct ns_scan_params_t scan_env; +/* Private function prototypes -----------------------------------------------*/ +/// Application Task Descriptor +extern const struct ke_task_desc TASK_DESC_APP_M; +/* Private functions ---------------------------------------------------------*/ + + +IRQ_HANNDLE_FUN user_HardFault_Handler = NULL; +IRQ_HANNDLE_FUN user_EXTI4_12_IRQHandler = NULL; +#ifdef SLEEP_LP_TIMER_ENABLE +IRQ_HANNDLE_FUN lpt_wakeup_hdl = NULL; +IRQ_HANNDLE_FUN user_RTC_IRQHandler = NULL; +/** + * @brief RTC IRQ Handler + * @param + * @return void + * @note + */ +void ns_RTC_IRQHandler(void) +{ + if(((RTC->INITSTS & RTC_INITSTS_WTF) != RESET) || + ((EXTI->PEND & EXTI_LINE9) != RESET)) //EXTI_GetITStatus + { + RTC->INITSTS &=~RTC_INITSTS_WTF; + EXTI->PEND = EXTI_LINE9; //EXTI_ClrITPendBit + if(lpt_wakeup_hdl != NULL) + { + lpt_wakeup_hdl(); + } + } + if(user_RTC_IRQHandler != NULL) + { + user_RTC_IRQHandler(); + } +} + +#endif +void ns_HardFault_Handler(void) +{ + uint32_t *stack_top = (uint32_t *)__get_MSP(); + NS_LOG_INIT(); + NS_LOG_ERROR("**************HardFault ERROR:REG INFO**************.\r\n"); \ + NS_LOG_ERROR("msp = 0x%08x.\r\n", (uint32_t)stack_top); \ + NS_LOG_ERROR("r0 = 0x%08x, \tr1 = 0x%08x.\r\n", stack_top[0], stack_top[1]); \ + NS_LOG_ERROR("r2 = 0x%08x, \tr3 = 0x%08x.\r\n", stack_top[2], stack_top[3]); \ + NS_LOG_ERROR("r12 = 0x%08x, \tlr = 0x%08x.\r\n", stack_top[4], stack_top[5]); \ + NS_LOG_ERROR("pc = 0x%08x, \txpsr = 0x%08x.\r\n", stack_top[6], stack_top[7]); + + + if(user_HardFault_Handler ) + { + user_HardFault_Handler();//call user HardFault_Handler + } + + NS_LOG_ERROR("%s\r\n",__func__); + + NVIC_SystemReset(); + while(1) + {} +} + +void ns_EXTI4_12_IRQHandler(void) +{ + /* EXTI line 11 for BLE Stack */ + if (RESET != EXTI_GetITStatus(EXTI_LINE11)) + { + EXTI_ClrITPendBit(EXTI_LINE11); + g_sleep_status_flag = 2; //BB_WAKEUP_OSEN + } + /* NRST Wakeup Interrupt through EXTI line 12 */ + if (RESET != EXTI_GetITStatus(EXTI_LINE12)) + { + EXTI_ClrITPendBit(EXTI_LINE12); + NS_LOG_INIT(); + NS_LOG_INFO("NRST->NVIC_SystemReset\r\n"); + NVIC_SystemReset(); + } + + if(user_EXTI4_12_IRQHandler) + { + user_EXTI4_12_IRQHandler();//call user EXTI4_12_IRQHandler + } +} + +static void ns_NRST_config(void) +{ + EXTI_InitType EXTI_InitStructure = {0}; + /* Enable the NRST Wakeup Interrupt through EXTI line 12 */ + EXTI_InitStructure.EXTI_Line = EXTI_LINE12; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); +} + + +static void ns_ble_stack_vtor_init(void) +{ + extern uint32_t __Vectors; + /*note: SPI1_IRQn and IRC_IRQn Interrupt not availed. */ + //init vtor address + volatile uint32_t* p_IrqFun = (void*)0x200009c0; + uint32_t* user_vtor = (&__Vectors); + + //system Interrupt + REG32(0x200000ec) = (uint32_t)user_vtor[16+NonMaskableInt_IRQn]; + REG32(0x200000f0) = (uint32_t)ns_HardFault_Handler; + REG32(0x200000e8) = (uint32_t)user_vtor[16+SVCall_IRQn]; + REG32(0x200000f4) = (uint32_t)user_vtor[16+SysTick_IRQn]; + REG32(0x200000f8) = (uint32_t)user_vtor[16+PendSV_IRQn]; + //user Interrupt + memcpy((void*)p_IrqFun,&user_vtor[16],124); + //clear ble Interrupt + p_IrqFun[BLE_SW_IRQn] = 0; + p_IrqFun[BLE_HSLOT_IRQn] = 0; + p_IrqFun[BLE_FINETGT_IRQn] = 0; + p_IrqFun[BLE_FIFO_IRQn] = (uint32_t)(&rwip_fifo_isr_codeArray[0x0d]); + p_IrqFun[BLE_ERROR_IRQn] = 0; + p_IrqFun[BLE_CRYPT_IRQn] = 0; + p_IrqFun[BLE_TIMESTAMP_TGT1_IRQn] = 0; + p_IrqFun[BLE_TIMESTAMP_TGT2_IRQn] = 0; + p_IrqFun[BLE_SLP_IRQn] = (uint32_t)rwip_slp_isr; + + p_IrqFun[EXTI4_12_IRQn] = (uint32_t)ns_EXTI4_12_IRQHandler; + + + //Register updated ble fifo irq function + g_sch_prog_fifo_iar_branch = false; + rwip_prog_delay = 3; + //enable Interrupt of remaped in flash + NVIC_EnableIRQ(BLE_FIFO_IRQn); + NVIC_EnableIRQ(BLE_SLP_IRQn); + NVIC_EnableIRQ(EXTI4_12_IRQn); + + //register HardFault Interrupt if user define it + uint32_t temp_addr =(*(uint32_t *)&user_vtor[3]) - 1; + uint16_t temp_cmd = *((uint16_t*)temp_addr); + if( temp_cmd != 0xe7fe) // ASM cmd B + { + user_HardFault_Handler = (IRQ_HANNDLE_FUN)(*(uint32_t *)&user_vtor[3]);; + } + //register EXTI4_12 Interrupt if user define it + temp_addr =(*(uint32_t *)&user_vtor[24]) - 1; + temp_cmd = *((uint16_t*)temp_addr); + if( temp_cmd != 0xe7fe) // ASM cmd B + { + user_EXTI4_12_IRQHandler = (IRQ_HANNDLE_FUN)(*(uint32_t *)&user_vtor[24]); + } + #ifdef SLEEP_LP_TIMER_ENABLE + p_IrqFun[RTC_IRQn] = (uint32_t)ns_RTC_IRQHandler; + //register RTC Interrupt if user define it + temp_addr =(*(uint32_t *)&user_vtor[18]) - 1; //16+RTC_IRQn + temp_cmd = *((uint16_t*)temp_addr); + if( temp_cmd != 0xe7fe) // ASM cmd B + { + user_RTC_IRQHandler = (IRQ_HANNDLE_FUN)(*(uint32_t *)&user_vtor[18]); + } + #endif + // enable NRST pin Interrupt + ns_NRST_config(); + +} + + + + +static void app_create_advertising(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + if (app_env.adv_state == APP_ADV_STATE_IDLE ) + { + // Prepare the GAPM_ACTIVITY_CREATE_CMD message + struct gapm_activity_create_adv_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_CREATE_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_create_adv_cmd); + + // Set operation code + p_cmd->operation = GAPM_CREATE_ADV_ACTIVITY; + + // Fill the allocated kernel message + p_cmd->own_addr_type = gap_env.mac_addr_type; + p_cmd->adv_param.type = GAPM_ADV_TYPE_LEGACY; + p_cmd->adv_param.prop = GAPM_ADV_PROP_UNDIR_CONN_MASK; + p_cmd->adv_param.filter_pol = ADV_ALLOW_SCAN_ANY_CON_ANY; + p_cmd->adv_param.disc_mode = GAPM_ADV_MODE_GEN_DISC; + p_cmd->adv_param.prim_cfg.chnl_map = ADV_ALL_CHNLS_EN; + p_cmd->adv_param.prim_cfg.phy = adv_env.adv_phy; + + if(adv_env.beacon_enable) + { + p_cmd->adv_param.prop = GAPM_ADV_PROP_NON_CONN_NON_SCAN_MASK; + p_cmd->adv_param.disc_mode = GAPM_ADV_MODE_BEACON; + }else + if(adv_env.ex_adv_enable) + { + if( adv_env.adv_phy == PHY_2MBPS_VALUE) + { + p_cmd->adv_param.prim_cfg.phy = PHY_1MBPS_VALUE; + } + p_cmd->adv_param.type = GAPM_ADV_TYPE_EXTENDED; + p_cmd->adv_param.prop = GAPM_EXT_ADV_PROP_UNDIR_CONN_MASK; + p_cmd->adv_param.second_cfg.phy = adv_env.adv_phy; + p_cmd->adv_param.second_cfg.adv_sid = 1; + p_cmd->adv_param.second_cfg.max_skip = 0; + } + + switch (app_env.adv_mode) + { + case APP_ADV_MODE_DIRECTED: + /* + * If the peripheral is already bonded with a central device, use the direct advertising + * procedure (BD Address of the peer device is stored in NVDS. + */ + #if(BLE_APP_SEC) + if (ns_sec_get_bond_status()) + { + p_cmd->adv_param.prop = GAPM_ADV_PROP_DIR_CONN_MASK; + p_cmd->adv_param.disc_mode = GAPM_ADV_MODE_NON_DISC; + p_cmd->adv_param.prim_cfg.adv_intv_min = adv_env.directed_adv.adv_intv; + p_cmd->adv_param.prim_cfg.adv_intv_max = adv_env.directed_adv.adv_intv; + //set addr for dir + ns_bond_last_bonded_peer_id(&p_cmd->adv_param.peer_addr); + } + else + #endif + { + app_env.adv_mode = APP_ADV_MODE_FAST; + p_cmd->adv_param.prim_cfg.adv_intv_min = adv_env.fast_adv.adv_intv; + p_cmd->adv_param.prim_cfg.adv_intv_max = adv_env.fast_adv.adv_intv; + } + + break; + case APP_ADV_MODE_FAST: + p_cmd->adv_param.prim_cfg.adv_intv_min = adv_env.fast_adv.adv_intv; + p_cmd->adv_param.prim_cfg.adv_intv_max = adv_env.fast_adv.adv_intv; + break; + case APP_ADV_MODE_SLOW: + p_cmd->adv_param.prim_cfg.adv_intv_min = adv_env.slow_adv.adv_intv; + p_cmd->adv_param.prim_cfg.adv_intv_max = adv_env.slow_adv.adv_intv; + + break; + default: + break; + } + // Keep the current operation + app_env.adv_state = APP_ADV_STATE_CREATING; + // And the next expected operation code for the command completed event + app_env.current_op = CURRENT_OP_CREATE_ADV; + // Send the message + ke_msg_send(p_cmd); + } +} + +static void app_delete_activity(void) +{ + // Prepare the GAPM_ACTIVITY_CREATE_CMD message + struct gapm_activity_delete_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_DELETE_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_delete_cmd); + NS_LOG_DEBUG("%s\r\n", __func__); + // Set operation code + p_cmd->operation = GAPM_DELETE_ACTIVITY; + p_cmd->actv_idx = app_env.adv_actv_idx; + + // Keep the current operation + // And the next expected operation code for the command completed event + app_env.current_op = CURRENT_OP_DELETE_ADV; + + app_env.adv_state = APP_ADV_STATE_IDLE; //reset state + //set next adv mode + if(ke_state_get(TASK_APP) == APP_CONNECTED) + { + //connected, stop adv + app_env.adv_mode = APP_ADV_MODE_STOP; + } + else + { //not connect yet, start next adv + switch (app_env.adv_mode) + { + case APP_ADV_MODE_ENABLE: + //restart adv + case APP_ADV_MODE_DIRECTED: + if(adv_env.fast_adv.enable) + { + app_env.adv_mode = APP_ADV_MODE_FAST; + break; + } + case APP_ADV_MODE_FAST: + if(adv_env.slow_adv.enable) + { + app_env.adv_mode = APP_ADV_MODE_SLOW; + break; + } + case APP_ADV_MODE_SLOW: + app_env.adv_mode = APP_ADV_MODE_STOP; + break; + default: + app_env.adv_mode = APP_ADV_MODE_STOP; + break; + } + } + // Send the message + ke_msg_send(p_cmd); +} + +static void app_start_advertising(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Prepare the GAPM_ACTIVITY_START_CMD message + struct gapm_activity_start_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_START_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_start_cmd); + + p_cmd->operation = GAPM_START_ACTIVITY; + p_cmd->actv_idx = app_env.adv_actv_idx; + + switch (app_env.adv_mode) + { + case APP_ADV_MODE_DIRECTED: + NS_LOG_DEBUG("APP_ADV_MODE_DIRECTED "); + p_cmd->u_param.adv_add_param.duration = SECS_TO_UNIT(adv_env.directed_adv.duration , SECS_UNIT_10MS); + break; + case APP_ADV_MODE_FAST: + NS_LOG_DEBUG("APP_ADV_MODE_FAST "); + p_cmd->u_param.adv_add_param.duration = SECS_TO_UNIT(adv_env.fast_adv.duration, SECS_UNIT_10MS); + break; + case APP_ADV_MODE_SLOW: + NS_LOG_DEBUG("APP_ADV_MODE_SLOW "); + p_cmd->u_param.adv_add_param.duration = SECS_TO_UNIT(adv_env.slow_adv.duration, SECS_UNIT_10MS); + break; + default: + p_cmd->u_param.adv_add_param.duration = 0; + break; + } + NS_LOG_DEBUG(", duration: %d x10 ms\r\n",p_cmd->u_param.adv_add_param.duration); + + p_cmd->u_param.adv_add_param.max_adv_evt = 0; + + llhwc_modem_setmode(adv_env.adv_phy); + // Keep the current operation + app_env.adv_state = APP_ADV_STATE_STARTING; + // And the next expected operation code for the command completed event + app_env.current_op = CURRENT_OP_START_ADV; + + // Send the message + ke_msg_send(p_cmd); +} + + +static void app_stop_advertising(void) +{ + // Prepare the GAPM_ACTIVITY_STOP_CMD message + struct gapm_activity_stop_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_STOP_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_stop_cmd); + NS_LOG_DEBUG("%s\r\n", __func__); + // Fill the allocated kernel message + p_cmd->operation = GAPM_STOP_ACTIVITY; + p_cmd->actv_idx = app_env.adv_actv_idx; + // Update advertising state + app_env.adv_state = APP_ADV_STATE_STOPPING; + // And the next expected operation code for the command completed event + app_env.current_op = CURRENT_OP_STOP_ADV; + // Send the message + ke_msg_send(p_cmd); +} + + + +static void app_set_adv_data(void) +{ + uint8_t data_len; + if(adv_env.ex_adv_enable) + { + data_len = adv_env.ex_adv_data_len; + } + else{ + data_len = adv_env.adv_data_len; + } + // Prepare the GAPM_SET_ADV_DATA_CMD message + struct gapm_set_adv_data_cmd *p_cmd = KE_MSG_ALLOC_DYN(GAPM_SET_ADV_DATA_CMD, + TASK_GAPM, TASK_APP, + gapm_set_adv_data_cmd, + data_len); + NS_LOG_DEBUG("%s\r\n", __func__); + // Fill the allocated kernel message + p_cmd->operation = GAPM_SET_ADV_DATA; + p_cmd->actv_idx = app_env.adv_actv_idx; + + p_cmd->length = 0; + + // GAP will use 3 bytes for the AD Type + if(adv_env.ex_adv_enable) + { + memcpy(&p_cmd->data[0],adv_env.ex_adv_p_data, adv_env.ex_adv_data_len); + } + else{ + memcpy(&p_cmd->data[0],adv_env.adv_data, adv_env.adv_data_len); + } + p_cmd->length += data_len; + + // Update advertising state + if (app_env.adv_state != APP_ADV_STATE_STARTED) //update adv data when adv started + app_env.adv_state = APP_ADV_STATE_SETTING_ADV_DATA; + // And the next expected operation code for the command completed event + app_env.current_op = CURRENT_OP_SET_ADV_DATA; + // Send the message + ke_msg_send(p_cmd); +} + +static void app_set_scan_rsp_data(void) +{ + uint8_t rem_len = ADV_DATA_LEN; + + // Prepare the GAPM_SET_ADV_DATA_CMD message + struct gapm_set_adv_data_cmd *p_cmd = KE_MSG_ALLOC_DYN(GAPM_SET_ADV_DATA_CMD, + TASK_GAPM, TASK_APP, + gapm_set_adv_data_cmd, + ADV_DATA_LEN); + NS_LOG_DEBUG("%s\r\n", __func__); + // Fill the allocated kernel message + p_cmd->operation = GAPM_SET_SCAN_RSP_DATA; + p_cmd->actv_idx = app_env.adv_actv_idx; + + p_cmd->length = adv_env.scan_rsp_data_len; + memcpy(&p_cmd->data[0], adv_env.scan_rsp_data, adv_env.scan_rsp_data_len); + + // Get remaining space in the Advertising Data - 2 bytes are used for name length/flag + rem_len -= p_cmd->length; + + uint8_t *p_buf = &p_cmd->data[p_cmd->length]; + // Check if additional data can be added to the Advertising data - 2 bytes needed for type and length + if (rem_len > 3 && adv_env.attach_appearance) + { + // appearance length + *p_buf = 3 ; + // appearance flag + *(p_buf + 1) = 0x19;//ADV_TYPE_APPEARANCE + // Copy device name + *(p_buf + 3) = (gap_env.appearance>>8)&0xff; //hight 8bit + *(p_buf + 2) = gap_env.appearance&0xff; //low 8bit + // Update advertising data length + p_cmd->length += 4; + p_buf += 4; + //Update Remaining Length + rem_len -= 4; + } + // Check if additional data can be added to the Advertising data - 2 bytes needed for type and length + if (rem_len > 2 && adv_env.attach_name) + { + uint8_t dev_name_length = co_min(gap_env.dev_name_len, (rem_len - 2)); + + // Device name length + *p_buf = dev_name_length + 1; + // Device name flag (check if device name is complete or not) + *(p_buf + 1) = (dev_name_length == gap_env.dev_name_len) ? '\x09' : '\x08'; + // Copy device name + memcpy(p_buf + 2, gap_env.dev_name, dev_name_length); + + // Update advertising data length + p_cmd->length += (dev_name_length + 2); + } + + // Update advertising state + if (app_env.adv_state != APP_ADV_STATE_STARTED) //update rsp data when adv started + app_env.adv_state = APP_ADV_STATE_SETTING_SCAN_RSP_DATA; + // And the next expected operation code for the command completed event + app_env.current_op = CURRENT_OP_SET_RSP_DATA; + // Send the message + ke_msg_send(p_cmd); +} + + + +static void app_send_gapm_reset_cmd(void) +{ + // Reset the stack + struct gapm_reset_cmd *p_cmd = KE_MSG_ALLOC(GAPM_RESET_CMD, + TASK_GAPM, TASK_APP, + gapm_reset_cmd); + + p_cmd->operation = GAPM_RESET; + ke_msg_send(p_cmd); +} + + +/** + * @brief Initialize the BLE application environment. + **/ +static void ns_ble_evn_init(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Reset the application manager environment + memset(&app_env, 0, sizeof(app_env)); + memset(&gap_env, 0, sizeof(gap_env)); + memset(&adv_env, 0, sizeof(adv_env)); + memset(&scan_env, 0, sizeof(scan_env)); + app_env.adv_actv_idx = 0xFF; + app_env.scan_actv_idx = 0xFF; + app_env.init_actv_idx = 0xFF; + + for (uint8_t i =0;ioperation = GAPC_SET_PREF_SLAVE_LATENCY; + p_cmd->latency = latency_cfg; + + // Send the message + ke_msg_send(p_cmd); +} + +/** + * @brief Send to request to update the connection parameters + **/ +bool ns_ble_update_param(struct gapc_conn_param *p_conn_param) +{ + /********** connection parameters requirement ************* + Interval Max * (Slave Latency + 1) <= 4 s + Interval Max >= 7.5 ms + Interval Min <= Interval Max + ConnSupervisionTimeout <= 10 s + Interval Max * ( Slave Latency + 1) * 3 < ConnSupervisionTimeout + ****************************************************************/ + NS_LOG_DEBUG("%s\r\n",__func__); + if(( p_conn_param->intv_max*(p_conn_param->latency+1) > 3200/* 4s */) || + ( p_conn_param->intv_max < 6 /* 7.5ms */) || + ( p_conn_param->intv_max < p_conn_param->intv_min) || + ( p_conn_param->time_out > 1000 /* 10s */)|| + ( p_conn_param->intv_max*(p_conn_param->latency+1)*3) > (p_conn_param->time_out*8 /* 10/1.25 */)) + { + NS_LOG_WARNING("request parameters error\r\n"); + return false; + } + + // Prepare the GAPC_PARAM_UPDATE_CMD message + struct gapc_param_update_cmd *p_cmd = KE_MSG_ALLOC(GAPC_PARAM_UPDATE_CMD, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_param_update_cmd); + + p_cmd->operation = GAPC_UPDATE_PARAMS; + p_cmd->intv_min = p_conn_param->intv_min; + p_cmd->intv_max = p_conn_param->intv_max; + p_cmd->latency = p_conn_param->latency; + p_cmd->time_out = p_conn_param->time_out; + + // not used by a slave device + p_cmd->ce_len_min = 0x0; + p_cmd->ce_len_max = 0xFFFF; + + // Send the message + ke_msg_send(p_cmd); + return true; +} + +/** + * @brief master device get peer info + * op: GAPC_GET_PEER_FEATURES + * GAPC_GET_PEER_VERSION + */ +void ns_ble_get_peer_info(uint8_t op) +{ + NS_LOG_DEBUG("%s,app_env.conidx= %d\r\n", __func__,app_env.conidx); + struct gapc_get_info_cmd *cmd = KE_MSG_ALLOC(GAPC_GET_INFO_CMD, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_get_info_cmd); + cmd->operation = op; + // Send the message + ke_msg_send(cmd); +} + +/** + * @brief set ble dle + **/ +void ns_ble_dle_set(uint16_t tx_octets, uint16_t tx_time) +{ + struct gapc_set_le_pkt_size_cmd *cmd = KE_MSG_ALLOC(GAPC_SET_LE_PKT_SIZE_CMD, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_set_le_pkt_size_cmd); + cmd->operation = GAPC_SET_LE_PKT_SIZE; + cmd->tx_octets = tx_octets; + cmd->tx_time = tx_time; + // Send the message + ke_msg_send(cmd); +} + + +/** + * @brief set ble mtu + **/ +void ns_ble_mtu_set(uint16_t mtu) +{ + + struct gattc_exc_mtu_cmd *cmd = KE_MSG_ALLOC(GATTC_EXC_MTU_CMD, + KE_BUILD_ID(TASK_GATTC, app_env.conidx), TASK_APP, + gattc_exc_mtu_cmd); + //ROM bug fix + gapm_env.max_mtu = mtu; + + cmd->operation = GATTC_MTU_EXCH; + cmd->seq_num = 0; + ke_msg_send(cmd); +} + + + +/** + * @brief set ble phy + **/ +void ns_ble_phy_set(enum ble_phy_val phy) +{ + struct gapc_set_phy_cmd *cmd = KE_MSG_ALLOC(GAPC_SET_PHY_CMD, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_set_phy_cmd); + + cmd->operation = GAPC_SET_PHY; + cmd->rx_phy = phy & (GAP_PHY_LE_1MBPS|GAP_PHY_LE_2MBPS|GAP_PHY_LE_CODED); + cmd->tx_phy = phy & (GAP_PHY_LE_1MBPS|GAP_PHY_LE_2MBPS|GAP_PHY_LE_CODED); + cmd->phy_opt = (phy>>4)&(PHY_OPT_S8_LE_CODED_TX_PREF|PHY_OPT_S2_LE_CODED_TX_PREF); + + ke_msg_send(cmd); +} + +/** + * @brief avtive get ble RSSI with an interval in ms. 0ms mean active one time only + **/ +void ns_ble_active_rssi(uint32_t interval) +{ + struct gapc_get_info_cmd* info_cmd = KE_MSG_ALLOC(GAPC_GET_INFO_CMD, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_get_info_cmd); + + app_env.rssi_intv = interval; + app_env.rssi_conidx = app_env.conidx; + // request RSSI + info_cmd->operation = GAPC_GET_CON_RSSI; + // send command + ke_msg_send(info_cmd); +} + + +void ns_ble_adv_fsm_next(void) +{ + NS_LOG_DEBUG("%s,adv_state:%d \r\n",__func__,app_env.adv_state); + switch (app_env.adv_state) + { + case (APP_ADV_STATE_IDLE): + { + if(app_env.adv_mode != APP_ADV_MODE_STOP) + { + // Create advertising + app_create_advertising(); + } + } break; + + case (APP_ADV_STATE_CREATING): + { + if(app_env.adv_mode == APP_ADV_MODE_DIRECTED) + { + // Start advertising activity + app_start_advertising(); + } + else{ + // Set advertising data + app_set_adv_data(); + } + } break; + + case (APP_ADV_STATE_SETTING_ADV_DATA): + { + if(adv_env.beacon_enable || adv_env.ex_adv_enable) + { + app_start_advertising(); + }else{ + // Set scan response data + app_set_scan_rsp_data(); + } + } break; + + case (APP_ADV_STATE_CREATED): + case (APP_ADV_STATE_SETTING_SCAN_RSP_DATA): + { + // Start advertising activity + app_start_advertising(); + } break; + + case (APP_ADV_STATE_STARTING): + { + // Go to started state + app_env.adv_state = APP_ADV_STATE_STARTED; + } break; + + case (APP_ADV_STATE_STARTED): + { + // Stop advertising activity + app_stop_advertising(); + } break; + + case (APP_ADV_STATE_STOPPING): + { + //delete activity when advertising stop + app_delete_activity(); + + } break; + + default: + { + ASSERT_ERR(0); + } break; + } +} + +void ns_ble_lsc_config(ble_lsc_cfg_t lsc_set) +{ + //Config the LSC for stack + if(lsc_set == BLE_LSC_LSE_32768HZ) + { + //enable LSE and select LSC as LSE + *(uint32_t*)0x40011008 |= 0xF00; + RCC->LSCTRL |= RCC_LSCTRL_LSEEN; + while(!(RCC->LSCTRL & RCC_LSCTRL_LSERD)); + RCC->LSCTRL |= RCC_LSCTRL_LSXSEL_LSE; + + g_lsi_1_syscle_cal_value = 1000; + //lse frequency 32768 + g_lsi_1_syscle_cnt_value = 976; //32000000/32768 = 976.56 //must fixed + } + else + { + //LSC select LSI + RCC->LSCTRL |= RCC_LSCTRL_LSIEN; + while(!(RCC->LSCTRL & RCC_LSCTRL_LSIRD)); + RCC->LSCTRL &= ~RCC_LSCTRL_LSXSEL_LSE; + /* set lsi frequency, (32m/lsc_freq) 32k:1000 , 28.8k 1111.11 , 32.768: 976.56 */ + /* g_lsi_1_syscle_cal_value = 32000000/lsc_freq; */ + switch (lsc_set) + { + case BLE_LSC_LSI_32768HZ: + g_lsi_1_syscle_cal_value = 977; + break; + case BLE_LSC_LSI_28800HZ: + g_lsi_1_syscle_cal_value = 1111; + break; + case BLE_LSC_LSI_32000HZ: + default: + g_lsi_1_syscle_cal_value = 1000; + break; + } + g_lsi_1_syscle_cnt_value = calib_lsi_clk(); //take 7.5ms + } +} + +void ns_ble_stack_init(struct ns_stack_cfg_t const* p_init) +{ + ns_ble_stack_vtor_init(); + ns_ble_evn_init(); + app_env.ble_msg_handler = p_init->ble_msg_handler; + app_env.user_msg_handler = p_init->user_msg_handler; + app_env.iwdg_cycle = p_init->iwdg_cycle; + if( p_init->lsc_cfg <= BLE_LSC_LSE_32768HZ ) + { + app_env.lsc_cfg = p_init->lsc_cfg; + } + else + { + //set LSI 32000HZ as default + app_env.lsc_cfg = BLE_LSC_LSI_32000HZ; + } + + NS_BLE_PATCH_INIT(); + NS_BLE_STACK_INIT(); + ns_ble_task_init(); + prf_init(RWIP_INIT); + // Reset the stack + app_send_gapm_reset_cmd(); +} + +void ns_ble_gap_init(struct ns_gap_params_t const* p_init) +{ + if(p_init != NULL) + { + memcpy(&gap_env,p_init,sizeof(struct ns_gap_params_t)); + } + + //generate local IRK + uint8_t tmp_irk[KEY_LEN]; + memcpy(&tmp_irk[0], SEC_DEFAULT_IRK, KEY_LEN); + for (uint8_t i=0;i ADV_DATA_LEN-3) + && (adv_env.beacon_enable == false) ) + { + adv_env.adv_data_len = ADV_DATA_LEN-3; + } + if(adv_env.scan_rsp_data_len > ADV_DATA_LEN) + { + adv_env.scan_rsp_data_len = ADV_DATA_LEN; + } + if(adv_env.ex_adv_data_len > EXT_ADV_DATA_MAX_LEN-3) + { + adv_env.ex_adv_data_len = EXT_ADV_DATA_MAX_LEN-3; + } +} + +bool ns_ble_adv_data_set(uint8_t* p_dat, uint16_t len) +{ + adv_env.adv_data_len = len; + if((adv_env.adv_data_len > ADV_DATA_LEN-3) + && (adv_env.beacon_enable == false) ) + { + adv_env.adv_data_len = ADV_DATA_LEN-3; + } + + memcpy(adv_env.adv_data,p_dat,adv_env.adv_data_len); + + if(app_env.adv_mode == APP_ADV_MODE_FAST || + app_env.adv_mode == APP_ADV_MODE_SLOW) + { + app_set_adv_data(); + app_env.current_op = 0xff; //cancel next step + return true; + } + return false; +} + +bool ns_ble_scan_rsp_data_set(uint8_t* p_dat, uint16_t len) +{ + adv_env.scan_rsp_data_len = len; + if(adv_env.scan_rsp_data_len > ADV_DATA_LEN) + { + adv_env.scan_rsp_data_len = ADV_DATA_LEN; + } + + memcpy(adv_env.scan_rsp_data,p_dat,adv_env.scan_rsp_data_len); + + if(app_env.adv_mode == APP_ADV_MODE_FAST || + app_env.adv_mode == APP_ADV_MODE_SLOW) + { + app_set_scan_rsp_data(); + app_env.current_op = 0xff; //cancel next step + return true; + } + return false; +} + +bool ns_ble_ex_adv_data_set(uint8_t* p_dat, uint16_t len) +{ + adv_env.ex_adv_data_len = len; + if(adv_env.ex_adv_data_len > EXT_ADV_DATA_MAX_LEN-3) + { + adv_env.ex_adv_data_len = EXT_ADV_DATA_MAX_LEN-3; + } + adv_env.ex_adv_p_data = p_dat; + if(app_env.adv_mode == APP_ADV_MODE_FAST || + app_env.adv_mode == APP_ADV_MODE_SLOW) + { + app_set_adv_data(); + app_env.current_op = 0xff; //cancel next step + return true; + } + return false; +} + +void ns_ble_adv_start(void) +{ + if(app_env.adv_state == APP_ADV_STATE_STOPPING) + { + app_env.adv_mode = APP_ADV_MODE_ENABLE; + return; + } + + switch (app_env.adv_mode) + { + case APP_ADV_MODE_IDLE: + //on idle mode then enable. + app_env.adv_mode = APP_ADV_MODE_ENABLE; + break; + + case APP_ADV_MODE_ENABLE: + case APP_ADV_MODE_STOP: + //on ready mode then start + if(adv_env.directed_adv.enable) + { + app_env.adv_mode = APP_ADV_MODE_DIRECTED; + } + else if(adv_env.fast_adv.enable) + { + app_env.adv_mode = APP_ADV_MODE_FAST; + } + else if(adv_env.slow_adv.enable) + { + app_env.adv_mode = APP_ADV_MODE_SLOW; + } + else + { + app_env.adv_mode = APP_ADV_MODE_STOP; + } + app_create_advertising(); + break; + default: + //on started mode do nothing + break; + } + + +} + +void ns_ble_adv_stop(void) +{ + switch (app_env.adv_mode) + { + case APP_ADV_MODE_IDLE: + case APP_ADV_MODE_ENABLE: + //on idle and enable mode then disable + app_env.adv_mode = APP_ADV_MODE_STOP; + break; + case APP_ADV_MODE_STOP: + //on stop mode then do nothing + break; + case APP_ADV_MODE_DIRECTED: + case APP_ADV_MODE_FAST: + case APP_ADV_MODE_SLOW: + default: + //on started mode then stop + app_env.adv_mode = APP_ADV_MODE_STOP; + app_stop_advertising(); + break; + } +} + +void ns_ble_disconnect(void) +{ + struct gapc_disconnect_cmd *p_cmd = KE_MSG_ALLOC(GAPC_DISCONNECT_CMD, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_disconnect_cmd); + + NS_LOG_DEBUG("%s\r\n", __func__); + p_cmd->operation = GAPC_DISCONNECT; + p_cmd->reason = CO_ERROR_REMOTE_USER_TERM_CON; + + // Send the message + ke_msg_send(p_cmd); +} + + + + +/* Master device API*/ + +void ns_ble_scan_init(struct ns_scan_params_t *p_init) +{ + if(p_init != NULL) + { + memcpy(&scan_env,p_init, sizeof(struct ns_scan_params_t)); + } +} + + + +void ns_ble_create_scan(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + if(app_env.scan_actv_idx == 0xFF) + { + // Prepare the GAPM_ACTIVITY_CREATE_CMD message + struct gapm_activity_create_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_CREATE_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_create_cmd); + // Set operation code + p_cmd->operation = GAPM_CREATE_SCAN_ACTIVITY; + // Fill the allocated kernel message + p_cmd->own_addr_type = gap_env.mac_addr_type;//GAPM_STATIC_ADDR; + + // Send the message + ke_msg_send(p_cmd); + } +} + +void ns_ble_start_scan(void) +{ + NS_LOG_DEBUG("%s,%x\r\n", __func__,app_env.scan_actv_idx); + + if(app_env.scan_actv_idx == 0xFF) + { + scan_env.scan_enable = true; + //creat scan active if not created yet + ns_ble_create_scan(); + return; + } + else if(!scan_env.scan_enable) + { + //scan already started + return; + } + scan_env.scan_enable = false; + app_env.wl_reconnect = false; + // Prepare the GAPM_ACTIVITY_START_CMD message + struct gapm_activity_start_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_START_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_start_cmd); + + p_cmd->operation = GAPM_START_ACTIVITY; + p_cmd->actv_idx = app_env.scan_actv_idx; + + p_cmd->u_param.scan_param.type = scan_env.type; + p_cmd->u_param.scan_param.dup_filt_pol = scan_env.dup_filt_pol; + p_cmd->u_param.scan_param.scan_param_1m.scan_intv = scan_env.scan_intv; + p_cmd->u_param.scan_param.scan_param_1m.scan_wd = scan_env.scan_wd; + p_cmd->u_param.scan_param.duration = scan_env.duration; + p_cmd->u_param.scan_param.period = scan_env.period; + //scan 1M as default + p_cmd->u_param.scan_param.prop = GAPM_SCAN_PROP_PHY_1M_BIT; + llhwc_modem_setmode(GAP_PHY_1MBPS); + + if(scan_env.phy_coded_enable) + { + p_cmd->u_param.scan_param.prop |= GAPM_SCAN_PROP_PHY_CODED_BIT; + p_cmd->u_param.scan_param.scan_param_coded.scan_intv = scan_env.scan_intv; + p_cmd->u_param.scan_param.scan_param_coded.scan_wd = scan_env.scan_wd; + llhwc_modem_setmode(GAP_PHY_CODED); + } + + if(scan_env.prop_active_enable) + { + p_cmd->u_param.scan_param.prop |= GAPM_SCAN_PROP_ACTIVE_1M_BIT|GAPM_SCAN_PROP_ACTIVE_CODED_BIT; + } + + app_env.current_op = CURRENT_OP_START_SCAN; + app_env.target_found = false; + // Send the message + ke_msg_send(p_cmd); +} + +void ns_ble_delete_scan(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + if(app_env.scan_actv_idx != 0xff) + { + struct gapm_activity_delete_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_DELETE_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_delete_cmd); + // Set operation code + p_cmd->operation = GAPM_DELETE_ACTIVITY; + p_cmd->actv_idx = app_env.scan_actv_idx; + app_env.current_op = CURRENT_OP_NULL; + // Send the message + ke_msg_send(p_cmd); + } +} + +void ns_ble_stop_scan(void) +{ + NS_LOG_DEBUG("%s,%x\r\n", __func__,app_env.scan_actv_idx); + + if(app_env.scan_actv_idx != 0xff && app_env.current_op != CURRENT_OP_STOP_SCAN) + { + struct gapm_activity_stop_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_STOP_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_stop_cmd); + // Set operation code + p_cmd->operation = GAPM_STOP_ACTIVITY; + p_cmd->actv_idx = app_env.scan_actv_idx; + app_env.current_op = CURRENT_OP_STOP_SCAN; + // Send the message + ke_msg_send(p_cmd); + } +} + +void ns_ble_create_init(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + if(app_env.init_actv_idx == 0xFF) + { + // Prepare the GAPM_ACTIVITY_CREATE_CMD message + struct gapm_activity_create_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_CREATE_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_create_cmd); + // Set operation code + p_cmd->operation = GAPM_CREATE_INIT_ACTIVITY; + // Fill the allocated kernel message + p_cmd->own_addr_type = gap_env.mac_addr_type; + // Send the message + ke_msg_send(p_cmd); + } +} + +void ns_ble_start_init(uint8_t *addr, uint8_t addr_type) +{ + NS_LOG_DEBUG("%s,%x\r\n", __func__,app_env.init_actv_idx); + if(app_env.init_actv_idx == 0xFF) + { + //creat init active if not created yet + ns_ble_create_init(); + + app_env.target_addr_type = addr_type; + memcpy(app_env.target_addr.addr, addr, 6); + app_env.target_found = true; + scan_env.connect_enable = true; + return; + } + //set init timeout timer + if(scan_env.initiating_timeout) + { + ke_timer_set(APP_INIT_TIMEOUT_EVT,TASK_APP,scan_env.initiating_timeout); + } + + // Prepare the GAPM_ACTIVITY_START_CMD message + struct gapm_activity_start_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_START_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_start_cmd); + + p_cmd->operation = GAPM_START_ACTIVITY; + p_cmd->actv_idx = app_env.init_actv_idx; + + if (app_env.wl_reconnect){ + p_cmd->u_param.init_param.type = GAPM_INIT_TYPE_AUTO_CONN_EST; + p_cmd->u_param.init_param.conn_to = 0; + app_env.wl_reconnect = false; + } + else { + p_cmd->u_param.init_param.type = GAPM_INIT_TYPE_DIRECT_CONN_EST; + p_cmd->u_param.init_param.conn_to = 0; + } + p_cmd->u_param.init_param.prop = GAPM_INIT_PROP_1M_BIT; + p_cmd->u_param.init_param.scan_param_1m.scan_intv = 0x320; + p_cmd->u_param.init_param.scan_param_1m.scan_wd = 0x320; + p_cmd->u_param.init_param.conn_param_1m.conn_intv_min = gap_env.dev_conn_param.intv_min; + p_cmd->u_param.init_param.conn_param_1m.conn_intv_max = gap_env.dev_conn_param.intv_max; + p_cmd->u_param.init_param.conn_param_1m.conn_latency = gap_env.dev_conn_param.latency; + p_cmd->u_param.init_param.conn_param_1m.supervision_to = gap_env.dev_conn_param.time_out; + p_cmd->u_param.init_param.conn_param_1m.ce_len_min = 0; + p_cmd->u_param.init_param.conn_param_1m.ce_len_max = 0x140; + + if(scan_env.phy_coded_enable) + { + p_cmd->u_param.init_param.prop |= GAPM_INIT_PROP_CODED_BIT; + p_cmd->u_param.init_param.scan_param_coded.scan_intv = 0x320; + p_cmd->u_param.init_param.scan_param_coded.scan_wd = 0x320; + p_cmd->u_param.init_param.conn_param_coded.conn_intv_min = gap_env.dev_conn_param.intv_min; + p_cmd->u_param.init_param.conn_param_coded.conn_intv_max = gap_env.dev_conn_param.intv_max; + p_cmd->u_param.init_param.conn_param_coded.conn_latency = gap_env.dev_conn_param.latency; + p_cmd->u_param.init_param.conn_param_coded.supervision_to = gap_env.dev_conn_param.time_out; + p_cmd->u_param.init_param.conn_param_coded.ce_len_min = 0; + p_cmd->u_param.init_param.conn_param_coded.ce_len_max = 0x140; + } + + p_cmd->u_param.init_param.peer_addr.addr_type = addr_type; + + memcpy(p_cmd->u_param.init_param.peer_addr.addr.addr, addr, 6); + + if(p_cmd->u_param.init_param.prop & GAPM_INIT_PROP_2M_BIT) + { + llhwc_modem_setmode(GAP_PHY_2MBPS); + } + else if(p_cmd->u_param.init_param.prop & GAPM_INIT_PROP_CODED_BIT) + { + llhwc_modem_setmode(GAP_PHY_CODED); + } + else{ + llhwc_modem_setmode(GAP_PHY_1MBPS); + } + + app_env.current_op = CURRENT_OP_START_INIT; + // Send the message + ke_msg_send(p_cmd); +} + +void ns_ble_stop_init(void) +{ + NS_LOG_DEBUG("%s,init_actv_idx = 0x%x\r\n", __func__,app_env.init_actv_idx); + if (app_env.init_actv_idx != 0xFF) + { + struct gapm_activity_stop_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_STOP_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_stop_cmd); + // Set operation code + p_cmd->operation = GAPM_STOP_ACTIVITY; + p_cmd->actv_idx = app_env.init_actv_idx; + app_env.current_op = CURRENT_OP_STOP_INIT; + // Send the message + ke_msg_send(p_cmd); + } +} + +void ns_ble_delete_init(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + if (app_env.init_actv_idx != 0xFF) + { + struct gapm_activity_delete_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_DELETE_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_delete_cmd); + // Set operation code + p_cmd->operation = GAPM_DELETE_ACTIVITY; + p_cmd->actv_idx = app_env.init_actv_idx; + + app_env.current_op = CURRENT_OP_NULL; + app_env.init_actv_idx = 0xFF; + // Send the message + ke_msg_send(p_cmd); + } +} + + +bool ns_ble_scan_data_find(uint8_t types, const uint8_t *p_filter_data, uint8_t *p_data, uint8_t len ) +{ + uint8_t pack_len; + uint8_t pack_type; + while(len) + { + // check if pack incomplete + if(len < (*p_data)+1 || len < 3) + { + break; + } + pack_len = (*p_data)-1; // get pack len + p_data++; + pack_type = *p_data; // get pack type + p_data++; + if(pack_type == types) // + { + if(memcmp(p_data,p_filter_data,pack_len) == 0) + { + return true; + } + } + p_data += pack_len; //next pack + len -= (pack_len+2); + } + + return false; +} + +/* Used before connection operation or set connection parameter*/ +void ns_ble_set_active_connection (uint8_t conidx) +{ + app_env.conidx = conidx; +} + +uint8_t ns_ble_get_active_connection (void) +{ + return app_env.conidx; +} + +/* check the connection status by indx: true is connected,false is disconnected */ +bool ns_ble_get_connection_state(uint8_t conidx) +{ + bool status = false; + if ((app_env.conn_env[conidx].conidx != GAP_INVALID_CONIDX ) && (conidx < APP_CON_IDX_MAX) ) + { + status = true; + } + return status; +} + +/* Get the connection number*/ +uint8_t ns_ble_get_connection_num (void) +{ + uint8_t conidx_cnt = 0; + for (uint8_t i =0;ioperation = GAPM_RESOLV_ADDR; + p_cmd->nb_key = nb_key; + + memcpy(&(p_cmd->addr.addr[0]), addr, sizeof(bd_addr_t)); + memcpy(&(p_cmd->irk[0]), irk, KEY_LEN*nb_key); + NS_LOG_DEBUG("%s\r\n", __func__); + + // Send the message + ke_msg_send(p_cmd); +} + +/* Set resolving list */ +void ns_ble_list_set_ral(struct gap_ral_dev_info *ral_list,uint8_t ral_cnt) +{ + struct gapm_list_set_ral_cmd *p_cmd = KE_MSG_ALLOC_DYN(GAPM_LIST_SET_CMD, + TASK_GAPM, TASK_APP, + gapm_list_set_ral_cmd, + (ral_cnt * sizeof(struct gap_ral_dev_info))); + + NS_LOG_DEBUG("%s,ral_cnt:%d\r\n", __func__,ral_cnt); + p_cmd->operation = GAPM_SET_RAL; + p_cmd->size = ral_cnt; + for (uint8_t cnt = 0; cnt < ral_cnt; cnt++) + { + ral_list[cnt].priv_mode = 0; + memcpy(&p_cmd->ral_info[cnt], &ral_list[cnt], sizeof(struct gap_ral_dev_info)); + NS_LOG_DEBUG("set_ral:%d,%d,%d,%d,%d\r\n",ral_list[cnt].priv_mode,\ + ral_list[cnt].local_irk[0],\ + ral_list[cnt].peer_irk[0],\ + ral_list[cnt].addr.addr_type,\ + ral_list[cnt].addr.addr.addr[0]); + } + ke_msg_send(p_cmd); +} + +/* Set white list */ +void ns_ble_list_set_wl(struct gap_bdaddr *wl_addr,uint8_t wl_cnt) +{ + struct gapm_list_set_wl_cmd *p_cmd = KE_MSG_ALLOC_DYN(GAPM_LIST_SET_CMD, + TASK_GAPM, TASK_APP, + gapm_list_set_wl_cmd, + wl_cnt * sizeof(struct gap_bdaddr)); + + NS_LOG_DEBUG("%s,wl_cnt:%d\r\n", __func__,wl_cnt); + p_cmd->operation = GAPM_SET_WL; + p_cmd->size = wl_cnt; + for (uint8_t cnt = 0; cnt < wl_cnt; cnt++) + { + memcpy(&p_cmd->wl_info[cnt], &wl_addr[cnt], sizeof(struct gap_bdaddr)); + NS_LOG_DEBUG("set_wl:%x,%x,%x,%x,%x,%x;addr type: %d\r\n", wl_addr[cnt].addr.addr[0],\ + wl_addr[cnt].addr.addr[1],\ + wl_addr[cnt].addr.addr[2],\ + wl_addr[cnt].addr.addr[3],\ + wl_addr[cnt].addr.addr[4],\ + wl_addr[cnt].addr.addr[5],\ + wl_addr[cnt].addr_type); + } + ke_msg_send(p_cmd); +} + +void ns_ble_set_channel_map( uint8_t* newchmap) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct gapm_set_channel_map_cmd *p_cmd = KE_MSG_ALLOC(GAPM_SET_CHANNEL_MAP_CMD, + TASK_GAPM, TASK_APP, + gapm_set_channel_map_cmd); + // Set operation code + p_cmd->operation = GAPM_SET_CHANNEL_MAP; + memcpy(&(p_cmd->chmap.map), newchmap, sizeof(le_chnl_map_t)); + // Send the message + ke_msg_send(p_cmd); +} + + +/* enter rf test mode */ +void ns_ble_prod_test_cmd_send(struct gapm_le_test_mode_ctrl_cmd *p_params, bool cw_mode) +{ + struct gapm_le_test_mode_ctrl_cmd *p_cmd = KE_MSG_ALLOC(GAPM_LE_TEST_MODE_CTRL_CMD, + TASK_GAPM, TASK_APP, + gapm_le_test_mode_ctrl_cmd); + + if(cw_mode) + { + REG32(MODEM_BASE + 0xc6 * 4) = 0; + REG32(MODEM_BASE + 0xc7 * 4) = 0; + REG32(MODEM_BASE + 0xc8 * 4) = 0; +#ifndef INFTRX + ble_rftestcntl_infinitetx_setf(1); + p_params->tx_pkt_payload = 0; +#endif + p_params->operation = GAPM_LE_TEST_TX_START; + } + else + { +#ifdef INFTRX + ble_rftestcntl_infinitetx_setf(1); + p_params->tx_pkt_payload = 0; +#endif + } + memcpy(p_cmd,p_params,sizeof(struct gapm_le_test_mode_ctrl_cmd)); + llhwc_modem_setmode(p_params->phy); + // Send the message + ke_msg_send(p_cmd); +} + + + +/** + * @brief set the radio fact frequency to calibrate it. + * @param fact_freq: the fact frequency test in CW mode, uint is Hz. + * @param std_freq: the standard frequency shoud get in CW mode. + * @return void + * @note for example: you can use RFTest example to test the CW in 0 channel, + * it should be 2402000000 Hz, but we get 2401950000, it meam it offset 50k Hz. + * We can call the function: ns_ble_radio_calibration(2401950000, 2402000000); + */ +void ns_ble_radio_calibration(uint32_t fact_freq,uint32_t std_freq) +{ + float Ndiv = (float)std_freq / 8000000; + uint32_t mco_freq = fact_freq / Ndiv; + + extern void radio_hse_mco_set(uint32_t mco_freq); + radio_hse_mco_set(mco_freq); +} + +/** + * @brief set the radio tx power. + * @param tx_pwr: the power value to set, it can be set as below. + TX_POWER_0_DBM + TX_POWER_Neg2_DBM + TX_POWER_Neg4_DBM + TX_POWER_Neg8_DBM + TX_POWER_Neg15_DBM + TX_POWER_Neg20_DBM + TX_POWER_Pos2_DBM + TX_POWER_Pos3_DBM + TX_POWER_Pos4_DBM + TX_POWER_Pos6_DBM + * @return + * @note + */ +void ns_ble_radio_power_set(rf_tx_power_t tx_pwr) +{ + rf_tx_power_set(tx_pwr); +} + + +static rwip_time_t reload_time = {0}; + +/** + * @brief Config the peripheral. + * @param + * @return + * @note + */ +void ns_peripheral_config(void) +{ + while(!(RCC->CTRL&RCC_CTRL_HSERDF));//wait HSE ready + ns_ble_lsc_config(app_env.lsc_cfg); + + /* Check if the system has resumed from IWDG reset */ + if (((RCC->CTRLSTS&(RCC_CTRLSTS_PORRSTF|RCC_CTRLSTS_IWDGRSTF)) == RCC_CTRLSTS_IWDGRSTF)) + { + /* IWDGRST flag set*/ + NS_LOG_WARNING("IWDGRST is set, reset from IWDG!!!\r\n"); + } + /* Clear reset flags */ + RCC->CTRLSTS |= RCC_CTRLSTS_RMRSTF; + RCC->CTRLSTS &= ~RCC_CTRLSTS_RMRSTF; + //iwdg + ns_iwdg_config(); + rwip_time_t current_time = rwip_time_get(); + reload_time.hs = current_time.hs; + + #if NS_LSI_CALIB_EN + //enalbe lsi measurement + if(app_env.lsc_cfg != BLE_LSC_LSE_32768HZ) + { + ns_sleep_lock_acquire();//pending sleep for calib + RCC->OSCFCCR &= ~(0xFF<< 8); + RCC->OSCFCCR |= (LSI_CLOCK_CNT_CYCLES <<8); + RCC->OSCFCCR |= 1; + //start lis calib timer + ke_timer_set(APP_LSI_CALIB_EVT,TASK_APP,1); + } + #endif + + //ble irq + NVIC_SetPriority(BLE_SW_IRQn, 0); + NVIC_SetPriority(BLE_FIFO_IRQn, 0); +} + + +/** + * @brief Config the iwdg if iwdg_cycle is valid. + * @param + * @return + * @note + */ +void ns_iwdg_config(void) +{ + //Do not add any printf log here, because it call after wakeup!!! + if(app_env.iwdg_cycle > 10) // iwdg_cycle < 4000ms + { + RCC->APB1PCLKEN |= RCC_APB1_PERIPH_PWR; + RCC->DBGMCU_CR |= DBG_IWDG_STOP; + /* Enable write access to IWDG_PR and IWDG_RLR registers */ + IWDG->KEY = IWDG_WRITE_ENABLE; + /* IWDG counter clock: LSI/32 */ + IWDG->PREDIV = IWDG_PRESCALER_DIV32; + /* Set counter reload value to obtain 300ms IWDG TimeOut.*/ + IWDG->RELV = app_env.iwdg_cycle; + /* Reload IWDG counter */ + IWDG->KEY = 0xAAAA; + /* Enable IWDG (the LSI oscillator will be enabled by hardware) */ + IWDG->KEY = 0xCCCC; + } +} +/** + * @brief Reload the iwdg if ((current_time-reload_time)/3.2) > iwdg_cycle. + * @param + * @return + * @note + */ +void ns_iwdg_reload(void) +{ + rwip_time_t current_time = rwip_time_get(); + int32_t pass_hs = CLK_DIFF(reload_time.hs,current_time.hs ); + if((pass_hs>>1) > (app_env.iwdg_cycle)) + { + /* Reload IWDG counter */ + IWDG->KEY = 0xAAAA; + + NS_LOG_DEBUG("%s, C_time:%d, R_time%d\r\n",__func__,current_time.hs,reload_time.hs); + reload_time.hs = current_time.hs; + } + + +} +#endif //(BLE_APP_PRESENT) + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble.h new file mode 100644 index 0000000..8eba732 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble.h @@ -0,0 +1,561 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _NS_BLE_H_ +#define _NS_BLE_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Application entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_PRESENT) +#include "global_func.h" +/* Define ------------------------------------------------------------*/ +#define NS_IWDG_CYCLE_MAX (0xfff) +#define APP_ADV_DURATION_MAX (655) + +#define SECS_UNIT_1_25_MS (800) +#define SECS_UNIT_10MS (100) +#define SECS_TO_UNIT(sec,uint) ((sec)*(uint)) + +#define MSECS_UNIT_1_25_MS (1250) +#define MSECS_UNIT_10_MS (10000) +#define MSECS_TO_UNIT(msec,uint) ((msec*1000)/(uint)) + +/// Maximal length of the Device Name value +#define APP_DEVICE_NAME_MAX_LEN (18) +#define APP_MESH_DEMO_TYPE_LEN (1) +/// Device IRK used for Resolvable Private Address generation (LSB first) +#define SEC_DEFAULT_IRK "\x50\x19\x21\x90\x1f\x04\xd5\x62\x4f\xa4\x89\xab\x90\xd0\xcf\x23" + +/* + * MACROS + **/ + +#define APP_HANDLERS(subtask) {&subtask##_msg_handler_list[0], ARRAY_LEN(subtask##_msg_handler_list)} + + +/* Typedef -----------------------------------------------------------*/ +typedef void (* ble_hw_check_t)(uint8_t,uint32_t); +typedef void (*ns_ble_add_prf_func_t)(void); + +enum current_op_t +{ + CURRENT_OP_NULL, + //adv + CURRENT_OP_CREATE_ADV, + CURRENT_OP_SET_ADV_DATA, + CURRENT_OP_SET_RSP_DATA, + CURRENT_OP_START_ADV, + CURRENT_OP_STOP_ADV, + CURRENT_OP_DELETE_ADV, + //scan + CURRENT_OP_CREATE_SCAN, + CURRENT_OP_START_SCAN, + CURRENT_OP_STOP_SCAN, + CURRENT_OP_DELETE_SCAN, + + //init (master connect) + CURRENT_OP_CREATE_INIT, + CURRENT_OP_START_INIT, + CURRENT_OP_STOP_INIT, + CURRENT_OP_DELETE_INIT, +}; + +/// Advertising state machine +enum app_adv_state +{ + /// Advertising activity does not exists + APP_ADV_STATE_IDLE = 0, + #if BLE_APP_PRF + /// Creating advertising activity + APP_ADV_STATE_CREATING, + /// Setting advertising data + APP_ADV_STATE_SETTING_ADV_DATA, + /// Setting scan response data + APP_ADV_STATE_SETTING_SCAN_RSP_DATA, + + /// Advertising activity created + APP_ADV_STATE_CREATED, + /// Starting advertising activity + APP_ADV_STATE_STARTING, + /// Advertising activity started + APP_ADV_STATE_STARTED, + /// Stopping advertising activity + APP_ADV_STATE_STOPPING, + #endif //(BLE_APP_PRF) +}; + +enum app_adv_mode +{ + APP_ADV_MODE_IDLE = 0, + APP_ADV_MODE_ENABLE, + APP_ADV_MODE_DIRECTED, + APP_ADV_MODE_FAST, + APP_ADV_MODE_SLOW, + APP_ADV_MODE_STOP, + +}; + +enum app_ble_msg +{ + APP_BLE_NULL_MSG= 0, + APP_BLE_OS_READY, + APP_BLE_GAP_CONNECTED, + APP_BLE_GAP_DISCONNECTED, + APP_BLE_GAP_PARAMS_REQUEST, + APP_BLE_GAP_CMP_EVT, + APP_BLE_GAP_RSSI_IND, + APP_BLE_GATTC_MTU_IND, + APP_BLE_GAP_PARAMS_IND, + APP_BLE_GATTC_CMP_EVT, +}; + +struct ble_msg_t +{ + enum app_ble_msg msg_id; + + //income message + union + { + struct gapm_cmp_evt const* p_gapm_cmp; + struct gapc_connection_req_ind const* p_connection_ind; + struct gapc_disconnect_ind const* p_disconnect_ind; + struct gapc_param_update_req_ind const* p_param_req; + struct gapc_cmp_evt const* p_gapc_cmp; + struct gapc_con_rssi_ind const* p_gapc_rssi; + struct gattc_mtu_changed_ind const* p_gattc_mtu; + struct gapc_param_updated_ind const* p_param_updated; + struct gattc_cmp_evt const* p_gattc_cmp; + }msg; + // output command + union + { + struct gapm_set_dev_config_cmd* p_dev_config; + struct gapc_connection_cfm* p_connection_cfm; + struct gapc_param_update_cfm* p_param_cfm; + }cmd; +}; + + +typedef enum +{ + BLE_LSC_LSI_32000HZ = 0, + BLE_LSC_LSI_32768HZ, + BLE_LSC_LSI_28800HZ, + BLE_LSC_LSE_32768HZ +}ble_lsc_cfg_t; + +/* Public define ------------------------------------------------------------*/ + +/// Structure containing information about the handlers for an application subtask +struct app_subtask_handlers +{ + /// Pointer to the message handler table + const struct ke_msg_handler *p_msg_handler_tab; + /// Number of messages handled + uint16_t msg_cnt; +}; + +//APP_CON_IDX_MAX less than BLE_CONNECTION_MAX-1 +/// Application connection environment structure +enum app_connection_num +{ + APP_CON_IDX_0 = 0, + APP_CON_IDX_1, + APP_CON_IDX_2, + APP_CON_IDX_MAX, +}; + +struct app_con_env_tag +{ + /// Connection handle + uint16_t conhdl; + /// Connection Index + uint8_t conidx; + /// Last paired peer address type + uint8_t peer_addr_type; + + /// Last paired peer address + struct bd_addr peer_addr; + /// Maximum device MTU size + uint16_t max_mtu; + ///DLE, the maximum number of payload octets in TX + uint16_t tx_pkt_size; + /// Role of device in connection (0 = Master / 1 = Slave) + uint8_t role; + +}; + +/// Application environment structure +struct app_env_tag +{ + /// Connection handle + uint16_t conhdl; + /// Connection Index + uint8_t conidx; + + /// Advertising activity index + uint8_t adv_actv_idx; + /// Current advertising state (@see enum app_adv_state) + uint8_t adv_state; + /// Next expected operation completed event + uint8_t current_op; + /// Advertising mode + enum app_adv_mode adv_mode; + + /// Last initialized profile + uint8_t next_svc; + + /// Last paired peer address type + uint8_t peer_addr_type; + + /// Last paired peer address + struct bd_addr peer_addr; + + /// Local device IRK + uint8_t loc_irk[KEY_LEN]; + + struct gap_sec_key peer_irk; + + /// Counter used to generate IRK + uint8_t rand_cnt; + + /// Maximum device MTU size + uint16_t max_mtu; + ///DLE, the maximum number of payload octets in TX + uint16_t tx_pkt_size; + + //master device + uint8_t scan_actv_idx; + uint8_t init_actv_idx; + + // found the target near by + uint8_t target_found; + /// target device address type + uint8_t target_addr_type; + /// target device address going to connect + struct bd_addr target_addr; + + + //ble msg hanlder + void (*ble_msg_handler)(struct ble_msg_t const *); + //user msg handler + void (*user_msg_handler)(ke_msg_id_t const, void const *); + + #if (BLE_APP_NS_IUS) + uint8_t manual_conn_param_update; + uint8_t manual_mtu_update; + #endif + struct app_con_env_tag conn_env[APP_CON_IDX_MAX]; + + uint32_t rssi_intv; + uint8_t rssi_conidx; + ble_lsc_cfg_t lsc_cfg; + uint16_t iwdg_cycle; + bool wl_reconnect; +}; + + +/// Application GAP device infomation structure +struct ns_gap_params_t +{ + /// Attribute database configuration (@see enum gapm_att_cfg_flag) + uint16_t att_cfg; + /// Device role (@see enum gap_role) + uint8_t dev_role; + /// Device MAC address type (enum gapm_own_addr) + uint8_t mac_addr_type; + /// Device MAC address + struct bd_addr mac_addr; + /// Device appearance + uint16_t appearance; + /// Device Name length + uint8_t dev_name_len; + /// Device Name + uint8_t dev_name[APP_DEVICE_NAME_MAX_LEN]; + /// Device connection parameters + struct gapc_conn_param dev_conn_param; + /// Delay time of update connection parameters, 0 mean not active + uint16_t conn_param_update_delay; +}; + +struct adv_time_t +{ + uint8_t enable; + /// Advertising duration (in unit of 10ms). 0 means that advertising continues + /// until the host disable it + uint16_t duration; + /// advertising interval (in unit of 625us). Must be greater than 20ms + uint16_t adv_intv; +}; + +struct ns_adv_params_t +{ + void (*ble_adv_msg_handler)(enum app_adv_mode); + uint8_t adv_data[ADV_DATA_LEN]; + uint8_t adv_data_len; + uint8_t scan_rsp_data[ADV_DATA_LEN]; + uint8_t scan_rsp_data_len; + uint8_t attach_appearance; + uint8_t attach_name; + uint8_t adv_phy; + uint8_t ex_adv_enable; + uint8_t* ex_adv_p_data; + uint8_t ex_adv_data_len; + + // beacon mode without presence of AD_TYPE_FLAG in advertising data + uint8_t beacon_enable; + + struct adv_time_t directed_adv; + struct adv_time_t fast_adv; + struct adv_time_t slow_adv; +}; + +enum scan_state_t +{ + SCAN_STATE_IDLE = 0, + SCAN_STATE_SCANING, + SCAN_STATE_FOUND, + SCAN_STATE_CONNECTING, + SCAN_STATE_CONN_TIMEOUT, +}; + +enum scan_filter_type +{ + SCAN_FILTER_DISABLE = 0, + SCAN_FILTER_BY_ADDRESS, + SCAN_FILTER_BY_NAME, + SCAN_FILTER_BY_UUID128, + SCAN_FILTER_BY_UUID16, + SCAN_FILTER_BY_APPEARANCE, + + SCAN_FILTER_ALL, +}; +struct ns_scan_params_t +{ + /// Initiating type (@see enum gapm_init_type) + uint8_t type; + // if enable scan + uint8_t scan_enable :1; + // if connect the device if match + uint8_t connect_enable :1; + /// if use coded phy mode + uint8_t phy_coded_enable :1; + /// Properties for the scan active mode, enable will require scan respond data + uint8_t prop_active_enable :1; + /// Duplicate packet filtering policy + uint8_t dup_filt_pol :2; + /// Scan interval + uint16_t scan_intv; + /// Scan window + uint16_t scan_wd; + /// Scan duration (in unit of 10ms). 0 means that the controller will scan continuously until + /// reception of a stop command from the application + uint16_t duration; + /// Scan period (in unit of 1.28s). Time interval betweem two consequent starts of a scan duration + /// by the controller. 0 means that the scan procedure is not periodic + uint16_t period; + + uint32_t initiating_timeout; + + void (*ble_scan_state_handler)(enum scan_state_t); + void (*ble_scan_data_handler)(struct gapm_ext_adv_report_ind const*); + + enum scan_filter_type filter_type; + const uint8_t *filter_data; + +}; + + +struct ns_stack_cfg_t +{ + //ble msg hanlder + void (*ble_msg_handler)(struct ble_msg_t const *); + //user msg handler + void (*user_msg_handler)(ke_msg_id_t const, void const *); + //system lsc selected + ble_lsc_cfg_t lsc_cfg; + uint16_t iwdg_cycle; +}; + + +struct prf_task_t +{ + uint16_t prf_task_id; + struct app_subtask_handlers const* prf_task_handler; + +}; + +struct ns_ble_prf_evn_t +{ + uint8_t prf_num; + struct prf_task_t prf_task_list[BLE_NB_PROFILES]; +}; + + + +struct ns_ble_add_prf_evn_t +{ + uint8_t prf_num; + ns_ble_add_prf_func_t add_prf_func_list[BLE_NB_PROFILES]; +}; + + +/// Enumeration of TX/RX PHY values +enum ble_phy_val +{ + /// No preferred PHY + BLE_PHY_ANY = GAP_PHY_ANY, + /// LE 1M PHY (TX or RX) + BLE_PHY_1MBPS = GAP_PHY_LE_1MBPS, + /// LE 2M PHY (TX or RX) + BLE_PHY_2MBPS = GAP_PHY_LE_2MBPS, + /// LE Coded PHY (RX Only) + BLE_PHY_CODED = GAP_PHY_LE_CODED, + /// LE Coded PHY with S=8 data coding (TX Only) + BLE_PHY_500KBPS = GAP_PHY_LE_CODED|(GAPC_PHY_OPT_LE_CODED_500K_RATE << 4), + /// LE Coded PHY with S=2 data coding (TX Only) + BLE_PHY_125KBPS = GAP_PHY_LE_CODED|(GAPC_PHY_OPT_LE_CODED_125K_RATE << 4), +}; + +/* Public variables ---------------------------------------------------------*/ +/// Application environment +extern struct app_env_tag app_env; +extern struct ns_gap_params_t gap_env; +extern struct ns_adv_params_t adv_env; +extern struct ns_scan_params_t scan_env; +extern struct ns_ble_prf_evn_t ble_prf_evn; +/* Public function prototypes -----------------------------------------------*/ +void llhwc_modem_setmode(uint8_t phy); +bool ns_ble_add_svc(void); +void ns_ble_adv_fsm_next(void); + +//General function for master and slave +void ns_ble_resolv_addr(struct gap_sec_key *irk, uint8_t nb_key,struct bd_addr* addr); +void ns_ble_list_set_ral(struct gap_ral_dev_info *ral_list,uint8_t ral_cnt); +void ns_ble_list_set_wl(struct gap_bdaddr *wl_addr,uint8_t wl_cnt); +void ns_ble_set_channel_map( uint8_t* newchmap); +void ns_ble_set_slave_latency(uint16_t latency_cfg); +bool ns_ble_update_param(struct gapc_conn_param *conn_param); +void ns_ble_mtu_set(uint16_t mtu); +void ns_ble_phy_set(enum ble_phy_val phy); +void ns_ble_get_peer_info(uint8_t op); +void ns_ble_dle_set(uint16_t tx_octets, uint16_t tx_time); +void ns_ble_active_rssi(uint32_t interval); +void ns_ble_disconnect(void); +//stack and profile init function for master and slave +void ns_ble_lsc_config(ble_lsc_cfg_t lsc_set); +void ns_ble_stack_init(struct ns_stack_cfg_t const* p_handler); +void ns_ble_gap_init(struct ns_gap_params_t const* p_dev_info); +bool ns_ble_add_prf_func_register(ns_ble_add_prf_func_t func); +bool ns_ble_prf_task_register(struct prf_task_t *prf); + +//function for slave role +void ns_ble_adv_init(struct ns_adv_params_t const* p_adv_init); +void ns_ble_adv_start(void); +void ns_ble_adv_stop(void); +bool ns_ble_adv_data_set(uint8_t* p_dat, uint16_t len); +bool ns_ble_scan_rsp_data_set(uint8_t* p_dat, uint16_t len); +bool ns_ble_ex_adv_data_set(uint8_t* p_dat, uint16_t len); + +//function for master role +void ns_ble_scan_init(struct ns_scan_params_t *p_init); +void ns_ble_start_scan(void); +void ns_ble_delete_scan(void); +void ns_ble_stop_scan(void); +void ns_ble_start_init(uint8_t *addr, uint8_t addr_type); +void ns_ble_stop_init(void); +void ns_ble_delete_init(void); +bool ns_ble_scan_data_find(uint8_t types, const uint8_t *p_filter_data, uint8_t *p_data, uint8_t len); + + +void ns_ble_set_active_connection(uint8_t conidx); +uint8_t ns_ble_get_active_connection(void); +bool ns_ble_get_connection_state(uint8_t conidx); +uint8_t ns_ble_get_connection_num(void); +uint8_t ns_ble_get_conidx_by_role(uint8_t role); +uint8_t ns_ble_master_connection_num(void); +uint8_t ns_ble_slave_connection_num(void); + + +void ns_ble_prod_test_cmd_send(struct gapm_le_test_mode_ctrl_cmd *p_params, bool cw_mode); + +void ns_ble_radio_calibration(uint32_t fact_freq,uint32_t std_freq); +void ns_ble_radio_power_set(rf_tx_power_t tx_pwr); + +void ns_peripheral_config(void); +void ns_iwdg_reload(void); +void ns_iwdg_config(void); + +#define NS_WAKEUP_CONFIG() do{ns_iwdg_config(); }while(0) + +/// @} APP +/// + +#endif //(BLE_APP_PRESENT) + +#endif // _NS_BLE_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble_task.c new file mode 100644 index 0000000..15c6df3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble_task.c @@ -0,0 +1,1686 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble_task.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APPTASK + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration +#include "l2cm_int.h" +#if (BLE_APP_PRESENT) +#include "ns_ble_task.h" // Application Manager Task API +#include "ns_ble.h" // Application Manager Definition +#if (BLE_APP_SEC) +#include "ns_sec.h" // Security Module Definition +#endif //(BLE_APP_SEC) +#if (NS_TIMER_ENABLE) +#include "ns_timer.h" +#endif //NS_TIMER_ENABLE +#if (BLE_APP_NS_IUS) +#include "ns_dfu_ble.h" +#endif //BLE_APP_NS_IUS +#include "ns_sleep.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#ifndef CFG_PRF_GAP +#define CFG_PRF_GAP 1 +#endif + +#ifndef CFG_PRF_GATT +#define CFG_PRF_GATT 1 +#endif + + + +/* Private constants ---------------------------------------------------------*/ +#if (CFG_PRF_GAP) +/// GAP Attribute database description +static const struct attm_desc gapm_att_db[GAP_IDX_NUMBER] = +{ + // GAP_IDX_PRIM_SVC - GAP service + [GAP_IDX_PRIM_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0}, + // GAP_IDX_CHAR_DEVNAME - device name declaration + [GAP_IDX_CHAR_DEVNAME] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // GAP_IDX_DEVNAME - device name definition + [GAP_IDX_DEVNAME] = {ATT_CHAR_DEVICE_NAME, (PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE)), PERM(RI, ENABLE), GAP_MAX_NAME_SIZE}, + // GAP_IDX_CHAR_ICON - appearance declaration + [GAP_IDX_CHAR_ICON] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // GAP_IDX_ICON -appearance + [GAP_IDX_ICON] = {ATT_CHAR_APPEARANCE, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint16_t)}, + // GAP_IDX_CHAR_SLAVE_PREF_PARAM - Peripheral parameters declaration + [GAP_IDX_CHAR_SLAVE_PREF_PARAM] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // GAP_IDX_SLAVE_PREF_PARAM - Peripheral parameters definition + [GAP_IDX_SLAVE_PREF_PARAM] = {ATT_CHAR_PERIPH_PREF_CON_PARAM, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(struct gap_slv_pref)}, + // GAP_IDX_CHAR_ADDR_RESOL - Central Address Resolution declaration + [GAP_IDX_CHAR_CNT_ADDR_RESOL] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // GAP_IDX_ADDR_RESOL_SUPP - Central Address Resolution supported + [GAP_IDX_CNT_ADDR_RESOL] = {ATT_CHAR_CTL_ADDR_RESOL_SUPP, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, + // GAP_IDX_CHAR_RSLV_PRIV_ADDR_ONLY - Resolvable Private Address Only declaration + [GAP_IDX_CHAR_RSLV_PRIV_ADDR_ONLY] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + // GAP_IDX_CHAR_RSLV_PRIV_ADDR_ONLY - Resolvable Private Address Only declaration supported + [GAP_IDX_RSLV_PRIV_ADDR_ONLY] = {ATT_CHAR_RSLV_PRIV_ADDR_ONLY, PERM(RD, ENABLE), PERM(RI, ENABLE), sizeof(uint8_t)}, +}; +#endif +#if (CFG_PRF_GATT) +/// GATT Attribute database description +static const struct attm_desc gattm_att_db[GATT_IDX_NUMBER] = +{ + // GATT service + [GATT_IDX_PRIM_SVC] = { ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0 }, + + // Service Changed + [GATT_IDX_CHAR_SVC_CHANGED] = { ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0}, + [GATT_IDX_SVC_CHANGED] = { ATT_CHAR_SERVICE_CHANGED, PERM(IND, ENABLE), PERM(RI, ENABLE), sizeof(uint16_t) *2}, + [GATT_IDX_SVC_CHANGED_CFG] = { ATT_DESC_CLIENT_CHAR_CFG, (PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE)), 0, sizeof(uint16_t) }, + + // Client Supported Features + [GATT_IDX_CHAR_CLI_SUP_FEAT] = { ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0 }, + [GATT_IDX_CLI_SUP_FEAT] = { ATT_CHAR_CLI_SUP_FEAT, (PERM(RD, ENABLE)| PERM(WRITE_REQ, ENABLE)), PERM(RI, ENABLE), ATT_MAX_CLI_FEAT_LEN }, + + // Database Hash + [GATT_IDX_CHAR_DB_HASH] = { ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), 0, 0 }, + [GATT_IDX_DB_HASH] = { ATT_CHAR_DB_HASH, PERM(RD, ENABLE), PERM(RI, ENABLE), GAP_KEY_LEN }, +}; +#endif +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ + +static int gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *gattc_cmp_evt, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + + NS_LOG_DEBUG("%s status = %x, operation = %x\r\n",__func__,gattc_cmp_evt->status,gattc_cmp_evt->operation); + if(app_env.ble_msg_handler) + { + struct ble_msg_t ble_msg = {APP_BLE_NULL_MSG,NULL,NULL}; + ble_msg.msg_id = APP_BLE_GATTC_CMP_EVT; + ble_msg.msg.p_gattc_cmp = gattc_cmp_evt; + app_env.ble_msg_handler((void const*)&ble_msg); + } + switch(gattc_cmp_evt->operation) + { + case (GATTC_MTU_EXCH): + { + #if (BLE_APP_NS_IUS) + if(app_env.manual_mtu_update) + { + app_env.manual_mtu_update = 0; + ns_dfu_ble_handler_mtu_update(gattc_cmp_evt->status); + } + #endif + if (gattc_cmp_evt->status != ATT_ERR_NO_ERROR) + { + } + } + break; + case GATTC_NOTIFY: + + break; + case GATTC_INDICATE: + + break; + case (GATTC_DISC_ALL_SVC): + { + + }break; + + case (GATTC_DISC_ALL_CHAR): + { + + }break; + + case (GATTC_DISC_DESC_CHAR): + { + + }break; + + case (GATTC_WRITE_NO_RESPONSE): + { + NS_LOG_DEBUG("GATTC_WRITE_NO_RESPONSE CMP\r\n"); + + }break; + + case (GATTC_READ): + { + + }break; + default: + { + } + break; + } + + + return (KE_MSG_CONSUMED); +} + + + +static uint8_t app_get_handler(const struct app_subtask_handlers *handler_list_desc, + ke_msg_id_t msgid, + void *p_param, + ke_task_id_t src_id) +{ + // Counter + uint8_t counter; + NS_LOG_DEBUG("%s,sid:%d\r\n",__func__,src_id); + // Get the message handler function by parsing the message table + for (counter = handler_list_desc->msg_cnt; 0 < counter; counter--) + { + struct ke_msg_handler handler + = /*(struct ke_msg_handler)*/(*(handler_list_desc->p_msg_handler_tab + counter - 1)); + + if ((handler.id == msgid) || + (handler.id == KE_MSG_DEFAULT_HANDLER)) + { + // If handler is NULL, message should not have been received in this state + ASSERT_ERR(handler.func); + + return (uint8_t)(handler.func(msgid, p_param, TASK_APP, src_id)); + } + } + + // If we are here no handler has been found, drop the message + return (KE_MSG_CONSUMED); +} + + +/* + * MESSAGE HANDLERS + */ +#if (BLE_APP_PRF) +/** + * @brief Handles GAPM_ACTIVITY_CREATED_IND event + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapm_activity_created_ind_handler(ke_msg_id_t const msgid, + struct gapm_activity_created_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + if(p_param->actv_type == GAPM_ACTV_TYPE_ADV) + { + if (app_env.adv_state == APP_ADV_STATE_CREATING) + { + // Store the advertising activity index + app_env.adv_actv_idx = p_param->actv_idx; + } + } + else if(p_param->actv_type == GAPM_ACTV_TYPE_SCAN) + { + app_env.scan_actv_idx = p_param->actv_idx; + } + else if(p_param->actv_type == GAPM_ACTV_TYPE_INIT) + { + app_env.init_actv_idx = p_param->actv_idx; + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles GAPM_ACTIVITY_STOPPED_IND event. + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapm_activity_stopped_ind_handler(ke_msg_id_t const msgid, + struct gapm_activity_stopped_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + if(p_param->actv_type == GAPM_ACTV_TYPE_ADV) + { + NS_LOG_DEBUG("ADV STOP\r\n"); + if (app_env.adv_state == APP_ADV_STATE_STARTED) + { + // Act as if activity had been stopped by the application + app_env.adv_state = APP_ADV_STATE_STOPPING; + + // Perform next operation + ns_ble_adv_fsm_next(); + } + } + else if(p_param->actv_type == GAPM_ACTV_TYPE_SCAN) + { + NS_LOG_DEBUG("SCAN STOP:%d\r\n",app_env.scan_actv_idx); + if( app_env.scan_actv_idx != 0xFF) + { + ns_ble_delete_scan(); + app_env.scan_actv_idx = 0xFF; + + if(scan_env.ble_scan_state_handler != NULL) + { + scan_env.ble_scan_state_handler(SCAN_STATE_IDLE); + } + } + } + else if(p_param->actv_type == GAPM_ACTV_TYPE_INIT) + { + NS_LOG_DEBUG("INIT STOP:%d\r\n",app_env.init_actv_idx ); + if( app_env.init_actv_idx != 0xFF) + { + ns_ble_delete_init(); + app_env.init_actv_idx = 0xFF; + } + } + else + { + NS_LOG_DEBUG("OTHER STOP\r\n"); + } + + return (KE_MSG_CONSUMED); +} +#endif //(BLE_APP_PRF) + +/** + * @brief Handles GAPM_PROFILE_ADDED_IND event + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapm_profile_added_ind_handler(ke_msg_id_t const msgid, + struct gapm_profile_added_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + // Current State + ke_state_t state = ke_state_get(dest_id); + NS_LOG_DEBUG("%s,state %x\r\n", __func__,state); + + if (state == APP_CREATE_DB) + { + switch (p_param->prf_task_id) + { + + default: /* Nothing to do */ break; + } + } + else + { + ASSERT_INFO(0, state, src_id); + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles GAP manager command complete events. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapm_cmp_evt_handler(ke_msg_id_t const msgid, + struct gapm_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if(p_param->status != CO_ERROR_NO_ERROR) + { + NS_LOG_ERROR("%s, op = %x, status = %x\r\n", __func__, p_param->operation, p_param->status); + } + else{ + NS_LOG_DEBUG("%s, op = %x, status = %x\r\n", __func__, p_param->operation, p_param->status); + } + + switch(p_param->operation) + { + + // Reset completed + case (GAPM_RESET): + { + if(p_param->status == GAP_ERR_NO_ERROR) + { + + //reset prf_init + prf_init(RWIP_1ST_RST); + + //init peripheral + ns_peripheral_config(); + + // Set Device configuration + struct gapm_set_dev_config_cmd* p_cmd = KE_MSG_ALLOC(GAPM_SET_DEV_CONFIG_CMD, + TASK_GAPM, TASK_APP, + gapm_set_dev_config_cmd); + // Set the operation + p_cmd->operation = GAPM_SET_DEV_CONFIG; + #if (BLE_APP_PRF) + // Set the device role - Peripheral + p_cmd->role = gap_env.dev_role; + #endif //(BLE_APP_PRF) + + #if (BLE_APP_SEC_CON) + // The Max MTU is increased to support the Public Key exchange + // HOWEVER, with secure connections enabled you cannot sniff the + // LEAP and LEAS protocols + //p_cmd->max_mtu = app_env.rsp_max_mtu; + p_cmd->pairing_mode = GAPM_PAIRING_SEC_CON | GAPM_PAIRING_LEGACY; + #else // !(BLE_APP_SEC_CON) + // Do not support secure connections + p_cmd->pairing_mode = GAPM_PAIRING_LEGACY; + #endif //(BLE_APP_SEC_CON) + + // Set Data length parameters + p_cmd->sugg_max_tx_octets = 251; + p_cmd->max_mtu = 517; //app_env.rsp_max_mtu; + p_cmd->sugg_max_tx_time = 2120; + + p_cmd->att_cfg = gap_env.att_cfg; + + // Host privacy enabled by default + p_cmd->privacy_cfg = 0; + + memcpy(p_cmd->addr.addr,gap_env.mac_addr.addr,BD_ADDR_LEN); + // Check if address is a static random address + if (((gap_env.mac_addr.addr[5] & 0xC0) == 0xC0) && (!(gap_env.dev_role&GAP_ROLE_CENTRAL))) //central can't set PRIV + { + // Host privacy enabled by default + p_cmd->privacy_cfg |= GAPM_PRIV_CFG_PRIV_ADDR_BIT; + } + p_cmd->privacy_cfg |= GAPM_PRIV_CFG_PRIV_EN_BIT; + p_cmd->renew_dur = 36000;//900; + if (gap_env.mac_addr_type == GAPM_GEN_RSLV_ADDR) + { + memcpy(&p_cmd->irk.key[0], &app_env.loc_irk[0], KEY_LEN); + } + else + { + memset(&p_cmd->irk.key[0], 0x00, KEY_LEN); + } + if(app_env.ble_msg_handler) + { + struct ble_msg_t ble_msg = {APP_BLE_NULL_MSG,NULL,NULL}; + ble_msg.msg_id = APP_BLE_OS_READY; + ble_msg.msg.p_gapm_cmp = p_param; + ble_msg.cmd.p_dev_config = p_cmd; + app_env.ble_msg_handler((void const*)&ble_msg); + } + llhwc_modem_setmode(GAP_PHY_1MBPS); + // Send message + ke_msg_send(p_cmd); + + //init rand function + struct gapm_gen_rand_nb_cmd *p_rand_cmd = KE_MSG_ALLOC(GAPM_GEN_RAND_NB_CMD, + TASK_GAPM, TASK_APP, + gapm_gen_rand_nb_cmd); + p_rand_cmd->operation = GAPM_GEN_RAND_NB; + ke_msg_send(p_rand_cmd); + } + else + { + ASSERT_ERR(0); + } + } + break; + + // Device Configuration updated + case (GAPM_SET_DEV_CONFIG): + { + struct gap_ral_dev_info dev_info={0}; + #if (BLE_APP_SEC) + struct gap_bdaddr bond_addr={0}; + if (ns_sec_get_bond_status()==true) + { + ns_bond_last_bonded_ral_info(&dev_info); + ns_bond_last_bonded_addr(&bond_addr); + } + if ((ns_sec_get_bond_status()==true) && (dev_info.addr.addr_type == 0) && (bond_addr.addr_type != 0) ) + { + ns_ble_list_set_ral(&dev_info,1); + } + else + #endif + { + //use device addr to set ral list as defauft + memcpy(dev_info.addr.addr.addr,&gap_env.mac_addr,GAP_BD_ADDR_LEN); + dev_info.addr.addr_type = 0; + memcpy(dev_info.peer_irk,&app_env.loc_irk[0],GAP_KEY_LEN); + if (gap_env.mac_addr_type == GAPM_GEN_RSLV_ADDR) + { + memcpy(dev_info.local_irk,&app_env.loc_irk[0],GAP_KEY_LEN); + } + else + { + memset(dev_info.local_irk, 0, GAP_KEY_LEN); + } + ns_ble_list_set_ral(&dev_info,1); + } + } + break; + case (GAPM_SET_RAL): + { + if (!app_env.rand_cnt) + { + struct gapm_set_irk_cmd *p_cmd = KE_MSG_ALLOC(GAPM_SET_IRK_CMD, + TASK_GAPM, TASK_APP, + gapm_set_irk_cmd); + /// - GAPM_SET_IRK + p_cmd->operation = GAPM_SET_IRK; + if (gap_env.mac_addr_type == GAPM_GEN_RSLV_ADDR) + { + memcpy(&p_cmd->irk.key[0],&app_env.loc_irk[0], KEY_LEN); + } + else + { + memset(&p_cmd->irk.key[0], 0x00, KEY_LEN); + } + ke_msg_send(p_cmd); + } + app_env.rand_cnt = 0; + } break; + + case (GAPM_SET_IRK): + { + prf_init(RWIP_1ST_RST); + ASSERT_INFO(p_param->status == GAP_ERR_NO_ERROR, p_param->operation, p_param->status); + + // Go to the create db state + ke_state_set(TASK_APP, APP_CREATE_DB); + + uint8_t status = GAP_ERR_NO_ERROR; + + #if (CFG_PRF_GAP) + /* initialize GAP Start Handle */ + gapm_env.svc_start_hdl = 0x1; + uint32_t feat_gap = 0x001F;//| 0x0060 | 0x0180; + + if(GETF(gap_env.att_cfg, GAPM_ATT_SLV_PREF_CON_PAR_EN)) + { + feat_gap |= 0x0060; + } + if (gap_env.dev_role & GAP_ROLE_CENTRAL) + { + //if (param->privacy_cfg & GAPM_PRIV_CFG_PRIV_EN_BIT) + { + feat_gap |= 0x0180; + } + } + // Enable presence of Resolvable private address only characteristic. + if(GETF(gap_env.att_cfg, GAPM_ATT_RSLV_PRIV_ADDR_ONLY)) + { + feat_gap |= 0x0600; + } + + /* Create GAP Attribute Database */ + status = attm_svc_create_db(&(gapm_env.svc_start_hdl), ATT_SVC_GENERIC_ACCESS, (uint8_t*) &feat_gap, + GAP_IDX_NUMBER, NULL, TASK_GAPC, &gapm_att_db[0], + PERM(SVC_MI, ENABLE)); + + if(status != GAP_ERR_NO_ERROR) + { + break; + } + #endif // defined(CFG_PRF_GAP) + + #if (CFG_PRF_GATT) + /* initialize GATT Start Handle */ + gattm_env.svc_start_hdl = 0x0; + uint32_t feat_gatt = 0x00FF; + + /* Create GATT Attribute Database */ + status = attm_svc_create_db(&(gattm_env.svc_start_hdl), ATT_SVC_GENERIC_ATTRIBUTE, (uint8_t*) &feat_gatt, GATT_IDX_NUMBER, + NULL, TASK_GATTC, &gattm_att_db[0], PERM(SVC_MI, ENABLE)); + + if(status != GAP_ERR_NO_ERROR) + { + break; + } + #endif // defined(CFG_PRF_GATT) + (void)status; + // Add the first required service in the database + // and wait for the PROFILE_ADDED_IND + if (!ns_ble_add_svc()) + { + // Go to the ready state + ke_state_set(TASK_APP, APP_READY); + // No more service to add, start advertising or scan + if(app_env.adv_mode == APP_ADV_MODE_ENABLE) + { + ns_ble_adv_start(); + } + else{ + ns_ble_adv_stop(); + + //avoid adv and scan create at the same time + if(scan_env.scan_enable) + { + ns_ble_start_scan(); + } + } + } + } + break; + case (GAPM_PROFILE_TASK_ADD): + #if (BLE_APP_PRF) + { + // ASSERT_INFO(p_param->status == GAP_ERR_NO_ERROR, p_param->operation, p_param->status); + // If not Bonded already store the generated value in NVDS + #if(BLE_APP_SEC) + if (ns_sec_get_bond_status()==false) + { + } + #endif + app_env.rand_cnt = 0; + // Add the next requested service + if (!ns_ble_add_svc()) + { + // Go to the ready state + ke_state_set(TASK_APP, APP_READY); + // No more service to add, start advertising or scan + if(app_env.adv_mode == APP_ADV_MODE_ENABLE) + { + ns_ble_adv_start(); + } + else{ + ns_ble_adv_stop(); + + //avoid adv and scan create at the same time + if(scan_env.scan_enable) + { + ns_ble_start_scan(); + } + } + } + } + #endif // (BLE_APP_PRF) + break; + case (GAPM_RESOLV_ADDR): + { + #if (BLE_APP_SEC) + if(p_param->status != CO_ERROR_NO_ERROR) + { + //not match yet, resolv next addr + ns_bond_resolv_addr_start(&app_env.peer_addr,app_env.next_svc--); + } + #endif + } break; + + #if (BLE_APP_PRF) + + case (GAPM_START_ACTIVITY): + case (GAPM_DELETE_ACTIVITY): + case (GAPM_CREATE_ADV_ACTIVITY): + case (GAPM_SET_ADV_DATA): + case (GAPM_SET_SCAN_RSP_DATA): + case (GAPM_STOP_ACTIVITY): + { + //handle adv operation only + if( (app_env.current_op >= CURRENT_OP_CREATE_ADV) && + (app_env.current_op <= CURRENT_OP_DELETE_ADV)) + { + // Perform next operation + if (!((p_param->operation == GAPM_DELETE_ACTIVITY) && (app_env.adv_state != APP_ADV_STATE_IDLE))) + ns_ble_adv_fsm_next(); + } + + if(p_param->operation == GAPM_START_ACTIVITY || + p_param->operation == GAPM_DELETE_ACTIVITY) + { + //active advertising mode callback + switch (app_env.current_op) + { + case CURRENT_OP_START_ADV: + case CURRENT_OP_DELETE_ADV: + if(adv_env.ble_adv_msg_handler) + { + adv_env.ble_adv_msg_handler(app_env.adv_mode); + } + break; + case CURRENT_OP_START_SCAN: + if(scan_env.ble_scan_state_handler != NULL) + { + scan_env.ble_scan_state_handler(SCAN_STATE_SCANING); + } + break; + case CURRENT_OP_START_INIT: + if(scan_env.ble_scan_state_handler != NULL) + { + scan_env.ble_scan_state_handler(SCAN_STATE_CONNECTING); + } + break; + default: + break; + } + } + + } break; + + case (GAPM_DELETE_ALL_ACTIVITIES) : + { + // Re-Invoke Advertising + app_env.adv_state = APP_ADV_STATE_IDLE; + app_env.adv_actv_idx = 0xFF; + app_env.scan_actv_idx = 0xFF; + app_env.init_actv_idx = 0xFF; + } break; + #endif //(BLE_APP_PRF) + + case (GAPM_CREATE_SCAN_ACTIVITY): + { + if( (app_env.scan_actv_idx != 0xFF) && (p_param->status == CO_ERROR_NO_ERROR) ) + { + if(scan_env.scan_enable) + { + ns_ble_start_scan(); + } + } + else + { + ns_ble_delete_scan(); + } + } break; + + case (GAPM_CREATE_INIT_ACTIVITY): + { + if( (app_env.init_actv_idx != 0xFF) && (p_param->status == CO_ERROR_NO_ERROR) ) + { + if(app_env.target_found && scan_env.connect_enable ) + { + ns_ble_start_init(app_env.target_addr.addr, app_env.target_addr_type); + } + } + else + { + ns_ble_delete_init(); + } + } break; + + default: + { + // Drop the message + } + break; + } + + return (KE_MSG_CONSUMED); +} + + +/* + * @brief Handles GAPC_GET_DEV_INFO_REQ_IND event. + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * @return If the message was consumed or not. +*/ +static int gapc_get_dev_info_req_ind_handler(ke_msg_id_t const msgid, + struct gapc_get_dev_info_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s, req:%d\r\n",__func__,p_param->req); + switch(p_param->req) + { + case GAPC_DEV_NAME: + { + struct gapc_get_dev_info_cfm * cfm = KE_MSG_ALLOC_DYN(GAPC_GET_DEV_INFO_CFM, + src_id, dest_id, + gapc_get_dev_info_cfm, APP_DEVICE_NAME_MAX_LEN); + cfm->req = p_param->req; + cfm->info.name.length = gap_env.dev_name_len; + memcpy(cfm->info.name.value,gap_env.dev_name,gap_env.dev_name_len); + + // Send message + ke_msg_send(cfm); + } break; + + case GAPC_DEV_APPEARANCE: + { + // Allocate message + struct gapc_get_dev_info_cfm *cfm = KE_MSG_ALLOC(GAPC_GET_DEV_INFO_CFM, + src_id, dest_id, + gapc_get_dev_info_cfm); + cfm->req = p_param->req; + // Set the device appearance + // No appearance + cfm->info.appearance = gap_env.appearance; + // Send message + ke_msg_send(cfm); + } break; + + case GAPC_DEV_SLV_PREF_PARAMS: + { + // Allocate message + struct gapc_get_dev_info_cfm *cfm = KE_MSG_ALLOC(GAPC_GET_DEV_INFO_CFM, + src_id, dest_id, + gapc_get_dev_info_cfm); + cfm->req = p_param->req; + // Slave preferred Connection interval Min + cfm->info.slv_pref_params.con_intv_min = gap_env.dev_conn_param.intv_min; + // Slave preferred Connection interval Max + cfm->info.slv_pref_params.con_intv_max = gap_env.dev_conn_param.intv_max; + // Slave preferred Connection latency + cfm->info.slv_pref_params.slave_latency = gap_env.dev_conn_param.latency; + // Slave preferred Link supervision timeout + cfm->info.slv_pref_params.conn_timeout = gap_env.dev_conn_param.time_out; + + // Send message + ke_msg_send(cfm); + } break; + + default: /* Do Nothing */ break; + } + + return (KE_MSG_CONSUMED); +} + +#if (BLE_APP_PRF) +/** + * @brief Handles GAPC_SET_DEV_INFO_REQ_IND message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapc_set_dev_info_req_ind_handler(ke_msg_id_t const msgid, + struct gapc_set_dev_info_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + // Set Device configuration + struct gapc_set_dev_info_cfm* cfm = KE_MSG_ALLOC(GAPC_SET_DEV_INFO_CFM, src_id, dest_id, + gapc_set_dev_info_cfm); + NS_LOG_DEBUG("%s\r\n",__func__); + + gap_env.dev_name_len = p_param->info.name.length; + memcpy(gap_env.dev_name,p_param->info.name.value,p_param->info.name.length); + + cfm->status = GAP_ERR_NO_ERROR; + cfm->req = p_param->req; + // Send message + ke_msg_send(cfm); + + return (KE_MSG_CONSUMED); +} + +#endif //(BLE_APP_PRF) + +/** + * @brief Handles connection complete event from the GAP. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapc_connection_req_ind_handler(ke_msg_id_t const msgid, + struct gapc_connection_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_INFO("%s, sid:%d,conidx:%d\r\n",__func__,src_id,KE_IDX_GET(src_id)); + app_env.conidx = KE_IDX_GET(src_id); + + // Check if the received connection index is valid + if (app_env.conidx != GAP_INVALID_CONIDX) + { + // Allocate connection confirmation + struct gapc_connection_cfm *cfm = KE_MSG_ALLOC(GAPC_CONNECTION_CFM, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_connection_cfm); + + app_env.conn_env[app_env.conidx].conidx = app_env.conidx; + app_env.conn_env[app_env.conidx].conhdl = p_param->conhdl; + app_env.conn_env[app_env.conidx].peer_addr_type = p_param->peer_addr_type; + memcpy(app_env.conn_env[app_env.conidx].peer_addr.addr, p_param->peer_addr.addr, BD_ADDR_LEN); + if (p_param->role == ROLE_SLAVE) + { + app_env.conn_env[app_env.conidx].role = ROLE_SLAVE; + } + else if (p_param->role == ROLE_MASTER) + { + app_env.conn_env[app_env.conidx].role = ROLE_MASTER; + } + // Store received connection handle + app_env.conhdl = p_param->conhdl; + app_env.peer_addr_type = p_param->peer_addr_type; + memcpy(app_env.peer_addr.addr, p_param->peer_addr.addr, BD_ADDR_LEN); + + #if(BLE_APP_SEC) + if(ns_sec_get_bond_status()) + { + //set the addr solved task in next 5ms. + if (p_param->peer_addr_type == 1) + ke_msg_send_basic(GAPM_ADDR_SOLVED_IND,TASK_APP,TASK_APP); + switch (ns_sec_get_iocap()) + { + case GAP_IO_CAP_NO_INPUT_NO_OUTPUT: + cfm->pairing_lvl = GAP_PAIRING_BOND_UNAUTH; + break; + case GAP_IO_CAP_DISPLAY_ONLY: + case GAP_IO_CAP_DISPLAY_YES_NO: + case GAP_IO_CAP_KB_ONLY: + case GAP_IO_CAP_KB_DISPLAY: + #if (BLE_APP_SEC_CON) + cfm->pairing_lvl = GAP_PAIRING_BOND_SECURE_CON; + #else + cfm->pairing_lvl = GAP_PAIRING_BOND_AUTH; + #endif + break; + default: + cfm->pairing_lvl = GAP_PAIRING_NO_BOND; + break; + } + } + else + { + cfm->pairing_lvl = GAP_PAIRING_NO_BOND; + } + #else // !(BLE_APP_SEC) + cfm->pairing_lvl = GAP_PAIRING_NO_BOND; + #endif // (BLE_APP_SEC) + /*-------------------------------------------------------------- + * ENABLE REQUIRED PROFILES + *--------------------------------------------------------------*/ + + // We are now in connected State + ke_state_set(dest_id, APP_CONNECTED); + + //init MTU as 23 (user data len 20) + app_env.max_mtu = 23; + app_env.conn_env[app_env.conidx].max_mtu = 23; + if(scan_env.initiating_timeout) + { + ke_timer_clear(APP_INIT_TIMEOUT_EVT,TASK_APP); + } + //actiive connection params update timer + if(gap_env.conn_param_update_delay) + { + ke_timer_set(APP_PARAMS_UPDATE_EVT, TASK_APP, gap_env.conn_param_update_delay); + } + if(app_env.ble_msg_handler) + { + struct ble_msg_t ble_msg = {APP_BLE_NULL_MSG,NULL,NULL}; + ble_msg.msg_id = APP_BLE_GAP_CONNECTED; + ble_msg.msg.p_connection_ind = p_param; + ble_msg.cmd.p_connection_cfm = cfm; + app_env.ble_msg_handler((void const*)&ble_msg); + } + // Send the message + ke_msg_send(cfm); + } + else + { + #if (BLE_APP_PRF) + // No connection has been established, restart advertising + ns_ble_adv_start(); + + #endif //(BLE_APP_PRF) + } + return (KE_MSG_CONSUMED); +} +/** + * @brief Handles connection parameters update require event from the GAP. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapc_param_update_req_ind_handler(ke_msg_id_t const msgid, + struct gapc_param_update_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + + // Check if the received Connection Handle was valid + if (KE_IDX_GET(src_id) != GAP_INVALID_CONIDX) + { + // Send connection confirmation + struct gapc_param_update_cfm *cfm = KE_MSG_ALLOC(GAPC_PARAM_UPDATE_CFM, + KE_BUILD_ID(TASK_GAPC, KE_IDX_GET(src_id)), TASK_APP, + gapc_param_update_cfm); + //set default value + cfm->accept = true; + cfm->ce_len_min = 2; + cfm->ce_len_max = 0x140; + if(app_env.ble_msg_handler) + { + //call user code + struct ble_msg_t ble_msg = {APP_BLE_NULL_MSG,NULL,NULL}; + ble_msg.msg_id = APP_BLE_GAP_PARAMS_REQUEST; + ble_msg.msg.p_param_req = p_param; + ble_msg.cmd.p_param_cfm = cfm; + app_env.ble_msg_handler((void const*)&ble_msg); + } + + // Send message + ke_msg_send(cfm); + } + else + { +#if (BLE_APP_PRF) + // No connection has been established, restart advertising + ns_ble_adv_start(); +#endif // (BLE_APP_PRF) + } + + return (KE_MSG_CONSUMED); +} + +#if (BLE_APP_PRF) +/** + * @brief Handles GAP controller command complete events. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gapc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s, operation =%x status = %x\r\n", __func__,p_param->operation, p_param->status); + if(app_env.ble_msg_handler) + { + struct ble_msg_t ble_msg = {APP_BLE_NULL_MSG,NULL,NULL}; + ble_msg.msg_id = APP_BLE_GAP_CMP_EVT; + ble_msg.msg.p_gapc_cmp = p_param; + app_env.ble_msg_handler((void const*)&ble_msg); + } + + switch(p_param->operation) + { + case (GAPC_UPDATE_PARAMS): + { + #if (BLE_APP_NS_IUS) + if(app_env.manual_conn_param_update) + { + app_env.manual_conn_param_update = 0; + ns_dfu_ble_handler_conn_param_update(p_param->status); + } + #endif + } + case (GAPC_SET_LE_PKT_SIZE): + { + if (p_param->status != GAP_ERR_NO_ERROR) + { + } + }break; + + case (GAPC_SECURITY_REQ): + { + if (p_param->status == GAP_ERR_NO_ERROR) + { + } + else + { + } + } + break; + + case (GAPC_GET_PEER_FEATURES): + { + + } break; + + case (GAPC_GET_PEER_VERSION): + { + + } break; + + default: + { + } + break; + } + + return (KE_MSG_CONSUMED); +} +#endif //(BLE_APP_PRF) + +/** + * @brief Handles disconnection complete event from the GAP. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapc_disconnect_ind_handler(ke_msg_id_t const msgid, + struct gapc_disconnect_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + NS_LOG_INFO("BLE Disconnected,reson:%x,conidx:%d \r\n",p_param->reason,KE_IDX_GET(src_id)); + + app_env.conn_env[KE_IDX_GET(src_id)].conidx = GAP_INVALID_CONIDX; + if(ns_ble_get_connection_num() == 0) + { + ke_state_set(TASK_APP, APP_READY);// Go to the ready state + } + if(app_env.ble_msg_handler) + { + struct ble_msg_t ble_msg = {APP_BLE_NULL_MSG,NULL,NULL}; + ble_msg.msg_id = APP_BLE_GAP_DISCONNECTED; + ble_msg.msg.p_disconnect_ind = p_param; + app_env.ble_msg_handler((void const*)&ble_msg); + } + memset (&app_env.peer_irk.key,0,GAP_KEY_LEN); + if(l2cm_env.con_tx_state) + { + ke_event_set(KE_EVENT_L2CAP_TX); + } + return (KE_MSG_CONSUMED); +} + + +/** + * @brief Handles reception of all messages sent from the lower layers to the application + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_msg_handler(ke_msg_id_t const msgid, + void *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id, + enum ke_msg_status_tag *msg_ret) +{ + + // Retrieve identifier of the task from received message + ke_task_id_t src_task_id = MSG_T(msgid); + // Message policy + uint8_t msg_pol = KE_MSG_CONSUMED; + + NS_LOG_DEBUG("%s, task = %x, msg = %x \r\n",__func__, src_task_id,MSG_I(msgid)); + + //for ns sec + if(src_task_id == TASK_ID_GAPC) + { + #if (BLE_APP_SEC) + if ((msgid >= GAPC_BOND_CMD) && + (msgid <= GAPC_SECURITY_IND)) + { + // Call the Security Module + msg_pol = app_get_handler(&app_sec_handlers, msgid, p_param, src_id); + } + #endif //(BLE_APP_SEC) + } + else{ + //app prf sub task + for(uint8_t id = 0; id < ble_prf_evn.prf_num;id++) + { + //find the prf task id + if(src_task_id == ble_prf_evn.prf_task_list[id].prf_task_id ) + { + //found prf + msg_pol = app_get_handler(ble_prf_evn.prf_task_list[id].prf_task_handler, msgid, p_param, src_id); + } + } + } + + return (msg_pol); +} + +#if (BLE_APP_PRF) +/** + * @brief Handles reception of random number generated message + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapm_gen_rand_nb_ind_handler(ke_msg_id_t const msgid, struct gapm_gen_rand_nb_ind *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + + NS_LOG_DEBUG("%s\r\n",__func__); + + //init rand function + uint32_t real_rand; + memcpy(&real_rand, &p_param->randnb.nb[0], 4); + srand(real_rand); + return (KE_MSG_CONSUMED); +} + + +static int gapm_addr_solved_ind_handler(ke_msg_id_t const msgid, + struct gapm_addr_solved_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,src:%d\r\n",__func__,src_id); + if(src_id == TASK_APP) //ke msg + { + //start solved + ns_bond_search_addr_irk(&(app_env.peer_addr),app_env.peer_addr_type); + } + else + { + memcpy(app_env.peer_irk.key,p_param->irk.key ,GAP_KEY_LEN); + #if 0 //debug + NS_LOG_DEBUG("This mac solved:%02X %02X %02X %02X %02X %02X \r\n", + p_param->addr.addr[0], + p_param->addr.addr[1], + p_param->addr.addr[2], + p_param->addr.addr[3], + p_param->addr.addr[4], + p_param->addr.addr[5]); + NS_LOG_DEBUG("This irk:"); + for(uint8_t i = 0; iirk.key[i]); + } + NS_LOG_DEBUG("\r\n"); + #endif + } + + + return (KE_MSG_CONSUMED); +} +#endif //(BLE_APP_PRF) + +static int gapc_param_updated_ind_handler(ke_msg_id_t const msgid, + struct gapc_param_updated_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,%d,%d,%d\r\n",__func__,p_param->con_interval,p_param->con_latency,p_param->sup_to); + if(app_env.ble_msg_handler) + { + struct ble_msg_t ble_msg = {APP_BLE_NULL_MSG,NULL,NULL}; + ble_msg.msg_id = APP_BLE_GAP_PARAMS_IND; + ble_msg.msg.p_param_updated = p_param; + app_env.ble_msg_handler((void const*)&ble_msg); + } + return (KE_MSG_CONSUMED); +} + +static int gapc_le_pkt_size_ind_handler(ke_msg_id_t const msgid, + struct gapc_le_pkt_size_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + app_env.tx_pkt_size = p_param->max_tx_octets; + app_env.conn_env[KE_IDX_GET(src_id)].tx_pkt_size = p_param->max_tx_octets; + return (KE_MSG_CONSUMED); +} + +static int gattc_mtu_changed_ind_handler(ke_msg_id_t const msgid, + struct gattc_mtu_changed_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + NS_LOG_DEBUG("%s,mtu:%x, num:%x \r\n",__func__, p_param->mtu,p_param->seq_num); + app_env.max_mtu = p_param->mtu; + app_env.conn_env[KE_IDX_GET(src_id)].max_mtu = p_param->mtu; + + if(app_env.ble_msg_handler) + { + struct ble_msg_t ble_msg = {APP_BLE_NULL_MSG,NULL,NULL}; + ble_msg.msg_id = APP_BLE_GATTC_MTU_IND; + ble_msg.msg.p_gattc_mtu = p_param; + app_env.ble_msg_handler((void const*)&ble_msg); + } + //fix to set mut again + extern struct gattc_env_tag* gattc_env[]; + if(gattc_env[KE_IDX_GET(src_id)] != NULL) + { + gattc_env[KE_IDX_GET(src_id)]->mtu_exch = false; + } + return (KE_MSG_CONSUMED); +} + +static int gapc_le_phy_ind_handler(ke_msg_id_t const msgid, + struct gapc_le_phy_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + NS_LOG_INFO("tx_phy:%d, rx_phy:%d\r\n",p_param->tx_phy,p_param->rx_phy); + + llhwc_modem_setmode(p_param->tx_phy); + + return (KE_MSG_CONSUMED); +} + + +/** + * @brief Handles user define update connection params + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_conn_params_update_evt_handler(ke_msg_id_t const msgid, void *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + + NS_LOG_DEBUG("%s\r\n",__func__); + + ns_ble_update_param(&gap_env.dev_conn_param); + + return (KE_MSG_CONSUMED); +} + + +#if NS_LSI_CALIB_EN +/** + * @brief Handles user lsi calib + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_lsi_calib_evt_handler(ke_msg_id_t const msgid, void *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + static uint16_t calib_times = LSI_CLOCK_CALIB_TIMES; + if((RCC->OSCFCSR) & 0x01) + { + uint32_t lsicnt = RCC->OSCFCLSICNT; + extern uint32_t g_lsi_1_syscle_cal_value; + int32_t lpc_dif = lsicnt - (LSI_CLOCK_CNT_CYCLES*g_lsi_1_syscle_cal_value); + calib_times--; + if(lpc_dif < -600 || lpc_dif > 600) + { + NS_LOG_DEBUG("lsi config,%d,%d \r\n",lsicnt,lpc_dif); + calib_times=0; + //config lis + RCC->LSCTRL &= ~1; //off lsi + if((*(uint32_t*)0x40011000) & 0xC000) + { + *(uint32_t*)0x40011000 &= ~0xC000; + } + else + { + *(uint32_t*)0x40011000 |= 0xC000; + } + ns_ble_lsc_config(app_env.lsc_cfg); + } + } + + if(calib_times) + { + RCC->OSCFCCR |= 1; + ke_timer_set(APP_LSI_CALIB_EVT,TASK_APP,LSI_CLOCK_EVENT_INTV); + } + else + { + RCC->OSCFCCR &= ~(0xFF<< 8); + RCC->OSCFCCR |= (20 <<8); //write count n syscle + RCC->OSCFCCR |= 1; + ns_sleep_lock_release(); //release when lsi calib finsh + } + + return (KE_MSG_CONSUMED); +} +#endif + +/** + * @brief Handles rssi event from the GAP. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapc_conn_rssi_ind_handler(ke_msg_id_t const msgid, + struct gapc_con_rssi_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + if(src_id != 0xff) + { + NS_LOG_DEBUG("RSSI = %d\r\n", param->rssi); + if(app_env.ble_msg_handler) + { + struct ble_msg_t ble_msg = {APP_BLE_NULL_MSG,NULL,NULL}; + ble_msg.msg_id = APP_BLE_GAP_RSSI_IND; + ble_msg.msg.p_gapc_rssi = param; + app_env.ble_msg_handler((void const*)&ble_msg); + } + + if(ke_state_get(TASK_APP) == APP_CONNECTED) + { + if(app_env.rssi_intv) + { + //active this event again + ke_timer_set(GAPC_CON_RSSI_IND,TASK_APP,app_env.rssi_intv); + } + } + } + else{ + //repeat get rssi event + struct gapc_get_info_cmd* info_cmd = KE_MSG_ALLOC(GAPC_GET_INFO_CMD, + KE_BUILD_ID(TASK_GAPC, app_env.rssi_conidx), TASK_APP, + gapc_get_info_cmd); + + // request RSSI + info_cmd->operation = GAPC_GET_CON_RSSI; + // send command + ke_msg_send(info_cmd); + } + return (KE_MSG_CONSUMED); +} + + +int app_entry_point_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + enum ke_msg_status_tag process_msg_handling_result; + + //add others user handler + +#if (NS_TIMER_ENABLE) + ns_timer_api_process_handler(msgid, param, dest_id, src_id,&process_msg_handling_result); + if(process_msg_handling_result == KE_MSG_CONSUMED) + return (KE_MSG_CONSUMED); +#endif //NS_TIMER_ENABLE + + app_msg_handler(msgid, (void *)param, dest_id, src_id, &process_msg_handling_result); + if(process_msg_handling_result == KE_MSG_CONSUMED) + return (KE_MSG_CONSUMED); + + //keep it as last event handler + if(app_env.user_msg_handler) + { + app_env.user_msg_handler(msgid, param); + } + + return (KE_MSG_CONSUMED); +} + + + +/** + * @brief Handles adv repoer of scan result. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapm_ext_adv_repoer_ind_handler(ke_msg_id_t const msgid, struct gapm_ext_adv_report_ind const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + bool target_found = false; + NS_LOG_DEBUG("\r\nReport %x, ", param->trans_addr.addr_type); + for(int i = 0; i < 6; i++) + { + NS_LOG_DEBUG("%02x ", param->trans_addr.addr.addr[i]); + } + switch (scan_env.filter_type) + { + case SCAN_FILTER_DISABLE: + target_found = true; + break; + case SCAN_FILTER_BY_ADDRESS: + if(memcmp((uint8_t *)param->trans_addr.addr.addr, scan_env.filter_data, 6) == 0) + { + target_found = true; + } + break; + case SCAN_FILTER_BY_NAME: + if(ns_ble_scan_data_find(GAP_AD_TYPE_COMPLETE_NAME,scan_env.filter_data,(uint8_t*)param->data,param->length)) + { + target_found = true; + } + break; + case SCAN_FILTER_BY_UUID128: + if(ns_ble_scan_data_find(GAP_AD_TYPE_SERVICE_128_BIT_DATA,scan_env.filter_data,(uint8_t*)param->data,param->length)) + { + target_found = true; + } + break; + case SCAN_FILTER_BY_UUID16: + if(ns_ble_scan_data_find(GAP_AD_TYPE_SERVICE_16_BIT_DATA,scan_env.filter_data,(uint8_t*)param->data,param->length)) + { + target_found = true; + } + break; + case SCAN_FILTER_BY_APPEARANCE: + if(ns_ble_scan_data_find(GAP_AD_TYPE_APPEARANCE,scan_env.filter_data,(uint8_t*)param->data,param->length)) + { + target_found = true; + } + break; + default: + break; + } + if(!app_env.target_found) + { + if(scan_env.ble_scan_data_handler != NULL) + { + scan_env.ble_scan_data_handler(param); + } + if(target_found) + { + NS_LOG_DEBUG("Found target device\r\n"); + if(scan_env.ble_scan_state_handler != NULL) + { + scan_env.ble_scan_state_handler(SCAN_STATE_FOUND); + } + ns_ble_stop_scan(); + ns_ble_start_init((uint8_t*)param->trans_addr.addr.addr, param->trans_addr.addr_type); + + } + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles scan request event from GAPM. Need to config GAPM_ADV_PROP_SCAN_REQ_NTF_EN_BIT in adv create + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int gapm_scan_request_ind_handler(ke_msg_id_t const msgid, struct gapm_scan_request_ind const *param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("\r\nReport %x, ", param->trans_addr.addr_type); + for(int i = 0; i < 6; i++) + { + NS_LOG_DEBUG("%02x ", param->trans_addr.addr.addr[i]); + } + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles timeout of master establishing a connection, it will stop init a + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_init_timeout_evt_handler(ke_msg_id_t const msgid, void *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + ns_ble_stop_init(); + if(scan_env.ble_scan_state_handler != NULL) + { + scan_env.ble_scan_state_handler(SCAN_STATE_CONN_TIMEOUT); + } + return (KE_MSG_CONSUMED); +} + +/* + * GLOBAL VARIABLES DEFINITION + */ +#if (BLE_APP_NS_IUS) +extern int app_dfu_ble_reset_handler(ke_msg_id_t const msgid, void const *p_param, ke_task_id_t const dest_id, ke_task_id_t const src_id); +#endif +/* Default State handlers definition. */ +KE_MSG_HANDLER_TAB(app) +{ + + // Note: first message is latest message checked by kernel so default is put on top. + {KE_MSG_DEFAULT_HANDLER, (ke_msg_func_t)app_entry_point_handler}, + + // GAPM messages + {GAPM_ACTIVITY_CREATED_IND, (ke_msg_func_t)gapm_activity_created_ind_handler}, + {GAPM_ACTIVITY_STOPPED_IND, (ke_msg_func_t)gapm_activity_stopped_ind_handler}, + {GAPM_GEN_RAND_NB_IND, (ke_msg_func_t)gapm_gen_rand_nb_ind_handler}, + {GAPM_ADDR_SOLVED_IND, (ke_msg_func_t)gapm_addr_solved_ind_handler}, + {GAPM_CMP_EVT, (ke_msg_func_t)gapm_cmp_evt_handler}, + {GAPM_PROFILE_ADDED_IND, (ke_msg_func_t)gapm_profile_added_ind_handler}, + {GAPM_EXT_ADV_REPORT_IND, (ke_msg_func_t)gapm_ext_adv_repoer_ind_handler}, + {GAPM_SCAN_REQUEST_IND, (ke_msg_func_t)gapm_scan_request_ind_handler}, + // GATTC messages + {GATTC_MTU_CHANGED_IND, (ke_msg_func_t)gattc_mtu_changed_ind_handler}, + {GATTC_CMP_EVT, (ke_msg_func_t)gattc_cmp_evt_handler}, + + // GAPC messages + {GAPC_CONNECTION_REQ_IND, (ke_msg_func_t)gapc_connection_req_ind_handler}, + {GAPC_PARAM_UPDATE_REQ_IND, (ke_msg_func_t)gapc_param_update_req_ind_handler}, + {GAPC_PARAM_UPDATED_IND, (ke_msg_func_t)gapc_param_updated_ind_handler}, + {GAPC_LE_PKT_SIZE_IND, (ke_msg_func_t)gapc_le_pkt_size_ind_handler}, + {GAPC_DISCONNECT_IND, (ke_msg_func_t)gapc_disconnect_ind_handler}, + {GAPC_GET_DEV_INFO_REQ_IND, (ke_msg_func_t)gapc_get_dev_info_req_ind_handler}, + {GAPC_LE_PHY_IND, (ke_msg_func_t)gapc_le_phy_ind_handler}, + {GAPC_SET_DEV_INFO_REQ_IND, (ke_msg_func_t)gapc_set_dev_info_req_ind_handler}, + {GAPC_CMP_EVT, (ke_msg_func_t)gapc_cmp_evt_handler}, + {GAPC_CON_RSSI_IND, (ke_msg_func_t)gapc_conn_rssi_ind_handler}, + + #if NS_LSI_CALIB_EN + {APP_LSI_CALIB_EVT, (ke_msg_func_t)app_lsi_calib_evt_handler}, + #endif + {APP_PARAMS_UPDATE_EVT, (ke_msg_func_t)app_conn_params_update_evt_handler}, + {APP_INIT_TIMEOUT_EVT, (ke_msg_func_t)app_init_timeout_evt_handler}, + + #if (BLE_APP_SEC) + {APP_BOND_STORE_EVT, (ke_msg_func_t)ns_sec_bond_store_evt_handler}, + #endif //(BLE_APP_SEC) + #if (BLE_APP_NS_IUS) + {APP_DFU_BLE_RESET_TIMER, (ke_msg_func_t)app_dfu_ble_reset_handler}, + #endif + +}; + +/* Defines the place holder for the states of all the task instances. */ +ke_state_t app_state[APP_IDX_MAX]; + +// Application task descriptor +const struct ke_task_desc TASK_DESC_APP_M = {app_msg_handler_tab, app_state, APP_IDX_MAX, ARRAY_LEN(app_msg_handler_tab)}; + +#endif //(BLE_APP_PRESENT) + +/// @} APPTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble_task.h new file mode 100644 index 0000000..dc8acaa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble_task.h @@ -0,0 +1,165 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble_task.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _NS_BLE_TASK_H_ +#define _NS_BLE_TASK_H_ + +/** + * @addtogroup APPTASK Task + * @ingroup APP + * @brief Routes ALL messages to/from APP block. + * + * The APPTASK is the block responsible for bridging the final application with the + * RWBLE software host stack. It communicates with the different modules of the BLE host, + * i.e. @ref SMP, @ref GAP and @ref GATT. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_PRESENT) +#include "global_func.h" + +/* Define ------------------------------------------------------------*/ + +/// Number of APP Task Instances +#define APP_IDX_MAX (1) + + +#ifndef NS_LSI_CALIB_EN +#define NS_LSI_CALIB_EN 1 +#endif +#define LSI_CLOCK_CNT_CYCLES (126) +#define LSI_CLOCK_EVENT_INTV (5) //1000/(32000/126) +#define LSI_CLOCK_CALIB_TIMES (500) +/* Typedef -----------------------------------------------------------*/ + + /// Process event response +enum process_event_response +{ + /// Handled + PR_EVENT_HANDLED = 0, + + /// Unhandled + PR_EVENT_UNHANDLED +}; + + +/// States of APP task +enum app_state +{ + /// Initialization state + APP_INIT, + /// Database create state + APP_CREATE_DB, + /// Ready State + APP_READY, + /// Connected state + APP_CONNECTED, + + /// Number of defined states. + APP_STATE_MAX +}; + + +/// APP Task messages +/*@TRACE*/ +enum app_msg_id +{ + APP_DUMMY_MSG = TASK_FIRST_MSG(TASK_ID_APP), + APP_LSI_CALIB_EVT, + APP_PARAMS_UPDATE_EVT, + APP_INIT_TIMEOUT_EVT, + APP_BOND_STORE_EVT, + #if (BLE_APP_NS_IUS) + APP_DFU_BLE_RESET_TIMER, + #endif + #if (NS_TIMER_ENABLE) + /*ns timer*/ + APP_CANCEL_TIMER, + APP_MODIFY_TIMER, + //Do not alter the order of the next messages + //they are considered a range + NS_TIMER_API_MES0, + NS_TIMER_API_MES1=NS_TIMER_API_MES0+1, + NS_TIMER_API_MES2=NS_TIMER_API_MES0+2, + NS_TIMER_API_MES3=NS_TIMER_API_MES0+3, + NS_TIMER_API_MES4=NS_TIMER_API_MES0+4, + NS_TIMER_API_MES5=NS_TIMER_API_MES0+5, + NS_TIMER_API_MES6=NS_TIMER_API_MES0+6, + NS_TIMER_API_MES7=NS_TIMER_API_MES0+7, + NS_TIMER_API_MES8=NS_TIMER_API_MES0+8, + NS_TIMER_API_MES9=NS_TIMER_API_MES0+9, + NS_TIMER_API_LAST_MES=NS_TIMER_API_MES9, + #endif //NS_TIMER_ENABLE + + //keep APP_FREE_EVE_FOR_USER as last event + APP_FREE_EVE_FOR_USER, + +}; + + +/* Public variables ---------------------------------------------------------*/ + +/// @} APPTASK + +#endif //(BLE_APP_PRESENT) + +#endif // _NS_BLE_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/delay/ns_delay.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/delay/ns_delay.h new file mode 100644 index 0000000..9bed344 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/delay/ns_delay.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_delay.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef __NS_DELAY_H__ +#define __NS_DELAY_H__ + +/* Includes ------------------------------------------------------------------*/ +#include // standard boolean definitions +#include // standard integer functions +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief delay in cycles which is running 4 asm instructions in (10/110) us + * @param ui32Cycles delay time in (10/110) us + * @return + * @note + */ +void delay_cycles(uint32_t ui32Cycles); + +/** + * @brief delay in 10us + * @param val delay time in 10us + * @return + * @note + */ +void delay_n_10us(uint32_t val); + +/** + * @brief delay in ms + * @param val delay time in ms + * @return + * @note + */ +void delay_n_ms(uint32_t val); + +/** + * @brief delay in us + * @param val delay time in us + * @return + * @note + */ +void delay_n_us(uint32_t val); + + +#endif //__NS_DELAY_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_ble.c new file mode 100644 index 0000000..0ee2df7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_ble.c @@ -0,0 +1,482 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_dfu_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "ns_dfu_ble.h" +#include +#include +#include +#include "ke_timer.h" +#include "ns_ble.h" +#include "ns_ble_task.h" +#include "ns_dfu_boot.h" +#include "ns_error.h" +#include "ns_log.h" +#include "dfu_crc.h" +#include "dfu_delay.h" +/* Private typedef -----------------------------------------------------------*/ +static struct{ + uint32_t total_size; + uint32_t address; + uint32_t offset; + uint32_t size; + uint32_t crc; +}m_ota_image; +/* Private define ------------------------------------------------------------*/ +#define OTA_ECC_ECDSA_SHA256_ENABLE 1 + +#if OTA_ECC_ECDSA_SHA256_ENABLE +#include "ns_ecc.h" +#endif + +#define OTA_CMD_CONN_PARAM_UPDATE 1 +#define OTA_CMD_MTU_UPDATE 2 +#define OTA_CMD_VERSION 3 +#define OTA_CMD_CREATE_OTA_SETTING 4 +#define OTA_CMD_CREATE_OTA_IMAGE 5 +#define OTA_CMD_VALIDATE_OTA_IMAGE 6 +#define OTA_CMD_ACTIVATE_OTA_IMAGE 7 +#define OTA_CMD_JUMP_IMAGE_UPDATE 8 + +#define OTA_RC_STATE_NONE 0 +#define OTA_RC_STATE_DFU_SETTING 1 +#define OTA_RC_STATE_DFU_IMAGE 2 +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static uint8_t m_rc_state = OTA_RC_STATE_NONE; +static Dfu_setting_t m_dfu_setting; +static uint8_t m_buffer[2048]; +static uint32_t rc_mtu_offset = 0; +static uint8_t ota_selection = 0; +static uint32_t m_ota_setting_size = 0; +/* Private function prototypes -----------------------------------------------*/ +extern void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length); +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Processing and handling ius service cc characteristic data. + * @param[in] input data to process. + * @param[in] input_len data length. + * @param[out] output response data. + * @param[out] output_len response data length. + * @return none + */ +void ns_dfu_ble_handler_cc(uint8_t const *input, uint8_t input_len, uint8_t *output, uint8_t *output_len) +{ + + switch(input[0]){ + + case OTA_CMD_CONN_PARAM_UPDATE:{ + struct gapc_conn_param conn_param; + conn_param.intv_min = input[1]<<8 | input[2]; + conn_param.intv_max = input[3]<<8 | input[4]; + conn_param.latency = input[5]<<8 | input[6]; + conn_param.time_out = input[7]<<8 | input[8]; + app_env.manual_conn_param_update = 1; + ns_ble_update_param(&conn_param); + *output_len = 0; + }break; + case OTA_CMD_MTU_UPDATE:{ + app_env.manual_mtu_update = 1; + ns_ble_mtu_set(input[1]<<8 | input[2]); + *output_len = 0; + }break; + + case OTA_CMD_VERSION:{ + rc_mtu_offset = 0; + memset(&m_ota_image,0,sizeof(m_ota_image)); + uint32_t new_app1_size = input[1]<<24 | input[2]<<16 | input[3]<<8 | input[4]; + uint32_t new_app2_size = input[5]<<24 | input[6]<<16 | input[7]<<8 | input[8]; + uint32_t new_image_update_size = input[9]<<24 | input[10]<<16 | input[11]<<8 | input[12]; + uint32_t new_image_update_version = input[13]<<24 | input[14]<<16 | input[15]<<8 | input[16]; + + + #ifdef APPLICATION + + ota_selection = 0; + + if(CURRENT_APP_START_ADDRESS == NS_APP1_START_ADDRESS){ + if(ns_bootsetting.app1.size > NS_APP1_DEFAULT_SIZE || new_app1_size > NS_APP1_DEFAULT_SIZE || new_app2_size == 0){ + if(ns_bootsetting.ImageUpdate.crc == dfu_crc32((uint8_t *)((uint32_t *)ns_bootsetting.ImageUpdate.start_address), ns_bootsetting.ImageUpdate.size)){ + if(new_image_update_version > ns_bootsetting.ImageUpdate.version){ + ota_selection = 3; + m_ota_image.total_size = new_image_update_size; + m_ota_image.address = NS_IMAGE_UPDATE_START_ADDRESS; + }else{ + ota_selection = 4; + } + }else + { + ota_selection = 3; + m_ota_image.total_size = new_image_update_size; + m_ota_image.address = NS_IMAGE_UPDATE_START_ADDRESS; + } + }else{ + ota_selection = 2; + m_ota_image.total_size = new_app2_size; + m_ota_image.address = NS_APP2_START_ADDRESS; + } + }else if(CURRENT_APP_START_ADDRESS == NS_APP2_START_ADDRESS){ + if(new_app1_size > NS_APP1_DEFAULT_SIZE){ + if(ns_bootsetting.ImageUpdate.crc == dfu_crc32((uint8_t *)((uint32_t *)ns_bootsetting.ImageUpdate.start_address), ns_bootsetting.ImageUpdate.size)){ + if(new_image_update_version > ns_bootsetting.ImageUpdate.version){ + ota_selection = 3; + m_ota_image.total_size = new_image_update_size; + m_ota_image.address = NS_IMAGE_UPDATE_START_ADDRESS; + }else{ + ota_selection = 4; + } + }else{ + ota_selection = 3; + m_ota_image.total_size = new_image_update_size; + m_ota_image.address = NS_IMAGE_UPDATE_START_ADDRESS; + } + }else{ + ota_selection = 1; + m_ota_image.total_size = new_app1_size; + m_ota_image.address = NS_APP1_START_ADDRESS; + } + } + #else + (void)new_app2_size; + (void)new_image_update_size; + (void)new_image_update_version; + #endif + + + #ifdef IMAGE_UPDATE + m_ota_image.total_size = new_app1_size; + m_ota_image.address = NS_APP1_START_ADDRESS; + ota_selection = 1; + #endif + + + output[0] = OTA_CMD_VERSION; + output[1] = ns_bootsetting.app1.version>>24; + output[2] = ns_bootsetting.app1.version>>16; + output[3] = ns_bootsetting.app1.version>>8; + output[4] = ns_bootsetting.app1.version; + output[5] = ns_bootsetting.app2.version>>24; + output[6] = ns_bootsetting.app2.version>>16; + output[7] = ns_bootsetting.app2.version>>8; + output[8] = ns_bootsetting.app2.version; + output[9] = ns_bootsetting.ImageUpdate.version>>24; + output[10] = ns_bootsetting.ImageUpdate.version>>16; + output[11] = ns_bootsetting.ImageUpdate.version>>8; + output[12] = ns_bootsetting.ImageUpdate.version; + output[13] = ota_selection; + *output_len = 14; + }break; + + case OTA_CMD_JUMP_IMAGE_UPDATE:{ + uint8_t error = 0; + NS_Bootsetting_t m_ns_bootsetting; + memcpy(&m_ns_bootsetting,&ns_bootsetting,sizeof(NS_Bootsetting_t)); + m_ns_bootsetting.app1.activation = NS_BOOTSETTING_ACTIVATION_NO; + m_ns_bootsetting.app2.activation = NS_BOOTSETTING_ACTIVATION_NO; + m_ns_bootsetting.ImageUpdate.activation = NS_BOOTSETTING_ACTIVATION_YES; + m_ns_bootsetting.crc = dfu_crc32((uint8_t *)&m_ns_bootsetting.crc + 4, sizeof(NS_Bootsetting_t) - 4); + Qflash_Erase_Sector(NS_BOOTSETTING_START_ADDRESS); + Qflash_Write(NS_BOOTSETTING_START_ADDRESS, (uint8_t *)&m_ns_bootsetting, sizeof(NS_Bootsetting_t)); + if(m_ns_bootsetting.crc != dfu_crc32((uint8_t *)((uint32_t *)(NS_BOOTSETTING_START_ADDRESS + 4)), sizeof(NS_Bootsetting_t) - 4)) + { + error = 2; + } + + output[0] = OTA_CMD_JUMP_IMAGE_UPDATE; + output[1] = error; + *output_len = 2; + + if(error == 0)ke_timer_set(APP_DFU_BLE_RESET_TIMER, TASK_APP, 1000); + + }break; + + + case OTA_CMD_CREATE_OTA_SETTING:{ + m_ota_setting_size = input[1]<<24 | input[2]<<16 | input[3]<<8 | input[4]; + m_rc_state = OTA_RC_STATE_DFU_SETTING; + rc_mtu_offset = 0; + *output_len = 0; + }break; + + case OTA_CMD_CREATE_OTA_IMAGE:{ + m_ota_image.offset = input[1]<<24 | input[2]<<16 | input[3]<<8 | input[4]; + m_ota_image.size = input[5]<<24 | input[6]<<16 | input[7]<<8 | input[8]; + m_ota_image.crc = input[9]<<24 | input[10]<<16 | input[11]<<8 | input[12]; + m_rc_state = OTA_RC_STATE_DFU_IMAGE; + rc_mtu_offset = 0; + *output_len = 0; + }break; + + + case OTA_CMD_VALIDATE_OTA_IMAGE:{ + output[0] = OTA_CMD_VALIDATE_OTA_IMAGE; + output[1] = 0; + if(ota_selection == 1){ + if(m_dfu_setting.app1.crc != dfu_crc32((uint8_t *)((uint32_t *)m_dfu_setting.app1.start_address), m_dfu_setting.app1.size)) + { + output[1] = 2; + } + }else if(ota_selection == 2){ + if(m_dfu_setting.app2.crc != dfu_crc32((uint8_t *)((uint32_t *)m_dfu_setting.app2.start_address), m_dfu_setting.app2.size)) + { + output[1] = 2; + } + }else if(ota_selection == 3){ + if(m_dfu_setting.image_update.crc != dfu_crc32((uint8_t *)((uint32_t *)m_dfu_setting.image_update.start_address), m_dfu_setting.image_update.size)) + { + output[1] = 2; + } + } + *output_len = 2; + }break; + + case OTA_CMD_ACTIVATE_OTA_IMAGE:{ + + uint8_t error = 0; + NS_Bootsetting_t m_ns_bootsetting; + memcpy(&m_ns_bootsetting,&ns_bootsetting,sizeof(NS_Bootsetting_t)); + m_ns_bootsetting.app1.activation = NS_BOOTSETTING_ACTIVATION_NO; + m_ns_bootsetting.app2.activation = NS_BOOTSETTING_ACTIVATION_NO; + m_ns_bootsetting.ImageUpdate.activation = NS_BOOTSETTING_ACTIVATION_NO; + m_ns_bootsetting.master_boot_force_update = NS_BOOTSETTING_MASTER_BOOT_FORCE_UPDATE_NO; + + if(ota_selection == 1){ + m_ns_bootsetting.app1.start_address = NS_APP1_START_ADDRESS; + m_ns_bootsetting.app1.size = m_dfu_setting.app1.size; + m_ns_bootsetting.app1.version = m_dfu_setting.app1.version; + m_ns_bootsetting.app1.crc = m_dfu_setting.app1.crc; + m_ns_bootsetting.app1.activation = NS_BOOTSETTING_ACTIVATION_YES; + }else if(ota_selection == 2){ + m_ns_bootsetting.app2.start_address = NS_APP2_START_ADDRESS; + m_ns_bootsetting.app2.size = m_dfu_setting.app2.size; + m_ns_bootsetting.app2.version = m_dfu_setting.app2.version; + m_ns_bootsetting.app2.crc = m_dfu_setting.app2.crc; + m_ns_bootsetting.app2.activation = NS_BOOTSETTING_ACTIVATION_YES; + }else if(ota_selection == 3){ + m_ns_bootsetting.ImageUpdate.start_address = NS_IMAGE_UPDATE_START_ADDRESS; + m_ns_bootsetting.ImageUpdate.size = m_dfu_setting.image_update.size; + m_ns_bootsetting.ImageUpdate.version = m_dfu_setting.image_update.version; + m_ns_bootsetting.ImageUpdate.crc = m_dfu_setting.image_update.crc; + m_ns_bootsetting.ImageUpdate.activation = NS_BOOTSETTING_ACTIVATION_YES; + } + m_ns_bootsetting.crc = dfu_crc32((uint8_t *)&m_ns_bootsetting.crc + 4, sizeof(NS_Bootsetting_t) - 4); + Qflash_Erase_Sector(NS_BOOTSETTING_START_ADDRESS); + Qflash_Write(NS_BOOTSETTING_START_ADDRESS, (uint8_t *)&m_ns_bootsetting, sizeof(NS_Bootsetting_t)); + if(m_ns_bootsetting.crc != dfu_crc32((uint8_t *)((uint32_t *)(NS_BOOTSETTING_START_ADDRESS + 4)), sizeof(NS_Bootsetting_t) - 4)) + { + error = 2; + } + + output[0] = OTA_CMD_ACTIVATE_OTA_IMAGE; + output[1] = error; + *output_len = 2; + + + if(error == 0)ke_timer_set(APP_DFU_BLE_RESET_TIMER, TASK_APP, 1000); + + }break; + + } + + + + +} + +/** + * @brief Reset System. + * @param[in] msgid. + * @param[in] p_param. + * @param[in] dest_id. + * @param[in] src_id. + * @return msg + */ +int app_dfu_ble_reset_handler(ke_msg_id_t const msgid, void const *p_param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + NVIC_SystemReset(); + return KE_MSG_CONSUMED; +} +/** + * @brief Connection update result response. + * @param[in] status connection update succeed or fail. + * @return none + */ +void ns_dfu_ble_handler_conn_param_update(uint8_t status) +{ + uint8_t response[2] = {OTA_CMD_CONN_PARAM_UPDATE}; + response[1] = status; + ns_ble_ius_app_cc_send(response,sizeof(response)); +} +/** + * @brief mtu update result response. + * @param[in] status mtu update succeed or fail. + * @return none + */ +void ns_dfu_ble_handler_mtu_update(uint8_t status) +{ + uint8_t response[2] = {OTA_CMD_MTU_UPDATE}; + response[1] = status; + ns_ble_ius_app_cc_send(response,sizeof(response)); +} + + + + + +/** + * @brief Processing and handling ius service rc characteristic data. + * @param[in] input data to process. + * @param[in] input_len data length. + * @return none + */ +void ns_dfu_ble_handler_rc(uint8_t const *input, uint32_t input_len) +{ + switch(m_rc_state){ + + case OTA_RC_STATE_DFU_SETTING:{ + memcpy(m_buffer + rc_mtu_offset, input , input_len); + rc_mtu_offset += input_len; + if(rc_mtu_offset >= m_ota_setting_size){ + rc_mtu_offset = 0; + m_rc_state = OTA_RC_STATE_NONE; + memcpy(&m_dfu_setting, m_buffer, sizeof(Dfu_setting_t)); + uint32_t crc = dfu_crc32((uint8_t *)&m_dfu_setting.crc + 4, sizeof(Dfu_setting_t) - 4); + if(crc == m_dfu_setting.crc){ + uint8_t error = 0; + + #if OTA_ECC_ECDSA_SHA256_ENABLE + uint8_t raw_data[sizeof(Dfu_setting_bank_t)*3]; + memcpy(raw_data,&m_dfu_setting.app1,sizeof(Dfu_setting_bank_t)); + memcpy(raw_data+sizeof(Dfu_setting_bank_t),&m_dfu_setting.app2,sizeof(Dfu_setting_bank_t)); + memcpy(raw_data+sizeof(Dfu_setting_bank_t)*2,&m_dfu_setting.image_update,sizeof(Dfu_setting_bank_t)); + uint8_t hash_digest[32]; + if(ERROR_SUCCESS == ns_lib_ecc_hash_sha256(raw_data, sizeof(Dfu_setting_bank_t)*3, hash_digest)){ + if(ERROR_SUCCESS != ns_lib_ecc_ecdsa_verify(ns_bootsetting.public_key, hash_digest, 32, m_dfu_setting.signature)){ + error = 3; + } + }else{ + error = 3; + } + #endif + + + uint8_t response[2] = {OTA_CMD_CREATE_OTA_SETTING}; + response[1] = error; + ns_ble_ius_app_cc_send(response,sizeof(response)); + }else{ + uint8_t response[2] = {OTA_CMD_CREATE_OTA_SETTING}; + response[1] = 2; + ns_ble_ius_app_cc_send(response,sizeof(response)); + } + + } + + }break; + + + + case OTA_RC_STATE_DFU_IMAGE:{ + memcpy(m_buffer + rc_mtu_offset, input , input_len); + rc_mtu_offset += input_len; + if(rc_mtu_offset >= m_ota_image.size){ + m_rc_state = OTA_RC_STATE_NONE; + rc_mtu_offset = 0; + uint32_t crc = dfu_crc32(m_buffer, m_ota_image.size); + uint8_t error = 0; + if(crc == m_ota_image.crc) + { + if((m_ota_image.address + m_ota_image.offset) % FLASH_SECTOR_SIZE == 0){ + #ifdef APPLICATION + NS_LOG_INFO("bsp_flash_erase_sector --> 0x%08X\r\n",m_ota_image.address + m_ota_image.offset); + #endif + Qflash_Erase_Sector(m_ota_image.address + m_ota_image.offset); + } + #ifdef APPLICATION + NS_LOG_INFO("bsp_flash_write --> 0x%08X\r\n",m_ota_image.address + m_ota_image.offset); + #endif + Qflash_Write(m_ota_image.address + m_ota_image.offset, m_buffer, m_ota_image.size); + if(m_ota_image.crc != dfu_crc32((uint8_t *)((uint32_t *)(m_ota_image.address + m_ota_image.offset)), m_ota_image.size)) + { + error = 3; + } + uint8_t response[2] = {OTA_CMD_CREATE_OTA_IMAGE}; + response[1] = error; + ns_ble_ius_app_cc_send(response,sizeof(response)); + + } + else + { + + uint8_t response[2] = {OTA_CMD_CREATE_OTA_IMAGE}; + response[1] = 2; + ns_ble_ius_app_cc_send(response,sizeof(response)); + } + } + + }break; + } + +} + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_ble.h new file mode 100644 index 0000000..0b8090d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_ble.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_dfu_ble.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef __NS_DFU_BLE_H__ +#define __NS_DFU_BLE_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include + +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +typedef struct{ + uint32_t start_address; + uint32_t size; + uint32_t crc; + uint32_t version; +}Dfu_setting_bank_t; + +typedef struct{ + + uint32_t crc; + Dfu_setting_bank_t app1; + Dfu_setting_bank_t app2; + Dfu_setting_bank_t image_update; + uint8_t signature[64]; +}Dfu_setting_t; +/* Public define ------------------------------------------------------------*/ +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +void ns_dfu_ble_handler_cc(uint8_t const *input, uint8_t input_len, uint8_t *output, uint8_t *output_len); +void ns_dfu_ble_handler_rc(uint8_t const *input, uint32_t input_len); +void ns_dfu_ble_handler_conn_param_update(uint8_t status); +void ns_dfu_ble_handler_mtu_update(uint8_t status); + +#ifdef __cplusplus +} +#endif + + + +#endif //__NS_DFU_BLE_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_boot.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_boot.c new file mode 100644 index 0000000..933bb3b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_boot.c @@ -0,0 +1,125 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_dfu_boot.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "ns_dfu_boot.h" +#include "n32wb03x.h" +#include "dfu_crc.h" +#include "ns_error.h" +/* Private typedef -----------------------------------------------------------*/ +typedef void (*func_ptr_t)(void); +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +NS_Bootsetting_t ns_bootsetting __attribute__((at(NS_BOOTSETTING_START_ADDRESS))) __attribute__((used)); +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Inter program jump function. + * @param[in] address program flash address. + * @return none, function will not return + */ +void ns_dfu_boot_jump(uint32_t address) +{ + + uint32_t JumpAddress; + func_ptr_t JumpToApplication; + JumpAddress = *(__IO uint32_t *)(address + 4); + JumpToApplication = (func_ptr_t)JumpAddress; + __set_MSP(*(__IO uint32_t *)address); + JumpToApplication(); + +} + + +/** + * @brief Write force usart image update variable in bootsetting. + * @param[in] none. + * @return none + */ +bool ns_dfu_boot_force_usart_dfu(void) +{ + NS_Bootsetting_t ns_bootsetting_tmp; + memcpy(&ns_bootsetting_tmp,&ns_bootsetting,sizeof(NS_Bootsetting_t)); + ns_bootsetting_tmp.master_boot_force_update = NS_BOOTSETTING_MASTER_BOOT_FORCE_UPDATE_YES; + ns_bootsetting_tmp.crc = dfu_crc32((uint8_t *)&ns_bootsetting_tmp.crc + 4, sizeof(NS_Bootsetting_t) - 4); + Qflash_Erase_Sector(NS_BOOTSETTING_START_ADDRESS); + Qflash_Write(NS_BOOTSETTING_START_ADDRESS, (uint8_t *)&ns_bootsetting_tmp, sizeof(NS_Bootsetting_t)); + + if(ns_bootsetting_tmp.crc == dfu_crc32((uint8_t *)((uint32_t *)(NS_BOOTSETTING_START_ADDRESS + 4)), sizeof(NS_Bootsetting_t) - 4)) + { + NVIC_SystemReset(); + return ERROR_SUCCESS; + } + else + { + return ERROR_INTERNAL; + } +} + + + + + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_boot.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_boot.h new file mode 100644 index 0000000..dae1382 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_boot.h @@ -0,0 +1,128 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_dfu_boot.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef __NS_DFU_BOOT_H__ +#define __NS_DFU_BOOT_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include +#include +#include + +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +typedef struct +{ + uint32_t start_address; + uint32_t size; + uint32_t crc; + uint32_t version; + uint32_t activation; + uint32_t reserve[5]; +}NS_Bank_t; + +typedef struct +{ + uint32_t crc; + uint32_t master_boot_force_update; + NS_Bank_t app1; + NS_Bank_t app2; + NS_Bank_t ImageUpdate; + uint8_t public_key[64]; +}NS_Bootsetting_t; +/* Public define ------------------------------------------------------------*/ +extern int Image$$ER_IROM1$$Base; +#define CURRENT_APP_START_ADDRESS (uint32_t)&Image$$ER_IROM1$$Base + +#define NS_MASTERBOOT_START_ADDRESS (0x01000000) +#define NS_MASTERBOOT_SIZE (0x2000) +#define NS_BOOTSETTING_START_ADDRESS (0x01002000) +#define NS_BOOTSETTING_SIZE (0x1000) +#define NS_APP_DATA_START_ADDRESS (0x01003000) +#define NS_APP_DATA_SIZE (0x1000) +#define NS_APP1_START_ADDRESS (0x01004000) +#define NS_APP1_DEFAULT_SIZE (0x1C000) +#define NS_APP2_START_ADDRESS (0x01020000) +#define NS_APP2_DEFAULT_SIZE (0x1C000) +#define NS_IMAGE_UPDATE_START_ADDRESS (0x0103C000) +#define NS_IMAGE_UPDATE_SIZE (0x4000) + +#define NS_BOOTSETTING_ACTIVATION_YES (0x00000001) +#define NS_BOOTSETTING_ACTIVATION_NO (0xFFFFFFFF) +#define NS_BOOTSETTING_MASTER_BOOT_FORCE_UPDATE_YES (0x00000001) +#define NS_BOOTSETTING_MASTER_BOOT_FORCE_UPDATE_NO (0xFFFFFFFF) + +/* Public variables ---------------------------------------------------------*/ +extern NS_Bootsetting_t ns_bootsetting; +/* Public function prototypes -----------------------------------------------*/ +void ns_dfu_boot_jump(uint32_t address); +bool ns_dfu_boot_force_usart_dfu(void); + + +#ifdef __cplusplus +} +#endif + + +#endif //__NS_DFU_BOOT_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_serial.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_serial.c new file mode 100644 index 0000000..b923bc1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_serial.c @@ -0,0 +1,410 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_dfu_serial.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "ns_dfu_serial.h" +#include "ns_scheduler.h" +#include "ns_dfu_boot.h" +#include "dfu_usart.h" +#include "n32wb03x.h" +#include "ns_error.h" +#include "dfu_delay.h" +#include "dfu_crc.h" +/* Private typedef -----------------------------------------------------------*/ +static struct +{ + uint8_t buffer[4096]; + uint32_t offset; +}m_pkt; + +typedef struct +{ + uint32_t crc; + uint32_t app_start_address; + uint32_t app_size; + uint32_t app_crc; + uint32_t app_version; + uint32_t reserve[10]; +}_init_pkt; +static _init_pkt m_init_pkt; +typedef struct +{ + uint32_t offset; + uint32_t size; + uint32_t crc; +}_pkt_header; + +/* Private define ------------------------------------------------------------*/ +#define DFU_SERIAL_HEADER 0xAA +#define DFU_SERIAL_CMD_Ping 0x01 +#define DFU_SERIAL_CMD_InitPkt 0x02 +#define DFU_SERIAL_CMD_Pkt_header 0x03 +#define DFU_SERIAL_CMD_Pkt 0x04 +#define DFU_SERIAL_CMD_PostValidate 0x05 +#define DFU_SERIAL_CMD_ActivateReset 0x06 +#define DFU_SERIAL_CMD_JumpToMasterBoot 0x07 + +#define SCHED_EVT_RX_DATA 1 +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static _pkt_header m_pkt_header; +static NS_Bootsetting_t m_ns_bootsetting; +/* Private function prototypes -----------------------------------------------*/ +static void sched_evt(void * p_event_data, uint16_t event_size); +static uint32_t serial_send_data(uint8_t *p_data, uint32_t length); +static uint8_t m_buffer[256]; +static void dfu_serial_cmd_ping(void); +static void dfu_serial_cmd_init_pkt(void); +static void dfu_serial_cmd_pkt_header(void); +static void dfu_serial_cmd_pkt(void); +static void dfu_serial_cmd_postvalidate(void); +static void dfu_serial_cmd_activate_reset(void); +static void dfu_serial_cmd_jump_to_master_boot(void); +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Initialize serial dfu. + * @param[in] none. + * @return none + */ +void ns_dfu_serial_init(void) +{ + Qflash_Init(); + if(ns_bootsetting.crc == dfu_crc32((uint8_t *)&ns_bootsetting.crc + 4, sizeof(NS_Bootsetting_t) - 4)) + { + if(ns_bootsetting.master_boot_force_update == NS_BOOTSETTING_MASTER_BOOT_FORCE_UPDATE_YES) + { + NS_Bootsetting_t ns_bootsetting_tmp; + do{ + memcpy(&ns_bootsetting_tmp,&ns_bootsetting,sizeof(NS_Bootsetting_t)); + ns_bootsetting_tmp.master_boot_force_update = NS_BOOTSETTING_MASTER_BOOT_FORCE_UPDATE_NO; + ns_bootsetting_tmp.crc = dfu_crc32((uint8_t *)&ns_bootsetting_tmp.crc + 4, sizeof(NS_Bootsetting_t) - 4); + Qflash_Erase_Sector(NS_BOOTSETTING_START_ADDRESS); + Qflash_Write(NS_BOOTSETTING_START_ADDRESS, (uint8_t *)&ns_bootsetting_tmp, sizeof(NS_Bootsetting_t)); + }while(ns_bootsetting_tmp.crc != dfu_crc32((uint8_t *)((uint32_t *)(NS_BOOTSETTING_START_ADDRESS + 4)), sizeof(NS_Bootsetting_t) - 4)); + } + } + + + dfu_usart1_interrupt_config(); + dfu_usart1_enable(); +} + + + +/** + * @brief Process data received from serial port. + * @param[in] p_event_data event type. + * @param[in] event_size event size. + * @return none + */ +static void sched_evt(void * p_event_data, uint16_t event_size) +{ + switch(*(uint8_t *)p_event_data) + { + case SCHED_EVT_RX_DATA:{ + if(m_buffer[0] == DFU_SERIAL_HEADER) + { + switch(m_buffer[1]){ + + case DFU_SERIAL_CMD_Ping:{ + dfu_serial_cmd_ping(); + }break; + case DFU_SERIAL_CMD_InitPkt:{ + dfu_serial_cmd_init_pkt(); + }break; + case DFU_SERIAL_CMD_Pkt_header:{ + dfu_serial_cmd_pkt_header(); + }break; + case DFU_SERIAL_CMD_Pkt:{ + dfu_serial_cmd_pkt(); + }break; + case DFU_SERIAL_CMD_PostValidate:{ + dfu_serial_cmd_postvalidate(); + }break; + case DFU_SERIAL_CMD_ActivateReset:{ + dfu_serial_cmd_activate_reset(); + }break; + case DFU_SERIAL_CMD_JumpToMasterBoot:{ + dfu_serial_cmd_jump_to_master_boot(); + }break; + } + } + }break; + } +} +/** + * @brief Ping the board. + * @param[in] none. + * @return none + */ +static void dfu_serial_cmd_ping(void) +{ + uint8_t cmd[] = {DFU_SERIAL_HEADER,DFU_SERIAL_CMD_Ping}; + serial_send_data(cmd, sizeof(cmd)); +} +/** + * @brief Process init packet. + * @param[in] none. + * @return none + */ +static void dfu_serial_cmd_init_pkt(void) +{ + uint8_t error = 0; + memcpy(&m_init_pkt,m_buffer+2,sizeof(_init_pkt)); + if(m_init_pkt.crc != dfu_crc32((uint8_t *)&m_init_pkt.crc + 4, sizeof(_init_pkt) - 4)) + { + error = 1; + } + if(m_init_pkt.app_start_address < NS_BOOTSETTING_START_ADDRESS) + { + error = 1; + } + uint8_t cmd[] = {DFU_SERIAL_HEADER,DFU_SERIAL_CMD_InitPkt,error}; + serial_send_data(cmd, sizeof(cmd)); +} +/** + * @brief Process packet header. + * @param[in] none. + * @return none + */ +static void dfu_serial_cmd_pkt_header(void) +{ + m_pkt.offset = 0; + uint8_t error = 0; + memcpy(&m_pkt_header,m_buffer+2,sizeof(_pkt_header)); + uint8_t cmd[] = {DFU_SERIAL_HEADER,DFU_SERIAL_CMD_Pkt_header,error}; + serial_send_data(cmd, sizeof(cmd)); +} +/** + * @brief Process packet data. + * @param[in] none. + * @return none + */ +static void dfu_serial_cmd_pkt(void) +{ + uint8_t error = 0; + memcpy(m_pkt.buffer+m_pkt.offset,m_buffer+3,m_buffer[2]); + m_pkt.offset += m_buffer[2]; + + if(m_pkt.offset >= m_pkt_header.size) + { + if(m_pkt_header.crc == dfu_crc32(m_pkt.buffer, m_pkt_header.size)) + { + Qflash_Erase_Sector(m_init_pkt.app_start_address + m_pkt_header.offset); + Qflash_Write(m_init_pkt.app_start_address + m_pkt_header.offset, m_pkt.buffer, m_pkt_header.size); + if(m_pkt_header.crc != dfu_crc32((uint8_t *)((uint32_t *)(m_init_pkt.app_start_address + m_pkt_header.offset)), m_pkt_header.size)) + { + error = 1; + } + } + else + { + error = 1; + } + } + uint8_t cmd[] = {DFU_SERIAL_HEADER,DFU_SERIAL_CMD_Pkt,error}; + serial_send_data(cmd, sizeof(cmd)); +} +/** + * @brief Validate receviced data. + * @param[in] none. + * @return none + */ +static void dfu_serial_cmd_postvalidate(void) +{ + uint8_t error = 0; + + if(m_init_pkt.app_crc != dfu_crc32((uint8_t *)((uint32_t *)m_init_pkt.app_start_address), m_init_pkt.app_size)) + { + error = 1; + } + else{ + memcpy(&m_ns_bootsetting,&ns_bootsetting,sizeof(NS_Bootsetting_t)); + + m_ns_bootsetting.app1.activation = NS_BOOTSETTING_ACTIVATION_NO; + m_ns_bootsetting.app2.activation = NS_BOOTSETTING_ACTIVATION_NO; + m_ns_bootsetting.ImageUpdate.activation = NS_BOOTSETTING_ACTIVATION_NO; + m_ns_bootsetting.master_boot_force_update = NS_BOOTSETTING_MASTER_BOOT_FORCE_UPDATE_NO; + if(m_init_pkt.app_start_address == NS_APP1_START_ADDRESS) + { + m_ns_bootsetting.app1.start_address = NS_APP1_START_ADDRESS; + m_ns_bootsetting.app1.size = m_init_pkt.app_size; + m_ns_bootsetting.app1.version = m_init_pkt.app_version; + m_ns_bootsetting.app1.crc = m_init_pkt.app_crc; + m_ns_bootsetting.app1.activation = NS_BOOTSETTING_ACTIVATION_YES; + } + else if(m_init_pkt.app_start_address == NS_APP2_START_ADDRESS) + { + m_ns_bootsetting.app2.start_address = NS_APP2_START_ADDRESS; + m_ns_bootsetting.app2.size = m_init_pkt.app_size; + m_ns_bootsetting.app2.version = m_init_pkt.app_version; + m_ns_bootsetting.app2.crc = m_init_pkt.app_crc; + m_ns_bootsetting.app2.activation = NS_BOOTSETTING_ACTIVATION_YES; + } + else if(m_init_pkt.app_start_address == NS_IMAGE_UPDATE_START_ADDRESS) + { + m_ns_bootsetting.ImageUpdate.start_address = NS_IMAGE_UPDATE_START_ADDRESS; + m_ns_bootsetting.ImageUpdate.size = m_init_pkt.app_size; + m_ns_bootsetting.ImageUpdate.version = m_init_pkt.app_version; + m_ns_bootsetting.ImageUpdate.crc = m_init_pkt.app_crc; + m_ns_bootsetting.ImageUpdate.activation = NS_BOOTSETTING_ACTIVATION_YES; + } + else + { + error = 1; + } + + if(error == 0){ + m_ns_bootsetting.crc = dfu_crc32((uint8_t *)&m_ns_bootsetting.crc + 4, sizeof(NS_Bootsetting_t) - 4); + Qflash_Erase_Sector(NS_BOOTSETTING_START_ADDRESS); + Qflash_Write(NS_BOOTSETTING_START_ADDRESS, (uint8_t *)&m_ns_bootsetting, sizeof(NS_Bootsetting_t)); + if(m_ns_bootsetting.crc != dfu_crc32((uint8_t *)((uint32_t *)(NS_BOOTSETTING_START_ADDRESS + 4)), sizeof(NS_Bootsetting_t) - 4)) + { + error = 2; + } + } + + } + uint8_t cmd[] = {DFU_SERIAL_HEADER,DFU_SERIAL_CMD_PostValidate,error}; + serial_send_data(cmd, sizeof(cmd)); +} + + + +/** + * @brief Reset System. + * @param[in] none. + * @return none + */ +static void dfu_serial_cmd_activate_reset(void) +{ + uint8_t error = 0; + + uint8_t cmd[] = {DFU_SERIAL_HEADER,DFU_SERIAL_CMD_ActivateReset,error}; + serial_send_data(cmd, sizeof(cmd)); + + if(error == 0) + { + dfu_delay_ms(100); + NVIC_SystemReset(); + + } + + +} + + + + + +static void dfu_serial_cmd_jump_to_master_boot(void) +{ + uint8_t cmd[] = {DFU_SERIAL_HEADER,DFU_SERIAL_CMD_JumpToMasterBoot}; + serial_send_data(cmd, sizeof(cmd)); +} + + + + + + +void USART1_IRQHandler(void) +{ + static uint32_t index = 0; + static uint8_t buffer[256]; + + if(USART_GetFlagStatus(USART1, USART_FLAG_RXDNE) != RESET) + { + buffer[index] = USART_ReceiveData(USART1); + + if(buffer[0] == DFU_SERIAL_HEADER) + { + index++; + if(index >= 256) + { + index = 0; + memset(m_buffer,0,sizeof(m_buffer)); + memcpy(m_buffer,buffer, 256); + + uint8_t event = SCHED_EVT_RX_DATA; + uint32_t err_code = app_sched_event_put(&event ,sizeof(uint8_t),sched_evt); + ERROR_CHECK(err_code); + } + } + } +} + + + +static uint32_t serial_send_data(uint8_t *p_data, uint32_t length) +{ + uint8_t cmd[256]; + memset(cmd,0,sizeof(cmd)); + memcpy(cmd,p_data,length); + dfu_usart1_send(cmd,sizeof(cmd)); + return 0; +} + + + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_serial.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_serial.h new file mode 100644 index 0000000..418581f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/dfu/ns_dfu_serial.h @@ -0,0 +1,89 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_dfu_serial.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef __NS_DFU_SERIAL_H__ +#define __NS_DFU_SERIAL_H__ + + + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include + +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +void ns_dfu_serial_init(void); + + + + +#ifdef __cplusplus +} +#endif + + + +#endif //__NS_DFU_SERIAL_H__ +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/ns_ecc.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/ns_ecc.c new file mode 100644 index 0000000..1aea6c6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/ns_ecc.c @@ -0,0 +1,170 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ecc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "ns_ecc.h" +#include +#include +#include "uECC.h" +#include "sha256.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + + + +/** + * @brief Calculate hash degest. + * @param[in] p_data raw data to process. + * @param[in] data_len raw data length. + * @param[out] p_hash hash degest. + * @return error code + */ +uint32_t ns_lib_ecc_hash_sha256(uint8_t *p_data, uint32_t data_len, uint8_t *p_hash) +{ + sha256_context_t hash_context; + sha256_init(&hash_context); + if(!sha256_update(&hash_context, p_data, data_len)){ + sha256_final(&hash_context, p_hash, 0); + return 0; + } + return 1; +} + + +/** + * @brief big to little endian swap function. + * @param[out] p_out output little endian data. + * @param[in] p_in big endian raw data. + * @param[in] size data length. + * @return none + */ +static void swap_endian(uint8_t * p_out, uint8_t const * p_in, size_t size) +{ + uint8_t const * p_first = p_in; + uint8_t * p_last = p_out + size - 1; + while (p_last >= p_out) + { + *p_last = *p_first; + p_first++; + p_last--; + } +} + +/** + * @brief big to little endian swap function with two sets of data. + * @param[out] p_out output little endian data. + * @param[in] p_in big endian raw data. + * @param[in] size half data length. + * @return none + */ +static void double_swap_endian(uint8_t * p_out, uint8_t const * p_in, size_t part_size) +{ + swap_endian(p_out, p_in, part_size); + swap_endian(&p_out[part_size], &p_in[part_size], part_size); +} + + + +/** + * @brief ECDSA SHA256 digital signature verification function. + * @param[in] p_public_key public key data. + * @param[in] p_hash sha256 hash degest data. + * @param[in] hash_size hash degest length. + * @param[in] p_signature digital signature. + * @return error code + */ +uint32_t ns_lib_ecc_ecdsa_verify(uint8_t *p_public_key, uint8_t *p_hash, uint32_t hash_size, uint8_t *p_signature) +{ + uint32_t error = 0; + uint8_t hash_le [32]; + uint8_t signature_le[64]; + uint8_t public_key_le[64]; + swap_endian(hash_le, p_hash, sizeof(hash_le)); + double_swap_endian(signature_le,p_signature,32); + double_swap_endian(public_key_le,p_public_key,32); + int result = uECC_verify(public_key_le, hash_le, hash_size, signature_le, &curve_secp256r1); + if(result != 1){ + error = 1; + } + return error; +} + + + + + + + + + + + + + + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/ns_ecc.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/ns_ecc.h new file mode 100644 index 0000000..8b075df --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/ns_ecc.h @@ -0,0 +1,93 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ecc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef __NS_ECC_H__ +#define __NS_ECC_H__ + + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include + +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +uint32_t ns_lib_ecc_hash_sha256(uint8_t *p_data, uint32_t data_len, uint8_t *p_hash); +uint32_t ns_lib_ecc_ecdsa_verify(uint8_t *p_public_key, uint8_t *p_hash, uint32_t hash_size, uint8_t *p_signature); + + + +#ifdef __cplusplus +} +#endif + + + +#endif //__NS_ECC_H__ +/** + * @} + */ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/sha256.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/sha256.c new file mode 100644 index 0000000..f043aec --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/sha256.c @@ -0,0 +1,239 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file sha256.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include +#include "sha256.h" +#include + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define ROTLEFT(a,b) (((a) << (b)) | ((a) >> (32 - (b)))) +#define ROTRIGHT(a,b) (((a) >> (b)) | ((a) << (32 - (b)))) + +#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z))) +#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) +#define EP0(x) (ROTRIGHT(x,2) ^ ROTRIGHT(x,13) ^ ROTRIGHT(x,22)) +#define EP1(x) (ROTRIGHT(x,6) ^ ROTRIGHT(x,11) ^ ROTRIGHT(x,25)) +#define SIG0(x) (ROTRIGHT(x,7) ^ ROTRIGHT(x,18) ^ ((x) >> 3)) +#define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) >> 10)) + +/* Private constants ---------------------------------------------------------*/ +static const uint32_t k[64] = { + 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, + 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174, + 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da, + 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967, + 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85, + 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070, + 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3, + 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 +}; +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +void sha256_transform(sha256_context_t *ctx, const uint8_t * data) +{ + uint32_t a, b, c, d, e, f, g, h, i, j, t1, t2, m[64]; + + for (i = 0, j = 0; i < 16; ++i, j += 4) + m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]); + for ( ; i < 64; ++i) + m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16]; + + a = ctx->state[0]; + b = ctx->state[1]; + c = ctx->state[2]; + d = ctx->state[3]; + e = ctx->state[4]; + f = ctx->state[5]; + g = ctx->state[6]; + h = ctx->state[7]; + + for (i = 0; i < 64; ++i) { + t1 = h + EP1(e) + CH(e,f,g) + k[i] + m[i]; + t2 = EP0(a) + MAJ(a,b,c); + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + } + + ctx->state[0] += a; + ctx->state[1] += b; + ctx->state[2] += c; + ctx->state[3] += d; + ctx->state[4] += e; + ctx->state[5] += f; + ctx->state[6] += g; + ctx->state[7] += h; +} + + +uint32_t sha256_init(sha256_context_t *ctx) +{ + + ctx->datalen = 0; + ctx->bitlen = 0; + ctx->state[0] = 0x6a09e667; + ctx->state[1] = 0xbb67ae85; + ctx->state[2] = 0x3c6ef372; + ctx->state[3] = 0xa54ff53a; + ctx->state[4] = 0x510e527f; + ctx->state[5] = 0x9b05688c; + ctx->state[6] = 0x1f83d9ab; + ctx->state[7] = 0x5be0cd19; + + return 0; +} + + +uint32_t sha256_update(sha256_context_t *ctx, const uint8_t * data, size_t len) +{ + if (((len > 0) && (data == NULL))) + { + return 1; + } + + uint32_t i; + + for (i = 0; i < len; ++i) { + ctx->data[ctx->datalen] = data[i]; + ctx->datalen++; + if (ctx->datalen == 64) { + sha256_transform(ctx, ctx->data); + ctx->bitlen += 512; + ctx->datalen = 0; + } + } + + return 0; +} + + +uint32_t sha256_final(sha256_context_t *ctx, uint8_t * hash, uint8_t le) +{ + uint32_t i; + + i = ctx->datalen; + + // Pad whatever data is left in the buffer. + if (ctx->datalen < 56) { + ctx->data[i++] = 0x80; + while (i < 56) + ctx->data[i++] = 0x00; + } + else { + ctx->data[i++] = 0x80; + while (i < 64) + ctx->data[i++] = 0x00; + sha256_transform(ctx, ctx->data); + memset(ctx->data, 0, 56); + } + + // Append to the padding the total message's length in bits and transform. + ctx->bitlen += (uint64_t)ctx->datalen * 8; + ctx->data[63] = ctx->bitlen; + ctx->data[62] = ctx->bitlen >> 8; + ctx->data[61] = ctx->bitlen >> 16; + ctx->data[60] = ctx->bitlen >> 24; + ctx->data[59] = ctx->bitlen >> 32; + ctx->data[58] = ctx->bitlen >> 40; + ctx->data[57] = ctx->bitlen >> 48; + ctx->data[56] = ctx->bitlen >> 56; + sha256_transform(ctx, ctx->data); + + if (le) + { + for (i = 0; i < 4; ++i) { + hash[i] = (ctx->state[7] >> (i * 8)) & 0x000000ff; + hash[i + 4] = (ctx->state[6] >> (i * 8)) & 0x000000ff; + hash[i + 8] = (ctx->state[5] >> (i * 8)) & 0x000000ff; + hash[i + 12] = (ctx->state[4] >> (i * 8)) & 0x000000ff; + hash[i + 16] = (ctx->state[3] >> (i * 8)) & 0x000000ff; + hash[i + 20] = (ctx->state[2] >> (i * 8)) & 0x000000ff; + hash[i + 24] = (ctx->state[1] >> (i * 8)) & 0x000000ff; + hash[i + 28] = (ctx->state[0] >> (i * 8)) & 0x000000ff; + } + } + else + { + + // Since this implementation uses little endian uint8_t ordering and SHA uses big endian, + // reverse all the uint8_ts when copying the final state to the output hash. + for (i = 0; i < 4; ++i) { + hash[i] = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff; + hash[i + 4] = (ctx->state[1] >> (24 - i * 8)) & 0x000000ff; + hash[i + 8] = (ctx->state[2] >> (24 - i * 8)) & 0x000000ff; + hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0x000000ff; + hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0x000000ff; + hash[i + 20] = (ctx->state[5] >> (24 - i * 8)) & 0x000000ff; + hash[i + 24] = (ctx->state[6] >> (24 - i * 8)) & 0x000000ff; + hash[i + 28] = (ctx->state[7] >> (24 - i * 8)) & 0x000000ff; + } + } + + return 0; +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/sha256.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/sha256.h new file mode 100644 index 0000000..0089948 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/sha256.h @@ -0,0 +1,97 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file sha256.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef SHA256_H +#define SHA256_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include + + + +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +typedef struct { + uint8_t data[64]; + uint32_t datalen; + uint64_t bitlen; + uint32_t state[8]; +} sha256_context_t; + +/* Public define ------------------------------------------------------------*/ +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +uint32_t sha256_init(sha256_context_t *ctx); +uint32_t sha256_update(sha256_context_t *ctx, const uint8_t * data, const size_t len); +uint32_t sha256_final(sha256_context_t *ctx, uint8_t * hash, uint8_t le); + + +#ifdef __cplusplus +} +#endif + + +#endif // SHA256_H +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/uECC.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/uECC.c new file mode 100644 index 0000000..c7569d0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/uECC.c @@ -0,0 +1,806 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file uECC.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "uECC.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define uECC_VLI_API static + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + + + + + +static void bcopy(uint8_t *dst, + const uint8_t *src, + unsigned num_bytes) { + while (0 != num_bytes) { + num_bytes--; + dst[num_bytes] = src[num_bytes]; + } +} + + + + +uECC_VLI_API uECC_word_t uECC_vli_add(uECC_word_t *result, + const uECC_word_t *left, + const uECC_word_t *right, + wordcount_t num_words) { + uECC_word_t carry = 0; + wordcount_t i; + for (i = 0; i < num_words; ++i) { + uECC_word_t sum = left[i] + right[i] + carry; + if (sum != left[i]) { + carry = (sum < left[i]); + } + result[i] = sum; + } + return carry; +} + +uECC_VLI_API uECC_word_t uECC_vli_sub(uECC_word_t *result, + const uECC_word_t *left, + const uECC_word_t *right, + wordcount_t num_words) { + uECC_word_t borrow = 0; + wordcount_t i; + for (i = 0; i < num_words; ++i) { + uECC_word_t diff = left[i] - right[i] - borrow; + if (diff != left[i]) { + borrow = (diff > left[i]); + } + result[i] = diff; + } + return borrow; +} + + +static void muladd(uECC_word_t a, + uECC_word_t b, + uECC_word_t *r0, + uECC_word_t *r1, + uECC_word_t *r2) { + uECC_dword_t p = (uECC_dword_t)a * b; + uECC_dword_t r01 = ((uECC_dword_t)(*r1) << uECC_WORD_BITS) | *r0; + r01 += p; + *r2 += (r01 < p); + *r1 = r01 >> uECC_WORD_BITS; + *r0 = (uECC_word_t)r01; +} + +uECC_VLI_API void uECC_vli_mult(uECC_word_t *result, + const uECC_word_t *left, + const uECC_word_t *right, + wordcount_t num_words) { + uECC_word_t r0 = 0; + uECC_word_t r1 = 0; + uECC_word_t r2 = 0; + wordcount_t i, k; + + /* Compute each digit of result in sequence, maintaining the carries. */ + for (k = 0; k < num_words; ++k) { + for (i = 0; i <= k; ++i) { + muladd(left[i], right[k - i], &r0, &r1, &r2); + } + result[k] = r0; + r0 = r1; + r1 = r2; + r2 = 0; + } + for (k = num_words; k < num_words * 2 - 1; ++k) { + for (i = (k + 1) - num_words; i < num_words; ++i) { + muladd(left[i], right[k - i], &r0, &r1, &r2); + } + result[k] = r0; + r0 = r1; + r1 = r2; + r2 = 0; + } + result[num_words * 2 - 1] = r0; +} + +uECC_VLI_API void uECC_vli_set(uECC_word_t *dest, const uECC_word_t *src, wordcount_t num_words) { + wordcount_t i; + for (i = 0; i < num_words; ++i) { + dest[i] = src[i]; + } +} + +/* Constant-time comparison to zero - secure way to compare long integers */ +/* Returns 1 if vli == 0, 0 otherwise. */ +uECC_VLI_API uECC_word_t uECC_vli_isZero(const uECC_word_t *vli, wordcount_t num_words) { + uECC_word_t bits = 0; + wordcount_t i; + for (i = 0; i < num_words; ++i) { + bits |= vli[i]; + } + return (bits == 0); +} +uECC_VLI_API void uECC_vli_modMult_fast(uECC_word_t *result, + const uECC_word_t *left, + const uECC_word_t *right, + uECC_Curve curve) { + uECC_word_t product[2 * uECC_MAX_WORDS]; + uECC_vli_mult(product, left, right, curve->num_words); + curve->mmod_fast(result, product); +} + + +/* Returns sign of left - right. */ +static cmpresult_t uECC_vli_cmp_unsafe(const uECC_word_t *left, + const uECC_word_t *right, + wordcount_t num_words) { + wordcount_t i; + for (i = num_words - 1; i >= 0; --i) { + if (left[i] > right[i]) { + return 1; + } else if (left[i] < right[i]) { + return -1; + } + } + return 0; +} + +/* Computes result = (left + right) % mod. + Assumes that left < mod and right < mod, and that result does not overlap mod. */ +uECC_VLI_API void uECC_vli_modAdd(uECC_word_t *result, + const uECC_word_t *left, + const uECC_word_t *right, + const uECC_word_t *mod, + wordcount_t num_words) { + uECC_word_t carry = uECC_vli_add(result, left, right, num_words); + if (carry || uECC_vli_cmp_unsafe(mod, result, num_words) != 1) { + /* result > mod (result = mod + remainder), so subtract mod to get remainder. */ + uECC_vli_sub(result, result, mod, num_words); + } +} + + + +uECC_VLI_API void uECC_vli_modSquare_fast(uECC_word_t *result, + const uECC_word_t *left, + uECC_Curve curve) { + uECC_vli_modMult_fast(result, left, left, curve); +} + + +/* Computes result = (left - right) % mod. + Assumes that left < mod and right < mod, and that result does not overlap mod. */ +uECC_VLI_API void uECC_vli_modSub(uECC_word_t *result, + const uECC_word_t *left, + const uECC_word_t *right, + const uECC_word_t *mod, + wordcount_t num_words) { + uECC_word_t l_borrow = uECC_vli_sub(result, left, right, num_words); + if (l_borrow) { + /* In this case, result == -diff == (max int) - diff. Since -x % d == d - x, + we can get the correct result from result + mod (with overflow). */ + uECC_vli_add(result, result, mod, num_words); + } +} +/* Returns nonzero if bit 'bit' of vli is set. */ +uECC_VLI_API uECC_word_t uECC_vli_testBit(const uECC_word_t *vli, bitcount_t bit) { + return (vli[bit >> uECC_WORD_BITS_SHIFT] & ((uECC_word_t)1 << (bit & uECC_WORD_BITS_MASK))); +} +uECC_VLI_API void uECC_vli_rshift1(uECC_word_t *vli, wordcount_t num_words) { + uECC_word_t *end = vli; + uECC_word_t carry = 0; + + vli += num_words; + while (vli-- > end) { + uECC_word_t temp = *vli; + *vli = (temp >> 1) | carry; + carry = temp << (uECC_WORD_BITS - 1); + } +} + +static void double_jacobian_default(uECC_word_t * X1, + uECC_word_t * Y1, + uECC_word_t * Z1, + uECC_Curve curve) { + /* t1 = X, t2 = Y, t3 = Z */ + uECC_word_t t4[uECC_MAX_WORDS]; + uECC_word_t t5[uECC_MAX_WORDS]; + wordcount_t num_words = curve->num_words; + + if (uECC_vli_isZero(Z1, num_words)) { + return; + } + + uECC_vli_modSquare_fast(t4, Y1, curve); /* t4 = y1^2 */ + uECC_vli_modMult_fast(t5, X1, t4, curve); /* t5 = x1*y1^2 = A */ + uECC_vli_modSquare_fast(t4, t4, curve); /* t4 = y1^4 */ + uECC_vli_modMult_fast(Y1, Y1, Z1, curve); /* t2 = y1*z1 = z3 */ + uECC_vli_modSquare_fast(Z1, Z1, curve); /* t3 = z1^2 */ + + uECC_vli_modAdd(X1, X1, Z1, curve->p, num_words); /* t1 = x1 + z1^2 */ + uECC_vli_modAdd(Z1, Z1, Z1, curve->p, num_words); /* t3 = 2*z1^2 */ + uECC_vli_modSub(Z1, X1, Z1, curve->p, num_words); /* t3 = x1 - z1^2 */ + uECC_vli_modMult_fast(X1, X1, Z1, curve); /* t1 = x1^2 - z1^4 */ + + uECC_vli_modAdd(Z1, X1, X1, curve->p, num_words); /* t3 = 2*(x1^2 - z1^4) */ + uECC_vli_modAdd(X1, X1, Z1, curve->p, num_words); /* t1 = 3*(x1^2 - z1^4) */ + if (uECC_vli_testBit(X1, 0)) { + uECC_word_t l_carry = uECC_vli_add(X1, X1, curve->p, num_words); + uECC_vli_rshift1(X1, num_words); + X1[num_words - 1] |= l_carry << (uECC_WORD_BITS - 1); + } else { + uECC_vli_rshift1(X1, num_words); + } + /* t1 = 3/2*(x1^2 - z1^4) = B */ + + uECC_vli_modSquare_fast(Z1, X1, curve); /* t3 = B^2 */ + uECC_vli_modSub(Z1, Z1, t5, curve->p, num_words); /* t3 = B^2 - A */ + uECC_vli_modSub(Z1, Z1, t5, curve->p, num_words); /* t3 = B^2 - 2A = x3 */ + uECC_vli_modSub(t5, t5, Z1, curve->p, num_words); /* t5 = A - x3 */ + uECC_vli_modMult_fast(X1, X1, t5, curve); /* t1 = B * (A - x3) */ + uECC_vli_modSub(t4, X1, t4, curve->p, num_words); /* t4 = B * (A - x3) - y1^4 = y3 */ + + uECC_vli_set(X1, Z1, num_words); + uECC_vli_set(Z1, Y1, num_words); + uECC_vli_set(Y1, t4, num_words); +} + + + + +const struct uECC_Curve_t curve_secp256r1; + + + +void vli_mmod_fast_secp256r1(uint32_t *result, uint32_t *product) { + uint32_t tmp[num_words_secp256r1]; + int carry; + + /* t */ + uECC_vli_set(result, product, num_words_secp256r1); + + /* s1 */ + tmp[0] = tmp[1] = tmp[2] = 0; + tmp[3] = product[11]; + tmp[4] = product[12]; + tmp[5] = product[13]; + tmp[6] = product[14]; + tmp[7] = product[15]; + carry = uECC_vli_add(tmp, tmp, tmp, num_words_secp256r1); + carry += uECC_vli_add(result, result, tmp, num_words_secp256r1); + + /* s2 */ + tmp[3] = product[12]; + tmp[4] = product[13]; + tmp[5] = product[14]; + tmp[6] = product[15]; + tmp[7] = 0; + carry += uECC_vli_add(tmp, tmp, tmp, num_words_secp256r1); + carry += uECC_vli_add(result, result, tmp, num_words_secp256r1); + + /* s3 */ + tmp[0] = product[8]; + tmp[1] = product[9]; + tmp[2] = product[10]; + tmp[3] = tmp[4] = tmp[5] = 0; + tmp[6] = product[14]; + tmp[7] = product[15]; + carry += uECC_vli_add(result, result, tmp, num_words_secp256r1); + + /* s4 */ + tmp[0] = product[9]; + tmp[1] = product[10]; + tmp[2] = product[11]; + tmp[3] = product[13]; + tmp[4] = product[14]; + tmp[5] = product[15]; + tmp[6] = product[13]; + tmp[7] = product[8]; + carry += uECC_vli_add(result, result, tmp, num_words_secp256r1); + + /* d1 */ + tmp[0] = product[11]; + tmp[1] = product[12]; + tmp[2] = product[13]; + tmp[3] = tmp[4] = tmp[5] = 0; + tmp[6] = product[8]; + tmp[7] = product[10]; + carry -= uECC_vli_sub(result, result, tmp, num_words_secp256r1); + + /* d2 */ + tmp[0] = product[12]; + tmp[1] = product[13]; + tmp[2] = product[14]; + tmp[3] = product[15]; + tmp[4] = tmp[5] = 0; + tmp[6] = product[9]; + tmp[7] = product[11]; + carry -= uECC_vli_sub(result, result, tmp, num_words_secp256r1); + + /* d3 */ + tmp[0] = product[13]; + tmp[1] = product[14]; + tmp[2] = product[15]; + tmp[3] = product[8]; + tmp[4] = product[9]; + tmp[5] = product[10]; + tmp[6] = 0; + tmp[7] = product[12]; + carry -= uECC_vli_sub(result, result, tmp, num_words_secp256r1); + + /* d4 */ + tmp[0] = product[14]; + tmp[1] = product[15]; + tmp[2] = 0; + tmp[3] = product[9]; + tmp[4] = product[10]; + tmp[5] = product[11]; + tmp[6] = 0; + tmp[7] = product[13]; + carry -= uECC_vli_sub(result, result, tmp, num_words_secp256r1); + + if (carry < 0) { + do { + carry += uECC_vli_add(result, result, curve_secp256r1.p, num_words_secp256r1); + } while (carry < 0); + } else { + while (carry || uECC_vli_cmp_unsafe(curve_secp256r1.p, result, num_words_secp256r1) != 1) { + carry -= uECC_vli_sub(result, result, curve_secp256r1.p, num_words_secp256r1); + } + } +} + +/* Computes result = x^3 + ax + b. result must not overlap x. */ +static void x_side_default(uECC_word_t *result, const uECC_word_t *x, uECC_Curve curve) { + uECC_word_t _3[uECC_MAX_WORDS] = {3}; /* -a = 3 */ + wordcount_t num_words = curve->num_words; + + uECC_vli_modSquare_fast(result, x, curve); /* r = x^2 */ + uECC_vli_modSub(result, result, _3, curve->p, num_words); /* r = x^2 - 3 */ + uECC_vli_modMult_fast(result, result, x, curve); /* r = x^3 - 3x */ + uECC_vli_modAdd(result, result, curve->b, curve->p, num_words); /* r = x^3 - 3x + b */ +} + + +const struct uECC_Curve_t curve_secp256r1 = { + num_words_secp256r1, + num_bytes_secp256r1, + 256, /* num_n_bits */ + { BYTES_TO_WORDS_8(FF, FF, FF, FF, FF, FF, FF, FF), + BYTES_TO_WORDS_8(FF, FF, FF, FF, 00, 00, 00, 00), + BYTES_TO_WORDS_8(00, 00, 00, 00, 00, 00, 00, 00), + BYTES_TO_WORDS_8(01, 00, 00, 00, FF, FF, FF, FF) }, + { BYTES_TO_WORDS_8(51, 25, 63, FC, C2, CA, B9, F3), + BYTES_TO_WORDS_8(84, 9E, 17, A7, AD, FA, E6, BC), + BYTES_TO_WORDS_8(FF, FF, FF, FF, FF, FF, FF, FF), + BYTES_TO_WORDS_8(00, 00, 00, 00, FF, FF, FF, FF) }, + { BYTES_TO_WORDS_8(96, C2, 98, D8, 45, 39, A1, F4), + BYTES_TO_WORDS_8(A0, 33, EB, 2D, 81, 7D, 03, 77), + BYTES_TO_WORDS_8(F2, 40, A4, 63, E5, E6, BC, F8), + BYTES_TO_WORDS_8(47, 42, 2C, E1, F2, D1, 17, 6B), + + BYTES_TO_WORDS_8(F5, 51, BF, 37, 68, 40, B6, CB), + BYTES_TO_WORDS_8(CE, 5E, 31, 6B, 57, 33, CE, 2B), + BYTES_TO_WORDS_8(16, 9E, 0F, 7C, 4A, EB, E7, 8E), + BYTES_TO_WORDS_8(9B, 7F, 1A, FE, E2, 42, E3, 4F) }, + { BYTES_TO_WORDS_8(4B, 60, D2, 27, 3E, 3C, CE, 3B), + BYTES_TO_WORDS_8(F6, B0, 53, CC, B0, 06, 1D, 65), + BYTES_TO_WORDS_8(BC, 86, 98, 76, 55, BD, EB, B3), + BYTES_TO_WORDS_8(E7, 93, 3A, AA, D8, 35, C6, 5A) }, + &double_jacobian_default, + &x_side_default, + &vli_mmod_fast_secp256r1 +}; + +uECC_VLI_API void uECC_vli_clear(uECC_word_t *vli, wordcount_t num_words) { + wordcount_t i; + for (i = 0; i < num_words; ++i) { + vli[i] = 0; + } +} +#define EVEN(vli) (!(vli[0] & 1)) +static void vli_modInv_update(uECC_word_t *uv, + const uECC_word_t *mod, + wordcount_t num_words) { + uECC_word_t carry = 0; + if (!EVEN(uv)) { + carry = uECC_vli_add(uv, uv, mod, num_words); + } + uECC_vli_rshift1(uv, num_words); + if (carry) { + uv[num_words - 1] |= HIGH_BIT_SET; + } +} +/* Computes result = (1 / input) % mod. All VLIs are the same size. + See "From Euclid's GCD to Montgomery Multiplication to the Great Divide" */ +uECC_VLI_API void uECC_vli_modInv(uECC_word_t *result, + const uECC_word_t *input, + const uECC_word_t *mod, + wordcount_t num_words) { + uECC_word_t a[uECC_MAX_WORDS], b[uECC_MAX_WORDS], u[uECC_MAX_WORDS], v[uECC_MAX_WORDS]; + cmpresult_t cmpResult; + + if (uECC_vli_isZero(input, num_words)) { + uECC_vli_clear(result, num_words); + return; + } + + uECC_vli_set(a, input, num_words); + uECC_vli_set(b, mod, num_words); + uECC_vli_clear(u, num_words); + u[0] = 1; + uECC_vli_clear(v, num_words); + while ((cmpResult = uECC_vli_cmp_unsafe(a, b, num_words)) != 0) { + if (EVEN(a)) { + uECC_vli_rshift1(a, num_words); + vli_modInv_update(u, mod, num_words); + } else if (EVEN(b)) { + uECC_vli_rshift1(b, num_words); + vli_modInv_update(v, mod, num_words); + } else if (cmpResult > 0) { + uECC_vli_sub(a, a, b, num_words); + uECC_vli_rshift1(a, num_words); + if (uECC_vli_cmp_unsafe(u, v, num_words) < 0) { + uECC_vli_add(u, u, mod, num_words); + } + uECC_vli_sub(u, u, v, num_words); + vli_modInv_update(u, mod, num_words); + } else { + uECC_vli_sub(b, b, a, num_words); + uECC_vli_rshift1(b, num_words); + if (uECC_vli_cmp_unsafe(v, u, num_words) < 0) { + uECC_vli_add(v, v, mod, num_words); + } + uECC_vli_sub(v, v, u, num_words); + vli_modInv_update(v, mod, num_words); + } + } + uECC_vli_set(result, u, num_words); +} +static void bits2int(uECC_word_t *native, + const uint8_t *bits, + unsigned bits_size, + uECC_Curve curve) { + unsigned num_n_bytes = BITS_TO_BYTES(curve->num_n_bits); + unsigned num_n_words = BITS_TO_WORDS(curve->num_n_bits); + int shift; + uECC_word_t carry; + uECC_word_t *ptr; + + if (bits_size > num_n_bytes) { + bits_size = num_n_bytes; + } + + uECC_vli_clear(native, num_n_words); + bcopy((uint8_t *) native, bits, bits_size); + if (bits_size * 8 <= (unsigned)curve->num_n_bits) { + return; + } + shift = bits_size * 8 - curve->num_n_bits; + carry = 0; + ptr = native + num_n_words; + while (ptr-- > native) { + uECC_word_t temp = *ptr; + *ptr = (temp >> shift) | carry; + carry = temp << (uECC_WORD_BITS - shift); + } + + /* Reduce mod curve_n */ + if (uECC_vli_cmp_unsafe(curve->n, native, num_n_words) != 1) { + uECC_vli_sub(native, native, curve->n, num_n_words); + } +} + +/* Counts the number of words in vli. */ +static wordcount_t vli_numDigits(const uECC_word_t *vli, const wordcount_t max_words) { + wordcount_t i; + /* Search from the end until we find a non-zero digit. + We do it in reverse because we expect that most digits will be nonzero. */ + for (i = max_words - 1; i >= 0 && vli[i] == 0; --i) { + } + + return (i + 1); +} +/* Counts the number of bits required to represent vli. */ +uECC_VLI_API bitcount_t uECC_vli_numBits(const uECC_word_t *vli, const wordcount_t max_words) { + uECC_word_t i; + uECC_word_t digit; + + wordcount_t num_digits = vli_numDigits(vli, max_words); + if (num_digits == 0) { + return 0; + } + + digit = vli[num_digits - 1]; + for (i = 0; digit; ++i) { + digit >>= 1; + } + + return (((bitcount_t)(num_digits - 1) << uECC_WORD_BITS_SHIFT) + i); +} + +/* Computes result = product % mod, where product is 2N words long. */ +/* Currently only designed to work for curve_p or curve_n. */ +uECC_VLI_API void uECC_vli_mmod(uECC_word_t *result, + uECC_word_t *product, + const uECC_word_t *mod, + wordcount_t num_words) { + uECC_word_t mod_multiple[2 * uECC_MAX_WORDS]; + uECC_word_t tmp[2 * uECC_MAX_WORDS]; + uECC_word_t *v[2] = {tmp, product}; + uECC_word_t index; + + /* Shift mod so its highest set bit is at the maximum position. */ + bitcount_t shift = (num_words * 2 * uECC_WORD_BITS) - uECC_vli_numBits(mod, num_words); + wordcount_t word_shift = shift / uECC_WORD_BITS; + wordcount_t bit_shift = shift % uECC_WORD_BITS; + uECC_word_t carry = 0; + uECC_vli_clear(mod_multiple, word_shift); + if (bit_shift > 0) { + for(index = 0; index < (uECC_word_t)num_words; ++index) { + mod_multiple[word_shift + index] = (mod[index] << bit_shift) | carry; + carry = mod[index] >> (uECC_WORD_BITS - bit_shift); + } + } else { + uECC_vli_set(mod_multiple + word_shift, mod, num_words); + } + + for (index = 1; shift >= 0; --shift) { + uECC_word_t borrow = 0; + wordcount_t i; + for (i = 0; i < num_words * 2; ++i) { + uECC_word_t diff = v[index][i] - mod_multiple[i] - borrow; + if (diff != v[index][i]) { + borrow = (diff > v[index][i]); + } + v[1 - index][i] = diff; + } + index = !(index ^ borrow); /* Swap the index if there was no borrow */ + uECC_vli_rshift1(mod_multiple, num_words); + mod_multiple[num_words - 1] |= mod_multiple[num_words] << (uECC_WORD_BITS - 1); + uECC_vli_rshift1(mod_multiple + num_words, num_words); + } + uECC_vli_set(result, v[index], num_words); +} +/* Computes result = (left * right) % mod. */ +uECC_VLI_API void uECC_vli_modMult(uECC_word_t *result, + const uECC_word_t *left, + const uECC_word_t *right, + const uECC_word_t *mod, + wordcount_t num_words) { + uECC_word_t product[2 * uECC_MAX_WORDS]; + uECC_vli_mult(product, left, right, num_words); + uECC_vli_mmod(result, product, mod, num_words); +} + + + +/* Input P = (x1, y1, Z), Q = (x2, y2, Z) + Output P' = (x1', y1', Z3), P + Q = (x3, y3, Z3) + or P => P', Q => P + Q +*/ +static void XYcZ_add(uECC_word_t * X1, + uECC_word_t * Y1, + uECC_word_t * X2, + uECC_word_t * Y2, + uECC_Curve curve) { + /* t1 = X1, t2 = Y1, t3 = X2, t4 = Y2 */ + uECC_word_t t5[uECC_MAX_WORDS]; + wordcount_t num_words = curve->num_words; + + uECC_vli_modSub(t5, X2, X1, curve->p, num_words); /* t5 = x2 - x1 */ + uECC_vli_modSquare_fast(t5, t5, curve); /* t5 = (x2 - x1)^2 = A */ + uECC_vli_modMult_fast(X1, X1, t5, curve); /* t1 = x1*A = B */ + uECC_vli_modMult_fast(X2, X2, t5, curve); /* t3 = x2*A = C */ + uECC_vli_modSub(Y2, Y2, Y1, curve->p, num_words); /* t4 = y2 - y1 */ + uECC_vli_modSquare_fast(t5, Y2, curve); /* t5 = (y2 - y1)^2 = D */ + + uECC_vli_modSub(t5, t5, X1, curve->p, num_words); /* t5 = D - B */ + uECC_vli_modSub(t5, t5, X2, curve->p, num_words); /* t5 = D - B - C = x3 */ + uECC_vli_modSub(X2, X2, X1, curve->p, num_words); /* t3 = C - B */ + uECC_vli_modMult_fast(Y1, Y1, X2, curve); /* t2 = y1*(C - B) */ + uECC_vli_modSub(X2, X1, t5, curve->p, num_words); /* t3 = B - x3 */ + uECC_vli_modMult_fast(Y2, Y2, X2, curve); /* t4 = (y2 - y1)*(B - x3) */ + uECC_vli_modSub(Y2, Y2, Y1, curve->p, num_words); /* t4 = y3 */ + + uECC_vli_set(X2, t5, num_words); +} +/* Point multiplication algorithm using Montgomery's ladder with co-Z coordinates. +From http://eprint.iacr.org/2011/338.pdf +*/ + +/* Modify (x1, y1) => (x1 * z^2, y1 * z^3) */ +static void apply_z(uECC_word_t * X1, + uECC_word_t * Y1, + const uECC_word_t * const Z, + uECC_Curve curve) { + uECC_word_t t1[uECC_MAX_WORDS]; + + uECC_vli_modSquare_fast(t1, Z, curve); /* z^2 */ + uECC_vli_modMult_fast(X1, X1, t1, curve); /* x1 * z^2 */ + uECC_vli_modMult_fast(t1, t1, Z, curve); /* z^3 */ + uECC_vli_modMult_fast(Y1, Y1, t1, curve); /* y1 * z^3 */ +} + +static bitcount_t smax(bitcount_t a, bitcount_t b) { + return (a > b ? a : b); +} +/* Constant-time comparison function - secure way to compare long integers */ +/* Returns one if left == right, zero otherwise. */ +uECC_VLI_API uECC_word_t uECC_vli_equal(const uECC_word_t *left, + const uECC_word_t *right, + wordcount_t num_words) { + uECC_word_t diff = 0; + wordcount_t i; + for (i = num_words - 1; i >= 0; --i) { + diff |= (left[i] ^ right[i]); + } + return (diff == 0); +} + + + +int uECC_verify(const uint8_t *public_key, + const uint8_t *message_hash, + unsigned hash_size, + const uint8_t *signature, + uECC_Curve curve) { + uECC_word_t u1[uECC_MAX_WORDS], u2[uECC_MAX_WORDS]; + uECC_word_t z[uECC_MAX_WORDS]; + uECC_word_t sum[uECC_MAX_WORDS * 2]; + uECC_word_t rx[uECC_MAX_WORDS]; + uECC_word_t ry[uECC_MAX_WORDS]; + uECC_word_t tx[uECC_MAX_WORDS]; + uECC_word_t ty[uECC_MAX_WORDS]; + uECC_word_t tz[uECC_MAX_WORDS]; + const uECC_word_t *points[4]; + const uECC_word_t *point; + bitcount_t num_bits; + bitcount_t i; + uECC_word_t *_public = (uECC_word_t *)public_key; + uECC_word_t r[uECC_MAX_WORDS], s[uECC_MAX_WORDS]; + wordcount_t num_words = curve->num_words; + wordcount_t num_n_words = BITS_TO_WORDS(curve->num_n_bits); + + rx[num_n_words - 1] = 0; + r[num_n_words - 1] = 0; + s[num_n_words - 1] = 0; + + bcopy((uint8_t *) r, signature, curve->num_bytes); + bcopy((uint8_t *) s, signature + curve->num_bytes, curve->num_bytes); + + + /* r, s must not be 0. */ + if (uECC_vli_isZero(r, num_words) || uECC_vli_isZero(s, num_words)) { + return 0; + } + + /* r, s must be < n. */ + if (uECC_vli_cmp_unsafe(curve->n, r, num_n_words) != 1 || + uECC_vli_cmp_unsafe(curve->n, s, num_n_words) != 1) { + return 0; + } + + /* Calculate u1 and u2. */ + uECC_vli_modInv(z, s, curve->n, num_n_words); /* z = 1/s */ + u1[num_n_words - 1] = 0; + bits2int(u1, message_hash, hash_size, curve); + uECC_vli_modMult(u1, u1, z, curve->n, num_n_words); /* u1 = e/s */ + uECC_vli_modMult(u2, r, z, curve->n, num_n_words); /* u2 = r/s */ + + /* Calculate sum = G + Q. */ + uECC_vli_set(sum, _public, num_words); + uECC_vli_set(sum + num_words, _public + num_words, num_words); + uECC_vli_set(tx, curve->G, num_words); + uECC_vli_set(ty, curve->G + num_words, num_words); + uECC_vli_modSub(z, sum, tx, curve->p, num_words); /* z = x2 - x1 */ + XYcZ_add(tx, ty, sum, sum + num_words, curve); + uECC_vli_modInv(z, z, curve->p, num_words); /* z = 1/z */ + apply_z(sum, sum + num_words, z, curve); + + /* Use Shamir's trick to calculate u1*G + u2*Q */ + points[0] = 0; + points[1] = curve->G; + points[2] = _public; + points[3] = sum; + num_bits = smax(uECC_vli_numBits(u1, num_n_words), + uECC_vli_numBits(u2, num_n_words)); + + point = points[(!!uECC_vli_testBit(u1, num_bits - 1)) | + ((!!uECC_vli_testBit(u2, num_bits - 1)) << 1)]; + uECC_vli_set(rx, point, num_words); + uECC_vli_set(ry, point + num_words, num_words); + uECC_vli_clear(z, num_words); + z[0] = 1; + + for (i = num_bits - 2; i >= 0; --i) { + uECC_word_t index; + curve->double_jacobian(rx, ry, z, curve); + + index = (!!uECC_vli_testBit(u1, i)) | ((!!uECC_vli_testBit(u2, i)) << 1); + point = points[index]; + if (point) { + uECC_vli_set(tx, point, num_words); + uECC_vli_set(ty, point + num_words, num_words); + apply_z(tx, ty, z, curve); + uECC_vli_modSub(tz, rx, tx, curve->p, num_words); /* Z = x2 - x1 */ + XYcZ_add(tx, ty, rx, ry, curve); + uECC_vli_modMult_fast(z, z, tz, curve); + } + } + + uECC_vli_modInv(z, z, curve->p, num_words); /* Z = 1/Z */ + apply_z(rx, ry, z, curve); + + /* v = x1 (mod n) */ + if (uECC_vli_cmp_unsafe(curve->n, rx, num_n_words) != 1) { + uECC_vli_sub(rx, rx, curve->n, num_n_words); + } + + /* Accept only if v == r. */ + return (int)(uECC_vli_equal(rx, r, num_words)); +} + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/uECC.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/uECC.h new file mode 100644 index 0000000..3dbda40 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/ecc/uECC.h @@ -0,0 +1,136 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file uECC.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef __UECC_H__ +#define __UECC_H__ + +#ifdef __cplusplus +extern "C" { +#endif +/* Includes ------------------------------------------------------------------*/ +#include + +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +typedef uint32_t uECC_word_t; +typedef uint64_t uECC_dword_t; +typedef int8_t wordcount_t; +typedef int16_t bitcount_t; +typedef int8_t cmpresult_t; +/* Public define ------------------------------------------------------------*/ +#define HIGH_BIT_SET 0x80000000 +#define uECC_WORD_BITS 32 +#define uECC_MAX_WORDS 8 +#define uECC_WORD_BITS_SHIFT 5 +#define uECC_WORD_BITS_MASK 0x01F + + +#define num_bytes_secp256r1 32 +#define num_words_secp256r1 8 + + + + +#define BYTES_TO_WORDS_8(a, b, c, d, e, f, g, h) 0x##d##c##b##a, 0x##h##g##f##e +#define BYTES_TO_WORDS_4(a, b, c, d) 0x##d##c##b##a + + +#define uECC_WORD_SIZE 4 +#define BITS_TO_WORDS(num_bits) ((num_bits + ((uECC_WORD_SIZE * 8) - 1)) / (uECC_WORD_SIZE * 8)) +#define BITS_TO_BYTES(num_bits) ((num_bits + 7) / 8) + +typedef const struct uECC_Curve_t * uECC_Curve; +struct uECC_Curve_t { + wordcount_t num_words; + wordcount_t num_bytes; + bitcount_t num_n_bits; + uECC_word_t p[uECC_MAX_WORDS]; + uECC_word_t n[uECC_MAX_WORDS]; + uECC_word_t G[uECC_MAX_WORDS * 2]; + uECC_word_t b[uECC_MAX_WORDS]; + void (*double_jacobian)(uECC_word_t * X1, + uECC_word_t * Y1, + uECC_word_t * Z1, + uECC_Curve curve); + void (*x_side)(uECC_word_t *result, const uECC_word_t *x, uECC_Curve curve); + void (*mmod_fast)(uECC_word_t *result, uECC_word_t *product); +}; + + + +extern const struct uECC_Curve_t curve_secp256r1; + +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +int uECC_verify(const uint8_t *public_key, + const uint8_t *message_hash, + unsigned hash_size, + const uint8_t *signature, + uECC_Curve curve); + + +#ifdef __cplusplus +} +#endif + +#endif //__UECC_H__ +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/error/ns_error.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/error/ns_error.c new file mode 100644 index 0000000..b365d16 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/error/ns_error.c @@ -0,0 +1,139 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_error.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "ns_error.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Save the error state. + * @param[in] error information + * @return none + */ +static void error_save_and_stop(uint32_t info) +{ + /* static error variables - in order to prevent removal by optimizers */ + static volatile struct + { + uint32_t err_code; + uint32_t line_num; + const uint8_t * p_file_name; + } m_error_data = {0,0,NULL}; + + // 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; + + m_error_data.err_code = ((error_info_t *)(info))->err_code; + m_error_data.line_num = (unsigned int) ((error_info_t *)(info))->line_num; + m_error_data.p_file_name = ((error_info_t *)(info))->p_file_name; + + + + + while (loop); + +} + + + + +/** + * @brief Handle the error state. + * @param[in] error_code error code. + * @param[in] line_num error file line number. + * @param[in] p_file_name error file name. + * @return none + */ +void error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name) +{ + error_info_t error_info = + { + .line_num = line_num, + .p_file_name = p_file_name, + .err_code = error_code, + }; + error_save_and_stop((uint32_t)(&error_info)); +} + + + + + + + + + + + + + + + + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/error/ns_error.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/error/ns_error.h new file mode 100644 index 0000000..1c6c5e2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/error/ns_error.h @@ -0,0 +1,146 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_error.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef __NS_LIB_ERROR_H__ +#define __NS_LIB_ERROR_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include +#include +#include +/* Public define ------------------------------------------------------------*/ +#define ERROR_BASE_NUM (0x0) + +#define ERROR_SUCCESS (ERROR_BASE_NUM + 0) +#define ERROR_INTERNAL (ERROR_BASE_NUM + 1) +#define ERROR_NO_MEM (ERROR_BASE_NUM + 2) +#define ERROR_NOT_FOUND (ERROR_BASE_NUM + 3) +#define ERROR_NOT_SUPPORTED (ERROR_BASE_NUM + 4) +#define ERROR_INVALID_PARAM (ERROR_BASE_NUM + 5) +#define ERROR_INVALID_STATE (ERROR_BASE_NUM + 6) +#define ERROR_INVALID_LENGTH (ERROR_BASE_NUM + 7) +#define ERROR_INVALID_FLAGS (ERROR_BASE_NUM + 8) +#define ERROR_INVALID_DATA (ERROR_BASE_NUM + 9) +#define ERROR_DATA_SIZE (ERROR_BASE_NUM + 10) +#define ERROR_TIMEOUT (ERROR_BASE_NUM + 11) +#define ERROR_NULL (ERROR_BASE_NUM + 12) +#define ERROR_FORBIDDEN (ERROR_BASE_NUM + 13) +#define ERROR_INVALID_ADDR (ERROR_BASE_NUM + 14) +#define ERROR_BUSY (ERROR_BASE_NUM + 15) +#define ERROR_CRC (ERROR_BASE_NUM + 16) +#define ERROR_HARD_FAULT (ERROR_BASE_NUM + 17) +/* Public typedef -----------------------------------------------------------*/ +typedef struct +{ + uint16_t line_num; + uint8_t const * p_file_name; + uint32_t err_code; +} error_info_t; +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +void error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name); + + +#define ERROR_HANDLER(ERR_CODE) \ + do \ + { \ + error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__); \ + } while (0) + + + +#define ERROR_CHECK(ERR_CODE) \ + do \ + { \ + const uint32_t LOCAL_ERR_CODE = (ERR_CODE); \ + if (LOCAL_ERR_CODE != ERROR_SUCCESS) \ + { \ + ERROR_HANDLER(LOCAL_ERR_CODE); \ + } \ + } while (0) + + + + + + + + +#ifdef __cplusplus +} +#endif + + + + + + + + +#endif //__NS_LIB_ERROR_H__ +/** + * @} + */ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log.h new file mode 100644 index 0000000..005e0ed --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log.h @@ -0,0 +1,179 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_log.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef __NS_LOG_H__ +#define __NS_LOG_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "app_user_config.h" + +#if (NS_LOG_LPUART_ENABLE) +#include "ns_log_lpuart.h" +#elif (NS_LOG_USART_ENABLE) +#include "ns_log_usart.h" +#elif (NS_LOG_RTT_ENABLE) +#include "ns_log_rtt.h" +#endif + +/* Private define ------------------------------------------------------------*/ +#ifndef NS_LOG_ERROR_ENABLE +#define NS_LOG_ERROR_ENABLE 0 +#endif +#ifndef NS_LOG_WARNING_ENABLE +#define NS_LOG_WARNING_ENABLE 0 +#endif +#ifndef NS_LOG_INFO_ENABLE +#define NS_LOG_INFO_ENABLE 0 +#endif +#ifndef NS_LOG_DEBUG_ENABLE +#define NS_LOG_DEBUG_ENABLE 0 +#endif +#ifndef NS_LOG_LPUART_ENABLE +#define NS_LOG_LPUART_ENABLE 0 +#endif +#ifndef NS_LOG_USART_ENABLE +#define NS_LOG_USART_ENABLE 0 +#endif +#ifndef NS_LOG_RTT_ENABLE +#define NS_LOG_RTT_ENABLE 0 +#endif + +#ifndef PRINTF_COLOR_ENABLE +#define PRINTF_COLOR_ENABLE 0 +#endif +#define LOG_COLOR_RED "\033[0;31m" +#define LOG_COLOR_YELLOW "\033[0;33m" +#define LOG_COLOR_CYAN "\033[0;36m" +#define LOG_COLOR_GREEN "\033[0;32m" + + +#if (NS_LOG_LPUART_ENABLE) +#define NS_LOG_INTERNAL_OUTPUT(color, ...) NS_LOG_LPUART_OUTPUT(color, __VA_ARGS__) +#define NS_LOG_INTERNAL_INIT() NS_LOG_LPUART_INIT() +#define NS_LOG_INTERNAL_DEINIT() +#elif (NS_LOG_USART_ENABLE) +#define NS_LOG_INTERNAL_OUTPUT(color, ...) NS_LOG_USART_OUTPUT(color, __VA_ARGS__) +#define NS_LOG_INTERNAL_INIT() NS_LOG_USART_INIT() +#define NS_LOG_INTERNAL_DEINIT() NS_LOG_USART_DEINIT() +#elif (NS_LOG_RTT_ENABLE) +#define NS_LOG_INTERNAL_OUTPUT(color, ...) NS_LOG_RTT_OUTPUT(color, __VA_ARGS__) +#define NS_LOG_INTERNAL_INIT() NS_LOG_RTT_INIT() +#define NS_LOG_INTERNAL_DEINIT() NS_LOG_RTT_DEINIT() +#else +#define NS_LOG_INTERNAL_OUTPUT(color, ...) +#define NS_LOG_INTERNAL_INIT() +#define NS_LOG_INTERNAL_DEINIT() +#endif +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#if NS_LOG_ERROR_ENABLE +#define NS_LOG_ERROR(...) NS_LOG_INTERNAL_OUTPUT(LOG_COLOR_RED, __VA_ARGS__) +#else +#define NS_LOG_ERROR( ...) +#endif + +#if NS_LOG_WARNING_ENABLE +#define NS_LOG_WARNING(...) NS_LOG_INTERNAL_OUTPUT(LOG_COLOR_YELLOW, __VA_ARGS__) +#else +#define NS_LOG_WARNING( ...) +#endif + +#if NS_LOG_INFO_ENABLE +#define NS_LOG_INFO(...) NS_LOG_INTERNAL_OUTPUT(LOG_COLOR_CYAN, __VA_ARGS__) +#else +#define NS_LOG_INFO( ...) +#endif + +#if NS_LOG_DEBUG_ENABLE +#define NS_LOG_DEBUG(...) NS_LOG_INTERNAL_OUTPUT(LOG_COLOR_GREEN, __VA_ARGS__) +#else +#define NS_LOG_DEBUG( ...) +#endif + + +/** + * @brief Initialization the log module + * @param + * @return + * @note + */ +#define NS_LOG_INIT() NS_LOG_INTERNAL_INIT() + +/** + * @brief Deinitialize the log module + * @param + * @return + * @note + */ +#define NS_LOG_DEINIT() NS_LOG_INTERNAL_DEINIT() +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ + + + +#ifdef __cplusplus +} +#endif + +#endif /* __NS_LOG_H__ */ +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_lpuart.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_lpuart.c new file mode 100644 index 0000000..0566185 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_lpuart.c @@ -0,0 +1,198 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_log_lpuart.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include +#include "n32wb03x.h" +#include "ns_log.h" +#if (NS_LOG_LPUART_ENABLE) +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define _LPUART1_COM_ (0) + +#if (_LPUART1_COM_ == 0) +#define LPUARTx LPUART1 +#define LPUARTx_CLK RCC_LPUART1CLK +#define LPUARTx_GPIO GPIOB +#define LPUARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTx_RxPin GPIO_PIN_2 +#define LPUARTx_TxPin GPIO_PIN_1 +#define LPUARTx_Rx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTx_Tx_GPIO_AF GPIO_AF4_LPUART1 +#else +#define LPUARTx LPUART1 +#define LPUARTx_CLK RCC_LPUART1CLK +#define LPUARTx_GPIO GPIOB +#define LPUARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTx_RxPin GPIO_PIN_11 +#define LPUARTx_TxPin GPIO_PIN_12 +#define LPUARTx_Rx_GPIO_AF GPIO_AF2_LPUART1 +#define LPUARTx_Tx_GPIO_AF GPIO_AF2_LPUART1 +#endif + + +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +//extern void lpuart_init(void); +void RCC_Configuration(uint32_t LPUART_CLK_SRC); +void GPIO_Configuration(void); +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief init the log feature + */ +void ns_log_lpuart_init(void) +{ + LPUART_InitType LPUART_InitStructure; + /* System Clocks Configuration */ +#if 0 + RCC_Configuration(RCC_LPUARTCLK_SRC_LSI_LSE); +#else + RCC_Configuration(RCC_LPUARTCLK_SRC_APB1); +#endif + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + LPUART_DeInit(LPUARTx); + /* LPUARTx configuration ------------------------------------------------------*/ + LPUART_InitStructure.BaudRate = 115200; + LPUART_InitStructure.Parity = LPUART_PE_NO; + LPUART_InitStructure.RtsThreshold = LPUART_RTSTH_FIFOFU; + LPUART_InitStructure.HardwareFlowControl = LPUART_HFCTRL_NONE; + LPUART_InitStructure.Mode = LPUART_MODE_TX; + /* Configure LPUARTx */ + LPUART_Init(LPUARTx, &LPUART_InitStructure); + +} + +/** + * @brief Configures the different system clocks. + * @param LPUART_CLK_SRC: specifies the LPUARTx clock source. + */ +void RCC_Configuration(uint32_t LPUART_CLK_SRC) +{ + switch(LPUART_CLK_SRC) + { + case RCC_LPUARTCLK_SRC_LSI_LSE: + { + /* Specifies the LPUARTx clock source, LSE selected as LPUARTx clock */ + RCC_ConfigLpuartClk(LPUARTx_CLK, RCC_LPUARTCLK_SRC_LSI_LSE); + } + break; + default: + { + /* Specifies the LPUARTx clock source, APB1 selected as LPUARTx clock */ + RCC_ConfigLpuartClk(LPUARTx_CLK, RCC_LPUARTCLK_SRC_APB1); + } + break; + } + + /* Enable LPUARTx Clock */ + RCC_EnableLpuartClk(ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(LPUARTx_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure LPUARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = LPUARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LPUARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(LPUARTx_GPIO, &GPIO_InitStructure); + +} + +void ns_log_lpuart_deinit(void) +{ + +} + +/* retarget the C library printf function to the LPUARTx */ +int fputc(int ch, FILE* f) +{ + static uint8_t func_lock = 1; + if(func_lock) + { + func_lock = 0; + LPUART_SendData(LPUARTx, (uint8_t)ch); + while (LPUART_GetFlagStatus(LPUARTx, LPUART_FLAG_TXC) == RESET); + LPUART_ClrFlag(LPUARTx, LPUART_FLAG_TXC); + func_lock = 1; + } + + return (ch); +} +#endif +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_lpuart.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_lpuart.h new file mode 100644 index 0000000..9402d68 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_lpuart.h @@ -0,0 +1,104 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_log_lpuart.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ + +#ifndef __NS_LOG_LPUART_H__ +#define __NS_LOG_LPUART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define NS_LOG_LPUART_OUTPUT(color, ...) \ +do{ \ + if(PRINTF_COLOR_ENABLE) \ + { \ + printf("%s",color ); \ + } \ + printf(__VA_ARGS__); \ +}while(0) + + +#define NS_LOG_LPUART_INIT() \ +do{ \ + ns_log_lpuart_init(); \ +}while(0) + +#define NS_LOG_LPUART_DEINIT() \ +do{ \ + ns_log_lpuart_deinit(); \ +}while(0) +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +void ns_log_lpuart_init(void); +void ns_log_lpuart_deinit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NS_LOG_LPUART_H__ */ +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_usart.c new file mode 100644 index 0000000..29279b9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_usart.c @@ -0,0 +1,171 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_log_usart.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include +#include "n32wb03x.h" +#include "ns_log.h" + +#if (NS_LOG_USART_ENABLE) +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk +#endif + +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief init the log feature + */ +void ns_log_usart_init(void) +{ + GPIO_InitType GPIO_InitStructure; + USART_InitType USART_InitStructure; + + /* System Clocks Configuration */ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + + /* Configure the GPIO ports */ + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + + +} + +void ns_log_usart_deinit(void) +{ + /*ns_link rx require hardware pull up */ + USART_Enable(USARTx, DISABLE); + GPIO_DeInitPin(USARTx_GPIO,USARTx_TxPin); +} + +/* retarget the C library printf function to the USART */ +int fputc(int ch, FILE* f) +{ + static uint8_t func_lock = 1; + if(func_lock) + { + func_lock = 0; + USART_SendData(USARTx, (uint8_t)ch); + while (USART_GetFlagStatus(USARTx, USART_FLAG_TXDE) == RESET); + func_lock = 1; + } + + return (ch); +} +#endif + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_usart.h new file mode 100644 index 0000000..77cc84b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/log/ns_log_usart.h @@ -0,0 +1,104 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_log_usart.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ + +#ifndef __NS_LOG_LPUART_H__ +#define __NS_LOG_LPUART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define NS_LOG_USART_OUTPUT(color, ...) \ +do{ \ + if(PRINTF_COLOR_ENABLE) \ + { \ + printf("%s",color ); \ + } \ + printf(__VA_ARGS__); \ +}while(0) + + +#define NS_LOG_USART_INIT() \ +do{ \ + ns_log_usart_init(); \ +}while(0) + +#define NS_LOG_USART_DEINIT() \ +do{ \ + ns_log_usart_deinit(); \ +}while(0) +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +void ns_log_usart_init(void); +void ns_log_usart_deinit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NS_LOG_LPUART_H__ */ +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/scheduler/ns_scheduler.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/scheduler/ns_scheduler.c new file mode 100644 index 0000000..8185528 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/scheduler/ns_scheduler.c @@ -0,0 +1,241 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_scheduler.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "ns_scheduler.h" + + + +#define CRITICAL_REGION_ENTER() +#define CRITICAL_REGION_EXIT() + + +typedef struct +{ + app_sched_event_handler_t handler; /**< Pointer to event handler to receive the event. */ + uint16_t event_data_size; /**< Size of event data. */ +} event_header_t; + +static event_header_t * m_queue_event_headers; /**< Array for holding the queue event headers. */ +static uint8_t * m_queue_event_data; /**< Array for holding the queue event data. */ +static volatile uint8_t m_queue_start_index; /**< Index of queue entry at the start of the queue. */ +static volatile uint8_t m_queue_end_index; /**< Index of queue entry at the end of the queue. */ +static uint16_t m_queue_event_size; /**< Maximum event size in queue. */ +static uint16_t m_queue_size; /**< Number of queue entries. */ + + + +static __inline bool is_word_aligned(void const* p) +{ + return (((uintptr_t)p & 0x03) == 0); +} + + +/**@brief Function for incrementing a queue index, and handle wrap-around. + * + * @param[in] index Old index. + * + * @return New (incremented) index. + */ +static __inline uint8_t next_index(uint8_t index) +{ + return (index < m_queue_size) ? (index + 1) : 0; +} + + +static __inline uint8_t app_sched_queue_full() +{ + uint8_t tmp = m_queue_start_index; + return next_index(m_queue_end_index) == tmp; +} + +/**@brief Macro for checking if a queue is full. */ +#define APP_SCHED_QUEUE_FULL() app_sched_queue_full() + + +static __inline uint8_t app_sched_queue_empty() +{ + uint8_t tmp = m_queue_start_index; + return m_queue_end_index == tmp; +} + +/**@brief Macro for checking if a queue is empty. */ +#define APP_SCHED_QUEUE_EMPTY() app_sched_queue_empty() + + +uint32_t app_sched_init(uint16_t event_size, uint16_t queue_size, void * p_event_buffer) +{ + uint16_t data_start_index = (queue_size + 1) * sizeof(event_header_t); + + // Check that buffer is correctly aligned + if (!is_word_aligned(p_event_buffer)) + { + return 1; + } + + // Initialize event scheduler + m_queue_event_headers = p_event_buffer; + m_queue_event_data = &((uint8_t *)p_event_buffer)[data_start_index]; + m_queue_end_index = 0; + m_queue_start_index = 0; + m_queue_event_size = event_size; + m_queue_size = queue_size; + + return 0; +} + + + +uint16_t app_sched_queue_space_get() +{ + uint16_t start = m_queue_start_index; + uint16_t end = m_queue_end_index; + uint16_t free_space = m_queue_size - ((end >= start) ? + (end - start) : (m_queue_size + 1 - start + end)); + return free_space; +} + + +uint32_t app_sched_event_put(void const * p_event_data, + uint16_t event_data_size, + app_sched_event_handler_t handler) +{ + uint32_t err_code; + + if (event_data_size <= m_queue_event_size) + { + uint16_t event_index = 0xFFFF; + + CRITICAL_REGION_ENTER(); + + if (!APP_SCHED_QUEUE_FULL()) + { + event_index = m_queue_end_index; + m_queue_end_index = next_index(m_queue_end_index); + } + + CRITICAL_REGION_EXIT(); + + if (event_index != 0xFFFF) + { + // NOTE: This can be done outside the critical region since the event consumer will + // always be called from the main loop, and will thus never interrupt this code. + m_queue_event_headers[event_index].handler = handler; + if ((p_event_data != NULL) && (event_data_size > 0)) + { + memcpy(&m_queue_event_data[event_index * m_queue_event_size], + p_event_data, + event_data_size); + m_queue_event_headers[event_index].event_data_size = event_data_size; + } + else + { + m_queue_event_headers[event_index].event_data_size = 0; + } + + err_code = 0; + } + else + { + err_code = 1; + } + } + else + { + err_code = 1; + } + + return err_code; +} + + + + + +void app_sched_execute(void) +{ + while (!APP_SCHED_QUEUE_EMPTY()) + { + // Since this function is only called from the main loop, there is no + // need for a critical region here, however a special care must be taken + // regarding update of the queue start index (see the end of the loop). + uint16_t event_index = m_queue_start_index; + + void * p_event_data; + uint16_t event_data_size; + app_sched_event_handler_t event_handler; + + p_event_data = &m_queue_event_data[event_index * m_queue_event_size]; + event_data_size = m_queue_event_headers[event_index].event_data_size; + event_handler = m_queue_event_headers[event_index].handler; + + event_handler(p_event_data, event_data_size); + + // Event processed, now it is safe to move the queue start index, + // so the queue entry occupied by this event can be used to store + // a next one. + m_queue_start_index = next_index(m_queue_start_index); + } +} + + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/scheduler/ns_scheduler.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/scheduler/ns_scheduler.h new file mode 100644 index 0000000..df1d4f4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/scheduler/ns_scheduler.h @@ -0,0 +1,194 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_scheduler.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef __NS_SCHEDULER_H__ +#define __NS_SCHEDULER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ + + + +#include +#include +#include +#include + + +#define APP_SCHED_EVENT_HEADER_SIZE 8 /**< Size of app_scheduler.event_header_t (only for use inside APP_SCHED_BUF_SIZE()). */ + + +/**@brief Compute number of bytes required to hold the scheduler buffer. + * + * @param[in] EVENT_SIZE Maximum size of events to be passed through the scheduler. + * @param[in] QUEUE_SIZE Number of entries in scheduler queue (i.e. the maximum number of events + * that can be scheduled for execution). + * + * @return Required scheduler buffer size (in bytes). + */ +#define APP_SCHED_BUF_SIZE(EVENT_SIZE, QUEUE_SIZE) \ + (((EVENT_SIZE) + APP_SCHED_EVENT_HEADER_SIZE) * ((QUEUE_SIZE) + 1)) + +/**@brief Scheduler event handler type. */ +typedef void (*app_sched_event_handler_t)(void * p_event_data, uint16_t event_size); + +/**@brief Macro for performing integer division, making sure the result is rounded up. + * + * @details One typical use for this is to compute the number of objects with size B is needed to + * hold A number of bytes. + * + * @param[in] A Numerator. + * @param[in] B Denominator. + * + * @return Integer result of dividing A by B, rounded up. + */ +#define CEIL_DIV(A, B) \ + (((A) + (B) - 1) / (B)) +/**@brief Macro for initializing the event scheduler. + * + * @details It will also handle dimensioning and allocation of the memory buffer required by the + * scheduler, making sure the buffer is correctly aligned. + * + * @param[in] EVENT_SIZE Maximum size of events to be passed through the scheduler. + * @param[in] QUEUE_SIZE Number of entries in scheduler queue (i.e. the maximum number of events + * that can be scheduled for execution). + * + * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it + * several times as long as it is from the same location, e.g. to do a reinitialization). + */ +#define NS_SCHED_INIT(EVENT_SIZE, QUEUE_SIZE) \ + do \ + { \ + static uint32_t APP_SCHED_BUF[CEIL_DIV(APP_SCHED_BUF_SIZE((EVENT_SIZE), (QUEUE_SIZE)), \ + sizeof(uint32_t))]; \ + uint32_t ERR_CODE = app_sched_init((EVENT_SIZE), (QUEUE_SIZE), APP_SCHED_BUF); \ + \ + } while (0) + + +/**@brief Function for initializing the Scheduler. + * + * @details It must be called before entering the main loop. + * + * @param[in] max_event_size Maximum size of events to be passed through the scheduler. + * @param[in] queue_size Number of entries in scheduler queue (i.e. the maximum number of + * events that can be scheduled for execution). + * @param[in] p_evt_buffer Pointer to memory buffer for holding the scheduler queue. It must + * be dimensioned using the APP_SCHED_BUFFER_SIZE() macro. The buffer + * must be aligned to a 4 byte boundary. + * + * @note Normally initialization should be done using the APP_SCHED_INIT() macro, as that will both + * allocate the scheduler buffer, and also align the buffer correctly. + * + * @retval NRF_SUCCESS Successful initialization. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte + * boundary). + */ +uint32_t app_sched_init(uint16_t max_event_size, uint16_t queue_size, void * p_evt_buffer); + +/**@brief Function for executing all scheduled events. + * + * @details This function must be called from within the main loop. It will execute all events + * scheduled since the last time it was called. + */ +void app_sched_execute(void); + +/**@brief Function for scheduling an event. + * + * @details Puts an event into the event queue. + * + * @param[in] p_event_data Pointer to event data to be scheduled. + * @param[in] event_size Size of event data to be scheduled. + * @param[in] handler Event handler to receive the event. + * + * @return NRF_SUCCESS on success, otherwise an error code. + */ +uint32_t app_sched_event_put(void const * p_event_data, + uint16_t event_size, + app_sched_event_handler_t handler); + + +/**@brief Function for getting the current amount of free space in the queue. + * + * @details The real amount of free space may be less if entries are being added from an interrupt. + * To get the sxact value, this function should be called from the critical section. + * + * @return Amount of free space in the queue. + */ +uint16_t app_sched_queue_space_get(void); + + +#ifdef __cplusplus +} +#endif + + + + + + + +#endif //__NS_SCHEDULER_H__ +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/sec/ns_sec.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/sec/ns_sec.c new file mode 100644 index 0000000..b08a499 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/sec/ns_sec.c @@ -0,0 +1,996 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_sec.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +/** @addtogroup APP + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" + +#if (BLE_APP_SEC) +#include "ns_ble.h" // Application API Definition +#include "ns_ble_task.h" +#include "ns_sec.h" // Application Security API Definition + + +#if (DISPLAY_SUPPORT) +#include "app_display.h" // Display Application Definitions +#endif //(DISPLAY_SUPPORT) + +#if (NVDS_SUPPORT) +#include "nvds.h" // NVDS API Definitions +#endif //(NVDS_SUPPORT) + +#if (BLE_APP_AM0) +#include "app_am0.h" +#endif //(BLE_APP_AM0) + +#include "ahi_task.h" + + +/* Private typedef -----------------------------------------------------------*/ + +/* Private define ------------------------------------------------------------*/ +#define BOND_SPACE_VALID_FLAG 0x1234 +#define BOND_STORE_LATENCY 500 // unit 20ms +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +struct app_sec_bond_data_env_tag app_sec_bond_data; +/// Application Security Environment Structure +struct app_sec_env_tag app_sec_env; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ +extern __INLINE uint32_t co_rand_word(void); + + +/** + * @brief ns bond database get size + * @param + * @return + * @note + */ +static uint8_t ns_bond_db_get_size(void) +{ + uint8_t bond_num = 0; + uint16_t bond_space_valid = 0; + struct local_device_bond_data_tag* p_strored = (void*)app_sec_env.sec_init.bond_db_addr; + + //NS_LOG_DEBUG("%s\r\n",__func__); + + bond_space_valid = p_strored->valid_flag; + bond_num = p_strored->num; + + if(bond_space_valid == BOND_SPACE_VALID_FLAG) + { + if(bond_num > app_sec_env.sec_init.bond_max_peer) + { + bond_num = 0; + + // Erase full sector + Qflash_Erase_Sector(app_sec_env.sec_init.bond_db_addr); + } + } + else + { + bond_num = 0; + } + + return bond_num; +} + + +/** + * @brief bond database init + */ +static void ns_bond_db_init(void) +{ + uint8_t peer_num = 0; + Qflash_Init(); + NS_LOG_DEBUG("%s\r\n",__func__); + peer_num = ns_bond_db_get_size(); + if(app_sec_env.sec_init.ns_sec_msg_handler) + { + struct sec_msg_t sec_msg = {NS_SEC_NULL_MSG,NULL}; + sec_msg.msg_id = NS_SEC_BOND_STATE; + sec_msg.msg.peer_num = &peer_num; + app_sec_env.sec_init.ns_sec_msg_handler(&sec_msg); + } + + if(peer_num != 0) + { + app_sec_env.bonded = true; + } + else + { + app_sec_env.bonded = false; + } +} + +/** + * @brief ns bond database add entry + * @param + * @return + * @note + */ +static void ns_bond_db_add_entry(struct app_sec_bond_data_env_tag * bond_data_param) +{ + // Load bond data from flash + struct local_device_bond_data_tag local_device_bond_data = {0}; + struct local_device_bond_data_tag* p_strored = (void*)app_sec_env.sec_init.bond_db_addr; + if(!app_sec_env.sec_init.bond_enable ) + { + return; + } + + local_device_bond_data.num = ns_bond_db_get_size(); + + // Update bond data + if(local_device_bond_data.num < app_sec_env.sec_init.bond_max_peer) + { + uint32_t load_size = sizeof(struct app_sec_bond_data_env_tag) * local_device_bond_data.num; + memcpy(&local_device_bond_data.single_peer_bond_data, &(p_strored->single_peer_bond_data[0]),load_size); + local_device_bond_data.num ++; + } + else + { + uint32_t load_size = sizeof(struct app_sec_bond_data_env_tag) * (local_device_bond_data.num-1); + memcpy(&local_device_bond_data.single_peer_bond_data,&(p_strored->single_peer_bond_data[1]), load_size); + } + + memcpy(&local_device_bond_data.single_peer_bond_data[local_device_bond_data.num-1], bond_data_param, + sizeof(struct app_sec_bond_data_env_tag) ); + + local_device_bond_data.valid_flag = BOND_SPACE_VALID_FLAG; + + // Erase full sector + Qflash_Erase_Sector(app_sec_env.sec_init.bond_db_addr); + + // Re-write data + Qflash_Write(app_sec_env.sec_init.bond_db_addr, (uint8_t*)(&local_device_bond_data), sizeof(struct local_device_bond_data_tag) ); + +} + +/** + * @brief ns bond database load + * @param + * @return + * @note + */ +static void ns_bond_db_load(uint8_t index, struct app_sec_bond_data_env_tag * single_bond_data) +{ + uint32_t length = sizeof(struct app_sec_bond_data_env_tag); + struct local_device_bond_data_tag* p_strored = (void*)app_sec_env.sec_init.bond_db_addr; + //NS_LOG_DEBUG("%s\r\n",__func__); + + memcpy(single_bond_data, &(p_strored->single_peer_bond_data[index]), length); +} + + +/** + * @brief return the address of last bonded device + * @param + * @return + * @note + */ +void ns_bond_last_bonded_addr(struct gap_bdaddr *p_addr) +{ + uint8_t peer_num = 0; + struct app_sec_bond_data_env_tag bond_data = {0}; + peer_num = ns_bond_db_get_size(); + ns_bond_db_load( peer_num-1, &bond_data); + p_addr->addr_type = bond_data.peer_addr_type; + memcpy(p_addr->addr.addr,bond_data.peer_addr.addr,GAP_BD_ADDR_LEN); +} + +/** + * @brief return the peer identy address of last bonded device + * @param + * @return + * @note + */ +void ns_bond_last_bonded_peer_id(struct gap_bdaddr *p_addr) +{ + uint8_t peer_num = 0; + struct app_sec_bond_data_env_tag bond_data = {0}; + peer_num = ns_bond_db_get_size(); + ns_bond_db_load( peer_num-1, &bond_data); + p_addr->addr_type = bond_data.irk.addr.addr_type; + memcpy(p_addr->addr.addr,bond_data.irk.addr.addr.addr,GAP_BD_ADDR_LEN); +} + +/** + * @brief return the ral info of last bonded device + * @param + * @return + * @note + */ +void ns_bond_last_bonded_ral_info(struct gap_ral_dev_info *ral_list) +{ + uint8_t peer_num = 0; + struct app_sec_bond_data_env_tag bond_data = {0}; + NS_LOG_DEBUG("%s\r\n", __func__); + peer_num = ns_bond_db_get_size(); + ns_bond_db_load( peer_num-1, &bond_data); + memcpy(ral_list->addr.addr.addr,bond_data.irk.addr.addr.addr,GAP_BD_ADDR_LEN); + ral_list->addr.addr_type = bond_data.irk.addr.addr_type; + memcpy(ral_list->peer_irk,bond_data.irk.irk.key,GAP_KEY_LEN); + if (gap_env.mac_addr_type == GAPM_GEN_RSLV_ADDR) + { + memcpy(ral_list->local_irk,&app_env.loc_irk[0],GAP_KEY_LEN); + } + else + { + memset(ral_list->local_irk, 0, GAP_KEY_LEN); + } +} + +/** + * @brief resolv addr and get the irk for resolvable private random address + * @param + * @return + * @note + */ +void ns_bond_resolv_addr_start(struct bd_addr* addr, uint8_t idx) +{ + uint8_t peer_num = ns_bond_db_get_size(); + NS_LOG_DEBUG("%s, idx:%d, num:%d\r\n", __func__, idx ,peer_num); + + if((idx > 0) && (idx<= peer_num)) + { + // Prepare the GAPM_RESOLV_ADDR_CMD message + struct gapm_resolv_addr_cmd *p_cmd = KE_MSG_ALLOC_DYN(GAPM_RESOLV_ADDR_CMD, + TASK_GAPM, TASK_APP, + gapm_resolv_addr_cmd,KEY_LEN); + // Set operation code + p_cmd->operation = GAPM_RESOLV_ADDR; + p_cmd->nb_key = 1; + + memcpy(p_cmd->addr.addr, addr, sizeof(bd_addr_t)); + + struct app_sec_bond_data_env_tag bond_data = {0}; + ns_bond_db_load( idx-1, &bond_data); + memcpy(&(p_cmd->irk[0]), &(bond_data.irk.irk), KEY_LEN); + + // Send the message + ke_msg_send(p_cmd); + //get resond at GAPM_ADDR_SOLVED_IND + } +} + +/** + * @brief get the irk of this address + * @param + * @return + * @note + */ +void ns_bond_search_addr_irk(struct bd_addr* addr,uint8_t addr_type) +{ + struct app_sec_bond_data_env_tag bond_data = {0}; + uint8_t peer_num = ns_bond_db_get_size(); + + NS_LOG_DEBUG("%s,type:%d,bond num:%d\r\n", __func__,addr_type,peer_num); +// NS_LOG_DEBUG("search_addr:%02X %02X %02X %02X %02X %02X \r\n", addr->addr[0], +// addr->addr[1], addr->addr[2], addr->addr[3], addr->addr[4], addr->addr[5]); + + if(addr_type == GAPM_GEN_RSLV_ADDR) + { + //start resolv addr + app_env.next_svc = peer_num; + ns_bond_resolv_addr_start(addr,app_env.next_svc--); + } + else{ + // not need to resolv + for(uint8_t i = peer_num; i > 0; i--) + { + ns_bond_db_load( i-1, &bond_data); + if(!memcmp(addr->addr,bond_data.irk.addr.addr.addr,BD_ADDR_LEN)) + { + //found + memcpy(&app_env.peer_irk.key,&bond_data.irk.irk.key,GAP_KEY_LEN); + NS_LOG_DEBUG("IRK found, static addr\r\n"); + break; + } + } + } +} + + +/** + * @brief erase all bond database + */ +void ns_sec_bond_db_erase_all(void) +{ + // Erase full sector + Qflash_Erase_Sector(app_sec_env.sec_init.bond_db_addr); + app_sec_env.bonded = false; +} + + +/** + * @brief security init + * @param + * @return + * @note + */ +void ns_sec_init(struct ns_sec_init_t const* init) +{ + memcpy(&app_sec_env.sec_init,init,sizeof(struct ns_sec_init_t)); + + // Bond Init + if(app_sec_env.sec_init.bond_enable) + { + ns_bond_db_init(); + } +} + + +bool ns_sec_get_bond_status(void) +{ + return app_sec_env.bonded; +} + +uint8_t ns_sec_get_iocap(void) +{ + return app_sec_env.sec_init.pairing_feat.iocap; +} + +void ns_sec_send_security_req(uint8_t conidx) +{ + // Send security request + struct gapc_security_cmd *cmd = KE_MSG_ALLOC(GAPC_SECURITY_CMD, + KE_BUILD_ID(TASK_GAPC, conidx), TASK_APP, + gapc_security_cmd); + NS_LOG_DEBUG("%s\r\n",__func__); + cmd->operation = GAPC_SECURITY_REQ; + + cmd->auth = app_sec_env.sec_init.pairing_feat.auth; + + // Send the message + ke_msg_send(cmd); +} + +/** + * @brief start bond by central + */ +void ns_sec_send_bond_start(uint8_t conidx) +{ + // Send security request + struct gapc_bond_cmd *cmd = KE_MSG_ALLOC(GAPC_BOND_CMD, + KE_BUILD_ID(TASK_GAPC, conidx), TASK_APP, + gapc_bond_cmd); + NS_LOG_DEBUG("%s\r\n",__func__); + cmd->operation = GAPC_BOND; + + cmd->pairing.iocap = app_sec_env.sec_init.pairing_feat.iocap ; + cmd->pairing.oob = app_sec_env.sec_init.pairing_feat.oob ; + cmd->pairing.auth = app_sec_env.sec_init.pairing_feat.auth ; + cmd->pairing.key_size = app_sec_env.sec_init.pairing_feat.key_size ; + cmd->pairing.ikey_dist = app_sec_env.sec_init.pairing_feat.ikey_dist ; + cmd->pairing.rkey_dist = app_sec_env.sec_init.pairing_feat.rkey_dist ; + cmd->pairing.sec_req = app_sec_env.sec_init.pairing_feat.sec_req ; + + // Send the message + ke_msg_send(cmd); +} + +/** + * @brief start encrypt request by central + */ +void ns_sec_send_encrypt_req(uint8_t conidx) +{ + // Send security request + struct gapc_encrypt_cmd *cmd = KE_MSG_ALLOC(GAPC_ENCRYPT_CMD, + KE_BUILD_ID(TASK_GAPC, conidx), TASK_APP, + gapc_encrypt_cmd); + NS_LOG_DEBUG("%s\r\n",__func__); + cmd->operation = GAPC_ENCRYPT; + if(app_sec_env.sec_init.bond_enable) + { + uint8_t peer_num = 0; + struct app_sec_bond_data_env_tag bond_data = {0}; + peer_num = ns_bond_db_get_size(); + + for(uint8_t i = peer_num; i > 0; i--) + { + ns_bond_db_load( i-1, &bond_data); + if( !memcmp(&bond_data.peer_addr, &app_env.peer_addr, GAP_BD_ADDR_LEN)) + { + NS_LOG_DEBUG("Found bonded device\r\n"); + cmd->ltk.ediv = bond_data.ediv; + cmd->ltk.key_size = bond_data.key_size; + memcpy(cmd->ltk.ltk.key, bond_data.ltk.key, sizeof(struct gap_sec_key)); + memcpy(cmd->ltk.randnb.nb, bond_data.rand_nb.nb, sizeof(struct rand_nb)); + break; + } + } + } + else + { + cmd->ltk.ediv = app_sec_bond_data.ediv; + cmd->ltk.key_size = app_sec_bond_data.key_size; + memcpy(cmd->ltk.ltk.key, app_sec_bond_data.ltk.key, sizeof(struct gap_sec_key)); + memcpy(cmd->ltk.randnb.nb, app_sec_bond_data.rand_nb.nb, sizeof(struct rand_nb)); + } + // Send the message + ke_msg_send(cmd); +} + +/** + * @brief respond pin code after NS_SEC_PINCODE_ENTER message + * @param + * @return + * @note + */ +void ns_sec_pincode_respond(uint8_t conidx, uint32_t pincode) +{ + NS_LOG_DEBUG("%s:pin_code: 0x%x\r\n",__func__,pincode); + // Prepare the GAPC_BOND_CFM message + struct gapc_bond_cfm *cfm = KE_MSG_ALLOC(GAPC_BOND_CFM, + KE_BUILD_ID(TASK_GAPC, conidx), TASK_APP, + gapc_bond_cfm); + cfm->accept = true; + cfm->request = GAPC_TK_EXCH; + memset(cfm->data.tk.key, 0, KEY_LEN); + + cfm->data.tk.key[0] = (uint8_t)((pincode & 0x000000FF) >> 0); + cfm->data.tk.key[1] = (uint8_t)((pincode & 0x0000FF00) >> 8); + cfm->data.tk.key[2] = (uint8_t)((pincode & 0x00FF0000) >> 16); + cfm->data.tk.key[3] = (uint8_t)((pincode & 0xFF000000) >> 24); + + // Send the message + ke_msg_send(cfm); +} + +static int gapc_bond_req_ind_handler(ke_msg_id_t const msgid, + struct gapc_bond_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + NS_LOG_DEBUG("case: %02x\r\n",param->request); + + // Prepare the GAPC_BOND_CFM message + struct gapc_bond_cfm *cfm = KE_MSG_ALLOC(GAPC_BOND_CFM, + src_id, TASK_APP, + gapc_bond_cfm); + cfm->accept = true; + + switch (param->request) + { + case (GAPC_PAIRING_REQ): + { + cfm->request = GAPC_PAIRING_RSP; + + cfm->accept = true; + + cfm->data.pairing_feat.auth = app_sec_env.sec_init.pairing_feat.auth; + cfm->data.pairing_feat.iocap = app_sec_env.sec_init.pairing_feat.iocap; + cfm->data.pairing_feat.key_size = app_sec_env.sec_init.pairing_feat.key_size; + cfm->data.pairing_feat.oob = app_sec_env.sec_init.pairing_feat.oob; + cfm->data.pairing_feat.ikey_dist = app_sec_env.sec_init.pairing_feat.ikey_dist; + cfm->data.pairing_feat.rkey_dist = app_sec_env.sec_init.pairing_feat.rkey_dist; + cfm->data.pairing_feat.sec_req = app_sec_env.sec_init.pairing_feat.sec_req; + + if(app_sec_env.sec_init.ns_sec_msg_handler) + { + struct sec_msg_t sec_msg = {NS_SEC_NULL_MSG,NULL}; + sec_msg.msg_id = NS_SEC_PAIRING_RSP; + sec_msg.msg.cfm = cfm; + app_sec_env.sec_init.ns_sec_msg_handler(&sec_msg); + } + + } break; + + case (GAPC_LTK_EXCH): + { + // Counter + uint8_t counter; + rwip_time_t current_time; + + cfm->request = GAPC_LTK_EXCH; + cfm->accept = true; + + // Get current time + current_time = rwip_time_get(); + + // Generate all the values + cfm->data.ltk.ediv = (uint16_t)(co_rand_word() + current_time.hs); + + for (counter = 0; counter < RAND_NB_LEN; counter++) + { + cfm->data.ltk.ltk.key[counter] = (uint8_t)(co_rand_word() + current_time.hs); + cfm->data.ltk.randnb.nb[counter] = (uint8_t)(co_rand_word() + current_time.hus); + } + + for (counter = RAND_NB_LEN; counter < KEY_LEN; counter++) + { + cfm->data.ltk.ltk.key[counter] = (uint8_t)(co_rand_word() + current_time.hus + current_time.hs); + } + cfm->data.ltk.key_size = SEC_PARAM_KEY_SIZE; + + if (app_env.conn_env[app_env.conidx].role == ROLE_SLAVE) + { + memcpy(&app_sec_bond_data.ltk.key, &cfm->data.ltk.ltk.key, sizeof(struct gapc_ltk)); + memcpy(&app_sec_bond_data.rand_nb, &cfm->data.ltk.randnb, sizeof(rand_nb_t)); + app_sec_bond_data.ediv = cfm->data.ltk.ediv; + app_sec_bond_data.key_size = cfm->data.ltk.key_size; + } + + } break; + + case (GAPC_IRK_EXCH): + { + cfm->request = GAPC_IRK_EXCH; + + } break; + + case (GAPC_NC_EXCH): + { + cfm->request = GAPC_NC_EXCH; + + } break; + + case (GAPC_TK_EXCH): + { + cfm->request = GAPC_TK_EXCH; + if(param->data.tk_type == GAP_TK_DISPLAY || param->data.tk_type == GAP_TK_OOB) + { + uint32_t pin_code; + cfm->accept = true; + + if(app_sec_env.sec_init.rand_pin_enable) + { + // Get current time + rwip_time_t current_time = rwip_time_get(); + // Generate a PIN Code- (Between 100000 and 999999) + pin_code = ((100000 + (co_rand_word()%900000) + current_time.hs) % 999999); + } + else + { + pin_code = app_sec_env.sec_init.pin_code; //fix pin code + } + if(app_sec_env.sec_init.ns_sec_msg_handler) + { + struct sec_msg_t sec_msg = {NS_SEC_NULL_MSG,NULL}; + sec_msg.msg_id = NS_SEC_PINCODE_DISPLAY; + sec_msg.msg.pincode = &pin_code; + app_sec_env.sec_init.ns_sec_msg_handler(&sec_msg); + } + // Set the TK value + memset(cfm->data.tk.key, 0, KEY_LEN); + + cfm->data.tk.key[0] = (uint8_t)((pin_code & 0x000000FF) >> 0); + cfm->data.tk.key[1] = (uint8_t)((pin_code & 0x0000FF00) >> 8); + cfm->data.tk.key[2] = (uint8_t)((pin_code & 0x00FF0000) >> 16); + cfm->data.tk.key[3] = (uint8_t)((pin_code & 0xFF000000) >> 24); + + } + else if (param->data.tk_type == GAP_TK_KEY_ENTRY) + { + if(app_sec_env.sec_init.ns_sec_msg_handler) + { + struct sec_msg_t sec_msg = {NS_SEC_NULL_MSG,NULL} ; + sec_msg.msg_id = NS_SEC_PINCODE_ENTER; + app_sec_env.sec_init.ns_sec_msg_handler(&sec_msg); + } + + //free the msg add return without repsond + //user code have to respond the pincode with function ns_sec_pincode_respond + KE_MSG_FREE(cfm); + return (KE_MSG_CONSUMED); + } + else + { + ASSERT_ERR(0); + } + + } break; + + case (GAPC_CSRK_EXCH): + { + cfm->request = GAPC_CSRK_EXCH; + + if(gap_env.mac_addr_type == GAPM_GEN_RSLV_ADDR) + { + memcpy(&cfm->data.irk.irk.key, &app_env.loc_irk[0], GAP_KEY_LEN); + } + else + { + memset(&cfm->data.irk.irk.key, 0x00, KEY_LEN); + } + memcpy(&cfm->data.irk.addr.addr, &gap_env.mac_addr, BD_ADDR_LEN); + cfm->data.irk.addr.addr_type = 0; + + + } break; + + + default: + { + ASSERT_ERR(0); + } break; + } + + // Send the message + ke_msg_send(cfm); + + return (KE_MSG_CONSUMED); +} + +static int gapc_bond_ind_handler(ke_msg_id_t const msgid, + struct gapc_bond_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + NS_LOG_DEBUG("%s\r\n",__func__); + NS_LOG_DEBUG("case: %x\r\n",param->info); + switch (param->info) + { + case (GAPC_PAIRING_SUCCEED): + { + NS_LOG_DEBUG("GAPC_PAIRING_SUCCEED\r\n"); + app_sec_env.bonded = true; + + app_sec_bond_data.auth = param->data.pairing.level; + + if(param->data.pairing.level & GAP_AUTH_BOND) + { + memcpy(&app_sec_bond_data.peer_addr.addr, app_env.peer_addr.addr, BD_ADDR_LEN); + app_sec_bond_data.peer_addr_type = app_env.peer_addr_type; + } + if(app_sec_env.sec_init.bond_sync_delay > 0) + { + app_sec_env.store_latency = BOND_STORE_LATENCY; + ke_timer_set(APP_BOND_STORE_EVT, TASK_APP, app_sec_env.sec_init.bond_sync_delay); + } + if(app_sec_env.sec_init.ns_sec_msg_handler) + { + struct sec_msg_t sec_msg = {NS_SEC_NULL_MSG,NULL}; + sec_msg.msg_id = NS_SEC_PAIR_SUCCEED; + app_sec_env.sec_init.ns_sec_msg_handler(&sec_msg); + } + + } break; + + case (GAPC_PAIRING_FAILED): + { + NS_LOG_DEBUG("GAPC_PAIRING_FAILED\r\n"); + app_sec_bond_data.auth = GAP_AUTH_NONE; + ns_ble_disconnect(); + if(app_sec_env.sec_init.ns_sec_msg_handler) + { + struct sec_msg_t sec_msg = {NS_SEC_NULL_MSG,NULL}; + sec_msg.msg_id = NS_SEC_PAIR_FAILED; + app_sec_env.sec_init.ns_sec_msg_handler(&sec_msg); + } + + } break; + + case (GAPC_IRK_EXCH): + { + NS_LOG_DEBUG("GAPC_IRK_EXCH\r\n"); + memcpy(&app_sec_bond_data.irk, ¶m->data.irk, sizeof(struct gapc_irk)); + } break; + + + case (GAPC_LTK_EXCH) : + { + #if (BLE_APP_SEC_CON == 0) + if (app_env.conn_env[app_env.conidx].role == ROLE_MASTER ) + #endif + { + memcpy(&app_sec_bond_data.ltk.key, ¶m->data.ltk.ltk.key, sizeof(struct gapc_ltk)); + memcpy(&app_sec_bond_data.rand_nb, ¶m->data.ltk.randnb, sizeof(rand_nb_t)); + app_sec_bond_data.ediv = param->data.ltk.ediv; + app_sec_bond_data.key_size = param->data.ltk.key_size; + } + } + break; + + case (GAPC_CSRK_EXCH) : + { + NS_LOG_DEBUG("GAPC_CSRK_EXCH\r\n"); + } + break; + + default: + { + NS_LOG_DEBUG("gapc_bond_ind--default\r\n"); + ASSERT_ERR(0); + } break; + } + + return (KE_MSG_CONSUMED); +} + +static int gapc_encrypt_req_ind_handler(ke_msg_id_t const msgid, + struct gapc_encrypt_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + struct gapc_encrypt_cfm *cfm = KE_MSG_ALLOC(GAPC_ENCRYPT_CFM, + src_id, TASK_APP, + gapc_encrypt_cfm); + + NS_LOG_DEBUG("%s\r\n",__func__); + + cfm->found = false; + + if (app_sec_env.bonded) + { +// NS_LOG_DEBUG("bonded,searching ltk\r\n"); + if(app_sec_env.sec_init.bond_enable) + { + uint8_t peer_num = 0; + struct app_sec_bond_data_env_tag bond_data = {0}; + + peer_num = ns_bond_db_get_size(); + + for(uint8_t i = peer_num; i > 0; i--) + { + ns_bond_db_load( i-1, &bond_data); + #if (BLE_APP_SEC_CON) + rand_nb_t lesc_rand_nb = {0}; + if(param->ediv == 0 && + !memcmp(bond_data.rand_nb.nb, lesc_rand_nb.nb, GAP_RAND_NB_LEN)) + { + //LESC mode, ediv and rand_nb are 0x0 + if((app_env.peer_addr_type == GAPM_STATIC_ADDR) && + (!memcmp(app_env.peer_addr.addr, bond_data.peer_addr.addr,GAP_BD_ADDR_LEN)) ) + { + NS_LOG_INFO("static addr match\r\n"); + cfm->found = true; + } + else if(!memcmp(app_env.peer_irk.key, bond_data.irk.irk.key,GAP_KEY_LEN)) + { + NS_LOG_INFO("irk match\r\n"); + cfm->found = true; + } + }else + #endif + if( (bond_data.ediv == param->ediv) && + !memcmp(&bond_data.rand_nb, ¶m->rand_nb.nb, sizeof(struct rand_nb)) ) + { + NS_LOG_INFO("ediv&rand_nb match\r\n"); + cfm->found = true; + } + if(cfm->found) + { + cfm->key_size = bond_data.key_size; + memcpy(cfm->ltk.key, bond_data.ltk.key, sizeof(struct gap_sec_key)); + break; + } + } + } + else + { + if( (app_sec_bond_data.ediv == param->ediv) && + !memcmp(&app_sec_bond_data.rand_nb, ¶m->rand_nb.nb, sizeof(struct rand_nb)) ) + { + NS_LOG_DEBUG("Found\r\n"); + + cfm->found = true; + cfm->key_size = app_sec_bond_data.key_size; + memcpy(cfm->ltk.key, app_sec_bond_data.ltk.key, sizeof(struct gap_sec_key)); + } + } + } + if(cfm->found == false) + { + NS_LOG_DEBUG("Not found\r\n"); + if(app_sec_env.sec_init.ns_sec_msg_handler) + { + struct sec_msg_t sec_msg = {NS_SEC_NULL_MSG,NULL}; + sec_msg.msg_id = NS_SEC_LTK_MISSING; + app_sec_env.sec_init.ns_sec_msg_handler(&sec_msg); + } + + //disconnect if key miss + struct gapc_disconnect_cmd *p_cmd = KE_MSG_ALLOC(GAPC_DISCONNECT_CMD, + src_id , TASK_APP, + gapc_disconnect_cmd); + + NS_LOG_DEBUG("%s\r\n", __func__); + p_cmd->operation = GAPC_DISCONNECT; + p_cmd->reason = CO_ERROR_PIN_MISSING; + + // Send the message + ke_msg_send(p_cmd); + } + else{ + if(app_sec_env.sec_init.ns_sec_msg_handler) + { + struct sec_msg_t sec_msg = {NS_SEC_NULL_MSG,NULL}; + sec_msg.msg_id = NS_SEC_LTK_FOUND; + app_sec_env.sec_init.ns_sec_msg_handler(&sec_msg); + } + } + + ke_msg_send(cfm); + + return (KE_MSG_CONSUMED); +} + + +static int gapc_encrypt_ind_handler(ke_msg_id_t const msgid, + struct gapc_encrypt_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,lvl:%d\r\n",__func__,param->pairing_lvl); + if(app_sec_env.sec_init.ns_sec_msg_handler) + { + struct sec_msg_t sec_msg = {NS_SEC_NULL_MSG,NULL}; + sec_msg.msg_id = NS_SEC_ENC_SUCCEED; + app_sec_env.sec_init.ns_sec_msg_handler(&sec_msg); + } + return (KE_MSG_CONSUMED); +} + + + +static int app_sec_msg_dflt_handler(ke_msg_id_t const msgid, + void *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles bond sync store handle + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +int ns_sec_bond_store_evt_handler(ke_msg_id_t const msgid, void *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + + NS_LOG_DEBUG("%s\r\n",__func__); + + rwip_time_t current_time = rwip_time_get(); + rwip_time_t target_time = {0}; + target_time.hs = ip_clkntgt1_getf(); + target_time.hus = ip_hmicrosectgt1_getf(); + int32_t duration = CLK_DIFF(current_time.hs, target_time.hs); + if((duration > 64) || (app_sec_env.store_latency == 0))// 20ms, xMS / 0.3125 + { + //erase and write flash + ns_bond_db_add_entry(&app_sec_bond_data); + app_sec_env.store_latency = BOND_STORE_LATENCY; + NS_LOG_INFO("Bond info stored\r\n"); + #if 0 + NS_LOG_DEBUG("save peer, type:%d, addr:%02X %02X %02X %02X %02X %02X \r\n", + app_sec_bond_data.peer_addr_type, + app_sec_bond_data.peer_addr.addr[0], + app_sec_bond_data.peer_addr.addr[1], + app_sec_bond_data.peer_addr.addr[2], + app_sec_bond_data.peer_addr.addr[3], + app_sec_bond_data.peer_addr.addr[4], + app_sec_bond_data.peer_addr.addr[5]); + + NS_LOG_DEBUG("save IRK addr:%02X %02X %02X %02X %02X %02X \r\n", + app_sec_bond_data.irk.addr.addr.addr[0], + app_sec_bond_data.irk.addr.addr.addr[1], + app_sec_bond_data.irk.addr.addr.addr[2], + app_sec_bond_data.irk.addr.addr.addr[3], + app_sec_bond_data.irk.addr.addr.addr[4], + app_sec_bond_data.irk.addr.addr.addr[5]); + NS_LOG_DEBUG("save IRK key:"); + for(uint8_t i = 0; iINITSTS&RTC_INITSTS_INITSF) == 0) + { + RTC_InitType RTC_InitStructure; + RTC_InitStructure.RTC_AsynchPrediv = 0x7D; // 7f:23768 , 7d:32k + RTC_InitStructure.RTC_SynchPrediv = 0xFF; + RTC_InitStructure.RTC_HourFormat = RTC_24HOUR_FORMAT; + RTC_Init(&RTC_InitStructure); + } + /* set wakeup timer*/ + RTC_ConfigWakeUpClock(RTC_WKUPCLK_RTCCLK_DIV16); //32k/16 = 2K + RTC_SetWakeUpCounter(period_ms*2); + + /* Enable the RTC WakeUp Interrupt */ + EXTI_InitType EXTI_InitStructure; + EXTI_ClrITPendBit(EXTI_LINE9); + EXTI_InitStructure.EXTI_Line = EXTI_LINE9; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + NVIC_InitType NVIC_InitStructure; + NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + NVIC_SetPriority(EXTI4_12_IRQn, 3); + + + RTC_ConfigInt(RTC_INT_WUT, ENABLE); + /* Enable wakeup timer*/ + RTC_EnableWakeUp(ENABLE); +} + +/** + * @brief active rwip(bb) in wakeup callback. + * @param + * @return void + * @note + */ +void ns_sleep_lp_timer_wake_ble(void) +{ + g_sleep_status_flag = BB_WAKEUP_USER; +} +#endif + +/** + * @brief Acquire a sleep lock, it will prevent the os enter sleep mode. + * We should call ns_sleep_lock_release function when this lock can be release. + * @param + * @return + * @note + */ +uint8_t ns_sleep_lock_acquire(void) +{ + if(ns_sleep_lock++ == 0) + { + //overflow + return false; + } + return true; +} + +/** + * @brief Release a sleep lock, if all the lock has been released, os will enter sleep mode + * when run out of task. + * @param + * @return + * @note + */ +uint8_t ns_sleep_lock_release(void) +{ + if(ns_sleep_lock) + { + ns_sleep_lock--; + return true; + } + return false; +} + + +/** + * @brief entry_sleep + * @param + * @return + * @note + */ +void entry_sleep(void) +{ + uint32_t reg_rt_0 = REG32(0x40011004); + RCC->APB1PCLKEN |= RCC_APB1_PERIPH_PWR; // PWR enable + REG32(0x40028030) |= 0x07; + REG32(0x40011004) = 0x00; + EXTI_PA11_Configuration(); + g_sleep_status_flag = BB_SLEEP; + while(PWR->CR1&0x20); //wait ble sleep + while(1) + { + __set_PRIMASK(1);//disable irq + volatile uint8_t *p_flag = &g_sleep_status_flag; + if( (*p_flag) != BB_SLEEP ) + { + __set_PRIMASK(0);//enable irq + //wake up rwip + break; + } + NS_LOG_DEINIT(); + + PWR->CR1 = 0x0A; + SCB->SCR |= 0x04; + __WFI(); + + RCC->LSCTRL |= 1; //rewrite LSCTRL + RCC->CFG |= RCC_HCLK_DIV2; //APB1 = HCLK/2, APB1 max is 32M + RCC->APB1PCLKEN |= RCC_APB1_PERIPH_PWR; // PWR enable + RCC->APB2PCLKEN |= RCC_APB2_PERIPH_GPIOA|RCC_APB2_PERIPH_GPIOB|RCC_APB2_PERIPH_AFIO; + REG32(0x40011004) = reg_rt_0; + NS_WAKEUP_CONFIG(); + NS_LOG_INIT(); + + #ifdef SLEEP_LP_TIMER_ENABLE + if( (EXTI->PEND)&(~EXTI_LINE9) ) + { + //rtc extra wake up + g_sleep_status_flag = BB_WAKEUP_EXIT; + } + __set_PRIMASK(0);//enable irq + //wait IRQ handler + uint8_t exit_wait = 0xff; + while((EXTI->PEND&EXTI->IMASK) != 0) + { + exit_wait--; + if(exit_wait == 0) + { + //timeout error, wake ble + g_sleep_status_flag = BB_WAKEUP_ERROR; + break; + } + } + #else + //wake up rwip in all case + g_sleep_status_flag = BB_WAKEUP_ALL; + break; + #endif + } + //wake ble with wakeup req + PWR->CR2 |= 0x100; //1<<8 wake up ble + while(!(PWR->CR1&0x20));//wait ble active +} + +/** + * @brief entry Idle mode + * @param + * @return + * @note + */ +void entry_idle(void) +{ + EXTI_PA11_Configuration(); + PWR->CR1 &= 0xF0; + SCB->SCR &= 0xFB; + __WFI(); +} + +/** + * @brief sleep task function, usually run after rwip_schedule function in main loop. + * @param + * @return + * @note + */ +void ns_sleep(void) +{ + if(ns_sleep_lock != 0) + { + return; + } + GLOBAL_INT_DISABLE(); + app_sleep_prepare_proc(); + switch(rwip_sleep()) + { + case RWIP_DEEP_SLEEP: + { + entry_sleep(); + } + break; + case RWIP_CPU_SLEEP: + { + entry_idle(); + } + break; + case RWIP_ACTIVE: + default: + { + + } + break; + } + GLOBAL_INT_RESTORE(); + + /* check ble out of sleep */ + if(((*p_prevent_sleep) & (RW_WAKE_UP_ONGOING|RW_DEEP_SLEEP) )) + { + uint32_t wait_sleep = 12800; //2*800us + while((*p_prevent_sleep) & (RW_WAKE_UP_ONGOING|RW_DEEP_SLEEP)) + { + wait_sleep--; + if(wait_sleep == 0) + { + break; + } + } + rwip_time_t current_time = rwip_time_get(); + // check if 1ms timer is active and make sure ke timer active. + if(rwip_env.timer_1ms_target.hs != RWIP_INVALID_TARGET_TIME) + { + int32_t duration = CLK_DIFF(current_time.hs, rwip_env.timer_1ms_target.hs); + if(duration < 0 ) + { + // Mark that 1ms timer is over + ke_event_set(KE_EVENT_KE_TIMER); + } + } + } + + app_sleep_resume_proc(); + +} + +/** + * @brief User code beofre enter sleep mode + * @param + * @return + * @note + */ +__weak void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief User code after out of sleep mode. This function run after interrupt + * handler function if any interrupt pending when sleep. + * @param + * @return + * @note + */ +__weak void app_sleep_resume_proc(void) +{ + +} + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/sleep/ns_sleep.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/sleep/ns_sleep.h new file mode 100644 index 0000000..f99a5f6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/sleep/ns_sleep.h @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_sleep.h + * @author NSING Firmware Team + * @version v1.0.3 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ +#ifndef __NS_SLEEP_H__ +#define __NS_SLEEP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes -----------------------------------------------------------------*/ +#include "global_func.h" +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief sleep task function, usually run after rwip_schedule function in main loop. + * @param + * @return + * @note + */ +void ns_sleep(void); + +/** + * @brief Acquire a sleep lock, it will prevent the os enter sleep mode. + * We should call ns_sleep_lock_release function when this lock can be release. + * @param + * @return + * @note + */ +uint8_t ns_sleep_lock_acquire(void); + +/** + * @brief Release a sleep lock, if all the lock has been released, os will enter sleep mode + * when run out of task. + * @param + * @return + * @note + */ +uint8_t ns_sleep_lock_release(void); +/** + * @brief User code beofre enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void); + +/** + * @brief User code after out of sleep mode. This function run after interrupt + * handler function if any interrupt pending when sleep. + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void); + +#ifdef SLEEP_LP_TIMER_ENABLE +/** + * @brief low power timer initialization. + * @param period_ms: 1 - 0x7fff + * @param func: low power timer callback, not suggest run over 2ms + * @return void + * @note + */ +void ns_sleep_lp_timer_config(uint16_t period_ms, IRQ_HANNDLE_FUN func); + +/** + * @brief active rwip in wakeup callback. + * @param + * @return void + * @note + */ +void ns_sleep_lp_timer_wake_ble(void); +#endif + +#endif /* __NS_SLEEP_H__ */ +/** + * @} + */ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/timer/ns_timer.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/timer/ns_timer.c new file mode 100644 index 0000000..37f3624 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/timer/ns_timer.c @@ -0,0 +1,381 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file template.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup ns_timer + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_PRESENT) +#include "ke_timer.h" +#include "ke_msg.h" +#include "ns_ble.h" +#include "ns_timer.h" +#include "ns_ble_task.h" +#include +/* Private define ------------------------------------------------------------*/ +#define NS_TIMER_MAX_NUM (NS_TIMER_API_LAST_MES - NS_TIMER_API_MES0 + 1) +//handler: Timer handler values = 0...NS_TIMER_MAX_NUM -1 +#define NS_TIMER_HANDLER_TO_MSG_ID(hnd_idx) (hnd_idx + NS_TIMER_API_MES0) +#define NS_TIMER_MSG_ID_TO_HANDLER(msg_id) (msg_id - NS_TIMER_API_MES0) +#define NS_TIMER_HANDLER_IS_VALID(hnd_idx) (hnd_idx < NS_TIMER_MAX_NUM) + +#define CREATE_TIMER(timer_id,delay) ke_timer_set(NS_TIMER_HANDLER_TO_MSG_ID(timer_id), TASK_APP, delay) + +/* Private typedef -----------------------------------------------------------*/ +struct cancel_timer_t +{ + timer_hnd_t timer_id; + uint32_t delay; +}; + +struct modify_timer_t +{ + timer_hnd_t timer_id; + uint32_t delay; +}; +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +// Array that holds the callback function of the active timers +static timer_callback_t timer_callback_array[NS_TIMER_MAX_NUM]; + +// Array that holds the callback function of the active timers, whose delay period is to be modified +static timer_callback_t modified_timer_callback_array[NS_TIMER_MAX_NUM]; + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Place a callback in the first available position in the timer callback array. + * @param fn The callback to be added + * @return The handler of the timer for future reference. NS_TIMER_INVALID_HANDLER if + * there is no timer available + */ +static timer_hnd_t set_callback(timer_callback_t fn) +{ + for (int i = 0; i < NS_TIMER_MAX_NUM; i++) + { + if (timer_callback_array[i] == NULL) + { + timer_callback_array[i] = fn; + return (i); + } + } + return NS_TIMER_INVALID_HANDLER; +} + +/** + * @brief Dummy callback used when canceling a timer. + */ +static void timer_canceled_handler(void) +{ + //keep empty +} + +/** + * @brief Dummy callback used when modifying a timer. + */ +static void timer_modified_handler(void) +{ + //keep empty +} + +/** + * @brief Call the callback of a specific timer handler if it exists. + * @param timer_id The handler to call + */ +static void call_user_callback(const timer_hnd_t timer_id) +{ + void (*return_timer_cb)(timer_hnd_t timer_id); + + if NS_TIMER_HANDLER_IS_VALID(timer_id) + { + if (timer_callback_array[timer_id] != NULL) + { + timer_callback_t fn = timer_callback_array[timer_id]; + // Check if the a timer to be modified or canceled has expired + if ((fn != timer_modified_handler) && (fn != timer_canceled_handler)) + { + timer_callback_array[timer_id] = NULL; + modified_timer_callback_array[timer_id] = NULL; + return_timer_cb = (void (*)(timer_hnd_t))fn; + return_timer_cb(timer_id); + } + } + } + else + { + ASSERT_WARN(0,0,0); + } +} + +/** + * @brief Handler function that is called when the TASK_APP receives the APP_CANCEL_TIMER + * message. + * @param msgid Id of the message received + * @param param The timer details to be canceled + * @param dest_id ID of the receiving task instance + * @param src_id ID of the sending task instance + * @return KE_MSG_CONSUMED + */ +static int cancel_timer_msg_handler(ke_msg_id_t const msgid, + struct cancel_timer_t const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if NS_TIMER_HANDLER_IS_VALID(param->timer_id) + { + int i = param->timer_id; + if (timer_callback_array[i] == timer_canceled_handler) + { + timer_callback_array[i] = NULL; + modified_timer_callback_array[i] = NULL; + } + else if (timer_callback_array[i] == timer_modified_handler) + { + struct modify_timer_t *req = KE_MSG_ALLOC(APP_MODIFY_TIMER, + TASK_APP, + TASK_APP, + modify_timer_t); + + req->timer_id = param->timer_id; + req->delay = param->delay; + ke_msg_send(req); + } + } + else + { + ASSERT_ERR(0); + } + return KE_MSG_CONSUMED; +} + +/** +* + * @brief Handler function that is called when the TASK_APP receives the APP_MODIFY_TIMER + * message. + * @param msgid Id of the message received + * @param param The timer details to be modified + * @param dest_id ID of the receiving task instance + * @param src_id ID of the sending task instance + * @return KE_MSG_CONSUMED +* + */ +static int modify_timer_msg_handler(ke_msg_id_t const msgid, + struct modify_timer_t const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if NS_TIMER_HANDLER_IS_VALID(param->timer_id) + { + if (timer_callback_array[param->timer_id] == timer_modified_handler) + { + // Restore timer callback function + timer_callback_array[param->timer_id] = modified_timer_callback_array[param->timer_id]; + + // Re-create the timer with new delay + CREATE_TIMER(param->timer_id, param->delay); + } + } + else + { + ASSERT_ERR(0); + } + return KE_MSG_CONSUMED; +} + + +enum process_event_response ns_timer_api_process_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id, + enum ke_msg_status_tag *msg_ret) +{ + + NS_LOG_DEBUG("app_timer_api_process_handler:msgid:%04x\r\n",msgid); + switch (msgid) + { + case APP_CANCEL_TIMER: + *msg_ret = (enum ke_msg_status_tag)cancel_timer_msg_handler(msgid, param, dest_id, src_id); + return PR_EVENT_HANDLED; + + case APP_MODIFY_TIMER: + *msg_ret = (enum ke_msg_status_tag)modify_timer_msg_handler(msgid, param, dest_id, src_id); + return PR_EVENT_HANDLED; + + default: + if ((msgid < NS_TIMER_API_MES0) || (msgid > NS_TIMER_API_LAST_MES)) + { + *msg_ret = KE_MSG_NO_FREE; + return PR_EVENT_UNHANDLED; + } + else + { + call_user_callback(NS_TIMER_MSG_ID_TO_HANDLER(msgid)); + *msg_ret = KE_MSG_CONSUMED; + } + return PR_EVENT_HANDLED; + } +} + +timer_hnd_t ns_timer_create(const uint32_t delay, timer_callback_t fn) +{ + // Sanity checks + ASSERT_ERR(delay > 0); // Delay should not be zero + ASSERT_ERR(delay < KE_TIMER_DELAY_MAX); // Delay should not be more than maximum allowed + + timer_hnd_t timer_id = set_callback(fn); + if (timer_id == NS_TIMER_INVALID_HANDLER) + { + return NS_TIMER_INVALID_HANDLER; //No timers available + } + + // Create timer + CREATE_TIMER(timer_id, delay); + + return timer_id; +} + +void ns_timer_cancel(const timer_hnd_t timer_id) +{ + if NS_TIMER_HANDLER_IS_VALID(timer_id) + { + if ((timer_callback_array[timer_id] != NULL) && + (timer_callback_array[timer_id] != timer_canceled_handler)) + { + // Remove the timer from the timer queue + ke_timer_clear(NS_TIMER_HANDLER_TO_MSG_ID(timer_id), TASK_APP); + + timer_callback_array[timer_id] = timer_canceled_handler; + + struct cancel_timer_t *req = KE_MSG_ALLOC(APP_CANCEL_TIMER, TASK_APP, TASK_APP, + cancel_timer_t); + + req->timer_id = timer_id; + ke_msg_send(req); + } + else + { + ASSERT_WARN(0,0,0); + } + } + else + { + ASSERT_WARN(0,0,0); + } +} + +timer_hnd_t ns_timer_modify(const timer_hnd_t timer_id, uint32_t delay) +{ + // Sanity checks + ASSERT_ERR(delay > 0); // Delay should not be zero + ASSERT_ERR(delay < KE_TIMER_DELAY_MAX); // Delay should not be more than maximum allowed + + if NS_TIMER_HANDLER_IS_VALID(timer_id) + { + if ((timer_callback_array[timer_id] != NULL) && + (timer_callback_array[timer_id] != timer_modified_handler)) + { + // Remove the timer from the timer queue + ke_timer_clear(NS_TIMER_HANDLER_TO_MSG_ID(timer_id), TASK_APP); + + // Store the timer function callback + modified_timer_callback_array[timer_id] = timer_callback_array[timer_id]; + + timer_callback_array[timer_id] = timer_modified_handler; + + struct cancel_timer_t *req = KE_MSG_ALLOC(APP_CANCEL_TIMER, TASK_APP, TASK_APP, + cancel_timer_t); + + req->timer_id = timer_id; + req->delay = delay; + ke_msg_send(req); + + return timer_id; + } + else + { + ASSERT_WARN(0,0,0); + } + } + else + { + ASSERT_WARN(0,0,0); + } + return NS_TIMER_INVALID_HANDLER; +} + +void ns_timer_cancel_all(void) +{ + for (int i = 0; i < NS_TIMER_MAX_NUM; i++) + { + if ((timer_callback_array[i] != NULL) && + (timer_callback_array[i] != timer_canceled_handler)) + { + ns_timer_cancel(i); + } + } +} + +#endif // (BLE_APP_PRESENT) + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/timer/ns_timer.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/timer/ns_timer.h new file mode 100644 index 0000000..3915b1f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Nationstech/ble_library/ns_library/timer/ns_timer.h @@ -0,0 +1,132 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_timer.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +#ifndef _NS_TIMER_H_ +#define _NS_TIMER_H_ + +/* Includes ------------------------------------------------------------------*/ +#include "ke_msg.h" +/* Public typedef -----------------------------------------------------------*/ +/// Timer handler type +typedef uint8_t timer_hnd_t; +/// Timer callback function type definition +typedef void (* timer_callback_t)(void); +/* Public define ------------------------------------------------------------*/ +/// Max timer delay 41943sec (41943000ms) +#define KE_TIMER_DELAY_MAX (41943000) +/// Value indicating an invalide timer operation +#define NS_TIMER_INVALID_HANDLER (0xFF) +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ + + +/** + * @brief Process handler for the Timer messages. + * @param msgid Id of the message received + * @param param Pointer to the parameters of the message + * @param dest_id ID of the receiving task instance (probably unused) + * @param src_id ID of the sending task instance + * @param msg_ret Result of the message handler + * @return Returns if the message is handled by the process handler + * @note + */ + +enum process_event_response ns_timer_api_process_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id, + enum ke_msg_status_tag *msg_ret); + + +/** + * @brief Create a new timer. + * @param Param input + * @brief Create a new timer. + * @param delay The amount of timer value to wait (time resolution is 1ms) + * @param fn The callback to be called when the timer expires + * @return The handler of the timer for future reference. If there are not timers available + * NS_TIMER_INVALID_HANDLER will be returned + */ +timer_hnd_t ns_timer_create(const uint32_t delay, timer_callback_t fn); + +/** + * @brief Cancel an active timer. + * @param timer_id The timer handler to cancel + */ +void ns_timer_cancel(const timer_hnd_t timer_id); + +/** + * @brief Modify the delay of an existing timer. + * @param timer_id The timer handler to modify + * @param delay The new delay value (time resolution is 1ms) + * @return The timer handler if everything is ok + */ +timer_hnd_t ns_timer_modify(const timer_hnd_t timer_id, const uint32_t delay); + +/** + * @brief Cancel all the active timers. + */ +void ns_timer_cancel_all(void); + +#endif // _NS_TIMER_H_ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/License/license.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/License/license.txt new file mode 100644 index 0000000..0072310 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/License/license.txt @@ -0,0 +1,37 @@ +The FreeRTOS kernel is released under the MIT open source license, the text of +which is provided below. + +This license covers the FreeRTOS kernel source files, which are located in the +/FreeRTOS/Source directory of the official FreeRTOS kernel download. It also +covers most of the source files in the demo application projects, which are +located in the /FreeRTOS/Demo directory of the official FreeRTOS download. The +demo projects may also include third party software that is not part of FreeRTOS +and is licensed separately to FreeRTOS. Examples of third party software +includes header files provided by chip or tools vendors, linker scripts, +peripheral drivers, etc. All the software in subdirectories of the /FreeRTOS +directory is either open source or distributed with permission, and is free for +use. For the avoidance of doubt, refer to the comments at the top of each +source file. + + +License text: +------------- + +Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. +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. + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c new file mode 100644 index 0000000..d6ee06a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c @@ -0,0 +1,1741 @@ +/* ---------------------------------------------------------------------- + * $Date: 5. February 2013 + * $Revision: V1.02 + * + * Project: CMSIS-RTOS API + * Title: cmsis_os.c + * + * Version 0.02 + * Initial Proposal Phase + * Version 0.03 + * osKernelStart added, optional feature: main started as thread + * osSemaphores have standard behavior + * osTimerCreate does not start the timer, added osTimerStart + * osThreadPass is renamed to osThreadYield + * Version 1.01 + * Support for C++ interface + * - const attribute removed from the osXxxxDef_t typedef's + * - const attribute added to the osXxxxDef macros + * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete + * Added: osKernelInitialize + * Version 1.02 + * Control functions for short timeouts in microsecond resolution: + * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec + * Removed: osSignalGet + * + * + *---------------------------------------------------------------------------- + * + * Portions Copyright (c) 2013 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. + *---------------------------------------------------------------------------*/ + + /** + ****************************************************************************** + * @file cmsis_os.c + * @author + * @date + * @brief CMSIS-RTOS API implementation for FreeRTOS V10.0.1 + ****************************************************************************** + * @attention + * + ****************************************************************************** + */ + +#include +#include "cmsis_os.h" + +/* + * ARM Compiler 4/5 + */ +#if defined ( __CC_ARM ) + + #define __ASM __asm + #define __INLINE __inline + #define __STATIC_INLINE static __inline + + #include "cmsis_armcc.h" + +/* + * GNU Compiler + */ +#elif defined ( __GNUC__ ) + + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + #define __STATIC_INLINE static inline + + #include "cmsis_gcc.h" + + +/* + * IAR Compiler + */ +#elif defined ( __ICCARM__ ) + + #ifndef __ASM + #define __ASM __asm + #endif + #ifndef __INLINE + #define __INLINE inline + #endif + #ifndef __STATIC_INLINE + #define __STATIC_INLINE static inline + #endif + + #include +#endif + +extern void xPortSysTickHandler(void); + +/* Convert from CMSIS type osPriority to FreeRTOS priority number */ +static unsigned portBASE_TYPE makeFreeRtosPriority (osPriority priority) +{ + unsigned portBASE_TYPE fpriority = tskIDLE_PRIORITY; + + if (priority != osPriorityError) { + fpriority += (priority - osPriorityIdle); + } + + return fpriority; +} + +#if (INCLUDE_uxTaskPriorityGet == 1) +/* Convert from FreeRTOS priority number to CMSIS type osPriority */ +static osPriority makeCmsisPriority (unsigned portBASE_TYPE fpriority) +{ + osPriority priority = osPriorityError; + + if ((fpriority - tskIDLE_PRIORITY) <= (osPriorityRealtime - osPriorityIdle)) { + priority = (osPriority)((int)osPriorityIdle + (int)(fpriority - tskIDLE_PRIORITY)); + } + + return priority; +} +#endif + + +/* Determine whether we are in thread mode or handler mode. */ +static int inHandlerMode (void) +{ + return __get_IPSR() != 0; +} + +/*********************** Kernel Control Functions *****************************/ +/** +* @brief Initialize the RTOS Kernel for creating objects. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS. +*/ +osStatus osKernelInitialize (void); + +/** +* @brief Start the RTOS Kernel with executing the specified thread. +* @param thread_def thread definition referenced with \ref osThread. +* @param argument pointer that is passed to the thread function as start argument. +* @retval status code that indicates the execution status of the function +* @note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS. +*/ +osStatus osKernelStart (void) +{ + vTaskStartScheduler(); + + return osOK; +} + +/** +* @brief Check if the RTOS kernel is already started +* @param None +* @retval (0) RTOS is not started +* (1) RTOS is started +* (-1) if this feature is disabled in FreeRTOSConfig.h +* @note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS. +*/ +int32_t osKernelRunning(void) +{ +#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) + return 0; + else + return 1; +#else + return (-1); +#endif +} + +#if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available +/** +* @brief Get the value of the Kernel SysTick timer +* @param None +* @retval None +* @note MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS. +*/ +uint32_t osKernelSysTick(void) +{ + if (inHandlerMode()) { + return xTaskGetTickCountFromISR(); + } + else { + return xTaskGetTickCount(); + } +} +#endif // System Timer available +/*********************** Thread Management *****************************/ +/** +* @brief Create a thread and add it to Active Threads and set it to state READY. +* @param thread_def thread definition referenced with \ref osThread. +* @param argument pointer that is passed to the thread function as start argument. +* @retval thread ID for reference by other functions or NULL in case of error. +* @note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS. +*/ +osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument) +{ + TaskHandle_t handle; + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + if((thread_def->buffer != NULL) && (thread_def->controlblock != NULL)) { + handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, + thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), + thread_def->buffer, thread_def->controlblock); + } + else { + if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, + thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), + &handle) != pdPASS) { + return NULL; + } + } +#elif( configSUPPORT_STATIC_ALLOCATION == 1 ) + + handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, + thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), + thread_def->buffer, thread_def->controlblock); +#else + if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, + thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), + &handle) != pdPASS) { + return NULL; + } +#endif + + return handle; +} + +/** +* @brief Return the thread ID of the current running thread. +* @retval thread ID for reference by other functions or NULL in case of error. +* @note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS. +*/ +osThreadId osThreadGetId (void) +{ +#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) + return xTaskGetCurrentTaskHandle(); +#else + return NULL; +#endif +} + +/** +* @brief Terminate execution of a thread and remove it from Active Threads. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS. +*/ +osStatus osThreadTerminate (osThreadId thread_id) +{ +#if (INCLUDE_vTaskDelete == 1) + vTaskDelete(thread_id); + return osOK; +#else + return osErrorOS; +#endif +} + +/** +* @brief Pass control to next thread that is in state \b READY. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS. +*/ +osStatus osThreadYield (void) +{ + taskYIELD(); + + return osOK; +} + +/** +* @brief Change priority of an active thread. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @param priority new priority value for the thread function. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS. +*/ +osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority) +{ +#if (INCLUDE_vTaskPrioritySet == 1) + vTaskPrioritySet(thread_id, makeFreeRtosPriority(priority)); + return osOK; +#else + return osErrorOS; +#endif +} + +/** +* @brief Get current priority of an active thread. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @retval current priority value of the thread function. +* @note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS. +*/ +osPriority osThreadGetPriority (osThreadId thread_id) +{ +#if (INCLUDE_uxTaskPriorityGet == 1) + if (inHandlerMode()) + { + return makeCmsisPriority(uxTaskPriorityGetFromISR(thread_id)); + } + else + { + return makeCmsisPriority(uxTaskPriorityGet(thread_id)); + } +#else + return osPriorityError; +#endif +} + +/*********************** Generic Wait Functions *******************************/ +/** +* @brief Wait for Timeout (Time Delay) +* @param millisec time delay value +* @retval status code that indicates the execution status of the function. +*/ +osStatus osDelay (uint32_t millisec) +{ +#if INCLUDE_vTaskDelay + TickType_t ticks = millisec / portTICK_PERIOD_MS; + + vTaskDelay(ticks ? ticks : 1); /* Minimum delay = 1 tick */ + + return osOK; +#else + (void) millisec; + + return osErrorResource; +#endif +} + +#if (defined (osFeature_Wait) && (osFeature_Wait != 0)) /* Generic Wait available */ +/** +* @brief Wait for Signal, Message, Mail, or Timeout +* @param millisec timeout value or 0 in case of no time-out +* @retval event that contains signal, message, or mail information or error code. +* @note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS. +*/ +osEvent osWait (uint32_t millisec); + +#endif /* Generic Wait available */ + +/*********************** Timer Management Functions ***************************/ +/** +* @brief Create a timer. +* @param timer_def timer object referenced with \ref osTimer. +* @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. +* @param argument argument to the timer call back function. +* @retval timer ID for reference by other functions or NULL in case of error. +* @note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS. +*/ +osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument) +{ +#if (configUSE_TIMERS == 1) + +#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + if(timer_def->controlblock != NULL) { + return xTimerCreateStatic((const char *)"", + 1, // period should be filled when starting the Timer using osTimerStart + (type == osTimerPeriodic) ? pdTRUE : pdFALSE, + (void *) argument, + (TaskFunction_t)timer_def->ptimer, + (StaticTimer_t *)timer_def->controlblock); + } + else { + return xTimerCreate((const char *)"", + 1, // period should be filled when starting the Timer using osTimerStart + (type == osTimerPeriodic) ? pdTRUE : pdFALSE, + (void *) argument, + (TaskFunction_t)timer_def->ptimer); + } +#elif( configSUPPORT_STATIC_ALLOCATION == 1 ) + return xTimerCreateStatic((const char *)"", + 1, // period should be filled when starting the Timer using osTimerStart + (type == osTimerPeriodic) ? pdTRUE : pdFALSE, + (void *) argument, + (TaskFunction_t)timer_def->ptimer, + (StaticTimer_t *)timer_def->controlblock); +#else + return xTimerCreate((const char *)"", + 1, // period should be filled when starting the Timer using osTimerStart + (type == osTimerPeriodic) ? pdTRUE : pdFALSE, + (void *) argument, + (TaskFunction_t)timer_def->ptimer); +#endif + +#else + return NULL; +#endif +} + +/** +* @brief Start or restart a timer. +* @param timer_id timer ID obtained by \ref osTimerCreate. +* @param millisec time delay value of the timer. +* @retval status code that indicates the execution status of the function +* @note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS. +*/ +osStatus osTimerStart (osTimerId timer_id, uint32_t millisec) +{ + osStatus result = osOK; +#if (configUSE_TIMERS == 1) + portBASE_TYPE taskWoken = pdFALSE; + TickType_t ticks = millisec / portTICK_PERIOD_MS; + + if (ticks == 0) + ticks = 1; + + if (inHandlerMode()) + { + if (xTimerChangePeriodFromISR(timer_id, ticks, &taskWoken) != pdPASS) + { + result = osErrorOS; + } + else + { + portEND_SWITCHING_ISR(taskWoken); + } + } + else + { + if (xTimerChangePeriod(timer_id, ticks, 0) != pdPASS) + result = osErrorOS; + } + +#else + result = osErrorOS; +#endif + return result; +} + +/** +* @brief Stop a timer. +* @param timer_id timer ID obtained by \ref osTimerCreate +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS. +*/ +osStatus osTimerStop (osTimerId timer_id) +{ + osStatus result = osOK; +#if (configUSE_TIMERS == 1) + portBASE_TYPE taskWoken = pdFALSE; + + if (inHandlerMode()) { + if (xTimerStopFromISR(timer_id, &taskWoken) != pdPASS) { + return osErrorOS; + } + portEND_SWITCHING_ISR(taskWoken); + } + else { + if (xTimerStop(timer_id, 0) != pdPASS) { + result = osErrorOS; + } + } +#else + result = osErrorOS; +#endif + return result; +} + +/** +* @brief Delete a timer. +* @param timer_id timer ID obtained by \ref osTimerCreate +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS. +*/ +osStatus osTimerDelete (osTimerId timer_id) +{ +osStatus result = osOK; + +#if (configUSE_TIMERS == 1) + + if (inHandlerMode()) { + return osErrorISR; + } + else { + if ((xTimerDelete(timer_id, osWaitForever )) != pdPASS) { + result = osErrorOS; + } + } + +#else + result = osErrorOS; +#endif + + return result; +} + +/*************************** Signal Management ********************************/ +/** +* @brief Set the specified Signal Flags of an active thread. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @param signals specifies the signal flags of the thread that should be set. +* @retval previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. +* @note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS. +*/ +int32_t osSignalSet (osThreadId thread_id, int32_t signal) +{ +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + uint32_t ulPreviousNotificationValue = 0; + + if (inHandlerMode()) + { + if(xTaskGenericNotifyFromISR( thread_id , (uint32_t)signal, eSetBits, &ulPreviousNotificationValue, &xHigherPriorityTaskWoken ) != pdPASS ) + return 0x80000000; + + portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); + } + else if(xTaskGenericNotify( thread_id , (uint32_t)signal, eSetBits, &ulPreviousNotificationValue) != pdPASS ) + return 0x80000000; + + return ulPreviousNotificationValue; +#else + (void) thread_id; + (void) signal; + + return 0x80000000; /* Task Notification not supported */ +#endif +} + +/** +* @brief Clear the specified Signal Flags of an active thread. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @param signals specifies the signal flags of the thread that shall be cleared. +* @retval previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. +* @note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS. +*/ +int32_t osSignalClear (osThreadId thread_id, int32_t signal); + +/** +* @brief Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread. +* @param signals wait until all specified signal flags set or 0 for any single signal flag. +* @param millisec timeout value or 0 in case of no time-out. +* @retval event flag information or error code. +* @note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS. +*/ +osEvent osSignalWait (int32_t signals, uint32_t millisec) +{ + osEvent ret; + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + + TickType_t ticks; + + ret.value.signals = 0; + ticks = 0; + if (millisec == osWaitForever) { + ticks = portMAX_DELAY; + } + else if (millisec != 0) { + ticks = millisec / portTICK_PERIOD_MS; + if (ticks == 0) { + ticks = 1; + } + } + + if (inHandlerMode()) + { + ret.status = osErrorISR; /*Not allowed in ISR*/ + } + else + { + if(xTaskNotifyWait( 0,(uint32_t) signals, (uint32_t *)&ret.value.signals, ticks) != pdTRUE) + { + if(ticks == 0) ret.status = osOK; + else ret.status = osEventTimeout; + } + else if(ret.value.signals < 0) + { + ret.status = osErrorValue; + } + else ret.status = osEventSignal; + } +#else + (void) signals; + (void) millisec; + + ret.status = osErrorOS; /* Task Notification not supported */ +#endif + + return ret; +} + +/**************************** Mutex Management ********************************/ +/** +* @brief Create and Initialize a Mutex object +* @param mutex_def mutex definition referenced with \ref osMutex. +* @retval mutex ID for reference by other functions or NULL in case of error. +* @note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS. +*/ +osMutexId osMutexCreate (const osMutexDef_t *mutex_def) +{ +#if ( configUSE_MUTEXES == 1) + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + if (mutex_def->controlblock != NULL) { + return xSemaphoreCreateMutexStatic( mutex_def->controlblock ); + } + else { + return xSemaphoreCreateMutex(); + } +#elif ( configSUPPORT_STATIC_ALLOCATION == 1 ) + return xSemaphoreCreateMutexStatic( mutex_def->controlblock ); +#else + return xSemaphoreCreateMutex(); +#endif +#else + return NULL; +#endif +} + +/** +* @brief Wait until a Mutex becomes available +* @param mutex_id mutex ID obtained by \ref osMutexCreate. +* @param millisec timeout value or 0 in case of no time-out. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS. +*/ +osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec) +{ + TickType_t ticks; + portBASE_TYPE taskWoken = pdFALSE; + + + if (mutex_id == NULL) { + return osErrorParameter; + } + + ticks = 0; + if (millisec == osWaitForever) { + ticks = portMAX_DELAY; + } + else if (millisec != 0) { + ticks = millisec / portTICK_PERIOD_MS; + if (ticks == 0) { + ticks = 1; + } + } + + if (inHandlerMode()) { + if (xSemaphoreTakeFromISR(mutex_id, &taskWoken) != pdTRUE) { + return osErrorOS; + } + portEND_SWITCHING_ISR(taskWoken); + } + else if (xSemaphoreTake(mutex_id, ticks) != pdTRUE) { + return osErrorOS; + } + + return osOK; +} + +/** +* @brief Release a Mutex that was obtained by \ref osMutexWait +* @param mutex_id mutex ID obtained by \ref osMutexCreate. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS. +*/ +osStatus osMutexRelease (osMutexId mutex_id) +{ + osStatus result = osOK; + portBASE_TYPE taskWoken = pdFALSE; + + if (inHandlerMode()) { + if (xSemaphoreGiveFromISR(mutex_id, &taskWoken) != pdTRUE) { + return osErrorOS; + } + portEND_SWITCHING_ISR(taskWoken); + } + else if (xSemaphoreGive(mutex_id) != pdTRUE) + { + result = osErrorOS; + } + return result; +} + +/** +* @brief Delete a Mutex +* @param mutex_id mutex ID obtained by \ref osMutexCreate. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS. +*/ +osStatus osMutexDelete (osMutexId mutex_id) +{ + if (inHandlerMode()) { + return osErrorISR; + } + + vQueueDelete(mutex_id); + + return osOK; +} + +/******************** Semaphore Management Functions **************************/ + +#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) + +/** +* @brief Create and Initialize a Semaphore object used for managing resources +* @param semaphore_def semaphore definition referenced with \ref osSemaphore. +* @param count number of available resources. +* @retval semaphore ID for reference by other functions or NULL in case of error. +* @note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS. +*/ +osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count) +{ +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + osSemaphoreId sema; + + if (semaphore_def->controlblock != NULL){ + if (count == 1) { + return xSemaphoreCreateBinaryStatic( semaphore_def->controlblock ); + } + else { +#if (configUSE_COUNTING_SEMAPHORES == 1 ) + return xSemaphoreCreateCountingStatic( count, count, semaphore_def->controlblock ); +#else + return NULL; +#endif + } + } + else { + if (count == 1) { + vSemaphoreCreateBinary(sema); + return sema; + } + else { +#if (configUSE_COUNTING_SEMAPHORES == 1 ) + return xSemaphoreCreateCounting(count, count); +#else + return NULL; +#endif + } + } +#elif ( configSUPPORT_STATIC_ALLOCATION == 1 ) // configSUPPORT_DYNAMIC_ALLOCATION == 0 + if(count == 1) { + return xSemaphoreCreateBinaryStatic( semaphore_def->controlblock ); + } + else + { +#if (configUSE_COUNTING_SEMAPHORES == 1 ) + return xSemaphoreCreateCountingStatic( count, count, semaphore_def->controlblock ); +#else + return NULL; +#endif + } +#else // configSUPPORT_STATIC_ALLOCATION == 0 && configSUPPORT_DYNAMIC_ALLOCATION == 1 + osSemaphoreId sema; + + if (count == 1) { + vSemaphoreCreateBinary(sema); + return sema; + } + else { +#if (configUSE_COUNTING_SEMAPHORES == 1 ) + return xSemaphoreCreateCounting(count, count); +#else + return NULL; +#endif + } +#endif +} + +/** +* @brief Wait until a Semaphore token becomes available +* @param semaphore_id semaphore object referenced with \ref osSemaphore. +* @param millisec timeout value or 0 in case of no time-out. +* @retval number of available tokens, or -1 in case of incorrect parameters. +* @note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS. +*/ +int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec) +{ + TickType_t ticks; + portBASE_TYPE taskWoken = pdFALSE; + + + if (semaphore_id == NULL) { + return osErrorParameter; + } + + ticks = 0; + if (millisec == osWaitForever) { + ticks = portMAX_DELAY; + } + else if (millisec != 0) { + ticks = millisec / portTICK_PERIOD_MS; + if (ticks == 0) { + ticks = 1; + } + } + + if (inHandlerMode()) { + if (xSemaphoreTakeFromISR(semaphore_id, &taskWoken) != pdTRUE) { + return osErrorOS; + } + portEND_SWITCHING_ISR(taskWoken); + } + else if (xSemaphoreTake(semaphore_id, ticks) != pdTRUE) { + return osErrorOS; + } + + return osOK; +} + +/** +* @brief Release a Semaphore token +* @param semaphore_id semaphore object referenced with \ref osSemaphore. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS. +*/ +osStatus osSemaphoreRelease (osSemaphoreId semaphore_id) +{ + osStatus result = osOK; + portBASE_TYPE taskWoken = pdFALSE; + + + if (inHandlerMode()) { + if (xSemaphoreGiveFromISR(semaphore_id, &taskWoken) != pdTRUE) { + return osErrorOS; + } + portEND_SWITCHING_ISR(taskWoken); + } + else { + if (xSemaphoreGive(semaphore_id) != pdTRUE) { + result = osErrorOS; + } + } + + return result; +} + +/** +* @brief Delete a Semaphore +* @param semaphore_id semaphore object referenced with \ref osSemaphore. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS. +*/ +osStatus osSemaphoreDelete (osSemaphoreId semaphore_id) +{ + if (inHandlerMode()) { + return osErrorISR; + } + + vSemaphoreDelete(semaphore_id); + + return osOK; +} + +#endif /* Use Semaphores */ + +/******************* Memory Pool Management Functions ***********************/ + +#if (defined (osFeature_Pool) && (osFeature_Pool != 0)) + +//TODO +//This is a primitive and inefficient wrapper around the existing FreeRTOS memory management. +//A better implementation will have to modify heap_x.c! + + +typedef struct os_pool_cb { + void *pool; + uint8_t *markers; + uint32_t pool_sz; + uint32_t item_sz; + uint32_t currentIndex; +} os_pool_cb_t; + + +/** +* @brief Create and Initialize a memory pool +* @param pool_def memory pool definition referenced with \ref osPool. +* @retval memory pool ID for reference by other functions or NULL in case of error. +* @note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS. +*/ +osPoolId osPoolCreate (const osPoolDef_t *pool_def) +{ +#if (configSUPPORT_DYNAMIC_ALLOCATION == 1) + osPoolId thePool; + int itemSize = 4 * ((pool_def->item_sz + 3) / 4); + uint32_t i; + + /* First have to allocate memory for the pool control block. */ + thePool = pvPortMalloc(sizeof(os_pool_cb_t)); + + + if (thePool) { + thePool->pool_sz = pool_def->pool_sz; + thePool->item_sz = itemSize; + thePool->currentIndex = 0; + + /* Memory for markers */ + thePool->markers = pvPortMalloc(pool_def->pool_sz); + + if (thePool->markers) { + /* Now allocate the pool itself. */ + thePool->pool = pvPortMalloc(pool_def->pool_sz * itemSize); + + if (thePool->pool) { + for (i = 0; i < pool_def->pool_sz; i++) { + thePool->markers[i] = 0; + } + } + else { + vPortFree(thePool->markers); + vPortFree(thePool); + thePool = NULL; + } + } + else { + vPortFree(thePool); + thePool = NULL; + } + } + + return thePool; + +#else + return NULL; +#endif +} + +/** +* @brief Allocate a memory block from a memory pool +* @param pool_id memory pool ID obtain referenced with \ref osPoolCreate. +* @retval address of the allocated memory block or NULL in case of no memory available. +* @note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS. +*/ +void *osPoolAlloc (osPoolId pool_id) +{ + int dummy = 0; + void *p = NULL; + uint32_t i; + uint32_t index; + + if (inHandlerMode()) { + dummy = portSET_INTERRUPT_MASK_FROM_ISR(); + } + else { + vPortEnterCritical(); + } + + for (i = 0; i < pool_id->pool_sz; i++) { + index = pool_id->currentIndex + i; + if (index >= pool_id->pool_sz) { + index = 0; + } + + if (pool_id->markers[index] == 0) { + pool_id->markers[index] = 1; + p = (void *)((uint32_t)(pool_id->pool) + (index * pool_id->item_sz)); + pool_id->currentIndex = index; + break; + } + } + + if (inHandlerMode()) { + portCLEAR_INTERRUPT_MASK_FROM_ISR(dummy); + } + else { + vPortExitCritical(); + } + + return p; +} + +/** +* @brief Allocate a memory block from a memory pool and set memory block to zero +* @param pool_id memory pool ID obtain referenced with \ref osPoolCreate. +* @retval address of the allocated memory block or NULL in case of no memory available. +* @note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS. +*/ +void *osPoolCAlloc (osPoolId pool_id) +{ + void *p = osPoolAlloc(pool_id); + + if (p != NULL) + { + memset(p, 0, sizeof(pool_id->pool_sz)); + } + + return p; +} + +/** +* @brief Return an allocated memory block back to a specific memory pool +* @param pool_id memory pool ID obtain referenced with \ref osPoolCreate. +* @param block address of the allocated memory block that is returned to the memory pool. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS. +*/ +osStatus osPoolFree (osPoolId pool_id, void *block) +{ + uint32_t index; + + if (pool_id == NULL) { + return osErrorParameter; + } + + if (block == NULL) { + return osErrorParameter; + } + + if (block < pool_id->pool) { + return osErrorParameter; + } + + index = (uint32_t)block - (uint32_t)(pool_id->pool); + if (index % pool_id->item_sz) { + return osErrorParameter; + } + index = index / pool_id->item_sz; + if (index >= pool_id->pool_sz) { + return osErrorParameter; + } + + pool_id->markers[index] = 0; + + return osOK; +} + + +#endif /* Use Memory Pool Management */ + +/******************* Message Queue Management Functions *********************/ + +#if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) /* Use Message Queues */ + +/** +* @brief Create and Initialize a Message Queue +* @param queue_def queue definition referenced with \ref osMessageQ. +* @param thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. +* @retval message queue ID for reference by other functions or NULL in case of error. +* @note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS. +*/ +osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id) +{ + (void) thread_id; + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + if ((queue_def->buffer != NULL) && (queue_def->controlblock != NULL)) { + return xQueueCreateStatic(queue_def->queue_sz, queue_def->item_sz, queue_def->buffer, queue_def->controlblock); + } + else { + return xQueueCreate(queue_def->queue_sz, queue_def->item_sz); + } +#elif ( configSUPPORT_STATIC_ALLOCATION == 1 ) + return xQueueCreateStatic(queue_def->queue_sz, queue_def->item_sz, queue_def->buffer, queue_def->controlblock); +#else + return xQueueCreate(queue_def->queue_sz, queue_def->item_sz); +#endif +} + +/** +* @brief Put a Message to a Queue. +* @param queue_id message queue ID obtained with \ref osMessageCreate. +* @param info message information. +* @param millisec timeout value or 0 in case of no time-out. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS. +*/ +osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec) +{ + portBASE_TYPE taskWoken = pdFALSE; + TickType_t ticks; + + ticks = millisec / portTICK_PERIOD_MS; + if (ticks == 0) { + ticks = 1; + } + + if (inHandlerMode()) { + if (xQueueSendFromISR(queue_id, &info, &taskWoken) != pdTRUE) { + return osErrorOS; + } + portEND_SWITCHING_ISR(taskWoken); + } + else { + if (xQueueSend(queue_id, &info, ticks) != pdTRUE) { + return osErrorOS; + } + } + + return osOK; +} + +/** +* @brief Get a Message or Wait for a Message from a Queue. +* @param queue_id message queue ID obtained with \ref osMessageCreate. +* @param millisec timeout value or 0 in case of no time-out. +* @retval event information that includes status code. +* @note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS. +*/ +osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec) +{ + portBASE_TYPE taskWoken; + TickType_t ticks; + osEvent event; + + event.def.message_id = queue_id; + event.value.v = 0; + + if (queue_id == NULL) { + event.status = osErrorParameter; + return event; + } + + taskWoken = pdFALSE; + + ticks = 0; + if (millisec == osWaitForever) { + ticks = portMAX_DELAY; + } + else if (millisec != 0) { + ticks = millisec / portTICK_PERIOD_MS; + if (ticks == 0) { + ticks = 1; + } + } + + if (inHandlerMode()) { + if (xQueueReceiveFromISR(queue_id, &event.value.v, &taskWoken) == pdTRUE) { + /* We have mail */ + event.status = osEventMessage; + } + else { + event.status = osOK; + } + portEND_SWITCHING_ISR(taskWoken); + } + else { + if (xQueueReceive(queue_id, &event.value.v, ticks) == pdTRUE) { + /* We have mail */ + event.status = osEventMessage; + } + else { + event.status = (ticks == 0) ? osOK : osEventTimeout; + } + } + + return event; +} + +#endif /* Use Message Queues */ + +/******************** Mail Queue Management Functions ***********************/ +#if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) /* Use Mail Queues */ + + +typedef struct os_mailQ_cb { + const osMailQDef_t *queue_def; + QueueHandle_t handle; + osPoolId pool; +} os_mailQ_cb_t; + +/** +* @brief Create and Initialize mail queue +* @param queue_def reference to the mail queue definition obtain with \ref osMailQ +* @param thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. +* @retval mail queue ID for reference by other functions or NULL in case of error. +* @note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS. +*/ +osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id) +{ +#if (configSUPPORT_DYNAMIC_ALLOCATION == 1) + (void) thread_id; + + osPoolDef_t pool_def = {queue_def->queue_sz, queue_def->item_sz, NULL}; + + /* Create a mail queue control block */ + + *(queue_def->cb) = pvPortMalloc(sizeof(struct os_mailQ_cb)); + + if (*(queue_def->cb) == NULL) { + return NULL; + } + (*(queue_def->cb))->queue_def = queue_def; + + /* Create a queue in FreeRTOS */ + (*(queue_def->cb))->handle = xQueueCreate(queue_def->queue_sz, sizeof(void *)); + + + if ((*(queue_def->cb))->handle == NULL) { + vPortFree(*(queue_def->cb)); + return NULL; + } + + /* Create a mail pool */ + (*(queue_def->cb))->pool = osPoolCreate(&pool_def); + if ((*(queue_def->cb))->pool == NULL) { + //TODO: Delete queue. How to do it in FreeRTOS? + vPortFree(*(queue_def->cb)); + return NULL; + } + + return *(queue_def->cb); +#else + return NULL; +#endif +} + +/** +* @brief Allocate a memory block from a mail +* @param queue_id mail queue ID obtained with \ref osMailCreate. +* @param millisec timeout value or 0 in case of no time-out. +* @retval pointer to memory block that can be filled with mail or NULL in case error. +* @note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS. +*/ +void *osMailAlloc (osMailQId queue_id, uint32_t millisec) +{ + (void) millisec; + void *p; + + + if (queue_id == NULL) { + return NULL; + } + + p = osPoolAlloc(queue_id->pool); + + return p; +} + +/** +* @brief Allocate a memory block from a mail and set memory block to zero +* @param queue_id mail queue ID obtained with \ref osMailCreate. +* @param millisec timeout value or 0 in case of no time-out. +* @retval pointer to memory block that can be filled with mail or NULL in case error. +* @note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS. +*/ +void *osMailCAlloc (osMailQId queue_id, uint32_t millisec) +{ + uint32_t i; + void *p = osMailAlloc(queue_id, millisec); + + if (p) { + for (i = 0; i < queue_id->queue_def->item_sz; i++) { + ((uint8_t *)p)[i] = 0; + } + } + + return p; +} + +/** +* @brief Put a mail to a queue +* @param queue_id mail queue ID obtained with \ref osMailCreate. +* @param mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS. +*/ +osStatus osMailPut (osMailQId queue_id, void *mail) +{ + portBASE_TYPE taskWoken; + + + if (queue_id == NULL) { + return osErrorParameter; + } + + taskWoken = pdFALSE; + + if (inHandlerMode()) { + if (xQueueSendFromISR(queue_id->handle, &mail, &taskWoken) != pdTRUE) { + return osErrorOS; + } + portEND_SWITCHING_ISR(taskWoken); + } + else { + if (xQueueSend(queue_id->handle, &mail, 0) != pdTRUE) { + return osErrorOS; + } + } + + return osOK; +} + +/** +* @brief Get a mail from a queue +* @param queue_id mail queue ID obtained with \ref osMailCreate. +* @param millisec timeout value or 0 in case of no time-out +* @retval event that contains mail information or error code. +* @note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS. +*/ +osEvent osMailGet (osMailQId queue_id, uint32_t millisec) +{ + portBASE_TYPE taskWoken; + TickType_t ticks; + osEvent event; + + event.def.mail_id = queue_id; + + if (queue_id == NULL) { + event.status = osErrorParameter; + return event; + } + + taskWoken = pdFALSE; + + ticks = 0; + if (millisec == osWaitForever) { + ticks = portMAX_DELAY; + } + else if (millisec != 0) { + ticks = millisec / portTICK_PERIOD_MS; + if (ticks == 0) { + ticks = 1; + } + } + + if (inHandlerMode()) { + if (xQueueReceiveFromISR(queue_id->handle, &event.value.p, &taskWoken) == pdTRUE) { + /* We have mail */ + event.status = osEventMail; + } + else { + event.status = osOK; + } + portEND_SWITCHING_ISR(taskWoken); + } + else { + if (xQueueReceive(queue_id->handle, &event.value.p, ticks) == pdTRUE) { + /* We have mail */ + event.status = osEventMail; + } + else { + event.status = (ticks == 0) ? osOK : osEventTimeout; + } + } + + return event; +} + +/** +* @brief Free a memory block from a mail +* @param queue_id mail queue ID obtained with \ref osMailCreate. +* @param mail pointer to the memory block that was obtained with \ref osMailGet. +* @retval status code that indicates the execution status of the function. +* @note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS. +*/ +osStatus osMailFree (osMailQId queue_id, void *mail) +{ + if (queue_id == NULL) { + return osErrorParameter; + } + + return osPoolFree(queue_id->pool, mail); +} +#endif /* Use Mail Queues */ + +/*************************** Additional specific APIs to Free RTOS ************/ +/** +* @brief Handles the tick increment +* @param none. +* @retval none. +*/ +void osSystickHandler(void) +{ + +#if (INCLUDE_xTaskGetSchedulerState == 1 ) + if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) + { +#endif /* INCLUDE_xTaskGetSchedulerState */ + xPortSysTickHandler(); +#if (INCLUDE_xTaskGetSchedulerState == 1 ) + } +#endif /* INCLUDE_xTaskGetSchedulerState */ +} + +#if ( INCLUDE_eTaskGetState == 1 ) +/** +* @brief Obtain the state of any thread. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @retval the stae of the thread, states are encoded by the osThreadState enumerated type. +*/ +osThreadState osThreadGetState(osThreadId thread_id) +{ + eTaskState ThreadState; + osThreadState result; + + ThreadState = eTaskGetState(thread_id); + + switch (ThreadState) + { + case eRunning : + result = osThreadRunning; + break; + case eReady : + result = osThreadReady; + break; + case eBlocked : + result = osThreadBlocked; + break; + case eSuspended : + result = osThreadSuspended; + break; + case eDeleted : + result = osThreadDeleted; + break; + default: + result = osThreadError; + } + + return result; +} +#endif /* INCLUDE_eTaskGetState */ + +#if (INCLUDE_eTaskGetState == 1) +/** +* @brief Check if a thread is already suspended or not. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadIsSuspended(osThreadId thread_id) +{ + if (eTaskGetState(thread_id) == eSuspended) + return osOK; + else + return osErrorOS; +} +#endif /* INCLUDE_eTaskGetState */ +/** +* @brief Suspend execution of a thread. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadSuspend (osThreadId thread_id) +{ +#if (INCLUDE_vTaskSuspend == 1) + vTaskSuspend(thread_id); + + return osOK; +#else + return osErrorResource; +#endif +} + +/** +* @brief Resume execution of a suspended thread. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadResume (osThreadId thread_id) +{ +#if (INCLUDE_vTaskSuspend == 1) + if(inHandlerMode()) + { + if (xTaskResumeFromISR(thread_id) == pdTRUE) + { + portYIELD_FROM_ISR(pdTRUE); + } + } + else + { + vTaskResume(thread_id); + } + return osOK; +#else + return osErrorResource; +#endif +} + +/** +* @brief Suspend execution of a all active threads. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadSuspendAll (void) +{ + vTaskSuspendAll(); + + return osOK; +} + +/** +* @brief Resume execution of a all suspended threads. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadResumeAll (void) +{ + if (xTaskResumeAll() == pdTRUE) + return osOK; + else + return osErrorOS; + +} + +/** +* @brief Delay a task until a specified time +* @param PreviousWakeTime Pointer to a variable that holds the time at which the +* task was last unblocked. PreviousWakeTime must be initialised with the current time +* prior to its first use (PreviousWakeTime = osKernelSysTick() ) +* @param millisec time delay value +* @retval status code that indicates the execution status of the function. +*/ +osStatus osDelayUntil (uint32_t *PreviousWakeTime, uint32_t millisec) +{ +#if INCLUDE_vTaskDelayUntil + TickType_t ticks = (millisec / portTICK_PERIOD_MS); + vTaskDelayUntil((TickType_t *) PreviousWakeTime, ticks ? ticks : 1); + + return osOK; +#else + (void) millisec; + (void) PreviousWakeTime; + + return osErrorResource; +#endif +} + +/** +* @brief Abort the delay for a specific thread +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId +* @retval status code that indicates the execution status of the function. +*/ +osStatus osAbortDelay(osThreadId thread_id) +{ +#if INCLUDE_xTaskAbortDelay + + xTaskAbortDelay(thread_id); + + return osOK; +#else + (void) thread_id; + + return osErrorResource; +#endif +} + +/** +* @brief Lists all the current threads, along with their current state +* and stack usage high water mark. +* @param buffer A buffer into which the above mentioned details +* will be written +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadList (uint8_t *buffer) +{ +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) + vTaskList((char *)buffer); +#endif + return osOK; +} + +/** +* @brief Receive an item from a queue without removing the item from the queue. +* @param queue_id message queue ID obtained with \ref osMessageCreate. +* @param millisec timeout value or 0 in case of no time-out. +* @retval event information that includes status code. +*/ +osEvent osMessagePeek (osMessageQId queue_id, uint32_t millisec) +{ + TickType_t ticks; + osEvent event; + + event.def.message_id = queue_id; + + if (queue_id == NULL) { + event.status = osErrorParameter; + return event; + } + + ticks = 0; + if (millisec == osWaitForever) { + ticks = portMAX_DELAY; + } + else if (millisec != 0) { + ticks = millisec / portTICK_PERIOD_MS; + if (ticks == 0) { + ticks = 1; + } + } + + if (xQueuePeek(queue_id, &event.value.v, ticks) == pdTRUE) + { + /* We have mail */ + event.status = osEventMessage; + } + else + { + event.status = (ticks == 0) ? osOK : osEventTimeout; + } + + return event; +} + +/** +* @brief Get the number of messaged stored in a queue. +* @param queue_id message queue ID obtained with \ref osMessageCreate. +* @retval number of messages stored in a queue. +*/ +uint32_t osMessageWaiting(osMessageQId queue_id) +{ + if (inHandlerMode()) { + return uxQueueMessagesWaitingFromISR(queue_id); + } + else + { + return uxQueueMessagesWaiting(queue_id); + } +} + +/** +* @brief Get the available space in a message queue. +* @param queue_id message queue ID obtained with \ref osMessageCreate. +* @retval available space in a message queue. +*/ +uint32_t osMessageAvailableSpace(osMessageQId queue_id) +{ + return uxQueueSpacesAvailable(queue_id); +} + +/** +* @brief Delete a Message Queue +* @param queue_id message queue ID obtained with \ref osMessageCreate. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osMessageDelete (osMessageQId queue_id) +{ + if (inHandlerMode()) { + return osErrorISR; + } + + vQueueDelete(queue_id); + + return osOK; +} + +/** +* @brief Create and Initialize a Recursive Mutex +* @param mutex_def mutex definition referenced with \ref osMutex. +* @retval mutex ID for reference by other functions or NULL in case of error.. +*/ +osMutexId osRecursiveMutexCreate (const osMutexDef_t *mutex_def) +{ +#if (configUSE_RECURSIVE_MUTEXES == 1) +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + if (mutex_def->controlblock != NULL){ + return xSemaphoreCreateRecursiveMutexStatic( mutex_def->controlblock ); + } + else { + return xSemaphoreCreateRecursiveMutex(); + } +#elif ( configSUPPORT_STATIC_ALLOCATION == 1 ) + return xSemaphoreCreateRecursiveMutexStatic( mutex_def->controlblock ); +#else + return xSemaphoreCreateRecursiveMutex(); +#endif +#else + return NULL; +#endif +} + +/** +* @brief Release a Recursive Mutex +* @param mutex_id mutex ID obtained by \ref osRecursiveMutexCreate. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osRecursiveMutexRelease (osMutexId mutex_id) +{ +#if (configUSE_RECURSIVE_MUTEXES == 1) + osStatus result = osOK; + + if (xSemaphoreGiveRecursive(mutex_id) != pdTRUE) + { + result = osErrorOS; + } + return result; +#else + return osErrorResource; +#endif +} + +/** +* @brief Release a Recursive Mutex +* @param mutex_id mutex ID obtained by \ref osRecursiveMutexCreate. +* @param millisec timeout value or 0 in case of no time-out. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osRecursiveMutexWait (osMutexId mutex_id, uint32_t millisec) +{ +#if (configUSE_RECURSIVE_MUTEXES == 1) + TickType_t ticks; + + if (mutex_id == NULL) + { + return osErrorParameter; + } + + ticks = 0; + if (millisec == osWaitForever) + { + ticks = portMAX_DELAY; + } + else if (millisec != 0) + { + ticks = millisec / portTICK_PERIOD_MS; + if (ticks == 0) + { + ticks = 1; + } + } + + if (xSemaphoreTakeRecursive(mutex_id, ticks) != pdTRUE) + { + return osErrorOS; + } + return osOK; +#else + return osErrorResource; +#endif +} + +/** +* @brief Returns the current count value of a counting semaphore +* @param semaphore_id semaphore_id ID obtained by \ref osSemaphoreCreate. +* @retval count value +*/ +uint32_t osSemaphoreGetCount(osSemaphoreId semaphore_id) +{ + return uxSemaphoreGetCount(semaphore_id); +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h new file mode 100644 index 0000000..c3f2cc2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h @@ -0,0 +1,1039 @@ +/* ---------------------------------------------------------------------- + * $Date: 5. February 2013 + * $Revision: V1.02 + * + * Project: CMSIS-RTOS API + * Title: cmsis_os.h header file + * + * Version 0.02 + * Initial Proposal Phase + * Version 0.03 + * osKernelStart added, optional feature: main started as thread + * osSemaphores have standard behavior + * osTimerCreate does not start the timer, added osTimerStart + * osThreadPass is renamed to osThreadYield + * Version 1.01 + * Support for C++ interface + * - const attribute removed from the osXxxxDef_t typedef's + * - const attribute added to the osXxxxDef macros + * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete + * Added: osKernelInitialize + * Version 1.02 + * Control functions for short timeouts in microsecond resolution: + * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec + * Removed: osSignalGet + * + * + *---------------------------------------------------------------------------- + * + * Portions Copyright (c) 2013 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. + *---------------------------------------------------------------------------*/ + + /** + ****************************************************************************** + * @file cmsis_os.h + * @author + * @date + * @brief Header of cmsis_os.c + * A new set of APIs are added in addition to existing ones, these APIs + * are specific to FreeRTOS. + ****************************************************************************** + * @attention + * + ****************************************************************************** + */ + +#include "FreeRTOS.h" +#include "task.h" +#include "timers.h" +#include "queue.h" +#include "semphr.h" +#include "event_groups.h" + +/** +\page cmsis_os_h Header File Template: cmsis_os.h + +The file \b cmsis_os.h is a template header file for a CMSIS-RTOS compliant Real-Time Operating System (RTOS). +Each RTOS that is compliant with CMSIS-RTOS shall provide a specific \b cmsis_os.h header file that represents +its implementation. + +The file cmsis_os.h contains: + - CMSIS-RTOS API function definitions + - struct definitions for parameters and return types + - status and priority values used by CMSIS-RTOS API functions + - macros for defining threads and other kernel objects + + +Name conventions and header file modifications + +All definitions are prefixed with \b os to give an unique name space for CMSIS-RTOS functions. +Definitions that are prefixed \b os_ are not used in the application code but local to this header file. +All definitions and functions that belong to a module are grouped and have a common prefix, i.e. \b osThread. + +Definitions that are marked with CAN BE CHANGED can be adapted towards the needs of the actual CMSIS-RTOS implementation. +These definitions can be specific to the underlying RTOS kernel. + +Definitions that are marked with MUST REMAIN UNCHANGED cannot be altered. Otherwise the CMSIS-RTOS implementation is no longer +compliant to the standard. Note that some functions are optional and need not to be provided by every CMSIS-RTOS implementation. + + +Function calls from interrupt service routines + +The following CMSIS-RTOS functions can be called from threads and interrupt service routines (ISR): + - \ref osSignalSet + - \ref osSemaphoreRelease + - \ref osPoolAlloc, \ref osPoolCAlloc, \ref osPoolFree + - \ref osMessagePut, \ref osMessageGet + - \ref osMailAlloc, \ref osMailCAlloc, \ref osMailGet, \ref osMailPut, \ref osMailFree + +Functions that cannot be called from an ISR are verifying the interrupt status and return in case that they are called +from an ISR context the status code \b osErrorISR. In some implementations this condition might be caught using the HARD FAULT vector. + +Some CMSIS-RTOS implementations support CMSIS-RTOS function calls from multiple ISR at the same time. +If this is impossible, the CMSIS-RTOS rejects calls by nested ISR functions with the status code \b osErrorISRRecursive. + + +Define and reference object definitions + +With \#define osObjectsExternal objects are defined as external symbols. This allows to create a consistent header file +that is used throughout a project as shown below: + +Header File +\code +#include // CMSIS RTOS header file + +// Thread definition +extern void thread_sample (void const *argument); // function prototype +osThreadDef (thread_sample, osPriorityBelowNormal, 1, 100); + +// Pool definition +osPoolDef(MyPool, 10, long); +\endcode + + +This header file defines all objects when included in a C/C++ source file. When \#define osObjectsExternal is +present before the header file, the objects are defined as external symbols. A single consistent header file can therefore be +used throughout the whole project. + +Example +\code +#include "osObjects.h" // Definition of the CMSIS-RTOS objects +\endcode + +\code +#define osObjectExternal // Objects will be defined as external symbols +#include "osObjects.h" // Reference to the CMSIS-RTOS objects +\endcode + +*/ + +#ifndef _CMSIS_OS_H +#define _CMSIS_OS_H + +/// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version. +#define osCMSIS 0x10002 ///< API version (main [31:16] .sub [15:0]) + +/// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number. +#define osCMSIS_KERNEL 0x10000 ///< RTOS identification and version (main [31:16] .sub [15:0]) + +/// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS. +#define osKernelSystemId "KERNEL V1.00" ///< RTOS identification string + +/// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS. +#define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available +#define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available +#define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available +#define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available +#define osFeature_Signals 8 ///< maximum number of Signal Flags available per thread +#define osFeature_Semaphore 1 ///< osFeature_Semaphore function: 1=available, 0=not available +#define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available +#define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available + +#ifdef __cplusplus +extern "C" +{ +#endif + + +// ==== Enumeration, structures, defines ==== + +/// Priority used for thread control. +/// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS. +typedef enum { + osPriorityIdle = -3, ///< priority: idle (lowest) + osPriorityLow = -2, ///< priority: low + osPriorityBelowNormal = -1, ///< priority: below normal + osPriorityNormal = 0, ///< priority: normal (default) + osPriorityAboveNormal = +1, ///< priority: above normal + osPriorityHigh = +2, ///< priority: high + osPriorityRealtime = +3, ///< priority: realtime (highest) + osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority +} osPriority; + +/// Timeout value. +/// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS. +#define osWaitForever 0xFFFFFFFF ///< wait forever timeout value + +/// Status code values returned by CMSIS-RTOS functions. +/// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS. +typedef enum { + osOK = 0, ///< function completed; no error or event occurred. + osEventSignal = 0x08, ///< function completed; signal event occurred. + osEventMessage = 0x10, ///< function completed; message event occurred. + osEventMail = 0x20, ///< function completed; mail event occurred. + osEventTimeout = 0x40, ///< function completed; timeout occurred. + osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object. + osErrorResource = 0x81, ///< resource not available: a specified resource was not available. + osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period. + osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines. + osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object. + osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority. + osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation. + osErrorValue = 0x86, ///< value of a parameter is out of range. + osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits. + os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization. +} osStatus; + +#if ( INCLUDE_eTaskGetState == 1 ) +/* Thread state returned by osThreadGetState */ +typedef enum { + osThreadRunning = 0x0, /* A thread is querying the state of itself, so must be running. */ + osThreadReady = 0x1 , /* The thread being queried is in a read or pending ready list. */ + osThreadBlocked = 0x2, /* The thread being queried is in the Blocked state. */ + osThreadSuspended = 0x3, /* The thread being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */ + osThreadDeleted = 0x4, /* The thread being queried has been deleted, but its TCB has not yet been freed. */ + osThreadError = 0x7FFFFFFF +} osThreadState; +#endif /* INCLUDE_eTaskGetState */ + +/// Timer type value for the timer definition. +/// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS. +typedef enum { + osTimerOnce = 0, ///< one-shot timer + osTimerPeriodic = 1 ///< repeating timer +} os_timer_type; + +/// Entry point of a thread. +/// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS. +typedef void (*os_pthread) (void const *argument); + +/// Entry point of a timer call back function. +/// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS. +typedef void (*os_ptimer) (void const *argument); + +// >>> the following data type definitions may shall adapted towards a specific RTOS + +/// Thread ID identifies the thread (pointer to a thread control block). +/// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS. +typedef TaskHandle_t osThreadId; + +/// Timer ID identifies the timer (pointer to a timer control block). +/// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS. +typedef TimerHandle_t osTimerId; + +/// Mutex ID identifies the mutex (pointer to a mutex control block). +/// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS. +typedef SemaphoreHandle_t osMutexId; + +/// Semaphore ID identifies the semaphore (pointer to a semaphore control block). +/// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS. +typedef SemaphoreHandle_t osSemaphoreId; + +/// Pool ID identifies the memory pool (pointer to a memory pool control block). +/// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS. +typedef struct os_pool_cb *osPoolId; + +/// Message ID identifies the message queue (pointer to a message queue control block). +/// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS. +typedef QueueHandle_t osMessageQId; + +/// Mail ID identifies the mail queue (pointer to a mail queue control block). +/// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS. +typedef struct os_mailQ_cb *osMailQId; + + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + +typedef StaticTask_t osStaticThreadDef_t; +typedef StaticTimer_t osStaticTimerDef_t; +typedef StaticSemaphore_t osStaticMutexDef_t; +typedef StaticSemaphore_t osStaticSemaphoreDef_t; +typedef StaticQueue_t osStaticMessageQDef_t; + +#endif + + + + +/// Thread Definition structure contains startup information of a thread. +/// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS. +typedef struct os_thread_def { + char *name; ///< Thread name + os_pthread pthread; ///< start address of thread function + osPriority tpriority; ///< initial thread priority + uint32_t instances; ///< maximum number of instances of that thread function + uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + uint32_t *buffer; ///< stack buffer for static allocation; NULL for dynamic allocation + osStaticThreadDef_t *controlblock; ///< control block to hold thread's data for static allocation; NULL for dynamic allocation +#endif +} osThreadDef_t; + +/// Timer Definition structure contains timer parameters. +/// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS. +typedef struct os_timer_def { + os_ptimer ptimer; ///< start address of a timer function +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + osStaticTimerDef_t *controlblock; ///< control block to hold timer's data for static allocation; NULL for dynamic allocation +#endif +} osTimerDef_t; + +/// Mutex Definition structure contains setup information for a mutex. +/// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS. +typedef struct os_mutex_def { + uint32_t dummy; ///< dummy value. +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + osStaticMutexDef_t *controlblock; ///< control block for static allocation; NULL for dynamic allocation +#endif +} osMutexDef_t; + +/// Semaphore Definition structure contains setup information for a semaphore. +/// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS. +typedef struct os_semaphore_def { + uint32_t dummy; ///< dummy value. +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + osStaticSemaphoreDef_t *controlblock; ///< control block for static allocation; NULL for dynamic allocation +#endif +} osSemaphoreDef_t; + +/// Definition structure for memory block allocation. +/// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS. +typedef struct os_pool_def { + uint32_t pool_sz; ///< number of items (elements) in the pool + uint32_t item_sz; ///< size of an item + void *pool; ///< pointer to memory for pool +} osPoolDef_t; + +/// Definition structure for message queue. +/// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS. +typedef struct os_messageQ_def { + uint32_t queue_sz; ///< number of elements in the queue + uint32_t item_sz; ///< size of an item +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + uint8_t *buffer; ///< buffer for static allocation; NULL for dynamic allocation + osStaticMessageQDef_t *controlblock; ///< control block to hold queue's data for static allocation; NULL for dynamic allocation +#endif + //void *pool; ///< memory array for messages +} osMessageQDef_t; + +/// Definition structure for mail queue. +/// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS. +typedef struct os_mailQ_def { + uint32_t queue_sz; ///< number of elements in the queue + uint32_t item_sz; ///< size of an item + struct os_mailQ_cb **cb; +} osMailQDef_t; + +/// Event structure contains detailed information about an event. +/// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS. +/// However the struct may be extended at the end. +typedef struct { + osStatus status; ///< status code: event or error information + union { + uint32_t v; ///< message as 32-bit value + void *p; ///< message or mail as void pointer + int32_t signals; ///< signal flags + } value; ///< event value + union { + osMailQId mail_id; ///< mail id obtained by \ref osMailCreate + osMessageQId message_id; ///< message id obtained by \ref osMessageCreate + } def; ///< event definition +} osEvent; + + +// ==== Kernel Control Functions ==== + +/// Initialize the RTOS Kernel for creating objects. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS. +osStatus osKernelInitialize (void); + +/// Start the RTOS Kernel. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS. +osStatus osKernelStart (void); + +/// Check if the RTOS kernel is already started. +/// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS. +/// \return 0 RTOS is not started, 1 RTOS is started. +int32_t osKernelRunning(void); + +#if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available + +/// Get the RTOS kernel system timer counter +/// \note MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS. +/// \return RTOS kernel system timer as 32-bit value +uint32_t osKernelSysTick (void); + +/// The RTOS kernel system timer frequency in Hz +/// \note Reflects the system timer setting and is typically defined in a configuration file. +#define osKernelSysTickFrequency (configTICK_RATE_HZ) + +/// Convert a microseconds value to a RTOS kernel system timer value. +/// \param microsec time value in microseconds. +/// \return time value normalized to the \ref osKernelSysTickFrequency +#define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000) + +#endif // System Timer available + +// ==== Thread Management ==== + +/// Create a Thread Definition with function, priority, and stack requirements. +/// \param name name of the thread function. +/// \param priority initial priority of the thread function. +/// \param instances number of possible thread instances. +/// \param stacksz stack size (in bytes) requirements for the thread function. +/// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#if defined (osObjectsExternal) // object is external +#define osThreadDef(name, thread, priority, instances, stacksz) \ +extern const osThreadDef_t os_thread_def_##name +#else // define the object + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) +#define osThreadDef(name, thread, priority, instances, stacksz) \ +const osThreadDef_t os_thread_def_##name = \ +{ #name, (thread), (priority), (instances), (stacksz), NULL, NULL } + +#define osThreadStaticDef(name, thread, priority, instances, stacksz, buffer, control) \ +const osThreadDef_t os_thread_def_##name = \ +{ #name, (thread), (priority), (instances), (stacksz), (buffer), (control) } +#else //configSUPPORT_STATIC_ALLOCATION == 0 + +#define osThreadDef(name, thread, priority, instances, stacksz) \ +const osThreadDef_t os_thread_def_##name = \ +{ #name, (thread), (priority), (instances), (stacksz)} +#endif +#endif + +/// Access a Thread definition. +/// \param name name of the thread definition object. +/// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#define osThread(name) \ +&os_thread_def_##name + +/// Create a thread and add it to Active Threads and set it to state READY. +/// \param[in] thread_def thread definition referenced with \ref osThread. +/// \param[in] argument pointer that is passed to the thread function as start argument. +/// \return thread ID for reference by other functions or NULL in case of error. +/// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS. +osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument); + +/// Return the thread ID of the current running thread. +/// \return thread ID for reference by other functions or NULL in case of error. +/// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS. +osThreadId osThreadGetId (void); + +/// Terminate execution of a thread and remove it from Active Threads. +/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS. +osStatus osThreadTerminate (osThreadId thread_id); + +/// Pass control to next thread that is in state \b READY. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS. +osStatus osThreadYield (void); + +/// Change priority of an active thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +/// \param[in] priority new priority value for the thread function. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS. +osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority); + +/// Get current priority of an active thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +/// \return current priority value of the thread function. +/// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS. +osPriority osThreadGetPriority (osThreadId thread_id); + + +// ==== Generic Wait Functions ==== + +/// Wait for Timeout (Time Delay). +/// \param[in] millisec time delay value +/// \return status code that indicates the execution status of the function. +osStatus osDelay (uint32_t millisec); + +#if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available + +/// Wait for Signal, Message, Mail, or Timeout. +/// \param[in] millisec timeout value or 0 in case of no time-out +/// \return event that contains signal, message, or mail information or error code. +/// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS. +osEvent osWait (uint32_t millisec); + +#endif // Generic Wait available + + +// ==== Timer Management Functions ==== +/// Define a Timer object. +/// \param name name of the timer object. +/// \param function name of the timer call back function. +/// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#if defined (osObjectsExternal) // object is external +#define osTimerDef(name, function) \ +extern const osTimerDef_t os_timer_def_##name +#else // define the object + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) +#define osTimerDef(name, function) \ +const osTimerDef_t os_timer_def_##name = \ +{ (function), NULL } + +#define osTimerStaticDef(name, function, control) \ +const osTimerDef_t os_timer_def_##name = \ +{ (function), (control) } +#else //configSUPPORT_STATIC_ALLOCATION == 0 +#define osTimerDef(name, function) \ +const osTimerDef_t os_timer_def_##name = \ +{ (function) } +#endif +#endif + +/// Access a Timer definition. +/// \param name name of the timer object. +/// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#define osTimer(name) \ +&os_timer_def_##name + +/// Create a timer. +/// \param[in] timer_def timer object referenced with \ref osTimer. +/// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. +/// \param[in] argument argument to the timer call back function. +/// \return timer ID for reference by other functions or NULL in case of error. +/// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS. +osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument); + +/// Start or restart a timer. +/// \param[in] timer_id timer ID obtained by \ref osTimerCreate. +/// \param[in] millisec time delay value of the timer. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS. +osStatus osTimerStart (osTimerId timer_id, uint32_t millisec); + +/// Stop the timer. +/// \param[in] timer_id timer ID obtained by \ref osTimerCreate. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS. +osStatus osTimerStop (osTimerId timer_id); + +/// Delete a timer that was created by \ref osTimerCreate. +/// \param[in] timer_id timer ID obtained by \ref osTimerCreate. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS. +osStatus osTimerDelete (osTimerId timer_id); + + +// ==== Signal Management ==== + +/// Set the specified Signal Flags of an active thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +/// \param[in] signals specifies the signal flags of the thread that should be set. +/// \return osOK if successful, osErrorOS if failed. +/// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS. +int32_t osSignalSet (osThreadId thread_id, int32_t signals); + +/// Clear the specified Signal Flags of an active thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +/// \param[in] signals specifies the signal flags of the thread that shall be cleared. +/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. +/// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS. +int32_t osSignalClear (osThreadId thread_id, int32_t signals); + +/// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread. +/// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag. +/// \param[in] millisec timeout value or 0 in case of no time-out. +/// \return event flag information or error code. +/// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS. +osEvent osSignalWait (int32_t signals, uint32_t millisec); + + +// ==== Mutex Management ==== + +/// Define a Mutex. +/// \param name name of the mutex object. +/// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#if defined (osObjectsExternal) // object is external +#define osMutexDef(name) \ +extern const osMutexDef_t os_mutex_def_##name +#else // define the object + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) +#define osMutexDef(name) \ +const osMutexDef_t os_mutex_def_##name = { 0, NULL } + +#define osMutexStaticDef(name, control) \ +const osMutexDef_t os_mutex_def_##name = { 0, (control) } +#else //configSUPPORT_STATIC_ALLOCATION == 0 +#define osMutexDef(name) \ +const osMutexDef_t os_mutex_def_##name = { 0 } + +#endif + +#endif + +/// Access a Mutex definition. +/// \param name name of the mutex object. +/// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#define osMutex(name) \ +&os_mutex_def_##name + +/// Create and Initialize a Mutex object. +/// \param[in] mutex_def mutex definition referenced with \ref osMutex. +/// \return mutex ID for reference by other functions or NULL in case of error. +/// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS. +osMutexId osMutexCreate (const osMutexDef_t *mutex_def); + +/// Wait until a Mutex becomes available. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. +/// \param[in] millisec timeout value or 0 in case of no time-out. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS. +osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec); + +/// Release a Mutex that was obtained by \ref osMutexWait. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS. +osStatus osMutexRelease (osMutexId mutex_id); + +/// Delete a Mutex that was created by \ref osMutexCreate. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS. +osStatus osMutexDelete (osMutexId mutex_id); + + +// ==== Semaphore Management Functions ==== + +#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available + +/// Define a Semaphore object. +/// \param name name of the semaphore object. +/// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#if defined (osObjectsExternal) // object is external +#define osSemaphoreDef(name) \ +extern const osSemaphoreDef_t os_semaphore_def_##name +#else // define the object + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) +#define osSemaphoreDef(name) \ +const osSemaphoreDef_t os_semaphore_def_##name = { 0, NULL } + +#define osSemaphoreStaticDef(name, control) \ +const osSemaphoreDef_t os_semaphore_def_##name = { 0, (control) } + +#else //configSUPPORT_STATIC_ALLOCATION == 0 +#define osSemaphoreDef(name) \ +const osSemaphoreDef_t os_semaphore_def_##name = { 0 } +#endif +#endif + +/// Access a Semaphore definition. +/// \param name name of the semaphore object. +/// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#define osSemaphore(name) \ +&os_semaphore_def_##name + +/// Create and Initialize a Semaphore object used for managing resources. +/// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore. +/// \param[in] count number of available resources. +/// \return semaphore ID for reference by other functions or NULL in case of error. +/// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS. +osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count); + +/// Wait until a Semaphore token becomes available. +/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. +/// \param[in] millisec timeout value or 0 in case of no time-out. +/// \return number of available tokens, or -1 in case of incorrect parameters. +/// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS. +int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec); + +/// Release a Semaphore token. +/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS. +osStatus osSemaphoreRelease (osSemaphoreId semaphore_id); + +/// Delete a Semaphore that was created by \ref osSemaphoreCreate. +/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS. +osStatus osSemaphoreDelete (osSemaphoreId semaphore_id); + +#endif // Semaphore available + + +// ==== Memory Pool Management Functions ==== + +#if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available + +/// \brief Define a Memory Pool. +/// \param name name of the memory pool. +/// \param no maximum number of blocks (objects) in the memory pool. +/// \param type data type of a single block (object). +/// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#if defined (osObjectsExternal) // object is external +#define osPoolDef(name, no, type) \ +extern const osPoolDef_t os_pool_def_##name +#else // define the object +#define osPoolDef(name, no, type) \ +const osPoolDef_t os_pool_def_##name = \ +{ (no), sizeof(type), NULL } +#endif + +/// \brief Access a Memory Pool definition. +/// \param name name of the memory pool +/// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#define osPool(name) \ +&os_pool_def_##name + +/// Create and Initialize a memory pool. +/// \param[in] pool_def memory pool definition referenced with \ref osPool. +/// \return memory pool ID for reference by other functions or NULL in case of error. +/// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS. +osPoolId osPoolCreate (const osPoolDef_t *pool_def); + +/// Allocate a memory block from a memory pool. +/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. +/// \return address of the allocated memory block or NULL in case of no memory available. +/// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS. +void *osPoolAlloc (osPoolId pool_id); + +/// Allocate a memory block from a memory pool and set memory block to zero. +/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. +/// \return address of the allocated memory block or NULL in case of no memory available. +/// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS. +void *osPoolCAlloc (osPoolId pool_id); + +/// Return an allocated memory block back to a specific memory pool. +/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. +/// \param[in] block address of the allocated memory block that is returned to the memory pool. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS. +osStatus osPoolFree (osPoolId pool_id, void *block); + +#endif // Memory Pool Management available + + +// ==== Message Queue Management Functions ==== + +#if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available + +/// \brief Create a Message Queue Definition. +/// \param name name of the queue. +/// \param queue_sz maximum number of messages in the queue. +/// \param type data type of a single message element (for debugger). +/// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#if defined (osObjectsExternal) // object is external +#define osMessageQDef(name, queue_sz, type) \ +extern const osMessageQDef_t os_messageQ_def_##name +#else // define the object +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) +#define osMessageQDef(name, queue_sz, type) \ +const osMessageQDef_t os_messageQ_def_##name = \ +{ (queue_sz), sizeof (type), NULL, NULL } + +#define osMessageQStaticDef(name, queue_sz, type, buffer, control) \ +const osMessageQDef_t os_messageQ_def_##name = \ +{ (queue_sz), sizeof (type) , (buffer), (control)} +#else //configSUPPORT_STATIC_ALLOCATION == 1 +#define osMessageQDef(name, queue_sz, type) \ +const osMessageQDef_t os_messageQ_def_##name = \ +{ (queue_sz), sizeof (type) } + +#endif +#endif + +/// \brief Access a Message Queue Definition. +/// \param name name of the queue +/// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#define osMessageQ(name) \ +&os_messageQ_def_##name + +/// Create and Initialize a Message Queue. +/// \param[in] queue_def queue definition referenced with \ref osMessageQ. +/// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. +/// \return message queue ID for reference by other functions or NULL in case of error. +/// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS. +osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id); + +/// Put a Message to a Queue. +/// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. +/// \param[in] info message information. +/// \param[in] millisec timeout value or 0 in case of no time-out. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS. +osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec); + +/// Get a Message or Wait for a Message from a Queue. +/// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. +/// \param[in] millisec timeout value or 0 in case of no time-out. +/// \return event information that includes status code. +/// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS. +osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec); + +#endif // Message Queues available + + +// ==== Mail Queue Management Functions ==== + +#if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available + +/// \brief Create a Mail Queue Definition. +/// \param name name of the queue +/// \param queue_sz maximum number of messages in queue +/// \param type data type of a single message element +/// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#if defined (osObjectsExternal) // object is external +#define osMailQDef(name, queue_sz, type) \ +extern struct os_mailQ_cb *os_mailQ_cb_##name \ +extern osMailQDef_t os_mailQ_def_##name +#else // define the object +#define osMailQDef(name, queue_sz, type) \ +struct os_mailQ_cb *os_mailQ_cb_##name; \ +const osMailQDef_t os_mailQ_def_##name = \ +{ (queue_sz), sizeof (type), (&os_mailQ_cb_##name) } +#endif + +/// \brief Access a Mail Queue Definition. +/// \param name name of the queue +/// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the +/// macro body is implementation specific in every CMSIS-RTOS. +#define osMailQ(name) \ +&os_mailQ_def_##name + +/// Create and Initialize mail queue. +/// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ +/// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. +/// \return mail queue ID for reference by other functions or NULL in case of error. +/// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS. +osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id); + +/// Allocate a memory block from a mail. +/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. +/// \param[in] millisec timeout value or 0 in case of no time-out +/// \return pointer to memory block that can be filled with mail or NULL in case of error. +/// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS. +void *osMailAlloc (osMailQId queue_id, uint32_t millisec); + +/// Allocate a memory block from a mail and set memory block to zero. +/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. +/// \param[in] millisec timeout value or 0 in case of no time-out +/// \return pointer to memory block that can be filled with mail or NULL in case of error. +/// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS. +void *osMailCAlloc (osMailQId queue_id, uint32_t millisec); + +/// Put a mail to a queue. +/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. +/// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS. +osStatus osMailPut (osMailQId queue_id, void *mail); + +/// Get a mail from a queue. +/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. +/// \param[in] millisec timeout value or 0 in case of no time-out +/// \return event that contains mail information or error code. +/// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS. +osEvent osMailGet (osMailQId queue_id, uint32_t millisec); + +/// Free a memory block from a mail. +/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. +/// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet. +/// \return status code that indicates the execution status of the function. +/// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS. +osStatus osMailFree (osMailQId queue_id, void *mail); + +#endif // Mail Queues available + +/*************************** Additional specific APIs to Free RTOS ************/ +/** +* @brief Handles the tick increment +* @param none. +* @retval none. +*/ +void osSystickHandler(void); + +#if ( INCLUDE_eTaskGetState == 1 ) +/** +* @brief Obtain the state of any thread. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @retval the stae of the thread, states are encoded by the osThreadState enumerated type. +*/ +osThreadState osThreadGetState(osThreadId thread_id); +#endif /* INCLUDE_eTaskGetState */ + +#if ( INCLUDE_eTaskGetState == 1 ) +/** +* @brief Check if a thread is already suspended or not. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @retval status code that indicates the execution status of the function. +*/ + +osStatus osThreadIsSuspended(osThreadId thread_id); + +#endif /* INCLUDE_eTaskGetState */ + +/** +* @brief Suspend execution of a thread. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadSuspend (osThreadId thread_id); + +/** +* @brief Resume execution of a suspended thread. +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadResume (osThreadId thread_id); + +/** +* @brief Suspend execution of a all active threads. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadSuspendAll (void); + +/** +* @brief Resume execution of a all suspended threads. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadResumeAll (void); + +/** +* @brief Delay a task until a specified time +* @param PreviousWakeTime Pointer to a variable that holds the time at which the +* task was last unblocked. PreviousWakeTime must be initialised with the current time +* prior to its first use (PreviousWakeTime = osKernelSysTick() ) +* @param millisec time delay value +* @retval status code that indicates the execution status of the function. +*/ +osStatus osDelayUntil (uint32_t *PreviousWakeTime, uint32_t millisec); + +/** +* @brief Abort the delay for a specific thread +* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId +* @retval status code that indicates the execution status of the function. +*/ +osStatus osAbortDelay(osThreadId thread_id); + +/** +* @brief Lists all the current threads, along with their current state +* and stack usage high water mark. +* @param buffer A buffer into which the above mentioned details +* will be written +* @retval status code that indicates the execution status of the function. +*/ +osStatus osThreadList (uint8_t *buffer); + +/** +* @brief Receive an item from a queue without removing the item from the queue. +* @param queue_id message queue ID obtained with \ref osMessageCreate. +* @param millisec timeout value or 0 in case of no time-out. +* @retval event information that includes status code. +*/ +osEvent osMessagePeek (osMessageQId queue_id, uint32_t millisec); + +/** +* @brief Get the number of messaged stored in a queue. +* @param queue_id message queue ID obtained with \ref osMessageCreate. +* @retval number of messages stored in a queue. +*/ +uint32_t osMessageWaiting(osMessageQId queue_id); + +/** +* @brief Get the available space in a message queue. +* @param queue_id message queue ID obtained with \ref osMessageCreate. +* @retval available space in a message queue. +*/ +uint32_t osMessageAvailableSpace(osMessageQId queue_id); + +/** +* @brief Delete a Message Queue +* @param queue_id message queue ID obtained with \ref osMessageCreate. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osMessageDelete (osMessageQId queue_id); + +/** +* @brief Create and Initialize a Recursive Mutex +* @param mutex_def mutex definition referenced with \ref osMutex. +* @retval mutex ID for reference by other functions or NULL in case of error.. +*/ +osMutexId osRecursiveMutexCreate (const osMutexDef_t *mutex_def); + +/** +* @brief Release a Recursive Mutex +* @param mutex_id mutex ID obtained by \ref osRecursiveMutexCreate. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osRecursiveMutexRelease (osMutexId mutex_id); + +/** +* @brief Release a Recursive Mutex +* @param mutex_id mutex ID obtained by \ref osRecursiveMutexCreate. +* @param millisec timeout value or 0 in case of no time-out. +* @retval status code that indicates the execution status of the function. +*/ +osStatus osRecursiveMutexWait (osMutexId mutex_id, uint32_t millisec); + +/** +* @brief Returns the current count value of a counting semaphore +* @param semaphore_id semaphore_id ID obtained by \ref osSemaphoreCreate. +* @retval count value +*/ +uint32_t osSemaphoreGetCount(osSemaphoreId semaphore_id); + +#ifdef __cplusplus +} +#endif + +#endif // _CMSIS_OS_H diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/croutine.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/croutine.c new file mode 100644 index 0000000..b715884 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/croutine.c @@ -0,0 +1,353 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#include "FreeRTOS.h" +#include "task.h" +#include "croutine.h" + +/* Remove the whole file is co-routines are not being used. */ +#if( configUSE_CO_ROUTINES != 0 ) + +/* + * Some kernel aware debuggers require data to be viewed to be global, rather + * than file scope. + */ +#ifdef portREMOVE_STATIC_QUALIFIER + #define static +#endif + + +/* Lists for ready and blocked co-routines. --------------------*/ +static List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */ +static List_t xDelayedCoRoutineList1; /*< Delayed co-routines. */ +static List_t xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */ +static List_t * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */ +static List_t * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */ +static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */ + +/* Other file private variables. --------------------------------*/ +CRCB_t * pxCurrentCoRoutine = NULL; +static UBaseType_t uxTopCoRoutineReadyPriority = 0; +static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0; + +/* The initial state of the co-routine when it is created. */ +#define corINITIAL_STATE ( 0 ) + +/* + * Place the co-routine represented by pxCRCB into the appropriate ready queue + * for the priority. It is inserted at the end of the list. + * + * This macro accesses the co-routine ready lists and therefore must not be + * used from within an ISR. + */ +#define prvAddCoRoutineToReadyQueue( pxCRCB ) \ +{ \ + if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority ) \ + { \ + uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \ + } \ + vListInsertEnd( ( List_t * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \ +} + +/* + * Utility to ready all the lists used by the scheduler. This is called + * automatically upon the creation of the first co-routine. + */ +static void prvInitialiseCoRoutineLists( void ); + +/* + * Co-routines that are readied by an interrupt cannot be placed directly into + * the ready lists (there is no mutual exclusion). Instead they are placed in + * in the pending ready list in order that they can later be moved to the ready + * list by the co-routine scheduler. + */ +static void prvCheckPendingReadyList( void ); + +/* + * Macro that looks at the list of co-routines that are currently delayed to + * see if any require waking. + * + * Co-routines are stored in the queue in the order of their wake time - + * meaning once one co-routine has been found whose timer has not expired + * we need not look any further down the list. + */ +static void prvCheckDelayedList( void ); + +/*-----------------------------------------------------------*/ + +BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex ) +{ +BaseType_t xReturn; +CRCB_t *pxCoRoutine; + + /* Allocate the memory that will store the co-routine control block. */ + pxCoRoutine = ( CRCB_t * ) pvPortMalloc( sizeof( CRCB_t ) ); + if( pxCoRoutine ) + { + /* If pxCurrentCoRoutine is NULL then this is the first co-routine to + be created and the co-routine data structures need initialising. */ + if( pxCurrentCoRoutine == NULL ) + { + pxCurrentCoRoutine = pxCoRoutine; + prvInitialiseCoRoutineLists(); + } + + /* Check the priority is within limits. */ + if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES ) + { + uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1; + } + + /* Fill out the co-routine control block from the function parameters. */ + pxCoRoutine->uxState = corINITIAL_STATE; + pxCoRoutine->uxPriority = uxPriority; + pxCoRoutine->uxIndex = uxIndex; + pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode; + + /* Initialise all the other co-routine control block parameters. */ + vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) ); + vListInitialiseItem( &( pxCoRoutine->xEventListItem ) ); + + /* Set the co-routine control block as a link back from the ListItem_t. + This is so we can get back to the containing CRCB from a generic item + in a list. */ + listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine ); + listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine ); + + /* Event lists are always in priority order. */ + listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), ( ( TickType_t ) configMAX_CO_ROUTINE_PRIORITIES - ( TickType_t ) uxPriority ) ); + + /* Now the co-routine has been initialised it can be added to the ready + list at the correct priority. */ + prvAddCoRoutineToReadyQueue( pxCoRoutine ); + + xReturn = pdPASS; + } + else + { + xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList ) +{ +TickType_t xTimeToWake; + + /* Calculate the time to wake - this may overflow but this is + not a problem. */ + xTimeToWake = xCoRoutineTickCount + xTicksToDelay; + + /* We must remove ourselves from the ready list before adding + ourselves to the blocked list as the same list item is used for + both lists. */ + ( void ) uxListRemove( ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); + + /* The list item will be inserted in wake time order. */ + listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake ); + + if( xTimeToWake < xCoRoutineTickCount ) + { + /* Wake time has overflowed. Place this item in the + overflow list. */ + vListInsert( ( List_t * ) pxOverflowDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); + } + else + { + /* The wake time has not overflowed, so we can use the + current block list. */ + vListInsert( ( List_t * ) pxDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); + } + + if( pxEventList ) + { + /* Also add the co-routine to an event list. If this is done then the + function must be called with interrupts disabled. */ + vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) ); + } +} +/*-----------------------------------------------------------*/ + +static void prvCheckPendingReadyList( void ) +{ + /* Are there any co-routines waiting to get moved to the ready list? These + are co-routines that have been readied by an ISR. The ISR cannot access + the ready lists itself. */ + while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE ) + { + CRCB_t *pxUnblockedCRCB; + + /* The pending ready list can be accessed by an ISR. */ + portDISABLE_INTERRUPTS(); + { + pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) ); + ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); + } + portENABLE_INTERRUPTS(); + + ( void ) uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); + prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); + } +} +/*-----------------------------------------------------------*/ + +static void prvCheckDelayedList( void ) +{ +CRCB_t *pxCRCB; + + xPassedTicks = xTaskGetTickCount() - xLastTickCount; + while( xPassedTicks ) + { + xCoRoutineTickCount++; + xPassedTicks--; + + /* If the tick count has overflowed we need to swap the ready lists. */ + if( xCoRoutineTickCount == 0 ) + { + List_t * pxTemp; + + /* Tick count has overflowed so we need to swap the delay lists. If there are + any items in pxDelayedCoRoutineList here then there is an error! */ + pxTemp = pxDelayedCoRoutineList; + pxDelayedCoRoutineList = pxOverflowDelayedCoRoutineList; + pxOverflowDelayedCoRoutineList = pxTemp; + } + + /* See if this tick has made a timeout expire. */ + while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE ) + { + pxCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList ); + + if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) ) + { + /* Timeout not yet expired. */ + break; + } + + portDISABLE_INTERRUPTS(); + { + /* The event could have occurred just before this critical + section. If this is the case then the generic list item will + have been moved to the pending ready list and the following + line is still valid. Also the pvContainer parameter will have + been set to NULL so the following lines are also valid. */ + ( void ) uxListRemove( &( pxCRCB->xGenericListItem ) ); + + /* Is the co-routine waiting on an event also? */ + if( pxCRCB->xEventListItem.pvContainer ) + { + ( void ) uxListRemove( &( pxCRCB->xEventListItem ) ); + } + } + portENABLE_INTERRUPTS(); + + prvAddCoRoutineToReadyQueue( pxCRCB ); + } + } + + xLastTickCount = xCoRoutineTickCount; +} +/*-----------------------------------------------------------*/ + +void vCoRoutineSchedule( void ) +{ + /* See if any co-routines readied by events need moving to the ready lists. */ + prvCheckPendingReadyList(); + + /* See if any delayed co-routines have timed out. */ + prvCheckDelayedList(); + + /* Find the highest priority queue that contains ready co-routines. */ + while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) ) + { + if( uxTopCoRoutineReadyPriority == 0 ) + { + /* No more co-routines to check. */ + return; + } + --uxTopCoRoutineReadyPriority; + } + + /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines + of the same priority get an equal share of the processor time. */ + listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ); + + /* Call the co-routine. */ + ( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex ); + + return; +} +/*-----------------------------------------------------------*/ + +static void prvInitialiseCoRoutineLists( void ) +{ +UBaseType_t uxPriority; + + for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ ) + { + vListInitialise( ( List_t * ) &( pxReadyCoRoutineLists[ uxPriority ] ) ); + } + + vListInitialise( ( List_t * ) &xDelayedCoRoutineList1 ); + vListInitialise( ( List_t * ) &xDelayedCoRoutineList2 ); + vListInitialise( ( List_t * ) &xPendingReadyCoRoutineList ); + + /* Start with pxDelayedCoRoutineList using list1 and the + pxOverflowDelayedCoRoutineList using list2. */ + pxDelayedCoRoutineList = &xDelayedCoRoutineList1; + pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2; +} +/*-----------------------------------------------------------*/ + +BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList ) +{ +CRCB_t *pxUnblockedCRCB; +BaseType_t xReturn; + + /* This function is called from within an interrupt. It can only access + event lists and the pending ready list. This function assumes that a + check has already been made to ensure pxEventList is not empty. */ + pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); + ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); + vListInsertEnd( ( List_t * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) ); + + if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} + +#endif /* configUSE_CO_ROUTINES == 0 */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/event_groups.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/event_groups.c new file mode 100644 index 0000000..14d7b02 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/event_groups.c @@ -0,0 +1,738 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* Standard includes. */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "timers.h" +#include "event_groups.h" + +/* Lint e961 and e750 are suppressed as a MISRA exception justified because the +MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the +header files above, but not in this file, in order to generate the correct +privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */ + +/* The following bit fields convey control information in a task's event list +item value. It is important they don't clash with the +taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */ +#if configUSE_16_BIT_TICKS == 1 + #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x0100U + #define eventUNBLOCKED_DUE_TO_BIT_SET 0x0200U + #define eventWAIT_FOR_ALL_BITS 0x0400U + #define eventEVENT_BITS_CONTROL_BYTES 0xff00U +#else + #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL + #define eventUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL + #define eventWAIT_FOR_ALL_BITS 0x04000000UL + #define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL +#endif + +typedef struct xEventGroupDefinition +{ + EventBits_t uxEventBits; + List_t xTasksWaitingForBits; /*< List of tasks waiting for a bit to be set. */ + + #if( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxEventGroupNumber; + #endif + + #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the event group is statically allocated to ensure no attempt is made to free the memory. */ + #endif +} EventGroup_t; + +/*-----------------------------------------------------------*/ + +/* + * Test the bits set in uxCurrentEventBits to see if the wait condition is met. + * The wait condition is defined by xWaitForAllBits. If xWaitForAllBits is + * pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor + * are also set in uxCurrentEventBits. If xWaitForAllBits is pdFALSE then the + * wait condition is met if any of the bits set in uxBitsToWait for are also set + * in uxCurrentEventBits. + */ +static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits ) PRIVILEGED_FUNCTION; + +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + + EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer ) + { + EventGroup_t *pxEventBits; + + /* A StaticEventGroup_t object must be provided. */ + configASSERT( pxEventGroupBuffer ); + + #if( configASSERT_DEFINED == 1 ) + { + /* Sanity check that the size of the structure used to declare a + variable of type StaticEventGroup_t equals the size of the real + event group structure. */ + volatile size_t xSize = sizeof( StaticEventGroup_t ); + configASSERT( xSize == sizeof( EventGroup_t ) ); + } + #endif /* configASSERT_DEFINED */ + + /* The user has provided a statically allocated event group - use it. */ + pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer; /*lint !e740 EventGroup_t and StaticEventGroup_t are guaranteed to have the same size and alignment requirement - checked by configASSERT(). */ + + if( pxEventBits != NULL ) + { + pxEventBits->uxEventBits = 0; + vListInitialise( &( pxEventBits->xTasksWaitingForBits ) ); + + #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + { + /* Both static and dynamic allocation can be used, so note that + this event group was created statically in case the event group + is later deleted. */ + pxEventBits->ucStaticallyAllocated = pdTRUE; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + + traceEVENT_GROUP_CREATE( pxEventBits ); + } + else + { + traceEVENT_GROUP_CREATE_FAILED(); + } + + return ( EventGroupHandle_t ) pxEventBits; + } + +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + EventGroupHandle_t xEventGroupCreate( void ) + { + EventGroup_t *pxEventBits; + + /* Allocate the event group. */ + pxEventBits = ( EventGroup_t * ) pvPortMalloc( sizeof( EventGroup_t ) ); + + if( pxEventBits != NULL ) + { + pxEventBits->uxEventBits = 0; + vListInitialise( &( pxEventBits->xTasksWaitingForBits ) ); + + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + /* Both static and dynamic allocation can be used, so note this + event group was allocated statically in case the event group is + later deleted. */ + pxEventBits->ucStaticallyAllocated = pdFALSE; + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ + + traceEVENT_GROUP_CREATE( pxEventBits ); + } + else + { + traceEVENT_GROUP_CREATE_FAILED(); + } + + return ( EventGroupHandle_t ) pxEventBits; + } + +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ) +{ +EventBits_t uxOriginalBitValue, uxReturn; +EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; +BaseType_t xAlreadyYielded; +BaseType_t xTimeoutOccurred = pdFALSE; + + configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); + configASSERT( uxBitsToWaitFor != 0 ); + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + vTaskSuspendAll(); + { + uxOriginalBitValue = pxEventBits->uxEventBits; + + ( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet ); + + if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor ) + { + /* All the rendezvous bits are now set - no need to block. */ + uxReturn = ( uxOriginalBitValue | uxBitsToSet ); + + /* Rendezvous always clear the bits. They will have been cleared + already unless this is the only task in the rendezvous. */ + pxEventBits->uxEventBits &= ~uxBitsToWaitFor; + + xTicksToWait = 0; + } + else + { + if( xTicksToWait != ( TickType_t ) 0 ) + { + traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor ); + + /* Store the bits that the calling task is waiting for in the + task's event list item so the kernel knows when a match is + found. Then enter the blocked state. */ + vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait ); + + /* This assignment is obsolete as uxReturn will get set after + the task unblocks, but some compilers mistakenly generate a + warning about uxReturn being returned without being set if the + assignment is omitted. */ + uxReturn = 0; + } + else + { + /* The rendezvous bits were not set, but no block time was + specified - just return the current event bit value. */ + uxReturn = pxEventBits->uxEventBits; + xTimeoutOccurred = pdTRUE; + } + } + } + xAlreadyYielded = xTaskResumeAll(); + + if( xTicksToWait != ( TickType_t ) 0 ) + { + if( xAlreadyYielded == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* The task blocked to wait for its required bits to be set - at this + point either the required bits were set or the block time expired. If + the required bits were set they will have been stored in the task's + event list item, and they should now be retrieved then cleared. */ + uxReturn = uxTaskResetEventItemValue(); + + if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 ) + { + /* The task timed out, just return the current event bit value. */ + taskENTER_CRITICAL(); + { + uxReturn = pxEventBits->uxEventBits; + + /* Although the task got here because it timed out before the + bits it was waiting for were set, it is possible that since it + unblocked another task has set the bits. If this is the case + then it needs to clear the bits before exiting. */ + if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor ) + { + pxEventBits->uxEventBits &= ~uxBitsToWaitFor; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + xTimeoutOccurred = pdTRUE; + } + else + { + /* The task unblocked because the bits were set. */ + } + + /* Control bits might be set as the task had blocked should not be + returned. */ + uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES; + } + + traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred ); + + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xTimeoutOccurred; + + return uxReturn; +} +/*-----------------------------------------------------------*/ + +EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ) +{ +EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; +EventBits_t uxReturn, uxControlBits = 0; +BaseType_t xWaitConditionMet, xAlreadyYielded; +BaseType_t xTimeoutOccurred = pdFALSE; + + /* Check the user is not attempting to wait on the bits used by the kernel + itself, and that at least one bit is being requested. */ + configASSERT( xEventGroup ); + configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); + configASSERT( uxBitsToWaitFor != 0 ); + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + vTaskSuspendAll(); + { + const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits; + + /* Check to see if the wait condition is already met or not. */ + xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits ); + + if( xWaitConditionMet != pdFALSE ) + { + /* The wait condition has already been met so there is no need to + block. */ + uxReturn = uxCurrentEventBits; + xTicksToWait = ( TickType_t ) 0; + + /* Clear the wait bits if requested to do so. */ + if( xClearOnExit != pdFALSE ) + { + pxEventBits->uxEventBits &= ~uxBitsToWaitFor; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else if( xTicksToWait == ( TickType_t ) 0 ) + { + /* The wait condition has not been met, but no block time was + specified, so just return the current value. */ + uxReturn = uxCurrentEventBits; + xTimeoutOccurred = pdTRUE; + } + else + { + /* The task is going to block to wait for its required bits to be + set. uxControlBits are used to remember the specified behaviour of + this call to xEventGroupWaitBits() - for use when the event bits + unblock the task. */ + if( xClearOnExit != pdFALSE ) + { + uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( xWaitForAllBits != pdFALSE ) + { + uxControlBits |= eventWAIT_FOR_ALL_BITS; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Store the bits that the calling task is waiting for in the + task's event list item so the kernel knows when a match is + found. Then enter the blocked state. */ + vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait ); + + /* This is obsolete as it will get set after the task unblocks, but + some compilers mistakenly generate a warning about the variable + being returned without being set if it is not done. */ + uxReturn = 0; + + traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor ); + } + } + xAlreadyYielded = xTaskResumeAll(); + + if( xTicksToWait != ( TickType_t ) 0 ) + { + if( xAlreadyYielded == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* The task blocked to wait for its required bits to be set - at this + point either the required bits were set or the block time expired. If + the required bits were set they will have been stored in the task's + event list item, and they should now be retrieved then cleared. */ + uxReturn = uxTaskResetEventItemValue(); + + if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 ) + { + taskENTER_CRITICAL(); + { + /* The task timed out, just return the current event bit value. */ + uxReturn = pxEventBits->uxEventBits; + + /* It is possible that the event bits were updated between this + task leaving the Blocked state and running again. */ + if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE ) + { + if( xClearOnExit != pdFALSE ) + { + pxEventBits->uxEventBits &= ~uxBitsToWaitFor; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + xTimeoutOccurred = pdTRUE; + } + taskEXIT_CRITICAL(); + } + else + { + /* The task unblocked because the bits were set. */ + } + + /* The task blocked so control bits may have been set. */ + uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES; + } + traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred ); + + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xTimeoutOccurred; + + return uxReturn; +} +/*-----------------------------------------------------------*/ + +EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) +{ +EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; +EventBits_t uxReturn; + + /* Check the user is not attempting to clear the bits used by the kernel + itself. */ + configASSERT( xEventGroup ); + configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); + + taskENTER_CRITICAL(); + { + traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear ); + + /* The value returned is the event group value prior to the bits being + cleared. */ + uxReturn = pxEventBits->uxEventBits; + + /* Clear the bits. */ + pxEventBits->uxEventBits &= ~uxBitsToClear; + } + taskEXIT_CRITICAL(); + + return uxReturn; +} +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) + + BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) + { + BaseType_t xReturn; + + traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear ); + xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ); + + return xReturn; + } + +#endif +/*-----------------------------------------------------------*/ + +EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) +{ +UBaseType_t uxSavedInterruptStatus; +EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; +EventBits_t uxReturn; + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + uxReturn = pxEventBits->uxEventBits; + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return uxReturn; +} +/*-----------------------------------------------------------*/ + +EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) +{ +ListItem_t *pxListItem, *pxNext; +ListItem_t const *pxListEnd; +List_t *pxList; +EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits; +EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; +BaseType_t xMatchFound = pdFALSE; + + /* Check the user is not attempting to set the bits used by the kernel + itself. */ + configASSERT( xEventGroup ); + configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); + + pxList = &( pxEventBits->xTasksWaitingForBits ); + pxListEnd = listGET_END_MARKER( pxList ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ + vTaskSuspendAll(); + { + traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet ); + + pxListItem = listGET_HEAD_ENTRY( pxList ); + + /* Set the bits. */ + pxEventBits->uxEventBits |= uxBitsToSet; + + /* See if the new bit value should unblock any tasks. */ + while( pxListItem != pxListEnd ) + { + pxNext = listGET_NEXT( pxListItem ); + uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem ); + xMatchFound = pdFALSE; + + /* Split the bits waited for from the control bits. */ + uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES; + uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES; + + if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 ) + { + /* Just looking for single bit being set. */ + if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 ) + { + xMatchFound = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor ) + { + /* All bits are set. */ + xMatchFound = pdTRUE; + } + else + { + /* Need all bits to be set, but not all the bits were set. */ + } + + if( xMatchFound != pdFALSE ) + { + /* The bits match. Should the bits be cleared on exit? */ + if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 ) + { + uxBitsToClear |= uxBitsWaitedFor; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Store the actual event flag value in the task's event list + item before removing the task from the event list. The + eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows + that is was unblocked due to its required bits matching, rather + than because it timed out. */ + vTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET ); + } + + /* Move onto the next list item. Note pxListItem->pxNext is not + used here as the list item may have been removed from the event list + and inserted into the ready/pending reading list. */ + pxListItem = pxNext; + } + + /* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT + bit was set in the control word. */ + pxEventBits->uxEventBits &= ~uxBitsToClear; + } + ( void ) xTaskResumeAll(); + + return pxEventBits->uxEventBits; +} +/*-----------------------------------------------------------*/ + +void vEventGroupDelete( EventGroupHandle_t xEventGroup ) +{ +EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; +const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits ); + + vTaskSuspendAll(); + { + traceEVENT_GROUP_DELETE( xEventGroup ); + + while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 ) + { + /* Unblock the task, returning 0 as the event list is being deleted + and cannot therefore have any bits set. */ + configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( const ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) ); + vTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET ); + } + + #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) ) + { + /* The event group can only have been allocated dynamically - free + it again. */ + vPortFree( pxEventBits ); + } + #elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + { + /* The event group could have been allocated statically or + dynamically, so check before attempting to free the memory. */ + if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdFALSE ) + { + vPortFree( pxEventBits ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + } + ( void ) xTaskResumeAll(); +} +/*-----------------------------------------------------------*/ + +/* For internal use only - execute a 'set bits' command that was pended from +an interrupt. */ +void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet ) +{ + ( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet ); +} +/*-----------------------------------------------------------*/ + +/* For internal use only - execute a 'clear bits' command that was pended from +an interrupt. */ +void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear ) +{ + ( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear ); +} +/*-----------------------------------------------------------*/ + +static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits ) +{ +BaseType_t xWaitConditionMet = pdFALSE; + + if( xWaitForAllBits == pdFALSE ) + { + /* Task only has to wait for one bit within uxBitsToWaitFor to be + set. Is one already set? */ + if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 ) + { + xWaitConditionMet = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* Task has to wait for all the bits in uxBitsToWaitFor to be set. + Are they set already? */ + if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor ) + { + xWaitConditionMet = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + return xWaitConditionMet; +} +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) + + BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken ) + { + BaseType_t xReturn; + + traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet ); + xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ); + + return xReturn; + } + +#endif +/*-----------------------------------------------------------*/ + +#if (configUSE_TRACE_FACILITY == 1) + + UBaseType_t uxEventGroupGetNumber( void* xEventGroup ) + { + UBaseType_t xReturn; + EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; + + if( xEventGroup == NULL ) + { + xReturn = 0; + } + else + { + xReturn = pxEventBits->uxEventGroupNumber; + } + + return xReturn; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + void vEventGroupSetNumber( void * xEventGroup, UBaseType_t uxEventGroupNumber ) + { + ( ( EventGroup_t * ) xEventGroup )->uxEventGroupNumber = uxEventGroupNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h new file mode 100644 index 0000000..3e3ed27 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h @@ -0,0 +1,1168 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef INC_FREERTOS_H +#define INC_FREERTOS_H + +/* + * Include the generic headers required for the FreeRTOS port being used. + */ +#include + +/* + * If stdint.h cannot be located then: + * + If using GCC ensure the -nostdint options is *not* being used. + * + Ensure the project's include path includes the directory in which your + * compiler stores stdint.h. + * + Set any compiler options necessary for it to support C99, as technically + * stdint.h is only mandatory with C99 (FreeRTOS does not require C99 in any + * other way). + * + The FreeRTOS download includes a simple stdint.h definition that can be + * used in cases where none is provided by the compiler. The files only + * contains the typedefs required to build FreeRTOS. Read the instructions + * in FreeRTOS/source/stdint.readme for more information. + */ +#include /* READ COMMENT ABOVE. */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Application specific configuration options. */ +#include "FreeRTOSConfig.h" + +/* Basic FreeRTOS definitions. */ +#include "projdefs.h" + +/* Definitions specific to the port being used. */ +#include "portable.h" + +/* Must be defaulted before configUSE_NEWLIB_REENTRANT is used below. */ +#ifndef configUSE_NEWLIB_REENTRANT + #define configUSE_NEWLIB_REENTRANT 0 +#endif + +/* Required if struct _reent is used. */ +#if ( configUSE_NEWLIB_REENTRANT == 1 ) + #include +#endif +/* + * Check all the required application specific macros have been defined. + * These macros are application specific and (as downloaded) are defined + * within FreeRTOSConfig.h. + */ + +#ifndef configMINIMAL_STACK_SIZE + #error Missing definition: configMINIMAL_STACK_SIZE must be defined in FreeRTOSConfig.h. configMINIMAL_STACK_SIZE defines the size (in words) of the stack allocated to the idle task. Refer to the demo project provided for your port for a suitable value. +#endif + +#ifndef configMAX_PRIORITIES + #error Missing definition: configMAX_PRIORITIES must be defined in FreeRTOSConfig.h. See the Configuration section of the FreeRTOS API documentation for details. +#endif + +#if configMAX_PRIORITIES < 1 + #error configMAX_PRIORITIES must be defined to be greater than or equal to 1. +#endif + +#ifndef configUSE_PREEMPTION + #error Missing definition: configUSE_PREEMPTION must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. +#endif + +#ifndef configUSE_IDLE_HOOK + #error Missing definition: configUSE_IDLE_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. +#endif + +#ifndef configUSE_TICK_HOOK + #error Missing definition: configUSE_TICK_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. +#endif + +#ifndef configUSE_16_BIT_TICKS + #error Missing definition: configUSE_16_BIT_TICKS must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. +#endif + +#ifndef configUSE_CO_ROUTINES + #define configUSE_CO_ROUTINES 0 +#endif + +#ifndef INCLUDE_vTaskPrioritySet + #define INCLUDE_vTaskPrioritySet 0 +#endif + +#ifndef INCLUDE_uxTaskPriorityGet + #define INCLUDE_uxTaskPriorityGet 0 +#endif + +#ifndef INCLUDE_vTaskDelete + #define INCLUDE_vTaskDelete 0 +#endif + +#ifndef INCLUDE_vTaskSuspend + #define INCLUDE_vTaskSuspend 0 +#endif + +#ifndef INCLUDE_vTaskDelayUntil + #define INCLUDE_vTaskDelayUntil 0 +#endif + +#ifndef INCLUDE_vTaskDelay + #define INCLUDE_vTaskDelay 0 +#endif + +#ifndef INCLUDE_xTaskGetIdleTaskHandle + #define INCLUDE_xTaskGetIdleTaskHandle 0 +#endif + +#ifndef INCLUDE_xTaskAbortDelay + #define INCLUDE_xTaskAbortDelay 0 +#endif + +#ifndef INCLUDE_xQueueGetMutexHolder + #define INCLUDE_xQueueGetMutexHolder 0 +#endif + +#ifndef INCLUDE_xSemaphoreGetMutexHolder + #define INCLUDE_xSemaphoreGetMutexHolder INCLUDE_xQueueGetMutexHolder +#endif + +#ifndef INCLUDE_xTaskGetHandle + #define INCLUDE_xTaskGetHandle 0 +#endif + +#ifndef INCLUDE_uxTaskGetStackHighWaterMark + #define INCLUDE_uxTaskGetStackHighWaterMark 0 +#endif + +#ifndef INCLUDE_eTaskGetState + #define INCLUDE_eTaskGetState 0 +#endif + +#ifndef INCLUDE_xTaskResumeFromISR + #define INCLUDE_xTaskResumeFromISR 1 +#endif + +#ifndef INCLUDE_xTimerPendFunctionCall + #define INCLUDE_xTimerPendFunctionCall 0 +#endif + +#ifndef INCLUDE_xTaskGetSchedulerState + #define INCLUDE_xTaskGetSchedulerState 0 +#endif + +#ifndef INCLUDE_xTaskGetCurrentTaskHandle + #define INCLUDE_xTaskGetCurrentTaskHandle 0 +#endif + +#if configUSE_CO_ROUTINES != 0 + #ifndef configMAX_CO_ROUTINE_PRIORITIES + #error configMAX_CO_ROUTINE_PRIORITIES must be greater than or equal to 1. + #endif +#endif + +#ifndef configUSE_DAEMON_TASK_STARTUP_HOOK + #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 +#endif + +#ifndef configUSE_APPLICATION_TASK_TAG + #define configUSE_APPLICATION_TASK_TAG 0 +#endif + +#ifndef configNUM_THREAD_LOCAL_STORAGE_POINTERS + #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0 +#endif + +#ifndef configUSE_RECURSIVE_MUTEXES + #define configUSE_RECURSIVE_MUTEXES 0 +#endif + +#ifndef configUSE_MUTEXES + #define configUSE_MUTEXES 0 +#endif + +#ifndef configUSE_TIMERS + #define configUSE_TIMERS 0 +#endif + +#ifndef configUSE_COUNTING_SEMAPHORES + #define configUSE_COUNTING_SEMAPHORES 0 +#endif + +#ifndef configUSE_ALTERNATIVE_API + #define configUSE_ALTERNATIVE_API 0 +#endif + +#ifndef portCRITICAL_NESTING_IN_TCB + #define portCRITICAL_NESTING_IN_TCB 0 +#endif + +#ifndef configMAX_TASK_NAME_LEN + #define configMAX_TASK_NAME_LEN 16 +#endif + +#ifndef configIDLE_SHOULD_YIELD + #define configIDLE_SHOULD_YIELD 1 +#endif + +#if configMAX_TASK_NAME_LEN < 1 + #error configMAX_TASK_NAME_LEN must be set to a minimum of 1 in FreeRTOSConfig.h +#endif + +#ifndef configASSERT + #define configASSERT( x ) + #define configASSERT_DEFINED 0 +#else + #define configASSERT_DEFINED 1 +#endif + +/* The timers module relies on xTaskGetSchedulerState(). */ +#if configUSE_TIMERS == 1 + + #ifndef configTIMER_TASK_PRIORITY + #error If configUSE_TIMERS is set to 1 then configTIMER_TASK_PRIORITY must also be defined. + #endif /* configTIMER_TASK_PRIORITY */ + + #ifndef configTIMER_QUEUE_LENGTH + #error If configUSE_TIMERS is set to 1 then configTIMER_QUEUE_LENGTH must also be defined. + #endif /* configTIMER_QUEUE_LENGTH */ + + #ifndef configTIMER_TASK_STACK_DEPTH + #error If configUSE_TIMERS is set to 1 then configTIMER_TASK_STACK_DEPTH must also be defined. + #endif /* configTIMER_TASK_STACK_DEPTH */ + +#endif /* configUSE_TIMERS */ + +#ifndef portSET_INTERRUPT_MASK_FROM_ISR + #define portSET_INTERRUPT_MASK_FROM_ISR() 0 +#endif + +#ifndef portCLEAR_INTERRUPT_MASK_FROM_ISR + #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue +#endif + +#ifndef portCLEAN_UP_TCB + #define portCLEAN_UP_TCB( pxTCB ) ( void ) pxTCB +#endif + +#ifndef portPRE_TASK_DELETE_HOOK + #define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxYieldPending ) +#endif + +#ifndef portSETUP_TCB + #define portSETUP_TCB( pxTCB ) ( void ) pxTCB +#endif + +#ifndef configQUEUE_REGISTRY_SIZE + #define configQUEUE_REGISTRY_SIZE 0U +#endif + +#if ( configQUEUE_REGISTRY_SIZE < 1 ) + #define vQueueAddToRegistry( xQueue, pcName ) + #define vQueueUnregisterQueue( xQueue ) + #define pcQueueGetName( xQueue ) +#endif + +#ifndef portPOINTER_SIZE_TYPE + #define portPOINTER_SIZE_TYPE uint32_t +#endif + +/* Remove any unused trace macros. */ +#ifndef traceSTART + /* Used to perform any necessary initialisation - for example, open a file + into which trace is to be written. */ + #define traceSTART() +#endif + +#ifndef traceEND + /* Use to close a trace, for example close a file into which trace has been + written. */ + #define traceEND() +#endif + +#ifndef traceTASK_SWITCHED_IN + /* Called after a task has been selected to run. pxCurrentTCB holds a pointer + to the task control block of the selected task. */ + #define traceTASK_SWITCHED_IN() +#endif + +#ifndef traceINCREASE_TICK_COUNT + /* Called before stepping the tick count after waking from tickless idle + sleep. */ + #define traceINCREASE_TICK_COUNT( x ) +#endif + +#ifndef traceLOW_POWER_IDLE_BEGIN + /* Called immediately before entering tickless idle. */ + #define traceLOW_POWER_IDLE_BEGIN() +#endif + +#ifndef traceLOW_POWER_IDLE_END + /* Called when returning to the Idle task after a tickless idle. */ + #define traceLOW_POWER_IDLE_END() +#endif + +#ifndef traceTASK_SWITCHED_OUT + /* Called before a task has been selected to run. pxCurrentTCB holds a pointer + to the task control block of the task being switched out. */ + #define traceTASK_SWITCHED_OUT() +#endif + +#ifndef traceTASK_PRIORITY_INHERIT + /* Called when a task attempts to take a mutex that is already held by a + lower priority task. pxTCBOfMutexHolder is a pointer to the TCB of the task + that holds the mutex. uxInheritedPriority is the priority the mutex holder + will inherit (the priority of the task that is attempting to obtain the + muted. */ + #define traceTASK_PRIORITY_INHERIT( pxTCBOfMutexHolder, uxInheritedPriority ) +#endif + +#ifndef traceTASK_PRIORITY_DISINHERIT + /* Called when a task releases a mutex, the holding of which had resulted in + the task inheriting the priority of a higher priority task. + pxTCBOfMutexHolder is a pointer to the TCB of the task that is releasing the + mutex. uxOriginalPriority is the task's configured (base) priority. */ + #define traceTASK_PRIORITY_DISINHERIT( pxTCBOfMutexHolder, uxOriginalPriority ) +#endif + +#ifndef traceBLOCKING_ON_QUEUE_RECEIVE + /* Task is about to block because it cannot read from a + queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore + upon which the read was attempted. pxCurrentTCB points to the TCB of the + task that attempted the read. */ + #define traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ) +#endif + +#ifndef traceBLOCKING_ON_QUEUE_PEEK + /* Task is about to block because it cannot read from a + queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore + upon which the read was attempted. pxCurrentTCB points to the TCB of the + task that attempted the read. */ + #define traceBLOCKING_ON_QUEUE_PEEK( pxQueue ) +#endif + +#ifndef traceBLOCKING_ON_QUEUE_SEND + /* Task is about to block because it cannot write to a + queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore + upon which the write was attempted. pxCurrentTCB points to the TCB of the + task that attempted the write. */ + #define traceBLOCKING_ON_QUEUE_SEND( pxQueue ) +#endif + +#ifndef configCHECK_FOR_STACK_OVERFLOW + #define configCHECK_FOR_STACK_OVERFLOW 0 +#endif + +#ifndef configRECORD_STACK_HIGH_ADDRESS + #define configRECORD_STACK_HIGH_ADDRESS 0 +#endif + +#ifndef configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H + #define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 0 +#endif + +/* The following event macros are embedded in the kernel API calls. */ + +#ifndef traceMOVED_TASK_TO_READY_STATE + #define traceMOVED_TASK_TO_READY_STATE( pxTCB ) +#endif + +#ifndef tracePOST_MOVED_TASK_TO_READY_STATE + #define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) +#endif + +#ifndef traceQUEUE_CREATE + #define traceQUEUE_CREATE( pxNewQueue ) +#endif + +#ifndef traceQUEUE_CREATE_FAILED + #define traceQUEUE_CREATE_FAILED( ucQueueType ) +#endif + +#ifndef traceCREATE_MUTEX + #define traceCREATE_MUTEX( pxNewQueue ) +#endif + +#ifndef traceCREATE_MUTEX_FAILED + #define traceCREATE_MUTEX_FAILED() +#endif + +#ifndef traceGIVE_MUTEX_RECURSIVE + #define traceGIVE_MUTEX_RECURSIVE( pxMutex ) +#endif + +#ifndef traceGIVE_MUTEX_RECURSIVE_FAILED + #define traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex ) +#endif + +#ifndef traceTAKE_MUTEX_RECURSIVE + #define traceTAKE_MUTEX_RECURSIVE( pxMutex ) +#endif + +#ifndef traceTAKE_MUTEX_RECURSIVE_FAILED + #define traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex ) +#endif + +#ifndef traceCREATE_COUNTING_SEMAPHORE + #define traceCREATE_COUNTING_SEMAPHORE() +#endif + +#ifndef traceCREATE_COUNTING_SEMAPHORE_FAILED + #define traceCREATE_COUNTING_SEMAPHORE_FAILED() +#endif + +#ifndef traceQUEUE_SEND + #define traceQUEUE_SEND( pxQueue ) +#endif + +#ifndef traceQUEUE_SEND_FAILED + #define traceQUEUE_SEND_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_RECEIVE + #define traceQUEUE_RECEIVE( pxQueue ) +#endif + +#ifndef traceQUEUE_PEEK + #define traceQUEUE_PEEK( pxQueue ) +#endif + +#ifndef traceQUEUE_PEEK_FAILED + #define traceQUEUE_PEEK_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_PEEK_FROM_ISR + #define traceQUEUE_PEEK_FROM_ISR( pxQueue ) +#endif + +#ifndef traceQUEUE_RECEIVE_FAILED + #define traceQUEUE_RECEIVE_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_SEND_FROM_ISR + #define traceQUEUE_SEND_FROM_ISR( pxQueue ) +#endif + +#ifndef traceQUEUE_SEND_FROM_ISR_FAILED + #define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_RECEIVE_FROM_ISR + #define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) +#endif + +#ifndef traceQUEUE_RECEIVE_FROM_ISR_FAILED + #define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_PEEK_FROM_ISR_FAILED + #define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_DELETE + #define traceQUEUE_DELETE( pxQueue ) +#endif + +#ifndef traceTASK_CREATE + #define traceTASK_CREATE( pxNewTCB ) +#endif + +#ifndef traceTASK_CREATE_FAILED + #define traceTASK_CREATE_FAILED() +#endif + +#ifndef traceTASK_DELETE + #define traceTASK_DELETE( pxTaskToDelete ) +#endif + +#ifndef traceTASK_DELAY_UNTIL + #define traceTASK_DELAY_UNTIL( x ) +#endif + +#ifndef traceTASK_DELAY + #define traceTASK_DELAY() +#endif + +#ifndef traceTASK_PRIORITY_SET + #define traceTASK_PRIORITY_SET( pxTask, uxNewPriority ) +#endif + +#ifndef traceTASK_SUSPEND + #define traceTASK_SUSPEND( pxTaskToSuspend ) +#endif + +#ifndef traceTASK_RESUME + #define traceTASK_RESUME( pxTaskToResume ) +#endif + +#ifndef traceTASK_RESUME_FROM_ISR + #define traceTASK_RESUME_FROM_ISR( pxTaskToResume ) +#endif + +#ifndef traceTASK_INCREMENT_TICK + #define traceTASK_INCREMENT_TICK( xTickCount ) +#endif + +#ifndef traceTIMER_CREATE + #define traceTIMER_CREATE( pxNewTimer ) +#endif + +#ifndef traceTIMER_CREATE_FAILED + #define traceTIMER_CREATE_FAILED() +#endif + +#ifndef traceTIMER_COMMAND_SEND + #define traceTIMER_COMMAND_SEND( xTimer, xMessageID, xMessageValueValue, xReturn ) +#endif + +#ifndef traceTIMER_EXPIRED + #define traceTIMER_EXPIRED( pxTimer ) +#endif + +#ifndef traceTIMER_COMMAND_RECEIVED + #define traceTIMER_COMMAND_RECEIVED( pxTimer, xMessageID, xMessageValue ) +#endif + +#ifndef traceMALLOC + #define traceMALLOC( pvAddress, uiSize ) +#endif + +#ifndef traceFREE + #define traceFREE( pvAddress, uiSize ) +#endif + +#ifndef traceEVENT_GROUP_CREATE + #define traceEVENT_GROUP_CREATE( xEventGroup ) +#endif + +#ifndef traceEVENT_GROUP_CREATE_FAILED + #define traceEVENT_GROUP_CREATE_FAILED() +#endif + +#ifndef traceEVENT_GROUP_SYNC_BLOCK + #define traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor ) +#endif + +#ifndef traceEVENT_GROUP_SYNC_END + #define traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred ) ( void ) xTimeoutOccurred +#endif + +#ifndef traceEVENT_GROUP_WAIT_BITS_BLOCK + #define traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor ) +#endif + +#ifndef traceEVENT_GROUP_WAIT_BITS_END + #define traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred ) ( void ) xTimeoutOccurred +#endif + +#ifndef traceEVENT_GROUP_CLEAR_BITS + #define traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear ) +#endif + +#ifndef traceEVENT_GROUP_CLEAR_BITS_FROM_ISR + #define traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear ) +#endif + +#ifndef traceEVENT_GROUP_SET_BITS + #define traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet ) +#endif + +#ifndef traceEVENT_GROUP_SET_BITS_FROM_ISR + #define traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet ) +#endif + +#ifndef traceEVENT_GROUP_DELETE + #define traceEVENT_GROUP_DELETE( xEventGroup ) +#endif + +#ifndef tracePEND_FUNC_CALL + #define tracePEND_FUNC_CALL(xFunctionToPend, pvParameter1, ulParameter2, ret) +#endif + +#ifndef tracePEND_FUNC_CALL_FROM_ISR + #define tracePEND_FUNC_CALL_FROM_ISR(xFunctionToPend, pvParameter1, ulParameter2, ret) +#endif + +#ifndef traceQUEUE_REGISTRY_ADD + #define traceQUEUE_REGISTRY_ADD(xQueue, pcQueueName) +#endif + +#ifndef traceTASK_NOTIFY_TAKE_BLOCK + #define traceTASK_NOTIFY_TAKE_BLOCK() +#endif + +#ifndef traceTASK_NOTIFY_TAKE + #define traceTASK_NOTIFY_TAKE() +#endif + +#ifndef traceTASK_NOTIFY_WAIT_BLOCK + #define traceTASK_NOTIFY_WAIT_BLOCK() +#endif + +#ifndef traceTASK_NOTIFY_WAIT + #define traceTASK_NOTIFY_WAIT() +#endif + +#ifndef traceTASK_NOTIFY + #define traceTASK_NOTIFY() +#endif + +#ifndef traceTASK_NOTIFY_FROM_ISR + #define traceTASK_NOTIFY_FROM_ISR() +#endif + +#ifndef traceTASK_NOTIFY_GIVE_FROM_ISR + #define traceTASK_NOTIFY_GIVE_FROM_ISR() +#endif + +#ifndef traceSTREAM_BUFFER_CREATE_FAILED + #define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_CREATE_STATIC_FAILED + #define traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_CREATE + #define traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_DELETE + #define traceSTREAM_BUFFER_DELETE( xStreamBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_RESET + #define traceSTREAM_BUFFER_RESET( xStreamBuffer ) +#endif + +#ifndef traceBLOCKING_ON_STREAM_BUFFER_SEND + #define traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_SEND + #define traceSTREAM_BUFFER_SEND( xStreamBuffer, xBytesSent ) +#endif + +#ifndef traceSTREAM_BUFFER_SEND_FAILED + #define traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_SEND_FROM_ISR + #define traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xBytesSent ) +#endif + +#ifndef traceBLOCKING_ON_STREAM_BUFFER_RECEIVE + #define traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_RECEIVE + #define traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength ) +#endif + +#ifndef traceSTREAM_BUFFER_RECEIVE_FAILED + #define traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_RECEIVE_FROM_ISR + #define traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength ) +#endif + +#ifndef configGENERATE_RUN_TIME_STATS + #define configGENERATE_RUN_TIME_STATS 0 +#endif + +#if ( configGENERATE_RUN_TIME_STATS == 1 ) + + #ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS + #error If configGENERATE_RUN_TIME_STATS is defined then portCONFIGURE_TIMER_FOR_RUN_TIME_STATS must also be defined. portCONFIGURE_TIMER_FOR_RUN_TIME_STATS should call a port layer function to setup a peripheral timer/counter that can then be used as the run time counter time base. + #endif /* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS */ + + #ifndef portGET_RUN_TIME_COUNTER_VALUE + #ifndef portALT_GET_RUN_TIME_COUNTER_VALUE + #error If configGENERATE_RUN_TIME_STATS is defined then either portGET_RUN_TIME_COUNTER_VALUE or portALT_GET_RUN_TIME_COUNTER_VALUE must also be defined. See the examples provided and the FreeRTOS web site for more information. + #endif /* portALT_GET_RUN_TIME_COUNTER_VALUE */ + #endif /* portGET_RUN_TIME_COUNTER_VALUE */ + +#endif /* configGENERATE_RUN_TIME_STATS */ + +#ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS + #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() +#endif + +#ifndef configUSE_MALLOC_FAILED_HOOK + #define configUSE_MALLOC_FAILED_HOOK 0 +#endif + +#ifndef portPRIVILEGE_BIT + #define portPRIVILEGE_BIT ( ( UBaseType_t ) 0x00 ) +#endif + +#ifndef portYIELD_WITHIN_API + #define portYIELD_WITHIN_API portYIELD +#endif + +#ifndef portSUPPRESS_TICKS_AND_SLEEP + #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) +#endif + +#ifndef configEXPECTED_IDLE_TIME_BEFORE_SLEEP + #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2 +#endif + +#if configEXPECTED_IDLE_TIME_BEFORE_SLEEP < 2 + #error configEXPECTED_IDLE_TIME_BEFORE_SLEEP must not be less than 2 +#endif + +#ifndef configUSE_TICKLESS_IDLE + #define configUSE_TICKLESS_IDLE 0 +#endif + +#ifndef configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING + #define configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( x ) +#endif + +#ifndef configPRE_SLEEP_PROCESSING + #define configPRE_SLEEP_PROCESSING( x ) +#endif + +#ifndef configPOST_SLEEP_PROCESSING + #define configPOST_SLEEP_PROCESSING( x ) +#endif + +#ifndef configUSE_QUEUE_SETS + #define configUSE_QUEUE_SETS 0 +#endif + +#ifndef portTASK_USES_FLOATING_POINT + #define portTASK_USES_FLOATING_POINT() +#endif + +#ifndef portTASK_CALLS_SECURE_FUNCTIONS + #define portTASK_CALLS_SECURE_FUNCTIONS() +#endif + +#ifndef configUSE_TIME_SLICING + #define configUSE_TIME_SLICING 1 +#endif + +#ifndef configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS + #define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0 +#endif + +#ifndef configUSE_STATS_FORMATTING_FUNCTIONS + #define configUSE_STATS_FORMATTING_FUNCTIONS 0 +#endif + +#ifndef portASSERT_IF_INTERRUPT_PRIORITY_INVALID + #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() +#endif + +#ifndef configUSE_TRACE_FACILITY + #define configUSE_TRACE_FACILITY 0 +#endif + +#ifndef mtCOVERAGE_TEST_MARKER + #define mtCOVERAGE_TEST_MARKER() +#endif + +#ifndef mtCOVERAGE_TEST_DELAY + #define mtCOVERAGE_TEST_DELAY() +#endif + +#ifndef portASSERT_IF_IN_ISR + #define portASSERT_IF_IN_ISR() +#endif + +#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION + #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#endif + +#ifndef configAPPLICATION_ALLOCATED_HEAP + #define configAPPLICATION_ALLOCATED_HEAP 0 +#endif + +#ifndef configUSE_TASK_NOTIFICATIONS + #define configUSE_TASK_NOTIFICATIONS 1 +#endif + +#ifndef portTICK_TYPE_IS_ATOMIC + #define portTICK_TYPE_IS_ATOMIC 0 +#endif + +#ifndef configSUPPORT_STATIC_ALLOCATION + /* Defaults to 0 for backward compatibility. */ + #define configSUPPORT_STATIC_ALLOCATION 0 +#endif + +#ifndef configSUPPORT_DYNAMIC_ALLOCATION + /* Defaults to 1 for backward compatibility. */ + #define configSUPPORT_DYNAMIC_ALLOCATION 1 +#endif + +#ifndef configSTACK_DEPTH_TYPE + /* Defaults to uint16_t for backward compatibility, but can be overridden + in FreeRTOSConfig.h if uint16_t is too restrictive. */ + #define configSTACK_DEPTH_TYPE uint16_t +#endif + +/* Sanity check the configuration. */ +#if( configUSE_TICKLESS_IDLE != 0 ) + #if( INCLUDE_vTaskSuspend != 1 ) + #error INCLUDE_vTaskSuspend must be set to 1 if configUSE_TICKLESS_IDLE is not set to 0 + #endif /* INCLUDE_vTaskSuspend */ +#endif /* configUSE_TICKLESS_IDLE */ + +#if( ( configSUPPORT_STATIC_ALLOCATION == 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) ) + #error configSUPPORT_STATIC_ALLOCATION and configSUPPORT_DYNAMIC_ALLOCATION cannot both be 0, but can both be 1. +#endif + +#if( ( configUSE_RECURSIVE_MUTEXES == 1 ) && ( configUSE_MUTEXES != 1 ) ) + #error configUSE_MUTEXES must be set to 1 to use recursive mutexes +#endif + +#ifndef configINITIAL_TICK_COUNT + #define configINITIAL_TICK_COUNT 0 +#endif + +#if( portTICK_TYPE_IS_ATOMIC == 0 ) + /* Either variables of tick type cannot be read atomically, or + portTICK_TYPE_IS_ATOMIC was not set - map the critical sections used when + the tick count is returned to the standard critical section macros. */ + #define portTICK_TYPE_ENTER_CRITICAL() portENTER_CRITICAL() + #define portTICK_TYPE_EXIT_CRITICAL() portEXIT_CRITICAL() + #define portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR() + #define portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( ( x ) ) +#else + /* The tick type can be read atomically, so critical sections used when the + tick count is returned can be defined away. */ + #define portTICK_TYPE_ENTER_CRITICAL() + #define portTICK_TYPE_EXIT_CRITICAL() + #define portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR() 0 + #define portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( x ) ( void ) x +#endif + +/* Definitions to allow backward compatibility with FreeRTOS versions prior to +V8 if desired. */ +#ifndef configENABLE_BACKWARD_COMPATIBILITY + #define configENABLE_BACKWARD_COMPATIBILITY 1 +#endif + +#ifndef configPRINTF + /* configPRINTF() was not defined, so define it away to nothing. To use + configPRINTF() then define it as follows (where MyPrintFunction() is + provided by the application writer): + + void MyPrintFunction(const char *pcFormat, ... ); + #define configPRINTF( X ) MyPrintFunction X + + Then call like a standard printf() function, but placing brackets around + all parameters so they are passed as a single parameter. For example: + configPRINTF( ("Value = %d", MyVariable) ); */ + #define configPRINTF( X ) +#endif + +#ifndef configMAX + /* The application writer has not provided their own MAX macro, so define + the following generic implementation. */ + #define configMAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) ) +#endif + +#ifndef configMIN + /* The application writer has not provided their own MAX macro, so define + the following generic implementation. */ + #define configMIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) ) +#endif + +#if configENABLE_BACKWARD_COMPATIBILITY == 1 + #define eTaskStateGet eTaskGetState + #define portTickType TickType_t + #define xTaskHandle TaskHandle_t + #define xQueueHandle QueueHandle_t + #define xSemaphoreHandle SemaphoreHandle_t + #define xQueueSetHandle QueueSetHandle_t + #define xQueueSetMemberHandle QueueSetMemberHandle_t + #define xTimeOutType TimeOut_t + #define xMemoryRegion MemoryRegion_t + #define xTaskParameters TaskParameters_t + #define xTaskStatusType TaskStatus_t + #define xTimerHandle TimerHandle_t + #define xCoRoutineHandle CoRoutineHandle_t + #define pdTASK_HOOK_CODE TaskHookFunction_t + #define portTICK_RATE_MS portTICK_PERIOD_MS + #define pcTaskGetTaskName pcTaskGetName + #define pcTimerGetTimerName pcTimerGetName + #define pcQueueGetQueueName pcQueueGetName + #define vTaskGetTaskInfo vTaskGetInfo + + /* Backward compatibility within the scheduler code only - these definitions + are not really required but are included for completeness. */ + #define tmrTIMER_CALLBACK TimerCallbackFunction_t + #define pdTASK_CODE TaskFunction_t + #define xListItem ListItem_t + #define xList List_t +#endif /* configENABLE_BACKWARD_COMPATIBILITY */ + +#if( configUSE_ALTERNATIVE_API != 0 ) + #error The alternative API was deprecated some time ago, and was removed in FreeRTOS V9.0 0 +#endif + +/* Set configUSE_TASK_FPU_SUPPORT to 0 to omit floating point support even +if floating point hardware is otherwise supported by the FreeRTOS port in use. +This constant is not supported by all FreeRTOS ports that include floating +point support. */ +#ifndef configUSE_TASK_FPU_SUPPORT + #define configUSE_TASK_FPU_SUPPORT 1 +#endif + +/* + * In line with software engineering best practice, FreeRTOS implements a strict + * data hiding policy, so the real structures used by FreeRTOS to maintain the + * state of tasks, queues, semaphores, etc. are not accessible to the application + * code. However, if the application writer wants to statically allocate such + * an object then the size of the object needs to be know. Dummy structures + * that are guaranteed to have the same size and alignment requirements of the + * real objects are used for this purpose. The dummy list and list item + * structures below are used for inclusion in such a dummy structure. + */ +struct xSTATIC_LIST_ITEM +{ + TickType_t xDummy1; + void *pvDummy2[ 4 ]; +}; +typedef struct xSTATIC_LIST_ITEM StaticListItem_t; + +/* See the comments above the struct xSTATIC_LIST_ITEM definition. */ +struct xSTATIC_MINI_LIST_ITEM +{ + TickType_t xDummy1; + void *pvDummy2[ 2 ]; +}; +typedef struct xSTATIC_MINI_LIST_ITEM StaticMiniListItem_t; + +/* See the comments above the struct xSTATIC_LIST_ITEM definition. */ +typedef struct xSTATIC_LIST +{ + UBaseType_t uxDummy1; + void *pvDummy2; + StaticMiniListItem_t xDummy3; +} StaticList_t; + +/* + * In line with software engineering best practice, especially when supplying a + * library that is likely to change in future versions, FreeRTOS implements a + * strict data hiding policy. This means the Task structure used internally by + * FreeRTOS is not accessible to application code. However, if the application + * writer wants to statically allocate the memory required to create a task then + * the size of the task object needs to be know. The StaticTask_t structure + * below is provided for this purpose. Its sizes and alignment requirements are + * guaranteed to match those of the genuine structure, no matter which + * architecture is being used, and no matter how the values in FreeRTOSConfig.h + * are set. Its contents are somewhat obfuscated in the hope users will + * recognise that it would be unwise to make direct use of the structure members. + */ +typedef struct xSTATIC_TCB +{ + void *pxDummy1; + #if ( portUSING_MPU_WRAPPERS == 1 ) + xMPU_SETTINGS xDummy2; + #endif + StaticListItem_t xDummy3[ 2 ]; + UBaseType_t uxDummy5; + void *pxDummy6; + uint8_t ucDummy7[ configMAX_TASK_NAME_LEN ]; + #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) + void *pxDummy8; + #endif + #if ( portCRITICAL_NESTING_IN_TCB == 1 ) + UBaseType_t uxDummy9; + #endif + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxDummy10[ 2 ]; + #endif + #if ( configUSE_MUTEXES == 1 ) + UBaseType_t uxDummy12[ 2 ]; + #endif + #if ( configUSE_APPLICATION_TASK_TAG == 1 ) + void *pxDummy14; + #endif + #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 ) + void *pvDummy15[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ]; + #endif + #if ( configGENERATE_RUN_TIME_STATS == 1 ) + uint32_t ulDummy16; + #endif + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + struct _reent xDummy17; + #endif + #if ( configUSE_TASK_NOTIFICATIONS == 1 ) + uint32_t ulDummy18; + uint8_t ucDummy19; + #endif + #if( ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) || ( portUSING_MPU_WRAPPERS == 1 ) ) + uint8_t uxDummy20; + #endif + + #if( INCLUDE_xTaskAbortDelay == 1 ) + uint8_t ucDummy21; + #endif + +} StaticTask_t; + +/* + * In line with software engineering best practice, especially when supplying a + * library that is likely to change in future versions, FreeRTOS implements a + * strict data hiding policy. This means the Queue structure used internally by + * FreeRTOS is not accessible to application code. However, if the application + * writer wants to statically allocate the memory required to create a queue + * then the size of the queue object needs to be know. The StaticQueue_t + * structure below is provided for this purpose. Its sizes and alignment + * requirements are guaranteed to match those of the genuine structure, no + * matter which architecture is being used, and no matter how the values in + * FreeRTOSConfig.h are set. Its contents are somewhat obfuscated in the hope + * users will recognise that it would be unwise to make direct use of the + * structure members. + */ +typedef struct xSTATIC_QUEUE +{ + void *pvDummy1[ 3 ]; + + union + { + void *pvDummy2; + UBaseType_t uxDummy2; + } u; + + StaticList_t xDummy3[ 2 ]; + UBaseType_t uxDummy4[ 3 ]; + uint8_t ucDummy5[ 2 ]; + + #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + uint8_t ucDummy6; + #endif + + #if ( configUSE_QUEUE_SETS == 1 ) + void *pvDummy7; + #endif + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxDummy8; + uint8_t ucDummy9; + #endif + +} StaticQueue_t; +typedef StaticQueue_t StaticSemaphore_t; + +/* + * In line with software engineering best practice, especially when supplying a + * library that is likely to change in future versions, FreeRTOS implements a + * strict data hiding policy. This means the event group structure used + * internally by FreeRTOS is not accessible to application code. However, if + * the application writer wants to statically allocate the memory required to + * create an event group then the size of the event group object needs to be + * know. The StaticEventGroup_t structure below is provided for this purpose. + * Its sizes and alignment requirements are guaranteed to match those of the + * genuine structure, no matter which architecture is being used, and no matter + * how the values in FreeRTOSConfig.h are set. Its contents are somewhat + * obfuscated in the hope users will recognise that it would be unwise to make + * direct use of the structure members. + */ +typedef struct xSTATIC_EVENT_GROUP +{ + TickType_t xDummy1; + StaticList_t xDummy2; + + #if( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxDummy3; + #endif + + #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + uint8_t ucDummy4; + #endif + +} StaticEventGroup_t; + +/* + * In line with software engineering best practice, especially when supplying a + * library that is likely to change in future versions, FreeRTOS implements a + * strict data hiding policy. This means the software timer structure used + * internally by FreeRTOS is not accessible to application code. However, if + * the application writer wants to statically allocate the memory required to + * create a software timer then the size of the queue object needs to be know. + * The StaticTimer_t structure below is provided for this purpose. Its sizes + * and alignment requirements are guaranteed to match those of the genuine + * structure, no matter which architecture is being used, and no matter how the + * values in FreeRTOSConfig.h are set. Its contents are somewhat obfuscated in + * the hope users will recognise that it would be unwise to make direct use of + * the structure members. + */ +typedef struct xSTATIC_TIMER +{ + void *pvDummy1; + StaticListItem_t xDummy2; + TickType_t xDummy3; + UBaseType_t uxDummy4; + void *pvDummy5[ 2 ]; + #if( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxDummy6; + #endif + + #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + uint8_t ucDummy7; + #endif + +} StaticTimer_t; + +/* +* In line with software engineering best practice, especially when supplying a +* library that is likely to change in future versions, FreeRTOS implements a +* strict data hiding policy. This means the stream buffer structure used +* internally by FreeRTOS is not accessible to application code. However, if +* the application writer wants to statically allocate the memory required to +* create a stream buffer then the size of the stream buffer object needs to be +* know. The StaticStreamBuffer_t structure below is provided for this purpose. +* Its size and alignment requirements are guaranteed to match those of the +* genuine structure, no matter which architecture is being used, and no matter +* how the values in FreeRTOSConfig.h are set. Its contents are somewhat +* obfuscated in the hope users will recognise that it would be unwise to make +* direct use of the structure members. +*/ +typedef struct xSTATIC_STREAM_BUFFER +{ + size_t uxDummy1[ 4 ]; + void * pvDummy2[ 3 ]; + uint8_t ucDummy3; + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxDummy4; + #endif +} StaticStreamBuffer_t; + +/* Message buffers are built on stream buffers. */ +typedef StaticStreamBuffer_t StaticMessageBuffer_t; + +#ifdef __cplusplus +} +#endif + +#endif /* INC_FREERTOS_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOSConfig_template.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOSConfig_template.h new file mode 100644 index 0000000..0bef5a4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOSConfig_template.h @@ -0,0 +1,162 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * this is a template configuration files + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * These parameters and more are described within the 'configuration' section of the + * FreeRTOS API documentation available on the FreeRTOS.org web site. + * + * See http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + extern uint32_t SystemCoreClock; +#endif + +/* CMSIS-RTOSv2 defines 56 levels of priorities. To be able to use them + * all and avoid application misbehavior, configUSE_PORT_OPTIMISED_TASK_SELECTION + * must be set to 0 and configMAX_PRIORITIES to 56 + * + */ +/* #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0*/ +/* #define configMAX_PRIORITIES ( 56 ) */ +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configMAX_PRIORITIES (7) +#define configSUPPORT_STATIC_ALLOCATION 0 +#define configCPU_CLOCK_HZ (SystemCoreClock) +#define configTICK_RATE_HZ ((TickType_t)1000) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configTOTAL_HEAP_SIZE ((size_t)(15 * 1024)) +#define configMAX_TASK_NAME_LEN (16) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) + +/* Software timer definitions. */ +#define configUSE_TIMERS 0 +#define configTIMER_TASK_PRIORITY (2) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 0 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 + +/*------------- CMSIS-RTOS V2 specific defines -----------*/ +/* When using CMSIS-RTOSv2 set configSUPPORT_STATIC_ALLOCATION to 1 + * is mandatory to avoid compile errors. + * CMSIS-RTOS V2 implmentation requires the following defines + * +#define configSUPPORT_STATIC_ALLOCATION 1 <-- cmsis_os threads are created using xTaskCreateStatic() API +#define configMAX_PRIORITIES (56) <-- Priority range in CMSIS-RTOS V2 is [0 .. 56] +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 <-- when set to 1, configMAX_PRIORITIES can't be more than 32 which is not suitable for the new CMSIS-RTOS v2 priority range +*/ + +/* the CMSIS-RTOS V2 FreeRTOS wrapper is dependent on the heap implementation used + * by the application thus the correct define need to be enabled from the list + * below + * +//define USE_FreeRTOS_HEAP_1 +//define USE_FreeRTOS_HEAP_2 +//define USE_FreeRTOS_HEAP_3 +//define USE_FreeRTOS_HEAP_4 +//define USE_FreeRTOS_HEAP_5 + +*/ + + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 4 /* 15 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS + standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler + +/* IMPORTANT: FreeRTOS is using the SysTick as internal time base, thus make sure the system and peripherials are + using a different time base (TIM based for example). + */ +#define xPortSysTickHandler SysTick_Handler + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/StackMacros.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/StackMacros.h new file mode 100644 index 0000000..534f004 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/StackMacros.h @@ -0,0 +1,133 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef STACK_MACROS_H +#define STACK_MACROS_H + +#ifndef _MSC_VER /* Visual Studio doesn't support #warning. */ + #warning The name of this file has changed to stack_macros.h. Please update your code accordingly. This source file (which has the original name) will be removed in future released. +#endif + +/* + * Call the stack overflow hook function if the stack of the task being swapped + * out is currently overflowed, or looks like it might have overflowed in the + * past. + * + * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check + * the current stack state only - comparing the current top of stack value to + * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 + * will also cause the last few stack bytes to be checked to ensure the value + * to which the bytes were set when the task was created have not been + * overwritten. Note this second test does not guarantee that an overflowed + * stack will always be recognised. + */ + +/*-----------------------------------------------------------*/ + +#if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) ) + + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ +/*-----------------------------------------------------------*/ + +#if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) ) + + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ +/*-----------------------------------------------------------*/ + +#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) + + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ + const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \ + \ + if( ( pulStack[ 0 ] != ulCheckValue ) || \ + ( pulStack[ 1 ] != ulCheckValue ) || \ + ( pulStack[ 2 ] != ulCheckValue ) || \ + ( pulStack[ 3 ] != ulCheckValue ) ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ +/*-----------------------------------------------------------*/ + +#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) + + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ + static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ + \ + \ + pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ + \ + /* Has the extremity of the task stack ever been written over? */ \ + if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ +/*-----------------------------------------------------------*/ + +/* Remove stack overflow macro if not being used. */ +#ifndef taskCHECK_FOR_STACK_OVERFLOW + #define taskCHECK_FOR_STACK_OVERFLOW() +#endif + + + +#endif /* STACK_MACROS_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/croutine.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/croutine.h new file mode 100644 index 0000000..f4c54d2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/croutine.h @@ -0,0 +1,720 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef CO_ROUTINE_H +#define CO_ROUTINE_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h must appear in source files before include croutine.h" +#endif + +#include "list.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Used to hide the implementation of the co-routine control block. The +control block structure however has to be included in the header due to +the macro implementation of the co-routine functionality. */ +typedef void * CoRoutineHandle_t; + +/* Defines the prototype to which co-routine functions must conform. */ +typedef void (*crCOROUTINE_CODE)( CoRoutineHandle_t, UBaseType_t ); + +typedef struct corCoRoutineControlBlock +{ + crCOROUTINE_CODE pxCoRoutineFunction; + ListItem_t xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */ + ListItem_t xEventListItem; /*< List item used to place the CRCB in event lists. */ + UBaseType_t uxPriority; /*< The priority of the co-routine in relation to other co-routines. */ + UBaseType_t uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */ + uint16_t uxState; /*< Used internally by the co-routine implementation. */ +} CRCB_t; /* Co-routine control block. Note must be identical in size down to uxPriority with TCB_t. */ + +/** + * croutine. h + *
+ BaseType_t xCoRoutineCreate(
+                                 crCOROUTINE_CODE pxCoRoutineCode,
+                                 UBaseType_t uxPriority,
+                                 UBaseType_t uxIndex
+                               );
+ * + * Create a new co-routine and add it to the list of co-routines that are + * ready to run. + * + * @param pxCoRoutineCode Pointer to the co-routine function. Co-routine + * functions require special syntax - see the co-routine section of the WEB + * documentation for more information. + * + * @param uxPriority The priority with respect to other co-routines at which + * the co-routine will run. + * + * @param uxIndex Used to distinguish between different co-routines that + * execute the same function. See the example below and the co-routine section + * of the WEB documentation for further information. + * + * @return pdPASS if the co-routine was successfully created and added to a ready + * list, otherwise an error code defined with ProjDefs.h. + * + * Example usage: +
+ // Co-routine to be created.
+ void vFlashCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ {
+ // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ // This may not be necessary for const variables.
+ static const char cLedToFlash[ 2 ] = { 5, 6 };
+ static const TickType_t uxFlashRates[ 2 ] = { 200, 400 };
+
+     // Must start every co-routine with a call to crSTART();
+     crSTART( xHandle );
+
+     for( ;; )
+     {
+         // This co-routine just delays for a fixed period, then toggles
+         // an LED.  Two co-routines are created using this function, so
+         // the uxIndex parameter is used to tell the co-routine which
+         // LED to flash and how int32_t to delay.  This assumes xQueue has
+         // already been created.
+         vParTestToggleLED( cLedToFlash[ uxIndex ] );
+         crDELAY( xHandle, uxFlashRates[ uxIndex ] );
+     }
+
+     // Must end every co-routine with a call to crEND();
+     crEND();
+ }
+
+ // Function that creates two co-routines.
+ void vOtherFunction( void )
+ {
+ uint8_t ucParameterToPass;
+ TaskHandle_t xHandle;
+
+     // Create two co-routines at priority 0.  The first is given index 0
+     // so (from the code above) toggles LED 5 every 200 ticks.  The second
+     // is given index 1 so toggles LED 6 every 400 ticks.
+     for( uxIndex = 0; uxIndex < 2; uxIndex++ )
+     {
+         xCoRoutineCreate( vFlashCoRoutine, 0, uxIndex );
+     }
+ }
+   
+ * \defgroup xCoRoutineCreate xCoRoutineCreate + * \ingroup Tasks + */ +BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex ); + + +/** + * croutine. h + *
+ void vCoRoutineSchedule( void );
+ * + * Run a co-routine. + * + * vCoRoutineSchedule() executes the highest priority co-routine that is able + * to run. The co-routine will execute until it either blocks, yields or is + * preempted by a task. Co-routines execute cooperatively so one + * co-routine cannot be preempted by another, but can be preempted by a task. + * + * If an application comprises of both tasks and co-routines then + * vCoRoutineSchedule should be called from the idle task (in an idle task + * hook). + * + * Example usage: +
+ // This idle task hook will schedule a co-routine each time it is called.
+ // The rest of the idle task will execute between co-routine calls.
+ void vApplicationIdleHook( void )
+ {
+	vCoRoutineSchedule();
+ }
+
+ // Alternatively, if you do not require any other part of the idle task to
+ // execute, the idle task hook can call vCoRoutineScheduler() within an
+ // infinite loop.
+ void vApplicationIdleHook( void )
+ {
+    for( ;; )
+    {
+        vCoRoutineSchedule();
+    }
+ }
+ 
+ * \defgroup vCoRoutineSchedule vCoRoutineSchedule + * \ingroup Tasks + */ +void vCoRoutineSchedule( void ); + +/** + * croutine. h + *
+ crSTART( CoRoutineHandle_t xHandle );
+ * + * This macro MUST always be called at the start of a co-routine function. + * + * Example usage: +
+ // Co-routine to be created.
+ void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ {
+ // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ static int32_t ulAVariable;
+
+     // Must start every co-routine with a call to crSTART();
+     crSTART( xHandle );
+
+     for( ;; )
+     {
+          // Co-routine functionality goes here.
+     }
+
+     // Must end every co-routine with a call to crEND();
+     crEND();
+ }
+ * \defgroup crSTART crSTART + * \ingroup Tasks + */ +#define crSTART( pxCRCB ) switch( ( ( CRCB_t * )( pxCRCB ) )->uxState ) { case 0: + +/** + * croutine. h + *
+ crEND();
+ * + * This macro MUST always be called at the end of a co-routine function. + * + * Example usage: +
+ // Co-routine to be created.
+ void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ {
+ // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ static int32_t ulAVariable;
+
+     // Must start every co-routine with a call to crSTART();
+     crSTART( xHandle );
+
+     for( ;; )
+     {
+          // Co-routine functionality goes here.
+     }
+
+     // Must end every co-routine with a call to crEND();
+     crEND();
+ }
+ * \defgroup crSTART crSTART + * \ingroup Tasks + */ +#define crEND() } + +/* + * These macros are intended for internal use by the co-routine implementation + * only. The macros should not be used directly by application writers. + */ +#define crSET_STATE0( xHandle ) ( ( CRCB_t * )( xHandle ) )->uxState = (__LINE__ * 2); return; case (__LINE__ * 2): +#define crSET_STATE1( xHandle ) ( ( CRCB_t * )( xHandle ) )->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1): + +/** + * croutine. h + *
+ crDELAY( CoRoutineHandle_t xHandle, TickType_t xTicksToDelay );
+ * + * Delay a co-routine for a fixed period of time. + * + * crDELAY can only be called from the co-routine function itself - not + * from within a function called by the co-routine function. This is because + * co-routines do not maintain their own stack. + * + * @param xHandle The handle of the co-routine to delay. This is the xHandle + * parameter of the co-routine function. + * + * @param xTickToDelay The number of ticks that the co-routine should delay + * for. The actual amount of time this equates to is defined by + * configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant portTICK_PERIOD_MS + * can be used to convert ticks to milliseconds. + * + * Example usage: +
+ // Co-routine to be created.
+ void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ {
+ // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ // This may not be necessary for const variables.
+ // We are to delay for 200ms.
+ static const xTickType xDelayTime = 200 / portTICK_PERIOD_MS;
+
+     // Must start every co-routine with a call to crSTART();
+     crSTART( xHandle );
+
+     for( ;; )
+     {
+        // Delay for 200ms.
+        crDELAY( xHandle, xDelayTime );
+
+        // Do something here.
+     }
+
+     // Must end every co-routine with a call to crEND();
+     crEND();
+ }
+ * \defgroup crDELAY crDELAY + * \ingroup Tasks + */ +#define crDELAY( xHandle, xTicksToDelay ) \ + if( ( xTicksToDelay ) > 0 ) \ + { \ + vCoRoutineAddToDelayedList( ( xTicksToDelay ), NULL ); \ + } \ + crSET_STATE0( ( xHandle ) ); + +/** + *
+ crQUEUE_SEND(
+                  CoRoutineHandle_t xHandle,
+                  QueueHandle_t pxQueue,
+                  void *pvItemToQueue,
+                  TickType_t xTicksToWait,
+                  BaseType_t *pxResult
+             )
+ * + * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine + * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. + * + * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas + * xQueueSend() and xQueueReceive() can only be used from tasks. + * + * crQUEUE_SEND can only be called from the co-routine function itself - not + * from within a function called by the co-routine function. This is because + * co-routines do not maintain their own stack. + * + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and + * co-routines. + * + * @param xHandle The handle of the calling co-routine. This is the xHandle + * parameter of the co-routine function. + * + * @param pxQueue The handle of the queue on which the data will be posted. + * The handle is obtained as the return value when the queue is created using + * the xQueueCreate() API function. + * + * @param pvItemToQueue A pointer to the data being posted onto the queue. + * The number of bytes of each queued item is specified when the queue is + * created. This number of bytes is copied from pvItemToQueue into the queue + * itself. + * + * @param xTickToDelay The number of ticks that the co-routine should block + * to wait for space to become available on the queue, should space not be + * available immediately. The actual amount of time this equates to is defined + * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant + * portTICK_PERIOD_MS can be used to convert ticks to milliseconds (see example + * below). + * + * @param pxResult The variable pointed to by pxResult will be set to pdPASS if + * data was successfully posted onto the queue, otherwise it will be set to an + * error defined within ProjDefs.h. + * + * Example usage: +
+ // Co-routine function that blocks for a fixed period then posts a number onto
+ // a queue.
+ static void prvCoRoutineFlashTask( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ {
+ // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ static BaseType_t xNumberToPost = 0;
+ static BaseType_t xResult;
+
+    // Co-routines must begin with a call to crSTART().
+    crSTART( xHandle );
+
+    for( ;; )
+    {
+        // This assumes the queue has already been created.
+        crQUEUE_SEND( xHandle, xCoRoutineQueue, &xNumberToPost, NO_DELAY, &xResult );
+
+        if( xResult != pdPASS )
+        {
+            // The message was not posted!
+        }
+
+        // Increment the number to be posted onto the queue.
+        xNumberToPost++;
+
+        // Delay for 100 ticks.
+        crDELAY( xHandle, 100 );
+    }
+
+    // Co-routines must end with a call to crEND().
+    crEND();
+ }
+ * \defgroup crQUEUE_SEND crQUEUE_SEND + * \ingroup Tasks + */ +#define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \ +{ \ + *( pxResult ) = xQueueCRSend( ( pxQueue) , ( pvItemToQueue) , ( xTicksToWait ) ); \ + if( *( pxResult ) == errQUEUE_BLOCKED ) \ + { \ + crSET_STATE0( ( xHandle ) ); \ + *pxResult = xQueueCRSend( ( pxQueue ), ( pvItemToQueue ), 0 ); \ + } \ + if( *pxResult == errQUEUE_YIELD ) \ + { \ + crSET_STATE1( ( xHandle ) ); \ + *pxResult = pdPASS; \ + } \ +} + +/** + * croutine. h + *
+  crQUEUE_RECEIVE(
+                     CoRoutineHandle_t xHandle,
+                     QueueHandle_t pxQueue,
+                     void *pvBuffer,
+                     TickType_t xTicksToWait,
+                     BaseType_t *pxResult
+                 )
+ * + * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine + * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. + * + * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas + * xQueueSend() and xQueueReceive() can only be used from tasks. + * + * crQUEUE_RECEIVE can only be called from the co-routine function itself - not + * from within a function called by the co-routine function. This is because + * co-routines do not maintain their own stack. + * + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and + * co-routines. + * + * @param xHandle The handle of the calling co-routine. This is the xHandle + * parameter of the co-routine function. + * + * @param pxQueue The handle of the queue from which the data will be received. + * The handle is obtained as the return value when the queue is created using + * the xQueueCreate() API function. + * + * @param pvBuffer The buffer into which the received item is to be copied. + * The number of bytes of each queued item is specified when the queue is + * created. This number of bytes is copied into pvBuffer. + * + * @param xTickToDelay The number of ticks that the co-routine should block + * to wait for data to become available from the queue, should data not be + * available immediately. The actual amount of time this equates to is defined + * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant + * portTICK_PERIOD_MS can be used to convert ticks to milliseconds (see the + * crQUEUE_SEND example). + * + * @param pxResult The variable pointed to by pxResult will be set to pdPASS if + * data was successfully retrieved from the queue, otherwise it will be set to + * an error code as defined within ProjDefs.h. + * + * Example usage: +
+ // A co-routine receives the number of an LED to flash from a queue.  It
+ // blocks on the queue until the number is received.
+ static void prvCoRoutineFlashWorkTask( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ {
+ // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ static BaseType_t xResult;
+ static UBaseType_t uxLEDToFlash;
+
+    // All co-routines must start with a call to crSTART().
+    crSTART( xHandle );
+
+    for( ;; )
+    {
+        // Wait for data to become available on the queue.
+        crQUEUE_RECEIVE( xHandle, xCoRoutineQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
+
+        if( xResult == pdPASS )
+        {
+            // We received the LED to flash - flash it!
+            vParTestToggleLED( uxLEDToFlash );
+        }
+    }
+
+    crEND();
+ }
+ * \defgroup crQUEUE_RECEIVE crQUEUE_RECEIVE + * \ingroup Tasks + */ +#define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \ +{ \ + *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), ( xTicksToWait ) ); \ + if( *( pxResult ) == errQUEUE_BLOCKED ) \ + { \ + crSET_STATE0( ( xHandle ) ); \ + *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), 0 ); \ + } \ + if( *( pxResult ) == errQUEUE_YIELD ) \ + { \ + crSET_STATE1( ( xHandle ) ); \ + *( pxResult ) = pdPASS; \ + } \ +} + +/** + * croutine. h + *
+  crQUEUE_SEND_FROM_ISR(
+                            QueueHandle_t pxQueue,
+                            void *pvItemToQueue,
+                            BaseType_t xCoRoutinePreviouslyWoken
+                       )
+ * + * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the + * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() + * functions used by tasks. + * + * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to + * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and + * xQueueReceiveFromISR() can only be used to pass data between a task and and + * ISR. + * + * crQUEUE_SEND_FROM_ISR can only be called from an ISR to send data to a queue + * that is being used from within a co-routine. + * + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and + * co-routines. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param xCoRoutinePreviouslyWoken This is included so an ISR can post onto + * the same queue multiple times from a single interrupt. The first call + * should always pass in pdFALSE. Subsequent calls should pass in + * the value returned from the previous call. + * + * @return pdTRUE if a co-routine was woken by posting onto the queue. This is + * used by the ISR to determine if a context switch may be required following + * the ISR. + * + * Example usage: +
+ // A co-routine that blocks on a queue waiting for characters to be received.
+ static void vReceivingCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ {
+ char cRxedChar;
+ BaseType_t xResult;
+
+     // All co-routines must start with a call to crSTART().
+     crSTART( xHandle );
+
+     for( ;; )
+     {
+         // Wait for data to become available on the queue.  This assumes the
+         // queue xCommsRxQueue has already been created!
+         crQUEUE_RECEIVE( xHandle, xCommsRxQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
+
+         // Was a character received?
+         if( xResult == pdPASS )
+         {
+             // Process the character here.
+         }
+     }
+
+     // All co-routines must end with a call to crEND().
+     crEND();
+ }
+
+ // An ISR that uses a queue to send characters received on a serial port to
+ // a co-routine.
+ void vUART_ISR( void )
+ {
+ char cRxedChar;
+ BaseType_t xCRWokenByPost = pdFALSE;
+
+     // We loop around reading characters until there are none left in the UART.
+     while( UART_RX_REG_NOT_EMPTY() )
+     {
+         // Obtain the character from the UART.
+         cRxedChar = UART_RX_REG;
+
+         // Post the character onto a queue.  xCRWokenByPost will be pdFALSE
+         // the first time around the loop.  If the post causes a co-routine
+         // to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE.
+         // In this manner we can ensure that if more than one co-routine is
+         // blocked on the queue only one is woken by this ISR no matter how
+         // many characters are posted to the queue.
+         xCRWokenByPost = crQUEUE_SEND_FROM_ISR( xCommsRxQueue, &cRxedChar, xCRWokenByPost );
+     }
+ }
+ * \defgroup crQUEUE_SEND_FROM_ISR crQUEUE_SEND_FROM_ISR + * \ingroup Tasks + */ +#define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) xQueueCRSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( xCoRoutinePreviouslyWoken ) ) + + +/** + * croutine. h + *
+  crQUEUE_SEND_FROM_ISR(
+                            QueueHandle_t pxQueue,
+                            void *pvBuffer,
+                            BaseType_t * pxCoRoutineWoken
+                       )
+ * + * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the + * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() + * functions used by tasks. + * + * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to + * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and + * xQueueReceiveFromISR() can only be used to pass data between a task and and + * ISR. + * + * crQUEUE_RECEIVE_FROM_ISR can only be called from an ISR to receive data + * from a queue that is being used from within a co-routine (a co-routine + * posted to the queue). + * + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and + * co-routines. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvBuffer A pointer to a buffer into which the received item will be + * placed. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from the queue into + * pvBuffer. + * + * @param pxCoRoutineWoken A co-routine may be blocked waiting for space to become + * available on the queue. If crQUEUE_RECEIVE_FROM_ISR causes such a + * co-routine to unblock *pxCoRoutineWoken will get set to pdTRUE, otherwise + * *pxCoRoutineWoken will remain unchanged. + * + * @return pdTRUE an item was successfully received from the queue, otherwise + * pdFALSE. + * + * Example usage: +
+ // A co-routine that posts a character to a queue then blocks for a fixed
+ // period.  The character is incremented each time.
+ static void vSendingCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ {
+ // cChar holds its value while this co-routine is blocked and must therefore
+ // be declared static.
+ static char cCharToTx = 'a';
+ BaseType_t xResult;
+
+     // All co-routines must start with a call to crSTART().
+     crSTART( xHandle );
+
+     for( ;; )
+     {
+         // Send the next character to the queue.
+         crQUEUE_SEND( xHandle, xCoRoutineQueue, &cCharToTx, NO_DELAY, &xResult );
+
+         if( xResult == pdPASS )
+         {
+             // The character was successfully posted to the queue.
+         }
+		 else
+		 {
+			// Could not post the character to the queue.
+		 }
+
+         // Enable the UART Tx interrupt to cause an interrupt in this
+		 // hypothetical UART.  The interrupt will obtain the character
+		 // from the queue and send it.
+		 ENABLE_RX_INTERRUPT();
+
+		 // Increment to the next character then block for a fixed period.
+		 // cCharToTx will maintain its value across the delay as it is
+		 // declared static.
+		 cCharToTx++;
+		 if( cCharToTx > 'x' )
+		 {
+			cCharToTx = 'a';
+		 }
+		 crDELAY( 100 );
+     }
+
+     // All co-routines must end with a call to crEND().
+     crEND();
+ }
+
+ // An ISR that uses a queue to receive characters to send on a UART.
+ void vUART_ISR( void )
+ {
+ char cCharToTx;
+ BaseType_t xCRWokenByPost = pdFALSE;
+
+     while( UART_TX_REG_EMPTY() )
+     {
+         // Are there any characters in the queue waiting to be sent?
+		 // xCRWokenByPost will automatically be set to pdTRUE if a co-routine
+		 // is woken by the post - ensuring that only a single co-routine is
+		 // woken no matter how many times we go around this loop.
+         if( crQUEUE_RECEIVE_FROM_ISR( pxQueue, &cCharToTx, &xCRWokenByPost ) )
+		 {
+			 SEND_CHARACTER( cCharToTx );
+		 }
+     }
+ }
+ * \defgroup crQUEUE_RECEIVE_FROM_ISR crQUEUE_RECEIVE_FROM_ISR + * \ingroup Tasks + */ +#define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) xQueueCRReceiveFromISR( ( pxQueue ), ( pvBuffer ), ( pxCoRoutineWoken ) ) + +/* + * This function is intended for internal use by the co-routine macros only. + * The macro nature of the co-routine implementation requires that the + * prototype appears here. The function should not be used by application + * writers. + * + * Removes the current co-routine from its ready list and places it in the + * appropriate delayed list. + */ +void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList ); + +/* + * This function is intended for internal use by the queue implementation only. + * The function should not be used by application writers. + * + * Removes the highest priority co-routine from the event list and places it in + * the pending ready list. + */ +BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList ); + +#ifdef __cplusplus +} +#endif + +#endif /* CO_ROUTINE_H */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h new file mode 100644 index 0000000..fb4910f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h @@ -0,0 +1,279 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef DEPRECATED_DEFINITIONS_H +#define DEPRECATED_DEFINITIONS_H + + +/* Each FreeRTOS port has a unique portmacro.h header file. Originally a +pre-processor definition was used to ensure the pre-processor found the correct +portmacro.h file for the port being used. That scheme was deprecated in favour +of setting the compiler's include path such that it found the correct +portmacro.h file - removing the need for the constant and allowing the +portmacro.h file to be located anywhere in relation to the port being used. The +definitions below remain in the code for backward compatibility only. New +projects should not use them. */ + +#ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT + #include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h" + typedef void ( __interrupt __far *pxISR )(); +#endif + +#ifdef OPEN_WATCOM_FLASH_LITE_186_PORT + #include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h" + typedef void ( __interrupt __far *pxISR )(); +#endif + +#ifdef GCC_MEGA_AVR + #include "../portable/GCC/ATMega323/portmacro.h" +#endif + +#ifdef IAR_MEGA_AVR + #include "../portable/IAR/ATMega323/portmacro.h" +#endif + +#ifdef MPLAB_PIC24_PORT + #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h" +#endif + +#ifdef MPLAB_DSPIC_PORT + #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h" +#endif + +#ifdef MPLAB_PIC18F_PORT + #include "../../Source/portable/MPLAB/PIC18F/portmacro.h" +#endif + +#ifdef MPLAB_PIC32MX_PORT + #include "../../Source/portable/MPLAB/PIC32MX/portmacro.h" +#endif + +#ifdef _FEDPICC + #include "libFreeRTOS/Include/portmacro.h" +#endif + +#ifdef SDCC_CYGNAL + #include "../../Source/portable/SDCC/Cygnal/portmacro.h" +#endif + +#ifdef GCC_ARM7 + #include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h" +#endif + +#ifdef GCC_ARM7_ECLIPSE + #include "portmacro.h" +#endif + +#ifdef ROWLEY_LPC23xx + #include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h" +#endif + +#ifdef IAR_MSP430 + #include "..\..\Source\portable\IAR\MSP430\portmacro.h" +#endif + +#ifdef GCC_MSP430 + #include "../../Source/portable/GCC/MSP430F449/portmacro.h" +#endif + +#ifdef ROWLEY_MSP430 + #include "../../Source/portable/Rowley/MSP430F449/portmacro.h" +#endif + +#ifdef ARM7_LPC21xx_KEIL_RVDS + #include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h" +#endif + +#ifdef SAM7_GCC + #include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h" +#endif + +#ifdef SAM7_IAR + #include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h" +#endif + +#ifdef SAM9XE_IAR + #include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h" +#endif + +#ifdef LPC2000_IAR + #include "..\..\Source\portable\IAR\LPC2000\portmacro.h" +#endif + +#ifdef STR71X_IAR + #include "..\..\Source\portable\IAR\STR71x\portmacro.h" +#endif + +#ifdef STR75X_IAR + #include "..\..\Source\portable\IAR\STR75x\portmacro.h" +#endif + +#ifdef STR75X_GCC + #include "..\..\Source\portable\GCC\STR75x\portmacro.h" +#endif + +#ifdef STR91X_IAR + #include "..\..\Source\portable\IAR\STR91x\portmacro.h" +#endif + +#ifdef GCC_H8S + #include "../../Source/portable/GCC/H8S2329/portmacro.h" +#endif + +#ifdef GCC_AT91FR40008 + #include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h" +#endif + +#ifdef RVDS_ARMCM3_LM3S102 + #include "../../Source/portable/RVDS/ARM_CM3/portmacro.h" +#endif + +#ifdef GCC_ARMCM3_LM3S102 + #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" +#endif + +#ifdef GCC_ARMCM3 + #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" +#endif + +#ifdef IAR_ARM_CM3 + #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" +#endif + +#ifdef IAR_ARMCM3_LM + #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" +#endif + +#ifdef HCS12_CODE_WARRIOR + #include "../../Source/portable/CodeWarrior/HCS12/portmacro.h" +#endif + +#ifdef MICROBLAZE_GCC + #include "../../Source/portable/GCC/MicroBlaze/portmacro.h" +#endif + +#ifdef TERN_EE + #include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h" +#endif + +#ifdef GCC_HCS12 + #include "../../Source/portable/GCC/HCS12/portmacro.h" +#endif + +#ifdef GCC_MCF5235 + #include "../../Source/portable/GCC/MCF5235/portmacro.h" +#endif + +#ifdef COLDFIRE_V2_GCC + #include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h" +#endif + +#ifdef COLDFIRE_V2_CODEWARRIOR + #include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h" +#endif + +#ifdef GCC_PPC405 + #include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h" +#endif + +#ifdef GCC_PPC440 + #include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h" +#endif + +#ifdef _16FX_SOFTUNE + #include "..\..\Source\portable\Softune\MB96340\portmacro.h" +#endif + +#ifdef BCC_INDUSTRIAL_PC_PORT + /* A short file name has to be used in place of the normal + FreeRTOSConfig.h when using the Borland compiler. */ + #include "frconfig.h" + #include "..\portable\BCC\16BitDOS\PC\prtmacro.h" + typedef void ( __interrupt __far *pxISR )(); +#endif + +#ifdef BCC_FLASH_LITE_186_PORT + /* A short file name has to be used in place of the normal + FreeRTOSConfig.h when using the Borland compiler. */ + #include "frconfig.h" + #include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h" + typedef void ( __interrupt __far *pxISR )(); +#endif + +#ifdef __GNUC__ + #ifdef __AVR32_AVR32A__ + #include "portmacro.h" + #endif +#endif + +#ifdef __ICCAVR32__ + #ifdef __CORE__ + #if __CORE__ == __AVR32A__ + #include "portmacro.h" + #endif + #endif +#endif + +#ifdef __91467D + #include "portmacro.h" +#endif + +#ifdef __96340 + #include "portmacro.h" +#endif + + +#ifdef __IAR_V850ES_Fx3__ + #include "../../Source/portable/IAR/V850ES/portmacro.h" +#endif + +#ifdef __IAR_V850ES_Jx3__ + #include "../../Source/portable/IAR/V850ES/portmacro.h" +#endif + +#ifdef __IAR_V850ES_Jx3_L__ + #include "../../Source/portable/IAR/V850ES/portmacro.h" +#endif + +#ifdef __IAR_V850ES_Jx2__ + #include "../../Source/portable/IAR/V850ES/portmacro.h" +#endif + +#ifdef __IAR_V850ES_Hx2__ + #include "../../Source/portable/IAR/V850ES/portmacro.h" +#endif + +#ifdef __IAR_78K0R_Kx3__ + #include "../../Source/portable/IAR/78K0R/portmacro.h" +#endif + +#ifdef __IAR_78K0R_Kx3L__ + #include "../../Source/portable/IAR/78K0R/portmacro.h" +#endif + +#endif /* DEPRECATED_DEFINITIONS_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/event_groups.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/event_groups.h new file mode 100644 index 0000000..0c1582b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/event_groups.h @@ -0,0 +1,756 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef EVENT_GROUPS_H +#define EVENT_GROUPS_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h" must appear in source files before "include event_groups.h" +#endif + +/* FreeRTOS includes. */ +#include "timers.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An event group is a collection of bits to which an application can assign a + * meaning. For example, an application may create an event group to convey + * the status of various CAN bus related events in which bit 0 might mean "A CAN + * message has been received and is ready for processing", bit 1 might mean "The + * application has queued a message that is ready for sending onto the CAN + * network", and bit 2 might mean "It is time to send a SYNC message onto the + * CAN network" etc. A task can then test the bit values to see which events + * are active, and optionally enter the Blocked state to wait for a specified + * bit or a group of specified bits to be active. To continue the CAN bus + * example, a CAN controlling task can enter the Blocked state (and therefore + * not consume any processing time) until either bit 0, bit 1 or bit 2 are + * active, at which time the bit that was actually active would inform the task + * which action it had to take (process a received message, send a message, or + * send a SYNC). + * + * The event groups implementation contains intelligence to avoid race + * conditions that would otherwise occur were an application to use a simple + * variable for the same purpose. This is particularly important with respect + * to when a bit within an event group is to be cleared, and when bits have to + * be set and then tested atomically - as is the case where event groups are + * used to create a synchronisation point between multiple tasks (a + * 'rendezvous'). + * + * \defgroup EventGroup + */ + + + +/** + * event_groups.h + * + * Type by which event groups are referenced. For example, a call to + * xEventGroupCreate() returns an EventGroupHandle_t variable that can then + * be used as a parameter to other event group functions. + * + * \defgroup EventGroupHandle_t EventGroupHandle_t + * \ingroup EventGroup + */ +typedef void * EventGroupHandle_t; + +/* + * The type that holds event bits always matches TickType_t - therefore the + * number of bits it holds is set by configUSE_16_BIT_TICKS (16 bits if set to 1, + * 32 bits if set to 0. + * + * \defgroup EventBits_t EventBits_t + * \ingroup EventGroup + */ +typedef TickType_t EventBits_t; + +/** + * event_groups.h + *
+ EventGroupHandle_t xEventGroupCreate( void );
+ 
+ * + * Create a new event group. + * + * Internally, within the FreeRTOS implementation, event groups use a [small] + * block of memory, in which the event group's structure is stored. If an event + * groups is created using xEventGropuCreate() then the required memory is + * automatically dynamically allocated inside the xEventGroupCreate() function. + * (see http://www.freertos.org/a00111.html). If an event group is created + * using xEventGropuCreateStatic() then the application writer must instead + * provide the memory that will get used by the event group. + * xEventGroupCreateStatic() therefore allows an event group to be created + * without using any dynamic memory allocation. + * + * Although event groups are not related to ticks, for internal implementation + * reasons the number of bits available for use in an event group is dependent + * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If + * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit + * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has + * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store + * event bits within an event group. + * + * @return If the event group was created then a handle to the event group is + * returned. If there was insufficient FreeRTOS heap available to create the + * event group then NULL is returned. See http://www.freertos.org/a00111.html + * + * Example usage: +
+    // Declare a variable to hold the created event group.
+    EventGroupHandle_t xCreatedEventGroup;
+
+    // Attempt to create the event group.
+    xCreatedEventGroup = xEventGroupCreate();
+
+    // Was the event group created successfully?
+    if( xCreatedEventGroup == NULL )
+    {
+        // The event group was not created because there was insufficient
+        // FreeRTOS heap available.
+    }
+    else
+    {
+        // The event group was created.
+    }
+   
+ * \defgroup xEventGroupCreate xEventGroupCreate + * \ingroup EventGroup + */ +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + EventGroupHandle_t xEventGroupCreate( void ) PRIVILEGED_FUNCTION; +#endif + +/** + * event_groups.h + *
+ EventGroupHandle_t xEventGroupCreateStatic( EventGroupHandle_t * pxEventGroupBuffer );
+ 
+ * + * Create a new event group. + * + * Internally, within the FreeRTOS implementation, event groups use a [small] + * block of memory, in which the event group's structure is stored. If an event + * groups is created using xEventGropuCreate() then the required memory is + * automatically dynamically allocated inside the xEventGroupCreate() function. + * (see http://www.freertos.org/a00111.html). If an event group is created + * using xEventGropuCreateStatic() then the application writer must instead + * provide the memory that will get used by the event group. + * xEventGroupCreateStatic() therefore allows an event group to be created + * without using any dynamic memory allocation. + * + * Although event groups are not related to ticks, for internal implementation + * reasons the number of bits available for use in an event group is dependent + * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If + * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit + * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has + * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store + * event bits within an event group. + * + * @param pxEventGroupBuffer pxEventGroupBuffer must point to a variable of type + * StaticEventGroup_t, which will be then be used to hold the event group's data + * structures, removing the need for the memory to be allocated dynamically. + * + * @return If the event group was created then a handle to the event group is + * returned. If pxEventGroupBuffer was NULL then NULL is returned. + * + * Example usage: +
+    // StaticEventGroup_t is a publicly accessible structure that has the same
+    // size and alignment requirements as the real event group structure.  It is
+    // provided as a mechanism for applications to know the size of the event
+    // group (which is dependent on the architecture and configuration file
+    // settings) without breaking the strict data hiding policy by exposing the
+    // real event group internals.  This StaticEventGroup_t variable is passed
+    // into the xSemaphoreCreateEventGroupStatic() function and is used to store
+    // the event group's data structures
+    StaticEventGroup_t xEventGroupBuffer;
+
+    // Create the event group without dynamically allocating any memory.
+    xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
+   
+ */ +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer ) PRIVILEGED_FUNCTION; +#endif + +/** + * event_groups.h + *
+    EventBits_t xEventGroupWaitBits(     EventGroupHandle_t xEventGroup,
+                                        const EventBits_t uxBitsToWaitFor,
+                                        const BaseType_t xClearOnExit,
+                                        const BaseType_t xWaitForAllBits,
+                                        const TickType_t xTicksToWait );
+ 
+ * + * [Potentially] block to wait for one or more bits to be set within a + * previously created event group. + * + * This function cannot be called from an interrupt. + * + * @param xEventGroup The event group in which the bits are being tested. The + * event group must have previously been created using a call to + * xEventGroupCreate(). + * + * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test + * inside the event group. For example, to wait for bit 0 and/or bit 2 set + * uxBitsToWaitFor to 0x05. To wait for bits 0 and/or bit 1 and/or bit 2 set + * uxBitsToWaitFor to 0x07. Etc. + * + * @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within + * uxBitsToWaitFor that are set within the event group will be cleared before + * xEventGroupWaitBits() returns if the wait condition was met (if the function + * returns for a reason other than a timeout). If xClearOnExit is set to + * pdFALSE then the bits set in the event group are not altered when the call to + * xEventGroupWaitBits() returns. + * + * @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then + * xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor + * are set or the specified block time expires. If xWaitForAllBits is set to + * pdFALSE then xEventGroupWaitBits() will return when any one of the bits set + * in uxBitsToWaitFor is set or the specified block time expires. The block + * time is specified by the xTicksToWait parameter. + * + * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait + * for one/all (depending on the xWaitForAllBits value) of the bits specified by + * uxBitsToWaitFor to become set. + * + * @return The value of the event group at the time either the bits being waited + * for became set, or the block time expired. Test the return value to know + * which bits were set. If xEventGroupWaitBits() returned because its timeout + * expired then not all the bits being waited for will be set. If + * xEventGroupWaitBits() returned because the bits it was waiting for were set + * then the returned value is the event group value before any bits were + * automatically cleared in the case that xClearOnExit parameter was set to + * pdTRUE. + * + * Example usage: +
+   #define BIT_0    ( 1 << 0 )
+   #define BIT_4    ( 1 << 4 )
+
+   void aFunction( EventGroupHandle_t xEventGroup )
+   {
+   EventBits_t uxBits;
+   const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
+
+        // Wait a maximum of 100ms for either bit 0 or bit 4 to be set within
+        // the event group.  Clear the bits before exiting.
+        uxBits = xEventGroupWaitBits(
+                    xEventGroup,    // The event group being tested.
+                    BIT_0 | BIT_4,    // The bits within the event group to wait for.
+                    pdTRUE,            // BIT_0 and BIT_4 should be cleared before returning.
+                    pdFALSE,        // Don't wait for both bits, either bit will do.
+                    xTicksToWait );    // Wait a maximum of 100ms for either bit to be set.
+
+        if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
+        {
+            // xEventGroupWaitBits() returned because both bits were set.
+        }
+        else if( ( uxBits & BIT_0 ) != 0 )
+        {
+            // xEventGroupWaitBits() returned because just BIT_0 was set.
+        }
+        else if( ( uxBits & BIT_4 ) != 0 )
+        {
+            // xEventGroupWaitBits() returned because just BIT_4 was set.
+        }
+        else
+        {
+            // xEventGroupWaitBits() returned because xTicksToWait ticks passed
+            // without either BIT_0 or BIT_4 becoming set.
+        }
+   }
+   
+ * \defgroup xEventGroupWaitBits xEventGroupWaitBits + * \ingroup EventGroup + */ +EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * event_groups.h + *
+    EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear );
+ 
+ * + * Clear bits within an event group. This function cannot be called from an + * interrupt. + * + * @param xEventGroup The event group in which the bits are to be cleared. + * + * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear + * in the event group. For example, to clear bit 3 only, set uxBitsToClear to + * 0x08. To clear bit 3 and bit 0 set uxBitsToClear to 0x09. + * + * @return The value of the event group before the specified bits were cleared. + * + * Example usage: +
+   #define BIT_0    ( 1 << 0 )
+   #define BIT_4    ( 1 << 4 )
+
+   void aFunction( EventGroupHandle_t xEventGroup )
+   {
+   EventBits_t uxBits;
+
+        // Clear bit 0 and bit 4 in xEventGroup.
+        uxBits = xEventGroupClearBits(
+                                xEventGroup,    // The event group being updated.
+                                BIT_0 | BIT_4 );// The bits being cleared.
+
+        if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
+        {
+            // Both bit 0 and bit 4 were set before xEventGroupClearBits() was
+            // called.  Both will now be clear (not set).
+        }
+        else if( ( uxBits & BIT_0 ) != 0 )
+        {
+            // Bit 0 was set before xEventGroupClearBits() was called.  It will
+            // now be clear.
+        }
+        else if( ( uxBits & BIT_4 ) != 0 )
+        {
+            // Bit 4 was set before xEventGroupClearBits() was called.  It will
+            // now be clear.
+        }
+        else
+        {
+            // Neither bit 0 nor bit 4 were set in the first place.
+        }
+   }
+   
+ * \defgroup xEventGroupClearBits xEventGroupClearBits + * \ingroup EventGroup + */ +EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION; + +/** + * event_groups.h + *
+    BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
+ 
+ * + * A version of xEventGroupClearBits() that can be called from an interrupt. + * + * Setting bits in an event group is not a deterministic operation because there + * are an unknown number of tasks that may be waiting for the bit or bits being + * set. FreeRTOS does not allow nondeterministic operations to be performed + * while interrupts are disabled, so protects event groups that are accessed + * from tasks by suspending the scheduler rather than disabling interrupts. As + * a result event groups cannot be accessed directly from an interrupt service + * routine. Therefore xEventGroupClearBitsFromISR() sends a message to the + * timer task to have the clear operation performed in the context of the timer + * task. + * + * @param xEventGroup The event group in which the bits are to be cleared. + * + * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear. + * For example, to clear bit 3 only, set uxBitsToClear to 0x08. To clear bit 3 + * and bit 0 set uxBitsToClear to 0x09. + * + * @return If the request to execute the function was posted successfully then + * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned + * if the timer service queue was full. + * + * Example usage: +
+   #define BIT_0    ( 1 << 0 )
+   #define BIT_4    ( 1 << 4 )
+
+   // An event group which it is assumed has already been created by a call to
+   // xEventGroupCreate().
+   EventGroupHandle_t xEventGroup;
+
+   void anInterruptHandler( void )
+   {
+        // Clear bit 0 and bit 4 in xEventGroup.
+        xResult = xEventGroupClearBitsFromISR(
+                            xEventGroup,     // The event group being updated.
+                            BIT_0 | BIT_4 ); // The bits being set.
+
+        if( xResult == pdPASS )
+        {
+            // The message was posted successfully.
+        }
+  }
+   
+ * \defgroup xEventGroupClearBitsFromISR xEventGroupClearBitsFromISR + * \ingroup EventGroup + */ +#if( configUSE_TRACE_FACILITY == 1 ) + BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION; +#else + #define xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear ) xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ) +#endif + +/** + * event_groups.h + *
+    EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
+ 
+ * + * Set bits within an event group. + * This function cannot be called from an interrupt. xEventGroupSetBitsFromISR() + * is a version that can be called from an interrupt. + * + * Setting bits in an event group will automatically unblock tasks that are + * blocked waiting for the bits. + * + * @param xEventGroup The event group in which the bits are to be set. + * + * @param uxBitsToSet A bitwise value that indicates the bit or bits to set. + * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3 + * and bit 0 set uxBitsToSet to 0x09. + * + * @return The value of the event group at the time the call to + * xEventGroupSetBits() returns. There are two reasons why the returned value + * might have the bits specified by the uxBitsToSet parameter cleared. First, + * if setting a bit results in a task that was waiting for the bit leaving the + * blocked state then it is possible the bit will be cleared automatically + * (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any + * unblocked (or otherwise Ready state) task that has a priority above that of + * the task that called xEventGroupSetBits() will execute and may change the + * event group value before the call to xEventGroupSetBits() returns. + * + * Example usage: +
+   #define BIT_0    ( 1 << 0 )
+   #define BIT_4    ( 1 << 4 )
+
+   void aFunction( EventGroupHandle_t xEventGroup )
+   {
+   EventBits_t uxBits;
+
+        // Set bit 0 and bit 4 in xEventGroup.
+        uxBits = xEventGroupSetBits(
+                            xEventGroup,    // The event group being updated.
+                            BIT_0 | BIT_4 );// The bits being set.
+
+        if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
+        {
+            // Both bit 0 and bit 4 remained set when the function returned.
+        }
+        else if( ( uxBits & BIT_0 ) != 0 )
+        {
+            // Bit 0 remained set when the function returned, but bit 4 was
+            // cleared.  It might be that bit 4 was cleared automatically as a
+            // task that was waiting for bit 4 was removed from the Blocked
+            // state.
+        }
+        else if( ( uxBits & BIT_4 ) != 0 )
+        {
+            // Bit 4 remained set when the function returned, but bit 0 was
+            // cleared.  It might be that bit 0 was cleared automatically as a
+            // task that was waiting for bit 0 was removed from the Blocked
+            // state.
+        }
+        else
+        {
+            // Neither bit 0 nor bit 4 remained set.  It might be that a task
+            // was waiting for both of the bits to be set, and the bits were
+            // cleared as the task left the Blocked state.
+        }
+   }
+   
+ * \defgroup xEventGroupSetBits xEventGroupSetBits + * \ingroup EventGroup + */ +EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION; + +/** + * event_groups.h + *
+    BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken );
+ 
+ * + * A version of xEventGroupSetBits() that can be called from an interrupt. + * + * Setting bits in an event group is not a deterministic operation because there + * are an unknown number of tasks that may be waiting for the bit or bits being + * set. FreeRTOS does not allow nondeterministic operations to be performed in + * interrupts or from critical sections. Therefore xEventGroupSetBitsFromISR() + * sends a message to the timer task to have the set operation performed in the + * context of the timer task - where a scheduler lock is used in place of a + * critical section. + * + * @param xEventGroup The event group in which the bits are to be set. + * + * @param uxBitsToSet A bitwise value that indicates the bit or bits to set. + * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3 + * and bit 0 set uxBitsToSet to 0x09. + * + * @param pxHigherPriorityTaskWoken As mentioned above, calling this function + * will result in a message being sent to the timer daemon task. If the + * priority of the timer daemon task is higher than the priority of the + * currently running task (the task the interrupt interrupted) then + * *pxHigherPriorityTaskWoken will be set to pdTRUE by + * xEventGroupSetBitsFromISR(), indicating that a context switch should be + * requested before the interrupt exits. For that reason + * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the + * example code below. + * + * @return If the request to execute the function was posted successfully then + * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned + * if the timer service queue was full. + * + * Example usage: +
+   #define BIT_0    ( 1 << 0 )
+   #define BIT_4    ( 1 << 4 )
+
+   // An event group which it is assumed has already been created by a call to
+   // xEventGroupCreate().
+   EventGroupHandle_t xEventGroup;
+
+   void anInterruptHandler( void )
+   {
+   BaseType_t xHigherPriorityTaskWoken, xResult;
+
+        // xHigherPriorityTaskWoken must be initialised to pdFALSE.
+        xHigherPriorityTaskWoken = pdFALSE;
+
+        // Set bit 0 and bit 4 in xEventGroup.
+        xResult = xEventGroupSetBitsFromISR(
+                            xEventGroup,    // The event group being updated.
+                            BIT_0 | BIT_4   // The bits being set.
+                            &xHigherPriorityTaskWoken );
+
+        // Was the message posted successfully?
+        if( xResult == pdPASS )
+        {
+            // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
+            // switch should be requested.  The macro used is port specific and
+            // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
+            // refer to the documentation page for the port being used.
+            portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+        }
+  }
+   
+ * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR + * \ingroup EventGroup + */ +#if( configUSE_TRACE_FACILITY == 1 ) + BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; +#else + #define xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken ) xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ) +#endif + +/** + * event_groups.h + *
+    EventBits_t xEventGroupSync(    EventGroupHandle_t xEventGroup,
+                                    const EventBits_t uxBitsToSet,
+                                    const EventBits_t uxBitsToWaitFor,
+                                    TickType_t xTicksToWait );
+ 
+ * + * Atomically set bits within an event group, then wait for a combination of + * bits to be set within the same event group. This functionality is typically + * used to synchronise multiple tasks, where each task has to wait for the other + * tasks to reach a synchronisation point before proceeding. + * + * This function cannot be used from an interrupt. + * + * The function will return before its block time expires if the bits specified + * by the uxBitsToWait parameter are set, or become set within that time. In + * this case all the bits specified by uxBitsToWait will be automatically + * cleared before the function returns. + * + * @param xEventGroup The event group in which the bits are being tested. The + * event group must have previously been created using a call to + * xEventGroupCreate(). + * + * @param uxBitsToSet The bits to set in the event group before determining + * if, and possibly waiting for, all the bits specified by the uxBitsToWait + * parameter are set. + * + * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test + * inside the event group. For example, to wait for bit 0 and bit 2 set + * uxBitsToWaitFor to 0x05. To wait for bits 0 and bit 1 and bit 2 set + * uxBitsToWaitFor to 0x07. Etc. + * + * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait + * for all of the bits specified by uxBitsToWaitFor to become set. + * + * @return The value of the event group at the time either the bits being waited + * for became set, or the block time expired. Test the return value to know + * which bits were set. If xEventGroupSync() returned because its timeout + * expired then not all the bits being waited for will be set. If + * xEventGroupSync() returned because all the bits it was waiting for were + * set then the returned value is the event group value before any bits were + * automatically cleared. + * + * Example usage: +
+ // Bits used by the three tasks.
+ #define TASK_0_BIT        ( 1 << 0 )
+ #define TASK_1_BIT        ( 1 << 1 )
+ #define TASK_2_BIT        ( 1 << 2 )
+
+ #define ALL_SYNC_BITS ( TASK_0_BIT | TASK_1_BIT | TASK_2_BIT )
+
+ // Use an event group to synchronise three tasks.  It is assumed this event
+ // group has already been created elsewhere.
+ EventGroupHandle_t xEventBits;
+
+ void vTask0( void *pvParameters )
+ {
+ EventBits_t uxReturn;
+ TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
+
+     for( ;; )
+     {
+        // Perform task functionality here.
+
+        // Set bit 0 in the event flag to note this task has reached the
+        // sync point.  The other two tasks will set the other two bits defined
+        // by ALL_SYNC_BITS.  All three tasks have reached the synchronisation
+        // point when all the ALL_SYNC_BITS are set.  Wait a maximum of 100ms
+        // for this to happen.
+        uxReturn = xEventGroupSync( xEventBits, TASK_0_BIT, ALL_SYNC_BITS, xTicksToWait );
+
+        if( ( uxReturn & ALL_SYNC_BITS ) == ALL_SYNC_BITS )
+        {
+            // All three tasks reached the synchronisation point before the call
+            // to xEventGroupSync() timed out.
+        }
+    }
+ }
+
+ void vTask1( void *pvParameters )
+ {
+     for( ;; )
+     {
+        // Perform task functionality here.
+
+        // Set bit 1 in the event flag to note this task has reached the
+        // synchronisation point.  The other two tasks will set the other two
+        // bits defined by ALL_SYNC_BITS.  All three tasks have reached the
+        // synchronisation point when all the ALL_SYNC_BITS are set.  Wait
+        // indefinitely for this to happen.
+        xEventGroupSync( xEventBits, TASK_1_BIT, ALL_SYNC_BITS, portMAX_DELAY );
+
+        // xEventGroupSync() was called with an indefinite block time, so
+        // this task will only reach here if the syncrhonisation was made by all
+        // three tasks, so there is no need to test the return value.
+     }
+ }
+
+ void vTask2( void *pvParameters )
+ {
+     for( ;; )
+     {
+        // Perform task functionality here.
+
+        // Set bit 2 in the event flag to note this task has reached the
+        // synchronisation point.  The other two tasks will set the other two
+        // bits defined by ALL_SYNC_BITS.  All three tasks have reached the
+        // synchronisation point when all the ALL_SYNC_BITS are set.  Wait
+        // indefinitely for this to happen.
+        xEventGroupSync( xEventBits, TASK_2_BIT, ALL_SYNC_BITS, portMAX_DELAY );
+
+        // xEventGroupSync() was called with an indefinite block time, so
+        // this task will only reach here if the syncrhonisation was made by all
+        // three tasks, so there is no need to test the return value.
+    }
+ }
+
+ 
+ * \defgroup xEventGroupSync xEventGroupSync + * \ingroup EventGroup + */ +EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + + +/** + * event_groups.h + *
+    EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup );
+ 
+ * + * Returns the current value of the bits in an event group. This function + * cannot be used from an interrupt. + * + * @param xEventGroup The event group being queried. + * + * @return The event group bits at the time xEventGroupGetBits() was called. + * + * \defgroup xEventGroupGetBits xEventGroupGetBits + * \ingroup EventGroup + */ +#define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( xEventGroup, 0 ) + +/** + * event_groups.h + *
+    EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
+ 
+ * + * A version of xEventGroupGetBits() that can be called from an ISR. + * + * @param xEventGroup The event group being queried. + * + * @return The event group bits at the time xEventGroupGetBitsFromISR() was called. + * + * \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR + * \ingroup EventGroup + */ +EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION; + +/** + * event_groups.h + *
+    void xEventGroupDelete( EventGroupHandle_t xEventGroup );
+ 
+ * + * Delete an event group that was previously created by a call to + * xEventGroupCreate(). Tasks that are blocked on the event group will be + * unblocked and obtain 0 as the event group's value. + * + * @param xEventGroup The event group being deleted. + */ +void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION; + +/* For internal use only. */ +void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION; +void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION; + + +#if (configUSE_TRACE_FACILITY == 1) + UBaseType_t uxEventGroupGetNumber( void* xEventGroup ) PRIVILEGED_FUNCTION; + void vEventGroupSetNumber( void* xEventGroup, UBaseType_t uxEventGroupNumber ) PRIVILEGED_FUNCTION; +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT_GROUPS_H */ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/list.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/list.h new file mode 100644 index 0000000..9f8e557 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/list.h @@ -0,0 +1,411 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* + * This is the list implementation used by the scheduler. While it is tailored + * heavily for the schedulers needs, it is also available for use by + * application code. + * + * list_ts can only store pointers to list_item_ts. Each ListItem_t contains a + * numeric value (xItemValue). Most of the time the lists are sorted in + * descending item value order. + * + * Lists are created already containing one list item. The value of this + * item is the maximum possible that can be stored, it is therefore always at + * the end of the list and acts as a marker. The list member pxHead always + * points to this marker - even though it is at the tail of the list. This + * is because the tail contains a wrap back pointer to the true head of + * the list. + * + * In addition to it's value, each list item contains a pointer to the next + * item in the list (pxNext), a pointer to the list it is in (pxContainer) + * and a pointer to back to the object that contains it. These later two + * pointers are included for efficiency of list manipulation. There is + * effectively a two way link between the object containing the list item and + * the list item itself. + * + * + * \page ListIntroduction List Implementation + * \ingroup FreeRTOSIntro + */ + +#ifndef INC_FREERTOS_H + #error FreeRTOS.h must be included before list.h +#endif + +#ifndef LIST_H +#define LIST_H + +/* + * The list structure members are modified from within interrupts, and therefore + * by rights should be declared volatile. However, they are only modified in a + * functionally atomic way (within critical sections of with the scheduler + * suspended) and are either passed by reference into a function or indexed via + * a volatile variable. Therefore, in all use cases tested so far, the volatile + * qualifier can be omitted in order to provide a moderate performance + * improvement without adversely affecting functional behaviour. The assembly + * instructions generated by the IAR, ARM and GCC compilers when the respective + * compiler's options were set for maximum optimisation has been inspected and + * deemed to be as intended. That said, as compiler technology advances, and + * especially if aggressive cross module optimisation is used (a use case that + * has not been exercised to any great extend) then it is feasible that the + * volatile qualifier will be needed for correct optimisation. It is expected + * that a compiler removing essential code because, without the volatile + * qualifier on the list structure members and with aggressive cross module + * optimisation, the compiler deemed the code unnecessary will result in + * complete and obvious failure of the scheduler. If this is ever experienced + * then the volatile qualifier can be inserted in the relevant places within the + * list structures by simply defining configLIST_VOLATILE to volatile in + * FreeRTOSConfig.h (as per the example at the bottom of this comment block). + * If configLIST_VOLATILE is not defined then the preprocessor directives below + * will simply #define configLIST_VOLATILE away completely. + * + * To use volatile list structure members then add the following line to + * FreeRTOSConfig.h (without the quotes): + * "#define configLIST_VOLATILE volatile" + */ +#ifndef configLIST_VOLATILE + #define configLIST_VOLATILE +#endif /* configSUPPORT_CROSS_MODULE_OPTIMISATION */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Macros that can be used to place known values within the list structures, +then check that the known values do not get corrupted during the execution of +the application. These may catch the list data structures being overwritten in +memory. They will not catch data errors caused by incorrect configuration or +use of FreeRTOS.*/ +#if( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 ) + /* Define the macros to do nothing. */ + #define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE + #define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE + #define listFIRST_LIST_INTEGRITY_CHECK_VALUE + #define listSECOND_LIST_INTEGRITY_CHECK_VALUE + #define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) + #define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) + #define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ) + #define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ) + #define listTEST_LIST_ITEM_INTEGRITY( pxItem ) + #define listTEST_LIST_INTEGRITY( pxList ) +#else + /* Define macros that add new members into the list structures. */ + #define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue1; + #define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue2; + #define listFIRST_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue1; + #define listSECOND_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue2; + + /* Define macros that set the new structure members to known values. */ + #define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue1 = pdINTEGRITY_CHECK_VALUE + #define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue2 = pdINTEGRITY_CHECK_VALUE + #define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ) ( pxList )->xListIntegrityValue1 = pdINTEGRITY_CHECK_VALUE + #define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ) ( pxList )->xListIntegrityValue2 = pdINTEGRITY_CHECK_VALUE + + /* Define macros that will assert if one of the structure members does not + contain its expected value. */ + #define listTEST_LIST_ITEM_INTEGRITY( pxItem ) configASSERT( ( ( pxItem )->xListItemIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxItem )->xListItemIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) ) + #define listTEST_LIST_INTEGRITY( pxList ) configASSERT( ( ( pxList )->xListIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxList )->xListIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) ) +#endif /* configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES */ + + +/* + * Definition of the only type of object that a list can contain. + */ +struct xLIST_ITEM +{ + listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ + configLIST_VOLATILE TickType_t xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */ + struct xLIST_ITEM * configLIST_VOLATILE pxNext; /*< Pointer to the next ListItem_t in the list. */ + struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; /*< Pointer to the previous ListItem_t in the list. */ + void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */ + void * configLIST_VOLATILE pvContainer; /*< Pointer to the list in which this list item is placed (if any). */ + listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ +}; +typedef struct xLIST_ITEM ListItem_t; /* For some reason lint wants this as two separate definitions. */ + +struct xMINI_LIST_ITEM +{ + listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ + configLIST_VOLATILE TickType_t xItemValue; + struct xLIST_ITEM * configLIST_VOLATILE pxNext; + struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; +}; +typedef struct xMINI_LIST_ITEM MiniListItem_t; + +/* + * Definition of the type of queue used by the scheduler. + */ +typedef struct xLIST +{ + listFIRST_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ + volatile UBaseType_t uxNumberOfItems; + ListItem_t * configLIST_VOLATILE pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to listGET_OWNER_OF_NEXT_ENTRY (). */ + MiniListItem_t xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */ + listSECOND_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ +} List_t; + +/* + * Access macro to set the owner of a list item. The owner of a list item + * is the object (usually a TCB) that contains the list item. + * + * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER + * \ingroup LinkedList + */ +#define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) ) + +/* + * Access macro to get the owner of a list item. The owner of a list item + * is the object (usually a TCB) that contains the list item. + * + * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER + * \ingroup LinkedList + */ +#define listGET_LIST_ITEM_OWNER( pxListItem ) ( ( pxListItem )->pvOwner ) + +/* + * Access macro to set the value of the list item. In most cases the value is + * used to sort the list in descending order. + * + * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE + * \ingroup LinkedList + */ +#define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( ( pxListItem )->xItemValue = ( xValue ) ) + +/* + * Access macro to retrieve the value of the list item. The value can + * represent anything - for example the priority of a task, or the time at + * which a task should be unblocked. + * + * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE + * \ingroup LinkedList + */ +#define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue ) + +/* + * Access macro to retrieve the value of the list item at the head of a given + * list. + * + * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE + * \ingroup LinkedList + */ +#define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext->xItemValue ) + +/* + * Return the list item at the head of the list. + * + * \page listGET_HEAD_ENTRY listGET_HEAD_ENTRY + * \ingroup LinkedList + */ +#define listGET_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext ) + +/* + * Return the list item at the head of the list. + * + * \page listGET_NEXT listGET_NEXT + * \ingroup LinkedList + */ +#define listGET_NEXT( pxListItem ) ( ( pxListItem )->pxNext ) + +/* + * Return the list item that marks the end of the list + * + * \page listGET_END_MARKER listGET_END_MARKER + * \ingroup LinkedList + */ +#define listGET_END_MARKER( pxList ) ( ( ListItem_t const * ) ( &( ( pxList )->xListEnd ) ) ) + +/* + * Access macro to determine if a list contains any items. The macro will + * only have the value true if the list is empty. + * + * \page listLIST_IS_EMPTY listLIST_IS_EMPTY + * \ingroup LinkedList + */ +#define listLIST_IS_EMPTY( pxList ) ( ( BaseType_t ) ( ( pxList )->uxNumberOfItems == ( UBaseType_t ) 0 ) ) + +/* + * Access macro to return the number of items in the list. + */ +#define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems ) + +/* + * Access function to obtain the owner of the next entry in a list. + * + * The list member pxIndex is used to walk through a list. Calling + * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list + * and returns that entry's pxOwner parameter. Using multiple calls to this + * function it is therefore possible to move through every item contained in + * a list. + * + * The pxOwner parameter of a list item is a pointer to the object that owns + * the list item. In the scheduler this is normally a task control block. + * The pxOwner parameter effectively creates a two way link between the list + * item and its owner. + * + * @param pxTCB pxTCB is set to the address of the owner of the next list item. + * @param pxList The list from which the next item owner is to be returned. + * + * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY + * \ingroup LinkedList + */ +#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \ +{ \ +List_t * const pxConstList = ( pxList ); \ + /* Increment the index to the next item and return the item, ensuring */ \ + /* we don't return the marker used at the end of the list. */ \ + ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ + if( ( void * ) ( pxConstList )->pxIndex == ( void * ) &( ( pxConstList )->xListEnd ) ) \ + { \ + ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ + } \ + ( pxTCB ) = ( pxConstList )->pxIndex->pvOwner; \ +} + + +/* + * Access function to obtain the owner of the first entry in a list. Lists + * are normally sorted in ascending item value order. + * + * This function returns the pxOwner member of the first item in the list. + * The pxOwner parameter of a list item is a pointer to the object that owns + * the list item. In the scheduler this is normally a task control block. + * The pxOwner parameter effectively creates a two way link between the list + * item and its owner. + * + * @param pxList The list from which the owner of the head item is to be + * returned. + * + * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY + * \ingroup LinkedList + */ +#define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( (&( ( pxList )->xListEnd ))->pxNext->pvOwner ) + +/* + * Check to see if a list item is within a list. The list item maintains a + * "container" pointer that points to the list it is in. All this macro does + * is check to see if the container and the list match. + * + * @param pxList The list we want to know if the list item is within. + * @param pxListItem The list item we want to know if is in the list. + * @return pdTRUE if the list item is in the list, otherwise pdFALSE. + */ +#define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( BaseType_t ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) ) ) + +/* + * Return the list a list item is contained within (referenced from). + * + * @param pxListItem The list item being queried. + * @return A pointer to the List_t object that references the pxListItem + */ +#define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pvContainer ) + +/* + * This provides a crude means of knowing if a list has been initialised, as + * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise() + * function. + */ +#define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY ) + +/* + * Must be called before a list is used! This initialises all the members + * of the list structure and inserts the xListEnd item into the list as a + * marker to the back of the list. + * + * @param pxList Pointer to the list being initialised. + * + * \page vListInitialise vListInitialise + * \ingroup LinkedList + */ +void vListInitialise( List_t * const pxList ) PRIVILEGED_FUNCTION; + +/* + * Must be called before a list item is used. This sets the list container to + * null so the item does not think that it is already contained in a list. + * + * @param pxItem Pointer to the list item being initialised. + * + * \page vListInitialiseItem vListInitialiseItem + * \ingroup LinkedList + */ +void vListInitialiseItem( ListItem_t * const pxItem ) PRIVILEGED_FUNCTION; + +/* + * Insert a list item into a list. The item will be inserted into the list in + * a position determined by its item value (descending item value order). + * + * @param pxList The list into which the item is to be inserted. + * + * @param pxNewListItem The item that is to be placed in the list. + * + * \page vListInsert vListInsert + * \ingroup LinkedList + */ +void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION; + +/* + * Insert a list item into a list. The item will be inserted in a position + * such that it will be the last item within the list returned by multiple + * calls to listGET_OWNER_OF_NEXT_ENTRY. + * + * The list member pxIndex is used to walk through a list. Calling + * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list. + * Placing an item in a list using vListInsertEnd effectively places the item + * in the list position pointed to by pxIndex. This means that every other + * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before + * the pxIndex parameter again points to the item being inserted. + * + * @param pxList The list into which the item is to be inserted. + * + * @param pxNewListItem The list item to be inserted into the list. + * + * \page vListInsertEnd vListInsertEnd + * \ingroup LinkedList + */ +void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION; + +/* + * Remove an item from a list. The list item has a pointer to the list that + * it is in, so only the list item need be passed into the function. + * + * @param uxListRemove The item to be removed. The item will remove itself from + * the list pointed to by it's pxContainer parameter. + * + * @return The number of items that remain in the list after the list item has + * been removed. + * + * \page uxListRemove uxListRemove + * \ingroup LinkedList + */ +UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) PRIVILEGED_FUNCTION; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/message_buffer.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/message_buffer.h new file mode 100644 index 0000000..91e34fa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/message_buffer.h @@ -0,0 +1,779 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + + +/* + * Message buffers build functionality on top of FreeRTOS stream buffers. + * Whereas stream buffers are used to send a continuous stream of data from one + * task or interrupt to another, message buffers are used to send variable + * length discrete messages from one task or interrupt to another. Their + * implementation is light weight, making them particularly suited for interrupt + * to task and core to core communication scenarios. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xMessageBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xMessageBufferRead()) inside a critical section and set the receive + * timeout to 0. + * + * Message buffers hold variable length messages. To enable that, when a + * message is written to the message buffer an additional sizeof( size_t ) bytes + * are also written to store the message's length (that happens internally, with + * the API function). sizeof( size_t ) is typically 4 bytes on a 32-bit + * architecture, so writing a 10 byte message to a message buffer on a 32-bit + * architecture will actually reduce the available space in the message buffer + * by 14 bytes (10 byte are used by the message, and 4 bytes to hold the length + * of the message). + */ + +#ifndef FREERTOS_MESSAGE_BUFFER_H +#define FREERTOS_MESSAGE_BUFFER_H + +/* Message buffers are built onto of stream buffers. */ +#include "stream_buffer.h" + +#if defined( __cplusplus ) +extern "C" { +#endif + +/** + * Type by which message buffers are referenced. For example, a call to + * xMessageBufferCreate() returns an MessageBufferHandle_t variable that can + * then be used as a parameter to xMessageBufferSend(), xMessageBufferReceive(), + * etc. + */ +typedef void * MessageBufferHandle_t; + +/*-----------------------------------------------------------*/ + +/** + * message_buffer.h + * +
+MessageBufferHandle_t xMessageBufferCreate( size_t xBufferSizeBytes );
+
+ * + * Creates a new message buffer using dynamically allocated memory. See + * xMessageBufferCreateStatic() for a version that uses statically allocated + * memory (memory that is allocated at compile time). + * + * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in + * FreeRTOSConfig.h for xMessageBufferCreate() to be available. + * + * @param xBufferSizeBytes The total number of bytes (not messages) the message + * buffer will be able to hold at any one time. When a message is written to + * the message buffer an additional sizeof( size_t ) bytes are also written to + * store the message's length. sizeof( size_t ) is typically 4 bytes on a + * 32-bit architecture, so on most 32-bit architectures a 10 byte message will + * take up 14 bytes of message buffer space. + * + * @return If NULL is returned, then the message buffer cannot be created + * because there is insufficient heap memory available for FreeRTOS to allocate + * the message buffer data structures and storage area. A non-NULL value being + * returned indicates that the message buffer has been created successfully - + * the returned value should be stored as the handle to the created message + * buffer. + * + * Example use: +
+
+void vAFunction( void )
+{
+MessageBufferHandle_t xMessageBuffer;
+const size_t xMessageBufferSizeBytes = 100;
+
+    // Create a message buffer that can hold 100 bytes.  The memory used to hold
+    // both the message buffer structure and the messages themselves is allocated
+    // dynamically.  Each message added to the buffer consumes an additional 4
+    // bytes which are used to hold the lengh of the message.
+    xMessageBuffer = xMessageBufferCreate( xMessageBufferSizeBytes );
+
+    if( xMessageBuffer == NULL )
+    {
+        // There was not enough heap memory space available to create the
+        // message buffer.
+    }
+    else
+    {
+        // The message buffer was created successfully and can now be used.
+    }
+
+
+ * \defgroup xMessageBufferCreate xMessageBufferCreate + * \ingroup MessageBufferManagement + */ +#define xMessageBufferCreate( xBufferSizeBytes ) ( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE ) + +/** + * message_buffer.h + * +
+MessageBufferHandle_t xMessageBufferCreateStatic( size_t xBufferSizeBytes,
+                                                  uint8_t *pucMessageBufferStorageArea,
+                                                  StaticMessageBuffer_t *pxStaticMessageBuffer );
+
+ * Creates a new message buffer using statically allocated memory. See + * xMessageBufferCreate() for a version that uses dynamically allocated memory. + * + * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the + * pucMessageBufferStorageArea parameter. When a message is written to the + * message buffer an additional sizeof( size_t ) bytes are also written to store + * the message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit + * architecture, so on most 32-bit architecture a 10 byte message will take up + * 14 bytes of message buffer space. The maximum number of bytes that can be + * stored in the message buffer is actually (xBufferSizeBytes - 1). + * + * @param pucMessageBufferStorageArea Must point to a uint8_t array that is at + * least xBufferSizeBytes + 1 big. This is the array to which messages are + * copied when they are written to the message buffer. + * + * @param pxStaticMessageBuffer Must point to a variable of type + * StaticMessageBuffer_t, which will be used to hold the message buffer's data + * structure. + * + * @return If the message buffer is created successfully then a handle to the + * created message buffer is returned. If either pucMessageBufferStorageArea or + * pxStaticmessageBuffer are NULL then NULL is returned. + * + * Example use: +
+
+// Used to dimension the array used to hold the messages.  The available space
+// will actually be one less than this, so 999.
+#define STORAGE_SIZE_BYTES 1000
+
+// Defines the memory that will actually hold the messages within the message
+// buffer.
+static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
+
+// The variable used to hold the message buffer structure.
+StaticMessageBuffer_t xMessageBufferStruct;
+
+void MyFunction( void )
+{
+MessageBufferHandle_t xMessageBuffer;
+
+    xMessageBuffer = xMessageBufferCreateStatic( sizeof( ucBufferStorage ),
+                                                 ucBufferStorage,
+                                                 &xMessageBufferStruct );
+
+    // As neither the pucMessageBufferStorageArea or pxStaticMessageBuffer
+    // parameters were NULL, xMessageBuffer will not be NULL, and can be used to
+    // reference the created message buffer in other message buffer API calls.
+
+    // Other code that uses the message buffer can go here.
+}
+
+
+ * \defgroup xMessageBufferCreateStatic xMessageBufferCreateStatic + * \ingroup MessageBufferManagement + */ +#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) ( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer ) + +/** + * message_buffer.h + * +
+size_t xMessageBufferSend( MessageBufferHandle_t xMessageBuffer,
+                           const void *pvTxData,
+                           size_t xDataLengthBytes,
+                           TickType_t xTicksToWait );
+
+ *
+ * Sends a discrete message to the message buffer.  The message can be any
+ * length that fits within the buffer's free space, and is copied into the
+ * buffer.
+ *
+ * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer
+ * implementation (so also the message buffer implementation, as message buffers
+ * are built on top of stream buffers) assumes there is only one task or
+ * interrupt that will write to the buffer (the writer), and only one task or
+ * interrupt that will read from the buffer (the reader).  It is safe for the
+ * writer and reader to be different tasks or interrupts, but, unlike other
+ * FreeRTOS objects, it is not safe to have multiple different writers or
+ * multiple different readers.  If there are to be multiple different writers
+ * then the application writer must place each call to a writing API function
+ * (such as xMessageBufferSend()) inside a critical section and set the send
+ * block time to 0.  Likewise, if there are to be multiple different readers
+ * then the application writer must place each call to a reading API function
+ * (such as xMessageBufferRead()) inside a critical section and set the receive
+ * block time to 0.
+ *
+ * Use xMessageBufferSend() to write to a message buffer from a task.  Use
+ * xMessageBufferSendFromISR() to write to a message buffer from an interrupt
+ * service routine (ISR).
+ *
+ * @param xMessageBuffer The handle of the message buffer to which a message is
+ * being sent.
+ *
+ * @param pvTxData A pointer to the message that is to be copied into the
+ * message buffer.
+ *
+ * @param xDataLengthBytes The length of the message.  That is, the number of
+ * bytes to copy from pvTxData into the message buffer.  When a message is
+ * written to the message buffer an additional sizeof( size_t ) bytes are also
+ * written to store the message's length.  sizeof( size_t ) is typically 4 bytes
+ * on a 32-bit architecture, so on most 32-bit architecture setting
+ * xDataLengthBytes to 20 will reduce the free space in the message buffer by 24
+ * bytes (20 bytes of message data and 4 bytes to hold the message length).
+ *
+ * @param xTicksToWait The maximum amount of time the calling task should remain
+ * in the Blocked state to wait for enough space to become available in the
+ * message buffer, should the message buffer have insufficient space when
+ * xMessageBufferSend() is called.  The calling task will never block if
+ * xTicksToWait is zero.  The block time is specified in tick periods, so the
+ * absolute time it represents is dependent on the tick frequency.  The macro
+ * pdMS_TO_TICKS() can be used to convert a time specified in milliseconds into
+ * a time specified in ticks.  Setting xTicksToWait to portMAX_DELAY will cause
+ * the task to wait indefinitely (without timing out), provided
+ * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h.  Tasks do not use any
+ * CPU time when they are in the Blocked state.
+ *
+ * @return The number of bytes written to the message buffer.  If the call to
+ * xMessageBufferSend() times out before there was enough space to write the
+ * message into the message buffer then zero is returned.  If the call did not
+ * time out then xDataLengthBytes is returned.
+ *
+ * Example use:
+
+void vAFunction( MessageBufferHandle_t xMessageBuffer )
+{
+size_t xBytesSent;
+uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
+char *pcStringToSend = "String to send";
+const TickType_t x100ms = pdMS_TO_TICKS( 100 );
+
+    // Send an array to the message buffer, blocking for a maximum of 100ms to
+    // wait for enough space to be available in the message buffer.
+    xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );
+
+    if( xBytesSent != sizeof( ucArrayToSend ) )
+    {
+        // The call to xMessageBufferSend() times out before there was enough
+        // space in the buffer for the data to be written.
+    }
+
+    // Send the string to the message buffer.  Return immediately if there is
+    // not enough space in the buffer.
+    xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );
+
+    if( xBytesSent != strlen( pcStringToSend ) )
+    {
+        // The string could not be added to the message buffer because there was
+        // not enough free space in the buffer.
+    }
+}
+
+ * \defgroup xMessageBufferSend xMessageBufferSend + * \ingroup MessageBufferManagement + */ +#define xMessageBufferSend( xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) xStreamBufferSend( ( StreamBufferHandle_t ) xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) + +/** + * message_buffer.h + * +
+size_t xMessageBufferSendFromISR( MessageBufferHandle_t xMessageBuffer,
+                                  const void *pvTxData,
+                                  size_t xDataLengthBytes,
+                                  BaseType_t *pxHigherPriorityTaskWoken );
+
+ *
+ * Interrupt safe version of the API function that sends a discrete message to
+ * the message buffer.  The message can be any length that fits within the
+ * buffer's free space, and is copied into the buffer.
+ *
+ * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer
+ * implementation (so also the message buffer implementation, as message buffers
+ * are built on top of stream buffers) assumes there is only one task or
+ * interrupt that will write to the buffer (the writer), and only one task or
+ * interrupt that will read from the buffer (the reader).  It is safe for the
+ * writer and reader to be different tasks or interrupts, but, unlike other
+ * FreeRTOS objects, it is not safe to have multiple different writers or
+ * multiple different readers.  If there are to be multiple different writers
+ * then the application writer must place each call to a writing API function
+ * (such as xMessageBufferSend()) inside a critical section and set the send
+ * block time to 0.  Likewise, if there are to be multiple different readers
+ * then the application writer must place each call to a reading API function
+ * (such as xMessageBufferRead()) inside a critical section and set the receive
+ * block time to 0.
+ *
+ * Use xMessageBufferSend() to write to a message buffer from a task.  Use
+ * xMessageBufferSendFromISR() to write to a message buffer from an interrupt
+ * service routine (ISR).
+ *
+ * @param xMessageBuffer The handle of the message buffer to which a message is
+ * being sent.
+ *
+ * @param pvTxData A pointer to the message that is to be copied into the
+ * message buffer.
+ *
+ * @param xDataLengthBytes The length of the message.  That is, the number of
+ * bytes to copy from pvTxData into the message buffer.  When a message is
+ * written to the message buffer an additional sizeof( size_t ) bytes are also
+ * written to store the message's length.  sizeof( size_t ) is typically 4 bytes
+ * on a 32-bit architecture, so on most 32-bit architecture setting
+ * xDataLengthBytes to 20 will reduce the free space in the message buffer by 24
+ * bytes (20 bytes of message data and 4 bytes to hold the message length).
+ *
+ * @param pxHigherPriorityTaskWoken  It is possible that a message buffer will
+ * have a task blocked on it waiting for data.  Calling
+ * xMessageBufferSendFromISR() can make data available, and so cause a task that
+ * was waiting for data to leave the Blocked state.  If calling
+ * xMessageBufferSendFromISR() causes a task to leave the Blocked state, and the
+ * unblocked task has a priority higher than the currently executing task (the
+ * task that was interrupted), then, internally, xMessageBufferSendFromISR()
+ * will set *pxHigherPriorityTaskWoken to pdTRUE.  If
+ * xMessageBufferSendFromISR() sets this value to pdTRUE, then normally a
+ * context switch should be performed before the interrupt is exited.  This will
+ * ensure that the interrupt returns directly to the highest priority Ready
+ * state task.  *pxHigherPriorityTaskWoken should be set to pdFALSE before it
+ * is passed into the function.  See the code example below for an example.
+ *
+ * @return The number of bytes actually written to the message buffer.  If the
+ * message buffer didn't have enough free space for the message to be stored
+ * then 0 is returned, otherwise xDataLengthBytes is returned.
+ *
+ * Example use:
+
+// A message buffer that has already been created.
+MessageBufferHandle_t xMessageBuffer;
+
+void vAnInterruptServiceRoutine( void )
+{
+size_t xBytesSent;
+char *pcStringToSend = "String to send";
+BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
+
+    // Attempt to send the string to the message buffer.
+    xBytesSent = xMessageBufferSendFromISR( xMessageBuffer,
+                                            ( void * ) pcStringToSend,
+                                            strlen( pcStringToSend ),
+                                            &xHigherPriorityTaskWoken );
+
+    if( xBytesSent != strlen( pcStringToSend ) )
+    {
+        // The string could not be added to the message buffer because there was
+        // not enough free space in the buffer.
+    }
+
+    // If xHigherPriorityTaskWoken was set to pdTRUE inside
+    // xMessageBufferSendFromISR() then a task that has a priority above the
+    // priority of the currently executing task was unblocked and a context
+    // switch should be performed to ensure the ISR returns to the unblocked
+    // task.  In most FreeRTOS ports this is done by simply passing
+    // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
+    // variables value, and perform the context switch if necessary.  Check the
+    // documentation for the port in use for port specific instructions.
+    taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+}
+
+ * \defgroup xMessageBufferSendFromISR xMessageBufferSendFromISR + * \ingroup MessageBufferManagement + */ +#define xMessageBufferSendFromISR( xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) xStreamBufferSendFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) + +/** + * message_buffer.h + * +
+size_t xMessageBufferReceive( MessageBufferHandle_t xMessageBuffer,
+                              void *pvRxData,
+                              size_t xBufferLengthBytes,
+                              TickType_t xTicksToWait );
+
+ * + * Receives a discrete message from a message buffer. Messages can be of + * variable length and are copied out of the buffer. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xMessageBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xMessageBufferRead()) inside a critical section and set the receive + * block time to 0. + * + * Use xMessageBufferReceive() to read from a message buffer from a task. Use + * xMessageBufferReceiveFromISR() to read from a message buffer from an + * interrupt service routine (ISR). + * + * @param xMessageBuffer The handle of the message buffer from which a message + * is being received. + * + * @param pvRxData A pointer to the buffer into which the received message is + * to be copied. + * + * @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData + * parameter. This sets the maximum length of the message that can be received. + * If xBufferLengthBytes is too small to hold the next message then the message + * will be left in the message buffer and 0 will be returned. + * + * @param xTicksToWait The maximum amount of time the task should remain in the + * Blocked state to wait for a message, should the message buffer be empty. + * xMessageBufferReceive() will return immediately if xTicksToWait is zero and + * the message buffer is empty. The block time is specified in tick periods, so + * the absolute time it represents is dependent on the tick frequency. The + * macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds + * into a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will + * cause the task to wait indefinitely (without timing out), provided + * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. Tasks do not use any + * CPU time when they are in the Blocked state. + * + * @return The length, in bytes, of the message read from the message buffer, if + * any. If xMessageBufferReceive() times out before a message became available + * then zero is returned. If the length of the message is greater than + * xBufferLengthBytes then the message will be left in the message buffer and + * zero is returned. + * + * Example use: +
+void vAFunction( MessageBuffer_t xMessageBuffer )
+{
+uint8_t ucRxData[ 20 ];
+size_t xReceivedBytes;
+const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
+
+    // Receive the next message from the message buffer.  Wait in the Blocked
+    // state (so not using any CPU processing time) for a maximum of 100ms for
+    // a message to become available.
+    xReceivedBytes = xMessageBufferReceive( xMessageBuffer,
+                                            ( void * ) ucRxData,
+                                            sizeof( ucRxData ),
+                                            xBlockTime );
+
+    if( xReceivedBytes > 0 )
+    {
+        // A ucRxData contains a message that is xReceivedBytes long.  Process
+        // the message here....
+    }
+}
+
+ * \defgroup xMessageBufferReceive xMessageBufferReceive + * \ingroup MessageBufferManagement + */ +#define xMessageBufferReceive( xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) xStreamBufferReceive( ( StreamBufferHandle_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) + + +/** + * message_buffer.h + * +
+size_t xMessageBufferReceiveFromISR( MessageBufferHandle_t xMessageBuffer,
+                                     void *pvRxData,
+                                     size_t xBufferLengthBytes,
+                                     BaseType_t *pxHigherPriorityTaskWoken );
+
+ * + * An interrupt safe version of the API function that receives a discrete + * message from a message buffer. Messages can be of variable length and are + * copied out of the buffer. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xMessageBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xMessageBufferRead()) inside a critical section and set the receive + * block time to 0. + * + * Use xMessageBufferReceive() to read from a message buffer from a task. Use + * xMessageBufferReceiveFromISR() to read from a message buffer from an + * interrupt service routine (ISR). + * + * @param xMessageBuffer The handle of the message buffer from which a message + * is being received. + * + * @param pvRxData A pointer to the buffer into which the received message is + * to be copied. + * + * @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData + * parameter. This sets the maximum length of the message that can be received. + * If xBufferLengthBytes is too small to hold the next message then the message + * will be left in the message buffer and 0 will be returned. + * + * @param pxHigherPriorityTaskWoken It is possible that a message buffer will + * have a task blocked on it waiting for space to become available. Calling + * xMessageBufferReceiveFromISR() can make space available, and so cause a task + * that is waiting for space to leave the Blocked state. If calling + * xMessageBufferReceiveFromISR() causes a task to leave the Blocked state, and + * the unblocked task has a priority higher than the currently executing task + * (the task that was interrupted), then, internally, + * xMessageBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE. + * If xMessageBufferReceiveFromISR() sets this value to pdTRUE, then normally a + * context switch should be performed before the interrupt is exited. That will + * ensure the interrupt returns directly to the highest priority Ready state + * task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it is + * passed into the function. See the code example below for an example. + * + * @return The length, in bytes, of the message read from the message buffer, if + * any. + * + * Example use: +
+// A message buffer that has already been created.
+MessageBuffer_t xMessageBuffer;
+
+void vAnInterruptServiceRoutine( void )
+{
+uint8_t ucRxData[ 20 ];
+size_t xReceivedBytes;
+BaseType_t xHigherPriorityTaskWoken = pdFALSE;  // Initialised to pdFALSE.
+
+    // Receive the next message from the message buffer.
+    xReceivedBytes = xMessageBufferReceiveFromISR( xMessageBuffer,
+                                                  ( void * ) ucRxData,
+                                                  sizeof( ucRxData ),
+                                                  &xHigherPriorityTaskWoken );
+
+    if( xReceivedBytes > 0 )
+    {
+        // A ucRxData contains a message that is xReceivedBytes long.  Process
+        // the message here....
+    }
+
+    // If xHigherPriorityTaskWoken was set to pdTRUE inside
+    // xMessageBufferReceiveFromISR() then a task that has a priority above the
+    // priority of the currently executing task was unblocked and a context
+    // switch should be performed to ensure the ISR returns to the unblocked
+    // task.  In most FreeRTOS ports this is done by simply passing
+    // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
+    // variables value, and perform the context switch if necessary.  Check the
+    // documentation for the port in use for port specific instructions.
+    taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+}
+
+ * \defgroup xMessageBufferReceiveFromISR xMessageBufferReceiveFromISR + * \ingroup MessageBufferManagement + */ +#define xMessageBufferReceiveFromISR( xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) xStreamBufferReceiveFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) + +/** + * message_buffer.h + * +
+void vMessageBufferDelete( MessageBufferHandle_t xMessageBuffer );
+
+ * + * Deletes a message buffer that was previously created using a call to + * xMessageBufferCreate() or xMessageBufferCreateStatic(). If the message + * buffer was created using dynamic memory (that is, by xMessageBufferCreate()), + * then the allocated memory is freed. + * + * A message buffer handle must not be used after the message buffer has been + * deleted. + * + * @param xMessageBuffer The handle of the message buffer to be deleted. + * + */ +#define vMessageBufferDelete( xMessageBuffer ) vStreamBufferDelete( ( StreamBufferHandle_t ) xMessageBuffer ) + +/** + * message_buffer.h +
+BaseType_t xMessageBufferIsFull( MessageBufferHandle_t xMessageBuffer ) );
+
+ * + * Tests to see if a message buffer is full. A message buffer is full if it + * cannot accept any more messages, of any size, until space is made available + * by a message being removed from the message buffer. + * + * @param xMessageBuffer The handle of the message buffer being queried. + * + * @return If the message buffer referenced by xMessageBuffer is full then + * pdTRUE is returned. Otherwise pdFALSE is returned. + */ +#define xMessageBufferIsFull( xMessageBuffer ) xStreamBufferIsFull( ( StreamBufferHandle_t ) xMessageBuffer ) + +/** + * message_buffer.h +
+BaseType_t xMessageBufferIsEmpty( MessageBufferHandle_t xMessageBuffer ) );
+
+ * + * Tests to see if a message buffer is empty (does not contain any messages). + * + * @param xMessageBuffer The handle of the message buffer being queried. + * + * @return If the message buffer referenced by xMessageBuffer is empty then + * pdTRUE is returned. Otherwise pdFALSE is returned. + * + */ +#define xMessageBufferIsEmpty( xMessageBuffer ) xStreamBufferIsEmpty( ( StreamBufferHandle_t ) xMessageBuffer ) + +/** + * message_buffer.h +
+BaseType_t xMessageBufferReset( MessageBufferHandle_t xMessageBuffer );
+
+ * + * Resets a message buffer to its initial empty state, discarding any message it + * contained. + * + * A message buffer can only be reset if there are no tasks blocked on it. + * + * @param xMessageBuffer The handle of the message buffer being reset. + * + * @return If the message buffer was reset then pdPASS is returned. If the + * message buffer could not be reset because either there was a task blocked on + * the message queue to wait for space to become available, or to wait for a + * a message to be available, then pdFAIL is returned. + * + * \defgroup xMessageBufferReset xMessageBufferReset + * \ingroup MessageBufferManagement + */ +#define xMessageBufferReset( xMessageBuffer ) xStreamBufferReset( ( StreamBufferHandle_t ) xMessageBuffer ) + + +/** + * message_buffer.h +
+size_t xMessageBufferSpaceAvailable( MessageBufferHandle_t xMessageBuffer ) );
+
+ * Returns the number of bytes of free space in the message buffer. + * + * @param xMessageBuffer The handle of the message buffer being queried. + * + * @return The number of bytes that can be written to the message buffer before + * the message buffer would be full. When a message is written to the message + * buffer an additional sizeof( size_t ) bytes are also written to store the + * message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit + * architecture, so if xMessageBufferSpacesAvailable() returns 10, then the size + * of the largest message that can be written to the message buffer is 6 bytes. + * + * \defgroup xMessageBufferSpaceAvailable xMessageBufferSpaceAvailable + * \ingroup MessageBufferManagement + */ +#define xMessageBufferSpaceAvailable( xMessageBuffer ) xStreamBufferSpacesAvailable( ( StreamBufferHandle_t ) xMessageBuffer ) + +/** + * message_buffer.h + * +
+BaseType_t xMessageBufferSendCompletedFromISR( MessageBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
+
+ * + * For advanced users only. + * + * The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when + * data is sent to a message buffer or stream buffer. If there was a task that + * was blocked on the message or stream buffer waiting for data to arrive then + * the sbSEND_COMPLETED() macro sends a notification to the task to remove it + * from the Blocked state. xMessageBufferSendCompletedFromISR() does the same + * thing. It is provided to enable application writers to implement their own + * version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME. + * + * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for + * additional information. + * + * @param xStreamBuffer The handle of the stream buffer to which data was + * written. + * + * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be + * initialised to pdFALSE before it is passed into + * xMessageBufferSendCompletedFromISR(). If calling + * xMessageBufferSendCompletedFromISR() removes a task from the Blocked state, + * and the task has a priority above the priority of the currently running task, + * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a + * context switch should be performed before exiting the ISR. + * + * @return If a task was removed from the Blocked state then pdTRUE is returned. + * Otherwise pdFALSE is returned. + * + * \defgroup xMessageBufferSendCompletedFromISR xMessageBufferSendCompletedFromISR + * \ingroup StreamBufferManagement + */ +#define xMessageBufferSendCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) xStreamBufferSendCompletedFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pxHigherPriorityTaskWoken ) + +/** + * message_buffer.h + * +
+BaseType_t xMessageBufferReceiveCompletedFromISR( MessageBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
+
+ * + * For advanced users only. + * + * The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when + * data is read out of a message buffer or stream buffer. If there was a task + * that was blocked on the message or stream buffer waiting for data to arrive + * then the sbRECEIVE_COMPLETED() macro sends a notification to the task to + * remove it from the Blocked state. xMessageBufferReceiveCompletedFromISR() + * does the same thing. It is provided to enable application writers to + * implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT + * ANY OTHER TIME. + * + * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for + * additional information. + * + * @param xStreamBuffer The handle of the stream buffer from which data was + * read. + * + * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be + * initialised to pdFALSE before it is passed into + * xMessageBufferReceiveCompletedFromISR(). If calling + * xMessageBufferReceiveCompletedFromISR() removes a task from the Blocked state, + * and the task has a priority above the priority of the currently running task, + * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a + * context switch should be performed before exiting the ISR. + * + * @return If a task was removed from the Blocked state then pdTRUE is returned. + * Otherwise pdFALSE is returned. + * + * \defgroup xMessageBufferReceiveCompletedFromISR xMessageBufferReceiveCompletedFromISR + * \ingroup StreamBufferManagement + */ +#define xMessageBufferReceiveCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) xStreamBufferReceiveCompletedFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pxHigherPriorityTaskWoken ) + +#if defined( __cplusplus ) +} /* extern "C" */ +#endif + +#endif /* !defined( FREERTOS_MESSAGE_BUFFER_H ) */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/mpu_prototypes.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/mpu_prototypes.h new file mode 100644 index 0000000..e2c89ab --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/mpu_prototypes.h @@ -0,0 +1,155 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* + * When the MPU is used the standard (non MPU) API functions are mapped to + * equivalents that start "MPU_", the prototypes for which are defined in this + * header files. This will cause the application code to call the MPU_ version + * which wraps the non-MPU version with privilege promoting then demoting code, + * so the kernel code always runs will full privileges. + */ + + +#ifndef MPU_PROTOTYPES_H +#define MPU_PROTOTYPES_H + +/* MPU versions of tasks.h API functions. */ +BaseType_t MPU_xTaskCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask ); +TaskHandle_t MPU_xTaskCreateStatic( TaskFunction_t pxTaskCode, const char * const pcName, const uint32_t ulStackDepth, void * const pvParameters, UBaseType_t uxPriority, StackType_t * const puxStackBuffer, StaticTask_t * const pxTaskBuffer ); +BaseType_t MPU_xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ); +BaseType_t MPU_xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ); +void MPU_vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ); +void MPU_vTaskDelete( TaskHandle_t xTaskToDelete ); +void MPU_vTaskDelay( const TickType_t xTicksToDelay ); +void MPU_vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ); +BaseType_t MPU_xTaskAbortDelay( TaskHandle_t xTask ); +UBaseType_t MPU_uxTaskPriorityGet( TaskHandle_t xTask ); +eTaskState MPU_eTaskGetState( TaskHandle_t xTask ); +void MPU_vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ); +void MPU_vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ); +void MPU_vTaskSuspend( TaskHandle_t xTaskToSuspend ); +void MPU_vTaskResume( TaskHandle_t xTaskToResume ); +void MPU_vTaskStartScheduler( void ); +void MPU_vTaskSuspendAll( void ); +BaseType_t MPU_xTaskResumeAll( void ); +TickType_t MPU_xTaskGetTickCount( void ); +UBaseType_t MPU_uxTaskGetNumberOfTasks( void ); +char * MPU_pcTaskGetName( TaskHandle_t xTaskToQuery ); +TaskHandle_t MPU_xTaskGetHandle( const char *pcNameToQuery ); +UBaseType_t MPU_uxTaskGetStackHighWaterMark( TaskHandle_t xTask ); +void MPU_vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ); +TaskHookFunction_t MPU_xTaskGetApplicationTaskTag( TaskHandle_t xTask ); +void MPU_vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ); +void * MPU_pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ); +BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ); +TaskHandle_t MPU_xTaskGetIdleTaskHandle( void ); +UBaseType_t MPU_uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ); +void MPU_vTaskList( char * pcWriteBuffer ); +void MPU_vTaskGetRunTimeStats( char *pcWriteBuffer ); +BaseType_t MPU_xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ); +BaseType_t MPU_xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ); +uint32_t MPU_ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ); +BaseType_t MPU_xTaskNotifyStateClear( TaskHandle_t xTask ); +BaseType_t MPU_xTaskIncrementTick( void ); +TaskHandle_t MPU_xTaskGetCurrentTaskHandle( void ); +void MPU_vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ); +BaseType_t MPU_xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ); +void MPU_vTaskMissedYield( void ); +BaseType_t MPU_xTaskGetSchedulerState( void ); + +/* MPU versions of queue.h API functions. */ +BaseType_t MPU_xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ); +BaseType_t MPU_xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ); +BaseType_t MPU_xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ); +BaseType_t MPU_xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ); +UBaseType_t MPU_uxQueueMessagesWaiting( const QueueHandle_t xQueue ); +UBaseType_t MPU_uxQueueSpacesAvailable( const QueueHandle_t xQueue ); +void MPU_vQueueDelete( QueueHandle_t xQueue ); +QueueHandle_t MPU_xQueueCreateMutex( const uint8_t ucQueueType ); +QueueHandle_t MPU_xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ); +QueueHandle_t MPU_xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ); +QueueHandle_t MPU_xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ); +void* MPU_xQueueGetMutexHolder( QueueHandle_t xSemaphore ); +BaseType_t MPU_xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ); +BaseType_t MPU_xQueueGiveMutexRecursive( QueueHandle_t pxMutex ); +void MPU_vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcName ); +void MPU_vQueueUnregisterQueue( QueueHandle_t xQueue ); +const char * MPU_pcQueueGetName( QueueHandle_t xQueue ); +QueueHandle_t MPU_xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ); +QueueHandle_t MPU_xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ); +QueueSetHandle_t MPU_xQueueCreateSet( const UBaseType_t uxEventQueueLength ); +BaseType_t MPU_xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ); +BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ); +QueueSetMemberHandle_t MPU_xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait ); +BaseType_t MPU_xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ); +void MPU_vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ); +UBaseType_t MPU_uxQueueGetQueueNumber( QueueHandle_t xQueue ); +uint8_t MPU_ucQueueGetQueueType( QueueHandle_t xQueue ); + +/* MPU versions of timers.h API functions. */ +TimerHandle_t MPU_xTimerCreate( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction ); +TimerHandle_t MPU_xTimerCreateStatic( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction, StaticTimer_t *pxTimerBuffer ); +void * MPU_pvTimerGetTimerID( const TimerHandle_t xTimer ); +void MPU_vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ); +BaseType_t MPU_xTimerIsTimerActive( TimerHandle_t xTimer ); +TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ); +BaseType_t MPU_xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait ); +const char * MPU_pcTimerGetName( TimerHandle_t xTimer ); +TickType_t MPU_xTimerGetPeriod( TimerHandle_t xTimer ); +TickType_t MPU_xTimerGetExpiryTime( TimerHandle_t xTimer ); +BaseType_t MPU_xTimerCreateTimerTask( void ); +BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ); + +/* MPU versions of event_group.h API functions. */ +EventGroupHandle_t MPU_xEventGroupCreate( void ); +EventGroupHandle_t MPU_xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer ); +EventBits_t MPU_xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ); +EventBits_t MPU_xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ); +EventBits_t MPU_xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ); +EventBits_t MPU_xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ); +void MPU_vEventGroupDelete( EventGroupHandle_t xEventGroup ); +UBaseType_t MPU_uxEventGroupGetNumber( void* xEventGroup ); + +/* MPU versions of message/stream_buffer.h API functions. */ +size_t MPU_xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, TickType_t xTicksToWait ); +size_t MPU_xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t * const pxHigherPriorityTaskWoken ); +size_t MPU_xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, TickType_t xTicksToWait ); +size_t MPU_xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t * const pxHigherPriorityTaskWoken ); +void MPU_vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ); +BaseType_t MPU_xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ); +BaseType_t MPU_xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ); +BaseType_t MPU_xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ); +size_t MPU_xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ); +size_t MPU_xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ); +BaseType_t MPU_xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel ); +StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer ); +StreamBufferHandle_t MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer, uint8_t * const pucStreamBufferStorageArea, StaticStreamBuffer_t * const pxStaticStreamBuffer ); + + + +#endif /* MPU_PROTOTYPES_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/mpu_wrappers.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/mpu_wrappers.h new file mode 100644 index 0000000..58a4035 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/mpu_wrappers.h @@ -0,0 +1,181 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef MPU_WRAPPERS_H +#define MPU_WRAPPERS_H + +/* This file redefines API functions to be called through a wrapper macro, but +only for ports that are using the MPU. */ +#ifdef portUSING_MPU_WRAPPERS + + /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is + included from queue.c or task.c to prevent it from having an effect within + those files. */ + #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + + /* + * Map standard (non MPU) API functions to equivalents that start + * "MPU_". This will cause the application code to call the MPU_ + * version, which wraps the non-MPU version with privilege promoting + * then demoting code, so the kernel code always runs will full + * privileges. + */ + + /* Map standard tasks.h API functions to the MPU equivalents. */ + #define xTaskCreate MPU_xTaskCreate + #define xTaskCreateStatic MPU_xTaskCreateStatic + #define xTaskCreateRestricted MPU_xTaskCreateRestricted + #define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions + #define vTaskDelete MPU_vTaskDelete + #define vTaskDelay MPU_vTaskDelay + #define vTaskDelayUntil MPU_vTaskDelayUntil + #define xTaskAbortDelay MPU_xTaskAbortDelay + #define uxTaskPriorityGet MPU_uxTaskPriorityGet + #define eTaskGetState MPU_eTaskGetState + #define vTaskGetInfo MPU_vTaskGetInfo + #define vTaskPrioritySet MPU_vTaskPrioritySet + #define vTaskSuspend MPU_vTaskSuspend + #define vTaskResume MPU_vTaskResume + #define vTaskSuspendAll MPU_vTaskSuspendAll + #define xTaskResumeAll MPU_xTaskResumeAll + #define xTaskGetTickCount MPU_xTaskGetTickCount + #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks + #define pcTaskGetName MPU_pcTaskGetName + #define xTaskGetHandle MPU_xTaskGetHandle + #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark + #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag + #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag + #define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer + #define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer + #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook + #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle + #define uxTaskGetSystemState MPU_uxTaskGetSystemState + #define vTaskList MPU_vTaskList + #define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats + #define xTaskGenericNotify MPU_xTaskGenericNotify + #define xTaskNotifyWait MPU_xTaskNotifyWait + #define ulTaskNotifyTake MPU_ulTaskNotifyTake + #define xTaskNotifyStateClear MPU_xTaskNotifyStateClear + + #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle + #define vTaskSetTimeOutState MPU_vTaskSetTimeOutState + #define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut + #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState + + /* Map standard queue.h API functions to the MPU equivalents. */ + #define xQueueGenericSend MPU_xQueueGenericSend + #define xQueueReceive MPU_xQueueReceive + #define xQueuePeek MPU_xQueuePeek + #define xQueueSemaphoreTake MPU_xQueueSemaphoreTake + #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting + #define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable + #define vQueueDelete MPU_vQueueDelete + #define xQueueCreateMutex MPU_xQueueCreateMutex + #define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic + #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore + #define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic + #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder + #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive + #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive + #define xQueueGenericCreate MPU_xQueueGenericCreate + #define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic + #define xQueueCreateSet MPU_xQueueCreateSet + #define xQueueAddToSet MPU_xQueueAddToSet + #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet + #define xQueueSelectFromSet MPU_xQueueSelectFromSet + #define xQueueGenericReset MPU_xQueueGenericReset + + #if( configQUEUE_REGISTRY_SIZE > 0 ) + #define vQueueAddToRegistry MPU_vQueueAddToRegistry + #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue + #define pcQueueGetName MPU_pcQueueGetName + #endif + + /* Map standard timer.h API functions to the MPU equivalents. */ + #define xTimerCreate MPU_xTimerCreate + #define xTimerCreateStatic MPU_xTimerCreateStatic + #define pvTimerGetTimerID MPU_pvTimerGetTimerID + #define vTimerSetTimerID MPU_vTimerSetTimerID + #define xTimerIsTimerActive MPU_xTimerIsTimerActive + #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle + #define xTimerPendFunctionCall MPU_xTimerPendFunctionCall + #define pcTimerGetName MPU_pcTimerGetName + #define xTimerGetPeriod MPU_xTimerGetPeriod + #define xTimerGetExpiryTime MPU_xTimerGetExpiryTime + #define xTimerGenericCommand MPU_xTimerGenericCommand + + /* Map standard event_group.h API functions to the MPU equivalents. */ + #define xEventGroupCreate MPU_xEventGroupCreate + #define xEventGroupCreateStatic MPU_xEventGroupCreateStatic + #define xEventGroupWaitBits MPU_xEventGroupWaitBits + #define xEventGroupClearBits MPU_xEventGroupClearBits + #define xEventGroupSetBits MPU_xEventGroupSetBits + #define xEventGroupSync MPU_xEventGroupSync + #define vEventGroupDelete MPU_vEventGroupDelete + + /* Map standard message/stream_buffer.h API functions to the MPU + equivalents. */ + #define xStreamBufferSend MPU_xStreamBufferSend + #define xStreamBufferSendFromISR MPU_xStreamBufferSendFromISR + #define xStreamBufferReceive MPU_xStreamBufferReceive + #define xStreamBufferReceiveFromISR MPU_xStreamBufferReceiveFromISR + #define vStreamBufferDelete MPU_vStreamBufferDelete + #define xStreamBufferIsFull MPU_xStreamBufferIsFull + #define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty + #define xStreamBufferReset MPU_xStreamBufferReset + #define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable + #define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable + #define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel + #define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate + #define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic + + + /* Remove the privileged function macro, but keep the PRIVILEGED_DATA + macro so applications can place data in privileged access sections + (useful when using statically allocated objects). */ + #define PRIVILEGED_FUNCTION + #define PRIVILEGED_DATA __attribute__((section("privileged_data"))) + + #else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ + + /* Ensure API functions go in the privileged execution section. */ + #define PRIVILEGED_FUNCTION __attribute__((section("privileged_functions"))) + #define PRIVILEGED_DATA __attribute__((section("privileged_data"))) + + #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ + +#else /* portUSING_MPU_WRAPPERS */ + + #define PRIVILEGED_FUNCTION + #define PRIVILEGED_DATA + #define portUSING_MPU_WRAPPERS 0 + +#endif /* portUSING_MPU_WRAPPERS */ + + +#endif /* MPU_WRAPPERS_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/portable.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/portable.h new file mode 100644 index 0000000..3758f10 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/portable.h @@ -0,0 +1,165 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/*----------------------------------------------------------- + * Portable layer API. Each function must be defined for each port. + *----------------------------------------------------------*/ + +#ifndef PORTABLE_H +#define PORTABLE_H + +/* Each FreeRTOS port has a unique portmacro.h header file. Originally a +pre-processor definition was used to ensure the pre-processor found the correct +portmacro.h file for the port being used. That scheme was deprecated in favour +of setting the compiler's include path such that it found the correct +portmacro.h file - removing the need for the constant and allowing the +portmacro.h file to be located anywhere in relation to the port being used. +Purely for reasons of backward compatibility the old method is still valid, but +to make it clear that new projects should not use it, support for the port +specific constants has been moved into the deprecated_definitions.h header +file. */ +#include "deprecated_definitions.h" + +/* If portENTER_CRITICAL is not defined then including deprecated_definitions.h +did not result in a portmacro.h header file being included - and it should be +included here. In this case the path to the correct portmacro.h header file +must be set in the compiler's include path. */ +#ifndef portENTER_CRITICAL + #include "portmacro.h" +#endif + +#if portBYTE_ALIGNMENT == 32 + #define portBYTE_ALIGNMENT_MASK ( 0x001f ) +#endif + +#if portBYTE_ALIGNMENT == 16 + #define portBYTE_ALIGNMENT_MASK ( 0x000f ) +#endif + +#if portBYTE_ALIGNMENT == 8 + #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) +#endif + +#if portBYTE_ALIGNMENT == 4 + #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) +#endif + +#if portBYTE_ALIGNMENT == 2 + #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) +#endif + +#if portBYTE_ALIGNMENT == 1 + #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) +#endif + +#ifndef portBYTE_ALIGNMENT_MASK + #error "Invalid portBYTE_ALIGNMENT definition" +#endif + +#ifndef portNUM_CONFIGURABLE_REGIONS + #define portNUM_CONFIGURABLE_REGIONS 1 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mpu_wrappers.h" + +/* + * Setup the stack of a new task so it is ready to be placed under the + * scheduler control. The registers have to be placed on the stack in + * the order that the port expects to find them. + * + */ +#if( portUSING_MPU_WRAPPERS == 1 ) + StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; +#else + StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION; +#endif + +/* Used by heap_5.c. */ +typedef struct HeapRegion +{ + uint8_t *pucStartAddress; + size_t xSizeInBytes; +} HeapRegion_t; + +/* + * Used to define multiple heap regions for use by heap_5.c. This function + * must be called before any calls to pvPortMalloc() - not creating a task, + * queue, semaphore, mutex, software timer, event group, etc. will result in + * pvPortMalloc being called. + * + * pxHeapRegions passes in an array of HeapRegion_t structures - each of which + * defines a region of memory that can be used as the heap. The array is + * terminated by a HeapRegions_t structure that has a size of 0. The region + * with the lowest start address must appear first in the array. + */ +void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION; + + +/* + * Map to the memory management routines required for the port. + */ +void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; +void vPortFree( void *pv ) PRIVILEGED_FUNCTION; +void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION; +size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION; +size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION; + +/* + * Setup the hardware ready for the scheduler to take control. This generally + * sets up a tick interrupt and sets timers for the correct tick frequency. + */ +BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION; + +/* + * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so + * the hardware is left in its original condition after the scheduler stops + * executing. + */ +void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; + +/* + * The structures and methods of manipulating the MPU are contained within the + * port layer. + * + * Fills the xMPUSettings structure with the memory region information + * contained in xRegions. + */ +#if( portUSING_MPU_WRAPPERS == 1 ) + struct xMEMORY_REGION; + void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint32_t ulStackDepth ) PRIVILEGED_FUNCTION; +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* PORTABLE_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/projdefs.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/projdefs.h new file mode 100644 index 0000000..05ba7cd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/projdefs.h @@ -0,0 +1,124 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef PROJDEFS_H +#define PROJDEFS_H + +/* + * Defines the prototype to which task functions must conform. Defined in this + * file to ensure the type is known before portable.h is included. + */ +typedef void (*TaskFunction_t)( void * ); + +/* Converts a time in milliseconds to a time in ticks. This macro can be +overridden by a macro of the same name defined in FreeRTOSConfig.h in case the +definition here is not suitable for your application. */ +#ifndef pdMS_TO_TICKS + #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) ) +#endif + +#define pdFALSE ( ( BaseType_t ) 0 ) +#define pdTRUE ( ( BaseType_t ) 1 ) + +#define pdPASS ( pdTRUE ) +#define pdFAIL ( pdFALSE ) +#define errQUEUE_EMPTY ( ( BaseType_t ) 0 ) +#define errQUEUE_FULL ( ( BaseType_t ) 0 ) + +/* FreeRTOS error definitions. */ +#define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 ) +#define errQUEUE_BLOCKED ( -4 ) +#define errQUEUE_YIELD ( -5 ) + +/* Macros used for basic data corruption checks. */ +#ifndef configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES + #define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0 +#endif + +#if( configUSE_16_BIT_TICKS == 1 ) + #define pdINTEGRITY_CHECK_VALUE 0x5a5a +#else + #define pdINTEGRITY_CHECK_VALUE 0x5a5a5a5aUL +#endif + +/* The following errno values are used by FreeRTOS+ components, not FreeRTOS +itself. */ +#define pdFREERTOS_ERRNO_NONE 0 /* No errors */ +#define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */ +#define pdFREERTOS_ERRNO_EINTR 4 /* Interrupted system call */ +#define pdFREERTOS_ERRNO_EIO 5 /* I/O error */ +#define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */ +#define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */ +#define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */ +#define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */ +#define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */ +#define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */ +#define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */ +#define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */ +#define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */ +#define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */ +#define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */ +#define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */ +#define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */ +#define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */ +#define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */ +#define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */ +#define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */ +#define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */ +#define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */ +#define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */ +#define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */ +#define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */ +#define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */ +#define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */ +#define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */ +#define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */ +#define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */ +#define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */ +#define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */ +#define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */ +#define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */ +#define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */ +#define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */ +#define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */ +#define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */ + +/* The following endian values are used by FreeRTOS+ components, not FreeRTOS +itself. */ +#define pdFREERTOS_LITTLE_ENDIAN 0 +#define pdFREERTOS_BIG_ENDIAN 1 + +/* Re-defining endian values for generic naming. */ +#define pdLITTLE_ENDIAN pdFREERTOS_LITTLE_ENDIAN +#define pdBIG_ENDIAN pdFREERTOS_BIG_ENDIAN + + +#endif /* PROJDEFS_H */ + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/queue.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/queue.h new file mode 100644 index 0000000..ffddee3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/queue.h @@ -0,0 +1,1653 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + + +#ifndef QUEUE_H +#define QUEUE_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h" must appear in source files before "include queue.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Type by which queues are referenced. For example, a call to xQueueCreate() + * returns an QueueHandle_t variable that can then be used as a parameter to + * xQueueSend(), xQueueReceive(), etc. + */ +typedef void * QueueHandle_t; + +/** + * Type by which queue sets are referenced. For example, a call to + * xQueueCreateSet() returns an xQueueSet variable that can then be used as a + * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc. + */ +typedef void * QueueSetHandle_t; + +/** + * Queue sets can contain both queues and semaphores, so the + * QueueSetMemberHandle_t is defined as a type to be used where a parameter or + * return value can be either an QueueHandle_t or an SemaphoreHandle_t. + */ +typedef void * QueueSetMemberHandle_t; + +/* For internal use only. */ +#define queueSEND_TO_BACK ( ( BaseType_t ) 0 ) +#define queueSEND_TO_FRONT ( ( BaseType_t ) 1 ) +#define queueOVERWRITE ( ( BaseType_t ) 2 ) + +/* For internal use only. These definitions *must* match those in queue.c. */ +#define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U ) +#define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U ) +#define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U ) +#define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U ) +#define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U ) +#define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U ) + +/** + * queue. h + *
+ QueueHandle_t xQueueCreate(
+                              UBaseType_t uxQueueLength,
+                              UBaseType_t uxItemSize
+                          );
+ * 
+ * + * Creates a new queue instance, and returns a handle by which the new queue + * can be referenced. + * + * Internally, within the FreeRTOS implementation, queues use two blocks of + * memory. The first block is used to hold the queue's data structures. The + * second block is used to hold items placed into the queue. If a queue is + * created using xQueueCreate() then both blocks of memory are automatically + * dynamically allocated inside the xQueueCreate() function. (see + * http://www.freertos.org/a00111.html). If a queue is created using + * xQueueCreateStatic() then the application writer must provide the memory that + * will get used by the queue. xQueueCreateStatic() therefore allows a queue to + * be created without using any dynamic memory allocation. + * + * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html + * + * @param uxQueueLength The maximum number of items that the queue can contain. + * + * @param uxItemSize The number of bytes each item in the queue will require. + * Items are queued by copy, not by reference, so this is the number of bytes + * that will be copied for each posted item. Each item on the queue must be + * the same size. + * + * @return If the queue is successfully create then a handle to the newly + * created queue is returned. If the queue cannot be created then 0 is + * returned. + * + * Example usage: +
+ struct AMessage
+ {
+    char ucMessageID;
+    char ucData[ 20 ];
+ };
+
+ void vATask( void *pvParameters )
+ {
+ QueueHandle_t xQueue1, xQueue2;
+
+    // Create a queue capable of containing 10 uint32_t values.
+    xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
+    if( xQueue1 == 0 )
+    {
+        // Queue was not created and must not be used.
+    }
+
+    // Create a queue capable of containing 10 pointers to AMessage structures.
+    // These should be passed by pointer as they contain a lot of data.
+    xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
+    if( xQueue2 == 0 )
+    {
+        // Queue was not created and must not be used.
+    }
+
+    // ... Rest of task code.
+ }
+ 
+ * \defgroup xQueueCreate xQueueCreate + * \ingroup QueueManagement + */ +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) ) +#endif + +/** + * queue. h + *
+ QueueHandle_t xQueueCreateStatic(
+                              UBaseType_t uxQueueLength,
+                              UBaseType_t uxItemSize,
+                              uint8_t *pucQueueStorageBuffer,
+                              StaticQueue_t *pxQueueBuffer
+                          );
+ * 
+ * + * Creates a new queue instance, and returns a handle by which the new queue + * can be referenced. + * + * Internally, within the FreeRTOS implementation, queues use two blocks of + * memory. The first block is used to hold the queue's data structures. The + * second block is used to hold items placed into the queue. If a queue is + * created using xQueueCreate() then both blocks of memory are automatically + * dynamically allocated inside the xQueueCreate() function. (see + * http://www.freertos.org/a00111.html). If a queue is created using + * xQueueCreateStatic() then the application writer must provide the memory that + * will get used by the queue. xQueueCreateStatic() therefore allows a queue to + * be created without using any dynamic memory allocation. + * + * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html + * + * @param uxQueueLength The maximum number of items that the queue can contain. + * + * @param uxItemSize The number of bytes each item in the queue will require. + * Items are queued by copy, not by reference, so this is the number of bytes + * that will be copied for each posted item. Each item on the queue must be + * the same size. + * + * @param pucQueueStorageBuffer If uxItemSize is not zero then + * pucQueueStorageBuffer must point to a uint8_t array that is at least large + * enough to hold the maximum number of items that can be in the queue at any + * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is + * zero then pucQueueStorageBuffer can be NULL. + * + * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which + * will be used to hold the queue's data structure. + * + * @return If the queue is created then a handle to the created queue is + * returned. If pxQueueBuffer is NULL then NULL is returned. + * + * Example usage: +
+ struct AMessage
+ {
+    char ucMessageID;
+    char ucData[ 20 ];
+ };
+
+ #define QUEUE_LENGTH 10
+ #define ITEM_SIZE sizeof( uint32_t )
+
+ // xQueueBuffer will hold the queue structure.
+ StaticQueue_t xQueueBuffer;
+
+ // ucQueueStorage will hold the items posted to the queue.  Must be at least
+ // [(queue length) * ( queue item size)] bytes long.
+ uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
+
+ void vATask( void *pvParameters )
+ {
+ QueueHandle_t xQueue1;
+
+    // Create a queue capable of containing 10 uint32_t values.
+    xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
+                            ITEM_SIZE      // The size of each item in the queue
+                            &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
+                            &xQueueBuffer ); // The buffer that will hold the queue structure.
+
+    // The queue is guaranteed to be created successfully as no dynamic memory
+    // allocation is used.  Therefore xQueue1 is now a handle to a valid queue.
+
+    // ... Rest of task code.
+ }
+ 
+ * \defgroup xQueueCreateStatic xQueueCreateStatic + * \ingroup QueueManagement + */ +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * queue. h + *
+ BaseType_t xQueueSendToToFront(
+                                   QueueHandle_t    xQueue,
+                                   const void        *pvItemToQueue,
+                                   TickType_t        xTicksToWait
+                               );
+ * 
+ * + * Post an item to the front of a queue. The item is queued by copy, not by + * reference. This function must not be called from an interrupt service + * routine. See xQueueSendFromISR () for an alternative which may be used + * in an ISR. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for space to become available on the queue, should it already + * be full. The call will return immediately if this is set to 0 and the + * queue is full. The time is defined in tick periods so the constant + * portTICK_PERIOD_MS should be used to convert to real time if this is required. + * + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. + * + * Example usage: +
+ struct AMessage
+ {
+    char ucMessageID;
+    char ucData[ 20 ];
+ } xMessage;
+
+ uint32_t ulVar = 10UL;
+
+ void vATask( void *pvParameters )
+ {
+ QueueHandle_t xQueue1, xQueue2;
+ struct AMessage *pxMessage;
+
+    // Create a queue capable of containing 10 uint32_t values.
+    xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
+
+    // Create a queue capable of containing 10 pointers to AMessage structures.
+    // These should be passed by pointer as they contain a lot of data.
+    xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
+
+    // ...
+
+    if( xQueue1 != 0 )
+    {
+        // Send an uint32_t.  Wait for 10 ticks for space to become
+        // available if necessary.
+        if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
+        {
+            // Failed to post the message, even after 10 ticks.
+        }
+    }
+
+    if( xQueue2 != 0 )
+    {
+        // Send a pointer to a struct AMessage object.  Don't block if the
+        // queue is already full.
+        pxMessage = & xMessage;
+        xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
+    }
+
+    // ... Rest of task code.
+ }
+ 
+ * \defgroup xQueueSend xQueueSend + * \ingroup QueueManagement + */ +#define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT ) + +/** + * queue. h + *
+ BaseType_t xQueueSendToBack(
+                                   QueueHandle_t    xQueue,
+                                   const void        *pvItemToQueue,
+                                   TickType_t        xTicksToWait
+                               );
+ * 
+ * + * This is a macro that calls xQueueGenericSend(). + * + * Post an item to the back of a queue. The item is queued by copy, not by + * reference. This function must not be called from an interrupt service + * routine. See xQueueSendFromISR () for an alternative which may be used + * in an ISR. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for space to become available on the queue, should it already + * be full. The call will return immediately if this is set to 0 and the queue + * is full. The time is defined in tick periods so the constant + * portTICK_PERIOD_MS should be used to convert to real time if this is required. + * + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. + * + * Example usage: +
+ struct AMessage
+ {
+    char ucMessageID;
+    char ucData[ 20 ];
+ } xMessage;
+
+ uint32_t ulVar = 10UL;
+
+ void vATask( void *pvParameters )
+ {
+ QueueHandle_t xQueue1, xQueue2;
+ struct AMessage *pxMessage;
+
+    // Create a queue capable of containing 10 uint32_t values.
+    xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
+
+    // Create a queue capable of containing 10 pointers to AMessage structures.
+    // These should be passed by pointer as they contain a lot of data.
+    xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
+
+    // ...
+
+    if( xQueue1 != 0 )
+    {
+        // Send an uint32_t.  Wait for 10 ticks for space to become
+        // available if necessary.
+        if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
+        {
+            // Failed to post the message, even after 10 ticks.
+        }
+    }
+
+    if( xQueue2 != 0 )
+    {
+        // Send a pointer to a struct AMessage object.  Don't block if the
+        // queue is already full.
+        pxMessage = & xMessage;
+        xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
+    }
+
+    // ... Rest of task code.
+ }
+ 
+ * \defgroup xQueueSend xQueueSend + * \ingroup QueueManagement + */ +#define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) + +/** + * queue. h + *
+ BaseType_t xQueueSend(
+                              QueueHandle_t xQueue,
+                              const void * pvItemToQueue,
+                              TickType_t xTicksToWait
+                         );
+ * 
+ * + * This is a macro that calls xQueueGenericSend(). It is included for + * backward compatibility with versions of FreeRTOS.org that did not + * include the xQueueSendToFront() and xQueueSendToBack() macros. It is + * equivalent to xQueueSendToBack(). + * + * Post an item on a queue. The item is queued by copy, not by reference. + * This function must not be called from an interrupt service routine. + * See xQueueSendFromISR () for an alternative which may be used in an ISR. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for space to become available on the queue, should it already + * be full. The call will return immediately if this is set to 0 and the + * queue is full. The time is defined in tick periods so the constant + * portTICK_PERIOD_MS should be used to convert to real time if this is required. + * + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. + * + * Example usage: +
+ struct AMessage
+ {
+    char ucMessageID;
+    char ucData[ 20 ];
+ } xMessage;
+
+ uint32_t ulVar = 10UL;
+
+ void vATask( void *pvParameters )
+ {
+ QueueHandle_t xQueue1, xQueue2;
+ struct AMessage *pxMessage;
+
+    // Create a queue capable of containing 10 uint32_t values.
+    xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
+
+    // Create a queue capable of containing 10 pointers to AMessage structures.
+    // These should be passed by pointer as they contain a lot of data.
+    xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
+
+    // ...
+
+    if( xQueue1 != 0 )
+    {
+        // Send an uint32_t.  Wait for 10 ticks for space to become
+        // available if necessary.
+        if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
+        {
+            // Failed to post the message, even after 10 ticks.
+        }
+    }
+
+    if( xQueue2 != 0 )
+    {
+        // Send a pointer to a struct AMessage object.  Don't block if the
+        // queue is already full.
+        pxMessage = & xMessage;
+        xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
+    }
+
+    // ... Rest of task code.
+ }
+ 
+ * \defgroup xQueueSend xQueueSend + * \ingroup QueueManagement + */ +#define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) + +/** + * queue. h + *
+ BaseType_t xQueueOverwrite(
+                              QueueHandle_t xQueue,
+                              const void * pvItemToQueue
+                         );
+ * 
+ * + * Only for use with queues that have a length of one - so the queue is either + * empty or full. + * + * Post an item on a queue. If the queue is already full then overwrite the + * value held in the queue. The item is queued by copy, not by reference. + * + * This function must not be called from an interrupt service routine. + * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR. + * + * @param xQueue The handle of the queue to which the data is being sent. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and + * therefore has the same return values as xQueueSendToFront(). However, pdPASS + * is the only value that can be returned because xQueueOverwrite() will write + * to the queue even when the queue is already full. + * + * Example usage: +
+
+ void vFunction( void *pvParameters )
+ {
+ QueueHandle_t xQueue;
+ uint32_t ulVarToSend, ulValReceived;
+
+    // Create a queue to hold one uint32_t value.  It is strongly
+    // recommended *not* to use xQueueOverwrite() on queues that can
+    // contain more than one value, and doing so will trigger an assertion
+    // if configASSERT() is defined.
+    xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
+
+    // Write the value 10 to the queue using xQueueOverwrite().
+    ulVarToSend = 10;
+    xQueueOverwrite( xQueue, &ulVarToSend );
+
+    // Peeking the queue should now return 10, but leave the value 10 in
+    // the queue.  A block time of zero is used as it is known that the
+    // queue holds a value.
+    ulValReceived = 0;
+    xQueuePeek( xQueue, &ulValReceived, 0 );
+
+    if( ulValReceived != 10 )
+    {
+        // Error unless the item was removed by a different task.
+    }
+
+    // The queue is still full.  Use xQueueOverwrite() to overwrite the
+    // value held in the queue with 100.
+    ulVarToSend = 100;
+    xQueueOverwrite( xQueue, &ulVarToSend );
+
+    // This time read from the queue, leaving the queue empty once more.
+    // A block time of 0 is used again.
+    xQueueReceive( xQueue, &ulValReceived, 0 );
+
+    // The value read should be the last value written, even though the
+    // queue was already full when the value was written.
+    if( ulValReceived != 100 )
+    {
+        // Error!
+    }
+
+    // ...
+}
+ 
+ * \defgroup xQueueOverwrite xQueueOverwrite + * \ingroup QueueManagement + */ +#define xQueueOverwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE ) + + +/** + * queue. h + *
+ BaseType_t xQueueGenericSend(
+                                    QueueHandle_t xQueue,
+                                    const void * pvItemToQueue,
+                                    TickType_t xTicksToWait
+                                    BaseType_t xCopyPosition
+                                );
+ * 
+ * + * It is preferred that the macros xQueueSend(), xQueueSendToFront() and + * xQueueSendToBack() are used in place of calling this function directly. + * + * Post an item on a queue. The item is queued by copy, not by reference. + * This function must not be called from an interrupt service routine. + * See xQueueSendFromISR () for an alternative which may be used in an ISR. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for space to become available on the queue, should it already + * be full. The call will return immediately if this is set to 0 and the + * queue is full. The time is defined in tick periods so the constant + * portTICK_PERIOD_MS should be used to convert to real time if this is required. + * + * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the + * item at the back of the queue, or queueSEND_TO_FRONT to place the item + * at the front of the queue (for high priority messages). + * + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. + * + * Example usage: +
+ struct AMessage
+ {
+    char ucMessageID;
+    char ucData[ 20 ];
+ } xMessage;
+
+ uint32_t ulVar = 10UL;
+
+ void vATask( void *pvParameters )
+ {
+ QueueHandle_t xQueue1, xQueue2;
+ struct AMessage *pxMessage;
+
+    // Create a queue capable of containing 10 uint32_t values.
+    xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
+
+    // Create a queue capable of containing 10 pointers to AMessage structures.
+    // These should be passed by pointer as they contain a lot of data.
+    xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
+
+    // ...
+
+    if( xQueue1 != 0 )
+    {
+        // Send an uint32_t.  Wait for 10 ticks for space to become
+        // available if necessary.
+        if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
+        {
+            // Failed to post the message, even after 10 ticks.
+        }
+    }
+
+    if( xQueue2 != 0 )
+    {
+        // Send a pointer to a struct AMessage object.  Don't block if the
+        // queue is already full.
+        pxMessage = & xMessage;
+        xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
+    }
+
+    // ... Rest of task code.
+ }
+ 
+ * \defgroup xQueueSend xQueueSend + * \ingroup QueueManagement + */ +BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ BaseType_t xQueuePeek(
+                             QueueHandle_t xQueue,
+                             void * const pvBuffer,
+                             TickType_t xTicksToWait
+                         );
+ * + * Receive an item from a queue without removing the item from the queue. + * The item is received by copy so a buffer of adequate size must be + * provided. The number of bytes copied into the buffer was defined when + * the queue was created. + * + * Successfully received items remain on the queue so will be returned again + * by the next call, or a call to xQueueReceive(). + * + * This macro must not be used in an interrupt service routine. See + * xQueuePeekFromISR() for an alternative that can be called from an interrupt + * service routine. + * + * @param xQueue The handle to the queue from which the item is to be + * received. + * + * @param pvBuffer Pointer to the buffer into which the received item will + * be copied. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for an item to receive should the queue be empty at the time + * of the call. The time is defined in tick periods so the constant + * portTICK_PERIOD_MS should be used to convert to real time if this is required. + * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue + * is empty. + * + * @return pdTRUE if an item was successfully received from the queue, + * otherwise pdFALSE. + * + * Example usage: +
+ struct AMessage
+ {
+    char ucMessageID;
+    char ucData[ 20 ];
+ } xMessage;
+
+ QueueHandle_t xQueue;
+
+ // Task to create a queue and post a value.
+ void vATask( void *pvParameters )
+ {
+ struct AMessage *pxMessage;
+
+    // Create a queue capable of containing 10 pointers to AMessage structures.
+    // These should be passed by pointer as they contain a lot of data.
+    xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
+    if( xQueue == 0 )
+    {
+        // Failed to create the queue.
+    }
+
+    // ...
+
+    // Send a pointer to a struct AMessage object.  Don't block if the
+    // queue is already full.
+    pxMessage = & xMessage;
+    xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
+
+    // ... Rest of task code.
+ }
+
+ // Task to peek the data from the queue.
+ void vADifferentTask( void *pvParameters )
+ {
+ struct AMessage *pxRxedMessage;
+
+    if( xQueue != 0 )
+    {
+        // Peek a message on the created queue.  Block for 10 ticks if a
+        // message is not immediately available.
+        if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
+        {
+            // pcRxedMessage now points to the struct AMessage variable posted
+            // by vATask, but the item still remains on the queue.
+        }
+    }
+
+    // ... Rest of task code.
+ }
+ 
+ * \defgroup xQueuePeek xQueuePeek + * \ingroup QueueManagement + */ +BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ BaseType_t xQueuePeekFromISR(
+                                    QueueHandle_t xQueue,
+                                    void *pvBuffer,
+                                );
+ * + * A version of xQueuePeek() that can be called from an interrupt service + * routine (ISR). + * + * Receive an item from a queue without removing the item from the queue. + * The item is received by copy so a buffer of adequate size must be + * provided. The number of bytes copied into the buffer was defined when + * the queue was created. + * + * Successfully received items remain on the queue so will be returned again + * by the next call, or a call to xQueueReceive(). + * + * @param xQueue The handle to the queue from which the item is to be + * received. + * + * @param pvBuffer Pointer to the buffer into which the received item will + * be copied. + * + * @return pdTRUE if an item was successfully received from the queue, + * otherwise pdFALSE. + * + * \defgroup xQueuePeekFromISR xQueuePeekFromISR + * \ingroup QueueManagement + */ +BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ BaseType_t xQueueReceive(
+                                 QueueHandle_t xQueue,
+                                 void *pvBuffer,
+                                 TickType_t xTicksToWait
+                            );
+ * + * Receive an item from a queue. The item is received by copy so a buffer of + * adequate size must be provided. The number of bytes copied into the buffer + * was defined when the queue was created. + * + * Successfully received items are removed from the queue. + * + * This function must not be used in an interrupt service routine. See + * xQueueReceiveFromISR for an alternative that can. + * + * @param xQueue The handle to the queue from which the item is to be + * received. + * + * @param pvBuffer Pointer to the buffer into which the received item will + * be copied. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for an item to receive should the queue be empty at the time + * of the call. xQueueReceive() will return immediately if xTicksToWait + * is zero and the queue is empty. The time is defined in tick periods so the + * constant portTICK_PERIOD_MS should be used to convert to real time if this is + * required. + * + * @return pdTRUE if an item was successfully received from the queue, + * otherwise pdFALSE. + * + * Example usage: +
+ struct AMessage
+ {
+    char ucMessageID;
+    char ucData[ 20 ];
+ } xMessage;
+
+ QueueHandle_t xQueue;
+
+ // Task to create a queue and post a value.
+ void vATask( void *pvParameters )
+ {
+ struct AMessage *pxMessage;
+
+    // Create a queue capable of containing 10 pointers to AMessage structures.
+    // These should be passed by pointer as they contain a lot of data.
+    xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
+    if( xQueue == 0 )
+    {
+        // Failed to create the queue.
+    }
+
+    // ...
+
+    // Send a pointer to a struct AMessage object.  Don't block if the
+    // queue is already full.
+    pxMessage = & xMessage;
+    xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
+
+    // ... Rest of task code.
+ }
+
+ // Task to receive from the queue.
+ void vADifferentTask( void *pvParameters )
+ {
+ struct AMessage *pxRxedMessage;
+
+    if( xQueue != 0 )
+    {
+        // Receive a message on the created queue.  Block for 10 ticks if a
+        // message is not immediately available.
+        if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
+        {
+            // pcRxedMessage now points to the struct AMessage variable posted
+            // by vATask.
+        }
+    }
+
+    // ... Rest of task code.
+ }
+ 
+ * \defgroup xQueueReceive xQueueReceive + * \ingroup QueueManagement + */ +BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );
+ * + * Return the number of messages stored in a queue. + * + * @param xQueue A handle to the queue being queried. + * + * @return The number of messages available in the queue. + * + * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting + * \ingroup QueueManagement + */ +UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );
+ * + * Return the number of free spaces available in a queue. This is equal to the + * number of items that can be sent to the queue before the queue becomes full + * if no items are removed. + * + * @param xQueue A handle to the queue being queried. + * + * @return The number of spaces available in the queue. + * + * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting + * \ingroup QueueManagement + */ +UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
void vQueueDelete( QueueHandle_t xQueue );
+ * + * Delete a queue - freeing all the memory allocated for storing of items + * placed on the queue. + * + * @param xQueue A handle to the queue to be deleted. + * + * \defgroup vQueueDelete vQueueDelete + * \ingroup QueueManagement + */ +void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ BaseType_t xQueueSendToFrontFromISR(
+                                         QueueHandle_t xQueue,
+                                         const void *pvItemToQueue,
+                                         BaseType_t *pxHigherPriorityTaskWoken
+                                      );
+ 
+ * + * This is a macro that calls xQueueGenericSendFromISR(). + * + * Post an item to the front of a queue. It is safe to use this macro from + * within an interrupt service routine. + * + * Items are queued by copy not reference so it is preferable to only + * queue small items, especially when called from an ISR. In most cases + * it would be preferable to store a pointer to the item being queued. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the data was successfully sent to the queue, otherwise + * errQUEUE_FULL. + * + * Example usage for buffered IO (where the ISR can obtain more than one value + * per call): +
+ void vBufferISR( void )
+ {
+ char cIn;
+ BaseType_t xHigherPrioritTaskWoken;
+
+    // We have not woken a task at the start of the ISR.
+    xHigherPriorityTaskWoken = pdFALSE;
+
+    // Loop until the buffer is empty.
+    do
+    {
+        // Obtain a byte from the buffer.
+        cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
+
+        // Post the byte.
+        xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
+
+    } while( portINPUT_BYTE( BUFFER_COUNT ) );
+
+    // Now the buffer is empty we can switch context if necessary.
+    if( xHigherPriorityTaskWoken )
+    {
+        taskYIELD ();
+    }
+ }
+ 
+ * + * \defgroup xQueueSendFromISR xQueueSendFromISR + * \ingroup QueueManagement + */ +#define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT ) + + +/** + * queue. h + *
+ BaseType_t xQueueSendToBackFromISR(
+                                         QueueHandle_t xQueue,
+                                         const void *pvItemToQueue,
+                                         BaseType_t *pxHigherPriorityTaskWoken
+                                      );
+ 
+ * + * This is a macro that calls xQueueGenericSendFromISR(). + * + * Post an item to the back of a queue. It is safe to use this macro from + * within an interrupt service routine. + * + * Items are queued by copy not reference so it is preferable to only + * queue small items, especially when called from an ISR. In most cases + * it would be preferable to store a pointer to the item being queued. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the data was successfully sent to the queue, otherwise + * errQUEUE_FULL. + * + * Example usage for buffered IO (where the ISR can obtain more than one value + * per call): +
+ void vBufferISR( void )
+ {
+ char cIn;
+ BaseType_t xHigherPriorityTaskWoken;
+
+    // We have not woken a task at the start of the ISR.
+    xHigherPriorityTaskWoken = pdFALSE;
+
+    // Loop until the buffer is empty.
+    do
+    {
+        // Obtain a byte from the buffer.
+        cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
+
+        // Post the byte.
+        xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
+
+    } while( portINPUT_BYTE( BUFFER_COUNT ) );
+
+    // Now the buffer is empty we can switch context if necessary.
+    if( xHigherPriorityTaskWoken )
+    {
+        taskYIELD ();
+    }
+ }
+ 
+ * + * \defgroup xQueueSendFromISR xQueueSendFromISR + * \ingroup QueueManagement + */ +#define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK ) + +/** + * queue. h + *
+ BaseType_t xQueueOverwriteFromISR(
+                              QueueHandle_t xQueue,
+                              const void * pvItemToQueue,
+                              BaseType_t *pxHigherPriorityTaskWoken
+                         );
+ * 
+ * + * A version of xQueueOverwrite() that can be used in an interrupt service + * routine (ISR). + * + * Only for use with queues that can hold a single item - so the queue is either + * empty or full. + * + * Post an item on a queue. If the queue is already full then overwrite the + * value held in the queue. The item is queued by copy, not by reference. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return xQueueOverwriteFromISR() is a macro that calls + * xQueueGenericSendFromISR(), and therefore has the same return values as + * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be + * returned because xQueueOverwriteFromISR() will write to the queue even when + * the queue is already full. + * + * Example usage: +
+
+ QueueHandle_t xQueue;
+
+ void vFunction( void *pvParameters )
+ {
+     // Create a queue to hold one uint32_t value.  It is strongly
+    // recommended *not* to use xQueueOverwriteFromISR() on queues that can
+    // contain more than one value, and doing so will trigger an assertion
+    // if configASSERT() is defined.
+    xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
+}
+
+void vAnInterruptHandler( void )
+{
+// xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
+BaseType_t xHigherPriorityTaskWoken = pdFALSE;
+uint32_t ulVarToSend, ulValReceived;
+
+    // Write the value 10 to the queue using xQueueOverwriteFromISR().
+    ulVarToSend = 10;
+    xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
+
+    // The queue is full, but calling xQueueOverwriteFromISR() again will still
+    // pass because the value held in the queue will be overwritten with the
+    // new value.
+    ulVarToSend = 100;
+    xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
+
+    // Reading from the queue will now return 100.
+
+    // ...
+
+    if( xHigherPrioritytaskWoken == pdTRUE )
+    {
+        // Writing to the queue caused a task to unblock and the unblocked task
+        // has a priority higher than or equal to the priority of the currently
+        // executing task (the task this interrupt interrupted).  Perform a context
+        // switch so this interrupt returns directly to the unblocked task.
+        portYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port.
+    }
+}
+ 
+ * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR + * \ingroup QueueManagement + */ +#define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE ) + +/** + * queue. h + *
+ BaseType_t xQueueSendFromISR(
+                                     QueueHandle_t xQueue,
+                                     const void *pvItemToQueue,
+                                     BaseType_t *pxHigherPriorityTaskWoken
+                                );
+ 
+ * + * This is a macro that calls xQueueGenericSendFromISR(). It is included + * for backward compatibility with versions of FreeRTOS.org that did not + * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR() + * macros. + * + * Post an item to the back of a queue. It is safe to use this function from + * within an interrupt service routine. + * + * Items are queued by copy not reference so it is preferable to only + * queue small items, especially when called from an ISR. In most cases + * it would be preferable to store a pointer to the item being queued. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xQueueSendFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the data was successfully sent to the queue, otherwise + * errQUEUE_FULL. + * + * Example usage for buffered IO (where the ISR can obtain more than one value + * per call): +
+ void vBufferISR( void )
+ {
+ char cIn;
+ BaseType_t xHigherPriorityTaskWoken;
+
+    // We have not woken a task at the start of the ISR.
+    xHigherPriorityTaskWoken = pdFALSE;
+
+    // Loop until the buffer is empty.
+    do
+    {
+        // Obtain a byte from the buffer.
+        cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
+
+        // Post the byte.
+        xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
+
+    } while( portINPUT_BYTE( BUFFER_COUNT ) );
+
+    // Now the buffer is empty we can switch context if necessary.
+    if( xHigherPriorityTaskWoken )
+    {
+        // Actual macro used here is port specific.
+        portYIELD_FROM_ISR ();
+    }
+ }
+ 
+ * + * \defgroup xQueueSendFromISR xQueueSendFromISR + * \ingroup QueueManagement + */ +#define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK ) + +/** + * queue. h + *
+ BaseType_t xQueueGenericSendFromISR(
+                                           QueueHandle_t        xQueue,
+                                           const    void    *pvItemToQueue,
+                                           BaseType_t    *pxHigherPriorityTaskWoken,
+                                           BaseType_t    xCopyPosition
+                                       );
+ 
+ * + * It is preferred that the macros xQueueSendFromISR(), + * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place + * of calling this function directly. xQueueGiveFromISR() is an + * equivalent for use by semaphores that don't actually copy any data. + * + * Post an item on a queue. It is safe to use this function from within an + * interrupt service routine. + * + * Items are queued by copy not reference so it is preferable to only + * queue small items, especially when called from an ISR. In most cases + * it would be preferable to store a pointer to the item being queued. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the + * item at the back of the queue, or queueSEND_TO_FRONT to place the item + * at the front of the queue (for high priority messages). + * + * @return pdTRUE if the data was successfully sent to the queue, otherwise + * errQUEUE_FULL. + * + * Example usage for buffered IO (where the ISR can obtain more than one value + * per call): +
+ void vBufferISR( void )
+ {
+ char cIn;
+ BaseType_t xHigherPriorityTaskWokenByPost;
+
+    // We have not woken a task at the start of the ISR.
+    xHigherPriorityTaskWokenByPost = pdFALSE;
+
+    // Loop until the buffer is empty.
+    do
+    {
+        // Obtain a byte from the buffer.
+        cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
+
+        // Post each byte.
+        xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
+
+    } while( portINPUT_BYTE( BUFFER_COUNT ) );
+
+    // Now the buffer is empty we can switch context if necessary.  Note that the
+    // name of the yield function required is port specific.
+    if( xHigherPriorityTaskWokenByPost )
+    {
+        taskYIELD_YIELD_FROM_ISR();
+    }
+ }
+ 
+ * + * \defgroup xQueueSendFromISR xQueueSendFromISR + * \ingroup QueueManagement + */ +BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION; +BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ BaseType_t xQueueReceiveFromISR(
+                                       QueueHandle_t    xQueue,
+                                       void    *pvBuffer,
+                                       BaseType_t *pxTaskWoken
+                                   );
+ * 
+ * + * Receive an item from a queue. It is safe to use this function from within an + * interrupt service routine. + * + * @param xQueue The handle to the queue from which the item is to be + * received. + * + * @param pvBuffer Pointer to the buffer into which the received item will + * be copied. + * + * @param pxTaskWoken A task may be blocked waiting for space to become + * available on the queue. If xQueueReceiveFromISR causes such a task to + * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will + * remain unchanged. + * + * @return pdTRUE if an item was successfully received from the queue, + * otherwise pdFALSE. + * + * Example usage: +
+
+ QueueHandle_t xQueue;
+
+ // Function to create a queue and post some values.
+ void vAFunction( void *pvParameters )
+ {
+ char cValueToPost;
+ const TickType_t xTicksToWait = ( TickType_t )0xff;
+
+    // Create a queue capable of containing 10 characters.
+    xQueue = xQueueCreate( 10, sizeof( char ) );
+    if( xQueue == 0 )
+    {
+        // Failed to create the queue.
+    }
+
+    // ...
+
+    // Post some characters that will be used within an ISR.  If the queue
+    // is full then this task will block for xTicksToWait ticks.
+    cValueToPost = 'a';
+    xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
+    cValueToPost = 'b';
+    xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
+
+    // ... keep posting characters ... this task may block when the queue
+    // becomes full.
+
+    cValueToPost = 'c';
+    xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
+ }
+
+ // ISR that outputs all the characters received on the queue.
+ void vISR_Routine( void )
+ {
+ BaseType_t xTaskWokenByReceive = pdFALSE;
+ char cRxedChar;
+
+    while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
+    {
+        // A character was received.  Output the character now.
+        vOutputCharacter( cRxedChar );
+
+        // If removing the character from the queue woke the task that was
+        // posting onto the queue cTaskWokenByReceive will have been set to
+        // pdTRUE.  No matter how many times this loop iterates only one
+        // task will be woken.
+    }
+
+    if( cTaskWokenByPost != ( char ) pdFALSE;
+    {
+        taskYIELD ();
+    }
+ }
+ 
+ * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR + * \ingroup QueueManagement + */ +BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/* + * Utilities to query queues that are safe to use from an ISR. These utilities + * should be used only from witin an ISR, or within a critical section. + */ +BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; +BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; +UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; + +/* + * The functions defined above are for passing data to and from tasks. The + * functions below are the equivalents for passing data to and from + * co-routines. + * + * These functions are called from the co-routine macro implementation and + * should not be called directly from application code. Instead use the macro + * wrappers defined within croutine.h. + */ +BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t xCoRoutinePreviouslyWoken ); +BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxTaskWoken ); +BaseType_t xQueueCRSend( QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait ); +BaseType_t xQueueCRReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait ); + +/* + * For internal use only. Use xSemaphoreCreateMutex(), + * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling + * these functions directly. + */ +QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; +QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION; +QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION; +QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION; +BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; +void* xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION; +void* xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION; + +/* + * For internal use only. Use xSemaphoreTakeMutexRecursive() or + * xSemaphoreGiveMutexRecursive() instead of calling these functions directly. + */ +BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; +BaseType_t xQueueGiveMutexRecursive( QueueHandle_t pxMutex ) PRIVILEGED_FUNCTION; + +/* + * Reset a queue back to its original empty state. The return value is now + * obsolete and is always set to pdPASS. + */ +#define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE ) + +/* + * The registry is provided as a means for kernel aware debuggers to + * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add + * a queue, semaphore or mutex handle to the registry if you want the handle + * to be available to a kernel aware debugger. If you are not using a kernel + * aware debugger then this function can be ignored. + * + * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the + * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0 + * within FreeRTOSConfig.h for the registry to be available. Its value + * does not effect the number of queues, semaphores and mutexes that can be + * created - just the number that the registry can hold. + * + * @param xQueue The handle of the queue being added to the registry. This + * is the handle returned by a call to xQueueCreate(). Semaphore and mutex + * handles can also be passed in here. + * + * @param pcName The name to be associated with the handle. This is the + * name that the kernel aware debugger will display. The queue registry only + * stores a pointer to the string - so the string must be persistent (global or + * preferably in ROM/Flash), not on the stack. + */ +#if( configQUEUE_REGISTRY_SIZE > 0 ) + void vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ +#endif + +/* + * The registry is provided as a means for kernel aware debuggers to + * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add + * a queue, semaphore or mutex handle to the registry if you want the handle + * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to + * remove the queue, semaphore or mutex from the register. If you are not using + * a kernel aware debugger then this function can be ignored. + * + * @param xQueue The handle of the queue being removed from the registry. + */ +#if( configQUEUE_REGISTRY_SIZE > 0 ) + void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; +#endif + +/* + * The queue registry is provided as a means for kernel aware debuggers to + * locate queues, semaphores and mutexes. Call pcQueueGetName() to look + * up and return the name of a queue in the queue registry from the queue's + * handle. + * + * @param xQueue The handle of the queue the name of which will be returned. + * @return If the queue is in the registry then a pointer to the name of the + * queue is returned. If the queue is not in the registry then NULL is + * returned. + */ +#if( configQUEUE_REGISTRY_SIZE > 0 ) + const char *pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ +#endif + +/* + * Generic version of the function used to creaet a queue using dynamic memory + * allocation. This is called by other functions and macros that create other + * RTOS objects that use the queue structure as their base. + */ +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; +#endif + +/* + * Generic version of the function used to creaet a queue using dynamic memory + * allocation. This is called by other functions and macros that create other + * RTOS objects that use the queue structure as their base. + */ +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; +#endif + +/* + * Queue sets provide a mechanism to allow a task to block (pend) on a read + * operation from multiple queues or semaphores simultaneously. + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * A queue set must be explicitly created using a call to xQueueCreateSet() + * before it can be used. Once created, standard FreeRTOS queues and semaphores + * can be added to the set using calls to xQueueAddToSet(). + * xQueueSelectFromSet() is then used to determine which, if any, of the queues + * or semaphores contained in the set is in a state where a queue read or + * semaphore take operation would be successful. + * + * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html + * for reasons why queue sets are very rarely needed in practice as there are + * simpler methods of blocking on multiple objects. + * + * Note 2: Blocking on a queue set that contains a mutex will not cause the + * mutex holder to inherit the priority of the blocked task. + * + * Note 3: An additional 4 bytes of RAM is required for each space in a every + * queue added to a queue set. Therefore counting semaphores that have a high + * maximum count value should not be added to a queue set. + * + * Note 4: A receive (in the case of a queue) or take (in the case of a + * semaphore) operation must not be performed on a member of a queue set unless + * a call to xQueueSelectFromSet() has first returned a handle to that set member. + * + * @param uxEventQueueLength Queue sets store events that occur on + * the queues and semaphores contained in the set. uxEventQueueLength specifies + * the maximum number of events that can be queued at once. To be absolutely + * certain that events are not lost uxEventQueueLength should be set to the + * total sum of the length of the queues added to the set, where binary + * semaphores and mutexes have a length of 1, and counting semaphores have a + * length set by their maximum count value. Examples: + * + If a queue set is to hold a queue of length 5, another queue of length 12, + * and a binary semaphore, then uxEventQueueLength should be set to + * (5 + 12 + 1), or 18. + * + If a queue set is to hold three binary semaphores then uxEventQueueLength + * should be set to (1 + 1 + 1 ), or 3. + * + If a queue set is to hold a counting semaphore that has a maximum count of + * 5, and a counting semaphore that has a maximum count of 3, then + * uxEventQueueLength should be set to (5 + 3), or 8. + * + * @return If the queue set is created successfully then a handle to the created + * queue set is returned. Otherwise NULL is returned. + */ +QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION; + +/* + * Adds a queue or semaphore to a queue set that was previously created by a + * call to xQueueCreateSet(). + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * Note 1: A receive (in the case of a queue) or take (in the case of a + * semaphore) operation must not be performed on a member of a queue set unless + * a call to xQueueSelectFromSet() has first returned a handle to that set member. + * + * @param xQueueOrSemaphore The handle of the queue or semaphore being added to + * the queue set (cast to an QueueSetMemberHandle_t type). + * + * @param xQueueSet The handle of the queue set to which the queue or semaphore + * is being added. + * + * @return If the queue or semaphore was successfully added to the queue set + * then pdPASS is returned. If the queue could not be successfully added to the + * queue set because it is already a member of a different queue set then pdFAIL + * is returned. + */ +BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION; + +/* + * Removes a queue or semaphore from a queue set. A queue or semaphore can only + * be removed from a set if the queue or semaphore is empty. + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * @param xQueueOrSemaphore The handle of the queue or semaphore being removed + * from the queue set (cast to an QueueSetMemberHandle_t type). + * + * @param xQueueSet The handle of the queue set in which the queue or semaphore + * is included. + * + * @return If the queue or semaphore was successfully removed from the queue set + * then pdPASS is returned. If the queue was not in the queue set, or the + * queue (or semaphore) was not empty, then pdFAIL is returned. + */ +BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION; + +/* + * xQueueSelectFromSet() selects from the members of a queue set a queue or + * semaphore that either contains data (in the case of a queue) or is available + * to take (in the case of a semaphore). xQueueSelectFromSet() effectively + * allows a task to block (pend) on a read operation on all the queues and + * semaphores in a queue set simultaneously. + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html + * for reasons why queue sets are very rarely needed in practice as there are + * simpler methods of blocking on multiple objects. + * + * Note 2: Blocking on a queue set that contains a mutex will not cause the + * mutex holder to inherit the priority of the blocked task. + * + * Note 3: A receive (in the case of a queue) or take (in the case of a + * semaphore) operation must not be performed on a member of a queue set unless + * a call to xQueueSelectFromSet() has first returned a handle to that set member. + * + * @param xQueueSet The queue set on which the task will (potentially) block. + * + * @param xTicksToWait The maximum time, in ticks, that the calling task will + * remain in the Blocked state (with other tasks executing) to wait for a member + * of the queue set to be ready for a successful queue read or semaphore take + * operation. + * + * @return xQueueSelectFromSet() will return the handle of a queue (cast to + * a QueueSetMemberHandle_t type) contained in the queue set that contains data, + * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained + * in the queue set that is available, or NULL if no such queue or semaphore + * exists before before the specified block time expires. + */ +QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/* + * A version of xQueueSelectFromSet() that can be used from an ISR. + */ +QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION; + +/* Not public API functions. */ +void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION; +BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ) PRIVILEGED_FUNCTION; +void vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION; +UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; +uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; + + +#ifdef __cplusplus +} +#endif + +#endif /* QUEUE_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/semphr.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/semphr.h new file mode 100644 index 0000000..8b0382d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/semphr.h @@ -0,0 +1,1140 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef SEMAPHORE_H +#define SEMAPHORE_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h" must appear in source files before "include semphr.h" +#endif + +#include "queue.h" + +typedef QueueHandle_t SemaphoreHandle_t; + +#define semBINARY_SEMAPHORE_QUEUE_LENGTH ( ( uint8_t ) 1U ) +#define semSEMAPHORE_QUEUE_ITEM_LENGTH ( ( uint8_t ) 0U ) +#define semGIVE_BLOCK_TIME ( ( TickType_t ) 0U ) + + +/** + * semphr. h + *
vSemaphoreCreateBinary( SemaphoreHandle_t xSemaphore )
+ * + * In many usage scenarios it is faster and more memory efficient to use a + * direct to task notification in place of a binary semaphore! + * http://www.freertos.org/RTOS-task-notifications.html + * + * This old vSemaphoreCreateBinary() macro is now deprecated in favour of the + * xSemaphoreCreateBinary() function. Note that binary semaphores created using + * the vSemaphoreCreateBinary() macro are created in a state such that the + * first call to 'take' the semaphore would pass, whereas binary semaphores + * created using xSemaphoreCreateBinary() are created in a state such that the + * the semaphore must first be 'given' before it can be 'taken'. + * + * Macro that implements a semaphore by using the existing queue mechanism. + * The queue length is 1 as this is a binary semaphore. The data size is 0 + * as we don't want to actually store any data - we just want to know if the + * queue is empty or full. + * + * This type of semaphore can be used for pure synchronisation between tasks or + * between an interrupt and a task. The semaphore need not be given back once + * obtained, so one task/interrupt can continuously 'give' the semaphore while + * another continuously 'takes' the semaphore. For this reason this type of + * semaphore does not use a priority inheritance mechanism. For an alternative + * that does use priority inheritance see xSemaphoreCreateMutex(). + * + * @param xSemaphore Handle to the created semaphore. Should be of type SemaphoreHandle_t. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore = NULL;
+
+ void vATask( void * pvParameters )
+ {
+    // Semaphore cannot be used before a call to vSemaphoreCreateBinary ().
+    // This is a macro so pass the variable in directly.
+    vSemaphoreCreateBinary( xSemaphore );
+
+    if( xSemaphore != NULL )
+    {
+        // The semaphore was created successfully.
+        // The semaphore can now be used.
+    }
+ }
+ 
+ * \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary + * \ingroup Semaphores + */ +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + #define vSemaphoreCreateBinary( xSemaphore ) \ + { \ + ( xSemaphore ) = xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE ); \ + if( ( xSemaphore ) != NULL ) \ + { \ + ( void ) xSemaphoreGive( ( xSemaphore ) ); \ + } \ + } +#endif + +/** + * semphr. h + *
SemaphoreHandle_t xSemaphoreCreateBinary( void )
+ * + * Creates a new binary semaphore instance, and returns a handle by which the + * new semaphore can be referenced. + * + * In many usage scenarios it is faster and more memory efficient to use a + * direct to task notification in place of a binary semaphore! + * http://www.freertos.org/RTOS-task-notifications.html + * + * Internally, within the FreeRTOS implementation, binary semaphores use a block + * of memory, in which the semaphore structure is stored. If a binary semaphore + * is created using xSemaphoreCreateBinary() then the required memory is + * automatically dynamically allocated inside the xSemaphoreCreateBinary() + * function. (see http://www.freertos.org/a00111.html). If a binary semaphore + * is created using xSemaphoreCreateBinaryStatic() then the application writer + * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a + * binary semaphore to be created without using any dynamic memory allocation. + * + * The old vSemaphoreCreateBinary() macro is now deprecated in favour of this + * xSemaphoreCreateBinary() function. Note that binary semaphores created using + * the vSemaphoreCreateBinary() macro are created in a state such that the + * first call to 'take' the semaphore would pass, whereas binary semaphores + * created using xSemaphoreCreateBinary() are created in a state such that the + * the semaphore must first be 'given' before it can be 'taken'. + * + * This type of semaphore can be used for pure synchronisation between tasks or + * between an interrupt and a task. The semaphore need not be given back once + * obtained, so one task/interrupt can continuously 'give' the semaphore while + * another continuously 'takes' the semaphore. For this reason this type of + * semaphore does not use a priority inheritance mechanism. For an alternative + * that does use priority inheritance see xSemaphoreCreateMutex(). + * + * @return Handle to the created semaphore, or NULL if the memory required to + * hold the semaphore's data structures could not be allocated. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore = NULL;
+
+ void vATask( void * pvParameters )
+ {
+    // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
+    // This is a macro so pass the variable in directly.
+    xSemaphore = xSemaphoreCreateBinary();
+
+    if( xSemaphore != NULL )
+    {
+        // The semaphore was created successfully.
+        // The semaphore can now be used.
+    }
+ }
+ 
+ * \defgroup xSemaphoreCreateBinary xSemaphoreCreateBinary + * \ingroup Semaphores + */ +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + #define xSemaphoreCreateBinary() xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE ) +#endif + +/** + * semphr. h + *
SemaphoreHandle_t xSemaphoreCreateBinaryStatic( StaticSemaphore_t *pxSemaphoreBuffer )
+ * + * Creates a new binary semaphore instance, and returns a handle by which the + * new semaphore can be referenced. + * + * NOTE: In many usage scenarios it is faster and more memory efficient to use a + * direct to task notification in place of a binary semaphore! + * http://www.freertos.org/RTOS-task-notifications.html + * + * Internally, within the FreeRTOS implementation, binary semaphores use a block + * of memory, in which the semaphore structure is stored. If a binary semaphore + * is created using xSemaphoreCreateBinary() then the required memory is + * automatically dynamically allocated inside the xSemaphoreCreateBinary() + * function. (see http://www.freertos.org/a00111.html). If a binary semaphore + * is created using xSemaphoreCreateBinaryStatic() then the application writer + * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a + * binary semaphore to be created without using any dynamic memory allocation. + * + * This type of semaphore can be used for pure synchronisation between tasks or + * between an interrupt and a task. The semaphore need not be given back once + * obtained, so one task/interrupt can continuously 'give' the semaphore while + * another continuously 'takes' the semaphore. For this reason this type of + * semaphore does not use a priority inheritance mechanism. For an alternative + * that does use priority inheritance see xSemaphoreCreateMutex(). + * + * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t, + * which will then be used to hold the semaphore's data structure, removing the + * need for the memory to be allocated dynamically. + * + * @return If the semaphore is created then a handle to the created semaphore is + * returned. If pxSemaphoreBuffer is NULL then NULL is returned. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore = NULL;
+ StaticSemaphore_t xSemaphoreBuffer;
+
+ void vATask( void * pvParameters )
+ {
+    // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
+    // The semaphore's data structures will be placed in the xSemaphoreBuffer
+    // variable, the address of which is passed into the function.  The
+    // function's parameter is not NULL, so the function will not attempt any
+    // dynamic memory allocation, and therefore the function will not return
+    // return NULL.
+    xSemaphore = xSemaphoreCreateBinary( &xSemaphoreBuffer );
+
+    // Rest of task code goes here.
+ }
+ 
+ * \defgroup xSemaphoreCreateBinaryStatic xSemaphoreCreateBinaryStatic + * \ingroup Semaphores + */ +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xSemaphoreCreateBinaryStatic( pxStaticSemaphore ) xQueueGenericCreateStatic( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticSemaphore, queueQUEUE_TYPE_BINARY_SEMAPHORE ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * semphr. h + *
xSemaphoreTake(
+ *                   SemaphoreHandle_t xSemaphore,
+ *                   TickType_t xBlockTime
+ *               )
+ * + * Macro to obtain a semaphore. The semaphore must have previously been + * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or + * xSemaphoreCreateCounting(). + * + * @param xSemaphore A handle to the semaphore being taken - obtained when + * the semaphore was created. + * + * @param xBlockTime The time in ticks to wait for the semaphore to become + * available. The macro portTICK_PERIOD_MS can be used to convert this to a + * real time. A block time of zero can be used to poll the semaphore. A block + * time of portMAX_DELAY can be used to block indefinitely (provided + * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h). + * + * @return pdTRUE if the semaphore was obtained. pdFALSE + * if xBlockTime expired without the semaphore becoming available. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore = NULL;
+
+ // A task that creates a semaphore.
+ void vATask( void * pvParameters )
+ {
+    // Create the semaphore to guard a shared resource.
+    xSemaphore = xSemaphoreCreateBinary();
+ }
+
+ // A task that uses the semaphore.
+ void vAnotherTask( void * pvParameters )
+ {
+    // ... Do other things.
+
+    if( xSemaphore != NULL )
+    {
+        // See if we can obtain the semaphore.  If the semaphore is not available
+        // wait 10 ticks to see if it becomes free.
+        if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
+        {
+            // We were able to obtain the semaphore and can now access the
+            // shared resource.
+
+            // ...
+
+            // We have finished accessing the shared resource.  Release the
+            // semaphore.
+            xSemaphoreGive( xSemaphore );
+        }
+        else
+        {
+            // We could not obtain the semaphore and can therefore not access
+            // the shared resource safely.
+        }
+    }
+ }
+ 
+ * \defgroup xSemaphoreTake xSemaphoreTake + * \ingroup Semaphores + */ +#define xSemaphoreTake( xSemaphore, xBlockTime ) xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) ) + +/** + * semphr. h + * xSemaphoreTakeRecursive( + * SemaphoreHandle_t xMutex, + * TickType_t xBlockTime + * ) + * + * Macro to recursively obtain, or 'take', a mutex type semaphore. + * The mutex must have previously been created using a call to + * xSemaphoreCreateRecursiveMutex(); + * + * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this + * macro to be available. + * + * This macro must not be used on mutexes created using xSemaphoreCreateMutex(). + * + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex + * doesn't become available again until the owner has called + * xSemaphoreGiveRecursive() for each successful 'take' request. For example, + * if a task successfully 'takes' the same mutex 5 times then the mutex will + * not be available to any other task until it has also 'given' the mutex back + * exactly five times. + * + * @param xMutex A handle to the mutex being obtained. This is the + * handle returned by xSemaphoreCreateRecursiveMutex(); + * + * @param xBlockTime The time in ticks to wait for the semaphore to become + * available. The macro portTICK_PERIOD_MS can be used to convert this to a + * real time. A block time of zero can be used to poll the semaphore. If + * the task already owns the semaphore then xSemaphoreTakeRecursive() will + * return immediately no matter what the value of xBlockTime. + * + * @return pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime + * expired without the semaphore becoming available. + * + * Example usage: +
+ SemaphoreHandle_t xMutex = NULL;
+
+ // A task that creates a mutex.
+ void vATask( void * pvParameters )
+ {
+    // Create the mutex to guard a shared resource.
+    xMutex = xSemaphoreCreateRecursiveMutex();
+ }
+
+ // A task that uses the mutex.
+ void vAnotherTask( void * pvParameters )
+ {
+    // ... Do other things.
+
+    if( xMutex != NULL )
+    {
+        // See if we can obtain the mutex.  If the mutex is not available
+        // wait 10 ticks to see if it becomes free.
+        if( xSemaphoreTakeRecursive( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
+        {
+            // We were able to obtain the mutex and can now access the
+            // shared resource.
+
+            // ...
+            // For some reason due to the nature of the code further calls to
+            // xSemaphoreTakeRecursive() are made on the same mutex.  In real
+            // code these would not be just sequential calls as this would make
+            // no sense.  Instead the calls are likely to be buried inside
+            // a more complex call structure.
+            xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
+            xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
+
+            // The mutex has now been 'taken' three times, so will not be
+            // available to another task until it has also been given back
+            // three times.  Again it is unlikely that real code would have
+            // these calls sequentially, but instead buried in a more complex
+            // call structure.  This is just for illustrative purposes.
+            xSemaphoreGiveRecursive( xMutex );
+            xSemaphoreGiveRecursive( xMutex );
+            xSemaphoreGiveRecursive( xMutex );
+
+            // Now the mutex can be taken by other tasks.
+        }
+        else
+        {
+            // We could not obtain the mutex and can therefore not access
+            // the shared resource safely.
+        }
+    }
+ }
+ 
+ * \defgroup xSemaphoreTakeRecursive xSemaphoreTakeRecursive + * \ingroup Semaphores + */ +#if( configUSE_RECURSIVE_MUTEXES == 1 ) + #define xSemaphoreTakeRecursive( xMutex, xBlockTime ) xQueueTakeMutexRecursive( ( xMutex ), ( xBlockTime ) ) +#endif + +/** + * semphr. h + *
xSemaphoreGive( SemaphoreHandle_t xSemaphore )
+ * + * Macro to release a semaphore. The semaphore must have previously been + * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or + * xSemaphoreCreateCounting(). and obtained using sSemaphoreTake(). + * + * This macro must not be used from an ISR. See xSemaphoreGiveFromISR () for + * an alternative which can be used from an ISR. + * + * This macro must also not be used on semaphores created using + * xSemaphoreCreateRecursiveMutex(). + * + * @param xSemaphore A handle to the semaphore being released. This is the + * handle returned when the semaphore was created. + * + * @return pdTRUE if the semaphore was released. pdFALSE if an error occurred. + * Semaphores are implemented using queues. An error can occur if there is + * no space on the queue to post a message - indicating that the + * semaphore was not first obtained correctly. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore = NULL;
+
+ void vATask( void * pvParameters )
+ {
+    // Create the semaphore to guard a shared resource.
+    xSemaphore = vSemaphoreCreateBinary();
+
+    if( xSemaphore != NULL )
+    {
+        if( xSemaphoreGive( xSemaphore ) != pdTRUE )
+        {
+            // We would expect this call to fail because we cannot give
+            // a semaphore without first "taking" it!
+        }
+
+        // Obtain the semaphore - don't block if the semaphore is not
+        // immediately available.
+        if( xSemaphoreTake( xSemaphore, ( TickType_t ) 0 ) )
+        {
+            // We now have the semaphore and can access the shared resource.
+
+            // ...
+
+            // We have finished accessing the shared resource so can free the
+            // semaphore.
+            if( xSemaphoreGive( xSemaphore ) != pdTRUE )
+            {
+                // We would not expect this call to fail because we must have
+                // obtained the semaphore to get here.
+            }
+        }
+    }
+ }
+ 
+ * \defgroup xSemaphoreGive xSemaphoreGive + * \ingroup Semaphores + */ +#define xSemaphoreGive( xSemaphore ) xQueueGenericSend( ( QueueHandle_t ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK ) + +/** + * semphr. h + *
xSemaphoreGiveRecursive( SemaphoreHandle_t xMutex )
+ * + * Macro to recursively release, or 'give', a mutex type semaphore. + * The mutex must have previously been created using a call to + * xSemaphoreCreateRecursiveMutex(); + * + * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this + * macro to be available. + * + * This macro must not be used on mutexes created using xSemaphoreCreateMutex(). + * + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex + * doesn't become available again until the owner has called + * xSemaphoreGiveRecursive() for each successful 'take' request. For example, + * if a task successfully 'takes' the same mutex 5 times then the mutex will + * not be available to any other task until it has also 'given' the mutex back + * exactly five times. + * + * @param xMutex A handle to the mutex being released, or 'given'. This is the + * handle returned by xSemaphoreCreateMutex(); + * + * @return pdTRUE if the semaphore was given. + * + * Example usage: +
+ SemaphoreHandle_t xMutex = NULL;
+
+ // A task that creates a mutex.
+ void vATask( void * pvParameters )
+ {
+    // Create the mutex to guard a shared resource.
+    xMutex = xSemaphoreCreateRecursiveMutex();
+ }
+
+ // A task that uses the mutex.
+ void vAnotherTask( void * pvParameters )
+ {
+    // ... Do other things.
+
+    if( xMutex != NULL )
+    {
+        // See if we can obtain the mutex.  If the mutex is not available
+        // wait 10 ticks to see if it becomes free.
+        if( xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 ) == pdTRUE )
+        {
+            // We were able to obtain the mutex and can now access the
+            // shared resource.
+
+            // ...
+            // For some reason due to the nature of the code further calls to
+            // xSemaphoreTakeRecursive() are made on the same mutex.  In real
+            // code these would not be just sequential calls as this would make
+            // no sense.  Instead the calls are likely to be buried inside
+            // a more complex call structure.
+            xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
+            xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
+
+            // The mutex has now been 'taken' three times, so will not be
+            // available to another task until it has also been given back
+            // three times.  Again it is unlikely that real code would have
+            // these calls sequentially, it would be more likely that the calls
+            // to xSemaphoreGiveRecursive() would be called as a call stack
+            // unwound.  This is just for demonstrative purposes.
+            xSemaphoreGiveRecursive( xMutex );
+            xSemaphoreGiveRecursive( xMutex );
+            xSemaphoreGiveRecursive( xMutex );
+
+            // Now the mutex can be taken by other tasks.
+        }
+        else
+        {
+            // We could not obtain the mutex and can therefore not access
+            // the shared resource safely.
+        }
+    }
+ }
+ 
+ * \defgroup xSemaphoreGiveRecursive xSemaphoreGiveRecursive + * \ingroup Semaphores + */ +#if( configUSE_RECURSIVE_MUTEXES == 1 ) + #define xSemaphoreGiveRecursive( xMutex ) xQueueGiveMutexRecursive( ( xMutex ) ) +#endif + +/** + * semphr. h + *
+ xSemaphoreGiveFromISR(
+                          SemaphoreHandle_t xSemaphore,
+                          BaseType_t *pxHigherPriorityTaskWoken
+                      )
+ * + * Macro to release a semaphore. The semaphore must have previously been + * created with a call to xSemaphoreCreateBinary() or xSemaphoreCreateCounting(). + * + * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex()) + * must not be used with this macro. + * + * This macro can be used from an ISR. + * + * @param xSemaphore A handle to the semaphore being released. This is the + * handle returned when the semaphore was created. + * + * @param pxHigherPriorityTaskWoken xSemaphoreGiveFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if giving the semaphore caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xSemaphoreGiveFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL. + * + * Example usage: +
+ \#define LONG_TIME 0xffff
+ \#define TICKS_TO_WAIT    10
+ SemaphoreHandle_t xSemaphore = NULL;
+
+ // Repetitive task.
+ void vATask( void * pvParameters )
+ {
+    for( ;; )
+    {
+        // We want this task to run every 10 ticks of a timer.  The semaphore
+        // was created before this task was started.
+
+        // Block waiting for the semaphore to become available.
+        if( xSemaphoreTake( xSemaphore, LONG_TIME ) == pdTRUE )
+        {
+            // It is time to execute.
+
+            // ...
+
+            // We have finished our task.  Return to the top of the loop where
+            // we will block on the semaphore until it is time to execute
+            // again.  Note when using the semaphore for synchronisation with an
+            // ISR in this manner there is no need to 'give' the semaphore back.
+        }
+    }
+ }
+
+ // Timer ISR
+ void vTimerISR( void * pvParameters )
+ {
+ static uint8_t ucLocalTickCount = 0;
+ static BaseType_t xHigherPriorityTaskWoken;
+
+    // A timer tick has occurred.
+
+    // ... Do other time functions.
+
+    // Is it time for vATask () to run?
+    xHigherPriorityTaskWoken = pdFALSE;
+    ucLocalTickCount++;
+    if( ucLocalTickCount >= TICKS_TO_WAIT )
+    {
+        // Unblock the task by releasing the semaphore.
+        xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
+
+        // Reset the count so we release the semaphore again in 10 ticks time.
+        ucLocalTickCount = 0;
+    }
+
+    if( xHigherPriorityTaskWoken != pdFALSE )
+    {
+        // We can force a context switch here.  Context switching from an
+        // ISR uses port specific syntax.  Check the demo task for your port
+        // to find the syntax required.
+    }
+ }
+ 
+ * \defgroup xSemaphoreGiveFromISR xSemaphoreGiveFromISR + * \ingroup Semaphores + */ +#define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGiveFromISR( ( QueueHandle_t ) ( xSemaphore ), ( pxHigherPriorityTaskWoken ) ) + +/** + * semphr. h + *
+ xSemaphoreTakeFromISR(
+                          SemaphoreHandle_t xSemaphore,
+                          BaseType_t *pxHigherPriorityTaskWoken
+                      )
+ * + * Macro to take a semaphore from an ISR. The semaphore must have + * previously been created with a call to xSemaphoreCreateBinary() or + * xSemaphoreCreateCounting(). + * + * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex()) + * must not be used with this macro. + * + * This macro can be used from an ISR, however taking a semaphore from an ISR + * is not a common operation. It is likely to only be useful when taking a + * counting semaphore when an interrupt is obtaining an object from a resource + * pool (when the semaphore count indicates the number of resources available). + * + * @param xSemaphore A handle to the semaphore being taken. This is the + * handle returned when the semaphore was created. + * + * @param pxHigherPriorityTaskWoken xSemaphoreTakeFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if taking the semaphore caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xSemaphoreTakeFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the semaphore was successfully taken, otherwise + * pdFALSE + */ +#define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueReceiveFromISR( ( QueueHandle_t ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ) ) + +/** + * semphr. h + *
SemaphoreHandle_t xSemaphoreCreateMutex( void )
+ * + * Creates a new mutex type semaphore instance, and returns a handle by which + * the new mutex can be referenced. + * + * Internally, within the FreeRTOS implementation, mutex semaphores use a block + * of memory, in which the mutex structure is stored. If a mutex is created + * using xSemaphoreCreateMutex() then the required memory is automatically + * dynamically allocated inside the xSemaphoreCreateMutex() function. (see + * http://www.freertos.org/a00111.html). If a mutex is created using + * xSemaphoreCreateMutexStatic() then the application writer must provided the + * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created + * without using any dynamic memory allocation. + * + * Mutexes created using this function can be accessed using the xSemaphoreTake() + * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and + * xSemaphoreGiveRecursive() macros must not be used. + * + * This type of semaphore uses a priority inheritance mechanism so a task + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the + * semaphore it is no longer required. + * + * Mutex type semaphores cannot be used from within interrupt service routines. + * + * See xSemaphoreCreateBinary() for an alternative implementation that can be + * used for pure synchronisation (where one task or interrupt always 'gives' the + * semaphore and another always 'takes' the semaphore) and from within interrupt + * service routines. + * + * @return If the mutex was successfully created then a handle to the created + * semaphore is returned. If there was not enough heap to allocate the mutex + * data structures then NULL is returned. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore;
+
+ void vATask( void * pvParameters )
+ {
+    // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
+    // This is a macro so pass the variable in directly.
+    xSemaphore = xSemaphoreCreateMutex();
+
+    if( xSemaphore != NULL )
+    {
+        // The semaphore was created successfully.
+        // The semaphore can now be used.
+    }
+ }
+ 
+ * \defgroup xSemaphoreCreateMutex xSemaphoreCreateMutex + * \ingroup Semaphores + */ +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + #define xSemaphoreCreateMutex() xQueueCreateMutex( queueQUEUE_TYPE_MUTEX ) +#endif + +/** + * semphr. h + *
SemaphoreHandle_t xSemaphoreCreateMutexStatic( StaticSemaphore_t *pxMutexBuffer )
+ * + * Creates a new mutex type semaphore instance, and returns a handle by which + * the new mutex can be referenced. + * + * Internally, within the FreeRTOS implementation, mutex semaphores use a block + * of memory, in which the mutex structure is stored. If a mutex is created + * using xSemaphoreCreateMutex() then the required memory is automatically + * dynamically allocated inside the xSemaphoreCreateMutex() function. (see + * http://www.freertos.org/a00111.html). If a mutex is created using + * xSemaphoreCreateMutexStatic() then the application writer must provided the + * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created + * without using any dynamic memory allocation. + * + * Mutexes created using this function can be accessed using the xSemaphoreTake() + * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and + * xSemaphoreGiveRecursive() macros must not be used. + * + * This type of semaphore uses a priority inheritance mechanism so a task + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the + * semaphore it is no longer required. + * + * Mutex type semaphores cannot be used from within interrupt service routines. + * + * See xSemaphoreCreateBinary() for an alternative implementation that can be + * used for pure synchronisation (where one task or interrupt always 'gives' the + * semaphore and another always 'takes' the semaphore) and from within interrupt + * service routines. + * + * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t, + * which will be used to hold the mutex's data structure, removing the need for + * the memory to be allocated dynamically. + * + * @return If the mutex was successfully created then a handle to the created + * mutex is returned. If pxMutexBuffer was NULL then NULL is returned. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore;
+ StaticSemaphore_t xMutexBuffer;
+
+ void vATask( void * pvParameters )
+ {
+    // A mutex cannot be used before it has been created.  xMutexBuffer is
+    // into xSemaphoreCreateMutexStatic() so no dynamic memory allocation is
+    // attempted.
+    xSemaphore = xSemaphoreCreateMutexStatic( &xMutexBuffer );
+
+    // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
+    // so there is no need to check it.
+ }
+ 
+ * \defgroup xSemaphoreCreateMutexStatic xSemaphoreCreateMutexStatic + * \ingroup Semaphores + */ + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xSemaphoreCreateMutexStatic( pxMutexBuffer ) xQueueCreateMutexStatic( queueQUEUE_TYPE_MUTEX, ( pxMutexBuffer ) ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + + +/** + * semphr. h + *
SemaphoreHandle_t xSemaphoreCreateRecursiveMutex( void )
+ * + * Creates a new recursive mutex type semaphore instance, and returns a handle + * by which the new recursive mutex can be referenced. + * + * Internally, within the FreeRTOS implementation, recursive mutexs use a block + * of memory, in which the mutex structure is stored. If a recursive mutex is + * created using xSemaphoreCreateRecursiveMutex() then the required memory is + * automatically dynamically allocated inside the + * xSemaphoreCreateRecursiveMutex() function. (see + * http://www.freertos.org/a00111.html). If a recursive mutex is created using + * xSemaphoreCreateRecursiveMutexStatic() then the application writer must + * provide the memory that will get used by the mutex. + * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to + * be created without using any dynamic memory allocation. + * + * Mutexes created using this macro can be accessed using the + * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The + * xSemaphoreTake() and xSemaphoreGive() macros must not be used. + * + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex + * doesn't become available again until the owner has called + * xSemaphoreGiveRecursive() for each successful 'take' request. For example, + * if a task successfully 'takes' the same mutex 5 times then the mutex will + * not be available to any other task until it has also 'given' the mutex back + * exactly five times. + * + * This type of semaphore uses a priority inheritance mechanism so a task + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the + * semaphore it is no longer required. + * + * Mutex type semaphores cannot be used from within interrupt service routines. + * + * See xSemaphoreCreateBinary() for an alternative implementation that can be + * used for pure synchronisation (where one task or interrupt always 'gives' the + * semaphore and another always 'takes' the semaphore) and from within interrupt + * service routines. + * + * @return xSemaphore Handle to the created mutex semaphore. Should be of type + * SemaphoreHandle_t. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore;
+
+ void vATask( void * pvParameters )
+ {
+    // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
+    // This is a macro so pass the variable in directly.
+    xSemaphore = xSemaphoreCreateRecursiveMutex();
+
+    if( xSemaphore != NULL )
+    {
+        // The semaphore was created successfully.
+        // The semaphore can now be used.
+    }
+ }
+ 
+ * \defgroup xSemaphoreCreateRecursiveMutex xSemaphoreCreateRecursiveMutex + * \ingroup Semaphores + */ +#if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) ) + #define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex( queueQUEUE_TYPE_RECURSIVE_MUTEX ) +#endif + +/** + * semphr. h + *
SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic( StaticSemaphore_t *pxMutexBuffer )
+ * + * Creates a new recursive mutex type semaphore instance, and returns a handle + * by which the new recursive mutex can be referenced. + * + * Internally, within the FreeRTOS implementation, recursive mutexs use a block + * of memory, in which the mutex structure is stored. If a recursive mutex is + * created using xSemaphoreCreateRecursiveMutex() then the required memory is + * automatically dynamically allocated inside the + * xSemaphoreCreateRecursiveMutex() function. (see + * http://www.freertos.org/a00111.html). If a recursive mutex is created using + * xSemaphoreCreateRecursiveMutexStatic() then the application writer must + * provide the memory that will get used by the mutex. + * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to + * be created without using any dynamic memory allocation. + * + * Mutexes created using this macro can be accessed using the + * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The + * xSemaphoreTake() and xSemaphoreGive() macros must not be used. + * + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex + * doesn't become available again until the owner has called + * xSemaphoreGiveRecursive() for each successful 'take' request. For example, + * if a task successfully 'takes' the same mutex 5 times then the mutex will + * not be available to any other task until it has also 'given' the mutex back + * exactly five times. + * + * This type of semaphore uses a priority inheritance mechanism so a task + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the + * semaphore it is no longer required. + * + * Mutex type semaphores cannot be used from within interrupt service routines. + * + * See xSemaphoreCreateBinary() for an alternative implementation that can be + * used for pure synchronisation (where one task or interrupt always 'gives' the + * semaphore and another always 'takes' the semaphore) and from within interrupt + * service routines. + * + * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t, + * which will then be used to hold the recursive mutex's data structure, + * removing the need for the memory to be allocated dynamically. + * + * @return If the recursive mutex was successfully created then a handle to the + * created recursive mutex is returned. If pxMutexBuffer was NULL then NULL is + * returned. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore;
+ StaticSemaphore_t xMutexBuffer;
+
+ void vATask( void * pvParameters )
+ {
+    // A recursive semaphore cannot be used before it is created.  Here a
+    // recursive mutex is created using xSemaphoreCreateRecursiveMutexStatic().
+    // The address of xMutexBuffer is passed into the function, and will hold
+    // the mutexes data structures - so no dynamic memory allocation will be
+    // attempted.
+    xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xMutexBuffer );
+
+    // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
+    // so there is no need to check it.
+ }
+ 
+ * \defgroup xSemaphoreCreateRecursiveMutexStatic xSemaphoreCreateRecursiveMutexStatic + * \ingroup Semaphores + */ +#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) ) + #define xSemaphoreCreateRecursiveMutexStatic( pxStaticSemaphore ) xQueueCreateMutexStatic( queueQUEUE_TYPE_RECURSIVE_MUTEX, pxStaticSemaphore ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * semphr. h + *
SemaphoreHandle_t xSemaphoreCreateCounting( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount )
+ * + * Creates a new counting semaphore instance, and returns a handle by which the + * new counting semaphore can be referenced. + * + * In many usage scenarios it is faster and more memory efficient to use a + * direct to task notification in place of a counting semaphore! + * http://www.freertos.org/RTOS-task-notifications.html + * + * Internally, within the FreeRTOS implementation, counting semaphores use a + * block of memory, in which the counting semaphore structure is stored. If a + * counting semaphore is created using xSemaphoreCreateCounting() then the + * required memory is automatically dynamically allocated inside the + * xSemaphoreCreateCounting() function. (see + * http://www.freertos.org/a00111.html). If a counting semaphore is created + * using xSemaphoreCreateCountingStatic() then the application writer can + * instead optionally provide the memory that will get used by the counting + * semaphore. xSemaphoreCreateCountingStatic() therefore allows a counting + * semaphore to be created without using any dynamic memory allocation. + * + * Counting semaphores are typically used for two things: + * + * 1) Counting events. + * + * In this usage scenario an event handler will 'give' a semaphore each time + * an event occurs (incrementing the semaphore count value), and a handler + * task will 'take' a semaphore each time it processes an event + * (decrementing the semaphore count value). The count value is therefore + * the difference between the number of events that have occurred and the + * number that have been processed. In this case it is desirable for the + * initial count value to be zero. + * + * 2) Resource management. + * + * In this usage scenario the count value indicates the number of resources + * available. To obtain control of a resource a task must first obtain a + * semaphore - decrementing the semaphore count value. When the count value + * reaches zero there are no free resources. When a task finishes with the + * resource it 'gives' the semaphore back - incrementing the semaphore count + * value. In this case it is desirable for the initial count value to be + * equal to the maximum count value, indicating that all resources are free. + * + * @param uxMaxCount The maximum count value that can be reached. When the + * semaphore reaches this value it can no longer be 'given'. + * + * @param uxInitialCount The count value assigned to the semaphore when it is + * created. + * + * @return Handle to the created semaphore. Null if the semaphore could not be + * created. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore;
+
+ void vATask( void * pvParameters )
+ {
+ SemaphoreHandle_t xSemaphore = NULL;
+
+    // Semaphore cannot be used before a call to xSemaphoreCreateCounting().
+    // The max value to which the semaphore can count should be 10, and the
+    // initial value assigned to the count should be 0.
+    xSemaphore = xSemaphoreCreateCounting( 10, 0 );
+
+    if( xSemaphore != NULL )
+    {
+        // The semaphore was created successfully.
+        // The semaphore can now be used.
+    }
+ }
+ 
+ * \defgroup xSemaphoreCreateCounting xSemaphoreCreateCounting + * \ingroup Semaphores + */ +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + #define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ) ) +#endif + +/** + * semphr. h + *
SemaphoreHandle_t xSemaphoreCreateCountingStatic( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount, StaticSemaphore_t *pxSemaphoreBuffer )
+ * + * Creates a new counting semaphore instance, and returns a handle by which the + * new counting semaphore can be referenced. + * + * In many usage scenarios it is faster and more memory efficient to use a + * direct to task notification in place of a counting semaphore! + * http://www.freertos.org/RTOS-task-notifications.html + * + * Internally, within the FreeRTOS implementation, counting semaphores use a + * block of memory, in which the counting semaphore structure is stored. If a + * counting semaphore is created using xSemaphoreCreateCounting() then the + * required memory is automatically dynamically allocated inside the + * xSemaphoreCreateCounting() function. (see + * http://www.freertos.org/a00111.html). If a counting semaphore is created + * using xSemaphoreCreateCountingStatic() then the application writer must + * provide the memory. xSemaphoreCreateCountingStatic() therefore allows a + * counting semaphore to be created without using any dynamic memory allocation. + * + * Counting semaphores are typically used for two things: + * + * 1) Counting events. + * + * In this usage scenario an event handler will 'give' a semaphore each time + * an event occurs (incrementing the semaphore count value), and a handler + * task will 'take' a semaphore each time it processes an event + * (decrementing the semaphore count value). The count value is therefore + * the difference between the number of events that have occurred and the + * number that have been processed. In this case it is desirable for the + * initial count value to be zero. + * + * 2) Resource management. + * + * In this usage scenario the count value indicates the number of resources + * available. To obtain control of a resource a task must first obtain a + * semaphore - decrementing the semaphore count value. When the count value + * reaches zero there are no free resources. When a task finishes with the + * resource it 'gives' the semaphore back - incrementing the semaphore count + * value. In this case it is desirable for the initial count value to be + * equal to the maximum count value, indicating that all resources are free. + * + * @param uxMaxCount The maximum count value that can be reached. When the + * semaphore reaches this value it can no longer be 'given'. + * + * @param uxInitialCount The count value assigned to the semaphore when it is + * created. + * + * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t, + * which will then be used to hold the semaphore's data structure, removing the + * need for the memory to be allocated dynamically. + * + * @return If the counting semaphore was successfully created then a handle to + * the created counting semaphore is returned. If pxSemaphoreBuffer was NULL + * then NULL is returned. + * + * Example usage: +
+ SemaphoreHandle_t xSemaphore;
+ StaticSemaphore_t xSemaphoreBuffer;
+
+ void vATask( void * pvParameters )
+ {
+ SemaphoreHandle_t xSemaphore = NULL;
+
+    // Counting semaphore cannot be used before they have been created.  Create
+    // a counting semaphore using xSemaphoreCreateCountingStatic().  The max
+    // value to which the semaphore can count is 10, and the initial value
+    // assigned to the count will be 0.  The address of xSemaphoreBuffer is
+    // passed in and will be used to hold the semaphore structure, so no dynamic
+    // memory allocation will be used.
+    xSemaphore = xSemaphoreCreateCounting( 10, 0, &xSemaphoreBuffer );
+
+    // No memory allocation was attempted so xSemaphore cannot be NULL, so there
+    // is no need to check its value.
+ }
+ 
+ * \defgroup xSemaphoreCreateCountingStatic xSemaphoreCreateCountingStatic + * \ingroup Semaphores + */ +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xSemaphoreCreateCountingStatic( uxMaxCount, uxInitialCount, pxSemaphoreBuffer ) xQueueCreateCountingSemaphoreStatic( ( uxMaxCount ), ( uxInitialCount ), ( pxSemaphoreBuffer ) ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * semphr. h + *
void vSemaphoreDelete( SemaphoreHandle_t xSemaphore );
+ * + * Delete a semaphore. This function must be used with care. For example, + * do not delete a mutex type semaphore if the mutex is held by a task. + * + * @param xSemaphore A handle to the semaphore to be deleted. + * + * \defgroup vSemaphoreDelete vSemaphoreDelete + * \ingroup Semaphores + */ +#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) ) + +/** + * semphr.h + *
TaskHandle_t xSemaphoreGetMutexHolder( SemaphoreHandle_t xMutex );
+ * + * If xMutex is indeed a mutex type semaphore, return the current mutex holder. + * If xMutex is not a mutex type semaphore, or the mutex is available (not held + * by a task), return NULL. + * + * Note: This is a good way of determining if the calling task is the mutex + * holder, but not a good way of determining the identity of the mutex holder as + * the holder may change between the function exiting and the returned value + * being tested. + */ +#define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) ) + +/** + * semphr.h + *
TaskHandle_t xSemaphoreGetMutexHolderFromISR( SemaphoreHandle_t xMutex );
+ * + * If xMutex is indeed a mutex type semaphore, return the current mutex holder. + * If xMutex is not a mutex type semaphore, or the mutex is available (not held + * by a task), return NULL. + * + */ +#define xSemaphoreGetMutexHolderFromISR( xSemaphore ) xQueueGetMutexHolderFromISR( ( xSemaphore ) ) + +/** + * semphr.h + *
UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore );
+ * + * If the semaphore is a counting semaphore then uxSemaphoreGetCount() returns + * its current count value. If the semaphore is a binary semaphore then + * uxSemaphoreGetCount() returns 1 if the semaphore is available, and 0 if the + * semaphore is not available. + * + */ +#define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) ) + +#endif /* SEMAPHORE_H */ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/stack_macros.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/stack_macros.h new file mode 100644 index 0000000..42a351b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/stack_macros.h @@ -0,0 +1,129 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef STACK_MACROS_H +#define STACK_MACROS_H + +/* + * Call the stack overflow hook function if the stack of the task being swapped + * out is currently overflowed, or looks like it might have overflowed in the + * past. + * + * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check + * the current stack state only - comparing the current top of stack value to + * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 + * will also cause the last few stack bytes to be checked to ensure the value + * to which the bytes were set when the task was created have not been + * overwritten. Note this second test does not guarantee that an overflowed + * stack will always be recognised. + */ + +/*-----------------------------------------------------------*/ + +#if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) ) + + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ +/*-----------------------------------------------------------*/ + +#if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) ) + + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ +/*-----------------------------------------------------------*/ + +#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) + + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ + const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \ + \ + if( ( pulStack[ 0 ] != ulCheckValue ) || \ + ( pulStack[ 1 ] != ulCheckValue ) || \ + ( pulStack[ 2 ] != ulCheckValue ) || \ + ( pulStack[ 3 ] != ulCheckValue ) ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ +/*-----------------------------------------------------------*/ + +#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) + + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ + static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ + \ + \ + pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ + \ + /* Has the extremity of the task stack ever been written over? */ \ + if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ +/*-----------------------------------------------------------*/ + +/* Remove stack overflow macro if not being used. */ +#ifndef taskCHECK_FOR_STACK_OVERFLOW + #define taskCHECK_FOR_STACK_OVERFLOW() +#endif + + + +#endif /* STACK_MACROS_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/stdint.readme b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/stdint.readme new file mode 100644 index 0000000..4414c29 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/stdint.readme @@ -0,0 +1,27 @@ + +#ifndef FREERTOS_STDINT +#define FREERTOS_STDINT + +/******************************************************************************* + * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions + * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be + * built using compilers that do not provide their own stdint.h definition. + * + * To use this file: + * + * 1) Copy this file into the directory that contains your FreeRTOSConfig.h + * header file, as that directory will already be in the compilers include + * path. + * + * 2) Rename the copied file stdint.h. + * + */ + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef short int16_t; +typedef unsigned short uint16_t; +typedef long int32_t; +typedef unsigned long uint32_t; + +#endif /* FREERTOS_STDINT */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/stream_buffer.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/stream_buffer.h new file mode 100644 index 0000000..5418e05 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/stream_buffer.h @@ -0,0 +1,852 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* + * Stream buffers are used to send a continuous stream of data from one task or + * interrupt to another. Their implementation is light weight, making them + * particularly suited for interrupt to task and core to core communication + * scenarios. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xStreamBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xStreamBufferRead()) inside a critical section section and set the + * receive block time to 0. + * + */ + +#ifndef STREAM_BUFFER_H +#define STREAM_BUFFER_H + +#if defined( __cplusplus ) +extern "C" { +#endif + +/** + * Type by which stream buffers are referenced. For example, a call to + * xStreamBufferCreate() returns an StreamBufferHandle_t variable that can + * then be used as a parameter to xStreamBufferSend(), xStreamBufferReceive(), + * etc. + */ +typedef void * StreamBufferHandle_t; + + +/** + * message_buffer.h + * +
+StreamBufferHandle_t xStreamBufferCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes );
+
+ * + * Creates a new stream buffer using dynamically allocated memory. See + * xStreamBufferCreateStatic() for a version that uses statically allocated + * memory (memory that is allocated at compile time). + * + * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in + * FreeRTOSConfig.h for xStreamBufferCreate() to be available. + * + * @param xBufferSizeBytes The total number of bytes the stream buffer will be + * able to hold at any one time. + * + * @param xTriggerLevelBytes The number of bytes that must be in the stream + * buffer before a task that is blocked on the stream buffer to wait for data is + * moved out of the blocked state. For example, if a task is blocked on a read + * of an empty stream buffer that has a trigger level of 1 then the task will be + * unblocked when a single byte is written to the buffer or the task's block + * time expires. As another example, if a task is blocked on a read of an empty + * stream buffer that has a trigger level of 10 then the task will not be + * unblocked until the stream buffer contains at least 10 bytes or the task's + * block time expires. If a reading task's block time expires before the + * trigger level is reached then the task will still receive however many bytes + * are actually available. Setting a trigger level of 0 will result in a + * trigger level of 1 being used. It is not valid to specify a trigger level + * that is greater than the buffer size. + * + * @return If NULL is returned, then the stream buffer cannot be created + * because there is insufficient heap memory available for FreeRTOS to allocate + * the stream buffer data structures and storage area. A non-NULL value being + * returned indicates that the stream buffer has been created successfully - + * the returned value should be stored as the handle to the created stream + * buffer. + * + * Example use: +
+
+void vAFunction( void )
+{
+StreamBufferHandle_t xStreamBuffer;
+const size_t xStreamBufferSizeBytes = 100, xTriggerLevel = 10;
+
+    // Create a stream buffer that can hold 100 bytes.  The memory used to hold
+    // both the stream buffer structure and the data in the stream buffer is
+    // allocated dynamically.
+    xStreamBuffer = xStreamBufferCreate( xStreamBufferSizeBytes, xTriggerLevel );
+
+    if( xStreamBuffer == NULL )
+    {
+        // There was not enough heap memory space available to create the
+        // stream buffer.
+    }
+    else
+    {
+        // The stream buffer was created successfully and can now be used.
+    }
+}
+
+ * \defgroup xStreamBufferCreate xStreamBufferCreate + * \ingroup StreamBufferManagement + */ +#define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE ) + +/** + * stream_buffer.h + * +
+StreamBufferHandle_t xStreamBufferCreateStatic( size_t xBufferSizeBytes,
+                                                size_t xTriggerLevelBytes,
+                                                uint8_t *pucStreamBufferStorageArea,
+                                                StaticStreamBuffer_t *pxStaticStreamBuffer );
+
+ * Creates a new stream buffer using statically allocated memory. See + * xStreamBufferCreate() for a version that uses dynamically allocated memory. + * + * configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for + * xStreamBufferCreateStatic() to be available. + * + * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the + * pucStreamBufferStorageArea parameter. + * + * @param xTriggerLevelBytes The number of bytes that must be in the stream + * buffer before a task that is blocked on the stream buffer to wait for data is + * moved out of the blocked state. For example, if a task is blocked on a read + * of an empty stream buffer that has a trigger level of 1 then the task will be + * unblocked when a single byte is written to the buffer or the task's block + * time expires. As another example, if a task is blocked on a read of an empty + * stream buffer that has a trigger level of 10 then the task will not be + * unblocked until the stream buffer contains at least 10 bytes or the task's + * block time expires. If a reading task's block time expires before the + * trigger level is reached then the task will still receive however many bytes + * are actually available. Setting a trigger level of 0 will result in a + * trigger level of 1 being used. It is not valid to specify a trigger level + * that is greater than the buffer size. + * + * @param pucStreamBufferStorageArea Must point to a uint8_t array that is at + * least xBufferSizeBytes + 1 big. This is the array to which streams are + * copied when they are written to the stream buffer. + * + * @param pxStaticStreamBuffer Must point to a variable of type + * StaticStreamBuffer_t, which will be used to hold the stream buffer's data + * structure. + * + * @return If the stream buffer is created successfully then a handle to the + * created stream buffer is returned. If either pucStreamBufferStorageArea or + * pxStaticstreamBuffer are NULL then NULL is returned. + * + * Example use: +
+
+// Used to dimension the array used to hold the streams.  The available space
+// will actually be one less than this, so 999.
+#define STORAGE_SIZE_BYTES 1000
+
+// Defines the memory that will actually hold the streams within the stream
+// buffer.
+static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
+
+// The variable used to hold the stream buffer structure.
+StaticStreamBuffer_t xStreamBufferStruct;
+
+void MyFunction( void )
+{
+StreamBufferHandle_t xStreamBuffer;
+const size_t xTriggerLevel = 1;
+
+    xStreamBuffer = xStreamBufferCreateStatic( sizeof( ucBufferStorage ),
+                                               xTriggerLevel,
+                                               ucBufferStorage,
+                                               &xStreamBufferStruct );
+
+    // As neither the pucStreamBufferStorageArea or pxStaticStreamBuffer
+    // parameters were NULL, xStreamBuffer will not be NULL, and can be used to
+    // reference the created stream buffer in other stream buffer API calls.
+
+    // Other code that uses the stream buffer can go here.
+}
+
+
+ * \defgroup xStreamBufferCreateStatic xStreamBufferCreateStatic + * \ingroup StreamBufferManagement + */ +#define xStreamBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pucStreamBufferStorageArea, pxStaticStreamBuffer ) + +/** + * stream_buffer.h + * +
+size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
+                          const void *pvTxData,
+                          size_t xDataLengthBytes,
+                          TickType_t xTicksToWait );
+
+ *
+ * Sends bytes to a stream buffer.  The bytes are copied into the stream buffer.
+ *
+ * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer
+ * implementation (so also the message buffer implementation, as message buffers
+ * are built on top of stream buffers) assumes there is only one task or
+ * interrupt that will write to the buffer (the writer), and only one task or
+ * interrupt that will read from the buffer (the reader).  It is safe for the
+ * writer and reader to be different tasks or interrupts, but, unlike other
+ * FreeRTOS objects, it is not safe to have multiple different writers or
+ * multiple different readers.  If there are to be multiple different writers
+ * then the application writer must place each call to a writing API function
+ * (such as xStreamBufferSend()) inside a critical section and set the send
+ * block time to 0.  Likewise, if there are to be multiple different readers
+ * then the application writer must place each call to a reading API function
+ * (such as xStreamBufferRead()) inside a critical section and set the receive
+ * block time to 0.
+ *
+ * Use xStreamBufferSend() to write to a stream buffer from a task.  Use
+ * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt
+ * service routine (ISR).
+ *
+ * @param xStreamBuffer The handle of the stream buffer to which a stream is
+ * being sent.
+ *
+ * @param pvTxData A pointer to the buffer that holds the bytes to be copied
+ * into the stream buffer.
+ *
+ * @param xDataLengthBytes   The maximum number of bytes to copy from pvTxData
+ * into the stream buffer.
+ *
+ * @param xTicksToWait The maximum amount of time the task should remain in the
+ * Blocked state to wait for enough space to become available in the stream
+ * buffer, should the stream buffer contain too little space to hold the
+ * another xDataLengthBytes bytes.  The block time is specified in tick periods,
+ * so the absolute time it represents is dependent on the tick frequency.  The
+ * macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds
+ * into a time specified in ticks.  Setting xTicksToWait to portMAX_DELAY will
+ * cause the task to wait indefinitely (without timing out), provided
+ * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h.  If a task times out
+ * before it can write all xDataLengthBytes into the buffer it will still write
+ * as many bytes as possible.  A task does not use any CPU time when it is in
+ * the blocked state.
+ *
+ * @return The number of bytes written to the stream buffer.  If a task times
+ * out before it can write all xDataLengthBytes into the buffer it will still
+ * write as many bytes as possible.
+ *
+ * Example use:
+
+void vAFunction( StreamBufferHandle_t xStreamBuffer )
+{
+size_t xBytesSent;
+uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
+char *pcStringToSend = "String to send";
+const TickType_t x100ms = pdMS_TO_TICKS( 100 );
+
+    // Send an array to the stream buffer, blocking for a maximum of 100ms to
+    // wait for enough space to be available in the stream buffer.
+    xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );
+
+    if( xBytesSent != sizeof( ucArrayToSend ) )
+    {
+        // The call to xStreamBufferSend() times out before there was enough
+        // space in the buffer for the data to be written, but it did
+        // successfully write xBytesSent bytes.
+    }
+
+    // Send the string to the stream buffer.  Return immediately if there is not
+    // enough space in the buffer.
+    xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );
+
+    if( xBytesSent != strlen( pcStringToSend ) )
+    {
+        // The entire string could not be added to the stream buffer because
+        // there was not enough free space in the buffer, but xBytesSent bytes
+        // were sent.  Could try again to send the remaining bytes.
+    }
+}
+
+ * \defgroup xStreamBufferSend xStreamBufferSend + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, + const void *pvTxData, + size_t xDataLengthBytes, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
+                                 const void *pvTxData,
+                                 size_t xDataLengthBytes,
+                                 BaseType_t *pxHigherPriorityTaskWoken );
+
+ *
+ * Interrupt safe version of the API function that sends a stream of bytes to
+ * the stream buffer.
+ *
+ * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer
+ * implementation (so also the message buffer implementation, as message buffers
+ * are built on top of stream buffers) assumes there is only one task or
+ * interrupt that will write to the buffer (the writer), and only one task or
+ * interrupt that will read from the buffer (the reader).  It is safe for the
+ * writer and reader to be different tasks or interrupts, but, unlike other
+ * FreeRTOS objects, it is not safe to have multiple different writers or
+ * multiple different readers.  If there are to be multiple different writers
+ * then the application writer must place each call to a writing API function
+ * (such as xStreamBufferSend()) inside a critical section and set the send
+ * block time to 0.  Likewise, if there are to be multiple different readers
+ * then the application writer must place each call to a reading API function
+ * (such as xStreamBufferRead()) inside a critical section and set the receive
+ * block time to 0.
+ *
+ * Use xStreamBufferSend() to write to a stream buffer from a task.  Use
+ * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt
+ * service routine (ISR).
+ *
+ * @param xStreamBuffer The handle of the stream buffer to which a stream is
+ * being sent.
+ *
+ * @param pvTxData A pointer to the data that is to be copied into the stream
+ * buffer.
+ *
+ * @param xDataLengthBytes The maximum number of bytes to copy from pvTxData
+ * into the stream buffer.
+ *
+ * @param pxHigherPriorityTaskWoken  It is possible that a stream buffer will
+ * have a task blocked on it waiting for data.  Calling
+ * xStreamBufferSendFromISR() can make data available, and so cause a task that
+ * was waiting for data to leave the Blocked state.  If calling
+ * xStreamBufferSendFromISR() causes a task to leave the Blocked state, and the
+ * unblocked task has a priority higher than the currently executing task (the
+ * task that was interrupted), then, internally, xStreamBufferSendFromISR()
+ * will set *pxHigherPriorityTaskWoken to pdTRUE.  If
+ * xStreamBufferSendFromISR() sets this value to pdTRUE, then normally a
+ * context switch should be performed before the interrupt is exited.  This will
+ * ensure that the interrupt returns directly to the highest priority Ready
+ * state task.  *pxHigherPriorityTaskWoken should be set to pdFALSE before it
+ * is passed into the function.  See the example code below for an example.
+ *
+ * @return The number of bytes actually written to the stream buffer, which will
+ * be less than xDataLengthBytes if the stream buffer didn't have enough free
+ * space for all the bytes to be written.
+ *
+ * Example use:
+
+// A stream buffer that has already been created.
+StreamBufferHandle_t xStreamBuffer;
+
+void vAnInterruptServiceRoutine( void )
+{
+size_t xBytesSent;
+char *pcStringToSend = "String to send";
+BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
+
+    // Attempt to send the string to the stream buffer.
+    xBytesSent = xStreamBufferSendFromISR( xStreamBuffer,
+                                           ( void * ) pcStringToSend,
+                                           strlen( pcStringToSend ),
+                                           &xHigherPriorityTaskWoken );
+
+    if( xBytesSent != strlen( pcStringToSend ) )
+    {
+        // There was not enough free space in the stream buffer for the entire
+        // string to be written, ut xBytesSent bytes were written.
+    }
+
+    // If xHigherPriorityTaskWoken was set to pdTRUE inside
+    // xStreamBufferSendFromISR() then a task that has a priority above the
+    // priority of the currently executing task was unblocked and a context
+    // switch should be performed to ensure the ISR returns to the unblocked
+    // task.  In most FreeRTOS ports this is done by simply passing
+    // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
+    // variables value, and perform the context switch if necessary.  Check the
+    // documentation for the port in use for port specific instructions.
+    taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+}
+
+ * \defgroup xStreamBufferSendFromISR xStreamBufferSendFromISR + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer, + const void *pvTxData, + size_t xDataLengthBytes, + BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
+                             void *pvRxData,
+                             size_t xBufferLengthBytes,
+                             TickType_t xTicksToWait );
+
+ * + * Receives bytes from a stream buffer. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xStreamBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xStreamBufferRead()) inside a critical section and set the receive + * block time to 0. + * + * Use xStreamBufferReceive() to read from a stream buffer from a task. Use + * xStreamBufferReceiveFromISR() to read from a stream buffer from an + * interrupt service routine (ISR). + * + * @param xStreamBuffer The handle of the stream buffer from which bytes are to + * be received. + * + * @param pvRxData A pointer to the buffer into which the received bytes will be + * copied. + * + * @param xBufferLengthBytes The length of the buffer pointed to by the + * pvRxData parameter. This sets the maximum number of bytes to receive in one + * call. xStreamBufferReceive will return as many bytes as possible up to a + * maximum set by xBufferLengthBytes. + * + * @param xTicksToWait The maximum amount of time the task should remain in the + * Blocked state to wait for data to become available if the stream buffer is + * empty. xStreamBufferReceive() will return immediately if xTicksToWait is + * zero. The block time is specified in tick periods, so the absolute time it + * represents is dependent on the tick frequency. The macro pdMS_TO_TICKS() can + * be used to convert a time specified in milliseconds into a time specified in + * ticks. Setting xTicksToWait to portMAX_DELAY will cause the task to wait + * indefinitely (without timing out), provided INCLUDE_vTaskSuspend is set to 1 + * in FreeRTOSConfig.h. A task does not use any CPU time when it is in the + * Blocked state. + * + * @return The number of bytes actually read from the stream buffer, which will + * be less than xBufferLengthBytes if the call to xStreamBufferReceive() timed + * out before xBufferLengthBytes were available. + * + * Example use: +
+void vAFunction( StreamBuffer_t xStreamBuffer )
+{
+uint8_t ucRxData[ 20 ];
+size_t xReceivedBytes;
+const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
+
+    // Receive up to another sizeof( ucRxData ) bytes from the stream buffer.
+    // Wait in the Blocked state (so not using any CPU processing time) for a
+    // maximum of 100ms for the full sizeof( ucRxData ) number of bytes to be
+    // available.
+    xReceivedBytes = xStreamBufferReceive( xStreamBuffer,
+                                           ( void * ) ucRxData,
+                                           sizeof( ucRxData ),
+                                           xBlockTime );
+
+    if( xReceivedBytes > 0 )
+    {
+        // A ucRxData contains another xRecievedBytes bytes of data, which can
+        // be processed here....
+    }
+}
+
+ * \defgroup xStreamBufferReceive xStreamBufferReceive + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, + void *pvRxData, + size_t xBufferLengthBytes, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
+                                    void *pvRxData,
+                                    size_t xBufferLengthBytes,
+                                    BaseType_t *pxHigherPriorityTaskWoken );
+
+ * + * An interrupt safe version of the API function that receives bytes from a + * stream buffer. + * + * Use xStreamBufferReceive() to read bytes from a stream buffer from a task. + * Use xStreamBufferReceiveFromISR() to read bytes from a stream buffer from an + * interrupt service routine (ISR). + * + * @param xStreamBuffer The handle of the stream buffer from which a stream + * is being received. + * + * @param pvRxData A pointer to the buffer into which the received bytes are + * copied. + * + * @param xBufferLengthBytes The length of the buffer pointed to by the + * pvRxData parameter. This sets the maximum number of bytes to receive in one + * call. xStreamBufferReceive will return as many bytes as possible up to a + * maximum set by xBufferLengthBytes. + * + * @param pxHigherPriorityTaskWoken It is possible that a stream buffer will + * have a task blocked on it waiting for space to become available. Calling + * xStreamBufferReceiveFromISR() can make space available, and so cause a task + * that is waiting for space to leave the Blocked state. If calling + * xStreamBufferReceiveFromISR() causes a task to leave the Blocked state, and + * the unblocked task has a priority higher than the currently executing task + * (the task that was interrupted), then, internally, + * xStreamBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE. + * If xStreamBufferReceiveFromISR() sets this value to pdTRUE, then normally a + * context switch should be performed before the interrupt is exited. That will + * ensure the interrupt returns directly to the highest priority Ready state + * task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it is + * passed into the function. See the code example below for an example. + * + * @return The number of bytes read from the stream buffer, if any. + * + * Example use: +
+// A stream buffer that has already been created.
+StreamBuffer_t xStreamBuffer;
+
+void vAnInterruptServiceRoutine( void )
+{
+uint8_t ucRxData[ 20 ];
+size_t xReceivedBytes;
+BaseType_t xHigherPriorityTaskWoken = pdFALSE;  // Initialised to pdFALSE.
+
+    // Receive the next stream from the stream buffer.
+    xReceivedBytes = xStreamBufferReceiveFromISR( xStreamBuffer,
+                                                  ( void * ) ucRxData,
+                                                  sizeof( ucRxData ),
+                                                  &xHigherPriorityTaskWoken );
+
+    if( xReceivedBytes > 0 )
+    {
+        // ucRxData contains xReceivedBytes read from the stream buffer.
+        // Process the stream here....
+    }
+
+    // If xHigherPriorityTaskWoken was set to pdTRUE inside
+    // xStreamBufferReceiveFromISR() then a task that has a priority above the
+    // priority of the currently executing task was unblocked and a context
+    // switch should be performed to ensure the ISR returns to the unblocked
+    // task.  In most FreeRTOS ports this is done by simply passing
+    // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
+    // variables value, and perform the context switch if necessary.  Check the
+    // documentation for the port in use for port specific instructions.
+    taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+}
+
+ * \defgroup xStreamBufferReceiveFromISR xStreamBufferReceiveFromISR + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer, + void *pvRxData, + size_t xBufferLengthBytes, + BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer );
+
+ * + * Deletes a stream buffer that was previously created using a call to + * xStreamBufferCreate() or xStreamBufferCreateStatic(). If the stream + * buffer was created using dynamic memory (that is, by xStreamBufferCreate()), + * then the allocated memory is freed. + * + * A stream buffer handle must not be used after the stream buffer has been + * deleted. + * + * @param xStreamBuffer The handle of the stream buffer to be deleted. + * + * \defgroup vStreamBufferDelete vStreamBufferDelete + * \ingroup StreamBufferManagement + */ +void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer );
+
+ * + * Queries a stream buffer to see if it is full. A stream buffer is full if it + * does not have any free space, and therefore cannot accept any more data. + * + * @param xStreamBuffer The handle of the stream buffer being queried. + * + * @return If the stream buffer is full then pdTRUE is returned. Otherwise + * pdFALSE is returned. + * + * \defgroup xStreamBufferIsFull xStreamBufferIsFull + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer );
+
+ * + * Queries a stream buffer to see if it is empty. A stream buffer is empty if + * it does not contain any data. + * + * @param xStreamBuffer The handle of the stream buffer being queried. + * + * @return If the stream buffer is empty then pdTRUE is returned. Otherwise + * pdFALSE is returned. + * + * \defgroup xStreamBufferIsEmpty xStreamBufferIsEmpty + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer );
+
+ * + * Resets a stream buffer to its initial, empty, state. Any data that was in + * the stream buffer is discarded. A stream buffer can only be reset if there + * are no tasks blocked waiting to either send to or receive from the stream + * buffer. + * + * @param xStreamBuffer The handle of the stream buffer being reset. + * + * @return If the stream buffer is reset then pdPASS is returned. If there was + * a task blocked waiting to send to or read from the stream buffer then the + * stream buffer is not reset and pdFAIL is returned. + * + * \defgroup xStreamBufferReset xStreamBufferReset + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer );
+
+ * + * Queries a stream buffer to see how much free space it contains, which is + * equal to the amount of data that can be sent to the stream buffer before it + * is full. + * + * @param xStreamBuffer The handle of the stream buffer being queried. + * + * @return The number of bytes that can be written to the stream buffer before + * the stream buffer would be full. + * + * \defgroup xStreamBufferSpacesAvailable xStreamBufferSpacesAvailable + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer );
+
+ * + * Queries a stream buffer to see how much data it contains, which is equal to + * the number of bytes that can be read from the stream buffer before the stream + * buffer would be empty. + * + * @param xStreamBuffer The handle of the stream buffer being queried. + * + * @return The number of bytes that can be read from the stream buffer before + * the stream buffer would be empty. + * + * \defgroup xStreamBufferBytesAvailable xStreamBufferBytesAvailable + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel );
+
+ * + * A stream buffer's trigger level is the number of bytes that must be in the + * stream buffer before a task that is blocked on the stream buffer to + * wait for data is moved out of the blocked state. For example, if a task is + * blocked on a read of an empty stream buffer that has a trigger level of 1 + * then the task will be unblocked when a single byte is written to the buffer + * or the task's block time expires. As another example, if a task is blocked + * on a read of an empty stream buffer that has a trigger level of 10 then the + * task will not be unblocked until the stream buffer contains at least 10 bytes + * or the task's block time expires. If a reading task's block time expires + * before the trigger level is reached then the task will still receive however + * many bytes are actually available. Setting a trigger level of 0 will result + * in a trigger level of 1 being used. It is not valid to specify a trigger + * level that is greater than the buffer size. + * + * A trigger level is set when the stream buffer is created, and can be modified + * using xStreamBufferSetTriggerLevel(). + * + * @param xStreamBuffer The handle of the stream buffer being updated. + * + * @param xTriggerLevel The new trigger level for the stream buffer. + * + * @return If xTriggerLevel was less than or equal to the stream buffer's length + * then the trigger level will be updated and pdTRUE is returned. Otherwise + * pdFALSE is returned. + * + * \defgroup xStreamBufferSetTriggerLevel xStreamBufferSetTriggerLevel + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
+
+ * + * For advanced users only. + * + * The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when + * data is sent to a message buffer or stream buffer. If there was a task that + * was blocked on the message or stream buffer waiting for data to arrive then + * the sbSEND_COMPLETED() macro sends a notification to the task to remove it + * from the Blocked state. xStreamBufferSendCompletedFromISR() does the same + * thing. It is provided to enable application writers to implement their own + * version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME. + * + * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for + * additional information. + * + * @param xStreamBuffer The handle of the stream buffer to which data was + * written. + * + * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be + * initialised to pdFALSE before it is passed into + * xStreamBufferSendCompletedFromISR(). If calling + * xStreamBufferSendCompletedFromISR() removes a task from the Blocked state, + * and the task has a priority above the priority of the currently running task, + * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a + * context switch should be performed before exiting the ISR. + * + * @return If a task was removed from the Blocked state then pdTRUE is returned. + * Otherwise pdFALSE is returned. + * + * \defgroup xStreamBufferSendCompletedFromISR xStreamBufferSendCompletedFromISR + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * +
+BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
+
+ * + * For advanced users only. + * + * The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when + * data is read out of a message buffer or stream buffer. If there was a task + * that was blocked on the message or stream buffer waiting for data to arrive + * then the sbRECEIVE_COMPLETED() macro sends a notification to the task to + * remove it from the Blocked state. xStreamBufferReceiveCompletedFromISR() + * does the same thing. It is provided to enable application writers to + * implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT + * ANY OTHER TIME. + * + * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for + * additional information. + * + * @param xStreamBuffer The handle of the stream buffer from which data was + * read. + * + * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be + * initialised to pdFALSE before it is passed into + * xStreamBufferReceiveCompletedFromISR(). If calling + * xStreamBufferReceiveCompletedFromISR() removes a task from the Blocked state, + * and the task has a priority above the priority of the currently running task, + * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a + * context switch should be performed before exiting the ISR. + * + * @return If a task was removed from the Blocked state then pdTRUE is returned. + * Otherwise pdFALSE is returned. + * + * \defgroup xStreamBufferReceiveCompletedFromISR xStreamBufferReceiveCompletedFromISR + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/* Functions below here are not part of the public API. */ +StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer ) PRIVILEGED_FUNCTION; + +StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer, + uint8_t * const pucStreamBufferStorageArea, + StaticStreamBuffer_t * const pxStaticStreamBuffer ) PRIVILEGED_FUNCTION; + +#if( configUSE_TRACE_FACILITY == 1 ) + void vStreamBufferSetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer, UBaseType_t uxStreamBufferNumber ) PRIVILEGED_FUNCTION; + UBaseType_t uxStreamBufferGetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + uint8_t ucStreamBufferGetStreamBufferType( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; +#endif + +#if defined( __cplusplus ) +} +#endif + +#endif /* !defined( STREAM_BUFFER_H ) */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/task.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/task.h new file mode 100644 index 0000000..6c9d428 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/task.h @@ -0,0 +1,2338 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + + +#ifndef INC_TASK_H +#define INC_TASK_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h must appear in source files before include task.h" +#endif + +#include "list.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*----------------------------------------------------------- + * MACROS AND DEFINITIONS + *----------------------------------------------------------*/ + +#define tskKERNEL_VERSION_NUMBER "V10.0.1" +#define tskKERNEL_VERSION_MAJOR 10 +#define tskKERNEL_VERSION_MINOR 0 +#define tskKERNEL_VERSION_BUILD 1 + +/** + * task. h + * + * Type by which tasks are referenced. For example, a call to xTaskCreate + * returns (via a pointer parameter) an TaskHandle_t variable that can then + * be used as a parameter to vTaskDelete to delete the task. + * + * \defgroup TaskHandle_t TaskHandle_t + * \ingroup Tasks + */ +typedef void * TaskHandle_t; + +/* + * Defines the prototype to which the application task hook function must + * conform. + */ +typedef BaseType_t (*TaskHookFunction_t)( void * ); + +/* Task states returned by eTaskGetState. */ +typedef enum +{ + eRunning = 0, /* A task is querying the state of itself, so must be running. */ + eReady, /* The task being queried is in a read or pending ready list. */ + eBlocked, /* The task being queried is in the Blocked state. */ + eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */ + eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */ + eInvalid /* Used as an 'invalid state' value. */ +} eTaskState; + +/* Actions that can be performed when vTaskNotify() is called. */ +typedef enum +{ + eNoAction = 0, /* Notify the task without updating its notify value. */ + eSetBits, /* Set bits in the task's notification value. */ + eIncrement, /* Increment the task's notification value. */ + eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */ + eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */ +} eNotifyAction; + +/* + * Used internally only. + */ +typedef struct xTIME_OUT +{ + BaseType_t xOverflowCount; + TickType_t xTimeOnEntering; +} TimeOut_t; + +/* + * Defines the memory ranges allocated to the task when an MPU is used. + */ +typedef struct xMEMORY_REGION +{ + void *pvBaseAddress; + uint32_t ulLengthInBytes; + uint32_t ulParameters; +} MemoryRegion_t; + +/* + * Parameters required to create an MPU protected task. + */ +typedef struct xTASK_PARAMETERS +{ + TaskFunction_t pvTaskCode; + const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + uint16_t usStackDepth; + void *pvParameters; + UBaseType_t uxPriority; + StackType_t *puxStackBuffer; + MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ]; + #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + StaticTask_t * const pxTaskBuffer; + #endif +} TaskParameters_t; + +/* Used with the uxTaskGetSystemState() function to return the state of each task +in the system. */ +typedef struct xTASK_STATUS +{ + TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */ + const char *pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + UBaseType_t xTaskNumber; /* A number unique to the task. */ + eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */ + UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */ + UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */ + uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See http://www.freertos.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */ + StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */ + uint16_t usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */ +} TaskStatus_t; + +/* Possible return values for eTaskConfirmSleepModeStatus(). */ +typedef enum +{ + eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPORESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */ + eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */ + eNoTasksWaitingTimeout /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */ +} eSleepModeStatus; + +/** + * Defines the priority used by the idle task. This must not be modified. + * + * \ingroup TaskUtils + */ +#define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U ) + +/** + * task. h + * + * Macro for forcing a context switch. + * + * \defgroup taskYIELD taskYIELD + * \ingroup SchedulerControl + */ +#define taskYIELD() portYIELD() + +/** + * task. h + * + * Macro to mark the start of a critical code region. Preemptive context + * switches cannot occur when in a critical region. + * + * NOTE: This may alter the stack (depending on the portable implementation) + * so must be used with care! + * + * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL + * \ingroup SchedulerControl + */ +#define taskENTER_CRITICAL() portENTER_CRITICAL() +#define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR() + +/** + * task. h + * + * Macro to mark the end of a critical code region. Preemptive context + * switches cannot occur when in a critical region. + * + * NOTE: This may alter the stack (depending on the portable implementation) + * so must be used with care! + * + * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL + * \ingroup SchedulerControl + */ +#define taskEXIT_CRITICAL() portEXIT_CRITICAL() +#define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) +/** + * task. h + * + * Macro to disable all maskable interrupts. + * + * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS + * \ingroup SchedulerControl + */ +#define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS() + +/** + * task. h + * + * Macro to enable microcontroller interrupts. + * + * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS + * \ingroup SchedulerControl + */ +#define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS() + +/* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is +0 to generate more optimal code when configASSERT() is defined as the constant +is used in assert() statements. */ +#define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 ) +#define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 ) +#define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 ) + + +/*----------------------------------------------------------- + * TASK CREATION API + *----------------------------------------------------------*/ + +/** + * task. h + *
+ BaseType_t xTaskCreate(
+                              TaskFunction_t pvTaskCode,
+                              const char * const pcName,
+                              configSTACK_DEPTH_TYPE usStackDepth,
+                              void *pvParameters,
+                              UBaseType_t uxPriority,
+                              TaskHandle_t *pvCreatedTask
+                          );
+ * + * Create a new task and add it to the list of tasks that are ready to run. + * + * Internally, within the FreeRTOS implementation, tasks use two blocks of + * memory. The first block is used to hold the task's data structures. The + * second block is used by the task as its stack. If a task is created using + * xTaskCreate() then both blocks of memory are automatically dynamically + * allocated inside the xTaskCreate() function. (see + * http://www.freertos.org/a00111.html). If a task is created using + * xTaskCreateStatic() then the application writer must provide the required + * memory. xTaskCreateStatic() therefore allows a task to be created without + * using any dynamic memory allocation. + * + * See xTaskCreateStatic() for a version that does not use any dynamic memory + * allocation. + * + * xTaskCreate() can only be used to create a task that has unrestricted + * access to the entire microcontroller memory map. Systems that include MPU + * support can alternatively create an MPU constrained task using + * xTaskCreateRestricted(). + * + * @param pvTaskCode Pointer to the task entry function. Tasks + * must be implemented to never return (i.e. continuous loop). + * + * @param pcName A descriptive name for the task. This is mainly used to + * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default + * is 16. + * + * @param usStackDepth The size of the task stack specified as the number of + * variables the stack can hold - not the number of bytes. For example, if + * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes + * will be allocated for stack storage. + * + * @param pvParameters Pointer that will be used as the parameter for the task + * being created. + * + * @param uxPriority The priority at which the task should run. Systems that + * include MPU support can optionally create tasks in a privileged (system) + * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For + * example, to create a privileged task at priority 2 the uxPriority parameter + * should be set to ( 2 | portPRIVILEGE_BIT ). + * + * @param pvCreatedTask Used to pass back a handle by which the created task + * can be referenced. + * + * @return pdPASS if the task was successfully created and added to a ready + * list, otherwise an error code defined in the file projdefs.h + * + * Example usage: +
+ // Task to be created.
+ void vTaskCode( void * pvParameters )
+ {
+     for( ;; )
+     {
+         // Task code goes here.
+     }
+ }
+
+ // Function that creates a task.
+ void vOtherFunction( void )
+ {
+ static uint8_t ucParameterToPass;
+ TaskHandle_t xHandle = NULL;
+
+     // Create the task, storing the handle.  Note that the passed parameter ucParameterToPass
+     // must exist for the lifetime of the task, so in this case is declared static.  If it was just an
+     // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
+     // the new task attempts to access it.
+     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
+     configASSERT( xHandle );
+
+     // Use the handle to delete the task.
+     if( xHandle != NULL )
+     {
+         vTaskDelete( xHandle );
+     }
+ }
+   
+ * \defgroup xTaskCreate xTaskCreate + * \ingroup Tasks + */ +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + BaseType_t xTaskCreate( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const configSTACK_DEPTH_TYPE usStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION; +#endif + +/** + * task. h + *
+ TaskHandle_t xTaskCreateStatic( TaskFunction_t pvTaskCode,
+                                 const char * const pcName,
+                                 uint32_t ulStackDepth,
+                                 void *pvParameters,
+                                 UBaseType_t uxPriority,
+                                 StackType_t *pxStackBuffer,
+                                 StaticTask_t *pxTaskBuffer );
+ * + * Create a new task and add it to the list of tasks that are ready to run. + * + * Internally, within the FreeRTOS implementation, tasks use two blocks of + * memory. The first block is used to hold the task's data structures. The + * second block is used by the task as its stack. If a task is created using + * xTaskCreate() then both blocks of memory are automatically dynamically + * allocated inside the xTaskCreate() function. (see + * http://www.freertos.org/a00111.html). If a task is created using + * xTaskCreateStatic() then the application writer must provide the required + * memory. xTaskCreateStatic() therefore allows a task to be created without + * using any dynamic memory allocation. + * + * @param pvTaskCode Pointer to the task entry function. Tasks + * must be implemented to never return (i.e. continuous loop). + * + * @param pcName A descriptive name for the task. This is mainly used to + * facilitate debugging. The maximum length of the string is defined by + * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h. + * + * @param ulStackDepth The size of the task stack specified as the number of + * variables the stack can hold - not the number of bytes. For example, if + * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes + * will be allocated for stack storage. + * + * @param pvParameters Pointer that will be used as the parameter for the task + * being created. + * + * @param uxPriority The priority at which the task will run. + * + * @param pxStackBuffer Must point to a StackType_t array that has at least + * ulStackDepth indexes - the array will then be used as the task's stack, + * removing the need for the stack to be allocated dynamically. + * + * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will + * then be used to hold the task's data structures, removing the need for the + * memory to be allocated dynamically. + * + * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will + * be created and pdPASS is returned. If either pxStackBuffer or pxTaskBuffer + * are NULL then the task will not be created and + * errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned. + * + * Example usage: +
+
+    // Dimensions the buffer that the task being created will use as its stack.
+    // NOTE:  This is the number of words the stack will hold, not the number of
+    // bytes.  For example, if each stack item is 32-bits, and this is set to 100,
+    // then 400 bytes (100 * 32-bits) will be allocated.
+    #define STACK_SIZE 200
+
+    // Structure that will hold the TCB of the task being created.
+    StaticTask_t xTaskBuffer;
+
+    // Buffer that the task being created will use as its stack.  Note this is
+    // an array of StackType_t variables.  The size of StackType_t is dependent on
+    // the RTOS port.
+    StackType_t xStack[ STACK_SIZE ];
+
+    // Function that implements the task being created.
+    void vTaskCode( void * pvParameters )
+    {
+        // The parameter value is expected to be 1 as 1 is passed in the
+        // pvParameters value in the call to xTaskCreateStatic().
+        configASSERT( ( uint32_t ) pvParameters == 1UL );
+
+        for( ;; )
+        {
+            // Task code goes here.
+        }
+    }
+
+    // Function that creates a task.
+    void vOtherFunction( void )
+    {
+        TaskHandle_t xHandle = NULL;
+
+        // Create the task without using any dynamic memory allocation.
+        xHandle = xTaskCreateStatic(
+                      vTaskCode,       // Function that implements the task.
+                      "NAME",          // Text name for the task.
+                      STACK_SIZE,      // Stack size in words, not bytes.
+                      ( void * ) 1,    // Parameter passed into the task.
+                      tskIDLE_PRIORITY,// Priority at which the task is created.
+                      xStack,          // Array to use as the task's stack.
+                      &xTaskBuffer );  // Variable to hold the task's data structure.
+
+        // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
+        // been created, and xHandle will be the task's handle.  Use the handle
+        // to suspend the task.
+        vTaskSuspend( xHandle );
+    }
+   
+ * \defgroup xTaskCreateStatic xTaskCreateStatic + * \ingroup Tasks + */ +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const uint32_t ulStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + StackType_t * const puxStackBuffer, + StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION; +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * task. h + *
+ BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
+ * + * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1. + * + * xTaskCreateRestricted() should only be used in systems that include an MPU + * implementation. + * + * Create a new task and add it to the list of tasks that are ready to run. + * The function parameters define the memory regions and associated access + * permissions allocated to the task. + * + * See xTaskCreateRestrictedStatic() for a version that does not use any + * dynamic memory allocation. + * + * @param pxTaskDefinition Pointer to a structure that contains a member + * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API + * documentation) plus an optional stack buffer and the memory region + * definitions. + * + * @param pxCreatedTask Used to pass back a handle by which the created task + * can be referenced. + * + * @return pdPASS if the task was successfully created and added to a ready + * list, otherwise an error code defined in the file projdefs.h + * + * Example usage: +
+// Create an TaskParameters_t structure that defines the task to be created.
+static const TaskParameters_t xCheckTaskParameters =
+{
+    vATask,        // pvTaskCode - the function that implements the task.
+    "ATask",    // pcName - just a text name for the task to assist debugging.
+    100,        // usStackDepth    - the stack size DEFINED IN WORDS.
+    NULL,        // pvParameters - passed into the task function as the function parameters.
+    ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
+    cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
+
+    // xRegions - Allocate up to three separate memory regions for access by
+    // the task, with appropriate access permissions.  Different processors have
+    // different memory alignment requirements - refer to the FreeRTOS documentation
+    // for full information.
+    {
+        // Base address                    Length    Parameters
+        { cReadWriteArray,                32,        portMPU_REGION_READ_WRITE },
+        { cReadOnlyArray,                32,        portMPU_REGION_READ_ONLY },
+        { cPrivilegedOnlyAccessArray,    128,    portMPU_REGION_PRIVILEGED_READ_WRITE }
+    }
+};
+
+int main( void )
+{
+TaskHandle_t xHandle;
+
+    // Create a task from the const structure defined above.  The task handle
+    // is requested (the second parameter is not NULL) but in this case just for
+    // demonstration purposes as its not actually used.
+    xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
+
+    // Start the scheduler.
+    vTaskStartScheduler();
+
+    // Will only get here if there was insufficient memory to create the idle
+    // and/or timer task.
+    for( ;; );
+}
+   
+ * \defgroup xTaskCreateRestricted xTaskCreateRestricted + * \ingroup Tasks + */ +#if( portUSING_MPU_WRAPPERS == 1 ) + BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION; +#endif + +/** + * task. h + *
+ BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
+ * + * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1. + * + * xTaskCreateRestrictedStatic() should only be used in systems that include an + * MPU implementation. + * + * Internally, within the FreeRTOS implementation, tasks use two blocks of + * memory. The first block is used to hold the task's data structures. The + * second block is used by the task as its stack. If a task is created using + * xTaskCreateRestricted() then the stack is provided by the application writer, + * and the memory used to hold the task's data structure is automatically + * dynamically allocated inside the xTaskCreateRestricted() function. If a task + * is created using xTaskCreateRestrictedStatic() then the application writer + * must provide the memory used to hold the task's data structures too. + * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be + * created without using any dynamic memory allocation. + * + * @param pxTaskDefinition Pointer to a structure that contains a member + * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API + * documentation) plus an optional stack buffer and the memory region + * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure + * contains an additional member, which is used to point to a variable of type + * StaticTask_t - which is then used to hold the task's data structure. + * + * @param pxCreatedTask Used to pass back a handle by which the created task + * can be referenced. + * + * @return pdPASS if the task was successfully created and added to a ready + * list, otherwise an error code defined in the file projdefs.h + * + * Example usage: +
+// Create an TaskParameters_t structure that defines the task to be created.
+// The StaticTask_t variable is only included in the structure when
+// configSUPPORT_STATIC_ALLOCATION is set to 1.  The PRIVILEGED_DATA macro can
+// be used to force the variable into the RTOS kernel's privileged data area.
+static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
+static const TaskParameters_t xCheckTaskParameters =
+{
+    vATask,        // pvTaskCode - the function that implements the task.
+    "ATask",    // pcName - just a text name for the task to assist debugging.
+    100,        // usStackDepth    - the stack size DEFINED IN WORDS.
+    NULL,        // pvParameters - passed into the task function as the function parameters.
+    ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
+    cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
+
+    // xRegions - Allocate up to three separate memory regions for access by
+    // the task, with appropriate access permissions.  Different processors have
+    // different memory alignment requirements - refer to the FreeRTOS documentation
+    // for full information.
+    {
+        // Base address                    Length    Parameters
+        { cReadWriteArray,                32,        portMPU_REGION_READ_WRITE },
+        { cReadOnlyArray,                32,        portMPU_REGION_READ_ONLY },
+        { cPrivilegedOnlyAccessArray,    128,    portMPU_REGION_PRIVILEGED_READ_WRITE }
+    }
+
+    &xTaskBuffer; // Holds the task's data structure.
+};
+
+int main( void )
+{
+TaskHandle_t xHandle;
+
+    // Create a task from the const structure defined above.  The task handle
+    // is requested (the second parameter is not NULL) but in this case just for
+    // demonstration purposes as its not actually used.
+    xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
+
+    // Start the scheduler.
+    vTaskStartScheduler();
+
+    // Will only get here if there was insufficient memory to create the idle
+    // and/or timer task.
+    for( ;; );
+}
+   
+ * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic + * \ingroup Tasks + */ +#if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION; +#endif + +/** + * task. h + *
+ void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );
+ * + * Memory regions are assigned to a restricted task when the task is created by + * a call to xTaskCreateRestricted(). These regions can be redefined using + * vTaskAllocateMPURegions(). + * + * @param xTask The handle of the task being updated. + * + * @param xRegions A pointer to an MemoryRegion_t structure that contains the + * new memory region definitions. + * + * Example usage: +
+// Define an array of MemoryRegion_t structures that configures an MPU region
+// allowing read/write access for 1024 bytes starting at the beginning of the
+// ucOneKByte array.  The other two of the maximum 3 definable regions are
+// unused so set to zero.
+static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
+{
+    // Base address        Length        Parameters
+    { ucOneKByte,        1024,        portMPU_REGION_READ_WRITE },
+    { 0,                0,            0 },
+    { 0,                0,            0 }
+};
+
+void vATask( void *pvParameters )
+{
+    // This task was created such that it has access to certain regions of
+    // memory as defined by the MPU configuration.  At some point it is
+    // desired that these MPU regions are replaced with that defined in the
+    // xAltRegions const struct above.  Use a call to vTaskAllocateMPURegions()
+    // for this purpose.  NULL is used as the task handle to indicate that this
+    // function should modify the MPU regions of the calling task.
+    vTaskAllocateMPURegions( NULL, xAltRegions );
+
+    // Now the task can continue its function, but from this point on can only
+    // access its stack and the ucOneKByte array (unless any other statically
+    // defined or shared regions have been declared elsewhere).
+}
+   
+ * \defgroup xTaskCreateRestricted xTaskCreateRestricted + * \ingroup Tasks + */ +void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void vTaskDelete( TaskHandle_t xTask );
+ * + * INCLUDE_vTaskDelete must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Remove a task from the RTOS real time kernel's management. The task being + * deleted will be removed from all ready, blocked, suspended and event lists. + * + * NOTE: The idle task is responsible for freeing the kernel allocated + * memory from tasks that have been deleted. It is therefore important that + * the idle task is not starved of microcontroller processing time if your + * application makes any calls to vTaskDelete (). Memory allocated by the + * task code is not automatically freed, and should be freed before the task + * is deleted. + * + * See the demo application file death.c for sample code that utilises + * vTaskDelete (). + * + * @param xTask The handle of the task to be deleted. Passing NULL will + * cause the calling task to be deleted. + * + * Example usage: +
+ void vOtherFunction( void )
+ {
+ TaskHandle_t xHandle;
+
+     // Create the task, storing the handle.
+     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
+
+     // Use the handle to delete the task.
+     vTaskDelete( xHandle );
+ }
+   
+ * \defgroup vTaskDelete vTaskDelete + * \ingroup Tasks + */ +void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION; + +/*----------------------------------------------------------- + * TASK CONTROL API + *----------------------------------------------------------*/ + +/** + * task. h + *
void vTaskDelay( const TickType_t xTicksToDelay );
+ * + * Delay a task for a given number of ticks. The actual time that the + * task remains blocked depends on the tick rate. The constant + * portTICK_PERIOD_MS can be used to calculate real time from the tick + * rate - with the resolution of one tick period. + * + * INCLUDE_vTaskDelay must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * + * vTaskDelay() specifies a time at which the task wishes to unblock relative to + * the time at which vTaskDelay() is called. For example, specifying a block + * period of 100 ticks will cause the task to unblock 100 ticks after + * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method + * of controlling the frequency of a periodic task as the path taken through the + * code, as well as other task and interrupt activity, will effect the frequency + * at which vTaskDelay() gets called and therefore the time at which the task + * next executes. See vTaskDelayUntil() for an alternative API function designed + * to facilitate fixed frequency execution. It does this by specifying an + * absolute time (rather than a relative time) at which the calling task should + * unblock. + * + * @param xTicksToDelay The amount of time, in tick periods, that + * the calling task should block. + * + * Example usage: + + void vTaskFunction( void * pvParameters ) + { + // Block for 500ms. + const TickType_t xDelay = 500 / portTICK_PERIOD_MS; + + for( ;; ) + { + // Simply toggle the LED every 500ms, blocking between each toggle. + vToggleLED(); + vTaskDelay( xDelay ); + } + } + + * \defgroup vTaskDelay vTaskDelay + * \ingroup TaskCtrl + */ +void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
+ * + * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Delay a task until a specified time. This function can be used by periodic + * tasks to ensure a constant execution frequency. + * + * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will + * cause a task to block for the specified number of ticks from the time vTaskDelay () is + * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed + * execution frequency as the time between a task starting to execute and that task + * calling vTaskDelay () may not be fixed [the task may take a different path though the + * code between calls, or may get interrupted or preempted a different number of times + * each time it executes]. + * + * Whereas vTaskDelay () specifies a wake time relative to the time at which the function + * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to + * unblock. + * + * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick + * rate - with the resolution of one tick period. + * + * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the + * task was last unblocked. The variable must be initialised with the current time + * prior to its first use (see the example below). Following this the variable is + * automatically updated within vTaskDelayUntil (). + * + * @param xTimeIncrement The cycle time period. The task will be unblocked at + * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the + * same xTimeIncrement parameter value will cause the task to execute with + * a fixed interface period. + * + * Example usage: +
+ // Perform an action every 10 ticks.
+ void vTaskFunction( void * pvParameters )
+ {
+ TickType_t xLastWakeTime;
+ const TickType_t xFrequency = 10;
+
+     // Initialise the xLastWakeTime variable with the current time.
+     xLastWakeTime = xTaskGetTickCount ();
+     for( ;; )
+     {
+         // Wait for the next cycle.
+         vTaskDelayUntil( &xLastWakeTime, xFrequency );
+
+         // Perform action here.
+     }
+ }
+   
+ * \defgroup vTaskDelayUntil vTaskDelayUntil + * \ingroup TaskCtrl + */ +void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
+ * + * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this + * function to be available. + * + * A task will enter the Blocked state when it is waiting for an event. The + * event it is waiting for can be a temporal event (waiting for a time), such + * as when vTaskDelay() is called, or an event on an object, such as when + * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task + * that is in the Blocked state is used in a call to xTaskAbortDelay() then the + * task will leave the Blocked state, and return from whichever function call + * placed the task into the Blocked state. + * + * @param xTask The handle of the task to remove from the Blocked state. + * + * @return If the task referenced by xTask was not in the Blocked state then + * pdFAIL is returned. Otherwise pdPASS is returned. + * + * \defgroup xTaskAbortDelay xTaskAbortDelay + * \ingroup TaskCtrl + */ +BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask );
+ * + * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Obtain the priority of any task. + * + * @param xTask Handle of the task to be queried. Passing a NULL + * handle results in the priority of the calling task being returned. + * + * @return The priority of xTask. + * + * Example usage: +
+ void vAFunction( void )
+ {
+ TaskHandle_t xHandle;
+
+     // Create a task, storing the handle.
+     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
+
+     // ...
+
+     // Use the handle to obtain the priority of the created task.
+     // It was created with tskIDLE_PRIORITY, but may have changed
+     // it itself.
+     if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
+     {
+         // The task has changed it's priority.
+     }
+
+     // ...
+
+     // Is our priority higher than the created task?
+     if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
+     {
+         // Our priority (obtained using NULL handle) is higher.
+     }
+ }
+   
+ * \defgroup uxTaskPriorityGet uxTaskPriorityGet + * \ingroup TaskCtrl + */ +UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask );
+ * + * A version of uxTaskPriorityGet() that can be used from an ISR. + */ +UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
eTaskState eTaskGetState( TaskHandle_t xTask );
+ * + * INCLUDE_eTaskGetState must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Obtain the state of any task. States are encoded by the eTaskState + * enumerated type. + * + * @param xTask Handle of the task to be queried. + * + * @return The state of xTask at the time the function was called. Note the + * state of the task might change between the function being called, and the + * functions return value being tested by the calling task. + */ +eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );
+ * + * configUSE_TRACE_FACILITY must be defined as 1 for this function to be + * available. See the configuration section for more information. + * + * Populates a TaskStatus_t structure with information about a task. + * + * @param xTask Handle of the task being queried. If xTask is NULL then + * information will be returned about the calling task. + * + * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be + * filled with information about the task referenced by the handle passed using + * the xTask parameter. + * + * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report + * the stack high water mark of the task being queried. Calculating the stack + * high water mark takes a relatively long time, and can make the system + * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to + * allow the high water mark checking to be skipped. The high watermark value + * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is + * not set to pdFALSE; + * + * @param eState The TaskStatus_t structure contains a member to report the + * state of the task being queried. Obtaining the task state is not as fast as + * a simple assignment - so the eState parameter is provided to allow the state + * information to be omitted from the TaskStatus_t structure. To obtain state + * information then set eState to eInvalid - otherwise the value passed in + * eState will be reported as the task state in the TaskStatus_t structure. + * + * Example usage: +
+ void vAFunction( void )
+ {
+ TaskHandle_t xHandle;
+ TaskStatus_t xTaskDetails;
+
+    // Obtain the handle of a task from its name.
+    xHandle = xTaskGetHandle( "Task_Name" );
+
+    // Check the handle is not NULL.
+    configASSERT( xHandle );
+
+    // Use the handle to obtain further information about the task.
+    vTaskGetInfo( xHandle,
+                  &xTaskDetails,
+                  pdTRUE, // Include the high water mark in xTaskDetails.
+                  eInvalid ); // Include the task state in xTaskDetails.
+ }
+   
+ * \defgroup vTaskGetInfo vTaskGetInfo + * \ingroup TaskCtrl + */ +void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );
+ * + * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Set the priority of any task. + * + * A context switch will occur before the function returns if the priority + * being set is higher than the currently executing task. + * + * @param xTask Handle to the task for which the priority is being set. + * Passing a NULL handle results in the priority of the calling task being set. + * + * @param uxNewPriority The priority to which the task will be set. + * + * Example usage: +
+ void vAFunction( void )
+ {
+ TaskHandle_t xHandle;
+
+     // Create a task, storing the handle.
+     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
+
+     // ...
+
+     // Use the handle to raise the priority of the created task.
+     vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
+
+     // ...
+
+     // Use a NULL handle to raise our priority to the same value.
+     vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
+ }
+   
+ * \defgroup vTaskPrioritySet vTaskPrioritySet + * \ingroup TaskCtrl + */ +void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void vTaskSuspend( TaskHandle_t xTaskToSuspend );
+ * + * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Suspend any task. When suspended a task will never get any microcontroller + * processing time, no matter what its priority. + * + * Calls to vTaskSuspend are not accumulative - + * i.e. calling vTaskSuspend () twice on the same task still only requires one + * call to vTaskResume () to ready the suspended task. + * + * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL + * handle will cause the calling task to be suspended. + * + * Example usage: +
+ void vAFunction( void )
+ {
+ TaskHandle_t xHandle;
+
+     // Create a task, storing the handle.
+     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
+
+     // ...
+
+     // Use the handle to suspend the created task.
+     vTaskSuspend( xHandle );
+
+     // ...
+
+     // The created task will not run during this period, unless
+     // another task calls vTaskResume( xHandle ).
+
+     //...
+
+
+     // Suspend ourselves.
+     vTaskSuspend( NULL );
+
+     // We cannot get here unless another task calls vTaskResume
+     // with our handle as the parameter.
+ }
+   
+ * \defgroup vTaskSuspend vTaskSuspend + * \ingroup TaskCtrl + */ +void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void vTaskResume( TaskHandle_t xTaskToResume );
+ * + * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Resumes a suspended task. + * + * A task that has been suspended by one or more calls to vTaskSuspend () + * will be made available for running again by a single call to + * vTaskResume (). + * + * @param xTaskToResume Handle to the task being readied. + * + * Example usage: +
+ void vAFunction( void )
+ {
+ TaskHandle_t xHandle;
+
+     // Create a task, storing the handle.
+     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
+
+     // ...
+
+     // Use the handle to suspend the created task.
+     vTaskSuspend( xHandle );
+
+     // ...
+
+     // The created task will not run during this period, unless
+     // another task calls vTaskResume( xHandle ).
+
+     //...
+
+
+     // Resume the suspended task ourselves.
+     vTaskResume( xHandle );
+
+     // The created task will once again get microcontroller processing
+     // time in accordance with its priority within the system.
+ }
+   
+ * \defgroup vTaskResume vTaskResume + * \ingroup TaskCtrl + */ +void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void xTaskResumeFromISR( TaskHandle_t xTaskToResume );
+ * + * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be + * available. See the configuration section for more information. + * + * An implementation of vTaskResume() that can be called from within an ISR. + * + * A task that has been suspended by one or more calls to vTaskSuspend () + * will be made available for running again by a single call to + * xTaskResumeFromISR (). + * + * xTaskResumeFromISR() should not be used to synchronise a task with an + * interrupt if there is a chance that the interrupt could arrive prior to the + * task being suspended - as this can lead to interrupts being missed. Use of a + * semaphore as a synchronisation mechanism would avoid this eventuality. + * + * @param xTaskToResume Handle to the task being readied. + * + * @return pdTRUE if resuming the task should result in a context switch, + * otherwise pdFALSE. This is used by the ISR to determine if a context switch + * may be required following the ISR. + * + * \defgroup vTaskResumeFromISR vTaskResumeFromISR + * \ingroup TaskCtrl + */ +BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION; + +/*----------------------------------------------------------- + * SCHEDULER CONTROL + *----------------------------------------------------------*/ + +/** + * task. h + *
void vTaskStartScheduler( void );
+ * + * Starts the real time kernel tick processing. After calling the kernel + * has control over which tasks are executed and when. + * + * See the demo application file main.c for an example of creating + * tasks and starting the kernel. + * + * Example usage: +
+ void vAFunction( void )
+ {
+     // Create at least one task before starting the kernel.
+     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+
+     // Start the real time kernel with preemption.
+     vTaskStartScheduler ();
+
+     // Will not get here unless a task calls vTaskEndScheduler ()
+ }
+   
+ * + * \defgroup vTaskStartScheduler vTaskStartScheduler + * \ingroup SchedulerControl + */ +void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void vTaskEndScheduler( void );
+ * + * NOTE: At the time of writing only the x86 real mode port, which runs on a PC + * in place of DOS, implements this function. + * + * Stops the real time kernel tick. All created tasks will be automatically + * deleted and multitasking (either preemptive or cooperative) will + * stop. Execution then resumes from the point where vTaskStartScheduler () + * was called, as if vTaskStartScheduler () had just returned. + * + * See the demo application file main. c in the demo/PC directory for an + * example that uses vTaskEndScheduler (). + * + * vTaskEndScheduler () requires an exit function to be defined within the + * portable layer (see vPortEndScheduler () in port. c for the PC port). This + * performs hardware specific operations such as stopping the kernel tick. + * + * vTaskEndScheduler () will cause all of the resources allocated by the + * kernel to be freed - but will not free resources allocated by application + * tasks. + * + * Example usage: +
+ void vTaskCode( void * pvParameters )
+ {
+     for( ;; )
+     {
+         // Task code goes here.
+
+         // At some point we want to end the real time kernel processing
+         // so call ...
+         vTaskEndScheduler ();
+     }
+ }
+
+ void vAFunction( void )
+ {
+     // Create at least one task before starting the kernel.
+     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+
+     // Start the real time kernel with preemption.
+     vTaskStartScheduler ();
+
+     // Will only get here when the vTaskCode () task has called
+     // vTaskEndScheduler ().  When we get here we are back to single task
+     // execution.
+ }
+   
+ * + * \defgroup vTaskEndScheduler vTaskEndScheduler + * \ingroup SchedulerControl + */ +void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void vTaskSuspendAll( void );
+ * + * Suspends the scheduler without disabling interrupts. Context switches will + * not occur while the scheduler is suspended. + * + * After calling vTaskSuspendAll () the calling task will continue to execute + * without risk of being swapped out until a call to xTaskResumeAll () has been + * made. + * + * API functions that have the potential to cause a context switch (for example, + * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler + * is suspended. + * + * Example usage: +
+ void vTask1( void * pvParameters )
+ {
+     for( ;; )
+     {
+         // Task code goes here.
+
+         // ...
+
+         // At some point the task wants to perform a long operation during
+         // which it does not want to get swapped out.  It cannot use
+         // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
+         // operation may cause interrupts to be missed - including the
+         // ticks.
+
+         // Prevent the real time kernel swapping out the task.
+         vTaskSuspendAll ();
+
+         // Perform the operation here.  There is no need to use critical
+         // sections as we have all the microcontroller processing time.
+         // During this time interrupts will still operate and the kernel
+         // tick count will be maintained.
+
+         // ...
+
+         // The operation is complete.  Restart the kernel.
+         xTaskResumeAll ();
+     }
+ }
+   
+ * \defgroup vTaskSuspendAll vTaskSuspendAll + * \ingroup SchedulerControl + */ +void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
BaseType_t xTaskResumeAll( void );
+ * + * Resumes scheduler activity after it was suspended by a call to + * vTaskSuspendAll(). + * + * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks + * that were previously suspended by a call to vTaskSuspend(). + * + * @return If resuming the scheduler caused a context switch then pdTRUE is + * returned, otherwise pdFALSE is returned. + * + * Example usage: +
+ void vTask1( void * pvParameters )
+ {
+     for( ;; )
+     {
+         // Task code goes here.
+
+         // ...
+
+         // At some point the task wants to perform a long operation during
+         // which it does not want to get swapped out.  It cannot use
+         // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
+         // operation may cause interrupts to be missed - including the
+         // ticks.
+
+         // Prevent the real time kernel swapping out the task.
+         vTaskSuspendAll ();
+
+         // Perform the operation here.  There is no need to use critical
+         // sections as we have all the microcontroller processing time.
+         // During this time interrupts will still operate and the real
+         // time kernel tick count will be maintained.
+
+         // ...
+
+         // The operation is complete.  Restart the kernel.  We want to force
+         // a context switch - but there is no point if resuming the scheduler
+         // caused a context switch already.
+         if( !xTaskResumeAll () )
+         {
+              taskYIELD ();
+         }
+     }
+ }
+   
+ * \defgroup xTaskResumeAll xTaskResumeAll + * \ingroup SchedulerControl + */ +BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION; + +/*----------------------------------------------------------- + * TASK UTILITIES + *----------------------------------------------------------*/ + +/** + * task. h + *
TickType_t xTaskGetTickCount( void );
+ * + * @return The count of ticks since vTaskStartScheduler was called. + * + * \defgroup xTaskGetTickCount xTaskGetTickCount + * \ingroup TaskUtils + */ +TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
TickType_t xTaskGetTickCountFromISR( void );
+ * + * @return The count of ticks since vTaskStartScheduler was called. + * + * This is a version of xTaskGetTickCount() that is safe to be called from an + * ISR - provided that TickType_t is the natural word size of the + * microcontroller being used or interrupt nesting is either not supported or + * not being used. + * + * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR + * \ingroup TaskUtils + */ +TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
uint16_t uxTaskGetNumberOfTasks( void );
+ * + * @return The number of tasks that the real time kernel is currently managing. + * This includes all ready, blocked and suspended tasks. A task that + * has been deleted but not yet freed by the idle task will also be + * included in the count. + * + * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks + * \ingroup TaskUtils + */ +UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
char *pcTaskGetName( TaskHandle_t xTaskToQuery );
+ * + * @return The text (human readable) name of the task referenced by the handle + * xTaskToQuery. A task can query its own name by either passing in its own + * handle, or by setting xTaskToQuery to NULL. + * + * \defgroup pcTaskGetName pcTaskGetName + * \ingroup TaskUtils + */ +char *pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + +/** + * task. h + *
TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );
+ * + * NOTE: This function takes a relatively long time to complete and should be + * used sparingly. + * + * @return The handle of the task that has the human readable name pcNameToQuery. + * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle + * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available. + * + * \defgroup pcTaskGetHandle pcTaskGetHandle + * \ingroup TaskUtils + */ +TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + +/** + * task.h + *
UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
+ * + * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for + * this function to be available. + * + * Returns the high water mark of the stack associated with xTask. That is, + * the minimum free stack space there has been (in words, so on a 32 bit machine + * a value of 1 means 4 bytes) since the task started. The smaller the returned + * number the closer the task has come to overflowing its stack. + * + * @param xTask Handle of the task associated with the stack to be checked. + * Set xTask to NULL to check the stack of the calling task. + * + * @return The smallest amount of free stack space there has been (in words, so + * actual spaces on the stack rather than bytes) since the task referenced by + * xTask was created. + */ +UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/* When using trace macros it is sometimes necessary to include task.h before +FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined, +so the following two prototypes will cause a compilation error. This can be +fixed by simply guarding against the inclusion of these two prototypes unless +they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration +constant. */ +#ifdef configUSE_APPLICATION_TASK_TAG + #if configUSE_APPLICATION_TASK_TAG == 1 + /** + * task.h + *
void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
+ * + * Sets pxHookFunction to be the task hook function used by the task xTask. + * Passing xTask as NULL has the effect of setting the calling tasks hook + * function. + */ + void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION; + + /** + * task.h + *
void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
+ * + * Returns the pxHookFunction value assigned to the task xTask. + */ + TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + #endif /* configUSE_APPLICATION_TASK_TAG ==1 */ +#endif /* ifdef configUSE_APPLICATION_TASK_TAG */ + +#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 ) + + /* Each task contains an array of pointers that is dimensioned by the + configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The + kernel does not use the pointers itself, so the application writer can use + the pointers for any purpose they wish. The following two functions are + used to set and query a pointer respectively. */ + void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) PRIVILEGED_FUNCTION; + void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION; + +#endif + +/** + * task.h + *
BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
+ * + * Calls the hook function associated with xTask. Passing xTask as NULL has + * the effect of calling the Running tasks (the calling task) hook function. + * + * pvParameter is passed to the hook function for the task to interpret as it + * wants. The return value is the value returned by the task hook function + * registered by the user. + */ +BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) PRIVILEGED_FUNCTION; + +/** + * xTaskGetIdleTaskHandle() is only available if + * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h. + * + * Simply returns the handle of the idle task. It is not valid to call + * xTaskGetIdleTaskHandle() before the scheduler has been started. + */ +TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION; + +/** + * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for + * uxTaskGetSystemState() to be available. + * + * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in + * the system. TaskStatus_t structures contain, among other things, members + * for the task handle, task name, task priority, task state, and total amount + * of run time consumed by the task. See the TaskStatus_t structure + * definition in this file for the full member list. + * + * NOTE: This function is intended for debugging use only as its use results in + * the scheduler remaining suspended for an extended period. + * + * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures. + * The array must contain at least one TaskStatus_t structure for each task + * that is under the control of the RTOS. The number of tasks under the control + * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function. + * + * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray + * parameter. The size is specified as the number of indexes in the array, or + * the number of TaskStatus_t structures contained in the array, not by the + * number of bytes in the array. + * + * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in + * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the + * total run time (as defined by the run time stats clock, see + * http://www.freertos.org/rtos-run-time-stats.html) since the target booted. + * pulTotalRunTime can be set to NULL to omit the total run time information. + * + * @return The number of TaskStatus_t structures that were populated by + * uxTaskGetSystemState(). This should equal the number returned by the + * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed + * in the uxArraySize parameter was too small. + * + * Example usage: +
+    // This example demonstrates how a human readable table of run time stats
+    // information is generated from raw data provided by uxTaskGetSystemState().
+    // The human readable table is written to pcWriteBuffer
+    void vTaskGetRunTimeStats( char *pcWriteBuffer )
+    {
+    TaskStatus_t *pxTaskStatusArray;
+    volatile UBaseType_t uxArraySize, x;
+    uint32_t ulTotalRunTime, ulStatsAsPercentage;
+
+        // Make sure the write buffer does not contain a string.
+        *pcWriteBuffer = 0x00;
+
+        // Take a snapshot of the number of tasks in case it changes while this
+        // function is executing.
+        uxArraySize = uxTaskGetNumberOfTasks();
+
+        // Allocate a TaskStatus_t structure for each task.  An array could be
+        // allocated statically at compile time.
+        pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
+
+        if( pxTaskStatusArray != NULL )
+        {
+            // Generate raw status information about each task.
+            uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
+
+            // For percentage calculations.
+            ulTotalRunTime /= 100UL;
+
+            // Avoid divide by zero errors.
+            if( ulTotalRunTime > 0 )
+            {
+                // For each populated position in the pxTaskStatusArray array,
+                // format the raw data as human readable ASCII data
+                for( x = 0; x < uxArraySize; x++ )
+                {
+                    // What percentage of the total run time has the task used?
+                    // This will always be rounded down to the nearest integer.
+                    // ulTotalRunTimeDiv100 has already been divided by 100.
+                    ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
+
+                    if( ulStatsAsPercentage > 0UL )
+                    {
+                        sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
+                    }
+                    else
+                    {
+                        // If the percentage is zero here then the task has
+                        // consumed less than 1% of the total run time.
+                        sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
+                    }
+
+                    pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
+                }
+            }
+
+            // The array is no longer needed, free the memory it consumes.
+            vPortFree( pxTaskStatusArray );
+        }
+    }
+    
+ */ +UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void vTaskList( char *pcWriteBuffer );
+ * + * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must + * both be defined as 1 for this function to be available. See the + * configuration section of the FreeRTOS.org website for more information. + * + * NOTE 1: This function will disable interrupts for its duration. It is + * not intended for normal application runtime use but as a debug aid. + * + * Lists all the current tasks, along with their current state and stack + * usage high water mark. + * + * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or + * suspended ('S'). + * + * PLEASE NOTE: + * + * This function is provided for convenience only, and is used by many of the + * demo applications. Do not consider it to be part of the scheduler. + * + * vTaskList() calls uxTaskGetSystemState(), then formats part of the + * uxTaskGetSystemState() output into a human readable table that displays task + * names, states and stack usage. + * + * vTaskList() has a dependency on the sprintf() C library function that might + * bloat the code size, use a lot of stack, and provide different results on + * different platforms. An alternative, tiny, third party, and limited + * functionality implementation of sprintf() is provided in many of the + * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note + * printf-stdarg.c does not provide a full snprintf() implementation!). + * + * It is recommended that production systems call uxTaskGetSystemState() + * directly to get access to raw stats data, rather than indirectly through a + * call to vTaskList(). + * + * @param pcWriteBuffer A buffer into which the above mentioned details + * will be written, in ASCII form. This buffer is assumed to be large + * enough to contain the generated report. Approximately 40 bytes per + * task should be sufficient. + * + * \defgroup vTaskList vTaskList + * \ingroup TaskUtils + */ +void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + +/** + * task. h + *
void vTaskGetRunTimeStats( char *pcWriteBuffer );
+ * + * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS + * must both be defined as 1 for this function to be available. The application + * must also then provide definitions for + * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE() + * to configure a peripheral timer/counter and return the timers current count + * value respectively. The counter should be at least 10 times the frequency of + * the tick count. + * + * NOTE 1: This function will disable interrupts for its duration. It is + * not intended for normal application runtime use but as a debug aid. + * + * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total + * accumulated execution time being stored for each task. The resolution + * of the accumulated time value depends on the frequency of the timer + * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro. + * Calling vTaskGetRunTimeStats() writes the total execution time of each + * task into a buffer, both as an absolute count value and as a percentage + * of the total system execution time. + * + * NOTE 2: + * + * This function is provided for convenience only, and is used by many of the + * demo applications. Do not consider it to be part of the scheduler. + * + * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the + * uxTaskGetSystemState() output into a human readable table that displays the + * amount of time each task has spent in the Running state in both absolute and + * percentage terms. + * + * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function + * that might bloat the code size, use a lot of stack, and provide different + * results on different platforms. An alternative, tiny, third party, and + * limited functionality implementation of sprintf() is provided in many of the + * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note + * printf-stdarg.c does not provide a full snprintf() implementation!). + * + * It is recommended that production systems call uxTaskGetSystemState() directly + * to get access to raw stats data, rather than indirectly through a call to + * vTaskGetRunTimeStats(). + * + * @param pcWriteBuffer A buffer into which the execution times will be + * written, in ASCII form. This buffer is assumed to be large enough to + * contain the generated report. Approximately 40 bytes per task should + * be sufficient. + * + * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats + * \ingroup TaskUtils + */ +void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + +/** + * task. h + *
BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
+ * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this + * function to be available. + * + * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private + * "notification value", which is a 32-bit unsigned integer (uint32_t). + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment the task's notification value. In that way + * task notifications can be used to send data to a task, or be used as light + * weight and fast binary or counting semaphores. + * + * A notification sent to a task will remain pending until it is cleared by the + * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was + * already in the Blocked state to wait for a notification when the notification + * arrives then the task will automatically be removed from the Blocked state + * (unblocked) and the notification cleared. + * + * A task can use xTaskNotifyWait() to [optionally] block to wait for a + * notification to be pending, or ulTaskNotifyTake() to [optionally] block + * to wait for its notification value to have a non-zero value. The task does + * not consume any CPU time while it is in the Blocked state. + * + * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * @param xTaskToNotify The handle of the task being notified. The handle to a + * task can be returned from the xTaskCreate() API function used to create the + * task, and the handle of the currently running task can be obtained by calling + * xTaskGetCurrentTaskHandle(). + * + * @param ulValue Data that can be sent with the notification. How the data is + * used depends on the value of the eAction parameter. + * + * @param eAction Specifies how the notification updates the task's notification + * value, if at all. Valid values for eAction are as follows: + * + * eSetBits - + * The task's notification value is bitwise ORed with ulValue. xTaskNofify() + * always returns pdPASS in this case. + * + * eIncrement - + * The task's notification value is incremented. ulValue is not used and + * xTaskNotify() always returns pdPASS in this case. + * + * eSetValueWithOverwrite - + * The task's notification value is set to the value of ulValue, even if the + * task being notified had not yet processed the previous notification (the + * task already had a notification pending). xTaskNotify() always returns + * pdPASS in this case. + * + * eSetValueWithoutOverwrite - + * If the task being notified did not already have a notification pending then + * the task's notification value is set to ulValue and xTaskNotify() will + * return pdPASS. If the task being notified already had a notification + * pending then no action is performed and pdFAIL is returned. + * + * eNoAction - + * The task receives a notification without its notification value being + * updated. ulValue is not used and xTaskNotify() always returns pdPASS in + * this case. + * + * pulPreviousNotificationValue - + * Can be used to pass out the subject task's notification value before any + * bits are modified by the notify function. + * + * @return Dependent on the value of eAction. See the description of the + * eAction parameter. + * + * \defgroup xTaskNotify xTaskNotify + * \ingroup TaskNotifications + */ +BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) PRIVILEGED_FUNCTION; +#define xTaskNotify( xTaskToNotify, ulValue, eAction ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL ) +#define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) ) + +/** + * task. h + *
BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
+ * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this + * function to be available. + * + * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private + * "notification value", which is a 32-bit unsigned integer (uint32_t). + * + * A version of xTaskNotify() that can be used from an interrupt service routine + * (ISR). + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment the task's notification value. In that way + * task notifications can be used to send data to a task, or be used as light + * weight and fast binary or counting semaphores. + * + * A notification sent to a task will remain pending until it is cleared by the + * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was + * already in the Blocked state to wait for a notification when the notification + * arrives then the task will automatically be removed from the Blocked state + * (unblocked) and the notification cleared. + * + * A task can use xTaskNotifyWait() to [optionally] block to wait for a + * notification to be pending, or ulTaskNotifyTake() to [optionally] block + * to wait for its notification value to have a non-zero value. The task does + * not consume any CPU time while it is in the Blocked state. + * + * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * @param xTaskToNotify The handle of the task being notified. The handle to a + * task can be returned from the xTaskCreate() API function used to create the + * task, and the handle of the currently running task can be obtained by calling + * xTaskGetCurrentTaskHandle(). + * + * @param ulValue Data that can be sent with the notification. How the data is + * used depends on the value of the eAction parameter. + * + * @param eAction Specifies how the notification updates the task's notification + * value, if at all. Valid values for eAction are as follows: + * + * eSetBits - + * The task's notification value is bitwise ORed with ulValue. xTaskNofify() + * always returns pdPASS in this case. + * + * eIncrement - + * The task's notification value is incremented. ulValue is not used and + * xTaskNotify() always returns pdPASS in this case. + * + * eSetValueWithOverwrite - + * The task's notification value is set to the value of ulValue, even if the + * task being notified had not yet processed the previous notification (the + * task already had a notification pending). xTaskNotify() always returns + * pdPASS in this case. + * + * eSetValueWithoutOverwrite - + * If the task being notified did not already have a notification pending then + * the task's notification value is set to ulValue and xTaskNotify() will + * return pdPASS. If the task being notified already had a notification + * pending then no action is performed and pdFAIL is returned. + * + * eNoAction - + * The task receives a notification without its notification value being + * updated. ulValue is not used and xTaskNotify() always returns pdPASS in + * this case. + * + * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the + * task to which the notification was sent to leave the Blocked state, and the + * unblocked task has a priority higher than the currently running task. If + * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should + * be requested before the interrupt is exited. How a context switch is + * requested from an ISR is dependent on the port - see the documentation page + * for the port in use. + * + * @return Dependent on the value of eAction. See the description of the + * eAction parameter. + * + * \defgroup xTaskNotify xTaskNotify + * \ingroup TaskNotifications + */ +BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; +#define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) ) +#define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) ) + +/** + * task. h + *
BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
+ * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this + * function to be available. + * + * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private + * "notification value", which is a 32-bit unsigned integer (uint32_t). + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment the task's notification value. In that way + * task notifications can be used to send data to a task, or be used as light + * weight and fast binary or counting semaphores. + * + * A notification sent to a task will remain pending until it is cleared by the + * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was + * already in the Blocked state to wait for a notification when the notification + * arrives then the task will automatically be removed from the Blocked state + * (unblocked) and the notification cleared. + * + * A task can use xTaskNotifyWait() to [optionally] block to wait for a + * notification to be pending, or ulTaskNotifyTake() to [optionally] block + * to wait for its notification value to have a non-zero value. The task does + * not consume any CPU time while it is in the Blocked state. + * + * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value + * will be cleared in the calling task's notification value before the task + * checks to see if any notifications are pending, and optionally blocks if no + * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if + * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have + * the effect of resetting the task's notification value to 0. Setting + * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged. + * + * @param ulBitsToClearOnExit If a notification is pending or received before + * the calling task exits the xTaskNotifyWait() function then the task's + * notification value (see the xTaskNotify() API function) is passed out using + * the pulNotificationValue parameter. Then any bits that are set in + * ulBitsToClearOnExit will be cleared in the task's notification value (note + * *pulNotificationValue is set before any bits are cleared). Setting + * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL + * (if limits.h is not included) will have the effect of resetting the task's + * notification value to 0 before the function exits. Setting + * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged + * when the function exits (in which case the value passed out in + * pulNotificationValue will match the task's notification value). + * + * @param pulNotificationValue Used to pass the task's notification value out + * of the function. Note the value passed out will not be effected by the + * clearing of any bits caused by ulBitsToClearOnExit being non-zero. + * + * @param xTicksToWait The maximum amount of time that the task should wait in + * the Blocked state for a notification to be received, should a notification + * not already be pending when xTaskNotifyWait() was called. The task + * will not consume any processing time while it is in the Blocked state. This + * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be + * used to convert a time specified in milliseconds to a time specified in + * ticks. + * + * @return If a notification was received (including notifications that were + * already pending when xTaskNotifyWait was called) then pdPASS is + * returned. Otherwise pdFAIL is returned. + * + * \defgroup xTaskNotifyWait xTaskNotifyWait + * \ingroup TaskNotifications + */ +BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );
+ * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro + * to be available. + * + * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private + * "notification value", which is a 32-bit unsigned integer (uint32_t). + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment the task's notification value. In that way + * task notifications can be used to send data to a task, or be used as light + * weight and fast binary or counting semaphores. + * + * xTaskNotifyGive() is a helper macro intended for use when task notifications + * are used as light weight and faster binary or counting semaphore equivalents. + * Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function, + * the equivalent action that instead uses a task notification is + * xTaskNotifyGive(). + * + * When task notifications are being used as a binary or counting semaphore + * equivalent then the task being notified should wait for the notification + * using the ulTaskNotificationTake() API function rather than the + * xTaskNotifyWait() API function. + * + * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details. + * + * @param xTaskToNotify The handle of the task being notified. The handle to a + * task can be returned from the xTaskCreate() API function used to create the + * task, and the handle of the currently running task can be obtained by calling + * xTaskGetCurrentTaskHandle(). + * + * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the + * eAction parameter set to eIncrement - so pdPASS is always returned. + * + * \defgroup xTaskNotifyGive xTaskNotifyGive + * \ingroup TaskNotifications + */ +#define xTaskNotifyGive( xTaskToNotify ) xTaskGenericNotify( ( xTaskToNotify ), ( 0 ), eIncrement, NULL ) + +/** + * task. h + *
void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
+ *
+ * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
+ * to be available.
+ *
+ * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
+ * "notification value", which is a 32-bit unsigned integer (uint32_t).
+ *
+ * A version of xTaskNotifyGive() that can be called from an interrupt service
+ * routine (ISR).
+ *
+ * Events can be sent to a task using an intermediary object.  Examples of such
+ * objects are queues, semaphores, mutexes and event groups.  Task notifications
+ * are a method of sending an event directly to a task without the need for such
+ * an intermediary object.
+ *
+ * A notification sent to a task can optionally perform an action, such as
+ * update, overwrite or increment the task's notification value.  In that way
+ * task notifications can be used to send data to a task, or be used as light
+ * weight and fast binary or counting semaphores.
+ *
+ * vTaskNotifyGiveFromISR() is intended for use when task notifications are
+ * used as light weight and faster binary or counting semaphore equivalents.
+ * Actual FreeRTOS semaphores are given from an ISR using the
+ * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
+ * a task notification is vTaskNotifyGiveFromISR().
+ *
+ * When task notifications are being used as a binary or counting semaphore
+ * equivalent then the task being notified should wait for the notification
+ * using the ulTaskNotificationTake() API function rather than the
+ * xTaskNotifyWait() API function.
+ *
+ * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
+ *
+ * @param xTaskToNotify The handle of the task being notified.  The handle to a
+ * task can be returned from the xTaskCreate() API function used to create the
+ * task, and the handle of the currently running task can be obtained by calling
+ * xTaskGetCurrentTaskHandle().
+ *
+ * @param pxHigherPriorityTaskWoken  vTaskNotifyGiveFromISR() will set
+ * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
+ * task to which the notification was sent to leave the Blocked state, and the
+ * unblocked task has a priority higher than the currently running task.  If
+ * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
+ * should be requested before the interrupt is exited.  How a context switch is
+ * requested from an ISR is dependent on the port - see the documentation page
+ * for the port in use.
+ *
+ * \defgroup xTaskNotifyWait xTaskNotifyWait
+ * \ingroup TaskNotifications
+ */
+void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
+
+/**
+ * task. h
+ * 
uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
+ * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this + * function to be available. + * + * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private + * "notification value", which is a 32-bit unsigned integer (uint32_t). + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment the task's notification value. In that way + * task notifications can be used to send data to a task, or be used as light + * weight and fast binary or counting semaphores. + * + * ulTaskNotifyTake() is intended for use when a task notification is used as a + * faster and lighter weight binary or counting semaphore alternative. Actual + * FreeRTOS semaphores are taken using the xSemaphoreTake() API function, the + * equivalent action that instead uses a task notification is + * ulTaskNotifyTake(). + * + * When a task is using its notification value as a binary or counting semaphore + * other tasks should send notifications to it using the xTaskNotifyGive() + * macro, or xTaskNotify() function with the eAction parameter set to + * eIncrement. + * + * ulTaskNotifyTake() can either clear the task's notification value to + * zero on exit, in which case the notification value acts like a binary + * semaphore, or decrement the task's notification value on exit, in which case + * the notification value acts like a counting semaphore. + * + * A task can use ulTaskNotifyTake() to [optionally] block to wait for a + * the task's notification value to be non-zero. The task does not consume any + * CPU time while it is in the Blocked state. + * + * Where as xTaskNotifyWait() will return when a notification is pending, + * ulTaskNotifyTake() will return when the task's notification value is + * not zero. + * + * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's + * notification value is decremented when the function exits. In this way the + * notification value acts like a counting semaphore. If xClearCountOnExit is + * not pdFALSE then the task's notification value is cleared to zero when the + * function exits. In this way the notification value acts like a binary + * semaphore. + * + * @param xTicksToWait The maximum amount of time that the task should wait in + * the Blocked state for the task's notification value to be greater than zero, + * should the count not already be greater than zero when + * ulTaskNotifyTake() was called. The task will not consume any processing + * time while it is in the Blocked state. This is specified in kernel ticks, + * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time + * specified in milliseconds to a time specified in ticks. + * + * @return The task's notification count before it is either cleared to zero or + * decremented (see the xClearCountOnExit parameter). + * + * \defgroup ulTaskNotifyTake ulTaskNotifyTake + * \ingroup TaskNotifications + */ +uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
+ * + * If the notification state of the task referenced by the handle xTask is + * eNotified, then set the task's notification state to eNotWaitingNotification. + * The task's notification value is not altered. Set xTask to NULL to clear the + * notification state of the calling task. + * + * @return pdTRUE if the task's notification state was set to + * eNotWaitingNotification, otherwise pdFALSE. + * \defgroup xTaskNotifyStateClear xTaskNotifyStateClear + * \ingroup TaskNotifications + */ +BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask ); + +/*----------------------------------------------------------- + * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES + *----------------------------------------------------------*/ + +/* + * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY + * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS + * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. + * + * Called from the real time kernel tick (either preemptive or cooperative), + * this increments the tick count and checks if any tasks that are blocked + * for a finite period required removing from a blocked list and placing on + * a ready list. If a non-zero value is returned then a context switch is + * required because either: + * + A task was removed from a blocked list because its timeout had expired, + * or + * + Time slicing is in use and there is a task of equal priority to the + * currently running task. + */ +BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION; + +/* + * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN + * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. + * + * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. + * + * Removes the calling task from the ready list and places it both + * on the list of tasks waiting for a particular event, and the + * list of delayed tasks. The task will be removed from both lists + * and replaced on the ready list should either the event occur (and + * there be no higher priority tasks waiting on the same event) or + * the delay period expires. + * + * The 'unordered' version replaces the event list item value with the + * xItemValue value, and inserts the list item at the end of the list. + * + * The 'ordered' version uses the existing event list item value (which is the + * owning tasks priority) to insert the list item into the event list is task + * priority order. + * + * @param pxEventList The list containing tasks that are blocked waiting + * for the event to occur. + * + * @param xItemValue The item value to use for the event list item when the + * event list is not ordered by task priority. + * + * @param xTicksToWait The maximum amount of time that the task should wait + * for the event to occur. This is specified in kernel ticks,the constant + * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time + * period. + */ +void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; +void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/* + * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN + * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. + * + * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. + * + * This function performs nearly the same function as vTaskPlaceOnEventList(). + * The difference being that this function does not permit tasks to block + * indefinitely, whereas vTaskPlaceOnEventList() does. + * + */ +void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION; + +/* + * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN + * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. + * + * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. + * + * Removes a task from both the specified event list and the list of blocked + * tasks, and places it on a ready queue. + * + * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called + * if either an event occurs to unblock a task, or the block timeout period + * expires. + * + * xTaskRemoveFromEventList() is used when the event list is in task priority + * order. It removes the list item from the head of the event list as that will + * have the highest priority owning task of all the tasks on the event list. + * vTaskRemoveFromUnorderedEventList() is used when the event list is not + * ordered and the event list items hold something other than the owning tasks + * priority. In this case the event list item value is updated to the value + * passed in the xItemValue parameter. + * + * @return pdTRUE if the task being removed has a higher priority than the task + * making the call, otherwise pdFALSE. + */ +BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION; +void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) PRIVILEGED_FUNCTION; + +/* + * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY + * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS + * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. + * + * Sets the pointer to the current TCB to the TCB of the highest priority task + * that is ready to run. + */ +void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION; + +/* + * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY + * THE EVENT BITS MODULE. + */ +TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION; + +/* + * Return the handle of the calling task. + */ +TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION; + +/* + * Capture the current time status for future reference. + */ +void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION; + +/* + * Compare the time status now with that previously captured to see if the + * timeout has expired. + */ +BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION; + +/* + * Shortcut used by the queue implementation to prevent unnecessary call to + * taskYIELD(); + */ +void vTaskMissedYield( void ) PRIVILEGED_FUNCTION; + +/* + * Returns the scheduler state as taskSCHEDULER_RUNNING, + * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED. + */ +BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION; + +/* + * Raises the priority of the mutex holder to that of the calling task should + * the mutex holder have a priority less than the calling task. + */ +BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION; + +/* + * Set the priority of a task back to its proper priority in the case that it + * inherited a higher priority while it was holding a semaphore. + */ +BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION; + +/* + * If a higher priority task attempting to obtain a mutex caused a lower + * priority task to inherit the higher priority task's priority - but the higher + * priority task then timed out without obtaining the mutex, then the lower + * priority task will disinherit the priority again - but only down as far as + * the highest priority task that is still waiting for the mutex (if there were + * more than one task waiting for the mutex). + */ +void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION; + +/* + * Get the uxTCBNumber assigned to the task referenced by the xTask parameter. + */ +UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/* + * Set the uxTaskNumber of the task referenced by the xTask parameter to + * uxHandle. + */ +void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION; + +/* + * Only available when configUSE_TICKLESS_IDLE is set to 1. + * If tickless mode is being used, or a low power mode is implemented, then + * the tick interrupt will not execute during idle periods. When this is the + * case, the tick count value maintained by the scheduler needs to be kept up + * to date with the actual execution time by being skipped forward by a time + * equal to the idle period. + */ +void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION; + +/* + * Only avilable when configUSE_TICKLESS_IDLE is set to 1. + * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port + * specific sleep function to determine if it is ok to proceed with the sleep, + * and if it is ok to proceed, if it is ok to sleep indefinitely. + * + * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only + * called with the scheduler suspended, not from within a critical section. It + * is therefore possible for an interrupt to request a context switch between + * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being + * entered. eTaskConfirmSleepModeStatus() should be called from a short + * critical section between the timer being stopped and the sleep mode being + * entered to ensure it is ok to proceed into the sleep mode. + */ +eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION; + +/* + * For internal use only. Increment the mutex held count when a mutex is + * taken and return the handle of the task that has taken the mutex. + */ +void *pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION; + +/* + * For internal use only. Same as vTaskSetTimeOutState(), but without a critial + * section. + */ +void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION; + + +#ifdef __cplusplus +} +#endif +#endif /* INC_TASK_H */ + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/timers.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/timers.h new file mode 100644 index 0000000..7995ab9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/include/timers.h @@ -0,0 +1,1277 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + + +#ifndef TIMERS_H +#define TIMERS_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h must appear in source files before include timers.h" +#endif + +/*lint -save -e537 This headers are only multiply included if the application code +happens to also be including task.h. */ +#include "task.h" +/*lint -restore */ + +#ifdef __cplusplus +extern "C" { +#endif + +/*----------------------------------------------------------- + * MACROS AND DEFINITIONS + *----------------------------------------------------------*/ + +/* IDs for commands that can be sent/received on the timer queue. These are to +be used solely through the macros that make up the public software timer API, +as defined below. The commands that are sent from interrupts must use the +highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task +or interrupt version of the queue send function should be used. */ +#define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 ) +#define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 ) +#define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 ) +#define tmrCOMMAND_START ( ( BaseType_t ) 1 ) +#define tmrCOMMAND_RESET ( ( BaseType_t ) 2 ) +#define tmrCOMMAND_STOP ( ( BaseType_t ) 3 ) +#define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 ) +#define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 ) + +#define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 ) +#define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 ) +#define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 ) +#define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 ) +#define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 ) + + +/** + * Type by which software timers are referenced. For example, a call to + * xTimerCreate() returns an TimerHandle_t variable that can then be used to + * reference the subject timer in calls to other software timer API functions + * (for example, xTimerStart(), xTimerReset(), etc.). + */ +typedef void * TimerHandle_t; + +/* + * Defines the prototype to which timer callback functions must conform. + */ +typedef void (*TimerCallbackFunction_t)( TimerHandle_t xTimer ); + +/* + * Defines the prototype to which functions used with the + * xTimerPendFunctionCallFromISR() function must conform. + */ +typedef void (*PendedFunction_t)( void *, uint32_t ); + +/** + * TimerHandle_t xTimerCreate( const char * const pcTimerName, + * TickType_t xTimerPeriodInTicks, + * UBaseType_t uxAutoReload, + * void * pvTimerID, + * TimerCallbackFunction_t pxCallbackFunction ); + * + * Creates a new software timer instance, and returns a handle by which the + * created software timer can be referenced. + * + * Internally, within the FreeRTOS implementation, software timers use a block + * of memory, in which the timer data structure is stored. If a software timer + * is created using xTimerCreate() then the required memory is automatically + * dynamically allocated inside the xTimerCreate() function. (see + * http://www.freertos.org/a00111.html). If a software timer is created using + * xTimerCreateStatic() then the application writer must provide the memory that + * will get used by the software timer. xTimerCreateStatic() therefore allows a + * software timer to be created without using any dynamic memory allocation. + * + * Timers are created in the dormant state. The xTimerStart(), xTimerReset(), + * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and + * xTimerChangePeriodFromISR() API functions can all be used to transition a + * timer into the active state. + * + * @param pcTimerName A text name that is assigned to the timer. This is done + * purely to assist debugging. The kernel itself only ever references a timer + * by its handle, and never by its name. + * + * @param xTimerPeriodInTicks The timer period. The time is defined in tick + * periods so the constant portTICK_PERIOD_MS can be used to convert a time that + * has been specified in milliseconds. For example, if the timer must expire + * after 100 ticks, then xTimerPeriodInTicks should be set to 100. + * Alternatively, if the timer must expire after 500ms, then xPeriod can be set + * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or + * equal to 1000. + * + * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will + * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter. + * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and + * enter the dormant state after it expires. + * + * @param pvTimerID An identifier that is assigned to the timer being created. + * Typically this would be used in the timer callback function to identify which + * timer expired when the same callback function is assigned to more than one + * timer. + * + * @param pxCallbackFunction The function to call when the timer expires. + * Callback functions must have the prototype defined by TimerCallbackFunction_t, + * which is "void vCallbackFunction( TimerHandle_t xTimer );". + * + * @return If the timer is successfully created then a handle to the newly + * created timer is returned. If the timer cannot be created (because either + * there is insufficient FreeRTOS heap remaining to allocate the timer + * structures, or the timer period was set to 0) then NULL is returned. + * + * Example usage: + * @verbatim + * #define NUM_TIMERS 5 + * + * // An array to hold handles to the created timers. + * TimerHandle_t xTimers[ NUM_TIMERS ]; + * + * // An array to hold a count of the number of times each timer expires. + * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 }; + * + * // Define a callback function that will be used by multiple timer instances. + * // The callback function does nothing but count the number of times the + * // associated timer expires, and stop the timer once the timer has expired + * // 10 times. + * void vTimerCallback( TimerHandle_t pxTimer ) + * { + * int32_t lArrayIndex; + * const int32_t xMaxExpiryCountBeforeStopping = 10; + * + * // Optionally do something if the pxTimer parameter is NULL. + * configASSERT( pxTimer ); + * + * // Which timer expired? + * lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer ); + * + * // Increment the number of times that pxTimer has expired. + * lExpireCounters[ lArrayIndex ] += 1; + * + * // If the timer has expired 10 times then stop it from running. + * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping ) + * { + * // Do not use a block time if calling a timer API function from a + * // timer callback function, as doing so could cause a deadlock! + * xTimerStop( pxTimer, 0 ); + * } + * } + * + * void main( void ) + * { + * int32_t x; + * + * // Create then start some timers. Starting the timers before the scheduler + * // has been started means the timers will start running immediately that + * // the scheduler starts. + * for( x = 0; x < NUM_TIMERS; x++ ) + * { + * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel. + * ( 100 * x ), // The timer period in ticks. + * pdTRUE, // The timers will auto-reload themselves when they expire. + * ( void * ) x, // Assign each timer a unique id equal to its array index. + * vTimerCallback // Each timer calls the same callback when it expires. + * ); + * + * if( xTimers[ x ] == NULL ) + * { + * // The timer was not created. + * } + * else + * { + * // Start the timer. No block time is specified, and even if one was + * // it would be ignored because the scheduler has not yet been + * // started. + * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS ) + * { + * // The timer could not be set into the Active state. + * } + * } + * } + * + * // ... + * // Create tasks here. + * // ... + * + * // Starting the scheduler will start the timers running as they have already + * // been set into the active state. + * vTaskStartScheduler(); + * + * // Should not reach here. + * for( ;; ); + * } + * @endverbatim + */ +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction ) PRIVILEGED_FUNCTION; +#endif + +/** + * TimerHandle_t xTimerCreateStatic(const char * const pcTimerName, + * TickType_t xTimerPeriodInTicks, + * UBaseType_t uxAutoReload, + * void * pvTimerID, + * TimerCallbackFunction_t pxCallbackFunction, + * StaticTimer_t *pxTimerBuffer ); + * + * Creates a new software timer instance, and returns a handle by which the + * created software timer can be referenced. + * + * Internally, within the FreeRTOS implementation, software timers use a block + * of memory, in which the timer data structure is stored. If a software timer + * is created using xTimerCreate() then the required memory is automatically + * dynamically allocated inside the xTimerCreate() function. (see + * http://www.freertos.org/a00111.html). If a software timer is created using + * xTimerCreateStatic() then the application writer must provide the memory that + * will get used by the software timer. xTimerCreateStatic() therefore allows a + * software timer to be created without using any dynamic memory allocation. + * + * Timers are created in the dormant state. The xTimerStart(), xTimerReset(), + * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and + * xTimerChangePeriodFromISR() API functions can all be used to transition a + * timer into the active state. + * + * @param pcTimerName A text name that is assigned to the timer. This is done + * purely to assist debugging. The kernel itself only ever references a timer + * by its handle, and never by its name. + * + * @param xTimerPeriodInTicks The timer period. The time is defined in tick + * periods so the constant portTICK_PERIOD_MS can be used to convert a time that + * has been specified in milliseconds. For example, if the timer must expire + * after 100 ticks, then xTimerPeriodInTicks should be set to 100. + * Alternatively, if the timer must expire after 500ms, then xPeriod can be set + * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or + * equal to 1000. + * + * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will + * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter. + * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and + * enter the dormant state after it expires. + * + * @param pvTimerID An identifier that is assigned to the timer being created. + * Typically this would be used in the timer callback function to identify which + * timer expired when the same callback function is assigned to more than one + * timer. + * + * @param pxCallbackFunction The function to call when the timer expires. + * Callback functions must have the prototype defined by TimerCallbackFunction_t, + * which is "void vCallbackFunction( TimerHandle_t xTimer );". + * + * @param pxTimerBuffer Must point to a variable of type StaticTimer_t, which + * will be then be used to hold the software timer's data structures, removing + * the need for the memory to be allocated dynamically. + * + * @return If the timer is created then a handle to the created timer is + * returned. If pxTimerBuffer was NULL then NULL is returned. + * + * Example usage: + * @verbatim + * + * // The buffer used to hold the software timer's data structure. + * static StaticTimer_t xTimerBuffer; + * + * // A variable that will be incremented by the software timer's callback + * // function. + * UBaseType_t uxVariableToIncrement = 0; + * + * // A software timer callback function that increments a variable passed to + * // it when the software timer was created. After the 5th increment the + * // callback function stops the software timer. + * static void prvTimerCallback( TimerHandle_t xExpiredTimer ) + * { + * UBaseType_t *puxVariableToIncrement; + * BaseType_t xReturned; + * + * // Obtain the address of the variable to increment from the timer ID. + * puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer ); + * + * // Increment the variable to show the timer callback has executed. + * ( *puxVariableToIncrement )++; + * + * // If this callback has executed the required number of times, stop the + * // timer. + * if( *puxVariableToIncrement == 5 ) + * { + * // This is called from a timer callback so must not block. + * xTimerStop( xExpiredTimer, staticDONT_BLOCK ); + * } + * } + * + * + * void main( void ) + * { + * // Create the software time. xTimerCreateStatic() has an extra parameter + * // than the normal xTimerCreate() API function. The parameter is a pointer + * // to the StaticTimer_t structure that will hold the software timer + * // structure. If the parameter is passed as NULL then the structure will be + * // allocated dynamically, just as if xTimerCreate() had been called. + * xTimer = xTimerCreateStatic( "T1", // Text name for the task. Helps debugging only. Not used by FreeRTOS. + * xTimerPeriod, // The period of the timer in ticks. + * pdTRUE, // This is an auto-reload timer. + * ( void * ) &uxVariableToIncrement, // A variable incremented by the software timer's callback function + * prvTimerCallback, // The function to execute when the timer expires. + * &xTimerBuffer ); // The buffer that will hold the software timer structure. + * + * // The scheduler has not started yet so a block time is not used. + * xReturned = xTimerStart( xTimer, 0 ); + * + * // ... + * // Create tasks here. + * // ... + * + * // Starting the scheduler will start the timers running as they have already + * // been set into the active state. + * vTaskStartScheduler(); + * + * // Should not reach here. + * for( ;; ); + * } + * @endverbatim + */ +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction, + StaticTimer_t *pxTimerBuffer ) PRIVILEGED_FUNCTION; +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * void *pvTimerGetTimerID( TimerHandle_t xTimer ); + * + * Returns the ID assigned to the timer. + * + * IDs are assigned to timers using the pvTimerID parameter of the call to + * xTimerCreated() that was used to create the timer, and by calling the + * vTimerSetTimerID() API function. + * + * If the same callback function is assigned to multiple timers then the timer + * ID can be used as time specific (timer local) storage. + * + * @param xTimer The timer being queried. + * + * @return The ID assigned to the timer being queried. + * + * Example usage: + * + * See the xTimerCreate() API function example usage scenario. + */ +void *pvTimerGetTimerID( const TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; + +/** + * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ); + * + * Sets the ID assigned to the timer. + * + * IDs are assigned to timers using the pvTimerID parameter of the call to + * xTimerCreated() that was used to create the timer. + * + * If the same callback function is assigned to multiple timers then the timer + * ID can be used as time specific (timer local) storage. + * + * @param xTimer The timer being updated. + * + * @param pvNewID The ID to assign to the timer. + * + * Example usage: + * + * See the xTimerCreate() API function example usage scenario. + */ +void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ) PRIVILEGED_FUNCTION; + +/** + * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ); + * + * Queries a timer to see if it is active or dormant. + * + * A timer will be dormant if: + * 1) It has been created but not started, or + * 2) It is an expired one-shot timer that has not been restarted. + * + * Timers are created in the dormant state. The xTimerStart(), xTimerReset(), + * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and + * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the + * active state. + * + * @param xTimer The timer being queried. + * + * @return pdFALSE will be returned if the timer is dormant. A value other than + * pdFALSE will be returned if the timer is active. + * + * Example usage: + * @verbatim + * // This function assumes xTimer has already been created. + * void vAFunction( TimerHandle_t xTimer ) + * { + * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )" + * { + * // xTimer is active, do something. + * } + * else + * { + * // xTimer is not active, do something else. + * } + * } + * @endverbatim + */ +BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; + +/** + * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ); + * + * Simply returns the handle of the timer service/daemon task. It it not valid + * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started. + */ +TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) PRIVILEGED_FUNCTION; + +/** + * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait ); + * + * Timer functionality is provided by a timer service/daemon task. Many of the + * public FreeRTOS timer API functions send commands to the timer service task + * through a queue called the timer command queue. The timer command queue is + * private to the kernel itself and is not directly accessible to application + * code. The length of the timer command queue is set by the + * configTIMER_QUEUE_LENGTH configuration constant. + * + * xTimerStart() starts a timer that was previously created using the + * xTimerCreate() API function. If the timer had already been started and was + * already in the active state, then xTimerStart() has equivalent functionality + * to the xTimerReset() API function. + * + * Starting a timer ensures the timer is in the active state. If the timer + * is not stopped, deleted, or reset in the mean time, the callback function + * associated with the timer will get called 'n' ticks after xTimerStart() was + * called, where 'n' is the timers defined period. + * + * It is valid to call xTimerStart() before the scheduler has been started, but + * when this is done the timer will not actually start until the scheduler is + * started, and the timers expiry time will be relative to when the scheduler is + * started, not relative to when xTimerStart() was called. + * + * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart() + * to be available. + * + * @param xTimer The handle of the timer being started/restarted. + * + * @param xTicksToWait Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the start command to be successfully + * sent to the timer command queue, should the queue already be full when + * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called + * before the scheduler is started. + * + * @return pdFAIL will be returned if the start command could not be sent to + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will + * be returned if the command was successfully sent to the timer command queue. + * When the command is actually processed will depend on the priority of the + * timer service/daemon task relative to other tasks in the system, although the + * timers expiry time is relative to when xTimerStart() is actually called. The + * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY + * configuration constant. + * + * Example usage: + * + * See the xTimerCreate() API function example usage scenario. + * + */ +#define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) ) + +/** + * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait ); + * + * Timer functionality is provided by a timer service/daemon task. Many of the + * public FreeRTOS timer API functions send commands to the timer service task + * through a queue called the timer command queue. The timer command queue is + * private to the kernel itself and is not directly accessible to application + * code. The length of the timer command queue is set by the + * configTIMER_QUEUE_LENGTH configuration constant. + * + * xTimerStop() stops a timer that was previously started using either of the + * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(), + * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions. + * + * Stopping a timer ensures the timer is not in the active state. + * + * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop() + * to be available. + * + * @param xTimer The handle of the timer being stopped. + * + * @param xTicksToWait Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the stop command to be successfully + * sent to the timer command queue, should the queue already be full when + * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called + * before the scheduler is started. + * + * @return pdFAIL will be returned if the stop command could not be sent to + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will + * be returned if the command was successfully sent to the timer command queue. + * When the command is actually processed will depend on the priority of the + * timer service/daemon task relative to other tasks in the system. The timer + * service/daemon task priority is set by the configTIMER_TASK_PRIORITY + * configuration constant. + * + * Example usage: + * + * See the xTimerCreate() API function example usage scenario. + * + */ +#define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) ) + +/** + * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer, + * TickType_t xNewPeriod, + * TickType_t xTicksToWait ); + * + * Timer functionality is provided by a timer service/daemon task. Many of the + * public FreeRTOS timer API functions send commands to the timer service task + * through a queue called the timer command queue. The timer command queue is + * private to the kernel itself and is not directly accessible to application + * code. The length of the timer command queue is set by the + * configTIMER_QUEUE_LENGTH configuration constant. + * + * xTimerChangePeriod() changes the period of a timer that was previously + * created using the xTimerCreate() API function. + * + * xTimerChangePeriod() can be called to change the period of an active or + * dormant state timer. + * + * The configUSE_TIMERS configuration constant must be set to 1 for + * xTimerChangePeriod() to be available. + * + * @param xTimer The handle of the timer that is having its period changed. + * + * @param xNewPeriod The new period for xTimer. Timer periods are specified in + * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time + * that has been specified in milliseconds. For example, if the timer must + * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively, + * if the timer must expire after 500ms, then xNewPeriod can be set to + * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than + * or equal to 1000. + * + * @param xTicksToWait Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the change period command to be + * successfully sent to the timer command queue, should the queue already be + * full when xTimerChangePeriod() was called. xTicksToWait is ignored if + * xTimerChangePeriod() is called before the scheduler is started. + * + * @return pdFAIL will be returned if the change period command could not be + * sent to the timer command queue even after xTicksToWait ticks had passed. + * pdPASS will be returned if the command was successfully sent to the timer + * command queue. When the command is actually processed will depend on the + * priority of the timer service/daemon task relative to other tasks in the + * system. The timer service/daemon task priority is set by the + * configTIMER_TASK_PRIORITY configuration constant. + * + * Example usage: + * @verbatim + * // This function assumes xTimer has already been created. If the timer + * // referenced by xTimer is already active when it is called, then the timer + * // is deleted. If the timer referenced by xTimer is not active when it is + * // called, then the period of the timer is set to 500ms and the timer is + * // started. + * void vAFunction( TimerHandle_t xTimer ) + * { + * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )" + * { + * // xTimer is already active - delete it. + * xTimerDelete( xTimer ); + * } + * else + * { + * // xTimer is not active, change its period to 500ms. This will also + * // cause the timer to start. Block for a maximum of 100 ticks if the + * // change period command cannot immediately be sent to the timer + * // command queue. + * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS ) + * { + * // The command was successfully sent. + * } + * else + * { + * // The command could not be sent, even after waiting for 100 ticks + * // to pass. Take appropriate action here. + * } + * } + * } + * @endverbatim + */ + #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) ) + +/** + * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait ); + * + * Timer functionality is provided by a timer service/daemon task. Many of the + * public FreeRTOS timer API functions send commands to the timer service task + * through a queue called the timer command queue. The timer command queue is + * private to the kernel itself and is not directly accessible to application + * code. The length of the timer command queue is set by the + * configTIMER_QUEUE_LENGTH configuration constant. + * + * xTimerDelete() deletes a timer that was previously created using the + * xTimerCreate() API function. + * + * The configUSE_TIMERS configuration constant must be set to 1 for + * xTimerDelete() to be available. + * + * @param xTimer The handle of the timer being deleted. + * + * @param xTicksToWait Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the delete command to be + * successfully sent to the timer command queue, should the queue already be + * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete() + * is called before the scheduler is started. + * + * @return pdFAIL will be returned if the delete command could not be sent to + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will + * be returned if the command was successfully sent to the timer command queue. + * When the command is actually processed will depend on the priority of the + * timer service/daemon task relative to other tasks in the system. The timer + * service/daemon task priority is set by the configTIMER_TASK_PRIORITY + * configuration constant. + * + * Example usage: + * + * See the xTimerChangePeriod() API function example usage scenario. + */ +#define xTimerDelete( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) ) + +/** + * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait ); + * + * Timer functionality is provided by a timer service/daemon task. Many of the + * public FreeRTOS timer API functions send commands to the timer service task + * through a queue called the timer command queue. The timer command queue is + * private to the kernel itself and is not directly accessible to application + * code. The length of the timer command queue is set by the + * configTIMER_QUEUE_LENGTH configuration constant. + * + * xTimerReset() re-starts a timer that was previously created using the + * xTimerCreate() API function. If the timer had already been started and was + * already in the active state, then xTimerReset() will cause the timer to + * re-evaluate its expiry time so that it is relative to when xTimerReset() was + * called. If the timer was in the dormant state then xTimerReset() has + * equivalent functionality to the xTimerStart() API function. + * + * Resetting a timer ensures the timer is in the active state. If the timer + * is not stopped, deleted, or reset in the mean time, the callback function + * associated with the timer will get called 'n' ticks after xTimerReset() was + * called, where 'n' is the timers defined period. + * + * It is valid to call xTimerReset() before the scheduler has been started, but + * when this is done the timer will not actually start until the scheduler is + * started, and the timers expiry time will be relative to when the scheduler is + * started, not relative to when xTimerReset() was called. + * + * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset() + * to be available. + * + * @param xTimer The handle of the timer being reset/started/restarted. + * + * @param xTicksToWait Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the reset command to be successfully + * sent to the timer command queue, should the queue already be full when + * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called + * before the scheduler is started. + * + * @return pdFAIL will be returned if the reset command could not be sent to + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will + * be returned if the command was successfully sent to the timer command queue. + * When the command is actually processed will depend on the priority of the + * timer service/daemon task relative to other tasks in the system, although the + * timers expiry time is relative to when xTimerStart() is actually called. The + * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY + * configuration constant. + * + * Example usage: + * @verbatim + * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass + * // without a key being pressed, then the LCD back-light is switched off. In + * // this case, the timer is a one-shot timer. + * + * TimerHandle_t xBacklightTimer = NULL; + * + * // The callback function assigned to the one-shot timer. In this case the + * // parameter is not used. + * void vBacklightTimerCallback( TimerHandle_t pxTimer ) + * { + * // The timer expired, therefore 5 seconds must have passed since a key + * // was pressed. Switch off the LCD back-light. + * vSetBacklightState( BACKLIGHT_OFF ); + * } + * + * // The key press event handler. + * void vKeyPressEventHandler( char cKey ) + * { + * // Ensure the LCD back-light is on, then reset the timer that is + * // responsible for turning the back-light off after 5 seconds of + * // key inactivity. Wait 10 ticks for the command to be successfully sent + * // if it cannot be sent immediately. + * vSetBacklightState( BACKLIGHT_ON ); + * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS ) + * { + * // The reset command was not executed successfully. Take appropriate + * // action here. + * } + * + * // Perform the rest of the key processing here. + * } + * + * void main( void ) + * { + * int32_t x; + * + * // Create then start the one-shot timer that is responsible for turning + * // the back-light off if no keys are pressed within a 5 second period. + * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel. + * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks. + * pdFALSE, // The timer is a one-shot timer. + * 0, // The id is not used by the callback so can take any value. + * vBacklightTimerCallback // The callback function that switches the LCD back-light off. + * ); + * + * if( xBacklightTimer == NULL ) + * { + * // The timer was not created. + * } + * else + * { + * // Start the timer. No block time is specified, and even if one was + * // it would be ignored because the scheduler has not yet been + * // started. + * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS ) + * { + * // The timer could not be set into the Active state. + * } + * } + * + * // ... + * // Create tasks here. + * // ... + * + * // Starting the scheduler will start the timer running as it has already + * // been set into the active state. + * vTaskStartScheduler(); + * + * // Should not reach here. + * for( ;; ); + * } + * @endverbatim + */ +#define xTimerReset( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) ) + +/** + * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer, + * BaseType_t *pxHigherPriorityTaskWoken ); + * + * A version of xTimerStart() that can be called from an interrupt service + * routine. + * + * @param xTimer The handle of the timer being started/restarted. + * + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most + * of its time in the Blocked state, waiting for messages to arrive on the timer + * command queue. Calling xTimerStartFromISR() writes a message to the timer + * command queue, so has the potential to transition the timer service/daemon + * task out of the Blocked state. If calling xTimerStartFromISR() causes the + * timer service/daemon task to leave the Blocked state, and the timer service/ + * daemon task has a priority equal to or greater than the currently executing + * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will + * get set to pdTRUE internally within the xTimerStartFromISR() function. If + * xTimerStartFromISR() sets this value to pdTRUE then a context switch should + * be performed before the interrupt exits. + * + * @return pdFAIL will be returned if the start command could not be sent to + * the timer command queue. pdPASS will be returned if the command was + * successfully sent to the timer command queue. When the command is actually + * processed will depend on the priority of the timer service/daemon task + * relative to other tasks in the system, although the timers expiry time is + * relative to when xTimerStartFromISR() is actually called. The timer + * service/daemon task priority is set by the configTIMER_TASK_PRIORITY + * configuration constant. + * + * Example usage: + * @verbatim + * // This scenario assumes xBacklightTimer has already been created. When a + * // key is pressed, an LCD back-light is switched on. If 5 seconds pass + * // without a key being pressed, then the LCD back-light is switched off. In + * // this case, the timer is a one-shot timer, and unlike the example given for + * // the xTimerReset() function, the key press event handler is an interrupt + * // service routine. + * + * // The callback function assigned to the one-shot timer. In this case the + * // parameter is not used. + * void vBacklightTimerCallback( TimerHandle_t pxTimer ) + * { + * // The timer expired, therefore 5 seconds must have passed since a key + * // was pressed. Switch off the LCD back-light. + * vSetBacklightState( BACKLIGHT_OFF ); + * } + * + * // The key press interrupt service routine. + * void vKeyPressEventInterruptHandler( void ) + * { + * BaseType_t xHigherPriorityTaskWoken = pdFALSE; + * + * // Ensure the LCD back-light is on, then restart the timer that is + * // responsible for turning the back-light off after 5 seconds of + * // key inactivity. This is an interrupt service routine so can only + * // call FreeRTOS API functions that end in "FromISR". + * vSetBacklightState( BACKLIGHT_ON ); + * + * // xTimerStartFromISR() or xTimerResetFromISR() could be called here + * // as both cause the timer to re-calculate its expiry time. + * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was + * // declared (in this function). + * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS ) + * { + * // The start command was not executed successfully. Take appropriate + * // action here. + * } + * + * // Perform the rest of the key processing here. + * + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch + * // should be performed. The syntax required to perform a context switch + * // from inside an ISR varies from port to port, and from compiler to + * // compiler. Inspect the demos for the port you are using to find the + * // actual syntax required. + * if( xHigherPriorityTaskWoken != pdFALSE ) + * { + * // Call the interrupt safe yield function here (actual function + * // depends on the FreeRTOS port being used). + * } + * } + * @endverbatim + */ +#define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U ) + +/** + * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer, + * BaseType_t *pxHigherPriorityTaskWoken ); + * + * A version of xTimerStop() that can be called from an interrupt service + * routine. + * + * @param xTimer The handle of the timer being stopped. + * + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most + * of its time in the Blocked state, waiting for messages to arrive on the timer + * command queue. Calling xTimerStopFromISR() writes a message to the timer + * command queue, so has the potential to transition the timer service/daemon + * task out of the Blocked state. If calling xTimerStopFromISR() causes the + * timer service/daemon task to leave the Blocked state, and the timer service/ + * daemon task has a priority equal to or greater than the currently executing + * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will + * get set to pdTRUE internally within the xTimerStopFromISR() function. If + * xTimerStopFromISR() sets this value to pdTRUE then a context switch should + * be performed before the interrupt exits. + * + * @return pdFAIL will be returned if the stop command could not be sent to + * the timer command queue. pdPASS will be returned if the command was + * successfully sent to the timer command queue. When the command is actually + * processed will depend on the priority of the timer service/daemon task + * relative to other tasks in the system. The timer service/daemon task + * priority is set by the configTIMER_TASK_PRIORITY configuration constant. + * + * Example usage: + * @verbatim + * // This scenario assumes xTimer has already been created and started. When + * // an interrupt occurs, the timer should be simply stopped. + * + * // The interrupt service routine that stops the timer. + * void vAnExampleInterruptServiceRoutine( void ) + * { + * BaseType_t xHigherPriorityTaskWoken = pdFALSE; + * + * // The interrupt has occurred - simply stop the timer. + * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined + * // (within this function). As this is an interrupt service routine, only + * // FreeRTOS API functions that end in "FromISR" can be used. + * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS ) + * { + * // The stop command was not executed successfully. Take appropriate + * // action here. + * } + * + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch + * // should be performed. The syntax required to perform a context switch + * // from inside an ISR varies from port to port, and from compiler to + * // compiler. Inspect the demos for the port you are using to find the + * // actual syntax required. + * if( xHigherPriorityTaskWoken != pdFALSE ) + * { + * // Call the interrupt safe yield function here (actual function + * // depends on the FreeRTOS port being used). + * } + * } + * @endverbatim + */ +#define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U ) + +/** + * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer, + * TickType_t xNewPeriod, + * BaseType_t *pxHigherPriorityTaskWoken ); + * + * A version of xTimerChangePeriod() that can be called from an interrupt + * service routine. + * + * @param xTimer The handle of the timer that is having its period changed. + * + * @param xNewPeriod The new period for xTimer. Timer periods are specified in + * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time + * that has been specified in milliseconds. For example, if the timer must + * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively, + * if the timer must expire after 500ms, then xNewPeriod can be set to + * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than + * or equal to 1000. + * + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most + * of its time in the Blocked state, waiting for messages to arrive on the timer + * command queue. Calling xTimerChangePeriodFromISR() writes a message to the + * timer command queue, so has the potential to transition the timer service/ + * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR() + * causes the timer service/daemon task to leave the Blocked state, and the + * timer service/daemon task has a priority equal to or greater than the + * currently executing task (the task that was interrupted), then + * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the + * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets + * this value to pdTRUE then a context switch should be performed before the + * interrupt exits. + * + * @return pdFAIL will be returned if the command to change the timers period + * could not be sent to the timer command queue. pdPASS will be returned if the + * command was successfully sent to the timer command queue. When the command + * is actually processed will depend on the priority of the timer service/daemon + * task relative to other tasks in the system. The timer service/daemon task + * priority is set by the configTIMER_TASK_PRIORITY configuration constant. + * + * Example usage: + * @verbatim + * // This scenario assumes xTimer has already been created and started. When + * // an interrupt occurs, the period of xTimer should be changed to 500ms. + * + * // The interrupt service routine that changes the period of xTimer. + * void vAnExampleInterruptServiceRoutine( void ) + * { + * BaseType_t xHigherPriorityTaskWoken = pdFALSE; + * + * // The interrupt has occurred - change the period of xTimer to 500ms. + * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined + * // (within this function). As this is an interrupt service routine, only + * // FreeRTOS API functions that end in "FromISR" can be used. + * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS ) + * { + * // The command to change the timers period was not executed + * // successfully. Take appropriate action here. + * } + * + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch + * // should be performed. The syntax required to perform a context switch + * // from inside an ISR varies from port to port, and from compiler to + * // compiler. Inspect the demos for the port you are using to find the + * // actual syntax required. + * if( xHigherPriorityTaskWoken != pdFALSE ) + * { + * // Call the interrupt safe yield function here (actual function + * // depends on the FreeRTOS port being used). + * } + * } + * @endverbatim + */ +#define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U ) + +/** + * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer, + * BaseType_t *pxHigherPriorityTaskWoken ); + * + * A version of xTimerReset() that can be called from an interrupt service + * routine. + * + * @param xTimer The handle of the timer that is to be started, reset, or + * restarted. + * + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most + * of its time in the Blocked state, waiting for messages to arrive on the timer + * command queue. Calling xTimerResetFromISR() writes a message to the timer + * command queue, so has the potential to transition the timer service/daemon + * task out of the Blocked state. If calling xTimerResetFromISR() causes the + * timer service/daemon task to leave the Blocked state, and the timer service/ + * daemon task has a priority equal to or greater than the currently executing + * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will + * get set to pdTRUE internally within the xTimerResetFromISR() function. If + * xTimerResetFromISR() sets this value to pdTRUE then a context switch should + * be performed before the interrupt exits. + * + * @return pdFAIL will be returned if the reset command could not be sent to + * the timer command queue. pdPASS will be returned if the command was + * successfully sent to the timer command queue. When the command is actually + * processed will depend on the priority of the timer service/daemon task + * relative to other tasks in the system, although the timers expiry time is + * relative to when xTimerResetFromISR() is actually called. The timer service/daemon + * task priority is set by the configTIMER_TASK_PRIORITY configuration constant. + * + * Example usage: + * @verbatim + * // This scenario assumes xBacklightTimer has already been created. When a + * // key is pressed, an LCD back-light is switched on. If 5 seconds pass + * // without a key being pressed, then the LCD back-light is switched off. In + * // this case, the timer is a one-shot timer, and unlike the example given for + * // the xTimerReset() function, the key press event handler is an interrupt + * // service routine. + * + * // The callback function assigned to the one-shot timer. In this case the + * // parameter is not used. + * void vBacklightTimerCallback( TimerHandle_t pxTimer ) + * { + * // The timer expired, therefore 5 seconds must have passed since a key + * // was pressed. Switch off the LCD back-light. + * vSetBacklightState( BACKLIGHT_OFF ); + * } + * + * // The key press interrupt service routine. + * void vKeyPressEventInterruptHandler( void ) + * { + * BaseType_t xHigherPriorityTaskWoken = pdFALSE; + * + * // Ensure the LCD back-light is on, then reset the timer that is + * // responsible for turning the back-light off after 5 seconds of + * // key inactivity. This is an interrupt service routine so can only + * // call FreeRTOS API functions that end in "FromISR". + * vSetBacklightState( BACKLIGHT_ON ); + * + * // xTimerStartFromISR() or xTimerResetFromISR() could be called here + * // as both cause the timer to re-calculate its expiry time. + * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was + * // declared (in this function). + * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS ) + * { + * // The reset command was not executed successfully. Take appropriate + * // action here. + * } + * + * // Perform the rest of the key processing here. + * + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch + * // should be performed. The syntax required to perform a context switch + * // from inside an ISR varies from port to port, and from compiler to + * // compiler. Inspect the demos for the port you are using to find the + * // actual syntax required. + * if( xHigherPriorityTaskWoken != pdFALSE ) + * { + * // Call the interrupt safe yield function here (actual function + * // depends on the FreeRTOS port being used). + * } + * } + * @endverbatim + */ +#define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U ) + + +/** + * BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, + * void *pvParameter1, + * uint32_t ulParameter2, + * BaseType_t *pxHigherPriorityTaskWoken ); + * + * + * Used from application interrupt service routines to defer the execution of a + * function to the RTOS daemon task (the timer service task, hence this function + * is implemented in timers.c and is prefixed with 'Timer'). + * + * Ideally an interrupt service routine (ISR) is kept as short as possible, but + * sometimes an ISR either has a lot of processing to do, or needs to perform + * processing that is not deterministic. In these cases + * xTimerPendFunctionCallFromISR() can be used to defer processing of a function + * to the RTOS daemon task. + * + * A mechanism is provided that allows the interrupt to return directly to the + * task that will subsequently execute the pended callback function. This + * allows the callback function to execute contiguously in time with the + * interrupt - just as if the callback had executed in the interrupt itself. + * + * @param xFunctionToPend The function to execute from the timer service/ + * daemon task. The function must conform to the PendedFunction_t + * prototype. + * + * @param pvParameter1 The value of the callback function's first parameter. + * The parameter has a void * type to allow it to be used to pass any type. + * For example, unsigned longs can be cast to a void *, or the void * can be + * used to point to a structure. + * + * @param ulParameter2 The value of the callback function's second parameter. + * + * @param pxHigherPriorityTaskWoken As mentioned above, calling this function + * will result in a message being sent to the timer daemon task. If the + * priority of the timer daemon task (which is set using + * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of + * the currently running task (the task the interrupt interrupted) then + * *pxHigherPriorityTaskWoken will be set to pdTRUE within + * xTimerPendFunctionCallFromISR(), indicating that a context switch should be + * requested before the interrupt exits. For that reason + * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the + * example code below. + * + * @return pdPASS is returned if the message was successfully sent to the + * timer daemon task, otherwise pdFALSE is returned. + * + * Example usage: + * @verbatim + * + * // The callback function that will execute in the context of the daemon task. + * // Note callback functions must all use this same prototype. + * void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 ) + * { + * BaseType_t xInterfaceToService; + * + * // The interface that requires servicing is passed in the second + * // parameter. The first parameter is not used in this case. + * xInterfaceToService = ( BaseType_t ) ulParameter2; + * + * // ...Perform the processing here... + * } + * + * // An ISR that receives data packets from multiple interfaces + * void vAnISR( void ) + * { + * BaseType_t xInterfaceToService, xHigherPriorityTaskWoken; + * + * // Query the hardware to determine which interface needs processing. + * xInterfaceToService = prvCheckInterfaces(); + * + * // The actual processing is to be deferred to a task. Request the + * // vProcessInterface() callback function is executed, passing in the + * // number of the interface that needs processing. The interface to + * // service is passed in the second parameter. The first parameter is + * // not used in this case. + * xHigherPriorityTaskWoken = pdFALSE; + * xTimerPendFunctionCallFromISR( vProcessInterface, NULL, ( uint32_t ) xInterfaceToService, &xHigherPriorityTaskWoken ); + * + * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context + * // switch should be requested. The macro used is port specific and will + * // be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to + * // the documentation page for the port being used. + * portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); + * + * } + * @endverbatim + */ +BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + + /** + * BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, + * void *pvParameter1, + * uint32_t ulParameter2, + * TickType_t xTicksToWait ); + * + * + * Used to defer the execution of a function to the RTOS daemon task (the timer + * service task, hence this function is implemented in timers.c and is prefixed + * with 'Timer'). + * + * @param xFunctionToPend The function to execute from the timer service/ + * daemon task. The function must conform to the PendedFunction_t + * prototype. + * + * @param pvParameter1 The value of the callback function's first parameter. + * The parameter has a void * type to allow it to be used to pass any type. + * For example, unsigned longs can be cast to a void *, or the void * can be + * used to point to a structure. + * + * @param ulParameter2 The value of the callback function's second parameter. + * + * @param xTicksToWait Calling this function will result in a message being + * sent to the timer daemon task on a queue. xTicksToWait is the amount of + * time the calling task should remain in the Blocked state (so not using any + * processing time) for space to become available on the timer queue if the + * queue is found to be full. + * + * @return pdPASS is returned if the message was successfully sent to the + * timer daemon task, otherwise pdFALSE is returned. + * + */ +BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * const char * const pcTimerGetName( TimerHandle_t xTimer ); + * + * Returns the name that was assigned to a timer when the timer was created. + * + * @param xTimer The handle of the timer being queried. + * + * @return The name assigned to the timer specified by the xTimer parameter. + */ +const char * pcTimerGetName( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + +/** + * TickType_t xTimerGetPeriod( TimerHandle_t xTimer ); + * + * Returns the period of a timer. + * + * @param xTimer The handle of the timer being queried. + * + * @return The period of the timer in ticks. + */ +TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; + +/** +* TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ); +* +* Returns the time in ticks at which the timer will expire. If this is less +* than the current tick count then the expiry time has overflowed from the +* current time. +* +* @param xTimer The handle of the timer being queried. +* +* @return If the timer is running then the time in ticks at which the timer +* will next expire is returned. If the timer is not running then the return +* value is undefined. +*/ +TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; + +/* + * Functions beyond this part are not part of the public API and are intended + * for use by the kernel only. + */ +BaseType_t xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION; +BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +#if( configUSE_TRACE_FACILITY == 1 ) + void vTimerSetTimerNumber( TimerHandle_t xTimer, UBaseType_t uxTimerNumber ) PRIVILEGED_FUNCTION; + UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; +#endif + +#ifdef __cplusplus +} +#endif +#endif /* TIMERS_H */ + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/list.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/list.c new file mode 100644 index 0000000..bc8636c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/list.c @@ -0,0 +1,198 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + + +#include +#include "FreeRTOS.h" +#include "list.h" + +/*----------------------------------------------------------- + * PUBLIC LIST API documented in list.h + *----------------------------------------------------------*/ + +void vListInitialise( List_t * const pxList ) +{ + /* The list structure contains a list item which is used to mark the + end of the list. To initialise the list the list end is inserted + as the only list entry. */ + pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ + + /* The list end value is the highest possible value in the list to + ensure it remains at the end of the list. */ + pxList->xListEnd.xItemValue = portMAX_DELAY; + + /* The list end next and previous pointers point to itself so we know + when the list is empty. */ + pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ + pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );/*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ + + pxList->uxNumberOfItems = ( UBaseType_t ) 0U; + + /* Write known values into the list if + configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ + listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ); + listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ); +} +/*-----------------------------------------------------------*/ + +void vListInitialiseItem( ListItem_t * const pxItem ) +{ + /* Make sure the list item is not recorded as being on a list. */ + pxItem->pvContainer = NULL; + + /* Write known values into the list item if + configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ + listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ); + listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ); +} +/*-----------------------------------------------------------*/ + +void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) +{ +ListItem_t * const pxIndex = pxList->pxIndex; + + /* Only effective when configASSERT() is also defined, these tests may catch + the list data structures being overwritten in memory. They will not catch + data errors caused by incorrect configuration or use of FreeRTOS. */ + listTEST_LIST_INTEGRITY( pxList ); + listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); + + /* Insert a new list item into pxList, but rather than sort the list, + makes the new list item the last item to be removed by a call to + listGET_OWNER_OF_NEXT_ENTRY(). */ + pxNewListItem->pxNext = pxIndex; + pxNewListItem->pxPrevious = pxIndex->pxPrevious; + + /* Only used during decision coverage testing. */ + mtCOVERAGE_TEST_DELAY(); + + pxIndex->pxPrevious->pxNext = pxNewListItem; + pxIndex->pxPrevious = pxNewListItem; + + /* Remember which list the item is in. */ + pxNewListItem->pvContainer = ( void * ) pxList; + + ( pxList->uxNumberOfItems )++; +} +/*-----------------------------------------------------------*/ + +void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem ) +{ +ListItem_t *pxIterator; +const TickType_t xValueOfInsertion = pxNewListItem->xItemValue; + + /* Only effective when configASSERT() is also defined, these tests may catch + the list data structures being overwritten in memory. They will not catch + data errors caused by incorrect configuration or use of FreeRTOS. */ + listTEST_LIST_INTEGRITY( pxList ); + listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); + + /* Insert the new list item into the list, sorted in xItemValue order. + + If the list already contains a list item with the same item value then the + new list item should be placed after it. This ensures that TCB's which are + stored in ready lists (all of which have the same xItemValue value) get a + share of the CPU. However, if the xItemValue is the same as the back marker + the iteration loop below will not end. Therefore the value is checked + first, and the algorithm slightly modified if necessary. */ + if( xValueOfInsertion == portMAX_DELAY ) + { + pxIterator = pxList->xListEnd.pxPrevious; + } + else + { + /* *** NOTE *********************************************************** + If you find your application is crashing here then likely causes are + listed below. In addition see http://www.freertos.org/FAQHelp.html for + more tips, and ensure configASSERT() is defined! + http://www.freertos.org/a00110.html#configASSERT + + 1) Stack overflow - + see http://www.freertos.org/Stacks-and-stack-overflow-checking.html + 2) Incorrect interrupt priority assignment, especially on Cortex-M + parts where numerically high priority values denote low actual + interrupt priorities, which can seem counter intuitive. See + http://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition + of configMAX_SYSCALL_INTERRUPT_PRIORITY on + http://www.freertos.org/a00110.html + 3) Calling an API function from within a critical section or when + the scheduler is suspended, or calling an API function that does + not end in "FromISR" from an interrupt. + 4) Using a queue or semaphore before it has been initialised or + before the scheduler has been started (are interrupts firing + before vTaskStartScheduler() has been called?). + **********************************************************************/ + + for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ + { + /* There is nothing to do here, just iterating to the wanted + insertion position. */ + } + } + + pxNewListItem->pxNext = pxIterator->pxNext; + pxNewListItem->pxNext->pxPrevious = pxNewListItem; + pxNewListItem->pxPrevious = pxIterator; + pxIterator->pxNext = pxNewListItem; + + /* Remember which list the item is in. This allows fast removal of the + item later. */ + pxNewListItem->pvContainer = ( void * ) pxList; + + ( pxList->uxNumberOfItems )++; +} +/*-----------------------------------------------------------*/ + +UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) +{ +/* The list item knows which list it is in. Obtain the list from the list +item. */ +List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer; + + pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious; + pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext; + + /* Only used during decision coverage testing. */ + mtCOVERAGE_TEST_DELAY(); + + /* Make sure the index is left pointing to a valid item. */ + if( pxList->pxIndex == pxItemToRemove ) + { + pxList->pxIndex = pxItemToRemove->pxPrevious; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + pxItemToRemove->pvContainer = NULL; + ( pxList->uxNumberOfItems )--; + + return pxList->uxNumberOfItems; +} +/*-----------------------------------------------------------*/ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/Common/mpu_wrappers.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/Common/mpu_wrappers.c new file mode 100644 index 0000000..6872b74 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/Common/mpu_wrappers.c @@ -0,0 +1,1290 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* + * Implementation of the wrapper functions used to raise the processor privilege + * before calling a standard FreeRTOS API function. + */ + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "timers.h" +#include "event_groups.h" +#include "stream_buffer.h" +#include "mpu_prototypes.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* + * Checks to see if being called from the context of an unprivileged task, and + * if so raises the privilege level and returns false - otherwise does nothing + * other than return true. + */ +extern BaseType_t xPortRaisePrivilege( void ); + +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + BaseType_t MPU_xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskCreateRestricted( pxTaskDefinition, pxCreatedTask ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif /* conifgSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + BaseType_t MPU_xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskCreateRestrictedStatic( pxTaskDefinition, pxCreatedTask ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif /* conifgSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + BaseType_t MPU_xTaskCreate( TaskFunction_t pvTaskCode, const char * const pcName, uint16_t usStackDepth, void *pvParameters, UBaseType_t uxPriority, TaskHandle_t *pxCreatedTask ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + TaskHandle_t MPU_xTaskCreateStatic( TaskFunction_t pxTaskCode, const char * const pcName, const uint32_t ulStackDepth, void * const pvParameters, UBaseType_t uxPriority, StackType_t * const puxStackBuffer, StaticTask_t * const pxTaskBuffer ) + { + TaskHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskCreateStatic( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, puxStackBuffer, pxTaskBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +void MPU_vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const xRegions ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskAllocateMPURegions( xTask, xRegions ); + vPortResetPrivilege( xRunningPrivileged ); +} +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelete == 1 ) + void MPU_vTaskDelete( TaskHandle_t pxTaskToDelete ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskDelete( pxTaskToDelete ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelayUntil == 1 ) + void MPU_vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, TickType_t xTimeIncrement ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskAbortDelay == 1 ) + BaseType_t MPU_xTaskAbortDelay( TaskHandle_t xTask ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskAbortDelay( xTask ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelay == 1 ) + void MPU_vTaskDelay( TickType_t xTicksToDelay ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskDelay( xTicksToDelay ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_uxTaskPriorityGet == 1 ) + UBaseType_t MPU_uxTaskPriorityGet( TaskHandle_t pxTask ) + { + UBaseType_t uxReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + uxReturn = uxTaskPriorityGet( pxTask ); + vPortResetPrivilege( xRunningPrivileged ); + return uxReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskPrioritySet == 1 ) + void MPU_vTaskPrioritySet( TaskHandle_t pxTask, UBaseType_t uxNewPriority ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskPrioritySet( pxTask, uxNewPriority ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_eTaskGetState == 1 ) + eTaskState MPU_eTaskGetState( TaskHandle_t pxTask ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + eTaskState eReturn; + + eReturn = eTaskGetState( pxTask ); + vPortResetPrivilege( xRunningPrivileged ); + return eReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TRACE_FACILITY == 1 ) + void MPU_vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskGetInfo( xTask, pxTaskStatus, xGetFreeStackSpace, eState ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) + TaskHandle_t MPU_xTaskGetIdleTaskHandle( void ) + { + TaskHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskGetIdleTaskHandle(); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskSuspend == 1 ) + void MPU_vTaskSuspend( TaskHandle_t pxTaskToSuspend ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskSuspend( pxTaskToSuspend ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskSuspend == 1 ) + void MPU_vTaskResume( TaskHandle_t pxTaskToResume ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskResume( pxTaskToResume ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +void MPU_vTaskSuspendAll( void ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskSuspendAll(); + vPortResetPrivilege( xRunningPrivileged ); +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xTaskResumeAll( void ) +{ +BaseType_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskResumeAll(); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +TickType_t MPU_xTaskGetTickCount( void ) +{ +TickType_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskGetTickCount(); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +UBaseType_t MPU_uxTaskGetNumberOfTasks( void ) +{ +UBaseType_t uxReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + uxReturn = uxTaskGetNumberOfTasks(); + vPortResetPrivilege( xRunningPrivileged ); + return uxReturn; +} +/*-----------------------------------------------------------*/ + +char * MPU_pcTaskGetName( TaskHandle_t xTaskToQuery ) +{ +char *pcReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + pcReturn = pcTaskGetName( xTaskToQuery ); + vPortResetPrivilege( xRunningPrivileged ); + return pcReturn; +} +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskGetHandle == 1 ) + TaskHandle_t MPU_xTaskGetHandle( const char *pcNameToQuery ) + { + TaskHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskGetHandle( pcNameToQuery ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + void MPU_vTaskList( char *pcWriteBuffer ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskList( pcWriteBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + void MPU_vTaskGetRunTimeStats( char *pcWriteBuffer ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskGetRunTimeStats( pcWriteBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + void MPU_vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxTagValue ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskSetApplicationTaskTag( xTask, pxTagValue ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + TaskHookFunction_t MPU_xTaskGetApplicationTaskTag( TaskHandle_t xTask ) + { + TaskHookFunction_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskGetApplicationTaskTag( xTask ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) + void MPU_vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskSetThreadLocalStoragePointer( xTaskToSet, xIndex, pvValue ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) + void *MPU_pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) + { + void *pvReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + pvReturn = pvTaskGetThreadLocalStoragePointer( xTaskToQuery, xIndex ); + vPortResetPrivilege( xRunningPrivileged ); + return pvReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskCallApplicationTaskHook( xTask, pvParameter ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t MPU_uxTaskGetSystemState( TaskStatus_t *pxTaskStatusArray, UBaseType_t uxArraySize, uint32_t *pulTotalRunTime ) + { + UBaseType_t uxReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime ); + vPortResetPrivilege( xRunningPrivileged ); + return uxReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) + UBaseType_t MPU_uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) + { + UBaseType_t uxReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + uxReturn = uxTaskGetStackHighWaterMark( xTask ); + vPortResetPrivilege( xRunningPrivileged ); + return uxReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) + TaskHandle_t MPU_xTaskGetCurrentTaskHandle( void ) + { + TaskHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskGetCurrentTaskHandle(); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskGetSchedulerState == 1 ) + BaseType_t MPU_xTaskGetSchedulerState( void ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskGetSchedulerState(); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +void MPU_vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTaskSetTimeOutState( pxTimeOut ); + vPortResetPrivilege( xRunningPrivileged ); +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) +{ +BaseType_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskCheckForTimeOut( pxTimeOut, pxTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + BaseType_t MPU_xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskGenericNotify( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + BaseType_t MPU_xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + uint32_t MPU_ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) + { + uint32_t ulReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + ulReturn = ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + return ulReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + BaseType_t MPU_xTaskNotifyStateClear( TaskHandle_t xTask ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskNotifyStateClear( xTask ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + QueueHandle_t MPU_xQueueGenericCreate( UBaseType_t uxQueueLength, UBaseType_t uxItemSize, uint8_t ucQueueType ) + { + QueueHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + QueueHandle_t MPU_xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ) + { + QueueHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueGenericCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxStaticQueue, ucQueueType ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xQueueGenericReset( QueueHandle_t pxQueue, BaseType_t xNewQueue ) +{ +BaseType_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueGenericReset( pxQueue, xNewQueue ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, BaseType_t xCopyPosition ) +{ +BaseType_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, xCopyPosition ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +UBaseType_t MPU_uxQueueMessagesWaiting( const QueueHandle_t pxQueue ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); +UBaseType_t uxReturn; + + uxReturn = uxQueueMessagesWaiting( pxQueue ); + vPortResetPrivilege( xRunningPrivileged ); + return uxReturn; +} +/*-----------------------------------------------------------*/ + +UBaseType_t MPU_uxQueueSpacesAvailable( const QueueHandle_t xQueue ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); +UBaseType_t uxReturn; + + uxReturn = uxQueueSpacesAvailable( xQueue ); + vPortResetPrivilege( xRunningPrivileged ); + return uxReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xQueueReceive( QueueHandle_t pxQueue, void * const pvBuffer, TickType_t xTicksToWait ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); +BaseType_t xReturn; + + xReturn = xQueueReceive( pxQueue, pvBuffer, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); +BaseType_t xReturn; + + xReturn = xQueuePeek( xQueue, pvBuffer, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); +BaseType_t xReturn; + + xReturn = xQueueSemaphoreTake( xQueue, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xQueuePeekFromISR( QueueHandle_t pxQueue, void * const pvBuffer ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); +BaseType_t xReturn; + + xReturn = xQueuePeekFromISR( pxQueue, pvBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +void* MPU_xQueueGetMutexHolder( QueueHandle_t xSemaphore ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); +void * xReturn; + + xReturn = ( void * ) xQueueGetMutexHolder( xSemaphore ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +#if( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + QueueHandle_t MPU_xQueueCreateMutex( const uint8_t ucQueueType ) + { + QueueHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueCreateMutex( ucQueueType ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + QueueHandle_t MPU_xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) + { + QueueHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueCreateMutexStatic( ucQueueType, pxStaticQueue ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + QueueHandle_t MPU_xQueueCreateCountingSemaphore( UBaseType_t uxCountValue, UBaseType_t uxInitialCount ) + { + QueueHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueCreateCountingSemaphore( uxCountValue, uxInitialCount ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + + QueueHandle_t MPU_xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) + { + QueueHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueCreateCountingSemaphoreStatic( uxMaxCount, uxInitialCount, pxStaticQueue ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_RECURSIVE_MUTEXES == 1 ) + BaseType_t MPU_xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xBlockTime ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueTakeMutexRecursive( xMutex, xBlockTime ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_RECURSIVE_MUTEXES == 1 ) + BaseType_t MPU_xQueueGiveMutexRecursive( QueueHandle_t xMutex ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueGiveMutexRecursive( xMutex ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + QueueSetHandle_t MPU_xQueueCreateSet( UBaseType_t uxEventQueueLength ) + { + QueueSetHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueCreateSet( uxEventQueueLength ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + QueueSetMemberHandle_t MPU_xQueueSelectFromSet( QueueSetHandle_t xQueueSet, TickType_t xBlockTimeTicks ) + { + QueueSetMemberHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueSelectFromSet( xQueueSet, xBlockTimeTicks ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + BaseType_t MPU_xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueAddToSet( xQueueOrSemaphore, xQueueSet ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xQueueRemoveFromSet( xQueueOrSemaphore, xQueueSet ); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if configQUEUE_REGISTRY_SIZE > 0 + void MPU_vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcName ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vQueueAddToRegistry( xQueue, pcName ); + + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if configQUEUE_REGISTRY_SIZE > 0 + void MPU_vQueueUnregisterQueue( QueueHandle_t xQueue ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vQueueUnregisterQueue( xQueue ); + + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if configQUEUE_REGISTRY_SIZE > 0 + const char *MPU_pcQueueGetName( QueueHandle_t xQueue ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + const char *pcReturn; + + pcReturn = pcQueueGetName( xQueue ); + + vPortResetPrivilege( xRunningPrivileged ); + return pcReturn; + } +#endif +/*-----------------------------------------------------------*/ + +void MPU_vQueueDelete( QueueHandle_t xQueue ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vQueueDelete( xQueue ); + + vPortResetPrivilege( xRunningPrivileged ); +} +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + void *MPU_pvPortMalloc( size_t xSize ) + { + void *pvReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + pvReturn = pvPortMalloc( xSize ); + + vPortResetPrivilege( xRunningPrivileged ); + + return pvReturn; + } +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + void MPU_vPortFree( void *pv ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vPortFree( pv ); + + vPortResetPrivilege( xRunningPrivileged ); + } +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + void MPU_vPortInitialiseBlocks( void ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vPortInitialiseBlocks(); + + vPortResetPrivilege( xRunningPrivileged ); + } +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + size_t MPU_xPortGetFreeHeapSize( void ) + { + size_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xPortGetFreeHeapSize(); + + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) ) + TimerHandle_t MPU_xTimerCreate( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction ) + { + TimerHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTimerCreate( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) ) + TimerHandle_t MPU_xTimerCreateStatic( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction, StaticTimer_t *pxTimerBuffer ) + { + TimerHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTimerCreateStatic( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxTimerBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TIMERS == 1 ) + void *MPU_pvTimerGetTimerID( const TimerHandle_t xTimer ) + { + void * pvReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + pvReturn = pvTimerGetTimerID( xTimer ); + vPortResetPrivilege( xRunningPrivileged ); + + return pvReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TIMERS == 1 ) + void MPU_vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ) + { + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vTimerSetTimerID( xTimer, pvNewID ); + vPortResetPrivilege( xRunningPrivileged ); + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TIMERS == 1 ) + BaseType_t MPU_xTimerIsTimerActive( TimerHandle_t xTimer ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTimerIsTimerActive( xTimer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TIMERS == 1 ) + TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) + { + TaskHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTimerGetTimerDaemonTaskHandle(); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) + BaseType_t MPU_xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTimerPendFunctionCall( xFunctionToPend, pvParameter1, ulParameter2, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TIMERS == 1 ) + const char * MPU_pcTimerGetName( TimerHandle_t xTimer ) + { + const char * pcReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + pcReturn = pcTimerGetName( xTimer ); + vPortResetPrivilege( xRunningPrivileged ); + + return pcReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TIMERS == 1 ) + TickType_t MPU_xTimerGetPeriod( TimerHandle_t xTimer ) + { + TickType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTimerGetPeriod( xTimer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TIMERS == 1 ) + TickType_t MPU_xTimerGetExpiryTime( TimerHandle_t xTimer ) + { + TickType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTimerGetExpiryTime( xTimer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configUSE_TIMERS == 1 ) + BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) + { + BaseType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTimerGenericCommand( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + EventGroupHandle_t MPU_xEventGroupCreate( void ) + { + EventGroupHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xEventGroupCreate(); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + EventGroupHandle_t MPU_xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer ) + { + EventGroupHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xEventGroupCreateStatic( pxEventGroupBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + +EventBits_t MPU_xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ) +{ +EventBits_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xEventGroupWaitBits( xEventGroup, uxBitsToWaitFor, xClearOnExit, xWaitForAllBits, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +EventBits_t MPU_xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) +{ +EventBits_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xEventGroupClearBits( xEventGroup, uxBitsToClear ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +EventBits_t MPU_xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) +{ +EventBits_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xEventGroupSetBits( xEventGroup, uxBitsToSet ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +EventBits_t MPU_xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ) +{ +EventBits_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xEventGroupSync( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +void MPU_vEventGroupDelete( EventGroupHandle_t xEventGroup ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vEventGroupDelete( xEventGroup ); + vPortResetPrivilege( xRunningPrivileged ); +} +/*-----------------------------------------------------------*/ + +size_t MPU_xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, TickType_t xTicksToWait ) +{ +size_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferSend( xStreamBuffer, pvTxData, xDataLengthBytes, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t MPU_xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t * const pxHigherPriorityTaskWoken ) +{ +size_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferSendFromISR( xStreamBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t MPU_xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, TickType_t xTicksToWait ) +{ +size_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferReceive( xStreamBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t MPU_xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t * const pxHigherPriorityTaskWoken ) +{ +size_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferReceiveFromISR( xStreamBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +void MPU_vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + vStreamBufferDelete( xStreamBuffer ); + vPortResetPrivilege( xRunningPrivileged ); +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ) +{ +BaseType_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferIsFull( xStreamBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) +{ +BaseType_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferIsEmpty( xStreamBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) +{ +BaseType_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferReset( xStreamBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t MPU_xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ) +{ +size_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferSpacesAvailable( xStreamBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t MPU_xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ) +{ +size_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferBytesAvailable( xStreamBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t MPU_xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel ) +{ +BaseType_t xReturn; +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferSetTriggerLevel( xStreamBuffer, xTriggerLevel ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer ) + { + StreamBufferHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, xIsMessageBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + StreamBufferHandle_t MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer, uint8_t * const pucStreamBufferStorageArea, StaticStreamBuffer_t * const pxStaticStreamBuffer ) + { + StreamBufferHandle_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, xIsMessageBuffer, pucStreamBufferStorageArea, pxStaticStreamBuffer ); + vPortResetPrivilege( xRunningPrivileged ); + + return xReturn; + } +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + + +/* Functions that the application writer wants to execute in privileged mode +can be defined in application_defined_privileged_functions.h. The functions +must take the same format as those above whereby the privilege state on exit +equals the privilege state on entry. For example: + +void MPU_FunctionName( [parameters ] ) +{ +BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + FunctionName( [parameters ] ); + + vPortResetPrivilege( xRunningPrivileged ); +} +*/ + +#if configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS == 1 + #include "application_defined_privileged_functions.h" +#endif diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c new file mode 100644 index 0000000..aaa1801 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c @@ -0,0 +1,416 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/*----------------------------------------------------------- + * Implementation of functions defined in portable.h for the ARM CM0 port. + *----------------------------------------------------------*/ + +/* IAR includes. */ +#include "intrinsics.h" + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "task.h" + +#ifndef configSYSTICK_CLOCK_HZ + #define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ +#endif + +/* Constants required to manipulate the NVIC. */ +/* Constants required to manipulate the NVIC. */ +#define portNVIC_SYSTICK_CTRL ( * ( ( volatile uint32_t * ) 0xe000e010 ) ) +#define portNVIC_SYSTICK_LOAD ( * ( ( volatile uint32_t * ) 0xe000e014 ) ) +#define portNVIC_SYSTICK_CURRENT_VALUE ( * ( ( volatile uint32_t * ) 0xe000e018 ) ) +#define portNVIC_SYSPRI2 ( * ( ( volatile uint32_t * ) 0xe000ed20 ) ) +#define portNVIC_SYSTICK_CLK 0x00000004 +#define portNVIC_SYSTICK_INT 0x00000002 +#define portNVIC_SYSTICK_ENABLE 0x00000001 +#define portNVIC_SYSTICK_COUNT_FLAG ( 1UL << 16UL ) +#define portMIN_INTERRUPT_PRIORITY ( 255UL ) +#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL ) +#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL ) + +/* Constants required to set up the initial stack. */ +#define portINITIAL_XPSR ( 0x01000000 ) + +/* For backward compatibility, ensure configKERNEL_INTERRUPT_PRIORITY is +defined. The value 255 should also ensure backward compatibility. +FreeRTOS.org versions prior to V4.3.0 did not include this definition. */ +#ifndef configKERNEL_INTERRUPT_PRIORITY + #define configKERNEL_INTERRUPT_PRIORITY 0 +#endif + +/* The systick is a 24-bit counter. */ +#define portMAX_24_BIT_NUMBER ( 0xffffffUL ) + +/* A fiddle factor to estimate the number of SysTick counts that would have +occurred while the SysTick counter is stopped during tickless idle +calculations. */ +#define portMISSED_COUNTS_FACTOR ( 45UL ) + +/* Each task maintains its own interrupt status in the critical nesting +variable. */ +static UBaseType_t uxCriticalNesting = 0xaaaaaaaa; + +/* + * Setup the timer to generate the tick interrupts. + */ +static void prvSetupTimerInterrupt( void ); + +/* + * Exception handlers. + */ +void xPortSysTickHandler( void ); + +/* + * Start first task is a separate function so it can be tested in isolation. + */ +extern void vPortStartFirstTask( void ); + +/* + * Used to catch tasks that attempt to return from their implementing function. + */ +static void prvTaskExitError( void ); + +/*-----------------------------------------------------------*/ + +/* + * The number of SysTick increments that make up one tick period. + */ +#if configUSE_TICKLESS_IDLE == 1 + static unsigned long ulTimerCountsForOneTick = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* + * The maximum number of tick periods that can be suppressed is limited by the + * 24 bit resolution of the SysTick timer. + */ +#if configUSE_TICKLESS_IDLE == 1 + static unsigned long xMaximumPossibleSuppressedTicks = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* + * Compensate for the CPU cycles that pass while the SysTick is stopped (low + * power functionality only. + */ +#if configUSE_TICKLESS_IDLE == 1 + static unsigned long ulStoppedTimerCompensation = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* + * See header file for description. + */ +StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) +{ + /* Simulate the stack frame as it would be created by a context switch + interrupt. */ + pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts. */ + *pxTopOfStack = portINITIAL_XPSR; /* xPSR */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) pxCode; /* PC */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) prvTaskExitError; /* LR */ + pxTopOfStack -= 5; /* R12, R3, R2 and R1. */ + *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */ + pxTopOfStack -= 8; /* R11..R4. */ + + return pxTopOfStack; +} +/*-----------------------------------------------------------*/ + +static void prvTaskExitError( void ) +{ + /* A function that implements a task must not exit or attempt to return to + its caller as there is nothing to return to. If a task wants to exit it + should instead call vTaskDelete( NULL ). + + Artificially force an assert() to be triggered if configASSERT() is + defined, then stop here so application writers can catch the error. */ + configASSERT( uxCriticalNesting == ~0UL ); + portDISABLE_INTERRUPTS(); + for( ;; ); +} +/*-----------------------------------------------------------*/ + +/* + * See header file for description. + */ +BaseType_t xPortStartScheduler( void ) +{ + /* Make PendSV and SysTick the lowest priority interrupts. */ + portNVIC_SYSPRI2 |= portNVIC_PENDSV_PRI; + portNVIC_SYSPRI2 |= portNVIC_SYSTICK_PRI; + + /* Start the timer that generates the tick ISR. Interrupts are disabled + here already. */ + prvSetupTimerInterrupt(); + + /* Initialise the critical nesting count ready for the first task. */ + uxCriticalNesting = 0; + + /* Start the first task. */ + vPortStartFirstTask(); + + /* Should not get here! */ + return 0; +} +/*-----------------------------------------------------------*/ + +void vPortEndScheduler( void ) +{ + /* Not implemented in ports where there is nothing to return to. + Artificially force an assert. */ + configASSERT( uxCriticalNesting == 1000UL ); +} +/*-----------------------------------------------------------*/ + +void vPortYield( void ) +{ + /* Set a PendSV to request a context switch. */ + *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; + + /* Barriers are normally not required but do ensure the code is completely + within the specified behaviour for the architecture. */ + __DSB(); + __ISB(); +} +/*-----------------------------------------------------------*/ + +void vPortEnterCritical( void ) +{ + portDISABLE_INTERRUPTS(); + uxCriticalNesting++; + __DSB(); + __ISB(); +} +/*-----------------------------------------------------------*/ + +void vPortExitCritical( void ) +{ + configASSERT( uxCriticalNesting ); + uxCriticalNesting--; + if( uxCriticalNesting == 0 ) + { + portENABLE_INTERRUPTS(); + } +} +/*-----------------------------------------------------------*/ + +void xPortSysTickHandler( void ) +{ +uint32_t ulPreviousMask; + + ulPreviousMask = portSET_INTERRUPT_MASK_FROM_ISR(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { + /* Pend a context switch. */ + *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( ulPreviousMask ); +} +/*-----------------------------------------------------------*/ + +#if configUSE_TICKLESS_IDLE == 1 + + __weak void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) + { + uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickCTRL; + TickType_t xModifiableIdleTime; + + /* Make sure the SysTick reload value does not overflow the counter. */ + if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks ) + { + xExpectedIdleTime = xMaximumPossibleSuppressedTicks; + } + + /* Stop the SysTick momentarily. The time the SysTick is stopped for + is accounted for as best it can be, but using the tickless mode will + inevitably result in some tiny drift of the time maintained by the + kernel with respect to calendar time. */ + portNVIC_SYSTICK_CTRL &= ~portNVIC_SYSTICK_ENABLE; + + /* Calculate the reload value required to wait xExpectedIdleTime + tick periods. -1 is used because this code will execute part way + through one of the tick periods. */ + ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) ); + if( ulReloadValue > ulStoppedTimerCompensation ) + { + ulReloadValue -= ulStoppedTimerCompensation; + } + + /* Enter a critical section but don't use the taskENTER_CRITICAL() + method as that will mask interrupts that should exit sleep mode. */ + __disable_interrupt(); + + /* If a context switch is pending or a task is waiting for the scheduler + to be unsuspended then abandon the low power entry. */ + if( eTaskConfirmSleepModeStatus() == eAbortSleep ) + { + /* Restart from whatever is left in the count register to complete + this tick period. */ + portNVIC_SYSTICK_LOAD = portNVIC_SYSTICK_CURRENT_VALUE; + + /* Restart SysTick. */ + portNVIC_SYSTICK_CTRL |= portNVIC_SYSTICK_ENABLE; + + /* Reset the reload register to the value required for normal tick + periods. */ + portNVIC_SYSTICK_LOAD = ulTimerCountsForOneTick - 1UL; + + /* Re-enable interrupts - see comments above __disable_interrupt() + call above. */ + __enable_interrupt(); + } + else + { + /* Set the new reload value. */ + portNVIC_SYSTICK_LOAD = ulReloadValue; + + /* Clear the SysTick count flag and set the count value back to + zero. */ + portNVIC_SYSTICK_CURRENT_VALUE = 0UL; + + /* Restart SysTick. */ + portNVIC_SYSTICK_CTRL |= portNVIC_SYSTICK_ENABLE; + + /* Sleep until something happens. configPRE_SLEEP_PROCESSING() can + set its parameter to 0 to indicate that its implementation contains + its own wait for interrupt or wait for event instruction, and so wfi + should not be executed again. However, the original expected idle + time variable must remain unmodified, so a copy is taken. */ + xModifiableIdleTime = xExpectedIdleTime; + configPRE_SLEEP_PROCESSING( &xModifiableIdleTime ); + if( xModifiableIdleTime > 0 ) + { + __DSB(); + __WFI(); + __ISB(); + } + configPOST_SLEEP_PROCESSING( &xExpectedIdleTime ); + + /* Stop SysTick. Again, the time the SysTick is stopped for is + accounted for as best it can be, but using the tickless mode will + inevitably result in some tiny drift of the time maintained by the + kernel with respect to calendar time. */ + ulSysTickCTRL = portNVIC_SYSTICK_CTRL; + portNVIC_SYSTICK_CTRL = ( ulSysTickCTRL & ~portNVIC_SYSTICK_ENABLE ); + + /* Re-enable interrupts - see comments above __disable_interrupt() + call above. */ + __enable_interrupt(); + + if( ( ulSysTickCTRL & portNVIC_SYSTICK_COUNT_FLAG ) != 0 ) + { + uint32_t ulCalculatedLoadValue; + + /* The tick interrupt has already executed, and the SysTick + count reloaded with ulReloadValue. Reset the + portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick + period. */ + ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE ); + + /* Don't allow a tiny value, or values that have somehow + underflowed because the post sleep hook did something + that took too long. */ + if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) ) + { + ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ); + } + + portNVIC_SYSTICK_LOAD = ulCalculatedLoadValue; + + /* The tick interrupt handler will already have pended the tick + processing in the kernel. As the pending tick will be + processed as soon as this function exits, the tick value + maintained by the tick is stepped forward by one less than the + time spent waiting. */ + ulCompleteTickPeriods = xExpectedIdleTime - 1UL; + } + else + { + /* Something other than the tick interrupt ended the sleep. + Work out how long the sleep lasted rounded to complete tick + periods (not the ulReload value which accounted for part + ticks). */ + ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE; + + /* How many complete tick periods passed while the processor + was waiting? */ + ulCompleteTickPeriods = ulCompletedSysTickDecrements / ulTimerCountsForOneTick; + + /* The reload value is set to whatever fraction of a single tick + period remains. */ + portNVIC_SYSTICK_LOAD = ( ( ulCompleteTickPeriods + 1 ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements; + } + + /* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG + again, then set portNVIC_SYSTICK_LOAD_REG back to its standard + value. The critical section is used to ensure the tick interrupt + can only execute once in the case that the reload register is near + zero. */ + portNVIC_SYSTICK_CURRENT_VALUE = 0UL; + portENTER_CRITICAL(); + { + portNVIC_SYSTICK_CTRL |= portNVIC_SYSTICK_ENABLE; + vTaskStepTick( ulCompleteTickPeriods ); + portNVIC_SYSTICK_LOAD = ulTimerCountsForOneTick - 1UL; + } + portEXIT_CRITICAL(); + } + } + +#endif /* #if configUSE_TICKLESS_IDLE */ +/*-----------------------------------------------------------*/ + +/* + * Setup the systick timer to generate the tick interrupts at the required + * frequency. + */ +static void prvSetupTimerInterrupt( void ) +{ + /* Calculate the constants required to configure the tick interrupt. */ + #if configUSE_TICKLESS_IDLE == 1 + { + ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ); + xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick; + ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ ); + } + #endif /* configUSE_TICKLESS_IDLE */ + + /* Stop and reset the SysTick. */ + portNVIC_SYSTICK_CTRL = 0UL; + portNVIC_SYSTICK_CURRENT_VALUE = 0UL; + + /* Configure SysTick to interrupt at the requested rate. */ + portNVIC_SYSTICK_LOAD = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL; + portNVIC_SYSTICK_CTRL = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE; +} +/*-----------------------------------------------------------*/ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM0/portasm.s b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM0/portasm.s new file mode 100644 index 0000000..ec98a86 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM0/portasm.s @@ -0,0 +1,131 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#include + + RSEG CODE:CODE(2) + thumb + + EXTERN vPortYieldFromISR + EXTERN pxCurrentTCB + EXTERN vTaskSwitchContext + + PUBLIC vSetMSP + PUBLIC xPortPendSVHandler + PUBLIC vPortSVCHandler + PUBLIC vPortStartFirstTask + PUBLIC ulSetInterruptMaskFromISR + PUBLIC vClearInterruptMaskFromISR + +/*-----------------------------------------------------------*/ + +vSetMSP + msr msp, r0 + bx lr + +/*-----------------------------------------------------------*/ + +xPortPendSVHandler: + mrs r0, psp + + ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */ + ldr r2, [r3] + + subs r0, r0, #32 /* Make space for the remaining low registers. */ + str r0, [r2] /* Save the new top of stack. */ + stmia r0!, {r4-r7} /* Store the low registers that are not saved automatically. */ + mov r4, r8 /* Store the high registers. */ + mov r5, r9 + mov r6, r10 + mov r7, r11 + stmia r0!, {r4-r7} + + push {r3, r14} + cpsid i + bl vTaskSwitchContext + cpsie i + pop {r2, r3} /* lr goes in r3. r2 now holds tcb pointer. */ + + ldr r1, [r2] + ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */ + adds r0, r0, #16 /* Move to the high registers. */ + ldmia r0!, {r4-r7} /* Pop the high registers. */ + mov r8, r4 + mov r9, r5 + mov r10, r6 + mov r11, r7 + + msr psp, r0 /* Remember the new top of stack for the task. */ + + subs r0, r0, #32 /* Go back for the low registers that are not automatically restored. */ + ldmia r0!, {r4-r7} /* Pop low registers. */ + + bx r3 + +/*-----------------------------------------------------------*/ + +vPortSVCHandler; + /* This function is no longer used, but retained for backward + compatibility. */ + bx lr + +/*-----------------------------------------------------------*/ + +vPortStartFirstTask + /* The MSP stack is not reset as, unlike on M3/4 parts, there is no vector + table offset register that can be used to locate the initial stack value. + Not all M0 parts have the application vector table at address 0. */ + + ldr r3, =pxCurrentTCB /* Obtain location of pxCurrentTCB. */ + ldr r1, [r3] + ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */ + adds r0, #32 /* Discard everything up to r0. */ + msr psp, r0 /* This is now the new top of stack to use in the task. */ + movs r0, #2 /* Switch to the psp stack. */ + msr CONTROL, r0 + isb + pop {r0-r5} /* Pop the registers that are saved automatically. */ + mov lr, r5 /* lr is now in r5. */ + pop {r3} /* The return address is now in r3. */ + pop {r2} /* Pop and discard the XPSR. */ + cpsie i /* The first task has its context and interrupts can be enabled. */ + bx r3 /* Jump to the user defined task code. */ + +/*-----------------------------------------------------------*/ + +ulSetInterruptMaskFromISR + mrs r0, PRIMASK + cpsid i + bx lr + +/*-----------------------------------------------------------*/ + +vClearInterruptMaskFromISR + msr PRIMASK, r0 + bx lr + + END diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM0/portmacro.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM0/portmacro.h new file mode 100644 index 0000000..02e2cbd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM0/portmacro.h @@ -0,0 +1,128 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + + +#ifndef PORTMACRO_H +#define PORTMACRO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*----------------------------------------------------------- + * Port specific definitions. + * + * The settings in this file configure FreeRTOS correctly for the + * given hardware and compiler. + * + * These settings should not be altered. + *----------------------------------------------------------- + */ + +/* Type definitions. */ +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT short +#define portSTACK_TYPE uint32_t +#define portBASE_TYPE long + +typedef portSTACK_TYPE StackType_t; +typedef long BaseType_t; +typedef unsigned long UBaseType_t; + + +#if( configUSE_16_BIT_TICKS == 1 ) + typedef uint16_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffff +#else + typedef uint32_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffffffffUL + + /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do + not need to be guarded with a critical section. */ + #define portTICK_TYPE_IS_ATOMIC 1 +#endif +/*-----------------------------------------------------------*/ + +/* Architecture specifics. */ +#define portSTACK_GROWTH ( -1 ) +#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) +#define portBYTE_ALIGNMENT 8 +/*-----------------------------------------------------------*/ + + +/* Scheduler utilities. */ +extern void vPortYield( void ); +#define portNVIC_INT_CTRL ( ( volatile uint32_t *) 0xe000ed04 ) +#define portNVIC_PENDSVSET 0x10000000 +#define portYIELD() vPortYield() +#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET +#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) +/*-----------------------------------------------------------*/ + + +/* Critical section management. */ + +extern void vPortEnterCritical( void ); +extern void vPortExitCritical( void ); +extern uint32_t ulSetInterruptMaskFromISR( void ); +extern void vClearInterruptMaskFromISR( uint32_t ulMask ); + +#define portDISABLE_INTERRUPTS() __asm volatile( "cpsid i" ) +#define portENABLE_INTERRUPTS() __asm volatile( "cpsie i" ) +#define portENTER_CRITICAL() vPortEnterCritical() +#define portEXIT_CRITICAL() vPortExitCritical() +#define portSET_INTERRUPT_MASK_FROM_ISR() ulSetInterruptMaskFromISR() +#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vClearInterruptMaskFromISR( x ) + +/*-----------------------------------------------------------*/ + +/* Tickless idle/low power functionality. */ +#ifndef portSUPPRESS_TICKS_AND_SLEEP + extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ); + #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime ) +#endif +/*-----------------------------------------------------------*/ +/* Task function macros as described on the FreeRTOS.org WEB site. */ +#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) +#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) + +#define portNOP() + +/* Suppress warnings that are generated by the IAR tools, but cannot be fixed in +the source code because to do so would cause other compilers to generate +warnings. */ +#pragma diag_suppress=Pa082 + +#ifdef __cplusplus +} +#endif + +#endif /* PORTMACRO_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/Keil/See-also-the-RVDS-directory.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/Keil/See-also-the-RVDS-directory.txt new file mode 100644 index 0000000..bd7fab7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/Keil/See-also-the-RVDS-directory.txt @@ -0,0 +1 @@ +Nothing to see here. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/ReadMe.url b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/ReadMe.url new file mode 100644 index 0000000..6c23737 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/ReadMe.url @@ -0,0 +1,5 @@ +[{000214A0-0000-0000-C000-000000000046}] +Prop3=19,2 +[InternetShortcut] +URL=http://www.freertos.org/a00111.html +IDList= diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_1.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_1.c new file mode 100644 index 0000000..7ff6dfa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_1.c @@ -0,0 +1,147 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + + +/* + * The simplest possible implementation of pvPortMalloc(). Note that this + * implementation does NOT allow allocated memory to be freed again. + * + * See heap_2.c, heap_3.c and heap_4.c for alternative implementations, and the + * memory management pages of http://www.FreeRTOS.org for more information. + */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#endif + +/* A few bytes might be lost to byte aligning the heap start address. */ +#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) + +/* Allocate the memory for the heap. */ +/* Allocate the memory for the heap. */ +#if( configAPPLICATION_ALLOCATED_HEAP == 1 ) + /* The application writer has already defined the array used for the RTOS + heap - probably so it can be placed in a special segment or address. */ + extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#else + static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#endif /* configAPPLICATION_ALLOCATED_HEAP */ + +/* Index into the ucHeap array. */ +static size_t xNextFreeByte = ( size_t ) 0; + +/*-----------------------------------------------------------*/ + +void *pvPortMalloc( size_t xWantedSize ) +{ +void *pvReturn = NULL; +static uint8_t *pucAlignedHeap = NULL; + + /* Ensure that blocks are always aligned to the required number of bytes. */ + #if( portBYTE_ALIGNMENT != 1 ) + { + if( xWantedSize & portBYTE_ALIGNMENT_MASK ) + { + /* Byte alignment required. */ + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); + } + } + #endif + + vTaskSuspendAll(); + { + if( pucAlignedHeap == NULL ) + { + /* Ensure the heap starts on a correctly aligned boundary. */ + pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); + } + + /* Check there is enough room left for the allocation. */ + if( ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) && + ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */ + { + /* Return the next free byte then increment the index past this + block. */ + pvReturn = pucAlignedHeap + xNextFreeByte; + xNextFreeByte += xWantedSize; + } + + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + } + #endif + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void *pv ) +{ + /* Memory cannot be freed using this scheme. See heap_2.c, heap_3.c and + heap_4.c for alternative implementations, and the memory management pages of + http://www.FreeRTOS.org for more information. */ + ( void ) pv; + + /* Force an assert as it is invalid to call this function. */ + configASSERT( pv == NULL ); +} +/*-----------------------------------------------------------*/ + +void vPortInitialiseBlocks( void ) +{ + /* Only required when static memory is not cleared. */ + xNextFreeByte = ( size_t ) 0; +} +/*-----------------------------------------------------------*/ + +size_t xPortGetFreeHeapSize( void ) +{ + return ( configADJUSTED_HEAP_SIZE - xNextFreeByte ); +} + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_2.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_2.c new file mode 100644 index 0000000..941b4f2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_2.c @@ -0,0 +1,272 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* + * A sample implementation of pvPortMalloc() and vPortFree() that permits + * allocated blocks to be freed, but does not combine adjacent free blocks + * into a single larger block (and so will fragment memory). See heap_4.c for + * an equivalent that does combine adjacent blocks into single larger blocks. + * + * See heap_1.c, heap_3.c and heap_4.c for alternative implementations, and the + * memory management pages of http://www.FreeRTOS.org for more information. + */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#endif + +/* A few bytes might be lost to byte aligning the heap start address. */ +#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) + +/* + * Initialises the heap structures before their first use. + */ +static void prvHeapInit( void ); + +/* Allocate the memory for the heap. */ +#if( configAPPLICATION_ALLOCATED_HEAP == 1 ) + /* The application writer has already defined the array used for the RTOS + heap - probably so it can be placed in a special segment or address. */ + extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#else + static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#endif /* configAPPLICATION_ALLOCATED_HEAP */ + + +/* Define the linked list structure. This is used to link free blocks in order +of their size. */ +typedef struct A_BLOCK_LINK +{ + struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */ + size_t xBlockSize; /*<< The size of the free block. */ +} BlockLink_t; + + +static const uint16_t heapSTRUCT_SIZE = ( ( sizeof ( BlockLink_t ) + ( portBYTE_ALIGNMENT - 1 ) ) & ~portBYTE_ALIGNMENT_MASK ); +#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) ) + +/* Create a couple of list links to mark the start and end of the list. */ +static BlockLink_t xStart, xEnd; + +/* Keeps track of the number of free bytes remaining, but says nothing about +fragmentation. */ +static size_t xFreeBytesRemaining = configADJUSTED_HEAP_SIZE; + +/* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */ + +/* + * Insert a block into the list of free blocks - which is ordered by size of + * the block. Small blocks at the start of the list and large blocks at the end + * of the list. + */ +#define prvInsertBlockIntoFreeList( pxBlockToInsert ) \ +{ \ +BlockLink_t *pxIterator; \ +size_t xBlockSize; \ + \ + xBlockSize = pxBlockToInsert->xBlockSize; \ + \ + /* Iterate through the list until a block is found that has a larger size */ \ + /* than the block we are inserting. */ \ + for( pxIterator = &xStart; pxIterator->pxNextFreeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextFreeBlock ) \ + { \ + /* There is nothing to do here - just iterate to the correct position. */ \ + } \ + \ + /* Update the list to include the block being inserted in the correct */ \ + /* position. */ \ + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; \ + pxIterator->pxNextFreeBlock = pxBlockToInsert; \ +} +/*-----------------------------------------------------------*/ + +void *pvPortMalloc( size_t xWantedSize ) +{ +BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink; +static BaseType_t xHeapHasBeenInitialised = pdFALSE; +void *pvReturn = NULL; + + vTaskSuspendAll(); + { + /* If this is the first call to malloc then the heap will require + initialisation to setup the list of free blocks. */ + if( xHeapHasBeenInitialised == pdFALSE ) + { + prvHeapInit(); + xHeapHasBeenInitialised = pdTRUE; + } + + /* The wanted size is increased so it can contain a BlockLink_t + structure in addition to the requested amount of bytes. */ + if( xWantedSize > 0 ) + { + xWantedSize += heapSTRUCT_SIZE; + + /* Ensure that blocks are always aligned to the required number of bytes. */ + if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0 ) + { + /* Byte alignment required. */ + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); + } + } + + if( ( xWantedSize > 0 ) && ( xWantedSize < configADJUSTED_HEAP_SIZE ) ) + { + /* Blocks are stored in byte order - traverse the list from the start + (smallest) block until one of adequate size is found. */ + pxPreviousBlock = &xStart; + pxBlock = xStart.pxNextFreeBlock; + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) + { + pxPreviousBlock = pxBlock; + pxBlock = pxBlock->pxNextFreeBlock; + } + + /* If we found the end marker then a block of adequate size was not found. */ + if( pxBlock != &xEnd ) + { + /* Return the memory space - jumping over the BlockLink_t structure + at its start. */ + pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE ); + + /* This block is being returned for use so must be taken out of the + list of free blocks. */ + pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; + + /* If the block is larger than required it can be split into two. */ + if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) + { + /* This block is to be split into two. Create a new block + following the number of bytes requested. The void cast is + used to prevent byte alignment warnings from the compiler. */ + pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize ); + + /* Calculate the sizes of two blocks split from the single + block. */ + pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; + pxBlock->xBlockSize = xWantedSize; + + /* Insert the new block into the list of free blocks. */ + prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); + } + + xFreeBytesRemaining -= pxBlock->xBlockSize; + } + } + + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + } + #endif + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void *pv ) +{ +uint8_t *puc = ( uint8_t * ) pv; +BlockLink_t *pxLink; + + if( pv != NULL ) + { + /* The memory being freed will have an BlockLink_t structure immediately + before it. */ + puc -= heapSTRUCT_SIZE; + + /* This unexpected casting is to keep some compilers from issuing + byte alignment warnings. */ + pxLink = ( void * ) puc; + + vTaskSuspendAll(); + { + /* Add this block to the list of free blocks. */ + prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) ); + xFreeBytesRemaining += pxLink->xBlockSize; + traceFREE( pv, pxLink->xBlockSize ); + } + ( void ) xTaskResumeAll(); + } +} +/*-----------------------------------------------------------*/ + +size_t xPortGetFreeHeapSize( void ) +{ + return xFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +void vPortInitialiseBlocks( void ) +{ + /* This just exists to keep the linker quiet. */ +} +/*-----------------------------------------------------------*/ + +static void prvHeapInit( void ) +{ +BlockLink_t *pxFirstFreeBlock; +uint8_t *pucAlignedHeap; + + /* Ensure the heap starts on a correctly aligned boundary. */ + pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); + + /* xStart is used to hold a pointer to the first item in the list of free + blocks. The void cast is used to prevent compiler warnings. */ + xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap; + xStart.xBlockSize = ( size_t ) 0; + + /* xEnd is used to mark the end of the list of free blocks. */ + xEnd.xBlockSize = configADJUSTED_HEAP_SIZE; + xEnd.pxNextFreeBlock = NULL; + + /* To start with there is a single free block that is sized to take up the + entire heap space. */ + pxFirstFreeBlock = ( void * ) pucAlignedHeap; + pxFirstFreeBlock->xBlockSize = configADJUSTED_HEAP_SIZE; + pxFirstFreeBlock->pxNextFreeBlock = &xEnd; +} +/*-----------------------------------------------------------*/ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_3.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_3.c new file mode 100644 index 0000000..c8c3f54 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_3.c @@ -0,0 +1,97 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + + +/* + * Implementation of pvPortMalloc() and vPortFree() that relies on the + * compilers own malloc() and free() implementations. + * + * This file can only be used if the linker is configured to to generate + * a heap memory area. + * + * See heap_1.c, heap_2.c and heap_4.c for alternative implementations, and the + * memory management pages of http://www.FreeRTOS.org for more information. + */ + +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#endif + +/*-----------------------------------------------------------*/ + +void *pvPortMalloc( size_t xWantedSize ) +{ +void *pvReturn; + + vTaskSuspendAll(); + { + pvReturn = malloc( xWantedSize ); + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + } + #endif + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void *pv ) +{ + if( pv ) + { + vTaskSuspendAll(); + { + free( pv ); + traceFREE( pv, 0 ); + } + ( void ) xTaskResumeAll(); + } +} + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c new file mode 100644 index 0000000..94bf5bb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c @@ -0,0 +1,436 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* + * A sample implementation of pvPortMalloc() and vPortFree() that combines + * (coalescences) adjacent memory blocks as they are freed, and in so doing + * limits memory fragmentation. + * + * See heap_1.c, heap_2.c and heap_3.c for alternative implementations, and the + * memory management pages of http://www.FreeRTOS.org for more information. + */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#endif + +/* Block sizes must not get too small. */ +#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) ) + +/* Assumes 8bit bytes! */ +#define heapBITS_PER_BYTE ( ( size_t ) 8 ) + +/* Allocate the memory for the heap. */ +#if( configAPPLICATION_ALLOCATED_HEAP == 1 ) + /* The application writer has already defined the array used for the RTOS + heap - probably so it can be placed in a special segment or address. */ + extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#else + static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#endif /* configAPPLICATION_ALLOCATED_HEAP */ + +/* Define the linked list structure. This is used to link free blocks in order +of their memory address. */ +typedef struct A_BLOCK_LINK +{ + struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */ + size_t xBlockSize; /*<< The size of the free block. */ +} BlockLink_t; + +/*-----------------------------------------------------------*/ + +/* + * Inserts a block of memory that is being freed into the correct position in + * the list of free memory blocks. The block being freed will be merged with + * the block in front it and/or the block behind it if the memory blocks are + * adjacent to each other. + */ +static void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert ); + +/* + * Called automatically to setup the required heap structures the first time + * pvPortMalloc() is called. + */ +static void prvHeapInit( void ); + +/*-----------------------------------------------------------*/ + +/* The size of the structure placed at the beginning of each allocated memory +block must by correctly byte aligned. */ +static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); + +/* Create a couple of list links to mark the start and end of the list. */ +static BlockLink_t xStart, *pxEnd = NULL; + +/* Keeps track of the number of free bytes remaining, but says nothing about +fragmentation. */ +static size_t xFreeBytesRemaining = 0U; +static size_t xMinimumEverFreeBytesRemaining = 0U; + +/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize +member of an BlockLink_t structure is set then the block belongs to the +application. When the bit is free the block is still part of the free heap +space. */ +static size_t xBlockAllocatedBit = 0; + +/*-----------------------------------------------------------*/ + +void *pvPortMalloc( size_t xWantedSize ) +{ +BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink; +void *pvReturn = NULL; + + vTaskSuspendAll(); + { + /* If this is the first call to malloc then the heap will require + initialisation to setup the list of free blocks. */ + if( pxEnd == NULL ) + { + prvHeapInit(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Check the requested block size is not so large that the top bit is + set. The top bit of the block size member of the BlockLink_t structure + is used to determine who owns the block - the application or the + kernel, so it must be free. */ + if( ( xWantedSize & xBlockAllocatedBit ) == 0 ) + { + /* The wanted size is increased so it can contain a BlockLink_t + structure in addition to the requested amount of bytes. */ + if( xWantedSize > 0 ) + { + xWantedSize += xHeapStructSize; + + /* Ensure that blocks are always aligned to the required number + of bytes. */ + if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 ) + { + /* Byte alignment required. */ + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); + configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) ) + { + /* Traverse the list from the start (lowest address) block until + one of adequate size is found. */ + pxPreviousBlock = &xStart; + pxBlock = xStart.pxNextFreeBlock; + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) + { + pxPreviousBlock = pxBlock; + pxBlock = pxBlock->pxNextFreeBlock; + } + + /* If the end marker was reached then a block of adequate size + was not found. */ + if( pxBlock != pxEnd ) + { + /* Return the memory space pointed to - jumping over the + BlockLink_t structure at its start. */ + pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize ); + + /* This block is being returned for use so must be taken out + of the list of free blocks. */ + pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; + + /* If the block is larger than required it can be split into + two. */ + if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) + { + /* This block is to be split into two. Create a new + block following the number of bytes requested. The void + cast is used to prevent byte alignment warnings from the + compiler. */ + pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize ); + configASSERT( ( ( ( size_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 ); + + /* Calculate the sizes of two blocks split from the + single block. */ + pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; + pxBlock->xBlockSize = xWantedSize; + + /* Insert the new block into the list of free blocks. */ + prvInsertBlockIntoFreeList( pxNewBlockLink ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xFreeBytesRemaining -= pxBlock->xBlockSize; + + if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining ) + { + xMinimumEverFreeBytesRemaining = xFreeBytesRemaining; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* The block is being returned - it is allocated and owned + by the application and has no "next" block. */ + pxBlock->xBlockSize |= xBlockAllocatedBit; + pxBlock->pxNextFreeBlock = NULL; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif + + configASSERT( ( ( ( size_t ) pvReturn ) & ( size_t ) portBYTE_ALIGNMENT_MASK ) == 0 ); + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void *pv ) +{ +uint8_t *puc = ( uint8_t * ) pv; +BlockLink_t *pxLink; + + if( pv != NULL ) + { + /* The memory being freed will have an BlockLink_t structure immediately + before it. */ + puc -= xHeapStructSize; + + /* This casting is to keep the compiler from issuing warnings. */ + pxLink = ( void * ) puc; + + /* Check the block is actually allocated. */ + configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ); + configASSERT( pxLink->pxNextFreeBlock == NULL ); + + if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ) + { + if( pxLink->pxNextFreeBlock == NULL ) + { + /* The block is being returned to the heap - it is no longer + allocated. */ + pxLink->xBlockSize &= ~xBlockAllocatedBit; + + vTaskSuspendAll(); + { + /* Add this block to the list of free blocks. */ + xFreeBytesRemaining += pxLink->xBlockSize; + traceFREE( pv, pxLink->xBlockSize ); + prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) ); + } + ( void ) xTaskResumeAll(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } +} +/*-----------------------------------------------------------*/ + +size_t xPortGetFreeHeapSize( void ) +{ + return xFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +size_t xPortGetMinimumEverFreeHeapSize( void ) +{ + return xMinimumEverFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +void vPortInitialiseBlocks( void ) +{ + /* This just exists to keep the linker quiet. */ +} +/*-----------------------------------------------------------*/ + +static void prvHeapInit( void ) +{ +BlockLink_t *pxFirstFreeBlock; +uint8_t *pucAlignedHeap; +size_t uxAddress; +size_t xTotalHeapSize = configTOTAL_HEAP_SIZE; + + /* Ensure the heap starts on a correctly aligned boundary. */ + uxAddress = ( size_t ) ucHeap; + + if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 ) + { + uxAddress += ( portBYTE_ALIGNMENT - 1 ); + uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); + xTotalHeapSize -= uxAddress - ( size_t ) ucHeap; + } + + pucAlignedHeap = ( uint8_t * ) uxAddress; + + /* xStart is used to hold a pointer to the first item in the list of free + blocks. The void cast is used to prevent compiler warnings. */ + xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap; + xStart.xBlockSize = ( size_t ) 0; + + /* pxEnd is used to mark the end of the list of free blocks and is inserted + at the end of the heap space. */ + uxAddress = ( ( size_t ) pucAlignedHeap ) + xTotalHeapSize; + uxAddress -= xHeapStructSize; + uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); + pxEnd = ( void * ) uxAddress; + pxEnd->xBlockSize = 0; + pxEnd->pxNextFreeBlock = NULL; + + /* To start with there is a single free block that is sized to take up the + entire heap space, minus the space taken by pxEnd. */ + pxFirstFreeBlock = ( void * ) pucAlignedHeap; + pxFirstFreeBlock->xBlockSize = uxAddress - ( size_t ) pxFirstFreeBlock; + pxFirstFreeBlock->pxNextFreeBlock = pxEnd; + + /* Only one block exists - and it covers the entire usable heap space. */ + xMinimumEverFreeBytesRemaining = pxFirstFreeBlock->xBlockSize; + xFreeBytesRemaining = pxFirstFreeBlock->xBlockSize; + + /* Work out the position of the top bit in a size_t variable. */ + xBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 ); +} +/*-----------------------------------------------------------*/ + +static void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert ) +{ +BlockLink_t *pxIterator; +uint8_t *puc; + + /* Iterate through the list until a block is found that has a higher address + than the block being inserted. */ + for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock ) + { + /* Nothing to do here, just iterate to the right position. */ + } + + /* Do the block being inserted, and the block it is being inserted after + make a contiguous block of memory? */ + puc = ( uint8_t * ) pxIterator; + if( ( puc + pxIterator->xBlockSize ) == ( uint8_t * ) pxBlockToInsert ) + { + pxIterator->xBlockSize += pxBlockToInsert->xBlockSize; + pxBlockToInsert = pxIterator; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Do the block being inserted, and the block it is being inserted before + make a contiguous block of memory? */ + puc = ( uint8_t * ) pxBlockToInsert; + if( ( puc + pxBlockToInsert->xBlockSize ) == ( uint8_t * ) pxIterator->pxNextFreeBlock ) + { + if( pxIterator->pxNextFreeBlock != pxEnd ) + { + /* Form one big block from the two blocks. */ + pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize; + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock; + } + else + { + pxBlockToInsert->pxNextFreeBlock = pxEnd; + } + } + else + { + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; + } + + /* If the block being inserted plugged a gab, so was merged with the block + before and the block after, then it's pxNextFreeBlock pointer will have + already been set, and should not be set here as that would make it point + to itself. */ + if( pxIterator != pxBlockToInsert ) + { + pxIterator->pxNextFreeBlock = pxBlockToInsert; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } +} + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_5.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_5.c new file mode 100644 index 0000000..51c53a9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_5.c @@ -0,0 +1,485 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* + * A sample implementation of pvPortMalloc() that allows the heap to be defined + * across multiple non-contigous blocks and combines (coalescences) adjacent + * memory blocks as they are freed. + * + * See heap_1.c, heap_2.c, heap_3.c and heap_4.c for alternative + * implementations, and the memory management pages of http://www.FreeRTOS.org + * for more information. + * + * Usage notes: + * + * vPortDefineHeapRegions() ***must*** be called before pvPortMalloc(). + * pvPortMalloc() will be called if any task objects (tasks, queues, event + * groups, etc.) are created, therefore vPortDefineHeapRegions() ***must*** be + * called before any other objects are defined. + * + * vPortDefineHeapRegions() takes a single parameter. The parameter is an array + * of HeapRegion_t structures. HeapRegion_t is defined in portable.h as + * + * typedef struct HeapRegion + * { + * uint8_t *pucStartAddress; << Start address of a block of memory that will be part of the heap. + * size_t xSizeInBytes; << Size of the block of memory. + * } HeapRegion_t; + * + * The array is terminated using a NULL zero sized region definition, and the + * memory regions defined in the array ***must*** appear in address order from + * low address to high address. So the following is a valid example of how + * to use the function. + * + * HeapRegion_t xHeapRegions[] = + * { + * { ( uint8_t * ) 0x80000000UL, 0x10000 }, << Defines a block of 0x10000 bytes starting at address 0x80000000 + * { ( uint8_t * ) 0x90000000UL, 0xa0000 }, << Defines a block of 0xa0000 bytes starting at address of 0x90000000 + * { NULL, 0 } << Terminates the array. + * }; + * + * vPortDefineHeapRegions( xHeapRegions ); << Pass the array into vPortDefineHeapRegions(). + * + * Note 0x80000000 is the lower address so appears in the array first. + * + */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#endif + +/* Block sizes must not get too small. */ +#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) ) + +/* Assumes 8bit bytes! */ +#define heapBITS_PER_BYTE ( ( size_t ) 8 ) + +/* Define the linked list structure. This is used to link free blocks in order +of their memory address. */ +typedef struct A_BLOCK_LINK +{ + struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */ + size_t xBlockSize; /*<< The size of the free block. */ +} BlockLink_t; + +/*-----------------------------------------------------------*/ + +/* + * Inserts a block of memory that is being freed into the correct position in + * the list of free memory blocks. The block being freed will be merged with + * the block in front it and/or the block behind it if the memory blocks are + * adjacent to each other. + */ +static void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert ); + +/*-----------------------------------------------------------*/ + +/* The size of the structure placed at the beginning of each allocated memory +block must by correctly byte aligned. */ +static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); + +/* Create a couple of list links to mark the start and end of the list. */ +static BlockLink_t xStart, *pxEnd = NULL; + +/* Keeps track of the number of free bytes remaining, but says nothing about +fragmentation. */ +static size_t xFreeBytesRemaining = 0U; +static size_t xMinimumEverFreeBytesRemaining = 0U; + +/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize +member of an BlockLink_t structure is set then the block belongs to the +application. When the bit is free the block is still part of the free heap +space. */ +static size_t xBlockAllocatedBit = 0; + +/*-----------------------------------------------------------*/ + +void *pvPortMalloc( size_t xWantedSize ) +{ +BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink; +void *pvReturn = NULL; + + /* The heap must be initialised before the first call to + prvPortMalloc(). */ + configASSERT( pxEnd ); + + vTaskSuspendAll(); + { + /* Check the requested block size is not so large that the top bit is + set. The top bit of the block size member of the BlockLink_t structure + is used to determine who owns the block - the application or the + kernel, so it must be free. */ + if( ( xWantedSize & xBlockAllocatedBit ) == 0 ) + { + /* The wanted size is increased so it can contain a BlockLink_t + structure in addition to the requested amount of bytes. */ + if( xWantedSize > 0 ) + { + xWantedSize += xHeapStructSize; + + /* Ensure that blocks are always aligned to the required number + of bytes. */ + if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 ) + { + /* Byte alignment required. */ + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) ) + { + /* Traverse the list from the start (lowest address) block until + one of adequate size is found. */ + pxPreviousBlock = &xStart; + pxBlock = xStart.pxNextFreeBlock; + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) + { + pxPreviousBlock = pxBlock; + pxBlock = pxBlock->pxNextFreeBlock; + } + + /* If the end marker was reached then a block of adequate size + was not found. */ + if( pxBlock != pxEnd ) + { + /* Return the memory space pointed to - jumping over the + BlockLink_t structure at its start. */ + pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize ); + + /* This block is being returned for use so must be taken out + of the list of free blocks. */ + pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; + + /* If the block is larger than required it can be split into + two. */ + if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) + { + /* This block is to be split into two. Create a new + block following the number of bytes requested. The void + cast is used to prevent byte alignment warnings from the + compiler. */ + pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize ); + + /* Calculate the sizes of two blocks split from the + single block. */ + pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; + pxBlock->xBlockSize = xWantedSize; + + /* Insert the new block into the list of free blocks. */ + prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xFreeBytesRemaining -= pxBlock->xBlockSize; + + if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining ) + { + xMinimumEverFreeBytesRemaining = xFreeBytesRemaining; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* The block is being returned - it is allocated and owned + by the application and has no "next" block. */ + pxBlock->xBlockSize |= xBlockAllocatedBit; + pxBlock->pxNextFreeBlock = NULL; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void *pv ) +{ +uint8_t *puc = ( uint8_t * ) pv; +BlockLink_t *pxLink; + + if( pv != NULL ) + { + /* The memory being freed will have an BlockLink_t structure immediately + before it. */ + puc -= xHeapStructSize; + + /* This casting is to keep the compiler from issuing warnings. */ + pxLink = ( void * ) puc; + + /* Check the block is actually allocated. */ + configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ); + configASSERT( pxLink->pxNextFreeBlock == NULL ); + + if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ) + { + if( pxLink->pxNextFreeBlock == NULL ) + { + /* The block is being returned to the heap - it is no longer + allocated. */ + pxLink->xBlockSize &= ~xBlockAllocatedBit; + + vTaskSuspendAll(); + { + /* Add this block to the list of free blocks. */ + xFreeBytesRemaining += pxLink->xBlockSize; + traceFREE( pv, pxLink->xBlockSize ); + prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) ); + } + ( void ) xTaskResumeAll(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } +} +/*-----------------------------------------------------------*/ + +size_t xPortGetFreeHeapSize( void ) +{ + return xFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +size_t xPortGetMinimumEverFreeHeapSize( void ) +{ + return xMinimumEverFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +static void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert ) +{ +BlockLink_t *pxIterator; +uint8_t *puc; + + /* Iterate through the list until a block is found that has a higher address + than the block being inserted. */ + for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock ) + { + /* Nothing to do here, just iterate to the right position. */ + } + + /* Do the block being inserted, and the block it is being inserted after + make a contiguous block of memory? */ + puc = ( uint8_t * ) pxIterator; + if( ( puc + pxIterator->xBlockSize ) == ( uint8_t * ) pxBlockToInsert ) + { + pxIterator->xBlockSize += pxBlockToInsert->xBlockSize; + pxBlockToInsert = pxIterator; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Do the block being inserted, and the block it is being inserted before + make a contiguous block of memory? */ + puc = ( uint8_t * ) pxBlockToInsert; + if( ( puc + pxBlockToInsert->xBlockSize ) == ( uint8_t * ) pxIterator->pxNextFreeBlock ) + { + if( pxIterator->pxNextFreeBlock != pxEnd ) + { + /* Form one big block from the two blocks. */ + pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize; + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock; + } + else + { + pxBlockToInsert->pxNextFreeBlock = pxEnd; + } + } + else + { + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; + } + + /* If the block being inserted plugged a gab, so was merged with the block + before and the block after, then it's pxNextFreeBlock pointer will have + already been set, and should not be set here as that would make it point + to itself. */ + if( pxIterator != pxBlockToInsert ) + { + pxIterator->pxNextFreeBlock = pxBlockToInsert; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } +} +/*-----------------------------------------------------------*/ + +void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) +{ +BlockLink_t *pxFirstFreeBlockInRegion = NULL, *pxPreviousFreeBlock; +size_t xAlignedHeap; +size_t xTotalRegionSize, xTotalHeapSize = 0; +BaseType_t xDefinedRegions = 0; +size_t xAddress; +const HeapRegion_t *pxHeapRegion; + + /* Can only call once! */ + configASSERT( pxEnd == NULL ); + + pxHeapRegion = &( pxHeapRegions[ xDefinedRegions ] ); + + while( pxHeapRegion->xSizeInBytes > 0 ) + { + xTotalRegionSize = pxHeapRegion->xSizeInBytes; + + /* Ensure the heap region starts on a correctly aligned boundary. */ + xAddress = ( size_t ) pxHeapRegion->pucStartAddress; + if( ( xAddress & portBYTE_ALIGNMENT_MASK ) != 0 ) + { + xAddress += ( portBYTE_ALIGNMENT - 1 ); + xAddress &= ~portBYTE_ALIGNMENT_MASK; + + /* Adjust the size for the bytes lost to alignment. */ + xTotalRegionSize -= xAddress - ( size_t ) pxHeapRegion->pucStartAddress; + } + + xAlignedHeap = xAddress; + + /* Set xStart if it has not already been set. */ + if( xDefinedRegions == 0 ) + { + /* xStart is used to hold a pointer to the first item in the list of + free blocks. The void cast is used to prevent compiler warnings. */ + xStart.pxNextFreeBlock = ( BlockLink_t * ) xAlignedHeap; + xStart.xBlockSize = ( size_t ) 0; + } + else + { + /* Should only get here if one region has already been added to the + heap. */ + configASSERT( pxEnd != NULL ); + + /* Check blocks are passed in with increasing start addresses. */ + configASSERT( xAddress > ( size_t ) pxEnd ); + } + + /* Remember the location of the end marker in the previous region, if + any. */ + pxPreviousFreeBlock = pxEnd; + + /* pxEnd is used to mark the end of the list of free blocks and is + inserted at the end of the region space. */ + xAddress = xAlignedHeap + xTotalRegionSize; + xAddress -= xHeapStructSize; + xAddress &= ~portBYTE_ALIGNMENT_MASK; + pxEnd = ( BlockLink_t * ) xAddress; + pxEnd->xBlockSize = 0; + pxEnd->pxNextFreeBlock = NULL; + + /* To start with there is a single free block in this region that is + sized to take up the entire heap region minus the space taken by the + free block structure. */ + pxFirstFreeBlockInRegion = ( BlockLink_t * ) xAlignedHeap; + pxFirstFreeBlockInRegion->xBlockSize = xAddress - ( size_t ) pxFirstFreeBlockInRegion; + pxFirstFreeBlockInRegion->pxNextFreeBlock = pxEnd; + + /* If this is not the first region that makes up the entire heap space + then link the previous region to this region. */ + if( pxPreviousFreeBlock != NULL ) + { + pxPreviousFreeBlock->pxNextFreeBlock = pxFirstFreeBlockInRegion; + } + + xTotalHeapSize += pxFirstFreeBlockInRegion->xBlockSize; + + /* Move onto the next HeapRegion_t structure. */ + xDefinedRegions++; + pxHeapRegion = &( pxHeapRegions[ xDefinedRegions ] ); + } + + xMinimumEverFreeBytesRemaining = xTotalHeapSize; + xFreeBytesRemaining = xTotalHeapSize; + + /* Check something was actually defined before it is accessed. */ + configASSERT( xTotalHeapSize ); + + /* Work out the position of the top bit in a size_t variable. */ + xBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 ); +} + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM0/port.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM0/port.c new file mode 100644 index 0000000..37eff67 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM0/port.c @@ -0,0 +1,510 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/*----------------------------------------------------------- + * Implementation of functions defined in portable.h for the ARM CM0 port. + *----------------------------------------------------------*/ + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "task.h" + +#ifndef configSYSTICK_CLOCK_HZ + #define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ +#endif + +/* Constants required to manipulate the NVIC. */ +#define portNVIC_SYSTICK_CTRL ( *( ( volatile uint32_t *) 0xe000e010 )) +#define portNVIC_SYSTICK_LOAD ( *( ( volatile uint32_t *) 0xe000e014 )) +#define portNVIC_SYSTICK_CURRENT_VALUE ( * ( ( volatile uint32_t * ) 0xe000e018 ) ) +#define portNVIC_INT_CTRL ( ( volatile uint32_t *) 0xe000ed04 ) +#define portNVIC_SYSPRI2 ( ( volatile uint32_t *) 0xe000ed20 ) +#define portNVIC_SYSTICK_CLK 0x00000004 +#define portNVIC_SYSTICK_INT 0x00000002 +#define portNVIC_SYSTICK_ENABLE 0x00000001 +#define portNVIC_SYSTICK_COUNT_FLAG ( 1UL << 16UL ) +#define portNVIC_PENDSVSET 0x10000000 +#define portMIN_INTERRUPT_PRIORITY ( 255UL ) +#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL ) +#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL ) + +/* Constants required to set up the initial stack. */ +#define portINITIAL_XPSR ( 0x01000000 ) + +/* Constants used with memory barrier intrinsics. */ +#define portSY_FULL_READ_WRITE ( 15 ) + +/* The systick is a 24-bit counter. */ +#define portMAX_24_BIT_NUMBER ( 0xffffffUL ) + +/* A fiddle factor to estimate the number of SysTick counts that would have +occurred while the SysTick counter is stopped during tickless idle +calculations. */ +#define portMISSED_COUNTS_FACTOR ( 45UL ) + +/* Each task maintains its own interrupt status in the critical nesting +variable. */ +static UBaseType_t uxCriticalNesting = 0xaaaaaaaa; + +/* + * Setup the timer to generate the tick interrupts. + */ +static void prvSetupTimerInterrupt( void ); + +/* + * Exception handlers. + */ +void xPortPendSVHandler( void ); +void xPortSysTickHandler( void ); +void vPortSVCHandler( void ); + +/* + * Start first task is a separate function so it can be tested in isolation. + */ +static void prvPortStartFirstTask( void ); + +/* + * Used to catch tasks that attempt to return from their implementing function. + */ +static void prvTaskExitError( void ); + +/*-----------------------------------------------------------*/ + +/* + * The number of SysTick increments that make up one tick period. + */ +#if configUSE_TICKLESS_IDLE == 1 + static unsigned long ulTimerCountsForOneTick = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* + * The maximum number of tick periods that can be suppressed is limited by the + * 24 bit resolution of the SysTick timer. + */ +#if configUSE_TICKLESS_IDLE == 1 + static unsigned long xMaximumPossibleSuppressedTicks = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* + * Compensate for the CPU cycles that pass while the SysTick is stopped (low + * power functionality only. + */ +#if configUSE_TICKLESS_IDLE == 1 + static unsigned long ulStoppedTimerCompensation = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* + * See header file for description. + */ +StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) +{ + /* Simulate the stack frame as it would be created by a context switch + interrupt. */ + pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts. */ + *pxTopOfStack = portINITIAL_XPSR; /* xPSR */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) pxCode; /* PC */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) prvTaskExitError; /* LR */ + pxTopOfStack -= 5; /* R12, R3, R2 and R1. */ + *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */ + pxTopOfStack -= 8; /* R11..R4. */ + + return pxTopOfStack; +} +/*-----------------------------------------------------------*/ + +static void prvTaskExitError( void ) +{ + /* A function that implements a task must not exit or attempt to return to + its caller as there is nothing to return to. If a task wants to exit it + should instead call vTaskDelete( NULL ). + + Artificially force an assert() to be triggered if configASSERT() is + defined, then stop here so application writers can catch the error. */ + configASSERT( uxCriticalNesting == ~0UL ); + portDISABLE_INTERRUPTS(); + for( ;; ); +} +/*-----------------------------------------------------------*/ + +void vPortSVCHandler( void ) +{ + /* This function is no longer used, but retained for backward + compatibility. */ +} +/*-----------------------------------------------------------*/ + +__asm void prvPortStartFirstTask( void ) +{ + extern pxCurrentTCB; + + PRESERVE8 + + /* The MSP stack is not reset as, unlike on M3/4 parts, there is no vector + table offset register that can be used to locate the initial stack value. + Not all M0 parts have the application vector table at address 0. */ + + ldr r3, =pxCurrentTCB /* Obtain location of pxCurrentTCB. */ + ldr r1, [r3] + ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */ + adds r0, #32 /* Discard everything up to r0. */ + msr psp, r0 /* This is now the new top of stack to use in the task. */ + movs r0, #2 /* Switch to the psp stack. */ + msr CONTROL, r0 + isb + pop {r0-r5} /* Pop the registers that are saved automatically. */ + mov lr, r5 /* lr is now in r5. */ + pop {r3} /* The return address is now in r3. */ + pop {r2} /* Pop and discard the XPSR. */ + cpsie i /* The first task has its context and interrupts can be enabled. */ + bx r3 /* Finally, jump to the user defined task code. */ + + ALIGN +} +/*-----------------------------------------------------------*/ + +/* + * See header file for description. + */ +BaseType_t xPortStartScheduler( void ) +{ + /* Make PendSV, CallSV and SysTick the same priroity as the kernel. */ + *(portNVIC_SYSPRI2) |= portNVIC_PENDSV_PRI; + *(portNVIC_SYSPRI2) |= portNVIC_SYSTICK_PRI; + + /* Start the timer that generates the tick ISR. Interrupts are disabled + here already. */ + prvSetupTimerInterrupt(); + + /* Initialise the critical nesting count ready for the first task. */ + uxCriticalNesting = 0; + + /* Start the first task. */ + prvPortStartFirstTask(); + + /* Should not get here! */ + return 0; +} +/*-----------------------------------------------------------*/ + +void vPortEndScheduler( void ) +{ + /* Not implemented in ports where there is nothing to return to. + Artificially force an assert. */ + configASSERT( uxCriticalNesting == 1000UL ); +} +/*-----------------------------------------------------------*/ + +void vPortYield( void ) +{ + /* Set a PendSV to request a context switch. */ + *( portNVIC_INT_CTRL ) = portNVIC_PENDSVSET; + + /* Barriers are normally not required but do ensure the code is completely + within the specified behaviour for the architecture. */ + __dsb( portSY_FULL_READ_WRITE ); + __isb( portSY_FULL_READ_WRITE ); +} +/*-----------------------------------------------------------*/ + +void vPortEnterCritical( void ) +{ + portDISABLE_INTERRUPTS(); + uxCriticalNesting++; + __dsb( portSY_FULL_READ_WRITE ); + __isb( portSY_FULL_READ_WRITE ); +} +/*-----------------------------------------------------------*/ + +void vPortExitCritical( void ) +{ + configASSERT( uxCriticalNesting ); + uxCriticalNesting--; + if( uxCriticalNesting == 0 ) + { + portENABLE_INTERRUPTS(); + } +} +/*-----------------------------------------------------------*/ + +__asm uint32_t ulSetInterruptMaskFromISR( void ) +{ + mrs r0, PRIMASK + cpsid i + bx lr +} +/*-----------------------------------------------------------*/ + +__asm void vClearInterruptMaskFromISR( uint32_t ulMask ) +{ + msr PRIMASK, r0 + bx lr +} +/*-----------------------------------------------------------*/ + +__asm void xPortPendSVHandler( void ) +{ + extern vTaskSwitchContext + extern pxCurrentTCB + + PRESERVE8 + + mrs r0, psp + + ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */ + ldr r2, [r3] + + subs r0, #32 /* Make space for the remaining low registers. */ + str r0, [r2] /* Save the new top of stack. */ + stmia r0!, {r4-r7} /* Store the low registers that are not saved automatically. */ + mov r4, r8 /* Store the high registers. */ + mov r5, r9 + mov r6, r10 + mov r7, r11 + stmia r0!, {r4-r7} + + push {r3, r14} + cpsid i + bl vTaskSwitchContext + cpsie i + pop {r2, r3} /* lr goes in r3. r2 now holds tcb pointer. */ + + ldr r1, [r2] + ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */ + adds r0, #16 /* Move to the high registers. */ + ldmia r0!, {r4-r7} /* Pop the high registers. */ + mov r8, r4 + mov r9, r5 + mov r10, r6 + mov r11, r7 + + msr psp, r0 /* Remember the new top of stack for the task. */ + + subs r0, #32 /* Go back for the low registers that are not automatically restored. */ + ldmia r0!, {r4-r7} /* Pop low registers. */ + + bx r3 + ALIGN +} +/*-----------------------------------------------------------*/ + +void xPortSysTickHandler( void ) +{ +uint32_t ulPreviousMask; + + ulPreviousMask = portSET_INTERRUPT_MASK_FROM_ISR(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { + /* Pend a context switch. */ + *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( ulPreviousMask ); +} +/*-----------------------------------------------------------*/ + +#if configUSE_TICKLESS_IDLE == 1 + + __weak void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) + { + uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickCTRL; + TickType_t xModifiableIdleTime; + + /* Make sure the SysTick reload value does not overflow the counter. */ + if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks ) + { + xExpectedIdleTime = xMaximumPossibleSuppressedTicks; + } + + /* Stop the SysTick momentarily. The time the SysTick is stopped for + is accounted for as best it can be, but using the tickless mode will + inevitably result in some tiny drift of the time maintained by the + kernel with respect to calendar time. */ + portNVIC_SYSTICK_CTRL &= ~portNVIC_SYSTICK_ENABLE; + + /* Calculate the reload value required to wait xExpectedIdleTime + tick periods. -1 is used because this code will execute part way + through one of the tick periods. */ + ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) ); + if( ulReloadValue > ulStoppedTimerCompensation ) + { + ulReloadValue -= ulStoppedTimerCompensation; + } + + /* Enter a critical section but don't use the taskENTER_CRITICAL() + method as that will mask interrupts that should exit sleep mode. */ + __disable_irq(); + + /* If a context switch is pending or a task is waiting for the scheduler + to be unsuspended then abandon the low power entry. */ + if( eTaskConfirmSleepModeStatus() == eAbortSleep ) + { + /* Restart from whatever is left in the count register to complete + this tick period. */ + portNVIC_SYSTICK_LOAD = portNVIC_SYSTICK_CURRENT_VALUE; + + /* Restart SysTick. */ + portNVIC_SYSTICK_CTRL |= portNVIC_SYSTICK_ENABLE; + + /* Reset the reload register to the value required for normal tick + periods. */ + portNVIC_SYSTICK_LOAD = ulTimerCountsForOneTick - 1UL; + + /* Re-enable interrupts - see comments above __disable_irq() call + above. */ + __enable_irq(); + } + else + { + /* Set the new reload value. */ + portNVIC_SYSTICK_LOAD = ulReloadValue; + + /* Clear the SysTick count flag and set the count value back to + zero. */ + portNVIC_SYSTICK_CURRENT_VALUE = 0UL; + + /* Restart SysTick. */ + portNVIC_SYSTICK_CTRL |= portNVIC_SYSTICK_ENABLE; + + /* Sleep until something happens. configPRE_SLEEP_PROCESSING() can + set its parameter to 0 to indicate that its implementation contains + its own wait for interrupt or wait for event instruction, and so wfi + should not be executed again. However, the original expected idle + time variable must remain unmodified, so a copy is taken. */ + xModifiableIdleTime = xExpectedIdleTime; + configPRE_SLEEP_PROCESSING( &xModifiableIdleTime ); + if( xModifiableIdleTime > 0 ) + { + __dsb( portSY_FULL_READ_WRITE ); + __wfi(); + __isb( portSY_FULL_READ_WRITE ); + } + configPOST_SLEEP_PROCESSING( &xExpectedIdleTime ); + + /* Stop SysTick. Again, the time the SysTick is stopped for is + accounted for as best it can be, but using the tickless mode will + inevitably result in some tiny drift of the time maintained by the + kernel with respect to calendar time. */ + ulSysTickCTRL = portNVIC_SYSTICK_CTRL; + portNVIC_SYSTICK_CTRL = ( ulSysTickCTRL & ~portNVIC_SYSTICK_ENABLE ); + + /* Re-enable interrupts - see comments above __disable_irq() call + above. */ + __enable_irq(); + + if( ( ulSysTickCTRL & portNVIC_SYSTICK_COUNT_FLAG ) != 0 ) + { + uint32_t ulCalculatedLoadValue; + + /* The tick interrupt has already executed, and the SysTick + count reloaded with ulReloadValue. Reset the + portNVIC_SYSTICK_LOAD with whatever remains of this tick + period. */ + ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE ); + + /* Don't allow a tiny value, or values that have somehow + underflowed because the post sleep hook did something + that took too long. */ + if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) ) + { + ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ); + } + + portNVIC_SYSTICK_LOAD = ulCalculatedLoadValue; + + /* The tick interrupt handler will already have pended the tick + processing in the kernel. As the pending tick will be + processed as soon as this function exits, the tick value + maintained by the tick is stepped forward by one less than the + time spent waiting. */ + ulCompleteTickPeriods = xExpectedIdleTime - 1UL; + } + else + { + /* Something other than the tick interrupt ended the sleep. + Work out how long the sleep lasted rounded to complete tick + periods (not the ulReload value which accounted for part + ticks). */ + ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE; + + /* How many complete tick periods passed while the processor + was waiting? */ + ulCompleteTickPeriods = ulCompletedSysTickDecrements / ulTimerCountsForOneTick; + + /* The reload value is set to whatever fraction of a single tick + period remains. */ + portNVIC_SYSTICK_LOAD = ( ( ulCompleteTickPeriods + 1 ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements; + } + + /* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD + again, then set portNVIC_SYSTICK_LOAD back to its standard + value. The critical section is used to ensure the tick interrupt + can only execute once in the case that the reload register is near + zero. */ + portNVIC_SYSTICK_CURRENT_VALUE = 0UL; + portENTER_CRITICAL(); + { + portNVIC_SYSTICK_CTRL |= portNVIC_SYSTICK_ENABLE; + vTaskStepTick( ulCompleteTickPeriods ); + portNVIC_SYSTICK_LOAD = ulTimerCountsForOneTick - 1UL; + } + portEXIT_CRITICAL(); + } + } + +#endif /* #if configUSE_TICKLESS_IDLE */ + +/*-----------------------------------------------------------*/ + +/* + * Setup the systick timer to generate the tick interrupts at the required + * frequency. + */ +void prvSetupTimerInterrupt( void ) +{ + /* Calculate the constants required to configure the tick interrupt. */ + #if configUSE_TICKLESS_IDLE == 1 + { + ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ); + xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick; + ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ ); + } + #endif /* configUSE_TICKLESS_IDLE */ + + /* Stop and reset the SysTick. */ + portNVIC_SYSTICK_CTRL = 0UL; + portNVIC_SYSTICK_CURRENT_VALUE = 0UL; + + /* Configure SysTick to interrupt at the requested rate. */ + portNVIC_SYSTICK_LOAD = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL; + portNVIC_SYSTICK_CTRL = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE; +} +/*-----------------------------------------------------------*/ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM0/portmacro.h b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM0/portmacro.h new file mode 100644 index 0000000..dddec5a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM0/portmacro.h @@ -0,0 +1,114 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + + +#ifndef PORTMACRO_H +#define PORTMACRO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*----------------------------------------------------------- + * Port specific definitions. + * + * The settings in this file configure FreeRTOS correctly for the + * given hardware and compiler. + * + * These settings should not be altered. + *----------------------------------------------------------- + */ + +/* Type definitions. */ +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT short +#define portSTACK_TYPE uint32_t +#define portBASE_TYPE long + +typedef portSTACK_TYPE StackType_t; +typedef long BaseType_t; +typedef unsigned long UBaseType_t; + +#if( configUSE_16_BIT_TICKS == 1 ) + typedef uint16_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffff +#else + typedef uint32_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffffffffUL + + /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do + not need to be guarded with a critical section. */ + #define portTICK_TYPE_IS_ATOMIC 1 +#endif +/*-----------------------------------------------------------*/ + +/* Architecture specifics. */ +#define portSTACK_GROWTH ( -1 ) +#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) +#define portBYTE_ALIGNMENT 8 +/*-----------------------------------------------------------*/ + + +/* Scheduler utilities. */ +extern void vPortYield( void ); +#define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) +#define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) +#define portYIELD() vPortYield() +#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT +#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) +/*-----------------------------------------------------------*/ + +/* Critical section management. */ +extern void vPortEnterCritical( void ); +extern void vPortExitCritical( void ); +extern uint32_t ulSetInterruptMaskFromISR( void ); +extern void vClearInterruptMaskFromISR( uint32_t ulMask ); + +#define portSET_INTERRUPT_MASK_FROM_ISR() ulSetInterruptMaskFromISR() +#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vClearInterruptMaskFromISR( x ) +#define portDISABLE_INTERRUPTS() __disable_irq() +#define portENABLE_INTERRUPTS() __enable_irq() +#define portENTER_CRITICAL() vPortEnterCritical() +#define portEXIT_CRITICAL() vPortExitCritical() + +/*-----------------------------------------------------------*/ + +/* Task function macros as described on the FreeRTOS.org WEB site. */ +#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) +#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) + +#define portNOP() + +#ifdef __cplusplus +} +#endif + +#endif /* PORTMACRO_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/readme.txt new file mode 100644 index 0000000..b68d2d5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/portable/readme.txt @@ -0,0 +1,20 @@ +Each real time kernel port consists of three files that contain the core kernel +components and are common to every port, and one or more files that are +specific to a particular microcontroller and/or compiler. + + ++ The FreeRTOS/Source/Portable/MemMang directory contains the five sample +memory allocators as described on the http://www.FreeRTOS.org WEB site. + ++ The other directories each contain files specific to a particular +microcontroller or compiler, where the directory name denotes the compiler +specific files the directory contains. + + + +For example, if you are interested in the [compiler] port for the [architecture] +microcontroller, then the port specific files are contained in +FreeRTOS/Source/Portable/[compiler]/[architecture] directory. If this is the +only port you are interested in then all the other directories can be +ignored. + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/queue.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/queue.c new file mode 100644 index 0000000..bce014d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/queue.c @@ -0,0 +1,2908 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#include +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" + +#if ( configUSE_CO_ROUTINES == 1 ) + #include "croutine.h" +#endif + +/* Lint e961 and e750 are suppressed as a MISRA exception justified because the +MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the +header files above, but not in this file, in order to generate the correct +privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */ + + +/* Constants used with the cRxLock and cTxLock structure members. */ +#define queueUNLOCKED ( ( int8_t ) -1 ) +#define queueLOCKED_UNMODIFIED ( ( int8_t ) 0 ) + +/* When the Queue_t structure is used to represent a base queue its pcHead and +pcTail members are used as pointers into the queue storage area. When the +Queue_t structure is used to represent a mutex pcHead and pcTail pointers are +not necessary, and the pcHead pointer is set to NULL to indicate that the +pcTail pointer actually points to the mutex holder (if any). Map alternative +names to the pcHead and pcTail structure members to ensure the readability of +the code is maintained despite this dual use of two structure members. An +alternative implementation would be to use a union, but use of a union is +against the coding standard (although an exception to the standard has been +permitted where the dual use also significantly changes the type of the +structure member). */ +#define pxMutexHolder pcTail +#define uxQueueType pcHead +#define queueQUEUE_IS_MUTEX NULL + +/* Semaphores do not actually store or copy data, so have an item size of +zero. */ +#define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( UBaseType_t ) 0 ) +#define queueMUTEX_GIVE_BLOCK_TIME ( ( TickType_t ) 0U ) + +#if( configUSE_PREEMPTION == 0 ) + /* If the cooperative scheduler is being used then a yield should not be + performed just because a higher priority task has been woken. */ + #define queueYIELD_IF_USING_PREEMPTION() +#else + #define queueYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API() +#endif + +/* + * Definition of the queue used by the scheduler. + * Items are queued by copy, not reference. See the following link for the + * rationale: http://www.freertos.org/Embedded-RTOS-Queues.html + */ +typedef struct QueueDefinition +{ + int8_t *pcHead; /*< Points to the beginning of the queue storage area. */ + int8_t *pcTail; /*< Points to the byte at the end of the queue storage area. Once more byte is allocated than necessary to store the queue items, this is used as a marker. */ + int8_t *pcWriteTo; /*< Points to the free next place in the storage area. */ + + union /* Use of a union is an exception to the coding standard to ensure two mutually exclusive structure members don't appear simultaneously (wasting RAM). */ + { + int8_t *pcReadFrom; /*< Points to the last place that a queued item was read from when the structure is used as a queue. */ + UBaseType_t uxRecursiveCallCount;/*< Maintains a count of the number of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */ + } u; + + List_t xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */ + List_t xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */ + + volatile UBaseType_t uxMessagesWaiting;/*< The number of items currently in the queue. */ + UBaseType_t uxLength; /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */ + UBaseType_t uxItemSize; /*< The size of each items that the queue will hold. */ + + volatile int8_t cRxLock; /*< Stores the number of items received from the queue (removed from the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */ + volatile int8_t cTxLock; /*< Stores the number of items transmitted to the queue (added to the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */ + + #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the memory used by the queue was statically allocated to ensure no attempt is made to free the memory. */ + #endif + + #if ( configUSE_QUEUE_SETS == 1 ) + struct QueueDefinition *pxQueueSetContainer; + #endif + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxQueueNumber; + uint8_t ucQueueType; + #endif + +} xQUEUE; + +/* The old xQUEUE name is maintained above then typedefed to the new Queue_t +name below to enable the use of older kernel aware debuggers. */ +typedef xQUEUE Queue_t; + +/*-----------------------------------------------------------*/ + +/* + * The queue registry is just a means for kernel aware debuggers to locate + * queue structures. It has no other purpose so is an optional component. + */ +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + + /* The type stored within the queue registry array. This allows a name + to be assigned to each queue making kernel aware debugging a little + more user friendly. */ + typedef struct QUEUE_REGISTRY_ITEM + { + const char *pcQueueName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + QueueHandle_t xHandle; + } xQueueRegistryItem; + + /* The old xQueueRegistryItem name is maintained above then typedefed to the + new xQueueRegistryItem name below to enable the use of older kernel aware + debuggers. */ + typedef xQueueRegistryItem QueueRegistryItem_t; + + /* The queue registry is simply an array of QueueRegistryItem_t structures. + The pcQueueName member of a structure being NULL is indicative of the + array position being vacant. */ + PRIVILEGED_DATA QueueRegistryItem_t xQueueRegistry[ configQUEUE_REGISTRY_SIZE ]; + +#endif /* configQUEUE_REGISTRY_SIZE */ + +/* + * Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not + * prevent an ISR from adding or removing items to the queue, but does prevent + * an ISR from removing tasks from the queue event lists. If an ISR finds a + * queue is locked it will instead increment the appropriate queue lock count + * to indicate that a task may require unblocking. When the queue in unlocked + * these lock counts are inspected, and the appropriate action taken. + */ +static void prvUnlockQueue( Queue_t * const pxQueue ) PRIVILEGED_FUNCTION; + +/* + * Uses a critical section to determine if there is any data in a queue. + * + * @return pdTRUE if the queue contains no items, otherwise pdFALSE. + */ +static BaseType_t prvIsQueueEmpty( const Queue_t *pxQueue ) PRIVILEGED_FUNCTION; + +/* + * Uses a critical section to determine if there is any space in a queue. + * + * @return pdTRUE if there is no space, otherwise pdFALSE; + */ +static BaseType_t prvIsQueueFull( const Queue_t *pxQueue ) PRIVILEGED_FUNCTION; + +/* + * Copies an item into the queue, either at the front of the queue or the + * back of the queue. + */ +static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition ) PRIVILEGED_FUNCTION; + +/* + * Copies an item out of a queue. + */ +static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION; + +#if ( configUSE_QUEUE_SETS == 1 ) + /* + * Checks to see if a queue is a member of a queue set, and if so, notifies + * the queue set that the queue contains data. + */ + static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION; +#endif + +/* + * Called after a Queue_t structure has been allocated either statically or + * dynamically to fill in the structure's members. + */ +static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, const uint8_t ucQueueType, Queue_t *pxNewQueue ) PRIVILEGED_FUNCTION; + +/* + * Mutexes are a special type of queue. When a mutex is created, first the + * queue is created, then prvInitialiseMutex() is called to configure the queue + * as a mutex. + */ +#if( configUSE_MUTEXES == 1 ) + static void prvInitialiseMutex( Queue_t *pxNewQueue ) PRIVILEGED_FUNCTION; +#endif + +#if( configUSE_MUTEXES == 1 ) + /* + * If a task waiting for a mutex causes the mutex holder to inherit a + * priority, but the waiting task times out, then the holder should + * disinherit the priority - but only down to the highest priority of any + * other tasks that are waiting for the same mutex. This function returns + * that priority. + */ + static UBaseType_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue ) PRIVILEGED_FUNCTION; +#endif +/*-----------------------------------------------------------*/ + +/* + * Macro to mark a queue as locked. Locking a queue prevents an ISR from + * accessing the queue event lists. + */ +#define prvLockQueue( pxQueue ) \ + taskENTER_CRITICAL(); \ + { \ + if( ( pxQueue )->cRxLock == queueUNLOCKED ) \ + { \ + ( pxQueue )->cRxLock = queueLOCKED_UNMODIFIED; \ + } \ + if( ( pxQueue )->cTxLock == queueUNLOCKED ) \ + { \ + ( pxQueue )->cTxLock = queueLOCKED_UNMODIFIED; \ + } \ + } \ + taskEXIT_CRITICAL() +/*-----------------------------------------------------------*/ + +BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ) +{ +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + configASSERT( pxQueue ); + + taskENTER_CRITICAL(); + { + pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize ); + pxQueue->uxMessagesWaiting = ( UBaseType_t ) 0U; + pxQueue->pcWriteTo = pxQueue->pcHead; + pxQueue->u.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( UBaseType_t ) 1U ) * pxQueue->uxItemSize ); + pxQueue->cRxLock = queueUNLOCKED; + pxQueue->cTxLock = queueUNLOCKED; + + if( xNewQueue == pdFALSE ) + { + /* If there are tasks blocked waiting to read from the queue, then + the tasks will remain blocked as after this function exits the queue + will still be empty. If there are tasks blocked waiting to write to + the queue, then one should be unblocked as after this function exits + it will be possible to write to it. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* Ensure the event queues start in the correct state. */ + vListInitialise( &( pxQueue->xTasksWaitingToSend ) ); + vListInitialise( &( pxQueue->xTasksWaitingToReceive ) ); + } + } + taskEXIT_CRITICAL(); + + /* A value is returned for calling semantic consistency with previous + versions. */ + return pdPASS; +} +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + + QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ) + { + Queue_t *pxNewQueue; + + configASSERT( uxQueueLength > ( UBaseType_t ) 0 ); + + /* The StaticQueue_t structure and the queue storage area must be + supplied. */ + configASSERT( pxStaticQueue != NULL ); + + /* A queue storage area should be provided if the item size is not 0, and + should not be provided if the item size is 0. */ + configASSERT( !( ( pucQueueStorage != NULL ) && ( uxItemSize == 0 ) ) ); + configASSERT( !( ( pucQueueStorage == NULL ) && ( uxItemSize != 0 ) ) ); + + #if( configASSERT_DEFINED == 1 ) + { + /* Sanity check that the size of the structure used to declare a + variable of type StaticQueue_t or StaticSemaphore_t equals the size of + the real queue and semaphore structures. */ + volatile size_t xSize = sizeof( StaticQueue_t ); + configASSERT( xSize == sizeof( Queue_t ) ); + } + #endif /* configASSERT_DEFINED */ + + /* The address of a statically allocated queue was passed in, use it. + The address of a statically allocated storage area was also passed in + but is already set. */ + pxNewQueue = ( Queue_t * ) pxStaticQueue; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */ + + if( pxNewQueue != NULL ) + { + #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + { + /* Queues can be allocated wither statically or dynamically, so + note this queue was allocated statically in case the queue is + later deleted. */ + pxNewQueue->ucStaticallyAllocated = pdTRUE; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + + prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue ); + } + else + { + traceQUEUE_CREATE_FAILED( ucQueueType ); + } + + return pxNewQueue; + } + +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) + { + Queue_t *pxNewQueue; + size_t xQueueSizeInBytes; + uint8_t *pucQueueStorage; + + configASSERT( uxQueueLength > ( UBaseType_t ) 0 ); + + if( uxItemSize == ( UBaseType_t ) 0 ) + { + /* There is not going to be a queue storage area. */ + xQueueSizeInBytes = ( size_t ) 0; + } + else + { + /* Allocate enough space to hold the maximum number of items that + can be in the queue at any time. */ + xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + } + + pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes ); + + if( pxNewQueue != NULL ) + { + /* Jump past the queue structure to find the location of the queue + storage area. */ + pucQueueStorage = ( ( uint8_t * ) pxNewQueue ) + sizeof( Queue_t ); + + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + /* Queues can be created either statically or dynamically, so + note this task was created dynamically in case it is later + deleted. */ + pxNewQueue->ucStaticallyAllocated = pdFALSE; + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ + + prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue ); + } + else + { + traceQUEUE_CREATE_FAILED( ucQueueType ); + } + + return pxNewQueue; + } + +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, const uint8_t ucQueueType, Queue_t *pxNewQueue ) +{ + /* Remove compiler warnings about unused parameters should + configUSE_TRACE_FACILITY not be set to 1. */ + ( void ) ucQueueType; + + if( uxItemSize == ( UBaseType_t ) 0 ) + { + /* No RAM was allocated for the queue storage area, but PC head cannot + be set to NULL because NULL is used as a key to say the queue is used as + a mutex. Therefore just set pcHead to point to the queue as a benign + value that is known to be within the memory map. */ + pxNewQueue->pcHead = ( int8_t * ) pxNewQueue; + } + else + { + /* Set the head to the start of the queue storage area. */ + pxNewQueue->pcHead = ( int8_t * ) pucQueueStorage; + } + + /* Initialise the queue members as described where the queue type is + defined. */ + pxNewQueue->uxLength = uxQueueLength; + pxNewQueue->uxItemSize = uxItemSize; + ( void ) xQueueGenericReset( pxNewQueue, pdTRUE ); + + #if ( configUSE_TRACE_FACILITY == 1 ) + { + pxNewQueue->ucQueueType = ucQueueType; + } + #endif /* configUSE_TRACE_FACILITY */ + + #if( configUSE_QUEUE_SETS == 1 ) + { + pxNewQueue->pxQueueSetContainer = NULL; + } + #endif /* configUSE_QUEUE_SETS */ + + traceQUEUE_CREATE( pxNewQueue ); +} +/*-----------------------------------------------------------*/ + +#if( configUSE_MUTEXES == 1 ) + + static void prvInitialiseMutex( Queue_t *pxNewQueue ) + { + if( pxNewQueue != NULL ) + { + /* The queue create function will set all the queue structure members + correctly for a generic queue, but this function is creating a + mutex. Overwrite those members that need to be set differently - + in particular the information required for priority inheritance. */ + pxNewQueue->pxMutexHolder = NULL; + pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX; + + /* In case this is a recursive mutex. */ + pxNewQueue->u.uxRecursiveCallCount = 0; + + traceCREATE_MUTEX( pxNewQueue ); + + /* Start with the semaphore in the expected state. */ + ( void ) xQueueGenericSend( pxNewQueue, NULL, ( TickType_t ) 0U, queueSEND_TO_BACK ); + } + else + { + traceCREATE_MUTEX_FAILED(); + } + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) + { + Queue_t *pxNewQueue; + const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0; + + pxNewQueue = ( Queue_t * ) xQueueGenericCreate( uxMutexLength, uxMutexSize, ucQueueType ); + prvInitialiseMutex( pxNewQueue ); + + return pxNewQueue; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + + QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) + { + Queue_t *pxNewQueue; + const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0; + + /* Prevent compiler warnings about unused parameters if + configUSE_TRACE_FACILITY does not equal 1. */ + ( void ) ucQueueType; + + pxNewQueue = ( Queue_t * ) xQueueGenericCreateStatic( uxMutexLength, uxMutexSize, NULL, pxStaticQueue, ucQueueType ); + prvInitialiseMutex( pxNewQueue ); + + return pxNewQueue; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) + + void* xQueueGetMutexHolder( QueueHandle_t xSemaphore ) + { + void *pxReturn; + + /* This function is called by xSemaphoreGetMutexHolder(), and should not + be called directly. Note: This is a good way of determining if the + calling task is the mutex holder, but not a good way of determining the + identity of the mutex holder, as the holder may change between the + following critical section exiting and the function returning. */ + taskENTER_CRITICAL(); + { + if( ( ( Queue_t * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX ) + { + pxReturn = ( void * ) ( ( Queue_t * ) xSemaphore )->pxMutexHolder; + } + else + { + pxReturn = NULL; + } + } + taskEXIT_CRITICAL(); + + return pxReturn; + } /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */ + +#endif +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) + + void* xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) + { + void *pxReturn; + + configASSERT( xSemaphore ); + + /* Mutexes cannot be used in interrupt service routines, so the mutex + holder should not change in an ISR, and therefore a critical section is + not required here. */ + if( ( ( Queue_t * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX ) + { + pxReturn = ( void * ) ( ( Queue_t * ) xSemaphore )->pxMutexHolder; + } + else + { + pxReturn = NULL; + } + + return pxReturn; + } /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */ + +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_RECURSIVE_MUTEXES == 1 ) + + BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) + { + BaseType_t xReturn; + Queue_t * const pxMutex = ( Queue_t * ) xMutex; + + configASSERT( pxMutex ); + + /* If this is the task that holds the mutex then pxMutexHolder will not + change outside of this task. If this task does not hold the mutex then + pxMutexHolder can never coincidentally equal the tasks handle, and as + this is the only condition we are interested in it does not matter if + pxMutexHolder is accessed simultaneously by another task. Therefore no + mutual exclusion is required to test the pxMutexHolder variable. */ + if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Not a redundant cast as TaskHandle_t is a typedef. */ + { + traceGIVE_MUTEX_RECURSIVE( pxMutex ); + + /* uxRecursiveCallCount cannot be zero if pxMutexHolder is equal to + the task handle, therefore no underflow check is required. Also, + uxRecursiveCallCount is only modified by the mutex holder, and as + there can only be one, no mutual exclusion is required to modify the + uxRecursiveCallCount member. */ + ( pxMutex->u.uxRecursiveCallCount )--; + + /* Has the recursive call count unwound to 0? */ + if( pxMutex->u.uxRecursiveCallCount == ( UBaseType_t ) 0 ) + { + /* Return the mutex. This will automatically unblock any other + task that might be waiting to access the mutex. */ + ( void ) xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xReturn = pdPASS; + } + else + { + /* The mutex cannot be given because the calling task is not the + holder. */ + xReturn = pdFAIL; + + traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex ); + } + + return xReturn; + } + +#endif /* configUSE_RECURSIVE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_RECURSIVE_MUTEXES == 1 ) + + BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ) + { + BaseType_t xReturn; + Queue_t * const pxMutex = ( Queue_t * ) xMutex; + + configASSERT( pxMutex ); + + /* Comments regarding mutual exclusion as per those within + xQueueGiveMutexRecursive(). */ + + traceTAKE_MUTEX_RECURSIVE( pxMutex ); + + if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Cast is not redundant as TaskHandle_t is a typedef. */ + { + ( pxMutex->u.uxRecursiveCallCount )++; + xReturn = pdPASS; + } + else + { + xReturn = xQueueSemaphoreTake( pxMutex, xTicksToWait ); + + /* pdPASS will only be returned if the mutex was successfully + obtained. The calling task may have entered the Blocked state + before reaching here. */ + if( xReturn != pdFAIL ) + { + ( pxMutex->u.uxRecursiveCallCount )++; + } + else + { + traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex ); + } + } + + return xReturn; + } + +#endif /* configUSE_RECURSIVE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + + QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) + { + QueueHandle_t xHandle; + + configASSERT( uxMaxCount != 0 ); + configASSERT( uxInitialCount <= uxMaxCount ); + + xHandle = xQueueGenericCreateStatic( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticQueue, queueQUEUE_TYPE_COUNTING_SEMAPHORE ); + + if( xHandle != NULL ) + { + ( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount; + + traceCREATE_COUNTING_SEMAPHORE(); + } + else + { + traceCREATE_COUNTING_SEMAPHORE_FAILED(); + } + + return xHandle; + } + +#endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) + { + QueueHandle_t xHandle; + + configASSERT( uxMaxCount != 0 ); + configASSERT( uxInitialCount <= uxMaxCount ); + + xHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE ); + + if( xHandle != NULL ) + { + ( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount; + + traceCREATE_COUNTING_SEMAPHORE(); + } + else + { + traceCREATE_COUNTING_SEMAPHORE_FAILED(); + } + + return xHandle; + } + +#endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */ +/*-----------------------------------------------------------*/ + +BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) +{ +BaseType_t xEntryTimeSet = pdFALSE, xYieldRequired; +TimeOut_t xTimeOut; +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + configASSERT( pxQueue ); + configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) ); + configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) ); + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + + /* This function relaxes the coding standard somewhat to allow return + statements within the function itself. This is done in the interest + of execution time efficiency. */ + for( ;; ) + { + taskENTER_CRITICAL(); + { + /* Is there room on the queue now? The running task must be the + highest priority task wanting to access the queue. If the head item + in the queue is to be overwritten then it does not matter if the + queue is full. */ + if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) ) + { + traceQUEUE_SEND( pxQueue ); + xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition ); + + #if ( configUSE_QUEUE_SETS == 1 ) + { + if( pxQueue->pxQueueSetContainer != NULL ) + { + if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != pdFALSE ) + { + /* The queue is a member of a queue set, and posting + to the queue set caused a higher priority task to + unblock. A context switch is required. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* If there was a task waiting for data to arrive on the + queue then unblock it now. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The unblocked task has a priority higher than + our own so yield immediately. Yes it is ok to + do this from within the critical section - the + kernel takes care of that. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else if( xYieldRequired != pdFALSE ) + { + /* This path is a special case that will only get + executed if the task was holding multiple mutexes + and the mutexes were given back in an order that is + different to that in which they were taken. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + #else /* configUSE_QUEUE_SETS */ + { + /* If there was a task waiting for data to arrive on the + queue then unblock it now. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The unblocked task has a priority higher than + our own so yield immediately. Yes it is ok to do + this from within the critical section - the kernel + takes care of that. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else if( xYieldRequired != pdFALSE ) + { + /* This path is a special case that will only get + executed if the task was holding multiple mutexes and + the mutexes were given back in an order that is + different to that in which they were taken. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_QUEUE_SETS */ + + taskEXIT_CRITICAL(); + return pdPASS; + } + else + { + if( xTicksToWait == ( TickType_t ) 0 ) + { + /* The queue was full and no block time is specified (or + the block time has expired) so leave now. */ + taskEXIT_CRITICAL(); + + /* Return to the original privilege level before exiting + the function. */ + traceQUEUE_SEND_FAILED( pxQueue ); + return errQUEUE_FULL; + } + else if( xEntryTimeSet == pdFALSE ) + { + /* The queue was full and a block time was specified so + configure the timeout structure. */ + vTaskInternalSetTimeOutState( &xTimeOut ); + xEntryTimeSet = pdTRUE; + } + else + { + /* Entry time was already set. */ + mtCOVERAGE_TEST_MARKER(); + } + } + } + taskEXIT_CRITICAL(); + + /* Interrupts and other tasks can send to and receive from the queue + now the critical section has been exited. */ + + vTaskSuspendAll(); + prvLockQueue( pxQueue ); + + /* Update the timeout state to see if it has expired yet. */ + if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ) + { + if( prvIsQueueFull( pxQueue ) != pdFALSE ) + { + traceBLOCKING_ON_QUEUE_SEND( pxQueue ); + vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait ); + + /* Unlocking the queue means queue events can effect the + event list. It is possible that interrupts occurring now + remove this task from the event list again - but as the + scheduler is suspended the task will go onto the pending + ready last instead of the actual ready list. */ + prvUnlockQueue( pxQueue ); + + /* Resuming the scheduler will move tasks from the pending + ready list into the ready list - so it is feasible that this + task is already in a ready list before it yields - in which + case the yield will not cause a context switch unless there + is also a higher priority task in the pending ready list. */ + if( xTaskResumeAll() == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + } + else + { + /* Try again. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + } + } + else + { + /* The timeout has expired. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + + traceQUEUE_SEND_FAILED( pxQueue ); + return errQUEUE_FULL; + } + } +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition ) +{ +BaseType_t xReturn; +UBaseType_t uxSavedInterruptStatus; +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + configASSERT( pxQueue ); + configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) ); + configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) ); + + /* RTOS ports that support interrupt nesting have the concept of a maximum + system call (or maximum API call) interrupt priority. Interrupts that are + above the maximum system call priority are kept permanently enabled, even + when the RTOS kernel is in a critical section, but cannot make any calls to + FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + failure if a FreeRTOS API function is called from an interrupt that has been + assigned a priority above the configured maximum system call priority. + Only FreeRTOS functions that end in FromISR can be called from interrupts + that have been assigned a priority at or (logically) below the maximum + system call interrupt priority. FreeRTOS maintains a separate interrupt + safe API to ensure interrupt entry is as fast and as simple as possible. + More information (albeit Cortex-M specific) is provided on the following + link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + /* Similar to xQueueGenericSend, except without blocking if there is no room + in the queue. Also don't directly wake a task that was blocked on a queue + read, instead return a flag to say whether a context switch is required or + not (i.e. has a task with a higher priority than us been woken by this + post). */ + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) ) + { + const int8_t cTxLock = pxQueue->cTxLock; + + traceQUEUE_SEND_FROM_ISR( pxQueue ); + + /* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a + semaphore or mutex. That means prvCopyDataToQueue() cannot result + in a task disinheriting a priority and prvCopyDataToQueue() can be + called here even though the disinherit function does not check if + the scheduler is suspended before accessing the ready lists. */ + ( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition ); + + /* The event list is not altered if the queue is locked. This will + be done when the queue is unlocked later. */ + if( cTxLock == queueUNLOCKED ) + { + #if ( configUSE_QUEUE_SETS == 1 ) + { + if( pxQueue->pxQueueSetContainer != NULL ) + { + if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != pdFALSE ) + { + /* The queue is a member of a queue set, and posting + to the queue set caused a higher priority task to + unblock. A context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so + record that a context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + #else /* configUSE_QUEUE_SETS */ + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_QUEUE_SETS */ + } + else + { + /* Increment the lock count so the task that unlocks the queue + knows that data was posted while it was locked. */ + pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 ); + } + + xReturn = pdPASS; + } + else + { + traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ); + xReturn = errQUEUE_FULL; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) +{ +BaseType_t xReturn; +UBaseType_t uxSavedInterruptStatus; +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + /* Similar to xQueueGenericSendFromISR() but used with semaphores where the + item size is 0. Don't directly wake a task that was blocked on a queue + read, instead return a flag to say whether a context switch is required or + not (i.e. has a task with a higher priority than us been woken by this + post). */ + + configASSERT( pxQueue ); + + /* xQueueGenericSendFromISR() should be used instead of xQueueGiveFromISR() + if the item size is not 0. */ + configASSERT( pxQueue->uxItemSize == 0 ); + + /* Normally a mutex would not be given from an interrupt, especially if + there is a mutex holder, as priority inheritance makes no sense for an + interrupts, only tasks. */ + configASSERT( !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->pxMutexHolder != NULL ) ) ); + + /* RTOS ports that support interrupt nesting have the concept of a maximum + system call (or maximum API call) interrupt priority. Interrupts that are + above the maximum system call priority are kept permanently enabled, even + when the RTOS kernel is in a critical section, but cannot make any calls to + FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + failure if a FreeRTOS API function is called from an interrupt that has been + assigned a priority above the configured maximum system call priority. + Only FreeRTOS functions that end in FromISR can be called from interrupts + that have been assigned a priority at or (logically) below the maximum + system call interrupt priority. FreeRTOS maintains a separate interrupt + safe API to ensure interrupt entry is as fast and as simple as possible. + More information (albeit Cortex-M specific) is provided on the following + link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting; + + /* When the queue is used to implement a semaphore no data is ever + moved through the queue but it is still valid to see if the queue 'has + space'. */ + if( uxMessagesWaiting < pxQueue->uxLength ) + { + const int8_t cTxLock = pxQueue->cTxLock; + + traceQUEUE_SEND_FROM_ISR( pxQueue ); + + /* A task can only have an inherited priority if it is a mutex + holder - and if there is a mutex holder then the mutex cannot be + given from an ISR. As this is the ISR version of the function it + can be assumed there is no mutex holder and no need to determine if + priority disinheritance is needed. Simply increase the count of + messages (semaphores) available. */ + pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1; + + /* The event list is not altered if the queue is locked. This will + be done when the queue is unlocked later. */ + if( cTxLock == queueUNLOCKED ) + { + #if ( configUSE_QUEUE_SETS == 1 ) + { + if( pxQueue->pxQueueSetContainer != NULL ) + { + if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) != pdFALSE ) + { + /* The semaphore is a member of a queue set, and + posting to the queue set caused a higher priority + task to unblock. A context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so + record that a context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + #else /* configUSE_QUEUE_SETS */ + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_QUEUE_SETS */ + } + else + { + /* Increment the lock count so the task that unlocks the queue + knows that data was posted while it was locked. */ + pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 ); + } + + xReturn = pdPASS; + } + else + { + traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ); + xReturn = errQUEUE_FULL; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) +{ +BaseType_t xEntryTimeSet = pdFALSE; +TimeOut_t xTimeOut; +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + /* Check the pointer is not NULL. */ + configASSERT( ( pxQueue ) ); + + /* The buffer into which data is received can only be NULL if the data size + is zero (so no data is copied into the buffer. */ + configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) ); + + /* Cannot block if the scheduler is suspended. */ + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + /* This function relaxes the coding standard somewhat to allow return + statements within the function itself. This is done in the interest + of execution time efficiency. */ + + for( ;; ) + { + taskENTER_CRITICAL(); + { + const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting; + + /* Is there data in the queue now? To be running the calling task + must be the highest priority task wanting to access the queue. */ + if( uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + /* Data available, remove one item. */ + prvCopyDataFromQueue( pxQueue, pvBuffer ); + traceQUEUE_RECEIVE( pxQueue ); + pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1; + + /* There is now space in the queue, were any tasks waiting to + post to the queue? If so, unblock the highest priority waiting + task. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + taskEXIT_CRITICAL(); + return pdPASS; + } + else + { + if( xTicksToWait == ( TickType_t ) 0 ) + { + /* The queue was empty and no block time is specified (or + the block time has expired) so leave now. */ + taskEXIT_CRITICAL(); + traceQUEUE_RECEIVE_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else if( xEntryTimeSet == pdFALSE ) + { + /* The queue was empty and a block time was specified so + configure the timeout structure. */ + vTaskInternalSetTimeOutState( &xTimeOut ); + xEntryTimeSet = pdTRUE; + } + else + { + /* Entry time was already set. */ + mtCOVERAGE_TEST_MARKER(); + } + } + } + taskEXIT_CRITICAL(); + + /* Interrupts and other tasks can send to and receive from the queue + now the critical section has been exited. */ + + vTaskSuspendAll(); + prvLockQueue( pxQueue ); + + /* Update the timeout state to see if it has expired yet. */ + if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ) + { + /* The timeout has not expired. If the queue is still empty place + the task on the list of tasks waiting to receive from the queue. */ + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ); + vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait ); + prvUnlockQueue( pxQueue ); + if( xTaskResumeAll() == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* The queue contains data again. Loop back to try and read the + data. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + } + } + else + { + /* Timed out. If there is no data in the queue exit, otherwise loop + back and attempt to read the data. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + traceQUEUE_RECEIVE_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) +{ +BaseType_t xEntryTimeSet = pdFALSE; +TimeOut_t xTimeOut; +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + +#if( configUSE_MUTEXES == 1 ) + BaseType_t xInheritanceOccurred = pdFALSE; +#endif + + /* Check the queue pointer is not NULL. */ + configASSERT( ( pxQueue ) ); + + /* Check this really is a semaphore, in which case the item size will be + 0. */ + configASSERT( pxQueue->uxItemSize == 0 ); + + /* Cannot block if the scheduler is suspended. */ + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + + /* This function relaxes the coding standard somewhat to allow return + statements within the function itself. This is done in the interest + of execution time efficiency. */ + + for( ;; ) + { + taskENTER_CRITICAL(); + { + /* Semaphores are queues with an item size of 0, and where the + number of messages in the queue is the semaphore's count value. */ + const UBaseType_t uxSemaphoreCount = pxQueue->uxMessagesWaiting; + + /* Is there data in the queue now? To be running the calling task + must be the highest priority task wanting to access the queue. */ + if( uxSemaphoreCount > ( UBaseType_t ) 0 ) + { + traceQUEUE_RECEIVE( pxQueue ); + + /* Semaphores are queues with a data size of zero and where the + messages waiting is the semaphore's count. Reduce the count. */ + pxQueue->uxMessagesWaiting = uxSemaphoreCount - ( UBaseType_t ) 1; + + #if ( configUSE_MUTEXES == 1 ) + { + if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) + { + /* Record the information required to implement + priority inheritance should it become necessary. */ + pxQueue->pxMutexHolder = ( int8_t * ) pvTaskIncrementMutexHeldCount(); /*lint !e961 Cast is not redundant as TaskHandle_t is a typedef. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_MUTEXES */ + + /* Check to see if other tasks are blocked waiting to give the + semaphore, and if so, unblock the highest priority such task. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + taskEXIT_CRITICAL(); + return pdPASS; + } + else + { + if( xTicksToWait == ( TickType_t ) 0 ) + { + /* For inheritance to have occurred there must have been an + initial timeout, and an adjusted timeout cannot become 0, as + if it were 0 the function would have exited. */ + #if( configUSE_MUTEXES == 1 ) + { + configASSERT( xInheritanceOccurred == pdFALSE ); + } + #endif /* configUSE_MUTEXES */ + + /* The semaphore count was 0 and no block time is specified + (or the block time has expired) so exit now. */ + taskEXIT_CRITICAL(); + traceQUEUE_RECEIVE_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else if( xEntryTimeSet == pdFALSE ) + { + /* The semaphore count was 0 and a block time was specified + so configure the timeout structure ready to block. */ + vTaskInternalSetTimeOutState( &xTimeOut ); + xEntryTimeSet = pdTRUE; + } + else + { + /* Entry time was already set. */ + mtCOVERAGE_TEST_MARKER(); + } + } + } + taskEXIT_CRITICAL(); + + /* Interrupts and other tasks can give to and take from the semaphore + now the critical section has been exited. */ + + vTaskSuspendAll(); + prvLockQueue( pxQueue ); + + /* Update the timeout state to see if it has expired yet. */ + if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ) + { + /* A block time is specified and not expired. If the semaphore + count is 0 then enter the Blocked state to wait for a semaphore to + become available. As semaphores are implemented with queues the + queue being empty is equivalent to the semaphore count being 0. */ + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ); + + #if ( configUSE_MUTEXES == 1 ) + { + if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) + { + taskENTER_CRITICAL(); + { + xInheritanceOccurred = xTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder ); + } + taskEXIT_CRITICAL(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif + + vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait ); + prvUnlockQueue( pxQueue ); + if( xTaskResumeAll() == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* There was no timeout and the semaphore count was not 0, so + attempt to take the semaphore again. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + } + } + else + { + /* Timed out. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + + /* If the semaphore count is 0 exit now as the timeout has + expired. Otherwise return to attempt to take the semaphore that is + known to be available. As semaphores are implemented by queues the + queue being empty is equivalent to the semaphore count being 0. */ + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + #if ( configUSE_MUTEXES == 1 ) + { + /* xInheritanceOccurred could only have be set if + pxQueue->uxQueueType == queueQUEUE_IS_MUTEX so no need to + test the mutex type again to check it is actually a mutex. */ + if( xInheritanceOccurred != pdFALSE ) + { + taskENTER_CRITICAL(); + { + UBaseType_t uxHighestWaitingPriority; + + /* This task blocking on the mutex caused another + task to inherit this task's priority. Now this task + has timed out the priority should be disinherited + again, but only as low as the next highest priority + task that is waiting for the same mutex. */ + uxHighestWaitingPriority = prvGetDisinheritPriorityAfterTimeout( pxQueue ); + vTaskPriorityDisinheritAfterTimeout( ( void * ) pxQueue->pxMutexHolder, uxHighestWaitingPriority ); + } + taskEXIT_CRITICAL(); + } + } + #endif /* configUSE_MUTEXES */ + + traceQUEUE_RECEIVE_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) +{ +BaseType_t xEntryTimeSet = pdFALSE; +TimeOut_t xTimeOut; +int8_t *pcOriginalReadPosition; +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + /* Check the pointer is not NULL. */ + configASSERT( ( pxQueue ) ); + + /* The buffer into which data is received can only be NULL if the data size + is zero (so no data is copied into the buffer. */ + configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) ); + + /* Cannot block if the scheduler is suspended. */ + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + + /* This function relaxes the coding standard somewhat to allow return + statements within the function itself. This is done in the interest + of execution time efficiency. */ + + for( ;; ) + { + taskENTER_CRITICAL(); + { + const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting; + + /* Is there data in the queue now? To be running the calling task + must be the highest priority task wanting to access the queue. */ + if( uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + /* Remember the read position so it can be reset after the data + is read from the queue as this function is only peeking the + data, not removing it. */ + pcOriginalReadPosition = pxQueue->u.pcReadFrom; + + prvCopyDataFromQueue( pxQueue, pvBuffer ); + traceQUEUE_PEEK( pxQueue ); + + /* The data is not being removed, so reset the read pointer. */ + pxQueue->u.pcReadFrom = pcOriginalReadPosition; + + /* The data is being left in the queue, so see if there are + any other tasks waiting for the data. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority than this task. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + taskEXIT_CRITICAL(); + return pdPASS; + } + else + { + if( xTicksToWait == ( TickType_t ) 0 ) + { + /* The queue was empty and no block time is specified (or + the block time has expired) so leave now. */ + taskEXIT_CRITICAL(); + traceQUEUE_PEEK_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else if( xEntryTimeSet == pdFALSE ) + { + /* The queue was empty and a block time was specified so + configure the timeout structure ready to enter the blocked + state. */ + vTaskInternalSetTimeOutState( &xTimeOut ); + xEntryTimeSet = pdTRUE; + } + else + { + /* Entry time was already set. */ + mtCOVERAGE_TEST_MARKER(); + } + } + } + taskEXIT_CRITICAL(); + + /* Interrupts and other tasks can send to and receive from the queue + now the critical section has been exited. */ + + vTaskSuspendAll(); + prvLockQueue( pxQueue ); + + /* Update the timeout state to see if it has expired yet. */ + if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ) + { + /* Timeout has not expired yet, check to see if there is data in the + queue now, and if not enter the Blocked state to wait for data. */ + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + traceBLOCKING_ON_QUEUE_PEEK( pxQueue ); + vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait ); + prvUnlockQueue( pxQueue ); + if( xTaskResumeAll() == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* There is data in the queue now, so don't enter the blocked + state, instead return to try and obtain the data. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + } + } + else + { + /* The timeout has expired. If there is still no data in the queue + exit, otherwise go back and try to read the data again. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + traceQUEUE_PEEK_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, BaseType_t * const pxHigherPriorityTaskWoken ) +{ +BaseType_t xReturn; +UBaseType_t uxSavedInterruptStatus; +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + configASSERT( pxQueue ); + configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) ); + + /* RTOS ports that support interrupt nesting have the concept of a maximum + system call (or maximum API call) interrupt priority. Interrupts that are + above the maximum system call priority are kept permanently enabled, even + when the RTOS kernel is in a critical section, but cannot make any calls to + FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + failure if a FreeRTOS API function is called from an interrupt that has been + assigned a priority above the configured maximum system call priority. + Only FreeRTOS functions that end in FromISR can be called from interrupts + that have been assigned a priority at or (logically) below the maximum + system call interrupt priority. FreeRTOS maintains a separate interrupt + safe API to ensure interrupt entry is as fast and as simple as possible. + More information (albeit Cortex-M specific) is provided on the following + link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting; + + /* Cannot block in an ISR, so check there is data available. */ + if( uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + const int8_t cRxLock = pxQueue->cRxLock; + + traceQUEUE_RECEIVE_FROM_ISR( pxQueue ); + + prvCopyDataFromQueue( pxQueue, pvBuffer ); + pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1; + + /* If the queue is locked the event list will not be modified. + Instead update the lock count so the task that unlocks the queue + will know that an ISR has removed data while the queue was + locked. */ + if( cRxLock == queueUNLOCKED ) + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + /* The task waiting has a higher priority than us so + force a context switch. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* Increment the lock count so the task that unlocks the queue + knows that data was removed while it was locked. */ + pxQueue->cRxLock = ( int8_t ) ( cRxLock + 1 ); + } + + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; + traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ); + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer ) +{ +BaseType_t xReturn; +UBaseType_t uxSavedInterruptStatus; +int8_t *pcOriginalReadPosition; +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + configASSERT( pxQueue ); + configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) ); + configASSERT( pxQueue->uxItemSize != 0 ); /* Can't peek a semaphore. */ + + /* RTOS ports that support interrupt nesting have the concept of a maximum + system call (or maximum API call) interrupt priority. Interrupts that are + above the maximum system call priority are kept permanently enabled, even + when the RTOS kernel is in a critical section, but cannot make any calls to + FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + failure if a FreeRTOS API function is called from an interrupt that has been + assigned a priority above the configured maximum system call priority. + Only FreeRTOS functions that end in FromISR can be called from interrupts + that have been assigned a priority at or (logically) below the maximum + system call interrupt priority. FreeRTOS maintains a separate interrupt + safe API to ensure interrupt entry is as fast and as simple as possible. + More information (albeit Cortex-M specific) is provided on the following + link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + /* Cannot block in an ISR, so check there is data available. */ + if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + traceQUEUE_PEEK_FROM_ISR( pxQueue ); + + /* Remember the read position so it can be reset as nothing is + actually being removed from the queue. */ + pcOriginalReadPosition = pxQueue->u.pcReadFrom; + prvCopyDataFromQueue( pxQueue, pvBuffer ); + pxQueue->u.pcReadFrom = pcOriginalReadPosition; + + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; + traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue ); + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) +{ +UBaseType_t uxReturn; + + configASSERT( xQueue ); + + taskENTER_CRITICAL(); + { + uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting; + } + taskEXIT_CRITICAL(); + + return uxReturn; +} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */ +/*-----------------------------------------------------------*/ + +UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) +{ +UBaseType_t uxReturn; +Queue_t *pxQueue; + + pxQueue = ( Queue_t * ) xQueue; + configASSERT( pxQueue ); + + taskENTER_CRITICAL(); + { + uxReturn = pxQueue->uxLength - pxQueue->uxMessagesWaiting; + } + taskEXIT_CRITICAL(); + + return uxReturn; +} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */ +/*-----------------------------------------------------------*/ + +UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) +{ +UBaseType_t uxReturn; + + configASSERT( xQueue ); + + uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting; + + return uxReturn; +} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */ +/*-----------------------------------------------------------*/ + +void vQueueDelete( QueueHandle_t xQueue ) +{ +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + configASSERT( pxQueue ); + traceQUEUE_DELETE( pxQueue ); + + #if ( configQUEUE_REGISTRY_SIZE > 0 ) + { + vQueueUnregisterQueue( pxQueue ); + } + #endif + + #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) ) + { + /* The queue can only have been allocated dynamically - free it + again. */ + vPortFree( pxQueue ); + } + #elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + { + /* The queue could have been allocated statically or dynamically, so + check before attempting to free the memory. */ + if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdFALSE ) + { + vPortFree( pxQueue ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #else + { + /* The queue must have been statically allocated, so is not going to be + deleted. Avoid compiler warnings about the unused parameter. */ + ( void ) pxQueue; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) + { + return ( ( Queue_t * ) xQueue )->uxQueueNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + void vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ) + { + ( ( Queue_t * ) xQueue )->uxQueueNumber = uxQueueNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) + { + return ( ( Queue_t * ) xQueue )->ucQueueType; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if( configUSE_MUTEXES == 1 ) + + static UBaseType_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue ) + { + UBaseType_t uxHighestPriorityOfWaitingTasks; + + /* If a task waiting for a mutex causes the mutex holder to inherit a + priority, but the waiting task times out, then the holder should + disinherit the priority - but only down to the highest priority of any + other tasks that are waiting for the same mutex. For this purpose, + return the priority of the highest priority task that is waiting for the + mutex. */ + if( listCURRENT_LIST_LENGTH( &( pxQueue->xTasksWaitingToReceive ) ) > 0 ) + { + uxHighestPriorityOfWaitingTasks = configMAX_PRIORITIES - listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( pxQueue->xTasksWaitingToReceive ) ); + } + else + { + uxHighestPriorityOfWaitingTasks = tskIDLE_PRIORITY; + } + + return uxHighestPriorityOfWaitingTasks; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition ) +{ +BaseType_t xReturn = pdFALSE; +UBaseType_t uxMessagesWaiting; + + /* This function is called from a critical section. */ + + uxMessagesWaiting = pxQueue->uxMessagesWaiting; + + if( pxQueue->uxItemSize == ( UBaseType_t ) 0 ) + { + #if ( configUSE_MUTEXES == 1 ) + { + if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) + { + /* The mutex is no longer being held. */ + xReturn = xTaskPriorityDisinherit( ( void * ) pxQueue->pxMutexHolder ); + pxQueue->pxMutexHolder = NULL; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_MUTEXES */ + } + else if( xPosition == queueSEND_TO_BACK ) + { + ( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. */ + pxQueue->pcWriteTo += pxQueue->uxItemSize; + if( pxQueue->pcWriteTo >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */ + { + pxQueue->pcWriteTo = pxQueue->pcHead; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + ( void ) memcpy( ( void * ) pxQueue->u.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + pxQueue->u.pcReadFrom -= pxQueue->uxItemSize; + if( pxQueue->u.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */ + { + pxQueue->u.pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( xPosition == queueOVERWRITE ) + { + if( uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + /* An item is not being added but overwritten, so subtract + one from the recorded number of items in the queue so when + one is added again below the number of recorded items remains + correct. */ + --uxMessagesWaiting; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1; + + return xReturn; +} +/*-----------------------------------------------------------*/ + +static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer ) +{ + if( pxQueue->uxItemSize != ( UBaseType_t ) 0 ) + { + pxQueue->u.pcReadFrom += pxQueue->uxItemSize; + if( pxQueue->u.pcReadFrom >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */ + { + pxQueue->u.pcReadFrom = pxQueue->pcHead; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports. Also previous logic ensures a null pointer can only be passed to memcpy() when the count is 0. */ + } +} +/*-----------------------------------------------------------*/ + +static void prvUnlockQueue( Queue_t * const pxQueue ) +{ + /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */ + + /* The lock counts contains the number of extra data items placed or + removed from the queue while the queue was locked. When a queue is + locked items can be added or removed, but the event lists cannot be + updated. */ + taskENTER_CRITICAL(); + { + int8_t cTxLock = pxQueue->cTxLock; + + /* See if data was added to the queue while it was locked. */ + while( cTxLock > queueLOCKED_UNMODIFIED ) + { + /* Data was posted while the queue was locked. Are any tasks + blocked waiting for data to become available? */ + #if ( configUSE_QUEUE_SETS == 1 ) + { + if( pxQueue->pxQueueSetContainer != NULL ) + { + if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) != pdFALSE ) + { + /* The queue is a member of a queue set, and posting to + the queue set caused a higher priority task to unblock. + A context switch is required. */ + vTaskMissedYield(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* Tasks that are removed from the event list will get + added to the pending ready list as the scheduler is still + suspended. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + context switch is required. */ + vTaskMissedYield(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + break; + } + } + } + #else /* configUSE_QUEUE_SETS */ + { + /* Tasks that are removed from the event list will get added to + the pending ready list as the scheduler is still suspended. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that + a context switch is required. */ + vTaskMissedYield(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + break; + } + } + #endif /* configUSE_QUEUE_SETS */ + + --cTxLock; + } + + pxQueue->cTxLock = queueUNLOCKED; + } + taskEXIT_CRITICAL(); + + /* Do the same for the Rx lock. */ + taskENTER_CRITICAL(); + { + int8_t cRxLock = pxQueue->cRxLock; + + while( cRxLock > queueLOCKED_UNMODIFIED ) + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + vTaskMissedYield(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + --cRxLock; + } + else + { + break; + } + } + + pxQueue->cRxLock = queueUNLOCKED; + } + taskEXIT_CRITICAL(); +} +/*-----------------------------------------------------------*/ + +static BaseType_t prvIsQueueEmpty( const Queue_t *pxQueue ) +{ +BaseType_t xReturn; + + taskENTER_CRITICAL(); + { + if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + taskEXIT_CRITICAL(); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) +{ +BaseType_t xReturn; + + configASSERT( xQueue ); + if( ( ( Queue_t * ) xQueue )->uxMessagesWaiting == ( UBaseType_t ) 0 ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} /*lint !e818 xQueue could not be pointer to const because it is a typedef. */ +/*-----------------------------------------------------------*/ + +static BaseType_t prvIsQueueFull( const Queue_t *pxQueue ) +{ +BaseType_t xReturn; + + taskENTER_CRITICAL(); + { + if( pxQueue->uxMessagesWaiting == pxQueue->uxLength ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + taskEXIT_CRITICAL(); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) +{ +BaseType_t xReturn; + + configASSERT( xQueue ); + if( ( ( Queue_t * ) xQueue )->uxMessagesWaiting == ( ( Queue_t * ) xQueue )->uxLength ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} /*lint !e818 xQueue could not be pointer to const because it is a typedef. */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_CO_ROUTINES == 1 ) + + BaseType_t xQueueCRSend( QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait ) + { + BaseType_t xReturn; + Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + /* If the queue is already full we may have to block. A critical section + is required to prevent an interrupt removing something from the queue + between the check to see if the queue is full and blocking on the queue. */ + portDISABLE_INTERRUPTS(); + { + if( prvIsQueueFull( pxQueue ) != pdFALSE ) + { + /* The queue is full - do we want to block or just leave without + posting? */ + if( xTicksToWait > ( TickType_t ) 0 ) + { + /* As this is called from a coroutine we cannot block directly, but + return indicating that we need to block. */ + vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) ); + portENABLE_INTERRUPTS(); + return errQUEUE_BLOCKED; + } + else + { + portENABLE_INTERRUPTS(); + return errQUEUE_FULL; + } + } + } + portENABLE_INTERRUPTS(); + + portDISABLE_INTERRUPTS(); + { + if( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) + { + /* There is room in the queue, copy the data into the queue. */ + prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK ); + xReturn = pdPASS; + + /* Were any co-routines waiting for data to become available? */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + /* In this instance the co-routine could be placed directly + into the ready list as we are within a critical section. + Instead the same pending ready list mechanism is used as if + the event were caused from within an interrupt. */ + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The co-routine waiting has a higher priority so record + that a yield might be appropriate. */ + xReturn = errQUEUE_YIELD; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + xReturn = errQUEUE_FULL; + } + } + portENABLE_INTERRUPTS(); + + return xReturn; + } + +#endif /* configUSE_CO_ROUTINES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_CO_ROUTINES == 1 ) + + BaseType_t xQueueCRReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait ) + { + BaseType_t xReturn; + Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + /* If the queue is already empty we may have to block. A critical section + is required to prevent an interrupt adding something to the queue + between the check to see if the queue is empty and blocking on the queue. */ + portDISABLE_INTERRUPTS(); + { + if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 ) + { + /* There are no messages in the queue, do we want to block or just + leave with nothing? */ + if( xTicksToWait > ( TickType_t ) 0 ) + { + /* As this is a co-routine we cannot block directly, but return + indicating that we need to block. */ + vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) ); + portENABLE_INTERRUPTS(); + return errQUEUE_BLOCKED; + } + else + { + portENABLE_INTERRUPTS(); + return errQUEUE_FULL; + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + portENABLE_INTERRUPTS(); + + portDISABLE_INTERRUPTS(); + { + if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + /* Data is available from the queue. */ + pxQueue->u.pcReadFrom += pxQueue->uxItemSize; + if( pxQueue->u.pcReadFrom >= pxQueue->pcTail ) + { + pxQueue->u.pcReadFrom = pxQueue->pcHead; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + --( pxQueue->uxMessagesWaiting ); + ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize ); + + xReturn = pdPASS; + + /* Were any co-routines waiting for space to become available? */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + /* In this instance the co-routine could be placed directly + into the ready list as we are within a critical section. + Instead the same pending ready list mechanism is used as if + the event were caused from within an interrupt. */ + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + xReturn = errQUEUE_YIELD; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + xReturn = pdFAIL; + } + } + portENABLE_INTERRUPTS(); + + return xReturn; + } + +#endif /* configUSE_CO_ROUTINES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_CO_ROUTINES == 1 ) + + BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t xCoRoutinePreviouslyWoken ) + { + Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + /* Cannot block within an ISR so if there is no space on the queue then + exit without doing anything. */ + if( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) + { + prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK ); + + /* We only want to wake one co-routine per ISR, so check that a + co-routine has not already been woken. */ + if( xCoRoutinePreviouslyWoken == pdFALSE ) + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + return pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xCoRoutinePreviouslyWoken; + } + +#endif /* configUSE_CO_ROUTINES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_CO_ROUTINES == 1 ) + + BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxCoRoutineWoken ) + { + BaseType_t xReturn; + Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + /* We cannot block from an ISR, so check there is data available. If + not then just leave without doing anything. */ + if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + /* Copy the data from the queue. */ + pxQueue->u.pcReadFrom += pxQueue->uxItemSize; + if( pxQueue->u.pcReadFrom >= pxQueue->pcTail ) + { + pxQueue->u.pcReadFrom = pxQueue->pcHead; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + --( pxQueue->uxMessagesWaiting ); + ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize ); + + if( ( *pxCoRoutineWoken ) == pdFALSE ) + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + *pxCoRoutineWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; + } + + return xReturn; + } + +#endif /* configUSE_CO_ROUTINES */ +/*-----------------------------------------------------------*/ + +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + + void vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcQueueName ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + { + UBaseType_t ux; + + /* See if there is an empty space in the registry. A NULL name denotes + a free slot. */ + for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ ) + { + if( xQueueRegistry[ ux ].pcQueueName == NULL ) + { + /* Store the information on this queue. */ + xQueueRegistry[ ux ].pcQueueName = pcQueueName; + xQueueRegistry[ ux ].xHandle = xQueue; + + traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName ); + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + +#endif /* configQUEUE_REGISTRY_SIZE */ +/*-----------------------------------------------------------*/ + +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + + const char *pcQueueGetName( QueueHandle_t xQueue ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + { + UBaseType_t ux; + const char *pcReturn = NULL; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + + /* Note there is nothing here to protect against another task adding or + removing entries from the registry while it is being searched. */ + for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ ) + { + if( xQueueRegistry[ ux ].xHandle == xQueue ) + { + pcReturn = xQueueRegistry[ ux ].pcQueueName; + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + return pcReturn; + } /*lint !e818 xQueue cannot be a pointer to const because it is a typedef. */ + +#endif /* configQUEUE_REGISTRY_SIZE */ +/*-----------------------------------------------------------*/ + +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + + void vQueueUnregisterQueue( QueueHandle_t xQueue ) + { + UBaseType_t ux; + + /* See if the handle of the queue being unregistered in actually in the + registry. */ + for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ ) + { + if( xQueueRegistry[ ux ].xHandle == xQueue ) + { + /* Set the name to NULL to show that this slot if free again. */ + xQueueRegistry[ ux ].pcQueueName = NULL; + + /* Set the handle to NULL to ensure the same queue handle cannot + appear in the registry twice if it is added, removed, then + added again. */ + xQueueRegistry[ ux ].xHandle = ( QueueHandle_t ) 0; + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */ + +#endif /* configQUEUE_REGISTRY_SIZE */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TIMERS == 1 ) + + void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) + { + Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + /* This function should not be called by application code hence the + 'Restricted' in its name. It is not part of the public API. It is + designed for use by kernel code, and has special calling requirements. + It can result in vListInsert() being called on a list that can only + possibly ever have one item in it, so the list will be fast, but even + so it should be called with the scheduler locked and not from a critical + section. */ + + /* Only do anything if there are no messages in the queue. This function + will not actually cause the task to block, just place it on a blocked + list. It will not block until the scheduler is unlocked - at which + time a yield will be performed. If an item is added to the queue while + the queue is locked, and the calling task blocks on the queue, then the + calling task will be immediately unblocked when the queue is unlocked. */ + prvLockQueue( pxQueue ); + if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0U ) + { + /* There is nothing in the queue, block for the specified period. */ + vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait, xWaitIndefinitely ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + prvUnlockQueue( pxQueue ); + } + +#endif /* configUSE_TIMERS */ +/*-----------------------------------------------------------*/ + +#if( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) + { + QueueSetHandle_t pxQueue; + + pxQueue = xQueueGenericCreate( uxEventQueueLength, ( UBaseType_t ) sizeof( Queue_t * ), queueQUEUE_TYPE_SET ); + + return pxQueue; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) + { + BaseType_t xReturn; + + taskENTER_CRITICAL(); + { + if( ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL ) + { + /* Cannot add a queue/semaphore to more than one queue set. */ + xReturn = pdFAIL; + } + else if( ( ( Queue_t * ) xQueueOrSemaphore )->uxMessagesWaiting != ( UBaseType_t ) 0 ) + { + /* Cannot add a queue/semaphore to a queue set if there are already + items in the queue/semaphore. */ + xReturn = pdFAIL; + } + else + { + ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet; + xReturn = pdPASS; + } + } + taskEXIT_CRITICAL(); + + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) + { + BaseType_t xReturn; + Queue_t * const pxQueueOrSemaphore = ( Queue_t * ) xQueueOrSemaphore; + + if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet ) + { + /* The queue was not a member of the set. */ + xReturn = pdFAIL; + } + else if( pxQueueOrSemaphore->uxMessagesWaiting != ( UBaseType_t ) 0 ) + { + /* It is dangerous to remove a queue from a set when the queue is + not empty because the queue set will still hold pending events for + the queue. */ + xReturn = pdFAIL; + } + else + { + taskENTER_CRITICAL(); + { + /* The queue is no longer contained in the set. */ + pxQueueOrSemaphore->pxQueueSetContainer = NULL; + } + taskEXIT_CRITICAL(); + xReturn = pdPASS; + } + + return xReturn; + } /*lint !e818 xQueueSet could not be declared as pointing to const as it is a typedef. */ + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, TickType_t const xTicksToWait ) + { + QueueSetMemberHandle_t xReturn = NULL; + + ( void ) xQueueReceive( ( QueueHandle_t ) xQueueSet, &xReturn, xTicksToWait ); /*lint !e961 Casting from one typedef to another is not redundant. */ + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) + { + QueueSetMemberHandle_t xReturn = NULL; + + ( void ) xQueueReceiveFromISR( ( QueueHandle_t ) xQueueSet, &xReturn, NULL ); /*lint !e961 Casting from one typedef to another is not redundant. */ + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue, const BaseType_t xCopyPosition ) + { + Queue_t *pxQueueSetContainer = pxQueue->pxQueueSetContainer; + BaseType_t xReturn = pdFALSE; + + /* This function must be called form a critical section. */ + + configASSERT( pxQueueSetContainer ); + configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength ); + + if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength ) + { + const int8_t cTxLock = pxQueueSetContainer->cTxLock; + + traceQUEUE_SEND( pxQueueSetContainer ); + + /* The data copied is the handle of the queue that contains data. */ + xReturn = prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition ); + + if( cTxLock == queueUNLOCKED ) + { + if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority. */ + xReturn = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + pxQueueSetContainer->cTxLock = ( int8_t ) ( cTxLock + 1 ); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ + + + + + + + + + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/readme.txt new file mode 100644 index 0000000..58480c5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/readme.txt @@ -0,0 +1,17 @@ +Each real time kernel port consists of three files that contain the core kernel +components and are common to every port, and one or more files that are +specific to a particular microcontroller and or compiler. + ++ The FreeRTOS/Source directory contains the three files that are common to +every port - list.c, queue.c and tasks.c. The kernel is contained within these +three files. croutine.c implements the optional co-routine functionality - which +is normally only used on very memory limited systems. + ++ The FreeRTOS/Source/Portable directory contains the files that are specific to +a particular microcontroller and or compiler. + ++ The FreeRTOS/Source/include directory contains the real time kernel header +files. + +See the readme file in the FreeRTOS/Source/Portable directory for more +information. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c new file mode 100644 index 0000000..c60045f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c @@ -0,0 +1,1199 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* Standard includes. */ +#include +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "stream_buffer.h" + +#if( configUSE_TASK_NOTIFICATIONS != 1 ) + #error configUSE_TASK_NOTIFICATIONS must be set to 1 to build stream_buffer.c +#endif + +/* Lint e961 and e750 are suppressed as a MISRA exception justified because the +MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the +header files above, but not in this file, in order to generate the correct +privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */ + +/* If the user has not provided application specific Rx notification macros, +or #defined the notification macros away, them provide default implementations +that uses task notifications. */ +/*lint -save -e9026 Function like macros allowed and needed here so they can be overidden. */ +#ifndef sbRECEIVE_COMPLETED + #define sbRECEIVE_COMPLETED( pxStreamBuffer ) \ + vTaskSuspendAll(); \ + { \ + if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL ) \ + { \ + ( void ) xTaskNotify( ( pxStreamBuffer )->xTaskWaitingToSend, \ + ( uint32_t ) 0, \ + eNoAction ); \ + ( pxStreamBuffer )->xTaskWaitingToSend = NULL; \ + } \ + } \ + ( void ) xTaskResumeAll(); +#endif /* sbRECEIVE_COMPLETED */ + +#ifndef sbRECEIVE_COMPLETED_FROM_ISR + #define sbRECEIVE_COMPLETED_FROM_ISR( pxStreamBuffer, \ + pxHigherPriorityTaskWoken ) \ + { \ + UBaseType_t uxSavedInterruptStatus; \ + \ + uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); \ + { \ + if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL ) \ + { \ + ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToSend, \ + ( uint32_t ) 0, \ + eNoAction, \ + pxHigherPriorityTaskWoken ); \ + ( pxStreamBuffer )->xTaskWaitingToSend = NULL; \ + } \ + } \ + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \ + } +#endif /* sbRECEIVE_COMPLETED_FROM_ISR */ + +/* If the user has not provided an application specific Tx notification macro, +or #defined the notification macro away, them provide a default implementation +that uses task notifications. */ +#ifndef sbSEND_COMPLETED + #define sbSEND_COMPLETED( pxStreamBuffer ) \ + vTaskSuspendAll(); \ + { \ + if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL ) \ + { \ + ( void ) xTaskNotify( ( pxStreamBuffer )->xTaskWaitingToReceive, \ + ( uint32_t ) 0, \ + eNoAction ); \ + ( pxStreamBuffer )->xTaskWaitingToReceive = NULL; \ + } \ + } \ + ( void ) xTaskResumeAll(); +#endif /* sbSEND_COMPLETED */ + +#ifndef sbSEND_COMPLETE_FROM_ISR + #define sbSEND_COMPLETE_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken ) \ + { \ + UBaseType_t uxSavedInterruptStatus; \ + \ + uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); \ + { \ + if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL ) \ + { \ + ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToReceive, \ + ( uint32_t ) 0, \ + eNoAction, \ + pxHigherPriorityTaskWoken ); \ + ( pxStreamBuffer )->xTaskWaitingToReceive = NULL; \ + } \ + } \ + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \ + } +#endif /* sbSEND_COMPLETE_FROM_ISR */ +/*lint -restore (9026) */ + +/* The number of bytes used to hold the length of a message in the buffer. */ +#define sbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( size_t ) ) + +/* Bits stored in the ucFlags field of the stream buffer. */ +#define sbFLAGS_IS_MESSAGE_BUFFER ( ( uint8_t ) 1 ) /* Set if the stream buffer was created as a message buffer, in which case it holds discrete messages rather than a stream. */ +#define sbFLAGS_IS_STATICALLY_ALLOCATED ( ( uint8_t ) 2 ) /* Set if the stream buffer was created using statically allocated memory. */ + +/*-----------------------------------------------------------*/ + +/* Structure that hold state information on the buffer. */ +typedef struct xSTREAM_BUFFER /*lint !e9058 Style convention uses tag. */ +{ + volatile size_t xTail; /* Index to the next item to read within the buffer. */ + volatile size_t xHead; /* Index to the next item to write within the buffer. */ + size_t xLength; /* The length of the buffer pointed to by pucBuffer. */ + size_t xTriggerLevelBytes; /* The number of bytes that must be in the stream buffer before a task that is waiting for data is unblocked. */ + volatile TaskHandle_t xTaskWaitingToReceive; /* Holds the handle of a task waiting for data, or NULL if no tasks are waiting. */ + volatile TaskHandle_t xTaskWaitingToSend; /* Holds the handle of a task waiting to send data to a message buffer that is full. */ + uint8_t *pucBuffer; /* Points to the buffer itself - that is - the RAM that stores the data passed through the buffer. */ + uint8_t ucFlags; + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxStreamBufferNumber; /* Used for tracing purposes. */ + #endif +} StreamBuffer_t; + +/* + * The number of bytes available to be read from the buffer. + */ +static size_t prvBytesInBuffer( const StreamBuffer_t * const pxStreamBuffer ) PRIVILEGED_FUNCTION; + +/* + * Add xCount bytes from pucData into the pxStreamBuffer message buffer. + * Returns the number of bytes written, which will either equal xCount in the + * success case, or 0 if there was not enough space in the buffer (in which case + * no data is written into the buffer). + */ +static size_t prvWriteBytesToBuffer( StreamBuffer_t * const pxStreamBuffer, const uint8_t *pucData, size_t xCount ) PRIVILEGED_FUNCTION; + +/* + * If the stream buffer is being used as a message buffer, then reads an entire + * message out of the buffer. If the stream buffer is being used as a stream + * buffer then read as many bytes as possible from the buffer. + * prvReadBytesFromBuffer() is called to actually extract the bytes from the + * buffer's data storage area. + */ +static size_t prvReadMessageFromBuffer( StreamBuffer_t *pxStreamBuffer, + void *pvRxData, + size_t xBufferLengthBytes, + size_t xBytesAvailable, + size_t xBytesToStoreMessageLength ) PRIVILEGED_FUNCTION; + +/* + * If the stream buffer is being used as a message buffer, then writes an entire + * message to the buffer. If the stream buffer is being used as a stream + * buffer then write as many bytes as possible to the buffer. + * prvWriteBytestoBuffer() is called to actually send the bytes to the buffer's + * data storage area. + */ +static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer, + const void * pvTxData, + size_t xDataLengthBytes, + size_t xSpace, + size_t xRequiredSpace ) PRIVILEGED_FUNCTION; + +/* + * Read xMaxCount bytes from the pxStreamBuffer message buffer and write them + * to pucData. + */ +static size_t prvReadBytesFromBuffer( StreamBuffer_t *pxStreamBuffer, + uint8_t *pucData, + size_t xMaxCount, + size_t xBytesAvailable ); PRIVILEGED_FUNCTION + +/* + * Called by both pxStreamBufferCreate() and pxStreamBufferCreateStatic() to + * initialise the members of the newly created stream buffer structure. + */ +static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer, + uint8_t * const pucBuffer, + size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer ) PRIVILEGED_FUNCTION; + +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer ) + { + uint8_t *pucAllocatedMemory; + + /* In case the stream buffer is going to be used as a message buffer + (that is, it will hold discrete messages with a little meta data that + says how big the next message is) check the buffer will be large enough + to hold at least one message. */ + configASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH ); + configASSERT( xTriggerLevelBytes <= xBufferSizeBytes ); + + /* A trigger level of 0 would cause a waiting task to unblock even when + the buffer was empty. */ + if( xTriggerLevelBytes == ( size_t ) 0 ) + { + xTriggerLevelBytes = ( size_t ) 1; /*lint !e9044 Parameter modified to ensure it doesn't have a dangerous value. */ + } + + /* A stream buffer requires a StreamBuffer_t structure and a buffer. + Both are allocated in a single call to pvPortMalloc(). The + StreamBuffer_t structure is placed at the start of the allocated memory + and the buffer follows immediately after. The requested size is + incremented so the free space is returned as the user would expect - + this is a quirk of the implementation that means otherwise the free + space would be reported as one byte smaller than would be logically + expected. */ + xBufferSizeBytes++; + pucAllocatedMemory = ( uint8_t * ) pvPortMalloc( xBufferSizeBytes + sizeof( StreamBuffer_t ) ); /*lint !e9079 malloc() only returns void*. */ + + if( pucAllocatedMemory != NULL ) + { + prvInitialiseNewStreamBuffer( ( StreamBuffer_t * ) pucAllocatedMemory, /* Structure at the start of the allocated memory. */ /*lint !e9087 Safe cast as allocated memory is aligned. */ /*lint !e826 Area is not too small and alignment is guaranteed provided malloc() behaves as expected and returns aligned buffer. */ + pucAllocatedMemory + sizeof( StreamBuffer_t ), /* Storage area follows. */ /*lint !e9016 Indexing past structure valid for uint8_t pointer, also storage area has no alignment requirement. */ + xBufferSizeBytes, + xTriggerLevelBytes, + xIsMessageBuffer ); + + traceSTREAM_BUFFER_CREATE( ( ( StreamBuffer_t * ) pucAllocatedMemory ), xIsMessageBuffer ); + } + else + { + traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ); + } + + return ( StreamBufferHandle_t * ) pucAllocatedMemory; /*lint !e9087 !e826 Safe cast as allocated memory is aligned. */ + } + +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + + StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer, + uint8_t * const pucStreamBufferStorageArea, + StaticStreamBuffer_t * const pxStaticStreamBuffer ) + { + StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer; /*lint !e740 !e9087 Safe cast as StaticStreamBuffer_t is opaque Streambuffer_t. */ + StreamBufferHandle_t xReturn; + + configASSERT( pucStreamBufferStorageArea ); + configASSERT( pxStaticStreamBuffer ); + configASSERT( xTriggerLevelBytes <= xBufferSizeBytes ); + + /* A trigger level of 0 would cause a waiting task to unblock even when + the buffer was empty. */ + if( xTriggerLevelBytes == ( size_t ) 0 ) + { + xTriggerLevelBytes = ( size_t ) 1; /*lint !e9044 Function parameter deliberately modified to ensure it is in range. */ + } + + /* In case the stream buffer is going to be used as a message buffer + (that is, it will hold discrete messages with a little meta data that + says how big the next message is) check the buffer will be large enough + to hold at least one message. */ + configASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH ); + + #if( configASSERT_DEFINED == 1 ) + { + /* Sanity check that the size of the structure used to declare a + variable of type StaticStreamBuffer_t equals the size of the real + message buffer structure. */ + volatile size_t xSize = sizeof( StaticStreamBuffer_t ); + configASSERT( xSize == sizeof( StreamBuffer_t ) ); + } + #endif /* configASSERT_DEFINED */ + + if( ( pucStreamBufferStorageArea != NULL ) && ( pxStaticStreamBuffer != NULL ) ) + { + prvInitialiseNewStreamBuffer( pxStreamBuffer, + pucStreamBufferStorageArea, + xBufferSizeBytes, + xTriggerLevelBytes, + xIsMessageBuffer ); + + /* Remember this was statically allocated in case it is ever deleted + again. */ + pxStreamBuffer->ucFlags |= sbFLAGS_IS_STATICALLY_ALLOCATED; + + traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer ); + + xReturn = ( StreamBufferHandle_t ) pxStaticStreamBuffer; /*lint !e9087 Data hiding requires cast to opaque type. */ + } + else + { + xReturn = NULL; + traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer ); + } + + return xReturn; + } + +#endif /* ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ +/*-----------------------------------------------------------*/ + +void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) +{ +StreamBuffer_t * pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ + + configASSERT( pxStreamBuffer ); + + traceSTREAM_BUFFER_DELETE( xStreamBuffer ); + + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) pdFALSE ) + { + #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + { + /* Both the structure and the buffer were allocated using a single call + to pvPortMalloc(), hence only one call to vPortFree() is required. */ + vPortFree( ( void * ) pxStreamBuffer ); /*lint !e9087 Standard free() semantics require void *, plus pxStreamBuffer was allocated by pvPortMalloc(). */ + } + #else + { + /* Should not be possible to get here, ucFlags must be corrupt. + Force an assert. */ + configASSERT( xStreamBuffer == ( StreamBufferHandle_t ) ~0 ); + } + #endif + } + else + { + /* The structure and buffer were not allocated dynamically and cannot be + freed - just scrub the structure so future use will assert. */ + memset( pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) ); + } +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) +{ +StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +BaseType_t xReturn = pdFAIL, xIsMessageBuffer; + +#if( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxStreamBufferNumber; +#endif + + configASSERT( pxStreamBuffer ); + + #if( configUSE_TRACE_FACILITY == 1 ) + { + /* Store the stream buffer number so it can be restored after the + reset. */ + uxStreamBufferNumber = pxStreamBuffer->uxStreamBufferNumber; + } + #endif + + /* Can only reset a message buffer if there are no tasks blocked on it. */ + if( pxStreamBuffer->xTaskWaitingToReceive == NULL ) + { + if( pxStreamBuffer->xTaskWaitingToSend == NULL ) + { + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xIsMessageBuffer = pdTRUE; + } + else + { + xIsMessageBuffer = pdFALSE; + } + + prvInitialiseNewStreamBuffer( pxStreamBuffer, + pxStreamBuffer->pucBuffer, + pxStreamBuffer->xLength, + pxStreamBuffer->xTriggerLevelBytes, + xIsMessageBuffer ); + xReturn = pdPASS; + + #if( configUSE_TRACE_FACILITY == 1 ) + { + pxStreamBuffer->uxStreamBufferNumber = uxStreamBufferNumber; + } + #endif + + traceSTREAM_BUFFER_RESET( xStreamBuffer ); + } + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel ) +{ +StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +BaseType_t xReturn; + + configASSERT( pxStreamBuffer ); + + /* It is not valid for the trigger level to be 0. */ + if( xTriggerLevel == ( size_t ) 0 ) + { + xTriggerLevel = ( size_t ) 1; /*lint !e9044 Parameter modified to ensure it doesn't have a dangerous value. */ + } + + /* The trigger level is the number of bytes that must be in the stream + buffer before a task that is waiting for data is unblocked. */ + if( xTriggerLevel <= pxStreamBuffer->xLength ) + { + pxStreamBuffer->xTriggerLevelBytes = xTriggerLevel; + xReturn = pdPASS; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ) +{ +const StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +size_t xSpace; + + configASSERT( pxStreamBuffer ); + + xSpace = pxStreamBuffer->xLength + pxStreamBuffer->xTail; + xSpace -= pxStreamBuffer->xHead; + xSpace -= ( size_t ) 1; + + if( xSpace >= pxStreamBuffer->xLength ) + { + xSpace -= pxStreamBuffer->xLength; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xSpace; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ) +{ +const StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +size_t xReturn; + + configASSERT( pxStreamBuffer ); + + xReturn = prvBytesInBuffer( pxStreamBuffer ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, + const void *pvTxData, + size_t xDataLengthBytes, + TickType_t xTicksToWait ) +{ +StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +size_t xReturn, xSpace = 0; +size_t xRequiredSpace = xDataLengthBytes; +TimeOut_t xTimeOut; + + configASSERT( pvTxData ); + configASSERT( pxStreamBuffer ); + + /* This send function is used to write to both message buffers and stream + buffers. If this is a message buffer then the space needed must be + increased by the amount of bytes needed to store the length of the + message. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( xTicksToWait != ( TickType_t ) 0 ) + { + vTaskSetTimeOutState( &xTimeOut ); + + do + { + /* Wait until the required number of bytes are free in the message + buffer. */ + taskENTER_CRITICAL(); + { + xSpace = xStreamBufferSpacesAvailable( pxStreamBuffer ); + + if( xSpace < xRequiredSpace ) + { + /* Clear notification state as going to wait for space. */ + ( void ) xTaskNotifyStateClear( NULL ); + + /* Should only be one writer. */ + configASSERT( pxStreamBuffer->xTaskWaitingToSend == NULL ); + pxStreamBuffer->xTaskWaitingToSend = xTaskGetCurrentTaskHandle(); + } + else + { + taskEXIT_CRITICAL(); + break; + } + } + taskEXIT_CRITICAL(); + + traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer ); + ( void ) xTaskNotifyWait( ( uint32_t ) 0, UINT32_MAX, NULL, xTicksToWait ); + pxStreamBuffer->xTaskWaitingToSend = NULL; + + } while( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( xSpace == ( size_t ) 0 ) + { + xSpace = xStreamBufferSpacesAvailable( pxStreamBuffer ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xReturn = prvWriteMessageToBuffer( pxStreamBuffer, pvTxData, xDataLengthBytes, xSpace, xRequiredSpace ); + + if( xReturn > ( size_t ) 0 ) + { + traceSTREAM_BUFFER_SEND( xStreamBuffer, xReturn ); + + /* Was a task waiting for the data? */ + if( prvBytesInBuffer( pxStreamBuffer ) >= pxStreamBuffer->xTriggerLevelBytes ) + { + sbSEND_COMPLETED( pxStreamBuffer ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer ); + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer, + const void *pvTxData, + size_t xDataLengthBytes, + BaseType_t * const pxHigherPriorityTaskWoken ) +{ +StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +size_t xReturn, xSpace; +size_t xRequiredSpace = xDataLengthBytes; + + configASSERT( pvTxData ); + configASSERT( pxStreamBuffer ); + + /* This send function is used to write to both message buffers and stream + buffers. If this is a message buffer then the space needed must be + increased by the amount of bytes needed to store the length of the + message. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xSpace = xStreamBufferSpacesAvailable( pxStreamBuffer ); + xReturn = prvWriteMessageToBuffer( pxStreamBuffer, pvTxData, xDataLengthBytes, xSpace, xRequiredSpace ); + + if( xReturn > ( size_t ) 0 ) + { + /* Was a task waiting for the data? */ + if( prvBytesInBuffer( pxStreamBuffer ) >= pxStreamBuffer->xTriggerLevelBytes ) + { + sbSEND_COMPLETE_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xReturn ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer, + const void * pvTxData, + size_t xDataLengthBytes, + size_t xSpace, + size_t xRequiredSpace ) +{ + BaseType_t xShouldWrite; + size_t xReturn; + + if( xSpace == ( size_t ) 0 ) + { + /* Doesn't matter if this is a stream buffer or a message buffer, there + is no space to write. */ + xShouldWrite = pdFALSE; + } + else if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) == ( uint8_t ) 0 ) + { + /* This is a stream buffer, as opposed to a message buffer, so writing a + stream of bytes rather than discrete messages. Write as many bytes as + possible. */ + xShouldWrite = pdTRUE; + xDataLengthBytes = configMIN( xDataLengthBytes, xSpace ); /*lint !e9044 Function parameter modified to ensure it is capped to available space. */ + } + else if( xSpace >= xRequiredSpace ) + { + /* This is a message buffer, as opposed to a stream buffer, and there + is enough space to write both the message length and the message itself + into the buffer. Start by writing the length of the data, the data + itself will be written later in this function. */ + xShouldWrite = pdTRUE; + ( void ) prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) &( xDataLengthBytes ), sbBYTES_TO_STORE_MESSAGE_LENGTH ); + } + else + { + /* There is space available, but not enough space. */ + xShouldWrite = pdFALSE; + } + + if( xShouldWrite != pdFALSE ) + { + /* Writes the data itself. */ + xReturn = prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) pvTxData, xDataLengthBytes ); /*lint !e9079 Storage buffer is implemented as uint8_t for ease of sizing, alighment and access. */ + } + else + { + xReturn = 0; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, + void *pvRxData, + size_t xBufferLengthBytes, + TickType_t xTicksToWait ) +{ +StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +size_t xReceivedLength = 0, xBytesAvailable, xBytesToStoreMessageLength; + + configASSERT( pvRxData ); + configASSERT( pxStreamBuffer ); + + /* This receive function is used by both message buffers, which store + discrete messages, and stream buffers, which store a continuous stream of + bytes. Discrete messages include an additional + sbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the + message. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH; + } + else + { + xBytesToStoreMessageLength = 0; + } + + if( xTicksToWait != ( TickType_t ) 0 ) + { + /* Checking if there is data and clearing the notification state must be + performed atomically. */ + taskENTER_CRITICAL(); + { + xBytesAvailable = prvBytesInBuffer( pxStreamBuffer ); + + /* If this function was invoked by a message buffer read then + xBytesToStoreMessageLength holds the number of bytes used to hold + the length of the next discrete message. If this function was + invoked by a stream buffer read then xBytesToStoreMessageLength will + be 0. */ + if( xBytesAvailable <= xBytesToStoreMessageLength ) + { + /* Clear notification state as going to wait for data. */ + ( void ) xTaskNotifyStateClear( NULL ); + + /* Should only be one reader. */ + configASSERT( pxStreamBuffer->xTaskWaitingToReceive == NULL ); + pxStreamBuffer->xTaskWaitingToReceive = xTaskGetCurrentTaskHandle(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + if( xBytesAvailable <= xBytesToStoreMessageLength ) + { + /* Wait for data to be available. */ + traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer ); + ( void ) xTaskNotifyWait( ( uint32_t ) 0, UINT32_MAX, NULL, xTicksToWait ); + pxStreamBuffer->xTaskWaitingToReceive = NULL; + + /* Recheck the data available after blocking. */ + xBytesAvailable = prvBytesInBuffer( pxStreamBuffer ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + xBytesAvailable = prvBytesInBuffer( pxStreamBuffer ); + } + + /* Whether receiving a discrete message (where xBytesToStoreMessageLength + holds the number of bytes used to store the message length) or a stream of + bytes (where xBytesToStoreMessageLength is zero), the number of bytes + available must be greater than xBytesToStoreMessageLength to be able to + read bytes from the buffer. */ + if( xBytesAvailable > xBytesToStoreMessageLength ) + { + xReceivedLength = prvReadMessageFromBuffer( pxStreamBuffer, pvRxData, xBufferLengthBytes, xBytesAvailable, xBytesToStoreMessageLength ); + + /* Was a task waiting for space in the buffer? */ + if( xReceivedLength != ( size_t ) 0 ) + { + traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength ); + sbRECEIVE_COMPLETED( pxStreamBuffer ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer ); + mtCOVERAGE_TEST_MARKER(); + } + + return xReceivedLength; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer, + void *pvRxData, + size_t xBufferLengthBytes, + BaseType_t * const pxHigherPriorityTaskWoken ) +{ +StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +size_t xReceivedLength = 0, xBytesAvailable, xBytesToStoreMessageLength; + + configASSERT( pvRxData ); + configASSERT( pxStreamBuffer ); + + /* This receive function is used by both message buffers, which store + discrete messages, and stream buffers, which store a continuous stream of + bytes. Discrete messages include an additional + sbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the + message. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH; + } + else + { + xBytesToStoreMessageLength = 0; + } + + xBytesAvailable = prvBytesInBuffer( pxStreamBuffer ); + + /* Whether receiving a discrete message (where xBytesToStoreMessageLength + holds the number of bytes used to store the message length) or a stream of + bytes (where xBytesToStoreMessageLength is zero), the number of bytes + available must be greater than xBytesToStoreMessageLength to be able to + read bytes from the buffer. */ + if( xBytesAvailable > xBytesToStoreMessageLength ) + { + xReceivedLength = prvReadMessageFromBuffer( pxStreamBuffer, pvRxData, xBufferLengthBytes, xBytesAvailable, xBytesToStoreMessageLength ); + + /* Was a task waiting for space in the buffer? */ + if( xReceivedLength != ( size_t ) 0 ) + { + sbRECEIVE_COMPLETED_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength ); + + return xReceivedLength; +} +/*-----------------------------------------------------------*/ + +static size_t prvReadMessageFromBuffer( StreamBuffer_t *pxStreamBuffer, + void *pvRxData, + size_t xBufferLengthBytes, + size_t xBytesAvailable, + size_t xBytesToStoreMessageLength ) +{ +size_t xOriginalTail, xReceivedLength, xNextMessageLength; + + if( xBytesToStoreMessageLength != ( size_t ) 0 ) + { + /* A discrete message is being received. First receive the length + of the message. A copy of the tail is stored so the buffer can be + returned to its prior state if the length of the message is too + large for the provided buffer. */ + xOriginalTail = pxStreamBuffer->xTail; + ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable ); + + /* Reduce the number of bytes available by the number of bytes just + read out. */ + xBytesAvailable -= xBytesToStoreMessageLength; + + /* Check there is enough space in the buffer provided by the + user. */ + if( xNextMessageLength > xBufferLengthBytes ) + { + /* The user has provided insufficient space to read the message + so return the buffer to its previous state (so the length of + the message is in the buffer again). */ + pxStreamBuffer->xTail = xOriginalTail; + xNextMessageLength = 0; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* A stream of bytes is being received (as opposed to a discrete + message), so read as many bytes as possible. */ + xNextMessageLength = xBufferLengthBytes; + } + + /* Read the actual data. */ + xReceivedLength = prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) pvRxData, xNextMessageLength, xBytesAvailable ); /*lint !e9079 Data storage area is implemented as uint8_t array for ease of sizing, indexing and alignment. */ + + return xReceivedLength; +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) +{ +const StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +BaseType_t xReturn; +size_t xTail; + + configASSERT( pxStreamBuffer ); + + /* True if no bytes are available. */ + xTail = pxStreamBuffer->xTail; + if( pxStreamBuffer->xHead == xTail ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ) +{ +BaseType_t xReturn; +size_t xBytesToStoreMessageLength; +const StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ + + configASSERT( pxStreamBuffer ); + + /* This generic version of the receive function is used by both message + buffers, which store discrete messages, and stream buffers, which store a + continuous stream of bytes. Discrete messages include an additional + sbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the message. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH; + } + else + { + xBytesToStoreMessageLength = 0; + } + + /* True if the available space equals zero. */ + if( xStreamBufferSpacesAvailable( xStreamBuffer ) <= xBytesToStoreMessageLength ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken ) +{ +StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +BaseType_t xReturn; +UBaseType_t uxSavedInterruptStatus; + + configASSERT( pxStreamBuffer ); + + uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); + { + if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL ) + { + ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToReceive, + ( uint32_t ) 0, + eNoAction, + pxHigherPriorityTaskWoken ); + ( pxStreamBuffer )->xTaskWaitingToReceive = NULL; + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken ) +{ +StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ +BaseType_t xReturn; +UBaseType_t uxSavedInterruptStatus; + + configASSERT( pxStreamBuffer ); + + uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); + { + if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL ) + { + ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToSend, + ( uint32_t ) 0, + eNoAction, + pxHigherPriorityTaskWoken ); + ( pxStreamBuffer )->xTaskWaitingToSend = NULL; + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +static size_t prvWriteBytesToBuffer( StreamBuffer_t * const pxStreamBuffer, const uint8_t *pucData, size_t xCount ) +{ +size_t xNextHead, xFirstLength; + + configASSERT( xCount > ( size_t ) 0 ); + + xNextHead = pxStreamBuffer->xHead; + + /* Calculate the number of bytes that can be added in the first write - + which may be less than the total number of bytes that need to be added if + the buffer will wrap back to the beginning. */ + xFirstLength = configMIN( pxStreamBuffer->xLength - xNextHead, xCount ); + + /* Write as many bytes as can be written in the first write. */ + configASSERT( ( xNextHead + xFirstLength ) <= pxStreamBuffer->xLength ); + memcpy( ( void* ) ( &( pxStreamBuffer->pucBuffer[ xNextHead ] ) ), ( const void * ) pucData, xFirstLength ); /*lint !e9087 memcpy() requires void *. */ + + /* If the number of bytes written was less than the number that could be + written in the first write... */ + if( xCount > xFirstLength ) + { + /* ...then write the remaining bytes to the start of the buffer. */ + configASSERT( ( xCount - xFirstLength ) <= pxStreamBuffer->xLength ); + memcpy( ( void * ) pxStreamBuffer->pucBuffer, ( const void * ) &( pucData[ xFirstLength ] ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xNextHead += xCount; + if( xNextHead >= pxStreamBuffer->xLength ) + { + xNextHead -= pxStreamBuffer->xLength; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + pxStreamBuffer->xHead = xNextHead; + + return xCount; +} +/*-----------------------------------------------------------*/ + +static size_t prvReadBytesFromBuffer( StreamBuffer_t *pxStreamBuffer, uint8_t *pucData, size_t xMaxCount, size_t xBytesAvailable ) +{ +size_t xCount, xFirstLength, xNextTail; + + /* Use the minimum of the wanted bytes and the available bytes. */ + xCount = configMIN( xBytesAvailable, xMaxCount ); + + if( xCount > ( size_t ) 0 ) + { + xNextTail = pxStreamBuffer->xTail; + + /* Calculate the number of bytes that can be read - which may be + less than the number wanted if the data wraps around to the start of + the buffer. */ + xFirstLength = configMIN( pxStreamBuffer->xLength - xNextTail, xCount ); + + /* Obtain the number of bytes it is possible to obtain in the first + read. Asserts check bounds of read and write. */ + configASSERT( xFirstLength <= xMaxCount ); + configASSERT( ( xNextTail + xFirstLength ) <= pxStreamBuffer->xLength ); + memcpy( ( void * ) pucData, ( const void * ) &( pxStreamBuffer->pucBuffer[ xNextTail ] ), xFirstLength ); /*lint !e9087 memcpy() requires void *. */ + + /* If the total number of wanted bytes is greater than the number + that could be read in the first read... */ + if( xCount > xFirstLength ) + { + /*...then read the remaining bytes from the start of the buffer. */ + configASSERT( xCount <= xMaxCount ); + memcpy( ( void * ) &( pucData[ xFirstLength ] ), ( void * ) ( pxStreamBuffer->pucBuffer ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Move the tail pointer to effectively remove the data read from + the buffer. */ + xNextTail += xCount; + + if( xNextTail >= pxStreamBuffer->xLength ) + { + xNextTail -= pxStreamBuffer->xLength; + } + + pxStreamBuffer->xTail = xNextTail; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xCount; +} +/*-----------------------------------------------------------*/ + +static size_t prvBytesInBuffer( const StreamBuffer_t * const pxStreamBuffer ) +{ +/* Returns the distance between xTail and xHead. */ +size_t xCount; + + xCount = pxStreamBuffer->xLength + pxStreamBuffer->xHead; + xCount -= pxStreamBuffer->xTail; + if ( xCount >= pxStreamBuffer->xLength ) + { + xCount -= pxStreamBuffer->xLength; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xCount; +} +/*-----------------------------------------------------------*/ + +static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer, + uint8_t * const pucBuffer, + size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer ) +{ + /* Assert here is deliberately writing to the entire buffer to ensure it can + be written to without generating exceptions, and is setting the buffer to a + known value to assist in development/debugging. */ + #if( configASSERT_DEFINED == 1 ) + { + /* The value written just has to be identifiable when looking at the + memory. Don't use 0xA5 as that is the stack fill value and could + result in confusion as to what is actually being observed. */ + const BaseType_t xWriteValue = 0x55; + configASSERT( memset( pucBuffer, ( int ) xWriteValue, xBufferSizeBytes ) == pucBuffer ); + } + #endif + + memset( ( void * ) pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) ); /*lint !e9087 memset() requires void *. */ + pxStreamBuffer->pucBuffer = pucBuffer; + pxStreamBuffer->xLength = xBufferSizeBytes; + pxStreamBuffer->xTriggerLevelBytes = xTriggerLevelBytes; + + if( xIsMessageBuffer != pdFALSE ) + { + pxStreamBuffer->ucFlags |= sbFLAGS_IS_MESSAGE_BUFFER; + } +} + +#if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxStreamBufferGetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer ) + { + return ( ( StreamBuffer_t * ) xStreamBuffer )->uxStreamBufferNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + void vStreamBufferSetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer, UBaseType_t uxStreamBufferNumber ) + { + ( ( StreamBuffer_t * ) xStreamBuffer )->uxStreamBufferNumber = uxStreamBufferNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + uint8_t ucStreamBufferGetStreamBufferType( StreamBufferHandle_t xStreamBuffer ) + { + return ( ( StreamBuffer_t * )xStreamBuffer )->ucFlags | sbFLAGS_IS_MESSAGE_BUFFER; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/tasks.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/tasks.c new file mode 100644 index 0000000..bb69765 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/tasks.c @@ -0,0 +1,5039 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* Standard includes. */ +#include +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "timers.h" +#include "stack_macros.h" + +/* Lint e961 and e750 are suppressed as a MISRA exception justified because the +MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the +header files above, but not in this file, in order to generate the correct +privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */ + +/* Set configUSE_STATS_FORMATTING_FUNCTIONS to 2 to include the stats formatting +functions but without including stdio.h here. */ +#if ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) + /* At the bottom of this file are two optional functions that can be used + to generate human readable text from the raw data generated by the + uxTaskGetSystemState() function. Note the formatting functions are provided + for convenience only, and are NOT considered part of the kernel. */ + #include +#endif /* configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) */ + +#if( configUSE_PREEMPTION == 0 ) + /* If the cooperative scheduler is being used then a yield should not be + performed just because a higher priority task has been woken. */ + #define taskYIELD_IF_USING_PREEMPTION() +#else + #define taskYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API() +#endif + +/* Values that can be assigned to the ucNotifyState member of the TCB. */ +#define taskNOT_WAITING_NOTIFICATION ( ( uint8_t ) 0 ) +#define taskWAITING_NOTIFICATION ( ( uint8_t ) 1 ) +#define taskNOTIFICATION_RECEIVED ( ( uint8_t ) 2 ) + +/* + * The value used to fill the stack of a task when the task is created. This + * is used purely for checking the high water mark for tasks. + */ +#define tskSTACK_FILL_BYTE ( 0xa5U ) + +/* Sometimes the FreeRTOSConfig.h settings only allow a task to be created using +dynamically allocated RAM, in which case when any task is deleted it is known +that both the task's stack and TCB need to be freed. Sometimes the +FreeRTOSConfig.h settings only allow a task to be created using statically +allocated RAM, in which case when any task is deleted it is known that neither +the task's stack or TCB should be freed. Sometimes the FreeRTOSConfig.h +settings allow a task to be created using either statically or dynamically +allocated RAM, in which case a member of the TCB is used to record whether the +stack and/or TCB were allocated statically or dynamically, so when a task is +deleted the RAM that was allocated dynamically is freed again and no attempt is +made to free the RAM that was allocated statically. +tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is only true if it is possible for a +task to be created using either statically or dynamically allocated RAM. Note +that if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with +a statically allocated stack and a dynamically allocated TCB. +!!!NOTE!!! If the definition of tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is +changed then the definition of StaticTask_t must also be updated. */ +#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) +#define tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB ( ( uint8_t ) 0 ) +#define tskSTATICALLY_ALLOCATED_STACK_ONLY ( ( uint8_t ) 1 ) +#define tskSTATICALLY_ALLOCATED_STACK_AND_TCB ( ( uint8_t ) 2 ) + +/* If any of the following are set then task stacks are filled with a known +value so the high water mark can be determined. If none of the following are +set then don't fill the stack so there is no unnecessary dependency on memset. */ +#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) + #define tskSET_NEW_STACKS_TO_KNOWN_VALUE 1 +#else + #define tskSET_NEW_STACKS_TO_KNOWN_VALUE 0 +#endif + +/* + * Macros used by vListTask to indicate which state a task is in. + */ +#define tskRUNNING_CHAR ( 'X' ) +#define tskBLOCKED_CHAR ( 'B' ) +#define tskREADY_CHAR ( 'R' ) +#define tskDELETED_CHAR ( 'D' ) +#define tskSUSPENDED_CHAR ( 'S' ) + +/* + * Some kernel aware debuggers require the data the debugger needs access to be + * global, rather than file scope. + */ +#ifdef portREMOVE_STATIC_QUALIFIER + #define static +#endif + +/* The name allocated to the Idle task. This can be overridden by defining +configIDLE_TASK_NAME in FreeRTOSConfig.h. */ +#ifndef configIDLE_TASK_NAME + #define configIDLE_TASK_NAME "IDLE" +#endif + +#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 ) + + /* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 then task selection is + performed in a generic way that is not optimised to any particular + microcontroller architecture. */ + + /* uxTopReadyPriority holds the priority of the highest priority ready + state task. */ + #define taskRECORD_READY_PRIORITY( uxPriority ) \ + { \ + if( ( uxPriority ) > uxTopReadyPriority ) \ + { \ + uxTopReadyPriority = ( uxPriority ); \ + } \ + } /* taskRECORD_READY_PRIORITY */ + + /*-----------------------------------------------------------*/ + + #define taskSELECT_HIGHEST_PRIORITY_TASK() \ + { \ + UBaseType_t uxTopPriority = uxTopReadyPriority; \ + \ + /* Find the highest priority queue that contains ready tasks. */ \ + while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopPriority ] ) ) ) \ + { \ + configASSERT( uxTopPriority ); \ + --uxTopPriority; \ + } \ + \ + /* listGET_OWNER_OF_NEXT_ENTRY indexes through the list, so the tasks of \ + the same priority get an equal share of the processor time. */ \ + listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \ + uxTopReadyPriority = uxTopPriority; \ + } /* taskSELECT_HIGHEST_PRIORITY_TASK */ + + /*-----------------------------------------------------------*/ + + /* Define away taskRESET_READY_PRIORITY() and portRESET_READY_PRIORITY() as + they are only required when a port optimised method of task selection is + being used. */ + #define taskRESET_READY_PRIORITY( uxPriority ) + #define portRESET_READY_PRIORITY( uxPriority, uxTopReadyPriority ) + +#else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ + + /* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 1 then task selection is + performed in a way that is tailored to the particular microcontroller + architecture being used. */ + + /* A port optimised version is provided. Call the port defined macros. */ + #define taskRECORD_READY_PRIORITY( uxPriority ) portRECORD_READY_PRIORITY( uxPriority, uxTopReadyPriority ) + + /*-----------------------------------------------------------*/ + + #define taskSELECT_HIGHEST_PRIORITY_TASK() \ + { \ + UBaseType_t uxTopPriority; \ + \ + /* Find the highest priority list that contains ready tasks. */ \ + portGET_HIGHEST_PRIORITY( uxTopPriority, uxTopReadyPriority ); \ + configASSERT( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ uxTopPriority ] ) ) > 0 ); \ + listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \ + } /* taskSELECT_HIGHEST_PRIORITY_TASK() */ + + /*-----------------------------------------------------------*/ + + /* A port optimised version is provided, call it only if the TCB being reset + is being referenced from a ready list. If it is referenced from a delayed + or suspended list then it won't be in a ready list. */ + #define taskRESET_READY_PRIORITY( uxPriority ) \ + { \ + if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ ( uxPriority ) ] ) ) == ( UBaseType_t ) 0 ) \ + { \ + portRESET_READY_PRIORITY( ( uxPriority ), ( uxTopReadyPriority ) ); \ + } \ + } + +#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ + +/*-----------------------------------------------------------*/ + +/* pxDelayedTaskList and pxOverflowDelayedTaskList are switched when the tick +count overflows. */ +#define taskSWITCH_DELAYED_LISTS() \ +{ \ + List_t *pxTemp; \ + \ + /* The delayed tasks list should be empty when the lists are switched. */ \ + configASSERT( ( listLIST_IS_EMPTY( pxDelayedTaskList ) ) ); \ + \ + pxTemp = pxDelayedTaskList; \ + pxDelayedTaskList = pxOverflowDelayedTaskList; \ + pxOverflowDelayedTaskList = pxTemp; \ + xNumOfOverflows++; \ + prvResetNextTaskUnblockTime(); \ +} + +/*-----------------------------------------------------------*/ + +/* + * Place the task represented by pxTCB into the appropriate ready list for + * the task. It is inserted at the end of the list. + */ +#define prvAddTaskToReadyList( pxTCB ) \ + traceMOVED_TASK_TO_READY_STATE( pxTCB ); \ + taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ + vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \ + tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) +/*-----------------------------------------------------------*/ + +/* + * Several functions take an TaskHandle_t parameter that can optionally be NULL, + * where NULL is used to indicate that the handle of the currently executing + * task should be used in place of the parameter. This macro simply checks to + * see if the parameter is NULL and returns a pointer to the appropriate TCB. + */ +#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( TCB_t * ) pxCurrentTCB : ( TCB_t * ) ( pxHandle ) ) + +/* The item value of the event list item is normally used to hold the priority +of the task to which it belongs (coded to allow it to be held in reverse +priority order). However, it is occasionally borrowed for other purposes. It +is important its value is not updated due to a task priority change while it is +being used for another purpose. The following bit definition is used to inform +the scheduler that the value should not be changed - in which case it is the +responsibility of whichever module is using the value to ensure it gets set back +to its original value when it is released. */ +#if( configUSE_16_BIT_TICKS == 1 ) + #define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x8000U +#else + #define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x80000000UL +#endif + +/* + * Task control block. A task control block (TCB) is allocated for each task, + * and stores task state information, including a pointer to the task's context + * (the task's run time environment, including register values) + */ +typedef struct tskTaskControlBlock +{ + volatile StackType_t *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */ + + #if ( portUSING_MPU_WRAPPERS == 1 ) + xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */ + #endif + + ListItem_t xStateListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */ + ListItem_t xEventListItem; /*< Used to reference a task from an event list. */ + UBaseType_t uxPriority; /*< The priority of the task. 0 is the lowest priority. */ + StackType_t *pxStack; /*< Points to the start of the stack. */ + char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + + #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) + StackType_t *pxEndOfStack; /*< Points to the highest valid address for the stack. */ + #endif + + #if ( portCRITICAL_NESTING_IN_TCB == 1 ) + UBaseType_t uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */ + #endif + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxTCBNumber; /*< Stores a number that increments each time a TCB is created. It allows debuggers to determine when a task has been deleted and then recreated. */ + UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */ + #endif + + #if ( configUSE_MUTEXES == 1 ) + UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */ + UBaseType_t uxMutexesHeld; + #endif + + #if ( configUSE_APPLICATION_TASK_TAG == 1 ) + TaskHookFunction_t pxTaskTag; + #endif + + #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 ) + void *pvThreadLocalStoragePointers[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ]; + #endif + + #if( configGENERATE_RUN_TIME_STATS == 1 ) + uint32_t ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */ + #endif + + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + /* Allocate a Newlib reent structure that is specific to this task. + Note Newlib support has been included by popular demand, but is not + used by the FreeRTOS maintainers themselves. FreeRTOS is not + responsible for resulting newlib operation. User must be familiar with + newlib and must provide system-wide implementations of the necessary + stubs. Be warned that (at the time of writing) the current newlib design + implements a system-wide malloc() that must be provided with locks. */ + struct _reent xNewLib_reent; + #endif + + #if( configUSE_TASK_NOTIFICATIONS == 1 ) + volatile uint32_t ulNotifiedValue; + volatile uint8_t ucNotifyState; + #endif + + /* See the comments above the definition of + tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */ + #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */ + uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */ + #endif + + #if( INCLUDE_xTaskAbortDelay == 1 ) + uint8_t ucDelayAborted; + #endif + +} tskTCB; + +/* The old tskTCB name is maintained above then typedefed to the new TCB_t name +below to enable the use of older kernel aware debuggers. */ +typedef tskTCB TCB_t; + +/*lint -save -e956 A manual analysis and inspection has been used to determine +which static variables must be declared volatile. */ + +PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL; + +/* Lists for ready and blocked tasks. --------------------*/ +PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ] = {0}; /*< Prioritised ready tasks. */ +PRIVILEGED_DATA static List_t xDelayedTaskList1 = {0}; /*< Delayed tasks. */ +PRIVILEGED_DATA static List_t xDelayedTaskList2 = {0}; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */ +PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList = NULL; /*< Points to the delayed task list currently being used. */ +PRIVILEGED_DATA static List_t * volatile pxOverflowDelayedTaskList = NULL; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */ +PRIVILEGED_DATA static List_t xPendingReadyList = {0}; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */ + +#if( INCLUDE_vTaskDelete == 1 ) + + PRIVILEGED_DATA static List_t xTasksWaitingTermination = {0}; /*< Tasks that have been deleted - but their memory not yet freed. */ + PRIVILEGED_DATA static volatile UBaseType_t uxDeletedTasksWaitingCleanUp = ( UBaseType_t ) 0U; + +#endif + +#if ( INCLUDE_vTaskSuspend == 1 ) + + PRIVILEGED_DATA static List_t xSuspendedTaskList = {0}; /*< Tasks that are currently suspended. */ + +#endif + +/* Other file private variables. --------------------------------*/ +PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U; +PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT; +PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY; +PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE; +PRIVILEGED_DATA static volatile UBaseType_t uxPendedTicks = ( UBaseType_t ) 0U; +PRIVILEGED_DATA static volatile BaseType_t xYieldPending = pdFALSE; +PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0; +PRIVILEGED_DATA static UBaseType_t uxTaskNumber = ( UBaseType_t ) 0U; +PRIVILEGED_DATA static volatile TickType_t xNextTaskUnblockTime = ( TickType_t ) 0U; /* Initialised to portMAX_DELAY before the scheduler starts. */ +PRIVILEGED_DATA static TaskHandle_t xIdleTaskHandle = NULL; /*< Holds the handle of the idle task. The idle task is created automatically when the scheduler is started. */ + +/* Context switches are held pending while the scheduler is suspended. Also, +interrupts must not manipulate the xStateListItem of a TCB, or any of the +lists the xStateListItem can be referenced from, if the scheduler is suspended. +If an interrupt needs to unblock a task while the scheduler is suspended then it +moves the task's event list item into the xPendingReadyList, ready for the +kernel to move the task from the pending ready list into the real ready list +when the scheduler is unsuspended. The pending ready list itself can only be +accessed from a critical section. */ +PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t ) pdFALSE; + +#if ( configGENERATE_RUN_TIME_STATS == 1 ) + + PRIVILEGED_DATA static uint32_t ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */ + PRIVILEGED_DATA static uint32_t ulTotalRunTime = 0UL; /*< Holds the total amount of execution time as defined by the run time counter clock. */ + +#endif + +/*lint -restore */ + +/*-----------------------------------------------------------*/ + +/* Callback function prototypes. --------------------------*/ +#if( configCHECK_FOR_STACK_OVERFLOW > 0 ) + extern void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ); +#endif + +#if( configUSE_TICK_HOOK > 0 ) + extern void vApplicationTickHook( void ); +#endif + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + extern void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ); +#endif + +/* File private functions. --------------------------------*/ + +/** + * Utility task that simply returns pdTRUE if the task referenced by xTask is + * currently in the Suspended state, or pdFALSE if the task referenced by xTask + * is in any other state. + */ +#if ( INCLUDE_vTaskSuspend == 1 ) + + static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +#endif /* INCLUDE_vTaskSuspend */ + +/* + * Utility to ready all the lists used by the scheduler. This is called + * automatically upon the creation of the first task. + */ +static void prvInitialiseTaskLists( void ) PRIVILEGED_FUNCTION; + +/* + * The idle task, which as all tasks is implemented as a never ending loop. + * The idle task is automatically created and added to the ready lists upon + * creation of the first user task. + * + * The portTASK_FUNCTION_PROTO() macro is used to allow port/compiler specific + * language extensions. The equivalent prototype for this function is: + * + * void prvIdleTask( void *pvParameters ); + * + */ +static portTASK_FUNCTION_PROTO( prvIdleTask, pvParameters ); + +/* + * Utility to free all memory allocated by the scheduler to hold a TCB, + * including the stack pointed to by the TCB. + * + * This does not free memory allocated by the task itself (i.e. memory + * allocated by calls to pvPortMalloc from within the tasks application code). + */ +#if ( INCLUDE_vTaskDelete == 1 ) + + static void prvDeleteTCB( TCB_t *pxTCB ) PRIVILEGED_FUNCTION; + +#endif + +/* + * Used only by the idle task. This checks to see if anything has been placed + * in the list of tasks waiting to be deleted. If so the task is cleaned up + * and its TCB deleted. + */ +static void prvCheckTasksWaitingTermination( void ) PRIVILEGED_FUNCTION; + +/* + * The currently executing task is entering the Blocked state. Add the task to + * either the current or the overflow delayed task list. + */ +static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, const BaseType_t xCanBlockIndefinitely ) PRIVILEGED_FUNCTION; + +/* + * Fills an TaskStatus_t structure with information on each task that is + * referenced from the pxList list (which may be a ready list, a delayed list, + * a suspended list, etc.). + * + * THIS FUNCTION IS INTENDED FOR DEBUGGING ONLY, AND SHOULD NOT BE CALLED FROM + * NORMAL APPLICATION CODE. + */ +#if ( configUSE_TRACE_FACILITY == 1 ) + + static UBaseType_t prvListTasksWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState ) PRIVILEGED_FUNCTION; + +#endif + +/* + * Searches pxList for a task with name pcNameToQuery - returning a handle to + * the task if it is found, or NULL if the task is not found. + */ +#if ( INCLUDE_xTaskGetHandle == 1 ) + + static TCB_t *prvSearchForNameWithinSingleList( List_t *pxList, const char pcNameToQuery[] ) PRIVILEGED_FUNCTION; + +#endif + +/* + * When a task is created, the stack of the task is filled with a known value. + * This function determines the 'high water mark' of the task stack by + * determining how much of the stack remains at the original preset value. + */ +#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) + + static uint16_t prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte ) PRIVILEGED_FUNCTION; + +#endif + +/* + * Return the amount of time, in ticks, that will pass before the kernel will + * next move a task from the Blocked state to the Running state. + * + * This conditional compilation should use inequality to 0, not equality to 1. + * This is to ensure portSUPPRESS_TICKS_AND_SLEEP() can be called when user + * defined low power mode implementations require configUSE_TICKLESS_IDLE to be + * set to a value other than 1. + */ +#if ( configUSE_TICKLESS_IDLE != 0 ) + + static TickType_t prvGetExpectedIdleTime( void ) PRIVILEGED_FUNCTION; + +#endif + +/* + * Set xNextTaskUnblockTime to the time at which the next Blocked state task + * will exit the Blocked state. + */ +static void prvResetNextTaskUnblockTime( void ); + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) + + /* + * Helper function used to pad task names with spaces when printing out + * human readable tables of task information. + */ + static char *prvWriteNameToBuffer( char *pcBuffer, const char *pcTaskName ) PRIVILEGED_FUNCTION; + +#endif + +/* + * Called after a Task_t structure has been allocated either statically or + * dynamically to fill in the structure's members. + */ +static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const uint32_t ulStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t * const pxCreatedTask, + TCB_t *pxNewTCB, + const MemoryRegion_t * const xRegions ) PRIVILEGED_FUNCTION; + +/* + * Called after a new task has been created and initialised to place the task + * under the control of the scheduler. + */ +static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION; + +/* + * freertos_tasks_c_additions_init() should only be called if the user definable + * macro FREERTOS_TASKS_C_ADDITIONS_INIT() is defined, as that is the only macro + * called by the function. + */ +#ifdef FREERTOS_TASKS_C_ADDITIONS_INIT + + static void freertos_tasks_c_additions_init( void ) PRIVILEGED_FUNCTION; + +#endif + +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + + TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const uint32_t ulStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + StackType_t * const puxStackBuffer, + StaticTask_t * const pxTaskBuffer ) + { + TCB_t *pxNewTCB; + TaskHandle_t xReturn; + + configASSERT( puxStackBuffer != NULL ); + configASSERT( pxTaskBuffer != NULL ); + + #if( configASSERT_DEFINED == 1 ) + { + /* Sanity check that the size of the structure used to declare a + variable of type StaticTask_t equals the size of the real task + structure. */ + volatile size_t xSize = sizeof( StaticTask_t ); + configASSERT( xSize == sizeof( TCB_t ) ); + } + #endif /* configASSERT_DEFINED */ + + + if( ( pxTaskBuffer != NULL ) && ( puxStackBuffer != NULL ) ) + { + /* The memory used for the task's TCB and stack are passed into this + function - use them. */ + pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */ + pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer; + + #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */ + { + /* Tasks can be created statically or dynamically, so note this + task was created statically in case the task is later deleted. */ + pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + + prvInitialiseNewTask( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, &xReturn, pxNewTCB, NULL ); + prvAddNewTaskToReadyList( pxNewTCB ); + } + else + { + xReturn = NULL; + } + + return xReturn; + } + +#endif /* SUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + + BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) + { + TCB_t *pxNewTCB; + BaseType_t xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; + + configASSERT( pxTaskDefinition->puxStackBuffer != NULL ); + configASSERT( pxTaskDefinition->pxTaskBuffer != NULL ); + + if( ( pxTaskDefinition->puxStackBuffer != NULL ) && ( pxTaskDefinition->pxTaskBuffer != NULL ) ) + { + /* Allocate space for the TCB. Where the memory comes from depends + on the implementation of the port malloc function and whether or + not static allocation is being used. */ + pxNewTCB = ( TCB_t * ) pxTaskDefinition->pxTaskBuffer; + + /* Store the stack location in the TCB. */ + pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer; + + #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) + { + /* Tasks can be created statically or dynamically, so note this + task was created statically in case the task is later deleted. */ + pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + + prvInitialiseNewTask( pxTaskDefinition->pvTaskCode, + pxTaskDefinition->pcName, + ( uint32_t ) pxTaskDefinition->usStackDepth, + pxTaskDefinition->pvParameters, + pxTaskDefinition->uxPriority, + pxCreatedTask, pxNewTCB, + pxTaskDefinition->xRegions ); + + prvAddNewTaskToReadyList( pxNewTCB ); + xReturn = pdPASS; + } + + return xReturn; + } + +#endif /* ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ +/*-----------------------------------------------------------*/ + +#if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) + { + TCB_t *pxNewTCB; + BaseType_t xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; + + configASSERT( pxTaskDefinition->puxStackBuffer ); + + if( pxTaskDefinition->puxStackBuffer != NULL ) + { + /* Allocate space for the TCB. Where the memory comes from depends + on the implementation of the port malloc function and whether or + not static allocation is being used. */ + pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) ); + + if( pxNewTCB != NULL ) + { + /* Store the stack location in the TCB. */ + pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer; + + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + /* Tasks can be created statically or dynamically, so note + this task had a statically allocated stack in case it is + later deleted. The TCB was allocated dynamically. */ + pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_ONLY; + } + #endif + + prvInitialiseNewTask( pxTaskDefinition->pvTaskCode, + pxTaskDefinition->pcName, + ( uint32_t ) pxTaskDefinition->usStackDepth, + pxTaskDefinition->pvParameters, + pxTaskDefinition->uxPriority, + pxCreatedTask, pxNewTCB, + pxTaskDefinition->xRegions ); + + prvAddNewTaskToReadyList( pxNewTCB ); + xReturn = pdPASS; + } + } + + return xReturn; + } + +#endif /* portUSING_MPU_WRAPPERS */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + BaseType_t xTaskCreate( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const configSTACK_DEPTH_TYPE usStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t * const pxCreatedTask ) + { + TCB_t *pxNewTCB; + BaseType_t xReturn; + + /* If the stack grows down then allocate the stack then the TCB so the stack + does not grow into the TCB. Likewise if the stack grows up then allocate + the TCB then the stack. */ + #if( portSTACK_GROWTH > 0 ) + { + /* Allocate space for the TCB. Where the memory comes from depends on + the implementation of the port malloc function and whether or not static + allocation is being used. */ + pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) ); + + if( pxNewTCB != NULL ) + { + /* Allocate space for the stack used by the task being created. + The base of the stack memory stored in the TCB so the task can + be deleted later if required. */ + pxNewTCB->pxStack = ( StackType_t * ) pvPortMalloc( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + + if( pxNewTCB->pxStack == NULL ) + { + /* Could not allocate the stack. Delete the allocated TCB. */ + vPortFree( pxNewTCB ); + pxNewTCB = NULL; + } + } + } + #else /* portSTACK_GROWTH */ + { + StackType_t *pxStack; + + /* Allocate space for the stack used by the task being created. */ + pxStack = ( StackType_t * ) pvPortMalloc( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + + if( pxStack != NULL ) + { + /* Allocate space for the TCB. */ + pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) ); /*lint !e961 MISRA exception as the casts are only redundant for some paths. */ + + if( pxNewTCB != NULL ) + { + /* Store the stack location in the TCB. */ + pxNewTCB->pxStack = pxStack; + } + else + { + /* The stack cannot be used as the TCB was not created. Free + it again. */ + vPortFree( pxStack ); + } + } + else + { + pxNewTCB = NULL; + } + } + #endif /* portSTACK_GROWTH */ + + if( pxNewTCB != NULL ) + { + #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */ + { + /* Tasks can be created statically or dynamically, so note this + task was created dynamically in case it is later deleted. */ + pxNewTCB->ucStaticallyAllocated = tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB; + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ + + prvInitialiseNewTask( pxTaskCode, pcName, ( uint32_t ) usStackDepth, pvParameters, uxPriority, pxCreatedTask, pxNewTCB, NULL ); + prvAddNewTaskToReadyList( pxNewTCB ); + xReturn = pdPASS; + } + else + { + xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; + } + + return xReturn; + } + +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const uint32_t ulStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t * const pxCreatedTask, + TCB_t *pxNewTCB, + const MemoryRegion_t * const xRegions ) +{ +StackType_t *pxTopOfStack; +UBaseType_t x; + + #if( portUSING_MPU_WRAPPERS == 1 ) + /* Should the task be created in privileged mode? */ + BaseType_t xRunPrivileged; + if( ( uxPriority & portPRIVILEGE_BIT ) != 0U ) + { + xRunPrivileged = pdTRUE; + } + else + { + xRunPrivileged = pdFALSE; + } + uxPriority &= ~portPRIVILEGE_BIT; + #endif /* portUSING_MPU_WRAPPERS == 1 */ + + /* Avoid dependency on memset() if it is not required. */ + #if( tskSET_NEW_STACKS_TO_KNOWN_VALUE == 1 ) + { + /* Fill the stack with a known value to assist debugging. */ + ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) ulStackDepth * sizeof( StackType_t ) ); + } + #endif /* tskSET_NEW_STACKS_TO_KNOWN_VALUE */ + + /* Calculate the top of stack address. This depends on whether the stack + grows from high memory to low (as per the 80x86) or vice versa. + portSTACK_GROWTH is used to make the result positive or negative as required + by the port. */ + #if( portSTACK_GROWTH < 0 ) + { + pxTopOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 ); + pxTopOfStack = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); /*lint !e923 MISRA exception. Avoiding casts between pointers and integers is not practical. Size differences accounted for using portPOINTER_SIZE_TYPE type. */ + + /* Check the alignment of the calculated top of stack is correct. */ + configASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) ); + + #if( configRECORD_STACK_HIGH_ADDRESS == 1 ) + { + /* Also record the stack's high address, which may assist + debugging. */ + pxNewTCB->pxEndOfStack = pxTopOfStack; + } + #endif /* configRECORD_STACK_HIGH_ADDRESS */ + } + #else /* portSTACK_GROWTH */ + { + pxTopOfStack = pxNewTCB->pxStack; + + /* Check the alignment of the stack buffer is correct. */ + configASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxNewTCB->pxStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) ); + + /* The other extreme of the stack space is required if stack checking is + performed. */ + pxNewTCB->pxEndOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 ); + } + #endif /* portSTACK_GROWTH */ + + /* Store the task name in the TCB. */ + for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ ) + { + pxNewTCB->pcTaskName[ x ] = pcName[ x ]; + + /* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than + configMAX_TASK_NAME_LEN characters just in case the memory after the + string is not accessible (extremely unlikely). */ + if( pcName[ x ] == 0x00 ) + { + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + /* Ensure the name string is terminated in the case that the string length + was greater or equal to configMAX_TASK_NAME_LEN. */ + pxNewTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = '\0'; + + /* This is used as an array index so must ensure it's not too large. First + remove the privilege bit if one is present. */ + if( uxPriority >= ( UBaseType_t ) configMAX_PRIORITIES ) + { + uxPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + pxNewTCB->uxPriority = uxPriority; + #if ( configUSE_MUTEXES == 1 ) + { + pxNewTCB->uxBasePriority = uxPriority; + pxNewTCB->uxMutexesHeld = 0; + } + #endif /* configUSE_MUTEXES */ + + vListInitialiseItem( &( pxNewTCB->xStateListItem ) ); + vListInitialiseItem( &( pxNewTCB->xEventListItem ) ); + + /* Set the pxNewTCB as a link back from the ListItem_t. This is so we can get + back to the containing TCB from a generic item in a list. */ + listSET_LIST_ITEM_OWNER( &( pxNewTCB->xStateListItem ), pxNewTCB ); + + /* Event lists are always in priority order. */ + listSET_LIST_ITEM_VALUE( &( pxNewTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + listSET_LIST_ITEM_OWNER( &( pxNewTCB->xEventListItem ), pxNewTCB ); + + #if ( portCRITICAL_NESTING_IN_TCB == 1 ) + { + pxNewTCB->uxCriticalNesting = ( UBaseType_t ) 0U; + } + #endif /* portCRITICAL_NESTING_IN_TCB */ + + #if ( configUSE_APPLICATION_TASK_TAG == 1 ) + { + pxNewTCB->pxTaskTag = NULL; + } + #endif /* configUSE_APPLICATION_TASK_TAG */ + + #if ( configGENERATE_RUN_TIME_STATS == 1 ) + { + pxNewTCB->ulRunTimeCounter = 0UL; + } + #endif /* configGENERATE_RUN_TIME_STATS */ + + #if ( portUSING_MPU_WRAPPERS == 1 ) + { + vPortStoreTaskMPUSettings( &( pxNewTCB->xMPUSettings ), xRegions, pxNewTCB->pxStack, ulStackDepth ); + } + #else + { + /* Avoid compiler warning about unreferenced parameter. */ + ( void ) xRegions; + } + #endif + + #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) + { + for( x = 0; x < ( UBaseType_t ) configNUM_THREAD_LOCAL_STORAGE_POINTERS; x++ ) + { + pxNewTCB->pvThreadLocalStoragePointers[ x ] = NULL; + } + } + #endif + + #if ( configUSE_TASK_NOTIFICATIONS == 1 ) + { + pxNewTCB->ulNotifiedValue = 0; + pxNewTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION; + } + #endif + + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + /* Initialise this task's Newlib reent structure. */ + _REENT_INIT_PTR( ( &( pxNewTCB->xNewLib_reent ) ) ); + } + #endif + + #if( INCLUDE_xTaskAbortDelay == 1 ) + { + pxNewTCB->ucDelayAborted = pdFALSE; + } + #endif + + /* Initialize the TCB stack to look as if the task was already running, + but had been interrupted by the scheduler. The return address is set + to the start of the task function. Once the stack has been initialised + the top of stack variable is updated. */ + #if( portUSING_MPU_WRAPPERS == 1 ) + { + pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters, xRunPrivileged ); + } + #else /* portUSING_MPU_WRAPPERS */ + { + pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters ); + } + #endif /* portUSING_MPU_WRAPPERS */ + + if( ( void * ) pxCreatedTask != NULL ) + { + /* Pass the handle out in an anonymous way. The handle can be used to + change the created task's priority, delete the created task, etc.*/ + *pxCreatedTask = ( TaskHandle_t ) pxNewTCB; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } +} +/*-----------------------------------------------------------*/ + +static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) +{ + /* Ensure interrupts don't access the task lists while the lists are being + updated. */ + taskENTER_CRITICAL(); + { + uxCurrentNumberOfTasks++; + if( pxCurrentTCB == NULL ) + { + /* There are no other tasks, or all the other tasks are in + the suspended state - make this the current task. */ + pxCurrentTCB = pxNewTCB; + + if( uxCurrentNumberOfTasks == ( UBaseType_t ) 1 ) + { + /* This is the first task to be created so do the preliminary + initialisation required. We will not recover if this call + fails, but we will report the failure. */ + prvInitialiseTaskLists(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* If the scheduler is not already running, make this task the + current task if it is the highest priority task to be created + so far. */ + if( xSchedulerRunning == pdFALSE ) + { + if( pxCurrentTCB->uxPriority <= pxNewTCB->uxPriority ) + { + pxCurrentTCB = pxNewTCB; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + uxTaskNumber++; + + #if ( configUSE_TRACE_FACILITY == 1 ) + { + /* Add a counter into the TCB for tracing only. */ + pxNewTCB->uxTCBNumber = uxTaskNumber; + } + #endif /* configUSE_TRACE_FACILITY */ + traceTASK_CREATE( pxNewTCB ); + + prvAddTaskToReadyList( pxNewTCB ); + + portSETUP_TCB( pxNewTCB ); + } + taskEXIT_CRITICAL(); + + if( xSchedulerRunning != pdFALSE ) + { + /* If the created task is of a higher priority than the current task + then it should run now. */ + if( pxCurrentTCB->uxPriority < pxNewTCB->uxPriority ) + { + taskYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } +} +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelete == 1 ) + + void vTaskDelete( TaskHandle_t xTaskToDelete ) + { + TCB_t *pxTCB; + + taskENTER_CRITICAL(); + { + /* If null is passed in here then it is the calling task that is + being deleted. */ + pxTCB = prvGetTCBFromHandle( xTaskToDelete ); + + /* Remove task from the ready list. */ + if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + taskRESET_READY_PRIORITY( pxTCB->uxPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Is the task waiting on an event also? */ + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) + { + ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Increment the uxTaskNumber also so kernel aware debuggers can + detect that the task lists need re-generating. This is done before + portPRE_TASK_DELETE_HOOK() as in the Windows port that macro will + not return. */ + uxTaskNumber++; + + if( pxTCB == pxCurrentTCB ) + { + /* A task is deleting itself. This cannot complete within the + task itself, as a context switch to another task is required. + Place the task in the termination list. The idle task will + check the termination list and free up any memory allocated by + the scheduler for the TCB and stack of the deleted task. */ + vListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xStateListItem ) ); + + /* Increment the ucTasksDeleted variable so the idle task knows + there is a task that has been deleted and that it should therefore + check the xTasksWaitingTermination list. */ + ++uxDeletedTasksWaitingCleanUp; + + /* The pre-delete hook is primarily for the Windows simulator, + in which Windows specific clean up operations are performed, + after which it is not possible to yield away from this task - + hence xYieldPending is used to latch that a context switch is + required. */ + portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPending ); + } + else + { + --uxCurrentNumberOfTasks; + prvDeleteTCB( pxTCB ); + + /* Reset the next expected unblock time in case it referred to + the task that has just been deleted. */ + prvResetNextTaskUnblockTime(); + } + + traceTASK_DELETE( pxTCB ); + } + taskEXIT_CRITICAL(); + + /* Force a reschedule if it is the currently running task that has just + been deleted. */ + if( xSchedulerRunning != pdFALSE ) + { + if( pxTCB == pxCurrentTCB ) + { + configASSERT( uxSchedulerSuspended == 0 ); + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + +#endif /* INCLUDE_vTaskDelete */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelayUntil == 1 ) + + void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) + { + TickType_t xTimeToWake; + BaseType_t xAlreadyYielded, xShouldDelay = pdFALSE; + + configASSERT( pxPreviousWakeTime ); + configASSERT( ( xTimeIncrement > 0U ) ); + configASSERT( uxSchedulerSuspended == 0 ); + + vTaskSuspendAll(); + { + /* Minor optimisation. The tick count cannot change in this + block. */ + const TickType_t xConstTickCount = xTickCount; + + /* Generate the tick time at which the task wants to wake. */ + xTimeToWake = *pxPreviousWakeTime + xTimeIncrement; + + if( xConstTickCount < *pxPreviousWakeTime ) + { + /* The tick count has overflowed since this function was + lasted called. In this case the only time we should ever + actually delay is if the wake time has also overflowed, + and the wake time is greater than the tick time. When this + is the case it is as if neither time had overflowed. */ + if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xConstTickCount ) ) + { + xShouldDelay = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* The tick time has not overflowed. In this case we will + delay if either the wake time has overflowed, and/or the + tick time is less than the wake time. */ + if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xConstTickCount ) ) + { + xShouldDelay = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + /* Update the wake time ready for the next call. */ + *pxPreviousWakeTime = xTimeToWake; + + if( xShouldDelay != pdFALSE ) + { + traceTASK_DELAY_UNTIL( xTimeToWake ); + + /* prvAddCurrentTaskToDelayedList() needs the block time, not + the time to wake, so subtract the current tick count. */ + prvAddCurrentTaskToDelayedList( xTimeToWake - xConstTickCount, pdFALSE ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + xAlreadyYielded = xTaskResumeAll(); + + /* Force a reschedule if xTaskResumeAll has not already done so, we may + have put ourselves to sleep. */ + if( xAlreadyYielded == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* INCLUDE_vTaskDelayUntil */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelay == 1 ) + + void vTaskDelay( const TickType_t xTicksToDelay ) + { + BaseType_t xAlreadyYielded = pdFALSE; + + /* A delay time of zero just forces a reschedule. */ + if( xTicksToDelay > ( TickType_t ) 0U ) + { + configASSERT( uxSchedulerSuspended == 0 ); + vTaskSuspendAll(); + { + traceTASK_DELAY(); + + /* A task that is removed from the event list while the + scheduler is suspended will not get placed in the ready + list or removed from the blocked list until the scheduler + is resumed. + + This task cannot be in an event list as it is the currently + executing task. */ + prvAddCurrentTaskToDelayedList( xTicksToDelay, pdFALSE ); + } + xAlreadyYielded = xTaskResumeAll(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Force a reschedule if xTaskResumeAll has not already done so, we may + have put ourselves to sleep. */ + if( xAlreadyYielded == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* INCLUDE_vTaskDelay */ +/*-----------------------------------------------------------*/ + +#if( ( INCLUDE_eTaskGetState == 1 ) || ( configUSE_TRACE_FACILITY == 1 ) ) + + eTaskState eTaskGetState( TaskHandle_t xTask ) + { + eTaskState eReturn; + List_t *pxStateList; + const TCB_t * const pxTCB = ( TCB_t * ) xTask; + + configASSERT( pxTCB ); + + if( pxTCB == pxCurrentTCB ) + { + /* The task calling this function is querying its own state. */ + eReturn = eRunning; + } + else + { + taskENTER_CRITICAL(); + { + pxStateList = ( List_t * ) listLIST_ITEM_CONTAINER( &( pxTCB->xStateListItem ) ); + } + taskEXIT_CRITICAL(); + + if( ( pxStateList == pxDelayedTaskList ) || ( pxStateList == pxOverflowDelayedTaskList ) ) + { + /* The task being queried is referenced from one of the Blocked + lists. */ + eReturn = eBlocked; + } + + #if ( INCLUDE_vTaskSuspend == 1 ) + else if( pxStateList == &xSuspendedTaskList ) + { + /* The task being queried is referenced from the suspended + list. Is it genuinely suspended or is it block + indefinitely? */ + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL ) + { + eReturn = eSuspended; + } + else + { + eReturn = eBlocked; + } + } + #endif + + #if ( INCLUDE_vTaskDelete == 1 ) + else if( ( pxStateList == &xTasksWaitingTermination ) || ( pxStateList == NULL ) ) + { + /* The task being queried is referenced from the deleted + tasks list, or it is not referenced from any lists at + all. */ + eReturn = eDeleted; + } + #endif + + else /*lint !e525 Negative indentation is intended to make use of pre-processor clearer. */ + { + /* If the task is not in any other state, it must be in the + Ready (including pending ready) state. */ + eReturn = eReady; + } + } + + return eReturn; + } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */ + +#endif /* INCLUDE_eTaskGetState */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_uxTaskPriorityGet == 1 ) + + UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask ) + { + TCB_t *pxTCB; + UBaseType_t uxReturn; + + taskENTER_CRITICAL(); + { + /* If null is passed in here then it is the priority of the that + called uxTaskPriorityGet() that is being queried. */ + pxTCB = prvGetTCBFromHandle( xTask ); + uxReturn = pxTCB->uxPriority; + } + taskEXIT_CRITICAL(); + + return uxReturn; + } + +#endif /* INCLUDE_uxTaskPriorityGet */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_uxTaskPriorityGet == 1 ) + + UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask ) + { + TCB_t *pxTCB; + UBaseType_t uxReturn, uxSavedInterruptState; + + /* RTOS ports that support interrupt nesting have the concept of a + maximum system call (or maximum API call) interrupt priority. + Interrupts that are above the maximum system call priority are keep + permanently enabled, even when the RTOS kernel is in a critical section, + but cannot make any calls to FreeRTOS API functions. If configASSERT() + is defined in FreeRTOSConfig.h then + portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + failure if a FreeRTOS API function is called from an interrupt that has + been assigned a priority above the configured maximum system call + priority. Only FreeRTOS functions that end in FromISR can be called + from interrupts that have been assigned a priority at or (logically) + below the maximum system call interrupt priority. FreeRTOS maintains a + separate interrupt safe API to ensure interrupt entry is as fast and as + simple as possible. More information (albeit Cortex-M specific) is + provided on the following link: + http://www.freertos.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptState = portSET_INTERRUPT_MASK_FROM_ISR(); + { + /* If null is passed in here then it is the priority of the calling + task that is being queried. */ + pxTCB = prvGetTCBFromHandle( xTask ); + uxReturn = pxTCB->uxPriority; + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptState ); + + return uxReturn; + } + +#endif /* INCLUDE_uxTaskPriorityGet */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskPrioritySet == 1 ) + + void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) + { + TCB_t *pxTCB; + UBaseType_t uxCurrentBasePriority, uxPriorityUsedOnEntry; + BaseType_t xYieldRequired = pdFALSE; + + configASSERT( ( uxNewPriority < configMAX_PRIORITIES ) ); + + /* Ensure the new priority is valid. */ + if( uxNewPriority >= ( UBaseType_t ) configMAX_PRIORITIES ) + { + uxNewPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + taskENTER_CRITICAL(); + { + /* If null is passed in here then it is the priority of the calling + task that is being changed. */ + pxTCB = prvGetTCBFromHandle( xTask ); + + traceTASK_PRIORITY_SET( pxTCB, uxNewPriority ); + + #if ( configUSE_MUTEXES == 1 ) + { + uxCurrentBasePriority = pxTCB->uxBasePriority; + } + #else + { + uxCurrentBasePriority = pxTCB->uxPriority; + } + #endif + + if( uxCurrentBasePriority != uxNewPriority ) + { + /* The priority change may have readied a task of higher + priority than the calling task. */ + if( uxNewPriority > uxCurrentBasePriority ) + { + if( pxTCB != pxCurrentTCB ) + { + /* The priority of a task other than the currently + running task is being raised. Is the priority being + raised above that of the running task? */ + if( uxNewPriority >= pxCurrentTCB->uxPriority ) + { + xYieldRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* The priority of the running task is being raised, + but the running task must already be the highest + priority task able to run so no yield is required. */ + } + } + else if( pxTCB == pxCurrentTCB ) + { + /* Setting the priority of the running task down means + there may now be another task of higher priority that + is ready to execute. */ + xYieldRequired = pdTRUE; + } + else + { + /* Setting the priority of any other task down does not + require a yield as the running task must be above the + new priority of the task being modified. */ + } + + /* Remember the ready list the task might be referenced from + before its uxPriority member is changed so the + taskRESET_READY_PRIORITY() macro can function correctly. */ + uxPriorityUsedOnEntry = pxTCB->uxPriority; + + #if ( configUSE_MUTEXES == 1 ) + { + /* Only change the priority being used if the task is not + currently using an inherited priority. */ + if( pxTCB->uxBasePriority == pxTCB->uxPriority ) + { + pxTCB->uxPriority = uxNewPriority; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* The base priority gets set whatever. */ + pxTCB->uxBasePriority = uxNewPriority; + } + #else + { + pxTCB->uxPriority = uxNewPriority; + } + #endif + + /* Only reset the event list item value if the value is not + being used for anything else. */ + if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL ) + { + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxNewPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* If the task is in the blocked or suspended list we need do + nothing more than change its priority variable. However, if + the task is in a ready list it needs to be removed and placed + in the list appropriate to its new priority. */ + if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xStateListItem ) ) != pdFALSE ) + { + /* The task is currently in its ready list - remove before + adding it to it's new ready list. As we are in a critical + section we can do this even if the scheduler is suspended. */ + if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + /* It is known that the task is in its ready list so + there is no need to check again and the port level + reset macro can be called directly. */ + portRESET_READY_PRIORITY( uxPriorityUsedOnEntry, uxTopReadyPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + prvAddTaskToReadyList( pxTCB ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( xYieldRequired != pdFALSE ) + { + taskYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Remove compiler warning about unused variables when the port + optimised task selection is not being used. */ + ( void ) uxPriorityUsedOnEntry; + } + } + taskEXIT_CRITICAL(); + } + +#endif /* INCLUDE_vTaskPrioritySet */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskSuspend == 1 ) + + void vTaskSuspend( TaskHandle_t xTaskToSuspend ) + { + TCB_t *pxTCB; + + taskENTER_CRITICAL(); + { + /* If null is passed in here then it is the running task that is + being suspended. */ + pxTCB = prvGetTCBFromHandle( xTaskToSuspend ); + + traceTASK_SUSPEND( pxTCB ); + + /* Remove task from the ready/delayed list and place in the + suspended list. */ + if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + taskRESET_READY_PRIORITY( pxTCB->uxPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Is the task waiting on an event also? */ + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) + { + ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) ); + + #if( configUSE_TASK_NOTIFICATIONS == 1 ) + { + if( pxTCB->ucNotifyState == taskWAITING_NOTIFICATION ) + { + /* The task was blocked to wait for a notification, but is + now suspended, so no notification was received. */ + pxTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION; + } + } + #endif + } + taskEXIT_CRITICAL(); + + if( xSchedulerRunning != pdFALSE ) + { + /* Reset the next expected unblock time in case it referred to the + task that is now in the Suspended state. */ + taskENTER_CRITICAL(); + { + prvResetNextTaskUnblockTime(); + } + taskEXIT_CRITICAL(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( pxTCB == pxCurrentTCB ) + { + if( xSchedulerRunning != pdFALSE ) + { + /* The current task has just been suspended. */ + configASSERT( uxSchedulerSuspended == 0 ); + portYIELD_WITHIN_API(); + } + else + { + /* The scheduler is not running, but the task that was pointed + to by pxCurrentTCB has just been suspended and pxCurrentTCB + must be adjusted to point to a different task. */ + if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == uxCurrentNumberOfTasks ) + { + /* No other tasks are ready, so set pxCurrentTCB back to + NULL so when the next task is created pxCurrentTCB will + be set to point to it no matter what its relative priority + is. */ + pxCurrentTCB = NULL; + } + else + { + vTaskSwitchContext(); + } + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* INCLUDE_vTaskSuspend */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskSuspend == 1 ) + + static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask ) + { + BaseType_t xReturn = pdFALSE; + const TCB_t * const pxTCB = ( TCB_t * ) xTask; + + /* Accesses xPendingReadyList so must be called from a critical + section. */ + + /* It does not make sense to check if the calling task is suspended. */ + configASSERT( xTask ); + + /* Is the task being resumed actually in the suspended list? */ + if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xStateListItem ) ) != pdFALSE ) + { + /* Has the task already been resumed from within an ISR? */ + if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) == pdFALSE ) + { + /* Is it in the suspended list because it is in the Suspended + state, or because is is blocked with no timeout? */ + if( listIS_CONTAINED_WITHIN( NULL, &( pxTCB->xEventListItem ) ) != pdFALSE ) /*lint !e961. The cast is only redundant when NULL is used. */ + { + xReturn = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xReturn; + } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */ + +#endif /* INCLUDE_vTaskSuspend */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskSuspend == 1 ) + + void vTaskResume( TaskHandle_t xTaskToResume ) + { + TCB_t * const pxTCB = ( TCB_t * ) xTaskToResume; + + /* It does not make sense to resume the calling task. */ + configASSERT( xTaskToResume ); + + /* The parameter cannot be NULL as it is impossible to resume the + currently executing task. */ + if( ( pxTCB != NULL ) && ( pxTCB != pxCurrentTCB ) ) + { + taskENTER_CRITICAL(); + { + if( prvTaskIsTaskSuspended( pxTCB ) != pdFALSE ) + { + traceTASK_RESUME( pxTCB ); + + /* The ready list can be accessed even if the scheduler is + suspended because this is inside a critical section. */ + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + + /* A higher priority task may have just been resumed. */ + if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) + { + /* This yield may not cause the task just resumed to run, + but will leave the lists in the correct state for the + next yield. */ + taskYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* INCLUDE_vTaskSuspend */ + +/*-----------------------------------------------------------*/ + +#if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) + + BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) + { + BaseType_t xYieldRequired = pdFALSE; + TCB_t * const pxTCB = ( TCB_t * ) xTaskToResume; + UBaseType_t uxSavedInterruptStatus; + + configASSERT( xTaskToResume ); + + /* RTOS ports that support interrupt nesting have the concept of a + maximum system call (or maximum API call) interrupt priority. + Interrupts that are above the maximum system call priority are keep + permanently enabled, even when the RTOS kernel is in a critical section, + but cannot make any calls to FreeRTOS API functions. If configASSERT() + is defined in FreeRTOSConfig.h then + portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + failure if a FreeRTOS API function is called from an interrupt that has + been assigned a priority above the configured maximum system call + priority. Only FreeRTOS functions that end in FromISR can be called + from interrupts that have been assigned a priority at or (logically) + below the maximum system call interrupt priority. FreeRTOS maintains a + separate interrupt safe API to ensure interrupt entry is as fast and as + simple as possible. More information (albeit Cortex-M specific) is + provided on the following link: + http://www.freertos.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + if( prvTaskIsTaskSuspended( pxTCB ) != pdFALSE ) + { + traceTASK_RESUME_FROM_ISR( pxTCB ); + + /* Check the ready lists can be accessed. */ + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + /* Ready lists can be accessed so move the task from the + suspended list to the ready list directly. */ + if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) + { + xYieldRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + } + else + { + /* The delayed or ready lists cannot be accessed so the task + is held in the pending ready list until the scheduler is + unsuspended. */ + vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) ); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xYieldRequired; + } + +#endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */ +/*-----------------------------------------------------------*/ + +void vTaskStartScheduler( void ) +{ +BaseType_t xReturn; + + /* Add the idle task at the lowest priority. */ + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + StaticTask_t *pxIdleTaskTCBBuffer = NULL; + StackType_t *pxIdleTaskStackBuffer = NULL; + uint32_t ulIdleTaskStackSize; + + /* The Idle task is created using user provided RAM - obtain the + address of the RAM then create the idle task. */ + vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &ulIdleTaskStackSize ); + xIdleTaskHandle = xTaskCreateStatic( prvIdleTask, + configIDLE_TASK_NAME, + ulIdleTaskStackSize, + ( void * ) NULL, /*lint !e961. The cast is not redundant for all compilers. */ + ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), + pxIdleTaskStackBuffer, + pxIdleTaskTCBBuffer ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */ + + if( xIdleTaskHandle != NULL ) + { + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; + } + } + #else + { + /* The Idle task is being created using dynamically allocated RAM. */ + xReturn = xTaskCreate( prvIdleTask, + configIDLE_TASK_NAME, + configMINIMAL_STACK_SIZE, + ( void * ) NULL, + ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), + &xIdleTaskHandle ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */ + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ + + #if ( configUSE_TIMERS == 1 ) + { + if( xReturn == pdPASS ) + { + xReturn = xTimerCreateTimerTask(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_TIMERS */ + + if( xReturn == pdPASS ) + { + /* freertos_tasks_c_additions_init() should only be called if the user + definable macro FREERTOS_TASKS_C_ADDITIONS_INIT() is defined, as that is + the only macro called by the function. */ + #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT + { + freertos_tasks_c_additions_init(); + } + #endif + + /* Interrupts are turned off here, to ensure a tick does not occur + before or during the call to xPortStartScheduler(). The stacks of + the created tasks contain a status word with interrupts switched on + so interrupts will automatically get re-enabled when the first task + starts to run. */ + portDISABLE_INTERRUPTS(); + + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + /* Switch Newlib's _impure_ptr variable to point to the _reent + structure specific to the task that will run first. */ + _impure_ptr = &( pxCurrentTCB->xNewLib_reent ); + } + #endif /* configUSE_NEWLIB_REENTRANT */ + + xNextTaskUnblockTime = portMAX_DELAY; + xSchedulerRunning = pdTRUE; + xTickCount = ( TickType_t ) 0U; + + /* If configGENERATE_RUN_TIME_STATS is defined then the following + macro must be defined to configure the timer/counter used to generate + the run time counter time base. NOTE: If configGENERATE_RUN_TIME_STATS + is set to 0 and the following line fails to build then ensure you do not + have portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() defined in your + FreeRTOSConfig.h file. */ + portCONFIGURE_TIMER_FOR_RUN_TIME_STATS(); + + /* Setting up the timer tick is hardware specific and thus in the + portable interface. */ + if( xPortStartScheduler() != pdFALSE ) + { + /* Should not reach here as if the scheduler is running the + function will not return. */ + } + else + { + /* Should only reach here if a task calls xTaskEndScheduler(). */ + } + } + else + { + /* This line will only be reached if the kernel could not be started, + because there was not enough FreeRTOS heap to create the idle task + or the timer task. */ + configASSERT( xReturn != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ); + } + + /* Prevent compiler warnings if INCLUDE_xTaskGetIdleTaskHandle is set to 0, + meaning xIdleTaskHandle is not used anywhere else. */ + ( void ) xIdleTaskHandle; +} +/*-----------------------------------------------------------*/ + +void vTaskEndScheduler( void ) +{ + /* Stop the scheduler interrupts and call the portable scheduler end + routine so the original ISRs can be restored if necessary. The port + layer must ensure interrupts enable bit is left in the correct state. */ + portDISABLE_INTERRUPTS(); + xSchedulerRunning = pdFALSE; + vPortEndScheduler(); +} +/*----------------------------------------------------------*/ + +void vTaskSuspendAll( void ) +{ + /* A critical section is not required as the variable is of type + BaseType_t. Please read Richard Barry's reply in the following link to a + post in the FreeRTOS support forum before reporting this as a bug! - + http://goo.gl/wu4acr */ + ++uxSchedulerSuspended; +} +/*----------------------------------------------------------*/ + +#if ( configUSE_TICKLESS_IDLE != 0 ) + + static TickType_t prvGetExpectedIdleTime( void ) + { + TickType_t xReturn; + UBaseType_t uxHigherPriorityReadyTasks = pdFALSE; + + /* uxHigherPriorityReadyTasks takes care of the case where + configUSE_PREEMPTION is 0, so there may be tasks above the idle priority + task that are in the Ready state, even though the idle task is + running. */ + #if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 ) + { + if( uxTopReadyPriority > tskIDLE_PRIORITY ) + { + uxHigherPriorityReadyTasks = pdTRUE; + } + } + #else + { + const UBaseType_t uxLeastSignificantBit = ( UBaseType_t ) 0x01; + + /* When port optimised task selection is used the uxTopReadyPriority + variable is used as a bit map. If bits other than the least + significant bit are set then there are tasks that have a priority + above the idle priority that are in the Ready state. This takes + care of the case where the co-operative scheduler is in use. */ + if( uxTopReadyPriority > uxLeastSignificantBit ) + { + uxHigherPriorityReadyTasks = pdTRUE; + } + } + #endif + + if( pxCurrentTCB->uxPriority > tskIDLE_PRIORITY ) + { + xReturn = 0; + } + else if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > 1 ) + { + /* There are other idle priority tasks in the ready state. If + time slicing is used then the very next tick interrupt must be + processed. */ + xReturn = 0; + } + else if( uxHigherPriorityReadyTasks != pdFALSE ) + { + /* There are tasks in the Ready state that have a priority above the + idle priority. This path can only be reached if + configUSE_PREEMPTION is 0. */ + xReturn = 0; + } + else + { + xReturn = xNextTaskUnblockTime - xTickCount; + } + + return xReturn; + } + +#endif /* configUSE_TICKLESS_IDLE */ +/*----------------------------------------------------------*/ + +BaseType_t xTaskResumeAll( void ) +{ +TCB_t *pxTCB = NULL; +BaseType_t xAlreadyYielded = pdFALSE; + + /* If uxSchedulerSuspended is zero then this function does not match a + previous call to vTaskSuspendAll(). */ + configASSERT( uxSchedulerSuspended ); + + /* It is possible that an ISR caused a task to be removed from an event + list while the scheduler was suspended. If this was the case then the + removed task will have been added to the xPendingReadyList. Once the + scheduler has been resumed it is safe to move all the pending ready + tasks from this list into their appropriate ready list. */ + taskENTER_CRITICAL(); + { + --uxSchedulerSuspended; + + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + if( uxCurrentNumberOfTasks > ( UBaseType_t ) 0U ) + { + /* Move any readied tasks from the pending list into the + appropriate ready list. */ + while( listLIST_IS_EMPTY( &xPendingReadyList ) == pdFALSE ) + { + pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyList ) ); + ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + + /* If the moved task has a priority higher than the current + task then a yield must be performed. */ + if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) + { + xYieldPending = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + if( pxTCB != NULL ) + { + /* A task was unblocked while the scheduler was suspended, + which may have prevented the next unblock time from being + re-calculated, in which case re-calculate it now. Mainly + important for low power tickless implementations, where + this can prevent an unnecessary exit from low power + state. */ + prvResetNextTaskUnblockTime(); + } + + /* If any ticks occurred while the scheduler was suspended then + they should be processed now. This ensures the tick count does + not slip, and that any delayed tasks are resumed at the correct + time. */ + { + UBaseType_t uxPendedCounts = uxPendedTicks; /* Non-volatile copy. */ + + if( uxPendedCounts > ( UBaseType_t ) 0U ) + { + do + { + if( xTaskIncrementTick() != pdFALSE ) + { + xYieldPending = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + --uxPendedCounts; + } while( uxPendedCounts > ( UBaseType_t ) 0U ); + + uxPendedTicks = 0; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + if( xYieldPending != pdFALSE ) + { + #if( configUSE_PREEMPTION != 0 ) + { + xAlreadyYielded = pdTRUE; + } + #endif + taskYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + return xAlreadyYielded; +} +/*-----------------------------------------------------------*/ + +TickType_t xTaskGetTickCount( void ) +{ +TickType_t xTicks; + + /* Critical section required if running on a 16 bit processor. */ + portTICK_TYPE_ENTER_CRITICAL(); + { + xTicks = xTickCount; + } + portTICK_TYPE_EXIT_CRITICAL(); + + return xTicks; +} +/*-----------------------------------------------------------*/ + +TickType_t xTaskGetTickCountFromISR( void ) +{ +TickType_t xReturn; +UBaseType_t uxSavedInterruptStatus; + + /* RTOS ports that support interrupt nesting have the concept of a maximum + system call (or maximum API call) interrupt priority. Interrupts that are + above the maximum system call priority are kept permanently enabled, even + when the RTOS kernel is in a critical section, but cannot make any calls to + FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + failure if a FreeRTOS API function is called from an interrupt that has been + assigned a priority above the configured maximum system call priority. + Only FreeRTOS functions that end in FromISR can be called from interrupts + that have been assigned a priority at or (logically) below the maximum + system call interrupt priority. FreeRTOS maintains a separate interrupt + safe API to ensure interrupt entry is as fast and as simple as possible. + More information (albeit Cortex-M specific) is provided on the following + link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptStatus = portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR(); + { + xReturn = xTickCount; + } + portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +UBaseType_t uxTaskGetNumberOfTasks( void ) +{ + /* A critical section is not required because the variables are of type + BaseType_t. */ + return uxCurrentNumberOfTasks; +} +/*-----------------------------------------------------------*/ + +char *pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ +{ +TCB_t *pxTCB; + + /* If null is passed in here then the name of the calling task is being + queried. */ + pxTCB = prvGetTCBFromHandle( xTaskToQuery ); + configASSERT( pxTCB ); + return &( pxTCB->pcTaskName[ 0 ] ); +} +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskGetHandle == 1 ) + + static TCB_t *prvSearchForNameWithinSingleList( List_t *pxList, const char pcNameToQuery[] ) + { + TCB_t *pxNextTCB, *pxFirstTCB, *pxReturn = NULL; + UBaseType_t x; + char cNextChar; + + /* This function is called with the scheduler suspended. */ + + if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 ) + { + listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList ); + + do + { + listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList ); + + /* Check each character in the name looking for a match or + mismatch. */ + for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ ) + { + cNextChar = pxNextTCB->pcTaskName[ x ]; + + if( cNextChar != pcNameToQuery[ x ] ) + { + /* Characters didn't match. */ + break; + } + else if( cNextChar == 0x00 ) + { + /* Both strings terminated, a match must have been + found. */ + pxReturn = pxNextTCB; + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + if( pxReturn != NULL ) + { + /* The handle has been found. */ + break; + } + + } while( pxNextTCB != pxFirstTCB ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return pxReturn; + } + +#endif /* INCLUDE_xTaskGetHandle */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskGetHandle == 1 ) + + TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + { + UBaseType_t uxQueue = configMAX_PRIORITIES; + TCB_t* pxTCB; + + /* Task names will be truncated to configMAX_TASK_NAME_LEN - 1 bytes. */ + configASSERT( strlen( pcNameToQuery ) < configMAX_TASK_NAME_LEN ); + + vTaskSuspendAll(); + { + /* Search the ready lists. */ + do + { + uxQueue--; + pxTCB = prvSearchForNameWithinSingleList( ( List_t * ) &( pxReadyTasksLists[ uxQueue ] ), pcNameToQuery ); + + if( pxTCB != NULL ) + { + /* Found the handle. */ + break; + } + + } while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + + /* Search the delayed lists. */ + if( pxTCB == NULL ) + { + pxTCB = prvSearchForNameWithinSingleList( ( List_t * ) pxDelayedTaskList, pcNameToQuery ); + } + + if( pxTCB == NULL ) + { + pxTCB = prvSearchForNameWithinSingleList( ( List_t * ) pxOverflowDelayedTaskList, pcNameToQuery ); + } + + #if ( INCLUDE_vTaskSuspend == 1 ) + { + if( pxTCB == NULL ) + { + /* Search the suspended list. */ + pxTCB = prvSearchForNameWithinSingleList( &xSuspendedTaskList, pcNameToQuery ); + } + } + #endif + + #if( INCLUDE_vTaskDelete == 1 ) + { + if( pxTCB == NULL ) + { + /* Search the deleted list. */ + pxTCB = prvSearchForNameWithinSingleList( &xTasksWaitingTermination, pcNameToQuery ); + } + } + #endif + } + ( void ) xTaskResumeAll(); + + return ( TaskHandle_t ) pxTCB; + } + +#endif /* INCLUDE_xTaskGetHandle */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ) + { + UBaseType_t uxTask = 0, uxQueue = configMAX_PRIORITIES; + + vTaskSuspendAll(); + { + /* Is there a space in the array for each task in the system? */ + if( uxArraySize >= uxCurrentNumberOfTasks ) + { + /* Fill in an TaskStatus_t structure with information on each + task in the Ready state. */ + do + { + uxQueue--; + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady ); + + } while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + + /* Fill in an TaskStatus_t structure with information on each + task in the Blocked state. */ + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, eBlocked ); + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxOverflowDelayedTaskList, eBlocked ); + + #if( INCLUDE_vTaskDelete == 1 ) + { + /* Fill in an TaskStatus_t structure with information on + each task that has been deleted but not yet cleaned up. */ + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted ); + } + #endif + + #if ( INCLUDE_vTaskSuspend == 1 ) + { + /* Fill in an TaskStatus_t structure with information on + each task in the Suspended state. */ + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended ); + } + #endif + + #if ( configGENERATE_RUN_TIME_STATS == 1) + { + if( pulTotalRunTime != NULL ) + { + #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE + portALT_GET_RUN_TIME_COUNTER_VALUE( ( *pulTotalRunTime ) ); + #else + *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE(); + #endif + } + } + #else + { + if( pulTotalRunTime != NULL ) + { + *pulTotalRunTime = 0; + } + } + #endif + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + ( void ) xTaskResumeAll(); + + return uxTask; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) + + TaskHandle_t xTaskGetIdleTaskHandle( void ) + { + /* If xTaskGetIdleTaskHandle() is called before the scheduler has been + started, then xIdleTaskHandle will be NULL. */ + configASSERT( ( xIdleTaskHandle != NULL ) ); + return xIdleTaskHandle; + } + +#endif /* INCLUDE_xTaskGetIdleTaskHandle */ +/*----------------------------------------------------------*/ + +/* This conditional compilation should use inequality to 0, not equality to 1. +This is to ensure vTaskStepTick() is available when user defined low power mode +implementations require configUSE_TICKLESS_IDLE to be set to a value other than +1. */ +#if ( configUSE_TICKLESS_IDLE != 0 ) + + void vTaskStepTick( const TickType_t xTicksToJump ) + { + /* Correct the tick count value after a period during which the tick + was suppressed. Note this does *not* call the tick hook function for + each stepped tick. */ + configASSERT( ( xTickCount + xTicksToJump ) <= xNextTaskUnblockTime ); + xTickCount += xTicksToJump; + traceINCREASE_TICK_COUNT( xTicksToJump ); + } + +#endif /* configUSE_TICKLESS_IDLE */ +/*----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskAbortDelay == 1 ) + + BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) + { + TCB_t *pxTCB = ( TCB_t * ) xTask; + BaseType_t xReturn; + + configASSERT( pxTCB ); + + vTaskSuspendAll(); + { + /* A task can only be prematurely removed from the Blocked state if + it is actually in the Blocked state. */ + if( eTaskGetState( xTask ) == eBlocked ) + { + xReturn = pdPASS; + + /* Remove the reference to the task from the blocked list. An + interrupt won't touch the xStateListItem because the + scheduler is suspended. */ + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + + /* Is the task waiting on an event also? If so remove it from + the event list too. Interrupts can touch the event list item, + even though the scheduler is suspended, so a critical section + is used. */ + taskENTER_CRITICAL(); + { + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) + { + ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); + pxTCB->ucDelayAborted = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + /* Place the unblocked task into the appropriate ready list. */ + prvAddTaskToReadyList( pxTCB ); + + /* A task being unblocked cannot cause an immediate context + switch if preemption is turned off. */ + #if ( configUSE_PREEMPTION == 1 ) + { + /* Preemption is on, but a context switch should only be + performed if the unblocked task has a priority that is + equal to or higher than the currently executing task. */ + if( pxTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* Pend the yield to be performed when the scheduler + is unsuspended. */ + xYieldPending = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_PREEMPTION */ + } + else + { + xReturn = pdFAIL; + } + } + ( void ) xTaskResumeAll(); + + return xReturn; + } + +#endif /* INCLUDE_xTaskAbortDelay */ +/*----------------------------------------------------------*/ + +BaseType_t xTaskIncrementTick( void ) +{ +TCB_t * pxTCB; +TickType_t xItemValue; +BaseType_t xSwitchRequired = pdFALSE; + + /* Called by the portable layer each time a tick interrupt occurs. + Increments the tick then checks to see if the new tick value will cause any + tasks to be unblocked. */ + traceTASK_INCREMENT_TICK( xTickCount ); + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + /* Minor optimisation. The tick count cannot change in this + block. */ + const TickType_t xConstTickCount = xTickCount + ( TickType_t ) 1; + + /* Increment the RTOS tick, switching the delayed and overflowed + delayed lists if it wraps to 0. */ + xTickCount = xConstTickCount; + + if( xConstTickCount == ( TickType_t ) 0U ) /*lint !e774 'if' does not always evaluate to false as it is looking for an overflow. */ + { + taskSWITCH_DELAYED_LISTS(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* See if this tick has made a timeout expire. Tasks are stored in + the queue in the order of their wake time - meaning once one task + has been found whose block time has not expired there is no need to + look any further down the list. */ + if( xConstTickCount >= xNextTaskUnblockTime ) + { + for( ;; ) + { + if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE ) + { + /* The delayed list is empty. Set xNextTaskUnblockTime + to the maximum possible value so it is extremely + unlikely that the + if( xTickCount >= xNextTaskUnblockTime ) test will pass + next time through. */ + xNextTaskUnblockTime = portMAX_DELAY; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + break; + } + else + { + /* The delayed list is not empty, get the value of the + item at the head of the delayed list. This is the time + at which the task at the head of the delayed list must + be removed from the Blocked state. */ + pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); + xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ) ); + + if( xConstTickCount < xItemValue ) + { + /* It is not time to unblock this item yet, but the + item value is the time at which the task at the head + of the blocked list must be removed from the Blocked + state - so record the item value in + xNextTaskUnblockTime. */ + xNextTaskUnblockTime = xItemValue; + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* It is time to remove the item from the Blocked state. */ + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + + /* Is the task waiting on an event also? If so remove + it from the event list. */ + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) + { + ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Place the unblocked task into the appropriate ready + list. */ + prvAddTaskToReadyList( pxTCB ); + + /* A task being unblocked cannot cause an immediate + context switch if preemption is turned off. */ + #if ( configUSE_PREEMPTION == 1 ) + { + /* Preemption is on, but a context switch should + only be performed if the unblocked task has a + priority that is equal to or higher than the + currently executing task. */ + if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) + { + xSwitchRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_PREEMPTION */ + } + } + } + + /* Tasks of equal priority to the currently running task will share + processing time (time slice) if preemption is on, and the application + writer has not explicitly turned time slicing off. */ + #if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) + { + if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ pxCurrentTCB->uxPriority ] ) ) > ( UBaseType_t ) 1 ) + { + xSwitchRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) */ + + #if ( configUSE_TICK_HOOK == 1 ) + { + /* Guard against the tick hook being called when the pended tick + count is being unwound (when the scheduler is being unlocked). */ + if( uxPendedTicks == ( UBaseType_t ) 0U ) + { + vApplicationTickHook(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_TICK_HOOK */ + } + else + { + ++uxPendedTicks; + + /* The tick hook gets called at regular intervals, even if the + scheduler is locked. */ + #if ( configUSE_TICK_HOOK == 1 ) + { + vApplicationTickHook(); + } + #endif + } + + #if ( configUSE_PREEMPTION == 1 ) + { + if( xYieldPending != pdFALSE ) + { + xSwitchRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_PREEMPTION */ + + return xSwitchRequired; +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + + void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) + { + TCB_t *xTCB; + + /* If xTask is NULL then it is the task hook of the calling task that is + getting set. */ + if( xTask == NULL ) + { + xTCB = ( TCB_t * ) pxCurrentTCB; + } + else + { + xTCB = ( TCB_t * ) xTask; + } + + /* Save the hook function in the TCB. A critical section is required as + the value can be accessed from an interrupt. */ + taskENTER_CRITICAL(); + xTCB->pxTaskTag = pxHookFunction; + taskEXIT_CRITICAL(); + } + +#endif /* configUSE_APPLICATION_TASK_TAG */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + + TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) + { + TCB_t *xTCB; + TaskHookFunction_t xReturn; + + /* If xTask is NULL then we are setting our own task hook. */ + if( xTask == NULL ) + { + xTCB = ( TCB_t * ) pxCurrentTCB; + } + else + { + xTCB = ( TCB_t * ) xTask; + } + + /* Save the hook function in the TCB. A critical section is required as + the value can be accessed from an interrupt. */ + taskENTER_CRITICAL(); + { + xReturn = xTCB->pxTaskTag; + } + taskEXIT_CRITICAL(); + + return xReturn; + } + +#endif /* configUSE_APPLICATION_TASK_TAG */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + + BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) + { + TCB_t *xTCB; + BaseType_t xReturn; + + /* If xTask is NULL then we are calling our own task hook. */ + if( xTask == NULL ) + { + xTCB = ( TCB_t * ) pxCurrentTCB; + } + else + { + xTCB = ( TCB_t * ) xTask; + } + + if( xTCB->pxTaskTag != NULL ) + { + xReturn = xTCB->pxTaskTag( pvParameter ); + } + else + { + xReturn = pdFAIL; + } + + return xReturn; + } + +#endif /* configUSE_APPLICATION_TASK_TAG */ +/*-----------------------------------------------------------*/ + +void vTaskSwitchContext( void ) +{ + if( uxSchedulerSuspended != ( UBaseType_t ) pdFALSE ) + { + /* The scheduler is currently suspended - do not allow a context + switch. */ + xYieldPending = pdTRUE; + } + else + { + xYieldPending = pdFALSE; + traceTASK_SWITCHED_OUT(); + + #if ( configGENERATE_RUN_TIME_STATS == 1 ) + { + #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE + portALT_GET_RUN_TIME_COUNTER_VALUE( ulTotalRunTime ); + #else + ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE(); + #endif + + /* Add the amount of time the task has been running to the + accumulated time so far. The time the task started running was + stored in ulTaskSwitchedInTime. Note that there is no overflow + protection here so count values are only valid until the timer + overflows. The guard against negative values is to protect + against suspect run time stat counter implementations - which + are provided by the application, not the kernel. */ + if( ulTotalRunTime > ulTaskSwitchedInTime ) + { + pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + ulTaskSwitchedInTime = ulTotalRunTime; + } + #endif /* configGENERATE_RUN_TIME_STATS */ + + /* Check for stack overflow, if configured. */ + taskCHECK_FOR_STACK_OVERFLOW(); + + /* Select a new task to run using either the generic C or port + optimised asm code. */ + taskSELECT_HIGHEST_PRIORITY_TASK(); + traceTASK_SWITCHED_IN(); + + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + /* Switch Newlib's _impure_ptr variable to point to the _reent + structure specific to this task. */ + _impure_ptr = &( pxCurrentTCB->xNewLib_reent ); + } + #endif /* configUSE_NEWLIB_REENTRANT */ + } +} +/*-----------------------------------------------------------*/ + +void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) +{ + configASSERT( pxEventList ); + + /* THIS FUNCTION MUST BE CALLED WITH EITHER INTERRUPTS DISABLED OR THE + SCHEDULER SUSPENDED AND THE QUEUE BEING ACCESSED LOCKED. */ + + /* Place the event list item of the TCB in the appropriate event list. + This is placed in the list in priority order so the highest priority task + is the first to be woken by the event. The queue that contains the event + list is locked, preventing simultaneous access from interrupts. */ + vListInsert( pxEventList, &( pxCurrentTCB->xEventListItem ) ); + + prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE ); +} +/*-----------------------------------------------------------*/ + +void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) +{ + configASSERT( pxEventList ); + + /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by + the event groups implementation. */ + configASSERT( uxSchedulerSuspended != 0 ); + + /* Store the item value in the event list item. It is safe to access the + event list item here as interrupts won't access the event list item of a + task that is not in the Blocked state. */ + listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE ); + + /* Place the event list item of the TCB at the end of the appropriate event + list. It is safe to access the event list here because it is part of an + event group implementation - and interrupts don't access event groups + directly (instead they access them indirectly by pending function calls to + the task level). */ + vListInsertEnd( pxEventList, &( pxCurrentTCB->xEventListItem ) ); + + prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE ); +} +/*-----------------------------------------------------------*/ + +#if( configUSE_TIMERS == 1 ) + + void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) + { + configASSERT( pxEventList ); + + /* This function should not be called by application code hence the + 'Restricted' in its name. It is not part of the public API. It is + designed for use by kernel code, and has special calling requirements - + it should be called with the scheduler suspended. */ + + + /* Place the event list item of the TCB in the appropriate event list. + In this case it is assume that this is the only task that is going to + be waiting on this event list, so the faster vListInsertEnd() function + can be used in place of vListInsert. */ + vListInsertEnd( pxEventList, &( pxCurrentTCB->xEventListItem ) ); + + /* If the task should block indefinitely then set the block time to a + value that will be recognised as an indefinite delay inside the + prvAddCurrentTaskToDelayedList() function. */ + if( xWaitIndefinitely != pdFALSE ) + { + xTicksToWait = portMAX_DELAY; + } + + traceTASK_DELAY_UNTIL( ( xTickCount + xTicksToWait ) ); + prvAddCurrentTaskToDelayedList( xTicksToWait, xWaitIndefinitely ); + } + +#endif /* configUSE_TIMERS */ +/*-----------------------------------------------------------*/ + +BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) +{ +TCB_t *pxUnblockedTCB; +BaseType_t xReturn; + + /* THIS FUNCTION MUST BE CALLED FROM A CRITICAL SECTION. It can also be + called from a critical section within an ISR. */ + + /* The event list is sorted in priority order, so the first in the list can + be removed as it is known to be the highest priority. Remove the TCB from + the delayed list, and add it to the ready list. + + If an event is for a queue that is locked then this function will never + get called - the lock count on the queue will get modified instead. This + means exclusive access to the event list is guaranteed here. + + This function assumes that a check has already been made to ensure that + pxEventList is not empty. */ + pxUnblockedTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); + configASSERT( pxUnblockedTCB ); + ( void ) uxListRemove( &( pxUnblockedTCB->xEventListItem ) ); + + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + ( void ) uxListRemove( &( pxUnblockedTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxUnblockedTCB ); + } + else + { + /* The delayed and ready lists cannot be accessed, so hold this task + pending until the scheduler is resumed. */ + vListInsertEnd( &( xPendingReadyList ), &( pxUnblockedTCB->xEventListItem ) ); + } + + if( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* Return true if the task removed from the event list has a higher + priority than the calling task. This allows the calling task to know if + it should force a context switch now. */ + xReturn = pdTRUE; + + /* Mark that a yield is pending in case the user is not using the + "xHigherPriorityTaskWoken" parameter to an ISR safe FreeRTOS function. */ + xYieldPending = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + #if( configUSE_TICKLESS_IDLE != 0 ) + { + /* If a task is blocked on a kernel object then xNextTaskUnblockTime + might be set to the blocked task's time out time. If the task is + unblocked for a reason other than a timeout xNextTaskUnblockTime is + normally left unchanged, because it is automatically reset to a new + value when the tick count equals xNextTaskUnblockTime. However if + tickless idling is used it might be more important to enter sleep mode + at the earliest possible time - so reset xNextTaskUnblockTime here to + ensure it is updated at the earliest possible time. */ + prvResetNextTaskUnblockTime(); + } + #endif + + return xReturn; +} +/*-----------------------------------------------------------*/ + +void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) +{ +TCB_t *pxUnblockedTCB; + + /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by + the event flags implementation. */ + configASSERT( uxSchedulerSuspended != pdFALSE ); + + /* Store the new item value in the event list. */ + listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE ); + + /* Remove the event list form the event flag. Interrupts do not access + event flags. */ + pxUnblockedTCB = ( TCB_t * ) listGET_LIST_ITEM_OWNER( pxEventListItem ); + configASSERT( pxUnblockedTCB ); + ( void ) uxListRemove( pxEventListItem ); + + /* Remove the task from the delayed list and add it to the ready list. The + scheduler is suspended so interrupts will not be accessing the ready + lists. */ + ( void ) uxListRemove( &( pxUnblockedTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxUnblockedTCB ); + + if( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* The unblocked task has a priority above that of the calling task, so + a context switch is required. This function is called with the + scheduler suspended so xYieldPending is set so the context switch + occurs immediately that the scheduler is resumed (unsuspended). */ + xYieldPending = pdTRUE; + } +} +/*-----------------------------------------------------------*/ + +void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) +{ + configASSERT( pxTimeOut ); + taskENTER_CRITICAL(); + { + pxTimeOut->xOverflowCount = xNumOfOverflows; + pxTimeOut->xTimeOnEntering = xTickCount; + } + taskEXIT_CRITICAL(); +} +/*-----------------------------------------------------------*/ + +void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) +{ + /* For internal use only as it does not use a critical section. */ + pxTimeOut->xOverflowCount = xNumOfOverflows; + pxTimeOut->xTimeOnEntering = xTickCount; +} +/*-----------------------------------------------------------*/ + +BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) +{ +BaseType_t xReturn; + + configASSERT( pxTimeOut ); + configASSERT( pxTicksToWait ); + + taskENTER_CRITICAL(); + { + /* Minor optimisation. The tick count cannot change in this block. */ + const TickType_t xConstTickCount = xTickCount; + const TickType_t xElapsedTime = xConstTickCount - pxTimeOut->xTimeOnEntering; + + #if( INCLUDE_xTaskAbortDelay == 1 ) + if( pxCurrentTCB->ucDelayAborted != pdFALSE ) + { + /* The delay was aborted, which is not the same as a time out, + but has the same result. */ + pxCurrentTCB->ucDelayAborted = pdFALSE; + xReturn = pdTRUE; + } + else + #endif + + #if ( INCLUDE_vTaskSuspend == 1 ) + if( *pxTicksToWait == portMAX_DELAY ) + { + /* If INCLUDE_vTaskSuspend is set to 1 and the block time + specified is the maximum block time then the task should block + indefinitely, and therefore never time out. */ + xReturn = pdFALSE; + } + else + #endif + + if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( xConstTickCount >= pxTimeOut->xTimeOnEntering ) ) /*lint !e525 Indentation preferred as is to make code within pre-processor directives clearer. */ + { + /* The tick count is greater than the time at which + vTaskSetTimeout() was called, but has also overflowed since + vTaskSetTimeOut() was called. It must have wrapped all the way + around and gone past again. This passed since vTaskSetTimeout() + was called. */ + xReturn = pdTRUE; + } + else if( xElapsedTime < *pxTicksToWait ) /*lint !e961 Explicit casting is only redundant with some compilers, whereas others require it to prevent integer conversion errors. */ + { + /* Not a genuine timeout. Adjust parameters for time remaining. */ + *pxTicksToWait -= xElapsedTime; + vTaskInternalSetTimeOutState( pxTimeOut ); + xReturn = pdFALSE; + } + else + { + *pxTicksToWait = 0; + xReturn = pdTRUE; + } + } + taskEXIT_CRITICAL(); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +void vTaskMissedYield( void ) +{ + xYieldPending = pdTRUE; +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) + { + UBaseType_t uxReturn; + TCB_t *pxTCB; + + if( xTask != NULL ) + { + pxTCB = ( TCB_t * ) xTask; + uxReturn = pxTCB->uxTaskNumber; + } + else + { + uxReturn = 0U; + } + + return uxReturn; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) + { + TCB_t *pxTCB; + + if( xTask != NULL ) + { + pxTCB = ( TCB_t * ) xTask; + pxTCB->uxTaskNumber = uxHandle; + } + } + +#endif /* configUSE_TRACE_FACILITY */ + +/* + * ----------------------------------------------------------- + * The Idle task. + * ---------------------------------------------------------- + * + * The portTASK_FUNCTION() macro is used to allow port/compiler specific + * language extensions. The equivalent prototype for this function is: + * + * void prvIdleTask( void *pvParameters ); + * + */ +static portTASK_FUNCTION( prvIdleTask, pvParameters ) +{ + /* Stop warnings. */ + ( void ) pvParameters; + + /** THIS IS THE RTOS IDLE TASK - WHICH IS CREATED AUTOMATICALLY WHEN THE + SCHEDULER IS STARTED. **/ + + /* In case a task that has a secure context deletes itself, in which case + the idle task is responsible for deleting the task's secure context, if + any. */ + portTASK_CALLS_SECURE_FUNCTIONS(); + + for( ;; ) + { + /* See if any tasks have deleted themselves - if so then the idle task + is responsible for freeing the deleted task's TCB and stack. */ + prvCheckTasksWaitingTermination(); + + #if ( configUSE_PREEMPTION == 0 ) + { + /* If we are not using preemption we keep forcing a task switch to + see if any other task has become available. If we are using + preemption we don't need to do this as any task becoming available + will automatically get the processor anyway. */ + taskYIELD(); + } + #endif /* configUSE_PREEMPTION */ + + #if ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) ) + { + /* When using preemption tasks of equal priority will be + timesliced. If a task that is sharing the idle priority is ready + to run then the idle task should yield before the end of the + timeslice. + + A critical region is not required here as we are just reading from + the list, and an occasional incorrect value will not matter. If + the ready list at the idle priority contains more than one task + then a task other than the idle task is ready to execute. */ + if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( UBaseType_t ) 1 ) + { + taskYIELD(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) ) */ + + #if ( configUSE_IDLE_HOOK == 1 ) + { + extern void vApplicationIdleHook( void ); + + /* Call the user defined function from within the idle task. This + allows the application designer to add background functionality + without the overhead of a separate task. + NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES, + CALL A FUNCTION THAT MIGHT BLOCK. */ + vApplicationIdleHook(); + } + #endif /* configUSE_IDLE_HOOK */ + + /* This conditional compilation should use inequality to 0, not equality + to 1. This is to ensure portSUPPRESS_TICKS_AND_SLEEP() is called when + user defined low power mode implementations require + configUSE_TICKLESS_IDLE to be set to a value other than 1. */ + #if ( configUSE_TICKLESS_IDLE != 0 ) + { + TickType_t xExpectedIdleTime; + + /* It is not desirable to suspend then resume the scheduler on + each iteration of the idle task. Therefore, a preliminary + test of the expected idle time is performed without the + scheduler suspended. The result here is not necessarily + valid. */ + xExpectedIdleTime = prvGetExpectedIdleTime(); + + if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP ) + { + vTaskSuspendAll(); + { + /* Now the scheduler is suspended, the expected idle + time can be sampled again, and this time its value can + be used. */ + configASSERT( xNextTaskUnblockTime >= xTickCount ); + xExpectedIdleTime = prvGetExpectedIdleTime(); + + /* Define the following macro to set xExpectedIdleTime to 0 + if the application does not want + portSUPPRESS_TICKS_AND_SLEEP() to be called. */ + configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( xExpectedIdleTime ); + + if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP ) + { + traceLOW_POWER_IDLE_BEGIN(); + portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ); + traceLOW_POWER_IDLE_END(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + ( void ) xTaskResumeAll(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_TICKLESS_IDLE */ + } +} +/*-----------------------------------------------------------*/ + +#if( configUSE_TICKLESS_IDLE != 0 ) + + eSleepModeStatus eTaskConfirmSleepModeStatus( void ) + { + /* The idle task exists in addition to the application tasks. */ + const UBaseType_t uxNonApplicationTasks = 1; + eSleepModeStatus eReturn = eStandardSleep; + + if( listCURRENT_LIST_LENGTH( &xPendingReadyList ) != 0 ) + { + /* A task was made ready while the scheduler was suspended. */ + eReturn = eAbortSleep; + } + else if( xYieldPending != pdFALSE ) + { + /* A yield was pended while the scheduler was suspended. */ + eReturn = eAbortSleep; + } + else + { + /* If all the tasks are in the suspended list (which might mean they + have an infinite block time rather than actually being suspended) + then it is safe to turn all clocks off and just wait for external + interrupts. */ + if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == ( uxCurrentNumberOfTasks - uxNonApplicationTasks ) ) + { + eReturn = eNoTasksWaitingTimeout; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + return eReturn; + } + +#endif /* configUSE_TICKLESS_IDLE */ +/*-----------------------------------------------------------*/ + +#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) + + void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) + { + TCB_t *pxTCB; + + if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS ) + { + pxTCB = prvGetTCBFromHandle( xTaskToSet ); + pxTCB->pvThreadLocalStoragePointers[ xIndex ] = pvValue; + } + } + +#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */ +/*-----------------------------------------------------------*/ + +#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) + + void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) + { + void *pvReturn = NULL; + TCB_t *pxTCB; + + if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS ) + { + pxTCB = prvGetTCBFromHandle( xTaskToQuery ); + pvReturn = pxTCB->pvThreadLocalStoragePointers[ xIndex ]; + } + else + { + pvReturn = NULL; + } + + return pvReturn; + } + +#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */ +/*-----------------------------------------------------------*/ + +#if ( portUSING_MPU_WRAPPERS == 1 ) + + void vTaskAllocateMPURegions( TaskHandle_t xTaskToModify, const MemoryRegion_t * const xRegions ) + { + TCB_t *pxTCB; + + /* If null is passed in here then we are modifying the MPU settings of + the calling task. */ + pxTCB = prvGetTCBFromHandle( xTaskToModify ); + + vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, NULL, 0 ); + } + +#endif /* portUSING_MPU_WRAPPERS */ +/*-----------------------------------------------------------*/ + +static void prvInitialiseTaskLists( void ) +{ +UBaseType_t uxPriority; + + for( uxPriority = ( UBaseType_t ) 0U; uxPriority < ( UBaseType_t ) configMAX_PRIORITIES; uxPriority++ ) + { + vListInitialise( &( pxReadyTasksLists[ uxPriority ] ) ); + } + + vListInitialise( &xDelayedTaskList1 ); + vListInitialise( &xDelayedTaskList2 ); + vListInitialise( &xPendingReadyList ); + + #if ( INCLUDE_vTaskDelete == 1 ) + { + vListInitialise( &xTasksWaitingTermination ); + } + #endif /* INCLUDE_vTaskDelete */ + + #if ( INCLUDE_vTaskSuspend == 1 ) + { + vListInitialise( &xSuspendedTaskList ); + } + #endif /* INCLUDE_vTaskSuspend */ + + /* Start with pxDelayedTaskList using list1 and the pxOverflowDelayedTaskList + using list2. */ + pxDelayedTaskList = &xDelayedTaskList1; + pxOverflowDelayedTaskList = &xDelayedTaskList2; +} +/*-----------------------------------------------------------*/ + +static void prvCheckTasksWaitingTermination( void ) +{ + + /** THIS FUNCTION IS CALLED FROM THE RTOS IDLE TASK **/ + + #if ( INCLUDE_vTaskDelete == 1 ) + { + TCB_t *pxTCB; + + /* uxDeletedTasksWaitingCleanUp is used to prevent vTaskSuspendAll() + being called too often in the idle task. */ + while( uxDeletedTasksWaitingCleanUp > ( UBaseType_t ) 0U ) + { + taskENTER_CRITICAL(); + { + pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xTasksWaitingTermination ) ); + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + --uxCurrentNumberOfTasks; + --uxDeletedTasksWaitingCleanUp; + } + taskEXIT_CRITICAL(); + + prvDeleteTCB( pxTCB ); + } + } + #endif /* INCLUDE_vTaskDelete */ +} +/*-----------------------------------------------------------*/ + +#if( configUSE_TRACE_FACILITY == 1 ) + + void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ) + { + TCB_t *pxTCB; + + /* xTask is NULL then get the state of the calling task. */ + pxTCB = prvGetTCBFromHandle( xTask ); + + pxTaskStatus->xHandle = ( TaskHandle_t ) pxTCB; + pxTaskStatus->pcTaskName = ( const char * ) &( pxTCB->pcTaskName [ 0 ] ); + pxTaskStatus->uxCurrentPriority = pxTCB->uxPriority; + pxTaskStatus->pxStackBase = pxTCB->pxStack; + pxTaskStatus->xTaskNumber = pxTCB->uxTCBNumber; + + #if ( configUSE_MUTEXES == 1 ) + { + pxTaskStatus->uxBasePriority = pxTCB->uxBasePriority; + } + #else + { + pxTaskStatus->uxBasePriority = 0; + } + #endif + + #if ( configGENERATE_RUN_TIME_STATS == 1 ) + { + pxTaskStatus->ulRunTimeCounter = pxTCB->ulRunTimeCounter; + } + #else + { + pxTaskStatus->ulRunTimeCounter = 0; + } + #endif + + /* Obtaining the task state is a little fiddly, so is only done if the + value of eState passed into this function is eInvalid - otherwise the + state is just set to whatever is passed in. */ + if( eState != eInvalid ) + { + if( pxTCB == pxCurrentTCB ) + { + pxTaskStatus->eCurrentState = eRunning; + } + else + { + pxTaskStatus->eCurrentState = eState; + + #if ( INCLUDE_vTaskSuspend == 1 ) + { + /* If the task is in the suspended list then there is a + chance it is actually just blocked indefinitely - so really + it should be reported as being in the Blocked state. */ + if( eState == eSuspended ) + { + vTaskSuspendAll(); + { + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) + { + pxTaskStatus->eCurrentState = eBlocked; + } + } + ( void ) xTaskResumeAll(); + } + } + #endif /* INCLUDE_vTaskSuspend */ + } + } + else + { + pxTaskStatus->eCurrentState = eTaskGetState( pxTCB ); + } + + /* Obtaining the stack space takes some time, so the xGetFreeStackSpace + parameter is provided to allow it to be skipped. */ + if( xGetFreeStackSpace != pdFALSE ) + { + #if ( portSTACK_GROWTH > 0 ) + { + pxTaskStatus->usStackHighWaterMark = prvTaskCheckFreeStackSpace( ( uint8_t * ) pxTCB->pxEndOfStack ); + } + #else + { + pxTaskStatus->usStackHighWaterMark = prvTaskCheckFreeStackSpace( ( uint8_t * ) pxTCB->pxStack ); + } + #endif + } + else + { + pxTaskStatus->usStackHighWaterMark = 0; + } + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + static UBaseType_t prvListTasksWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState ) + { + configLIST_VOLATILE TCB_t *pxNextTCB, *pxFirstTCB; + UBaseType_t uxTask = 0; + + if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 ) + { + listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList ); + + /* Populate an TaskStatus_t structure within the + pxTaskStatusArray array for each task that is referenced from + pxList. See the definition of TaskStatus_t in task.h for the + meaning of each TaskStatus_t structure member. */ + do + { + listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList ); + vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState ); + uxTask++; + } while( pxNextTCB != pxFirstTCB ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return uxTask; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) + + static uint16_t prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte ) + { + uint32_t ulCount = 0U; + + while( *pucStackByte == ( uint8_t ) tskSTACK_FILL_BYTE ) + { + pucStackByte -= portSTACK_GROWTH; + ulCount++; + } + + ulCount /= ( uint32_t ) sizeof( StackType_t ); /*lint !e961 Casting is not redundant on smaller architectures. */ + + return ( uint16_t ) ulCount; + } + +#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) + + UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) + { + TCB_t *pxTCB; + uint8_t *pucEndOfStack; + UBaseType_t uxReturn; + + pxTCB = prvGetTCBFromHandle( xTask ); + + #if portSTACK_GROWTH < 0 + { + pucEndOfStack = ( uint8_t * ) pxTCB->pxStack; + } + #else + { + pucEndOfStack = ( uint8_t * ) pxTCB->pxEndOfStack; + } + #endif + + uxReturn = ( UBaseType_t ) prvTaskCheckFreeStackSpace( pucEndOfStack ); + + return uxReturn; + } + +#endif /* INCLUDE_uxTaskGetStackHighWaterMark */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelete == 1 ) + + static void prvDeleteTCB( TCB_t *pxTCB ) + { + /* This call is required specifically for the TriCore port. It must be + above the vPortFree() calls. The call is also used by ports/demos that + want to allocate and clean RAM statically. */ + portCLEAN_UP_TCB( pxTCB ); + + /* Free up the memory allocated by the scheduler for the task. It is up + to the task to free any memory allocated at the application level. */ + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + _reclaim_reent( &( pxTCB->xNewLib_reent ) ); + } + #endif /* configUSE_NEWLIB_REENTRANT */ + + #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) && ( portUSING_MPU_WRAPPERS == 0 ) ) + { + /* The task can only have been allocated dynamically - free both + the stack and TCB. */ + vPortFree( pxTCB->pxStack ); + vPortFree( pxTCB ); + } + #elif( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */ + { + /* The task could have been allocated statically or dynamically, so + check what was statically allocated before trying to free the + memory. */ + if( pxTCB->ucStaticallyAllocated == tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB ) + { + /* Both the stack and TCB were allocated dynamically, so both + must be freed. */ + vPortFree( pxTCB->pxStack ); + vPortFree( pxTCB ); + } + else if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_ONLY ) + { + /* Only the stack was statically allocated, so the TCB is the + only memory that must be freed. */ + vPortFree( pxTCB ); + } + else + { + /* Neither the stack nor the TCB were allocated dynamically, so + nothing needs to be freed. */ + configASSERT( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB ); + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + } + +#endif /* INCLUDE_vTaskDelete */ +/*-----------------------------------------------------------*/ + +static void prvResetNextTaskUnblockTime( void ) +{ +TCB_t *pxTCB; + + if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE ) + { + /* The new current delayed list is empty. Set xNextTaskUnblockTime to + the maximum possible value so it is extremely unlikely that the + if( xTickCount >= xNextTaskUnblockTime ) test will pass until + there is an item in the delayed list. */ + xNextTaskUnblockTime = portMAX_DELAY; + } + else + { + /* The new current delayed list is not empty, get the value of + the item at the head of the delayed list. This is the time at + which the task at the head of the delayed list should be removed + from the Blocked state. */ + ( pxTCB ) = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); + xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( ( pxTCB )->xStateListItem ) ); + } +} +/*-----------------------------------------------------------*/ + +#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) + + TaskHandle_t xTaskGetCurrentTaskHandle( void ) + { + TaskHandle_t xReturn; + + /* A critical section is not required as this is not called from + an interrupt and the current TCB will always be the same for any + individual execution thread. */ + xReturn = pxCurrentTCB; + + return xReturn; + } + +#endif /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + + BaseType_t xTaskGetSchedulerState( void ) + { + BaseType_t xReturn; + + if( xSchedulerRunning == pdFALSE ) + { + xReturn = taskSCHEDULER_NOT_STARTED; + } + else + { + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + xReturn = taskSCHEDULER_RUNNING; + } + else + { + xReturn = taskSCHEDULER_SUSPENDED; + } + } + + return xReturn; + } + +#endif /* ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_MUTEXES == 1 ) + + BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) + { + TCB_t * const pxMutexHolderTCB = ( TCB_t * ) pxMutexHolder; + BaseType_t xReturn = pdFALSE; + + /* If the mutex was given back by an interrupt while the queue was + locked then the mutex holder might now be NULL. _RB_ Is this still + needed as interrupts can no longer use mutexes? */ + if( pxMutexHolder != NULL ) + { + /* If the holder of the mutex has a priority below the priority of + the task attempting to obtain the mutex then it will temporarily + inherit the priority of the task attempting to obtain the mutex. */ + if( pxMutexHolderTCB->uxPriority < pxCurrentTCB->uxPriority ) + { + /* Adjust the mutex holder state to account for its new + priority. Only reset the event list item value if the value is + not being used for anything else. */ + if( ( listGET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL ) + { + listSET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* If the task being modified is in the ready state it will need + to be moved into a new list. */ + if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxMutexHolderTCB->uxPriority ] ), &( pxMutexHolderTCB->xStateListItem ) ) != pdFALSE ) + { + if( uxListRemove( &( pxMutexHolderTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + taskRESET_READY_PRIORITY( pxMutexHolderTCB->uxPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Inherit the priority before being moved into the new list. */ + pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority; + prvAddTaskToReadyList( pxMutexHolderTCB ); + } + else + { + /* Just inherit the priority. */ + pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority; + } + + traceTASK_PRIORITY_INHERIT( pxMutexHolderTCB, pxCurrentTCB->uxPriority ); + + /* Inheritance occurred. */ + xReturn = pdTRUE; + } + else + { + if( pxMutexHolderTCB->uxBasePriority < pxCurrentTCB->uxPriority ) + { + /* The base priority of the mutex holder is lower than the + priority of the task attempting to take the mutex, but the + current priority of the mutex holder is not lower than the + priority of the task attempting to take the mutex. + Therefore the mutex holder must have already inherited a + priority, but inheritance would have occurred if that had + not been the case. */ + xReturn = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xReturn; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_MUTEXES == 1 ) + + BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) + { + TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder; + BaseType_t xReturn = pdFALSE; + + if( pxMutexHolder != NULL ) + { + /* A task can only have an inherited priority if it holds the mutex. + If the mutex is held by a task then it cannot be given from an + interrupt, and if a mutex is given by the holding task then it must + be the running state task. */ + configASSERT( pxTCB == pxCurrentTCB ); + configASSERT( pxTCB->uxMutexesHeld ); + ( pxTCB->uxMutexesHeld )--; + + /* Has the holder of the mutex inherited the priority of another + task? */ + if( pxTCB->uxPriority != pxTCB->uxBasePriority ) + { + /* Only disinherit if no other mutexes are held. */ + if( pxTCB->uxMutexesHeld == ( UBaseType_t ) 0 ) + { + /* A task can only have an inherited priority if it holds + the mutex. If the mutex is held by a task then it cannot be + given from an interrupt, and if a mutex is given by the + holding task then it must be the running state task. Remove + the holding task from the ready list. */ + if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + taskRESET_READY_PRIORITY( pxTCB->uxPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Disinherit the priority before adding the task into the + new ready list. */ + traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority ); + pxTCB->uxPriority = pxTCB->uxBasePriority; + + /* Reset the event list item value. It cannot be in use for + any other purpose if this task is running, and it must be + running to give back the mutex. */ + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + prvAddTaskToReadyList( pxTCB ); + + /* Return true to indicate that a context switch is required. + This is only actually required in the corner case whereby + multiple mutexes were held and the mutexes were given back + in an order different to that in which they were taken. + If a context switch did not occur when the first mutex was + returned, even if a task was waiting on it, then a context + switch should occur when the last mutex is returned whether + a task is waiting on it or not. */ + xReturn = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xReturn; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_MUTEXES == 1 ) + + void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask ) + { + TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder; + UBaseType_t uxPriorityUsedOnEntry, uxPriorityToUse; + const UBaseType_t uxOnlyOneMutexHeld = ( UBaseType_t ) 1; + + if( pxMutexHolder != NULL ) + { + /* If pxMutexHolder is not NULL then the holder must hold at least + one mutex. */ + configASSERT( pxTCB->uxMutexesHeld ); + + /* Determine the priority to which the priority of the task that + holds the mutex should be set. This will be the greater of the + holding task's base priority and the priority of the highest + priority task that is waiting to obtain the mutex. */ + if( pxTCB->uxBasePriority < uxHighestPriorityWaitingTask ) + { + uxPriorityToUse = uxHighestPriorityWaitingTask; + } + else + { + uxPriorityToUse = pxTCB->uxBasePriority; + } + + /* Does the priority need to change? */ + if( pxTCB->uxPriority != uxPriorityToUse ) + { + /* Only disinherit if no other mutexes are held. This is a + simplification in the priority inheritance implementation. If + the task that holds the mutex is also holding other mutexes then + the other mutexes may have caused the priority inheritance. */ + if( pxTCB->uxMutexesHeld == uxOnlyOneMutexHeld ) + { + /* If a task has timed out because it already holds the + mutex it was trying to obtain then it cannot of inherited + its own priority. */ + configASSERT( pxTCB != pxCurrentTCB ); + + /* Disinherit the priority, remembering the previous + priority to facilitate determining the subject task's + state. */ + traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority ); + uxPriorityUsedOnEntry = pxTCB->uxPriority; + pxTCB->uxPriority = uxPriorityToUse; + + /* Only reset the event list item value if the value is not + being used for anything else. */ + if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL ) + { + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxPriorityToUse ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* If the running task is not the task that holds the mutex + then the task that holds the mutex could be in either the + Ready, Blocked or Suspended states. Only remove the task + from its current state list if it is in the Ready state as + the task's priority is going to change and there is one + Ready list per priority. */ + if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xStateListItem ) ) != pdFALSE ) + { + if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + taskRESET_READY_PRIORITY( pxTCB->uxPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + prvAddTaskToReadyList( pxTCB ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( portCRITICAL_NESTING_IN_TCB == 1 ) + + void vTaskEnterCritical( void ) + { + portDISABLE_INTERRUPTS(); + + if( xSchedulerRunning != pdFALSE ) + { + ( pxCurrentTCB->uxCriticalNesting )++; + + /* This is not the interrupt safe version of the enter critical + function so assert() if it is being called from an interrupt + context. Only API functions that end in "FromISR" can be used in an + interrupt. Only assert if the critical nesting count is 1 to + protect against recursive calls if the assert function also uses a + critical section. */ + if( pxCurrentTCB->uxCriticalNesting == 1 ) + { + portASSERT_IF_IN_ISR(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* portCRITICAL_NESTING_IN_TCB */ +/*-----------------------------------------------------------*/ + +#if ( portCRITICAL_NESTING_IN_TCB == 1 ) + + void vTaskExitCritical( void ) + { + if( xSchedulerRunning != pdFALSE ) + { + if( pxCurrentTCB->uxCriticalNesting > 0U ) + { + ( pxCurrentTCB->uxCriticalNesting )--; + + if( pxCurrentTCB->uxCriticalNesting == 0U ) + { + portENABLE_INTERRUPTS(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* portCRITICAL_NESTING_IN_TCB */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) + + static char *prvWriteNameToBuffer( char *pcBuffer, const char *pcTaskName ) + { + size_t x; + + /* Start by copying the entire string. */ + strcpy( pcBuffer, pcTaskName ); + + /* Pad the end of the string with spaces to ensure columns line up when + printed out. */ + for( x = strlen( pcBuffer ); x < ( size_t ) ( configMAX_TASK_NAME_LEN - 1 ); x++ ) + { + pcBuffer[ x ] = ' '; + } + + /* Terminate. */ + pcBuffer[ x ] = 0x00; + + /* Return the new end of string. */ + return &( pcBuffer[ x ] ); + } + +#endif /* ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + void vTaskList( char * pcWriteBuffer ) + { + TaskStatus_t *pxTaskStatusArray; + volatile UBaseType_t uxArraySize, x; + char cStatus; + + /* + * PLEASE NOTE: + * + * This function is provided for convenience only, and is used by many + * of the demo applications. Do not consider it to be part of the + * scheduler. + * + * vTaskList() calls uxTaskGetSystemState(), then formats part of the + * uxTaskGetSystemState() output into a human readable table that + * displays task names, states and stack usage. + * + * vTaskList() has a dependency on the sprintf() C library function that + * might bloat the code size, use a lot of stack, and provide different + * results on different platforms. An alternative, tiny, third party, + * and limited functionality implementation of sprintf() is provided in + * many of the FreeRTOS/Demo sub-directories in a file called + * printf-stdarg.c (note printf-stdarg.c does not provide a full + * snprintf() implementation!). + * + * It is recommended that production systems call uxTaskGetSystemState() + * directly to get access to raw stats data, rather than indirectly + * through a call to vTaskList(). + */ + + + /* Make sure the write buffer does not contain a string. */ + *pcWriteBuffer = 0x00; + + /* Take a snapshot of the number of tasks in case it changes while this + function is executing. */ + uxArraySize = uxCurrentNumberOfTasks; + + /* Allocate an array index for each task. NOTE! if + configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will + equate to NULL. */ + pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) ); + + if( pxTaskStatusArray != NULL ) + { + /* Generate the (binary) data. */ + uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL ); + + /* Create a human readable table from the binary data. */ + for( x = 0; x < uxArraySize; x++ ) + { + switch( pxTaskStatusArray[ x ].eCurrentState ) + { + case eRunning: cStatus = tskRUNNING_CHAR; + break; + + case eReady: cStatus = tskREADY_CHAR; + break; + + case eBlocked: cStatus = tskBLOCKED_CHAR; + break; + + case eSuspended: cStatus = tskSUSPENDED_CHAR; + break; + + case eDeleted: cStatus = tskDELETED_CHAR; + break; + + default: /* Should not get here, but it is included + to prevent static checking errors. */ + cStatus = 0x00; + break; + } + + /* Write the task name to the string, padding with spaces so it + can be printed in tabular form more easily. */ + pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName ); + + /* Write the rest of the string. */ + sprintf( pcWriteBuffer, "\t%c\t%u\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber ); + pcWriteBuffer += strlen( pcWriteBuffer ); + } + + /* Free the array again. NOTE! If configSUPPORT_DYNAMIC_ALLOCATION + is 0 then vPortFree() will be #defined to nothing. */ + vPortFree( pxTaskStatusArray ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */ +/*----------------------------------------------------------*/ + +#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + void vTaskGetRunTimeStats( char *pcWriteBuffer ) + { + TaskStatus_t *pxTaskStatusArray; + volatile UBaseType_t uxArraySize, x; + uint32_t ulTotalTime, ulStatsAsPercentage; + + #if( configUSE_TRACE_FACILITY != 1 ) + { + #error configUSE_TRACE_FACILITY must also be set to 1 in FreeRTOSConfig.h to use vTaskGetRunTimeStats(). + } + #endif + + /* + * PLEASE NOTE: + * + * This function is provided for convenience only, and is used by many + * of the demo applications. Do not consider it to be part of the + * scheduler. + * + * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part + * of the uxTaskGetSystemState() output into a human readable table that + * displays the amount of time each task has spent in the Running state + * in both absolute and percentage terms. + * + * vTaskGetRunTimeStats() has a dependency on the sprintf() C library + * function that might bloat the code size, use a lot of stack, and + * provide different results on different platforms. An alternative, + * tiny, third party, and limited functionality implementation of + * sprintf() is provided in many of the FreeRTOS/Demo sub-directories in + * a file called printf-stdarg.c (note printf-stdarg.c does not provide + * a full snprintf() implementation!). + * + * It is recommended that production systems call uxTaskGetSystemState() + * directly to get access to raw stats data, rather than indirectly + * through a call to vTaskGetRunTimeStats(). + */ + + /* Make sure the write buffer does not contain a string. */ + *pcWriteBuffer = 0x00; + + /* Take a snapshot of the number of tasks in case it changes while this + function is executing. */ + uxArraySize = uxCurrentNumberOfTasks; + + /* Allocate an array index for each task. NOTE! If + configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will + equate to NULL. */ + pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) ); + + if( pxTaskStatusArray != NULL ) + { + /* Generate the (binary) data. */ + uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime ); + + /* For percentage calculations. */ + ulTotalTime /= 100UL; + + /* Avoid divide by zero errors. */ + if( ulTotalTime > 0 ) + { + /* Create a human readable table from the binary data. */ + for( x = 0; x < uxArraySize; x++ ) + { + /* What percentage of the total run time has the task used? + This will always be rounded down to the nearest integer. + ulTotalRunTimeDiv100 has already been divided by 100. */ + ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime; + + /* Write the task name to the string, padding with + spaces so it can be printed in tabular form more + easily. */ + pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName ); + + if( ulStatsAsPercentage > 0UL ) + { + #ifdef portLU_PRINTF_SPECIFIER_REQUIRED + { + sprintf( pcWriteBuffer, "\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage ); + } + #else + { + /* sizeof( int ) == sizeof( long ) so a smaller + printf() library can be used. */ + sprintf( pcWriteBuffer, "\t%u\t\t%u%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage ); + } + #endif + } + else + { + /* If the percentage is zero here then the task has + consumed less than 1% of the total run time. */ + #ifdef portLU_PRINTF_SPECIFIER_REQUIRED + { + sprintf( pcWriteBuffer, "\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter ); + } + #else + { + /* sizeof( int ) == sizeof( long ) so a smaller + printf() library can be used. */ + sprintf( pcWriteBuffer, "\t%u\t\t<1%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter ); + } + #endif + } + + pcWriteBuffer += strlen( pcWriteBuffer ); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Free the array again. NOTE! If configSUPPORT_DYNAMIC_ALLOCATION + is 0 then vPortFree() will be #defined to nothing. */ + vPortFree( pxTaskStatusArray ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */ +/*-----------------------------------------------------------*/ + +TickType_t uxTaskResetEventItemValue( void ) +{ +TickType_t uxReturn; + + uxReturn = listGET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ) ); + + /* Reset the event list item to its normal value - so it can be used with + queues and semaphores. */ + listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), ( ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + + return uxReturn; +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_MUTEXES == 1 ) + + void *pvTaskIncrementMutexHeldCount( void ) + { + /* If xSemaphoreCreateMutex() is called before any tasks have been created + then pxCurrentTCB will be NULL. */ + if( pxCurrentTCB != NULL ) + { + ( pxCurrentTCB->uxMutexesHeld )++; + } + + return pxCurrentTCB; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + + uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) + { + uint32_t ulReturn; + + taskENTER_CRITICAL(); + { + /* Only block if the notification count is not already non-zero. */ + if( pxCurrentTCB->ulNotifiedValue == 0UL ) + { + /* Mark this task as waiting for a notification. */ + pxCurrentTCB->ucNotifyState = taskWAITING_NOTIFICATION; + + if( xTicksToWait > ( TickType_t ) 0 ) + { + prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE ); + traceTASK_NOTIFY_TAKE_BLOCK(); + + /* All ports are written to allow a yield in a critical + section (some will yield immediately, others wait until the + critical section exits) - but it is not something that + application code should ever do. */ + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + taskENTER_CRITICAL(); + { + traceTASK_NOTIFY_TAKE(); + ulReturn = pxCurrentTCB->ulNotifiedValue; + + if( ulReturn != 0UL ) + { + if( xClearCountOnExit != pdFALSE ) + { + pxCurrentTCB->ulNotifiedValue = 0UL; + } + else + { + pxCurrentTCB->ulNotifiedValue = ulReturn - ( uint32_t ) 1; + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + pxCurrentTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION; + } + taskEXIT_CRITICAL(); + + return ulReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + + BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) + { + BaseType_t xReturn; + + taskENTER_CRITICAL(); + { + /* Only block if a notification is not already pending. */ + if( pxCurrentTCB->ucNotifyState != taskNOTIFICATION_RECEIVED ) + { + /* Clear bits in the task's notification value as bits may get + set by the notifying task or interrupt. This can be used to + clear the value to zero. */ + pxCurrentTCB->ulNotifiedValue &= ~ulBitsToClearOnEntry; + + /* Mark this task as waiting for a notification. */ + pxCurrentTCB->ucNotifyState = taskWAITING_NOTIFICATION; + + if( xTicksToWait > ( TickType_t ) 0 ) + { + prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE ); + traceTASK_NOTIFY_WAIT_BLOCK(); + + /* All ports are written to allow a yield in a critical + section (some will yield immediately, others wait until the + critical section exits) - but it is not something that + application code should ever do. */ + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + taskENTER_CRITICAL(); + { + traceTASK_NOTIFY_WAIT(); + + if( pulNotificationValue != NULL ) + { + /* Output the current notification value, which may or may not + have changed. */ + *pulNotificationValue = pxCurrentTCB->ulNotifiedValue; + } + + /* If ucNotifyValue is set then either the task never entered the + blocked state (because a notification was already pending) or the + task unblocked because of a notification. Otherwise the task + unblocked because of a timeout. */ + if( pxCurrentTCB->ucNotifyState != taskNOTIFICATION_RECEIVED ) + { + /* A notification was not received. */ + xReturn = pdFALSE; + } + else + { + /* A notification was already pending or a notification was + received while the task was waiting. */ + pxCurrentTCB->ulNotifiedValue &= ~ulBitsToClearOnExit; + xReturn = pdTRUE; + } + + pxCurrentTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION; + } + taskEXIT_CRITICAL(); + + return xReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + + BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) + { + TCB_t * pxTCB; + BaseType_t xReturn = pdPASS; + uint8_t ucOriginalNotifyState; + + configASSERT( xTaskToNotify ); + pxTCB = ( TCB_t * ) xTaskToNotify; + + taskENTER_CRITICAL(); + { + if( pulPreviousNotificationValue != NULL ) + { + *pulPreviousNotificationValue = pxTCB->ulNotifiedValue; + } + + ucOriginalNotifyState = pxTCB->ucNotifyState; + + pxTCB->ucNotifyState = taskNOTIFICATION_RECEIVED; + + switch( eAction ) + { + case eSetBits : + pxTCB->ulNotifiedValue |= ulValue; + break; + + case eIncrement : + ( pxTCB->ulNotifiedValue )++; + break; + + case eSetValueWithOverwrite : + pxTCB->ulNotifiedValue = ulValue; + break; + + case eSetValueWithoutOverwrite : + if( ucOriginalNotifyState != taskNOTIFICATION_RECEIVED ) + { + pxTCB->ulNotifiedValue = ulValue; + } + else + { + /* The value could not be written to the task. */ + xReturn = pdFAIL; + } + break; + + case eNoAction: + /* The task is being notified without its notify value being + updated. */ + break; + } + + traceTASK_NOTIFY(); + + /* If the task is in the blocked state specifically to wait for a + notification then unblock it now. */ + if( ucOriginalNotifyState == taskWAITING_NOTIFICATION ) + { + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + + /* The task should not have been on an event list. */ + configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL ); + + #if( configUSE_TICKLESS_IDLE != 0 ) + { + /* If a task is blocked waiting for a notification then + xNextTaskUnblockTime might be set to the blocked task's time + out time. If the task is unblocked for a reason other than + a timeout xNextTaskUnblockTime is normally left unchanged, + because it will automatically get reset to a new value when + the tick count equals xNextTaskUnblockTime. However if + tickless idling is used it might be more important to enter + sleep mode at the earliest possible time - so reset + xNextTaskUnblockTime here to ensure it is updated at the + earliest possible time. */ + prvResetNextTaskUnblockTime(); + } + #endif + + if( pxTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* The notified task has a priority above the currently + executing task so a yield is required. */ + taskYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + return xReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + + BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ) + { + TCB_t * pxTCB; + uint8_t ucOriginalNotifyState; + BaseType_t xReturn = pdPASS; + UBaseType_t uxSavedInterruptStatus; + + configASSERT( xTaskToNotify ); + + /* RTOS ports that support interrupt nesting have the concept of a + maximum system call (or maximum API call) interrupt priority. + Interrupts that are above the maximum system call priority are keep + permanently enabled, even when the RTOS kernel is in a critical section, + but cannot make any calls to FreeRTOS API functions. If configASSERT() + is defined in FreeRTOSConfig.h then + portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + failure if a FreeRTOS API function is called from an interrupt that has + been assigned a priority above the configured maximum system call + priority. Only FreeRTOS functions that end in FromISR can be called + from interrupts that have been assigned a priority at or (logically) + below the maximum system call interrupt priority. FreeRTOS maintains a + separate interrupt safe API to ensure interrupt entry is as fast and as + simple as possible. More information (albeit Cortex-M specific) is + provided on the following link: + http://www.freertos.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + pxTCB = ( TCB_t * ) xTaskToNotify; + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + if( pulPreviousNotificationValue != NULL ) + { + *pulPreviousNotificationValue = pxTCB->ulNotifiedValue; + } + + ucOriginalNotifyState = pxTCB->ucNotifyState; + pxTCB->ucNotifyState = taskNOTIFICATION_RECEIVED; + + switch( eAction ) + { + case eSetBits : + pxTCB->ulNotifiedValue |= ulValue; + break; + + case eIncrement : + ( pxTCB->ulNotifiedValue )++; + break; + + case eSetValueWithOverwrite : + pxTCB->ulNotifiedValue = ulValue; + break; + + case eSetValueWithoutOverwrite : + if( ucOriginalNotifyState != taskNOTIFICATION_RECEIVED ) + { + pxTCB->ulNotifiedValue = ulValue; + } + else + { + /* The value could not be written to the task. */ + xReturn = pdFAIL; + } + break; + + case eNoAction : + /* The task is being notified without its notify value being + updated. */ + break; + } + + traceTASK_NOTIFY_FROM_ISR(); + + /* If the task is in the blocked state specifically to wait for a + notification then unblock it now. */ + if( ucOriginalNotifyState == taskWAITING_NOTIFICATION ) + { + /* The task should not have been on an event list. */ + configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL ); + + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + } + else + { + /* The delayed and ready lists cannot be accessed, so hold + this task pending until the scheduler is resumed. */ + vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) ); + } + + if( pxTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* The notified task has a priority above the currently + executing task so a yield is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + /* Mark that a yield is pending in case the user is not + using the "xHigherPriorityTaskWoken" parameter to an ISR + safe FreeRTOS function. */ + xYieldPending = pdTRUE; + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + + void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken ) + { + TCB_t * pxTCB; + uint8_t ucOriginalNotifyState; + UBaseType_t uxSavedInterruptStatus; + + configASSERT( xTaskToNotify ); + + /* RTOS ports that support interrupt nesting have the concept of a + maximum system call (or maximum API call) interrupt priority. + Interrupts that are above the maximum system call priority are keep + permanently enabled, even when the RTOS kernel is in a critical section, + but cannot make any calls to FreeRTOS API functions. If configASSERT() + is defined in FreeRTOSConfig.h then + portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + failure if a FreeRTOS API function is called from an interrupt that has + been assigned a priority above the configured maximum system call + priority. Only FreeRTOS functions that end in FromISR can be called + from interrupts that have been assigned a priority at or (logically) + below the maximum system call interrupt priority. FreeRTOS maintains a + separate interrupt safe API to ensure interrupt entry is as fast and as + simple as possible. More information (albeit Cortex-M specific) is + provided on the following link: + http://www.freertos.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + pxTCB = ( TCB_t * ) xTaskToNotify; + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + ucOriginalNotifyState = pxTCB->ucNotifyState; + pxTCB->ucNotifyState = taskNOTIFICATION_RECEIVED; + + /* 'Giving' is equivalent to incrementing a count in a counting + semaphore. */ + ( pxTCB->ulNotifiedValue )++; + + traceTASK_NOTIFY_GIVE_FROM_ISR(); + + /* If the task is in the blocked state specifically to wait for a + notification then unblock it now. */ + if( ucOriginalNotifyState == taskWAITING_NOTIFICATION ) + { + /* The task should not have been on an event list. */ + configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL ); + + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + } + else + { + /* The delayed and ready lists cannot be accessed, so hold + this task pending until the scheduler is resumed. */ + vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) ); + } + + if( pxTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* The notified task has a priority above the currently + executing task so a yield is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + /* Mark that a yield is pending in case the user is not + using the "xHigherPriorityTaskWoken" parameter in an ISR + safe FreeRTOS function. */ + xYieldPending = pdTRUE; + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ + +/*-----------------------------------------------------------*/ + +#if( configUSE_TASK_NOTIFICATIONS == 1 ) + + BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask ) + { + TCB_t *pxTCB; + BaseType_t xReturn; + + /* If null is passed in here then it is the calling task that is having + its notification state cleared. */ + pxTCB = prvGetTCBFromHandle( xTask ); + + taskENTER_CRITICAL(); + { + if( pxTCB->ucNotifyState == taskNOTIFICATION_RECEIVED ) + { + pxTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION; + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; + } + } + taskEXIT_CRITICAL(); + + return xReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + + +static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, const BaseType_t xCanBlockIndefinitely ) +{ +TickType_t xTimeToWake; +const TickType_t xConstTickCount = xTickCount; + + #if( INCLUDE_xTaskAbortDelay == 1 ) + { + /* About to enter a delayed list, so ensure the ucDelayAborted flag is + reset to pdFALSE so it can be detected as having been set to pdTRUE + when the task leaves the Blocked state. */ + pxCurrentTCB->ucDelayAborted = pdFALSE; + } + #endif + + /* Remove the task from the ready list before adding it to the blocked list + as the same list item is used for both lists. */ + if( uxListRemove( &( pxCurrentTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + /* The current task must be in a ready list, so there is no need to + check, and the port reset macro can be called directly. */ + portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + #if ( INCLUDE_vTaskSuspend == 1 ) + { + if( ( xTicksToWait == portMAX_DELAY ) && ( xCanBlockIndefinitely != pdFALSE ) ) + { + /* Add the task to the suspended task list instead of a delayed task + list to ensure it is not woken by a timing event. It will block + indefinitely. */ + vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { + /* Calculate the time at which the task should be woken if the event + does not occur. This may overflow but this doesn't matter, the + kernel will manage it correctly. */ + xTimeToWake = xConstTickCount + xTicksToWait; + + /* The list item will be inserted in wake time order. */ + listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xStateListItem ), xTimeToWake ); + + if( xTimeToWake < xConstTickCount ) + { + /* Wake time has overflowed. Place this item in the overflow + list. */ + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { + /* The wake time has not overflowed, so the current block list + is used. */ + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + + /* If the task entering the blocked state was placed at the + head of the list of blocked tasks then xNextTaskUnblockTime + needs to be updated too. */ + if( xTimeToWake < xNextTaskUnblockTime ) + { + xNextTaskUnblockTime = xTimeToWake; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + } + #else /* INCLUDE_vTaskSuspend */ + { + /* Calculate the time at which the task should be woken if the event + does not occur. This may overflow but this doesn't matter, the kernel + will manage it correctly. */ + xTimeToWake = xConstTickCount + xTicksToWait; + + /* The list item will be inserted in wake time order. */ + listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xStateListItem ), xTimeToWake ); + + if( xTimeToWake < xConstTickCount ) + { + /* Wake time has overflowed. Place this item in the overflow list. */ + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { + /* The wake time has not overflowed, so the current block list is used. */ + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + + /* If the task entering the blocked state was placed at the head of the + list of blocked tasks then xNextTaskUnblockTime needs to be updated + too. */ + if( xTimeToWake < xNextTaskUnblockTime ) + { + xNextTaskUnblockTime = xTimeToWake; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + /* Avoid compiler warning when INCLUDE_vTaskSuspend is not 1. */ + ( void ) xCanBlockIndefinitely; + } + #endif /* INCLUDE_vTaskSuspend */ +} + +/* Code below here allows additional code to be inserted into this source file, +especially where access to file scope functions and data is needed (for example +when performing module tests). */ + +#ifdef FREERTOS_MODULE_TEST + #include "tasks_test_access_functions.h" +#endif + + +#if( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 ) + + #include "freertos_tasks_c_additions.h" + + static void freertos_tasks_c_additions_init( void ) + { + #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT + FREERTOS_TASKS_C_ADDITIONS_INIT(); + #endif + } + +#endif + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/timers.c b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/timers.c new file mode 100644 index 0000000..78a4003 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/middlewares/Third_Party/FreeRTOS/Source/timers.c @@ -0,0 +1,1076 @@ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/* Standard includes. */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "timers.h" + +#if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 ) + #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available. +#endif + +/* Lint e961 and e750 are suppressed as a MISRA exception justified because the +MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the +header files above, but not in this file, in order to generate the correct +privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */ + + +/* This entire source file will be skipped if the application is not configured +to include software timer functionality. This #if is closed at the very bottom +of this file. If you want to include software timer functionality then ensure +configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */ +#if ( configUSE_TIMERS == 1 ) + +/* Misc definitions. */ +#define tmrNO_DELAY ( TickType_t ) 0U + +/* The name assigned to the timer service task. This can be overridden by +defining trmTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */ +#ifndef configTIMER_SERVICE_TASK_NAME + #define configTIMER_SERVICE_TASK_NAME "Tmr Svc" +#endif + +/* The definition of the timers themselves. */ +typedef struct tmrTimerControl +{ + const char *pcTimerName; /*<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + ListItem_t xTimerListItem; /*<< Standard linked list item as used by all kernel features for event management. */ + TickType_t xTimerPeriodInTicks;/*<< How quickly and often the timer expires. */ + UBaseType_t uxAutoReload; /*<< Set to pdTRUE if the timer should be automatically restarted once expired. Set to pdFALSE if the timer is, in effect, a one-shot timer. */ + void *pvTimerID; /*<< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. */ + TimerCallbackFunction_t pxCallbackFunction; /*<< The function that will be called when the timer expires. */ + #if( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxTimerNumber; /*<< An ID assigned by trace tools such as FreeRTOS+Trace */ + #endif + + #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + uint8_t ucStaticallyAllocated; /*<< Set to pdTRUE if the timer was created statically so no attempt is made to free the memory again if the timer is later deleted. */ + #endif +} xTIMER; + +/* The old xTIMER name is maintained above then typedefed to the new Timer_t +name below to enable the use of older kernel aware debuggers. */ +typedef xTIMER Timer_t; + +/* The definition of messages that can be sent and received on the timer queue. +Two types of message can be queued - messages that manipulate a software timer, +and messages that request the execution of a non-timer related callback. The +two message types are defined in two separate structures, xTimerParametersType +and xCallbackParametersType respectively. */ +typedef struct tmrTimerParameters +{ + TickType_t xMessageValue; /*<< An optional value used by a subset of commands, for example, when changing the period of a timer. */ + Timer_t * pxTimer; /*<< The timer to which the command will be applied. */ +} TimerParameter_t; + + +typedef struct tmrCallbackParameters +{ + PendedFunction_t pxCallbackFunction; /* << The callback function to execute. */ + void *pvParameter1; /* << The value that will be used as the callback functions first parameter. */ + uint32_t ulParameter2; /* << The value that will be used as the callback functions second parameter. */ +} CallbackParameters_t; + +/* The structure that contains the two message types, along with an identifier +that is used to determine which message type is valid. */ +typedef struct tmrTimerQueueMessage +{ + BaseType_t xMessageID; /*<< The command being sent to the timer service task. */ + union + { + TimerParameter_t xTimerParameters; + + /* Don't include xCallbackParameters if it is not going to be used as + it makes the structure (and therefore the timer queue) larger. */ + #if ( INCLUDE_xTimerPendFunctionCall == 1 ) + CallbackParameters_t xCallbackParameters; + #endif /* INCLUDE_xTimerPendFunctionCall */ + } u; +} DaemonTaskMessage_t; + +/*lint -save -e956 A manual analysis and inspection has been used to determine +which static variables must be declared volatile. */ + +/* The list in which active timers are stored. Timers are referenced in expire +time order, with the nearest expiry time at the front of the list. Only the +timer service task is allowed to access these lists. */ +PRIVILEGED_DATA static List_t xActiveTimerList1 = {0}; +PRIVILEGED_DATA static List_t xActiveTimerList2 = {0}; +PRIVILEGED_DATA static List_t *pxCurrentTimerList = NULL; +PRIVILEGED_DATA static List_t *pxOverflowTimerList = NULL; + +/* A queue that is used to send commands to the timer service task. */ +PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL; +PRIVILEGED_DATA static TaskHandle_t xTimerTaskHandle = NULL; + +/*lint -restore */ + +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + + /* If static allocation is supported then the application must provide the + following callback function - which enables the application to optionally + provide the memory that will be used by the timer task as the task's stack + and TCB. */ + extern void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ); + +#endif + +/* + * Initialise the infrastructure used by the timer service task if it has not + * been initialised already. + */ +static void prvCheckForValidListAndQueue( void ) PRIVILEGED_FUNCTION; + +/* + * The timer service task (daemon). Timer functionality is controlled by this + * task. Other tasks communicate with the timer service task using the + * xTimerQueue queue. + */ +static void prvTimerTask( void *pvParameters ) PRIVILEGED_FUNCTION; + +/* + * Called by the timer service task to interpret and process a command it + * received on the timer queue. + */ +static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION; + +/* + * Insert the timer into either xActiveTimerList1, or xActiveTimerList2, + * depending on if the expire time causes a timer counter overflow. + */ +static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer, const TickType_t xNextExpiryTime, const TickType_t xTimeNow, const TickType_t xCommandTime ) PRIVILEGED_FUNCTION; + +/* + * An active timer has reached its expire time. Reload the timer if it is an + * auto reload timer, then call its callback. + */ +static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, const TickType_t xTimeNow ) PRIVILEGED_FUNCTION; + +/* + * The tick count has overflowed. Switch the timer lists after ensuring the + * current timer list does not still reference some timers. + */ +static void prvSwitchTimerLists( void ) PRIVILEGED_FUNCTION; + +/* + * Obtain the current tick count, setting *pxTimerListsWereSwitched to pdTRUE + * if a tick count overflow occurred since prvSampleTimeNow() was last called. + */ +static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched ) PRIVILEGED_FUNCTION; + +/* + * If the timer list contains any active timers then return the expire time of + * the timer that will expire first and set *pxListWasEmpty to false. If the + * timer list does not contain any timers then return 0 and set *pxListWasEmpty + * to pdTRUE. + */ +static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty ) PRIVILEGED_FUNCTION; + +/* + * If a timer has expired, process it. Otherwise, block the timer service task + * until either a timer does expire or a command is received. + */ +static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseType_t xListWasEmpty ) PRIVILEGED_FUNCTION; + +/* + * Called after a Timer_t structure has been allocated either statically or + * dynamically to fill in the structure's members. + */ +static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction, + Timer_t *pxNewTimer ) PRIVILEGED_FUNCTION; +/*-----------------------------------------------------------*/ + +BaseType_t xTimerCreateTimerTask( void ) +{ +BaseType_t xReturn = pdFAIL; + + /* This function is called when the scheduler is started if + configUSE_TIMERS is set to 1. Check that the infrastructure used by the + timer service task has been created/initialised. If timers have already + been created then the initialisation will already have been performed. */ + prvCheckForValidListAndQueue(); + + if( xTimerQueue != NULL ) + { + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + StaticTask_t *pxTimerTaskTCBBuffer = NULL; + StackType_t *pxTimerTaskStackBuffer = NULL; + uint32_t ulTimerTaskStackSize; + + vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize ); + xTimerTaskHandle = xTaskCreateStatic( prvTimerTask, + configTIMER_SERVICE_TASK_NAME, + ulTimerTaskStackSize, + NULL, + ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, + pxTimerTaskStackBuffer, + pxTimerTaskTCBBuffer ); + + if( xTimerTaskHandle != NULL ) + { + xReturn = pdPASS; + } + } + #else + { + xReturn = xTaskCreate( prvTimerTask, + configTIMER_SERVICE_TASK_NAME, + configTIMER_TASK_STACK_DEPTH, + NULL, + ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, + &xTimerTaskHandle ); + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + configASSERT( xReturn ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction ) + { + Timer_t *pxNewTimer; + + pxNewTimer = ( Timer_t * ) pvPortMalloc( sizeof( Timer_t ) ); + + if( pxNewTimer != NULL ) + { + prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer ); + + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + /* Timers can be created statically or dynamically, so note this + timer was created dynamically in case the timer is later + deleted. */ + pxNewTimer->ucStaticallyAllocated = pdFALSE; + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ + } + + return pxNewTimer; + } + +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if( configSUPPORT_STATIC_ALLOCATION == 1 ) + + TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction, + StaticTimer_t *pxTimerBuffer ) + { + Timer_t *pxNewTimer; + + #if( configASSERT_DEFINED == 1 ) + { + /* Sanity check that the size of the structure used to declare a + variable of type StaticTimer_t equals the size of the real timer + structure. */ + volatile size_t xSize = sizeof( StaticTimer_t ); + configASSERT( xSize == sizeof( Timer_t ) ); + } + #endif /* configASSERT_DEFINED */ + + /* A pointer to a StaticTimer_t structure MUST be provided, use it. */ + configASSERT( pxTimerBuffer ); + pxNewTimer = ( Timer_t * ) pxTimerBuffer; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */ + + if( pxNewTimer != NULL ) + { + prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer ); + + #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + { + /* Timers can be created statically or dynamically so note this + timer was created statically in case it is later deleted. */ + pxNewTimer->ucStaticallyAllocated = pdTRUE; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + } + + return pxNewTimer; + } + +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction, + Timer_t *pxNewTimer ) +{ + /* 0 is not a valid value for xTimerPeriodInTicks. */ + configASSERT( ( xTimerPeriodInTicks > 0 ) ); + + if( pxNewTimer != NULL ) + { + /* Ensure the infrastructure used by the timer service task has been + created/initialised. */ + prvCheckForValidListAndQueue(); + + /* Initialise the timer structure members using the function + parameters. */ + pxNewTimer->pcTimerName = pcTimerName; + pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks; + pxNewTimer->uxAutoReload = uxAutoReload; + pxNewTimer->pvTimerID = pvTimerID; + pxNewTimer->pxCallbackFunction = pxCallbackFunction; + vListInitialiseItem( &( pxNewTimer->xTimerListItem ) ); + traceTIMER_CREATE( pxNewTimer ); + } +} +/*-----------------------------------------------------------*/ + +BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) +{ +BaseType_t xReturn = pdFAIL; +DaemonTaskMessage_t xMessage; + + configASSERT( xTimer ); + + /* Send a message to the timer service task to perform a particular action + on a particular timer definition. */ + if( xTimerQueue != NULL ) + { + /* Send a command to the timer service task to start the xTimer timer. */ + xMessage.xMessageID = xCommandID; + xMessage.u.xTimerParameters.xMessageValue = xOptionalValue; + xMessage.u.xTimerParameters.pxTimer = ( Timer_t * ) xTimer; + + if( xCommandID < tmrFIRST_FROM_ISR_COMMAND ) + { + if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING ) + { + xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait ); + } + else + { + xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY ); + } + } + else + { + xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken ); + } + + traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) +{ + /* If xTimerGetTimerDaemonTaskHandle() is called before the scheduler has been + started, then xTimerTaskHandle will be NULL. */ + configASSERT( ( xTimerTaskHandle != NULL ) ); + return xTimerTaskHandle; +} +/*-----------------------------------------------------------*/ + +TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) +{ +Timer_t *pxTimer = ( Timer_t * ) xTimer; + + configASSERT( xTimer ); + return pxTimer->xTimerPeriodInTicks; +} +/*-----------------------------------------------------------*/ + +TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) +{ +Timer_t * pxTimer = ( Timer_t * ) xTimer; +TickType_t xReturn; + + configASSERT( xTimer ); + xReturn = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +const char * pcTimerGetName( TimerHandle_t xTimer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ +{ +Timer_t *pxTimer = ( Timer_t * ) xTimer; + + configASSERT( xTimer ); + return pxTimer->pcTimerName; +} +/*-----------------------------------------------------------*/ + +static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, const TickType_t xTimeNow ) +{ +BaseType_t xResult; +Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); + + /* Remove the timer from the list of active timers. A check has already + been performed to ensure the list is not empty. */ + ( void ) uxListRemove( &( pxTimer->xTimerListItem ) ); + traceTIMER_EXPIRED( pxTimer ); + + /* If the timer is an auto reload timer then calculate the next + expiry time and re-insert the timer in the list of active timers. */ + if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE ) + { + /* The timer is inserted into a list using a time relative to anything + other than the current time. It will therefore be inserted into the + correct list relative to the time this task thinks it is now. */ + if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) != pdFALSE ) + { + /* The timer expired before it was added to the active timer + list. Reload it now. */ + xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY ); + configASSERT( xResult ); + ( void ) xResult; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Call the timer callback. */ + pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); +} +/*-----------------------------------------------------------*/ + +static void prvTimerTask( void *pvParameters ) +{ +TickType_t xNextExpireTime; +BaseType_t xListWasEmpty; + + /* Just to avoid compiler warnings. */ + ( void ) pvParameters; + + #if( configUSE_DAEMON_TASK_STARTUP_HOOK == 1 ) + { + extern void vApplicationDaemonTaskStartupHook( void ); + + /* Allow the application writer to execute some code in the context of + this task at the point the task starts executing. This is useful if the + application includes initialisation code that would benefit from + executing after the scheduler has been started. */ + vApplicationDaemonTaskStartupHook(); + } + #endif /* configUSE_DAEMON_TASK_STARTUP_HOOK */ + + for( ;; ) + { + /* Query the timers list to see if it contains any timers, and if so, + obtain the time at which the next timer will expire. */ + xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty ); + + /* If a timer has expired, process it. Otherwise, block this task + until either a timer does expire, or a command is received. */ + prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty ); + + /* Empty the command queue. */ + prvProcessReceivedCommands(); + } +} +/*-----------------------------------------------------------*/ + +static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseType_t xListWasEmpty ) +{ +TickType_t xTimeNow; +BaseType_t xTimerListsWereSwitched; + + vTaskSuspendAll(); + { + /* Obtain the time now to make an assessment as to whether the timer + has expired or not. If obtaining the time causes the lists to switch + then don't process this timer as any timers that remained in the list + when the lists were switched will have been processed within the + prvSampleTimeNow() function. */ + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); + if( xTimerListsWereSwitched == pdFALSE ) + { + /* The tick count has not overflowed, has the timer expired? */ + if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) ) + { + ( void ) xTaskResumeAll(); + prvProcessExpiredTimer( xNextExpireTime, xTimeNow ); + } + else + { + /* The tick count has not overflowed, and the next expire + time has not been reached yet. This task should therefore + block to wait for the next expire time or a command to be + received - whichever comes first. The following line cannot + be reached unless xNextExpireTime > xTimeNow, except in the + case when the current timer list is empty. */ + if( xListWasEmpty != pdFALSE ) + { + /* The current timer list is empty - is the overflow list + also empty? */ + xListWasEmpty = listLIST_IS_EMPTY( pxOverflowTimerList ); + } + + vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty ); + + if( xTaskResumeAll() == pdFALSE ) + { + /* Yield to wait for either a command to arrive, or the + block time to expire. If a command arrived between the + critical section being exited and this yield then the yield + will not cause the task to block. */ + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + else + { + ( void ) xTaskResumeAll(); + } + } +} +/*-----------------------------------------------------------*/ + +static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty ) +{ +TickType_t xNextExpireTime; + + /* Timers are listed in expiry time order, with the head of the list + referencing the task that will expire first. Obtain the time at which + the timer with the nearest expiry time will expire. If there are no + active timers then just set the next expire time to 0. That will cause + this task to unblock when the tick count overflows, at which point the + timer lists will be switched and the next expiry time can be + re-assessed. */ + *pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList ); + if( *pxListWasEmpty == pdFALSE ) + { + xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList ); + } + else + { + /* Ensure the task unblocks when the tick count rolls over. */ + xNextExpireTime = ( TickType_t ) 0U; + } + + return xNextExpireTime; +} +/*-----------------------------------------------------------*/ + +static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched ) +{ +TickType_t xTimeNow; +PRIVILEGED_DATA static TickType_t xLastTime = ( TickType_t ) 0U; /*lint !e956 Variable is only accessible to one task. */ + + xTimeNow = xTaskGetTickCount(); + + if( xTimeNow < xLastTime ) + { + prvSwitchTimerLists(); + *pxTimerListsWereSwitched = pdTRUE; + } + else + { + *pxTimerListsWereSwitched = pdFALSE; + } + + xLastTime = xTimeNow; + + return xTimeNow; +} +/*-----------------------------------------------------------*/ + +static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer, const TickType_t xNextExpiryTime, const TickType_t xTimeNow, const TickType_t xCommandTime ) +{ +BaseType_t xProcessTimerNow = pdFALSE; + + listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime ); + listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer ); + + if( xNextExpiryTime <= xTimeNow ) + { + /* Has the expiry time elapsed between the command to start/reset a + timer was issued, and the time the command was processed? */ + if( ( ( TickType_t ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks ) /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + { + /* The time between a command being issued and the command being + processed actually exceeds the timers period. */ + xProcessTimerNow = pdTRUE; + } + else + { + vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) ); + } + } + else + { + if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) ) + { + /* If, since the command was issued, the tick count has overflowed + but the expiry time has not, then the timer must have already passed + its expiry time and should be processed immediately. */ + xProcessTimerNow = pdTRUE; + } + else + { + vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) ); + } + } + + return xProcessTimerNow; +} +/*-----------------------------------------------------------*/ + +static void prvProcessReceivedCommands( void ) +{ +DaemonTaskMessage_t xMessage; +Timer_t *pxTimer; +BaseType_t xTimerListsWereSwitched, xResult; +TickType_t xTimeNow; + + while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) /*lint !e603 xMessage does not have to be initialised as it is passed out, not in, and it is not used unless xQueueReceive() returns pdTRUE. */ + { + #if ( INCLUDE_xTimerPendFunctionCall == 1 ) + { + /* Negative commands are pended function calls rather than timer + commands. */ + if( xMessage.xMessageID < ( BaseType_t ) 0 ) + { + const CallbackParameters_t * const pxCallback = &( xMessage.u.xCallbackParameters ); + + /* The timer uses the xCallbackParameters member to request a + callback be executed. Check the callback is not NULL. */ + configASSERT( pxCallback ); + + /* Call the function. */ + pxCallback->pxCallbackFunction( pxCallback->pvParameter1, pxCallback->ulParameter2 ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* INCLUDE_xTimerPendFunctionCall */ + + /* Commands that are positive are timer commands rather than pended + function calls. */ + if( xMessage.xMessageID >= ( BaseType_t ) 0 ) + { + /* The messages uses the xTimerParameters member to work on a + software timer. */ + pxTimer = xMessage.u.xTimerParameters.pxTimer; + + if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) /*lint !e961. The cast is only redundant when NULL is passed into the macro. */ + { + /* The timer is in a list, remove it. */ + ( void ) uxListRemove( &( pxTimer->xTimerListItem ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.u.xTimerParameters.xMessageValue ); + + /* In this case the xTimerListsWereSwitched parameter is not used, but + it must be present in the function call. prvSampleTimeNow() must be + called after the message is received from xTimerQueue so there is no + possibility of a higher priority task adding a message to the message + queue with a time that is ahead of the timer daemon task (because it + pre-empted the timer daemon task after the xTimeNow value was set). */ + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); + + switch( xMessage.xMessageID ) + { + case tmrCOMMAND_START : + case tmrCOMMAND_START_FROM_ISR : + case tmrCOMMAND_RESET : + case tmrCOMMAND_RESET_FROM_ISR : + case tmrCOMMAND_START_DONT_TRACE : + /* Start or restart a timer. */ + if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE ) + { + /* The timer expired before it was added to the active + timer list. Process it now. */ + pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); + traceTIMER_EXPIRED( pxTimer ); + + if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE ) + { + xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY ); + configASSERT( xResult ); + ( void ) xResult; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + break; + + case tmrCOMMAND_STOP : + case tmrCOMMAND_STOP_FROM_ISR : + /* The timer has already been removed from the active list. + There is nothing to do here. */ + break; + + case tmrCOMMAND_CHANGE_PERIOD : + case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR : + pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue; + configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) ); + + /* The new period does not really have a reference, and can + be longer or shorter than the old one. The command time is + therefore set to the current time, and as the period cannot + be zero the next expiry time can only be in the future, + meaning (unlike for the xTimerStart() case above) there is + no fail case that needs to be handled here. */ + ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow ); + break; + + case tmrCOMMAND_DELETE : + /* The timer has already been removed from the active list, + just free up the memory if the memory was dynamically + allocated. */ + #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) ) + { + /* The timer can only have been allocated dynamically - + free it again. */ + vPortFree( pxTimer ); + } + #elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + { + /* The timer could have been allocated statically or + dynamically, so check before attempting to free the + memory. */ + if( pxTimer->ucStaticallyAllocated == ( uint8_t ) pdFALSE ) + { + vPortFree( pxTimer ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + break; + + default : + /* Don't expect to get here. */ + break; + } + } + } +} +/*-----------------------------------------------------------*/ + +static void prvSwitchTimerLists( void ) +{ +TickType_t xNextExpireTime, xReloadTime; +List_t *pxTemp; +Timer_t *pxTimer; +BaseType_t xResult; + + /* The tick count has overflowed. The timer lists must be switched. + If there are any timers still referenced from the current timer list + then they must have expired and should be processed before the lists + are switched. */ + while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE ) + { + xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList ); + + /* Remove the timer from the list. */ + pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); + ( void ) uxListRemove( &( pxTimer->xTimerListItem ) ); + traceTIMER_EXPIRED( pxTimer ); + + /* Execute its callback, then send a command to restart the timer if + it is an auto-reload timer. It cannot be restarted here as the lists + have not yet been switched. */ + pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); + + if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE ) + { + /* Calculate the reload value, and if the reload value results in + the timer going into the same timer list then it has already expired + and the timer should be re-inserted into the current list so it is + processed again within this loop. Otherwise a command should be sent + to restart the timer to ensure it is only inserted into a list after + the lists have been swapped. */ + xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ); + if( xReloadTime > xNextExpireTime ) + { + listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime ); + listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer ); + vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) ); + } + else + { + xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY ); + configASSERT( xResult ); + ( void ) xResult; + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + pxTemp = pxCurrentTimerList; + pxCurrentTimerList = pxOverflowTimerList; + pxOverflowTimerList = pxTemp; +} +/*-----------------------------------------------------------*/ + +static void prvCheckForValidListAndQueue( void ) +{ + /* Check that the list from which active timers are referenced, and the + queue used to communicate with the timer service, have been + initialised. */ + taskENTER_CRITICAL(); + { + if( xTimerQueue == NULL ) + { + vListInitialise( &xActiveTimerList1 ); + vListInitialise( &xActiveTimerList2 ); + pxCurrentTimerList = &xActiveTimerList1; + pxOverflowTimerList = &xActiveTimerList2; + + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + /* The timer queue is allocated statically in case + configSUPPORT_DYNAMIC_ALLOCATION is 0. */ + static StaticQueue_t xStaticTimerQueue; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */ + static uint8_t ucStaticTimerQueueStorage[ ( size_t ) configTIMER_QUEUE_LENGTH * sizeof( DaemonTaskMessage_t ) ]; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */ + + xTimerQueue = xQueueCreateStatic( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, ( UBaseType_t ) sizeof( DaemonTaskMessage_t ), &( ucStaticTimerQueueStorage[ 0 ] ), &xStaticTimerQueue ); + } + #else + { + xTimerQueue = xQueueCreate( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, sizeof( DaemonTaskMessage_t ) ); + } + #endif + + #if ( configQUEUE_REGISTRY_SIZE > 0 ) + { + if( xTimerQueue != NULL ) + { + vQueueAddToRegistry( xTimerQueue, "TmrQ" ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configQUEUE_REGISTRY_SIZE */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); +} +/*-----------------------------------------------------------*/ + +BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) +{ +BaseType_t xTimerIsInActiveList; +Timer_t *pxTimer = ( Timer_t * ) xTimer; + + configASSERT( xTimer ); + + /* Is the timer in the list of active timers? */ + taskENTER_CRITICAL(); + { + /* Checking to see if it is in the NULL list in effect checks to see if + it is referenced from either the current or the overflow timer lists in + one go, but the logic has to be reversed, hence the '!'. */ + xTimerIsInActiveList = ( BaseType_t ) !( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) ); /*lint !e961. Cast is only redundant when NULL is passed into the macro. */ + } + taskEXIT_CRITICAL(); + + return xTimerIsInActiveList; +} /*lint !e818 Can't be pointer to const due to the typedef. */ +/*-----------------------------------------------------------*/ + +void *pvTimerGetTimerID( const TimerHandle_t xTimer ) +{ +Timer_t * const pxTimer = ( Timer_t * ) xTimer; +void *pvReturn; + + configASSERT( xTimer ); + + taskENTER_CRITICAL(); + { + pvReturn = pxTimer->pvTimerID; + } + taskEXIT_CRITICAL(); + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ) +{ +Timer_t * const pxTimer = ( Timer_t * ) xTimer; + + configASSERT( xTimer ); + + taskENTER_CRITICAL(); + { + pxTimer->pvTimerID = pvNewID; + } + taskEXIT_CRITICAL(); +} +/*-----------------------------------------------------------*/ + +#if( INCLUDE_xTimerPendFunctionCall == 1 ) + + BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken ) + { + DaemonTaskMessage_t xMessage; + BaseType_t xReturn; + + /* Complete the message with the function parameters and post it to the + daemon task. */ + xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR; + xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend; + xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1; + xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2; + + xReturn = xQueueSendFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken ); + + tracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, xReturn ); + + return xReturn; + } + +#endif /* INCLUDE_xTimerPendFunctionCall */ +/*-----------------------------------------------------------*/ + +#if( INCLUDE_xTimerPendFunctionCall == 1 ) + + BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait ) + { + DaemonTaskMessage_t xMessage; + BaseType_t xReturn; + + /* This function can only be called after a timer has been created or + after the scheduler has been started because, until then, the timer + queue does not exist. */ + configASSERT( xTimerQueue ); + + /* Complete the message with the function parameters and post it to the + daemon task. */ + xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK; + xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend; + xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1; + xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2; + + xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait ); + + tracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, xReturn ); + + return xReturn; + } + +#endif /* INCLUDE_xTimerPendFunctionCall */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer ) + { + return ( ( Timer_t * ) xTimer )->uxTimerNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + void vTimerSetTimerNumber( TimerHandle_t xTimer, UBaseType_t uxTimerNumber ) + { + ( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +/* This entire source file will be skipped if the application is not configured +to include software timer functionality. If you want to include software timer +functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */ +#endif /* configUSE_TIMERS == 1 */ + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/MDK-ARM/FreeRTOS_Mail_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/MDK-ARM/FreeRTOS_Mail_Proj.uvoptx new file mode 100644 index 0000000..0bdce8c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/MDK-ARM/FreeRTOS_Mail_Proj.uvoptx @@ -0,0 +1,439 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + list.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + queue.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + tasks.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + timers.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + cmsis_os.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + 0 + 0 + 0 + 0 + + 6 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + port.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + 0 + 0 + 0 + 0 + + 7 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + heap_4.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 9 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/MDK-ARM/FreeRTOS_Mail_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/MDK-ARM/FreeRTOS_Mail_Proj.uvprojx new file mode 100644 index 0000000..5e55c4b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/MDK-ARM/FreeRTOS_Mail_Proj.uvprojx @@ -0,0 +1,515 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + FreeRTOS_Mail_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\FreeRTOS_Mail_Proj.bin .\Objects\FreeRTOS_Mail_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + middlewares\Third_Party\FreeRTOS\Source + + + list.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + + + queue.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + + + tasks.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + + + timers.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + + + cmsis_os.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + + + port.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + + + heap_4.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/inc/FreeRTOSConfig.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..13442df --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/inc/FreeRTOSConfig.h @@ -0,0 +1,170 @@ +/* + FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + extern uint32_t SystemCoreClock; +#endif + + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ( ( portTickType ) 1000 ) +#define configMAX_PRIORITIES ( 7 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 3 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Software timer definitions. */ +#define configUSE_TIMERS 0 +#define configTIMER_TASK_PRIORITY ( 2 ) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 0 +#define INCLUDE_vTaskDelayUntil 0 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 2 /* 3 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler + +/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware, + to prevent overwriting SysTick_Handler defined within STM32Cube HAL */ +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/inc/main.h new file mode 100644 index 0000000..8fec498 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/inc/main.h @@ -0,0 +1,113 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#define TICK_INT_PRIORITY (((uint32_t)1U<<__NVIC_PRIO_BITS) - 1U) + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +typedef enum +{ + LED1 = 0, + LED2 = 1 +} Led_TypeDef; + +static void MailQueueProducer (const void *argument); +static void MailQueueConsumer (const void *argument); + +static void LED_Thread1(void const *argument); +static void LED_Thread2(void const *argument); +static void Signal_Gen_Thread(void const *argument); + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/readme.txt new file mode 100644 index 0000000..66e1533 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/readme.txt @@ -0,0 +1,23 @@ +1. Function description + + This example mainly demonstrates the use of the tickless mode with low power consumption of FreeRTOS (in and out of the Idle mode of the kernel) + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + + usage method: + 1. Burn to development board after compilation + 2. Check LED blinking + +4. Precautions \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/src/main.c new file mode 100644 index 0000000..68e7f28 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/src/main.c @@ -0,0 +1,300 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "cmsis_os.h" + +/** + * FreeRTOS Mail + */ + +/* Private typedef -----------------------------------------------------------*/ +typedef struct +{ /* Mail object structure */ + uint32_t var1; /* var1 is a uint32_t */ + uint32_t var2; /* var2 is a uint32_t */ + uint8_t var3; /* var3 is a uint8_t */ +} Amail_TypeDef; +/* Private define ------------------------------------------------------------*/ +#define blckqSTACK_SIZE configMINIMAL_STACK_SIZE +#define MAIL_SIZE (uint32_t) 1 +#define SYSTICK_1MS ((uint32_t)1000) +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint32_t Tick_num = 0; +//osThreadId LED1_ThreadId, LED2_ThreadId; +osMailQId mailId; + +uint32_t ProducerValue1 = 0, ProducerValue2 = 0; +uint8_t ProducerValue3 = 0; +uint32_t ConsumerValue1 = 0, ConsumerValue2 = 0; +uint8_t ConsumerValue3 = 0; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program. + */ +int main(void) +{ + /*Configure the SysTick IRQ priority */ + N32_NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY, 0); + /* Get SystemCoreClock */ + SystemCoreClockUpdate(); + + /* Config 1s SysTick 1ms */ + SysTick_Config(SystemCoreClock/SYSTICK_1MS); + + /* Initialize Led1~Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Turn off Led1~Led2*/ + LedOff(LED1_PORT, LED1_PIN); + LedOff(LED2_PORT, LED2_PIN); + + /* Create the mail queue used by the two tasks to pass the struct Amail_TypeDef */ + osMailQDef(mail, MAIL_SIZE, Amail_TypeDef); /* Define mail queue */ + mailId = osMailCreate(osMailQ(mail), NULL); /* create mail queue */ + + /* Note the producer has a lower priority than the consumer when the tasks are + spawned. */ + osThreadDef(QCons, MailQueueConsumer, osPriorityBelowNormal, 0, blckqSTACK_SIZE); + osThreadCreate(osThread(QCons), NULL); + + osThreadDef(QProd, MailQueueProducer, osPriorityBelowNormal, 0, blckqSTACK_SIZE); + osThreadCreate(osThread(QProd), NULL); + + /* Start scheduler */ + osKernelStart (); + + /* We should never get here as control is now taken by the scheduler */ + for(;;); +} + +/** + * @brief Mail Producer Thread. + * @param argument: Not used + * @retval None + */ +static void MailQueueProducer(const void *argument) +{ + Amail_TypeDef *pTMail; + + for(;;) + { + + pTMail = osMailAlloc(mailId, osWaitForever); /* Allocate memory */ + pTMail->var1 = ProducerValue1; /* Set the mail content */ + pTMail->var2 = ProducerValue2; + pTMail->var3 = ProducerValue3; + + if(osMailPut(mailId, pTMail) != osOK) /* Send Mail */ + { + /* Turn on LED2 to indicate error */ + LedOn(LED2_PORT,LED2_PIN); + } + else + { + /* Increment the variables we are going to post next time round. The + consumer will expect the numbers to follow in numerical order. */ + ++ProducerValue1; + ProducerValue2 += 2; + ProducerValue3 += 3; + + /* Toggle LED1 to indicate a correct number received */ + LedBlink(LED1_PORT,LED1_PIN); + + osDelay(250); + } + } +} + +/** + * @brief Mail Consumer Thread. + * @param argument: Not used + * @retval None + */ +static void MailQueueConsumer (const void *argument) +{ + osEvent event; + Amail_TypeDef *pRMail; + + for(;;) + { + /* Get the message from the queue */ + event = osMailGet(mailId, osWaitForever); /* wait for mail */ + + if(event.status == osEventMail) + { + pRMail = event.value.p; + + if((pRMail->var1 != ConsumerValue1) || (pRMail->var2 != ConsumerValue2) || (pRMail->var3 != ConsumerValue3)) + { + /* Catch-up. */ + ConsumerValue1 = pRMail->var1; + ConsumerValue2 = pRMail->var2; + ConsumerValue3 = pRMail->var3; + + /* Turn on LED2 to indicate error */ + LedOn(LED2_PORT,LED2_PIN); + } + else + { + /* Calculate values we expect to remove from the mail queue next time + round. */ + ++ConsumerValue1; + ConsumerValue2 += 2; + ConsumerValue3 += 3; + } + + osMailFree(mailId, pRMail); /* free memory allocated for mail */ + } + } +} + +/** + * @brief Sets the priority of an interrupt. + * @param IRQn External interrupt number . + * This parameter can be an enumerator of IRQn_Type enumeration + * @param PreemptPriority The pre-emption priority for the IRQn channel. + * This parameter can be a value between 0 and 3. + * A lower priority value indicates a higher priority + * @param SubPriority the subpriority level for the IRQ channel. + * this parameter is a dummy value and it is ignored, because + * no subpriority supported in Cortex M0 based products. + * @retval None + */ +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) +{ + /* Check the parameters */ + assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)); + NVIC_SetPriority(IRQn,PreemptPriority); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/src/n32wb03x_it.c new file mode 100644 index 0000000..9a7f49a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mail/src/n32wb03x_it.c @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "cmsis_os.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +extern uint32_t Tick_num; + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + Tick_num++; + osSystickHandler(); +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/MDK-ARM/FreeRTOS_Mutexes_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/MDK-ARM/FreeRTOS_Mutexes_Proj.uvoptx new file mode 100644 index 0000000..0bdce8c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/MDK-ARM/FreeRTOS_Mutexes_Proj.uvoptx @@ -0,0 +1,439 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + list.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + queue.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + tasks.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + timers.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + cmsis_os.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + 0 + 0 + 0 + 0 + + 6 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + port.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + 0 + 0 + 0 + 0 + + 7 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + heap_4.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 9 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/MDK-ARM/FreeRTOS_Mutexes_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/MDK-ARM/FreeRTOS_Mutexes_Proj.uvprojx new file mode 100644 index 0000000..b6f4401 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/MDK-ARM/FreeRTOS_Mutexes_Proj.uvprojx @@ -0,0 +1,515 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + FreeRTOS_Mutexes_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\FreeRTOS_Mutexes_Proj.bin .\Objects\FreeRTOS_Mutexes_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + middlewares\Third_Party\FreeRTOS\Source + + + list.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + + + queue.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + + + tasks.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + + + timers.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + + + cmsis_os.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + + + port.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + + + heap_4.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/inc/FreeRTOSConfig.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..614352c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/inc/FreeRTOSConfig.h @@ -0,0 +1,169 @@ +/* + FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + extern uint32_t SystemCoreClock; +#endif + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 7 ) +#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 3 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Software timer definitions. */ +#define configUSE_TIMERS 0 +#define configTIMER_TASK_PRIORITY ( 2 ) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 0 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xQueueGetMutexHolder 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_eTaskGetState 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 2 /* 3 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 3 + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 3 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler + +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/inc/main.h new file mode 100644 index 0000000..2cf18cf --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/inc/main.h @@ -0,0 +1,103 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#define TICK_INT_PRIORITY (((uint32_t)1U<<__NVIC_PRIO_BITS) - 1U) + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +static void MutexHighPriorityThread(void const *argument); +static void MutexMediumPriorityThread(void const *argument); +static void MutexLowPriorityThread(void const *argument); + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/readme.txt new file mode 100644 index 0000000..947b51c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/readme.txt @@ -0,0 +1,23 @@ +1. Function description + + This example mainly demonstrates the creation and use of FreeRTOS mutex semaphores + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + + usage method: + 1. Burn to development board after compilation + 2. Check LED blinking + +4. Precautions \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/src/main.c new file mode 100644 index 0000000..11bff63 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/src/main.c @@ -0,0 +1,400 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "cmsis_os.h" + +/** + * FreeRTOS Mutexes + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define SYSTICK_1MS ((uint32_t)1000) +/* Private macro -------------------------------------------------------------*/ +#define mutexSHORT_DELAY ((uint32_t) 20) +#define mutexNO_DELAY ((uint32_t) 0) +#define mutexTWO_TICK_DELAY ((uint32_t) 2) +/* Private variables ---------------------------------------------------------*/ +uint32_t Tick_num = 0; +static osMutexId osMutex; + +/* Variables used to detect and latch errors */ +__IO uint32_t HighPriorityThreadCycles = 0, MediumPriorityThreadCycles = 0, LowPriorityThreadCycles = 0; + +/* Handles of the two higher priority tasks, required so they can be resumed(unsuspended) */ +static osThreadId osHighPriorityThreadHandle, osMediumPriorityThreadHandle; + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program. + */ +int main(void) +{ + /*Configure the SysTick IRQ priority */ + N32_NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY, 0); + /* Get SystemCoreClock */ + SystemCoreClockUpdate(); + + /* Config 1s SysTick 1ms */ + SysTick_Config(SystemCoreClock/SYSTICK_1MS); + + /* Initialize Led1~Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Turn off Led1~Led2*/ + LedOff(LED1_PORT, LED1_PIN); + LedOff(LED2_PORT, LED2_PIN); + + /* Create the mutex */ + osMutexDef(osMutex); + osMutex = osMutexCreate(osMutex(osMutex)); + + if (osMutex != NULL) + { + /* Define and create the high priority thread */ + osThreadDef(MutHigh, MutexHighPriorityThread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE); + osHighPriorityThreadHandle = osThreadCreate(osThread(MutHigh), NULL); + + /* Define and create the medium priority thread */ + osThreadDef(MutMedium, MutexMediumPriorityThread, osPriorityLow, 0, configMINIMAL_STACK_SIZE); + osMediumPriorityThreadHandle = osThreadCreate(osThread(MutMedium), NULL); + + /* Define and create the low priority thread */ + osThreadDef(MutLow, MutexLowPriorityThread, osPriorityIdle, 0, configMINIMAL_STACK_SIZE); + osThreadCreate(osThread(MutLow), NULL); + } + + /* Start scheduler */ + osKernelStart(); + + /* We should never get here as control is now taken by the scheduler */ + for(;;); +} + +/** + * @brief Mutex High Priority Thread. + * @param argument: Not used + * @retval None + */ +static void MutexHighPriorityThread(void const *argument) +{ + /* Just to remove compiler warning */ + (void) argument; + + for (;;) + { + /* The first time through the mutex will be immediately available, on + subsequent times through the mutex will be held by the low priority thread + at this point and this Take will cause the low priority thread to inherit + the priority of this tadhr. In this case the block time must be + long enough to ensure the low priority thread will execute again before the + block time expires. If the block time does expire then the error + flag will be set here */ + if (osMutexWait(osMutex, mutexTWO_TICK_DELAY) != osOK) + { + /* Toggle LED2 to indicate error */ + LedBlink(LED2_PORT,LED2_PIN); + } + + /* Ensure the other thread attempting to access the mutex + are able to execute to ensure they either block (where a block + time is specified) or return an error (where no block time is + specified) as the mutex is held by this task */ + osDelay(mutexSHORT_DELAY); + + /* We should now be able to release the mutex . + When the mutex is available again the medium priority thread + should be unblocked but not run because it has a lower priority + than this thread. The low priority thread should also not run + at this point as it too has a lower priority than this thread */ + if (osMutexRelease(osMutex) != osOK) + { + /* Toggle LED2 to indicate error */ + LedBlink(LED2_PORT,LED2_PIN); + } + + /* Keep count of the number of cycles this thread has performed */ + HighPriorityThreadCycles++; + LedBlink(LED1_PORT,LED1_PIN); + + /* Suspend ourselves to the medium priority thread can execute */ + osThreadSuspend(NULL); + } +} + +/** + * @brief Mutex Medium Priority Thread. + * @param argument: Not used + * @retval None + */ +static void MutexMediumPriorityThread(void const *argument) +{ + /* Just to remove compiler warning */ + (void) argument; + + for (;;) + { + /* This thread will run while the high-priority thread is blocked, and the + high-priority thread will block only once it has the mutex - therefore + this call should block until the high-priority thread has given up the + mutex, and not actually execute past this call until the high-priority + thread is suspended */ + if (osMutexWait(osMutex, osWaitForever) == osOK) + { + if (osThreadGetState(osHighPriorityThreadHandle) != osThreadSuspended) + { + /* Did not expect to execute until the high priority thread was + suspended. + Toggle LED2 to indicate error */ + LedBlink(LED2_PORT,LED2_PIN); + } + else + { + /* Give the mutex back before suspending ourselves to allow + the low priority thread to obtain the mutex */ + if (osMutexRelease(osMutex) != osOK) + { + /* Toggle LED2 to indicate error */ + LedBlink(LED2_PORT,LED2_PIN); + } + osThreadSuspend(NULL); + } + } + else + { + /* We should not leave the osMutexWait() function + until the mutex was obtained. + Toggle LED2 to indicate error */ + LedBlink(LED2_PORT,LED2_PIN); + } + + /* The High and Medium priority threads should be in lock step */ + if (HighPriorityThreadCycles != (MediumPriorityThreadCycles + 1)) + { + /* Toggle LED2 to indicate error */ + LedBlink(LED2_PORT,LED2_PIN); + } + + /* Keep count of the number of cycles this task has performed so a + stall can be detected */ + MediumPriorityThreadCycles++; + LedBlink(LED1_PORT,LED1_PIN); + } +} + +/** + * @brief Mutex Low Priority Thread. + * @param argument: Not used + * @retval None + */ +static void MutexLowPriorityThread(void const *argument) +{ + /* Just to remove compiler warning */ + (void) argument; + + for (;;) + { + /* Keep attempting to obtain the mutex. We should only obtain it when + the medium-priority thread has suspended itself, which in turn should only + happen when the high-priority thread is also suspended */ + if (osMutexWait(osMutex, mutexNO_DELAY) == osOK) + { + /* Is the haigh and medium-priority threads suspended? */ + if ((osThreadGetState(osHighPriorityThreadHandle) != osThreadSuspended) || (osThreadGetState(osMediumPriorityThreadHandle) != osThreadSuspended)) + { + /* Toggle LED2 to indicate error */ + LedBlink(LED2_PORT,LED2_PIN); + } + else + { + /* Keep count of the number of cycles this task has performed + so a stall can be detected */ + LowPriorityThreadCycles++; + LedBlink(LED1_PORT,LED1_PIN); + + /* We can resume the other tasks here even though they have a + higher priority than the this thread. When they execute they + will attempt to obtain the mutex but fail because the low-priority + thread is still the mutex holder. this thread will then inherit + the higher priority. The medium-priority thread will block indefinitely + when it attempts to obtain the mutex, the high-priority thread will only + block for a fixed period and an error will be latched if the + high-priority thread has not returned the mutex by the time this + fixed period has expired */ + osThreadResume(osMediumPriorityThreadHandle); + osThreadResume(osHighPriorityThreadHandle); + + /* The other two tasks should now have executed and no longer + be suspended */ + if ((osThreadGetState(osHighPriorityThreadHandle) == osThreadSuspended) || (osThreadGetState(osMediumPriorityThreadHandle) == osThreadSuspended)) + { + /* Toggle LED2 to indicate error */ + LedBlink(LED2_PORT,LED2_PIN); + } + + /* Release the mutex, disinheriting the higher priority again */ + if (osMutexRelease(osMutex) != osOK) + { + /* Toggle LED2 to indicate error */ + LedBlink(LED2_PORT,LED2_PIN); + } + } + } + +#if configUSE_PREEMPTION == 0 + { + taskYIELD(); + } +#endif + } +} + +/** + * @brief Sets the priority of an interrupt. + * @param IRQn External interrupt number . + * This parameter can be an enumerator of IRQn_Type enumeration + * @param PreemptPriority The pre-emption priority for the IRQn channel. + * This parameter can be a value between 0 and 3. + * A lower priority value indicates a higher priority + * @param SubPriority the subpriority level for the IRQ channel. + * this parameter is a dummy value and it is ignored, because + * no subpriority supported in Cortex M0 based products. + * @retval None + */ +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) +{ + /* Check the parameters */ + assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)); + NVIC_SetPriority(IRQn,PreemptPriority); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/src/n32wb03x_it.c new file mode 100644 index 0000000..9a7f49a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Mutexes/src/n32wb03x_it.c @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "cmsis_os.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +extern uint32_t Tick_num; + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + Tick_num++; + osSystickHandler(); +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/MDK-ARM/FreeRTOS_Queues_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/MDK-ARM/FreeRTOS_Queues_Proj.uvoptx new file mode 100644 index 0000000..0bdce8c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/MDK-ARM/FreeRTOS_Queues_Proj.uvoptx @@ -0,0 +1,439 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + list.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + queue.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + tasks.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + timers.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + cmsis_os.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + 0 + 0 + 0 + 0 + + 6 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + port.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + 0 + 0 + 0 + 0 + + 7 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + heap_4.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 9 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/MDK-ARM/FreeRTOS_Queues_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/MDK-ARM/FreeRTOS_Queues_Proj.uvprojx new file mode 100644 index 0000000..baec2d4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/MDK-ARM/FreeRTOS_Queues_Proj.uvprojx @@ -0,0 +1,515 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + FreeRTOS_Queues_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\FreeRTOS_Queues_Proj.bin .\Objects\FreeRTOS_Queues_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + middlewares\Third_Party\FreeRTOS\Source + + + list.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + + + queue.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + + + tasks.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + + + timers.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + + + cmsis_os.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + + + port.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + + + heap_4.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/inc/FreeRTOSConfig.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..614352c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/inc/FreeRTOSConfig.h @@ -0,0 +1,169 @@ +/* + FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + extern uint32_t SystemCoreClock; +#endif + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 7 ) +#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 3 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Software timer definitions. */ +#define configUSE_TIMERS 0 +#define configTIMER_TASK_PRIORITY ( 2 ) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 0 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xQueueGetMutexHolder 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_eTaskGetState 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 2 /* 3 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 3 + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 3 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler + +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/inc/main.h new file mode 100644 index 0000000..4971453 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/inc/main.h @@ -0,0 +1,104 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#define TICK_INT_PRIORITY (((uint32_t)1U<<__NVIC_PRIO_BITS) - 1U) + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +/* Thread function that creates an incrementing number and posts it on a queue */ +static void MessageQueueProducer(const void *argument); +/* Thread function that removes the incrementing number from a queue and checks that it is the expected number */ +static void MessageQueueConsumer(const void *argument); + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/readme.txt new file mode 100644 index 0000000..7db50bd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + + This example mainly demonstrates the creation and use of FreeRTOS message queue + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + + usage method: + 1. Burn to development board after compilation + 2. Check LED blinking + +4. Precautions \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/src/main.c new file mode 100644 index 0000000..36e97f1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/src/main.c @@ -0,0 +1,269 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "cmsis_os.h" + +/** + * FreeRTOS Queues + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define SYSTICK_1MS ((uint32_t)1000) +/* Private macro -------------------------------------------------------------*/ +#define blckqSTACK_SIZE configMINIMAL_STACK_SIZE +#define QUEUE_SIZE (uint32_t) 1 +/* Private variables ---------------------------------------------------------*/ +uint32_t Tick_num = 0; +osMessageQId osQueue; +uint32_t ProducerValue = 0, ConsumerValue = 0; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program. + */ +int main(void) +{ + /*Configure the SysTick IRQ priority */ + N32_NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY, 0); + /* Get SystemCoreClock */ + SystemCoreClockUpdate(); + + /* Config 1s SysTick 1ms */ + SysTick_Config(SystemCoreClock/SYSTICK_1MS); + + /* Initialize Led1~Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Turn off Led1~Led2*/ + LedOff(LED1_PORT, LED1_PIN); + LedOff(LED2_PORT, LED2_PIN); + + /* Create the queue used by the two tasks to pass the incrementing number. + Pass a pointer to the queue in the parameter structure */ + osMessageQDef(osqueue, QUEUE_SIZE, uint16_t); + osQueue = osMessageCreate(osMessageQ(osqueue), NULL); + + /* Note that the producer has a lower priority than the consumer when the tasks are spawned */ + osThreadDef(QCons, MessageQueueConsumer, osPriorityBelowNormal, 0, blckqSTACK_SIZE); + osThreadCreate(osThread(QCons), NULL); + + osThreadDef(QProd, MessageQueueProducer, osPriorityBelowNormal, 0, blckqSTACK_SIZE); + osThreadCreate(osThread(QProd), NULL); + + /* Start scheduler */ + osKernelStart(); + + /* We should never get here as control is now taken by the scheduler */ + for(;;); +} + +/** + * @brief Message Queue Producer Thread. + * @param argument: Not used + * @retval None + */ +static void MessageQueueProducer(const void *argument) +{ + for (;;) + { + if (osMessagePut(osQueue, ProducerValue, 100) != osOK) + { + /* Switch On continuously LED2 to indicate error */ + LedOn(LED2_PORT, LED2_PIN); + } + else + { + /* Increment the variable we are going to post next time round. The + consumer will expect the numbers to follow in numerical order */ + ++ProducerValue; + + /* Toggle LED1 to indicate a correct number received */ + LedBlink(LED1_PORT, LED1_PIN); + osDelay(1000); + } + } +} + +/** + * @brief Message Queue Consumer Thread. + * @param argument: Not used + * @retval None + */ +static void MessageQueueConsumer(const void *argument) +{ + osEvent event; + + for (;;) + { + /* Get the message from the queue */ + event = osMessageGet(osQueue, 100); + + if (event.status == osEventMessage) + { + if (event.value.v != ConsumerValue) + { + /* Catch-up */ + ConsumerValue = event.value.v; + + /* Switch On continuously LED2 to indicate error */ + LedOn(LED2_PORT, LED2_PIN); + } + else + { + /* Increment the value we expect to remove from the queue next time + round */ + ++ConsumerValue; + } + } + } +} + +/** + * @brief Sets the priority of an interrupt. + * @param IRQn External interrupt number . + * This parameter can be an enumerator of IRQn_Type enumeration + * @param PreemptPriority The pre-emption priority for the IRQn channel. + * This parameter can be a value between 0 and 3. + * A lower priority value indicates a higher priority + * @param SubPriority the subpriority level for the IRQ channel. + * this parameter is a dummy value and it is ignored, because + * no subpriority supported in Cortex M0 based products. + * @retval None + */ +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) +{ + /* Check the parameters */ + assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)); + NVIC_SetPriority(IRQn,PreemptPriority); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/src/n32wb03x_it.c new file mode 100644 index 0000000..9a7f49a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Queues/src/n32wb03x_it.c @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "cmsis_os.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +extern uint32_t Tick_num; + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + Tick_num++; + osSystickHandler(); +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/MDK-ARM/FreeRTOS_Semaphore_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/MDK-ARM/FreeRTOS_Semaphore_Proj.uvoptx new file mode 100644 index 0000000..0bdce8c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/MDK-ARM/FreeRTOS_Semaphore_Proj.uvoptx @@ -0,0 +1,439 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + list.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + queue.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + tasks.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + timers.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + cmsis_os.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + 0 + 0 + 0 + 0 + + 6 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + port.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + 0 + 0 + 0 + 0 + + 7 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + heap_4.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 9 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/MDK-ARM/FreeRTOS_Semaphore_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/MDK-ARM/FreeRTOS_Semaphore_Proj.uvprojx new file mode 100644 index 0000000..91c9ee0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/MDK-ARM/FreeRTOS_Semaphore_Proj.uvprojx @@ -0,0 +1,515 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + FreeRTOS_Semaphore_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\FreeRTOS_Semaphore_Proj.bin .\Objects\FreeRTOS_Semaphore_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + middlewares\Third_Party\FreeRTOS\Source + + + list.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + + + queue.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + + + tasks.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + + + timers.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + + + cmsis_os.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + + + port.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + + + heap_4.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/inc/FreeRTOSConfig.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..614352c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/inc/FreeRTOSConfig.h @@ -0,0 +1,169 @@ +/* + FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + extern uint32_t SystemCoreClock; +#endif + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 7 ) +#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 3 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Software timer definitions. */ +#define configUSE_TIMERS 0 +#define configTIMER_TASK_PRIORITY ( 2 ) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 0 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xQueueGetMutexHolder 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_eTaskGetState 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 2 /* 3 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 3 + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 3 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler + +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/inc/main.h new file mode 100644 index 0000000..582cb67 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/inc/main.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#define TICK_INT_PRIORITY (((uint32_t)1U<<__NVIC_PRIO_BITS) - 1U) + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +static void SemaphoreThread1(void const *argument); +static void SemaphoreThread2(void const *argument); + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/readme.txt new file mode 100644 index 0000000..c847129 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + + This example mainly demonstrates the creation and use of FreeRTOS semaphores + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + + usage method: + 1. Burn to development board after compilation + 2. Check LED blinking + +4. Precautions \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/src/main.c new file mode 100644 index 0000000..3b963ad --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/src/main.c @@ -0,0 +1,290 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "cmsis_os.h" + +/** + * FreeRTOS Semaphore + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define SYSTICK_1MS ((uint32_t)1000) +/* Private macro -------------------------------------------------------------*/ +#define semtstSTACK_SIZE configMINIMAL_STACK_SIZE +/* Private variables ---------------------------------------------------------*/ +uint32_t Tick_num = 0; +osThreadId SemThread1Handle, SemThread2Handle; +osSemaphoreId osSemaphore; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program. + */ +int main(void) +{ + /*Configure the SysTick IRQ priority */ + N32_NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY, 0); + /* Get SystemCoreClock */ + SystemCoreClockUpdate(); + + /* Config 1s SysTick 1ms */ + SysTick_Config(SystemCoreClock/SYSTICK_1MS); + + /* Initialize Led1~Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Turn on Led1~Led2*/ + LedOn(LED1_PORT, LED1_PIN); + LedOn(LED2_PORT, LED2_PIN); + + /* Define used semaphore */ + osSemaphoreDef(SEM); + + /* Create the semaphore used by the two threads */ + osSemaphore = osSemaphoreCreate(osSemaphore(SEM) , 1); + + /* Create the first Thread */ + osThreadDef(SEM_Thread1, SemaphoreThread1, osPriorityLow, 0, semtstSTACK_SIZE); + SemThread1Handle = osThreadCreate(osThread(SEM_Thread1), (void *) osSemaphore); + + /* Create the second Thread */ + osThreadDef(SEM_Thread2, SemaphoreThread2, osPriorityIdle, 0, semtstSTACK_SIZE); + SemThread2Handle = osThreadCreate(osThread(SEM_Thread2), (void *) osSemaphore); + + /* Start scheduler */ + osKernelStart(); + + /* We should never get here as control is now taken by the scheduler */ + for(;;); +} + +/** + * @brief Semaphore Thread 1 function + * @param argument: shared semaphore + * @retval None + */ +static void SemaphoreThread1(void const *argument) +{ + uint32_t count = 0; + osSemaphoreId semaphore = (osSemaphoreId) argument; + + for (;;) + { + if (semaphore != NULL) + { + /* Try to obtain the semaphore */ + if (osSemaphoreWait(semaphore , 100) == osOK) + { + count = osKernelSysTick() + 5000; + + /* Toggle LED2 every 200 ms for 5 seconds */ + while (count >= osKernelSysTick()) + { + /* Toggle LED1 */ + LedBlink(LED1_PORT, LED1_PIN); + + /* Delay 200 ms */ + osDelay(200); + } + + /* Turn off LED1*/ + LedOff(LED1_PORT, LED1_PIN);; + /* Release the semaphore */ + osSemaphoreRelease(semaphore); + + /* Suspend ourseleves to execute thread 2 (lower priority) */ + osThreadSuspend(NULL); + } + } + } +} + +/** + * @brief Semaphore Thread 2 function + * @param argument: shared semaphore + * @retval None + */ +static void SemaphoreThread2(void const *argument) +{ + uint32_t count = 0; + osSemaphoreId semaphore = (osSemaphoreId) argument; + + for (;;) + { + if (semaphore != NULL) + { + /* Try to obtain the semaphore */ + if (osSemaphoreWait(semaphore , 0) == osOK) + { + /* Resume Thread 1 (higher priority)*/ + osThreadResume(SemThread1Handle); + + count = osKernelSysTick() + 5000; + + /* Toggle LED2 every 200 ms for 5 seconds*/ + while (count >= osKernelSysTick()) + { + LedBlink(LED2_PORT, LED2_PIN); + + osDelay(200); + } + + /* Turn off LED2 */ + LedOff(LED2_PORT, LED2_PIN); + + /* Release the semaphore to unblock Thread 1 (higher priority) */ + osSemaphoreRelease(semaphore); + } + } + } +} + +/** + * @brief Sets the priority of an interrupt. + * @param IRQn External interrupt number . + * This parameter can be an enumerator of IRQn_Type enumeration + * @param PreemptPriority The pre-emption priority for the IRQn channel. + * This parameter can be a value between 0 and 3. + * A lower priority value indicates a higher priority + * @param SubPriority the subpriority level for the IRQ channel. + * this parameter is a dummy value and it is ignored, because + * no subpriority supported in Cortex M0 based products. + * @retval None + */ +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) +{ + /* Check the parameters */ + assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)); + NVIC_SetPriority(IRQn,PreemptPriority); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/src/n32wb03x_it.c new file mode 100644 index 0000000..9a7f49a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Semaphore/src/n32wb03x_it.c @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "cmsis_os.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +extern uint32_t Tick_num; + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + Tick_num++; + osSystickHandler(); +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/MDK-ARM/FreeRTOS_SemaphoreFromISR_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/MDK-ARM/FreeRTOS_SemaphoreFromISR_Proj.uvoptx new file mode 100644 index 0000000..4bdc1ba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/MDK-ARM/FreeRTOS_SemaphoreFromISR_Proj.uvoptx @@ -0,0 +1,451 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + list.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + queue.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + tasks.c + 0 + 0 + + + 4 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + timers.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + 0 + 0 + 0 + 0 + + 5 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + cmsis_os.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + 0 + 0 + 0 + 0 + + 6 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + port.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + 0 + 0 + 0 + 0 + + 7 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + heap_4.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 9 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/MDK-ARM/FreeRTOS_SemaphoreFromISR_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/MDK-ARM/FreeRTOS_SemaphoreFromISR_Proj.uvprojx new file mode 100644 index 0000000..add63cd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/MDK-ARM/FreeRTOS_SemaphoreFromISR_Proj.uvprojx @@ -0,0 +1,520 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + FreeRTOS_SemaphoreFromISR_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\FreeRTOS_SemaphoreFromISR_Proj.bin .\Objects\FreeRTOS_SemaphoreFromISR_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + + + middlewares\Third_Party\FreeRTOS\Source + + + list.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + + + queue.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + + + tasks.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + + + timers.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + + + cmsis_os.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + + + port.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + + + heap_4.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/inc/FreeRTOSConfig.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..a5dde07 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/inc/FreeRTOSConfig.h @@ -0,0 +1,169 @@ +/* + FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + extern uint32_t SystemCoreClock; +#endif + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 7 ) +#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 2 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Software timer definitions. */ +#define configUSE_TIMERS 0 +#define configTIMER_TASK_PRIORITY ( 2 ) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 0 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xQueueGetMutexHolder 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_eTaskGetState 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 2 /* 3 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 3 + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 3 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler + +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/inc/main.h new file mode 100644 index 0000000..5e65a24 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/inc/main.h @@ -0,0 +1,111 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#define TICK_INT_PRIORITY (((uint32_t)1U<<__NVIC_PRIO_BITS) - 1U) + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +#define KEY_INPUT_PORT GPIOB +#define KEY_INPUT_PIN GPIO_PIN_1 +#define KEY_INPUT_EXTI_LINE EXTI_LINE1 +#define KEY_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY_INPUT_PIN_SOURCE GPIO_PIN_SOURCE1 +#define KEY_INPUT_IRQn EXTI0_1_IRQn + +static void SemaphoreTest(void const *argument); +void ReleaseSemaphore(void); +void SystemClock_Config(void); + +void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/inc/n32wb03x_it.h new file mode 100644 index 0000000..8e5f9d4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void EXTI4_15_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/readme.txt new file mode 100644 index 0000000..027a49b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + + This example mainly demonstrates the creation and use of FreeRTOS semaphores (processing calls in interrupt service functions) + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + + usage method: + 1. Burn to development board after compilation + 2. Check LED blinking + +4. Precautions \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/src/main.c new file mode 100644 index 0000000..a0ebd7f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/src/main.c @@ -0,0 +1,293 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "cmsis_os.h" + +/** + * FreeRTOS SemaphoreFromISR + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define SYSTICK_1MS ((uint32_t)1000) +/* Private macro -------------------------------------------------------------*/ +#define semtstSTACK_SIZE configMINIMAL_STACK_SIZE +/* Private variables ---------------------------------------------------------*/ +uint32_t Tick_num = 0; +osSemaphoreId osSemaphore; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program. + */ +int main(void) +{ + /*Configure the SysTick IRQ priority */ + N32_NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY, 0); + /* Get SystemCoreClock */ + SystemCoreClockUpdate(); + + /* Config 1s SysTick 1ms */ + SysTick_Config(SystemCoreClock/SYSTICK_1MS); + + /* Initialize Led1~Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Turn off Led1~Led2*/ + LedOff(LED1_PORT, LED1_PIN); + LedOff(LED2_PORT, LED2_PIN); + + /*Initialize key as external line interrupt*/ + KeyInputExtiInit(KEY_INPUT_PORT, KEY_INPUT_PIN); + + /* Define used semaphore */ + osSemaphoreDef(SEM); + + /* Create the semaphore used by the two threads */ + osSemaphore = osSemaphoreCreate(osSemaphore(SEM) , 1); + + /* Create the Thread that toggle LED1 */ + osThreadDef(SEM_Thread, SemaphoreTest, osPriorityNormal, 0, semtstSTACK_SIZE); + osThreadCreate(osThread(SEM_Thread), (void *) osSemaphore); + + /* Start scheduler */ + osKernelStart(); + + /* We should never get here as control is now taken by the scheduler */ + for(;;); +} + +/** + * @brief Semaphore Test. + * @param argument: Not used + * @retval None + */ +static void SemaphoreTest(void const *argument) +{ + for (;;) + { + if (osSemaphore != NULL) + { + /* Try to obtain the semaphore */ + if (osSemaphoreWait(osSemaphore , 0) == osOK) + { + LedBlink(LED1_PORT, LED1_PIN); + } + } + } +} + +/** + * @brief Release the semaphore. + * @param None + * @retval None + */ +void ReleaseSemaphore(void) +{ + /* Release the semaphore to unblock Thread */ + osSemaphoreRelease(osSemaphore); +} + +/** + * @brief Sets the priority of an interrupt. + * @param IRQn External interrupt number . + * This parameter can be an enumerator of IRQn_Type enumeration + * @param PreemptPriority The pre-emption priority for the IRQn channel. + * This parameter can be a value between 0 and 3. + * A lower priority value indicates a higher priority + * @param SubPriority the subpriority level for the IRQ channel. + * this parameter is a dummy value and it is ignored, because + * no subpriority supported in Cortex M0 based products. + * @retval None + */ +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) +{ + /* Check the parameters */ + assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)); + NVIC_SetPriority(IRQn,PreemptPriority); +} + +/** + * @brief Configures key port. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + } + else + { + return; + } + + /*Configure the GPIO pin as input floating*/ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } + + /*Configure key EXTI Line to key input Pin*/ + GPIO_ConfigEXTILine(KEY_INPUT_PORT_SOURCE, KEY_INPUT_PIN_SOURCE); + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; // EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/src/n32wb03x_it.c new file mode 100644 index 0000000..9f2d94f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SemaphoreFromISR/src/n32wb03x_it.c @@ -0,0 +1,128 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "cmsis_os.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +extern uint32_t Tick_num; + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + Tick_num++; + osSystickHandler(); +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief External lines 0 to 1 interrupt. + */ +void EXTI0_1_IRQHandler(void) +{ + if (RESET != EXTI_GetITStatus(KEY_INPUT_EXTI_LINE)) + { + /* Release the semaphore */ + ReleaseSemaphore(); + EXTI_ClrITPendBit(KEY_INPUT_EXTI_LINE); + } +} + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/MDK-ARM/FreeRTOS_Signal_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/MDK-ARM/FreeRTOS_Signal_Proj.uvoptx new file mode 100644 index 0000000..0bdce8c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/MDK-ARM/FreeRTOS_Signal_Proj.uvoptx @@ -0,0 +1,439 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + list.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + queue.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + tasks.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + timers.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + cmsis_os.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + 0 + 0 + 0 + 0 + + 6 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + port.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + 0 + 0 + 0 + 0 + + 7 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + heap_4.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 9 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/MDK-ARM/FreeRTOS_Signal_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/MDK-ARM/FreeRTOS_Signal_Proj.uvprojx new file mode 100644 index 0000000..2c3b440 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/MDK-ARM/FreeRTOS_Signal_Proj.uvprojx @@ -0,0 +1,515 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + FreeRTOS_Signal_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\FreeRTOS_Signal_Proj.bin .\Objects\FreeRTOS_Signal_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + middlewares\Third_Party\FreeRTOS\Source + + + list.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + + + queue.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + + + tasks.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + + + timers.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + + + cmsis_os.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + + + port.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + + + heap_4.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/inc/FreeRTOSConfig.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..0065642 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/inc/FreeRTOSConfig.h @@ -0,0 +1,170 @@ +/* + FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + extern uint32_t SystemCoreClock; +#endif + + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 8 ) +#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 5 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +#define configENABLE_BACKWARD_COMPATIBILITY 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY ( 2 ) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_eTaskGetState 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 2 /* 3 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/inc/main.h new file mode 100644 index 0000000..97ad9e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/inc/main.h @@ -0,0 +1,109 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#define TICK_INT_PRIORITY (((uint32_t)1U<<__NVIC_PRIO_BITS) - 1U) + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +typedef enum +{ + LED1 = 0, + LED2 = 1 +} Led_TypeDef; + +static void LED_Thread1(void const *argument); +static void LED_Thread2(void const *argument); +static void Signal_Gen_Thread(void const *argument); + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/readme.txt new file mode 100644 index 0000000..3c3e661 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + + This example mainly demonstrates the creation and use of FreeRTOS binary semaphores + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + + usage method: + 1. Burn to development board after compilation + 2. Check LED blinking + +4. Precautions \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/src/main.c new file mode 100644 index 0000000..6f04bd1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/src/main.c @@ -0,0 +1,271 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "cmsis_os.h" + +/** + * FreeRTOS Signal + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define BIT_0 ( 1 << 0 ) +#define BIT_1 ( 1 << 1 ) +#define BIT_2 ( 1 << 2 ) +#define SYSTICK_1MS ((uint32_t)1000) +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint32_t Tick_num = 0; +osThreadId LED1_ThreadId, LED2_ThreadId; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program. + */ +int main(void) +{ + /*Configure the SysTick IRQ priority */ + N32_NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY, 0); + /* Get SystemCoreClock */ + SystemCoreClockUpdate(); + + /* Config 1s SysTick 1ms */ + SysTick_Config(SystemCoreClock/SYSTICK_1MS); + + /* Initialize Led1~Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Turn on Led1~Led2*/ + LedOn(LED1_PORT, LED1_PIN); + LedOn(LED2_PORT, LED2_PIN); + + /* Thread 1 definition */ + osThreadDef(LED1, LED_Thread1, osPriorityNormal, 0, configMINIMAL_STACK_SIZE); + + /* Thread 2 definition */ + osThreadDef(LED2, LED_Thread2, osPriorityNormal, 0, configMINIMAL_STACK_SIZE); + + /* Thread 3 definition */ + osThreadDef(SIGNAL_GEN, Signal_Gen_Thread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE); + + /* Start thread 1 */ + LED1_ThreadId = osThreadCreate(osThread(LED1), NULL); + + /* Start thread 2 */ + LED2_ThreadId = osThreadCreate(osThread(LED2), NULL); + + /* Start thread 3 */ + osThreadCreate(osThread(SIGNAL_GEN), NULL); + /* Start scheduler */ + osKernelStart(); + + /* We should never get here as control is now taken by the scheduler */ + for(;;); +} + +/** + * @brief Thread (LED_Thread1) used to toggle a LED when getting the appropriate signal. + * @param Thread not used + * @retval None + */ +static void LED_Thread1(void const *argument) +{ + (void) argument; + osEvent event; + + for(;;) + { + event = osSignalWait( BIT_0, osWaitForever); + if(event.value.signals == BIT_0) + { + LedBlink(LED1_PORT,LED1_PIN); + } + } +} + +/** + * @brief Thread (LED_Thread2) used to toggle a LED when getting the appropriate signal. + * @param argument not used + * @retval None + */ +static void LED_Thread2(void const *argument) +{ + (void) argument; + osEvent event; + + for(;;) + { + event = osSignalWait( BIT_1 | BIT_2, osWaitForever); + if(event.value.signals == (BIT_1 | BIT_2)) + { + LedBlink(LED2_PORT,LED2_PIN); + } + } +} + +/** + * @brief Signal generator thread + * @param Thread not used + * @retval None + */ +static void Signal_Gen_Thread(void const *argument) +{ + (void) argument; + + for(;;) + { + osSignalSet( LED1_ThreadId, BIT_0 ); + osDelay(500); + osSignalSet( LED2_ThreadId, BIT_1 | BIT_2 ); + osDelay(500); + } +} + +/** + * @brief Sets the priority of an interrupt. + * @param IRQn External interrupt number . + * This parameter can be an enumerator of IRQn_Type enumeration + * @param PreemptPriority The pre-emption priority for the IRQn channel. + * This parameter can be a value between 0 and 3. + * A lower priority value indicates a higher priority + * @param SubPriority the subpriority level for the IRQ channel. + * this parameter is a dummy value and it is ignored, because + * no subpriority supported in Cortex M0 based products. + * @retval None + */ +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) +{ + /* Check the parameters */ + assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)); + NVIC_SetPriority(IRQn,PreemptPriority); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/src/n32wb03x_it.c new file mode 100644 index 0000000..9a7f49a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Signal/src/n32wb03x_it.c @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "cmsis_os.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +extern uint32_t Tick_num; + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + Tick_num++; + osSystickHandler(); +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/MDK-ARM/FreeRTOS_SignalFromISR_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/MDK-ARM/FreeRTOS_SignalFromISR_Proj.uvoptx new file mode 100644 index 0000000..0bdce8c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/MDK-ARM/FreeRTOS_SignalFromISR_Proj.uvoptx @@ -0,0 +1,439 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + list.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + queue.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + tasks.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + timers.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + cmsis_os.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + 0 + 0 + 0 + 0 + + 6 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + port.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + 0 + 0 + 0 + 0 + + 7 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + heap_4.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 9 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/MDK-ARM/FreeRTOS_SignalFromISR_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/MDK-ARM/FreeRTOS_SignalFromISR_Proj.uvprojx new file mode 100644 index 0000000..d6cd0aa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/MDK-ARM/FreeRTOS_SignalFromISR_Proj.uvprojx @@ -0,0 +1,515 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + FreeRTOS_SignalFromISR_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\FreeRTOS_SignalFromISR_Proj.bin .\Objects\FreeRTOS_SignalFromISR_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + middlewares\Third_Party\FreeRTOS\Source + + + list.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + + + queue.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + + + tasks.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + + + timers.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + + + cmsis_os.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + + + port.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + + + heap_4.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/inc/FreeRTOSConfig.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..d832c0c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/inc/FreeRTOSConfig.h @@ -0,0 +1,170 @@ +/* + FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + extern uint32_t SystemCoreClock; +#endif + + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 8 ) +#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 3 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +#define configENABLE_BACKWARD_COMPATIBILITY 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY ( 2 ) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_eTaskGetState 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 2 /* 3 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/inc/main.h new file mode 100644 index 0000000..e81ce1a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/inc/main.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#define TICK_INT_PRIORITY (((uint32_t)1U<<__NVIC_PRIO_BITS) - 1U) + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +static void LED1_Thread(void const *argument); +void Toggle_Led(void); + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t Priority); + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/readme.txt new file mode 100644 index 0000000..31c6f1e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + + This example mainly demonstrates the creation and use of FreeRTOS binary semaphores (processing calls in interrupt service functions) + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + + usage method: + 1. Burn to development board after compilation + 2. Check LED blinking + +4. Precautions \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/src/main.c new file mode 100644 index 0000000..36f7978 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/src/main.c @@ -0,0 +1,239 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "cmsis_os.h" + +/** + * FreeRTOS SignalFromISR + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define BIT_0 ( 1 << 0 ) +#define BIT_1 ( 1 << 1 ) +#define BIT_2 ( 1 << 2 ) +#define SYSTICK_1MS ((uint32_t)1000) +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint32_t Tick_num = 0; +osThreadId LED1_ThreadId; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program. + */ +int main(void) +{ + /*Configure the SysTick IRQ priority */ + N32_NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY); + /* Get SystemCoreClock */ + SystemCoreClockUpdate(); + + /* Config 1s SysTick 1ms */ + SysTick_Config(SystemCoreClock/SYSTICK_1MS); + + /* Initialize Led1~Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Turn on Led1~Led2*/ + LedOn(LED1_PORT, LED1_PIN); + LedOn(LED2_PORT, LED2_PIN); + + /* Thread 1 definition */ + osThreadDef(LED1, LED1_Thread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE); + + /* Start thread 1 */ + LED1_ThreadId = osThreadCreate(osThread(LED1), NULL); + + /* Start scheduler */ + osKernelStart(); + + /* We should never get here as control is now taken by the scheduler */ + for(;;); +} + +/** + * @brief Toggle LED1 thread. + * @param Thread not used + * @retval None + */ +static void LED1_Thread(void const *argument) +{ + (void) argument; + osEvent event; + + for(;;) + { + event = osSignalWait( BIT_1 | BIT_2, osWaitForever); + if(event.value.signals == (BIT_1 | BIT_2)) + { + LedBlink(LED1_PORT,LED1_PIN); + } + } +} + +/** + * @brief Toggles LED to show user input state. + * @param None + * @retval None + */ +void Toggle_Led(void) +{ + static uint32_t ticks = 0; + if(ticks == 400) + { + osSignalSet( LED1_ThreadId, BIT_1); + } + else if(ticks == 1000) + { + osSignalSet( LED1_ThreadId, BIT_1 | BIT_2 ); + ticks = 0; + } + ticks++; +} + +/** + * @brief Sets the priority of an interrupt. + * @param IRQn External interrupt number . + * This parameter can be an enumerator of IRQn_Type enumeration + * @param Priority The priority for the IRQn channel. + * This parameter can be a value between 0 and 3. + * A lower priority value indicates a higher priority + * @retval None + */ +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t Priority) +{ + /* Check the parameters */ + assert_param(IS_NVIC_PRIORITY(Priority)); + NVIC_SetPriority(IRQn,Priority); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/src/n32wb03x_it.c new file mode 100644 index 0000000..c344996 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_SignalFromISR/src/n32wb03x_it.c @@ -0,0 +1,116 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "cmsis_os.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +extern uint32_t Tick_num; + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + Tick_num++; + osSystickHandler(); + Toggle_Led(); +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/MDK-ARM/FreeRTOS_ThreadCreation_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/MDK-ARM/FreeRTOS_ThreadCreation_Proj.uvoptx new file mode 100644 index 0000000..0bdce8c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/MDK-ARM/FreeRTOS_ThreadCreation_Proj.uvoptx @@ -0,0 +1,439 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + list.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + queue.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + tasks.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + timers.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + cmsis_os.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + 0 + 0 + 0 + 0 + + 6 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + port.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + 0 + 0 + 0 + 0 + + 7 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + heap_4.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 9 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/MDK-ARM/FreeRTOS_ThreadCreation_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/MDK-ARM/FreeRTOS_ThreadCreation_Proj.uvprojx new file mode 100644 index 0000000..4b180d0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/MDK-ARM/FreeRTOS_ThreadCreation_Proj.uvprojx @@ -0,0 +1,515 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + FreeRTOS_ThreadCreation_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\FreeRTOS_ThreadCreation_Proj.bin .\Objects\FreeRTOS_ThreadCreation_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + middlewares\Third_Party\FreeRTOS\Source + + + list.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + + + queue.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + + + tasks.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + + + timers.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + + + cmsis_os.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + + + port.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + + + heap_4.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/inc/FreeRTOSConfig.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..7799df9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/inc/FreeRTOSConfig.h @@ -0,0 +1,169 @@ +/* + FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + extern uint32_t SystemCoreClock; +#endif + + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 7 ) +#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 2 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Software timer definitions. */ +#define configUSE_TIMERS 0 +#define configTIMER_TASK_PRIORITY ( 2 ) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xQueueGetMutexHolder 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_eTaskGetState 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 2 /* 3 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 3 + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 3 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/inc/main.h new file mode 100644 index 0000000..5b16c40 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/inc/main.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#define TICK_INT_PRIORITY (((uint32_t)1U<<__NVIC_PRIO_BITS) - 1U) + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +static void LED_Thread1(void const *argument); +static void LED_Thread2(void const *argument); + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/inc/n32wb03x_it.h new file mode 100644 index 0000000..3bdfeb9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/inc/n32wb03x_it.h @@ -0,0 +1,84 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/readme.txt new file mode 100644 index 0000000..e61d448 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/readme.txt @@ -0,0 +1,27 @@ +1�功能说明 + + 该例程主�演示FreeRTOS任务的创建与使用 + +1. Function description + + This example mainly demonstrates the creation and use of FreeRTOS tasks + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + + usage method: + 1. Burn to development board after compilation + 2. Check LED blinking + +4. Precautions \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/src/main.c new file mode 100644 index 0000000..ff0474e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/src/main.c @@ -0,0 +1,281 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "cmsis_os.h" + +/** + * FreeRTOS ThreadCreation + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define SYSTICK_1MS ((uint32_t)1000) +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint32_t Tick_num = 0; +osThreadId LEDThread1Handle, LEDThread2Handle; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program. + */ +int main(void) +{ + /*Configure the SysTick IRQ priority */ + N32_NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY, 0); + /* Get SystemCoreClock */ + SystemCoreClockUpdate(); + + /* Config 1s SysTick 1ms */ + SysTick_Config(SystemCoreClock/SYSTICK_1MS); + + /* Initialize Led1~Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Turn off Led1~Led2*/ + LedOff(LED1_PORT, LED1_PIN); + LedOff(LED2_PORT, LED2_PIN); + + /* Thread 1 definition */ + osThreadDef(LED1, LED_Thread1, osPriorityNormal, 0, configMINIMAL_STACK_SIZE); + + /* Thread 2 definition */ + osThreadDef(LED2, LED_Thread2, osPriorityNormal, 0, configMINIMAL_STACK_SIZE); + + /* Start thread 1 */ + LEDThread1Handle = osThreadCreate(osThread(LED1), NULL); + + /* Start thread 2 */ + LEDThread2Handle = osThreadCreate(osThread(LED2), NULL); + + /* Start scheduler */ + osKernelStart(); + + /* We should never get here as control is now taken by the scheduler */ + for(;;); +} + +/** + * @brief Toggle LED1 thread + * @param thread not used + * @retval None + */ +static void LED_Thread1(void const *argument) +{ + uint32_t count = 0; + (void) argument; + + for (;;) + { + count = osKernelSysTick() + 5000; + + /* Toggle LED1 every 200 ms for 5 s */ + while (count >= osKernelSysTick()) + { + LedBlink(LED1_PORT,LED1_PIN); + + osDelay(200); + } + + /* Turn off LED2 */ + LedOff(LED1_PORT,LED1_PIN); + + /* Suspend Thread 1 */ + osThreadSuspend(NULL); + + count = osKernelSysTick() + 5000; + + /* Toggle LED1 every 400 ms for 5 s */ + while (count >= osKernelSysTick()) + { + LedBlink(LED1_PORT,LED1_PIN); + + osDelay(400); + } + + /* Resume Thread 2*/ + osThreadResume(LEDThread2Handle); + } +} + +/** + * @brief Toggle LED2 thread + * @param argument not used + * @retval None + */ +static void LED_Thread2(void const *argument) +{ + uint32_t count; + (void) argument; + + for (;;) + { + count = osKernelSysTick() + 10000; + + /* Toggle LED2 every 500 ms for 10 s */ + while (count >= osKernelSysTick()) + { + LedBlink(LED2_PORT,LED2_PIN); + + osDelay(500); + } + + /* Turn off LED2 */ + LedOff(LED2_PORT,LED2_PIN); + + /* Resume Thread 1 */ + osThreadResume(LEDThread1Handle); + + /* Suspend Thread 2 */ + osThreadSuspend(NULL); + } +} + +/** + * @brief Sets the priority of an interrupt. + * @param IRQn External interrupt number . + * This parameter can be an enumerator of IRQn_Type enumeration + * @param PreemptPriority The pre-emption priority for the IRQn channel. + * This parameter can be a value between 0 and 3. + * A lower priority value indicates a higher priority + * @param SubPriority the subpriority level for the IRQ channel. + * this parameter is a dummy value and it is ignored, because + * no subpriority supported in Cortex M0 based products. + * @retval None + */ +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) +{ + /* Check the parameters */ + assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)); + NVIC_SetPriority(IRQn,PreemptPriority); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/src/n32wb03x_it.c new file mode 100644 index 0000000..9a7f49a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_ThreadCreation/src/n32wb03x_it.c @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "cmsis_os.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +extern uint32_t Tick_num; + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + Tick_num++; + osSystickHandler(); +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/MDK-ARM/FreeRTOS_Timers_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/MDK-ARM/FreeRTOS_Timers_Proj.uvoptx new file mode 100644 index 0000000..0bdce8c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/MDK-ARM/FreeRTOS_Timers_Proj.uvoptx @@ -0,0 +1,439 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + list.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + queue.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + tasks.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + timers.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + cmsis_os.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + 0 + 0 + 0 + 0 + + 6 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + port.c + 0 + 0 + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + 0 + 0 + 0 + 0 + + 7 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + heap_4.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 9 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/MDK-ARM/FreeRTOS_Timers_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/MDK-ARM/FreeRTOS_Timers_Proj.uvprojx new file mode 100644 index 0000000..e512d1a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/MDK-ARM/FreeRTOS_Timers_Proj.uvprojx @@ -0,0 +1,515 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + FreeRTOS_Timers_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\FreeRTOS_Timers_Proj.bin .\Objects\FreeRTOS_Timers_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + middlewares\Third_Party\FreeRTOS\Source + + + list.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\list.c + + + queue.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\queue.c + + + tasks.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\tasks.c + + + timers.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\timers.c + + + + + middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS + + + cmsis_os.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS\cmsis_os.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0 + + + port.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM0\port.c + + + + + middlewares\Third_Party\FreeRTOS\Source\portable\MemMang + + + heap_4.c + 1 + ..\..\..\..\..\..\middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/inc/FreeRTOSConfig.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..f5e5282 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/inc/FreeRTOSConfig.h @@ -0,0 +1,169 @@ +/* + FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) + #include + extern uint32_t SystemCoreClock; +#endif + + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 7 ) +#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 3 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY ( 2 ) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xQueueGetMutexHolder 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_eTaskGetState 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 2 /* 3 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 3 + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 3 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/inc/main.h new file mode 100644 index 0000000..6e51265 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/inc/main.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#define TICK_INT_PRIORITY (((uint32_t)1U<<__NVIC_PRIO_BITS) - 1U) + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +static void osTimerCallback(void const *argument); +static void ToggleLEDsThread(void const *argument); + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/inc/n32wb03x_it.h new file mode 100644 index 0000000..3bdfeb9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/inc/n32wb03x_it.h @@ -0,0 +1,84 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/readme.txt new file mode 100644 index 0000000..afbc294 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + + This example mainly demonstrates the creation and use of FreeRTOS timers + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + + usage method: + 1. Burn to development board after compilation + 2. Check LED blinking + +4. Precautions \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/src/main.c new file mode 100644 index 0000000..ad4a2e8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/src/main.c @@ -0,0 +1,233 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "cmsis_os.h" + +/** + * FreeRTOS Timers + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define SYSTICK_1MS ((uint32_t)1000) +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint32_t Tick_num = 0; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program. + */ +int main(void) +{ + /*Configure the SysTick IRQ priority */ + N32_NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY, 0); + /* Get SystemCoreClock */ + SystemCoreClockUpdate(); + + /* Config 1s SysTick 1ms */ + SysTick_Config(SystemCoreClock/SYSTICK_1MS); + + /* Initialize Led1~Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Turn on Led1~Led2*/ + LedOn(LED1_PORT, LED1_PIN); + LedOn(LED2_PORT, LED2_PIN); + + /* Create Timer */ + osTimerDef(LEDTimer, osTimerCallback); + osTimerId osTimer = osTimerCreate(osTimer(LEDTimer), osTimerPeriodic, NULL); + /* Start Timer */ + osTimerStart(osTimer, 200); + + /* Create LED Thread */ + osThreadDef(LEDThread, ToggleLEDsThread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE); + osThreadCreate(osThread(LEDThread), NULL); + + /* Start scheduler */ + osKernelStart(); + + /* We should never get here as control is now taken by the scheduler */ + for(;;); +} + +/** + * @brief Timer Callback that toggle LED1 + * @param argument not used + * @retval None + */ +static void osTimerCallback(void const *argument) +{ + (void) argument; + + /* Toggle LED1*/ + LedBlink(LED1_PORT,LED1_PIN); +} + +/** + * @brief Toggle LED2 thread + * @param argument not used + * @retval None + */ +static void ToggleLEDsThread(void const *argument) +{ + (void) argument; + + for (;;) + { + /* Toggle LED2 each 400ms */ + LedBlink(LED2_PORT,LED2_PIN); + + osDelay(400); + } +} + +/** + * @brief Sets the priority of an interrupt. + * @param IRQn External interrupt number . + * This parameter can be an enumerator of IRQn_Type enumeration + * @param PreemptPriority The pre-emption priority for the IRQn channel. + * This parameter can be a value between 0 and 3. + * A lower priority value indicates a higher priority + * @param SubPriority the subpriority level for the IRQ channel. + * this parameter is a dummy value and it is ignored, because + * no subpriority supported in Cortex M0 based products. + * @retval None + */ +void N32_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) +{ + /* Check the parameters */ + assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)); + NVIC_SetPriority(IRQn,PreemptPriority); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/src/n32wb03x_it.c new file mode 100644 index 0000000..e993c1d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/FreeRTOS/FreeRTOS_Timers/src/n32wb03x_it.c @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "main.h" +#include "cmsis_os.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +extern uint32_t Tick_num; + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + Tick_num++; + osSystickHandler(); +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM/peripheral_alone.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM/peripheral_alone.uvoptx new file mode 100644 index 0000000..819d5a0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM/peripheral_alone.uvoptx @@ -0,0 +1,469 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 1 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 1 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rtc.c + n32wb03x_rtc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\app_rtc.c + app_rtc.c + 0 + 0 + + + 4 + 17 + 1 + 0 + 0 + 0 + ..\src\app_tim.c + app_tim.c + 0 + 0 + + + 4 + 18 + 1 + 0 + 0 + 0 + ..\src\app_adc.c + app_adc.c + 0 + 0 + + + 4 + 19 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + 4 + 20 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 21 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM/peripheral_alone.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM/peripheral_alone.uvprojx new file mode 100644 index 0000000..445b4e9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM/peripheral_alone.uvprojx @@ -0,0 +1,522 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.4.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + peripheral_alone + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\peripheral_alone.bin .\Objects\peripheral_alone.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, TEST_200MS_WAKEUPx + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + n32wb03x_rtc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rtc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + app_rtc.c + 1 + ..\src\app_rtc.c + + + app_tim.c + 1 + ..\src\app_tim.c + + + app_adc.c + 1 + ..\src\app_adc.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/peripheral_alone_run_from_RAM.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/peripheral_alone_run_from_RAM.uvoptx new file mode 100644 index 0000000..4b09dea --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/peripheral_alone_run_from_RAM.uvoptx @@ -0,0 +1,494 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + .\startup.ini + BIN\CMSIS_AGDI.dll + + + + 0 + UL2CM3 + -UV0498UAE -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO8 -FD20000000 -FC4000 -FN1 -FF0N32WB03X -FS01000000 -FL080000 + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO8 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + ARMRTXEVENTFLAGS + -L70 -Z18 -C0 -M0 -T1 + + + 0 + DLGTARM + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0) + + + 0 + ARMDBGFLAGS + + + + 0 + DLGUARM + + + + + + + 0 + 1 + TIM1 + + + + 0 + + + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rtc.c + n32wb03x_rtc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\app_rtc.c + app_rtc.c + 0 + 0 + + + 4 + 17 + 1 + 0 + 0 + 0 + ..\src\app_tim.c + app_tim.c + 0 + 0 + + + 4 + 18 + 1 + 0 + 0 + 0 + ..\src\app_adc.c + app_adc.c + 0 + 0 + + + 4 + 19 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + 4 + 20 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 21 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/peripheral_alone_run_from_RAM.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/peripheral_alone_run_from_RAM.uvprojx new file mode 100644 index 0000000..a66f6f8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/peripheral_alone_run_from_RAM.uvprojx @@ -0,0 +1,520 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Demo + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Demo.bin .\Objects\Demo.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x2000000 + 0x8000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20008000 + 0x4000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_HSI_64Mx, TEST_200MS_WAKEUPx,RUN_FROM_RAM + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + .\run_from_RAM.sct + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + n32wb03x_rtc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rtc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + app_rtc.c + 1 + ..\src\app_rtc.c + + + app_tim.c + 1 + ..\src\app_tim.c + + + app_adc.c + 1 + ..\src\app_adc.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/run_from_RAM.sct b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/run_from_RAM.sct new file mode 100644 index 0000000..965105b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/run_from_RAM.sct @@ -0,0 +1,37 @@ +; ************************************************************* +; *** Scatter-Loading Description File generated by uVision *** +; ************************************************************* + +;R_ROM1 0x01000000 0x40000 +;{ + ;ER_ROM1 0x01000000 0x40000 + ;{ + ;*.o (RESET, +First) + ;*(InRoot$$Sections) + ;* (+RO) + ;} + + ;ARM_LIB_STACK 0x20009000 EMPTY -0x1000 + ;{ + + ;} + + ;RW_RAM 0x20009000 0x3000 ;6K RW ZI + ;{ + ;*(ram_code) + ;* (+RW +ZI) + + ;} + +;} + +LR_IROM1 0x20000000 0x00008000 { ; load region size_region + ER_IROM1 0x20000000 0x00008000 { ; load address = execution address + *.o (RESET, +First) + *(InRoot$$Sections) + .ANY (+RO) + } + RW_IRAM1 0x20008000 0x00004000 { ; RW data + .ANY (+RW +ZI) + } +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/startup.ini b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/startup.ini new file mode 100644 index 0000000..766276d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/MDK-ARM_run_from_RAM/startup.ini @@ -0,0 +1,14 @@ +FUNC void Setup(void){ + SP = _RDWORD(0x20000000); + PC = _RDWORD(0x20000004); + _WDWORD(0xE000ED08,0x20000000); +} +Setup(); + +//FUNC void Setup(void){ +// SP = _RDWORD(0x20008000); +// PC = _RDWORD(0x20008004); +// _WDWORD(0xE000ED08,0x20008000); +//} + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_adc.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_adc.h new file mode 100644 index 0000000..558c127 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_adc.h @@ -0,0 +1,83 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + +/** + * @file app_adc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_ADC_H__ +#define __APP_ADC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void ADC_Configuration(void); +uint16_t ADC_GetDataBlocking(uint32_t ADC_Channel); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_ADC_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_gpio.h new file mode 100644 index 0000000..6e71306 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_gpio.h @@ -0,0 +1,84 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void KeyInputExtiInit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_rtc.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_rtc.h new file mode 100644 index 0000000..69a0100 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_rtc.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rtc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_RTC_H__ +#define __APP_RTC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +void RTC_Configuration(void); + +void RTC_TimeShow(void); +void RTC_DateShow(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_RTC_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_tim.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_tim.h new file mode 100644 index 0000000..6f3f892 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_tim.h @@ -0,0 +1,83 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_tim.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_TIM_H__ +#define __APP_TIM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void TIM1_PWM_Configuration(void); +void TIM3_PWM_Configuration(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_TIM_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_usart.h new file mode 100644 index 0000000..dd63a23 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/app_usart.h @@ -0,0 +1,83 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" +void USART_Deinitializes(void); +void USART_Configuration(void); +void USART_EchoTask(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/main.h new file mode 100644 index 0000000..fde9782 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/main.h @@ -0,0 +1,154 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include "n32wb03x.h" + + + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; +#define GLOBAL_INT_DISABLE() \ +uint32_t ui32IntStatus = 0; \ +do{ \ + ui32IntStatus = __get_PRIMASK(); \ + __set_PRIMASK(1); \ +}while(0) + +#define GLOBAL_INT_RESTORE() \ +do{ \ + __set_PRIMASK(ui32IntStatus); \ +}while(0) + +#define _USART1_COM_ //don't use it with ADC test at the same time, PB7 as ADC CH4. +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk +#endif + + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +#define KEY1_INPUT_PORT GPIOB +#define KEY1_INPUT_PIN GPIO_PIN_1 +#define KEY1_INPUT_EXTI_LINE EXTI_LINE1 +#define KEY1_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY1_INPUT_PIN_SOURCE GPIO_PIN_SOURCE1 +#define KEY1_INPUT_IRQn EXTI0_1_IRQn + +#define KEY2_INPUT_PORT GPIOB +#define KEY2_INPUT_PIN GPIO_PIN_2 +#define KEY2_INPUT_EXTI_LINE EXTI_LINE2 +#define KEY2_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY2_INPUT_PIN_SOURCE GPIO_PIN_SOURCE2 +#define KEY2_INPUT_IRQn EXTI2_3_IRQn + + + +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +uint16_t ADC_GetData_blocking(uint32_t ADC_Channel); +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/readme.txt new file mode 100644 index 0000000..f6b556d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/readme.txt @@ -0,0 +1,46 @@ +1. Function description + 1. LED1 and LED2 light up upon startup + 2. Short press K1 to enter the sleep mode, long press K1 to enter the sleep mode and + RTC wake-up function, and short press K1 to wake up the sleep + 3. Short press K2 to read the value of ADC CH1 (PB10) and output it to the serial port + 4. Timer TIM3 CH1 (PB4) CH2 (PB5) PWM with the same output frequency and different duty cycle + 5. The serial port runs the loopback application with 115200 8n1 parameters, and the input + string of less than 256 bytes will return to the output immediately + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + PB4 selects CH1 output of TIM3 + PB5 selects CH2 output of TIM3 + PB6 selects TX as USART + PB7 selects RX as USART + PB10 is selected as CH1 of ADC + Select LED1 for PB0 + Select LED2 for PA6 + Select K1 for PB1 + Select K2 for PB2 + 3. The frequency of TIM3 is 40KHz, the duty cycle of CH1 is 75%, and the duty cycle of CH2 is 50% + 4. Serial port uses USART1, the baud rate is 115200, 8bit data bit, no check bit, 1bit stop bit, no flow control. + 5. ADC CH1 can measure from 0.15 to 0.95V + + usage method: + 1. Burn to development board after compilation + 2. Observe the waveform of PB4 and PB5 with an oscilloscope or logic analyzer + 3. Connect the serial port tool to USART1 + 4. After the program runs, LED1 and LED2 on the board light up + 6. Send any string (less than 256 bytes) to the serial port to receive and return the same string + 6. Short press K1 to go to sleep, and press K1 or K2 to wake up + 7. Long press K1 to enter sleep, and start the wake-up function of RTC. After 10 seconds, MCU will wake up. + 8. Short press K2 to flip LED1, read the ADC value, and convert it to voltage (mA). + +4. Precautions + 1. If there is no HSE crystal on the board, please define macro NO on the option C/C++page_ HSE_ ON_ BOORD: Enable direct + writing of HSI to trim values. The default value is 0x4F. + If the frequency is wrong, you can fine-tune it by yourself. Later, you will write the correct trim value to + flash in production, and users only need to read and write the register. + 2. Program cannot be burned during MCU sleep. Please reset and burn. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_adc.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_adc.c new file mode 100644 index 0000000..4e2f67a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_adc.c @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + +/** + * @file app_adc.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_adc.h" +#include "main.h" +#include + + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + + + +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_ADC(void) +{ + /* Enable peripheral clocks */ + /* Enable GPIOB clocks */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + /* Enable ADC clocks */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC, ENABLE); + RCC_Enable_ADC_CLK_SRC_AUDIOPLL(ENABLE); + + RCC_ConfigAdcClk(RCC_ADCCLK_SRC_AUDIOPLL); + +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_ADC(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure PB.10 (ADC Channel1) as analog input --------*/ + GPIO_InitStructure.Pin = GPIO_PIN_10; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +/** + * @brief Configures the ADC and Read CH1 CH2. + */ +void ADC_Configuration(void) +{ + RCC_Configuration_ADC(); + GPIO_Configuration_ADC(); + + /* Select the ADC channel */ + ADC_ConfigChannel(ADC, ADC_CTRL_CH_1); + + ADC_EnableBypassFilter(ADC, ENABLE); + + +} + +/** + * @brief Configures and read the selected ADC channel + * @param ADC_Channel the ADC channel to read. + * This parameter can be any combination of the following values: + * @arg ADC_CTRL_CH_0 ADC Channel0 selected (PGA PB11/PB13) + * @arg ADC_CTRL_CH_1 ADC Channel1 selected (PB10) + * @arg ADC_CTRL_CH_2 ADC Channel2 selected (PB9) + * @arg ADC_CTRL_CH_3 ADC Channel3 selected (PB8) + * @arg ADC_CTRL_CH_4 ADC Channel4 selected (PB7) + * @arg ADC_CTRL_CH_5 ADC Channel5 selected (PB6) + * @arg ADC_CTRL_CH_6 ADC Channel6 selected (external voltage) + * @arg ADC_CTRL_CH_7 ADC Channel7 selected (temperature) + */ +uint16_t ADC_GetDataBlocking(uint32_t ADC_Channel) +{ + uint16_t dat; + uint32_t timer = 0; + + /* Select the ADC channel */ + ADC_ConfigChannel(ADC, ADC_Channel); + /* Enable ADC */ + ADC_Enable(ADC, ENABLE); + + while(ADC_GetFlagStatus(ADC,ADC_FLAG_DONE)== RESET) + { + if(++timer > 0xfffff) + return 0xffff; + } + ADC_ClearFlag(ADC,ADC_FLAG_DONE); + dat=ADC_GetDat(ADC); + return dat; +} + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_gpio.c new file mode 100644 index 0000000..e3ba5fa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_gpio.c @@ -0,0 +1,206 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" +#include "main.h" +#include + + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + + + +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @brief Configures key port. + */ +void KeyInputExtiInit(void) +{ + GPIO_InitType GPIO_InitStructure; + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + + /*Configure the GPIO pin as input floating */ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = KEY1_INPUT_PIN; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(KEY1_INPUT_PORT, &GPIO_InitStructure); + + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + + /*Configure the GPIO pin as input floating*/ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = KEY2_INPUT_PIN; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(KEY2_INPUT_PORT, &GPIO_InitStructure); + + /*Configure key EXTI Line to key input Pin*/ + GPIO_ConfigEXTILine(KEY1_INPUT_PORT_SOURCE, KEY1_INPUT_PIN_SOURCE); + GPIO_ConfigEXTILine(KEY2_INPUT_PORT_SOURCE, KEY2_INPUT_PIN_SOURCE); + + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY1_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY1_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY2_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY2_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 2; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_rtc.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_rtc.c new file mode 100644 index 0000000..e60f7b8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_rtc.c @@ -0,0 +1,423 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rtc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_rtc.h" +#include "main.h" +#include + + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +#define RCT_LOG_ENABLE +#ifdef RCT_LOG_ENABLE +#define log_info printf +#else +#define log_info(str, ...) +#endif +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +RTC_DateType RTC_DateStructure; +RTC_DateType RTC_DateDefault; +RTC_TimeType RTC_TimeStructure; +RTC_TimeType RTC_TimeDefault; +RTC_InitType RTC_InitStructure; +RTC_AlarmType RTC_AlarmStructure; +uint32_t SynchPrediv, AsynchPrediv; + +/* Private function prototypes -----------------------------------------------*/ +void RTC_CLKSourceConfig(uint8_t ClkSrc); +ErrorStatus RTC_TimeRegulate(void); +ErrorStatus RTC_DateRegulate(void); +void RTC_DateAndTimeDefaultVale(void); +static void RTC_PrescalerConfig(void); +void EXTI9_RTCWKUP_Configuration(FunctionalState Cmd); +void WakeUpClockSelect(uint8_t WKUPClkSrcSel); + + + + +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief app rtc init + */ +void RTC_Configuration(void) +{ + if((RTC->INITSTS&RTC_INITSTS_INITSF) == 0) + { + /* RTC date time alarm default value*/ + RTC_DateAndTimeDefaultVale(); + + /* RTC clock source select 1:LSE 2:LSI*/ + RTC_CLKSourceConfig(2); + RTC_PrescalerConfig(); + + /* Adjust time by values entered by the user on the hyperterminal */ + RTC_DateRegulate(); + RTC_TimeRegulate(); + } + else + { + /* Enable the RTC Clock */ + RCC_EnableRtcClk(ENABLE); + RTC_WaitForSynchro(); + RTC_TimeShow(); + } + + + #ifdef TEST_200MS_WAKEUP + /* wake up clock select */ + WakeUpClockSelect(1); + /* wake up timer value */ + RTC_SetWakeUpCounter( 1000 );//400->200ms ,1000->500ms + #else + + /* wake up clock select */ + WakeUpClockSelect(5); + /* wake up timer value */ + RTC_SetWakeUpCounter(10); + #endif + + EXTI9_RTCWKUP_Configuration(ENABLE); + /* Enable the RTC Wakeup Interrupt */ + RTC_ConfigInt(RTC_INT_WUT, ENABLE); + + + +} + + +/** + * @brief Wake up clock config. + */ +void WakeUpClockSelect(uint8_t WKUPClkSrcSel) +{ + /* Configure the RTC WakeUp Clock source: CK_SPRE (1Hz) */ + if (WKUPClkSrcSel == 0x01) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_RTCCLK_DIV16); + else if (WKUPClkSrcSel == 0x02) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_RTCCLK_DIV8); + else if (WKUPClkSrcSel == 0x03) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_RTCCLK_DIV4); + else if (WKUPClkSrcSel == 0x04) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_RTCCLK_DIV2); + else if (WKUPClkSrcSel == 0x05) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_CK_SPRE_16BITS); + else if (WKUPClkSrcSel == 0x06) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_CK_SPRE_17BITS); +} +/** + * @brief Config RTC wake up Interrupt. + */ +void EXTI9_RTCWKUP_Configuration(FunctionalState Cmd) +{ + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + EXTI_ClrITPendBit(EXTI_LINE9); + EXTI_InitStructure.EXTI_Line = EXTI_LINE9; +#ifdef __TEST_SEVONPEND_WFE_NVIC_DIS__ + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event; +#else + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; +#endif + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /* Enable the RTC WakeUp Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = Cmd; + NVIC_Init(&NVIC_InitStructure); +} + + + +/** + * @brief Display the current Date on the Hyperterminal. + */ +void RTC_DateShow(void) +{ + /* Get the current Date */ + RTC_GetDate(RTC_FORMAT_BIN, &RTC_DateStructure); + log_info("The current date (WeekDay-Date-Month-Year) is : %0.2d-%0.2d-%0.2d-%0.2d\r\n", + RTC_DateStructure.WeekDay, + RTC_DateStructure.Date, + RTC_DateStructure.Month, + RTC_DateStructure.Year); +} + +/** + * @brief Display the current time on the Hyperterminal. + */ +void RTC_TimeShow(void) +{ + /* Get the current Time and Date */ + RTC_GetTime(RTC_FORMAT_BIN, &RTC_TimeStructure); + log_info("The current time (Hour-Minute-Second) is : %0.2d:%0.2d:%0.2d \r\n", + RTC_TimeStructure.Hours, + RTC_TimeStructure.Minutes, + RTC_TimeStructure.Seconds); + /* Unfreeze the RTC DAT Register */ + (void)RTC->DATE; +} +/** + * @brief RTC initalize default value. + */ +void RTC_DateAndTimeDefaultVale(void) +{ // Date + RTC_DateDefault.WeekDay = 3; + RTC_DateDefault.Date = 20; + RTC_DateDefault.Month = 11; + RTC_DateDefault.Year = 19; + // Time + RTC_TimeDefault.H12 = RTC_AM_H12; + RTC_TimeDefault.Hours = 4; + RTC_TimeDefault.Minutes = 5; + RTC_TimeDefault.Seconds = 1; +} +/** + * @brief RTC date regulate with the default value. + */ +ErrorStatus RTC_DateRegulate(void) +{ + uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF; + + tmp_hh = RTC_DateDefault.WeekDay; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.WeekDay = tmp_hh; + } + tmp_hh = 0xFF; + tmp_hh = RTC_DateDefault.Date; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Date = tmp_hh; + } + tmp_mm = RTC_DateDefault.Month; + if (tmp_mm == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Month = tmp_mm; + } + tmp_ss = RTC_DateDefault.Year; + if (tmp_ss == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Year = tmp_ss; + } + + /* Configure the RTC date register */ + if (RTC_SetDate(RTC_FORMAT_BIN, &RTC_DateStructure) == ERROR) + { + log_info(">> !! RTC Set Date failed. !! <<\n\r"); + return ERROR; + } + else + { + RTC_DateShow(); + return SUCCESS; + } +} +/** + * @brief RTC time regulate with the default value. + */ +ErrorStatus RTC_TimeRegulate(void) +{ + uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF; + + RTC_TimeStructure.H12 = RTC_TimeDefault.H12; + tmp_hh = RTC_TimeDefault.Hours; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Hours = tmp_hh; + } + tmp_mm = RTC_TimeDefault.Minutes; + if (tmp_mm == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Minutes = tmp_mm; + } + + tmp_ss = RTC_TimeDefault.Seconds; + if (tmp_ss == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Seconds = tmp_ss; + } + + + /* Configure the RTC time register */ + if (RTC_ConfigTime(RTC_FORMAT_BIN, &RTC_TimeStructure) == ERROR) + { + log_info(">> !! RTC Set Time failed. !! <<\n\r"); + return ERROR; + } + else + { + RTC_TimeShow(); + return SUCCESS; + } +} + +/** + * @brief RTC prescaler config. + */ +static void RTC_PrescalerConfig(void) +{ + /* Configure the RTC data register and RTC prescaler */ + RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; + RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; + RTC_InitStructure.RTC_HourFormat = RTC_24HOUR_FORMAT; + + /* Check on RTC init */ + if (RTC_Init(&RTC_InitStructure) == ERROR) + { + log_info("//******* RTC Prescaler Config failed **********// \r\n"); + } +} + +/** + * @brief Configures RTC. + * Configure the RTC peripheral by selecting the clock source + */ + +void RTC_CLKSourceConfig(uint8_t ClkSrc) +{ + assert_param(IS_CLKSRC_VALUE(ClkSrc)); + assert_param(IS_FLCFG_VALUE(FirstLastCfg)); + + /* Enable the PWR clock */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Disable RTC clock */ + RCC_EnableRtcClk(DISABLE); + + + if (ClkSrc == 0x01) + { + +#if (_TEST_LSE_BYPASS_) + RCC_ConfigLse(RCC_LSE_BYPASS); +#else + RCC_ConfigLse(RCC_LSE_ENABLE); +#endif + + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } + + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + RCC_EnableLsi(DISABLE); + + SynchPrediv = 0xFF; // 32.768KHz + AsynchPrediv = 0x7F; // value range: 0-7F + } + else if (ClkSrc == 0x02) + { + RCC_EnableLsi(ENABLE); + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } + + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + + SynchPrediv = 0xFF; // 32.768KHz + AsynchPrediv = 0x7F; // value range: 0-7F + } + else + { + log_info("RTC_ClkSrc Value is error! \r\n"); + } + + /* Enable the RTC Clock */ + RCC_EnableRtcClk(ENABLE); + RTC_WaitForSynchro(); +} + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_tim.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_tim.c new file mode 100644 index 0000000..025cb44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_tim.c @@ -0,0 +1,327 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_tim.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_tim.h" +#include "main.h" +#include + + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define SRC_BUF_SIZE 161 +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint16_t CCR1_Val = 300; +uint16_t CCR2_Val = 200; +uint16_t CCR3_Val = 100; +uint16_t CCR4_Val = 50; + +uint16_t SRC_Buffer[SRC_BUF_SIZE] = {0}; +/* Private function prototypes -----------------------------------------------*/ + + + +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_TIM3(void) +{ + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIOB clock enable */ + RCC_EnableAPB2PeriphClk( RCC_APB2_PERIPH_GPIOB| RCC_APB2_PERIPH_AFIO, ENABLE); +} + + + + +/** + * @brief Configure the TIM3 Ouput Channels. + */ +void GPIO_Configuration_TIM3(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* GPIOB Configuration:TIM3 Channel 1 and 2 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_4|GPIO_PIN_5; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + +} + +/** + * @brief Configure the TIM3 as PWM mode and enable output + */ +void TIM3_PWM_Configuration(void) +{ + uint16_t PrescalerValue = 0; + TIM_TimeBaseInitType TIM_TimeBaseStructure; + OCInitType TIM_OCInitStructure; + + + /* System Clocks Configuration */ + RCC_Configuration_TIM3(); + + /* GPIO Configuration */ + GPIO_Configuration_TIM3(); + + /* ----------------------------------------------------------------------- + TIM1 Configuration: generate 2 PWM signals with 2 different duty cycles: + The TIM1CLK frequency is set to SystemCoreClock (Hz), to get TIM1 counter + clock at 16 MHz the Prescaler is computed as following: + - Prescaler = (TIM1CLK / TIM1 counter clock) - 1 + SystemCoreClock is set to 32(HSE) or 64(HSI) MHz for N32WB03X device + + The TIM1 is running at 40 KHz: TIM1 Frequency = TIM1 counter clock/(AR + 1) + = 16 MHz / 400 = 40 KHz + TIM1 Channel1 duty cycle = (TIM1_CCR1/ TIM1_ARR)* 100 = 75% + TIM1 Channel2 duty cycle = (TIM1_CCR2/ TIM1_ARR)* 100 = 50% + ----------------------------------------------------------------------- */ + /* Compute the prescaler value */ + PrescalerValue = (uint16_t)(SystemCoreClock / 16000000) - 1; + /* Time base configuration*/ + TIM_TimeBaseStructure.Period = (400-1); + TIM_TimeBaseStructure.Prescaler = PrescalerValue; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* PWM1 Mode configuration: Channel1 */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM1; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR1_Val; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH; + + TIM_InitOc1(TIM3, &TIM_OCInitStructure); + + TIM_EnableOc1Preload(TIM3, TIM_OC_PRE_LOAD_ENABLE); + + /* PWM1 Mode configuration: Channel2 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR2_Val; + + TIM_InitOc2(TIM3, &TIM_OCInitStructure); + + TIM_ConfigOc2Preload(TIM3, TIM_OC_PRE_LOAD_ENABLE); + + + /* TIM3 enable AR Preload */ + TIM_ConfigArPreload(TIM3, ENABLE); + + /* TIM3 enable counter */ + TIM_Enable(TIM3, ENABLE); + + +} + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_TIM1(void) +{ + + /* TIM3 and GPIOB clock enable */ + RCC_EnableAPB2PeriphClk( RCC_APB2_PERIPH_GPIOB| RCC_APB2_PERIPH_AFIO | RCC_APB2_PERIPH_TIM1, ENABLE); +} + + + + +/** + * @brief Configure the TIM1 Ouput Channels. + */ +void GPIO_Configuration_TIM1(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* GPIOB Configuration:TIM1 Channel 2,3 and 4 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + +} + + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + uint8_t i =0; + /* init SRC_Buffer data*/ + for( i =0; i < SRC_BUF_SIZE; i++ ) + { + SRC_Buffer[i] = i; + } + + /* DMA Channel5 Config */ + DMA_DeInit(DMA_CH5); + + DMA_InitStructure.PeriphAddr = (uint32_t)&TIM1->CCDAT2; //TIM1_CCR2_Address; + DMA_InitStructure.MemAddr = (uint32_t)SRC_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = SRC_BUF_SIZE; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.Priority = DMA_PRIORITY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + + DMA_Init(DMA_CH5, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_TIM1_UP, DMA, DMA_CH5, ENABLE); + /* DMA Channel5 enable */ + DMA_EnableChannel(DMA_CH5, ENABLE); +} + +/** + * @brief Configure the TIM1 as PWM mode and enable output + */ +void TIM1_PWM_Configuration(void) +{ + uint16_t PrescalerValue = 0; + TIM_TimeBaseInitType TIM_TimeBaseStructure; + OCInitType TIM_OCInitStructure; + + + /* System Clocks Configuration */ + RCC_Configuration_TIM1(); + + /* GPIO Configuration */ + GPIO_Configuration_TIM1(); + + /* DMA Configuration */ + DMA_Configuration(); + + /* ----------------------------------------------------------------------- + TIM1 Configuration: generate 2 PWM signals with 2 different duty cycles: + The TIM1CLK frequency is set to SystemCoreClock (Hz), to get TIM1 counter + clock at 16 MHz the Prescaler is computed as following: + - Prescaler = (TIM1CLK / TIM1 counter clock) - 1 + SystemCoreClock is set to 32(HSE) or 64(HSI) MHz for N32WB03X device + + The TIM1 is running at 40 KHz: TIM1 Frequency = TIM1 counter clock/(AR + 1) + = 32 MHz / 160 = 200 KHz + TIM1 Channel2 duty cycle = (TIM1_CCR1/ TIM1_ARR)* 100 = 0-100% + TIM1 Channel3 duty cycle = (TIM1_CCR2/ TIM1_ARR)* 100 = 63% + TIM1 Channel3 duty cycle = (TIM1_CCR2/ TIM1_ARR)* 100 = 32% + ----------------------------------------------------------------------- */ + /* Compute the prescaler value */ + PrescalerValue = (uint16_t)(SystemCoreClock / 32000000) - 1; + /* Time base configuration*/ + TIM_TimeBaseStructure.Period = (160-1); + TIM_TimeBaseStructure.Prescaler = PrescalerValue; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_TimeBaseStructure.RepetCnt = 0; + + TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure); + + /* PWM1 Mode configuration: Channel2 */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM2; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.OutputNState = TIM_OUTPUT_NSTATE_DISABLE; + TIM_OCInitStructure.Pulse = SRC_Buffer[0]; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_LOW; + + TIM_InitOc2(TIM1, &TIM_OCInitStructure); + + /* PWM1 Mode configuration: Channel3 */ + TIM_OCInitStructure.Pulse = CCR3_Val; + TIM_InitOc3(TIM1, &TIM_OCInitStructure); + + /* PWM1 Mode configuration: Channel4 */ + TIM_OCInitStructure.Pulse = CCR4_Val; + TIM_InitOc4(TIM1, &TIM_OCInitStructure); + + /* TIM1 Update DMA Request enable */ + TIM_EnableDma(TIM1, TIM_DMA_UPDATE, ENABLE); + + /* TIM1 enable counter */ + TIM_Enable(TIM1, ENABLE); + + /* TIM1 Main Output Enable */ + TIM_EnableCtrlPwmOutputs(TIM1, ENABLE); + +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_usart.c new file mode 100644 index 0000000..8855512 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/app_usart.c @@ -0,0 +1,203 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_usart.h" +#include "main.h" +#include + + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_fifo_buf[256] = {0}; +__IO uint8_t USART_fifo_in = 0; +__IO uint8_t USART_fifo_out = 0; +/* Private function prototypes -----------------------------------------------*/ + + + +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Deinitializes the USART. + */ +void USART_Deinitializes(void) +{ + GPIO_InitType GPIO_InitStructure; + USART_Enable(USARTx, DISABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx Rx as ANALOG to save power */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void USART_Configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief USART + */ +void USART_EchoTask(void) +{ + /* USART receive */ + if(USART_GetFlagStatus(USARTx, USART_FLAG_RXDNE) != RESET) + { + /*buffer not full yet*/ + if((USART_fifo_in+1) != USART_fifo_out) + { + /* Store the received byte in USART_fifo_buf */ + USART_fifo_buf[USART_fifo_in++] = USART_ReceiveData(USARTx); + } + } + + /* USART send */ + if(USART_GetFlagStatus(USARTx, USART_FLAG_TXDE) != RESET) + { + /*buffer not empty yet*/ + if(USART_fifo_out != USART_fifo_in) + { + /*Send one byte to USART from buf */ + USART_SendData(USARTx, USART_fifo_buf[USART_fifo_out++]); + } + } + +} + +/* retarget the C library printf function to the USART */ +int fputc(int ch, FILE* f) +{ + USART_SendData(USARTx, (uint8_t)ch); + while (USART_GetFlagStatus(USARTx, USART_FLAG_TXDE) == RESET); + + return (ch); +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/main.c new file mode 100644 index 0000000..067a44e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/main.c @@ -0,0 +1,309 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "app_rtc.h" +#include "app_tim.h" +#include "app_gpio.h" +#include "app_usart.h" +#include "app_adc.h" + +/** @addtogroup Demo + * @{ + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define PWM_TEST_ENABLE +#define RTC_TEST_ENABLE + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t EnterSleep = 0; +uint8_t key1_flag = 0; +uint8_t key2_flag = 0; +/* Private function prototypes -----------------------------------------------*/ +void app_user_key_handler(void); +extern void system_delay_n_10us(uint32_t value); +/* Private functions ---------------------------------------------------------*/ + + +void init_peripheral(void) +{ + + /*Initialize USART */ + USART_Configuration(); +#ifdef PWM_TEST_ENABLE + /*Initialize TIM3 as PWM mode */ + TIM3_PWM_Configuration(); +#endif + /*Initialize Led1 and Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + /*Turn on Led1 and LED2 */ + LedOn(LED1_PORT, LED1_PIN); + LedOn(LED2_PORT, LED2_PIN); + /*Initialize ADC and read CH1 */ + ADC_Configuration(); + + EnterSleep = 0; + key1_flag = 0; + key2_flag = 0; + system_delay_n_10us(100*500); //500ms, prevent enter sleep with the wakeup press + + +} + +void deinit_peripheral(void) +{ + /*before enter sleep */ + LedOff(LED1_PORT, LED1_PIN); + LedOff(LED2_PORT, LED2_PIN); + /*Deinitializes USART to save power*/ + USART_Deinitializes(); + +} + + + +/** + * @brief Main program + */ +int main(void) +{ +#ifdef RUN_FROM_RAM + //rum from RAW + PWR->VTOR_REG = 0xA0000000; +#endif + + /*Initialize peripheral */ + init_peripheral(); + /*Initialize key as external line interrupt */ + KeyInputExtiInit(); +#ifdef RTC_TEST_ENABLE + /*Initialize RTC */ + RTC_Configuration(); +#endif +#ifdef TEST_200MS_WAKEUP + system_delay_n_10us(200*1000); //delay few secoonds for SWD + /*before enter sleep */ + printf("Enter sleep and wait RTC auto wakeup in 200ms loop!\r\n"); + + /* Enable auto wakeup */ + RTC_EnableWakeUp(ENABLE); + /*Deinitializes peripheral to save power*/ + deinit_peripheral(); + + while(1) + { + /* Enable PWR Clock */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + PWR_EnterSLEEPMode(PWR_SLEEPENTRY_WFI); + + } +#endif + + /* Output a message on Hyperterminal using printf function */ + printf("\r\n************************** N32WB03x DEMO Start **************************\r\n"); + printf("1. LED1(PB0) and LED2(PA6) should turnn on after powoer on.\r\n"); + printf("2. Short press Key1(PB1) will Toggles LED1 and enter sleep mode, press any key will wakeup\r\n"); + printf("3. Long press Key1(PB1) will Toggles LED1 annd enter sleep and will wakeup form RTC after 10 second \r\n"); + printf("4. Short press Key2(PB2) will read and print ADC CH1(PB10) \r\n"); + printf("5. TIM3 PWM CH1(PB4) is run in 40 KHz and 75%% (300/400).\r\n"); + printf("6. TIM3 PWM CH2(PB5) is run in 40 KHz and 50%% (200/400).\r\n"); + printf("7. USART1(Tx:PB6, Rx:PB7, 115200 8N1) is enable and running echo task.\r\n"); + printf("***************************************************************************\r\n"); + printf("Now you can enter some charaters(<256 bytes one time) to test USART1:\r\n"); + + while (1) + { + /*Run the USART echo task*/ + USART_EchoTask(); + /*Run the user key task*/ + app_user_key_handler(); + + /*sleep task*/ + if(EnterSleep == 1) + { + GLOBAL_INT_DISABLE(); + printf("Enter sleep \r\n"); + /* deinit peripheral before sleep*/ + deinit_peripheral(); + + /* enter sleep */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + PWR_EnterSLEEPMode(PWR_SLEEPENTRY_WFI); + + /* after wakeup */ + init_peripheral(); + GLOBAL_INT_RESTORE(); + + printf("Out of sleep \r\n"); + RTC_TimeShow(); + + } + else if(EnterSleep == 2) + { + /* Enable auto wakeup */ + RTC_EnableWakeUp(ENABLE); + printf("Enter sleep and wait RTC auto wakeup in 10 seconds!\r\n"); + /* deinit peripheral before sleep*/ + deinit_peripheral(); + + /* enter sleep */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + PWR_EnterSLEEPMode(PWR_SLEEPENTRY_WFI); + + /* after wakeup */ + init_peripheral(); + + printf("Out of sleep with RTC auto wakeup!\r\n"); + RTC_TimeShow(); + /*stop auto wake up*/ + RTC_EnableWakeUp(DISABLE); + + } + + } +} + +void app_user_key_handler(void) +{ + uint16_t ADCConvertedValue[2]; + uint32_t voltage[2] = {0}; + uint32_t keyPressTimer = 0; + if(key1_flag) + { + + if(GPIO_ReadInputDataBit(KEY1_INPUT_PORT,KEY1_INPUT_PIN) == RESET) + { + LedBlink(LED1_PORT, LED1_PIN); + while(GPIO_ReadInputDataBit(KEY1_INPUT_PORT,KEY1_INPUT_PIN) == RESET) + { + if(keyPressTimer < 0xffffff) + { + keyPressTimer++; + } + system_delay_n_10us(80); + } + /* Set sleep flag */ + if(keyPressTimer > 3000) + { + EnterSleep = 2; + } + else if(keyPressTimer > 200) + { + EnterSleep = 1; + } + else{ + EnterSleep = 0; + } + } + key1_flag = 0; + } + if(key2_flag) + { + if(GPIO_ReadInputDataBit(KEY2_INPUT_PORT,KEY2_INPUT_PIN) == RESET) + { + LedBlink(LED2_PORT, LED2_PIN); + while(GPIO_ReadInputDataBit(KEY2_INPUT_PORT,KEY2_INPUT_PIN) == RESET) + {} + + ADCConvertedValue[0] = ADC_GetDataBlocking(ADC_CTRL_CH_1); + + voltage[0] = ADC_ConverValueToVoltage(ADCConvertedValue[0], ADC_CTRL_CH_1); + printf("ADC_CH1 value: %4d | ADC_CH1 vol_mV: %4d .\r\n",ADCConvertedValue[0],voltage[0]); + + } + + } + +} + + + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ + +/*************** (C) COPYRIGHT NSING Technologies Inc *****END OF FILE***************/ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/n32wb03x_it.c new file mode 100644 index 0000000..afd927b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/application/peripheral_alone/src/n32wb03x_it.c @@ -0,0 +1,169 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "app_adc.h" +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief External lines 0 to 1 interrupt. + */ +void EXTI0_1_IRQHandler(void) +{ + extern uint8_t key1_flag; + if (RESET != EXTI_GetITStatus(KEY1_INPUT_EXTI_LINE)) + { + key1_flag = 1; + EXTI_ClrITPendBit(KEY1_INPUT_EXTI_LINE); + } +} + +/** + * @brief External lines 2 to 3 interrupt. + */ +void EXTI2_3_IRQHandler(void) +{ + + + extern uint8_t key2_flag; + if (RESET != EXTI_GetITStatus(KEY2_INPUT_EXTI_LINE)) + { + key2_flag = 1; + EXTI_ClrITPendBit(KEY2_INPUT_EXTI_LINE); + } +} + + +/** + * @brief This function handles RTC WakeUp interrupt request. + */ + +void RTC_IRQHandler(void) +{ + + if (RESET != EXTI_GetITStatus(EXTI_LINE9)) + { + if (RTC_GetITStatus(RTC_INT_WUT) != RESET) + { + RTC_ClrIntPendingBit(RTC_INT_WUT); + } + EXTI_ClrITPendBit(EXTI_LINE9); + } +} + + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/MDK-ARM/beacon.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/MDK-ARM/beacon.uvoptx new file mode 100644 index 0000000..17297db --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/MDK-ARM/beacon.uvoptx @@ -0,0 +1,645 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + ARMRTXEVENTFLAGS + -L70 -Z18 -C0 -M0 -T1 + + + 0 + DLGTARM + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0) + + + 0 + ARMDBGFLAGS + + + + 0 + DLGUARM + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + + 1 + 0 + 0x01004118 + 0 + + + + 0 + + + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + ns_log_usart.c + 0 + 0 + + + 6 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 7 + 26 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 7 + 27 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 28 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 9 + 29 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 30 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/MDK-ARM/beacon.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/MDK-ARM/beacon.uvprojx new file mode 100644 index 0000000..a61147a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/MDK-ARM/beacon.uvprojx @@ -0,0 +1,714 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + beacon + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\beacon.bin .\Objects\beacon.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\inc\app_profile;..\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + 2 + 0 + 0 + 0 + 0 + 1 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_log_usart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_ble.h new file mode 100644 index 0000000..0d16f44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..5f4bcdc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_profile/rwapp_config.h @@ -0,0 +1,125 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_user_config.h new file mode 100644 index 0000000..4b6c6c2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/inc/app_user_config.h @@ -0,0 +1,139 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ + +#define CUSTOM_DEVICE_NAME "Beacon" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 0 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + + +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x1a\xff"\ + "\x4c\x00\x02"\ + "\x15"\ + "\x10\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff" /* iBeacon UUID */ \ + "\x12\x34" /* iBeacon Major */ \ + "\x56\x78" /* iBeacon Minor */ \ + "\xCE" /* iBeacon RSSI */ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA "" + +// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (5000) /**< Time of initiating event to update connection params (5 seconds). */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 0 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +/* profiles config */ +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +//#define CFG_APP_BATT 1 +//#define CFG_PRF_BASS 1 + + +/* User config */ +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_USART_ENABLE 1 + +#define NS_TIMER_ENABLE 0 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/readme.txt new file mode 100644 index 0000000..e6fe1a8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/readme.txt @@ -0,0 +1,36 @@ +1. Function description + + Bluetooth BLE Beacon routine, you can scan san scan the BLE adv in beacon mode(not connect able). + UUID: 0x10,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff". + Major and Minor will change every 5 sencond with a randrom number. RSSI is -50 dBm. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + usage method: + 1. Burn to development board after compilation + 2. Power on development board and check the log. + 3. Connect the BLE device with the name above. + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. + + +5. firmware authentication feature test step: + 1. Define ENABLE_FIRMWARE_AUTH in project preprocessor. + 2. Build and program firmware in development board A, it run as expect and printf demo string on USART1(PB6) . + 3. Read firmware from firmware in development board A (run utilities\dfu\JLink\ReadAll.bat). + 4. Flash all All.bin to development board B, it will not able to run as expect and printf the demo string. + 5. erase and program the All.bin into development board A, it will run as expect and printf demo string. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/src/app_ble.c new file mode 100644 index 0000000..0e5a554 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/src/app_ble.c @@ -0,0 +1,362 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "ns_sec.h" +#include "app_dis.h" +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t uuid[16] = {0x10,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff}; +uint16_t major = 0x3412; +uint16_t minor = 0x7856; +int8_t rssi = -50; +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +void app_printf_ibeacon(uint8_t* uuid, uint16_t major, uint16_t minor, int8_t rssi) +{ + NS_LOG_INFO("\r\nUUID(hex):"); + for(uint8_t i=0;i<16;i++) + { + NS_LOG_INFO(" %02X",uuid[i]); + } + NS_LOG_INFO("\r\nMajor: %d",major ); + NS_LOG_INFO("\r\nMinor: %d",minor ); + NS_LOG_INFO("\r\nRSSI at 1m: %d dBm\r\n",rssi ); +} + +void app_update_ibeacon(uint8_t* uuid, uint16_t major, uint16_t minor, int8_t rssi) +{ + uint8_t ibc_data[27] = + {0x1a,0xff, + 0x4c,0x00,0x02, + 0x15, + 0x10,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff, + 0x12,0x34, + 0x56,0x78, + 0xCE}; + memcpy(&ibc_data[6], uuid, 16); + memcpy(&ibc_data[22], &major, 2); + memcpy(&ibc_data[24], &minor, 2); + ibc_data[26] = rssi; + + ns_ble_adv_data_set(ibc_data,27); +} + + + + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_CUSTS_TEST_EVT: + { + major = rand(); //random + minor = rand(); //random + app_update_ibeacon(uuid,major,minor,rssi); + app_printf_ibeacon(uuid,major,minor,rssi); + //repeat timer + ke_timer_set(APP_CUSTS_TEST_EVT,TASK_APP,5000); + } + break; + + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + ke_timer_set(APP_CUSTS_TEST_EVT,TASK_APP,5000); + break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = false; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + user_adv.beacon_enable = true; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + + +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising + ns_ble_adv_start(); + +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/src/main.c new file mode 100644 index 0000000..bb821e0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/beacon/src/main.c @@ -0,0 +1,134 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_ble.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING Beacon demo \r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/MDK-ARM/blood_pressure.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/MDK-ARM/blood_pressure.uvoptx new file mode 100644 index 0000000..b428b60 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/MDK-ARM/blood_pressure.uvoptx @@ -0,0 +1,749 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + lib_att.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\blp\blps\src\blps.c + blps.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\blp\blps\src\blps_task.c + blps_task.c + 0 + 0 + + + 5 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + bass.c + 0 + 0 + + + 5 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + bass_task.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + ns_log_usart.c + 0 + 0 + + + 6 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 6 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 31 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 33 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 7 + 34 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 7 + 35 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_batt.c + app_batt.c + 0 + 0 + + + 7 + 36 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_blps.c + app_blps.c + 0 + 0 + + + 7 + 37 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 38 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 39 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 9 + 40 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 41 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/MDK-ARM/blood_pressure.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/MDK-ARM/blood_pressure.uvprojx new file mode 100644 index 0000000..3c9947f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/MDK-ARM/blood_pressure.uvprojx @@ -0,0 +1,726 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + blood_pressure + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\blood_pressure.bin .\Objects\blood_pressure.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\blp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\blp\blps\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\blp\blps\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + blps.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\blp\blps\src\blps.c + + + blps_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\blp\blps\src\blps_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_log_usart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_blps.c + 1 + ..\src\app_profile\app_blps.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + + + + + blood_pressure + 1 + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_ble.h new file mode 100644 index 0000000..0d16f44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/app_batt.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/app_batt.h new file mode 100644 index 0000000..5fc237b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/app_batt.h @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef APP_BATT_H_ +#define APP_BATT_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include // Standard Integer Definition +#include "ke_task.h" // Kernel Task Definition + +/* Public typedef -----------------------------------------------------------*/ + +/// Battery Application Module Environment Structure +struct app_batt_env_tag +{ + /// Connection handle + uint8_t conidx; + /// Current Battery Level + uint8_t batt_lvl; +}; + +/* Public variables ---------------------------------------------------------*/ + +/// Battery Application environment +extern struct app_batt_env_tag app_batt_env; + +/// Table of message handlers +extern const struct app_subtask_handlers app_batt_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * + * Health Thermometer Application Functions + * + **/ + +/** + * @brief Initialize Battery Application Module + **/ +void app_batt_init(void); + +/** + * @brief Add a Battery Service instance in the DB + **/ +void app_batt_add_bas(void); + +/** + * @brief Enable the Battery Service + **/ +void app_batt_enable_prf(uint8_t conidx); + +/** + * @brief Send a Battery level value + **/ +void app_batt_send_lvl(uint8_t batt_lvl); + +#endif //(BLE_APP_BATT) + +/// @} APP + +#endif // APP_BATT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/app_blps.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/app_blps.h new file mode 100644 index 0000000..0ba747d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/app_blps.h @@ -0,0 +1,139 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_blps.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_BLPS_H_ +#define APP_BLPS_H_ + +/** + * @addtogroup APP + * + * @brief Blood Pressure Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_BLPS) + +#include +#include "blp_common.h" +/* Define ------------------------------------------------------------*/ + +#define APP_BLPS_ALL_FEATURES 0x1FF + +#define APP_BLPS_SUP_FEATUEES APP_BLPS_ALL_FEATURES + +enum blps_cfg +{ + BLPS_CFG_NTFIND_STP, + BLPS_CFG_NTFIND_NTF_EN, + BLPS_CFG_NTFIND_IND_EN, +}; + +enum app_blps_prfl_cfg +{ + APP_BLPS_INTM_CUFF_PRESS_SUP = 1, + APP_BLPS_RACP_SUP = 2, +}; + + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_blps_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Blood Pressure Sensor Application + **/ +void app_blps_init(void); + +/** + * @brief Add a Blood Pressure Sensor instance in the DB + **/ +void app_blps_add_blps(void); + +/** + * @brief Enable Blood Pressure Sensor + */ +void app_blps_enable_prf(uint8_t conidx); + +/** + * @brief Send Blood Pressure Measurement value + */ +void app_blps_measurement_send(uint8_t conidx, struct bps_bp_meas *data); + +/** + * @brief Send Intermediate Cuff Pressure value + */ +void app_blps_intm_cuff_press_send(uint8_t conidx, struct bps_bp_meas *data); + +/** + * @brief send record access control point response value + */ +void app_blps_racp_resp_send(uint8_t conidx, uint8_t *data, uint8_t data_len); + +#endif //BLE_APP_BLPSS + +/// @} APP + +#endif //APP_BLPS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_user_config.h new file mode 100644 index 0000000..876e6d8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/inc/app_user_config.h @@ -0,0 +1,143 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_Blood_Pressuse" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 0 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + +// Advertise data +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_BLOOD_PRESSURE_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (5000) /**< Time of initiating event to update connection params (5 seconds). */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 0 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +/* profiles config */ +#define CFG_PRF_GAP 1 +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +//#define CFG_APP_BATT 1 +//#define CFG_PRF_BASS 1 +#define CFG_PRF_BLPS 1 +#define BLE_APP_BLPS 1 + +/* User config */ + +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 0 +#define NS_LOG_USART_ENABLE 1 + +#define NS_TIMER_ENABLE 1 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + + + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/readme.txt new file mode 100644 index 0000000..894cf49 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/readme.txt @@ -0,0 +1,31 @@ + +1. Function description + + Bluetooth BLE blood pressure service routine. After the BLE host connects to the device, + the chip automatically generates heart rate data and reports it through the Bluetooth blood pressure service. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 4. Bluetooth BLE name: NS_ Blood_ Pressuse + 5. LED1 lights up when it is turned on, LED2 indicates the connection status, and lights up when Bluetooth is connected + 6. After Bluetooth connection, the blood pressure data will be reported every second. + + usage method: + 1. Burn to development board after compilation + 2. Power on development board and check the log. + 3. Connect the BLE device with the name above, and check the BLE data upstreaming. + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_ble.c new file mode 100644 index 0000000..a424b05 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_ble.c @@ -0,0 +1,333 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "app_gpio.h" +#include "ns_sec.h" +#include "app_blps.h" +#include "app_batt.h" +#include "app_dis.h" +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_CUSTS_TEST_EVT: + + break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); + + #if (BLE_APP_BATT) + //add battery leavel server + ns_ble_add_prf_func_register(app_batt_add_bas); + #endif + + //add blood pressure server(blps) + ns_ble_add_prf_func_register(app_blps_add_blps); + + + +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + LedOn(LED2_PORT,LED2_PIN); + +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising + ns_ble_adv_start(); + + LedOff(LED2_PORT,LED2_PIN); +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_profile/app_batt.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_profile/app_batt.c new file mode 100644 index 0000000..cd57454 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_profile/app_batt.c @@ -0,0 +1,257 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2019, Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +/** + * @addtogroup APP + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include "app_batt.h" // Battery Application Module Definitions +#include "ns_ble.h" // Application Definitions +#include "ns_ble_task.h" // application task definitions +#include "bass_task.h" // health thermometer functions +#include "co_bt.h" +#include "bass.h" +#include "prf_types.h" // Profile common types definition +#include "arch.h" // Platform Definitions +#include "prf.h" +#include + +/* Private define ------------------------------------------------------------*/ +/// Battery Application Module Environment Structure +struct app_batt_env_tag app_batt_env; + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief bat server init + * @param + * @return + * @note + */ +void app_batt_init(void) +{ + // Reset the environment + memset(&app_batt_env, 0, sizeof(struct app_batt_env_tag)); + + // Initial battery level: 100 + app_batt_env.batt_lvl = 100; + + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_BASS; + prf.prf_task_handler = &app_batt_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_BASS; + get_func.prf_itf_get_func = bass_prf_itf_get; + prf_get_itf_func_register(&get_func); + +} + +/** + * @brief add bat server + * @param + * @return + * @note + */ +void app_batt_add_bas(void) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + struct bass_db_cfg* db_cfg; + // Allocate the BASS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct bass_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_BASS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct bass_db_cfg* ) req->param; + + // Add a BAS instance + db_cfg->bas_nb = 1; + // Sending of notifications is supported + db_cfg->features[0] = BAS_BATT_LVL_NTF_SUP; + + // Send the message + ke_msg_send(req); + + app_batt_init(); +} + +/** + * @brief enable batt server profile + * @param + * @return + * @note + */ +void app_batt_enable_prf(uint8_t conidx) +{ + app_batt_env.conidx = conidx; + + // Allocate the message + struct bass_enable_req * req = KE_MSG_ALLOC(BASS_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + + // NTF initial status - Disabled + req->ntf_cfg = PRF_CLI_STOP_NTFIND; + req->old_batt_lvl[0] = 50; + + // Send the message + ke_msg_send(req); +} + +/** + * @brief send battery level + * @param + * @return + * @note + */ +void app_batt_send_lvl(uint8_t batt_lvl) +{ + ASSERT_ERR(batt_lvl <= BAS_BATTERY_LVL_MAX); + + // Allocate the message + struct bass_batt_level_upd_req * req = KE_MSG_ALLOC(BASS_BATT_LEVEL_UPD_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_batt_level_upd_req); + + // Fill in the parameter structure + req->bas_instance = 0; + req->batt_level = batt_lvl; + + // Send the message + ke_msg_send(req); +} + +static int bass_batt_level_ntf_cfg_ind_handler(ke_msg_id_t const msgid, + struct bass_batt_level_ntf_cfg_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +static int batt_level_upd_handler(ke_msg_id_t const msgid, + struct bass_batt_level_upd_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +/** + * @brief + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_batt_msg_dflt_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Drop the message + + return (KE_MSG_CONSUMED); +} + +/* + * LOCAL VARIABLE DEFINITIONS + */ + +/// Default State handlers definition +const struct ke_msg_handler app_batt_msg_handler_list[] = +{ + // Note: first message is latest message checked by kernel so default is put on top. + {KE_MSG_DEFAULT_HANDLER, (ke_msg_func_t)app_batt_msg_dflt_handler}, + + {BASS_BATT_LEVEL_NTF_CFG_IND, (ke_msg_func_t)bass_batt_level_ntf_cfg_ind_handler}, + {BASS_BATT_LEVEL_UPD_RSP, (ke_msg_func_t)batt_level_upd_handler}, +}; + +const struct app_subtask_handlers app_batt_handlers = APP_HANDLERS(app_batt); + +#endif //BLE_APP_BATT + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_profile/app_blps.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_profile/app_blps.c new file mode 100644 index 0000000..f2d5704 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_profile/app_blps.c @@ -0,0 +1,439 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_blps.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BLPS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_blps.h" // BLPS Service Application Definitions +#include "blps_task.h" // BLPS Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include +#include "co_utils.h" +#include "ns_timer.h" +#include "blps.h" +#include "ns_ble_task.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define BLOOD_PRESSURE_SEND_DELAY 1000 +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ +struct bps_bp_meas app_meas; + + +void app_blood_pressure_timeout_handler(void) +{ + //send simulated data + app_blps_measurement_send(app_env.conidx, &app_meas); + + //update simulated data + app_meas.diastolic -= 1; + app_meas.systolic += 1; + app_meas.mean_arterial_pressure -= 1; + app_meas.pulse_rate += 1; + + //update time_stamp + app_meas.time_stamp.sec++; + if(app_meas.time_stamp.sec>59) + { + app_meas.time_stamp.sec = 0; + app_meas.time_stamp.min++; + if(app_meas.time_stamp.min>59) + { + app_meas.time_stamp.min = 0; + } + } + + //reset the timer + if(ke_state_get(TASK_APP)== APP_CONNECTED) + { + ns_timer_create(BLOOD_PRESSURE_SEND_DELAY,app_blood_pressure_timeout_handler); + } +} + + + + +/** + * @brief BLPS config indicate handler + * @param + * @return + * @note + */ +static int blps_cfg_indntf_ind_handler(ke_msg_id_t const msgid, + struct blps_cfg_indntf_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if(param->char_code == BPS_BP_MEAS_CHAR) + { + if(param->cfg_val & PRF_CLI_START_IND) + { + NS_LOG_INFO("BPS_BP_MEAS_CHAR START_IND\r\n"); + ns_timer_create(BLOOD_PRESSURE_SEND_DELAY,app_blood_pressure_timeout_handler); + } + else + { + NS_LOG_INFO("BPS_BP_MEAS_CHAR STOP\r\n"); + } + } + else if(param->char_code == BPS_INTM_CUFF_MEAS_CHAR) + { + if(param->cfg_val & PRF_CLI_START_NTF) + { + NS_LOG_INFO("BPS_INTM_CUFF_MEAS_CHAR START_IND\r\n"); + } + else + { + NS_LOG_INFO("BPS_INTM_CUFF_MEAS_CHAR STOP\r\n"); + } + } + else if(param->char_code == BPS_RACP_CHAR) + { + if(param->cfg_val & PRF_CLI_START_IND) + { + NS_LOG_INFO("BPS_RACP_CHAR START_IND\r\n"); + } + else + { + NS_LOG_INFO("BPS_RACP_CHAR STOP\r\n"); + } + } + + return KE_MSG_CONSUMED; +} + + +/** + * @brief enable blood pressure sensor + * @param + * @return + * @note + */ +void app_blps_enable_prf(uint8_t conidx) +{ + // Allocate the message + struct blps_enable_req * req = KE_MSG_ALLOC(BLPS_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_BLPS), + TASK_APP, + blps_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + + req->bp_meas_ind_en = PRF_CLI_STOP_NTFIND; + req->interm_cp_ntf_en = PRF_CLI_STOP_NTFIND; + req->racp_ind_en = PRF_CLI_STOP_NTFIND; + + // Send the message + ke_msg_send(req); +} + +/** + * @brief blood pressure sensor Initialize + * @param + * @return + * @note + */ +void app_blps_init(void) +{ + //Initialize simulated data + app_meas.flags = BPS_MEAS_PULSE_RATE_BIT|BPS_MEAS_FLAG_TIME_STAMP_BIT; + app_meas.systolic = 115; + app_meas.diastolic = 74; + app_meas.mean_arterial_pressure = 102; + app_meas.pulse_rate = 61; + //time stamp + app_meas.time_stamp.year = 2022; + app_meas.time_stamp.month = 3; + app_meas.time_stamp.day = 21; + app_meas.time_stamp.hour = 17; + app_meas.time_stamp.sec = 55; + + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_BLPS; + prf.prf_task_handler = &app_blps_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_BLPS; + get_func.prf_itf_get_func = blps_prf_itf_get; + prf_get_itf_func_register(&get_func); + +} + +/** + * @brief add blood pressure sensor service + * @param + * @return + * @note + */ +void app_blps_add_blps(void) +{ + struct blps_db_cfg* db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct blps_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + + req->prf_task_id = TASK_ID_BLPS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct blps_db_cfg* ) req->param; + + db_cfg->prfl_cfg = APP_BLPS_INTM_CUFF_PRESS_SUP | APP_BLPS_RACP_SUP; + db_cfg->features = APP_BLPS_SUP_FEATUEES; + + // Send the message + ke_msg_send(req); + + app_blps_init(); +} + +/** + * @brief send blood pressure value + * @param + * @return + * @note + */ +void app_blps_measurement_send(uint8_t conidx, struct bps_bp_meas *data) +{ + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + + if (GETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_BP_MEAS_IND_CFG)) + { + // Allocate the message + struct blps_meas_send_cmd * cmd = KE_MSG_ALLOC(BLPS_MEAS_SEND_CMD, + prf_get_task_from_id(TASK_ID_BLPS), + TASK_APP, + blps_meas_send_cmd); + + // Fill in the parameter structure + cmd->conidx = conidx; + cmd->flag_interm_cp = 0; //refer: flag_interm_cp + memcpy(&(cmd->meas_val), data, sizeof(struct bps_bp_meas)); + + // Send the message + ke_msg_send(cmd); + } + else + { + NS_LOG_INFO("BP_MEAS_SEND ERR\r\n"); + } +} + +/** + * @brief send intermediate cuff pressure value + * @param + * @return + * @note + */ +void app_blps_intm_cuff_press_send(uint8_t conidx, struct bps_bp_meas *data) +{ + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + + if (GETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_INTM_CUFF_PRESS_NTF_CFG)) + { + // Allocate the message + struct blps_meas_send_cmd * cmd = KE_MSG_ALLOC(BLPS_MEAS_SEND_CMD, + prf_get_task_from_id(TASK_ID_BLPS), + TASK_APP, + blps_meas_send_cmd); + + // Fill in the parameter structure + cmd->conidx = conidx; + cmd->flag_interm_cp = 1; //refer: flag_interm_cp + memcpy(&(cmd->meas_val), data, BLPS_BP_MEAS_MAX_LEN); + + // Send the message + ke_msg_send(cmd); + } + else + { + NS_LOG_INFO("BP_INTF_CUFF_SEND ERR\r\n"); + } +} + +/** + * @brief send record access control point response value + * @param + * @return + * @note + */ +void app_blps_racp_resp_send(uint8_t conidx, uint8_t *data, uint8_t data_len) +{ + struct blps_env_tag *p_blps_env = PRF_ENV_GET(BLPS, blps); + + if (GETB(p_blps_env->prfl_ntf_ind_cfg[conidx], BLPS_RACP_IND_CFG)) + { + // Allocate the message + struct blps_racp_resp_send_cmd * cmd = KE_MSG_ALLOC_DYN(BLPS_RACP_RESP_SEND_CMD, + prf_get_task_from_id(TASK_ID_BLPS), + TASK_APP, + blps_racp_resp_send_cmd, + BLPS_RACP_MAX_LEN); + + + // Fill in the parameter structure + cmd->conidx = conidx; + cmd->write_val_len = data_len; + + memcpy(&cmd->write_val, data, data_len); + + // Send the message + ke_msg_send(cmd); + } + else + { + NS_LOG_INFO("BP_RACP_SEND ERR\r\n"); + } +} + +/** + * @brief BLPS enable response handler + * @param + * @return + * @note + */ +static int blps_enable_rsp_handler(ke_msg_id_t const msgid, + struct blps_enable_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_INFO("BLPS PROFILE ENABLE STATUS: %x\r\n", param->status); + return KE_MSG_CONSUMED; +} + +/** + * @brief BLPS RACP write handler + * @param + * @return + * @note + */ +static int blps_racp_write_ind_handler(ke_msg_id_t const msgid, + struct blps_racp_write_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_INFO("RACP length: %x\r\n", param->write_val_len); + NS_LOG_INFO("RACP opcode: %x\r\n", param->write_val.opcode); + NS_LOG_INFO("RACP operator: %x\r\n", param->write_val.op_operator); + + if(param->write_val_len >= 3) + { + NS_LOG_INFO("RACP operand: %x\r\n", param->write_val.operand); + + NS_LOG_INFO("RACP data: "); + for(uint8_t i=0; i<(param->write_val_len-3); i++) + { + NS_LOG_INFO("%x ", param->write_val.data[i]); + } + NS_LOG_INFO("\r\n"); + } + + return KE_MSG_CONSUMED; +} + +/** + * @brief BLPS RACP write handler + * @param + * @return + * @note + */ +static int blps_cmp_evt_handler(ke_msg_id_t const msgid, + struct blps_cmp_evt const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + NS_LOG_INFO("BLPS CMP operation: %x, code: %x, status: %x \r\n ", \ + param->operation, param->operation_code, param->status); + + return KE_MSG_CONSUMED; +} + +/// Default State handlers definition +const struct ke_msg_handler app_blps_msg_handler_list[] = +{ + {BLPS_ENABLE_RSP, (ke_msg_func_t)blps_enable_rsp_handler}, + {BLPS_CFG_INDNTF_IND, (ke_msg_func_t)blps_cfg_indntf_ind_handler}, + {BLPS_RACP_WRITE_IND, (ke_msg_func_t)blps_racp_write_ind_handler}, + {BLPS_CMP_EVT, (ke_msg_func_t)blps_cmp_evt_handler}, +}; + +const struct app_subtask_handlers app_blps_handlers = APP_HANDLERS(app_blps); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/main.c new file mode 100644 index 0000000..679166d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/blood_pressure/src/main.c @@ -0,0 +1,141 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_gpio.h" +#include "app_ble.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING Blood Pressure Demo \r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/MDK-ARM/dis.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/MDK-ARM/dis.uvoptx new file mode 100644 index 0000000..4bee432 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/MDK-ARM/dis.uvoptx @@ -0,0 +1,615 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + ns_log_usart.c + 0 + 0 + + + 6 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 7 + 26 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 7 + 27 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 28 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 9 + 29 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 30 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/MDK-ARM/dis.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/MDK-ARM/dis.uvprojx new file mode 100644 index 0000000..a54a688 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/MDK-ARM/dis.uvprojx @@ -0,0 +1,708 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + dis + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\dis.bin .\Objects\dis.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\inc\app_profile;..\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + 2 + 0 + 0 + 0 + 0 + 1 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_log_usart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_ble.h new file mode 100644 index 0000000..0d16f44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..5f4bcdc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_profile/rwapp_config.h @@ -0,0 +1,125 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_user_config.h new file mode 100644 index 0000000..8dea0ac --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/inc/app_user_config.h @@ -0,0 +1,138 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ + +#define CUSTOM_DEVICE_NAME "NS_DIS" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 30 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + + +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_DEVICE_INFORMATION_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (5000) /**< Time of initiating event to update connection params (5 seconds). */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 0 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +/* profiles config */ +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +//#define CFG_APP_BATT 1 +//#define CFG_PRF_BASS 1 + + +/* User config */ +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_USART_ENABLE 1 + +#define NS_TIMER_ENABLE 0 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/readme.txt new file mode 100644 index 0000000..1221bdf --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/readme.txt @@ -0,0 +1,27 @@ +1. Function description + + Bluetooth BLE device service (dis) routine, you can view device service data after connecting the device + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 4. Bluetooth BLE name: NS_DIS + + usage method: + 1. Burn to development board after compilation + 2. Power on development board and check the log. + 3. Connect the BLE device with the name above. + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/src/app_ble.c new file mode 100644 index 0000000..851ba85 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/src/app_ble.c @@ -0,0 +1,318 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "ns_sec.h" +#include "app_dis.h" +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_CUSTS_TEST_EVT: + + break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + + +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising + ns_ble_adv_start(); + +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/src/main.c new file mode 100644 index 0000000..9219951 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/dis/src/main.c @@ -0,0 +1,135 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_ble.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING device information server(dis) demo \r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/MDK-ARM/heart_rate.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/MDK-ARM/heart_rate.uvoptx new file mode 100644 index 0000000..aab7f1b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/MDK-ARM/heart_rate.uvoptx @@ -0,0 +1,699 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + lib_att.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src\hrps.c + hrps.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src\hrps_task.c + hrps_task.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 6 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 7 + 31 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 7 + 32 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_hrps.c + app_hrps.c + 0 + 0 + + + 7 + 33 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 34 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 35 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 9 + 36 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 37 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/MDK-ARM/heart_rate.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/MDK-ARM/heart_rate.uvprojx new file mode 100644 index 0000000..7756b74 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/MDK-ARM/heart_rate.uvprojx @@ -0,0 +1,693 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + heart_rate + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\heart_rate.bin .\Objects\heart_rate.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\custom;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\custom\custs\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + hrps.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src\hrps.c + + + hrps_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src\hrps_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_hrps.c + 1 + ..\src\app_profile\app_hrps.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_ble.h new file mode 100644 index 0000000..0d16f44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_profile/app_hrps.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_profile/app_hrps.h new file mode 100644 index 0000000..037938a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_profile/app_hrps.h @@ -0,0 +1,139 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_hrps.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_HRPS_H_ +#define APP_HRPS_H_ + +/** + * @addtogroup APP + * + * @brief Heart Rate Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_HRPS) + +#include + +/* Define ------------------------------------------------------------*/ + +#define APP_HRPS_FEATURES (0x04) //HRPS ALL FEATURES 0x07 + +#define HEART_RATE_SEND_DELAY 1000 + +enum hrps_cfg +{ + HRPS_CFG_NTF_EN = 1, +}; + +/// Heart Rate Application Module Environment Structure +struct app_hrps_env_tag +{ + /// Connection handle + uint8_t conidx; + /// Heart Rate Value + uint8_t hrps_value; +}; + +/// Heart Rate Application environment +extern struct app_hrps_env_tag app_hrps_env; + +extern uint16_t heart_rate_timer_id; + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_hrps_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Heart Rate Service Application + **/ +void app_hrps_init(void); + +/** + * @brief Add a Heart Rate Service in the DB + **/ +void app_hrps_add_hrps(void); + +/** + * @brief Enable the Heart Rate profile + **/ +void app_hrps_enable_prf(uint8_t conidx, uint8_t cfg); + +/** + * @brief Send heart rate value + */ +void app_heart_rate_send(uint16_t heart_rate); + +/** + * @brief Send heart rate value periodically + */ +void app_heart_rate_timeout_handler(void); + +#endif //BLE_APP_HRPS + +/// @} APP + +#endif //APP_HRPS_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_user_config.h new file mode 100644 index 0000000..539a47a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/inc/app_user_config.h @@ -0,0 +1,139 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_Heart_Rate" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 0 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + +// Advertise data +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_HEART_RATE_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (5000) /**< Time of initiating event to update connection params (5 seconds). */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 0 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +/* profiles config */ +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +#define CFG_PRF_HRPS 1 +#define BLE_APP_HRPS 1 + +/* User config */ + +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 1 + +#define NS_TIMER_ENABLE 1 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + + + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/readme.txt new file mode 100644 index 0000000..5baed27 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/readme.txt @@ -0,0 +1,31 @@ +1. Function description + + Bluetooth BLE heart rate service routine. After the BLE host connects to the device, + the chip automatically generates heart rate data and reports it through the Bluetooth heart rate service. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB1(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 4. Bluetooth BLE name: NS_Heart_Rate + 5. LED1 lights up when it is turned on, LED2 indicates the connection status, and lights up when Bluetooth is connected + 6. After Bluetooth connection, the heart rate data will be reported, and the heart rate data will increase from 35 to 180, + so as to cycle. + + usage method: + 1. Burn to development board after compilation + 2. Power on development board and check the log. + 3. Connect the BLE device with the name above, and check the BLE data upstreaming. + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_ble.c new file mode 100644 index 0000000..ab3b057 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_ble.c @@ -0,0 +1,327 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "app_gpio.h" +#include "ns_sec.h" +#include "app_hrps.h" +#include "app_dis.h" +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_CUSTS_TEST_EVT: + + break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); + + //add heart rate server(hrps) + ns_ble_add_prf_func_register(app_hrps_add_hrps); + + + +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + LedOn(LED2_PORT,LED2_PIN); + +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising + ns_ble_adv_start(); + + LedOff(LED2_PORT,LED2_PIN); +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_profile/app_hrps.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_profile/app_hrps.c new file mode 100644 index 0000000..5037937 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/app_profile/app_hrps.c @@ -0,0 +1,251 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_hrps.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_HRPS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_hrps.h" // Device Information Service Application Definitions +#include "hrps_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include +#include "co_utils.h" +#include "hrps.h" +#include "stdio.h" +#include "ns_timer.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/// Heart Rate Application environment +struct app_hrps_env_tag app_hrps_env; + +uint16_t heart_rate_timer_id; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief hrps server Initialize + * @param + * @return + * @note + */ +void app_hrps_init(void) +{ + app_hrps_env.hrps_value = 35; + + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_HRPS; + prf.prf_task_handler = &app_hrps_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_HRPS; + get_func.prf_itf_get_func = hrps_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add hrps server + * @param + * @return + * @note + */ +void app_hrps_add_hrps(void) +{ + struct hrps_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct hrps_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + + req->prf_task_id = TASK_ID_HRPS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct hrps_db_cfg* ) req->param; + db_cfg->features = APP_HRPS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_hrps_init(); +} + +/** + * @brief enable heart rate profile + * @param + * @return + * @note + */ +void app_hrps_enable_prf(uint8_t conidx, uint8_t cfg) +{ + app_hrps_env.conidx = conidx; + + // Allocate the message + struct hrps_enable_req * req = KE_MSG_ALLOC(HRPS_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_HRPS), + TASK_APP, + hrps_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + + // NTF status + req->hr_meas_ntf = cfg; + + // Send the message + ke_msg_send(req); +} + +/** + * @brief send heart rate value + * @param + * @return + * @note + */ +void app_heart_rate_send(uint16_t heart_rate) +{ + // Allocate the message + struct hrps_meas_send_cmd * cmd = KE_MSG_ALLOC(HRPS_MEAS_SEND_CMD, + prf_get_task_from_id(TASK_ID_HRPS), + TASK_APP, + hrps_meas_send_cmd); + + // Fill in the parameter structure + cmd->meas_val.heart_rate = heart_rate; + + // Send the message + ke_msg_send(cmd); +} + +/** + * @brief heart rate send timeout handler + * @param + * @return + * @note + */ +void app_heart_rate_timeout_handler(void) +{ + app_hrps_env.hrps_value ++; + + if(app_hrps_env.hrps_value >= 180) + { + app_hrps_env.hrps_value = 35; + } + + app_heart_rate_send(app_hrps_env.hrps_value); + + ns_timer_cancel(heart_rate_timer_id); + + heart_rate_timer_id = ns_timer_create(HEART_RATE_SEND_DELAY,app_heart_rate_timeout_handler); +} + +/** + * @brief HRPS config indicate handler + * @param + * @return + * @note + */ +static int hrps_cfg_indntf_ind_handler(ke_msg_id_t const msgid, + struct hrps_cfg_indntf_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if( (param->cfg_val & HRPS_CFG_NTF_EN) != 0) + { + app_hrps_enable_prf(0, PRF_CLI_START_NTF); + heart_rate_timer_id = ns_timer_create(HEART_RATE_SEND_DELAY,app_heart_rate_timeout_handler); + } + else + { + app_hrps_enable_prf(0, PRF_CLI_STOP_NTFIND); + ns_timer_cancel(heart_rate_timer_id); + } + + return KE_MSG_CONSUMED; +} + + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_hrps_msg_handler_list[] = +{ + {HRPS_CFG_INDNTF_IND, (ke_msg_func_t)hrps_cfg_indntf_ind_handler}, +}; + +const struct app_subtask_handlers app_hrps_handlers = APP_HANDLERS(app_hrps); + + +#endif //BLE_APP_HRPS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/main.c new file mode 100644 index 0000000..c4d4da7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/heart_rate/src/main.c @@ -0,0 +1,141 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_gpio.h" +#include "app_ble.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING Heart Rate Demo \r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/MDK-ARM/hid_mouse.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/MDK-ARM/hid_mouse.uvoptx new file mode 100644 index 0000000..b0a094e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/MDK-ARM/hid_mouse.uvoptx @@ -0,0 +1,735 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_keyscan.c + n32wb03x_keyscan.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + lib_att.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + bass.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + bass_task.c + 0 + 0 + + + 5 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src\hogpd.c + hogpd.c + 0 + 0 + + + 5 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src\hogpd_task.c + hogpd_task.c + 0 + 0 + + + 5 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + rdts_common.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + ns_log_usart.c + 0 + 0 + + + 6 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 31 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 7 + 33 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 7 + 34 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_batt.c + app_batt.c + 0 + 0 + + + 7 + 35 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_hid.c + app_hid.c + 0 + 0 + + + 7 + 36 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 37 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 38 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 9 + 39 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 40 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/MDK-ARM/hid_mouse.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/MDK-ARM/hid_mouse.uvprojx new file mode 100644 index 0000000..76a9a44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/MDK-ARM/hid_mouse.uvprojx @@ -0,0 +1,708 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + hid_mouse + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\hid_mouse.bin .\Objects\hid_mouse.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_keyscan.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_keyscan.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + hogpd.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src\hogpd.c + + + hogpd_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src\hogpd_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + + + NS_LIB + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_log_usart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_hid.c + 1 + ..\src\app_profile\app_hid.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_ble.h new file mode 100644 index 0000000..dece4cb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_ble.h @@ -0,0 +1,96 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_KEY_DETECTED, + APP_HID_MOUSE_TIMEOUT_TIMER, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_gpio.h new file mode 100644 index 0000000..60d76b3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_gpio.h @@ -0,0 +1,109 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +#define KEY1_INPUT_PORT GPIOB +#define KEY1_INPUT_PIN GPIO_PIN_1 +#define KEY1_INPUT_EXTI_LINE EXTI_LINE1 +#define KEY1_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY1_INPUT_PIN_SOURCE GPIO_PIN_SOURCE1 +#define KEY1_INPUT_IRQn EXTI0_1_IRQn + +#define KEY2_INPUT_PORT GPIOB +#define KEY2_INPUT_PIN GPIO_PIN_2 +#define KEY2_INPUT_EXTI_LINE EXTI_LINE2 +#define KEY2_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY2_INPUT_PIN_SOURCE GPIO_PIN_SOURCE2 +#define KEY2_INPUT_IRQn EXTI2_3_IRQn + + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void app_key_press_timeout_handler(void); +void app_key_configuration(void); +void app_key_reinit_after_sleep(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/app_batt.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/app_batt.h new file mode 100644 index 0000000..5fc237b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/app_batt.h @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef APP_BATT_H_ +#define APP_BATT_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include // Standard Integer Definition +#include "ke_task.h" // Kernel Task Definition + +/* Public typedef -----------------------------------------------------------*/ + +/// Battery Application Module Environment Structure +struct app_batt_env_tag +{ + /// Connection handle + uint8_t conidx; + /// Current Battery Level + uint8_t batt_lvl; +}; + +/* Public variables ---------------------------------------------------------*/ + +/// Battery Application environment +extern struct app_batt_env_tag app_batt_env; + +/// Table of message handlers +extern const struct app_subtask_handlers app_batt_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * + * Health Thermometer Application Functions + * + **/ + +/** + * @brief Initialize Battery Application Module + **/ +void app_batt_init(void); + +/** + * @brief Add a Battery Service instance in the DB + **/ +void app_batt_add_bas(void); + +/** + * @brief Enable the Battery Service + **/ +void app_batt_enable_prf(uint8_t conidx); + +/** + * @brief Send a Battery level value + **/ +void app_batt_send_lvl(uint8_t batt_lvl); + +#endif //(BLE_APP_BATT) + +/// @} APP + +#endif // APP_BATT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/app_hid.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/app_hid.h new file mode 100644 index 0000000..56d2bf1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/app_hid.h @@ -0,0 +1,161 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_hid.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_HID_H_ +#define APP_HID_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief HID Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_HID) + +#include // Standard Integer Definition +#include "ke_task.h" // Kernel Task Definition + +#if (PS2_SUPPORT) +#include "ps2.h" // PS2 Mouse Driver +#endif //(PS2_SUPPORT) + +/* Public typedef -----------------------------------------------------------*/ + + +/// HID Application Module Environment Structure +struct app_hid_env_tag +{ + /// Connection handle + uint8_t conidx; + /// Mouse timeout value + uint16_t timeout; + /// Internal state of the module + uint8_t state; + /// Timer enabled + bool timer_enabled; + /// Number of report that can be sent + uint8_t nb_report; +}; + +/// Mouse report (data packet) +struct ps2_mouse_msg +{ + /// Buttons + uint8_t b; + /// X Axis Relative Movement + uint8_t x; + /// Y Axis Relative Movement + uint8_t y; + /// Wheel Relative Movement + uint8_t w; +}; + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_hid_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * + * Health Thermometer Application Functions + * + **/ + +/** + * @brief Initialize HID Application Module + **/ +void app_hid_init(void); + +/** + * @brief Add a HID Service instance in the DB + **/ +void app_hid_add_hids(void); + +/** + * @brief Enable the HID Over GATT Profile device role + * + * @param[in]: conhdl - Connection handle for the connection + **/ +void app_hid_enable_prf(uint8_t conidx); + +/** + * @brief Send a mouse report to the peer device + * + * @param[in]: report - Mouse report sent by the PS2 driver + **/ +void app_hid_send_mouse_report(struct ps2_mouse_msg report); + +int app_hid_mouse_timeout_timer_handler(ke_msg_id_t const msgid,void const *param); + +void app_hid_send_consumer_report(uint8_t* report); +void app_hid_send_voice_report(uint8_t* report, uint8_t len); +bool is_app_hid_ready(void); +#endif //(BLE_APP_HID) + +/// @} APP + +#endif // APP_HID_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..f7cf50d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_profile/rwapp_config.h @@ -0,0 +1,124 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_user_config.h new file mode 100644 index 0000000..753fe2b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/inc/app_user_config.h @@ -0,0 +1,149 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "hid_mouse" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 0//30 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + + +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_INCOMPLETE_LIST_16BIT_SERVICE_IDS\ + ADV_UUID_HUMAN_INTERFACE_DEVICE_SERVICE\ + + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +/// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +/// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 30 /**< Minimum connection interval (30 ms) */ +#define MAX_CONN_INTERVAL 50 /**< Maximum connection interval (50 ms). */ +#define SLAVE_LATENCY 5 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY 0 /**< Time of initiating event to update connection params. */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_DISPLAY_ONLY /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 1 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +/* profiles config */ +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 + +#define CFG_APP_BATT 1 +#define CFG_PRF_BASS 1 + +#define CFG_PRF_HOGPD 1 +#define CFG_APP_HID 1 + +// enable this patch if your MTK phone pair fail +#define _PATCH_ENC_RESPONDSE_ 1 + + +/* User config */ + +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_USART_ENABLE 1 + + +#define NS_TIMER_ENABLE 1 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + + + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/readme.txt new file mode 100644 index 0000000..6cbe7d7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/readme.txt @@ -0,0 +1,34 @@ + +1. Function description + + Bluetooth BLE HID mouse service routine. After the BLE host is connected to the device, + the mouse displacement command is triggered through button1, and the multimedia volume + decrement command is triggered through button2. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 4. Bluetooth BLE name: hid_mouse + 5. LED1 lights up when it is turned on, LED2 indicates the connection status, and lights up when Bluetooth is connected + + + usage method: + 1. Burn to development board after compilation + 2. Power on development board and check the log. + 3. Search and connect devices on the Bluetooth page of the system in smartphone. The pairing password is 123456. + 4. Press button1 to send the mouse displacement command, and the mouse moves 10 pixels to the right. + 5. Press button2 to send multimedia key value, and the volume decreases. + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_ble.c new file mode 100644 index 0000000..d76e987 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_ble.c @@ -0,0 +1,362 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "app_gpio.h" +#include "ns_sec.h" +#include "app_hid.h" +#include "app_dis.h" +#include "app_batt.h" +#if (BLE_APP_NS_IUS) +#include "app_ns_ius.h" +#endif //BLE_APP_NS_IUS +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_HID_MOUSE_TIMEOUT_TIMER: + app_hid_mouse_timeout_timer_handler(msgid,p_param); + break; + case APP_KEY_DETECTED: + { + app_key_press_timeout_handler(); + }break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_batt_enable_prf(app_env.conidx); + app_hid_enable_prf(app_env.conidx); + + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_sec_msg_handler(struct sec_msg_t const * p_msg) +{ + switch (p_msg->msg_id) + { + case NS_SEC_PINCODE_DISPLAY: + + break; + case NS_SEC_PAIR_SUCCEED: + ke_timer_set(APP_PARAMS_UPDATE_EVT, TASK_APP, FIRST_CONN_PARAMS_UPDATE_DELAY); + break; + case NS_SEC_PAIR_FAILED: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 962; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = true; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 5000; + + sec_init.ns_sec_msg_handler = app_ble_sec_msg_handler; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); + //add battery level server + ns_ble_add_prf_func_register(app_batt_add_bas); + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_hid_add_hids); + + + +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + LedOn(LED2_PORT,LED2_PIN); + +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising + ns_ble_adv_start(); + + LedOff(LED2_PORT,LED2_PIN); +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_gpio.c new file mode 100644 index 0000000..682a1db --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_gpio.c @@ -0,0 +1,315 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" +#include +#include "global_func.h" +#include "app_hid.h" +#include "ns_log.h" +#include "ns_timer.h" +#include "ns_delay.h" +#include "app_ble.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define KEY_PRESS_DELAY 100 +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t key1_irq_actived = 0; +uint8_t key2_irq_actived = 0; + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @brief Configures key port. + */ +void app_key_configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + + /*Configure the GPIO pin as input floating */ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = KEY1_INPUT_PIN; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(KEY1_INPUT_PORT, &GPIO_InitStructure); + + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + + /*Configure the GPIO pin as input floating*/ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = KEY2_INPUT_PIN; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(KEY2_INPUT_PORT, &GPIO_InitStructure); + + /*Configure key EXTI Line to key input Pin*/ + GPIO_ConfigEXTILine(KEY1_INPUT_PORT_SOURCE, KEY1_INPUT_PIN_SOURCE); + GPIO_ConfigEXTILine(KEY2_INPUT_PORT_SOURCE, KEY2_INPUT_PIN_SOURCE); + + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY1_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY1_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY2_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY2_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief re-configures key port aafter sleep. + */ +void app_key_reinit_after_sleep(void) +{ + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + +} + +/** + * @brief key press timer handler. + */ +void app_key_press_timeout_handler(void) +{ + + if(key1_irq_actived == 1) + { + LedBlink(LED1_PORT, LED1_PIN); + #if (CFG_APP_HID) + //send move x up + struct ps2_mouse_msg msg = {0}; + msg.x = 10; + app_hid_send_mouse_report(msg); + + #endif + NS_LOG_INFO("Button 1, mouse moving\r\n"); + key1_irq_actived = 0; + } + else if(key1_irq_actived == 2 ) + { + //re-start timer if got irq after first created timer + ns_timer_create(KEY_PRESS_DELAY,app_key_press_timeout_handler); + key1_irq_actived = 1; + } + + if(key2_irq_actived == 1) + { + LedBlink(LED1_PORT, LED1_PIN); + #if (CFG_APP_HID) + + uint8_t key = 0; + key = 0x08; //Volume Down +// key = 0x10; //Volume up +// key = 0x20; //Mute + app_hid_send_consumer_report((uint8_t*)&key); + key = 0x0; //send release key + app_hid_send_consumer_report((uint8_t*)&key); + #endif + NS_LOG_INFO("Button 2, Volume Down\r\n"); + key2_irq_actived = 0; + } + else if(key2_irq_actived == 2) + { + //re-start timer if got irq after first created timer + ns_timer_create(KEY_PRESS_DELAY,app_key_press_timeout_handler); + key2_irq_actived = 1; + } + +} + +/** + * @brief External lines 1 interrupt. + */ +void EXTI0_1_IRQHandler(void) +{ + + if ( EXTI_GetITStatus(KEY1_INPUT_EXTI_LINE)!= RESET) + { + + if(key1_irq_actived == 0) + { + ke_msg_send_basic(APP_KEY_DETECTED, TASK_APP, TASK_APP); + key1_irq_actived = 1; + } + else if(key1_irq_actived == 1) + { + //if timer started, update flag + key1_irq_actived = 2; + + } + EXTI_ClrITPendBit(KEY1_INPUT_EXTI_LINE); + } +} + +/** + * @brief External lines 2 interrupt. + */ +void EXTI2_3_IRQHandler(void) +{ + if ( EXTI_GetITStatus(KEY2_INPUT_EXTI_LINE)!= RESET) + { + + if(key2_irq_actived == 0) + { + ke_msg_send_basic(APP_KEY_DETECTED, TASK_APP, TASK_APP); + key2_irq_actived = 1; + } + else if(key2_irq_actived == 1) + { + //if timer started, update flag + key2_irq_actived = 2; + } + EXTI_ClrITPendBit(KEY2_INPUT_EXTI_LINE); + } +} + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_profile/app_batt.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_profile/app_batt.c new file mode 100644 index 0000000..4b650ba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_profile/app_batt.c @@ -0,0 +1,257 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +/** + * @addtogroup APP + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include "app_batt.h" // Battery Application Module Definitions +#include "ns_ble.h" // Application Definitions +#include "ns_ble_task.h" // application task definitions +#include "bass_task.h" // health thermometer functions +#include "co_bt.h" +#include "bass.h" +#include "prf_types.h" // Profile common types definition +#include "arch.h" // Platform Definitions +#include "prf.h" +#include + +/* Private define ------------------------------------------------------------*/ +/// Battery Application Module Environment Structure +struct app_batt_env_tag app_batt_env; + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief bat server init + * @param + * @return + * @note + */ +void app_batt_init(void) +{ + // Reset the environment + memset(&app_batt_env, 0, sizeof(struct app_batt_env_tag)); + + // Initial battery level: 100 + app_batt_env.batt_lvl = 100; + + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_BASS; + prf.prf_task_handler = &app_batt_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_BASS; + get_func.prf_itf_get_func = bass_prf_itf_get; + prf_get_itf_func_register(&get_func); + +} + +/** + * @brief add bat server + * @param + * @return + * @note + */ +void app_batt_add_bas(void) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + struct bass_db_cfg* db_cfg; + // Allocate the BASS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct bass_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_BASS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct bass_db_cfg* ) req->param; + + // Add a BAS instance + db_cfg->bas_nb = 1; + // Sending of notifications is supported + db_cfg->features[0] = BAS_BATT_LVL_NTF_SUP; + + // Send the message + ke_msg_send(req); + + app_batt_init(); +} + +/** + * @brief enable batt server profile + * @param + * @return + * @note + */ +void app_batt_enable_prf(uint8_t conidx) +{ + app_batt_env.conidx = conidx; + + // Allocate the message + struct bass_enable_req * req = KE_MSG_ALLOC(BASS_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + + // NTF initial status - Disabled + req->ntf_cfg = PRF_CLI_STOP_NTFIND; + req->old_batt_lvl[0] = 50; + + // Send the message + ke_msg_send(req); +} + +/** + * @brief send battery level + * @param + * @return + * @note + */ +void app_batt_send_lvl(uint8_t batt_lvl) +{ + ASSERT_ERR(batt_lvl <= BAS_BATTERY_LVL_MAX); + + // Allocate the message + struct bass_batt_level_upd_req * req = KE_MSG_ALLOC(BASS_BATT_LEVEL_UPD_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_batt_level_upd_req); + + // Fill in the parameter structure + req->bas_instance = 0; + req->batt_level = batt_lvl; + + // Send the message + ke_msg_send(req); +} + +static int bass_batt_level_ntf_cfg_ind_handler(ke_msg_id_t const msgid, + struct bass_batt_level_ntf_cfg_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +static int batt_level_upd_handler(ke_msg_id_t const msgid, + struct bass_batt_level_upd_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +/** + * @brief + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_batt_msg_dflt_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Drop the message + + return (KE_MSG_CONSUMED); +} + +/* + * LOCAL VARIABLE DEFINITIONS + */ + +/// Default State handlers definition +const struct ke_msg_handler app_batt_msg_handler_list[] = +{ + // Note: first message is latest message checked by kernel so default is put on top. + {KE_MSG_DEFAULT_HANDLER, (ke_msg_func_t)app_batt_msg_dflt_handler}, + + {BASS_BATT_LEVEL_NTF_CFG_IND, (ke_msg_func_t)bass_batt_level_ntf_cfg_ind_handler}, + {BASS_BATT_LEVEL_UPD_RSP, (ke_msg_func_t)batt_level_upd_handler}, +}; + +const struct app_subtask_handlers app_batt_handlers = APP_HANDLERS(app_batt); + +#endif //BLE_APP_BATT + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_profile/app_hid.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_profile/app_hid.c new file mode 100644 index 0000000..c50cee7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/app_profile/app_hid.c @@ -0,0 +1,1002 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_hid.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#include +#include + +#if (BLE_APP_HID) + +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Definitions +#include "ns_sec.h" // Application Security Module API +#include "ns_ble_task.h" // Application task definitions +#include "app_hid.h" // HID Application Module Definitions +#include "hogpd_task.h" // HID Over GATT Profile Device Role Functions +#include "prf_types.h" // Profile common types Definition +#include "arch.h" // Platform Definitions +#include "prf.h" +#include "ke_timer.h" + +#if (NVDS_SUPPORT) +#include "nvds.h" // NVDS Definitions +#endif //(NVDS_SUPPORT) +#include "hogpd.h" +#include "co_utils.h" // Common functions + +#if (KE_PROFILING) +#include "ke_mem.h" +#endif //(KE_PROFILING) +#include "app_gpio.h" +#include "app_ble.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/// Length of the HID Report +#define APP_HID_CONSUMER_REPORT_LEN (1) +#define APP_HID_MOUSE_REPORT_LEN (6) +/// Length of the Report Descriptor for an HID Mouse +#define APP_HID_MOUSE_REPORT_MAP_LEN (sizeof(app_hid_mouse_report_map)) + +/// Duration before connection update procedure if no report received (mouse is silent) - 20s +#define APP_HID_SILENCE_DURATION_1 0//(2000) +/// Duration before disconnection if no report is received after connection update - 60s +#define APP_HID_SILENCE_DURATION_2 (6000) + +/// Number of reports that can be sent +#define APP_HID_NB_SEND_REPORT (10) + +/// States of the Application HID Module +enum app_hid_states +{ + /// Module is disabled (Service not added in DB) + APP_HID_DISABLED, + /// Module is idle (Service added but profile not enabled) + APP_HID_IDLE, + /// Module is enabled (Device is connected and the profile is enabled) + APP_HID_ENABLED, + /// The application can send reports + APP_HID_READY, + /// Waiting for a report + APP_HID_WAIT_REP, + + APP_HID_STATE_MAX, +}; + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/// HID Application Module Environment Structure +static struct app_hid_env_tag app_hid_env; + +/// HID Mouse Report Descriptor +static const uint8_t app_hid_mouse_report_map[] = +{ + /** + * -------------------------------------------------------------------------- + * Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * -------------------------------------------------------------------------- + * Byte 0 | Not Used | Middle| Right | Left | + * -------------------------------------------------------------------------- + * Byte 1 | X Axis Relative Movement | + * -------------------------------------------------------------------------- + * Byte 2 | Y Axis Relative Movement | + * -------------------------------------------------------------------------- + * Byte 3 | Wheel Relative Movement | + * -------------------------------------------------------------------------- + */ + + 0x05, 0x01, /// USAGE PAGE (Generic Desktop) + 0x09, 0x02, /// USAGE (Mouse) + + 0xA1, 0x01, /// COLLECTION (Application) + + 0x85, 0x01, /// REPORT ID (1) - MANDATORY + 0x09, 0x01, /// USAGE (Pointer) + 0xA1, 0x00, /// COLLECTION (Physical) + + /** + * ---------------------------------------------------------------------------- + * BUTTONS + * ---------------------------------------------------------------------------- + */ + 0x05, 0x09, /// USAGE PAGE (Buttons) + 0x19, 0x01, /// USAGE MINIMUM (1) + 0x29, 0x08, /// USAGE MAXIMUM (8) + 0x15, 0x00, /// LOGICAL MINIMUM (0) + 0x25, 0x01, /// LOGICAL MAXIMUM (1) + 0x75, 0x01, /// REPORT SIZE (1) + 0x95, 0x08, /// REPORT COUNT (8) + 0x81, 0x02, /// INPUT (Data, Variable, Absolute) + + /** + * ---------------------------------------------------------------------------- + * MOVEMENT DATA + * ---------------------------------------------------------------------------- + */ + 0x05, 0x01, /// USAGE PAGE (Generic Desktop) + 0x16, 0x08, 0xFF, /// LOGICAL MINIMUM (-255) + 0x26, 0xFF, 0x00, /// LOGICAL MAXIMUM (255) + 0x75, 0x10, /// REPORT SIZE (16) + 0x95, 0x02, /// REPORT COUNT (2) + 0x09, 0x30, /// USAGE (X) + 0x09, 0x31, /// USAGE (Y) + 0x81, 0x06, /// INPUT (Data, Variable, Relative) + + 0x15, 0x81, /// LOGICAL MINIMUM (-127) + 0x25, 0x7F, /// LOGICAL MAXIMUM (127) + 0x75, 0x08, /// REPORT SIZE (8) + 0x95, 0x01, /// REPORT COUNT (1) + 0x09, 0x38, /// USAGE (Wheel) + 0x81, 0x06, /// INPUT (Data, Variable, Relative) + + 0xC0, /// END COLLECTION (Physical) + 0xC0, /// END COLLECTION (Application) + + // Report ID 2: Advanced buttons + 0x05, 0x0C, // Usage Page (Consumer) + 0x09, 0x01, // Usage (Consumer Control) + 0xA1, 0x01, // Collection (Application) + 0x85, 0x02, // Report Id (2) + 0x15, 0x00, // Logical minimum (0) + 0x25, 0x01, // Logical maximum (1) + 0x75, 0x01, // Report Size (1) + 0x95, 0x08, // Report Count (8) + + 0x09, 0xCD, // Usage (Play/Pause) //test, for audio final + 0x09, 0xB6, // Usage (Scan Previous Track) + 0x09, 0xB5, // Usage (Scan Next Track) + 0x09, 0xEA, // Usage (Volume Down) + 0x09, 0xE9, // Usage (Volume Up) + 0x09, 0xE2, // Usage (Mute) + 0x09, 0xCC, // Usage (Stop eject) + 0x09, 0xB7, // Usage (Stop) + 0x81, 0x06, // Input (Data,Value,Relative,Bit Field) + + 0xC0, // End Collection + +}; + + + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +void app_hid_init(void) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + + // Reset the environment + memset(&app_hid_env, 0, sizeof(app_hid_env)); + + app_hid_env.nb_report = APP_HID_NB_SEND_REPORT; + + + app_hid_env.timeout = APP_HID_SILENCE_DURATION_1; + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_HOGPD; + prf.prf_task_handler = &app_hid_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_HOGPD; + get_func.prf_itf_get_func = hogpd_prf_itf_get; + prf_get_itf_func_register(&get_func); + +} + + +void app_hid_add_hids(void) +{ + struct hogpd_db_cfg *db_cfg; + // Prepare the HOGPD_CREATE_DB_REQ message + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct hogpd_db_cfg)); + + NS_LOG_DEBUG("%s\r\n",__func__); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, UNAUTH); // NO_AUTH UNAUTH AUTH + req->prf_task_id = TASK_ID_HOGPD; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct hogpd_db_cfg* ) req->param; + + // Only one HIDS instance is useful + db_cfg->hids_nb = 1; + + // The device is a mouse + db_cfg->cfg[0].svc_features = HOGPD_CFG_MOUSE;//HOGPD_CFG_MOUSE_BIT; + + // Only one Report Characteristic is requested + db_cfg->cfg[0].report_nb = 2; + + db_cfg->cfg[0].report_id[0] = 1; + db_cfg->cfg[0].report_char_cfg[0] = HOGPD_CFG_REPORT_IN; + + db_cfg->cfg[0].report_id[1] = 2; + db_cfg->cfg[0].report_char_cfg[1] = HOGPD_CFG_REPORT_IN; + + // HID Information + db_cfg->cfg[0].hid_info.bcdHID = 0x0111; // HID Version 1.11 + db_cfg->cfg[0].hid_info.bCountryCode = 0x00; + db_cfg->cfg[0].hid_info.flags = HIDS_REMOTE_WAKE_CAPABLE | HIDS_NORM_CONNECTABLE; + + // Send the message + ke_msg_send(req); + + app_hid_init(); +} + + + + +/* + * @brief Function called when get connection complete event from the GAP + * + */ +void app_hid_enable_prf(uint8_t conidx) +{ + uint16_t ntf_cfg; + NS_LOG_DEBUG("%s,idx %x\r\n",__func__,conidx); + + // Store the connection handle + app_hid_env.conidx = conidx; + + // Allocate the message + struct hogpd_enable_req * req = KE_MSG_ALLOC(HOGPD_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_HOGPD), + TASK_APP, + hogpd_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + // Notifications are disabled + ntf_cfg = 0; + + // Go to Enabled state + app_hid_env.state = APP_HID_ENABLED; + + // If first connection with the peer device + if (ns_sec_get_bond_status()) + { + app_hid_env.state = APP_HID_READY; + app_hid_env.nb_report = APP_HID_NB_SEND_REPORT; + ntf_cfg = 0xC2; + NS_LOG_DEBUG("HID ready for bonded device\r\n"); + + } + + req->ntf_cfg[conidx] = ntf_cfg; + + // Send the message + ke_msg_send(req); +} + + + + + + + +/* + * @brief Function called from PS2 driver + * + */ +void app_hid_send_mouse_report(struct ps2_mouse_msg report) +{ + + NS_LOG_DEBUG("HID report, state:%d, x:%d, y:%d \r\n",app_hid_env.state, report.x, report.y); + switch (app_hid_env.state) + { + case (APP_HID_READY): + { + // Check if the report can be sent + if (app_hid_env.nb_report) + { + // Buffer used to create the Report + uint8_t report_buff[APP_HID_MOUSE_REPORT_LEN]; + // X, Y and wheel relative movements + int16_t x; + int16_t y; + + // Clean the report buffer + memset(&report_buff[0], 0, APP_HID_MOUSE_REPORT_LEN); + + // Set the button states + report_buff[0] = (report.b & 0x07); + + // If X value is negative + if (report.b & 0x10) + { + report.x = ~report.x; + report.x += 1; + x = (int16_t)report.x; + x *= (-1); + } + else + { + x = (int16_t)report.x; + } + + // If Y value is negative + if (report.b & 0x20) + { + report.y = ~report.y; + report.y += 1; + y = (int16_t)report.y; + } + else + { + y = (int16_t)report.y; + y *= (-1); + } + + + // Set the X and Y movement value in the report + co_write16p(&report_buff[1], x); + co_write16p(&report_buff[3], y); + report_buff[5] =(signed char) (-1) * report.w; + + // Allocate the HOGPD_REPORT_UPD_REQ message + struct hogpd_report_upd_req * req = KE_MSG_ALLOC_DYN(HOGPD_REPORT_UPD_REQ, + prf_get_task_from_id(TASK_ID_HOGPD), + TASK_APP, + hogpd_report_upd_req, + APP_HID_MOUSE_REPORT_LEN); + + req->conidx = app_hid_env.conidx; + //now fill report + req->report.hid_idx = app_hid_env.conidx; + req->report.type = HOGPD_REPORT; //HOGPD_BOOT_MOUSE_INPUT_REPORT;// + req->report.idx = 0; //0 for boot reports and report map + req->report.length = APP_HID_MOUSE_REPORT_LEN; + memcpy(&req->report.value[0], &report_buff[0], APP_HID_MOUSE_REPORT_LEN); + + ke_msg_send(req); + + app_hid_env.nb_report--; + + // Restart the mouse timeout timer if needed + if (app_hid_env.timeout != 0) + { + ke_timer_set(APP_HID_MOUSE_TIMEOUT_TIMER, TASK_APP, (uint16_t)(app_hid_env.timeout)); + app_hid_env.timer_enabled = true; + } + } + } break; + + case (APP_HID_WAIT_REP): + { + // Requested connection parameters + struct gapc_conn_param conn_param; + + /* + * Requested connection interval: 10ms + * Latency: 25 + * Supervision Timeout: 2s + */ + conn_param.intv_min = 8; + conn_param.intv_max = 8; + conn_param.latency = 25; + conn_param.time_out = 200; + + ns_ble_update_param(&conn_param); + // Restart the mouse timeout timer if needed + if (app_hid_env.timeout != 0) + { + ke_timer_set(APP_HID_MOUSE_TIMEOUT_TIMER, TASK_APP, (uint16_t)(app_hid_env.timeout)); + app_hid_env.timer_enabled = true; + } + + // Go back to the ready state + app_hid_env.state = APP_HID_READY; + } break; + + case (APP_HID_IDLE): + { + // Try to restart advertising if needed +// app_update_adv_state(true); + } break; + + + // DISABLE and ENABLED states + default: + { + // Drop the message + } break; + } + +} + + +/* + * @brief Function + * + */ +void app_hid_send_consumer_report(uint8_t* report) +{ + NS_LOG_DEBUG("Consumer,state:%d ,%d\r\n",app_hid_env.state,app_hid_env.nb_report); + switch (app_hid_env.state) + { + case (APP_HID_READY): + { + // Check if the report can be sent + if (app_hid_env.nb_report) + { + // Allocate the HOGPD_REPORT_UPD_REQ message + struct hogpd_report_upd_req * req = KE_MSG_ALLOC_DYN(HOGPD_REPORT_UPD_REQ, + prf_get_task_from_id(TASK_ID_HOGPD), + TASK_APP, + hogpd_report_upd_req, + APP_HID_CONSUMER_REPORT_LEN); + + req->conidx = app_hid_env.conidx; + //now fill report + req->report.hid_idx = app_hid_env.conidx; + req->report.type = HOGPD_REPORT; //HOGPD_BOOT_MOUSE_INPUT_REPORT;// + req->report.idx = 1; //repoort id 2 report map + req->report.length = APP_HID_CONSUMER_REPORT_LEN; + memcpy(&req->report.value[0], &report[0],APP_HID_CONSUMER_REPORT_LEN); + + ke_msg_send(req); + + app_hid_env.nb_report--; + + // Restart the mouse timeout timer if needed + if (app_hid_env.timeout != 0) + { + ke_timer_set(APP_HID_MOUSE_TIMEOUT_TIMER, TASK_APP, (uint16_t)(app_hid_env.timeout)); + app_hid_env.timer_enabled = true; + } + } + } break; + + case (APP_HID_WAIT_REP): + { + // Requested connection parameters + struct gapc_conn_param conn_param; + + /* + * Requested connection interval: 10ms + * Latency: 25 + * Supervision Timeout: 2s + */ + conn_param.intv_min = 8; + conn_param.intv_max = 8; + conn_param.latency = 25; + conn_param.time_out = 200; + ns_ble_update_param(&conn_param); + + // Restart the mouse timeout timer if needed + if (app_hid_env.timeout != 0) + { + ke_timer_set(APP_HID_MOUSE_TIMEOUT_TIMER, TASK_APP, (uint16_t)(app_hid_env.timeout)); + app_hid_env.timer_enabled = true; + } + + // Go back to the ready state + app_hid_env.state = APP_HID_READY; + } break; + + case (APP_HID_IDLE): + { + // Try to restart advertising if needed +// app_update_adv_state(true); + } break; + + + // DISABLE and ENABLED states + default: + { + // Drop the message + } break; + } +#if (KE_PROFILING) +// app_display_hdl_env_size(0xFFFF, ke_get_mem_usage(KE_MEM_ENV)); +// app_display_hdl_db_size(0xFFFF, ke_get_mem_usage(KE_MEM_ATT_DB)); +// app_display_hdl_msg_size((uint16_t)ke_get_max_mem_usage(), ke_get_mem_usage(KE_MEM_KE_MSG)); + #endif //(KE_PROFILING) +} + + +bool is_app_hid_ready(void) +{ + if (app_hid_env.state == APP_HID_READY) + { + return true; + } + + return false; +} + + +/* + * MESSAGE HANDLERS + */ + + +static int hogpd_ctnl_pt_ind_handler(ke_msg_id_t const msgid, + struct hogpd_ctnl_pt_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + + if (param->conidx == app_hid_env.conidx) + { + //make use of param->hid_ctnl_pt + struct hogpd_report_cfm *req = KE_MSG_ALLOC_DYN(HOGPD_REPORT_CFM, + prf_get_task_from_id(TASK_ID_HOGPD),/* src_id */ + TASK_APP, + hogpd_report_cfm, + 0); + + req->conidx = param->conidx; ///app_hid_env.conidx; ///??? + /// Operation requested (read/write @see enum hogpd_op) + req->operation = HOGPD_OP_REPORT_WRITE; + /// Status of the request + req->status = GAP_ERR_NO_ERROR; ///??? + /// Report Info + //req->report; + /// HIDS Instance + req->report.hid_idx = app_hid_env.conidx; ///??? + /// type of report (@see enum hogpd_report_type) + req->report.type = (uint8_t)-1;//outside + /// Report Length (uint8_t) + req->report.length = 0; + /// Report Instance - 0 for boot reports and report map + req->report.idx = 0; + /// Report data + + + // Send the message + ke_msg_send(req); + } + return (KE_MSG_CONSUMED); +} + + + + +static int hogpd_ntf_cfg_ind_handler(ke_msg_id_t const msgid, + struct hogpd_ntf_cfg_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,v_idx;%x,p_idx;%x\r\n",__func__,app_hid_env.conidx,param->conidx); + if (app_hid_env.conidx == param->conidx) + { + if ((param->ntf_cfg[param->conidx] & HOGPD_CFG_REPORT_NTF_EN ) != 0) + { + // The device is ready to send reports to the peer device + app_hid_env.state = APP_HID_READY; + NS_LOG_INFO("HID Ready\r\n"); + } + else + { + // Come back to the Enabled state + if (app_hid_env.state == APP_HID_READY) + { + app_hid_env.state = APP_HID_ENABLED; + } + NS_LOG_DEBUG("HID enable\r\n"); + } + NS_LOG_DEBUG("ntf_cfg:0x%x\r\n",param->ntf_cfg[param->conidx]); + #if (NVDS_SUPPORT) + // Store the notification configuration in the database + if (nvds_put(NVDS_TAG_MOUSE_NTF_CFG, NVDS_LEN_MOUSE_NTF_CFG, + (uint8_t *)¶m->ntf_cfg[param->conidx]) != NVDS_OK) + { + // Should not happen + ASSERT_ERR(0); + } + #endif //(NVDS_SUPPORT) + } + + return (KE_MSG_CONSUMED); +} + +static int hogpd_report_req_ind_handler(ke_msg_id_t const msgid, + struct hogpd_report_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + if ((param->operation == HOGPD_OP_REPORT_READ) && (param->report.type == HOGPD_REPORT_MAP)) + { + struct hogpd_report_cfm *req = KE_MSG_ALLOC_DYN(HOGPD_REPORT_CFM, + src_id, + dest_id, + hogpd_report_cfm, + APP_HID_MOUSE_REPORT_MAP_LEN); + + req->conidx = app_hid_env.conidx; ///??? + /// Operation requested (read/write @see enum hogpd_op) + req->operation = HOGPD_OP_REPORT_READ; + /// Status of the request + req->status = GAP_ERR_NO_ERROR; ///??? + /// Report Info + //req->report; + /// HIDS Instance + req->report.hid_idx = param->report.hid_idx;/// ???///app_hid_env.conidx; ///??? + /// type of report (@see enum hogpd_report_type) + req->report.type = HOGPD_REPORT_MAP; + /// Report Length (uint8_t) + req->report.length = APP_HID_MOUSE_REPORT_MAP_LEN; + /// Report Instance - 0 for boot reports and report map + req->report.idx = 0; + /// Report data + memcpy(&req->report.value[0], &app_hid_mouse_report_map[0], APP_HID_MOUSE_REPORT_MAP_LEN); + + // Send the message + ke_msg_send(req); + } + else + { + if (param->report.type == HOGPD_BOOT_MOUSE_INPUT_REPORT) + { //request of boot mouse report + struct hogpd_report_cfm *req = KE_MSG_ALLOC_DYN(HOGPD_REPORT_CFM, + prf_get_task_from_id(TASK_ID_HOGPD),/* src_id */ + TASK_APP, + hogpd_report_cfm, + 0/*param->report.length*/); + + req->conidx = param->conidx; ///app_hid_env.conidx; ///??? + /// Operation requested (read/write @see enum hogpd_op) + req->operation = HOGPD_OP_REPORT_READ; + /// Status of the request + req->status = GAP_ERR_NO_ERROR; ///??? + /// HIDS Instance + req->report.hid_idx = app_hid_env.conidx; ///??? + /// type of report (@see enum hogpd_report_type) + req->report.type = param->report.type;//-1;//outside + /// Report Length (uint8_t) + req->report.length = 0; //param->report.length; + /// Report Instance - 0 for boot reports and report map + req->report.idx = param->report.idx; //0; + /// Report data + + // Send the message + ke_msg_send(req); + } + else + if (param->report.type == HOGPD_REPORT) + { //request of mouse report + struct hogpd_report_cfm *req = KE_MSG_ALLOC_DYN(HOGPD_REPORT_CFM, + prf_get_task_from_id(TASK_ID_HOGPD),/* src_id */ + TASK_APP, + hogpd_report_cfm, + 8/*param->report.length*/); + + req->conidx = param->conidx; ///app_hid_env.conidx; ///??? + /// Operation requested (read/write @see enum hogpd_op) + req->operation = HOGPD_OP_REPORT_READ; + /// Status of the request + req->status = GAP_ERR_NO_ERROR; ///??? + /// Report Info + //req->report; + /// HIDS Instance + req->report.hid_idx = app_hid_env.conidx; ///??? + /// type of report (@see enum hogpd_report_type) + req->report.type = param->report.type;//-1;//outside + /// Report Length (uint8_t) + req->report.length = 8; //param->report.length; + /// Report Instance - 0 for boot reports and report map + req->report.idx = param->report.idx; //0; + /// Report data + memset(&req->report.value[0], 0, 8); //??? + req->report.value[0] = param->report.hid_idx; /// HIDS Instance + req->report.value[1] = param->report.type; /// type of report (@see enum hogpd_report_type) + req->report.value[2] = param->report.length; /// Report Length (uint8_t) + req->report.value[3] = param->report.idx; /// Report Instance - 0 for boot reports and report map + + // Send the message + ke_msg_send(req); + } + else + { + struct hogpd_report_cfm *req = KE_MSG_ALLOC_DYN(HOGPD_REPORT_CFM, + prf_get_task_from_id(TASK_ID_HOGPD),/* src_id */ + TASK_APP, + hogpd_report_cfm, + 8/*param->report.length*/); + + req->conidx = param->conidx; ///app_hid_env.conidx; ///??? + /// Operation requested (read/write @see enum hogpd_op) + req->operation = HOGPD_OP_REPORT_READ; + /// Status of the request + req->status = GAP_ERR_NO_ERROR; ///??? + /// Report Info + //req->report; + /// HIDS Instance + req->report.hid_idx = app_hid_env.conidx; ///??? + /// type of report (@see enum hogpd_report_type) + req->report.type = param->report.type;//-1;//outside + /// Report Length (uint8_t) + req->report.length = 8; //param->report.length; + /// Report Instance - 0 for boot reports and report map + req->report.idx = param->report.idx; //0; + /// Report data + memset(&req->report.value[0], 0, 8); //??? + req->report.value[0] = param->report.hid_idx; /// HIDS Instance + req->report.value[1] = param->report.type; /// type of report (@see enum hogpd_report_type) + req->report.value[2] = param->report.length; /// Report Length (uint8_t) + req->report.value[3] = param->report.idx; /// Report Instance - 0 for boot reports and report map + + // Send the message + ke_msg_send(req); + } + } + + return (KE_MSG_CONSUMED); +} + +static int hogpd_proto_mode_req_ind_handler(ke_msg_id_t const msgid, + struct hogpd_proto_mode_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + if ((param->conidx == app_hid_env.conidx) && (param->operation == HOGPD_OP_PROT_UPDATE)) + { + + //make use of param->proto_mode + struct hogpd_proto_mode_cfm *req = KE_MSG_ALLOC_DYN(HOGPD_PROTO_MODE_CFM, + prf_get_task_from_id(TASK_ID_HOGPD),/* src_id */ + TASK_APP, + hogpd_proto_mode_cfm, + 0); + /// Connection Index + req->conidx = app_hid_env.conidx; + /// Status of the request + req->status = GAP_ERR_NO_ERROR; + /// HIDS Instance + req->hid_idx = app_hid_env.conidx; + /// New Protocol Mode Characteristic Value + req->proto_mode = param->proto_mode; + + + // Send the message + ke_msg_send(req); + } + else + { + struct hogpd_proto_mode_cfm *req = KE_MSG_ALLOC_DYN(HOGPD_PROTO_MODE_CFM, + prf_get_task_from_id(TASK_ID_HOGPD),/* src_id */ + TASK_APP, + hogpd_proto_mode_cfm, + 0); + /// Status of the request + req->status = ATT_ERR_APP_ERROR; + + /// Connection Index + req->conidx = app_hid_env.conidx; + /// HIDS Instance + req->hid_idx = app_hid_env.conidx; + /// New Protocol Mode Characteristic Value + req->proto_mode = param->proto_mode; + + // Send the message + ke_msg_send(req); + } + return (KE_MSG_CONSUMED); +} + + +static int hogpd_report_upd_handler(ke_msg_id_t const msgid, + struct hogpd_report_upd_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,status:%x \r\n",__func__,param->status); + if (app_hid_env.conidx == param->conidx) + { + if (GAP_ERR_NO_ERROR == param->status) + { + if (app_hid_env.nb_report < APP_HID_NB_SEND_REPORT) + { + app_hid_env.nb_report++; + } + + + } + else + { + // we get this message if error occur while sending report + // most likely - disconnect + // Go back to the ready state + app_hid_env.state = APP_HID_IDLE; + // change mode + // restart adv + // Try to restart advertising if needed +// app_update_adv_state(true); + + //report was not success - need to restart??? + } + } + return (KE_MSG_CONSUMED); +} + +static int hogpd_enable_rsp_handler(ke_msg_id_t const msgid, + struct hogpd_enable_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,idx %x,status %x\r\n",__func__,param->conidx,param->status); + return (KE_MSG_CONSUMED); +} + +/** + * @brief Function called when the APP_HID_MOUSE_TIMEOUT_TIMER expires. + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +int app_hid_mouse_timeout_timer_handler(ke_msg_id_t const msgid,void const *param) +{ + app_hid_env.timer_enabled = false; + NS_LOG_DEBUG("%s\r\n",__func__); + if (app_hid_env.state == APP_HID_READY) + { + // Requested connection parameters + struct gapc_conn_param conn_param; + // Timer value + uint16_t timer_val; + + /* + * Request an update of the connection parameters + * Requested connection interval: 10ms + * Latency: 200 + * Supervision Timeout: 5s + */ + conn_param.intv_min = 8; + conn_param.intv_max = 8; + conn_param.latency = 200; + conn_param.time_out = 500; + ns_ble_update_param(&conn_param); + + // Go to the Wait for Report state + app_hid_env.state = APP_HID_WAIT_REP; + + timer_val = APP_HID_SILENCE_DURATION_2; + + // Relaunch the timer + ke_timer_set(APP_HID_MOUSE_TIMEOUT_TIMER, TASK_APP, timer_val); + app_hid_env.timer_enabled = true; + } + else if (app_hid_env.state == APP_HID_WAIT_REP) + { + // Disconnect the link with the device + ns_ble_disconnect(); + + + // Go back to the ready state + app_hid_env.state = APP_HID_IDLE; + } + + return (KE_MSG_CONSUMED); +} + + + + + +/** + * @brief + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_hid_msg_dflt_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Drop the message + NS_LOG_DEBUG("%s\r\n",__func__); + return (KE_MSG_CONSUMED); +} + +/** + * @brief Set the value of the Report Map Characteristic in the database + */ +void app_hid_set_report_map(void); + +/* + * LOCAL VARIABLE DEFINITIONS + */ + +/// Default State handlers definition +const struct ke_msg_handler app_hid_msg_handler_list[] = +{ + // Note: first message is latest message checked by kernel so default is put on top. + {KE_MSG_DEFAULT_HANDLER, (ke_msg_func_t)app_hid_msg_dflt_handler}, + + {HOGPD_ENABLE_RSP, (ke_msg_func_t)hogpd_enable_rsp_handler}, + {HOGPD_NTF_CFG_IND, (ke_msg_func_t)hogpd_ntf_cfg_ind_handler}, + {HOGPD_REPORT_REQ_IND, (ke_msg_func_t)hogpd_report_req_ind_handler}, + {HOGPD_PROTO_MODE_REQ_IND, (ke_msg_func_t)hogpd_proto_mode_req_ind_handler}, + {HOGPD_CTNL_PT_IND, (ke_msg_func_t)hogpd_ctnl_pt_ind_handler}, + {HOGPD_REPORT_UPD_RSP, (ke_msg_func_t)hogpd_report_upd_handler}, + +}; + +const struct app_subtask_handlers app_hid_handlers = APP_HANDLERS(app_hid); + +#endif //(BLE_APP_HID) + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/main.c new file mode 100644 index 0000000..946ff0d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/hid_mouse/src/main.c @@ -0,0 +1,142 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_gpio.h" +#include "app_ble.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING HID mouse demo \r\n" +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + app_key_configuration(); + LedInit(LED1_PORT, LED1_PIN); //power led + LedInit(LED2_PORT, LED2_PIN); //connection state + LedOn(LED1_PORT, LED1_PIN); + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + +} + + + +/** + * @} + */ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/MDK-ARM/lesc&aes.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/MDK-ARM/lesc&aes.uvoptx new file mode 100644 index 0000000..1f681cd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/MDK-ARM/lesc&aes.uvoptx @@ -0,0 +1,1276 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + ARMRTXEVENTFLAGS + -L70 -Z18 -C0 -M0 -T1 + + + 0 + DLGTARM + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0) + + + 0 + ARMDBGFLAGS + + + + 0 + DLGUARM + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + + 0 + 1 + cbc_output + + + + 0 + + + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + OTA_IMG_1 + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 0 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + + + + + + + + + + + BIN\UL2CM3.DLL + + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + OTA_IMG_2 + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 0 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + + + + + + + + + + + BIN\UL2CM3.DLL + + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + 4 + 17 + 4 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + n32wb03x_host_lib.lib + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + bass.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + bass_task.c + 0 + 0 + + + 5 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + rdtss.c + 0 + 0 + + + 5 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + rdtss_task.c + 0 + 0 + + + 5 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + rdts_common.c + 0 + 0 + + + 5 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + ns_iuss.c + 0 + 0 + + + 5 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + ns_iuss_task.c + 0 + 0 + + + + + NS_DFU + 0 + 0 + 0 + 0 + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_crc.c + dfu_crc.c + 0 + 0 + + + 6 + 30 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_delay.c + dfu_delay.c + 0 + 0 + + + 6 + 31 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_led.c + dfu_led.c + 0 + 0 + + + 6 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + ns_dfu_ble.c + 0 + 0 + + + 6 + 33 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + ns_dfu_boot.c + 0 + 0 + + + + + Crypto + 0 + 0 + 0 + 0 + + 7 + 34 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + ns_ecc.c + 0 + 0 + + + 7 + 35 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + sha256.c + 0 + 0 + + + 7 + 36 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + uECC.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 8 + 37 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 8 + 38 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 8 + 39 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 8 + 40 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 8 + 41 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 8 + 42 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 8 + 43 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 9 + 44 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 9 + 45 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_batt.c + app_batt.c + 0 + 0 + + + 9 + 46 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtss.c + app_rdtss.c + 0 + 0 + + + 9 + 47 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_ns_ius.c + app_ns_ius.c + 0 + 0 + + + 9 + 48 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 10 + 49 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 10 + 50 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + 10 + 51 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 11 + 52 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 12 + 53 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + + + AES + 0 + 0 + 0 + 0 + + 13 + 54 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\aes_cbc.c + aes_cbc.c + 0 + 0 + + + 13 + 55 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\aes_ccm.c + aes_ccm.c + 0 + 0 + + + 13 + 56 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\ns_aes.c + ns_aes.c + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/MDK-ARM/lesc&aes.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/MDK-ARM/lesc&aes.uvprojx new file mode 100644 index 0000000..61b4c54 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/MDK-ARM/lesc&aes.uvprojx @@ -0,0 +1,2697 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + lesc_aes + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\lesc_aes.bin .\Objects\lesc_aes.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 5 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15_central.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + n32wb03x_host_lib.lib + 4 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + + + NS_DFU + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + AES + + + aes_cbc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\aes_cbc.c + + + aes_ccm.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\aes_ccm.c + + + ns_aes.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\ns_aes.c + + + + + + + OTA_IMG_1 + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtss_ota + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\rdtss_ota.bin .\Objects\rdtss_ota.axf + cmd.exe /C copy .\bin\rdtss_ota.bin ..\..\..\..\..\utilities\dfu\Image\APP1.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1004000 + 0x1c000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, APPLICATION, BLE_OTA_ENABLE + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\dfu\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15_central.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + n32wb03x_host_lib.lib + 4 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + + + NS_DFU + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + AES + + + aes_cbc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\aes_cbc.c + + + aes_ccm.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\aes_ccm.c + + + ns_aes.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\ns_aes.c + + + + + + + OTA_IMG_2 + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtss_ota + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\rdtss_ota.bin .\Objects\rdtss_ota.axf + cmd.exe /C copy .\bin\rdtss_ota.bin ..\..\..\..\..\utilities\dfu\Image\APP2.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1020000 + 0x1c000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, APPLICATION, BLE_OTA_ENABLE + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\dfu\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15_central.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + n32wb03x_host_lib.lib + 4 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + + + NS_DFU + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + AES + + + aes_cbc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\aes_cbc.c + + + aes_ccm.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\aes_ccm.c + + + ns_aes.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\aes\ns_aes.c + + + + + + + + + + + + + RTE\Compiler\EventRecorderConf.h + + + + + + + + + + + AES + 1 + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_ble.h new file mode 100644 index 0000000..0d16f44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_batt.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_batt.h new file mode 100644 index 0000000..5fc237b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_batt.h @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef APP_BATT_H_ +#define APP_BATT_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include // Standard Integer Definition +#include "ke_task.h" // Kernel Task Definition + +/* Public typedef -----------------------------------------------------------*/ + +/// Battery Application Module Environment Structure +struct app_batt_env_tag +{ + /// Connection handle + uint8_t conidx; + /// Current Battery Level + uint8_t batt_lvl; +}; + +/* Public variables ---------------------------------------------------------*/ + +/// Battery Application environment +extern struct app_batt_env_tag app_batt_env; + +/// Table of message handlers +extern const struct app_subtask_handlers app_batt_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * + * Health Thermometer Application Functions + * + **/ + +/** + * @brief Initialize Battery Application Module + **/ +void app_batt_init(void); + +/** + * @brief Add a Battery Service instance in the DB + **/ +void app_batt_add_bas(void); + +/** + * @brief Enable the Battery Service + **/ +void app_batt_enable_prf(uint8_t conidx); + +/** + * @brief Send a Battery level value + **/ +void app_batt_send_lvl(uint8_t batt_lvl); + +#endif //(BLE_APP_BATT) + +/// @} APP + +#endif // APP_BATT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_ns_ius.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_ns_ius.h new file mode 100644 index 0000000..726f13b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_ns_ius.h @@ -0,0 +1,105 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ns_ius.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef __APP_NS_IUS_H__ +#define __APP_NS_IUS_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#include "prf_types.h" +#include "prf.h" + + +#if (BLE_APP_NS_IUS) +/* Public typedef -----------------------------------------------------------*/ +enum +{ + NS_IUS_IDX_SVC, + + NS_IUS_IDX_RC_CHAR, + NS_IUS_IDX_RC_VAL, + NS_IUS_IDX_RC_CFG, + + NS_IUS_IDX_CC_CHAR, + NS_IUS_IDX_CC_VAL, + NS_IUS_IDX_CC_CFG, + + NS_IUS_IDX_NB, +}; + +/* Public define ------------------------------------------------------------*/ +#define SERVICE_NS_IUS {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, 0x01,0x00, 0x11,0x11} +#define CHAR_NS_IUS_RC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x02,0x00, 0x11,0x11} +#define CHAR_NS_IUS_CC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x03,0x00, 0x11,0x11} + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ +extern struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB]; +/* Public function prototypes -----------------------------------------------*/ +extern const struct app_subtask_handlers ns_ius_app_handlers; + +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length); +void app_ns_ius_add_ns_ius(void); +void app_ns_ius_init(void); + +#endif //BLE_APP_NS_IUS + +#endif //__APP_NS_IUS_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_rdtss.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_rdtss.h new file mode 100644 index 0000000..b875e05 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/app_rdtss.h @@ -0,0 +1,121 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSS_H_ +#define APP_RDTSS_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/// Manufacturer Name Value +#define APP_RDTSS_MANUFACTURER_NAME ("NSING") +#define APP_RDTSS_MANUFACTURER_NAME_LEN (5) + + + +#define ATT_SERVICE_AM_SPEED_128 {0x01,0x10,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Service UUID */ +#define ATT_CHAR_AM_SPEED_WRITE_128 {0x01,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_NTF_128 {0x02,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ + + +/// rdtss Service Attributes Indexes +enum +{ + RDTSS_IDX_SVC, + + RDTSS_IDX_WRITE_CHAR, + RDTSS_IDX_WRITE_VAL, + RDTSS_IDX_WRITE_CFG, + + RDTSS_IDX_NTF_CHAR, + RDTSS_IDX_NTF_VAL, + RDTSS_IDX_NTF_CFG, + + RDTSS_IDX_NB, +}; + + +/** + * @brief Initialize Device Information Service Application + **/ +void app_rdtss_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_rdtss_add_rdts(void); + +void rdtss_send_notify(uint8_t *data, uint16_t length); + + +#endif //BLE_RDTSS_SERVER + +/// @} APP + +#endif // APP_RDTSS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_usart.h new file mode 100644 index 0000000..754d7e9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_usart.h @@ -0,0 +1,152 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTx_DAT_Base (USART1_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART1_RX +#define USARTx_IRQn USART1_IRQn +#define USARTx_IRQHandler USART1_IRQHandler +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define USARTx_DAT_Base (USART2_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#define USARTx_IRQn USART2_IRQn +#define USARTx_IRQHandler USART2_IRQHandler +#endif + + +#define USART_RX_DMA_SIZE 256 +#define USART_RX_FIFO_SIZE 1000 +#define USART_TX_FIFO_SIZE 1000 + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + +/* Public function prototypes -----------------------------------------------*/ + +void app_usart_configuration(void); +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len); +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len); +void app_usart_tx_data_blocking(uint8_t *p_data, uint16_t len); + +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len); +void usart_forward_to_ble_loop(void); +void app_usart_dma_enable(FunctionalState Cmd); +void app_usart_tx_process(void); +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_user_config.h new file mode 100644 index 0000000..f994f7f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/inc/app_user_config.h @@ -0,0 +1,151 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_LESC" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 0//30 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + +// Advertise data +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_DEVICE_INFORMATION_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (5000) /**< Time of initiating event to update connection params (5 seconds). */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_DISPLAY_ONLY /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 1 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_IDKEY /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_SEC1_SEC_CON_PAIR_ENC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 1 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +//LESC +#define CFG_ECCH (1) +#define BLE_APP_SEC_CON (1) +#define _PATCH_ENC_RESPONDSE_ (1) + +#define AES_DECRYPT_ENABLE (1) + +/* profiles config */ +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +//#define CFG_APP_BATT 1 +//#define CFG_PRF_BASS 1 +#define CFG_PRF_RDTSS 1 + +#ifdef BLE_OTA_ENABLE +#define CFG_APP_NS_IUS 1 +#endif + +/* User config */ + +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 1 + +#define NS_TIMER_ENABLE 1 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + + + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/readme.txt new file mode 100644 index 0000000..99d80a1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/readme.txt @@ -0,0 +1,58 @@ + +1. Function description + + Bluetooth Secure Connection and AES routine, user can connect this demo with PIN code "123456" in LESC mode. + The AES demo task will run ECB, CBC and CCM test, and keep repeating the CBC test every second. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB1(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 4. Bluetooth BLE name: NS_LESC + 5. LED1 lights up when it is turned on, LED2 indicates the connection status, and lights up when Bluetooth is connected + 6. BLE Data: USART1 PB6(TX) and PB7(RX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + usage method: + 1. Burn to development board after compilation + 2. Power on development board and check the log. + 3. Connect the master device, pair and bond the device with PIN code "123456", send data via USART1 each other. + 4. change the log of AES test. + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. + + +5. Cover a slave project to using LESC pairing. + 1. add n32wb03x_host.lib file. + 2. change symbol_g15.obj to symbol_g15_central.obj in Misc control. (change for all target) + 3. remove lib_att.c. + 4. set define as below: + #define BOND_STORE_ENABLE 1 + #define SEC_PARAM_LESC 1 + #define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_DISPLAY_ONLY + #define SEC_PARAM_IKEY GAP_KDIST_IDKEY + 5. add define as below: + #define CFG_ECCH (1) + #define BLE_APP_SEC_CON (1) + 6. save LTK at gapc_bond_ind_handler -> GAPC_LTK_EXCH. (1.3.2 alread changed) + 7. change NO_AUTH change to SEC_CON at app_rdtss_add_rdts. + 8. input PINGCODE "123456" when pairing. + + +6. firmware authentication feature test step: + 1. Define ENABLE_FIRMWARE_AUTH in project preprocessor. + 2. Build and program firmware in development board A, it run as expect and printf demo string on PB1 . + 3. Read firmware from firmware in development board A (run utilities\dfu\JLink\ReadAll.bat). + 4. Flash all All.bin to development board B, it will not able to run as expect and printf the demo string. + 5. erase and program the All.bin into development board A, it will run as expect and printf demo string. + \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_ble.c new file mode 100644 index 0000000..bfc334e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_ble.c @@ -0,0 +1,570 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "ns_sec.h" +#include "app_ble.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_rdtss.h" +#include "app_dis.h" +#include "app_batt.h" +#include "ns_timer.h" +#include "ns_aes.h" +#if (BLE_APP_NS_IUS) +#include "app_ns_ius.h" +#endif //BLE_APP_NS_IUS +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static uint8_t cipher = 1; +#define DATA_BLOCK 5 +uint8_t test_input [DATA_BLOCK][16] = {0} ; +uint8_t test_cipher[DATA_BLOCK][16] = {0} ; +uint8_t test_plain [DATA_BLOCK][16] = {0} ; + +#define CCM_MIC_LEN 16 +uint8_t key[16] = {"0123456789abcdef"}; +uint8_t nonce[13] = {"0000111122223"}; +uint8_t add_auth_data[2] = {"12"}; +uint8_t iv[16] = {"1111222233334444"}; + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +#define AES_LOG NS_LOG_DEBUG // uart ouput all AES test data will block BLE pairing +/** + * @brief output data in HEX format + * @param + * @return + * @note Note + */ +void print_text(uint8_t *data, uint32_t len) +{ + for(int i=0;i0)) AES_LOG("\r\n"); + AES_LOG("%02X ",data[i]); + } + AES_LOG("\r\n"); +} + + + +void app_aes_ccm_cb(bool mic_error, uint32_t src_info) +{ + + if(cipher == 1) + { + AES_LOG("ccm plain: \r\n"); + print_text(test_plain[0],16*(DATA_BLOCK-1)); + + if(mic_error) + { + NS_LOG_INFO("Tag(mic) authentication fail!\r\n"); + } + else{ + NS_LOG_INFO("Tag(mic) authentication pass!\r\n"); + } + if(memcmp(test_input,test_plain,16*(DATA_BLOCK-1)) == 0) + { + NS_LOG_INFO("CCM data decrypt pass!\r\n"); + } + else{ + NS_LOG_INFO("CCM data decrypt fail!\r\n"); + } + + + } + else{ + AES_LOG("ccm cipher: \r\n"); + print_text(test_cipher[0],16*(DATA_BLOCK-1)); + + AES_LOG("Tag(mic): \r\n"); + print_text(test_cipher[DATA_BLOCK-1],CCM_MIC_LEN); + + #ifdef USE_ERROR_MIC_TO_DECIPHER + // change mic to decipher, then the mic_error set flag when decipher + test_cipher[DATA_BLOCK-1][0] = 0; + #endif + } +} + +void app_aes_ccm_demo(void) +{ + static uint8_t key_lsb[AES_BLOCK_SIZE]; + if(cipher) + { + cipher = 0; + uint8_t *p = test_input[0]; + for(uint8_t i=0;i<16*DATA_BLOCK;i++) + { + p[i] = rand(); + } + NS_LOG_INFO("\r\n\r\nAES CCM Test Demo\r\n"); + AES_LOG("key: "); + print_text(key,16); + AES_LOG("nonce: "); + print_text(nonce,13); + AES_LOG("add_auth_data: "); + print_text(add_auth_data,2); + + AES_LOG("input_text: \r\n"); + print_text(test_input[0],16*(DATA_BLOCK-1)); + + ns_ase_swap_array(key_lsb,key,AES_BLOCK_SIZE); + ns_aes_ccm(key_lsb, nonce, test_input[0], test_cipher[0], 16*(DATA_BLOCK-1), CCM_MIC_LEN , true, add_auth_data, 2, app_aes_ccm_cb, 0); + + //do the decrypt 2ms later + ns_timer_create(5,app_aes_ccm_demo); + } + else{ + ns_ase_swap_array(key_lsb,key,AES_BLOCK_SIZE); + ns_aes_ccm(key_lsb, nonce, test_cipher[0], test_plain[0], 16*(DATA_BLOCK-1), CCM_MIC_LEN , false, add_auth_data, 2, app_aes_ccm_cb, 0); + cipher = 1; + //repeat cbc encrypt test 1000ms later +// ns_timer_create(1000,app_aes_ccm_demo); + } +} + + + +void app_aes_cbc_cb(uint8_t status, const uint8_t* aes_res, uint32_t src_info) +{ + if(src_info == DECRYPT_SRC_MARK) + { + AES_LOG("cbc_plain: \r\n"); + print_text(test_plain[0],16*DATA_BLOCK); + if(memcmp(test_input,test_plain,16*DATA_BLOCK) == 0) + { + NS_LOG_INFO("CBC encrypt and decrypt pass!\r\n"); + } + else{ + NS_LOG_INFO("CBC encrypt and decrypt fail!\r\n"); + } + } + else{ + AES_LOG("cbc_cipher: \r\n"); + print_text(test_cipher[0],16*DATA_BLOCK); + } +} + + +void app_aes_cbc_demo(void) +{ + if(cipher) + { + cipher = 0; + uint8_t *p = test_input[0]; + for(uint8_t i=0;i<16*DATA_BLOCK;i++) + { + p[i] = rand(); + } + NS_LOG_INFO("\r\n\r\nAES CBC Test Demo\r\n"); + AES_LOG("key: "); + print_text(key,16); + AES_LOG("iv: "); + print_text(iv,16); + + AES_LOG("input_text: \r\n"); + print_text(test_input[0],16*DATA_BLOCK); + + ns_aes_cbc(key, iv, test_input[0],test_cipher[0],true, 16*DATA_BLOCK, app_aes_cbc_cb); + + //do the decrypt 2ms later + ns_timer_create(5,app_aes_cbc_demo); + } + else{ + ns_aes_cbc(key, iv, test_cipher[0],test_plain[0],false, 16*DATA_BLOCK, app_aes_cbc_cb); + cipher = 1; + //repeat cbc encrypt test 1000ms later + ns_timer_create(1000,app_aes_cbc_demo); + } +} + + + +void app_aes_result_cb(uint8_t status, const uint8_t* aes_res, uint32_t src_info) +{ + if(src_info == DECRYPT_SRC_MARK ) //decrypt + { + memcpy(test_plain[0],aes_res,16); + AES_LOG("plaintext : "); + print_text(test_plain[0],16); + if(memcmp(test_input[0],test_plain[0],16) == 0) + { + NS_LOG_INFO("AES encrypt and decrypt pass!\r\n"); + } + else{ + NS_LOG_INFO("AES encrypt and decrypt fail!\r\n"); + } + } + else{ + memcpy(test_cipher[0],aes_res,16); + AES_LOG("ciphertext: "); + print_text(test_cipher[0],16); + } +} + +/** + * @brief aes example fucntion + * @param + * @return + * @note Note + */ +void ase_test_demo(void) +{ + if(cipher) + { + NS_LOG_INFO("\r\n\r\nAES Test Demo\r\n"); + AES_LOG("128bit key: "); + print_text(key,16); + uint8_t *p_in = test_input[0]; + for(uint8_t i=0;i<16;i++) + { + p_in[i] = rand(); + } + AES_LOG("randString: "); + print_text(p_in,16); + + ns_aes_ciphering(key,p_in,app_aes_result_cb); + cipher = 0; + + //do the decrypt 2ms later + ns_timer_create(2,ase_test_demo); + } + else{ + cipher = 1; + + ns_aes_deciphering(key,test_cipher[0], app_aes_result_cb); + //repeat +// ns_timer_create(500,ase_test_demo); + } +} + + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_CUSTS_TEST_EVT: + app_usart_tx_process(); + break; +// case : +// break; + default: + break; + } +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + ns_timer_create(10,ase_test_demo); + ns_timer_create(1000,app_aes_cbc_demo); + ns_timer_create(2000,app_aes_ccm_demo); + break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + #if (BLE_APP_DIS) + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); + #endif //BLE_APP_DIS + #if (BLE_APP_BATT) + //add battery level server + ns_ble_add_prf_func_register(app_batt_add_bas); + #endif //BLE_APP_BATT + #if (BLE_APP_NS_IUS) + ns_ble_add_prf_func_register(app_ns_ius_add_ns_ius); + #endif //BLE_APP_NS_IUS + + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtss_add_rdts); + + + +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + //enable usart receive + app_usart_dma_enable(ENABLE); + LedOn(LED2_PORT,LED2_PIN); + + #if (BLE_APP_BATT) + // Enable Battery Service + app_batt_enable_prf(app_env.conidx); + #endif //(BLE_APP_BATT) +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising + ns_ble_adv_start(); + + //disable usart receive + app_usart_dma_enable(DISABLE); + LedOff(LED2_PORT,LED2_PIN); +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_batt.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_batt.c new file mode 100644 index 0000000..4b650ba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_batt.c @@ -0,0 +1,257 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +/** + * @addtogroup APP + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include "app_batt.h" // Battery Application Module Definitions +#include "ns_ble.h" // Application Definitions +#include "ns_ble_task.h" // application task definitions +#include "bass_task.h" // health thermometer functions +#include "co_bt.h" +#include "bass.h" +#include "prf_types.h" // Profile common types definition +#include "arch.h" // Platform Definitions +#include "prf.h" +#include + +/* Private define ------------------------------------------------------------*/ +/// Battery Application Module Environment Structure +struct app_batt_env_tag app_batt_env; + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief bat server init + * @param + * @return + * @note + */ +void app_batt_init(void) +{ + // Reset the environment + memset(&app_batt_env, 0, sizeof(struct app_batt_env_tag)); + + // Initial battery level: 100 + app_batt_env.batt_lvl = 100; + + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_BASS; + prf.prf_task_handler = &app_batt_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_BASS; + get_func.prf_itf_get_func = bass_prf_itf_get; + prf_get_itf_func_register(&get_func); + +} + +/** + * @brief add bat server + * @param + * @return + * @note + */ +void app_batt_add_bas(void) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + struct bass_db_cfg* db_cfg; + // Allocate the BASS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct bass_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_BASS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct bass_db_cfg* ) req->param; + + // Add a BAS instance + db_cfg->bas_nb = 1; + // Sending of notifications is supported + db_cfg->features[0] = BAS_BATT_LVL_NTF_SUP; + + // Send the message + ke_msg_send(req); + + app_batt_init(); +} + +/** + * @brief enable batt server profile + * @param + * @return + * @note + */ +void app_batt_enable_prf(uint8_t conidx) +{ + app_batt_env.conidx = conidx; + + // Allocate the message + struct bass_enable_req * req = KE_MSG_ALLOC(BASS_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + + // NTF initial status - Disabled + req->ntf_cfg = PRF_CLI_STOP_NTFIND; + req->old_batt_lvl[0] = 50; + + // Send the message + ke_msg_send(req); +} + +/** + * @brief send battery level + * @param + * @return + * @note + */ +void app_batt_send_lvl(uint8_t batt_lvl) +{ + ASSERT_ERR(batt_lvl <= BAS_BATTERY_LVL_MAX); + + // Allocate the message + struct bass_batt_level_upd_req * req = KE_MSG_ALLOC(BASS_BATT_LEVEL_UPD_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_batt_level_upd_req); + + // Fill in the parameter structure + req->bas_instance = 0; + req->batt_level = batt_lvl; + + // Send the message + ke_msg_send(req); +} + +static int bass_batt_level_ntf_cfg_ind_handler(ke_msg_id_t const msgid, + struct bass_batt_level_ntf_cfg_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +static int batt_level_upd_handler(ke_msg_id_t const msgid, + struct bass_batt_level_upd_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +/** + * @brief + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_batt_msg_dflt_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Drop the message + + return (KE_MSG_CONSUMED); +} + +/* + * LOCAL VARIABLE DEFINITIONS + */ + +/// Default State handlers definition +const struct ke_msg_handler app_batt_msg_handler_list[] = +{ + // Note: first message is latest message checked by kernel so default is put on top. + {KE_MSG_DEFAULT_HANDLER, (ke_msg_func_t)app_batt_msg_dflt_handler}, + + {BASS_BATT_LEVEL_NTF_CFG_IND, (ke_msg_func_t)bass_batt_level_ntf_cfg_ind_handler}, + {BASS_BATT_LEVEL_UPD_RSP, (ke_msg_func_t)batt_level_upd_handler}, +}; + +const struct app_subtask_handlers app_batt_handlers = APP_HANDLERS(app_batt); + +#endif //BLE_APP_BATT + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_ns_ius.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_ns_ius.c new file mode 100644 index 0000000..1846f9b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_ns_ius.c @@ -0,0 +1,248 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ns_ius.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_NS_IUS) + +#include "app_ns_ius.h" +#include +#include "ns_iuss.h" +#include "ns_iuss_task.h" +#include "ns_dfu_ble.h" +#include "attm.h" +#include "ke_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "gattc_task.h" +#include "attm_db.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" +#include "ke_msg.h" +#include "ns_ble.h" +#include "ns_log.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB] = +{ + [NS_IUS_IDX_SVC] = {{0x00,0x28}, PERM(RD, ENABLE),0,0}, + + [NS_IUS_IDX_RC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE),0, 0}, + [NS_IUS_IDX_RC_VAL] = {CHAR_NS_IUS_RC, PERM(WRITE_COMMAND, ENABLE), PERM_VAL(UUID_LEN, 0x02), 247}, + [NS_IUS_IDX_RC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + [NS_IUS_IDX_CC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + [NS_IUS_IDX_CC_VAL] = {CHAR_NS_IUS_CC, PERM(WRITE_REQ, ENABLE) | PERM(NTF, ENABLE) , PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 20 }, + [NS_IUS_IDX_CC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + + + + + +static bool notification_enable = false; + + + + + +static int ns_ius_val_write_ind_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + const struct ns_ius_val_write_ind *p_param = (const struct ns_ius_val_write_ind *)param; + + switch (p_param->handle) + { + case NS_IUS_IDX_CC_CFG:{ + + if(p_param->length == 2) + { + uint16_t cfg_value = p_param->value[0] + p_param->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + notification_enable = true; + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + notification_enable = false; + } + NS_LOG_DEBUG("notification_enable %d\r\n",notification_enable); + } + + }break; + + + case NS_IUS_IDX_CC_VAL:{ + uint8_t output[20]; + uint8_t output_len = 0; + ns_dfu_ble_handler_cc(p_param->value, p_param->length, output, &output_len); + if(output_len)ns_ble_ius_app_cc_send(output, output_len); + }break; + + case NS_IUS_IDX_RC_VAL:{ + ns_dfu_ble_handler_rc(p_param->value, p_param->length); + }break; + default: + break; + + } + + return KE_MSG_CONSUMED; +} + + + +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length) +{ + uint8_t state = ke_state_get(ns_ble_ius_task); + if (state == NS_IUS_BUSY || notification_enable == false) + { + return; + } + ke_state_set(ns_ble_ius_task, NS_IUS_BUSY); + + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + struct gattc_send_evt_cmd * req = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, KE_BUILD_ID(TASK_GATTC, app_env.conidx), ns_ius_env->prf_env.prf_task, gattc_send_evt_cmd, length); + req->operation = GATTC_NOTIFY; + req->handle = ns_ius_env->shdl + NS_IUS_IDX_CC_VAL; + req->length = length; + memcpy(req->value, p_data, length); + ke_msg_send(req); +} + + + +static int ns_ius_disconnect_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + notification_enable = false; + return KE_MSG_CONSUMED; +} + + +const struct ke_msg_handler ns_ius_app_msg_handler_list[] = +{ + {NS_IUS_VAL_WRITE_IND, ns_ius_val_write_ind_handler}, + {NS_IUS_DISCONNECT, ns_ius_disconnect_handler}, +}; + + +const struct app_subtask_handlers ns_ius_app_handlers = APP_HANDLERS(ns_ius_app); + + + + + + + +void app_ns_ius_add_ns_ius(void) +{ + Qflash_Init(); + + struct ns_ius_db_cfg *db_cfg; + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct ns_ius_db_cfg)); + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_NS_IUS; + req->app_task = TASK_APP; + req->start_hdl = 0; + db_cfg = (struct ns_ius_db_cfg *) req->param; + db_cfg->att_tbl = NULL; + db_cfg->cfg_flag = 0; + db_cfg->features = 0; + ke_msg_send(req); + + app_ns_ius_init(); +} + +void app_ns_ius_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_NS_IUS; + prf.prf_task_handler = &ns_ius_app_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_NS_IUS; + get_func.prf_itf_get_func = ns_ius_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + + +#endif //BLE_APP_NS_IUS + + +/// @} APP + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_rdtss.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_rdtss.c new file mode 100644 index 0000000..9fae64a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_profile/app_rdtss.c @@ -0,0 +1,306 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtss.h" // rdtss Application Module Definitions +#include "rdtss_task.h" // Device Information Profile Functions +#include "gapm_task.h" // GAP Manager Task API +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" +#include "stdio.h" +#include "rdtss.h" +#include "app_usart.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +const uint8_t app_rdts_svc_uuid[16] = ATT_SERVICE_AM_SPEED_128; +const struct attm_desc_128 app_rdts_att_db[RDTSS_IDX_NB] = +{ + /* Service Declaration */ + [0] = {{0x00,0x28}, PERM(RD, ENABLE), 0, 0 }, + + /* Characteristic Declaration */ + [1] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [2] = {ATT_CHAR_AM_SPEED_WRITE_128, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [3] = {{0x01,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + /* Characteristic Declaration */ + [4] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [5] = {ATT_CHAR_AM_SPEED_NTF_128, PERM(NTF, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [6] = {{0x02,0x29}, PERM(RD, ENABLE) |PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, +}; + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtss_add_rdts(void) +{ + struct rdtss_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtss_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, SEC_CON); + req->prf_task_id = TASK_ID_RDTSS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtss_db_cfg *) req->param; + // Attribute table. In case the handle offset needs to be saved + db_cfg->att_tbl = &app_rdts_att_db[0]; + db_cfg->svc_uuid = &app_rdts_svc_uuid[0]; + db_cfg->max_nb_att = RDTSS_IDX_NB; + + // Send the message + ke_msg_send(req); + + app_rdtss_init(); +} + +/** + * @brief rdtss value require indicate handler + * @param + * @return + * @note Note + */ +static int rdtss_value_req_ind_handler(ke_msg_id_t const msgid, + struct rdtss_value_req_ind const *req_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + len = APP_RDTSS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_RDTSS_MANUFACTURER_NAME; + + + // Allocate confirmation to send the value + struct rdtss_value_req_rsp *rsp_value = KE_MSG_ALLOC_DYN(RDTSS_VALUE_REQ_RSP, + src_id, dest_id, + rdtss_value_req_rsp, + len); + rsp_value->status = 0; + rsp_value->conidx = req_value ->conidx; + rsp_value->length = len; + rsp_value->att_idx = req_value->att_idx; + if (len) + { + // Copy data + memcpy(&rsp_value->value, data, len); + } + // Send message + ke_msg_send(rsp_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief cuusts write indicate handler + * @param + * @return + * @note + */ +static int rdtss_val_write_ind_handler(ke_msg_id_t const msgid, + struct rdtss_val_write_ind const *ind_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,write handle = %x,length = %x\r\n",__func__ ,ind_value->handle, ind_value->length); + + for(uint16_t i=0; ilength; i++) + { + NS_LOG_DEBUG("%x ",ind_value->value[i]); + } + NS_LOG_DEBUG("\r\n"); + + uint16_t handle = ind_value->handle; + uint16_t length = ind_value->length; + + switch (handle) + { + case RDTSS_IDX_NTF_CFG: + + if(length == 2) + { + uint16_t cfg_value = ind_value->value[0] + ind_value->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + //enabled notify + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + } + } + + break; + case RDTSS_IDX_WRITE_VAL: + //ble data receive + app_usart_tx_fifo_enter(ind_value->value,ind_value->length); + + break; + default: + break; + + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Functions + * @param + * @return + * @note Note + */ +static int rdtss_val_ntf_cfm_handler(ke_msg_id_t const msgid, + struct rdtss_val_ntf_cfm const *cfm_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,ntf cfm handle = %x, status = %x\r\n",__func__, cfm_value->handle, cfm_value->status); + + usart_forward_to_ble_loop(); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief rdtss send notify + * @param + * @return + * @note + */ +void rdtss_send_notify(uint8_t *data, uint16_t length) +{ + struct rdtss_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(RDTSS_VAL_NTF_REQ, + prf_get_task_from_id(TASK_ID_RDTSS), + TASK_APP, + rdtss_val_ntf_ind_req, + length); + + req->conidx = app_env.conidx; + req->notification = true; + req->handle = RDTSS_IDX_NTF_VAL; + req->length = length; + memcpy(&req->value[0], data, length); + + ke_msg_send(req); +} + + +/// Default State handlers definition +const struct ke_msg_handler app_rdtss_msg_handler_list[] = +{ + {RDTSS_VALUE_REQ_IND, (ke_msg_func_t)rdtss_value_req_ind_handler}, + {RDTSS_VAL_WRITE_IND, (ke_msg_func_t)rdtss_val_write_ind_handler}, + {RDTSS_VAL_NTF_CFM, (ke_msg_func_t)rdtss_val_ntf_cfm_handler}, + +}; + +const struct app_subtask_handlers app_rdtss_handlers = APP_HANDLERS(app_rdtss); + + +void app_rdtss_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSS; + prf.prf_task_handler = &app_rdtss_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSS; + get_func.prf_itf_get_func = rdtss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +#endif //BLE_RDTSS_SERVER diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_usart.c new file mode 100644 index 0000000..9ac8195 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/app_usart.c @@ -0,0 +1,566 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include +#include "global_func.h" +#include "app_usart.h" +#include "app_rdtss.h" +#include "ns_sleep.h" +#include "ns_log.h" +#include "ns_timer.h" +#include "ke_timer.h" +#include "app_ble.h" +#include "rdtss_task.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] = {0}; +uint16_t rx_old_pos = 0; + +uint8_t usart_rx_fifo_buf[USART_RX_FIFO_SIZE] = {0}; +uint32_t usart_rx_fifo_in = 0; +uint32_t usart_rx_fifo_out = 0; + + +uint8_t usart_tx_fifo_buf[USART_TX_FIFO_SIZE] = {0}; +uint32_t usart_tx_fifo_in = 0; +uint32_t usart_tx_fifo_out = 0; + +uint8_t usart_sending = false; +uint8_t ble_sending = false; +uint16_t ble_att_mtu = (ATT_DEFAULT_MTU-3); + +/* Private function prototypes -----------------------------------------------*/ +void app_usart_tx_process(void); + +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTx_Tx_DMA_Channel); + DMA_RequestRemap(USARTx_Tx_DMA_REMAP, DMA, USARTx_Tx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Tx_DMA_Channel,DMA_INT_TXC ,ENABLE); + + /* USARTx RX DMA1 Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTx_Rx_DMA_Channel); + DMA_RequestRemap(USARTx_Rx_DMA_REMAP, DMA, USARTx_Rx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Rx_DMA_Channel,DMA_INT_TXC|DMA_INT_HTX ,ENABLE); + + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)USART_rx_dma_buf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = USART_RX_DMA_SIZE; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Rx_DMA_Channel, &DMA_InitStructure); + +} + + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + NVIC_DisableIRQ(DMA_Channel1_2_3_4_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + + NVIC_DisableIRQ(USARTx_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void app_usart_configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* Configure the DMA */ + DMA_Configuration(); + + NVIC_Configuration(); + + /* USARTx and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; //921600 + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTx, USART_INT_IDLEF, ENABLE); + + /* Enable USARTx DMA Rx and TX request */ + USART_EnableDMA(USARTx, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief enable or disable the usart dma + */ +void app_usart_dma_enable(FunctionalState Cmd) +{ + if(Cmd == ENABLE) + { + ns_sleep_lock_acquire(); + rx_old_pos = 0; + usart_tx_fifo_in = usart_tx_fifo_out = 0; //clean fifo + usart_rx_fifo_in = usart_rx_fifo_out = 0; //clean fifo + app_usart_configuration(); + + } + else{ + ns_sleep_lock_release(); + USART_Enable(USARTx, DISABLE); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, DISABLE); + DMA_EnableChannel(USARTx_Tx_DMA_Channel, DISABLE); + /* Deinit IO of USART to save power */ + GPIO_InitType GPIO_InitStructure; + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + } +} + +/** + * @brief forward usart rx data too ble notify + */ +void usart_forward_to_ble_loop(void) +{ + uint32_t in_temp; + uint16_t ble_send_len; + + in_temp = usart_rx_fifo_in; + if(usart_rx_fifo_out < in_temp) + { + ble_send_len = in_temp-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out > in_temp){ + ble_send_len = USART_RX_FIFO_SIZE-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out == in_temp){ + // fifo empty, stop send loop + ble_sending = false; + return; + } + if ((app_env.max_mtu-3)> ble_att_mtu) + { + ble_att_mtu = (app_env.max_mtu-3); + } + if(ble_send_len > ble_att_mtu) + { + ble_send_len = ble_att_mtu; + } + ble_sending = true; + #if (BLE_RDTSS_SERVER) + rdtss_send_notify( &usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + #endif + usart_rx_fifo_out = (usart_rx_fifo_out+ble_send_len)%USART_RX_FIFO_SIZE; + + return; +} + + +/** + * @brief usart rx data enter fifo and active ble send first package if not active yet + */ +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len; + //store data in fifo + while(len) + { + if(usart_rx_fifo_in >= usart_rx_fifo_out ) + { + in_len = USART_RX_FIFO_SIZE-usart_rx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + } + else if(usart_rx_fifo_in < usart_rx_fifo_out ) + { + in_len = usart_rx_fifo_out-usart_rx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,usart_rx_fifo_in,usart_rx_fifo_out); + } + break; + } + } + + if(!ble_sending) + { + ke_timer_set(RDTSS_VAL_NTF_CFM, TASK_APP, 10); + } + + + return len; +} + +/** + * @brief usart send data via dma + */ +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len) +{ + DMA_InitType DMA_InitStructure; + + if(usart_sending) + { + return false; + } + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)p_data; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = len; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Tx_DMA_Channel, &DMA_InitStructure); + + usart_sending = true; + DMA_EnableChannel(USARTx_Tx_DMA_Channel, ENABLE); + + return true; +} + +/** + * @brief usart send data in blocking mode + */ +void usart_tx_data_blocking(uint8_t *p_data, uint16_t len) +{ + while(len--) + { + USART_SendData(USARTx, *p_data); + p_data++; + } +} + +/** + * @brief usart tx fifo enter and active dma send out + */ +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len, out_temp; + //store data in fifo + NS_LOG_DEBUG("%d,%d,%d\r\n",len,usart_tx_fifo_in,usart_tx_fifo_out); + out_temp = usart_tx_fifo_out; + while(len) + { + if(usart_tx_fifo_in >= out_temp ) + { + in_len = USART_TX_FIFO_SIZE-usart_tx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + } + else if(usart_tx_fifo_in < out_temp ) + { + in_len = out_temp-usart_tx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,usart_tx_fifo_in,out_temp); + } + + break; + } + } + + // ble treaming cut timer, active usart send after it. + ke_timer_set(APP_CUSTS_TEST_EVT, TASK_APP, 50); + + return len; +} + +/** + * @brief usart tx data from fifo + */ +void app_usart_tx_process(void) +{ + uint32_t in_temp,len; + uint8_t *p_data; + + in_temp = usart_tx_fifo_in; + if(usart_tx_fifo_out < in_temp) + { + len = in_temp-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = in_temp; + } + + } + else if(usart_tx_fifo_out > in_temp) + { + len = USART_TX_FIFO_SIZE-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = 0; + } + + } +} + + +/** + * @brief check the dma buffer which has been received + */ +void usart_rx_check_in_irq(void) +{ + uint16_t rx_pos; + + rx_pos = USART_RX_DMA_SIZE - DMA_GetCurrDataCounter(USARTx_Rx_DMA_Channel); + if(rx_pos < rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(USART_RX_DMA_SIZE - rx_old_pos)); + + if(rx_pos > 0) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[0],rx_pos); + } + + rx_old_pos = rx_pos; + } + else if(rx_pos > rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(rx_pos - rx_old_pos)); + rx_old_pos = rx_pos; + } + else if(rx_pos != rx_old_pos) + { + //error + rx_old_pos = rx_pos; + } + +} + + +/** + * @brief dma irq handler + */ +void DMA_Channel1_2_3_4_IRQHandler(void) +{ + //TX + if(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)) + { + //TX Transfer complete interrupt + usart_sending = false; + ke_msg_send_basic(APP_CUSTS_TEST_EVT, TASK_APP, TASK_APP); + + DMA_ClearFlag(DMA_FLAG_TC1, DMA); + } + //RX + if(DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + //RX Transfer complete interrupt + DMA_ClearFlag(DMA_FLAG_TC2, DMA); + usart_rx_check_in_irq(); + + } + if(DMA_GetFlagStatus(DMA_FLAG_HT2, DMA)) + { + //RX Half transfer interrupt + DMA_ClearFlag(DMA_FLAG_HT2, DMA); + usart_rx_check_in_irq(); + } + +} + +/** + * @brief usart irq handler + */ +void USARTx_IRQHandler(void) +{ + uint8_t temp; + //usart idlle interrupt + if(USART_GetFlagStatus(USARTx,USART_FLAG_IDLEF)) + { + //read sts and data will clear rx idle interrupt + temp = USARTx->DAT; + usart_rx_check_in_irq(); + (void)temp; + } + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/main.c new file mode 100644 index 0000000..c6deb90 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/lesc&aes/src/main.c @@ -0,0 +1,160 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_ble.h" +#if (CFG_APP_NS_IUS) +#include "ns_dfu_boot.h" +#endif + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING BLE Secure Connection and AES demo \r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + + NS_LOG_INIT(); + + #if (CFG_APP_NS_IUS) + if(CURRENT_APP_START_ADDRESS == NS_APP1_START_ADDRESS){ + NS_LOG_INFO("application 1 start new ...\r\n"); + }else if(CURRENT_APP_START_ADDRESS == NS_APP2_START_ADDRESS){ + NS_LOG_INFO("application 2 start new ...\r\n"); + } + #endif + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + app_usart_dma_enable(ENABLE); + //init text + usart_tx_dma_send((uint8_t*)DEMO_STRING, sizeof(DEMO_STRING)); + + delay_n_10us(500); + //disable usart for enter sleep + app_usart_dma_enable(DISABLE); + + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/MDK-ARM/rdtss.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/MDK-ARM/rdtss.uvoptx new file mode 100644 index 0000000..8f213c8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/MDK-ARM/rdtss.uvoptx @@ -0,0 +1,1191 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + OTA_IMG_1 + 0x4 + ARM-ADS + + 64000000 + + 0 + 1 + 1 + 0 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 0 + + 255 + + 1 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + -1 + + + + + + + + + + + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + OTA_IMG_2 + 0x4 + ARM-ADS + + 64000000 + + 0 + 1 + 1 + 0 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 0 + + 255 + + 1 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + -1 + + + + + + + + + + + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + lib_att.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + bass.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + bass_task.c + 0 + 0 + + + 5 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + rdtss.c + 0 + 0 + + + 5 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + rdtss_task.c + 0 + 0 + + + 5 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + rdts_common.c + 0 + 0 + + + 5 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + ns_iuss.c + 0 + 0 + + + 5 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + ns_iuss_task.c + 0 + 0 + + + + + NS_DFU + 0 + 0 + 0 + 0 + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_crc.c + dfu_crc.c + 0 + 0 + + + 6 + 30 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_delay.c + dfu_delay.c + 0 + 0 + + + 6 + 31 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_led.c + dfu_led.c + 0 + 0 + + + 6 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + ns_dfu_ble.c + 0 + 0 + + + 6 + 33 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + ns_dfu_boot.c + 0 + 0 + + + + + Crypto + 0 + 0 + 0 + 0 + + 7 + 34 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + ns_ecc.c + 0 + 0 + + + 7 + 35 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + sha256.c + 0 + 0 + + + 7 + 36 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + uECC.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 8 + 37 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 8 + 38 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 8 + 39 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 8 + 40 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 8 + 41 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 8 + 42 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 8 + 43 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 9 + 44 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 9 + 45 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_batt.c + app_batt.c + 0 + 0 + + + 9 + 46 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtss.c + app_rdtss.c + 0 + 0 + + + 9 + 47 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_ns_ius.c + app_ns_ius.c + 0 + 0 + + + 9 + 48 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 10 + 49 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 10 + 50 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + 10 + 51 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 11 + 52 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 12 + 53 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/MDK-ARM/rdtss.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/MDK-ARM/rdtss.uvprojx new file mode 100644 index 0000000..be35614 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/MDK-ARM/rdtss.uvprojx @@ -0,0 +1,2615 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.4.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdts + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\rdts.bin .\Objects\rdts.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + + + NS_DFU + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + OTA_IMG_1 + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.4.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtss_ota + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\rdtss_ota.bin .\Objects\rdtss_ota.axf + cmd.exe /C copy .\bin\rdtss_ota.bin ..\..\..\..\..\utilities\dfu\Image\APP1.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1004000 + 0x1c000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, APPLICATION, BLE_OTA_ENABLE + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\dfu\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + + + NS_DFU + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + OTA_IMG_2 + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.4.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtss_ota + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\rdtss_ota.bin .\Objects\rdtss_ota.axf + cmd.exe /C copy .\bin\rdtss_ota.bin ..\..\..\..\..\utilities\dfu\Image\APP2.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1020000 + 0x1c000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, APPLICATION, BLE_OTA_ENABLE + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\dfu\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + + + NS_DFU + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_ble.h new file mode 100644 index 0000000..0d16f44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_batt.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_batt.h new file mode 100644 index 0000000..5fc237b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_batt.h @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef APP_BATT_H_ +#define APP_BATT_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include // Standard Integer Definition +#include "ke_task.h" // Kernel Task Definition + +/* Public typedef -----------------------------------------------------------*/ + +/// Battery Application Module Environment Structure +struct app_batt_env_tag +{ + /// Connection handle + uint8_t conidx; + /// Current Battery Level + uint8_t batt_lvl; +}; + +/* Public variables ---------------------------------------------------------*/ + +/// Battery Application environment +extern struct app_batt_env_tag app_batt_env; + +/// Table of message handlers +extern const struct app_subtask_handlers app_batt_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * + * Health Thermometer Application Functions + * + **/ + +/** + * @brief Initialize Battery Application Module + **/ +void app_batt_init(void); + +/** + * @brief Add a Battery Service instance in the DB + **/ +void app_batt_add_bas(void); + +/** + * @brief Enable the Battery Service + **/ +void app_batt_enable_prf(uint8_t conidx); + +/** + * @brief Send a Battery level value + **/ +void app_batt_send_lvl(uint8_t batt_lvl); + +#endif //(BLE_APP_BATT) + +/// @} APP + +#endif // APP_BATT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_ns_ius.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_ns_ius.h new file mode 100644 index 0000000..726f13b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_ns_ius.h @@ -0,0 +1,105 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ns_ius.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef __APP_NS_IUS_H__ +#define __APP_NS_IUS_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#include "prf_types.h" +#include "prf.h" + + +#if (BLE_APP_NS_IUS) +/* Public typedef -----------------------------------------------------------*/ +enum +{ + NS_IUS_IDX_SVC, + + NS_IUS_IDX_RC_CHAR, + NS_IUS_IDX_RC_VAL, + NS_IUS_IDX_RC_CFG, + + NS_IUS_IDX_CC_CHAR, + NS_IUS_IDX_CC_VAL, + NS_IUS_IDX_CC_CFG, + + NS_IUS_IDX_NB, +}; + +/* Public define ------------------------------------------------------------*/ +#define SERVICE_NS_IUS {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, 0x01,0x00, 0x11,0x11} +#define CHAR_NS_IUS_RC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x02,0x00, 0x11,0x11} +#define CHAR_NS_IUS_CC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x03,0x00, 0x11,0x11} + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ +extern struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB]; +/* Public function prototypes -----------------------------------------------*/ +extern const struct app_subtask_handlers ns_ius_app_handlers; + +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length); +void app_ns_ius_add_ns_ius(void); +void app_ns_ius_init(void); + +#endif //BLE_APP_NS_IUS + +#endif //__APP_NS_IUS_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_rdtss.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_rdtss.h new file mode 100644 index 0000000..53d8e3a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/app_rdtss.h @@ -0,0 +1,121 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSS_H_ +#define APP_RDTSS_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/// Manufacturer Name Value +#define APP_RDTSS_MANUFACTURER_NAME ("NSING") +#define APP_RDTSS_MANUFACTURER_NAME_LEN (5) + + + +#define ATT_SERVICE_AM_SPEED_128 {0x01,0x10,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Service UUID */ +#define ATT_CHAR_AM_SPEED_WRITE_128 {0x01,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_NTF_128 {0x02,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ + + +/// rdtss Service Attributes Indexes +enum +{ + RDTSS_IDX_SVC, + + RDTSS_IDX_WRITE_CHAR, + RDTSS_IDX_WRITE_VAL, + RDTSS_IDX_WRITE_CFG, + + RDTSS_IDX_NTF_CHAR, + RDTSS_IDX_NTF_VAL, + RDTSS_IDX_NTF_CFG, + + RDTSS_IDX_NB, +}; + +extern uint8_t notify_en; +/** + * @brief Initialize Device Information Service Application + **/ +void app_rdtss_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_rdtss_add_rdts(void); + +void rdtss_send_notify(uint8_t *data, uint16_t length); + + +#endif //BLE_RDTSS_SERVER + +/// @} APP + +#endif // APP_RDTSS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_usart.h new file mode 100644 index 0000000..754d7e9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_usart.h @@ -0,0 +1,152 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTx_DAT_Base (USART1_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART1_RX +#define USARTx_IRQn USART1_IRQn +#define USARTx_IRQHandler USART1_IRQHandler +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define USARTx_DAT_Base (USART2_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#define USARTx_IRQn USART2_IRQn +#define USARTx_IRQHandler USART2_IRQHandler +#endif + + +#define USART_RX_DMA_SIZE 256 +#define USART_RX_FIFO_SIZE 1000 +#define USART_TX_FIFO_SIZE 1000 + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + +/* Public function prototypes -----------------------------------------------*/ + +void app_usart_configuration(void); +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len); +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len); +void app_usart_tx_data_blocking(uint8_t *p_data, uint16_t len); + +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len); +void usart_forward_to_ble_loop(void); +void app_usart_dma_enable(FunctionalState Cmd); +void app_usart_tx_process(void); +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_user_config.h new file mode 100644 index 0000000..c4365da --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/inc/app_user_config.h @@ -0,0 +1,144 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_RDTSS" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 0//30 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + +// Advertise data +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_DEVICE_INFORMATION_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (5000) /**< Time of initiating event to update connection params (5 seconds). */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 0 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +/* profiles config */ +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +//#define CFG_APP_BATT 1 +//#define CFG_PRF_BASS 1 +#define CFG_PRF_RDTSS 1 + +#ifdef BLE_OTA_ENABLE +#define CFG_APP_NS_IUS 1 +#endif + +/* User config */ + +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 1 + +#define NS_TIMER_ENABLE 1 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + + + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/readme.txt new file mode 100644 index 0000000..69081e8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/readme.txt @@ -0,0 +1,31 @@ + +1. Function description + + Bluetooth BLE data transmission service (rdts) routine, using 128bit UUID. After the BLE host connects to the device, + the downlink data will be transparently transmitted to USART1, and the data received by USART1 will be transparently transmitted to the BLE host + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB1(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 4. Bluetooth BLE name: NS_RDTSS + 5. LED1 lights up when it is turned on, LED2 indicates the connection status, and lights up when Bluetooth is connected + 6. BLE Data: USART1 PB6(TX) and PB7(RX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + usage method: + 1. Burn to development board after compilation + 2. Power on development board and check the log. + 3. Connect the master device, and send data via USART1 each other. + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_ble.c new file mode 100644 index 0000000..5f9788f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_ble.c @@ -0,0 +1,350 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "ns_sec.h" +#include "app_ble.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_rdtss.h" +#include "app_dis.h" +#include "app_batt.h" +#if (BLE_APP_NS_IUS) +#include "app_ns_ius.h" +#endif //BLE_APP_NS_IUS +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_CUSTS_TEST_EVT: + app_usart_tx_process(); + break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + #if (BLE_APP_DIS) + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); + #endif //BLE_APP_DIS + #if (BLE_APP_BATT) + //add battery level server + ns_ble_add_prf_func_register(app_batt_add_bas); + #endif //BLE_APP_BATT + #if (BLE_APP_NS_IUS) + ns_ble_add_prf_func_register(app_ns_ius_add_ns_ius); + #endif //BLE_APP_NS_IUS + + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtss_add_rdts); + + + +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + //enable usart receive + app_usart_dma_enable(ENABLE); + LedOn(LED2_PORT,LED2_PIN); + notify_en = 0; + #if (BLE_APP_BATT) + // Enable Battery Service + app_batt_enable_prf(app_env.conidx); + #endif //(BLE_APP_BATT) +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising + ns_ble_adv_start(); + + //disable usart receive + app_usart_dma_enable(DISABLE); + LedOff(LED2_PORT,LED2_PIN); + notify_en = 0; +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_batt.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_batt.c new file mode 100644 index 0000000..4b650ba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_batt.c @@ -0,0 +1,257 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +/** + * @addtogroup APP + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include "app_batt.h" // Battery Application Module Definitions +#include "ns_ble.h" // Application Definitions +#include "ns_ble_task.h" // application task definitions +#include "bass_task.h" // health thermometer functions +#include "co_bt.h" +#include "bass.h" +#include "prf_types.h" // Profile common types definition +#include "arch.h" // Platform Definitions +#include "prf.h" +#include + +/* Private define ------------------------------------------------------------*/ +/// Battery Application Module Environment Structure +struct app_batt_env_tag app_batt_env; + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief bat server init + * @param + * @return + * @note + */ +void app_batt_init(void) +{ + // Reset the environment + memset(&app_batt_env, 0, sizeof(struct app_batt_env_tag)); + + // Initial battery level: 100 + app_batt_env.batt_lvl = 100; + + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_BASS; + prf.prf_task_handler = &app_batt_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_BASS; + get_func.prf_itf_get_func = bass_prf_itf_get; + prf_get_itf_func_register(&get_func); + +} + +/** + * @brief add bat server + * @param + * @return + * @note + */ +void app_batt_add_bas(void) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + struct bass_db_cfg* db_cfg; + // Allocate the BASS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct bass_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_BASS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct bass_db_cfg* ) req->param; + + // Add a BAS instance + db_cfg->bas_nb = 1; + // Sending of notifications is supported + db_cfg->features[0] = BAS_BATT_LVL_NTF_SUP; + + // Send the message + ke_msg_send(req); + + app_batt_init(); +} + +/** + * @brief enable batt server profile + * @param + * @return + * @note + */ +void app_batt_enable_prf(uint8_t conidx) +{ + app_batt_env.conidx = conidx; + + // Allocate the message + struct bass_enable_req * req = KE_MSG_ALLOC(BASS_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + + // NTF initial status - Disabled + req->ntf_cfg = PRF_CLI_STOP_NTFIND; + req->old_batt_lvl[0] = 50; + + // Send the message + ke_msg_send(req); +} + +/** + * @brief send battery level + * @param + * @return + * @note + */ +void app_batt_send_lvl(uint8_t batt_lvl) +{ + ASSERT_ERR(batt_lvl <= BAS_BATTERY_LVL_MAX); + + // Allocate the message + struct bass_batt_level_upd_req * req = KE_MSG_ALLOC(BASS_BATT_LEVEL_UPD_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_batt_level_upd_req); + + // Fill in the parameter structure + req->bas_instance = 0; + req->batt_level = batt_lvl; + + // Send the message + ke_msg_send(req); +} + +static int bass_batt_level_ntf_cfg_ind_handler(ke_msg_id_t const msgid, + struct bass_batt_level_ntf_cfg_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +static int batt_level_upd_handler(ke_msg_id_t const msgid, + struct bass_batt_level_upd_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +/** + * @brief + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_batt_msg_dflt_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Drop the message + + return (KE_MSG_CONSUMED); +} + +/* + * LOCAL VARIABLE DEFINITIONS + */ + +/// Default State handlers definition +const struct ke_msg_handler app_batt_msg_handler_list[] = +{ + // Note: first message is latest message checked by kernel so default is put on top. + {KE_MSG_DEFAULT_HANDLER, (ke_msg_func_t)app_batt_msg_dflt_handler}, + + {BASS_BATT_LEVEL_NTF_CFG_IND, (ke_msg_func_t)bass_batt_level_ntf_cfg_ind_handler}, + {BASS_BATT_LEVEL_UPD_RSP, (ke_msg_func_t)batt_level_upd_handler}, +}; + +const struct app_subtask_handlers app_batt_handlers = APP_HANDLERS(app_batt); + +#endif //BLE_APP_BATT + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_ns_ius.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_ns_ius.c new file mode 100644 index 0000000..1846f9b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_ns_ius.c @@ -0,0 +1,248 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ns_ius.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_NS_IUS) + +#include "app_ns_ius.h" +#include +#include "ns_iuss.h" +#include "ns_iuss_task.h" +#include "ns_dfu_ble.h" +#include "attm.h" +#include "ke_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "gattc_task.h" +#include "attm_db.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" +#include "ke_msg.h" +#include "ns_ble.h" +#include "ns_log.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB] = +{ + [NS_IUS_IDX_SVC] = {{0x00,0x28}, PERM(RD, ENABLE),0,0}, + + [NS_IUS_IDX_RC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE),0, 0}, + [NS_IUS_IDX_RC_VAL] = {CHAR_NS_IUS_RC, PERM(WRITE_COMMAND, ENABLE), PERM_VAL(UUID_LEN, 0x02), 247}, + [NS_IUS_IDX_RC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + [NS_IUS_IDX_CC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + [NS_IUS_IDX_CC_VAL] = {CHAR_NS_IUS_CC, PERM(WRITE_REQ, ENABLE) | PERM(NTF, ENABLE) , PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 20 }, + [NS_IUS_IDX_CC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + + + + + +static bool notification_enable = false; + + + + + +static int ns_ius_val_write_ind_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + const struct ns_ius_val_write_ind *p_param = (const struct ns_ius_val_write_ind *)param; + + switch (p_param->handle) + { + case NS_IUS_IDX_CC_CFG:{ + + if(p_param->length == 2) + { + uint16_t cfg_value = p_param->value[0] + p_param->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + notification_enable = true; + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + notification_enable = false; + } + NS_LOG_DEBUG("notification_enable %d\r\n",notification_enable); + } + + }break; + + + case NS_IUS_IDX_CC_VAL:{ + uint8_t output[20]; + uint8_t output_len = 0; + ns_dfu_ble_handler_cc(p_param->value, p_param->length, output, &output_len); + if(output_len)ns_ble_ius_app_cc_send(output, output_len); + }break; + + case NS_IUS_IDX_RC_VAL:{ + ns_dfu_ble_handler_rc(p_param->value, p_param->length); + }break; + default: + break; + + } + + return KE_MSG_CONSUMED; +} + + + +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length) +{ + uint8_t state = ke_state_get(ns_ble_ius_task); + if (state == NS_IUS_BUSY || notification_enable == false) + { + return; + } + ke_state_set(ns_ble_ius_task, NS_IUS_BUSY); + + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + struct gattc_send_evt_cmd * req = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, KE_BUILD_ID(TASK_GATTC, app_env.conidx), ns_ius_env->prf_env.prf_task, gattc_send_evt_cmd, length); + req->operation = GATTC_NOTIFY; + req->handle = ns_ius_env->shdl + NS_IUS_IDX_CC_VAL; + req->length = length; + memcpy(req->value, p_data, length); + ke_msg_send(req); +} + + + +static int ns_ius_disconnect_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + notification_enable = false; + return KE_MSG_CONSUMED; +} + + +const struct ke_msg_handler ns_ius_app_msg_handler_list[] = +{ + {NS_IUS_VAL_WRITE_IND, ns_ius_val_write_ind_handler}, + {NS_IUS_DISCONNECT, ns_ius_disconnect_handler}, +}; + + +const struct app_subtask_handlers ns_ius_app_handlers = APP_HANDLERS(ns_ius_app); + + + + + + + +void app_ns_ius_add_ns_ius(void) +{ + Qflash_Init(); + + struct ns_ius_db_cfg *db_cfg; + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct ns_ius_db_cfg)); + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_NS_IUS; + req->app_task = TASK_APP; + req->start_hdl = 0; + db_cfg = (struct ns_ius_db_cfg *) req->param; + db_cfg->att_tbl = NULL; + db_cfg->cfg_flag = 0; + db_cfg->features = 0; + ke_msg_send(req); + + app_ns_ius_init(); +} + +void app_ns_ius_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_NS_IUS; + prf.prf_task_handler = &ns_ius_app_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_NS_IUS; + get_func.prf_itf_get_func = ns_ius_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + + +#endif //BLE_APP_NS_IUS + + +/// @} APP + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_rdtss.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_rdtss.c new file mode 100644 index 0000000..09f1d1c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_profile/app_rdtss.c @@ -0,0 +1,317 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtss.h" // rdtss Application Module Definitions +#include "rdtss_task.h" // Device Information Profile Functions +#include "gapm_task.h" // GAP Manager Task API +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" +#include "stdio.h" +#include "rdtss.h" +#include "app_usart.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +extern uint8_t ble_sending; +uint8_t notify_en = 0; +const uint8_t app_rdts_svc_uuid[16] = ATT_SERVICE_AM_SPEED_128; +const struct attm_desc_128 app_rdts_att_db[RDTSS_IDX_NB] = +{ + /* Service Declaration */ + [0] = {{0x00,0x28}, PERM(RD, ENABLE), 0, 0 }, + + /* Characteristic Declaration */ + [1] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [2] = {ATT_CHAR_AM_SPEED_WRITE_128, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [3] = {{0x01,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + /* Characteristic Declaration */ + [4] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [5] = {ATT_CHAR_AM_SPEED_NTF_128, PERM(NTF, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [6] = {{0x02,0x29}, PERM(RD, ENABLE) |PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, +}; + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtss_add_rdts(void) +{ + struct rdtss_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtss_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtss_db_cfg *) req->param; + // Attribute table. In case the handle offset needs to be saved + db_cfg->att_tbl = &app_rdts_att_db[0]; + db_cfg->svc_uuid = &app_rdts_svc_uuid[0]; + db_cfg->max_nb_att = RDTSS_IDX_NB; + + // Send the message + ke_msg_send(req); + + app_rdtss_init(); +} + +/** + * @brief rdtss value require indicate handler + * @param + * @return + * @note Note + */ +static int rdtss_value_req_ind_handler(ke_msg_id_t const msgid, + struct rdtss_value_req_ind const *req_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + len = APP_RDTSS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_RDTSS_MANUFACTURER_NAME; + + + // Allocate confirmation to send the value + struct rdtss_value_req_rsp *rsp_value = KE_MSG_ALLOC_DYN(RDTSS_VALUE_REQ_RSP, + src_id, dest_id, + rdtss_value_req_rsp, + len); + rsp_value->status = 0; + rsp_value->conidx = req_value ->conidx; + rsp_value->length = len; + rsp_value->att_idx = req_value->att_idx; + if (len) + { + // Copy data + memcpy(&rsp_value->value, data, len); + } + // Send message + ke_msg_send(rsp_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief cuusts write indicate handler + * @param + * @return + * @note + */ +static int rdtss_val_write_ind_handler(ke_msg_id_t const msgid, + struct rdtss_val_write_ind const *ind_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,write handle = %x,length = %x\r\n",__func__ ,ind_value->handle, ind_value->length); + + for(uint16_t i=0; ilength; i++) + { + NS_LOG_DEBUG("%x ",ind_value->value[i]); + } + NS_LOG_DEBUG("\r\n"); + + uint16_t handle = ind_value->handle; + uint16_t length = ind_value->length; + + switch (handle) + { + case RDTSS_IDX_NTF_CFG: + + if(length == 2) + { + uint16_t cfg_value = ind_value->value[0] + ind_value->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + //enabled notify + notify_en = 1; + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + notify_en = 0; + } + } + + break; + case RDTSS_IDX_WRITE_VAL: + //ble data receive + app_usart_tx_fifo_enter(ind_value->value,ind_value->length); + + break; + default: + break; + + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Functions + * @param + * @return + * @note Note + */ +static int rdtss_val_ntf_cfm_handler(ke_msg_id_t const msgid, + struct rdtss_val_ntf_cfm const *cfm_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,ntf cfm handle = %x, status = %x\r\n",__func__, cfm_value->handle, cfm_value->status); + + usart_forward_to_ble_loop(); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief rdtss send notify + * @param + * @return + * @note + */ +void rdtss_send_notify(uint8_t *data, uint16_t length) +{ + if (notify_en) + { + struct rdtss_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(RDTSS_VAL_NTF_REQ, + prf_get_task_from_id(TASK_ID_RDTSS), + TASK_APP, + rdtss_val_ntf_ind_req, + length); + + req->conidx = app_env.conidx; + req->notification = true; + req->handle = RDTSS_IDX_NTF_VAL; + req->length = length; + memcpy(&req->value[0], data, length); + + ke_msg_send(req); + } + else + { + ble_sending = false; + NS_LOG_INFO("Not enable notify\r\n"); + } +} + + +/// Default State handlers definition +const struct ke_msg_handler app_rdtss_msg_handler_list[] = +{ + {RDTSS_VALUE_REQ_IND, (ke_msg_func_t)rdtss_value_req_ind_handler}, + {RDTSS_VAL_WRITE_IND, (ke_msg_func_t)rdtss_val_write_ind_handler}, + {RDTSS_VAL_NTF_CFM, (ke_msg_func_t)rdtss_val_ntf_cfm_handler}, + +}; + +const struct app_subtask_handlers app_rdtss_handlers = APP_HANDLERS(app_rdtss); + + +void app_rdtss_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSS; + prf.prf_task_handler = &app_rdtss_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSS; + get_func.prf_itf_get_func = rdtss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +#endif //BLE_RDTSS_SERVER diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_usart.c new file mode 100644 index 0000000..9243724 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/app_usart.c @@ -0,0 +1,583 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include +#include "global_func.h" +#include "app_usart.h" +#include "app_rdtss.h" +#include "ns_sleep.h" +#include "ns_log.h" +#include "ns_timer.h" +#include "ke_timer.h" +#include "app_ble.h" +#include "rdtss_task.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] = {0}; +uint16_t rx_old_pos = 0; + +uint8_t usart_rx_fifo_buf[USART_RX_FIFO_SIZE] = {0}; +uint32_t usart_rx_fifo_in = 0; +uint32_t usart_rx_fifo_out = 0; + + +uint8_t usart_tx_fifo_buf[USART_TX_FIFO_SIZE] = {0}; +uint32_t usart_tx_fifo_in = 0; +uint32_t usart_tx_fifo_out = 0; + +uint8_t usart_sending = false; +uint8_t ble_sending = false; +uint16_t ble_att_mtu = (ATT_DEFAULT_MTU-3); + +/* Private function prototypes -----------------------------------------------*/ +void app_usart_tx_process(void); + +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTx_Tx_DMA_Channel); + DMA_RequestRemap(USARTx_Tx_DMA_REMAP, DMA, USARTx_Tx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Tx_DMA_Channel,DMA_INT_TXC ,ENABLE); + + /* USARTx RX DMA1 Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTx_Rx_DMA_Channel); + DMA_RequestRemap(USARTx_Rx_DMA_REMAP, DMA, USARTx_Rx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Rx_DMA_Channel,DMA_INT_TXC|DMA_INT_HTX ,ENABLE); + + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)USART_rx_dma_buf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = USART_RX_DMA_SIZE; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Rx_DMA_Channel, &DMA_InitStructure); + +} + + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + NVIC_DisableIRQ(DMA_Channel1_2_3_4_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + + NVIC_DisableIRQ(USARTx_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void app_usart_configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* Configure the DMA */ + DMA_Configuration(); + + NVIC_Configuration(); + + /* USARTx and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; //921600 + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTx, USART_INT_IDLEF, ENABLE); + + /* Enable USARTx DMA Rx and TX request */ + USART_EnableDMA(USARTx, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief enable or disable the usart dma + */ +void app_usart_dma_enable(FunctionalState Cmd) +{ + if(Cmd == ENABLE) + { + ns_sleep_lock_acquire(); + rx_old_pos = 0; + usart_tx_fifo_in = usart_tx_fifo_out = 0; //clean fifo + usart_rx_fifo_in = usart_rx_fifo_out = 0; //clean fifo + app_usart_configuration(); + + } + else{ + ns_sleep_lock_release(); + USART_Enable(USARTx, DISABLE); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, DISABLE); + DMA_EnableChannel(USARTx_Tx_DMA_Channel, DISABLE); + /* Deinit IO of USART to save power */ + GPIO_InitType GPIO_InitStructure; + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + } +} + +/** + * @brief forward usart rx data too ble notify + */ +bool fg_rx_end = false; +void usart_forward_to_ble_loop(void) +{ + uint32_t in_temp; + uint16_t ble_send_len; + uint16_t temp_len = USART_RX_FIFO_SIZE-usart_rx_fifo_out; + + in_temp = usart_rx_fifo_in; + if(usart_rx_fifo_out < in_temp) + { + ble_send_len = in_temp-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out > in_temp){ + ble_send_len = (USART_RX_FIFO_SIZE-usart_rx_fifo_out + usart_rx_fifo_in); + fg_rx_end = true; + } + else if(usart_rx_fifo_out == in_temp){ + // fifo empty, stop send loop + ble_sending = false; + return; + } + if ((app_env.max_mtu-3)> ble_att_mtu) + { + ble_att_mtu = (app_env.max_mtu-3); + } + if(ble_send_len > ble_att_mtu) + { + ble_send_len = ble_att_mtu; + } + ble_sending = true; + + if (fg_rx_end && (ble_send_len > temp_len)) + { + uint8_t temp_buf[512] = {0}; + memcpy(&temp_buf[0],&usart_rx_fifo_buf[usart_rx_fifo_out],temp_len); + memcpy(&temp_buf[temp_len],&usart_rx_fifo_buf[0],(ble_send_len-temp_len)); + #if (BLE_RDTSS_SERVER) + rdtss_send_notify(&temp_buf[0], ble_send_len); + #endif + usart_rx_fifo_out = (ble_send_len-temp_len)%USART_RX_FIFO_SIZE; + } + else + { + #if (BLE_RDTSS_SERVER) + rdtss_send_notify(&usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + #endif + usart_rx_fifo_out = (usart_rx_fifo_out+ble_send_len)%USART_RX_FIFO_SIZE; + } + fg_rx_end = false; + return; +} + + +/** + * @brief usart rx data enter fifo and active ble send first package if not active yet + */ +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len; + //store data in fifo + while(len) + { + if(usart_rx_fifo_in >= usart_rx_fifo_out ) + { + in_len = USART_RX_FIFO_SIZE-usart_rx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + } + else if(usart_rx_fifo_in < usart_rx_fifo_out ) + { + in_len = usart_rx_fifo_out-usart_rx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,usart_rx_fifo_in,usart_rx_fifo_out); + } + break; + } + } + + if(!ble_sending) + { + ke_timer_set(RDTSS_VAL_NTF_CFM, TASK_APP, 10); + } + + + return len; +} + +/** + * @brief usart send data via dma + */ +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len) +{ + DMA_InitType DMA_InitStructure; + + if(usart_sending) + { + return false; + } + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)p_data; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = len; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Tx_DMA_Channel, &DMA_InitStructure); + + usart_sending = true; + DMA_EnableChannel(USARTx_Tx_DMA_Channel, ENABLE); + + return true; +} + +/** + * @brief usart send data in blocking mode + */ +void usart_tx_data_blocking(uint8_t *p_data, uint16_t len) +{ + while(len--) + { + USART_SendData(USARTx, *p_data); + p_data++; + } +} + +/** + * @brief usart tx fifo enter and active dma send out + */ +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len, out_temp; + //store data in fifo + NS_LOG_DEBUG("%d,%d,%d\r\n",len,usart_tx_fifo_in,usart_tx_fifo_out); + out_temp = usart_tx_fifo_out; + while(len) + { + if(usart_tx_fifo_in >= out_temp ) + { + in_len = USART_TX_FIFO_SIZE-usart_tx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + } + else if(usart_tx_fifo_in < out_temp ) + { + in_len = out_temp-usart_tx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,usart_tx_fifo_in,out_temp); + } + + break; + } + } + + // ble treaming cut timer, active usart send after it. + ke_timer_set(APP_CUSTS_TEST_EVT, TASK_APP, 50); + + return len; +} + +/** + * @brief usart tx data from fifo + */ +void app_usart_tx_process(void) +{ + uint32_t in_temp,len; + uint8_t *p_data; + + in_temp = usart_tx_fifo_in; + if(usart_tx_fifo_out < in_temp) + { + len = in_temp-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = in_temp; + } + + } + else if(usart_tx_fifo_out > in_temp) + { + len = USART_TX_FIFO_SIZE-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = 0; + } + + } +} + + +/** + * @brief check the dma buffer which has been received + */ +void usart_rx_check_in_irq(void) +{ + uint16_t rx_pos; + + rx_pos = USART_RX_DMA_SIZE - DMA_GetCurrDataCounter(USARTx_Rx_DMA_Channel); + if(rx_pos < rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(USART_RX_DMA_SIZE - rx_old_pos)); + + if(rx_pos > 0) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[0],rx_pos); + } + + rx_old_pos = rx_pos; + } + else if(rx_pos > rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(rx_pos - rx_old_pos)); + rx_old_pos = rx_pos; + } + else if(rx_pos != rx_old_pos) + { + //error + rx_old_pos = rx_pos; + } + +} + + +/** + * @brief dma irq handler + */ +void DMA_Channel1_2_3_4_IRQHandler(void) +{ + //TX + if(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)) + { + //TX Transfer complete interrupt + usart_sending = false; + ke_msg_send_basic(APP_CUSTS_TEST_EVT, TASK_APP, TASK_APP); + + DMA_ClearFlag(DMA_FLAG_TC1, DMA); + } + //RX + if(DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + //RX Transfer complete interrupt + DMA_ClearFlag(DMA_FLAG_TC2, DMA); + usart_rx_check_in_irq(); + + } + if(DMA_GetFlagStatus(DMA_FLAG_HT2, DMA)) + { + //RX Half transfer interrupt + DMA_ClearFlag(DMA_FLAG_HT2, DMA); + usart_rx_check_in_irq(); + } + +} + +/** + * @brief usart irq handler + */ +void USARTx_IRQHandler(void) +{ + uint8_t temp; + //usart idlle interrupt + if(USART_GetFlagStatus(USARTx,USART_FLAG_IDLEF)) + { + //read sts and data will clear rx idle interrupt + temp = USARTx->DAT; + usart_rx_check_in_irq(); + (void)temp; + } + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/main.c new file mode 100644 index 0000000..ed0a6b9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss/src/main.c @@ -0,0 +1,160 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_ble.h" +#if (CFG_APP_NS_IUS) +#include "ns_dfu_boot.h" +#endif + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING raw data transfer server(128bit UUID) demo \r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + + NS_LOG_INIT(); + + #if (CFG_APP_NS_IUS) + if(CURRENT_APP_START_ADDRESS == NS_APP1_START_ADDRESS){ + NS_LOG_INFO("application 1 start new ...\r\n"); + }else if(CURRENT_APP_START_ADDRESS == NS_APP2_START_ADDRESS){ + NS_LOG_INFO("application 2 start new ...\r\n"); + } + #endif + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + app_usart_dma_enable(ENABLE); + //init text + usart_tx_dma_send((uint8_t*)DEMO_STRING, sizeof(DEMO_STRING)); + + delay_n_10us(500); + //disable usart for enter sleep + app_usart_dma_enable(DISABLE); + + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/MDK-ARM/rdtss_16bit.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/MDK-ARM/rdtss_16bit.uvoptx new file mode 100644 index 0000000..7fa22c5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/MDK-ARM/rdtss_16bit.uvoptx @@ -0,0 +1,1210 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + OTA_IMG_1 + 0x4 + ARM-ADS + + 64000000 + + 0 + 1 + 1 + 0 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 0 + + 255 + + 1 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + -1 + + + + + + + + + + + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + OTA_IMG_2 + 0x4 + ARM-ADS + + 64000000 + + 0 + 1 + 1 + 0 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 0 + + 255 + + 1 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + -1 + + + + + + + + + + + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + lib_att.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + bass.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + bass_task.c + 0 + 0 + + + 5 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + rdtss.c + 0 + 0 + + + 5 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + rdtss_task.c + 0 + 0 + + + 5 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + rdts_common.c + 0 + 0 + + + 5 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + ns_iuss.c + 0 + 0 + + + 5 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + ns_iuss_task.c + 0 + 0 + + + 5 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_16bit.c + rdtss_16bit.c + 0 + 0 + + + 5 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_16bit_task.c + rdtss_16bit_task.c + 0 + 0 + + + + + NS_DFU + 0 + 0 + 0 + 0 + + 6 + 31 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_crc.c + dfu_crc.c + 0 + 0 + + + 6 + 32 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_delay.c + dfu_delay.c + 0 + 0 + + + 6 + 33 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_led.c + dfu_led.c + 0 + 0 + + + 6 + 34 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + ns_dfu_ble.c + 0 + 0 + + + 6 + 35 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + ns_dfu_boot.c + 0 + 0 + + + + + Crypto + 0 + 0 + 0 + 0 + + 7 + 36 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + ns_ecc.c + 0 + 0 + + + 7 + 37 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + sha256.c + 0 + 0 + + + 7 + 38 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + uECC.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 8 + 39 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 8 + 40 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 8 + 41 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 8 + 42 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 8 + 43 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 8 + 44 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 8 + 45 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 1 + 0 + 0 + 0 + + 9 + 46 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + 9 + 47 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 9 + 48 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_batt.c + app_batt.c + 0 + 0 + + + 9 + 49 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtss_16bit.c + app_rdtss_16bit.c + 0 + 0 + + + 9 + 50 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_ns_ius.c + app_ns_ius.c + 0 + 0 + + + + + USER + 1 + 0 + 0 + 0 + + 10 + 51 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 10 + 52 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + 10 + 53 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + + + CONFIG + 1 + 0 + 0 + 0 + + 11 + 54 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 12 + 55 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/MDK-ARM/rdtss_16bit.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/MDK-ARM/rdtss_16bit.uvprojx new file mode 100644 index 0000000..3275583 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/MDK-ARM/rdtss_16bit.uvprojx @@ -0,0 +1,2644 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdts + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\rdts.bin .\Objects\rdts.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + rdtss_16bit.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_16bit.c + + + rdtss_16bit_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_16bit_task.c + + + + + NS_DFU + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_ble.c + 1 + ..\src\app_ble.c + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss_16bit.c + 1 + ..\src\app_profile\app_rdtss_16bit.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + OTA_IMG_1 + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtss_ota + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\rdtss_ota.bin .\Objects\rdtss_ota.axf + cmd.exe /C copy .\bin\rdtss_ota.bin ..\..\..\..\..\utilities\dfu\Image\APP1.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1004000 + 0x1c000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, APPLICATION, BLE_OTA_ENABLE + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\dfu\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + rdtss_16bit.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_16bit.c + + + rdtss_16bit_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_16bit_task.c + + + + + NS_DFU + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_ble.c + 1 + ..\src\app_ble.c + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss_16bit.c + 1 + ..\src\app_profile\app_rdtss_16bit.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + OTA_IMG_2 + 0x4 + ARM-ADS + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtss_ota + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\rdtss_ota.bin .\Objects\rdtss_ota.axf + cmd.exe /C copy .\bin\rdtss_ota.bin ..\..\..\..\..\utilities\dfu\Image\APP2.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1020000 + 0x1c000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, APPLICATION, BLE_OTA_ENABLE + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\dfu\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + rdtss_16bit.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_16bit.c + + + rdtss_16bit_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_16bit_task.c + + + + + NS_DFU + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_ble.c + 1 + ..\src\app_ble.c + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss_16bit.c + 1 + ..\src\app_profile\app_rdtss_16bit.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_ble.h new file mode 100644 index 0000000..0d16f44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_batt.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_batt.h new file mode 100644 index 0000000..5fc237b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_batt.h @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef APP_BATT_H_ +#define APP_BATT_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include // Standard Integer Definition +#include "ke_task.h" // Kernel Task Definition + +/* Public typedef -----------------------------------------------------------*/ + +/// Battery Application Module Environment Structure +struct app_batt_env_tag +{ + /// Connection handle + uint8_t conidx; + /// Current Battery Level + uint8_t batt_lvl; +}; + +/* Public variables ---------------------------------------------------------*/ + +/// Battery Application environment +extern struct app_batt_env_tag app_batt_env; + +/// Table of message handlers +extern const struct app_subtask_handlers app_batt_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * + * Health Thermometer Application Functions + * + **/ + +/** + * @brief Initialize Battery Application Module + **/ +void app_batt_init(void); + +/** + * @brief Add a Battery Service instance in the DB + **/ +void app_batt_add_bas(void); + +/** + * @brief Enable the Battery Service + **/ +void app_batt_enable_prf(uint8_t conidx); + +/** + * @brief Send a Battery level value + **/ +void app_batt_send_lvl(uint8_t batt_lvl); + +#endif //(BLE_APP_BATT) + +/// @} APP + +#endif // APP_BATT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_ns_ius.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_ns_ius.h new file mode 100644 index 0000000..726f13b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_ns_ius.h @@ -0,0 +1,105 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ns_ius.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef __APP_NS_IUS_H__ +#define __APP_NS_IUS_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#include "prf_types.h" +#include "prf.h" + + +#if (BLE_APP_NS_IUS) +/* Public typedef -----------------------------------------------------------*/ +enum +{ + NS_IUS_IDX_SVC, + + NS_IUS_IDX_RC_CHAR, + NS_IUS_IDX_RC_VAL, + NS_IUS_IDX_RC_CFG, + + NS_IUS_IDX_CC_CHAR, + NS_IUS_IDX_CC_VAL, + NS_IUS_IDX_CC_CFG, + + NS_IUS_IDX_NB, +}; + +/* Public define ------------------------------------------------------------*/ +#define SERVICE_NS_IUS {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, 0x01,0x00, 0x11,0x11} +#define CHAR_NS_IUS_RC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x02,0x00, 0x11,0x11} +#define CHAR_NS_IUS_CC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x03,0x00, 0x11,0x11} + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ +extern struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB]; +/* Public function prototypes -----------------------------------------------*/ +extern const struct app_subtask_handlers ns_ius_app_handlers; + +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length); +void app_ns_ius_add_ns_ius(void); +void app_ns_ius_init(void); + +#endif //BLE_APP_NS_IUS + +#endif //__APP_NS_IUS_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_rdtss_16bit.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_rdtss_16bit.h new file mode 100644 index 0000000..b4f56c9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/app_rdtss_16bit.h @@ -0,0 +1,119 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss_16bit.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSS_16BIT_H_ +#define APP_RDTSS_16BIT_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_16BIT_SERVER) + +/// Manufacturer Name Value +#define APP_RDTSS_16BIT_MANUFACTURER_NAME ("NSING") +#define APP_RDTSS_16BIT_MANUFACTURER_NAME_LEN (5) + + + +#define ATT_SERVICE_AM_SPEED_16 0xfffa /*!< Service UUID */ +#define ATT_CHAR_AM_SPEED_WRITE_16 0xfffb /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_NTF_16 0xfffc /*!< Characteristic value UUID */ + +/// rdtss 16bit uuid Service Attributes Indexes +enum +{ + RDTSS_16BIT_IDX_SVC, + + RDTSS_16BIT_IDX_WRITE_CHAR, + RDTSS_16BIT_IDX_WRITE_VAL, + RDTSS_16BIT_IDX_WRITE_CFG, + + RDTSS_16BIT_IDX_NTF_CHAR, + RDTSS_16BIT_IDX_NTF_VAL, + RDTSS_16BIT_IDX_NTF_CFG, + + RDTSS_16BIT_IDX_NB, +}; + +/** + * @brief Initialize Device Information Service Application + **/ +void app_rdtss_16bit_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_rdtss_16bit_add_rdtss_16bit(void); + +void rdtss_16bit_send_notify(uint8_t *data, uint16_t length); + + +#endif //BLE_RDTSS_16BIT_SERVER + +/// @} APP + +#endif // APP_RDTSS_16BIT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_usart.h new file mode 100644 index 0000000..754d7e9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_usart.h @@ -0,0 +1,152 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTx_DAT_Base (USART1_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART1_RX +#define USARTx_IRQn USART1_IRQn +#define USARTx_IRQHandler USART1_IRQHandler +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define USARTx_DAT_Base (USART2_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#define USARTx_IRQn USART2_IRQn +#define USARTx_IRQHandler USART2_IRQHandler +#endif + + +#define USART_RX_DMA_SIZE 256 +#define USART_RX_FIFO_SIZE 1000 +#define USART_TX_FIFO_SIZE 1000 + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + +/* Public function prototypes -----------------------------------------------*/ + +void app_usart_configuration(void); +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len); +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len); +void app_usart_tx_data_blocking(uint8_t *p_data, uint16_t len); + +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len); +void usart_forward_to_ble_loop(void); +void app_usart_dma_enable(FunctionalState Cmd); +void app_usart_tx_process(void); +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_user_config.h new file mode 100644 index 0000000..24144a4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/inc/app_user_config.h @@ -0,0 +1,145 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_RDTSS" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 0//30 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + +// Advertise data +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_DEVICE_INFORMATION_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (5000) /**< Time of initiating event to update connection params (5 seconds). */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 0 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +/* profiles config */ +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +#define CFG_APP_BATT 1 +#define CFG_PRF_BASS 1 +#define CFG_PRF_RDTSS_16BIT 1 + + +#ifdef BLE_OTA_ENABLE +#define CFG_APP_NS_IUS 1 +#endif + +/* User config */ + +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 1 + +#define NS_TIMER_ENABLE 1 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + + + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/readme.txt new file mode 100644 index 0000000..534cf31 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/readme.txt @@ -0,0 +1,30 @@ +1. Function description + + Bluetooth BLE data transmission service (rdts) routine, using 16bit UUID. After the BLE host connects to the device, + the downtream data will be transparently transmitted to USART1, and the data received by USART1 will be transparently transmitted to the BLE host + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB1(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 4. Bluetooth BLE name: NS_RDTSS + 5. LED1 lights up when it is turned on, LED2 indicates the connection status, and lights up when Bluetooth is connected + 6. BLE Data: USART1 PB6(TX) and PB7(RX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + usage method: + 1. Burn to development board after compilation + 2. Power on development board and check the log. + 3. Connect the master device, and send data via USART1 each other. + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_ble.c new file mode 100644 index 0000000..026cc67 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_ble.c @@ -0,0 +1,364 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API + +#include "app_ble.h" +#include "app_usart.h" +#include "app_gpio.h" + +#include "ns_sec.h" +#include "app_rdtss_16bit.h" +#include "app_dis.h" +#include "app_batt.h" +#if (BLE_APP_NS_IUS) +#include "app_ns_ius.h" +#endif //BLE_APP_NS_IUS +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_CUSTS_TEST_EVT: + app_usart_tx_process(); + break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + #if (EX_ADV_TEST_ENABLE) + user_adv.ex_adv_enable = true; + const static uint8_t ex_adv[] = {"\x0D\x09RDTSS-EX_ADV\x29\xff""1234567890123456789012345678901234567890"}; + user_adv.ex_adv_p_data = (uint8_t*)ex_adv; + user_adv.ex_adv_data_len = 14+42; + #if (CODED_ADV_TEST_ENABLE) + user_adv.adv_phy = PHY_CODED_VALUE; + #endif + #endif + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + #if (BLE_APP_DIS) + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); + #endif //BLE_APP_DIS + #if (BLE_APP_BATT) + //add battery level server + ns_ble_add_prf_func_register(app_batt_add_bas); + #endif //BLE_APP_BATT + #if (BLE_APP_NS_IUS) + ns_ble_add_prf_func_register(app_ns_ius_add_ns_ius); + #endif //BLE_APP_NS_IUS + + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtss_16bit_add_rdtss_16bit); + + + +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + //enable usart receive + app_usart_dma_enable(ENABLE); + LedOn(LED2_PORT,LED2_PIN); + + #if (BLE_APP_BATT) + // Enable Battery Service + app_batt_enable_prf(app_env.conidx); + #endif //(BLE_APP_BATT) + + #if (0) + ns_ble_phy_set(GAP_PHY_125KBPS); + #endif +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising + ns_ble_adv_start(); + + //disable usart receive + app_usart_dma_enable(DISABLE); + LedOff(LED2_PORT,LED2_PIN); +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_batt.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_batt.c new file mode 100644 index 0000000..4b650ba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_batt.c @@ -0,0 +1,257 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +/** + * @addtogroup APP + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include "app_batt.h" // Battery Application Module Definitions +#include "ns_ble.h" // Application Definitions +#include "ns_ble_task.h" // application task definitions +#include "bass_task.h" // health thermometer functions +#include "co_bt.h" +#include "bass.h" +#include "prf_types.h" // Profile common types definition +#include "arch.h" // Platform Definitions +#include "prf.h" +#include + +/* Private define ------------------------------------------------------------*/ +/// Battery Application Module Environment Structure +struct app_batt_env_tag app_batt_env; + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief bat server init + * @param + * @return + * @note + */ +void app_batt_init(void) +{ + // Reset the environment + memset(&app_batt_env, 0, sizeof(struct app_batt_env_tag)); + + // Initial battery level: 100 + app_batt_env.batt_lvl = 100; + + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_BASS; + prf.prf_task_handler = &app_batt_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_BASS; + get_func.prf_itf_get_func = bass_prf_itf_get; + prf_get_itf_func_register(&get_func); + +} + +/** + * @brief add bat server + * @param + * @return + * @note + */ +void app_batt_add_bas(void) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + struct bass_db_cfg* db_cfg; + // Allocate the BASS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct bass_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_BASS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct bass_db_cfg* ) req->param; + + // Add a BAS instance + db_cfg->bas_nb = 1; + // Sending of notifications is supported + db_cfg->features[0] = BAS_BATT_LVL_NTF_SUP; + + // Send the message + ke_msg_send(req); + + app_batt_init(); +} + +/** + * @brief enable batt server profile + * @param + * @return + * @note + */ +void app_batt_enable_prf(uint8_t conidx) +{ + app_batt_env.conidx = conidx; + + // Allocate the message + struct bass_enable_req * req = KE_MSG_ALLOC(BASS_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + + // NTF initial status - Disabled + req->ntf_cfg = PRF_CLI_STOP_NTFIND; + req->old_batt_lvl[0] = 50; + + // Send the message + ke_msg_send(req); +} + +/** + * @brief send battery level + * @param + * @return + * @note + */ +void app_batt_send_lvl(uint8_t batt_lvl) +{ + ASSERT_ERR(batt_lvl <= BAS_BATTERY_LVL_MAX); + + // Allocate the message + struct bass_batt_level_upd_req * req = KE_MSG_ALLOC(BASS_BATT_LEVEL_UPD_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_batt_level_upd_req); + + // Fill in the parameter structure + req->bas_instance = 0; + req->batt_level = batt_lvl; + + // Send the message + ke_msg_send(req); +} + +static int bass_batt_level_ntf_cfg_ind_handler(ke_msg_id_t const msgid, + struct bass_batt_level_ntf_cfg_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +static int batt_level_upd_handler(ke_msg_id_t const msgid, + struct bass_batt_level_upd_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +/** + * @brief + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_batt_msg_dflt_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Drop the message + + return (KE_MSG_CONSUMED); +} + +/* + * LOCAL VARIABLE DEFINITIONS + */ + +/// Default State handlers definition +const struct ke_msg_handler app_batt_msg_handler_list[] = +{ + // Note: first message is latest message checked by kernel so default is put on top. + {KE_MSG_DEFAULT_HANDLER, (ke_msg_func_t)app_batt_msg_dflt_handler}, + + {BASS_BATT_LEVEL_NTF_CFG_IND, (ke_msg_func_t)bass_batt_level_ntf_cfg_ind_handler}, + {BASS_BATT_LEVEL_UPD_RSP, (ke_msg_func_t)batt_level_upd_handler}, +}; + +const struct app_subtask_handlers app_batt_handlers = APP_HANDLERS(app_batt); + +#endif //BLE_APP_BATT + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_ns_ius.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_ns_ius.c new file mode 100644 index 0000000..1846f9b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_ns_ius.c @@ -0,0 +1,248 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ns_ius.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_NS_IUS) + +#include "app_ns_ius.h" +#include +#include "ns_iuss.h" +#include "ns_iuss_task.h" +#include "ns_dfu_ble.h" +#include "attm.h" +#include "ke_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "gattc_task.h" +#include "attm_db.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" +#include "ke_msg.h" +#include "ns_ble.h" +#include "ns_log.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB] = +{ + [NS_IUS_IDX_SVC] = {{0x00,0x28}, PERM(RD, ENABLE),0,0}, + + [NS_IUS_IDX_RC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE),0, 0}, + [NS_IUS_IDX_RC_VAL] = {CHAR_NS_IUS_RC, PERM(WRITE_COMMAND, ENABLE), PERM_VAL(UUID_LEN, 0x02), 247}, + [NS_IUS_IDX_RC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + [NS_IUS_IDX_CC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + [NS_IUS_IDX_CC_VAL] = {CHAR_NS_IUS_CC, PERM(WRITE_REQ, ENABLE) | PERM(NTF, ENABLE) , PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 20 }, + [NS_IUS_IDX_CC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + + + + + +static bool notification_enable = false; + + + + + +static int ns_ius_val_write_ind_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + const struct ns_ius_val_write_ind *p_param = (const struct ns_ius_val_write_ind *)param; + + switch (p_param->handle) + { + case NS_IUS_IDX_CC_CFG:{ + + if(p_param->length == 2) + { + uint16_t cfg_value = p_param->value[0] + p_param->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + notification_enable = true; + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + notification_enable = false; + } + NS_LOG_DEBUG("notification_enable %d\r\n",notification_enable); + } + + }break; + + + case NS_IUS_IDX_CC_VAL:{ + uint8_t output[20]; + uint8_t output_len = 0; + ns_dfu_ble_handler_cc(p_param->value, p_param->length, output, &output_len); + if(output_len)ns_ble_ius_app_cc_send(output, output_len); + }break; + + case NS_IUS_IDX_RC_VAL:{ + ns_dfu_ble_handler_rc(p_param->value, p_param->length); + }break; + default: + break; + + } + + return KE_MSG_CONSUMED; +} + + + +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length) +{ + uint8_t state = ke_state_get(ns_ble_ius_task); + if (state == NS_IUS_BUSY || notification_enable == false) + { + return; + } + ke_state_set(ns_ble_ius_task, NS_IUS_BUSY); + + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + struct gattc_send_evt_cmd * req = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, KE_BUILD_ID(TASK_GATTC, app_env.conidx), ns_ius_env->prf_env.prf_task, gattc_send_evt_cmd, length); + req->operation = GATTC_NOTIFY; + req->handle = ns_ius_env->shdl + NS_IUS_IDX_CC_VAL; + req->length = length; + memcpy(req->value, p_data, length); + ke_msg_send(req); +} + + + +static int ns_ius_disconnect_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + notification_enable = false; + return KE_MSG_CONSUMED; +} + + +const struct ke_msg_handler ns_ius_app_msg_handler_list[] = +{ + {NS_IUS_VAL_WRITE_IND, ns_ius_val_write_ind_handler}, + {NS_IUS_DISCONNECT, ns_ius_disconnect_handler}, +}; + + +const struct app_subtask_handlers ns_ius_app_handlers = APP_HANDLERS(ns_ius_app); + + + + + + + +void app_ns_ius_add_ns_ius(void) +{ + Qflash_Init(); + + struct ns_ius_db_cfg *db_cfg; + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct ns_ius_db_cfg)); + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_NS_IUS; + req->app_task = TASK_APP; + req->start_hdl = 0; + db_cfg = (struct ns_ius_db_cfg *) req->param; + db_cfg->att_tbl = NULL; + db_cfg->cfg_flag = 0; + db_cfg->features = 0; + ke_msg_send(req); + + app_ns_ius_init(); +} + +void app_ns_ius_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_NS_IUS; + prf.prf_task_handler = &ns_ius_app_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_NS_IUS; + get_func.prf_itf_get_func = ns_ius_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + + +#endif //BLE_APP_NS_IUS + + +/// @} APP + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_rdtss_16bit.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_rdtss_16bit.c new file mode 100644 index 0000000..0562496 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_profile/app_rdtss_16bit.c @@ -0,0 +1,308 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss_16bit.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration +#include "stdio.h" +#if (BLE_RDTSS_16BIT_SERVER) + +/* Includes ------------------------------------------------------------------*/ +#include "rdtss_16bit.h" +#include "app_rdtss_16bit.h" +#include "rdtss_16bit_task.h" +#include "gapm_task.h" +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" + + +#include "app_usart.h" + + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +const uint16_t app_rdts_svc_uuid = ATT_SERVICE_AM_SPEED_16; + +const struct attm_desc app_rdts_att_db[RDTSS_16BIT_IDX_NB] = +{ + /* Service Declaration */ + [0] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), 0, 0 }, + + /* Characteristic Declaration */ + [1] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [2] = {ATT_CHAR_AM_SPEED_WRITE_16, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [3] = {ATT_DESC_CHAR_USER_DESCRIPTION, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + /* Characteristic Declaration */ + [4] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [5] = {ATT_CHAR_AM_SPEED_NTF_16, PERM(NTF, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [6] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE) |PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, +}; + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtss_16bit_add_rdtss_16bit(void) +{ + struct rdtss_16bit_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtss_16bit_db_cfg)); + NS_LOG_DEBUG("%s\r\n",__func__); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSS_16BIT; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtss_16bit_db_cfg *) req->param; + // Attribute table. In case the handle offset needs to be saved + db_cfg->att_tbl = &app_rdts_att_db[0]; + db_cfg->svc_uuid = &app_rdts_svc_uuid; + db_cfg->max_nb_att = RDTSS_16BIT_IDX_NB; + // Send the message + ke_msg_send(req); + + app_rdtss_16bit_init(); +} + +/** + * @brief rdtss value require indicate handler + * @param + * @return + * @note Note + */ +static int rdtss_16bit_value_req_ind_handler(ke_msg_id_t const msgid, + struct rdtss_16bit_value_req_ind const *req_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + len = APP_RDTSS_16BIT_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_RDTSS_16BIT_MANUFACTURER_NAME; + + + // Allocate confirmation to send the value + struct rdtss_16bit_value_req_rsp *rsp_value = KE_MSG_ALLOC_DYN(RDTSS_16BIT_VALUE_REQ_RSP, + src_id, dest_id, + rdtss_16bit_value_req_rsp, + len); + + rsp_value->length = len; + rsp_value->att_idx = req_value->att_idx; + if (len) + { + // Copy data + memcpy(&rsp_value->value, data, len); + } + // Send message + ke_msg_send(rsp_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief cuusts write indicate handler + * @param + * @return + * @note + */ +static int rdtss_16bit_val_write_ind_handler(ke_msg_id_t const msgid, + struct rdtss_16bit_val_write_ind const *ind_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,write handle = %x,length = %x\r\n",__func__ ,ind_value->handle, ind_value->length); + + for(uint16_t i=0; ilength; i++) + { + NS_LOG_DEBUG("%x ",ind_value->value[i]); + } + NS_LOG_DEBUG("\r\n"); + + uint16_t handle = ind_value->handle; + uint16_t length = ind_value->length; + + switch (handle) + { + case RDTSS_16BIT_IDX_NTF_CFG: + + NS_LOG_DEBUG("RDTSS_16BIT_IDX_NTF_CFG\r\n"); + + if(length == 2) + { + uint16_t cfg_value = ind_value->value[0] + ind_value->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + //enabled notify + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + } + } + + break; + case RDTSS_16BIT_IDX_WRITE_VAL: + NS_LOG_DEBUG("RDTSS_16BIT_IDX_WRITE_VAL\r\n"); + app_usart_tx_fifo_enter(ind_value->value,ind_value->length); + break; + default: + break; + + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Functions + * @param + * @return + * @note Note + */ +static int rdtss_16bit_val_ntf_cfm_handler(ke_msg_id_t const msgid, + struct rdtss_16bit_val_ntf_cfm const *cfm_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,ntf cfm handle = %x, status = %x\r\n",__func__, cfm_value->handle, cfm_value->status); + + usart_forward_to_ble_loop(); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief rdtss_16bit send notify + * @param + * @return + * @note + */ +void rdtss_16bit_send_notify(uint8_t *data, uint16_t length) +{ + struct rdtss_16bit_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(RDTSS_16BIT_VAL_NTF_REQ, + prf_get_task_from_id(TASK_ID_RDTSS_16BIT), + TASK_APP, + rdtss_16bit_val_ntf_ind_req, + length); + + req->conidx = app_env.conidx; + req->notification = true; + req->handle = RDTSS_16BIT_IDX_NTF_VAL; + req->length = length; + memcpy(&req->value[0], data, length); + + ke_msg_send(req); +} + + +/// Default State handlers definition +const struct ke_msg_handler app_rdtss_16bit_msg_handler_list[] = +{ + {RDTSS_16BIT_VALUE_REQ_IND, (ke_msg_func_t)rdtss_16bit_value_req_ind_handler}, + {RDTSS_16BIT_VAL_WRITE_IND, (ke_msg_func_t)rdtss_16bit_val_write_ind_handler}, + {RDTSS_16BIT_VAL_NTF_CFM, (ke_msg_func_t)rdtss_16bit_val_ntf_cfm_handler}, + +}; + +const struct app_subtask_handlers app_rdtss_16bit_handlers = APP_HANDLERS(app_rdtss_16bit); + +void app_rdtss_16bit_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSS_16BIT; + prf.prf_task_handler = &app_rdtss_16bit_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSS_16BIT; + get_func.prf_itf_get_func = rdtss_16bit_prf_itf_get; + prf_get_itf_func_register(&get_func); + +} + +#endif //BLE_RDTSS_16BIT_SERVER diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_usart.c new file mode 100644 index 0000000..928fc6c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/app_usart.c @@ -0,0 +1,575 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include +#include "global_func.h" +#include "app_usart.h" +#include "ns_sleep.h" +#include "ns_log.h" +#include "ns_timer.h" +#include "ke_timer.h" +#include "app_ble.h" + +#if (CFG_PRF_RDTSS) +#include "rdtss_task.h" +#include "app_rdtss.h" +#endif +#if (CFG_PRF_RDTSS_16BIT) +#include "rdtss_16bit_task.h" +#include "app_rdtss_16bit.h" +#endif +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] = {0}; +uint16_t rx_old_pos = 0; + +uint8_t usart_rx_fifo_buf[USART_RX_FIFO_SIZE] = {0}; +uint32_t usart_rx_fifo_in = 0; +uint32_t usart_rx_fifo_out = 0; + + +uint8_t usart_tx_fifo_buf[USART_TX_FIFO_SIZE] = {0}; +uint32_t usart_tx_fifo_in = 0; +uint32_t usart_tx_fifo_out = 0; + +uint8_t usart_sending = false; +uint8_t ble_sending = false; +uint16_t ble_att_mtu = (ATT_DEFAULT_MTU-3); + +/* Private function prototypes -----------------------------------------------*/ +void app_usart_tx_process(void); + +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTx_Tx_DMA_Channel); + DMA_RequestRemap(USARTx_Tx_DMA_REMAP, DMA, USARTx_Tx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Tx_DMA_Channel,DMA_INT_TXC ,ENABLE); + + /* USARTx RX DMA1 Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTx_Rx_DMA_Channel); + DMA_RequestRemap(USARTx_Rx_DMA_REMAP, DMA, USARTx_Rx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Rx_DMA_Channel,DMA_INT_TXC|DMA_INT_HTX ,ENABLE); + + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)USART_rx_dma_buf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = USART_RX_DMA_SIZE; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Rx_DMA_Channel, &DMA_InitStructure); + +} + + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + NVIC_DisableIRQ(DMA_Channel1_2_3_4_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + NVIC_DisableIRQ(USARTx_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void app_usart_configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* Configure the DMA */ + DMA_Configuration(); + + NVIC_Configuration(); + + /* USARTx and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; //921600 + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTx, USART_INT_IDLEF, ENABLE); + + /* Enable USARTx DMA Rx and TX request */ + USART_EnableDMA(USARTx, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief enable or disable the usart dma + */ +void app_usart_dma_enable(FunctionalState Cmd) +{ + if(Cmd == ENABLE) + { + ns_sleep_lock_acquire(); + rx_old_pos = 0; + usart_tx_fifo_in = usart_tx_fifo_out = 0; //clean fifo + usart_rx_fifo_in = usart_rx_fifo_out = 0; //clean fifo + app_usart_configuration(); + + } + else{ + ns_sleep_lock_release(); + USART_Enable(USARTx, DISABLE); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, DISABLE); + DMA_EnableChannel(USARTx_Tx_DMA_Channel, DISABLE); + /* Deinit IO of USART to save power */ + GPIO_InitType GPIO_InitStructure; + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + } +} + +/** + * @brief forward usart rx data too ble notify + */ +void usart_forward_to_ble_loop(void) +{ + uint32_t in_temp; + uint16_t ble_send_len; + + in_temp = usart_rx_fifo_in; + if(usart_rx_fifo_out < in_temp) + { + ble_send_len = in_temp-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out > in_temp){ + ble_send_len = USART_RX_FIFO_SIZE-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out == in_temp){ + // fifo empty, stop send loop + ble_sending = false; + return; + } + if ((app_env.max_mtu-3)> ble_att_mtu) + { + ble_att_mtu = (app_env.max_mtu-3); + } + if(ble_send_len > ble_att_mtu) + { + ble_send_len = ble_att_mtu; + } + ble_sending = true; + #if (BLE_RDTSS_SERVER) + rdtss_send_notify( &usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + #endif + + #if (BLE_RDTSS_16BIT_SERVER) + rdtss_16bit_send_notify( &usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + #endif + usart_rx_fifo_out = (usart_rx_fifo_out+ble_send_len)%USART_RX_FIFO_SIZE; + + return; +} + + +/** + * @brief usart rx data enter fifo and active ble send first package if not active yet + */ +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len; + //store data in fifo + while(len) + { + if(usart_rx_fifo_in >= usart_rx_fifo_out ) + { + in_len = USART_RX_FIFO_SIZE-usart_rx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + } + else if(usart_rx_fifo_in < usart_rx_fifo_out ) + { + in_len = usart_rx_fifo_out-usart_rx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,usart_rx_fifo_in,usart_rx_fifo_out); + } + break; + } + } + if(!ble_sending) + { + // active send ble event after usart streaming cut + ke_timer_set(RDTSS_16BIT_VAL_NTF_CFM, TASK_APP, 10); + } + + return len; +} + +/** + * @brief usart send data via dma + */ +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len) +{ + DMA_InitType DMA_InitStructure; + + if(usart_sending) + { + return false; + } + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)p_data; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = len; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Tx_DMA_Channel, &DMA_InitStructure); + + usart_sending = true; + DMA_EnableChannel(USARTx_Tx_DMA_Channel, ENABLE); + + return true; +} + +/** + * @brief usart send data in blocking mode + */ +void usart_tx_data_blocking(uint8_t *p_data, uint16_t len) +{ + while(len--) + { + USART_SendData(USARTx, *p_data); + p_data++; + } +} + +/** + * @brief usart tx fifo enter and active dma send out + */ +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len, out_temp; + //store data in fifo + NS_LOG_DEBUG("%d,%d,%d\r\n",len,usart_tx_fifo_in,usart_tx_fifo_out); + out_temp = usart_tx_fifo_out; + while(len) + { + if(usart_tx_fifo_in >= out_temp ) + { + in_len = USART_TX_FIFO_SIZE-usart_tx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + } + else if(usart_tx_fifo_in < out_temp ) + { + in_len = out_temp-usart_tx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,usart_tx_fifo_in,out_temp); + } + + break; + } + } + + // ble treaming cut timer, active usart send after it. + ke_timer_set(APP_CUSTS_TEST_EVT, TASK_APP, 50); + + return len; +} + +/** + * @brief usart tx data from fifo + */ +void app_usart_tx_process(void) +{ + uint32_t in_temp,len; + uint8_t *p_data; + + in_temp = usart_tx_fifo_in; + if(usart_tx_fifo_out < in_temp) + { + len = in_temp-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = in_temp; + } + + } + else if(usart_tx_fifo_out > in_temp) + { + len = USART_TX_FIFO_SIZE-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = 0; + } + + } +} + + +/** + * @brief check the dma buffer which has been received + */ +void usart_rx_check_in_irq(void) +{ + uint16_t rx_pos; + + rx_pos = USART_RX_DMA_SIZE - DMA_GetCurrDataCounter(USARTx_Rx_DMA_Channel); + if(rx_pos < rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(USART_RX_DMA_SIZE - rx_old_pos)); + + if(rx_pos > 0) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[0],rx_pos); + } + + rx_old_pos = rx_pos; + } + else if(rx_pos > rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(rx_pos - rx_old_pos)); + rx_old_pos = rx_pos; + } + else if(rx_pos != rx_old_pos) + { + //error + rx_old_pos = rx_pos; + } + +} + + +/** + * @brief dma irq handler + */ +void DMA_Channel1_2_3_4_IRQHandler(void) +{ + //TX + if(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)) + { + //TX Transfer complete interrupt + usart_sending = false; + ke_msg_send_basic(APP_CUSTS_TEST_EVT, TASK_APP, TASK_APP); + + DMA_ClearFlag(DMA_FLAG_TC1, DMA); + } + //RX + if(DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + //RX Transfer complete interrupt + DMA_ClearFlag(DMA_FLAG_TC2, DMA); + usart_rx_check_in_irq(); + + } + if(DMA_GetFlagStatus(DMA_FLAG_HT2, DMA)) + { + //RX Half transfer interrupt + DMA_ClearFlag(DMA_FLAG_HT2, DMA); + usart_rx_check_in_irq(); + } + +} + +/** + * @brief usart irq handler + */ +void USARTx_IRQHandler(void) +{ + uint8_t temp; + //usart idlle interrupt + if(USART_GetFlagStatus(USARTx,USART_FLAG_IDLEF)) + { + //read sts and data will clear rx idle interrupt + temp = USARTx->DAT; + usart_rx_check_in_irq(); + (void)temp; + } + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/main.c new file mode 100644 index 0000000..50b2a93 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_16bit/src/main.c @@ -0,0 +1,160 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_ble.h" +#if (CFG_APP_NS_IUS) +#include "ns_dfu_boot.h" +#endif + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING raw data transfer server(16bit UUID) demo \r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + + NS_LOG_INIT(); + + #if (CFG_APP_NS_IUS) + if(CURRENT_APP_START_ADDRESS == NS_APP1_START_ADDRESS){ + NS_LOG_INFO("application 1 start new ...\r\n"); + }else if(CURRENT_APP_START_ADDRESS == NS_APP2_START_ADDRESS){ + NS_LOG_INFO("application 2 start new ...\r\n"); + } + #endif + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + app_usart_dma_enable(ENABLE); + //init text + usart_tx_dma_send((uint8_t*)DEMO_STRING, sizeof(DEMO_STRING)); + + delay_n_10us(500); + //disable usart for enter sleep + app_usart_dma_enable(DISABLE); + + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/MDK-ARM/rdtss.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/MDK-ARM/rdtss.uvoptx new file mode 100644 index 0000000..b40a15d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/MDK-ARM/rdtss.uvoptx @@ -0,0 +1,1191 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + OTA_IMG_1 + 0x4 + ARM-ADS + + 64000000 + + 0 + 1 + 1 + 0 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 0 + + 255 + + 1 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + -1 + + + + + + + + + + + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + OTA_IMG_2 + 0x4 + ARM-ADS + + 64000000 + + 0 + 1 + 1 + 0 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 0 + + 255 + + 1 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + -1 + + + + + + + + + + + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + lib_att.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + bass.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + bass_task.c + 0 + 0 + + + 5 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + rdtss.c + 0 + 0 + + + 5 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + rdtss_task.c + 0 + 0 + + + 5 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + rdts_common.c + 0 + 0 + + + 5 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + ns_iuss.c + 0 + 0 + + + 5 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + ns_iuss_task.c + 0 + 0 + + + + + NS_DFU + 0 + 0 + 0 + 0 + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_crc.c + dfu_crc.c + 0 + 0 + + + 6 + 30 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_delay.c + dfu_delay.c + 0 + 0 + + + 6 + 31 + 1 + 0 + 0 + 0 + ..\..\..\dfu\common\dfu_led.c + dfu_led.c + 0 + 0 + + + 6 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + ns_dfu_ble.c + 0 + 0 + + + 6 + 33 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + ns_dfu_boot.c + 0 + 0 + + + + + Crypto + 0 + 0 + 0 + 0 + + 7 + 34 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + ns_ecc.c + 0 + 0 + + + 7 + 35 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + sha256.c + 0 + 0 + + + 7 + 36 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + uECC.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 8 + 37 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 8 + 38 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 8 + 39 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 8 + 40 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 8 + 41 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 8 + 42 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 8 + 43 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 9 + 44 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 9 + 45 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_batt.c + app_batt.c + 0 + 0 + + + 9 + 46 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtss.c + app_rdtss.c + 0 + 0 + + + 9 + 47 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_ns_ius.c + app_ns_ius.c + 0 + 0 + + + 9 + 48 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 10 + 49 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 10 + 50 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + 10 + 51 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 11 + 52 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 12 + 53 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/MDK-ARM/rdtss.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/MDK-ARM/rdtss.uvprojx new file mode 100644 index 0000000..e6cd460 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/MDK-ARM/rdtss.uvprojx @@ -0,0 +1,2618 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdts + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\rdts.bin .\Objects\rdts.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + + + NS_DFU + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + OTA_IMG_1 + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtss_ota + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\rdtss_ota.bin .\Objects\rdtss_ota.axf + cmd.exe /C copy .\bin\rdtss_ota.bin ..\..\..\..\..\utilities\dfu\Image\APP1.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1004000 + 0x1c000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, APPLICATION, BLE_OTA_ENABLE + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\dfu\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + + + NS_DFU + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + OTA_IMG_2 + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtss_ota + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\rdtss_ota.bin .\Objects\rdtss_ota.axf + cmd.exe /C copy .\bin\rdtss_ota.bin ..\..\..\..\..\utilities\dfu\Image\APP2.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1020000 + 0x1c000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, APPLICATION, BLE_OTA_ENABLE + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\dfu\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + bass.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass.c + + + bass_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\src\bass_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + + + NS_DFU + + + dfu_crc.c + 1 + ..\..\..\dfu\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\..\dfu\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\..\dfu\common\dfu_led.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_batt.c + 1 + ..\src\app_profile\app_batt.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_ble.h new file mode 100644 index 0000000..0d16f44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_batt.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_batt.h new file mode 100644 index 0000000..5fc237b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_batt.h @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef APP_BATT_H_ +#define APP_BATT_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include // Standard Integer Definition +#include "ke_task.h" // Kernel Task Definition + +/* Public typedef -----------------------------------------------------------*/ + +/// Battery Application Module Environment Structure +struct app_batt_env_tag +{ + /// Connection handle + uint8_t conidx; + /// Current Battery Level + uint8_t batt_lvl; +}; + +/* Public variables ---------------------------------------------------------*/ + +/// Battery Application environment +extern struct app_batt_env_tag app_batt_env; + +/// Table of message handlers +extern const struct app_subtask_handlers app_batt_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * + * Health Thermometer Application Functions + * + **/ + +/** + * @brief Initialize Battery Application Module + **/ +void app_batt_init(void); + +/** + * @brief Add a Battery Service instance in the DB + **/ +void app_batt_add_bas(void); + +/** + * @brief Enable the Battery Service + **/ +void app_batt_enable_prf(uint8_t conidx); + +/** + * @brief Send a Battery level value + **/ +void app_batt_send_lvl(uint8_t batt_lvl); + +#endif //(BLE_APP_BATT) + +/// @} APP + +#endif // APP_BATT_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_ns_ius.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_ns_ius.h new file mode 100644 index 0000000..726f13b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_ns_ius.h @@ -0,0 +1,105 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ns_ius.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef __APP_NS_IUS_H__ +#define __APP_NS_IUS_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#include "prf_types.h" +#include "prf.h" + + +#if (BLE_APP_NS_IUS) +/* Public typedef -----------------------------------------------------------*/ +enum +{ + NS_IUS_IDX_SVC, + + NS_IUS_IDX_RC_CHAR, + NS_IUS_IDX_RC_VAL, + NS_IUS_IDX_RC_CFG, + + NS_IUS_IDX_CC_CHAR, + NS_IUS_IDX_CC_VAL, + NS_IUS_IDX_CC_CFG, + + NS_IUS_IDX_NB, +}; + +/* Public define ------------------------------------------------------------*/ +#define SERVICE_NS_IUS {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, 0x01,0x00, 0x11,0x11} +#define CHAR_NS_IUS_RC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x02,0x00, 0x11,0x11} +#define CHAR_NS_IUS_CC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x03,0x00, 0x11,0x11} + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ +extern struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB]; +/* Public function prototypes -----------------------------------------------*/ +extern const struct app_subtask_handlers ns_ius_app_handlers; + +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length); +void app_ns_ius_add_ns_ius(void); +void app_ns_ius_init(void); + +#endif //BLE_APP_NS_IUS + +#endif //__APP_NS_IUS_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_rdtss.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_rdtss.h new file mode 100644 index 0000000..ff19814 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/app_rdtss.h @@ -0,0 +1,120 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSS_H_ +#define APP_RDTSS_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/// Manufacturer Name Value +#define APP_RDTSS_MANUFACTURER_NAME ("NSING") +#define APP_RDTSS_MANUFACTURER_NAME_LEN (5) + + + +#define ATT_SERVICE_AM_SPEED_128 {0x01,0x10,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Service UUID */ +#define ATT_CHAR_AM_SPEED_WRITE_128 {0x01,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_NTF_128 {0x02,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ + + +/// rdtss Service Attributes Indexes +enum +{ + RDTSS_IDX_SVC, + + RDTSS_IDX_WRITE_CHAR, + RDTSS_IDX_WRITE_VAL, + RDTSS_IDX_WRITE_CFG, + + RDTSS_IDX_NTF_CHAR, + RDTSS_IDX_NTF_VAL, + RDTSS_IDX_NTF_CFG, + + RDTSS_IDX_NB, +}; + + +/** + * @brief Initialize Device Information Service Application + **/ +void app_rdtss_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_rdtss_add_rdts(void); +void rdtss_send_notify_all(uint8_t *data, uint16_t length); +void rdtss_send_notify(uint8_t *data, uint16_t length); + +#endif //BLE_RDTSS_SERVER + +/// @} APP + +#endif // APP_RDTSS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_usart.h new file mode 100644 index 0000000..754d7e9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_usart.h @@ -0,0 +1,152 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTx_DAT_Base (USART1_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART1_RX +#define USARTx_IRQn USART1_IRQn +#define USARTx_IRQHandler USART1_IRQHandler +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define USARTx_DAT_Base (USART2_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#define USARTx_IRQn USART2_IRQn +#define USARTx_IRQHandler USART2_IRQHandler +#endif + + +#define USART_RX_DMA_SIZE 256 +#define USART_RX_FIFO_SIZE 1000 +#define USART_TX_FIFO_SIZE 1000 + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + +/* Public function prototypes -----------------------------------------------*/ + +void app_usart_configuration(void); +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len); +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len); +void app_usart_tx_data_blocking(uint8_t *p_data, uint16_t len); + +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len); +void usart_forward_to_ble_loop(void); +void app_usart_dma_enable(FunctionalState Cmd); +void app_usart_tx_process(void); +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_user_config.h new file mode 100644 index 0000000..935c9e8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/inc/app_user_config.h @@ -0,0 +1,149 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "MS_NS_RDTSS" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 0//30 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + +// Advertise data +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_DEVICE_INFORMATION_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (3000) /**< Time of initiating event to update connection params (5 seconds). */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 0 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +/* profiles config */ +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +//#define CFG_APP_BATT 1 +//#define CFG_PRF_BASS 1 +#define CFG_PRF_RDTSS 1 +#define BLE_SLAVE_CONN 3 // make sure less than APP_CON_IDX_MAX +#if (BLE_SLAVE_CONN > 3) +#error BLE_SLAVE_CONN exceed APP_CON_IDX_MAX +#endif + + +#ifdef BLE_OTA_ENABLE +#define CFG_APP_NS_IUS 1 +#endif + +/* User config */ + +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 1 + +#define NS_TIMER_ENABLE 1 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + + + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/readme.txt new file mode 100644 index 0000000..2fcd504 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/readme.txt @@ -0,0 +1,35 @@ +1. Function description + + Bluetooth BLE data transmission service (rdts) example, using 128bit UUID. + After the BLE host connects to the device, the downlink data will be transparently + transmitted to USART1, and the data received by USART1 will be transparently + transmitted to the BLE host. + This example will allow connect to 3 master at the same time. The first byte will + be the connection to send if it in 0x00 to 0x02, otherwise send the data to all connection. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB1(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 4. Bluetooth BLE name: NS_RDTSS + 5. LED1 lights up when it is turned on, LED2 indicates the connection status, and lights up when Bluetooth is connected + 6. BLE Data: USART1 PB6(TX) and PB7(RX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + usage method: + 1. Burn to development board after compilation + 2. Power on development board and check the log. + 3. Connect the master device, and send data via USART1 each other. + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. + Press the RESET button to execute the program burning step within one second. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_ble.c new file mode 100644 index 0000000..0a9a339 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_ble.c @@ -0,0 +1,355 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "ns_sec.h" +#include "app_ble.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_rdtss.h" +#include "app_dis.h" +#include "app_batt.h" +#if (BLE_APP_NS_IUS) +#include "app_ns_ius.h" +#endif //BLE_APP_NS_IUS +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_CUSTS_TEST_EVT: + app_usart_tx_process(); + break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + case APP_ADV_MODE_STOP: + if (ns_ble_get_connection_num() < BLE_SLAVE_CONN) + { + ns_ble_adv_start(); + } + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x0E\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + #if (BLE_APP_DIS) + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); + #endif //BLE_APP_DIS + #if (BLE_APP_BATT) + //add battery level server + ns_ble_add_prf_func_register(app_batt_add_bas); + #endif //BLE_APP_BATT + #if (BLE_APP_NS_IUS) + ns_ble_add_prf_func_register(app_ns_ius_add_ns_ius); + #endif //BLE_APP_NS_IUS + + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtss_add_rdts); + + + +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + //enable usart receive + app_usart_dma_enable(ENABLE); + LedOn(LED2_PORT,LED2_PIN); + + #if (BLE_APP_BATT) + // Enable Battery Service + app_batt_enable_prf(app_env.conidx); + #endif //(BLE_APP_BATT) +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising + ns_ble_adv_start(); + + if (ns_ble_get_connection_num() == 0) + { + //disable usart receive + app_usart_dma_enable(DISABLE); + LedOff(LED2_PORT,LED2_PIN); + } +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_batt.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_batt.c new file mode 100644 index 0000000..4b650ba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_batt.c @@ -0,0 +1,257 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_batt.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + + +/** + * @addtogroup APP + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_BATT) + +#include "app_batt.h" // Battery Application Module Definitions +#include "ns_ble.h" // Application Definitions +#include "ns_ble_task.h" // application task definitions +#include "bass_task.h" // health thermometer functions +#include "co_bt.h" +#include "bass.h" +#include "prf_types.h" // Profile common types definition +#include "arch.h" // Platform Definitions +#include "prf.h" +#include + +/* Private define ------------------------------------------------------------*/ +/// Battery Application Module Environment Structure +struct app_batt_env_tag app_batt_env; + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief bat server init + * @param + * @return + * @note + */ +void app_batt_init(void) +{ + // Reset the environment + memset(&app_batt_env, 0, sizeof(struct app_batt_env_tag)); + + // Initial battery level: 100 + app_batt_env.batt_lvl = 100; + + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_BASS; + prf.prf_task_handler = &app_batt_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_BASS; + get_func.prf_itf_get_func = bass_prf_itf_get; + prf_get_itf_func_register(&get_func); + +} + +/** + * @brief add bat server + * @param + * @return + * @note + */ +void app_batt_add_bas(void) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + struct bass_db_cfg* db_cfg; + // Allocate the BASS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct bass_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_BASS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct bass_db_cfg* ) req->param; + + // Add a BAS instance + db_cfg->bas_nb = 1; + // Sending of notifications is supported + db_cfg->features[0] = BAS_BATT_LVL_NTF_SUP; + + // Send the message + ke_msg_send(req); + + app_batt_init(); +} + +/** + * @brief enable batt server profile + * @param + * @return + * @note + */ +void app_batt_enable_prf(uint8_t conidx) +{ + app_batt_env.conidx = conidx; + + // Allocate the message + struct bass_enable_req * req = KE_MSG_ALLOC(BASS_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + + // NTF initial status - Disabled + req->ntf_cfg = PRF_CLI_STOP_NTFIND; + req->old_batt_lvl[0] = 50; + + // Send the message + ke_msg_send(req); +} + +/** + * @brief send battery level + * @param + * @return + * @note + */ +void app_batt_send_lvl(uint8_t batt_lvl) +{ + ASSERT_ERR(batt_lvl <= BAS_BATTERY_LVL_MAX); + + // Allocate the message + struct bass_batt_level_upd_req * req = KE_MSG_ALLOC(BASS_BATT_LEVEL_UPD_REQ, + prf_get_task_from_id(TASK_ID_BASS), + TASK_APP, + bass_batt_level_upd_req); + + // Fill in the parameter structure + req->bas_instance = 0; + req->batt_level = batt_lvl; + + // Send the message + ke_msg_send(req); +} + +static int bass_batt_level_ntf_cfg_ind_handler(ke_msg_id_t const msgid, + struct bass_batt_level_ntf_cfg_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +static int batt_level_upd_handler(ke_msg_id_t const msgid, + struct bass_batt_level_upd_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + return (KE_MSG_CONSUMED); +} + +/** + * @brief + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + */ +static int app_batt_msg_dflt_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + // Drop the message + + return (KE_MSG_CONSUMED); +} + +/* + * LOCAL VARIABLE DEFINITIONS + */ + +/// Default State handlers definition +const struct ke_msg_handler app_batt_msg_handler_list[] = +{ + // Note: first message is latest message checked by kernel so default is put on top. + {KE_MSG_DEFAULT_HANDLER, (ke_msg_func_t)app_batt_msg_dflt_handler}, + + {BASS_BATT_LEVEL_NTF_CFG_IND, (ke_msg_func_t)bass_batt_level_ntf_cfg_ind_handler}, + {BASS_BATT_LEVEL_UPD_RSP, (ke_msg_func_t)batt_level_upd_handler}, +}; + +const struct app_subtask_handlers app_batt_handlers = APP_HANDLERS(app_batt); + +#endif //BLE_APP_BATT + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_ns_ius.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_ns_ius.c new file mode 100644 index 0000000..1846f9b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_ns_ius.c @@ -0,0 +1,248 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ns_ius.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_NS_IUS) + +#include "app_ns_ius.h" +#include +#include "ns_iuss.h" +#include "ns_iuss_task.h" +#include "ns_dfu_ble.h" +#include "attm.h" +#include "ke_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "gattc_task.h" +#include "attm_db.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" +#include "ke_msg.h" +#include "ns_ble.h" +#include "ns_log.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB] = +{ + [NS_IUS_IDX_SVC] = {{0x00,0x28}, PERM(RD, ENABLE),0,0}, + + [NS_IUS_IDX_RC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE),0, 0}, + [NS_IUS_IDX_RC_VAL] = {CHAR_NS_IUS_RC, PERM(WRITE_COMMAND, ENABLE), PERM_VAL(UUID_LEN, 0x02), 247}, + [NS_IUS_IDX_RC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + [NS_IUS_IDX_CC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + [NS_IUS_IDX_CC_VAL] = {CHAR_NS_IUS_CC, PERM(WRITE_REQ, ENABLE) | PERM(NTF, ENABLE) , PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 20 }, + [NS_IUS_IDX_CC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + + + + + +static bool notification_enable = false; + + + + + +static int ns_ius_val_write_ind_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + const struct ns_ius_val_write_ind *p_param = (const struct ns_ius_val_write_ind *)param; + + switch (p_param->handle) + { + case NS_IUS_IDX_CC_CFG:{ + + if(p_param->length == 2) + { + uint16_t cfg_value = p_param->value[0] + p_param->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + notification_enable = true; + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + notification_enable = false; + } + NS_LOG_DEBUG("notification_enable %d\r\n",notification_enable); + } + + }break; + + + case NS_IUS_IDX_CC_VAL:{ + uint8_t output[20]; + uint8_t output_len = 0; + ns_dfu_ble_handler_cc(p_param->value, p_param->length, output, &output_len); + if(output_len)ns_ble_ius_app_cc_send(output, output_len); + }break; + + case NS_IUS_IDX_RC_VAL:{ + ns_dfu_ble_handler_rc(p_param->value, p_param->length); + }break; + default: + break; + + } + + return KE_MSG_CONSUMED; +} + + + +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length) +{ + uint8_t state = ke_state_get(ns_ble_ius_task); + if (state == NS_IUS_BUSY || notification_enable == false) + { + return; + } + ke_state_set(ns_ble_ius_task, NS_IUS_BUSY); + + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + struct gattc_send_evt_cmd * req = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, KE_BUILD_ID(TASK_GATTC, app_env.conidx), ns_ius_env->prf_env.prf_task, gattc_send_evt_cmd, length); + req->operation = GATTC_NOTIFY; + req->handle = ns_ius_env->shdl + NS_IUS_IDX_CC_VAL; + req->length = length; + memcpy(req->value, p_data, length); + ke_msg_send(req); +} + + + +static int ns_ius_disconnect_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + notification_enable = false; + return KE_MSG_CONSUMED; +} + + +const struct ke_msg_handler ns_ius_app_msg_handler_list[] = +{ + {NS_IUS_VAL_WRITE_IND, ns_ius_val_write_ind_handler}, + {NS_IUS_DISCONNECT, ns_ius_disconnect_handler}, +}; + + +const struct app_subtask_handlers ns_ius_app_handlers = APP_HANDLERS(ns_ius_app); + + + + + + + +void app_ns_ius_add_ns_ius(void) +{ + Qflash_Init(); + + struct ns_ius_db_cfg *db_cfg; + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct ns_ius_db_cfg)); + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_NS_IUS; + req->app_task = TASK_APP; + req->start_hdl = 0; + db_cfg = (struct ns_ius_db_cfg *) req->param; + db_cfg->att_tbl = NULL; + db_cfg->cfg_flag = 0; + db_cfg->features = 0; + ke_msg_send(req); + + app_ns_ius_init(); +} + +void app_ns_ius_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_NS_IUS; + prf.prf_task_handler = &ns_ius_app_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_NS_IUS; + get_func.prf_itf_get_func = ns_ius_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + + +#endif //BLE_APP_NS_IUS + + +/// @} APP + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_rdtss.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_rdtss.c new file mode 100644 index 0000000..271ce68 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_profile/app_rdtss.c @@ -0,0 +1,336 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtss.h" // rdtss Application Module Definitions +#include "rdtss_task.h" // Device Information Profile Functions +#include "gapm_task.h" // GAP Manager Task API +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" +#include "stdio.h" +#include "rdtss.h" +#include "app_usart.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +const uint8_t app_rdts_svc_uuid[16] = ATT_SERVICE_AM_SPEED_128; +const struct attm_desc_128 app_rdts_att_db[RDTSS_IDX_NB] = +{ + /* Service Declaration */ + [0] = {{0x00,0x28}, PERM(RD, ENABLE), 0, 0 }, + + /* Characteristic Declaration */ + [1] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [2] = {ATT_CHAR_AM_SPEED_WRITE_128, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [3] = {{0x01,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + /* Characteristic Declaration */ + [4] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [5] = {ATT_CHAR_AM_SPEED_NTF_128, PERM(NTF, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [6] = {{0x02,0x29}, PERM(RD, ENABLE) |PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, +}; + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtss_add_rdts(void) +{ + struct rdtss_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtss_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtss_db_cfg *) req->param; + // Attribute table. In case the handle offset needs to be saved + db_cfg->att_tbl = &app_rdts_att_db[0]; + db_cfg->svc_uuid = &app_rdts_svc_uuid[0]; + db_cfg->max_nb_att = RDTSS_IDX_NB; + + // Send the message + ke_msg_send(req); + + app_rdtss_init(); +} + +/** + * @brief rdtss value require indicate handler + * @param + * @return + * @note Note + */ +static int rdtss_value_req_ind_handler(ke_msg_id_t const msgid, + struct rdtss_value_req_ind const *req_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + len = APP_RDTSS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_RDTSS_MANUFACTURER_NAME; + + + // Allocate confirmation to send the value + struct rdtss_value_req_rsp *rsp_value = KE_MSG_ALLOC_DYN(RDTSS_VALUE_REQ_RSP, + src_id, dest_id, + rdtss_value_req_rsp, + len); + rsp_value->status = 0; + rsp_value->conidx = req_value ->conidx; + rsp_value->length = len; + rsp_value->att_idx = req_value->att_idx; + rsp_value->conidx = req_value->conidx; + if (len) + { + // Copy data + memcpy(&rsp_value->value, data, len); + } + // Send message + ke_msg_send(rsp_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief cuusts write indicate handler + * @param + * @return + * @note + */ +static int rdtss_val_write_ind_handler(ke_msg_id_t const msgid, + struct rdtss_val_write_ind const *ind_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,write handle = %x,length = %x\r\n",__func__ ,ind_value->handle, ind_value->length); + + for(uint16_t i=0; ilength; i++) + { + NS_LOG_DEBUG("%x ",ind_value->value[i]); + } + NS_LOG_DEBUG("\r\n"); + + uint16_t handle = ind_value->handle; + uint16_t length = ind_value->length; + + switch (handle) + { + case RDTSS_IDX_NTF_CFG: + + if(length == 2) + { + uint16_t cfg_value = ind_value->value[0] + ind_value->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + //enabled notify + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + } + } + + break; + case RDTSS_IDX_WRITE_VAL: + //ble data receive + app_usart_tx_fifo_enter(ind_value->value,ind_value->length); + + break; + default: + break; + + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Functions + * @param + * @return + * @note Note + */ +static int rdtss_val_ntf_cfm_handler(ke_msg_id_t const msgid, + struct rdtss_val_ntf_cfm const *cfm_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,ntf cfm handle = %x, status = %x\r\n",__func__, cfm_value->handle, cfm_value->status); + + usart_forward_to_ble_loop(); + + return (KE_MSG_CONSUMED); +} + + +/** + * @brief rdtss send notify to all connection + * @param + * @return + * @note + */ +void rdtss_send_notify_all(uint8_t *data, uint16_t length) +{ + for(int i = 0; i < BLE_SLAVE_CONN; i++) + { + if(app_env.conn_env[i].conidx != 0xff) + { + struct rdtss_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(RDTSS_VAL_NTF_REQ, + prf_get_task_from_id(TASK_ID_RDTSS), + TASK_APP, + rdtss_val_ntf_ind_req, + length); + + req->conidx = i; + //req->notification = true; + req->handle = RDTSS_IDX_NTF_VAL; + req->length = length; + memcpy(&req->value[0], data, length); + NS_LOG_INFO("%s,conidx = %d\r\n",__func__, req->conidx); + ke_msg_send(req); + } + } +} + +/** + * @brief rdtss send notify + * @param + * @return + * @note + */ +void rdtss_send_notify(uint8_t *data, uint16_t length) +{ + struct rdtss_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(RDTSS_VAL_NTF_REQ, + prf_get_task_from_id(TASK_ID_RDTSS), + TASK_APP, + rdtss_val_ntf_ind_req, + length); + + req->conidx = app_env.conidx; + req->notification = true; + req->handle = RDTSS_IDX_NTF_VAL; + req->length = length; + memcpy(&req->value[0], data, length); + + ke_msg_send(req); +} + +/// Default State handlers definition +const struct ke_msg_handler app_rdtss_msg_handler_list[] = +{ + {RDTSS_VALUE_REQ_IND, (ke_msg_func_t)rdtss_value_req_ind_handler}, + {RDTSS_VAL_WRITE_IND, (ke_msg_func_t)rdtss_val_write_ind_handler}, + {RDTSS_VAL_NTF_CFM, (ke_msg_func_t)rdtss_val_ntf_cfm_handler}, + +}; + +const struct app_subtask_handlers app_rdtss_handlers = APP_HANDLERS(app_rdtss); + + +void app_rdtss_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSS; + prf.prf_task_handler = &app_rdtss_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSS; + get_func.prf_itf_get_func = rdtss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +#endif //BLE_RDTSS_SERVER diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_usart.c new file mode 100644 index 0000000..75b3da4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/app_usart.c @@ -0,0 +1,575 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include +#include "global_func.h" +#include "app_usart.h" +#include "app_rdtss.h" +#include "ns_sleep.h" +#include "ns_log.h" +#include "ns_timer.h" +#include "ke_timer.h" +#include "app_ble.h" +#include "rdtss_task.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] = {0}; +uint16_t rx_old_pos = 0; + +uint8_t usart_rx_fifo_buf[USART_RX_FIFO_SIZE] = {0}; +uint32_t usart_rx_fifo_in = 0; +uint32_t usart_rx_fifo_out = 0; + + +uint8_t usart_tx_fifo_buf[USART_TX_FIFO_SIZE] = {0}; +uint32_t usart_tx_fifo_in = 0; +uint32_t usart_tx_fifo_out = 0; + +uint8_t usart_sending = false; +uint8_t ble_sending = false; +uint16_t ble_att_mtu = (ATT_DEFAULT_MTU-3); + +/* Private function prototypes -----------------------------------------------*/ +void app_usart_tx_process(void); + +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTx_Tx_DMA_Channel); + DMA_RequestRemap(USARTx_Tx_DMA_REMAP, DMA, USARTx_Tx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Tx_DMA_Channel,DMA_INT_TXC ,ENABLE); + + /* USARTx RX DMA1 Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTx_Rx_DMA_Channel); + DMA_RequestRemap(USARTx_Rx_DMA_REMAP, DMA, USARTx_Rx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Rx_DMA_Channel,DMA_INT_TXC|DMA_INT_HTX ,ENABLE); + + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)USART_rx_dma_buf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = USART_RX_DMA_SIZE; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Rx_DMA_Channel, &DMA_InitStructure); + +} + + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + NVIC_DisableIRQ(DMA_Channel1_2_3_4_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + NVIC_DisableIRQ(USARTx_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void app_usart_configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* Configure the DMA */ + DMA_Configuration(); + + NVIC_Configuration(); + + /* USARTx and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; //921600 + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTx, USART_INT_IDLEF, ENABLE); + + /* Enable USARTx DMA Rx and TX request */ + USART_EnableDMA(USARTx, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief enable or disable the usart dma + */ +void app_usart_dma_enable(FunctionalState Cmd) +{ + if(Cmd == ENABLE) + { + ns_sleep_lock_acquire(); + rx_old_pos = 0; + usart_tx_fifo_in = usart_tx_fifo_out = 0; //clean fifo + usart_rx_fifo_in = usart_rx_fifo_out = 0; //clean fifo + app_usart_configuration(); + + } + else{ + ns_sleep_lock_release(); + USART_Enable(USARTx, DISABLE); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, DISABLE); + DMA_EnableChannel(USARTx_Tx_DMA_Channel, DISABLE); + /* Deinit IO of USART to save power */ + GPIO_InitType GPIO_InitStructure; + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + } +} + +/** + * @brief forward usart rx data too ble notify + */ +void usart_forward_to_ble_loop(void) +{ + uint32_t in_temp; + uint16_t ble_send_len; + + in_temp = usart_rx_fifo_in; + if(usart_rx_fifo_out < in_temp) + { + ble_send_len = in_temp-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out > in_temp){ + ble_send_len = USART_RX_FIFO_SIZE-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out == in_temp){ + // fifo empty, stop send loop + ble_sending = false; + return; + } + if ((app_env.max_mtu-3)> ble_att_mtu) + { + ble_att_mtu = (app_env.max_mtu-3); + } + if(ble_send_len > ble_att_mtu) + { + ble_send_len = ble_att_mtu; + } + ble_sending = true; + #if (BLE_RDTSS_SERVER) + + if (usart_rx_fifo_buf[usart_rx_fifo_out] < BLE_SLAVE_CONN) + { + ns_ble_set_active_connection(usart_rx_fifo_buf[usart_rx_fifo_out]); + rdtss_send_notify( &usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + } + else + { + rdtss_send_notify_all(&usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + } + + #endif + usart_rx_fifo_out = (usart_rx_fifo_out+ble_send_len)%USART_RX_FIFO_SIZE; + + return; +} + + +/** + * @brief usart rx data enter fifo and active ble send first package if not active yet + */ +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len; + //store data in fifo + while(len) + { + if(usart_rx_fifo_in >= usart_rx_fifo_out ) + { + in_len = USART_RX_FIFO_SIZE-usart_rx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + } + else if(usart_rx_fifo_in < usart_rx_fifo_out ) + { + in_len = usart_rx_fifo_out-usart_rx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,usart_rx_fifo_in,usart_rx_fifo_out); + } + break; + } + } + + if(!ble_sending) + { + ke_timer_set(RDTSS_VAL_NTF_CFM, TASK_APP, 10); + } + + + return len; +} + +/** + * @brief usart send data via dma + */ +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len) +{ + DMA_InitType DMA_InitStructure; + + if(usart_sending) + { + return false; + } + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)p_data; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = len; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Tx_DMA_Channel, &DMA_InitStructure); + + usart_sending = true; + DMA_EnableChannel(USARTx_Tx_DMA_Channel, ENABLE); + + return true; +} + +/** + * @brief usart send data in blocking mode + */ +void usart_tx_data_blocking(uint8_t *p_data, uint16_t len) +{ + while(len--) + { + USART_SendData(USARTx, *p_data); + p_data++; + } +} + +/** + * @brief usart tx fifo enter and active dma send out + */ +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len, out_temp; + //store data in fifo + NS_LOG_DEBUG("%d,%d,%d\r\n",len,usart_tx_fifo_in,usart_tx_fifo_out); + out_temp = usart_tx_fifo_out; + while(len) + { + if(usart_tx_fifo_in >= out_temp ) + { + in_len = USART_TX_FIFO_SIZE-usart_tx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + } + else if(usart_tx_fifo_in < out_temp ) + { + in_len = out_temp-usart_tx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,usart_tx_fifo_in,out_temp); + } + + break; + } + } + + // ble treaming cut timer, active usart send after it. + ke_timer_set(APP_CUSTS_TEST_EVT, TASK_APP, 50); + + return len; +} + +/** + * @brief usart tx data from fifo + */ +void app_usart_tx_process(void) +{ + uint32_t in_temp,len; + uint8_t *p_data; + + in_temp = usart_tx_fifo_in; + if(usart_tx_fifo_out < in_temp) + { + len = in_temp-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = in_temp; + } + + } + else if(usart_tx_fifo_out > in_temp) + { + len = USART_TX_FIFO_SIZE-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = 0; + } + + } +} + + +/** + * @brief check the dma buffer which has been received + */ +void usart_rx_check_in_irq(void) +{ + uint16_t rx_pos; + + rx_pos = USART_RX_DMA_SIZE - DMA_GetCurrDataCounter(USARTx_Rx_DMA_Channel); + if(rx_pos < rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(USART_RX_DMA_SIZE - rx_old_pos)); + + if(rx_pos > 0) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[0],rx_pos); + } + + rx_old_pos = rx_pos; + } + else if(rx_pos > rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(rx_pos - rx_old_pos)); + rx_old_pos = rx_pos; + } + else if(rx_pos != rx_old_pos) + { + //error + rx_old_pos = rx_pos; + } + +} + + +/** + * @brief dma irq handler + */ +void DMA_Channel1_2_3_4_IRQHandler(void) +{ + //TX + if(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)) + { + //TX Transfer complete interrupt + usart_sending = false; + ke_msg_send_basic(APP_CUSTS_TEST_EVT, TASK_APP, TASK_APP); + + DMA_ClearFlag(DMA_FLAG_TC1, DMA); + } + //RX + if(DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + //RX Transfer complete interrupt + DMA_ClearFlag(DMA_FLAG_TC2, DMA); + usart_rx_check_in_irq(); + + } + if(DMA_GetFlagStatus(DMA_FLAG_HT2, DMA)) + { + //RX Half transfer interrupt + DMA_ClearFlag(DMA_FLAG_HT2, DMA); + usart_rx_check_in_irq(); + } + +} + +/** + * @brief usart irq handler + */ +void USARTx_IRQHandler(void) +{ + uint8_t temp; + //usart idlle interrupt + if(USART_GetFlagStatus(USARTx,USART_FLAG_IDLEF)) + { + //read sts and data will clear rx idle interrupt + temp = USARTx->DAT; + usart_rx_check_in_irq(); + (void)temp; + } + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/main.c new file mode 100644 index 0000000..ed0a6b9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble/rdtss_3s/src/main.c @@ -0,0 +1,160 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_ble.h" +#if (CFG_APP_NS_IUS) +#include "ns_dfu_boot.h" +#endif + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING raw data transfer server(128bit UUID) demo \r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + + NS_LOG_INIT(); + + #if (CFG_APP_NS_IUS) + if(CURRENT_APP_START_ADDRESS == NS_APP1_START_ADDRESS){ + NS_LOG_INFO("application 1 start new ...\r\n"); + }else if(CURRENT_APP_START_ADDRESS == NS_APP2_START_ADDRESS){ + NS_LOG_INFO("application 2 start new ...\r\n"); + } + #endif + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + app_usart_dma_enable(ENABLE); + //init text + usart_tx_dma_send((uint8_t*)DEMO_STRING, sizeof(DEMO_STRING)); + + delay_n_10us(500); + //disable usart for enter sleep + app_usart_dma_enable(DISABLE); + + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/MDK-ARM/hogprh.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/MDK-ARM/hogprh.uvoptx new file mode 100644 index 0000000..c24118e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/MDK-ARM/hogprh.uvoptx @@ -0,0 +1,665 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + 4 + 17 + 4 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + n32wb03x_host_lib.lib + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogprh\src\hogprh.c + hogprh.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogprh\src\hogprh_task.c + hogprh_task.c + 0 + 0 + + + + + NS_LIB + 1 + 0 + 0 + 0 + + 6 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 6 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + 6 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + ns_log_usart.c + 0 + 0 + + + + + BLE_APP + 1 + 0 + 0 + 0 + + 7 + 29 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + 7 + 30 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_hogprh.c + app_hogprh.c + 0 + 0 + + + + + USER + 1 + 0 + 0 + 0 + + 8 + 31 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 32 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + + + CONFIG + 1 + 0 + 0 + 0 + + 9 + 33 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 1 + 0 + 0 + 0 + + 10 + 34 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/MDK-ARM/hogprh.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/MDK-ARM/hogprh.uvprojx new file mode 100644 index 0000000..3e55524 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/MDK-ARM/hogprh.uvprojx @@ -0,0 +1,681 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.4.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0x8000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + hogprh + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\hogprh.bin .\Objects\hogprh.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x8000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogprh\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogprh\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\custom;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\custom\custs\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15_central.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + n32wb03x_host_lib.lib + 4 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + hogprh.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogprh\src\hogprh.c + + + hogprh_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogprh\src\hogprh_task.c + + + + + NS_LIB + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + ns_log_usart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + + + + + BLE_APP + + + app_ble.c + 1 + ..\src\app_ble.c + + + app_hogprh.c + 1 + ..\src\app_profile\app_hogprh.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_ble.h new file mode 100644 index 0000000..6e4c112 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_ble.h @@ -0,0 +1,96 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_UART_TX_EVT, + APP_RECONNECT_EVT, + APP_KEY_DETECTED, +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_gpio.h new file mode 100644 index 0000000..60d76b3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_gpio.h @@ -0,0 +1,109 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +#define KEY1_INPUT_PORT GPIOB +#define KEY1_INPUT_PIN GPIO_PIN_1 +#define KEY1_INPUT_EXTI_LINE EXTI_LINE1 +#define KEY1_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY1_INPUT_PIN_SOURCE GPIO_PIN_SOURCE1 +#define KEY1_INPUT_IRQn EXTI0_1_IRQn + +#define KEY2_INPUT_PORT GPIOB +#define KEY2_INPUT_PIN GPIO_PIN_2 +#define KEY2_INPUT_EXTI_LINE EXTI_LINE2 +#define KEY2_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY2_INPUT_PIN_SOURCE GPIO_PIN_SOURCE2 +#define KEY2_INPUT_IRQn EXTI2_3_IRQn + + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void app_key_press_timeout_handler(void); +void app_key_configuration(void); +void app_key_reinit_after_sleep(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_profile/app_hogprh.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_profile/app_hogprh.h new file mode 100644 index 0000000..b7e78f1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_profile/app_hogprh.h @@ -0,0 +1,89 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_hogprh.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_HOGPRH_H_ +#define APP_HOGPRH_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (CFG_PRF_HOGPRH) + + +/// Table of message handlers +extern const struct app_subtask_handlers app_hogprh_handlers; + +void app_hogprh_init(void); +void app_hogprh_add_hid(void); +void app_hogprh_enable_prf(uint8_t conidx); +void hogprh_write_ble_data(uint8_t info, uint8_t hid_idx, uint8_t report_idx,uint8_t *data); + +#endif //CFG_PRF_HOGPRH + +/// @} APP + +#endif // APP_HOGPRH_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_user_config.h new file mode 100644 index 0000000..ed8fa04 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/inc/app_user_config.h @@ -0,0 +1,114 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_HID_CLIENT" /** +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "app_gpio.h" +#include "ns_sec.h" +#include "app_user_config.h" +#if (CFG_PRF_HOGPRH) +#include "app_hogprh.h" +#endif +#include "ke_timer.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + struct gap_bdaddr peer_addr = {0}; + switch (msgid) + { + case APP_RECONNECT_EVT: + ns_bond_last_bonded_addr(&peer_addr); + NS_LOG_DEBUG("\r\nAddr: "); + for(int i = 0; i < 6; i++) + { + NS_LOG_DEBUG("%02x ", peer_addr.addr.addr[i]); + } + NS_LOG_DEBUG("\r\naddr type: %x, ", peer_addr.addr_type); + ns_ble_list_set_wl(&peer_addr,1); + ns_ble_start_init(NULL, peer_addr.addr_type); + break; + case APP_KEY_DETECTED: + { + app_key_press_timeout_handler(); + }break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + if (ns_sec_get_bond_status()) + { + ke_timer_set(APP_RECONNECT_EVT, TASK_APP, 500); + } + break; + case APP_BLE_GAP_CONNECTED: + if (ns_sec_get_bond_status()) + { + ns_sec_send_encrypt_req(app_env.conidx); + } + else + { + ns_sec_send_bond_start(app_env.conidx); + } + #if (CFG_PRF_HOGPRH) + app_hogprh_enable_prf(app_env.conidx); + #endif + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief scan data handler + * @param + * @return + * @note + */ +void app_ble_scan_data_handler(struct gapm_ext_adv_report_ind const* p_param) +{ +// NS_LOG_INFO("Found:%02x%02x%02x%02x%02x%02x, rssi:%d \r\n", +// p_param->trans_addr.addr.addr[0], +// p_param->trans_addr.addr.addr[1], +// p_param->trans_addr.addr.addr[2], +// p_param->trans_addr.addr.addr[3], +// p_param->trans_addr.addr.addr[4], +// p_param->trans_addr.addr.addr[5], +// p_param->rssi); + +} + +/** + * @brief scan state handler + * @param + * @return + * @note + */ +void app_ble_scan_state_handler(enum scan_state_t state) +{ + switch (state) + { + case SCAN_STATE_SCANING: + NS_LOG_INFO("Scaning.\r\n"); + break; + case SCAN_STATE_FOUND: + NS_LOG_INFO("Found target.\r\n"); + break; + case SCAN_STATE_CONN_TIMEOUT: + NS_LOG_INFO("Connect timeout.\r\n"); + break; + default: + break; + } +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x0C\x0D\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_ALL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble scan initialization + * @param + * @return + * @note + */ +void app_ble_scan_init(void) +{ + struct ns_scan_params_t init = {0}; +// static const uint8_t target_addr[] = {"\x11\x11\x11\x11\x11\x11"}; + static const uint8_t target_name[] = {"hid_mouse"}; +// static const uint16_t target_uuid16 = 0x180A; + + init.type = SCAN_PARAM_TYPE; + init.dup_filt_pol = SCAN_PARAM_DUP_FILT_POL; + init.connect_enable = SCAN_PARAM_CONNECT_EN; + init.prop_active_enable = SCAN_PARAM_PROP_ACTIVE; + init.scan_intv = SCAN_PARAM_INTV; + init.scan_wd = SCAN_PARAM_WD; + init.duration = SCAN_PARAM_DURATION; + init.initiating_timeout = 0;//3000; + + init.filter_type = SCAN_FILTER_BY_NAME;//SCAN_FILTER_BY_ADDRESS; + init.filter_data = (uint8_t*)&target_name; + + init.ble_scan_data_handler = app_ble_scan_data_handler; + init.ble_scan_state_handler = app_ble_scan_state_handler; + + ns_ble_scan_init(&init); +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + #if (CFG_PRF_HOGPRH) + ns_ble_add_prf_func_register(app_hogprh_add_hid); + #endif +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_scan_init(); + app_ble_prf_init(); + //start scan + if (ns_sec_get_bond_status()) + app_env.wl_reconnect = true; + else + ns_ble_start_scan(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + LedOn(LED2_PORT,LED2_PIN); + +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + if (!ns_sec_get_bond_status()) + { + // Restart scan + ns_ble_start_scan(); + } + else if (app_env.wl_reconnect) + { + ke_timer_set(APP_RECONNECT_EVT, TASK_APP, 100); + } + + LedOff(LED2_PORT,LED2_PIN); +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/src/app_gpio.c new file mode 100644 index 0000000..aa390af --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/src/app_gpio.c @@ -0,0 +1,295 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" +#include +#include "global_func.h" +#include "ns_log.h" +#include "ns_timer.h" +#include "ns_delay.h" +#include "app_ble.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define KEY_PRESS_DELAY 100 +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t key1_irq_actived = 0; +uint8_t key2_irq_actived = 0; + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @brief Configures key port. + */ +void app_key_configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + + /*Configure the GPIO pin as input floating */ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = KEY1_INPUT_PIN; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(KEY1_INPUT_PORT, &GPIO_InitStructure); + + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + + /*Configure the GPIO pin as input floating*/ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = KEY2_INPUT_PIN; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(KEY2_INPUT_PORT, &GPIO_InitStructure); + + /*Configure key EXTI Line to key input Pin*/ + GPIO_ConfigEXTILine(KEY1_INPUT_PORT_SOURCE, KEY1_INPUT_PIN_SOURCE); + GPIO_ConfigEXTILine(KEY2_INPUT_PORT_SOURCE, KEY2_INPUT_PIN_SOURCE); + + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY1_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY1_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY2_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY2_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief re-configures key port aafter sleep. + */ +void app_key_reinit_after_sleep(void) +{ + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + +} + +/** + * @brief key press timer handler. + */ +void app_key_press_timeout_handler(void) +{ + + if(key1_irq_actived == 1) + { + extern void ns_sec_bond_db_erase_all(void); + ns_sec_bond_db_erase_all(); + NS_LOG_INFO("Button 1: ns_sec_bond_db_erase_all\r\n"); + key1_irq_actived = 0; + } + else if(key1_irq_actived == 2 ) + { + //re-start timer if got irq after first created timer + ns_timer_create(KEY_PRESS_DELAY,app_key_press_timeout_handler); + key1_irq_actived = 1; + } + + if(key2_irq_actived == 1) + { + NS_LOG_INFO("Button 2\r\n"); + key2_irq_actived = 0; + } + else if(key2_irq_actived == 2) + { + //re-start timer if got irq after first created timer + ns_timer_create(KEY_PRESS_DELAY,app_key_press_timeout_handler); + key2_irq_actived = 1; + } + +} + +/** + * @brief External lines 1 interrupt. + */ +void EXTI0_1_IRQHandler(void) +{ + + if ( EXTI_GetITStatus(KEY1_INPUT_EXTI_LINE)!= RESET) + { + if(key1_irq_actived == 0) + { + ke_msg_send_basic(APP_KEY_DETECTED, TASK_APP, TASK_APP); + key1_irq_actived = 1; + } + else if(key1_irq_actived == 1) + { + //if timer started, update flag + key1_irq_actived = 2; + + } + EXTI_ClrITPendBit(KEY1_INPUT_EXTI_LINE); + } +} + +/** + * @brief External lines 2 interrupt. + */ +void EXTI2_3_IRQHandler(void) +{ + if ( EXTI_GetITStatus(KEY2_INPUT_EXTI_LINE)!= RESET) + { + if(key2_irq_actived == 0) + { + ke_msg_send_basic(APP_KEY_DETECTED, TASK_APP, TASK_APP); + key2_irq_actived = 1; + } + else if(key2_irq_actived == 1) + { + //if timer started, update flag + key2_irq_actived = 2; + } + EXTI_ClrITPendBit(KEY2_INPUT_EXTI_LINE); + } +} + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/src/app_profile/app_hogprh.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/src/app_profile/app_hogprh.c new file mode 100644 index 0000000..5b674ab --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/src/app_profile/app_hogprh.c @@ -0,0 +1,402 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_hogprh.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (CFG_PRF_HOGPRH) + +/* Includes ------------------------------------------------------------------*/ +#include "app_hogprh.h" +#include "hogprh_task.h" +#include "hogprh.h" +#include "ns_ble.h" +#include "ns_ble_task.h" +#include "ns_timer.h" +#include "app_gpio.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/// Parameters of the @ref HOGPRH_CACHE +struct hogprh_cache +{ + /// Number of HIDS instances + uint8_t hids_nb; + /// Existing handle values hids + struct hogprh_content hids[HOGPRH_NB_HIDS_INST_MAX]; +}; +/* Private constants ---------------------------------------------------------*/ +static uint8_t cache_save_latency = 200; +static bool cache_done = false; +static struct hogprh_cache hids_cache; +extern bool ns_sec_get_bond_status(void); +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +void app_hogprh_save_cache(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + rwip_time_t current_time = rwip_time_get(); + rwip_time_t target_time = {0}; + target_time.hs = ip_clkntgt1_getf(); + target_time.hus = ip_hmicrosectgt1_getf(); + int32_t duration = CLK_DIFF(current_time.hs, target_time.hs); + if((duration > 64) || (cache_save_latency == 0))// 20ms, xMS / 0.3125 + { + Qflash_Erase_Sector(CACHE_DATA_BASE_ADDR); + Qflash_Write(CACHE_DATA_BASE_ADDR, (uint8_t*)(&hids_cache), sizeof(struct hogprh_content)*hids_cache.hids_nb + 1 ); + } + else + { + cache_save_latency --; + ns_timer_create(20,app_hogprh_save_cache); + } + } + +void app_hogprh_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_HOGPRH; + prf.prf_task_handler = &app_hogprh_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_HOGPRH; + get_func.prf_itf_get_func = hogprh_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_hogprh_add_hid(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + 0); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, UNAUTH);// NO_AUTH UNAUTH AUTH + req->prf_task_id = TASK_ID_HOGPRH; + req->app_task = TASK_APP; + req->start_hdl = 0; + + + // Send the message + ke_msg_send(req); + + app_hogprh_init(); +} + + +void app_hogprh_enable_prf(uint8_t conidx) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct hogprh_enable_req * req = KE_MSG_ALLOC(HOGPRH_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_HOGPRH), + TASK_APP, + hogprh_enable_req); + + // Fill in the parameter structure + cache_done = false; + if (ns_sec_get_bond_status()) + { + cache_done = true; + req->con_type = PRF_CON_NORMAL; + struct hogprh_cache* p_cache = (void*)CACHE_DATA_BASE_ADDR; + memcpy(&hids_cache, p_cache, sizeof(struct hogprh_content)*p_cache->hids_nb + 1); + req->hids_nb = p_cache->hids_nb; + memcpy((req->hids), (p_cache->hids), sizeof(struct hogprh_content)*p_cache->hids_nb); + NS_LOG_DEBUG("hids_cache hids_nb: %d,shdl: %d,ehdl:%d\r\n",hids_cache.hids_nb,hids_cache.hids[0].svc.shdl,hids_cache.hids[0].svc.ehdl); + } + else + req->con_type = PRF_CON_DISCOVERY; + + // Send the message + ke_msg_send(req); +} + +void hogprh_read_ble_data(uint8_t info, uint8_t hid_idx, uint8_t report_idx) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct hogprh_read_info_req * req = KE_MSG_ALLOC_DYN(HOGPRH_READ_INFO_REQ, + prf_get_task_from_id(TASK_ID_HOGPRH), + TASK_APP, + hogprh_read_info_req, + 0); + + req->info = info; + req->hid_idx = hid_idx; + req->report_idx = report_idx; + + ke_msg_send(req); +} + +void hogprh_write_ble_data(uint8_t info, uint8_t hid_idx, uint8_t report_idx,uint8_t *data) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct hogprh_write_req * req = KE_MSG_ALLOC_DYN(HOGPRH_WRITE_REQ, + prf_get_task_from_id(TASK_ID_HOGPRH), + TASK_APP, + hogprh_write_req, + 0); + + req->info = info; + req->hid_idx = hid_idx; + req->report_idx = report_idx; + req->wr_cmd = 0; + switch (info) + { + case HOGPRH_PROTO_MODE: + memcpy(&req->data.proto_mode, data, 1); + break; + case HOGPRH_HID_CTNL_PT: + memcpy(&req->data.hid_ctnl_pt, data, 1); + break; + case HOGPRH_REPORT: + memcpy(&req->data.report, data, sizeof(struct hogprh_report)); + break; + case HOGPRH_REPORT_NTF_CFG: + memcpy(&req->data.report_cfg, data, 1); + break; + default: + break; + } + ke_msg_send(req); +} + + +/** + **************************************************************************************** + * @brief Handles client enable confirmation + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int hogprh_enable_cfm_handler(ke_msg_id_t const msgid, + struct hogprh_enable_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ +// NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("HOGPRH profile was enabled,status: %d,hids_nb:%d\r\n",param->status,param->hids_nb); + NS_LOG_DEBUG("SVC shdl: %d,hids_nb:%d,report_nb: %d\r\n",param->hids[0].svc.shdl,param->hids[0].svc.ehdl,param->hids[0].report_nb); + + if (!param->status && !cache_done) + { + hids_cache.hids_nb = param->hids_nb; + memcpy(&hids_cache.hids[0], &(param->hids[0]), sizeof(struct hogprh_content)*param->hids_nb); + NS_LOG_DEBUG("hids_cache[0] shdl: %d,ehdl:%d,report_nb: %d\r\n",hids_cache.hids[0].svc.shdl,hids_cache.hids[0].svc.ehdl,hids_cache.hids[0].report_nb); + //need to save it by timer + ns_timer_create(1000,app_hogprh_save_cache); + } + hogprh_read_ble_data(HOGPRH_REPORT_MAP,0,0); +// ns_ble_get_peer_info(GAPC_GET_PEER_FEATURES); + return (KE_MSG_CONSUMED); +} + +/* + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int hogprh_write_cfm_handler(ke_msg_id_t const msgid, + struct hogprh_write_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,%d,hid_idx: %d,report_idx: %d,info: %d\r\n", __func__,param->status,param->hid_idx,param->report_idx,param->info); +if (param->info == HOGPRH_REPORT_NTF_CFG && ((param->report_idx + 1) < (hids_cache.hids[param->hid_idx].report_nb))) +{ + uint8_t ntg_enable[2] = {0x01,0x00}; + hogprh_write_ble_data(HOGPRH_REPORT_NTF_CFG,param->hid_idx,param->report_idx+1,ntg_enable); +} + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles report data from notification + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ + +int hogprh_report_ind_handler(ke_msg_id_t const msgid, + struct hogprh_report_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("HOGP Data was received\r\n"); + NS_LOG_DEBUG("length = %x\r\n", param->report.length); + NS_LOG_DEBUG("report_idx = %x\r\n", param->report_idx); + NS_LOG_DEBUG("hid_idx = %x\r\n", param->hid_idx); + NS_LOG_DEBUG("data "); + for(uint8_t i=0; ireport.length; i++) + { + NS_LOG_DEBUG(" %x", param->report.value[i]); + } + NS_LOG_DEBUG("\r\n"); + + if (param->report.value[1] == 0x0A) + { + LedOff(LED2_PORT,LED2_PIN); + } + else if (param->report.value[0] == 0x08) + { + LedOn(LED2_PORT,LED2_PIN); + } + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles the data recieved from read command + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int hogprh_read_info_rsp_handler(ke_msg_id_t const msgid, + struct hogprh_read_info_rsp const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,%d,hid_idx: %d,report_idx: %d\r\n", __func__,param->status,param->hid_idx,param->report_idx); + + switch (param->info) + { + case HOGPRH_REPORT_MAP: + NS_LOG_DEBUG("Report Map: "); + for(uint8_t i=0; idata.report_map.length; i++) + { + NS_LOG_DEBUG(" %x", param->data.report_map.value[i]); + } + NS_LOG_DEBUG("\r\n"); + hogprh_read_ble_data(HOGPRH_HID_INFO,param->hid_idx,0); + break; + case HOGPRH_HID_INFO: + hogprh_read_ble_data(HOGPRH_REPORT_REF,param->hid_idx,0); + break; + case HOGPRH_REPORT_REF: + NS_LOG_DEBUG("Report REF: \r\n"); + NS_LOG_DEBUG("id %x\r\n", param->data.report_ref.id); + NS_LOG_DEBUG("type %x\r\n", param->data.report_ref.type); + if ((param->report_idx + 1) < (hids_cache.hids[param->hid_idx].report_nb)) + { + hogprh_read_ble_data(HOGPRH_REPORT_REF,param->hid_idx,(param->report_idx + 1)); + } + else + { + uint8_t ntg_enable[2] = {0x01,0x00}; + hogprh_write_ble_data(HOGPRH_REPORT_NTF_CFG,param->hid_idx,0,ntg_enable); + } + break; + default: + break; + } + return (KE_MSG_CONSUMED); +} + +/// Default State handlers definition +const struct ke_msg_handler app_hogprh_msg_handler_list[] = +{ + {HOGPRH_ENABLE_RSP, (ke_msg_func_t)hogprh_enable_cfm_handler}, + {HOGPRH_WRITE_RSP, (ke_msg_func_t)hogprh_write_cfm_handler}, + {HOGPRH_REPORT_IND, (ke_msg_func_t)hogprh_report_ind_handler}, + {HOGPRH_READ_INFO_RSP, (ke_msg_func_t)hogprh_read_info_rsp_handler}, +}; + +const struct app_subtask_handlers app_hogprh_handlers = APP_HANDLERS(app_hogprh); + + +#endif //CFG_PRF_HOGPRH diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/src/main.c new file mode 100644 index 0000000..0928d4c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_hogprh/src/main.c @@ -0,0 +1,143 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_gpio.h" +#include "app_ble.h" + + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\nHID Report Host Client demo\r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + app_key_configuration(); + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/MDK-ARM/central_rdts_c&s.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/MDK-ARM/central_rdts_c&s.uvoptx new file mode 100644 index 0000000..35a7c6a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/MDK-ARM/central_rdts_c&s.uvoptx @@ -0,0 +1,737 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 1 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + 4 + 17 + 4 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + n32wb03x_host_lib.lib + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils_128.c + prf_utils_128.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client.c + rdts_client.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_task.c + rdts_client_task.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + rdts_common.c + 0 + 0 + + + 5 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + rdtss_task.c + 0 + 0 + + + 5 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + rdtss.c + 0 + 0 + + + + + NS_LIB + 1 + 0 + 0 + 0 + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 31 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 1 + 0 + 0 + 0 + + 7 + 33 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtsc.c + app_rdtsc.c + 0 + 0 + + + 7 + 34 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + 7 + 35 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtss.c + app_rdtss.c + 0 + 0 + + + + + USER + 1 + 0 + 0 + 0 + + 8 + 36 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 37 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + 8 + 38 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + + + CONFIG + 1 + 0 + 0 + 0 + + 9 + 39 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 40 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/MDK-ARM/central_rdts_c&s.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/MDK-ARM/central_rdts_c&s.uvprojx new file mode 100644 index 0000000..9fdee8b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/MDK-ARM/central_rdts_c&s.uvprojx @@ -0,0 +1,711 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0x8000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtsc + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\rdtsc.bin .\Objects\rdtsc.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x8000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15_central.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + n32wb03x_host_lib.lib + 4 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + prf_utils_128.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils_128.c + + + rdts_client.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client.c + + + rdts_client_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_rdtsc.c + 1 + ..\src\app_profile\app_rdtsc.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_ble.h new file mode 100644 index 0000000..e60ae7c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_ble.h @@ -0,0 +1,96 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_UART_TX_EVT, + APP_SWITCH_MODE, + APP_SWITCH_CMD, + +}; + +/* ble application initialization */ +void app_ble_master_init(void); + +void app_ble_slave_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_gpio.h new file mode 100644 index 0000000..0a1e72b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_gpio.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +#define KEY2_INPUT_PORT GPIOB +#define KEY2_INPUT_PIN GPIO_PIN_2 +#define KEY2_INPUT_EXTI_LINE EXTI_LINE2 +#define KEY2_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY2_INPUT_PIN_SOURCE GPIO_PIN_SOURCE2 +#define KEY2_INPUT_IRQn EXTI2_3_IRQn + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +void app_key_configuration(void); +void app_key_reinit_after_sleep(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_profile/app_rdtsc.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_profile/app_rdtsc.h new file mode 100644 index 0000000..2c4eaae --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_profile/app_rdtsc.h @@ -0,0 +1,89 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSC_H_ +#define APP_RDTSC_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_CLIENT) + + +/// Table of message handlers +extern const struct app_subtask_handlers app_rdtsc_handlers; + +void app_rdtsc_init(void); +void app_rdtsc_add_rdts(void); +void app_rdtsc_enable_prf(uint8_t conidx); +void user_send_ble_data(const uint8_t *data, uint16_t length); + +#endif //BLE_RDTS_CLIENT + +/// @} APP + +#endif // APP_RDTSC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_profile/app_rdtss.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_profile/app_rdtss.h new file mode 100644 index 0000000..b875e05 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_profile/app_rdtss.h @@ -0,0 +1,121 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSS_H_ +#define APP_RDTSS_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/// Manufacturer Name Value +#define APP_RDTSS_MANUFACTURER_NAME ("NSING") +#define APP_RDTSS_MANUFACTURER_NAME_LEN (5) + + + +#define ATT_SERVICE_AM_SPEED_128 {0x01,0x10,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Service UUID */ +#define ATT_CHAR_AM_SPEED_WRITE_128 {0x01,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_NTF_128 {0x02,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ + + +/// rdtss Service Attributes Indexes +enum +{ + RDTSS_IDX_SVC, + + RDTSS_IDX_WRITE_CHAR, + RDTSS_IDX_WRITE_VAL, + RDTSS_IDX_WRITE_CFG, + + RDTSS_IDX_NTF_CHAR, + RDTSS_IDX_NTF_VAL, + RDTSS_IDX_NTF_CFG, + + RDTSS_IDX_NB, +}; + + +/** + * @brief Initialize Device Information Service Application + **/ +void app_rdtss_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_rdtss_add_rdts(void); + +void rdtss_send_notify(uint8_t *data, uint16_t length); + + +#endif //BLE_RDTSS_SERVER + +/// @} APP + +#endif // APP_RDTSS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_usart.h new file mode 100644 index 0000000..2115114 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_usart.h @@ -0,0 +1,152 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTx_DAT_Base (USART1_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART1_RX +#define USARTx_IRQn USART1_IRQn +#define USARTx_IRQHandler USART1_IRQHandler +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define USARTx_DAT_Base (USART2_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#define USARTx_IRQn USART2_IRQn +#define USARTx_IRQHandler USART2_IRQHandler +#endif + + +#define USART_RX_DMA_SIZE 256 +#define USART_RX_FIFO_SIZE 1000 +#define USART_TX_FIFO_SIZE 1000 + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + +/* Public function prototypes -----------------------------------------------*/ + +void app_usart_configuration(void); +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len); +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len); +void app_usart_tx_data_blocking(uint8_t *p_data, uint16_t len); + +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len); +void usart_forward_to_ble_loop(void); +void app_usart_dma_enable(FunctionalState Cmd); +void app_usart_tx_process(void); +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_user_config.h new file mode 100644 index 0000000..02a3841 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/inc/app_user_config.h @@ -0,0 +1,142 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ +#include "ns_adv_data_def.h" +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_RDTSS" /** +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "ns_sec.h" +#include "app_rdtsc.h" +#include "app_user_config.h" +#include "app_rdtss.h" +#include "ke_timer.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t fw_mode = 1; // 0: master 1: slave +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_UART_TX_EVT: + app_usart_tx_process(); + break; + case APP_SWITCH_CMD: + NS_LOG_DEBUG("APP_SWITCH_CMD\r\n"); + if(ke_state_get(TASK_APP) == APP_CONNECTED) + { + ns_ble_disconnect(); + }else{ + //disconnect mode, stop adv or scan + if(fw_mode == 0) + { + //Stop scan + ns_ble_stop_scan(); + } + else { + // Stop Advertising + ns_ble_adv_stop(); + } + } + //switch mode + if(fw_mode) + fw_mode = 0; + else fw_mode = 1; + ke_timer_set(APP_SWITCH_MODE, TASK_APP, 50); + break; + case APP_SWITCH_MODE: + LedOn(LED1_PORT, LED1_PIN); + NS_LOG_DEBUG("APP_SWITCH_MODE\r\n"); + if(fw_mode == 0) + { + NS_LOG_INFO("Master mode\r\n"); + //Sstart scan + ns_ble_start_scan(); + } + else { + NS_LOG_INFO("Slave mode\r\n"); + // Start Advertising + ns_ble_adv_start(); + } + break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + NS_LOG_INFO("Connected\r\n"); + if(fw_mode == 0) + { + //master + app_rdtsc_enable_prf(app_env.conidx); + } + else if(fw_mode == 1) + { + //slave + } + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + if(fw_mode == 0) + { + // Restart scan + ns_ble_start_scan(); + } + else if(fw_mode == 1) + { + // Restart Advertising + ns_ble_adv_start(); + } + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief scan data handler + * @param + * @return + * @note + */ +void app_ble_scan_data_handler(struct gapm_ext_adv_report_ind const* p_param) +{ + #if (NS_LOG_DEBUG_ENABLE == 0) + NS_LOG_INFO("Found:%02x%02x%02x%02x%02x%02x, rssi:%d \r\n", + p_param->trans_addr.addr.addr[0], + p_param->trans_addr.addr.addr[1], + p_param->trans_addr.addr.addr[2], + p_param->trans_addr.addr.addr[3], + p_param->trans_addr.addr.addr[4], + p_param->trans_addr.addr.addr[5], + p_param->rssi); + #endif + +} + +/** + * @brief scan state handler + * @param + * @return + * @note + */ +void app_ble_scan_state_handler(enum scan_state_t state) +{ + switch (state) + { + case SCAN_STATE_SCANING: + NS_LOG_INFO("Scaning.\r\n"); + break; + case SCAN_STATE_FOUND: + NS_LOG_INFO("Found target.\r\n"); + break; + case SCAN_STATE_CONN_TIMEOUT: + NS_LOG_INFO("Connect timeout.\r\n"); + break; + default: + break; + } +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + case APP_ADV_MODE_FAST: + case APP_ADV_MODE_SLOW: + NS_LOG_INFO("Advertising\r\n"); + break; + case APP_ADV_MODE_STOP: + + break; + default: + break; + } + +} + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_ALL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +static void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + + +/** + * @brief ble scan initialization + * @param + * @return + * @note + */ +void app_ble_scan_init(void) +{ + struct ns_scan_params_t init = {0}; +// static const uint8_t target_addr[] = {"\x11\x11\x11\x11\x11\x11"}; + static const uint8_t target_name[] = {"NS_RDTSS"}; +// static const uint16_t target_uuid16 = 0x180A; + + init.type = SCAN_PARAM_TYPE; + init.dup_filt_pol = SCAN_PARAM_DUP_FILT_POL; + init.connect_enable = SCAN_PARAM_CONNECT_EN; + init.prop_active_enable = SCAN_PARAM_PROP_ACTIVE; + init.scan_intv = SCAN_PARAM_INTV; + init.scan_wd = SCAN_PARAM_WD; + init.duration = SCAN_PARAM_DURATION; + init.initiating_timeout = 3000; + + init.filter_type = SCAN_FILTER_BY_NAME;//SCAN_FILTER_BY_ADDRESS; + init.filter_data = (uint8_t*)&target_name; + + init.ble_scan_data_handler = app_ble_scan_data_handler; + init.ble_scan_state_handler = app_ble_scan_state_handler; + + ns_ble_scan_init(&init); +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtsc_add_rdts); + + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtss_add_rdts); + +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_master_init(void) +{ + + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_scan_init(); + app_ble_prf_init(); + + if(fw_mode == 0) + { + // Restart scan + ns_ble_start_scan(); + } + else if(fw_mode == 1) + { + // Restart Advertising + ns_ble_adv_start(); + } +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + //enable usart receive + app_usart_dma_enable(ENABLE); + LedOn(LED2_PORT,LED2_PIN); +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + //disable usart receive + app_usart_dma_enable(DISABLE); + LedOff(LED2_PORT,LED2_PIN); +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_gpio.c new file mode 100644 index 0000000..94213f5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_gpio.c @@ -0,0 +1,238 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" +#include "ns_timer.h" +#include "global_func.h" +#include "ns_delay.h" +#include "ke_timer.h" +#include "app_ble.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define KEY_PRESS_DELAY 100 +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t key1_irq_actived = 0; +uint8_t key2_irq_actived = 0; + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + +/** + * @brief Configures key port. + */ +void app_key_configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + + /*Configure the GPIO pin as input floating*/ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = KEY2_INPUT_PIN; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(KEY2_INPUT_PORT, &GPIO_InitStructure); + + GPIO_ConfigEXTILine(KEY2_INPUT_PORT_SOURCE, KEY2_INPUT_PIN_SOURCE); + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY2_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY2_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief re-configures key port aafter sleep. + */ +void app_key_reinit_after_sleep(void) +{ + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + +} + +/** + * @brief key press timer handler. + */ +void app_key_press_timeout_handler(void) +{ + + if(key2_irq_actived == 1) + { + LedOff(LED1_PORT, LED1_PIN); + ke_timer_set(APP_SWITCH_CMD, TASK_APP, 500); + key2_irq_actived = 0; + } + else if(key2_irq_actived == 2) + { + //re-start timer if got irq after first created timer + ns_timer_create(KEY_PRESS_DELAY,app_key_press_timeout_handler); + key2_irq_actived = 1; + } + +} + +/** + * @brief External lines 1 and 2 interrupt. + */ +void EXTI2_3_IRQHandler(void) +{ + + if ( EXTI_GetITStatus(KEY2_INPUT_EXTI_LINE)!= RESET) + { + + if(key2_irq_actived == 0) + { + delay_n_10us(5); + ns_timer_create(KEY_PRESS_DELAY,app_key_press_timeout_handler); + key2_irq_actived = 1; + } + else if(key2_irq_actived == 1) + { + //if timer started, update flag + key2_irq_actived = 2; + } + EXTI_ClrITPendBit(KEY2_INPUT_EXTI_LINE); + } +} + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_profile/app_rdtsc.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_profile/app_rdtsc.c new file mode 100644 index 0000000..49d25bd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_profile/app_rdtsc.c @@ -0,0 +1,271 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_CLIENT) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtsc.h" +#include "rdts_client_task.h" +#include "gapm_task.h" +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" +#include "stdio.h" +#include "ns_ble_task.h" +#include "app_usart.h" +#include "string.h" +#include "prf_utils_128.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define RDTS_SERVICE_UUID {0x01, 0x10, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_TX_UUID {0x02, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_RX_UUID {0x01, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} + +/* Private constants ---------------------------------------------------------*/ +const uint8_t rdtsc_uuid128[]= RDTS_SERVICE_UUID; +/// State machine used to retrieve RDTS characteristics information +const struct prf_char_def_128 rdtsc_char[RDTSC_CHAR_MAX] = +{ + [RDTSC_SRV_TX_DATA_CHAR] = {RDTS_SERVER_TX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_NTF}, + [RDTSC_SRV_RX_DATA_CHAR] = {RDTS_SERVER_RX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_WR_NO_RESP}, +}; +/// State machine used to retrieve RDTS service characteristic description information +const struct prf_char_desc_def rdtsc_desc[RDTSC_DESC_MAX] = +{ + ///RDTS Client Config + [RDTSC_SRV_TX_DATA_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, RDTSC_SRV_TX_DATA_CHAR}, +}; + +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +void app_rdtsc_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSC; + prf.prf_task_handler = &app_rdtsc_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSC; + get_func.prf_itf_get_func = rdtsc_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtsc_add_rdts(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtsc_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSC; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtsc_db_cfg *) req->param; + + // Attribute table. In case the handle offset needs to be saved + db_cfg->p_char = &rdtsc_char[0]; + db_cfg->p_desc = &rdtsc_desc[0]; + db_cfg->p_uuid128 = rdtsc_uuid128; + + // Send the message + ke_msg_send(req); + + app_rdtsc_init(); +} + + +void app_rdtsc_enable_prf(uint8_t conidx) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_enable_req * req = KE_MSG_ALLOC(RDTSC_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_RDTSC), + TASK_APP, + rdtsc_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + req->con_type = PRF_CON_DISCOVERY; + + // Send the message + ke_msg_send(req); +} + + +void user_send_ble_data(const uint8_t *data, uint16_t length) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_data_tx_req * req = KE_MSG_ALLOC_DYN(RDTSC_DATA_TX_REQ, + prf_get_task_from_id(TASK_ID_RDTSC), + TASK_APP, + rdtsc_data_tx_req, + length); + + req->length = length; + memcpy(&req->data[0], data, length); + ke_msg_send(req); +} + + +/** + **************************************************************************************** + * @brief Handles client enable confirmation + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_enable_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_enable_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("RDTSC profile was enabled\r\n"); + + ns_ble_get_peer_info(GAPC_GET_PEER_FEATURES); + + return (KE_MSG_CONSUMED); +} + +/* + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_data_tx_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_data_tx_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + usart_forward_to_ble_loop(); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_data_rx_ind_handler(ke_msg_id_t const msgid, + struct rdtsc_data_rx_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + app_usart_tx_fifo_enter(param->data,param->length); + + return (KE_MSG_CONSUMED); +} + +/// Default State handlers definition +const struct ke_msg_handler app_rdtsc_msg_handler_list[] = +{ + {RDTSC_ENABLE_CFM, (ke_msg_func_t)rdtsc_enable_cfm_handler}, + {RDTSC_DATA_TX_CFM, (ke_msg_func_t)rdtsc_data_tx_cfm_handler}, + {RDTSC_DATA_RX_IND, (ke_msg_func_t)rdtsc_data_rx_ind_handler}, +}; + +const struct app_subtask_handlers app_rdtsc_handlers = APP_HANDLERS(app_rdtsc); + + +#endif //BLE_RDTS_CLIENT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_profile/app_rdtss.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_profile/app_rdtss.c new file mode 100644 index 0000000..e977cdd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_profile/app_rdtss.c @@ -0,0 +1,306 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtss.h" // rdtss Application Module Definitions +#include "rdtss_task.h" // Device Information Profile Functions +#include "gapm_task.h" // GAP Manager Task API +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" +#include "stdio.h" +#include "rdtss.h" +#include "app_usart.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +const uint8_t app_rdts_svc_uuid[16] = ATT_SERVICE_AM_SPEED_128; +const struct attm_desc_128 app_rdts_att_db[RDTSS_IDX_NB] = +{ + /* Service Declaration */ + [0] = {{0x00,0x28}, PERM(RD, ENABLE), 0, 0 }, + + /* Characteristic Declaration */ + [1] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [2] = {ATT_CHAR_AM_SPEED_WRITE_128, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [3] = {{0x01,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + /* Characteristic Declaration */ + [4] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [5] = {ATT_CHAR_AM_SPEED_NTF_128, PERM(NTF, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [6] = {{0x02,0x29}, PERM(RD, ENABLE) |PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, +}; + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtss_add_rdts(void) +{ + struct rdtss_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtss_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtss_db_cfg *) req->param; + // Attribute table. In case the handle offset needs to be saved + db_cfg->att_tbl = &app_rdts_att_db[0]; + db_cfg->svc_uuid = &app_rdts_svc_uuid[0]; + db_cfg->max_nb_att = RDTSS_IDX_NB; + + // Send the message + ke_msg_send(req); + + app_rdtss_init(); +} + +/** + * @brief rdtss value require indicate handler + * @param + * @return + * @note Note + */ +static int rdtss_value_req_ind_handler(ke_msg_id_t const msgid, + struct rdtss_value_req_ind const *req_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + len = APP_RDTSS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_RDTSS_MANUFACTURER_NAME; + + + // Allocate confirmation to send the value + struct rdtss_value_req_rsp *rsp_value = KE_MSG_ALLOC_DYN(RDTSS_VALUE_REQ_RSP, + src_id, dest_id, + rdtss_value_req_rsp, + len); + rsp_value->status = 0; + rsp_value->conidx = req_value ->conidx; + rsp_value->length = len; + rsp_value->att_idx = req_value->att_idx; + if (len) + { + // Copy data + memcpy(&rsp_value->value, data, len); + } + // Send message + ke_msg_send(rsp_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief cuusts write indicate handler + * @param + * @return + * @note + */ +static int rdtss_val_write_ind_handler(ke_msg_id_t const msgid, + struct rdtss_val_write_ind const *ind_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,write handle = %x,length = %x\r\n",__func__ ,ind_value->handle, ind_value->length); + + for(uint16_t i=0; ilength; i++) + { + NS_LOG_DEBUG("%x ",ind_value->value[i]); + } + NS_LOG_DEBUG("\r\n"); + + uint16_t handle = ind_value->handle; + uint16_t length = ind_value->length; + + switch (handle) + { + case RDTSS_IDX_NTF_CFG: + + if(length == 2) + { + uint16_t cfg_value = ind_value->value[0] + ind_value->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + //enabled notify + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + } + } + + break; + case RDTSS_IDX_WRITE_VAL: + //ble data receive + app_usart_tx_fifo_enter(ind_value->value,ind_value->length); + + break; + default: + break; + + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Functions + * @param + * @return + * @note Note + */ +static int rdtss_val_ntf_cfm_handler(ke_msg_id_t const msgid, + struct rdtss_val_ntf_cfm const *cfm_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,ntf cfm handle = %x, status = %x\r\n",__func__, cfm_value->handle, cfm_value->status); + + usart_forward_to_ble_loop(); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief rdtss send notify + * @param + * @return + * @note + */ +void rdtss_send_notify(uint8_t *data, uint16_t length) +{ + struct rdtss_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(RDTSS_VAL_NTF_REQ, + prf_get_task_from_id(TASK_ID_RDTSS), + TASK_APP, + rdtss_val_ntf_ind_req, + length); + + req->conidx = app_env.conidx; + req->notification = true; + req->handle = RDTSS_IDX_NTF_VAL; + req->length = length; + memcpy(&req->value[0], data, length); + + ke_msg_send(req); +} + + +/// Default State handlers definition +const struct ke_msg_handler app_rdtss_msg_handler_list[] = +{ + {RDTSS_VALUE_REQ_IND, (ke_msg_func_t)rdtss_value_req_ind_handler}, + {RDTSS_VAL_WRITE_IND, (ke_msg_func_t)rdtss_val_write_ind_handler}, + {RDTSS_VAL_NTF_CFM, (ke_msg_func_t)rdtss_val_ntf_cfm_handler}, + +}; + +const struct app_subtask_handlers app_rdtss_handlers = APP_HANDLERS(app_rdtss); + + +void app_rdtss_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSS; + prf.prf_task_handler = &app_rdtss_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSS; + get_func.prf_itf_get_func = rdtss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +#endif //BLE_RDTSS_SERVER diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_usart.c new file mode 100644 index 0000000..361cded --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/app_usart.c @@ -0,0 +1,609 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include +#include "global_func.h" +#include "app_usart.h" +#include "app_rdtsc.h" +#include "ns_sleep.h" +#include "ns_log.h" +#include "ns_timer.h" +#include "ke_timer.h" +#include "app_ble.h" +#include "rdts_client_task.h" +#include "app_rdtss.h" +#include "rdtss_task.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] = {0}; +uint16_t rx_old_pos = 0; + +uint8_t usart_rx_fifo_buf[USART_RX_FIFO_SIZE] = {0}; +uint32_t usart_rx_fifo_in = 0; +uint32_t usart_rx_fifo_out = 0; + + +uint8_t usart_tx_fifo_buf[USART_TX_FIFO_SIZE] = {0}; +uint32_t usart_tx_fifo_in = 0; +uint32_t usart_tx_fifo_out = 0; + +uint8_t usart_sending = false; +uint8_t ble_sending = false; +uint16_t ble_att_mtu = (ATT_DEFAULT_MTU-3); +extern uint8_t fw_mode ; +/* Private function prototypes -----------------------------------------------*/ +void app_usart_tx_process(void); + +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTx_Tx_DMA_Channel); + DMA_RequestRemap(USARTx_Tx_DMA_REMAP, DMA, USARTx_Tx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Tx_DMA_Channel,DMA_INT_TXC ,ENABLE); + + /* USARTx RX DMA1 Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTx_Rx_DMA_Channel); + DMA_RequestRemap(USARTx_Rx_DMA_REMAP, DMA, USARTx_Rx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Rx_DMA_Channel,DMA_INT_TXC|DMA_INT_HTX ,ENABLE); + + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)USART_rx_dma_buf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = USART_RX_DMA_SIZE; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Rx_DMA_Channel, &DMA_InitStructure); + +} + + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + NVIC_DisableIRQ(DMA_Channel1_2_3_4_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + + NVIC_DisableIRQ(USARTx_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void app_usart_configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* Configure the DMA */ + DMA_Configuration(); + + NVIC_Configuration(); + + /* USARTx and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; //921600 + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTx, USART_INT_IDLEF, ENABLE); + + /* Enable USARTx DMA Rx and TX request */ + USART_EnableDMA(USARTx, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief enable or disable the usart dma + */ +void app_usart_dma_enable(FunctionalState Cmd) +{ + if(Cmd == ENABLE) + { + ns_sleep_lock_acquire(); + rx_old_pos = 0; + usart_tx_fifo_in = usart_tx_fifo_out = 0; //clean fifo + usart_rx_fifo_in = usart_rx_fifo_out = 0; //clean fifo + app_usart_configuration(); + + } + else{ + ns_sleep_lock_release(); + USART_Enable(USARTx, DISABLE); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, DISABLE); + DMA_EnableChannel(USARTx_Tx_DMA_Channel, DISABLE); + /* Deinit IO of USART to save power */ + GPIO_InitType GPIO_InitStructure; + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + } +} + +/** + * @brief forward usart rx data too ble notify + */ +void usart_forward_to_ble_loop(void) +{ + NS_LOG_DEBUG("usart_rx_fifo_out = %x\r\n", usart_rx_fifo_out); + NS_LOG_DEBUG("usart_rx_fifo_in = %x\r\n", usart_rx_fifo_in); + + uint32_t in_temp; + uint16_t ble_send_len; + + in_temp = usart_rx_fifo_in; + if(usart_rx_fifo_out < in_temp) + { + ble_send_len = in_temp-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out > in_temp){ + ble_send_len = USART_RX_FIFO_SIZE-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out == in_temp){ + // fifo empty, stop send loop + ble_sending = false; + return; + } + if ((app_env.max_mtu-3)> ble_att_mtu) + { + ble_att_mtu = (app_env.max_mtu-3); + } + if(ble_send_len > ble_att_mtu) + { + ble_send_len = ble_att_mtu; + } + if(ble_send_len == 2) + { + if(memcmp( &usart_rx_fifo_buf[usart_rx_fifo_out],"\xfa\x55",2) == 0) + { + ke_timer_set(APP_SWITCH_CMD, TASK_APP, 10); + usart_rx_fifo_out = usart_rx_fifo_in = 0; + return; + } + } + + + if(ke_state_get(TASK_APP) == 3) //connected + { + ble_sending = true; + if(fw_mode) + { + NS_LOG_DEBUG("slave send, %x\r\n", ble_send_len); + rdtss_send_notify(&usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + } + else{ + NS_LOG_DEBUG("master send, %x\r\n", ble_send_len); + user_send_ble_data(&usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + } + } + else + { + NS_LOG_DEBUG("Not connect yet\r\n"); + } + + usart_rx_fifo_out = (usart_rx_fifo_out+ble_send_len)%USART_RX_FIFO_SIZE; + + return; +} + + +/** + * @brief usart rx data enter fifo and active ble send first package if not active yet + */ +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len; + //store data in fifo + while(len) + { + if(usart_rx_fifo_in >= usart_rx_fifo_out ) + { + in_len = USART_RX_FIFO_SIZE-usart_rx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + } + else if(usart_rx_fifo_in < usart_rx_fifo_out ) + { + in_len = usart_rx_fifo_out-usart_rx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F_RX:%d,%d,%d\r\n",len,usart_rx_fifo_in,usart_rx_fifo_out); + } + break; + } + } + + if(!ble_sending) + { + if(fw_mode) + { + // active send ble event after usart streaming cut + ke_timer_set(RDTSS_VAL_NTF_CFM, TASK_APP, 10); + } + else + { + // active send ble event after usart streaming cut + ke_timer_set(RDTSC_DATA_TX_CFM, TASK_APP, 10); + } + + } + + return len; +} + +/** + * @brief usart send data via dma + */ +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len) +{ + DMA_InitType DMA_InitStructure; + + if(usart_sending) + { + return false; + } + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)p_data; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = len; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Tx_DMA_Channel, &DMA_InitStructure); + + usart_sending = true; + DMA_EnableChannel(USARTx_Tx_DMA_Channel, ENABLE); + + return true; +} + +/** + * @brief usart send data in blocking mode + */ +void usart_tx_data_blocking(uint8_t *p_data, uint16_t len) +{ + while(len--) + { + USART_SendData(USARTx, *p_data); + p_data++; + } +} + +/** + * @brief usart tx fifo enter and active dma send out + */ +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len, out_temp; + //store data in fifo + NS_LOG_DEBUG("%d,%d,%d\r\n",len,usart_tx_fifo_in,usart_tx_fifo_out); + out_temp = usart_tx_fifo_out; + while(len) + { + if(usart_tx_fifo_in >= out_temp ) + { + in_len = USART_TX_FIFO_SIZE-usart_tx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + } + else if(usart_tx_fifo_in < out_temp ) + { + in_len = out_temp-usart_tx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F_TX:%d,%d,%d\r\n",len,usart_tx_fifo_in,out_temp); + } + break; + } + } + + // ble treaming cut timer, active usart send after it. + ke_timer_set(APP_UART_TX_EVT, TASK_APP, 50); + + return len; +} + +/** + * @brief usart tx data from fifo + */ +void app_usart_tx_process(void) +{ + uint32_t in_temp,len; + uint8_t *p_data; + + in_temp = usart_tx_fifo_in; + if(usart_tx_fifo_out < in_temp) + { + len = in_temp-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = in_temp; + } + + } + else if(usart_tx_fifo_out > in_temp) + { + len = USART_TX_FIFO_SIZE-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = 0; + } + + } +} + + +/** + * @brief check the dma buffer which has been received + */ +void usart_rx_check_in_irq(void) +{ + uint16_t rx_pos; + + rx_pos = USART_RX_DMA_SIZE - DMA_GetCurrDataCounter(USARTx_Rx_DMA_Channel); + + NS_LOG_DEBUG("RX_POS = %x\r\n", rx_pos); + NS_LOG_DEBUG("RX_OLD_POS = %x\r\n", rx_old_pos); + + if(rx_pos < rx_old_pos) + { + + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(USART_RX_DMA_SIZE - rx_old_pos)); + + if(rx_pos > 0) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[0],rx_pos); + } + + rx_old_pos = rx_pos; + } + else if(rx_pos > rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(rx_pos - rx_old_pos)); + rx_old_pos = rx_pos; + } + else if(rx_pos != rx_old_pos) + { + //error + rx_old_pos = rx_pos; + } + +} + + +/** + * @brief dma irq handler + */ +void DMA_Channel1_2_3_4_IRQHandler(void) +{ + //TX + if(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)) + { + //TX Transfer complete interrupt + usart_sending = false; + ke_msg_send_basic(APP_UART_TX_EVT, TASK_APP, TASK_APP); + + DMA_ClearFlag(DMA_FLAG_TC1, DMA); + } + //RX + if(DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + //RX Transfer complete interrupt + DMA_ClearFlag(DMA_FLAG_TC2, DMA); + usart_rx_check_in_irq(); + + } + if(DMA_GetFlagStatus(DMA_FLAG_HT2, DMA)) + { + //RX Half transfer interrupt + DMA_ClearFlag(DMA_FLAG_HT2, DMA); + usart_rx_check_in_irq(); + } + + +} + +/** + * @brief usart irq handler + */ +void USARTx_IRQHandler(void) +{ + uint8_t temp; + //usart idlle interrupt + if(USART_GetFlagStatus(USARTx,USART_FLAG_IDLEF)) + { + //read sts and data will clear rx idle interrupt + temp = USARTx->DAT; + usart_rx_check_in_irq(); + (void)temp; + } +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/main.c new file mode 100644 index 0000000..16db81c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdts_c&s/src/main.c @@ -0,0 +1,148 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_ble.h" + + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\nRaw Data Transfer Server and Client(128bit UUID) demo\r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + NS_LOG_INIT(); + NS_LOG_INFO(DEMO_STRING); + app_ble_master_init(); + // periph init + app_key_configuration(); + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + app_usart_dma_enable(ENABLE); + //init text + usart_tx_dma_send((uint8_t*)DEMO_STRING, sizeof(DEMO_STRING)); + + delay_n_10us(500); + //disable usart for enter sleep + app_usart_dma_enable(DISABLE); + + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + app_key_reinit_after_sleep(); + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/MDK-ARM/central_rdtsc.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/MDK-ARM/central_rdtsc.uvoptx new file mode 100644 index 0000000..cc88289 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/MDK-ARM/central_rdtsc.uvoptx @@ -0,0 +1,687 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + 4 + 17 + 4 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + n32wb03x_host_lib.lib + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils_128.c + prf_utils_128.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client.c + rdts_client.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_task.c + rdts_client_task.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 7 + 30 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtsc.c + app_rdtsc.c + 0 + 0 + + + 7 + 31 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 32 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 33 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + 8 + 34 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 9 + 35 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 36 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/MDK-ARM/central_rdtsc.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/MDK-ARM/central_rdtsc.uvprojx new file mode 100644 index 0000000..ce7a4c7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/MDK-ARM/central_rdtsc.uvprojx @@ -0,0 +1,688 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0x8000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtsc + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\rdtsc.bin .\Objects\rdtsc.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x8000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\custom;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\custom\custs\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15_central.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + n32wb03x_host_lib.lib + 4 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + prf_utils_128.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils_128.c + + + rdts_client.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client.c + + + rdts_client_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_rdtsc.c + 1 + ..\src\app_profile\app_rdtsc.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_ble.h new file mode 100644 index 0000000..dc094fa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_UART_TX_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_profile/app_rdtsc.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_profile/app_rdtsc.h new file mode 100644 index 0000000..2c4eaae --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_profile/app_rdtsc.h @@ -0,0 +1,89 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSC_H_ +#define APP_RDTSC_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_CLIENT) + + +/// Table of message handlers +extern const struct app_subtask_handlers app_rdtsc_handlers; + +void app_rdtsc_init(void); +void app_rdtsc_add_rdts(void); +void app_rdtsc_enable_prf(uint8_t conidx); +void user_send_ble_data(const uint8_t *data, uint16_t length); + +#endif //BLE_RDTS_CLIENT + +/// @} APP + +#endif // APP_RDTSC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_usart.h new file mode 100644 index 0000000..2115114 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_usart.h @@ -0,0 +1,152 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTx_DAT_Base (USART1_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART1_RX +#define USARTx_IRQn USART1_IRQn +#define USARTx_IRQHandler USART1_IRQHandler +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define USARTx_DAT_Base (USART2_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#define USARTx_IRQn USART2_IRQn +#define USARTx_IRQHandler USART2_IRQHandler +#endif + + +#define USART_RX_DMA_SIZE 256 +#define USART_RX_FIFO_SIZE 1000 +#define USART_TX_FIFO_SIZE 1000 + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + +/* Public function prototypes -----------------------------------------------*/ + +void app_usart_configuration(void); +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len); +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len); +void app_usart_tx_data_blocking(uint8_t *p_data, uint16_t len); + +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len); +void usart_forward_to_ble_loop(void); +void app_usart_dma_enable(FunctionalState Cmd); +void app_usart_tx_process(void); +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_user_config.h new file mode 100644 index 0000000..1c0c5ff --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/inc/app_user_config.h @@ -0,0 +1,113 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_RDTS_CLIENT" /** +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "ns_sec.h" +#include "app_rdtsc.h" +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_UART_TX_EVT: + app_usart_tx_process(); + break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_rdtsc_enable_prf(app_env.conidx); + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief scan data handler + * @param + * @return + * @note + */ +void app_ble_scan_data_handler(struct gapm_ext_adv_report_ind const* p_param) +{ + NS_LOG_INFO("Found:%02x%02x%02x%02x%02x%02x, rssi:%d \r\n", + p_param->trans_addr.addr.addr[0], + p_param->trans_addr.addr.addr[1], + p_param->trans_addr.addr.addr[2], + p_param->trans_addr.addr.addr[3], + p_param->trans_addr.addr.addr[4], + p_param->trans_addr.addr.addr[5], + p_param->rssi); + +} + +/** + * @brief scan state handler + * @param + * @return + * @note + */ +void app_ble_scan_state_handler(enum scan_state_t state) +{ + switch (state) + { + case SCAN_STATE_SCANING: + NS_LOG_INFO("Scaning.\r\n"); + break; + case SCAN_STATE_FOUND: + NS_LOG_INFO("Found target.\r\n"); + break; + case SCAN_STATE_CONN_TIMEOUT: + NS_LOG_INFO("Connect timeout.\r\n"); + break; + default: + break; + } +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_ALL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble scan initialization + * @param + * @return + * @note + */ +void app_ble_scan_init(void) +{ + struct ns_scan_params_t init = {0}; +// static const uint8_t target_addr[] = {"\x11\x11\x11\x11\x11\x11"}; + static const uint8_t target_name[] = {"NS_RDTSS"}; +// static const uint16_t target_uuid16 = 0x180A; + + init.type = SCAN_PARAM_TYPE; + init.dup_filt_pol = SCAN_PARAM_DUP_FILT_POL; + init.connect_enable = SCAN_PARAM_CONNECT_EN; + init.prop_active_enable = SCAN_PARAM_PROP_ACTIVE; + init.scan_intv = SCAN_PARAM_INTV; + init.scan_wd = SCAN_PARAM_WD; + init.duration = SCAN_PARAM_DURATION; + init.initiating_timeout = 3000; + + init.filter_type = SCAN_FILTER_BY_NAME;//SCAN_FILTER_BY_ADDRESS; + init.filter_data = (uint8_t*)&target_name; + + init.ble_scan_data_handler = app_ble_scan_data_handler; + init.ble_scan_state_handler = app_ble_scan_state_handler; + + ns_ble_scan_init(&init); +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtsc_add_rdts); +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_scan_init(); + app_ble_prf_init(); + //start scan + ns_ble_start_scan(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + //enable usart receive + app_usart_dma_enable(ENABLE); + LedOn(LED2_PORT,LED2_PIN); + + #if (BLE_APP_BATT) + // Enable Battery Service + app_batt_enable_prf(app_env.conidx); + #endif //(BLE_APP_BATT) +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart scan + ns_ble_start_scan(); + + //disable usart receive + app_usart_dma_enable(DISABLE); + LedOff(LED2_PORT,LED2_PIN); +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/app_profile/app_rdtsc.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/app_profile/app_rdtsc.c new file mode 100644 index 0000000..021e288 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/app_profile/app_rdtsc.c @@ -0,0 +1,282 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_CLIENT) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtsc.h" +#include "rdts_client_task.h" +#include "gapm_task.h" +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" +#include "stdio.h" +#include "ns_ble_task.h" +#include "app_usart.h" +#include "string.h" +#include "prf_utils_128.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define RDTS_SERVICE_UUID {0x01, 0x10, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_TX_UUID {0x02, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_RX_UUID {0x01, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} + +/* Private constants ---------------------------------------------------------*/ +const uint8_t rdtsc_uuid128[]= RDTS_SERVICE_UUID; +/// State machine used to retrieve RDTS characteristics information +const struct prf_char_def_128 rdtsc_char[RDTSC_CHAR_MAX] = +{ + [RDTSC_SRV_TX_DATA_CHAR] = {RDTS_SERVER_TX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_NTF}, + [RDTSC_SRV_RX_DATA_CHAR] = {RDTS_SERVER_RX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_WR_NO_RESP}, +}; +/// State machine used to retrieve RDTS service characteristic description information +const struct prf_char_desc_def rdtsc_desc[RDTSC_DESC_MAX] = +{ + ///RDTS Client Config + [RDTSC_SRV_TX_DATA_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, RDTSC_SRV_TX_DATA_CHAR}, +}; + +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +void app_rdtsc_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSC; + prf.prf_task_handler = &app_rdtsc_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSC; + get_func.prf_itf_get_func = rdtsc_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtsc_add_rdts(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtsc_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSC; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtsc_db_cfg *) req->param; + + // Attribute table. In case the handle offset needs to be saved + db_cfg->p_char = &rdtsc_char[0]; + db_cfg->p_desc = &rdtsc_desc[0]; + db_cfg->p_uuid128 = rdtsc_uuid128; + + // Send the message + ke_msg_send(req); + + app_rdtsc_init(); +} + + +void app_rdtsc_enable_prf(uint8_t conidx) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_enable_req * req = KE_MSG_ALLOC(RDTSC_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_RDTSC), + TASK_APP, + rdtsc_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + req->con_type = PRF_CON_DISCOVERY; + + // Send the message + ke_msg_send(req); +} + + +void user_send_ble_data(const uint8_t *data, uint16_t length) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_data_tx_req * req = KE_MSG_ALLOC_DYN(RDTSC_DATA_TX_REQ, + prf_get_task_from_id(TASK_ID_RDTSC), + TASK_APP, + rdtsc_data_tx_req, + length); + + req->length = length; + memcpy(&req->data[0], data, length); + ke_msg_send(req); +} + + +/** + **************************************************************************************** + * @brief Handles client enable confirmation + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_enable_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_enable_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("RDTSC profile was enabled\r\n"); + + ns_ble_get_peer_info(GAPC_GET_PEER_FEATURES); + + return (KE_MSG_CONSUMED); +} + +/* + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_data_tx_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_data_tx_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + usart_forward_to_ble_loop(); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_data_rx_ind_handler(ke_msg_id_t const msgid, + struct rdtsc_data_rx_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("BLE Data was received\r\n"); + NS_LOG_DEBUG("length = %x\r\n", param->length); + NS_LOG_DEBUG("handle = %x\r\n", param->handle); + NS_LOG_DEBUG("type = %x\r\n", param->type); + NS_LOG_DEBUG("data "); + for(uint8_t i=0; ilength; i++) + { + NS_LOG_DEBUG(" %x", param->data[i]); + } + NS_LOG_DEBUG("\r\n"); + + app_usart_tx_fifo_enter(param->data,param->length); + + return (KE_MSG_CONSUMED); +} + +/// Default State handlers definition +const struct ke_msg_handler app_rdtsc_msg_handler_list[] = +{ + {RDTSC_ENABLE_CFM, (ke_msg_func_t)rdtsc_enable_cfm_handler}, + {RDTSC_DATA_TX_CFM, (ke_msg_func_t)rdtsc_data_tx_cfm_handler}, + {RDTSC_DATA_RX_IND, (ke_msg_func_t)rdtsc_data_rx_ind_handler}, +}; + +const struct app_subtask_handlers app_rdtsc_handlers = APP_HANDLERS(app_rdtsc); + + +#endif //BLE_RDTS_CLIENT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/app_usart.c new file mode 100644 index 0000000..0bdb085 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/app_usart.c @@ -0,0 +1,575 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include +#include "global_func.h" +#include "app_usart.h" +#include "app_rdtsc.h" +#include "ns_sleep.h" +#include "ns_log.h" +#include "ns_timer.h" +#include "ke_timer.h" +#include "app_ble.h" +#include "rdts_client_task.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] = {0}; +uint16_t rx_old_pos = 0; + +uint8_t usart_rx_fifo_buf[USART_RX_FIFO_SIZE] = {0}; +uint32_t usart_rx_fifo_in = 0; +uint32_t usart_rx_fifo_out = 0; + + +uint8_t usart_tx_fifo_buf[USART_TX_FIFO_SIZE] = {0}; +uint32_t usart_tx_fifo_in = 0; +uint32_t usart_tx_fifo_out = 0; + +uint8_t usart_sending = false; +uint8_t ble_sending = false; +uint16_t ble_att_mtu = (ATT_DEFAULT_MTU-3); + +/* Private function prototypes -----------------------------------------------*/ +void app_usart_tx_process(void); + +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTx_Tx_DMA_Channel); + DMA_RequestRemap(USARTx_Tx_DMA_REMAP, DMA, USARTx_Tx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Tx_DMA_Channel,DMA_INT_TXC ,ENABLE); + + /* USARTx RX DMA1 Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTx_Rx_DMA_Channel); + DMA_RequestRemap(USARTx_Rx_DMA_REMAP, DMA, USARTx_Rx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Rx_DMA_Channel,DMA_INT_TXC|DMA_INT_HTX ,ENABLE); + + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)USART_rx_dma_buf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = USART_RX_DMA_SIZE; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Rx_DMA_Channel, &DMA_InitStructure); + +} + + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + NVIC_DisableIRQ(DMA_Channel1_2_3_4_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + + NVIC_DisableIRQ(USARTx_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void app_usart_configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* Configure the DMA */ + DMA_Configuration(); + + NVIC_Configuration(); + + /* USARTx and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; //921600 + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTx, USART_INT_IDLEF, ENABLE); + + /* Enable USARTx DMA Rx and TX request */ + USART_EnableDMA(USARTx, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief enable or disable the usart dma + */ +void app_usart_dma_enable(FunctionalState Cmd) +{ + if(Cmd == ENABLE) + { + ns_sleep_lock_acquire(); + rx_old_pos = 0; + usart_tx_fifo_in = usart_tx_fifo_out = 0; //clean fifo + usart_rx_fifo_in = usart_rx_fifo_out = 0; //clean fifo + app_usart_configuration(); + + } + else{ + ns_sleep_lock_release(); + USART_Enable(USARTx, DISABLE); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, DISABLE); + DMA_EnableChannel(USARTx_Tx_DMA_Channel, DISABLE); + /* Deinit IO of USART to save power */ + GPIO_InitType GPIO_InitStructure; + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + } +} + +/** + * @brief forward usart rx data too ble notify + */ +void usart_forward_to_ble_loop(void) +{ + NS_LOG_DEBUG("usart_rx_fifo_out = %x\r\n", usart_rx_fifo_out); + NS_LOG_DEBUG("usart_rx_fifo_in = %x\r\n", usart_rx_fifo_in); + + uint32_t in_temp; + uint16_t ble_send_len; + + in_temp = usart_rx_fifo_in; + if(usart_rx_fifo_out < in_temp) + { + ble_send_len = in_temp-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out > in_temp){ + ble_send_len = USART_RX_FIFO_SIZE-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out == in_temp){ + // fifo empty, stop send loop + ble_sending = false; + return; + } + if ((app_env.max_mtu-3)> ble_att_mtu) + { + ble_att_mtu = (app_env.max_mtu-3); + } + if(ble_send_len > ble_att_mtu) + { + ble_send_len = ble_att_mtu; + } + ble_sending = true; + #if (BLE_RDTS_CLIENT) + NS_LOG_DEBUG("ble_send_len = %x\r\n", ble_send_len); + user_send_ble_data(&usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + #endif + usart_rx_fifo_out = (usart_rx_fifo_out+ble_send_len)%USART_RX_FIFO_SIZE; + + return; +} + + +/** + * @brief usart rx data enter fifo and active ble send first package if not active yet + */ +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len; + //store data in fifo + while(len) + { + if(usart_rx_fifo_in >= usart_rx_fifo_out ) + { + in_len = USART_RX_FIFO_SIZE-usart_rx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + } + else if(usart_rx_fifo_in < usart_rx_fifo_out ) + { + in_len = usart_rx_fifo_out-usart_rx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F_RX:%d,%d,%d\r\n",len,usart_rx_fifo_in,usart_rx_fifo_out); + } + break; + } + } + + if(!ble_sending) + { + // active send ble event after usart streaming cut + ke_timer_set(RDTSC_DATA_TX_CFM, TASK_APP, 10); + } + + return len; +} + +/** + * @brief usart send data via dma + */ +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len) +{ + DMA_InitType DMA_InitStructure; + + if(usart_sending) + { + return false; + } + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)p_data; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = len; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Tx_DMA_Channel, &DMA_InitStructure); + + usart_sending = true; + DMA_EnableChannel(USARTx_Tx_DMA_Channel, ENABLE); + + return true; +} + +/** + * @brief usart send data in blocking mode + */ +void usart_tx_data_blocking(uint8_t *p_data, uint16_t len) +{ + while(len--) + { + USART_SendData(USARTx, *p_data); + p_data++; + } +} + +/** + * @brief usart tx fifo enter and active dma send out + */ +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len, out_temp; + //store data in fifo + NS_LOG_DEBUG("%d,%d,%d\r\n",len,usart_tx_fifo_in,usart_tx_fifo_out); + out_temp = usart_tx_fifo_out; + while(len) + { + if(usart_tx_fifo_in >= out_temp ) + { + in_len = USART_TX_FIFO_SIZE-usart_tx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + } + else if(usart_tx_fifo_in < out_temp ) + { + in_len = out_temp-usart_tx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F_TX:%d,%d,%d\r\n",len,usart_tx_fifo_in,out_temp); + } + break; + } + } + + // ble treaming cut timer, active usart send after it. + ke_timer_set(APP_UART_TX_EVT, TASK_APP, 50); + + return len; +} + +/** + * @brief usart tx data from fifo + */ +void app_usart_tx_process(void) +{ + uint32_t in_temp,len; + uint8_t *p_data; + + in_temp = usart_tx_fifo_in; + if(usart_tx_fifo_out < in_temp) + { + len = in_temp-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = in_temp; + } + + } + else if(usart_tx_fifo_out > in_temp) + { + len = USART_TX_FIFO_SIZE-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = 0; + } + + } +} + + +/** + * @brief check the dma buffer which has been received + */ +void usart_rx_check_in_irq(void) +{ + uint16_t rx_pos; + + rx_pos = USART_RX_DMA_SIZE - DMA_GetCurrDataCounter(USARTx_Rx_DMA_Channel); + + NS_LOG_DEBUG("RX_POS = %x\r\n", rx_pos); + NS_LOG_DEBUG("RX_OLD_POS = %x\r\n", rx_old_pos); + + if(rx_pos < rx_old_pos) + { + + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(USART_RX_DMA_SIZE - rx_old_pos)); + + if(rx_pos > 0) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[0],rx_pos); + } + + rx_old_pos = rx_pos; + } + else if(rx_pos > rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(rx_pos - rx_old_pos)); + rx_old_pos = rx_pos; + } + else if(rx_pos != rx_old_pos) + { + //error + rx_old_pos = rx_pos; + } + +} + + +/** + * @brief dma irq handler + */ +void DMA_Channel1_2_3_4_IRQHandler(void) +{ + //TX + if(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)) + { + //TX Transfer complete interrupt + usart_sending = false; + ke_msg_send_basic(APP_UART_TX_EVT, TASK_APP, TASK_APP); + + DMA_ClearFlag(DMA_FLAG_TC1, DMA); + } + //RX + if(DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + //RX Transfer complete interrupt + DMA_ClearFlag(DMA_FLAG_TC2, DMA); + usart_rx_check_in_irq(); + + } + if(DMA_GetFlagStatus(DMA_FLAG_HT2, DMA)) + { + //RX Half transfer interrupt + DMA_ClearFlag(DMA_FLAG_HT2, DMA); + usart_rx_check_in_irq(); + } + + +} + +/** + * @brief usart irq handler + */ +void USARTx_IRQHandler(void) +{ + uint8_t temp; + //usart idlle interrupt + if(USART_GetFlagStatus(USARTx,USART_FLAG_IDLEF)) + { + //read sts and data will clear rx idle interrupt + temp = USARTx->DAT; + usart_rx_check_in_irq(); + (void)temp; + } + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/main.c new file mode 100644 index 0000000..71fe06f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc/src/main.c @@ -0,0 +1,150 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_ble.h" + + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\nRaw Data Transfer Client(128bit UUID) demo\r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + app_usart_dma_enable(ENABLE); + //init text + usart_tx_dma_send((uint8_t*)DEMO_STRING, sizeof(DEMO_STRING)); + + delay_n_10us(500); + //disable usart for enter sleep + app_usart_dma_enable(DISABLE); + + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/MDK-ARM/central_rdtsc_16bit.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/MDK-ARM/central_rdtsc_16bit.uvoptx new file mode 100644 index 0000000..b2c120b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/MDK-ARM/central_rdtsc_16bit.uvoptx @@ -0,0 +1,672 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + 4 + 17 + 4 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + n32wb03x_host_lib.lib + 0 + 0 + + + + + BLE_PROFILE + 1 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_16bit.c + rdts_client_16bit.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_16bit_task.c + rdts_client_16bit_task.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 6 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 1 + 0 + 0 + 0 + + 7 + 29 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + 7 + 30 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtsc_16bit.c + app_rdtsc_16bit.c + 0 + 0 + + + + + USER + 1 + 0 + 0 + 0 + + 8 + 31 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 32 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + 8 + 33 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + + + CONFIG + 1 + 0 + 0 + 0 + + 9 + 34 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 1 + 0 + 0 + 0 + + 10 + 35 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/MDK-ARM/central_rdtsc_16bit.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/MDK-ARM/central_rdtsc_16bit.uvprojx new file mode 100644 index 0000000..8d18b8d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/MDK-ARM/central_rdtsc_16bit.uvprojx @@ -0,0 +1,686 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0x8000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtsc_16bit + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\rdtsc_16bit.bin .\Objects\rdtsc_16bit.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x8000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\custom;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\custom\custs\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15_central.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + n32wb03x_host_lib.lib + 4 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + rdts_client_16bit.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_16bit.c + + + rdts_client_16bit_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_16bit_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_ble.c + 1 + ..\src\app_ble.c + + + app_rdtsc_16bit.c + 1 + ..\src\app_profile\app_rdtsc_16bit.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_ble.h new file mode 100644 index 0000000..dc094fa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_UART_TX_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_profile/app_rdtsc_16bit.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_profile/app_rdtsc_16bit.h new file mode 100644 index 0000000..f681efe --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_profile/app_rdtsc_16bit.h @@ -0,0 +1,89 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc_16bit.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSC_H_ +#define APP_RDTSC_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_16BIT_CLIENT) + + +/// Table of message handlers +extern const struct app_subtask_handlers app_rdtsc_16bit_handlers; + +void app_rdtsc_16bit_init(void); +void app_rdtsc_16bit_add_rdts(void); +void app_rdtsc_16bit_enable_prf(uint8_t conidx); +void user_send_ble_data(const uint8_t *data, uint16_t length); + +#endif //BLE_RDTS_16BIT_CLIENT + +/// @} APP + +#endif // APP_RDTSC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_usart.h new file mode 100644 index 0000000..2115114 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_usart.h @@ -0,0 +1,152 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTx_DAT_Base (USART1_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART1_RX +#define USARTx_IRQn USART1_IRQn +#define USARTx_IRQHandler USART1_IRQHandler +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define USARTx_DAT_Base (USART2_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#define USARTx_IRQn USART2_IRQn +#define USARTx_IRQHandler USART2_IRQHandler +#endif + + +#define USART_RX_DMA_SIZE 256 +#define USART_RX_FIFO_SIZE 1000 +#define USART_TX_FIFO_SIZE 1000 + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + +/* Public function prototypes -----------------------------------------------*/ + +void app_usart_configuration(void); +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len); +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len); +void app_usart_tx_data_blocking(uint8_t *p_data, uint16_t len); + +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len); +void usart_forward_to_ble_loop(void); +void app_usart_dma_enable(FunctionalState Cmd); +void app_usart_tx_process(void); +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_user_config.h new file mode 100644 index 0000000..59b4867 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/inc/app_user_config.h @@ -0,0 +1,113 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_RDTS_CLIENT" /** +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "ns_sec.h" +#include "app_rdtsc_16bit.h" +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_UART_TX_EVT: + app_usart_tx_process(); + break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_rdtsc_16bit_enable_prf(app_env.conidx); + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief scan data handler + * @param + * @return + * @note + */ +void app_ble_scan_data_handler(struct gapm_ext_adv_report_ind const* p_param) +{ +// NS_LOG_INFO("Found:%02x%02x%02x%02x%02x%02x, rssi:%d \r\n", +// p_param->trans_addr.addr.addr[0], +// p_param->trans_addr.addr.addr[1], +// p_param->trans_addr.addr.addr[2], +// p_param->trans_addr.addr.addr[3], +// p_param->trans_addr.addr.addr[4], +// p_param->trans_addr.addr.addr[5], +// p_param->rssi); + +} + +/** + * @brief scan state handler + * @param + * @return + * @note + */ +void app_ble_scan_state_handler(enum scan_state_t state) +{ + switch (state) + { + case SCAN_STATE_SCANING: + NS_LOG_INFO("Scaning.\r\n"); + break; + case SCAN_STATE_FOUND: + NS_LOG_INFO("Found target.\r\n"); + break; + case SCAN_STATE_CONN_TIMEOUT: + NS_LOG_INFO("Connect timeout.\r\n"); + break; + default: + break; + } +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_ALL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble scan initialization + * @param + * @return + * @note + */ +void app_ble_scan_init(void) +{ + struct ns_scan_params_t init = {0}; +// static const uint8_t target_addr[] = {"\x11\x11\x11\x11\x11\x11"}; + static const uint8_t target_name[] = {"NS_RDTSS_16"}; +// static const uint16_t target_uuid16 = 0x180A; + + init.type = SCAN_PARAM_TYPE; + init.dup_filt_pol = SCAN_PARAM_DUP_FILT_POL; + init.connect_enable = SCAN_PARAM_CONNECT_EN; + init.prop_active_enable = SCAN_PARAM_PROP_ACTIVE; + init.scan_intv = SCAN_PARAM_INTV; + init.scan_wd = SCAN_PARAM_WD; + init.duration = SCAN_PARAM_DURATION; + init.initiating_timeout = 3000; + + init.filter_type = SCAN_FILTER_BY_NAME;//SCAN_FILTER_BY_ADDRESS; + init.filter_data = (uint8_t*)&target_name; + + init.ble_scan_data_handler = app_ble_scan_data_handler; + init.ble_scan_state_handler = app_ble_scan_state_handler; + + ns_ble_scan_init(&init); +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add 16bit raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtsc_16bit_add_rdts); +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_scan_init(); + app_ble_prf_init(); + //start scan + ns_ble_start_scan(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + //enable usart receive + app_usart_dma_enable(ENABLE); + LedOn(LED2_PORT,LED2_PIN); + + #if (BLE_APP_BATT) + // Enable Battery Service + app_batt_enable_prf(app_env.conidx); + #endif //(BLE_APP_BATT) +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart scan + ns_ble_start_scan(); + + //disable usart receive + app_usart_dma_enable(DISABLE); + LedOff(LED2_PORT,LED2_PIN); +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/app_profile/app_rdtsc_16bit.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/app_profile/app_rdtsc_16bit.c new file mode 100644 index 0000000..5979801 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/app_profile/app_rdtsc_16bit.c @@ -0,0 +1,281 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc_16bit.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_16BIT_CLIENT) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtsc_16bit.h" +#include "rdts_client_16bit_task.h" +#include "gapm_task.h" +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" +#include "stdio.h" +#include "ns_ble_task.h" +#include "app_usart.h" +#include "string.h" +#include "prf_utils.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define RDTS_SERVICE_UUID 0xfffa +#define RDTS_SERVER_TX_UUID 0xfffb +#define RDTS_SERVER_RX_UUID 0xfffc + +/* Private constants ---------------------------------------------------------*/ +const uint16_t rdtsc_uuid16 = RDTS_SERVICE_UUID; +/// State machine used to retrieve RDTS characteristics information + struct prf_char_def rdtsc_char[RDTSC_CHAR_MAX] = +{ + [RDTSC_SRV_TX_DATA_CHAR] = {RDTS_SERVER_TX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_WR_NO_RESP}, + [RDTSC_SRV_RX_DATA_CHAR] = {RDTS_SERVER_RX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_NTF}, +}; +/// State machine used to retrieve RDTS service characteristic description information + struct prf_char_desc_def rdtsc_desc[RDTSC_DESC_MAX] = +{ + ///RDTS Client Config + [RDTSC_SRV_TX_DATA_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, RDTSC_SRV_RX_DATA_CHAR}, +}; + +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +void app_rdtsc_16bit_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSC_16BIT; + prf.prf_task_handler = &app_rdtsc_16bit_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSC_16BIT; + get_func.prf_itf_get_func = rdtsc_16bit_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief Create 16bit raw data transfer server profile database. + * @return void + */ +void app_rdtsc_16bit_add_rdts(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtsc_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSC_16BIT; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtsc_db_cfg *) req->param; + + // Attribute table. In case the handle offset needs to be saved + db_cfg->p_char = &rdtsc_char[0]; + db_cfg->p_desc = &rdtsc_desc[0]; + db_cfg->uuid16 = rdtsc_uuid16; + + // Send the message + ke_msg_send(req); + + app_rdtsc_16bit_init(); +} + + +void app_rdtsc_16bit_enable_prf(uint8_t conidx) +{ + struct rdtsc_enable_req * req = KE_MSG_ALLOC(RDTSC_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_RDTSC_16BIT), + TASK_APP, + rdtsc_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + req->con_type = PRF_CON_DISCOVERY; + + // Send the message + ke_msg_send(req); +} + + +void user_send_ble_data(const uint8_t *data, uint16_t length) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_data_tx_req * req = KE_MSG_ALLOC_DYN(RDTSC_DATA_TX_REQ, + prf_get_task_from_id(TASK_ID_RDTSC_16BIT), + TASK_APP, + rdtsc_data_tx_req, + length); + + req->length = length; + memcpy(&req->data[0], data, length); + ke_msg_send(req); +} + + +/** + **************************************************************************************** + * @brief Handles client enable confirmation + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_16bit_enable_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_enable_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("RDTSC_16BIT profile was enabled, 0x%x\r\n",param->status); + + ns_ble_get_peer_info(GAPC_GET_PEER_FEATURES); + + return (KE_MSG_CONSUMED); +} + +/* + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_16bit_data_tx_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_data_tx_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + usart_forward_to_ble_loop(); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_16bit_data_rx_ind_handler(ke_msg_id_t const msgid, + struct rdtsc_data_rx_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("BLE Data was received\r\n"); + NS_LOG_DEBUG("length = %x\r\n", param->length); + NS_LOG_DEBUG("handle = %x\r\n", param->handle); + NS_LOG_DEBUG("type = %x\r\n", param->type); + NS_LOG_DEBUG("data "); + for(uint8_t i=0; ilength; i++) + { + NS_LOG_DEBUG(" %x", param->data[i]); + } + NS_LOG_DEBUG("\r\n"); + + app_usart_tx_fifo_enter(param->data,param->length); + + return (KE_MSG_CONSUMED); +} + +/// Default State handlers definition +const struct ke_msg_handler app_rdtsc_16bit_msg_handler_list[] = +{ + {RDTSC_ENABLE_CFM, (ke_msg_func_t)rdtsc_16bit_enable_cfm_handler}, + {RDTSC_DATA_TX_CFM, (ke_msg_func_t)rdtsc_16bit_data_tx_cfm_handler}, + {RDTSC_DATA_RX_IND, (ke_msg_func_t)rdtsc_16bit_data_rx_ind_handler}, +}; + +const struct app_subtask_handlers app_rdtsc_16bit_handlers = APP_HANDLERS(app_rdtsc_16bit); + + +#endif //BLE_RDTS_16BIT_CLIENT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/app_usart.c new file mode 100644 index 0000000..77d54ad --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/app_usart.c @@ -0,0 +1,575 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include +#include "global_func.h" +#include "app_usart.h" +#include "app_rdtsc_16bit.h" +#include "ns_sleep.h" +#include "ns_log.h" +#include "ns_timer.h" +#include "ke_timer.h" +#include "app_ble.h" +#include "rdts_client_16bit_task.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] = {0}; +uint16_t rx_old_pos = 0; + +uint8_t usart_rx_fifo_buf[USART_RX_FIFO_SIZE] = {0}; +uint32_t usart_rx_fifo_in = 0; +uint32_t usart_rx_fifo_out = 0; + + +uint8_t usart_tx_fifo_buf[USART_TX_FIFO_SIZE] = {0}; +uint32_t usart_tx_fifo_in = 0; +uint32_t usart_tx_fifo_out = 0; + +uint8_t usart_sending = false; +uint8_t ble_sending = false; +uint16_t ble_att_mtu = (ATT_DEFAULT_MTU-3); + +/* Private function prototypes -----------------------------------------------*/ +void app_usart_tx_process(void); + +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTx_Tx_DMA_Channel); + DMA_RequestRemap(USARTx_Tx_DMA_REMAP, DMA, USARTx_Tx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Tx_DMA_Channel,DMA_INT_TXC ,ENABLE); + + /* USARTx RX DMA1 Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTx_Rx_DMA_Channel); + DMA_RequestRemap(USARTx_Rx_DMA_REMAP, DMA, USARTx_Rx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Rx_DMA_Channel,DMA_INT_TXC|DMA_INT_HTX ,ENABLE); + + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)USART_rx_dma_buf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = USART_RX_DMA_SIZE; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Rx_DMA_Channel, &DMA_InitStructure); + +} + + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + NVIC_DisableIRQ(DMA_Channel1_2_3_4_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + + NVIC_DisableIRQ(USARTx_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void app_usart_configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* Configure the DMA */ + DMA_Configuration(); + + NVIC_Configuration(); + + /* USARTx and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; //921600 + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTx, USART_INT_IDLEF, ENABLE); + + /* Enable USARTx DMA Rx and TX request */ + USART_EnableDMA(USARTx, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief enable or disable the usart dma + */ +void app_usart_dma_enable(FunctionalState Cmd) +{ + if(Cmd == ENABLE) + { + ns_sleep_lock_acquire(); + rx_old_pos = 0; + usart_tx_fifo_in = usart_tx_fifo_out = 0; //clean fifo + usart_rx_fifo_in = usart_rx_fifo_out = 0; //clean fifo + app_usart_configuration(); + + } + else{ + ns_sleep_lock_release(); + USART_Enable(USARTx, DISABLE); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, DISABLE); + DMA_EnableChannel(USARTx_Tx_DMA_Channel, DISABLE); + /* Deinit IO of USART to save power */ + GPIO_InitType GPIO_InitStructure; + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + } +} + +/** + * @brief forward usart rx data too ble notify + */ +void usart_forward_to_ble_loop(void) +{ + NS_LOG_DEBUG("usart_rx_fifo_out = %x\r\n", usart_rx_fifo_out); + NS_LOG_DEBUG("usart_rx_fifo_in = %x\r\n", usart_rx_fifo_in); + + uint32_t in_temp; + uint16_t ble_send_len; + + in_temp = usart_rx_fifo_in; + if(usart_rx_fifo_out < in_temp) + { + ble_send_len = in_temp-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out > in_temp){ + ble_send_len = USART_RX_FIFO_SIZE-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out == in_temp){ + // fifo empty, stop send loop + ble_sending = false; + return; + } + if ((app_env.max_mtu-3)> ble_att_mtu) + { + ble_att_mtu = (app_env.max_mtu-3); + } + if(ble_send_len > ble_att_mtu) + { + ble_send_len = ble_att_mtu; + } + ble_sending = true; + #if (BLE_RDTS_16BIT_CLIENT) + NS_LOG_DEBUG("ble_send_len = %x\r\n", ble_send_len); + user_send_ble_data(&usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + #endif + usart_rx_fifo_out = (usart_rx_fifo_out+ble_send_len)%USART_RX_FIFO_SIZE; + + return; +} + + +/** + * @brief usart rx data enter fifo and active ble send first package if not active yet + */ +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len; + //store data in fifo + while(len) + { + if(usart_rx_fifo_in >= usart_rx_fifo_out ) + { + in_len = USART_RX_FIFO_SIZE-usart_rx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + } + else if(usart_rx_fifo_in < usart_rx_fifo_out ) + { + in_len = usart_rx_fifo_out-usart_rx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F_RX:%d,%d,%d\r\n",len,usart_rx_fifo_in,usart_rx_fifo_out); + } + break; + } + } + + if(!ble_sending) + { + // active send ble event after usart streaming cut + ke_timer_set(RDTSC_DATA_TX_CFM, TASK_APP, 10); + } + + return len; +} + +/** + * @brief usart send data via dma + */ +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len) +{ + DMA_InitType DMA_InitStructure; + + if(usart_sending) + { + return false; + } + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)p_data; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = len; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Tx_DMA_Channel, &DMA_InitStructure); + + usart_sending = true; + DMA_EnableChannel(USARTx_Tx_DMA_Channel, ENABLE); + + return true; +} + +/** + * @brief usart send data in blocking mode + */ +void usart_tx_data_blocking(uint8_t *p_data, uint16_t len) +{ + while(len--) + { + USART_SendData(USARTx, *p_data); + p_data++; + } +} + +/** + * @brief usart tx fifo enter and active dma send out + */ +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len, out_temp; + //store data in fifo + NS_LOG_DEBUG("%d,%d,%d\r\n",len,usart_tx_fifo_in,usart_tx_fifo_out); + out_temp = usart_tx_fifo_out; + while(len) + { + if(usart_tx_fifo_in >= out_temp ) + { + in_len = USART_TX_FIFO_SIZE-usart_tx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + } + else if(usart_tx_fifo_in < out_temp ) + { + in_len = out_temp-usart_tx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F_TX:%d,%d,%d\r\n",len,usart_tx_fifo_in,out_temp); + } + break; + } + } + + // ble treaming cut timer, active usart send after it. + ke_timer_set(APP_UART_TX_EVT, TASK_APP, 50); + + return len; +} + +/** + * @brief usart tx data from fifo + */ +void app_usart_tx_process(void) +{ + uint32_t in_temp,len; + uint8_t *p_data; + + in_temp = usart_tx_fifo_in; + if(usart_tx_fifo_out < in_temp) + { + len = in_temp-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = in_temp; + } + + } + else if(usart_tx_fifo_out > in_temp) + { + len = USART_TX_FIFO_SIZE-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = 0; + } + + } +} + + +/** + * @brief check the dma buffer which has been received + */ +void usart_rx_check_in_irq(void) +{ + uint16_t rx_pos; + + rx_pos = USART_RX_DMA_SIZE - DMA_GetCurrDataCounter(USARTx_Rx_DMA_Channel); + + NS_LOG_DEBUG("RX_POS = %x\r\n", rx_pos); + NS_LOG_DEBUG("RX_OLD_POS = %x\r\n", rx_old_pos); + + if(rx_pos < rx_old_pos) + { + + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(USART_RX_DMA_SIZE - rx_old_pos)); + + if(rx_pos > 0) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[0],rx_pos); + } + + rx_old_pos = rx_pos; + } + else if(rx_pos > rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(rx_pos - rx_old_pos)); + rx_old_pos = rx_pos; + } + else if(rx_pos != rx_old_pos) + { + //error + rx_old_pos = rx_pos; + } + +} + + +/** + * @brief dma irq handler + */ +void DMA_Channel1_2_3_4_IRQHandler(void) +{ + //TX + if(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)) + { + //TX Transfer complete interrupt + usart_sending = false; + ke_msg_send_basic(APP_UART_TX_EVT, TASK_APP, TASK_APP); + + DMA_ClearFlag(DMA_FLAG_TC1, DMA); + } + //RX + if(DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + //RX Transfer complete interrupt + DMA_ClearFlag(DMA_FLAG_TC2, DMA); + usart_rx_check_in_irq(); + + } + if(DMA_GetFlagStatus(DMA_FLAG_HT2, DMA)) + { + //RX Half transfer interrupt + DMA_ClearFlag(DMA_FLAG_HT2, DMA); + usart_rx_check_in_irq(); + } + + +} + +/** + * @brief usart irq handler + */ +void USARTx_IRQHandler(void) +{ + uint8_t temp; + //usart idlle interrupt + if(USART_GetFlagStatus(USARTx,USART_FLAG_IDLEF)) + { + //read sts and data will clear rx idle interrupt + temp = USARTx->DAT; + usart_rx_check_in_irq(); + (void)temp; + } + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/main.c new file mode 100644 index 0000000..871e80d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_16bit/src/main.c @@ -0,0 +1,150 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_ble.h" + + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\nRaw Data Transfer Client(16bit UUID) demo\r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + app_usart_dma_enable(ENABLE); + //init text + usart_tx_dma_send((uint8_t*)DEMO_STRING, sizeof(DEMO_STRING)); + + delay_n_10us(500); + //disable usart for enter sleep + app_usart_dma_enable(DISABLE); + + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/MDK-ARM/central_rdtsc.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/MDK-ARM/central_rdtsc.uvoptx new file mode 100644 index 0000000..06ed317 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/MDK-ARM/central_rdtsc.uvoptx @@ -0,0 +1,689 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + 4 + 17 + 4 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + n32wb03x_host_lib.lib + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils_128.c + prf_utils_128.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client.c + rdts_client.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_task.c + rdts_client_task.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 7 + 30 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtsc.c + app_rdtsc.c + 0 + 0 + + + 7 + 31 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 32 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 33 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + 8 + 34 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 9 + 35 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 36 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/MDK-ARM/central_rdtsc.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/MDK-ARM/central_rdtsc.uvprojx new file mode 100644 index 0000000..fdda83b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/MDK-ARM/central_rdtsc.uvprojx @@ -0,0 +1,692 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0x8000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtsc + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\rdtsc.bin .\Objects\rdtsc.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x8000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\custom;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\custom\custs\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15_central.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + n32wb03x_host_lib.lib + 4 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + prf_utils_128.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils_128.c + + + rdts_client.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client.c + + + rdts_client_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_rdtsc.c + 1 + ..\src\app_profile\app_rdtsc.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + app_usart.c + 1 + ..\src\app_usart.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_ble.h new file mode 100644 index 0000000..dc094fa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_UART_TX_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_profile/app_rdtsc.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_profile/app_rdtsc.h new file mode 100644 index 0000000..2c4eaae --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_profile/app_rdtsc.h @@ -0,0 +1,89 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSC_H_ +#define APP_RDTSC_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_CLIENT) + + +/// Table of message handlers +extern const struct app_subtask_handlers app_rdtsc_handlers; + +void app_rdtsc_init(void); +void app_rdtsc_add_rdts(void); +void app_rdtsc_enable_prf(uint8_t conidx); +void user_send_ble_data(const uint8_t *data, uint16_t length); + +#endif //BLE_RDTS_CLIENT + +/// @} APP + +#endif // APP_RDTSC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_usart.h new file mode 100644 index 0000000..2115114 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_usart.h @@ -0,0 +1,152 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTx_DAT_Base (USART1_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART1_RX +#define USARTx_IRQn USART1_IRQn +#define USARTx_IRQHandler USART1_IRQHandler +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define USARTx_DAT_Base (USART2_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#define USARTx_IRQn USART2_IRQn +#define USARTx_IRQHandler USART2_IRQHandler +#endif + + +#define USART_RX_DMA_SIZE 256 +#define USART_RX_FIFO_SIZE 1000 +#define USART_TX_FIFO_SIZE 1000 + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + +/* Public function prototypes -----------------------------------------------*/ + +void app_usart_configuration(void); +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len); +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len); +void app_usart_tx_data_blocking(uint8_t *p_data, uint16_t len); + +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len); +void usart_forward_to_ble_loop(void); +void app_usart_dma_enable(FunctionalState Cmd); +void app_usart_tx_process(void); +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_user_config.h new file mode 100644 index 0000000..651fd88 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/inc/app_user_config.h @@ -0,0 +1,117 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_RDTS_CLIENT" /** 3) +#error BLE_MASTER_CONN exceed APP_CON_IDX_MAX +#endif + +/* scan config */ +#define SCAN_PARAM_TYPE GAPM_SCAN_TYPE_OBSERVER /**< scan type (@enum gapm_scan_type) */ +#define SCAN_PARAM_PROP_ACTIVE 1 /**< if requre scan respond data. 1:active, 0:passive*/ +#define SCAN_PARAM_DUP_FILT_POL GAPM_DUP_FILT_DIS /**< (@enum gapm_dup_filter_pol) */ +#define SCAN_PARAM_INTV 160 /**< scan interval, unit:0.625ms */ +#define SCAN_PARAM_WD 150 /**< scan window, unit:0.625ms */ +#define SCAN_PARAM_DURATION 0 /**< scan duration, unit:10ms, 0 mean forever */ +#define SCAN_PARAM_CONNECT_EN true + +/* User config */ +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 1 +#define NS_TIMER_ENABLE 1 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/readme.txt new file mode 100644 index 0000000..0baf067 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/readme.txt @@ -0,0 +1,37 @@ + +1. Function description + + Bluetooth BLE data transmission service (rdts) master example, using 128bit UUID. + After connecting the slave device, the data received by Bluetooth will be transparently + transmitted to USART1, and the data received by USART1 will be transparently transmitted + to the slave device. + This example is allow connect up to 3 slave deivce(rdtss example). It needs to set the + active connection befor sending data. The first byte will be the connection to send if + it in 0x00 to 0x02 + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB1(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 4. BLE Data: USART1 PB6(TX) and PB7(RX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 5. LED1 lights up when it is turned on, LED2 indicates the connection status, and lights up when Bluetooth is connected + 6. The counter test routine is the rdtss slave routine in the ble directory + + usage method: + 1. Burn to development board after compilation + 2. Power on development board and check the log. + 3. Connect the salve device, and send data via USART1 each other. + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. + Press the RESET button to execute the program burning step within one second. diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_ble.c new file mode 100644 index 0000000..06b9a3c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_ble.c @@ -0,0 +1,353 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "ns_sec.h" +#include "app_rdtsc.h" +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_UART_TX_EVT: + app_usart_tx_process(); + break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_rdtsc_enable_prf(app_env.conidx); + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + case APP_BLE_GAP_PARAMS_IND: + // restart scan if not reach max connection + if (ns_ble_get_connection_num() < BLE_MASTER_CONN) + { + NS_LOG_INFO("restart scan\r\n"); + ns_ble_start_scan(); + } + break; + default: + break; + } + +} + +/** + * @brief scan data handler + * @param + * @return + * @note + */ +void app_ble_scan_data_handler(struct gapm_ext_adv_report_ind const* p_param) +{ +// NS_LOG_INFO("Found:%02x%02x%02x%02x%02x%02x, rssi:%d \r\n", +// p_param->trans_addr.addr.addr[0], +// p_param->trans_addr.addr.addr[1], +// p_param->trans_addr.addr.addr[2], +// p_param->trans_addr.addr.addr[3], +// p_param->trans_addr.addr.addr[4], +// p_param->trans_addr.addr.addr[5], +// p_param->rssi); + +} + +/** + * @brief scan state handler + * @param + * @return + * @note + */ +void app_ble_scan_state_handler(enum scan_state_t state) +{ + switch (state) + { + case SCAN_STATE_SCANING: + NS_LOG_INFO("Scaning.\r\n"); + break; + case SCAN_STATE_FOUND: + NS_LOG_INFO("Found target.\r\n"); + break; + case SCAN_STATE_CONN_TIMEOUT: + NS_LOG_INFO("Connect timeout.\r\n"); + break; + default: + break; + } +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x0C\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_ALL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble scan initialization + * @param + * @return + * @note + */ +void app_ble_scan_init(void) +{ + struct ns_scan_params_t init = {0}; +// static const uint8_t target_addr[] = {"\x11\x11\x11\x11\x11\x11"}; + static const uint8_t target_name[] = {"NS_RDTSS"}; +// static const uint16_t target_uuid16 = 0x180A; + + init.type = SCAN_PARAM_TYPE; + init.dup_filt_pol = SCAN_PARAM_DUP_FILT_POL; + init.connect_enable = SCAN_PARAM_CONNECT_EN; + init.prop_active_enable = SCAN_PARAM_PROP_ACTIVE; + init.scan_intv = SCAN_PARAM_INTV; + init.scan_wd = SCAN_PARAM_WD; + init.duration = SCAN_PARAM_DURATION; + init.initiating_timeout = 3000; + + init.filter_type = SCAN_FILTER_BY_NAME;//SCAN_FILTER_BY_ADDRESS; + init.filter_data = (uint8_t*)&target_name; + + init.ble_scan_data_handler = app_ble_scan_data_handler; + init.ble_scan_state_handler = app_ble_scan_state_handler; + + ns_ble_scan_init(&init); +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtsc_add_rdts); +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_scan_init(); + app_ble_prf_init(); + //start scan + ns_ble_start_scan(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + //enable usart receive + app_usart_dma_enable(ENABLE); + LedOn(LED2_PORT,LED2_PIN); + + #if (BLE_APP_BATT) + // Enable Battery Service + app_batt_enable_prf(app_env.conidx); + #endif //(BLE_APP_BATT) +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart scan + + if (ns_ble_get_connection_num() < BLE_MASTER_CONN) + { + ns_ble_start_scan(); + } + if (ns_ble_get_connection_num() == 0) + { + //disable usart receive + app_usart_dma_enable(DISABLE); + LedOff(LED2_PORT,LED2_PIN); + } +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_profile/app_rdtsc.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_profile/app_rdtsc.c new file mode 100644 index 0000000..2d22373 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_profile/app_rdtsc.c @@ -0,0 +1,285 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_CLIENT) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtsc.h" +#include "rdts_client_task.h" +#include "gapm_task.h" +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" +#include "stdio.h" +#include "ns_ble_task.h" +#include "app_usart.h" +#include "string.h" +#include "prf_utils_128.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define RDTS_SERVICE_UUID {0x01, 0x10, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_TX_UUID {0x02, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_RX_UUID {0x01, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} + +/* Private constants ---------------------------------------------------------*/ +const uint8_t rdtsc_uuid128[]= RDTS_SERVICE_UUID; +/// State machine used to retrieve RDTS characteristics information +const struct prf_char_def_128 rdtsc_char[RDTSC_CHAR_MAX] = +{ + [RDTSC_SRV_TX_DATA_CHAR] = {RDTS_SERVER_TX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_NTF}, + [RDTSC_SRV_RX_DATA_CHAR] = {RDTS_SERVER_RX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_WR_NO_RESP}, +}; +/// State machine used to retrieve RDTS service characteristic description information +const struct prf_char_desc_def rdtsc_desc[RDTSC_DESC_MAX] = +{ + ///RDTS Client Config + [RDTSC_SRV_TX_DATA_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, RDTSC_SRV_TX_DATA_CHAR}, +}; + +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +void app_rdtsc_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSC; + prf.prf_task_handler = &app_rdtsc_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSC; + get_func.prf_itf_get_func = rdtsc_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtsc_add_rdts(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtsc_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSC; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtsc_db_cfg *) req->param; + + // Attribute table. In case the handle offset needs to be saved + db_cfg->p_char = &rdtsc_char[0]; + db_cfg->p_desc = &rdtsc_desc[0]; + db_cfg->p_uuid128 = rdtsc_uuid128; + + // Send the message + ke_msg_send(req); + + app_rdtsc_init(); +} + + +void app_rdtsc_enable_prf(uint8_t conidx) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_enable_req * req = KE_MSG_ALLOC(RDTSC_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_RDTSC), + TASK_APP, + rdtsc_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + req->con_type = PRF_CON_DISCOVERY; + + // Send the message + ke_msg_send(req); +} + + +void user_send_ble_data(const uint8_t *data, uint16_t length) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_data_tx_req * req = KE_MSG_ALLOC_DYN(RDTSC_DATA_TX_REQ, + prf_get_task_from_id(TASK_ID_RDTSC), + TASK_APP, + rdtsc_data_tx_req, + length); +#if defined(BLE_MASTER_CONN) + req->cursor = ns_ble_get_active_connection(); +#endif + req->length = length; + memcpy(&req->data[0], data, length); + ke_msg_send(req); +} + + +/** + **************************************************************************************** + * @brief Handles client enable confirmation + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_enable_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_enable_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("RDTSC profile was enabled\r\n"); + + ns_ble_get_peer_info(GAPC_GET_PEER_FEATURES); +// ns_ble_active_rssi(500); + + return (KE_MSG_CONSUMED); +} + +/* + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_data_tx_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_data_tx_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + usart_forward_to_ble_loop(); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_data_rx_ind_handler(ke_msg_id_t const msgid, + struct rdtsc_data_rx_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("BLE Data was received\r\n"); + NS_LOG_DEBUG("length = %x\r\n", param->length); + NS_LOG_DEBUG("handle = %x\r\n", param->handle); + NS_LOG_DEBUG("type = %x\r\n", param->type); + NS_LOG_DEBUG("data "); + for(uint8_t i=0; ilength; i++) + { + NS_LOG_DEBUG(" %x", param->data[i]); + } + NS_LOG_DEBUG("\r\n"); + + app_usart_tx_fifo_enter(param->data,param->length); + + return (KE_MSG_CONSUMED); +} + +/// Default State handlers definition +const struct ke_msg_handler app_rdtsc_msg_handler_list[] = +{ + {RDTSC_ENABLE_CFM, (ke_msg_func_t)rdtsc_enable_cfm_handler}, + {RDTSC_DATA_TX_CFM, (ke_msg_func_t)rdtsc_data_tx_cfm_handler}, + {RDTSC_DATA_RX_IND, (ke_msg_func_t)rdtsc_data_rx_ind_handler}, +}; + +const struct app_subtask_handlers app_rdtsc_handlers = APP_HANDLERS(app_rdtsc); + + +#endif //BLE_RDTS_CLIENT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_usart.c new file mode 100644 index 0000000..86803a7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/app_usart.c @@ -0,0 +1,578 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include +#include "global_func.h" +#include "app_usart.h" +#include "app_rdtsc.h" +#include "ns_sleep.h" +#include "ns_log.h" +#include "ns_timer.h" +#include "ke_timer.h" +#include "app_ble.h" +#include "rdts_client_task.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] = {0}; +uint16_t rx_old_pos = 0; + +uint8_t usart_rx_fifo_buf[USART_RX_FIFO_SIZE] = {0}; +uint32_t usart_rx_fifo_in = 0; +uint32_t usart_rx_fifo_out = 0; + + +uint8_t usart_tx_fifo_buf[USART_TX_FIFO_SIZE] = {0}; +uint32_t usart_tx_fifo_in = 0; +uint32_t usart_tx_fifo_out = 0; + +uint8_t usart_sending = false; +uint8_t ble_sending = false; +uint16_t ble_att_mtu = (ATT_DEFAULT_MTU-3); + +/* Private function prototypes -----------------------------------------------*/ +void app_usart_tx_process(void); + +/* Private functions ---------------------------------------------------------*/ + + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTx_Tx_DMA_Channel); + DMA_RequestRemap(USARTx_Tx_DMA_REMAP, DMA, USARTx_Tx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Tx_DMA_Channel,DMA_INT_TXC ,ENABLE); + + /* USARTx RX DMA1 Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTx_Rx_DMA_Channel); + DMA_RequestRemap(USARTx_Rx_DMA_REMAP, DMA, USARTx_Rx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Rx_DMA_Channel,DMA_INT_TXC|DMA_INT_HTX ,ENABLE); + + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)USART_rx_dma_buf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = USART_RX_DMA_SIZE; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Rx_DMA_Channel, &DMA_InitStructure); + +} + + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + NVIC_DisableIRQ(DMA_Channel1_2_3_4_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + + NVIC_DisableIRQ(USARTx_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void app_usart_configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* Configure the DMA */ + DMA_Configuration(); + + NVIC_Configuration(); + + /* USARTx and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; //921600 + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTx, USART_INT_IDLEF, ENABLE); + + /* Enable USARTx DMA Rx and TX request */ + USART_EnableDMA(USARTx, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief enable or disable the usart dma + */ +void app_usart_dma_enable(FunctionalState Cmd) +{ + if(Cmd == ENABLE) + { + ns_sleep_lock_acquire(); + rx_old_pos = 0; + usart_tx_fifo_in = usart_tx_fifo_out = 0; //clean fifo + usart_rx_fifo_in = usart_rx_fifo_out = 0; //clean fifo + app_usart_configuration(); + } + else{ + ns_sleep_lock_release(); + USART_Enable(USARTx, DISABLE); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, DISABLE); + DMA_EnableChannel(USARTx_Tx_DMA_Channel, DISABLE); + /* Deinit IO of USART to save power */ + GPIO_InitType GPIO_InitStructure; + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + } +} + +/** + * @brief forward usart rx data too ble notify + */ +void usart_forward_to_ble_loop(void) +{ + NS_LOG_DEBUG("usart_rx_fifo_out = %x\r\n", usart_rx_fifo_out); + NS_LOG_DEBUG("usart_rx_fifo_in = %x\r\n", usart_rx_fifo_in); + + uint32_t in_temp; + uint16_t ble_send_len; + + in_temp = usart_rx_fifo_in; + if(usart_rx_fifo_out < in_temp) + { + ble_send_len = in_temp-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out > in_temp){ + ble_send_len = USART_RX_FIFO_SIZE-usart_rx_fifo_out; + } + else if(usart_rx_fifo_out == in_temp){ + // fifo empty, stop send loop + ble_sending = false; + return; + } + if ((app_env.max_mtu-3)> ble_att_mtu) + { + ble_att_mtu = (app_env.max_mtu-3); + } + if(ble_send_len > ble_att_mtu) + { + ble_send_len = ble_att_mtu; + } + ble_sending = true; + #if (BLE_RDTS_CLIENT) + NS_LOG_INFO("ble_send_len = %x\r\n", ble_send_len); + + if (usart_rx_fifo_buf[usart_rx_fifo_out] < 3) + { + ns_ble_set_active_connection(usart_rx_fifo_buf[usart_rx_fifo_out]); + } + user_send_ble_data(&usart_rx_fifo_buf[usart_rx_fifo_out], ble_send_len); + #endif + usart_rx_fifo_out = (usart_rx_fifo_out+ble_send_len)%USART_RX_FIFO_SIZE; + + return; +} + + +/** + * @brief usart rx data enter fifo and active ble send first package if not active yet + */ +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len; + //store data in fifo + while(len) + { + if(usart_rx_fifo_in >= usart_rx_fifo_out ) + { + in_len = USART_RX_FIFO_SIZE-usart_rx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + } + else if(usart_rx_fifo_in < usart_rx_fifo_out ) + { + in_len = usart_rx_fifo_out-usart_rx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_rx_fifo_buf[usart_rx_fifo_in],p_data,in_len); + len = len-in_len; + usart_rx_fifo_in = (usart_rx_fifo_in + in_len)%USART_RX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F_RX:%d,%d,%d\r\n",len,usart_rx_fifo_in,usart_rx_fifo_out); + } + break; + } + } + + if(!ble_sending) + { + // active send ble event after usart streaming cut + ke_timer_set(RDTSC_DATA_TX_CFM, TASK_APP, 10); + } + + return len; +} + +/** + * @brief usart send data via dma + */ +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len) +{ + DMA_InitType DMA_InitStructure; + + if(usart_sending) + { + return false; + } + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)p_data; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = len; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Tx_DMA_Channel, &DMA_InitStructure); + + usart_sending = true; + DMA_EnableChannel(USARTx_Tx_DMA_Channel, ENABLE); + + return true; +} + +/** + * @brief usart send data in blocking mode + */ +void usart_tx_data_blocking(uint8_t *p_data, uint16_t len) +{ + while(len--) + { + USART_SendData(USARTx, *p_data); + p_data++; + } +} + +/** + * @brief usart tx fifo enter and active dma send out + */ +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len, out_temp; + //store data in fifo + NS_LOG_DEBUG("%d,%d,%d\r\n",len,usart_tx_fifo_in,usart_tx_fifo_out); + out_temp = usart_tx_fifo_out; + while(len) + { + if(usart_tx_fifo_in >= out_temp ) + { + in_len = USART_TX_FIFO_SIZE-usart_tx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + } + else if(usart_tx_fifo_in < out_temp ) + { + in_len = out_temp-usart_tx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F_TX:%d,%d,%d\r\n",len,usart_tx_fifo_in,out_temp); + } + break; + } + } + + // ble treaming cut timer, active usart send after it. + ke_timer_set(APP_UART_TX_EVT, TASK_APP, 50); + + return len; +} + +/** + * @brief usart tx data from fifo + */ +void app_usart_tx_process(void) +{ + uint32_t in_temp,len; + uint8_t *p_data; + + in_temp = usart_tx_fifo_in; + if(usart_tx_fifo_out < in_temp) + { + len = in_temp-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = in_temp; + } + + } + else if(usart_tx_fifo_out > in_temp) + { + len = USART_TX_FIFO_SIZE-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = 0; + } + + } +} + + +/** + * @brief check the dma buffer which has been received + */ +void usart_rx_check_in_irq(void) +{ + uint16_t rx_pos; + + rx_pos = USART_RX_DMA_SIZE - DMA_GetCurrDataCounter(USARTx_Rx_DMA_Channel); + + NS_LOG_DEBUG("RX_POS = %x\r\n", rx_pos); + NS_LOG_DEBUG("RX_OLD_POS = %x\r\n", rx_old_pos); + + if(rx_pos < rx_old_pos) + { + + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(USART_RX_DMA_SIZE - rx_old_pos)); + + if(rx_pos > 0) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[0],rx_pos); + } + + rx_old_pos = rx_pos; + } + else if(rx_pos > rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(rx_pos - rx_old_pos)); + rx_old_pos = rx_pos; + } + else if(rx_pos != rx_old_pos) + { + //error + rx_old_pos = rx_pos; + } + +} + + +/** + * @brief dma irq handler + */ +void DMA_Channel1_2_3_4_IRQHandler(void) +{ + //TX + if(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)) + { + //TX Transfer complete interrupt + usart_sending = false; + ke_msg_send_basic(APP_UART_TX_EVT, TASK_APP, TASK_APP); + + DMA_ClearFlag(DMA_FLAG_TC1, DMA); + } + //RX + if(DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + //RX Transfer complete interrupt + DMA_ClearFlag(DMA_FLAG_TC2, DMA); + usart_rx_check_in_irq(); + + } + if(DMA_GetFlagStatus(DMA_FLAG_HT2, DMA)) + { + //RX Half transfer interrupt + DMA_ClearFlag(DMA_FLAG_HT2, DMA); + usart_rx_check_in_irq(); + } + + +} + +/** + * @brief usart irq handler + */ +void USARTx_IRQHandler(void) +{ + uint8_t temp; + //usart idlle interrupt + if(USART_GetFlagStatus(USARTx,USART_FLAG_IDLEF)) + { + //read sts and data will clear rx idle interrupt + temp = USARTx->DAT; + usart_rx_check_in_irq(); + (void)temp; + } +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/main.c new file mode 100644 index 0000000..290099e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_rdtsc_3m/src/main.c @@ -0,0 +1,150 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "rwip.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_usart.h" +#include "app_gpio.h" +#include "app_ble.h" + + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\nRaw Data Transfer Client(128bit UUID) demo\r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + LedOn(LED1_PORT,LED1_PIN); + app_usart_dma_enable(ENABLE); + //init text + usart_tx_dma_send((uint8_t*)DEMO_STRING, sizeof(DEMO_STRING)); + + delay_n_10us(500); + //disable usart for enter sleep + app_usart_dma_enable(DISABLE); + + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); +// ns_sleep(); + + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/MDK-ARM/central_relay.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/MDK-ARM/central_relay.uvoptx new file mode 100644 index 0000000..b22c97a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/MDK-ARM/central_relay.uvoptx @@ -0,0 +1,737 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO3 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + 4 + 17 + 4 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + n32wb03x_host_lib.lib + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils_128.c + prf_utils_128.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client.c + rdts_client.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_task.c + rdts_client_task.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + rdtss.c + 0 + 0 + + + 5 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + rdtss_task.c + 0 + 0 + + + 5 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + rdts_common.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 31 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + 6 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 7 + 33 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtsc.c + app_rdtsc.c + 0 + 0 + + + 7 + 34 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtss.c + app_rdtss.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 35 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 36 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + 8 + 37 + 1 + 0 + 0 + 0 + ..\src\app_fifo.c + app_fifo.c + 0 + 0 + + + 8 + 38 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 9 + 39 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 40 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/MDK-ARM/central_relay.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/MDK-ARM/central_relay.uvprojx new file mode 100644 index 0000000..10ce12f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/MDK-ARM/central_relay.uvprojx @@ -0,0 +1,712 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0x8000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtsc + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\rdtsc.bin .\Objects\rdtsc.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + -REMAP + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x8000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15_central.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + n32wb03x_host_lib.lib + 4 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + prf_utils_128.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils_128.c + + + rdts_client.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client.c + + + rdts_client_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + + + BLE_APP + + + app_rdtsc.c + 1 + ..\src\app_profile\app_rdtsc.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + app_fifo.c + 1 + ..\src\app_fifo.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_ble.h new file mode 100644 index 0000000..29526cc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_UART_TX_EVT, + APP_CUSTS_TEST_EVT, +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_fifo.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_fifo.h new file mode 100644 index 0000000..1e25b1f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_fifo.h @@ -0,0 +1,93 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_fifo.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define MASTER_RX_FIFO_SIZE 1000 + +/** + * @brief pop own master RX data, notify data to peer master + */ +void pop_matser_rx_to_ble(void); + +/** + * @brief push own master RX data to fifo and active ble send first package if + * not active yet + */ +uint8_t push_master_rx_data_to_fifo(const uint8_t *p_data, uint16_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_profile/app_rdtsc.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_profile/app_rdtsc.h new file mode 100644 index 0000000..3c8d211 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_profile/app_rdtsc.h @@ -0,0 +1,94 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSC_H_ +#define APP_RDTSC_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_CLIENT) + + +#define RDTS_SERVICE_UUID {0x01, 0x10, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_TX_UUID {0x02, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_RX_UUID {0x01, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} + + +/// Table of message handlers +extern const struct app_subtask_handlers app_rdtsc_handlers; + +void app_rdtsc_init(void); +void app_rdtsc_add_rdts(void); +void app_rdtsc_enable_prf(uint8_t conidx); +void user_send_ble_data(const uint8_t *data, uint16_t length); + +#endif //BLE_RDTS_CLIENT + +/// @} APP + +#endif // APP_RDTSC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_profile/app_rdtss.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_profile/app_rdtss.h new file mode 100644 index 0000000..da847fc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_profile/app_rdtss.h @@ -0,0 +1,153 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSS_H_ +#define APP_RDTSS_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/// Manufacturer Name Value +#define APP_RDTSS_MANUFACTURER_NAME ("NSING") +#define APP_RDTSS_MANUFACTURER_NAME_LEN (5) + + + +#define ATT_SERVICE_AM_SPEED_128 {0x01,0x10,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Service UUID */ +#define ATT_CHAR_AM_SPEED_WRITE_128 {0x01,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_NTF_128 {0x02,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_CNTL_POINT_128 {0x03,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_CMD_CMP_NTF_128 {0x04,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ + +/// rdtss Service Attributes Indexes +enum +{ + RDTSS_IDX_SVC, + + RDTSS_IDX_WRITE_CHAR, + RDTSS_IDX_WRITE_VAL, + RDTSS_IDX_WRITE_CFG, + + RDTSS_IDX_NTF_CHAR, + RDTSS_IDX_NTF_VAL, + RDTSS_IDX_NTF_CFG, + + RDTSS_IDX_CNTL_POINT_CHAR, + RDTSS_IDX_CNTL_POINT_VAL, + + RDTSS_IDX_CMD_CMP_NTF_CHAR, + RDTSS_IDX_CMD_CMP_NTF_VAL, + RDTSS_IDX_CMD_CMP_NTF_CFG, + + RDTSS_IDX_NB, +}; + +enum cntl_point_op_status +{ + STATUS_NO_ERR = 0, + STATUS_ERR_START_INIT_FAIL = 1, + STATUS_ERR_DISCONN_FAIL = 2, + STATUS_ERR_NOT_CONNECTED = 3, + STATUS_ERR_MASTER_HAS_CONNECTED = 4, + STATUS_ERR_MASTER_IS_CONNECTING = 5, +}; + +enum cntl_point_op +{ + CNTL_POINT_OP_CONN = 0x01, + CNTL_POINT_OP_DISCONN = 0x02, +}; + +enum upload_evt_op +{ + CNTL_POINT_CMD_CMP = 0x21, +}; +/// Table of message handlers +extern const struct app_subtask_handlers app_rdtss_handlers; + +/** + * @brief Initialize Device Information Service Application + **/ +void app_rdtss_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_rdtss_add_rdts(void); + +void rdtss_send_notify(uint8_t *data, uint16_t length); + +void rdtss_notify_ctrl_point_cmd_cmp(uint8_t cmd, uint8_t status, uint8_t *data, uint16_t length); + + +#endif //BLE_RDTSS_SERVER + +/// @} APP + +#endif // APP_RDTSS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_user_config.h new file mode 100644 index 0000000..85fdda0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/inc/app_user_config.h @@ -0,0 +1,142 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_RDTS_RELAY" /** +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "app_gpio.h" +#include "ns_sec.h" +#include "app_rdtsc.h" +#include "app_rdtss.h" +#include "app_user_config.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_rdtsc_enable_prf(app_env.conidx); + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief scan data handler + * @param + * @return + * @note + */ +void app_ble_scan_data_handler(struct gapm_ext_adv_report_ind const* p_param) +{ +// NS_LOG_INFO("Found:%02x%02x%02x%02x%02x%02x, rssi:%d \r\n", +// p_param->trans_addr.addr.addr[0], +// p_param->trans_addr.addr.addr[1], +// p_param->trans_addr.addr.addr[2], +// p_param->trans_addr.addr.addr[3], +// p_param->trans_addr.addr.addr[4], +// p_param->trans_addr.addr.addr[5], +// p_param->rssi); + +} + +/** + * @brief scan state handler + * @param + * @return + * @note + */ +void app_ble_scan_state_handler(enum scan_state_t state) +{ + switch (state) + { + case SCAN_STATE_SCANING: + NS_LOG_INFO("Scaning.\r\n"); + break; + case SCAN_STATE_FOUND: + NS_LOG_INFO("Found target.\r\n"); + break; + case SCAN_STATE_CONN_TIMEOUT: + NS_LOG_INFO("Connect timeout.\r\n"); + break; + default: + break; + } +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + if(ns_ble_master_connection_num()==0 && + scan_env.scan_enable == false ) + { + ns_ble_start_scan(); + } + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = NULL;//SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x0C\x0D\x06" , BD_ADDR_LEN); + } + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_ALL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +/** + * @brief ble scan initialization + * @param + * @return + * @note + */ +void app_ble_scan_init(void) +{ + struct ns_scan_params_t init = {0}; + static const uint8_t target_name[] = {"NS_RDTSS"}; + + init.type = SCAN_PARAM_TYPE; + init.dup_filt_pol = SCAN_PARAM_DUP_FILT_POL; + init.connect_enable = SCAN_PARAM_CONNECT_EN; + init.prop_active_enable = SCAN_PARAM_PROP_ACTIVE; + init.scan_intv = SCAN_PARAM_INTV; + init.scan_wd = SCAN_PARAM_WD; + init.duration = SCAN_PARAM_DURATION; + init.initiating_timeout = 3000; + + init.filter_type = SCAN_FILTER_BY_NAME; + init.filter_data = (uint8_t*)&target_name; + + init.ble_scan_data_handler = app_ble_scan_data_handler; + init.ble_scan_state_handler = app_ble_scan_state_handler; + + ns_ble_scan_init(&init); +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtss_add_rdts); + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtsc_add_rdts); +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_scan_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); + +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + if(ns_ble_slave_connection_num()) + { + LedOn(LED2_PORT,LED2_PIN); + } + + if(ns_ble_master_connection_num()) + { + LedOn(LED1_PORT,LED1_PIN); + } +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart adv/scan + if (ns_ble_slave_connection_num() == 0) + { + ns_ble_adv_start(); + LedOff(LED2_PORT,LED2_PIN); + } + if (ns_ble_master_connection_num()==0) + { + LedOff(LED1_PORT,LED1_PIN); + if (scan_env.scan_enable == false) + { + ns_ble_start_scan(); + } + } + +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_fifo.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_fifo.c new file mode 100644 index 0000000..eb73761 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_fifo.c @@ -0,0 +1,172 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_fifo.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_fifo.h" +#include "app_rdtss.h" +#include "rwprf_config.h" +#include "string.h" +#include "ke_timer.h" +#include "rdtss_task.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +uint8_t master_rx_fifo_buf[MASTER_RX_FIFO_SIZE] = {0}; +uint32_t master_rx_fifo_in = 0; +uint32_t master_rx_fifo_out = 0; +bool sending_to_master; +uint16_t num_send_to_peer_master = 20; //MTU-3 + +/** + * @brief pop own master RX data, send data to peer master + */ +void pop_matser_rx_to_ble(void) +{ + uint32_t in_temp; + uint16_t ble_send_len; + + in_temp = master_rx_fifo_in; + if(master_rx_fifo_out < in_temp) + { + ble_send_len = in_temp-master_rx_fifo_out; + } + else if(master_rx_fifo_out > in_temp){ + ble_send_len = MASTER_RX_FIFO_SIZE-master_rx_fifo_out; + } + else if(master_rx_fifo_out == in_temp){ + // fifo empty, stop send loop + sending_to_master = false; + return; + } + if(ble_send_len > num_send_to_peer_master) + { + ble_send_len = num_send_to_peer_master; + } + sending_to_master = true; + #if (BLE_RDTSS_SERVER) + rdtss_send_notify( &master_rx_fifo_buf[master_rx_fifo_out], ble_send_len); + #endif + master_rx_fifo_out = (master_rx_fifo_out+ble_send_len)%MASTER_RX_FIFO_SIZE; + + return; +} + +/** + * @brief push master RX data to fifo and active ble send first package if not active yet + */ +uint8_t push_master_rx_data_to_fifo(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len; + //store data in fifo + while(len) + { + if(master_rx_fifo_in >= master_rx_fifo_out ) + { + in_len = MASTER_RX_FIFO_SIZE-master_rx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&master_rx_fifo_buf[master_rx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + master_rx_fifo_in = (master_rx_fifo_in + in_len)%MASTER_RX_FIFO_SIZE; + + } + else if(master_rx_fifo_in < master_rx_fifo_out ) + { + in_len = master_rx_fifo_out-master_rx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&master_rx_fifo_buf[master_rx_fifo_in],p_data,in_len); + len = len-in_len; + master_rx_fifo_in = (master_rx_fifo_in + in_len)%MASTER_RX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,master_rx_fifo_in,master_rx_fifo_out); + } + break; + } + } + + if(master_rx_fifo_in != master_rx_fifo_out) //data need to send + { + if(!sending_to_master) + { + ke_timer_set(RDTSS_VAL_NTF_CFM, TASK_APP, 10); + } + } + + return len; +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_profile/app_rdtsc.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_profile/app_rdtsc.c new file mode 100644 index 0000000..77767b6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_profile/app_rdtsc.c @@ -0,0 +1,290 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_CLIENT) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtsc.h" +#include "rdts_client_task.h" +#include "gapm_task.h" +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" +#include "stdio.h" +#include "ns_ble_task.h" +#include "app_fifo.h" +#include "string.h" +#include "prf_utils_128.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define RDTS_SERVICE_UUID {0x01, 0x10, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_TX_UUID {0x02, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_RX_UUID {0x01, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} + +/* Private constants ---------------------------------------------------------*/ +const uint8_t rdtsc_uuid128[]= RDTS_SERVICE_UUID; +/// State machine used to retrieve RDTS characteristics information +const struct prf_char_def_128 rdtsc_char[RDTSC_CHAR_MAX] = +{ + [RDTSC_SRV_TX_DATA_CHAR] = {RDTS_SERVER_TX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_NTF}, + [RDTSC_SRV_RX_DATA_CHAR] = {RDTS_SERVER_RX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_WR_NO_RESP}, +}; +/// State machine used to retrieve RDTS service characteristic description information +const struct prf_char_desc_def rdtsc_desc[RDTSC_DESC_MAX] = +{ + ///RDTS Client Config + [RDTSC_SRV_TX_DATA_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, RDTSC_SRV_TX_DATA_CHAR}, +}; + +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +void app_rdtsc_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSC; + prf.prf_task_handler = &app_rdtsc_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSC; + get_func.prf_itf_get_func = rdtsc_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtsc_add_rdts(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtsc_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSC; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtsc_db_cfg *) req->param; + + // Attribute table. In case the handle offset needs to be saved + db_cfg->p_char = &rdtsc_char[0]; + db_cfg->p_desc = &rdtsc_desc[0]; + db_cfg->p_uuid128 = rdtsc_uuid128; + + // Send the message + ke_msg_send(req); + + app_rdtsc_init(); +} + + +void app_rdtsc_enable_prf(uint8_t conidx) +{ + NS_LOG_DEBUG("%s %x\r\n", __func__, conidx); + struct rdtsc_enable_req * req = KE_MSG_ALLOC(RDTSC_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_RDTSC), + TASK_APP, + rdtsc_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + req->con_type = PRF_CON_DISCOVERY; + + // Send the message + ke_msg_send(req); +} + + +void user_send_ble_data(const uint8_t *data, uint16_t length) +{ + NS_LOG_INFO("%s\r\n", __func__); + + if(ns_ble_master_connection_num()) + { + + struct rdtsc_data_tx_req * req = KE_MSG_ALLOC_DYN(RDTSC_DATA_TX_REQ, + prf_get_task_from_id(TASK_ID_RDTSC), + TASK_APP, + rdtsc_data_tx_req, + length); + + req->cursor = ns_ble_get_conidx_by_role(ROLE_MASTER); + req->length = length; + memcpy(&req->data[0], data, length); + ke_msg_send(req); + } + else + { + NS_LOG_INFO("Connect error with peripheral device\r\n"); + } +} + +/** + **************************************************************************************** + * @brief Handles client enable confirmation + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_enable_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_enable_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("RDTSC profile was enabled = %x\r\n", param->status); + + ns_ble_get_peer_info(GAPC_GET_PEER_FEATURES); + + return (KE_MSG_CONSUMED); +} + +/* + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_data_tx_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_data_tx_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_INFO("%s\r\n", __func__); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_data_rx_ind_handler(ke_msg_id_t const msgid, + struct rdtsc_data_rx_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_DEBUG("Data from connected peripheral\r\n"); + NS_LOG_DEBUG("length = %x\r\n", param->length); + NS_LOG_DEBUG("handle = %x\r\n", param->handle); + NS_LOG_DEBUG("type = %x\r\n", param->type); + NS_LOG_DEBUG("data "); + for(uint8_t i=0; ilength; i++) + { + NS_LOG_DEBUG(" %x", param->data[i]); + } + NS_LOG_DEBUG("\r\n"); + + push_master_rx_data_to_fifo((uint8_t *)(param->data), param->length); + + return (KE_MSG_CONSUMED); +} + +/// Default State handlers definition +const struct ke_msg_handler app_rdtsc_msg_handler_list[] = +{ + {RDTSC_ENABLE_CFM, (ke_msg_func_t)rdtsc_enable_cfm_handler}, + {RDTSC_DATA_TX_CFM, (ke_msg_func_t)rdtsc_data_tx_cfm_handler}, + {RDTSC_DATA_RX_IND, (ke_msg_func_t)rdtsc_data_rx_ind_handler}, +}; + +const struct app_subtask_handlers app_rdtsc_handlers = APP_HANDLERS(app_rdtsc); + + +#endif //BLE_RDTS_CLIENT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_profile/app_rdtss.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_profile/app_rdtss.c new file mode 100644 index 0000000..817daec --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/app_profile/app_rdtss.c @@ -0,0 +1,430 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtss.h" // rdtss Application Module Definitions +#include "rdtss_task.h" // Device Information Profile Functions +#include "gapm_task.h" // GAP Manager Task API +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" + +#include "stdio.h" +#include "rdtss.h" +#include "app_fifo.h" +#include "app_rdtsc.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +const uint8_t app_rdts_svc_uuid[16] = ATT_SERVICE_AM_SPEED_128; +const struct attm_desc_128 app_rdts_att_db[RDTSS_IDX_NB] = +{ + /* Service Declaration */ + [0] = {{0x00,0x28}, PERM(RD, ENABLE), 0, 0 }, + + /* Characteristic Declaration */ + [1] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [2] = {ATT_CHAR_AM_SPEED_WRITE_128, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [3] = {{0x01,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + /* Characteristic Declaration */ + [4] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [5] = {ATT_CHAR_AM_SPEED_NTF_128, PERM(NTF, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [6] = {{0x02,0x29}, PERM(RD, ENABLE) |PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + /* Characteristic Declaration */ + [7] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [8] = {ATT_CHAR_AM_SPEED_CNTL_POINT_128, PERM(WRITE_COMMAND, ENABLE), PERM_VAL(UUID_LEN, 0x02), 20 }, + + /* Characteristic Declaration */ + [9] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [10] = {ATT_CHAR_AM_SPEED_CMD_CMP_NTF_128, PERM(NTF, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [11] = {{0x02,0x29}, PERM(RD, ENABLE) |PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + +}; + + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtss_add_rdts(void) +{ + struct rdtss_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtss_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtss_db_cfg *) req->param; + // Attribute table. In case the handle offset needs to be saved + db_cfg->att_tbl = &app_rdts_att_db[0]; + db_cfg->svc_uuid = &app_rdts_svc_uuid[0]; + db_cfg->max_nb_att = RDTSS_IDX_NB; + + // Send the message + ke_msg_send(req); + + app_rdtss_init(); +} + +/** + * @brief rdtss value require indicate handler + * @param + * @return + * @note Note + */ +static int rdtss_value_req_ind_handler(ke_msg_id_t const msgid, + struct rdtss_value_req_ind const *req_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + len = APP_RDTSS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_RDTSS_MANUFACTURER_NAME; + + + // Allocate confirmation to send the value + struct rdtss_value_req_rsp *rsp_value = KE_MSG_ALLOC_DYN(RDTSS_VALUE_REQ_RSP, + src_id, dest_id, + rdtss_value_req_rsp, + len); + rsp_value->status = 0; + rsp_value->conidx = req_value ->conidx; + rsp_value->length = len; + rsp_value->att_idx = req_value->att_idx; + if (len) + { + // Copy data + memcpy(&rsp_value->value, data, len); + } + // Send message + ke_msg_send(rsp_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief cuusts write indicate handler + * @param + * @return + * @note + */ +static int rdtss_val_write_ind_handler(ke_msg_id_t const msgid, + struct rdtss_val_write_ind const *ind_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,write handle = %x,length = %x\r\n",__func__ ,ind_value->handle, ind_value->length); + + for(uint16_t i=0; ilength; i++) + { + NS_LOG_DEBUG("%x ",ind_value->value[i]); + } + NS_LOG_DEBUG("\r\n"); + + uint16_t handle = ind_value->handle; + uint16_t length = ind_value->length; + uint16_t conidx_m = ns_ble_get_conidx_by_role(ROLE_MASTER); + + switch (handle) + { + case RDTSS_IDX_NTF_CFG: + + if(length == 2) + { + uint16_t cfg_value = ind_value->value[0] + ind_value->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + //enabled notify + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + } + } + + break; + case RDTSS_IDX_WRITE_VAL: + //ble data receive + NS_LOG_INFO("Data from connected central\r\n"); + user_send_ble_data(ind_value->value,ind_value->length); + break; + + case RDTSS_IDX_CNTL_POINT_VAL: + { + + switch(ind_value->value[0]) + { + case CNTL_POINT_OP_CONN: + { + //data strructure: || addr_type || addr || + // || 1B || 6B || + + uint8_t i; + + //check addr type + if(ind_value->value[1] > 1) + { + NS_LOG_INFO("ADDR type error: %x\r\n", ind_value->value[1]); + } + else + { + if(conidx_m != GAP_INVALID_CONIDX) + { + NS_LOG_INFO("Master connetion has been established\r\n"); + rdtss_notify_ctrl_point_cmd_cmp(CNTL_POINT_OP_CONN, STATUS_ERR_MASTER_HAS_CONNECTED, NULL, 0); + } + else + { + NS_LOG_INFO("Start connecting peripheral, index: %x\r\n", i); + NS_LOG_INFO("Target ADDR: "); + for(uint8_t k=0; k<6; k++) + { + NS_LOG_INFO(" %x ", ind_value->value[k+2]); + } + NS_LOG_INFO("\r\n"); + + ns_ble_stop_scan(); + NS_LOG_INFO("Stop SCAN\r\n"); + + ns_ble_start_init((uint8_t *)&(ind_value->value[2]), ind_value->value[1]); + } + } + + }break; + + case CNTL_POINT_OP_DISCONN: + { + NS_LOG_INFO("IDX = %x \r\n", conidx_m); + + if(conidx_m != GAP_INVALID_CONIDX) + { + ns_ble_set_active_connection(conidx_m); + ns_ble_disconnect(); + } + else + { + rdtss_notify_ctrl_point_cmd_cmp(CNTL_POINT_OP_DISCONN, STATUS_ERR_NOT_CONNECTED, NULL, 0); + } + }break; + + default:break; + } + } + break; + + default: + break; + + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Functions + * @param + * @return + * @note Note + */ +static int rdtss_val_ntf_cfm_handler(ke_msg_id_t const msgid, + struct rdtss_val_ntf_cfm const *cfm_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,ntf cfm handle = %x, status = %x\r\n",__func__, cfm_value->handle, cfm_value->status); + + pop_matser_rx_to_ble(); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief rdtss send notify + * @param + * @return + * @note + */ +void rdtss_send_notify(uint8_t *data, uint16_t length) +{ + if(ns_ble_slave_connection_num()) + { + struct rdtss_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(RDTSS_VAL_NTF_REQ, + prf_get_task_from_id(TASK_ID_RDTSS), + TASK_APP, + rdtss_val_ntf_ind_req, + length); + + req->conidx = ns_ble_get_conidx_by_role(ROLE_SLAVE); + req->notification = true; + req->handle = RDTSS_IDX_NTF_VAL; + req->length = length; + memcpy(&req->value[0], data, length); + + NS_LOG_DEBUG("%x", req->value[0]); + + ke_msg_send(req); + } + else + { + NS_LOG_INFO("Not connected with central device\r\n"); + } +} + +void rdtss_notify_ctrl_point_cmd_cmp(uint8_t cmd, uint8_t status, uint8_t *data, uint16_t length) +{ + if(ns_ble_slave_connection_num()) + { + struct rdtss_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(RDTSS_VAL_NTF_REQ, + prf_get_task_from_id(TASK_ID_RDTSS), + TASK_APP, + rdtss_val_ntf_ind_req, + length + 4); + + req->conidx = ns_ble_get_conidx_by_role(ROLE_SLAVE); + req->notification = true; + req->handle = RDTSS_IDX_CMD_CMP_NTF_VAL; + + req->length = length + 4; + + req->value[0] = CNTL_POINT_CMD_CMP; + req->value[1] = cmd; + req->value[2] = status; + req->value[3] = length; + + if(data != NULL) + { + memcpy(&req->value[4], data, length); + } + + ke_msg_send(req); + } + else + { + NS_LOG_INFO("Not connected with central device\r\n"); + } +} + +/// Default State handlers definition +const struct ke_msg_handler app_rdtss_msg_handler_list[] = +{ + {RDTSS_VALUE_REQ_IND, (ke_msg_func_t)rdtss_value_req_ind_handler}, + {RDTSS_VAL_WRITE_IND, (ke_msg_func_t)rdtss_val_write_ind_handler}, + {RDTSS_VAL_NTF_CFM, (ke_msg_func_t)rdtss_val_ntf_cfm_handler}, + +}; + +const struct app_subtask_handlers app_rdtss_handlers = APP_HANDLERS(app_rdtss); + + +void app_rdtss_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSS; + prf.prf_task_handler = &app_rdtss_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSS; + get_func.prf_itf_get_func = rdtss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +#endif //BLE_RDTSS_SERVER diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/main.c new file mode 100644 index 0000000..7d9c867 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m1s/src/main.c @@ -0,0 +1,138 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_gpio.h" +#include "app_ble.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING1 "\r\nRaw Data Transfer RELAY demo\r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING1); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + + //init text + delay_n_10us(500); + //disable usart for enter sleep + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/MDK-ARM/central_relay.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/MDK-ARM/central_relay.uvoptx new file mode 100644 index 0000000..ce06522 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/MDK-ARM/central_relay.uvoptx @@ -0,0 +1,737 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO3 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + 4 + 17 + 4 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + n32wb03x_host_lib.lib + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils_128.c + prf_utils_128.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client.c + rdts_client.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_task.c + rdts_client_task.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + rdtss.c + 0 + 0 + + + 5 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + rdtss_task.c + 0 + 0 + + + 5 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + rdts_common.c + 0 + 0 + + + + + NS_LIB + 1 + 0 + 0 + 0 + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 6 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 31 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + 6 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + + + BLE_APP + 1 + 0 + 0 + 0 + + 7 + 33 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtsc.c + app_rdtsc.c + 0 + 0 + + + 7 + 34 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_rdtss.c + app_rdtss.c + 0 + 0 + + + + + USER + 1 + 0 + 0 + 0 + + 8 + 35 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 8 + 36 + 1 + 0 + 0 + 0 + ..\src\app_gpio.c + app_gpio.c + 0 + 0 + + + 8 + 37 + 1 + 0 + 0 + 0 + ..\src\app_fifo.c + app_fifo.c + 0 + 0 + + + 8 + 38 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + CONFIG + 1 + 0 + 0 + 0 + + 9 + 39 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 40 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/MDK-ARM/central_relay.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/MDK-ARM/central_relay.uvprojx new file mode 100644 index 0000000..3b36c29 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/MDK-ARM/central_relay.uvprojx @@ -0,0 +1,711 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0x8000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + rdtsc + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\rdtsc.bin .\Objects\rdtsc.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + -REMAP + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x8000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 3 + 0 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\bas\bass\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hrp\hrps\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\inc\rw;..\inc\app_profile;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15_central.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + n32wb03x_host_lib.lib + 4 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\host_lib\n32wb03x_host_lib.lib + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + prf_utils_128.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils_128.c + + + rdts_client.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client.c + + + rdts_client_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtsc\src\rdts_client_task.c + + + rdtss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss.c + + + rdtss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\src\rdtss_task.c + + + rdts_common.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdts_common.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + + + BLE_APP + + + app_rdtsc.c + 1 + ..\src\app_profile\app_rdtsc.c + + + app_rdtss.c + 1 + ..\src\app_profile\app_rdtss.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + app_gpio.c + 1 + ..\src\app_gpio.c + + + app_fifo.c + 1 + ..\src\app_fifo.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_ble.h new file mode 100644 index 0000000..29526cc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_UART_TX_EVT, + APP_CUSTS_TEST_EVT, +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_fifo.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_fifo.h new file mode 100644 index 0000000..1e25b1f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_fifo.h @@ -0,0 +1,93 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_fifo.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define MASTER_RX_FIFO_SIZE 1000 + +/** + * @brief pop own master RX data, notify data to peer master + */ +void pop_matser_rx_to_ble(void); + +/** + * @brief push own master RX data to fifo and active ble send first package if + * not active yet + */ +uint8_t push_master_rx_data_to_fifo(const uint8_t *p_data, uint16_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_gpio.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_gpio.h new file mode 100644 index 0000000..8a1ae55 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_gpio.h @@ -0,0 +1,91 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_GPIO_H__ +#define __APP_GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_GPIO_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_profile/app_rdtsc.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_profile/app_rdtsc.h new file mode 100644 index 0000000..3c8d211 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_profile/app_rdtsc.h @@ -0,0 +1,94 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSC_H_ +#define APP_RDTSC_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_CLIENT) + + +#define RDTS_SERVICE_UUID {0x01, 0x10, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_TX_UUID {0x02, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_RX_UUID {0x01, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} + + +/// Table of message handlers +extern const struct app_subtask_handlers app_rdtsc_handlers; + +void app_rdtsc_init(void); +void app_rdtsc_add_rdts(void); +void app_rdtsc_enable_prf(uint8_t conidx); +void user_send_ble_data(const uint8_t *data, uint16_t length); + +#endif //BLE_RDTS_CLIENT + +/// @} APP + +#endif // APP_RDTSC_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_profile/app_rdtss.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_profile/app_rdtss.h new file mode 100644 index 0000000..da847fc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_profile/app_rdtss.h @@ -0,0 +1,153 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_RDTSS_H_ +#define APP_RDTSS_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Battery Application Module entry point + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/// Manufacturer Name Value +#define APP_RDTSS_MANUFACTURER_NAME ("NSING") +#define APP_RDTSS_MANUFACTURER_NAME_LEN (5) + + + +#define ATT_SERVICE_AM_SPEED_128 {0x01,0x10,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Service UUID */ +#define ATT_CHAR_AM_SPEED_WRITE_128 {0x01,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_NTF_128 {0x02,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_CNTL_POINT_128 {0x03,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ +#define ATT_CHAR_AM_SPEED_CMD_CMP_NTF_128 {0x04,0x00,0x2E,0xC7,0x8a,0x0E, 0x73,0x90, 0xE1,0x11, 0xC2,0x08, 0x60,0x27,0x00,0x00} /*!< Characteristic value UUID */ + +/// rdtss Service Attributes Indexes +enum +{ + RDTSS_IDX_SVC, + + RDTSS_IDX_WRITE_CHAR, + RDTSS_IDX_WRITE_VAL, + RDTSS_IDX_WRITE_CFG, + + RDTSS_IDX_NTF_CHAR, + RDTSS_IDX_NTF_VAL, + RDTSS_IDX_NTF_CFG, + + RDTSS_IDX_CNTL_POINT_CHAR, + RDTSS_IDX_CNTL_POINT_VAL, + + RDTSS_IDX_CMD_CMP_NTF_CHAR, + RDTSS_IDX_CMD_CMP_NTF_VAL, + RDTSS_IDX_CMD_CMP_NTF_CFG, + + RDTSS_IDX_NB, +}; + +enum cntl_point_op_status +{ + STATUS_NO_ERR = 0, + STATUS_ERR_START_INIT_FAIL = 1, + STATUS_ERR_DISCONN_FAIL = 2, + STATUS_ERR_NOT_CONNECTED = 3, + STATUS_ERR_MASTER_HAS_CONNECTED = 4, + STATUS_ERR_MASTER_IS_CONNECTING = 5, +}; + +enum cntl_point_op +{ + CNTL_POINT_OP_CONN = 0x01, + CNTL_POINT_OP_DISCONN = 0x02, +}; + +enum upload_evt_op +{ + CNTL_POINT_CMD_CMP = 0x21, +}; +/// Table of message handlers +extern const struct app_subtask_handlers app_rdtss_handlers; + +/** + * @brief Initialize Device Information Service Application + **/ +void app_rdtss_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_rdtss_add_rdts(void); + +void rdtss_send_notify(uint8_t *data, uint16_t length); + +void rdtss_notify_ctrl_point_cmd_cmp(uint8_t cmd, uint8_t status, uint8_t *data, uint16_t length); + + +#endif //BLE_RDTSS_SERVER + +/// @} APP + +#endif // APP_RDTSS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..0320ae9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_profile/rwapp_config.h @@ -0,0 +1,131 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_user_config.h new file mode 100644 index 0000000..e26b5dd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/inc/app_user_config.h @@ -0,0 +1,147 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NS_RDTS_RELAY" /** 3) +#error BLE_SLAVE_CONN exceed APP_CON_IDX_MAX +#endif + +/* scan config */ +#define SCAN_PARAM_TYPE GAPM_SCAN_TYPE_OBSERVER /**< scan type (@enum gapm_scan_type) */ +#define SCAN_PARAM_PROP_ACTIVE 1 /**< if requre scan respond data. 1:active, 0:passive*/ +#define SCAN_PARAM_DUP_FILT_POL GAPM_DUP_FILT_DIS /**< (@enum gapm_dup_filter_pol) */ +#define SCAN_PARAM_INTV 160 /**< scan interval, unit:0.625ms */ +#define SCAN_PARAM_WD 150 /**< scan window, unit:0.625ms */ +#define SCAN_PARAM_DURATION 0 /**< scan duration, unit:10ms, 0 mean forever */ +#define SCAN_PARAM_CONNECT_EN true + +/* User config */ +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 1 +#define NS_TIMER_ENABLE 1 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/readme.txt new file mode 100644 index 0000000..4f92cd0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/readme.txt @@ -0,0 +1,90 @@ + +1. Function description + Bluetooth BLE realy example With 128bit UUID, the relay device can be connected to one master and + two slave at the same time. After establishment, the received slave data can be sent to the master, + received master data can be sent to the slave. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + System configuration; + 1. Clock source: HSI=64M + 2. LED1/LED2 indicates the connection status, and lights up when Bluetooth is connected. + + Test steps: + 1. Prepare two N32WB031_STB Development board and a mobile phone. + 2. Connect SWD and USART1 on development board J10. + 3. Connect development boards J7 and J8 to supply power to MCU and NS Link. + 4. Download a master slave relay routine to one development board (relay development board). + The project path is: ble_central\central_relay_1m2s\MDK-ARM\central_relay.uvprojx. + + The following "5" or "6" methods can be used to establish the connection between the master + and slave at the same time: + +5. Download slave routines to another development board (slave development board). + Project path: \ble\rdtss\MDK-ARM\rdtss.uvprojx. The slave device ble name is "NS_RDTSS". + Use the default Bluetooth MAC address: " x0C x02 x03 x04 x05 x06". + + 5.1 After the two development boards are powered on, the relay development board automatically + connects to the slave development board. When the relay development board LED1 lights up, it + indicates that the connection with the slave is successful. + 5.2 Use APP to scan BLE devices and connect devices "NS_RDTS_RELAY ", when the relay development + board LED2 lights up, it indicates that the connection with the host is successful. + +6. Download slave routines to another development board (slave development board). Project path: + N32WB03x_SDK\projects\n32wb03x_EVAL\ble\rdtss\MDK-ARM\rdtss.uvprojx. + Use the default Bluetooth MAC address: "x0C x02 x03 x04 x05 x07", change the ble name is not same as "NS_RDTSS". + 6.1 Use APP to scan BLE devices and connect devices "NS_RDTS_RELAY ", when the relay development board + LED2 lights up, it indicates that the connection with the host is successful. + 6.2 Use the APP to scan the BLE device to ensure that the device with the address + of "x0C x02 x03 x04 x05 x07" can be scanned. + 6.3 Enable NS_RDTSS Notify permission of the second notify feature of RELAY on mobile. + 6.4 On the mobile phone APP, turn to NS_RDTS_Write data in the second write feature of RELAY: 01000C0203040507 + 6.5 When the relay development board LED1 lights up, it indicates that the connection with the slave is successful. + + 7. Enable NS_RDTSS Notify permission of the first notify feature of RELAY on mobile APP. + 8. Send data to the first write feature of the relay development board through the mobile phone APP, + and the corresponding data can be received at the serial port of the slave development board. + 9. After sending data to the slave development board through the serial port, the first notify feature + of the phone can receive the data. + +4. Process description: + After the relay device is powered on, the device is scanning and broadcasting at the same time. + When the relay is connected to the 2 master devices, the broadcast stops; When the relay is disconnected + from the master device, the broadcast starts. + When the relay is connected to the peer slave device, the scanning stops; When the relay is disconnected + from the peer slave device, the scan starts. + +5. Description of relay as a slave profile + Service: 0x01102EC78a0E7390E111C20860270000 + RDTSS_ RX: 0x01002EC78a0E7390E111C20860270000(Write) mobile phone send data to this UUID will be relayed + to the slave device connected to the relay device + RDTSS_ TX: 0x02002EC78a0E7390E111C20860270000(NTF) After the slave device connected to the relay device + sends the notify data, the data is relayed to the mobile phone through this feature + Control_ Point: 0x03002EC78a0E7390E111C20860270000(Write) The mobile phone can send control commands to relay + through this feature (for example, connect the slave at a specific address and disconnect the slave) + Command_ Complete: 0x04002EC78a0E7390E111C20860270000(NTF) Mobile phone returns Command completion status, + when the relay is connected/disconnected from the slave, report the status to the mobile phone. + +6�Control_ Point Command + Command data structure: + value[0] = cmd; + value[1...] = data; + Cmd=01 Connect slave + Example of a complete command: 01000C0203040507 + 01: Connect slave + 00: Slave address type: Public + 0C0203040507: Slave address + Cmd=02 Disconnect from slave + Example of a complete command: 02 + 02: Disconnect the slave + +7�Command_ Complete event + Event data structure: + value[0] = CNTL_ POINT_ CMD_ CMP; + value[1] = cmd; + value[2] = status; + value[3] = length; + value[4...] = data; diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_ble.c new file mode 100644 index 0000000..7887452 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_ble.c @@ -0,0 +1,429 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "app_ble.h" +#include "app_gpio.h" +#include "ns_sec.h" +#include "app_rdtsc.h" +#include "app_rdtss.h" +#include "app_user_config.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + if(app_env.conn_env[app_env.conidx].role == ROLE_MASTER) + { + app_rdtsc_enable_prf(app_env.conidx); + } + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief scan data handler + * @param + * @return + * @note + */ +void app_ble_scan_data_handler(struct gapm_ext_adv_report_ind const* p_param) +{ +// NS_LOG_INFO("Found:%02x%02x%02x%02x%02x%02x, rssi:%d \r\n", +// p_param->trans_addr.addr.addr[0], +// p_param->trans_addr.addr.addr[1], +// p_param->trans_addr.addr.addr[2], +// p_param->trans_addr.addr.addr[3], +// p_param->trans_addr.addr.addr[4], +// p_param->trans_addr.addr.addr[5], +// p_param->rssi); + +} + +/** + * @brief scan state handler + * @param + * @return + * @note + */ +void app_ble_scan_state_handler(enum scan_state_t state) +{ + switch (state) + { + case SCAN_STATE_SCANING: + NS_LOG_INFO("Scaning.\r\n"); + break; + case SCAN_STATE_FOUND: + NS_LOG_INFO("Found target.\r\n"); + break; + case SCAN_STATE_CONN_TIMEOUT: + NS_LOG_INFO("Connect timeout.\r\n"); + break; + default: + break; + } +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + if(ns_ble_master_connection_num()==0 && + scan_env.scan_enable == false ) + { + ns_ble_start_scan(); + } + break; + case APP_ADV_MODE_SLOW: + + break; + case APP_ADV_MODE_STOP: + if (ns_ble_slave_connection_num() < BLE_SLAVE_CONN) + { + NS_LOG_INFO("START ADV...\r\n"); + ns_ble_adv_start(); + } + break; + default: + break; + } + +} + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = NULL;//SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x0C\x0D\x06" , BD_ADDR_LEN); + } + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_ALL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +/** + * @brief ble scan initialization + * @param + * @return + * @note + */ +void app_ble_scan_init(void) +{ + struct ns_scan_params_t init = {0}; + static const uint8_t target_name[] = {"NS_RDTSS"}; + + init.type = SCAN_PARAM_TYPE; + init.dup_filt_pol = SCAN_PARAM_DUP_FILT_POL; + init.connect_enable = SCAN_PARAM_CONNECT_EN; + init.prop_active_enable = SCAN_PARAM_PROP_ACTIVE; + init.scan_intv = SCAN_PARAM_INTV; + init.scan_wd = SCAN_PARAM_WD; + init.duration = SCAN_PARAM_DURATION; + init.initiating_timeout = 3000; + + init.filter_type = SCAN_FILTER_BY_NAME; + init.filter_data = (uint8_t*)&target_name; + + init.ble_scan_data_handler = app_ble_scan_data_handler; + init.ble_scan_state_handler = app_ble_scan_state_handler; + + ns_ble_scan_init(&init); +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtss_add_rdts); + //add raw data transmit server(rdts) + ns_ble_add_prf_func_register(app_rdtsc_add_rdts); +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_scan_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + if(ns_ble_slave_connection_num()) + { + LedOn(LED2_PORT,LED2_PIN); + } + + if(ns_ble_master_connection_num()) + { + LedOn(LED1_PORT,LED1_PIN); + } +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart adv/scan + if (ns_ble_slave_connection_num() < BLE_SLAVE_CONN) + { + ns_ble_adv_start(); + if (!ns_ble_slave_connection_num()) + { + LedOff(LED2_PORT,LED2_PIN); + } + } + + if (ns_ble_master_connection_num() < BLE_MASTER_CONN) + { + + ns_ble_start_scan(); + if (!ns_ble_master_connection_num()) + { + LedOff(LED1_PORT,LED1_PIN); + } + } + +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_fifo.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_fifo.c new file mode 100644 index 0000000..eb73761 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_fifo.c @@ -0,0 +1,172 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_fifo.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_fifo.h" +#include "app_rdtss.h" +#include "rwprf_config.h" +#include "string.h" +#include "ke_timer.h" +#include "rdtss_task.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +uint8_t master_rx_fifo_buf[MASTER_RX_FIFO_SIZE] = {0}; +uint32_t master_rx_fifo_in = 0; +uint32_t master_rx_fifo_out = 0; +bool sending_to_master; +uint16_t num_send_to_peer_master = 20; //MTU-3 + +/** + * @brief pop own master RX data, send data to peer master + */ +void pop_matser_rx_to_ble(void) +{ + uint32_t in_temp; + uint16_t ble_send_len; + + in_temp = master_rx_fifo_in; + if(master_rx_fifo_out < in_temp) + { + ble_send_len = in_temp-master_rx_fifo_out; + } + else if(master_rx_fifo_out > in_temp){ + ble_send_len = MASTER_RX_FIFO_SIZE-master_rx_fifo_out; + } + else if(master_rx_fifo_out == in_temp){ + // fifo empty, stop send loop + sending_to_master = false; + return; + } + if(ble_send_len > num_send_to_peer_master) + { + ble_send_len = num_send_to_peer_master; + } + sending_to_master = true; + #if (BLE_RDTSS_SERVER) + rdtss_send_notify( &master_rx_fifo_buf[master_rx_fifo_out], ble_send_len); + #endif + master_rx_fifo_out = (master_rx_fifo_out+ble_send_len)%MASTER_RX_FIFO_SIZE; + + return; +} + +/** + * @brief push master RX data to fifo and active ble send first package if not active yet + */ +uint8_t push_master_rx_data_to_fifo(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len; + //store data in fifo + while(len) + { + if(master_rx_fifo_in >= master_rx_fifo_out ) + { + in_len = MASTER_RX_FIFO_SIZE-master_rx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&master_rx_fifo_buf[master_rx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + master_rx_fifo_in = (master_rx_fifo_in + in_len)%MASTER_RX_FIFO_SIZE; + + } + else if(master_rx_fifo_in < master_rx_fifo_out ) + { + in_len = master_rx_fifo_out-master_rx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&master_rx_fifo_buf[master_rx_fifo_in],p_data,in_len); + len = len-in_len; + master_rx_fifo_in = (master_rx_fifo_in + in_len)%MASTER_RX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,master_rx_fifo_in,master_rx_fifo_out); + } + break; + } + } + + if(master_rx_fifo_in != master_rx_fifo_out) //data need to send + { + if(!sending_to_master) + { + ke_timer_set(RDTSS_VAL_NTF_CFM, TASK_APP, 10); + } + } + + return len; +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_gpio.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_gpio.c new file mode 100644 index 0000000..89d0a08 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_gpio.c @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_gpio.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_gpio.h" + +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to B to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_profile/app_rdtsc.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_profile/app_rdtsc.c new file mode 100644 index 0000000..77767b6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_profile/app_rdtsc.c @@ -0,0 +1,290 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtsc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTS_CLIENT) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtsc.h" +#include "rdts_client_task.h" +#include "gapm_task.h" +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" +#include "stdio.h" +#include "ns_ble_task.h" +#include "app_fifo.h" +#include "string.h" +#include "prf_utils_128.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define RDTS_SERVICE_UUID {0x01, 0x10, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_TX_UUID {0x02, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} +#define RDTS_SERVER_RX_UUID {0x01, 0x00, 0x2E, 0xC7, 0x8a, 0x0E, 0x73, 0x90, 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x00, 0x00} + +/* Private constants ---------------------------------------------------------*/ +const uint8_t rdtsc_uuid128[]= RDTS_SERVICE_UUID; +/// State machine used to retrieve RDTS characteristics information +const struct prf_char_def_128 rdtsc_char[RDTSC_CHAR_MAX] = +{ + [RDTSC_SRV_TX_DATA_CHAR] = {RDTS_SERVER_TX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_NTF}, + [RDTSC_SRV_RX_DATA_CHAR] = {RDTS_SERVER_RX_UUID, ATT_MANDATORY, ATT_CHAR_PROP_WR_NO_RESP}, +}; +/// State machine used to retrieve RDTS service characteristic description information +const struct prf_char_desc_def rdtsc_desc[RDTSC_DESC_MAX] = +{ + ///RDTS Client Config + [RDTSC_SRV_TX_DATA_CLI_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, ATT_MANDATORY, RDTSC_SRV_TX_DATA_CHAR}, +}; + +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +void app_rdtsc_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSC; + prf.prf_task_handler = &app_rdtsc_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSC; + get_func.prf_itf_get_func = rdtsc_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtsc_add_rdts(void) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + struct rdtsc_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtsc_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSC; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtsc_db_cfg *) req->param; + + // Attribute table. In case the handle offset needs to be saved + db_cfg->p_char = &rdtsc_char[0]; + db_cfg->p_desc = &rdtsc_desc[0]; + db_cfg->p_uuid128 = rdtsc_uuid128; + + // Send the message + ke_msg_send(req); + + app_rdtsc_init(); +} + + +void app_rdtsc_enable_prf(uint8_t conidx) +{ + NS_LOG_DEBUG("%s %x\r\n", __func__, conidx); + struct rdtsc_enable_req * req = KE_MSG_ALLOC(RDTSC_ENABLE_REQ, + prf_get_task_from_id(TASK_ID_RDTSC), + TASK_APP, + rdtsc_enable_req); + + // Fill in the parameter structure + req->conidx = conidx; + req->con_type = PRF_CON_DISCOVERY; + + // Send the message + ke_msg_send(req); +} + + +void user_send_ble_data(const uint8_t *data, uint16_t length) +{ + NS_LOG_INFO("%s\r\n", __func__); + + if(ns_ble_master_connection_num()) + { + + struct rdtsc_data_tx_req * req = KE_MSG_ALLOC_DYN(RDTSC_DATA_TX_REQ, + prf_get_task_from_id(TASK_ID_RDTSC), + TASK_APP, + rdtsc_data_tx_req, + length); + + req->cursor = ns_ble_get_conidx_by_role(ROLE_MASTER); + req->length = length; + memcpy(&req->data[0], data, length); + ke_msg_send(req); + } + else + { + NS_LOG_INFO("Connect error with peripheral device\r\n"); + } +} + +/** + **************************************************************************************** + * @brief Handles client enable confirmation + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_enable_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_enable_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_INFO("RDTSC profile was enabled = %x\r\n", param->status); + + ns_ble_get_peer_info(GAPC_GET_PEER_FEATURES); + + return (KE_MSG_CONSUMED); +} + +/* + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_data_tx_cfm_handler(ke_msg_id_t const msgid, + struct rdtsc_data_tx_cfm const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_INFO("%s\r\n", __func__); + + return (KE_MSG_CONSUMED); +} + +/** + **************************************************************************************** + * @brief Handles confirmation that data has been sent + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **************************************************************************************** + */ +int rdtsc_data_rx_ind_handler(ke_msg_id_t const msgid, + struct rdtsc_data_rx_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + NS_LOG_DEBUG("Data from connected peripheral\r\n"); + NS_LOG_DEBUG("length = %x\r\n", param->length); + NS_LOG_DEBUG("handle = %x\r\n", param->handle); + NS_LOG_DEBUG("type = %x\r\n", param->type); + NS_LOG_DEBUG("data "); + for(uint8_t i=0; ilength; i++) + { + NS_LOG_DEBUG(" %x", param->data[i]); + } + NS_LOG_DEBUG("\r\n"); + + push_master_rx_data_to_fifo((uint8_t *)(param->data), param->length); + + return (KE_MSG_CONSUMED); +} + +/// Default State handlers definition +const struct ke_msg_handler app_rdtsc_msg_handler_list[] = +{ + {RDTSC_ENABLE_CFM, (ke_msg_func_t)rdtsc_enable_cfm_handler}, + {RDTSC_DATA_TX_CFM, (ke_msg_func_t)rdtsc_data_tx_cfm_handler}, + {RDTSC_DATA_RX_IND, (ke_msg_func_t)rdtsc_data_rx_ind_handler}, +}; + +const struct app_subtask_handlers app_rdtsc_handlers = APP_HANDLERS(app_rdtsc); + + +#endif //BLE_RDTS_CLIENT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_profile/app_rdtss.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_profile/app_rdtss.c new file mode 100644 index 0000000..817daec --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/app_profile/app_rdtss.c @@ -0,0 +1,430 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_rdtss.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ + +#include "rwip_config.h" // SW configuration + +#if (BLE_RDTSS_SERVER) + +/* Includes ------------------------------------------------------------------*/ +#include "co_utils.h" +#include "app_rdtss.h" // rdtss Application Module Definitions +#include "rdtss_task.h" // Device Information Profile Functions +#include "gapm_task.h" // GAP Manager Task API +#include "ns_ble.h" +#include "prf.h" +#include "ke_timer.h" + +#include "stdio.h" +#include "rdtss.h" +#include "app_fifo.h" +#include "app_rdtsc.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +const uint8_t app_rdts_svc_uuid[16] = ATT_SERVICE_AM_SPEED_128; +const struct attm_desc_128 app_rdts_att_db[RDTSS_IDX_NB] = +{ + /* Service Declaration */ + [0] = {{0x00,0x28}, PERM(RD, ENABLE), 0, 0 }, + + /* Characteristic Declaration */ + [1] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [2] = {ATT_CHAR_AM_SPEED_WRITE_128, PERM(WRITE_COMMAND, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [3] = {{0x01,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + /* Characteristic Declaration */ + [4] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [5] = {ATT_CHAR_AM_SPEED_NTF_128, PERM(NTF, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [6] = {{0x02,0x29}, PERM(RD, ENABLE) |PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + /* Characteristic Declaration */ + [7] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [8] = {ATT_CHAR_AM_SPEED_CNTL_POINT_128, PERM(WRITE_COMMAND, ENABLE), PERM_VAL(UUID_LEN, 0x02), 20 }, + + /* Characteristic Declaration */ + [9] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + /* Characteristic Value */ + [10] = {ATT_CHAR_AM_SPEED_CMD_CMP_NTF_128, PERM(NTF, ENABLE), PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 0x200 }, + /* Client Characteristic Configuration Descriptor */ + [11] = {{0x02,0x29}, PERM(RD, ENABLE) |PERM(WRITE_REQ, ENABLE), PERM(RI, ENABLE), 20 }, + + +}; + + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Create raw data transfer server profile database. + * @return void + */ +void app_rdtss_add_rdts(void) +{ + struct rdtss_db_cfg *db_cfg; + + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct rdtss_db_cfg)); + + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_RDTSS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct rdtss_db_cfg *) req->param; + // Attribute table. In case the handle offset needs to be saved + db_cfg->att_tbl = &app_rdts_att_db[0]; + db_cfg->svc_uuid = &app_rdts_svc_uuid[0]; + db_cfg->max_nb_att = RDTSS_IDX_NB; + + // Send the message + ke_msg_send(req); + + app_rdtss_init(); +} + +/** + * @brief rdtss value require indicate handler + * @param + * @return + * @note Note + */ +static int rdtss_value_req_ind_handler(ke_msg_id_t const msgid, + struct rdtss_value_req_ind const *req_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n",__func__); + + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + len = APP_RDTSS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_RDTSS_MANUFACTURER_NAME; + + + // Allocate confirmation to send the value + struct rdtss_value_req_rsp *rsp_value = KE_MSG_ALLOC_DYN(RDTSS_VALUE_REQ_RSP, + src_id, dest_id, + rdtss_value_req_rsp, + len); + rsp_value->status = 0; + rsp_value->conidx = req_value ->conidx; + rsp_value->length = len; + rsp_value->att_idx = req_value->att_idx; + if (len) + { + // Copy data + memcpy(&rsp_value->value, data, len); + } + // Send message + ke_msg_send(rsp_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief cuusts write indicate handler + * @param + * @return + * @note + */ +static int rdtss_val_write_ind_handler(ke_msg_id_t const msgid, + struct rdtss_val_write_ind const *ind_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,write handle = %x,length = %x\r\n",__func__ ,ind_value->handle, ind_value->length); + + for(uint16_t i=0; ilength; i++) + { + NS_LOG_DEBUG("%x ",ind_value->value[i]); + } + NS_LOG_DEBUG("\r\n"); + + uint16_t handle = ind_value->handle; + uint16_t length = ind_value->length; + uint16_t conidx_m = ns_ble_get_conidx_by_role(ROLE_MASTER); + + switch (handle) + { + case RDTSS_IDX_NTF_CFG: + + if(length == 2) + { + uint16_t cfg_value = ind_value->value[0] + ind_value->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + //enabled notify + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + } + } + + break; + case RDTSS_IDX_WRITE_VAL: + //ble data receive + NS_LOG_INFO("Data from connected central\r\n"); + user_send_ble_data(ind_value->value,ind_value->length); + break; + + case RDTSS_IDX_CNTL_POINT_VAL: + { + + switch(ind_value->value[0]) + { + case CNTL_POINT_OP_CONN: + { + //data strructure: || addr_type || addr || + // || 1B || 6B || + + uint8_t i; + + //check addr type + if(ind_value->value[1] > 1) + { + NS_LOG_INFO("ADDR type error: %x\r\n", ind_value->value[1]); + } + else + { + if(conidx_m != GAP_INVALID_CONIDX) + { + NS_LOG_INFO("Master connetion has been established\r\n"); + rdtss_notify_ctrl_point_cmd_cmp(CNTL_POINT_OP_CONN, STATUS_ERR_MASTER_HAS_CONNECTED, NULL, 0); + } + else + { + NS_LOG_INFO("Start connecting peripheral, index: %x\r\n", i); + NS_LOG_INFO("Target ADDR: "); + for(uint8_t k=0; k<6; k++) + { + NS_LOG_INFO(" %x ", ind_value->value[k+2]); + } + NS_LOG_INFO("\r\n"); + + ns_ble_stop_scan(); + NS_LOG_INFO("Stop SCAN\r\n"); + + ns_ble_start_init((uint8_t *)&(ind_value->value[2]), ind_value->value[1]); + } + } + + }break; + + case CNTL_POINT_OP_DISCONN: + { + NS_LOG_INFO("IDX = %x \r\n", conidx_m); + + if(conidx_m != GAP_INVALID_CONIDX) + { + ns_ble_set_active_connection(conidx_m); + ns_ble_disconnect(); + } + else + { + rdtss_notify_ctrl_point_cmd_cmp(CNTL_POINT_OP_DISCONN, STATUS_ERR_NOT_CONNECTED, NULL, 0); + } + }break; + + default:break; + } + } + break; + + default: + break; + + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Functions + * @param + * @return + * @note Note + */ +static int rdtss_val_ntf_cfm_handler(ke_msg_id_t const msgid, + struct rdtss_val_ntf_cfm const *cfm_value, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s,ntf cfm handle = %x, status = %x\r\n",__func__, cfm_value->handle, cfm_value->status); + + pop_matser_rx_to_ble(); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief rdtss send notify + * @param + * @return + * @note + */ +void rdtss_send_notify(uint8_t *data, uint16_t length) +{ + if(ns_ble_slave_connection_num()) + { + struct rdtss_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(RDTSS_VAL_NTF_REQ, + prf_get_task_from_id(TASK_ID_RDTSS), + TASK_APP, + rdtss_val_ntf_ind_req, + length); + + req->conidx = ns_ble_get_conidx_by_role(ROLE_SLAVE); + req->notification = true; + req->handle = RDTSS_IDX_NTF_VAL; + req->length = length; + memcpy(&req->value[0], data, length); + + NS_LOG_DEBUG("%x", req->value[0]); + + ke_msg_send(req); + } + else + { + NS_LOG_INFO("Not connected with central device\r\n"); + } +} + +void rdtss_notify_ctrl_point_cmd_cmp(uint8_t cmd, uint8_t status, uint8_t *data, uint16_t length) +{ + if(ns_ble_slave_connection_num()) + { + struct rdtss_val_ntf_ind_req *req = KE_MSG_ALLOC_DYN(RDTSS_VAL_NTF_REQ, + prf_get_task_from_id(TASK_ID_RDTSS), + TASK_APP, + rdtss_val_ntf_ind_req, + length + 4); + + req->conidx = ns_ble_get_conidx_by_role(ROLE_SLAVE); + req->notification = true; + req->handle = RDTSS_IDX_CMD_CMP_NTF_VAL; + + req->length = length + 4; + + req->value[0] = CNTL_POINT_CMD_CMP; + req->value[1] = cmd; + req->value[2] = status; + req->value[3] = length; + + if(data != NULL) + { + memcpy(&req->value[4], data, length); + } + + ke_msg_send(req); + } + else + { + NS_LOG_INFO("Not connected with central device\r\n"); + } +} + +/// Default State handlers definition +const struct ke_msg_handler app_rdtss_msg_handler_list[] = +{ + {RDTSS_VALUE_REQ_IND, (ke_msg_func_t)rdtss_value_req_ind_handler}, + {RDTSS_VAL_WRITE_IND, (ke_msg_func_t)rdtss_val_write_ind_handler}, + {RDTSS_VAL_NTF_CFM, (ke_msg_func_t)rdtss_val_ntf_cfm_handler}, + +}; + +const struct app_subtask_handlers app_rdtss_handlers = APP_HANDLERS(app_rdtss); + + +void app_rdtss_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_RDTSS; + prf.prf_task_handler = &app_rdtss_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_RDTSS; + get_func.prf_itf_get_func = rdtss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +#endif //BLE_RDTSS_SERVER diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/main.c new file mode 100644 index 0000000..4846179 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/ble_central/central_relay_1m2s/src/main.c @@ -0,0 +1,139 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "ns_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "app_gpio.h" +#include "app_ble.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING1 "\r\nRaw Data Transfer RELAY demo\r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + //for hold the SWD before sleep + delay_n_10us(200*1000); + + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING1); + + // periph init + LedInit(LED1_PORT,LED1_PIN); // power led + LedInit(LED2_PORT,LED2_PIN); //connection state + + //init text + delay_n_10us(500); + //disable usart for enter sleep + + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + ns_sleep(); + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/bsp/inc/log.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/bsp/inc/log.h new file mode 100644 index 0000000..4828bba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/bsp/inc/log.h @@ -0,0 +1,118 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file log.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __LOG_H__ +#define __LOG_H__ + +#ifndef LOG_ENABLE +#define LOG_ENABLE 1 +#endif + +#if LOG_ENABLE + +#include + +#define LOG_NONE 0 +#define LOG_ERROR 10 +#define LOG_WARNING 20 +#define LOG_INFO 30 +#define LOG_DEBUG 40 + +#ifndef LOG_LEVEL +#define LOG_LEVEL LOG_DEBUG +#endif + +#if LOG_LEVEL >= LOG_INFO +#define log_info(...) printf(__VA_ARGS__) +#else +#define log_info(...) +#endif + +#if LOG_LEVEL >= LOG_ERROR +#define log_error(...) printf(__VA_ARGS__) +#else +#define log_error(...) +#endif + +#if LOG_LEVEL >= LOG_WARNING +#define log_warning(...) printf(__VA_ARGS__) +#else +#define log_warning(...) +#endif + +#if LOG_LEVEL >= LOG_DEBUG +#define log_debug(...) printf(__VA_ARGS__) +#else +#define log_debug(...) +#endif + +void log_init(void); +void Delay(unsigned int count); +void Delay_ms(unsigned int count); +void log_buff(unsigned char *data, int len); + +#else /* !LOG_ENABLE */ + +#define log_info(...) +#define log_warning(...) +#define log_error(...) +#define log_debug(...) +#define log_init() + +#endif + +#define log_func() log_debug("call %s\r\n", __FUNCTION__) + +#endif /* __LOG_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/bsp/src/log.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/bsp/src/log.c new file mode 100644 index 0000000..a29a233 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/bsp/src/log.c @@ -0,0 +1,224 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file log.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "log.h" + +#if LOG_ENABLE + +#include "n32wb03x.h" +#include "n32wb03x_gpio.h" +#include "n32wb03x_usart.h" +#include "n32wb03x_rcc.h" + +#define LOG_USART (1) + +#if (LOG_USART == 1) +#define LOG_USARTx USART1 +#define LOG_PERIPH RCC_APB2_PERIPH_USART1 +#define LOG_GPIO GPIOB +#define LOG_PERIPH_GPIO RCC_APB2_PERIPH_GPIOB +#define LOG_TX_PIN GPIO_PIN_6 +#define LOG_RX_PIN GPIO_PIN_7 +#define LOG_GPIO_AF GPIO_AF4_USART1 +#else +#define LOG_USARTx USART2 +#define LOG_PERIPH RCC_APB1_PERIPH_USART2 +#define LOG_GPIO GPIOB +#define LOG_PERIPH_GPIO RCC_APB2_PERIPH_GPIOB +#define LOG_TX_PIN GPIO_PIN_4 +#define LOG_RX_PIN GPIO_PIN_5 +#define LOG_GPIO_AF GPIO_AF3_USART2 //GPIO_AF4_USART1 +#endif + +void gpio_starup_deinit(void) +{ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_I2C1, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_I2C1, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_I2C1, DISABLE); + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_I2C1, DISABLE); + RCC_EnableAPB2PeriphClk( RCC_APB2_PERIPH_AFIO, DISABLE); + RCC_EnableAPB2PeriphClk (RCC_APB2_PERIPH_GPIOB, DISABLE ); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_I2C1, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_I2C1, DISABLE); + + GPIO_DeInit(GPIOA); + GPIO_DeInit(GPIOB); + + GPIO_AFIOInitDefault(); + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, DISABLE); + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, DISABLE); +} + +void log_init(void) +{ + GPIO_InitType GPIO_InitStructure; + USART_InitType USART_InitStructure; + + gpio_starup_deinit(); + + GPIO_InitStruct(&GPIO_InitStructure); + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | LOG_PERIPH_GPIO, ENABLE); + +#if (LOG_USART == 1) + RCC_EnableAPB2PeriphClk(LOG_PERIPH, ENABLE); +#else + RCC_EnableAPB1PeriphClk(LOG_PERIPH, ENABLE); +#endif + + GPIO_InitStructure.Pin = LOG_TX_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = LOG_RX_PIN; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + // init uart + USART_Init(LOG_USARTx, &USART_InitStructure); + + // enable uart + USART_Enable(LOG_USARTx, ENABLE); +} + +static int is_lr_sent = 0; + +int fputc(int ch, FILE* f) +{ + if (ch == '\r') + { + is_lr_sent = 1; + } + else if (ch == '\n') + { + if (!is_lr_sent) + { + USART_SendData(LOG_USARTx, (uint8_t)'\r'); + /* Loop until the end of transmission */ + while (USART_GetFlagStatus(LOG_USARTx, USART_FLAG_TXC) == RESET) + { + } + } + is_lr_sent = 0; + } + else + { + is_lr_sent = 0; + } + USART_SendData(LOG_USARTx, (uint8_t)ch); + /* Loop until the end of transmission */ + while (USART_GetFlagStatus(LOG_USARTx, USART_FLAG_TXC) == RESET) + { + } + return ch; +} + +void log_buff(uint8_t *data, int len) +{ + int i = 0; + for(i=0; i 0; count--) + { + i++; + } + +} + +extern void system_delay_n_10us(uint32_t value); +void Delay_ms(uint32_t count) +{ + system_delay_n_10us(100*count); +} + +#ifdef USE_FULL_ASSERT + +//__WEAK +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + log_error("assertion failed: `%s` at %s:%d", expr, file, line); + while (1) + { + } +} +#endif // USE_FULL_ASSERT + +#endif // LOG_ENABLE diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/MDK-ARM/app_ota.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/MDK-ARM/app_ota.uvoptx new file mode 100644 index 0000000..f1d884c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/MDK-ARM/app_ota.uvoptx @@ -0,0 +1,906 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + DFU-APP1 + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + DFU-APP2 + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 0 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + 4 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + lib_att.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + ns_iuss.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + ns_iuss_task.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 6 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + ns_timer.c + 0 + 0 + + + 6 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + Crypto + 0 + 0 + 0 + 0 + + 7 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + ns_ecc.c + 0 + 0 + + + 7 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + sha256.c + 0 + 0 + + + 7 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + uECC.c + 0 + 0 + + + + + NS_DFU + 0 + 0 + 0 + 0 + + 8 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + ns_dfu_ble.c + 0 + 0 + + + 8 + 31 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + ns_dfu_boot.c + 0 + 0 + + + 8 + 32 + 1 + 0 + 0 + 0 + ..\..\common\dfu_crc.c + dfu_crc.c + 0 + 0 + + + 8 + 33 + 1 + 0 + 0 + 0 + ..\..\common\dfu_delay.c + dfu_delay.c + 0 + 0 + + + 8 + 34 + 1 + 0 + 0 + 0 + ..\..\common\dfu_led.c + dfu_led.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 9 + 35 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 9 + 36 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_ns_ius.c + app_ns_ius.c + 0 + 0 + + + 9 + 37 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 10 + 38 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 11 + 39 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 12 + 40 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/MDK-ARM/app_ota.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/MDK-ARM/app_ota.uvprojx new file mode 100644 index 0000000..3d57dcb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/MDK-ARM/app_ota.uvprojx @@ -0,0 +1,1300 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + DFU-APP1 + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + app_ota + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\app_ota.bin .\Objects\app_ota.axf + cmd.exe /C copy .\bin\app_ota.bin ..\..\..\..\..\utilities\dfu\Image\APP1.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1004000 + 0x1c000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03x, USE_STDPERIPH_DRIVER,APPLICATION + + ..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\inc\app_profile;..\inc\rw;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + + + BLE_STACK + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_DFU + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + dfu_crc.c + 1 + ..\..\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\common\dfu_led.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + DFU-APP2 + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + app_ota + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\app_ota.bin .\Objects\app_ota.axf + cmd.exe /C copy .\bin\app_ota.bin ..\..\..\..\..\utilities\dfu\Image\APP2.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1020000 + 0x1c000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03x, USE_STDPERIPH_DRIVER,APPLICATION + + ..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\inc\app_profile;..\inc\rw;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + + + BLE_STACK + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_timer.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer\ns_timer.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_DFU + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + dfu_crc.c + 1 + ..\..\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\common\dfu_delay.c + + + dfu_led.c + 1 + ..\..\common\dfu_led.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + + + + + app_ota + 1 + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_ble.h new file mode 100644 index 0000000..0d16f44 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_ble.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_profile/app_dis.h new file mode 100644 index 0000000..d9d4fe5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_profile/app_dis.h @@ -0,0 +1,157 @@ + /** + * Copyright (c) 2025, NSING Technologies Inc. + * + * All rights reserved. + * + * This software is the exclusive property of NSING Technologies Inc. (Hereinafter + * referred to as NSING). This software, and the product of NSING described herein + * (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties + * of the People's Republic of China and other applicable jurisdictions worldwide. + * + * NSING does not grant any license under its patents, copyrights, trademarks, or other + * intellectual property rights. Names and brands of third party may be mentioned or referred + * thereto (if any) for identification purposes only. + * + * NSING reserves the right to make changes, corrections, enhancements, modifications, and + * improvements to this software at any time without notice. Please contact NSING and obtain + * the latest version of this software before placing orders. + + * Although NSING has attempted to provide accurate and reliable information, NSING assumes + * no responsibility for the accuracy and reliability of this software. + * + * It is the responsibility of the user of this software to properly design, program, and test + * the functionality and safety of any application made of this information and any resulting product. + * In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or + * consequential damages arising in any way out of the use of this software or the Product. + * + * NSING Products are neither intended nor warranted for usage in systems or equipment, any + * malfunction or failure of which may cause loss of human life, bodily injury or severe property + * damage. Such applications are deemed, "Insecure Usage". + * + * All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING + * harmless from and against all claims, costs, damages, and other liabilities, arising from or related + * to any customer's Insecure Usage. + + * Any express or implied warranty with regard to this software or the Product, including,but not + * limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement + * are disclaimed to the fullest extent permitted by law. + + * Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe + * or otherwise distribute this software for any purposes, in whole or in part. + * + * NSING products and technologies shall not be used for or incorporated into any products or systems + * whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. + * User shall comply with any applicable export control laws and regulations promulgated and administered by + * the governments of any countries asserting jurisdiction over the parties or transactions. + **/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("6.1.2") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("6.3.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_profile/app_ns_ius.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_profile/app_ns_ius.h new file mode 100644 index 0000000..c55f634 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_profile/app_ns_ius.h @@ -0,0 +1,112 @@ + /** + * Copyright (c) 2025, NSING Technologies Inc. + * + * All rights reserved. + * + * This software is the exclusive property of NSING Technologies Inc. (Hereinafter + * referred to as NSING). This software, and the product of NSING described herein + * (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties + * of the People's Republic of China and other applicable jurisdictions worldwide. + * + * NSING does not grant any license under its patents, copyrights, trademarks, or other + * intellectual property rights. Names and brands of third party may be mentioned or referred + * thereto (if any) for identification purposes only. + * + * NSING reserves the right to make changes, corrections, enhancements, modifications, and + * improvements to this software at any time without notice. Please contact NSING and obtain + * the latest version of this software before placing orders. + + * Although NSING has attempted to provide accurate and reliable information, NSING assumes + * no responsibility for the accuracy and reliability of this software. + * + * It is the responsibility of the user of this software to properly design, program, and test + * the functionality and safety of any application made of this information and any resulting product. + * In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or + * consequential damages arising in any way out of the use of this software or the Product. + * + * NSING Products are neither intended nor warranted for usage in systems or equipment, any + * malfunction or failure of which may cause loss of human life, bodily injury or severe property + * damage. Such applications are deemed, "Insecure Usage". + * + * All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING + * harmless from and against all claims, costs, damages, and other liabilities, arising from or related + * to any customer's Insecure Usage. + + * Any express or implied warranty with regard to this software or the Product, including,but not + * limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement + * are disclaimed to the fullest extent permitted by law. + + * Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe + * or otherwise distribute this software for any purposes, in whole or in part. + * + * NSING products and technologies shall not be used for or incorporated into any products or systems + * whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. + * User shall comply with any applicable export control laws and regulations promulgated and administered by + * the governments of any countries asserting jurisdiction over the parties or transactions. + **/ + + +/** + * @file app_ns_ius.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef __APP_NS_IUS_H__ +#define __APP_NS_IUS_H__ + + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration +#include "prf_types.h" +#include "prf.h" + +#if (BLE_APP_NS_IUS) + + +#define SERVICE_NS_IUS {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, 0x01,0x00, 0x11,0x11} +#define CHAR_NS_IUS_RC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x02,0x00, 0x11,0x11} +#define CHAR_NS_IUS_CC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x03,0x00, 0x11,0x11} +/* Public typedef -----------------------------------------------------------*/ +enum +{ + NS_IUS_IDX_SVC, + NS_IUS_IDX_RC_CHAR, + NS_IUS_IDX_RC_VAL, + NS_IUS_IDX_RC_CFG, + NS_IUS_IDX_CC_CHAR, + NS_IUS_IDX_CC_VAL, + NS_IUS_IDX_CC_CFG, + NS_IUS_IDX_NB, +}; + +/* Public variables ---------------------------------------------------------*/ +extern struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB]; +extern const struct app_subtask_handlers ns_ius_app_handlers; + + +/* Public function prototypes -----------------------------------------------*/ +/** + * @brief SEND DATA THROUGH NS IUS SERVICE + **/ +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length); +/** + * @brief Add a NATIONS IMAGE UPDATE Service instance in the DB + **/ +void app_ns_ius_add_ns_ius(void); +/** + * @brief Initialize NATIONS IMAGE UPDATE Service Application + **/ +void app_ns_ius_init(void); + +#endif //BLE_APP_NS_IUS + + + + + + +#endif //__APP_NS_IUS_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..d91790c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_profile/rwapp_config.h @@ -0,0 +1,134 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + + + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_user_config.h new file mode 100644 index 0000000..46632d7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/inc/app_user_config.h @@ -0,0 +1,141 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "NATIONS" +#define CUSTOM_BLE_MAC_ADDRESS "\x89\x22\x77\x44\x55\x66" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 1600 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 1 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 0 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + + +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_DEVICE_INFORMATION_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +/// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +/// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 7.5 /**< Minimum connection interval (7.5 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 6 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (0) /**< Time of initiating event to update connection params (5 seconds). */ + + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 0 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +//frofiles config +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +#define CFG_APP_NS_IUS 1 + +/* User config */ + +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 1 +#define NS_LOG_USART_ENABLE 0 +#define NS_LOG_RTT_ENABLE 0 + +#define NS_TIMER_ENABLE 1 + +#define FIRMWARE_VERSION "0.0.01" +#define HARDWARE_VERSION "0.0.01" + + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/readme.txt new file mode 100644 index 0000000..f9053f5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/readme.txt @@ -0,0 +1,28 @@ + +1. Function description + + 1. This routine shows the OTA upgrade application layer. + 2. The dual bank upgrade function is realized. + 3. Realize the function of copying Image Update and jumping to Image Update in single bank upgrade. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. Log print: DEMO board PB1(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + 4. Bluetooth BLE name: NATIONS + + usage method: + Refer to Chapter 7.3 of the Firmware Upgrade User's Guide + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/app_ble.c new file mode 100644 index 0000000..ff7e5a6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/app_ble.c @@ -0,0 +1,332 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "n32wb03x.h" +#include "gapm_task.h" // GAP Manager Task API +#include "ns_sec.h" +#include "app_ble.h" +#include "app_dis.h" +#if (BLE_APP_NS_IUS) +#include "app_ns_ius.h" +#endif //BLE_APP_NS_IUS +#include "app_user_config.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + + switch (msgid) + { + case APP_CUSTS_TEST_EVT: + + break; +// case : +// break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, CUSTOM_BLE_MAC_ADDRESS , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + #if (BLE_APP_DIS) + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); + #endif //BLE_APP_DIS + + #if (BLE_APP_NS_IUS) + ns_ble_add_prf_func_register(app_ns_ius_add_ns_ius); + #endif //BLE_APP_NS_IUS + + +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32000HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + //start adv + ns_ble_adv_start(); +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + + #if (BLE_APP_BATT) + // Enable Battery Service + app_batt_enable_prf(app_env.conidx); + #endif //(BLE_APP_BATT) +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising + ns_ble_adv_start(); + +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/app_profile/app_ns_ius.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/app_profile/app_ns_ius.c new file mode 100644 index 0000000..1846f9b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/app_profile/app_ns_ius.c @@ -0,0 +1,248 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ns_ius.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_NS_IUS) + +#include "app_ns_ius.h" +#include +#include "ns_iuss.h" +#include "ns_iuss_task.h" +#include "ns_dfu_ble.h" +#include "attm.h" +#include "ke_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "gattc_task.h" +#include "attm_db.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" +#include "ke_msg.h" +#include "ns_ble.h" +#include "ns_log.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB] = +{ + [NS_IUS_IDX_SVC] = {{0x00,0x28}, PERM(RD, ENABLE),0,0}, + + [NS_IUS_IDX_RC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE),0, 0}, + [NS_IUS_IDX_RC_VAL] = {CHAR_NS_IUS_RC, PERM(WRITE_COMMAND, ENABLE), PERM_VAL(UUID_LEN, 0x02), 247}, + [NS_IUS_IDX_RC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + [NS_IUS_IDX_CC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + [NS_IUS_IDX_CC_VAL] = {CHAR_NS_IUS_CC, PERM(WRITE_REQ, ENABLE) | PERM(NTF, ENABLE) , PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 20 }, + [NS_IUS_IDX_CC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + + + + + +static bool notification_enable = false; + + + + + +static int ns_ius_val_write_ind_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + const struct ns_ius_val_write_ind *p_param = (const struct ns_ius_val_write_ind *)param; + + switch (p_param->handle) + { + case NS_IUS_IDX_CC_CFG:{ + + if(p_param->length == 2) + { + uint16_t cfg_value = p_param->value[0] + p_param->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + notification_enable = true; + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + notification_enable = false; + } + NS_LOG_DEBUG("notification_enable %d\r\n",notification_enable); + } + + }break; + + + case NS_IUS_IDX_CC_VAL:{ + uint8_t output[20]; + uint8_t output_len = 0; + ns_dfu_ble_handler_cc(p_param->value, p_param->length, output, &output_len); + if(output_len)ns_ble_ius_app_cc_send(output, output_len); + }break; + + case NS_IUS_IDX_RC_VAL:{ + ns_dfu_ble_handler_rc(p_param->value, p_param->length); + }break; + default: + break; + + } + + return KE_MSG_CONSUMED; +} + + + +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length) +{ + uint8_t state = ke_state_get(ns_ble_ius_task); + if (state == NS_IUS_BUSY || notification_enable == false) + { + return; + } + ke_state_set(ns_ble_ius_task, NS_IUS_BUSY); + + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + struct gattc_send_evt_cmd * req = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, KE_BUILD_ID(TASK_GATTC, app_env.conidx), ns_ius_env->prf_env.prf_task, gattc_send_evt_cmd, length); + req->operation = GATTC_NOTIFY; + req->handle = ns_ius_env->shdl + NS_IUS_IDX_CC_VAL; + req->length = length; + memcpy(req->value, p_data, length); + ke_msg_send(req); +} + + + +static int ns_ius_disconnect_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + notification_enable = false; + return KE_MSG_CONSUMED; +} + + +const struct ke_msg_handler ns_ius_app_msg_handler_list[] = +{ + {NS_IUS_VAL_WRITE_IND, ns_ius_val_write_ind_handler}, + {NS_IUS_DISCONNECT, ns_ius_disconnect_handler}, +}; + + +const struct app_subtask_handlers ns_ius_app_handlers = APP_HANDLERS(ns_ius_app); + + + + + + + +void app_ns_ius_add_ns_ius(void) +{ + Qflash_Init(); + + struct ns_ius_db_cfg *db_cfg; + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct ns_ius_db_cfg)); + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_NS_IUS; + req->app_task = TASK_APP; + req->start_hdl = 0; + db_cfg = (struct ns_ius_db_cfg *) req->param; + db_cfg->att_tbl = NULL; + db_cfg->cfg_flag = 0; + db_cfg->features = 0; + ke_msg_send(req); + + app_ns_ius_init(); +} + +void app_ns_ius_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_NS_IUS; + prf.prf_task_handler = &ns_ius_app_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_NS_IUS; + get_func.prf_itf_get_func = ns_ius_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + + +#endif //BLE_APP_NS_IUS + + +/// @} APP + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/main.c new file mode 100644 index 0000000..cb05a03 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/app_ota/src/main.c @@ -0,0 +1,116 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ + +#include "dfu_led.h" +#include "n32wb03x.h" +#include "dfu_delay.h" +#include "rwip.h" +#include "ns_ble.h" +#include "app_ble.h" +#include "ns_sleep.h" +#include "ns_delay.h" +#include "ns_log.h" +#include "ns_dfu_boot.h" + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + + NS_LOG_INIT(); + + if(CURRENT_APP_START_ADDRESS == NS_APP1_START_ADDRESS){ + NS_LOG_INFO("application 1 start new ...\r\n"); + }else if(CURRENT_APP_START_ADDRESS == NS_APP2_START_ADDRESS){ + NS_LOG_INFO("application 2 start new ...\r\n"); + } + + dfu_leds_config(); + + for(uint8_t i=0;i<10;i++) + { + dfu_led_toggle(LED1_GPIO_PORT, LED_GPIO1_PIN); + if(CURRENT_APP_START_ADDRESS == NS_APP1_START_ADDRESS){ + dfu_delay_ms(100); + }else if(CURRENT_APP_START_ADDRESS == NS_APP2_START_ADDRESS){ + dfu_delay_ms(500); + } + dfu_led_toggle(LED2_GPIO_PORT, LED_GPIO2_PIN); + } + dfu_led_off(LED1_GPIO_PORT, LED_GPIO1_PIN); + dfu_led_off(LED2_GPIO_PORT, LED_GPIO2_PIN); + + app_ble_init(); + + while(1) + { + rwip_schedule(); + ns_sleep(); + } +} + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_crc.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_crc.c new file mode 100644 index 0000000..1540f91 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_crc.c @@ -0,0 +1,135 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file dfu_crc.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "dfu_crc.h" +#include "n32wb03x_crc.h" + +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ + +#define LITTLE_TO_BIG(u32) \ +(uint32_t) ((u32 & 0x000000FF) << 24) | \ +(uint32_t) ((u32 & 0x0000FF00) << 8) | \ +(uint32_t) ((u32 & 0x00FF0000) >> 8) | \ +(uint32_t) ((u32 & 0xFF000000) >> 24) + +/** + * @brief Calculate crc32 for given data, using hardware crc32. + * @param[in] p_data raw data. + * @param[in] len raw data len. + * @return crc32 result. + */ +uint32_t dfu_crc32(uint8_t * p_data, uint32_t len) +{ + if ((uint32_t)p_data == 0xFFFFFFFF) return 0; + uint32_t u32p_data; + RCC->AHBPCLKEN |= RCC_AHB_PERIPH_CRC; + CRC->CRC32CTRL = CRC32_CTRL_RESET; + uint32_t index = 0; + + //for if led%4 > 0 + switch (len&0x3) + { + case 1: + CRC->CRC32DAT = 0x6AA59E9D; + u32p_data = p_data[index]; + CRC->CRC32DAT = u32p_data; + index += 1; + break; + case 2: + CRC->CRC32DAT = 0x9746CD0A; + u32p_data = (uint32_t)(p_data[index]<<8)| p_data[index + 1]; + CRC->CRC32DAT = u32p_data; + index += 2; + break; + case 3: + CRC->CRC32DAT = 0xCC6021D0; + u32p_data = (uint32_t)(p_data[index]<<16)| (p_data[index + 1]<<8)|(p_data[index + 2]); + CRC->CRC32DAT = u32p_data; + index += 3; + break; + default: + break; + } + + while (index < len) + { + u32p_data = p_data[index]; + index++; + u32p_data = (u32p_data<<8)|p_data[index]; + index++; + u32p_data = (u32p_data<<8)|p_data[index]; + index++; + u32p_data = (u32p_data<<8)|p_data[index]; + index++; + CRC->CRC32DAT = u32p_data; + } + + return CRC->CRC32DAT; +} + +/** + * @} + */ + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_crc.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_crc.h new file mode 100644 index 0000000..fe6e069 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_crc.h @@ -0,0 +1,85 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file dfu_crc.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef __DFU_CRC_H__ +#define __DFU_CRC_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include + +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +uint32_t dfu_crc32(uint8_t * p_data, uint32_t len); + + + +#ifdef __cplusplus +} +#endif +#endif //__DFU_CRC_H__ + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_delay.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_delay.c new file mode 100644 index 0000000..07f46e8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_delay.c @@ -0,0 +1,109 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file dfu_delay.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "dfu_delay.h" +#include "n32wb03x.h" + + +__ASM volatile void delay_cycles(uint32_t cycles) +{ + SUBS r0, #1 + BNE delay_cycles + BX LR +} + + +static void delay_10us(uint32_t us_10) +{ + delay_cycles(40*us_10); +} + +/** + * @brief Hold the cpu for number of ms. + * @param[in] ms time in ms unit. + * @return none. + */ +void dfu_delay_ms(uint32_t ms) +{ + for(uint32_t i=0;i + +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +void dfu_delay_10us(uint32_t us_10); +void dfu_delay_ms(uint32_t ms); + + + +#ifdef __cplusplus +} +#endif + + +#endif //__DFU_DELAY_H__ +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_led.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_led.c new file mode 100644 index 0000000..d2d2411 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_led.c @@ -0,0 +1,138 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file dfu_led.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "dfu_led.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Development board led init. + * @param[in] none. + * @return none. + */ +void dfu_leds_config(void) +{ + GPIO_InitType GPIO_InitStructure; + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + + GPIO_InitStructure.Pin = LED_GPIO1_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitPeripheral(LED1_GPIO_PORT, &GPIO_InitStructure); + GPIO_InitStructure.Pin = LED_GPIO2_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitPeripheral(LED2_GPIO_PORT, &GPIO_InitStructure); + + GPIO_ResetBits(LED1_GPIO_PORT, LED_GPIO1_PIN); + GPIO_ResetBits(LED2_GPIO_PORT, LED_GPIO2_PIN); + +} +/** + * @brief Development board led turn on. + * @param[in] led_port led port num. + * @param[in] led_pin led pin num. + * @return none. + */ +void dfu_led_on(GPIO_Module* led_port, uint32_t led_pin) +{ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + GPIO_SetBits(led_port, led_pin); +} +/** + * @brief Development board led turn off. + * @param[in] led_port led port num. + * @param[in] led_pin led pin num. + * @return none. + */ +void dfu_led_off(GPIO_Module* led_port, uint32_t led_pin) +{ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + GPIO_ResetBits(led_port, led_pin); +} +/** + * @brief Development board led toggle. + * @param[in] led_port led port num. + * @param[in] led_pin led pin num. + * @return none. + */ +void dfu_led_toggle(GPIO_Module* led_port, uint32_t led_pin) +{ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + GPIO_TogglePin(led_port, led_pin); +} + + + +/** + * @} + */ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_led.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_led.h new file mode 100644 index 0000000..aba2317 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_led.h @@ -0,0 +1,97 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file dfu_led.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef __DFU_LED_H__ +#define __DFU_LED_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ + +#include "n32wb03x.h" +#include + + +/* Public define ------------------------------------------------------------*/ +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define LED1_GPIO_PORT GPIOB +#define LED2_GPIO_PORT GPIOA +#define LED_GPIO1_PIN GPIO_PIN_0 +#define LED_GPIO2_PIN GPIO_PIN_6 + +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +void dfu_leds_config(void); +void dfu_led_on(GPIO_Module* led_port, uint32_t led_pin); +void dfu_led_off(GPIO_Module* led_port, uint32_t led_pin); +void dfu_led_toggle(GPIO_Module* led_port, uint32_t led_pin); + + + +#ifdef __cplusplus +} +#endif + + + + +#endif //__DFU_LED_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_usart.c new file mode 100644 index 0000000..aa64019 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_usart.c @@ -0,0 +1,284 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file dfu_usart.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "dfu_usart.h" +#include "n32wb03x.h" +#include +#include +extern void system_delay_cycles(uint32_t i); + +/** + * @brief config rcc of usart1 + * @param + * @return + * @note + */ +static void rcc_configure_usart1(void) +{ + RCC->APB2PCLKEN |= RCC_APB2_PERIPH_GPIOA|RCC_APB2_PERIPH_GPIOB; + RCC->APB2PCLKEN |= RCC_APB2_PERIPH_USART1; +} + +/** + * @brief config gpio of usart1 + * @param + * @return + * @note + */ +static void gpio_configure_usart1(uint8_t gpio) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + if(gpio == USART1_GPIO_PA45) + { + GPIO_InitStructure.Pin = GPIO_PIN_4; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF3_USART1; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIO_PIN_5; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF3_USART1; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + + } + else { + + GPIO_InitStructure.Pin = GPIO_PIN_4; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0_SWD; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIO_PIN_5; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0_SWD; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF4_USART1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIO_PIN_7; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF4_USART1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + } + + +} + +/** + * @brief config usart1 + * @param + * @return + * @note + */ +static void config_usart1(uint32_t baud) +{ + USART_InitType USART_InitStructure; + + USART_InitStructure.BaudRate = baud; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + USART_Init(USART1, &USART_InitStructure); + +} + +/** + * @brief config usart1 for dfu + * @param + * @return + * @note + */ + +void dfu_usart1_poll_config(uint8_t gpio,uint32_t baud) +{ + + rcc_configure_usart1(); + gpio_configure_usart1(gpio); + dfu_usart1_disable(); + config_usart1(baud); + dfu_usart1_enable(); +} + +/** + * @brief enable usart1 + * @param + * @return + * @note + */ +void dfu_usart1_enable(void) +{ + USART_Enable(USART1, ENABLE); +} + + +/** + * @brief disable usart1 + * @param + * @return + * @note + */ +void dfu_usart1_disable(void) +{ + USART_Enable(USART1, DISABLE); +} + +/** + * @brief send data via usart1 + * @param + * @return + * @note + */ +void dfu_usart1_send(uint8_t *p_data, uint32_t len) +{ + for(uint32_t i=0;iAPB2PRST |= RCC_APB2_PERIPH_AFIO|RCC_APB2_PERIPH_GPIOA|RCC_APB2_PERIPH_GPIOB|RCC_APB2_PERIPH_USART1; + RCC->APB2PRST &= ~(RCC_APB2_PERIPH_AFIO|RCC_APB2_PERIPH_GPIOA|RCC_APB2_PERIPH_GPIOB|RCC_APB2_PERIPH_USART1); + + RCC->APB2PCLKEN &= ~(RCC_APB2_PERIPH_AFIO|RCC_APB2_PERIPH_GPIOA|RCC_APB2_PERIPH_GPIOB|RCC_APB2_PERIPH_USART1); +} + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_usart.h new file mode 100644 index 0000000..399cf64 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/common/dfu_usart.h @@ -0,0 +1,83 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file dfu_crc.h + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + /** @addtogroup + * @{ + */ +#ifndef __DFU_USART_H__ +#define __DFU_USART_H__ + +/* Includes ------------------------------------------------------------------*/ +#include + +#define USART1_GPIO_PA45 0 +#define USART1_GPIO_PB67 1 +/* Public constants ---------------------------------------------------------*/ +/* Public function prototypes -----------------------------------------------*/ +void dfu_usart1_disable(void); +void dfu_usart1_enable(void); +void dfu_usart1_config(void); +void dfu_usart1_send(uint8_t *p_data, uint32_t len); +uint8_t dfu_usart1_receive(uint8_t *p_data); +void dfu_usart1_interrupt_config(void); +void dfu_usart1_interrupt_config(void); +void dfu_usart1_poll_config(uint8_t gpio,uint32_t baud); +void dfu_usart1_default_config(void); +uint8_t dfu_usart1_poll_boot_byte(uint8_t byte, uint32_t timeout); + + +#endif //__DFU_USART_H__ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/MDK-ARM/image_update.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/MDK-ARM/image_update.uvoptx new file mode 100644 index 0000000..16baaaf --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/MDK-ARM/image_update.uvoptx @@ -0,0 +1,607 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + lib_att.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + ns_iuss.c + 0 + 0 + + + 5 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + ns_iuss_task.c + 0 + 0 + + + + + Crypto + 0 + 0 + 0 + 0 + + 6 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + ns_ecc.c + 0 + 0 + + + 6 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + sha256.c + 0 + 0 + + + 6 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + uECC.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 7 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + + + NS_DFU + 0 + 0 + 0 + 0 + + 8 + 19 + 1 + 0 + 0 + 0 + ..\..\common\dfu_crc.c + dfu_crc.c + 0 + 0 + + + 8 + 20 + 1 + 0 + 0 + 0 + ..\..\common\dfu_delay.c + dfu_delay.c + 0 + 0 + + + 8 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + ns_dfu_ble.c + 0 + 0 + + + 8 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + ns_dfu_boot.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 9 + 23 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_ns_ius.c + app_ns_ius.c + 0 + 0 + + + 9 + 24 + 1 + 0 + 0 + 0 + ..\src\ns_ble.c + ns_ble.c + 0 + 0 + + + 9 + 25 + 1 + 0 + 0 + 0 + ..\src\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 10 + 26 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 11 + 27 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 12 + 28 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/MDK-ARM/image_update.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/MDK-ARM/image_update.uvprojx new file mode 100644 index 0000000..3cbe795 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/MDK-ARM/image_update.uvprojx @@ -0,0 +1,640 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + image_update + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\image_update.bin .\Objects\image_update.axf + cmd.exe /C copy .\bin\image_update.bin ..\..\..\..\..\utilities\dfu\Image\ImageUpdate.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + -1 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x103c000 + 0x4000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03x, USE_STDPERIPH_DRIVER,IMAGE_UPDATE + + ..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\inc\app_profile;..\inc\rw;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\rdts\rdtss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp\hogpd\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\hogp;..\..\common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + lib_att.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\att\lib_att.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + ns_iuss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss.c + + + ns_iuss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\ns_ius\ns_iuss\src\ns_iuss_task.c + + + + + Crypto + + + ns_ecc.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\ns_ecc.c + + + sha256.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\sha256.c + + + uECC.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ecc\uECC.c + + + + + NS_LIB + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + + + NS_DFU + + + dfu_crc.c + 1 + ..\..\common\dfu_crc.c + + + dfu_delay.c + 1 + ..\..\common\dfu_delay.c + + + ns_dfu_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_ble.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + + + BLE_APP + + + app_ns_ius.c + 1 + ..\src\app_profile\app_ns_ius.c + + + ns_ble.c + 1 + ..\src\ns_ble.c + + + ns_ble_task.c + 1 + ..\src\ns_ble_task.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/app_profile/app_ns_ius.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/app_profile/app_ns_ius.h new file mode 100644 index 0000000..7c028e7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/app_profile/app_ns_ius.h @@ -0,0 +1,112 @@ + /** + * Copyright (c) 2025, NSING Technologies Inc. + * + * All rights reserved. + * + * This software is the exclusive property of NSING Technologies Inc. (Hereinafter + * referred to as NSING). This software, and the product of NSING described herein + * (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties + * of the People's Republic of China and other applicable jurisdictions worldwide. + * + * NSING does not grant any license under its patents, copyrights, trademarks, or other + * intellectual property rights. Names and brands of third party may be mentioned or referred + * thereto (if any) for identification purposes only. + * + * NSING reserves the right to make changes, corrections, enhancements, modifications, and + * improvements to this software at any time without notice. Please contact NSING and obtain + * the latest version of this software before placing orders. + + * Although NSING has attempted to provide accurate and reliable information, NSING assumes + * no responsibility for the accuracy and reliability of this software. + * + * It is the responsibility of the user of this software to properly design, program, and test + * the functionality and safety of any application made of this information and any resulting product. + * In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or + * consequential damages arising in any way out of the use of this software or the Product. + * + * NSING Products are neither intended nor warranted for usage in systems or equipment, any + * malfunction or failure of which may cause loss of human life, bodily injury or severe property + * damage. Such applications are deemed, "Insecure Usage". + * + * All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING + * harmless from and against all claims, costs, damages, and other liabilities, arising from or related + * to any customer's Insecure Usage. + + * Any express or implied warranty with regard to this software or the Product, including,but not + * limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement + * are disclaimed to the fullest extent permitted by law. + + * Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe + * or otherwise distribute this software for any purposes, in whole or in part. + * + * NSING products and technologies shall not be used for or incorporated into any products or systems + * whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. + * User shall comply with any applicable export control laws and regulations promulgated and administered by + * the governments of any countries asserting jurisdiction over the parties or transactions. + **/ + + +/** + * @file app_ns_ius.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef __APP_NS_IUS_H__ +#define __APP_NS_IUS_H__ + + +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration +#include "prf_types.h" +#include "prf.h" + +#if (BLE_APP_NS_IUS) + + +#define SERVICE_NS_IUS {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, 0x01,0x00, 0x11,0x11} +#define CHAR_NS_IUS_RC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x02,0x00, 0x11,0x11} +#define CHAR_NS_IUS_CC {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 ,0x03,0x00, 0x11,0x11} +/* Public typedef -----------------------------------------------------------*/ +enum +{ + NS_IUS_IDX_SVC, + NS_IUS_IDX_RC_CHAR, + NS_IUS_IDX_RC_VAL, + NS_IUS_IDX_RC_CFG, + NS_IUS_IDX_CC_CHAR, + NS_IUS_IDX_CC_VAL, + NS_IUS_IDX_CC_CFG, + NS_IUS_IDX_NB, +}; + +/* Public variables ---------------------------------------------------------*/ +extern struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB]; +extern const struct app_subtask_handlers ns_ius_app_handlers; + + +/* Public function prototypes -----------------------------------------------*/ +/** + * @brief SEND DATA THROUGH NS IUS SERVICE + **/ +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length); +/** + * @brief Add a NATIONS IMAGE UPDATE Service instance in the DB + **/ +void app_ns_ius_add_ns_ius(void); +/** + * @brief Initialize NATIONS IMAGE UPDATE Service Application + **/ +void app_ns_ius_init(void); + +#endif //BLE_APP_NS_IUS + + + + + + +#endif //__APP_NS_IUS_H__ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..218a3c8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/app_profile/rwapp_config.h @@ -0,0 +1,134 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" + +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if 0 +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + + + +#if defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 1 +#else // defined(CFG_APP_NS_IUS) +#define BLE_APP_NS_IUS 0 +#endif // defined(CFG_APP_NS_IUS) + + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/app_user_config.h new file mode 100644 index 0000000..64c95bb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/app_user_config.h @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ +#define CUSTOM_DEVICE_NAME "ImageUpdate" +#define CUSTOM_BLE_MAC_ADDRESS "\x8A\x22\x77\x44\x55\x66" + + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 64 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 40 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 64 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 40 ms.). */ + +#define CUSTOM_ADV_FAST_DURATION 0//30 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + + +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_DEVICE_INFORMATION_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +/// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +/// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 7.5 /**< Minimum connection interval (7.5 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 6 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (0) /**< Time of initiating event to update connection params (5 seconds). */ + +//forfiles config +#define CFG_APP_NS_IUS 1 + + +/* User config */ + +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 0 +#define NS_LOG_USART_ENABLE 0 +#define NS_LOG_RTT_ENABLE 0 + +#define NS_TIMER_ENABLE 0 + +#define FIRMWARE_VERSION "0.0.01" +#define HARDWARE_VERSION "0.0.01" + + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/ns_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/ns_ble.h new file mode 100644 index 0000000..03f6f7b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/ns_ble.h @@ -0,0 +1,398 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_H_ +#define APP_H_ + +/** + * @addtogroup APP + * @ingroup RICOW + * + * @brief Application entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_PRESENT) + +#include // Standard Integer Definition +#include "arch.h" // Platform Definitions +#include // Common BT Definitions + + +#include "gapc_task.h" // GAPC Definitions +#include "gattc_task.h" // GATTC Definitions + +#if (NVDS_SUPPORT) +#include "nvds.h" +#endif // (NVDS_SUPPORT) + + +/* Define ------------------------------------------------------------*/ + + + + +#define APP_ADV_DURATION_MAX (655) + +#define SECS_UNIT_1_25_MS (800) +#define SECS_UNIT_10MS (100) +#define SECS_TO_UNIT(sec,uint) ((sec)*(uint)) + +#define MSECS_UNIT_1_25_MS (1250) +#define MSECS_UNIT_10_MS (10000) +#define MSECS_TO_UNIT(msec,uint) ((msec*1000)/(uint)) + +/// Maximal length of the Device Name value +#define APP_DEVICE_NAME_MAX_LEN (18) +#define APP_MESH_DEMO_TYPE_LEN (1) + +/* + * MACROS + **/ + +#define APP_HANDLERS(subtask) {&subtask##_msg_handler_list[0], ARRAY_LEN(subtask##_msg_handler_list)} + +/* Typedef -----------------------------------------------------------*/ + +#if (NVDS_SUPPORT) +/// List of Application NVDS TAG identifiers +enum app_nvds_tag +{ + /// Device Name + NVDS_TAG_DEVICE_NAME = 0x02, + NVDS_LEN_DEVICE_NAME = 62, + + /// BD Address + NVDS_TAG_BD_ADDRESS = 0x01, + NVDS_LEN_BD_ADDRESS = 6, + + /// Local device Identity resolving key + NVDS_TAG_LOC_IRK = 0xA0, + NVDS_LEN_LOC_IRK = KEY_LEN, + + + + #if (BLE_APP_PRF) + /// BLE Application Advertising data + NVDS_TAG_APP_BLE_ADV_DATA = 0x0B, + NVDS_LEN_APP_BLE_ADV_DATA = 32, + + /// BLE Application Scan response data + NVDS_TAG_APP_BLE_SCAN_RESP_DATA = 0x0C, + NVDS_LEN_APP_BLE_SCAN_RESP_DATA = 32, + + /// Mouse Sample Rate + NVDS_TAG_MOUSE_SAMPLE_RATE = 0x38, + NVDS_LEN_MOUSE_SAMPLE_RATE = 1, + + /// Peripheral Bonded + NVDS_TAG_PERIPH_BONDED = 0x39, + NVDS_LEN_PERIPH_BONDED = 1, + + /// Mouse NTF Cfg + NVDS_TAG_MOUSE_NTF_CFG = 0x3A, + NVDS_LEN_MOUSE_NTF_CFG = 2, + + /// Mouse Timeout value + NVDS_TAG_MOUSE_TIMEOUT = 0x3B, + NVDS_LEN_MOUSE_TIMEOUT = 2, + + /// Peer Device BD Address + NVDS_TAG_PEER_BD_ADDRESS = 0x3C, + NVDS_LEN_PEER_BD_ADDRESS = 7, + + /// Mouse Energy Safe + NVDS_TAG_MOUSE_ENERGY_SAFE = 0x3D, + NVDS_LEN_MOUSE_SAFE_ENERGY = 2, + + /// EDIV (2bytes), RAND NB (8bytes), LTK (16 bytes), Key Size (1 byte) + NVDS_TAG_LTK = 0x3E, + NVDS_LEN_LTK = 28, + + /// PAIRING + NVDS_TAG_PAIRING = 0x3F, + NVDS_LEN_PAIRING = 54, + + /// Audio mode 0 task + NVDS_TAG_AM0_FIRST = 0x90, + NVDS_TAG_AM0_LAST = 0x9F, + + /// Peer device Resolving identity key (+identity address) + NVDS_TAG_PEER_IRK = 0xA1, + NVDS_LEN_PEER_IRK = sizeof(struct gapc_irk), + + //TODO +#endif //(BLE_APP_PRF) +}; +#endif // (NVDS_SUPPORT) + + +/// Advertising state machine +enum app_adv_state +{ + /// Advertising activity does not exists + APP_ADV_STATE_IDLE = 0, + #if BLE_APP_PRF + /// Creating advertising activity + APP_ADV_STATE_CREATING, + /// Setting advertising data + APP_ADV_STATE_SETTING_ADV_DATA, + /// Setting scan response data + APP_ADV_STATE_SETTING_SCAN_RSP_DATA, + + /// Advertising activity created + APP_ADV_STATE_CREATED, + /// Starting advertising activity + APP_ADV_STATE_STARTING, + /// Advertising activity started + APP_ADV_STATE_STARTED, + /// Stopping advertising activity + APP_ADV_STATE_STOPPING, + #endif //(BLE_APP_PRF) +}; + +enum app_adv_mode +{ + APP_ADV_MODE_IDLE = 0, + APP_ADV_MODE_DIRECTED_HIGH_DUTY, + APP_ADV_MODE_DIRECTED, + APP_ADV_MODE_FAST, + APP_ADV_MODE_SLOW, + +}; +typedef enum +{ + BLE_LSC_LSI_32000HZ = 0, + BLE_LSC_LSI_32768HZ, + BLE_LSC_LSI_28800HZ, + BLE_LSC_LSE_32768HZ +}ble_lsc_cfg_t; +/* Public define ------------------------------------------------------------*/ + +/// Structure containing information about the handlers for an application subtask +struct app_subtask_handlers +{ + /// Pointer to the message handler table + const struct ke_msg_handler *p_msg_handler_tab; + /// Number of messages handled + uint16_t msg_cnt; +}; + +/// Application environment structure +struct app_env_tag +{ + /// Connection handle + uint16_t conhdl; + /// Connection Index + uint8_t conidx; + + /// Advertising activity index + uint8_t adv_actv_idx; + /// Current advertising state (@see enum app_adv_state) + uint8_t adv_state; + /// Next expected operation completed event + uint8_t adv_op; + + /// Last initialized profile + uint8_t next_svc; + + /// Bonding status + bool bonded; + + /// Device Name length + uint8_t dev_name_len; + /// Device Name + uint8_t dev_name[APP_DEVICE_NAME_MAX_LEN]; + + /// Local device IRK + uint8_t loc_irk[KEY_LEN]; + + /// Secure Connections on current link + bool sec_con_enabled; + + /// Counter used to generate IRK + uint8_t rand_cnt; + + /// Advertising mode + uint8_t adv_mode; + /// Maximum device MTU size + uint16_t max_mtu; + + /// Demonstration type length + uint8_t demo_type_len; + /// Demonstration type + uint8_t demo_type; + + uint8_t manual_conn_param_update; + uint8_t manual_mtu_update; + ble_lsc_cfg_t lsc_cfg; + + uint8_t scan_actv_idx; + uint8_t init_actv_idx; +}; +struct ns_scan_params_t +{ + /// Initiating type (@see enum gapm_init_type) + uint8_t type; + // if enable scan + uint8_t scan_enable :1; + // if connect the device if match + uint8_t connect_enable :1; + /// if use coded phy mode + uint8_t phy_coded_enable :1; + /// Properties for the scan active mode, enable will require scan respond data + uint8_t prop_active_enable :1; + /// Duplicate packet filtering policy + uint8_t dup_filt_pol :2; + /// Scan interval + uint16_t scan_intv; + /// Scan window + uint16_t scan_wd; + /// Scan duration (in unit of 10ms). 0 means that the controller will scan continuously until + /// reception of a stop command from the application + uint16_t duration; + /// Scan period (in unit of 1.28s). Time interval betweem two consequent starts of a scan duration + /// by the controller. 0 means that the scan procedure is not periodic + uint16_t period; + +// void (*ble_scan_state_handler)(enum scan_state_t); +// void (*ble_scan_data_handler)(struct gapm_ext_adv_report_ind const*); + +// enum scan_filter_type filter_type; +// const uint8_t *filter_data; + +}; +/* Public variables ---------------------------------------------------------*/ + +/// Application environment +extern struct app_env_tag app_env; +extern struct ns_scan_params_t scan_env; +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize the BLE demo application. + **/ +void app_init(void); + +/** + * @brief Add a required service in the database + **/ +bool app_add_svc(void); + +/** + * @brief Retrieve device name + * + * @param[out] Pointer at which device name will be returned + * + * @return Name length + **/ +uint8_t app_get_dev_name(uint8_t* p_name); + +#if (BLE_APP_PRF) +/** + * @brief + **/ +void app_adv_fsm_next(void); + +/** + * @brief Send to request to update the connection parameters + **/ +void ns_ble_update_param(struct gapc_conn_param *p_conn_param); + +/** + * @brief Send a disconnection request + **/ +void app_disconnect(void); + +/** + * @brief Start/stop advertising + * + * @param[in] start True if advertising has to be started, else false + **/ + +void app_update_adv_state(bool start); + +/** + * @brief delete advertising + * + * @param[in] none + **/ + +void app_delete_advertising(void); +/** + * @brief Return if the device is currently bonded + **/ +bool app_sec_get_bond_status(void); + +/** + * @brief set mtu + * + * @param[in] none + **/ +void ns_ble_mtu_set(uint16_t mtu); + +/// @} APP +/// +#endif //(BLE_APP_PRF) +#endif //(BLE_APP_PRESENT) + +#endif // APP_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/ns_ble_task.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/ns_ble_task.h new file mode 100644 index 0000000..5703c1f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/inc/ns_ble_task.h @@ -0,0 +1,173 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble_task.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_TASK_H_ +#define APP_TASK_H_ + +/** + * @addtogroup APPTASK Task + * @ingroup APP + * @brief Routes ALL messages to/from APP block. + * + * The APPTASK is the block responsible for bridging the final application with the + * RWBLE software host stack. It communicates with the different modules of the BLE host, + * i.e. @ref SMP, @ref GAP and @ref GATT. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_PRESENT) + +#include // Standard Integer +#include "rwip_task.h" // Task definitions +#include "ke_task.h" // Kernel Task + +/* Define ------------------------------------------------------------*/ + +/// Number of APP Task Instances +#define APP_IDX_MAX (1) + + + +/* Typedef -----------------------------------------------------------*/ + + /// Process event response +enum process_event_response +{ + /// Handled + PR_EVENT_HANDLED = 0, + + /// Unhandled + PR_EVENT_UNHANDLED +}; + + +/// States of APP task +enum app_state +{ + /// Initialization state + APP_INIT, + /// Database create state + APP_CREATE_DB, + /// Ready State + APP_READY, + /// Connected state + APP_CONNECTED, + + /// Number of defined states. + APP_STATE_MAX +}; + + +/// APP Task messages +/*@TRACE*/ +enum app_msg_id +{ + APP_DUMMY_MSG = TASK_FIRST_MSG(TASK_ID_APP), + + #if (BLE_APP_PRF) + #if (BLE_APP_HT) + /// Timer used to refresh the temperature measurement value + APP_HT_MEAS_INTV_TIMER, + #endif //(BLE_APP_HT) + + #if (BLE_APP_HID) + /// Timer used to disconnect the moue if no activity is detecter + APP_HID_MOUSE_TIMEOUT_TIMER, + #endif //(BLE_APP_HID) + #endif //(BLE_APP_PRF) + + + //user event + APP_PARAMS_UPDATE_EVT, + APP_CUSTS_TEST_EVT, + APP_HID_DATA_PROCESS_EVT, + APP_DFU_BLE_RESET_TIMER, + +#if (NS_TIMER_ENABLE) + /*ns timer*/ + APP_CANCEL_TIMER, + APP_MODIFY_TIMER, + //Do not alter the order of the next messages + //they are considered a range + NS_TIMER_API_MES0, + NS_TIMER_API_MES1=NS_TIMER_API_MES0+1, + NS_TIMER_API_MES2=NS_TIMER_API_MES0+2, + NS_TIMER_API_MES3=NS_TIMER_API_MES0+3, + NS_TIMER_API_MES4=NS_TIMER_API_MES0+4, + NS_TIMER_API_MES5=NS_TIMER_API_MES0+5, + NS_TIMER_API_MES6=NS_TIMER_API_MES0+6, + NS_TIMER_API_MES7=NS_TIMER_API_MES0+7, + NS_TIMER_API_MES8=NS_TIMER_API_MES0+8, + NS_TIMER_API_MES9=NS_TIMER_API_MES0+9, + NS_TIMER_API_LAST_MES=NS_TIMER_API_MES9, +#endif //NS_TIMER_ENABLE + +}; + + +/* Public variables ---------------------------------------------------------*/ + +/// @} APPTASK + +#endif //(BLE_APP_PRESENT) + +#endif // APP_TASK_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/readme.txt new file mode 100644 index 0000000..b9186c1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/readme.txt @@ -0,0 +1,22 @@ + +1. Function description + + 1. This routine shows the Image Update application layer of a single bank in OTA upgrade. + 2. Realize the function of upgrading the Image Update layer in a single bank. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Bluetooth BLE name: ImageUpdate + + + usage method: + Refer to Chapter 7.4 of the Firmware Upgrade User's Guide + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/app_profile/app_ns_ius.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/app_profile/app_ns_ius.c new file mode 100644 index 0000000..5be3f42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/app_profile/app_ns_ius.c @@ -0,0 +1,243 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ns_ius.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + */ +/* Includes ------------------------------------------------------------------*/ +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_NS_IUS) + +#include "app_ns_ius.h" +#include +#include "ns_iuss.h" +#include "ns_iuss_task.h" +#include "ns_dfu_ble.h" +#include "attm.h" +#include "ke_task.h" +#include "gapc.h" +#include "gapc_task.h" +#include "gattc_task.h" +#include "attm_db.h" +#include "prf_utils.h" +#include "ke_mem.h" +#include "co_utils.h" +#include "ke_msg.h" +#include "ns_ble.h" +#include "ns_log.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +struct attm_desc_128 ns_ius_att_db[NS_IUS_IDX_NB] = +{ + [NS_IUS_IDX_SVC] = {{0x00,0x28}, PERM(RD, ENABLE),0,0}, + + [NS_IUS_IDX_RC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE),0, 0}, + [NS_IUS_IDX_RC_VAL] = {CHAR_NS_IUS_RC, PERM(WRITE_COMMAND, ENABLE), PERM_VAL(UUID_LEN, 0x02), 247}, + [NS_IUS_IDX_RC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, + + [NS_IUS_IDX_CC_CHAR] = {{0x03,0x28}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0 }, + [NS_IUS_IDX_CC_VAL] = {CHAR_NS_IUS_CC, PERM(WRITE_REQ, ENABLE) | PERM(NTF, ENABLE) , PERM(RI, ENABLE)| PERM_VAL(UUID_LEN, 0x02), 20 }, + [NS_IUS_IDX_CC_CFG] = {{0x02,0x29}, PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE), 0, 0}, +}; + + + + + +static bool notification_enable = false; + + + + + +static int ns_ius_val_write_ind_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + const struct ns_ius_val_write_ind *p_param = (const struct ns_ius_val_write_ind *)param; + + switch (p_param->handle) + { + case NS_IUS_IDX_CC_CFG:{ + + if(p_param->length == 2) + { + uint16_t cfg_value = p_param->value[0] + p_param->value[1]; + + if(cfg_value == PRF_CLI_START_NTF) + { + notification_enable = true; + } + else if(cfg_value == PRF_CLI_STOP_NTFIND) + { + notification_enable = false; + } + NS_LOG_DEBUG("notification_enable %d\r\n",notification_enable); + } + + }break; + + + case NS_IUS_IDX_CC_VAL:{ + uint8_t output[20]; + uint8_t output_len = 0; + ns_dfu_ble_handler_cc(p_param->value, p_param->length, output, &output_len); + if(output_len)ns_ble_ius_app_cc_send(output, output_len); + }break; + + case NS_IUS_IDX_RC_VAL:{ + ns_dfu_ble_handler_rc(p_param->value, p_param->length); + }break; + default: + break; + + } + + return KE_MSG_CONSUMED; +} + + + +void ns_ble_ius_app_cc_send(uint8_t *p_data, uint16_t length) +{ + uint8_t state = ke_state_get(ns_ble_ius_task); + if (state == NS_IUS_BUSY || notification_enable == false) + { + return; + } + ke_state_set(ns_ble_ius_task, NS_IUS_BUSY); + + struct ns_ius_env_tag *ns_ius_env = PRF_ENV_GET(NS_IUS, ns_ius); + struct gattc_send_evt_cmd * req = KE_MSG_ALLOC_DYN(GATTC_SEND_EVT_CMD, KE_BUILD_ID(TASK_GATTC, app_env.conidx), ns_ius_env->prf_env.prf_task, gattc_send_evt_cmd, length); + req->operation = GATTC_NOTIFY; + req->handle = ns_ius_env->shdl + NS_IUS_IDX_CC_VAL; + req->length = length; + memcpy(req->value, p_data, length); + ke_msg_send(req); +} + + + +static int ns_ius_disconnect_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + notification_enable = false; + return KE_MSG_CONSUMED; +} + + +const struct ke_msg_handler ns_ius_app_msg_handler_list[] = +{ + {NS_IUS_VAL_WRITE_IND, ns_ius_val_write_ind_handler}, + {NS_IUS_DISCONNECT, ns_ius_disconnect_handler}, +}; + + +const struct app_subtask_handlers ns_ius_app_handlers = APP_HANDLERS(ns_ius_app); + + + + + + + +void app_ns_ius_add_ns_ius(void) +{ + Qflash_Init(); + + struct ns_ius_db_cfg *db_cfg; + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, + TASK_APP, + gapm_profile_task_add_cmd, + sizeof(struct ns_ius_db_cfg)); + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_NS_IUS; + req->app_task = TASK_APP; + req->start_hdl = 0; + db_cfg = (struct ns_ius_db_cfg *) req->param; + db_cfg->att_tbl = NULL; + db_cfg->cfg_flag = 0; + db_cfg->features = 0; + ke_msg_send(req); + + app_ns_ius_init(); +} + +void app_ns_ius_init(void) +{ + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_NS_IUS; + get_func.prf_itf_get_func = ns_ius_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + + +#endif //BLE_APP_NS_IUS + + +/// @} APP + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/main.c new file mode 100644 index 0000000..33da605 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/main.c @@ -0,0 +1,111 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "dfu_crc.h" +#include "ble_stack_common.h" +#include "ns_ble.h" +#include "prf.h" +#include "ns_dfu_boot.h" + + +/** + * @brief Set the bootsetting to default value, so next time boot up will not goin to imageupdate again. + * @param[in] none. + * @return none + */ +static void bootsetting_reset(void) +{ + NS_Bootsetting_t m_ns_bootsetting; + memcpy(&m_ns_bootsetting,&ns_bootsetting,sizeof(NS_Bootsetting_t)); + Qflash_Init(); + if(ns_bootsetting.app1.crc == dfu_crc32((uint8_t *)((uint32_t *)ns_bootsetting.app1.start_address), ns_bootsetting.app1.size) ) + { + m_ns_bootsetting.app1.activation = NS_BOOTSETTING_ACTIVATION_YES; + m_ns_bootsetting.ImageUpdate.activation = NS_BOOTSETTING_ACTIVATION_NO; + } + else if(ns_bootsetting.app2.crc == dfu_crc32((uint8_t *)((uint32_t *)ns_bootsetting.app2.start_address), ns_bootsetting.app2.size) ) + { + m_ns_bootsetting.app2.activation = NS_BOOTSETTING_ACTIVATION_YES; + m_ns_bootsetting.ImageUpdate.activation = NS_BOOTSETTING_ACTIVATION_NO; + } + if(m_ns_bootsetting.ImageUpdate.activation == NS_BOOTSETTING_ACTIVATION_NO) + { + m_ns_bootsetting.crc = dfu_crc32((uint8_t *)&m_ns_bootsetting.crc + 4, sizeof(NS_Bootsetting_t) - 4); + Qflash_Erase_Sector(NS_BOOTSETTING_START_ADDRESS); + Qflash_Write(NS_BOOTSETTING_START_ADDRESS, (uint8_t *)&m_ns_bootsetting, sizeof(NS_Bootsetting_t)); + } +} + +int main(void) +{ + bootsetting_reset(); + + app_init(); + prf_init(RWIP_INIT); + + while(1) + { + rwip_schedule(); + } +} + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/ns_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/ns_ble.c new file mode 100644 index 0000000..56be34c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/ns_ble.c @@ -0,0 +1,839 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_PRESENT) + +#include +#include +#include "ns_ble_task.h" // Application task Definition +#include "ns_ble.h" // Application Definition +#include "gap.h" // GAP Definition +#include "gapm_task.h" // GAP Manager Task API +#include "gapc_task.h" // GAP Controller Task API +#include "gapm_int.h" +#include "co_math.h" // Common Maths Definition +#include "ble_stack_common.h" +#if (BLE_APP_SEC) +#include "ns_sec.h" // Application security Definition +#endif // (BLE_APP_SEC) + +#if (BLE_APP_HT) +#include "app_ht.h" // Health Thermometer Application Definitions +#endif //(BLE_APP_HT) + +#if (BLE_APP_DIS) +#include "app_dis.h" // Device Information Service Application Definitions +#endif //(BLE_APP_DIS) + +#if (BLE_APP_BATT) +#include "app_batt.h" // Battery Application Definitions +#endif //(BLE_APP_DIS) + +#if (BLE_APP_HID) +#include "app_hid.h" // HID Application Definitions +#endif //(BLE_APP_HID) + + +#if (BLE_RDTSS_SERVER) +#include "app_rdtss.h" // RDTSS Application Definitions +#endif //(BLE_RDTSS_SERVER) + +#if (BLE_APP_NS_IUS) +#include "app_ns_ius.h" // NS_IUS Application Definitions +#endif //(BLE_APP_NS_IUS) + + +#if (NS_TIMER_ENABLE) +#include "ns_timer.h" +#endif //NS_TIMER_ENABLE + +#include "ke_timer.h" + +#include +#include "global_func.h" + +/* Define ------------------------------------------------------------*/ +/// Default Device Name +#ifdef CUSTOM_DEVICE_NAME +#define APP_DFLT_DEVICE_NAME CUSTOM_DEVICE_NAME +#define APP_DFLT_DEVICE_NAME_LEN (sizeof(CUSTOM_DEVICE_NAME)-1) +#elif DEFAULT_DEVICE_NAME +#define APP_DFLT_DEVICE_NAME DEFAULT_DEVICE_NAME +#define APP_DFLT_DEVICE_NAME_LEN (sizeof(DEFAULT_DEVICE_NAME)-1) +#endif + + /** + * Define advertise data + */ +#ifdef CUSTOM_USER_ADVERTISE_DATA +#define USER_ADVERTISE_DATA CUSTOM_USER_ADVERTISE_DATA +#define USER_ADVERTISE_DATA_LEN CUSTOM_USER_ADVERTISE_DATA_LEN +#elif DEFAULT_ADVERTISE_DATA +#define USER_ADVERTISE_DATA DEFAULT_USER_ADVERTISE_DATA +#define USER_ADVERTISE_DATA_LEN DEFAULT_USER_ADVERTISE_DATA_LEN +#endif + +/** + * Default Scan response data + */ +#ifdef CUSTOM_USER_ADV_SCNRSP_DATA +#define USER_ADV_SCNRSP_DATA CUSTOM_USER_ADV_SCNRSP_DATA +#define USER_ADV_SCNRSP_DATA_LEN CUSTOM_USER_ADV_SCNRSP_DATA_LEN +#elif DEFAULT_USER_ADV_SCNRSP_DATA +#define USER_ADV_SCNRSP_DATA DEFAULT_USER_ADV_SCNRSP_DATA +#define USER_ADV_SCNRSP_DATA_LEN DEFAULT_USER_ADV_SCNRSP_DATA_LEN +#endif + + + +/** + * Advertising Parameters + */ +#if (BLE_APP_HID) +/// Default Advertising duration - 30s (in multiple of 10ms) +#define APP_DFLT_ADV_DURATION (3000) +#endif //(BLE_APP_HID) +/// Advertising channel map - 37, 38, 39 +#define APP_ADV_CHMAP (0x07) +/// Advertising minimum interval - 40ms (64*0.625ms) +#define APP_ADV_INT_MIN (64) +/// Advertising maximum interval - 40ms (64*0.625ms) +#define APP_ADV_INT_MAX (64) +/// Fast advertising interval +#define APP_ADV_FAST_INT (32) + +/* Private define ------------------------------------------------------------*/ + +typedef void (*app_add_svc_func_t)(void); + +/* Typedef -----------------------------------------------------------*/ + +/// List of service to add in the database +enum app_svc_list +{ + #if (BLE_APP_HT) + APP_SVC_HTS, + #endif //(BLE_APP_HT) + #if (BLE_APP_DIS) + APP_SVC_DIS, + #endif //(BLE_APP_DIS) + #if (BLE_APP_BATT) + APP_SVC_BATT, + #endif //(BLE_APP_BATT) + #if (BLE_APP_HID) + APP_SVC_HIDS, + #endif //(BLE_APP_HID) + #if (BLE_RDTSS_SERVER) + APP_SVC_RDTS, + #endif //(BLE_RDTSS_SERVER) + #if (BLE_APP_NS_IUS) + APP_SVC_NS_IUS, + #endif //(BLE_APP_NS_IUS) + APP_SVC_LIST_STOP, +}; + +/* + * LOCAL VARIABLES DEFINITIONS + **/ + +/// Application Task Descriptor +extern const struct ke_task_desc TASK_DESC_APP_M; + +/// List of functions used to create the database +static const app_add_svc_func_t app_add_svc_func_list[APP_SVC_LIST_STOP] = +{ + #if (BLE_APP_HT) + (app_add_svc_func_t)app_ht_add_hts, + #endif //(BLE_APP_HT) + #if (BLE_APP_DIS) + (app_add_svc_func_t)app_dis_add_dis, + #endif //(BLE_APP_DIS) + #if (BLE_APP_BATT) + (app_add_svc_func_t)app_batt_add_bas, + #endif //(BLE_APP_BATT) + #if (BLE_APP_HID) + (app_add_svc_func_t)app_hid_add_hids, + #endif //(BLE_APP_HID) + #if (BLE_RDTSS_SERVER) + (app_add_svc_func_t)app_rdtss_add_rdts, + #endif //(BLE_RDTSS_SERVER) + #if (BLE_APP_NS_IUS) + (app_add_svc_func_t)app_ns_ius_add_ns_ius, + #endif //(BLE_APP_NS_IUS) +}; + +/* + * GLOBAL VARIABLE DEFINITIONS + **/ + +/// Application Environment Structure +struct app_env_tag app_env; +struct ns_scan_params_t scan_env; +/* + * LOCAL FUNCTION DEFINITIONS + **/ + +#if (BLE_APP_PRF) + +static void app_build_adv_data(uint16_t max_length, uint16_t *p_length, uint8_t *p_buf) +{ + // Remaining Length + uint8_t rem_len = max_length; + + #ifdef CUSTOM_USER_ADVERTISE_DATA + ASSERT_ERR( CUSTOM_USER_ADVERTISE_DATA >= rem_len ); + + memcpy(p_buf,CUSTOM_USER_ADVERTISE_DATA, CUSTOM_USER_ADVERTISE_DATA_LEN); + *p_length += CUSTOM_USER_ADVERTISE_DATA_LEN; + p_buf += CUSTOM_USER_ADVERTISE_DATA_LEN; + + #elif DEFAULT_ADVERTISE_DATA + ASSERT_ERR( DEFAULT_ADVERTISE_DATA >= rem_len ); + + memcpy(p_buf,DEFAULT_ADVERTISE_DATA,DEFAULT_ADVERTISE_DATA_LEN); + *p_length += DEFAULT_ADVERTISE_DATA_LEN; + p_buf += DEFAULT_ADVERTISE_DATA_LEN; + + #endif + + // Sanity check + ASSERT_ERR(rem_len >= max_length); + + // Get remaining space in the Advertising Data - 2 bytes are used for name length/flag + rem_len -= *p_length; + + // Check if additional data can be added to the Advertising data - 2 bytes needed for type and length + if (rem_len > 2) + { + uint8_t dev_name_length = co_min(app_env.dev_name_len, (rem_len - 2)); + + // Device name length + *p_buf = dev_name_length + 1; + // Device name flag (check if device name is complete or not) + *(p_buf + 1) = (dev_name_length == app_env.dev_name_len) ? '\x09' : '\x08'; + // Copy device name + memcpy(p_buf + 2, app_env.dev_name, dev_name_length); + + // Update advertising data length + *p_length += (dev_name_length + 2); + } +} + + void app_start_advertising_with_mode(void) +{ + // Prepare the GAPM_ACTIVITY_START_CMD message + struct gapm_activity_start_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_START_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_start_cmd); + + p_cmd->operation = GAPM_START_ACTIVITY; + p_cmd->actv_idx = app_env.adv_actv_idx; + + switch (app_env.adv_mode) + { + case APP_ADV_MODE_DIRECTED_HIGH_DUTY: + p_cmd->u_param.adv_add_param.duration = SECS_TO_UNIT(CUSTOM_ADV_FAST_DURATION, SECS_UNIT_10MS); + break; + case APP_ADV_MODE_DIRECTED: + p_cmd->u_param.adv_add_param.duration = SECS_TO_UNIT(CUSTOM_ADV_FAST_DURATION, SECS_UNIT_10MS); + break; + case APP_ADV_MODE_FAST: + p_cmd->u_param.adv_add_param.duration = SECS_TO_UNIT(CUSTOM_ADV_FAST_DURATION, SECS_UNIT_10MS); + break; + case APP_ADV_MODE_SLOW: + p_cmd->u_param.adv_add_param.duration = SECS_TO_UNIT(CUSTOM_ADV_SLOW_DURATION, SECS_UNIT_10MS); + break; + default: + p_cmd->u_param.adv_add_param.duration = 0; + break; + } + + p_cmd->u_param.adv_add_param.max_adv_evt = 0; + + // Send the message + ke_msg_send(p_cmd); + + // Keep the current operation + app_env.adv_state = APP_ADV_STATE_STARTING; + // And the next expected operation code for the command completed event + app_env.adv_op = GAPM_START_ACTIVITY; + + +} + + + void app_stop_advertising(void) +{ + + // Prepare the GAPM_ACTIVITY_STOP_CMD message + struct gapm_activity_stop_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_STOP_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_stop_cmd); + // Fill the allocated kernel message + p_cmd->operation = GAPM_STOP_ACTIVITY; + p_cmd->actv_idx = app_env.adv_actv_idx; + + // Send the message + ke_msg_send(p_cmd); + + // Update advertising state + app_env.adv_state = APP_ADV_STATE_STOPPING; + // And the next expected operation code for the command completed event + app_env.adv_op = GAPM_STOP_ACTIVITY; +} + + +static void app_set_adv_data(void) +{ + + // Prepare the GAPM_SET_ADV_DATA_CMD message + struct gapm_set_adv_data_cmd *p_cmd = KE_MSG_ALLOC_DYN(GAPM_SET_ADV_DATA_CMD, + TASK_GAPM, TASK_APP, + gapm_set_adv_data_cmd, + ADV_DATA_LEN); + // Fill the allocated kernel message + p_cmd->operation = GAPM_SET_ADV_DATA; + p_cmd->actv_idx = app_env.adv_actv_idx; + + p_cmd->length = 0; + // GAP will use 3 bytes for the AD Type + app_build_adv_data(ADV_DATA_LEN - 3, &p_cmd->length, &p_cmd->data[0]); + + // Send the message + ke_msg_send(p_cmd); + + // Update advertising state + app_env.adv_state = APP_ADV_STATE_SETTING_ADV_DATA; + // And the next expected operation code for the command completed event + app_env.adv_op = GAPM_SET_ADV_DATA; +} + +static void app_set_scan_rsp_data(void) +{ + // Prepare the GAPM_SET_ADV_DATA_CMD message + struct gapm_set_adv_data_cmd *p_cmd = KE_MSG_ALLOC_DYN(GAPM_SET_ADV_DATA_CMD, + TASK_GAPM, TASK_APP, + gapm_set_adv_data_cmd, + ADV_DATA_LEN); + // Fill the allocated kernel message + p_cmd->operation = GAPM_SET_SCAN_RSP_DATA; + p_cmd->actv_idx = app_env.adv_actv_idx; + + p_cmd->length = USER_ADV_SCNRSP_DATA_LEN; + memcpy(&p_cmd->data[0], USER_ADV_SCNRSP_DATA, USER_ADV_SCNRSP_DATA_LEN); + + // Send the message + ke_msg_send(p_cmd); + + // Update advertising state + app_env.adv_state = APP_ADV_STATE_SETTING_SCAN_RSP_DATA; + // And the next expected operation code for the command completed event + app_env.adv_op = GAPM_SET_SCAN_RSP_DATA; +} + +#endif //(BLE_APP_PRF) + + void app_send_gapm_reset_cmd(void) +{ + // Reset the stack + struct gapm_reset_cmd *p_cmd = KE_MSG_ALLOC(GAPM_RESET_CMD, + TASK_GAPM, TASK_APP, + gapm_reset_cmd); + + p_cmd->operation = GAPM_RESET; + ke_msg_send(p_cmd); +} + + + +void ns_ble_lsc_config(ble_lsc_cfg_t lsc_set) +{ + //Config the LSC for stack + if(lsc_set == BLE_LSC_LSE_32768HZ) + { + //enable LSE and select LSC as LSE + *(uint32_t*)0x40011008 |= 0xF00; + RCC->LSCTRL |= RCC_LSCTRL_LSEEN; + while(!(RCC->LSCTRL & RCC_LSCTRL_LSERD)); + RCC->LSCTRL |= RCC_LSCTRL_LSXSEL_LSE; + + g_lsi_1_syscle_cal_value = 1000; + //lse frequency 32768 + g_lsi_1_syscle_cnt_value = 976; //32000000/32768 = 976.56 //must fixed + } + else + { + //LSC select LSI + RCC->LSCTRL |= RCC_LSCTRL_LSIEN; + while(!(RCC->LSCTRL & RCC_LSCTRL_LSIRD)); + RCC->LSCTRL &= ~RCC_LSCTRL_LSXSEL_LSE; + /* set lsi frequency, (32m/lsc_freq) 32k:1000 , 28.8k 1111.11 , 32.768: 976.56 */ + /* g_lsi_1_syscle_cal_value = 32000000/lsc_freq; */ + switch (lsc_set) + { + case BLE_LSC_LSI_32768HZ: + g_lsi_1_syscle_cal_value = 976; + break; + case BLE_LSC_LSI_28800HZ: + g_lsi_1_syscle_cal_value = 1111; + break; + case BLE_LSC_LSI_32000HZ: + default: + g_lsi_1_syscle_cal_value = 1000; + break; + } + g_lsi_1_syscle_cnt_value = calib_lsi_clk(); //take 7.5ms + } +} + + + +/* + * GLOBAL FUNCTION DEFINITIONS + **/ +extern struct bd_addr g_co_default_bdaddr; +void app_init() +{ + uint8_t *p_mac = SystemGetMacAddr(); + uint8_t dfu_mac[BD_ADDR_LEN]; + // Reset the application manager environment + memset(&app_env, 0, sizeof(app_env)); + + app_env.scan_actv_idx = 0xff; + app_env.adv_actv_idx = 0xff; + app_env.init_actv_idx = 0xff; + + app_env.lsc_cfg = BLE_LSC_LSI_32000HZ; + ns_ble_lsc_config(app_env.lsc_cfg); + NS_BLE_STACK_INIT(); + + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dfu_mac,p_mac, BD_ADDR_LEN); + dfu_mac[0]++; + memcpy(g_co_default_bdaddr.addr, dfu_mac , BD_ADDR_LEN); + } + else{ + memcpy(g_co_default_bdaddr.addr, CUSTOM_BLE_MAC_ADDRESS, 6); + } + + // Create APP task + ke_task_create(TASK_APP, &TASK_DESC_APP_M); + + // Initialize Task state + ke_state_set(TASK_APP, APP_INIT); + + + #if (NVDS_SUPPORT) + // Get the Device Name to add in the Advertising Data (Default one or NVDS one) + app_env.dev_name_len = APP_DEVICE_NAME_MAX_LEN; + if (nvds_get(NVDS_TAG_DEVICE_NAME, &(app_env.dev_name_len), app_env.dev_name) != NVDS_OK) + #endif //(NVDS_SUPPORT) + { + // Get default Device Name (No name if not enough space) + memcpy(app_env.dev_name, APP_DFLT_DEVICE_NAME, APP_DFLT_DEVICE_NAME_LEN); + app_env.dev_name_len = APP_DFLT_DEVICE_NAME_LEN; + + // TODO update this value per profiles + } + + /*------------------------------------------------------ + * INITIALIZE ALL MODULES + *------------------------------------------------------*/ + + // load device information: + + #if (BLE_APP_SEC) + // Security Module + app_sec_init(); + #endif // (BLE_APP_SEC) + + #if (BLE_APP_HT) + // Health Thermometer Module + app_ht_init(); + #endif //(BLE_APP_HT) + + #if (BLE_APP_DIS) + // Device Information Module + app_dis_init(); + #endif //(BLE_APP_DIS) + + #if (BLE_APP_HID) + // HID Module + app_hid_init(); + #endif //(BLE_APP_HID) + + #if (BLE_APP_BATT) + // Battery Module + app_batt_init(); + #endif //(BLE_APP_BATT) + + + + #if (BLE_RDTSS_SERVER) + // rdtss Module + app_rdtss_init(); + #endif //(BLE_RDTSS_SERVER) + + #if (BLE_APP_NS_IUS) + // DFU OTA Service + app_ns_ius_init(); + #endif //(BLE_APP_NS_IUS) + + // Reset the stack + app_send_gapm_reset_cmd(); +} + +bool app_add_svc(void) +{ + // Indicate if more services need to be added in the database + bool more_svc = false; + // Check if another should be added in the database + if (app_env.next_svc != APP_SVC_LIST_STOP) + { + ASSERT_INFO(app_add_svc_func_list[app_env.next_svc] != NULL, app_env.next_svc, 1); + + // Call the function used to add the required service + app_add_svc_func_list[app_env.next_svc](); + + // Select following service to add + app_env.next_svc++; + more_svc = true; + } + + return more_svc; +} + +uint8_t app_get_dev_name(uint8_t* name) +{ + // copy name to provided pointer + memcpy(name, app_env.dev_name, app_env.dev_name_len); + // return name length + return app_env.dev_name_len; +} + +#if (BLE_APP_PRF) +void app_disconnect(void) +{ + struct gapc_disconnect_cmd *p_cmd = KE_MSG_ALLOC(GAPC_DISCONNECT_CMD, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_disconnect_cmd); + + p_cmd->operation = GAPC_DISCONNECT; + p_cmd->reason = CO_ERROR_REMOTE_USER_TERM_CON; + + // Send the message + ke_msg_send(p_cmd); +} + + + + void app_create_advertising_with_mode(void) +{ + if (app_env.adv_state == APP_ADV_STATE_IDLE) + { + // Prepare the GAPM_ACTIVITY_CREATE_CMD message + struct gapm_activity_create_adv_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_CREATE_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_create_adv_cmd); + + // Set operation code + p_cmd->operation = GAPM_CREATE_ADV_ACTIVITY; + + // Fill the allocated kernel message + p_cmd->own_addr_type = GAPM_STATIC_ADDR; + p_cmd->adv_param.type = GAPM_ADV_TYPE_LEGACY; + p_cmd->adv_param.prop = GAPM_ADV_PROP_UNDIR_CONN_MASK; + p_cmd->adv_param.filter_pol = ADV_ALLOW_SCAN_ANY_CON_ANY; + p_cmd->adv_param.prim_cfg.chnl_map = APP_ADV_CHMAP; + p_cmd->adv_param.prim_cfg.phy = GAP_PHY_LE_1MBPS; + + + switch (app_env.adv_mode) + { + case APP_ADV_MODE_DIRECTED_HIGH_DUTY: + case APP_ADV_MODE_DIRECTED: + case APP_ADV_MODE_FAST: + p_cmd->adv_param.prim_cfg.adv_intv_min = CUSTOM_ADV_FAST_INTERVAL; + p_cmd->adv_param.prim_cfg.adv_intv_max = CUSTOM_ADV_FAST_INTERVAL; + p_cmd->adv_param.disc_mode = GAPM_ADV_MODE_GEN_DISC; + break; + case APP_ADV_MODE_SLOW: + p_cmd->adv_param.prim_cfg.adv_intv_min = CUSTOM_ADV_SLOW_INTERVAL; + p_cmd->adv_param.prim_cfg.adv_intv_max = CUSTOM_ADV_SLOW_INTERVAL; + p_cmd->adv_param.disc_mode = GAPM_ADV_MODE_GEN_DISC; + break; + default: + break; + } + + // Send the message + ke_msg_send(p_cmd); + + // Keep the current operation + app_env.adv_state = APP_ADV_STATE_CREATING; + // And the next expected operation code for the command completed event + app_env.adv_op = GAPM_CREATE_ADV_ACTIVITY; + } +} + + void app_create_advertising(void) +{ + if (app_env.adv_state == APP_ADV_STATE_IDLE) + { + // Prepare the GAPM_ACTIVITY_CREATE_CMD message + struct gapm_activity_create_adv_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_CREATE_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_create_adv_cmd); + + // Set operation code + p_cmd->operation = GAPM_CREATE_ADV_ACTIVITY; + + // Fill the allocated kernel message + p_cmd->own_addr_type = GAPM_STATIC_ADDR; + p_cmd->adv_param.type = GAPM_ADV_TYPE_LEGACY; + p_cmd->adv_param.prop = GAPM_ADV_PROP_UNDIR_CONN_MASK; + p_cmd->adv_param.filter_pol = ADV_ALLOW_SCAN_ANY_CON_ANY; + p_cmd->adv_param.prim_cfg.chnl_map = APP_ADV_CHMAP; + p_cmd->adv_param.prim_cfg.phy = GAP_PHY_LE_1MBPS; + + #if (BLE_APP_HID) + p_cmd->adv_param.disc_mode = GAPM_ADV_MODE_LIM_DISC; + + /* + * If the peripheral is already bonded with a central device, use the direct advertising + * procedure (BD Address of the peer device is stored in NVDS. + */ + if (app_sec_get_bond_status()) + { + p_cmd->adv_param.prim_cfg.adv_intv_min = APP_ADV_FAST_INT; + p_cmd->adv_param.prim_cfg.adv_intv_max = APP_ADV_FAST_INT; + } + else + { + p_cmd->adv_param.prim_cfg.adv_intv_min = APP_ADV_INT_MIN; + p_cmd->adv_param.prim_cfg.adv_intv_max = APP_ADV_INT_MAX; + } + #else //(BLE_APP_HID) + p_cmd->adv_param.disc_mode = GAPM_ADV_MODE_GEN_DISC; + p_cmd->adv_param.prim_cfg.adv_intv_min = APP_ADV_INT_MIN; //app_env.adv_interval; //APP_ADV_INT_MIN; + p_cmd->adv_param.prim_cfg.adv_intv_max = APP_ADV_INT_MAX; //app_env.adv_interval; //APP_ADV_INT_MAX; + #endif //(BLE_APP_HID) + + + // Send the message + ke_msg_send(p_cmd); + + // Keep the current operation + app_env.adv_state = APP_ADV_STATE_CREATING; + // And the next expected operation code for the command completed event + app_env.adv_op = GAPM_CREATE_ADV_ACTIVITY; + } +} + +void app_delete_advertising(void) +{ + + // Prepare the GAPM_ACTIVITY_CREATE_CMD message + struct gapm_activity_delete_cmd *p_cmd = KE_MSG_ALLOC(GAPM_ACTIVITY_DELETE_CMD, + TASK_GAPM, TASK_APP, + gapm_activity_delete_cmd); + // Set operation code + p_cmd->operation = GAPM_DELETE_ALL_ACTIVITIES; + + // Send the message + ke_msg_send(p_cmd); + + // Keep the current operation + // And the next expected operation code for the command completed event + app_env.adv_op = GAPM_DELETE_ALL_ACTIVITIES; +} + +void app_adv_fsm_next(void) +{ + + switch (app_env.adv_state) + { + case (APP_ADV_STATE_IDLE): + { + // Create advertising + //app_create_advertising(); + app_create_advertising_with_mode(); + } break; + + case (APP_ADV_STATE_CREATING): + { + // Set advertising data + app_set_adv_data(); + } break; + + case (APP_ADV_STATE_SETTING_ADV_DATA): + { + // Set scan response data + app_set_scan_rsp_data(); + } break; + + case (APP_ADV_STATE_CREATED): + case (APP_ADV_STATE_SETTING_SCAN_RSP_DATA): + { + // Start advertising activity + app_start_advertising_with_mode(); + } break; + + case (APP_ADV_STATE_STARTING): + { + + + + // Go to started state + app_env.adv_state = APP_ADV_STATE_STARTED; + } break; + + case (APP_ADV_STATE_STARTED): + { + // Stop advertising activity + app_stop_advertising(); + } break; + + case (APP_ADV_STATE_STOPPING): + { + + // Go created state + //app_env.adv_state = APP_ADV_STATE_CREATED; + + if(ke_state_get(TASK_APP) != APP_CONNECTED) + { + if(app_env.adv_mode == APP_ADV_MODE_FAST) + { + app_env.adv_mode = APP_ADV_MODE_SLOW; + app_env.adv_state = APP_ADV_STATE_IDLE; + app_create_advertising_with_mode(); + } + else if(app_env.adv_mode == APP_ADV_MODE_SLOW) + { + app_env.adv_state = APP_ADV_STATE_CREATED; + } + } + else + { + app_env.adv_state = APP_ADV_STATE_CREATED; + } + + } break; + + default: + { + ASSERT_ERR(0); + } break; + } +} + +void ns_ble_update_param(struct gapc_conn_param *p_conn_param) +{ + // Prepare the GAPC_PARAM_UPDATE_CMD message + struct gapc_param_update_cmd *p_cmd = KE_MSG_ALLOC(GAPC_PARAM_UPDATE_CMD, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_param_update_cmd); + + + p_cmd->operation = GAPC_UPDATE_PARAMS; + p_cmd->intv_min = p_conn_param->intv_min; + p_cmd->intv_max = p_conn_param->intv_max; + p_cmd->latency = p_conn_param->latency; + p_cmd->time_out = p_conn_param->time_out; + + // not used by a slave device + p_cmd->ce_len_min = 0xFFFF; + p_cmd->ce_len_max = 0xFFFF; + + // Send the message + ke_msg_send(p_cmd); +} + +void app_update_adv_state(bool start) +{ + // TODO [LT] - Check current advertising state + if(start) + { + app_env.adv_mode = APP_ADV_MODE_FAST; + } + + // Start or stop advertising + app_adv_fsm_next(); +} + +void ns_ble_mtu_set(uint16_t mtu) +{ + gapm_env.max_mtu = mtu; + struct gattc_exc_mtu_cmd *cmd = KE_MSG_ALLOC(GATTC_EXC_MTU_CMD, + KE_BUILD_ID(TASK_GATTC, app_env.conidx), TASK_APP, + gattc_exc_mtu_cmd); + cmd->operation = GATTC_MTU_EXCH; + cmd->seq_num = 0; + ke_msg_send(cmd); +} + + + +#endif //(BLE_APP_PRF) +#endif //(BLE_APP_PRESENT) + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/ns_ble_task.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/ns_ble_task.c new file mode 100644 index 0000000..f0d4812 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/image_update/src/ns_ble_task.c @@ -0,0 +1,1175 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble_task.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_PRESENT) + +#include "ns_ble_task.h" // Application Manager Task API +#include "ns_ble.h" // Application Manager Definition +#include "gapm_task.h" // GAP Manager Task API +#include +#include "co_utils.h" +#include "ke_timer.h" // Kernel timer + +#if (BLE_APP_SEC) +#include "ns_sec.h" // Security Module Definition +#endif //(BLE_APP_SEC) + +#if (BLE_APP_HT) +#include "app_ht.h" // Health Thermometer Module Definition +#include "htpt_task.h" +#endif //(BLE_APP_HT) + +#if (BLE_APP_DIS) +#include "app_dis.h" // Device Information Module Definition +#include "diss_task.h" +#endif //(BLE_APP_DIS) + +#if (BLE_APP_BATT) +#include "app_batt.h" // Battery Module Definition +#include "bass_task.h" +#endif //(BLE_APP_BATT) + +#if (BLE_APP_HID) +#include "app_hid.h" // HID Module Definition +#include "hogpd_task.h" +#endif //(BLE_APP_HID) + + +#if (BLE_RDTSS_SERVER) +#include "app_rdtss.h" // RDTSS Application Definitions +#endif //(BLE_RDTSS_SERVER) + +#if (BLE_APP_NS_IUS) +#include "app_ns_ius.h" // NS IUS Application Definitions +#include "ns_dfu_ble.h" +#endif //(BLE_RDTSS_SERVER) + + +#include "ahi_task.h" +#include "co_hci.h" +#include "hci.h" +#include "stdio.h" +#include "attm.h" +#include "atts.h" + +#include "ns_delay.h" +#include "gapm_int.h" +#include "llm_int.h" +#include "ns_sleep.h" + +#include "prf.h" +#if (NS_TIMER_ENABLE) +#include "ns_timer.h" +#endif //NS_TIMER_ENABLE + + + +/* + * LOCAL FUNCTION DEFINITIONS + **/ + +void user_exe_operation_t(void) +{ + +} + +static int appm_gattc_cmp_evt_handler(ke_msg_id_t const msgid, struct gattc_cmp_evt const *gattc_cmp_evt, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + switch(gattc_cmp_evt->operation){ + + case GATTC_MTU_EXCH:{ + if(app_env.manual_mtu_update){ + app_env.manual_mtu_update = 0; + ns_dfu_ble_handler_mtu_update(gattc_cmp_evt->status); + } + + + + } + break; + + } + + return (KE_MSG_CONSUMED); +} + + + +static uint8_t app_get_handler(const struct app_subtask_handlers *handler_list_desc, + ke_msg_id_t msgid, + void *p_param, + ke_task_id_t src_id) +{ + // Counter + uint8_t counter; + // Get the message handler function by parsing the message table + for (counter = handler_list_desc->msg_cnt; 0 < counter; counter--) + { + struct ke_msg_handler handler + = /*(struct ke_msg_handler)*/(*(handler_list_desc->p_msg_handler_tab + counter - 1)); + + if ((handler.id == msgid) || + (handler.id == KE_MSG_DEFAULT_HANDLER)) + { + // If handler is NULL, message should not have been received in this state + ASSERT_ERR(handler.func); + + return (uint8_t)(handler.func(msgid, p_param, TASK_APP, src_id)); + } + } + + // If we are here no handler has been found, drop the message + return (KE_MSG_CONSUMED); +} + + +/* + * MESSAGE HANDLERS + **/ +#if (BLE_APP_PRF) +/** + * @brief Handles GAPM_ACTIVITY_CREATED_IND event + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int gapm_activity_created_ind_handler(ke_msg_id_t const msgid, + struct gapm_activity_created_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (app_env.adv_state == APP_ADV_STATE_CREATING) + { + // Store the advertising activity index + app_env.adv_actv_idx = p_param->actv_idx; + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles GAPM_ACTIVITY_STOPPED_IND event. + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int gapm_activity_stopped_ind_handler(ke_msg_id_t const msgid, + struct gapm_activity_stopped_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + if (app_env.adv_state == APP_ADV_STATE_STARTED) + { + // Act as if activity had been stopped by the application + app_env.adv_state = APP_ADV_STATE_STOPPING; + + // Perform next operation + app_adv_fsm_next(); + } + + return (KE_MSG_CONSUMED); +} +#endif //(BLE_APP_PRF) + +/** + * @brief Handles GAPM_PROFILE_ADDED_IND event + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance. + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int gapm_profile_added_ind_handler(ke_msg_id_t const msgid, + struct gapm_profile_added_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + // Current State + ke_state_t state = ke_state_get(dest_id); + + if (state == APP_CREATE_DB) + { + switch (p_param->prf_task_id) + { + + + default: /* Nothing to do */ break; + } + } + else + { + ASSERT_INFO(0, state, src_id); + } + + return (KE_MSG_CONSUMED); +} + +/** + * @brief Handles GAP manager command complete events. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int gapm_cmp_evt_handler(ke_msg_id_t const msgid, + struct gapm_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + #if (NVDS_SUPPORT) + uint8_t key_len = KEY_LEN; + #endif //(NVDS_SUPPORT) + + + switch(p_param->operation) + { + + // Reset completed + case (GAPM_RESET): + { + if(p_param->status == GAP_ERR_NO_ERROR) + { + //reset prf_init + prf_init(RWIP_1ST_RST); + + #if (NVDS_SUPPORT) + nvds_tag_len_t len; + #endif //(NVDS_SUPPORT) + #if (BLE_APP_HID) + app_hid_start_mouse(); + #endif //(BLE_APP_HID) + + // Set Device configuration + struct gapm_set_dev_config_cmd* p_cmd = KE_MSG_ALLOC(GAPM_SET_DEV_CONFIG_CMD, + TASK_GAPM, TASK_APP, + gapm_set_dev_config_cmd); + // Set the operation + p_cmd->operation = GAPM_SET_DEV_CONFIG; + #if (BLE_APP_PRF) + // Set the device role - Peripheral + p_cmd->role = GAP_ROLE_PERIPHERAL; + #endif //(BLE_APP_PRF) + + p_cmd->pairing_mode = GAPM_PAIRING_LEGACY; + + // Set Data length parameters + p_cmd->sugg_max_tx_octets = BLE_MIN_OCTETS; + p_cmd->max_mtu = 517; //app_env.rsp_max_mtu; + p_cmd->sugg_max_tx_time = BLE_MIN_TIME; + + #if (BLE_APP_HID) + // Enable Slave Preferred Connection Parameters present + p_cmd->att_cfg = 0; + SETF(p_cmd->att_cfg, GAPM_ATT_SLV_PREF_CON_PAR_EN, 1); + #endif //(BLE_APP_HID) + + // Host privacy enabled by default + p_cmd->privacy_cfg = 0; + + #if (NVDS_SUPPORT) + if (nvds_get(NVDS_TAG_BD_ADDRESS, &len, &p_cmd->addr.addr[0]) == NVDS_OK) + { + // Check if address is a static random address + if (p_cmd->addr.addr[5] & 0xC0) + { + // Host privacy enabled by default + p_cmd->privacy_cfg |= GAPM_PRIV_CFG_PRIV_ADDR_BIT; + } + } + #endif //(NVDS_SUPPORT) + + #if (NVDS_SUPPORT) + #if (BLE_APP_PRF) + if ((app_sec_get_bond_status()==true) && + (nvds_get(NVDS_TAG_LOC_IRK, &key_len, app_env.loc_irk) == NVDS_OK)) + { + memcpy(p_cmd->irk.key, app_env.loc_irk, 16); + } + else + + #endif // (BLE_APP_PRF) + #endif //(NVDS_SUPPORT) + { + memset((void *)&p_cmd->irk.key[0], 0x00, KEY_LEN); + } + + + // Send message + ke_msg_send(p_cmd); + } + else + { + ASSERT_ERR(0); + } + } + break; + + case (GAPM_PROFILE_TASK_ADD): + { + #if (BLE_APP_PRF) +// if (app_sec_get_bond_status()==true) +// { +// #if (NVDS_SUPPORT) +// // If Bonded retrieve the local IRK from NVDS +// if (nvds_get(NVDS_TAG_LOC_IRK, &key_len, app_env.loc_irk) == NVDS_OK) +// { +// // Set the IRK in the GAP +// struct gapm_set_irk_cmd *p_cmd = KE_MSG_ALLOC(GAPM_SET_IRK_CMD, +// TASK_GAPM, TASK_APP, +// gapm_set_irk_cmd); +// /// - GAPM_SET_IRK: +// p_cmd->operation = GAPM_SET_IRK; +// memcpy(&p_cmd->irk.key[0], &app_env.loc_irk[0], KEY_LEN); +// ke_msg_send(p_cmd); +// } +// else +// #endif //(NVDS_SUPPORT) +// { +// // If cannot read IRK from NVDS ASSERT +// ASSERT_ERR(0); +// } +// } +// else // Need to start the generation of new IRK + { + struct gapm_gen_rand_nb_cmd *p_cmd = KE_MSG_ALLOC(GAPM_GEN_RAND_NB_CMD, + TASK_GAPM, TASK_APP, + gapm_gen_rand_nb_cmd); + p_cmd->operation = GAPM_GEN_RAND_NB; + app_env.rand_cnt = 1; + ke_msg_send(p_cmd); + } + + #endif // (BLE_APP_PRF) + } + break; + + #if (BLE_APP_PRF) + case (GAPM_GEN_RAND_NB) : + { + if (app_env.rand_cnt == 1) + { + // Generate a second random number + app_env.rand_cnt++; + struct gapm_gen_rand_nb_cmd *p_cmd = KE_MSG_ALLOC(GAPM_GEN_RAND_NB_CMD, + TASK_GAPM, TASK_APP, + gapm_gen_rand_nb_cmd); + p_cmd->operation = GAPM_GEN_RAND_NB; + ke_msg_send(p_cmd); + } + else + { + struct gapm_set_irk_cmd *p_cmd = KE_MSG_ALLOC(GAPM_SET_IRK_CMD, + TASK_GAPM, TASK_APP, + gapm_set_irk_cmd); + app_env.rand_cnt=0; + /// - GAPM_SET_IRK + p_cmd->operation = GAPM_SET_IRK; + memcpy(&p_cmd->irk.key[0], &app_env.loc_irk[0], KEY_LEN); + ke_msg_send(p_cmd); + } + } + break; + #endif //(BLE_APP_PRF) + + #if (BLE_APP_PRF) + case (GAPM_SET_IRK): + { + // ASSERT_INFO(p_param->status == GAP_ERR_NO_ERROR, p_param->operation, p_param->status); + // If not Bonded already store the generated value in NVDS +// if (app_sec_get_bond_status()==false) +// { +// #if (NVDS_SUPPORT) +// if (nvds_put(NVDS_TAG_LOC_IRK, KEY_LEN, (uint8_t *)&app_env.loc_irk) != NVDS_OK) +// #endif //(NVDS_SUPPORT) +// { +// ASSERT_INFO(0, 0, 0); +// } +// } + + app_env.rand_cnt = 0; + // Add the next requested service + if (!app_add_svc()) + { + // Go to the ready state + ke_state_set(TASK_APP, APP_READY); + + // No more service to add, start advertising + app_update_adv_state(true); + } + } + break; + #endif //(BLE_APP_PRF) + + // Device Configuration updated + case (GAPM_SET_DEV_CONFIG): + { + prf_init(RWIP_1ST_RST); + ASSERT_INFO(p_param->status == GAP_ERR_NO_ERROR, p_param->operation, p_param->status); + + // Go to the create db state + ke_state_set(TASK_APP, APP_CREATE_DB); + + // Add the first required service in the database + // and wait for the PROFILE_ADDED_IND + app_add_svc(); + } + break; + + #if (BLE_APP_PRF) + case (GAPM_CREATE_ADV_ACTIVITY): + case (GAPM_STOP_ACTIVITY): + case (GAPM_START_ACTIVITY): + case (GAPM_DELETE_ACTIVITY): + case (GAPM_SET_ADV_DATA): + case (GAPM_SET_SCAN_RSP_DATA): + { + // Sanity checks + ASSERT_INFO(app_env.adv_op == p_param->operation, app_env.adv_op, p_param->operation); + ASSERT_INFO(p_param->status == GAP_ERR_NO_ERROR, p_param->status, app_env.adv_op); + + + // Perform next operation + app_adv_fsm_next(); + + } break; + + case (GAPM_DELETE_ALL_ACTIVITIES) : + { + // Re-Invoke Advertising + app_env.adv_state = APP_ADV_STATE_IDLE; + } break; + #endif //(BLE_APP_PRF) + + default: + { + // Drop the message + } + break; + } + + return (KE_MSG_CONSUMED); +} + +static int gapc_get_dev_info_req_ind_handler(ke_msg_id_t const msgid, + struct gapc_get_dev_info_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + switch(p_param->req) + { + case GAPC_DEV_NAME: + { + struct gapc_get_dev_info_cfm * cfm = KE_MSG_ALLOC_DYN(GAPC_GET_DEV_INFO_CFM, + src_id, dest_id, + gapc_get_dev_info_cfm, APP_DEVICE_NAME_MAX_LEN); + cfm->req = p_param->req; + cfm->info.name.length = app_get_dev_name(cfm->info.name.value); + + // Send message + ke_msg_send(cfm); + } break; + + case GAPC_DEV_APPEARANCE: + { + // Allocate message + struct gapc_get_dev_info_cfm *cfm = KE_MSG_ALLOC(GAPC_GET_DEV_INFO_CFM, + src_id, dest_id, + gapc_get_dev_info_cfm); + cfm->req = p_param->req; + // Set the device appearance + #if (BLE_APP_HT) + // Generic Thermometer + cfm->info.appearance = 728; + #elif (BLE_APP_HID) + // HID Mouse + cfm->info.appearance = 962; + #else + // No appearance + cfm->info.appearance = 0; + #endif + + // Send message + ke_msg_send(cfm); + } break; + + case GAPC_DEV_SLV_PREF_PARAMS: + { + // Allocate message + struct gapc_get_dev_info_cfm *cfm = KE_MSG_ALLOC(GAPC_GET_DEV_INFO_CFM, + src_id, dest_id, + gapc_get_dev_info_cfm); + cfm->req = p_param->req; + // Slave preferred Connection interval Min + cfm->info.slv_pref_params.con_intv_min = 8; + // Slave preferred Connection interval Max + cfm->info.slv_pref_params.con_intv_max = 10; + // Slave preferred Connection latency + cfm->info.slv_pref_params.slave_latency = 0; + // Slave preferred Link supervision timeout + cfm->info.slv_pref_params.conn_timeout = 200; // 2s (500*10ms) + + // Send message + ke_msg_send(cfm); + } break; + + default: /* Do Nothing */ break; + } + + return (KE_MSG_CONSUMED); +} + +#if (BLE_APP_PRF) +/** + * @brief Handles GAPC_SET_DEV_INFO_REQ_IND message. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int gapc_set_dev_info_req_ind_handler(ke_msg_id_t const msgid, + struct gapc_set_dev_info_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + // Set Device configuration + struct gapc_set_dev_info_cfm* cfm = KE_MSG_ALLOC(GAPC_SET_DEV_INFO_CFM, src_id, dest_id, + gapc_set_dev_info_cfm); + + // Reject to change parameters + cfm->status = GAP_ERR_REJECTED; + cfm->req = p_param->req; + // Send message + ke_msg_send(cfm); + + return (KE_MSG_CONSUMED); +} + +#endif //(BLE_APP_PRF) + +/** + * @brief Handles connection complete event from the GAP. Enable all required profiles + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int gapc_connection_req_ind_handler(ke_msg_id_t const msgid, + struct gapc_connection_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + app_env.conidx = KE_IDX_GET(src_id); + + // Check if the received connection index is valid + if (app_env.conidx != GAP_INVALID_CONIDX) + { + // Allocate connection confirmation + struct gapc_connection_cfm *cfm = KE_MSG_ALLOC(GAPC_CONNECTION_CFM, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_connection_cfm); + + // Store received connection handle + app_env.conhdl = p_param->conhdl; + +// #if(BLE_APP_SEC) +// cfm->pairing_lvl = app_sec_get_bond_status() ? GAP_AUTH_REQ_NO_MITM_BOND : GAP_AUTH_REQ_NO_MITM_NO_BOND; //TODO TODOOOOOO 2021_01_28 +// #else // !(BLE_APP_SEC) +// cfm->auth = app_env.cfm_auth; +// #endif // (BLE_APP_SEC) + + cfm->pairing_lvl = GAP_AUTH_REQ_NO_MITM_NO_BOND; + // Send the message + ke_msg_send(cfm); + + /*-------------------------------------------------------------- + * ENABLE REQUIRED PROFILES + *--------------------------------------------------------------*/ + + #if (BLE_APP_BATT) + // Enable Battery Service + app_batt_enable_prf(app_env.conidx); + #endif //(BLE_APP_BATT) + + #if (BLE_APP_HID) + // Enable HID Service + app_hid_enable_prf(app_env.conidx); + #endif //(BLE_APP_HID) + + // We are now in connected State + ke_state_set(dest_id, APP_CONNECTED); + + } + else + { + #if (BLE_APP_PRF) + // No connection has been established, restart advertising + app_update_adv_state(true); + + #endif //(BLE_APP_PRF) + } + + + return (KE_MSG_CONSUMED); +} +/** + * @brief Handles connection complete event from the GAP. Enable all required profiles + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int gapc_param_update_req_ind_handler(ke_msg_id_t const msgid, + struct gapc_param_update_req_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + app_env.conidx = KE_IDX_GET(src_id); + + // Check if the received Connection Handle was valid + if (app_env.conidx != GAP_INVALID_CONIDX) + { + // Send connection confirmation + struct gapc_param_update_cfm *cfm = KE_MSG_ALLOC(GAPC_PARAM_UPDATE_CFM, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_param_update_cfm); + + cfm->accept = true; + cfm->ce_len_min = 2; + cfm->ce_len_max = 4; + + // Send message + ke_msg_send(cfm); + } + else + { +#if (BLE_APP_PRF) + // No connection has been established, restart advertising + app_update_adv_state(true); +#endif // (BLE_APP_PRF) + } + + return (KE_MSG_CONSUMED); +} + +#if (BLE_APP_PRF) +/** + * @brief Handles GAP controller command complete events. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int gapc_cmp_evt_handler(ke_msg_id_t const msgid, + struct gapc_cmp_evt const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + + switch(p_param->operation) + { + case (GAPC_UPDATE_PARAMS): + { + + if(app_env.manual_conn_param_update){ + app_env.manual_conn_param_update = 0; + ns_dfu_ble_handler_conn_param_update(p_param->status); + } + + if (p_param->status != GAP_ERR_NO_ERROR) + { + + // it's application specific what to do when the Param Upd request is rejected + //TODO + + + } + } + case (GAPC_SET_LE_PKT_SIZE): + { + if (p_param->status != GAP_ERR_NO_ERROR) + { + + } + } + case (GAPC_SECURITY_REQ): + { + if (p_param->status == GAP_ERR_NO_ERROR) + { + + } + else + { + + } + + } + + + break; + + default: + { + } + break; + } + + return (KE_MSG_CONSUMED); +} +#endif //(BLE_APP_PRF) + +/** + * @brief Handles disconnection complete event from the GAP. + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int gapc_disconnect_ind_handler(ke_msg_id_t const msgid, + struct gapc_disconnect_ind const *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + // Go to the ready state + ke_state_set(TASK_APP, APP_READY); + + + #if (BLE_APP_PRF) + #if (BLE_APP_HT) + // Stop interval timer + app_stop_timer(); + #endif //(BLE_APP_HT) + + #if (BLE_ISO_MODE_0_PROTOCOL) + app_env.adv_state = APP_ADV_STATE_CREATING; + #endif //(BLE_ISO_MODE_0_PROTOCOL) + + #if (!BLE_APP_HID) + // Restart Advertising + app_update_adv_state(true); + #endif //(!BLE_APP_HID) + + + #endif //(BLE_APP_PRF) + + #if (BLE_RDTSS_SERVER) + //disable usart receive + + #endif //(BLE_RDTSS_SERVER) + // Restart Advertising + app_update_adv_state(true); + + + return (KE_MSG_CONSUMED); +} + + +/** + * @brief Handles reception of all messages sent from the lower layers to the application + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ + +extern struct ke_task_desc TASK_DESC_APP_DIS; +extern const struct app_subtask_handlers app_sec_handlers; + +static int app_msg_handler(ke_msg_id_t const msgid, + void *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id, + enum ke_msg_status_tag *msg_ret) +{ + + // Retrieve identifier of the task from received message + ke_task_id_t src_task_id = MSG_T(msgid); + // Message policy + uint8_t msg_pol = KE_MSG_CONSUMED; + + switch (src_task_id) + { + case (TASK_ID_GAPC): + { + #if (BLE_APP_SEC) + if ((msgid >= GAPC_BOND_CMD) && + (msgid <= GAPC_SECURITY_IND)) + { + // Call the Security Module + msg_pol = app_get_handler(&app_sec_handlers, msgid, p_param, src_id); + } + #endif //(BLE_APP_SEC) + // else drop the message + } break; + + case (TASK_ID_GATTC): + { + // Service Changed - Drop + } break; + + #if (BLE_APP_HT) + case (TASK_ID_HTPT): + { + // Call the Health Thermometer Module + msg_pol = app_get_handler(&app_ht_handlers, msgid, p_param, src_id); + } break; + #endif //(BLE_APP_HT) + + #if (BLE_APP_DIS) + case (TASK_ID_DISS): + { + // Call the Device Information Module + msg_pol = app_get_handler(&app_dis_handlers, msgid, p_param, src_id); + } break; + #endif //(BLE_APP_DIS) + + #if (BLE_APP_HID) + case (TASK_ID_HOGPD): + { + // Call the HID Module + msg_pol = app_get_handler(&app_hid_handlers, msgid, p_param, src_id); + } break; + #endif //(BLE_APP_HID) + + + #if (BLE_APP_BATT) + case (TASK_ID_BASS): + { + // Call the Battery Module + msg_pol = app_get_handler(&app_batt_handlers, msgid, p_param, src_id); + } break; + #endif //(BLE_APP_BATT) + + + #if(BLE_RDTSS_SERVER) + case (TASK_ID_RDTSS): + { + // Call the rdtss Module + msg_pol = app_get_handler(&app_rdtss_handlers, msgid, p_param, src_id); + } break; + #endif //(TASK_ID_RDTSS) + + #if(BLE_APP_NS_IUS) + case (TASK_ID_NS_IUS): + { + msg_pol = app_get_handler(&ns_ius_app_handlers, msgid, p_param, src_id); + } break; + #endif //(BLE_APP_NS_IUS) + + default: + { + #if (BLE_APP_HT) + if (msgid == APP_HT_MEAS_INTV_TIMER) + { + msg_pol = app_get_handler(&TASK_DESC_APP_HT, msgid, p_param, src_id); + } + #endif //(BLE_APP_HT) + + #if (BLE_APP_HID) + if (msgid == APP_HID_MOUSE_TIMEOUT_TIMER) + { + msg_pol = app_get_handler(&app_hid_handlers, msgid, p_param, src_id); + } + #endif //(BLE_APP_HID) + + + } break; + } + + return (msg_pol); +} + +#if (BLE_APP_PRF) +/** + * @brief Handles reception of random number generated message + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int gapm_gen_rand_nb_ind_handler(ke_msg_id_t const msgid, struct gapm_gen_rand_nb_ind *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + + if (app_env.rand_cnt==1) // First part of IRK + { + memcpy(&app_env.loc_irk[0], &p_param->randnb.nb[0], 8); + } + else if (app_env.rand_cnt==2) // Second part of IRK + { + memcpy(&app_env.loc_irk[8], &p_param->randnb.nb[0], 8); + } + return (KE_MSG_CONSUMED); +} + +#endif //(BLE_APP_PRF) + +__STATIC int gapc_param_updated_ind_handler(ke_msg_id_t const msgid, + struct gapc_param_updated_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + return (KE_MSG_CONSUMED); +} + +__STATIC int gapc_le_pkt_size_ind_handler(ke_msg_id_t const msgid, + struct gapc_le_pkt_size_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + return (KE_MSG_CONSUMED); +} + +__STATIC int gattc_mtu_changed_ind_handler(ke_msg_id_t const msgid, + struct gattc_mtu_changed_ind *p_param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + return (KE_MSG_CONSUMED); +} + + +/** + * @brief Handles + * + * @param[in] msgid Id of the message received. + * @param[in] p_param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int app_conn_params_update_evt_handler(ke_msg_id_t const msgid, void *p_param,//struct app_adv_timer_evt_t *p_param, + ke_task_id_t const dest_id, ke_task_id_t const src_id) +{ + + // Prepare the GAPC_PARAM_UPDATE_CMD message + struct gapc_param_update_cmd *p_cmd = KE_MSG_ALLOC(GAPC_PARAM_UPDATE_CMD, + KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, + gapc_param_update_cmd); + + p_cmd->operation = GAPC_UPDATE_PARAMS; + p_cmd->intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL, MSECS_UNIT_1_25_MS); + p_cmd->intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL, MSECS_UNIT_1_25_MS); + p_cmd->latency = SLAVE_LATENCY; + p_cmd->time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT, MSECS_UNIT_10_MS); + + // not used by a slave device + p_cmd->ce_len_min = 0xFFFF; + p_cmd->ce_len_max = 0xFFFF; + + // Send the message + ke_msg_send(p_cmd); + + return (KE_MSG_CONSUMED); +} + + +int app_entry_point_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + enum ke_msg_status_tag process_msg_handling_result; + + //add others user handler + //TODO + + +#if (NS_TIMER_ENABLE) + ns_timer_api_process_handler(msgid, param, dest_id, src_id,&process_msg_handling_result); + if(process_msg_handling_result == KE_MSG_CONSUMED) + return (KE_MSG_CONSUMED); +#endif //NS_TIMER_ENABLE + app_msg_handler(msgid, (void *)param, dest_id, src_id, &process_msg_handling_result); + if(process_msg_handling_result == KE_MSG_CONSUMED) + return (KE_MSG_CONSUMED); + + return (KE_MSG_CONSUMED); +} + + + +/** + * @brief Function called when the APP_HID_DATA_PROCESS_EVT expires. + * + * @param[in] msgid Id of the message received. + * @param[in] param Pointer to the parameters of the message. + * @param[in] dest_id ID of the receiving task instance (TASK_GAP). + * @param[in] src_id ID of the sending task instance. + * + * @return If the message was consumed or not. + **/ +static int app_hid_data_process_handler(ke_msg_id_t const msgid, + void const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + + + // Relaunch the timer + ke_timer_set(APP_HID_DATA_PROCESS_EVT, TASK_APP, 1000); + + + return (KE_MSG_CONSUMED); +} + + +/* + * GLOBAL VARIABLES DEFINITION + **/ +extern int app_dfu_ble_reset_handler(ke_msg_id_t const msgid, void const *p_param, ke_task_id_t const dest_id, ke_task_id_t const src_id); +/* Default State handlers definition. */ +KE_MSG_HANDLER_TAB(app) +{ + + // Note: first message is latest message checked by kernel so default is put on top. + {KE_MSG_DEFAULT_HANDLER, (ke_msg_func_t)app_entry_point_handler}, + + + // GAPM messages + #if (BLE_APP_PRF) + {GAPM_ACTIVITY_CREATED_IND, (ke_msg_func_t)gapm_activity_created_ind_handler}, + {GAPM_ACTIVITY_STOPPED_IND, (ke_msg_func_t)gapm_activity_stopped_ind_handler}, + {GAPM_GEN_RAND_NB_IND, (ke_msg_func_t)gapm_gen_rand_nb_ind_handler}, + #endif //(BLE_APP_PRF) + {GAPM_CMP_EVT, (ke_msg_func_t)gapm_cmp_evt_handler}, + {GAPM_PROFILE_ADDED_IND, (ke_msg_func_t)gapm_profile_added_ind_handler}, + + // GATTC messages + {GATTC_MTU_CHANGED_IND, (ke_msg_func_t)gattc_mtu_changed_ind_handler}, + + // GAPC messages + {GAPC_CONNECTION_REQ_IND, (ke_msg_func_t)gapc_connection_req_ind_handler}, + {GAPC_PARAM_UPDATE_REQ_IND, (ke_msg_func_t)gapc_param_update_req_ind_handler}, + {GAPC_PARAM_UPDATED_IND, (ke_msg_func_t)gapc_param_updated_ind_handler}, + {GAPC_LE_PKT_SIZE_IND, (ke_msg_func_t)gapc_le_pkt_size_ind_handler}, + {GAPC_DISCONNECT_IND, (ke_msg_func_t)gapc_disconnect_ind_handler}, + {GAPC_GET_DEV_INFO_REQ_IND, (ke_msg_func_t)gapc_get_dev_info_req_ind_handler}, + + + #if (BLE_APP_PRF) + {GAPC_SET_DEV_INFO_REQ_IND, (ke_msg_func_t)gapc_set_dev_info_req_ind_handler}, + {GAPC_CMP_EVT, (ke_msg_func_t)gapc_cmp_evt_handler}, + + #endif //(BLE_APP_PRF) + + {GATTC_CMP_EVT, (ke_msg_func_t)appm_gattc_cmp_evt_handler}, + + //user event + {APP_PARAMS_UPDATE_EVT, (ke_msg_func_t)app_conn_params_update_evt_handler}, + {APP_HID_DATA_PROCESS_EVT, (ke_msg_func_t)app_hid_data_process_handler}, + + + {APP_DFU_BLE_RESET_TIMER, (ke_msg_func_t)app_dfu_ble_reset_handler}, + +}; + +/* Defines the place holder for the states of all the task instances. */ +ke_state_t app_state[APP_IDX_MAX]; + +// Application task descriptor +const struct ke_task_desc TASK_DESC_APP_M = {app_msg_handler_tab, app_state, APP_IDX_MAX, ARRAY_LEN(app_msg_handler_tab)}; + +#endif //(BLE_APP_PRESENT) + +/// @} APPTASK diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/MDK-ARM/masterboot.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/MDK-ARM/masterboot.uvoptx new file mode 100644 index 0000000..0d059a9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/MDK-ARM/masterboot.uvoptx @@ -0,0 +1,449 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + USER + 1 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + + + NS_LIB + 1 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + ns_error.c + 0 + 0 + + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\scheduler\ns_scheduler.c + ns_scheduler.c + 0 + 0 + + + + + DOC + 1 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + + + NS_DFU + 0 + 0 + 0 + 0 + + 7 + 13 + 1 + 0 + 0 + 0 + ..\..\common\dfu_usart.c + dfu_usart.c + 0 + 0 + + + 7 + 14 + 1 + 0 + 0 + 0 + ..\..\common\dfu_led.c + dfu_led.c + 0 + 0 + + + 7 + 15 + 1 + 0 + 0 + 0 + ..\..\common\dfu_delay.c + dfu_delay.c + 0 + 0 + + + 7 + 16 + 1 + 0 + 0 + 0 + ..\..\common\dfu_crc.c + dfu_crc.c + 0 + 0 + + + 7 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + ns_dfu_boot.c + 0 + 0 + + + 7 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_serial.c + ns_dfu_serial.c + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/MDK-ARM/masterboot.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/MDK-ARM/masterboot.uvprojx new file mode 100644 index 0000000..5697b0e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/MDK-ARM/masterboot.uvprojx @@ -0,0 +1,517 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.4.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + masterboot + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 1 + fromelf --bin --output=.\bin\masterboot.bin .\Objects\masterboot.axf + cmd.exe /C copy .\bin\masterboot.bin ..\..\..\..\..\utilities\dfu\Image\MasterBoot.bin + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x2000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03x, USE_STDPERIPH_DRIVER,MASTERBOOT + + ..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\scheduler;..\..\common + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + + + NS_LIB + + + ns_error.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\error\ns_error.c + + + ns_scheduler.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\scheduler\ns_scheduler.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + NS_DFU + + + dfu_usart.c + 1 + ..\..\common\dfu_usart.c + + + dfu_led.c + 1 + ..\..\common\dfu_led.c + + + dfu_delay.c + 1 + ..\..\common\dfu_delay.c + + + dfu_crc.c + 1 + ..\..\common\dfu_crc.c + + + ns_dfu_boot.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_boot.c + + + ns_dfu_serial.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\dfu\ns_dfu_serial.c + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/readme.txt new file mode 100644 index 0000000..63bcc2a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/readme.txt @@ -0,0 +1,22 @@ + + +1. Function description + + 1. This routine shows the application of Master Boot layer in serial port upgrade. + 2. Realize serial port receiving data and rewriting the application function in Bank1. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 6. Data: USART1 PA4(TX) and PA5(RX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + usage method: + Refer to Chapter 7.1 of the Firmware Upgrade User's Guide + +4. Precautions + Since the program will enter the sleep mode, the SWD will not be accessible. Press the RESET button to execute the program burning step within one second. diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/src/main.c new file mode 100644 index 0000000..969588c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/dfu/masterboot/src/main.c @@ -0,0 +1,170 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + + /* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "dfu_led.h" +#include "ns_dfu_boot.h" +#include "dfu_crc.h" +#include "ns_scheduler.h" +#include "ns_dfu_serial.h" +#include "dfu_usart.h" + +/** + * @brief Loop up the bootsetting and decide which bank to jump to , or stay in masterboot for usart image update. + * @param[in] none. + * @return none + */ +static void masterboot(void) +{ + uint32_t jump_address = NULL; + if(ns_bootsetting.crc == dfu_crc32((uint8_t *)&ns_bootsetting.crc + 4, sizeof(NS_Bootsetting_t) - 4)) + { + if(ns_bootsetting.master_boot_force_update != NS_BOOTSETTING_MASTER_BOOT_FORCE_UPDATE_YES) + { + if(ns_bootsetting.app1.activation == NS_BOOTSETTING_ACTIVATION_YES && ns_bootsetting.app1.start_address == NS_APP1_START_ADDRESS) + { + if(ns_bootsetting.app1.crc == dfu_crc32((uint8_t *)((uint32_t *)ns_bootsetting.app1.start_address), ns_bootsetting.app1.size)) + { + jump_address = ns_bootsetting.app1.start_address; + } + } + else if(ns_bootsetting.app2.activation == NS_BOOTSETTING_ACTIVATION_YES && ns_bootsetting.app2.start_address == NS_APP2_START_ADDRESS) + { + if(ns_bootsetting.app2.crc == dfu_crc32((uint8_t *)((uint32_t *)ns_bootsetting.app2.start_address), ns_bootsetting.app2.size)) + { + jump_address = ns_bootsetting.app2.start_address; + } + } + else if(ns_bootsetting.ImageUpdate.activation == NS_BOOTSETTING_ACTIVATION_YES && ns_bootsetting.ImageUpdate.start_address == NS_IMAGE_UPDATE_START_ADDRESS) + { + if(ns_bootsetting.ImageUpdate.crc == dfu_crc32((uint8_t *)((uint32_t *)ns_bootsetting.ImageUpdate.start_address), ns_bootsetting.ImageUpdate.size)) + { + jump_address = ns_bootsetting.ImageUpdate.start_address; + } + } + if(jump_address == NULL) + { + if(ns_bootsetting.app1.crc == dfu_crc32((uint8_t *)((uint32_t *)ns_bootsetting.app1.start_address), ns_bootsetting.app1.size)) + { + jump_address = ns_bootsetting.app1.start_address; + } + else if(ns_bootsetting.app2.crc == dfu_crc32((uint8_t *)((uint32_t *)ns_bootsetting.app2.start_address), ns_bootsetting.app2.size)) + { + jump_address = ns_bootsetting.app2.start_address; + } + else if(ns_bootsetting.ImageUpdate.crc == dfu_crc32((uint8_t *)((uint32_t *)ns_bootsetting.ImageUpdate.start_address), ns_bootsetting.ImageUpdate.size)) + { + jump_address = ns_bootsetting.ImageUpdate.start_address; + } + } + if(jump_address != NULL) + { + dfu_usart1_default_config(); + ns_dfu_boot_jump(jump_address); + } + } + } +} + +#define POLL_UART_CYCLE (0x6FFF) //20ms +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + /// swd -> uart + dfu_usart1_poll_config(USART1_GPIO_PA45,1000000); + if(dfu_usart1_poll_boot_byte(0x7F, POLL_UART_CYCLE) == false) + { + dfu_usart1_poll_config(USART1_GPIO_PA45,115200); + if(dfu_usart1_poll_boot_byte(0x7F, POLL_UART_CYCLE) == false) + { + dfu_usart1_poll_config(USART1_GPIO_PB67,1000000); + if(dfu_usart1_poll_boot_byte(0x7F, POLL_UART_CYCLE) == false) + { + dfu_usart1_poll_config(USART1_GPIO_PB67,115200); + if(dfu_usart1_poll_boot_byte(0x7F, POLL_UART_CYCLE) == false) + { + //normal boot + masterboot(); + } + } + } + } + NS_SCHED_INIT(256, 16); + ns_dfu_serial_init(); + + while(1) + { + app_sched_execute(); + __WFE(); + __SEV(); + __WFE(); + } +} + + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/MDK-ARM/ADC_16Bit.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/MDK-ARM/ADC_16Bit.uvoptx new file mode 100644 index 0000000..a29936c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/MDK-ARM/ADC_16Bit.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + JL2CM3 + -U59800867 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO7 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + ARMRTXEVENTFLAGS + -L70 -Z18 -C0 -M0 -T1 + + + 0 + DLGTARM + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0) + + + 0 + ARMDBGFLAGS + + + + 0 + DLGUARM + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + + 0 + 1 + ADCBuf,0x0A + + + 1 + 1 + trim_stored,0x0A + + + 2 + 1 + DMA_CH1,0x10 + + + + + 1 + 265 + ADCBuf + 0 + + + + 0 + + + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/MDK-ARM/ADC_16Bit.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/MDK-ARM/ADC_16Bit.uvprojx new file mode 100644 index 0000000..2670200 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/MDK-ARM/ADC_16Bit.uvprojx @@ -0,0 +1,483 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + ADC_SingRead + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\ADC_SingRead.bin .\Objects\ADC_SingRead.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/inc/main.h new file mode 100644 index 0000000..fde155b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/inc/main.h @@ -0,0 +1,81 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include "n32wb03x.h" + + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/readme.txt new file mode 100644 index 0000000..dfcb1c0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/readme.txt @@ -0,0 +1,27 @@ + +1. Function description + 1. 16bit ADC samples and converts the analog voltage of the PB8 pin and PB9 pin. + 2. The ADC conversion result is read to the variable ADC ConvertedValue through the DMA_CH1 channel + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. Clock source: + HSE=32M, HSI=64M, AHB=64M, APB1=32M, APB2=64M, ADC CLK=HSE/8, DMA CLK=64M + 2. Port configuration: + ADC conversion channel 2 is PB9, ADC conversion channel 3 is PB8. + 3. DMA: + DMA1_CH1 channel is configuered as circular mode, carries a half-word ADC conversion result to ADCConvertedValue variable + 4. ADC: + ADC configuration: continuous conversion, software trigger, 16-bit data, ADC conversion channel is channel 2 and channel 3. + + 5. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + Instructions: + 1. Download after compiling and reset to run the program, check conversion result at log. + 2. By changing the voltage of the PA1 pin, you can see that the conversion result variable changes synchronously + +4. Matters needing attention + Please make sure connect the J15 to left side and J16 to right side which is connect the IO to pogo pin not the crystal. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/src/main.c new file mode 100644 index 0000000..e12694f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_16Bit/src/main.c @@ -0,0 +1,263 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" +/* NOTE: +1. 16bit ADC must DISABLE BypassFilter +2. 16bit ADC must ENABLE ContinuousMode +3. every 248 16Bit ADC samples will output 2*16bit invalid data, + if you use DMA, you can set data len as 250, then drop the last 2 samples.*/ + +#define USE_ADC_16BIT_DMA 1 +#define ADC_16BIT_DROP 8 +#define ADC_DMA_BUF_SIZE 250 +#define ADC_AVG_NUM 200 + +#if ((ADC_AVG_NUM+ADC_16BIT_DROP) > ADC_DMA_BUF_SIZE) +#error "ADC_AVG_NUM+ADC_16BIT_DROP must less than ADC_DMA_BUF_SIZE!!!" +#endif + +extern void system_delay_n_10us(uint32_t value); + +int16_t ADCBuf[ADC_DMA_BUF_SIZE]; + + +int16_t ADC16bit_DMA_Get_AVG_Val(uint16_t Channel, uint8_t avg_num) +{ + uint16_t i, null_num; + int16_t avg; + int64_t sum = 0; + DMA_InitType DMA_InitStructure = {0}; + + /* Enable peripheral clocks */ + /* Enable ADC clocks */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC, ENABLE); + RCC_ConfigAdcClk(RCC_ADCCLK_SRC_AUDIOPLL); + /* enable ADC 4M clock */ + RCC_Enable_ADC_CLK_SRC_AUDIOPLL(ENABLE); + /* Enable peripheral clocks */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + + /* DMA channel1 configuration ----------------------------------------------*/ + DMA_DeInit(DMA_CH1); + DMA_InitStructure.PeriphAddr = (uint32_t)&ADC->DAT; + DMA_InitStructure.MemAddr = (uint32_t)&ADCBuf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = avg_num+ADC_16BIT_DROP; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(DMA_CH1, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_ADC, DMA, DMA_CH1, ENABLE); + /* Enable DMA channel1 */ + DMA_EnableChannel(DMA_CH1, ENABLE); + /* configer ADC */ + ADC_EnableBypassFilter(ADC, DISABLE); + ADC_ConfigContinuousMode(ADC, ENABLE); + ADC_ConfigChannel(ADC, Channel); + ADC_EnableDMA(ADC, ENABLE); + ADC_Enable(ADC, ENABLE); + /* wait DMA finish */ + while(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA) == RESET); + ADC_Enable(ADC, DISABLE); + DMA_EnableChannel(DMA_CH1, DISABLE); + null_num = 0; + + for( i = ADC_16BIT_DROP;i<(avg_num+ADC_16BIT_DROP);i++) + { + if(ADCBuf[i] == 0) + { + null_num++; + continue; + } + sum += ADCBuf[i]; + } + avg = sum/(avg_num-null_num); + + return avg; +} + + +uint16_t ADC16bit_SingleRead_Val(uint16_t Channel , uint8_t avg_num) +{ + int32_t sum = 0; + uint16_t i,null_num; + int16_t adc_val; + /* Enable peripheral clocks */ + /* Enable ADC clocks */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC, ENABLE); + RCC_ConfigAdcClk(RCC_ADCCLK_SRC_AUDIOPLL); + /* enable ADC 4M clock */ + RCC_Enable_ADC_CLK_SRC_AUDIOPLL(ENABLE); + /* configer ADC */ + ADC_EnableBypassFilter(ADC, DISABLE); + ADC_ConfigContinuousMode(ADC, ENABLE); + ADC_ConfigChannel(ADC, Channel); + ADC_Enable(ADC, ENABLE); + /* drop invalid data */ + system_delay_n_10us(100); //1ms + /* get adc data */ + null_num = 0; + for(i = 0; i + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/MDK-ARM/ADC_DMA.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/MDK-ARM/ADC_DMA.uvprojx new file mode 100644 index 0000000..1ef4577 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/MDK-ARM/ADC_DMA.uvprojx @@ -0,0 +1,480 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + ADC_DMA + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\ADC_DMA.bin .\Objects\ADC_DMA.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/inc/main.h new file mode 100644 index 0000000..fde155b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/inc/main.h @@ -0,0 +1,81 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include "n32wb03x.h" + + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/readme.txt new file mode 100644 index 0000000..7536945 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/readme.txt @@ -0,0 +1,26 @@ + +1. Function description + 1. ADC samples and converts the analog voltage of the PB8 pin + 2. The ADC conversion result is read to the variable ADCConvertedValue through the DMA_CH1 channel + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. Clock source: + HSE=32M, HSI=64M, AHB=64M, APB1=32M, APB2=64M, ADC CLK=HSE/8, DMA CLK=64M + 2. Port configuration: + PB8 is selected as analog function, ADC conversion channel 3 + 3. DMA: + DMA1_CH1 channel is configuered as circular mode, carries a half-word ADC conversion result to ADCConvertedValue variable + 4. ADC: + ADC configuration: continuous conversion, software trigger, 10-bit data, conversion channel 3 is the analog voltage data of PB8 + 5. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + Instructions: + 1. Download after compiling and reset to rum the program, check conversion result at log. + 2. By changing the voltage of the PA1 pin, you can see that the conversion result variable changes synchronously + +4. Matters needing attention + Please make sure connect the J15 to left side and J16 to right side which is connect the IO to pogo pin not the crystal. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/src/main.c new file mode 100644 index 0000000..8e7a87a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/src/main.c @@ -0,0 +1,174 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +void RCC_Configuration(void); +void GPIO_Configuration(void); + +__IO uint16_t ADCConvertedValue; +uint16_t voltage_val = 0; +DMA_InitType DMA_InitStructure; +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + log_info("\nThis is a ADC DMA Demo.\n"); + log_info("Please make sure J15 and J16 connect the IO to pin on board!\n"); + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* DMA channel1 configuration ----------------------------------------------*/ + DMA_DeInit(DMA_CH1); + DMA_InitStructure.PeriphAddr = (uint32_t)&ADC->DAT; + DMA_InitStructure.MemAddr = (uint32_t)&ADCConvertedValue; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = 1; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_DISABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.Priority = DMA_PRIORITY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(DMA_CH1, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_ADC, DMA, DMA_CH1, ENABLE); + /* Enable DMA channel1 */ + DMA_EnableChannel(DMA_CH1, ENABLE); + + ADC_EnableBypassFilter(ADC, ENABLE); + ADC_ConfigChannel(ADC, ADC_CTRL_CH_3); + ADC_ConfigContinuousMode(ADC, ENABLE); + ADC_EnableDMA(ADC, ENABLE); + ADC_Enable(ADC, ENABLE); + + while (1) + { + voltage_val = ADC_ConverValueToVoltage(ADCConvertedValue, ADC_CTRL_CH_3); + log_info("ADC CH3 value: %4d | ADC CH3 vol_mV: %4d .\r\n",ADCConvertedValue,voltage_val); + Delay_ms(1000); + } +} + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + /* Enable GPIOB clocks */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + /* Enable ADC clocks */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC, ENABLE); + /* enable ADC 4M clock */ + RCC_ConfigAdcClk(RCC_ADCCLK_SRC_HSE_DIV8); + +} + + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure PB.8 (ADC Channel3)as analog input --------*/ + GPIO_InitStructure.Pin = GPIO_PIN_8; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ + +/*************** (C) COPYRIGHT NSING Technologies Inc *****END OF FILE***************/ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/src/n32wb03x_it.c new file mode 100644 index 0000000..4c65872 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_DMA/src/n32wb03x_it.c @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/MDK-ARM/ADC_SingleRead.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/MDK-ARM/ADC_SingleRead.uvoptx new file mode 100644 index 0000000..0c5fa3d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/MDK-ARM/ADC_SingleRead.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/MDK-ARM/ADC_SingleRead.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/MDK-ARM/ADC_SingleRead.uvprojx new file mode 100644 index 0000000..17d0c0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/MDK-ARM/ADC_SingleRead.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + ADC_SingRead + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\ADC_SingRead.bin .\Objects\ADC_SingRead.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/inc/main.h new file mode 100644 index 0000000..fde155b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/inc/main.h @@ -0,0 +1,81 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include "n32wb03x.h" + + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/readme.txt new file mode 100644 index 0000000..41fd2ee --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/readme.txt @@ -0,0 +1,26 @@ + +1. Function description + 1. ADC samples and converts the analog voltage of the PB8 pin and PB10 pin. + 2. Use software to trigger once and collect once + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. Clock source: + HSE=32M, HSI=64M, AHB=64M, APB1=32M, APB2=64M, ADC CLK=HSE/8 + 2. Port configuration: + PB8 is selected as analog function, ADC conversion channel 3 (hight voltage channel) + PB10 is selected as analog function, ADC conversion channel 1 (low voltage channel) + 3. ADC: + ADC configuration: continuous conversion, software trigger, 10-bit data, conversion channel 3 is the analog voltage data of PB8, + conversion channel 1 is the analog voltage data of PB10 + 4. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + Instructions: + 1. Download after compiling and reset to rum the program, check conversion result at log. + 2. By changing the voltage of the PA1 pin, you can see that the conversion result variable changes synchronously + +4. Matters needing attention + Please make sure connect the J15 to left side and J16 to right side which is connect the IO to pogo pin not the crystal. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/src/main.c new file mode 100644 index 0000000..c0491b5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/src/main.c @@ -0,0 +1,167 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void ADC_Configuration(void); + +uint16_t ADCConvertedValue[2]; +uint32_t voltage[2] = {0}; +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + log_info("\nthis is adc single read Demo.\n"); + log_info("Please make sure J15 and J16 connect the IO to pin on board!\n"); + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + ADC_EnableBypassFilter(ADC, ENABLE); + while (1) + { + ADC_ConfigChannel(ADC, ADC_CTRL_CH_3); + ADC_Enable(ADC, ENABLE); + while(ADC_GetFlagStatus(ADC,ADC_FLAG_DONE) == RESET); + ADC_ClearFlag(ADC,ADC_FLAG_DONE); + ADCConvertedValue[1] = ADC_GetDat(ADC); + + voltage[1] = ADC_ConverValueToVoltage(ADCConvertedValue[1], ADC_CTRL_CH_3); + log_info("ADC CH3 value: %4d | ADC CH3 vol_mV: %4d .\r\n",ADCConvertedValue[1],voltage[1]); + + ADC_ConfigChannel(ADC, ADC_CTRL_CH_1); + ADC_Enable(ADC, ENABLE); + while(ADC_GetFlagStatus(ADC,ADC_FLAG_DONE) == RESET); + ADC_ClearFlag(ADC,ADC_FLAG_DONE); + ADCConvertedValue[0] = ADC_GetDat(ADC); + + voltage[0] = ADC_ConverValueToVoltage(ADCConvertedValue[0], ADC_CTRL_CH_1); + log_info("ADC CH1 value: %4d | ADC CH1 vol_mV: %4d .\r\n\r\n",ADCConvertedValue[0],voltage[0]); + Delay_ms(1000); + } +} + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks */ + /* Enable GPIOB clocks */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + /* Enable ADC clocks */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC, ENABLE); + + RCC_ConfigAdcClk(RCC_ADCCLK_SRC_AUDIOPLL); + + /* enable ADC 4M clock */ + RCC_Enable_ADC_CLK_SRC_AUDIOPLL(ENABLE); +} + + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure PB.10 (ADC Channel1) PB.8 (ADC Channel3) as analog input --------*/ + GPIO_InitStructure.Pin = GPIO_PIN_10|GPIO_PIN_8; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ + +/*************** (C) COPYRIGHT NSING Technologies Inc *****END OF FILE***************/ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/src/n32wb03x_it.c new file mode 100644 index 0000000..4c65872 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_SingleRead/src/n32wb03x_it.c @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/MDK-ARM/ADC_Temperature.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/MDK-ARM/ADC_Temperature.uvoptx new file mode 100644 index 0000000..381d63e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/MDK-ARM/ADC_Temperature.uvoptx @@ -0,0 +1,367 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/MDK-ARM/ADC_Temperature.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/MDK-ARM/ADC_Temperature.uvprojx new file mode 100644 index 0000000..66d605a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/MDK-ARM/ADC_Temperature.uvprojx @@ -0,0 +1,480 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + ADC_Temperature + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\ADC_Temperature.bin .\Objects\ADC_Temperature.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/inc/main.h new file mode 100644 index 0000000..fde155b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/inc/main.h @@ -0,0 +1,81 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include "n32wb03x.h" + + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/readme.txt new file mode 100644 index 0000000..72484be --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/readme.txt @@ -0,0 +1,23 @@ + +1. Function description + 1. ADC samples and converts the analog voltage of the internal temperature sensor and converts it to a temperature value + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. Clock source: + HSE=32M, HSI=64M, AHB=64M, APB1=32M, APB2=64M, ADC CLK=HSE/8 + 2. Port configuration: + PB8 is selected as analog function, ADC conversion channel 3 + 4. ADC: + ADC configuration: continuous conversion, software trigger, 10-bit data, conversion channel 7 is the analog voltage data of the internal temperature sensor + 5. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + Instructions: + 1. Download after compiling and reset to rum the program, check conversion result at log. + 2. The serial port tool displays the temperature value in the real-time chip + +4. Matters needing attention + Please make sure connect the J15 to left side and J16 to right side which is connect the IO to pogo pin not the crystal. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/src/main.c new file mode 100644 index 0000000..9ae8e19 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_Temperature/src/main.c @@ -0,0 +1,203 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "log.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define ADC_BUF_SIZE (10) + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint16_t ADCConvertedBuffer[ADC_BUF_SIZE]; +uint16_t ADCConvertedValue; +uint32_t Voltage_mA; +float Temperature; +/* Private function prototypes -----------------------------------------------*/ +void RCC_Configuration(void); +void GPIO_Configuration(void); +void ADC_Configuration(void); +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Main program + */ +int main(void) +{ + DMA_InitType DMA_InitStructure; + uint32_t adc_sum,i; + + log_init(); + log_info("\nthis is adc temperature sensor read demo.\n"); + + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* DMA channel1 configuration ----------------------------------------------*/ + DMA_DeInit(DMA_CH1); + DMA_InitStructure.PeriphAddr = (uint32_t)&ADC->DAT; + DMA_InitStructure.MemAddr = (uint32_t)ADCConvertedBuffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = ADC_BUF_SIZE; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.Priority = DMA_PRIORITY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(DMA_CH1, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_ADC, DMA, DMA_CH1, ENABLE); + + /* Enable DMA channel 1 */ + DMA_EnableChannel(DMA_CH1, ENABLE); + ADC_SetOverSampleCounter(ADC,3); + ADC_EnableBypassFilter(ADC, ENABLE); + ADC_ConfigChannel(ADC, ADC_CTRL_CH_7); + ADC_ConfigContinuousMode(ADC, ENABLE); + ADC_EnableDMA(ADC, ENABLE); + ADC_EnableTS(ADC, ENABLE); + ADC_Enable(ADC, ENABLE); + + while (1) + { + + /* Transfer complete */ + while (!DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)); + adc_sum = 0; + for(i=0;i + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/MDK-ARM/ADC_WDT.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/MDK-ARM/ADC_WDT.uvprojx new file mode 100644 index 0000000..6e14599 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/MDK-ARM/ADC_WDT.uvprojx @@ -0,0 +1,478 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + ADC_WDT + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\ADC_WDT.bin .\Objects\ADC_WDT.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/inc/main.h new file mode 100644 index 0000000..b63fbb3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/inc/main.h @@ -0,0 +1,84 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include "n32wb03x.h" + +#define ADC_AWD_HIG_THRESHOLD 800 +#define ADC_AWD_LOW_THRESHOLD 100 + + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/readme.txt new file mode 100644 index 0000000..4768d07 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/readme.txt @@ -0,0 +1,27 @@ + +1. Function description + 1. ADC analog watchdog feature work at channel 1 which is PB10. + 2. Enable the ADC continuous mode, analog watchdog and interrupt feature. + 3. The analog watchdog flag will set and active ADC interrupt when the ADC value highter than high threshold value, + or lower than the low threshold value. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. Clock source: + HSE=32M, HSI=64M, AHB=64M, APB1=32M, APB2=64M, ADC CLK=HSE/8 + 2. Port configuration: + PB10 is selected as analog function, ADC conversion channel 1 (low voltage channel) + 3. ADC: + ADC configuration: continuous conversion, continuous mode, 10-bit data, enable analog watchdog and interrupt mode + conversion channel 1 is the analog voltage data of PB10, + + 4. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + Instructions: + 1. Download after compiling and reset to rum the program, check conversion result at log. + 2. By changing the voltage of the PB10 pin, when the voltage over the threshold, it set the analog watchdog state bit(AWD_F) and active ADC interrupt. + +4. Matters needing attention diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/src/main.c new file mode 100644 index 0000000..5b6ffed --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/src/main.c @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void ADC_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + log_info("\nThis is adc analog watchdog demo.\r\n"); + log_info("AWD interrupt ative when adc value higher than %d or lower than %d\r\n",\ + ADC_AWD_HIG_THRESHOLD,ADC_AWD_LOW_THRESHOLD); + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* Configure the ADC NVIC */ + NVIC_SetPriority(ADC_IRQn,0); + NVIC_EnableIRQ(ADC_IRQn); + + ADC_ConfigChannel(ADC, ADC_CTRL_CH_1); + ADC_EnableBypassFilter(ADC, ENABLE); + ADC_ConfigContinuousMode(ADC, ENABLE); + ADC_ConfigAnalogWatchdogThresholds(ADC, ADC_AWD_HIG_THRESHOLD, ADC_AWD_LOW_THRESHOLD); + ADC_ConfigInt(ADC, ADC_INT_AWD, ENABLE); + ADC_EnableAWD(ADC, ENABLE); + ADC_Enable(ADC, ENABLE); + while (1) + { + } +} + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks */ + /* Enable GPIOB clocks */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + /* Enable ADC clocks */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC, ENABLE); + + RCC_ConfigAdcClk(RCC_ADCCLK_SRC_AUDIOPLL); + + /* enable ADC 4M clock */ + RCC_Enable_ADC_CLK_SRC_AUDIOPLL(ENABLE); +} + + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure PB.10 (ADC Channel1) as analog input --------*/ + GPIO_InitStructure.Pin = GPIO_PIN_10; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ + +/*************** (C) COPYRIGHT NSING Technologies Inc *****END OF FILE***************/ + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/src/n32wb03x_it.c new file mode 100644 index 0000000..7bcd0b8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/ADC/ADC_WDT/src/n32wb03x_it.c @@ -0,0 +1,126 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + + +void ADC_IRQHandler(void) +{ + if(ADC_GetFlagStatus(ADC, ADC_FLAG_AWD) == SET) + { + ADC_ClearFlag(ADC, ADC_FLAG_AWD); + log_info("AWD interrupt, the adc value is higher than %d or lower than %d\r\n",\ + ADC_AWD_HIG_THRESHOLD,ADC_AWD_LOW_THRESHOLD); + } +} +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/MDK-ARM/CoreMark_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/MDK-ARM/CoreMark_Proj.uvoptx new file mode 100644 index 0000000..c617ff0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/MDK-ARM/CoreMark_Proj.uvoptx @@ -0,0 +1,435 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\startup\startup_n32wb03x_CoreMark.s + startup_n32wb03x_CoreMark.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + COREMARK + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\coremark\core_list_join.c + core_list_join.c + 0 + 0 + + + 5 + 11 + 1 + 0 + 0 + 0 + ..\coremark\core_main.c + core_main.c + 0 + 0 + + + 5 + 12 + 1 + 0 + 0 + 0 + ..\coremark\core_matrix.c + core_matrix.c + 0 + 0 + + + 5 + 13 + 1 + 0 + 0 + 0 + ..\coremark\core_portme.c + core_portme.c + 0 + 0 + + + 5 + 14 + 1 + 0 + 0 + 0 + ..\coremark\core_state.c + core_state.c + 0 + 0 + + + 5 + 15 + 1 + 0 + 0 + 0 + ..\coremark\core_util.c + core_util.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 6 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 7 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/MDK-ARM/CoreMark_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/MDK-ARM/CoreMark_Proj.uvprojx new file mode 100644 index 0000000..2d3deee --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/MDK-ARM/CoreMark_Proj.uvprojx @@ -0,0 +1,510 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + CoreMark_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\CoreMark_Proj.bin .\Objects\CoreMark_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 4 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, SYSCLK_SRC=SYSCLK_USE_HSE_PLL + + ..\inc;..\coremark;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x_CoreMark.s + 2 + ..\startup\startup_n32wb03x_CoreMark.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + COREMARK + + + core_list_join.c + 1 + ..\coremark\core_list_join.c + + + core_main.c + 1 + ..\coremark\core_main.c + + + core_matrix.c + 1 + ..\coremark\core_matrix.c + + + core_portme.c + 1 + ..\coremark\core_portme.c + + + core_state.c + 1 + ..\coremark\core_state.c + + + core_util.c + 1 + ..\coremark\core_util.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_list_join.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_list_join.c new file mode 100644 index 0000000..a58857c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_list_join.c @@ -0,0 +1,556 @@ +/* +Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Original Author: Shay Gal-on +*/ + +#include "coremark.h" +/* +Topic: Description + Benchmark using a linked list. + + Linked list is a common data structure used in many applications. + + For our purposes, this will excercise the memory units of the processor. + In particular, usage of the list pointers to find and alter data. + + We are not using Malloc since some platforms do not support this library. + + Instead, the memory block being passed in is used to create a list, + and the benchmark takes care not to add more items then can be + accomodated by the memory block. The porting layer will make sure + that we have a valid memory block. + + All operations are done in place, without using any extra memory. + + The list itself contains list pointers and pointers to data items. + Data items contain the following: + + idx - An index that captures the initial order of the list. + data - Variable data initialized based on the input parameters. The 16b are divided as follows: + o Upper 8b are backup of original data. + o Bit 7 indicates if the lower 7 bits are to be used as is or calculated. + o Bits 0-2 indicate type of operation to perform to get a 7b value. + o Bits 3-6 provide input for the operation. + +*/ + +/* local functions */ + +list_head* core_list_find(list_head* list, list_data* info); +list_head* core_list_reverse(list_head* list); +list_head* core_list_remove(list_head* item); +list_head* core_list_undo_remove(list_head* item_removed, list_head* item_modified); +list_head* core_list_insert_new(list_head* insert_point, + list_data* info, + list_head** memblock, + list_data** datablock, + list_head* memblock_end, + list_data* datablock_end); +typedef ee_s32 (*list_cmp)(list_data* a, list_data* b, core_results* res); +list_head* core_list_mergesort(list_head* list, list_cmp cmp, core_results* res); + +ee_s16 calc_func(ee_s16* pdata, core_results* res) +{ + ee_s16 data = *pdata; + ee_s16 retval; + ee_u8 optype = (data >> 7) & 1; /* bit 7 indicates if the function result has been cached */ + if (optype) /* if cached, use cache */ + return (data & 0x007f); + else + { /* otherwise calculate and cache the result */ + ee_s16 flag = data & 0x7; /* bits 0-2 is type of function to perform */ + ee_s16 dtype = ((data >> 3) & 0xf); /* bits 3-6 is specific data for the operation */ + dtype |= dtype << 4; /* replicate the lower 4 bits to get an 8b value */ + switch (flag) + { + case 0: + if (dtype < 0x22) /* set min period for bit corruption */ + dtype = 0x22; + retval = core_bench_state(res->size, res->memblock[3], res->seed1, res->seed2, dtype, res->crc); + if (res->crcstate == 0) + res->crcstate = retval; + break; + case 1: + retval = core_bench_matrix(&(res->mat), dtype, res->crc); + if (res->crcmatrix == 0) + res->crcmatrix = retval; + break; + default: + retval = data; + break; + } + res->crc = crcu16(retval, res->crc); + retval &= 0x007f; + *pdata = (data & 0xff00) | 0x0080 | retval; /* cache the result */ + return retval; + } +} +/* Function: cmp_complex + Compare the data item in a list cell. + + Can be used by mergesort. +*/ +ee_s32 cmp_complex(list_data* a, list_data* b, core_results* res) +{ + ee_s16 val1 = calc_func(&(a->data16), res); + ee_s16 val2 = calc_func(&(b->data16), res); + return val1 - val2; +} + +/* Function: cmp_idx + Compare the idx item in a list cell, and regen the data. + + Can be used by mergesort. +*/ +ee_s32 cmp_idx(list_data* a, list_data* b, core_results* res) +{ + if (res == NULL) + { + a->data16 = (a->data16 & 0xff00) | (0x00ff & (a->data16 >> 8)); + b->data16 = (b->data16 & 0xff00) | (0x00ff & (b->data16 >> 8)); + } + return a->idx - b->idx; +} + +void copy_info(list_data* to, list_data* from) +{ + to->data16 = from->data16; + to->idx = from->idx; +} + +/* Benchmark for linked list: + - Try to find multiple data items. + - List sort + - Operate on data from list (crc) + - Single remove/reinsert + * At the end of this function, the list is back to original state +*/ +ee_u16 core_bench_list(core_results* res, ee_s16 finder_idx) +{ + ee_u16 retval = 0; + ee_u16 found = 0, missed = 0; + list_head* list = res->list; + ee_s16 find_num = res->seed3; + list_head* this_find; + list_head *finder, *remover; + list_data info; + ee_s16 i; + + info.idx = finder_idx; + /* find values in the list, and change the list each time (reverse and cache if value found) */ + for (i = 0; i < find_num; i++) + { + info.data16 = (i & 0xff); + this_find = core_list_find(list, &info); + list = core_list_reverse(list); + if (this_find == NULL) + { + missed++; + retval += (list->next->info->data16 >> 8) & 1; + } + else + { + found++; + if (this_find->info->data16 & 0x1) /* use found value */ + retval += (this_find->info->data16 >> 9) & 1; + /* and cache next item at the head of the list (if any) */ + if (this_find->next != NULL) + { + finder = this_find->next; + this_find->next = finder->next; + finder->next = list->next; + list->next = finder; + } + } + if (info.idx >= 0) + info.idx++; +#if CORE_DEBUG + ee_printf("List find %d: [%d,%d,%d]\n", i, retval, missed, found); +#endif + } + retval += found * 4 - missed; + /* sort the list by data content and remove one item*/ + if (finder_idx > 0) + list = core_list_mergesort(list, cmp_complex, res); + remover = core_list_remove(list->next); + /* CRC data content of list from location of index N forward, and then undo remove */ + finder = core_list_find(list, &info); + if (!finder) + finder = list->next; + while (finder) + { + retval = crc16(list->info->data16, retval); + finder = finder->next; + } +#if CORE_DEBUG + ee_printf("List sort 1: %04x\n", retval); +#endif + remover = core_list_undo_remove(remover, list->next); + /* sort the list by index, in effect returning the list to original state */ + list = core_list_mergesort(list, cmp_idx, NULL); + /* CRC data content of list */ + finder = list->next; + while (finder) + { + retval = crc16(list->info->data16, retval); + finder = finder->next; + } +#if CORE_DEBUG + ee_printf("List sort 2: %04x\n", retval); +#endif + return retval; +} +/* Function: core_list_init + Initialize list with data. + + Parameters: + blksize - Size of memory to be initialized. + memblock - Pointer to memory block. + seed - Actual values chosen depend on the seed parameter. + The seed parameter MUST be supplied from a source that cannot be determined at compile time + + Returns: + Pointer to the head of the list. + +*/ +list_head* core_list_init(ee_u32 blksize, list_head* memblock, ee_s16 seed) +{ + /* calculated pointers for the list */ + ee_u32 per_item = 16 + sizeof(struct list_data_s); + ee_u32 size = + (blksize / per_item) + - 2; /* to accomodate systems with 64b pointers, and make sure same code is executed, set max list elements */ + list_head* memblock_end = memblock + size; + list_data* datablock = (list_data*)(memblock_end); + list_data* datablock_end = datablock + size; + /* some useful variables */ + ee_u32 i; + list_head *finder, *list = memblock; + list_data info; + + /* create a fake items for the list head and tail */ + list->next = NULL; + list->info = datablock; + list->info->idx = 0x0000; + list->info->data16 = (ee_s16)0x8080; + memblock++; + datablock++; + info.idx = 0x7fff; + info.data16 = (ee_s16)0xffff; + core_list_insert_new(list, &info, &memblock, &datablock, memblock_end, datablock_end); + + /* then insert size items */ + for (i = 0; i < size; i++) + { + ee_u16 datpat = ((ee_u16)(seed ^ i) & 0xf); + ee_u16 dat = (datpat << 3) | (i & 0x7); /* alternate between algorithms */ + info.data16 = (dat << 8) | dat; /* fill the data with actual data and upper bits with rebuild value */ + core_list_insert_new(list, &info, &memblock, &datablock, memblock_end, datablock_end); + } + /* and now index the list so we know initial seed order of the list */ + finder = list->next; + i = 1; + while (finder->next != NULL) + { + if (i < size / 5) /* first 20% of the list in order */ + finder->info->idx = i++; + else + { + ee_u16 pat = (ee_u16)(i++ ^ seed); /* get a pseudo random number */ + finder->info->idx = + 0x3fff & (((i & 0x07) << 8) | pat); /* make sure the mixed items end up after the ones in sequence */ + } + finder = finder->next; + } + list = core_list_mergesort(list, cmp_idx, NULL); +#if CORE_DEBUG + ee_printf("Initialized list:\n"); + finder = list; + while (finder) + { + ee_printf("[%04x,%04x]", finder->info->idx, (ee_u16)finder->info->data16); + finder = finder->next; + } + ee_printf("\n"); +#endif + return list; +} + +/* Function: core_list_insert + Insert an item to the list + + Parameters: + insert_point - where to insert the item. + info - data for the cell. + memblock - pointer for the list header + datablock - pointer for the list data + memblock_end - end of region for list headers + datablock_end - end of region for list data + + Returns: + Pointer to new item. +*/ +list_head* core_list_insert_new(list_head* insert_point, + list_data* info, + list_head** memblock, + list_data** datablock, + list_head* memblock_end, + list_data* datablock_end) +{ + list_head* newitem; + + if ((*memblock + 1) >= memblock_end) + return NULL; + if ((*datablock + 1) >= datablock_end) + return NULL; + + newitem = *memblock; + (*memblock)++; + newitem->next = insert_point->next; + insert_point->next = newitem; + + newitem->info = *datablock; + (*datablock)++; + copy_info(newitem->info, info); + + return newitem; +} + +/* Function: core_list_remove + Remove an item from the list. + + Operation: + For a singly linked list, remove by copying the data from the next item + over to the current cell, and unlinking the next item. + + Note: + since there is always a fake item at the end of the list, no need to check for NULL. + + Returns: + Removed item. +*/ +list_head* core_list_remove(list_head* item) +{ + list_data* tmp; + list_head* ret = item->next; + /* swap data pointers */ + tmp = item->info; + item->info = ret->info; + ret->info = tmp; + /* and eliminate item */ + item->next = item->next->next; + ret->next = NULL; + return ret; +} + +/* Function: core_list_undo_remove + Undo a remove operation. + + Operation: + Since we want each iteration of the benchmark to be exactly the same, + we need to be able to undo a remove. + Link the removed item back into the list, and switch the info items. + + Parameters: + item_removed - Return value from the + item_modified - List item that was modified during + + Returns: + The item that was linked back to the list. + +*/ +list_head* core_list_undo_remove(list_head* item_removed, list_head* item_modified) +{ + list_data* tmp; + /* swap data pointers */ + tmp = item_removed->info; + item_removed->info = item_modified->info; + item_modified->info = tmp; + /* and insert item */ + item_removed->next = item_modified->next; + item_modified->next = item_removed; + return item_removed; +} + +/* Function: core_list_find + Find an item in the list + + Operation: + Find an item by idx (if not 0) or specific data value + + Parameters: + list - list head + info - idx or data to find + + Returns: + Found item, or NULL if not found. +*/ +list_head* core_list_find(list_head* list, list_data* info) +{ + if (info->idx >= 0) + { + while (list && (list->info->idx != info->idx)) + list = list->next; + return list; + } + else + { + while (list && ((list->info->data16 & 0xff) != info->data16)) + list = list->next; + return list; + } +} +/* Function: core_list_reverse + Reverse a list + + Operation: + Rearrange the pointers so the list is reversed. + + Parameters: + list - list head + info - idx or data to find + + Returns: + Found item, or NULL if not found. +*/ + +list_head* core_list_reverse(list_head* list) +{ + list_head *next = NULL, *tmp; + while (list) + { + tmp = list->next; + list->next = next; + next = list; + list = tmp; + } + return next; +} +/* Function: core_list_mergesort + Sort the list in place without recursion. + + Description: + Use mergesort, as for linked list this is a realistic solution. + Also, since this is aimed at embedded, care was taken to use iterative rather then recursive algorithm. + The sort can either return the list to original order (by idx) , + or use the data item to invoke other other algorithms and change the order of the list. + + Parameters: + list - list to be sorted. + cmp - cmp function to use + + Returns: + New head of the list. + + Note: + We have a special header for the list that will always be first, + but the algorithm could theoretically modify where the list starts. + + */ +list_head* core_list_mergesort(list_head* list, list_cmp cmp, core_results* res) +{ + list_head *p, *q, *e, *tail; + ee_s32 insize, nmerges, psize, qsize, i; + + insize = 1; + + while (1) + { + p = list; + list = NULL; + tail = NULL; + + nmerges = 0; /* count number of merges we do in this pass */ + + while (p) + { + nmerges++; /* there exists a merge to be done */ + /* step `insize' places along from p */ + q = p; + psize = 0; + for (i = 0; i < insize; i++) + { + psize++; + q = q->next; + if (!q) + break; + } + + /* if q hasn't fallen off end, we have two lists to merge */ + qsize = insize; + + /* now we have two lists; merge them */ + while (psize > 0 || (qsize > 0 && q)) + { + /* decide whether next element of merge comes from p or q */ + if (psize == 0) + { + /* p is empty; e must come from q. */ + e = q; + q = q->next; + qsize--; + } + else if (qsize == 0 || !q) + { + /* q is empty; e must come from p. */ + e = p; + p = p->next; + psize--; + } + else if (cmp(p->info, q->info, res) <= 0) + { + /* First element of p is lower (or same); e must come from p. */ + e = p; + p = p->next; + psize--; + } + else + { + /* First element of q is lower; e must come from q. */ + e = q; + q = q->next; + qsize--; + } + + /* add the next element to the merged list */ + if (tail) + { + tail->next = e; + } + else + { + list = e; + } + tail = e; + } + + /* now p has stepped `insize' places along, and q has too */ + p = q; + } + + tail->next = NULL; + + /* If we have done only one merge, we're finished. */ + if (nmerges <= 1) /* allow for nmerges==0, the empty list case */ + return list; + + /* Otherwise repeat, merging lists twice the size */ + insize *= 2; + } +#if COMPILER_REQUIRES_SORT_RETURN + return list; +#endif +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_main.c new file mode 100644 index 0000000..3e81369 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_main.c @@ -0,0 +1,400 @@ +/* +Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Original Author: Shay Gal-on +*/ + +/* File: core_main.c + This file contains the framework to acquire a block of memory, seed initial parameters, tun t he benchmark and + report the results. +*/ +#include "coremark.h" + +/* Function: iterate + Run the benchmark for a specified number of iterations. + + Operation: + For each type of benchmarked algorithm: + a - Initialize the data block for the algorithm. + b - Execute the algorithm N times. + + Returns: + NULL. +*/ +static ee_u16 list_known_crc[] = {(ee_u16)0xd4b0, (ee_u16)0x3340, (ee_u16)0x6a79, (ee_u16)0xe714, (ee_u16)0xe3c1}; +static ee_u16 matrix_known_crc[] = {(ee_u16)0xbe52, (ee_u16)0x1199, (ee_u16)0x5608, (ee_u16)0x1fd7, (ee_u16)0x0747}; +static ee_u16 state_known_crc[] = {(ee_u16)0x5e47, (ee_u16)0x39bf, (ee_u16)0xe5a4, (ee_u16)0x8e3a, (ee_u16)0x8d84}; +void* iterate(void* pres) +{ + ee_u32 i; + ee_u16 crc; + core_results* res = (core_results*)pres; + ee_u32 iterations = res->iterations; + res->crc = 0; + res->crclist = 0; + res->crcmatrix = 0; + res->crcstate = 0; + + for (i = 0; i < iterations; i++) + { + crc = core_bench_list(res, 1); + res->crc = crcu16(crc, res->crc); + crc = core_bench_list(res, -1); + res->crc = crcu16(crc, res->crc); + if (i == 0) + res->crclist = res->crc; + } + return NULL; +} + +#if (SEED_METHOD == SEED_ARG) +ee_s32 get_seed_args(int i, int argc, char* argv[]); +#define get_seed(x) (ee_s16) get_seed_args(x, argc, argv) +#define get_seed_32(x) get_seed_args(x, argc, argv) +#else /* via function or volatile */ +ee_s32 get_seed_32(int i); +#define get_seed(x) (ee_s16) get_seed_32(x) +#endif + +#if (MEM_METHOD == MEM_STATIC) +ee_u8 static_memblk[TOTAL_DATA_SIZE]; +#endif +char* mem_name[3] = {"Static", "Heap", "Stack"}; +/* Function: main + Main entry routine for the benchmark. + This function is responsible for the following steps: + + 1 - Initialize input seeds from a source that cannot be determined at compile time. + 2 - Initialize memory block for use. + 3 - Run and time the benchmark. + 4 - Report results, testing the validity of the output if the seeds are known. + + Arguments: + 1 - first seed : Any value + 2 - second seed : Must be identical to first for iterations to be identical + 3 - third seed : Any value, should be at least an order of magnitude less then the input size, but bigger + then 32. 4 - Iterations : Special, if set to 0, iterations will be automatically determined such that the benchmark + will run between 10 to 100 secs + +*/ + +#if MAIN_HAS_NOARGC +MAIN_RETURN_TYPE CoreMark(void) +{ + int argc = 0; + char* argv[1]; +#else +MAIN_RETURN_TYPE CoreMark(int argc, char* argv[]) +{ +#endif + ee_u16 i, j = 0, num_algorithms = 0; + ee_s16 known_id = -1, total_errors = 0; + ee_u16 seedcrc = 0; + CORE_TICKS total_time; + core_results results[MULTITHREAD]; +#if (MEM_METHOD == MEM_STACK) + ee_u8 stack_memblock[TOTAL_DATA_SIZE * MULTITHREAD]; +#endif + /* first call any initializations needed */ + portable_init(&(results[0].port), &argc, argv); + /* First some checks to make sure benchmark will run ok */ + if (sizeof(struct list_head_s) > 128) + { + ee_printf("list_head structure too big for comparable data!\n"); + return MAIN_RETURN_VAL; + } + results[0].seed1 = get_seed(1); + results[0].seed2 = get_seed(2); + results[0].seed3 = get_seed(3); + results[0].iterations = get_seed_32(4); +#if CORE_DEBUG + results[0].iterations = 1; +#endif + results[0].execs = get_seed_32(5); + if (results[0].execs == 0) + { /* if not supplied, execute all algorithms */ + results[0].execs = ALL_ALGORITHMS_MASK; + } + /* put in some default values based on one seed only for easy testing */ + if ((results[0].seed1 == 0) && (results[0].seed2 == 0) && (results[0].seed3 == 0)) + { /* validation run */ + results[0].seed1 = 0; + results[0].seed2 = 0; + results[0].seed3 = 0x66; + } + if ((results[0].seed1 == 1) && (results[0].seed2 == 0) && (results[0].seed3 == 0)) + { /* perfromance run */ + results[0].seed1 = 0x3415; + results[0].seed2 = 0x3415; + results[0].seed3 = 0x66; + } +#if (MEM_METHOD == MEM_STATIC) + results[0].memblock[0] = (void*)static_memblk; + results[0].size = TOTAL_DATA_SIZE; + results[0].err = 0; +#if (MULTITHREAD > 1) +#error "Cannot use a static data area with multiple contexts!" +#endif +#elif (MEM_METHOD == MEM_MALLOC) + for (i = 0; i < MULTITHREAD; i++) + { + ee_s32 malloc_override = get_seed(7); + if (malloc_override != 0) + results[i].size = malloc_override; + else + results[i].size = TOTAL_DATA_SIZE; + results[i].memblock[0] = portable_malloc(results[i].size); + results[i].seed1 = results[0].seed1; + results[i].seed2 = results[0].seed2; + results[i].seed3 = results[0].seed3; + results[i].err = 0; + results[i].execs = results[0].execs; + } +#elif (MEM_METHOD == MEM_STACK) +for (i = 0; i < MULTITHREAD; i++) +{ + results[i].memblock[0] = stack_memblock + i * TOTAL_DATA_SIZE; + results[i].size = TOTAL_DATA_SIZE; + results[i].seed1 = results[0].seed1; + results[i].seed2 = results[0].seed2; + results[i].seed3 = results[0].seed3; + results[i].err = 0; + results[i].execs = results[0].execs; +} +#else +#error "Please define a way to initialize a memory block." +#endif + /* Data init */ + /* Find out how space much we have based on number of algorithms */ + for (i = 0; i < NUM_ALGORITHMS; i++) + { + if ((1 << (ee_u32)i) & results[0].execs) + num_algorithms++; + } + for (i = 0; i < MULTITHREAD; i++) + results[i].size = results[i].size / num_algorithms; + /* Assign pointers */ + for (i = 0; i < NUM_ALGORITHMS; i++) + { + ee_u32 ctx; + if ((1 << (ee_u32)i) & results[0].execs) + { + for (ctx = 0; ctx < MULTITHREAD; ctx++) + results[ctx].memblock[i + 1] = (char*)(results[ctx].memblock[0]) + results[0].size * j; + j++; + } + } + /* call inits */ + for (i = 0; i < MULTITHREAD; i++) + { + if (results[i].execs & ID_LIST) + { + results[i].list = core_list_init(results[0].size, results[i].memblock[1], results[i].seed1); + } + if (results[i].execs & ID_MATRIX) + { + core_init_matrix(results[0].size, + results[i].memblock[2], + (ee_s32)results[i].seed1 | (((ee_s32)results[i].seed2) << 16), + &(results[i].mat)); + } + if (results[i].execs & ID_STATE) + { + core_init_state(results[0].size, results[i].seed1, results[i].memblock[3]); + } + } + + /* automatically determine number of iterations if not set */ + if (results[0].iterations == 0) + { + secs_ret secs_passed = 0; + ee_u32 divisor; + results[0].iterations = 1; + while (secs_passed < (secs_ret)1) + { + results[0].iterations *= 10; + start_time(); + iterate(&results[0]); + stop_time(); + secs_passed = time_in_secs(get_time()); + } + /* now we know it executes for at least 1 sec, set actual run time at about 10 secs */ + divisor = (ee_u32)secs_passed; + if (divisor == 0) /* some machines cast float to int as 0 since this conversion is not defined by ANSI, but we + know at least one second passed */ + divisor = 1; + results[0].iterations *= 1 + 10 / divisor; + } + /* perform actual benchmark */ + start_time(); +#if (MULTITHREAD > 1) + if (default_num_contexts > MULTITHREAD) + { + default_num_contexts = MULTITHREAD; + } + for (i = 0; i < default_num_contexts; i++) + { + results[i].iterations = results[0].iterations; + results[i].execs = results[0].execs; + core_start_parallel(&results[i]); + } + for (i = 0; i < default_num_contexts; i++) + { + core_stop_parallel(&results[i]); + } +#else + iterate(&results[0]); +#endif + stop_time(); + total_time = get_time(); + /* get a function of the input to report */ + seedcrc = crc16(results[0].seed1, seedcrc); + seedcrc = crc16(results[0].seed2, seedcrc); + seedcrc = crc16(results[0].seed3, seedcrc); + seedcrc = crc16(results[0].size, seedcrc); + + switch (seedcrc) + { /* test known output for common seeds */ + case 0x8a02: /* seed1=0, seed2=0, seed3=0x66, size 2000 per algorithm */ + known_id = 0; + ee_printf("6k performance run parameters for coremark.\n"); + break; + case 0x7b05: /* seed1=0x3415, seed2=0x3415, seed3=0x66, size 2000 per algorithm */ + known_id = 1; + ee_printf("6k validation run parameters for coremark.\n"); + break; + case 0x4eaf: /* seed1=0x8, seed2=0x8, seed3=0x8, size 400 per algorithm */ + known_id = 2; + ee_printf("Profile generation run parameters for coremark.\n"); + break; + case 0xe9f5: /* seed1=0, seed2=0, seed3=0x66, size 666 per algorithm */ + known_id = 3; + ee_printf("2K performance run parameters for coremark.\n"); + break; + case 0x18f2: /* seed1=0x3415, seed2=0x3415, seed3=0x66, size 666 per algorithm */ + known_id = 4; + ee_printf("2K validation run parameters for coremark.\n"); + break; + default: + total_errors = -1; + break; + } + if (known_id >= 0) + { + for (i = 0; i < default_num_contexts; i++) + { + results[i].err = 0; + if ((results[i].execs & ID_LIST) && (results[i].crclist != list_known_crc[known_id])) + { + ee_printf( + "[%u]ERROR! list crc 0x%04x - should be 0x%04x\n", i, results[i].crclist, list_known_crc[known_id]); + results[i].err++; + } + if ((results[i].execs & ID_MATRIX) && (results[i].crcmatrix != matrix_known_crc[known_id])) + { + ee_printf("[%u]ERROR! matrix crc 0x%04x - should be 0x%04x\n", + i, + results[i].crcmatrix, + matrix_known_crc[known_id]); + results[i].err++; + } + if ((results[i].execs & ID_STATE) && (results[i].crcstate != state_known_crc[known_id])) + { + ee_printf("[%u]ERROR! state crc 0x%04x - should be 0x%04x\n", + i, + results[i].crcstate, + state_known_crc[known_id]); + results[i].err++; + } + total_errors += results[i].err; + } + } + total_errors += check_data_types(); + /* and report results */ + ee_printf("CoreMark Size : %lu\n", (long unsigned)results[0].size); + ee_printf("Total ticks : %lu\n", (long unsigned)total_time); +#if HAS_FLOAT + ee_printf("Total time (secs): %f\n", time_in_secs(total_time)); + if (time_in_secs(total_time) > 0) + ee_printf("Iterations/Sec : %f\n", default_num_contexts * results[0].iterations / time_in_secs(total_time)); +#else + ee_printf("Total time (secs): %d\n", time_in_secs(total_time)); + if (time_in_secs(total_time) > 0) + ee_printf("Iterations/Sec : %d\n", default_num_contexts * results[0].iterations / time_in_secs(total_time)); +#endif + if (time_in_secs(total_time) < 10) + { + ee_printf("ERROR! Must execute for at least 10 secs for a valid result!\n"); + total_errors++; + } + + ee_printf("Iterations : %lu\n", (long unsigned)default_num_contexts * results[0].iterations); + ee_printf("Compiler version : %s\n", COMPILER_VERSION); + ee_printf("Compiler flags : %s\n", COMPILER_FLAGS); +#if (MULTITHREAD > 1) + ee_printf("Parallel %s : %d\n", PARALLEL_METHOD, default_num_contexts); +#endif + ee_printf("Memory location : %s\n", MEM_LOCATION); + /* output for verification */ + ee_printf("seedcrc : 0x%04x\n", seedcrc); + if (results[0].execs & ID_LIST) + for (i = 0; i < default_num_contexts; i++) + ee_printf("[%d]crclist : 0x%04x\n", i, results[i].crclist); + if (results[0].execs & ID_MATRIX) + for (i = 0; i < default_num_contexts; i++) + ee_printf("[%d]crcmatrix : 0x%04x\n", i, results[i].crcmatrix); + if (results[0].execs & ID_STATE) + for (i = 0; i < default_num_contexts; i++) + ee_printf("[%d]crcstate : 0x%04x\n", i, results[i].crcstate); + for (i = 0; i < default_num_contexts; i++) + ee_printf("[%d]crcfinal : 0x%04x\n", i, results[i].crc); + if (total_errors == 0) + { + ee_printf("Correct operation validated. See README.md for run and reporting rules.\n"); +#if HAS_FLOAT + if (known_id == 3) + { + ee_printf("CoreMark 1.0 : %f / %s %s", + default_num_contexts * results[0].iterations / time_in_secs(total_time), + COMPILER_VERSION, + COMPILER_FLAGS); +#if defined(MEM_LOCATION) && !defined(MEM_LOCATION_UNSPEC) + ee_printf(" / %s", MEM_LOCATION); +#else + ee_printf(" / %s", mem_name[MEM_METHOD]); +#endif + +#if (MULTITHREAD > 1) + ee_printf(" / %d:%s", default_num_contexts, PARALLEL_METHOD); +#endif + ee_printf("\n"); + } +#endif + } + if (total_errors > 0) + ee_printf("Errors detected\n"); + if (total_errors < 0) + ee_printf( + "Cannot validate operation for these seed values, please compare with results on a known platform.\n"); + +#if (MEM_METHOD == MEM_MALLOC) + for (i = 0; i < MULTITHREAD; i++) + portable_free(results[i].memblock[0]); +#endif + /* And last call any target specific code for finalizing */ + portable_fini(&(results[0].port)); + + return MAIN_RETURN_VAL; +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_matrix.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_matrix.c new file mode 100644 index 0000000..a89be63 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_matrix.c @@ -0,0 +1,341 @@ +/* +Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Original Author: Shay Gal-on +*/ + +#include "coremark.h" +/* +Topic: Description + Matrix manipulation benchmark + + This very simple algorithm forms the basis of many more complex algorithms. + + The tight inner loop is the focus of many optimizations (compiler as well as hardware based) + and is thus relevant for embedded processing. + + The total available data space will be divided to 3 parts: + NxN Matrix A - initialized with small values (upper 3/4 of the bits all zero). + NxN Matrix B - initialized with medium values (upper half of the bits all zero). + NxN Matrix C - used for the result. + + The actual values for A and B must be derived based on input that is not available at compile time. +*/ +ee_s16 matrix_test(ee_u32 N, MATRES* C, MATDAT* A, MATDAT* B, MATDAT val); +ee_s16 matrix_sum(ee_u32 N, MATRES* C, MATDAT clipval); +void matrix_mul_const(ee_u32 N, MATRES* C, MATDAT* A, MATDAT val); +void matrix_mul_vect(ee_u32 N, MATRES* C, MATDAT* A, MATDAT* B); +void matrix_mul_matrix(ee_u32 N, MATRES* C, MATDAT* A, MATDAT* B); +void matrix_mul_matrix_bitextract(ee_u32 N, MATRES* C, MATDAT* A, MATDAT* B); +void matrix_add_const(ee_u32 N, MATDAT* A, MATDAT val); + +#define matrix_test_next(x) (x + 1) +#define matrix_clip(x, y) ((y) ? (x)&0x0ff : (x)&0x0ffff) +#define matrix_big(x) (0xf000 | (x)) +#define bit_extract(x, from, to) (((x) >> (from)) & (~(0xffffffff << (to)))) + +#if CORE_DEBUG +void printmat(MATDAT* A, ee_u32 N, char* name) +{ + ee_u32 i, j; + ee_printf("Matrix %s [%dx%d]:\n", name, N, N); + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + { + if (j != 0) + ee_printf(","); + ee_printf("%d", A[i * N + j]); + } + ee_printf("\n"); + } +} +void printmatC(MATRES* C, ee_u32 N, char* name) +{ + ee_u32 i, j; + ee_printf("Matrix %s [%dx%d]:\n", name, N, N); + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + { + if (j != 0) + ee_printf(","); + ee_printf("%d", C[i * N + j]); + } + ee_printf("\n"); + } +} +#endif +/* Function: core_bench_matrix + Benchmark function + + Iterate N times, + changing the matrix values slightly by a constant amount each time. +*/ +ee_u16 core_bench_matrix(mat_params* p, ee_s16 seed, ee_u16 crc) +{ + ee_u32 N = p->N; + MATRES* C = p->C; + MATDAT* A = p->A; + MATDAT* B = p->B; + MATDAT val = (MATDAT)seed; + + crc = crc16(matrix_test(N, C, A, B, val), crc); + + return crc; +} + +/* Function: matrix_test + Perform matrix manipulation. + + Parameters: + N - Dimensions of the matrix. + C - memory for result matrix. + A - input matrix + B - operator matrix (not changed during operations) + + Returns: + A CRC value that captures all results calculated in the function. + In particular, crc of the value calculated on the result matrix + after each step by . + + Operation: + + 1 - Add a constant value to all elements of a matrix. + 2 - Multiply a matrix by a constant. + 3 - Multiply a matrix by a vector. + 4 - Multiply a matrix by a matrix. + 5 - Add a constant value to all elements of a matrix. + + After the last step, matrix A is back to original contents. +*/ +ee_s16 matrix_test(ee_u32 N, MATRES* C, MATDAT* A, MATDAT* B, MATDAT val) +{ + ee_u16 crc = 0; + MATDAT clipval = matrix_big(val); + + matrix_add_const(N, A, val); /* make sure data changes */ +#if CORE_DEBUG + printmat(A, N, "matrix_add_const"); +#endif + matrix_mul_const(N, C, A, val); + crc = crc16(matrix_sum(N, C, clipval), crc); +#if CORE_DEBUG + printmatC(C, N, "matrix_mul_const"); +#endif + matrix_mul_vect(N, C, A, B); + crc = crc16(matrix_sum(N, C, clipval), crc); +#if CORE_DEBUG + printmatC(C, N, "matrix_mul_vect"); +#endif + matrix_mul_matrix(N, C, A, B); + crc = crc16(matrix_sum(N, C, clipval), crc); +#if CORE_DEBUG + printmatC(C, N, "matrix_mul_matrix"); +#endif + matrix_mul_matrix_bitextract(N, C, A, B); + crc = crc16(matrix_sum(N, C, clipval), crc); +#if CORE_DEBUG + printmatC(C, N, "matrix_mul_matrix_bitextract"); +#endif + + matrix_add_const(N, A, -val); /* return matrix to initial value */ + return crc; +} + +/* Function : matrix_init + Initialize the memory block for matrix benchmarking. + + Parameters: + blksize - Size of memory to be initialized. + memblk - Pointer to memory block. + seed - Actual values chosen depend on the seed parameter. + p - pointers to containing initialized matrixes. + + Returns: + Matrix dimensions. + + Note: + The seed parameter MUST be supplied from a source that cannot be determined at compile time +*/ +ee_u32 core_init_matrix(ee_u32 blksize, void* memblk, ee_s32 seed, mat_params* p) +{ + ee_u32 N = 0; + MATDAT* A; + MATDAT* B; + ee_s32 order = 1; + MATDAT val; + ee_u32 i = 0, j = 0; + if (seed == 0) + seed = 1; + while (j < blksize) + { + i++; + j = i * i * 2 * 4; + } + N = i - 1; + A = (MATDAT*)align_mem(memblk); + B = A + N * N; + + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + { + seed = ((order * seed) % 65536); + val = (seed + order); + val = matrix_clip(val, 0); + B[i * N + j] = val; + val = (val + order); + val = matrix_clip(val, 1); + A[i * N + j] = val; + order++; + } + } + + p->A = A; + p->B = B; + p->C = (MATRES*)align_mem(B + N * N); + p->N = N; +#if CORE_DEBUG + printmat(A, N, "A"); + printmat(B, N, "B"); +#endif + return N; +} + +/* Function: matrix_sum + Calculate a function that depends on the values of elements in the matrix. + + For each element, accumulate into a temporary variable. + + As long as this value is under the parameter clipval, + add 1 to the result if the element is bigger then the previous. + + Otherwise, reset the accumulator and add 10 to the result. +*/ +ee_s16 matrix_sum(ee_u32 N, MATRES* C, MATDAT clipval) +{ + MATRES tmp = 0, prev = 0, cur = 0; + ee_s16 ret = 0; + ee_u32 i, j; + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + { + cur = C[i * N + j]; + tmp += cur; + if (tmp > clipval) + { + ret += 10; + tmp = 0; + } + else + { + ret += (cur > prev) ? 1 : 0; + } + prev = cur; + } + } + return ret; +} + +/* Function: matrix_mul_const + Multiply a matrix by a constant. + This could be used as a scaler for instance. +*/ +void matrix_mul_const(ee_u32 N, MATRES* C, MATDAT* A, MATDAT val) +{ + ee_u32 i, j; + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + { + C[i * N + j] = (MATRES)A[i * N + j] * (MATRES)val; + } + } +} + +/* Function: matrix_add_const + Add a constant value to all elements of a matrix. +*/ +void matrix_add_const(ee_u32 N, MATDAT* A, MATDAT val) +{ + ee_u32 i, j; + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + { + A[i * N + j] += val; + } + } +} + +/* Function: matrix_mul_vect + Multiply a matrix by a vector. + This is common in many simple filters (e.g. fir where a vector of coefficients is applied to the matrix.) +*/ +void matrix_mul_vect(ee_u32 N, MATRES* C, MATDAT* A, MATDAT* B) +{ + ee_u32 i, j; + for (i = 0; i < N; i++) + { + C[i] = 0; + for (j = 0; j < N; j++) + { + C[i] += (MATRES)A[i * N + j] * (MATRES)B[j]; + } + } +} + +/* Function: matrix_mul_matrix + Multiply a matrix by a matrix. + Basic code is used in many algorithms, mostly with minor changes such as scaling. +*/ +void matrix_mul_matrix(ee_u32 N, MATRES* C, MATDAT* A, MATDAT* B) +{ + ee_u32 i, j, k; + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + { + C[i * N + j] = 0; + for (k = 0; k < N; k++) + { + C[i * N + j] += (MATRES)A[i * N + k] * (MATRES)B[k * N + j]; + } + } + } +} + +/* Function: matrix_mul_matrix_bitextract + Multiply a matrix by a matrix, and extract some bits from the result. + Basic code is used in many algorithms, mostly with minor changes such as scaling. +*/ +void matrix_mul_matrix_bitextract(ee_u32 N, MATRES* C, MATDAT* A, MATDAT* B) +{ + ee_u32 i, j, k; + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + { + C[i * N + j] = 0; + for (k = 0; k < N; k++) + { + MATRES tmp = (MATRES)A[i * N + k] * (MATRES)B[k * N + j]; + C[i * N + j] += bit_extract(tmp, 2, 4) * bit_extract(tmp, 5, 7); + } + } + } +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_portme.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_portme.c new file mode 100644 index 0000000..5d7e97d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_portme.c @@ -0,0 +1,140 @@ +/* +Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Original Author: Shay Gal-on +*/ + +#include +#include +#include +#include "coremark.h" + +#if VALIDATION_RUN +volatile ee_s32 seed1_volatile = 0x3415; +volatile ee_s32 seed2_volatile = 0x3415; +volatile ee_s32 seed3_volatile = 0x66; +#endif +#if PERFORMANCE_RUN +volatile ee_s32 seed1_volatile = 0x0; +volatile ee_s32 seed2_volatile = 0x0; +volatile ee_s32 seed3_volatile = 0x66; +#endif +#if PROFILE_RUN +volatile ee_s32 seed1_volatile = 0x8; +volatile ee_s32 seed2_volatile = 0x8; +volatile ee_s32 seed3_volatile = 0x8; +#endif +volatile ee_s32 seed4_volatile = ITERATIONS; +volatile ee_s32 seed5_volatile = 0; +/* Porting : Timing functions + How to capture time and convert to seconds must be ported to whatever is supported by the platform. + e.g. Read value from on board RTC, read value from cpu clock cycles performance counter etc. + Sample implementation for standard time.h and windows.h definitions included. +*/ +/* Define : TIMER_RES_DIVIDER + Divider to trade off timer resolution and total time that can be measured. + + Use lower values to increase resolution, but make sure that overflow does not occur. + If there are issues with the return value overflowing, increase this value. + */ +/* #define NSECS_PER_SEC CLOCKS_PER_SEC +#define CORETIMETYPE clock_t +#define GETMYTIME(_t) (*_t=clock()) +#define MYTIMEDIFF(fin,ini) ((fin)-(ini)) +#define TIMER_RES_DIVIDER 1 +#define SAMPLE_TIME_IMPLEMENTATION 1 +#define EE_TICKS_PER_SEC (NSECS_PER_SEC / TIMER_RES_DIVIDER) */ +#define EE_TICKS_PER_SEC ((uint32_t)1000) +#define SYSTICK_1MS ((uint32_t)1000) + +/** Define Host specific (POSIX), or target specific global time variables. */ +// static CORETIMETYPE start_time_val, stop_time_val; + +volatile uint32_t Tick; +extern void SysTick_Init(uint32_t NUM); +extern void SysTick_Stop_time(void); + +/* Function : start_time + This function will be called right before starting the timed portion of the benchmark. + + Implementation may be capturing a system timer (as implemented in the example code) + or zeroing some system parameters - e.g. setting the cpu clocks cycles to 0. +*/ +void start_time(void) +{ + Tick = 0; + SysTick_Init(SYSTICK_1MS); +} +/* Function : stop_time + This function will be called right after ending the timed portion of the benchmark. + + Implementation may be capturing a system timer (as implemented in the example code) + or other system parameters - e.g. reading the current value of cpu cycles counter. +*/ +void stop_time(void) +{ + SysTick_Stop_time(); +} +/* Function : get_time + Return an abstract "ticks" number that signifies time on the system. + + Actual value returned may be cpu cycles, milliseconds or any other value, + as long as it can be converted to seconds by . + This methodology is taken to accomodate any hardware or simulated platform. + The sample implementation returns millisecs by default, + and the resolution is controlled by +*/ +CORE_TICKS get_time(void) +{ + CORE_TICKS elapsed = (CORE_TICKS)Tick; + return elapsed; +} +/* Function : time_in_secs + Convert the value returned by get_time to seconds. + + The type is used to accomodate systems with no support for floating point. + Default implementation implemented by the EE_TICKS_PER_SEC macro above. +*/ +secs_ret time_in_secs(CORE_TICKS ticks) +{ + secs_ret retval = ((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC; + return retval; +} + +ee_u32 default_num_contexts = 1; + +/* Function : portable_init + Target specific initialization code + Test for some common mistakes. +*/ +void portable_init(core_portable* p, int* argc, char* argv[]) +{ + if (sizeof(ee_ptr_int) != sizeof(ee_u8*)) + { + ee_printf("ERROR! Please define ee_ptr_int to a type that holds a pointer!\n"); + } + if (sizeof(ee_u32) != 4) + { + ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n"); + } + p->portable_id = 1; +} +/* Function : portable_fini + Target specific final code +*/ +void portable_fini(core_portable* p) +{ + p->portable_id = 0; +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_portme.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_portme.h new file mode 100644 index 0000000..2095773 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_portme.h @@ -0,0 +1,201 @@ +/* +Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Original Author: Shay Gal-on +*/ + +/* Topic : Description + This file contains configuration constants required to execute on different platforms +*/ +#ifndef CORE_PORTME_H +#define CORE_PORTME_H +/************************/ +/* Data types and settings */ +/************************/ +/* Configuration : HAS_FLOAT + Define to 1 if the platform supports floating point. +*/ +#ifndef HAS_FLOAT +#define HAS_FLOAT 1 +#endif +/* Configuration : HAS_TIME_H + Define to 1 if platform has the time.h header file, + and implementation of functions thereof. +*/ +#ifndef HAS_TIME_H +#define HAS_TIME_H 1 +#endif +/* Configuration : USE_CLOCK + Define to 1 if platform has the time.h header file, + and implementation of functions thereof. +*/ +#ifndef USE_CLOCK +#define USE_CLOCK 1 +#endif +/* Configuration : HAS_STDIO + Define to 1 if the platform has stdio.h. +*/ +#ifndef HAS_STDIO +#define HAS_STDIO 1 +#endif +/* Configuration : HAS_PRINTF + Define to 1 if the platform has stdio.h and implements the printf function. +*/ +#ifndef HAS_PRINTF +#define HAS_PRINTF 1 +#endif + +/* Configuration : CORE_TICKS + Define type of return from the timing functions. + */ +#include +typedef clock_t CORE_TICKS; + +/* Definitions : COMPILER_VERSION, COMPILER_FLAGS, MEM_LOCATION + Initialize these strings per platform +*/ +#ifndef COMPILER_VERSION +#ifdef __GNUC__ +#define COMPILER_VERSION "GCC"__VERSION__ +#else +#define COMPILER_VERSION "Please put compiler version here (e.g. gcc 4.1)" +#endif +#endif +#ifndef COMPILER_FLAGS +// #define COMPILER_FLAGS FLAGS_STR /* "Please put compiler flags here (e.g. -o3)" */ +#define COMPILER_FLAGS "-Ohs -no_size_constraints" +#endif +#ifndef MEM_LOCATION +#define MEM_LOCATION "STACK" +#endif + +/* Data Types : + To avoid compiler issues, define the data types that need ot be used for 8b, 16b and 32b in . + + *Imprtant* : + ee_ptr_int needs to be the data type used to hold pointers, otherwise coremark may fail!!! +*/ +typedef signed short ee_s16; +typedef unsigned short ee_u16; +typedef signed int ee_s32; +typedef double ee_f32; +typedef unsigned char ee_u8; +typedef unsigned int ee_u32; +typedef ee_u32 ee_ptr_int; +typedef size_t ee_size_t; +/* align_mem : + This macro is used to align an offset to point to a 32b value. It is used in the Matrix algorithm to initialize + the input memory blocks. +*/ +#define align_mem(x) (void*)(4 + (((ee_ptr_int)(x)-1) & ~3)) + +/* Configuration : SEED_METHOD + Defines method to get seed values that cannot be computed at compile time. + + Valid values : + SEED_ARG - from command line. + SEED_FUNC - from a system function. + SEED_VOLATILE - from volatile variables. +*/ +#ifndef SEED_METHOD +#define SEED_METHOD SEED_VOLATILE +#endif + +/* Configuration : MEM_METHOD + Defines method to get a block of memry. + + Valid values : + MEM_MALLOC - for platforms that implement malloc and have malloc.h. + MEM_STATIC - to use a static memory array. + MEM_STACK - to allocate the data block on the stack (NYI). +*/ +#ifndef MEM_METHOD +#define MEM_METHOD MEM_STACK +#endif + +/* Configuration : MULTITHREAD + Define for parallel execution + + Valid values : + 1 - only one context (default). + N>1 - will execute N copies in parallel. + + Note : + If this flag is defined to more then 1, an implementation for launching parallel contexts must be defined. + + Two sample implementations are provided. Use or to enable them. + + It is valid to have a different implementation of and in + , to fit a particular architecture. +*/ +#ifndef MULTITHREAD +#define MULTITHREAD 1 +#define USE_PTHREAD 0 +#define USE_FORK 0 +#define USE_SOCKET 0 +#endif + +/* Configuration : MAIN_HAS_NOARGC + Needed if platform does not support getting arguments to main. + + Valid values : + 0 - argc/argv to main is supported + 1 - argc/argv to main is not supported + + Note : + This flag only matters if MULTITHREAD has been defined to a value greater then 1. +*/ +#ifndef MAIN_HAS_NOARGC +#define MAIN_HAS_NOARGC 1 +#endif + +/* Configuration : MAIN_HAS_NORETURN + Needed if platform does not support returning a value from main. + + Valid values : + 0 - main returns an int, and return value will be 0. + 1 - platform does not support returning a value from main +*/ +#ifndef MAIN_HAS_NORETURN +#define MAIN_HAS_NORETURN 0 +#endif + +#define ITERATIONS 700//12000 + +/* Variable : default_num_contexts + Not used for this simple port, must cintain the value 1. +*/ +extern ee_u32 default_num_contexts; + +typedef struct CORE_PORTABLE_S +{ + ee_u8 portable_id; +} core_portable; + +/* target specific init/fini */ +void portable_init(core_portable* p, int* argc, char* argv[]); +void portable_fini(core_portable* p); + +#if !defined(PROFILE_RUN) && !defined(PERFORMANCE_RUN) && !defined(VALIDATION_RUN) +#if (TOTAL_DATA_SIZE == 1200) +#define PROFILE_RUN 1 +#elif (TOTAL_DATA_SIZE == 2000) +#define PERFORMANCE_RUN 1 +#else +#define VALIDATION_RUN 1 +#endif +#endif + +#endif /* CORE_PORTME_H */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_state.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_state.c new file mode 100644 index 0000000..13bdfbd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_state.c @@ -0,0 +1,308 @@ +/* +Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Original Author: Shay Gal-on +*/ + +#include "coremark.h" +/* local functions */ +enum CORE_STATE core_state_transition(ee_u8** instr, ee_u32* transition_count); + +/* +Topic: Description + Simple state machines like this one are used in many embedded products. + + For more complex state machines, sometimes a state transition table implementation is used instead, + trading speed of direct coding for ease of maintenance. + + Since the main goal of using a state machine in CoreMark is to excercise the switch/if behaviour, + we are using a small moore machine. + + In particular, this machine tests type of string input, + trying to determine whether the input is a number or something else. + (see core_state.png). +*/ + +/* Function: core_bench_state + Benchmark function + + Go over the input twice, once direct, and once after introducing some corruption. +*/ +ee_u16 core_bench_state(ee_u32 blksize, ee_u8* memblock, ee_s16 seed1, ee_s16 seed2, ee_s16 step, ee_u16 crc) +{ + ee_u32 final_counts[NUM_CORE_STATES]; + ee_u32 track_counts[NUM_CORE_STATES]; + ee_u8* p = memblock; + ee_u32 i; + +#if CORE_DEBUG + ee_printf("State Bench: %d,%d,%d,%04x\n", seed1, seed2, step, crc); +#endif + for (i = 0; i < NUM_CORE_STATES; i++) + { + final_counts[i] = track_counts[i] = 0; + } + /* run the state machine over the input */ + while (*p != 0) + { + enum CORE_STATE fstate = core_state_transition(&p, track_counts); + final_counts[fstate]++; +#if CORE_DEBUG + ee_printf("%d,", fstate); + } + ee_printf("\n"); +#else + } +#endif + p = memblock; + while (p < (memblock + blksize)) + { /* insert some corruption */ + if (*p != ',') + *p ^= (ee_u8)seed1; + p += step; + } + p = memblock; + /* run the state machine over the input again */ + while (*p != 0) + { + enum CORE_STATE fstate = core_state_transition(&p, track_counts); + final_counts[fstate]++; +#if CORE_DEBUG + ee_printf("%d,", fstate); + } + ee_printf("\n"); +#else + } +#endif + p = memblock; + while (p < (memblock + blksize)) + { /* undo corruption is seed1 and seed2 are equal */ + if (*p != ',') + *p ^= (ee_u8)seed2; + p += step; + } + /* end timing */ + for (i = 0; i < NUM_CORE_STATES; i++) + { + crc = crcu32(final_counts[i], crc); + crc = crcu32(track_counts[i], crc); + } + return crc; +} + +/* Default initialization patterns */ +static ee_u8* intpat[4] = {(ee_u8*)"5012", (ee_u8*)"1234", (ee_u8*)"-874", (ee_u8*)"+122"}; +static ee_u8* floatpat[4] = {(ee_u8*)"35.54400", (ee_u8*)".1234500", (ee_u8*)"-110.700", (ee_u8*)"+0.64400"}; +static ee_u8* scipat[4] = {(ee_u8*)"5.500e+3", (ee_u8*)"-.123e-2", (ee_u8*)"-87e+832", (ee_u8*)"+0.6e-12"}; +static ee_u8* errpat[4] = {(ee_u8*)"T0.3e-1F", (ee_u8*)"-T.T++Tq", (ee_u8*)"1T3.4e4z", (ee_u8*)"34.0e-T^"}; + +/* Function: core_init_state + Initialize the input data for the state machine. + + Populate the input with several predetermined strings, interspersed. + Actual patterns chosen depend on the seed parameter. + + Note: + The seed parameter MUST be supplied from a source that cannot be determined at compile time +*/ +void core_init_state(ee_u32 size, ee_s16 seed, ee_u8* p) +{ + ee_u32 total = 0, next = 0, i; + ee_u8* buf = 0; +#if CORE_DEBUG + ee_u8* start = p; + ee_printf("State: %d,%d\n", size, seed); +#endif + size--; + next = 0; + while ((total + next + 1) < size) + { + if (next > 0) + { + for (i = 0; i < next; i++) + *(p + total + i) = buf[i]; + *(p + total + i) = ','; + total += next + 1; + } + seed++; + switch (seed & 0x7) + { + case 0: /* int */ + case 1: /* int */ + case 2: /* int */ + buf = intpat[(seed >> 3) & 0x3]; + next = 4; + break; + case 3: /* float */ + case 4: /* float */ + buf = floatpat[(seed >> 3) & 0x3]; + next = 8; + break; + case 5: /* scientific */ + case 6: /* scientific */ + buf = scipat[(seed >> 3) & 0x3]; + next = 8; + break; + case 7: /* invalid */ + buf = errpat[(seed >> 3) & 0x3]; + next = 8; + break; + default: /* Never happen, just to make some compilers happy */ + break; + } + } + size++; + while (total < size) + { /* fill the rest with 0 */ + *(p + total) = 0; + total++; + } +#if CORE_DEBUG + ee_printf("State Input: %s\n", start); +#endif +} + +static ee_u8 ee_isdigit(ee_u8 c) +{ + ee_u8 retval; + retval = ((c >= '0') & (c <= '9')) ? 1 : 0; + return retval; +} + +/* Function: core_state_transition + Actual state machine. + + The state machine will continue scanning until either: + 1 - an invalid input is detcted. + 2 - a valid number has been detected. + + The input pointer is updated to point to the end of the token, and the end state is returned (either specific + format determined or invalid). +*/ + +enum CORE_STATE core_state_transition(ee_u8** instr, ee_u32* transition_count) +{ + ee_u8* str = *instr; + ee_u8 NEXT_SYMBOL; + enum CORE_STATE state = CORE_START; + for (; *str && state != CORE_INVALID; str++) + { + NEXT_SYMBOL = *str; + if (NEXT_SYMBOL == ',') /* end of this input */ + { + str++; + break; + } + switch (state) + { + case CORE_START: + if (ee_isdigit(NEXT_SYMBOL)) + { + state = CORE_INT; + } + else if (NEXT_SYMBOL == '+' || NEXT_SYMBOL == '-') + { + state = CORE_S1; + } + else if (NEXT_SYMBOL == '.') + { + state = CORE_FLOAT; + } + else + { + state = CORE_INVALID; + transition_count[CORE_INVALID]++; + } + transition_count[CORE_START]++; + break; + case CORE_S1: + if (ee_isdigit(NEXT_SYMBOL)) + { + state = CORE_INT; + transition_count[CORE_S1]++; + } + else if (NEXT_SYMBOL == '.') + { + state = CORE_FLOAT; + transition_count[CORE_S1]++; + } + else + { + state = CORE_INVALID; + transition_count[CORE_S1]++; + } + break; + case CORE_INT: + if (NEXT_SYMBOL == '.') + { + state = CORE_FLOAT; + transition_count[CORE_INT]++; + } + else if (!ee_isdigit(NEXT_SYMBOL)) + { + state = CORE_INVALID; + transition_count[CORE_INT]++; + } + break; + case CORE_FLOAT: + if (NEXT_SYMBOL == 'E' || NEXT_SYMBOL == 'e') + { + state = CORE_S2; + transition_count[CORE_FLOAT]++; + } + else if (!ee_isdigit(NEXT_SYMBOL)) + { + state = CORE_INVALID; + transition_count[CORE_FLOAT]++; + } + break; + case CORE_S2: + if (NEXT_SYMBOL == '+' || NEXT_SYMBOL == '-') + { + state = CORE_EXPONENT; + transition_count[CORE_S2]++; + } + else + { + state = CORE_INVALID; + transition_count[CORE_S2]++; + } + break; + case CORE_EXPONENT: + if (ee_isdigit(NEXT_SYMBOL)) + { + state = CORE_SCIENTIFIC; + transition_count[CORE_EXPONENT]++; + } + else + { + state = CORE_INVALID; + transition_count[CORE_EXPONENT]++; + } + break; + case CORE_SCIENTIFIC: + if (!ee_isdigit(NEXT_SYMBOL)) + { + state = CORE_INVALID; + transition_count[CORE_INVALID]++; + } + break; + default: + break; + } + } + *instr = str; + return state; +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_util.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_util.c new file mode 100644 index 0000000..95901d9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/core_util.c @@ -0,0 +1,234 @@ +/* +Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Original Author: Shay Gal-on +*/ + +#include "coremark.h" +/* Function: get_seed + Get a values that cannot be determined at compile time. + + Since different embedded systems and compilers are used, 3 different methods are provided: + 1 - Using a volatile variable. This method is only valid if the compiler is forced to generate code that + reads the value of a volatile variable from memory at run time. + Please note, if using this method, you would need to modify core_portme.c to generate training profile. + 2 - Command line arguments. This is the preferred method if command line arguments are supported. + 3 - System function. If none of the first 2 methods is available on the platform, + a system function which is not a stub can be used. + + e.g. read the value on GPIO pins connected to switches, or invoke special simulator functions. +*/ +#if (SEED_METHOD == SEED_VOLATILE) +extern volatile ee_s32 seed1_volatile; +extern volatile ee_s32 seed2_volatile; +extern volatile ee_s32 seed3_volatile; +extern volatile ee_s32 seed4_volatile; +extern volatile ee_s32 seed5_volatile; +ee_s32 get_seed_32(int i) +{ + ee_s32 retval; + switch (i) + { + case 1: + retval = seed1_volatile; + break; + case 2: + retval = seed2_volatile; + break; + case 3: + retval = seed3_volatile; + break; + case 4: + retval = seed4_volatile; + break; + case 5: + retval = seed5_volatile; + break; + default: + retval = 0; + break; + } + return retval; +} +#elif (SEED_METHOD == SEED_ARG) +ee_s32 parseval(char* valstring) +{ + ee_s32 retval = 0; + ee_s32 neg = 1; + int hexmode = 0; + if (*valstring == '-') + { + neg = -1; + valstring++; + } + if ((valstring[0] == '0') && (valstring[1] == 'x')) + { + hexmode = 1; + valstring += 2; + } + /* first look for digits */ + if (hexmode) + { + while (((*valstring >= '0') && (*valstring <= '9')) || ((*valstring >= 'a') && (*valstring <= 'f'))) + { + ee_s32 digit = *valstring - '0'; + if (digit > 9) + digit = 10 + *valstring - 'a'; + retval *= 16; + retval += digit; + valstring++; + } + } + else + { + while ((*valstring >= '0') && (*valstring <= '9')) + { + ee_s32 digit = *valstring - '0'; + retval *= 10; + retval += digit; + valstring++; + } + } + /* now add qualifiers */ + if (*valstring == 'K') + retval *= 1024; + if (*valstring == 'M') + retval *= 1024 * 1024; + + retval *= neg; + return retval; +} + +ee_s32 get_seed_args(int i, int argc, char* argv[]) +{ + if (argc > i) + return parseval(argv[i]); + return 0; +} + +#elif (SEED_METHOD == SEED_FUNC) +/* If using OS based function, you must define and implement the functions below in core_portme.h and core_portme.c ! */ +ee_s32 get_seed_32(int i) +{ + ee_s32 retval; + switch (i) + { + case 1: + retval = portme_sys1(); + break; + case 2: + retval = portme_sys2(); + break; + case 3: + retval = portme_sys3(); + break; + case 4: + retval = portme_sys4(); + break; + case 5: + retval = portme_sys5(); + break; + default: + retval = 0; + break; + } + return retval; +} +#endif + +/* Function: crc* + Service functions to calculate 16b CRC code. + +*/ +ee_u16 crcu8(ee_u8 data, ee_u16 crc) +{ + ee_u8 i = 0, x16 = 0, carry = 0; + + for (i = 0; i < 8; i++) + { + x16 = (ee_u8)((data & 1) ^ ((ee_u8)crc & 1)); + data >>= 1; + + if (x16 == 1) + { + crc ^= 0x4002; + carry = 1; + } + else + carry = 0; + crc >>= 1; + if (carry) + crc |= 0x8000; + else + crc &= 0x7fff; + } + return crc; +} +ee_u16 crcu16(ee_u16 newval, ee_u16 crc) +{ + crc = crcu8((ee_u8)(newval), crc); + crc = crcu8((ee_u8)((newval) >> 8), crc); + return crc; +} +ee_u16 crcu32(ee_u32 newval, ee_u16 crc) +{ + crc = crc16((ee_s16)newval, crc); + crc = crc16((ee_s16)(newval >> 16), crc); + return crc; +} +ee_u16 crc16(ee_s16 newval, ee_u16 crc) +{ + return crcu16((ee_u16)newval, crc); +} + +ee_u8 check_data_types(void) +{ + ee_u8 retval = 0; + if (sizeof(ee_u8) != 1) + { + ee_printf("ERROR: ee_u8 is not an 8b datatype!\n"); + retval++; + } + if (sizeof(ee_u16) != 2) + { + ee_printf("ERROR: ee_u16 is not a 16b datatype!\n"); + retval++; + } + if (sizeof(ee_s16) != 2) + { + ee_printf("ERROR: ee_s16 is not a 16b datatype!\n"); + retval++; + } + if (sizeof(ee_s32) != 4) + { + ee_printf("ERROR: ee_s32 is not a 32b datatype!\n"); + retval++; + } + if (sizeof(ee_u32) != 4) + { + ee_printf("ERROR: ee_u32 is not a 32b datatype!\n"); + retval++; + } + if (sizeof(ee_ptr_int) != sizeof(int*)) + { + ee_printf("ERROR: ee_ptr_int is not a datatype that holds an int pointer!\n"); + retval++; + } + if (retval > 0) + { + ee_printf("ERROR: Please modify the datatypes in core_portme.h!\n"); + } + return retval; +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/coremark.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/coremark.h new file mode 100644 index 0000000..9f1b022 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/coremark/coremark.h @@ -0,0 +1,175 @@ +/* +Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Original Author: Shay Gal-on +*/ + +/* Topic: Description + This file contains declarations of the various benchmark functions. +*/ + +/* Configuration: TOTAL_DATA_SIZE + Define total size for data algorithms will operate on +*/ +#ifndef TOTAL_DATA_SIZE +#define TOTAL_DATA_SIZE 2 * 1000 +#endif + +#define SEED_ARG 0 +#define SEED_FUNC 1 +#define SEED_VOLATILE 2 + +#define MEM_STATIC 0 +#define MEM_MALLOC 1 +#define MEM_STACK 2 + +#include "core_portme.h" + +#if HAS_STDIO +#include +#endif +#if HAS_PRINTF +#define ee_printf printf +#endif + +/* Actual benchmark execution in iterate */ +void* iterate(void* pres); + +/* Typedef: secs_ret + For machines that have floating point support, get number of seconds as a double. + Otherwise an unsigned int. +*/ +#if HAS_FLOAT +typedef double secs_ret; +#else +typedef ee_u32 secs_ret; +#endif + +#if MAIN_HAS_NORETURN +#define MAIN_RETURN_VAL +#define MAIN_RETURN_TYPE void +#else +#define MAIN_RETURN_VAL 0 +#define MAIN_RETURN_TYPE int +#endif + +void start_time(void); +void stop_time(void); +CORE_TICKS get_time(void); +secs_ret time_in_secs(CORE_TICKS ticks); + +/* Misc useful functions */ +ee_u16 crcu8(ee_u8 data, ee_u16 crc); +ee_u16 crc16(ee_s16 newval, ee_u16 crc); +ee_u16 crcu16(ee_u16 newval, ee_u16 crc); +ee_u16 crcu32(ee_u32 newval, ee_u16 crc); +ee_u8 check_data_types(void); +void* portable_malloc(ee_size_t size); +void portable_free(void* p); +ee_s32 parseval(char* valstring); + +/* Algorithm IDS */ +#define ID_LIST (1 << 0) +#define ID_MATRIX (1 << 1) +#define ID_STATE (1 << 2) +#define ALL_ALGORITHMS_MASK (ID_LIST | ID_MATRIX | ID_STATE) +#define NUM_ALGORITHMS 3 + +/* list data structures */ +typedef struct list_data_s +{ + ee_s16 data16; + ee_s16 idx; +} list_data; + +typedef struct list_head_s +{ + struct list_head_s* next; + struct list_data_s* info; +} list_head; + +/*matrix benchmark related stuff */ +#define MATDAT_INT 1 +#if MATDAT_INT +typedef ee_s16 MATDAT; +typedef ee_s32 MATRES; +#else +typedef ee_f16 MATDAT; +typedef ee_f32 MATRES; +#endif + +typedef struct MAT_PARAMS_S +{ + int N; + MATDAT* A; + MATDAT* B; + MATRES* C; +} mat_params; + +/* state machine related stuff */ +/* List of all the possible states for the FSM */ +typedef enum CORE_STATE +{ + CORE_START = 0, + CORE_INVALID, + CORE_S1, + CORE_S2, + CORE_INT, + CORE_FLOAT, + CORE_EXPONENT, + CORE_SCIENTIFIC, + NUM_CORE_STATES +} core_state_e; + +/* Helper structure to hold results */ +typedef struct RESULTS_S +{ + /* inputs */ + ee_s16 seed1; /* Initializing seed */ + ee_s16 seed2; /* Initializing seed */ + ee_s16 seed3; /* Initializing seed */ + void* memblock[4]; /* Pointer to safe memory location */ + ee_u32 size; /* Size of the data */ + ee_u32 iterations; /* Number of iterations to execute */ + ee_u32 execs; /* Bitmask of operations to execute */ + struct list_head_s* list; + mat_params mat; + /* outputs */ + ee_u16 crc; + ee_u16 crclist; + ee_u16 crcmatrix; + ee_u16 crcstate; + ee_s16 err; + /* ultithread specific */ + core_portable port; +} core_results; + +/* Multicore execution handling */ +#if (MULTITHREAD > 1) +ee_u8 core_start_parallel(core_results* res); +ee_u8 core_stop_parallel(core_results* res); +#endif + +/* list benchmark functions */ +list_head* core_list_init(ee_u32 blksize, list_head* memblock, ee_s16 seed); +ee_u16 core_bench_list(core_results* res, ee_s16 finder_idx); + +/* state benchmark functions */ +void core_init_state(ee_u32 size, ee_s16 seed, ee_u8* p); +ee_u16 core_bench_state(ee_u32 blksize, ee_u8* memblock, ee_s16 seed1, ee_s16 seed2, ee_s16 step, ee_u16 crc); + +/* matrix benchmark functions */ +ee_u32 core_init_matrix(ee_u32 blksize, void* memblk, ee_s32 seed, mat_params* p); +ee_u16 core_bench_matrix(mat_params* p, ee_s16 seed, ee_u16 crc); diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/inc/main.h new file mode 100644 index 0000000..a923084 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/inc/main.h @@ -0,0 +1,93 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +void SysTick_Init(uint32_t NUM); +void SysTick_Stop_time(void); +void USART_Config(void); +void Usart_SendByte(USART_Module* pUSARTx, uint8_t ch); +void Usart_SendString(USART_Module* pUSARTx, char* str); +void Usart_SendHalfWord(USART_Module* pUSARTx, uint16_t ch); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/readme.txt new file mode 100644 index 0000000..8049ca6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/readme.txt @@ -0,0 +1,25 @@ + +1. Function description + + /* Briefly describe the project function */ + This example configures and demonstrates the MCU benchmark + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + /* Describe related module configuration methods; for example: clock, I/O, etc. */ + SystemClock: HSI:64MHz + Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + SysTick: Clock ticks configured as 1MS + + /* Describe the test steps and phenomena of the Demo */ + 1. After compiling, download the program to reset and run; + 2. Print out the running score results through the serial port; + + +4. Matters needing attention diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/src/main.c new file mode 100644 index 0000000..2f1f8d1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/src/main.c @@ -0,0 +1,143 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "log.h" + +/** + * iCache_CoreMark + */ + +#define SYSTICK_1MS ((uint32_t)1000) +#define SYSTICK_COUNTER_DIASBLE ((uint32_t)0xFFFFFFFE) +#define SYSTICK_COUNTER_ENABLE ((uint32_t)0x00000001) +#define SYSTICK_COUNTER_CLEAR ((uint32_t)0x00000000) +#define COREMARK_USART_BAUDRATE ((uint32_t)115200) + +extern int CoreMark(void); + +/** + * @brief Main program. + */ +int main(void) +{ + + /* log Init */ + log_init(); + printf("CoreMark Test Start\r\n"); + + /* SysTick Init */ + SysTick_Init(SYSTICK_1MS); + + /* CoreMark Test */ + CoreMark(); + + while (1) + { + } +} + +/** + * @brief SysTick Init. + * @param NUM Interrupt Time(us) + */ +void SysTick_Init(uint32_t NUM) +{ + /* SystemCoreClock / NUM */ + if (SysTick_Config(SystemCoreClock / NUM)) + { + while (1) + ; + } +} + +/** + * @brief SysTick_Stop_time. + */ +void SysTick_Stop_time(void) +{ + SysTick->CTRL &= SYSTICK_COUNTER_DIASBLE; + /* Clear the SysTick Counter */ + SysTick->VAL = SYSTICK_COUNTER_CLEAR; +} + + +/** + * @} + */ + +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name +* line: assert_param error line source number + * @return None + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + {} +} + +/** + * @} + */ +#endif diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/src/n32wb03x_it.c new file mode 100644 index 0000000..4af5058 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/src/n32wb03x_it.c @@ -0,0 +1,126 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + /* User Code begin SysTick_IRQn */ + extern volatile uint32_t Tick; + Tick++; + /* User Code END SysTick_IRQn */ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/startup/startup_n32wb03x_CoreMark.s b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/startup/startup_n32wb03x_CoreMark.s new file mode 100644 index 0000000..44cae49 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/COREMARK/CoreMark/startup/startup_n32wb03x_CoreMark.s @@ -0,0 +1,251 @@ +; **************************************************************************** +; Copyright (c) 2019, Nations Technologies Inc. +; +; 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 disclaimer below. +; +; Nations' name may not be used to endorse or promote products derived from +; this software without specific prior written permission. +; +; DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR +; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE +; DISCLAIMED. IN NO EVENT SHALL NATIONS 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. +; **************************************************************************** + +; Amount of memory (in bytes) allocated for Stack +; Tailor this value to your application needs +; Stack Configuration +; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + +Stack_Size EQU 0x00001800 + + AREA STACK, NOINIT, READWRITE, ALIGN=3 +Stack_Mem SPACE Stack_Size +__initial_sp + +; Heap Configuration +; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + +Heap_Size EQU 0x00000300 + + AREA HEAP, NOINIT, READWRITE, ALIGN=3 +__heap_base +Heap_Mem SPACE Heap_Size +__heap_limit + + PRESERVE8 + THUMB + + +; Vector Table Mapped to Address 0 at Reset + AREA RESET, DATA, READONLY + EXPORT __Vectors + EXPORT __Vectors_End + EXPORT __Vectors_Size + +__Vectors DCD __initial_sp ; Top of Stack + DCD Reset_Handler ; Reset Handler + DCD NMI_Handler ; NMI Handler + DCD HardFault_Handler ; Hard Fault Handler + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD SVC_Handler ; SVCall Handler + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD PendSV_Handler ; PendSV Handler + DCD SysTick_Handler ; SysTick Handler + + ; External Interrupts + DCD WWDG_IRQHandler ; Window Watchdog + DCD BLE_SW_IRQHandler ; BLE_SW interrupt + DCD RTC_IRQHandler ; RTC interrupt(through EXTI line 17/19/20 interrupt) + DCD BLE_HSLOT_IRQHandler ; BLE_HSLOT + DCD FLASH_IRQHandler ; Flash + DCD RCC_IRQHandler ; RCC + DCD EXTI0_1_IRQHandler ; EXTI Line 0.1 + DCD EXTI2_3_IRQHandler ; EXTI Line 2.3 + DCD EXTI4_12_IRQHandler ; EXTI Line 4..12 + DCD BLE_FINETGT_IRQHandler ; BLE_FINETGT + DCD BLE_FIFO_IRQHandler ; BLE_FIFO + DCD DMA_Channel1_2_3_4_IRQHandler ; DMA Channel 1,2,3,4 + DCD DMA_Channel5_IRQHandler ; DMA Channel 5,6,7,8 + DCD TIM1_BRK_UP_TRG_COM_IRQHandler ; TIM1 Break/Update/Trigger and Commutation + DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare + DCD RESERVED_IRQHandler ; + DCD TIM3_IRQHandler ; TIM3 + DCD BLE_ERROR_IRQHandler ; BLE_ERROR + DCD BLE_CRYPT_IRQHandler ; BLE_CYPT_IRQHandler + DCD BLE_TIMESTAMP_TGT1_IRQHandler ; BLE_TIMESTAMP_TGT1 + DCD TIM6_IRQHandler ; TIM6 + DCD ADC_IRQHandler ; ADC + DCD SPI2_IRQHandler ; SPI2 + DCD I2C1_IRQHandler ; I2C1 + DCD BLE_TIMESTAMP_TGT2_IRQHandler ; BLE_TIMESTAMP_TGT12 + DCD SPI1_IRQHandler ; SPI1 + DCD BLE_SLP_IRQHandler ; BLE_SLP + DCD KEYSCAN_IRQHandler ; KEYSCAN + DCD USART1_IRQHandler ; USART1 + DCD LPUART1_IRQHandler ; LPUART1 + DCD USART2_IRQHandler ; USART2 + DCD IRC_IRQHandler ; IRC +__Vectors_End + +__Vectors_Size EQU __Vectors_End - __Vectors + + AREA |.text|, CODE, READONLY + +; Reset handler +Reset_Handler PROC + EXPORT Reset_Handler [WEAK] + IMPORT __main + IMPORT SystemInit + LDR R0, =SystemInit + BLX R0 + LDR R0, =__main + BX R0 + ENDP + +; Dummy Exception Handlers (infinite loops which can be modified) + +NMI_Handler PROC + EXPORT NMI_Handler [WEAK] + B . + ENDP +HardFault_Handler\ + PROC + EXPORT HardFault_Handler [WEAK] + B . + ENDP +SVC_Handler PROC + EXPORT SVC_Handler [WEAK] + B . + ENDP +PendSV_Handler PROC + EXPORT PendSV_Handler [WEAK] + B . + ENDP +SysTick_Handler PROC + EXPORT SysTick_Handler [WEAK] + B . + ENDP + +Default_Handler PROC + + EXPORT WWDG_IRQHandler [WEAK] + EXPORT BLE_SW_IRQHandler [WEAK] + EXPORT RTC_IRQHandler [WEAK] + EXPORT BLE_HSLOT_IRQHandler [WEAK] + EXPORT FLASH_IRQHandler [WEAK] + EXPORT RCC_IRQHandler [WEAK] + EXPORT EXTI0_1_IRQHandler [WEAK] + EXPORT EXTI2_3_IRQHandler [WEAK] + EXPORT EXTI4_12_IRQHandler [WEAK] + EXPORT BLE_FINETGT_IRQHandler [WEAK] + EXPORT BLE_FIFO_IRQHandler [WEAK] + EXPORT DMA_Channel1_2_3_4_IRQHandler [WEAK] + EXPORT DMA_Channel5_IRQHandler [WEAK] + EXPORT TIM1_BRK_UP_TRG_COM_IRQHandler [WEAK] + EXPORT TIM1_CC_IRQHandler [WEAK] + EXPORT RESERVED_IRQHandler [WEAK] + EXPORT TIM3_IRQHandler [WEAK] + EXPORT BLE_ERROR_IRQHandler [WEAK] + EXPORT BLE_CRYPT_IRQHandler [WEAK] + EXPORT BLE_TIMESTAMP_TGT1_IRQHandler [WEAK] + EXPORT TIM6_IRQHandler [WEAK] + EXPORT ADC_IRQHandler [WEAK] + EXPORT SPI2_IRQHandler [WEAK] + EXPORT I2C1_IRQHandler [WEAK] + EXPORT BLE_TIMESTAMP_TGT2_IRQHandler [WEAK] + EXPORT SPI1_IRQHandler [WEAK] + EXPORT BLE_SLP_IRQHandler [WEAK] + EXPORT KEYSCAN_IRQHandler [WEAK] + EXPORT USART1_IRQHandler [WEAK] + EXPORT LPUART1_IRQHandler [WEAK] + EXPORT USART2_IRQHandler [WEAK] + EXPORT IRC_IRQHandler [WEAK] + +WWDG_IRQHandler +BLE_SW_IRQHandler +RTC_IRQHandler +BLE_HSLOT_IRQHandler +FLASH_IRQHandler +RCC_IRQHandler +EXTI0_1_IRQHandler +EXTI2_3_IRQHandler +EXTI4_12_IRQHandler +BLE_FINETGT_IRQHandler +BLE_FIFO_IRQHandler +DMA_Channel1_2_3_4_IRQHandler +DMA_Channel5_IRQHandler +TIM1_BRK_UP_TRG_COM_IRQHandler +TIM1_CC_IRQHandler +RESERVED_IRQHandler +TIM3_IRQHandler +BLE_ERROR_IRQHandler +BLE_CRYPT_IRQHandler +BLE_TIMESTAMP_TGT1_IRQHandler +TIM6_IRQHandler +ADC_IRQHandler +SPI2_IRQHandler +I2C1_IRQHandler +BLE_TIMESTAMP_TGT2_IRQHandler +SPI1_IRQHandler +BLE_SLP_IRQHandler +KEYSCAN_IRQHandler +USART1_IRQHandler +LPUART1_IRQHandler +USART2_IRQHandler +IRC_IRQHandler + B . + + ENDP + + ALIGN + +;******************************************************************************* +; User Stack and Heap initialization +;******************************************************************************* + IF :DEF:__MICROLIB + + EXPORT __initial_sp + EXPORT __heap_base + EXPORT __heap_limit + + ELSE + + IMPORT __use_two_region_memory + EXPORT __user_initial_stackheap + +__user_initial_stackheap + + LDR R0, = Heap_Mem + LDR R1, =(Stack_Mem + Stack_Size) + LDR R2, = (Heap_Mem + Heap_Size) + LDR R3, = Stack_Mem + BX LR + + ALIGN + + ENDIF + + END diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/MDK-ARM/CalCRC.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/MDK-ARM/CalCRC.uvoptx new file mode 100644 index 0000000..4325ac5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/MDK-ARM/CalCRC.uvoptx @@ -0,0 +1,352 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/MDK-ARM/CalCRC.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/MDK-ARM/CalCRC.uvprojx new file mode 100644 index 0000000..f61d4df --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/MDK-ARM/CalCRC.uvprojx @@ -0,0 +1,478 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + CalCRC + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\CalCRC.bin .\Objects\CalCRC.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/inc/main.h new file mode 100644 index 0000000..5b29a11 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/inc/main.h @@ -0,0 +1,92 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define DMA_CHANNEL_USED DMA1_CH1 +#define DMA_IRQ_HANDLER DMA1_Channel1_IRQHandler +#define DMA_IT_FLAG_TC DMA1_INT_TXC1 +#define DMA_IT_FLAG_GL DMA1_INT_GLB1 +#define DMA_IRQN DMA1_Channel1_IRQn + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/readme.txt new file mode 100644 index 0000000..3d7b75d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + This routine demonstrates the basic functions and algorithms of hardware CRC. + + Among them, there are 16bit checksum and 32bit checksum, + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + /* Describe related module configuration methods; for example: clock, I/O, etc. */ + SystemClock: HSI:64MHz + Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + /* Describe the test steps and phenomena of the Demo */ + 1. After compiling, download the program to reset and run; + 2. You can check the CRC result in Log. + +4. Matters needing attention + none \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/src/main.c new file mode 100644 index 0000000..6064551 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/src/main.c @@ -0,0 +1,195 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup CRC_Calculation + * @{ + */ + +#define BUFFER_SIZE 114 +#define CRC_DFE_POLY 0x8005 + +static const uint32_t DataBuffer[BUFFER_SIZE] = { + 0x00001021, 0x20423063, 0x408450a5, 0x60c670e7, 0x9129a14a, 0xb16bc18c, 0xd1ade1ce, 0xf1ef1231, 0x32732252, + 0x52b54294, 0x72f762d6, 0x93398318, 0xa35ad3bd, 0xc39cf3ff, 0xe3de2462, 0x34430420, 0x64e674c7, 0x44a45485, + 0xa56ab54b, 0x85289509, 0xf5cfc5ac, 0xd58d3653, 0x26721611, 0x063076d7, 0x569546b4, 0xb75ba77a, 0x97198738, + 0xf7dfe7fe, 0xc7bc48c4, 0x58e56886, 0x78a70840, 0x18612802, 0xc9ccd9ed, 0xe98ef9af, 0x89489969, 0xa90ab92b, + 0x4ad47ab7, 0x6a961a71, 0x0a503a33, 0x2a12dbfd, 0xfbbfeb9e, 0x9b798b58, 0xbb3bab1a, 0x6ca67c87, 0x5cc52c22, + 0x3c030c60, 0x1c41edae, 0xfd8fcdec, 0xad2abd0b, 0x8d689d49, 0x7e976eb6, 0x5ed54ef4, 0x2e321e51, 0x0e70ff9f, + 0xefbedfdd, 0xcffcbf1b, 0x9f598f78, 0x918881a9, 0xb1caa1eb, 0xd10cc12d, 0xe16f1080, 0x00a130c2, 0x20e35004, + 0x40257046, 0x83b99398, 0xa3fbb3da, 0xc33dd31c, 0xe37ff35e, 0x129022f3, 0x32d24235, 0x52146277, 0x7256b5ea, + 0x95a88589, 0xf56ee54f, 0xd52cc50d, 0x34e224c3, 0x04817466, 0x64475424, 0x4405a7db, 0xb7fa8799, 0xe75ff77e, + 0xc71dd73c, 0x26d336f2, 0x069116b0, 0x76764615, 0x5634d94c, 0xc96df90e, 0xe92f99c8, 0xb98aa9ab, 0x58444865, + 0x78066827, 0x18c008e1, 0x28a3cb7d, 0xdb5ceb3f, 0xfb1e8bf9, 0x9bd8abbb, 0x4a755a54, 0x6a377a16, 0x0af11ad0, + 0x2ab33a92, 0xed0fdd6c, 0xcd4dbdaa, 0xad8b9de8, 0x8dc97c26, 0x5c644c45, 0x3ca22c83, 0x1ce00cc1, 0xef1fff3e, + 0xdf7caf9b, 0xbfba8fd9, 0x9ff86e17, 0x7e364e55, 0x2e933eb2, 0x0ed11ef0}; + +static const uint8_t Buffer[8] = {0x7e, 0x11, 0x36, 0x4e, 0x55, 0x0a, 0xf1, 0x1a}; + +__IO uint32_t CRCValue = 0; +__IO uint16_t CRC16Value = 0; + +void Delay(__IO uint32_t nCount); + +uint8_t ReverseBits(uint8_t bufin) +{ + uint8_t bufout = 0; + uint8_t j = 0; + for (j = 0; j < 4; j++) + { + bufout |= (bufin & (0x01 << j)) << (7 - 2 * j); + bufout |= (bufin & (0x10 << (j))) >> (2 * j + 1); + } + return bufout; +} +uint16_t GetCRC16_Software(uint8_t* buf, uint32_t len, uint16_t initcrc) +{ + uint16_t crc16 = initcrc; + uint8_t i = 0, j = 0; + + for (i = 0; i < len; i++) + { + crc16 ^= (uint16_t)(buf[i] << 8); + for (j = 0; j < 8; j++) + { + if ((crc16 & 0x8000) > 0) + { + crc16 = (uint16_t)((crc16 << 1) ^ CRC_DFE_POLY); + } + else + { + crc16 <<= 1; + } + } + } + return crc16; +} + + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + + log_init(); + log_info("\nthis is a CRC Demo.\n"); + + /* Enable CRC clock */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_CRC, ENABLE); + + /* Compute the 32bit CRC of "DataBuffer" */ + CRC32_ResetCrc(); + CRCValue = CRC32_CalcBufCrc((uint32_t*)DataBuffer, BUFFER_SIZE); + printf("Step1 hardware CRC32Value:0x%08x\r\n", CRCValue); + + /* Compute the 16bit CRC of an array */ + CRC16Value = CRC16_CalcBufCrc((uint8_t*)Buffer, 8); + printf("Step2 hardware CRC16Value:0x%04x\r\n", CRC16Value); + + /* Compute the 16bit CRC of an array by software*/ + CRCValue = GetCRC16_Software((uint8_t*)Buffer, 8, 0x00); + printf("Step3 software CRC16Value:0x%04x\r\n", CRCValue); + + while (1) + { + } +} + +/** + * @brief Inserts a delay time. + * @param nCount specifies the delay time length. + */ + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/src/n32wb03x_it.c new file mode 100644 index 0000000..793b2a5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/CRC/CalCRC/src/n32wb03x_it.c @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/** @addtogroup CRC_Calculation + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/MDK-ARM/CM0_ProcessStack_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/MDK-ARM/CM0_ProcessStack_Proj.uvoptx new file mode 100644 index 0000000..6b11c35 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/MDK-ARM/CM0_ProcessStack_Proj.uvoptx @@ -0,0 +1,343 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/MDK-ARM/CM0_ProcessStack_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/MDK-ARM/CM0_ProcessStack_Proj.uvprojx new file mode 100644 index 0000000..be90b9f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/MDK-ARM/CM0_ProcessStack_Proj.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + CM0_ProcessStack_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\CM0_ProcessStack_Proj.bin .\Objects\CM0_ProcessStack_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/inc/main.h new file mode 100644 index 0000000..281e77a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/inc/main.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +void USART_Config(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/readme.txt new file mode 100644 index 0000000..d629ab8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + + /* Briefly describe the project function */ + Demonstrates how to modify thread mode privileged access and stack + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + /* Describe related module configuration methods; for example: clock, I/O, etc. */ + SystemClock: HSI:64MHz + Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + /* Describe the test steps and phenomena of the Demo */ + 1. After compiling, download the program to reset and run; + 2. You can use the "Cortex Register" window of the compiler to view the stack used in thread mode and the access level of the code (privileged level/unprivileged level); + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/src/main.c new file mode 100644 index 0000000..1fbb19c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/src/main.c @@ -0,0 +1,181 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "log.h" + +/** + * Cortex-M0 ProcessStack + */ + +#define DEMO_USART_BAUDRATE ((uint32_t)115200) + +#define SP_PROCESS_SIZE 0x200 /* Process stack size */ +#define SP_PROCESS 0x02 /* Process stack */ +#define SP_MAIN 0x00 /* Main stack */ + +/* clang-format off */ +#if defined ( __CC_ARM ) + __ASM void __SVC(void) + { + SVC 0x01 + BX R14 + } +#elif defined ( __ICCARM__ ) + static __INLINE void __SVC() { __ASM ("svc 0x01");} +#elif defined ( __GNUC__ ) + static __INLINE void __SVC() { __ASM volatile ("svc 0x01");} +#endif +/* clang-format on */ + +__IO uint8_t PSPMemAlloc[SP_PROCESS_SIZE]; +__IO uint32_t Index = 0, PSPValue = 0, CurrentStack = 0, IsrStack = 0xFF; + +/** + * @brief Main program. + */ +int main(void) +{ + /* log Init */ + log_init(); + printf("Cortex-M0 ProcessStack \r\n"); + + /* Switch Thread mode Stack from Main to Process */ + /* Initialize memory reserved for Process Stack */ + for (Index = 0; Index < SP_PROCESS_SIZE; Index++) + { + PSPMemAlloc[Index] = 0x00; + } + + /* Set Process stack value */ + __set_PSP((uint32_t)PSPMemAlloc + SP_PROCESS_SIZE); + + /* Select Process Stack as Thread mode Stack */ + __set_CONTROL(SP_PROCESS); + + /* Execute ISB instruction to flush pipeline as recommended by Arm */ + __ISB(); + + /* Get the Thread mode stack used */ + CurrentStack = (__get_CONTROL() & 0x02); + + /* Get process stack pointer value */ + PSPValue = __get_PSP(); + + /* Check is mode has been well applied */ + if(CurrentStack != SP_PROCESS) + { + printf("Cortex-M0 ProcessStack Test Error 0 \r\n"); + while(1); + } + + /* Generate a system call exception: Main Stack pointer should be automaticcaly + when entering in ISR context */ + __SVC(); + + /* Check is Main stack was used under ISR*/ + if(IsrStack != SP_MAIN) + { + printf("Cortex-M0 ProcessStack Test Error 1 \r\n"); + while(1); + } + + /* Get the Thread mode stack used to verify we have switched back automatically + to Process Stack */ + + CurrentStack = (__get_CONTROL() & 0x02); + + /* Check is mode has been well applied */ + if(CurrentStack != SP_PROCESS) + { + printf("Cortex-M0 ProcessStack Test Error 2 \r\n"); + } + else + { + printf("Cortex-M0 ProcessStack Test Success \r\n"); + } + + while (1) + { + } +} + +/** + * @} + */ + +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name +* line: assert_param error line source number + * @return None + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + {} +} + +/** + * @} + */ +#endif diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/src/n32wb03x_it.c new file mode 100644 index 0000000..3e508f3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/ProcessStack/src/n32wb03x_it.c @@ -0,0 +1,125 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ + IsrStack = (__get_CONTROL() & 0x02); +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/MDK-ARM/CM0_SysTick_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/MDK-ARM/CM0_SysTick_Proj.uvoptx new file mode 100644 index 0000000..6b11c35 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/MDK-ARM/CM0_SysTick_Proj.uvoptx @@ -0,0 +1,343 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/MDK-ARM/CM0_SysTick_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/MDK-ARM/CM0_SysTick_Proj.uvprojx new file mode 100644 index 0000000..be90b9f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/MDK-ARM/CM0_SysTick_Proj.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + CM0_ProcessStack_Proj + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\CM0_ProcessStack_Proj.bin .\Objects\CM0_ProcessStack_Proj.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/inc/main.h new file mode 100644 index 0000000..281e77a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/inc/main.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +void USART_Config(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/readme.txt new file mode 100644 index 0000000..d2026e9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/readme.txt @@ -0,0 +1,25 @@ + +1. Function description + + /* Briefly describe the project function */ + This routine configures and demonstrates how to use SysTick + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + /* Describe related module configuration methods; for example: clock, I/O, etc. */ + SystemClock: HSI 64MHz + Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + SysTick: 1s interrupt + + /* Describe the test steps and phenomena of the Demo */ + 1. After compiling, download the program to reset and run; + 2. Start counting after the SysTick interrupt is triggered, and print information when the count is even; + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/src/main.c new file mode 100644 index 0000000..322b36a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/src/main.c @@ -0,0 +1,139 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include "log.h" +/** + * Cortex-M0 SysTick + */ + + +#define SYSTICK_1MS ((uint32_t)1000) +#define DEMO_USART_BAUDRATE ((uint32_t)115200) + +uint32_t Tick_num = 0; + +void rcc_debug(void) +{ + GPIO_InitType GPIO_InitStructure; + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure rcc_mco pin*/ + GPIO_InitStructure.Pin = GPIO_PIN_5; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF4_MCO; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + RCC_ConfigMco(RCC_MCO_SYSCLK); + printf("RCC->CFG:0x%02x\r\n", RCC->CFG); +} + +/** + * @brief Main program. + */ +int main(void) +{ + /* USART Init */ + log_init(); + printf("Cortex-M0 SysTick \r\n"); + + rcc_debug(); + /* Get SystemCoreClock */ + SystemCoreClockUpdate(); + printf("SystemCoreClock:%d\r\n", SystemCoreClock); + /* Config 1s SysTick */ + SysTick_Config(SystemCoreClock/SYSTICK_1MS); + + while (1) + { + if((Tick_num%1000) == 0) + { + printf("Cortex-M0 SysTick IRQ \r\n"); + } + } +} + +/** + * @} + */ + +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name +* line: assert_param error line source number + * @return None + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + {} +} + +/** + * @} + */ +#endif diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/src/n32wb03x_it.c new file mode 100644 index 0000000..c3bca35 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/Cortex-M0/SysTick/src/n32wb03x_it.c @@ -0,0 +1,128 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +extern __IO uint32_t IsrStack; + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +extern uint32_t Tick_num; + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + Tick_num++; + +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/MDK-ARM/I2C_Ram.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/MDK-ARM/I2C_Ram.uvoptx new file mode 100644 index 0000000..10b038b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/MDK-ARM/I2C_Ram.uvoptx @@ -0,0 +1,347 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/MDK-ARM/I2C_Ram.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/MDK-ARM/I2C_Ram.uvprojx new file mode 100644 index 0000000..1ff5cb5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/MDK-ARM/I2C_Ram.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + DMA_I2C + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\DMA_I2C.bin .\Objects\DMA_I2C.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER,USE_FULL_ASSERT=1 + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\bsp\inc;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/inc/main.h new file mode 100644 index 0000000..5b29a11 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/inc/main.h @@ -0,0 +1,92 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define DMA_CHANNEL_USED DMA1_CH1 +#define DMA_IRQ_HANDLER DMA1_Channel1_IRQHandler +#define DMA_IT_FLAG_TC DMA1_INT_TXC1 +#define DMA_IT_FLAG_GL DMA1_INT_GLB1 +#define DMA_IRQN DMA1_Channel1_IRQn + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/readme.txt new file mode 100644 index 0000000..5fe5f84 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/readme.txt @@ -0,0 +1,26 @@ + +1. Function description + This routine provides a DMA usage for transferring data between I2C peripheral and RAM. + This demo as I2C master device, it need another board as slave device to demonstrates, we can use I2C/I2C_Slave example. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + 1.Clock source: HSI 64M + 2.DMA channels: DMA_CH4, DMA_CH5 + 3.I2C1 configuration: + SCL --> PB6 + SDA --> PB7 + ADDR:0x30(7bit) + CLOCK:100K + +4.Log print: DEMO board PB4(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + +5.Test steps and phenomena + 1. Compile download code reset run + 2. View the printed information from the serial port and verify the result + +6. Precautions + None \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/src/main.c new file mode 100644 index 0000000..3250aa9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/src/main.c @@ -0,0 +1,385 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "log.h" + +#include + +#define LOG_USARTx USART2 +#define LOG_PERIPH RCC_APB1_PERIPH_USART2 +#define LOG_GPIO GPIOB +#define LOG_PERIPH_GPIO RCC_APB2_PERIPH_GPIOB +#define LOG_TX_PIN GPIO_PIN_4 +#define LOG_RX_PIN GPIO_PIN_5 +#define LOG_GPIO_AF GPIO_AF3_USART2 //GPIO_AF4_USART1 + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define I2C1_MASTER_ADDRESS7 0x30 +#define I2C2_SLAVE_ADDRESS7 0xA0 +#define BUFFER_SIZE 32 +#define I2C_CLK_SPEED 100000 + +I2C_InitType I2C_InitStructure; +DMA_InitType DMA_InitStructure; +uint8_t I2C1_Tx_Buffer[BUFFER_SIZE]; +uint8_t I2C2_Rx_Buffer[BUFFER_SIZE]; +uint8_t Tx_Idx = 0, Rx_Idx = 0; +void RCC_Configuration(void); +void GPIO_Configuration(void); + +int main(void) +{ + int i = 0; + + log_init(); + log_info("\n this is a DMA I2C Demo.\n"); + + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* Fill the buffer to send */ + for (i = 0; i < BUFFER_SIZE; i++) + { + I2C1_Tx_Buffer[i] = i; + } + memset(I2C2_Rx_Buffer, 0, BUFFER_SIZE); + + /* DMA channel5 configuration ----------------------------------------------*/ + DMA_DeInit(DMA_CH5); + DMA_InitStructure.PeriphAddr = (uint32_t)&I2C1->DAT; + DMA_InitStructure.MemAddr = (uint32_t)I2C1_Tx_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = BUFFER_SIZE; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(DMA_CH5, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_I2C_TX, DMA, DMA_CH5, ENABLE); + + /* DMA channel4 configuration ----------------------------------------------*/ + DMA_DeInit(DMA_CH4); + DMA_InitStructure.PeriphAddr = (uint32_t)&I2C1->DAT; + DMA_InitStructure.MemAddr = (uint32_t)I2C2_Rx_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.Priority = DMA_PRIORITY_HIGH; + DMA_InitStructure.BufSize = BUFFER_SIZE; + DMA_Init(DMA_CH4, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_I2C_RX, DMA, DMA_CH4, ENABLE); + + I2C_DeInit(I2C1); + /* I2C1 configuration ------------------------------------------------------*/ + I2C_InitStructure.BusMode = I2C_BUSMODE_I2C; + I2C_InitStructure.FmDutyCycle = I2C_FMDUTYCYCLE_1; + I2C_InitStructure.OwnAddr1 = I2C1_MASTER_ADDRESS7; + I2C_InitStructure.AckEnable = I2C_ACKEN; + I2C_InitStructure.AddrMode = I2C_ADDR_MODE_7BIT; + I2C_InitStructure.ClkSpeed = I2C_CLK_SPEED; + I2C_Init(I2C1, &I2C_InitStructure); + + /* Enable I2C1 and I2C2 ----------------------------------------------------*/ + I2C_Enable(I2C1, ENABLE); + + + /*----- Transmission Phase -----*/ + while (I2C_GetFlag(I2C1, I2C_FLAG_BUSY)) + ; + /* Send I2C1 START condition */ + I2C_GenerateStart(I2C1, ENABLE); + /* Test on I2C1 EV5 and clear it */ + while (!I2C_CheckEvent(I2C1, I2C_EVT_MASTER_MODE_FLAG)) + ; + + /* Send I2C2 slave Address for write */ + I2C_SendAddr7bit(I2C1, I2C2_SLAVE_ADDRESS7, I2C_DIRECTION_SEND); + /* Test on I2C1 EV6 and clear it */ + while (!I2C_CheckEvent(I2C1, I2C_EVT_MASTER_TXMODE_FLAG)) + ; + + /* Enable I2C1 Send DMA */ + I2C_EnableDMA(I2C1, ENABLE); + /* Enable DMA Channel5 */ + DMA_EnableChannel(DMA_CH5, ENABLE); + + + /* DMA Channel5 transfer complete test */ + while (!DMA_GetFlagStatus(DMA_FLAG_TC5, DMA)) + ; + + Delay_ms(5); + /* Send I2C1 STOP Condition */ + I2C_GenerateStop(I2C1, ENABLE); + + /*I2C read*/ + while (I2C_GetFlag(I2C1, I2C_FLAG_BUSY)) + ; + /** Send START condition */ + I2C_GenerateStart(I2C1, ENABLE); + /* Test on I2C1 EV5 and clear it */ + while (!I2C_CheckEvent(I2C1, I2C_EVT_MASTER_MODE_FLAG)) + ; + + // send addr + I2C_SendAddr7bit(I2C1, I2C2_SLAVE_ADDRESS7, I2C_DIRECTION_RECV); + while (!I2C_CheckEvent(I2C1, I2C_EVT_MASTER_RXMODE_FLAG)) // EV6 + ; + + /* Enable I2C1 Recv DMA */ + I2C_EnableDMA(I2C1, ENABLE); + /* Enable DMA Channel5 */ + DMA_EnableChannel(DMA_CH4, ENABLE); + + while(1) + { + if(DMA_GetCurrDataCounter(DMA_CH4) == 1) + { + I2C_ConfigAck(I2C1, DISABLE); + I2C_GenerateStop(I2C1, ENABLE); + break; + } + } + + /* DMA Channel5 transfer complete test */ + while (!DMA_GetFlagStatus(DMA_FLAG_TC4, DMA)) + ; + + /* Send I2C1 STOP Condition */ + //I2C_GenerateStop(I2C1, ENABLE); + + log_buff(I2C1_Tx_Buffer, BUFFER_SIZE); + log_buff(I2C2_Rx_Buffer, BUFFER_SIZE); + printf("test end\r\n"); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable DMA clock */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + /* Enable I2C1 and I2C2 clock */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_I2C1, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure I2C1 pins: SCL and SDA */ + GPIO_InitStructure.Pin = GPIO_PIN_6 | GPIO_PIN_7; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_LOW; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_OD; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF3_I2C; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +void gpio_starup_deinit(void) +{ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_I2C1, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_I2C1, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_I2C1, DISABLE); + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_I2C1, DISABLE); + RCC_EnableAPB2PeriphClk( RCC_APB2_PERIPH_AFIO, DISABLE); + RCC_EnableAPB2PeriphClk (RCC_APB2_PERIPH_GPIOB, DISABLE ); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_I2C1, ENABLE); + RCC_EnableAPB1PeriphReset(RCC_APB1_PERIPH_I2C1, DISABLE); + + GPIO_DeInit(GPIOA); + GPIO_DeInit(GPIOB); + + GPIO_AFIOInitDefault(); + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, DISABLE); + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, DISABLE); +} + +void log_init(void) +{ + GPIO_InitType GPIO_InitStructure; + USART_InitType USART_InitStructure; + + gpio_starup_deinit(); + + GPIO_InitStruct(&GPIO_InitStructure); + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | LOG_PERIPH_GPIO, ENABLE); + +#if (LOG_USART == 1) + RCC_EnableAPB2PeriphClk(LOG_PERIPH, ENABLE); +#else + RCC_EnableAPB1PeriphClk(LOG_PERIPH, ENABLE); +#endif + + GPIO_InitStructure.Pin = LOG_TX_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = LOG_RX_PIN; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + // init uart + USART_Init(LOG_USARTx, &USART_InitStructure); + + // enable uart + USART_Enable(LOG_USARTx, ENABLE); +} + +static int is_lr_sent = 0; + +int fputc(int ch, FILE* f) +{ + if (ch == '\r') + { + is_lr_sent = 1; + } + else if (ch == '\n') + { + if (!is_lr_sent) + { + USART_SendData(LOG_USARTx, (uint8_t)'\r'); + /* Loop until the end of transmission */ + while (USART_GetFlagStatus(LOG_USARTx, USART_FLAG_TXC) == RESET) + { + } + } + is_lr_sent = 0; + } + else + { + is_lr_sent = 0; + } + USART_SendData(LOG_USARTx, (uint8_t)ch); + /* Loop until the end of transmission */ + while (USART_GetFlagStatus(LOG_USARTx, USART_FLAG_TXC) == RESET) + { + } + return ch; +} + +void log_buff(uint8_t *data, int len) +{ + int i = 0; + for(i=0; i 0; count--) + { + i++; + } + +} + +extern void system_delay_n_10us(uint32_t value); +void Delay_ms(uint32_t count) +{ + system_delay_n_10us(100*count); +} + +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + log_error("assertion failed: `%s` at %s:%d", expr, file, line); + while (1) + { + } +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/src/n32wb03x_it.c new file mode 100644 index 0000000..546d2a4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/I2C_RAM/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/MDK-ARM/SPI_Ram.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/MDK-ARM/SPI_Ram.uvoptx new file mode 100644 index 0000000..f0c7460 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/MDK-ARM/SPI_Ram.uvoptx @@ -0,0 +1,367 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/MDK-ARM/SPI_Ram.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/MDK-ARM/SPI_Ram.uvprojx new file mode 100644 index 0000000..a116d1e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/MDK-ARM/SPI_Ram.uvprojx @@ -0,0 +1,480 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + SPI_Ram_Project + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\SPI_Ram_Project.bin .\Objects\SPI_Ram_Project.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\bsp\inc;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/inc/main.h new file mode 100644 index 0000000..144dbee --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/inc/main.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#define SPI_MASTER SPI1 +#define SPI_MASTER_CLK RCC_APB2_PERIPH_SPI1 +#define SPI_MASTER_GPIO GPIOA +#define SPI_MASTER_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define SPI_MASTER_PIN_SCK GPIO_PIN_1 +#define SPI_MASTER_PIN_MISO GPIO_PIN_3 +#define SPI_MASTER_PIN_MOSI GPIO_PIN_2 +#define SPI_MASTER_DMA DMA +#define SPI_MASTER_DMA_CLK RCC_AHB_PERIPH_DMA +#define SPI_MASTER_RX_DMA_CHANNEL DMA_CH2 +#define SPI_MASTER_RX_DMA_FLAG DMA_FLAG_TC2 +#define SPI_MASTER_TX_DMA_CHANNEL DMA_CH3 +#define SPI_MASTER_TX_DMA_FLAG DMA_FLAG_TC3 + +#define SPI_SLAVE SPI2 +#define SPI_SLAVE_CLK RCC_APB2_PERIPH_SPI2 +#define SPI_SLAVE_GPIO GPIOB +#define SPI_SLAVE_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define SPI_SLAVE_PIN_SCK GPIO_PIN_1 +#define SPI_SLAVE_PIN_MISO GPIO_PIN_3 +#define SPI_SLAVE_PIN_MOSI GPIO_PIN_2 +#define SPI_SLAVE_DMA DMA +#define SPI_SLAVE_DMA_CLK RCC_AHB_PERIPH_DMA +#define SPI_SLAVE_RX_DMA_CHANNEL DMA_CH4 +#define SPI_SLAVE_RX_DMA_FLAG DMA_FLAG_TC4 +#define SPI_SLAVE_TX_DMA_CHANNEL DMA_CH5 +#define SPI_SLAVE_TX_DMA_FLAG DMA_FLAG_TC5 + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/readme.txt new file mode 100644 index 0000000..89b9f1e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/readme.txt @@ -0,0 +1,47 @@ + + +1. Function description + This routine provides a DMA usage for transferring data between I2C peripheral and RAM. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + 1.Clock source: HSI 64M + 2.DMA channels: DMA_CH4, DMA_CH5 + 3. SPI1 configuration: + SCK --> PA1 + MISO --> PA3 + MOSI --> PA2 + Full duplex + Main mode + 8 bit transmission + Polarity: start at low/second edge + Piece of software to choose + Big end in front MSB + + 4. SPI2 Configuration: + SCK --> PB1 + MISO --> PB3 + MOSI --> PB2 + Full duplex + From the pattern + 8 bit transmission + Polarity: start at low/second edge + Piece of software to choose + Big end in front MSB + + 5.USART1 configuration: + TX --> PB6 + Baud rate: 115200 + Data bit: 8 bits + Stop bit: 1bit + No check + + 6.Test steps and phenomena + 1. Compile download code reset run + 2. View the printed information from the serial port and verify the result + +4. Precautions + None diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/src/main.c new file mode 100644 index 0000000..f827f65 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/src/main.c @@ -0,0 +1,342 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "n32wb03x.h" +#include "log.h" + +#include + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup DMA_SPI_RAM + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define BUFFER_SIZE 32 +#define CRC_POLYNOMIAL 7 + +SPI_InitType SPI_InitStructure; +DMA_InitType DMA_InitStructure; +uint8_t SPI_Master_Rx_Buffer[BUFFER_SIZE], SPI_Slave_Rx_Buffer[BUFFER_SIZE]; +volatile uint8_t SPI_MASTERCRCValue = 0, SPI_SLAVECRCValue = 0; +volatile Status TransferStatus1 = FAILED, TransferStatus2 = FAILED; + +uint8_t SPI_Master_Tx_Buffer[BUFFER_SIZE] = {0xf1, 0x2e, 0xf1, 0xaf, 0x08, 0xa2, 0x41, 0xb4, 0xc8, 0x19, 0x38, + 0xb7, 0xd9, 0xdb, 0x9a, 0x64, 0x1f, 0xd6, 0x99, 0x9c, 0x0f, 0xae, + 0x84, 0xab, 0xda, 0x12, 0x95, 0x6c, 0xdb, 0xec, 0x06, 0x08}; + +uint8_t SPI_Slave_Tx_Buffer[BUFFER_SIZE] = {0x2c, 0x99, 0xd7, 0x26, 0xb0, 0xe5, 0xb2, 0xfc, 0xee, 0x88, 0x3f, + 0xde, 0xa4, 0x37, 0x87, 0xc9, 0xb2, 0x9c, 0xce, 0xc8, 0x2c, 0x22, + 0x6b, 0xfe, 0xba, 0x49, 0x94, 0x0a, 0x47, 0x5a, 0xb7, 0x89}; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength); + +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + log_info("\n this is a SPI_DMA to RAM Demo.\n"); + + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* SPI_MASTER configuration + * ------------------------------------------------*/ + SPI_I2S_DeInit(SPI_MASTER); + SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX; + SPI_InitStructure.SpiMode = SPI_MODE_MASTER; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_4; + SPI_InitStructure.FirstBit = SPI_FB_MSB; + SPI_InitStructure.CRCPoly = CRC_POLYNOMIAL; + SPI_Init(SPI_MASTER, &SPI_InitStructure); + + /* SPI_SLAVE configuration + * -------------------------------------------------*/ + SPI_I2S_DeInit(SPI_SLAVE); + SPI_InitStructure.SpiMode = SPI_MODE_SLAVE; + SPI_Init(SPI_SLAVE, &SPI_InitStructure); + + /* SPI_MASTER_RX_DMA_CHANNEL configuration + * ---------------------------------*/ + DMA_DeInit(SPI_MASTER_RX_DMA_CHANNEL); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI1->DAT; //SPI_MASTER_DR_BASE; + DMA_InitStructure.MemAddr = (uint32_t)SPI_Master_Rx_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = BUFFER_SIZE; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(SPI_MASTER_RX_DMA_CHANNEL, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_SPI1_RX,DMA,SPI_MASTER_RX_DMA_CHANNEL,ENABLE); + + /* SPI_MASTER_TX_DMA_CHANNEL configuration + * ---------------------------------*/ + DMA_DeInit(SPI_MASTER_TX_DMA_CHANNEL); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI1->DAT; + DMA_InitStructure.MemAddr = (uint32_t)SPI_Master_Tx_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.Priority = DMA_PRIORITY_LOW; + DMA_Init(SPI_MASTER_TX_DMA_CHANNEL, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_SPI1_TX,DMA,SPI_MASTER_TX_DMA_CHANNEL,ENABLE); + + /* SPI_SLAVE_RX_DMA_CHANNEL configuration + * ----------------------------------*/ + DMA_DeInit(SPI_SLAVE_RX_DMA_CHANNEL); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI2->DAT; + DMA_InitStructure.MemAddr = (uint32_t)SPI_Slave_Rx_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_Init(SPI_SLAVE_RX_DMA_CHANNEL, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_SPI2_RX,DMA,SPI_SLAVE_RX_DMA_CHANNEL,ENABLE); + + /* SPI_SLAVE_TX_DMA_CHANNEL configuration + * ----------------------------------*/ + DMA_DeInit(SPI_SLAVE_TX_DMA_CHANNEL); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI2->DAT; + DMA_InitStructure.MemAddr = (uint32_t)SPI_Slave_Tx_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.Priority = DMA_PRIORITY_MEDIUM; + DMA_Init(SPI_SLAVE_TX_DMA_CHANNEL, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_SPI2_TX,DMA,SPI_SLAVE_TX_DMA_CHANNEL,ENABLE); + + /* Enable SPI_MASTER DMA Tx request */ + SPI_I2S_EnableDma(SPI_MASTER, SPI_I2S_DMA_TX, ENABLE); + /* Enable SPI_MASTER DMA Rx request */ + SPI_I2S_EnableDma(SPI_MASTER, SPI_I2S_DMA_RX, ENABLE); + /* Enable SPI_SLAVE DMA Tx request */ + SPI_I2S_EnableDma(SPI_SLAVE, SPI_I2S_DMA_TX, ENABLE); + /* Enable SPI_SLAVE DMA Rx request */ + SPI_I2S_EnableDma(SPI_SLAVE, SPI_I2S_DMA_RX, ENABLE); + + /* Enable SPI_MASTER CRC calculation */ + SPI_EnableCalculateCrc(SPI_MASTER, ENABLE); + /* Enable SPI_MASTER */ + SPI_Enable(SPI_MASTER, ENABLE); + + /* Enable SPI_SLAVE CRC calculation */ + SPI_EnableCalculateCrc(SPI_SLAVE, ENABLE); + /* Enable SPI_SLAVE */ + SPI_Enable(SPI_SLAVE, ENABLE); + + /* Enable DMA channels */ + DMA_EnableChannel(SPI_MASTER_RX_DMA_CHANNEL, ENABLE); + DMA_EnableChannel(SPI_SLAVE_RX_DMA_CHANNEL, ENABLE); + DMA_EnableChannel(SPI_SLAVE_TX_DMA_CHANNEL, ENABLE); + DMA_EnableChannel(SPI_MASTER_TX_DMA_CHANNEL, ENABLE); + + /* Transfer complete */ + while (!DMA_GetFlagStatus(SPI_MASTER_RX_DMA_FLAG, SPI_MASTER_DMA)) + ; + while (!DMA_GetFlagStatus(SPI_SLAVE_RX_DMA_FLAG, SPI_SLAVE_DMA)) + ; + while (!DMA_GetFlagStatus(SPI_SLAVE_TX_DMA_FLAG, SPI_SLAVE_DMA)) + ; + while (!DMA_GetFlagStatus(SPI_MASTER_TX_DMA_FLAG, SPI_MASTER_DMA)) + ; + + /* Wait for SPI_MASTER data reception: CRC transmitted by SPI_SLAVE */ + while (SPI_I2S_GetStatus(SPI_MASTER, SPI_I2S_RNE_FLAG) == RESET) + ; + /* Wait for SPI_SLAVE data reception: CRC transmitted by SPI_MASTER */ + while (SPI_I2S_GetStatus(SPI_SLAVE, SPI_I2S_RNE_FLAG) == RESET) + ; + + /* Check the correctness of written dada */ + TransferStatus1 = Buffercmp(SPI_Slave_Rx_Buffer, SPI_Master_Tx_Buffer, BUFFER_SIZE); + TransferStatus2 = Buffercmp(SPI_Master_Rx_Buffer, SPI_Slave_Tx_Buffer, BUFFER_SIZE); + + /* Test on the SPI_MASTER CRCR ERROR flag */ + if ((SPI_I2S_GetStatus(SPI_MASTER, SPI_CRCERR_FLAG)) != RESET) + { + TransferStatus1 = FAILED; + } + /* Test on the SPI_SLAVE CRCR ERROR flag */ + if ((SPI_I2S_GetStatus(SPI_SLAVE, SPI_CRCERR_FLAG)) != RESET) + { + TransferStatus2 = FAILED; + } + + /* Read SPI_MASTER received CRC value */ + SPI_MASTERCRCValue = SPI_I2S_ReceiveData(SPI_MASTER); + /* Read SPI_SLAVE received CRC value */ + SPI_SLAVECRCValue = SPI_I2S_ReceiveData(SPI_SLAVE); + + if (TransferStatus1 != FAILED) + { + log_info("SPI master passed.\n"); + } + else + { + log_error("SPI master failed.\n"); + } + + if (TransferStatus2 != FAILED) + { + log_info("SPI slave passed.\n"); + } + else + { + log_error("SPI slave failed.\n"); + } + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks + * ------------------------------------------------*/ + /* Enable DMA clock */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + + /* Enable SPI_MASTER clock and GPIO clock for SPI_MASTER and SPI_SLAVE */ + RCC_EnableAPB2PeriphClk(SPI_MASTER_GPIO_CLK | SPI_SLAVE_GPIO_CLK | SPI_MASTER_CLK | SPI_SLAVE_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure SPI_MASTER pins: SCK and MOSI */ + GPIO_InitStructure.Pin = SPI_MASTER_PIN_SCK | SPI_MASTER_PIN_MOSI; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_LOW; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_SPI1; + GPIO_InitPeripheral(SPI_MASTER_GPIO, &GPIO_InitStructure); + /* Configure SPI_MASTER pins: MISO */ + GPIO_InitStructure.Pin = SPI_MASTER_PIN_MISO; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_SPI1; + GPIO_InitPeripheral(SPI_MASTER_GPIO, &GPIO_InitStructure); + + /* Configure SPI_SLAVE pins: SCK and MOSI */ + GPIO_InitStructure.Pin = SPI_SLAVE_PIN_SCK | SPI_SLAVE_PIN_MOSI; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_SPI2; + GPIO_InitPeripheral(SPI_SLAVE_GPIO, &GPIO_InitStructure); + /* Configure SPI_SLAVE pins: MISO */ + GPIO_InitStructure.Pin = SPI_SLAVE_PIN_MISO; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_SPI2; + GPIO_InitPeripheral(SPI_SLAVE_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer, pBuffer1: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer identical to pBuffer1 + * FAILED: pBuffer differs from pBuffer1 + */ +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer != *pBuffer1) + { + return FAILED; + } + + pBuffer++; + pBuffer1++; + } + + return PASSED; +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/src/n32wb03x_it.c new file mode 100644 index 0000000..546d2a4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/DMA/SPI_RAM/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/MDK-ARM/KeyInterrupt.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/MDK-ARM/KeyInterrupt.uvoptx new file mode 100644 index 0000000..d78d037 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/MDK-ARM/KeyInterrupt.uvoptx @@ -0,0 +1,323 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 9 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/MDK-ARM/KeyInterrupt.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/MDK-ARM/KeyInterrupt.uvprojx new file mode 100644 index 0000000..6ef0897 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/MDK-ARM/KeyInterrupt.uvprojx @@ -0,0 +1,460 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + KeyInterrupt + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\KeyInterrupt.bin .\Objects\KeyInterrupt.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/inc/main.h new file mode 100644 index 0000000..93be156 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/inc/main.h @@ -0,0 +1,109 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 + +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +#if 0 +#define KEY_INPUT_PORT GPIOB +#define KEY_INPUT_PIN GPIO_PIN_1 +#define KEY_INPUT_EXTI_LINE EXTI_LINE1 +#define KEY_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY_INPUT_PIN_SOURCE GPIO_PIN_SOURCE1 +#define KEY_INPUT_IRQn EXTI0_1_IRQn +#else +#define KEY_INPUT_PORT GPIOB +#define KEY_INPUT_PIN GPIO_PIN_2 +#define KEY_INPUT_EXTI_LINE EXTI_LINE2 +#define KEY_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY_INPUT_PIN_SOURCE GPIO_PIN_SOURCE2 +#define KEY_INPUT_IRQn EXTI2_3_IRQn +#endif + +void Delay(uint32_t count); +void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/inc/n32wb03x_it.h new file mode 100644 index 0000000..5136e6d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void DMA_IRQ_HANDLER(void); +void EXTI4_15_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/readme.txt new file mode 100644 index 0000000..12df461 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/readme.txt @@ -0,0 +1,22 @@ + +1. Function description + + This example shows how to control LED blinking by externally triggering an interrupt. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + //Describe related module configuration methods; for example, clock, I/O, etc. + 1. SystemClock: HSI:64MHz + 2. GPIO: PB2 is selected as the external interrupt entry, PA6 controls the LED2 to flash. + + //Describe the test steps and phenomena of the Demo + 1. Compile and download the code to reset and run. + 2. Press and release the KEY2 button,then the LED will flash. + +4. Matters needing attention + None \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/src/main.c new file mode 100644 index 0000000..458b70e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/src/main.c @@ -0,0 +1,223 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include + +/** + * @brief Main program. + */ +int main(void) +{ + /*Initialize Led1 and Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Initialize key as external line interrupt*/ + KeyInputExtiInit(KEY_INPUT_PORT, KEY_INPUT_PIN); + + /*Turn on Led1*/ + LedOn(LED1_PORT, LED1_PIN); + + while (1) + { + } +} + +/** + * @brief Inserts a delay time. + * @param count specifies the delay time length. + */ +void Delay(uint32_t count) +{ + for (; count > 0; count--) + ; +} +/** + * @brief Configures key port. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + } + else + { + return; + } + + /*Configure the GPIO pin as input floating*/ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } + + /*Configure key EXTI Line to key input Pin*/ + GPIO_ConfigEXTILine(KEY_INPUT_PORT_SOURCE, KEY_INPUT_PIN_SOURCE); + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; // EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin as output push-pull */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @brief Assert failed function by user. + * @param file The name of the call that failed. + * @param line The source line number of the call that failed. + */ +#ifdef USE_FULL_ASSERT +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + while (1) + { + } +} +#endif // USE_FULL_ASSERT +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/src/n32wb03x_it.c new file mode 100644 index 0000000..6a95304 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/EXTI/KeyInterrupt/src/n32wb03x_it.c @@ -0,0 +1,163 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup n32wb03x_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/** + * @brief This function handles DMA interrupt request defined in main.h . + */ +void DMA_IRQ_HANDLER(void) +{ +} + +/******************************************************************************/ +/* n32wb03x Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ +/** + * @brief External lines 4 to 15 interrupt. + */ + +void EXTI0_1_IRQHandler(void) +{ + if (RESET != EXTI_GetITStatus(KEY_INPUT_EXTI_LINE)) + { + if(GPIO_ReadInputDataBit(KEY_INPUT_PORT, KEY_INPUT_PIN) == RESET) + { + Delay(10); + if(GPIO_ReadInputDataBit(KEY_INPUT_PORT, KEY_INPUT_PIN) == RESET) + { + LedBlink(LED2_PORT, LED2_PIN); + } + } + EXTI_ClrITPendBit(KEY_INPUT_EXTI_LINE); + } +} + +void EXTI2_3_IRQHandler(void) +{ + if (RESET != EXTI_GetITStatus(KEY_INPUT_EXTI_LINE)) + { + if(GPIO_ReadInputDataBit(KEY_INPUT_PORT, KEY_INPUT_PIN) == RESET) + { + Delay(10); + if(GPIO_ReadInputDataBit(KEY_INPUT_PORT, KEY_INPUT_PIN) == RESET) + { + LedBlink(LED2_PORT, LED2_PIN); + } + } + EXTI_ClrITPendBit(KEY_INPUT_EXTI_LINE); + } +} +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/MDK-ARM/flash_rw.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/MDK-ARM/flash_rw.uvoptx new file mode 100644 index 0000000..2bf7eb3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/MDK-ARM/flash_rw.uvoptx @@ -0,0 +1,323 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 5 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc\n32wb03x_qflash.h + n32wb03x_qflash.h + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 9 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/MDK-ARM/flash_rw.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/MDK-ARM/flash_rw.uvprojx new file mode 100644 index 0000000..b64c1a8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/MDK-ARM/flash_rw.uvprojx @@ -0,0 +1,460 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + flash_rw + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\flash_rw.bin .\Objects\flash_rw.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03x, USE_STDPERIPH_DRIVER + + ..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_qflash.h + 5 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc\n32wb03x_qflash.h + + + + + USER + + + main.c + 1 + ..\src\main.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/readme.txt new file mode 100644 index 0000000..81bce72 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/readme.txt @@ -0,0 +1,45 @@ + +1. Function description + + /* Briefly describe the project function */ + Demonstrates how to read, write and erase Qflash. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + /* Describe related module configuration methods; for example: clock, I/O, etc. */ + SystemClock: HSI 64MHz + LED1: PB0 + LED2: PA6 + + /* Describe the test steps and phenomena of the Demo */ + 1. After compiling, download the program to reset and run; + 2. LED1 light meaning read and write fial. + 3. LED2 light meaning read and write success. + + +4. Matters needing attention + + + + + + + + + + + + + + + + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/src/main.c new file mode 100644 index 0000000..79fbac2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/FLASH/FLASH_RW/src/main.c @@ -0,0 +1,144 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include +#include +#include +#include "n32wb03x.h" + + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +#define FLASH_TEST_ADDRESS 0x1020000 +#define BUFFER_SIZE 4096 +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static uint8_t m_buffer[BUFFER_SIZE]; +//Allocate a buffer for read flash memory and for compare with a static buffer. +static uint8_t buffer[BUFFER_SIZE]; +GPIO_InitType GPIO_InitStructure; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +static void assert_handle(void) +{ + GPIO_SetBits(LED1_PORT, LED1_PIN); + while(1){ + + } +} + + +/** + * @brief Main program. + */ +int main(void) +{ + //Initialize dev board leds + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + GPIO_InitStructure.Pin = LED1_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitPeripheral(LED1_PORT, &GPIO_InitStructure); + GPIO_InitStructure.Pin = LED2_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitPeripheral(LED2_PORT, &GPIO_InitStructure); + GPIO_ResetBits(LED1_PORT, LED1_PIN); + GPIO_ResetBits(LED2_PORT, LED2_PIN); + + //Initialize Qflash. + Qflash_Init(); + //Erase one Flash Sector + Qflash_Erase_Sector(FLASH_TEST_ADDRESS); + //Read test flash sector into buffer ram + Qflash_Read(FLASH_TEST_ADDRESS, buffer, BUFFER_SIZE); + for(uint32_t i=0;i + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 5 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 6 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 7 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/MDK-ARM/IOToggle_MaxFrequency.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/MDK-ARM/IOToggle_MaxFrequency.uvprojx new file mode 100644 index 0000000..d49ba27 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/MDK-ARM/IOToggle_MaxFrequency.uvprojx @@ -0,0 +1,450 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + IOToggle_MaxFrequency + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\IOToggle_MaxFrequency.bin .\Objects\IOToggle_MaxFrequency.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/inc/main.h new file mode 100644 index 0000000..640bd56 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/inc/main.h @@ -0,0 +1,84 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define GPIOx GPIOA +#define GPIOx_PIN GPIO_PIN_0 +#define GPIOx_CLK RCC_APB2_PERIPH_GPIOA + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/inc/n32wb03x_it.h new file mode 100644 index 0000000..e706c93 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void DMA1_Channel6_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/readme.txt new file mode 100644 index 0000000..4dc9702 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/readme.txt @@ -0,0 +1,17 @@ + +1. Function description + 1. This routine shows IO level flipping quickly +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO: the level of the PA0 pin flips quickly + + Instructions: + 1. After compiling, download the program to reset and run + 2. Use an oscilloscope to see the PA0 pin level flips quickly +4. Matters needing attention + Null diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/src/main.c new file mode 100644 index 0000000..545da4c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/src/main.c @@ -0,0 +1,118 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include + +GPIO_InitType GPIO_InitStructure; + +/** + * @brief Main program. + */ +int main(void) +{ + /* -1- Enable GPIOx Clock (to be able to program the configuration registers) */ + RCC_EnableAPB2PeriphClk(GPIOx_CLK, ENABLE); + + /* -2- Configure GPIOx_PIN in output push-pull mode */ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIOx_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + + /* -3- Toggle GPIOx_PIN in an infinite loop */ + while (1) + { + GPIOA->POD = 1; + GPIOA->POD = 0; + GPIOA->POD = 1; + GPIOA->POD = 0; + GPIOA->POD = 1; + GPIOA->POD = 0; + GPIOA->POD = 1; + GPIOA->POD = 0; + GPIOA->POD = 1; + GPIOA->POD = 0; + GPIOA->POD = 1; + GPIOA->POD = 0; + GPIOA->POD = 1; + GPIOA->POD = 0; + GPIOA->POD = 1; + GPIOA->POD = 0; + GPIOA->POD = 1; + GPIOA->POD = 0; + GPIOA->POD = 1; + GPIOA->POD = 0; + } +} + +/** + * @brief Assert failed function by user. + * @param file The name of the call that failed. + * @param line The source line number of the call that failed. + */ +#ifdef USE_FULL_ASSERT +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + while (1) + { + } +} +#endif // USE_FULL_ASSERT +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/src/n32wb03x_it.c new file mode 100644 index 0000000..3aa1ef8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/IOToggle_MaxFrequency/src/n32wb03x_it.c @@ -0,0 +1,130 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/** + * @brief This function handles DMA interrupt request defined in main.h . + */ +void DMA_IRQ_HANDLER(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/MDK-ARM/LedBlink.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/MDK-ARM/LedBlink.uvoptx new file mode 100644 index 0000000..783d72c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/MDK-ARM/LedBlink.uvoptx @@ -0,0 +1,299 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 5 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 6 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 7 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/MDK-ARM/LedBlink.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/MDK-ARM/LedBlink.uvprojx new file mode 100644 index 0000000..a43ef42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/MDK-ARM/LedBlink.uvprojx @@ -0,0 +1,450 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + LedBlink + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\LedBlink.bin .\Objects\LedBlink.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/inc/main.h new file mode 100644 index 0000000..b4787d3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/inc/main.h @@ -0,0 +1,92 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 + +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +void Delay(uint32_t count); +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/inc/n32wb03x_it.h new file mode 100644 index 0000000..14ecd43 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void DMA_IRQ_HANDLER(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/readme.txt new file mode 100644 index 0000000..39ed6a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/readme.txt @@ -0,0 +1,18 @@ + + +1. Function description + 1. This routine shows the IO control LED blinking + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO: PB0, PA6 control LED1, LED2 to blink + Instructions: + 1. After compiling, download the program to reset and run + 2. LED1, LED2 to blinking +4. Matters needing attention + No \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/src/main.c new file mode 100644 index 0000000..a593cec --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/src/main.c @@ -0,0 +1,187 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include + +/** + * @brief Main program. + */ +int main(void) +{ + /* Initialize Led1~Led2 as output pushpull mode*/ + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + /*Turn on Led1~Led2*/ + LedOn(LED1_PORT, LED1_PIN); + LedOn(LED2_PORT, LED2_PIN); + + while (1) + { + /*LED1_PORT, LED1_PORT and LED2_PORT are the same port group.*/ + + /*Led1 blink */ + LedBlink(LED1_PORT, LED1_PIN); + + /*Turn Led2 off*/ + LedOff(LED2_PORT, LED2_PIN); + /* Insert delay */ + Delay(0x28FFFF); + + /*Turn on Led2*/ + LedOn(LED2_PORT, LED2_PIN); + /* Insert delay */ + Delay(0x28FFFF); + } +} + +/** + * @brief Inserts a delay time. + * @param count specifies the delay time length. + */ +void Delay(uint32_t count) +{ + int i = 0; + for (; count > 0; count--) + { + i++; + } + +} +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @brief Assert failed function by user. + * @param file The name of the call that failed. + * @param line The source line number of the call that failed. + */ +#ifdef USE_FULL_ASSERT +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + while (1) + { + } +} +#endif // USE_FULL_ASSERT + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/src/n32wb03x_it.c new file mode 100644 index 0000000..e32b9ee --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/GPIO/LedBlink/src/n32wb03x_it.c @@ -0,0 +1,128 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/** + * @brief This function handles DMA interrupt request defined in main.h . + */ +void DMA_IRQ_HANDLER(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/MDK-ARM/I2C_EEPROM.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/MDK-ARM/I2C_EEPROM.uvoptx new file mode 100644 index 0000000..5ecbba3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/MDK-ARM/I2C_EEPROM.uvoptx @@ -0,0 +1,359 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + 4 + 11 + 1 + 0 + 0 + 0 + ..\src\i2c_eeprom.c + i2c_eeprom.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/MDK-ARM/I2C_EEPROM.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/MDK-ARM/I2C_EEPROM.uvprojx new file mode 100644 index 0000000..5bf8a30 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/MDK-ARM/I2C_EEPROM.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + I2C_EEPROM_Project + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\I2C_EEPROM_Project.bin .\Objects\I2C_EEPROM_Project.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER,USE_FULL_ASSERT=1 + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\src + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + i2c_eeprom.c + 1 + ..\src\i2c_eeprom.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/inc/main.h new file mode 100644 index 0000000..8c40b4b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/inc/main.h @@ -0,0 +1,105 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define DMA_CHANNEL_USED DMA1_CH1 +#define DMA_IRQ_HANDLER DMA1_Channel1_IRQHandler +#define DMA_IT_FLAG_TC DMA1_INT_TXC1 +#define DMA_IT_FLAG_GL DMA1_INT_GLB1 +#define DMA_IRQN DMA1_Channel1_IRQn + +#define LOG_USARTx USART2 +#define LOG_PERIPH RCC_APB1_PERIPH_USART2 +#define LOG_GPIO GPIOB +#define LOG_PERIPH_GPIO RCC_APB2_PERIPH_GPIOB +#define LOG_TX_PIN GPIO_PIN_4 +#define LOG_RX_PIN GPIO_PIN_5 +#define LOG_GPIO_AF GPIO_AF3_USART2 //GPIO_AF4_USART1 + +#define log_info(...) printf(__VA_ARGS__) +#define log_error(...) printf(__VA_ARGS__) +void log_init(void); +void log_buff(uint8_t *data, int len); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/readme.txt new file mode 100644 index 0000000..eebe54f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/readme.txt @@ -0,0 +1,34 @@ + +1. Function description + + This example demonstrates the communication with the external EEPRON through the I2C module. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + 1. SystemClock: HSI 64MHz + 2. I2C1 configuration: + SCL --> PB7 + SDA --> PB6 + CLOCK: 100KHz + + 3. USART2 configuration: + TX --> PB4 + RX --> PB5 + Baud rate: 115200 + + 4. Test using EEPROM model: + AT24C04 (capacity 4kb) + + + 5. Test steps and phenomena + a, check the EEPROM connection + b, compile and download the code, reset and run + c, view the print information from the serial port and verify the result + +4. Matters needing attention + SCL and SDA must be pulled up \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/i2c_eeprom.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/i2c_eeprom.c new file mode 100644 index 0000000..542bc48 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/i2c_eeprom.c @@ -0,0 +1,822 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file i2c_eeprom.c + * @author NSING Firmware Team + * @version v1.0.4 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "n32wb03x_dma.h" +#include "i2c_eeprom.h" +#include "string.h" +#include "stdbool.h" + +#include "main.h" + +/** @addtogroup I2C_EEPROM + * @{ + */ + +/* when EEPROM is writing data inside,it won't response the request from the master.check the ack, +if EEPROM response,make clear that EEPROM finished the last data-writing,allow the next operation */ +static bool check_begin = FALSE; +static bool DeviceDone = FALSE; +static bool addressDone = FALSE; +u32 sEETimeout = sEE_LONG_TIMEOUT; + +static u8 MasterDirection = Transmitter; +static u16 SlaveADDR; +static u16 DeviceOffset = 0x0; + +u16 I2C_NumByteToWrite = 0; +u8 I2C_NumByteWritingNow = 0; +u8* I2C_pBuffer = 0; +u16 I2C_WriteAddr = 0; + +static u8 SendBuf[32] = {0}; +static u8 *recvBuf = NULL; +static u16 BufCount = 0; +static volatile u16 Int_NumByteToWrite = 0; +static volatile u16 Int_NumByteToRead = 0; +/* global state variable i2c_comm_state */ +volatile I2C_STATE i2c_comm_state; + +/** + * @brief Timeout callback used by the I2C EEPROM driver. + */ +u8 sEE_TIMEOUT_UserCallback(void) +{ + printf("error!!!\r\n"); + /* Block communication and all processes */ + while (1) + { + } +} + +/** + * @brief Initializes peripherals used by the I2C EEPROM driver. + */ +void I2C_EE_Init(void) +{ + /** GPIO configuration and clock enable */ + GPIO_InitType GPIO_InitStructure; + I2C_InitType I2C_InitStructure; + +#if (PROCESS_MODE == 1) // interrupt + NVIC_InitType NVIC_InitStructure; +#endif + + GPIO_InitStruct(&GPIO_InitStructure); + + /** enable peripheral clk*/ + I2Cx_peripheral_clk_en(); + I2C_DeInit(I2Cx); + + I2Cx_scl_clk_en(); + I2Cx_sda_clk_en(); + + GPIO_InitStructure.Pin = I2Cx_SCL_PIN | I2Cx_SDA_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_LOW; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_OD; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = I2Cx_GPIO_AF; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + + /** I2C periphral configuration */ + I2C_DeInit(I2Cx); + I2C_InitStructure.BusMode = I2C_BUSMODE_I2C; + I2C_InitStructure.FmDutyCycle = I2C_FMDUTYCYCLE_1; + I2C_InitStructure.OwnAddr1 = 0xff; + I2C_InitStructure.AckEnable = I2C_ACKEN; + I2C_InitStructure.AddrMode = I2C_ADDR_MODE_7BIT; + I2C_InitStructure.ClkSpeed = I2C_Speed; + I2C_Init(I2Cx, &I2C_InitStructure); + +#if (PROCESS_MODE == 1) /* interrupt */ + /** I2C NVIC configuration */ + NVIC_InitStructure.NVIC_IRQChannel = I2Cx_IRQ; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +#elif PROCESS_MODE == 2 /* DMA */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +#endif +} + +/** + * @brief Writes buffer of data to the I2C EEPROM. + * @param pBuffer pointer to the buffer containing the data to be + * written to the EEPROM. + * @param WriteAddr EEPROM's internal address to write to. + * @param NumByteToWrite number of bytes to write to the EEPROM. + */ +void I2C_EE_WriteBuffer(u8* pBuffer, u16 WriteAddr, u16 NumByteToWrite) +{ + if (I2C_GetFlag(I2Cx, I2C_FLAG_BUSY)) + { + printf("I2C busy\r\n"); + I2C_ClrFlag(I2Cx, I2C_FLAG_BUSY); + return; + } + I2C_pBuffer = pBuffer; + I2C_WriteAddr = WriteAddr; + I2C_NumByteToWrite = NumByteToWrite; + + while (I2C_NumByteToWrite > 0) + { + I2C_EE_WriteOnePage(I2C_pBuffer, I2C_WriteAddr, I2C_NumByteToWrite); + } +} + +/** + * @brief Writes a page of data to the I2C EEPROM, general called by + * I2C_EE_WriteBuffer. + * @param pBuffer pointer to the buffer containing the data to be + * written to the EEPROM. + * @param WriteAddr EEPROM's internal address to write to. + * @param NumByteToWrite number of bytes to write to the EEPROM. + */ +void I2C_EE_WriteOnePage(u8* pBuffer, u16 WriteAddr, u16 NumByteToWrite) +{ + u8 NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0; + + Addr = WriteAddr % I2C_PageSize; + count = I2C_PageSize - Addr; + NumOfPage = NumByteToWrite / I2C_PageSize; + NumOfSingle = NumByteToWrite % I2C_PageSize; + + I2C_NumByteWritingNow = 0; + /** If WriteAddr is I2C_PageSize aligned */ + if (Addr == 0) + { + /** If NumByteToWrite < I2C_PageSize */ + if (NumOfPage == 0) + { + I2C_NumByteWritingNow = NumOfSingle; + I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle); + } + /** If NumByteToWrite > I2C_PageSize */ + else + { + I2C_NumByteWritingNow = I2C_PageSize; + I2C_EE_PageWrite(pBuffer, WriteAddr, I2C_PageSize); + } + } + /** If WriteAddr is not I2C_PageSize aligned */ + else + { + /* If NumByteToWrite < I2C_PageSize */ + if (NumOfPage == 0) + { + I2C_NumByteWritingNow = NumOfSingle; + I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle); + } + /* If NumByteToWrite > I2C_PageSize */ + else + { + if (count != 0) + { + I2C_NumByteWritingNow = count; + I2C_EE_PageWrite(pBuffer, WriteAddr, count); + } + } + } +} + +/** + * @brief Writes more than one byte to the EEPROM with a single WRITE + * cycle. The number of byte can't exceed the EEPROM page size. + * @param pBuffer pointer to the buffer containing the data to be + * written to the EEPROM. + * @param WriteAddr EEPROM's internal address to write to (1-16). + * @param NumByteToWrite number of bytes to write to the EEPROM. + */ +void I2C_EE_PageWrite(u8* pBuffer, u16 WriteAddr, u16 NumByteToWrite) +{ +#if (PROCESS_MODE == 0) /* polling */ + sEETimeout = sEE_LONG_TIMEOUT; + while (I2C_GetFlag(I2Cx, I2C_FLAG_BUSY)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + /** Send START condition */ + I2C_GenerateStart(I2Cx, ENABLE); + /** Test on EV5 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_MODE_FLAG)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** Send EEPROM address for write */ + I2C_SendAddr7bit(I2Cx, EEPROM_ADDRESS, I2C_DIRECTION_SEND); + /** Test on EV6 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_TXMODE_FLAG)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** Send the EEPROM's internal address to write to */ + I2C_SendData(I2Cx, WriteAddr>>8); + /** Test on EV8 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_DATA_SENDED)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + I2C_SendData(I2Cx, WriteAddr); + /** Test on EV8 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_DATA_SENDED)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** While there is data to be written */ + while (NumByteToWrite--) + { + /** Send the current byte */ + I2C_SendData(I2Cx, *pBuffer); + /** Point to the next byte to be written */ + pBuffer++; + /** Test on EV8 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_DATA_SENDED)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + } + /** Send STOP condition */ + I2C_GenerateStop(I2Cx, ENABLE); + I2C_EE_WaitEepromStandbyState(); + I2C_EE_WriteOnePageCompleted(); + +#elif PROCESS_MODE == 1 /* interrupt */ + /** initialize static parameter */ + MasterDirection = Transmitter; + i2c_comm_state = COMM_PRE; + /** initialize static parameter according to input parameter */ + SlaveADDR = EEPROM_ADDRESS; /// this byte shoule be send by F/W (in loop or INTSTS way) + DeviceOffset = WriteAddr; /// this byte can be send by both F/W and DMA + check_begin = FALSE; + + memcpy(SendBuf, pBuffer, NumByteToWrite); + BufCount = 0; + Int_NumByteToWrite = NumByteToWrite; + + I2C_ConfigAck(I2Cx, ENABLE); + I2C_ConfigInt(I2Cx, I2C_INT_EVENT | I2C_INT_BUF | I2C_INT_ERR, ENABLE); + + /** Send START condition */ + sEETimeout = sEE_LONG_TIMEOUT; + while (I2C_GetFlag(I2Cx, I2C_FLAG_BUSY)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + I2C_GenerateStart(I2Cx, ENABLE); + I2C_EE_WaitOperationIsCompleted(); + I2C_EE_WriteOnePageCompleted(); + +#elif PROCESS_MODE == 2 /* DMA */ + DMA_InitType DMA_InitStructure; + NVIC_InitType NVIC_InitStructure; + /** DMA initialization */ + DMA_DeInit(DMA_CH2); + DMA_InitStructure.PeriphAddr = (u32)&I2Cx->DAT; /// (u32)I2C1_DR_Address; + DMA_InitStructure.MemAddr = (u32)pBuffer; /// from function input parameter + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; /// fixed for send function + DMA_InitStructure.BufSize = NumByteToWrite; /// from function input parameter + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; // fixed + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; /// fixed + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; /// fixed + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; /// fixed + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; /// fixed + DMA_InitStructure.Priority = DMA_PRIORITY_HIGH; /// up to user + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; /// fixed + DMA_Init(DMA_CH2, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_I2C_TX, DMA, DMA_CH2, ENABLE); + DMA_ConfigInt(DMA_CH2, DMA_INT_TXC, ENABLE); + + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + i2c_comm_state = COMM_PRE; + sEETimeout = sEE_LONG_TIMEOUT; + while (I2C_GetFlag(I2Cx, I2C_FLAG_BUSY)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + /** Send START condition */ + I2C_GenerateStart(I2Cx, ENABLE); + /** Test on EV5 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_MODE_FLAG)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** Send EEPROM address for write */ + I2C_SendAddr7bit(I2Cx, EEPROM_ADDRESS, I2C_DIRECTION_SEND); + /** Test on EV6 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_TXMODE_FLAG)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** Send the EEPROM's internal address to write to */ + I2C_SendData(I2Cx, WriteAddr>>8); + /** Test on EV8 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_DATA_SENDED)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + I2C_SendData(I2Cx, WriteAddr); + /** Test on EV8 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_DATA_SENDED)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + I2C_EnableDMA(I2C1, ENABLE); + DMA_EnableChannel(DMA_CH2, ENABLE); + + sEETimeout = sEE_LONG_TIMEOUT; + while (i2c_comm_state != COMM_IN_PROCESS) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + I2C_EE_WaitEepromStandbyState(); + I2C_EE_WriteOnePageCompleted(); +#endif +} + +/** + * @brief Process Write one page completed. + */ +void I2C_EE_WriteOnePageCompleted(void) +{ + I2C_pBuffer += I2C_NumByteWritingNow; + I2C_WriteAddr += I2C_NumByteWritingNow; + I2C_NumByteToWrite -= I2C_NumByteWritingNow; +} + +/** + * @brief Reads a block of data from the EEPROM. + * @param pBuffer pointer to the buffer that receives the data read + * from the EEPROM. + * @param ReadAddr EEPROM's internal address to read from. + * @param NumByteToRead number of bytes to read from the EEPROM. + */ +void I2C_EE_ReadBuffer(u8* pBuffer, u16 ReadAddr, u16 NumByteToRead) +{ + sEETimeout = sEE_LONG_TIMEOUT; + while (I2C_GetFlag(I2Cx, I2C_FLAG_BUSY)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** Send START condition */ + I2C_GenerateStart(I2Cx, ENABLE); + /** Test on EV5 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_MODE_FLAG)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** Send EEPROM address for write */ + I2C_SendAddr7bit(I2Cx, EEPROM_ADDRESS, I2C_DIRECTION_SEND); + /** Test on EV6 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_TXMODE_FLAG)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** Clear EV6 by setting again the PE bit */ + I2C_Enable(I2Cx, ENABLE); + /** Send the EEPROM's internal address to write to */ + I2C_SendData(I2Cx, ReadAddr>>8); + /** Test on EV8 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_DATA_SENDED)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + I2C_SendData(I2Cx, ReadAddr); + /** Test on EV8 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_DATA_SENDED)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** Send STRAT condition a second time */ + I2C_GenerateStart(I2Cx, ENABLE); + /** Test on EV5 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_MODE_FLAG)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + /** Send EEPROM address for read */ + I2C_SendAddr7bit(I2Cx, EEPROM_ADDRESS, I2C_DIRECTION_RECV); + /* Test on EV6 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_GetFlag(I2Cx, I2C_FLAG_ADDRF)) //EV6 + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /* While there is data to be read */ + while (NumByteToRead) + { + /** One byte */ + if (NumByteToRead == 1) + { + /** Disable Acknowledgement */ + I2C_ConfigAck(I2Cx, DISABLE); + /** Send STOP Condition */ + I2C_GenerateStop(I2Cx, ENABLE); + } + /** Test on EV7 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_DATA_RECVD_FLAG)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + /** Read data from DAT */ + *pBuffer = I2C_RecvData(I2Cx); + /** Point to the next location where the byte read will be saved */ + pBuffer++; + /** Decrement the read bytes counter */ + NumByteToRead--; + } + /* Enable Acknowledgement to be ready for another reception */ + I2C_ConfigAck(I2Cx, ENABLE); +} + +/** + * @brief wait operation is completed. + */ +void I2C_EE_WaitOperationIsCompleted(void) +{ + sEETimeout = sEE_LONG_TIMEOUT*1000; + while (i2c_comm_state != COMM_DONE) + { + if ((sEETimeout--) == 0) + { + printf("wait error\r\n"); + sEE_TIMEOUT_UserCallback(); + } + } +} + +/** + * @brief I2c1 event interrupt Service Routines. + */ +void I2C1_IRQHandler(void) +{ + uint32_t lastevent = I2C_GetLastEvent(I2Cx); + + //printf("0x%08x, %d, %d\r\n", lastevent, Int_NumByteToWrite, Int_NumByteToRead); + switch (lastevent) + { + /** Master Invoke */ + case I2C_EVT_MASTER_MODE_FLAG: /// 0x00030001 EV5 + if (!check_begin) + { + i2c_comm_state = COMM_IN_PROCESS; + } + if (MasterDirection == Receiver) + { + if (DeviceDone == FALSE) + { + DeviceDone = TRUE; + I2C_SendAddr7bit(I2Cx, SlaveADDR, I2C_DIRECTION_SEND); + } + else + { + /** Send slave Address for read */ + I2C_SendAddr7bit(I2Cx, SlaveADDR, I2C_DIRECTION_RECV); + } + } + else + { + /** Send slave Address for write */ + I2C_SendAddr7bit(I2Cx, SlaveADDR, I2C_DIRECTION_SEND); + } + break; + + /** Master Transmitter events */ + case I2C_EVT_MASTER_TXMODE_FLAG: // 0x00070082. EV6 Send first addr + if(check_begin) + { + check_begin = FALSE; + I2C_ConfigInt(I2C1, I2C_INT_EVENT | I2C_INT_BUF | I2C_INT_ERR, DISABLE); + I2C_GenerateStop(I2C1, ENABLE); + i2c_comm_state = COMM_DONE; + break; + } + if (MasterDirection == Receiver) + { + I2C_SendData(I2Cx, DeviceOffset); + addressDone = TRUE; + } + else + { + I2C_SendData(I2Cx, DeviceOffset); + addressDone = TRUE; + } + break; + + case I2C_EVT_MASTER_DATA_SENDING: // 0x00070080. EV8 Sending data + if(addressDone == TRUE) + { + I2C_SendData(I2Cx, DeviceOffset); + addressDone = FALSE; + } + break; + + case I2C_EVT_MASTER_DATA_SENDED: // 0x00070084.EV8_2 Send finish + if (MasterDirection == Receiver) + { + I2C_GenerateStart(I2Cx, ENABLE); + } + else + { + if (Int_NumByteToWrite == 0) + { + I2C_GenerateStop(I2Cx, ENABLE); + sEETimeout = sEE_LONG_TIMEOUT; + while (I2C_GetFlag(I2Cx, I2C_FLAG_BUSY)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + check_begin = TRUE; + I2C_GenerateStart(I2C1, ENABLE); + } + else + { + I2C_SendData(I2Cx, SendBuf[BufCount++]); + Int_NumByteToWrite--; + } + } + break; + + case 0x00030400: + if (check_begin) /// EEPROM write busy + { + I2C_GenerateStart(I2C1, ENABLE); + } + I2C_ClrFlag(I2Cx, I2C_FLAG_ACKFAIL); + break; + + /** Master Receiver events */ + case I2C_EVT_MASTER_RXMODE_FLAG: /// EV6 0x00030002 + if(Int_NumByteToRead == 1) + { + I2C_ConfigAck(I2C1, DISABLE); + I2C_GenerateStop(I2Cx, ENABLE); + } + else if(Int_NumByteToRead == 2) + { + I2C1->CTRL1 |= I2C_NACK_POS_NEXT; /// set ACKPOS + I2C_ConfigAck(I2Cx, DISABLE); + } + break; + + case I2C_EVT_MASTER_DATA_RECVD_FLAG: // 0x00030040. EV7.one byte recved + break; + + case I2C_EVT_MASTER_DATA_RECVD_BSF_FLAG: // 0x00030044. EV7.When the I2C communication rate is too high, BSF = 1 + *recvBuf = I2C_RecvData(I2Cx); + recvBuf++; + Int_NumByteToRead--; + if (Int_NumByteToRead == 1) + { + /** Disable Acknowledgement */ + I2C_ConfigAck(I2Cx, DISABLE); + } + if (Int_NumByteToRead == 0) + { + I2C_GenerateStop(I2Cx, ENABLE); + I2C_ConfigInt(I2Cx, I2C_INT_EVENT | I2C_INT_BUF | I2C_INT_ERR, DISABLE); + i2c_comm_state = COMM_DONE; + } + break; + + case 0x00000044: + I2C_ConfigInt(I2Cx, I2C_INT_EVENT | I2C_INT_BUF | I2C_INT_ERR, DISABLE); + i2c_comm_state = COMM_DONE; + break; + + default: + break; + } +} + +/** + * @brief I2c1 dma send interrupt Service Routines. + */ +void DMA_Channel1_2_3_4_IRQHandler() +{ + if (DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + if (I2Cx->STS2 & 0x01) /// master send DMA finish, check process later + { + /** DMA1-6 (I2Cx Tx DMA)transfer complete INTSTS */ + I2C_EnableDMA(I2Cx, DISABLE); + DMA_EnableChannel(DMA_CH2, DISABLE); + /** wait until BTF */ + while (!I2C_GetFlag(I2Cx, I2C_FLAG_BYTEF)) + ; + I2C_GenerateStop(I2Cx, ENABLE); + /** wait until BUSY clear */ + while (I2C_GetFlag(I2Cx, I2C_FLAG_BUSY)) + ; + i2c_comm_state = COMM_IN_PROCESS; + } + DMA_ClearFlag(DMA_FLAG_TC2, DMA); + } + else if (DMA_GetFlagStatus(DMA_FLAG_TC3, DMA)) + { + if (I2Cx->STS2 & 0x01) /// master send DMA finish, check process later + { + /** DMA1-6 (I2Cx Tx DMA)transfer complete INTSTS */ + I2C_EnableDMA(I2Cx, DISABLE); + DMA_EnableChannel(DMA_CH2, DISABLE); + /** wait until BTF */ + while (!I2C_GetFlag(I2Cx, I2C_FLAG_BYTEF)) + ; + I2C_GenerateStop(I2Cx, ENABLE); + /** wait until BUSY clear */ + while (I2C_GetFlag(I2Cx, I2C_FLAG_BUSY)) + ; + i2c_comm_state = COMM_IN_PROCESS; + } + DMA_ClearFlag(DMA_FLAG_TC3, DMA); + } +} + +/** + * @brief Wait eeprom standby state. + */ +void I2C_EE_WaitEepromStandbyState(void) +{ + __IO uint16_t tmpSR1 = 0; + __IO uint32_t sEETrials = 0; + + /** While the bus is busy */ + sEETimeout = sEE_LONG_TIMEOUT; + while (I2C_GetFlag(I2Cx, I2C_FLAG_BUSY)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** Keep looping till the slave acknowledge his address or maximum number + of trials is reached (this number is defined by sEE_MAX_TRIALS_NUMBER) */ + while (1) + { + /** Send START condition */ + I2C_GenerateStart(I2Cx, ENABLE); + + /** Test on EV5 and clear it */ + sEETimeout = sEE_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx, I2C_EVT_MASTER_MODE_FLAG)) + { + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + + /** Send EEPROM address for write */ + I2C_SendAddr7bit(I2Cx, EEPROM_ADDRESS, I2C_DIRECTION_SEND); + /** Wait for ADDR flag to be set (Slave acknowledged his address) */ + sEETimeout = sEE_LONG_TIMEOUT; + do + { + /** Get the current value of the STS1 register */ + tmpSR1 = I2Cx->STS1; + + /** Update the timeout value and exit if it reach 0 */ + if ((sEETimeout--) == 0) + sEE_TIMEOUT_UserCallback(); + } + /** Keep looping till the Address is acknowledged or the AF flag is + set (address not acknowledged at time) */ + while ((tmpSR1 & (I2C_STS1_ADDRF | I2C_STS1_ACKFAIL)) == 0); + + /** Check if the ADDR flag has been set */ + if (tmpSR1 & I2C_STS1_ADDRF) + { + /** Clear ADDR Flag by reading STS1 then STS2 registers (STS1 have already + been read) */ + (void)I2Cx->STS2; + + /** STOP condition */ + I2C_GenerateStop(I2Cx, ENABLE); + + /** Exit the function */ + return; + } + else + { + /** Clear AF flag */ + I2C_ClrFlag(I2Cx, I2C_FLAG_ACKFAIL); + } + + /** Check if the maximum allowed numbe of trials has bee reached */ + if (sEETrials++ == sEE_MAX_TRIALS_NUMBER) + { + /** If the maximum number of trials has been reached, exit the function */ + sEE_TIMEOUT_UserCallback(); + } + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/i2c_eeprom.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/i2c_eeprom.h new file mode 100644 index 0000000..f7f7ba7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/i2c_eeprom.h @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file i2c_eeprom.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __I2C_EEPROM_H__ +#define __I2C_EEPROM_H__ + +#include "n32wb03x.h" +#include + +typedef enum i2c_state +{ + COMM_DONE = 0, /// done successfully + COMM_PRE = 1, + COMM_IN_PROCESS = 2, + COMM_EXIT = 3 /// exit since failure +} I2C_STATE; + +typedef enum i2c_direction +{ + Transmitter = 0x00, + Receiver = 0x01 +} I2C_DIRECTION; + +/** + * PROCESS MODE + * 0=polling + * 1=interrupt + * 2=DMA + */ + +#define PROCESS_MODE (0) + +#define I2C1_TEST +//#define I2C1_REMAP + +#ifdef I2C1_TEST +#define I2Cx I2C1 +#define I2Cx_SCL_PIN GPIO_PIN_7 +#define I2Cx_SDA_PIN GPIO_PIN_6 +#define GPIOx GPIOB +#define I2Cx_GPIO_AF GPIO_AF3_I2C +#define I2Cx_IRQ I2C1_IRQn + +#define I2Cx_peripheral_clk_en() RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_I2C1, ENABLE) +#define I2Cx_scl_clk_en() RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE) +#define I2Cx_sda_clk_en() RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE) +#endif + +#define TEST_EEPROM_SIZE 256 +#define TEST_EEPROM_ADDR 0x00 +#define I2C_Speed 100000 +#define EEPROM_ADDRESS 0xA0 +#define I2C_PageSize 16//32 /// eeprom IC type M24C32 +#define sEE_FLAG_TIMEOUT ((uint32_t)0x1000) +#define sEE_LONG_TIMEOUT ((uint32_t)(100 * sEE_FLAG_TIMEOUT)) + +/** Maximum number of trials for sEE_WaitEepromStandbyState() function */ +#define sEE_MAX_TRIALS_NUMBER 150 +#define FALSE 0 +#define TRUE 1 + +void I2C_EE_Init(void); +void I2C_EE_WriteBuffer(u8* pBuffer, u16 WriteAddr, u16 NumByteToWrite); +void I2C_EE_WriteOnePage(u8* pBuffer, u16 WriteAddr, u16 NumByteToWrite); +void I2C_EE_PageWrite(u8* pBuffer, u16 WriteAddr, u16 NumByteToWrite); +void I2C_EE_WriteOnePageCompleted(void); + +void I2C_EE_ReadBuffer(u8* pBuffer, u16 ReadAddr, u16 NumByteToRead); +void I2C_EE_WaitOperationIsCompleted(void); +void I2C_EE_WaitEepromStandbyState(void); + +void i2c1_evt_handle(void); +void i2c1_err_handle(void); +void i2c1_send_dma_handle(void); +void i2c1_receive_dma_handle(void); + +#endif /* __I2C_EEPROM_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/main.c new file mode 100644 index 0000000..740d8a9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/main.c @@ -0,0 +1,198 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "i2c_eeprom.h" +#include "stdio.h" +#include "main.h" +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup I2C_EEPROM + * @{ + */ + +uint8_t tx_buf[TEST_EEPROM_SIZE] = {0}; +uint8_t rx_buf[TEST_EEPROM_SIZE] = {0}; +volatile Status test_status = FAILED; + +Status Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Main program + */ +int main(void) +{ + uint16_t i = 0; + log_init(); + log_info("\n this is a I2C EEPROM demo, mode:%d\r\n", PROCESS_MODE); + + /* Initialize the I2C EEPROM driver ----------------------------------------*/ + I2C_EE_Init(); + + /* Fill the buffer to send */ + for (i = 0; i < TEST_EEPROM_SIZE; i++) + { + tx_buf[i] = i; + } + + /* First write in the memory followed by a read of the written data --------*/ + /* Write to I2C EEPROM from TEST_EEPROM_ADDR */ + I2C_EE_WriteBuffer(tx_buf, TEST_EEPROM_ADDR, TEST_EEPROM_SIZE); + + /* Read from I2C EEPROM from sEE_READ_ADDRESS1 */ + I2C_EE_ReadBuffer(rx_buf, TEST_EEPROM_ADDR, TEST_EEPROM_SIZE); + + /* Check if the data written to the memory is read correctly */ + test_status = Buffercmp(tx_buf, rx_buf, TEST_EEPROM_SIZE); + + if (test_status == PASSED) + { + log_info("the write and read data are the same,I2C EEPROM test pass\r\n"); + } + else + { + log_info("the write and read data are different,I2C EEPROM test fail\r\n"); + } + + while (1) + { + } +} + +/** + * @brief Compares two buffers. + * @param pBuffer, pBuffer1: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer identical to pBuffer1 + * FAILED: pBuffer differs from pBuffer1 + */ +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer != *pBuffer1) + { + return FAILED; + } + + pBuffer++; + pBuffer1++; + } + + return PASSED; +} + + +void log_init(void) +{ + GPIO_InitType GPIO_InitStructure; + USART_InitType USART_InitStructure; + + + GPIO_InitStruct(&GPIO_InitStructure); + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | LOG_PERIPH_GPIO, ENABLE); + + RCC_EnableAPB1PeriphClk(LOG_PERIPH, ENABLE); + + GPIO_InitStructure.Pin = LOG_TX_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = LOG_RX_PIN; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + // init uart + USART_Init(LOG_USARTx, &USART_InitStructure); + + // enable uart + USART_Enable(LOG_USARTx, ENABLE); +} + +int fputc(int ch, FILE* f) +{ + USART_SendData(LOG_USARTx, (uint8_t)ch); + /* Loop until the end of transmission */ + while (USART_GetFlagStatus(LOG_USARTx, USART_FLAG_TXC) == RESET) + { + } + return ch; +} + +#ifdef USE_FULL_ASSERT + +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + log_error("assertion failed: `%s` at %s:%d", expr, file, line); + while (1) + { + } +} +#endif // USE_FULL_ASSERT + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/n32wb03x_it.c new file mode 100644 index 0000000..f0ad905 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/EEPROM/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/MDK-ARM/I2C_Master.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/MDK-ARM/I2C_Master.uvoptx new file mode 100644 index 0000000..bf08554 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/MDK-ARM/I2C_Master.uvoptx @@ -0,0 +1,335 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/MDK-ARM/I2C_Master.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/MDK-ARM/I2C_Master.uvprojx new file mode 100644 index 0000000..8837c11 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/MDK-ARM/I2C_Master.uvprojx @@ -0,0 +1,465 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + I2C_Master_Project + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\I2C_Master_Project.bin .\Objects\I2C_Master_Project.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER,USE_FULL_ASSERT=1 + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/inc/main.h new file mode 100644 index 0000000..b65f7fc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/inc/main.h @@ -0,0 +1,144 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define NON_REENTRANT + +#define I2Cx_MASTER I2C1 +#define I2Cx_MASTER_CLK RCC_APB1_PERIPH_I2C1 +#define I2Cx_MASTER_GPIO GPIOB +#define I2Cx_MASTER_GPIO_AF GPIO_AF3_I2C +#define I2Cx_MASTER_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define I2Cx_MASTER_SDA_PIN GPIO_PIN_6 +#define I2Cx_MASTER_SCL_PIN GPIO_PIN_7 + +#define DMA_CHANNEL_USED DMA1_CH1 +#define DMA_IRQ_HANDLER DMA1_Channel1_IRQHandler +#define DMA_IT_FLAG_TC DMA1_INT_TXC1 +#define DMA_IT_FLAG_GL DMA1_INT_GLB1 +#define DMA_IRQN DMA1_Channel1_IRQn + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +typedef enum +{ + C_READY = 0, + C_START_BIT, + C_STOP_BIT +}CommCtrl_t; + +typedef enum +{ + MASTER_OK = 0, + MASTER_BUSY, + MASTER_MODE, + MASTER_TXMODE, + MASTER_RXMODE, + MASTER_SENDING, + MASTER_SENDED, + MASTER_RECVD, + MASTER_BYTEF, + MASTER_BUSERR, + MASTER_UNKNOW, + SLAVE_OK = 20, + SLAVE_BUSY, + SLAVE_MODE, + SLAVE_BUSERR, + SLAVE_UNKNOW, + +}ErrCode_t; + + +#define LOG_USARTx USART2 +#define LOG_PERIPH RCC_APB1_PERIPH_USART2 +#define LOG_GPIO GPIOB +#define LOG_PERIPH_GPIO RCC_APB2_PERIPH_GPIOB +#define LOG_TX_PIN GPIO_PIN_4 +#define LOG_RX_PIN GPIO_PIN_5 +#define LOG_GPIO_AF GPIO_AF3_USART2 //GPIO_AF4_USART1 + +#define log_info(...) printf(__VA_ARGS__) +#define log_error(...) printf(__VA_ARGS__) +void log_init(void); +void log_buff(uint8_t *data, int len); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/readme.txt new file mode 100644 index 0000000..b020354 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/readme.txt @@ -0,0 +1,32 @@ + + +1. Function description + + This example demonstrates the use of I2C as a master to send and receive data. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + 1. SystemClock: HSI 64MHz + 2. I2C1 configuration: + SCL --> PB7 + SDA --> PB6 + CLOCK: 100KHz + + 3. USART2 configuration: + TX --> PB4 + RX --> PB5 + Baud rate: 115200 + + + 4. Test steps and phenomena + a, jumper wire to connect slave I2C1 + b, compile and download the code, reset and run + c, view the print information from the serial port and verify the result + +4. Matters needing attention + SCL and SDA must be pulled up \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/src/main.c new file mode 100644 index 0000000..c830b6b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master/src/main.c @@ -0,0 +1,365 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "n32wb03x_i2c.h" +#include "main.h" +#include "stdio.h" +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup I2C_Master + * @{ + */ + +#define TEST_BUFFER_SIZE 32 +#define I2CT_FLAG_TIMEOUT ((uint32_t)0x1000) +#define I2CT_LONG_TIMEOUT ((uint32_t)(20 * I2CT_FLAG_TIMEOUT)) ///((uint32_t)(20 * I2C_FLAG_TIMOUT)) +#define I2C_MASTER_ADDR 0x30 +#define I2C_SLAVE_ADDR 0xA0 + +uint8_t tx_buf[TEST_BUFFER_SIZE] = {0}; +uint8_t rx_buf[TEST_BUFFER_SIZE] = {0}; +volatile Status test_status = FAILED; +uint32_t stsbuf[4]; +Status Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +static __IO uint32_t I2CTimeout = I2CT_LONG_TIMEOUT; +void delay(uint32_t count) +{ + uint32_t i; + for(i = 0; i< count; i++) + { + } +} +int i2c_master_init(void) +{ + I2C_InitType i2c1_master; + GPIO_InitType i2c1_gpio; + + RCC_EnableAPB1PeriphClk(I2Cx_MASTER_CLK, ENABLE); + RCC_EnableAPB2PeriphClk(I2Cx_MASTER_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /*PB7 -- SCL; PB6 -- SDA*/ + GPIO_InitStruct(&i2c1_gpio); + i2c1_gpio.Pin = I2Cx_MASTER_SCL_PIN | I2Cx_MASTER_SDA_PIN; + i2c1_gpio.GPIO_Speed = GPIO_SPEED_HIGH; + i2c1_gpio.GPIO_Mode = GPIO_MODE_AF_OD; + i2c1_gpio.GPIO_Alternate = I2Cx_MASTER_GPIO_AF; + i2c1_gpio.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(I2Cx_MASTER_GPIO, &i2c1_gpio); + + I2C_DeInit(I2Cx_MASTER); + i2c1_master.BusMode = I2C_BUSMODE_I2C; + i2c1_master.FmDutyCycle = I2C_FMDUTYCYCLE_1; + i2c1_master.OwnAddr1 = I2C_MASTER_ADDR; + i2c1_master.AckEnable = I2C_ACKEN; + i2c1_master.AddrMode = I2C_ADDR_MODE_7BIT; + i2c1_master.ClkSpeed = 100000; //100k + + I2C_Init(I2Cx_MASTER, &i2c1_master); + I2C_Enable(I2Cx_MASTER, ENABLE); + return 0; +} + +int i2c_master_send(uint8_t* data, int len) +{ + uint8_t* sendBufferPtr = data; + I2CTimeout = I2CT_LONG_TIMEOUT; + while (I2C_GetFlag(I2Cx_MASTER, I2C_FLAG_BUSY)) + { + if ((I2CTimeout--) == 0) + return 4; + }; + + + I2C_ConfigAck(I2Cx_MASTER, ENABLE); + + I2C_GenerateStart(I2Cx_MASTER, ENABLE); + I2CTimeout = I2CT_FLAG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx_MASTER, I2C_EVT_MASTER_MODE_FLAG)) // EV5 + { + if ((I2CTimeout--) == 0) + return 5; + }; + + I2C_SendAddr7bit(I2Cx_MASTER, I2C_SLAVE_ADDR, I2C_DIRECTION_SEND); + I2CTimeout = I2CT_FLAG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx_MASTER, I2C_EVT_MASTER_TXMODE_FLAG)) // EV6 + { + if ((I2CTimeout--) == 0) + return 6; + }; + + // send data + while (len-- > 0) + { + I2C_SendData(I2Cx_MASTER, *sendBufferPtr++); + I2CTimeout = I2CT_FLAG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx_MASTER, I2C_EVT_MASTER_DATA_SENDING)) // EV8 + { + if ((I2CTimeout--) == 0) + return 7; + }; + }; + + I2CTimeout = I2CT_FLAG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx_MASTER, I2C_EVT_MASTER_DATA_SENDED)) // EV8-2 + { + if ((I2CTimeout--) == 0) + return 8; + }; + + I2C_GenerateStop(I2Cx_MASTER, ENABLE); + return 0; +} + +int i2c_master_recv(uint8_t* data, int len) +{ + uint8_t* recvBufferPtr = data; + I2CTimeout = I2CT_LONG_TIMEOUT; + while (I2C_GetFlag(I2Cx_MASTER, I2C_FLAG_BUSY)) + { + if ((I2CTimeout--) == 0) + return 9; + }; + + I2C_ConfigAck(I2Cx_MASTER, ENABLE); + + // send start + I2C_GenerateStart(I2Cx_MASTER, ENABLE); + + I2CTimeout = I2CT_FLAG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx_MASTER, I2C_EVT_MASTER_MODE_FLAG)) // EV5 + { + if ((I2CTimeout--) == 0) + return 10; + }; + + // send addr + I2C_SendAddr7bit(I2Cx_MASTER, I2C_SLAVE_ADDR, I2C_DIRECTION_RECV); + I2CTimeout = I2CT_FLAG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx_MASTER, I2C_EVT_MASTER_RXMODE_FLAG)) // EV6 + { + if ((I2CTimeout--) == 0) + return 6; + }; + + // recv data + while (len-- > 0) + { + I2CTimeout = I2CT_LONG_TIMEOUT; + while (!I2C_CheckEvent(I2Cx_MASTER, I2C_EVT_MASTER_DATA_RECVD_FLAG)) // EV7 + { + if ((I2CTimeout--) == 0) + return 14; + }; + + if (len == 1) + { + I2C_ConfigAck(I2C1, DISABLE); + I2C_GenerateStop(I2C1, ENABLE); + } + + if (len == 0) + { + //I2C_GenerateStop(I2C1, ENABLE); + } + *recvBufferPtr++ = I2C_RecvData(I2C1); + + }; + return 0; +} + +/** + * @brief Main program + */ +int main(void) +{ + uint16_t i = 0; + + log_init(); + log_info("\n this is a i2c master demo\r\n"); + /* Initialize the I2C EEPROM driver ----------------------------------------*/ + i2c_master_init(); + + /* Fill the buffer to send */ + for (i = 0; i < TEST_BUFFER_SIZE; i++) + { + tx_buf[i] = i; + } + + /* First write in the memory followed by a read of the written data --------*/ + /* Write data*/ + i2c_master_send(tx_buf, TEST_BUFFER_SIZE); + + /* Read data */ + i2c_master_recv(rx_buf, TEST_BUFFER_SIZE); + + /* Check if the data written to the memory is read correctly */ + test_status = Buffercmp(tx_buf, rx_buf, TEST_BUFFER_SIZE); + + if (test_status == PASSED) + { + log_info("write and read data the same, i2c master test pass\r\n"); + } + else + { + log_info("write and read data are different, i2c master test fail\r\n"); + } + log_buff(rx_buf, TEST_BUFFER_SIZE); + + /* test_status = PASSED, if the write and read data are the same */ + /* test_status = FAILED, if the write and read data are different */ + while (1) + { + } +} + +/** + * @brief Compares two buffers. + * @param pBuffer, pBuffer1: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer identical to pBuffer1 + * FAILED: pBuffer differs from pBuffer1 + */ +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer != *pBuffer1) + { + return FAILED; + } + + pBuffer++; + pBuffer1++; + } + + return PASSED; +} + +void log_init(void) +{ + GPIO_InitType GPIO_InitStructure; + USART_InitType USART_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | LOG_PERIPH_GPIO, ENABLE); + + RCC_EnableAPB1PeriphClk(LOG_PERIPH, ENABLE); + + GPIO_InitStructure.Pin = LOG_TX_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = LOG_RX_PIN; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + // init uart + USART_Init(LOG_USARTx, &USART_InitStructure); + + // enable uart + USART_Enable(LOG_USARTx, ENABLE); +} + +void log_buff(uint8_t *data, int len) +{ + int i = 0; + for(i=0; i + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/MDK-ARM/I2C_Master_Int.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/MDK-ARM/I2C_Master_Int.uvprojx new file mode 100644 index 0000000..e460a3c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/MDK-ARM/I2C_Master_Int.uvprojx @@ -0,0 +1,465 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + I2C_Master_Int_Project + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\I2C_Master_Int_Project.bin .\Objects\I2C_Master_Int_Project.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER,USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/inc/main.h new file mode 100644 index 0000000..71086ce --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/inc/main.h @@ -0,0 +1,142 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define I2Cx_MASTER I2C1 +#define I2Cx_MASTER_CLK RCC_APB1_PERIPH_I2C1 +#define I2Cx_MASTER_GPIO GPIOB +#define I2Cx_MASTER_GPIO_AF GPIO_AF3_I2C +#define I2Cx_MASTER_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define I2Cx_MASTER_SDA_PIN GPIO_PIN_6 +#define I2Cx_MASTER_SCL_PIN GPIO_PIN_7 +#define I2Cx_MASTER_IRQ I2C1_IRQn + +#define DMA_CHANNEL_USED DMA1_CH1 +#define DMA_IRQ_HANDLER DMA1_Channel1_IRQHandler +#define DMA_IT_FLAG_TC DMA1_INT_TXC1 +#define DMA_IT_FLAG_GL DMA1_INT_GLB1 +#define DMA_IRQN DMA1_Channel1_IRQn + +typedef enum +{ + C_READY = 0, + C_START_BIT, + C_STOP_BIT +}CommCtrl_t; + +typedef enum +{ + MASTER_OK = 0, + MASTER_BUSY, + MASTER_MODE, + MASTER_TXMODE, + MASTER_RXMODE, + MASTER_SENDING, + MASTER_SENDED, + MASTER_RECVD, + MASTER_BYTEF, + MASTER_BUSERR, + MASTER_UNKNOW, + SLAVE_OK = 20, + SLAVE_BUSY, + SLAVE_MODE, + SLAVE_BUSERR, + SLAVE_UNKNOW, + +}ErrCode_t; + +#define LOG_USARTx USART2 +#define LOG_PERIPH RCC_APB1_PERIPH_USART2 +#define LOG_GPIO GPIOB +#define LOG_PERIPH_GPIO RCC_APB2_PERIPH_GPIOB +#define LOG_TX_PIN GPIO_PIN_4 +#define LOG_RX_PIN GPIO_PIN_5 +#define LOG_GPIO_AF GPIO_AF3_USART2 //GPIO_AF4_USART1 + +#define log_info(...) printf(__VA_ARGS__) +#define log_error(...) printf(__VA_ARGS__) +void log_init(void); +void log_buff(uint8_t *data, int len); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/readme.txt new file mode 100644 index 0000000..e16cb43 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/readme.txt @@ -0,0 +1,30 @@ + +1. Function description + + This example demonstrates the use of I2C interrupts as a master to send and receive data. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + 1. Main clock: 48MHz + 2. I2C1 configuration: + SCL --> PB6 + SDA --> PB7 + CLOCK: 100KHz + + 3. USART2 configuration: + TX --> PB4 + RX --> PB5 + Baud rate: 115200 + + + 4. Test steps and phenomena + a, jumper wire to connect slave I2C1 + b, compile and download the code, reset and run + c, view the print information from the serial port and verify the result + +4. Matters needing attention + SCL and SDA must be pulled up \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/src/main.c new file mode 100644 index 0000000..840cd62 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Master_Int/src/main.c @@ -0,0 +1,475 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#include "n32wb03x.h" +#include "n32wb03x_i2c.h" +#include "stdio.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup I2C_Master_Int + * @{ + */ + + +#define TEST_BUFFER_SIZE 32 +#define I2CT_FLAG_TIMEOUT ((uint32_t)0x1000) +#define I2CT_LONG_TIMEOUT ((uint32_t)(10 * I2CT_FLAG_TIMEOUT)) +#define I2C_MASTER_ADDR 0x30 +#define I2C_SLAVE_ADDR 0xA0 +volatile Status test_status = FAILED; + +static CommCtrl_t Comm_Flag = C_READY; +uint8_t tx_buf[TEST_BUFFER_SIZE] = {0}; +uint8_t rx_buf[TEST_BUFFER_SIZE] = {0}; + +uint8_t flag_master_recv_finish = 0; +uint8_t flag_master_send_finish = 0; +uint8_t flag_trans_direct = 0; // write +uint8_t flag_overrun = 0; + +Status Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); +void Memset(void* s, uint8_t c, uint32_t count); +void CommTimeOut_CallBack(ErrCode_t errcode); + +static __IO uint32_t I2CTimeout = I2CT_LONG_TIMEOUT; + +/** + * @brief i2c Interrupt configuration + * @param ch I2C channel + */ +void NVIC_ConfigurationMaster(void) +{ + NVIC_InitType NVIC_InitStructure; + NVIC_InitStructure.NVIC_IRQChannel = I2Cx_MASTER_IRQ; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief i2c Interrupt disable + * @param ch I2C channel + */ +void NVIC_ConfigurationMasterDis(void) +{ + NVIC_InitType NVIC_InitStructure; + NVIC_InitStructure.NVIC_IRQChannel = I2Cx_MASTER_IRQ; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief i2c master init + * @return 0:init finish + * + */ +int i2c_master_init(void) +{ + I2C_InitType i2c1_master; + GPIO_InitType i2c1_gpio; + + RCC_EnableAPB1PeriphClk(I2Cx_MASTER_CLK, ENABLE); + RCC_EnableAPB2PeriphClk(I2Cx_MASTER_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + GPIO_InitStruct(&i2c1_gpio); + /*PB6 -- SCL; PB7 -- SDA*/ + i2c1_gpio.Pin = I2Cx_MASTER_SDA_PIN | I2Cx_MASTER_SCL_PIN; + i2c1_gpio.GPIO_Speed = GPIO_SPEED_HIGH; + i2c1_gpio.GPIO_Mode = GPIO_MODE_AF_OD; + i2c1_gpio.GPIO_Alternate = I2Cx_MASTER_GPIO_AF; + i2c1_gpio.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(I2Cx_MASTER_GPIO, &i2c1_gpio); + + I2C_DeInit(I2Cx_MASTER); + i2c1_master.BusMode = I2C_BUSMODE_I2C; + i2c1_master.FmDutyCycle = I2C_FMDUTYCYCLE_1; + i2c1_master.OwnAddr1 = I2C_MASTER_ADDR; + i2c1_master.AckEnable = I2C_ACKEN; + i2c1_master.AddrMode = I2C_ADDR_MODE_7BIT; + i2c1_master.ClkSpeed = 100000; // 100K + + I2C_Init(I2Cx_MASTER, &i2c1_master); + // int enable + I2C_ConfigInt(I2Cx_MASTER, I2C_INT_EVENT | I2C_INT_BUF | I2C_INT_ERR, ENABLE); + NVIC_ConfigurationMaster(); + + I2C_Enable(I2Cx_MASTER, ENABLE); + return 0; +} + +/** + * @brief Main program + */ +int main(void) +{ + uint16_t i = 0; + + log_init(); + log_info("\n\rthis is a i2c master int demo\r\n"); + + i2c_master_init(); + + /* Fill the buffer to send */ + for (i = 0; i < TEST_BUFFER_SIZE; i++) + { + tx_buf[i] = i; + } + + /* First write in the memory followed by a read of the written data --------*/ + /* Write data*/ + flag_trans_direct = 0; + if (Comm_Flag == C_READY) + { + Comm_Flag = C_START_BIT; + I2C_GenerateStart(I2C1, ENABLE); + } + + I2CTimeout = I2CT_LONG_TIMEOUT * 1000; + while (flag_master_send_finish == 0) + { + if ((I2CTimeout--) == 0) + { + CommTimeOut_CallBack(MASTER_UNKNOW); + } + } + + // master send finish + log_info("I2C master send finish\r\n"); + flag_master_send_finish = 0; + I2CTimeout = I2CT_LONG_TIMEOUT; + while (I2C_GetFlag(I2C1, I2C_FLAG_BUSY)) + { + if ((I2CTimeout--) == 0) + { + CommTimeOut_CallBack(MASTER_BUSY); + } + } + Comm_Flag = C_READY; + + printf("send finish\r\n"); + + /*read data*/ + flag_trans_direct = 1; + I2C_ConfigAck(I2C1, ENABLE); + if (Comm_Flag == C_READY) + { + Comm_Flag = C_START_BIT; + I2C_GenerateStart(I2C1, ENABLE); + } + + I2CTimeout = I2CT_LONG_TIMEOUT * 1000; + while (flag_master_recv_finish == 0) + { + if ((I2CTimeout--) == 0) + { + CommTimeOut_CallBack(MASTER_UNKNOW); + } + } + + log_info("I2C master recv finish\r\n"); + flag_master_recv_finish = 0; + I2CTimeout = I2CT_LONG_TIMEOUT; + while (I2C_GetFlag(I2C1, I2C_FLAG_BUSY)) + { + if ((I2CTimeout--) == 0) + { + CommTimeOut_CallBack(MASTER_BUSY); + } + } + Comm_Flag = C_READY; + + /* Check if the data written to the memory is read correctly */ + test_status = Buffercmp(tx_buf, rx_buf, TEST_BUFFER_SIZE); + if (test_status == PASSED) /* test_status = PASSED, if the write and read dataare the same */ + { + log_info("the write and read data the same, i2c master int test pass\r\n"); + } + else /* test_status = FAILED, if the write and read dataare different */ + { + log_info("the write and read data are different, i2c master int test fail\r\n"); + } + + while (1) + { + } +} + +/** + * @brief i2c Interrupt service function + * + */ + +/* Master mode */ +#define I2C_ROLE_MASTER ((uint32_t)0x00010000) /* MSMODE */ + +void I2C1_IRQHandler(void) +{ + uint32_t last_event; + static uint8_t rx_num = 0; + static uint8_t tx_num = 0; + + last_event = I2C_GetLastEvent(I2Cx_MASTER); + + if ((last_event & I2C_ROLE_MASTER) == I2C_ROLE_MASTER) // master mode + { + switch (last_event) + { + case I2C_EVT_MASTER_MODE_FLAG: // 0x00030001.EV5 Send addr + if(flag_trans_direct) // read + { + Memset(rx_buf, 0, TEST_BUFFER_SIZE); // clear recv buf, ready to recv data + I2C_SendAddr7bit(I2Cx_MASTER, I2C_SLAVE_ADDR, I2C_DIRECTION_RECV); + rx_num = 0; + } + else // write + { + I2C_SendAddr7bit(I2Cx_MASTER, I2C_SLAVE_ADDR, I2C_DIRECTION_SEND); + tx_num = 0; + } + break; + + // MasterTransmitter + case I2C_EVT_MASTER_TXMODE_FLAG: // 0x00070082. EV6 Send first data + Comm_Flag = C_READY; + I2C_SendData(I2Cx_MASTER, tx_buf[tx_num++]); + break; + + case I2C_EVT_MASTER_DATA_SENDING: // 0x00070080. EV8 Sending data + + break; + + case I2C_EVT_MASTER_DATA_SENDED: // 0x00070084.EV8_2 Send finish + if (tx_num == TEST_BUFFER_SIZE) + { + if (Comm_Flag == C_READY) + { + Comm_Flag = C_STOP_BIT; + I2C_GenerateStop(I2Cx_MASTER, ENABLE); + flag_master_send_finish = 1; + } + } + else + { + I2C_SendData(I2Cx_MASTER, tx_buf[tx_num++]); + } + break; + + // MasterReceiver + case I2C_EVT_MASTER_RXMODE_FLAG: // 0x00030002.EV6 + break; + + case I2C_EVT_MASTER_DATA_RECVD_FLAG: // 0x00030040. EV7.one byte recved + case I2C_EVT_MASTER_DATA_RECVD_BSF_FLAG: // 0x00030044. EV7.When the I2C communication rate is too high, BSF = 1 + rx_buf[rx_num++] = I2C_RecvData(I2Cx_MASTER); + if (rx_num == (TEST_BUFFER_SIZE - 1)) + { + I2C_ConfigAck(I2C1, DISABLE); // Disable I2C1 acknowledgement. + I2C_GenerateStop(I2C1, ENABLE); // Send I2C1 STOP Condition. + } + else if (rx_num == TEST_BUFFER_SIZE) + { + flag_master_recv_finish = 1; + } + break; + + case 0x00030201: // Arbitration lost + case 0x00030401: // Acknowledge failure + case 0x00030501: // Acknowledge failure and Bus error + I2C_GenerateStop(I2C1, ENABLE); + break; + + default: + log_info("I2C error status:0x%x\r\n", last_event); + while(1); //stop + //break; + } + } +} + +/** + * @brief Compares two buffers. + * @param pBuffer, pBuffer1: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer identical to pBuffer1 + * FAILED: pBuffer differs from pBuffer1 + */ +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer != *pBuffer1) + { + return FAILED; + } + + pBuffer++; + pBuffer1++; + } + + return PASSED; +} + +void Delay_us(uint32_t nCount) +{ + uint32_t tcnt; + while (nCount--) + { + tcnt = 64 / 5; + while (tcnt--){;} + } +} + +void CommTimeOut_CallBack(ErrCode_t errcode) +{ + log_info("...ErrCode:%d\r\n", errcode); +} + +/** + * @brief memery set a value + * @param s source + * @param c value + * @param count number + * @return pointer of the memery + */ +void Memset(void* s, uint8_t c, uint32_t count) +{ + char* xs = (char*)s; + + while (count--) // clear 17byte buffer + { + *xs++ = c; + } + + return; +} + +void log_init(void) +{ + GPIO_InitType GPIO_InitStructure; + USART_InitType USART_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | LOG_PERIPH_GPIO, ENABLE); + + RCC_EnableAPB1PeriphClk(LOG_PERIPH, ENABLE); + + GPIO_InitStructure.Pin = LOG_TX_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = LOG_RX_PIN; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + // init uart + USART_Init(LOG_USARTx, &USART_InitStructure); + + // enable uart + USART_Enable(LOG_USARTx, ENABLE); +} + +void log_buff(uint8_t *data, int len) +{ + int i = 0; + for(i=0; i + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/MDK-ARM/I2C_Slave.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/MDK-ARM/I2C_Slave.uvprojx new file mode 100644 index 0000000..bf35aed --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/MDK-ARM/I2C_Slave.uvprojx @@ -0,0 +1,465 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + I2C_Slave_Project + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\I2C_Slave_Project.bin .\Objects\I2C_Slave_Project.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER,USE_FULL_ASSERT=1 + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/inc/main.h new file mode 100644 index 0000000..d1439f3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/inc/main.h @@ -0,0 +1,134 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define I2Cx_SLAVE I2C1 +#define I2Cx_SLAVE_CLK RCC_APB1_PERIPH_I2C1 +#define I2Cx_SLAVE_GPIO GPIOB +#define I2Cx_SLAVE_GPIO_AF GPIO_AF3_I2C +#define I2Cx_SLAVE_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define I2Cx_SLAVE_SDA_PIN GPIO_PIN_6 +#define I2Cx_SLAVE_SCL_PIN GPIO_PIN_7 + +typedef enum +{ + MASTER_OK = 0, + MASTER_BUSY, + MASTER_MODE, + MASTER_TXMODE, + MASTER_RXMODE, + MASTER_SENDING, + MASTER_SENDED, + MASTER_RECVD, + MASTER_BYTEF, + MASTER_BUSERR, + MASTER_UNKNOW, + SLAVE_OK = 20, + SLAVE_BUSY, + SLAVE_MODE, + SLAVE_BUSERR, + SLAVE_UNKNOW, + +}ErrCode_t; + +#define DMA_CHANNEL_USED DMA1_CH1 +#define DMA_IRQ_HANDLER DMA1_Channel1_IRQHandler +#define DMA_IT_FLAG_TC DMA1_INT_TXC1 +#define DMA_IT_FLAG_GL DMA1_INT_GLB1 +#define DMA_IRQN DMA1_Channel1_IRQn + +#define LOG_USARTx USART2 +#define LOG_PERIPH RCC_APB1_PERIPH_USART2 +#define LOG_GPIO GPIOB +#define LOG_PERIPH_GPIO RCC_APB2_PERIPH_GPIOB +#define LOG_TX_PIN GPIO_PIN_4 +#define LOG_RX_PIN GPIO_PIN_5 +#define LOG_GPIO_AF GPIO_AF3_USART2 //GPIO_AF4_USART1 + +#define log_info(...) printf(__VA_ARGS__) +#define log_error(...) printf(__VA_ARGS__) +void log_init(void); +void log_buff(uint8_t *data, int len); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/readme.txt new file mode 100644 index 0000000..596241e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/readme.txt @@ -0,0 +1,32 @@ + + +1. Function description + + This example demonstrates the use of I2C as a slave to send and receive data. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + 1. SystemClock: HSI 64MHz + 2. I2C1 configuration: + SCL --> PB7 + SDA --> PB6 + CLOCK: 100KHz + + 3. USART2 configuration: + TX --> PB4 + RX --> PB5 + Baud rate: 115200 + + + 4. Test steps and phenomena + a, the jumper wire connects the master I2C1 + b, compile and download the code, reset and run + c, view the print information from the serial port and verify the result + +4. Matters needing attention + SCL and SDA must be pulled up \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/src/main.c new file mode 100644 index 0000000..04f8d4f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave/src/main.c @@ -0,0 +1,333 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "n32wb03x_i2c.h" +#include "stdio.h" +#include "main.h" +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup I2C_Slave + * @{ + */ + +//#define I2C_SLAVE_LOW_LEVEL +#define TEST_BUFFER_SIZE 32 +#define I2CT_FLAG_TIMEOUT ((uint32_t)0x1000) +#define I2CT_LONG_TIMEOUT ((uint32_t)(10 * I2CT_FLAG_TIMEOUT)) +#define I2C_SLAVE_ADDR 0xA0 + +uint8_t data_buf[TEST_BUFFER_SIZE] = {0}; +volatile Status test_status = FAILED; + +Status Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +static __IO uint32_t I2CTimeout = I2CT_LONG_TIMEOUT; + +void CommTimeOut_CallBack(ErrCode_t errcode); + +/** + * @brief I2C slave init + * + * @return 0:init finish + */ +int i2c_slave_init(void) +{ + I2C_InitType i2c1_slave; + GPIO_InitType i2c1_gpio; + + // enable clk + RCC_EnableAPB1PeriphClk(I2Cx_SLAVE_CLK, ENABLE); + RCC_EnableAPB2PeriphClk(I2Cx_SLAVE_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + GPIO_InitStruct(&i2c1_gpio); + + /*PB7 -- SCL; PB6 -- SDA*/ + i2c1_gpio.Pin = I2Cx_SLAVE_SDA_PIN | I2Cx_SLAVE_SCL_PIN; + i2c1_gpio.GPIO_Speed = GPIO_SPEED_HIGH; + i2c1_gpio.GPIO_Mode = GPIO_MODE_AF_OD; + i2c1_gpio.GPIO_Alternate = I2Cx_SLAVE_GPIO_AF; + i2c1_gpio.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(I2Cx_SLAVE_GPIO, &i2c1_gpio); + + I2C_DeInit(I2Cx_SLAVE); + i2c1_slave.BusMode = I2C_BUSMODE_I2C; + i2c1_slave.FmDutyCycle = I2C_FMDUTYCYCLE_1; + i2c1_slave.OwnAddr1 = I2C_SLAVE_ADDR; + i2c1_slave.AckEnable = I2C_ACKEN; + i2c1_slave.AddrMode = I2C_ADDR_MODE_7BIT; + i2c1_slave.ClkSpeed = 100000; //100k + + I2C_Init(I2Cx_SLAVE, &i2c1_slave); + I2C_Enable(I2Cx_SLAVE, ENABLE); + return 0; +} + +/** + * @brief I2C slave send data + * + * @param data data buffer + * @param len send data len + * @return 0:send finish + */ +int i2c_slave_send(uint8_t* data, int len) +{ + uint32_t lastevent; + uint8_t* sendBufferPtr = data; + I2CTimeout = I2CT_LONG_TIMEOUT; + + while (!I2C_CheckEvent(I2Cx_SLAVE, I2C_EVT_SLAVE_SEND_ADDR_MATCHED)) + ; // send addr matched + + // send data + I2C_Enable(I2C1, ENABLE); + I2C_SendData(I2C1, *sendBufferPtr++); + while (1) + { + lastevent = I2C_GetLastEvent(I2C1); + if (lastevent == I2C_EVT_SLAVE_DATA_SENDED) + { + I2C_SendData(I2C1, *sendBufferPtr++); + I2CTimeout = I2CT_LONG_TIMEOUT; + } + else if ((lastevent == I2C_EVT_SLAVE_ACK_MISS) || (lastevent == I2C_EVT_SLAVE_STOP_RECVD)) + { + I2C_ClrFlag(I2C1, I2C_FLAG_ACKFAIL); + I2C_Enable(I2C1, ENABLE); + break; + } + else if ((lastevent & 0x00000100) == 0x00000100) + { + CommTimeOut_CallBack(SLAVE_BUSERR); + } + else + { + if ((I2CTimeout--) == 0) + CommTimeOut_CallBack(SLAVE_UNKNOW); + } + } + return 0; +} + +/** + * @brief I2C slave receive data + * + * @param data data buffer,use to save received data + * @param rcv_len receive data len + * @return 0:recv finish + */ +int i2c_slave_recv(uint8_t* data, uint32_t rcv_len) +{ + uint32_t lastevent; + uint32_t rxDataNum = 0; + I2CTimeout = I2CT_LONG_TIMEOUT; + + while (!I2C_CheckEvent(I2Cx_SLAVE, I2C_EVT_SLAVE_RECV_ADDR_MATCHED)) + ; // receive addr matched + + I2C_Enable(I2C1, ENABLE); + + while (1) + { + lastevent = I2C_GetLastEvent(I2C1); + if (lastevent == I2C_EVT_SLAVE_DATA_RECVD) + { + *data++ = I2C_RecvData(I2C1); + rxDataNum++; + I2CTimeout = I2CT_LONG_TIMEOUT; + } + else if (lastevent == I2C_EVT_SLAVE_STOP_RECVD) + { + I2C_Enable(I2C1, ENABLE); + break; + } + else if ((lastevent & 0x00000100) == 0x00000100) + { + CommTimeOut_CallBack(SLAVE_BUSERR); + } + else + { + if ((I2CTimeout--) == 0) + CommTimeOut_CallBack(SLAVE_UNKNOW); + } + } + + return 0; +} + +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + log_info("\r\n this is a i2c slave test demo\r\n"); + /* Initialize the I2C EEPROM driver ----------------------------------------*/ + i2c_slave_init(); + + /* Read data */ + log_info("i2c slave recv data start\r\n"); + i2c_slave_recv(data_buf, TEST_BUFFER_SIZE); + log_buff(data_buf, TEST_BUFFER_SIZE); + + /* Write data*/ + log_info("i2c slave send data start\r\n"); + i2c_slave_send(data_buf, TEST_BUFFER_SIZE); + log_info("i2c slave test pass\r\n"); + while (1) + { + } +} + +/** + * @brief Compares two buffers. + * @param pBuffer, pBuffer1: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer identical to pBuffer1 + * FAILED: pBuffer differs from pBuffer1 + */ +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer != *pBuffer1) + { + return FAILED; + } + + pBuffer++; + pBuffer1++; + } + + return PASSED; +} + +void CommTimeOut_CallBack(ErrCode_t errcode) +{ + log_info("...ErrCode:%d\r\n", errcode); +} + +void log_init(void) +{ + GPIO_InitType GPIO_InitStructure; + USART_InitType USART_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | LOG_PERIPH_GPIO, ENABLE); + + RCC_EnableAPB1PeriphClk(LOG_PERIPH, ENABLE); + + GPIO_InitStructure.Pin = LOG_TX_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = LOG_RX_PIN; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + // init uart + USART_Init(LOG_USARTx, &USART_InitStructure); + + // enable uart + USART_Enable(LOG_USARTx, ENABLE); +} + +void log_buff(uint8_t *data, int len) +{ + int i = 0; + for(i=0; i + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/MDK-ARM/I2C_Slave_Int.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/MDK-ARM/I2C_Slave_Int.uvprojx new file mode 100644 index 0000000..3134d1a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/MDK-ARM/I2C_Slave_Int.uvprojx @@ -0,0 +1,465 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + I2C_Slave_Int_Project + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\I2C_Slave_Int_Project.bin .\Objects\I2C_Slave_Int_Project.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER,USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/inc/main.h new file mode 100644 index 0000000..deb9db1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/inc/main.h @@ -0,0 +1,135 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define I2Cx_SLAVE I2C1 +#define I2Cx_SLAVE_CLK RCC_APB1_PERIPH_I2C1 +#define I2Cx_SLAVE_GPIO GPIOB +#define I2Cx_SLAVE_GPIO_AF GPIO_AF3_I2C +#define I2Cx_SLAVE_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define I2Cx_SLAVE_SDA_PIN GPIO_PIN_6 +#define I2Cx_SLAVE_SCL_PIN GPIO_PIN_7 +#define I2Cx_SLAVE_IRQ I2C1_IRQn + +#define DMA_CHANNEL_USED DMA1_CH1 +#define DMA_IRQ_HANDLER DMA1_Channel1_IRQHandler +#define DMA_IT_FLAG_TC DMA1_INT_TXC1 +#define DMA_IT_FLAG_GL DMA1_INT_GLB1 +#define DMA_IRQN DMA1_Channel1_IRQn + +typedef enum +{ + MASTER_OK = 0, + MASTER_BUSY, + MASTER_MODE, + MASTER_TXMODE, + MASTER_RXMODE, + MASTER_SENDING, + MASTER_SENDED, + MASTER_RECVD, + MASTER_BYTEF, + MASTER_BUSERR, + MASTER_UNKNOW, + SLAVE_OK = 20, + SLAVE_BUSY, + SLAVE_MODE, + SLAVE_BUSERR, + SLAVE_UNKNOW, + +}ErrCode_t; + +#define LOG_USARTx USART2 +#define LOG_PERIPH RCC_APB1_PERIPH_USART2 +#define LOG_GPIO GPIOB +#define LOG_PERIPH_GPIO RCC_APB2_PERIPH_GPIOB +#define LOG_TX_PIN GPIO_PIN_4 +#define LOG_RX_PIN GPIO_PIN_5 +#define LOG_GPIO_AF GPIO_AF3_USART2 //GPIO_AF4_USART1 + +#define log_info(...) printf(__VA_ARGS__) +#define log_error(...) printf(__VA_ARGS__) +void log_init(void); +void log_buff(uint8_t *data, int len); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/readme.txt new file mode 100644 index 0000000..ed3b0eb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/readme.txt @@ -0,0 +1,32 @@ + + +1. Function description + + This example demonstrates the use of I2C interrupts to send and receive data as a slave. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + 1. SystemClock: HSI 64MHz + 2. I2C1 configuration: + SCL --> PB7 + SDA --> PB6 + CLOCK: 100KHz + + 3. USART2 configuration: + TX --> PB4 + RX --> PB5 + Baud rate: 115200 + + + 4. Test steps and phenomena + a, the jumper wire connects the master I2C1 + b, compile and download the code, reset and run + c, view the print information from the serial port and verify the result + +4. Matters needing attention + SCL and SDA must be pulled up \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/src/main.c new file mode 100644 index 0000000..db068c8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/I2C_Slave_Int/src/main.c @@ -0,0 +1,390 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "n32wb03x_i2c.h" +#include "stdio.h" +#include "main.h" +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup I2C_Slave_Int + * @{ + */ + + + +//#define I2C_SLAVE_LOW_LEVEL +#define TEST_BUFFER_SIZE 100 +#define I2CT_FLAG_TIMEOUT ((uint32_t)0x1000) +#define I2CT_LONG_TIMEOUT ((uint32_t)(10 * I2CT_FLAG_TIMEOUT)) +#define I2C_MASTER_ADDR 0x30 +#define I2C_SLAVE_ADDR 0xA0 + +uint8_t data_buf[TEST_BUFFER_SIZE] = {0}; +static __IO uint32_t I2CTimeout; +uint8_t flag_slave_recv_finish = 0; +uint8_t flag_slave_send_finish = 0; +static uint8_t rxDataNum = 0; +static __IO uint32_t I2CTimeout = I2CT_LONG_TIMEOUT; + +Status Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); +void Memset(void* s, uint8_t c, uint32_t count); +void CommTimeOut_CallBack(ErrCode_t errcode); + + + +/** + * @brief i2c slave Interrupt configuration + * @param ch I2C channel + */ +void NVIC_ConfigurationSlave(void) +{ + NVIC_InitType NVIC_InitStructure; + NVIC_InitStructure.NVIC_IRQChannel = I2Cx_SLAVE_IRQ; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief i2c slave init + * @return 0:init finish + */ +int i2c_slave_init(void) +{ + I2C_InitType i2c1_master; + GPIO_InitType i2c1_gpio; + + RCC_EnableAPB1PeriphClk(I2Cx_SLAVE_CLK, ENABLE); + RCC_EnableAPB2PeriphClk(I2Cx_SLAVE_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + GPIO_InitStruct(&i2c1_gpio); + /*PB7 -- SCL; PB6 -- SDA*/ + i2c1_gpio.Pin = I2Cx_SLAVE_SDA_PIN | I2Cx_SLAVE_SCL_PIN; + i2c1_gpio.GPIO_Speed = GPIO_SPEED_HIGH; + i2c1_gpio.GPIO_Mode = GPIO_MODE_AF_OD; + i2c1_gpio.GPIO_Alternate = I2Cx_SLAVE_GPIO_AF; + i2c1_gpio.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(I2Cx_SLAVE_GPIO, &i2c1_gpio); + + I2C_DeInit(I2Cx_SLAVE); + i2c1_master.BusMode = I2C_BUSMODE_I2C; + i2c1_master.FmDutyCycle = I2C_FMDUTYCYCLE_1; + i2c1_master.OwnAddr1 = I2C_SLAVE_ADDR; + i2c1_master.AckEnable = I2C_ACKEN; + i2c1_master.AddrMode = I2C_ADDR_MODE_7BIT; + i2c1_master.ClkSpeed = 100000; + + I2C_Init(I2Cx_SLAVE, &i2c1_master); + // int enable + I2C_ConfigInt(I2Cx_SLAVE, I2C_INT_EVENT | I2C_INT_BUF | I2C_INT_ERR, ENABLE); + NVIC_ConfigurationSlave(); + + I2C_Enable(I2Cx_SLAVE, ENABLE); + return 0; +} + +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + log_info("this is a i2c slave int demo\r\n"); + + /* Initialize the I2C slave driver ----------------------------------------*/ + i2c_slave_init(); + + // recive data + Memset(data_buf, (uint8_t)0, TEST_BUFFER_SIZE); // clear buf, ready to recv data + I2CTimeout = I2CT_LONG_TIMEOUT * 1000; + while (flag_slave_recv_finish == 0) // wait for recv data finish + { + if ((I2CTimeout--) == 0) + { + CommTimeOut_CallBack(SLAVE_UNKNOW); + } + } + + log_info("recv finish, recv len = %d\r\n", rxDataNum); + flag_slave_recv_finish = 0; + + // send data + I2CTimeout = I2CT_LONG_TIMEOUT * 1000; + while (flag_slave_send_finish == 0) // wait for send data finish + { + if ((I2CTimeout--) == 0) + { + CommTimeOut_CallBack(SLAVE_UNKNOW); + } + + } + flag_slave_send_finish = 0; + log_info("tx finish,tx len = %d\r\n", rxDataNum-1); + log_buff(data_buf, rxDataNum-1); + + while (1) + { + + } +} + +/** + * @brief i2c slave Interrupt service function + */ +void I2C1_IRQHandler(void) +{ + uint8_t timeout_flag = 0; + uint32_t last_event; + + last_event = I2C_GetLastEvent(I2C1); + if ((last_event & 0x00010000) != 0x00010000) // MSMODE = 0:I2C slave mode + { + switch (last_event) + { + case I2C_EVT_SLAVE_RECV_ADDR_MATCHED: //0x00020002.EV1 Rx addr matched + rxDataNum = 0; + break; + + case I2C_EVT_SLAVE_SEND_ADDR_MATCHED: //0x00060082.EV1 Tx addr matched + rxDataNum = 0; + break; + + case I2C_EVT_SLAVE_DATA_SENDING: //0x00060080. EV3 Sending data + I2C1->DAT = data_buf[rxDataNum++]; + break; + + case I2C_EVT_SLAVE_DATA_SENDED: + I2C1->DAT = data_buf[rxDataNum++]; + break; + + // SlaveReceiver + case I2C_EVT_SLAVE_DATA_RECVD: //0x00020040.EV2 one byte recved + data_buf[rxDataNum++] = I2C1->DAT; + break; + + case I2C_EVT_SLAVE_STOP_RECVD: // 0x00000010 EV4 + I2C_Enable(I2C1, ENABLE); + if(rxDataNum != 0) + { + flag_slave_recv_finish = 1; // The STOPF bit is not set after a NACK reception + } + break; + + case I2C_EVT_SLAVE_ACK_MISS: + I2C_ClrFlag(I2C1, I2C_FLAG_ACKFAIL); + if(rxDataNum != 0) //slave send the last data and recv NACK + { + flag_slave_send_finish = 1; + } + else //not the last data recv nack, send fail + { + + } + break; + + default: + //printf("last_event:0x%x\r\n", last_event); + I2C_Enable(I2C1, ENABLE); + timeout_flag = 1; + break; + } + } + + if (timeout_flag) + { + if ((I2CTimeout--) == 0) + { + printf("last_event:0x%x\r\n", last_event); + CommTimeOut_CallBack(SLAVE_UNKNOW); + } + } + else + { + I2CTimeout = I2CT_LONG_TIMEOUT; + } +} + +void Delay_us(uint32_t nCount) +{ + uint32_t tcnt; + while (nCount--) + { + tcnt = 64 / 5; + while (tcnt--){;} + } +} + +void CommTimeOut_CallBack(ErrCode_t errcode) +{ + log_info("...ErrCode:%d\r\n", errcode); +} + +/** + * @brief Compares two buffers. + * @param pBuffer, pBuffer1: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer identical to pBuffer1 + * FAILED: pBuffer differs from pBuffer1 + */ +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer != *pBuffer1) + { + return FAILED; + } + + pBuffer++; + pBuffer1++; + } + + return PASSED; +} + +/** + * @brief memery set a value + * @param s source + * @param c value + * @param count number + * @return pointer of the memery + */ +void Memset(void* s, uint8_t c, uint32_t count) +{ + char* xs = (char*)s; + + while (count--) // clear 17byte buffer + { + *xs++ = c; + } + + return; +} + + +void log_init(void) +{ + GPIO_InitType GPIO_InitStructure; + USART_InitType USART_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | LOG_PERIPH_GPIO, ENABLE); + + RCC_EnableAPB1PeriphClk(LOG_PERIPH, ENABLE); + + GPIO_InitStructure.Pin = LOG_TX_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = LOG_RX_PIN; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + // init uart + USART_Init(LOG_USARTx, &USART_InitStructure); + + // enable uart + USART_Enable(LOG_USARTx, ENABLE); +} + +void log_buff(uint8_t *data, int len) +{ + int i = 0; + for(i=0; i + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\software_i2c.c + software_i2c.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/MDK-ARM/Softeware_I2C_Master.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/MDK-ARM/Softeware_I2C_Master.uvprojx new file mode 100644 index 0000000..264f6db --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/MDK-ARM/Softeware_I2C_Master.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Softeware_I2C_Master + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Softeware_I2C_Master.bin .\Objects\Softeware_I2C_Master.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER,USE_FULL_ASSERT=1 + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + software_i2c.c + 1 + ..\src\software_i2c.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/inc/main.h new file mode 100644 index 0000000..b65f7fc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/inc/main.h @@ -0,0 +1,144 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define NON_REENTRANT + +#define I2Cx_MASTER I2C1 +#define I2Cx_MASTER_CLK RCC_APB1_PERIPH_I2C1 +#define I2Cx_MASTER_GPIO GPIOB +#define I2Cx_MASTER_GPIO_AF GPIO_AF3_I2C +#define I2Cx_MASTER_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define I2Cx_MASTER_SDA_PIN GPIO_PIN_6 +#define I2Cx_MASTER_SCL_PIN GPIO_PIN_7 + +#define DMA_CHANNEL_USED DMA1_CH1 +#define DMA_IRQ_HANDLER DMA1_Channel1_IRQHandler +#define DMA_IT_FLAG_TC DMA1_INT_TXC1 +#define DMA_IT_FLAG_GL DMA1_INT_GLB1 +#define DMA_IRQN DMA1_Channel1_IRQn + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +typedef enum +{ + C_READY = 0, + C_START_BIT, + C_STOP_BIT +}CommCtrl_t; + +typedef enum +{ + MASTER_OK = 0, + MASTER_BUSY, + MASTER_MODE, + MASTER_TXMODE, + MASTER_RXMODE, + MASTER_SENDING, + MASTER_SENDED, + MASTER_RECVD, + MASTER_BYTEF, + MASTER_BUSERR, + MASTER_UNKNOW, + SLAVE_OK = 20, + SLAVE_BUSY, + SLAVE_MODE, + SLAVE_BUSERR, + SLAVE_UNKNOW, + +}ErrCode_t; + + +#define LOG_USARTx USART2 +#define LOG_PERIPH RCC_APB1_PERIPH_USART2 +#define LOG_GPIO GPIOB +#define LOG_PERIPH_GPIO RCC_APB2_PERIPH_GPIOB +#define LOG_TX_PIN GPIO_PIN_4 +#define LOG_RX_PIN GPIO_PIN_5 +#define LOG_GPIO_AF GPIO_AF3_USART2 //GPIO_AF4_USART1 + +#define log_info(...) printf(__VA_ARGS__) +#define log_error(...) printf(__VA_ARGS__) +void log_init(void); +void log_buff(uint8_t *data, int len); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/inc/software_i2c.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/inc/software_i2c.h new file mode 100644 index 0000000..cbd9340 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/inc/software_i2c.h @@ -0,0 +1,116 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file software_i2c.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __SOFTWARE_I2C_H__ +#define __SOFTWARE_I2C_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + + + +//??IIC?????? +typedef struct +{ + GPIO_Module *SDA_GPIOx; //SDA port + GPIO_Module *SCL_GPIOx; //SCL port + uint32_t SDA_PINx; //SDA pin + uint32_t SCL_PINx; //SCL pin + uint32_t DelayUS; //delay time in US + //port function + void (*Start)(void *pHandle); //SI2C start signal + void (*Stop)(void *pHandle); //SI2C stop signal + bool (*SendByte)(void *pHandle, uint8_t data); //SI2C send a byte + uint8_t (*ReadByte)(void *pHandle,bool isAck); //SI2C read a byte +}SI2C_HANDLE; + + +bool SI2C_Init(SI2C_HANDLE *pHandle, GPIO_Module *SDA_GPIOx, GPIO_Module *SCL_GPIOx,\ + uint32_t SDA_Pin, uint32_t SCL_Pin,uint8_t DelayUS); //??IIC??? + +void SI2C_Start(SI2C_HANDLE *pHandle); //SI2C start signal +void SI2C_Stop(SI2C_HANDLE *pHandle); //SI2C stop signal +bool SI2C_WaitAck(SI2C_HANDLE *pHandle); //SI2C wait ack signal +void SI2C_Ack(SI2C_HANDLE *pHandle); //SI2C send ack signal +void SI2C_NAck(SI2C_HANDLE *pHandle); //SI2C send nack signal +bool SI2C_SendByte(SI2C_HANDLE *pHandle, uint8_t data); //SI2C send a byte +uint8_t SI2C_ReadByte(SI2C_HANDLE *pHandle,bool isAck); //SI2C read a byte +bool SI2C_ReadReg(SI2C_HANDLE *pHandle, uint8_t SlaveAddr, uint16_t RegAddr, \ + bool is8bitRegAddr, uint8_t *pDataBuff, uint16_t ReadByteNum); //SI2C read reg +bool SI2C_WriteReg(SI2C_HANDLE *pHandle, uint8_t SlaveAddr, uint16_t RegAddr, \ + bool is8bitRegAddr, uint8_t *pDataBuff, uint16_t WriteByteNum); //SI2C write reg + +bool SI2C_MasterWrite(SI2C_HANDLE *pHandle, uint8_t SlaveAddr, uint8_t *pDataBuff, uint16_t WriteByteNum); +bool SI2C_MasterRead(SI2C_HANDLE *pHandle, uint8_t SlaveAddr, uint8_t *pDataBuff, uint16_t ReadByteNum); +#ifdef __cplusplus +} +#endif + +#endif /* __SOFTWARE_I2C_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/readme.txt new file mode 100644 index 0000000..9dbae9e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/readme.txt @@ -0,0 +1,31 @@ + +1. Function description + + This example demonstrates the use of software I2C as a master to send and receive data. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + 1. SystemClock: HSI 64MHz + 2. I2C1 configuration: + SCL --> PB7 + SDA --> PB6 + CLOCK: 100KHz + + 3. USART2 configuration: + TX --> PB4 + RX --> PB5 + Baud rate: 115200 + + + 4. Test steps and phenomena + a, jumper wire to connect slave I2C1 + b, compile and download the code, reset and run + c, view the print information from the serial port and verify the result + +4. Matters needing attention + SCL and SDA must be pulled up \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/src/main.c new file mode 100644 index 0000000..80cd282 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2C/Software_I2C_Master/src/main.c @@ -0,0 +1,224 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#include "n32wb03x.h" +#include "software_i2c.h" +#include "main.h" +#include "stdio.h" +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup Software I2C_Master + * @{ + */ +#define SI2C_SDA_GPIOx GPIOB +#define SI2C_SCL_GPIOx GPIOB +#define SI2C_SDA_Pin GPIO_PIN_6 +#define SI2C_SCL_Pin GPIO_PIN_7 + +#define TEST_BUFFER_SIZE 32 +#define I2C_MASTER_ADDR 0x30 +#define I2C_SLAVE_ADDR 0xA0 + +uint8_t tx_buf[TEST_BUFFER_SIZE] = {0}; +uint8_t rx_buf[TEST_BUFFER_SIZE] = {0}; +Status test_status = FAILED; +static SI2C_HANDLE SI2C_handle; +Status Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); +extern void system_delay_n_10us(uint32_t value); +/** + * @brief Main program + */ +int main(void) +{ + uint16_t i = 0; + + log_init(); + log_info("\n this is a software i2c master demo\r\n"); + if(SI2C_Init(&SI2C_handle,SI2C_SDA_GPIOx, SI2C_SCL_GPIOx, SI2C_SDA_Pin, SI2C_SCL_Pin, 5) == false) + { + log_info("software i2c init fail \r\n"); + while(1); + } + /* Fill the buffer to send */ + for (i = 0; i < TEST_BUFFER_SIZE; i++) + { + tx_buf[i] = i; + } + + /* First write in the memory followed by a read of the written data --------*/ + /* Write data*/ + SI2C_MasterWrite(&SI2C_handle,I2C_SLAVE_ADDR, tx_buf, TEST_BUFFER_SIZE); + + //delay for make sure slave device ready + system_delay_n_10us(100*50); + /* Read data */ + SI2C_MasterRead(&SI2C_handle, I2C_SLAVE_ADDR, rx_buf, TEST_BUFFER_SIZE); + + /* Check if the data written to the memory is read correctly */ + test_status = Buffercmp(tx_buf, rx_buf, TEST_BUFFER_SIZE); + + if (test_status == PASSED) + { + log_info("write and read data the same, i2c master test pass\r\n"); + } + else + { + log_info("write and read data are different, i2c master test fail\r\n"); + } + log_buff(rx_buf, TEST_BUFFER_SIZE); + /* test_status = PASSED, if the write and read data are the same */ + /* test_status = FAILED, if the write and read data are different */ + while (1) + { + } +} + +/** + * @brief Compares two buffers. + * @param pBuffer, pBuffer1: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer identical to pBuffer1 + * FAILED: pBuffer differs from pBuffer1 + */ +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer != *pBuffer1) + { + return FAILED; + } + + pBuffer++; + pBuffer1++; + } + + return PASSED; +} + + +void log_init(void) +{ + GPIO_InitType GPIO_InitStructure; + USART_InitType USART_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | LOG_PERIPH_GPIO, ENABLE); + + RCC_EnableAPB1PeriphClk(LOG_PERIPH, ENABLE); + + GPIO_InitStructure.Pin = LOG_TX_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = LOG_RX_PIN; + GPIO_InitStructure.GPIO_Alternate = LOG_GPIO_AF; + GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure); + + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + // init uart + USART_Init(LOG_USARTx, &USART_InitStructure); + + // enable uart + USART_Enable(LOG_USARTx, ENABLE); +} + +void log_buff(uint8_t *data, int len) +{ + int i = 0; + for(i=0; i +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup software_i2c + * @{ + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define SI2C_DBUG 1 +#if SI2C_DBUG +#include "main.h" +#define SI2C_Debug(format,...) printf(format,##__VA_ARGS__) +#else +#define SI2C_Debug(format,...) +#endif //SI2C_DBUG + + +#define GPIOx_MODE_SET(GPIOx,bit,mode) do{ \ +GPIOx->POTYPE &= ~(1U << bit); \ +GPIOx->POTYPE |= (((mode >> 4U) & 1U) << bit); \ +GPIOx->PMODE&= ~(03U<<(bit * 2U)); \ +GPIOx->PMODE|= (mode& 03U)<<(bit*2U); \ +}while(0); + +//IO control +#define SDA_OUT_MODE(GPIOx,bit) GPIOx_MODE_SET(GPIOx,bit,GPIO_MODE_OUTPUT_OD) //SDA output +#define SDA_IN_MODE(GPIOx,bit) GPIOx_MODE_SET(GPIOx,bit,GPIO_MODE_INPUT) //SDA input +#define SCL_OUT_MODE(GPIOx,bit) GPIOx_MODE_SET(GPIOx,bit,GPIO_MODE_OUTPUT_PP) //SCL output +#define SDA_OUT_H(GPIOx,bit) (GPIOx->PBSC = 1<PBC = 1<PBSC = 1<PBC = 1<PID) & (1< 100) DelayUS = 100; + pHandle->DelayUS = DelayUS; + pHandle->SDA_GPIOx = SDA_GPIOx; //SDA port + pHandle->SCL_GPIOx = SCL_GPIOx; //SCL port + + for(bit = 0; (SDA_Pin >> bit)!=1 ;bit++ ) + { + if(bit>13) + break; + } + pHandle->SDA_PINx = bit; //SDA pin + for(bit = 0; (SCL_Pin >> bit)!=1 ;bit++ ) + { + if(bit>13) + break; + } + pHandle->SCL_PINx = bit; //SCL pin + //init GPIO + if (SDA_GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (SDA_GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + if (SCL_GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (SCL_GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + SDA_OUT_H(pHandle->SDA_GPIOx, pHandle->SDA_PINx); //SDA=1 + SCL_OUT_H(pHandle->SCL_GPIOx, pHandle->SCL_PINx); //SCL=1 + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = SDA_Pin; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitPeripheral(SDA_GPIOx, &GPIO_InitStructure); + GPIO_InitStructure.Pin = SCL_Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(SCL_GPIOx, &GPIO_InitStructure); + + SDA_OUT_H(pHandle->SDA_GPIOx, pHandle->SDA_PINx); //SDA=1 + SCL_OUT_H(pHandle->SCL_GPIOx, pHandle->SCL_PINx); //SCL=1 + //fucntion init + pHandle->Start = (void (*)(void *))SI2C_Start; + pHandle->Stop = (void (*)(void *))SI2C_Stop; + pHandle->SendByte = (bool (*)(void *,uint8_t))SI2C_SendByte; + pHandle->ReadByte = (uint8_t (*)(void *, bool))SI2C_ReadByte; + + return true; +} + + + +/** + * @brief software i2c send start singal + * @param + * @return + * @note + */ +void SI2C_Start(SI2C_HANDLE *pHandle) +{ + SDA_OUT_MODE(pHandle->SDA_GPIOx, pHandle->SDA_PINx); + SDA_OUT_H(pHandle->SDA_GPIOx, pHandle->SDA_PINx); //SDA=1 + SCL_OUT_H(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=1 + SI2C_DelayUS(pHandle->DelayUS); + SDA_OUT_L(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA=0 + SI2C_DelayUS(pHandle->DelayUS); + SCL_OUT_L(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=0 +} + + +/** + * @brief software i2c send stop singal + * @param + * @return + * @note + */ +void SI2C_Stop(SI2C_HANDLE *pHandle) +{ + SCL_OUT_L(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=0 + SI2C_DelayUS(1); + SDA_OUT_L(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA=0 + SI2C_DelayUS(pHandle->DelayUS); + SCL_OUT_H(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=1 + SI2C_DelayUS(pHandle->DelayUS); + SDA_OUT_H(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA=1 + SI2C_DelayUS(1); +} + + +/** + * @brief software i2c wait ack signal + * @param + * @return + * @note + */ +bool SI2C_WaitAck(SI2C_HANDLE *pHandle) +{ + uint8_t ucErrTime=0; + + SDA_OUT_H(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA=1 + SDA_IN_MODE(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA input + SI2C_DelayUS(pHandle->DelayUS); + SCL_OUT_H(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=1 + SI2C_DelayUS(pHandle->DelayUS); + + while(SDA_IN(pHandle->SDA_GPIOx, pHandle->SDA_PINx)) //wait low + { + ucErrTime++; + if(ucErrTime>50) + { + SI2C_Stop(pHandle); + return false; + } + SI2C_DelayUS(1); + } + SCL_OUT_L(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=0 + SI2C_DelayUS(1); + SDA_OUT_MODE(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA output + + return true; +} + + +/** + * @brief software i2c send ack singal + * @param + * @return + * @note + */ +void SI2C_Ack(SI2C_HANDLE *pHandle) +{ + SDA_OUT_L(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA=0 + SI2C_DelayUS(pHandle->DelayUS); + SCL_OUT_H(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=1 + SI2C_DelayUS(pHandle->DelayUS); + SCL_OUT_L(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=0 +} + +/** + * @brief software i2c send nack singal + * @param + * @return + * @note + */ +void SI2C_NAck(SI2C_HANDLE *pHandle) +{ + SDA_OUT_H(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA=1 + SI2C_DelayUS(pHandle->DelayUS); + SCL_OUT_H(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=1 + SI2C_DelayUS(pHandle->DelayUS); + SCL_OUT_L(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=0 +} + + + + +/** + * @brief software i2c send a byte + * @param + * @return + * @note + */ +bool SI2C_SendByte(SI2C_HANDLE *pHandle, uint8_t data) +{ + uint8_t t; + + for(t=0;t<8;t++) + { + if(data & 0X80) + { + SDA_OUT_H(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA=1 + } + else + { + SDA_OUT_L(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA=0 + } + data <<= 1; + SI2C_DelayUS(pHandle->DelayUS); + SCL_OUT_H(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=1 + SI2C_DelayUS(pHandle->DelayUS); + SCL_OUT_L(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=0 + } + return SI2C_WaitAck(pHandle); +} + + + +/** + * @brief software i2c read a byte + * @param + * @return + * @note + */ +uint8_t SI2C_ReadByte(SI2C_HANDLE *pHandle,bool isAck) +{ + uint8_t i,receive=0; + SDA_OUT_H(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA=1 pull up + SDA_IN_MODE(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA input + for(i=0;i<8;i++ ) + { + receive<<=1; + SI2C_DelayUS(pHandle->DelayUS); + SCL_OUT_H(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=1 + SI2C_DelayUS(pHandle->DelayUS); + if(SDA_IN(pHandle->SDA_GPIOx, pHandle->SDA_PINx)) + { + receive++; + } + __nop(); + SCL_OUT_L(pHandle->SCL_GPIOx, pHandle->SCL_PINx);//SCL=0 + } + __nop();__nop();__nop(); + + SDA_OUT_MODE(pHandle->SDA_GPIOx, pHandle->SDA_PINx);//SDA output + if (!isAck) + SI2C_NAck(pHandle);//send nack + else + SI2C_Ack(pHandle); //send ack + + return receive; +} + + +/** + * @brief software i2c read a reg + * @param + * @return + * @note + */ +bool SI2C_ReadReg(SI2C_HANDLE *pHandle, uint8_t SlaveAddr, uint16_t RegAddr,\ + bool is8bitRegAddr, uint8_t *pDataBuff, uint16_t ReadByteNum) +{ + uint16_t i; + + SI2C_Start(pHandle); + if(SI2C_SendByte(pHandle, SlaveAddr) == false) + { + SI2C_Debug("[SI2C ERROR]:address MBS write fail\r\n"); + return false; + } + if(is8bitRegAddr == false) + { + if(SI2C_SendByte(pHandle, RegAddr>>8) == false) + { + SI2C_Debug("[SI2C ERROR]:reg write fail\r\n"); + return false; + } + } + if(SI2C_SendByte(pHandle, RegAddr) == false) + { + SI2C_Debug("[SI2C ERROR]:address LSB write fail\r\n"); + return false; + } + + SI2C_Start(pHandle); + if(SI2C_SendByte(pHandle, SlaveAddr|1) == false) + { + SI2C_Debug("[SI2C ERROR]:address read fail\r\n"); + return false; + } + for(i = 0;i < ReadByteNum;i ++) + { + if(i == (ReadByteNum-1)) + { + pDataBuff[i] = SI2C_ReadByte(pHandle, false); + } + else + { + pDataBuff[i] = SI2C_ReadByte(pHandle, true); + } + } + SI2C_Stop(pHandle); + + return true; +} + + + +/** + * @brief software i2c write a reg + * @param + * @return + * @note + */ +bool SI2C_WriteReg(SI2C_HANDLE *pHandle, uint8_t SlaveAddr, uint16_t RegAddr,\ + bool is8bitRegAddr, uint8_t *pDataBuff, uint16_t WriteByteNum) +{ + uint16_t i; + + SI2C_Start(pHandle); + if(SI2C_SendByte(pHandle, SlaveAddr) == false) + { + SI2C_Debug("[SI2C ERROR]:address write fail\r\n"); + return false; + } + if(is8bitRegAddr == false) + { + if(SI2C_SendByte(pHandle, RegAddr>>8) == false) + { + SI2C_Debug("[SI2C ERROR]:reg MSB write fail\r\n"); + return false; + } + } + if(SI2C_SendByte(pHandle, RegAddr) == false) + { + SI2C_Debug("[SI2C ERROR]:reg LSB write fail\r\n"); + return false; + } + for(i = 0;i < WriteByteNum;i ++) + { + if(SI2C_SendByte(pHandle, pDataBuff[i]) == false) + { + SI2C_Debug("[SI2C ERROR]:data write fail\r\n"); + return false; + } + } + SI2C_Stop(pHandle); + + return true; +} + + +/** + * @brief software i2c master read + * @param + * @return + * @note + */ +bool SI2C_MasterRead(SI2C_HANDLE *pHandle, uint8_t SlaveAddr, uint8_t *pDataBuff, uint16_t ReadByteNum) +{ + uint16_t i; + + SI2C_Start(pHandle); + if(SI2C_SendByte(pHandle, SlaveAddr|0x01) == false) + { + SI2C_Debug("[SI2C ERROR]:address read fail\r\n"); + return false; + } + for(i = 0;i < ReadByteNum;i ++) + { + if(i == (ReadByteNum-1)) + { + pDataBuff[i] = SI2C_ReadByte(pHandle, false); + } + else + { + pDataBuff[i] = SI2C_ReadByte(pHandle, true); + } + } + SI2C_Stop(pHandle); + + return true; +} +/** + * @brief software i2c master write + * @param + * @return + * @note + */ +bool SI2C_MasterWrite(SI2C_HANDLE *pHandle, uint8_t SlaveAddr, uint8_t *pDataBuff, uint16_t WriteByteNum) +{ + uint16_t i; + + SI2C_Start(pHandle); + if(SI2C_SendByte(pHandle, SlaveAddr&0xFE) == false) + { + SI2C_Debug("[SI2C ERROR]:address write fail\r\n"); + return false; + } + + for(i = 0;i < WriteByteNum;i ++) + { + if(SI2C_SendByte(pHandle, pDataBuff[i]) == false) + { + SI2C_Debug("[SI2C ERROR]:data write fail\r\n"); + return false; + } + } + SI2C_Stop(pHandle); + + return true; +} + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/MDK-ARM/I2S_DMA_MASTER.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/MDK-ARM/I2S_DMA_MASTER.uvoptx new file mode 100644 index 0000000..dad6941 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/MDK-ARM/I2S_DMA_MASTER.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/MDK-ARM/I2S_DMA_MASTER.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/MDK-ARM/I2S_DMA_MASTER.uvprojx new file mode 100644 index 0000000..7876254 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/MDK-ARM/I2S_DMA_MASTER.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + I2S_DMA + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\I2S_DMA.bin .\Objects\I2S_DMA.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/inc/main.h new file mode 100644 index 0000000..abb8bc5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/inc/main.h @@ -0,0 +1,77 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + +#define I2S_MASTER SPI1 +#define I2S_MASTER_CLK RCC_APB2_PERIPH_SPI1 +#define I2S_MASTER_PIN_CK GPIO_PIN_1 +#define I2S_MASTER_PIN_SD GPIO_PIN_2 +#define I2S_MASTER_PIN_WS GPIO_PIN_0 +#define I2S_MASTER_PIN_PORT GPIOA +#define I2S_MASTER_PIN_AF GPIO_AF1_SPI1 + +#define I2S_MASTER_DMA DMA +#define I2S_MASTER_DMA_CLK RCC_AHB_PERIPH_DMA +#define I2S_MASTER_Rx_DMA_Channel DMA_CH2 +#define I2S_MASTER_Rx_DMA_FLAG DMA_FLAG_TC2 +#define I2S_MASTER_Tx_DMA_Channel DMA_CH3 +#define I2S_MASTER_Tx_DMA_FLAG DMA_FLAG_TC3 + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/readme.txt new file mode 100644 index 0000000..64d0d0c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/readme.txt @@ -0,0 +1,25 @@ + +1. Function description + 1. I2S master mode sends and receives data through DMA + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO:(Master mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + (Slave mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + 3. DMA: I2S1 transmission adopts DMA_CH3 channel, I2S1 reception adopts DMA_CH2 channel; + 4. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Instructions: + 1. After compiling, download the program to reset and run; + 2. After the master mode DEMO board and slave mode DEMO board PA0, PA1, PA2 are connected, + the master mode DEMO board is connected to the serial port printing tool, power on, + first press and hold the master mode DEMO board reset button, and then press the slave mode DEMO board reset button, + after the slave mode DEMO board has run, release the reset button of the master mode DEMO board and then check the printing test is successful; + +4. Matters needing attention + Two demo boards are required, one board to burn the master mode program, one board to burn the slave mode program, connect the VCC and GND of the two boards \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/src/main.c new file mode 100644 index 0000000..c249ca5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_MASTER/src/main.c @@ -0,0 +1,308 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup I2S_DMA + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +#define BufferSize 32 + +DMA_InitType DMA_InitStructure; +GPIO_InitType GPIO_InitStructure; +I2S_InitType I2S_InitStructure; + + +const uint16_t I2S_MASTER_Buffer_Tx[BufferSize] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C, 0x0D0E, 0x0F10, + 0x1112, 0x1314, 0x1516, 0x1718, 0x191A, 0x1B1C, 0x1D1E, 0x1F20, + 0x2122, 0x2324, 0x2526, 0x2728, 0x292A, 0x2B2C, 0x2D2E, 0x2F30, + 0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C, 0x3D3E, 0x3F40}; +uint16_t I2S_MASTER_Buffer_Rx[BufferSize] = {0}; + +volatile TestStatus TransferStatus = FAILED; +ErrorStatus HSEStartUpStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + uint8_t i = 0; + + log_init(); + log_info("\n this is a I2S DMA MASTER Demo.\n"); + + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + /* Deinitializes the I2S master peripheral registers --------------------*/ + SPI_I2S_DeInit(I2S_MASTER); + + /* I2S_MASTER_Tx_DMA_Channel configuration ---------------------------------------------*/ + DMA_DeInit(I2S_MASTER_Tx_DMA_Channel); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI1->DAT; + DMA_InitStructure.MemAddr = (uint32_t)I2S_MASTER_Buffer_Tx; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = BufferSize; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(I2S_MASTER_Tx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_SPI1_TX,DMA,I2S_MASTER_Tx_DMA_Channel,ENABLE); + + /* I2S peripheral configuration */ + I2S_InitStructure.Standard = I2S_STD_PHILLIPS; + I2S_InitStructure.DataFormat = I2S_DATA_FMT_16BITS_EXTENDED; + I2S_InitStructure.AudioFrequency = I2S_AUDIO_FREQ_48K; + I2S_InitStructure.CLKPOL = I2S_CLKPOL_LOW; + + /* Master Transmitter to Slave Receiver communication ------------*/ + /* I2S configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_MASTER_TX; + I2S_Init(I2S_MASTER, &I2S_InitStructure); + + /* Enable I2S_MASTER Tx request */ + SPI_I2S_EnableDma(I2S_MASTER, SPI_I2S_DMA_TX, ENABLE); + + /* Enable the I2S */ + I2S_Enable(I2S_MASTER, ENABLE); + + /* Enable DMA tx Channel */ + DMA_EnableChannel(I2S_MASTER_Tx_DMA_Channel, ENABLE); + + /* Wait for DMA tx channel transfer complete */ + while (!DMA_GetFlagStatus(I2S_MASTER_Tx_DMA_FLAG, DMA)) + ; + + /* I2S_MASTER_Rx_DMA_Channel configuration ---------------------------------------------*/ + DMA_DeInit(I2S_MASTER_Rx_DMA_Channel); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI1->DAT; + DMA_InitStructure.MemAddr = (uint32_t)I2S_MASTER_Buffer_Rx; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = BufferSize; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(I2S_MASTER_Rx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_SPI1_RX,DMA,I2S_MASTER_Rx_DMA_Channel,ENABLE); + + DMA_EnableChannel(I2S_MASTER_Tx_DMA_Channel, DISABLE); + SPI_I2S_EnableDma(I2S_MASTER, SPI_I2S_DMA_TX, DISABLE); + I2S_Enable(I2S_MASTER, DISABLE); + + I2S_InitStructure.I2sMode = I2S_MODE_MASTER_RX; + I2S_Init(I2S_MASTER, &I2S_InitStructure); + + /* Insert delay */ + Delay(0xFF); + + /* Enable I2S_MASTER Rx request */ + SPI_I2S_EnableDma(I2S_MASTER, SPI_I2S_DMA_RX, ENABLE); + + /* Enable the I2S */ + I2S_Enable(I2S_MASTER, ENABLE); + + /* Enable DMA rx Channel */ + DMA_EnableChannel(I2S_MASTER_Rx_DMA_Channel, ENABLE); + + /* Wait for DMA rx channel transfer complete */ + while (!DMA_GetFlagStatus(I2S_MASTER_Rx_DMA_FLAG, DMA)) + ; + + /* Check the correctness of written data */ + TransferStatus = Buffercmp(I2S_MASTER_Buffer_Rx, (uint16_t*)I2S_MASTER_Buffer_Tx, BufferSize); + /* TransferStatus = PASSED, if the transmitted and received data + are equal */ + /* TransferStatus = FAILED, if the transmitted and received data + are different */ + + if(TransferStatus == PASSED) + { + log_info("I2S DMA MASTER Demo test Succeed.\n"); + } + else + { + log_info("I2S DMA MASTER Demo test Fail.\n"); + for(i=0; i + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/MDK-ARM/I2S_DMA_SLAVE.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/MDK-ARM/I2S_DMA_SLAVE.uvprojx new file mode 100644 index 0000000..7876254 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/MDK-ARM/I2S_DMA_SLAVE.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + I2S_DMA + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\I2S_DMA.bin .\Objects\I2S_DMA.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/inc/main.h new file mode 100644 index 0000000..d09e42d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/inc/main.h @@ -0,0 +1,78 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + +#define I2S_SLAVE SPI1 +#define I2S_SLAVE_CLK RCC_APB2_PERIPH_SPI1 +#define I2S_SLAVE_PIN_CK GPIO_PIN_1 +#define I2S_SLAVE_PIN_SD GPIO_PIN_2 +#define I2S_SLAVE_PIN_WS GPIO_PIN_0 +#define I2S_SLAVE_PIN_PORT GPIOA +#define I2S_SLAVE_PIN_AF GPIO_AF1_SPI1 + +#define I2S_SLAVE_DMA DMA +#define I2S_SLAVE_DMA_CLK RCC_AHB_PERIPH_DMA +#define I2S_SLAVE_Rx_DMA_Channel DMA_CH2 +#define I2S_SLAVE_Rx_DMA_FLAG DMA_FLAG_TC2 +#define I2S_SLAVE_Tx_DMA_Channel DMA_CH3 +#define I2S_SLAVE_Tx_DMA_FLAG DMA_FLAG_TC3 + + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/readme.txt new file mode 100644 index 0000000..64908e9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/readme.txt @@ -0,0 +1,25 @@ + +1. Function description + 1. I2S slave mode sends and receives data through DMA + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO:(Master mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + (Slave mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + 3. DMA: I2S1 transmission adopts DMA_CH3 channel, I2S1 reception adopts DMA_CH2 channel; + 4. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Instructions: + 1. After compiling, download the program to reset and run; + 2. After the master mode DEMO board and slave mode DEMO board PA0, PA1, PA2 are connected, + the master mode DEMO board is connected to the serial port printing tool, power on, + first press and hold the master mode DEMO board reset button, and then press the slave mode DEMO board reset button, + after the slave mode DEMO board has run, release the reset button of the master mode DEMO board and then check the printing test is successful; + +4. Matters needing attention + Two demo boards are required, one board to burn the master mode program, one board to burn the slave mode program, connect the VCC and GND of the two boards \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/src/main.c new file mode 100644 index 0000000..75bc9dc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/src/main.c @@ -0,0 +1,306 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x.h" +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup I2S_DMA + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +#define BufferSize 32 + +DMA_InitType DMA_InitStructure; +GPIO_InitType GPIO_InitStructure; +I2S_InitType I2S_InitStructure; + +const uint16_t I2S_MASTER_Buffer_Tx[BufferSize] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C, 0x0D0E, 0x0F10, + 0x1112, 0x1314, 0x1516, 0x1718, 0x191A, 0x1B1C, 0x1D1E, 0x1F20, + 0x2122, 0x2324, 0x2526, 0x2728, 0x292A, 0x2B2C, 0x2D2E, 0x2F30, + 0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C, 0x3D3E, 0x3F40}; +uint16_t I2S_SLAVE_Buffer_Rx[BufferSize]; +volatile TestStatus TransferStatus = FAILED; +ErrorStatus HSEStartUpStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + int i = 0; + log_init(); + log_info("\n this is a I2S DMA SLAVE Demo.\n"); + + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + /* Deinitializes the I2S slave peripheral registers --------------------*/ + SPI_I2S_DeInit(I2S_SLAVE); + + /* I2S_SLAVE_Rx_DMA_Channel configuration ---------------------------------------------*/ + DMA_DeInit(I2S_SLAVE_Rx_DMA_Channel); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI1->DAT; + DMA_InitStructure.MemAddr = (uint32_t)I2S_SLAVE_Buffer_Rx; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = BufferSize; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(I2S_SLAVE_Rx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_SPI1_RX,DMA,I2S_SLAVE_Rx_DMA_Channel,ENABLE); + + /* I2S peripheral configuration */ + I2S_InitStructure.Standard = I2S_STD_PHILLIPS; + I2S_InitStructure.DataFormat = I2S_DATA_FMT_16BITS_EXTENDED; + I2S_InitStructure.AudioFrequency = I2S_AUDIO_FREQ_48K; + I2S_InitStructure.CLKPOL = I2S_CLKPOL_LOW; + + /* Master Transmitter to Slave Receiver communication ------------*/ + /* I2S configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_SlAVE_RX; + I2S_Init(I2S_SLAVE, &I2S_InitStructure); + + /* Enable I2S_SLAVE Rx request */ + SPI_I2S_EnableDma(I2S_SLAVE, SPI_I2S_DMA_RX, ENABLE); + + /* Enable the I2S */ + I2S_Enable(I2S_SLAVE, ENABLE); + + /* Enable DMA rx Channel */ + DMA_EnableChannel(I2S_SLAVE_Rx_DMA_Channel, ENABLE); + + /* Wait for DMA rx channel transfer complete */ + while (!DMA_GetFlagStatus(I2S_SLAVE_Rx_DMA_FLAG, DMA)) + ; + + /* Check the correctness of written data */ + TransferStatus = Buffercmp(I2S_SLAVE_Buffer_Rx, (uint16_t*)I2S_MASTER_Buffer_Tx, BufferSize); + /* TransferStatus = PASSED, if the transmitted and received data + are equal */ + /* TransferStatus = FAILED, if the transmitted and received data + are different */ + + /* I2S_MASTER_Tx_DMA_Channel configuration ---------------------------------------------*/ + DMA_DeInit(I2S_SLAVE_Tx_DMA_Channel); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI1->DAT; + DMA_InitStructure.MemAddr = (uint32_t)I2S_SLAVE_Buffer_Rx; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = BufferSize; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(I2S_SLAVE_Tx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_SPI1_TX,DMA,I2S_SLAVE_Tx_DMA_Channel,ENABLE); + + DMA_EnableChannel(I2S_SLAVE_Rx_DMA_Channel, DISABLE); + SPI_I2S_EnableDma(I2S_SLAVE, SPI_I2S_DMA_RX, DISABLE); + I2S_Enable(I2S_SLAVE, DISABLE); + + /* Master Transmitter to Slave Receiver communication ------------*/ + /* I2S configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_SlAVE_TX; + I2S_Init(I2S_SLAVE, &I2S_InitStructure); + + /* Enable I2S_SLAVE tx request */ + SPI_I2S_EnableDma(I2S_SLAVE, SPI_I2S_DMA_TX, ENABLE); + + /* Enable the I2S */ + I2S_Enable(I2S_SLAVE, ENABLE); + + /* Enable DMA tx Channel */ + DMA_EnableChannel(I2S_SLAVE_Tx_DMA_Channel, ENABLE); + + /* Wait for DMA tx channel transfer complete */ + while (!DMA_GetFlagStatus(I2S_SLAVE_Tx_DMA_FLAG, DMA)) + ; + + if(TransferStatus == PASSED) + { + log_info("I2S DMA SLAVE Demo test Succeed.\n"); + } + else + { + log_info("I2S DMA SLAVE Demo test Fail.\n"); + } + + + for(i=0; i<32; i++) + { + log_info("0x%04x ",I2S_SLAVE_Buffer_Rx[i]); + } + + while (1) + { + + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks --------------------------------------------------*/ + /* Enable I2S_SLAVE DMA clock */ + RCC_EnableAHBPeriphClk(I2S_SLAVE_DMA_CLK, ENABLE); + + /* GPIOA and AFIO clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* I2S clocks enable */ + RCC_EnableAPB2PeriphClk(I2S_SLAVE_CLK , ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure I2S pins: CK, WS and SD ---------------------------------*/ + GPIO_InitStructure.Pin = I2S_SLAVE_PIN_CK | I2S_SLAVE_PIN_SD | I2S_SLAVE_PIN_WS; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = I2S_SLAVE_PIN_AF; + GPIO_InitPeripheral(I2S_SLAVE_PIN_PORT, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/src/n32wb03x_it.c new file mode 100644 index 0000000..f8eea6f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_DMA_SLAVE/src/n32wb03x_it.c @@ -0,0 +1,121 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/MDK-ARM/I2S_Interrupt_MASTER.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/MDK-ARM/I2S_Interrupt_MASTER.uvoptx new file mode 100644 index 0000000..3f9c2d8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/MDK-ARM/I2S_Interrupt_MASTER.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/MDK-ARM/I2S_Interrupt_MASTER.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/MDK-ARM/I2S_Interrupt_MASTER.uvprojx new file mode 100644 index 0000000..f27c1bc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/MDK-ARM/I2S_Interrupt_MASTER.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + I2S_Interrupt + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\I2S_Interrupt.bin .\Objects\I2S_Interrupt.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/inc/main.h new file mode 100644 index 0000000..77e8e75 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/inc/main.h @@ -0,0 +1,64 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + + + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/inc/n32wb03x_it.h new file mode 100644 index 0000000..6ae2916 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void SPI1_IRQHandler(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/readme.txt new file mode 100644 index 0000000..cdbe9d4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + 1. I2S master mode sends data via interrupt + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO:(Master mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + (Slave mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + 3. Interrupt: I2S1 interrupt entry function SPI1_IRQHandler + 4. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Instructions: + 1. After compiling, download the program to reset and run; + 2. The slave mode DEMO board enters the debug mode, first press and hold the master mode DEMO board reset button, + then the slave mode DEMO board runs at full speed,then release the reset button of the master mode DEMO board. + +4. Matters needing attention + Two demo boards are required, one board to program the master mode program, one board to program the slave mode program, + the two boards need to be powered on together, and connect the VCC and GND of the two boards. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/src/main.c new file mode 100644 index 0000000..fc5802d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/src/main.c @@ -0,0 +1,291 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +I2S_InitType I2S_InitStructure; +const uint16_t I2S3_Buffer_Tx[32] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C, 0x0D0E, 0x0F10, + 0x1112, 0x1314, 0x1516, 0x1718, 0x191A, 0x1B1C, 0x1D1E, 0x1F20, + 0x2122, 0x2324, 0x2526, 0x2728, 0x292A, 0x2B2C, 0x2D2E, 0x2F30, + 0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C, 0x3D3E, 0x3F40}; + +uint16_t I2S2_Buffer_Rx[32]; +__IO uint32_t TxIdx = 0, RxIdx = 0; +TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; +ErrorStatus HSEStartUpStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); +TestStatus Buffercmp24bits(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Main program. + */ +int main(void) +{ + log_init(); + log_info("\n this is a I2S INTERRUPT MASTER Demo.\n"); + + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + + /* NVIC configuration ------------------------------------------------------*/ + NVIC_Configuration(); + + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + SPI_I2S_DeInit(SPI1); + /* I2S peripheral configuration */ + I2S_InitStructure.Standard = I2S_STD_PHILLIPS; + I2S_InitStructure.DataFormat = I2S_DATA_FMT_16BITS_EXTENDED; + I2S_InitStructure.AudioFrequency = I2S_AUDIO_FREQ_96K; + I2S_InitStructure.CLKPOL = I2S_CLKPOL_LOW; + + /* Master Transmitter to Slave Receiver communication -----------*/ + /* I2S1 configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_MASTER_TX; + I2S_Init(SPI1, &I2S_InitStructure); + + /* Enable the I2S1 TE interrupt */ + SPI_I2S_EnableInt(SPI1, SPI_I2S_INT_TE, ENABLE); + + /* Enable the I2S1 */ + I2S_Enable(SPI1, ENABLE); + + /* Wait the end of communication */ + while (TxIdx < 32) + { + } + + /* delay sometime */ + for (RxIdx = 0; RxIdx < 1024; RxIdx++) + { + + } + + TxIdx = 0; + + SPI_I2S_DeInit(SPI1); + + /* I2S peripheral configuration */ + I2S_InitStructure.Standard = I2S_STD_PHILLIPS; + I2S_InitStructure.DataFormat = I2S_DATA_FMT_24BITS; + I2S_InitStructure.AudioFrequency = I2S_AUDIO_FREQ_16K; + I2S_InitStructure.CLKPOL = I2S_CLKPOL_LOW; + + /* Master Transmitter to Slave Receiver communication -----------*/ + /* I2S1 configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_MASTER_TX; + I2S_Init(SPI1, &I2S_InitStructure); + + /* Enable the I2S1 TE interrupt */ + SPI_I2S_EnableInt(SPI1, SPI_I2S_INT_TE, ENABLE); + + /* Enable the I2S1 */ + I2S_Enable(SPI1, ENABLE); + + /* Wait the end of communication */ + while (TxIdx < 32) + { + } + printf("I2S INTERRUPT MASTER send end\r\n"); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks ------------------------------------------------*/ + /* GPIOA and AFIO clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* SPI1 clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_SPI1, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure SPI1 pins: CK, WS and SD ---------------------------------*/ + GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_SPI1; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* SPI1 IRQ Channel configuration */ + NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +/** + * @brief Compares two buffers in 24 bits data format. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp24bits(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + if (*pBuffer1 != (*pBuffer2 & 0xFF00)) + { + return FAILED; + } + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/src/n32wb03x_it.c new file mode 100644 index 0000000..0323a2d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_MASTER/src/n32wb03x_it.c @@ -0,0 +1,150 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern const uint16_t I2S3_Buffer_Tx[32]; +extern uint16_t I2S2_Buffer_Rx[32]; +extern __IO uint32_t TxIdx, RxIdx; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles SPI1 global interrupt request. + */ +void SPI1_IRQHandler(void) +{ + /* Check the interrupt source */ + if (SPI_I2S_GetIntStatus(SPI1, SPI_I2S_INT_TE) == SET) + { + /* Send a data from I2S1 */ + SPI_I2S_TransmitData(SPI1, I2S3_Buffer_Tx[TxIdx++]); + } + + /* Check the end of buffer transfer */ + if (TxIdx == 32) + { + /* Disable the I2S1 TE interrupt to end the communication */ + SPI_I2S_EnableInt(SPI1, SPI_I2S_INT_TE, DISABLE); + } +} + + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/MDK-ARM/I2S_Interrupt_SLAVE.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/MDK-ARM/I2S_Interrupt_SLAVE.uvoptx new file mode 100644 index 0000000..3f9c2d8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/MDK-ARM/I2S_Interrupt_SLAVE.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/MDK-ARM/I2S_Interrupt_SLAVE.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/MDK-ARM/I2S_Interrupt_SLAVE.uvprojx new file mode 100644 index 0000000..f27c1bc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/MDK-ARM/I2S_Interrupt_SLAVE.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + I2S_Interrupt + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\I2S_Interrupt.bin .\Objects\I2S_Interrupt.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/inc/main.h new file mode 100644 index 0000000..77e8e75 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/inc/main.h @@ -0,0 +1,64 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + + + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/inc/n32wb03x_it.h new file mode 100644 index 0000000..721c40f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void SPI1_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/readme.txt new file mode 100644 index 0000000..b8f5d91 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + 1. I2S slave mode sends data via interrupt + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO:(Master mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + (Slave mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + 3. Interrupt: I2S1 interrupt entry function SPI1_IRQHandler + 4. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Instructions: + 1. After compiling, download the program to reset and run; + 2. The slave mode DEMO board enters the debug mode, first press and hold the master mode DEMO board reset button, + then the slave mode DEMO board runs at full speed,then release the reset button of the master mode DEMO board. + +4. Matters needing attention + Two demo boards are required, one board to program the master mode program, one board to program the slave mode program, + the two boards need to be powered on together, and connect the VCC and GND of the two boards. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/src/main.c new file mode 100644 index 0000000..3fc53c8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/src/main.c @@ -0,0 +1,317 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +I2S_InitType I2S_InitStructure; +const uint16_t I2S3_Buffer_Tx[32] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C, 0x0D0E, 0x0F10, + 0x1112, 0x1314, 0x1516, 0x1718, 0x191A, 0x1B1C, 0x1D1E, 0x1F20, + 0x2122, 0x2324, 0x2526, 0x2728, 0x292A, 0x2B2C, 0x2D2E, 0x2F30, + 0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C, 0x3D3E, 0x3F40}; + +uint16_t I2S2_Buffer_Rx[32]; +__IO uint32_t TxIdx = 0, RxIdx = 0; +TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; +ErrorStatus HSEStartUpStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); +TestStatus Buffercmp24bits(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + + log_init(); + + log_info("\n this is a I2S INTERRUPT SLAVE Demo.\n"); + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + + /* NVIC configuration ------------------------------------------------------*/ + NVIC_Configuration(); + + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + SPI_I2S_DeInit(SPI1); + + /* I2S peripheral configuration */ + I2S_InitStructure.Standard = I2S_STD_PHILLIPS; + I2S_InitStructure.DataFormat = I2S_DATA_FMT_16BITS_EXTENDED; + I2S_InitStructure.AudioFrequency = I2S_AUDIO_FREQ_96K; + I2S_InitStructure.CLKPOL = I2S_CLKPOL_LOW; + + /* Master Transmitter to Slave Receiver communication -----------*/ + /* I2S1 configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_SlAVE_RX; + I2S_Init(SPI1, &I2S_InitStructure); + + /* Enable the I2S1 RNE interrupt */ + SPI_I2S_EnableInt(SPI1, SPI_I2S_INT_RNE, ENABLE); + + /* Enable the I2S1 */ + I2S_Enable(SPI1, ENABLE); + + /* Wait the end of communication */ + while (RxIdx < 32) + { + } + + TransferStatus1 = Buffercmp(I2S2_Buffer_Rx, (uint16_t*)I2S3_Buffer_Tx, 32); + /* TransferStatus1 = PASSED, if the data transmitted from master and received by + slave are the same + TransferStatus1 = FAILED, if the data transmitted from master and received by + slave are different */ + /* Reinitialize the buffers */ + for (RxIdx = 0; RxIdx < 32; RxIdx++) + { + I2S2_Buffer_Rx[RxIdx] = 0; + } + TxIdx = 0; + RxIdx = 0; + + SPI_I2S_DeInit(SPI1); + /* I2S peripheral configuration */ + I2S_InitStructure.Standard = I2S_STD_PHILLIPS; + I2S_InitStructure.DataFormat = I2S_DATA_FMT_24BITS; + I2S_InitStructure.AudioFrequency = I2S_AUDIO_FREQ_16K; + I2S_InitStructure.CLKPOL = I2S_CLKPOL_LOW; + + /* Master Transmitter to Slave Receiver communication -----------*/ + /* I2S1 configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_SlAVE_RX; + I2S_Init(SPI1, &I2S_InitStructure); + + /* Enable the I2S1 RNE interrupt */ + SPI_I2S_EnableInt(SPI1, SPI_I2S_INT_RNE, ENABLE); + + /* Enable the I2S1 */ + I2S_Enable(SPI1, ENABLE); + + /* Wait the end of communication */ + while (RxIdx < 32) + { + } + + TransferStatus2 = Buffercmp24bits(I2S2_Buffer_Rx, (uint16_t*)I2S3_Buffer_Tx, 32); + /* TransferStatus2 = PASSED, if the data transmitted from master and received by + slave are the same + TransferStatus2 = FAILED, if the data transmitted from master and received by + slave are different */ + printf("TransferStatus1:%d\tTransferStatus2:%d\r\n", TransferStatus1, TransferStatus2); + + if((TransferStatus1 == PASSED) && (TransferStatus2 == PASSED)) + { + log_info("I2S DMA MASTER Demo test Succeed.\n"); + } + else + { + log_info("I2S DMA MASTER Demo test Fail.\n"); + } + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks ------------------------------------------------*/ + /* GPIOA and AFIO clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* SPI1 clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_SPI1, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure SPI1 pins: CK, WS and SD ---------------------------------*/ + GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_SPI1; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* SPI1 IRQ Channel configuration */ + NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +/** + * @brief Compares two buffers in 24 bits data format. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp24bits(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + if (*pBuffer1 != (*pBuffer2 & 0xFF00)) + { + return FAILED; + } + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/src/n32wb03x_it.c new file mode 100644 index 0000000..762955a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/I2S_Interrupt_SLAVE/src/n32wb03x_it.c @@ -0,0 +1,144 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern const uint16_t I2S3_Buffer_Tx[32]; +extern uint16_t I2S2_Buffer_Rx[32]; +extern __IO uint32_t TxIdx, RxIdx; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles SPI1 global interrupt request. + */ +void SPI1_IRQHandler(void) +{ + /* Check the interrupt source */ + if(SPI1->STS & SPI_I2S_RNE_FLAG) + { + /* Store the I2S1 received data in the relative data table */ + I2S2_Buffer_Rx[RxIdx++] = SPI1->DAT; + } +} + + + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/MDK-ARM/SPI_I2S_Switch_MASTER.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/MDK-ARM/SPI_I2S_Switch_MASTER.uvoptx new file mode 100644 index 0000000..7bcee3d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/MDK-ARM/SPI_I2S_Switch_MASTER.uvoptx @@ -0,0 +1,343 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/MDK-ARM/SPI_I2S_Switch_MASTER.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/MDK-ARM/SPI_I2S_Switch_MASTER.uvprojx new file mode 100644 index 0000000..1dc9da5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/MDK-ARM/SPI_I2S_Switch_MASTER.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + SPI_I2S_Switch + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\SPI_I2S_Switch.bin .\Objects\SPI_I2S_Switch.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/inc/main.h new file mode 100644 index 0000000..77e8e75 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/inc/main.h @@ -0,0 +1,64 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + + + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/readme.txt new file mode 100644 index 0000000..b7d3cd9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/readme.txt @@ -0,0 +1,23 @@ + + +1. Function description + 1. After I2S master mode sends data, switch to SPI master mode to send data, and then switch to I2S slave mode to send data + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO:(Master mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + (Slave mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + 3. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Instructions: + 1. After compiling, download the program to reset and run; + 2. The slave mode DEMO board enters the debug mode, first press and hold the master mode DEMO board reset button, + then the slave mode DEMO board runs at full speed,then release the reset button of the master mode DEMO board. + +4. Matters needing attention + Two demo boards are required, one board to burn the master mode program, one board to burn the slave mode program, connect the VCC and GND of the two boards \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/src/main.c new file mode 100644 index 0000000..aa68142 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/src/main.c @@ -0,0 +1,299 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup SPI_I2S_Switch + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +#define BufferSize 32 + +I2S_InitType I2S_InitStructure; +SPI_InitType SPI_InitStructure; +uint16_t I2S3_Buffer_Tx[BufferSize] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C, 0x0D0E, 0x0F10, + 0x1112, 0x1314, 0x1516, 0x1718, 0x191A, 0x1B1C, 0x1D1E, 0x1F20, + 0x2122, 0x2324, 0x2526, 0x2728, 0x292A, 0x2B2C, 0x2D2E, 0x2F30, + 0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C, 0x3D3E, 0x3F40}; + +uint16_t SPI3_Buffer_Tx[BufferSize] = {0x5152, 0x5354, 0x5556, 0x5758, 0x595A, 0x5B5C, 0x5D5E, 0x5F60, + 0x6162, 0x6364, 0x6566, 0x6768, 0x696A, 0x6B6C, 0x6D6E, 0x6F70, + 0x7172, 0x7374, 0x7576, 0x7778, 0x797A, 0x7B7C, 0x7D7E, 0x7F80, + 0x8182, 0x8384, 0x8586, 0x8788, 0x898A, 0x8B8C, 0x8D8E, 0x8F90}; + +__IO uint16_t I2S2_Buffer_Rx[BufferSize]; +__IO uint16_t SPI2_Buffer_Rx[BufferSize]; +__IO uint16_t TxIdx = 0, RxIdx = 0; +volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; +volatile TestStatus TransferStatus3 = FAILED; +ErrorStatus HSEStartUpStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Main program. + */ +int main(void) +{ + log_init(); + log_info("\n this is a I2S switch MASTER Demo.\n"); + + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + /* Deinitializes the SPI1 peripheral registers --------------------*/ + SPI_I2S_DeInit(SPI1); + /* I2S peripheral configuration */ + I2S_InitStructure.Standard = I2S_STD_PHILLIPS; + I2S_InitStructure.DataFormat = I2S_DATA_FMT_16BITS_EXTENDED; + I2S_InitStructure.AudioFrequency = I2S_AUDIO_FREQ_48K; + I2S_InitStructure.CLKPOL = I2S_CLKPOL_LOW; + + /* I2S1 configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_MASTER_TX; + I2S_Init(SPI1, &I2S_InitStructure); + + /* Enable the I2S1 */ + I2S_Enable(SPI1, ENABLE); + + /* Begin the communication in I2S mode */ + while (TxIdx < BufferSize) + { + /* Wait the Tx buffer to be empty */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_TE_FLAG) == RESET) + { + } + /* Send a data from I2S1 */ + SPI_I2S_TransmitData(SPI1, I2S3_Buffer_Tx[TxIdx++]); + } + + /* delay sometimes */ + for (RxIdx = 0; RxIdx < 1024; RxIdx++) + { + + } + + /* Reset TxIdx, RxIdx indexes */ + TxIdx = 0; + RxIdx = 0; + + SPI_I2S_DeInit(SPI1); + /* Switch to SPI mode communication ----------------------------------------*/ + /* SPI1 configuration */ + SPI_InitStructure.DataDirection = SPI_DIR_SINGLELINE_TX; + SPI_InitStructure.SpiMode = SPI_MODE_MASTER; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_16BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_16; + SPI_InitStructure.FirstBit = SPI_FB_MSB; + SPI_InitStructure.CRCPoly = 7; + SPI_Init(SPI1, &SPI_InitStructure); + + /* Enable SPI1 */ + SPI_Enable(SPI1, ENABLE); + + /* Begin the communication in SPI mode */ + while (TxIdx < BufferSize) + { + /* Wait the Tx buffer to be empty */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_TE_FLAG) == RESET) + { + } + /* Send a data from SPI3 */ + SPI_I2S_TransmitData(SPI1, SPI3_Buffer_Tx[TxIdx++]); + } + + /* Reset TxIdx, RxIdx indexes and receive table values */ + for (TxIdx = 0; TxIdx < BufferSize; TxIdx++) + { + I2S2_Buffer_Rx[TxIdx] = 0; + } + + TxIdx = 0; + RxIdx = 0; + + /* Slave Transmitter to Master Receiver communication ------------*/ + /* I2S1 configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_SlAVE_TX; + I2S_Init(SPI1, &I2S_InitStructure); + + /* Wait the Tx buffer to be empty */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_TE_FLAG) == RESET) + { + } + /* Prepare the first data to be sent from the slave */ + SPI_I2S_TransmitData(SPI1, I2S3_Buffer_Tx[TxIdx++]); + + /* Enable the I2S1 */ + I2S_Enable(SPI1, ENABLE); + + /* Begin the communication in I2S mode */ + while (TxIdx < BufferSize) + { + /* Wait the Tx buffer to be empty */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_TE_FLAG) == RESET) + { + } + /* Send a data from I2S1 */ + SPI_I2S_TransmitData(SPI1, I2S3_Buffer_Tx[TxIdx++]); + } + + printf(" I2S switch MASTER send end\r\n"); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks --------------------------------------------------*/ + /* GPIOA and AFIO clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* SPI1 clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_SPI1, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure SPI1/I2S1 pins: CK, WS and SD ---------------------------------*/ + GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_SPI1; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_MASTER/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/MDK-ARM/SPI_I2S_Switch_SLAVE.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/MDK-ARM/SPI_I2S_Switch_SLAVE.uvoptx new file mode 100644 index 0000000..7bcee3d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/MDK-ARM/SPI_I2S_Switch_SLAVE.uvoptx @@ -0,0 +1,343 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/MDK-ARM/SPI_I2S_Switch_SLAVE.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/MDK-ARM/SPI_I2S_Switch_SLAVE.uvprojx new file mode 100644 index 0000000..1dc9da5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/MDK-ARM/SPI_I2S_Switch_SLAVE.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + SPI_I2S_Switch + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\SPI_I2S_Switch.bin .\Objects\SPI_I2S_Switch.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/inc/main.h new file mode 100644 index 0000000..77e8e75 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/inc/main.h @@ -0,0 +1,64 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + + + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/readme.txt new file mode 100644 index 0000000..62c67c6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/readme.txt @@ -0,0 +1,22 @@ + +1. Function description + 1. After receiving data in I2S slave mode, switch to SPI slave mode to receive data, and then switch to I2S master mode to receive data + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO:(Master mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + (Slave mode DEMO board) I2S1: WS--PA0, CK--PA1, SD--PA2 + 3. Log print: DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Instructions: + 1. After compiling, download the program to reset and run; + 2. The slave mode DEMO board enters the debug mode, first press and hold the master mode DEMO board reset button, + then the slave mode DEMO board runs at full speed,then release the reset button of the master mode DEMO board. + +4. Matters needing attention + Two demo boards are required, one board to burn the master mode program, one board to burn the slave mode program, connect the VCC and GND of the two boards \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/src/main.c new file mode 100644 index 0000000..a671026 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/src/main.c @@ -0,0 +1,310 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup SPI_I2S_Switch + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +#define BufferSize 32 + +I2S_InitType I2S_InitStructure; +SPI_InitType SPI_InitStructure; +uint16_t I2S3_Buffer_Tx[BufferSize] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C, 0x0D0E, 0x0F10, + 0x1112, 0x1314, 0x1516, 0x1718, 0x191A, 0x1B1C, 0x1D1E, 0x1F20, + 0x2122, 0x2324, 0x2526, 0x2728, 0x292A, 0x2B2C, 0x2D2E, 0x2F30, + 0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C, 0x3D3E, 0x3F40}; + +uint16_t SPI3_Buffer_Tx[BufferSize] = {0x5152, 0x5354, 0x5556, 0x5758, 0x595A, 0x5B5C, 0x5D5E, 0x5F60, + 0x6162, 0x6364, 0x6566, 0x6768, 0x696A, 0x6B6C, 0x6D6E, 0x6F70, + 0x7172, 0x7374, 0x7576, 0x7778, 0x797A, 0x7B7C, 0x7D7E, 0x7F80, + 0x8182, 0x8384, 0x8586, 0x8788, 0x898A, 0x8B8C, 0x8D8E, 0x8F90}; + +__IO uint16_t I2S2_Buffer_Rx[BufferSize]; +__IO uint16_t SPI2_Buffer_Rx[BufferSize]; +__IO uint16_t TxIdx = 0, RxIdx = 0; +volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; +volatile TestStatus TransferStatus3 = FAILED; +ErrorStatus HSEStartUpStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Main program. + */ +int main(void) +{ + log_init(); + log_info("\n this is a I2S switch Slave Demo.\n"); + + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + /* Deinitializes the SPI1 peripheral registers --------------------*/ + SPI_I2S_DeInit(SPI1); + + /* I2S peripheral configuration */ + I2S_InitStructure.Standard = I2S_STD_PHILLIPS; + I2S_InitStructure.DataFormat = I2S_DATA_FMT_16BITS_EXTENDED; + I2S_InitStructure.AudioFrequency = I2S_AUDIO_FREQ_48K; + I2S_InitStructure.CLKPOL = I2S_CLKPOL_LOW; + + /* Master Transmitter to Slave Receiver communication ------------*/ + /* I2S1 configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_SlAVE_RX; + I2S_Init(SPI1, &I2S_InitStructure); + + /* Enable the I2S1 */ + I2S_Enable(SPI1, ENABLE); + + /* Begin the communication in I2S mode */ + while (RxIdx < BufferSize) + { + /* Wait the Rx buffer to be full */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_RNE_FLAG) == RESET) + { + } + /* Store the I2S1 received data in the relative data table */ + I2S2_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI1); + } + + TransferStatus1 = Buffercmp((uint16_t*)I2S2_Buffer_Rx, I2S3_Buffer_Tx, BufferSize); + /* TransferStatus1 = PASSED, if the data transmitted from master and received by + slave are the same + TransferStatus1 = FAILED, if the data transmitted from master and received by + slave are different */ + + /* Reset TxIdx, RxIdx indexes */ + TxIdx = 0; + RxIdx = 0; + + /* Switch to SPI mode communication ----------------------------------------*/ + /* SPI1 configuration */ + SPI_I2S_DeInit(SPI1); + SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_RONLY; + SPI_InitStructure.SpiMode = SPI_MODE_SLAVE; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_16BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_16; + SPI_InitStructure.FirstBit = SPI_FB_MSB; + SPI_InitStructure.CRCPoly = 7; + SPI_Init(SPI1, &SPI_InitStructure); + + /* Enable SPI1 */ + SPI_Enable(SPI1, ENABLE); + + /* Begin the communication in SPI mode */ + while (RxIdx < BufferSize) + { + /* Wait the Rx buffer to be full */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_RNE_FLAG) == RESET) + { + } + /* Store the SPI1 received data in the relative data table */ + SPI2_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI1); + } + + TransferStatus2 = Buffercmp((uint16_t*)SPI2_Buffer_Rx, SPI3_Buffer_Tx, BufferSize); + /* TransferStatus2 = PASSED, if the data transmitted from master and received by + slave are the same + TransferStatus2 = FAILED, if the data transmitted from master and received by + slave are different */ + + /* Reset TxIdx, RxIdx indexes and receive table values */ + for (TxIdx = 0; TxIdx < BufferSize; TxIdx++) + { + I2S2_Buffer_Rx[TxIdx] = 0; + } + + TxIdx = 0; + RxIdx = 0; + + /* Slave Transmitter to Master Receiver communication ------------*/ + /* I2S1 configuration */ + I2S_InitStructure.I2sMode = I2S_MODE_MASTER_RX; + I2S_Init(SPI1, &I2S_InitStructure); + + /* delay sometimes */ + for (TxIdx = 0; TxIdx < 512; TxIdx++) + { + + } + + /* Enable the I2S1 */ + I2S_Enable(SPI1, ENABLE); + + /* Begin the communication in I2S mode */ + while (RxIdx < BufferSize) + { + /* Wait the Rx buffer to be full */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_RNE_FLAG) == RESET) + { + } + /* Store the I2S1 received data in the relative data table */ + I2S2_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI1); + } + + TransferStatus3 = Buffercmp((uint16_t*)I2S2_Buffer_Rx, I2S3_Buffer_Tx, BufferSize); + /* TransferStatus3 = PASSED, if the data transmitted from master and received by + slave are the same + TransferStatus3 = FAILED, if the data transmitted from master and received by + slave are different */ + printf("TransferStatus1:%d, TransferStatus2:%d, TransferStatus3:%d\r\n", TransferStatus1, TransferStatus2, TransferStatus3); + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks --------------------------------------------------*/ + /* GPIOA and AFIO clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* SPI1 clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_SPI1, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure SPI1/I2S1 pins: CK, WS and SD ---------------------------------*/ + GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_SPI1; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/I2S/SPI_I2S_Switch_SLAVE/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/MDK-ARM/NEC_Protocol.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/MDK-ARM/NEC_Protocol.uvoptx new file mode 100644 index 0000000..e0da52d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/MDK-ARM/NEC_Protocol.uvoptx @@ -0,0 +1,338 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + UL2CM3 + -UAny -O198 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO23 -FD20000000 -FC4000 -FN1 -FF0N32WB03X -FS01000000 -FL080000 + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8009 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + ARMRTXEVENTFLAGS + -L70 -Z18 -C0 -M0 -T1 + + + 0 + DLGTARM + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0) + + + 0 + ARMDBGFLAGS + + + + 0 + DLGUARM + + + + + + + 0 + 1 + CRCValue + + + 1 + 1 + CRC16Value + + + 2 + 1 + IR + + + + 0 + + + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 5 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 6 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 7 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/MDK-ARM/NEC_Protocol.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/MDK-ARM/NEC_Protocol.uvprojx new file mode 100644 index 0000000..aca3b22 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/MDK-ARM/NEC_Protocol.uvprojx @@ -0,0 +1,463 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + NEC_Protocol + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\NEC_Protocol.bin .\Objects\NEC_Protocol.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + + + + + <Project Info> + 0 + 1 + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/inc/main.h new file mode 100644 index 0000000..5e3a641 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/inc/main.h @@ -0,0 +1,121 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _LPUART1_USART1_ + +#ifdef _LPUART1_USART1_ +#define LPUARTy LPUART1 +#define LPUARTy_CLK RCC_LPUART1CLK +#define LPUARTy_GPIO GPIOB +#define LPUARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTy_RxPin GPIO_PIN_2 +#define LPUARTy_TxPin GPIO_PIN_1 +#define LPUARTy_Rx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_Tx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_DAT_Base (LPUART1_BASE + 0x10) +#define LPUARTy_Tx_DMA_Channel DMA_CH1 +#define LPUARTy_Tx_DMA_FLAG DMA_FLAG_TC1 +#define LPUARTy_Rx_DMA_Channel DMA_CH2 +#define LPUARTy_Rx_DMA_FLAG DMA_FLAG_TC2 +#define LPUARTy_Tx_DMA_REMAP DMA_REMAP_LPUART_TX +#define LPUARTy_Rx_DMA_REMAP DMA_REMAP_LPUART_RX +#define LPUARTy_IRQn LPUART1_IRQn +#define LPUARTy_IRQHandler LPUART1_IRQHandler + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#define USARTz_DAT_Base (USART2_BASE + 0x04) +#define USARTz_Tx_DMA_Channel DMA_CH4 +#define USARTz_Tx_DMA_FLAG DMA_FLAG_TC4 +#define USARTz_Rx_DMA_Channel DMA_CH5 +#define USARTz_Rx_DMA_FLAG DMA_FLAG_TC5 +#define USARTz_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTz_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#endif + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(uint32_t LPUART_CLK_SRC); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +void DMA_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); +void Delay(__IO uint32_t nCount); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/inc/n32wb03x_it.h new file mode 100644 index 0000000..58aea54 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void LPUART1_2_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/readme.txt new file mode 100644 index 0000000..280f410 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/readme.txt @@ -0,0 +1,22 @@ + +1. Function description + This is a sample to the hardware IRC module output NEC IR protocol. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. Clock source: + HSE=32M, HSI=64M, AHB=64M, APB1=32M, APB2=64M, ADC CLK=HSE/8, DMA CLK=64M + 2. Port configuration: + PB4 as the IRC tx pin. + + Instructions: + 1. Download after compiling and reset to run the program, check the wave of PB4. + 2. We can connect the IR led board to PB4 then check the data receive from IR receiver. + 3. Or we can connect the logic analyzer to PB4 and check the wave it output. + +4. Matters needing attention + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/src/main.c new file mode 100644 index 0000000..e32799d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/src/main.c @@ -0,0 +1,242 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ +extern void system_delay_n_10us(uint32_t value); + + +/** + * @brief Configures the GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIO_PIN_4; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +/** + * @brief IRgen module send data in NEC protocol + * @param + * @return + * @note + */ +void irgen_module_send_NEC(uint16_t address, uint16_t command) +{ + // Set carrier frequency 38k. 64M/38k = 1684, 1684*1/3 = 561,1684*2/3 = 1122.6 + IRC->FREQ_CARRIER_ON = 561; + IRC->FREQ_CARRIER_OFF = 1122; + + // Set "logic 0" parameters + IRC->LOGIC_ZERO_TIME = 0x1515; // mark and space duration = 1 clock cycle + + // Set "logic 1" parameters + IRC->LOGIC_ONE_TIME = 0x153f; // same here + + IRC->REPEAT_TIME = 4180; //110ms*38k = 4180 + + IRC->CTRL |= IR_CTRL_ENABLE_Msk; + + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_CODE,HW_IRGEN_PAINT_MARK,342); // 9ms*38K = 342 + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_CODE,HW_IRGEN_PAINT_SPACE,171); // 4.5ms*38K = 171 + + hw_irgen_insert_digital_message(HW_IRGEN_FIFO_CODE, 16, address); //((~address)<<8|address) + + hw_irgen_insert_digital_message(HW_IRGEN_FIFO_CODE, 16, ((~command)<<8|command)); + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_CODE,HW_IRGEN_PAINT_MARK,21); // 560us*38k = 21 + + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_MARK,342); // 9ms*38K = 342 + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_SPACE,85); // 2.25ms*38k = 85.5 + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_MARK,21); // 560us*38k = 21.28 + + hw_irgen_start(); +} + +/** + * @brief IRgen module send data in RC5 protocol + * @param + * @return + * @note + */ +void irgen_module_send_RC5(uint16_t address, uint16_t command) +{ + static uint8_t toggle_bit = 0; + uint16_t rc5_format; + // Set carrier frequency 36k. 64M/36k = 1778, 1778*1/3 = 592,842*2/3 =1185 + IRC->FREQ_CARRIER_ON = 592; + IRC->FREQ_CARRIER_OFF = 1185; + + // Set "logic 0" parameters 889us*36k = 32 + IRC->LOGIC_ZERO_TIME = 0x2020; // mark and space duration = 1 clock cycle + + // Set "logic 1" parameters 889us*36k = 32 + IRC->LOGIC_ONE_TIME = 0x2020; // same here + + IRC->REPEAT_TIME = 4000; // 111ms*36k = 4000 + + IRC->CTRL |= IR_CTRL_ENABLE_Msk; + IRC->CTRL |= IR_CTRL_LOGIC_ONE_FORMAT_Msk; // logic 1 is space to mark + IRC->CTRL &= ~IR_CTRL_LOGIC_ZERO_FORMAT_Msk; // logic 0 is mark to space + + // '1' '1' as start bit + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_SPACE,32); // 889us*36k = 32 + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_MARK,32); // 889us*36k = 32 + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_SPACE,32); // 889us*36k = 32 + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_MARK,32); // 889us*36k *2 = 32 + + // Toggle Bit + toggle_bit++; + if(toggle_bit&0x01) + { + //'1' + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_SPACE,32); // 889us*36k = 32 + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_MARK,32); // 889us*36k = 32 + }else + { + //'0' + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_MARK,32); // 889us*36k = 32 + hw_irgen_insert_paint_message(HW_IRGEN_FIFO_REPEAT,HW_IRGEN_PAINT_SPACE,32); // 889us*36k = 32 + } + + // address and data + rc5_format = hw_irgen_reverse_bit_order(address,5); + hw_irgen_insert_digital_message(HW_IRGEN_FIFO_REPEAT, 5, rc5_format); + + rc5_format = hw_irgen_reverse_bit_order(command,6); + hw_irgen_insert_digital_message(HW_IRGEN_FIFO_REPEAT, 6,rc5_format ); + + hw_irgen_start(); + +} + + +/** + * @brief Main program. + */ +int main(void) +{ + uint16_t ADDRESS = 0x59A6; + uint8_t COMMAND1 = 0x16; + uint8_t COMMAND2 = 0x18; + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_IRC, ENABLE); + + GPIO_Configuration(); + + #if 1 + irgen_module_send_NEC(ADDRESS,COMMAND1); + system_delay_n_10us(100*500); // 500ms + hw_irgen_stop(); + system_delay_n_10us(100); + + irgen_module_send_NEC(ADDRESS,COMMAND2); + system_delay_n_10us(100*500); // 500ms + hw_irgen_stop(); + system_delay_n_10us(100); + #else + irgen_module_send_RC5(ADDRESS,COMMAND1); + system_delay_n_10us(100*500); // 500ms + hw_irgen_stop(); + system_delay_n_10us(100); + + irgen_module_send_RC5(ADDRESS,COMMAND2); + system_delay_n_10us(100*500); // 500ms + hw_irgen_stop(); + system_delay_n_10us(100); + #endif + + while (1) + { + } +} + + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/src/n32wb03x_it.c new file mode 100644 index 0000000..e32b9ee --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IRC/NEC_Protocol/src/n32wb03x_it.c @@ -0,0 +1,128 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/** + * @brief This function handles DMA interrupt request defined in main.h . + */ +void DMA_IRQ_HANDLER(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/MDK-ARM/IWDG_Reset.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/MDK-ARM/IWDG_Reset.uvoptx new file mode 100644 index 0000000..a09dd87 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/MDK-ARM/IWDG_Reset.uvoptx @@ -0,0 +1,379 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 4 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 5 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 5 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 5 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 5 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 5 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 13 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/MDK-ARM/IWDG_Reset.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/MDK-ARM/IWDG_Reset.uvprojx new file mode 100644 index 0000000..48b6544 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/MDK-ARM/IWDG_Reset.uvprojx @@ -0,0 +1,485 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + IWDG + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\IWDG.bin .\Objects\IWDG.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc;..\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/inc/main.h new file mode 100644 index 0000000..31aca0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/inc/main.h @@ -0,0 +1,68 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 + +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/inc/n32wb03x_it.h new file mode 100644 index 0000000..8ca7e81 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/readme.txt new file mode 100644 index 0000000..3d1a1f5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/readme.txt @@ -0,0 +1,30 @@ + + +1. Function description + + IWDG reset function. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + System Configuration: + 1. IWDG clock source: LSI/128 + 2. Timeout value: 300ms (4ms*75) + 3. light Indicator: LED1(PB0) LED2(PA6) + + Test steps and phenomenon: + 1. Compile and download the code to reset and run.The indicator LED2 + keeps flashing. It means that IWDG feeds the dog normally and the code runs normally. + 2. Change the parameter of the Delay() function from 250 to 350 or more, the whole system + will always be in the reset state, and LED1 will be on. + + +4. Matters needing attention + 1. If you simulate through the programmer, you need to enable DBG_ConfigPeriph(DBG_IWDG_STOP,ENABLE). + 2. 300ms is the timeout value obtained by theoretical calculation. In practice, the LSI clock has deviation, + so the parameters of the delay function are determined according to the actual situation.The skew range of + the LSI clock is detailed in the data sheet. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/src/main.c new file mode 100644 index 0000000..b4f74c3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/src/main.c @@ -0,0 +1,246 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +/** @addtogroup n32wb03x_StdPeriph_Examples + * @{ + */ + +/** @addtogroup + * @{ + */ + +__IO uint32_t TimingDelay = 0; +__IO uint32_t LsiFreq = 32000; +extern __IO uint16_t CaptureNumber; + +static void Delay(__IO uint32_t nTime); + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param Led Specifies the Led to be set on. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIOx->PBSC = Pin; +} +/** + * @brief Turns selected Led Off. + * @param Led Specifies the Led to be set off. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIOx->PBC = Pin; +} + +/** + * @brief Toggles the selected Led. + * @param Led Specifies the Led to be toggled. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIOx->POD ^= Pin; +} + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + log_init(); + log_info("--- IWDG demo ---\n"); + + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + LedOff(LED1_PORT, LED1_PIN); + LedOff(LED2_PORT, LED2_PIN); + + /* Enable PWR Clock */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + DBG_ConfigPeriph(DBG_IWDG_STOP, ENABLE); + + SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); + /* Setup SysTick Timer for 1 msec interrupts */ + if (SysTick_Config(SystemCoreClock / 1000)) + { + /* Capture error */ + while (1) + ; + } + + /* Check if the system has resumed from IWDG reset */ + if (RCC_GetFlagStatus(RCC_CTRLSTS_FLAG_IWDGRSTF) != RESET) + { + /* IWDGRST flag set, Turn on LED1*/ + LedOn(LED1_PORT, LED1_PIN); + log_info("reset by IWDG\n"); + + /* Clear reset flags */ + RCC_ClrFlag(); + } + else + { + /* IWDGRST flag is not set, Turn off LED1*/ + LedOff(LED1_PORT, LED1_PIN); + } + + /* Enable write access to IWDG_PR and IWDG_RLR registers */ + IWDG_WriteConfig(IWDG_WRITE_ENABLE); + + /* IWDG counter clock: LSI/128 */ + IWDG_SetPrescalerDiv(IWDG_PRESCALER_DIV128); + + /* Set counter reload value to obtain 300ms IWDG TimeOut.*/ + IWDG_CntReload(75); + + /* Reload IWDG counter */ + IWDG_ReloadKey(); + + /* Enable IWDG (the LSI oscillator will be enabled by hardware) */ + IWDG_Enable(); + + while (1) + { + /* Toggle LED2 */ + LedBlink(LED2_PORT, LED2_PIN); + /* Insert long delay */ + Delay(250); + + /* Reload IWDG counter */ + IWDG_ReloadKey(); + } +} + +/** + * @brief Inserts a delay time. + * @param nTime specifies the delay time length, in milliseconds. + */ +static void Delay(__IO uint32_t nTime) +{ + TimingDelay = nTime; + + while (TimingDelay != 0) + ; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/src/n32wb03x_it.c new file mode 100644 index 0000000..bb39a4d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/IWDG/IWDG_Reset/src/n32wb03x_it.c @@ -0,0 +1,137 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t TimingDelay; +__IO uint16_t IC1ReadValue1 = 0, IC1ReadValue2 = 0; +__IO uint16_t CaptureNumber = 0; +__IO uint32_t Capture = 0; +extern uint32_t LsiFreq; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + TimingDelay--; +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/******************************************************************************/ + + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/MDK-ARM/keyboard.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/MDK-ARM/keyboard.uvoptx new file mode 100644 index 0000000..7d8eb34 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/MDK-ARM/keyboard.uvoptx @@ -0,0 +1,398 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + UL2CM3 + -UAny -O198 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO23 -FD20000000 -FC4000 -FN1 -FF0N32WB03X -FS01000000 -FL080000 + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8009 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + ARMRTXEVENTFLAGS + -L70 -Z18 -C0 -M0 -T1 + + + 0 + DLGTARM + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0) + + + 0 + ARMDBGFLAGS + + + + 0 + DLGUARM + + + + + + + 0 + 1 + CRCValue + + + 1 + 1 + CRC16Value + + + 2 + 1 + IR + + + + 0 + + + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_keyscan.c + n32wb03x_keyscan.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + 4 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/MDK-ARM/keyboard.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/MDK-ARM/keyboard.uvprojx new file mode 100644 index 0000000..4809f78 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/MDK-ARM/keyboard.uvprojx @@ -0,0 +1,488 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + keyboard + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\keyboard.bin .\Objects\keyboard.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_keyscan.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_keyscan.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + + + + + <Project Info> + 0 + 1 + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/inc/main.h new file mode 100644 index 0000000..2484515 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/inc/main.h @@ -0,0 +1,175 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" +#include "log.h" +#include "string.h" +#define KEYSCAN_INFO_CHECK 2 +static const uint32_t keyscan_map[][KEYSCAN_INFO_CHECK] = +{ + 0x00,0x00, //NULL + 0x00000000,0x00000001, + 0x00000000,0x00000002, + 0x00000000,0x00000004, + 0x00000000,0x00000008, + 0x00000000,0x00000010, + 0x00000000,0x00000020, + 0x00000000,0x00000040, + 0x00000000,0x00000080, + 0x00000000,0x00000100, + 0x00000000,0x00000200, + 0x00000000,0x00000400, + 0x00000000,0x00000800, + 0x00000000,0x00001000, + 0x00000000,0x00002000, + 0x00000000,0x00004000, + 0x00000000,0x00010000, + 0x00000000,0x00020000, + 0x00000000,0x00040000, + 0x00000000,0x00080000, + 0x00000000,0x00100000, + 0x00000000,0x00200000, + 0x00000000,0x00400000, + 0x00000000,0x00800000, + 0x00000000,0x01000000, + 0x00000000,0x02000000, + 0x00000000,0x04000000, + 0x00000000,0x08000000, + 0x00000000,0x10000000, + 0x00000001,0x00000000, + 0x00000002,0x00000000, + 0x00000004,0x00000000, + 0x00000008,0x00000000, + 0x00000010,0x00000000, + 0x00000020,0x00000000, + 0x00000040,0x00000000, + 0x00000080,0x00000000, + 0x00010000,0x00000000, + 0x00020000,0x00000000, + 0x00040000,0x00000000, + 0x00080000,0x00000000, + 0x00100000,0x00000000, + 0x00200000,0x00000000, + 0x00400000,0x00000000, + 0x00800000,0x00000000, + + 0x00,0x00, //NULL + +}; + +enum KEY_NUM{ + KEYSCAN_NULL = 0, + + KEYSCAN_KEY1, + KEYSCAN_KEY2, + KEYSCAN_KEY3, + KEYSCAN_KEY4, + KEYSCAN_KEY5, + KEYSCAN_KEY6, + KEYSCAN_KEY7, + KEYSCAN_KEY8, + KEYSCAN_KEY9, + KEYSCAN_KEY10, + KEYSCAN_KEY11, + KEYSCAN_KEY12, + KEYSCAN_KEY13, + KEYSCAN_KEY14, + KEYSCAN_KEY15, + KEYSCAN_KEY16, + KEYSCAN_KEY17, + KEYSCAN_KEY18, + KEYSCAN_KEY19, + KEYSCAN_KEY20, + KEYSCAN_KEY21, + KEYSCAN_KEY22, + KEYSCAN_KEY23, + KEYSCAN_KEY24, + KEYSCAN_KEY25, + KEYSCAN_KEY26, + KEYSCAN_KEY27, + KEYSCAN_KEY28, + KEYSCAN_KEY29, + KEYSCAN_KEY30, + KEYSCAN_KEY31, + KEYSCAN_KEY32, + KEYSCAN_KEY33, + KEYSCAN_KEY34, + KEYSCAN_KEY35, + KEYSCAN_KEY36, + KEYSCAN_KEY37, + KEYSCAN_KEY38, + KEYSCAN_KEY39, + KEYSCAN_KEY40, + KEYSCAN_KEY41, + KEYSCAN_KEY42, + KEYSCAN_KEY43, + KEYSCAN_KEY44, + + KEYSCAN_KEY_MAX +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/inc/n32wb03x_it.h new file mode 100644 index 0000000..58aea54 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void LPUART1_2_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/readme.txt new file mode 100644 index 0000000..ca66707 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/readme.txt @@ -0,0 +1,22 @@ + +1. Function description + This is a sample to the hardware IRC module output NEC IR protocol. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. Clock source: + HSE=32M, HSI=64M, AHB=64M, APB1=32M, APB2=64M, ADC CLK=HSE/8, DMA CLK=64M + 2. Port configuration: + PB4 as the IRC tx pin. + + Instructions: + 1. Download after compiling and reset to rum the program, check the wave of PB4. + 2. We can connect the IR led board to PB4 than check the data receive from IR receiver. + 3. Or we can connect the logic analyzer to PB4 and check the wave it output. + +4. Matters needing attention + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/src/main.c new file mode 100644 index 0000000..3223651 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/src/main.c @@ -0,0 +1,187 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ +extern void system_delay_n_10us(uint32_t value); +void KEYSCAN_Configuration(uint8_t key_mask, uint8_t mode, uint8_t dts, uint8_t wts, bool int_en); +NVIC_InitType NVIC_InitStructure; +EXTI_InitType EXTI_InitStructure; +GPIO_InitType GPIO_InitStructure; +KEYSCAN_InitType KEYSCAN_InitStructure; +uint16_t key_receive = 0; + + +/** + * @brief Main program. + */ +int main(void) +{ + log_init(); + log_info("\nThis is KEYSCAN demo in 44 key mode with 8 GPIO!\n"); + log_info("Connect each other PA0, PA1, PA2, PA3, PA6, PB8, PB9, PB10,\n"); + log_info("Or connect one of then to GND or VCC as one key pressed. \n"); + log_info(" VCC\n"); + log_info("PA0-----------------------------------------------------------KEY_29-|--KEY_37--|\n"); + log_info("PA1---KEY_1---------------------------------------------------KEY_30-|--KEY_38--|\n"); + log_info("PA2---KEY_2---KEY_3-------------------------------------------KEY_31-|--KEY_39--|\n"); + log_info("PA3---KEY_4---KEY_5---KEY_6-----------------------------------KEY_32-|--KEY_40--|\n"); + log_info("PA6---KEY_7---KEY_8---KEY_9---KEY_10--------------------------KEY_33-|--KEY_41--|\n"); + log_info("PB10--KEY_11--KEY_12--KEY_13--KEY_14--KEY_15------------------KEY_34-|--KEY_42--|\n"); + log_info("PB8---KEY_16--KEY_17--KEY_18--KEY_19--KEY_20--KEY_21----------KEY_35-|--KEY_43--|\n"); + log_info("PB9---KEY_22--KEY_23--KEY_24--KEY_25--KEY_26--KEY_27--KEY_28--KEY_36-|--KEY_44--|\n"); + log_info(" GND \n"); + + KEYSCAN_Configuration(KEY_44,MODE_FIXED_INTV, DTS_10MS, WTS_0MS, INT_EN); + while (1) + { + if(key_receive) + { + log_info("Keyboard detect KEY_%d pressed.\n",key_receive); + key_receive = 0;// clear last key value + } + } +} + +/** + * @brief KEYSCAN Configuration + * @param @KEY_MASK : KEY_65, KEY_44, KEY_104 + * @param @KEY_MODE : MODE_FIXED_INTV, MODE_SW_TRIG, MODE_PRESS_TRIG, + * @param @KEY_DTS : DTS_10MS, DTS_20MS, DTS_40MS, DTS_80MS, DTS_160MS, DTS_320MS, DTS_640MS, DTS_640MS_2 + * @param @KEY_WTS : WTS_0MS, WTS_32MS, WTS_64MS, WTS_96MS, WTS_128MS, WTS_160MS, WTS_192MS, WTS_224MS + * @param @KEY_INT : INT_DIS, INT_EN + * @return Return value + * @note Note + */ +void KEYSCAN_Configuration(uint8_t key_mask, uint8_t mode, uint8_t dts, uint8_t wts, bool int_en) +{ + /* KEYSCAN CLK EN */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + RCC->LSCTRL |= RCC_LSCTRL_KEYSCANEN; + /* config GPIO */ + GPIO_InitStruct(&GPIO_InitStructure); + if(key_mask == KEY_65) + { + GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6; + } + else if(key_mask == KEY_44) + { + GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_6; + } + else + { + GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6; + } + + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_OD; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF5; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = 0; //deinit + if(key_mask == KEY_65 ||key_mask == KEY_44) + { + GPIO_InitStructure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10; + } + else + { + GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10; + } + + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_OD; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF5; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + /* config KEYSCAN */ + KEYSCAN_InitStructure.Mask = key_mask; + KEYSCAN_InitStructure.Mode = mode; + KEYSCAN_InitStructure.Wts = wts; + KEYSCAN_InitStructure.Dts = dts; + KEYSCAN_InitStructure.Int_en = int_en; + KEYSCAN_Init(&KEYSCAN_InitStructure); + /* config intterrupt */ + if(int_en) + { + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Line = EXTI_LINE13; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitPeripheral(&EXTI_InitStructure); + + + NVIC_DisableIRQ(KEYSCAN_IRQn); + /* Enable the KEYSCAN Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = KEYSCAN_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + NVIC_EnableIRQ(KEYSCAN_IRQn); + } + /* Enable KEYSCAN */ + KEYSCAN_Enable(ENABLE); +} + + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/src/n32wb03x_it.c new file mode 100644 index 0000000..ba63065 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/KEYSCAN/keyboard/src/n32wb03x_it.c @@ -0,0 +1,173 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/** + * @brief This function handles DMA interrupt request defined in main.h . + */ +void DMA_IRQ_HANDLER(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + + +void KEYSCAN_IRQHandler(void) +{ + uint32_t key_data[5] = {0}; + uint8_t num; + if(KEYSCAN_GetInterruptState() == SET) + { + KEYSCAN_ClearInterrupt(); + } + + if(EXTI_GetITStatus(EXTI_LINE13)) + { + EXTI_ClrITPendBit(EXTI_LINE13); + } + + KEYSCAN_ReadKeyData(key_data); + #if 0 + log_info("REG data: "); + log_info("0x%08x,", key_data[0]); + log_info("0x%08x,", key_data[1]); + log_info("0x%08x,", key_data[2]); + log_info("0x%08x,", key_data[3]); + log_info("0x%08x ", key_data[4]); + log_info("\r\n"); + #endif + + for(num = 1; num < KEYSCAN_KEY_MAX; num++) + { + if(memcmp(key_data,&keyscan_map[num][0],(KEYSCAN_INFO_CHECK<<2)) == 0) + { + break; + } + } + + if(num != KEYSCAN_KEY_MAX) + { + #if 1 + extern uint16_t key_receive ; + key_receive = num; + #else + log_info("Detect key %d Pressed!\r\n", num); + #endif + } +} +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvoptx new file mode 100644 index 0000000..b024476 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvoptx @@ -0,0 +1,367 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvprojx new file mode 100644 index 0000000..d9df6df --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvprojx @@ -0,0 +1,480 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + DMA_Interrupt + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\DMA_Interrupt.bin .\Objects\DMA_Interrupt.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/inc/main.h new file mode 100644 index 0000000..9efda75 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/inc/main.h @@ -0,0 +1,121 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _LPUART1_USART1_ + +#ifdef _LPUART1_USART1_ +#define LPUARTy LPUART1 +#define LPUARTy_CLK RCC_LPUART1CLK +#define LPUARTy_GPIO GPIOB +#define LPUARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTy_RxPin GPIO_PIN_2 +#define LPUARTy_TxPin GPIO_PIN_1 +#define LPUARTy_Rx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_Tx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_DAT_Base (LPUART1_BASE + 0x10) +#define LPUARTy_Tx_DMA_Channel DMA_CH1 +#define LPUARTy_Tx_DMA_FLAG DMA_FLAG_TC1 +#define LPUARTy_Rx_DMA_Channel DMA_CH2 +#define LPUARTy_Rx_DMA_FLAG DMA_FLAG_TC2 +#define LPUARTy_Tx_DMA_REMAP DMA_REMAP_LPUART_TX +#define LPUARTy_Rx_DMA_REMAP DMA_REMAP_LPUART_RX +#define LPUARTy_IRQn LPUART1_IRQn +#define LPUARTy_IRQHandler LPUART1_IRQHandler + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#define USARTz_DAT_Base (USART2_BASE + 0x04) +#define USARTz_Tx_DMA_Channel DMA_CH4 +#define USARTz_Tx_DMA_FLAG DMA_FLAG_TC4 +#define USARTz_Rx_DMA_Channel DMA_CH5 +#define USARTz_Rx_DMA_FLAG DMA_FLAG_TC5 +#define USARTz_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTz_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#endif + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(uint32_t LPUART_CLK_SRC); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +void DMA_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); +void Delay(__IO uint32_t nCount); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/inc/n32wb03x_it.h new file mode 100644 index 0000000..58aea54 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void LPUART1_2_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/readme.txt new file mode 100644 index 0000000..3d9b571 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/readme.txt @@ -0,0 +1,60 @@ + +1. Function description + + This test example demonstrates the basic communication between LPUART and USARTz via DMA (interrupt). + USARTz can be USART2. + First, DMA transfers the TxBuffer1 data to the LPUART send data register. After the transfer is completed, + a DMA interrupt is generated, and then the data is sent to USARTz. USARTz receives data, DMA moves data + from USARTz receive data register to RxBuffer2, and generates DMA interrupt after completion. + At the same time, DMA transfers TxBuffer2 data to the USARTz send data register, the transfer is completed + and a DMA interrupt is generated, and then the data is sent to LPUART. LPUART receives data, DMA moves data + from LPUART receive data register to RxBuffer1, and generates DMA interrupt after completion. + Finally, compare the two groups of receiving and sending data respectively, and store the comparison results + in the TransferStatus1 variable and the TransferStatus2 variable. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The LPUART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits (fixed) + -1 stop bit (fixed) + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + -DMA transmit mode and DMA receive mode enable + + The USART2 configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + -DMA transmit mode and DMA receive mode enable + + The USART pin connections are as follows: + -LPUART_Tx.PB1 <-------> USART2_Rx.PB5 + -LPUART_Rx.PB2 <-------> USART2_Tx.PB4 + + Log print: + - DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus1 and TransferStatus2 in turn, + PASSED means the test passed, FAILED means the test is abnormal + + +4. Matters needing attention + \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/src/main.c new file mode 100644 index 0000000..6468b6d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/src/main.c @@ -0,0 +1,344 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup LPUART_DMA_Interrupt + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1)) +#define TxBufferSize2 (countof(TxBuffer2)) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +LPUART_InitType LPUART_InitStructure; +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "LPUARTy DMA Interrupt: LPUARTy -> USARTz using DMA Tx and Rx Flag"; +uint8_t TxBuffer2[] = "LPUARTy DMA Interrupt: USARTz -> LPUARTy using DMA Tx and Rx Interrupt"; +uint8_t RxBuffer1[TxBufferSize2]; +uint8_t RxBuffer2[TxBufferSize1]; +__IO uint8_t RxCounter = 0x00; +uint8_t NbrOfDataToRead = TxBufferSize2; +uint32_t indexFlag = 0; +volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + printf("\n This is lpuart dma interrupt demo\r\n"); + + /* System Clocks Configuration */ + RCC_Configuration(RCC_LPUARTCLK_SRC_APB1); + + /* NVIC configuration */ + NVIC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* Configure the DMA */ + DMA_Configuration(); + + /* LPUARTy and USARTz configuration ------------------------------------------------------*/ + + USART_DeInit(USARTz); + USART_InitStructure.BaudRate = 9600; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + /* Configure USARTz */ + USART_Init(USARTz, &USART_InitStructure); + /* Enable the USARTz */ + USART_Enable(USARTz, ENABLE); + + Delay(0x2FFFF); + + LPUART_DeInit(LPUARTy); + LPUART_InitStructure.BaudRate = 9600; + LPUART_InitStructure.Parity = LPUART_PE_NO; + LPUART_InitStructure.RtsThreshold = LPUART_RTSTH_FIFOFU; + LPUART_InitStructure.HardwareFlowControl = LPUART_HFCTRL_NONE; + LPUART_InitStructure.Mode = LPUART_MODE_RX | LPUART_MODE_TX; + /* Configure LPUARTy */ + LPUART_Init(LPUARTy, &LPUART_InitStructure); + + /* Flush LPUARTy RX FIFO */ + LPUART_FlushRxFifo(LPUARTy); + + /* Enable LPUARTy DMA Rx and TX request */ + LPUART_EnableDMA(LPUARTy, LPUART_DMAREQ_TX, ENABLE); + /* Enable USARTz DMA Rx and TX request */ + USART_EnableDMA(USARTz, USART_DMAREQ_TX, ENABLE); + + /* Enable the LPUARTy Receive Interrupt */ + LPUART_ConfigInt(LPUARTy, LPUART_INT_FIFO_NE, ENABLE); + + /* Enable LPUARTy TX DMA Channel */ + DMA_EnableChannel(LPUARTy_Tx_DMA_Channel, ENABLE); + /* Enable USARTz TX DMA Channel */ + DMA_EnableChannel(USARTz_Tx_DMA_Channel, ENABLE); + + /* Receive the TxBuffer2 */ + while (indexFlag < TxBufferSize1) + { + while (USART_GetFlagStatus(USARTz, USART_FLAG_RXDNE) == RESET) + { + } + RxBuffer2[indexFlag++] = USART_ReceiveData(USARTz); + } + + /* Wait until USARTz TX DMA Channel Transfer Complete */ + while (DMA_GetFlagStatus(USARTz_Tx_DMA_FLAG, DMA) == RESET) + { + } + + /* Wait until end of transmission from USARTz to LPUARTy */ + while (RxCounter < TxBufferSize2) + { + + } + + /* Check the received data with the send ones */ + TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); + /* TransferStatus1 = PASSED, if the data transmitted from USARTz and + received by LPUARTy are the same */ + /* TransferStatus1 = FAILED, if the data transmitted from USARTz and + received by LPUARTy are different */ + TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); + /* TransferStatus2 = PASSED, if the data transmitted from LPUARTy and + received by USARTz are the same */ + /* TransferStatus2 = FAILED, if the data transmitted from LPUARTy and + received by USARTz are different */ + + printf("test result TransferStatus1:%d, TransferStatus2:%d\r\n", TransferStatus1, TransferStatus2); + printf("RxBuffer1:%s\r\n", RxBuffer1); + printf("RxBuffer2:%s\r\n", RxBuffer2); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + * @param LPUART_CLK_SRC: specifies the LPUARTy clock source. + */ +void RCC_Configuration(uint32_t LPUART_CLK_SRC) +{ + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); + + switch(LPUART_CLK_SRC) + { + case RCC_LPUARTCLK_SRC_LSI_LSE: + { +#if 0 + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + /* Configures the External Low Speed oscillator (LSE) */ + RCC_ConfigLse(RCC_LSE_ENABLE); //32.768KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } +#else + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + RCC_EnableLsi(ENABLE); //32KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } +#endif + /* Specifies the LPUARTy clock source, LSE selected as LPUARTy clock */ + RCC_ConfigLpuartClk(LPUARTy_CLK, RCC_LPUARTCLK_SRC_LSI_LSE); + } + break; + + default: + { + /* Specifies the LPUARTy clock source, APB1 selected as LPUARTy clock */ + RCC_ConfigLpuartClk(LPUARTy_CLK, RCC_LPUARTCLK_SRC_APB1); + } + break; + } + + /* Enable LPUARTy Clock */ + RCC_EnableLpuartClk(ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(LPUARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure LPUARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = LPUARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LPUARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(LPUARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_TxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); + + /* Configure LPUARTy Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = LPUARTy_RxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = LPUARTy_Rx_GPIO_AF; + GPIO_InitPeripheral(LPUARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = USARTz_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the USARTz Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = LPUARTy_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + + /* LPUART_Tx_DMA_Channel (triggered by LPUART Tx event) Config */ + DMA_DeInit(LPUARTy_Tx_DMA_Channel); + DMA_InitStructure.PeriphAddr = LPUARTy_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)TxBuffer1; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = TxBufferSize1; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(LPUARTy_Tx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(LPUARTy_Tx_DMA_REMAP, DMA, LPUARTy_Tx_DMA_Channel, ENABLE); + + /* USARTz_Tx_DMA_Channel (triggered by USARTz Tx event) Config */ + DMA_DeInit(USARTz_Tx_DMA_Channel); + DMA_InitStructure.PeriphAddr = USARTz_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)TxBuffer2; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = TxBufferSize2; + DMA_Init(USARTz_Tx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(USARTz_Tx_DMA_REMAP, DMA, USARTz_Tx_DMA_Channel, ENABLE); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/src/n32wb03x_it.c new file mode 100644 index 0000000..0bfafb1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Interrupt/src/n32wb03x_it.c @@ -0,0 +1,143 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern uint8_t RxBuffer1[]; +extern uint8_t RxCounter; +extern uint8_t NbrOfDataToRead; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ +/** + * @brief This function handles USART2 global interrupt request. + */ +void LPUARTy_IRQHandler(void) +{ + if (LPUART_GetIntStatus(LPUARTy, LPUART_INT_FIFO_NE) != RESET) + { + /* Read one byte from the receive data register */ + RxBuffer1[RxCounter++] = LPUART_ReceiveData(LPUARTy); + + if (RxCounter == NbrOfDataToRead) + { + /* Disable the USART2 Receive interrupt */ + LPUART_ConfigInt(LPUARTy, LPUART_INT_FIFO_NE, DISABLE); + } + } +} + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/MDK-ARM/DMA_Polling.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/MDK-ARM/DMA_Polling.uvoptx new file mode 100644 index 0000000..b024476 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/MDK-ARM/DMA_Polling.uvoptx @@ -0,0 +1,367 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/MDK-ARM/DMA_Polling.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/MDK-ARM/DMA_Polling.uvprojx new file mode 100644 index 0000000..ea890f4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/MDK-ARM/DMA_Polling.uvprojx @@ -0,0 +1,480 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + DMA_Polling + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\DMA_Polling.bin .\Objects\DMA_Polling.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/inc/main.h new file mode 100644 index 0000000..b0e8220 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/inc/main.h @@ -0,0 +1,119 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _LPUART1_USART1_ + +#ifdef _LPUART1_USART1_ +#define LPUARTy LPUART1 +#define LPUARTy_CLK RCC_LPUART1CLK +#define LPUARTy_RCC_CLK RCC_APB1_PERIPH_LPUART1 +#define LPUARTy_GPIO GPIOB +#define LPUARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTy_RxPin GPIO_PIN_2 +#define LPUARTy_TxPin GPIO_PIN_1 +#define LPUARTy_Rx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_Tx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_DAT_Base (LPUART1_BASE + 0x10) +#define LPUARTy_Tx_DMA_Channel DMA_CH1 +#define LPUARTy_Tx_DMA_FLAG DMA_FLAG_TC1 +#define LPUARTy_Rx_DMA_Channel DMA_CH2 +#define LPUARTy_Rx_DMA_FLAG DMA_FLAG_TC2 +#define LPUARTy_Tx_DMA_REMAP DMA_REMAP_LPUART_TX +#define LPUARTy_Rx_DMA_REMAP DMA_REMAP_LPUART_RX + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#define USARTz_DAT_Base (USART2_BASE + 0x04) +#define USARTz_Tx_DMA_Channel DMA_CH4 +#define USARTz_Tx_DMA_FLAG DMA_FLAG_TC4 +#define USARTz_Rx_DMA_Channel DMA_CH5 +#define USARTz_Rx_DMA_FLAG DMA_FLAG_TC5 +#define USARTz_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTz_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#endif + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(uint32_t LPUART_CLK_SRC); +void GPIO_Configuration(void); +void DMA_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); +void Delay(__IO uint32_t nCount); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/readme.txt new file mode 100644 index 0000000..614d7cc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/readme.txt @@ -0,0 +1,54 @@ + +1. Function description + + This test example demonstrates the basic communication between LPUART and USARTz through DMA (query). USARTz can be USART2. + First, DMA transfers TxBuffer1 data to the LPUART send data register, and then the data is sent to USARTz. USARTz receives data, + and DMA moves the data from the USARTz receive data register to RxBuffer2. + Compare the received and sent data, and store the comparison result in the TransferStatus2 variable. + At the same time, DMA transfers TxBuffer2 data to the USARTz send data register, and then the data is sent to LPUART. LPUART + receives data, DMA moves data from LPUART receive data register to RxBuffer1. + Compare the received and sent data, and the comparison result is stored in the TransferStatus1 variable. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The LPUART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits (fixed) + -1 stop bit (fixed) + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + -DMA transmit mode and DMA receive mode enable + + The USART2 configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + -DMA transmit mode and DMA receive mode enable + + The USART pin connections are as follows: + -LPUART_Tx.PB1 <-------> USART2_Rx.PB5 + -LPUART_Rx.PB2 <-------> USART2_Tx.PB4 + + Log print: + - DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus1 and TransferStatus2 in turn, + PASSED means the test passed, FAILED means the test is abnormal + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/src/main.c new file mode 100644 index 0000000..6612846 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/src/main.c @@ -0,0 +1,343 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup LPUART_DMA_Polling + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1)) +#define TxBufferSize2 (countof(TxBuffer2)) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +LPUART_InitType LPUART_InitStructure; +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "LPUARTy DMA Polling: LPUARTy -> USARTz using DMA"; +uint8_t TxBuffer2[] = "LPUARTy DMA Polling: USARTz -> LPUARTy using DMA"; +uint8_t RxBuffer1[TxBufferSize2]; +uint8_t RxBuffer2[TxBufferSize1]; +volatile TestStatus TransferStatus1 = FAILED; +volatile TestStatus TransferStatus2 = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + printf("\n This is lpuart dma polling dmoe\r\n"); + + /* System Clocks Configuration */ + RCC_Configuration(RCC_LPUARTCLK_SRC_APB1); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* Configure the DMA */ + DMA_Configuration(); + + /* LPUARTy and USARTz configuration ------------------------------------------------------*/ + USART_DeInit(USARTz); + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + /* Configure USARTz */ + USART_Init(USARTz, &USART_InitStructure); + /* Enable the USARTz */ + USART_Enable(USARTz, ENABLE); + + Delay(0x2FFFF); + + LPUART_DeInit(LPUARTy); + LPUART_InitStructure.BaudRate = 115200; + LPUART_InitStructure.Parity = LPUART_PE_NO; + LPUART_InitStructure.RtsThreshold = LPUART_RTSTH_FIFOFU; + LPUART_InitStructure.HardwareFlowControl = LPUART_HFCTRL_NONE; + LPUART_InitStructure.Mode = LPUART_MODE_RX | LPUART_MODE_TX; + /* Configure LPUARTy */ + LPUART_Init(LPUARTy, &LPUART_InitStructure); + + /* Flush LPUARTy RX FIFO */ + LPUART_FlushRxFifo(LPUARTy); + + /* Enable LPUARTy DMA Rx and TX request */ + LPUART_EnableDMA(LPUARTy, LPUART_DMAREQ_RX | LPUART_DMAREQ_TX, ENABLE); + /* Enable USARTz DMA Rx and TX request */ + USART_EnableDMA(USARTz, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + /* Enable LPUARTy TX DMA Channel */ + DMA_EnableChannel(LPUARTy_Tx_DMA_Channel, ENABLE); + /* Enable LPUART RX DMA Channel */ + DMA_EnableChannel(LPUARTy_Rx_DMA_Channel, ENABLE); + + /* Enable USARTz TX DMA Channel */ + DMA_EnableChannel(USARTz_Tx_DMA_Channel, ENABLE); + /* Enable USARTz RX DMA Channel */ + DMA_EnableChannel(USARTz_Rx_DMA_Channel, ENABLE); + + /* Wait until LPUARTy TX DMA Channel Transfer Complete */ + while (DMA_GetFlagStatus(LPUARTy_Tx_DMA_FLAG, DMA) == RESET) + { + } + /* Wait until USARTz RX DMA Channel Receive Complete */ + while (DMA_GetFlagStatus(USARTz_Rx_DMA_FLAG, DMA) == RESET) + { + } + + /* Wait until USARTz TX DMA Channel Transfer Complete */ + while (DMA_GetFlagStatus(USARTz_Tx_DMA_FLAG, DMA) == RESET) + { + } + /* Wait until LPUARTy RX DMA Channel Receive Complete */ + while (DMA_GetFlagStatus(LPUARTy_Rx_DMA_FLAG, DMA) == RESET) + { + } + + /* Check the received data with the send ones */ + TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); + /* TransferStatus1 = PASSED, if the data transmitted from USARTz and + received by LPUARTy are the same */ + /* TransferStatus1 = FAILED, if the data transmitted from USARTz and + received by LPUARTy are different */ + TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); + /* TransferStatus2 = PASSED, if the data transmitted from LPUARTy and + received by USARTz are the same */ + /* TransferStatus2 = FAILED, if the data transmitted from LPUARTy and + received by USARTz are different */ + + printf("test result TransferStatus1:%d, TransferStatus2:%d\r\n", TransferStatus1, TransferStatus2); + printf("RxBuffer1:%s\r\n", RxBuffer1); + printf("RxBuffer2:%s\r\n", RxBuffer2); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + * @param LPUART_CLK_SRC: specifies the LPUARTy clock source. + */ +void RCC_Configuration(uint32_t LPUART_CLK_SRC) +{ + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); + + switch(LPUART_CLK_SRC) + { + case RCC_LPUARTCLK_SRC_LSI_LSE: + { +#if 0 + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + /* Configures the External Low Speed oscillator (LSE) */ + RCC_ConfigLse(RCC_LSE_ENABLE); //32.768KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } +#else + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + RCC_EnableLsi(ENABLE); //32KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } +#endif + /* Specifies the LPUARTy clock source, LSE selected as LPUARTy clock */ + RCC_ConfigLpuartClk(LPUARTy_CLK, RCC_LPUARTCLK_SRC_LSI_LSE); + } + break; + + default: + { + /* Specifies the LPUARTy clock source, APB1 selected as LPUARTy clock */ + RCC_ConfigLpuartClk(LPUARTy_CLK, RCC_LPUARTCLK_SRC_APB1); + } + break; + } + + /* Enable LPUARTy Clock */ + RCC_EnableLpuartClk(ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(LPUARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure LPUARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = LPUARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LPUARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(LPUARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_TxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); + + /* Configure LPUARTy Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = LPUARTy_RxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = LPUARTy_Rx_GPIO_AF; + GPIO_InitPeripheral(LPUARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = USARTz_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + + /* LPUARTy TX DMA Channel (triggered by LPUARTy Tx event) Config */ + DMA_DeInit(LPUARTy_Tx_DMA_Channel); + DMA_InitStructure.PeriphAddr = LPUARTy_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)TxBuffer1; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = TxBufferSize1; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(LPUARTy_Tx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(LPUARTy_Tx_DMA_REMAP, DMA, LPUARTy_Tx_DMA_Channel, ENABLE); + + /* LPUARTy RX DMA Channel (triggered by LPUARTy Rx event) Config */ + DMA_DeInit(LPUARTy_Rx_DMA_Channel); + DMA_InitStructure.PeriphAddr = LPUARTy_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)RxBuffer1; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = TxBufferSize2; + DMA_Init(LPUARTy_Rx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(LPUARTy_Rx_DMA_REMAP, DMA, LPUARTy_Rx_DMA_Channel, ENABLE); + + /* USARTx TX DMA Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTz_Tx_DMA_Channel); + DMA_InitStructure.PeriphAddr = USARTz_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)TxBuffer2; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = TxBufferSize2; + DMA_Init(USARTz_Tx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(USARTz_Tx_DMA_REMAP, DMA, USARTz_Tx_DMA_Channel, ENABLE); + + /* USARTx RX DMA Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTz_Rx_DMA_Channel); + DMA_InitStructure.PeriphAddr = USARTz_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)RxBuffer2; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = TxBufferSize1; + DMA_Init(USARTz_Rx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(USARTz_Rx_DMA_REMAP, DMA, USARTz_Rx_DMA_Channel, ENABLE); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/src/n32wb03x_it.c new file mode 100644 index 0000000..17d66e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/DMA_Polling/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvoptx new file mode 100644 index 0000000..ebf3e48 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvprojx new file mode 100644 index 0000000..7639458 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Receive_RTS + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Receive_RTS.bin .\Objects\Receive_RTS.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\inc;..\..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/inc/main.h new file mode 100644 index 0000000..dabb22a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/inc/main.h @@ -0,0 +1,97 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _LPUART1_COM_ + +#ifdef _LPUART1_COM_ +#define LPUARTz LPUART1 +#define LPUARTz_CLK RCC_LPUART1CLK +#define LPUARTz_GPIO GPIOB +#define LPUARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTz_RxPin GPIO_PIN_2 +#define LPUARTz_TxPin GPIO_PIN_1 +#define LPUARTz_RTSPin GPIO_PIN_0 +#define LPUARTz_CTSPin GPIO_PIN_3 +#define LPUARTz_Rx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTz_Tx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTz_RTS_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTz_CTS_GPIO_AF GPIO_AF4_LPUART1 +#endif + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(uint32_t LPUART_CLK_SRC); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); +void Delay(__IO uint32_t nCount); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/readme.txt new file mode 100644 index 0000000..a602d3d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/readme.txt @@ -0,0 +1,51 @@ + + +1. Function description + + This test example demonstrates the basic communication between LPUART of two demo board using hardware flow control. + First, Board1_LPUART uses CTS to send TxBuffer1 data, Board2_LPUART uses RTS to receive data and stores it in RxBuffer1; + Then, compare the received data with the sent data, and the comparison results are stored in the variables TransferStatus respectively. + Note: Board1_LPUART is example at LPUART\HardwareFlowCtrl_ok\Transmit_CTS + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + Board1_LPUART configuration is as follows: + -Baud rate = 9600 baud + -Word length = 8 data bits (fixed) + -1 stop bit (fixed) + -Verification control disabled + -CTS hardware flow control enable + -transmitter enable + + Board2_LPUART configuration is as follows: + -Baud rate = 9600 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -RTS hardware flow control enable) + -Receiver enable + + + The LPUART and USART pin connections are as follows: + - Board1_LPUART_Tx.PB1 <-------> Board2_LPUART_Rx.PB2 + - Board1_LPUART_CTS.PB3 <-------> Board2_LPUART_RTS.PB0 + + Log print: + - DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Test steps and phenomena: + -After the demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus in log, + PASSED(1) means the test passed, FAILED(0) means the test is abnormal + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/src/main.c new file mode 100644 index 0000000..e991272 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/src/main.c @@ -0,0 +1,222 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup LPUART_Receive_RTS + * @{ + */ + + +#define TxBufferSize1 (countof(TxBuffer1)) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +LPUART_InitType LPUART_InitStructure; +uint8_t TxBuffer1[] = "LPUART Flow_Control Mode Example: Board1_LPUARTy -> Board2_LPUARTz using CTS and RTS Flags"; +uint8_t RxBuffer1[TxBufferSize1]; +__IO uint8_t RxCounter = 0; +volatile TestStatus TransferStatus = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + printf("\n This is lpuart hardware FlowCtrl rx demo\r\n"); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* System Clocks Configuration */ + RCC_Configuration(RCC_LPUARTCLK_SRC_APB1); + + /* LPUARTz configuration ------------------------------------------------------*/ + LPUART_DeInit(LPUARTz); + LPUART_InitStructure.BaudRate = 9600; + LPUART_InitStructure.Parity = LPUART_PE_NO; + LPUART_InitStructure.RtsThreshold = LPUART_RTSTH_FIFOFU; + LPUART_InitStructure.HardwareFlowControl = LPUART_HFCTRL_RTS; + LPUART_InitStructure.Mode = LPUART_MODE_RX; + /* Configure LPUARTz */ + LPUART_Init(LPUARTz, &LPUART_InitStructure); + + while (RxCounter < TxBufferSize1) + { + /* Loop until the Board2_LPUARTz Receive Data Register is not empty */ + while (LPUART_GetFlagStatus(LPUARTz, LPUART_FLAG_FIFO_NE) == RESET) + { + } + + /* Store the received byte in RxBuffer */ + RxBuffer1[RxCounter++] = LPUART_ReceiveData(LPUARTz); + } + + /* Check the received data with the send ones */ + TransferStatus = Buffercmp(TxBuffer1, RxBuffer1, TxBufferSize1); + + printf("test result TransferStatus:%d\r\n", TransferStatus); + printf("RxBuffer1:%s\r\n", RxBuffer1); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + * @param LPUART_CLK_SRC: specifies the LPUARTz clock source. + */ +void RCC_Configuration(uint32_t LPUART_CLK_SRC) +{ + switch(LPUART_CLK_SRC) + { + case RCC_LPUARTCLK_SRC_LSI_LSE: + { +#if 0 + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + /* Configures the External Low Speed oscillator (LSE) */ + RCC_ConfigLse(RCC_LSE_ENABLE); //32.768KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } +#else + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + RCC_EnableLsi(ENABLE); //32KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } +#endif + /* Specifies the LPUARTz clock source, LSE selected as LPUARTz clock */ + RCC_ConfigLpuartClk(LPUARTz_CLK, RCC_LPUARTCLK_SRC_LSI_LSE); + } + break; + + default: + { + /* Specifies the LPUARTz clock source, APB1 selected as LPUARTz clock */ + RCC_ConfigLpuartClk(LPUARTz_CLK, RCC_LPUARTCLK_SRC_APB1); + } + break; + } + + /* Enable LPUARTz Clock */ + RCC_EnableLpuartClk(ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(LPUARTz_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure LPUARTz RTS as alternate function push-pull */ + GPIO_InitStructure.Pin = LPUARTz_RTSPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LPUARTz_RTS_GPIO_AF; + GPIO_InitPeripheral(LPUARTz_GPIO, &GPIO_InitStructure); + + /* Configure LPUARTz Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = LPUARTz_RxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = LPUARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(LPUARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/src/n32wb03x_it.c new file mode 100644 index 0000000..894a999 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Receive_RTS/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M4 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvoptx new file mode 100644 index 0000000..ebf3e48 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvprojx new file mode 100644 index 0000000..494c986 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Transmit_CTS + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Transmit_CTS.bin .\Objects\Transmit_CTS.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\inc;..\..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/inc/main.h new file mode 100644 index 0000000..9732e0f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/inc/main.h @@ -0,0 +1,95 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _LPUART1_COM_ + +#ifdef _LPUART1_COM_ +#define LPUARTy LPUART1 +#define LPUARTy_CLK RCC_LPUART1CLK +#define LPUARTy_GPIO GPIOB +#define LPUARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTy_RxPin GPIO_PIN_2 +#define LPUARTy_TxPin GPIO_PIN_1 +#define LPUARTy_RTSPin GPIO_PIN_0 +#define LPUARTy_CTSPin GPIO_PIN_3 +#define LPUARTy_Rx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_Tx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_RTS_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_CTS_GPIO_AF GPIO_AF4_LPUART1 +#endif + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(uint32_t LPUART_CLK_SRC); +void GPIO_Configuration(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/readme.txt new file mode 100644 index 0000000..8a79cdd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/readme.txt @@ -0,0 +1,50 @@ + +1. Function description + + This test example demonstrates the basic communication between LPUART of two demo board using hardware flow control. + First, Board1_LPUART uses CTS to send TxBuffer1 data, Board2_LPUART uses RTS to receive data and stores it in RxBuffer1; + Then, compare the received data with the sent data, and the comparison results are stored in the variables TransferStatus respectively. + Note: Board1_LPUART is example at LPUART\HardwareFlowCtrl_ok\Transmit_CTS + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + Board1_LPUART configuration is as follows: + -Baud rate = 9600 baud + -Word length = 8 data bits (fixed) + -1 stop bit (fixed) + -Verification control disabled + -CTS hardware flow control enable + -transmitter enable + + Board2_LPUART configuration is as follows: + -Baud rate = 9600 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -RTS hardware flow control enable) + -Receiver enable + + + The LPUART and USART pin connections are as follows: + - Board1_LPUART_Tx.PB1 <-------> Board2_LPUART_Rx.PB2 + - Board1_LPUART_CTS.PB3 <-------> Board2_LPUART_RTS.PB0 + + Log print: + - DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Test steps and phenomena: + -After the demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus in log, + PASSED(1) means the test passed, FAILED(0) means the test is abnormal + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/src/main.c new file mode 100644 index 0000000..24cab45 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/src/main.c @@ -0,0 +1,192 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup LPUART_Transmit_CTS + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1)) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +LPUART_InitType LPUART_InitStructure; +uint8_t TxBuffer1[] = "LPUART Flow_Control Mode Example: Board1_LPUARTy -> Board2_LPUARTz using CTS and RTS Flags"; +__IO uint8_t TxCounter = 0; + +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + printf("\n This is lpuart hardware FlowCtrl Tx demo\r\n"); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* System Clocks Configuration */ + RCC_Configuration(RCC_LPUARTCLK_SRC_APB1); + + /* LPUART configuration ------------------------------------------------------*/ + LPUART_DeInit(LPUARTy); + LPUART_InitStructure.BaudRate = 9600; + LPUART_InitStructure.Parity = LPUART_PE_NO; + LPUART_InitStructure.RtsThreshold = LPUART_RTSTH_FIFOFU; + LPUART_InitStructure.HardwareFlowControl = LPUART_HFCTRL_CTS; + LPUART_InitStructure.Mode = LPUART_MODE_TX; + /* Configure LPUART */ + LPUART_Init(LPUARTy, &LPUART_InitStructure); + + while (TxCounter < TxBufferSize1) + { + /* Send one byte from Board1_LPUART to Board2_LPUART */ + LPUART_SendData(LPUARTy, TxBuffer1[TxCounter++]); + /* Loop until Board1_LPUART DAT register is empty */ + while (LPUART_GetFlagStatus(LPUARTy, LPUART_FLAG_TXC) == RESET) + { + } + LPUART_ClrFlag(LPUARTy, LPUART_FLAG_TXC); + } + + printf("send finish\r\n"); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + * @param LPUART_CLK_SRC: specifies the LPUARTy clock source. + */ +void RCC_Configuration(uint32_t LPUART_CLK_SRC) +{ + switch(LPUART_CLK_SRC) + { + case RCC_LPUARTCLK_SRC_LSI_LSE: + { +#if 0 + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + /* Configures the External Low Speed oscillator (LSE) */ + RCC_ConfigLse(RCC_LSE_ENABLE); //32.768KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } +#else + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + RCC_EnableLsi(ENABLE); //32KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } +#endif + /* Specifies the LPUARTy clock source, LSE selected as LPUARTy clock */ + RCC_ConfigLpuartClk(LPUARTy_CLK, RCC_LPUARTCLK_SRC_LSI_LSE); + } + break; + + default: + { + /* Specifies the LPUARTy clock source, APB1 selected as LPUARTy clock */ + RCC_ConfigLpuartClk(LPUARTy_CLK, RCC_LPUARTCLK_SRC_APB1); + } + break; + } + + /* Enable LPUARTy Clock */ + RCC_EnableLpuartClk(ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(LPUARTy_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure LPUARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = LPUARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LPUARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(LPUARTy_GPIO, &GPIO_InitStructure); + + /* Configure LPUARTy CTS as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = LPUARTy_CTSPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = LPUARTy_CTS_GPIO_AF; + GPIO_InitPeripheral(LPUARTy_GPIO, &GPIO_InitStructure); +} + + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/src/n32wb03x_it.c new file mode 100644 index 0000000..894a999 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/HardwareFlowCtrl/Transmit_CTS/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M4 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/MDK-ARM/Interrupt.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/MDK-ARM/Interrupt.uvoptx new file mode 100644 index 0000000..cc6d601 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/MDK-ARM/Interrupt.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/MDK-ARM/Interrupt.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/MDK-ARM/Interrupt.uvprojx new file mode 100644 index 0000000..06e6f17 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/MDK-ARM/Interrupt.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Interrupt + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Interrupt.bin .\Objects\Interrupt.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/inc/main.h new file mode 100644 index 0000000..7b45dfe --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/inc/main.h @@ -0,0 +1,110 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _LPUART1_USART1_ + +#ifdef _LPUART1_USART1_ +#define LPUARTy LPUART1 +#define LPUARTy_CLK RCC_LPUART1CLK +#define LPUARTy_GPIO GPIOB +#define LPUARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTy_RxPin GPIO_PIN_2 +#define LPUARTy_TxPin GPIO_PIN_1 +#define LPUARTy_Rx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_Tx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_IRQn LPUART1_IRQn +#define LPUARTy_IRQHandler LPUART1_IRQHandler + + + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#define USARTz_IRQn USART2_IRQn +#define USARTz_IRQHandler USART2_IRQHandler +#endif + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(uint32_t LPUART_CLK_SRC); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); +void Delay(__IO uint32_t nCount); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/inc/n32wb03x_it.h new file mode 100644 index 0000000..1c54418 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/readme.txt new file mode 100644 index 0000000..7048195 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/readme.txt @@ -0,0 +1,53 @@ + + +1. Function description + + This test example demonstrates the basic communication between LPUART and USARTz through interrupts. + USARTz can be USART2. LPUART sends TxBuffer1 data to USARTz, and USARTz receives data to RxBuffer2. + At the same time, USARTz sends TxBuffer2 data to LPUART, and LPUART receives data to RxBuffer1. + Subsequently, the two groups of received data and sent data are compared respectively, and the comparison + results are stored in the TransferStatus1 variable and the TransferStatus2 variable. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The LPUART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits (fixed) + -1 stop bit (fixed) + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + + The USARTz configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + + The LPUART and USART pin connections are as follows: + - LPUART_Tx.PB1 <-------> USART1_Rx.PB5 + - LPUART_Rx.PB2 <-------> USART1_Tx.PB4 + + Log print: + - DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus1 and TransferStatus2 in turn, + PASSED means the test passed, FAILED means the test is abnormal + + +4. Matters needing attention + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/src/main.c new file mode 100644 index 0000000..338c75b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/src/main.c @@ -0,0 +1,303 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup LPUART_Interrupt + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1)) +#define TxBufferSize2 (countof(TxBuffer2)) +#define RxBufferSize1 TxBufferSize2 +#define RxBufferSize2 TxBufferSize1 + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +LPUART_InitType LPUART_InitStructure; +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "LPUARTy Interrupt Example: LPUARTy -> USARTz using Interrupt"; +uint8_t TxBuffer2[] = "LPUARTy Interrupt Example: USARTz -> LPUARTy using Interrupt"; +uint8_t RxBuffer1[RxBufferSize1]; +uint8_t RxBuffer2[RxBufferSize2]; +__IO uint8_t TxCounter1 = 0x00; +__IO uint8_t TxCounter2 = 0x00; +__IO uint8_t RxCounter1 = 0x00; +__IO uint8_t RxCounter2 = 0x00; +uint8_t NbrOfDataToTransfer1 = TxBufferSize1; +uint8_t NbrOfDataToTransfer2 = TxBufferSize2; +uint8_t NbrOfDataToRead1 = RxBufferSize1; +uint8_t NbrOfDataToRead2 = RxBufferSize2; +__IO TestStatus TransferStatus1 = FAILED; +__IO TestStatus TransferStatus2 = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + printf("\n This is lpuart interrupt dmoe\r\n"); + + /* System Clocks Configuration */ + RCC_Configuration(RCC_LPUARTCLK_SRC_APB1); + + /* NVIC configuration */ + NVIC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* LPUARTy and USARTz configuration ------------------------------------------------------*/ + + USART_DeInit(USARTz); + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + /* Configure USARTz */ + USART_Init(USARTz, &USART_InitStructure); + /* Enable the USARTz */ + USART_Enable(USARTz, ENABLE); + + LPUART_DeInit(LPUARTy); + LPUART_InitStructure.BaudRate = 115200; + LPUART_InitStructure.Parity = LPUART_PE_NO; + LPUART_InitStructure.RtsThreshold = LPUART_RTSTH_FIFOFU; + LPUART_InitStructure.HardwareFlowControl = LPUART_HFCTRL_NONE; + LPUART_InitStructure.Mode = LPUART_MODE_RX | LPUART_MODE_TX; + /* Configure LPUARTy */ + LPUART_Init(LPUARTy, &LPUART_InitStructure); + + /* Flush LPUARTy RX FIFO */ + LPUART_FlushRxFifo(LPUARTy); + + /* Enable LPUARTy Receive and Transmit interrupts */ + LPUART_ConfigInt(LPUARTy, LPUART_INT_FIFO_NE, ENABLE); + LPUART_ConfigInt(LPUARTy, LPUART_INT_TXC, ENABLE); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTz, USART_INT_RXDNE, ENABLE); + USART_ConfigInt(USARTz, USART_INT_TXDE, ENABLE); + + LPUART_SendData(LPUARTy, TxBuffer1[TxCounter1]); + /* Wait until end of transmission from LPUARTy to USARTz */ + while (RxCounter2 < RxBufferSize2) + { + } + + /* Wait until end of transmission from USARTz to LPUARTy */ + while (RxCounter1 < RxBufferSize1) + { + } + + /* Check the received data with the send ones */ + TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, RxBufferSize1); + /* TransferStatus1 = PASSED, if the data transmitted from USARTz and + received by LPUARTy are the same */ + /* TransferStatus1 = FAILED, if the data transmitted from USARTz and + received by LPUARTy are different */ + TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, RxBufferSize2); + /* TransferStatus2 = PASSED, if the data transmitted from LPUARTy and + received by USARTz are the same */ + /* TransferStatus2 = FAILED, if the data transmitted from LPUARTy and + received by USARTz are different */ + printf("test result TransferStatus1:%d, TransferStatus2:%d\r\n", TransferStatus1, TransferStatus2); + printf("RxBuffer1: %s\r\n", RxBuffer1); + printf("RxBuffer2: %s\r\n", RxBuffer2); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + * @param LPUART_CLK_SRC: specifies the LPUARTy clock source. + */ +void RCC_Configuration(uint32_t LPUART_CLK_SRC) +{ + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); + + switch(LPUART_CLK_SRC) + { + case RCC_LPUARTCLK_SRC_LSI_LSE: + { +#if 0 + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + /* Configures the External Low Speed oscillator (LSE) */ + RCC_ConfigLse(RCC_LSE_ENABLE); //32.768KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } +#else + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + RCC_EnableLsi(ENABLE); //32KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } +#endif + /* Specifies the LPUARTy clock source, LSE selected as LPUARTy clock */ + RCC_ConfigLpuartClk(LPUARTy_CLK, RCC_LPUARTCLK_SRC_LSI_LSE); + } + break; + + default: + { + /* Specifies the LPUARTy clock source, APB1 selected as LPUARTy clock */ + RCC_ConfigLpuartClk(LPUARTy_CLK, RCC_LPUARTCLK_SRC_APB1); + } + break; + } + + /* Enable LPUARTy Clock */ + RCC_EnableLpuartClk(ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(LPUARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure LPUARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = LPUARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LPUARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(LPUARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_TxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); + + /* Configure LPUARTy Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = LPUARTy_RxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = LPUARTy_Rx_GPIO_AF; + GPIO_InitPeripheral(LPUARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = USARTz_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the LPUART Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = LPUARTy_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + /* Enable the USARTz Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTz_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + + + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/src/n32wb03x_it.c new file mode 100644 index 0000000..fa840ee --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Interrupt/src/n32wb03x_it.c @@ -0,0 +1,193 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern uint8_t TxBuffer1[]; +extern uint8_t TxBuffer2[]; +extern uint8_t RxBuffer1[]; +extern uint8_t RxBuffer2[]; +extern __IO uint8_t TxCounter1; +extern __IO uint8_t TxCounter2; +extern __IO uint8_t RxCounter1; +extern __IO uint8_t RxCounter2; +extern uint8_t NbrOfDataToTransfer1; +extern uint8_t NbrOfDataToTransfer2; +extern uint8_t NbrOfDataToRead1; +extern uint8_t NbrOfDataToRead2; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles USARTy global interrupt request. + */ +void LPUARTy_IRQHandler(void) +{ + if (LPUART_GetIntStatus(LPUARTy, LPUART_INT_FIFO_NE) != RESET) + { + /* Read one byte from the receive data register */ + RxBuffer1[RxCounter1++] = LPUART_ReceiveData(LPUARTy); + + if (RxCounter1 == NbrOfDataToRead1) + { + /* Disable the LPUARTy Receive interrupt */ + LPUART_ConfigInt(LPUARTy, LPUART_INT_FIFO_NE, DISABLE); + } + } + + if (LPUART_GetIntStatus(LPUARTy, LPUART_INT_TXC) != RESET) + { + ++TxCounter1; + + /* Clear TXC Pending Bit */ + LPUART_ClrIntPendingBit(LPUARTy, LPUART_INT_TXC); + + /* Write one byte to the transmit data register */ + LPUART_SendData(LPUARTy, TxBuffer1[TxCounter1]); + + if (TxCounter1 == NbrOfDataToTransfer1) + { + /* Disable the LPUARTy Transmit interrupt */ + LPUART_ConfigInt(LPUARTy, LPUART_INT_TXC, DISABLE); + } + } +} + +/** + * @brief This function handles USARTz global interrupt request. + */ +void USARTz_IRQHandler(void) +{ + if (USART_GetIntStatus(USARTz, USART_INT_RXDNE) != RESET) + { + /* Read one byte from the receive data register */ + RxBuffer2[RxCounter2++] = USART_ReceiveData(USARTz); + + if (RxCounter2 == NbrOfDataToRead1) + { + /* Disable the USARTz Receive interrupt */ + USART_ConfigInt(USARTz, USART_INT_RXDNE, DISABLE); + } + } + + if (USART_GetIntStatus(USARTz, USART_INT_TXDE) != RESET) + { + /* Write one byte to the transmit data register */ + USART_SendData(USARTz, TxBuffer2[TxCounter2++]); + + if (TxCounter2 == NbrOfDataToTransfer2) + { + /* Disable the USARTz Transmit interrupt */ + USART_ConfigInt(USARTz, USART_INT_TXDE, DISABLE); + } + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/MDK-ARM/Polling.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/MDK-ARM/Polling.uvoptx new file mode 100644 index 0000000..cc6d601 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/MDK-ARM/Polling.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/MDK-ARM/Polling.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/MDK-ARM/Polling.uvprojx new file mode 100644 index 0000000..682c028 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/MDK-ARM/Polling.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Polling + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Polling.bin .\Objects\Polling.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/inc/main.h new file mode 100644 index 0000000..499ec12 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/inc/main.h @@ -0,0 +1,103 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _LPUART1_USART1_ + +#ifdef _LPUART1_USART1_ +#define LPUARTy LPUART1 +#define LPUARTy_CLK RCC_LPUART1CLK +#define LPUARTy_GPIO GPIOB +#define LPUARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTy_RxPin GPIO_PIN_2 +#define LPUARTy_TxPin GPIO_PIN_1 +#define LPUARTy_Rx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTy_Tx_GPIO_AF GPIO_AF4_LPUART1 + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#endif + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(uint32_t LPUART_CLK_SRC); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); +void Delay(__IO uint32_t nCount); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/readme.txt new file mode 100644 index 0000000..b949493 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/readme.txt @@ -0,0 +1,52 @@ + + +1. Function description + + This test example demonstrates the basic communication between LPUART and USARTz by querying the detection mark. + USARTz can be USART2.LPUART sends TxBuffer1 data to USARTz, and USARTz receives data to RxBuffer2. At the same time, + USARTz sends TxBuffer2 data to LPUART, and LPUART receives data to RxBuffer1. + Subsequently, the two groups of received data and sent data are compared respectively, and the comparison + results are stored in the TransferStatus1 variable and the TransferStatus2 variable. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The LPUART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits (fixed) + -1 stop bit (fixed) + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + + The USARTz configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + + The LPUART and USART pin connections are as follows: + - LPUART_Tx.PB1 <-------> USART1_Rx.PB5 + - LPUART_Rx.PB2 <-------> USART1_Tx.PB4 + + Log print: + - DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus1 and TransferStatus2 in turn, + PASSED means the test passed, FAILED means the test is abnormal + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/src/main.c new file mode 100644 index 0000000..e6bdf32 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/src/main.c @@ -0,0 +1,293 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup LPUART_Polling + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1)) +#define TxBufferSize2 (countof(TxBuffer2)) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +LPUART_InitType LPUART_InitStructure; +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "Buffer Send from LPUARTy to USARTz using Flags"; +uint8_t RxBuffer1[TxBufferSize1]; +uint8_t TxBuffer2[] = "Buffer Send from USARTz to LPUARTy using Flags"; +uint8_t RxBuffer2[TxBufferSize2]; +__IO uint8_t TxCounter = 0, RxCounter = 0; +volatile TestStatus TransferStatus = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + log_init(); + printf("\n this is lpuart polling demo\r\n"); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* System Clocks Configuration */ + RCC_Configuration(RCC_LPUARTCLK_SRC_APB1); + + /* LPUART and USARTz configuration ------------------------------------------------------*/ + USART_DeInit(USARTz); + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + /* Configure USARTz */ + USART_Init(USARTz, &USART_InitStructure); + /* Enable the USARTz */ + USART_Enable(USARTz, ENABLE); + + /* Wait for some delay */ + Delay(0x2FFFF); + + LPUART_DeInit(LPUARTy); + LPUART_InitStructure.BaudRate = 115200; + LPUART_InitStructure.Parity = LPUART_PE_NO; + LPUART_InitStructure.RtsThreshold = LPUART_RTSTH_FIFOFU; + LPUART_InitStructure.HardwareFlowControl = LPUART_HFCTRL_NONE; + LPUART_InitStructure.Mode = LPUART_MODE_RX | LPUART_MODE_TX; + /* Configure LPUART */ + LPUART_Init(LPUARTy, &LPUART_InitStructure); + + while (TxCounter < TxBufferSize1) + { + /* Send one byte from LPUART to USARTz */ + LPUART_SendData(LPUARTy, TxBuffer1[TxCounter++]); + + /* Loop until LPUART DAT register is empty */ + while (LPUART_GetFlagStatus(LPUARTy, LPUART_FLAG_TXC) == RESET) + { + } + LPUART_ClrFlag(LPUARTy, LPUART_FLAG_TXC); + + /* Loop until the USARTz Receive Data Register is not empty */ + while (USART_GetFlagStatus(USARTz, USART_FLAG_RXDNE) == RESET) + { + } + /* Store the received byte in RxBuffer */ + RxBuffer1[RxCounter++] = USART_ReceiveData(USARTz); + } + + /* Check the received data with the send ones */ + /* TransferStatus = PASSED, if the data transmitted from LPUART and + received by USARTz are the same */ + /* TransferStatus = FAILED, if the data transmitted from LPUART and + received by USARTz are different */ + TransferStatus = Buffercmp(TxBuffer1, RxBuffer1, TxBufferSize1); + printf("step 1 TransferStatus:%d\r\n", TransferStatus); + + TxCounter = 0; + RxCounter = 0; + TransferStatus = FAILED; + while (TxCounter < TxBufferSize1) + { + /* Send one byte from USARTz to LPUARTy */ + USART_SendData(USARTz, TxBuffer2[TxCounter++]); + /* Loop until USARTz DAT register is empty */ + while (USART_GetFlagStatus(USARTz, USART_FLAG_TXDE) == RESET) + { + } + + /* Loop until the LPUART Receive Data Register is not empty */ + while (LPUART_GetFlagStatus(LPUARTy, LPUART_FLAG_FIFO_NE) == RESET) + { + } + /* Store the received byte in RxBuffer */ + RxBuffer2[RxCounter++] = LPUART_ReceiveData(LPUARTy); + } + + /* Check the received data with the send ones */ + /* TransferStatus = PASSED, if the data transmitted from USARTz and + received by LPUART are the same */ + /* TransferStatus = FAILED, if the data transmitted from USARTz and + received by LPUART are different */ + TransferStatus = Buffercmp(TxBuffer2, RxBuffer2, TxBufferSize2); + + printf("step 2 TransferStatus:%d\r\n", TransferStatus); + + printf("RxBuffer1:%s\r\n", RxBuffer1); + printf("RxBuffer2:%s\r\n", RxBuffer2); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + * @param LPUART_CLK_SRC: specifies the LPUART clock source. + */ +void RCC_Configuration(uint32_t LPUART_CLK_SRC) +{ + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); + + switch(LPUART_CLK_SRC) + { + case RCC_LPUARTCLK_SRC_LSI_LSE: + { +#if 0 + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + /* Configures the External Low Speed oscillator (LSE) */ + RCC_ConfigLse(RCC_LSE_ENABLE); //32.768KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } +#else + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + RCC_EnableLsi(ENABLE); //32KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } +#endif + /* Specifies the LPUART clock source, LSE selected as LPUARTx clock */ + RCC_ConfigLpuartClk(LPUARTy_CLK, RCC_LPUARTCLK_SRC_LSI_LSE); + } + break; + + default: + { + /* Specifies the LPUART clock source, APB1 selected as LPUARTx clock */ + RCC_ConfigLpuartClk(LPUARTy_CLK, RCC_LPUARTCLK_SRC_APB1); + } + break; + } + + /* Enable LPUART Clock */ + RCC_EnableLpuartClk(ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(LPUARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure LPUARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = LPUARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LPUARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(LPUARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_TxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); + + /* Configure LPUARTy Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = LPUARTy_RxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = LPUARTy_Rx_GPIO_AF; + GPIO_InitPeripheral(LPUARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = USARTz_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/src/n32wb03x_it.c new file mode 100644 index 0000000..894a999 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Polling/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M4 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/MDK-ARM/Printf.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/MDK-ARM/Printf.uvoptx new file mode 100644 index 0000000..97d202d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/MDK-ARM/Printf.uvoptx @@ -0,0 +1,335 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/MDK-ARM/Printf.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/MDK-ARM/Printf.uvprojx new file mode 100644 index 0000000..a2ffb13 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/MDK-ARM/Printf.uvprojx @@ -0,0 +1,465 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Printf + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Printf.bin .\Objects\Printf.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/inc/main.h new file mode 100644 index 0000000..9cd9d43 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/inc/main.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _LPUART1_COM_ (0) + +#if (_LPUART1_COM_ == 0) +#define LPUARTx LPUART1 +#define LPUARTx_CLK RCC_LPUART1CLK +#define LPUARTx_GPIO GPIOB +#define LPUARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTx_RxPin GPIO_PIN_2 +#define LPUARTx_TxPin GPIO_PIN_1 +#define LPUARTx_Rx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTx_Tx_GPIO_AF GPIO_AF4_LPUART1 +#else +#define LPUARTx LPUART1 +#define LPUARTx_CLK RCC_LPUART1CLK +#define LPUARTx_GPIO GPIOB +#define LPUARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTx_RxPin GPIO_PIN_11 +#define LPUARTx_TxPin GPIO_PIN_12 +#define LPUARTx_Rx_GPIO_AF GPIO_AF2_LPUART1 +#define LPUARTx_Tx_GPIO_AF GPIO_AF2_LPUART1 +#endif + + + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(uint32_t LPUART_CLK_SRC); +void GPIO_Configuration(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/readme.txt new file mode 100644 index 0000000..0b65460 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/readme.txt @@ -0,0 +1,35 @@ + +1. Function description + + This test example demonstrates the basic communication between LPUART and PC by querying the detection mark. + Redirect the printf function to LPUART, and use the printf function to output messages to the terminal. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The LPUART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits (fixed) + -1 stop bit (fixed) + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + + The LPUART pin connections are as follows: + -LPUART_Tx.PB1 + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, view serial port print information + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/src/main.c new file mode 100644 index 0000000..676260a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/src/main.c @@ -0,0 +1,206 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup LPUART_Printf + * @{ + */ + +LPUART_InitType LPUART_InitStructure; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ +#if 0 + RCC_Configuration(RCC_LPUARTCLK_SRC_LSI_LSE); +#else + RCC_Configuration(RCC_LPUARTCLK_SRC_APB1); +#endif + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + LPUART_DeInit(LPUARTx); + /* LPUARTx configuration ------------------------------------------------------*/ + LPUART_InitStructure.BaudRate = 9600; + LPUART_InitStructure.Parity = LPUART_PE_NO; + LPUART_InitStructure.RtsThreshold = LPUART_RTSTH_FIFOFU; + LPUART_InitStructure.HardwareFlowControl = LPUART_HFCTRL_NONE; + LPUART_InitStructure.Mode = LPUART_MODE_RX | LPUART_MODE_TX; + /* Configure LPUARTx */ + LPUART_Init(LPUARTx, &LPUART_InitStructure); + + /* Output a message on Hyperterminal using printf function */ + printf("\n\rLPUART Printf Example: retarget the C library printf function to the LPUART mode:%d, src:0x%08x\n\r", _LPUART1_COM_, RCC_GetLpuartClkSrc(LPUARTx_CLK)); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + * @param LPUART_CLK_SRC: specifies the LPUARTx clock source. + */ +void RCC_Configuration(uint32_t LPUART_CLK_SRC) +{ + switch(LPUART_CLK_SRC) + { + case RCC_LPUARTCLK_SRC_LSI_LSE: + { +#if 0 + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + /* Configures the External Low Speed oscillator (LSE) */ + RCC_ConfigLse(RCC_LSE_ENABLE); //32.768KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } +#else + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + RCC_EnableLsi(ENABLE); //32KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } +#endif + /* Specifies the LPUARTx clock source, LSE selected as LPUARTx clock */ + RCC_ConfigLpuartClk(LPUARTx_CLK, RCC_LPUARTCLK_SRC_LSI_LSE); + } + break; + + default: + { + /* Specifies the LPUARTx clock source, APB1 selected as LPUARTx clock */ + RCC_ConfigLpuartClk(LPUARTx_CLK, RCC_LPUARTCLK_SRC_APB1); + } + break; + } + + /* Enable LPUARTx Clock */ + RCC_EnableLpuartClk(ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(LPUARTx_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure LPUARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = LPUARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LPUARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(LPUARTx_GPIO, &GPIO_InitStructure); + + /* Configure LPAURTx Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = LPUARTx_RxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = LPUARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(LPUARTx_GPIO, &GPIO_InitStructure); +} + +/* retarget the C library printf function to the LPUARTx */ +int fputc(int ch, FILE* f) +{ + LPUART_SendData(LPUARTx, (uint8_t)ch); + while (LPUART_GetFlagStatus(LPUARTx, LPUART_FLAG_TXC) == RESET) + ; + LPUART_ClrFlag(LPUARTx, LPUART_FLAG_TXC); + + return (ch); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/src/n32wb03x_it.c new file mode 100644 index 0000000..894a999 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/Printf/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M4 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/MDK-ARM/WakeUpFromStop.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/MDK-ARM/WakeUpFromStop.uvoptx new file mode 100644 index 0000000..fd0e78d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/MDK-ARM/WakeUpFromStop.uvoptx @@ -0,0 +1,347 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/MDK-ARM/WakeUpFromStop.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/MDK-ARM/WakeUpFromStop.uvprojx new file mode 100644 index 0000000..ea4239c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/MDK-ARM/WakeUpFromStop.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + WakeUpFromStop + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\WakeUpFromStop.bin .\Objects\WakeUpFromStop.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT, LSI_TRIM_32768HZ + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/inc/main.h new file mode 100644 index 0000000..de3b68a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/inc/main.h @@ -0,0 +1,97 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _LPUART1_COM_ (0) + +#if (_LPUART1_COM_ == 0) +#define LPUARTx LPUART1 +#define LPUARTx_CLK RCC_LPUART1CLK +#define LPUARTx_GPIO GPIOB +#define LPUARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTx_RxPin GPIO_PIN_2 +#define LPUARTx_TxPin GPIO_PIN_1 +#define LPUARTx_Rx_GPIO_AF GPIO_AF4_LPUART1 +#define LPUARTx_Tx_GPIO_AF GPIO_AF4_LPUART1 +#else +#define LPUARTx LPUART1 +#define LPUARTx_CLK RCC_LPUART1CLK +#define LPUARTx_GPIO GPIOB +#define LPUARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LPUARTx_RxPin GPIO_PIN_11 +#define LPUARTx_TxPin GPIO_PIN_12 +#define LPUARTx_Rx_GPIO_AF GPIO_AF2_LPUART1 +#define LPUARTx_Tx_GPIO_AF GPIO_AF2_LPUART1 +#endif + + +void RCC_Configuration(uint32_t LPUART_CLK_SRC); +void GPIO_Configuration(void); +void EXTI_Configuration(void); +void Delay(__IO uint32_t nCount); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/inc/n32wb03x_it.h new file mode 100644 index 0000000..28f5836 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void LPUART1_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/readme.txt new file mode 100644 index 0000000..7876975 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/readme.txt @@ -0,0 +1,48 @@ + +1. Function description + + This test example demonstrates how LPUART wakes up STOP mode through communication with PC. + The MCU enters the STOP mode, and the PC sends the correct data to wake up the MCU. When the correct wake-up event is recognized, the WUF interrupt will trigger and wake up the MCU. + In order to confirm whether to wake up, the MCU will send a confirmation message to the PC, and the PC will check whether it is the expected message. + The process will be repeated 4 times to verify different wake-up events: + 1 Start bit detection, such as sending wake-up data ‘5A’ (Hex) + 2 The receiving buffer is not empty detection, such as sending wake-up data ‘5A’ (Hex) + 3 One configurable receive byte, such as sending wake-up data ‘5A’ (Hex) + 4 One programmable 4-byte frame, such as sending wake-up data ‘4B3C2D1E’ (Hex) + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + -LPUART clock = LSE 32.768KHz + + The LPUART configuration is as follows: + -Baud rate = 9600 baud + -Word length = 8 data bits (fixed) + -1 stop bit (fixed) + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + + + The LPUART pin connections are as follows: + - LPUART_Tx.PB1 + - LPUART_Rx.PB2 + + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the serial port print information, send the corresponding character through the serial port, wake up the MCU, and again + Check the serial port print information (prompt "wake up"), this step needs to be repeated 4 times + + +4. Matters needing attention + Please make sure the J15 and J16 connect the pin to crystal not the pogo pin when select the LSE as clock of low speed clock. + If if need to use LSI as low speed clock and LPUART wake up, please trim the LSI to 32.768KHz. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/src/main.c new file mode 100644 index 0000000..a1ca393 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/src/main.c @@ -0,0 +1,422 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include +#include "string.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup LPUART_WakeUpFromStop + * @{ + */ + +LPUART_InitType LPUART_InitStructure; + +/* Buffer used for confirmation messages transmission */ +uint8_t TxBuffer1[] = "Start bit detection wake-up successful"; +uint8_t TxBuffer2[] = "RXNE detection wake-up successful"; +uint8_t TxBuffer3[] = "A configurable received byte match wake-up successful"; +uint8_t TxBuffer4[] = "A programmed 4-Byte frame match wake-up successful"; +uint32_t WakeUpTrigger[] = {0x5A, 0x1E2D3C4B}; + +uint8_t RxIndex = 0; +uint8_t RxBuffer[32] = {0}; + +/** + * @brief Main program + */ +int main(void) +{ + /* please reset for next flash, and you have do flash it bfore the MCU into sleep mode*/ + uint32_t dealy = 0x1E84800/2; + while(dealy--){} //delay few secoonds for SWD + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* System Clocks Configuration */ + RCC_Configuration(RCC_LPUARTCLK_SRC_LSI_LSE); + + /* Configure EXTI Line 10 */ + EXTI_Configuration(); + + + /* LPUART configuration ------------------------------------------------------*/ + LPUART_DeInit(LPUARTx); + LPUART_InitStructure.BaudRate = 9600; + LPUART_InitStructure.Parity = LPUART_PE_NO; + LPUART_InitStructure.RtsThreshold = LPUART_RTSTH_FIFOFU; + LPUART_InitStructure.HardwareFlowControl = LPUART_HFCTRL_NONE; + LPUART_InitStructure.Mode = LPUART_MODE_RX | LPUART_MODE_TX; + + LPUART_ConfigInt(LPUARTx, LPUART_INT_FIFO_NE, ENABLE); + + /* Configure LPUARTx */ + LPUART_Init(LPUARTx, &LPUART_InitStructure); + + /*##-1- Wake Up second step ###############################################*/ + printf("\n\r##-1-Start Bit Detection Wake-Up##\n\r"); + /* Set the Wake-Up Event: specify wake-up on start bit */ + LPUART_ConfigWakeUpMethod(LPUARTx, LPUART_WUSTP_STARTBIT); + /* Enable the LPUARTx Wake UP from STOP Mode Interrupt */ + LPUART_ConfigInt(LPUARTx, LPUART_INT_WUF, ENABLE); + /* Enable MCU Wake-up by LPUARTx */ + LPUART_EnableWakeUpStop(LPUARTx, ENABLE); + + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + /* Enter STOP Mode */ + PWR_EnterSLEEPMode(PWR_SLEEPENTRY_WFI); + /* ... STOP Mode ... */ + /* Wake Up based on Start Bit Detection successful */ + LPUART_EnableWakeUpStop(LPUARTx, DISABLE); + /* Output a message on Hyperterminal using printf function */ + printf("\n\rStart bit detection wake-up successful\n\r"); + + /*##-2- Wake Up second step ###############################################*/ + printf("\n\r##-2-RXNE Detection Wake-Up##\n\r"); + /* Set the Wake-Up Event: specify wake-up on RXNE flag */ + LPUART_ConfigWakeUpMethod(LPUARTx, LPUART_WUSTP_RXNE); + /* Enable the LPUART Wake UP from STOP Mode Interrupt */ + LPUART_ConfigInt(LPUARTx, LPUART_INT_WUF, ENABLE); + /* Enable MCU Wake-Up by LPUARTx */ + LPUART_EnableWakeUpStop(LPUARTx, ENABLE); + + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + /* Enter STOP Mode */ + PWR_EnterSLEEPMode(PWR_SLEEPENTRY_WFI); + /* ... STOP Mode ... */ + /* Wake Up based on RXNE Detection successful */ + LPUART_EnableWakeUpStop(LPUARTx, DISABLE); + /* Output a message on Hyperterminal using printf function */ + printf("\n\rRXNE detection wake-up successful\n\r"); + + /*##-3- Wake Up second step ###############################################*/ + printf("\n\r##-3-A Configurable Received Byte Match Wake-Up##\n\r"); + /* Set the Wake-Up Event: specify wake-up on a configurable received byte match */ + LPUART_ConfigWakeUpMethod(LPUARTx, LPUART_WUSTP_BYTE); + /* Set the Wake-Up Data */ + WakeUpTrigger[0] = 0xAA; + LPUART_ConfigWakeUpData(LPUARTx, WakeUpTrigger[0]); + /* Enable the LPUARTx Wake UP from STOP mode Interrupt */ + LPUART_ConfigInt(LPUARTx, LPUART_INT_WUF, ENABLE); + /* Enable MCU Wake-Up by LPUARTx */ + LPUART_EnableWakeUpStop(LPUARTx, ENABLE); + + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + /* Enter STOP Mode */ + PWR_EnterSLEEPMode(PWR_SLEEPENTRY_WFI); + /* ... STOP Mode ... */ + /* Wake Up based on a Configurable Received Byte Match successful */ + LPUART_EnableWakeUpStop(LPUARTx, DISABLE); + /* Output a message on Hyperterminal using printf function */ + printf("\n\rA configurable received byte match wake-up successful\n\r"); + + /*##-4- Wake Up second step ###############################################*/ + printf("\n\r##-4-A Programmed 4-Byte Frame Match Wake-Up##\n\r"); + /* Set the Wake-Up Event: specify wake-up on a programmed 4-Byte frame */ + LPUART_ConfigWakeUpMethod(LPUARTx, LPUART_WUSTP_FRAME); + /* Set the Wake-Up Data */ + WakeUpTrigger[1] = 0x1E2D3C4B; + LPUART_ConfigWakeUpData(LPUARTx, WakeUpTrigger[1]); + /* Enable the LPUARTx Wake UP from STOP mode Interrupt */ + LPUART_ConfigInt(LPUARTx, LPUART_INT_WUF, ENABLE); + /* Enable MCU Wake-Up by LPUARTx */ + LPUART_EnableWakeUpStop(LPUARTx, ENABLE); + + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + /* Enter STOP Mode */ + PWR_EnterSLEEPMode(PWR_SLEEPENTRY_WFI); + /* ... STOP Mode ... */ + /* Wake Up based on a Programmed 4-Byte Frame Match successful */ + LPUART_EnableWakeUpStop(LPUARTx, DISABLE); + /* Output a message on Hyperterminal using printf function */ + printf("\n\rA programmed 4-Byte frame match wake-up successful\n\r"); + +} + +/** + * @brief Enable the lsi and calibration it. + * @param + */ +uint32_t calib_lsi_clk(void) +{ + extern void system_delay_n_10us(uint32_t value); +// const uint32_t g_lsi_20_syscle_cal_value = 20000; //32000 +// const uint32_t g_lsi_20_syscle_cal_value = 22222; //28800 + const uint32_t g_lsi_20_syscle_cal_value = 19531; //32768 + + const uint32_t g_lsi_accuracy = 0; + const uint32_t g_lsi_count_n_syscle = 20; + const uint32_t g_timeoutcnt = 1000; + uint32_t lsi_timeoutcnt = 0; + uint32_t min = 0; + uint32_t max = 2047; + uint32_t mid = (RCC->LSCTRL >> 8) & 0x7FF; + uint32_t delta = 0; + uint32_t tmp_trim ; + uint32_t temp; + uint32_t count_value = 0; + + RCC->OSCFCCR &= ~(0xFF<< 8); + RCC->OSCFCCR |= (g_lsi_count_n_syscle <<8); //write count n syscle + + do{ + temp = RCC->LSCTRL & (~(0x7FF << 8)); //32K TRIM 8-18 bit + RCC->LSCTRL = temp | (mid << 8); // clear and set TRIM value + RCC->OSCFCCR |= 0x1 ; //start lsi + + while(1) + { + system_delay_n_10us(1); + if((RCC->OSCFCSR & 0x01)) + { + break; + } + if(lsi_timeoutcnt++ > g_timeoutcnt) + { + return 0; + } + } + count_value = RCC->OSCFCLSICNT; //ready cnt value + + delta = abs(count_value - g_lsi_20_syscle_cal_value); + if(count_value >= g_lsi_20_syscle_cal_value) + { + min = mid; + } + else + { + max = mid; + } + tmp_trim = (min + max)/2; + if(tmp_trim == mid ) //0 and 127 if not used + { + break; + } + mid = tmp_trim; + }while(delta > g_lsi_accuracy); + + return count_value; +} +/** + * @brief Configures the different system clocks. + * @param LPUART_CLK_SRC: specifies the LPUARTx clock source. + */ +void RCC_Configuration(uint32_t LPUART_CLK_SRC) +{ + /* get trim value */ + trim_stored_t *p_trim = SystemTrimValueGet(); + switch(LPUART_CLK_SRC) + { + case RCC_LPUARTCLK_SRC_LSI_LSE: + { +#if 1 + /* Configures the External Low Speed oscillator (LSE) */ + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + RCC_ConfigLse(RCC_LSE_ENABLE); //32.768KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } +#else + //calibration LSI + calib_lsi_clk(); + + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + RCC_EnableLsi(ENABLE); //32.768KHz + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } +#endif + /* Specifies the LPUARTx clock source, LSE selected as LPUARTx clock */ + RCC_ConfigLpuartClk(LPUARTx_CLK, RCC_LPUARTCLK_SRC_LSI_LSE); + } + break; + + default: + { + /* Specifies the LPUARTx clock source, APB1 selected as LPUARTx clock */ + RCC_ConfigLpuartClk(LPUARTx_CLK, RCC_LPUARTCLK_SRC_APB1); + } + break; + } + + /* Enable LPUARTx Clock */ + RCC_EnableLpuartClk(ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(LPUARTx_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure LPUARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = LPUARTx_TxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = LPUARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(LPUARTx_GPIO, &GPIO_InitStructure); + + /* Configure LPAURTx Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = LPUARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = LPUARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(LPUARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the LPUARTx Wakeup Interrupt through EXTI line 10 */ + NVIC_InitStructure.NVIC_IRQChannel = LPUART1_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + /* Enable the NRST Wakeup Interrupt through EXTI line 12 */ + NVIC_InitStructure.NVIC_IRQChannel = EXTI4_12_IRQn; + NVIC_Init(&NVIC_InitStructure); +} + + +/** + * @brief Configure EXTI_LINE23 as EXTI_Line and set the Priority. + */ +void EXTI_Configuration(void) +{ + EXTI_InitType EXTI_InitStructure; + + /* Configure NVIC */ + NVIC_Configuration(); + + /* Enable the LPUARTx Wakeup Interrupt through EXTI line 10 */ + EXTI_InitStructure.EXTI_Line = EXTI_LINE10; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /* Enable the NRST Wakeup Interrupt through EXTI line 12 */ + EXTI_InitStructure.EXTI_Line = EXTI_LINE12; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); +} + +/** + * @brief Inserts a delay time. + * @param nCount specifies the delay time length. + */ +void Delay(__IO uint32_t nCount) +{ + /* Decrement nCount value */ + for (; nCount != 0; nCount--) + ; +} + +/* retarget the C library printf function to the LPUART */ +int fputc(int ch, FILE* f) +{ + LPUART_SendData(LPUARTx, (uint8_t)ch); + while (LPUART_GetFlagStatus(LPUARTx, LPUART_FLAG_TXC) == RESET) + ; + LPUART_ClrFlag(LPUARTx, LPUART_FLAG_TXC); + + return (ch); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/src/n32wb03x_it.c new file mode 100644 index 0000000..c187b2c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/LPUART/WakeUpFromStop/src/n32wb03x_it.c @@ -0,0 +1,153 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M4 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ +/** + * @brief This function handles External interrupt Line 0 request. + */ +extern uint8_t RxIndex; +extern uint8_t RxBuffer[32]; +void LPUART1_IRQHandler(void) +{ + /* Clear EXTI Line22 Pending Bit */ + if(LPUART1->STS&LPUART_FLAG_FIFO_NE) + { + RxBuffer[RxIndex++] = LPUART_ReceiveData(LPUART1); + LPUART_ClrIntPendingBit(LPUART1, LPUART_INT_FIFO_NE); + } +} + +void EXTI4_12_IRQHandler(void) +{ + if (RESET != EXTI_GetITStatus(EXTI_LINE10)) + { + EXTI_ClrITPendBit(EXTI_LINE10); + LPUART_ClrIntPendingBit(LPUART1, LPUART_INT_WUF); + } + + /* NRST Wakeup Interrupt through EXTI line 12 */ + if (RESET != EXTI_GetITStatus(EXTI_LINE12)) + { + NVIC_SystemReset(); + EXTI_ClrITPendBit(EXTI_LINE12); + } +} + + + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/MDK-ARM/NVIC_IRQ_Mask_Proj.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/MDK-ARM/NVIC_IRQ_Mask_Proj.uvoptx new file mode 100644 index 0000000..ef77871 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/MDK-ARM/NVIC_IRQ_Mask_Proj.uvoptx @@ -0,0 +1,367 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 5 + 11 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/MDK-ARM/NVIC_IRQ_Mask_Proj.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/MDK-ARM/NVIC_IRQ_Mask_Proj.uvprojx new file mode 100644 index 0000000..e0b7f84 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/MDK-ARM/NVIC_IRQ_Mask_Proj.uvprojx @@ -0,0 +1,480 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + NVIC_IRQ_Mask + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\NVIC_IRQ_Mask.bin .\Objects\NVIC_IRQ_Mask.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/inc/main.h new file mode 100644 index 0000000..f364273 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/inc/main.h @@ -0,0 +1,94 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" +#include "log.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define KEY_INPUT_PORT GPIOB +#define KEY_INPUT_PIN GPIO_PIN_1 +#define KEY_INPUT_EXTI_LINE EXTI_LINE1 +#define KEY_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY_INPUT_PIN_SOURCE GPIO_PIN_SOURCE1 +#define KEY_INPUT_IRQn EXTI0_1_IRQn + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/inc/n32wb03x_it.h new file mode 100644 index 0000000..e6b4dc3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void DebugMon_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/readme.txt new file mode 100644 index 0000000..d79af4d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/readme.txt @@ -0,0 +1,25 @@ + +1. Function description + + /* Briefly describe the project function */ + This routine configures and demonstrates the use of EXIT external interrupt and TIM timer interrupt + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + /* Describe related module configuration methods; for example: clock, I/O, etc. */ + SystemClock: HSI 64MHz + USART: TX - PB6, baud rate 115200 + EXIT: PB1 is floating input mode, external interrupt line - EXIT_LINE1, open external interrupt + TIM: prescale factor - (SystemClock/1200-1), period - (1200-1), enable timer interrupt + + /* Describe the test steps and phenomena of the Demo */ + 1. After compiling, download the program to reset and run; + 2. Check the serial port printing information, the timer interrupt information is printed every 1S, press the button to stop printing, press it again to continue printing, indicating that the program is running normally; + + +4. Matters needing attention diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/src/main.c new file mode 100644 index 0000000..ed3e7cb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/src/main.c @@ -0,0 +1,219 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include + +/** + * NVIC IRQ Mask + */ + + + + + +volatile uint8_t Key_Status = DISABLE; + +void TIM_Config(void); +void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin); + + +/** + * @brief Main program. + */ +int main(void) +{ + /* log Init */ + log_init(); + log_info("\r\nNVIC IRQ Mask \r\n"); + + KeyInputExtiInit(KEY_INPUT_PORT, KEY_INPUT_PIN); + /* TIM configuration -------------------------------------------------------*/ + TIM_Config(); + + while (1) + { + while (Key_Status == DISABLE) + { + } + log_info("Disable irq \r\n"); + /* This instruction raises the execution priority to 0. This prevents all + exceptions with configurable priority from activating, other than through + the HardFault fault escalation mechanism. */ + + __disable_irq(); + + Delay_ms(5000); //Delay some time + + log_info("enable irq \r\n"); + /* This instruction will allow all exceptions with configurable priority to + be activated. */ + __enable_irq(); + + Key_Status = DISABLE; + } +} + +/** + * @brief Configures the used Timers. + */ +void TIM_Config(void) +{ + TIM_TimeBaseInitType TIM_TimeBaseStructure; + OCInitType TIM_OCInitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Enable TIM3 clocks */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* TIM3 configuration */ + TIM_TimeBaseStructure.Period = 0x4AF; + TIM_TimeBaseStructure.Prescaler = ((SystemCoreClock / 1200) - 1); + TIM_TimeBaseStructure.ClkDiv = 0x0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + TIM_InitOcStruct(&TIM_OCInitStructure); + + /* Output Compare Timing Mode configuration: Channel1 */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_TIMING; + TIM_OCInitStructure.Pulse = 0x0; + TIM_InitOc1(TIM3, &TIM_OCInitStructure); + + /* Immediate load of TIM3 Precaler values */ + TIM_ConfigPrescaler(TIM3, ((SystemCoreClock / 1200) - 1), TIM_PSC_RELOAD_MODE_IMMEDIATE); + + /* Clear TIM3 update pending flags */ + TIM_ClearFlag(TIM3, TIM_FLAG_UPDATE); + + /* Enable the TIM3 Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + /* Enable TIM3 Update interrupts */ + TIM_ConfigInt(TIM3, TIM_INT_UPDATE, ENABLE); + + /* TIM3 enable counters */ + TIM_Enable(TIM3, ENABLE); +} + +/** + * @brief Configures key port. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + GPIO_InitStruct(&GPIO_InitStructure); + + /* Enable the GPIO Clock */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + + /*Configure the GPIO pin as input floating*/ + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + + /*Configure key EXTI Line to key input Pin*/ + GPIO_ConfigEXTILine(KEY_INPUT_PORT_SOURCE, KEY_INPUT_PIN_SOURCE); + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} +/** + * @} + */ + +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name +* line: assert_param error line source number + * @return None + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + {} +} + +/** + * @} + */ +#endif diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/src/n32wb03x_it.c new file mode 100644 index 0000000..b2e3664 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/NVIC/IRQ_Mask/src/n32wb03x_it.c @@ -0,0 +1,155 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +extern uint8_t Key_Status; +/** + * @brief This function handles EXTI Lines 0 interrupt request. + */ +void EXTI0_1_IRQHandler(void) +{ + if (EXTI_GetITStatus(KEY_INPUT_EXTI_LINE) != RESET) + { + if (Key_Status == ENABLE) + { + Key_Status = DISABLE; + } + else + { + Key_Status = ENABLE; + } + /* Clears the SEL Button EXTI line pending bits. */ + EXTI_ClrITPendBit(KEY_INPUT_EXTI_LINE); + } +} + +/** + * @brief This function handles TIM3 global interrupt request. + */ +void TIM3_IRQHandler(void) +{ + /* Clear TIM3 update interrupt */ + TIM_ClrIntPendingBit(TIM3, TIM_INT_UPDATE); + + /* TIM3 IRQHandler */ + log_info("TIM3 IRQHandler \r\n"); +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/MDK-ARM/PD.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/MDK-ARM/PD.uvoptx new file mode 100644 index 0000000..ac82fa2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/MDK-ARM/PD.uvoptx @@ -0,0 +1,347 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + FWIB + 0 + 0 + 0 + 0 + + 4 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 4 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/MDK-ARM/PD.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/MDK-ARM/PD.uvprojx new file mode 100644 index 0000000..d164e8b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/MDK-ARM/PD.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + PD + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\PD.bin .\Objects\PD.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + FWIB + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/inc/main.h new file mode 100644 index 0000000..7d5b38b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/inc/main.h @@ -0,0 +1,92 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 + +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +void LedInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module *GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/inc/n32wb03x_it.h new file mode 100644 index 0000000..725b2fc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __n32wb03x_IT_H__ +#define __n32wb03x_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __n32wb03x_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/readme.txt new file mode 100644 index 0000000..f633ccb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/readme.txt @@ -0,0 +1,21 @@ + +1. Function description + 1. Entry and wake-up exit of PD mode. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO: PB0, PA6 control LED1, LED2 + + Instructions: + After compiling under KEIL, it is burned to the evaluation board, and the ammeter is connected in series. After a while, the current becomes significantly smaller. Press the WAKEUP button and the current returns to mA level. After a while it drops to uA again. + The LED1(PB0) light on when in run mode, after a while it will trun of LED1 and enter PD mode, press the WAKEUP button will wake up and resrart to run, and light on LED1(PB0). + + +4. Matters needing attention + none diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/src/main.c new file mode 100644 index 0000000..5f424a7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/src/main.c @@ -0,0 +1,235 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include +#include "log.h" +/** @addtogroup PWR_PD + * @{ + */ + + +void delay(vu32 nCount); +void SYSCLKConfig_STOP(uint32_t RCC_PLLMULL); +void EXTI_Configuration(void); + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + LedInit(LED1_PORT, LED1_PIN); + + EXTI_Configuration(); + while (1) + { + LedOn(LED1_PORT, LED1_PIN); + delay(3000); + LedOff(LED1_PORT, LED1_PIN); + + //Enter shutdown + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + PWR_EnterPDMode(PWR_PDENTRY_WFI); + } +} + +void EXTI_Configuration(void) +{ + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Configure NVIC */ + NVIC_InitStructure.NVIC_IRQChannel = EXTI4_12_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + /* Enable the NRST Wakeup Interrupt through EXTI line 12 */ + EXTI_InitStructure.EXTI_Line = EXTI_LINE12; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @brief Delay function. + * @arg nCount + */ +void delay(vu32 nCount) +{ + vu32 index = 0; + for (index = (3400 * nCount); index != 0; index--) + { + } +} + +/** + * @brief Configures key GPIO. + * @param key Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + GPIO_InitStruct(&GPIO_InitStructure); + /* Enable the GPIO Clock */ + + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + + /*Configure the GPIO pin as input floating*/ + + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + + /*Configure key EXTI Line to key input Pin*/ + GPIO_ConfigEXTILine(GPIOA_PORT_SOURCE, GPIO_PIN_SOURCE0); + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = EXTI_LINE0; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + + NVIC_Init(&NVIC_InitStructure); +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/src/n32wb03x_it.c new file mode 100644 index 0000000..d58d430 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/PD/src/n32wb03x_it.c @@ -0,0 +1,144 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + + + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + + +/** + * @brief This function handles the PVD Output interrupt request defined in main.h . + */ + +void EXTI0_1_IRQHandler(void) +{ + if (EXTI_GetITStatus(EXTI_LINE0) != RESET) + { + EXTI_ClrITPendBit(EXTI_LINE0); + } +} + +void EXTI4_12_IRQHandler(void) +{ + /* NRST Wakeup Interrupt through EXTI line 12 */ + if (RESET != EXTI_GetITStatus(EXTI_LINE12)) + { + NVIC_SystemReset(); + EXTI_ClrITPendBit(EXTI_LINE12); + } +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/MDK-ARM/SLEEP.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/MDK-ARM/SLEEP.uvoptx new file mode 100644 index 0000000..57700d7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/MDK-ARM/SLEEP.uvoptx @@ -0,0 +1,347 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + FBLW + 0 + 0 + 0 + 0 + + 4 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 4 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/MDK-ARM/SLEEP.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/MDK-ARM/SLEEP.uvprojx new file mode 100644 index 0000000..c21f804 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/MDK-ARM/SLEEP.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + SLEEP + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\SLEEP.bin .\Objects\SLEEP.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + FBLW + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/inc/main.h new file mode 100644 index 0000000..d4a9ee7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/inc/main.h @@ -0,0 +1,103 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/*STB led pin define*/ +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +#if 1 +#define KEY_INPUT_PORT GPIOB +#define KEY_INPUT_PIN GPIO_PIN_1 +#define KEY_INPUT_EXTI_LINE EXTI_LINE1 +#define KEY_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY_INPUT_PIN_SOURCE GPIO_PIN_SOURCE1 +#define KEY_INPUT_IRQn EXTI0_1_IRQn +#else +#define KEY_INPUT_PORT GPIOB +#define KEY_INPUT_PIN GPIO_PIN_2 +#define KEY_INPUT_EXTI_LINE EXTI_LINE2 +#define KEY_INPUT_PORT_SOURCE GPIOB_PORT_SOURCE +#define KEY_INPUT_PIN_SOURCE GPIO_PIN_SOURCE2 +#define KEY_INPUT_IRQn EXTI2_3_IRQn +#endif + +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/inc/n32wb03x_it.h new file mode 100644 index 0000000..725b2fc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __n32wb03x_IT_H__ +#define __n32wb03x_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __n32wb03x_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/readme.txt new file mode 100644 index 0000000..fe83d06 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/readme.txt @@ -0,0 +1,22 @@ + +1. Function description + 1. Entry and wake-up exit of Sleep mode. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO: PB0, PA6 control LED1, LED2 + + Instructions: + After compiling under KEIL, it is burned to the evaluation board, and the ammeter is connected in series. After a while, the current becomes significantly smaller. Press the button1(PB1) and the current returns to mA level. After a while it drops to uA again. + The LED1(PB0) light on when in run mode, after a while it will trun of LED1 and enter PD mode, press the button1(PB1) will wake up from sleep and continue run the code, it will light on LED1(PB0) 3000ms and sleep again. + + +4. Matters needing attention + none diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/src/main.c new file mode 100644 index 0000000..dffed12 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/src/main.c @@ -0,0 +1,232 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include +#include "log.h" +/** @addtogroup PWR_SLEEP + * @{ + */ + + +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin); +void LEDInit(GPIO_Module* GPIOx, uint16_t Pin); +void LedOn(GPIO_Module* GPIOx, uint16_t Pin); +void LedOff(GPIO_Module* GPIOx, uint16_t Pin); +void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin); +void delay(vu32 nCount); + +/** + * @brief Main program. + */ +int main(void) +{ + LEDInit(LED1_PORT, LED1_PIN); + KeyInputExtiInit(KEY_INPUT_PORT, KEY_INPUT_PIN); + + while (1) + { + LedOn(LED1_PORT, LED1_PIN); + delay(3000); + LedOff(LED1_PORT, LED1_PIN); + + /* Enable PWR Clock */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + + //enter sleep + PWR_EnterSLEEPMode(PWR_SLEEPENTRY_WFI); + + //exit sleep + LEDInit(LED1_PORT, LED1_PIN); + KeyInputExtiInit(KEY_INPUT_PORT, KEY_INPUT_PIN); + } +} + +/** + * @brief Turns selected Led on. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOn(GPIO_Module *GPIOx, uint16_t Pin) +{ + GPIO_SetBits(GPIOx, Pin); +} + +/** + * @brief Turns selected Led Off. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_ResetBits(GPIOx, Pin); +} + +/** + * @brief Toggles the selected Led. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_TogglePin(GPIOx, Pin); +} + +/** + * @brief Configures LED GPIO. + * @param GPIOx x can be A to G to select the GPIO port. + * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LEDInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); +} + +void delay(vu32 nCount) +{ + vu32 index = 0; + for (index = (3400 * nCount); index != 0; index--) + { + } +} + +/** + * @brief Configures key GPIO. + * @param key Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_AFIO, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + } + else + { + return; + } + + /*Configure the GPIO pin as input floating*/ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } + + /*Configure key EXTI Line to key input Pin*/ + GPIO_ConfigEXTILine(KEY_INPUT_PORT_SOURCE, KEY_INPUT_PIN_SOURCE); + + /*Configure key EXTI line*/ + EXTI_InitStructure.EXTI_Line = KEY_INPUT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; // EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /*Set key input interrupt priority*/ + NVIC_InitStructure.NVIC_IRQChannel = KEY_INPUT_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + /* Enable the NRST Wakeup Interrupt through EXTI line 12 */ + EXTI_InitStructure.EXTI_Line = EXTI_LINE12; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /* Configure NVIC */ + NVIC_InitStructure.NVIC_IRQChannel = EXTI4_12_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/src/n32wb03x_it.c new file mode 100644 index 0000000..bf38f84 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/PWR/SLEEP/src/n32wb03x_it.c @@ -0,0 +1,153 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + + +/** + * @brief This function handles the PVD Output interrupt request defined in main.h . + */ + +void EXTI0_1_IRQHandler(void) +{ + if (EXTI_GetITStatus(EXTI_LINE1) != RESET) + { + /* Clear the Key Button EXTI line pending bit */ + EXTI_ClrITPendBit(EXTI_LINE1); + } +} + +void EXTI2_3_IRQHandler(void) +{ + if (EXTI_GetITStatus(EXTI_LINE2) != RESET) + { + /* Clear the Key Button EXTI line pending bit */ + EXTI_ClrITPendBit(EXTI_LINE2); + } +} + +void EXTI4_12_IRQHandler(void) +{ + /* NRST Wakeup Interrupt through EXTI line 12 */ + if (RESET != EXTI_GetITStatus(EXTI_LINE12)) + { + NVIC_SystemReset(); + EXTI_ClrITPendBit(EXTI_LINE12); + } +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/MDK-ARM/Alarm.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/MDK-ARM/Alarm.uvoptx new file mode 100644 index 0000000..ab052fb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/MDK-ARM/Alarm.uvoptx @@ -0,0 +1,487 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rtc.c + n32wb03x_rtc.c + 0 + 0 + + + 3 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_wwdg.c + n32wb03x_wwdg.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 19 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 20 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + LOG + 0 + 0 + 0 + 0 + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 22 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/MDK-ARM/Alarm.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/MDK-ARM/Alarm.uvprojx new file mode 100644 index 0000000..d989d03 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/MDK-ARM/Alarm.uvprojx @@ -0,0 +1,580 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Alarm + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Alarm.bin .\Objects\Alarm.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc;..\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_rtc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rtc.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_wwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_wwdg.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + LOG + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/inc/main.h new file mode 100644 index 0000000..97e294d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/inc/main.h @@ -0,0 +1,82 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void RTC_TimeShow(void); +void RTC_DateShow(void); +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/inc/n32wb03x_it.h new file mode 100644 index 0000000..1c54418 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/readme.txt new file mode 100644 index 0000000..946b1f0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/readme.txt @@ -0,0 +1,33 @@ + + +1. Function description + 1. Trigger the alarm interrupt by setting the alarm time. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + +3. Instructions for use + + System Configuration; + 1. RTC clock source: LSI + 2. Serial port configuration: + - Serial port is USART1 (TX: PB6 RX: PB7): + - Data bits: 8 + - Stop bit: 1 + - Parity: none + - Baud rate: 115200 + + + Instructions: + After compiling under KEIL, burn it to the evaluation board, power on, and the serial port will print out the time set by the alarm clock. + +4. Matters needing attention + none \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/src/main.c new file mode 100644 index 0000000..0688dc4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/src/main.c @@ -0,0 +1,493 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include +#include "log.h" +#include "n32wb03x_rtc.h" + +/** @addtogroup RTC_Calendar + * @{ + */ +RTC_DateType RTC_DateStructure; +RTC_DateType RTC_DateDefault; +RTC_TimeType RTC_TimeStructure; +RTC_TimeType RTC_TimeDefault; +RTC_InitType RTC_InitStructure; +RTC_AlarmType RTC_AlarmStructure; +RTC_AlarmType RTC_AlarmDefault; +uint32_t SynchPrediv, AsynchPrediv; + +void RTC_CLKSourceConfig(uint8_t ClkSrc); +ErrorStatus RTC_TimeRegulate(void); +ErrorStatus RTC_DateRegulate(void); +ErrorStatus RTC_AlarmRegulate(uint32_t RTC_Alarm); +void RTC_DateAndTimeDefaultVale(void); +static void RTC_PrescalerConfig(void); + +void RTC_TimeShow(void); +void RTC_DateShow(void); +void RTC_AlarmShow(uint8_t AlarmX); +void EXTI8_RTCAlarm_Configuration(FunctionalState Cmd); + +/** + * @brief Main program. + */ +int main(void) +{ + /* Initialize debug uart*/ + log_init(); + log_info("\r\nRTC Alarm demo\r\n"); + + /* RTC date time alarm default value*/ + RTC_DateAndTimeDefaultVale(); + + /* RTC clock source select 1:LSE 2:LSI*/ + RTC_CLKSourceConfig(2); + RTC_PrescalerConfig(); + + /* RTC date time and alarm regulate*/ + /* Disable the RTC Wakeup Interrupt and delay more than 100us before set data and time */ + RTC_ConfigInt(RTC_INT_WUT, DISABLE); + RTC_EnableWakeUp(DISABLE); + RTC_DateRegulate(); + RTC_TimeRegulate(); + + RTC_AlarmRegulate(RTC_A_ALARM); + EXTI8_RTCAlarm_Configuration(ENABLE); + + while (1); +} + +/** + * @brief RTC alarm config EXTI Interrupt. + * @param Cmd Interrupt enable or disable + */ +void EXTI8_RTCAlarm_Configuration(FunctionalState Cmd) +{ + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + EXTI_ClrITPendBit(EXTI_LINE8); + EXTI_InitStructure.EXTI_Line = EXTI_LINE8; +#ifdef __TEST_SEVONPEND_WFE_NVIC_DIS__ + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event; +#else + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; +#endif + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /* Enable the RTC Alarm Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = Cmd; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Display the current alarm time on the Hyperterminal. + * @param AlarmX ALARMA + */ +void RTC_AlarmShow(uint8_t AlarmX) +{ + /* Get the current Alarm */ + if (AlarmX == 0x01) + RTC_GetAlarm(RTC_FORMAT_BIN, RTC_A_ALARM, &RTC_AlarmStructure); + + printf("\n\r //=========== Current Alarm Display ==============// \n\r"); + printf("\n\r The current alarm is : %0.2d:%0.2d:%0.2d \n\r", + RTC_AlarmStructure.AlarmTime.Hours, + RTC_AlarmStructure.AlarmTime.Minutes, + RTC_AlarmStructure.AlarmTime.Seconds); +} +/** + * @brief Display the current Date on the Hyperterminal. + */ +void RTC_DateShow(void) +{ + /* Get the current Date */ + RTC_GetDate(RTC_FORMAT_BIN, &RTC_DateStructure); + log_info("\n\r //=========== Current Date Display ==============// \n\r"); + log_info("\n\r The current date (WeekDay-Date-Month-Year) is : %0.2d-%0.2d-%0.2d-%0.2d \n\r", + RTC_DateStructure.WeekDay, + RTC_DateStructure.Date, + RTC_DateStructure.Month, + RTC_DateStructure.Year); +} + +/** + * @brief Display the current time on the Hyperterminal. + */ +void RTC_TimeShow(void) +{ + /* Get the current Time and Date */ + RTC_GetTime(RTC_FORMAT_BIN, &RTC_TimeStructure); + log_info("\n\r //============ Current Time Display ===============// \n\r"); + log_info("\n\r The current time (Hour-Minute-Second) is : %0.2d:%0.2d:%0.2d \n\r", + RTC_TimeStructure.Hours, + RTC_TimeStructure.Minutes, + RTC_TimeStructure.Seconds); + /* Unfreeze the RTC DAT Register */ + (void)RTC->DATE; +} +/** + * @brief RTC initalize default value. + */ +void RTC_DateAndTimeDefaultVale(void) +{ // Date + RTC_DateDefault.WeekDay = 3; + RTC_DateDefault.Date = 20; + RTC_DateDefault.Month = 11; + RTC_DateDefault.Year = 19; + // Time + RTC_TimeDefault.H12 = RTC_AM_H12; + RTC_TimeDefault.Hours = 4; + RTC_TimeDefault.Minutes = 22; + RTC_TimeDefault.Seconds = 30; + + // Alarm + RTC_AlarmDefault.AlarmTime.H12 = RTC_AM_H12; + RTC_AlarmDefault.AlarmTime.Hours = 4; + RTC_AlarmDefault.AlarmTime.Minutes = 23; + RTC_AlarmDefault.AlarmTime.Seconds = 05; + RTC_AlarmDefault.DateWeekMode = RTC_ALARM_SEL_WEEKDAY_DATE; + // RTC_AlarmDefault.DateWeekValue = 0x31; + // RTC_AlarmDefault.AlarmMask = RTC_ALARMMASK_MINUTES; +} + +/** + * @brief RTC alarm regulate with the default value. + */ +ErrorStatus RTC_AlarmRegulate(uint32_t RTC_Alarm) +{ + uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF; + + /* Disable the AlarmX */ + RTC_EnableAlarm(RTC_Alarm, DISABLE); + + printf("\n\r //==============Alarm X Settings================// \n\r"); + RTC_AlarmStructure.AlarmTime.H12 = RTC_AM_H12; + RTC_TimeStructure.H12 = RTC_AM_H12; + + printf("\n\r Please Set Alarm Hours"); + tmp_hh = RTC_AlarmDefault.AlarmTime.Hours; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_AlarmStructure.AlarmTime.Hours = tmp_hh; + } + printf(": %0.2d\n\r", tmp_hh); + + printf("\n\r Please Set Alarm Minutes"); + tmp_mm = RTC_AlarmDefault.AlarmTime.Minutes; + if (tmp_mm == 0xff) + { + return ERROR; + } + else + { + RTC_AlarmStructure.AlarmTime.Minutes = tmp_mm; + } + printf(": %0.2d\n\r", tmp_mm); + + printf("\n\r Please Set Alarm Seconds"); + tmp_ss = RTC_AlarmDefault.AlarmTime.Seconds; + if (tmp_ss == 0xff) + { + return ERROR; + } + else + { + RTC_AlarmStructure.AlarmTime.Seconds = tmp_ss; + } + printf(": %0.2d\n\r", tmp_ss); + + /* Set the Alarm X */ + RTC_AlarmStructure.DateWeekValue = 0x31; + + RTC_AlarmStructure.DateWeekMode = RTC_AlarmDefault.DateWeekMode; + + RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_WEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES; + + /* Configure the RTC Alarm A register */ + RTC_SetAlarm(RTC_FORMAT_BIN, RTC_Alarm, &RTC_AlarmStructure); + printf("\n\r>> !! RTC Set Alarm_X success. !! <<\n\r"); + + if (RTC_Alarm == RTC_A_ALARM) + { + /* Enable the RTC Alarm A Interrupt */ + RTC_ConfigInt(RTC_INT_ALRA, ENABLE); + RTC_AlarmShow(1); + } + + /* Enable the alarm */ + RTC_EnableAlarm(RTC_Alarm, ENABLE); + + return SUCCESS; +} +/** + * @brief RTC date regulate with the default value. + */ +ErrorStatus RTC_DateRegulate(void) +{ + uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF; + log_info("\n\r //=============Date Settings================// \n\r"); + + log_info("\n\r Please Set WeekDay (01-07)"); + tmp_hh = RTC_DateDefault.WeekDay; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.WeekDay = tmp_hh; + } + log_info(": %0.2d\n\r", tmp_hh); + + tmp_hh = 0xFF; + log_info("\n\r Please Set Date (01-31)"); + tmp_hh = RTC_DateDefault.Date; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Date = tmp_hh; + } + log_info(": %0.2d\n\r", tmp_hh); + + log_info("\n\r Please Set Month (01-12)"); + tmp_mm = RTC_DateDefault.Month; + if (tmp_mm == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Month = tmp_mm; + } + log_info(": %0.2d\n\r", tmp_mm); + + log_info("\n\r Please Set Year (00-99)"); + tmp_ss = RTC_DateDefault.Year; + if (tmp_ss == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Year = tmp_ss; + } + log_info(": %0.2d\n\r", tmp_ss); + + /* Configure the RTC date register */ + if (RTC_SetDate(RTC_FORMAT_BIN, &RTC_DateStructure) == ERROR) + { + log_info("\n\r>> !! RTC Set Date failed. !! <<\n\r"); + return ERROR; + } + else + { + log_info("\n\r>> !! RTC Set Date success. !! <<\n\r"); + RTC_DateShow(); + return SUCCESS; + } +} +/** + * @brief RTC time regulate with the default value. + */ +ErrorStatus RTC_TimeRegulate(void) +{ + uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF; + log_info("\n\r //==============Time Settings=================// \n\r"); + + RTC_TimeStructure.H12 = RTC_TimeDefault.H12; + + log_info("\n\r Please Set Hours"); + tmp_hh = RTC_TimeDefault.Hours; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Hours = tmp_hh; + } + log_info(": %0.2d\n\r", tmp_hh); + + log_info("\n\r Please Set Minutes"); + tmp_mm = RTC_TimeDefault.Minutes; + if (tmp_mm == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Minutes = tmp_mm; + } + log_info(": %0.2d\n\r", tmp_mm); + + log_info("\n\r Please Set Seconds"); + tmp_ss = RTC_TimeDefault.Seconds; + if (tmp_ss == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Seconds = tmp_ss; + } + log_info(": %0.2d\n\r", tmp_ss); + + /* Configure the RTC time register */ + if (RTC_ConfigTime(RTC_FORMAT_BIN, &RTC_TimeStructure) == ERROR) + { + log_info("\n\r>> !! RTC Set Time failed. !! <<\n\r"); + return ERROR; + } + else + { + log_info("\n\r>> !! RTC Set Time success. !! <<\n\r"); + RTC_TimeShow(); + return SUCCESS; + } +} + +/** + * @brief RTC prescaler config. + */ +static void RTC_PrescalerConfig(void) +{ + /* Configure the RTC data register and RTC prescaler */ + RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; + RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; + RTC_InitStructure.RTC_HourFormat = RTC_24HOUR_FORMAT; + + /* Check on RTC init */ + if (RTC_Init(&RTC_InitStructure) == ERROR) + { + log_info("\r\n //******* RTC Prescaler Config failed **********//\r\n"); + } +} + +/** + * @brief Configures RTC. + * Configure the RTC peripheral by selecting the clock source + */ + +void RTC_CLKSourceConfig(uint8_t ClkSrc) +{ + assert_param(IS_CLKSRC_VALUE(ClkSrc)); + assert_param(IS_FLCFG_VALUE(FirstLastCfg)); + + /* Enable the PWR clock */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Disable RTC clock */ + RCC_EnableRtcClk(DISABLE); + + + if (ClkSrc == 0x01) + { + log_info("\r\n RTC_ClkSrc Is Set LSE! \r\n"); + +#if (_TEST_LSE_BYPASS_) + RCC_ConfigLse(RCC_LSE_BYPASS); +#else + RCC_ConfigLse(RCC_LSE_ENABLE); +#endif + + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } + + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + RCC_EnableLsi(DISABLE); + + SynchPrediv = 0xFF; // 32.768KHz + AsynchPrediv = 0x7F; // value range: 0-7F + } + else if (ClkSrc == 0x02) + { + log_info("\r\n RTC_ClkSrc Is Set LSI! \r\n"); + + RCC_EnableLsi(ENABLE); + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } + + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + + SynchPrediv = 0xFF; // 32.768KHz + AsynchPrediv = 0x7F; // value range: 0-7F + } + else + { + log_info("\r\n RTC_ClkSrc Value is error! \r\n"); + } + + /* Enable the RTC Clock */ + RCC_EnableRtcClk(ENABLE); + RTC_WaitForSynchro(); +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/src/n32wb03x_it.c new file mode 100644 index 0000000..413cffa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Alarm/src/n32wb03x_it.c @@ -0,0 +1,134 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + + +/** + * @brief This function handles the PVD Output interrupt request defined in main.h . + */ + +/** + * @brief This function handles RTC Alarms interrupt request. + */ +void RTC_IRQHandler(void) +{ + if (RTC_GetITStatus(RTC_INT_ALRA) != RESET) + { + RTC_TimeShow(); + RTC_ClrIntPendingBit(RTC_INT_ALRA); + EXTI_ClrITPendBit(EXTI_LINE8); + } +} +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/MDK-ARM/Calendar.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/MDK-ARM/Calendar.uvoptx new file mode 100644 index 0000000..784cbb6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/MDK-ARM/Calendar.uvoptx @@ -0,0 +1,379 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rtc.c + n32wb03x_rtc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 11 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + LOG + 0 + 0 + 0 + 0 + + 5 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 13 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/MDK-ARM/Calendar.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/MDK-ARM/Calendar.uvprojx new file mode 100644 index 0000000..6ba7138 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/MDK-ARM/Calendar.uvprojx @@ -0,0 +1,485 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Calendar + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Calendar.bin .\Objects\Calendar.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\bsp\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rtc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rtc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + LOG + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/inc/main.h new file mode 100644 index 0000000..97e294d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/inc/main.h @@ -0,0 +1,82 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void RTC_TimeShow(void); +void RTC_DateShow(void); +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/inc/n32wb03x_it.h new file mode 100644 index 0000000..43be6a8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void DebugMon_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void DMA1_Channel6_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/readme.txt new file mode 100644 index 0000000..b2f727b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/readme.txt @@ -0,0 +1,28 @@ + +1. Function description + 1. Trigger the calendar printout through the EXTI line. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + System Configuration; + 1. RTC clock source: LSI + 2. Interrupt: TIM3 Interrupt 1Hz + 3. Serial port configuration: + - Serial port is USART1 (TX: PB6 RX: PB7): + - Data bits: 8 + - Stop bit: 1 + - Parity: none + - Baud rate: 115200 + + + Instructions: + After compiling under KEIL and burning to the evaluation board. After power-on, the serial port will print the corresponding calendar time every 1S. + + +4. Matters needing attention + none diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/src/main.c new file mode 100644 index 0000000..3b9f339 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/src/main.c @@ -0,0 +1,397 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include +#include "log.h" +#include "n32wb03x_rtc.h" +#include "n32wb03x.h" +/** @addtogroup RTC_Calendar + * @{ + */ +RTC_DateType RTC_DateStructure; +RTC_DateType RTC_DateDefault; +RTC_TimeType RTC_TimeStructure; +RTC_TimeType RTC_TimeDefault; +RTC_InitType RTC_InitStructure; +RTC_AlarmType RTC_AlarmStructure; +uint32_t SynchPrediv, AsynchPrediv; + +void RTC_CLKSourceConfig(uint8_t ClkSrc); +ErrorStatus RTC_TimeRegulate(void); +ErrorStatus RTC_DateRegulate(void); +void RTC_DateAndTimeDefaultVale(void); +static void RTC_PrescalerConfig(void); +void TIM3_Configuration(void); +void RTC_TimeShow(void); +void RTC_DateShow(void); + +/** + * @brief Main program. + */ +int main(void) +{ + /* Initialize debug uart*/ + log_init(); + log_info("\r\nRTC calendar demo\r\n"); + + /* RTC date time alarm default value*/ + RTC_DateAndTimeDefaultVale(); + + /* RTC clock source select 1:LSE 2:LSI*/ + RTC_CLKSourceConfig(2); + RTC_PrescalerConfig(); + log_info("RTC configured...."); + + /* Adjust time by values entered by the user on the hyperterminal */ + /* Disable the RTC Wakeup Interrupt and delay more than 100us before set data and time */ + RTC_ConfigInt(RTC_INT_WUT, DISABLE); + RTC_EnableWakeUp(DISABLE); + RTC_DateRegulate(); + RTC_TimeRegulate(); + + /* Configure the tim3 to generate an Interrupt with a period of 1s*/ + TIM3_Configuration(); + + log_info("\r\n RTC Config end....\r\n\r\n\r\n\r\n\r\n\r\n\r\n"); + + while (1) + ; +} + +void TIM3_Configuration(void) +{ + TIM_TimeBaseInitType TIM_TimeBaseStructure; + NVIC_InitType NVIC_InitStructure; + uint16_t PrescalerValue = 0; + + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* Compute the prescaler value */ + PrescalerValue = (uint16_t) (SystemCoreClock / 1000) - 1; + + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 1000-1; + TIM_TimeBaseStructure.Prescaler = PrescalerValue; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* TIM3 enable update irq */ + TIM_ConfigInt(TIM3, TIM_INT_UPDATE, ENABLE); + + /* TIM3 enable counter */ + TIM_Enable(TIM3, ENABLE); + + /* Enable the TIM3 global Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Display the current Date on the Hyperterminal. + */ +void RTC_DateShow(void) +{ + /* Get the current Date */ + RTC_GetDate(RTC_FORMAT_BIN, &RTC_DateStructure); + log_info("\n\r //=========== Current Date Display ==============// \n\r"); + log_info("\n\r The current date (WeekDay-Date-Month-Year) is : %0.2d-%0.2d-%0.2d-%0.2d \n\r", + RTC_DateStructure.WeekDay, + RTC_DateStructure.Date, + RTC_DateStructure.Month, + RTC_DateStructure.Year); +} + +/** + * @brief Display the current time on the Hyperterminal. + */ +void RTC_TimeShow(void) +{ + /* Get the current Time and Date */ + RTC_GetTime(RTC_FORMAT_BIN, &RTC_TimeStructure); + log_info("\n\r //============ Current Time Display ===============// \n\r"); + log_info("\n\r The current time (Hour-Minute-Second) is : %0.2d:%0.2d:%0.2d \n\r", + RTC_TimeStructure.Hours, + RTC_TimeStructure.Minutes, + RTC_TimeStructure.Seconds); + /* Unfreeze the RTC DAT Register */ + (void)RTC->DATE; +} +/** + * @brief RTC initalize default value. + */ +void RTC_DateAndTimeDefaultVale(void) +{ // Date + RTC_DateDefault.WeekDay = 3; + RTC_DateDefault.Date = 20; + RTC_DateDefault.Month = 11; + RTC_DateDefault.Year = 19; + // Time + RTC_TimeDefault.H12 = RTC_AM_H12; + RTC_TimeDefault.Hours = 4; + RTC_TimeDefault.Minutes = 5; + RTC_TimeDefault.Seconds = 1; +} +/** + * @brief RTC date regulate with the default value. + */ +ErrorStatus RTC_DateRegulate(void) +{ + uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF; + log_info("\n\r //=============Date Settings================// \n\r"); + + log_info("\n\r Please Set WeekDay (01-07) \n\r"); + tmp_hh = RTC_DateDefault.WeekDay; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.WeekDay = tmp_hh; + } + log_info(": %0.2d\n\r", tmp_hh); + + tmp_hh = 0xFF; + log_info("\n\r Please Set Date (01-31) \n\r"); + tmp_hh = RTC_DateDefault.Date; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Date = tmp_hh; + } + log_info(": %0.2d\n\r", tmp_hh); + + log_info("\n\r Please Set Month (01-12)\n\r"); + tmp_mm = RTC_DateDefault.Month; + if (tmp_mm == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Month = tmp_mm; + } + log_info(": %0.2d\n\r", tmp_mm); + + log_info("\n\r Please Set Year (00-99)\n\r"); + tmp_ss = RTC_DateDefault.Year; + if (tmp_ss == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Year = tmp_ss; + } + log_info(": %0.2d\n\r", tmp_ss); + + /* Configure the RTC date register */ + if (RTC_SetDate(RTC_FORMAT_BIN, &RTC_DateStructure) == ERROR) + { + log_info("\n\r>> !! RTC Set Date failed. !! <<\n\r"); + return ERROR; + } + else + { + log_info("\n\r>> !! RTC Set Date success. !! <<\n\r"); + RTC_DateShow(); + return SUCCESS; + } +} +/** + * @brief RTC time regulate with the default value. + */ +ErrorStatus RTC_TimeRegulate(void) +{ + uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF; + log_info("\n\r //==============Time Settings=================// \n\r"); + + RTC_TimeStructure.H12 = RTC_TimeDefault.H12; + + log_info("\n\r Please Set Hours \n\r"); + tmp_hh = RTC_TimeDefault.Hours; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Hours = tmp_hh; + } + log_info(": %0.2d\n\r", tmp_hh); + + log_info("\n\r Please Set Minutes \n\r"); + tmp_mm = RTC_TimeDefault.Minutes; + if (tmp_mm == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Minutes = tmp_mm; + } + log_info(": %0.2d\n\r", tmp_mm); + + log_info("\n\r Please Set Seconds \n\r"); + tmp_ss = RTC_TimeDefault.Seconds; + if (tmp_ss == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Seconds = tmp_ss; + } + log_info(": %0.2d\n\r", tmp_ss); + + /* Configure the RTC time register */ + if (RTC_ConfigTime(RTC_FORMAT_BIN, &RTC_TimeStructure) == ERROR) + { + log_info("\n\r>> !! RTC Set Time failed. !! <<\n\r"); + return ERROR; + } + else + { + log_info("\n\r>> !! RTC Set Time success. !! <<\n\r"); + RTC_TimeShow(); + return SUCCESS; + } +} + +/** + * @brief RTC prescaler config. + */ +static void RTC_PrescalerConfig(void) +{ + /* Configure the RTC data register and RTC prescaler */ + RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; + RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; + RTC_InitStructure.RTC_HourFormat = RTC_24HOUR_FORMAT; + + /* Check on RTC init */ + if (RTC_Init(&RTC_InitStructure) == ERROR) + { + log_info("\r\n //******* RTC Prescaler Config failed **********// \r\n"); + } +} + +/** + * @brief Configures RTC. + * Configure the RTC peripheral by selecting the clock source + */ + +void RTC_CLKSourceConfig(uint8_t ClkSrc) +{ + assert_param(IS_CLKSRC_VALUE(ClkSrc)); + + /* Enable the PWR clock */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Disable RTC clock */ + RCC_EnableRtcClk(DISABLE); + + if (ClkSrc == 0x01) + { + log_info("\r\n RTC_ClkSrc Is Set LSE! \r\n"); + +#if (_TEST_LSE_BYPASS_) + RCC_ConfigLse(RCC_LSE_BYPASS); +#else + RCC_ConfigLse(RCC_LSE_ENABLE); +#endif + + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } + + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + RCC_EnableLsi(DISABLE); + + SynchPrediv = 0xFF; // 32.768KHz + AsynchPrediv = 0x7F; // value range: 0-7F + } + else if (ClkSrc == 0x02) + { + log_info("\r\n RTC_ClkSrc Is Set LSI! \r\n"); + + /* Enable the LSI OSC */ + RCC_EnableLsi(ENABLE); + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } + + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + + SynchPrediv = 0xFF; // 32.768KHz + AsynchPrediv = 0x7F; // value range: 0-7F + } + else + { + log_info("\r\n RTC_ClkSrc Value is error! \r\n"); + } + + /* Enable the RTC Clock */ + RCC_EnableRtcClk(ENABLE); + RTC_WaitForSynchro(); +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/src/n32wb03x_it.c new file mode 100644 index 0000000..67144e2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/Calendar/src/n32wb03x_it.c @@ -0,0 +1,148 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M4 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + + + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles Debug Monitor exception. + */ +void DebugMon_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/** + * @brief This function handles DMA interrupt request defined in main.h . + */ +void DMA_IRQ_HANDLER(void) +{ +} + +/** + * @brief This function handles TIM3 global interrupt request. + */ +void TIM3_IRQHandler(void) +{ + if (TIM_GetIntStatus(TIM3, TIM_INT_UPDATE) != RESET) + { + TIM_ClrIntPendingBit(TIM3, TIM_INT_UPDATE); + + RTC_TimeShow(); + RTC_DateShow(); + } +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/MDK-ARM/RtcAutoWakeUp.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/MDK-ARM/RtcAutoWakeUp.uvoptx new file mode 100644 index 0000000..bdd1c3d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/MDK-ARM/RtcAutoWakeUp.uvoptx @@ -0,0 +1,379 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rtc.c + n32wb03x_rtc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 11 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + LOG + 0 + 0 + 0 + 0 + + 5 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 13 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/MDK-ARM/RtcAutoWakeUp.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/MDK-ARM/RtcAutoWakeUp.uvprojx new file mode 100644 index 0000000..5b36e20 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/MDK-ARM/RtcAutoWakeUp.uvprojx @@ -0,0 +1,485 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + RtcAutoWakeUp + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\RtcAutoWakeUp.bin .\Objects\RtcAutoWakeUp.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\bsp\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_rtc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rtc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + LOG + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/inc/main.h new file mode 100644 index 0000000..97e294d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/inc/main.h @@ -0,0 +1,82 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void RTC_TimeShow(void); +void RTC_DateShow(void); +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/inc/n32wb03x_it.h new file mode 100644 index 0000000..1c54418 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/readme.txt new file mode 100644 index 0000000..64e85ac --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/readme.txt @@ -0,0 +1,27 @@ + +1. Function description + 1. Trigger the interrupt by setting the wake-up time. + 2. Configure the IO output through the wake-up flag bit + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + System Configuration; + 1. Periodic wake-up clock source: RTCCLK (1HZ) + 2. Serial port configuration: + - Serial port is USART1 (TX: PB6 RX: PB7): + - Data bits: 8 + - Stop bit: 1 + - Parity: none + - Baud rate: 115200 + + + Instructions: + 1. After compiling under KEIL, burn it to the evaluation board. After power-on, the serial port will print I am in rtc_wkup every 4s. + +4. Matters needing attention + none \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/src/main.c new file mode 100644 index 0000000..8ac106a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/src/main.c @@ -0,0 +1,420 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include +#include +#include "log.h" +#include "n32wb03x_rtc.h" +#include "n32wb03x.h" +/** @addtogroup RTC_Calendar + * @{ + */ +RTC_DateType RTC_DateStructure; +RTC_DateType RTC_DateDefault; +RTC_TimeType RTC_TimeStructure; +RTC_TimeType RTC_TimeDefault; +RTC_InitType RTC_InitStructure; +RTC_AlarmType RTC_AlarmStructure; +uint32_t SynchPrediv, AsynchPrediv; + +void RTC_CLKSourceConfig(uint8_t ClkSrc); +ErrorStatus RTC_TimeRegulate(void); +ErrorStatus RTC_DateRegulate(void); +void RTC_DateAndTimeDefaultVale(void); +static void RTC_PrescalerConfig(void); +void EXTI9_RTCWKUP_Configuration(FunctionalState Cmd); +void RTC_TimeShow(void); +void RTC_DateShow(void); +void WakeUpClockSelect(uint8_t WKUPClkSrcSel); + +/** + * @brief Main program. + */ +int main(void) +{ + /* Initialize debug uart*/ + log_init(); + log_info("\r\nRTC auto wake up demo\r\n"); + + /* RTC date time alarm default value*/ + RTC_DateAndTimeDefaultVale(); + + /* RTC clock source select 1:LSE 2:LSI*/ + RTC_CLKSourceConfig(2); + RTC_PrescalerConfig(); + log_info("\r\n RTC configured...."); + + /* Adjust time by values entered by the user on the hyperterminal */ + /* Disable the RTC Wakeup Interrupt and delay more than 100us before set data and time */ + RTC_ConfigInt(RTC_INT_WUT, DISABLE); + RTC_EnableWakeUp(DISABLE); + RTC_DateRegulate(); + RTC_TimeRegulate(); + + /* wake up clock select */ + WakeUpClockSelect(5); + + /* wake up timer value */ + RTC_EnableWakeUp(DISABLE); + RTC_SetWakeUpCounter(3); + + EXTI9_RTCWKUP_Configuration(ENABLE); + /* Enable the RTC Wakeup Interrupt */ + RTC_ConfigInt(RTC_INT_WUT, ENABLE); + + RTC_EnableWakeUp(ENABLE); + while (1) + { + + } +} +/** + * @brief Wake up clock config. + */ +void WakeUpClockSelect(uint8_t WKUPClkSrcSel) +{ + /* Configure the RTC WakeUp Clock source: CK_SPRE (1Hz) */ + if (WKUPClkSrcSel == 0x01) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_RTCCLK_DIV16); + else if (WKUPClkSrcSel == 0x02) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_RTCCLK_DIV8); + else if (WKUPClkSrcSel == 0x03) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_RTCCLK_DIV4); + else if (WKUPClkSrcSel == 0x04) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_RTCCLK_DIV2); + else if (WKUPClkSrcSel == 0x05) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_CK_SPRE_16BITS); + else if (WKUPClkSrcSel == 0x06) + RTC_ConfigWakeUpClock(RTC_WKUPCLK_CK_SPRE_17BITS); +} +/** + * @brief Config RTC wake up Interrupt. + */ +void EXTI9_RTCWKUP_Configuration(FunctionalState Cmd) +{ + EXTI_InitType EXTI_InitStructure; + NVIC_InitType NVIC_InitStructure; + + EXTI_ClrITPendBit(EXTI_LINE9); + EXTI_InitStructure.EXTI_Line = EXTI_LINE9; +#ifdef __TEST_SEVONPEND_WFE_NVIC_DIS__ + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event; +#else + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; +#endif + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); + + /* Enable the RTC WakeUp Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = Cmd; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Display the current Date on the Hyperterminal. + */ +void RTC_DateShow(void) +{ + /* Get the current Date */ + RTC_GetDate(RTC_FORMAT_BIN, &RTC_DateStructure); + log_info("\n\r //=========== Current Date Display ==============// \n\r"); + log_info("\n\r The current date (WeekDay-Date-Month-Year) is : %0.2d-%0.2d-%0.2d-%0.2d \n\r", + RTC_DateStructure.WeekDay, + RTC_DateStructure.Date, + RTC_DateStructure.Month, + RTC_DateStructure.Year); +} + +/** + * @brief Display the current time on the Hyperterminal. + */ +void RTC_TimeShow(void) +{ + /* Get the current Time and Date */ + RTC_GetTime(RTC_FORMAT_BIN, &RTC_TimeStructure); + log_info("\n\r //============ Current Time Display ===============// \n\r"); + log_info("\n\r The current time (Hour-Minute-Second) is : %0.2d:%0.2d:%0.2d \n\r", + RTC_TimeStructure.Hours, + RTC_TimeStructure.Minutes, + RTC_TimeStructure.Seconds); + /* Unfreeze the RTC DAT Register */ + (void)RTC->DATE; +} +/** + * @brief RTC initalize default value. + */ +void RTC_DateAndTimeDefaultVale(void) +{ + // Date + RTC_DateDefault.WeekDay = 3; + RTC_DateDefault.Date = 20; + RTC_DateDefault.Month = 11; + RTC_DateDefault.Year = 11; + // Time + RTC_TimeDefault.H12 = RTC_AM_H12; + RTC_TimeDefault.Hours = 4; + RTC_TimeDefault.Minutes = 5; + RTC_TimeDefault.Seconds = 1; +} +/** + * @brief RTC date regulate with the default value. + */ +ErrorStatus RTC_DateRegulate(void) +{ + uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF; + log_info("\n\r //=============Date Settings================// \n\r"); + + log_info("\n\r Please Set WeekDay (01-07) \n\r"); + tmp_hh = RTC_DateDefault.WeekDay; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.WeekDay = tmp_hh; + } + log_info(": %0.2d\n\r", tmp_hh); + + tmp_hh = 0xFF; + log_info("\n\r Please Set Date (01-31) \n\r"); + tmp_hh = RTC_DateDefault.Date; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Date = tmp_hh; + } + log_info(": %0.2d\n\r", tmp_hh); + + log_info("\n\r Please Set Month (01-12)\n\r"); + tmp_mm = RTC_DateDefault.Month; + if (tmp_mm == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Month = tmp_mm; + } + log_info(": %0.2d\n\r", tmp_mm); + + log_info("\n\r Please Set Year (00-99)\n\r"); + tmp_ss = RTC_DateDefault.Year; + if (tmp_ss == 0xff) + { + return ERROR; + } + else + { + RTC_DateStructure.Year = tmp_ss; + } + log_info(": %0.2d\n\r", tmp_ss); + + /* Configure the RTC date register */ + if (RTC_SetDate(RTC_FORMAT_BIN, &RTC_DateStructure) == ERROR) + { + log_info("\n\r>> !! RTC Set Date failed. !! <<\n\r"); + return ERROR; + } + else + { + log_info("\n\r>> !! RTC Set Date success. !! <<\n\r"); + RTC_DateShow(); + return SUCCESS; + } +} +/** + * @brief RTC time regulate with the default value. + */ +ErrorStatus RTC_TimeRegulate(void) +{ + uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF; + log_info("\n\r //==============Time Settings=================// \n\r"); + + RTC_TimeStructure.H12 = RTC_TimeDefault.H12; + + log_info("\n\r Please Set Hours \n\r"); + tmp_hh = RTC_TimeDefault.Hours; + if (tmp_hh == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Hours = tmp_hh; + } + log_info(": %0.2d\n\r", tmp_hh); + + log_info("\n\r Please Set Minutes \n\r"); + tmp_mm = RTC_TimeDefault.Minutes; + if (tmp_mm == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Minutes = tmp_mm; + } + log_info(": %0.2d\n\r", tmp_mm); + + log_info("\n\r Please Set Seconds \n\r"); + tmp_ss = RTC_TimeDefault.Seconds; + if (tmp_ss == 0xff) + { + return ERROR; + } + else + { + RTC_TimeStructure.Seconds = tmp_ss; + } + log_info(": %0.2d\n\r", tmp_ss); + + /* Configure the RTC time register */ + if (RTC_ConfigTime(RTC_FORMAT_BIN, &RTC_TimeStructure) == ERROR) + { + log_info("\n\r>> !! RTC Set Time failed. !! <<\n\r"); + return ERROR; + } + else + { + log_info("\n\r>> !! RTC Set Time success. !! <<\n\r"); + RTC_TimeShow(); + return SUCCESS; + } +} + +/** + * @brief RTC prescaler config. + */ +static void RTC_PrescalerConfig(void) +{ + /* Configure the RTC data register and RTC prescaler */ + RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; + RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; + RTC_InitStructure.RTC_HourFormat = RTC_24HOUR_FORMAT; + + /* Check on RTC init */ + if (RTC_Init(&RTC_InitStructure) == ERROR) + { + log_info("\r\n //******* RTC Prescaler Config failed **********// \r\n"); + } +} + +/** + * @brief Configures RTC. + * Configure the RTC peripheral by selecting the clock source + */ + +void RTC_CLKSourceConfig(uint8_t ClkSrc) +{ + assert_param(IS_CLKSRC_VALUE(ClkSrc)); + + /* Enable the PWR clock */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Disable RTC clock */ + RCC_EnableRtcClk(DISABLE); + + if (ClkSrc == 0x01) + { + log_info("\r\n RTC_ClkSrc Is Set LSE! \r\n"); + +#if (_TEST_LSE_BYPASS_) + RCC_ConfigLse(RCC_LSE_BYPASS); +#else + RCC_ConfigLse(RCC_LSE_ENABLE); +#endif + + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSERD) == RESET) + { + } + + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSE); + RCC_EnableLsi(DISABLE); + + SynchPrediv = 0xFF; // 32.768KHz + AsynchPrediv = 0x7F; // value range: 0-7F + } + else if (ClkSrc == 0x02) + { + log_info("\r\n RTC_ClkSrc Is Set LSI! \r\n"); + + RCC_EnableLsi(ENABLE); + while (RCC_GetFlagStatus(RCC_LSCTRL_FLAG_LSIRD) == RESET) + { + } + + RCC_ConfigLSXSEL(RCC_RTCCLK_SRC_LSI); + + SynchPrediv = 0xFF; // 32.768KHz + AsynchPrediv = 0x7F; // value range: 0-7F + } + else + { + log_info("\r\n RTC_ClkSrc Value is error! \r\n"); + } + + /* Enable the RTC Clock */ + RCC_EnableRtcClk(ENABLE); + RTC_WaitForSynchro(); +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/src/n32wb03x_it.c new file mode 100644 index 0000000..83fe7fe --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/RTC/RtcAutoWakeUp/src/n32wb03x_it.c @@ -0,0 +1,135 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" +#include "main.h" +#include "log.h" +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + + +/** + * @brief This function handles RTC WakeUp interrupt request. + */ + +void RTC_IRQHandler(void) +{ + if (RTC_GetITStatus(RTC_INT_WUT) != RESET) + { + printf("\r\n I am in rtc_wkup!!! \r\n"); + RTC_TimeShow(); + RTC_ClrIntPendingBit(RTC_INT_WUT); + EXTI_ClrITPendBit(EXTI_LINE9); + } +} +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/MDK-ARM/CRC.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/MDK-ARM/CRC.uvoptx new file mode 100644 index 0000000..b41e03e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/MDK-ARM/CRC.uvoptx @@ -0,0 +1,343 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/MDK-ARM/CRC.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/MDK-ARM/CRC.uvprojx new file mode 100644 index 0000000..9375a9e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/MDK-ARM/CRC.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + SPI_CRC + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\SPI_CRC.bin .\Objects\SPI_CRC.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/inc/main.h new file mode 100644 index 0000000..77e8e75 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/inc/main.h @@ -0,0 +1,64 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + + + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/readme.txt new file mode 100644 index 0000000..9adaf22 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/readme.txt @@ -0,0 +1,20 @@ + +1. Function description + 1. SPI sends and receives data for CRC check + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock: HSI 64MHz + 2. GPIO:SSPI1: SCK--PA1� MISO--PA3�MOSI--PA2, + SPI2: SCK--PB1� MISO--PB3�MOSI--PB2, + + Instructions: + 1. After compiling, download the program to reset and run; + 2. SPI1, SPI2 send and receive data at the same time, after the transmission is completed, send CRC data, check the data and CRC value, Check that the status of TransferStatus1 and TransferStatus2 is PASSED, and then check the CRC value; + +4. Matters needing attention + No \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/src/main.c new file mode 100644 index 0000000..c345b01 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/src/main.c @@ -0,0 +1,313 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup SPI_CRC + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +#define BufferSize 32 + +SPI_InitType SPI_InitStructure; +uint16_t SPI1_Buffer_Tx[BufferSize] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C, 0x0D0E, 0x0F10, + 0x1112, 0x1314, 0x1516, 0x1718, 0x191A, 0x1B1C, 0x1D1E, 0x1F20, + 0x2122, 0x2324, 0x2526, 0x2728, 0x292A, 0x2B2C, 0x2D2E, 0x2F30, + 0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C, 0x3D3E, 0x3F40}; +uint16_t SPI2_Buffer_Tx[BufferSize] = {0x5152, 0x5354, 0x5556, 0x5758, 0x595A, 0x5B5C, 0x5D5E, 0x5F60, + 0x6162, 0x6364, 0x6566, 0x6768, 0x696A, 0x6B6C, 0x6D6E, 0x6F70, + 0x7172, 0x7374, 0x7576, 0x7778, 0x797A, 0x7B7C, 0x7D7E, 0x7F80, + 0x8182, 0x8384, 0x8586, 0x8788, 0x898A, 0x8B8C, 0x8D8E, 0x8F90}; +uint16_t SPI1_Buffer_Rx[BufferSize], SPI2_Buffer_Rx[BufferSize]; +uint32_t TxIdx = 0, RxIdx = 0; +__IO uint16_t CRC1Value = 0, CRC2Value = 0; +volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); + +uint32_t sts; +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32l40x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32l40x.c file + */ + log_init(); + log_info("\n this is a SPI CRC Demo.\n"); + + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + /* SPI1 configuration ------------------------------------------------------*/ + SPI_I2S_DeInit(SPI1); + SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX; + SPI_InitStructure.SpiMode = SPI_MODE_MASTER; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_16BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_32; + SPI_InitStructure.FirstBit = SPI_FB_MSB; + SPI_InitStructure.CRCPoly = 7; + SPI_Init(SPI1, &SPI_InitStructure); + + /* SPI2 configuration ------------------------------------------------------*/ + SPI_I2S_DeInit(SPI2); + SPI_InitStructure.SpiMode = SPI_MODE_SLAVE; + SPI_Init(SPI2, &SPI_InitStructure); + + /* Enable SPI1 CRC calculation */ + SPI_EnableCalculateCrc(SPI1, ENABLE); + /* Enable SPI1 */ + SPI_Enable(SPI1, ENABLE); + + /* Enable SPI2 CRC calculation */ + SPI_EnableCalculateCrc(SPI2, ENABLE); + /* Enable SPI2 */ + SPI_Enable(SPI2, ENABLE); + + /* Transfer procedure */ + while (TxIdx < BufferSize - 1) + { + /* Wait for SPI1 Tx buffer empty */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_TE_FLAG) == RESET) + ; + /* Send SPI2 data */ + SPI_I2S_TransmitData(SPI2, SPI2_Buffer_Tx[TxIdx]); + /* Send SPI1 data */ + SPI_I2S_TransmitData(SPI1, SPI1_Buffer_Tx[TxIdx++]); + /* Wait for SPI2 data reception */ + while (SPI_I2S_GetStatus(SPI2, SPI_I2S_RNE_FLAG) == RESET) + ; + /* Read SPI2 received data */ + SPI2_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI2); + /* Wait for SPI1 data reception */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_RNE_FLAG) == RESET) + ; + /* Read SPI1 received data */ + SPI1_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI1); + } + + /* Wait for SPI1 Tx buffer empty */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_TE_FLAG) == RESET) + ; + /* Wait for SPI2 Tx buffer empty */ + while (SPI_I2S_GetStatus(SPI2, SPI_I2S_TE_FLAG) == RESET) + ; + + /* Send last SPI2_Buffer_Tx data */ + SPI_I2S_TransmitData(SPI2, SPI2_Buffer_Tx[TxIdx]); + /* Enable SPI2 CRC transmission */ + SPI_TransmitCrcNext(SPI2); + + /* Send last SPI1_Buffer_Tx data */ + SPI_I2S_TransmitData(SPI1, SPI1_Buffer_Tx[TxIdx]); + /* Enable SPI1 CRC transmission */ + SPI_TransmitCrcNext(SPI1); + + /* Wait for SPI1 last data reception */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_RNE_FLAG) == RESET) + ; + /* Read SPI1 last received data */ + SPI1_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI1); + /* Read SPI2 last received data */ + SPI2_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI2); + + /* Wait for SPI2 data reception: CRC transmitted by SPI1 */ + while (SPI_I2S_GetStatus(SPI2, SPI_I2S_RNE_FLAG) == RESET) + ; + /* Wait for SPI1 data reception: CRC transmitted by SPI2 */ + while (SPI_I2S_GetStatus(SPI1, SPI_I2S_RNE_FLAG) == RESET) + ; + + /* Check the received data with the send ones */ + TransferStatus1 = Buffercmp(SPI1_Buffer_Rx, SPI2_Buffer_Tx, BufferSize); + TransferStatus2 = Buffercmp(SPI2_Buffer_Rx, SPI1_Buffer_Tx, BufferSize); + /* TransferStatus1, TransferStatus2 = PASSED, if the data transmitted and received + are correct */ + /* TransferStatus1, TransferStatus2 = FAILED, if the data transmitted and received + are different */ + printf("data SPI1 TransferStatus1:%d, SPI2 TransferStatus2:%d\r\n", TransferStatus1, TransferStatus2); + + /* Test on the SPI1 CRC Error flag */ + if ((SPI_I2S_GetStatus(SPI1, SPI_CRCERR_FLAG)) == SET) + { + TransferStatus1 = FAILED; + } + + /* Test on the SPI2 CRC Error flag */ + if ((SPI_I2S_GetStatus(SPI2, SPI_CRCERR_FLAG)) == SET) + { + TransferStatus2 = FAILED; + } + + printf("CRC SPI1 TransferStatus1:%d, SPI2 TransferStatus2:%d\r\n", TransferStatus1, TransferStatus2); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks --------------------------------------------------*/ + /* GPIOA, GPIOB, AFIO clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* SPI1 Periph clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_SPI1 | RCC_APB2_PERIPH_SPI2, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure SPI1 pins: SCK, MISO and MOSI ---------------------------------*/ + /* Confugure SCK , MISO and MOSI pins as Alternate Function Push Pull */ + GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_SPI1; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + + /* Configure SPI2 pins: SCK, MISO and MOSI ---------------------------------*/ + GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_SPI2; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/src/n32wb03x_it.c new file mode 100644 index 0000000..cc356f6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/CRC/src/n32wb03x_it.c @@ -0,0 +1,120 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/MDK-ARM/FullDuplex_SoftNSS.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/MDK-ARM/FullDuplex_SoftNSS.uvoptx new file mode 100644 index 0000000..b41e03e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/MDK-ARM/FullDuplex_SoftNSS.uvoptx @@ -0,0 +1,343 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/MDK-ARM/FullDuplex_SoftNSS.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/MDK-ARM/FullDuplex_SoftNSS.uvprojx new file mode 100644 index 0000000..899a5b7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/MDK-ARM/FullDuplex_SoftNSS.uvprojx @@ -0,0 +1,470 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + FullDuplex + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\FullDuplex.bin .\Objects\FullDuplex.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/inc/main.h new file mode 100644 index 0000000..fd5d8d8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/inc/main.h @@ -0,0 +1,80 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + +#define SPIy SPI1 +#define SPIy_CLK RCC_APB2_PERIPH_SPI1 +#define SPIy_GPIO GPIOA +#define SPIy_GPIO_AF GPIO_AF1_SPI1 +#define SPIy_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define SPIy_PIN_SCK GPIO_PIN_1 +#define SPIy_PIN_MISO GPIO_PIN_3 +#define SPIy_PIN_MOSI GPIO_PIN_2 + +#define SPIz SPI2 +#define SPIz_CLK RCC_APB2_PERIPH_SPI2 +#define SPIz_GPIO GPIOB +#define SPIz_GPIO_AF GPIO_AF2_SPI2 +#define SPIz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define SPIz_PIN_SCK GPIO_PIN_1 +#define SPIz_PIN_MISO GPIO_PIN_3 +#define SPIz_PIN_MOSI GPIO_PIN_2 + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/readme.txt new file mode 100644 index 0000000..c38415a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + 1. SPI full duplex software NSS mode to send and receive data + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock:48MHz + 2. GPIO:SPI1: SCK--PA1�MISO--PA3�MOSI--PA2, + SPI2: SCK--PB1�MISO--PB3�MOSI--PB2, + + Instructions: + 1. After compiling, download the program to reset and run; + 2. SPI1 is initialized as a master, sending data, SPI2 is initialized as a slave, receiving data, + after the transmission is completed, check the data, and check that the status of TransferStatus1 + and TransferStatus2 is PASSED; SPI2 is initialized as a master, sending data, SPI1 is initialized + as a slave, receiving data, after the transmission is completed, check the data, and check that + the status of TransferStatus3 and TransferStatus4 is PASSED; + +4. Matters needing attention + No \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/src/main.c new file mode 100644 index 0000000..7797d6d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/src/main.c @@ -0,0 +1,309 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup FullDuplex_SoftNSS + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +#define BufferSize 32 + +SPI_InitType SPI_InitStructure; +uint8_t SPIy_Buffer_Tx[BufferSize] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20}; +uint8_t SPIz_Buffer_Tx[BufferSize] = {0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, + 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, + 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70}; +uint8_t SPIy_Buffer_Rx[BufferSize], SPIz_Buffer_Rx[BufferSize]; +__IO uint8_t TxIdx = 0, RxIdx = 0, k = 0; +volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; +volatile TestStatus TransferStatus3 = FAILED, TransferStatus4 = FAILED; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + + log_init(); + log_info("\n this is a SPI FullDuplex_SoftNSS Demo.\n"); + + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + + /* 1st phase: SPIy Master and SPIz Slave */ + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + /* SPIy Config -------------------------------------------------------------*/ + SPI_I2S_DeInit(SPIy); + SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX; + SPI_InitStructure.SpiMode = SPI_MODE_MASTER; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_8; + SPI_InitStructure.FirstBit = SPI_FB_LSB; + SPI_InitStructure.CRCPoly = 7; + SPI_Init(SPIy, &SPI_InitStructure); + + /* SPIz Config -------------------------D------------------------------------*/ + SPI_I2S_DeInit(SPIz); + SPI_InitStructure.SpiMode = SPI_MODE_SLAVE; + SPI_Init(SPIz, &SPI_InitStructure); + + /* Enable SPIy */ + SPI_Enable(SPIy, ENABLE); + /* Enable SPIz */ + SPI_Enable(SPIz, ENABLE); + + /* Transfer procedure */ + while (TxIdx < BufferSize) + { + /* Wait for SPIy Tx buffer empty */ + while (SPI_I2S_GetStatus(SPIy, SPI_I2S_TE_FLAG) == RESET) + ; + /* Send SPIz data */ + SPI_I2S_TransmitData(SPIz, SPIz_Buffer_Tx[TxIdx]); + /* Send SPIy data */ + SPI_I2S_TransmitData(SPIy, SPIy_Buffer_Tx[TxIdx++]); + /* Wait for SPIz data reception */ + while (SPI_I2S_GetStatus(SPIz, SPI_I2S_RNE_FLAG) == RESET) + ; + /* Read SPIz received data */ + SPIz_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPIz); + /* Wait for SPIy data reception */ + while (SPI_I2S_GetStatus(SPIy, SPI_I2S_RNE_FLAG) == RESET) + ; + /* Read SPIy received data */ + SPIy_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPIy); + } + + /* Check the correctness of written dada */ + TransferStatus1 = Buffercmp(SPIz_Buffer_Rx, SPIy_Buffer_Tx, BufferSize); + TransferStatus2 = Buffercmp(SPIy_Buffer_Rx, SPIz_Buffer_Tx, BufferSize); + /* TransferStatus1, TransferStatus2 = PASSED, if the transmitted and received data + are equal */ + /* TransferStatus1, TransferStatus2 = FAILED, if the transmitted and received data + are different */ + + printf("SPIy->SPIz result TransferStatus1:%d, TransferStatus2:%d\r\n", TransferStatus1, TransferStatus2); + + /* SPIy Re-configuration ---------------------------------------------------*/ + SPI_InitStructure.SpiMode = SPI_MODE_SLAVE; + SPI_Init(SPIy, &SPI_InitStructure); + + /* SPIz Re-configuration ---------------------------------------------------*/ + SPI_InitStructure.SpiMode = SPI_MODE_MASTER; + SPI_Init(SPIz, &SPI_InitStructure); + + /* Reset TxIdx, RxIdx indexes and receive tables values */ + TxIdx = 0; + RxIdx = 0; + for (k = 0; k < BufferSize; k++) + SPIz_Buffer_Rx[k] = 0; + for (k = 0; k < BufferSize; k++) + SPIy_Buffer_Rx[k] = 0; + + /* Transfer procedure */ + while (TxIdx < BufferSize) + { + /* Wait for SPIz Tx buffer empty */ + while (SPI_I2S_GetStatus(SPIz, SPI_I2S_TE_FLAG) == RESET) + ; + /* Send SPIy data */ + SPI_I2S_TransmitData(SPIy, SPIy_Buffer_Tx[TxIdx]); + /* Send SPIz data */ + SPI_I2S_TransmitData(SPIz, SPIz_Buffer_Tx[TxIdx++]); + /* Wait for SPIy data reception */ + while (SPI_I2S_GetStatus(SPIy, SPI_I2S_RNE_FLAG) == RESET) + ; + /* Read SPIy received data */ + SPIy_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPIy); + /* Wait for SPIz data reception */ + while (SPI_I2S_GetStatus(SPIz, SPI_I2S_RNE_FLAG) == RESET) + ; + /* Read SPIz received data */ + SPIz_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPIz); + } + + /* Check the correctness of written dada */ + TransferStatus3 = Buffercmp(SPIz_Buffer_Rx, SPIy_Buffer_Tx, BufferSize); + TransferStatus4 = Buffercmp(SPIy_Buffer_Rx, SPIz_Buffer_Tx, BufferSize); + /* TransferStatus3, TransferStatus4 = PASSED, if the transmitted and received data + are equal */ + /* TransferStatus3, TransferStatus4 = FAILED, if the transmitted and received data + are different */ + printf("SPIz->SPIy result TransferStatus3:%d, TransferStatus4:%d\r\n", TransferStatus3, TransferStatus4); + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks --------------------------------------------------*/ + + /* Enable GPIO clock for SPIy and SPIz */ + RCC_EnableAPB2PeriphClk(SPIy_GPIO_CLK | SPIz_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Enable SPIy and SPIz Periph clock */ + RCC_EnableAPB2PeriphClk(SPIy_CLK | SPIz_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration() +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure SPI1 pins: SCK, MISO and MOSI ---------------------------------*/ + /* Confugure SCK , MISO and MOSI pins as Alternate Function Push Pull */ + GPIO_InitStructure.Pin = SPIy_PIN_SCK | SPIy_PIN_MISO | SPIy_PIN_MOSI; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = SPIy_GPIO_AF; + GPIO_InitPeripheral(SPIy_GPIO, &GPIO_InitStructure); + + /* Configure SPI2 pins: SCK, MISO and MOSI ---------------------------------*/ + /* Confugure SCK , MISO and MOSI pins as Alternate Function Push Pull */ + GPIO_InitStructure.Pin = SPIz_PIN_SCK | SPIz_PIN_MISO | SPIz_PIN_MOSI; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = SPIz_GPIO_AF; + GPIO_InitPeripheral(SPIz_GPIO, &GPIO_InitStructure); +} +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/FullDuplex_SoftNSS/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/MDK-ARM/SPI_DMA_MASTER.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/MDK-ARM/SPI_DMA_MASTER.uvoptx new file mode 100644 index 0000000..f473a9d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/MDK-ARM/SPI_DMA_MASTER.uvoptx @@ -0,0 +1,367 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/MDK-ARM/SPI_DMA_MASTER.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/MDK-ARM/SPI_DMA_MASTER.uvprojx new file mode 100644 index 0000000..7ff9a7d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/MDK-ARM/SPI_DMA_MASTER.uvprojx @@ -0,0 +1,480 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + SPI_DMA_MASTER + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\SPI_DMA_MASTER.bin .\Objects\SPI_DMA_MASTER.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\bsp\inc;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/inc/main.h new file mode 100644 index 0000000..80b4809 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/inc/main.h @@ -0,0 +1,79 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" + +#define SPI_MASTER SPI1 +#define SPI_MASTER_CLK RCC_APB2_PERIPH_SPI1 +#define SPI_MASTER_GPIO GPIOA +#define SPI_MASTER_GPIO_AF GPIO_AF1_SPI1 +#define SPI_MASTER_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define SPI_MASTER_PIN_SCK GPIO_PIN_1 +#define SPI_MASTER_PIN_MISO GPIO_PIN_3 +#define SPI_MASTER_PIN_MOSI GPIO_PIN_2 +#define SPI_MASTER_DMA DMA +#define SPI_MASTER_DMA_CLK RCC_AHB_PERIPH_DMA +#define SPI_MASTER_RX_DMA_CHANNEL DMA_CH2 +#define SPI_MASTER_RX_DMA_FLAG DMA_FLAG_TC2 +#define SPI_MASTER_RX_DMA_REMAP DMA_REMAP_SPI1_RX +#define SPI_MASTER_TX_DMA_CHANNEL DMA_CH3 +#define SPI_MASTER_TX_DMA_FLAG DMA_FLAG_TC3 +#define SPI_MASTER_TX_DMA_REMAP DMA_REMAP_SPI1_TX + + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/inc/n32wb03x_it.h new file mode 100644 index 0000000..9a292de --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void SPI1_IRQHandler(void); +void SPI2_3_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/readme.txt new file mode 100644 index 0000000..e735455 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/readme.txt @@ -0,0 +1,22 @@ + +1. Function description + 1. SPI master mode full duplex DMA send and single-wire receive data + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock:64MHz + 2. GPIO:(Master mode DEMO board) SPI1: SCK--PA1, MISO--PA3, MOSI--PA2 + (Slave mode DEMO board) SPI1: SCK--PA1, MISO--PA3, MOSI--PA2 + 3. Log print: master mode DEMO board PB6(TX), baud rate: 115200 + Instructions: + 1. After compiling, download the program to reset and run; + 2. Connect the serial port printing tool, power on, and check that the print test is successful; + + +4. Matters needing attention + Two demo boards are required, one board to program the master mode program, one board to program the slave mode program, + the two boards need to be powered on together, and connect the VCC and GND of the two boards; \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/src/main.c new file mode 100644 index 0000000..e979d8f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/src/main.c @@ -0,0 +1,274 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "n32wb03x.h" +#include "log.h" + +#include + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup DMA_SPI_RAM + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define BUFFER_SIZE 32 +#define CRC_POLYNOMIAL 7 + +SPI_InitType SPI_InitStructure; +DMA_InitType DMA_InitStructure; +uint8_t SPI_Master_Rx_Buffer[BUFFER_SIZE], SPI_Slave_Rx_Buffer[BUFFER_SIZE]; +volatile uint8_t SPI_MASTERCRCValue = 0, SPI_SLAVECRCValue = 0; +volatile Status TransferStatus1 = PASSED, TransferStatus2 = PASSED; + +uint8_t SPI_Master_Tx_Buffer[BUFFER_SIZE] = {0xf1, 0x2e, 0xf1, 0xaf, 0x08, 0xa2, 0x41, 0xb4, 0xc8, 0x19, 0x38, + 0xb7, 0xd9, 0xdb, 0x9a, 0x64, 0x1f, 0xd6, 0x99, 0x9c, 0x0f, 0xae, + 0x84, 0xab, 0xda, 0x12, 0x95, 0x6c, 0xdb, 0xec, 0x06, 0x08}; + +uint8_t SPI_Slave_Tx_Buffer[BUFFER_SIZE] = {0x2c, 0x99, 0xd7, 0x26, 0xb0, 0xe5, 0xb2, 0xfc, 0xee, 0x88, 0x3f, + 0xde, 0xa4, 0x37, 0x87, 0xc9, 0xb2, 0x9c, 0xce, 0xc8, 0x2c, 0x22, + 0x6b, 0xfe, 0xba, 0x49, 0x94, 0x0a, 0x47, 0x5a, 0xb7, 0x89}; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength); + +/** + * @brief Main program + */ +int main(void) +{ + uint8_t i; + log_init(); + + log_info("\n this is a SPI master DMA to RAM Demo.\n"); + + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + SPI_I2S_DeInit(SPI_MASTER); + /* SPI_MASTER configuration + * ------------------------------------------------*/ + SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX; + SPI_InitStructure.SpiMode = SPI_MODE_MASTER; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_32; + SPI_InitStructure.FirstBit = SPI_FB_MSB; + SPI_InitStructure.CRCPoly = CRC_POLYNOMIAL; + SPI_Init(SPI_MASTER, &SPI_InitStructure); + + /* SPI_MASTER_RX_DMA_CHANNEL configuration + * ---------------------------------*/ + DMA_DeInit(SPI_MASTER_RX_DMA_CHANNEL); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI_MASTER->DAT; + DMA_InitStructure.MemAddr = (uint32_t)SPI_Master_Rx_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = BUFFER_SIZE; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(SPI_MASTER_RX_DMA_CHANNEL, &DMA_InitStructure); + DMA_RequestRemap(SPI_MASTER_RX_DMA_REMAP, DMA, SPI_MASTER_RX_DMA_CHANNEL, ENABLE); + + /* SPI_MASTER_TX_DMA_CHANNEL configuration + * ---------------------------------*/ + DMA_DeInit(SPI_MASTER_TX_DMA_CHANNEL); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI_MASTER->DAT; + DMA_InitStructure.MemAddr = (uint32_t)SPI_Master_Tx_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.Priority = DMA_PRIORITY_LOW; + DMA_Init(SPI_MASTER_TX_DMA_CHANNEL, &DMA_InitStructure); + DMA_RequestRemap(SPI_MASTER_TX_DMA_REMAP, DMA, SPI_MASTER_TX_DMA_CHANNEL, ENABLE); + + /* Enable SPI_MASTER DMA Tx request */ + SPI_I2S_EnableDma(SPI_MASTER, SPI_I2S_DMA_TX, ENABLE); + /* Enable SPI_MASTER DMA Rx request */ + SPI_I2S_EnableDma(SPI_MASTER, SPI_I2S_DMA_RX, ENABLE); + + /* Enable SPI_MASTER CRC calculation */ + SPI_EnableCalculateCrc(SPI_MASTER, ENABLE); + + /* Enable SPI_MASTER */ + SPI_Enable(SPI_MASTER, ENABLE); + + /* Enable DMA channels */ + DMA_EnableChannel(SPI_MASTER_RX_DMA_CHANNEL, ENABLE); + DMA_EnableChannel(SPI_MASTER_TX_DMA_CHANNEL, ENABLE); + + /* Transfer complete */ + while (!DMA_GetFlagStatus(SPI_MASTER_RX_DMA_FLAG, SPI_MASTER_DMA)) + ; + while (!DMA_GetFlagStatus(SPI_MASTER_TX_DMA_FLAG, SPI_MASTER_DMA)) + ; + + /* Wait for SPI_MASTER data reception: CRC transmitted by SPI_SLAVE */ + while (SPI_I2S_GetStatus(SPI_MASTER, SPI_I2S_RNE_FLAG) == RESET) + ; + + /* Check the correctness of written dada */ + TransferStatus1 = Buffercmp(SPI_Master_Rx_Buffer, SPI_Slave_Tx_Buffer, BUFFER_SIZE); + + /* Test on the SPI_MASTER CRCR ERROR flag */ + if ((SPI_I2S_GetStatus(SPI_MASTER, SPI_CRCERR_FLAG)) != RESET) + { + TransferStatus2 = FAILED; + } + + /* Read SPI_MASTER received CRC value */ + SPI_MASTERCRCValue = SPI_I2S_ReceiveData(SPI_MASTER); + + printf("TransferStatus1:%d, TransferStatus2:%d, SPI_MASTERCRCValue:0x%02x\r\n", TransferStatus1, TransferStatus2, SPI_MASTERCRCValue); + + if (TransferStatus1 != FAILED) + { + log_info("SPI master passed.\n"); + log_info("master recv data = "); + for(i = 0; i< BUFFER_SIZE; i++) + { + log_info("%02x", SPI_Master_Rx_Buffer[i]); + } + log_info("\r\n"); + } + else + { + log_error("SPI master failed.\n"); + } + + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks + * ------------------------------------------------*/ + /* Enable DMA clock */ + RCC_EnableAHBPeriphClk(SPI_MASTER_DMA_CLK, ENABLE); + + /* Enable SPI_MASTER clock and GPIO clock for SPI_MASTER */ + RCC_EnableAPB2PeriphClk(SPI_MASTER_GPIO_CLK | SPI_MASTER_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure SPI_MASTER pins: SCK ,MISO and MOSI */ + GPIO_InitStructure.Pin = SPI_MASTER_PIN_SCK | SPI_MASTER_PIN_MOSI |SPI_MASTER_PIN_MISO; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Alternate = SPI_MASTER_GPIO_AF; + GPIO_InitPeripheral(SPI_MASTER_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer, pBuffer1: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer identical to pBuffer1 + * FAILED: pBuffer differs from pBuffer1 + */ +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer != *pBuffer1) + { + return FAILED; + } + + pBuffer++; + pBuffer1++; + } + + return PASSED; +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/src/n32wb03x_it.c new file mode 100644 index 0000000..546d2a4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_MASTER/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/MDK-ARM/SPI_DMA_SLAVE.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/MDK-ARM/SPI_DMA_SLAVE.uvoptx new file mode 100644 index 0000000..d36a2c5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/MDK-ARM/SPI_DMA_SLAVE.uvoptx @@ -0,0 +1,367 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/MDK-ARM/SPI_DMA_SLAVE.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/MDK-ARM/SPI_DMA_SLAVE.uvprojx new file mode 100644 index 0000000..65f3b5f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/MDK-ARM/SPI_DMA_SLAVE.uvprojx @@ -0,0 +1,480 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + SPI_DMA_SLAVE_SPI1 + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\SPI_DMA_SLAVE_SPI1.bin .\Objects\SPI_DMA_SLAVE_SPI1.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\bsp\inc;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/inc/main.h new file mode 100644 index 0000000..becf6f0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/inc/main.h @@ -0,0 +1,78 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" + +#define SPI_SLAVE SPI1 +#define SPI_SLAVE_CLK RCC_APB2_PERIPH_SPI1 +#define SPI_SLAVE_GPIO GPIOA +#define SPI_SLAVE_GPIO_AF GPIO_AF1_SPI1 +#define SPI_SLAVE_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define SPI_SLAVE_PIN_SCK GPIO_PIN_1 +#define SPI_SLAVE_PIN_MISO GPIO_PIN_3 +#define SPI_SLAVE_PIN_MOSI GPIO_PIN_2 +#define SPI_SLAVE_DMA DMA +#define SPI_SLAVE_DMA_CLK RCC_AHB_PERIPH_DMA +#define SPI_SLAVE_RX_DMA_CHANNEL DMA_CH4 +#define SPI_SLAVE_RX_DMA_FLAG DMA_FLAG_TC4 +#define SPI_SLAVE_RX_DMA_REMAP DMA_REMAP_SPI1_RX +#define SPI_SLAVE_TX_DMA_CHANNEL DMA_CH5 +#define SPI_SLAVE_TX_DMA_FLAG DMA_FLAG_TC5 +#define SPI_SLAVE_TX_DMA_REMAP DMA_REMAP_SPI1_TX + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/readme.txt new file mode 100644 index 0000000..e735455 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/readme.txt @@ -0,0 +1,22 @@ + +1. Function description + 1. SPI master mode full duplex DMA send and single-wire receive data + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock:64MHz + 2. GPIO:(Master mode DEMO board) SPI1: SCK--PA1, MISO--PA3, MOSI--PA2 + (Slave mode DEMO board) SPI1: SCK--PA1, MISO--PA3, MOSI--PA2 + 3. Log print: master mode DEMO board PB6(TX), baud rate: 115200 + Instructions: + 1. After compiling, download the program to reset and run; + 2. Connect the serial port printing tool, power on, and check that the print test is successful; + + +4. Matters needing attention + Two demo boards are required, one board to program the master mode program, one board to program the slave mode program, + the two boards need to be powered on together, and connect the VCC and GND of the two boards; \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/src/main.c new file mode 100644 index 0000000..f205b3a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/src/main.c @@ -0,0 +1,274 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "n32wb03x.h" +#include "log.h" + +#include + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup DMA_SPI_RAM + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#define BUFFER_SIZE 32 +#define CRC_POLYNOMIAL 7 + +SPI_InitType SPI_InitStructure; +DMA_InitType DMA_InitStructure; +uint8_t SPI_Master_Rx_Buffer[BUFFER_SIZE], SPI_Slave_Rx_Buffer[BUFFER_SIZE]; +volatile uint8_t SPI_MASTERCRCValue = 0, SPI_SLAVECRCValue = 0; +volatile Status TransferStatus1 = PASSED, TransferStatus2 = PASSED; + +uint8_t SPI_Master_Tx_Buffer[BUFFER_SIZE] = {0xf1, 0x2e, 0xf1, 0xaf, 0x08, 0xa2, 0x41, 0xb4, 0xc8, 0x19, 0x38, + 0xb7, 0xd9, 0xdb, 0x9a, 0x64, 0x1f, 0xd6, 0x99, 0x9c, 0x0f, 0xae, + 0x84, 0xab, 0xda, 0x12, 0x95, 0x6c, 0xdb, 0xec, 0x06, 0x08}; + +uint8_t SPI_Slave_Tx_Buffer[BUFFER_SIZE] = {0x2c, 0x99, 0xd7, 0x26, 0xb0, 0xe5, 0xb2, 0xfc, 0xee, 0x88, 0x3f, + 0xde, 0xa4, 0x37, 0x87, 0xc9, 0xb2, 0x9c, 0xce, 0xc8, 0x2c, 0x22, + 0x6b, 0xfe, 0xba, 0x49, 0x94, 0x0a, 0x47, 0x5a, 0xb7, 0x89}; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength); + +/** + * @brief Main program + */ +int main(void) +{ + uint8_t i; + log_init(); + + log_info("\n this is a SPI slave DMA to RAM Demo.\n"); + + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* SPI_SLAVE configuration + * ------------------------------------------------*/ + SPI_I2S_DeInit(SPI_SLAVE); + SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX; + SPI_InitStructure.SpiMode = SPI_MODE_SLAVE; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_32; + SPI_InitStructure.FirstBit = SPI_FB_MSB; + SPI_InitStructure.CRCPoly = CRC_POLYNOMIAL; + SPI_Init(SPI_SLAVE, &SPI_InitStructure); + + /* SPI_SLAVE_RX_DMA_CHANNEL configuration + * ----------------------------------*/ + DMA_DeInit(SPI_SLAVE_RX_DMA_CHANNEL); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI_SLAVE->DAT; + DMA_InitStructure.MemAddr = (uint32_t)SPI_Slave_Rx_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = BUFFER_SIZE; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(SPI_SLAVE_RX_DMA_CHANNEL, &DMA_InitStructure); + DMA_RequestRemap(SPI_SLAVE_RX_DMA_REMAP, DMA,SPI_SLAVE_RX_DMA_CHANNEL, ENABLE); + + /* SPI_SLAVE_TX_DMA_CHANNEL configuration + * ----------------------------------*/ + DMA_DeInit(SPI_SLAVE_TX_DMA_CHANNEL); + DMA_InitStructure.PeriphAddr = (uint32_t)&SPI_SLAVE->DAT; + DMA_InitStructure.MemAddr = (uint32_t)SPI_Slave_Tx_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.Priority = DMA_PRIORITY_MEDIUM; + DMA_Init(SPI_SLAVE_TX_DMA_CHANNEL, &DMA_InitStructure); + DMA_RequestRemap(SPI_SLAVE_TX_DMA_REMAP, DMA,SPI_SLAVE_TX_DMA_CHANNEL, ENABLE); + + /* Enable SPI_SLAVE DMA Tx request */ + SPI_I2S_EnableDma(SPI_SLAVE, SPI_I2S_DMA_TX, ENABLE); + /* Enable SPI_SLAVE DMA Rx request */ + SPI_I2S_EnableDma(SPI_SLAVE, SPI_I2S_DMA_RX, ENABLE); + + /* Enable SPI_SLAVE CRC calculation */ + SPI_EnableCalculateCrc(SPI_SLAVE, ENABLE); + + /* Enable SPI_SLAVE */ + SPI_Enable(SPI_SLAVE, ENABLE); + + /* Enable DMA channels */ + DMA_EnableChannel(SPI_SLAVE_RX_DMA_CHANNEL, ENABLE); + DMA_EnableChannel(SPI_SLAVE_TX_DMA_CHANNEL, ENABLE); + + /* Transfer complete */ + while (!DMA_GetFlagStatus(SPI_SLAVE_RX_DMA_FLAG, SPI_SLAVE_DMA)) + ; + while (!DMA_GetFlagStatus(SPI_SLAVE_TX_DMA_FLAG, SPI_SLAVE_DMA)) + ; + + /* Wait for SPI_SLAVE data reception: CRC transmitted by SPI_MASTER */ + while (SPI_I2S_GetStatus(SPI_SLAVE, SPI_I2S_RNE_FLAG) == RESET) + ; + + /* Check the correctness of written dada */ + TransferStatus1 = Buffercmp(SPI_Slave_Rx_Buffer, SPI_Master_Tx_Buffer, BUFFER_SIZE); + + /* Test on the SPI_SLAVE CRCR ERROR flag */ + if ((SPI_I2S_GetStatus(SPI_SLAVE, SPI_CRCERR_FLAG)) != RESET) + { + TransferStatus2 = FAILED; + } + + /* Read SPI_SLAVE received CRC value */ + SPI_SLAVECRCValue = SPI_I2S_ReceiveData(SPI_SLAVE); + + printf("TransferStatus1:%d, TransferStatus2:%d, SPI_SLAVECRCValue:0x%02x\r\n", TransferStatus1, TransferStatus2, SPI_SLAVECRCValue); + + if (TransferStatus1 != FAILED) + { + log_info("SPI slave passed.\n"); + log_info("slave recv data = "); + for(i = 0; i< BUFFER_SIZE; i++) + { + log_info("%02x", SPI_Slave_Rx_Buffer[i]); + } + log_info("\r\n"); + } + else + { + log_error("SPI slave failed.\n"); + } + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks + * ------------------------------------------------*/ + /* Enable DMA clock */ + RCC_EnableAHBPeriphClk(SPI_SLAVE_DMA_CLK, ENABLE); + + /* Enable SPI_SLAVE clock and GPIO clock for SPI_SLAVE */ + RCC_EnableAPB2PeriphClk(SPI_SLAVE_GPIO_CLK | SPI_SLAVE_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure SPI_SLAVE pins: SCK,MISO and MOSI */ + GPIO_InitStructure.Pin = SPI_SLAVE_PIN_SCK | SPI_SLAVE_PIN_MOSI |SPI_SLAVE_PIN_MISO; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = SPI_SLAVE_GPIO_AF; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitPeripheral(SPI_SLAVE_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer, pBuffer1: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer identical to pBuffer1 + * FAILED: pBuffer differs from pBuffer1 + */ +Status Buffercmp(uint8_t* pBuffer, uint8_t* pBuffer1, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer != *pBuffer1) + { + return FAILED; + } + + pBuffer++; + pBuffer1++; + } + + return PASSED; +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/src/n32wb03x_it.c new file mode 100644 index 0000000..546d2a4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_DMA_SLAVE/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/MDK-ARM/SPI_FLASH.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/MDK-ARM/SPI_FLASH.uvoptx new file mode 100644 index 0000000..1447004 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/MDK-ARM/SPI_FLASH.uvoptx @@ -0,0 +1,323 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 6 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\spi_flash.c + spi_flash.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 9 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/MDK-ARM/SPI_FLASH.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/MDK-ARM/SPI_FLASH.uvprojx new file mode 100644 index 0000000..b021acc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/MDK-ARM/SPI_FLASH.uvprojx @@ -0,0 +1,460 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + SPI_FLASH + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\SPI_FLASH.bin .\Objects\SPI_FLASH.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03x, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + spi_flash.c + 1 + ..\src\spi_flash.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/inc/main.h new file mode 100644 index 0000000..c312aed --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/inc/main.h @@ -0,0 +1,68 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 + +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/inc/spi_flash.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/inc/spi_flash.h new file mode 100644 index 0000000..5054a0f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/inc/spi_flash.h @@ -0,0 +1,213 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file spi_flash.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __SPI_FLASH_H__ +#define __SPI_FLASH_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +/** @addtogroup Utilities + * @{ + */ + +/** @addtogroup + * @{ + */ + +/** @addtogroup Common + * @{ + */ + +/** @addtogroup SPI_FLASH + * @{ + */ + +/** @addtogroup SPI_FLASH_Exported_Types + * @{ + */ +/** + * @} + */ + +/** @addtogroup SPI_FLASH_Exported_Constants + * @{ + */ +/** + * @brief SPI Flash supported commands + */ +#define sFLASH_CMD_WRITE 0x02 /*!< Write to Memory instruction */ +#define sFLASH_CMD_WRSR 0x01 /*!< Write Status Register instruction */ +#define sFLASH_CMD_WREN 0x06 /*!< Write enable instruction */ +#define sFLASH_CMD_READ 0x03 /*!< Read from Memory instruction */ +#define sFLASH_CMD_RDSR 0x05 /*!< Read Status Register instruction */ +#define sFLASH_CMD_RDID 0x9F /*!< Read identification */ +#define sFLASH_CMD_SE 0x20 /*!< Sector Erase instruction */ +#define sFLASH_CMD_BE 0xC7 /*!< Bulk Erase instruction */ + +#define sFLASH_WIP_FLAG 0x01 /*!< Write In Progress (WIP) flag */ + +#define sFLASH_DUMMY_BYTE 0xA5 +#define sFLASH_SPI_PAGESIZE 0x100 + +#define sFLASH_W25Q128_ID 0x00EF4014 +#define sFLASH_M25P64_ID 0x202017 + +#if 1 +#define sFLASH_SPI SPI1 +#define sFLASH_SPI_CLK RCC_APB2_PERIPH_SPI1 +#define sFLASH_SPI_AF GPIO_AF1_SPI1 +#define sFLASH_SPI_SCK_PIN GPIO_PIN_1 /* PA.01 */ +#define sFLASH_SPI_SCK_GPIO_PORT GPIOA /* GPIOA */ +#define sFLASH_SPI_SCK_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define sFLASH_SPI_MISO_PIN GPIO_PIN_3 /* PA.03 */ +#define sFLASH_SPI_MISO_GPIO_PORT GPIOA /* GPIOA */ +#define sFLASH_SPI_MISO_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define sFLASH_SPI_MOSI_PIN GPIO_PIN_2 /* PA.02 */ +#define sFLASH_SPI_MOSI_GPIO_PORT GPIOA /* GPIOA */ +#define sFLASH_SPI_MOSI_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define sFLASH_CS_PIN GPIO_PIN_0 /* PA.00 */ +#define sFLASH_CS_GPIO_PORT GPIOA /* GPIOA */ +#define sFLASH_CS_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#else +#define sFLASH_SPI SPI2 +#define sFLASH_SPI_CLK RCC_APB2_PERIPH_SPI2 +#define sFLASH_SPI_AF GPIO_AF2_SPI2 +#define sFLASH_SPI_SCK_PIN GPIO_PIN_1 /* PB.01 */ +#define sFLASH_SPI_SCK_GPIO_PORT GPIOB /* GPIOB */ +#define sFLASH_SPI_SCK_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define sFLASH_SPI_MISO_PIN GPIO_PIN_3 /* PB.03 */ +#define sFLASH_SPI_MISO_GPIO_PORT GPIOB /* GPIOB */ +#define sFLASH_SPI_MISO_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define sFLASH_SPI_MOSI_PIN GPIO_PIN_2 /* PB.02 */ +#define sFLASH_SPI_MOSI_GPIO_PORT GPIOB /* GPIOB */ +#define sFLASH_SPI_MOSI_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define sFLASH_CS_PIN GPIO_PIN_0 /* PB.00 */ +#define sFLASH_CS_GPIO_PORT GPIOB /* GPIOB */ +#define sFLASH_CS_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#endif + + +/** + * @} + */ + +/** @addtogroup SPI_FLASH_Exported_Macros + * @{ + */ +/** + * @brief Select sFLASH: Chip Select pin low + */ +#define sFLASH_CS_LOW() GPIO_ResetBits(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN) +/** + * @brief Deselect sFLASH: Chip Select pin high + */ +#define sFLASH_CS_HIGH() GPIO_SetBits(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN) +/** + * @} + */ + +/** @addtogroup SPI_FLASH_Exported_Functions + * @{ + */ +/** + * @brief High layer functions + */ +void sFLASH_DeInit(void); +void sFLASH_Init(void); +void sFLASH_EraseSector(uint32_t SectorAddr); +void sFLASH_EraseBulk(void); +void sFLASH_WritePage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite); +void sFLASH_WriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite); +void sFLASH_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead); +uint32_t sFLASH_ReadID(void); +void sFLASH_StartReadSequence(uint32_t ReadAddr); + +/** + * @brief Low layer functions + */ +uint8_t sFLASH_ReadByte(void); +uint8_t sFLASH_SendByte(uint8_t byte); +uint16_t sFLASH_SendHalfWord(uint16_t HalfWord); +void sFLASH_WriteEnable(void); +void sFLASH_WaitForWriteEnd(void); + +#ifdef __cplusplus +} +#endif + +#endif +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/readme.txt new file mode 100644 index 0000000..9f94a6d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/readme.txt @@ -0,0 +1,20 @@ + +1. Function description + 1. SPI read, write, erase W25Q128 + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock:64MHz + 2. SPI1: NSS--PA0, SCK--PA1, MISO--PA3, MOSI--PA2 + Instructions: + 1. After compiling, download the program to reset and run; + 2. Read the ID of W25Q128 through SPI1, then write the data, then read it out, compare the read and write data, + check that the status of TransferStatus1 is PASSED, then erase the block, and check that the erase block is normal; + +4. Matters needing attention + Connect the SPI1 interface of the development board to the W25Q128 development board, + the two development boards need to share the ground. diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/src/main.c new file mode 100644 index 0000000..8723806 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/src/main.c @@ -0,0 +1,287 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "spi_flash.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup SPI_FLASH + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +#define FLASH_WriteAddress 0x700000 +#define FLASH_ReadAddress FLASH_WriteAddress +#define FLASH_SectorToErase FLASH_WriteAddress + +#define sFLASH_ID sFLASH_W25Q128_ID + +#define BufferSize (countof(Tx_Buffer) - 1) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +uint8_t Tx_Buffer[] = "N32WB03X SPI Firmware Library Example: communication with an W25Q128 SPI FLASH"; +uint8_t Rx_Buffer[BufferSize]; +__IO uint8_t Index = 0x0; +volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = PASSED; +__IO uint32_t FlashID = 0; + +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + else + { + return; + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param Led Specifies the Led to be set on. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIOx->PBSC = Pin; +} +/** + * @brief Turns selected Led Off. + * @param Led Specifies the Led to be set off. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIOx->PBC = Pin; +} + +/** + * @brief Toggles the selected Led. + * @param Led Specifies the Led to be toggled. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIOx->POD ^= Pin; +} + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + LedOff(LED1_PORT, LED1_PIN); + LedOff(LED2_PORT, LED2_PIN); + + /* Initialize the SPI FLASH driver */ + sFLASH_Init(); + + /* Get SPI Flash ID */ + FlashID = sFLASH_ReadID(); + + /* Check the SPI Flash ID */ + if (FlashID == sFLASH_ID) + { + /* Perform a write in the Flash followed by a read of the written data */ + /* Erase SPI FLASH Sector to write on */ + sFLASH_EraseSector(FLASH_SectorToErase); + + /* Write Tx_Buffer data to SPI FLASH memory */ + sFLASH_WriteBuffer(Tx_Buffer, FLASH_WriteAddress, BufferSize); + + /* Read data from SPI FLASH memory */ + sFLASH_ReadBuffer(Rx_Buffer, FLASH_ReadAddress, BufferSize); + + /* Check the correctness of written dada */ + TransferStatus1 = Buffercmp(Tx_Buffer, Rx_Buffer, BufferSize); + /* TransferStatus1 = PASSED, if the transmitted and received data by SPI1 + are the same */ + /* TransferStatus1 = FAILED, if the transmitted and received data by SPI1 + are different */ + + /* Perform an erase in the Flash followed by a read of the written data */ + /* Erase SPI FLASH Sector to write on */ + sFLASH_EraseSector(FLASH_SectorToErase); + + /* Read data from SPI FLASH memory */ + sFLASH_ReadBuffer(Rx_Buffer, FLASH_ReadAddress, BufferSize); + + /* Check the correctness of erasing operation dada */ + for (Index = 0; Index < BufferSize; Index++) + { + if (Rx_Buffer[Index] != 0xFF) + { + TransferStatus2 = FAILED; + } + } + + if((TransferStatus1 == SUCCESS) && (TransferStatus2 == SUCCESS)) + { + /* OK: Turn on LED1 */ + LedOn(LED1_PORT, LED1_PIN); + } + else + { + /* Error: Turn on LED2 */ + LedOn(LED2_PORT, LED2_PIN); + } + /* TransferStatus2 = PASSED, if the specified sector part is erased */ + /* TransferStatus2 = FAILED, if the specified sector part is not well erased */ + } + else + { + /* Error: Turn on LED2 */ + LedOn(LED2_PORT, LED2_PIN); + } + + while (1) + { + } +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/src/spi_flash.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/src/spi_flash.c new file mode 100644 index 0000000..2052d99 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/SPI_FLASH/src/spi_flash.c @@ -0,0 +1,586 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file spi_flash.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "spi_flash.h" + +/** @addtogroup Utilities + * @{ + */ + +/** @addtogroup + * @{ + */ + +/** @addtogroup Common + * @{ + */ + +/** @addtogroup SPI_FLASH + * @brief + * @{ + */ + +/** @addtogroup SPI_FLASH_Private_Types + * @{ + */ +/** + * @} + */ + +/** @addtogroup SPI_FLASH_Private_Defines + * @{ + */ +/** + * @} + */ + +/** @addtogroup SPI_FLASH_Private_Macros + * @{ + */ +/** + * @} + */ + +/** @addtogroup SPI_FLASH_Private_Variables + * @{ + */ +/** + * @} + */ + +/** @addtogroup SPI_FLASH_Private_Function_Prototypes + * @{ + */ +/** + * @} + */ + +/** @addtogroup SPI_FLASH_Private_Functions + * @{ + */ + +/** + * @brief DeInitializes the peripherals used by the SPI FLASH driver. + */ +void sFLASH_LowLevel_DeInit(void) +{ + GPIO_InitType GPIO_InitStructure; + + /*!< Disable the sFLASH_SPI */ + SPI_Enable(sFLASH_SPI, DISABLE); + + /*!< DeInitializes the sFLASH_SPI */ + SPI_I2S_DeInit(sFLASH_SPI); + + /*!< sFLASH_SPI Periph clock disable */ + RCC_EnableAPB2PeriphClk(sFLASH_SPI_CLK, DISABLE); + + /*!< Configure sFLASH_SPI pins: SCK */ + GPIO_InitStructure.Pin = sFLASH_SPI_SCK_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT; + GPIO_InitPeripheral(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); + + /*!< Configure sFLASH_SPI pins: MISO */ + GPIO_InitStructure.Pin = sFLASH_SPI_MISO_PIN; + GPIO_InitPeripheral(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); + + /*!< Configure sFLASH_SPI pins: MOSI */ + GPIO_InitStructure.Pin = sFLASH_SPI_MOSI_PIN; + GPIO_InitPeripheral(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); + + /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */ + GPIO_InitStructure.Pin = sFLASH_CS_PIN; + GPIO_InitPeripheral(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure); +} + +/** + * @brief Initializes the peripherals used by the SPI FLASH driver. + */ +void sFLASH_LowLevel_Init(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO + and sFLASH_SPI_SCK_GPIO Periph clock enable */ + RCC_EnableAPB2PeriphClk( + sFLASH_CS_GPIO_CLK | sFLASH_SPI_MOSI_GPIO_CLK | sFLASH_SPI_MISO_GPIO_CLK | sFLASH_SPI_SCK_GPIO_CLK, ENABLE); + + /*!< sFLASH_SPI Periph clock enable */ + RCC_EnableAPB2PeriphClk(sFLASH_SPI_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /*!< Configure sFLASH_SPI pins: SCK */ + GPIO_InitStructure.Pin = sFLASH_SPI_SCK_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = sFLASH_SPI_AF; + GPIO_InitPeripheral(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); + + /*!< Configure sFLASH_SPI pins: MOSI */ + GPIO_InitStructure.Pin = sFLASH_SPI_MOSI_PIN; + GPIO_InitPeripheral(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); + + /*!< Configure sFLASH_SPI pins: MISO */ + GPIO_InitStructure.Pin = sFLASH_SPI_MISO_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitPeripheral(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); + + /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */ + GPIO_InitStructure.Pin = sFLASH_CS_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure); +} + +/** + * @brief DeInitializes the peripherals used by the SPI FLASH driver. + */ +void sFLASH_DeInit(void) +{ + sFLASH_LowLevel_DeInit(); +} + +/** + * @brief Initializes the peripherals used by the SPI FLASH driver. + */ +void sFLASH_Init(void) +{ + SPI_InitType SPI_InitStructure; + + sFLASH_LowLevel_Init(); + + /*!< Deselect the FLASH: Chip Select high */ + sFLASH_CS_HIGH(); + + /*!< SPI configuration */ + SPI_I2S_DeInit(sFLASH_SPI); + SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX; + SPI_InitStructure.SpiMode = SPI_MODE_MASTER; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_HIGH; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_4; + + SPI_InitStructure.FirstBit = SPI_FB_MSB; + SPI_InitStructure.CRCPoly = 7; + SPI_Init(sFLASH_SPI, &SPI_InitStructure); + + /*!< Enable the sFLASH_SPI */ + SPI_Enable(sFLASH_SPI, ENABLE); +} + +/** + * @brief Erases the specified FLASH sector. + * @param SectorAddr address of the sector to erase. + */ +void sFLASH_EraseSector(uint32_t SectorAddr) +{ + /*!< Send write enable instruction */ + sFLASH_WriteEnable(); + + /*!< Sector Erase */ + /*!< Select the FLASH: Chip Select low */ + sFLASH_CS_LOW(); + /*!< Send Sector Erase instruction */ + sFLASH_SendByte(sFLASH_CMD_SE); + /*!< Send SectorAddr high nibble address byte */ + sFLASH_SendByte((SectorAddr & 0xFF0000) >> 16); + /*!< Send SectorAddr medium nibble address byte */ + sFLASH_SendByte((SectorAddr & 0xFF00) >> 8); + /*!< Send SectorAddr low nibble address byte */ + sFLASH_SendByte(SectorAddr & 0xFF); + /*!< Deselect the FLASH: Chip Select high */ + sFLASH_CS_HIGH(); + + /*!< Wait the end of Flash writing */ + sFLASH_WaitForWriteEnd(); +} + +/** + * @brief Erases the entire FLASH. + */ +void sFLASH_EraseBulk(void) +{ + /*!< Send write enable instruction */ + sFLASH_WriteEnable(); + + /*!< Bulk Erase */ + /*!< Select the FLASH: Chip Select low */ + sFLASH_CS_LOW(); + /*!< Send Bulk Erase instruction */ + sFLASH_SendByte(sFLASH_CMD_BE); + /*!< Deselect the FLASH: Chip Select high */ + sFLASH_CS_HIGH(); + + /*!< Wait the end of Flash writing */ + sFLASH_WaitForWriteEnd(); +} + +/** + * @brief Writes more than one byte to the FLASH with a single WRITE cycle + * (Page WRITE sequence). + * @note The number of byte can't exceed the FLASH page size. + * @param pBuffer pointer to the buffer containing the data to be written + * to the FLASH. + * @param WriteAddr FLASH's internal address to write to. + * @param NumByteToWrite number of bytes to write to the FLASH, must be equal + * or less than "sFLASH_PAGESIZE" value. + */ +void sFLASH_WritePage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) +{ + /*!< Enable the write access to the FLASH */ + sFLASH_WriteEnable(); + + /*!< Select the FLASH: Chip Select low */ + sFLASH_CS_LOW(); + /*!< Send "Write to Memory " instruction */ + sFLASH_SendByte(sFLASH_CMD_WRITE); + /*!< Send WriteAddr high nibble address byte to write to */ + sFLASH_SendByte((WriteAddr & 0xFF0000) >> 16); + /*!< Send WriteAddr medium nibble address byte to write to */ + sFLASH_SendByte((WriteAddr & 0xFF00) >> 8); + /*!< Send WriteAddr low nibble address byte to write to */ + sFLASH_SendByte(WriteAddr & 0xFF); + + /*!< while there is data to be written on the FLASH */ + while (NumByteToWrite--) + { + /*!< Send the current byte */ + sFLASH_SendByte(*pBuffer); + /*!< Point on the next byte to be written */ + pBuffer++; + } + + /*!< Deselect the FLASH: Chip Select high */ + sFLASH_CS_HIGH(); + + /*!< Wait the end of Flash writing */ + sFLASH_WaitForWriteEnd(); +} + +/** + * @brief Writes block of data to the FLASH. In this function, the number of + * WRITE cycles are reduced, using Page WRITE sequence. + * @param pBuffer pointer to the buffer containing the data to be written + * to the FLASH. + * @param WriteAddr FLASH's internal address to write to. + * @param NumByteToWrite number of bytes to write to the FLASH. + */ +void sFLASH_WriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) +{ + uint8_t NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0; + + Addr = WriteAddr % sFLASH_SPI_PAGESIZE; + count = sFLASH_SPI_PAGESIZE - Addr; + NumOfPage = NumByteToWrite / sFLASH_SPI_PAGESIZE; + NumOfSingle = NumByteToWrite % sFLASH_SPI_PAGESIZE; + + if (Addr == 0) /*!< WriteAddr is sFLASH_PAGESIZE aligned */ + { + if (NumOfPage == 0) /*!< NumByteToWrite < sFLASH_PAGESIZE */ + { + sFLASH_WritePage(pBuffer, WriteAddr, NumByteToWrite); + } + else /*!< NumByteToWrite > sFLASH_PAGESIZE */ + { + while (NumOfPage--) + { + sFLASH_WritePage(pBuffer, WriteAddr, sFLASH_SPI_PAGESIZE); + WriteAddr += sFLASH_SPI_PAGESIZE; + pBuffer += sFLASH_SPI_PAGESIZE; + } + + sFLASH_WritePage(pBuffer, WriteAddr, NumOfSingle); + } + } + else /*!< WriteAddr is not sFLASH_PAGESIZE aligned */ + { + if (NumOfPage == 0) /*!< NumByteToWrite < sFLASH_PAGESIZE */ + { + if (NumOfSingle > count) /*!< (NumByteToWrite + WriteAddr) > sFLASH_PAGESIZE */ + { + temp = NumOfSingle - count; + + sFLASH_WritePage(pBuffer, WriteAddr, count); + WriteAddr += count; + pBuffer += count; + + sFLASH_WritePage(pBuffer, WriteAddr, temp); + } + else + { + sFLASH_WritePage(pBuffer, WriteAddr, NumByteToWrite); + } + } + else /*!< NumByteToWrite > sFLASH_PAGESIZE */ + { + NumByteToWrite -= count; + NumOfPage = NumByteToWrite / sFLASH_SPI_PAGESIZE; + NumOfSingle = NumByteToWrite % sFLASH_SPI_PAGESIZE; + + sFLASH_WritePage(pBuffer, WriteAddr, count); + WriteAddr += count; + pBuffer += count; + + while (NumOfPage--) + { + sFLASH_WritePage(pBuffer, WriteAddr, sFLASH_SPI_PAGESIZE); + WriteAddr += sFLASH_SPI_PAGESIZE; + pBuffer += sFLASH_SPI_PAGESIZE; + } + + if (NumOfSingle != 0) + { + sFLASH_WritePage(pBuffer, WriteAddr, NumOfSingle); + } + } + } +} + +/** + * @brief Reads a block of data from the FLASH. + * @param pBuffer pointer to the buffer that receives the data read from the FLASH. + * @param ReadAddr FLASH's internal address to read from. + * @param NumByteToRead number of bytes to read from the FLASH. + */ +void sFLASH_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead) +{ + /*!< Select the FLASH: Chip Select low */ + sFLASH_CS_LOW(); + + /*!< Send "Read from Memory " instruction */ + sFLASH_SendByte(sFLASH_CMD_READ); + + /*!< Send ReadAddr high nibble address byte to read from */ + sFLASH_SendByte((ReadAddr & 0xFF0000) >> 16); + /*!< Send ReadAddr medium nibble address byte to read from */ + sFLASH_SendByte((ReadAddr & 0xFF00) >> 8); + /*!< Send ReadAddr low nibble address byte to read from */ + sFLASH_SendByte(ReadAddr & 0xFF); + + while (NumByteToRead--) /*!< while there is data to be read */ + { + /*!< Read a byte from the FLASH */ + *pBuffer = sFLASH_SendByte(sFLASH_DUMMY_BYTE); + /*!< Point to the next location where the byte read will be saved */ + pBuffer++; + } + + /*!< Deselect the FLASH: Chip Select high */ + sFLASH_CS_HIGH(); +} + +/** + * @brief Reads FLASH identification. + * @return FLASH identification + */ +uint32_t sFLASH_ReadID(void) +{ + uint32_t Temp = 0, Temp0 = 0, Temp1 = 0, Temp2 = 0; + + /*!< Select the FLASH: Chip Select low */ + sFLASH_CS_LOW(); + + /*!< Send "RDID " instruction */ + sFLASH_SendByte(0x9F); + /*!< Read a byte from the FLASH */ + Temp0 = sFLASH_SendByte(sFLASH_DUMMY_BYTE); + + /*!< Read a byte from the FLASH */ + Temp1 = sFLASH_SendByte(sFLASH_DUMMY_BYTE); + + /*!< Read a byte from the FLASH */ + Temp2 = sFLASH_SendByte(sFLASH_DUMMY_BYTE); + + /*!< Deselect the FLASH: Chip Select high */ + sFLASH_CS_HIGH(); + + Temp = (Temp0 << 16) | (Temp1 << 8) | Temp2; + + return Temp; +} + +/** + * @brief Initiates a read data byte (READ) sequence from the Flash. + * This is done by driving the /CS line low to select the device, then the READ + * instruction is transmitted followed by 3 bytes address. This function exit + * and keep the /CS line low, so the Flash still being selected. With this + * technique the whole content of the Flash is read with a single READ instruction. + * @param ReadAddr FLASH's internal address to read from. + */ +void sFLASH_StartReadSequence(uint32_t ReadAddr) +{ + /*!< Select the FLASH: Chip Select low */ + sFLASH_CS_LOW(); + + /*!< Send "Read from Memory " instruction */ + sFLASH_SendByte(sFLASH_CMD_READ); + + /*!< Send the 24-bit address of the address to read from -------------------*/ + /*!< Send ReadAddr high nibble address byte */ + sFLASH_SendByte((ReadAddr & 0xFF0000) >> 16); + /*!< Send ReadAddr medium nibble address byte */ + sFLASH_SendByte((ReadAddr & 0xFF00) >> 8); + /*!< Send ReadAddr low nibble address byte */ + sFLASH_SendByte(ReadAddr & 0xFF); +} + +/** + * @brief Reads a byte from the SPI Flash. + * @note This function must be used only if the Start_Read_Sequence function + * has been previously called. + * @return Byte Read from the SPI Flash. + */ +uint8_t sFLASH_ReadByte(void) +{ + return (sFLASH_SendByte(sFLASH_DUMMY_BYTE)); +} + +/** + * @brief Sends a byte through the SPI interface and return the byte received + * from the SPI bus. + * @param byte byte to send. + * @return The value of the received byte. + */ +uint8_t sFLASH_SendByte(uint8_t byte) +{ + /*!< Loop while DAT register in not emplty */ + while (SPI_I2S_GetStatus(sFLASH_SPI, SPI_I2S_TE_FLAG) == RESET) + ; + + /*!< Send byte through the SPI1 peripheral */ + SPI_I2S_TransmitData(sFLASH_SPI, byte); + + /*!< Wait to receive a byte */ + while (SPI_I2S_GetStatus(sFLASH_SPI, SPI_I2S_RNE_FLAG) == RESET) + ; + + /*!< Return the byte read from the SPI bus */ + return SPI_I2S_ReceiveData(sFLASH_SPI); +} + +/** + * @brief Sends a Half Word through the SPI interface and return the Half Word + * received from the SPI bus. + * @param HalfWord Half Word to send. + * @return The value of the received Half Word. + */ +uint16_t sFLASH_SendHalfWord(uint16_t HalfWord) +{ + /*!< Loop while DAT register in not emplty */ + while (SPI_I2S_GetStatus(sFLASH_SPI, SPI_I2S_TE_FLAG) == RESET) + ; + + /*!< Send Half Word through the sFLASH peripheral */ + SPI_I2S_TransmitData(sFLASH_SPI, HalfWord); + + /*!< Wait to receive a Half Word */ + while (SPI_I2S_GetStatus(sFLASH_SPI, SPI_I2S_RNE_FLAG) == RESET) + ; + + /*!< Return the Half Word read from the SPI bus */ + return SPI_I2S_ReceiveData(sFLASH_SPI); +} + +/** + * @brief Enables the write access to the FLASH. + */ +void sFLASH_WriteEnable(void) +{ + /*!< Select the FLASH: Chip Select low */ + sFLASH_CS_LOW(); + + /*!< Send "Write Enable" instruction */ + sFLASH_SendByte(sFLASH_CMD_WREN); + + /*!< Deselect the FLASH: Chip Select high */ + sFLASH_CS_HIGH(); +} + +/** + * @brief Polls the status of the Write In Progress (WIP) flag in the FLASH's + * status register and loop until write opertaion has completed. + */ +void sFLASH_WaitForWriteEnd(void) +{ + uint8_t flashstatus = 0; + + /*!< Select the FLASH: Chip Select low */ + sFLASH_CS_LOW(); + + /*!< Send "Read Status Register" instruction */ + sFLASH_SendByte(sFLASH_CMD_RDSR); + + /*!< Loop as long as the memory is busy with a write cycle */ + do + { + /*!< Send a dummy byte to generate the clock needed by the FLASH + and put the value of the status register in FLASH_STS variable */ + flashstatus = sFLASH_SendByte(sFLASH_DUMMY_BYTE); + + } while ((flashstatus & sFLASH_WIP_FLAG) == SET); /* Write in progress */ + + /*!< Deselect the FLASH: Chip Select high */ + sFLASH_CS_HIGH(); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/MDK-ARM/Simplex_Interrupt.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/MDK-ARM/Simplex_Interrupt.uvoptx new file mode 100644 index 0000000..71ea726 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/MDK-ARM/Simplex_Interrupt.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/MDK-ARM/Simplex_Interrupt.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/MDK-ARM/Simplex_Interrupt.uvprojx new file mode 100644 index 0000000..8b3ae17 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/MDK-ARM/Simplex_Interrupt.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Simplex_Interrupt + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Simplex_Interrupt.bin .\Objects\Simplex_Interrupt.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/inc/main.h new file mode 100644 index 0000000..65fd68e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/inc/main.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + + +#define SPI_MASTER SPI1 +#define SPI_MASTER_CLK RCC_APB2_PERIPH_SPI1 +#define SPI_MASTER_GPIO GPIOA +#define SPI_MASTER_GPIO_AF GPIO_AF1_SPI1 +#define SPI_MASTER_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define SPI_MASTER_PIN_SCK GPIO_PIN_1 +#define SPI_MASTER_PIN_MISO GPIO_PIN_3 +#define SPI_MASTER_PIN_MOSI GPIO_PIN_2 +#define SPI_MASTER_IRQn SPI1_IRQn + +#define SPI_SLAVE SPI2 +#define SPI_SLAVE_CLK RCC_APB2_PERIPH_SPI2 +#define SPI_SLAVE_GPIO GPIOB +#define SPI_SLAVE_GPIO_AF GPIO_AF2_SPI2 +#define SPI_SLAVE_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define SPI_SLAVE_PIN_SCK GPIO_PIN_1 +#define SPI_SLAVE_PIN_MISO GPIO_PIN_3 +#define SPI_SLAVE_PIN_MOSI GPIO_PIN_2 +#define SPI_SLAVE_IRQn SPI2_IRQn + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/inc/n32wb03x_it.h new file mode 100644 index 0000000..6ae2916 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void SPI1_IRQHandler(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/readme.txt new file mode 100644 index 0000000..5a5fca1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/readme.txt @@ -0,0 +1,21 @@ + +1. Function description + 1. SPI single-wire interrupt send and receive data + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock: 64MHz + 2. GPIO:SPI1: SCK--PA1, MOSI--PA2 + SPI2: SCK--PB1, MISO--PB3 + 3. Interrupt: SPI1 interrupt entry function SPI1_IRQHandler, SPI2 interrupt entry function SPI2_IRQHandler + Instructions: + 1. After compiling, download the program to reset and run; + 2. When SPI1 has data to send, it enters the SPI1_IRQHandler interrupt function to send, and when SPI2 has data to receive, + it enters the SPI2_IRQHandler interrupt function to receive. After the data transmission is completed, check the TransferStatus status as PASSED; + +4. Matters needing attention + The "single wire" data lines are MOSI pins on the master side and MISO pins on the slave side diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/src/main.c new file mode 100644 index 0000000..fad6828 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/src/main.c @@ -0,0 +1,275 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup Simplex_Interrupt + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +#define BufferSize 32 + +SPI_InitType SPI_InitStructure; +uint8_t MASTER_Buffer_Tx[BufferSize] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20}; +uint8_t SLAVE_Buffer_Rx[BufferSize]; +__IO uint8_t TxIdx = 0, RxIdx = 0; +volatile TestStatus TransferStatus = FAILED; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + log_init(); + log_info("\n this is a SPI Simplex Interrupt Demo.\n"); + + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + + /* NVIC configuration ------------------------------------------------------*/ + NVIC_Configuration(); + + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + /* SPI_MASTER configuration ------------------------------------------------*/ + SPI_I2S_DeInit(SPI_MASTER); + SPI_InitStructure.DataDirection = SPI_DIR_SINGLELINE_TX; + SPI_InitStructure.SpiMode = SPI_MODE_MASTER; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_4; + SPI_InitStructure.FirstBit = SPI_FB_MSB; + SPI_InitStructure.CRCPoly = 7; + SPI_Init(SPI_MASTER, &SPI_InitStructure); + + /* SPI_SLAVE configuration -------------------------------------------------*/ + SPI_I2S_DeInit(SPI_SLAVE); + SPI_InitStructure.DataDirection = SPI_DIR_SINGLELINE_RX; + SPI_InitStructure.SpiMode = SPI_MODE_SLAVE; + SPI_Init(SPI_SLAVE, &SPI_InitStructure); + + /* Enable SPI_MASTER TXE interrupt */ + SPI_I2S_EnableInt(SPI_MASTER, SPI_I2S_INT_TE, ENABLE); + /* Enable SPI_SLAVE RXNE interrupt */ + SPI_I2S_EnableInt(SPI_SLAVE, SPI_I2S_INT_RNE, ENABLE); + + /* Enable SPI_SLAVE */ + SPI_Enable(SPI_SLAVE, ENABLE); + /* Enable SPI_MASTER */ + SPI_Enable(SPI_MASTER, ENABLE); + + /* Transfer procedure */ + while (RxIdx < BufferSize) + { + } + + /* Check the correctness of written dada */ + TransferStatus = Buffercmp(SLAVE_Buffer_Rx, MASTER_Buffer_Tx, BufferSize); + if(TransferStatus == PASSED) + { + log_info("SPI Simplex Interrupt Demo test success.\n"); + } + else + { + log_info("SPI Simplex Interrupt Demo test fail.\n"); + } + + /* TransferStatus = PASSED, if the transmitted and received data + are equal */ + /* TransferStatus = FAILED, if the transmitted and received data + are different */ + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks --------------------------------------------------*/ + RCC_EnableAPB2PeriphClk(SPI_MASTER_GPIO_CLK | SPI_SLAVE_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* SPI Periph clock enable */ + RCC_EnableAPB2PeriphClk(SPI_MASTER_CLK | SPI_SLAVE_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure SPI1 pins: SCK, MOSI ---------------------------------*/ + /* Confugure SCK , MOSI pins as Alternate Function Push Pull */ + GPIO_InitStructure.Pin = SPI_MASTER_PIN_SCK | SPI_MASTER_PIN_MOSI; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = SPI_MASTER_GPIO_AF; + GPIO_InitPeripheral(SPI_MASTER_GPIO, &GPIO_InitStructure); + + /* Configure SPI2 pins: SCK, MISO ---------------------------------*/ + /* Confugure SCK and MOSI pins as Input Floating */ + GPIO_InitStructure.Pin = SPI_SLAVE_PIN_SCK | SPI_SLAVE_PIN_MISO; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = SPI_SLAVE_GPIO_AF; + GPIO_InitPeripheral(SPI_SLAVE_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Configure and enable SPI_MASTER interrupt -------------------------------*/ + NVIC_InitStructure.NVIC_IRQChannel = SPI_MASTER_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 2; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + /* Configure and enable SPI_SLAVE interrupt --------------------------------*/ + NVIC_InitStructure.NVIC_IRQChannel = SPI_SLAVE_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/src/n32wb03x_it.c new file mode 100644 index 0000000..8fc1283 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt/src/n32wb03x_it.c @@ -0,0 +1,162 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +#define BufferSize 32 +extern __IO uint8_t TxIdx, RxIdx; +extern uint8_t MASTER_Buffer_Tx[BufferSize], SLAVE_Buffer_Rx[BufferSize]; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles SPI1 global interrupt request. + */ + +void SPI1_IRQHandler(void) +{ + if (SPI_I2S_GetIntStatus(SPI_MASTER, SPI_I2S_INT_TE) != RESET) + { + /* Send SPI_MASTER data */ + SPI_I2S_TransmitData(SPI_MASTER, MASTER_Buffer_Tx[TxIdx++]); + + /* Disable SPI_MASTER TE interrupt */ + if (TxIdx == BufferSize) + { + SPI_I2S_EnableInt(SPI_MASTER, SPI_I2S_INT_TE, DISABLE); + } + } +} + +/** + * @brief This function handles SPI2 global interrupt request. + */ +void SPI2_IRQHandler(void) +{ + if(SPI_I2S_GetIntStatus(SPI_SLAVE, SPI_I2S_INT_RNE) != RESET) + { + /* Store SPI_SLAVE received data */ + SLAVE_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI_SLAVE);//SPI_SLAVE + } + +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/MDK-ARM/Simplex_Interrupt_MASTER.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/MDK-ARM/Simplex_Interrupt_MASTER.uvoptx new file mode 100644 index 0000000..71ea726 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/MDK-ARM/Simplex_Interrupt_MASTER.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/MDK-ARM/Simplex_Interrupt_MASTER.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/MDK-ARM/Simplex_Interrupt_MASTER.uvprojx new file mode 100644 index 0000000..8b3ae17 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/MDK-ARM/Simplex_Interrupt_MASTER.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Simplex_Interrupt + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Simplex_Interrupt.bin .\Objects\Simplex_Interrupt.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/inc/main.h new file mode 100644 index 0000000..2e7a70d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/inc/main.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#if 1 +#define SPI_MASTER SPI1 +#define SPI_MASTER_CLK RCC_APB2_PERIPH_SPI1 +#define SPI_MASTER_GPIO GPIOA +#define SPI_MASTER_GPIO_AF GPIO_AF1_SPI1 +#define SPI_MASTER_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define SPI_MASTER_PIN_SCK GPIO_PIN_1 +#define SPI_MASTER_PIN_MISO GPIO_PIN_3 +#define SPI_MASTER_PIN_MOSI GPIO_PIN_2 +#define SPI_MASTER_IRQn SPI1_IRQn +#else +#define SPI_MASTER SPI2 +#define SPI_MASTER_CLK RCC_APB2_PERIPH_SPI2 +#define SPI_MASTER_GPIO GPIOB +#define SPI_MASTER_GPIO_AF GPIO_AF2_SPI2 +#define SPI_MASTER_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define SPI_MASTER_PIN_SCK GPIO_PIN_1 +#define SPI_MASTER_PIN_MISO GPIO_PIN_3 +#define SPI_MASTER_PIN_MOSI GPIO_PIN_2 +#define SPI_MASTER_IRQn SPI2_IRQn +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/inc/n32wb03x_it.h new file mode 100644 index 0000000..6ae2916 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void SPI1_IRQHandler(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/readme.txt new file mode 100644 index 0000000..91fee63 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/readme.txt @@ -0,0 +1,23 @@ + +1. Function description + 1. SPI master mode single-wire interrupt send data + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock:64MHz + 2. GPIO: (Master mode DEMO board) SPI1: SCK--PA1, MOSI--PA2 + (Slave mode DEMO board) SPI1: SCK--PA1, MISO--PA3 + 3. Log print: slave mode DEMO board PB6(TX), baud rate: 115200 + Instructions: + 1. After compiling, download the program to reset and run; + 2. The slave mode DEMO board connects the serial port printing tool, power on, and check that the printing test is successful. + + +4. Matters needing attention + Two demo boards are required, one board to program the master mode program, one board to program the slave mode program, + the two boards need to be powered on together, and connect the VCC and GND of the two boards; + The "single wire" data lines are MOSI pins on the master side and MISO pins on the slave side. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/src/main.c new file mode 100644 index 0000000..ec10267 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/src/main.c @@ -0,0 +1,235 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup Simplex_Interrupt + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +#define BufferSize 32 + +SPI_InitType SPI_InitStructure; +uint8_t MASTER_Buffer_Tx[BufferSize] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20}; +uint8_t SLAVE_Buffer_Rx[BufferSize]; +__IO uint8_t TxIdx = 0, RxIdx = 0; +volatile TestStatus TransferStatus = FAILED; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + log_init(); + log_info("\n this is a SPI Simplex Interrupt master Demo.\n"); + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + + /* NVIC configuration ------------------------------------------------------*/ + NVIC_Configuration(); + + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + /* SPI_MASTER configuration ------------------------------------------------*/ + SPI_I2S_DeInit(SPI_MASTER); + SPI_InitStructure.DataDirection = SPI_DIR_SINGLELINE_TX; + SPI_InitStructure.SpiMode = SPI_MODE_MASTER; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_32; + SPI_InitStructure.FirstBit = SPI_FB_MSB; + SPI_InitStructure.CRCPoly = 7; + SPI_Init(SPI_MASTER, &SPI_InitStructure); + + /* Enable SPI_MASTER TE interrupt */ + SPI_I2S_EnableInt(SPI_MASTER, SPI_I2S_INT_TE, ENABLE); + + /* Enable SPI_MASTER */ + SPI_Enable(SPI_MASTER, ENABLE); + + while (1) + { + if(TxIdx == BufferSize) + { + TxIdx ++; + printf("send data end\r\n"); + } + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks --------------------------------------------------*/ + + /* Enable GPIO clock for SPI_MASTER */ + RCC_EnableAPB2PeriphClk(SPI_MASTER_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Enable SPI_MASTER Periph clock */ + RCC_EnableAPB2PeriphClk(SPI_MASTER_CLK , ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure SPI_MASTER pins: SCK and MOSI */ + GPIO_InitStructure.Pin = SPI_MASTER_PIN_SCK | SPI_MASTER_PIN_MOSI; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Alternate = SPI_MASTER_GPIO_AF; + GPIO_InitPeripheral(SPI_MASTER_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Configure and enable SPI_MASTER interrupt -------------------------------*/ + NVIC_InitStructure.NVIC_IRQChannel = SPI_MASTER_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 2; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/src/n32wb03x_it.c new file mode 100644 index 0000000..2bad77f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_MASTER/src/n32wb03x_it.c @@ -0,0 +1,164 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +#define BufferSize 32 +extern __IO uint8_t TxIdx, RxIdx; +extern uint8_t MASTER_Buffer_Tx[BufferSize], SPI_SLAVE_Buffer_Rx[BufferSize]; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles SPI1 global interrupt request. + */ + +void SPI1_IRQHandler(void) +{ + if (SPI_I2S_GetIntStatus(SPI_MASTER, SPI_I2S_INT_TE) != RESET) + { + /* Send SPI_MASTER data */ + SPI_I2S_TransmitData(SPI_MASTER, MASTER_Buffer_Tx[TxIdx++]); + + /* Disable SPI_MASTER TE interrupt */ + if (TxIdx == BufferSize) + { + SPI_I2S_EnableInt(SPI_MASTER, SPI_I2S_INT_TE, DISABLE); + } + } +} + +void SPI2_IRQHandler(void) +{ + if (SPI_I2S_GetIntStatus(SPI_MASTER, SPI_I2S_INT_TE) != RESET) + { + /* Send SPI_MASTER data */ + SPI_I2S_TransmitData(SPI_MASTER, MASTER_Buffer_Tx[TxIdx++]); + + /* Disable SPI_MASTER TE interrupt */ + if (TxIdx == BufferSize) + { + SPI_I2S_EnableInt(SPI_MASTER, SPI_I2S_INT_TE, DISABLE); + } + } +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/MDK-ARM/Simplex_Interrupt_SLAVE.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/MDK-ARM/Simplex_Interrupt_SLAVE.uvoptx new file mode 100644 index 0000000..71ea726 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/MDK-ARM/Simplex_Interrupt_SLAVE.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/MDK-ARM/Simplex_Interrupt_SLAVE.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/MDK-ARM/Simplex_Interrupt_SLAVE.uvprojx new file mode 100644 index 0000000..8b3ae17 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/MDK-ARM/Simplex_Interrupt_SLAVE.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Simplex_Interrupt + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Simplex_Interrupt.bin .\Objects\Simplex_Interrupt.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/inc/main.h new file mode 100644 index 0000000..702622e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/inc/main.h @@ -0,0 +1,102 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#if 1 +#define SPI_SLAVE SPI1 +#define SPI_SLAVE_CLK RCC_APB2_PERIPH_SPI1 +#define SPI_SLAVE_GPIO GPIOA +#define SPI_SLAVE_GPIO_AF GPIO_AF1_SPI1 +#define SPI_SLAVE_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define SPI_SLAVE_PIN_SCK GPIO_PIN_1 +#define SPI_SLAVE_PIN_MISO GPIO_PIN_3 +#define SPI_SLAVE_PIN_MOSI GPIO_PIN_2 +#define SPI_SLAVE_IRQn SPI1_IRQn +#else +#define SPI_SLAVE SPI2 +#define SPI_SLAVE_CLK RCC_APB2_PERIPH_SPI2 +#define SPI_SLAVE_GPIO GPIOB +#define SPI_SLAVE_GPIO_AF GPIO_AF2_SPI2 +#define SPI_SLAVE_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define SPI_SLAVE_PIN_SCK GPIO_PIN_1 +#define SPI_SLAVE_PIN_MISO GPIO_PIN_3 +#define SPI_SLAVE_PIN_MOSI GPIO_PIN_2 +#define SPI_SLAVE_IRQn SPI2_IRQn +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/inc/n32wb03x_it.h new file mode 100644 index 0000000..9a292de --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void SPI1_IRQHandler(void); +void SPI2_3_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/readme.txt new file mode 100644 index 0000000..31154a3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/readme.txt @@ -0,0 +1,23 @@ + +1. Function description + 1. SPI slave mode single-wire interrupt receive data + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. SystemClock:64MHz + 2. GPIO: (Master mode DEMO board) SPI1: SCK--PA1, MOSI--PA2 + (Slave mode DEMO board) SPI1: SCK--PA1, MISO--PA3 + 3. Log print: slave mode DEMO board PB6(TX), baud rate: 115200 + Instructions: + 1. After compiling, download the program to reset and run; + 2. The slave mode DEMO board connects the serial port printing tool, power on, and check that the printing test is successful. + + +4. Matters needing attention + Two demo boards are required, one board to program the master mode program, one board to program the slave mode program, + the two boards need to be powered on together, and connect the VCC and GND of the two boards; + The "single wire" data lines are MOSI pins on the master side and MISO pins on the slave side. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/src/main.c new file mode 100644 index 0000000..f04b645 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/src/main.c @@ -0,0 +1,273 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "log.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup Simplex_Interrupt + * @{ + */ + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +#define BufferSize 32 + +SPI_InitType SPI_InitStructure; +uint8_t MASTER_Buffer_Tx[BufferSize] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20}; +uint8_t SLAVE_Buffer_Rx[BufferSize]; +__IO uint8_t TxIdx = 0, RxIdx = 0; +volatile TestStatus TransferStatus = FAILED; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +void RCC_ConfigMcoPllClk(uint32_t RCC_MCOPLLCLKPrescaler) +{ + uint32_t tmpregister = 0; + /* Check the parameters */ + assert_param(IS_RCC_MCOPLLCLKPRE(RCC_MCOPLLCLKPrescaler)); + + tmpregister = RCC->CFG; + /* Clear MCOPRE[3:0] bits */ + tmpregister &= ((uint32_t)0x0FFFFFFF); + /* Set MCOPRE[3:0] bits according to RCC_ADCHCLKPrescaler value */ + tmpregister |= RCC_MCOPLLCLKPrescaler; + + /* Store the new value */ + RCC->CFG = tmpregister; +} + + + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + log_init(); + log_info("\n this is a SPI Simplex Interrupt SLAVE Demo.\n"); + /* System clocks configuration ---------------------------------------------*/ + RCC_Configuration(); + /* NVIC configuration ------------------------------------------------------*/ + NVIC_Configuration(); + + /* GPIO configuration ------------------------------------------------------*/ + GPIO_Configuration(); + + /* SPI_SLAVE configuration ------------------------------------------------*/ + SPI_I2S_DeInit(SPI_SLAVE); + SPI_InitStructure.DataDirection = SPI_DIR_SINGLELINE_RX; + SPI_InitStructure.SpiMode = SPI_MODE_SLAVE; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_16; + SPI_InitStructure.FirstBit = SPI_FB_MSB; + SPI_InitStructure.CRCPoly = 7; + SPI_Init(SPI_SLAVE, &SPI_InitStructure); + + /* Enable SPI_SLAVE RNE interrupt */ + SPI_I2S_EnableInt(SPI_SLAVE, SPI_I2S_INT_RNE, ENABLE); + + /* Enable SPI_SLAVE */ + SPI_Enable(SPI_SLAVE, ENABLE); + + /* Transfer procedure */ + while (RxIdx < BufferSize) + { + } + + if (RxIdx == BufferSize) + { + SPI_I2S_EnableInt(SPI_SLAVE, SPI_I2S_INT_RNE, DISABLE); + } + + log_buff(SLAVE_Buffer_Rx, RxIdx); + /* Check the correctness of written dada */ + TransferStatus = Buffercmp(SLAVE_Buffer_Rx, MASTER_Buffer_Tx, BufferSize); + /* TransferStatus = PASSED, if the transmitted and received data + are equal */ + /* TransferStatus = FAILED, if the transmitted and received data + are different */ + if(TransferStatus == PASSED) + { + log_info("SPI Simplex Interrupt SLAVE Demo test Succeed.\n"); + } + else + { + log_info("SPI Simplex Interrupt SLAVE Demo test Fail.\n"); + } + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable peripheral clocks --------------------------------------------------*/ + + /* Enable GPIO clock for SPI_SLAVE */ + RCC_EnableAPB2PeriphClk(SPI_SLAVE_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Enable SPI_SLAVE Periph clock */ + RCC_EnableAPB2PeriphClk(SPI_SLAVE_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure SPI_SLAVE pins: SCK and MISO*/ + GPIO_InitStructure.Pin = SPI_SLAVE_PIN_SCK | SPI_SLAVE_PIN_MISO; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Alternate = SPI_SLAVE_GPIO_AF; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitPeripheral(SPI_SLAVE_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Configure and enable SPI_SLAVE interrupt --------------------------------*/ + NVIC_InitStructure.NVIC_IRQChannel = SPI_SLAVE_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/src/n32wb03x_it.c new file mode 100644 index 0000000..fad6c76 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/SPI/Simplex_Interrupt_SLAVE/src/n32wb03x_it.c @@ -0,0 +1,160 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +#define BufferSize 32 +extern __IO uint8_t TxIdx, RxIdx; +extern uint8_t MASTER_Buffer_Tx[BufferSize], SLAVE_Buffer_Rx[BufferSize]; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/******************************************************************************/ + + +/** + * @brief This function handles SPI1 global interrupt request. + */ +void SPI1_IRQHandler(void) +{ + /* Store SPI_SLAVE received data */ + if(SPI1->STS & SPI_I2S_RNE_FLAG) + { + SLAVE_Buffer_Rx[RxIdx] = SPI1->DAT; + RxIdx++; + } +} + +void SPI2_IRQHandler(void) +{ + /* Store SPI_SLAVE received data */ + + if (SPI_I2S_GetIntStatus(SPI_SLAVE, SPI_I2S_INT_RNE) != RESET) + { + SLAVE_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI_SLAVE); + + /* Disable SPI_SLAVE RNE interrupt */ + if (RxIdx == BufferSize) + { + SPI_I2S_EnableInt(SPI_SLAVE, SPI_I2S_INT_RNE, DISABLE); + } + } + +} +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/MDK-ARM/6Steps.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/MDK-ARM/6Steps.uvoptx new file mode 100644 index 0000000..e5c9b96 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/MDK-ARM/6Steps.uvoptx @@ -0,0 +1,431 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_wwdg.c + n32wb03x_wwdg.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 17 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 18 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/MDK-ARM/6Steps.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/MDK-ARM/6Steps.uvprojx new file mode 100644 index 0000000..2c429a4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/MDK-ARM/6Steps.uvprojx @@ -0,0 +1,505 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + 6Steps + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\6Steps.bin .\Objects\6Steps.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER,USE_FULL_ASSERT=1 + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_wwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_wwdg.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/inc/n32wb03x_it.h new file mode 100644 index 0000000..bc336e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void TIM1_BRK_UP_TRG_COM_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/readme.txt new file mode 100644 index 0000000..bf97bc4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/readme.txt @@ -0,0 +1,31 @@ + +1. Function description + 1. systick triggers TIM1 for 100ms to output 6-step commutation waveform + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + System Configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M,TIM1 CLK=64M + 2. Interrupt: + TIM1 COM event interrupt on, priority 1 + Systick 100ms interrupt, priority 0 + 3. Port configuration: + PB8 is selected as TIM1 CH1 output + PB9 is selected as TIM1 CH2 output + PB10 is selected as TIM1 CH3 output + PB12 is selected as TIM1 CH1N output + PB13 is selected as TIM1 CH2N output + PA4 is selected as TIM1 CH3N output + PA6 is selected as TIM1 Breakin input + 4. TIM: + TIM1 6-channel complementary freeze output mode, no brake, open COM interrupt + Instructions: + 1. Open the debug mode after compiling, and observe the output waveform of TIM1 with an oscilloscope or logic analyzer + 2. The systick triggers the COM interrupt every 100ms, and outputs the 6-step commutation waveform of AB AC BC BA CA CB in the COM interrupt of the TIM + +4. Matters needing attention + TIM3_CH3N is PA4 which is for SWDCLK also, it will delay 2s when power on and then change PA4 to TIM3_CH3N. diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/src/main.c new file mode 100644 index 0000000..73d5e75 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/src/main.c @@ -0,0 +1,267 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_6Steps + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +TIM_BDTRInitType TIM_BDTRInitStructure; +uint16_t CCR1_Val = 32767; +uint16_t CCR2_Val = 24575; +uint16_t CCR3_Val = 16383; +uint16_t CCR4_Val = 8191; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void SysTick_Configuration(void); +void NVIC_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* please reset for next flash, and you have do flash it bfore the PA4 change as PWM IO */ + uint32_t dealy = 0x1E84800/2; + while(dealy--){} //delay few secoonds for SWD + + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC Configuration */ + NVIC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* SysTick Configuration */ + SysTick_Configuration(); + + /*----------------------------------------------------------------------------- + The n32wb03x TIM1 peripheral offers the possibility to program in advance the + configuration for the next TIM1 outputs behaviour (step) and change the configuration + of all the channels at the same time. This operation is possible when the COM + (commutation) event is used. + The COM event can be generated by software by setting the COM bit in the TIM1_EGR + register or by hardware (on TRC rising edge). + In this example, a software COM event is generated each 100 ms: using the Systick + interrupt. + The TIM1 is configured in Timing Mode, each time a COM event occurs, + a new TIM1 configuration will be set in advance. + The following Table describes the TIM1 Channels states: + ----------------------------------------------- + | Step1 | Step2 | Step3 | Step4 | Step5 | Step6 | + ---------------------------------------------------------- + |Channel1 | 1 | 0 | 0 | 0 | 0 | 1 | + ---------------------------------------------------------- + |Channel1N | 0 | 0 | 1 | 1 | 0 | 0 | + ---------------------------------------------------------- + |Channel2 | 0 | 0 | 0 | 1 | 1 | 0 | + ---------------------------------------------------------- + |Channel2N | 1 | 1 | 0 | 0 | 0 | 0 | + ---------------------------------------------------------- + |Channel3 | 0 | 1 | 1 | 0 | 0 | 0 | + ---------------------------------------------------------- + |Channel3N | 0 | 0 | 0 | 0 | 1 | 1 | + ---------------------------------------------------------- + -----------------------------------------------------------------------------*/ + + /* Time Base configuration */ + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_TimeBaseStructure.Period = 4095; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.RepetCnt = 0; + + TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure); + + /* Channel 1, 2 and 3 Configuration in PWM mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_TIMING; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.OutputNState = TIM_OUTPUT_NSTATE_ENABLE; + TIM_OCInitStructure.Pulse = 2047; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH; + TIM_OCInitStructure.OcNPolarity = TIM_OCN_POLARITY_HIGH; + TIM_OCInitStructure.OcIdleState = TIM_OC_IDLE_STATE_SET; + TIM_OCInitStructure.OcNIdleState = TIM_OCN_IDLE_STATE_SET; + TIM_InitOc1(TIM1, &TIM_OCInitStructure); + + TIM_OCInitStructure.Pulse = 1023; + TIM_InitOc2(TIM1, &TIM_OCInitStructure); + + TIM_OCInitStructure.Pulse = 511; + TIM_InitOc3(TIM1, &TIM_OCInitStructure); + + /* Automatic Output enable, Break, dead time and lock configuration*/ + TIM_BDTRInitStructure.OssrState = TIM_OSSR_STATE_ENABLE; + TIM_BDTRInitStructure.OssiState = TIM_OSSI_STATE_ENABLE; + TIM_BDTRInitStructure.LockLevel = TIM_LOCK_LEVEL_OFF; + TIM_BDTRInitStructure.DeadTime = 1; + TIM_BDTRInitStructure.Break = TIM_BREAK_IN_DISABLE; + TIM_BDTRInitStructure.BreakPolarity = TIM_BREAK_POLARITY_HIGH; + TIM_BDTRInitStructure.AutomaticOutput = TIM_AUTO_OUTPUT_ENABLE; + + TIM_ConfigBkdt(TIM1, &TIM_BDTRInitStructure); + + TIM_EnableCapCmpPreloadControl(TIM1, ENABLE); + + TIM_ConfigInt(TIM1, TIM_INT_COM, ENABLE); + + /* TIM1 counter enable */ + TIM_Enable(TIM1, ENABLE); + + /* Main Output Enable */ + TIM_EnableCtrlPwmOutputs(TIM1, ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* TIM1, GPIOA, GPIOB and AFIO clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1 | RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB + | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the TIM1 Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* TIM1 CHx:PB8,PB9,PB10 CHxN:PB12,PB13,PA4 */ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_12 | GPIO_PIN_13; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = GPIO_PIN_4 ; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + + /* GPIOB Configuration: BKIN pin */ + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); +} + +/** + * @brief Configures the SysTick. + */ +void SysTick_Configuration(void) +{ + /* Setup SysTick Timer for 100 msec interrupts */ + if (SysTick_Config((SystemCoreClock) / 10)) + { + /* Capture error */ + while (1) + ; + } + + NVIC_SetPriority(SysTick_IRQn, 0x0); +} + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the TIM1 Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/src/n32wb03x_it.c new file mode 100644 index 0000000..d07415a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/6Steps/src/n32wb03x_it.c @@ -0,0 +1,231 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +__IO uint32_t step = 1; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + /* Generate TIM1 COM event by software */ + TIM_GenerateEvent(TIM1, TIM_EVT_SRC_COM); +} + +/******************************************************************************/ +/* n32wb03x Peripherals Interrupt Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles TIM1 Break Update Trigger and commutation interrupts + * requests. + */ +void TIM1_BRK_UP_TRG_COM_IRQHandler(void) +{ + /* Clear TIM1 COM pending bit */ + TIM_ClrIntPendingBit(TIM1, TIM_INT_COM); + + if (step == 1) + { + /* Next step: Step 2 Configuration ---------------------------- */ + /* Channel3 configuration */ + TIM_EnableCapCmpCh(TIM1, TIM_CH_3, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_3, TIM_CAP_CMP_N_DISABLE); + + /* Channel1 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_1, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_1, TIM_CAP_CMP_ENABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_1, TIM_CAP_CMP_N_DISABLE); + + /* Channel2 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_2, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_2, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_2, TIM_CAP_CMP_N_ENABLE); + step++; + } + else if (step == 2) + { + /* Next step: Step 3 Configuration ---------------------------- */ + /* Channel2 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_2, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_2, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_2, TIM_CAP_CMP_N_ENABLE); + + /* Channel3 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_3, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_3, TIM_CAP_CMP_ENABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_3, TIM_CAP_CMP_N_DISABLE); + + /* Channel1 configuration */ + TIM_EnableCapCmpCh(TIM1, TIM_CH_1, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_1, TIM_CAP_CMP_N_DISABLE); + step++; + } + else if (step == 3) + { + /* Next step: Step 4 Configuration ---------------------------- */ + /* Channel3 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_3, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_3, TIM_CAP_CMP_ENABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_3, TIM_CAP_CMP_N_DISABLE); + + /* Channel2 configuration */ + TIM_EnableCapCmpCh(TIM1, TIM_CH_2, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_2, TIM_CAP_CMP_N_DISABLE); + + /* Channel1 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_1, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_1, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_1, TIM_CAP_CMP_N_ENABLE); + step++; + } + else if (step == 4) + { + /* Next step: Step 5 Configuration ---------------------------- */ + /* Channel3 configuration */ + TIM_EnableCapCmpCh(TIM1, TIM_CH_3, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_3, TIM_CAP_CMP_N_DISABLE); + + /* Channel1 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_1, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_1, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_1, TIM_CAP_CMP_N_ENABLE); + + /* Channel2 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_2, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_2, TIM_CAP_CMP_ENABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_2, TIM_CAP_CMP_N_DISABLE); + step++; + } + else if (step == 5) + { + /* Next step: Step 6 Configuration ---------------------------- */ + /* Channel3 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_3, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_3, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_3, TIM_CAP_CMP_N_ENABLE); + + /* Channel1 configuration */ + TIM_EnableCapCmpCh(TIM1, TIM_CH_1, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_1, TIM_CAP_CMP_N_DISABLE); + + /* Channel2 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_2, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_2, TIM_CAP_CMP_ENABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_2, TIM_CAP_CMP_N_DISABLE); + step++; + } + else + { + /* Next step: Step 1 Configuration ---------------------------- */ + /* Channel1 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_1, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_1, TIM_CAP_CMP_ENABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_2, TIM_CAP_CMP_N_DISABLE); + + /* Channel3 configuration */ + TIM_SelectOcMode(TIM1, TIM_CH_3, TIM_OCMODE_PWM1); + TIM_EnableCapCmpCh(TIM1, TIM_CH_3, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_3, TIM_CAP_CMP_N_ENABLE); + + /* Channel2 configuration */ + TIM_EnableCapCmpCh(TIM1, TIM_CH_2, TIM_CAP_CMP_DISABLE); + TIM_EnableCapCmpChN(TIM1, TIM_CH_2, TIM_CAP_CMP_N_DISABLE); + step = 1; + } +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/MDK-ARM/7PWM_Output.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/MDK-ARM/7PWM_Output.uvoptx new file mode 100644 index 0000000..b6dcd15 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/MDK-ARM/7PWM_Output.uvoptx @@ -0,0 +1,443 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_wwdg.c + n32wb03x_wwdg.c + 0 + 0 + + + 3 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 17 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 18 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 19 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/MDK-ARM/7PWM_Output.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/MDK-ARM/7PWM_Output.uvprojx new file mode 100644 index 0000000..8a721e1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/MDK-ARM/7PWM_Output.uvprojx @@ -0,0 +1,510 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + 7PWM_Output + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\7PWM_Output.bin .\Objects\7PWM_Output.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_wwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_wwdg.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/readme.txt new file mode 100644 index 0000000..3521308 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/readme.txt @@ -0,0 +1,29 @@ + +1. Function description + 1. TIM1 output 3 complementary waveforms and 1 CH4 waveform + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M,TIM1 CLK=64M + 2. Port configuration: + PB8 is selected as TIM1 CH1 output + PB9 is selected as TIM1 CH2 output + PB10 is selected as TIM1 CH3 output + PB11 is selected as TIM1 CH4 output + PB12 is selected as TIM1 CH1N output + PB13 is selected as TIM1 CH2N output + PA4 is selected as TIM1 CH3N output + 3. TIM: + TIM1 6 complementary outputs, CH4 output + + Instructions: + 1. Open debugging mode after compilation and use an oscilloscope or logic analyzer to observe the output waveform of TIM1 + 2. Output waveform TIM1 3-way complementary plus one CH4 + +4. Matters needing attention + TIM3_CH3N is PA4 which is for SWDCLK also, it will delay 2s when power on and then change PA4 to TIM3_CH3N. diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/src/main.c new file mode 100644 index 0000000..e2efac2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/src/main.c @@ -0,0 +1,217 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_7PWM_Output + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +uint16_t TimerPeriod = 0; +uint16_t Channel1Pulse = 0, Channel2Pulse = 0, Channel3Pulse = 0, Channel4Pulse = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); + +/** + * @brief intial timx program + */ +void TIM_Initial(TIM_Module* TIMx) +{ + /* TIMx Configuration --------------------------------------------------- + The objective is to generate 7 PWM signal at 17.57 KHz: + - TIMx_Period = (SystemCoreClock / 17570) - 1 + The channel 1 and channel 1N duty cycle is set to 50% + The channel 2 and channel 2N duty cycle is set to 37.5% + The channel 3 and channel 3N duty cycle is set to 25% + The channel 4 duty cycle is set to 12.5% + The Timer pulse is calculated as follows: + - ChannelxPulse = DutyCycle * (TIM1_Period - 1) / 100 + ----------------------------------------------------------------------- */ + /* Compute the value to be set in AR regiter to generate signal frequency at 17.57 Khz */ + TimerPeriod = (SystemCoreClock / 17570 ) - 1; + /* Compute CCDAT1 value to generate a duty cycle at 50% for channel 1 and 1N */ + Channel1Pulse = (uint16_t)(((uint32_t)5 * (TimerPeriod - 1)) / 10); + /* Compute CCDAT2 value to generate a duty cycle at 37.5% for channel 2 and 2N */ + Channel2Pulse = (uint16_t)(((uint32_t)375 * (TimerPeriod - 1)) / 1000); + /* Compute CCDAT3 value to generate a duty cycle at 25% for channel 3 and 3N */ + Channel3Pulse = (uint16_t)(((uint32_t)25 * (TimerPeriod - 1)) / 100); //12 + /* Compute CCDAT4 value to generate a duty cycle at 12.5% for channel 4 */ + Channel4Pulse = (uint16_t)(((uint32_t)125 * (TimerPeriod - 1)) / 1000); //6 + + /* Time Base configuration */ + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_TimeBaseStructure.Period = TimerPeriod; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.RepetCnt = 0; + + TIM_InitTimeBase(TIMx, &TIM_TimeBaseStructure); + + /* Channel 1, 2, 3, 4Configuration in PWM mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM2; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.OutputNState = TIM_OUTPUT_NSTATE_ENABLE; + TIM_OCInitStructure.Pulse = Channel1Pulse; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_LOW; + TIM_OCInitStructure.OcNPolarity = TIM_OCN_POLARITY_LOW; + TIM_OCInitStructure.OcIdleState = TIM_OC_IDLE_STATE_SET; + TIM_OCInitStructure.OcNIdleState = TIM_OC_IDLE_STATE_RESET; + TIM_InitOc1(TIMx, &TIM_OCInitStructure); + + TIM_OCInitStructure.Pulse = Channel2Pulse; + TIM_InitOc2(TIMx, &TIM_OCInitStructure); + + TIM_OCInitStructure.Pulse = Channel3Pulse; + TIM_InitOc3(TIMx, &TIM_OCInitStructure); + + TIM_OCInitStructure.Pulse = Channel4Pulse; + TIM_InitOc4(TIMx, &TIM_OCInitStructure); + + /* TIM1 counter enable */ + TIM_Enable(TIMx, ENABLE); + + /* TIM1 Main Output Enable */ + TIM_EnableCtrlPwmOutputs(TIMx, ENABLE); +} +/** + * @brief Main program + */ +int main(void) +{ + /* please reset for next flash, and you have do flash it bfore the PA4 change as PWM IO */ + uint32_t dealy = 0x1E84800/2; + while(dealy--){} //delay few secoonds for SWD + + /* System Clocks Configuration */ + RCC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + TIM_Initial(TIM1); + while (1) + { + + } +} + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* TIM1, GPIOA, GPIOB, GPIOE and AFIO clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB + | RCC_APB2_PERIPH_TIM1 + | RCC_APB2_PERIPH_AFIO, + ENABLE); + /* When debug ,TIM1 stop */ +// DBG_ConfigPeriph(DBG_TIM1_STOP , ENABLE); +} + +/** + * @brief Configure the TIM1 Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* TIM1 CHx:PB8,PB9,PB10,PB11 CHxN:PB12,PB13,PA4 */ + GPIO_InitStructure.Pin = GPIO_PIN_4 ; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/src/n32wb03x_it.c new file mode 100644 index 0000000..c40ee2b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/7PWM_Output/src/n32wb03x_it.c @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/MDK-ARM/Cascade_Synchro.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/MDK-ARM/Cascade_Synchro.uvoptx new file mode 100644 index 0000000..9c0c813 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/MDK-ARM/Cascade_Synchro.uvoptx @@ -0,0 +1,335 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/MDK-ARM/Cascade_Synchro.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/MDK-ARM/Cascade_Synchro.uvprojx new file mode 100644 index 0000000..237479f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/MDK-ARM/Cascade_Synchro.uvprojx @@ -0,0 +1,465 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Cascade_Synchro + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Cascade_Synchro.bin .\Objects\Cascade_Synchro.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/readme.txt new file mode 100644 index 0000000..006acaf --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/readme.txt @@ -0,0 +1,23 @@ + +1. Function description + 1. TIM1 cycle gated TIM3 + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M,TIM1 CLK=64M + 2. Port configuration: + PB8 is selected as TIM1 CH1 output + PB4 is selected as TIM3 CH1 output + 3. TIM: + TIM1 cycle gating TIM3 + Instructions: + 1. Open debugging mode after compilation and observe TIM1 CH1, TIM3 CH1 waveforms with an oscilloscope or logic analyzer + 2. TIM3 4 times cycle TIM1 + +4. Matters needing attention + None \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/src/main.c new file mode 100644 index 0000000..6ef17d1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/src/main.c @@ -0,0 +1,188 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_Cascade_Synchro + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; + +void RCC_Configuration(void); +void GPIO_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* Timers synchronisation in cascade mode */ + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 255; + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure); + + TIM_TimeBaseStructure.Period = 3; + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* Master Configuration in PWM1 Mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM1; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = 64; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH; + TIM_InitOc1(TIM1, &TIM_OCInitStructure); + + /* Select the Master Slave Mode */ + TIM_SelectMasterSlaveMode(TIM1, TIM_MASTER_SLAVE_MODE_ENABLE); + + /* Master Mode selection */ + TIM_SelectOutputTrig(TIM1, TIM_TRGO_SRC_UPDATE); + + /* Slaves Configuration: PWM1 Mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM1; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = 1; + TIM_InitOc1(TIM3, &TIM_OCInitStructure); + + /* Slave Mode selection: TIM3 */ + TIM_SelectSlaveMode(TIM3, TIM_SLAVE_MODE_GATED); + TIM_SelectInputTrig(TIM3, TIM_TRIG_SEL_IN_TR0); + + /* Select the Master Slave Mode */ + TIM_SelectMasterSlaveMode(TIM3, TIM_MASTER_SLAVE_MODE_ENABLE); + + /* Master Mode selection: TIM3 */ + TIM_SelectOutputTrig(TIM3, TIM_TRGO_SRC_UPDATE); + + /* TIM enable counter */ + TIM_EnableCtrlPwmOutputs(TIM1,ENABLE); + TIM_Enable(TIM1, ENABLE); + TIM_Enable(TIM3, ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* TIM1 GPIOB and AFIO clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1 | RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the GPIOD Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOB Configuration: PB8(TIM1 CH1) as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_8; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + /* GPIOB Configuration: PB4(TIM3 CH1) as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_4; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Cascade_Synchro/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/MDK-ARM/ComplementarySignals.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/MDK-ARM/ComplementarySignals.uvoptx new file mode 100644 index 0000000..d6bbedd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/MDK-ARM/ComplementarySignals.uvoptx @@ -0,0 +1,383 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 12 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 13 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 14 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/MDK-ARM/ComplementarySignals.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/MDK-ARM/ComplementarySignals.uvprojx new file mode 100644 index 0000000..be6db03 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/MDK-ARM/ComplementarySignals.uvprojx @@ -0,0 +1,485 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Complementary + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Complementary.bin .\Objects\Complementary.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/readme.txt new file mode 100644 index 0000000..87dc94f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/readme.txt @@ -0,0 +1,27 @@ + +1. Function description + 1. TIM1 output 3 complementary waveforms + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M,TIM1 CLK=64M + 2. Port configuration: + PB8 is selected as TIM1 CH1 output + PB9 is selected as TIM1 CH2 output + PB10 is selected as TIM1 CH3 output + PB12 is selected as TIM1 CH1N output + PB13 is selected as TIM1 CH2N output + PA4 is selected as TIM1 CH3N output + PA6 is selected as TIM1 Breakin input + 3. TIM: + TIM1 6 Complementary with dead-time, with IOM Brake + Instructions: + 1. Open debugging mode after compilation and observe TIM1 waveform with oscilloscope or logic analyzer + 2. 3 complementary waveforms can be observed, and the output of PB12 pin can be turned off when the pin is high +4. Matters needing attention + TIM3_CH3N is PA4 which is for SWDCLK also, it will delay 2s when power on and then change PA4 to TIM3_CH3N. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/src/main.c new file mode 100644 index 0000000..9a79c30 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/src/main.c @@ -0,0 +1,230 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_ComplementarySignals + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +TIM_BDTRInitType TIM_BDTRInitStructure; +uint16_t TimerPeriod = 0; +uint16_t Channel1Pulse = 0, Channel2Pulse = 0, Channel3Pulse = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* please reset for next flash, and you have do flash it bfore the PA4 change as PWM IO */ + uint32_t dealy = 0x1E84800/2; + while(dealy--){} //delay few secoonds for SWD + + /* System Clocks Configuration */ + RCC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* ----------------------------------------------------------------------- + TIM1 Configuration to: + + 1/ Generate 3 complementary PWM signals with 3 different duty cycles: + TIM1CLK is fixed to SystemCoreClock, the TIM1 Prescaler is equal to 0 so the + TIM1 counter clock used is SystemCoreClock. + * SystemCoreClock is set to 64 MHz. + + The objective is to generate PWM signal at 17.57 KHz: + - TIM1_Period = (SystemCoreClock / 17570) - 1 + + The Three Duty cycles are computed as the following description: + + The channel 1 and channel 1N duty cycle is set to 50% + The channel 2 and channel 2N duty cycle is set to 25% + The channel 3 and channel 3N duty cycle is set to 12.5% + + The Timer pulse is calculated as follows: + - ChannelxPulse = DutyCycle * (TIM1_Period - 1) / 100 + + 2/ Insert a dead time equal to 11/SystemCoreClock ns + 3/ Configure the break feature, active at High level, and using the automatic + output enable feature + 4/ Use the Locking parameters level1. + ----------------------------------------------------------------------- */ + + /* Compute the value to be set in AR register to generate signal frequency at 17.57 Khz */ + TimerPeriod = (SystemCoreClock / 17570) - 1; + /* Compute CCDAT1 value to generate a duty cycle at 50% for channel 1 */ + Channel1Pulse = (uint16_t)(((uint32_t)5 * (TimerPeriod - 1)) / 10); + /* Compute CCDAT2 value to generate a duty cycle at 25% for channel 2 */ + Channel2Pulse = (uint16_t)(((uint32_t)25 * (TimerPeriod - 1)) / 100); + /* Compute CCDAT3 value to generate a duty cycle at 12.5% for channel 3 */ + Channel3Pulse = (uint16_t)(((uint32_t)125 * (TimerPeriod - 1)) / 1000); + + /* Time Base configuration */ + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_TimeBaseStructure.Period = TimerPeriod; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.RepetCnt = 0; + + TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure); + + /* Channel 1, 2 and 3 Configuration in PWM mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM2; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.OutputNState = TIM_OUTPUT_NSTATE_ENABLE; + TIM_OCInitStructure.Pulse = Channel1Pulse; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_LOW; + TIM_OCInitStructure.OcNPolarity = TIM_OCN_POLARITY_LOW; + TIM_OCInitStructure.OcIdleState = TIM_OC_IDLE_STATE_SET; + TIM_OCInitStructure.OcNIdleState = TIM_OC_IDLE_STATE_RESET; + TIM_InitOc1(TIM1, &TIM_OCInitStructure); + + TIM_OCInitStructure.Pulse = Channel2Pulse; + TIM_InitOc2(TIM1, &TIM_OCInitStructure); + + TIM_OCInitStructure.Pulse = Channel3Pulse; + TIM_InitOc3(TIM1, &TIM_OCInitStructure); + + /* Automatic Output enable, Break, dead time and lock configuration*/ + TIM_BDTRInitStructure.OssrState = TIM_OSSR_STATE_ENABLE; + TIM_BDTRInitStructure.OssiState = TIM_OSSI_STATE_ENABLE; + TIM_BDTRInitStructure.LockLevel = TIM_LOCK_LEVEL_1; + TIM_BDTRInitStructure.DeadTime = 110; + TIM_BDTRInitStructure.Break = TIM_BREAK_IN_ENABLE; + TIM_BDTRInitStructure.BreakPolarity = TIM_BREAK_POLARITY_HIGH; + TIM_BDTRInitStructure.AutomaticOutput = TIM_AUTO_OUTPUT_ENABLE; + TIM_BDTRInitStructure.IomBreakEn = true; + TIM_ConfigBkdt(TIM1, &TIM_BDTRInitStructure); + + /* TIM1 counter enable */ + TIM_Enable(TIM1, ENABLE); + + /* Main Output Enable */ + TIM_EnableCtrlPwmOutputs(TIM1, ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* TIM1, GPIOA, GPIOB, GPIOE and AFIO clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1 | RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB + | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the TIM1 Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* TIM1 CHx:PB8,PB9,PB10 CHxN:PB12,PB13,PA4 */ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_12 | GPIO_PIN_13; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = GPIO_PIN_4 ; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + + /* GPIOB Configuration: BKIN pin */ + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ComplementarySignals/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/MDK-ARM/DMA.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/MDK-ARM/DMA.uvoptx new file mode 100644 index 0000000..30acaae --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/MDK-ARM/DMA.uvoptx @@ -0,0 +1,395 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 13 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 14 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 15 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/MDK-ARM/DMA.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/MDK-ARM/DMA.uvprojx new file mode 100644 index 0000000..4919bf3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/MDK-ARM/DMA.uvprojx @@ -0,0 +1,490 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + TIM_DMA + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\TIM_DMA.bin .\Objects\TIM_DMA.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/readme.txt new file mode 100644 index 0000000..b8e3976 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/readme.txt @@ -0,0 +1,25 @@ + +1. Functional description + 1. TIM1 CH3 CH3N complementary signal changes duty cycle every 6 cycles + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M,TIM1 CLK=64M + 2. Port configuration: + PB8 selected as TIM1 CH1 Output + PB12 selected as TIM1 CH1N Output + 3. TIM: + TIM1 CH1 CH1N complementary output triggers DMA transmission every 6 cycles + 4. DMA: + DMA1_ CH5 Channel circular mode handling 3 half-Word SRC_ Buffer[3] variable to TIM1 CCDAT3 register + Instructions: + 1. After compiling, turn on the debug mode, use an oscilloscope or logic analyzer to observe the waveform of TIM1 CH1 CH1N + 2. Change the duty cycle of CH1 and CH1N once in 6 cycles of TIM1, and change cyclically + +4. Matters needing attention + None diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/src/main.c new file mode 100644 index 0000000..a9841e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/src/main.c @@ -0,0 +1,219 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_DMA + * @{ + */ + +#define TIM1_CCR3_Address 0x40012C3C + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +uint16_t SRC_Buffer[3] = {0, 0, 0}; +uint16_t TimerPeriod = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void DMA_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* DMA Configuration */ + DMA_Configuration(); + + /* TIM1 DMA Transfer example */ + /* Compute the value to be set in AR register to generate signal frequency at 17.57 Khz */ + TimerPeriod = (SystemCoreClock / 17570) - 1; + /* Compute CCDAT1 value to generate a duty cycle at 50% */ + SRC_Buffer[0] = (uint16_t)(((uint32_t)5 * (TimerPeriod - 1)) / 10); + /* Compute CCDAT1 value to generate a duty cycle at 37.5% */ + SRC_Buffer[1] = (uint16_t)(((uint32_t)375 * (TimerPeriod - 1)) / 1000); + /* Compute CCDAT1 value to generate a duty cycle at 25% */ + SRC_Buffer[2] = (uint16_t)(((uint32_t)25 * (TimerPeriod - 1)) / 100); + + /* TIM1 Peripheral Configuration --------------------------------------------*/ + /* Time Base configuration */ + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_TimeBaseStructure.Period = TimerPeriod; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.RepetCnt = 5; + + TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure); + + /* Channel 3 Configuration in PWM mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM2; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.OutputNState = TIM_OUTPUT_NSTATE_ENABLE; + TIM_OCInitStructure.Pulse = SRC_Buffer[0]; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_LOW; + TIM_OCInitStructure.OcNPolarity = TIM_OCN_POLARITY_LOW; + TIM_OCInitStructure.OcIdleState = TIM_OC_IDLE_STATE_SET; + TIM_OCInitStructure.OcNIdleState = TIM_OC_IDLE_STATE_RESET; + + TIM_InitOc1(TIM1, &TIM_OCInitStructure); + + /* TIM1 Update DMA Request enable */ + TIM_EnableDma(TIM1, TIM_DMA_UPDATE, ENABLE); + + /* TIM1 counter enable */ + TIM_Enable(TIM1, ENABLE); + + /* Main Output Enable */ + TIM_EnableCtrlPwmOutputs(TIM1, ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* TIM1 GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1 | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configure the TIM1 Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOB Configuration: Channel 1 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_8; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + /* GPIOB Configuration: Channel 1N as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_12; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* DMA Channel5 Config */ + DMA_DeInit(DMA_CH5); + + DMA_InitStructure.PeriphAddr = (uint32_t)&TIM1->CCDAT1; //TIM1_CCR1_Address; + DMA_InitStructure.MemAddr = (uint32_t)SRC_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = 3; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.Priority = DMA_PRIORITY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + + DMA_Init(DMA_CH5, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_TIM1_UP, DMA, DMA_CH5, ENABLE); + /* DMA Channel5 enable */ + DMA_EnableChannel(DMA_CH5, ENABLE); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMA/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/MDK-ARM/DMABurst.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/MDK-ARM/DMABurst.uvoptx new file mode 100644 index 0000000..7bdd535 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/MDK-ARM/DMABurst.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/MDK-ARM/DMABurst.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/MDK-ARM/DMABurst.uvprojx new file mode 100644 index 0000000..ba6da88 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/MDK-ARM/DMABurst.uvprojx @@ -0,0 +1,500 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + TIM_DMA_Burst + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\TIM_DMA_Burst.bin .\Objects\TIM_DMA_Burst.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/readme.txt new file mode 100644 index 0000000..cc6493c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/readme.txt @@ -0,0 +1,23 @@ + +1. Function description + 1. TIM1 changes the period and duty cycle at the same time after one cycle + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M,TIM1 CLK=64M + 2. Port configuration: + PA8 is selected as TIM1 CH1 output + 3. TIM: + TIM1 CH1 output, periodically triggered DMA burst transmission, loading AR, REPCNT, CCDAT1 registers, changing duty cycle, period and repeat counter + 4. DMA: + The DMA1_CH5 channel in normal mode transfers 3 half-word SRC_Buffer[3] variables to the TIM1 DMA register + Instructions: + 1. Open debugging mode after compilation and observe TIM1 CH 1 waveform with oscilloscope or logic analyzer + 2. After the first cycle of TIM1 is over, the following waveforms are the waveforms of changing cycle and duty cycle of DMA transport +4. Matters needing attention + None diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/src/main.c new file mode 100644 index 0000000..5454452 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/src/main.c @@ -0,0 +1,191 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_DMABurst + * @{ + */ + +#define TIM1_DMAR_ADDRESS ((uint32_t)0x40012C4C) /* TIM AR (Auto Reload Register) address */ + +GPIO_InitType GPIO_InitStructure; +DMA_InitType DMA_InitStructure; +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +uint16_t SRC_Buffer[6] = {0x0FFF, 0x0000, 0x0800}; +uint16_t DmaAgain = 0; + +/** + * @brief Main program + */ +int main(void) +{ + /* TIM1 and GPIOA clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1 | RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOB Configuration: Channel 1 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_8; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + /* TIM1 DeInit */ + TIM_DeInit(TIM1); + + /* DMA Channel5 Config */ + DMA_DeInit(DMA_CH5); + DMA_InitStructure.PeriphAddr = (uint32_t)&TIM1->DADDR; //TIM1_DMAR_ADDRESS; + DMA_InitStructure.MemAddr = (uint32_t)SRC_Buffer; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = 3; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(DMA_CH5, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_TIM1_UP,DMA,DMA_CH5,ENABLE); + + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 0xFFFF; + TIM_TimeBaseStructure.Prescaler = (uint16_t)(SystemCoreClock / 24000000) - 1; + TIM_TimeBaseStructure.ClkDiv = 0x0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure); + + /* TIM Configuration in PWM Mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM1; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = 0xFFF; + TIM_InitOc1(TIM1, &TIM_OCInitStructure); + + /* TIM1 DADDR Base register and DMA Burst Length Config */ + TIM_ConfigDma(TIM1, TIM_DMABASE_AR, TIM_DMABURST_LENGTH_3TRANSFERS); + + /* TIM1 DMA Update enable */ + TIM_EnableDma(TIM1, TIM_DMA_UPDATE, ENABLE); + + /* TIM1 enable */ + TIM_Enable(TIM1, ENABLE); + + /* TIM1 PWM Outputs Enable */ + TIM_EnableCtrlPwmOutputs(TIM1, ENABLE); + + /* DMA Channel5 enable */ + DMA_EnableChannel(DMA_CH5, ENABLE); + + /* Wait until DMA Channel5 end of Transfer */ + while (!DMA_GetFlagStatus(DMA_FLAG_TC5, DMA)) + { + } + + DMA_ClearFlag(DMA_FLAG_GL5 | DMA_FLAG_TC5 | DMA_FLAG_HT5 | DMA_FLAG_TE5, DMA); + /* Infinite loop */ + while (1) + { + if(DmaAgain) + { + DmaAgain = 0; + DMA_DeInit(DMA_CH5); + DMA_Init(DMA_CH5, &DMA_InitStructure); + DMA_RequestRemap(DMA_REMAP_TIM1_UP,DMA,DMA_CH5,ENABLE); + + TIM_ConfigDma(TIM1, TIM_DMABASE_AR, TIM_DMABURST_LENGTH_3TRANSFERS); + TIM_EnableDma(TIM1, TIM_DMA_UPDATE, ENABLE); + + /* DMA Channel5 enable */ + DMA_EnableChannel(DMA_CH5, ENABLE); + + /* Wait until DMA Channel5 end of Transfer */ + while (!DMA_GetFlagStatus(DMA_FLAG_TC5, DMA)) + { + } + + DMA_ClearFlag(DMA_FLAG_GL5 | DMA_FLAG_TC5 | DMA_FLAG_HT5 | DMA_FLAG_TE5, DMA); + } + + } +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} +#endif + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/DMABurst/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/MDK-ARM/ExtTrigger_Synchro.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/MDK-ARM/ExtTrigger_Synchro.uvoptx new file mode 100644 index 0000000..495ee94 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/MDK-ARM/ExtTrigger_Synchro.uvoptx @@ -0,0 +1,431 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_wwdg.c + n32wb03x_wwdg.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 17 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 18 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/MDK-ARM/ExtTrigger_Synchro.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/MDK-ARM/ExtTrigger_Synchro.uvprojx new file mode 100644 index 0000000..302def0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/MDK-ARM/ExtTrigger_Synchro.uvprojx @@ -0,0 +1,505 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Extrigger + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Extrigger.bin .\Objects\Extrigger.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_wwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_wwdg.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/readme.txt new file mode 100644 index 0000000..9ede78e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + 1. TIM1 CH2 gated CH1 and TIM3 + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M,TIM1 CLK=64M, TIM3 CLK=64M + 2. Port configuration: + PB8 is selected as TIM1 CH1 output + PB9 is selected as TIM1 CH2 input + PB4 is selected as TIM3 CH1 output + 3. TIM: + TIM1 CH2 Gated CH1, Gated TIM3 + Instructions: + 1. Open debugging mode after compilation and observe TIM1 CH1, TIM3 CH1 waveforms with an oscilloscope or logic analyzer + 2. TIM1 CH2 high level timer starts counting, low level stops + +4. Matters needing attention + None \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/src/main.c new file mode 100644 index 0000000..fa0780b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/src/main.c @@ -0,0 +1,201 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_ExtTrigger_Synchro + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +TIM_ICInitType TIM_ICInitStructure; +OCInitType TIM_OCInitStructure; + +void RCC_Configuration(void); +void GPIO_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* Timers synchronisation in cascade mode with an external trigger */ + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 100; + TIM_TimeBaseStructure.Prescaler = 2-1; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure); + + TIM_TimeBaseStructure.Period = 100; + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* Master Configuration in Toggle Mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_TOGGLE; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH; + TIM_InitOc1(TIM1, &TIM_OCInitStructure); + + /* TIM1 Input Capture Configuration */ + TIM_ICInitStructure.Channel = TIM_CH_2; + TIM_ICInitStructure.IcPolarity = TIM_IC_POLARITY_RISING; + TIM_ICInitStructure.IcSelection = TIM_IC_SELECTION_DIRECTTI; + TIM_ICInitStructure.IcPrescaler = TIM_IC_PSC_DIV1; + TIM_ICInitStructure.IcFilter = 0; + TIM_ICInit(TIM1, &TIM_ICInitStructure); + + /* TIM1 Input trigger configuration: External Trigger connected to TI2 */ + TIM_SelectInputTrig(TIM1, TIM_TRIG_SEL_TI2FP2); + TIM_SelectSlaveMode(TIM1, TIM_SLAVE_MODE_GATED); + + /* Select the Master Slave Mode */ + TIM_SelectMasterSlaveMode(TIM1, TIM_MASTER_SLAVE_MODE_ENABLE); + + /* Master Mode selection: TIM1 */ + TIM_SelectOutputTrig(TIM1, TIM_TRGO_SRC_ENABLE); + + /* Slaves Configuration: Toggle Mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_TOGGLE; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_InitOc1(TIM3, &TIM_OCInitStructure); + + /* Slave Mode selection: TIM3 */ + TIM_SelectInputTrig(TIM3, TIM_TRIG_SEL_IN_TR0); + TIM_SelectSlaveMode(TIM3, TIM_SLAVE_MODE_GATED); + + /* Select the Master Slave Mode */ + TIM_SelectMasterSlaveMode(TIM3, TIM_MASTER_SLAVE_MODE_ENABLE); + + /* Master Mode selection: TIM3 */ + TIM_SelectOutputTrig(TIM3, TIM_TRGO_SRC_ENABLE); + + /* TIM1 Main Output Enable */ + TIM_EnableCtrlPwmOutputs(TIM1, ENABLE); + + /* TIM enable counter */ + TIM_Enable(TIM1, ENABLE); + TIM_Enable(TIM3, ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3 , ENABLE); + + /* TIM1 and GPIOB clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1 | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the GPIO Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOB Configuration: PB.08(TIM1 CH1) and PB.09(TIM1 CH2) as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_8 | GPIO_PIN_9; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + //PB.04(TIM3 CH1) + GPIO_InitStructure.Pin = GPIO_PIN_4; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/ExtTrigger_Synchro/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/MDK-ARM/InputCapture.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/MDK-ARM/InputCapture.uvoptx new file mode 100644 index 0000000..58dda89 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/MDK-ARM/InputCapture.uvoptx @@ -0,0 +1,407 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/MDK-ARM/InputCapture.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/MDK-ARM/InputCapture.uvprojx new file mode 100644 index 0000000..dd383f4 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/MDK-ARM/InputCapture.uvprojx @@ -0,0 +1,495 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + InputCapture + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\InputCapture.bin .\Objects\InputCapture.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/inc/n32wb03x_it.h new file mode 100644 index 0000000..15f5fba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +void TIM3_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/readme.txt new file mode 100644 index 0000000..94c7c5b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/readme.txt @@ -0,0 +1,25 @@ + +1. Function description + 1. TIM3 CH2 rising edge calculation frequency + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M,TIM3 CLK=64M + 2. Interruption: + TIM3 CH2 rising edge interrupt open, priority 1 + 3. Port configuration: + PB5 is selected as TIM3 CH2 input + PA6 is selected as IO output + 4. TIM: + TIM3 CH2 rising edge capture interrupt is opened +Usage method: + 1. Open debugging mode after compilation, connect PB5 to PA6, add variables TIM3Freq, gOnePulsEn to the watch window + 2. Default gOnePulsEn=0, each time you manually give gOnePulsEn=1, you can see the frequency value calculated by TIM3Freq + +4. Matters needing attention + None diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/src/main.c new file mode 100644 index 0000000..52f5e78 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/src/main.c @@ -0,0 +1,221 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_Input_Capture + * @{ + */ + +TIM_ICInitType TIM_ICInitStructure; +uint16_t gOnePulsEn = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +void GenTwoRisingEdge(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC configuration */ + NVIC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* TIM3 configuration: Input Capture mode --------------------- + The external signal is connected to TIM3 CH2 pin (PB.05) + The Rising edge is used as active edge, + The TIM3 CCDAT2 is used to compute the frequency value + + gOnePulsEn = 1,will do GenTwoRisingEdge + then + see Capture that is dist time + ------------------------------------------------------------ */ + + TIM_ICInitStructure.Channel = TIM_CH_2; + TIM_ICInitStructure.IcPolarity = TIM_IC_POLARITY_RISING; + TIM_ICInitStructure.IcSelection = TIM_IC_SELECTION_DIRECTTI; + TIM_ICInitStructure.IcPrescaler = TIM_IC_PSC_DIV1; + TIM_ICInitStructure.IcFilter = 0x0; + + TIM_ICInit(TIM3, &TIM_ICInitStructure); + + /* TIM enable counter */ + TIM_Enable(TIM3, ENABLE); + + /* Enable the CC2 Interrupt Request */ + TIM_ConfigInt(TIM3, TIM_INT_CC2, ENABLE); + + while (1) + { + GenTwoRisingEdge(); + } +} + +// generation two rising edge +void GenTwoRisingEdge(void) +{ + if (gOnePulsEn) + { + gOnePulsEn = 0; + GPIO_SetBits(GPIOA, GPIO_PIN_6); + { + uint32_t i = 0; + while (i++ < 50) + ; + } + GPIO_ResetBits(GPIOA, GPIO_PIN_6); + { + uint32_t i = 0; + while (i++ < 500) + ; + } + + GPIO_SetBits(GPIOA, GPIO_PIN_6); + { + uint32_t i = 0; + while (i++ < 50) + ; + } + GPIO_ResetBits(GPIOA, GPIO_PIN_6); + { + uint32_t i = 0; + while (i++ < 500) + ; + } + } +} +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIOA and GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA|RCC_APB2_PERIPH_GPIOB, ENABLE); +} + +/** + * @brief Configure the GPIOA Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* TIM3 channel 2 pin (PB.05) configuration */ + GPIO_InitStructure.Pin = GPIO_PIN_5; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + GPIO_InitStruct(&GPIO_InitStructure); + + // PA6 + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the TIM3 global Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/src/n32wb03x_it.c new file mode 100644 index 0000000..7aac319 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture/src/n32wb03x_it.c @@ -0,0 +1,159 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +__IO uint16_t IC3ReadValue1 = 0, IC3ReadValue2 = 0; +__IO uint16_t CaptureNumber = 0; +__IO uint32_t Capture = 0; +__IO uint32_t TIM3Freq = 0; +__IO uint32_t TIM3EnterIrqCnt = 0; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles TIM3 global interrupt request. + */ +void TIM3_IRQHandler(void) +{ + if (TIM_GetIntStatus(TIM3, TIM_INT_CC2) == SET) + { + TIM3EnterIrqCnt++; + /* Clear TIM3 Capture compare interrupt pending bit */ + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC2); + if (CaptureNumber == 0) + { + /* Get the Input Capture value */ + IC3ReadValue1 = TIM_GetCap2(TIM3); + CaptureNumber = 1; + } + else if (CaptureNumber == 1) + { + /* Get the Input Capture value */ + IC3ReadValue2 = TIM_GetCap2(TIM3); + + /* Capture computation */ + if (IC3ReadValue2 > IC3ReadValue1) + { + Capture = (IC3ReadValue2 - IC3ReadValue1); + } + else + { + Capture = ((0xFFFF - IC3ReadValue1) + IC3ReadValue2); + } + /* Frequency computation */ + TIM3Freq = (uint32_t)SystemCoreClock / Capture; + CaptureNumber = 0; + } + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/MDK-ARM/InputCapture_DualEdge.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/MDK-ARM/InputCapture_DualEdge.uvoptx new file mode 100644 index 0000000..58dda89 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/MDK-ARM/InputCapture_DualEdge.uvoptx @@ -0,0 +1,407 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/MDK-ARM/InputCapture_DualEdge.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/MDK-ARM/InputCapture_DualEdge.uvprojx new file mode 100644 index 0000000..180247e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/MDK-ARM/InputCapture_DualEdge.uvprojx @@ -0,0 +1,495 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + InputCapture_DualEdge + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\InputCapture_DualEdge.bin .\Objects\InputCapture_DualEdge.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/inc/n32wb03x_it.h new file mode 100644 index 0000000..15f5fba --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +void TIM3_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/readme.txt new file mode 100644 index 0000000..f40faff --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + 1. TIM3 CH2 pin, CH2 rising edge, CH1 falling edge to calculate the frequency + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM3 CLK=64M + 2. Interruption: + TIM3 CH2 rising edge CH1 falling edge interrupt on, priority 1 + 3. Port configuration: + PB5 is selected TIM3 CH2 Input + PA6 is selected IO Output + 4. TIM: + TIM3 CH2 rising edge, CH1 falling edge capture interrupt is turned on +Usage method: + 1. Open debugging mode after compilation, connect PA3 to PA7, add variables TIM3Freq, gOnePulsEn to the watch window + 2. Default gOnePulsEn=0, each time you manually give gOnePulsEn=1, you can see the frequency value calculated by TIM3Freq +4. Matters needing attention + None diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/src/main.c new file mode 100644 index 0000000..0652346 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/src/main.c @@ -0,0 +1,226 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_Input_Capture + * @{ + */ + +TIM_ICInitType TIM_ICInitStructure; +uint16_t gOnePulsEn = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +void GenTwoRisingEdge(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC configuration */ + NVIC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* TIM3 configuration: Input Capture mode --------------------- + The TIM3 CCDAT1+CCDAT2 is used to compute the frequency value + + gOnePulsEn = 1,will do GenTwoRisingEdge + then + see Capture that is dist time + ------------------------------------------------------------ */ + + TIM_ICInitStructure.Channel = TIM_CH_2; + TIM_ICInitStructure.IcPolarity = TIM_IC_POLARITY_RISING; + TIM_ICInitStructure.IcSelection = TIM_IC_SELECTION_DIRECTTI; + TIM_ICInitStructure.IcPrescaler = TIM_IC_PSC_DIV1; + TIM_ICInitStructure.IcFilter = 0x0; + TIM_ICInit(TIM3, &TIM_ICInitStructure); + + TIM_ICInitStructure.Channel = TIM_CH_1; + TIM_ICInitStructure.IcPolarity = TIM_IC_POLARITY_FALLING; + TIM_ICInitStructure.IcSelection = TIM_IC_SELECTION_INDIRECTTI; + TIM_ICInitStructure.IcPrescaler = TIM_IC_PSC_DIV1; + TIM_ICInitStructure.IcFilter = 0x0; + TIM_ICInit(TIM3, &TIM_ICInitStructure); + + /* TIM enable counter */ + TIM_Enable(TIM3, ENABLE); + + /* Enable the CC2 Interrupt Request */ + TIM_ConfigInt(TIM3, TIM_INT_CC1 | TIM_INT_CC2, ENABLE); + + while (1) + { + GenTwoRisingEdge(); + } +} + +// generation two rising edge +void GenTwoRisingEdge(void) +{ + if (gOnePulsEn) + { + gOnePulsEn = 0; + GPIO_SetBits(GPIOA, GPIO_PIN_6); + { + uint32_t i = 0; + while (i++ < 400) + ; + } + GPIO_ResetBits(GPIOA, GPIO_PIN_6); + { + uint32_t i = 0; + while (i++ < 500) + ; + } + + GPIO_SetBits(GPIOA, GPIO_PIN_6); + { + uint32_t i = 0; + while (i++ < 600) + ; + } + GPIO_ResetBits(GPIOA, GPIO_PIN_6); + { + uint32_t i = 0; + while (i++ < 700) + ; + } + } +} +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIOA and GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the GPIOA Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* TIM3 channel 2 pin (PB5) configuration */ + GPIO_InitStructure.Pin = GPIO_PIN_5; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + // PA6 + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + GPIO_ResetBits(GPIOA, GPIO_PIN_6); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the TIM3 global Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/src/n32wb03x_it.c new file mode 100644 index 0000000..10d90bd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/InputCapture_DualEdge/src/n32wb03x_it.c @@ -0,0 +1,189 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +__IO uint16_t IC3ReadValueL = 0, IC3ReadValueH = 0; +__IO uint16_t CaptureNumber = 0; +__IO uint32_t Capture = 0, CaptureH = 0, CaptureL = 0; +__IO uint32_t TIM3Freq = 0; +__IO uint32_t TIM3EnterIrqCnt = 0; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles TIM3 global interrupt request. + */ +void TIM3_IRQHandler(void) +{ + /* TIM3 CH2 Rising Edge */ + if (TIM_GetIntStatus(TIM3, TIM_INT_CC2) == SET) + { + TIM3EnterIrqCnt++; + /* Clear TIM3 Capture compare interrupt pending bit */ + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC2); + if (CaptureNumber == 0) + { + /* Get the Input Capture value */ + IC3ReadValueL = TIM_GetCap2(TIM3); + CaptureNumber = 1; + } + else if (CaptureNumber == 1) + { + /* Get the Input Capture value */ + IC3ReadValueL = TIM_GetCap2(TIM3); + + /* Capture computation */ + if (IC3ReadValueL > IC3ReadValueH) + { + CaptureL = (IC3ReadValueL - IC3ReadValueH); + } + else + { + CaptureL = ((0xFFFF - IC3ReadValueH) + IC3ReadValueL); + } + /* Period computation */ + Capture = CaptureH + CaptureL; + /* Frequency computation */ + TIM3Freq = (uint32_t)SystemCoreClock / Capture; + + } + } + else if (TIM_GetIntStatus(TIM3, TIM_INT_CC1) == SET) + { + TIM3EnterIrqCnt++; + /* Clear TIM3 Capture compare interrupt pending bit */ + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC1); + if (CaptureNumber == 0) + { + /* Get the Input Capture value */ + IC3ReadValueH = TIM_GetCap1(TIM3); + CaptureNumber = 1; + } + else if (CaptureNumber == 1) + { + /* Get the Input Capture value */ + IC3ReadValueH = TIM_GetCap1(TIM3); + + /* Capture computation */ + if (IC3ReadValueH > IC3ReadValueL) + { + CaptureH = (IC3ReadValueH - IC3ReadValueL); + } + else + { + CaptureH = ((0xFFFF - IC3ReadValueL) + IC3ReadValueH); + } + } + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/MDK-ARM/OCActive.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/MDK-ARM/OCActive.uvoptx new file mode 100644 index 0000000..a42bef8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/MDK-ARM/OCActive.uvoptx @@ -0,0 +1,416 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + UL2CM3 + -U -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/MDK-ARM/OCActive.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/MDK-ARM/OCActive.uvprojx new file mode 100644 index 0000000..f0cae40 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/MDK-ARM/OCActive.uvprojx @@ -0,0 +1,503 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + OCActive + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\OCActive.bin .\Objects\OCActive.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/readme.txt new file mode 100644 index 0000000..17b20db --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/readme.txt @@ -0,0 +1,23 @@ + +1. Function description + 1. After TIM3 CH1 CH2 CH3 CH4 reaches the CC value, it outputs ACTIVE level + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM3 CLK=64M + 2. Port configuration: + PB4 is selected as TIM3 CH1 output + PB5 is selected as TIM3 CH2 output + PB6 is selected as TIM3 CH3 output + PB7 is selected as TIM3 CH4 output + PB8 is selected as IO output + Instructions: + 1. Open the debug mode after compiling, and observe the waveforms of TIM3 CH1 CH2 CH3 CH4 with an oscilloscope or logic analyzer + 2. After the timer runs to CC1 CC2 CC3 CC4, the output of the corresponding channel becomes Active +4. Matters needing attention + None \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/src/main.c new file mode 100644 index 0000000..3d3faa5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/src/main.c @@ -0,0 +1,207 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_OCActive + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +uint16_t CCR1_Val = 1000; +uint16_t CCR2_Val = 500; +uint16_t CCR3_Val = 250; +uint16_t CCR4_Val = 125; +uint16_t PrescalerValue = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* --------------------------------------------------------------- + TIM3 Configuration: + TIM3CLK = SystemCoreClock / 2, + The objective is to get TIM3 counter clock at 1 MHz: + - Prescaler = (TIM3CLK / TIM3 counter clock) - 1 + And generate 4 signals with 4 different delays: + TIM3_CH1 delay = CCR1_Val/TIM3 counter clock = 1000 ms + TIM3_CH2 delay = CCR2_Val/TIM3 counter clock = 500 ms + TIM3_CH3 delay = CCR3_Val/TIM3 counter clock = 250 ms + TIM3_CH4 delay = CCR4_Val/TIM3 counter clock = 125 ms + + --------------------------------------------------------------- */ + /*Compute the prescaler value */ + PrescalerValue = 32 - 1; + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 65535; + TIM_TimeBaseStructure.Prescaler = PrescalerValue; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* Output Compare Active Mode configuration: Channel1 */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_ACTIVE; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR1_Val; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH; + TIM_InitOc1(TIM3, &TIM_OCInitStructure); + TIM_EnableOc1Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Active Mode configuration: Channel2 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR2_Val; + TIM_InitOc2(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc2Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Active Mode configuration: Channel3 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR3_Val; + TIM_InitOc3(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc3Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Active Mode configuration: Channel4 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR4_Val; + TIM_InitOc4(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc4Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + TIM_ConfigArPreload(TIM3, ENABLE); + + /* Set PB.08 pin */ + GPIO_ResetBits(GPIOB, GPIO_PIN_8); + GPIO_SetBits(GPIOB, GPIO_PIN_8); + + /* TIM3 enable counter */ + TIM_Enable(TIM3, ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* PCLK1 = HCLK/4 */ + RCC_ConfigPclk1(RCC_HCLK_DIV4); + + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the TIM3 and the GPIOE Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOB Configuration:TIM3 Channel1 Channel2 Channel3 Channel4 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + /* GPIOB Configuration: Pin8 an Output push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_8; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCActive/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/MDK-ARM/OCInactive.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/MDK-ARM/OCInactive.uvoptx new file mode 100644 index 0000000..42a1a2e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/MDK-ARM/OCInactive.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -U-O206 -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + -U -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/MDK-ARM/OCInactive.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/MDK-ARM/OCInactive.uvprojx new file mode 100644 index 0000000..1dd6d07 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/MDK-ARM/OCInactive.uvprojx @@ -0,0 +1,500 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + OCInactive + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\OCInactive.bin .\Objects\OCInactive.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/readme.txt new file mode 100644 index 0000000..8b4560e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/readme.txt @@ -0,0 +1,26 @@ + +Function Description + 1. After TIM3 CH1 CH2 CH3 CH4 reaches the CC value, pull down the IO level of PB4 PB5 PB6 PB7 correspondingly. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM3 CLK=64M + 2. Interruption: + TIM3 compare interrupt is turned on, subpriority 1 + 3. Port configuration: + PB4 is selected as IO output + PB5 is selected as IO output + PB6 is selected as IO output + PB7 is selected as IO output + 4. TIM: + TIM3 configures the comparison value of CH1, CH2, CH3, CH4, and turns on the comparison interrupt + Instructions: + 1. Open the debug mode after compiling, and observe the waveforms of PA6 PA7 PA8 PA9 with an oscilloscope or logic analyzer + 2. After the timer runs to CC1 CC2 CC3 CC4, pull down the IO level of PA6 PA7 PA8 PA9 correspondingly +4. Matters needing attention + By default, the PB6 and PB7 jumper caps of the development board are connected to the virtual serial port of NSLINK. If PB6 and PB7 are not used as serial ports in the project, and are used for other purposes, the serial port jumper caps must be unplugged. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/src/main.c new file mode 100644 index 0000000..a7df2f5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/src/main.c @@ -0,0 +1,224 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_OCInactive + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +uint16_t CCR1_Val = 1000; +uint16_t CCR2_Val = 500; +uint16_t CCR3_Val = 250; +uint16_t CCR4_Val = 125; +uint16_t PrescalerValue = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC Configuration */ + NVIC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* --------------------------------------------------------------- + TIM3 Configuration: + TIM3CLK = SystemCoreClock / 2, + The objective is to get TIM3 counter clock at 1 MHz: + - Prescaler = (TIM3CLK / TIM3 counter clock) - 1 + And generate 4 signals with 4 different delays: + TIM3_CH1 delay = CCR1_Val/TIM3 counter clock = 1000 ms + TIM3_CH2 delay = CCR2_Val/TIM3 counter clock = 500 ms + TIM3_CH3 delay = CCR3_Val/TIM3 counter clock = 250 ms + TIM3_CH4 delay = CCR4_Val/TIM3 counter clock = 125 ms + + --------------------------------------------------------------- */ + /* Compute the prescaler value */ + PrescalerValue = 32 - 1; + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 65535; + TIM_TimeBaseStructure.Prescaler = PrescalerValue; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* Output Compare Active Mode configuration: Channel1 */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_INACTIVE; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR1_Val; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH; + TIM_InitOc1(TIM3, &TIM_OCInitStructure); + TIM_EnableOc1Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Active Mode configuration: Channel2 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR2_Val; + TIM_InitOc2(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc2Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Active Mode configuration: Channel3 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR3_Val; + TIM_InitOc3(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc3Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Active Mode configuration: Channel4 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR4_Val; + TIM_InitOc4(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc4Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + TIM_ConfigArPreload(TIM3, ENABLE); + + /* TIM IT enable */ + TIM_ConfigInt(TIM3, TIM_INT_CC1 | TIM_INT_CC2 | TIM_INT_CC3 | TIM_INT_CC4, ENABLE); + + /* Reset PB4, PB5, PB6 and PB7 pins */ + GPIO_ResetBits(GPIOB, GPIO_PIN_4 | GPIO_PIN_5 |GPIO_PIN_6 | GPIO_PIN_7); + /* Set PB4, PB5, PB6 and PB7 pins */ + GPIO_SetBits(GPIOB, GPIO_PIN_4 | GPIO_PIN_5 |GPIO_PIN_6 | GPIO_PIN_7); + /* TIM3 enable counter */ + TIM_Enable(TIM3, ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* PCLK1 = HCLK/4 */ + RCC_ConfigPclk1(RCC_HCLK_DIV4); + + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); +} + +/** + * @brief Configure the GPIOB Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* GPIOB Configuration: Pin4, 5, 6 and 7 as output push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_4 | GPIO_PIN_5 |GPIO_PIN_6 | GPIO_PIN_7; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the TIM3 Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + + NVIC_Init(&NVIC_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/src/n32wb03x_it.c new file mode 100644 index 0000000..249a71a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCInactive/src/n32wb03x_it.c @@ -0,0 +1,154 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles TIM3 global interrupt request. + */ +void TIM3_IRQHandler(void) +{ + if (TIM_GetIntStatus(TIM3, TIM_INT_CC1) != RESET) + { + /* Clear TIM3 Capture Compare1 interrupt pending bit*/ + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC1); + + /* PB4 turnoff after 1000 ms */ + GPIO_ResetBits(GPIOB, GPIO_PIN_4); + } + else if (TIM_GetIntStatus(TIM3, TIM_INT_CC2) != RESET) + { + /* Clear TIM3 Capture Compare2 interrupt pending bit*/ + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC2); + + /* PB5 turnoff after 500 ms */ + GPIO_ResetBits(GPIOB, GPIO_PIN_5); + } + else if (TIM_GetIntStatus(TIM3, TIM_INT_CC3) != RESET) + { + /* Clear TIM3 Capture Compare3 interrupt pending bit*/ + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC3); + + /* PB6 turnoff after 250 ms */ + GPIO_ResetBits(GPIOB, GPIO_PIN_6); + } + else + { + /* Clear TIM3 Capture Compare4 interrupt pending bit*/ + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC4); + + /* PB7 turnoff after 125 ms */ + GPIO_ResetBits(GPIOB, GPIO_PIN_7); + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/MDK-ARM/OCToggle.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/MDK-ARM/OCToggle.uvoptx new file mode 100644 index 0000000..7bdd535 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/MDK-ARM/OCToggle.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/MDK-ARM/OCToggle.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/MDK-ARM/OCToggle.uvprojx new file mode 100644 index 0000000..371d40d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/MDK-ARM/OCToggle.uvprojx @@ -0,0 +1,500 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + OCToggle + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\OCToggle.bin .\Objects\OCToggle.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/readme.txt new file mode 100644 index 0000000..66085b3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/readme.txt @@ -0,0 +1,26 @@ + +1. Function description + 1. After TIM3 CH1 CH2 CH3 CH4 reaches the CC value, the output is flipped, and the comparison value is accumulated + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM3 CLK=64M + 2. Interrupt: + TIM3 compare interrupt on, priority 0 + 3. Port configuration: + PB4 is selected as the CH1 output of TIM3 + PB5 is selected as the CH2 output of TIM3 + PB6 is selected as the CH3 output of TIM3 + PB7 is selected as the CH4 output of TIM3 + 4. TIM: + TIM3 configures the comparison value output of CH1 CH2 CH3 CH4 to flip, and open the comparison interrupt + Instructions: + 1. Open the debug mode after compiling, and observe the waveforms of CH1 CH2 CH3 CH4 of TIM3 with an oscilloscope or logic analyzer + 2. Whenever the comparison value is reached, the output is flipped, and the same comparison value is increased again, and the waveform duty cycle is 50% +4. Matters needing attention + By default, the PB6 and PB7 jumper caps of the development board are connected to the virtual serial port of NSLINK. If PB6 and PB7 are not used as serial ports in the project, and are used for other purposes, the serial port jumper caps must be unplugged. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/src/main.c new file mode 100644 index 0000000..544cf19 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/src/main.c @@ -0,0 +1,228 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_OCToggle + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +__IO uint16_t CCR1_Val = 32768; +__IO uint16_t CCR2_Val = 16384; +__IO uint16_t CCR3_Val = 8192; +__IO uint16_t CCR4_Val = 4096; +uint16_t PrescalerValue = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC Configuration */ + NVIC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* --------------------------------------------------------------------------- + TIM3 Configuration: Output Compare Toggle Mode: + TIM3CLK = pclk1 * 2, + The objective is to get TIM3 counter clock at 16 MHz: + - Prescaler = (TIM3CLK / TIM3 counter clock) - 1 + CC1 update rate = TIM3 counter clock / CCR1_Val = 488.28 Hz + CC2 update rate = TIM3 counter clock / CCR2_Val = 976.56 Hz + CC3 update rate = TIM3 counter clock / CCR3_Val = 1953.125 Hz + CC4 update rate = TIM3 counter clock / CCR4_Val = 3906.26 Hz + ----------------------------------------------------------------------------*/ + /* Compute the prescaler value */ + PrescalerValue = 2 - 1; //32M(pclk1*2) / 2 = 16M + + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 65535; + TIM_TimeBaseStructure.Prescaler = PrescalerValue; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* Output Compare Toggle Mode configuration: Channel1 */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_TOGGLE; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR1_Val; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_LOW; + TIM_InitOc1(TIM3, &TIM_OCInitStructure); + TIM_EnableOc1Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Toggle Mode configuration: Channel2 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR2_Val; + TIM_InitOc2(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc2Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Toggle Mode configuration: Channel3 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR3_Val; + TIM_InitOc3(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc3Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Toggle Mode configuration: Channel4 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR4_Val; + TIM_InitOc4(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc4Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* TIM enable counter */ + TIM_Enable(TIM3, ENABLE); + + /* TIM IT enable */ + TIM_ConfigInt(TIM3, TIM_INT_CC1 | TIM_INT_CC2 | TIM_INT_CC3 | TIM_INT_CC4, ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* PCLK1 = HCLK/4 */ + RCC_ConfigPclk1(RCC_HCLK_DIV4); + + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIOA clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the TIM3 Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOB Configuration:TIM3 Channel1, 2, 3 and 4 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_4; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = GPIO_PIN_5; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = GPIO_PIN_7; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the TIM3 global Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/src/n32wb03x_it.c new file mode 100644 index 0000000..4485c09 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OCToggle/src/n32wb03x_it.c @@ -0,0 +1,159 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +uint16_t capture = 0; +extern __IO uint16_t CCR1_Val; +extern __IO uint16_t CCR2_Val; +extern __IO uint16_t CCR3_Val; +extern __IO uint16_t CCR4_Val; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles TIM3 global interrupt request. + */ +void TIM3_IRQHandler(void) +{ + /* TIM3_CH1 toggling with frequency = 488.28 Hz */ + if (TIM_GetIntStatus(TIM3, TIM_INT_CC1) != RESET) + { + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC1); + capture = TIM_GetCap1(TIM3); + TIM_SetCmp1(TIM3, capture + CCR1_Val); + } + + /* TIM3_CH2 toggling with frequency = 976.56 Hz */ + if (TIM_GetIntStatus(TIM3, TIM_INT_CC2) != RESET) + { + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC2); + capture = TIM_GetCap2(TIM3); + TIM_SetCmp2(TIM3, capture + CCR2_Val); + } + + /* TIM3_CH3 toggling with frequency = 1953.125 Hz */ + if (TIM_GetIntStatus(TIM3, TIM_INT_CC3) != RESET) + { + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC3); + capture = TIM_GetCap3(TIM3); + TIM_SetCmp3(TIM3, capture + CCR3_Val); + } + + /* TIM3_CH4 toggling with frequency = 3906.26 Hz */ + if (TIM_GetIntStatus(TIM3, TIM_INT_CC4) != RESET) + { + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC4); + capture = TIM_GetCap4(TIM3); + TIM_SetCmp4(TIM3, capture + CCR4_Val); + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/MDK-ARM/OnePulse.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/MDK-ARM/OnePulse.uvoptx new file mode 100644 index 0000000..7bdd535 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/MDK-ARM/OnePulse.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/MDK-ARM/OnePulse.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/MDK-ARM/OnePulse.uvprojx new file mode 100644 index 0000000..4b6ce6a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/MDK-ARM/OnePulse.uvprojx @@ -0,0 +1,500 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + OnePulse + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\OnePulse.bin .\Objects\OnePulse.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/readme.txt new file mode 100644 index 0000000..9efe42a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/readme.txt @@ -0,0 +1,25 @@ + +1. Function description + 1. The rising edge of TIM3 CH2 triggers CH1 to output a single pulse + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM3 CLK=64M + 2. Port configuration: + PB6 is selected as the CH3 output of TIM3 + PB5 is selected as the CH2 input of TIM3 + PA6 is selected as IO output + 3. TIM: + TIM3 configures CH2 rising edge to trigger CH3 to output a single pulse + Instructions: + 1. Open the debug mode after compiling, connect PA6 to PB5, and observe the waveform of CH3 of TIM3 with an oscilloscope or logic analyzer + 2. Add the variable gSendTrigEn to the watch window, the default gSendTrigEn=0, every time you manually modify gSendTrigEn=1, you will see a single pulse output on the TIM3 CH3 port + +4. Matters needing attention + By default, the PB6 and PB7 jumper caps of the development board are connected to the virtual serial port of NSLINK. If PB6 and PB7 are not used as serial ports in the project, and are used for other purposes, the serial port jumper caps must be unplugged. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/src/main.c new file mode 100644 index 0000000..9bf4f42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/src/main.c @@ -0,0 +1,207 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_OnePulse + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +TIM_ICInitType TIM_ICInitStructure; +OCInitType TIM_OCInitStructure; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void SendOneTrig(void); +uint16_t gSendTrigEn = 1; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* TIM3 configuration: One Pulse mode */ + + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 65535; + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* TIM3 PWM2 Mode configuration: Channel1 */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM2; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = 16383; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH; + TIM_InitOc3(TIM3, &TIM_OCInitStructure); + + /* TIM3 configuration in Input Capture Mode */ + + TIM_InitIcStruct(&TIM_ICInitStructure); + TIM_ICInitStructure.Channel = TIM_CH_2; + TIM_ICInitStructure.IcPolarity = TIM_IC_POLARITY_RISING; + TIM_ICInitStructure.IcSelection = TIM_IC_SELECTION_DIRECTTI; + TIM_ICInitStructure.IcPrescaler = TIM_IC_PSC_DIV1; + TIM_ICInitStructure.IcFilter = 0; + TIM_ICInit(TIM3, &TIM_ICInitStructure); + + /* One Pulse Mode selection */ + TIM_SelectOnePulseMode(TIM3, TIM_OPMODE_SINGLE); + + /* Input Trigger selection */ + TIM_SelectInputTrig(TIM3, TIM_TRIG_SEL_TI2FP2); + + /* Slave Mode selection: Trigger Mode */ + TIM_SelectSlaveMode(TIM3, TIM_SLAVE_MODE_TRIG); + + while (1) + { + SendOneTrig(); + } +} + +/** + * @brief Send one trig byself. + */ +void SendOneTrig(void) +{ + if (gSendTrigEn) + { + gSendTrigEn = 0; + GPIO_SetBits(GPIOA, GPIO_PIN_6); + { + uint32_t i; + while (i++ < 10) + ; + } + GPIO_ResetBits(GPIOA, GPIO_PIN_6); + } +} +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + RCC_ConfigPclk1(RCC_HCLK_DIV4); + + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the GPIOA Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* TIM3_CH3 pin (PB.06) configuration as Alternate Function Push Pull Mode*/ + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + /* TIM3_CH2 pin (PB.05) configuration as Alternate Function Push Pull Mode*/ + GPIO_InitStructure.Pin = GPIO_PIN_5; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + /* pin (PA.06) configuration as Output Push Pull Mode */ + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/OnePulse/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/MDK-ARM/PWM_Input.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/MDK-ARM/PWM_Input.uvoptx new file mode 100644 index 0000000..58dda89 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/MDK-ARM/PWM_Input.uvoptx @@ -0,0 +1,407 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 14 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 16 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/MDK-ARM/PWM_Input.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/MDK-ARM/PWM_Input.uvprojx new file mode 100644 index 0000000..5aa3cc3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/MDK-ARM/PWM_Input.uvprojx @@ -0,0 +1,495 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + PWM_Input + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\PWM_Input.bin .\Objects\PWM_Input.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/readme.txt new file mode 100644 index 0000000..3fcfb9e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + 1. TIM3 CH2 capture pin calculates the duty cycle and frequency through the falling edge of CH1 and the rising edge of CH2 + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM1 CLK=64M, TIM3 CLK=64M + 2. Interrupt: + TIM3 CC2 compare interrupt is turned on, priority level 1 + 3. Port configuration: + PB5 is selected as the CH2 input of TIM3 + PA6 is selected as IO output + 4. TIM: + TIM3 CH1 captures the falling edge of CH2 signals.TIM3 CH2 captures the rising edge of CH2. + Instructions: + 1. Open the debug mode after compiling, connect PA3 and PA7, and add the variables TIM3Freq and gOnePulsEn to the watch window + 2. The default gOnePulsEn=0, manually give gOnePulsEn=1 each time, then you can see that the values of the duty cycle and frequency captured are stored in the DutyCycle and Frequency variables. +4. Matters needing attention + None \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/src/main.c new file mode 100644 index 0000000..4ed8972 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/src/main.c @@ -0,0 +1,216 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup TIM_PWM_Input + * @{ + */ +uint16_t gOnePulsEn = 1; +TIM_ICInitType TIM_ICInitStructure; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +void GenTwoRisingEdge(void); +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC configuration */ + NVIC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* TIM3 configuration: PWM Input mode ------------------------ + The external signal is connected to TIM3 CH2 pin (PB.05), + The Rising edge is used as active edge, + The TIM3 CCDAT2 is used to compute the frequency value + The TIM3 CCDAT1 is used to compute the duty cycle value + ------------------------------------------------------------ */ + + TIM_ICInitStructure.Channel = TIM_CH_2; + TIM_ICInitStructure.IcPolarity = TIM_IC_POLARITY_RISING; + TIM_ICInitStructure.IcSelection = TIM_IC_SELECTION_DIRECTTI; + TIM_ICInitStructure.IcPrescaler = TIM_IC_PSC_DIV1; + TIM_ICInitStructure.IcFilter = 0x0; + TIM_ConfigPwmIc(TIM3, &TIM_ICInitStructure); + + /* Select the TIM3 Input Trigger: TI2FP2 */ + TIM_SelectInputTrig(TIM3, TIM_TRIG_SEL_TI2FP2); + + /* Select the slave Mode: Reset Mode */ + TIM_SelectSlaveMode(TIM3, TIM_SLAVE_MODE_RESET); + + /* Enable the Master/Slave Mode */ + TIM_SelectMasterSlaveMode(TIM3, TIM_MASTER_SLAVE_MODE_ENABLE); + + /* TIM enable counter */ + TIM_Enable(TIM3, ENABLE); + + /* Enable the CC2 Interrupt Request */ + TIM_ConfigInt(TIM3, TIM_INT_CC2, ENABLE); + + while (1) + { + GenTwoRisingEdge(); + }; +} + +// generation two rising edge +void GenTwoRisingEdge(void) +{ + if (gOnePulsEn) + { + gOnePulsEn = 0; + GPIO_SetBits(GPIOA, GPIO_PIN_6); + GPIO_ResetBits(GPIOA, GPIO_PIN_6); + { + uint32_t i = 0; + while (i++ < 500) + ; + } + + GPIO_SetBits(GPIOA, GPIO_PIN_6); + GPIO_ResetBits(GPIOA, GPIO_PIN_6); + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + RCC_ConfigPclk1(RCC_HCLK_DIV4); + + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIOA GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the GPIO Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* TIM3 channel 2 pin (PB.05) configuration */ + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIO_PIN_5; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + // PA6 + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the TIM3 global Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/src/n32wb03x_it.c new file mode 100644 index 0000000..6c52a06 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Input/src/n32wb03x_it.c @@ -0,0 +1,145 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +__IO uint16_t IC2Value = 0; +__IO uint16_t DutyCycle = 0; +__IO uint32_t Frequency = 0; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles TIM3 global interrupt request. + */ +void TIM3_IRQHandler(void) +{ + /* Clear TIM3 Capture compare interrupt pending bit */ + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC2); + + /* Get the Input Capture value */ + IC2Value = TIM_GetCap2(TIM3); + + if (IC2Value != 0) + { + /* Duty cycle computation */ + DutyCycle = (TIM_GetCap1(TIM3) * 100) / IC2Value; + + /* Frequency computation */ + Frequency = SystemCoreClock / 2 / IC2Value; + } + else + { + DutyCycle = 0; + Frequency = 0; + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/MDK-ARM/PWM_Output.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/MDK-ARM/PWM_Output.uvoptx new file mode 100644 index 0000000..7bdd535 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/MDK-ARM/PWM_Output.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/MDK-ARM/PWM_Output.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/MDK-ARM/PWM_Output.uvprojx new file mode 100644 index 0000000..3a8e163 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/MDK-ARM/PWM_Output.uvprojx @@ -0,0 +1,550 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + PWM_Output + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\PWM_Output.bin .\Objects\PWM_Output.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/readme.txt new file mode 100644 index 0000000..b6972c1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + 1. TIM3 CH1 CH2 CH3 CH4 outputs PWM with the same frequency and different duty cycles + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM3 CLK=64M + 2. Port configuration: + PB4 is selected as the CH1 output of TIM3 + PB5 is selected as the CH2 output of TIM3 + PB6 is selected as the CH3 output of TIM3 + PB7 is selected as the CH4 output of TIM3 + 3. TIM: + TIM3 CH1 CH2 CH3 CH4 has the same period, and the duty cycle is not equal + Instructions: + 1. After compiling, turn on the debug mode, use an oscilloscope or logic analyzer to observe the waveforms of TIM3 CH1, CH2, CH3, CH4 + 2. After the program runs, 4 PWM signals with equal period and different duty cycle are generated +4. Matters needing attention + None \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/src/main.c new file mode 100644 index 0000000..321e985 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/src/main.c @@ -0,0 +1,204 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + + +#define USE_HSI_64M +/** @addtogroup TIM_PWM_Output + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +uint16_t CCR1_Val = 300; +uint16_t CCR2_Val = 200; +uint16_t CCR3_Val = 100; +uint16_t CCR4_Val = 50; + +uint16_t PrescalerValue = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); + + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* ----------------------------------------------------------------------- + TIM3 Configuration: generate 4 PWM signals with 4 different duty cycles: + The TIM3CLK frequency is set to SystemCoreClock (Hz), to get TIM3 counter + clock at 16 MHz the Prescaler is computed as following: + - Prescaler = (TIM3CLK / TIM3 counter clock) - 1 + SystemCoreClock is set to 32 MHz for N32WB03X device + + The TIM3 is running at 40 KHz: TIM3 Frequency = TIM3 counter clock/(AR + 1) + = 16 MHz / 400 = 40 KHz + TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR)* 100 = 75% + TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR)* 100 = 50% + TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR)* 100 = 25% + TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR)* 100 = 12.5% + ----------------------------------------------------------------------- */ + /* Compute the prescaler value */ + PrescalerValue = (uint16_t)(SystemCoreClock / 16000000) - 1; + /* Time base configuration */ + TIM_TimeBaseStructure.Period = (400-1); + TIM_TimeBaseStructure.Prescaler = PrescalerValue; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* PWM1 Mode configuration: Channel1 */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM1; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR1_Val; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH; + TIM_InitOc1(TIM3, &TIM_OCInitStructure); + TIM_EnableOc1Preload(TIM3, TIM_OC_PRE_LOAD_ENABLE); + + /* PWM1 Mode configuration: Channel2 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR2_Val; + TIM_InitOc2(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc2Preload(TIM3, TIM_OC_PRE_LOAD_ENABLE); + + /* PWM1 Mode configuration: Channel3 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR3_Val; + TIM_InitOc3(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc3Preload(TIM3, TIM_OC_PRE_LOAD_ENABLE); + + /* PWM1 Mode configuration: Channel4 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR4_Val; + TIM_InitOc4(TIM3, &TIM_OCInitStructure); + TIM_ConfigOc4Preload(TIM3, TIM_OC_PRE_LOAD_ENABLE); + + TIM_ConfigArPreload(TIM3, ENABLE); + + /* TIM3 enable counter */ + TIM_Enable(TIM3, ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIOB clock enable */ + RCC_EnableAPB2PeriphClk( RCC_APB2_PERIPH_GPIOB| RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the TIM3 Ouput Channels. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* GPIOB Configuration:TIM3 Channel 1,2,3 and 4 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/PWM_Output/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/MDK-ARM/Parallel_Synchro.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/MDK-ARM/Parallel_Synchro.uvoptx new file mode 100644 index 0000000..7bdd535 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/MDK-ARM/Parallel_Synchro.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/MDK-ARM/Parallel_Synchro.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/MDK-ARM/Parallel_Synchro.uvprojx new file mode 100644 index 0000000..a8b521d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/MDK-ARM/Parallel_Synchro.uvprojx @@ -0,0 +1,500 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Parallel_Synchro + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Parallel_Synchro.bin .\Objects\Parallel_Synchro.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/readme.txt new file mode 100644 index 0000000..b36e77d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/readme.txt @@ -0,0 +1,23 @@ + +1. Function description + 1. TIM1 cycle gated TIM3 + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM1 CLK=64M, TIM3 CLK=64M + 2. Port configuration: + PB8 is selected as CH1 output of TIM1 + PB7 is selected as CH1 output of TIM3 + 3. TIM: + TIM1 cycle triggers CH1 of gated TIM3, i.e. TIM3 is 10 times cycle in TIM1 +Usage method: + 1. Open debugging mode after compilation and observe TIM1 CH1, TIM3 CH1 waveforms with oscilloscope or logic analyzer + 2. The cycle of TIM3 is 10 times that of TIM1 + +4. Matters needing attention + By default, the PB6 and PB7 jumper caps of the development board are connected to the virtual serial port of NSLINK. If PB6 and PB7 are not used as serial ports in the project, and are used for other purposes, the serial port jumper caps must be unplugged. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/src/main.c new file mode 100644 index 0000000..bf69bab --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/src/main.c @@ -0,0 +1,187 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_Parallel_Synchro + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; + +void RCC_Configuration(void); +void GPIO_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* Timers synchronisation in parallel mode */ + + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 25500; + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure); + + TIM_TimeBaseStructure.Period = (10-1); + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* Master Configuration in PWM1 Mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM1; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = 6400; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH; + TIM_InitOc1(TIM1, &TIM_OCInitStructure); + + /* Select the Master Slave Mode */ + TIM_SelectMasterSlaveMode(TIM1, TIM_MASTER_SLAVE_MODE_ENABLE); + + /* Master Mode selection */ + TIM_SelectOutputTrig(TIM1, TIM_TRGO_SRC_UPDATE); + + /* Slaves Configuration: PWM1 Mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM1; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = 4; + TIM_InitOc4(TIM3, &TIM_OCInitStructure); + + /* Slave Mode selection: TIM3 */ + TIM_SelectSlaveMode(TIM3, TIM_SLAVE_MODE_GATED); + TIM_SelectInputTrig(TIM3, TIM_TRIG_SEL_IN_TR0); + + /* TIM enable counter */ + TIM_Enable(TIM3, ENABLE); + TIM_Enable(TIM1, ENABLE); + TIM_EnableCtrlPwmOutputs(TIM1,ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + RCC_ConfigPclk1(RCC_HCLK_DIV4); + RCC_ConfigPclk2(RCC_HCLK_DIV4); + + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* TIM1 GPIOB and AFIO clocks enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1 | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); +} + +/** + * @brief Configure the GPIO Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOB Configuration: PB7(TIM3 CH4) as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_7; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + + /* GPIOB Configuration: PB8(TIM1 CH1) as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_8; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/Parallel_Synchro/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/MDK-ARM/TIM1_Synchro.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/MDK-ARM/TIM1_Synchro.uvoptx new file mode 100644 index 0000000..a42bef8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/MDK-ARM/TIM1_Synchro.uvoptx @@ -0,0 +1,416 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + UL2CM3 + -U -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/MDK-ARM/TIM1_Synchro.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/MDK-ARM/TIM1_Synchro.uvprojx new file mode 100644 index 0000000..9dcee05 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/MDK-ARM/TIM1_Synchro.uvprojx @@ -0,0 +1,503 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + TIM_Synchro + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\TIM_Synchro.bin .\Objects\TIM_Synchro.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/readme.txt new file mode 100644 index 0000000..f2e7329 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/readme.txt @@ -0,0 +1,23 @@ + +1. Function description + 1. TIM3 counts under TIM1 cycle + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM1 CLK=64M,TIM3 CLK=64M + 2. Port configuration: + PB7 is selected as the CH1 output of TIM3 + PB8 is selected as the CH1 output of TIM1 + 3. TIM: + TIM1 CH1 periodically triggers the gate control of TIM3 + Instructions: + 1. Open the debug mode after compiling, and observe the waveforms of TIM1 CH1, TIM3 CH1,with an oscilloscope or logic analyzer + 2. After the program runs, The period of TIM3 is 8 times that of TIM1 + +4. Matters needing attention + By default, the PB6 and PB7 jumper caps of the development board are connected to the virtual serial port of NSLINK. If PB6 and PB7 are not used as serial ports in the project, and are used for other purposes, the serial port jumper caps must be unplugged. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/src/main.c new file mode 100644 index 0000000..077ba45 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/src/main.c @@ -0,0 +1,229 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_TIM1_Synchro + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +TIM_BDTRInitType TIM_BDTRInitStructure; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +RCC_ClocksType rcc_clocks; +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* TIM1 and TIM3 synchronisation in parallel mode ----------- + 1/TIM1 is configured as Master Timer: + - PWM Mode is used + - The TIM1 Update event is used as Trigger Output + + 2/TIM3 is slave for TIM1, + - PWM Mode is used + - The ITR0(TIM1) is used as input trigger for slave + - Gated mode is used, so starts and stops of slave counters + are controlled by the Master trigger output signal(update event). + + --------------------------------------------------------------------------- */ + + /* TIM3 Peripheral Configuration ----------------------------------------*/ + /* TIM3 Slave Configuration: PWM1 Mode */ + TIM_TimeBaseStructure.Period = 3; + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM1; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = 1; + TIM_InitOc4(TIM3, &TIM_OCInitStructure); + + /* Slave Mode selection: TIM3 */ + TIM_SelectSlaveMode(TIM3, TIM_SLAVE_MODE_GATED); + TIM_SelectInputTrig(TIM3, TIM_TRIG_SEL_IN_TR0); + + /* TIM1 Peripheral Configuration ----------------------------------------*/ + /* Time Base configuration */ + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_TimeBaseStructure.Period = 1000; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.RepetCnt = 1; + TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure); + + /* Channel 1 Configuration in PWM mode */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_PWM2; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.OutputNState = TIM_OUTPUT_NSTATE_ENABLE; + TIM_OCInitStructure.Pulse = 500; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_LOW; + TIM_OCInitStructure.OcNPolarity = TIM_OCN_POLARITY_LOW; + TIM_OCInitStructure.OcIdleState = TIM_OC_IDLE_STATE_SET; + TIM_OCInitStructure.OcNIdleState = TIM_OC_IDLE_STATE_RESET; + TIM_InitOc1(TIM1, &TIM_OCInitStructure); + + /* Automatic Output enable, Break, dead time and lock configuration*/ + TIM_BDTRInitStructure.OssrState = TIM_OSSR_STATE_ENABLE; + TIM_BDTRInitStructure.OssiState = TIM_OSSI_STATE_ENABLE; + TIM_BDTRInitStructure.LockLevel = TIM_LOCK_LEVEL_1; + TIM_BDTRInitStructure.DeadTime = 100; + TIM_BDTRInitStructure.Break = TIM_BREAK_IN_DISABLE; + TIM_BDTRInitStructure.BreakPolarity = TIM_BREAK_POLARITY_HIGH; + TIM_BDTRInitStructure.AutomaticOutput = TIM_AUTO_OUTPUT_DISABLE; + TIM_ConfigBkdt(TIM1, &TIM_BDTRInitStructure); + + /* Master Mode selection */ + TIM_SelectOutputTrig(TIM1, TIM_TRGO_SRC_UPDATE); + + /* Select the Master Slave Mode */ + TIM_SelectMasterSlaveMode(TIM1, TIM_MASTER_SLAVE_MODE_ENABLE); + + /* TIM1 counter enable */ + TIM_Enable(TIM1, ENABLE); + + /* TIM enable counter */ + TIM_Enable(TIM3, ENABLE); + + /* Main Output Enable */ + TIM_EnableCtrlPwmOutputs(TIM1, ENABLE); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* PCLK1 = HCLK/4 */ + RCC_ConfigPclk1(RCC_HCLK_DIV4); + + /* PCLK2 = HCLK/4 */ + RCC_ConfigPclk2(RCC_HCLK_DIV4); + + /* TIM1, GPIOA and GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1 | RCC_APB2_PERIPH_GPIOA + | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE); + + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + +} + +/** + * @brief Configures TIM1, TIM3 Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOB Configuration: TIM1 Channel1 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_8; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_TIM1; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + /* GPIOB Configuration: TIM3 Channel1 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_7; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM3; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/src/n32wb03x_it.c new file mode 100644 index 0000000..f55dd42 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TIM1_Synchro/src/n32wb03x_it.c @@ -0,0 +1,122 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/MDK-ARM/TimeBase.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/MDK-ARM/TimeBase.uvoptx new file mode 100644 index 0000000..7bdd535 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/MDK-ARM/TimeBase.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/MDK-ARM/TimeBase.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/MDK-ARM/TimeBase.uvprojx new file mode 100644 index 0000000..71bfe23 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/MDK-ARM/TimeBase.uvprojx @@ -0,0 +1,500 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + TimeBase + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\TimeBase.bin .\Objects\TimeBase.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/readme.txt new file mode 100644 index 0000000..f015dc9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/readme.txt @@ -0,0 +1,26 @@ + +1. Function description + 1. TIM3 uses the CH1 CH2 CH3 CH4 CC value to generate a timing interrupt and flip the IO level + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM1 CLK=64M,TIM3 CLK=64M + 2. Interruption: + TIM3 compare interrupt is turned on, priority level 1 + 3. Port configuration: + PB6 is selected as IO output + PB7 is selected as IO output + PB11 is selected as IO output + PB12 is selected as IO output + 4. TIM: + TIM3 output freeze mode, CH1 CH2 CH3 CH4 compare value interrupt + Instructions: + 1. Open the debug mode after compiling, and observe the waveform of PB6,PB7,PB11,PB12 with an oscilloscope or logic analyzer + 2. After the program runs, after the corresponding channel reaches the comparison value, the comparison value accumulates and flips the corresponding IO port level +Matters needing attention + By default, the PB6 and PB7 jumper caps of the development board are connected to the virtual serial port of NSLINK. If PB6 and PB7 are not used as serial ports in the project, and are used for other purposes, the serial port jumper caps must be unplugged. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/src/main.c new file mode 100644 index 0000000..3c4e47f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/src/main.c @@ -0,0 +1,223 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_TimeBase + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +__IO uint16_t CCR1_Val = 45000; +__IO uint16_t CCR2_Val = 30000; +__IO uint16_t CCR3_Val = 15000; +__IO uint16_t CCR4_Val = 6000; +uint16_t PrescalerValue = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + RCC_ClocksType RCC_Clocks; + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC Configuration */ + NVIC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* Compute the prescaler value */ + RCC_GetClocksFreqValue(&RCC_Clocks); + if(RCC_Clocks.Pclk1Freq != RCC_Clocks.HclkFreq) + { + PrescalerValue = (uint16_t)(RCC_Clocks.Pclk1Freq*2 / 4000000) - 1; + } + else + { + PrescalerValue = (uint16_t)(SystemCoreClock / 4000000) - 1; + } + + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 65535; + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* Prescaler configuration */ + TIM_ConfigPrescaler(TIM3, PrescalerValue, TIM_PSC_RELOAD_MODE_IMMEDIATE); + + /* Output Compare Timing Mode configuration: Channel1 */ + TIM_OCInitStructure.OcMode = TIM_OCMODE_TIMING; + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR1_Val; + TIM_OCInitStructure.OcPolarity = TIM_OC_POLARITY_HIGH; + TIM_InitOc1(TIM3, &TIM_OCInitStructure); + + TIM_EnableOc1Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Timing Mode configuration: Channel2 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR2_Val; + TIM_InitOc2(TIM3, &TIM_OCInitStructure); + + TIM_ConfigOc2Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Timing Mode configuration: Channel3 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR3_Val; + TIM_InitOc3(TIM3, &TIM_OCInitStructure); + + TIM_ConfigOc3Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* Output Compare Timing Mode configuration: Channel4 */ + TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE; + TIM_OCInitStructure.Pulse = CCR4_Val; + TIM_InitOc4(TIM3, &TIM_OCInitStructure); + + TIM_ConfigOc4Preload(TIM3, TIM_OC_PRE_LOAD_DISABLE); + + /* TIM IT enable */ + TIM_ConfigInt(TIM3, TIM_INT_CC1 | TIM_INT_CC2 | TIM_INT_CC3 | TIM_INT_CC4, ENABLE); + + /* TIM3 enable counter */ + TIM_Enable(TIM3, ENABLE); + + while (1) + ; +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* PCLK1 = HCLK/4 */ + RCC_ConfigPclk1(RCC_HCLK_DIV4); + + /* TIM clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIO clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO , ENABLE); +} + +/** + * @brief Configure the GPIO Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + + /* GPIOB Configuration:Pin6, 7, 11 and 12 as Output Push Pull Mode*/ + GPIO_InitStructure.Pin = GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_11 | GPIO_PIN_12; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the TIM global Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/src/n32wb03x_it.c new file mode 100644 index 0000000..2741c48 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBase/src/n32wb03x_it.c @@ -0,0 +1,164 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +uint16_t capture = 0; +extern __IO uint16_t CCR1_Val; +extern __IO uint16_t CCR2_Val; +extern __IO uint16_t CCR3_Val; +extern __IO uint16_t CCR4_Val; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles TIM3 global interrupt request. + */ +void TIM3_IRQHandler(void) +{ + if (TIM_GetIntStatus(TIM3, TIM_INT_CC1) != RESET) + { + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC1); + + /* Pin PB.06 toggling with frequency = 88.88 Hz */ + GPIO_WriteBit(GPIOB, GPIO_PIN_6, (Bit_OperateType)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_PIN_6))); + capture = TIM_GetCap1(TIM3); + TIM_SetCmp1(TIM3, capture + CCR1_Val); + } + else if (TIM_GetIntStatus(TIM3, TIM_INT_CC2) != RESET) + { + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC2); + + /* Pin PB.07 toggling with frequency = 133.33 Hz */ + GPIO_WriteBit(GPIOB, GPIO_PIN_7, (Bit_OperateType)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_PIN_7))); + capture = TIM_GetCap2(TIM3); + TIM_SetCmp2(TIM3, capture + CCR2_Val); + } + else if (TIM_GetIntStatus(TIM3, TIM_INT_CC3) != RESET) + { + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC3); + + /* Pin PB.08 toggling with frequency = 266.66 Hz */ + GPIO_WriteBit(GPIOB, GPIO_PIN_11, (Bit_OperateType)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_PIN_11))); + capture = TIM_GetCap3(TIM3); + TIM_SetCmp3(TIM3, capture + CCR3_Val); + } + else + { + TIM_ClrIntPendingBit(TIM3, TIM_INT_CC4); + + /* Pin PB.09 toggling with frequency = 666.66 Hz */ + GPIO_WriteBit(GPIOB, GPIO_PIN_12, (Bit_OperateType)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_PIN_12))); + capture = TIM_GetCap4(TIM3); + TIM_SetCmp4(TIM3, capture + CCR4_Val); + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/MDK-ARM/TimeBasic1.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/MDK-ARM/TimeBasic1.uvoptx new file mode 100644 index 0000000..7bdd535 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/MDK-ARM/TimeBasic1.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/MDK-ARM/TimeBasic1.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/MDK-ARM/TimeBasic1.uvprojx new file mode 100644 index 0000000..18421d0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/MDK-ARM/TimeBasic1.uvprojx @@ -0,0 +1,500 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + TimeBasic1 + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\TimeBasic1.bin .\Objects\TimeBasic1.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/readme.txt new file mode 100644 index 0000000..d10a656 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/readme.txt @@ -0,0 +1,23 @@ + +1. Function description + 1. TIM1 uses the update interrupt to generate timing rollover IO + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM1 CLK=64M,TIM3 CLK=64M + 2. Interruption: + TIM1 update interrupt is turned on, priority level 1 + 3. Port configuration: + PB6 is selected as IO output + 4. TIM: + TIM1 enables periodic interrupts + Instructions: + 1. After compiling, turn on the debug mode, and use an oscilloscope or logic analyzer to observe the PB6 waveform + 2. After the program is running, the periodic interrupt of TIM1 comes to reverse the level of PB6 +4. Matters needing attention + By default, the PB6 and PB7 jumper caps of the development board are connected to the virtual serial port of NSLINK. If PB6 and PB7 are not used as serial ports in the project, and are used for other purposes, the serial port jumper caps must be unplugged. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/src/main.c new file mode 100644 index 0000000..6f360d2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/src/main.c @@ -0,0 +1,190 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_TimeBase + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +uint16_t PrescalerValue = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +void TIM_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC Configuration */ + NVIC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* TIM Configuration */ + TIM_Configuration(); + + while (1) + { + ; + } +} + +/** + * @brief Configures tim1 clocks. + */ +void TIM_Configuration(void) +{ + /* Compute the prescaler value */ + PrescalerValue = 0; + + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 65535; + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + + TIM_InitTimeBase(TIM1, &TIM_TimeBaseStructure); + + /* Prescaler configuration */ + TIM_ConfigPrescaler(TIM1, PrescalerValue, TIM_PSC_RELOAD_MODE_IMMEDIATE); + + /* TIM1 enable update irq */ + TIM_ConfigInt(TIM1, TIM_INT_UPDATE, ENABLE); + + /* TIM1 enable counter */ + TIM_Enable(TIM1, ENABLE); +} +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* PCLK2 = HCLK/4 */ + RCC_ConfigPclk2(RCC_HCLK_DIV4); + + /* TIM1 clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1, ENABLE); + + /* GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); +} + +/** + * @brief Configure the GPIO Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOC Configuration:Pin6 as Output Push Pull Mode */ + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the TIM1 global Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/src/n32wb03x_it.c new file mode 100644 index 0000000..f60e5cd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic1/src/n32wb03x_it.c @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles TIM1 update interrupt request. + */ +void TIM1_BRK_UP_TRG_COM_IRQHandler(void) +{ + if (TIM_GetIntStatus(TIM1, TIM_INT_UPDATE) != RESET) + { + TIM_ClrIntPendingBit(TIM1, TIM_INT_UPDATE); + + /* Pin PB.06 toggling */ + GPIO_WriteBit(GPIOB, GPIO_PIN_6, (Bit_OperateType)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_PIN_6))); + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/MDK-ARM/TimeBasic3.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/MDK-ARM/TimeBasic3.uvoptx new file mode 100644 index 0000000..7bdd535 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/MDK-ARM/TimeBasic3.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/MDK-ARM/TimeBasic3.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/MDK-ARM/TimeBasic3.uvprojx new file mode 100644 index 0000000..24beb31 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/MDK-ARM/TimeBasic3.uvprojx @@ -0,0 +1,500 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + TimeBasic3 + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\TimeBasic3.bin .\Objects\TimeBasic3.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/readme.txt new file mode 100644 index 0000000..6b4f7a6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/readme.txt @@ -0,0 +1,23 @@ + +1. Function description + 1. TIM3 uses the update interrupt to generate timing rollover IO + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM1 CLK=64M,TIM3 CLK=64M + 2. Interruption: + TIM3 update interrupt is turned on, priority level 1 + 3. Port configuration: + PB6 is selected as IO output + 4. TIM: + TIM3 enables periodic interrupts + Instructions: + 1. After compiling, turn on the debug mode, and use an oscilloscope or logic analyzer to observe the PB6 waveform + 2. After the program is running, the periodic interrupt of TIM3 comes to reverse the level of PB6 +4. Matters needing attention + By default, the PB6 and PB7 jumper caps of the development board are connected to the virtual serial port of NSLINK. If PB6 and PB7 are not used as serial ports in the project, and are used for other purposes, the serial port jumper caps must be unplugged. diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/src/main.c new file mode 100644 index 0000000..b0fa08d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/src/main.c @@ -0,0 +1,190 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_TimeBase + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +uint16_t PrescalerValue = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +void TIM_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC Configuration */ + NVIC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* TIM Configuration */ + TIM_Configuration(); + + while (1) + { + ; + } +} + +/** + * @brief Configures tim3 clocks. + */ +void TIM_Configuration(void) +{ + /* Compute the prescaler value */ + PrescalerValue = 0; + + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 65535; + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + + TIM_InitTimeBase(TIM3, &TIM_TimeBaseStructure); + + /* Prescaler configuration */ + TIM_ConfigPrescaler(TIM3, PrescalerValue, TIM_PSC_RELOAD_MODE_IMMEDIATE); + + /* TIM3 enable update irq */ + TIM_ConfigInt(TIM3, TIM_INT_UPDATE, ENABLE); + + /* TIM3 enable counter */ + TIM_Enable(TIM3, ENABLE); +} +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* PCLK1 = HCLK/4 */ + RCC_ConfigPclk1(RCC_HCLK_DIV4); + + /* TIM3 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE); + + /* GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); +} + +/** + * @brief Configure the GPIO Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOB Configuration:Pin6 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the TIM3 global Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/src/n32wb03x_it.c new file mode 100644 index 0000000..e6866da --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic3/src/n32wb03x_it.c @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles TIM3 global interrupt request. + */ +void TIM3_IRQHandler(void) +{ + if (TIM_GetIntStatus(TIM3, TIM_INT_UPDATE) != RESET) + { + TIM_ClrIntPendingBit(TIM3, TIM_INT_UPDATE); + + /* Pin PB.06 toggling */ + GPIO_WriteBit(GPIOB, GPIO_PIN_6, (Bit_OperateType)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_PIN_6))); + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/MDK-ARM/TimeBasic6.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/MDK-ARM/TimeBasic6.uvoptx new file mode 100644 index 0000000..7bdd535 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/MDK-ARM/TimeBasic6.uvoptx @@ -0,0 +1,419 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + n32wb03x_i2c.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + n32wb03x_iwdg.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 15 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 16 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 17 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/MDK-ARM/TimeBasic6.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/MDK-ARM/TimeBasic6.uvprojx new file mode 100644 index 0000000..5ecbbf6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/MDK-ARM/TimeBasic6.uvprojx @@ -0,0 +1,500 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + TimeBasic6 + 1 + 0 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\TimeBasic6.bin .\Objects\TimeBasic6.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_i2c.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_i2c.c + + + n32wb03x_iwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_iwdg.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/inc/main.h new file mode 100644 index 0000000..f9940a2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/inc/main.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} Status; + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/readme.txt new file mode 100644 index 0000000..5eb7e7d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/readme.txt @@ -0,0 +1,24 @@ + +1. Function description + 1. TIM6 uses the update interrupt to generate timing rollover IO + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for Use + System configuration; + 1. Clock source: + HSI=64M,AHB=64M,APB1=32M,APB2=64M, TIM1 CLK=64M,TIM3 CLK=64M + 2. Interruption: + TIM6 update interrupt is turned on, priority level 1 + 3. Port configuration: + PB6 is selected as IO output + 4. TIM: + TIM6 enables periodic interrupts + Instructions: + 1. After compiling, turn on the debug mode, and use an oscilloscope or logic analyzer to observe the PB6 waveform + 2. After the program is running, the periodic interrupt of TIM6 comes to reverse the level of PB6 + +4. Matters needing attention + By default, the PB6 and PB7 jumper caps of the development board are connected to the virtual serial port of NSLINK. If PB6 and PB7 are not used as serial ports in the project, and are used for other purposes, the serial port jumper caps must be unplugged. \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/src/main.c new file mode 100644 index 0000000..40a184b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/src/main.c @@ -0,0 +1,190 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" + +/** @addtogroup TIM_TimeBase + * @{ + */ + +TIM_TimeBaseInitType TIM_TimeBaseStructure; +OCInitType TIM_OCInitStructure; +uint16_t PrescalerValue = 0; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +void TIM_Configuration(void); + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC Configuration */ + NVIC_Configuration(); + + /* GPIO Configuration */ + GPIO_Configuration(); + + /* TIM Configuration */ + TIM_Configuration(); + + while (1) + { + ; + } +} + +/** + * @brief Configures tim6 clocks. + */ +void TIM_Configuration(void) +{ + /* Compute the prescaler value */ + PrescalerValue = 0; + + /* Time base configuration */ + TIM_TimeBaseStructure.Period = 65535; + TIM_TimeBaseStructure.Prescaler = 0; + TIM_TimeBaseStructure.ClkDiv = 0; + TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP; + + TIM_InitTimeBase(TIM6, &TIM_TimeBaseStructure); + + /* Prescaler configuration */ + TIM_ConfigPrescaler(TIM6, PrescalerValue, TIM_PSC_RELOAD_MODE_IMMEDIATE); + + /* TIM6 enable update irq */ + TIM_ConfigInt(TIM6, TIM_INT_UPDATE, ENABLE); + + /* TIM6 enable counter */ + TIM_Enable(TIM6, ENABLE); +} +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* PCLK1 = HCLK/4 */ + RCC_ConfigPclk1(RCC_HCLK_DIV4); + + /* TIM6 clock enable */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM6, ENABLE); + + /* GPIOB clock enable */ + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); +} + +/** + * @brief Configure the GPIO Pins. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + GPIO_InitStruct(&GPIO_InitStructure); + /* GPIOB Configuration:Pin6 as alternate function push-pull */ + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW; + + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); +} + +/** + * @brief Configure the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the TIM6 global Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/src/n32wb03x_it.c new file mode 100644 index 0000000..da6d496 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/TIM/TimeBasic6/src/n32wb03x_it.c @@ -0,0 +1,129 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles TIM6 global interrupt request. + */ +void TIM6_IRQHandler(void) +{ + if (TIM_GetIntStatus(TIM6, TIM_INT_UPDATE) != RESET) + { + TIM_ClrIntPendingBit(TIM6, TIM_INT_UPDATE); + + /* Pin PB.06 toggling */ + GPIO_WriteBit(GPIOB, GPIO_PIN_6, (Bit_OperateType)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_PIN_6))); + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvoptx new file mode 100644 index 0000000..dc4b027 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvoptx @@ -0,0 +1,335 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvprojx new file mode 100644 index 0000000..a697416 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/MDK-ARM/DMA_Interrupt.uvprojx @@ -0,0 +1,465 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + DMA_Interrupt + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\DMA_Interrupt.bin .\Objects\DMA_Interrupt.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/inc/main.h new file mode 100644 index 0000000..5e076d8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/inc/main.h @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _USART1_USART2_ + +#ifdef _USART1_USART2_ +#define USARTy USART1 +#define USARTy_CLK RCC_APB2_PERIPH_USART1 +#define USARTy_GPIO GPIOB +#define USARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTy_RxPin GPIO_PIN_7 +#define USARTy_TxPin GPIO_PIN_6 +#define USARTy_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_Tx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USARTy_DAT_Base (USART1_BASE + 0x04) +#define USARTy_Tx_DMA_Channel DMA_CH1 +#define USARTy_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTy_Tx_DMA_REMAP DMA_REMAP_USART1_TX + + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#define USARTz_DAT_Base (USART2_BASE + 0x04) +#define USARTz_Tx_DMA_Channel DMA_CH3 +#define USARTz_Tx_DMA_FLAG DMA_FLAG_TC3 +#define USARTz_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTz_IRQn USART2_IRQn +#endif + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +void DMA_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/inc/n32wb03x_it.h new file mode 100644 index 0000000..701dd04 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void USART1_2_IRQHandler(void); +void UART5_6_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/readme.txt new file mode 100644 index 0000000..1d0c7dd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/readme.txt @@ -0,0 +1,42 @@ + +1. Function description + + This test example demonstrates the basic communication between USARTy and USARTz through DMA (interrupt). USARTy and USARTz can be USART1 and USART2. + First, DMA transfers the TxBuffer1 data to the USARTy send data register. After the transfer is completed, a DMA interrupt is generated, and then the data is sent to +USARTz. USARTz receives data, DMA moves data from USARTz receive data register to RxBuffer2, and generates DMA interrupt after completion. + At the same time, DMA transfers TxBuffer2 data to the USARTz send data register, the transfer is completed and a DMA interrupt is generated, and then the data is +sent to LPUART. USARTy receives data, DMA moves the data from the LPUART receive data register to RxBuffer1, and generates a DMA interrupt after completion. + Finally, compare the two groups of receiving and sending data respectively, and store the comparison results in the TransferStatus1 variable and the TransferStatus2 +variable. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + -DMA transmission mode is enabled, DMA reception mode is disabled + + The USART pin connections are as follows: + - USART1_Tx.PB6 <-------> USART2_Rx.PB5 + - USART1_Rx.PB7 <-------> USART2_Tx.PB4 + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus1 and TransferStatus2 in turn, + PASSED means the test passed, FAILED means the test is abnormal + + +4. Matters needing attention + the MCU_TX and MCU_RX jumper cap of the development board NS-LINK needs to be disconnected first \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/src/main.c new file mode 100644 index 0000000..afd3ed0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/src/main.c @@ -0,0 +1,305 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_DMA_Interrupt + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1) - 1) +#define TxBufferSize2 (countof(TxBuffer2) - 1) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "USART DMA Interrupt: USARTy -> USARTz using DMA Tx and Rx Flag"; +uint8_t TxBuffer2[] = "USART DMA Interrupt: USARTz -> USARTy using DMA Tx and Rx Interrupt"; +uint8_t RxBuffer1[TxBufferSize2]; +uint8_t RxBuffer2[TxBufferSize1]; +uint8_t NbrOfDataToRead = TxBufferSize1; +uint32_t indexFlag = 0; +volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC configuration */ + NVIC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* Configure the DMA */ + DMA_Configuration(); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTy and USARTz */ + USART_Init(USARTy, &USART_InitStructure); + USART_Init(USARTz, &USART_InitStructure); + + /* Enable USARTy DMA Rx and TX request */ + USART_EnableDMA(USARTy, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + /* Enable USARTz DMA Rx and TX request */ + USART_EnableDMA(USARTz, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + /* Enable the USARTz Receive Interrupt */ + USART_ConfigInt(USARTz, USART_INT_RXDNE, ENABLE); + + /* Enable USARTy TX DMA Channel */ + DMA_EnableChannel(USARTy_Tx_DMA_Channel, ENABLE); + /* Enable USARTz TX DMA Channel */ + DMA_EnableChannel(USARTz_Tx_DMA_Channel, ENABLE); + + /* Enable the USARTy and USARTz */ + USART_Enable(USARTy, ENABLE); + USART_Enable(USARTz, ENABLE); + + /* Receive the TxBuffer2 */ + while (indexFlag < TxBufferSize2) + { + while (USART_GetFlagStatus(USARTy, USART_FLAG_RXDNE) == RESET) + { + } + RxBuffer1[indexFlag++] = USART_ReceiveData(USARTy); + } + + /* Wait until USARTy TX DMA Channel Transfer Complete */ + while (DMA_GetFlagStatus(USARTy_Tx_DMA_FLAG, DMA) == RESET) + { + } + /* Wait until USARTz TX DMA Channel Transfer Complete */ + while (DMA_GetFlagStatus(USARTz_Tx_DMA_FLAG, DMA) == RESET) + { + } + + /* Check the received data with the send ones */ + TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); + /* TransferStatus1 = PASSED, if the data transmitted from USARTz and + received by USARTy are the same */ + /* TransferStatus1 = FAILED, if the data transmitted from USARTz and + received by USARTy are different */ + TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); + /* TransferStatus2 = PASSED, if the data transmitted from USARTy and + received by USARTz are the same */ + /* TransferStatus2 = FAILED, if the data transmitted from USARTy and + received by USARTz are different */ + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(USARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + /* Enable USARTy and USARTz Clock */ + USARTy_APBxClkCmd(USARTy_CLK, ENABLE); + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_TxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTy_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the USARTz Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTz_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTy_Tx_DMA_Channel (triggered by USARTy Tx event) Config */ + DMA_DeInit(USARTy_Tx_DMA_Channel); + DMA_InitStructure.PeriphAddr = USARTy_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)TxBuffer1; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = TxBufferSize1; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTy_Tx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(USARTy_Tx_DMA_REMAP, DMA, USARTy_Tx_DMA_Channel, ENABLE); + + /* USARTz_Tx_DMA_Channel (triggered by USARTz Tx event) Config */ + DMA_DeInit(USARTz_Tx_DMA_Channel); + DMA_InitStructure.PeriphAddr = USARTz_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)TxBuffer2; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = TxBufferSize2; + DMA_Init(USARTz_Tx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(USARTz_Tx_DMA_REMAP, DMA, USARTz_Tx_DMA_Channel, ENABLE); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/src/n32wb03x_it.c new file mode 100644 index 0000000..458f010 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Interrupt/src/n32wb03x_it.c @@ -0,0 +1,144 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +uint8_t RxCounter = 0; +extern uint8_t RxBuffer2[]; +extern uint8_t NbrOfDataToRead; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ +/** + * @brief This function handles USART2 global interrupt request. + */ +void USART2_IRQHandler(void) +{ + if (USART_GetIntStatus(USART2, USART_INT_RXDNE) != RESET) + { + /* Read one byte from the receive data register */ + RxBuffer2[RxCounter++] = USART_ReceiveData(USART2); + + if (RxCounter == NbrOfDataToRead) + { + /* Disable the USART2 Receive interrupt */ + USART_ConfigInt(USART2, USART_INT_RXDNE, DISABLE); + } + } +} + + + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/MDK-ARM/DMA_Polling.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/MDK-ARM/DMA_Polling.uvoptx new file mode 100644 index 0000000..dc4b027 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/MDK-ARM/DMA_Polling.uvoptx @@ -0,0 +1,335 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/MDK-ARM/DMA_Polling.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/MDK-ARM/DMA_Polling.uvprojx new file mode 100644 index 0000000..1e2226b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/MDK-ARM/DMA_Polling.uvprojx @@ -0,0 +1,465 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + DMA_Polling + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\DMA_Polling.bin .\Objects\DMA_Polling.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/inc/main.h new file mode 100644 index 0000000..954dbf9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/inc/main.h @@ -0,0 +1,119 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _USART1_USART2_ + +#ifdef _USART1_USART2_ +#define USARTy USART1 +#define USARTy_CLK RCC_APB2_PERIPH_USART1 +#define USARTy_GPIO GPIOB +#define USARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTy_RxPin GPIO_PIN_7 +#define USARTy_TxPin GPIO_PIN_6 +#define USARTy_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_Tx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USARTy_DAT_Base (USART1_BASE + 0x04) +#define USARTy_Tx_DMA_Channel DMA_CH1 +#define USARTy_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTy_Rx_DMA_Channel DMA_CH2 +#define USARTy_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTy_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTy_Rx_DMA_REMAP DMA_REMAP_USART1_RX + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#define USARTz_DAT_Base (USART2_BASE + 0x04) +#define USARTz_Tx_DMA_Channel DMA_CH3 +#define USARTz_Tx_DMA_FLAG DMA_FLAG_TC3 +#define USARTz_Rx_DMA_Channel DMA_CH4 +#define USARTz_Rx_DMA_FLAG DMA_FLAG_TC4 +#define USARTz_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTz_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#endif + + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void DMA_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/readme.txt new file mode 100644 index 0000000..10be945 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/readme.txt @@ -0,0 +1,44 @@ + +1. Function description + + This test example demonstrates the basic communication between USARTy and USARTz through DMA (interrupt). USARTy and USARTz can be USART1 and USART2. + First, DMA transfers the TxBuffer1 data to the USARTy send data register. After the transfer is completed, a DMA interrupt is generated, and then the data is sent to +USARTz. USARTz receives data, DMA moves data from USARTz receive data register to RxBuffer2, and generates DMA interrupt after completion. + At the same time, DMA transfers TxBuffer2 data to the USARTz send data register, the transfer is completed and a DMA interrupt is generated, and then the data is +sent to LPUART. USARTy receives data, DMA moves the data from the LPUART receive data register to RxBuffer1, and generates a DMA interrupt after completion. + Finally, compare the two groups of receiving and sending data respectively, and store the comparison results in the TransferStatus1 variable and the TransferStatus2 +variable. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + -DMA transmission mode is enabled, DMA reception mode is disabled + + The USART pin connections are as follows: + - USART1_Tx.PB6 <-------> USART2_Rx.PB5 + - USART1_Rx.PB7 <-------> USART2_Tx.PB4 + + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus1 and TransferStatus2 in turn, + PASSED means the test passed, FAILED means the test is abnormal + + +4. Matters needing attention + the MCU_TX and MCU_RX jumper cap of the development board NS-LINK needs to be disconnected first \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/src/main.c new file mode 100644 index 0000000..4a8fc31 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/src/main.c @@ -0,0 +1,307 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_DMA_Polling + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1) - 1) +#define TxBufferSize2 (countof(TxBuffer2) - 1) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "USART DMA Polling: USARTy -> USARTz using DMA"; +uint8_t TxBuffer2[] = "USART DMA Polling: USARTz -> USARTy using DMA"; +uint8_t RxBuffer1[TxBufferSize2]; +uint8_t RxBuffer2[TxBufferSize1]; +volatile TestStatus TransferStatus1 = FAILED; +volatile TestStatus TransferStatus2 = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* Configure the DMA */ + DMA_Configuration(); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTy and USARTz */ + USART_Init(USARTy, &USART_InitStructure); + USART_Init(USARTz, &USART_InitStructure); + + /* Enable USARTy DMA Rx and TX request */ + USART_EnableDMA(USARTy, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + /* Enable USARTz DMA Rx and TX request */ + USART_EnableDMA(USARTz, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + /* Enable USARTy TX DMA Channel */ + DMA_EnableChannel(USARTy_Tx_DMA_Channel, ENABLE); + /* Enable USARTy RX DMA Channel */ + DMA_EnableChannel(USARTy_Rx_DMA_Channel, ENABLE); + + /* Enable USARTz TX DMA Channel */ + DMA_EnableChannel(USARTz_Tx_DMA_Channel, ENABLE); + /* Enable USARTz RX DMA Channel */ + DMA_EnableChannel(USARTz_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTy and USARTz */ + USART_Enable(USARTy, ENABLE); + USART_Enable(USARTz, ENABLE); + + /* Wait until USARTy TX DMA Channel Transfer Complete */ + while (DMA_GetFlagStatus(USARTy_Tx_DMA_FLAG, DMA) == RESET) + { + } + /* Wait until USARTy RX DMA Channel Transfer Complete */ + while (DMA_GetFlagStatus(USARTy_Rx_DMA_FLAG, DMA) == RESET) + { + } + + /* Wait until USARTz TX DMA Channel Transfer Complete */ + while (DMA_GetFlagStatus(USARTz_Tx_DMA_FLAG, DMA) == RESET) + { + } + /* Wait until USARTz RX DMA Channel Transfer Complete */ + while (DMA_GetFlagStatus(USARTz_Rx_DMA_FLAG, DMA) == RESET) + { + } + + /* Check the received data with the send ones */ + TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); + /* TransferStatus1 = PASSED, if the data transmitted from USARTz and + received by USARTy are the same */ + /* TransferStatus1 = FAILED, if the data transmitted from USARTz and + received by USARTy are different */ + TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); + /* TransferStatus2 = PASSED, if the data transmitted from USARTy and + received by USARTz are the same */ + /* TransferStatus2 = FAILED, if the data transmitted from USARTy and + received by USARTz are different */ + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(USARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + /* Enable USARTy and USARTz Clock */ + USARTy_APBxClkCmd(USARTy_CLK, ENABLE); + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_TxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTy_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTy TX DMA Channel (triggered by USARTy Tx event) Config */ + DMA_DeInit(USARTy_Tx_DMA_Channel); + DMA_InitStructure.PeriphAddr = USARTy_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)TxBuffer1; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = TxBufferSize1; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTy_Tx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(USARTy_Tx_DMA_REMAP, DMA, USARTy_Tx_DMA_Channel, ENABLE); + + /* USARTy RX DMA Channel (triggered by USARTy Rx event) Config */ + DMA_DeInit(USARTy_Rx_DMA_Channel); + DMA_InitStructure.PeriphAddr = USARTy_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)RxBuffer1; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = TxBufferSize2; + DMA_Init(USARTy_Rx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(USARTy_Rx_DMA_REMAP, DMA, USARTy_Rx_DMA_Channel, ENABLE); + + /* USARTz TX DMA Channel (triggered by USARTz Tx event) Config */ + DMA_DeInit(USARTz_Tx_DMA_Channel); + DMA_InitStructure.PeriphAddr = USARTz_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)TxBuffer2; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = TxBufferSize2; + DMA_Init(USARTz_Tx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(USARTz_Tx_DMA_REMAP, DMA, USARTz_Tx_DMA_Channel, ENABLE); + + /* USARTz RX DMA Channel (triggered by USARTz Rx event) Config */ + DMA_DeInit(USARTz_Rx_DMA_Channel); + DMA_InitStructure.PeriphAddr = USARTz_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)RxBuffer2; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = TxBufferSize1; + DMA_Init(USARTz_Rx_DMA_Channel, &DMA_InitStructure); + DMA_RequestRemap(USARTz_Rx_DMA_REMAP, DMA, USARTz_Rx_DMA_Channel, ENABLE); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/src/n32wb03x_it.c new file mode 100644 index 0000000..17d66e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/DMA_Polling/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/MDK-ARM/HalfDuplex.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/MDK-ARM/HalfDuplex.uvoptx new file mode 100644 index 0000000..294d883 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/MDK-ARM/HalfDuplex.uvoptx @@ -0,0 +1,323 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 9 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/MDK-ARM/HalfDuplex.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/MDK-ARM/HalfDuplex.uvprojx new file mode 100644 index 0000000..39558aa --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/MDK-ARM/HalfDuplex.uvprojx @@ -0,0 +1,460 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + HalfDuplex + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\HalfDuplex.bin .\Objects\HalfDuplex.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/inc/main.h new file mode 100644 index 0000000..16727ef --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/inc/main.h @@ -0,0 +1,99 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _USART1_USART2_ + +#ifdef _USART1_USART2_ +#define USARTy USART1 +#define USARTy_CLK RCC_APB2_PERIPH_USART1 +#define USARTy_GPIO GPIOB +#define USARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTy_TxPin GPIO_PIN_6 +#define USARTy_Tx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#endif + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/readme.txt new file mode 100644 index 0000000..e12cff7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/readme.txt @@ -0,0 +1,41 @@ + +1. Function description + + This test example demonstrates the basic communication between USARTy and USARTz by querying and detecting identifications in half-duplex mode. + First, USARTy sends TxBuffer1 data to USARTz, and USARTz receives data and stores it in RxBuffer2. + Subsequently, USARTz sends TxBuffer2 data to USARTy, and USARTy receives data to RxBuffer1. + Finally, compare the two groups of received data and sent data respectively, and store the comparison results in the TransferStatus1 variable +And the TransferStatus2 variable. + USARTy and USARTz can be USART1 and USART2. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + -Half-duplex mode enabled + + The USART pin connections are as follows: + - USART1_Tx.PB6 <-------> USART2_Tx.PB4 + + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -After resetting the operation, check the variables TransferStatus1 and TransferStatus2 in turn, + PASSED means the test passed, FAILED means the test is abnormal + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/src/main.c new file mode 100644 index 0000000..60c3962 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/src/main.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_HalfDuplex + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1) - 1) +#define TxBufferSize2 (countof(TxBuffer2) - 1) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "USART Half Duplex: USARTy -> USARTz using HalfDuplex mode"; +uint8_t TxBuffer2[] = "USART Half Duplex: USARTz -> USARTy using HalfDuplex mode"; +uint8_t RxBuffer1[TxBufferSize2]; +uint8_t RxBuffer2[TxBufferSize1]; +uint32_t NbrOfDataToRead1 = TxBufferSize2; +uint32_t NbrOfDataToRead2 = TxBufferSize1; +uint8_t TxCounter1 = 0, RxCounter1 = 0; +uint8_t TxCounter2 = 0, RxCounter2 = 0; +volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTy and USARTz */ + USART_Init(USARTy, &USART_InitStructure); + USART_Init(USARTz, &USART_InitStructure); + + /* Enable the USARTy and USARTz */ + USART_Enable(USARTy, ENABLE); + USART_Enable(USARTz, ENABLE); + + /* Enable USARTy Half Duplex Mode*/ + USART_EnableHalfDuplex(USARTy, ENABLE); + /* Enable USARTz Half Duplex Mode*/ + USART_EnableHalfDuplex(USARTz, ENABLE); + + while (NbrOfDataToRead2--) + { + /* Wait until end of transmit */ + while (USART_GetFlagStatus(USARTy, USART_FLAG_TXDE) == RESET) + { + } + /* Write one byte in the USARTy Transmit Data Register */ + USART_SendData(USARTy, TxBuffer1[TxCounter1++]); + + /* Wait the byte is entirely received by USARTz */ + while (USART_GetFlagStatus(USARTz, USART_FLAG_RXDNE) == RESET) + { + } + /* Store the received byte in the RxBuffer2 */ + RxBuffer2[RxCounter2++] = USART_ReceiveData(USARTz); + } + + /* Clear the USARTy Data Register */ + USART_ReceiveData(USARTy); + + while (NbrOfDataToRead1--) + { + /* Wait until end of transmit */ + while (USART_GetFlagStatus(USARTz, USART_FLAG_TXDE) == RESET) + { + } + /* Write one byte in the USARTz Transmit Data Register */ + USART_SendData(USARTz, TxBuffer2[TxCounter2++]); + + /* Wait the byte is entirely received by USARTy */ + while (USART_GetFlagStatus(USARTy, USART_FLAG_RXDNE) == RESET) + { + } + /* Store the received byte in the RxBuffer1 */ + RxBuffer1[RxCounter1++] = USART_ReceiveData(USARTy); + } + + /* Check the received data with the send ones */ + TransferStatus1 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); + /* TransferStatus = PASSED, if the data transmitted from USARTy and + received by USARTz are the same */ + /* TransferStatus = FAILED, if the data transmitted from USARTy and + received by USARTz are different */ + TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); + /* TransferStatus = PASSED, if the data transmitted from USARTz and + received by USARTy are the same */ + /* TransferStatus = FAILED, if the data transmitted from USARTz and + received by USARTy are different */ + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(USARTy_GPIO_CLK | USARTz_GPIO_CLK, ENABLE); + /* Enable USARTy and USARTz Clock */ + USARTy_APBxClkCmd(USARTy_CLK, ENABLE); + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTy Tx as alternate function open-drain and pull-up */ + GPIO_InitStructure.Pin = USARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_OD; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = USARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Tx as alternate function open-drain */ + GPIO_InitStructure.Pin = USARTz_TxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL; + GPIO_InitStructure.GPIO_Alternate = USARTz_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/src/n32wb03x_it.c new file mode 100644 index 0000000..17d66e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HalfDuplex/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvoptx new file mode 100644 index 0000000..7dc38d6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvoptx @@ -0,0 +1,323 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 9 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvprojx new file mode 100644 index 0000000..7f50e70 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/MDK-ARM/Receive_RTS.uvprojx @@ -0,0 +1,460 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Receive_RTS + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Receive_RTS.bin .\Objects\Receive_RTS.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/inc/main.h new file mode 100644 index 0000000..9ced684 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/inc/main.h @@ -0,0 +1,115 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +#define USARTy USART1 +#define USARTy_CLK RCC_APB2_PERIPH_USART1 +#define USARTy_GPIO GPIOB +#define USARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTy_RxPin GPIO_PIN_7 +#define USARTy_TxPin GPIO_PIN_6 +#define USARTy_RTSPin GPIO_PIN_8 +#define USARTy_CTSPin GPIO_PIN_9 +#define USARTy_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_Tx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_RTS_GPIO_AF GPIO_AF3_USART1 +#define USARTy_CTS_GPIO_AF GPIO_AF3_USART1 +#define USARTy_APBxClkCmd RCC_EnableAPB2PeriphClk + + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_RTS_GPIO GPIOB +#define USARTz_CTS_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RTS_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_CTS_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_RTSPin GPIO_PIN_11 +#define USARTz_CTSPin GPIO_PIN_12 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_RTS_GPIO_AF GPIO_AF3_USART2 +#define USARTz_CTS_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk + + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); +void Delay(__IO uint32_t nCount); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/readme.txt new file mode 100644 index 0000000..c85e51d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/readme.txt @@ -0,0 +1,48 @@ + +1. Function description + + This example demonstrates the basic communication between USARTy and USARTz using hardware flow control. USARTy and USARTz can be USART1 and USART2. + First, USARTy uses CTS to send TxBuffer1 data, USARTz uses RTS to receive data and stores it in RxBuffer1; + Then, compare the received data with the sent data, and the comparison results are stored in the variables TransferStatus respectively. + + Note: test example with \USART\HardwareFlowCtrl_ok\Transmit_CTS + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USARTy configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -CTS hardware flow control enable + -Transmitter enable + + The USARTz configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -RTS hardware flow control enable + -Receiver enable + + + The USART pin connections are as follows: + - USART1_Tx.PB6 <-------> USART2_Rx.PB5 + - USART1_CTS.PB9 <-------> USART2_RTS.PB11 + + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus in turn, PASSED means the test passed and FAILED means the test is abnormal + + +4. Matters needing attention + the MCU_TX and MCU_RX jumper cap of the development board NS-LINK needs to be disconnected first \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/src/main.c new file mode 100644 index 0000000..00fbf8a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/src/main.c @@ -0,0 +1,222 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_Receive_RTS + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1) - 1) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "USART Flow_Control Mode Example: Board1_USARTy -> Board2_USARTz using CTS and RTS Flags"; +uint8_t RxBuffer1[TxBufferSize1]; +__IO uint8_t RxCounter = 0; +volatile TestStatus TransferStatus = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_RTS; + USART_InitStructure.Mode = USART_MODE_RX; + + /* Configure USARTz */ + USART_Init(USARTz, &USART_InitStructure); + /* Enable the USARTz */ + USART_Enable(USARTz, ENABLE); + + while (RxCounter < TxBufferSize1) + { + /* Loop until the USARTz Receive Data Register is not empty */ + while (USART_GetFlagStatus(USARTz, USART_FLAG_RXDNE) == RESET) + { + } + + Delay(0x2FFFF); + + /* Store the received byte in RxBuffer */ + RxBuffer1[RxCounter++] = USART_ReceiveData(USARTz); + } + + /* Check the received data with the send ones */ + /* TransferStatus = PASSED, if the data transmitted from USARTy and + received by USARTz are the same */ + /* TransferStatus = FAILED, if the data transmitted from USARTy and + received by USARTz are different */ + TransferStatus = Buffercmp(TxBuffer1, RxBuffer1, TxBufferSize1); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable GPIOx and AFIO clocks */ + RCC_EnableAPB2PeriphClk(USARTz_GPIO_CLK | USARTz_RTS_GPIO_CLK, ENABLE); + + /* Enable USARTz clocks */ + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTy RTS as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_RTSPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTz_RTS_GPIO_AF; + GPIO_InitPeripheral(USARTz_RTS_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = USARTz_RxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = USARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +/** + * @brief Inserts a delay time. + * @param nCount specifies the delay time length. + */ +void Delay(__IO uint32_t nCount) +{ + /* Decrement nCount value */ + for (; nCount != 0; nCount--) + ; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/src/n32wb03x_it.c new file mode 100644 index 0000000..894a999 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Receive_RTS/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M4 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvoptx new file mode 100644 index 0000000..7dc38d6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvoptx @@ -0,0 +1,323 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 9 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvprojx new file mode 100644 index 0000000..3a4ed1a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/MDK-ARM/Transmit_CTS.uvprojx @@ -0,0 +1,460 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Transmit_CTS + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Transmit_CTS.bin .\Objects\Transmit_CTS.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/inc/main.h new file mode 100644 index 0000000..9853a60 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/inc/main.h @@ -0,0 +1,113 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +#define USARTy USART1 +#define USARTy_CLK RCC_APB2_PERIPH_USART1 +#define USARTy_GPIO GPIOB +#define USARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTy_RxPin GPIO_PIN_7 +#define USARTy_TxPin GPIO_PIN_6 +#define USARTy_RTSPin GPIO_PIN_8 +#define USARTy_CTSPin GPIO_PIN_9 +#define USARTy_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_Tx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_RTS_GPIO_AF GPIO_AF3_USART1 +#define USARTy_CTS_GPIO_AF GPIO_AF3_USART1 +#define USARTy_APBxClkCmd RCC_EnableAPB2PeriphClk + + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_RTS_GPIO GPIOB +#define USARTz_CTS_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RTS_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_CTS_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_RTSPin GPIO_PIN_11 +#define USARTz_CTSPin GPIO_PIN_12 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_RTS_GPIO_AF GPIO_AF3_USART2 +#define USARTz_CTS_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk + + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/readme.txt new file mode 100644 index 0000000..44ba2e0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/readme.txt @@ -0,0 +1,48 @@ + +1. Function description + + This example demonstrates the basic communication between USARTy and USARTz using hardware flow control. USARTy and USARTz can be USART1 and USART2. + First, USARTy uses CTS to send TxBuffer1 data, USARTz uses RTS to receive data and stores it in RxBuffer1; + Then, compare the received data with the sent data, and the comparison results are stored in the variables TransferStatus respectively. + + Note: test example with \USART\HardwareFlowCtrl_ok\Transmit_RTS + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USARTy configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -CTS hardware flow control enable + -Transmitter enable + + The USARTz configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -RTS hardware flow control enable + -Receiver enable + + + The USART pin connections are as follows: + - USART1_Tx.PB6 <-------> USART2_Rx.PB5 + - USART1_CTS.PB9 <-------> USART2_RTS.PB11 + + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus in turn, PASSED means the test passed and FAILED means the test is abnormal + + +4. Matters needing attention + the MCU_TX and MCU_RX jumper cap of the development board NS-LINK needs to be disconnected first \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/src/main.c new file mode 100644 index 0000000..8e3cdbb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/src/main.c @@ -0,0 +1,177 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_Transmit_CTS + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1) - 1) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "USART Flow_Control Mode Example: Board1_USARTy -> Board2_USARTz using CTS and RTS Flags"; +__IO uint8_t TxCounter = 0; +volatile TestStatus TransferStatus = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_CTS; + USART_InitStructure.Mode = USART_MODE_TX; + + /* Configure USARTy */ + USART_Init(USARTy, &USART_InitStructure); + /* Enable the USARTy */ + USART_Enable(USARTy, ENABLE); + + while (TxCounter < TxBufferSize1) + { + /* Send one byte from Board1_USARTy to Board2_USARTz */ + USART_SendData(USARTy, TxBuffer1[TxCounter++]); + /* Loop until Board1_USARTy DAT register is empty */ + while (USART_GetFlagStatus(USARTy, USART_FLAG_TXDE) == RESET) + { + } + } + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable GPIOx and AFIO clocks */ + RCC_EnableAPB2PeriphClk(USARTy_GPIO_CLK, ENABLE); + + /* Enable USARTy clocks */ + USARTy_APBxClkCmd(USARTy_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTy CTS as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = USARTy_CTSPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = USARTy_CTS_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/src/n32wb03x_it.c new file mode 100644 index 0000000..894a999 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/HardwareFlowCtrl/Transmit_CTS/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M4 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/MDK-ARM/Interrupt.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/MDK-ARM/Interrupt.uvoptx new file mode 100644 index 0000000..294d883 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/MDK-ARM/Interrupt.uvoptx @@ -0,0 +1,323 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 9 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/MDK-ARM/Interrupt.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/MDK-ARM/Interrupt.uvprojx new file mode 100644 index 0000000..f31044c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/MDK-ARM/Interrupt.uvprojx @@ -0,0 +1,460 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Interrupt + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Interrupt.bin .\Objects\Interrupt.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/inc/main.h new file mode 100644 index 0000000..d352a5f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/inc/main.h @@ -0,0 +1,110 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _USART1_USART2_ + +#ifdef _USART1_USART2_ +#define USARTy USART1 +#define USARTy_CLK RCC_APB2_PERIPH_USART1 +#define USARTy_GPIO GPIOB +#define USARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTy_RxPin GPIO_PIN_7 +#define USARTy_TxPin GPIO_PIN_6 +#define USARTy_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_Tx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USARTy_IRQn USART1_IRQn +#define USARTy_IRQHandler USART1_IRQHandler + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#define USARTz_IRQn USART2_IRQn +#define USARTz_IRQHandler USART2_IRQHandler +#endif + + + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void NVIC_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/inc/n32wb03x_it.h new file mode 100644 index 0000000..6e7c451 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/inc/n32wb03x_it.h @@ -0,0 +1,88 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void USART1_IRQHandler(void); +void USART2_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/readme.txt new file mode 100644 index 0000000..fe322d6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/readme.txt @@ -0,0 +1,41 @@ + +1. Function description + + This test case demonstrates the basic communication between USARTy and USARTz through interrupts. + USARTy sends TxBuffer1 data to USARTz, and USARTz receives data to RxBuffer2. At the same time, USARTz sends TxBuffer2 +data to USARTy, and USARTy receives data to RxBuffer1. + Subsequently, the two groups of received data and sent data are compared respectively, and the comparison results are +stored in the TransferStatus1 variable and the TransferStatus2 variable. + USARTy and USARTz can be USART1 and USART2. + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + + The USART pin connections are as follows: + - USART1_Tx.PB6 <-------> USART2_Rx.PB5 + - USART1_Rx.PB7 <-------> USART2_Tx.PB4 + + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus1 and TransferStatus2 in turn, + PASSED means the test passed, FAILED means the test is abnormal + + +4. Matters needing attention + the MCU_TX and MCU_RX jumper cap of the development board NS-LINK needs to be disconnected first diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/src/main.c new file mode 100644 index 0000000..bde7029 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/src/main.c @@ -0,0 +1,269 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_Interrupt + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1) - 1) +#define TxBufferSize2 (countof(TxBuffer2) - 1) +#define RxBufferSize1 TxBufferSize2 +#define RxBufferSize2 TxBufferSize1 + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "USART Interrupt Example: USARTy -> USARTz using Interrupt"; +uint8_t TxBuffer2[] = "USART Interrupt Example: USARTz -> USARTy using Interrupt"; +uint8_t RxBuffer1[RxBufferSize1]; +uint8_t RxBuffer2[RxBufferSize2]; +__IO uint8_t TxCounter1 = 0x00; +__IO uint8_t TxCounter2 = 0x00; +__IO uint8_t RxCounter1 = 0x00; +__IO uint8_t RxCounter2 = 0x00; +uint8_t NbrOfDataToTransfer1 = TxBufferSize1; +uint8_t NbrOfDataToTransfer2 = TxBufferSize2; +uint8_t NbrOfDataToRead1 = RxBufferSize1; +uint8_t NbrOfDataToRead2 = RxBufferSize2; +__IO TestStatus TransferStatus1 = FAILED; +__IO TestStatus TransferStatus2 = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* NVIC configuration */ + NVIC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTy and USARTz */ + USART_Init(USARTy, &USART_InitStructure); + USART_Init(USARTz, &USART_InitStructure); + + /* Enable USARTy Receive and Transmit interrupts */ + USART_ConfigInt(USARTy, USART_INT_RXDNE, ENABLE); + USART_ConfigInt(USARTy, USART_INT_TXDE, ENABLE); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTz, USART_INT_RXDNE, ENABLE); + USART_ConfigInt(USARTz, USART_INT_TXDE, ENABLE); + + /* Enable the USARTy and USARTz */ + USART_Enable(USARTy, ENABLE); + USART_Enable(USARTz, ENABLE); + + /* Wait until end of transmission from USARTy to USARTz */ + while (RxCounter2 < RxBufferSize2) + { + } + + /* Wait until end of transmission from USARTz to USARTy */ + while (RxCounter1 < RxBufferSize1) + { + } + + /* Check the received data with the send ones */ + TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, RxBufferSize1); + /* TransferStatus1 = PASSED, if the data transmitted from USARTz and + received by USARTy are the same */ + /* TransferStatus1 = FAILED, if the data transmitted from USARTz and + received by USARTy are different */ + TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, RxBufferSize2); + /* TransferStatus2 = PASSED, if the data transmitted from USARTy and + received by USARTz are the same */ + /* TransferStatus2 = FAILED, if the data transmitted from USARTy and + received by USARTz are different */ + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(USARTy_GPIO_CLK | USARTz_GPIO_CLK, ENABLE); + /* Enable USARTy and USARTz Clock */ + USARTy_APBxClkCmd(USARTy_CLK, ENABLE); + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_TxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTy_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the USARTy Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTy_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + /* Enable the USARTz Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTz_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/src/n32wb03x_it.c new file mode 100644 index 0000000..64963d3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Interrupt/src/n32wb03x_it.c @@ -0,0 +1,188 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern uint8_t TxBuffer1[]; +extern uint8_t TxBuffer2[]; +extern uint8_t RxBuffer1[]; +extern uint8_t RxBuffer2[]; +extern __IO uint8_t TxCounter1; +extern __IO uint8_t TxCounter2; +extern __IO uint8_t RxCounter1; +extern __IO uint8_t RxCounter2; +extern uint8_t NbrOfDataToTransfer1; +extern uint8_t NbrOfDataToTransfer2; +extern uint8_t NbrOfDataToRead1; +extern uint8_t NbrOfDataToRead2; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles USARTy global interrupt request. + */ +void USARTy_IRQHandler(void) +{ + if (USART_GetIntStatus(USARTy, USART_INT_RXDNE) != RESET) + { + /* Read one byte from the receive data register */ + RxBuffer1[RxCounter1++] = USART_ReceiveData(USARTy); + + if (RxCounter1 == NbrOfDataToRead1) + { + /* Disable the USARTy Receive interrupt */ + USART_ConfigInt(USARTy, USART_INT_RXDNE, DISABLE); + } + } + + if (USART_GetIntStatus(USARTy, USART_INT_TXDE) != RESET) + { + /* Write one byte to the transmit data register */ + USART_SendData(USARTy, TxBuffer1[TxCounter1++]); + + if (TxCounter1 == NbrOfDataToTransfer1) + { + /* Disable the USARTy Transmit interrupt */ + USART_ConfigInt(USARTy, USART_INT_TXDE, DISABLE); + } + } +} + +/** + * @brief This function handles USARTz global interrupt request. + */ +void USARTz_IRQHandler(void) +{ + if (USART_GetIntStatus(USARTz, USART_INT_RXDNE) != RESET) + { + /* Read one byte from the receive data register */ + RxBuffer2[RxCounter2++] = USART_ReceiveData(USARTz); + + if (RxCounter2 == NbrOfDataToRead1) + { + /* Disable the USARTz Receive interrupt */ + USART_ConfigInt(USARTz, USART_INT_RXDNE, DISABLE); + } + } + + if (USART_GetIntStatus(USARTz, USART_INT_TXDE) != RESET) + { + /* Write one byte to the transmit data register */ + USART_SendData(USARTz, TxBuffer2[TxCounter2++]); + + if (TxCounter2 == NbrOfDataToTransfer2) + { + /* Disable the USARTz Transmit interrupt */ + USART_ConfigInt(USARTz, USART_INT_TXDE, DISABLE); + } + } +} + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/MDK-ARM/MultiProcessor.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/MDK-ARM/MultiProcessor.uvoptx new file mode 100644 index 0000000..4804888 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/MDK-ARM/MultiProcessor.uvoptx @@ -0,0 +1,359 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\bsp_key.c + bsp_key.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\bsp_led.c + bsp_led.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 11 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/MDK-ARM/MultiProcessor.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/MDK-ARM/MultiProcessor.uvprojx new file mode 100644 index 0000000..dc38313 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/MDK-ARM/MultiProcessor.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + MultiProcessor + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\MultiProcessor.bin .\Objects\MultiProcessor.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + bsp_key.c + 1 + ..\src\bsp_key.c + + + bsp_led.c + 1 + ..\src\bsp_led.c + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/bsp_key.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/bsp_key.h new file mode 100644 index 0000000..a757938 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/bsp_key.h @@ -0,0 +1,72 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file bsp_key.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __BSP_KEY_H__ +#define __BSP_KEY_H__ + +#include "n32wb03x.h" + +// Define of IO +#define KEY1_INT_GPIO_PORT GPIOB +#define KEY1_INT_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define KEY1_INT_GPIO_PIN GPIO_PIN_1 +#define KEY1_INT_EXTI_PORTSOURCE GPIOB_PORT_SOURCE +#define KEY1_INT_EXTI_PINSOURCE GPIO_PIN_SOURCE1 +#define KEY1_INT_EXTI_LINE EXTI_LINE1 +#define KEY1_INT_EXTI_IRQ EXTI0_1_IRQn + +void EXTI_Key_Config(void); + +#endif /* __BSP_KEY_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/bsp_led.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/bsp_led.h new file mode 100644 index 0000000..36f5ad5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/bsp_led.h @@ -0,0 +1,96 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file bsp_led.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __BSP_LED_H__ +#define __BSP_LED_H__ + +#include "n32wb03x.h" + +//************************************************************************************// +/* Define the LED that is connected GPIO*/ + +#define LED1_GPIO_PORT GPIOB +#define LED1_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define LED1_GPIO_PIN GPIO_PIN_0 + +#define LED2_GPIO_PORT GPIOA +#define LED2_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define LED2_GPIO_PIN GPIO_PIN_6 + + +#define digitalHi(p, i) \ + { \ + p->PBSC = i; \ + } // output high +#define digitalLo(p, i) \ + { \ + p->PBC = i; \ + } // output low +#define digitalToggle(p, i) \ + { \ + p->POD ^= i; \ + } // toggle + +#define LED1_TOGGLE digitalToggle(LED1_GPIO_PORT, LED1_GPIO_PIN) +#define LED1_OFF digitalLo(LED1_GPIO_PORT, LED1_GPIO_PIN) +#define LED1_ON digitalHi(LED1_GPIO_PORT, LED1_GPIO_PIN) + +#define LED2_TOGGLE digitalToggle(LED2_GPIO_PORT, LED2_GPIO_PIN) +#define LED2_OFF digitalLo(LED2_GPIO_PORT, LED2_GPIO_PIN) +#define LED2_ON digitalHi(LED2_GPIO_PORT, LED2_GPIO_PIN) + +void LED_GPIO_Config(void); + +#endif /* __BSP_LED_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/main.h new file mode 100644 index 0000000..0ac1f24 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/main.h @@ -0,0 +1,98 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _USART1_UART2_ + +#ifdef _USART1_UART2_ +#define USARTy USART1 +#define USARTy_CLK RCC_APB2_PERIPH_USART1 +#define USARTy_GPIO GPIOB +#define USARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTy_RxPin GPIO_PIN_7 +#define USARTy_TxPin GPIO_PIN_6 +#define USARTy_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_Tx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#endif + + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void Delay(__IO uint32_t nCount); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/n32wb03x_it.h new file mode 100644 index 0000000..4b6a912 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/inc/n32wb03x_it.h @@ -0,0 +1,87 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void EXTI2_3_IRQHandler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/readme.txt new file mode 100644 index 0000000..23a5ed3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/readme.txt @@ -0,0 +1,50 @@ + + +1. Function description + + This test example demonstrates how to use the USART multiprocessor mode. USARTy and USARTz can be USART1 and USART2. + First, set the addresses of USARTy and USARTz to 0x1 and 0x2 respectively. USARTy continuously sends the character 0x33 to +USARTz. USARTz receives 0x33 and flips the pins of LED1, LED2, and LED3. + Once the KEY1_INT_EXTI_LINE line detects the rising edge, the EXTI0 interrupt is generated. In the EXTI0_IRQHandler interrupt +processing function (the ControlFlag = 0), the USARTz enters the silent mode. In the silent mode, the LED pin stops toggling until +the KEY1_INT_EXTI_LINE line detects the rising edge ( the ControlFlag = 1). In the EXTI0_IRQHandler interrupt processing function, +USARTy sends address 0x102 to wake up USARTz. The LED pin restarts toggling. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USARTy configuration is as follows: + -Baud rate = 115200 baud + -Word length = 9 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + + + The USART pin connections are as follows: + - USART1_Tx.PB6 <-------> USART2_Rx.PB5 + - USART1_Rx.PB7 <-------> USART2_Tx.PB4 + + KEY1_INT_EXTI_LINE.PB1 <-------> BUTTON1 + + LED1 <-------> PB0 + LED2 <-------> PA6 + + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, observe whether LED1~2 are blinking + -Press the KEY button and observe if LED1~2 stop flashing + -Press the KEY button again and observe whether LED1~2 resume flashing + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/bsp_key.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/bsp_key.c new file mode 100644 index 0000000..4c5a567 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/bsp_key.c @@ -0,0 +1,101 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file bsp_key.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#include "bsp_key.h" + +/** + * @brief NVIC configuration. + */ +static void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + /* Enable the KEY1 Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = KEY1_INT_EXTI_IRQ; + NVIC_InitStructure.NVIC_IRQChannelPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/** + * @brief Configure the IO as EXTI_Line and set the Priority. + */ +void EXTI_Key_Config(void) +{ + GPIO_InitType GPIO_InitStructure; + EXTI_InitType EXTI_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(KEY1_INT_GPIO_CLK, ENABLE); + + /* Configure NVIC */ + NVIC_Configuration(); + + /*--------------------------KEY1_PA0 Configuration-----------------------------*/ + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure KEY1 as input floating */ + GPIO_InitStructure.Pin = KEY1_INT_GPIO_PIN; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitPeripheral(KEY1_INT_GPIO_PORT, &GPIO_InitStructure); + + GPIO_ConfigEXTILine(KEY1_INT_EXTI_PORTSOURCE, KEY1_INT_EXTI_PINSOURCE); + EXTI_InitStructure.EXTI_Line = KEY1_INT_EXTI_LINE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitPeripheral(&EXTI_InitStructure); +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/bsp_led.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/bsp_led.c new file mode 100644 index 0000000..6355942 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/bsp_led.c @@ -0,0 +1,84 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file bsp_led.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#include "bsp_led.h" + +/** + * @brief Initailise the IO of LED + */ +void LED_GPIO_Config(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(LED1_GPIO_CLK | LED2_GPIO_CLK, ENABLE); + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure LED1_GPIO_PIN as Out_PP */ + GPIO_InitStructure.Pin = LED1_GPIO_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(LED1_GPIO_PORT, &GPIO_InitStructure); + + /* Configure LED2_GPIO_PIN as Out_PP */ + GPIO_InitStructure.Pin = LED2_GPIO_PIN; + GPIO_InitPeripheral(LED2_GPIO_PORT, &GPIO_InitStructure); + + /* close the all LED */ + GPIO_SetBits(LED1_GPIO_PORT, LED1_GPIO_PIN); + GPIO_SetBits(LED2_GPIO_PORT, LED2_GPIO_PIN); +} diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/main.c new file mode 100644 index 0000000..f42ad31 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/main.c @@ -0,0 +1,220 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" +#include "bsp_led.h" +#include "bsp_key.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_MultiProcessor + * @{ + */ + +USART_InitType USART_InitStructure; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* Initialize Leds, Wakeup and Key Buttons mounted on board */ + LED_GPIO_Config(); + EXTI_Key_Config(); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_9B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTy and USARTz */ + USART_Init(USARTy, &USART_InitStructure); + USART_Init(USARTz, &USART_InitStructure); + + /* Enable the USARTy and USARTz */ + USART_Enable(USARTy, ENABLE); + USART_Enable(USARTz, ENABLE); + + /* Set the USARTy and USARTz Address */ + USART_SetAddr(USARTy, 0x1); + USART_SetAddr(USARTz, 0x2); + + /* Select the USARTz WakeUp Method */ + USART_ConfigWakeUpMode(USARTz, USART_WUM_ADDRMASK); + + while (1) + { + /* Send one byte from USARTy to USARTz */ + USART_SendData(USARTy, 0x33); + + /* Wait while USARTy TXE = 0 */ + while (USART_GetFlagStatus(USARTy, USART_FLAG_TXDE) == RESET) + { + } + + if (USART_GetFlagStatus(USARTz, USART_FLAG_RXDNE) != RESET) + { + if (USART_ReceiveData(USARTz) == 0x33) + { + LED1_ON; + Delay(0xFFFFF); + LED1_OFF; + Delay(0xFFFFF); + + LED2_ON; + Delay(0xFFFFF); + LED2_OFF; + Delay(0xFFFFF); + } + } + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(USARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE); + /* Enable USARTy and USARTz Clock */ + USARTy_APBxClkCmd(USARTy_CLK, ENABLE); + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_TxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); + + /* Configure USARTy Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = USARTy_RxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = USARTy_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Rx as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = USARTz_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Inserts a delay time. + * @param nCount specifies the delay time length. + */ +void Delay(__IO uint32_t nCount) +{ + /* Decrement nCount value */ + for (; nCount != 0; nCount--) + ; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/n32wb03x_it.c new file mode 100644 index 0000000..d94e931 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/MultiProcessor/src/n32wb03x_it.c @@ -0,0 +1,163 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "main.h" +#include "bsp_key.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +__IO uint32_t ControlFlag = 0; + +extern void Delay(__IO uint32_t nCount); + +/******************************************************************************/ +/* Cortex-M4 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles External interrupt Line 0 request. + */ +void EXTI0_1_IRQHandler(void) +{ + Delay(0xFFFFF); + if (ControlFlag == 2) + { + ControlFlag = 0; + } + + if (ControlFlag == 0) + { + /* Flush DAT register and clear the USARTz RXNE flag */ + USART_ReceiveData(USARTz); + /* Enable the USARTz mute mode*/ + USART_EnableRcvWakeUp(USARTz, ENABLE); + + ControlFlag = 1; + } + else if (ControlFlag == 1) + { + /* Send the address mark (0x102) to wakeup USARTz */ + USART_SendData(USARTy, 0x102); + /* Wait while USARTy TXE = 0 */ + while (USART_GetFlagStatus(USARTy, USART_FLAG_TXDE) == RESET) + { + } + + ControlFlag = 2; + } + + /* Clear Key Button EXTI Line Pending Bit */ + EXTI_ClrITPendBit(KEY1_INT_EXTI_LINE); +} + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/MDK-ARM/Polling.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/MDK-ARM/Polling.uvoptx new file mode 100644 index 0000000..294d883 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/MDK-ARM/Polling.uvoptx @@ -0,0 +1,323 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 9 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/MDK-ARM/Polling.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/MDK-ARM/Polling.uvprojx new file mode 100644 index 0000000..79f8f30 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/MDK-ARM/Polling.uvprojx @@ -0,0 +1,460 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Polling + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Polling.bin .\Objects\Polling.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/inc/main.h new file mode 100644 index 0000000..5689aea --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/inc/main.h @@ -0,0 +1,105 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _USART1_UART2_ + +#ifdef _USART1_UART2_ +#define USARTy USART1 +#define USARTy_CLK RCC_APB2_PERIPH_USART1 +#define USARTy_GPIO GPIOB +#define USARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTy_RxPin GPIO_PIN_7 +#define USARTy_TxPin GPIO_PIN_6 +#define USARTy_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_Tx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define USARTz USART2 +#define USARTz_CLK RCC_APB1_PERIPH_USART2 +#define USARTz_GPIO GPIOB +#define USARTz_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTz_RxPin GPIO_PIN_5 +#define USARTz_TxPin GPIO_PIN_4 +#define USARTz_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_Tx_GPIO_AF GPIO_AF3_USART2 +#define USARTz_APBxClkCmd RCC_EnableAPB1PeriphClk +#endif + + + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/readme.txt new file mode 100644 index 0000000..c9d3c25 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/readme.txt @@ -0,0 +1,43 @@ + +1. Function description + + This test case demonstrates the basic communication between USARTy and USARTz by querying the detection identification. + First, USARTy sends TxBuffer1 data to USARTz, and USARTz receives data and stores it in RxBuffer1. +Compare the received data with the sent data, and the comparison result is stored in the TransferStatus variable. + Subsequently, USARTz sends TxBuffer2 data to USARTy, and USARTy receives data to RxBuffer2. +Compare the received data with the sent data, and the result of the comparison is stored in the TransferStatus variable. + USARTy and USARTz can be USART1 and USART2. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + + The USART pin connections are as follows: + - USART1_Tx.PB6 <-------> USART2_Rx.PB5 + - USART1_Rx.PB7 <-------> USART2_Tx.PB4 + + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus in turn, + PASSED means the test passed, FAILED means the test is abnormal + + +4. Matters needing attention + + the MCU_TX and MCU_RX jumper cap of the development board NS-LINK needs to be disconnected first \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/src/main.c new file mode 100644 index 0000000..54a2d66 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/src/main.c @@ -0,0 +1,257 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_Polling + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1) - 1) +#define TxBufferSize2 (countof(TxBuffer2) - 1) + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +USART_InitType USART_InitStructure; +uint8_t TxBuffer1[] = "Buffer Send from USARTy to USARTz using Flags"; +uint8_t RxBuffer1[TxBufferSize1]; +uint8_t TxBuffer2[] = "Buffer Send from USARTz to USARTy using Flags"; +uint8_t RxBuffer2[TxBufferSize2]; +__IO uint8_t TxCounter = 0, RxCounter = 0; +volatile TestStatus TransferStatus = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTy and USARTz */ + USART_Init(USARTy, &USART_InitStructure); + USART_Init(USARTz, &USART_InitStructure); + + /* Enable the USARTy and USARTz */ + USART_Enable(USARTy, ENABLE); + USART_Enable(USARTz, ENABLE); + + while (TxCounter < TxBufferSize1) + { + /* Send one byte from USARTy to USARTz */ + USART_SendData(USARTy, TxBuffer1[TxCounter++]); + /* Loop until USARTy DAT register is empty */ + while (USART_GetFlagStatus(USARTy, USART_FLAG_TXDE) == RESET) + { + } + + /* Loop until the USARTz Receive Data Register is not empty */ + while (USART_GetFlagStatus(USARTz, USART_FLAG_RXDNE) == RESET) + { + } + /* Store the received byte in RxBuffer */ + RxBuffer1[RxCounter++] = USART_ReceiveData(USARTz); + } + + /* Check the received data with the send ones */ + /* TransferStatus = PASSED, if the data transmitted from USARTy and + received by USARTz are the same */ + /* TransferStatus = FAILED, if the data transmitted from USARTy and + received by USARTz are different */ + TransferStatus = Buffercmp(TxBuffer1, RxBuffer1, TxBufferSize1); + + TxCounter = 0; + RxCounter = 0; + TransferStatus = FAILED; + while (TxCounter < TxBufferSize1) + { + /* Send one byte from USARTz to USARTy */ + USART_SendData(USARTz, TxBuffer2[TxCounter++]); + /* Loop until USARTz DAT register is empty */ + while (USART_GetFlagStatus(USARTz, USART_FLAG_TXDE) == RESET) + { + } + + /* Loop until the USARTy Receive Data Register is not empty */ + while (USART_GetFlagStatus(USARTy, USART_FLAG_RXDNE) == RESET) + { + } + /* Store the received byte in RxBuffer */ + RxBuffer2[RxCounter++] = USART_ReceiveData(USARTy); + } + + /* Check the received data with the send ones */ + /* TransferStatus = PASSED, if the data transmitted from USARTz and + received by USARTy are the same */ + /* TransferStatus = FAILED, if the data transmitted from USARTz and + received by USARTy are different */ + TransferStatus = Buffercmp(TxBuffer2, RxBuffer2, TxBufferSize2); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(USARTy_GPIO_CLK | USARTz_GPIO_CLK, ENABLE); + /* Enable USARTy and USARTz Clock */ + USARTy_APBxClkCmd(USARTy_CLK, ENABLE); + USARTz_APBxClkCmd(USARTz_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTy Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_TxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTy_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure USARTz Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTz_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTz_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTz_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/src/n32wb03x_it.c new file mode 100644 index 0000000..17d66e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Polling/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/MDK-ARM/Printf.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/MDK-ARM/Printf.uvoptx new file mode 100644 index 0000000..294d883 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/MDK-ARM/Printf.uvoptx @@ -0,0 +1,323 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 9 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/MDK-ARM/Printf.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/MDK-ARM/Printf.uvprojx new file mode 100644 index 0000000..54f8312 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/MDK-ARM/Printf.uvprojx @@ -0,0 +1,460 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Printf + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Printf.bin .\Objects\Printf.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/inc/main.h new file mode 100644 index 0000000..d9049a6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/inc/main.h @@ -0,0 +1,101 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _USART1_COM_ +//#define _USART2_COM_ + +#ifdef _USART1_COM_ +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk +#endif + +void RCC_Configuration(void); +void GPIO_Configuration(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/readme.txt new file mode 100644 index 0000000..98e9de0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/readme.txt @@ -0,0 +1,39 @@ + +1. Function description + + This test case demonstrates the basic communication between USARTy and USARTz by querying the detection identification. + First, USARTy sends TxBuffer1 data to USARTz, and USARTz receives data and stores it in RxBuffer1. +Compare the received data with the sent data, and the comparison result is stored in the TransferStatus1 variable. + Subsequently, USARTz sends TxBuffer2 data to USARTy, and USARTy receives data to RxBuffer2. +Compare the received data with the sent data, and the result of the comparison is stored in the TransferStatus2 variable. + USARTy can be USART1 and USART2. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + + The USART pin connections are as follows: + - USART1_Tx.PB6 + + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the log + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/src/main.c new file mode 100644 index 0000000..1c7ad73 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/src/main.c @@ -0,0 +1,174 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_Printf + * @{ + */ + +USART_InitType USART_InitStructure; + +/** + * @brief Main program + */ +int main(void) +{ + RCC_ClocksType RCC_ClocksStatus; + + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + RCC_GetClocksFreqValue(&RCC_ClocksStatus); + + /* USARTy and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + + /* Output a message on Hyperterminal using printf function */ + printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r"); + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/* retarget the C library printf function to the USART */ +int fputc(int ch, FILE* f) +{ + USART_SendData(USARTx, (uint8_t)ch); + while (USART_GetFlagStatus(USARTx, USART_FLAG_TXDE) == RESET); + + return (ch); +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/src/n32wb03x_it.c new file mode 100644 index 0000000..17d66e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Printf/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/MDK-ARM/SmartCard.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/MDK-ARM/SmartCard.uvoptx new file mode 100644 index 0000000..9847475 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/MDK-ARM/SmartCard.uvoptx @@ -0,0 +1,355 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 5 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 5 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + 5 + 10 + 1 + 0 + 0 + 0 + ..\src\smartcard.c + smartcard.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 11 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/MDK-ARM/SmartCard.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/MDK-ARM/SmartCard.uvprojx new file mode 100644 index 0000000..59c4418 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/MDK-ARM/SmartCard.uvprojx @@ -0,0 +1,475 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + SmartCard + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\SmartCard.bin .\Objects\SmartCard.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + smartcard.c + 1 + ..\src\smartcard.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/inc/main.h new file mode 100644 index 0000000..830a2e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/inc/main.h @@ -0,0 +1,72 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void RCC_Configuration(void); +void GPIO_Configuration(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/inc/smartcard.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/inc/smartcard.h new file mode 100644 index 0000000..9393028 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/inc/smartcard.h @@ -0,0 +1,184 @@ +/** + ****************************************************************************** + * @file Smartcard/inc/smartcard.h + * @author MCD Application Team + * @version V3.1.0 + * @date 07/27/2009 + * @brief This file contains all the functions prototypes for the Smartcard + * firmware library. + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __SMARTCARD_H +#define __SMARTCARD_H + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" + + +/* Exported constants --------------------------------------------------------*/ +#define T0_PROTOCOL 0x00 /* T0 protocol */ +#define DIRECT 0x3B /* Direct bit convention */ +#define INDIRECT 0x3F /* Indirect bit convention */ +#define SETUP_LENGTH 20 +#define HIST_LENGTH 20 +#define LC_MAX 256//20 +#define SC_RECEIVE_TIMEOUT 0x4000 /* Direction to reader */ + +/* SC Tree Structure ----------------------------------------------------------- + MasterFile + ________|___________ + | | | + System UserData Note +------------------------------------------------------------------------------*/ + +//------------------------------------------------------------------------// +#define SC1_USART USART2 +#define SC1_USART_GPIO GPIOB +#define SC1_USART_CLK RCC_APB1_PERIPH_USART2 +#define SC1_USART_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define SC1_USART_PIN_TX GPIO_PIN_4 +#define SC1_USART_PIN_CK GPIO_PIN_13 +#define SC1_USART_PIN_AF GPIO_AF3_USART2 +#define SC1_USART_IRQn USART2_IRQn +#define SC1_USART_IRQHandler USART2_IRQHandler +//------------------------------------------------------------------------// + +#define SC1_PIN_RESET GPIO_PIN_0 +#define SC1_PIN_RESET_GPIO GPIOA +#define SC1_PIN_RESET_GPIO_CLK RCC_APB2_PERIPH_GPIOA +//------------------------------------------------------------------------// + +//#define SC_DETECT_EXTI EXTI_LINE7 +//#define SC_DETECT_PIN GPIOC_PORT_SOURCE//GPIO_PortSourceGPIOC +//#define SC_DETECT_GPIO GPIO_PIN_SOURCE7 +//#define SC_DETECT_IRQ EXTI9_5_IRQn +//#define SC_DETECT_IRQHandler EXTI9_5_IRQHandler //xzy9_4->4_15 + + + +/* SC ADPU Command: Operation Code -------------------------------------------*/ +#define SC_CLA_GSM11 0xA0 + +/*------------------------ Data Area Management Commands ---------------------*/ +#define SC_SELECT_FILE 0xA4 +#define SC_GET_RESPONCE 0xC0 +#define SC_STATUS 0xF2 +#define SC_UPDATE_BINARY 0xD6 +#define SC_READ_BINARY 0xB0 +#define SC_WRITE_BINARY 0xD0 +#define SC_UPDATE_RECORD 0xDC +#define SC_READ_RECORD 0xB2 + +/*-------------------------- Administrative Commands -------------------------*/ +#define SC_CREATE_FILE 0xE0 + +/*-------------------------- Safety Management Commands ----------------------*/ +#define SC_VERIFY 0x20 +#define SC_CHANGE 0x24 +#define SC_DISABLE 0x26 +#define SC_ENABLE 0x28 +#define SC_UNBLOCK 0x2C +#define SC_EXTERNAL_AUTH 0x82 +#define SC_GET_CHALLENGE 0x84 + +/*-------------------------- Answer to reset Commands ------------------------*/ +#define SC_GET_A2R 0x00 + +/* SC STATUS: Status Code ----------------------------------------------------*/ +#define SC_EF_SELECTED 0x9F +#define SC_DF_SELECTED 0x9F +#define SC_OP_TERMINATED 0x9000 + +/* Smartcard Voltage */ +#define SC_VOLTAGE_5V 0 +#define SC_VOLTAGE_3V 1 + +/* Exported types ------------------------------------------------------------*/ +typedef enum +{ + SC_POWER_ON = 0x00, + SC_RESET_LOW = 0x01, + SC_RESET_HIGH = 0x02, + SC_ACTIVE = 0x03, + SC_ACTIVE_ON_T0 = 0x04, + SC_POWER_OFF = 0x05 +} SC_State; +///* BitAction types ------------------------------------------------------------*/ +//typedef enum +//{ +// Bit_RESET = 0, +// Bit_SET +//}BitAction; + + +/* ATR structure - Answer To Reset -------------------------------------------*/ +typedef struct +{ + uint8_t TS; /* Bit Convention */ + uint8_t T0; /* High nibble = Number of setup byte; low nibble = Number of historical byte */ + uint8_t T[SETUP_LENGTH]; /* Setup array */ + uint8_t H[HIST_LENGTH]; /* Historical array */ + uint8_t Tlength; /* Setup array dimension */ + uint8_t Hlength; /* Historical array dimension */ +} SC_ATR; + +/* ADPU-Header command structure ---------------------------------------------*/ +typedef struct +{ + uint8_t CLA; /* Command class */ + uint8_t INS; /* Operation code */ + uint8_t P1; /* Selection Mode */ + uint8_t P2; /* Selection Option */ +} SC_Header; + +/* ADPU-Body command structure -----------------------------------------------*/ +typedef struct +{ + uint8_t LC; /* Data field length */ + uint8_t Data[LC_MAX]; /* Command parameters */ + uint8_t LE; /* Expected length of data to be returned */ +} SC_Body; + +/* ADPU Command structure ----------------------------------------------------*/ +typedef struct +{ + SC_Header Header; + SC_Body Body; +} SC_ADPU_Commands; + +/* SC response structure -----------------------------------------------------*/ +typedef struct +{ + uint8_t Data[LC_MAX]; /* Data returned from the card */ + uint8_t SW1; /* Command Processing status */ + uint8_t SW2; /* Command Processing qualification */ +} SC_ADPU_Responce; + +/* SC Initial structure -----------------------------------------------------*/ +typedef struct +{ + uint8_t Clk_Div; /* USART Clk Div Value */ + uint8_t GT; /* Guard Time*/ + uint8_t StopBits; + uint8_t Parity; + uint8_t NackEn; +} SC_InitStructure; + + + + +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ +/* APPLICATION LAYER ---------------------------------------------------------*/ +void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Responce *SC_Response, SC_InitStructure *SC_InitCfg); +void SC_PowerCmd(FunctionalState NewState); +void SC1_Reset(Bit_OperateType ResetState); +void SC_DetectPinConfig(void); +void SC_ParityErrorHandler(void); +void SC_PTSConfig(void); + +void SC1_DeInit(void); +#endif /* __SMARTCARD_H */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/readme.txt new file mode 100644 index 0000000..9cee716 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/readme.txt @@ -0,0 +1,30 @@ + +1. Function description + + This example demonstrates the basic communication between USART and SmartCard. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USART pin connections are as follows: + - USART2_Tx.PB4 <-------> SCDSIO + - USART2_CK.PB13 <-------> SCDCLK + - GPIO_PA0 <-------> SCDRST + + Log print: + DEMO board PB6(TX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the log if the USART2 read SmartCard success. + + +4. Matters needing attention \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/src/main.c new file mode 100644 index 0000000..3e444fd --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/src/main.c @@ -0,0 +1,237 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/* Includes ------------------------------------------------------------------*/ +#include +#include "main.h" +#include "log.h" +#include "smartcard.h" + +/* Private typedef -----------------------------------------------------------*/ +typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; +/* Private define ------------------------------------------------------------*/ + + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint32_t gTestResult; +uint8_t looptime = 0; +uint8_t F_HotReset = 0; + +uint8_t AppletAID[8] = {0xA0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00}; + +/* Data: Send to card */ +uint8_t TxData[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; +/* Data: Receive from card */ +uint8_t RxData[16] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 0xaa, 0x55, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44}; + +char gJsonObject[512]; +/* Private function prototypes -----------------------------------------------*/ +void Test_PSAM(void); +/* Private functions ---------------------------------------------------------*/ + + + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup SmartCard + * @{ + */ + + + +/** + * @brief Main program + */ +int main(void) +{ + + log_init(); + /* Output a message on Hyperterminal using printf function */ + printf("\n\rSmartCard 7816 demo\n\r"); + + while (1) + { + Test_PSAM(); + printf("PSAM_1 test finish\r\n"); + + SC1_DeInit(); + Delay_ms(1000); + +// Uart_Init(115200); + printf("System Init Finish!\r\n"); + } +} + +/** + * @brief smart card test + * @param + * @return + * @note Note + */ +void Test_PSAM(void) +{ + uint16_t i; + uint8_t timeout =0; + SC_InitStructure SC_InitCfg; + SC_State SCState = SC_POWER_OFF; + SC_ADPU_Commands SC_ADPU; + SC_ADPU_Responce SC_Responce; + + printf("USARTx Smart_Card_1 Test Start\r\n"); + + SC_InitCfg.Clk_Div = 10; + SC_InitCfg.GT = 16; + SC_InitCfg.StopBits = 3; + SC_InitCfg.Parity = 1; + SC_InitCfg.NackEn = 0; + looptime = 10; + + + SCState = SC_POWER_ON; + + SC_ADPU.Header.CLA = 0x00; + SC_ADPU.Header.INS = SC_GET_A2R; + SC_ADPU.Header.P1 = 0x00; + SC_ADPU.Header.P2 = 0x00; + SC_ADPU.Body.LC = 0x00; + + while(SCState != SC_ACTIVE_ON_T0) + { + SC_Handler(&SCState, &SC_ADPU, &SC_Responce, &SC_InitCfg); + + timeout++; + Delay_ms(10); + if(timeout>10) + { + break; + } + } + + /* Apply the Procedure Type Selection (PTS) */ + SC_PTSConfig(); + // + Delay_ms(10); + // Select Applet + SC_ADPU.Header.CLA = 0x00; + SC_ADPU.Header.INS = 0x84; + SC_ADPU.Header.P1 = 0x00; + SC_ADPU.Header.P2 = 0x00; + SC_ADPU.Body.LC = 0x00; + SC_ADPU.Body.LE = 0x08; + + for(i = 0; i < SC_ADPU.Body.LC; i++) + { + SC_ADPU.Body.Data[i] = AppletAID[i]; + } + while(i < LC_MAX) + { + SC_ADPU.Body.Data[i++] = 0; + } + + SC_Handler(&SCState, &SC_ADPU, &SC_Responce, &SC_InitCfg); + Delay_ms(10); + if((SC_Responce.SW1 == 0x90)&&(SC_Responce.SW2 == 0x00)) + { + printf("SmartCard Read Random success! \r\n"); + for(i = 0;i<8;i++) + { + printf("Random_Table[%d] = %x \r\n",i,SC_Responce.Data[i]); + } + + } + + F_HotReset = 1; + printf("USARTx Smart_Card Hot_Reset\r\n"); + + SC1_Reset(Bit_RESET); + Delay_ms(10); + SC1_Reset(Bit_SET); + + SC_InitCfg.Clk_Div = 10; + SC_InitCfg.GT = 16; + SC_InitCfg.StopBits = 3; + SC_InitCfg.Parity = 1; + SC_InitCfg.NackEn = 0; + looptime = 10; + + SCState = SC_POWER_ON; + + SC_ADPU.Header.CLA = 0x00; + SC_ADPU.Header.INS = SC_GET_A2R; + SC_ADPU.Header.P1 = 0x00; + SC_ADPU.Header.P2 = 0x00; + SC_ADPU.Body.LC = 0x00; + + while(SCState != SC_ACTIVE_ON_T0) + { + SC_Handler(&SCState, &SC_ADPU, &SC_Responce, &SC_InitCfg); + } + printf("USARTx Smart_Card Hot_Reset Finish\r\n"); + F_HotReset = 0; +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/src/n32wb03x_it.c new file mode 100644 index 0000000..17d66e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/src/smartcard.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/src/smartcard.c new file mode 100644 index 0000000..3daefee --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/SmartCard/src/smartcard.c @@ -0,0 +1,778 @@ +/** + ****************************************************************************** + * @file Smartcard/src/smartcard.c + * @author MCD Application Team + * @version V3.1.0 + * @date 07/27/2009 + * @brief This file provides all the Smartcard firmware functions. + ****************************************************************************** + * @copy + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + *

© COPYRIGHT 2009 STMicroelectronics

+ */ + +/** @addtogroup Smartcard + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +//#include "testusart.h" + +#if 1 + +#include "smartcard.h" +#include "stdio.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Global variables definition and initialization ----------------------------*/ +SC_ATR SC_A2R; +uint8_t SC_ATR_Table[40]; +static __IO uint8_t SCData = 0; +static uint32_t F_Table[16] = {0, 372, 558, 744, 1116, 1488, 1860, 0, + 0, 512, 768, 1024, 1536, 2048, 0, 0}; +static uint32_t D_Table[16] = {0, 1, 2, 4, 8, 16, 32, 64, + 12, 20, 0, 0, 0, 0, 0, 0}; + +extern uint8_t F_HotReset; + + + +/* Private function prototypes -----------------------------------------------*/ +/* Transport Layer -----------------------------------------------------------*/ +/*--------------APDU-----------*/ +static void SC_SendData(SC_ADPU_Commands *SC_ADPU, SC_ADPU_Responce *SC_ResponceStatus); + +/*------------ ATR ------------*/ +static void SC_AnswerReq(SC_State *SCState, uint8_t *card, uint8_t length); /* Ask ATR */ +static uint8_t SC_decode_Answer2reset(uint8_t *card); /* Decode ATR */ + +/* Physical Port Layer -------------------------------------------------------*/ +static void SC1_Init(SC_InitStructure *SC_InitCfg); +void SC1_DeInit(void); + +static ErrorStatus USART_ByteReceive(uint8_t *Data, uint32_t TimeOut); + +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Handles all Smartcard states and serves to send and receive all + * communication data between Smartcard and reader. + * @param SCState: pointer to an SC_State enumeration that will contain the Smartcard state. + * @param SC_ADPU: pointer to an SC_ADPU_Commands structure that will be initialized. + * @param SC_Response: pointer to a SC_ADPU_Responce structure which will be initialized. + * @retval None + */ +void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Responce *SC_Response, SC_InitStructure *SC_InitCfg) +{ + uint32_t i = 0; + + switch(*SCState) + { + case SC_POWER_ON: + if (SC_ADPU->Header.INS == SC_GET_A2R) + { + if(F_HotReset==0) + { + /* Smartcard intialization ------------------------------------------*/ + SC1_Init(SC_InitCfg); + } + /* Reset Data from SC buffer -----------------------------------------*/ + for (i = 0; i < 40; i++) + { + SC_ATR_Table[i] = 0; + } + /* Reset SC_A2R Structure --------------------------------------------*/ + SC_A2R.TS = 0; + SC_A2R.T0 = 0; + for (i = 0; i < SETUP_LENGTH; i++) + { + SC_A2R.T[i] = 0; + } + for (i = 0; i < HIST_LENGTH; i++) + { + SC_A2R.H[i] = 0; + } + SC_A2R.Tlength = 0; + SC_A2R.Hlength = 0; + + /* Next State --------------------------------------------------------*/ + *SCState = SC_RESET_LOW; + } + break; + case SC_RESET_LOW: + if(SC_ADPU->Header.INS == SC_GET_A2R) + { + /* If card is detected then Power ON, Card Reset and wait for an answer) */ + if (1) + { + while(((*SCState) != SC_POWER_OFF) && ((*SCState) != SC_ACTIVE)) + { + SC_AnswerReq(SCState, &SC_ATR_Table[0], 40); /* Check for answer to reset */ + + printf("SC_ATR_Table:"); + for(i=0;i<12;i++) + {printf("0x%x\r\n",SC_ATR_Table[i]);} + } + } + else + { + (*SCState) = SC_POWER_OFF; + } + } + break; + case SC_ACTIVE: + if (SC_ADPU->Header.INS == SC_GET_A2R) + { + if(SC_decode_Answer2reset(&SC_ATR_Table[0]) == T0_PROTOCOL) + { + (*SCState) = SC_ACTIVE_ON_T0; + } + else + { + (*SCState) = SC_POWER_OFF; + } + } + break; + case SC_ACTIVE_ON_T0: + SC_SendData(SC_ADPU, SC_Response); + break; + + case SC_POWER_OFF: + SC1_DeInit(); /* Disable Smartcard interface */ + break; + + default: (*SCState) = SC_POWER_OFF; + } +} +/** + * @brief Initializes all peripheral used for Smartcard interface. + * @param None + * @retval None + */ +static void SC1_Init(SC_InitStructure *SC_InitCfg) +{ + GPIO_InitType GPIO_InitStructure; + USART_InitType USART_InitStructure; + USART_ClockInitType USART_ClockInitStructure; + RCC_ClocksType RCC_ClocksStatus; + + USART_Module* SC_USART; + SC_USART = SC1_USART; + + /* Enable GPIO clocks */ + RCC_EnableAPB2PeriphClk( SC1_PIN_RESET_GPIO_CLK |SC1_USART_GPIO_CLK |RCC_APB2_PERIPH_AFIO, ENABLE); + + /* Enable USART clock */ + RCC_EnableAPB1PeriphClk(SC1_USART_CLK, ENABLE); + + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USART CK pin as alternate function push-pull */ + GPIO_InitStructure.Pin = SC1_USART_PIN_CK; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = SC1_USART_PIN_AF; + GPIO_InitPeripheral(SC1_USART_GPIO, &GPIO_InitStructure); + + /* Configure USART Tx pin as alternate function open-drain */ + GPIO_InitStructure.Pin = SC1_USART_PIN_TX; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_OD; + GPIO_InitStructure.GPIO_Alternate = SC1_USART_PIN_AF; + GPIO_InitPeripheral(SC1_USART_GPIO, &GPIO_InitStructure); + + /* Configure Smartcard Reset pin */ + GPIO_InitStructure.Pin = SC1_PIN_RESET; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(SC1_PIN_RESET_GPIO, &GPIO_InitStructure); + /* SC_USART configuration ----------------------------------------------------*/ + /* SC_USART configured as follow: + - Word Length = 9 Bits + - 0.5 Stop Bit + - Even parity + - BaudRate = 9677 baud + - Hardware flow control disabled (RTS and CTS signals) + - Tx and Rx enabled + - USART Clock enabled + */ + USART_SetPrescaler(SC_USART, 0x0F); //10·ÖƵ + /* USART Guard Time set to 16 Bit */ + USART_SetGuardTime(SC_USART, SC_InitCfg->GT); + + USART_ClockInitStructure.Clock = USART_CLK_ENABLE; + USART_ClockInitStructure.Polarity = USART_CLKPOL_LOW; + USART_ClockInitStructure.Phase = USART_CLKPHA_1EDGE; + USART_ClockInitStructure.LastBit = USART_CLKLB_ENABLE; + USART_ClockInit(SC_USART, &USART_ClockInitStructure); + + RCC_GetClocksFreqValue(&RCC_ClocksStatus); + + USART_InitStructure.BaudRate = RCC_ClocksStatus.Pclk1Freq/(372*((SC_USART->GTP & (uint16_t)0x00FF) * 2)); //ÕâÀïÉèÖÃĬÈϲ¨ÌØÂÊ0x11 + USART_InitStructure.WordLength = USART_WL_9B; + + if(SC_InitCfg->StopBits == 1) + USART_InitStructure.StopBits = USART_STPB_0_5; + else if(SC_InitCfg->StopBits == 3) + USART_InitStructure.StopBits = USART_STPB_1_5; + else printf("\r\n StopBits value is error !!! \r\n"); + + if(SC_InitCfg->Parity == 1) + USART_InitStructure.Parity = USART_PE_EVEN; + else if(SC_InitCfg->Parity == 2) + USART_InitStructure.Parity = USART_PE_ODD; + else printf("\r\n Parity value is error !!! \r\n"); + + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_Init(SC_USART, &USART_InitStructure); + + /* Enable the SC_USART Parity Error Interrupt */ + USART_ConfigInt(SC_USART, USART_INT_PEF, ENABLE); + /* Enable the SC_USART Framing Error Interrupt */ + USART_ConfigInt(SC_USART, USART_INT_ERRF, ENABLE); + /* Enable SC_USART */ + USART_Enable(SC_USART, ENABLE); + + /* Enable the NACK Transmission */ + if(SC_InitCfg->NackEn == 0) + USART_SetSmartCardNACK(SC_USART, DISABLE); + else if(SC_InitCfg->NackEn == 1) USART_SetSmartCardNACK(SC_USART, ENABLE); + else printf("\r\n NACK Enable value is error !!! \r\n"); + + /* Enable the Smartcard Interface */ + USART_EnableSmartCard(SC_USART, ENABLE); + + /* Set RSTIN HIGH */ + SC1_Reset(Bit_SET); +} +/** + * @brief Deinitializes all ressources used by the Smartcard interface. + * @param None + * @retval None + */ +void SC1_DeInit(void) +{ + /* Deinitializes the SC_USART */ + USART_DeInit(SC1_USART); + + GPIO_DeInit(SC1_PIN_RESET_GPIO); + + /* Disable GPIO clocks */ + RCC_EnableAPB2PeriphClk(SC1_PIN_RESET_GPIO_CLK | + SC1_USART_GPIO_CLK | + RCC_APB2_PERIPH_AFIO, DISABLE); + + /* Disable SC_USART clock */ + RCC_EnableAPB1PeriphClk(SC1_USART_CLK, DISABLE); +} +/** + * @brief Sets or clears the Smartcard reset pin. + * @param ResetState: this parameter specifies the state of the Smartcard + * reset pin. BitVal must be one of the BitAction enum values: + * @arg Bit_RESET: to clear the port pin. + * @arg Bit_SET: to set the port pin. + * @retval None + */ +void SC1_Reset(Bit_OperateType ResetState) +{ + GPIO_WriteBit(SC1_PIN_RESET_GPIO, SC1_PIN_RESET, ResetState); +} +/** + * @brief Resends the byte that failed to be received (by the Smartcard) correctly. + * @param None + * @retval None + */ +void SC_ParityErrorHandler(void) +{ + USART_Module* SC_USART; + + SC_USART = SC1_USART; + + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } +} + +/** + * @brief Configures the IO speed (BaudRate) communication. + * @param None + * @retval None + */ +void SC_PTSConfig(void) +{ + RCC_ClocksType RCC_ClocksStatus; + uint32_t workingbaudrate = 0, apbclock = 0; + uint8_t locData = 0, PTSConfirmStatus = 1; + USART_InitType USART_InitStructure; + USART_ClockInitType USART_ClockInitStructure; + + USART_Module* SC_USART; + + SC_USART = SC1_USART; + + /* Reconfigure the USART Baud Rate -------------------------------------------*/ + //RCC_GetClocksFreq(&RCC_ClocksStatus); + RCC_GetClocksFreqValue(&RCC_ClocksStatus); + // + apbclock = RCC_ClocksStatus.Pclk1Freq; + + apbclock /= ((SC_USART->GTP & (uint16_t)0x00FF) * 2); //PCLK1·ÖƵºóµÄʱÖÓ£¨Ìṩ¸ø¿¨µÄʱÖÓ£© + //apbclock = 40000000/10; + + /* Enable the DMA Receive (Set DMAR bit only) to enable interrupt generation + in case of a framing error FE */ + //USART_DMACmd(SC_USART, USART_DMAReq_Rx, ENABLE); + USART_EnableDMA(SC_USART, USART_DMAREQ_RX, ENABLE); + + if((SC_A2R.T0 & (uint8_t)0x10) == 0x10) + { + if(SC_A2R.T[0] != 0x11) + { + /* Send PTSS */ + SCData = 0xFF; + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + + /* Send PTS0 */ + SCData = 0x10; + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + + /* Send PTS1 */ + SCData = SC_A2R.T[0]; + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + + /* Send PCK */ + SCData = (uint8_t)0xFF^(uint8_t)0x10^(uint8_t)SC_A2R.T[0]; + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + + /* Disable the DMA Receive (Reset DMAR bit only) */ + //USART_DMACmd(SC_USART, USART_DMAReq_Rx, DISABLE); + USART_EnableDMA(SC_USART, USART_DMAREQ_RX, DISABLE); + + if((USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT)) == SUCCESS) + { + if(locData != 0xFF) + { + PTSConfirmStatus = 0x00; + } + } + if((USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT)) == SUCCESS) + { + if(locData != 0x10) + { + PTSConfirmStatus = 0x00; + } + } + if((USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT)) == SUCCESS) + { + if(locData != SC_A2R.T[0]) + { + PTSConfirmStatus = 0x00; + } + } + if((USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT)) == SUCCESS) + { + if(locData != ((uint8_t)0xFF^(uint8_t)0x10^(uint8_t)SC_A2R.T[0])) + { + PTSConfirmStatus = 0x00; + } + } + else + { + PTSConfirmStatus = 0x00; + } + + /* PTS Confirm - ½Ó¿ÚÉ豸ͨ¹ýЭÉÌʹÓÃÓ뿨ÏàͬµÄ²¨ÌØÂʽøÐÐͨÐÅ*/ + if(PTSConfirmStatus == 0x01) + { + workingbaudrate = apbclock * D_Table[(SC_A2R.T[0] & (uint8_t)0x0F)]; + workingbaudrate /= F_Table[((SC_A2R.T[0] >> 4) & (uint8_t)0x0F)]; + + USART_ClockInitStructure.Clock = USART_CLK_ENABLE; + USART_ClockInitStructure.Polarity = USART_CLKPOL_LOW; + USART_ClockInitStructure.Phase = USART_CLKPHA_1EDGE; + USART_ClockInitStructure.LastBit = USART_CLKLB_ENABLE; + USART_ClockInit(SC_USART, &USART_ClockInitStructure); + + USART_InitStructure.BaudRate = workingbaudrate; + USART_InitStructure.WordLength = USART_WL_9B; + USART_InitStructure.StopBits = USART_STPB_1_5; + USART_InitStructure.Parity = USART_PE_EVEN; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_Init(SC_USART, &USART_InitStructure); + } + } + } +} + +/** + * @brief Manages the Smartcard transport layer: send APDU commands and receives + * the APDU responce. + * @param SC_ADPU: pointer to a SC_ADPU_Commands structure which will be initialized. + * @param SC_Response: pointer to a SC_ADPU_Responce structure which will be initialized. + * @retval None + */ +static void SC_SendData(SC_ADPU_Commands *SC_ADPU, SC_ADPU_Responce *SC_ResponceStatus) +{ + uint32_t i = 0; + uint32_t number = 0; + uint8_t locData = 0; + + USART_Module* SC_USART; + + SC_USART = SC1_USART; + + /* Reset responce buffer ---------------------------------------------------*/ + for(i = 0; i < LC_MAX; i++) + { + SC_ResponceStatus->Data[i] = 0; + } + printf("\r\nSC_ADPU:0x%x",SC_ADPU->Header.CLA); + printf(" 0x%x",SC_ADPU->Header.INS); + printf(" 0x%x",SC_ADPU->Header.P1); + printf(" 0x%x",SC_ADPU->Header.P2); + printf(" 0x%x\r\n",SC_ADPU->Body.LC); + + SC_ResponceStatus->SW1 = 0; + SC_ResponceStatus->SW2 = 0; + + /* Enable the DMA Receive (Set DMAR bit only) to enable interrupt generation + in case of a framing error FE */ + // USART_DMACmd(SC_USART, USART_DMAReq_Rx, ENABLE); + + /* Send header -------------------------------------------------------------*/ + SCData = SC_ADPU->Header.CLA; + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + + SCData = SC_ADPU->Header.INS; + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + + SCData = SC_ADPU->Header.P1; + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + + SCData = SC_ADPU->Header.P2; + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + + /* Send body length to/from SC ---------------------------------------------*/ + if(SC_ADPU->Body.LC) + { + SCData = SC_ADPU->Body.LC; + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + } + else if(SC_ADPU->Body.LE) + { + SCData = SC_ADPU->Body.LE; + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + } + /* Flush the SC_USART DR */ + (void)USART_ReceiveData(SC_USART); + + /* -------------------------------------------------------- + Wait Procedure byte from card: + 1 - ACK + 2 - NULL + 3 - SW1; SW2 + -------------------------------------------------------- */ + + if((USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT)) == SUCCESS) + { + if(((locData & (uint8_t)0xF0) == 0x60) || ((locData & (uint8_t)0xF0) == 0x90)) + { + SC_ResponceStatus->Data[number] = locData; + number++; + + for(;number<(SC_ADPU->Body.LC);number++) + { + if((USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT)) == SUCCESS) + { + if(((locData & (uint8_t)0xF0) == 0x60) || ((locData & (uint8_t)0xF0) == 0x90)) + SC_ResponceStatus->Data[number] = locData; + + //printf("%x , %d\r\n",locData,number); + } + } + /* SW1 received */ + if((USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT)) == SUCCESS) + { + if(((locData & (uint8_t)0xF0) == 0x60) || ((locData & (uint8_t)0xF0) == 0x90)) + SC_ResponceStatus->SW1 = locData; + } + + if((USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT)) == SUCCESS) + { + /* SW2 received */ + if(((locData & (uint8_t)0xF0) == 0x60) || ((locData & (uint8_t)0xF0) == 0x90)) + SC_ResponceStatus->SW2 = locData; + } + } + else if (((locData & (uint8_t)0xFE) == (((uint8_t)~(SC_ADPU->Header.INS)) & \ + (uint8_t)0xFE))||((locData & (uint8_t)0xFE) == (SC_ADPU->Header.INS & (uint8_t)0xFE))) + { + SC_ResponceStatus->Data[0] = locData;/* ACK received */ + } + } + + /* If no status bytes received ---------------------------------------------*/ + if(SC_ResponceStatus->SW1 == 0x00) + { + /* Send body data to SC--------------------------------------------------*/ + if (SC_ADPU->Body.LC) + { + for(i = 0; i < SC_ADPU->Body.LC; i++) + { + SCData = SC_ADPU->Body.Data[i]; + + USART_SendData(SC_USART, SCData); + while(USART_GetFlagStatus(SC_USART, USART_FLAG_TXC) == RESET) + { + } + } + /* Flush the SC_USART DR */ + (void)USART_ReceiveData(SC_USART); + /* Disable the DMA Receive (Reset DMAR bit only) */ + //USART_DMACmd(SC_USART, USART_DMAReq_Rx, DISABLE); + USART_EnableDMA(SC_USART, USART_DMAREQ_RX, DISABLE); + } + /* Or receive body data from SC ------------------------------------------*/ + else if (SC_ADPU->Body.LE) + { + for(i = 0; i < SC_ADPU->Body.LE; i++) + { + if(USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT) == SUCCESS) + { + SC_ResponceStatus->Data[i] = locData; + } + } + } + /* Wait SW1 --------------------------------------------------------------*/ + i = 0; + while(i < 10) + { + if(USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT) == SUCCESS) + { + SC_ResponceStatus->SW1 = locData; + i = 11; + } + else + { + i++; + } + } + /* Wait SW2 ------------------------------------------------------------*/ + i = 0; + while(i < 10) + { + if(USART_ByteReceive(&locData, SC_RECEIVE_TIMEOUT) == SUCCESS) + { + SC_ResponceStatus->SW2 = locData; + i = 11; + } + else + { + i++; + } + } + } +} + +/** + * @brief Requests the reset answer from card. + * @param SCState: pointer to an SC_State enumeration that will contain the Smartcard state. + * @param card: pointer to a buffer which will contain the card ATR. + * @param length: maximum ATR length + * @retval None + */ +static void SC_AnswerReq(SC_State *SCState, uint8_t *card, uint8_t length) +{ + uint8_t Data = 0; + uint32_t i = 0; + + switch(*SCState) + { + case SC_RESET_LOW: + /* Check responce with reset low ---------------------------------------*/ + for (i = 0; i < length; i++) + { + if((USART_ByteReceive(&Data, SC_RECEIVE_TIMEOUT)) == SUCCESS) + { + card[i] = Data; + } + } + if(card[0]) + { + (*SCState) = SC_ACTIVE; + // + SC1_Reset(Bit_SET);/* Reset High */ + } + else + { + (*SCState) = SC_RESET_HIGH; + } + break; + + case SC_RESET_HIGH: + /* Check responce with reset high --------------------------------------*/ + SC1_Reset(Bit_SET); /* Reset High */ + while(length--) + { + if((USART_ByteReceive(&Data, SC_RECEIVE_TIMEOUT)) == SUCCESS) + { + *card++ = Data; /* Receive data for timeout = SC_RECEIVE_TIMEOUT */ + } + } + if(card[0]) + { + (*SCState) = SC_ACTIVE; + } + else + { + (*SCState) = SC_POWER_OFF; + } + break; + + case SC_ACTIVE: + break; + + case SC_POWER_OFF: + /* Close Connection if no answer received ------------------------------*/\ + SC1_Reset(Bit_SET); /* Reset high - a bit is used as level shifter from 3.3 to 5 V */ + + break; + + default: + (*SCState) = SC_RESET_LOW; + } +} + +/** + * @brief Decodes the Answer to reset received from card. + * @param card: pointer to the buffer containing the card ATR. + * @retval None + */ +static uint8_t SC_decode_Answer2reset(uint8_t *card) +{ + uint32_t i = 0, flag = 0, buf = 0, protocol = 0; + + SC_A2R.TS = card[0]; /* Initial character */ + SC_A2R.T0 = card[1]; /* Format character */ + + SC_A2R.Hlength = SC_A2R.T0 & (uint8_t)0x0F; + + if ((SC_A2R.T0 & (uint8_t)0x80) == 0x80) + { + flag = 1; + } + + for (i = 0; i < 4; i++) + { + SC_A2R.Tlength = SC_A2R.Tlength + (((SC_A2R.T0 & (uint8_t)0xF0) >> (4 + i)) & (uint8_t)0x1); + } + + for (i = 0; i < SC_A2R.Tlength; i++) + { + SC_A2R.T[i] = card[i + 2]; + } + + protocol = SC_A2R.T[SC_A2R.Tlength - 1] & (uint8_t)0x0F; + + while (flag) + { + if ((SC_A2R.T[SC_A2R.Tlength - 1] & (uint8_t)0x80) == 0x80) + { + flag = 1; + } + else + { + flag = 0; + } + + buf = SC_A2R.Tlength; + SC_A2R.Tlength = 0; + + for (i = 0; i < 4; i++) + { + SC_A2R.Tlength = SC_A2R.Tlength + (((SC_A2R.T[buf - 1] & (uint8_t)0xF0) >> (4 + i)) & (uint8_t)0x1); + } + + for (i = 0;i < SC_A2R.Tlength; i++) + { + SC_A2R.T[buf + i] = card[i + 2 + buf]; + } + SC_A2R.Tlength += (uint8_t)buf; + } + + for (i = 0; i < SC_A2R.Hlength; i++) + { + SC_A2R.H[i] = card[i + 2 + SC_A2R.Tlength]; + } + + return (uint8_t)protocol; +} +/** + * @brief Receives a new data while the time out not elapsed. + * @param None + * @retval An ErrorStatus enumuration value: + * - SUCCESS: New data has been received + * - ERROR: time out was elapsed and no further data is received + */ +static ErrorStatus USART_ByteReceive(uint8_t *Data, uint32_t TimeOut) +{ + uint32_t Counter = 0; + USART_Module* SC_USART; + + SC_USART = SC1_USART; + + while((USART_GetFlagStatus(SC_USART, USART_FLAG_RXDNE) == RESET) && (Counter != TimeOut)) + { + Counter++; + } + + if(Counter != TimeOut) + { + *Data = (uint8_t)USART_ReceiveData(SC_USART); + return SUCCESS; + } + else + { + return ERROR; + } +} +#endif diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/MDK-ARM/Syschronous.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/MDK-ARM/Syschronous.uvoptx new file mode 100644 index 0000000..56927c7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/MDK-ARM/Syschronous.uvoptx @@ -0,0 +1,335 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + n32wb03x_spi.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 4 + 8 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 5 + 10 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/MDK-ARM/Syschronous.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/MDK-ARM/Syschronous.uvprojx new file mode 100644 index 0000000..b8af2d8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/MDK-ARM/Syschronous.uvprojx @@ -0,0 +1,465 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + Syschronous + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\Syschronous.bin .\Objects\Syschronous.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_spi.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_spi.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/inc/main.h new file mode 100644 index 0000000..8744260 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/inc/main.h @@ -0,0 +1,138 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +#define _USART1_SPI1_ +//#define _USART2_SPI2_ + +#ifdef _USART1_SPI1_ +#define USARTy USART1 +#define USARTy_CLK RCC_APB2_PERIPH_USART1 +#define USARTy_GPIO GPIOB +#define USARTy_Clk_GPIO GPIOA +#define USARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTy_RxPin GPIO_PIN_7 +#define USARTy_TxPin GPIO_PIN_6 +#define USARTy_ClkPin GPIO_PIN_6 +#define USARTy_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_Tx_GPIO_AF GPIO_AF4_USART1 +#define USARTy_Clk_GPIO_AF GPIO_AF3_USART1 +#define USARTy_APBxClkCmd RCC_EnableAPB2PeriphClk + +#define SPIy SPI1 +#define SPIy_CLK RCC_APB2_PERIPH_SPI1 +#define SPIy_GPIO GPIOA +#define SPIy_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define SPIy_SCKPin GPIO_PIN_1 +#define SPIy_MISOPin GPIO_PIN_3 +#define SPIy_MOSIPin GPIO_PIN_2 +#define SPIy_SCK_GPIO_AF GPIO_AF1_SPI1 +#define SPIy_MISO_GPIO_AF GPIO_AF1_SPI1 +#define SPIy_MOSI_GPIO_AF GPIO_AF1_SPI1 +#define SPIy_APBxClkCmd RCC_EnableAPB2PeriphClk +#endif + +#ifdef _USART2_SPI2_ +#define USARTy USART2 +#define USARTy_CLK RCC_APB1_PERIPH_USART2 +#define USARTy_GPIO GPIOB +#define USARTy_Clk_GPIO GPIOB +#define USARTy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTy_RxPin GPIO_PIN_5 +#define USARTy_TxPin GPIO_PIN_4 +#define USARTy_ClkPin GPIO_PIN_13 +#define USARTy_Rx_GPIO_AF GPIO_AF3_USART1 +#define USARTy_Tx_GPIO_AF GPIO_AF3_USART1 +#define USARTy_Clk_GPIO_AF GPIO_AF3_USART1 +#define USARTy_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define SPIy SPI2 +#define SPIy_CLK RCC_APB2_PERIPH_SPI2 +#define SPIy_GPIO GPIOB +#define SPIy_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define SPIy_SCKPin GPIO_PIN_1 +#define SPIy_MISOPin GPIO_PIN_3 +#define SPIy_MOSIPin GPIO_PIN_2 +#define SPIy_SCK_GPIO_AF GPIO_AF2_SPI2 +#define SPIy_MISO_GPIO_AF GPIO_AF2_SPI2 +#define SPIy_MOSI_GPIO_AF GPIO_AF2_SPI2 +#define SPIy_APBxClkCmd RCC_EnableAPB2PeriphClk +#endif + + +typedef enum +{ + FAILED = 0, + PASSED = !FAILED +} TestStatus; + +void RCC_Configuration(void); +void GPIO_Configuration(void); +void SPI_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/readme.txt new file mode 100644 index 0000000..b33cef2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/readme.txt @@ -0,0 +1,59 @@ + +1. Function description + + This test example demonstrates the basic communication between USARTy (synchronous mode) and SPIy by querying the detection identifier. +USARTy and SPIy can be USART1 and SPI1, USART3 and SPI1 or USART2 and SPI2. + First, through the TXC detection flag, USARTy sends TxBuffer1 data to SPIy, while SPIy receives data, it queries the RNE detection flag, and the +received data is stored in RxBuffer1. + Subsequently, SPIy sends TxBuffer2 data to USARTy by querying the TE detection flag. USARTy uses the RXDNE detection flag to receive data +and stores it in RxBuffer2. + Finally, compare the two groups of receiving and sending data respectively, and store the comparison results in the TransferStatus1 variable +and the TransferStatus2 variable. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions for use + + The system clock configuration is as follows: + -Clock source = HSI 64M + -System clock = 64MHz + + The USART configuration is as follows: + -Baud rate = 115200 baud + -Word length = 8 data bits + -1 stop bit + -Verification control disabled + -Hardware flow control disabled (RTS and CTS signals) + -Receiver and transmitter enable + -Clock enable + -Clock polarity: keep high when not sending out + -Clock phase: sample the first data on the second clock edge + -The last clock pulse: the clock pulse of the last data is output from CK + + The SPI configuration is as follows: + -Direction = "Two-wire two-way" mode + -Mode = slave mode + -Data size = 8-bit data frame + -CPOL = In idle state, the clock stays high + -CPHA = data sampling starts from the second clock edge + -NSS = Enable software management from the device + -1st bit = 1st bit is LSB + + + The USART pin connections are as follows: + - USART1_Tx.PB6 <-------> SPI1_MOSI.PA2 + - USART1_Rx.PB7 <-------> SPI1_MISO.PA3 + - USART1_Clk.PA6 <-------> SPI1_SCK.PA1 + + Test steps and phenomena: + -After the Demo is compiled in the KEIL environment, download it to the MCU + -Reset operation, check the variables TransferStatus1 and TransferStatus2 in turn, + PASSED means the test passed, FAILED means the test is abnormal + + +4. Matters needing attention + + the MCU_TX and MCU_RX jumper cap of the development board NS-LINK needs to be disconnected first \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/src/main.c new file mode 100644 index 0000000..0f50e9b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/src/main.c @@ -0,0 +1,324 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include +#include "main.h" + +/** @addtogroup N32WB03X_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_Syschronous + * @{ + */ + +#define TxBufferSize1 (countof(TxBuffer1) - 1) +#define TxBufferSize2 (countof(TxBuffer2) - 1) +#define DYMMY_BYTE 0x00 + +#define countof(a) (sizeof(a) / sizeof(*(a))) + +USART_InitType USART_InitStructure; +USART_ClockInitType USART_ClockInitStructure; + +uint8_t TxBuffer1[] = "USART Synchronous Example: USARTy -> SPIy using TXE and RXNE Flags"; +uint8_t TxBuffer2[] = "USART Synchronous Example: SPIy -> USARTy using TXE and RXNE Flags"; +uint8_t RxBuffer1[TxBufferSize2]; +uint8_t RxBuffer2[TxBufferSize1]; +__IO uint8_t NbrOfDataToRead1 = TxBufferSize2; +__IO uint8_t NbrOfDataToRead2 = TxBufferSize1; +__IO uint8_t TxCounter1 = 0, RxCounter1 = 0; +__IO uint8_t TxCounter2 = 0, RxCounter2 = 0; +volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; + +/** + * @brief Main program + */ +int main(void) +{ + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* Configure the SPI */ + SPI_Configuration(); + + /* USARTy configuration ------------------------------------------------------*/ + /* USARTy configured as follow: + - BaudRate = 115200 baud + - Word Length = 8 Bits + - One Stop Bit + - No parity + - Hardware flow control disabled (RTS and CTS signals) + - Receive and transmit enabled + - USART Clock Enabled + - USART CPOL: Clock is active High + - USART CPHA: Data is captured on the second edge + - USART LastBit: The clock pulse of the last data bit is output to + the SCLK pin + */ + USART_ClockInitStructure.Clock = USART_CLK_ENABLE; + USART_ClockInitStructure.Polarity = USART_CLKPOL_HIGH; + USART_ClockInitStructure.Phase = USART_CLKPHA_2EDGE; + USART_ClockInitStructure.LastBit = USART_CLKLB_ENABLE; + USART_ClockInit(USARTy, &USART_ClockInitStructure); + + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + USART_Init(USARTy, &USART_InitStructure); + + /* Configure the USARTy */ + USART_Init(USARTy, &USART_InitStructure); + + /* Enable the USARTy */ + USART_Enable(USARTy, ENABLE); + + while (NbrOfDataToRead2--) + { + /* Write one byte in the USARTy Transmit Data Register */ + USART_SendData(USARTy, TxBuffer1[TxCounter1++]); + /* Wait until end of transmit */ + while (USART_GetFlagStatus(USARTy, USART_FLAG_TXC) == RESET) + { + } + /* Wait the byte is entirely received by SPIy */ + while (SPI_I2S_GetStatus(SPIy, SPI_I2S_RNE_FLAG) == RESET) + { + } + /* Store the received byte in the RxBuffer2 */ + RxBuffer2[RxCounter2++] = SPI_I2S_ReceiveData(SPIy); + } + + /* Clear the USARTy Data Register */ + USART_ReceiveData(USARTy); + + while (NbrOfDataToRead1--) + { + /* Wait until end of transmit */ + while (SPI_I2S_GetStatus(SPIy, SPI_I2S_TE_FLAG) == RESET) + { + } + /* Write one byte in the SPIy Transmit Data Register */ + SPI_I2S_TransmitData(SPIy, TxBuffer2[TxCounter2++]); + + /* Send a Dummy byte to generate clock to slave */ + USART_SendData(USARTy, DYMMY_BYTE); + /* Wait until end of transmit */ + while (USART_GetFlagStatus(USARTy, USART_FLAG_TXC) == RESET) + { + } + /* Wait the byte is entirely received by USARTy */ + while (USART_GetFlagStatus(USARTy, USART_FLAG_RXDNE) == RESET) + { + } + /* Store the received byte in the RxBuffer1 */ + RxBuffer1[RxCounter1++] = USART_ReceiveData(USARTy); + } + + /* Check the received data with the send ones */ + TransferStatus1 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); + /* TransferStatus = PASSED, if the data transmitted from USARTy and + received by SPIy are the same */ + /* TransferStatus = FAILED, if the data transmitted from USARTy and + received by SPIy are different */ + TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); + /* TransferStatus = PASSED, if the data transmitted from SPIy and + received by USARTy are the same */ + /* TransferStatus = FAILED, if the data transmitted from SPIy and + received by USARTy are different */ + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration(void) +{ + /* Enable GPIO clock */ + RCC_EnableAPB2PeriphClk(USARTy_GPIO_CLK | SPIy_GPIO_CLK, ENABLE); + /* Enable USARTy and USARTz Clock */ + USARTy_APBxClkCmd(USARTy_CLK, ENABLE); + /* Enable SPIy Clock */ + SPIy_APBxClkCmd(SPIy_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTy TX and USARTy CK pins as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTy_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTy_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = USARTy_ClkPin; + GPIO_InitStructure.GPIO_Alternate = USARTy_Clk_GPIO_AF; + GPIO_InitPeripheral(USARTy_Clk_GPIO, &GPIO_InitStructure); + + /* Configure SPI1 pins: SCK, MISO and MOSI */ + GPIO_InitStructure.Pin = SPIy_SCKPin; + GPIO_InitStructure.GPIO_Alternate = SPIy_SCK_GPIO_AF; + GPIO_InitPeripheral(SPIy_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = SPIy_MISOPin; + GPIO_InitStructure.GPIO_Alternate = SPIy_MISO_GPIO_AF; + GPIO_InitPeripheral(SPIy_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.Pin = SPIy_MOSIPin; + GPIO_InitStructure.GPIO_Alternate = SPIy_MOSI_GPIO_AF; + GPIO_InitPeripheral(SPIy_GPIO, &GPIO_InitStructure); + + /* Configure USARTy RX as alternate function push-pull and pull-up */ + GPIO_InitStructure.Pin = USARTy_RxPin; + GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP; + GPIO_InitStructure.GPIO_Alternate = USARTy_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTy_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the SPI. + */ +void SPI_Configuration(void) +{ + SPI_InitType SPI_InitStructure; + + /* Initialize SPI_InitStructure */ + SPI_InitStruct(&SPI_InitStructure); + + SPI_I2S_DeInit(SPIy); + + /* SPIy Config */ + SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX; + SPI_InitStructure.SpiMode = SPI_MODE_SLAVE; + SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS; + SPI_InitStructure.CLKPOL = SPI_CLKPOL_HIGH; + SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE; + SPI_InitStructure.NSS = SPI_NSS_SOFT; + SPI_InitStructure.FirstBit = SPI_FB_LSB; + + /* Configure SPIy */ + SPI_Init(SPIy, &SPI_InitStructure); + + /* SPIy enable */ + SPI_Enable(SPIy, ENABLE); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength buffer's length + * @return PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while (BufferLength--) + { + if (*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/src/n32wb03x_it.c new file mode 100644 index 0000000..17d66e5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/USART/Synchronous/src/n32wb03x_it.c @@ -0,0 +1,123 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" + +/** @addtogroup N32WB03X_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t CurrDataCounterEnd; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* N32WB03X Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/MDK-ARM/WWDG_Reset.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/MDK-ARM/WWDG_Reset.uvoptx new file mode 100644 index 0000000..c39aa69 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/MDK-ARM/WWDG_Reset.uvoptx @@ -0,0 +1,367 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03X + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 2 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"" -O206 -S0 -C0 -P00 -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\src\n32wb03x_it.c + n32wb03x_it.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 4 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 4 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 4 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 4 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_wwdg.c + n32wb03x_wwdg.c + 0 + 0 + + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + n32wb03x_pwr.c + 0 + 0 + + + 4 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + + + BSP + 0 + 0 + 0 + 0 + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\bsp\src\log.c + log.c + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 6 + 12 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/MDK-ARM/WWDG_Reset.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/MDK-ARM/WWDG_Reset.uvprojx new file mode 100644 index 0000000..1402ccb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/MDK-ARM/WWDG_Reset.uvprojx @@ -0,0 +1,480 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03X + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.0.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + WWDG + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\WWDG.bin .\Objects\WWDG.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\inc;..\..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\bsp\inc + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + USER + + + main.c + 1 + ..\src\main.c + + + n32wb03x_it.c + 1 + ..\src\n32wb03x_it.c + + + + + FWLB + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + misc.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_wwdg.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_wwdg.c + + + n32wb03x_pwr.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_pwr.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + + + BSP + + + log.c + 1 + ..\..\..\..\bsp\src\log.c + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/inc/main.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/inc/main.h new file mode 100644 index 0000000..234f8a7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/inc/main.h @@ -0,0 +1,68 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include "n32wb03x.h" +#include "n32wb03x_conf.h" + +#define LED1_PORT GPIOB +#define LED1_PIN GPIO_PIN_0 + +#define LED2_PORT GPIOA +#define LED2_PIN GPIO_PIN_6 + +#endif /* __MAIN_H__ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/inc/n32wb03x_it.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/inc/n32wb03x_it.h new file mode 100644 index 0000000..573f01f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/inc/n32wb03x_it.h @@ -0,0 +1,86 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __N32WB03X_IT_H__ +#define __N32WB03X_IT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __N32WB03X_IT_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/readme.txt new file mode 100644 index 0000000..4a4341a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/readme.txt @@ -0,0 +1,29 @@ + +1. Function description + + WWDG reset function. + + +2. Use environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + + +3. Instructions for use + + System Configuration: + 1. IWDG clock source: PCLK1(64MHZ) + 2. Window value: 24.064 ms < n < 32.768 ms + 3. light Indicator: PB0(LED1) PA6(LED2) + + Test steps and phenomenon: + 1. Compile and download the code to reset and run, the indicator LED2 keeps flashing. + It means that the window value is refreshed normally and the code is running normally. + 2. When the parameter of the Delay() function is changed from 28 to less than 24 or greater than 33, + the entire system will always be in the reset state. LED1 is on. + + +4. Matters needing attention + 1. When the window value is very small, the system is in a frequent reset state, and at this time, it is easy to + cause the program to fail to download normally. In this routine, 1s delay is added before WWDG is + turned on to avoid this phenomenon. Of course, without delay, you can directly pull up the BOOT0 pin to download normally. diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/src/main.c new file mode 100644 index 0000000..8524a43 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/src/main.c @@ -0,0 +1,252 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "main.h" +#include "n32wb03x.h" +#include "log.h" + +/** @addtogroup n32wb03x_StdPeriph_Examples + * @{ + */ + +/** @addtogroup WWDG_Reset + * @{ + */ + +__IO uint32_t TimingDelay = 0; + +static void Delay(__IO uint32_t nTime); + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be GPIO_PIN_0~GPIO_PIN_15. + */ +void LedInit(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIO_InitType GPIO_InitStructure; + + /* Check the parameters */ + assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); + + /* Enable the GPIO Clock */ + if (GPIOx == GPIOA) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE); + } + else if (GPIOx == GPIOB) + { + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE); + } + + /* Configure the GPIO pin */ + if (Pin <= GPIO_PIN_ALL) + { + GPIO_InitStruct(&GPIO_InitStructure); + GPIO_InitStructure.Pin = Pin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure); + } +} + +/** + * @brief Turns selected Led on. + * @param Led Specifies the Led to be set on. + */ +void LedOn(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIOx->PBSC = Pin; +} +/** + * @brief Turns selected Led Off. + * @param Led Specifies the Led to be set off. + */ +void LedOff(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIOx->PBC = Pin; +} + +/** + * @brief Toggles the selected Led. + * @param Led Specifies the Led to be toggled. + */ +void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) +{ + GPIOx->POD ^= Pin; +} + +/** + * @brief Main program. + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_n32wb03x.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_n32wb03x.c file + */ + RCC_ClocksType RCC_Clocks; + + log_init(); + printf("\r\n This is WWDG Reset demo\r\n"); + + WWDG_ClrEWINTF(); + + LedInit(LED1_PORT, LED1_PIN); + LedInit(LED2_PORT, LED2_PIN); + + LedOff(LED1_PORT, LED1_PIN); + LedOff(LED2_PORT, LED2_PIN); + + SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); + /* Setup SysTick Timer for 1 msec interrupts */ + if (SysTick_Config(SystemCoreClock / 1000)) + { + /* Capture error */ + while (1) + ; + } + + /* Enable PWR Clock */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE); + DBG_ConfigPeriph(DBG_WWDG_STOP, ENABLE); + + /* Check if the system has resumed from WWDG reset */ + if (RCC_GetFlagStatus(RCC_CTRLSTS_FLAG_WWDGRSTF) != RESET) + { + /* WWDGRST flag set, Turn on LED2*/ + LedOn(LED1_PORT, LED1_PIN); + log_info("reset by WWDG\n"); + /* Clear reset flags */ + RCC_ClrFlag(); + } + else + { + /* WWDGRST flag is not set, Turn off LED2*/ + LedOff(LED1_PORT, LED1_PIN); + } + + /* WWDG configuration */ + /* Enable WWDG clock */ + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_WWDG, ENABLE); + + RCC_GetClocksFreqValue(&RCC_Clocks); + printf("Pclk1Freq:%d\r\n", RCC_Clocks.Pclk1Freq); + + /* WWDG clock counter = 4096/(PCLK1(32MHz)/4) = (~512 us) */ + WWDG_SetPrescalerDiv(WWDG_PRESCALER_DIV4); + + /* Set Window value to 80; WWDG counter should be refreshed only when the counter + is below 80 (and greater than 64) otherwise a reset will be generated */ + WWDG_SetWValue(80); + + /* + Enable WWDG and set counter value to 127, WWDG timeout = ~512 us * 64 = 32.768 ms + In this case the refresh window is: ~512 us * (127-80) = 24.064 ms < refresh window < ~512 us * (127-64-1) = 32.768ms + */ + WWDG_Enable(127); + + while (1) + { + /* Toggle LED2 */ + LedBlink(LED2_PORT, LED2_PIN); + Delay(28); + /* Update WWDG counter */ + + WWDG_SetCnt(127); + } +} + +/** + * @brief Inserts a delay time. + * @param nTime specifies the delay time length, in milliseconds. + */ +static void Delay(__IO uint32_t nTime) +{ + TimingDelay = nTime; + while (TimingDelay != 0) + { + } +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file pointer to the source file name + * @param line assert_param error line source number + */ +void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/src/n32wb03x_it.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/src/n32wb03x_it.c new file mode 100644 index 0000000..cf24c4d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/peripheral/WWDG/WWDG_Reset/src/n32wb03x_it.c @@ -0,0 +1,130 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file n32wb03x_it.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "n32wb03x_it.h" +#include "n32wb03x.h" + +/** @addtogroup n32wb03x_StdPeriph_Template + * @{ + */ + +extern __IO uint32_t TimingDelay; + +/******************************************************************************/ +/* Cortex-M0 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + + +/** + * @brief This function handles SVCall exception. + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles PendSV_Handler exception. + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + */ +void SysTick_Handler(void) +{ + TimingDelay--; +} + +/******************************************************************************/ +/* n32wb03x Peripherals Interrupt Handlers */ +/******************************************************************************/ + +/******************************************************************************/ +/* n32wb03x Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_n32wb03x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/MDK-ARM/DTM_Test.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/MDK-ARM/DTM_Test.uvoptx new file mode 100644 index 0000000..130e98a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/MDK-ARM/DTM_Test.uvoptx @@ -0,0 +1,656 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + ARMRTXEVENTFLAGS + -L70 -Z18 -C0 -M0 -T1 + + + 0 + DLGTARM + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0) + + + 0 + ARMDBGFLAGS + + + + 0 + DLGUARM + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + + 0 + 1 + USART_rx_dma_buf + + + + 0 + + + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + ns_log_usart.c + 0 + 0 + + + 6 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 7 + 26 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 7 + 27 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 28 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + 8 + 29 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 9 + 30 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 31 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/MDK-ARM/DTM_Test.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/MDK-ARM/DTM_Test.uvprojx new file mode 100644 index 0000000..77c6829 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/MDK-ARM/DTM_Test.uvprojx @@ -0,0 +1,718 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + DTM_Test + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\DTM_Test.bin .\Objects\DTM_Test.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\inc\app_profile;..\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + 2 + 0 + 0 + 0 + 0 + 1 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_log_usart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + app_usart.c + 1 + ..\src\app_usart.c + + + main.c + 1 + ..\src\main.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_ble.h new file mode 100644 index 0000000..b3b1257 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_ble.h @@ -0,0 +1,96 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + APP_TIMER0, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..5f4bcdc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_profile/rwapp_config.h @@ -0,0 +1,125 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_usart.h new file mode 100644 index 0000000..d6104cb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_usart.h @@ -0,0 +1,163 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ +//#define USART1_ON_PA45 + +#ifdef _USART1_COM_ + +#ifndef USART1_ON_PA45 +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk +#else +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOA +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk +#endif + +#define USARTx_DAT_Base (USART1_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART1_RX +#define USARTx_IRQn USART1_IRQn + +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define USARTx_DAT_Base (USART2_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#define USARTx_IRQn USART2_IRQn + +#endif + + +#define USART_RX_DMA_SIZE 256 +#define USART_RX_FIFO_SIZE 1000 +#define USART_TX_FIFO_SIZE 1000 + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + +/* Public function prototypes -----------------------------------------------*/ + +void app_usart_configuration(void); +void app_usart_dma_enable(FunctionalState Cmd); +const struct rwip_eif_api* rwip_eif_get_flash(uint8_t type); +bool flash_utils_hci_cmd_check(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_user_config.h new file mode 100644 index 0000000..b9eb04b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/inc/app_user_config.h @@ -0,0 +1,138 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ + +#define CUSTOM_DEVICE_NAME "NS_DIS" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 30 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + + +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_DEVICE_INFORMATION_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (5000) /**< Time of initiating event to update connection params (5 seconds). */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 0 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +/* profiles config */ +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +//#define CFG_APP_BATT 1 +//#define CFG_PRF_BASS 1 + + +/* User config */ +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 1 + +#define NS_TIMER_ENABLE 0 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/readme.txt new file mode 100644 index 0000000..ca1af49 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/readme.txt @@ -0,0 +1,24 @@ +1. Function description + + Bluetooth DTM mode with HCI commands supported. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. command port: DEMO board PB6(TX) PB7(RX), baud rate: 115200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + usage method: + 1. Burn to development board after compilation + 2. Connect the UART com port to Bluetooth protocol tester, such as CMW270. + 3. Start TX or RX test with Bluetooth protocol tester. + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/app_ble.c new file mode 100644 index 0000000..75dfee3 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/app_ble.c @@ -0,0 +1,329 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_user_config.h" +#include "global_func.h" +#include "ns_sec.h" +#include "app_ble.h" +#include "app_dis.h" +#include "app_usart.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + switch (msgid) + { + case APP_CUSTS_TEST_EVT: + { + + }break; +// case GAPM_LE_TEST_END_IND: +// { +// extern uint8_t usart_sending; +// extern uint8_t m_stop_rx_rsp; +// ///respond cmd to usart +// struct gapm_le_test_end_ind* p = (struct gapm_le_test_end_ind*)p_param; +// uint16_t m_event; +// m_event = 0x8000 | p->nb_packet_received; +// uart_cmd[0] = (m_event>>8)& 0xFF; +// uart_cmd[1] = (m_event)& 0xFF; +// while(usart_sending){} +// +// usart_tx_dma_send(uart_cmd,2); +// m_stop_rx_rsp = true; +// }break; + + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32768HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + + +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/app_usart.c new file mode 100644 index 0000000..6e96def --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/app_usart.c @@ -0,0 +1,568 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#include "global_func.h" +#include "app_usart.h" +#include "ns_log.h" +#include "ns_delay.h" +#include "app_ble.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +typedef enum +{ + STATE_UNINITIALIZED, + STATE_IDLE, + STATE_TRANSMITTER_TEST, + STATE_CARRIER_TEST, + STATE_RECEIVER_TEST +} state_t; +/* Private define ------------------------------------------------------------*/ + +//#define LE_PACKET_REPORTING_EVENT 0x8000 +#define RF_TEST_STATUS_EVENT_SUCCESS 0x0000 +#define RF_TEST_STATUS_EVENT_ERROR 0x0001 + +#define CMD_RSP_SUCCESS 0x00 +#define CMD_RSP_ERROR_ILLEGAL_CHANNEL 0x01 +#define CMD_RSP_ERROR_INVALID_STATE 0x02 +#define CMD_RSP_ERROR_ILLEGAL_LENGTH 0x03 +#define CMD_RSP_ERROR_ILLEGAL_CONFIGURATION 0x04 +#define CMD_RSP_ERROR_UNINITIALIZED 0x05 + +#define RF_TEST_SETUP 0 +#define RF_RECEIVER_TEST 1 +#define RF_TRANSMITTER_TEST 2 +#define RF_TEST_END 3 + +#define RF_TEST_SETUP_RESET 0 +#define RF_TEST_SETUP_SET_UPPER 1 +#define RF_TEST_SETUP_SET_PHY 2 +#define RF_TEST_SETUP_SELECT_MODULATION 3 +#define RF_TEST_SETUP_READ_SUPPORTED 4 +#define RF_TEST_SETUP_READ_MAX 5 + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] = {0}; +uint16_t rx_old_pos = 0; + +uint8_t usart_rx_fifo_buf[USART_RX_FIFO_SIZE] = {0}; +uint32_t usart_rx_fifo_in = 0; +uint32_t usart_rx_fifo_out = 0; + + +uint8_t usart_tx_fifo_buf[USART_TX_FIFO_SIZE] = {0}; +uint32_t usart_tx_fifo_in = 0; +uint32_t usart_tx_fifo_out = 0; + +uint8_t usart_sending = false; +uint8_t ble_sending = false; +uint16_t ble_att_mtu = (ATT_DEFAULT_MTU-3); + + +/* Private function prototypes -----------------------------------------------*/ +void app_usart_tx_process(void); +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTx_Tx_DMA_Channel); + DMA_RequestRemap(USARTx_Tx_DMA_REMAP, DMA, USARTx_Tx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Tx_DMA_Channel,DMA_INT_TXC ,ENABLE); + + /* USARTx RX DMA1 Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTx_Rx_DMA_Channel); + DMA_RequestRemap(USARTx_Rx_DMA_REMAP, DMA, USARTx_Rx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Rx_DMA_Channel,DMA_INT_TXC|DMA_INT_HTX ,ENABLE); + + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)USART_rx_dma_buf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = USART_RX_DMA_SIZE; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Rx_DMA_Channel, &DMA_InitStructure); + +} + + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + NVIC_DisableIRQ(DMA_Channel1_2_3_4_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + NVIC_DisableIRQ(USARTx_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void app_usart_configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* Configure the DMA */ + DMA_Configuration(); + + NVIC_Configuration(); + + /* USARTx and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 115200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + + /* Enable USARTx DMA Rx and TX request */ + USART_EnableDMA(USARTx, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief enable or disable the usart dma + */ +void app_usart_dma_enable(FunctionalState Cmd) +{ + if(Cmd == ENABLE) + { + rx_old_pos = 0; + usart_tx_fifo_in = usart_tx_fifo_out = 0; //clean fifo + usart_rx_fifo_in = usart_rx_fifo_out = 0; //clean fifo + app_usart_configuration(); +// m_state = STATE_IDLE; + } + else{ + + USART_Enable(USARTx, DISABLE); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, DISABLE); + DMA_EnableChannel(USARTx_Tx_DMA_Channel, DISABLE); + /* Deinit IO of USART to save power */ + GPIO_InitType GPIO_InitStructure; + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + } +} + + +/** + * @brief usart send data in blocking mode + */ +void usart_tx_data_blocking(uint8_t *p_data, uint16_t len) +{ + while(len--) + { + USART_SendData(USARTx, *p_data); + while(USART_GetFlagStatus(USARTx,USART_FLAG_TXC) == RESET); + p_data++; + } +} + + + +/** + * @brief dma irq handler + */ +void DMA_Channel1_2_3_4_IRQHandler(void) +{ + //TX + if(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)) + { + //TX Transfer complete interrupt + usart_sending = false; + + DMA_ClearFlag(DMA_FLAG_TC1, DMA); + } + //RX + if(DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + //RX Transfer complete interrupt + DMA_ClearFlag(DMA_FLAG_TC2, DMA); +// usart_rx_check_in_irq(); + + } + if(DMA_GetFlagStatus(DMA_FLAG_HT2, DMA)) + { + //RX Half transfer interrupt + DMA_ClearFlag(DMA_FLAG_HT2, DMA); +// usart_rx_check_in_irq(); + } + + +} + + + +uint8_t g_send_interval_recv_flag =0; +#include "string.h" +#include "h4tl.h" +#define BYTES_TO_UINT16(n, p) \ +{ \ + n = ((uint16_t)(p)[0] + ((uint16_t)(p)[1] << 8)); \ +} + +void flash_utils_flow_on(void) +{ + +} + +void flash_utils_flow_off(void) +{ + +} + +struct utils_txrxchannel +{ + /// call back function pointer + void (*callback)(void*, uint8_t); + /// Dummy data pointer returned to callback when operation is over. + void* dummy; +}; + +/// UART environment structure +struct utils_env_tag +{ + /// tx channel + struct utils_txrxchannel tx; + /// rx channel + struct utils_txrxchannel rx; + /// error detect + uint8_t errordetect; + /// external wakeup + bool ext_wakeup; +}; +struct utils_env_tag flash_utils_env; + +uint16_t flash_g_recv_len = 0; +extern uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] ; +void flash_utils_hci_cmd_reset(void) +{ + flash_g_recv_len = 0; + + memset(USART_rx_dma_buf, 0x00, 8); + extern void DMA_Configuration(void); + DMA_Configuration(); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); +} + + + +uint16_t flash_utils_get_tx_len(void) +{ + return USART_RX_DMA_SIZE - DMA_GetCurrDataCounter(USARTx_Rx_DMA_Channel); +} + +void flash_utils_read (uint8_t *bufptr, uint32_t size, rwip_eif_callback callback, void* dummy) +{ + NS_LOG_INFO("%s\r\n",__func__); + flash_utils_env.rx.callback = callback; + flash_utils_env.rx.dummy = dummy; + uint32_t i; + uint8_t rx_state = 0; + //uint16_t payload_len = 0; + //uint8_t* dummytrans = utils_env.rx.dummy; + struct h4tl_env_tag *dummy_env = (struct h4tl_env_tag *)dummy; + rx_state = dummy_env->rx_state ; // dummytrans[12]; //RX_STATE is the 12th byte in the h4tl_env_tag structure + if (rx_state == H4TL_STATE_RX_START) //The first byte to receive + { + __NOP(); + } + else if (rx_state == H4TL_STATE_RX_HDR) //Receive header + { + if (size) + { + //Wait until enough length header been received + i = 0; + while (flash_utils_get_tx_len() < size + 1) + { + delay_n_10us(10); + if (i++ > 10000) + { + break; + } + } + } + } + else if ((rx_state == H4TL_STATE_RX_PAYL)) //Receive payload + { + if (size) + { + //Wait until enough length payload been received + i = 0; + while (flash_utils_get_tx_len() < flash_g_recv_len + size) + { + delay_n_ms(1); + if (i++ > 5000) //5s timeout + { + break ; + } + + } + } + } + /*Clear buffer and reset state when out of sync*/ + else if (rx_state == H4TL_STATE_RX_OUT_OF_SYNC) + { + while (flash_utils_get_tx_len() > 0) + { + flash_utils_hci_cmd_reset(); + delay_n_10us(50); + } + //dummytrans[12] = H4TL_STATE_RX_START; + dummy_env->rx_state = H4TL_STATE_RX_START; + flash_utils_env.rx.callback(flash_utils_env.rx.dummy, 3); + return; + } + /*Buffer copy*/ + for (i = 0; i < size; i++) + { + if (i + flash_g_recv_len < utils_max_buf_len) + { + bufptr[i] = USART_rx_dma_buf[i + flash_g_recv_len]; + } + } + flash_g_recv_len += size; + + int recv_flag = 0; + /*Parse command header for the length of payload*/ + if (rx_state == H4TL_STATE_RX_HDR) + { + uint16_t payload_len=0; + uint8_t rx_type = USART_rx_dma_buf[0]; + if(rx_type == HCI_CMD_MSG_TYPE) + { + payload_len=USART_rx_dma_buf[3]; + } + else if(rx_type==HCI_ACL_MSG_TYPE) + { + BYTES_TO_UINT16(payload_len, &USART_rx_dma_buf[3]); + } + else if(rx_type==AHI_KE_MSG_TYPE) + { + BYTES_TO_UINT16(payload_len, &USART_rx_dma_buf[7]); + } + + if(payload_len == 0) + { + recv_flag = 1; + } + } + + //Accumulate the length + if ((rx_state == H4TL_STATE_RX_PAYL)) //Done + { + recv_flag = 1; + } + + // Call handler + flash_utils_env.rx.callback(flash_utils_env.rx.dummy, RWIP_EIF_STATUS_OK); + if(recv_flag) + { + flash_utils_hci_cmd_reset(); + } + +} + + +void flash_utils_write(uint8_t* bufptr, uint32_t size, void (*callback)(void*, uint8_t), void* dummy) +{ + //uint8_t *temp_bufptr; + flash_utils_env.tx.callback = callback; + flash_utils_env.tx.dummy = dummy; + + /* Check if there is more than 1 hci command in the buffer*/ + //if more data in buffer then to handle + rwip_prevent_sleep_set(RW_TL_RX_ONGOING); + + usart_tx_data_blocking(bufptr, size); + + //printf("g_send_interval_recv_flag\r\n"); + flash_utils_hci_cmd_reset(); + + /*tx done */ + flash_utils_env.tx.callback(flash_utils_env.tx.dummy, RWIP_EIF_STATUS_OK); +} + + + + +//Creation of uart external interface api +const struct rwip_eif_api flash_utils_api = +{ + flash_utils_read, + flash_utils_write, + flash_utils_flow_on, + flash_utils_flow_off, +}; + +bool flash_utils_hci_cmd_check(void) +{ + if ((flash_utils_get_tx_len() >= 4) && ((USART_rx_dma_buf[0] == HCI_CMD_MSG_TYPE) || (USART_rx_dma_buf[0] == HCI_ACL_MSG_TYPE) || (USART_rx_dma_buf[0] == AHI_KE_MSG_TYPE) )) + { + rwip_prevent_sleep_set(RW_TL_RX_ONGOING); + return true; + } + else + { + /*Wrong packet type*/ + if ((USART_rx_dma_buf[0] != 0) && (USART_rx_dma_buf[0] != HCI_CMD_MSG_TYPE) && (USART_rx_dma_buf[0] != HCI_ACL_MSG_TYPE) && (USART_rx_dma_buf[0] != AHI_KE_MSG_TYPE) ) + { + while (flash_utils_get_tx_len() > 0) + { + flash_utils_hci_cmd_reset(); + delay_n_10us(50); + } + } + rwip_prevent_sleep_clear(RW_TL_RX_ONGOING); + return false; + } +} + + +const struct rwip_eif_api* rwip_eif_get_flash(uint8_t type) +{ + + return &flash_utils_api; +} + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/main.c new file mode 100644 index 0000000..e479ffb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/DTM_Test/src/main.c @@ -0,0 +1,142 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "ns_log.h" +#include "ns_delay.h" +#include "app_usart.h" +#include "app_ble.h" + +#include "h4tl.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING DTM Test demo \r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + #ifdef USART1_ON_PA45 + //for hold the SWD before sleep + delay_n_10us(200*1000); + #endif + NS_LOG_INIT(); + + app_ble_init(); + + h4tl_init(0, rwip_eif_get_flash(0)); + + NS_LOG_INFO(DEMO_STRING); + app_usart_dma_enable(ENABLE ); + + //rf_tx_power_set(TX_POWER_Pos6_DBM); + while (1) + { + if (flash_utils_hci_cmd_check()) //UART + { + h4tl_read_start_next(); + } + /*schedule all pending events*/ + rwip_schedule(); + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/MDK-ARM/RF_Test.uvoptx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/MDK-ARM/RF_Test.uvoptx new file mode 100644 index 0000000..130e98a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/MDK-ARM/RF_Test.uvoptx @@ -0,0 +1,656 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc; *.md + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + N32WB03x + 0x4 + ARM-ADS + + 64000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 255 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + ARMRTXEVENTFLAGS + -L70 -Z18 -C0 -M0 -T1 + + + 0 + DLGTARM + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0) + + + 0 + ARMDBGFLAGS + + + + 0 + DLGUARM + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S0 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0N32WB03x.FLM -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03x -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03x.FLM)) + + + + + + 0 + 1 + USART_rx_dma_buf + + + + 0 + + + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + STARTUP + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + startup_n32wb03x.s + 0 + 0 + + + + + CMSIS + 0 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + system_n32wb03x.c + 0 + 0 + + + + + FWLB + 0 + 0 + 0 + 0 + + 3 + 3 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + misc.c + 0 + 0 + + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + n32wb03x_adc.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + n32wb03x_crc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + n32wb03x_dma.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + n32wb03x_exti.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + n32wb03x_gpio.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + n32wb03x_rcc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + n32wb03x_tim.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + n32wb03x_usart.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + n32wb03x_lpuart.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + n32wb03x_qflash.c + 0 + 0 + + + + + BLE_STACK + 0 + 0 + 0 + 0 + + 4 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + rwip.c + 0 + 0 + + + 4 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + rwip_driver.c + 0 + 0 + + + + + BLE_PROFILE + 0 + 0 + 0 + 0 + + 5 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + prf.c + 0 + 0 + + + 5 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + prf_utils.c + 0 + 0 + + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + diss.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + diss_task.c + 0 + 0 + + + + + NS_LIB + 0 + 0 + 0 + 0 + + 6 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + ns_log_lpuart.c + 0 + 0 + + + 6 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + ns_sleep.c + 0 + 0 + + + 6 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + ns_log_usart.c + 0 + 0 + + + 6 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + ns_sec.c + 0 + 0 + + + 6 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + ns_ble.c + 0 + 0 + + + 6 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + ns_ble_task.c + 0 + 0 + + + + + BLE_APP + 0 + 0 + 0 + 0 + + 7 + 26 + 1 + 0 + 0 + 0 + ..\src\app_profile\app_dis.c + app_dis.c + 0 + 0 + + + 7 + 27 + 1 + 0 + 0 + 0 + ..\src\app_ble.c + app_ble.c + 0 + 0 + + + + + USER + 0 + 0 + 0 + 0 + + 8 + 28 + 1 + 0 + 0 + 0 + ..\src\app_usart.c + app_usart.c + 0 + 0 + + + 8 + 29 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + + + CONFIG + 0 + 0 + 0 + 0 + + 9 + 30 + 5 + 0 + 0 + 0 + ..\inc\app_user_config.h + app_user_config.h + 0 + 0 + + + + + DOC + 0 + 0 + 0 + 0 + + 10 + 31 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/MDK-ARM/RF_Test.uvprojx b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/MDK-ARM/RF_Test.uvprojx new file mode 100644 index 0000000..9c36dc8 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/MDK-ARM/RF_Test.uvprojx @@ -0,0 +1,718 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + N32WB03x + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + N32WB031 + Nationstech + Nationstech.N32WB03X_DFP.1.1.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0xC000) IROM(0x1000000,0x40000) CPUTYPE("Cortex-M0") CLOCK(64000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0N32WB03X -FS01000000 -FL040000 -FP0($$Device:N32WB031$Flash\N32WB03X.FLM)) + 0 + $$Device:N32WB031$firmware\CMSIS\device\n32wb03x.h + + + + + + + + + + $$Device:N32WB031$svd\N32WB03X.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + RF_Test + 1 + 0 + 1 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + fromelf --bin --output=.\bin\RF_Test.bin .\Objects\RF_Test.axf + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0 + SARMCM3.DLL + + TARMCM1.DLL + -pCM0 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x1000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x1000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20004000 + 0x8000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + N32WB03X, USE_STDPERIPH_DRIVER + + ..\..\..\..\..\firmware\CMSIS\core;..\..\..\..\..\firmware\CMSIS\device;..\..\..\..\..\firmware\n32wb03x_std_periph_driver\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ahi\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gap;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\gatt;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\hl\src\l2c;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\lld;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\ble\ll\src\llm;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\em\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\hci\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\ip\sch\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\aes\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\dbg\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ecc_p256\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\h4tl\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\ke\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\rwip\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\rfinit\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\api;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\modules\common\src;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\arch;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\adv;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\timer;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\delay;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec;..\inc\app_profile;..\inc;..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\symdef\symbol_g15.obj + + + + + + + + STARTUP + + + startup_n32wb03x.s + 2 + ..\..\..\..\..\firmware\CMSIS\device\startup\startup_n32wb03x.s + + + + + CMSIS + + + system_n32wb03x.c + 1 + ..\..\..\..\..\firmware\CMSIS\device\system_n32wb03x.c + + + + + FWLB + + + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 0 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + + + + + + + + + + + + misc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\misc.c + + + 2 + 0 + 0 + 0 + 0 + 1 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 0 + 0 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + n32wb03x_adc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_adc.c + + + n32wb03x_crc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_crc.c + + + n32wb03x_dma.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_dma.c + + + n32wb03x_exti.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_exti.c + + + n32wb03x_gpio.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_gpio.c + + + n32wb03x_rcc.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_rcc.c + + + n32wb03x_tim.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_tim.c + + + n32wb03x_usart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_usart.c + + + n32wb03x_lpuart.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_lpuart.c + + + n32wb03x_qflash.c + 1 + ..\..\..\..\..\firmware\n32wb03x_std_periph_driver\src\n32wb03x_qflash.c + + + + + BLE_STACK + + + rwip.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip.c + + + rwip_driver.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_stack\stack_common\rwip_driver.c + + + + + BLE_PROFILE + + + prf.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf.c + + + prf_utils.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\prf_utils.c + + + diss.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss.c + + + diss_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_ble_profile\dis\diss\src\diss_task.c + + + + + NS_LIB + + + ns_log_lpuart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_lpuart.c + + + ns_sleep.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sleep\ns_sleep.c + + + ns_log_usart.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\log\ns_log_usart.c + + + ns_sec.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\sec\ns_sec.c + + + ns_ble.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble.c + + + ns_ble_task.c + 1 + ..\..\..\..\..\middlewares\Nationstech\ble_library\ns_library\ble\ns_ble_task.c + + + + + BLE_APP + + + app_dis.c + 1 + ..\src\app_profile\app_dis.c + + + app_ble.c + 1 + ..\src\app_ble.c + + + + + USER + + + app_usart.c + 1 + ..\src\app_usart.c + + + main.c + 1 + ..\src\main.c + + + + + CONFIG + + + app_user_config.h + 5 + ..\inc\app_user_config.h + + + + + DOC + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + +
diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_ble.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_ble.h new file mode 100644 index 0000000..b3b1257 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_ble.h @@ -0,0 +1,96 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file ns_ble.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_BLE_H__ +#define __APP_BLE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ns_ble.h" +#include "ns_ble_task.h" + +/// User Task messages +enum user_msg_id +{ + APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER, + APP_CUSTS_TEST_EVT, + APP_TIMER0, + +}; + +/* ble application initialization */ +void app_ble_init(void); +void app_ble_gap_params_init(void); +void app_ble_adv_init(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_BLE_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_profile/app_dis.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_profile/app_dis.h new file mode 100644 index 0000000..cec9f0a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_profile/app_dis.h @@ -0,0 +1,158 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef APP_DIS_H_ +#define APP_DIS_H_ + +/** + * @addtogroup APP + * + * @brief Device Information Application Module Entry point. + * + * @{ + **/ + +/* Includes ------------------------------------------------------------------*/ + +#include "rwip_config.h" // SW Configuration + +#if (BLE_APP_DIS) + +#include + +/* Define ------------------------------------------------------------*/ + +/// Manufacturer Name Value +#define APP_DIS_MANUFACTURER_NAME ("NSING") +#define APP_DIS_MANUFACTURER_NAME_LEN (5) + +/// Model Number String Value +#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0") +#define APP_DIS_MODEL_NB_STR_LEN (10) + +/// Serial Number +#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE") +#define APP_DIS_SERIAL_NB_STR_LEN (10) + +/// Firmware Revision +#define APP_DIS_FIRM_REV_STR ("1.0.0") +#define APP_DIS_FIRM_REV_STR_LEN (5) + +/// System ID Value - LSB -> MSB +#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE") +#define APP_DIS_SYSTEM_ID_LEN (8) + +/// Hardware Revision String +#define APP_DIS_HARD_REV_STR ("1.0.0") +#define APP_DIS_HARD_REV_STR_LEN (5) + +/// Software Revision String +#define APP_DIS_SW_REV_STR ("1.0.0") +#define APP_DIS_SW_REV_STR_LEN (5) + +/// IEEE +#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA") +#define APP_DIS_IEEE_LEN (6) + +/** + * PNP ID Value - LSB -> MSB + * Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value) + * Vendor ID : 0x045E (Microsoft Corp) + * Product ID : 0x0040 + * Product Version : 0x0300 + */ +#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03") +#define APP_DIS_PNP_ID_LEN (7) + +#if (BLE_APP_HID) +#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\ + DIS_MODEL_NB_STR_CHAR_SUP_BIT |\ + DIS_SYSTEM_ID_CHAR_SUP_BIT |\ + DIS_PNP_ID_CHAR_SUP_BIT) + +#else +#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP) +#endif //(BLE_APP_HID) + + +/* Public variables ---------------------------------------------------------*/ + +/// Table of message handlers +extern const struct app_subtask_handlers app_dis_handlers; + +/* Public function prototypes -----------------------------------------------*/ + +/** + * @brief Initialize Device Information Service Application + **/ +void app_dis_init(void); + +/** + * @brief Add a Device Information Service instance in the DB + **/ +void app_dis_add_dis(void); + +/** + * @brief Enable the Device Information Service + **/ +void app_dis_enable_prf(uint16_t conhdl); + +#endif //BLE_APP_DIS + +/// @} APP + +#endif //APP_DIS_H_ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_profile/rwapp_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_profile/rwapp_config.h new file mode 100644 index 0000000..5f4bcdc --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_profile/rwapp_config.h @@ -0,0 +1,125 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file rwapp_config.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + + +#ifndef _RWAPP_CONFIG_H_ +#define _RWAPP_CONFIG_H_ + +/** + * @addtogroup app + * @brief Application configuration definition + * + * @{ + **/ + +#include "app_user_config.h" +#include "rwip_config.h" +/* Includes ------------------------------------------------------------------*/ + +/* Define ------------------------------------------------------------*/ + + +/// Application Profile +#if defined(CFG_APP_PRF) +#define BLE_APP_PRF 1 +#else // defined(CFG_APP_PRF) +#define BLE_APP_PRF 0 +#endif // defined(CFG_APP_PRF) + + +/// Health Thermometer Application +#if defined(CFG_APP_HT) +#define BLE_APP_HT 1 +#else // defined(CFG_APP_HT) +#define BLE_APP_HT 0 +#endif // defined(CFG_APP_HT) + +/// HID Application +#if defined(CFG_APP_HID) +#define BLE_APP_HID 1 +#else // defined(CFG_APP_HID) +#define BLE_APP_HID 0 +#endif // defined(CFG_APP_HID) + +/// DIS Application +#if defined(CFG_APP_DIS) +#define BLE_APP_DIS 1 +#else // defined(CFG_APP_DIS) +#define BLE_APP_DIS 0 +#endif // defined(CFG_APP_DIS) + + + +/// Battery Service Application +#if (CFG_APP_BATT) +#define BLE_APP_BATT 1 +#else +#define BLE_APP_BATT 0 +#endif //(CFG_APP_BATT) + +/// Security Application +#if (defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 1 +#else //(defined(CFG_APP_SEC) || BLE_APP_HID) +#define BLE_APP_SEC 0 +#endif //(defined(CFG_APP_SEC) || BLE_APP_HID) + + +#define AM0_APP_OPTIONAL_CHARACTERISTICS 0 + +/// @} rwapp_config + +#endif /* _RWAPP_CONFIG_H_ */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_usart.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_usart.h new file mode 100644 index 0000000..73bb9c2 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_usart.h @@ -0,0 +1,173 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.h + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#ifndef __APP_USART_H__ +#define __APP_USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "n32wb03x.h" + + +/* Public typedef -----------------------------------------------------------*/ +/* Public define ------------------------------------------------------------*/ +#define _USART1_COM_ +//#define _USART2_COM_ +//#define USART1_ON_PA45 + +#ifdef _USART1_COM_ + +#ifndef USART1_ON_PA45 + +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_7 +#define USARTx_TxPin GPIO_PIN_6 +#define USARTx_Rx_GPIO_AF GPIO_AF4_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF4_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USARTx_IRQHandler USART1_IRQHandler +#else + +#define USARTx USART1 +#define USARTx_CLK RCC_APB2_PERIPH_USART1 +#define USARTx_GPIO GPIOA +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOA +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART1 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART1 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USARTx_IRQHandler USART1_IRQHandler +#endif + + +#define USARTx_DAT_Base (USART1_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART1_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART1_RX +#define USARTx_IRQn USART1_IRQn + +#endif + +#ifdef _USART2_COM_ +#define USARTx USART2 +#define USARTx_CLK RCC_APB1_PERIPH_USART2 +#define USARTx_GPIO GPIOB +#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB +#define USARTx_RxPin GPIO_PIN_5 +#define USARTx_TxPin GPIO_PIN_4 +#define USARTx_Rx_GPIO_AF GPIO_AF3_USART2 +#define USARTx_Tx_GPIO_AF GPIO_AF3_USART2 +#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk +#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk + +#define USARTx_DAT_Base (USART2_BASE + 0x04) +#define USARTx_Tx_DMA_Channel DMA_CH1 +#define USARTx_Tx_DMA_FLAG DMA_FLAG_TC1 +#define USARTx_Rx_DMA_Channel DMA_CH2 +#define USARTx_Rx_DMA_FLAG DMA_FLAG_TC2 +#define USARTx_Tx_DMA_REMAP DMA_REMAP_USART2_TX +#define USARTx_Rx_DMA_REMAP DMA_REMAP_USART2_RX +#define USARTx_IRQn USART2_IRQn +#define USARTx_IRQHandler USART2_IRQHandler + + +#endif + + +#define USART_RX_DMA_SIZE 16 +#define USART_RX_FIFO_SIZE 1000 +#define USART_TX_FIFO_SIZE 1000 + + +/* Public macro -------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ + +/* Public function prototypes -----------------------------------------------*/ + +void app_usart_configuration(void); +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len); +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len); +void app_usart_tx_data_blocking(uint8_t *p_data, uint16_t len); + +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len); +void usart_forward_to_ble_loop(void); +void app_usart_dma_enable(FunctionalState Cmd); +#ifdef __cplusplus +} +#endif + +#endif /* __APP_USART_H__ */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_user_config.h b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_user_config.h new file mode 100644 index 0000000..63d9570 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/inc/app_user_config.h @@ -0,0 +1,138 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_user_config.h + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#ifndef _APP_USER_CONFIG_H_ +#define _APP_USER_CONFIG_H_ + +#include "ns_adv_data_def.h" + +/* Device name */ + +#define CUSTOM_DEVICE_NAME "NS_DIS" + +/* adv configer*/ +#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */ +#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */ + +#define CUSTOM_ADV_FAST_DURATION 30 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */ +#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */ + + +#define CUSTOM_USER_ADVERTISE_DATA \ + "\x03"\ + ADV_TYPE_SERVICE_DATA_16BIT_UUID\ + ADV_UUID_DEVICE_INFORMATION_SERVICE\ + + +#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1) + +// Scan response data +#define CUSTOM_USER_ADV_SCNRSP_DATA \ + "\x0a"\ + ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\ + "\xff\xffNations" + +// Scan response data length- maximum 31 bytes +#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1) + + +/* connection config */ +#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */ +#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */ +#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */ + +#define FIRST_CONN_PARAMS_UPDATE_DELAY (5000) /**< Time of initiating event to update connection params (5 seconds). */ + +//sec config +#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */ +#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */ +#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */ +#define SEC_PARAM_BOND 1 /**< Perform bonding. */ +#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */ +#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */ +#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ +#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */ +#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */ + +//bond conifg +#define MAX_BOND_PEER 5 +#define BOND_STORE_ENABLE 0 +#define BOND_DATA_BASE_ADDR 0x0103B000 + +/* profiles config */ +#define CFG_APP_DIS 1 +#define CFG_PRF_DISS 1 +//#define CFG_APP_BATT 1 +//#define CFG_PRF_BASS 1 + +//#define INFTRX /****PRBS9 pattern for SRRC/FCC certification*****/ +/* User config */ +#define NS_LOG_ERROR_ENABLE 1 +#define NS_LOG_WARNING_ENABLE 1 +#define NS_LOG_INFO_ENABLE 1 +#define NS_LOG_DEBUG_ENABLE 0 + +#define NS_LOG_LPUART_ENABLE 1 + +#define NS_TIMER_ENABLE 0 + +#define FIRMWARE_VERSION "1.0.0" +#define HARDWARE_VERSION "1.0.0" + +#endif // _APP_USER_CONFIG_H_ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/readme.txt b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/readme.txt new file mode 100644 index 0000000..ec1a858 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/readme.txt @@ -0,0 +1,28 @@ +1. Function description + + Bluetooth RF Test demo. User can send uart command to actiev LE test mode. It support BLE TX, RX mode +in different channel, tx power, physical layer, packet type. Packet type support constant carrier mode. + Define POWER_ON_ENTER_CW to set the program enter constant carrier mode after power on. Define POWER_ON_CW_CH +to set the channel of constant carrier mode. + +2. Operating environment + Software development environment: KEIL MDK-ARM V5.30.0.0 + Hardware environment: Developed based on the development board N32WB031_STB + +3. Instructions + + System configuration; + 1. Clock source: HSI=64M, AHB=64M, APB1=32M, APB2=64M + 2. Port configuration: + LED1: PB0 + LED2: PA6 + KEY1: PB1 + KEY2: PB2 + 3. command port: DEMO board PB6(TX) PB7(RX), baud rate: 19200, 8 data bits, 1 stop bit, no parity bit, no hardware flow control + + + usage method: + 1. Burn to development board after compilation + 2. Connect the UART com port in PC software. + 3. Send command via PC software to active board enter test mode. + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/app_ble.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/app_ble.c new file mode 100644 index 0000000..3a0bd9d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/app_ble.c @@ -0,0 +1,359 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_ble.c + * @author NSING Firmware Team + * @version v1.0.2 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ +#include "app_user_config.h" +#include "global_func.h" +#include "ns_sec.h" +#include "app_ble.h" +#include "app_dis.h" +#include "app_usart.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +//#define POWER_ON_ENTER_CW +#define POWER_ON_CW_CH 0 //2402 Hz +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Private functions ---------------------------------------------------------*/ +void app_ble_connected(void); +void app_ble_disconnected(void); + +/** + * @brief user message handler + * @param + * @return + * @note + */ +void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param) +{ + static uint8_t uart_cmd[2]; + switch (msgid) + { + case GAPM_LE_TEST_END_IND: + { + extern uint8_t usart_sending; + extern uint8_t m_stop_rx_rsp; + ///respond cmd to usart + struct gapm_le_test_end_ind* p = (struct gapm_le_test_end_ind*)p_param; + uint16_t m_event; + m_event = 0x8000 | p->nb_packet_received; + uart_cmd[0] = (m_event>>8)& 0xFF; + uart_cmd[1] = (m_event)& 0xFF; + while(usart_sending){} + + usart_tx_dma_send(uart_cmd,2); + m_stop_rx_rsp = true; + } + + break; + case APP_TIMER0: + { + extern uint8_t usart_sending; + extern uint8_t m_stop_rx_rsp; + if(!m_stop_rx_rsp) + { + //if not send respond yet + uart_cmd[0] = 0; + uart_cmd[1] = 0; + while(usart_sending){} + usart_tx_dma_send(uart_cmd,2); + m_stop_rx_rsp = true; + } + } + break; + default: + break; + } + + +} + +/** + * @brief ble message handler + * @param + * @return + * @note + */ +void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg) +{ + switch (p_ble_msg->msg_id) + { + case APP_BLE_OS_READY: + { + NS_LOG_INFO("APP_BLE_OS_READY\r\n"); + #ifdef POWER_ON_ENTER_CW + NS_LOG_INFO("POWER_ON_ENTER_CW\r\n"); + struct gapm_le_test_mode_ctrl_cmd rf_params = {0}; + rf_params.channel = POWER_ON_CW_CH; + rf_params.operation = GAPM_LE_TEST_TX_START; + rf_params.tx_data_length = 1; + rf_params.tx_pkt_payload = GAP_PKT_PLD_PRBS9; + rf_params.phy = GAP_PHY_1MBPS; + rf_params.slot_dur = 1; + rf_params.modulation_idx = GAP_MODULATION_STANDARD; + rf_params.switching_pattern_len = MIN_SWITCHING_PATTERN_LEN; + ns_ble_prod_test_cmd_send(&rf_params,true);//tx cw + #endif + + } break; + case APP_BLE_GAP_CONNECTED: + app_ble_connected(); + break; + case APP_BLE_GAP_DISCONNECTED: + app_ble_disconnected(); + break; + + default: + break; + } + +} + +/** + * @brief advertising message handler + * @param + * @return + * @note + */ +void app_ble_adv_msg_handler(enum app_adv_mode adv_mode) +{ + switch (adv_mode) + { + case APP_ADV_MODE_DIRECTED: + + break; + case APP_ADV_MODE_FAST: + + break; + case APP_ADV_MODE_SLOW: + + break; + default: + break; + } + +} + + +/** + * @brief ble GAP initialization + * @param + * @return + * @note + */ +void app_ble_gap_params_init(void) +{ + struct ns_gap_params_t dev_info = {0}; + uint8_t *p_mac = SystemGetMacAddr(); + //get UUID from trim stored + if(p_mac != NULL) + { + //set the uuid as mac address + memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN); + } + else{ + memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN); + } + + + /* init params*/ + dev_info.mac_addr_type = GAPM_STATIC_ADDR; + dev_info.appearance = 0; + dev_info.dev_role = GAP_ROLE_PERIPHERAL; + + dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1; + memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len); + + dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS); + dev_info.dev_conn_param.latency = SLAVE_LATENCY; + dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS); + dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; + + ns_ble_gap_init(&dev_info); + +} + + +/** + * @brief ble advertising initialization + * @param + * @return + * @note + */ +void app_ble_adv_init(void) +{ + struct ns_adv_params_t user_adv = {0}; + + //init advertising data + user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN; + memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN); + user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN; + memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN); + + user_adv.attach_appearance = false; + user_adv.attach_name = true; + user_adv.ex_adv_enable = false; + user_adv.adv_phy = PHY_1MBPS_VALUE; + + //init advertising params + user_adv.directed_adv.enable = false; + + user_adv.fast_adv.enable = true; + user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION; + user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL; + + user_adv.slow_adv.enable = true; + user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION; + user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL; + + user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler; + + ns_ble_adv_init(&user_adv); + + +} + +void app_ble_sec_init(void) +{ + struct ns_sec_init_t sec_init = {0}; + + sec_init.rand_pin_enable = false; + sec_init.pin_code = 123456; + + sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) ); + sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES; + sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE; + sec_init.pairing_feat.oob = SEC_PARAM_OOB; + sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY; + sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY; + sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL; + + sec_init.bond_enable = BOND_STORE_ENABLE; + sec_init.bond_db_addr = BOND_DATA_BASE_ADDR; + sec_init.bond_max_peer = MAX_BOND_PEER; + sec_init.bond_sync_delay = 2000; + + sec_init.ns_sec_msg_handler = NULL; + + ns_sec_init(&sec_init); +} + +void app_ble_prf_init(void) +{ + //add device informaiton server + ns_ble_add_prf_func_register(app_dis_add_dis); +} + + +/** + * @brief ble initialization + * @param + * @return + * @note + */ +void app_ble_init(void) +{ + struct ns_stack_cfg_t app_handler = {0}; + app_handler.ble_msg_handler = app_ble_msg_handler; + app_handler.user_msg_handler = app_user_msg_handler; + app_handler.lsc_cfg = BLE_LSC_LSI_32768HZ; + //initialization ble stack + ns_ble_stack_init(&app_handler); + + app_ble_gap_params_init(); + app_ble_sec_init(); + app_ble_adv_init(); + app_ble_prf_init(); + +} + +/** + * @brief ble connected + * @param + * @return + * @note + */ +void app_ble_connected(void) +{ + + +} + +/** + * @brief ble disconnected + * @param + * @return + * @note + */ +void app_ble_disconnected(void) +{ + // Restart Advertising +// ns_ble_adv_start(); + +} + + + + + +/** + * @} + */ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/app_profile/app_dis.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/app_profile/app_dis.c new file mode 100644 index 0000000..1ffd357 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/app_profile/app_dis.c @@ -0,0 +1,255 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_dis.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** + * @addtogroup APP + * @{ + **/ + +#include "rwip_config.h" // SW configuration + +#if (BLE_APP_DIS) +/* Includes ------------------------------------------------------------------*/ +#include "ns_ble.h" // Application Manager Definitions +#include "app_dis.h" // Device Information Service Application Definitions +#include "diss_task.h" // Device Information Profile Functions +#include "prf_types.h" // Profile Common Types Definitions +#include "ke_task.h" // Kernel +#include "gapm_task.h" // GAP Manager Task API +#include "diss.h" +#include +#include +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief dis server value require indicate handler + * @param + * @return + * @note + */ +static int diss_value_req_ind_handler(ke_msg_id_t const msgid, + struct diss_value_req_ind const *param, + ke_task_id_t const dest_id, + ke_task_id_t const src_id) +{ + NS_LOG_DEBUG("%s\r\n", __func__); + // Initialize length + uint8_t len = 0; + // Pointer to the data + uint8_t *data = NULL; + + // Check requested value + switch (param->value) + { + case DIS_MANUFACTURER_NAME_CHAR: + { + // Set information + len = APP_DIS_MANUFACTURER_NAME_LEN; + data = (uint8_t *)APP_DIS_MANUFACTURER_NAME; + } break; + + case DIS_MODEL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_MODEL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_MODEL_NB_STR; + } break; + + case DIS_SYSTEM_ID_CHAR: + { + // Set information + len = APP_DIS_SYSTEM_ID_LEN; + data = (uint8_t *)APP_DIS_SYSTEM_ID; + } break; + + case DIS_PNP_ID_CHAR: + { + // Set information + len = APP_DIS_PNP_ID_LEN; + data = (uint8_t *)APP_DIS_PNP_ID; + } break; + + case DIS_SERIAL_NB_STR_CHAR: + { + // Set information + len = APP_DIS_SERIAL_NB_STR_LEN; + data = (uint8_t *)APP_DIS_SERIAL_NB_STR; + } break; + + case DIS_HARD_REV_STR_CHAR: + { + // Set information + len = APP_DIS_HARD_REV_STR_LEN; + data = (uint8_t *)APP_DIS_HARD_REV_STR; + } break; + + case DIS_FIRM_REV_STR_CHAR: + { + // Set information + len = APP_DIS_FIRM_REV_STR_LEN; + data = (uint8_t *)APP_DIS_FIRM_REV_STR; + } break; + + case DIS_SW_REV_STR_CHAR: + { + // Set information + len = APP_DIS_SW_REV_STR_LEN; + data = (uint8_t *)APP_DIS_SW_REV_STR; + } break; + + case DIS_IEEE_CHAR: + { + // Set information + len = APP_DIS_IEEE_LEN; + data = (uint8_t *)APP_DIS_IEEE; + } break; + + default: + ASSERT_ERR(0); + break; + } + + // Allocate confirmation to send the value + struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM, + src_id, dest_id, + diss_value_cfm, + len); + + // Set parameters + cfm_value->value = param->value; + cfm_value->length = len; + if (len) + { + // Copy data + memcpy(&cfm_value->data[0], data, len); + } + // Send message + ke_msg_send(cfm_value); + + return (KE_MSG_CONSUMED); +} + +/** + * @brief dis server Initialize + * @param + * @return + * @note + */ +void app_dis_init(void) +{ + //register application subtask to app task + struct prf_task_t prf; + prf.prf_task_id = TASK_ID_DISS; + prf.prf_task_handler = &app_dis_handlers; + ns_ble_prf_task_register(&prf); + + //register get itf function to prf.c + struct prf_get_func_t get_func; + get_func.task_id = TASK_ID_DISS; + get_func.prf_itf_get_func = diss_prf_itf_get; + prf_get_itf_func_register(&get_func); +} + +/** + * @brief add dis server + * @param + * @return + * @note + */ +void app_dis_add_dis(void) +{ + struct diss_db_cfg* db_cfg; + // Allocate the DISS_CREATE_DB_REQ + struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD, + TASK_GAPM, TASK_APP, + gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg)); + // Fill message + req->operation = GAPM_PROFILE_TASK_ADD; + req->sec_lvl = PERM(SVC_AUTH, NO_AUTH); + req->prf_task_id = TASK_ID_DISS; + req->app_task = TASK_APP; + req->start_hdl = 0; + + // Set parameters + db_cfg = (struct diss_db_cfg* ) req->param; + db_cfg->features = APP_DIS_FEATURES; + + // Send the message + ke_msg_send(req); + + app_dis_init(); +} + +/* Public variables ---------------------------------------------------------*/ + +/// Default State handlers definition +const struct ke_msg_handler app_dis_msg_handler_list[] = +{ + {DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler}, +}; + +const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis); + + +#endif //BLE_APP_DIS + +/// @} APP diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/app_usart.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/app_usart.c new file mode 100644 index 0000000..64bf72d --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/app_usart.c @@ -0,0 +1,799 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file app_usart.c + * @author NSING Firmware Team + * @version v1.0.0 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +#include "global_func.h" +#include "app_usart.h" +#include "ns_log.h" +#include "ns_delay.h" +#include "app_ble.h" +/** @addtogroup + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +typedef enum +{ + STATE_UNINITIALIZED, + STATE_IDLE, + STATE_TRANSMITTER_TEST, + STATE_CARRIER_TEST, + STATE_RECEIVER_TEST +} state_t; +/* Private define ------------------------------------------------------------*/ + +//#define LE_PACKET_REPORTING_EVENT 0x8000 +#define RF_TEST_STATUS_EVENT_SUCCESS 0x0000 +#define RF_TEST_STATUS_EVENT_ERROR 0x0001 + +#define CMD_RSP_SUCCESS 0x00 +#define CMD_RSP_ERROR_ILLEGAL_CHANNEL 0x01 +#define CMD_RSP_ERROR_INVALID_STATE 0x02 +#define CMD_RSP_ERROR_ILLEGAL_LENGTH 0x03 +#define CMD_RSP_ERROR_ILLEGAL_CONFIGURATION 0x04 +#define CMD_RSP_ERROR_UNINITIALIZED 0x05 + +#define RF_TEST_SETUP 0 +#define RF_RECEIVER_TEST 1 +#define RF_TRANSMITTER_TEST 2 +#define RF_TEST_END 3 + +#define RF_TEST_SETUP_RESET 0 +#define RF_TEST_SETUP_SET_UPPER 1 +#define RF_TEST_SETUP_SET_PHY 2 +#define RF_TEST_SETUP_SELECT_MODULATION 3 +#define RF_TEST_SETUP_READ_SUPPORTED 4 +#define RF_TEST_SETUP_READ_MAX 5 + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +uint8_t USART_rx_dma_buf[USART_RX_DMA_SIZE] = {0}; +uint16_t rx_old_pos = 0; + +uint8_t usart_rx_fifo_buf[USART_RX_FIFO_SIZE] = {0}; +uint32_t usart_rx_fifo_in = 0; +uint32_t usart_rx_fifo_out = 0; + + +uint8_t usart_tx_fifo_buf[USART_TX_FIFO_SIZE] = {0}; +uint32_t usart_tx_fifo_in = 0; +uint32_t usart_tx_fifo_out = 0; + +uint8_t usart_sending = false; +uint8_t ble_sending = false; +uint16_t ble_att_mtu = (ATT_DEFAULT_MTU-3); + +//rf test +struct gapm_le_test_mode_ctrl_cmd m_rf_params; +static uint16_t m_event; +static bool m_new_event; +static uint16_t m_state = STATE_UNINITIALIZED; +uint8_t m_stop_rx_rsp = false; + +static uint8_t uart_cmd[2]; +/* Private function prototypes -----------------------------------------------*/ +void app_usart_tx_process(void); +extern void cwtx_test(uint8_t channel); +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief Configures the different system clocks. + */ +void RCC_Configuration_USART(void) +{ + /* Enable GPIO clock */ + GPIO_APBxClkCmd(USARTx_GPIO_CLK, ENABLE); + /* Enable USARTx Clock */ + USART_APBxClkCmd(USARTx_CLK, ENABLE); + /* DMA clock enable */ + RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_DMA, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + */ +void GPIO_Configuration_USART(void) +{ + GPIO_InitType GPIO_InitStructure; + + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + + /* Configure USARTx Rx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_RxPin; + GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the DMA. + */ +void DMA_Configuration(void) +{ + DMA_InitType DMA_InitStructure; + + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_DeInit(USARTx_Tx_DMA_Channel); + DMA_RequestRemap(USARTx_Tx_DMA_REMAP, DMA, USARTx_Tx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Tx_DMA_Channel,DMA_INT_TXC ,ENABLE); + + /* USARTx RX DMA1 Channel (triggered by USARTx Rx event) Config */ + DMA_DeInit(USARTx_Rx_DMA_Channel); + DMA_RequestRemap(USARTx_Rx_DMA_REMAP, DMA, USARTx_Rx_DMA_Channel, ENABLE); + DMA_ConfigInt(USARTx_Rx_DMA_Channel,DMA_INT_TXC|DMA_INT_HTX ,ENABLE); + + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)USART_rx_dma_buf; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC; + DMA_InitStructure.BufSize = USART_RX_DMA_SIZE; + DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Rx_DMA_Channel, &DMA_InitStructure); + +} + + +/** + * @brief Configures the nested vectored interrupt controller. + */ +void NVIC_Configuration(void) +{ + NVIC_InitType NVIC_InitStructure; + + NVIC_DisableIRQ(DMA_Channel1_2_3_4_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = DMA_Channel1_2_3_4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + NVIC_DisableIRQ(USARTx_IRQn); + /* Enable the DMA Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 3; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} + +/** + * @brief Configures the USART as 115200 8n1. + */ +void app_usart_configuration(void) +{ + + USART_InitType USART_InitStructure; + + /* Configure and enable RCC */ + RCC_Configuration_USART(); + /* Configure GPIO for USART */ + GPIO_Configuration_USART(); + + /* Configure the DMA */ + DMA_Configuration(); + + NVIC_Configuration(); + + /* USARTx and USARTz configuration ------------------------------------------------------*/ + USART_InitStructure.BaudRate = 19200; + USART_InitStructure.WordLength = USART_WL_8B; + USART_InitStructure.StopBits = USART_STPB_1; + USART_InitStructure.Parity = USART_PE_NO; + USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; + USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; + + /* Configure USARTx */ + USART_Init(USARTx, &USART_InitStructure); + + /* Enable USARTz Receive and Transmit interrupts */ + USART_ConfigInt(USARTx, USART_INT_IDLEF, ENABLE); + + /* Enable USARTx DMA Rx and TX request */ + USART_EnableDMA(USARTx, USART_DMAREQ_RX | USART_DMAREQ_TX, ENABLE); + + DMA_EnableChannel(USARTx_Rx_DMA_Channel, ENABLE); + + /* Enable the USARTx */ + USART_Enable(USARTx, ENABLE); + +} + +/** + * @brief enable or disable the usart dma + */ +void app_usart_dma_enable(FunctionalState Cmd) +{ + if(Cmd == ENABLE) + { + rx_old_pos = 0; + usart_tx_fifo_in = usart_tx_fifo_out = 0; //clean fifo + usart_rx_fifo_in = usart_rx_fifo_out = 0; //clean fifo + app_usart_configuration(); + m_state = STATE_IDLE; + } + else{ + + USART_Enable(USARTx, DISABLE); + DMA_EnableChannel(USARTx_Rx_DMA_Channel, DISABLE); + DMA_EnableChannel(USARTx_Tx_DMA_Channel, DISABLE); + /* Deinit IO of USART to save power */ + GPIO_InitType GPIO_InitStructure; + /* Initialize GPIO_InitStructure */ + GPIO_InitStruct(&GPIO_InitStructure); + /* Configure USARTx Tx as alternate function push-pull */ + GPIO_InitStructure.Pin = USARTx_TxPin|USARTx_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.GPIO_Alternate = GPIO_AF0; + GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure); + } +} + +static uint32_t app_rf_tx_power_cmd(uint32_t cmd) +{ + uint8_t new_power8; + new_power8 = (uint8_t)(cmd & 0xFF); + new_power8 = (new_power8 & 0x30) != 0 ? (new_power8 | 0xC0) : new_power8; + switch (new_power8) + { + case 0: + rf_tx_power_set(TX_POWER_0_DBM); + break; + case 1: case 2: + rf_tx_power_set(TX_POWER_Pos2_DBM); + break; + case 3: + rf_tx_power_set(TX_POWER_Pos3_DBM); + break; + case 4: + rf_tx_power_set(TX_POWER_Pos4_DBM); + break; + case 5: case 6: case 7: case 8: + rf_tx_power_set(TX_POWER_Pos6_DBM); + break; + case 0xfc: //-4 + rf_tx_power_set(TX_POWER_Neg2_DBM); + break; + case 0xf8: //-8 + rf_tx_power_set(TX_POWER_Neg8_DBM); + break; + case 0xf4: //-12 + case 0xf0: //-16 + rf_tx_power_set(TX_POWER_Neg15_DBM); + break; + case 0xec: //-20 + case 0xd8: //-40 + rf_tx_power_set(TX_POWER_Neg20_DBM); + break; + default: + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_ILLEGAL_CONFIGURATION; + } + return CMD_RSP_SUCCESS; +} + + +/** + * @brief rf test command handler + */ +uint32_t app_rf_test_cmd(uint32_t cmd, uint32_t freq, uint32_t length, uint32_t payload) +{ + m_rf_params.tx_data_length = (m_rf_params.tx_data_length&0xC0) |((uint8_t)length & 0x3F); + m_rf_params.tx_pkt_payload = payload; + m_rf_params.channel = freq; + + if ((m_rf_params.phy == 1 || m_rf_params.phy == 2) && payload == 3) + { + m_rf_params.tx_pkt_payload = 0xff; + } + + m_new_event = true; + m_event = RF_TEST_STATUS_EVENT_SUCCESS; + + if (cmd == RF_TEST_SETUP) + { + + if (freq == RF_TEST_SETUP_RESET) + { + if (length != 0x00) + { + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_ILLEGAL_CONFIGURATION; + } + m_rf_params.tx_data_length = 0; + + m_rf_params.phy = 1; + m_rf_params.slot_dur = 1; + m_rf_params.switching_pattern_len = MIN_SWITCHING_PATTERN_LEN; + m_rf_params.operation = GAPM_LE_TEST_STOP; + ns_ble_prod_test_cmd_send(&m_rf_params,false);//stop, reset + m_state = STATE_IDLE; + } + else if (freq == RF_TEST_SETUP_SET_UPPER) + { + if (length > 0x03) + { + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_ILLEGAL_CONFIGURATION; + } + m_rf_params.tx_data_length = length << 6; + } + else if (freq == RF_TEST_SETUP_SET_PHY) + { + switch (length) + { + case 1: + case 2: + case 3: + case 4: + m_rf_params.phy = length; + return CMD_RSP_SUCCESS; + + default: + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_ILLEGAL_CONFIGURATION; + } + } + else if (freq == RF_TEST_SETUP_SELECT_MODULATION) + { + if (length > 0x01) + { + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_ILLEGAL_CONFIGURATION; + } + else{ + m_rf_params.modulation_idx = length; + } + } + else if (freq == RF_TEST_SETUP_READ_SUPPORTED) + { + if (length != 0x00) + { + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_ILLEGAL_CONFIGURATION; + } + m_event = 0x0006; + } + else if (freq == RF_TEST_SETUP_READ_MAX) + { + switch (length) + { + case 0x00: + // Read supportedMaxTxOctets + m_event = 0x01FE; + break; + case 0x01: + // Read supportedMaxTxTime + m_event = 0x4290; + break; + case 0x02: + // Read supportedMaxRxOctets + m_event = 0x01FE; + break; + case 0x03: + // Read supportedMaxRxTime + m_event = 0x4290; + break; + default: + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_ILLEGAL_CONFIGURATION; + } + } + else + { + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_ILLEGAL_CONFIGURATION; + } + return CMD_RSP_SUCCESS; + } + + if (cmd == RF_TEST_END) + { + if (m_state == STATE_IDLE) + { + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_INVALID_STATE; + } + else if(m_state == STATE_CARRIER_TEST) + { + uart_cmd[0] = 0; + uart_cmd[1] = 0; + usart_tx_dma_send(uart_cmd,2); + delay_n_ms(5); + NVIC_SystemReset(); + } + //rx respond in gapm_le_test_end_ind_handler + m_rf_params.operation = GAPM_LE_TEST_STOP; + ns_ble_prod_test_cmd_send(&m_rf_params,false);//stop + // + if(m_state ==STATE_RECEIVER_TEST) + { + m_new_event = false; + + m_stop_rx_rsp = false; + ke_timer_set(APP_TIMER0, TASK_APP, 30); + } + + m_state = STATE_IDLE; + + return CMD_RSP_SUCCESS; + } + + if (m_state != STATE_IDLE) + { + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_INVALID_STATE; + } + + if (payload != 3 && m_rf_params.channel > 39) + { + m_event = RF_TEST_STATUS_EVENT_ERROR; + + return CMD_RSP_ERROR_ILLEGAL_CHANNEL; + } + + if (cmd == RF_RECEIVER_TEST) + { + + m_rf_params.operation = GAPM_LE_TEST_RX_START; + m_rf_params.slot_dur = 1; + m_rf_params.switching_pattern_len = MIN_SWITCHING_PATTERN_LEN; + ns_ble_prod_test_cmd_send(&m_rf_params,false);//rx + m_state = STATE_RECEIVER_TEST; + return CMD_RSP_SUCCESS; + } + + if (cmd == RF_TRANSMITTER_TEST) + { + switch (m_rf_params.tx_pkt_payload) + { + case 0://PRBS9 + case 1://0x0F + case 2://0x55 + break; + case 3: + m_rf_params.tx_pkt_payload = GAP_PKT_PLD_REPEATED_11111111;//4 + break; + case 0xff: + if(length == 0 || length ==1) + { + //continuous carrier signal(CW test) + m_rf_params.tx_pkt_payload = 0; + m_rf_params.operation = GAPM_LE_TEST_TX_START; + ns_ble_prod_test_cmd_send(&m_rf_params,true);//tx + + m_state = STATE_CARRIER_TEST; + return CMD_RSP_SUCCESS; + }else + if(length == 2)// set tx power command + { + return app_rf_tx_power_cmd(freq); + } + else{ + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_ILLEGAL_CONFIGURATION; + } + + default: + // Parameter error + m_event = RF_TEST_STATUS_EVENT_ERROR; + return CMD_RSP_ERROR_ILLEGAL_CONFIGURATION; + } + + m_rf_params.operation = GAPM_LE_TEST_TX_START; + ns_ble_prod_test_cmd_send(&m_rf_params,false);//tx + m_state = STATE_TRANSMITTER_TEST; + } + return CMD_RSP_SUCCESS; +} +//uint16_t command; +/** + * @brief usart rx data enter fifo and active ble send first package if not active yet + */ +uint8_t app_usart_rx_data_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + + if(len == 2) + { + uint16_t command = ((uint16_t)p_data[0]<<8)|p_data[1]; + uint32_t command_code = (command >> 14) & 0x03; + uint32_t freq = (command >> 8) & 0x3F; + uint32_t length = (command >> 2) & 0x3F; + uint32_t payload = command & 0x03; + + app_rf_test_cmd(command_code, freq, length, payload); + if(m_new_event) + { + m_new_event = false; + uart_cmd[0] = (m_event>>8)& 0xFF; + uart_cmd[1] = (m_event)& 0xFF; + usart_tx_dma_send(uart_cmd,2); + } + } + else{ + uart_cmd[0] = 0; + uart_cmd[1] = 0; + usart_tx_dma_send(uart_cmd,2); + NS_LOG_INFO("cmd len err=%d",len); + } + + return len; +} + +/** + * @brief usart send data via dma + */ +uint8_t usart_tx_dma_send(uint8_t *p_data, uint16_t len) +{ + DMA_InitType DMA_InitStructure; + + if(usart_sending) + { + return false; + } + /* USARTx_Tx_DMA_Channel (triggered by USARTx Tx event) Config */ + DMA_InitStructure.PeriphAddr = USARTx_DAT_Base; + DMA_InitStructure.MemAddr = (uint32_t)p_data; + DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST; + DMA_InitStructure.BufSize = len; + DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE; + DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE; + DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_BYTE; + DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.CircularMode = DMA_MODE_NORMAL; + DMA_InitStructure.Priority = DMA_PRIORITY_VERY_HIGH; + DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE; + DMA_Init(USARTx_Tx_DMA_Channel, &DMA_InitStructure); + + usart_sending = true; + DMA_EnableChannel(USARTx_Tx_DMA_Channel, ENABLE); + + return true; +} + +/** + * @brief usart send data in blocking mode + */ +void usart_tx_data_blocking(uint8_t *p_data, uint16_t len) +{ + while(len--) + { + USART_SendData(USARTx, *p_data); + p_data++; + } +} + +/** + * @brief usart tx fifo enter and active dma send out + */ +uint8_t app_usart_tx_fifo_enter(const uint8_t *p_data, uint16_t len) +{ + uint32_t in_len, out_temp; + //store data in fifo + NS_LOG_DEBUG("%d,%d,%d\r\n",len,usart_tx_fifo_in,usart_tx_fifo_out); + out_temp = usart_tx_fifo_out; + while(len) + { + if(usart_tx_fifo_in >= out_temp ) + { + in_len = USART_TX_FIFO_SIZE-usart_tx_fifo_in; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + p_data += in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + } + else if(usart_tx_fifo_in < out_temp ) + { + in_len = out_temp-usart_tx_fifo_in-1; + if(in_len > len) + { + in_len = len; + } + memcpy(&usart_tx_fifo_buf[usart_tx_fifo_in],p_data,in_len); + len = len-in_len; + usart_tx_fifo_in = (usart_tx_fifo_in + in_len)%USART_TX_FIFO_SIZE; + + //fifo full,drop the rest data + if(len) + { + NS_LOG_WARNING("F:%d,%d,%d\r\n",len,usart_tx_fifo_in,out_temp); + } + + break; + } + } + + // ble treaming cut timer, active usart send after it. + if(!usart_sending) + { + app_usart_tx_process(); + } + return len; +} + +/** + * @brief usart tx data from fifo + */ +void app_usart_tx_process(void) +{ + uint32_t in_temp,len; + uint8_t *p_data; + + in_temp = usart_tx_fifo_in; + if(usart_tx_fifo_out < in_temp) + { + len = in_temp-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = in_temp; + } + + } + else if(usart_tx_fifo_out > in_temp) + { + len = USART_TX_FIFO_SIZE-usart_tx_fifo_out; + p_data = &usart_tx_fifo_buf[usart_tx_fifo_out]; + if(usart_tx_dma_send(p_data,len) == true) + { + usart_tx_fifo_out = 0; + } + + } +} + + +/** + * @brief check the dma buffer which has been received + */ +void usart_rx_check_in_irq(void) +{ + uint16_t rx_pos; + + rx_pos = USART_RX_DMA_SIZE - DMA_GetCurrDataCounter(USARTx_Rx_DMA_Channel); + if(rx_pos < rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(USART_RX_DMA_SIZE - rx_old_pos)); + + if(rx_pos > 0) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[0],rx_pos); + } + + rx_old_pos = rx_pos; + } + else if(rx_pos > rx_old_pos) + { + app_usart_rx_data_fifo_enter(&USART_rx_dma_buf[rx_old_pos],(rx_pos - rx_old_pos)); + rx_old_pos = rx_pos; + } + else if(rx_pos != rx_old_pos) + { + //error + rx_old_pos = rx_pos; + } + +} + + +/** + * @brief dma irq handler + */ +void DMA_Channel1_2_3_4_IRQHandler(void) +{ + //TX + if(DMA_GetFlagStatus(DMA_FLAG_TC1, DMA)) + { + //TX Transfer complete interrupt + usart_sending = false; + + DMA_ClearFlag(DMA_FLAG_TC1, DMA); + } + //RX + if(DMA_GetFlagStatus(DMA_FLAG_TC2, DMA)) + { + //RX Transfer complete interrupt + DMA_ClearFlag(DMA_FLAG_TC2, DMA); + usart_rx_check_in_irq(); + + } + if(DMA_GetFlagStatus(DMA_FLAG_HT2, DMA)) + { + //RX Half transfer interrupt + DMA_ClearFlag(DMA_FLAG_HT2, DMA); + usart_rx_check_in_irq(); + } + + +} + +/** + * @brief usart irq handler + */ +void USARTx_IRQHandler(void) +{ + uint8_t temp; + //usart idlle interrupt + if(USART_GetFlagStatus(USARTx,USART_FLAG_IDLEF)) + { + //read sts and data will clear rx idle interrupt + temp = USARTx->DAT; + usart_rx_check_in_irq(); + (void)temp; + } + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/main.c b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/main.c new file mode 100644 index 0000000..8693b30 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/projects/n32wb03x_EVAL/prod_test/RF_Test/src/main.c @@ -0,0 +1,130 @@ +/** +* Copyright (c) 2025, NSING Technologies Inc. +* +* All rights reserved. +* +* This software is the exclusive property of NSING Technologies Inc. (Hereinafter +* referred to as NSING). This software, and the product of NSING described herein +* (Hereinafter referred to as the Product) are owned by NSING under the laws and treaties +* of the People's Republic of China and other applicable jurisdictions worldwide. +* +* NSING does not grant any license under its patents, copyrights, trademarks, or other +* intellectual property rights. Names and brands of third party may be mentioned or referred +* thereto (if any) for identification purposes only. +* +* NSING reserves the right to make changes, corrections, enhancements, modifications, and +* improvements to this software at any time without notice. Please contact NSING and obtain +* the latest version of this software before placing orders. + +* Although NSING has attempted to provide accurate and reliable information, NSING assumes +* no responsibility for the accuracy and reliability of this software. +* +* It is the responsibility of the user of this software to properly design, program, and test +* the functionality and safety of any application made of this information and any resulting product. +* In no event shall NSING be liable for any direct, indirect, incidental, special,exemplary, or +* consequential damages arising in any way out of the use of this software or the Product. +* +* NSING Products are neither intended nor warranted for usage in systems or equipment, any +* malfunction or failure of which may cause loss of human life, bodily injury or severe property +* damage. Such applications are deemed, "Insecure Usage". +* +* All Insecure Usage shall be made at user's risk. User shall indemnify NSING and hold NSING +* harmless from and against all claims, costs, damages, and other liabilities, arising from or related +* to any customer's Insecure Usage. + +* Any express or implied warranty with regard to this software or the Product, including,but not +* limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement +* are disclaimed to the fullest extent permitted by law. + +* Unless otherwise explicitly permitted by NSING, anyone may not duplicate, modify, transcribe +* or otherwise distribute this software for any purposes, in whole or in part. +* +* NSING products and technologies shall not be used for or incorporated into any products or systems +* whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. +* User shall comply with any applicable export control laws and regulations promulgated and administered by +* the governments of any countries asserting jurisdiction over the parties or transactions. +**/ + + +/** + * @file main.c + * @author NSING Firmware Team + * @version v1.0.1 + * + * @copyright Copyright (c) 2025, NSING Technologies Inc. All rights reserved. + */ + +/** @addtogroup + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "n32wb03x.h" +#include "ns_log.h" +#include "app_usart.h" +#include "app_ble.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +#define DEMO_STRING "\r\n NSING RF Test demo \r\n" + +/* Private constants ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + + +/** + * @brief main function + * @param + * @return + * @note Note + */ +int main(void) +{ + #ifdef USART1_ON_PA45 + //for hold the SWD before sleep + delay_n_10us(200*1000); + #endif + NS_LOG_INIT(); + + app_ble_init(); + + NS_LOG_INFO(DEMO_STRING); + app_usart_dma_enable(ENABLE ); + //rf_tx_power_set(TX_POWER_Pos6_DBM); + while (1) + { + /*schedule all pending events*/ + rwip_schedule(); + } +} + +/** + * @brief user handle before enter sleep mode + * @param + * @return + * @note + */ +void app_sleep_prepare_proc(void) +{ + +} + +/** + * @brief user handle after wake up from sleep mode + * @param + * @return + * @note + */ +void app_sleep_resume_proc(void) +{ + + +} + + + +/** + * @} + */ + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/release_notes.txt b/nations-tec/N32WB03x_SDK_V2.0.0/release_notes.txt new file mode 100644 index 0000000..be731b1 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/release_notes.txt @@ -0,0 +1,182 @@ +SDK V2.0.0-2025-09-05 +1. Optimize otp api for new model. +2. Fix the issue for rpa device address check flow. +3. Optimize the storage flow of bond info. +4. Fix the Sector Erase instruction in the SPI_FLASH example. +5. Fix the pclk configuration in the SmartCard example. +6. Optimize the RCC_HsiCalib function. +7. Update the Copyright Declaration. + +SDK V1.3.5-2025-05-09 +1. Remove redundancy function RCC_ConfigMcoClkPre. +2. Fix peripheral_alone and I2C_Master example. +3. Remove rtdss_FreeRTOS example. +4. Add a central_hogprh example project for hid report host with whitelist reconnect. +5. Optimize masterboot and RF_Test example. +6. Optimize rdtss example for data block and segmentation. +7. Fix GPIO_ConfigPinRemap and driver current configuration issue. +8. Fix the Jlink read issue in script. +9. Optimize the configuration of BLE TX Power. +10. Optimize the frequency calibration flow by trim value. +11. Optimize the long timer sleep issue. +12. Fix rssi issue with multi-connection. +13. Optimize the function ns_ble_prod_test_cmd_send for rf test. + +SDK V1.3.4-2024-10-15 +1. Fix rssi issue in scan state and in connection state with latency. +2. Optimize rdtss_value_req_ind_handler with conidx for multiple connection. +3. Fix adv stopped issue after disconnection by 0x3e. +4. Optimize set adv data and respond data flow. +5. Optimize dfu_crc32 with illegal address judgment for single bank OTA. +6. Optimize RAL setting flow. +7. Update read me for heart_rate and central_relay_1m1s. +8. Remove lptimer example. +9. Add GAPM_SCAN_REQUEST_IND with handler. +10. Optimize NC mode for security pair. +11. Add a rdtsc_16bit example project. +12. Add a relay_1m2s example project with _3_CONN_ rom patch. +13. Add a rtdss_FreeRTOS example project for FreeRTOS demo with BLE. +14. Add a rom patch _PATCH_MULTI_CON_ for multi-connection issue with same address. + +SDK V1.3.3-2023-11-29 +1. Fix the macro definition issue of the LPUART driver header file. +2. Add OTP read/write/erase function to Qflash driver. +3. ns_ble adds watchdog configuration interface, optimizes coded scanning and connection, optimizes annotation description, and corrects PHY macro definition. +4. The masterboot project has been updated to support PA45 and PB67 dual serial ports, as well as 1M and 115200 dual baud rates, fixing the issue of not restoring peripherals. +5. Update dfu_crc32 supports non-4-byte alignment and is a standard CRC-32 MPEG-2 algorithm. +6. Optimize the mapping IO of RFTest and DTM engineering support macro configuration serial port 1. +7. Resolve Multi-connection processing issues with rdtss_16bit services. +8. Remove 7PWM_Output_From_HSE example. + +—————————————————————————————————————————————— +SDK V1.3.2 - 2023-8-31 +1. Fix the issue with the function RCC_ConfigSysclk. +2. Optimize the function PWR_EnterSLEEPMode using HSI to shut down ble. +3. Optimize the function SystemTrimValueRead to avoid issues. +4. Optimize the function KEYSCAN_Init to increase retention voltage. +5. Optimize the maximum sleep time to more than 11 hours. +6. Optimize the set PHY API to support multiple PHYs. +7. Optimize the set adv and respond data APIs. +8. Optimize the set pincode API. +9. Optimize the scan API to support coded scan mode. +10. Optimize the modem for scan and master init (connect) mode. +11. Optimize baseband to improve 2M and coded connections. +12. Optimize the qflash init function. +13. Optimize bond data storage with a maximum delay. +14. Optimize all examples of sending ble data with the newest MTU. +15. Optimize all BLE APIs to be compatible with the RTOS. +16. Fix the issue of LSI running at 32768 Hz. +17. Fix the issue of multiple connections and master discover servers after abortive disconnects. +18. Add a patch to fix the issue with the function ke_timer_set. +19. Add an API to support write list and channel map. +20. Add an API to support searching addresses' irks and resolving addresses. +21. Add an API to support master paring, bonding, scan stopping feedback, and connect timeout. +22. Add an API to support setting frequency offsets. +23. Add a 16-bit ADC and AWD example project. +24. Add a keyscan example project. +25. Add an IRC example project. +26. Add output MCO as the clock source of TIM to output a precise PWM example project. +27. Add a lesc&aes example project and related APIs; update the library to support LESC. +28. Add a beacon example project. +29. Add a lptimer example project and relate APIs. +30. Update all binaries in the dfu folder and add scripts using NSLink. + + + +SDK V1.3.1 - 2023-3-15 +1. Update prf_search_chars_128 function, compatible with all kinds of uuid lengths. +2. Update ns_ble_start_scan function,enable GAPM_ SCAN_ PROP_ ACTIVE_ 1M_ BIT for active scan。 +3. Update the judgment condition for the static address. +4. Update the imageupdate project to solve the problem of incomplete functions. +5. Update the default configuration of routine LSI 32768 to LSI 32K. + +**************************************************** +SDK V1.3.0 - 2022-12-5 +Update summary: +1. n32wb03x_adc.c, correct ADC_ EnableBypassFilter, and ADC_ EnableEnergy and ADC_ DeInit function. +2. i2c_epprom.c deletes garbled comments. +3. n32wb03x_rtc.h remove non-existent functions. +4. n32wb03x_rcc.h add RCC_EnableRTCReset function declaration. +5. ble_stack_common.h and system_n32wb03x.c modifies the parameters of the delay function. +6. ns_ble.c and ns_sleep.c remove ns_ble_hw_check function. +7. ns_ble_task.c adds logic to solve the problem that MTU can only be updated once. +8. The SPI example adds delay to optimize the test process. +9. Mouse example hid_ The mouse updates the key logic processing to solve wakes up issue. +10. Increase retention voltage when keyscan is initialized. +11. RTC examples disable wake-up interrupts and add some delays before configuring RTC time. +12. LSI trim to 32.768K as default. +13. Fix reading problem with maximum Bluetooth binding. +14. Update the patch file, and add the Ke MSG set patch for rtos example. +15. fix issue of directional broadcasting and reconnect to master with random address. +16. Add two pairing process states to return to the application. +17. Add the logic that ensures sleep exits before exiting ns_sleep . +18. Add logic to confirm ke timer(1ms timer) before exiting ns_sleep. +19. Add confirmation of HSE ready after wake-up. +20. Add multiple connection examples (3 slave, 3 master, and update 1m1s). +21. Optimize interrupt vector initialization in the Bluetooth stack initialization, update usage in examples. +22. Optimize header files for Bluetooth library functions, and integrate them into global_func.h. +23. Optimize the log library to add locks to avoid issue of interrupting nesting. +24. Optimizing process state for activity +25. Update all readme in examples to English version. +26. Delete remote control examples, four SPI examples, and the FreeRTOS low power example. +27. update utilities\dfu to English version. +28. Add RF_Test and DTM_Test demo. + +**************************************************** +SDK V1.2.0 - 2022-4-28 +Update summary: +1. n32wb03x_Qflas.h File Update the return of function Qflash_Erase_Sector, Qflash_Write and Qflash_Read. +2. n32wb03x_rtc.h Remove macro definition IS_RTC_GET_RTC contained in INT_INT_ALRB. +3. n32wb03x_tim.c and n32wb03x_tim.h correct comments. +4. n32wb03x_adc.c update function ADC_ConvertValueToVoltage and ADC_ConverValueToTemperature. +5. n32wb03x_lpuart.c through macro LSI_TRIM_For 28800HZ, the LPUART uses the 28.8k option. +6. n32wb03x_pwr Remove PWR_EnterStandbyMode function. +7. GPIO_InitStruct, change the default GPIO current from high to low. +8. Fix issue of softwareI2C example and correct folder names +9. LPUART wake-up example adds LSI calibration function, and it is recommended to use 32.768k or 28.8k when using LSI. +10. Add precautions for jumper connection in ADC example. +11. Add the software patch of ble fifo interrupt function. +12. Add patch in ble_stack_common.h. The bluetooth example enables the encryption response patch by default +13. Add logic to delete corresponding active after scanning. +14. Add broadcast status callback, add directional broadcast function, and add the interface to obtain the latest binding device address. +15. Add the connection parameter update function incoming parameter limit and log. +16. Optimize Bluetooth sleep function. +17. Add 1 master 1 slave to getting rssi callback and demonstration code from example. +18. Add mtu change success message and connection parameter change completion instruction callback. +19. Add master&slave switching example. +20. Add blood pressure service example. +21. Fix the problem of local variables not initialized and compilation alarms. +22. Fix the problem of comments and do not select ns link by default. +23. Add gap server and gatt server, which are enabled by default. +24. Add Bluetooth stack configuration of different low speed clock setting options and LSI calibration mechanism. +25. Add HardFault_ Handler interrupt response function is configured by default. +26. Fix ns_ ble_ phy_ Set function parameter configuration problem. + + +**************************************************** +SDK V1.1.0 - 2022-1-6 +Update summary: +1. Add software calibration of ADC to the remote control example to avoid the problem of sound curve deviation. +2. Update the flash driver to read bank B (the last 256k), remove the built-in ble scheduling function, and mask interrupt. +3. Update FLASH_ RW examples. +4. Add BLE master example of data transmission(RDTSC). +5. Rename the trim value reading function, and encapsulate the mac reading and uid reading functions. +6. Fix ns_log_usart_Deinit may change some io configurations. +7. Complete the SystemInit function, use trim to calibrate HSI, and configure the APB1 CLK to HCKL/2 in HSI64M. +8. Correction ns_ The timer function annotation describes that the delay time is 1ms. +9. Package app. c and app_Task. c files as ble.c and ble_task.c library. +10. Configure the adv, gap, scan, sec and other related parameters through initialization. +11. Add broadcast initialization, set broadcast data, and open and close broadcast APIs. +12. Add/update mtu, phy, dle, connection parameter setting api, and add rssi reading api. +13. Add adv, sec, ble and user event callback interfaces. +14. Add the interface for profile registration. +15. Add extended broadcast (long packet) and coded broadcast APIs. +16. Update all Bluetooth examples based on the Bluetooth library. +17. Add 1 master and 1 slave example. (The ble.c public library is not used) +18. Modify Bluetooth RF parameters + + +**************************************************** +SDK V1.0.0 - 2021-10-26 + +Initial Version \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/GenerateKeyPair.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/GenerateKeyPair.bat new file mode 100644 index 0000000..4072cb9 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/GenerateKeyPair.bat @@ -0,0 +1,6 @@ +.\NSUtil\NSUtil.exe keys generate-private-key .\keys\private_key.pem +.\NSUtil\NSUtil.exe keys generate-public-key .\keys\public_key --private_key .\keys\private_key.pem + +PAUSE +EXIT + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/GenerateUpdateImage.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/GenerateUpdateImage.bat new file mode 100644 index 0000000..1f068ac --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/GenerateUpdateImage.bat @@ -0,0 +1,111 @@ + +echo off + +set output_ota_zip=ota + +set APP_VERSION=0x00000002 +set IMAGE_UPDATE_VERSION=0x00000001 + +set app1_bin=Image\APP1.bin +set app2_bin=Image\APP2.bin +::set image_update_bin=Image\ImageUpdate.bin + +set private_key=keys\private_key.pem +set NSUtil_path=.\NSUtil\NSUtil.exe + +if defined private_key ( + + if defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack otawithsigning %output_ota_zip% ^ + --private_key %private_key% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + + + ) + + if defined app2_bin if not defined image_update_bin ( + + %NSUtil_path% pack otawithsigning %output_ota_zip% ^ + --private_key %private_key% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% + + + ) + + if not defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack otawithsigning %output_ota_zip% ^ + --private_key %private_key% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + ) + +) + +if not defined private_key ( + + if defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack ota %output_ota_zip% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + + + ) + + if defined app2_bin if not defined image_update_bin ( + + %NSUtil_path% pack ota %output_ota_zip% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% + + + ) + + if not defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack ota %output_ota_zip% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + ) + +) + + + + +PAUSE +EXIT \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/APP1.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/APP1.bin new file mode 100644 index 0000000..d543a16 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/APP1.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/APP2.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/APP2.bin new file mode 100644 index 0000000..bd8b22c Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/APP2.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/GenerateUpdateImage.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/GenerateUpdateImage.bat new file mode 100644 index 0000000..3d60d80 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/GenerateUpdateImage.bat @@ -0,0 +1,112 @@ + +echo off + + +set NSUtil_path=..\..\NSUtil\NSUtil.exe +set private_key=..\..\keys\private_key.pem + + +set APP_VERSION=0x00000002 +set IMAGE_UPDATE_VERSION=0x00000002 +set output_ota_zip=Image\ota_dual_bank +set app1_bin=Image\APP1.bin +set app2_bin=Image\APP2.bin +set image_update_bin=Image\ImageUpdate.bin + + +if defined private_key ( + + if defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack otawithsigning %output_ota_zip% ^ + --private_key %private_key% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + + + ) + + if defined app2_bin if not defined image_update_bin ( + + %NSUtil_path% pack otawithsigning %output_ota_zip% ^ + --private_key %private_key% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% + + + ) + + if not defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack otawithsigning %output_ota_zip% ^ + --private_key %private_key% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + ) + +) + +if not defined private_key ( + + if defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack ota %output_ota_zip% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + + + ) + + if defined app2_bin if not defined image_update_bin ( + + %NSUtil_path% pack ota %output_ota_zip% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% + + + ) + + if not defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack ota %output_ota_zip% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + ) + +) + + + + +PAUSE +EXIT \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/APP1.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/APP1.bin new file mode 100644 index 0000000..d543a16 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/APP1.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/APP2.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/APP2.bin new file mode 100644 index 0000000..bd8b22c Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/APP2.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/ImageUpdate.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/ImageUpdate.bin new file mode 100644 index 0000000..fd23463 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/ImageUpdate.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/MasterBoot.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/MasterBoot.bin new file mode 100644 index 0000000..5771352 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/MasterBoot.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/bootsetting.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/bootsetting.bin new file mode 100644 index 0000000..6c4a248 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/bootsetting.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/ota_dual_bank.zip b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/ota_dual_bank.zip new file mode 100644 index 0000000..2fd424f Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/Image/ota_dual_bank.zip differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/JLINKProgramming.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/JLINKProgramming.bat new file mode 100644 index 0000000..118a9cb --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/DualBankProgrammingDemo/JLINKProgramming.bat @@ -0,0 +1,151 @@ +echo off + + +set JLink_path=..\..\JLink\JLink_V632\JLink.exe +set JLink_script_path=..\..\JLink\JLink_Script\download.jlink +set NSUtil_path=..\..\NSUtil\NSUtil.exe + +::Creating bootsetting file +::bootsetting.bin path +set output_bootsetting=.\Image\bootsetting.bin +::bank1 parameters£¬nonoptional +set bank1_start_address=0x1004000 +set bank1_version=0x00000001 +set bank1_bin=.\Image\APP1.bin +set bank1_activation=yes +::bank2 parameters£¬optional +set bank2_start_address=0x1020000 +set bank2_version=0x00000001 +set bank2_bin=.\Image\APP2.bin +set bank2_activation=no +::ImageUpdate parameters£¬optional +set image_update_start_address=0x0103C000 +set image_update_version=0x00000001 +::set image_update_bin=.\Image\ImageUpdate.bin +set image_update_activation=no +::Public key£¬optional +set public_key_file=..\..\keys\public_key.bin + + + +if defined public_key_file ( + + if defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% + ) + if not defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if not defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% + ) + + +) + +if not defined public_key_file ( + + if defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% + ) + if not defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if not defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% + ) + + + +) + + + +::Execute Jlink script file to program bin files +%JLink_path% -Device N32WB031 -If SWD -Speed 4000 -commanderscript %JLink_script_path% + +PAUSE +EXIT + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/ImageUpdate.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/ImageUpdate.bin new file mode 100644 index 0000000..fd23463 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/ImageUpdate.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/APP1.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/APP1.bin new file mode 100644 index 0000000..d543a16 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/APP1.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/APP2.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/APP2.bin new file mode 100644 index 0000000..bd8b22c Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/APP2.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/ImageUpdate.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/ImageUpdate.bin new file mode 100644 index 0000000..fd23463 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/ImageUpdate.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/MasterBoot.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/MasterBoot.bin new file mode 100644 index 0000000..5771352 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/MasterBoot.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/bootsetting.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/bootsetting.bin new file mode 100644 index 0000000..993611b Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/Image/bootsetting.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/JLINKProgramming.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/JLINKProgramming.bat new file mode 100644 index 0000000..1bbd3ca --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/JLINKProgrammingDemo/JLINKProgramming.bat @@ -0,0 +1,151 @@ +echo off + + +set JLink_path=..\..\JLink\JLink_V632\JLink.exe +set JLink_script_path=..\..\JLink\JLink_Script\download.jlink +set NSUtil_path=..\..\NSUtil\NSUtil.exe + +::Creating bootsetting file +::bootsetting.bin path +set output_bootsetting=.\Image\bootsetting.bin +::bank1 parameters£¬nonoptional +set bank1_start_address=0x1004000 +set bank1_version=0x00000001 +set bank1_bin=.\Image\APP1.bin +set bank1_activation=yes +::bank2 parameters£¬optional +set bank2_start_address=0x1020000 +set bank2_version=0x00000001 +set bank2_bin=.\Image\APP2.bin +set bank2_activation=no +::ImageUpdate parameters£¬optional +set image_update_start_address=0x0103C000 +set image_update_version=0x00000001 +set image_update_bin=.\Image\ImageUpdate.bin +set image_update_activation=no +::Public key£¬optional +set public_key_file=..\..\keys\public_key.bin + + + +if defined public_key_file ( + + if defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% + ) + if not defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if not defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% + ) + + +) + +if not defined public_key_file ( + + if defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% + ) + if not defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if not defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% + ) + + + +) + + + +::Execute Jlink script file to program bin files +%JLink_path% -Device N32WB031 -If SWD -Speed 4000 -commanderscript %JLink_script_path% + +PAUSE +EXIT + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/MasterBoot.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/MasterBoot.bin new file mode 100644 index 0000000..5771352 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/MasterBoot.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/GenerateUpdateImage.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/GenerateUpdateImage.bat new file mode 100644 index 0000000..fc48095 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/GenerateUpdateImage.bat @@ -0,0 +1,112 @@ + +echo off + + +set NSUtil_path=..\..\NSUtil\NSUtil.exe +set private_key=..\..\keys\private_key.pem + + +set APP_VERSION=0x00000002 +set IMAGE_UPDATE_VERSION=0x00000002 +set output_ota_zip=Image\ota_single_bank +set app1_bin=Image\APP1.bin +::set app2_bin=Image\APP2.bin +set image_update_bin=Image\ImageUpdate.bin + + +if defined private_key ( + + if defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack otawithsigning %output_ota_zip% ^ + --private_key %private_key% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + + + ) + + if defined app2_bin if not defined image_update_bin ( + + %NSUtil_path% pack otawithsigning %output_ota_zip% ^ + --private_key %private_key% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% + + + ) + + if not defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack otawithsigning %output_ota_zip% ^ + --private_key %private_key% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + ) + +) + +if not defined private_key ( + + if defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack ota %output_ota_zip% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + + + ) + + if defined app2_bin if not defined image_update_bin ( + + %NSUtil_path% pack ota %output_ota_zip% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --app2_start_address 0x01020000 ^ + --app2_version %APP_VERSION% ^ + --app2_bin %app2_bin% + + + ) + + if not defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack ota %output_ota_zip% ^ + --app1_start_address 0x01004000 ^ + --app1_version %APP_VERSION% ^ + --app1_bin %app1_bin% ^ + --image_update_start_address 0x0103C000 ^ + --image_update_version %IMAGE_UPDATE_VERSION% ^ + --image_update_bin %image_update_bin% + ) + +) + + + + +PAUSE +EXIT \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/APP1.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/APP1.bin new file mode 100644 index 0000000..d543a16 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/APP1.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/APP2.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/APP2.bin new file mode 100644 index 0000000..bd8b22c Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/APP2.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/ImageUpdate.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/ImageUpdate.bin new file mode 100644 index 0000000..fd23463 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/ImageUpdate.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/MasterBoot.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/MasterBoot.bin new file mode 100644 index 0000000..5771352 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/MasterBoot.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/bootsetting.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/bootsetting.bin new file mode 100644 index 0000000..6c4a248 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/bootsetting.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/ota_single_bank.zip b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/ota_single_bank.zip new file mode 100644 index 0000000..f5a480f Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/Image/ota_single_bank.zip differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/JLINKProgramming.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/JLINKProgramming.bat new file mode 100644 index 0000000..4eb5e8f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/SingleBankProgrammingDemo/JLINKProgramming.bat @@ -0,0 +1,151 @@ +echo off + + +set JLink_path=..\..\JLink\JLink_V632\JLink.exe +set JLink_script_path=..\..\JLink\JLink_Script\download.jlink +set NSUtil_path=..\..\NSUtil\NSUtil.exe + +::Creating bootsetting file +::bootsetting.bin path +set output_bootsetting=.\Image\bootsetting.bin +::bank1 parameters£¬nonoptional +set bank1_start_address=0x1004000 +set bank1_version=0x00000001 +set bank1_bin=.\Image\APP1.bin +set bank1_activation=yes +::bank2 parameters£¬optional +set bank2_start_address=0x1020000 +set bank2_version=0x00000001 +::set bank2_bin=.\Image\APP2.bin +set bank2_activation=no +::ImageUpdate parameters£¬optional +set image_update_start_address=0x0103C000 +set image_update_version=0x00000001 +::set image_update_bin=.\Image\ImageUpdate.bin +set image_update_activation=no +::Public key£¬optional +set public_key_file=..\..\keys\public_key.bin + + + +if defined public_key_file ( + + if defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% + ) + if not defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if not defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% + ) + + +) + +if not defined public_key_file ( + + if defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% + ) + if not defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if not defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% + ) + + + +) + + + +::Execute Jlink script file to program bin files +%JLink_path% -Device N32WB031 -If SWD -Speed 4000 -commanderscript %JLink_script_path% + +PAUSE +EXIT + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/bootsetting.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/bootsetting.bin new file mode 100644 index 0000000..abce622 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/Image/bootsetting.bin differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLINKDragFilesToProgram.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLINKDragFilesToProgram.bat new file mode 100644 index 0000000..df1f17f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLINKDragFilesToProgram.bat @@ -0,0 +1,21 @@ +echo off + +set JLink_path=.\JLink\JLink_V632\JLink.exe +set JLink_script_path=.\JLink\JLink_Script\loadDragFile.jlink + +if exist "%1" ( +echo start erase and program. +echo r > %JLink_script_path% +echo erase >> %JLink_script_path% +echo loadfile %1 0x01000000 >> %JLink_script_path% +echo r >> %JLink_script_path% +echo g >> %JLink_script_path% +echo q >> %JLink_script_path% +%JLink_path% -Device N32WB031 -If SWD -Speed 4000 -commanderscript %JLink_script_path% +del %JLink_script_path% /f +) else ( +echo. +echo Error! Do not double-click to run this bat!!! +echo. ) +PAUSE +EXIT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLINKProgramming.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLINKProgramming.bat new file mode 100644 index 0000000..4185380 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLINKProgramming.bat @@ -0,0 +1,163 @@ +@echo off + + +set JLink_path=.\JLink\JLink_V632\JLink.exe +set JLink_script_path=.\JLink\JLink_Script\download.jlink +set NSUtil_path=.\NSUtil\NSUtil.exe + +::Creating bootsetting file +::bootsetting.bin path +set output_bootsetting=.\Image\bootsetting.bin +::bank1 parameters£¬nonoptional +set bank1_start_address=0x1004000 +set bank1_version=0x00000001 +set bank1_bin=.\Image\APP1.bin +set bank1_activation=yes +::bank2 parameters£¬optional +set bank2_start_address=0x1020000 +set bank2_version=0x00000001 +set bank2_bin=.\Image\APP2.bin +set bank2_activation=no +::ImageUpdate parameters£¬optional +set image_update_start_address=0x0103C000 +set image_update_version=0x00000001 +::set image_update_bin=.\Image\ImageUpdate.bin +set image_update_activation=no +::ImageUpdate parameters£¬optional +set public_key_file=.\keys\public_key.bin + + +if exist %output_bootsetting% (del %output_bootsetting%) + +if defined public_key_file ( + + if defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + + + ) + if defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% + + + ) + if not defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + + + ) + if not defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% + + + ) + + +) + +if not defined public_key_file ( + + if defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% + ) + if not defined bank2_bin if defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --image_update_start_address %image_update_start_address% ^ + --image_update_version %image_update_version% ^ + --image_update_bin %image_update_bin% ^ + --image_update_activation %image_update_activation% + ) + if not defined bank2_bin if not defined image_update_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% + ) + + + +) +::Execute Jlink script file to program bin files +if exist %output_bootsetting% ( + %JLink_path% -Device N32WB031 -If SWD -Speed 4000 -commanderscript %JLink_script_path% +) + + + + + +PAUSE +EXIT + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLINKReadAll.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLINKReadAll.bat new file mode 100644 index 0000000..defa744 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLINKReadAll.bat @@ -0,0 +1,4 @@ +.\JLink\JLink_V632\JLink.exe -Device N32WB031 -If SWD -Speed 4000 -commanderscript .\JLink\JLink_Script\read_ALL.jlink + +PAUSE +EXIT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/download.jlink b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/download.jlink new file mode 100644 index 0000000..2b002c0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/download.jlink @@ -0,0 +1,11 @@ +r +h +erase +loadbin Image\MasterBoot.bin 0x01000000 +loadbin Image\Bootsetting.bin 0x01002000 +loadbin Image\APP1.bin 0x01004000 +loadbin Image\APP2.bin 0x01020000 +loadbin Image\ImageUpdate.bin 0x0103C000 +r +g +q diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_ALL.jlink b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_ALL.jlink new file mode 100644 index 0000000..172bc4b --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_ALL.jlink @@ -0,0 +1,4 @@ +savebin JLINKReadAllFile.bin 0x01000000 0x40000 +r +g +q diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_app1.jlink b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_app1.jlink new file mode 100644 index 0000000..9c4dcc6 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_app1.jlink @@ -0,0 +1,4 @@ +savebin app1.bin 0x01004000 0x1C000 +r +g +q diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_app2.jlink b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_app2.jlink new file mode 100644 index 0000000..bca8486 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_app2.jlink @@ -0,0 +1,4 @@ +savebin app2.bin 0x01020000 0x1C000 +r +g +q diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_bootsetting.jlink b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_bootsetting.jlink new file mode 100644 index 0000000..0086ac0 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_bootsetting.jlink @@ -0,0 +1,4 @@ +savebin bootsetting.bin 0x01002000 0x1000 +r +g +q diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_imageupdate.jlink b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_imageupdate.jlink new file mode 100644 index 0000000..3c34e9f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_imageupdate.jlink @@ -0,0 +1,4 @@ +savebin ImageUpdate.bin 0x0103C000 0x4000 +r +g +q diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_master_boot.jlink b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_master_boot.jlink new file mode 100644 index 0000000..8495e8c --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_Script/read_master_boot.jlink @@ -0,0 +1,4 @@ +savebin MasterBoot.bin 0x01000000 0x2000 +r +g +q diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/Devices/Nationstech/N32WB03x.FLM b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/Devices/Nationstech/N32WB03x.FLM new file mode 100644 index 0000000..214f123 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/Devices/Nationstech/N32WB03x.FLM differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLink.exe b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLink.exe new file mode 100644 index 0000000..2b82795 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLink.exe differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLinkARM.dll b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLinkARM.dll new file mode 100644 index 0000000..49a5a6e Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLinkARM.dll differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLinkDevices.xml b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLinkDevices.xml new file mode 100644 index 0000000..429e03e --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLinkDevices.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLink_x64.dll b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLink_x64.dll new file mode 100644 index 0000000..f1dd49e Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/JLink_V632/JLink_x64.dll differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadAPP1.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadAPP1.bat new file mode 100644 index 0000000..0ec8b61 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadAPP1.bat @@ -0,0 +1,4 @@ +JLink_V632\JLink.exe -Device N32WB031 -If SWD -Speed 4000 -commanderscript JLink_Script\read_app1.jlink + +PAUSE +EXIT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadAPP2.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadAPP2.bat new file mode 100644 index 0000000..eedc99a --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadAPP2.bat @@ -0,0 +1,4 @@ +JLink_V632\JLink.exe -Device N32WB031 -If SWD -Speed 4000 -commanderscript JLink_Script\read_app2.jlink + +PAUSE +EXIT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadImageUpdate.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadImageUpdate.bat new file mode 100644 index 0000000..806a891 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadImageUpdate.bat @@ -0,0 +1,4 @@ +JLink_V632\JLink.exe -Device N32WB031 -If SWD -Speed 4000 -commanderscript JLink_Script\read_imageupdate.jlink + +PAUSE +EXIT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadMasterBoot.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadMasterBoot.bat new file mode 100644 index 0000000..27787f7 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/ReadMasterBoot.bat @@ -0,0 +1,4 @@ +JLink_V632\JLink.exe -Device N32WB031 -If SWD -Speed 4000 -commanderscript JLink_Script\read_master_boot.jlink + +PAUSE +EXIT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/Readbootsetting.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/Readbootsetting.bat new file mode 100644 index 0000000..ab40663 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/JLink/Readbootsetting.bat @@ -0,0 +1,4 @@ +JLink_V632\JLink.exe -Device N32WB031 -If SWD -Speed 4000 -commanderscript JLink_Script\read_bootsetting.jlink + +PAUSE +EXIT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/MergeFirmwareFiles.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/MergeFirmwareFiles.bat new file mode 100644 index 0000000..71fc019 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/MergeFirmwareFiles.bat @@ -0,0 +1,95 @@ + +echo off + +set NSUtil_path=.\NSUtil\NSUtil.exe + +set output_file=MergeFirmware + +set masterboot_bin=Image\MasterBoot +set bootsetting_bin=Image\bootsetting + +set public_key_file=.\keys\public_key.bin +set output_bootsetting=.\Image\bootsetting.bin + +set app1_bin=Image\APP1 +set bank1_bin=.\Image\APP1.bin +set bank1_start_address=0x1004000 +set bank1_version=0x00000001 +set bank1_activation=yes + +set app2_bin=Image\APP2 +set bank2_bin=.\Image\APP2.bin +set bank2_start_address=0x1020000 +set bank2_version=0x00000001 +set bank2_activation=no + +set image_update_bin=Image\ImageUpdate + +if exist %output_bootsetting% (del %output_bootsetting%) + +if defined public_key_file ( + + if not defined app2_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% + ) + if defined app2_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% + ) +) + + +if defined bootsetting_bin ( + + if defined app1_bin if defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack mergebin %output_file% ^ + --masterboot %masterboot_bin% ^ + --bootsetting %bootsetting_bin% ^ + --app1 %app1_bin% ^ + --app2 %app2_bin% ^ + --imageupdate %image_update_bin% + + + ) + + if defined app1_bin if defined app2_bin if not defined image_update_bin ( + + %NSUtil_path% pack mergebin %output_file% ^ + --masterboot %masterboot_bin% ^ + --bootsetting %bootsetting_bin% ^ + --app1 %app1_bin% ^ + --app2 %app2_bin% + + + ) + + + if defined app1_bin if not defined app2_bin if not defined image_update_bin ( + + %NSUtil_path% pack mergebin %output_file% ^ + --masterboot %masterboot_bin% ^ + --bootsetting %bootsetting_bin% ^ + --app1 %app1_bin% + + + ) + +) +PAUSE +EXIT \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSAndroidUtil/NSAndroidUtilV1.5.apk b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSAndroidUtil/NSAndroidUtilV1.5.apk new file mode 100644 index 0000000..8348afd Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSAndroidUtil/NSAndroidUtilV1.5.apk differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSLinkDragFilesToProgram.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSLinkDragFilesToProgram.bat new file mode 100644 index 0000000..22e6744 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSLinkDragFilesToProgram.bat @@ -0,0 +1,16 @@ +echo off +if exist "%1" ( + echo. + echo Please make sure connect SWD and reset pin of chip to NSLink. + echo This script will reset the chip and start programming... + echo. + + .\NSpyocd\NSpyocd.exe erase --chip -M pre-reset -t n32wb031 + .\NSpyocd\NSpyocd.exe load -t n32wb031 %1% +)else ( + echo. + echo Error! Do not double-click to run this bat!!! + echo. +) +PAUSE +EXIT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSLinkProgramming.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSLinkProgramming.bat new file mode 100644 index 0000000..5fe36b5 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSLinkProgramming.bat @@ -0,0 +1,105 @@ + +echo off + + +set NSUtil_path=.\NSUtil\NSUtil.exe + +set output_file=Temp + +set masterboot_bin=Image\MasterBoot +set bootsetting_bin=Image\bootsetting + +set public_key_file=.\keys\public_key.bin +set output_bootsetting=.\Image\bootsetting.bin + +set app1_bin=Image\APP1 +set bank1_bin=.\Image\APP1.bin +set bank1_start_address=0x1004000 +set bank1_version=0x00000001 +set bank1_activation=yes + +::set app2_bin=Image\APP2 +::set bank2_bin=.\Image\APP2.bin +::set bank2_start_address=0x1020000 +::set bank2_version=0x00000001 +::set bank2_activation=no + +::set image_update_bin=Image\ImageUpdate + +echo. +echo Please make sure connect SWD and reset pin of chip to NSLink. +echo This script will reset the chip and start programming... +echo. + +if exist %output_bootsetting% (del %output_bootsetting%) + +if defined public_key_file ( + + if not defined app2_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% + ) + if defined app2_bin ( + + %NSUtil_path% bootsetting generate %output_bootsetting% ^ + --public_key_file %public_key_file% ^ + --bank1_start_address %bank1_start_address% ^ + --bank1_version %bank1_version% ^ + --bank1_bin %bank1_bin% ^ + --bank1_activation %bank1_activation% ^ + --bank2_start_address %bank2_start_address% ^ + --bank2_version %bank2_version% ^ + --bank2_bin %bank2_bin% ^ + --bank2_activation %bank2_activation% + ) +) + + +if defined bootsetting_bin ( + + if defined app1_bin if defined app2_bin if defined image_update_bin ( + + %NSUtil_path% pack mergebin %output_file% ^ + --masterboot %masterboot_bin% ^ + --bootsetting %bootsetting_bin% ^ + --app1 %app1_bin% ^ + --app2 %app2_bin% ^ + --imageupdate %image_update_bin% + + + ) + + if defined app1_bin if defined app2_bin if not defined image_update_bin ( + + %NSUtil_path% pack mergebin %output_file% ^ + --masterboot %masterboot_bin% ^ + --bootsetting %bootsetting_bin% ^ + --app1 %app1_bin% ^ + --app2 %app2_bin% + + + ) + + + if defined app1_bin if not defined app2_bin if not defined image_update_bin ( + + %NSUtil_path% pack mergebin %output_file% ^ + --masterboot %masterboot_bin% ^ + --bootsetting %bootsetting_bin% ^ + --app1 %app1_bin% + + ) +) + +.\NSpyocd\NSpyocd.exe erase --chip -M pre-reset -t n32wb031 +.\NSpyocd\NSpyocd.exe load -t n32wb031 %output_file%.hex +echo Program Finish!!! +del %output_file%.hex /f +del %output_file%.bin /f +PAUSE +EXIT \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSLinkReadAll.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSLinkReadAll.bat new file mode 100644 index 0000000..2168091 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSLinkReadAll.bat @@ -0,0 +1,15 @@ +echo off + +set filename=NSLinkReadChip.bin + +echo. +echo Please make sure connect SWD and reset pin of chip to NSLink. +echo This script will reset the chip and start reading... +echo. + +.\NSpyocd\NSpyocd.exe cmd -t n32wb031 -M pre-reset -c savemem 0x1000000 0x40000 %filename% + +echo Please check the readback file %filename% if read success. + +PAUSE +EXIT diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSUtil/NSUtil.exe b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSUtil/NSUtil.exe new file mode 100644 index 0000000..cc08ea5 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSUtil/NSUtil.exe differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSpyocd/NSpyocd.exe b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSpyocd/NSpyocd.exe new file mode 100644 index 0000000..40678af Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/NSpyocd/NSpyocd.exe differ diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/UartFirmwareUpdate.bat b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/UartFirmwareUpdate.bat new file mode 100644 index 0000000..a5ac59f --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/UartFirmwareUpdate.bat @@ -0,0 +1,32 @@ +echo off + +:: APP.bin is the update firmware +:: --app_start_address is the address of update firmware +:: --app_version is the version of update firmware +:: --serial_port is the serial port number +set app_bin=.\Image\APP1.bin +set app_start_address=0x1004000 +set app_version=0x01020304 +set serial_baudrat=1000000 +set force_update=True +set serial_port=COM4 + + +echo. +echo Please connect serial chip RX to PA4 and serial chip TX to PA5. +echo Please note that this tool is not compatible with the COM port of NSLink. +echo Please test it with other serial chips (such as CH340). +echo Please confirm the %serial_port% is the right serial port you connected. +echo Please reset the chip to enter bootloader mode. +echo Waiting to respond from bootloader mode of the chip... +.\NSUtil\NSUtil.exe ius serial %app_bin% ^ + --app_start_address %app_start_address% ^ + --app_version %app_version% ^ + --serial_port %serial_port% ^ + --serial_baudrate %serial_baudrat% ^ + --force_update %force_update% + + + +PAUSE +EXIT \ No newline at end of file diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/keys/private_key.pem b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/keys/private_key.pem new file mode 100644 index 0000000..3ee7106 --- /dev/null +++ b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/keys/private_key.pem @@ -0,0 +1,5 @@ +-----BEGIN EC PRIVATE KEY----- +MHcCAQEEIDgB1+ch0akK2ZIrjAs3HVkfmmRr5esfHl0NMnqY1ZKjoAoGCCqGSM49 +AwEHoUQDQgAErhxBpfQ13T2JyADYD40qwmM6AjckXS3b8Eahal5DJkRzIH0WhupB +a6ONDWDaYc2YU9UipRRq7mS7tH5AOaa1KQ== +-----END EC PRIVATE KEY----- diff --git a/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/keys/public_key.bin b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/keys/public_key.bin new file mode 100644 index 0000000..4946417 Binary files /dev/null and b/nations-tec/N32WB03x_SDK_V2.0.0/utilities/dfu/keys/public_key.bin differ